2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.caging;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import lombok.Getter;
|
|
|
|
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;
|
2018-01-01 03:43:10 +00:00
|
|
|
@Getter
|
|
|
|
private static String input = null;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
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;
|
2018-01-01 03:43:10 +00:00
|
|
|
this.input = null;
|
|
|
|
|
|
|
|
buildHistory(location, 2, fPlayer);
|
|
|
|
regenerate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cage(Location location, Material outer, Material inner, String input)
|
|
|
|
{
|
|
|
|
if (isCaged())
|
|
|
|
{
|
|
|
|
setCaged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.caged = true;
|
|
|
|
this.location = location;
|
|
|
|
this.outerMaterial = outer;
|
|
|
|
this.innerMaterial = inner;
|
|
|
|
this.input = input;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
cage(fPlayer.getPlayer().getLocation(), outerMaterial, innerMaterial, input);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-07-25 02:08:29 +00:00
|
|
|
if (material != Material.PLAYER_HEAD)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
// Glowstone light
|
|
|
|
if (material != Material.GLASS && xOffset == 0 && yOffset == 2 && zOffset == 0)
|
|
|
|
{
|
|
|
|
block.setType(Material.GLOWSTONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
block.setType(material);
|
|
|
|
}
|
2018-01-01 03:43:10 +00:00
|
|
|
else
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
if (Math.abs(xOffset) == length && Math.abs(yOffset) == length && Math.abs(zOffset) == length)
|
|
|
|
{
|
|
|
|
block.setType(Material.GLOWSTONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:08:29 +00:00
|
|
|
block.setType(Material.PLAYER_HEAD);
|
2018-01-01 03:43:10 +00:00
|
|
|
if (input != null)
|
|
|
|
{
|
|
|
|
Skull skull = (Skull) block.getState();
|
2018-07-25 02:08:29 +00:00
|
|
|
// This may or may not work in future versions of spigot
|
2018-01-01 03:43:10 +00:00
|
|
|
skull.setOwner(input);
|
|
|
|
skull.update();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|