Merged branch unfinished

This commit is contained in:
JeromSar 2013-08-09 17:11:30 +02:00
commit 9b62731e94
20 changed files with 327 additions and 301 deletions

View File

@ -1,6 +1,5 @@
#Fri, 09 Aug 2013 17:04:56 +0200 #Fri, 09 Aug 2013 15:38:23 +0200
program.VERSION=2.21
program.BUILDNUM=384
program.BUILDDATE=08/09/2013 05\:04 PM
program.VERSION=2.22
program.BUILDNUM=378
program.BUILDDATE=08/09/2013 03\:38 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Fri Aug 09 17:04:56 CEST 2013 #Fri Aug 09 15:38:23 CEST 2013
build.number=385 build.number=379

View File

@ -1,4 +1,4 @@
# TotalFreedomMod v2.21 Configuration # TotalFreedomMod v2.22 Configuration
# by Madgeek1450 and DarthSalamon # by Madgeek1450 and DarthSalamon
# Block placement prevention: # Block placement prevention:

View File

@ -48,7 +48,7 @@ public class Command_gtfo extends TFM_Command
TFM_WorldEditBridge.getInstance().undo(p, 15); TFM_WorldEditBridge.getInstance().undo(p, 15);
// rollback // rollback
TFM_RollbackManager.rollback(p); TFM_RollbackManager.rollback(p.getName());
// deop // deop
p.setOp(false); p.setOp(false);

View File

@ -1,8 +1,15 @@
package me.StevenLawson.TotalFreedomMod.Commands; 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) @CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "View ticks-per-second", usage = "/<command>") @CommandParameters(description = "View ticks-per-second", usage = "/<command>")
@ -11,39 +18,45 @@ public class Command_health extends TFM_Command
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) 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.
// new BukkitRunnable()
// Runnable task; {
// task = new Runnable() // async
// { @Override
// @Override public void run()
// public void run() {
// { try
// try {
// { final TFM_TickMeter meter = new TFM_TickMeter(plugin);
// TFM_TickMeter meter = new TFM_TickMeter(plugin); meter.startTicking();
// meter.startTicking(); Thread.sleep(1000); // per second
// Thread.sleep(1000); // per second meter.stopTicking();
// meter.stopTicking();
// final Runtime runtime = Runtime.getRuntime();
// Runtime runtime = Runtime.getRuntime(); final int mb = 1048576; // 1024 * 1024
// int mb = 1048576; // 1024 * 1024
// final float usedMem = runtime.totalMemory() - runtime.freeMemory();
// float usedMem = runtime.totalMemory() - runtime.freeMemory();
// new BukkitRunnable()
// playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb"); {
// playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format(usedMem / runtime.totalMemory() * 100) + "%)"); @Override
// playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb"); public void run() {
// playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks()); playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb");
// } playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format((usedMem / runtime.totalMemory()) * 100) + "%)");
// catch (Exception iex) playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb");
// { playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks());
// TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process."); }
// TFM_Log.warning(ExceptionUtils.getStackTrace(iex)); }.runTask(TotalFreedomMod.plugin);
// } }
// } catch (Exception iex)
// }; {
// new Thread(task, "TickMeter").start(); TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process.");
TFM_Log.warning(ExceptionUtils.getStackTrace(iex));
}
}
}.runTaskAsynchronously(TotalFreedomMod.plugin);
return true; return true;
} }
} }

View File

@ -22,7 +22,7 @@ public class Command_purgeall extends TFM_Command
TFM_Util.wipeEntities(true, true); TFM_Util.wipeEntities(true, true);
// Undisguise all players // Undisguise all players
TFM_DisguiseCraftBridge.getInstance().undisguiseAllPlayers(); TFM_DisguiseCraftBridge.undisguiseAllPlayers();
for (Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {

View File

@ -2,8 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_RadarData;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -71,4 +71,39 @@ public class Command_radar extends TFM_Command
return true; return true;
} }
private class TFM_RadarData implements Comparator<TFM_RadarData>
{
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;
}
}
}
} }

View File

@ -1,9 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,74 +14,61 @@ public class Command_rollback extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) 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[0].equalsIgnoreCase("purgeall"))
}
if (args.length == 1 && args[0].equalsIgnoreCase("purgeall"))
{ {
TFM_Util.adminAction(sender.getName(), "Puring all rollback data", false); TFM_Util.adminAction(sender.getName(), "Purging all rollback history.", false);
playerMsg("Purged entries for " + TFM_RollbackManager.purgeEntries() + " players."); playerMsg("Purged all rollback history for " + TFM_RollbackManager.purgeEntries() + " players.");
return true;
}
if (args.length == 2 && args[0].equalsIgnoreCase("purge"))
{
OfflinePlayer p;
try
{
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);
} }
else else
{ {
playerMsg("Purged " + TFM_RollbackManager.purgeEntries(p.getName()) + " entries."); String playerName = getPlayerName(args[0]);
return true; TFM_Util.adminAction(sender.getName(), "Rolling back player: " + playerName, false);
playerMsg("Rolled back " + TFM_RollbackManager.rollback(playerName) + " edits for " + playerName + ".");
} }
} }
else if (args.length == 2)
if (args.length != 1) {
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; return false;
} }
OfflinePlayer p; return true;
}
private String getPlayerName(String playerNameInput)
{
String playerName = null;
try try
{ {
p = getPlayer(args[0]); Player player = getPlayer(playerNameInput);
if (player != null)
{
playerName = player.getName();
}
} }
catch (CantFindPlayerException ex) 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); playerName = TFM_UserList.getInstance(plugin).searchByPartialName(playerNameInput);
return true;
} }
TFM_Util.adminAction(sender.getName(), "Rolling back player: " + p.getName(), false); return playerName;
playerMsg("Rolled back " + TFM_RollbackManager.rollback(p) + " blocks");
return true;
} }
} }

View File

@ -17,6 +17,7 @@ public class Command_tfupdate extends TFM_Command
{ {
"http://s3.madgeekonline.com/totalfreedom/BukkitHttpd.jar", "http://s3.madgeekonline.com/totalfreedom/BukkitHttpd.jar",
"http://s3.madgeekonline.com/totalfreedom/BukkitTelnet.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/Essentials.jar",
"http://s3.madgeekonline.com/totalfreedom/EssentialsSpawn.jar", "http://s3.madgeekonline.com/totalfreedom/EssentialsSpawn.jar",
"http://s3.madgeekonline.com/totalfreedom/TotalFreedomMod.jar", "http://s3.madgeekonline.com/totalfreedom/TotalFreedomMod.jar",

View File

@ -15,7 +15,7 @@ public class Command_uall extends TFM_Command
{ {
TFM_Util.adminAction(sender.getName(), "Undisguising all players", true); TFM_Util.adminAction(sender.getName(), "Undisguising all players", true);
TFM_DisguiseCraftBridge.getInstance().undisguiseAllPlayers(); TFM_DisguiseCraftBridge.undisguiseAllPlayers();
return true; return true;
} }

View File

@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackEntry;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; 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) @EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) 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) @EventHandler(priority = EventPriority.HIGH)
public void onBlockFromTo(BlockFromToEvent event) public void onBlockFromTo(BlockFromToEvent event)
{ {
@ -245,19 +256,4 @@ public class TFM_BlockListener implements Listener
event.setCancelled(true); 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());
}
} }

View File

@ -52,6 +52,7 @@ public class TFM_PlayerListener implements Listener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break;
} }
case LAVA_BUCKET: case LAVA_BUCKET:
{ {
@ -62,6 +63,7 @@ public class TFM_PlayerListener implements Listener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break;
} }
case EXPLOSIVE_MINECART: case EXPLOSIVE_MINECART:
{ {
@ -71,6 +73,7 @@ public class TFM_PlayerListener implements Listener
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
event.setCancelled(true); event.setCancelled(true);
} }
break;
} }
} }
break; break;

View File

@ -16,7 +16,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.server.CommandBlockSetEvent;
import org.bukkit.event.server.RemoteServerCommandEvent; import org.bukkit.event.server.RemoteServerCommandEvent;
import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.server.ServerListPingEvent; 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. // Just make sure that enable-command-block=false in server.properties.
// -Madgeek // -Madgeek
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onCommandBlockSet(CommandBlockSetEvent event) public void onCommandBlockSet(org.bukkit.event.server.CommandBlockSetEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
String newCommandRaw = event.getNewCommand(); String newCommandRaw = event.getNewCommand();

View File

@ -11,8 +11,13 @@ public class TFM_DisguiseCraftBridge
{ {
} }
public boolean undisguisePlayer(Player player) public static boolean undisguisePlayer(Player player)
{ {
if (!disguiseCraftEnabled())
{
return false;
}
try try
{ {
DisguiseCraftAPI api = DisguiseCraft.getAPI(); DisguiseCraftAPI api = DisguiseCraft.getAPI();
@ -29,8 +34,13 @@ public class TFM_DisguiseCraftBridge
return false; return false;
} }
public void undisguiseAllPlayers() public static void undisguiseAllPlayers()
{ {
if (!disguiseCraftEnabled())
{
return;
}
try try
{ {
DisguiseCraftAPI api = DisguiseCraft.getAPI(); 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; boolean pluginEnabled = false;
try
{
pluginEnabled = Bukkit.getPluginManager().isPluginEnabled("DisguiseCraft");
} }
catch (Exception ex)
private static class TFM_DisguiseCraftBridgeHolder
{ {
private static final TFM_DisguiseCraftBridge INSTANCE = new TFM_DisguiseCraftBridge(); }
return pluginEnabled;
} }
} }

View File

@ -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<TFM_RadarData>
{
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;
}
}
}

View File

@ -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);
}
}

View File

