This commit is contained in:
LCastr0 2017-02-24 19:39:54 -03:00
parent 8088cef29f
commit a32cb6ab2f
4 changed files with 238 additions and 6 deletions

View File

@ -65,14 +65,14 @@ public class OutfitStPatricksSuit extends OutfitGadget
if (!setActive(event.getPlayer()))
return;
// Drops emeralds
// Drops gold
ItemStack itemStack = new ItemStack(Material.GOLD_INGOT);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName("DROPPED" + System.currentTimeMillis() + UtilMath.random.nextInt());
itemStack.setItemMeta(itemMeta);
Item emerald = event.getPlayer().getWorld().dropItem(event.getPlayer().getLocation().add(0.5, 1.5, 0.5), itemStack);
_items.add(emerald);
emerald.setVelocity(new Vector((Math.random()-0.5)*0.3, Math.random()-0.4, (Math.random()-0.5)*0.3));
Item gold = event.getPlayer().getWorld().dropItem(event.getPlayer().getLocation().add(0.5, 1.5, 0.5), itemStack);
_items.add(gold);
gold.setVelocity(new Vector((Math.random()-0.5)*0.3, Math.random()-0.4, (Math.random()-0.5)*0.3));
}
@EventHandler

View File

@ -35,6 +35,7 @@ import mineplex.core.mount.types.MountMule;
import mineplex.core.mount.types.MountNightmareSteed;
import mineplex.core.mount.types.MountSlime;
import mineplex.core.mount.types.MountSpider;
import mineplex.core.mount.types.MountStPatricksHorse;
import mineplex.core.mount.types.MountTitan;
import mineplex.core.mount.types.MountUndead;
import mineplex.core.mount.types.MountValentinesSheep;
@ -48,7 +49,7 @@ public class MountManager extends MiniPlugin
private DisguiseManager _disguiseManager;
private List<Mount<?>> _types;
private NautHashMap<Player, Mount<?>> _playerActiveMountMap = new NautHashMap<Player, Mount<?>>();
private NautHashMap<Player, Mount<?>> _playerActiveMountMap = new NautHashMap<>();
public MountManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, BlockRestore blockRestore, DisguiseManager disguiseManager)
{
@ -79,10 +80,10 @@ public class MountManager extends MiniPlugin
_types.add(new MountValentinesSheep(this));
_types.add(new MountFreedomHorse(this));
_types.add(new MountNightmareSteed(this));
// Hidden in this update
_types.add(new MountChicken(this));
_types.add(new MountCake(this));
_types.add(new MountLoveTrain(this));
_types.add(new MountStPatricksHorse(this));
//_types.add(new MountSheep(this));
}

View File

@ -0,0 +1,119 @@
package mineplex.core.mount.types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.HorseJumpEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
import mineplex.core.mount.HorseMount;
import mineplex.core.mount.MountManager;
import mineplex.core.mount.SingleEntityMountData;
import mineplex.core.particleeffects.RainbowTrailEffect;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class MountStPatricksHorse extends HorseMount
{
private HashSet<Item> _items = new HashSet<>();
private Map<SingleEntityMountData<Horse>, RainbowTrailEffect> _trailMap = new HashMap<>();
public MountStPatricksHorse(MountManager manager)
{
super(manager, "St Patrick's Mount",
UtilText.splitLineToArray(UtilText.colorWords("The British might be coming, but with this impressive mount you have nothing to fear.",
ChatColor.RED, ChatColor.WHITE, ChatColor.BLUE), LineFormat.LORE),
Material.FIREWORK, (byte) 0, -7, Horse.Color.WHITE, Horse.Style.WHITE, Horse.Variant.HORSE, 1, null);
}
@Override
public void enableCustom(Player player)
{
super.enableCustom(player);
SingleEntityMountData<Horse> horseData = getActive().get(player);
horseData.getEntity().getInventory().setArmor(new ItemStack(Material.GOLD_BARDING));
_trailMap.put(horseData, new RainbowTrailEffect(horseData.getEntity(), Manager.getPlugin(), _items));
_trailMap.get(horseData).start();
}
@Override
public void disable(Player player)
{
super.disable(player);
List<SingleEntityMountData<Horse>> toRemove = new ArrayList<>();
for (SingleEntityMountData<Horse> horseData : _trailMap.keySet())
{
if (horseData.getOwner().equals(player))
toRemove.add(horseData);
}
for (SingleEntityMountData<Horse> horseData : toRemove)
{
_trailMap.get(horseData).stop();
_trailMap.remove(horseData);
}
}
@EventHandler
public void horseJump(HorseJumpEvent event)
{
for (SingleEntityMountData<Horse> horseData : _trailMap.keySet())
{
if (horseData.getEntity().equals(event.getEntity()))
{
if (!Recharge.Instance.use(horseData.getOwner(), getName(), 2500, false, false, "Cosmetics"))
{
event.setPower(0f);
event.setCancelled(true);
return;
}
_trailMap.get(horseData).setJumping(true);
}
}
}
@EventHandler
public void onItemPickup(PlayerPickupItemEvent event)
{
if (_items.contains(event.getItem()))
{
event.setCancelled(true);
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() == UpdateType.TICK)
cleanItems();
}
public void cleanItems()
{
Iterator<Item> it = _items.iterator();
while (it.hasNext())
{
Item item = it.next();
if (item.getTicksLived() >= 20)
{
item.remove();
it.remove();
}
}
}
}

View File

@ -0,0 +1,112 @@
package mineplex.core.particleeffects;
import java.awt.Color;
import java.util.HashSet;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
public class RainbowTrailEffect extends Effect
{
private HashSet<Item> _items;
private Color _color = Color.RED;
private long _count, _jumpingTimer = 0;
private boolean _isJumping = false;
private Entity _entity;
private Color _red = new Color(255, 0, 0);
private Color _orange = new Color(255, 127, 0);
private Color _yellow = new Color(255, 255, 0);
private Color _green = new Color(0, 255, 0);
private Color _blue = new Color(0, 0, 255);
private Color _indigo = new Color(75, 0, 130);
private Color _violet = new Color(143, 0, 255);
public RainbowTrailEffect(Entity entity, JavaPlugin javaPlugin, HashSet<Item> items)
{
super(-1, new EffectLocation(entity), javaPlugin);
_entity = entity;
_items = items;
}
@Override
public void runEffect()
{
if (!_entity.isValid() || _entity.isDead())
{
stop();
return;
}
ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST,
new DustSpellColor(_color), _effectLocation.getLocation().clone().add(0, .5, 0));
for (int i = 0; i < 7; i++)
{
coloredParticle.setLocation(_effectLocation.getLocation().clone().add(0, .5, 0));
coloredParticle.display();
if (_isJumping)
{
coloredParticle.setLocation(_effectLocation.getLocation().clone().add(.25, .5, 0));
coloredParticle.display();
coloredParticle.setLocation(_effectLocation.getLocation().clone().add(0, .5, .25));
coloredParticle.display();
}
}
if (_isJumping)
{
_jumpingTimer++;
if (_jumpingTimer >= 30)
{
setJumping(false);
_jumpingTimer = 0;
}
}
_count++;
if (_count % 5 == 0)
{
if (_color.equals(_red))
_color = _orange;
else if (_color.equals(_orange))
_color = _yellow;
else if (_color.equals(_yellow))
_color = _green;
else if (_color.equals(_green))
_color = _blue;
else if (_color.equals(_blue))
_color = _indigo;
else if (_color.equals(_indigo))
_color = _violet;
else
_color = _red;
}
if (_count == Long.MAX_VALUE - 1)
_count = 0;
}
public void setJumping(boolean jumping)
{
_isJumping = jumping;
if (_isJumping)
{
ItemStack itemStack = new ItemStack(Material.GOLD_INGOT);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName("DROPPED" + System.currentTimeMillis() + UtilMath.random.nextInt());
itemStack.setItemMeta(itemMeta);
Item gold = _entity.getWorld().dropItem(_entity.getLocation().add(0.5, 1.5, 0.5), itemStack);
_items.add(gold);
gold.setVelocity(new Vector((Math.random()-0.5)*0.3, Math.random()-0.4, (Math.random()-0.5)*0.3));
}
}
}