Reformat code

This commit is contained in:
dordsor21 2018-12-19 23:26:20 +00:00
parent fa2dbb2b89
commit 11ccfe7ac4
27 changed files with 365 additions and 401 deletions

View File

@ -32,8 +32,7 @@ import java.util.HashSet;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class ChunkListener implements Listener {
public class ChunkListener implements Listener {
private RefMethod methodGetHandleChunk; private RefMethod methodGetHandleChunk;
private RefField mustSave; private RefField mustSave;

View File

@ -18,8 +18,7 @@ import org.bukkit.plugin.Plugin;
import java.util.List; import java.util.List;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class EntityPortal_1_7_9 implements Listener {
public class EntityPortal_1_7_9 implements Listener {
private static boolean ignoreTP = false; private static boolean ignoreTP = false;
public EntityPortal_1_7_9() { public EntityPortal_1_7_9() {

View File

@ -16,8 +16,7 @@ import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class EntitySpawnListener implements Listener {
public class EntitySpawnListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void creatureSpawnEvent(EntitySpawnEvent event) { public void creatureSpawnEvent(EntitySpawnEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();

View File

@ -16,8 +16,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class ForceFieldListener {
public class ForceFieldListener {
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) { private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
Set<PlotPlayer> players = new HashSet<>(); Set<PlotPlayer> players = new HashSet<>();

View File

@ -56,8 +56,7 @@ import java.util.regex.Pattern;
/** /**
* Player Events involving plots. * Player Events involving plots.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener {
public class PlayerEvents extends PlotListener implements Listener {
private boolean pistonBlocks = true; private boolean pistonBlocks = true;
private float lastRadius; private float lastRadius;
@ -175,7 +174,8 @@ public class PlayerEvents extends PlotListener implements Listener {
case ZOMBIE_HORSE: case ZOMBIE_HORSE:
case SKELETON_HORSE: case SKELETON_HORSE:
// animal // animal
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
case BLAZE: case BLAZE:
case CAVE_SPIDER: case CAVE_SPIDER:
case CREEPER: case CREEPER:
@ -204,14 +204,16 @@ public class PlayerEvents extends PlotListener implements Listener {
case VEX: case VEX:
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
// monster // monster
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
default: default:
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
if (entity instanceof Animals) { if (entity instanceof Animals) {
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
} else if (entity instanceof Monster) { } else if (entity instanceof Monster) {
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, return EntityUtil
Flags.HOSTILE_CAP); .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
} else { } else {
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP); return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP);
} }
@ -943,8 +945,9 @@ public class PlayerEvents extends PlotListener implements Listener {
return; return;
} }
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings.fromLegacyId(PlotSquared.get().worldedit if (player.getInventory().getItemInMainHand().getType() == LegacyMappings
.getConfiguration().wandItem).getMaterial()) { .fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem)
.getMaterial()) {
return; return;
} }
} }
@ -1202,8 +1205,8 @@ public class PlayerEvents extends PlotListener implements Listener {
Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK); Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
Block block = event.getBlock(); Block block = event.getBlock();
if (destroy.isPresent() && destroy.get() if (destroy.isPresent() && destroy.get()
.contains(PlotBlock.get(block.getType().name())) .contains(PlotBlock.get(block.getType().name())) || Permissions
|| Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) { .hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -1679,8 +1682,9 @@ public class PlayerEvents extends PlotListener implements Listener {
return; return;
} }
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings.fromLegacyId(PlotSquared.get().worldedit if (player.getInventory().getItemInMainHand().getType() == LegacyMappings
.getConfiguration().wandItem).getMaterial()) { .fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem)
.getMaterial()) {
return; return;
} }
} }
@ -1991,8 +1995,7 @@ public class PlayerEvents extends PlotListener implements Listener {
} else if (!plot.isAdded(plotPlayer.getUUID())) { } else if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
if (use.isPresent() && use.get() if (use.isPresent() && use.get().contains(PlotBlock.get(block.getType().name()))) {
.contains(PlotBlock.get(block.getType().name()))) {
return; return;
} }
if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) { if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {

View File

@ -14,8 +14,7 @@ import org.bukkit.event.block.BlockExplodeEvent;
import java.util.Iterator; import java.util.Iterator;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlayerEvents183 implements Listener {
public class PlayerEvents183 implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBigBoom(BlockExplodeEvent event) { public void onBigBoom(BlockExplodeEvent event) {

View File

@ -32,8 +32,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlayerEvents_1_8 extends PlotListener implements Listener {
public class PlayerEvents_1_8 extends PlotListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -9,8 +9,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.LingeringPotionSplashEvent; import org.bukkit.event.entity.LingeringPotionSplashEvent;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlayerEvents_1_9 implements Listener {
public class PlayerEvents_1_9 implements Listener {
private final PlayerEvents parent; private final PlayerEvents parent;

View File

@ -28,8 +28,7 @@ import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
public class PlotPlusListener extends PlotListener implements Listener {
private static final HashMap<String, Interval> feedRunnable = new HashMap<>(); private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
private static final HashMap<String, Interval> healRunnable = new HashMap<>(); private static final HashMap<String, Interval> healRunnable = new HashMap<>();

View File

@ -12,8 +12,7 @@ import org.bukkit.event.entity.EntityPickupItemEvent;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlotPlusListener_1_12 implements Listener {
public class PlotPlusListener_1_12 implements Listener {
@EventHandler public void onItemPickup(EntityPickupItemEvent event) { @EventHandler public void onItemPickup(EntityPickupItemEvent event) {
LivingEntity ent = event.getEntity(); LivingEntity ent = event.getEntity();

View File

@ -11,8 +11,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class PlotPlusListener_Legacy implements Listener {
public class PlotPlusListener_Legacy implements Listener {
@EventHandler public void onItemPickup(PlayerPickupItemEvent event) { @EventHandler public void onItemPickup(PlayerPickupItemEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -19,8 +19,7 @@ import java.lang.reflect.Method;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
@SuppressWarnings("unused") @SuppressWarnings("unused") public class SingleWorldListener implements Listener {
public class SingleWorldListener implements Listener {
private Method methodGetHandleChunk; private Method methodGetHandleChunk;
private Field mustSave, done, lit, s; private Field mustSave, done, lit, s;

View File

@ -11,8 +11,7 @@ public class BukkitBlockRegistry extends BlockRegistry<Material> {
super(Material.class, preInitializedItems); super(Material.class, preInitializedItems);
} }
@Override @Override public PlotBlock getPlotBlock(@NonNull final Material item) {
public PlotBlock getPlotBlock(@NonNull final Material item) {
return PlotBlock.get(item.name()); return PlotBlock.get(item.name());
} }

View File

@ -3,26 +3,9 @@ package com.github.intellectualsites.plotsquared.bukkit.util;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem; import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.annotation.Nullable;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -37,12 +20,10 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.*;
import org.bukkit.material.Sandstone;
import org.bukkit.material.Step; import javax.annotation.Nullable;
import org.bukkit.material.Tree; import java.util.*;
import org.bukkit.material.WoodenStep;
import org.bukkit.material.Wool;
@SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil { @SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil {
@ -80,14 +61,6 @@ import org.bukkit.material.Wool;
return getLocation(location).getPlot(); return getLocation(location).getPlot();
} }
@Override public boolean isBlockSame(PlotBlock block1, PlotBlock block2) {
if (block1.equals(block2)) {
return true;
}
Material mat1 = getMaterial(block1), mat2 = getMaterial(block2);
return mat1 == mat2;
}
/** /**
* Get a plot based on the player location. * Get a plot based on the player location.
* *
@ -261,6 +234,30 @@ import org.bukkit.material.Wool;
location.getPitch()); location.getPitch());
} }
public static BukkitLegacyMappings getBukkitLegacyMappings() {
return (BukkitLegacyMappings) PlotSquared.imp().getLegacyMappings();
}
public static Material getMaterial(@NonNull final PlotBlock plotBlock) {
if (plotBlock instanceof StringPlotBlock) {
return Material
.getMaterial(((StringPlotBlock) plotBlock).getItemId().toUpperCase(Locale.ENGLISH));
} else {
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
return getBukkitLegacyMappings()
.fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData())
.to(Material.class);
}
}
@Override public boolean isBlockSame(PlotBlock block1, PlotBlock block2) {
if (block1.equals(block2)) {
return true;
}
Material mat1 = getMaterial(block1), mat2 = getMaterial(block2);
return mat1 == mat2;
}
@Override public boolean isWorld(@NonNull final String worldName) { @Override public boolean isWorld(@NonNull final String worldName) {
return getWorld(worldName) != null; return getWorld(worldName) != null;
} }
@ -379,10 +376,6 @@ import org.bukkit.material.Wool;
return list; return list;
} }
public static BukkitLegacyMappings getBukkitLegacyMappings() {
return (BukkitLegacyMappings) PlotSquared.imp().getLegacyMappings();
}
@Override @Override
public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) { public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) {
final World world = getWorld(worldName); final World world = getWorld(worldName);
@ -405,15 +398,6 @@ import org.bukkit.material.Wool;
return false; return false;
} }
public static Material getMaterial(@NonNull final PlotBlock plotBlock) {
if (plotBlock instanceof StringPlotBlock) {
return Material.getMaterial(((StringPlotBlock) plotBlock).getItemId().toUpperCase(Locale.ENGLISH));
} else {
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
return getBukkitLegacyMappings().fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData()).to(Material.class);
}
}
@Override public boolean isBlockSolid(@NonNull final PlotBlock block) { @Override public boolean isBlockSolid(@NonNull final PlotBlock block) {
try { try {
final Material material = getMaterial(block); final Material material = getMaterial(block);

View File

@ -199,7 +199,8 @@ public class Area extends SubCommand {
break; break;
case "w": case "w":
case "wall": case "wall":
pa.WALL_FILLING = Configuration.BLOCK_BUCKET.parseString(pair[1]); pa.WALL_FILLING =
Configuration.BLOCK_BUCKET.parseString(pair[1]);
break; break;
case "b": case "b":
case "border": case "border":

View File

@ -68,7 +68,8 @@ public class Set extends SubCommand {
StringComparison<PlotBlock>.ComparisonResult match = StringComparison<PlotBlock>.ComparisonResult match =
WorldUtil.IMP.getClosestBlock(unknownBlock); WorldUtil.IMP.getClosestBlock(unknownBlock);
if (match != null) { if (match != null) {
final String found = WorldUtil.IMP.getClosestMatchingName(match.best); final String found =
WorldUtil.IMP.getClosestMatchingName(match.best);
if (found != null) { if (found != null) {
MainUtil.sendMessage(player, C.DID_YOU_MEAN, MainUtil.sendMessage(player, C.DID_YOU_MEAN,
found.toLowerCase()); found.toLowerCase());

View File

@ -4,11 +4,11 @@ import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import java.util.ArrayList;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import java.util.ArrayList;
/** /**
* Main Configuration Utility * Main Configuration Utility
*/ */
@ -104,24 +104,9 @@ public class Configuration {
return value.best; return value.best;
} }
}; };
public static final class UnknownBlockException extends IllegalArgumentException {
@Getter
private final String unknownValue;
public UnknownBlockException(@NonNull final String unknownValue) {
super(String.format("\"%s\" is not a valid block", unknownValue));
this.unknownValue = unknownValue;
}
}
public static final SettingValue<BlockBucket> BLOCK_BUCKET = public static final SettingValue<BlockBucket> BLOCK_BUCKET =
new SettingValue<BlockBucket>("BLOCK_BUCKET") { new SettingValue<BlockBucket>("BLOCK_BUCKET") {
@Override @Override public BlockBucket parseString(final String string) {
public BlockBucket parseString(final String string) {
if (string == null || string.isEmpty()) { if (string == null || string.isEmpty()) {
return new BlockBucket(); return new BlockBucket();
} }
@ -151,8 +136,7 @@ public class Configuration {
return blockBucket; return blockBucket;
} }
@Override @Override public boolean validateValue(final String string) {
public boolean validateValue(final String string) {
try { try {
if (string == null || string.isEmpty()) { if (string == null || string.isEmpty()) {
return false; return false;
@ -184,7 +168,6 @@ public class Configuration {
return true; return true;
} }
}; };
public static final SettingValue<PlotBlock[]> BLOCKLIST = public static final SettingValue<PlotBlock[]> BLOCKLIST =
new SettingValue<PlotBlock[]>("BLOCKLIST") { new SettingValue<PlotBlock[]>("BLOCKLIST") {
@Override public boolean validateValue(String string) { @Override public boolean validateValue(String string) {
@ -263,6 +246,19 @@ public class Configuration {
return result; return result;
} }
public static final class UnknownBlockException extends IllegalArgumentException {
@Getter private final String unknownValue;
public UnknownBlockException(@NonNull final String unknownValue) {
super(String.format("\"%s\" is not a valid block", unknownValue));
this.unknownValue = unknownValue;
}
}
/** /**
* Create your own SettingValue object to make the management of plotworld configuration easier * Create your own SettingValue object to make the management of plotworld configuration easier
*/ */

View File

@ -13,12 +13,18 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
public int ROAD_HEIGHT = 64; public int ROAD_HEIGHT = 64;
public int PLOT_HEIGHT = 64; public int PLOT_HEIGHT = 64;
public int WALL_HEIGHT = 64; public int WALL_HEIGHT = 64;
public BlockBucket MAIN_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone")); // new PlotBlock[] {PlotBlock.get("stone")}; public BlockBucket MAIN_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone"));
public BlockBucket TOP_BLOCK = BlockBucket.withSingle(PlotBlock.get("grass")); //new PlotBlock[] {PlotBlock.get("grass")}; // new PlotBlock[] {PlotBlock.get("stone")};
public BlockBucket WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone_slab")); // PlotBlock.get((short) 44, (byte) 0); public BlockBucket TOP_BLOCK = BlockBucket.withSingle(PlotBlock.get("grass"));
public BlockBucket CLAIMED_WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("sandstone_slab")); // PlotBlock.get((short) 44, (byte) 1); //new PlotBlock[] {PlotBlock.get("grass")};
public BlockBucket WALL_FILLING = BlockBucket.withSingle(PlotBlock.get("stone")); //PlotBlock.get((short) 1, (byte) 0); public BlockBucket WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone_slab"));
public BlockBucket ROAD_BLOCK = BlockBucket.withSingle(PlotBlock.get("quartz_block")); // PlotBlock.get((short) 155, (byte) 0); // PlotBlock.get((short) 44, (byte) 0);
public BlockBucket CLAIMED_WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("sandstone_slab"));
// PlotBlock.get((short) 44, (byte) 1);
public BlockBucket WALL_FILLING = BlockBucket.withSingle(PlotBlock.get("stone"));
//PlotBlock.get((short) 1, (byte) 0);
public BlockBucket ROAD_BLOCK = BlockBucket.withSingle(PlotBlock.get("quartz_block"));
// PlotBlock.get((short) 155, (byte) 0);
public boolean PLOT_BEDROCK = true; public boolean PLOT_BEDROCK = true;
public ClassicPlotWorld(String worldName, String id, IndependentPlotGenerator generator, public ClassicPlotWorld(String worldName, String id, IndependentPlotGenerator generator,
@ -46,8 +52,7 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block", new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block",
Configuration.BLOCK_BUCKET), Configuration.BLOCK_BUCKET),
new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK, new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK,
"Wall block (claimed)", "Wall block (claimed)", Configuration.BLOCK_BUCKET),
Configuration.BLOCK_BUCKET),
new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width", new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width",
Configuration.INTEGER), Configuration.INTEGER),
new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height", new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height",
@ -77,7 +82,8 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
this.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block")); this.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block"));
this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height")); this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
this.ROAD_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("road.block")); this.ROAD_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("road.block"));
this.WALL_FILLING = Configuration.BLOCK_BUCKET.parseString(config.getString("wall.filling")); this.WALL_FILLING =
Configuration.BLOCK_BUCKET.parseString(config.getString("wall.filling"));
this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height")); this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
this.CLAIMED_WALL_BLOCK = this.CLAIMED_WALL_BLOCK =
Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block_claimed")); Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block_claimed"));

View File

@ -4,27 +4,20 @@ import com.github.intellectualsites.plotsquared.configuration.serialization.Conf
import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.Configuration;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.*;
import java.util.Map.Entry;
/** /**
* A block bucket is a container of block types, where each block * A block bucket is a container of block types, where each block
* has a specified chance of being randomly picked * has a specified chance of being randomly picked
*/ */
@EqualsAndHashCode @EqualsAndHashCode @SuppressWarnings({"unused", "WeakerAccess"}) public final class BlockBucket
@SuppressWarnings({"unused", "WeakerAccess"}) implements Iterable<PlotBlock>, ConfigurationSerializable {
public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSerializable {
private final Random random = new Random(); private final Random random = new Random();
private final Map<Range, PlotBlock> ranges = new HashMap<>(); private final Map<Range, PlotBlock> ranges = new HashMap<>();
@ -32,6 +25,10 @@ public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSeri
private final BucketIterator bucketIterator = new BucketIterator(); private final BucketIterator bucketIterator = new BucketIterator();
private boolean compiled; private boolean compiled;
public BlockBucket() {
this.blocks = new HashMap<>();
}
public static BlockBucket withSingle(@NonNull final PlotBlock block) { public static BlockBucket withSingle(@NonNull final PlotBlock block) {
final BlockBucket blockBucket = new BlockBucket(); final BlockBucket blockBucket = new BlockBucket();
blockBucket.addBlock(block); blockBucket.addBlock(block);
@ -44,8 +41,11 @@ public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSeri
return bucket; return bucket;
} }
public BlockBucket() { public static BlockBucket deserialize(@NonNull final Map<String, Object> map) {
this.blocks = new HashMap<>(); if (!map.containsKey("blocks")) {
return null;
}
return Configuration.BLOCK_BUCKET.parseString(map.get("blocks").toString());
} }
public void addBlock(@NonNull final PlotBlock block) { public void addBlock(@NonNull final PlotBlock block) {
@ -141,7 +141,7 @@ public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSeri
if (entry.getValue() == -1) { if (entry.getValue() == -1) {
continue; continue;
} }
temp.put(entry.getKey(), (int)(entry.getValue() * ratio)); temp.put(entry.getKey(), (int) (entry.getValue() * ratio));
} }
} else { } else {
temp.forEach(temp::put); temp.forEach(temp::put);
@ -151,15 +151,15 @@ public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSeri
final int rangeStart = start; final int rangeStart = start;
final int rangeEnd = rangeStart + entry.getValue(); final int rangeEnd = rangeStart + entry.getValue();
start = rangeEnd + 1; start = rangeEnd + 1;
final Range range = new Range(rangeStart, rangeEnd, unassigned.contains(entry.getKey())); final Range range =
new Range(rangeStart, rangeEnd, unassigned.contains(entry.getKey()));
this.ranges.put(range, entry.getKey()); this.ranges.put(range, entry.getKey());
} }
this.blocks.clear(); this.blocks.clear();
this.compiled = true; this.compiled = true;
} }
@Override @Override public Iterator<PlotBlock> iterator() {
public Iterator<PlotBlock> iterator() {
return this.bucketIterator; return this.bucketIterator;
} }
@ -205,40 +205,16 @@ public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSeri
return builder.toString(); return builder.toString();
} }
@Override @Override public Map<String, Object> serialize() {
public Map<String, Object> serialize() {
return ImmutableMap.of("blocks", this.toString()); return ImmutableMap.of("blocks", this.toString());
} }
public static BlockBucket deserialize(@NonNull final Map<String, Object> map) {
if (!map.containsKey("blocks")) {
return null;
}
return Configuration.BLOCK_BUCKET.parseString(map.get("blocks").toString());
}
private final class BucketIterator implements Iterator<PlotBlock> { @Getter @EqualsAndHashCode @RequiredArgsConstructor private final static class Range {
@Override
public boolean hasNext() {
return true;
}
@Override
public PlotBlock next() {
return getBlock();
}
}
@Getter
@EqualsAndHashCode
@RequiredArgsConstructor
private final static class Range {
private final int min; private final int min;
private final int max; private final int max;
@Getter @Getter private final boolean automatic;
private final boolean automatic;
public int getWeight() { public int getWeight() {
return max - min; return max - min;
@ -248,4 +224,16 @@ public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSeri
return num <= max && num >= min; return num <= max && num >= min;
} }
} }
private final class BucketIterator implements Iterator<PlotBlock> {
@Override public boolean hasNext() {
return true;
}
@Override public PlotBlock next() {
return getBlock();
}
}
} }

