From 8c911586dcafd577f3515086bf77c34d36143594 Mon Sep 17 00:00:00 2001 From: Graphica Date: Sat, 29 Jul 2017 22:53:29 -0400 Subject: [PATCH] Clean and document code --- .../core/cosmetic/ui/page/FlagPage.java | 4 ++- .../gadget/gadgets/morph/MorphMelonHead.java | 29 +++++-------------- .../core/gadget/types/FlagGadget.java | 2 -- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/FlagPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/FlagPage.java index c5fc5e852..34009c2b7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/FlagPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/FlagPage.java @@ -9,7 +9,6 @@ import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.ShopItem; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -37,8 +36,10 @@ public class FlagPage extends GadgetPage @Override protected void buildPage() { + // chose a beginning slot int slot = 10; + // grab all flags List list = getPlugin().getGadgetManager().getGadgets(GadgetType.FLAG); if(list != null) @@ -46,6 +47,7 @@ public class FlagPage extends GadgetPage int size = list.size(); int limit = (_page + 1) * 28; + // loop through the flags for a specific page for (int i = _page * 28; i < limit && i < size; ++i) { Gadget gadget = list.get(i); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphMelonHead.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphMelonHead.java index 2b503bfad..91731165c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphMelonHead.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphMelonHead.java @@ -5,49 +5,28 @@ import mineplex.core.common.skin.SkinData; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.LineFormat; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilSound; import mineplex.core.common.util.UtilText; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.morph.managers.UtilMorph; import mineplex.core.gadget.types.MorphGadget; -import mineplex.core.hologram.Hologram; -import mineplex.core.hologram.HologramManager; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.recharge.Recharge; -import mineplex.core.treasure.event.TreasureFinishEvent; -import mineplex.core.treasure.event.TreasureStartEvent; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; import mineplex.core.utils.UtilGameProfile; import org.apache.commons.lang3.tuple.Pair; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.FireworkEffect; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import java.time.Month; import java.time.YearMonth; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -118,6 +97,7 @@ public class MorphMelonHead extends MorphGadget @EventHandler public void handlePlayerInteract(EntityDamageByEntityEvent event) { + // Check it's two players interacting if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) { if (!isActive((Player) event.getDamager())) @@ -127,31 +107,38 @@ public class MorphMelonHead extends MorphGadget Player player = (Player) event.getEntity(); + // do nothing if the player has a helmet already if (player.getInventory().getHelmet() != null) { return; } + // do nothing if the player is supposed to already have a fruit helmet if (_heads.containsKey(player.getUniqueId())) { return; } + // select a head skin and name it Pair data = TEXTURES[ThreadLocalRandom.current().nextInt(TEXTURES.length)]; ItemStack head = data.getLeft().getSkull(data.getRight(), new ArrayList<>()); + // equip the head and notify the player of the action _heads.put(player.getUniqueId(), head); player.getInventory().setHelmet(head); player.getWorld().playSound(player.getEyeLocation(), Sound.CHICKEN_EGG_POP, 1, 0); UtilFirework.playFirework(player.getEyeLocation(), FireworkEffect.builder().withColor(Color.LIME).with(FireworkEffect.Type.BALL).build()); player.sendMessage(F.main("Melonhead", C.cYellow + "Wham! " + C.cGray + "You just got " + C.cGreen + "MELON'D!")); + // schedule the head to be removed later Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () -> { + // don't do anything if the player has logged off if (_heads.containsKey(player.getUniqueId())) { ItemStack item = _heads.remove(player.getUniqueId()); + // don't remove the helmet if it has already been changed. if (player.getInventory().getHelmet() != null && player.getInventory().getHelmet().equals(item)) { player.getInventory().setHelmet(null); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/FlagGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/FlagGadget.java index ab9697c84..7a7f255f3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/FlagGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/FlagGadget.java @@ -5,7 +5,6 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilText; -import mineplex.core.common.util.banner.CountryFlag; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.flag.FlagType; import org.bukkit.Material; @@ -15,7 +14,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; /**