2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.caging;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import lombok.Getter;
|
2017-10-13 18:35:11 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.command.Command_cage;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.SkullType;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.Skull;
|
|
|
|
|
|
|
|
public class CageData
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
private final FPlayer fPlayer;
|
|
|
|
//
|
2016-03-02 19:28:01 +00:00
|
|
|
private final List<BlockData> cageHistory = new ArrayList<>();
|
2015-11-15 23:32:04 +00:00
|
|
|
//
|
|
|
|
@Getter
|
|
|
|
private boolean caged = false;
|
|
|
|
@Getter
|
|
|
|
private Location location;
|
|
|
|
@Getter
|
|
|
|
private Material outerMaterial = Material.GLASS;
|
|
|
|
@Getter
|
|
|
|
private Material innerMaterial = Material.AIR;
|
|
|
|
|
|
|
|
public CageData(FPlayer player)
|
|
|
|
{
|
|
|
|
this.fPlayer = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCaged(boolean cage)
|
|
|
|
{
|
|
|
|
if (cage)
|
|
|
|
{
|
|
|
|
cage(fPlayer.getPlayer().getLocation(), Material.GLASS, Material.GLASS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.caged = false;
|
|
|
|
regenerateHistory();
|
|
|
|
clearHistory();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cage(Location location, Material outer, Material inner)
|
|
|
|
{
|
|
|
|
if (isCaged())
|
|
|
|
{
|
|
|
|
setCaged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.caged = true;
|
|
|
|
this.location = location;
|
|
|
|
this.outerMaterial = outer;
|
|
|
|
this.innerMaterial = inner;
|
|
|
|
|
|
|
|
buildHistory(location, 2, fPlayer);
|
2016-03-07 20:32:05 +00:00
|
|
|
regenerate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void regenerate()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!caged
|
|
|
|
|| location == null
|
|
|
|
|| outerMaterial == null
|
|
|
|
|| innerMaterial == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
generateHollowCube(location, 2, outerMaterial);
|
|
|
|
generateCube(location, 1, innerMaterial);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: EventHandlerize this?
|
|
|
|
public void playerJoin()
|
|
|
|
{
|
|
|
|
if (!isCaged())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cage(fPlayer.getPlayer().getLocation(), outerMaterial, innerMaterial);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playerQuit()
|
|
|
|
{
|
|
|
|
regenerateHistory();
|
|
|
|
clearHistory();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearHistory()
|
|
|
|
{
|
|
|
|
cageHistory.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void insertHistoryBlock(Location location, Material material)
|
|
|
|
{
|
|
|
|
cageHistory.add(new BlockData(location, material));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void regenerateHistory()
|
|
|
|
{
|
|
|
|
for (BlockData blockdata : this.cageHistory)
|
|
|
|
{
|
|
|
|
blockdata.location.getBlock().setType(blockdata.material);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buildHistory(Location location, int length, FPlayer playerdata)
|
|
|
|
{
|
|
|
|
final Block center = location.getBlock();
|
|
|
|
for (int xOffset = -length; xOffset <= length; xOffset++)
|
|
|
|
{
|
|
|
|
for (int yOffset = -length; yOffset <= length; yOffset++)
|
|
|
|
{
|
|
|
|
for (int zOffset = -length; zOffset <= length; zOffset++)
|
|
|
|
{
|
|
|
|
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
|
|
|
insertHistoryBlock(block.getLocation(), block.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Util methods
|
|
|
|
public static void generateCube(Location location, int length, Material material)
|
|
|
|
{
|
|
|
|
final Block center = location.getBlock();
|
|
|
|
for (int xOffset = -length; xOffset <= length; xOffset++)
|
|
|
|
{
|
|
|
|
for (int yOffset = -length; yOffset <= length; yOffset++)
|
|
|
|
{
|
|
|
|
for (int zOffset = -length; zOffset <= length; zOffset++)
|
|
|
|
{
|
|
|
|
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
|
|
|
if (block.getType() != material)
|
|
|
|
{
|
|
|
|
block.setType(material);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void generateHollowCube(Location location, int length, Material material)
|
|
|
|
{
|
|
|
|
final Block center = location.getBlock();
|
|
|
|
for (int xOffset = -length; xOffset <= length; xOffset++)
|
|
|
|
{
|
|
|
|
for (int yOffset = -length; yOffset <= length; yOffset++)
|
|
|
|
{
|
|
|
|
for (int zOffset = -length; zOffset <= length; zOffset++)
|
|
|
|
{
|
|
|
|
// Hollow
|
|
|
|
if (Math.abs(xOffset) != length && Math.abs(yOffset) != length && Math.abs(zOffset) != length)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
|
|
|
|
|
|
|
if (material != Material.SKULL)
|
|
|
|
{
|
|
|
|
// Glowstone light
|
|
|
|
if (material != Material.GLASS && xOffset == 0 && yOffset == 2 && zOffset == 0)
|
|
|
|
{
|
|
|
|
block.setType(Material.GLOWSTONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
block.setType(material);
|
|
|
|
}
|
|
|
|
else // Darth mode
|
|
|
|
{
|
|
|
|
if (Math.abs(xOffset) == length && Math.abs(yOffset) == length && Math.abs(zOffset) == length)
|
|
|
|
{
|
|
|
|
block.setType(Material.GLOWSTONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
block.setType(Material.SKULL);
|
|
|
|
final Skull skull = (Skull) block.getState();
|
|
|
|
skull.setSkullType(SkullType.PLAYER);
|
2017-10-13 18:35:11 +00:00
|
|
|
skull.setOwner(Command_cage.playerSkullName);
|
2015-11-15 23:32:04 +00:00
|
|
|
skull.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
public boolean isCaged()
|
|
|
|
{
|
|
|
|
return this.caged;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Location getLocation()
|
|
|
|
{
|
|
|
|
return this.location;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Material getOuterMaterial()
|
|
|
|
{
|
|
|
|
return this.outerMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Material getInnerMaterial()
|
|
|
|
{
|
|
|
|
return this.innerMaterial;
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
private static class BlockData
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
public Material material;
|
|
|
|
public Location location;
|
|
|
|
|
|
|
|
private BlockData(Location location, Material material)
|
|
|
|
{
|
|
|
|
this.location = location;
|
|
|
|
this.material = material;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|