View File

@ -1,14 +1,14 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import java.util.HashMap;
import java.util.Map;
public abstract class BlockRegistry<T> { public abstract class BlockRegistry<T> {
@Getter @Getter private final Class<T> type;
private final Class<T> type;
private final Map<PlotBlock, T> map = new HashMap<>(); private final Map<PlotBlock, T> map = new HashMap<>();
public BlockRegistry(@NonNull final Class<T> type, final T... preInitializedItems) { public BlockRegistry(@NonNull final Class<T> type, final T... preInitializedItems) {

View File

@ -15,10 +15,8 @@ public class LegacyPlotBlock extends PlotBlock {
} }
} }
@Getter @Getter public final short id;
public final short id; @Getter public final byte data;
@Getter
public final byte data;
public LegacyPlotBlock(short id, byte data) { public LegacyPlotBlock(short id, byte data) {
this.id = id; this.id = id;

View File

@ -5,13 +5,12 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import lombok.Getter; import lombok.Getter;
public class PlotItemStack { public class PlotItemStack {
// public final int id;
// public final short data;
@Getter
private final PlotBlock plotBlock;
public final int amount; public final int amount;
public final String name; public final String name;
public final String[] lore; public final String[] lore;
// public final int id;
// public final short data;
@Getter private final PlotBlock plotBlock;
@Deprecated @Deprecated
public PlotItemStack(final int id, final short data, final int amount, final String name, public PlotItemStack(final int id, final short data, final int amount, final String name,

View File

@ -12,46 +12,41 @@ import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAre
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import lombok.NonNull;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import lombok.NonNull;
/** /**
* The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}. * The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}.
*/ */
public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
public interface PlotPlayerConverter<BaseObject> { public static final String META_LAST_PLOT = "lastplot";
PlotPlayer convert(BaseObject object); public static final String META_LOCATION = "location";
}
private static final Map<Class, PlotPlayerConverter> converters = new HashMap<>(); private static final Map<Class, PlotPlayerConverter> converters = new HashMap<>();
private Map<String, byte[]> metaMap = new HashMap<>();
/**
* The metadata map.
*/
private ConcurrentHashMap<String, Object> meta;
public static <T> PlotPlayer from(@NonNull final T object) { public static <T> PlotPlayer from(@NonNull final T object) {
if (!converters.containsKey(object.getClass())) { if (!converters.containsKey(object.getClass())) {
throw new IllegalArgumentException( throw new IllegalArgumentException(String
String.format("There is no registered PlotPlayer converter for type %s", .format("There is no registered PlotPlayer converter for type %s",
object.getClass().getSimpleName())); object.getClass().getSimpleName()));
} }
return converters.get(object.getClass()).convert(object); return converters.get(object.getClass()).convert(object);
} }
public static <T> void registerConverter(@NonNull final Class<T> clazz, final PlotPlayerConverter<T> converter) { public static <T> void registerConverter(@NonNull final Class<T> clazz,
final PlotPlayerConverter<T> converter) {
converters.put(clazz, converter); converters.put(clazz, converter);
} }
public static final String META_LAST_PLOT = "lastplot";
public static final String META_LOCATION = "location";
private Map<String, byte[]> metaMap = new HashMap<>();
/**
* The metadata map.
*/
private ConcurrentHashMap<String, Object> meta;
/** /**
* Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)<br> * Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)<br>
* - Accepts sponge/bukkit Player (online) * - Accepts sponge/bukkit Player (online)
@ -304,10 +299,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return RequiredType.PLAYER; return RequiredType.PLAYER;
} }
/////////////// PLAYER META ///////////////
////////////// PARTIALLY IMPLEMENTED ///////////
/** /**
* Get this player's last recorded location or null if they don't any plot relevant location. * Get this player's last recorded location or null if they don't any plot relevant location.
* *
@ -321,7 +312,9 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return getLocationFull(); return getLocationFull();
} }
//////////////////////////////////////////////// /////////////// PLAYER META ///////////////
////////////// PARTIALLY IMPLEMENTED ///////////
/** /**
* Get this player's full location (including yaw/pitch) * Get this player's full location (including yaw/pitch)
@ -330,6 +323,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
*/ */
public abstract Location getLocationFull(); public abstract Location getLocationFull();
////////////////////////////////////////////////
/** /**
* Get this player's UUID. * Get this player's UUID.
* === !IMPORTANT ===<br> * === !IMPORTANT ===<br>
@ -376,7 +371,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
setPersistentMeta("attrib_" + key, new byte[] {(byte) 1}); setPersistentMeta("attrib_" + key, new byte[] {(byte) 1});
} }
/** /**
* Retrieves the attribute of this player. * Retrieves the attribute of this player.
* *
@ -666,4 +660,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
EconHandler.manager.depositMoney(this, amount); EconHandler.manager.depositMoney(this, amount);
} }
} }
public interface PlotPlayerConverter<BaseObject> {
PlotPlayer convert(BaseObject object);
}
} }

View File

@ -17,6 +17,7 @@ public class StringPlotBlock extends PlotBlock {
@Getter private final String itemId; @Getter private final String itemId;
@Getter @Setter private BaseBlock baseBlock = null; @Getter @Setter private BaseBlock baseBlock = null;
private boolean isForeign = false; private boolean isForeign = false;
public StringPlotBlock(@NonNull final String nameSpace, @NonNull final String itemId) { public StringPlotBlock(@NonNull final String nameSpace, @NonNull final String itemId) {
this.nameSpace = nameSpace.toLowerCase(Locale.ENGLISH); this.nameSpace = nameSpace.toLowerCase(Locale.ENGLISH);
this.itemId = itemId.toLowerCase(Locale.ENGLISH); this.itemId = itemId.toLowerCase(Locale.ENGLISH);

View File

@ -10,8 +10,7 @@ import lombok.experimental.UtilityClass;
/** /**
* Entity related general utility methods * Entity related general utility methods
*/ */
@UtilityClass @UtilityClass public final class EntityUtil {
public final class EntityUtil {
private static int capNumeral(@NonNull final String flagName) { private static int capNumeral(@NonNull final String flagName) {
int i; int i;

View File

@ -134,14 +134,16 @@ public abstract class EventUtil {
Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
if (use.isPresent()) { if (use.isPresent()) {
HashSet<PlotBlock> value = use.get(); HashSet<PlotBlock> value = use.get();
if (PlotBlock.containsEverything(value) || value.contains(block.getPlotBlock())) { if (PlotBlock.containsEverything(value) || value
.contains(block.getPlotBlock())) {
return true; return true;
} }
} }
Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK); Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
if (destroy.isPresent()) { if (destroy.isPresent()) {
HashSet<PlotBlock> value = destroy.get(); HashSet<PlotBlock> value = destroy.get();
if (PlotBlock.containsEverything(value) || value.contains(block.getPlotBlock())) { if (PlotBlock.containsEverything(value) || value
.contains(block.getPlotBlock())) {
return true; return true;
} }
} }