mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Reformat code
This commit is contained in:
parent
fa2dbb2b89
commit
11ccfe7ac4
@ -32,8 +32,7 @@ import java.util.HashSet;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ChunkListener implements Listener {
|
||||
@SuppressWarnings("unused") public class ChunkListener implements Listener {
|
||||
|
||||
private RefMethod methodGetHandleChunk;
|
||||
private RefField mustSave;
|
||||
|
@ -18,8 +18,7 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EntityPortal_1_7_9 implements Listener {
|
||||
@SuppressWarnings("unused") public class EntityPortal_1_7_9 implements Listener {
|
||||
private static boolean ignoreTP = false;
|
||||
|
||||
public EntityPortal_1_7_9() {
|
||||
|
@ -16,8 +16,7 @@ import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EntitySpawnListener implements Listener {
|
||||
@SuppressWarnings("unused") public class EntitySpawnListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(EntitySpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
@ -16,8 +16,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ForceFieldListener {
|
||||
@SuppressWarnings("unused") public class ForceFieldListener {
|
||||
|
||||
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||
Set<PlotPlayer> players = new HashSet<>();
|
||||
|
@ -56,8 +56,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Player Events involving plots.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEvents extends PlotListener implements Listener {
|
||||
@SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
private boolean pistonBlocks = true;
|
||||
private float lastRadius;
|
||||
@ -175,7 +174,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
case ZOMBIE_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
// 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 CAVE_SPIDER:
|
||||
case CREEPER:
|
||||
@ -204,14 +204,16 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
case VEX:
|
||||
case ZOMBIE_VILLAGER:
|
||||
// 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:
|
||||
if (entity instanceof LivingEntity) {
|
||||
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) {
|
||||
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);
|
||||
} else {
|
||||
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP);
|
||||
}
|
||||
@ -943,8 +945,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings.fromLegacyId(PlotSquared.get().worldedit
|
||||
.getConfiguration().wandItem).getMaterial()) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings
|
||||
.fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem)
|
||||
.getMaterial()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1202,8 +1205,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
|
||||
Block block = event.getBlock();
|
||||
if (destroy.isPresent() && destroy.get()
|
||||
.contains(PlotBlock.get(block.getType().name()))
|
||||
|| Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||
.contains(PlotBlock.get(block.getType().name())) || Permissions
|
||||
.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
@ -1679,8 +1682,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings.fromLegacyId(PlotSquared.get().worldedit
|
||||
.getConfiguration().wandItem).getMaterial()) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings
|
||||
.fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem)
|
||||
.getMaterial()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1991,8 +1995,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
|
||||
Block block = event.getBlockClicked();
|
||||
if (use.isPresent() && use.get()
|
||||
.contains(PlotBlock.get(block.getType().name()))) {
|
||||
if (use.isPresent() && use.get().contains(PlotBlock.get(block.getType().name()))) {
|
||||
return;
|
||||
}
|
||||
if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
|
@ -14,8 +14,7 @@ import org.bukkit.event.block.BlockExplodeEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEvents183 implements Listener {
|
||||
@SuppressWarnings("unused") public class PlayerEvents183 implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBigBoom(BlockExplodeEvent event) {
|
||||
|
@ -32,8 +32,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
||||
@SuppressWarnings("unused") public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
|
@ -9,8 +9,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEvents_1_9 implements Listener {
|
||||
@SuppressWarnings("unused") public class PlayerEvents_1_9 implements Listener {
|
||||
|
||||
private final PlayerEvents parent;
|
||||
|
||||
|
@ -28,8 +28,7 @@ import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotPlusListener extends PlotListener implements Listener {
|
||||
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
|
||||
|
||||
private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
|
||||
private static final HashMap<String, Interval> healRunnable = new HashMap<>();
|
||||
|
@ -12,8 +12,7 @@ import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotPlusListener_1_12 implements Listener {
|
||||
@SuppressWarnings("unused") public class PlotPlusListener_1_12 implements Listener {
|
||||
|
||||
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
|
||||
LivingEntity ent = event.getEntity();
|
||||
|
@ -11,9 +11,8 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotPlusListener_Legacy implements Listener {
|
||||
|
||||
@SuppressWarnings("unused") public class PlotPlusListener_Legacy implements Listener {
|
||||
|
||||
@EventHandler public void onItemPickup(PlayerPickupItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
|
@ -19,8 +19,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SingleWorldListener implements Listener {
|
||||
@SuppressWarnings("unused") public class SingleWorldListener implements Listener {
|
||||
|
||||
private Method methodGetHandleChunk;
|
||||
private Field mustSave, done, lit, s;
|
||||
|
@ -7,13 +7,12 @@ import org.bukkit.Material;
|
||||
|
||||
public class BukkitBlockRegistry extends BlockRegistry<Material> {
|
||||
|
||||
public BukkitBlockRegistry(final Material... preInitializedItems) {
|
||||
super(Material.class, preInitializedItems);
|
||||
}
|
||||
public BukkitBlockRegistry(final Material... preInitializedItems) {
|
||||
super(Material.class, preInitializedItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlock(@NonNull final Material item) {
|
||||
return PlotBlock.get(item.name());
|
||||
}
|
||||
@Override public PlotBlock getPlotBlock(@NonNull final Material item) {
|
||||
return PlotBlock.get(item.name());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,26 +3,9 @@ package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
|
||||
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.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
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 com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -37,12 +20,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Sandstone;
|
||||
import org.bukkit.material.Step;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.WoodenStep;
|
||||
import org.bukkit.material.Wool;
|
||||
import org.bukkit.material.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil {
|
||||
|
||||
@ -80,14 +61,6 @@ import org.bukkit.material.Wool;
|
||||
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.
|
||||
*
|
||||
@ -261,6 +234,30 @@ import org.bukkit.material.Wool;
|
||||
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) {
|
||||
return getWorld(worldName) != null;
|
||||
}
|
||||
@ -379,10 +376,6 @@ import org.bukkit.material.Wool;
|
||||
return list;
|
||||
}
|
||||
|
||||
public static BukkitLegacyMappings getBukkitLegacyMappings() {
|
||||
return (BukkitLegacyMappings) PlotSquared.imp().getLegacyMappings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) {
|
||||
final World world = getWorld(worldName);
|
||||
@ -405,15 +398,6 @@ import org.bukkit.material.Wool;
|
||||
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) {
|
||||
try {
|
||||
final Material material = getMaterial(block);
|
||||
@ -450,7 +434,7 @@ import org.bukkit.material.Wool;
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||
final PlotBlock plotBlock = BukkitUtil.getBukkitLegacyMappings().fromAny(name);
|
||||
if (plotBlock != null) {
|
||||
return new StringComparison<PlotBlock>().new ComparisonResult(1, plotBlock);
|
||||
return new StringComparison<PlotBlock>().new ComparisonResult(1, plotBlock);
|
||||
}
|
||||
return BukkitUtil.getBukkitLegacyMappings().getClosestsMatch(name);
|
||||
}
|
||||
|
@ -1939,7 +1939,7 @@ import java.util.zip.ZipInputStream;
|
||||
*
|
||||
* @param alias to search plots
|
||||
* @param worldname to filter alias to a specific world [optional] null means all worlds
|
||||
* @return Set<{ @ link Plot }> empty if nothing found
|
||||
* @return Set<{ @ link Plot }> empty if nothing found
|
||||
*/
|
||||
public Set<Plot> getPlotsByAlias(@Nullable final String alias,
|
||||
@NonNull final String worldname) {
|
||||
|
@ -199,7 +199,8 @@ public class Area extends SubCommand {
|
||||
break;
|
||||
case "w":
|
||||
case "wall":
|
||||
pa.WALL_FILLING = Configuration.BLOCK_BUCKET.parseString(pair[1]);
|
||||
pa.WALL_FILLING =
|
||||
Configuration.BLOCK_BUCKET.parseString(pair[1]);
|
||||
break;
|
||||
case "b":
|
||||
case "border":
|
||||
|
@ -68,7 +68,8 @@ public class Set extends SubCommand {
|
||||
StringComparison<PlotBlock>.ComparisonResult match =
|
||||
WorldUtil.IMP.getClosestBlock(unknownBlock);
|
||||
if (match != null) {
|
||||
final String found = WorldUtil.IMP.getClosestMatchingName(match.best);
|
||||
final String found =
|
||||
WorldUtil.IMP.getClosestMatchingName(match.best);
|
||||
if (found != null) {
|
||||
MainUtil.sendMessage(player, C.DID_YOU_MEAN,
|
||||
found.toLowerCase());
|
||||
|
@ -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.util.StringComparison;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Main Configuration Utility
|
||||
*/
|
||||
@ -104,24 +104,9 @@ public class Configuration {
|
||||
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 =
|
||||
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
|
||||
@Override
|
||||
public BlockBucket parseString(final String string) {
|
||||
@Override public BlockBucket parseString(final String string) {
|
||||
if (string == null || string.isEmpty()) {
|
||||
return new BlockBucket();
|
||||
}
|
||||
@ -151,8 +136,7 @@ public class Configuration {
|
||||
return blockBucket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
@Override public boolean validateValue(final String string) {
|
||||
try {
|
||||
if (string == null || string.isEmpty()) {
|
||||
return false;
|
||||
@ -184,7 +168,6 @@ public class Configuration {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public static final SettingValue<PlotBlock[]> BLOCKLIST =
|
||||
new SettingValue<PlotBlock[]>("BLOCKLIST") {
|
||||
@Override public boolean validateValue(String string) {
|
||||
@ -263,6 +246,19 @@ public class Configuration {
|
||||
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
|
||||
*/
|
||||
|
@ -13,12 +13,18 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
|
||||
public int ROAD_HEIGHT = 64;
|
||||
public int PLOT_HEIGHT = 64;
|
||||
public int WALL_HEIGHT = 64;
|
||||
public BlockBucket MAIN_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone")); // new PlotBlock[] {PlotBlock.get("stone")};
|
||||
public BlockBucket TOP_BLOCK = BlockBucket.withSingle(PlotBlock.get("grass")); //new PlotBlock[] {PlotBlock.get("grass")};
|
||||
public BlockBucket WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone_slab")); // 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 BlockBucket MAIN_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone"));
|
||||
// new PlotBlock[] {PlotBlock.get("stone")};
|
||||
public BlockBucket TOP_BLOCK = BlockBucket.withSingle(PlotBlock.get("grass"));
|
||||
//new PlotBlock[] {PlotBlock.get("grass")};
|
||||
public BlockBucket WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone_slab"));
|
||||
// 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 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",
|
||||
Configuration.BLOCK_BUCKET),
|
||||
new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK,
|
||||
"Wall block (claimed)",
|
||||
Configuration.BLOCK_BUCKET),
|
||||
"Wall block (claimed)", Configuration.BLOCK_BUCKET),
|
||||
new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width",
|
||||
Configuration.INTEGER),
|
||||
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.ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
|
||||
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.CLAIMED_WALL_BLOCK =
|
||||
Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block_claimed"));
|
||||
|
@ -4,248 +4,236 @@ import com.github.intellectualsites.plotsquared.configuration.serialization.Conf
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
||||
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.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* A block bucket is a container of block types, where each block
|
||||
* has a specified chance of being randomly picked
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSerializable {
|
||||
@EqualsAndHashCode @SuppressWarnings({"unused", "WeakerAccess"}) public final class BlockBucket
|
||||
implements Iterable<PlotBlock>, ConfigurationSerializable {
|
||||
|
||||
private final Random random = new Random();
|
||||
private final Map<Range, PlotBlock> ranges = new HashMap<>();
|
||||
private final Map<PlotBlock, Integer> blocks;
|
||||
private final BucketIterator bucketIterator = new BucketIterator();
|
||||
private boolean compiled;
|
||||
private final Random random = new Random();
|
||||
private final Map<Range, PlotBlock> ranges = new HashMap<>();
|
||||
private final Map<PlotBlock, Integer> blocks;
|
||||
private final BucketIterator bucketIterator = new BucketIterator();
|
||||
private boolean compiled;
|
||||
|
||||
public static BlockBucket withSingle(@NonNull final PlotBlock block) {
|
||||
final BlockBucket blockBucket = new BlockBucket();
|
||||
blockBucket.addBlock(block);
|
||||
return blockBucket;
|
||||
}
|
||||
|
||||
public static BlockBucket empty() {
|
||||
final BlockBucket bucket = new BlockBucket();
|
||||
bucket.compiled = true;
|
||||
return bucket;
|
||||
}
|
||||
|
||||
public BlockBucket() {
|
||||
this.blocks = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addBlock(@NonNull final PlotBlock block) {
|
||||
this.addBlock(block, -1);
|
||||
}
|
||||
|
||||
public void addBlock(@NonNull final PlotBlock block, final int chance) {
|
||||
this.blocks.put(block, chance);
|
||||
this.compiled = false;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
if (isCompiled()) {
|
||||
return ranges.isEmpty();
|
||||
}
|
||||
return blocks.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all blocks that are configured in the bucket
|
||||
*
|
||||
* @return Immutable collection containing all blocks that can
|
||||
* be found in the bucket
|
||||
*/
|
||||
public Collection<PlotBlock> getBlocks() {
|
||||
if (!isCompiled()) {
|
||||
this.compile();
|
||||
}
|
||||
return Collections.unmodifiableCollection(this.ranges.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection containing a specified amount of randomly selected blocks
|
||||
*
|
||||
* @param count Number of blocks
|
||||
* @return Immutable collection containing randomly selected blocks
|
||||
*/
|
||||
public Collection<PlotBlock> getBlocks(final int count) {
|
||||
final List<PlotBlock> blocks = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
blocks.add(getBlock());
|
||||
}
|
||||
return Collections.unmodifiableCollection(blocks);
|
||||
}
|
||||
|
||||
public void compile() {
|
||||
if (isCompiled()) {
|
||||
return;
|
||||
public BlockBucket() {
|
||||
this.blocks = new HashMap<>();
|
||||
}
|
||||
|
||||
if (blocks.size() == 1) {
|
||||
this.ranges.put(new Range(0, 100, true), blocks.keySet().toArray(new PlotBlock[1])[0]);
|
||||
this.compiled = true;
|
||||
return;
|
||||
public static BlockBucket withSingle(@NonNull final PlotBlock block) {
|
||||
final BlockBucket blockBucket = new BlockBucket();
|
||||
blockBucket.addBlock(block);
|
||||
return blockBucket;
|
||||
}
|
||||
|
||||
final Map<PlotBlock, Integer> temp = new HashMap<>(blocks.size());
|
||||
final List<PlotBlock> unassigned = new ArrayList<>(blocks.size());
|
||||
public static BlockBucket empty() {
|
||||
final BlockBucket bucket = new BlockBucket();
|
||||
bucket.compiled = true;
|
||||
return bucket;
|
||||
}
|
||||
|
||||
int sum = 0;
|
||||
for (final Map.Entry<PlotBlock, Integer> entry : blocks.entrySet()) {
|
||||
if (entry.getValue() == -1) {
|
||||
unassigned.add(entry.getKey());
|
||||
} else {
|
||||
sum += entry.getValue();
|
||||
}
|
||||
}
|
||||
//
|
||||
// If this doesn't amount to 100 add it up to exactly 100.
|
||||
//
|
||||
if (sum < 100) {
|
||||
final int remaining = 100 - sum;
|
||||
final int perUnassigned = remaining / unassigned.size();
|
||||
for (final PlotBlock block : unassigned) {
|
||||
temp.put(block, perUnassigned);
|
||||
sum += perUnassigned;
|
||||
}
|
||||
// Make sure there isn't a tiny difference remaining
|
||||
if (sum < 100) {
|
||||
final int difference = 100 - sum;
|
||||
temp.put(unassigned.get(0), perUnassigned + difference);
|
||||
sum = 100;
|
||||
}
|
||||
} else if (!unassigned.isEmpty()) {
|
||||
C.BUCKET_ENTRIES_IGNORED.send(ConsolePlayer.getConsole());
|
||||
}
|
||||
//
|
||||
// If the sum adds up to more than 100, divide all values
|
||||
//
|
||||
if (sum > 100) {
|
||||
final double ratio = 100D / sum;
|
||||
for (final Map.Entry<PlotBlock, Integer> entry : blocks.entrySet()) {
|
||||
if (entry.getValue() == -1) {
|
||||
continue;
|
||||
public static BlockBucket deserialize(@NonNull final Map<String, Object> map) {
|
||||
if (!map.containsKey("blocks")) {
|
||||
return null;
|
||||
}
|
||||
temp.put(entry.getKey(), (int)(entry.getValue() * ratio));
|
||||
}
|
||||
} else {
|
||||
temp.forEach(temp::put);
|
||||
}
|
||||
int start = 0;
|
||||
for (final Map.Entry<PlotBlock, Integer> entry : temp.entrySet()) {
|
||||
final int rangeStart = start;
|
||||
final int rangeEnd = rangeStart + entry.getValue();
|
||||
start = rangeEnd + 1;
|
||||
final Range range = new Range(rangeStart, rangeEnd, unassigned.contains(entry.getKey()));
|
||||
this.ranges.put(range, entry.getKey());
|
||||
}
|
||||
this.blocks.clear();
|
||||
this.compiled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<PlotBlock> iterator() {
|
||||
return this.bucketIterator;
|
||||
}
|
||||
|
||||
public boolean isCompiled() {
|
||||
return this.compiled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random block out of the bucket
|
||||
*
|
||||
* @return Randomly picked block (cased on specified rates)
|
||||
*/
|
||||
public PlotBlock getBlock() {
|
||||
if (!isCompiled()) {
|
||||
this.compile();
|
||||
}
|
||||
if (this.isEmpty()) {
|
||||
return StringPlotBlock.EVERYTHING;
|
||||
}
|
||||
final int number = random.nextInt(101);
|
||||
for (final Map.Entry<Range, PlotBlock> entry : ranges.entrySet()) {
|
||||
if (entry.getKey().isInRange(number)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
// Didn't find a block? Try again
|
||||
return getBlock();
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final Iterator<Entry<Range, PlotBlock>> iterator = this.ranges.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Entry<Range, PlotBlock> entry = iterator.next();
|
||||
builder.append(entry.getValue().getRawId());
|
||||
if (!entry.getKey().isAutomatic()) {
|
||||
builder.append(":").append(entry.getKey().getWeight());
|
||||
}
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
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> {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return true;
|
||||
return Configuration.BLOCK_BUCKET.parseString(map.get("blocks").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock next() {
|
||||
return getBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor
|
||||
private final static class Range {
|
||||
|
||||
private final int min;
|
||||
private final int max;
|
||||
@Getter
|
||||
private final boolean automatic;
|
||||
|
||||
public int getWeight() {
|
||||
return max - min;
|
||||
public void addBlock(@NonNull final PlotBlock block) {
|
||||
this.addBlock(block, -1);
|
||||
}
|
||||
|
||||
public boolean isInRange(final int num) {
|
||||
return num <= max && num >= min;
|
||||
public void addBlock(@NonNull final PlotBlock block, final int chance) {
|
||||
this.blocks.put(block, chance);
|
||||
this.compiled = false;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
if (isCompiled()) {
|
||||
return ranges.isEmpty();
|
||||
}
|
||||
return blocks.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all blocks that are configured in the bucket
|
||||
*
|
||||
* @return Immutable collection containing all blocks that can
|
||||
* be found in the bucket
|
||||
*/
|
||||
public Collection<PlotBlock> getBlocks() {
|
||||
if (!isCompiled()) {
|
||||
this.compile();
|
||||
}
|
||||
return Collections.unmodifiableCollection(this.ranges.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection containing a specified amount of randomly selected blocks
|
||||
*
|
||||
* @param count Number of blocks
|
||||
* @return Immutable collection containing randomly selected blocks
|
||||
*/
|
||||
public Collection<PlotBlock> getBlocks(final int count) {
|
||||
final List<PlotBlock> blocks = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
blocks.add(getBlock());
|
||||
}
|
||||
return Collections.unmodifiableCollection(blocks);
|
||||
}
|
||||
|
||||
public void compile() {
|
||||
if (isCompiled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (blocks.size() == 1) {
|
||||
this.ranges.put(new Range(0, 100, true), blocks.keySet().toArray(new PlotBlock[1])[0]);
|
||||
this.compiled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<PlotBlock, Integer> temp = new HashMap<>(blocks.size());
|
||||
final List<PlotBlock> unassigned = new ArrayList<>(blocks.size());
|
||||
|
||||
int sum = 0;
|
||||
for (final Map.Entry<PlotBlock, Integer> entry : blocks.entrySet()) {
|
||||
if (entry.getValue() == -1) {
|
||||
unassigned.add(entry.getKey());
|
||||
} else {
|
||||
sum += entry.getValue();
|
||||
}
|
||||
}
|
||||
//
|
||||
// If this doesn't amount to 100 add it up to exactly 100.
|
||||
//
|
||||
if (sum < 100) {
|
||||
final int remaining = 100 - sum;
|
||||
final int perUnassigned = remaining / unassigned.size();
|
||||
for (final PlotBlock block : unassigned) {
|
||||
temp.put(block, perUnassigned);
|
||||
sum += perUnassigned;
|
||||
}
|
||||
// Make sure there isn't a tiny difference remaining
|
||||
if (sum < 100) {
|
||||
final int difference = 100 - sum;
|
||||
temp.put(unassigned.get(0), perUnassigned + difference);
|
||||
sum = 100;
|
||||
}
|
||||
} else if (!unassigned.isEmpty()) {
|
||||
C.BUCKET_ENTRIES_IGNORED.send(ConsolePlayer.getConsole());
|
||||
}
|
||||
//
|
||||
// If the sum adds up to more than 100, divide all values
|
||||
//
|
||||
if (sum > 100) {
|
||||
final double ratio = 100D / sum;
|
||||
for (final Map.Entry<PlotBlock, Integer> entry : blocks.entrySet()) {
|
||||
if (entry.getValue() == -1) {
|
||||
continue;
|
||||
}
|
||||
temp.put(entry.getKey(), (int) (entry.getValue() * ratio));
|
||||
}
|
||||
} else {
|
||||
temp.forEach(temp::put);
|
||||
}
|
||||
int start = 0;
|
||||
for (final Map.Entry<PlotBlock, Integer> entry : temp.entrySet()) {
|
||||
final int rangeStart = start;
|
||||
final int rangeEnd = rangeStart + entry.getValue();
|
||||
start = rangeEnd + 1;
|
||||
final Range range =
|
||||
new Range(rangeStart, rangeEnd, unassigned.contains(entry.getKey()));
|
||||
this.ranges.put(range, entry.getKey());
|
||||
}
|
||||
this.blocks.clear();
|
||||
this.compiled = true;
|
||||
}
|
||||
|
||||
@Override public Iterator<PlotBlock> iterator() {
|
||||
return this.bucketIterator;
|
||||
}
|
||||
|
||||
public boolean isCompiled() {
|
||||
return this.compiled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random block out of the bucket
|
||||
*
|
||||
* @return Randomly picked block (cased on specified rates)
|
||||
*/
|
||||
public PlotBlock getBlock() {
|
||||
if (!isCompiled()) {
|
||||
this.compile();
|
||||
}
|
||||
if (this.isEmpty()) {
|
||||
return StringPlotBlock.EVERYTHING;
|
||||
}
|
||||
final int number = random.nextInt(101);
|
||||
for (final Map.Entry<Range, PlotBlock> entry : ranges.entrySet()) {
|
||||
if (entry.getKey().isInRange(number)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
// Didn't find a block? Try again
|
||||
return getBlock();
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final Iterator<Entry<Range, PlotBlock>> iterator = this.ranges.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Entry<Range, PlotBlock> entry = iterator.next();
|
||||
builder.append(entry.getValue().getRawId());
|
||||
if (!entry.getKey().isAutomatic()) {
|
||||
builder.append(":").append(entry.getKey().getWeight());
|
||||
}
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override public Map<String, Object> serialize() {
|
||||
return ImmutableMap.of("blocks", this.toString());
|
||||
}
|
||||
|
||||
|
||||
@Getter @EqualsAndHashCode @RequiredArgsConstructor private final static class Range {
|
||||
|
||||
private final int min;
|
||||
private final int max;
|
||||
@Getter private final boolean automatic;
|
||||
|
||||
public int getWeight() {
|
||||
return max - min;
|
||||
}
|
||||
|
||||
public boolean isInRange(final int num) {
|
||||
return num <= max && num >= min;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final class BucketIterator implements Iterator<PlotBlock> {
|
||||
|
||||
@Override public boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public PlotBlock next() {
|
||||
return getBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,34 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BlockRegistry<T> {
|
||||
|
||||
@Getter
|
||||
private final Class<T> type;
|
||||
private final Map<PlotBlock, T> map = new HashMap<>();
|
||||
@Getter private final Class<T> type;
|
||||
private final Map<PlotBlock, T> map = new HashMap<>();
|
||||
|
||||
public BlockRegistry(@NonNull final Class<T> type, final T... preInitializedItems) {
|
||||
this.type = type;
|
||||
for (final T preInitializedItem : preInitializedItems) {
|
||||
this.addMapping(getPlotBlock(preInitializedItem), preInitializedItem);
|
||||
public BlockRegistry(@NonNull final Class<T> type, final T... preInitializedItems) {
|
||||
this.type = type;
|
||||
for (final T preInitializedItem : preInitializedItems) {
|
||||
this.addMapping(getPlotBlock(preInitializedItem), preInitializedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void addMapping(@NonNull final PlotBlock plotBlock, @NonNull final T t) {
|
||||
if (map.containsKey(plotBlock)) {
|
||||
return;
|
||||
public final void addMapping(@NonNull final PlotBlock plotBlock, @NonNull final T t) {
|
||||
if (map.containsKey(plotBlock)) {
|
||||
return;
|
||||
}
|
||||
this.map.put(plotBlock, t);
|
||||
}
|
||||
this.map.put(plotBlock, t);
|
||||
}
|
||||
|
||||
public abstract PlotBlock getPlotBlock(final T item);
|
||||
public abstract PlotBlock getPlotBlock(final T item);
|
||||
|
||||
public final T getItem(final PlotBlock plotBlock) {
|
||||
return this.map.get(plotBlock);
|
||||
}
|
||||
public final T getItem(final PlotBlock plotBlock) {
|
||||
return this.map.get(plotBlock);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,10 +15,8 @@ public class LegacyPlotBlock extends PlotBlock {
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public final short id;
|
||||
@Getter
|
||||
public final byte data;
|
||||
@Getter public final short id;
|
||||
@Getter public final byte data;
|
||||
|
||||
public LegacyPlotBlock(short id, byte data) {
|
||||
this.id = id;
|
||||
|
@ -5,13 +5,12 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
public class PlotItemStack {
|
||||
// public final int id;
|
||||
// public final short data;
|
||||
@Getter
|
||||
private final PlotBlock plotBlock;
|
||||
public final int amount;
|
||||
public final String name;
|
||||
public final String[] lore;
|
||||
// public final int id;
|
||||
// public final short data;
|
||||
@Getter private final PlotBlock plotBlock;
|
||||
|
||||
@Deprecated
|
||||
public PlotItemStack(final int id, final short data, final int amount, final String name,
|
||||
|
@ -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.util.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import lombok.NonNull;
|
||||
|
||||
/**
|
||||
* The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}.
|
||||
*/
|
||||
public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
|
||||
public interface PlotPlayerConverter<BaseObject> {
|
||||
PlotPlayer convert(BaseObject object);
|
||||
}
|
||||
public static final String META_LAST_PLOT = "lastplot";
|
||||
public static final String META_LOCATION = "location";
|
||||
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) {
|
||||
if (!converters.containsKey(object.getClass())) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("There is no registered PlotPlayer converter for type %s",
|
||||
throw new IllegalArgumentException(String
|
||||
.format("There is no registered PlotPlayer converter for type %s",
|
||||
object.getClass().getSimpleName()));
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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>
|
||||
* - Accepts sponge/bukkit Player (online)
|
||||
@ -304,10 +299,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
return RequiredType.PLAYER;
|
||||
}
|
||||
|
||||
/////////////// PLAYER META ///////////////
|
||||
|
||||
////////////// PARTIALLY IMPLEMENTED ///////////
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
/////////////// PLAYER META ///////////////
|
||||
|
||||
////////////// PARTIALLY IMPLEMENTED ///////////
|
||||
|
||||
/**
|
||||
* Get this player's full location (including yaw/pitch)
|
||||
@ -330,6 +323,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
*/
|
||||
public abstract Location getLocationFull();
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get this player's UUID.
|
||||
* === !IMPORTANT ===<br>
|
||||
@ -376,7 +371,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
setPersistentMeta("attrib_" + key, new byte[] {(byte) 1});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the attribute of this player.
|
||||
*
|
||||
@ -666,4 +660,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
EconHandler.manager.depositMoney(this, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public interface PlotPlayerConverter<BaseObject> {
|
||||
PlotPlayer convert(BaseObject object);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public class StringPlotBlock extends PlotBlock {
|
||||
@Getter private final String itemId;
|
||||
@Getter @Setter private BaseBlock baseBlock = null;
|
||||
private boolean isForeign = false;
|
||||
|
||||
public StringPlotBlock(@NonNull final String nameSpace, @NonNull final String itemId) {
|
||||
this.nameSpace = nameSpace.toLowerCase(Locale.ENGLISH);
|
||||
this.itemId = itemId.toLowerCase(Locale.ENGLISH);
|
||||
|
@ -10,8 +10,7 @@ import lombok.experimental.UtilityClass;
|
||||
/**
|
||||
* Entity related general utility methods
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class EntityUtil {
|
||||
@UtilityClass public final class EntityUtil {
|
||||
|
||||
private static int capNumeral(@NonNull final String flagName) {
|
||||
int i;
|
||||
|
@ -134,14 +134,16 @@ public abstract class EventUtil {
|
||||
Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
|
||||
if (use.isPresent()) {
|
||||
HashSet<PlotBlock> value = use.get();
|
||||
if (PlotBlock.containsEverything(value) || value.contains(block.getPlotBlock())) {
|
||||
if (PlotBlock.containsEverything(value) || value
|
||||
.contains(block.getPlotBlock())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
|
||||
if (destroy.isPresent()) {
|
||||
HashSet<PlotBlock> value = destroy.get();
|
||||
if (PlotBlock.containsEverything(value) || value.contains(block.getPlotBlock())) {
|
||||
if (PlotBlock.containsEverything(value) || value
|
||||
.contains(block.getPlotBlock())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user