prozza gay

This commit is contained in:
Super_ 2019-12-23 22:26:40 -05:00
parent 1dc2bd8518
commit 1bc06f2c1d
4 changed files with 23 additions and 217 deletions

View File

@ -1,213 +0,0 @@
package me.totalfreedom.totalfreedommod;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Boat;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.EnderCrystal;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Explosive;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownExpBottle;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public class EntityWiper extends FreedomService
{
@Getter
private boolean enabled;
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 = 20;
//
private final List<Class<? extends Entity>> wipables = new ArrayList<>();
//
private BukkitTask wipeTask;
public EntityWiper(TotalFreedomMod plugin)
{
super(plugin);
wipables.add(EnderCrystal.class);
wipables.add(EnderSignal.class);
wipables.add(EnderPearl.class);
wipables.add(ExperienceOrb.class);
wipables.add(Projectile.class);
wipables.add(FallingBlock.class);
wipables.add(Firework.class);
wipables.add(Item.class);
wipables.add(ThrownPotion.class);
wipables.add(ThrownExpBottle.class);
wipables.add(AreaEffectCloud.class);
wipables.add(Minecart.class);
wipables.add(Boat.class);
wipables.add(FallingBlock.class);
wipables.add(ArmorStand.class);
wipables.add(Fireball.class);
wipables.add(DragonFireball.class);
wipables.add(Minecart.class);
}
@Override
protected void onStart()
{
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
{
return;
}
wipeTask = new BukkitRunnable()
{
@Override
public void run()
{
wipeEntities(false);
}
}.runTaskTimer(plugin, ENTITY_WIPE_RATE, ENTITY_WIPE_RATE);
}
@Override
protected void onStop()
{
FUtil.cancel(wipeTask);
wipeTask = null;
}
public boolean isWipeable(Entity entity)
{
for (Class<? extends Entity> c : wipables)
{
if (c.isAssignableFrom(entity.getClass()))
{
return true;
}
}
return false;
}
public int wipeEntities(boolean force)
{
int removed = 0;
Iterator<World> worlds = Bukkit.getWorlds().iterator();
while (worlds.hasNext())
{
removed += wipeEntities(worlds.next(), force);
}
return removed;
}
public int wipeEntities(World world, boolean force)
{
int removed = 0;
boolean wipeExpl = !ConfigEntry.ALLOW_EXPLOSIONS.getBoolean();
Iterator<Entity> entities = world.getEntities().iterator();
// Organise the entities in the world
Map<Chunk, List<Entity>> cem = new HashMap<>();
while (entities.hasNext())
{
final Entity entity = entities.next();
// Explosives
if (wipeExpl && Explosive.class.isAssignableFrom(entity.getClass()))
{
entity.remove();
removed++;
}
// Only wipeable entities can be wiped (duh!)
if (!isWipeable(entity))
{
continue;
}
Chunk c = entity.getLocation().getChunk();
List<Entity> cel = cem.get(c);
if (cel == null)
{
cem.put(c, new ArrayList<>(Arrays.asList(entity)));
}
else
{
cel.add(entity);
}
}
// Now purge the entities if necessary
for (Chunk c : cem.keySet())
{
List<Entity> cel = cem.get(c);
if (!force && cel.size() < CHUNK_ENTITY_MAX)
{
continue;
}
// Too many entities in this chunk, wipe them all
for (Entity e : cel)
{
e.remove();
removed++;
}
}
return removed;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event)
{
final Item entity = event.getEntity();
new BukkitRunnable()
{
@Override
public void run()
{
entity.remove();
}
}.runTaskLater(plugin, ITEM_DESPAWN_RATE);
}
@EventHandler
public void onDrop(PlayerDropItemEvent event)
{
enabled = ConfigEntry.AUTO_ENTITY_WIPE.getBoolean();
if (enabled)
{
event.setCancelled(true);
}
}
}

View File

@ -113,7 +113,6 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public AutoEject ae; public AutoEject ae;
public Monitors mo; public Monitors mo;
public MovementValidator mv; public MovementValidator mv;
public EntityWiper ew;
public ServerPing sp; public ServerPing sp;
public CurseListener cul; public CurseListener cul;
public ItemFun it; public ItemFun it;
@ -228,7 +227,6 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
mv = services.registerService(MovementValidator.class); mv = services.registerService(MovementValidator.class);
ew = services.registerService(EntityWiper.class);
sp = services.registerService(ServerPing.class); sp = services.registerService(ServerPing.class);
pv = services.registerService(PlayerVerification.class); pv = services.registerService(PlayerVerification.class);

View File

@ -2,8 +2,11 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@ -15,7 +18,16 @@ public class Command_entitywipe extends FreedomCommand
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
FUtil.adminAction(sender.getName(), "Removing all server entities", true); FUtil.adminAction(sender.getName(), "Removing all server entities", true);
msg((plugin.ew.wipeEntities(true)) + " entities removed."); int removed = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getEntities())
{
entity.remove();
removed++;
}
}
msg(removed + " entities removed.");
return true; return true;
} }

View File

@ -3,8 +3,11 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -19,7 +22,13 @@ public class Command_purgeall extends FreedomCommand
FUtil.adminAction(sender.getName(), "Purging all player data", true); FUtil.adminAction(sender.getName(), "Purging all player data", true);
// Purge entities // Purge entities
plugin.ew.wipeEntities(true); for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getEntities())
{
entity.remove();
}
}
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {