Minor refactoring in Util class

This commit is contained in:
Intelli 2021-07-19 17:19:35 -06:00
parent fae4c9e690
commit b5b6acaa9d
2 changed files with 166 additions and 207 deletions

View file

@ -480,7 +480,7 @@ public class Rollback extends Queue {
Block block = location1.getBlock(); Block block = location1.getBlock();
Material blockType = block.getType(); Material blockType = block.getType();
if (!BukkitAdapter.ADAPTER.isItemFrame(blockType) && !blockType.equals(Material.PAINTING) && !blockType.equals(Material.ARMOR_STAND)) { if (!BukkitAdapter.ADAPTER.isItemFrame(blockType) && !blockType.equals(Material.PAINTING) && !blockType.equals(Material.ARMOR_STAND)) {
Util.sendBlockChange(player, location1, blockType, block.getBlockData()); Util.sendBlockChange(player, location1, block.getBlockData());
blockCount1++; blockCount1++;
} }
} }
@ -490,7 +490,7 @@ public class Rollback extends Queue {
if (sendBlockData == null) { if (sendBlockData == null) {
sendBlockData = rowType.createBlockData(); sendBlockData = rowType.createBlockData();
} }
Util.sendBlockChange(player, location1, rowType, sendBlockData); Util.sendBlockChange(player, location1, sendBlockData);
blockCount1++; blockCount1++;
} }
} }

View file

