Added logblock stick

This commit is contained in:
JeromSar 2013-08-26 17:22:35 +02:00
parent fbdf2b5fc2
commit 5876f86ac3
5 changed files with 140 additions and 40 deletions

View File

@ -1,5 +1,5 @@
#Mon, 26 Aug 2013 15:12:00 +0200 #Mon, 26 Aug 2013 17:21:52 +0200
program.VERSION=3.1 program.VERSION=3.1
program.BUILDNUM=501 program.BUILDNUM=505
program.BUILDDATE=08/26/2013 03\:12 PM program.BUILDDATE=08/26/2013 05\:21 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Aug 26 15:12:00 CEST 2013 #Mon Aug 26 17:21:52 CEST 2013
build.number=502 build.number=506

View File

@ -23,7 +23,7 @@ public class Command_cage extends TFM_Command
if (TFM_Util.isStopCommand(args[0]) && sender instanceof Player) if (TFM_Util.isStopCommand(args[0]) && sender instanceof Player)
{ {
TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);; TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
playerdata.setCaged(false); playerdata.setCaged(false);

View File

@ -7,6 +7,8 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*; import me.StevenLawson.TotalFreedomMod.*;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.EntryType;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -83,6 +85,34 @@ public class TFM_PlayerListener implements Listener
switch (event.getMaterial()) switch (event.getMaterial())
{ {
case STICK: case STICK:
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
{
break;
}
event.setCancelled(true);
final Location location = player.getTargetBlock(null, 5).getLocation();
final List<RollbackEntry> entries = TFM_RollbackManager.getEntriesAtLocation(location);
if (entries.isEmpty())
{
TFM_Util.playerMsg(player, "No block edits at that location.");
break;
}
TFM_Util.playerMsg(player, "Block edits at (" + ChatColor.WHITE + "X" + location.getBlockX() + ", Y" + location.getBlockY() + ", Z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE);
for (RollbackEntry entry : entries)
{
String material = (entry.getType() == EntryType.BLOCK_BREAK ? entry.getFromMaterial() : entry.getToMaterial() + String.valueOf(entry.getData() == 0 ? entry.getData() : "")).toString();
TFM_Util.playerMsg(player, " - " + ChatColor.BLUE + entry.getAuthor() + " " + entry.getType() + " " + material);
}
break;
}
case BONE:
{ {
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
if (playerdata.mobThrowerEnabled()) if (playerdata.mobThrowerEnabled())
@ -98,6 +128,7 @@ public class TFM_PlayerListener implements Listener
} }
break; break;
} }
case SULPHUR: case SULPHUR:
{ {
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
@ -116,6 +147,7 @@ public class TFM_PlayerListener implements Listener
} }
break; break;
} }
case BLAZE_ROD: case BLAZE_ROD:
{ {
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
@ -148,6 +180,7 @@ public class TFM_PlayerListener implements Listener
} }
break; break;
} }
case CARROT: case CARROT:
{ {
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())

View File

@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
public class TFM_RollbackManager public class TFM_RollbackManager
{ {
private static final Map<String, List<TFM_RollbackManager_Entry>> PLAYER_HISTORY_MAP = new HashMap<String, List<TFM_RollbackManager_Entry>>(); private static final Map<String, List<RollbackEntry>> PLAYER_HISTORY_MAP = new HashMap<String, List<RollbackEntry>>();
private TFM_RollbackManager() private TFM_RollbackManager()
{ {
@ -21,17 +21,17 @@ public class TFM_RollbackManager
public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event) public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event)
{ {
storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_PLACE)); storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_PLACE));
} }
public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event) public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event)
{ {
storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_BREAK)); storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_BREAK));
} }
private static void storeEntry(Player player, TFM_RollbackManager_Entry entry) private static void storeEntry(Player player, RollbackEntry entry)
{ {
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(player.getName()); List<RollbackEntry> playerEntryList = getEntriesByPlayer(player.getName());
if (playerEntryList != null) if (playerEntryList != null)
{ {
playerEntryList.add(0, entry); playerEntryList.add(0, entry);
@ -40,10 +40,10 @@ public class TFM_RollbackManager
public static int purgeEntries() public static int purgeEntries()
{ {
Iterator<List<TFM_RollbackManager_Entry>> it = PLAYER_HISTORY_MAP.values().iterator(); Iterator<List<RollbackEntry>> it = PLAYER_HISTORY_MAP.values().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
List<TFM_RollbackManager_Entry> playerEntryList = it.next(); List<RollbackEntry> playerEntryList = it.next();
if (playerEntryList != null) if (playerEntryList != null)
{ {
playerEntryList.clear(); playerEntryList.clear();
@ -54,7 +54,7 @@ public class TFM_RollbackManager
public static int purgeEntries(String playerName) public static int purgeEntries(String playerName)
{ {
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(playerName); List<RollbackEntry> playerEntryList = getEntriesByPlayer(playerName);
if (playerEntryList != null) if (playerEntryList != null)
{ {
int count = playerEntryList.size(); int count = playerEntryList.size();
@ -71,14 +71,14 @@ public class TFM_RollbackManager
public static int rollback(String playerName) public static int rollback(String playerName)
{ {
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(playerName); List<RollbackEntry> playerEntryList = getEntriesByPlayer(playerName);
if (playerEntryList != null) if (playerEntryList != null)
{ {
int count = playerEntryList.size(); int count = playerEntryList.size();
Iterator<TFM_RollbackManager_Entry> it = playerEntryList.iterator(); Iterator<RollbackEntry> it = playerEntryList.iterator();
while (it.hasNext()) while (it.hasNext())
{ {
TFM_RollbackManager_Entry entry = it.next(); RollbackEntry entry = it.next();
if (entry != null) if (entry != null)
{ {
entry.restore(); entry.restore();
@ -90,49 +90,116 @@ public class TFM_RollbackManager
return 0; return 0;
} }
private static List<TFM_RollbackManager_Entry> getPlayerEntryList(String playerName) public static List<RollbackEntry> getEntriesAtLocation(Location location)
{
location = location.clone();
List<RollbackEntry> entries = new ArrayList<RollbackEntry>();
for (String playername : PLAYER_HISTORY_MAP.keySet())
{
for (RollbackEntry entry : PLAYER_HISTORY_MAP.get(playername))
{
if (entry.getLocation().equals(location))
{
entries.add(0, entry);
}
}
}
return entries;
}
private static List<RollbackEntry> getEntriesByPlayer(String playerName)
{ {
playerName = playerName.toLowerCase(); playerName = playerName.toLowerCase();
List<TFM_RollbackManager_Entry> playerEntryList = PLAYER_HISTORY_MAP.get(playerName); List<RollbackEntry> playerEntryList = PLAYER_HISTORY_MAP.get(playerName);
if (playerEntryList == null) if (playerEntryList == null)
{ {
playerEntryList = new ArrayList<TFM_RollbackManager_Entry>(); playerEntryList = new ArrayList<RollbackEntry>();
PLAYER_HISTORY_MAP.put(playerName, playerEntryList); PLAYER_HISTORY_MAP.put(playerName, playerEntryList);
} }
return playerEntryList; return playerEntryList;
} }
private enum TFM_RollbackManager_EntryType public enum EntryType
{ {
BLOCK_PLACE, BLOCK_BREAK BLOCK_PLACE, BLOCK_BREAK;
}
private static class TFM_RollbackManager_Entry @Override
public String toString()
{ {
private final Location location; if (this == BLOCK_PLACE)
private final Material material;
private final byte data;
public TFM_RollbackManager_Entry(Block block, TFM_RollbackManager_EntryType entryType)
{ {
this.location = block.getLocation(); return "placed";
if (entryType == TFM_RollbackManager_EntryType.BLOCK_BREAK)
{
this.material = block.getType();
this.data = block.getData();
} }
else else
{ {
this.material = Material.AIR; return "broke";
this.data = 0;
} }
} }
}
public static class RollbackEntry
{
private final String author;
private final Location location;
private final int toBlockId; // ints have less overhead than Materials
private final int fromBlockId;
private final byte data;
private RollbackEntry(String author, Block block, EntryType entryType)
{
this.location = block.getLocation().clone();
this.author = author;
if (entryType == EntryType.BLOCK_BREAK)
{
fromBlockId = block.getTypeId();
toBlockId = Material.AIR.getId();
data = block.getData();
}
else
{
fromBlockId = Material.AIR.getId();
toBlockId = block.getTypeId();
data = 0;
}
}
public String getAuthor()
{
return author;
}
public Location getLocation()
{
return location;
}
public Material getFromMaterial()
{
return Material.getMaterial(fromBlockId);
}
public Material getToMaterial()
{
return Material.getMaterial(toBlockId);
}
public byte getData()
{
return data;
}
public EntryType getType()
{
return (getFromMaterial() == Material.AIR ? EntryType.BLOCK_PLACE : EntryType.BLOCK_BREAK);
}
public void restore() public void restore()
{ {
Block b = this.location.getWorld().getBlockAt(this.location); Block block = location.getWorld().getBlockAt(location);
b.setType(this.material); block.setType(getFromMaterial());
b.setData(this.data); block.setData(data);
} }
} }
} }