mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-08-21 09:31:45 +00:00
Incomplete features:
-Adminworld -Better entity wiping
This commit is contained in:
parent
38b1035020
commit
326c3f6a2b
|
@ -1,5 +1,5 @@
|
|||
#Sat, 10 Aug 2013 15:43:16 -0400
|
||||
#Sun, 11 Aug 2013 21:06:54 -0400
|
||||
|
||||
program.VERSION=2.22
|
||||
program.BUILDNUM=392
|
||||
program.BUILDDATE=08/10/2013 03\:43 PM
|
||||
program.BUILDNUM=396
|
||||
program.BUILDDATE=08/11/2013 09\:06 PM
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#Build Number for ANT. Do not edit!
|
||||
#Sat Aug 10 15:43:16 EDT 2013
|
||||
build.number=393
|
||||
#Sun Aug 11 21:06:54 EDT 2013
|
||||
build.number=397
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command>")
|
||||
public class Command_adminworld extends TFM_Command
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
TFM_AdminWorld.getInstance().sendToAdminWorld(sender_p);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ public class Command_purgeall extends TFM_Command
|
|||
TFM_Util.adminAction(sender.getName(), "Purging all player data", true);
|
||||
|
||||
// Purge entities
|
||||
TFM_Util.wipeEntities(true, true);
|
||||
TFM_Util.TFM_EntityWiper.wipeEntities(true, true);
|
||||
|
||||
// Undisguise all players
|
||||
TFM_DisguiseCraftBridge.undisguiseAllPlayers();
|
||||
|
|
|
@ -13,7 +13,7 @@ public class Command_rd extends TFM_Command
|
|||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Removing all server entities.", true);
|
||||
playerMsg((TFM_Util.wipeEntities(true, true)) + " enties removed.");
|
||||
playerMsg((TFM_Util.TFM_EntityWiper.wipeEntities(true, true)) + " enties removed.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class Command_trail extends TFM_Command
|
|||
trailPlayers.add(sender_p);
|
||||
}
|
||||
|
||||
playerMsg("Trail enabled!");
|
||||
playerMsg("Trail enabled. Use \"/trail off\" to disable.");
|
||||
}
|
||||
|
||||
if (!trailPlayers.isEmpty())
|
||||
|
|
|
@ -125,9 +125,9 @@ public class TFM_EntityListener implements Listener
|
|||
{
|
||||
int mobcount = 0;
|
||||
|
||||
for (Entity ent : event.getLocation().getWorld().getLivingEntities())
|
||||
for (Entity entity : event.getLocation().getWorld().getLivingEntities())
|
||||
{
|
||||
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon)
|
||||
if (!(entity instanceof HumanEntity))
|
||||
{
|
||||
mobcount++;
|
||||
}
|
||||
|
|
|
@ -466,7 +466,7 @@ public class TFM_PlayerListener implements Listener
|
|||
|
||||
playerdata.resetMsgCount();
|
||||
|
||||
TFM_Util.wipeEntities(true, true);
|
||||
TFM_Util.TFM_EntityWiper.wipeEntities(true, true);
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -641,4 +641,10 @@ public class TFM_PlayerListener implements Listener
|
|||
{
|
||||
TFM_ServerInterface.handlePlayerLogin(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
TFM_AdminWorld.getInstance().validateTeleport(event);
|
||||
}
|
||||
}
|
||||
|
|
87
src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java
Normal file
87
src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
public class TFM_AdminWorld
|
||||
{
|
||||
private static final String GENERATION_PARAMETERS = "16,stone,32,dirt,1,grass";
|
||||
private static final String ADMINWORLD_NAME = "adminworld";
|
||||
private World adminWorld = null;
|
||||
|
||||
private TFM_AdminWorld()
|
||||
{
|
||||
}
|
||||
|
||||
public void sendToAdminWorld(Player player)
|
||||
{
|
||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (adminWorld == null || !Bukkit.getWorlds().contains(adminWorld))
|
||||
{
|
||||
generateWorld();
|
||||
}
|
||||
|
||||
player.teleport(adminWorld.getSpawnLocation());
|
||||
}
|
||||
|
||||
public void validateTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
if (adminWorld == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getTo().getWorld() == adminWorld)
|
||||
{
|
||||
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateWorld()
|
||||
{
|
||||
WorldCreator adminWorldCreator = new WorldCreator(ADMINWORLD_NAME);
|
||||
adminWorldCreator.generateStructures(false);
|
||||
adminWorldCreator.type(WorldType.NORMAL);
|
||||
adminWorldCreator.environment(World.Environment.NORMAL);
|
||||
adminWorldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS));
|
||||
|
||||
adminWorld = Bukkit.getServer().createWorld(adminWorldCreator);
|
||||
|
||||
adminWorld.setSpawnFlags(false, false);
|
||||
adminWorld.setSpawnLocation(0, 50, 0);
|
||||
|
||||
Block welcomeSignBlock = adminWorld.getBlockAt(0, 50, 0);
|
||||
welcomeSignBlock.setType(Material.SIGN_POST);
|
||||
Sign welcomeSign = (Sign) welcomeSignBlock.getState();
|
||||
welcomeSign.setLine(0, "AdminWorld");
|
||||
welcomeSign.setLine(1, "");
|
||||
welcomeSign.setLine(2, "");
|
||||
welcomeSign.setLine(3, "");
|
||||
|
||||
TFM_GameRuleHandler.commitGameRules();
|
||||
}
|
||||
|
||||
public static TFM_AdminWorld getInstance()
|
||||
{
|
||||
return TFM_AdminWorldHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class TFM_AdminWorldHolder
|
||||
{
|
||||
private static final TFM_AdminWorld INSTANCE = new TFM_AdminWorld();
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ public class TFM_Heartbeat extends BukkitRunnable
|
|||
|
||||
if (TotalFreedomMod.autoEntityWipe)
|
||||
{
|
||||
TFM_Util.wipeEntities(!TotalFreedomMod.allowExplosions, false);
|
||||
TFM_Util.TFM_EntityWiper.wipeEntities(!TotalFreedomMod.allowExplosions, false);
|
||||
}
|
||||
|
||||
if (TotalFreedomMod.disableWeather)
|
||||
|
|
|
@ -234,25 +234,81 @@ public class TFM_Util
|
|||
}
|
||||
}
|
||||
|
||||
public static int wipeEntities(boolean wipe_explosives, boolean wipe_vehicles)
|
||||
public static class TFM_EntityWiper
|
||||
{
|
||||
int removed = 0;
|
||||
for (World world : Bukkit.getWorlds())
|
||||
private static final List<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();
|
||||
|
||||
static
|
||||
{
|
||||
for (Entity ent : world.getEntities())
|
||||
WIPEABLES.add(EnderCrystal.class);
|
||||
WIPEABLES.add(EnderSignal.class);
|
||||
WIPEABLES.add(ExperienceOrb.class);
|
||||
WIPEABLES.add(Projectile.class);
|
||||
WIPEABLES.add(FallingBlock.class);
|
||||
WIPEABLES.add(Firework.class);
|
||||
WIPEABLES.add(Item.class);
|
||||
}
|
||||
|
||||
private TFM_EntityWiper()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
private static boolean canWipe(Entity entity, boolean wipeExplosives, boolean wipeVehicles)
|
||||
{
|
||||
if (wipeExplosives)
|
||||
{
|
||||
if (ent instanceof Projectile
|
||||
|| ent instanceof Item
|
||||
|| ent instanceof ExperienceOrb
|
||||
|| (ent instanceof Explosive && wipe_explosives)
|
||||
|| (ent instanceof Vehicle && wipe_vehicles))
|
||||
if (Explosive.class.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
ent.remove();
|
||||
removed++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (wipeVehicles)
|
||||
{
|
||||
if (Boat.class.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (Minecart.class.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Class<? extends Entity>> it = WIPEABLES.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
if (it.next().isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int wipeEntities(boolean wipeExplosives, boolean wipeVehicles)
|
||||
{
|
||||
int removed = 0;
|
||||
|
||||
Iterator<World> worlds = Bukkit.getWorlds().iterator();
|
||||
while (worlds.hasNext())
|
||||
{
|
||||
Iterator<Entity> entities = worlds.next().getEntities().iterator();
|
||||
while (entities.hasNext())
|
||||
{
|
||||
Entity entity = entities.next();
|
||||
if (canWipe(entity, wipeExplosives, wipeVehicles))
|
||||
{
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
public static boolean deleteFolder(File file)
|
||||
|
|
Loading…
Reference in a new issue