Fixed morph with lava, water, void and ender pearls

This commit is contained in:
LCastr0 2016-12-23 18:15:26 -02:00
parent 7f6f3464a1
commit c0afad0723
7 changed files with 130 additions and 24 deletions

View File

@ -1222,15 +1222,22 @@ public class GadgetManager extends MiniPlugin
if (!SwimManager.isSwimming(uuid))
{
SwimManager.addPlayer(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), true));
SwimManager.removePlayerLava(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), true, false));
}
}
else if (material == Material.LAVA || material == Material.STATIONARY_LAVA)
{
SwimManager.addPlayerLava(uuid);
SwimManager.removePlayer(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), false, true));
}
else
{
if (SwimManager.isSwimming(uuid))
if (SwimManager.isSwimming(uuid) || SwimManager.isInLava(uuid))
{
SwimManager.removePlayer(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), false));
SwimManager.removeLavaAndWater(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), false, false));
}
}
}

View File

@ -1,18 +1,21 @@
package mineplex.core.gadget.event;
import mineplex.core.gadget.types.ItemGadget;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class ItemGadgetUseEvent extends Event
import mineplex.core.gadget.types.ItemGadget;
public class ItemGadgetUseEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private ItemGadget _gadget;
private int _count;
private boolean _cancelled;
private String _cancelledMessage = "";
public ItemGadgetUseEvent(Player player, ItemGadget gadget, int count)
{
@ -45,4 +48,26 @@ public class ItemGadgetUseEvent extends Event
{
return _player;
}
@Override
public boolean isCancelled()
{
return _cancelled;
}
@Override
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public String getCancelledMessage()
{
return _cancelledMessage;
}
public void setCancelledMessage(String cancelledMessage)
{
_cancelledMessage = cancelledMessage;
}
}

View File

@ -10,9 +10,9 @@ public class PlayerToggleSwimEvent extends Event
private static final HandlerList handlers = new HandlerList();
private Player _player;
private boolean _swimming;
private boolean _swimming, _lava;
public PlayerToggleSwimEvent(Player player, boolean swimming)
public PlayerToggleSwimEvent(Player player, boolean swimming, boolean lava)
{
_player = player;
_swimming = swimming;
@ -28,6 +28,11 @@ public class PlayerToggleSwimEvent extends Event
return _swimming;
}
public boolean isInLava()
{
return _lava;
}
public HandlerList getHandlers()
{
return handlers;

View File

@ -12,8 +12,7 @@ import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.event.entity.EntityDamageEvent;
import com.mojang.authlib.GameProfile;
@ -25,6 +24,9 @@ import mineplex.core.common.util.UtilText;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.event.StackerEvent;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.ItemGadgetUseEvent;
import mineplex.core.gadget.event.PlayerToggleSwimEvent;
import mineplex.core.gadget.gadgets.item.ItemEtherealPearl;
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.utils.UtilGameProfile;
@ -38,14 +40,8 @@ public class MorphDinnerbone extends MorphGadget
public MorphDinnerbone(GadgetManager manager)
{
super(manager, "Dinnerbone Morph", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE),
-14, Material.GLASS, (byte) 0, YearMonth.of(2017, Month.JANUARY));
// Creates display item
ItemStack dinnerboneHead = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
SkullMeta skullMeta = (SkullMeta) dinnerboneHead.getItemMeta();
skullMeta.setOwner("Dinnerbone");
dinnerboneHead.setItemMeta(skullMeta);
setDisplayItem(dinnerboneHead);
super(manager, "Over Easy Morph", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE),
-14, Material.EGG, (byte) 0, YearMonth.of(2017, Month.JANUARY));
}
@Override
@ -120,4 +116,46 @@ public class MorphDinnerbone extends MorphGadget
event.setCancelled(true);
}
@EventHandler
public void onToggleSwim(PlayerToggleSwimEvent event)
{
if (!isActive(event.getPlayer()))
return;
// Disables morph if player is swimming or in lava
if (event.isSwimming() || event.isInLava())
{
disable(event.getPlayer());
}
}
@EventHandler
public void onVoid(EntityDamageEvent event)
{
if (event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
if (isActive(player))
{
if (event.getCause() == EntityDamageEvent.DamageCause.VOID)
{
disable(player);
}
}
}
}
@EventHandler
public void useEnderpearl(ItemGadgetUseEvent event)
{
if (event.getGadget() instanceof ItemEtherealPearl)
{
if (isActive(event.getPlayer()))
{
event.setCancelledMessage("You cannot use this item while morphed as " + getName() + "!");
event.setCancelled(true);
}
}
}
}

View File

@ -55,7 +55,7 @@ public class MorphSquid extends MorphGadget implements IThrown
applyArmor(player, message);
DisguiseSquid disguiseSquid = new DisguiseSquid(player);
UtilMorph.disguise(player, disguiseSquid, Manager);
onToggleSwim(new PlayerToggleSwimEvent(player, SwimManager.isSwimming(player.getUniqueId())));
onToggleSwim(new PlayerToggleSwimEvent(player, SwimManager.isSwimming(player.getUniqueId()), SwimManager.isInLava(player.getUniqueId())));
}
@Override

View File

@ -8,6 +8,7 @@ public class SwimManager
{
private static List<UUID> _swimming = new ArrayList<>();
private static List<UUID> _lava = new ArrayList<>();
public static void addPlayer(UUID uuid)
{
@ -22,9 +23,33 @@ public class SwimManager
}
}
public static void addPlayerLava(UUID uuid)
{
_lava.add(uuid);
}
public static void removePlayerLava(UUID uuid)
{
if (_lava.contains(uuid))
{
_lava.remove(uuid);
}
}
public static void removeLavaAndWater(UUID uuid)
{
removePlayerLava(uuid);
removePlayer(uuid);
}
public static boolean isSwimming(UUID uuid)
{
return _swimming.contains(uuid);
}
public static boolean isInLava(UUID uuid)
{
return _lava.contains(uuid);
}
}

View File

@ -173,14 +173,20 @@ public abstract class ItemGadget extends Gadget
UtilInv.Update(player);
return;
}
Manager.getInventoryManager().addItemToInventory(player, getName(), -1);
player.getInventory().setItem(Manager.getActiveItemSlot(), ItemStackFactory.Instance.CreateStack(getDisplayMaterial(), getDisplayData(), 1, F.item(Manager.getInventoryManager().Get(player).getItemCount(getName()) + " " + getName())));
ItemGadgetUseEvent itemGadgetUseEvent = new ItemGadgetUseEvent(player, this, 1);
UtilServer.CallEvent(itemGadgetUseEvent);
if (itemGadgetUseEvent.isCancelled())
{
UtilPlayer.message(player, F.main("Item", itemGadgetUseEvent.getCancelledMessage()));
return;
}
Manager.getInventoryManager().addItemToInventory(player, getName(), -1);
player.getInventory().setItem(Manager.getActiveItemSlot(), ItemStackFactory.Instance.CreateStack(getDisplayMaterial(), getDisplayData(), 1, F.item(Manager.getInventoryManager().Get(player).getItemCount(getName()) + " " + getName())));
ActivateCustom(event.getPlayer());
}