From a9fbbc2e274ca1bb260442714b845e1f11d2fd5b Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 20 Nov 2017 15:46:35 +0000 Subject: [PATCH] Cleanup CostumePage and implement some new Christmas particles --- .../core/common/shape/ShapeFidgetSpinner.java | 43 ++++++++++ .../core/cosmetic/ui/page/CostumePage.java | 40 ++++----- .../mineplex/core/gadget/GadgetManager.java | 7 +- .../outfit/freezesuit/OutfitFreezeSuit.java | 12 --- .../outfit/ravesuit/OutfitRaveSuit.java | 6 +- .../reindeer/OutfitReindeerAntlers.java | 9 +- .../outfit/spacesuit/OutfitSpaceSuit.java | 12 --- .../stpatricks/OutfitStPatricksSuit.java | 12 --- .../outfit/windupsuit/OutfitWindUpSuit.java | 6 +- .../particle/ParticleFidgetSpinner.java | 82 +++++++++++++++++++ .../particle/ParticleWingsChristmas.java | 66 +++++++++++++++ .../gadget/set/suits/SetReindeerSuit.java | 5 +- .../mineplex/core/gadget/types/HatGadget.java | 79 +----------------- .../core/gadget/types/OutfitGadget.java | 6 ++ 14 files changed, 241 insertions(+), 144 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/ShapeFidgetSpinner.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFidgetSpinner.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleWingsChristmas.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/ShapeFidgetSpinner.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/ShapeFidgetSpinner.java new file mode 100644 index 000000000..dc3cfd798 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/ShapeFidgetSpinner.java @@ -0,0 +1,43 @@ +package mineplex.core.common.shape; + +import org.bukkit.Location; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; + +public class ShapeFidgetSpinner extends Shape implements CosmeticShape +{ + + public ShapeFidgetSpinner(int petalCount, int rotationDegrees) + { + double x0, y0; + double sinRotation = Math.sin(rotationDegrees); + double cosRotation = Math.cos(rotationDegrees); + + for (double theta = 0; theta <= 2 * Math.PI; theta += Math.PI / 90) + { + double radius = Math.sin(petalCount * theta); + double x1 = radius * Math.cos(theta); + double y1 = radius * Math.sin(theta); + + x0 = cosRotation * x1 - sinRotation * y1; + y0 = 0.2 + sinRotation * x1 + cosRotation * y1; + + addPoint(new Vector(x0, y0, 0.4)); + } + } + + @Override + public void display(Location location) + { + Shape clone = clone(); + clone.rotateOnYAxis(Math.toRadians(location.getYaw() + 180)); + + for (Vector vector : clone.getPoints()) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, location.clone().add(vector), null, 0, 1, ViewDist.NORMAL); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/CostumePage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/CostumePage.java index 8616c741e..a01f40674 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/CostumePage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/CostumePage.java @@ -9,10 +9,6 @@ import mineplex.core.common.util.C; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.donation.DonationManager; -import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuit; -import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuit; -import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuit; -import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksSuit; import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.OutfitGadget; @@ -21,7 +17,7 @@ import mineplex.core.shop.item.ShopItem; public class CostumePage extends GadgetPage { - public CostumePage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player) + CostumePage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player) { super(plugin, shop, clientManager, donationManager, name, player); @@ -31,6 +27,8 @@ public class CostumePage extends GadgetPage protected void buildPage() { int slot; + int offset = 0; + Class lastGadgetClass = null; for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.COSTUME)) { @@ -41,22 +39,26 @@ public class CostumePage extends GadgetPage OutfitGadget outfitGadget = ((OutfitGadget) gadget); - int offset; + if (lastGadgetClass == null || !(gadget.getClass().getSuperclass().isAssignableFrom(lastGadgetClass.getSuperclass()))) + { + lastGadgetClass = outfitGadget.getClass(); + offset++; + } - if (gadget instanceof OutfitRaveSuit) offset = 0; - else if (gadget instanceof OutfitSpaceSuit) offset = 1; - else if (gadget instanceof OutfitFreezeSuit) offset = 2; - else if (gadget instanceof OutfitStPatricksSuit) offset = 3; - else offset = 4; + slot = offset + 18; // 18 = 2 lines down - slot = offset + 1 + 18; //1 buffer to left, 18 = 2 lines down - - if (outfitGadget.getSlot() == OutfitGadget.ArmorSlot.CHEST) - slot += 9; - else if (outfitGadget.getSlot() == OutfitGadget.ArmorSlot.LEGS) - slot += 18; - else if (outfitGadget.getSlot() == OutfitGadget.ArmorSlot.BOOTS) - slot += 27; + switch (outfitGadget.getSlot()) + { + case CHEST: + slot += 9; + break; + case LEGS: + slot += 18; + break; + case BOOTS: + slot += 27; + break; + } addGadget(gadget, slot); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index 60dce9725..cb96be5f9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -227,6 +227,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes; import mineplex.core.gadget.gadgets.particle.ParticleEmerald; import mineplex.core.gadget.gadgets.particle.ParticleEnchant; import mineplex.core.gadget.gadgets.particle.ParticleFairy; +import mineplex.core.gadget.gadgets.particle.ParticleFidgetSpinner; import mineplex.core.gadget.gadgets.particle.ParticleFireRings; import mineplex.core.gadget.gadgets.particle.ParticleFoot; import mineplex.core.gadget.gadgets.particle.ParticleFrostLord; @@ -239,6 +240,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleRain; import mineplex.core.gadget.gadgets.particle.ParticleTitan; import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; import mineplex.core.gadget.gadgets.particle.ParticleWingsBee; +import mineplex.core.gadget.gadgets.particle.ParticleWingsChristmas; import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; import mineplex.core.gadget.gadgets.particle.ParticleWingsLove; @@ -642,7 +644,8 @@ public class GadgetManager extends MiniPlugin addGadget(new ParticleCanadian(this)); addGadget(new ParticleHalloween(this)); - + addGadget(new ParticleWingsChristmas(this)); + addGadget(new ParticleFidgetSpinner(this)); // Arrow Trails addGadget(new ArrowTrailFrostLord(this)); @@ -1111,7 +1114,7 @@ public class GadgetManager extends MiniPlugin if (armor.getSlot() == slot) { - armor.removeArmor(player, true); + armor.disableCustom(player, true); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java index 3e8e9e88f..71f0b03e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java @@ -67,18 +67,6 @@ public class OutfitFreezeSuit extends OutfitGadget } } - @Override - public void enableCustom(Player player, boolean message) - { - applyArmor(player, message); - } - - @Override - public void disableCustom(Player player, boolean message) - { - removeArmor(player, message); - } - @EventHandler public void activateBridge(PlayerToggleSneakEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java index 48305d620..4ac5a846b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java @@ -39,14 +39,16 @@ public class OutfitRaveSuit extends OutfitGadget @Override public void enableCustom(Player player, boolean message) { - applyArmor(player, message); + super.enableCustom(player, message); + _colorPhase.put(player.getUniqueId(), -1); } @Override public void disableCustom(Player player, boolean message) { - removeArmor(player, message); + super.disableCustom(player, message); + _colorPhase.remove(player.getUniqueId()); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java index 9edf12604..fac6eecf3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java @@ -22,8 +22,8 @@ public class OutfitReindeerAntlers extends OutfitReindeer { private static final ItemStack IN_HAND = new ItemStack(Material.DEAD_BUSH); - private static final EulerAngle LEFT_POS = new EulerAngle(Math.PI / 2D, 0, Math.PI / 4D); - private static final EulerAngle RIGHT_POS = new EulerAngle(-LEFT_POS.getX(), 0, LEFT_POS.getZ()); + private static final EulerAngle LEFT_POS = new EulerAngle(Math.PI / 2D, 0, -Math.PI / 4D); + private static final EulerAngle RIGHT_POS = new EulerAngle(-LEFT_POS.getX(), 0, Math.PI - (LEFT_POS.getZ())); private final Map> _antlers; @@ -79,10 +79,11 @@ public class OutfitReindeerAntlers extends OutfitReindeer private void updateRotation(Player player, ArmorStand left, ArmorStand right) { Location location = player.getLocation().add(0, player.isSneaking() ? 0.3 : 0.6, 0); + location.setPitch(0); Vector direction = location.getDirection(); - direction.setY(0); - left.teleport(location.clone().add(direction).add(UtilAlg.getLeft(direction))); + left.teleport(location.clone().add(direction.add(UtilAlg.getLeft(direction)).multiply(0.4))); + direction.normalize(); right.teleport(location.clone().add(direction.multiply(-0.4))); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java index c203d1b52..1a9fe939b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java @@ -24,18 +24,6 @@ public class OutfitSpaceSuit extends OutfitGadget UtilText.splitLineToArray(C.cGray + "Designed specifically for combat in deep space for a sport known as \'Gravity\'", LineFormat.LORE), cost, slot, mat, data); } - - @Override - public void enableCustom(Player player, boolean message) - { - applyArmor(player, message); - } - - @Override - public void disableCustom(Player player, boolean message) - { - removeArmor(player, message); - } @EventHandler public void setBonus(UpdateEvent event) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/stpatricks/OutfitStPatricksSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/stpatricks/OutfitStPatricksSuit.java index ef4f511b2..980bdf7a0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/stpatricks/OutfitStPatricksSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/stpatricks/OutfitStPatricksSuit.java @@ -42,18 +42,6 @@ public class OutfitStPatricksSuit extends OutfitGadget setDisplayItem(displayItem); } - @Override - public void enableCustom(Player player, boolean message) - { - applyArmor(player, message); - } - - @Override - public void disableCustom(Player player, boolean message) - { - removeArmor(player, message); - } - @EventHandler public void onUpdate(UpdateEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java index 1d084921c..202ca0024 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java @@ -45,7 +45,8 @@ public class OutfitWindUpSuit extends OutfitGadget @Override public void enableCustom(Player player, boolean message) { - applyArmor(player, message); + super.enableCustom(player, message); + _colorPhase.put(player, 0); _percentage.put(player, 0); } @@ -53,7 +54,8 @@ public class OutfitWindUpSuit extends OutfitGadget @Override public void disableCustom(Player player, boolean message) { - removeArmor(player, message); + super.disableCustom(player, message); + _colorPhase.remove(player); _percentage.remove(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFidgetSpinner.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFidgetSpinner.java new file mode 100644 index 000000000..5eab3cea0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFidgetSpinner.java @@ -0,0 +1,82 @@ +package mineplex.core.gadget.gadgets.particle; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.shape.ShapeFidgetSpinner; +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilText; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.ParticleGadget; +import mineplex.core.gadget.util.CostConstants; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class ParticleFidgetSpinner extends ParticleGadget +{ + + private static final int MAX_ROTATION = 20; + private static final int PETAL_COUNT = 3; + private static final double HEIGHT = 0.9; + + private final List _shapes = new ArrayList<>(MAX_ROTATION); + + private int _shapeIndex; + + public ParticleFidgetSpinner(GadgetManager manager) + { + super(manager, "Fidget Spinner Aura", + UtilText.splitLineToArray(C.cGray + "The best gift this Christmas!", LineFormat.LORE), + CostConstants.FOUND_IN_GINGERBREAD_CHESTS, Material.RECORD_3, (byte) 0); + + for (int rotation = 0; rotation < MAX_ROTATION; rotation += 2) + { + _shapes.add(new ShapeFidgetSpinner(PETAL_COUNT, rotation)); + } + } + + @Override + public void playParticle(Player player, UpdateEvent event) + { + Location location = player.getLocation(); + + if (Manager.isMoving(player)) + { + for (int i = 0; i < 5; i++) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, UtilAlg.getRandomLocation(location, 1.5, 1.5, 1.5), null, 0, 1, ViewDist.NORMAL); + } + return; + } + + location.add(0, HEIGHT, 0); + ShapeFidgetSpinner shape = _shapes.get(_shapeIndex); + shape.display(location); + } + + @Override + @EventHandler + public void Caller(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + super.Caller(event); + if (++_shapeIndex == _shapes.size()) + { + _shapeIndex = 0; + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleWingsChristmas.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleWingsChristmas.java new file mode 100644 index 000000000..53a5a5a28 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleWingsChristmas.java @@ -0,0 +1,66 @@ +package mineplex.core.gadget.gadgets.particle; + +import java.awt.*; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import mineplex.core.common.shape.ShapeWings; +import mineplex.core.common.skin.SkinData; +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilText; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.ParticleGadget; +import mineplex.core.gadget.util.CostConstants; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class ParticleWingsChristmas extends ParticleGadget +{ + + private static final Color GREEN = new Color(0, 158, 21); + + private final ShapeWings _wings = new ShapeWings(ParticleType.RED_DUST.particleName, new Vector(1,1,1), 1, 0, false, ShapeWings.DEFAULT_ROTATION, ShapeWings.ANGEL_WING_PATTERN); + private final ShapeWings _wingsEdge = new ShapeWings(ParticleType.RED_DUST.particleName, new Vector(1,1,0.5), 1, 0, true, ShapeWings.DEFAULT_ROTATION, ShapeWings.ANGEL_WING_PATTERN); + + public ParticleWingsChristmas(GadgetManager manager) + { + super(manager, "Christmas Wings", + UtilText.splitLineToArray(C.cGray + "TODO", LineFormat.LORE), + CostConstants.FOUND_IN_GINGERBREAD_CHESTS, Material.GLASS, (byte) 0); + + setDisplayItem(SkinData.PRESENT.getSkull()); + } + + @Override + public void playParticle(Player player, UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST && event.getType() != UpdateType.FAST) + { + return; + } + + Location location = player.getLocation(); + location.add(0, 1.2, 0).add(location.getDirection().multiply(-0.2)); + + if (Manager.isMoving(player)) + { + if (event.getType() == UpdateType.FASTEST) + { + UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, location, 0.2F, 0.2F, 0.2F, 0, 3, ViewDist.NORMAL); + } + } + else if (event.getType() == UpdateType.FAST) + { + _wings.displayColored(location, GREEN); + _wingsEdge.displayColored(location, Color.RED); + } + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/suits/SetReindeerSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/suits/SetReindeerSuit.java index 484703b27..a5de50994 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/suits/SetReindeerSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/suits/SetReindeerSuit.java @@ -26,7 +26,7 @@ public class SetReindeerSuit extends GadgetSet { private static final Vector VELOCITY = new Vector(0, 2, 0); - private static final long COOLDOWN = TimeUnit.SECONDS.toMillis(8); + private static final long COOLDOWN = TimeUnit.SECONDS.toMillis(10); public SetReindeerSuit(GadgetManager manager) { @@ -43,7 +43,7 @@ public class SetReindeerSuit extends GadgetSet { Player player = event.getPlayer(); - if (event.isSneaking() || !isActive(player) || !Recharge.Instance.use(player, getName(), COOLDOWN, true, false)) + if (event.isSneaking() || !isActive(player) || !Recharge.Instance.use(player, getName() + " Leap", COOLDOWN, true, false)) { return; } @@ -69,7 +69,6 @@ public class SetReindeerSuit extends GadgetSet UtilAction.velocity(player, velocity); - UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, location, 0, 0, 0, 0.1F, 1, ViewDist.NORMAL); UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, location.subtract(0, 0.5, 0), 0, 0, 0, 0.1F, 3, ViewDist.NORMAL); if (iterations % 4 == 0) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java index d7a8c9637..98597d671 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java @@ -1,102 +1,29 @@ package mineplex.core.gadget.types; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.hat.HatType; public abstract class HatGadget extends OutfitGadget { - private ItemStack _hat; - private HatType _hatType; + + private final HatType _hatType; public HatGadget(GadgetManager manager, HatType type) { super(manager, type.getName(), type.getLore(), type.getCost(), ArmorSlot.HELMET, Material.GLASS, (byte) 0, type.getAltNames()); - _hat = type.getHat(); + _hatType = type; - setDisplayItem(type.getHat()); } - public HatGadget(GadgetManager manager, String name, String[] desc, int cost, ItemStack item) - { - super(manager, name, desc, cost, ArmorSlot.HELMET, item.getType(), item.getData().getData()); - } - - public HatGadget(GadgetManager manager, String name, String[] desc, int cost, String playerName) - { - this(manager, name, desc, cost, getSkull(playerName)); - } - - public ItemStack getHelmetItem() - { - return _hat.clone(); - } - - public void applyArmor(Player player, boolean message) - { - Manager.removeGadgetType(player, GadgetType.MORPH, this); - Manager.removeGadgetType(player, GadgetType.FLAG, this); - Manager.removeOutfit(player, _slot); - - _active.add(player); - - if (message) - UtilPlayer.message(player, F.main("Gadget", "You put on " + F.elem(getName()) + ".")); - - player.getInventory().setHelmet(getHelmetItem()); - } - - public void removeArmor(Player player, boolean message) - { - if (!_active.remove(player)) - return; - - if (message) - UtilPlayer.message(player, F.main("Gadget", "You took off " + F.elem(getName()) + ".")); - - player.getInventory().setHelmet(null); - } - - public static ItemStack getSkull(String playerName) - { - SkullMeta meta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM); - - meta.setOwner(playerName); - - ItemStack stack = new ItemStack(Material.SKULL_ITEM,1 , (byte)3); - - stack.setItemMeta(meta); - - return stack; - } - @Override public GadgetType getGadgetType() { return GadgetType.HAT; } - - @Override - public void enableCustom(Player player, boolean message) - { - applyArmor(player, message); - } - - @Override - public void disableCustom(Player player, boolean message) - { - removeArmor(player, message); - } - public HatType getHatType() { return _hatType; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java index d1d990584..3318d4fc5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java @@ -63,6 +63,12 @@ public abstract class OutfitGadget extends Gadget applyArmor(player, message); } + @Override + public void disableCustom(Player player, boolean message) + { + removeArmor(player, message); + } + public void applyArmor(Player player, boolean message) { Manager.removeGadgetType(player, GadgetType.MORPH, this);