diff --git a/appinfo.properties b/appinfo.properties index 142b7d78..25b20e4b 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,6 +1,5 @@ -#Fri, 09 Aug 2013 17:04:56 +0200 - -program.VERSION=2.21 -program.BUILDNUM=384 -program.BUILDDATE=08/09/2013 05\:04 PM +#Fri, 09 Aug 2013 15:38:23 +0200 +program.VERSION=2.22 +program.BUILDNUM=378 +program.BUILDDATE=08/09/2013 03\:38 PM diff --git a/buildnumber.properties b/buildnumber.properties index 47f88459..e221c716 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Fri Aug 09 17:04:56 CEST 2013 -build.number=385 +#Fri Aug 09 15:38:23 CEST 2013 +build.number=379 diff --git a/src/config.yml b/src/config.yml index fcae6030..2e4c125b 100644 --- a/src/config.yml +++ b/src/config.yml @@ -1,4 +1,4 @@ -# TotalFreedomMod v2.21 Configuration +# TotalFreedomMod v2.22 Configuration # by Madgeek1450 and DarthSalamon # Block placement prevention: diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java index 263e6287..75d57135 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java @@ -48,7 +48,7 @@ public class Command_gtfo extends TFM_Command TFM_WorldEditBridge.getInstance().undo(p, 15); // rollback - TFM_RollbackManager.rollback(p); + TFM_RollbackManager.rollback(p.getName()); // deop p.setOp(false); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java index 2ebc7ab1..e33323ea 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java @@ -1,8 +1,15 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import java.text.DecimalFormat; +import me.StevenLawson.TotalFreedomMod.TFM_Log; +import me.StevenLawson.TotalFreedomMod.TFM_TickMeter; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import org.apache.commons.lang.exception.ExceptionUtils; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; @CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) @CommandParameters(description = "View ticks-per-second", usage = "/") @@ -11,39 +18,45 @@ public class Command_health extends TFM_Command @Override public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { -// -- MADGEEK: This is not thread safe. It needs to be rewritten using proper Bukkit scheduler API. -// -// Runnable task; -// task = new Runnable() // async -// { -// @Override -// public void run() -// { -// try -// { -// TFM_TickMeter meter = new TFM_TickMeter(plugin); -// meter.startTicking(); -// Thread.sleep(1000); // per second -// meter.stopTicking(); -// -// Runtime runtime = Runtime.getRuntime(); -// int mb = 1048576; // 1024 * 1024 -// -// float usedMem = runtime.totalMemory() - runtime.freeMemory(); -// -// playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb"); -// playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format(usedMem / runtime.totalMemory() * 100) + "%)"); -// playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb"); -// playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks()); -// } -// catch (Exception iex) -// { -// TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process."); -// TFM_Log.warning(ExceptionUtils.getStackTrace(iex)); -// } -// } -// }; -// new Thread(task, "TickMeter").start(); + + new BukkitRunnable() + { + + @Override + public void run() + { + try + { + final TFM_TickMeter meter = new TFM_TickMeter(plugin); + meter.startTicking(); + Thread.sleep(1000); // per second + meter.stopTicking(); + + final Runtime runtime = Runtime.getRuntime(); + final int mb = 1048576; // 1024 * 1024 + + final float usedMem = runtime.totalMemory() - runtime.freeMemory(); + + new BukkitRunnable() + { + @Override + public void run() { + playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb"); + playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format((usedMem / runtime.totalMemory()) * 100) + "%)"); + playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb"); + playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks()); + } + }.runTask(TotalFreedomMod.plugin); + } + catch (Exception iex) + { + TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process."); + TFM_Log.warning(ExceptionUtils.getStackTrace(iex)); + } + } + + }.runTaskAsynchronously(TotalFreedomMod.plugin); + return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java index ff0ed949..dbf31568 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java @@ -22,7 +22,7 @@ public class Command_purgeall extends TFM_Command TFM_Util.wipeEntities(true, true); // Undisguise all players - TFM_DisguiseCraftBridge.getInstance().undisguiseAllPlayers(); + TFM_DisguiseCraftBridge.undisguiseAllPlayers(); for (Player p : server.getOnlinePlayers()) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java index 3bc540ff..a2bc5053 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java @@ -2,8 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_RadarData; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; @@ -71,4 +71,39 @@ public class Command_radar extends TFM_Command return true; } + + private class TFM_RadarData implements Comparator + { + public Player player; + public double distance; + public Location location; + + public TFM_RadarData(Player player, double distance, Location location) + { + this.player = player; + this.distance = distance; + this.location = location; + } + + public TFM_RadarData() + { + } + + @Override + public int compare(TFM_RadarData t1, TFM_RadarData t2) + { + if (t1.distance > t2.distance) + { + return 1; + } + else if (t1.distance < t2.distance) + { + return -1; + } + else + { + return 0; + } + } + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java index 69cf92ed..c27169a5 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java @@ -1,9 +1,8 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; +import me.StevenLawson.TotalFreedomMod.TFM_UserList; import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,74 +14,61 @@ public class Command_rollback extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length > 2) + if (args.length == 1) { - return false; - } - - if (args.length == 1 && args[0].equalsIgnoreCase("purgeall")) - { - TFM_Util.adminAction(sender.getName(), "Puring all rollback data", false); - playerMsg("Purged entries for " + TFM_RollbackManager.purgeEntries() + " players."); - return true; - } - - if (args.length == 2 && args[0].equalsIgnoreCase("purge")) - { - OfflinePlayer p; - try + if (args[0].equalsIgnoreCase("purgeall")) { - p = getPlayer(args[1]); - } - catch (CantFindPlayerException ex) - { - p = server.getOfflinePlayer(args[1]); - if (!p.hasPlayedBefore()) - { - playerMsg("Player is not online, or never joined the server.", ChatColor.RED); - return true; - } - } - - if (!TFM_RollbackManager.canRollback(p.getName())) - { - playerMsg("No rollback data found for that player", ChatColor.RED); + TFM_Util.adminAction(sender.getName(), "Purging all rollback history.", false); + playerMsg("Purged all rollback history for " + TFM_RollbackManager.purgeEntries() + " players."); } else { - playerMsg("Purged " + TFM_RollbackManager.purgeEntries(p.getName()) + " entries."); - return true; + String playerName = getPlayerName(args[0]); + TFM_Util.adminAction(sender.getName(), "Rolling back player: " + playerName, false); + playerMsg("Rolled back " + TFM_RollbackManager.rollback(playerName) + " edits for " + playerName + "."); } } - - if (args.length != 1) + else if (args.length == 2) + { + if (args[0].equalsIgnoreCase("purge")) + { + String playerName = getPlayerName(args[1]); + playerMsg("Purged " + TFM_RollbackManager.purgeEntries(playerName) + " rollback history entries for " + playerName + "."); + } + else + { + return false; + } + } + else { return false; } - OfflinePlayer p; + return true; + } + + private String getPlayerName(String playerNameInput) + { + String playerName = null; + try { - p = getPlayer(args[0]); + Player player = getPlayer(playerNameInput); + if (player != null) + { + playerName = player.getName(); + } } catch (CantFindPlayerException ex) { - p = server.getOfflinePlayer(args[0]); - if (!p.hasPlayedBefore()) - { - playerMsg("Player is not online, or never joined the server.", ChatColor.RED); - return true; - } } - if (!TFM_RollbackManager.canRollback(p.getName())) + if (playerName == null) { - playerMsg("Player has no rollback data set.", ChatColor.RED); - return true; + playerName = TFM_UserList.getInstance(plugin).searchByPartialName(playerNameInput); } - TFM_Util.adminAction(sender.getName(), "Rolling back player: " + p.getName(), false); - playerMsg("Rolled back " + TFM_RollbackManager.rollback(p) + " blocks"); - return true; + return playerName; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java index c03619eb..ba68554a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java @@ -17,6 +17,7 @@ public class Command_tfupdate extends TFM_Command { "http://s3.madgeekonline.com/totalfreedom/BukkitHttpd.jar", "http://s3.madgeekonline.com/totalfreedom/BukkitTelnet.jar", + "http://s3.madgeekonline.com/totalfreedom/DisguiseCraft.jar", "http://s3.madgeekonline.com/totalfreedom/Essentials.jar", "http://s3.madgeekonline.com/totalfreedom/EssentialsSpawn.jar", "http://s3.madgeekonline.com/totalfreedom/TotalFreedomMod.jar", diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java index d6a3a757..c2716959 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java @@ -15,7 +15,7 @@ public class Command_uall extends TFM_Command { TFM_Util.adminAction(sender.getName(), "Undisguising all players", true); - TFM_DisguiseCraftBridge.getInstance().undisguiseAllPlayers(); + TFM_DisguiseCraftBridge.undisguiseAllPlayers(); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java index d3c23dc9..a244663a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java @@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Listener; import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; -import me.StevenLawson.TotalFreedomMod.TFM_RollbackEntry; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; @@ -100,6 +99,12 @@ public class TFM_BlockListener implements Listener } } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onRollbackBlockBreak(BlockBreakEvent event) + { + TFM_RollbackManager.blockBreak(event); + } + @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { @@ -237,6 +242,12 @@ public class TFM_BlockListener implements Listener } } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onRollbackBlockPlace(BlockPlaceEvent event) + { + TFM_RollbackManager.blockPlace(event); + } + @EventHandler(priority = EventPriority.HIGH) public void onBlockFromTo(BlockFromToEvent event) { @@ -245,19 +256,4 @@ public class TFM_BlockListener implements Listener event.setCancelled(true); } } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onBlockPlaceRollback(BlockPlaceEvent event) - { - TFM_RollbackEntry entry = new TFM_RollbackEntry(); - entry.setLocation(event.getBlock().getLocation()); - entry.setMaterial(Material.AIR); - TFM_RollbackManager.blockUpdate(event.getPlayer(), entry); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockBreakRollback(BlockBreakEvent event) - { - TFM_RollbackManager.blockUpdate(event.getPlayer(), event.getBlock()); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index f96110cc..d1e36237 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -52,6 +52,7 @@ public class TFM_PlayerListener implements Listener event.setCancelled(true); return; } + break; } case LAVA_BUCKET: { @@ -62,6 +63,7 @@ public class TFM_PlayerListener implements Listener event.setCancelled(true); return; } + break; } case EXPLOSIVE_MINECART: { @@ -71,6 +73,7 @@ public class TFM_PlayerListener implements Listener player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); event.setCancelled(true); } + break; } } break; diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java index 61c84ade..9e86c9d2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java @@ -16,7 +16,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.server.CommandBlockSetEvent; import org.bukkit.event.server.RemoteServerCommandEvent; import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.server.ServerListPingEvent; @@ -32,7 +31,7 @@ public class TFM_ServerListener implements Listener // Just make sure that enable-command-block=false in server.properties. // -Madgeek @EventHandler(priority = EventPriority.NORMAL) - public void onCommandBlockSet(CommandBlockSetEvent event) + public void onCommandBlockSet(org.bukkit.event.server.CommandBlockSetEvent event) { Player player = event.getPlayer(); String newCommandRaw = event.getNewCommand(); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_DisguiseCraftBridge.java b/src/me/StevenLawson/TotalFreedomMod/TFM_DisguiseCraftBridge.java index f0cbb8b3..f114985d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_DisguiseCraftBridge.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_DisguiseCraftBridge.java @@ -11,8 +11,13 @@ public class TFM_DisguiseCraftBridge { } - public boolean undisguisePlayer(Player player) + public static boolean undisguisePlayer(Player player) { + if (!disguiseCraftEnabled()) + { + return false; + } + try { DisguiseCraftAPI api = DisguiseCraft.getAPI(); @@ -29,8 +34,13 @@ public class TFM_DisguiseCraftBridge return false; } - public void undisguiseAllPlayers() + public static void undisguiseAllPlayers() { + if (!disguiseCraftEnabled()) + { + return; + } + try { DisguiseCraftAPI api = DisguiseCraft.getAPI(); @@ -49,13 +59,16 @@ public class TFM_DisguiseCraftBridge } } - public static TFM_DisguiseCraftBridge getInstance() + public static boolean disguiseCraftEnabled() { - return TFM_DisguiseCraftBridgeHolder.INSTANCE; - } - - private static class TFM_DisguiseCraftBridgeHolder - { - private static final TFM_DisguiseCraftBridge INSTANCE = new TFM_DisguiseCraftBridge(); + boolean pluginEnabled = false; + try + { + pluginEnabled = Bukkit.getPluginManager().isPluginEnabled("DisguiseCraft"); + } + catch (Exception ex) + { + } + return pluginEnabled; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java b/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java deleted file mode 100644 index a07d24cf..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java +++ /dev/null @@ -1,40 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.Comparator; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -public class TFM_RadarData implements Comparator -{ - public Player player; - public double distance; - public Location location; - - public TFM_RadarData(Player player, double distance, Location location) - { - this.player = player; - this.distance = distance; - this.location = location; - } - - public TFM_RadarData() - { - } - - @Override - public int compare(TFM_RadarData t1, TFM_RadarData t2) - { - if (t1.distance > t2.distance) - { - return 1; - } - else if (t1.distance < t2.distance) - { - return -1; - } - else - { - return 0; - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackEntry.java b/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackEntry.java deleted file mode 100644 index a51c5a02..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackEntry.java +++ /dev/null @@ -1,52 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; - -public class TFM_RollbackEntry -{ - private Location location; - private Material material; - private byte data; - - public TFM_RollbackEntry() - { - } - - public TFM_RollbackEntry(Block block) - { - location = block.getLocation(); - material = block.getType(); - data = block.getData(); - } - - public void setBlock(Block block) - { - location = block.getLocation(); - material = block.getType(); - data = block.getData(); - } - - public void setLocation(Location location) - { - this.location = location; - } - - public void setMaterial(Material material) - { - this.material = material; - } - - public void setData(byte data) - { - this.data = data; - } - - public void restore() - { - Block b = location.getWorld().getBlockAt(location); - b.setType(material); - b.setData(data); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java b/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java index cdc7782f..4412947f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java @@ -2,85 +2,137 @@ package me.StevenLawson.TotalFreedomMod; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; -import org.bukkit.OfflinePlayer; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.Player; public class TFM_RollbackManager { - public static Map> entries = new HashMap>(); + private static final Map> PLAYER_HISTORY_MAP = new HashMap>(); - public static void blockUpdate(OfflinePlayer player, Block block) + private TFM_RollbackManager() { - List e; - if (entries.containsKey(player.getName())) - { - e = entries.get(player.getName()); - } - else - { - e = new ArrayList(); - } - e.add(0, new TFM_RollbackEntry(block)); - entries.put(player.getName(), e); + throw new AssertionError(); } - public static void blockUpdate(OfflinePlayer player, TFM_RollbackEntry entry) + public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event) { - List e; - if (entries.containsKey(player.getName())) - { - e = entries.get(player.getName()); - } - else - { - e = new ArrayList(); - } - e.add(0, entry); - entries.put(player.getName(), e); + storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_PLACE)); } - public static int rollback(OfflinePlayer player) + public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event) { - if (!canRollback(player.getName())) - { - TFM_Log.severe("Could not rollback player: " + player.getName() + "! No entries are set"); - return 0; - } - - List e = entries.get(player.getName()); - int counter = 0; - for (TFM_RollbackEntry entry : e) - { - entry.restore(); - counter++; - } - entries.remove(player.getName()); - return counter; + storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_BREAK)); } - public static boolean canRollback(String player) + private static void storeEntry(Player player, TFM_RollbackManager_Entry entry) { - return entries.containsKey(player); + List playerEntryList = getPlayerEntryList(player.getName()); + if (playerEntryList != null) + { + playerEntryList.add(0, entry); + } } public static int purgeEntries() { - int counter = entries.size(); - entries.clear(); - return counter; + Iterator> it = PLAYER_HISTORY_MAP.values().iterator(); + while (it.hasNext()) + { + List playerEntryList = it.next(); + if (playerEntryList != null) + { + playerEntryList.clear(); + } + } + return PLAYER_HISTORY_MAP.size(); } - public static int purgeEntries(String player) + public static int purgeEntries(String playerName) { - if (!canRollback(player)) + List playerEntryList = getPlayerEntryList(playerName); + if (playerEntryList != null) { - return 0; + int count = playerEntryList.size(); + playerEntryList.clear(); + return count; + } + return 0; + } + + public static boolean canRollback(String playerName) + { + return PLAYER_HISTORY_MAP.containsKey(playerName.toLowerCase()); + } + + public static int rollback(String playerName) + { + List playerEntryList = getPlayerEntryList(playerName); + if (playerEntryList != null) + { + int count = playerEntryList.size(); + Iterator it = playerEntryList.iterator(); + while (it.hasNext()) + { + TFM_RollbackManager_Entry entry = it.next(); + if (entry != null) + { + entry.restore(); + } + it.remove(); + } + return count; + } + return 0; + } + + private static List getPlayerEntryList(String playerName) + { + playerName = playerName.toLowerCase(); + List playerEntryList = PLAYER_HISTORY_MAP.get(playerName); + if (playerEntryList == null) + { + playerEntryList = new ArrayList(); + PLAYER_HISTORY_MAP.put(playerName, playerEntryList); + } + return playerEntryList; + } + + private enum TFM_RollbackManager_EntryType + { + BLOCK_PLACE, BLOCK_BREAK + } + + private static class TFM_RollbackManager_Entry + { + private final Location location; + private final Material material; + private final byte data; + + public TFM_RollbackManager_Entry(Block block, TFM_RollbackManager_EntryType entryType) + { + this.location = block.getLocation(); + if (entryType == TFM_RollbackManager_EntryType.BLOCK_BREAK) + { + this.material = block.getType(); + this.data = block.getData(); + } + else + { + this.material = Material.AIR; + this.data = 0; + } } - int counter = entries.get(player).size(); - entries.remove(player); - return counter; + public void restore() + { + Block b = this.location.getWorld().getBlockAt(this.location); + b.setType(this.material); + b.setData(this.data); + } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_TickMeter.java b/src/me/StevenLawson/TotalFreedomMod/TFM_TickMeter.java index 3e68b223..093e1512 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_TickMeter.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_TickMeter.java @@ -2,37 +2,37 @@ package me.StevenLawson.TotalFreedomMod; public class TFM_TickMeter { -// int ticks; -// int taskId; -// final TotalFreedomMod plugin; -// -// public TFM_TickMeter(TotalFreedomMod plugin) -// { -// this.plugin = plugin; -// } -// -// public int startTicking() -// { -// int tId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() -// { -// @Override -// public void run() -// { -// ticks += 1; -// } -// }, 1L, 1L); // ticks (20 in 1 second) -// -// taskId = tId; -// return tId; -// } -// -// public void stopTicking() -// { -// plugin.getServer().getScheduler().cancelTask(taskId); -// } -// -// public int getTicks() -// { -// return ticks; -// } + int ticks; + int taskId; + final TotalFreedomMod plugin; + + public TFM_TickMeter(TotalFreedomMod plugin) + { + this.plugin = plugin; + } + + public int startTicking() + { + int tId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() + { + @Override + public void run() + { + ticks += 1; + } + }, 1L, 1L); // ticks (20 in 1 second) + + taskId = tId; + return tId; + } + + public void stopTicking() + { + plugin.getServer().getScheduler().cancelTask(taskId); + } + + public int getTicks() + { + return ticks; + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java index e2fba739..c85d54f3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java @@ -4,8 +4,10 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -125,6 +127,25 @@ public class TFM_UserList exportList(); } + public String searchByPartialName(String needle) + { + needle = needle.toLowerCase().trim(); + Integer minEditDistance = null; + String minEditMatch = null; + Iterator it = _userlist.keySet().iterator(); + while (it.hasNext()) + { + String haystack = it.next(); + int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase()); + if (minEditDistance == null || minEditDistance.intValue() > editDistance) + { + minEditDistance = editDistance; + minEditMatch = haystack; + } + } + return minEditMatch; + } + public class TFM_UserListEntry { private String _username; diff --git a/src/plugin.yml b/src/plugin.yml index 6e377cc2..e00e57b0 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TotalFreedomMod main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod -version: 2.21 +version: 2.22 description: Plugin for the Total Freedom server. authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon]