mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Merge branch 'master' of https://github.com/TotalFreedom/TotalFreedomMod
This commit is contained in:
commit
c1d0c01524
@ -1,5 +1,5 @@
|
||||
#Mon, 12 Aug 2013 12:49:58 +0200
|
||||
#Mon, 12 Aug 2013 17:57:31 +0200
|
||||
|
||||
program.VERSION=2.22
|
||||
program.BUILDNUM=403
|
||||
program.BUILDDATE=08/12/2013 12\:49 PM
|
||||
program.BUILDNUM=406
|
||||
program.BUILDDATE=08/12/2013 05\:57 PM
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Mon Aug 12 12:49:58 CEST 2013
|
||||
build.number=404
|
||||
#Mon Aug 12 17:57:31 CEST 2013
|
||||
build.number=407
|
||||
|
@ -0,0 +1,27 @@
|
||||
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)
|
||||
{
|
||||
if (sender_p.getWorld() == TFM_AdminWorld.getInstance().getAdminWorld())
|
||||
{
|
||||
playerMsg("Going to the main world.");
|
||||
sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Going to the AdminWorld.");
|
||||
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++;
|
||||
}
|
||||
|
@ -216,6 +216,11 @@ public class TFM_PlayerListener implements Listener
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (!TFM_AdminWorld.getInstance().validateMovement(event))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = event.getPlayer();
|
||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
|
||||
|
||||
@ -471,7 +476,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;
|
||||
|
136
src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java
Normal file
136
src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java
Normal file
@ -0,0 +1,136 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TFM_AdminWorld
|
||||
{
|
||||
private static final String GENERATION_PARAMETERS = "16,stone,32,dirt,1,grass";
|
||||
private static final String ADMINWORLD_NAME = "adminworld";
|
||||
private final Map<CommandSender, Boolean> superadminCache = new HashMap<CommandSender, Boolean>();
|
||||
private Long cacheLastCleared = null;
|
||||
private World adminWorld = null;
|
||||
|
||||
private TFM_AdminWorld()
|
||||
{
|
||||
}
|
||||
|
||||
public void sendToAdminWorld(Player player)
|
||||
{
|
||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
loadAdminWorld();
|
||||
|
||||
player.teleport(adminWorld.getSpawnLocation());
|
||||
}
|
||||
|
||||
public boolean validateMovement(PlayerMoveEvent event)
|
||||
{
|
||||
if (adminWorld != null)
|
||||
{
|
||||
if (event.getTo().getWorld() == adminWorld)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
if (!cachedIsUserSuperadmin(player))
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, 20L);
|
||||
event.setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void loadAdminWorld()
|
||||
{
|
||||
if (adminWorld == null || !Bukkit.getWorlds().contains(adminWorld))
|
||||
{
|
||||
generateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
public World getAdminWorld()
|
||||
{
|
||||
return adminWorld;
|
||||
}
|
||||
|
||||
private boolean cachedIsUserSuperadmin(CommandSender user)
|
||||
{
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
if (cacheLastCleared == null || cacheLastCleared.longValue() >= currentTimeMillis + (10L * 1000L)) // Wipe every 10 seconds.
|
||||
{
|
||||
cacheLastCleared = currentTimeMillis;
|
||||
superadminCache.clear();
|
||||
}
|
||||
|
||||
Boolean cached = superadminCache.get(user);
|
||||
if (cached == null)
|
||||
{
|
||||
cached = TFM_SuperadminList.isUserSuperadmin(user);
|
||||
superadminCache.put(user, cached);
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
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);
|
||||
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState();
|
||||
|
||||
org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData();
|
||||
signData.setFacingDirection(BlockFace.NORTH);
|
||||
|
||||
welcomeSign.setLine(0, ChatColor.GREEN + "AdminWorld");
|
||||
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
|
||||
welcomeSign.setLine(2, ChatColor.YELLOW + "Spawn Point");
|
||||
welcomeSign.setLine(3, ChatColor.DARK_GRAY + "---");
|
||||
welcomeSign.update();
|
||||
|
||||
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)
|
||||
|
@ -83,6 +83,8 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
TFM_Util.generateFlatlands(flatlandsGenerationParams);
|
||||
}
|
||||
|
||||
TFM_AdminWorld.getInstance().loadAdminWorld();
|
||||
|
||||
if (disableWeather)
|
||||
{
|
||||
for (World world : server.getWorlds())
|
||||
|
Loading…
Reference in New Issue
Block a user