@ -2,85 +2,137 @@ package me.StevenLawson.TotalFreedomMod;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.OfflinePlayer; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class TFM_RollbackManager public class TFM_RollbackManager
{ {
public static Map<String, List<TFM_RollbackEntry>> entries = new HashMap<String, List<TFM_RollbackEntry>>(); private static final Map<String, List<TFM_RollbackManager_Entry>> PLAYER_HISTORY_MAP = new HashMap<String, List<TFM_RollbackManager_Entry>>();
public static void blockUpdate(OfflinePlayer player, Block block) private TFM_RollbackManager()
{ {
List<TFM_RollbackEntry> e; throw new AssertionError();
if (entries.containsKey(player.getName()))
{
e = entries.get(player.getName());
}
else
{
e = new ArrayList<TFM_RollbackEntry>();
}
e.add(0, new TFM_RollbackEntry(block));
entries.put(player.getName(), e);
} }
public static void blockUpdate(OfflinePlayer player, TFM_RollbackEntry entry) public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event)
{ {
List<TFM_RollbackEntry> e; storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_PLACE));
if (entries.containsKey(player.getName()))
{
e = entries.get(player.getName());
}
else
{
e = new ArrayList<TFM_RollbackEntry>();
}
e.add(0, entry);
entries.put(player.getName(), e);
} }
public static int rollback(OfflinePlayer player) public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event)
{ {
if (!canRollback(player.getName())) storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_BREAK));
{
TFM_Log.severe("Could not rollback player: " + player.getName() + "! No entries are set");
return 0;
} }
List<TFM_RollbackEntry> e = entries.get(player.getName()); private static void storeEntry(Player player, TFM_RollbackManager_Entry entry)
int counter = 0;
for (TFM_RollbackEntry entry : e)
{ {
entry.restore(); List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(player.getName());
counter++; if (playerEntryList != null)
}
entries.remove(player.getName());
return counter;
}
public static boolean canRollback(String player)
{ {
return entries.containsKey(player); playerEntryList.add(0, entry);
}
} }
public static int purgeEntries() public static int purgeEntries()
{ {
int counter = entries.size(); Iterator<List<TFM_RollbackManager_Entry>> it = PLAYER_HISTORY_MAP.values().iterator();
entries.clear(); while (it.hasNext())
return counter; {
List<TFM_RollbackManager_Entry> 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<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(playerName);
if (playerEntryList != null)
{ {
int count = playerEntryList.size();
playerEntryList.clear();
return count;
}
return 0; return 0;
} }
int counter = entries.get(player).size(); public static boolean canRollback(String playerName)
entries.remove(player); {
return counter; return PLAYER_HISTORY_MAP.containsKey(playerName.toLowerCase());
}
public static int rollback(String playerName)
{
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(playerName);
if (playerEntryList != null)
{
int count = playerEntryList.size();
Iterator<TFM_RollbackManager_Entry> 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<TFM_RollbackManager_Entry> getPlayerEntryList(String playerName)
{
playerName = playerName.toLowerCase();
List<TFM_RollbackManager_Entry> playerEntryList = PLAYER_HISTORY_MAP.get(playerName);
if (playerEntryList == null)
{
playerEntryList = new ArrayList<TFM_RollbackManager_Entry>();
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;
}
}
public void restore()
{
Block b = this.location.getWorld().getBlockAt(this.location);
b.setType(this.material);
b.setData(this.data);
}
} }
} }

View File

@ -2,37 +2,37 @@ package me.StevenLawson.TotalFreedomMod;
public class TFM_TickMeter public class TFM_TickMeter
{ {
// int ticks; int ticks;
// int taskId; int taskId;
// final TotalFreedomMod plugin; final TotalFreedomMod plugin;
//
// public TFM_TickMeter(TotalFreedomMod plugin) public TFM_TickMeter(TotalFreedomMod plugin)
// { {
// this.plugin = plugin; this.plugin = plugin;
// } }
//
// public int startTicking() public int startTicking()
// { {
// int tId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() int tId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
// { {
// @Override @Override
// public void run() public void run()
// { {
// ticks += 1; ticks += 1;
// } }
// }, 1L, 1L); // ticks (20 in 1 second) }, 1L, 1L); // ticks (20 in 1 second)
//
// taskId = tId; taskId = tId;
// return tId; return tId;
// } }
//
// public void stopTicking() public void stopTicking()
// { {
// plugin.getServer().getScheduler().cancelTask(taskId); plugin.getServer().getScheduler().cancelTask(taskId);
// } }
//
// public int getTicks() public int getTicks()
// { {
// return ticks; return ticks;
// } }
} }

View File

@ -4,8 +4,10 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -125,6 +127,25 @@ public class TFM_UserList
exportList(); exportList();
} }
public String searchByPartialName(String needle)
{
needle = needle.toLowerCase().trim();
Integer minEditDistance = null;
String minEditMatch = null;
Iterator<String> 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 public class TFM_UserListEntry
{ {
private String _username; private String _username;

View File

@ -1,6 +1,6 @@
name: TotalFreedomMod name: TotalFreedomMod
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
version: 2.21 version: 2.22
description: Plugin for the Total Freedom server. description: Plugin for the Total Freedom server.
authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon] authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon]