Moved gadgets to use a whitelist system instead of blacklist for
collisions
This commit is contained in:
parent
e64324b36c
commit
7fb6ff58d0
@ -14,6 +14,7 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@ -221,6 +222,8 @@ public class GadgetManager extends MiniPlugin
|
||||
private boolean _hideParticles = false;
|
||||
private int _activeItemSlot = 3;
|
||||
private boolean _gadgetsEnabled = true;
|
||||
|
||||
private Set<Entity> _gadgetCollideWhitelist = new HashSet<>();
|
||||
|
||||
public GadgetManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager,
|
||||
MountManager mountManager, PetManager petManager, PreferencesManager preferencesManager,
|
||||
@ -857,6 +860,46 @@ public class GadgetManager extends MiniPlugin
|
||||
{
|
||||
_lastMove.remove(event.getEntity());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onGadgetCollide(GadgetCollideEntityEvent event)
|
||||
{
|
||||
if(event.getOther() instanceof Player)
|
||||
{
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
if(isAffectedByGadgets(event.getOther()))
|
||||
{
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e The entity to check
|
||||
* @return Returns true if the entity is affected by gadgets like snowballs, flesh hooks etc
|
||||
*/
|
||||
public boolean isAffectedByGadgets(Entity e)
|
||||
{
|
||||
return _gadgetCollideWhitelist.contains(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the given entity should be affected by gadgets by snowball, flesh hooks etc
|
||||
* By default only players and naturally spawned entities are affected.
|
||||
*/
|
||||
public void setAffectedByGadgets(Entity e, boolean affected)
|
||||
{
|
||||
if(affected)
|
||||
{
|
||||
_gadgetCollideWhitelist.add(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
_gadgetCollideWhitelist.remove(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setActive(Player player, Gadget gadget)
|
||||
{
|
||||
|
@ -2,12 +2,16 @@ package mineplex.core.gadget.event;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import mineplex.core.gadget.types.Gadget;
|
||||
|
||||
public class GadgetCollideEntityEvent extends Event
|
||||
/**
|
||||
* An event called when a gadget used by a player collides with an entity. By default, only players are effected (event is cancelled).
|
||||
*/
|
||||
public class GadgetCollideEntityEvent extends Event implements Cancellable
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@ -15,7 +19,7 @@ public class GadgetCollideEntityEvent extends Event
|
||||
private Gadget _gadget;
|
||||
private Entity _other;
|
||||
|
||||
private boolean _cancelled = false;
|
||||
private boolean _cancelled = true;
|
||||
|
||||
public GadgetCollideEntityEvent(Player player, Gadget gadget, Entity other)
|
||||
{
|
||||
|
@ -45,6 +45,7 @@ import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -142,6 +143,15 @@ public class WorldManager extends MiniPlugin
|
||||
else _mobs.add(loc.getWorld().spawn(loc, Chicken.class));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGadgetCollide(GadgetCollideEntityEvent event)
|
||||
{
|
||||
if(_mobs.contains(event.getOther()))
|
||||
{
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void BlockBreak(BlockBreakEvent event)
|
||||
|
@ -16,6 +16,8 @@ import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.database.tables.records.NpcsRecord;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -229,15 +231,6 @@ public class BoosterPodium extends MiniPlugin
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGadgetCollide(GadgetCollideEntityEvent event)
|
||||
{
|
||||
if (event.getOther().equals(_activeArmorStand))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPodium(Location loc, int id, byte data)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user