Improve the rabbit morph

This commit is contained in:
Sam 2018-03-27 18:45:36 +01:00 committed by Alexander Meech
parent b555bb37ef
commit 7e1ec7e132
3 changed files with 136 additions and 114 deletions

View File

@ -833,4 +833,9 @@ public class UtilText
RN_X[number % 100 / 10] +
RN_I[number % 10];
}
public static String capitalise(String input)
{
return Character.toUpperCase(input.charAt(0)) + input.toLowerCase().substring(1);
}
}

View File

@ -1,22 +1,40 @@
package mineplex.core.disguise.disguises;
import org.bukkit.entity.EntityType;
import net.minecraft.server.v1_8_R3.EntityRabbit;
import net.minecraft.server.v1_8_R3.EntityVillager;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Rabbit.Type;
public class DisguiseRabbit extends DisguiseAnimal
{
private Type _type;
public DisguiseRabbit(org.bukkit.entity.Entity entity)
{
super(EntityType.RABBIT, entity);
_type = Type.BROWN;
DataWatcher.a(18, Byte.valueOf((byte) 0), EntityRabbit.META_TYPE, 0);
}
public void setType(Type type)
{
_type = type;
int id = type.ordinal();
DataWatcher.watch(18, id, EntityVillager.META_TYPE, id);
}
public Type getType()
{
return _type;
}
@Override
public Packet getSpawnPacket()
{

View File

@ -2,19 +2,23 @@ package mineplex.core.gadget.gadgets.morph;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
@ -34,60 +38,84 @@ import mineplex.core.common.util.UtilFirework;
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.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.disguise.disguises.DisguiseRabbit;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.gadget.util.CostConstants;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class MorphBunny extends MorphGadget
public class MorphBunny extends MorphAbilityGadget
{
private HashSet<Player> _jumpCharge = new HashSet<Player>();
private HashMap<Item, String> _eggs = new HashMap<Item, String>();
private static final long EGG_COOLDOWN = TimeUnit.SECONDS.toMillis(30);
private static final int SHARD_COST = 500, SHARD_REWARD = 450;
private static final float CHARGE_PER_TICK = 0.05F;
private static final int ITEM_LIFE_TICKS = 24000;
private static final ItemStack ACTIVE_ITEM = new ItemBuilder(Material.RABBIT_HIDE)
.setTitle(C.cGreen + "Switch Style")
.addLore("Clicking this will cycle through", "all possible rabbit styles.")
.build();
private final Set<Player> _jumpCharge = new HashSet<>();
private final Map<Item, UUID> _eggs = new HashMap<>();
public MorphBunny(GadgetManager manager)
{
super(manager, "Easter Bunny Morph", UtilText.splitLinesToArray(new String[]
{
C.cGray + "Happy Easter!",
C.blankLine,
"#" + C.cWhite + "Charge Crouch to use Super Jump",
"#" + C.cWhite + "Left Click to use Hide Easter Egg",
C.blankLine,
"#" + C.cRed + C.Bold + "WARNING: " + ChatColor.RESET + "Hide Easter Egg uses 500 Shards",
}, LineFormat.LORE),
-5,
Material.MONSTER_EGG, UtilEnt.getEntityEggData(EntityType.RABBIT));
{
C.cGray + "Happy Easter!",
C.blankLine,
"#" + C.cWhite + "Charge Crouch to use Super Jump",
"#" + C.cWhite + "Left Click to use Hide Easter Egg",
C.blankLine,
"#" + C.cRed + C.Bold + "WARNING: " + ChatColor.RESET + "Hide Easter Egg uses " + SHARD_COST + " Shards",
C.blankLine,
C.cBlue + "Purchasable from mineplex.com/shop during Easter 2018."
}, LineFormat.LORE), CostConstants.NO_LORE, Material.MONSTER_EGG, UtilEnt.getEntityEggData(EntityType.RABBIT), ACTIVE_ITEM, "Switch Style", TimeUnit.SECONDS.toMillis(1));
}
@Override
public void enableCustom(final Player player, boolean message)
{
this.applyArmor(player, message);
applyArmor(player, message);
DisguiseRabbit disguise = new DisguiseRabbit(player);
UtilMorph.disguise(player, disguise, Manager);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999999, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 999999999, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 1, false, false));
}
@Override
public void disableCustom(Player player, boolean message)
{
_jumpCharge.remove(player);
this.removeArmor(player);
removeArmor(player);
UtilMorph.undisguise(player, Manager.getDisguiseManager());
player.removePotionEffect(PotionEffectType.SPEED);
player.removePotionEffect(PotionEffectType.JUMP);
}
@Override
public void onAbilityActivate(Player player)
{
DisguiseRabbit disguise = (DisguiseRabbit) Manager.getDisguiseManager().getActiveDisguise(player);
if (disguise != null)
{
Rabbit.Type newType = Rabbit.Type.values()[(disguise.getType().ordinal() + 1) % Rabbit.Type.values().length - 1];
disguise.setType(newType);
Manager.getDisguiseManager().updateDisguise(disguise);
String name = UtilText.capitalise(newType.toString().replace("_", " "));
player.sendMessage(F.main(Manager.getName(), "You are now " + (name.startsWith("The") ? "" : "a ") + F.name(name) + " Rabbit."));
}
}
@EventHandler
@ -96,22 +124,24 @@ public class MorphBunny extends MorphGadget
Player player = event.getPlayer();
if (!isActive(player))
{
return;
}
//Start
if (!event.getPlayer().isSneaking())
if (!player.isSneaking())
{
if (UtilEnt.isGrounded(event.getPlayer()))
_jumpCharge.add(event.getPlayer());
if (UtilEnt.isGrounded(player))
{
_jumpCharge.add(player);
}
}
//Jump
else if (_jumpCharge.remove(event.getPlayer()))
else if (_jumpCharge.remove(player))
{
float power = player.getExp();
player.setExp(0f);
UtilAction.velocity(player, power * 4, 0.4, 4, true);
UtilAction.velocity(player, player.getExp() * 4, 1, 10, true);
player.setExp(0);
player.getWorld().playSound(player.getLocation(), Sound.CAT_HIT, 0.75f, 2f);
}
}
@ -120,24 +150,21 @@ public class MorphBunny extends MorphGadget
public void jumpBoost(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<Player> jumpIter = _jumpCharge.iterator();
while (jumpIter.hasNext())
{
Player player = jumpIter.next();
return;
}
_jumpCharge.removeIf(player ->
{
if (!player.isValid() || !player.isOnline() || !player.isSneaking())
{
jumpIter.remove();
continue;
return true;
}
player.setExp(Math.min(0.9999f, player.getExp() + 0.03f));
player.playSound(player.getLocation(), Sound.FIZZ, 0.25f + player.getExp() * 0.5f, 0.5f + player.getExp());
}
player.setExp(Math.min(0.999F, player.getExp() + CHARGE_PER_TICK));
player.playSound(player.getLocation(), Sound.FIZZ, 0.25f + player.getExp() * 0.5f, player.getExp());
return false;
});
}
@EventHandler
@ -145,70 +172,58 @@ public class MorphBunny extends MorphGadget
{
Player player = event.getPlayer();
if (!isActive(player))
return;
if (!UtilEvent.isAction(event, ActionType.L))
return;
if (Manager.getDonationManager().Get(player).getBalance(GlobalCurrency.TREASURE_SHARD) < 500)
if (!UtilEvent.isAction(event, ActionType.L) || !isActive(player))
{
UtilPlayer.message(player, F.main("Gadget", "You do not have enough Shards."));
return;
}
if (!Recharge.Instance.use(player, "Hide Egg", 30000, true, false))
if (Manager.getDonationManager().Get(player).getBalance(GlobalCurrency.TREASURE_SHARD) < SHARD_COST)
{
player.sendMessage(F.main("Gadget", "You do not have enough Shards."));
return;
}
//Color
if (!Recharge.Instance.use(player, "Hide Egg", EGG_COOLDOWN, true, false))
{
return;
}
//Item
Location location = player.getEyeLocation();
ItemStack eggStack = ItemStackFactory.Instance.CreateStack(getDisplayMaterial(), getDisplayData(), 1, "Hidden Egg" + System.currentTimeMillis());
Item egg = player.getWorld().dropItem(player.getEyeLocation().add(player.getLocation().getDirection()), eggStack);
UtilAction.velocity(egg, player.getLocation().getDirection(), 0.2, false, 0, 0.2, 1, false);
Manager.getDonationManager().rewardCurrency(GlobalCurrency.TREASURE_SHARD, player, this.getName() + " Egg Hide", -500);
Item egg = player.getWorld().dropItem(location.add(location.getDirection()), eggStack);
egg.setPickupDelay(40);
UtilEnt.addFlag(egg, UtilEnt.FLAG_NO_REMOVE);
UtilAction.velocity(egg, location.getDirection(), 0.2, false, 0, 0.2, 1, false);
_eggs.put(egg, player.getName());
Manager.getDonationManager().rewardCurrency(GlobalCurrency.TREASURE_SHARD, player, getName() + " Egg Hide", -SHARD_COST);
_eggs.put(egg, player.getUniqueId());
//Announce
Bukkit.broadcastMessage(C.cYellow + C.Bold + player.getName() +
ChatColor.RESET + C.Bold + " hid an " +
C.cYellow + C.Bold + "Easter Egg" +
ChatColor.RESET + C.Bold + " worth " +
C.cYellow + C.Bold + "450 Shards");
for (Player other : UtilServer.getPlayers())
other.playSound(other.getLocation(), Sound.CAT_HIT, 1.5f, 1.5f);
Bukkit.broadcastMessage(C.cYellowB + player.getName() + C.cWhiteB + " hid an " + C.cYellowB + "Easter Egg" + C.cWhiteB + " worth " + C.cYellowB + "450 Shards");
player.getWorld().playSound(player.getLocation(), Sound.CAT_HIT, 1.5f, 1.5f);
}
@EventHandler
public void eggPickup(PlayerPickupItemEvent event)
{
if (_eggs.containsKey(event.getItem()) && !_eggs.get(event.getItem()).equals(event.getPlayer().getName()))
Player player = event.getPlayer();
Item item = event.getItem();
if (!player.getUniqueId().equals(_eggs.get(item)))
{
_eggs.remove(event.getItem());
_eggs.remove(item);
event.setCancelled(true);
event.getItem().remove();
item.remove();
Manager.getDonationManager().rewardCurrency(GlobalCurrency.TREASURE_SHARD, event.getPlayer(), getName() + " Egg Pickup", 450);
Manager.getDonationManager().rewardCurrency(GlobalCurrency.TREASURE_SHARD, player, getName() + " Egg Pickup", SHARD_REWARD);
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1.5f, 0.75f);
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1.5f, 1.25f);
Location location = player.getLocation();
location.getWorld().playSound(location, Sound.ORB_PICKUP, 1, 0.75F);
location.getWorld().playSound(location, Sound.ORB_PICKUP, 1, 1.25F);
UtilFirework.playFirework(event.getItem().getLocation(), Type.BURST, Color.YELLOW, true, true);
//Announce
Bukkit.broadcastMessage(C.cGold + C.Bold + event.getPlayer().getName() +
ChatColor.RESET + C.Bold + " found an " +
C.cGold + C.Bold + "Easter Egg" +
ChatColor.RESET + C.Bold + "! " + _eggs.size() + " Eggs left!");
UtilFirework.playFirework(item.getLocation(), Type.BURST, Color.YELLOW, true, true);
Bukkit.broadcastMessage(C.cGoldB + player.getName() + C.cWhiteB + " found an " + C.cGoldB + "Easter Egg" + C.cWhiteB + "! " + _eggs.size() + " Eggs left!");
}
}
@ -216,37 +231,21 @@ public class MorphBunny extends MorphGadget
public void eggClean(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
Iterator<Item> eggIter = _eggs.keySet().iterator();
while (eggIter.hasNext())
{
Item egg = eggIter.next();
if (!egg.isValid() || egg.getTicksLived() > 24000)
{
egg.remove();
eggIter.remove();
//Announce
Bukkit.broadcastMessage(
ChatColor.RESET + C.Bold + "No one found an " +
C.cGold + C.Bold + "Easter Egg" +
ChatColor.RESET + C.Bold + "! " + _eggs.size() + " Eggs left!");
}
else
{
UtilParticle.PlayParticle(ParticleType.SPELL, egg.getLocation().add(0, 0.1, 0), 0.1f, 0.1f, 0.1f, 0, 1,
ViewDist.NORMAL, UtilServer.getPlayers());
}
return;
}
}
@EventHandler
public void eggDespawnCancel(ItemDespawnEvent event)
{
if (_eggs.containsKey(event.getEntity()))
event.setCancelled(true);
_eggs.keySet().removeIf(item ->
{
if (!item.isValid() || item.getTicksLived() > ITEM_LIFE_TICKS)
{
item.remove();
Bukkit.broadcastMessage(C.cWhiteB + "No one found an " + C.cGoldB + "Easter Egg" + C.cWhiteB + "! " + _eggs.size() + " Eggs left!");
return true;
}
UtilParticle.PlayParticleToAll(ParticleType.SPELL, item.getLocation().add(0, 0.1, 0), 0.1F, 0.1F, 0.1F, 0, 1, ViewDist.NORMAL);
return false;
});
}
}