mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-12-27 20:27:37 +00:00
Optimized RollbackEntry for memory
This commit is contained in:
parent
7a6cc55640
commit
b28a0778b4
@ -1,5 +1,5 @@
|
||||
#Mon, 26 Aug 2013 17:47:26 +0200
|
||||
#Tue, 27 Aug 2013 11:50:34 +0200
|
||||
|
||||
program.VERSION=3.1
|
||||
program.BUILDNUM=507
|
||||
program.BUILDDATE=08/26/2013 05\:47 PM
|
||||
program.BUILDNUM=513
|
||||
program.BUILDDATE=08/27/2013 11\:50 AM
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Mon Aug 26 17:47:26 CEST 2013
|
||||
build.number=508
|
||||
#Tue Aug 27 11:50:34 CEST 2013
|
||||
build.number=514
|
||||
|
@ -102,11 +102,10 @@ public class TFM_PlayerListener implements Listener
|
||||
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);
|
||||
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 ? String.valueOf(entry.getFromMaterial()) : entry.getToMaterial() + (entry.getData() != 0 ? ":" + String.valueOf(entry.getData()) : ""));
|
||||
TFM_Util.playerMsg(player, " - " + ChatColor.BLUE + entry.getAuthor() + " " + entry.getType() + " " + material);
|
||||
TFM_Util.playerMsg(player, " - " + ChatColor.BLUE + entry.getAuthor() + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.getData() == 0 ? "" : ":" + entry.getData()));
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -140,28 +141,37 @@ public class TFM_RollbackManager
|
||||
|
||||
public static class RollbackEntry
|
||||
{
|
||||
// Use of primitives to decrease overhead
|
||||
private final String author;
|
||||
private final Location location;
|
||||
private final int toBlockId; // ints have less overhead than Materials
|
||||
private final int fromBlockId;
|
||||
private final String worldName;
|
||||
private final int x;
|
||||
private final short y;
|
||||
private final int z;
|
||||
private final short blockId;
|
||||
private final byte data;
|
||||
private final boolean isBreak;
|
||||
|
||||
private RollbackEntry(String author, Block block, EntryType entryType)
|
||||
{
|
||||
this.location = block.getLocation().clone();
|
||||
final Location location = block.getLocation();
|
||||
|
||||
this.x = location.getBlockX();
|
||||
this.y = (short) location.getBlockY();
|
||||
this.z = location.getBlockZ();
|
||||
this.worldName = location.getWorld().getName();
|
||||
this.author = author;
|
||||
|
||||
if (entryType == EntryType.BLOCK_BREAK)
|
||||
{
|
||||
fromBlockId = block.getTypeId();
|
||||
toBlockId = Material.AIR.getId();
|
||||
data = block.getData();
|
||||
this.blockId = (short) block.getTypeId();
|
||||
this.data = block.getData();
|
||||
this.isBreak = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fromBlockId = Material.AIR.getId();
|
||||
toBlockId = block.getTypeId();
|
||||
blockId = (short) block.getTypeId();
|
||||
data = 0;
|
||||
this.isBreak = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,19 +182,37 @@ public class TFM_RollbackManager
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
return location;
|
||||
try
|
||||
{
|
||||
return new Location(Bukkit.getWorld(worldName), (double) x, (double) y, (double) z);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.warning("Could not get location of rollback entry at (" + worldName + ":" + x + "," + y + "," + x + ")!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Material getFromMaterial()
|
||||
public Material getMaterial()
|
||||
{
|
||||
return Material.getMaterial(fromBlockId);
|
||||
return Material.getMaterial(blockId);
|
||||
}
|
||||
|
||||
public Material getToMaterial()
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return Material.getMaterial(toBlockId);
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
public int getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
public byte getData()
|
||||
{
|
||||
return data;
|
||||
@ -192,14 +220,21 @@ public class TFM_RollbackManager
|
||||
|
||||
public EntryType getType()
|
||||
{
|
||||
return (getFromMaterial() == Material.AIR ? EntryType.BLOCK_PLACE : EntryType.BLOCK_BREAK);
|
||||
return (isBreak ? EntryType.BLOCK_BREAK : EntryType.BLOCK_PLACE);
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
Block block = location.getWorld().getBlockAt(location);
|
||||
block.setType(getFromMaterial());
|
||||
block.setData(data);
|
||||
Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
||||
if (isBreak)
|
||||
{
|
||||
block.setType(getMaterial());
|
||||
block.setData(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user