optimized item cleaning
This commit is contained in:
parent
a1ba0f6d86
commit
ade76791b3
@ -5,6 +5,8 @@ import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
@ -301,6 +303,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
_animation.itemClean();
|
||||
|
||||
if(_canVote)
|
||||
return;
|
||||
|
||||
@ -328,7 +332,6 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
creeper.getWorld().playSound(creeper.getLocation(), Sound.EXPLODE, 2f, 1f);
|
||||
_animation.setType(_pendingExplosions.get(0));
|
||||
_animation.setPlayer(_pendingExplosionsPlayers.get(0));
|
||||
_animation.setTime(System.currentTimeMillis());
|
||||
_animation.setRunning(true);
|
||||
}
|
||||
|
||||
@ -992,32 +995,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
return _pollManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ItemDecay(UpdateEvent event)
|
||||
{
|
||||
if(event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for(Entity entity : _carlNpc.getEntity().getNearbyEntities(10, -0.5, 10))
|
||||
{
|
||||
if(!(entity instanceof Item))
|
||||
continue;
|
||||
|
||||
if(!((Item)entity).getItemStack().hasItemMeta())
|
||||
entity.remove();
|
||||
|
||||
if(((Item)entity).getItemStack().hasItemMeta() && !((Item)entity).getItemStack().getItemMeta().getDisplayName().startsWith("Hidden"))
|
||||
entity.remove();
|
||||
|
||||
if(!((Item) entity).getItemStack().hasItemMeta())
|
||||
continue;
|
||||
|
||||
if(!((Item) entity).getItemStack().getItemMeta().getDisplayName().startsWith(" "))
|
||||
continue;
|
||||
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void Join(final PlayerJoinEvent event)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.core.bonuses.animations;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
@ -13,6 +15,8 @@ import mineplex.core.reward.Reward;
|
||||
import mineplex.core.reward.RewardData;
|
||||
import mineplex.core.reward.RewardRarity;
|
||||
import mineplex.core.treasure.animation.Animation;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
@ -23,19 +27,19 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class AnimationCarl extends Animation
|
||||
{
|
||||
|
||||
private boolean _isDone;
|
||||
private Block _creeper;
|
||||
private long _startTime;
|
||||
private Object _type;
|
||||
private Player _player;
|
||||
private Random _random = new Random();
|
||||
|
||||
private HashSet<Item> _items = new HashSet<Item>();
|
||||
|
||||
public AnimationCarl(Entity creeper)
|
||||
{
|
||||
@ -53,6 +57,9 @@ public class AnimationCarl extends Animation
|
||||
{
|
||||
Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i));
|
||||
Item coin = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.DOUBLE_PLANT, (byte) 0, 1, " " + i));
|
||||
_items.add(gem);
|
||||
_items.add(coin);
|
||||
|
||||
Vector vel = new Vector(Math.sin(i * 9/5d), 0, Math.cos(i * 9/5d));
|
||||
UtilAction.velocity(gem, vel, Math.abs(Math.sin(i * 12/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i * 12/3000d))*0.6, 1, false);
|
||||
UtilAction.velocity(coin, vel, Math.abs(Math.sin(UtilMath.r(i) * 30/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 30/3000d))*0.6, 1, false);
|
||||
@ -65,6 +72,8 @@ public class AnimationCarl extends Animation
|
||||
for (int i = 50; i < 60; i++)
|
||||
{
|
||||
Item coin = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.DOUBLE_PLANT, (byte) 0, 1, " " + i));
|
||||
_items.add(coin);
|
||||
|
||||
Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d));
|
||||
UtilAction.velocity(coin, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false);
|
||||
coin.setTicksLived(1160);
|
||||
@ -74,12 +83,16 @@ public class AnimationCarl extends Animation
|
||||
{
|
||||
|
||||
Item paper = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PAPER, (byte) 0, 1, " " + 64));
|
||||
_items.add(paper);
|
||||
|
||||
Vector vel = new Vector(Math.sin(64 * 8/5d), 0, Math.cos(64 * 8/5d));
|
||||
UtilAction.velocity(paper, vel, Math.abs(Math.sin(64 * 9/3000d)), false, 0, 0.2 + Math.abs(Math.cos(64 + 9/3000d))*0.6, 1, false);
|
||||
paper.setTicksLived(1160);
|
||||
for (int i = 50; i < 60; i++)
|
||||
{
|
||||
Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i));
|
||||
_items.add(gem);
|
||||
|
||||
Vector velo = new Vector(Math.sin(i * 8/5d), 0, Math.cos(i * 8/5d));
|
||||
UtilAction.velocity(gem, velo, Math.abs(Math.sin(i * 8/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i + 8/3000d))*0.6, 1, false);
|
||||
gem.setTicksLived(1160);
|
||||
@ -94,12 +107,11 @@ public class AnimationCarl extends Animation
|
||||
RewardData rewardData = ((Reward)_type).getFakeRewardData(_player);
|
||||
ItemStack itemStack = rewardData.getDisplayItem();
|
||||
Item item = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.7, 0.5), itemStack);
|
||||
_items.add(item);
|
||||
|
||||
Vector vel = new Vector(_player.getLocation().getX() - _creeper.getLocation().getX(), 0, _player.getLocation().getZ() - _creeper.getLocation().getZ());
|
||||
|
||||
UtilAction.velocity(item, vel, 0.1, false, 0, 0.2 + 1*0.4, 1, false);
|
||||
|
||||
item.setTicksLived(1160);
|
||||
}
|
||||
|
||||
if(((Reward)_type).getRarity() == RewardRarity.RARE)
|
||||
@ -137,11 +149,6 @@ public class AnimationCarl extends Animation
|
||||
_isDone = b;
|
||||
}
|
||||
|
||||
public void setTime(long time)
|
||||
{
|
||||
_startTime = time;
|
||||
}
|
||||
|
||||
public void setType(Object type)
|
||||
{
|
||||
_type = type;
|
||||
@ -265,4 +272,20 @@ public class AnimationCarl extends Animation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void itemClean()
|
||||
{
|
||||
Iterator<Item> itemIterator = _items.iterator();
|
||||
|
||||
while (itemIterator.hasNext())
|
||||
{
|
||||
Item item = itemIterator.next();
|
||||
|
||||
if (item.isOnGround() || !item.isValid() || item.getTicksLived() > 60)
|
||||
{
|
||||
item.remove();
|
||||
itemIterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user