2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.rollback;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
2018-07-25 02:08:29 +00:00
|
|
|
import org.bukkit.block.data.BlockData;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
public class RollbackEntry
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
// Use of primitives to decrease overhead
|
|
|
|
public final String author;
|
|
|
|
public final String worldName;
|
|
|
|
public final int x;
|
|
|
|
public final short y;
|
|
|
|
public final int z;
|
2018-07-25 02:08:29 +00:00
|
|
|
public final BlockData data;
|
2015-10-19 17:43:46 +00:00
|
|
|
public final Material blockMaterial;
|
|
|
|
private final boolean isBreak;
|
|
|
|
|
|
|
|
public RollbackEntry(String author, Block block, EntryType entryType)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
this.blockMaterial = block.getType();
|
2018-07-25 02:08:29 +00:00
|
|
|
this.data = block.getBlockData();
|
2015-10-19 17:43:46 +00:00
|
|
|
this.isBreak = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.blockMaterial = block.getType();
|
2018-07-25 02:08:29 +00:00
|
|
|
this.data = block.getBlockData();
|
2015-10-19 17:43:46 +00:00
|
|
|
this.isBreak = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Location getLocation()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new Location(Bukkit.getWorld(worldName), x, (int) y, z);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.warning("Could not get location of rollback entry at (" + worldName + ":" + x + "," + y + "," + x + ")!");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Material getMaterial()
|
|
|
|
{
|
|
|
|
return blockMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntryType getType()
|
|
|
|
{
|
|
|
|
return (isBreak ? EntryType.BLOCK_BREAK : EntryType.BLOCK_PLACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void restore()
|
|
|
|
{
|
|
|
|
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
|
|
|
if (isBreak)
|
|
|
|
{
|
|
|
|
block.setType(getMaterial());
|
2018-07-25 02:08:29 +00:00
|
|
|
block.setBlockData(data);
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void redo()
|
|
|
|
{
|
|
|
|
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
|
|
|
|
|
|
|
if (isBreak)
|
|
|
|
{
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
block.setType(getMaterial());
|
2018-07-25 02:08:29 +00:00
|
|
|
block.setBlockData(data);
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|