@ -107,8 +107,8 @@ import net.coreprotect.worldedit.CoreProtectEditSessionEvent;
public class Util extends Queue { public class Util extends Queue {
public static final java.util.regex.Pattern csvSplitter = java.util.regex.Pattern.compile(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
public static final java.util.regex.Pattern tagParser = java.util.regex.Pattern.compile(Chat.COMPONENT_TAG_OPEN + "(.+?)" + Chat.COMPONENT_TAG_CLOSE + "|(.+?)", java.util.regex.Pattern.DOTALL); public static final java.util.regex.Pattern tagParser = java.util.regex.Pattern.compile(Chat.COMPONENT_TAG_OPEN + "(.+?)" + Chat.COMPONENT_TAG_CLOSE + "|(.+?)", java.util.regex.Pattern.DOTALL);
private static final String NAMESPACE = "minecraft:";
public static String getPluginVersion() { public static String getPluginVersion() {
String version = CoreProtect.getInstance().getDescription().getVersion(); String version = CoreProtect.getInstance().getDescription().getVersion();
@ -196,7 +196,7 @@ public class Util extends Queue {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
double timeSince = currentTime - (logTime + 0.00); double timeSince = currentTime - (logTime + 0.00);
// minutes; // minutes
timeSince = timeSince / 60; timeSince = timeSince / 60;
if (timeSince < 60.0) { if (timeSince < 60.0) {
message.append(Phrase.build(Phrase.LOOKUP_TIME, new DecimalFormat("0.00").format(timeSince) + "/m")); message.append(Phrase.build(Phrase.LOOKUP_TIME, new DecimalFormat("0.00").format(timeSince) + "/m"));
@ -260,7 +260,7 @@ public class Util extends Queue {
name = name.toLowerCase(Locale.ROOT).trim(); name = name.toLowerCase(Locale.ROOT).trim();
if (!name.contains(":")) { if (!name.contains(":")) {
name = "minecraft:" + name; name = NAMESPACE + name;
} }
if (ConfigHandler.materials.get(name) != null) { if (ConfigHandler.materials.get(name) != null) {
@ -317,8 +317,7 @@ public class Util extends Queue {
public static String getBlockNameShort(int id) { public static String getBlockNameShort(int id) {
String name = getBlockName(id); String name = getBlockName(id);
if (name.contains(":")) { if (name.contains(":")) {
String[] block_name_split = name.split(":"); name = name.split(":")[1];
name = block_name_split[1];
} }
return name; return name;
@ -333,13 +332,11 @@ public class Util extends Queue {
for (ItemStack o1 : items) { for (ItemStack o1 : items) {
int c2 = 0; int c2 = 0;
for (ItemStack o2 : items) { for (ItemStack o2 : items) {
if (o1 != null && o2 != null) { if (o1 != null && o2 != null && c2 > c1 && o1.isSimilar(o2) && !Util.isAir(o1.getType())) { // Ignores amount
if (c2 > c1 && o1.isSimilar(o2) && !Util.isAir(o1.getType())) { // Ignores amount
int namount = o1.getAmount() + o2.getAmount(); int namount = o1.getAmount() + o2.getAmount();
o1.setAmount(namount); o1.setAmount(namount);
o2.setAmount(0); o2.setAmount(0);
} }
}
c2++; c2++;
} }
c1++; c1++;
@ -366,7 +363,7 @@ public class Util extends Queue {
return result; return result;
} }
if (material.isBlock() && !createBlockData(material).getAsString().equals(string) && string.startsWith("minecraft:" + material.name().toLowerCase(Locale.ROOT) + "[") && string.endsWith("]")) { if (material.isBlock() && !createBlockData(material).getAsString().equals(string) && string.startsWith(NAMESPACE + material.name().toLowerCase(Locale.ROOT) + "[") && string.endsWith("]")) {
String substring = string.substring(material.name().length() + 11, string.length() - 1); String substring = string.substring(material.name().length() + 11, string.length() - 1);
String[] blockDataSplit = substring.split(","); String[] blockDataSplit = substring.split(",");
ArrayList<String> blockDataArray = new ArrayList<>(); ArrayList<String> blockDataArray = new ArrayList<>();
@ -410,7 +407,7 @@ public class Util extends Queue {
blockDataArray.add(block); blockDataArray.add(block);
} }
} }
result = "minecraft:" + material.name().toLowerCase(Locale.ROOT) + "[" + String.join(",", blockDataArray) + "]"; result = NAMESPACE + material.name().toLowerCase(Locale.ROOT) + "[" + String.join(",", blockDataArray) + "]";
} }
else { else {
result = ""; result = "";
@ -457,10 +454,10 @@ public class Util extends Queue {
return sortedEntries; return sortedEntries;
} }
public static Waterlogged checkWaterlogged(BlockData BLOCK_PLACEdData, BlockState blockReplacedState) { public static Waterlogged checkWaterlogged(BlockData blockData, BlockState blockReplacedState) {
if (blockReplacedState.getType().equals(Material.WATER) && BLOCK_PLACEdData instanceof Waterlogged) { if (blockReplacedState.getType().equals(Material.WATER) && blockData instanceof Waterlogged) {
if (blockReplacedState.getBlockData().equals(Material.WATER.createBlockData())) { if (blockReplacedState.getBlockData().equals(Material.WATER.createBlockData())) {
Waterlogged waterlogged = (Waterlogged) BLOCK_PLACEdData; Waterlogged waterlogged = (Waterlogged) blockData;
waterlogged.setWaterlogged(true); waterlogged.setWaterlogged(true);
return waterlogged; return waterlogged;
} }
@ -498,7 +495,7 @@ public class Util extends Queue {
continue; continue;
} }
if ((oldItem == null && newItem != null) || !oldItem.equals(newItem)) { if (oldItem == null || !oldItem.equals(newItem)) {
return false; return false;
} }
} }
@ -524,18 +521,12 @@ public class Util extends Queue {
return false; return false;
} }
if (oldItem == null && newItem != null) { if (oldItem == null) {
return true; return true;
} }
if (newItem.equals(oldItem)) { if (!newItem.equals(oldItem)) {
continue; return (newItem.isSimilar(oldItem) && newItem.getAmount() > oldItem.getAmount());
}
else if (newItem.isSimilar(oldItem) && newItem.getAmount() > oldItem.getAmount()) {
return true;
}
else {
return false;
} }
} }
@ -670,8 +661,7 @@ public class Util extends Queue {
public static ItemStack[] getContainerContents(Material type, Object container, Location location) { public static ItemStack[] getContainerContents(Material type, Object container, Location location) {
ItemStack[] contents = null; ItemStack[] contents = null;
if (Config.getConfig(location.getWorld()).ITEM_TRANSACTIONS) { if (Config.getConfig(location.getWorld()).ITEM_TRANSACTIONS && BlockGroup.CONTAINERS.contains(type)) {
if (BlockGroup.CONTAINERS.contains(type)) {
try { try {
// container may be null if called from within WorldEdit logger // container may be null if called from within WorldEdit logger
if (container == null) { if (container == null) {
@ -713,23 +703,23 @@ public class Util extends Queue {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
return contents; return contents;
} }
public static Inventory getContainerInventory(BlockState block_state, boolean singleBlock) { public static Inventory getContainerInventory(BlockState blockState, boolean singleBlock) {
Inventory inventory = null; Inventory inventory = null;
try { try {
if (block_state instanceof BlockInventoryHolder) { if (blockState instanceof BlockInventoryHolder) {
if (singleBlock) { if (singleBlock) {
List<Material> chests = Arrays.asList(Material.CHEST, Material.TRAPPED_CHEST); List<Material> chests = Arrays.asList(Material.CHEST, Material.TRAPPED_CHEST);
Material block_type = block_state.getType(); Material type = blockState.getType();
if (chests.contains(block_type)) { if (chests.contains(type)) {
inventory = ((Chest) block_state).getBlockInventory(); inventory = ((Chest) blockState).getBlockInventory();
} }
} }
if (inventory == null) { if (inventory == null) {
inventory = ((BlockInventoryHolder) block_state).getInventory(); inventory = ((BlockInventoryHolder) blockState).getInventory();
} }
} }
} }
@ -798,9 +788,8 @@ public class Util extends Queue {
EntityType entitytype = null; EntityType entitytype = null;
if (ConfigHandler.entitiesReversed.get(id) != null) { if (ConfigHandler.entitiesReversed.get(id) != null) {
String name = ConfigHandler.entitiesReversed.get(id); String name = ConfigHandler.entitiesReversed.get(id);
if (name.contains("minecraft:")) { if (name.contains(NAMESPACE)) {
String[] block_name_split = name.split(":"); name = name.split(":")[1];
name = block_name_split[1];
} }
entitytype = EntityType.valueOf(name.toUpperCase(Locale.ROOT)); entitytype = EntityType.valueOf(name.toUpperCase(Locale.ROOT));
} }
@ -811,7 +800,7 @@ public class Util extends Queue {
// Name entered by user // Name entered by user
EntityType type = null; EntityType type = null;
name = name.toLowerCase(Locale.ROOT).trim(); name = name.toLowerCase(Locale.ROOT).trim();
if (name.contains("minecraft:")) { if (name.contains(NAMESPACE)) {
name = (name.split(":"))[1]; name = (name.split(":"))[1];
} }
@ -822,13 +811,13 @@ public class Util extends Queue {
return type; return type;
} }
public static int getHangingDelay(Map<String, Integer> hanging_delay, int row_wid, int row_x, int row_y, int row_z) { public static int getHangingDelay(Map<String, Integer> hangingDelay, int wid, int x, int y, int z) {
String token = row_wid + "." + row_x + "." + row_y + "." + row_z; String token = wid + "." + x + "." + y + "." + z;
int delay = 0; int delay = 0;
if (hanging_delay.get(token) != null) { if (hangingDelay.get(token) != null) {
delay = hanging_delay.get(token) + 1; delay = hangingDelay.get(token) + 1;
} }
hanging_delay.put(token, delay); hangingDelay.put(token, delay);
return delay; return delay;
} }
@ -881,9 +870,8 @@ public class Util extends Queue {
Material material = null; Material material = null;
if (ConfigHandler.materialsReversed.get(id) != null && id > 0) { if (ConfigHandler.materialsReversed.get(id) != null && id > 0) {
String name = ConfigHandler.materialsReversed.get(id).toUpperCase(Locale.ROOT); String name = ConfigHandler.materialsReversed.get(id).toUpperCase(Locale.ROOT);
if (name.contains("MINECRAFT:")) { if (name.contains(NAMESPACE.toUpperCase(Locale.ROOT))) {
String[] block_name_split = name.split(":"); name = name.split(":")[1];
name = block_name_split[1];
} }
name = BukkitAdapter.ADAPTER.parseLegacyName(name); name = BukkitAdapter.ADAPTER.parseLegacyName(name);
@ -898,9 +886,8 @@ public class Util extends Queue {
Material material = null; Material material = null;
name = name.toUpperCase(Locale.ROOT).trim(); name = name.toUpperCase(Locale.ROOT).trim();
if (!name.startsWith("#")) { if (!name.startsWith("#")) {
if (name.contains("MINECRAFT:")) { if (name.contains(NAMESPACE.toUpperCase(Locale.ROOT))) {
String[] block_name_split = name.split(":"); name = name.split(":")[1];
name = block_name_split[1];
} }
name = BukkitAdapter.ADAPTER.parseLegacyName(name); name = BukkitAdapter.ADAPTER.parseLegacyName(name);
@ -1057,15 +1044,15 @@ public class Util extends Queue {
String result = ""; String result = "";
name = name.replaceFirst("#", "").toLowerCase(Locale.ROOT).trim(); name = name.replaceFirst("#", "").toLowerCase(Locale.ROOT).trim();
for (World world : Bukkit.getServer().getWorlds()) { for (World world : Bukkit.getServer().getWorlds()) {
String world_name = world.getName(); String worldName = world.getName();
if (world_name.toLowerCase(Locale.ROOT).equals(name)) { if (worldName.toLowerCase(Locale.ROOT).equals(name)) {
result = world.getName(); result = world.getName();
break; break;
} }
else if (world_name.toLowerCase(Locale.ROOT).endsWith(name)) { else if (worldName.toLowerCase(Locale.ROOT).endsWith(name)) {
result = world.getName(); result = world.getName();
} }
else if (world_name.toLowerCase(Locale.ROOT).replaceAll("[^a-zA-Z0-9]", "").endsWith(name)) { else if (worldName.toLowerCase(Locale.ROOT).replaceAll("[^a-zA-Z0-9]", "").endsWith(name)) {
result = world.getName(); result = world.getName();
} }
} }
@ -1190,8 +1177,12 @@ public class Util extends Queue {
case 6: case 6:
name = "polished_andesite"; name = "polished_andesite";
break; break;
default:
name = "stone";
break;
} }
} }
return name; return name;
} }
@ -1249,26 +1240,25 @@ public class Util extends Queue {
return branch; return branch;
} }
public static boolean newVersion(Integer[] old_version, Integer[] current_version) { public static boolean newVersion(Integer[] oldVersion, Integer[] currentVersion) {
boolean result = false; if (oldVersion[0] < currentVersion[0]) {
if (old_version[0] < current_version[0]) {
// Major version // Major version
result = true; return true;
} }
else if (old_version[0] == current_version[0] && old_version[1] < current_version[1]) { else if (oldVersion[0].equals(currentVersion[0]) && oldVersion[1] < currentVersion[1]) {
// Minor version // Minor version
result = true; return true;
} }
else if (old_version.length < 3 && current_version.length >= 3 && old_version[0] == current_version[0] && old_version[1] == current_version[1] && 0 < current_version[2]) { else if (oldVersion.length < 3 && currentVersion.length >= 3 && oldVersion[0].equals(currentVersion[0]) && oldVersion[1].equals(currentVersion[1]) && 0 < currentVersion[2]) {
// Revision version (#.# vs #.#.#) // Revision version (#.# vs #.#.#)
result = true; return true;
} }
else if (old_version.length >= 3 && current_version.length >= 3 && old_version[0] == current_version[0] && old_version[1] == current_version[1] && old_version[2] < current_version[2]) { else if (oldVersion.length >= 3 && currentVersion.length >= 3 && oldVersion[0].equals(currentVersion[0]) && oldVersion[1].equals(currentVersion[1]) && oldVersion[2] < currentVersion[2]) {
// Revision version (#.#.# vs #.#.#) // Revision version (#.#.# vs #.#.#)
result = true; return true;
} }
return result; return false;
} }
public static boolean newVersion(Integer[] oldVersion, String currentVersion) { public static boolean newVersion(Integer[] oldVersion, String currentVersion) {
@ -1291,31 +1281,6 @@ public class Util extends Queue {
return newVersion(convertArray(oldVersionSplit), convertArray(currentVersionSplit)); return newVersion(convertArray(oldVersionSplit), convertArray(currentVersionSplit));
} }
public static String[] parseCSVString(String string) {
String[] result;
if (string.indexOf("\"") > -1) {
result = csvSplitter.split(string, -1);
}
else {
result = string.split(",", -1);
}
for (int i = 0; i < result.length; i++) {
String value = result[i];
if (value.length() == 0) {
value = null;
}
else if (string.indexOf("\"") > -1) {
value = value.replaceAll("^\"|\"$", "");
value = value.replaceAll("\"\"", "\"");
}
result[i] = value;
}
return result;
}
public static Map<Integer, Object> serializeItemStackLegacy(ItemStack itemStack, int slot) { public static Map<Integer, Object> serializeItemStackLegacy(ItemStack itemStack, int slot) {
Map<Integer, Object> result = new HashMap<>(); Map<Integer, Object> result = new HashMap<>();
Map<String, Object> itemMap = serializeItemStack(itemStack, slot); Map<String, Object> itemMap = serializeItemStack(itemStack, slot);
@ -1375,8 +1340,8 @@ public class Util extends Queue {
List<Object> meta = new ArrayList<>(); List<Object> meta = new ArrayList<>();
try { try {
if (block instanceof CommandBlock) { if (block instanceof CommandBlock) {
CommandBlock command_block = (CommandBlock) block; CommandBlock commandBlock = (CommandBlock) block;
String command = command_block.getCommand(); String command = commandBlock.getCommand();
if (command.length() > 0) { if (command.length() > 0) {
meta.add(command); meta.add(command);
} }
@ -1405,7 +1370,8 @@ public class Util extends Queue {
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (meta.size() == 0) {
if (meta.isEmpty()) {
meta = null; meta = null;
} }
return meta; return meta;
@ -1429,7 +1395,7 @@ public class Util extends Queue {
}, delay); }, delay);
} }
public static void sendBlockChange(Player player, Location location, Material type, BlockData blockData) { public static void sendBlockChange(Player player, Location location, BlockData blockData) {
player.sendBlockChange(location, blockData); player.sendBlockChange(location, blockData);
} }
@ -1469,7 +1435,7 @@ public class Util extends Queue {
location.setZ(location.getZ() + 0.50); location.setZ(location.getZ() + 0.50);
Entity entity = block.getLocation().getWorld().spawnEntity(location, type); Entity entity = block.getLocation().getWorld().spawnEntity(location, type);
if (list.size() == 0) { if (list.isEmpty()) {
return; return;
} }
@ -1769,7 +1735,7 @@ public class Util extends Queue {
merchantRecipe.setIngredients(merchantIngredients); merchantRecipe.setIngredients(merchantIngredients);
merchantRecipes.add(merchantRecipe); merchantRecipes.add(merchantRecipe);
} }
if (merchantRecipes.size() > 0) { if (!merchantRecipes.isEmpty()) {
abstractVillager.setRecipes(merchantRecipes); abstractVillager.setRecipes(merchantRecipes);
} }
} }
@ -1793,14 +1759,12 @@ public class Util extends Queue {
raider.setPatrolLeader(set); raider.setPatrolLeader(set);
} }
if (entity instanceof Spellcaster) { if (entity instanceof Spellcaster && count == 1) {
if (count == 1) {
Spellcaster spellcaster = (Spellcaster) entity; Spellcaster spellcaster = (Spellcaster) entity;
Spell set = (Spell) value; Spell set = (Spell) value;
spellcaster.setSpell(set); spellcaster.setSpell(set);
} }
} }
}
else if (entity instanceof Wolf) { else if (entity instanceof Wolf) {
Wolf wolf = (Wolf) entity; Wolf wolf = (Wolf) entity;
if (count == 0) { if (count == 0) {
@ -1890,8 +1854,7 @@ public class Util extends Queue {
horse.getInventory().setArmor(set); horse.getInventory().setArmor(set);
} }
} }
else if (count == 12) { else if (count == 12 && value != null) {
if (value != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
org.bukkit.Color set = org.bukkit.Color.deserialize((Map<String, Object>) value); org.bukkit.Color set = org.bukkit.Color.deserialize((Map<String, Object>) value);
ItemStack armor = horse.getInventory().getArmor(); ItemStack armor = horse.getInventory().getArmor();
@ -1905,7 +1868,6 @@ public class Util extends Queue {
} }
} }
} }
}
else if (entity instanceof ChestedHorse) { else if (entity instanceof ChestedHorse) {
if (count == 7) { if (count == 7) {
ChestedHorse chestedHorse = (ChestedHorse) entity; ChestedHorse chestedHorse = (ChestedHorse) entity;
@ -1945,44 +1907,40 @@ public class Util extends Queue {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try { try {
Block block = blockstate.getBlock(); Block block = blockstate.getBlock();
int row_x = block.getX(); int x = block.getX();
int row_y = block.getY(); int y = block.getY();
int row_z = block.getZ(); int z = block.getZ();
for (Entity e : block.getChunk().getEntities()) { for (Entity e : block.getChunk().getEntities()) {
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) { if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
Location el = e.getLocation(); Location el = e.getLocation();
if (el.getBlockX() == row_x && el.getBlockY() == row_y && el.getBlockZ() == row_z) { if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
e.remove(); e.remove();
break; break;
} }
} }
} }
int dx1 = row_x + 1; Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
int dx2 = row_x - 1; Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
int dz1 = row_z + 1; Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
int dz2 = row_z - 1; Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
Block c1 = block.getWorld().getBlockAt(dx1, row_y, row_z);
Block c2 = block.getWorld().getBlockAt(dx2, row_y, row_z);
Block c3 = block.getWorld().getBlockAt(row_x, row_y, dz1);
Block c4 = block.getWorld().getBlockAt(row_x, row_y, dz2);
BlockFace face_set = null; BlockFace faceSet = null;
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) { if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
face_set = BlockFace.WEST; faceSet = BlockFace.WEST;
block = c1; block = c1;
} }
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) { else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
face_set = BlockFace.EAST; faceSet = BlockFace.EAST;
block = c2; block = c2;
} }
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) { else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
face_set = BlockFace.NORTH; faceSet = BlockFace.NORTH;
block = c3; block = c3;
} }
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) { else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
face_set = BlockFace.SOUTH; faceSet = BlockFace.SOUTH;
block = c4; block = c4;
} }
@ -2000,58 +1958,58 @@ public class Util extends Queue {
face = BlockFace.SOUTH; face = BlockFace.SOUTH;
} }
if (face_set != null && face != null) { if (faceSet != null && face != null) {
if (rowType.equals(Material.PAINTING)) { if (rowType.equals(Material.PAINTING)) {
String art_name = Util.getArtName(rowData); String name = Util.getArtName(rowData);
Art painting = Art.getByName(art_name.toUpperCase(Locale.ROOT)); Art painting = Art.getByName(name.toUpperCase(Locale.ROOT));
int height = painting.getBlockHeight(); int height = painting.getBlockHeight();
int width = painting.getBlockWidth(); int width = painting.getBlockWidth();
int painting_x = row_x; int paintingX = x;
int painting_y = row_y; int paintingY = y;
int painting_z = row_z; int paintingZ = z;
if (height != 1 || width != 1) { if (height != 1 || width != 1) {
if (height > 1) { if (height > 1) {
if (height != 3) { if (height != 3) {
painting_y = painting_y - 1; paintingY = paintingY - 1;
} }
} }
if (width > 1) { if (width > 1) {
if (face_set.equals(BlockFace.WEST)) { if (faceSet.equals(BlockFace.WEST)) {
painting_z--; paintingZ--;
} }
else if (face_set.equals(BlockFace.SOUTH)) { else if (faceSet.equals(BlockFace.SOUTH)) {
painting_x--; paintingX--;
} }
} }
} }
Block spawn_block = block.getRelative(face); Block spawnBlock = block.getRelative(face);
Util.setTypeAndData(spawn_block, Material.AIR, null, true); Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
Painting hanging = null; Painting hanging = null;
try { try {
hanging = block.getWorld().spawn(spawn_block.getLocation(), Painting.class); hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
} }
catch (Exception e) { catch (Exception e) {
} }
if (hanging != null) { if (hanging != null) {
hanging.teleport(block.getWorld().getBlockAt(painting_x, painting_y, painting_z).getLocation()); hanging.teleport(block.getWorld().getBlockAt(paintingX, paintingY, paintingZ).getLocation());
hanging.setFacingDirection(face_set, true); hanging.setFacingDirection(faceSet, true);
hanging.setArt(painting, true); hanging.setArt(painting, true);
} }
} }
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) { else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
try { try {
Block spawn_block = block.getRelative(face); Block spawnBlock = block.getRelative(face);
Util.setTypeAndData(spawn_block, Material.AIR, null, true); Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType); Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
Entity entity = block.getWorld().spawn(spawn_block.getLocation(), itemFrame); Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
if (entity != null && entity instanceof ItemFrame) { if (entity instanceof ItemFrame) {
ItemFrame hanging = (ItemFrame) entity; ItemFrame hanging = (ItemFrame) entity;
hanging.teleport(block.getWorld().getBlockAt(row_x, row_y, row_z).getLocation()); hanging.teleport(block.getWorld().getBlockAt(x, y, z).getLocation());
hanging.setFacingDirection(face_set, true); hanging.setFacingDirection(faceSet, true);
Material row_data_material = Util.getType(rowData); Material type = Util.getType(rowData);
if (row_data_material != null) { if (type != null) {
ItemStack istack = new ItemStack(row_data_material, 1); ItemStack istack = new ItemStack(type, 1);
hanging.setItem(istack); hanging.setItem(istack);
} }
} }
@ -2084,22 +2042,23 @@ public class Util extends Queue {
return result; return result;
} }
public static String[] toStringArray(String[] data) { public static String[] toStringArray(String[] array) {
int size = data.length; int size = array.length;
if (size == 11) { if (size == 11) {
String action_time = data[0]; String time = array[0];
String action_player = data[1]; String user = array[1];
String action_x = data[2]; String x = array[2];
String action_y = data[3]; String y = array[3];
String action_z = data[4]; String z = array[4];
String action_type = data[5]; String type = array[5];
String action_data = data[6]; String data = array[6];
String action_action = data[7]; String action = array[7];
String action_rb = data[8]; String rolledBack = array[8];
String action_wid = data[9]; String wid = array[9];
String action_blockdata = data[10]; String blockData = array[10];
return new String[] { action_time, action_player, action_x, action_y, action_z, action_type, action_data, action_action, action_rb, action_wid, "", "", action_blockdata }; return new String[] { time, user, x, y, z, type, data, action, rolledBack, wid, "", "", blockData };
} }
return null; return null;
} }