Create melon head morph
This commit is contained in:
parent
ab91e3cfd6
commit
540e450f66
@ -0,0 +1,181 @@
|
|||||||
|
package mineplex.core.gadget.gadgets.morph;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
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;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PPC Reward for month of August 2017. Allows users to turn other player's heads into various fruits.
|
||||||
|
*/
|
||||||
|
public class MorphMelonHead extends MorphGadget
|
||||||
|
{
|
||||||
|
/** Fruit head texture options */
|
||||||
|
private static final Pair[] TEXTURES = {
|
||||||
|
Pair.of(SkinData.APPLE, C.cDRedB + "Apple Head"),
|
||||||
|
Pair.of(SkinData.MELON, C.cDGreen + "Melon Head"),
|
||||||
|
Pair.of(SkinData.ORANGE, C.cGoldB + "Orange Head"),
|
||||||
|
Pair.of(SkinData.STRAWBERRY, C.cRedB + "Berry Head"),
|
||||||
|
Pair.of(SkinData.PINEAPPLE, C.cYellowB + "Pineapple Head"),
|
||||||
|
Pair.of(SkinData.GREEN_APPLE, C.cGreenB + "Apple Head"),
|
||||||
|
Pair.of(SkinData.PLUM, C.cPurpleB + "Plum Head")
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Ticks that a fruit head change lasts */
|
||||||
|
private static final long TIME = 240;
|
||||||
|
|
||||||
|
/** Map of players to their current fruit heads */
|
||||||
|
private final Map<UUID, ItemStack> _heads = new HashMap<>();
|
||||||
|
|
||||||
|
public MorphMelonHead(GadgetManager manager)
|
||||||
|
{
|
||||||
|
super(manager, "Melonhead Morph", UtilText.splitLinesToArray(new String[] {
|
||||||
|
C.cGray + "Transform yourself into a melon.",
|
||||||
|
C.cGray + "Tag other players to build your melon army!",
|
||||||
|
"",
|
||||||
|
C.cGreen + "Left click" + C.cWhite + " players to turn their heads to fruit."
|
||||||
|
}, LineFormat.LORE), -14, Material.MELON, (byte) 0, YearMonth.of(2017, Month.AUGUST));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the player's skin to a Melon texture.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void enableCustom(Player player, boolean message)
|
||||||
|
{
|
||||||
|
applyArmor(player, message);
|
||||||
|
|
||||||
|
GameProfile profile = UtilGameProfile.getGameProfile(player);
|
||||||
|
profile.getProperties().clear();
|
||||||
|
profile.getProperties().put("textures", SkinData.MELON_PERSON.getProperty());
|
||||||
|
|
||||||
|
DisguisePlayer disguisePlayer = new DisguisePlayer(player, profile);
|
||||||
|
disguisePlayer.showInTabList(true, 0);
|
||||||
|
UtilMorph.disguise(player, disguisePlayer, Manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores the player's skin.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void disableCustom(Player player, boolean message)
|
||||||
|
{
|
||||||
|
removeArmor(player);
|
||||||
|
UtilMorph.undisguise(player, Manager.getDisguiseManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect when a player punches another player.
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void handlePlayerInteract(EntityDamageByEntityEvent event)
|
||||||
|
{
|
||||||
|
if (event.getDamager() instanceof Player && event.getEntity() instanceof Player)
|
||||||
|
{
|
||||||
|
if (!isActive((Player) event.getDamager()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) event.getEntity();
|
||||||
|
|
||||||
|
if (player.getInventory().getHelmet() != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_heads.containsKey(player.getUniqueId()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pair<SkinData, String> data = TEXTURES[ThreadLocalRandom.current().nextInt(TEXTURES.length)];
|
||||||
|
ItemStack head = data.getLeft().getSkull(data.getRight(), new ArrayList<>());
|
||||||
|
|
||||||
|
_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!"));
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () ->
|
||||||
|
{
|
||||||
|
if (_heads.containsKey(player.getUniqueId()))
|
||||||
|
{
|
||||||
|
ItemStack item = _heads.remove(player.getUniqueId());
|
||||||
|
|
||||||
|
if (player.getInventory().getHelmet() != null && player.getInventory().getHelmet().equals(item))
|
||||||
|
{
|
||||||
|
player.getInventory().setHelmet(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, TIME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean hash maps on player disconnect.
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDisconnect(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
if (isActive(event.getPlayer()))
|
||||||
|
{
|
||||||
|
if (_heads.containsKey(event.getPlayer().getUniqueId()))
|
||||||
|
{
|
||||||
|
_heads.remove(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user