mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-16 12:26:12 +00:00
Automatically despawn item entities after some time. Resolves #901
This commit is contained in:
parent
c885bbb144
commit
662cef44d5
@ -29,6 +29,7 @@ import org.bukkit.entity.ThrownPotion;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -37,7 +38,8 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
public class EntityWiper extends FreedomService
|
public class EntityWiper extends FreedomService
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final long WIPE_RATE = 5 * 20L;
|
public static final long ENTITY_WIPE_RATE = 5 * 20L;
|
||||||
|
public static final long ITEM_DESPAWN_RATE = 20L * 20L;
|
||||||
public static final int CHUNK_ENTITY_MAX = 30;
|
public static final int CHUNK_ENTITY_MAX = 30;
|
||||||
//
|
//
|
||||||
private final List<Class<? extends Entity>> wipables = new ArrayList<>();
|
private final List<Class<? extends Entity>> wipables = new ArrayList<>();
|
||||||
@ -78,7 +80,7 @@ public class EntityWiper extends FreedomService
|
|||||||
{
|
{
|
||||||
wipeEntities();
|
wipeEntities();
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, WIPE_RATE, WIPE_RATE);
|
}.runTaskTimer(plugin, ENTITY_WIPE_RATE, ENTITY_WIPE_RATE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,22 +174,21 @@ public class EntityWiper extends FreedomService
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onContainerBreak(BlockBreakEvent event)
|
public void onItemSpawn(ItemSpawnEvent event)
|
||||||
{
|
{
|
||||||
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
final Item entity = event.getEntity();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockState state = event.getBlock().getState();
|
new BukkitRunnable()
|
||||||
if (!(state instanceof InventoryHolder))
|
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Inventory inv = ((InventoryHolder) state).getInventory();
|
@Override
|
||||||
inv.clear();
|
public void run()
|
||||||
|
{
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, ITEM_DESPAWN_RATE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user