Clean and document code

This commit is contained in:
Graphica 2017-07-29 22:53:29 -04:00 committed by cnr
parent 04f182c745
commit 8c911586dc
3 changed files with 11 additions and 24 deletions

View File

@ -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<Gadget> 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);

View File

@ -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<SkinData, String> 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);

View File

@ -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;
/**