diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index a7835f8db..7d4c8bf4b 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -7,7 +7,19 @@ import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents; import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener; import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener; import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents; -import com.github.intellectualsites.plotsquared.bukkit.util.*; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitCommand; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEconHandler; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitHybridUtils; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitInventoryUtil; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSchematicHandler; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSetupUtils; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitTaskManager; +import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; +import com.github.intellectualsites.plotsquared.bukkit.util.Metrics; +import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB; import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue; import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper; import com.github.intellectualsites.plotsquared.bukkit.uuid.FileUUIDHandler; @@ -24,7 +36,6 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; import com.github.intellectualsites.plotsquared.plot.generator.HybridGen; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; @@ -35,14 +46,39 @@ import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManag import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.ChatManager; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.ConsoleColors; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation; +import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitCommandSender; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.extension.platform.Actor; import io.papermc.lib.PaperLib; import lombok.Getter; import lombok.NonNull; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -77,9 +113,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } } - private final LegacyMappings legacyMappings = new BukkitLegacyMappings(); - private final BlockRegistry blockRegistry = - new BukkitBlockRegistry(Material.values()); private int[] version; @Getter private String pluginName; @Getter private SingleWorldListener singleWorldListener; @@ -796,12 +829,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain return names; } - @Override public BlockRegistry getBlockRegistry() { - return this.blockRegistry; + @Override public Actor getConsole() { + @NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); + return wePlugin.wrapCommandSender(console); } - - @Override public LegacyMappings getLegacyMappings() { - return this.legacyMappings; - } - } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/FancyMessage.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/FancyMessage.java index 56635abb0..348f50f9a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/FancyMessage.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/FancyMessage.java @@ -19,8 +19,18 @@ import org.bukkit.inventory.ItemStack; import java.io.IOException; import java.io.StringWriter; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.logging.Level; /** diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java index bb5930228..49d399da1 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java @@ -16,7 +16,11 @@ import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.google.common.collect.Sets; @@ -24,8 +28,12 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map.Entry; +import java.util.UUID; @CommandDeclaration(command = "uuidconvert", permission = "plots.admin", description = "Debug UUID conversion", usage = "/plot uuidconvert ", diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 465fcab20..beafb2dc8 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -5,13 +5,13 @@ import com.github.intellectualsites.plotsquared.bukkit.util.block.GenChunk; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.sk89q.worldedit.math.BlockVector2; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; @@ -41,7 +41,7 @@ public class BukkitPlotGenerator extends ChunkGenerator this.plotGenerator = generator; this.platformGenerator = this; this.populators = new ArrayList<>(); - this.populators.add(new PlotBlockPopulator(this.plotGenerator)); + this.populators.add(new BlockStatePopulator(this.plotGenerator)); this.full = true; MainUtil.initCache(); } @@ -145,7 +145,7 @@ public class BukkitPlotGenerator extends ChunkGenerator if (this.platformGenerator != this) { return this.platformGenerator.generateChunkData(world, random, x, z, biome); } else { - generate(new ChunkLoc(x, z), world, result); + generate(BlockVector2.at(x, z), world, result); } } catch (Throwable e) { e.printStackTrace(); @@ -154,7 +154,7 @@ public class BukkitPlotGenerator extends ChunkGenerator return result.getChunkData(); } - private void generate(ChunkLoc loc, World world, ScopedLocalBlockQueue result) { + private void generate(BlockVector2 loc, World world, ScopedLocalBlockQueue result) { // Load if improperly loaded if (!this.loaded) { String name = world.getName(); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java index c8b57dc78..aab23d804 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java @@ -7,10 +7,9 @@ import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGe import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotId; -import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import lombok.RequiredArgsConstructor; import org.bukkit.World; @@ -46,7 +45,7 @@ import java.util.Random; for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { blockBuckets[0][(z << 4) | x] = - BlockBucket.withSingle(PlotBlock.get("bedrock")); + BlockBucket.withSingle(BlockUtil.get("bedrock")); } } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java index 9236e184a..de06df5a3 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Random; -@RequiredArgsConstructor final class PlotBlockPopulator extends BlockPopulator { +@RequiredArgsConstructor final class BlockStatePopulator extends BlockPopulator { private final IndependentPlotGenerator plotGenerator; private LocalBlockQueue queue; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ChunkListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ChunkListener.java index 5634ff02f..046c0de8f 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ChunkListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ChunkListener.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 611303552..721121ba0 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1,7 +1,7 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners; import com.github.intellectualsites.plotsquared.bukkit.BukkitMain; -import com.github.intellectualsites.plotsquared.bukkit.object.BukkitLazyBlock; +import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.PlotSquared; @@ -10,8 +10,27 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotHandler; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; +import com.github.intellectualsites.plotsquared.plot.util.EntityUtil; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.RegExUtil; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -20,21 +39,83 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.command.PluginCommand; -import org.bukkit.entity.*; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Animals; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Creature; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Fireball; +import org.bukkit.entity.Hanging; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.entity.Tameable; +import org.bukkit.entity.ThrownPotion; +import org.bukkit.entity.Vehicle; +import org.bukkit.entity.Villager; +import org.bukkit.entity.WaterMob; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.*; -import org.bukkit.event.entity.*; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.EntityBlockFormEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.LingeringPotionSplashEvent; +import org.bukkit.event.entity.PotionSplashEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.player.*; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerEggThrowEvent; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; @@ -53,8 +134,16 @@ import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; import java.lang.reflect.Field; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.function.Supplier; import java.util.regex.Pattern; /** @@ -1016,10 +1105,10 @@ import java.util.regex.Pattern; return; } if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() - .contains(PlotBlock.get(block.getType().name()))) { + .contains(BukkitAdapter.asBlockType(block.getType()))) { return; } if (Permissions @@ -1301,10 +1390,10 @@ import java.util.regex.Pattern; } PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() - .contains(PlotBlock.get(block.getType().name())) || Permissions + .contains(BukkitBlockUtil.get(block)) || Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } @@ -1536,7 +1625,7 @@ import java.util.regex.Pattern; if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) { return; } - List blocks = event.getBlocks(); + List blocks = event.getBlocks(); if (blocks.isEmpty()) { return; } @@ -1650,7 +1739,7 @@ import java.util.regex.Pattern; } } Block block = player.getTargetBlock(null, 7); - BlockState state = block.getState(); + org.bukkit.block.BlockState state = block.getState(); if (state == null) { return; } @@ -1829,9 +1918,10 @@ import java.util.regex.Pattern; Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY); if (block != null && block.getType() != Material.AIR) { Location location = BukkitUtil.getLocation(block.getLocation()); + Material finalType = type; if (!EventUtil.manager - .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, - new BukkitLazyBlock(PlotBlock.get(type.toString())), true)) { + .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asBlockType( + finalType).getDefaultState(), true)) { event.setCancelled(true); event.setUseItemInHand(Event.Result.DENY); } @@ -1849,14 +1939,14 @@ import java.util.regex.Pattern; return; } PlayerBlockEventType eventType = null; - BukkitLazyBlock lb; + Supplier lb; Location location; Action action = event.getAction(); switch (action) { case PHYSICAL: { eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; Block block = event.getClickedBlock(); - lb = new BukkitLazyBlock(block); + lb = BukkitBlockUtil.supply(block); location = BukkitUtil.getLocation(block.getLocation()); break; } @@ -2025,7 +2115,7 @@ import java.util.regex.Pattern; eventType = PlayerBlockEventType.INTERACT_BLOCK; } } - lb = new BukkitLazyBlock(PlotBlock.get(block.getType().toString())); + lb = BukkitBlockUtil.supply(block); if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK || !player.isSneaking())) { break; @@ -2044,7 +2134,7 @@ import java.util.regex.Pattern; type = offType; } // in the following, lb needs to have the material of the item in hand i.e. type - lb = new BukkitLazyBlock(PlotBlock.get(type.toString())); + lb = BukkitBlockUtil.supply(type); if (type.isBlock()) { location = BukkitUtil .getLocation(block.getRelative(event.getBlockFace()).getLocation()); @@ -2127,7 +2217,7 @@ import java.util.regex.Pattern; Block block = event.getClickedBlock(); location = BukkitUtil.getLocation(block.getLocation()); eventType = PlayerBlockEventType.BREAK_BLOCK; - lb = new BukkitLazyBlock(block); + lb = BukkitBlockUtil.supply(block); break; default: return; @@ -2386,7 +2476,7 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(pp.getUUID())) { - if (Flags.USE.contains(plot, PlotBlock.get(event.getBucket().name()))) { + if (Flags.USE.contains(plot, BukkitBlockUtil.get(block))) { return; } if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -2446,9 +2536,9 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> use = plot.getFlag(Flags.USE); + Optional> 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(BukkitBlockUtil.get(block))) { return; } if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -3004,10 +3094,10 @@ import java.util.regex.Pattern; return; } } else if (!plot.isAdded(pp.getUUID())) { - Set place = plot.getFlag(Flags.PLACE, null); + Set place = plot.getFlag(Flags.PLACE, null); if (place != null) { Block block = event.getBlock(); - if (place.contains(PlotBlock.get(block.getType().name()))) { + if (place.contains(BukkitBlockUtil.get(block))) { return; } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java new file mode 100644 index 000000000..1730ebd51 --- /dev/null +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java @@ -0,0 +1,26 @@ +package com.github.intellectualsites.plotsquared.bukkit.object; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.world.block.BlockState; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import java.util.function.Supplier; + +public class BukkitBlockUtil { + public static Supplier supply(Block block) { + return () -> BukkitAdapter.asBlockType(block.getType()).getDefaultState(); + } + + public static Supplier supply(Material type) { + return () -> BukkitAdapter.asBlockType(type).getDefaultState(); + } + + public static BlockState get(Block block) { + return get(block.getType()); + } + + public static BlockState get(Material material) { + return BukkitAdapter.asBlockType(material).getDefaultState(); + } +} diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitLazyBlock.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitLazyBlock.java deleted file mode 100644 index 0903e78d9..000000000 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitLazyBlock.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.intellectualsites.plotsquared.bukkit.object; - -import com.github.intellectualsites.plotsquared.plot.object.LazyBlock; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; -import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; -import org.bukkit.block.Block; - -public class BukkitLazyBlock extends LazyBlock { - - private StringPlotBlock pb; - - public BukkitLazyBlock(Block block) { - this.pb = (StringPlotBlock) PlotBlock.get(block.getType().toString()); - } - - public BukkitLazyBlock(StringPlotBlock pb) { - this.pb = pb; - } - - public StringPlotBlock getPlotBlock() { - return this.pb; - } - - -} diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java index 918a5ab3b..9ca1bbbae 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java @@ -4,7 +4,6 @@ import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.MathMan; @@ -12,9 +11,12 @@ import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.world.item.ItemType; import io.papermc.lib.PaperLib; import org.bukkit.GameMode; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.WeatherType; import org.bukkit.entity.Player; @@ -55,6 +57,10 @@ public class BukkitPlayer extends PlotPlayer { super.populatePersistentMetaMap(); } + @Override public Actor toActor() { + return BukkitAdapter.adapt(player); + } + @NotNull @Override public Location getLocation() { final Location location = super.getLocation(); return location == null ? BukkitUtil.getLocation(this.player) : location; @@ -277,8 +283,8 @@ public class BukkitPlayer extends PlotPlayer { this.player.setAllowFlight(fly); } - @Override public void playMusic(@NotNull final Location location, @NotNull final PlotBlock id) { - if (PlotBlock.isEverything(id) || id.isAir()) { + @Override public void playMusic(@NotNull final Location location, @NotNull final ItemType id) { + if (id.getBlockType().getMaterial().isAir()) { // Let's just stop all the discs because why not? for (final Sound sound : Arrays.stream(Sound.values()) .filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) { @@ -288,7 +294,7 @@ public class BukkitPlayer extends PlotPlayer { } else { // this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id.to(Material.class)); this.player.playSound(BukkitUtil.getLocation(location), - Sound.valueOf(id.to(Material.class).name()), Float.MAX_VALUE, 1f); + Sound.valueOf(BukkitAdapter.adapt(id).name()), Float.MAX_VALUE, 1f); } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/EntityBaseStats.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/EntityBaseStats.java index d33b4d913..c36236a5d 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/EntityBaseStats.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/EntityBaseStats.java @@ -1,6 +1,5 @@ package com.github.intellectualsites.plotsquared.bukkit.object.entity; - class EntityBaseStats { EntityWrapper passenger; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java index 769fcc9b3..a237bf96a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java @@ -8,7 +8,23 @@ import org.bukkit.Rotation; import org.bukkit.TreeSpecies; import org.bukkit.World; import org.bukkit.block.BlockFace; -import org.bukkit.entity.*; +import org.bukkit.entity.AbstractHorse; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Bat; +import org.bukkit.entity.Boat; +import org.bukkit.entity.ChestedHorse; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.Entity; +import org.bukkit.entity.IronGolem; +import org.bukkit.entity.Item; +import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Painting; +import org.bukkit.entity.Rabbit; +import org.bukkit.entity.Sheep; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Tameable; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/schematic/StateWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/schematic/StateWrapper.java index aaf5f4aa5..1d2d80198 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/schematic/StateWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/schematic/StateWrapper.java @@ -3,11 +3,15 @@ package com.github.intellectualsites.plotsquared.bukkit.object.schematic; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.ByteTag; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.ShortTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; import org.bukkit.block.Container; import org.bukkit.block.Sign; import org.bukkit.enchantments.Enchantment; @@ -23,10 +27,10 @@ import java.util.Map.Entry; public class StateWrapper { - public BlockState state = null; + public org.bukkit.block.BlockState state = null; public CompoundTag tag = null; - public StateWrapper(BlockState state) { + public StateWrapper(org.bukkit.block.BlockState state) { this.state = state; } @@ -151,7 +155,7 @@ public class StateWrapper { if (block == null) { return false; } - BlockState state = block.getState(); + org.bukkit.block.BlockState state = block.getState(); switch (tileid) { case "chest": case "beacon": diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitBlockRegistry.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitBlockRegistry.java deleted file mode 100644 index b5ac5f1fb..000000000 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitBlockRegistry.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.intellectualsites.plotsquared.bukkit.util; - -import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; -import lombok.NonNull; -import org.bukkit.Material; - -public class BukkitBlockRegistry extends BlockRegistry { - - public BukkitBlockRegistry(final Material... preInitializedItems) { - super(Material.class, preInitializedItems); - } - - @Override public PlotBlock getPlotBlock(@NonNull final Material item) { - return PlotBlock.get(item.name()); - } - -} diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java index 6771d1d3a..44bad9589 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java @@ -5,13 +5,21 @@ import com.github.intellectualsites.plotsquared.bukkit.object.entity.Replicating import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.generator.AugmentedUtils; import com.github.intellectualsites.plotsquared.plot.listener.WEExtent; -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.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotLoc; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import io.papermc.lib.PaperLib; @@ -25,30 +33,27 @@ import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.CompletableFuture; public class BukkitChunkManager extends ChunkManager { - public static boolean isIn(RegionWrapper region, int x, int z) { - return x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ; - } - - private static byte getOrdinal(Object[] list, Object value) { - for (byte i = 0; i < list.length; i++) { - if (list[i].equals(value)) { - return i; - } - } - return 0; + public static boolean isIn(CuboidRegion region, int x, int z) { + return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region.getMinimumPoint().getZ() && z <= region.getMaximumPoint().getZ(); } public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2, - RegionWrapper r1, RegionWrapper r2) { + CuboidRegion r1, CuboidRegion r2) { ContentMap map = new ContentMap(); - int relX = r2.minX - r1.minX; - int relZ = r2.minZ - r1.minZ; + int relX = r2.getMinimumPoint().getX() - r1.getMinimumPoint().getX(); + int relZ = r2.getMinimumPoint().getZ() - r1.getMinimumPoint().getZ(); map.saveEntitiesIn(pos1, r1, relX, relZ, true); map.saveEntitiesIn(pos2, r2, -relX, -relZ, true); @@ -65,8 +70,8 @@ public class BukkitChunkManager extends ChunkManager { LocalBlockQueue queue1 = GlobalBlockQueue.IMP.getNewQueue(worldName1, false); LocalBlockQueue queue2 = GlobalBlockQueue.IMP.getNewQueue(worldName2, false); - for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) { - for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) { + for (int x = Math.max(r1.getMinimumPoint().getX(), sx); x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) { + for (int z = Math.max(r1.getMinimumPoint().getZ(), sz); z <= Math.min(r1.getMaximumPoint().getZ(), sz + 15); z++) { for (int y = 0; y < 256; y++) { Block block1 = world1.getBlockAt(x, y, z); BaseBlock baseBlock1 = bukkitWorld1.getFullBlock(BlockVector3.at(x, y, z)); @@ -104,10 +109,10 @@ public class BukkitChunkManager extends ChunkManager { return map; } - @Override public Set getChunkChunks(String world) { - Set chunks = super.getChunkChunks(world); + @Override public Set getChunkChunks(String world) { + Set chunks = super.getChunkChunks(world); for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) { - ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5); + BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5); chunks.add(loc); } return chunks; @@ -194,8 +199,8 @@ public class BukkitChunkManager extends ChunkManager { final int relX = newPos.getX() - pos1.getX(); final int relZ = newPos.getZ() - pos1.getZ(); - final RegionWrapper region = - new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + final CuboidRegion region = + RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); final World oldWorld = Bukkit.getWorld(pos1.getWorld()); final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld); final World newWorld = Bukkit.getWorld(newPos.getWorld()); @@ -210,10 +215,10 @@ public class BukkitChunkManager extends ChunkManager { int bz = value[3]; int tx = value[4]; int tz = value[5]; - ChunkLoc loc = new ChunkLoc(value[0], value[1]); - int cxx = loc.x << 4; - int czz = loc.z << 4; - PaperLib.getChunkAtAsync(oldWorld, loc.x, loc.z) + BlockVector2 loc = BlockVector2.at(value[0], value[1]); + int cxx = loc.getX() << 4; + int czz = loc.getZ() << 4; + PaperLib.getChunkAtAsync(oldWorld, loc.getX(), loc.getZ()) .thenAccept(chunk1 -> map.saveEntitiesIn(chunk1, region)).thenRun(() -> { for (int x = bx & 15; x <= (tx & 15); x++) { for (int z = bz & 15; z <= (tz & 15); z++) { @@ -256,11 +261,11 @@ public class BukkitChunkManager extends ChunkManager { final int tcx = p2x >> 4; final int tcz = p2z >> 4; - final List chunks = new ArrayList<>(); + final List chunks = new ArrayList<>(); for (int x = bcx; x <= tcx; x++) { for (int z = bcz; z <= tcz; z++) { - chunks.add(new ChunkLoc(x, z)); + chunks.add(BlockVector2.at(x, z)); } } final World worldObj = Bukkit.getWorld(world); @@ -269,9 +274,9 @@ public class BukkitChunkManager extends ChunkManager { @Override public void run() { long start = System.currentTimeMillis(); while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) { - final ChunkLoc chunk = chunks.remove(0); - int x = chunk.x; - int z = chunk.z; + final BlockVector2 chunk = chunks.remove(0); + int x = chunk.getX(); + int z = chunk.getZ(); int xxb = x << 4; int zzb = z << 4; int xxt = xxb + 15; @@ -284,7 +289,7 @@ public class BukkitChunkManager extends ChunkManager { if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z && PlotSquared.imp().getServerVersion()[1] == 13) { AugmentedUtils - .bypass(ignoreAugment, () -> queue.regenChunkSafe(chunk.x, chunk.z)); + .bypass(ignoreAugment, () -> queue.regenChunkSafe(chunk.getX(), chunk.getZ())); continue; } boolean checkX1 = false; @@ -346,8 +351,8 @@ public class BukkitChunkManager extends ChunkManager { if (checkX2 && checkZ2) { map.saveRegion(bukkitWorldObj, xxt2, xxt, zzt2, zzt); // } - RegionWrapper currentPlotClear = - new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + CuboidRegion currentPlotClear = + RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); map.saveEntitiesOut(chunkObj, currentPlotClear); AugmentedUtils.bypass(ignoreAugment, () -> setChunkInPlotArea(null, new RunnableVal() { @@ -365,7 +370,7 @@ public class BukkitChunkManager extends ChunkManager { if (id != null) { value.setBlock(x1, y, z1, id); } else { - value.setBlock(x1, y, z1, PlotBlock.get("air")); + value.setBlock(x1, y, z1, BlockUtil.get("air")); } } for (int y = Math.min(128, ids.length); @@ -393,17 +398,17 @@ public class BukkitChunkManager extends ChunkManager { return true; } - @Override public CompletableFuture loadChunk(String world, ChunkLoc chunkLoc, boolean force) { - return PaperLib.getChunkAtAsync(BukkitUtil.getWorld(world),chunkLoc.x, chunkLoc.z, force); + @Override public CompletableFuture loadChunk(String world, BlockVector2 chunkLoc, boolean force) { + return PaperLib.getChunkAtAsync(BukkitUtil.getWorld(world),chunkLoc.getX(), chunkLoc.getZ(), force); } @Override - public void unloadChunk(final String world, final ChunkLoc chunkLoc, final boolean save) { + public void unloadChunk(final String world, final BlockVector2 chunkLoc, final boolean save) { if (!PlotSquared.get().isMainThread(Thread.currentThread())) { TaskManager.runTask( - () -> BukkitUtil.getWorld(world).unloadChunk(chunkLoc.x, chunkLoc.z, save)); + () -> BukkitUtil.getWorld(world).unloadChunk(chunkLoc.getX(), chunkLoc.getZ(), save)); } else { - BukkitUtil.getWorld(world).unloadChunk(chunkLoc.x, chunkLoc.z, save); + BukkitUtil.getWorld(world).unloadChunk(chunkLoc.getX(), chunkLoc.getZ(), save); } } @@ -430,10 +435,10 @@ public class BukkitChunkManager extends ChunkManager { @Override public void swap(Location bot1, Location top1, Location bot2, Location top2, final Runnable whenDone) { - RegionWrapper region1 = - new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); - RegionWrapper region2 = - new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); + CuboidRegion region1 = + RegionUtil.createRegion(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); + CuboidRegion region2 = + RegionUtil.createRegion(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); final World world1 = Bukkit.getWorld(bot1.getWorld()); World world2 = Bukkit.getWorld(bot2.getWorld()); @@ -618,7 +623,7 @@ public class BukkitChunkManager extends ChunkManager { } } - void saveEntitiesOut(Chunk chunk, RegionWrapper region) { + void saveEntitiesOut(Chunk chunk, CuboidRegion region) { for (Entity entity : chunk.getEntities()) { Location location = BukkitUtil.getLocation(entity); int x = location.getX(); @@ -635,11 +640,11 @@ public class BukkitChunkManager extends ChunkManager { } } - void saveEntitiesIn(Chunk chunk, RegionWrapper region) { + void saveEntitiesIn(Chunk chunk, CuboidRegion region) { saveEntitiesIn(chunk, region, 0, 0, false); } - void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, + void saveEntitiesIn(Chunk chunk, CuboidRegion region, int offsetX, int offsetZ, boolean delete) { for (Entity entity : chunk.getEntities()) { Location location = BukkitUtil.getLocation(entity); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitCommand.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitCommand.java index 27edabf78..190aa077a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitCommand.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitCommand.java @@ -4,7 +4,13 @@ import com.github.intellectualsites.plotsquared.bukkit.commands.DebugUUID; import com.github.intellectualsites.plotsquared.plot.commands.MainCommand; import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import org.bukkit.command.*; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import java.util.ArrayList; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java index c2e39715e..25ca0e16e 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java @@ -1,6 +1,22 @@ package com.github.intellectualsites.plotsquared.bukkit.util; -import com.github.intellectualsites.plotsquared.bukkit.events.*; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerClaimPlotEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerLeavePlotEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerPlotDeniedEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerPlotHelperEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerPlotTrustedEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlayerTeleportToPlotEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotAutoMergeEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotChangeOwnerEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotClearEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotComponentSetEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotDeleteEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotFlagAddEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotFlagRemoveEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotMergeEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotRateEvent; +import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.object.Location; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java index fb0d20fbc..95f4b2ebc 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java @@ -5,7 +5,11 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; @@ -13,7 +17,11 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -22,15 +30,16 @@ import org.bukkit.block.data.Directional; import org.bukkit.generator.ChunkGenerator; import java.util.HashSet; +import java.util.Set; public class BukkitHybridUtils extends HybridUtils { - @Override public void analyzeRegion(final String world, final RegionWrapper region, + @Override public void analyzeRegion(final String world, final CuboidRegion region, final RunnableVal whenDone) { // int diff, int variety, int vertices, int rotation, int height_sd /* * diff: compare to base by looping through all blocks - * variety: add to HashSet for each PlotBlock + * variety: add to HashSet for each BlockState * height_sd: loop over all blocks and get top block * * vertices: store air map and compare with neighbours @@ -47,8 +56,8 @@ public class BukkitHybridUtils extends HybridUtils { return; } - final Location bot = new Location(world, region.minX, region.minY, region.minZ); - final Location top = new Location(world, region.maxX, region.maxY, region.maxZ); + final Location bot = new Location(world, region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); + final Location top = new Location(world, region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); final int bx = bot.getX(); final int bz = bot.getZ(); @@ -65,8 +74,8 @@ public class BukkitHybridUtils extends HybridUtils { System.gc(); System.gc(); final BlockBucket[][][] oldBlocks = new BlockBucket[256][width][length]; - final PlotBlock[][][] newBlocks = new PlotBlock[256][width][length]; - final BlockBucket airBucket = BlockBucket.withSingle(StringPlotBlock.EVERYTHING); + final BlockState[][][] newBlocks = new BlockState[256][width][length]; + final BlockBucket airBucket = BlockBucket.withSingle(BlockTypes.AIR.getDefaultState()); PlotArea area = PlotSquared.get().getPlotArea(world, null); @@ -122,7 +131,7 @@ public class BukkitHybridUtils extends HybridUtils { for (int y = 0; y < blocks.length; y++) { if (blocks[y] != null) { result[(minY + y) >> 4][(((minY + y) & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(PlotBlock.get(blocks[y])); + BlockBucket.withSingle(blocks[y].toImmutableState()); } } } @@ -177,45 +186,45 @@ public class BukkitHybridUtils extends HybridUtils { int i = 0; for (int x = 0; x < width; x++) { for (int z = 0; z < length; z++) { - HashSet types = new HashSet<>(); + Set types = new HashSet<>(); for (int y = 0; y < 256; y++) { BlockBucket old = oldBlocks[y][x][z]; try { if (old == null) { old = airBucket; } - PlotBlock now = newBlocks[y][x][z]; + BlockState now = newBlocks[y][x][z]; if (!old.getBlocks().contains(now)) { changes[i]++; } - if (now.isAir()) { + if (now.getBlockType().getMaterial().isAir()) { air[i]++; } else { // check vertices // modifications_adjacent if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) { - if (newBlocks[y - 1][x][z].isAir()) { + if (newBlocks[y - 1][x][z].getBlockType().getMaterial().isAir()) { faces[i]++; } - if (newBlocks[y][x - 1][z].isAir()) { + if (newBlocks[y][x - 1][z].getBlockType().getMaterial().isAir()) { faces[i]++; } - if (newBlocks[y][x][z - 1].isAir()) { + if (newBlocks[y][x][z - 1].getBlockType().getMaterial().isAir()) { faces[i]++; } - if (newBlocks[y + 1][x][z].isAir()) { + if (newBlocks[y + 1][x][z].getBlockType().getMaterial().isAir()) { faces[i]++; } - if (newBlocks[y][x + 1][z].isAir()) { + if (newBlocks[y][x + 1][z].getBlockType().getMaterial().isAir()) { faces[i]++; } - if (newBlocks[y][x][z + 1].isAir()) { + if (newBlocks[y][x][z + 1].getBlockType().getMaterial().isAir()) { faces[i]++; } } - Material material = now.to(Material.class); + Material material = BukkitAdapter.adapt(now.getBlockType()); if (material != null) { BlockData blockData = material.createBlockData(); if (blockData instanceof Directional) { @@ -224,7 +233,7 @@ public class BukkitHybridUtils extends HybridUtils { data[i]++; } } - types.add(now); + types.add(now.getBlockType()); } } catch (NullPointerException e) { e.printStackTrace(); @@ -297,7 +306,7 @@ public class BukkitHybridUtils extends HybridUtils { for (int z = minZ; z <= maxZ; z++) { int zz = cbz + z; for (int y = 0; y < 256; y++) { - PlotBlock block = queue.getBlock(xx, y, zz); + BlockState block = queue.getBlock(xx, y, zz); int xr = xb + x; int zr = zb + z; newBlocks[y][xr][zr] = block; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitInventoryUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitInventoryUtil.java index 2c66f8d3f..a5a64b307 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitInventoryUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitInventoryUtil.java @@ -56,7 +56,7 @@ public class BukkitInventoryUtil extends InventoryUtil { if (item == null) { return null; } - ItemStack stack = new ItemStack(BukkitUtil.getMaterial(item.getPlotBlock()), item.amount); + ItemStack stack = new ItemStack(BukkitUtil.getMaterial(item.getBlockState()), item.amount); ItemMeta meta = null; if (item.name != null) { meta = stack.getItemMeta(); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java deleted file mode 100644 index 0331e948a..000000000 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java +++ /dev/null @@ -1,865 +0,0 @@ -package com.github.intellectualsites.plotsquared.bukkit.util; - -import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; -import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; -import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; -import com.github.intellectualsites.plotsquared.plot.util.StringComparison; -import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.ToString; -import org.bukkit.Bukkit; -import org.bukkit.Material; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * Borrowed from https://github.com/Phoenix616/IDConverter/blob/master/mappings/src/main/java/de/themoep/idconverter/IdMappings.java - * Original License: - *

- * Minecraft ID mappings Copyright (C) 2017 Max Lee (https://github.com/Phoenix616) - *

- * This program is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - *

- * You should have received a copy of the GNU General Public License along with this program. If - * not, see . - */ -public final class BukkitLegacyMappings extends LegacyMappings { - - private static final LegacyBlock[] BLOCKS = - new LegacyBlock[] {new LegacyBlock(0, "air"), new LegacyBlock(1, "stone"), - new LegacyBlock(1, 1, "stone", "granite"), - new LegacyBlock(1, 2, "stone", "polished_granite"), - new LegacyBlock(1, 3, "stone", "diorite"), - new LegacyBlock(1, 4, "stone", "polished_diorite"), - new LegacyBlock(1, 5, "stone", "andesite"), - new LegacyBlock(1, 6, "stone", "polished_andesite"), - new LegacyBlock(2, "grass", "grass_block"), new LegacyBlock(3, "dirt"), - new LegacyBlock(3, 1, "dirt", "coarse_dirt"), new LegacyBlock(3, 2, "dirt", "podzol"), - new LegacyBlock(4, "cobblestone"), new LegacyBlock(5, "wood", "oak_planks"), - new LegacyBlock(5, 1, "wood", "spruce_planks"), - new LegacyBlock(5, 2, "wood", "birch_planks"), - new LegacyBlock(5, 3, "wood", "jungle_planks"), - new LegacyBlock(5, 4, "wood", "acacia_planks"), - new LegacyBlock(5, 5, "wood", "dark_oak_planks"), - new LegacyBlock(6, "sapling", "oak_sapling"), - new LegacyBlock(6, 1, "sapling", "spruce_sapling"), - new LegacyBlock(6, 2, "sapling", "birch_sapling"), - new LegacyBlock(6, 3, "sapling", "jungle_sapling"), - new LegacyBlock(6, 4, "sapling", "acacia_sapling"), - new LegacyBlock(6, 5, "sapling", "dark_oak_sapling"), new LegacyBlock(7, "bedrock"), - new LegacyBlock(8, "water", "flowing_water"), - new LegacyBlock(9, "stationary_water", "water"), - new LegacyBlock(10, "lava", "flowing_lava"), - new LegacyBlock(11, "stationary_lava", "lava"), new LegacyBlock(12, "sand"), - new LegacyBlock(12, 1, "sand", "red_sand"), new LegacyBlock(13, "gravel"), - new LegacyBlock(14, "gold_ore"), new LegacyBlock(15, "iron_ore"), - new LegacyBlock(16, "coal_ore"), new LegacyBlock(17, "log", "oak_log"), - new LegacyBlock(17, 1, "log", "oak_log"), new LegacyBlock(17, 2, "log", "spruce_log"), - new LegacyBlock(17, 3, "log", "birch_log"), new LegacyBlock(17, 4, "log", "jungle_log"), - new LegacyBlock(17, 5, "log", "oak_bark"), new LegacyBlock(17, 6, "log", "spruce_bark"), - new LegacyBlock(17, 7, "log", "birch_bark"), - new LegacyBlock(17, 8, "log", "jungle_bark"), - new LegacyBlock(18, "leaves", "oak_leaves"), - new LegacyBlock(18, 1, "leaves", "spruce_leaves"), - new LegacyBlock(18, 2, "leaves", "birch_leaves"), - new LegacyBlock(18, 3, "leaves", "jungle_leaves"), new LegacyBlock(19, "sponge"), - new LegacyBlock(19, 1, "sponge", "wet_sponge"), new LegacyBlock(20, "glass"), - new LegacyBlock(21, "lapis_ore"), new LegacyBlock(22, "lapis_block"), - new LegacyBlock(23, "dispenser"), new LegacyBlock(24, "sandstone"), - new LegacyBlock(24, 1, "sandstone", "chiseled_sandstone"), - new LegacyBlock(24, 2, "sandstone", "cut_sandstone"), new LegacyBlock(25, "note_block"), - new LegacyBlock(26, "bed_block"), new LegacyBlock(27, "powered_rail"), - new LegacyBlock(28, "detector_rail"), - new LegacyBlock(29, "piston_sticky_base", "sticky_piston"), - new LegacyBlock(30, "web", "cobweb"), new LegacyBlock(31, "long_grass", "dead_bush"), - new LegacyBlock(31, 1, "long_grass", "grass"), - new LegacyBlock(31, 2, "long_grass", "fern"), new LegacyBlock(32, "dead_bush"), - new LegacyBlock(33, "piston_base", "piston"), - new LegacyBlock(34, "piston_extension", "piston_head"), - new LegacyBlock(35, "wool", "white_wool"), - new LegacyBlock(35, 1, "wool", "orange_wool"), - new LegacyBlock(35, 2, "wool", "magenta_wool"), - new LegacyBlock(35, 3, "wool", "light_blue_wool"), - new LegacyBlock(35, 4, "wool", "yellow_wool"), - new LegacyBlock(35, 5, "wool", "lime_wool"), - new LegacyBlock(35, 6, "wool", "pink_wool"), - new LegacyBlock(35, 7, "wool", "gray_wool"), - new LegacyBlock(35, 8, "wool", "light_gray_wool"), - new LegacyBlock(35, 9, "wool", "cyan_wool"), - new LegacyBlock(35, 10, "wool", "purple_wool"), - new LegacyBlock(35, 11, "wool", "blue_wool"), - new LegacyBlock(35, 12, "wool", "brown_wool"), - new LegacyBlock(35, 13, "wool", "green_wool"), - new LegacyBlock(35, 14, "wool", "red_wool"), - new LegacyBlock(35, 15, "wool", "black_wool"), - new LegacyBlock(36, "piston_moving_piece", "moving_piston"), - new LegacyBlock(37, "yellow_flower", "dandelion"), - new LegacyBlock(38, "red_rose", "poppy"), - new LegacyBlock(38, 1, "red_rose", "blue_orchid"), - new LegacyBlock(38, 2, "red_rose", "allium"), - new LegacyBlock(38, 3, "red_rose", "azure_bluet"), - new LegacyBlock(38, 4, "red_rose", "red_tulip"), - new LegacyBlock(38, 5, "red_rose", "orange_tulip"), - new LegacyBlock(38, 6, "red_rose", "white_tulip"), - new LegacyBlock(38, 7, "red_rose", "pink_tulip"), - new LegacyBlock(38, 8, "red_rose", "oxeye_daisy"), - new LegacyBlock(39, "brown_mushroom"), new LegacyBlock(40, "red_mushroom"), - new LegacyBlock(41, "gold_block"), new LegacyBlock(42, "iron_block"), - new LegacyBlock(43, "double_step"), - new LegacyBlock(43, 6, "double_step", "smooth_quartz"), - new LegacyBlock(43, 8, "double_step", "smooth_stone"), - new LegacyBlock(43, 9, "double_step", "smooth_sandstone"), - new LegacyBlock(44, "step", "stone_slab", "smooth_stone_slab"), - new LegacyBlock(44, 1, "step", "sandstone_slab"), - new LegacyBlock(44, 2, "step", "petrified_oak_slab"), - new LegacyBlock(44, 3, "step", "cobblestone_slab"), - new LegacyBlock(44, 4, "step", "brick_slab"), - new LegacyBlock(44, 5, "step", "stone_brick_slab"), - new LegacyBlock(44, 6, "step", "nether_brick_slab"), - new LegacyBlock(44, 7, "step", "quartz_slab"), new LegacyBlock(45, "brick", "bricks"), - new LegacyBlock(46, "tnt"), new LegacyBlock(47, "bookshelf"), - new LegacyBlock(48, "mossy_cobblestone"), new LegacyBlock(49, "obsidian"), - new LegacyBlock(50, "torch"), new LegacyBlock(50, 1, "torch", "wall_torch"), - new LegacyBlock(50, 2, "torch", "wall_torch"), - new LegacyBlock(50, 3, "torch", "wall_torch"), - new LegacyBlock(50, 4, "torch", "wall_torch"), new LegacyBlock(50, 5, "torch"), - new LegacyBlock(51, "fire"), new LegacyBlock(52, "mob_spawner"), - new LegacyBlock(53, "wood_stairs", "oak_stairs"), new LegacyBlock(54, "chest", "chest"), - new LegacyBlock(55, "redstone_wire"), new LegacyBlock(56, "diamond_ore"), - new LegacyBlock(57, "diamond_block"), - new LegacyBlock(58, "workbench", "crafting_table"), - new LegacyBlock(59, "crops", "wheat"), new LegacyBlock(60, "soil", "farmland"), - new LegacyBlock(61, "furnace"), new LegacyBlock(62, "burning_furnace"), - new LegacyBlock(63, "sign_post", "sign", "oak_sign"), - new LegacyBlock(64, "wooden_door", "oak_door"), new LegacyBlock(65, "ladder"), - new LegacyBlock(66, "rails", "rail"), new LegacyBlock(67, "cobblestone_stairs"), - new LegacyBlock(68, "wall_sign", "wall_sign", "oak_wall_sign"), - new LegacyBlock(69, "lever"), - new LegacyBlock(70, "stone_plate", "stone_pressure_plate"), - new LegacyBlock(71, "iron_door_block", "iron_door"), - new LegacyBlock(72, "wood_plate", "oak_pressure_plate"), - new LegacyBlock(73, "redstone_ore"), new LegacyBlock(74, "glowing_redstone_ore"), - new LegacyBlock(75, "redstone_torch_off"), - new LegacyBlock(76, "redstone_torch_on", "redstone_torch"), - new LegacyBlock(76, 1, "redstone_torch_on", "redstone_wall_torch"), - new LegacyBlock(76, 2, "redstone_torch_on", "redstone_wall_torch"), - new LegacyBlock(76, 3, "redstone_torch_on", "redstone_wall_torch"), - new LegacyBlock(76, 4, "redstone_torch_on", "redstone_wall_torch"), - new LegacyBlock(76, 5, "redstone_torch_on", "redstone_torch"), - new LegacyBlock(77, "stone_button"), new LegacyBlock(78, "snow"), - new LegacyBlock(79, "ice"), new LegacyBlock(80, "snow_block"), - new LegacyBlock(81, "cactus"), new LegacyBlock(82, "clay"), - new LegacyBlock(83, "sugar_cane_block", "sugar_cane"), new LegacyBlock(84, "jukebox"), - new LegacyBlock(85, "fence", "oak_fence"), - new LegacyBlock(86, "pumpkin", "carved_pumpkin"), new LegacyBlock(87, "netherrack"), - new LegacyBlock(88, "soul_sand"), new LegacyBlock(89, "glowstone"), - new LegacyBlock(90, "portal"), new LegacyBlock(91, "jack_o_lantern"), - new LegacyBlock(92, "cake_block", "cake"), new LegacyBlock(93, "diode_block_off"), - new LegacyBlock(94, "diode_block_on", "repeater"), - new LegacyBlock(95, "stained_glass", "white_stained_glass"), - new LegacyBlock(95, 1, "stained_glass", "orange_stained_glass"), - new LegacyBlock(95, 2, "stained_glass", "magenta_stained_glass"), - new LegacyBlock(95, 3, "stained_glass", "light_blue_stained_glass"), - new LegacyBlock(95, 4, "stained_glass", "yellow_stained_glass"), - new LegacyBlock(95, 5, "stained_glass", "lime_stained_glass"), - new LegacyBlock(95, 6, "stained_glass", "pink_stained_glass"), - new LegacyBlock(95, 7, "stained_glass", "gray_stained_glass"), - new LegacyBlock(95, 8, "stained_glass", "light_gray_stained_glass"), - new LegacyBlock(95, 9, "stained_glass", "cyan_stained_glass"), - new LegacyBlock(95, 10, "stained_glass", "purple_stained_glass"), - new LegacyBlock(95, 11, "stained_glass", "blue_stained_glass"), - new LegacyBlock(95, 12, "stained_glass", "brown_stained_glass"), - new LegacyBlock(95, 13, "stained_glass", "green_stained_glass"), - new LegacyBlock(95, 14, "stained_glass", "red_stained_glass"), - new LegacyBlock(95, 15, "stained_glass", "black_stained_glass"), - new LegacyBlock(96, "trap_door", "oak_trapdoor"), - new LegacyBlock(97, "monster_eggs", "infested_stone"), - new LegacyBlock(97, 1, "monster_eggs", "infested_cobblestone"), - new LegacyBlock(97, 2, "monster_eggs", "infested_stone_bricks"), - new LegacyBlock(97, 3, "monster_eggs", "infested_mossy_stone_bricks"), - new LegacyBlock(97, 4, "monster_eggs", "infested_cracked_stone_bricks"), - new LegacyBlock(97, 5, "monster_eggs", "infested_chiseled_stone_bricks"), - new LegacyBlock(98, "smooth_brick", "stone_bricks"), - new LegacyBlock(98, 1, "smooth_brick", "mossy_stone_bricks"), - new LegacyBlock(98, 2, "smooth_brick", "cracked_stone_bricks"), - new LegacyBlock(98, 3, "smooth_brick", "chiseled_bricks"), - new LegacyBlock(99, "huge_mushroom_1", "brown_mushroom_block"), - new LegacyBlock(99, 1, "huge_mushroom_1"), new LegacyBlock(99, 2, "huge_mushroom_1"), - new LegacyBlock(99, 3, "huge_mushroom_1"), new LegacyBlock(99, 4, "huge_mushroom_1"), - new LegacyBlock(99, 5, "huge_mushroom_1"), new LegacyBlock(99, 6, "huge_mushroom_1"), - new LegacyBlock(99, 7, "huge_mushroom_1"), new LegacyBlock(99, 8, "huge_mushroom_1"), - new LegacyBlock(99, 9, "huge_mushroom_1"), - new LegacyBlock(99, 10, "huge_mushroom_1", "mushroom_stem"), - new LegacyBlock(99, 14, "huge_mushroom_1"), new LegacyBlock(99, 15, "huge_mushroom_1"), - new LegacyBlock(100, "huge_mushroom_2", "red_mushroom_block"), - new LegacyBlock(100, 1, "huge_mushroom_2"), new LegacyBlock(100, 2, "huge_mushroom_2"), - new LegacyBlock(100, 3, "huge_mushroom_2"), new LegacyBlock(100, 4, "huge_mushroom_2"), - new LegacyBlock(100, 5, "huge_mushroom_2"), new LegacyBlock(100, 6, "huge_mushroom_2"), - new LegacyBlock(100, 7, "huge_mushroom_2"), new LegacyBlock(100, 8, "huge_mushroom_2"), - new LegacyBlock(100, 9, "huge_mushroom_2"), - new LegacyBlock(100, 10, "huge_mushroom_2", "mushroom_stem"), - new LegacyBlock(100, 14, "huge_mushroom_2"), - new LegacyBlock(100, 15, "huge_mushroom_2"), - new LegacyBlock(101, "iron_fence", "iron_bars"), - new LegacyBlock(102, "thin_glass", "glass_pane"), new LegacyBlock(103, "melon_block"), - new LegacyBlock(104, "pumpkin_stem"), new LegacyBlock(105, "melon_stem"), - new LegacyBlock(106, "vine"), new LegacyBlock(107, "fence_gate", "oak_fence_gate"), - new LegacyBlock(108, "brick_stairs"), - new LegacyBlock(109, "smooth_stairs", "stone_brick_stairs"), - new LegacyBlock(110, "mycel", "mycelium"), - new LegacyBlock(111, "water_lily", "lily_pad"), - new LegacyBlock(112, "nether_brick", "nether_bricks"), - new LegacyBlock(113, "nether_fence", "nether_brick_fence"), - new LegacyBlock(114, "nether_brick_stairs"), - new LegacyBlock(115, "nether_warts", "nether_wart"), - new LegacyBlock(116, "enchantment_table", "enchanting_table"), - new LegacyBlock(117, "brewing_stand"), new LegacyBlock(118, "cauldron"), - new LegacyBlock(119, "ender_portal", "end_portal"), - new LegacyBlock(120, "ender_portal_frame", "end_portal_frame"), - new LegacyBlock(121, "ender_stone", "end_stone"), new LegacyBlock(122, "dragon_egg"), - new LegacyBlock(123, "redstone_lamp_off"), - new LegacyBlock(124, "redstone_lamp_on", "redstone_lamp"), - new LegacyBlock(125, "wood_double_step"), new LegacyBlock(125, 1, "wood_double_step"), - new LegacyBlock(125, 2, "wood_double_step"), - new LegacyBlock(125, 3, "wood_double_step"), - new LegacyBlock(125, 4, "wood_double_step"), - new LegacyBlock(125, 5, "wood_double_step"), - new LegacyBlock(126, "wood_step", "oak_slab"), - new LegacyBlock(126, 1, "wood_step", "spruce_slab"), - new LegacyBlock(126, 2, "wood_step", "birch_slab"), - new LegacyBlock(126, 3, "wood_step", "jungle_slab"), - new LegacyBlock(126, 4, "wood_step", "acacia_slab"), - new LegacyBlock(126, 5, "wood_step", "dark_oak_slab"), new LegacyBlock(127, "cocoa"), - new LegacyBlock(128, "sandstone_stairs"), new LegacyBlock(129, "emerald_ore"), - new LegacyBlock(130, "ender_chest"), new LegacyBlock(131, "tripwire_hook"), - new LegacyBlock(132, "tripwire"), new LegacyBlock(133, "emerald_block"), - new LegacyBlock(134, "spruce_wood_stairs", "spruce_stairs"), - new LegacyBlock(135, "birch_wood_stairs", "birch_stairs"), - new LegacyBlock(136, "jungle_wood_stairs", "jungle_stairs"), - new LegacyBlock(137, "command", "command_block"), new LegacyBlock(138, "beacon"), - new LegacyBlock(139, "cobble_wall", "cobblestone_wall"), - new LegacyBlock(139, 1, "cobble_wall", "mossy_cobblestone_wall"), - new LegacyBlock(140, "flower_pot"), new LegacyBlock(141, "carrot", "carrots"), - new LegacyBlock(142, "potato", "potatoes"), - new LegacyBlock(143, "wood_button", "oak_button"), - new LegacyBlock(144, "skull", "skeleton_skull"), - new LegacyBlock(144, 1, "skull", "skeleton_wall_skull"), - new LegacyBlock(144, 2, "skull", "skeleton_wall_skull"), - new LegacyBlock(144, 3, "skull", "skeleton_wall_skull"), - new LegacyBlock(144, 4, "skull", "skeleton_wall_skull"), - new LegacyBlock(144, 5, "skull", "skeleton_wall_skull"), new LegacyBlock(145, "anvil"), - new LegacyBlock(145, 1, "anvil", "chipped_anvil"), - new LegacyBlock(145, 2, "anvil", "damaged_anvil"), - new LegacyBlock(146, "trapped_chest"), - new LegacyBlock(147, "gold_plate", "light_weighted_pressure_plate"), - new LegacyBlock(148, "iron_plate", "heavy_weighted_pressure_plate"), - new LegacyBlock(149, "redstone_comparator_off"), - new LegacyBlock(150, "redstone_comparator_on", "comparator"), - new LegacyBlock(151, "daylight_detector"), new LegacyBlock(152, "redstone_block"), - new LegacyBlock(153, "quartz_ore", "nether_quartz_ore"), new LegacyBlock(154, "hopper"), - new LegacyBlock(155, "quartz_block"), new LegacyBlock(156, "quartz_stairs"), - new LegacyBlock(157, "activator_rail"), new LegacyBlock(158, "dropper"), - new LegacyBlock(159, "stained_clay", "white_terracotta"), - new LegacyBlock(159, 1, "stained_clay", "orange_terracotta"), - new LegacyBlock(159, 2, "stained_clay", "magenta_terracotta"), - new LegacyBlock(159, 3, "stained_clay", "light_blue_terracotta"), - new LegacyBlock(159, 4, "stained_clay", "yellow_terracotta"), - new LegacyBlock(159, 5, "stained_clay", "lime_terracotta"), - new LegacyBlock(159, 6, "stained_clay", "pink_terracotta"), - new LegacyBlock(159, 7, "stained_clay", "gray_terracotta"), - new LegacyBlock(159, 8, "stained_clay", "light_gray_terracotta"), - new LegacyBlock(159, 9, "stained_clay", "cyan_terracotta"), - new LegacyBlock(159, 10, "stained_clay", "purple_terracotta"), - new LegacyBlock(159, 11, "stained_clay", "blue_terracotta"), - new LegacyBlock(159, 12, "stained_clay", "brown_terracotta"), - new LegacyBlock(159, 13, "stained_clay", "green_terracotta"), - new LegacyBlock(159, 14, "stained_clay", "red_terracotta"), - new LegacyBlock(159, 15, "stained_clay", "black_terracotta"), - new LegacyBlock(160, "stained_glass_pane", "white_stained_glass_pane"), - new LegacyBlock(160, 1, "stained_glass_pane", "orange_stained_glass_pane"), - new LegacyBlock(160, 2, "stained_glass_pane", "magenta_stained_glass_pane"), - new LegacyBlock(160, 3, "stained_glass_pane", "light_blue_stained_glass_pane"), - new LegacyBlock(160, 4, "stained_glass_pane", "yellow_stained_glass_pane"), - new LegacyBlock(160, 5, "stained_glass_pane", "lime_stained_glass_pane"), - new LegacyBlock(160, 6, "stained_glass_pane", "pink_stained_glass_pane"), - new LegacyBlock(160, 7, "stained_glass_pane", "gray_stained_glass_pane"), - new LegacyBlock(160, 8, "stained_glass_pane", "light_gray_stained_glass_pane"), - new LegacyBlock(160, 9, "stained_glass_pane", "cyan_stained_glass_pane"), - new LegacyBlock(160, 10, "stained_glass_pane", "purple_stained_glass_pane"), - new LegacyBlock(160, 11, "stained_glass_pane", "blue_stained_glass_pane"), - new LegacyBlock(160, 12, "stained_glass_pane", "brown_stained_glass_pane"), - new LegacyBlock(160, 13, "stained_glass_pane", "green_stained_glass_pane"), - new LegacyBlock(160, 14, "stained_glass_pane", "red_stained_glass_pane"), - new LegacyBlock(160, 15, "stained_glass_pane", "black_stained_glass_pane"), - new LegacyBlock(161, "leaves_2", "acacia_leaves"), - new LegacyBlock(161, 1, "leaves_2", "dark_oak_leaves"), - new LegacyBlock(162, "log_2", "acacia_log"), - new LegacyBlock(162, 1, "log_2", "spruce_log"), - new LegacyBlock(162, 2, "log_2", "birch_log"), - new LegacyBlock(162, 3, "log_2", "jungle_log"), - new LegacyBlock(163, "acacia_stairs", "acacia_stairs"), - new LegacyBlock(164, "dark_oak_stairs", "dark_oak_stairs"), - new LegacyBlock(165, "slime_block", "slime_block"), - new LegacyBlock(166, "barrier", "barrier"), - new LegacyBlock(167, "iron_trapdoor", "iron_trapdoor"), - new LegacyBlock(168, "prismarine"), - new LegacyBlock(168, 1, "prismarine", "prismarine_bricks"), - new LegacyBlock(168, 2, "prismarine", "dark_prismarine"), - new LegacyBlock(169, "sea_lantern"), new LegacyBlock(170, "hay_block"), - new LegacyBlock(171, "carpet", "white_carpet"), - new LegacyBlock(171, 1, "carpet", "orange_carpet"), - new LegacyBlock(171, 2, "carpet", "magenta_carpet"), - new LegacyBlock(171, 3, "carpet", "light_blue_carpet"), - new LegacyBlock(171, 4, "carpet", "yellow_carpet"), - new LegacyBlock(171, 5, "carpet", "lime_carpet"), - new LegacyBlock(171, 6, "carpet", "pink_carpet"), - new LegacyBlock(171, 7, "carpet", "gray_carpet"), - new LegacyBlock(171, 8, "carpet", "light_gray_carpet"), - new LegacyBlock(171, 9, "carpet", "cyan_carpet"), - new LegacyBlock(171, 10, "carpet", "purple_carpet"), - new LegacyBlock(171, 11, "carpet", "blue_carpet"), - new LegacyBlock(171, 12, "carpet", "brown_carpet"), - new LegacyBlock(171, 13, "carpet", "green_carpet"), - new LegacyBlock(171, 14, "carpet", "red_carpet"), - new LegacyBlock(171, 15, "carpet", "black_carpet"), - new LegacyBlock(172, "hard_clay", "terracotta"), new LegacyBlock(173, "coal_block"), - new LegacyBlock(174, "packed_ice"), new LegacyBlock(175, "double_plant", "sunflower"), - new LegacyBlock(175, 1, "double_plant", "lilac"), - new LegacyBlock(175, 2, "double_plant", "tall_grass"), - new LegacyBlock(175, 3, "double_plant", "large_fern"), - new LegacyBlock(175, 4, "double_plant", "rose_bush"), - new LegacyBlock(175, 5, "double_plant", "peony"), - new LegacyBlock(176, "standing_banner"), new LegacyBlock(177, "wall_banner"), - new LegacyBlock(178, "daylight_detector_inverted"), - new LegacyBlock(179, "red_sandstone", "red_sandstone"), - new LegacyBlock(179, 1, "red_sandstone", "chiseled_red_sandstone"), - new LegacyBlock(179, 2, "red_sandstone", "cut_red_sandstone"), - new LegacyBlock(180, "red_sandstone_stairs"), - new LegacyBlock(181, "double_stone_slab2"), - new LegacyBlock(181, 8, "double_stone_slab2", "smooth_red_sandstone"), - new LegacyBlock(182, "stone_slab2", "red_sandstone_slab"), - new LegacyBlock(183, "spruce_fence_gate"), new LegacyBlock(184, "birch_fence_gate"), - new LegacyBlock(185, "jungle_fence_gate"), new LegacyBlock(186, "dark_oak_fence_gate"), - new LegacyBlock(187, "acacia_fence_gate"), new LegacyBlock(188, "spruce_fence"), - new LegacyBlock(189, "birch_fence"), new LegacyBlock(190, "jungle_fence"), - new LegacyBlock(191, "dark_oak_fence"), new LegacyBlock(192, "acacia_fence"), - new LegacyBlock(193, "spruce_door"), new LegacyBlock(194, "birch_door"), - new LegacyBlock(195, "jungle_door"), new LegacyBlock(196, "acacia_door"), - new LegacyBlock(197, "dark_oak_door"), new LegacyBlock(198, "end_rod"), - new LegacyBlock(199, "chorus_plant"), new LegacyBlock(200, "chorus_flower"), - new LegacyBlock(201, "purpur_block"), new LegacyBlock(202, "purpur_pillar"), - new LegacyBlock(203, "purpur_stairs"), new LegacyBlock(204, "purpur_double_slab"), - new LegacyBlock(205, "purpur_slab"), - new LegacyBlock(206, "end_bricks", "end_stone_bricks"), - new LegacyBlock(207, "beetroot_block", "beetroots"), new LegacyBlock(208, "grass_path"), - new LegacyBlock(209, "end_gateway"), - new LegacyBlock(210, "command_repeating", "repeating_command_block"), - new LegacyBlock(211, "command_chain", "chain_command_block"), - new LegacyBlock(212, "frosted_ice"), new LegacyBlock(213, "magma", "magma_block"), - new LegacyBlock(214, "nether_wart_block"), - new LegacyBlock(215, "red_nether_brick", "red_nether_bricks"), - new LegacyBlock(216, "bone_block"), new LegacyBlock(217, "structure_void"), - new LegacyBlock(218, "observer"), new LegacyBlock(219, "white_shulker_box"), - new LegacyBlock(220, "orange_shulker_box"), new LegacyBlock(221, "magenta_shulker_box"), - new LegacyBlock(222, "light_blue_shulker_box"), - new LegacyBlock(223, "yellow_shulker_box"), new LegacyBlock(224, "lime_shulker_box"), - new LegacyBlock(225, "pink_shulker_box"), new LegacyBlock(226, "gray_shulker_box"), - new LegacyBlock(227, "silver_shulker_box", "light_gray_shulker_box"), - new LegacyBlock(228, "cyan_shulker_box"), new LegacyBlock(229, "purple_shulker_box"), - new LegacyBlock(230, "blue_shulker_box"), new LegacyBlock(231, "brown_shulker_box"), - new LegacyBlock(232, "green_shulker_box"), new LegacyBlock(233, "red_shulker_box"), - new LegacyBlock(234, "black_shulker_box"), - new LegacyBlock(235, "white_glazed_terracotta"), - new LegacyBlock(236, "orange_glazed_terracotta"), - new LegacyBlock(237, "magenta_glazed_terracotta"), - new LegacyBlock(238, "light_blue_glazed_terracotta"), - new LegacyBlock(239, "yellow_glazed_terracotta"), - new LegacyBlock(240, "lime_glazed_terracotta"), - new LegacyBlock(241, "pink_glazed_terracotta"), - new LegacyBlock(242, "gray_glazed_terracotta"), - new LegacyBlock(243, "silver_glazed_terracotta", "light_gray_glazed_terracotta"), - new LegacyBlock(244, "cyan_glazed_terracotta"), - new LegacyBlock(245, "purple_glazed_terracotta"), - new LegacyBlock(246, "blue_glazed_terracotta"), - new LegacyBlock(247, "brown_glazed_terracotta"), - new LegacyBlock(248, "green_glazed_terracotta"), - new LegacyBlock(249, "red_glazed_terracotta"), - new LegacyBlock(250, "black_glazed_terracotta"), - new LegacyBlock(251, "concrete", "white_concrete"), - new LegacyBlock(251, 1, "concrete", "orange_concrete"), - new LegacyBlock(251, 2, "concrete", "magenta_concrete"), - new LegacyBlock(251, 3, "concrete", "light_blue_concrete"), - new LegacyBlock(251, 4, "concrete", "yellow_concrete"), - new LegacyBlock(251, 5, "concrete", "lime_concrete"), - new LegacyBlock(251, 6, "concrete", "pink_concrete"), - new LegacyBlock(251, 7, "concrete", "gray_concrete"), - new LegacyBlock(251, 8, "concrete", "light_gray_concrete"), - new LegacyBlock(251, 9, "concrete", "cyan_concrete"), - new LegacyBlock(251, 10, "concrete", "purple_concrete"), - new LegacyBlock(251, 11, "concrete", "blue_concrete"), - new LegacyBlock(251, 12, "concrete", "brown_concrete"), - new LegacyBlock(251, 13, "concrete", "green_concrete"), - new LegacyBlock(251, 14, "concrete", "red_concrete"), - new LegacyBlock(251, 15, "concrete", "black_concrete"), - new LegacyBlock(252, "concrete_powder", "white_concrete_powder"), - new LegacyBlock(252, 1, "concrete_powder", "orange_concrete_powder"), - new LegacyBlock(252, 2, "concrete_powder", "magenta_concrete_powder"), - new LegacyBlock(252, 3, "concrete_powder", "light_blue_concrete_powder"), - new LegacyBlock(252, 4, "concrete_powder", "yellow_concrete_powder"), - new LegacyBlock(252, 5, "concrete_powder", "lime_concrete_powder"), - new LegacyBlock(252, 6, "concrete_powder", "pink_concrete_powder"), - new LegacyBlock(252, 7, "concrete_powder", "gray_concrete_powder"), - new LegacyBlock(252, 8, "concrete_powder", "light_gray_concrete_powder"), - new LegacyBlock(252, 9, "concrete_powder", "cyan_concrete_powder"), - new LegacyBlock(252, 10, "concrete_powder", "purple_concrete_powder"), - new LegacyBlock(252, 11, "concrete_powder", "blue_concrete_powder"), - new LegacyBlock(252, 12, "concrete_powder", "brown_concrete_powder"), - new LegacyBlock(252, 13, "concrete_powder", "green_concrete_powder"), - new LegacyBlock(252, 14, "concrete_powder", "red_concrete_powder"), - new LegacyBlock(252, 15, "concrete_powder", "black_concrete_powder"), - new LegacyBlock(255, "structure_block"), - new LegacyBlock(256, "iron_spade", "iron_shovel"), new LegacyBlock(257, "iron_pickaxe"), - new LegacyBlock(258, "iron_axe"), new LegacyBlock(259, "flint_and_steel"), - new LegacyBlock(260, "apple"), new LegacyBlock(261, "bow"), - new LegacyBlock(262, "arrow"), new LegacyBlock(263, "coal"), - new LegacyBlock(263, 1, "coal", "charcoal"), new LegacyBlock(264, "diamond"), - new LegacyBlock(265, "iron_ingot"), new LegacyBlock(266, "gold_ingot"), - new LegacyBlock(267, "iron_sword"), new LegacyBlock(268, "wood_sword", "wooden_sword"), - new LegacyBlock(269, "wood_spade", "wooden_shovel"), - new LegacyBlock(270, "wood_pickaxe", "wooden_pickaxe"), - new LegacyBlock(271, "wood_axe", "wooden_axe"), new LegacyBlock(272, "stone_sword"), - new LegacyBlock(273, "stone_spade", "stone_shovel"), - new LegacyBlock(274, "stone_pickaxe"), new LegacyBlock(275, "stone_axe"), - new LegacyBlock(276, "diamond_sword"), - new LegacyBlock(277, "diamond_spade", "diamond_shovel"), - new LegacyBlock(278, "diamond_pickaxe"), new LegacyBlock(279, "diamond_axe"), - new LegacyBlock(280, "stick"), new LegacyBlock(281, "bowl"), - new LegacyBlock(282, "mushroom_soup", "mushroom_stew"), - new LegacyBlock(283, "gold_sword", "golden_sword"), - new LegacyBlock(284, "gold_spade", "golden_shovel"), - new LegacyBlock(285, "gold_pickaxe", "golden_pickaxe"), - new LegacyBlock(286, "gold_axe", "golden_axe"), new LegacyBlock(287, "string"), - new LegacyBlock(288, "feather"), new LegacyBlock(289, "sulphur", "gunpowder"), - new LegacyBlock(290, "wood_hoe", "wooden_hoe"), new LegacyBlock(291, "stone_hoe"), - new LegacyBlock(292, "iron_hoe"), new LegacyBlock(293, "diamond_hoe"), - new LegacyBlock(294, "gold_hoe", "golden_hoe"), - new LegacyBlock(295, "seeds", "wheat_seeds"), new LegacyBlock(296, "wheat"), - new LegacyBlock(297, "bread"), new LegacyBlock(298, "leather_helmet"), - new LegacyBlock(299, "leather_chestplate"), new LegacyBlock(300, "leather_leggings"), - new LegacyBlock(301, "leather_boots"), new LegacyBlock(302, "chainmail_helmet"), - new LegacyBlock(303, "chainmail_chestplate"), - new LegacyBlock(304, "chainmail_leggings"), new LegacyBlock(305, "chainmail_boots"), - new LegacyBlock(306, "iron_helmet"), new LegacyBlock(307, "iron_chestplate"), - new LegacyBlock(308, "iron_leggings"), new LegacyBlock(309, "iron_boots"), - new LegacyBlock(310, "diamond_helmet"), new LegacyBlock(311, "diamond_chestplate"), - new LegacyBlock(312, "diamond_leggings"), new LegacyBlock(313, "diamond_boots"), - new LegacyBlock(314, "gold_helmet", "golden_helmet"), - new LegacyBlock(315, "gold_chestplate", "golden_chestplate"), - new LegacyBlock(316, "gold_leggings", "golden_leggings"), - new LegacyBlock(317, "gold_boots", "golden_boots"), new LegacyBlock(318, "flint"), - new LegacyBlock(319, "pork", "porkchop"), - new LegacyBlock(320, "grilled_pork", "cooked_porkchop"), - new LegacyBlock(321, "painting"), new LegacyBlock(322, "golden_apple", "golden_apple"), - new LegacyBlock(322, 1, "golden_apple", "enchanted_golden_apple"), - new LegacyBlock(323, "sign"), new LegacyBlock(324, "wood_door", "oak_door"), - new LegacyBlock(325, "bucket"), new LegacyBlock(326, "water_bucket"), - new LegacyBlock(327, "lava_bucket"), new LegacyBlock(328, "minecart"), - new LegacyBlock(329, "saddle"), new LegacyBlock(330, "iron_door"), - new LegacyBlock(331, "redstone"), new LegacyBlock(332, "snow_ball", "snowball"), - new LegacyBlock(333, "boat", "oak_boat"), new LegacyBlock(334, "leather"), - new LegacyBlock(335, "milk_bucket"), new LegacyBlock(336, "clay_brick", "brick"), - new LegacyBlock(337, "clay_ball"), new LegacyBlock(338, "sugar_cane"), - new LegacyBlock(339, "paper"), new LegacyBlock(340, "book"), - new LegacyBlock(341, "slime_ball"), - new LegacyBlock(342, "storage_minecart", "chest_minecart"), - new LegacyBlock(343, "powered_minecart", "furnace_minecart"), - new LegacyBlock(344, "egg"), new LegacyBlock(345, "compass"), - new LegacyBlock(346, "fishing_rod"), new LegacyBlock(347, "watch", "clock"), - new LegacyBlock(348, "glowstone_dust"), new LegacyBlock(349, "raw_fish", "cod"), - new LegacyBlock(349, 1, "raw_fish", "salmon"), - new LegacyBlock(349, 2, "raw_fish", "tropical_fish"), - new LegacyBlock(349, 3, "raw_fish", "pufferfish"), - new LegacyBlock(350, "cooked_fish", "cooked_cod"), - new LegacyBlock(350, 1, "cooked_fish", "cooked_salmon"), - new LegacyBlock(351, "ink_sack", "ink_sac"), - new LegacyBlock(351, 1, "ink_sack", "rose_red"), - new LegacyBlock(351, 2, "ink_sack", "cactus_green"), - new LegacyBlock(351, 3, "ink_sack", "cocoa_beans"), - new LegacyBlock(351, 4, "ink_sack", "lapis_lazuli"), - new LegacyBlock(351, 5, "ink_sack", "purple_dye"), - new LegacyBlock(351, 6, "ink_sack", "cyan_dye"), - new LegacyBlock(351, 7, "ink_sack", "light_gray_dye"), - new LegacyBlock(351, 8, "ink_sack", "gray_dye"), - new LegacyBlock(351, 9, "ink_sack", "pink_dye"), - new LegacyBlock(351, 10, "ink_sack", "lime_dye"), - new LegacyBlock(351, 11, "ink_sack", "dandelion_yellow"), - new LegacyBlock(351, 12, "ink_sack", "light_blue_dye"), - new LegacyBlock(351, 13, "ink_sack", "magenta_dye"), - new LegacyBlock(351, 14, "ink_sack", "orange_dye"), - new LegacyBlock(351, 15, "ink_sack", "bone_meal"), new LegacyBlock(352, "bone"), - new LegacyBlock(353, "sugar", "sugar"), new LegacyBlock(354, "cake", "cake"), - new LegacyBlock(355, "bed", "white_bed"), new LegacyBlock(355, 1, "bed", "orange_bed"), - new LegacyBlock(355, 2, "bed", "magenta_bed"), - new LegacyBlock(355, 3, "bed", "light_blue_bed"), - new LegacyBlock(355, 4, "bed", "yellow_bed"), - new LegacyBlock(355, 5, "bed", "lime_bed"), new LegacyBlock(355, 6, "bed", "pink_bed"), - new LegacyBlock(355, 7, "bed", "gray_bed"), - new LegacyBlock(355, 8, "bed", "light_gray_bed"), - new LegacyBlock(355, 9, "bed", "cyan_bed"), - new LegacyBlock(355, 10, "bed", "purple_bed"), - new LegacyBlock(355, 11, "bed", "blue_bed"), - new LegacyBlock(355, 12, "bed", "brown_bed"), - new LegacyBlock(355, 13, "bed", "green_bed"), - new LegacyBlock(355, 14, "bed", "red_bed"), - new LegacyBlock(355, 15, "bed", "black_bed"), new LegacyBlock(356, "diode", "repeater"), - new LegacyBlock(357, "cookie", "cookie"), new LegacyBlock(358, "map"), - new LegacyBlock(359, "shears"), new LegacyBlock(360, "melon", "melon"), - new LegacyBlock(361, "pumpkin_seeds", "pumpkin_seeds"), - new LegacyBlock(362, "melon_seeds", "melon_seeds"), - new LegacyBlock(363, "raw_beef", "beef"), new LegacyBlock(364, "cooked_beef"), - new LegacyBlock(365, "raw_chicken", "chicken"), new LegacyBlock(366, "cooked_chicken"), - new LegacyBlock(367, "rotten_flesh"), new LegacyBlock(368, "ender_pearl"), - new LegacyBlock(369, "blaze_rod"), new LegacyBlock(370, "ghast_tear"), - new LegacyBlock(371, "gold_nugget"), - new LegacyBlock(372, "nether_stalk", "nether_wart"), - new LegacyBlock(373, "potion", "potion"), new LegacyBlock(374, "glass_bottle"), - new LegacyBlock(375, "spider_eye"), new LegacyBlock(376, "fermented_spider_eye"), - new LegacyBlock(377, "blaze_powder"), new LegacyBlock(378, "magma_cream"), - new LegacyBlock(379, "brewing_stand_item", "brewing_stand"), - new LegacyBlock(380, "cauldron_item", "cauldron"), - new LegacyBlock(381, "eye_of_ender", "ender_eye"), - new LegacyBlock(382, "speckled_melon"), new LegacyBlock(383, "monster_egg"), - new LegacyBlock(383, 4, "monster_egg", "elder_guardian_spawn_egg"), - new LegacyBlock(383, 5, "monster_egg", "wither_skeleton_spawn_egg"), - new LegacyBlock(383, 6, "monster_egg", "stray_spawn_egg"), - new LegacyBlock(383, 23, "monster_egg", "husk_spawn_egg"), - new LegacyBlock(383, 27, "monster_egg", "zombie_villager_spawn_egg"), - new LegacyBlock(383, 28, "monster_egg", "skeleton_horse_spawn_egg"), - new LegacyBlock(383, 29, "monster_egg", "zombie_horse_spawn_egg"), - new LegacyBlock(383, 31, "monster_egg", "donkey_spawn_egg"), - new LegacyBlock(383, 32, "monster_egg", "mule_spawn_egg"), - new LegacyBlock(383, 34, "monster_egg", "evocation_illager_spawn_egg"), - new LegacyBlock(383, 35, "monster_egg", "vex_spawn_egg"), - new LegacyBlock(383, 36, "monster_egg", "vindication_illager_spawn_egg"), - new LegacyBlock(383, 50, "monster_egg", "creeper_spawn_egg"), - new LegacyBlock(383, 51, "monster_egg", "skeleton_spawn_egg"), - new LegacyBlock(383, 52, "monster_egg", "spider_spawn_egg"), - new LegacyBlock(383, 54, "monster_egg", "zombie_spawn_egg"), - new LegacyBlock(383, 55, "monster_egg", "slime_spawn_egg"), - new LegacyBlock(383, 56, "monster_egg", "ghast_spawn_egg"), - new LegacyBlock(383, 57, "monster_egg", "zombie_pigman_spawn_egg"), - new LegacyBlock(383, 58, "monster_egg", "enderman_spawn_egg"), - new LegacyBlock(383, 59, "monster_egg", "cave_spider_spawn_egg"), - new LegacyBlock(383, 60, "monster_egg", "silverfish_spawn_egg"), - new LegacyBlock(383, 61, "monster_egg", "blaze_spawn_egg"), - new LegacyBlock(383, 62, "monster_egg", "magma_cube_spawn_egg"), - new LegacyBlock(383, 65, "monster_egg", "bat_spawn_egg"), - new LegacyBlock(383, 66, "monster_egg", "witch_spawn_egg"), - new LegacyBlock(383, 67, "monster_egg", "endermite_spawn_egg"), - new LegacyBlock(383, 68, "monster_egg", "guardian_spawn_egg"), - new LegacyBlock(383, 69, "monster_egg", "shulker_spawn_egg"), - new LegacyBlock(383, 90, "monster_egg", "pig_spawn_egg"), - new LegacyBlock(383, 91, "monster_egg", "sheep_spawn_egg"), - new LegacyBlock(383, 92, "monster_egg", "cow_spawn_egg"), - new LegacyBlock(383, 93, "monster_egg", "chicken_spawn_egg"), - new LegacyBlock(383, 94, "monster_egg", "squid_spawn_egg"), - new LegacyBlock(383, 95, "monster_egg", "wolf_spawn_egg"), - new LegacyBlock(383, 96, "monster_egg", "mooshroom_spawn_egg"), - new LegacyBlock(383, 98, "monster_egg", "ocelot_spawn_egg"), - new LegacyBlock(383, 100, "monster_egg", "horse_spawn_egg"), - new LegacyBlock(383, 101, "monster_egg", "rabbit_spawn_egg"), - new LegacyBlock(383, 102, "monster_egg", "polar_bear_spawn_egg"), - new LegacyBlock(383, 103, "monster_egg", "llama_spawn_egg"), - new LegacyBlock(383, 120, "monster_egg", "villager_spawn_egg"), - new LegacyBlock(384, "exp_bottle", "experience_bottle"), - new LegacyBlock(385, "fireball", "fire_charge"), - new LegacyBlock(386, "book_and_quill", "writable_book"), - new LegacyBlock(387, "written_book"), new LegacyBlock(388, "emerald"), - new LegacyBlock(389, "item_frame"), - new LegacyBlock(390, "flower_pot_item", "flower_pot"), - new LegacyBlock(391, "carrot_item", "carrot"), - new LegacyBlock(392, "potato_item", "potato"), new LegacyBlock(393, "baked_potato"), - new LegacyBlock(394, "poisonous_potato"), new LegacyBlock(395, "empty_map", "map"), - new LegacyBlock(396, "golden_carrot"), - new LegacyBlock(397, "skull_item", "skeleton_skull"), - new LegacyBlock(397, 1, "skull_item", "wither_skeleton_skull"), - new LegacyBlock(397, 2, "skull_item", "zombie_head"), - new LegacyBlock(397, 3, "skull_item", "player_head"), - new LegacyBlock(397, 4, "skull_item", "creeper_head"), - new LegacyBlock(397, 5, "skull_item", "dragon_head"), - new LegacyBlock(398, "carrot_stick"), new LegacyBlock(399, "nether_star"), - new LegacyBlock(400, "pumpkin_pie"), - new LegacyBlock(401, "firework", "firework_rocket"), - new LegacyBlock(402, "firework_charge", "firework_star"), - new LegacyBlock(403, "enchanted_book"), - new LegacyBlock(404, "redstone_comparator", "comparator"), - new LegacyBlock(405, "nether_brick_item", "nether_brick"), - new LegacyBlock(406, "quartz"), - new LegacyBlock(407, "explosive_minecart", "tnt_minecart"), - new LegacyBlock(408, "hopper_minecart"), new LegacyBlock(409, "prismarine_shard"), - new LegacyBlock(410, "prismarine_crystals"), new LegacyBlock(411, "rabbit"), - new LegacyBlock(412, "cooked_rabbit"), new LegacyBlock(413, "rabbit_stew"), - new LegacyBlock(414, "rabbit_foot"), new LegacyBlock(415, "rabbit_hide"), - new LegacyBlock(416, "armor_stand"), - new LegacyBlock(417, "iron_barding", "iron_horse_armor"), - new LegacyBlock(418, "gold_barding", "gold_horse_armor"), - new LegacyBlock(419, "diamond_barding", "diamond_horse_armor"), - new LegacyBlock(420, "leash", "lead"), new LegacyBlock(421, "name_tag"), - new LegacyBlock(422, "command_minecart", "command_block_minecart"), - new LegacyBlock(423, "mutton"), new LegacyBlock(424, "cooked_mutton"), - new LegacyBlock(425, "banner", "white_banner"), - new LegacyBlock(425, 1, "banner", "orange_banner"), - new LegacyBlock(425, 2, "banner", "magenta_banner"), - new LegacyBlock(425, 3, "banner", "light_blue_banner"), - new LegacyBlock(425, 4, "banner", "yellow_banner"), - new LegacyBlock(425, 5, "banner", "lime_banner"), - new LegacyBlock(425, 6, "banner", "pink_banner"), - new LegacyBlock(425, 7, "banner", "gray_banner"), - new LegacyBlock(425, 8, "banner", "light_gray_banner"), - new LegacyBlock(425, 9, "banner", "cyan_banner"), - new LegacyBlock(425, 10, "banner", "purple_banner"), - new LegacyBlock(425, 11, "banner", "blue_banner"), - new LegacyBlock(425, 12, "banner", "brown_banner"), - new LegacyBlock(425, 13, "banner", "green_banner"), - new LegacyBlock(425, 14, "banner", "red_banner"), - new LegacyBlock(425, 15, "banner", "black_banner"), new LegacyBlock(426, "end_crystal"), - new LegacyBlock(427, "spruce_door_item", "spruce_door"), - new LegacyBlock(428, "birch_door_item", "birch_door"), - new LegacyBlock(429, "jungle_door_item", "jungle_door"), - new LegacyBlock(430, "acacia_door_item", "acacia_door"), - new LegacyBlock(431, "dark_oak_door_item", "dark_oak_door"), - new LegacyBlock(432, "chorus_fruit"), new LegacyBlock(433, "chorus_fruit_popped"), - new LegacyBlock(434, "beetroot"), new LegacyBlock(435, "beetroot_seeds"), - new LegacyBlock(436, "beetroot_soup"), - new LegacyBlock(437, "dragons_breath", "dragon_breath"), - new LegacyBlock(438, "splash_potion"), new LegacyBlock(439, "spectral_arrow"), - new LegacyBlock(440, "tipped_arrow"), new LegacyBlock(441, "lingering_potion"), - new LegacyBlock(442, "shield"), new LegacyBlock(443, "elytra"), - new LegacyBlock(444, "boat_spruce", "spruce_boat"), - new LegacyBlock(445, "boat_birch", "birch_boat"), - new LegacyBlock(446, "boat_jungle", "jungle_boat"), - new LegacyBlock(447, "boat_acacia", "acacia_boat"), - new LegacyBlock(448, "boat_dark_oak", "dark_oak_boat"), - new LegacyBlock(449, "totem", "totem_of_undying"), - new LegacyBlock(450, "shulker_shell"), new LegacyBlock(452, "iron_nugget"), - new LegacyBlock(453, "knowledge_book"), - new LegacyBlock(2256, "gold_record", "music_disc_13"), - new LegacyBlock(2257, "green_record", "music_disc_cat"), - new LegacyBlock(2258, "record_3", "music_disc_blocks"), - new LegacyBlock(2259, "record_4", "music_disc_chirp"), - new LegacyBlock(2260, "record_5", "music_disc_far"), - new LegacyBlock(2261, "record_6", "music_disc_mall"), - new LegacyBlock(2262, "record_7", "music_disc_mellohi"), - new LegacyBlock(2263, "record_8", "music_disc_stal"), - new LegacyBlock(2264, "record_9", "music_disc_strad"), - new LegacyBlock(2265, "record_10", "music_disc_ward"), - new LegacyBlock(2266, "record_11", "music_disc_11"), - new LegacyBlock(2267, "record_12", "music_disc_wait")}; - - private static final Map LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK = - new HashMap<>(); - private static final Map NEW_STRING_TO_LEGACY_PLOT_BLOCK = new HashMap<>(); - private static final Map OLD_STRING_TO_STRING_PLOT_BLOCK = new HashMap<>(); - - @SuppressWarnings("deprecation") public BukkitLegacyMappings() { - this.addAll(Arrays.asList(BLOCKS)); - // Make sure to add new blocks as well - final List missing = new ArrayList<>(); - for (final Material material : Material.values()) { - final String materialName = material.name().toLowerCase(Locale.ENGLISH); - if (NEW_STRING_TO_LEGACY_PLOT_BLOCK.get(materialName) == null) { - try { - final LegacyBlock missingBlock = - new LegacyBlock(material.getId(), materialName, materialName); - missing.add(missingBlock); - } catch (Exception ignored) { - } - } - } - addAll(missing); - } - - private void addAll(@NonNull final Collection blocks) { - for (final LegacyBlock legacyBlock : blocks) { - LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK - .put(new IdDataPair(legacyBlock.getNumericalId(), legacyBlock.getDataValue()), - legacyBlock.toStringPlotBlock()); - NEW_STRING_TO_LEGACY_PLOT_BLOCK - .put(legacyBlock.getNewName(), legacyBlock.toLegacyPlotBlock()); - OLD_STRING_TO_STRING_PLOT_BLOCK - .put(legacyBlock.getLegacyName(), legacyBlock.toStringPlotBlock()); - Material material; - try { - material = Material.valueOf(legacyBlock.getNewName()); - } catch (final Exception e) { - try { - material = Material.getMaterial(legacyBlock.getLegacyName(), true); - } catch (NoSuchMethodError error) { - PlotSquared.log("You can't use this version of PlotSquared on a server " - + "less than Minecraft 1.13.2"); - Bukkit.shutdown(); - break; - } - } - legacyBlock.material = material; - } - } - - public Collection getPlotBlocks() { - return Arrays.stream(BLOCKS).map(block -> PlotBlock.get(block.getNewName())) - .collect(Collectors.toList()); - } - - public StringComparison.ComparisonResult getClosestsMatch( - @NonNull final String string) { - final StringComparison comparison = - new StringComparison<>(string, getPlotBlocks()); - return comparison.getBestMatchAdvanced(); - } - - /** - * Try to find a legacy plot block by any means possible. Strategy: - Check if the name contains - * a namespace, if so, strip it - Check if there's a (new) material matching the name - Check if - * there's a legacy material matching the name - Check if there's a numerical ID matching the - * name - Return null if everything else fails - * - * @param string String ID - * @return LegacyBlock if found, else null - */ - public PlotBlock fromAny(@NonNull final String string) { - if (string.isEmpty()) { - return StringPlotBlock.EVERYTHING; - } - String workingString = string; - String[] parts = null; - IdDataPair idDataPair = null; - if (string.contains(":")) { - parts = string.split(":"); - if (parts.length > 1) { - if (parts[0].equalsIgnoreCase("minecraft")) { - workingString = parts[1]; - } else { - if (parts[0].matches("^\\d+$")) { - idDataPair = - new IdDataPair(Integer.parseInt(parts[0]), Integer.parseInt(parts[0])); - } else { - workingString = parts[0]; - } - } - } - } else if (string.matches("^\\d+$")) { - idDataPair = new IdDataPair(Integer.parseInt(string), 0); - } - PlotBlock plotBlock; - if (Material.matchMaterial(workingString) != null) { - return PlotBlock.get(workingString); - } else if (NEW_STRING_TO_LEGACY_PLOT_BLOCK.containsKey(workingString.toLowerCase())) { - return PlotBlock.get(workingString); - } else if ((plotBlock = fromLegacyToString(idDataPair)) != null) { - return plotBlock; - } else if ((plotBlock = fromLegacyToString(workingString)) != null) { - return plotBlock; - } else { - try { - if (parts != null && parts.length > 1) { - final int id = Integer.parseInt(parts[0]); - final int data = Integer.parseInt(parts[1]); - return fromLegacyToString(id, data); - } else { - return fromLegacyToString(Integer.parseInt(workingString), 0); - } - } catch (final Throwable exception) { - return null; - } - } - } - - public PlotBlock fromLegacyToString(final int id, final int data) { - return LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK.get(new IdDataPair(id, data)); - } - - public PlotBlock fromLegacyToString(IdDataPair idDataPair) { - if (idDataPair == null) { - return null; - } - return LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK.get(idDataPair); - } - - public PlotBlock fromLegacyToString(final String id) { - return OLD_STRING_TO_STRING_PLOT_BLOCK.get(id); - } - - public PlotBlock fromStringToLegacy(final String id) { - return NEW_STRING_TO_LEGACY_PLOT_BLOCK.get(id.toLowerCase(Locale.ENGLISH)); - } - - @Getter @EqualsAndHashCode @ToString @RequiredArgsConstructor - private static final class IdDataPair { - private final int id; - private final int data; - } - - - @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) - public static final class LegacyBlock { - - private final int numericalId; - private final int dataValue; - private final String legacyName; - private final String newName; - - private Material material; - - LegacyBlock(final int numericalId, final int dataValue, @NonNull final String legacyName) { - this(numericalId, dataValue, legacyName, legacyName); - } - - LegacyBlock(final int numericalId, final int dataValue, @NonNull final String legacyName, - @NonNull final String newName, @NonNull final String new14Name) { - this(numericalId, dataValue, legacyName, - PlotSquared.get().IMP.getServerVersion()[1] == 13 ? newName : new14Name); - } - - LegacyBlock(final int numericalId, @NonNull final String legacyName, - @NonNull final String newName, @NonNull final String new14Name) { - this(numericalId, 0, legacyName, - Bukkit.getBukkitVersion().split("-")[0].split("\\.")[1].equals("13") ? - newName : - new14Name); - } - - LegacyBlock(final int numericalId, @NonNull final String legacyName, - @NonNull final String newName) { - this(numericalId, 0, legacyName, newName); - } - - LegacyBlock(final int numericalId, @NonNull final String legacyName) { - this(numericalId, legacyName, legacyName); - } - - PlotBlock toStringPlotBlock() { - return StringPlotBlock.get(newName); - } - - PlotBlock toLegacyPlotBlock() { - return LegacyPlotBlock.get(numericalId, dataValue); - } - - @Override public String toString() { - return this.newName; - } - } - -} diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java index 76462a11e..ed0a8cfcc 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java @@ -2,19 +2,32 @@ package com.github.intellectualsites.plotsquared.bukkit.util; import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWrapper; import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.ByteArrayTag; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntArrayTag; +import com.sk89q.jnbt.IntTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.ShortTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BaseBlock; import java.io.ByteArrayOutputStream; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.IntStream; /** @@ -22,7 +35,7 @@ import java.util.stream.IntStream; */ public class BukkitSchematicHandler extends SchematicHandler { - @Override public void getCompoundTag(final String world, final Set regions, + @Override public void getCompoundTag(final String world, final Set regions, final RunnableVal whenDone) { // async TaskManager.runTaskAsync(new Runnable() { @@ -61,7 +74,7 @@ public class BukkitSchematicHandler extends SchematicHandler { List tileEntities = new ArrayList<>(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length); // Queue - final ArrayDeque queue = new ArrayDeque<>(regions); + final ArrayDeque queue = new ArrayDeque<>(regions); TaskManager.runTask(new Runnable() { @Override public void run() { if (queue.isEmpty()) { @@ -82,9 +95,9 @@ public class BukkitSchematicHandler extends SchematicHandler { return; } final Runnable regionTask = this; - RegionWrapper region = queue.poll(); - Location pos1 = new Location(world, region.minX, region.minY, region.minZ); - Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ); + CuboidRegion region = queue.poll(); + Location pos1 = new Location(world, region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); + Location pos2 = new Location(world, region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); final int p1x = pos1.getX(); final int sy = pos1.getY(); final int p1z = pos1.getZ(); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java index 0d00f7741..dcb562166 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java @@ -3,6 +3,8 @@ package com.github.intellectualsites.plotsquared.bukkit.util; import com.github.intellectualsites.plotsquared.bukkit.BukkitMain; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.NotNull; public class BukkitTaskManager extends TaskManager { @@ -26,7 +28,7 @@ public class BukkitTaskManager extends TaskManager { @Override public void taskAsync(Runnable runnable) { if (this.bukkitMain.isEnabled()) { this.bukkitMain.getServer().getScheduler() - .runTaskAsynchronously(this.bukkitMain, runnable).getTaskId(); + .runTaskAsynchronously(this.bukkitMain, runnable); } else { runnable.run(); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index bf7ed114a..026689c2d 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -3,7 +3,11 @@ 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.Captions; -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.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.sk89q.worldedit.regions.CuboidRegion; 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; @@ -11,7 +15,10 @@ import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.world.block.BlockState; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -20,7 +27,6 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.block.data.Directional; import org.bukkit.block.data.type.WallSign; @@ -36,7 +42,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Set; @SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil { @@ -258,23 +263,11 @@ import java.util.Set; location.getPitch()); } - public static BukkitLegacyMappings getBukkitLegacyMappings() { - return (BukkitLegacyMappings) PlotSquared.imp().getLegacyMappings(); + public static Material getMaterial(@NonNull final BlockState plotBlock) { + return BukkitAdapter.adapt(plotBlock.getBlockType()); } - 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) { + @Override public boolean isBlockSame(BlockState block1, BlockState block2) { if (block1.equals(block2)) { return true; } @@ -377,7 +370,7 @@ import java.util.Set; sign.setFacing(facing); block.setBlockData(sign, false); } - final BlockState blockstate = block.getState(); + final org.bukkit.block.BlockState blockstate = block.getState(); if (blockstate instanceof Sign) { final Sign sign = (Sign) blockstate; for (int i = 0; i < lines.length; i++) { @@ -405,13 +398,13 @@ import java.util.Set; public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) { final World world = getWorld(worldName); final Block block = world.getBlockAt(items.x, items.y, items.z); - final BlockState state = block.getState(); + final org.bukkit.block.BlockState state = block.getState(); if (state instanceof InventoryHolder) { InventoryHolder holder = (InventoryHolder) state; Inventory inv = holder.getInventory(); for (int i = 0; i < items.types.length; i++) { // ItemStack item = new ItemStack(LegacyMappings.fromLegacyId(items.id[i]).getMaterial(), items.amount[i], items.data[i]); - ItemStack item = new ItemStack(items.types[i].to(Material.class), items.amount[i]); + ItemStack item = new ItemStack(BukkitAdapter.adapt(items.types[i]), items.amount[i]); inv.addItem(item); } state.update(true); @@ -420,33 +413,11 @@ import java.util.Set; return false; } - @Override public boolean isBlockSolid(@NonNull final PlotBlock block) { - try { - Material material = getMaterial(block); - if (material.isLegacy()) { - material = getBukkitLegacyMappings().fromLegacyToString(material.name()) - .to(Material.class); - } - if (material.isBlock() && material.isSolid() && !material.hasGravity()) { - String name = material.name().toLowerCase(Locale.ENGLISH); - if (material.isOccluding() || name.contains("stairs") || name.contains("slab") - || name.contains("wool")) { - switch (material) { - case NOTE_BLOCK: - case SPAWNER: - return false; - default: - return true; - } - } - } - return false; - } catch (Exception ignored) { - return false; - } + @Override public boolean isBlockSolid(@NonNull final BlockState block) { + return block.getBlockType().getMaterial().isSolid(); } - @Override public String getClosestMatchingName(@NonNull final PlotBlock block) { + @Override public String getClosestMatchingName(@NonNull final BlockState block) { try { return getMaterial(block).name(); } catch (Exception ignored) { @@ -455,21 +426,18 @@ import java.util.Set; } @Override @Nullable - public StringComparison.ComparisonResult getClosestBlock(String name) { - final PlotBlock plotBlock = BukkitUtil.getBukkitLegacyMappings().fromAny(name); - if (plotBlock != null) { - return new StringComparison().new ComparisonResult(1, plotBlock); - } - return BukkitUtil.getBukkitLegacyMappings().getClosestsMatch(name); + public StringComparison.ComparisonResult getClosestBlock(String name) { + BlockState state = BlockUtil.get(name); + return new StringComparison().new ComparisonResult(1, state); } @Override - public void setBiomes(@NonNull final String worldName, @NonNull final RegionWrapper region, + public void setBiomes(@NonNull final String worldName, @NonNull final CuboidRegion region, @NonNull final String biomeString) { final World world = getWorld(worldName); final Biome biome = Biome.valueOf(biomeString.toUpperCase()); - for (int x = region.minX; x <= region.maxX; x++) { - for (int z = region.minZ; z <= region.maxZ; z++) { + for (int x = region.getMinimumPoint().getX(); x <= region.getMaximumPoint().getX(); x++) { + for (int z = region.getMinimumPoint().getZ(); z <= region.getMaximumPoint().getZ(); z++) { world.setBiome(x, z, biome); } } @@ -479,10 +447,10 @@ import java.util.Set; return new BukkitWorld(Bukkit.getWorld(world)); } - @Override public PlotBlock getBlock(@NonNull final Location location) { + @Override public BlockState getBlock(@NonNull final Location location) { final World world = getWorld(location.getWorld()); final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ()); - return PlotBlock.get(block.getType().name()); + return BlockUtil.get(block.getType().name()); } @Override public String getMainWorld() { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/Metrics.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/Metrics.java index ff6e1b310..edc2f9669 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/Metrics.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/Metrics.java @@ -10,12 +10,24 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import javax.net.ssl.HttpsURLConnection; -import java.io.*; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; @@ -36,6 +48,7 @@ public class Metrics { new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); // We want to make sure nobody just copy & pastes the example and use the wrong package names + if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) { throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java index acf0f82fa..10407f5ec 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java @@ -13,9 +13,28 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; +import java.io.BufferedInputStream; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.AbstractList; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentMap; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java index a3e40fae1..a4ee94f80 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java @@ -9,7 +9,13 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.UUID; -import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.*; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.callConstructor; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.callMethod; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getCbClass; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getNmsClass; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getUtilClass; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.makeConstructor; +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.makeMethod; public class OfflinePlayerUtil { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/SendChunk.java index 09f8462bb..8b5e89b27 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/SendChunk.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/SendChunk.java @@ -2,7 +2,6 @@ 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.object.ChunkLoc; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -12,6 +11,7 @@ import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefFie import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefMethod; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.sk89q.worldedit.math.BlockVector2; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -129,12 +129,12 @@ public class SendChunk { } } - public void sendChunk(String worldName, Collection chunkLocations) { + public void sendChunk(String worldName, Collection chunkLocations) { World myWorld = Bukkit.getWorld(worldName); ArrayList chunks = new ArrayList<>(); - for (ChunkLoc loc : chunkLocations) { - if (myWorld.isChunkLoaded(loc.x, loc.z)) { - PaperLib.getChunkAtAsync(myWorld, loc.x, loc.z).thenAccept(chunks::add); + for (BlockVector2 loc : chunkLocations) { + if (myWorld.isChunkLoaded(loc.getX(), loc.getZ())) { + PaperLib.getChunkAtAsync(myWorld, loc.getX(), loc.getZ()).thenAccept(chunks::add); } } sendChunk(chunks); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java index e7d05eedc..9f5dc4e7f 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java @@ -1,15 +1,15 @@ package com.github.intellectualsites.plotsquared.bukkit.util.block; +import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil; import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWrapper; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; -import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import io.papermc.lib.PaperLib; import lombok.NonNull; import org.bukkit.Bukkit; @@ -19,7 +19,6 @@ import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; -import java.util.Locale; import java.util.concurrent.ExecutionException; public class BukkitLocalQueue extends BasicLocalBlockQueue { @@ -38,13 +37,13 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { } - @Override public PlotBlock getBlock(int x, int y, int z) { + @Override public BlockState getBlock(int x, int y, int z) { World worldObj = Bukkit.getWorld(getWorld()); if (worldObj != null) { Block block = worldObj.getBlockAt(x, y, z); - return PlotBlock.get(block.getType().toString()); + return BukkitBlockUtil.get(block); } else { - return PlotBlock.get(0, 0); + return BlockUtil.get(0, 0); } } @@ -95,7 +94,7 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { BlockData blockData = BukkitAdapter.adapt(block); Block existing = chunk.getBlock(x, y, z); - if (equals(PlotBlock.get(block), existing) && existing + if (BukkitBlockUtil.get(existing).equals(block) && existing .getBlockData().matches(blockData)) { continue; } @@ -116,38 +115,13 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { }); } - private void setMaterial(@NonNull final PlotBlock plotBlock, @NonNull final Block block) { - final Material material; - if (plotBlock instanceof StringPlotBlock) { - material = Material - .getMaterial(((StringPlotBlock) plotBlock).getItemId().toUpperCase(Locale.ENGLISH)); - if (material == null) { - throw new IllegalStateException(String - .format("Could not find material that matches %s", - ((StringPlotBlock) plotBlock).getItemId())); - } - } else { - final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock; - material = PlotSquared.get().IMP.getLegacyMappings() - .fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData()) - .to(Material.class); - if (material == null) { - throw new IllegalStateException(String - .format("Could not find material that matches %s", legacyPlotBlock.toString())); - } - } + private void setMaterial(@NonNull final BlockState plotBlock, @NonNull final Block block) { + Material material = BukkitAdapter.adapt(plotBlock.getBlockType()); block.setType(material, false); } - private boolean equals(@NonNull final PlotBlock plotBlock, @NonNull final Block block) { - if (plotBlock instanceof StringPlotBlock) { - return ((StringPlotBlock) plotBlock).idEquals(block.getType().name()); - } - final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock; - return Material.getMaterial(PlotSquared.get().IMP.getLegacyMappings() - .fromLegacyToString(((LegacyPlotBlock) plotBlock).id, - ((LegacyPlotBlock) plotBlock).data).toString()) == block.getType() && ( - legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData()); + private boolean equals(@NonNull final BlockState plotBlock, @NonNull final Block block) { + return plotBlock.equals(BukkitBlockUtil.get(block)); } public void setBiomes(LocalChunk lc) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java index fc2bc3574..a93c22679 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java @@ -1,17 +1,18 @@ package com.github.intellectualsites.plotsquared.bukkit.util.block; +import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper; import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import lombok.Getter; import lombok.Setter; import org.bukkit.Chunk; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator.BiomeGrid; @@ -22,7 +23,7 @@ import java.util.Arrays; public class GenChunk extends ScopedLocalBlockQueue { public final Biome[] biomes; - public PlotBlock[][] result; + public BlockState[][] result; public BiomeGrid biomeGrid; public Chunk chunk; public String world; @@ -68,14 +69,14 @@ public class GenChunk extends ScopedLocalBlockQueue { } } - @Override public void setCuboid(Location pos1, Location pos2, PlotBlock block) { + @Override public void setCuboid(Location pos1, Location pos2, BlockState block) { if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) { for (int y = pos1.getY(); y <= pos2.getY(); y++) { int layer = y >> 4; - PlotBlock[] data = result[layer]; + BlockState[] data = result[layer]; if (data == null) { - result[layer] = data = new PlotBlock[4096]; + result[layer] = data = new BlockState[4096]; } int start = y << 8; int end = start + 256; @@ -88,8 +89,7 @@ public class GenChunk extends ScopedLocalBlockQueue { int maxX = Math.max(pos1.getX(), pos2.getX()); int maxY = Math.max(pos1.getY(), pos2.getY()); int maxZ = Math.max(pos1.getZ(), pos2.getZ()); - chunkData - .setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, block.to(Material.class)); + chunkData.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block)); } @Override public boolean setBiome(int x, int z, String biome) { @@ -104,21 +104,21 @@ public class GenChunk extends ScopedLocalBlockQueue { return false; } - @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { + @Override public boolean setBlock(int x, int y, int z, BlockState id) { if (this.result == null) { - this.chunkData.setBlock(x, y, z, id.to(Material.class)); + this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id)); return true; } - this.chunkData.setBlock(x, y, z, id.to(Material.class)); + this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id)); this.storeCache(x, y, z, id); return true; } - private void storeCache(final int x, final int y, final int z, final PlotBlock id) { + private void storeCache(final int x, final int y, final int z, final BlockState id) { int i = MainUtil.CACHE_I[y][x][z]; - PlotBlock[] v = this.result[i]; + BlockState[] v = this.result[i]; if (v == null) { - this.result[i] = v = new PlotBlock[4096]; + this.result[i] = v = new BlockState[4096]; } int j = MainUtil.CACHE_J[y][x][z]; v[j] = id; @@ -130,18 +130,18 @@ public class GenChunk extends ScopedLocalBlockQueue { return true; } this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id)); - this.storeCache(x, y, z, PlotBlock.get(id.getBlockType().getId())); + this.storeCache(x, y, z, BlockUtil.get(id.getBlockType().getId())); return true; } - @Override public PlotBlock getBlock(int x, int y, int z) { + @Override public BlockState getBlock(int x, int y, int z) { int i = MainUtil.CACHE_I[y][x][z]; if (result == null) { - return PlotBlock.get(chunkData.getType(x, y, z)); + return BukkitBlockUtil.get(chunkData.getType(x, y, z)); } - PlotBlock[] array = result[i]; + BlockState[] array = result[i]; if (array == null) { - return PlotBlock.get(""); + return BlockUtil.get(""); } int j = MainUtil.CACHE_J[y][x][z]; return array[j]; @@ -171,9 +171,9 @@ public class GenChunk extends ScopedLocalBlockQueue { GenChunk toReturn = new GenChunk(); if (this.result != null) { for (int i = 0; i < this.result.length; i++) { - PlotBlock[] matrix = this.result[i]; + BlockState[] matrix = this.result[i]; if (matrix != null) { - toReturn.result[i] = new PlotBlock[matrix.length]; + toReturn.result[i] = new BlockState[matrix.length]; System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java index 610362953..740db8fca 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java @@ -14,6 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; +import com.sk89q.worldedit.extension.platform.Actor; import lombok.NoArgsConstructor; import java.util.Collections; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java index faaf3c7af..691daa93e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java @@ -19,7 +19,15 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; public abstract class Command { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/MemorySection.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/MemorySection.java index 0f87931f4..14233b758 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/MemorySection.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/MemorySection.java @@ -1,6 +1,11 @@ package com.github.intellectualsites.plotsquared.configuration; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * A type of {@link ConfigurationSection} that is stored in memory. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java index a56c65901..e8123cfc9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java @@ -4,7 +4,16 @@ import com.github.intellectualsites.plotsquared.configuration.Configuration; import com.github.intellectualsites.plotsquared.configuration.InvalidConfigurationException; import com.github.intellectualsites.plotsquared.configuration.MemoryConfiguration; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java index cd67bb158..965e95644 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONObject.java @@ -7,8 +7,15 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.ResourceBundle; +import java.util.Set; import java.util.stream.IntStream; /** @@ -554,7 +561,9 @@ public class JSONObject { return new JSONObject((Map) object); } Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage.getName() : ""; + if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || ( object.getClass().getClassLoader() == null)) { return object.toString(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONTokener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONTokener.java index 290b9ea0b..195ceeb5d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONTokener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/json/JSONTokener.java @@ -1,6 +1,11 @@ package com.github.intellectualsites.plotsquared.json; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; /** * A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the JSONObject and diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java index 8fff0921d..bf4bf888a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java @@ -4,10 +4,19 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; import com.github.intellectualsites.plotsquared.plot.logger.ILogger; -import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.ChatManager; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; +import com.sk89q.worldedit.extension.platform.Actor; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -237,8 +246,5 @@ public interface IPlotMain extends ILogger { List getPluginIds(); - BlockRegistry getBlockRegistry(); - - LegacyMappings getLegacyMappings(); - + Actor getConsole(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 45c284a3f..fd57be3d8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -20,12 +20,38 @@ import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; import com.github.intellectualsites.plotsquared.plot.listener.WESubscriber; import com.github.intellectualsites.plotsquared.plot.logger.ILogger; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotCluster; +import com.github.intellectualsites.plotsquared.plot.object.PlotFilter; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.object.worlds.DefaultPlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.ChatManager; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.CommentManager; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil; +import com.github.intellectualsites.plotsquared.plot.util.LegacyConverter; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpiryTask; @@ -35,15 +61,37 @@ import lombok.NonNull; import lombok.Setter; import org.jetbrains.annotations.Nullable; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -105,7 +153,7 @@ import java.util.zip.ZipInputStream; // // Register configuration serializable classes // - ConfigurationSerialization.registerClass(PlotBlock.class, "PlotBlock"); +// ConfigurationSerialization.registerClass(BlockState.class, "BlockState"); ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket"); try { @@ -1272,7 +1320,7 @@ import java.util.zip.ZipInputStream; .filter(validArgument -> args.toLowerCase(Locale.ENGLISH).contains(validArgument)) .count(); - String[] split = args.toLowerCase(Locale.ENGLISH).split(","); + String[] split = args.toLowerCase(Locale.ENGLISH).split(",(?![^\\(\\[]*[\\]\\)])"); if (split.length > expected) { // This means we have multi-block block buckets @@ -1960,7 +2008,7 @@ import java.util.zip.ZipInputStream; return Collections.unmodifiableSet(result); } - public Set getPlotAreas(final String world, final RegionWrapper region) { + public Set getPlotAreas(final String world, final CuboidRegion region) { final PlotArea[] areas = plotAreaManager.getPlotAreas(world, region); final Set set = new HashSet<>(); Collections.addAll(set, areas); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java index f4c73a972..f773c1e1c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java @@ -7,8 +7,25 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.generator.AugmentedUtils; import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; +import com.github.intellectualsites.plotsquared.plot.object.SetupObject; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.sk89q.worldedit.math.BlockVector2; import java.io.IOException; import java.util.ArrayList; @@ -83,7 +100,7 @@ import java.util.Set; area.ROAD_WIDTH / 2; final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower); final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower); - final RegionWrapper region = new RegionWrapper(bx, tx, bz, tz); + final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz); Set areas = PlotSquared.get().getPlotAreas(area.worldname, region); if (!areas.isEmpty()) { @@ -120,10 +137,10 @@ import java.util.Set; player.teleport(WorldUtil.IMP.getSpawn(world)); if (area.TERRAIN != 3) { ChunkManager.largeRegionTask(world, region, - new RunnableVal() { - @Override public void run(ChunkLoc value) { + new RunnableVal() { + @Override public void run(BlockVector2 value) { AugmentedUtils - .generate(world, value.x, value.z, + .generate(world, value.getX(), value.getZ(), null); } }, null); @@ -415,9 +432,9 @@ import java.util.Set; return false; } ChunkManager - .largeRegionTask(area.worldname, area.getRegion(), new RunnableVal() { - @Override public void run(ChunkLoc value) { - AugmentedUtils.generate(area.worldname, value.x, value.z, null); + .largeRegionTask(area.worldname, area.getRegion(), new RunnableVal() { + @Override public void run(BlockVector2 value) { + AugmentedUtils.generate(area.worldname, value.getX(), value.getZ(), null); } }, () -> player.sendMessage("Regen complete")); return true; @@ -444,10 +461,10 @@ import java.util.Set; if (area.TYPE != 2) { center = WorldUtil.IMP.getSpawn(area.worldname); } else { - RegionWrapper region = area.getRegion(); + CuboidRegion region = area.getRegion(); center = - new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, - 0, region.minZ + (region.maxZ - region.minZ) / 2); + new Location(area.worldname, region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, + 0, region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); center.setY(1 + WorldUtil.IMP .getHighestBlock(area.worldname, center.getX(), center.getZ())); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java index 93eef7813..bf0a221b8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java @@ -5,14 +5,20 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Direction; +import com.github.intellectualsites.plotsquared.plot.object.Expression; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ByteArrayUtilities; import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; - import org.jetbrains.annotations.Nullable; + import java.util.Set; @CommandDeclaration(command = "auto", permission = "plots.auto", diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java index 94a82fdd8..aba59ad05 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java @@ -4,7 +4,13 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Direction; +import com.github.intellectualsites.plotsquared.plot.object.Expression; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ByteArrayUtilities; import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.Permissions; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java index 1bc8f779e..088273c9c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java @@ -5,7 +5,13 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockLoc; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotCluster; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java index de7d754a3..411a3290b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugClaimTest.java @@ -4,12 +4,19 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -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.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.google.common.collect.BiMap; +import com.sk89q.worldedit.math.BlockVector2; import java.util.ArrayList; import java.util.Map; @@ -55,7 +62,7 @@ public class DebugClaimTest extends SubCommand { continue; } Location location = manager.getSignLoc(plot); - ChunkLoc chunk = new ChunkLoc(location.getX() >> 4, location.getZ() >> 4); + BlockVector2 chunk = BlockVector2.at(location.getX() >> 4, location.getZ() >> 4); ChunkManager.manager.loadChunk(area.worldname, chunk, false).thenRun(() -> { String[] lines = WorldUtil.IMP.getSign(location); if (lines != null) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java index 841c6fc8c..8bafa55b7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java @@ -10,12 +10,33 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.listener.WEManager; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; import com.google.common.io.Files; +import com.sk89q.worldedit.world.block.BlockState; import javax.script.Bindings; import javax.script.ScriptContext; @@ -103,7 +124,7 @@ import java.util.concurrent.CompletableFuture; // Classes this.scope.put("Location", Location.class); - this.scope.put("PlotBlock", PlotBlock.class); + this.scope.put("BlockState", BlockState.class); this.scope.put("Plot", Plot.class); this.scope.put("PlotId", PlotId.class); this.scope.put("Runnable", Runnable.class); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index af0389dec..8ec105c88 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -5,15 +5,14 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; +import com.github.intellectualsites.plotsquared.plot.flag.BlockStateListFlag; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag; import com.github.intellectualsites.plotsquared.plot.flag.ListFlag; -import com.github.intellectualsites.plotsquared.plot.flag.PlotBlockListFlag; 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.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; @@ -21,8 +20,18 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.sk89q.worldedit.world.block.BlockType; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +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.Optional; +import java.util.Set; @CommandDeclaration(command = "setflag", aliases = {"f", "flag", "setflag"}, usage = "/plot flag ", description = "Set plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag") @@ -52,12 +61,12 @@ public class FlagCmd extends SubCommand { } catch (NumberFormatException ignore) { } - } else if (flag instanceof PlotBlockListFlag) { - final PlotBlockListFlag blockListFlag = (PlotBlockListFlag) flag; - final HashSet parsedBlocks = blockListFlag.parseValue(value); - for (final PlotBlock block : parsedBlocks) { + } else if (flag instanceof BlockStateListFlag) { + final BlockStateListFlag blockListFlag = (BlockStateListFlag) flag; + Set parsedBlocks = blockListFlag.parseValue(value); + for (final BlockType block : parsedBlocks) { final String permission = Captions.PERMISSION_SET_FLAG_KEY_VALUE - .f(key.toLowerCase(), block.getRawId().toString().toLowerCase()); + .f(key.toLowerCase(), block.toString().toLowerCase()); final boolean result = Permissions.hasPermission(player, permission); if (!result) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java index f839a9b1a..378da26c2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java @@ -14,7 +14,11 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; @CommandDeclaration(command = "like", permission = "plots.like", description = "Like the plot", usage = "/plot like [next|purge]", category = CommandCategory.INFO, diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index 4917e2499..2b70e48e5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -11,7 +11,13 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.Rating; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.StringComparison; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import java.util.ArrayList; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java index 31095cd75..dd060c88e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java @@ -5,7 +5,14 @@ import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; +import com.github.intellectualsites.plotsquared.plot.object.Expression; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm; import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.Permissions; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java index a763a3c51..e60ee9ba1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java @@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.sk89q.worldedit.world.item.ItemTypes; import java.util.Arrays; import java.util.Collection; @@ -39,11 +40,11 @@ import java.util.Locale; if (item == null) { return true; } - if (item.getPlotBlock().equalsAny(7, "bedrock")) { + if (item.getType() == ItemTypes.BEDROCK) { plot.removeFlag(Flags.MUSIC); Captions.FLAG_REMOVED.send(player); } else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) { - plot.setFlag(Flags.MUSIC, item.getPlotBlock().getRawId()); + plot.setFlag(Flags.MUSIC, item); Captions.FLAG_ADDED.send(player); } else { Captions.FLAG_NOT_ADDED.send(player); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java index 9c93925b6..f81f02719 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java @@ -7,8 +7,16 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotInventory; +import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Rating; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import java.util.ArrayList; import java.util.HashMap; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java index 9fcdc811d..e47cb610f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RegenAllRoads.java @@ -43,7 +43,7 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD); return false; } - //Set chunks = ChunkManager.manager.getChunkChunks(name); + //Set chunks = ChunkManager.manager.getChunkChunks(name); MainUtil .sendMessage(player, "&cIf no schematic is set, the following will not do anything"); MainUtil.sendMessage(player, diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java index 5af706df3..cc5c8c21a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java @@ -3,7 +3,11 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java index 481acba53..d000f55e2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java @@ -3,7 +3,11 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; -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.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java index 582dfb38a..771063217 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java @@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; @@ -19,6 +18,7 @@ import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; +import com.sk89q.worldedit.world.block.BlockState; import java.util.ArrayList; import java.util.Arrays; @@ -60,7 +60,7 @@ import java.util.stream.IntStream; Captions.PERMISSION_SET_COMPONENT.f(component)); return false; } - // PlotBlock[] blocks; + // BlockState[] blocks; BlockBucket bucket; try { if (args.length < 2) { @@ -73,7 +73,7 @@ import java.util.stream.IntStream; } catch (final UnknownBlockException unknownBlockException) { final String unknownBlock = unknownBlockException.getUnknownValue(); Captions.NOT_VALID_BLOCK.send(player, unknownBlock); - StringComparison.ComparisonResult match = + StringComparison.ComparisonResult match = WorldUtil.IMP.getClosestBlock(unknownBlock); if (match != null) { final String found = @@ -87,8 +87,8 @@ import java.util.stream.IntStream; } if (!allowUnsafe) { - for (final PlotBlock block : bucket.getBlocks()) { - if (!block.isAir() && !WorldUtil.IMP.isBlockSolid(block)) { + for (final BlockState block : bucket.getBlocks()) { + if (!block.getBlockType().getMaterial().isAir() && !WorldUtil.IMP.isBlockSolid(block)) { Captions.NOT_ALLOWED_BLOCK.send(player, block.toString()); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java index 7b21352e2..eb7826ee5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java @@ -15,11 +15,23 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; @CommandDeclaration(command = "setup", permission = "plots.admin.command.setup", description = "Setup wizard for plot worlds", usage = "/plot setup", aliases = {"create"}, @@ -264,8 +276,9 @@ import java.util.Map.Entry; Captions.NOT_ALLOWED_BLOCK.send(player, e.getUnsafeBlock().toString()); } if (valid) { - sendMessage(player, Captions.SETUP_VALID_ARG, step.getConstant(), args[0]); step.setValue(args[0]); + Object value = step.getValue(); + sendMessage(player, Captions.SETUP_VALID_ARG, step.getConstant(), value); object.setup_index++; if (object.setup_index == object.step.length) { onCommand(player, args); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java index fe41e61ab..85a0fe633 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Template.java @@ -8,14 +8,21 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.FileBytes; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.SetupObject; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java index 3b3504c24..66a024ec4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java @@ -3,7 +3,13 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; -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.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; @@ -11,6 +17,7 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; +import com.sk89q.worldedit.math.BlockVector2; import java.io.File; import java.io.IOException; @@ -31,7 +38,7 @@ import java.util.Set; public static ArrayList expired = null; private static volatile boolean TASK = false; - public static boolean getBulkRegions(final ArrayList empty, final String world, + public static boolean getBulkRegions(final ArrayList empty, final String world, final Runnable whenDone) { if (Trim.TASK) { return false; @@ -71,7 +78,7 @@ import java.util.Set; String[] split = name.split("\\."); int x = Integer.parseInt(split[1]); int z = Integer.parseInt(split[2]); - ChunkLoc loc = new ChunkLoc(x, z); + BlockVector2 loc = BlockVector2.at(x, z); empty.add(loc); } catch (NumberFormatException ignored) { PlotSquared.debug("INVALID MCA: " + name); @@ -90,7 +97,7 @@ import java.util.Set; * @return */ public static boolean getTrimRegions(String world, - final RunnableVal2, Set> result) { + final RunnableVal2, Set> result) { if (result == null) { return false; } @@ -114,7 +121,7 @@ import java.util.Set; int ccz2 = pos2.getZ() >> 9; for (int x = ccx1; x <= ccx2; x++) { for (int z = ccz1; z <= ccz2; z++) { - ChunkLoc loc = new ChunkLoc(x, z); + BlockVector2 loc = BlockVector2.at(x, z); if (result.value1.remove(loc)) { result.value2.add(loc); } @@ -141,8 +148,8 @@ import java.util.Set; } Trim.TASK = true; final boolean regen = args.length == 2 && Boolean.parseBoolean(args[1]); - getTrimRegions(world, new RunnableVal2, Set>() { - @Override public void run(Set viable, final Set nonViable) { + getTrimRegions(world, new RunnableVal2, Set>() { + @Override public void run(Set viable, final Set nonViable) { Runnable regenTask; if (regen) { PlotSquared.log("Starting regen task:"); @@ -155,43 +162,43 @@ import java.util.Set; player.sendMessage("Trim done!"); return; } - Iterator iterator = nonViable.iterator(); - ChunkLoc mcr = iterator.next(); + Iterator iterator = nonViable.iterator(); + BlockVector2 mcr = iterator.next(); iterator.remove(); - int cbx = mcr.x << 5; - int cbz = mcr.z << 5; + int cbx = mcr.getX() << 5; + int cbz = mcr.getZ() << 5; // get all 1024 chunks - HashSet chunks = new HashSet<>(); + HashSet chunks = new HashSet<>(); for (int x = cbx; x < cbx + 32; x++) { for (int z = cbz; z < cbz + 32; z++) { - ChunkLoc loc = new ChunkLoc(x, z); + BlockVector2 loc = BlockVector2.at(x, z); chunks.add(loc); } } int bx = cbx << 4; int bz = cbz << 4; - RegionWrapper region = new RegionWrapper(bx, bx + 511, bz, bz + 511); + CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, bz, bz + 511); for (Plot plot : PlotSquared.get().getPlots(world)) { Location bot = plot.getBottomAbs(); Location top = plot.getExtendedTopAbs(); - RegionWrapper plotReg = - new RegionWrapper(bot.getX(), top.getX(), bot.getZ(), + CuboidRegion plotReg = + RegionUtil.createRegion(bot.getX(), top.getX(), bot.getZ(), top.getZ()); - if (!region.intersects(plotReg)) { + if (!RegionUtil.intersects(region, plotReg)) { continue; } - for (int x = plotReg.minX >> 4; x <= plotReg.maxX >> 4; x++) { - for (int z = plotReg.minZ >> 4; z <= plotReg.maxZ >> 4; z++) { - ChunkLoc loc = new ChunkLoc(x, z); + for (int x = plotReg.getMinimumPoint().getX() >> 4; x <= plotReg.getMaximumPoint().getX() >> 4; x++) { + for (int z = plotReg.getMinimumPoint().getZ() >> 4; z <= plotReg.getMaximumPoint().getZ() >> 4; z++) { + BlockVector2 loc = BlockVector2.at(x, z); chunks.remove(loc); } } } final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); - TaskManager.objectTask(chunks, new RunnableVal() { - @Override public void run(ChunkLoc value) { - queue.regenChunk(value.x, value.z); + TaskManager.objectTask(chunks, new RunnableVal() { + @Override public void run(BlockVector2 value) { + queue.regenChunk(value.getX(), value.getZ()); } }, this); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java index 5c38ea63f..e2b7fa382 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java @@ -6,13 +6,21 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.UUID; import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "visit", permission = "plots.visit", diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java index ace39f846..f7bd5118e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java @@ -14,7 +14,11 @@ import java.lang.annotation.Target; import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class Config { @@ -361,12 +365,8 @@ public class Config { * @throws NoSuchFieldException * @throws IllegalAccessException */ - private static void setAccessible(Field field) - throws NoSuchFieldException, IllegalAccessException { + private static void setAccessible(Field field) { field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); } /** diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java index 3d636e0dd..94188b35b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java @@ -1,12 +1,18 @@ package com.github.intellectualsites.plotsquared.plot.config; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.StringComparison; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.sk89q.worldedit.world.block.BlockState; import lombok.Getter; import lombok.NonNull; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Main Configuration Utility */ @@ -57,30 +63,28 @@ public class Configuration { public static final SettingValue BLOCK_BUCKET = new SettingValue("BLOCK_BUCKET") { + + private Pattern pattern = Pattern.compile("((?[A-Za-z_]+):)?(?([A-Za-z_]+(\\[?[\\S\\s]+\\])?))(:(?[0-9]{1,3}))?"); + @Override public BlockBucket parseString(final String string) { if (string == null || string.isEmpty()) { return new BlockBucket(); } final BlockBucket blockBucket = new BlockBucket(); - final String[] parts = string.split(","); + final String[] parts = string.split(",(?![^\\(\\[]*[\\]\\)])"); for (final String part : parts) { - String block; - int chance = -1; - - if (part.contains(":")) { - final String[] innerParts = part.split(":"); - if (innerParts.length > 1) { - chance = Integer.parseInt(innerParts[1]); - } - block = innerParts[0]; - } else { - block = part; - } - final StringComparison.ComparisonResult value = + Matcher matcher = pattern.matcher(part); + matcher.find(); + String namespace = matcher.group("namespace"); + String block = matcher.group("block"); + String chanceStr = matcher.group("chance"); + if (namespace == null) namespace = "minecraft"; + int chance = chanceStr == null ? -1 : Integer.parseInt(chanceStr); + final StringComparison.ComparisonResult value = WorldUtil.IMP.getClosestBlock(block); if (value == null) { throw new UnknownBlockException(block); - } else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.isAir() + } else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.getBlockType().getMaterial().isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) { throw new UnsafeBlockException(value.best); } @@ -95,26 +99,24 @@ public class Configuration { if (string == null || string.isEmpty()) { return false; } - final String[] parts = string.split(","); + final String[] parts = string.split(",(?![^\\(\\[]*[\\]\\)])"); for (final String part : parts) { - String block; - if (part.contains(":")) { - final String[] innerParts = part.split(":"); - if (innerParts.length > 1) { - final int chance = Integer.parseInt(innerParts[1]); - if (chance < 1 || chance > 100) { - return false; - } - } - block = innerParts[0]; - } else { - block = part; + Matcher matcher = pattern.matcher(part); + matcher.find(); + String namespace = matcher.group("namespace"); + String block = matcher.group("block"); + String chanceStr = matcher.group("chance"); + if (namespace == null) namespace = "minecraft"; + int chance = chanceStr == null ? -1 : Integer.parseInt(chanceStr); + + if ((chance != -1 && (chance < 1 || chance > 100)) || block == null) { + return false; } - StringComparison.ComparisonResult value = + StringComparison.ComparisonResult value = WorldUtil.IMP.getClosestBlock(block); if (value == null || value.match > 1) { return false; - } else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.isAir() + } else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.getBlockType().getMaterial().isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) { throw new UnsafeBlockException(value.best); } @@ -162,9 +164,9 @@ public class Configuration { public static final class UnsafeBlockException extends IllegalArgumentException { - @Getter private final PlotBlock unsafeBlock; + @Getter private final BlockState unsafeBlock; - UnsafeBlockException(@NonNull final PlotBlock unsafeBlock) { + UnsafeBlockException(@NonNull final BlockState unsafeBlock) { super(String.format("%s is not a valid block", unsafeBlock)); this.unsafeBlock = unsafeBlock; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java index 31539d5c2..2b6167e97 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java @@ -1,8 +1,8 @@ package com.github.intellectualsites.plotsquared.plot.config; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.sk89q.worldedit.world.block.BlockState; import java.util.ArrayList; import java.util.Arrays; @@ -66,7 +66,7 @@ public class ConfigurationNode { if (this.value instanceof BlockBucket) { return this.value.toString(); } - if (this.value instanceof PlotBlock) { + if (this.value instanceof BlockState) { return this.value.toString(); } return this.value; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java index b1e239c78..8dd1be8a8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java @@ -16,10 +16,10 @@ public class Settings extends Config { @Comment("These first 7 aren't configurable") // This is a comment @Final // Indicates that this value isn't configurable - public static final String ISSUES = "https://github.com/IntellectualSites/PlotSquared/issues"; - @Final public static final String SUGGESTION = + public static String ISSUES = "https://github.com/IntellectualSites/PlotSquared/issues"; + @Final public static String SUGGESTION = "https://github.com/IntellectualSites/PlotSquaredSuggestions"; - @Final public static final String WIKI = + @Final public static String WIKI = "https://github.com/IntellectualSites/PlotSquared/wiki"; @Final public static String DATE; // These values are set from P2 before loading @Final public static String BUILD; // These values are set from P2 before loading diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java index d5943d1ac..f8b2cedb0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/MySQL.java @@ -3,7 +3,11 @@ package com.github.intellectualsites.plotsquared.plot.database; import com.github.intellectualsites.plotsquared.plot.config.Storage; import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; /** * Connects to and uses a MySQL database diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java index 2f041cc57..a62924e9e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java @@ -6,7 +6,13 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.config.Storage; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockLoc; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotCluster; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotSettings; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; @@ -14,11 +20,26 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.google.common.base.Charsets; import org.jetbrains.annotations.NotNull; -import java.sql.*; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Queue; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; @@ -857,10 +878,10 @@ import java.util.concurrent.atomic.AtomicInteger; statement.setInt(i * 10 + 9, hash); BlockLoc loc = pair.settings.getPosition(); String position; - if (loc.y == 0) { + if (loc.getY() == 0) { position = "DEFAULT"; } else { - position = loc.x + "," + loc.y + ',' + loc.z; + position = loc.getX() + "," + loc.getY() + ',' + loc.getZ(); } statement.setString(i * 10 + 10, position); } @@ -898,10 +919,10 @@ import java.util.concurrent.atomic.AtomicInteger; stmt.setInt(i * 10 + 9, n); BlockLoc loc = pair.settings.getPosition(); String position; - if (loc.y == 0) { + if (loc.getY() == 0) { position = "DEFAULT"; } else { - position = loc.x + "," + loc.y + ',' + loc.z; + position = loc.getX() + "," + loc.getY() + ',' + loc.getZ(); } stmt.setString(i * 10 + 10, position); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLite.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLite.java index 3675ad0cd..10ceb8784 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLite.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLite.java @@ -4,7 +4,11 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import java.io.File; import java.io.IOException; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; /** * Connects to and uses a SQLite database. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java new file mode 100644 index 000000000..b9f3367d0 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java @@ -0,0 +1,35 @@ +package com.github.intellectualsites.plotsquared.plot.flag; + +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +public class BlockStateListFlag extends ListFlag> { + + public BlockStateListFlag(String name) { + super(Captions.FLAG_CATEGORY_BLOCK_LIST, name); + } + + @Override public String valueToString(Object value) { + return StringMan.join((Set) value, ","); + } + + @Override public Set parseValue(final String value) { + return Arrays.stream(BlockUtil.parse(value)).map(BlockState::getBlockType).collect(Collectors.toSet()); + } + + @Override public String getValueDescription() { + return Captions.FLAG_ERROR_PLOTBLOCKLIST.getTranslated(); + } + + public boolean contains(Plot plot, BlockState value) { + return contains(plot, value.getBlockType()); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java index 6dc4aa2ff..51391f788 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java @@ -10,7 +10,12 @@ import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.google.common.collect.ImmutableSet; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; /** diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index 07e71a348..6df44dca7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -58,9 +58,9 @@ public final class Flags { public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition"); public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry"); public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); - public static final PlotBlockListFlag USE = new PlotBlockListFlag("use"); - public static final PlotBlockListFlag BREAK = new PlotBlockListFlag("break"); - public static final PlotBlockListFlag PLACE = new PlotBlockListFlag("place"); + public static final BlockStateListFlag USE = new BlockStateListFlag("use"); + public static final BlockStateListFlag BREAK = new BlockStateListFlag("break"); + public static final BlockStateListFlag PLACE = new BlockStateListFlag("place"); public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact"); public static final BooleanFlag VEHICLE_BREAK = new BooleanFlag("vehicle-break"); public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java deleted file mode 100644 index 1abaf32b0..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.flag; - -import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; -import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; -import com.github.intellectualsites.plotsquared.plot.util.StringMan; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - -public class PlotBlockListFlag extends ListFlag> { - - public PlotBlockListFlag(String name) { - super(Captions.FLAG_CATEGORY_BLOCK_LIST, name); - } - - @Override public String valueToString(Object value) { - return StringMan.join((HashSet) value, ","); - } - - @Override public HashSet parseValue(final String value) { - final LegacyMappings legacyMappings = PlotSquared.get().IMP.getLegacyMappings(); - return Arrays.stream(value.split(",")).map(legacyMappings::fromAny).filter(Objects::nonNull) - .collect(Collectors.toCollection(HashSet::new)); - } - - @Override public String getValueDescription() { - return Captions.FLAG_ERROR_PLOTBLOCKLIST.getTranslated(); - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java index 779f47e0d..21f1690a6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java @@ -1,6 +1,5 @@ package com.github.intellectualsites.plotsquared.plot.flag; - import com.github.intellectualsites.plotsquared.plot.config.Captions; public class StringFlag extends Flag { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java index 2a85581ad..f5aa2e440 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java @@ -3,14 +3,15 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; -import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.block.DelegateLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -33,7 +34,7 @@ public class AugmentedUtils { final int blockX = chunkX << 4; final int blockZ = chunkZ << 4; - RegionWrapper region = new RegionWrapper(blockX, blockX + 15, blockZ, blockZ + 15); + CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15); Set areas = PlotSquared.get().getPlotAreas(world, region); if (areas.isEmpty()) { return false; @@ -59,12 +60,12 @@ public class AugmentedUtils { int tzz; // gen if (area.TYPE == 2) { - bxx = Math.max(0, area.getRegion().minX - blockX); - bzz = Math.max(0, area.getRegion().minZ - blockZ); - txx = Math.min(15, area.getRegion().maxX - blockX); - tzz = Math.min(15, area.getRegion().maxZ - blockZ); + bxx = Math.max(0, area.getRegion().getMinimumPoint().getX() - blockX); + bzz = Math.max(0, area.getRegion().getMinimumPoint().getZ() - blockZ); + txx = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX); + tzz = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ); primaryMask = new DelegateLocalBlockQueue(queue) { - @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { + @Override public boolean setBlock(int x, int y, int z, BlockState id) { if (area.contains(x, z)) { return super.setBlock(x, y, z, id); } @@ -84,7 +85,7 @@ public class AugmentedUtils { primaryMask = queue; } LocalBlockQueue secondaryMask; - PlotBlock air = StringPlotBlock.EVERYTHING; + BlockState air = BlockTypes.AIR.getDefaultState(); if (area.TERRAIN == 2) { PlotManager manager = area.getPlotManager(); final boolean[][] canPlace = new boolean[16][16]; @@ -108,7 +109,7 @@ public class AugmentedUtils { } toReturn = true; secondaryMask = new DelegateLocalBlockQueue(primaryMask) { - @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { + @Override public boolean setBlock(int x, int y, int z, BlockState id) { if (canPlace[x - blockX][z - blockZ]) { return super.setBlock(x, y, z, id); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java index f7ce683ba..640ee389c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java @@ -1,8 +1,14 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.Direction; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; @@ -45,7 +51,9 @@ public class ClassicPlotManager extends SquarePlotManager { @Override public boolean unClaimPlot(Plot plot, Runnable whenDone) { setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING); - setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); + if (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) { + setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); + } return GlobalBlockQueue.IMP.addEmptyTask(whenDone); } @@ -53,11 +61,11 @@ public class ClassicPlotManager extends SquarePlotManager { Plot plot = classicPlotWorld.getPlotAbs(plotId); LocalBlockQueue queue = classicPlotWorld.getQueue(false); if (plot.isBasePlot()) { - for (RegionWrapper region : plot.getRegions()) { + for (CuboidRegion region : plot.getRegions()) { Location pos1 = - new Location(classicPlotWorld.worldname, region.minX, classicPlotWorld.PLOT_HEIGHT, region.minZ); + new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), classicPlotWorld.PLOT_HEIGHT, region.getMinimumPoint().getZ()); Location pos2 = - new Location(classicPlotWorld.worldname, region.maxX, classicPlotWorld.PLOT_HEIGHT, region.maxZ); + new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), classicPlotWorld.PLOT_HEIGHT, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } } @@ -71,9 +79,9 @@ public class ClassicPlotManager extends SquarePlotManager { } LocalBlockQueue queue = classicPlotWorld.getQueue(false); int maxY = getWorldHeight(); - for (RegionWrapper region : plot.getRegions()) { - Location pos1 = new Location(classicPlotWorld.worldname, region.minX, 1, region.minZ); - Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ); + for (CuboidRegion region : plot.getRegions()) { + Location pos1 = new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), 1, region.getMinimumPoint().getZ()); + Location pos2 = new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } return queue.enqueue(); @@ -86,10 +94,10 @@ public class ClassicPlotManager extends SquarePlotManager { } LocalBlockQueue queue = classicPlotWorld.getQueue(false); int maxY = getWorldHeight(); - for (RegionWrapper region : plot.getRegions()) { + for (CuboidRegion region : plot.getRegions()) { Location pos1 = - new Location(classicPlotWorld.worldname, region.minX, classicPlotWorld.PLOT_HEIGHT + 1, region.minZ); - Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ); + new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), classicPlotWorld.PLOT_HEIGHT + 1, region.getMinimumPoint().getZ()); + Location pos2 = new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } return queue.enqueue(); @@ -101,10 +109,10 @@ public class ClassicPlotManager extends SquarePlotManager { return false; } LocalBlockQueue queue = classicPlotWorld.getQueue(false); - for (RegionWrapper region : plot.getRegions()) { - Location pos1 = new Location(classicPlotWorld.worldname, region.minX, 1, region.minZ); + for (CuboidRegion region : plot.getRegions()) { + Location pos1 = new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), 1, region.getMinimumPoint().getZ()); Location pos2 = - new Location(classicPlotWorld.worldname, region.maxX, classicPlotWorld.PLOT_HEIGHT - 1, region.maxZ); + new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), classicPlotWorld.PLOT_HEIGHT - 1, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } return queue.enqueue(); @@ -167,9 +175,9 @@ public class ClassicPlotManager extends SquarePlotManager { } } if (plot.isBasePlot()) { - for (RegionWrapper region : plot.getRegions()) { - Location pos1 = new Location(classicPlotWorld.worldname, region.minX, maxY, region.minZ); - Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ); + for (CuboidRegion region : plot.getRegions()) { + Location pos1 = new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), maxY, region.getMinimumPoint().getZ()); + Location pos2 = new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } } @@ -278,9 +286,9 @@ public class ClassicPlotManager extends SquarePlotManager { queue.setCuboid( new Location(classicPlotWorld.worldname, sx, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz + 1), new Location(classicPlotWorld.worldname, ex, maxY, ez - 1), - PlotBlock.get((short) 0, (byte) 0)); + BlockUtil.get((short) 0, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 0, sz + 1), - new Location(classicPlotWorld.worldname, ex, 0, ez - 1), PlotBlock.get((short) 7, (byte) 0)); + new Location(classicPlotWorld.worldname, ex, 0, ez - 1), BlockUtil.get((short) 7, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz + 1), new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT + 1, sz + 1), @@ -306,9 +314,9 @@ public class ClassicPlotManager extends SquarePlotManager { new Location(classicPlotWorld.worldname, sx + 1, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), - ez), PlotBlock.get((short) 0, (byte) 0)); + ez), BlockUtil.get((short) 0, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 0, sz), - new Location(classicPlotWorld.worldname, ex - 1, 0, ez), PlotBlock.get((short) 7, (byte) 0)); + new Location(classicPlotWorld.worldname, ex - 1, 0, ez), BlockUtil.get((short) 7, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz), new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT, sz), classicPlotWorld.WALL_FILLING); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.WALL_HEIGHT + 1, sz), @@ -331,10 +339,10 @@ public class ClassicPlotManager extends SquarePlotManager { LocalBlockQueue queue = classicPlotWorld.getQueue(false); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.ROAD_HEIGHT + 1, sz + 1), new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), ez - 1), - PlotBlock.get((short) 0, (byte) 0)); + BlockUtil.get((short) 0, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 0, sz + 1), new Location(classicPlotWorld.worldname, ex - 1, 0, ez - 1), - PlotBlock.get((short) 7, (byte) 0)); + BlockUtil.get((short) 7, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1), new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK); return queue.enqueue(); @@ -352,7 +360,7 @@ public class ClassicPlotManager extends SquarePlotManager { new Location(classicPlotWorld.worldname, sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), - PlotBlock.get((short) 0, (byte) 0)); + BlockUtil.get((short) 0, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz + 1), new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT - 1, ez - 1), classicPlotWorld.MAIN_BLOCK); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.PLOT_HEIGHT, sz + 1), @@ -372,7 +380,7 @@ public class ClassicPlotManager extends SquarePlotManager { new Location(classicPlotWorld.worldname, sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), - PlotBlock.get((short) 0, (byte) 0)); + BlockUtil.get((short) 0, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz), new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK); queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.PLOT_HEIGHT, sz), @@ -389,7 +397,7 @@ public class ClassicPlotManager extends SquarePlotManager { LocalBlockQueue queue = classicPlotWorld.getQueue(false); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.ROAD_HEIGHT + 1, sz), new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), - PlotBlock.get((short) 0, (byte) 0)); + BlockUtil.get((short) 0, (byte) 0)); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz), new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK); queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.ROAD_HEIGHT, sz), @@ -403,44 +411,29 @@ public class ClassicPlotManager extends SquarePlotManager { * @return false if part of the merge failed, otherwise true if successful. */ @Override public boolean finishPlotMerge(List plotIds) { - final BlockBucket block = classicPlotWorld.CLAIMED_WALL_BLOCK; - boolean success = true; - for (PlotId plotId : plotIds) { - success &= setWall(plotId, block); + final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; + if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) { + for (PlotId plotId : plotIds) { + setWall(plotId, claim); + } } if (Settings.General.MERGE_REPLACE_WALL) { final BlockBucket wallBlock = classicPlotWorld.WALL_FILLING; for (PlotId id : plotIds) { - success &= setWallFilling(id, wallBlock); + setWallFilling(id, wallBlock); } } - return success; + return true; } @Override public boolean finishPlotUnlink(List plotIds) { - final BlockBucket block = classicPlotWorld.CLAIMED_WALL_BLOCK; - boolean success = true; - for (PlotId id : plotIds) { - success &= setWall(id, block); - } - return success; - } - - /** - * Sets all the blocks along all the plot walls to their correct state (claimed or unclaimed). - * - * @return true if the wall blocks were successfully set - */ - @Override public boolean regenerateAllPlotWalls() { - boolean success = true; - for (Plot plot : classicPlotWorld.getPlots()) { - if (plot.hasOwner()) { - success &= setWall(plot.getId(), classicPlotWorld.CLAIMED_WALL_BLOCK); - } else { - success &= setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); + final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; + if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) { + for (PlotId id : plotIds) { + setWall(id, claim); } } - return success; + return true; // return false if unlink has been denied } @Override public boolean startPlotMerge(List plotIds) { @@ -453,7 +446,10 @@ public class ClassicPlotManager extends SquarePlotManager { @Override public boolean claimPlot(Plot plot) { final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; - return setWall(plot.getId(), claim); + if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) { + return setWall(plot.getId(), claim); + } + return true; } @Override public String[] getPlotComponents(PlotId plotId) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java index 143879680..4d1ad357c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java @@ -6,11 +6,10 @@ import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; import java.lang.reflect.Field; import java.util.Locale; @@ -19,18 +18,18 @@ import java.util.Locale; public int ROAD_HEIGHT = 62; public int PLOT_HEIGHT = 62; public int WALL_HEIGHT = 62; - public BlockBucket MAIN_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone")); - // new PlotBlock[] {PlotBlock.get("stone")}; - public BlockBucket TOP_BLOCK = BlockBucket.withSingle(PlotBlock.get("grass_block")); - //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(BlockUtil.get("stone")); + // new BlockState[] {BlockUtil.get("stone")}; + public BlockBucket TOP_BLOCK = BlockBucket.withSingle(BlockUtil.get("grass_block")); + //new BlockState[] {BlockUtil.get("grass")}; + public BlockBucket WALL_BLOCK = BlockBucket.withSingle(BlockUtil.get("stone_slab")); + // BlockUtil.get((short) 44, (byte) 0); + public BlockBucket CLAIMED_WALL_BLOCK = BlockBucket.withSingle(BlockUtil.get("sandstone_slab")); + // BlockUtil.get((short) 44, (byte) 1); + public BlockBucket WALL_FILLING = BlockBucket.withSingle(BlockUtil.get("stone")); + //BlockUtil.get((short) 1, (byte) 0); + public BlockBucket ROAD_BLOCK = BlockBucket.withSingle(BlockUtil.get("quartz_block")); + // BlockUtil.get((short) 155, (byte) 0); public boolean PLOT_BEDROCK = true; public ClassicPlotWorld(String worldName, String id, diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java index 81d76b929..7df870508 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java @@ -2,8 +2,12 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.sk89q.worldedit.world.block.BaseBlock; @@ -39,7 +43,7 @@ public class HybridGen extends IndependentPlotGenerator { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { blockBuckets[0][(z << 4) | x] = - BlockBucket.withSingle(PlotBlock.get("bedrock")); + BlockBucket.withSingle(BlockUtil.get("bedrock")); } } } @@ -70,7 +74,7 @@ public class HybridGen extends IndependentPlotGenerator { if (hpw.PLOT_BEDROCK) { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - result.setBlock(x, 0, z, PlotBlock.get("bedrock")); + result.setBlock(x, 0, z, BlockUtil.get("bedrock")); } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java index cd711dd6e..0ab0947a4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java @@ -3,14 +3,21 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.commands.Template; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.FileBytes; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.google.common.collect.Sets; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import java.io.File; @@ -168,13 +175,13 @@ public class HybridPlotManager extends ClassicPlotManager { // The component blocks final BlockBucket plotfloor = hybridPlotWorld.TOP_BLOCK; final BlockBucket filling = hybridPlotWorld.MAIN_BLOCK; - final PlotBlock bedrock; + final BlockState bedrock; if (hybridPlotWorld.PLOT_BEDROCK) { - bedrock = PlotBlock.get((short) 7, (byte) 0); + bedrock = BlockUtil.get((short) 7, (byte) 0); } else { - bedrock = PlotBlock.get((short) 0, (byte) 0); + bedrock = BlockUtil.get((short) 0, (byte) 0); } - final PlotBlock air = PlotBlock.get((short) 0, (byte) 0); + final BlockState air = BlockUtil.get((short) 0, (byte) 0); final String biome = hybridPlotWorld.PLOT_BIOME; final LocalBlockQueue queue = hybridPlotWorld.getQueue(false); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java index 2f8c7c823..6b44487ce 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java @@ -14,7 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTagBuilder; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; import com.sk89q.worldedit.internal.helper.MCDirections; import com.sk89q.worldedit.math.BlockVector3; @@ -178,7 +178,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { if (schematic3 != null) { this.PLOT_SCHEMATIC = true; - BlockArrayClipboard blockArrayClipboard3 = schematic3.getClipboard(); + Clipboard blockArrayClipboard3 = schematic3.getClipboard(); BlockVector3 d3 = blockArrayClipboard3.getDimensions(); short w3 = (short) d3.getX(); @@ -252,9 +252,9 @@ public class HybridPlotWorld extends ClassicPlotWorld { } this.ROAD_SCHEMATIC_ENABLED = true; // Do not populate road if using schematic population - // TODO: What? this.ROAD_BLOCK = BlockBucket.empty(); // PlotBlock.getEmptyData(this.ROAD_BLOCK); // PlotBlock.get(this.ROAD_BLOCK.id, (byte) 0); + // TODO: What? this.ROAD_BLOCK = BlockBucket.empty(); // BlockState.getEmptyData(this.ROAD_BLOCK); // BlockUtil.get(this.ROAD_BLOCK.id, (byte) 0); - BlockArrayClipboard blockArrayClipboard1 = schematic1.getClipboard(); + Clipboard blockArrayClipboard1 = schematic1.getClipboard(); BlockVector3 d1 = blockArrayClipboard1.getDimensions(); short w1 = (short) d1.getX(); @@ -277,7 +277,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } - BlockArrayClipboard blockArrayClipboard2 = schematic2.getClipboard(); + Clipboard blockArrayClipboard2 = schematic2.getClipboard(); BlockVector3 d2 = blockArrayClipboard2.getDimensions(); short w2 = (short) d2.getX(); short l2 = (short) d2.getZ(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java index f7dc4d619..f397c3fc2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java @@ -5,7 +5,14 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.WEExtent; -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.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; @@ -15,26 +22,35 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import java.io.File; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; public abstract class HybridUtils { public static HybridUtils manager; - public static Set regions; - public static Set chunks = new HashSet<>(); + public static Set regions; + public static Set chunks = new HashSet<>(); public static PlotArea area; public static boolean UPDATE = false; - public abstract void analyzeRegion(String world, RegionWrapper region, + public abstract void analyzeRegion(String world, CuboidRegion region, RunnableVal whenDone); public void analyzePlot(final Plot origin, final RunnableVal whenDone) { - final ArrayDeque zones = new ArrayDeque<>(origin.getRegions()); + final ArrayDeque zones = new ArrayDeque<>(origin.getRegions()); final ArrayList analysis = new ArrayList<>(); Runnable run = new Runnable() { @Override public void run() { @@ -82,7 +98,7 @@ public abstract class HybridUtils { TaskManager.runTask(whenDone); return; } - RegionWrapper region = zones.poll(); + CuboidRegion region = zones.poll(); final Runnable task = this; analyzeRegion(origin.getWorldName(), region, new RunnableVal() { @Override public void run(PlotAnalysis value) { @@ -96,12 +112,12 @@ public abstract class HybridUtils { } public int checkModified(LocalBlockQueue queue, int x1, int x2, int y1, int y2, int z1, int z2, - PlotBlock[] blocks) { + BlockState[] blocks) { int count = 0; for (int y = y1; y <= y2; y++) { for (int x = x1; x <= x2; x++) { for (int z = z1; z <= z2; z++) { - PlotBlock block = queue.getBlock(x, y, z); + BlockState block = queue.getBlock(x, y, z); boolean same = Arrays.stream(blocks).anyMatch(p -> WorldUtil.IMP.isBlockSame(block, p)); if (!same) { @@ -113,13 +129,13 @@ public abstract class HybridUtils { return count; } - public final ArrayList getChunks(ChunkLoc region) { - ArrayList chunks = new ArrayList<>(); - int sx = region.x << 5; - int sz = region.z << 5; + public final ArrayList getChunks(BlockVector2 region) { + ArrayList chunks = new ArrayList<>(); + int sx = region.getX() << 5; + int sz = region.getZ() << 5; for (int x = sx; x < sx + 32; x++) { for (int z = sz; z < sz + 32; z++) { - chunks.add(new ChunkLoc(x, z)); + chunks.add(BlockVector2.at(x, z)); } } return chunks; @@ -130,7 +146,7 @@ public abstract class HybridUtils { return false; } HybridUtils.UPDATE = true; - Set regions = ChunkManager.manager.getChunkChunks(area.worldname); + Set regions = ChunkManager.manager.getChunkChunks(area.worldname); return scheduleRoadUpdate(area, regions, extend); } @@ -139,12 +155,12 @@ public abstract class HybridUtils { return false; } HybridUtils.UPDATE = true; - Set regions = new HashSet<>(); - regions.add(ChunkManager.getChunkChunk(plot.getCenter())); + Set regions = new HashSet<>(); + regions.add(ChunkManager.getRegion(plot.getCenter())); return scheduleRoadUpdate(plot.getArea(), regions, extend); } - public boolean scheduleRoadUpdate(final PlotArea area, Set regions, + public boolean scheduleRoadUpdate(final PlotArea area, Set regions, final int extend) { HybridUtils.regions = regions; HybridUtils.area = area; @@ -153,9 +169,9 @@ public abstract class HybridUtils { TaskManager.runTask(new Runnable() { @Override public void run() { if (!UPDATE) { - Iterator iter = chunks.iterator(); + Iterator iter = chunks.iterator(); while (iter.hasNext()) { - ChunkLoc chunk = iter.next(); + BlockVector2 chunk = iter.next(); iter.remove(); boolean regenedRoad = regenerateRoad(area, chunk, extend); if (!regenedRoad) { @@ -183,10 +199,10 @@ public abstract class HybridUtils { try { if (chunks.size() < 1024) { if (!HybridUtils.regions.isEmpty()) { - Iterator iterator = HybridUtils.regions.iterator(); - ChunkLoc loc = iterator.next(); + Iterator iterator = HybridUtils.regions.iterator(); + BlockVector2 loc = iterator.next(); iterator.remove(); - PlotSquared.debug("Updating .mcr: " + loc.x + ", " + loc.z + PlotSquared.debug("Updating .mcr: " + loc.getX() + ", " + loc.getZ() + " (approx 1024 chunks)"); PlotSquared .debug(" - Remaining: " + HybridUtils.regions.size()); @@ -198,10 +214,10 @@ public abstract class HybridUtils { TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { long start = System.currentTimeMillis(); - Iterator iterator = chunks.iterator(); + Iterator iterator = chunks.iterator(); while (System.currentTimeMillis() - start < 20 && !chunks .isEmpty()) { - final ChunkLoc chunk = iterator.next(); + final BlockVector2 chunk = iterator.next(); iterator.remove(); boolean regenedRoads = regenerateRoad(area, chunk, extend); @@ -214,18 +230,18 @@ public abstract class HybridUtils { } } catch (Exception e) { e.printStackTrace(); - Iterator iterator = HybridUtils.regions.iterator(); - ChunkLoc loc = iterator.next(); + Iterator iterator = HybridUtils.regions.iterator(); + BlockVector2 loc = iterator.next(); iterator.remove(); PlotSquared.debug( - "[ERROR] Could not update '" + area.worldname + "/region/r." + loc.x - + "." + loc.z + ".mca' (Corrupt chunk?)"); - int sx = loc.x << 5; - int sz = loc.z << 5; + "[ERROR] Could not update '" + area.worldname + "/region/r." + loc.getX() + + "." + loc.getZ() + ".mca' (Corrupt chunk?)"); + int sx = loc.getX() << 5; + int sz = loc.getZ() << 5; for (int x = sx; x < sx + 32; x++) { for (int z = sz; z < sz + 32; z++) { ChunkManager.manager - .unloadChunk(area.worldname, new ChunkLoc(x, z), true); + .unloadChunk(area.worldname, BlockVector2.at(x, z), true); } } PlotSquared.debug(" - Potentially skipping 1024 chunks"); @@ -256,10 +272,10 @@ public abstract class HybridUtils { int tz = sz - 1; int ty = get_ey(plotManager, queue, sx, ex, bz, tz, sy); - Set sideRoad = - new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ey, sz, ez))); - final Set intersection = - new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ty, bz, tz))); + Set sideRoad = + new HashSet<>(Collections.singletonList(RegionUtil.createRegion(sx, ex, sy, ey, sz, ez))); + final Set intersection = + new HashSet<>(Collections.singletonList(RegionUtil.createRegion(sx, ex, sy, ty, bz, tz))); final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.getArea() @@ -292,8 +308,8 @@ public abstract class HybridUtils { for (int z = sz; z <= ez; z++) { for (int y = sy; y <= pm.getWorldHeight(); y++) { if (y > ey) { - PlotBlock block = queue.getBlock(x, y, z); - if (!block.isAir()) { + BlockState block = queue.getBlock(x, y, z); + if (!block.getBlockType().getMaterial().isAir()) { ey = y; } } @@ -303,9 +319,9 @@ public abstract class HybridUtils { return ey; } - public boolean regenerateRoad(final PlotArea area, final ChunkLoc chunk, int extend) { - int x = chunk.x << 4; - int z = chunk.z << 4; + public boolean regenerateRoad(final PlotArea area, final BlockVector2 chunk, int extend) { + int x = chunk.getX() << 4; + int z = chunk.getZ() << 4; int ex = x + 15; int ez = z + 15; HybridPlotWorld plotWorld = (HybridPlotWorld) area; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java index 459aee272..def532368 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java @@ -1,7 +1,10 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.SetupObject; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; /** diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java index be19930fd..b05249d39 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java @@ -1,13 +1,19 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Direction; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; +import java.util.Set; /** * A plot manager with a square grid layout, with square shaped plots. @@ -23,20 +29,20 @@ public abstract class SquarePlotManager extends GridPlotManager { @Override public boolean clearPlot(final Plot plot, final Runnable whenDone) { - final HashSet regions = plot.getRegions(); + final Set regions = plot.getRegions(); Runnable run = new Runnable() { @Override public void run() { if (regions.isEmpty()) { whenDone.run(); return; } - Iterator iterator = regions.iterator(); - RegionWrapper region = iterator.next(); + Iterator iterator = regions.iterator(); + CuboidRegion region = iterator.next(); iterator.remove(); Location pos1 = - new Location(plot.getWorldName(), region.minX, region.minY, region.minZ); + new Location(plot.getWorldName(), region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); Location pos2 = - new Location(plot.getWorldName(), region.maxX, region.maxY, region.maxZ); + new Location(plot.getWorldName(), region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); ChunkManager.manager.regenerateRegion(pos1, pos2, false, this); } }; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index ce1007e15..7426b99c8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -8,11 +8,22 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.ByteArrayUtilities; +import com.github.intellectualsites.plotsquared.plot.util.CommentManager; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; +import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; import java.util.HashMap; import java.util.Map; @@ -135,21 +146,21 @@ public class PlotListener { Optional musicFlag = plot.getFlag(Flags.MUSIC); if (musicFlag.isPresent()) { final String id = musicFlag.get(); - final PlotBlock block = PlotBlock.get(id); - final String rawId = block.getRawId().toString(); - if (rawId.contains("disc") || PlotBlock.isEverything(block) || block.isAir()) { + final ItemType item = ItemUtil.get(id); + final String rawId = item.getId(); + if (rawId.contains("disc") || item == ItemTypes.AIR) { Location location = player.getLocation(); Location lastLocation = player.getMeta("music"); if (lastLocation != null) { - player.playMusic(lastLocation, PlotBlock.get("air")); - if (PlotBlock.isEverything(block) || block.isAir()) { + player.playMusic(lastLocation, ItemTypes.AIR); + if (item == ItemTypes.AIR) { player.deleteMeta("music"); } } - if (!(PlotBlock.isEverything(block) || block.isAir())) { + if (!(item == ItemTypes.AIR)) { try { player.setMeta("music", location); - player.playMusic(location, block); + player.playMusic(location, item); } catch (Exception ignored) { } } @@ -158,7 +169,7 @@ public class PlotListener { Location lastLoc = player.getMeta("music"); if (lastLoc != null) { player.deleteMeta("music"); - player.playMusic(lastLoc, PlotBlock.get("air")); + player.playMusic(lastLoc, ItemTypes.AIR); } } CommentManager.sendTitle(player, plot); @@ -266,7 +277,7 @@ public class PlotListener { Location lastLoc = player.getMeta("music"); if (lastLoc != null) { player.deleteMeta("music"); - player.playMusic(lastLoc, PlotBlock.get("air")); + player.playMusic(lastLoc, ItemTypes.AIR); } } return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java index 7d2d824b4..f72fb0520 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.listener; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -20,10 +20,11 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import java.lang.reflect.Field; import java.util.HashSet; +import java.util.Set; public class ProcessedWEExtent extends AbstractDelegateExtent { - private final HashSet mask; + private final Set mask; private final String world; private final int max; int BScount = 0; @@ -33,7 +34,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { private int count; private Extent parent; - public ProcessedWEExtent(String world, HashSet mask, int max, Extent child, + public ProcessedWEExtent(String world, Set mask, int max, Extent child, Extent parent) { super(child); this.mask = mask; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java index 073819fa3..ea9f404b8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.listener; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -16,14 +16,15 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.HashSet; +import java.util.Set; public class WEExtent extends AbstractDelegateExtent { public static BlockState AIRSTATE = BlockTypes.AIR.getDefaultState(); public static BaseBlock AIRBASE = BlockTypes.AIR.getDefaultState().toBaseBlock(); - private final HashSet mask; + private final Set mask; - public WEExtent(HashSet mask, Extent extent) { + public WEExtent(Set mask, Extent extent) { super(extent); this.mask = mask; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java index 3692efa51..8d0081273 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java @@ -7,62 +7,65 @@ import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class WEManager { - public static boolean maskContains(HashSet mask, int x, int y, int z) { - for (RegionWrapper region : mask) { - if (region.isIn(x, y, z)) { + public static boolean maskContains(Set mask, int x, int y, int z) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, y, z)) { return true; } } return false; } - public static boolean maskContains(HashSet mask, int x, int z) { - for (RegionWrapper region : mask) { - if (region.isIn(x, z)) { + public static boolean maskContains(Set mask, int x, int z) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, z)) { return true; } } return false; } - public static boolean maskContains(HashSet mask, double dx, double dy, + public static boolean maskContains(Set mask, double dx, double dy, double dz) { int x = Math.toIntExact(Math.round(dx >= 0 ? dx - 0.5 : dx + 0.5)); int y = Math.toIntExact(Math.round(dy - 0.5)); int z = Math.toIntExact(Math.round(dz >= 0 ? dz - 0.5 : dz + 0.5)); - for (RegionWrapper region : mask) { - if (region.isIn(x, y, z)) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, y, z)) { return true; } } return false; } - public static boolean maskContains(HashSet mask, double dx, double dz) { + public static boolean maskContains(Set mask, double dx, double dz) { int x = Math.toIntExact(Math.round(dx >= 0 ? dx - 0.5 : dx + 0.5)); int z = Math.toIntExact(Math.round(dz >= 0 ? dz - 0.5 : dz + 0.5)); - for (RegionWrapper region : mask) { - if (region.isIn(x, z)) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, z)) { return true; } } return false; } - public static HashSet getMask(PlotPlayer player) { - HashSet regions = new HashSet<>(); + public static HashSet getMask(PlotPlayer player) { + HashSet regions = new HashSet<>(); UUID uuid = player.getUUID(); Location location = player.getLocation(); String world = location.getWorld(); if (!PlotSquared.get().hasPlotArea(world)) { - regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, + regions.add(RegionUtil.createRegion(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)); return regions; } @@ -78,10 +81,10 @@ public class WEManager { if (plot != null && (!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot)) && ( (allowMember && plot.isAdded(uuid)) || (!allowMember && (plot.isOwner(uuid)) || plot .getTrusted().contains(uuid))) && !(Flags.NO_WORLDEDIT.isTrue(plot))) { - for (RegionWrapper region : plot.getRegions()) { - RegionWrapper copy = - new RegionWrapper(region.minX, region.maxX, area.MIN_BUILD_HEIGHT, - area.MAX_BUILD_HEIGHT, region.minZ, region.maxZ); + for (CuboidRegion region : plot.getRegions()) { + BlockVector3 pos1 = region.getMinimumPoint().withY(area.MIN_BUILD_HEIGHT); + BlockVector3 pos2 = region.getMaximumPoint().withY(area.MAX_BUILD_HEIGHT); + CuboidRegion copy = new CuboidRegion(pos1, pos2); regions.add(copy); } player.setMeta("WorldEditRegionPlot", plot); @@ -89,12 +92,12 @@ public class WEManager { return regions; } - public static boolean intersects(RegionWrapper region1, RegionWrapper region2) { - return region1.intersects(region2); + public static boolean intersects(CuboidRegion region1, CuboidRegion region2) { + return RegionUtil.intersects(region1, region2); } - public static boolean regionContains(RegionWrapper selection, HashSet mask) { - for (RegionWrapper region : mask) { + public static boolean regionContains(CuboidRegion selection, HashSet mask) { + for (CuboidRegion region : mask) { if (intersects(region, selection)) { return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java index 78379fd9e..a56063d08 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java @@ -5,7 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.sk89q.worldedit.WorldEdit; @@ -19,6 +19,7 @@ import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.World; import java.util.HashSet; +import java.util.Set; public class WESubscriber { @@ -37,7 +38,7 @@ public class WESubscriber { if (actor != null && actor.isPlayer()) { String name = actor.getName(); PlotPlayer plotPlayer = PlotPlayer.wrap(name); - HashSet mask; + Set mask; if (plotPlayer == null) { Player player = (Player) actor; Location location = player.getLocation(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java index 8dde0ee20..43b519fc3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java @@ -4,37 +4,45 @@ import com.github.intellectualsites.plotsquared.configuration.serialization.Conf import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.object.collection.RandomCollection; import com.google.common.collect.ImmutableMap; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import java.util.Map.Entry; +import java.util.Random; /** * 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, ConfigurationSerializable { +@EqualsAndHashCode(of={"blocks"}) @SuppressWarnings({"unused", "WeakerAccess"}) public final class BlockBucket + implements Iterable, ConfigurationSerializable { private final Random random = new Random(); - private final Map blocks; + private final Map blocks; private final BucketIterator bucketIterator = new BucketIterator(); private boolean compiled, singleItem; - private PlotBlock head; + private BlockState head; - private RandomCollection randomBlocks; - private PlotBlock single; + private RandomCollection randomBlocks; + private BlockState single; public BlockBucket() { this.blocks = new HashMap<>(); } - public static BlockBucket withSingle(@NonNull final PlotBlock block) { + public static BlockBucket withSingle(@NonNull final BlockState block) { final BlockBucket blockBucket = new BlockBucket(); blockBucket.addBlock(block, 100); return blockBucket; @@ -47,15 +55,15 @@ import java.util.Map.Entry; return Configuration.BLOCK_BUCKET.parseString(map.get("blocks").toString()); } - public void addBlock(@NonNull final PlotBlock block) { + public void addBlock(@NonNull final BlockState block) { this.addBlock(block, -1); } - public void addBlock(@NonNull final PlotBlock block, final int chance) { + public void addBlock(@NonNull final BlockState block, final int chance) { addBlock(block, (double) chance); } - private void addBlock(@NonNull final PlotBlock block, double chance) { + private void addBlock(@NonNull final BlockState block, double chance) { if (chance == -1) chance = 1; this.blocks.put(block, chance); @@ -75,7 +83,7 @@ import java.util.Map.Entry; * @return Immutable collection containing all blocks that can * be found in the bucket */ - public Collection getBlocks() { + public Collection getBlocks() { if (!isCompiled()) { this.compile(); } @@ -88,7 +96,7 @@ import java.util.Map.Entry; * @param count Number of blocks * @return Immutable collection containing randomly selected blocks */ - public Collection getBlocks(final int count) { + public Collection getBlocks(final int count) { return Arrays.asList(getBlockArray(count)); } @@ -98,8 +106,8 @@ import java.util.Map.Entry; * @param count Number of blocks * @return Immutable collection containing randomly selected blocks */ - public PlotBlock[] getBlockArray(final int count) { - final PlotBlock[] blocks = new PlotBlock[count]; + public BlockState[] getBlockArray(final int count) { + final BlockState[] blocks = new BlockState[count]; if (this.singleItem) { Arrays.fill(blocks, 0, count, getBlock()); } else { @@ -136,7 +144,7 @@ import java.util.Map.Entry; } } - @NotNull @Override public Iterator iterator() { + @NotNull @Override public Iterator iterator() { return this.bucketIterator; } @@ -149,7 +157,7 @@ import java.util.Map.Entry; * * @return Randomly picked block (cased on specified rates) */ - public PlotBlock getBlock() { + public BlockState getBlock() { if (!isCompiled()) { this.compile(); } @@ -159,19 +167,22 @@ import java.util.Map.Entry; if (randomBlocks != null) { return randomBlocks.next(); } - return StringPlotBlock.EVERYTHING; + return BlockTypes.AIR.getDefaultState(); } @Override public String toString() { if (!isCompiled()) { compile(); } + if (blocks.size() == 1) { + return blocks.entrySet().iterator().next().getKey().toString(); + } final StringBuilder builder = new StringBuilder(); - Iterator> iterator = blocks.entrySet().iterator(); + Iterator> iterator = blocks.entrySet().iterator(); while (iterator.hasNext()) { - Entry entry = iterator.next(); - PlotBlock block = entry.getKey(); - builder.append(block.getRawId()); + Entry entry = iterator.next(); + BlockState block = entry.getKey(); + builder.append(block); Double weight = entry.getValue(); if (weight != 1) { builder.append(":").append(weight.intValue()); @@ -183,6 +194,11 @@ import java.util.Map.Entry; return builder.toString(); } + public boolean isAir() { + compile(); + return blocks.isEmpty() || (single != null && single.getBlockType().getMaterial().isAir()); + } + @Override public Map serialize() { if (!isCompiled()) { compile(); @@ -190,7 +206,6 @@ import java.util.Map.Entry; return ImmutableMap.of("blocks", this.toString()); } - @Getter @EqualsAndHashCode @RequiredArgsConstructor private final static class Range { private final int min; @@ -207,13 +222,13 @@ import java.util.Map.Entry; } - private final class BucketIterator implements Iterator { + private final class BucketIterator implements Iterator { @Override public boolean hasNext() { return true; } - @Override public PlotBlock next() { + @Override public BlockState next() { return getBlock(); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockLoc.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockLoc.java index d170054a8..a4f02a9ef 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockLoc.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockLoc.java @@ -2,12 +2,12 @@ package com.github.intellectualsites.plotsquared.plot.object; public class BlockLoc { - public final int x; - public final int y; - public final int z; + private final int x; + private final int y; + private final int z; - public final float yaw; - public final float pitch; + private final float yaw; + private final float pitch; public BlockLoc(int x, int y, int z, float yaw, float pitch) { this.x = x; @@ -27,10 +27,6 @@ public class BlockLoc { float yaw; float pitch; - if (parts.length == 3) { - yaw = 0f; - pitch = 0f; - } if (parts.length == 5) { yaw = Float.parseFloat(parts[3]); pitch = Float.parseFloat(parts[4]); @@ -47,9 +43,9 @@ public class BlockLoc { @Override public int hashCode() { int prime = 31; int result = 1; - result = prime * result + this.x; - result = prime * result + this.y; - result = prime * result + this.z; + result = prime * result + this.getX(); + result = prime * result + this.getY(); + result = prime * result + this.getZ(); return result; } @@ -58,20 +54,42 @@ public class BlockLoc { return true; } if (obj == null) { - return this.x == 0 && this.y == 0 && this.z == 0; + return this.getX() == 0 && this.getY() == 0 && this.getZ() == 0; } if (getClass() != obj.getClass()) { return false; } BlockLoc other = (BlockLoc) obj; - return this.x == other.x && this.y == other.y && this.z == other.z; + return this.getX() == other.getX() && this.getY() == other.getY() && this.getZ() == other + .getZ(); } @Override public String toString() { - if (this.x == 0 && this.y == 0 && this.z == 0) { + if (this.getX() == 0 && this.getY() == 0 && this.getZ() == 0) { return ""; } - return this.x + "," + this.y + ',' + this.z + ',' + this.yaw + ',' + this.pitch; + return this.getX() + "," + this.getY() + ',' + this.getZ() + ',' + this.getYaw() + + ',' + this.getPitch(); } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getZ() { + return z; + } + + public float getYaw() { + return yaw; + } + + public float getPitch() { + return pitch; + } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockRegistry.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockRegistry.java deleted file mode 100644 index e125ca188..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockRegistry.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -import lombok.Getter; -import lombok.NonNull; - -import java.util.HashMap; -import java.util.Map; - -public abstract class BlockRegistry { - - @Getter private final Class type; - private final Map map = new HashMap<>(); - - public BlockRegistry(@NonNull final Class 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; - } - this.map.put(plotBlock, t); - } - - public abstract PlotBlock getPlotBlock(final T item); - - public final T getItem(final PlotBlock plotBlock) { - return this.map.get(plotBlock); - } - -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ChunkLoc.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ChunkLoc.java deleted file mode 100644 index 29bd3857f..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ChunkLoc.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -public class ChunkLoc { - - public int x; - public int z; - - public ChunkLoc(int x, int z) { - this.x = x; - this.z = z; - } - - public static long getChunkLong(int x, int z) { - return (long) x & 0xffffffffL | ((long) z & 0xffffffffL) << 32; - } - - public long toLong() { - return getChunkLong(this.x,this.z); - } - - public static int getX(long chunkLong) { - return (int)(chunkLong & 0xffffffffL); - } - - public static int getZ(long chunkLong) { - return (int)(chunkLong >>> 32 & 0xffffffffL); - } - - @Override public int hashCode() { - return (x << 16) | (z & 0xFFFF); - } - - @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ChunkLoc other = (ChunkLoc) obj; - return (this.x == other.x) && (this.z == other.z); - } - - @Override public String toString() { - return this.x + "," + this.z; - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java index 490a6e211..ae9fffb89 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java @@ -5,6 +5,10 @@ import com.github.intellectualsites.plotsquared.plot.commands.RequiredType; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.item.ItemType; import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -17,9 +21,9 @@ public class ConsolePlayer extends PlotPlayer { PlotArea area = PlotSquared.get().getFirstPlotArea(); Location location; if (area != null) { - RegionWrapper region = area.getRegion(); - location = new Location(area.worldname, region.minX + region.maxX / 2, 0, - region.minZ + region.maxZ / 2); + CuboidRegion region = area.getRegion(); + location = new Location(area.worldname, region.getMinimumPoint().getX() + region.getMaximumPoint().getX() / 2, 0, + region.getMinimumPoint().getZ() + region.getMaximumPoint().getZ() / 2); } else { location = new Location("world", 0, 0, 0); } @@ -34,6 +38,10 @@ public class ConsolePlayer extends PlotPlayer { return instance; } + @Override public Actor toActor() { + return PlotSquared.get().IMP.getConsole(); + } + @Override public boolean canTeleport(@NotNull Location location) { return true; } @@ -120,7 +128,7 @@ public class ConsolePlayer extends PlotPlayer { @Override public void setFlight(boolean fly) { } - @Override public void playMusic(@NotNull Location location, @NotNull PlotBlock id) { + @Override public void playMusic(@NotNull Location location, @NotNull ItemType id) { } @Override public void kick(String message) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LazyBlock.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LazyBlock.java index 3413bd235..9f3345a83 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LazyBlock.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LazyBlock.java @@ -1,10 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.object; +import com.sk89q.worldedit.world.block.BlockState; + public abstract class LazyBlock { - public abstract StringPlotBlock getPlotBlock(); + public abstract BlockState getBlockState(); public String getId() { - return getPlotBlock().getItemId(); + return getBlockState().toString(); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LegacyPlotBlock.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LegacyPlotBlock.java deleted file mode 100644 index 38407a52f..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/LegacyPlotBlock.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.registry.LegacyMapper; -import lombok.Getter; -import lombok.Setter; - -public class LegacyPlotBlock extends PlotBlock { - - public static final PlotBlock EVERYTHING = new LegacyPlotBlock((short) 0, (byte) 0); - public static final PlotBlock[] CACHE = new PlotBlock[65535]; - - static { - for (int i = 0; i < 65535; i++) { - short id = (short) (i >> 4); - byte data = (byte) (i & 15); - CACHE[i] = new LegacyPlotBlock(id, data); - } - } - - @Setter private BaseBlock baseBlock = null; - @Getter public final short id; - @Getter public final byte data; - - public LegacyPlotBlock(short id, byte data) { - this.id = id; - this.data = data; - } - - @Override public Object getRawId() { - return this.id; - } - - @Override public BaseBlock getBaseBlock() { - if (baseBlock == null) { - baseBlock = LegacyMapper.getInstance().getBlockFromLegacy(id, data).toBaseBlock(); - } - return baseBlock; - } - - @Override public boolean isAir() { - return this.id == 0; - } - - @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - LegacyPlotBlock other = (LegacyPlotBlock) obj; - return (this.id == other.id) && ((this.data == other.data) || (this.data == -1) || ( - other.data == -1)); - } - - @Override public int hashCode() { - return this.id; - } - - @Override public String toString() { - if (this.data == -1) { - return this.id + ""; - } - return this.id + ":" + this.data; - } - -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java index 2e28594df..30c8b19c8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java @@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import lombok.Getter; import lombok.Setter; @@ -26,10 +27,6 @@ public class Location implements Cloneable, Comparable { this.blockVector3 = BlockVector3.at(x, y, z); } - public Location() { - this.world = ""; - } - public Location(String world, int x, int y, int z) { this(world, x, y, z, 0f, 0f); } @@ -127,8 +124,8 @@ public class Location implements Cloneable, Comparable { } } - public ChunkLoc getChunkLoc() { - return new ChunkLoc(this.x >> 4, this.z >> 4); + public BlockVector2 getBlockVector2() { + return BlockVector2.at(this.x >> 4, this.z >> 4); } public Location add(int x, int y, int z) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index cafcae466..67fe23387 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -12,7 +12,17 @@ import com.github.intellectualsites.plotsquared.plot.generator.SquarePlotWorld; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; @@ -21,6 +31,9 @@ import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,8 +43,18 @@ import java.awt.geom.Rectangle2D; import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -45,13 +68,13 @@ import java.util.stream.Collectors; */ public class Plot { - private static final int MAX_HEIGHT = 256; + public static final int MAX_HEIGHT = 256; /** * @deprecated raw access is deprecated */ - @Deprecated private static HashSet connected_cache; - private static HashSet regions_cache; + @Deprecated private static Set connected_cache; + private static Set regions_cache; @NotNull private final PlotId id; @@ -844,7 +867,7 @@ public class Plot { return false; } } - final HashSet regions = this.getRegions(); + final Set regions = this.getRegions(); final Set plots = this.getConnectedPlots(); final ArrayDeque queue = new ArrayDeque<>(plots); if (isDelete) { @@ -856,8 +879,8 @@ public class Plot { @Override public void run() { if (queue.isEmpty()) { Runnable run = () -> { - for (RegionWrapper region : regions) { - Location[] corners = region.getCorners(getWorldName()); + for (CuboidRegion region : regions) { + Location[] corners = MainUtil.getCorners(getWorldName(), region); ChunkManager.manager.clearAllEntities(corners[0], corners[1]); } TaskManager.runTask(whenDone); @@ -899,7 +922,7 @@ public class Plot { * @param whenDone The task to run when finished, or null */ public void setBiome(final String biome, final Runnable whenDone) { - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); + final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); final int extendBiome; if (area instanceof SquarePlotWorld) { extendBiome = (((SquarePlotWorld) area).ROAD_WIDTH > 0) ? 1 : 0; @@ -913,14 +936,14 @@ public class Plot { TaskManager.runTask(whenDone); return; } - RegionWrapper region = regions.poll(); - Location pos1 = new Location(getWorldName(), region.minX - extendBiome, region.minY, - region.minZ - extendBiome); - Location pos2 = new Location(getWorldName(), region.maxX + extendBiome, region.maxY, - region.maxZ + extendBiome); + CuboidRegion region = regions.poll(); + Location pos1 = new Location(getWorldName(), region.getMinimumPoint().getX() - extendBiome, region.getMinimumPoint().getY(), + region.getMinimumPoint().getZ() - extendBiome); + Location pos2 = new Location(getWorldName(), region.getMaximumPoint().getX() + extendBiome, region.getMaximumPoint().getY(), + region.getMaximumPoint().getZ() + extendBiome); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { - ChunkLoc loc = new ChunkLoc(value[0], value[1]); + BlockVector2 loc = BlockVector2.at(value[0], value[1]); ChunkManager.manager.loadChunk(getWorldName(), loc, false); MainUtil.setBiome(getWorldName(), value[2], value[3], value[4], value[5], biome); @@ -1093,7 +1116,7 @@ public class Plot { * Delete a plot (use null for the runnable if you don't need to be notified on completion) * * @see PlotSquared#removePlot(Plot, boolean) - * @see #clear(Runnable) to simply clear a plot + * @see #clear(boolean, boolean, Runnable) to simply clear a plot */ public boolean deletePlot(final Runnable whenDone) { if (!this.hasOwner()) { @@ -1233,9 +1256,9 @@ public class Plot { } public Location getSide() { - RegionWrapper largest = getLargestRegion(); - int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; - int z = largest.minZ - 1; + CuboidRegion largest = getLargestRegion(); + int x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX(); + int z = largest.getMinimumPoint().getZ() - 1; PlotManager manager = getManager(); int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(getWorldName(), x, z) : 62; if (area.ALLOW_SIGNS && (y <= 0 || y >= 255)) { @@ -1251,17 +1274,18 @@ public class Plot { */ public Location getHome() { BlockLoc home = this.getPosition(); - if (home == null || home.x == 0 && home.z == 0) { + if (home == null || home.getX() == 0 && home.getZ() == 0) { return this.getDefaultHome(true); } else { Location bottom = this.getBottomAbs(); Location location = - new Location(bottom.getWorld(), bottom.getX() + home.x, bottom.getY() + home.y, - bottom.getZ() + home.z, home.yaw, home.pitch); + new Location(bottom.getWorld(), bottom.getX() + home.getX(), bottom.getY() + home + .getY(), + bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch()); if (!isLoaded()) { return location; } - if (!WorldUtil.IMP.getBlock(location).isAir()) { + if (!WorldUtil.IMP.getBlock(location).getBlockType().getMaterial().isAir()) { location.setY(Math.max(1 + WorldUtil.IMP .getHighestBlock(this.getWorldName(), location.getX(), location.getZ()), bottom.getY())); @@ -1306,9 +1330,9 @@ public class Plot { int z; if (loc.getX() == Integer.MAX_VALUE && loc.getZ() == Integer.MAX_VALUE) { // center - RegionWrapper largest = plot.getLargestRegion(); - x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; - z = (largest.maxZ >> 1) - (largest.minZ >> 1) + largest.minZ; + CuboidRegion largest = plot.getLargestRegion(); + x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX(); + z = (largest.getMaximumPoint().getZ() >> 1) - (largest.getMinimumPoint().getZ() >> 1) + largest.getMinimumPoint().getZ(); } else { // specific Location bot = plot.getBottomAbs(); @@ -1326,9 +1350,9 @@ public class Plot { public double getVolume() { double count = 0; - for (RegionWrapper region : getRegions()) { + for (CuboidRegion region : getRegions()) { count += - (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1) + (region.getMaximumPoint().getX() - (double) region.getMinimumPoint().getX() + 1) * (region.getMaximumPoint().getZ() - (double) region.getMinimumPoint().getZ() + 1) * MAX_HEIGHT; } return count; @@ -1413,11 +1437,11 @@ public class Plot { */ public void refreshChunks() { LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); - HashSet chunks = new HashSet<>(); - for (RegionWrapper region : Plot.this.getRegions()) { - for (int x = region.minX >> 4; x <= region.maxX >> 4; x++) { - for (int z = region.minZ >> 4; z <= region.maxZ >> 4; z++) { - if (chunks.add(new ChunkLoc(x, z))) { + HashSet chunks = new HashSet<>(); + for (CuboidRegion region : Plot.this.getRegions()) { + for (int x = region.getMinimumPoint().getX() >> 4; x <= region.getMaximumPoint().getX() >> 4; x++) { + for (int z = region.getMinimumPoint().getZ() >> 4; z <= region.getMaximumPoint().getZ() >> 4; z++) { + if (chunks.add(BlockVector2.at(x, z))) { queue.refreshChunk(x, z); } } @@ -1435,7 +1459,7 @@ public class Plot { } Location location = manager.getSignLoc(this); LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); - queue.setBlock(location.getX(), location.getY(), location.getZ(), PlotBlock.get("air")); + queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockUtil.get("air")); queue.flush(); } @@ -2142,7 +2166,7 @@ public class Plot { String[] lines = TaskManager.IMP.sync(new RunnableVal() { @Override public void run(String[] value) { ChunkManager.manager - .loadChunk(location.getWorld(), location.getChunkLoc(), false); + .loadChunk(location.getWorld(), location.getBlockVector2(), false); this.value = WorldUtil.IMP.getSign(location); } }); @@ -2571,7 +2595,7 @@ public class Plot { * * @return */ - @NotNull public HashSet getRegions() { + @NotNull public Set getRegions() { if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) { return regions_cache; } @@ -2579,14 +2603,13 @@ public class Plot { Location pos1 = this.getBottomAbs(); Location pos2 = this.getTopAbs(); connected_cache = Sets.newHashSet(this); - regions_cache = Sets.newHashSet( - new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getY(), pos2.getY(), pos1.getZ(), - pos2.getZ())); + CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()); + regions_cache = Collections.singleton(rg); return regions_cache; } Set plots = this.getConnectedPlots(); - HashSet regions = regions_cache = new HashSet<>(); - HashSet visited = new HashSet<>(); + Set regions = regions_cache = new HashSet<>(); + Set visited = new HashSet<>(); for (Plot current : plots) { if (visited.contains(current.getId())) { continue; @@ -2663,12 +2686,14 @@ public class Plot { Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); Location topabs = plot.getTopAbs(); - regions.add(new RegionWrapper(botabs.getX(), topabs.getX(), topabs.getZ() + 1, - toploc.getZ())); + BlockVector3 pos1 = BlockVector3.at(botabs.getX(), 0, topabs.getZ() + 1); + BlockVector3 pos2 = BlockVector3.at(topabs.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); + regions.add(new CuboidRegion(pos1, pos2)); if (plot.getMerged(Direction.SOUTHEAST)) { + pos1 = BlockVector3.at(topabs.getX() + 1, 0, topabs.getZ() + 1); + pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add( - new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1, - toploc.getZ())); + new CuboidRegion(pos1, pos2)); // intersection } } @@ -2681,18 +2706,22 @@ public class Plot { Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); Location topabs = plot.getTopAbs(); - regions.add(new RegionWrapper(topabs.getX() + 1, toploc.getX(), botabs.getZ(), - topabs.getZ())); + BlockVector3 pos1 = BlockVector3.at(topabs.getX() + 1, 0, botabs.getZ()); + BlockVector3 pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, topabs.getZ()); + regions.add(new CuboidRegion(pos1, pos2)); if (plot.getMerged(Direction.SOUTHEAST)) { + pos1 = BlockVector3.at(topabs.getX() + 1, 0, topabs.getZ() + 1); + pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add( - new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1, - toploc.getZ())); + new CuboidRegion(pos1, pos2)); // intersection } } } + BlockVector3 pos1 = BlockVector3.at(gbotabs.getX() + 1, 0, gbotabs.getZ()); + BlockVector3 pos2 = BlockVector3.at(gtopabs.getX(), Plot.MAX_HEIGHT - 1, gtopabs.getZ()); regions.add( - new RegionWrapper(gbotabs.getX(), gtopabs.getX(), gbotabs.getZ(), gtopabs.getZ())); + new CuboidRegion(pos1, pos2)); } return regions; } @@ -2702,13 +2731,13 @@ public class Plot { * * @return */ - public RegionWrapper getLargestRegion() { - HashSet regions = this.getRegions(); - RegionWrapper max = null; + public CuboidRegion getLargestRegion() { + Set regions = this.getRegions(); + CuboidRegion max = null; double area = Double.NEGATIVE_INFINITY; - for (RegionWrapper region : regions) { + for (CuboidRegion region : regions) { double current = - (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1); + (region.getMaximumPoint().getX() - (double) region.getMinimumPoint().getX() + 1) * (region.getMaximumPoint().getZ() - (double) region.getMinimumPoint().getZ() + 1); if (current > area) { max = region; area = current; @@ -2737,9 +2766,9 @@ public class Plot { */ public List getAllCorners() { Area area = new Area(); - for (RegionWrapper region : this.getRegions()) { - Rectangle2D rect = new Rectangle2D.Double(region.minX - 0.6, region.minZ - 0.6, - region.maxX - region.minX + 1.2, region.maxZ - region.minZ + 1.2); + for (CuboidRegion region : this.getRegions()) { + Rectangle2D rect = new Rectangle2D.Double(region.getMinimumPoint().getX() - 0.6, region.getMinimumPoint().getZ() - 0.6, + region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + 1.2, region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + 1.2); Area rectArea = new Area(rect); area.add(rectArea); } @@ -2954,7 +2983,7 @@ public class Plot { } // world border destination.updateWorldBorder(); - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); + final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); // move / swap data final PlotArea originArea = getArea(); for (Plot plot : plots) { @@ -2969,8 +2998,8 @@ public class Plot { TaskManager.runTask(whenDone); return; } - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); + CuboidRegion region = regions.poll(); + Location[] corners = MainUtil.getCorners(getWorldName(), region); Location pos1 = corners[0]; Location pos2 = corners[1]; Location pos3 = pos1.clone().add(offsetX, 0, offsetZ); @@ -2997,8 +3026,8 @@ public class Plot { return; } final Runnable task = this; - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); + CuboidRegion region = regions.poll(); + Location[] corners = MainUtil.getCorners(getWorldName(), region); final Location pos1 = corners[0]; final Location pos2 = corners[1]; Location newPos = pos1.clone().add(offsetX, 0, offsetZ); @@ -3071,7 +3100,7 @@ public class Plot { } } // copy terrain - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); + final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); Runnable run = new Runnable() { @Override public void run() { if (regions.isEmpty()) { @@ -3082,8 +3111,8 @@ public class Plot { TaskManager.runTask(whenDone); return; } - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); + CuboidRegion region = regions.poll(); + Location[] corners = MainUtil.getCorners(getWorldName(), region); Location pos1 = corners[0]; Location pos2 = corners[1]; Location newPos = pos1.clone().add(offsetX, 0, offsetZ); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index ff6668ea4..970c427b8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -19,13 +19,25 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; @@ -71,7 +83,7 @@ public abstract class PlotArea { public int MIN_BUILD_HEIGHT = 1; public PlotGameMode GAMEMODE = PlotGameMode.CREATIVE; private int hash; - private RegionWrapper region; + private CuboidRegion region; private ConcurrentHashMap meta; private QuadMap clusters; @@ -120,16 +132,16 @@ public abstract class PlotArea { } /** - * Returns the region for this PlotArea or a RegionWrapper encompassing + * Returns the region for this PlotArea or a CuboidRegion encompassing * the whole world if none exists. * - * @return RegionWrapper + * @return CuboidRegion */ - public RegionWrapper getRegion() { + public CuboidRegion getRegion() { this.region = getRegionAbs(); if (this.region == null) { - return new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, - Integer.MAX_VALUE); + return new CuboidRegion(BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), + BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)); } return this.region; } @@ -137,15 +149,16 @@ public abstract class PlotArea { /** * Returns the region for this PlotArea. * - * @return RegionWrapper or null if no applicable region + * @return CuboidRegion or null if no applicable region */ - private RegionWrapper getRegionAbs() { + private CuboidRegion getRegionAbs() { if (this.region == null) { if (this.min != null) { Location bot = getPlotManager().getPlotBottomLocAbs(this.min); Location top = getPlotManager().getPlotTopLocAbs(this.max); - this.region = new RegionWrapper(bot.getX() - 1, top.getX() + 1, bot.getZ() - 1, - top.getZ() + 1); + BlockVector3 pos1 = bot.getBlockVector3().subtract(BlockVector3.ONE); + BlockVector3 pos2 = top.getBlockVector3().add(BlockVector3.ONE); + this.region = new CuboidRegion(pos1, pos2); } } return this.region; @@ -489,7 +502,7 @@ public abstract class PlotArea { } public boolean contains(final int x, final int z) { - return this.TYPE != 2 || getRegionAbs().isIn(x, z); + return this.TYPE != 2 || RegionUtil.contains(getRegionAbs(), x, z); } public boolean contains(@NotNull final PlotId id) { @@ -499,7 +512,7 @@ public abstract class PlotArea { public boolean contains(@NotNull final Location location) { return StringMan.isEqual(location.getWorld(), this.worldname) && (getRegionAbs() == null - || this.region.isIn(location.getX(), location.getZ())); + || this.region.contains(location.getBlockVector3())); } @NotNull Set getPlotsAbs(final UUID uuid) { @@ -932,9 +945,10 @@ public abstract class PlotArea { public void addCluster(@Nullable final PlotCluster plotCluster) { if (this.clusters == null) { this.clusters = new QuadMap(Integer.MAX_VALUE, 0, 0, 62) { - @Override public RegionWrapper getRegion(PlotCluster value) { - return new RegionWrapper(value.getP1().x, value.getP2().x, value.getP1().y, - value.getP2().y); + @Override public CuboidRegion getRegion(PlotCluster value) { + BlockVector2 pos1 = BlockVector2.at(value.getP1().x, value.getP1().y); + BlockVector2 pos2 = BlockVector2.at(value.getP2().x, value.getP2().y); + return new CuboidRegion(pos1.toBlockVector3(), pos2.toBlockVector3(Plot.MAX_HEIGHT - 1)); } }; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotBlock.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotBlock.java deleted file mode 100644 index 5b9de5852..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotBlock.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerializable; -import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.google.common.collect.ImmutableMap; -import com.sk89q.worldedit.world.block.BaseBlock; -import lombok.NonNull; - -import java.util.Collection; -import java.util.Map; - -public abstract class PlotBlock implements ConfigurationSerializable { - - private static Class conversionType; - private static BlockRegistry blockRegistry; - - protected PlotBlock() { - } - - public static boolean isEverything(@NonNull final PlotBlock block) { - return block.equals(LegacyPlotBlock.EVERYTHING) || block.equals(StringPlotBlock.EVERYTHING); - } - - public static boolean containsEverything(@NonNull final Collection blocks) { - for (final PlotBlock block : blocks) { - if (isEverything(block)) { - return true; - } - } - return false; - } - - public static PlotBlock get(char combinedId) { - switch (combinedId) { - case 0: - return null; - case 1: - return get(0, 0); - default: - return get(combinedId >> 4, combinedId & 15); - } - } - - public static PlotBlock deserialize(@NonNull final Map map) { - if (map.containsKey("material")) { - final Object object = map.get("material"); - return get(object.toString()); - } - return null; - } - - public static StringPlotBlock get(@NonNull final String itemId) { - if (Settings.Enabled_Components.BLOCK_CACHE) { - return StringPlotBlock.getOrAdd(itemId); - } - return new StringPlotBlock(itemId); - } - - public static PlotBlock get(int id, int data) { - return Settings.Enabled_Components.BLOCK_CACHE && data > 0 ? - LegacyPlotBlock.CACHE[(id << 4) + data] : - new LegacyPlotBlock((short) id, (byte) data); - } - - public static PlotBlock getEmptyData(@NonNull final PlotBlock plotBlock) { - if (plotBlock instanceof StringPlotBlock) { - return plotBlock; - } - return get(((LegacyPlotBlock) plotBlock).getId(), (byte) 0); - } - - public static PlotBlock get(@NonNull final BaseBlock baseBlock) { - StringPlotBlock plotBlock = get(baseBlock.getBlockType().getId()); - plotBlock.setBaseBlock(baseBlock); - return plotBlock; - } - - public static PlotBlock get(@NonNull final Object type) { - if (blockRegistry == null) { - blockRegistry = PlotSquared.imp().getBlockRegistry(); - if (blockRegistry == null) { - throw new UnsupportedOperationException( - "The PlotSquared implementation has not registered a custom block registry." - + " This method can't be used."); - } - conversionType = blockRegistry.getType(); - } - if (!type.getClass().equals(conversionType)) { - throw new UnsupportedOperationException( - "The PlotSquared implementation has not registered a block registry for this object type"); - } - return blockRegistry.getPlotBlock(type); - } - - @Override public Map serialize() { - return ImmutableMap.of("material", this.getRawId()); - } - - public T to(@NonNull final Class clazz) { - if (blockRegistry == null) { - blockRegistry = PlotSquared.imp().getBlockRegistry(); - if (blockRegistry == null) { - throw new UnsupportedOperationException( - "The PlotSquared implementation has not registered a custom block registry." - + " This method can't be used."); - } - conversionType = blockRegistry.getType(); - } - if (!clazz.equals(conversionType)) { - throw new UnsupportedOperationException( - "The PlotSquared implementation has not registered a block registry for this object type"); - } - return clazz.cast(blockRegistry.getItem(this)); - } - - public abstract boolean isAir(); - - public final boolean equalsAny(final int id, @NonNull final String stringId) { - if (this instanceof StringPlotBlock) { - final StringPlotBlock stringPlotBlock = (StringPlotBlock) this; - return stringPlotBlock.idEquals(stringId); - } - final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) this; - return legacyPlotBlock.id == id; - } - - @Override public abstract boolean equals(Object obj); - - @Override public abstract int hashCode(); - - @Override public abstract String toString(); - - public abstract Object getRawId(); - - public abstract BaseBlock getBaseBlock(); - -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java index feaf64ddb..4a653d8dd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java @@ -2,6 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.HashSet; import java.util.UUID; @@ -15,7 +17,7 @@ public class PlotCluster { public int temp; private PlotId pos1; private PlotId pos2; - private RegionWrapper region; + private CuboidRegion region; public PlotCluster(PlotArea area, PlotId pos1, PlotId pos2, UUID owner) { this.area = area; @@ -56,10 +58,10 @@ public class PlotCluster { } private void setRegion() { - this.region = new RegionWrapper(this.pos1.x, this.pos2.x, this.pos1.y, this.pos2.y); + this.region = RegionUtil.createRegion(this.pos1.x, this.pos2.x, this.pos1.y, this.pos2.y); } - public RegionWrapper getRegion() { + public CuboidRegion getRegion() { return this.region; } @@ -126,7 +128,7 @@ public class PlotCluster { public Location getHome() { BlockLoc home = this.settings.getPosition(); Location toReturn; - if (home.y == 0) { + if (home.getY() == 0) { // default pos Plot center = getCenterPlot(); toReturn = center.getHome(); @@ -136,7 +138,7 @@ public class PlotCluster { toReturn.setY(location.getY()); } } else { - toReturn = getClusterBottom().add(home.x, home.y, home.z); + toReturn = getClusterBottom().add(home.getX(), home.getY(), home.getZ()); } int max = MainUtil.getHeighestBlock(this.area.worldname, toReturn.getX(), toReturn.getZ()); if (max > toReturn.getY()) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java index 21e7dc777..a777a6b6f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java @@ -25,6 +25,14 @@ public class PlotId { this.y = y; } + public int getX() { + return x; + } + + public int getY() { + return y; + } + /** * Get a Plot Id based on a string * @@ -40,7 +48,7 @@ public class PlotId { } @Nullable public static PlotId fromStringOrNull(@NotNull String string) { - String[] parts = string.split("[;|,]"); + String[] parts = string.split("[;,.]"); if (parts.length < 2) { return null; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotItemStack.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotItemStack.java index c0a9d93d0..b142eda79 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotItemStack.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotItemStack.java @@ -1,7 +1,9 @@ package com.github.intellectualsites.plotsquared.plot.object; -import com.github.intellectualsites.plotsquared.plot.util.StringComparison; -import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; +import com.sk89q.worldedit.world.registry.LegacyMapper; import lombok.Getter; public class PlotItemStack { @@ -9,7 +11,7 @@ public class PlotItemStack { public final int amount; public final String name; public final String[] lore; - @Getter private final PlotBlock plotBlock; + @Getter private final ItemType type; /** * @param id Legacy numerical item ID @@ -21,10 +23,11 @@ public class PlotItemStack { */ @Deprecated public PlotItemStack(final int id, final short data, final int amount, final String name, final String... lore) { + this.amount = amount; this.name = name; this.lore = lore; - this.plotBlock = PlotBlock.get(id, data); + this.type = LegacyMapper.getInstance().getItemFromLegacy(id, data); } /** @@ -35,10 +38,13 @@ public class PlotItemStack { */ public PlotItemStack(final String id, final int amount, final String name, final String... lore) { - StringComparison.ComparisonResult match = WorldUtil.IMP.getClosestBlock(id); - this.plotBlock = match.best; + this.type = ItemTypes.get(id); this.amount = amount; this.name = name; this.lore = lore; } + + public BlockState getBlockState() { + return type.getBlockType().getDefaultState(); + } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java index 0b39b2b7d..8f50f3504 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java @@ -90,6 +90,21 @@ public abstract class PlotManager { return 255; } - public abstract boolean regenerateAllPlotWalls(); + /** + * Sets all the blocks along all the plot walls to their correct state (claimed or unclaimed). + * + * @return true if the wall blocks were successfully set + */ + public boolean regenerateAllPlotWalls() { + boolean success = true; + for (Plot plot : plotArea.getPlots()) { + if (plot.hasOwner()) { + success &= claimPlot(plot); + } else { + success &= unClaimPlot(plot, null); + } + } + return success; + } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java index f8e21255b..f48cbc981 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java @@ -10,9 +10,17 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; +import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.google.common.base.Preconditions; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.world.item.ItemType; import lombok.NonNull; import org.jetbrains.annotations.NotNull; @@ -79,6 +87,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { return UUIDHandler.getPlayer(name); } + public abstract Actor toActor(); + /** * Set some session only metadata for this player. * @@ -464,7 +474,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { * @param location where to play the music * @param id the record item id */ - public abstract void playMusic(@NotNull Location location, @NotNull PlotBlock id); + public abstract void playMusic(@NotNull Location location, @NotNull ItemType id); /** * Check if this player is banned. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java index ce51fea33..8d7904690 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java @@ -104,7 +104,7 @@ public class PlotSettings { } public void setPosition(BlockLoc position) { - if (position != null && position.x == 0 && position.y == 0 && position.z == 0) { + if (position != null && position.getX() == 0 && position.getY() == 0 && position.getZ() == 0) { position = null; } this.position = position; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java deleted file mode 100644 index ced127a22..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -public class RegionWrapper { - public final int minX; - public final int maxX; - public final int minY; - public final int maxY; - public final int minZ; - public final int maxZ; - - public RegionWrapper(int minX, int maxX, int minZ, int maxZ) { - this.maxX = maxX; - this.minX = minX; - this.maxZ = maxZ; - this.minZ = minZ; - this.minY = 0; - this.maxY = 256; - } - - public RegionWrapper(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { - this.maxX = maxX; - this.minX = minX; - this.maxZ = maxZ; - this.minZ = minZ; - this.minY = minY; - this.maxY = maxY; - } - - public boolean isIn(int x, int y, int z) { - return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ - && y >= this.minY && y <= this.maxY; - } - - public boolean isIn(int x, int z) { - return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ; - } - - public boolean intersects(RegionWrapper other) { - return other.minX <= this.maxX && other.maxX >= this.minX && other.minY <= this.maxY - && other.maxY >= this.minY; - } - - @Override public int hashCode() { - return this.minX + 13 * this.maxX + 23 * this.minZ + 39 * this.maxZ; - } - - @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (obj instanceof RegionWrapper) { - RegionWrapper other = (RegionWrapper) obj; - return this.minX == other.minX && this.minZ == other.minZ && this.minY == other.minY - && this.maxX == other.maxX && this.maxZ == other.maxZ && this.maxY == other.maxY; - } - return false; - } - - @Override public String toString() { - return this.minX + "->" + this.maxX + "," + this.minZ + "->" + this.maxZ; - } - - public Location[] getCorners(String world) { - Location pos1 = new Location(world, this.minX, this.minY, this.minZ); - Location pos2 = new Location(world, this.maxX, this.maxY, this.maxZ); - return new Location[] {pos1, pos2}; - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/StringPlotBlock.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/StringPlotBlock.java deleted file mode 100644 index d4119ae92..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/StringPlotBlock.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockTypes; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -public class StringPlotBlock extends PlotBlock { - - public static final PlotBlock EVERYTHING = new StringPlotBlock("air"); - private static final Map STRING_PLOT_BLOCK_CACHE = new HashMap<>(); - @Getter private final String nameSpace; - @Getter private final String itemId; - @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); - this.determineForeign(); - } - - public StringPlotBlock(@NonNull final String itemId) { - if (itemId.contains(":")) { - final String[] parts = itemId.split(":"); - if (parts.length < 2) { - throw new IllegalArgumentException(String.format("Cannot parse \"%s\"", itemId)); - } - this.nameSpace = parts[0].toLowerCase(Locale.ENGLISH); - this.itemId = parts[1].toLowerCase(Locale.ENGLISH); - } else { - this.nameSpace = "minecraft"; - if (itemId.isEmpty()) { - this.itemId = "air"; - } else { - this.itemId = itemId.toLowerCase(Locale.ENGLISH); - } - } - this.determineForeign(); - } - - public static StringPlotBlock getOrAdd(@NonNull final String itemId) { - // final String id = itemId.toLowerCase(Locale.ENGLISH); - - StringPlotBlock plotBlock = STRING_PLOT_BLOCK_CACHE.get(itemId); - if (plotBlock == null) { - plotBlock = new StringPlotBlock(itemId); - STRING_PLOT_BLOCK_CACHE.put(itemId, plotBlock); - } - - return plotBlock; - } - - private void determineForeign() { - this.isForeign = !this.nameSpace.equals("minecraft"); - } - - @Override public String toString() { - return this.isForeign ? String.format("%s:%s", nameSpace, itemId) : itemId; - } - - @Override public boolean isAir() { - return this.itemId.isEmpty() || this.itemId.equalsIgnoreCase("air"); - } - - @Override public int hashCode() { - return this.toString().hashCode(); - } - - public boolean idEquals(@NonNull final String id) { - return id.equalsIgnoreCase(this.itemId); - } - - @Override public Object getRawId() { - return this.getItemId(); - } - - @Override public BaseBlock getBaseBlock() { - if (baseBlock == null) { - baseBlock = BlockTypes.get(itemId).getDefaultState().toBaseBlock(); - } - return baseBlock; - } - - @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - StringPlotBlock other = (StringPlotBlock) obj; - return other.nameSpace.equals(this.nameSpace) && other.itemId.equals(this.itemId); - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/ItemType.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/ItemType.java deleted file mode 100644 index f558b5243..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/ItemType.java +++ /dev/null @@ -1,307 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object.schematic; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public enum ItemType { - AIR("air", 0), STONE("stone", 1), GRANITE("stone", 1, 1), POLISHED_GRANITE("stone", 1, - 2), DIORITE("stone", 1, 3), POLISHED_DIORITE("stone", 1, 4), ANDESITE("stone", 1, - 5), POLISHED_ANDESITE("stone", 1, 6), GRASS("grass", 2), DIRT("dirt", 3), COARSE_DIRT( - "dirt", 3, 1), PODZOL("dirt", 3, 2), COBBLESTONE("cobblestone", 4), OAK_WOOD_PLANK("planks", - 5), SPRUCE_WOOD_PLANK("planks", 5, 1), BIRCH_WOOD_PLANK("planks", 5, 2), JUNGLE_WOOD_PLANK( - "planks", 5, 3), ACACIA_WOOD_PLANK("planks", 5, 4), DARK_OAK_WOOD_PLANK("planks", 5, - 5), OAK_SAPLING("sapling", 6), SPRUCE_SAPLING("sapling", 6, 1), BIRCH_SAPLING("sapling", 6, - 2), JUNGLE_SAPLING("sapling", 6, 3), ACACIA_SAPLING("sapling", 6, 4), DARK_OAK_SAPLING( - "sapling", 6, 5), BEDROCK("bedrock", 7), FLOWING_WATER("flowing_water", 8), STILL_WATER( - "water", 9), FLOWING_LAVA("flowing_lava", 10), STILL_LAVA("lava", 11), SAND("sand", - 12), RED_SAND("sand", 12, 1), GRAVEL("gravel", 13), GOLD_ORE("gold_ore", 14), IRON_ORE( - "iron_ore", 15), COAL_ORE("coal_ore", 16), OAK_WOOD("log", 17), SPRUCE_WOOD("log", 17, - 1), BIRCH_WOOD("log", 17, 2), JUNGLE_WOOD("log", 17, 3), OAK_LEAVES("leaves", - 18), SPRUCE_LEAVES("leaves", 18, 1), BIRCH_LEAVES("leaves", 18, 2), JUNGLE_LEAVES("leaves", - 18, 3), SPONGE("sponge", 19), WET_SPONGE("sponge", 19, 1), GLASS("glass", - 20), LAPIS_LAZULI_ORE("lapis_ore", 21), LAPIS_LAZULI_BLOCK("lapis_block", 22), DISPENSER( - "dispenser", 23), SANDSTONE("sandstone", 24), CHISELED_SANDSTONE("sandstone", 24, - 1), SMOOTH_SANDSTONE("sandstone", 24, 2), NOTE_BLOCK("noteblock", 25), BED("bed", - 26), POWERED_RAIL("golden_rail", 27), DETECTOR_RAIL("detector_rail", 28), STICKY_PISTON( - "sticky_piston", 29), COBWEB("web", 30), DEAD_SHRUB("tallgrass", 31), TALLGRASS("tallgrass", - 31, 1), FERN("tallgrass", 31, 2), DEAD_SHRUB1("deadbush", 32), PISTON("piston", - 33), PISTON_HEAD("piston_head", 34), WHITE_WOOL("wool", 35), ORANGE_WOOL("wool", 35, - 1), MAGENTA_WOOL("wool", 35, 2), LIGHT_BLUE_WOOL("wool", 35, 3), YELLOW_WOOL("wool", 35, - 4), LIME_WOOL("wool", 35, 5), PINK_WOOL("wool", 35, 6), GRAY_WOOL("wool", 35, - 7), LIGHT_GRAY_WOOL("wool", 35, 8), CYAN_WOOL("wool", 35, 9), PURPLE_WOOL("wool", 35, - 10), BLUE_WOOL("wool", 35, 11), BROWN_WOOL("wool", 35, 12), GREEN_WOOL("wool", 35, - 13), RED_WOOL("wool", 35, 14), BLACK_WOOL("wool", 35, 15), DANDELION("yellow_flower", - 37), POPPY("red_flower", 38), BLUE_ORCHID("red_flower", 38, 1), ALLIUM("red_flower", 38, - 2), AZURE_BLUET("red_flower", 38, 3), RED_TULIP("red_flower", 38, 4), ORANGE_TULIP( - "red_flower", 38, 5), WHITE_TULIP("red_flower", 38, 6), PINK_TULIP("red_flower", 38, - 7), OXEYE_DAISY("red_flower", 38, 8), BROWN_MUSHROOM("brown_mushroom", 39), RED_MUSHROOM( - "red_mushroom", 40), GOLD_BLOCK("gold_block", 41), IRON_BLOCK("iron_block", - 42), DOUBLE_STONE_SLAB("double_stone_slab", 43), DOUBLE_SANDSTONE_SLAB("double_stone_slab", - 43, 1), DOUBLE_WOODEN_SLAB("double_stone_slab", 43, 2), DOUBLE_COBBLESTONE_SLAB( - "double_stone_slab", 43, 3), DOUBLE_BRICK_SLAB("double_stone_slab", 43, - 4), DOUBLE_STONE_BRICK_SLAB("double_stone_slab", 43, 5), DOUBLE_NETHER_BRICK_SLAB( - "double_stone_slab", 43, 6), DOUBLE_QUARTZ_SLAB("double_stone_slab", 43, 7), STONE_SLAB( - "stone_slab", 44), SANDSTONE_SLAB("stone_slab", 44, 1), WOODEN_SLAB("stone_slab", 44, - 2), COBBLESTONE_SLAB("stone_slab", 44, 3), BRICK_SLAB("stone_slab", 44, - 4), STONE_BRICK_SLAB("stone_slab", 44, 5), NETHER_BRICK_SLAB("stone_slab", 44, - 6), QUARTZ_SLAB("stone_slab", 44, 7), BRICKS("brick_block", 45), TNT("tnt", 46), BOOKSHELF( - "bookshelf", 47), MOSS_STONE("mossy_cobblestone", 48), OBSIDIAN("obsidian", 49), TORCH( - "torch", 50), FIRE("fire", 51), MONSTER_SPAWNER("mob_spawner", 52), OAK_WOOD_STAIRS( - "oak_stairs", 53), CHEST("chest", 54), REDSTONE_WIRE("redstone_wire", 55), DIAMOND_ORE( - "diamond_ore", 56), DIAMOND_BLOCK("diamond_block", 57), CRAFTING_TABLE("crafting_table", - 58), WHEAT_CROPS("wheat", 59), FARMLAND("farmland", 60), FURNACE("furnace", - 61), BURNING_FURNACE("lit_furnace", 62), STANDING_SIGN_BLOCK("standing_sign", - 63), OAK_DOOR_BLOCK("wooden_door", 64), LADDER("ladder", 65), RAIL("rail", - 66), COBBLESTONE_STAIRS("stone_stairs", 67), WALL_MOUNTED_SIGN_BLOCK("wall_sign", - 68), LEVER("lever", 69), STONE_PRESSURE_PLATE("stone_pressure_plate", 70), IRON_DOOR_BLOCK( - "iron_door", 71), WOODEN_PRESSURE_PLATE("wooden_pressure_plate", 72), REDSTONE_ORE( - "redstone_ore", 73), GLOWING_REDSTONE_ORE("lit_redstone_ore", 74), REDSTONE_TORCH_OFF( - "unlit_redstone_torch", 75), REDSTONE_TORCH_ON("redstone_torch", 76), STONE_BUTTON( - "stone_button", 77), SNOW("snow_layer", 78), ICE("ice", 79), SNOW_BLOCK("snow", 80), CACTUS( - "cactus", 81), CLAY("clay", 82), SUGAR_CANES("reeds", 83), JUKEBOX("jukebox", - 84), OAK_FENCE("fence", 85), PUMPKIN("pumpkin", 86), NETHERRACK("netherrack", - 87), SOUL_SAND("soul_sand", 88), GLOWSTONE("glowstone", 89), NETHER_PORTAL("portal", - 90), JACK_OLANTERN("lit_pumpkin", 91), CAKE_BLOCK("cake", 92), REDSTONE_REPEATER_BLOCK_OFF( - "unpowered_repeater", 93), REDSTONE_REPEATER_BLOCK_ON("powered_repeater", - 94), WHITE_STAINED_GLASS("stained_glass", 95), ORANGE_STAINED_GLASS("stained_glass", 95, - 1), MAGENTA_STAINED_GLASS("stained_glass", 95, 2), LIGHT_BLUE_STAINED_GLASS("stained_glass", - 95, 3), YELLOW_STAINED_GLASS("stained_glass", 95, 4), LIME_STAINED_GLASS("stained_glass", - 95, 5), PINK_STAINED_GLASS("stained_glass", 95, 6), GRAY_STAINED_GLASS("stained_glass", 95, - 7), LIGHT_GRAY_STAINED_GLASS("stained_glass", 95, 8), CYAN_STAINED_GLASS("stained_glass", - 95, 9), PURPLE_STAINED_GLASS("stained_glass", 95, 10), BLUE_STAINED_GLASS("stained_glass", - 95, 11), BROWN_STAINED_GLASS("stained_glass", 95, 12), GREEN_STAINED_GLASS("stained_glass", - 95, 13), RED_STAINED_GLASS("stained_glass", 95, 14), BLACK_STAINED_GLASS("stained_glass", - 95, 15), WOODEN_TRAPDOOR("trapdoor", 96), STONE_MONSTER_EGG("monster_egg", - 97), COBBLESTONE_MONSTER_EGG("monster_egg", 97, 1), STONE_BRICK_MONSTER_EGG("monster_egg", - 97, 2), MOSSY_STONE_BRICK_MONSTER_EGG("monster_egg", 97, - 3), CRACKED_STONE_BRICK_MONSTER_EGG("monster_egg", 97, 4), CHISELED_STONE_BRICK_MONSTER_EGG( - "monster_egg", 97, 5), STONE_BRICKS("stonebrick", 98), MOSSY_STONE_BRICKS("stonebrick", 98, - 1), CRACKED_STONE_BRICKS("stonebrick", 98, 2), CHISELED_STONE_BRICKS("stonebrick", 98, - 3), RED_MUSHROOM_CAP("stonebrick", 99), BROWN_MUSHROOM_CAP("stonebrick", 100), IRON_BARS( - "iron_bars", 101), GLASS_PANE("glass_pane", 102), MELON_BLOCK("melon_block", - 103), PUMPKIN_STEM("pumpkin_stem", 104), MELON_STEM("melon_stem", 105), VINES("vine", - 106), OAK_FENCE_GATE("fence_gate", 107), BRICK_STAIRS("brick_stairs", - 108), STONE_BRICK_STAIRS("stone_brick_stairs", 109), MYCELIUM("mycelium", 110), LILY_PAD( - "waterlily", 111), NETHER_BRICK("nether_brick", 112), NETHER_BRICK_FENCE( - "nether_brick_fence", 113), NETHER_BRICK_STAIRS("nether_brick_stairs", 114), NETHER_WART( - "nether_wart", 115), ENCHANTMENT_TABLE("enchanting_table", 116), BREWING_STAND( - "brewing_stand", 117), CAULDRON("cauldron", 118), END_PORTAL("end_portal", - 119), END_PORTAL_FRAME("end_portal_frame", 120), END_STONE("end_stone", 121), DRAGON_EGG( - "dragon_egg", 122), REDSTONE_LAMP_INACTIVE("redstone_lamp", 123), REDSTONE_LAMP_ACTIVE( - "lit_redstone_lamp", 124), DOUBLE_OAK_WOOD_SLAB("double_wooden_slab", - 125), DOUBLE_SPRUCE_WOOD_SLAB("double_wooden_slab", 125, 1), DOUBLE_BIRCH_WOOD_SLAB( - "double_wooden_slab", 125, 2), DOUBLE_JUNGLE_WOOD_SLAB("double_wooden_slab", 125, - 3), DOUBLE_ACACIA_WOOD_SLAB("double_wooden_slab", 125, 4), DOUBLE_DARK_OAK_WOOD_SLAB( - "double_wooden_slab", 125, 5), OAK_WOOD_SLAB("wooden_slab", 126), SPRUCE_WOOD_SLAB( - "wooden_slab", 126, 1), BIRCH_WOOD_SLAB("wooden_slab", 126, 2), JUNGLE_WOOD_SLAB( - "wooden_slab", 126, 3), ACACIA_WOOD_SLAB("wooden_slab", 126, 4), DARK_OAK_WOOD_SLAB( - "wooden_slab", 126, 5), COCOA("cocoa", 127), SANDSTONE_STAIRS("sandstone_stairs", - 128), EMERALD_ORE("emerald_ore", 129), ENDER_CHEST("ender_chest", 130), TRIPWIRE_HOOK( - "tripwire_hook", 131), TRIPWIRE("tripwire_hook", 132), EMERALD_BLOCK("emerald_block", - 133), SPRUCE_WOOD_STAIRS("spruce_stairs", 134), BIRCH_WOOD_STAIRS("birch_stairs", - 135), JUNGLE_WOOD_STAIRS("jungle_stairs", 136), COMMAND_BLOCK("command_block", 137), BEACON( - "beacon", 138), COBBLESTONE_WALL("cobblestone_wall", 139), MOSSY_COBBLESTONE_WALL( - "cobblestone_wall", 139, 1), FLOWER_POT("flower_pot", 140), CARROTS("carrots", - 141), POTATOES("potatoes", 142), WOODEN_BUTTON("wooden_button", 143), MOB_HEAD("skull", - 144), ANVIL("anvil", 145), TRAPPED_CHEST("trapped_chest", - 146), WEIGHTED_PRESSURE_PLATE_LIGHT("light_weighted_pressure_plate", - 147), WEIGHTED_PRESSURE_PLATE_HEAVY("heavy_weighted_pressure_plate", - 148), REDSTONE_COMPARATOR_INACTIVE("unpowered_comparator", 149), REDSTONE_COMPARATOR_ACTIVE( - "powered_comparator", 150), DAYLIGHT_SENSOR("daylight_detector", 151), REDSTONE_BLOCK( - "redstone_block", 152), NETHER_QUARTZ_ORE("quartz_ore", 153), HOPPER("hopper", - 154), QUARTZ_BLOCK("quartz_block", 155), CHISELED_QUARTZ_BLOCK("quartz_block", 155, - 1), PILLAR_QUARTZ_BLOCK("quartz_block", 155, 2), QUARTZ_STAIRS("quartz_stairs", - 156), ACTIVATOR_RAIL("activator_rail", 157), DROPPER("dropper", 158), WHITE_STAINED_CLAY( - "stained_hardened_clay", 159), ORANGE_STAINED_CLAY("stained_hardened_clay", 159, - 1), MAGENTA_STAINED_CLAY("stained_hardened_clay", 159, 2), LIGHT_BLUE_STAINED_CLAY( - "stained_hardened_clay", 159, 3), YELLOW_STAINED_CLAY("stained_hardened_clay", 159, - 4), LIME_STAINED_CLAY("stained_hardened_clay", 159, 5), PINK_STAINED_CLAY( - "stained_hardened_clay", 159, 6), GRAY_STAINED_CLAY("stained_hardened_clay", 159, - 7), LIGHT_GRAY_STAINED_CLAY("stained_hardened_clay", 159, 8), CYAN_STAINED_CLAY( - "stained_hardened_clay", 159, 9), PURPLE_STAINED_CLAY("stained_hardened_clay", 159, - 10), BLUE_STAINED_CLAY("stained_hardened_clay", 159, 11), BROWN_STAINED_CLAY( - "stained_hardened_clay", 159, 12), GREEN_STAINED_CLAY("stained_hardened_clay", 159, - 13), RED_STAINED_CLAY("stained_hardened_clay", 159, 14), BLACK_STAINED_CLAY( - "stained_hardened_clay", 159, 15), WHITE_STAINED_GLASS_PANE("stained_glass_pane", - 160), ORANGE_STAINED_GLASS_PANE("stained_glass_pane", 160, 1), MAGENTA_STAINED_GLASS_PANE( - "stained_glass_pane", 160, 2), LIGHT_BLUE_STAINED_GLASS_PANE("stained_glass_pane", 160, - 3), YELLOW_STAINED_GLASS_PANE("stained_glass_pane", 160, 4), LIME_STAINED_GLASS_PANE( - "stained_glass_pane", 160, 5), PINK_STAINED_GLASS_PANE("stained_glass_pane", 160, - 6), GRAY_STAINED_GLASS_PANE("stained_glass_pane", 160, 7), LIGHT_GRAY_STAINED_GLASS_PANE( - "stained_glass_pane", 160, 8), CYAN_STAINED_GLASS_PANE("stained_glass_pane", 160, - 9), PURPLE_STAINED_GLASS_PANE("stained_glass_pane", 160, 10), BLUE_STAINED_GLASS_PANE( - "stained_glass_pane", 160, 11), BROWN_STAINED_GLASS_PANE("stained_glass_pane", 160, - 12), GREEN_STAINED_GLASS_PANE("stained_glass_pane", 160, 13), RED_STAINED_GLASS_PANE( - "stained_glass_pane", 160, 14), BLACK_STAINED_GLASS_PANE("stained_glass_pane", 160, - 15), ACACIA_LEAVES("leaves2", 161), DARK_OAK_LEAVES("leaves2", 161, 1), ACACIA_WOOD("log2", - 162), DARK_OAK_WOOD("log2", 162, 1), ACACIA_WOOD_STAIRS("acacia_stairs", - 163), DARK_OAK_WOOD_STAIRS("dark_oak_stairs", 164), SLIME_BLOCK("slime", 165), BARRIER( - "barrier", 166), IRON_TRAPDOOR("iron_trapdoor", 167), PRISMARINE("prismarine", - 168), PRISMARINE_BRICKS("prismarine", 168, 1), DARK_PRISMARINE("prismarine", 168, - 2), SEA_LANTERN("sea_lantern", 169), HAY_BALE("hay_block", 170), WHITE_CARPET("carpet", - 171), ORANGE_CARPET("carpet", 171, 1), MAGENTA_CARPET("carpet", 171, 2), LIGHT_BLUE_CARPET( - "carpet", 171, 3), YELLOW_CARPET("carpet", 171, 4), LIME_CARPET("carpet", 171, - 5), PINK_CARPET("carpet", 171, 6), GRAY_CARPET("carpet", 171, 7), LIGHT_GRAY_CARPET( - "carpet", 171, 8), CYAN_CARPET("carpet", 171, 9), PURPLE_CARPET("carpet", 171, - 10), BLUE_CARPET("carpet", 171, 11), BROWN_CARPET("carpet", 171, 12), GREEN_CARPET("carpet", - 171, 13), RED_CARPET("carpet", 171, 14), BLACK_CARPET("carpet", 171, 15), HARDENED_CLAY( - "hardened_clay", 172), BLOCK_OF_COAL("coal_block", 173), PACKED_ICE("packed_ice", - 174), SUNFLOWER("double_plant", 175), LILAC("double_plant", 175, 1), DOUBLE_TALLGRASS( - "double_plant", 175, 2), LARGE_FERN("double_plant", 175, 3), ROSE_BUSH("double_plant", 175, - 4), PEONY("double_plant", 175, 5), FREE_STANDING_BANNER("standing_banner", - 176), WALL_MOUNTED_BANNER("wall_banner", 177), INVERTED_DAYLIGHT_SENSOR( - "daylight_detector_inverted", 178), RED_SANDSTONE("red_sandstone", - 179), SMOOTH_RED_SANDSTONE("red_sandstone", 179, 1), CHISELED_RED_SANDSTONE("red_sandstone", - 179, 2), RED_SANDSTONE_STAIRS("red_sandstone_stairs", 180), DOUBLE_RED_SANDSTONE_SLAB( - "stone_slab2", 181), RED_SANDSTONE_SLAB("double_stone_slab2", 182), SPRUCE_FENCE_GATE( - "spruce_fence_gate", 183), BIRCH_FENCE_GATE("birch_fence_gate", 184), JUNGLE_FENCE_GATE( - "jungle_fence_gate", 185), DARK_OAK_FENCE_GATE("dark_oak_fence_gate", - 186), ACACIA_FENCE_GATE("acacia_fence_gate", 187), SPRUCE_FENCE("spruce_fence", - 188), BIRCH_FENCE("birch_fence", 189), JUNGLE_FENCE("jungle_fence", 190), DARK_OAK_FENCE( - "dark_oak_fence", 191), ACACIA_FENCE("acacia_fence", 192), SPRUCE_DOOR_BLOCK("spruce_door", - 193), BIRCH_DOOR_BLOCK("birch_door", 194), JUNGLE_DOOR_BLOCK("jungle_door", - 195), ACACIA_DOOR_BLOCK("acacia_door", 196), DARK_OAK_DOOR_BLOCK("dark_oak_door", - 197), IRON_SHOVEL("iron_shovel", 256), IRON_PICKAXE("iron_pickaxe", 257), IRON_AXE( - "iron_axe", 258), FLINT_AND_STEEL("flint_and_steel", 259), APPLE("apple", 260), BOW("bow", - 261), ARROW("arrow", 262), COAL("coal", 263), CHARCOAL("coal", 263, 1), DIAMOND("diamond", - 264), IRON_INGOT("iron_ingot", 265), GOLD_INGOT("gold_ingot", 266), IRON_SWORD("iron_sword", - 267), WOODEN_SWORD("wooden_sword", 268), WOODEN_SHOVEL("wooden_shovel", - 269), WOODEN_PICKAXE("wooden_pickaxe", 270), WOODEN_AXE("wooden_axe", 271), STONE_SWORD( - "stone_sword", 272), STONE_SHOVEL("stone_shovel", 273), STONE_PICKAXE("stone_pickaxe", - 274), STONE_AXE("stone_axe", 275), DIAMOND_SWORD("diamond_sword", 276), DIAMOND_SHOVEL( - "diamond_shovel", 277), DIAMOND_PICKAXE("diamond_pickaxe", 278), DIAMOND_AXE("diamond_axe", - 279), STICK("stick", 280), BOWL("bowl", 281), MUSHROOM_STEW("mushroom_stew", - 282), GOLDEN_SWORD("golden_sword", 283), GOLDEN_SHOVEL("golden_shovel", - 284), GOLDEN_PICKAXE("golden_pickaxe", 285), GOLDEN_AXE("golden_axe", 286), STRING("string", - 287), FEATHER("feather", 288), GUNPOWDER("gunpowder", 289), WOODEN_HOE("wooden_hoe", - 290), STONE_HOE("stone_hoe", 291), IRON_HOE("iron_hoe", 292), DIAMOND_HOE("diamond_hoe", - 293), GOLDEN_HOE("golden_hoe", 294), WHEAT_SEEDS("wheat_seeds", 295), WHEAT("wheat", - 296), BREAD("bread", 297), LEATHER_HELMET("leather_helmet", 298), LEATHER_TUNIC( - "leather_chestplate", 299), LEATHER_PANTS("leather_leggings", 300), LEATHER_BOOTS( - "leather_boots", 301), CHAINMAIL_HELMET("chainmail_helmet", 302), CHAINMAIL_CHESTPLATE( - "chainmail_chestplate", 303), CHAINMAIL_LEGGINGS("chainmail_leggings", - 304), CHAINMAIL_BOOTS("chainmail_boots", 305), IRON_HELMET("iron_helmet", - 306), IRON_CHESTPLATE("iron_chestplate", 307), IRON_LEGGINGS("iron_leggings", - 308), IRON_BOOTS("iron_boots", 309), DIAMOND_HELMET("diamond_helmet", - 310), DIAMOND_CHESTPLATE("diamond_chestplate", 311), DIAMOND_LEGGINGS("diamond_leggings", - 312), DIAMOND_BOOTS("diamond_boots", 313), GOLDEN_HELMET("golden_helmet", - 314), GOLDEN_CHESTPLATE("golden_chestplate", 315), GOLDEN_LEGGINGS("golden_leggings", - 316), GOLDEN_BOOTS("golden_boots", 317), FLINT("flint_and_steel", 318), RAW_PORKCHOP( - "porkchop", 319), COOKED_PORKCHOP("cooked_porkchop", 320), PAINTING("painting", - 321), GOLDEN_APPLE("golden_apple", 322), ENCHANTED_GOLDEN_APPLE("golden_apple", 322, - 1), SIGN("sign", 323), OAK_DOOR("wooden_door", 324), BUCKET("bucket", 325), WATER_BUCKET( - "water_bucket", 326), LAVA_BUCKET("lava_bucket", 327), MINECART("minecart", 328), SADDLE( - "saddle", 329), IRON_DOOR("iron_door", 330), REDSTONE("redstone", 331), SNOWBALL("snowball", - 332), BOAT("boat", 333), LEATHER("leather", 334), MILK_BUCKET("milk_bucket", 335), BRICK( - "brick", 336), CLAY1("clay_ball", 337), SUGAR_CANES1("reeds", 338), PAPER("paper", - 339), BOOK("book", 340), SLIMEBALL("slime_ball", 341), MINECART_WITH_CHEST("chest_minecart", - 342), MINECART_WITH_FURNACE("furnace_minecart", 343), EGG("egg", 344), COMPASS("compass", - 345), FISHING_ROD("fishing_rod", 346), CLOCK("clock", 347), GLOWSTONE_DUST("glowstone_dust", - 348), RAW_FISH("fish", 349), RAW_SALMON("fish", 349, 1), CLOWNFISH("fish", 349, - 2), PUFFERFISH("fish", 349, 3), COOKED_FISH("cooked_fish", 350), COOKED_SALMON( - "cooked_fish", 350, 1), INK_SACK("dye", 351), ROSE_RED("dye", 351, 1), CACTUS_GREEN("dye", - 351, 2), COCO_BEANS("dye", 351, 3), LAPIS_LAZULI("dye", 351, 4), PURPLE_DYE("dye", 351, - 5), CYAN_DYE("dye", 351, 6), LIGHT_GRAY_DYE("dye", 351, 7), GRAY_DYE("dye", 351, - 8), PINK_DYE("dye", 351, 9), LIME_DYE("dye", 351, 10), DANDELION_YELLOW("dye", 351, - 11), LIGHT_BLUE_DYE("dye", 351, 12), MAGENTA_DYE("dye", 351, 13), ORANGE_DYE("dye", 351, - 14), BONE_MEAL("dye", 351, 15), BONE("bone", 352), SUGAR("sugar", 353), CAKE("cake", - 354), BED1("bed", 355), REDSTONE_REPEATER("repeater", 356), COOKIE("cookie", 357), MAP( - "filled_map", 358), SHEARS("shears", 359), MELON("melon", 360), PUMPKIN_SEEDS( - "pumpkin_seeds", 361), MELON_SEEDS("melon_seeds", 362), RAW_BEEF("beef", 363), STEAK( - "cooked_beef", 364), RAW_CHICKEN("chicken", 365), COOKED_CHICKEN("cooked_chicken", - 366), ROTTEN_FLESH("rotten_flesh", 367), ENDER_PEARL("ender_pearl", 368), BLAZE_ROD( - "blaze_rod", 369), GHAST_TEAR("ghast_tear", 370), GOLD_NUGGET("gold_nugget", - 371), NETHER_WART1("nether_wart", 372), POTION("potion", 373), GLASS_BOTTLE("glass_bottle", - 374), SPIDER_EYE("spider_eye", 375), FERMENTED_SPIDER_EYE("fermented_spider_eye", - 376), BLAZE_POWDER("blaze_powder", 377), MAGMA_CREAM("magma_cream", 378), BREWING_STAND1( - "brewing_stand", 379), CAULDRON1("cauldron", 380), EYE_OF_ENDER("ender_eye", - 381), GLISTERING_MELON("speckled_melon", 382), SPAWN_CREEPER("spawn_egg", 383, - 50), SPAWN_SKELETON("spawn_egg", 383, 51), SPAWN_SPIDER("spawn_egg", 383, 52), SPAWN_ZOMBIE( - "spawn_egg", 383, 54), SPAWN_SLIME("spawn_egg", 383, 55), SPAWN_GHAST("spawn_egg", 383, - 56), SPAWN_PIGMAN("spawn_egg", 383, 57), SPAWN_ENDERMAN("spawn_egg", 383, - 58), SPAWN_CAVE_SPIDER("spawn_egg", 383, 59), SPAWN_SILVERFISH("spawn_egg", 383, - 60), SPAWN_BLAZE("spawn_egg", 383, 61), SPAWN_MAGMA_CUBE("spawn_egg", 383, 62), SPAWN_BAT( - "spawn_egg", 383, 65), SPAWN_WITCH("spawn_egg", 383, 66), SPAWN_ENDERMITE("spawn_egg", 383, - 67), SPAWN_GUARDIAN("spawn_egg", 383, 68), SPAWN_PIG("spawn_egg", 383, 90), SPAWN_SHEEP( - "spawn_egg", 383, 91), SPAWN_COW("spawn_egg", 383, 92), SPAWN_CHICKEN("spawn_egg", 383, - 93), SPAWN_SQUID("spawn_egg", 383, 94), SPAWN_WOLF("spawn_egg", 383, 95), SPAWN_MOOSHROOM( - "spawn_egg", 383, 96), SPAWN_OCELOT("spawn_egg", 383, 98), SPAWN_HORSE("spawn_egg", 383, - 100), SPAWN_RABBIT("spawn_egg", 383, 101), SPAWN_VILLAGER("spawn_egg", 383, - 120), BOTTLE_O_ENCHANTING("experience_bottle", 384), FIRE_CHARGE("fire_charge", - 385), BOOK_AND_QUILL("writable_book", 386), WRITTEN_BOOK("written_book", 387), EMERALD( - "emerald", 388), ITEM_FRAME("item_frame", 389), FLOWER_POT1("flower_pot", 390), CARROT( - "carrot", 391), POTATO("potato", 392), BAKED_POTATO("baked_potato", 393), POISONOUS_POTATO( - "poisonous_potato", 394), EMPTY_MAP("map", 395), GOLDEN_CARROT("golden_carrot", - 396), MOB_HEAD_SKELETON("skull", 397), MOB_HEAD_WITHER_SKELETON("skull", 397, - 1), MOB_HEAD_ZOMBIE("skull", 397, 2), MOB_HEAD_HUMAN("skull", 397, 3), MOB_HEAD_CREEPER( - "skull", 397, 4), CARROT_ON_A_STICK("carrot_on_a_stick", 398), NETHER_STAR("nether_star", - 399), PUMPKIN_PIE("pumpkin_pie", 400), FIREWORK_ROCKET("fireworks", 401), FIREWORK_STAR( - "firework_charge", 402), ENCHANTED_BOOK("enchanted_book", 403), REDSTONE_COMPARATOR( - "comparator", 404), NETHER_BRICK1("netherbrick", 405), NETHER_QUARTZ("quartz", - 406), MINECART_WITH_TNT("tnt_minecart", 407), MINECART_WITH_HOPPER("hopper_minecart", - 408), PRISMARINE_SHARD("prismarine_shard", 409), PRISMARINE_CRYSTALS("prismarine_crystals", - 410), RAW_RABBIT("rabbit", 411), COOKED_RABBIT("cooked_rabbit", 412), RABBIT_STEW( - "rabbit_stew", 413), RABBITS_FOOT("rabbit_foot", 414), RABBIT_HIDE("rabbit_hide", - 415), ARMOR_STAND("armor_stand", 416), IRON_HORSE_ARMOR("iron_horse_armor", - 417), GOLDEN_HORSE_ARMOR("golden_horse_armor", 418), DIAMOND_HORSE_ARMOR( - "diamond_horse_armor", 419), LEAD("lead", 420), NAME_TAG("name_tag", - 421), MINECART_WITH_COMMAND_BLOCK("command_block_minecart", 422), RAW_MUTTON("mutton", - 423), COOKED_MUTTON("cooked_mutton", 424), BANNER("banner", 425), SPRUCE_DOOR("spruce_door", - 427), BIRCH_DOOR("birch_door", 428), JUNGLE_DOOR("jungle_door", 429), ACACIA_DOOR( - "acacia_door", 430), DARK_OAK_DOOR("dark_oak_door", 431), DISC_13("record_13", - 2256), CAT_DISC("record_cat", 2257), BLOCKS_DISC("record_blocks", 2258), CHIRP_DISC( - "record_chirp", 2259), FAR_DISC("record_far", 2260), MALL_DISC("record_mall", - 2261), MELLOHI_DISC("record_mellohi", 2262), STAL_DISC("record_stal", 2263), STRAD_DISC( - "record_strad", 2264), WARD_DISC("record_ward", 2265), DISC_11("record_11", - 2266), WAIT_DISC("record_wait", 2267), END_ROD("end_rod", 198), CHORUS_PLANT("chorus_plant", - 199), CHORUS_FLOWER("chorus_flower", 200), PURPUR_BLOCK("purpur_block", 201), PURPUR_PILLAR( - "purpur_pillar", 202), PURPUR_STAIRS("purpur_stairs", 203), PURPUR_DOUBLE_SLAB( - "purpur_double_slab", 204), PURPUR_SLAB("purpur_slab", 205), END_BRICKS("end_bricks", - 206), BEETROOTS("beetroots", 207), GRASS_PATH("grass_path", 208), END_GATEWAY("end_gateway", - 209), REPEATING_COMMAND_BLOCK("repeating_command_block", 210), CHAIN_COMMAND_BLOCK( - "chain_command_block", 211), FROSTED_ICE("frosted_ice", 212), STRUCTURE_BLOCK( - "structure_block", 255); - - private static final Map ids = new HashMap<>(); - private static final Map datas = new HashMap<>(); - - static { - for (ItemType type : EnumSet.allOf(ItemType.class)) { - ids.put(type.name, type.id); - datas.put(type.name, type.data); - } - } - - private final int id; - private final byte data; - private final String name; - - ItemType(String name, int id) { - this.id = id; - this.data = 0; - this.name = name; - } - - ItemType(String name, int id, int data) { - this.id = id; - this.data = (byte) data; - this.name = name; - } - - public static int getId(String name) { - Integer value = ids.get(name); - if (value == null) { - return 0; - } - return value; - } - - public static byte getData(String name) { - Byte value = datas.get(name); - if (value == null) { - return 0; - } - return value; - } -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/PlotItem.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/PlotItem.java index 2b7e31295..16397d0da 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/PlotItem.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/PlotItem.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.object.schematic; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.sk89q.worldedit.world.item.ItemType; public class PlotItem { @@ -9,10 +9,10 @@ public class PlotItem { public final int z; // public final short[] id; // public final byte[] data; - public final PlotBlock[] types; + public final ItemType[] types; public final byte[] amount; - public PlotItem(short x, short y, short z, PlotBlock[] types, byte[] amount) { + public PlotItem(short x, short y, short z, ItemType[] types, byte[] amount) { this.x = x; this.y = y; this.z = z; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java index e2c222df5..cdd1f25f1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.object.schematic; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; @@ -17,10 +17,10 @@ import java.util.Map; public class Schematic { // Lossy but fast - @Getter private final BlockArrayClipboard clipboard; + @Getter private final Clipboard clipboard; @Getter private Map flags = new HashMap<>(); - public Schematic(BlockArrayClipboard clip) { + public Schematic(Clipboard clip) { this.clipboard = clip; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java index 31a86b874..0191b53df 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java @@ -2,11 +2,17 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; public class DefaultPlotAreaManager implements PlotAreaManager { @@ -93,7 +99,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { QuadMap map = this.plotAreaGrid.get(plotArea.worldname); if (map == null) { map = new QuadMap(Integer.MAX_VALUE, 0, 0) { - @Override public RegionWrapper getRegion(PlotArea value) { + @Override public CuboidRegion getRegion(PlotArea value) { return value.getRegion(); } }; @@ -195,7 +201,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { } } - @Override public PlotArea[] getPlotAreas(String world, RegionWrapper region) { + @Override public PlotArea[] getPlotAreas(String world, CuboidRegion region) { if (region == null) { PlotArea[] areas = this.plotAreaMap.get(world); if (areas == null) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java index 7a59dab9d..b34ad2787 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java @@ -2,7 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; public interface PlotAreaManager { PlotArea getApplicablePlotArea(Location location); @@ -11,7 +11,7 @@ public interface PlotAreaManager { PlotArea getPlotArea(String world, String id); - PlotArea[] getPlotAreas(String world, RegionWrapper region); + PlotArea[] getPlotAreas(String world, CuboidRegion region); PlotArea[] getAllPlotAreas(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java index 8c80e46a7..788e7a99a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java @@ -2,18 +2,27 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockLoc; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class SinglePlot extends Plot { - private HashSet regions = Sets.newHashSet( - new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, - Integer.MAX_VALUE)); + private Set regions = Collections.singleton( + new CuboidRegion(BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), + BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE))); public SinglePlot(PlotArea area, PlotId id, UUID owner) { super(area, id, owner); @@ -35,7 +44,7 @@ public class SinglePlot extends Plot { } @Override public String getWorldName() { - return getId().toCommaSeparatedString(); + return getId().getX() + "." + getId().getY(); } @Override public SinglePlotArea getArea() { @@ -60,7 +69,7 @@ public class SinglePlot extends Plot { return super.isLoaded(); } - @NotNull @Override public HashSet getRegions() { + @NotNull @Override public Set getRegions() { return regions; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index 8f8ac96b1..f04d340eb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -5,7 +5,14 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.generator.GridPlotWorld; -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.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotLoc; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; +import com.github.intellectualsites.plotsquared.plot.object.PlotSettings; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.SetupObject; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; @@ -40,7 +47,7 @@ public class SinglePlotArea extends GridPlotWorld { } public void loadWorld(final PlotId id) { - String worldName = id.toCommaSeparatedString(); + String worldName = id.getX() + "." + id.getY(); if (WorldUtil.IMP.isWorld(worldName)) { return; } @@ -52,12 +59,19 @@ public class SinglePlotArea extends GridPlotWorld { setup.step = new ConfigurationNode[0]; setup.world = worldName; + File container = PlotSquared.imp().getWorldContainer(); + File destination = new File(container, worldName); + + {// convert old + File oldFile = new File(container, id.toCommaSeparatedString()); + if (oldFile.exists()) { + oldFile.renameTo(destination); + } + } // Duplicate 0;0 if (setup.type != 0) { - File container = PlotSquared.imp().getWorldContainer(); - File destination = new File(container, worldName); if (!destination.exists()) { - File src = new File(container, "0,0"); + File src = new File(container, "0.0"); if (src.exists()) { if (!destination.exists()) { destination.mkdirs(); @@ -86,7 +100,7 @@ public class SinglePlotArea extends GridPlotWorld { TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { - String worldName = id.toCommaSeparatedString(); + String worldName = id.getX() + "." + id.getY(); if (WorldUtil.IMP.isWorld(worldName)) { return; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java index f2e0b3c03..d35257b9b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java @@ -2,7 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.ArrayUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; @@ -44,7 +44,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { } case 1: if ((c <= '/') || (c >= ':')) { - if (c == ';' || c == ',') { + if (c == '.') { mode = 2; continue; } @@ -90,7 +90,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { return isWorld(location.getWorld()) || location.getWorld().equals("*") ? area : null; } - @Override public PlotArea[] getPlotAreas(String world, RegionWrapper region) { + @Override public PlotArea[] getPlotAreas(String world, CuboidRegion region) { PlotArea[] found = super.getPlotAreas(world, region); if (found != null && found.length != 0) { return found; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java index 0c5a7e866..49d3788d5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java @@ -1,7 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java index 9ba3df278..0042ca222 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java @@ -2,7 +2,11 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; public class SingleWorldGenerator extends IndependentPlotGenerator { @@ -31,7 +35,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { blockBuckets[layer] = new BlockBucket[4096]; } blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(PlotBlock.get("bedrock")); + BlockBucket.withSingle(BlockUtil.get("bedrock")); } } } @@ -43,7 +47,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { blockBuckets[layer] = new BlockBucket[4096]; } blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(PlotBlock.get("dirt")); + BlockBucket.withSingle(BlockUtil.get("dirt")); } } } @@ -55,7 +59,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { blockBuckets[layer] = new BlockBucket[4096]; } blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(PlotBlock.get("grass_block")); + BlockBucket.withSingle(BlockUtil.get("grass_block")); } } } @@ -67,12 +71,12 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { if (area.VOID) { Location min = result.getMin(); if (min.getX() == 0 && min.getZ() == 0) { - result.setBlock(0, 0, 0, PlotBlock.get("bedrock")); + result.setBlock(0, 0, 0, BlockUtil.get("bedrock")); } } else { - result.setCuboid(bedrock1, bedrock2, PlotBlock.get("bedrock")); - result.setCuboid(dirt1, dirt2, PlotBlock.get("dirt")); - result.setCuboid(grass1, grass2, PlotBlock.get("grass_block")); + result.setCuboid(bedrock1, bedrock2, BlockUtil.get("bedrock")); + result.setCuboid(dirt1, dirt2, BlockUtil.get("dirt")); + result.setCuboid(grass1, grass2, BlockUtil.get("grass_block")); } result.fillBiome("PLAINS"); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java index 55a99c9b9..be8a79207 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java @@ -1,14 +1,14 @@ package com.github.intellectualsites.plotsquared.plot.util; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.sk89q.worldedit.math.BlockVector2; import java.io.File; import java.util.ArrayList; @@ -21,31 +21,31 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class ChunkManager { - private static final Map> forceChunks = + private static final Map> forceChunks = new ConcurrentHashMap<>(); - private static final Map> addChunks = + private static final Map> addChunks = new ConcurrentHashMap<>(); public static ChunkManager manager = null; - public static ChunkLoc getChunkChunk(Location location) { + public static BlockVector2 getRegion(Location location) { int x = location.getX() >> 9; int z = location.getZ() >> 9; - return new ChunkLoc(x, z); + return BlockVector2.at(x, z); } public static void setChunkInPlotArea(RunnableVal force, - RunnableVal add, String world, ChunkLoc loc) { + RunnableVal add, String world, BlockVector2 loc) { LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); if (PlotSquared.get().isAugmented(world)) { - int blockX = loc.x << 4; - int blockZ = loc.z << 4; + int blockX = loc.getX() << 4; + int blockZ = loc.getZ() << 4; ScopedLocalBlockQueue scoped = new ScopedLocalBlockQueue(queue, new Location(world, blockX, 0, blockZ), new Location(world, blockX + 15, 255, blockZ + 15)); if (force != null) { force.run(scoped); } else { - scoped.regenChunk(loc.x, loc.z); + scoped.regenChunk(loc.getX(), loc.getZ()); if (add != null) { add.run(scoped); } @@ -54,13 +54,13 @@ public abstract class ChunkManager { } else { forceChunks.put(loc, force); addChunks.put(loc, add); - queue.regenChunk(loc.x, loc.z); + queue.regenChunk(loc.getX(), loc.getZ()); forceChunks.remove(loc); addChunks.remove(loc); } } - public static boolean preProcessChunk(ChunkLoc loc, ScopedLocalBlockQueue queue) { + public static boolean preProcessChunk(BlockVector2 loc, ScopedLocalBlockQueue queue) { final RunnableVal forceChunk = forceChunks.get(loc); if (forceChunk != null) { forceChunk.run(queue); @@ -70,7 +70,7 @@ public abstract class ChunkManager { return false; } - public static boolean postProcessChunk(ChunkLoc loc, ScopedLocalBlockQueue queue) { + public static boolean postProcessChunk(BlockVector2 loc, ScopedLocalBlockQueue queue) { final RunnableVal addChunk = forceChunks.get(loc); if (addChunk != null) { addChunk.run(queue); @@ -80,36 +80,36 @@ public abstract class ChunkManager { return false; } - public static void largeRegionTask(final String world, final RegionWrapper region, - final RunnableVal task, final Runnable whenDone) { + public static void largeRegionTask(final String world, final CuboidRegion region, + final RunnableVal task, final Runnable whenDone) { TaskManager.runTaskAsync(() -> { - HashSet chunks = new HashSet<>(); - Set mcrs = manager.getChunkChunks(world); - for (ChunkLoc mcr : mcrs) { - int bx = mcr.x << 9; - int bz = mcr.z << 9; + HashSet chunks = new HashSet<>(); + Set mcrs = manager.getChunkChunks(world); + for (BlockVector2 mcr : mcrs) { + int bx = mcr.getX() << 9; + int bz = mcr.getZ() << 9; int tx = bx + 511; int tz = bz + 511; - if (bx <= region.maxX && tx >= region.minX && bz <= region.maxZ - && tz >= region.minZ) { + if (bx <= region.getMaximumPoint().getX() && tx >= region.getMinimumPoint().getX() && bz <= region.getMaximumPoint().getZ() + && tz >= region.getMinimumPoint().getZ()) { for (int x = bx >> 4; x <= (tx >> 4); x++) { int cbx = x << 4; int ctx = cbx + 15; - if (cbx <= region.maxX && ctx >= region.minX) { + if (cbx <= region.getMaximumPoint().getX() && ctx >= region.getMinimumPoint().getX()) { for (int z = bz >> 4; z <= (tz >> 4); z++) { int cbz = z << 4; int ctz = cbz + 15; - if (cbz <= region.maxZ && ctz >= region.minZ) { - chunks.add(new ChunkLoc(x, z)); + if (cbz <= region.getMaximumPoint().getZ() && ctz >= region.getMinimumPoint().getZ()) { + chunks.add(BlockVector2.at(x, z)); } } } } } } - TaskManager.objectTask(chunks, new RunnableVal() { + TaskManager.objectTask(chunks, new RunnableVal() { - @Override public void run(ChunkLoc value) { + @Override public void run(BlockVector2 value) { manager.loadChunk(world, value, false).thenRun(()-> task.run(value)); } }, whenDone); @@ -118,16 +118,16 @@ public abstract class ChunkManager { public static void chunkTask(final Plot plot, final RunnableVal task, final Runnable whenDone, final int allocate) { - final ArrayList regions = new ArrayList<>(plot.getRegions()); + final ArrayList regions = new ArrayList<>(plot.getRegions()); Runnable smallTask = new Runnable() { @Override public void run() { if (regions.isEmpty()) { TaskManager.runTask(whenDone); return; } - RegionWrapper value = regions.remove(0); - Location pos1 = new Location(plot.getWorldName(), value.minX, 0, value.minZ); - Location pos2 = new Location(plot.getWorldName(), value.maxX, 0, value.maxZ); + CuboidRegion value = regions.remove(0); + Location pos1 = new Location(plot.getWorldName(), value.getMinimumPoint().getX(), 0, value.getMinimumPoint().getZ()); + Location pos2 = new Location(plot.getWorldName(), value.getMaximumPoint().getX(), 0, value.getMaximumPoint().getZ()); chunkTask(pos1, pos2, task, this, allocate); } }; @@ -152,21 +152,21 @@ public abstract class ChunkManager { final int bcz = p1z >> 4; final int tcx = p2x >> 4; final int tcz = p2z >> 4; - final ArrayList chunks = new ArrayList<>(); + final ArrayList chunks = new ArrayList<>(); for (int x = bcx; x <= tcx; x++) { for (int z = bcz; z <= tcz; z++) { - chunks.add(new ChunkLoc(x, z)); + chunks.add(BlockVector2.at(x, z)); } } TaskManager.runTask(new Runnable() { @Override public void run() { long start = System.currentTimeMillis(); while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < allocate)) { - ChunkLoc chunk = chunks.remove(0); + BlockVector2 chunk = chunks.remove(0); task.value = new int[7]; - task.value[0] = chunk.x; - task.value[1] = chunk.z; + task.value[0] = chunk.getX(); + task.value[1] = chunk.getZ(); task.value[2] = task.value[0] << 4; task.value[3] = task.value[1] << 4; task.value[4] = task.value[2] + 15; @@ -211,11 +211,11 @@ public abstract class ChunkManager { */ public abstract int[] countEntities(Plot plot); - public abstract CompletableFuture loadChunk(String world, ChunkLoc loc, boolean force); + public abstract CompletableFuture loadChunk(String world, BlockVector2 loc, boolean force); - public abstract void unloadChunk(String world, ChunkLoc loc, boolean save); + public abstract void unloadChunk(String world, BlockVector2 loc, boolean save); - public Set getChunkChunks(String world) { + public Set getChunkChunks(String world) { File folder = new File(PlotSquared.get().IMP.getWorldContainer(), world + File.separator + "region"); File[] regionFiles = folder.listFiles(); @@ -223,7 +223,7 @@ public abstract class ChunkManager { throw new RuntimeException( "Could not find worlds folder: " + folder + " ? (no read access?)"); } - HashSet chunks = new HashSet<>(); + HashSet chunks = new HashSet<>(); for (File file : regionFiles) { String name = file.getName(); if (name.endsWith("mca")) { @@ -231,7 +231,7 @@ public abstract class ChunkManager { try { int x = Integer.parseInt(split[1]); int z = Integer.parseInt(split[2]); - ChunkLoc loc = new ChunkLoc(x, z); + BlockVector2 loc = BlockVector2.at(x, z); chunks.add(loc); } catch (NumberFormatException ignored) { } @@ -240,16 +240,16 @@ public abstract class ChunkManager { return chunks; } - public void deleteRegionFiles(String world, Collection chunks) { + public void deleteRegionFiles(String world, Collection chunks) { deleteRegionFiles(world, chunks, null); } - public void deleteRegionFiles(final String world, final Collection chunks, + public void deleteRegionFiles(final String world, final Collection chunks, final Runnable whenDone) { TaskManager.runTaskAsync(() -> { - for (ChunkLoc loc : chunks) { + for (BlockVector2 loc : chunks) { String directory = - world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + world + File.separator + "region" + File.separator + "r." + loc.getX() + "." + loc.getZ() + ".mca"; File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory); PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); @@ -261,9 +261,9 @@ public abstract class ChunkManager { }); } - public Plot hasPlot(String world, ChunkLoc chunk) { - int x1 = chunk.x << 4; - int z1 = chunk.z << 4; + public Plot hasPlot(String world, BlockVector2 chunk) { + int x1 = chunk.getX() << 4; + int z1 = chunk.getZ() << 4; int x2 = x1 + 15; int z2 = z1 + 15; Location bot = new Location(world, x1, 0, z1); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index fcb376355..dc8830769 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -6,15 +6,24 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; -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.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Rating; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; - +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.Nullable; -import java.util.HashSet; + import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.UUID; +import java.util.function.Supplier; public abstract class EventUtil { @@ -94,7 +103,7 @@ public abstract class EventUtil { } public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type, - Location location, LazyBlock block, boolean notifyPerms) { + Location location, Supplier block, boolean notifyPerms) { PlotArea area = location.getPlotArea(); assert area != null; Plot plot = area.getPlot(location); @@ -120,19 +129,19 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - Optional> use = plot.getFlag(Flags.USE); + Optional> use = plot.getFlag(Flags.USE); if (use.isPresent()) { - HashSet value = use.get(); - if (PlotBlock.containsEverything(value) || value - .contains(block.getPlotBlock())) { + Set value = use.get(); + if (value.contains(BlockTypes.AIR) || value + .contains(block.get())) { return true; } } - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); if (destroy.isPresent()) { - HashSet value = destroy.get(); - if (PlotBlock.containsEverything(value) || value - .contains(block.getPlotBlock())) { + Set value = destroy.get(); + if (value.contains(BlockTypes.AIR) || value + .contains(block.get())) { return true; } } @@ -214,10 +223,10 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - Optional> flagValue = plot.getFlag(Flags.USE); - HashSet value = flagValue.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { return Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) || !(!notifyPerms || MainUtil @@ -237,10 +246,10 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_BUILD_UNOWNED.getTranslated(), notifyPerms); } - Optional> flagValue = plot.getFlag(Flags.PLACE); - HashSet value = flagValue.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.PLACE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_BUILD_OTHER.getTranslated(), false)) { return true; @@ -264,10 +273,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.USE); - HashSet value = flagValue.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -291,10 +300,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.USE); - HashSet value = flagValue.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -320,10 +329,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.USE); - HashSet value = flag.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.USE); + Set value = flag.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -350,10 +359,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.USE); - HashSet value = flag.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.USE); + Set value = flag.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -380,10 +389,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.PLACE); - HashSet value = flagValue.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flagValue = plot.getFlag(Flags.PLACE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -410,10 +419,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.PLACE); - HashSet value = flag.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.PLACE); + Set value = flag.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -441,10 +450,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.PLACE); - HashSet value = flag.orElse(null); - if (value == null || !PlotBlock.containsEverything(value) && !value - .contains(block.getPlotBlock())) { + Optional> flag = plot.getFlag(Flags.PLACE); + Set value = flag.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(block.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/IncendoPaster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/IncendoPaster.java index 1fec0e567..b5ebe5d17 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/IncendoPaster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/IncendoPaster.java @@ -9,7 +9,12 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Locale; /** * Single class paster for the Incendo paste service diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java index dfbc0b3eb..93faabe87 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java @@ -4,7 +4,7 @@ import com.github.intellectualsites.plotsquared.configuration.ConfigurationSecti import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.sk89q.worldedit.world.block.BlockState; import lombok.NonNull; import java.util.Collection; @@ -36,7 +36,7 @@ import java.util.Map; } private BlockBucket blockToBucket(@NonNull final String block) { - final PlotBlock plotBlock = WorldUtil.IMP.getClosestBlock(block).best; + final BlockState plotBlock = WorldUtil.IMP.getClosestBlock(block).best; return BlockBucket.withSingle(plotBlock); } @@ -48,9 +48,9 @@ import java.util.Map; section.set(string, blocks.toString()); } - private BlockBucket blockListToBucket(@NonNull final PlotBlock[] blocks) { - final Map counts = new HashMap<>(); - for (final PlotBlock block : blocks) { + private BlockBucket blockListToBucket(@NonNull final BlockState[] blocks) { + final Map counts = new HashMap<>(); + for (final BlockState block : blocks) { counts.putIfAbsent(block, 0); counts.put(block, counts.get(block) + 1); } @@ -63,7 +63,7 @@ import java.util.Map; } final BlockBucket bucket = new BlockBucket(); if (includeRatios) { - for (final Map.Entry count : counts.entrySet()) { + for (final Map.Entry count : counts.entrySet()) { bucket.addBlock(count.getKey(), count.getValue()); } } else { @@ -72,9 +72,9 @@ import java.util.Map; return bucket; } - private PlotBlock[] splitBlockList(@NonNull final List list) { + private BlockState[] splitBlockList(@NonNull final List list) { return list.stream().map(s -> WorldUtil.IMP.getClosestBlock(s).best) - .toArray(PlotBlock[]::new); + .toArray(BlockState[]::new); } private void convertBlock(@NonNull final ConfigurationSection section, @@ -86,14 +86,14 @@ import java.util.Map; private void convertBlockList(@NonNull final ConfigurationSection section, @NonNull final String key, @NonNull final List blockList) { - final PlotBlock[] blocks = this.splitBlockList(blockList); + final BlockState[] blocks = this.splitBlockList(blockList); final BlockBucket bucket = this.blockListToBucket(blocks); this.setString(section, key, bucket); PlotSquared.log( Captions.LEGACY_CONFIG_REPLACED.f(plotBlockArrayString(blocks), bucket.toString())); } - private String plotBlockArrayString(@NonNull final PlotBlock[] blocks) { + private String plotBlockArrayString(@NonNull final BlockState[] blocks) { final StringBuilder builder = new StringBuilder(); for (int i = 0; i < blocks.length; i++) { builder.append(blocks[i].toString()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyMappings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyMappings.java deleted file mode 100644 index d79ad6653..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyMappings.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.util; - -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; - -public abstract class LegacyMappings { - - public abstract PlotBlock fromAny(final String string); - - public abstract PlotBlock fromLegacyToString(final int id, final int data); - - public abstract PlotBlock fromLegacyToString(final String id); - - public abstract PlotBlock fromStringToLegacy(final String id); - -} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index 1f42d6772..d06beab3f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -10,12 +10,27 @@ import com.github.intellectualsites.plotsquared.plot.flag.DoubleFlag; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.stream.AbstractDelegateOutputStream; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import org.jetbrains.annotations.NotNull; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Reader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; @@ -23,8 +38,17 @@ import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.text.DecimalFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -350,6 +374,14 @@ public class MainUtil { return plot.getFlag(Flags.SERVER_PLOT).orElse(false); } + @NotNull public static Location[] getCorners(String world, CuboidRegion region) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + Location pos1 = new Location(world, min.getX(), min.getY(), min.getZ()); + Location pos2 = new Location(world, max.getX(), max.getY(), max.getZ()); + return new Location[] {pos1, pos2}; + } + /** * Get the corner locations for a list of regions. * @@ -358,11 +390,11 @@ public class MainUtil { * @return * @see Plot#getCorners() */ - @NotNull public static Location[] getCorners(String world, Collection regions) { + @NotNull public static Location[] getCorners(String world, Collection regions) { Location min = null; Location max = null; - for (RegionWrapper region : regions) { - Location[] corners = region.getCorners(world); + for (CuboidRegion region : regions) { + Location[] corners = getCorners(world, region); if (min == null) { min = corners[0]; max = corners[1]; @@ -536,7 +568,9 @@ public class MainUtil { * @param biome */ public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, String biome) { - RegionWrapper region = new RegionWrapper(p1x, p2x, p1z, p2z); + BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(); + BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1); + CuboidRegion region = new CuboidRegion(pos1, pos2); WorldUtil.IMP.setBiomes(world, region, biome); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java index 326d151e6..75f8d79f0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java @@ -7,11 +7,10 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.generator.ClassicPlotWorld; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; @@ -20,22 +19,40 @@ import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader; import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import org.jetbrains.annotations.NotNull; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +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.Set; +import java.util.UUID; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -151,19 +168,19 @@ public abstract class SchematicHandler { final int LENGTH = dimension.getZ(); final int HEIGHT = dimension.getY(); // Validate dimensions - RegionWrapper region = plot.getLargestRegion(); - if (((region.maxX - region.minX + xOffset + 1) < WIDTH) || ( - (region.maxZ - region.minZ + zOffset + 1) < LENGTH) || (HEIGHT > 256)) { + CuboidRegion region = plot.getLargestRegion(); + if (((region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + xOffset + 1) < WIDTH) || ( + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + zOffset + 1) < LENGTH) || (HEIGHT > 256)) { PlotSquared.debug("Schematic is too large"); PlotSquared.debug( "(" + WIDTH + ',' + LENGTH + ',' + HEIGHT + ") is bigger than (" + ( - region.maxX - region.minX) + ',' + (region.maxZ - region.minZ) + region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) + ',' + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) + ",256)"); TaskManager.runTask(whenDone); return; } // block type and data arrays - final BlockArrayClipboard blockArrayClipboard = schematic.getClipboard(); + final Clipboard blockArrayClipboard = schematic.getClipboard(); // Calculate the optimal height to paste the schematic at final int y_offset_actual; if (autoHeight) { @@ -175,16 +192,16 @@ public abstract class SchematicHandler { y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; } else { y_offset_actual = yOffset + 1 + MainUtil - .getHeighestBlock(plot.getWorldName(), region.minX + 1, - region.minZ + 1); + .getHeighestBlock(plot.getWorldName(), region.getMinimumPoint().getX() + 1, + region.getMinimumPoint().getZ() + 1); } } } else { y_offset_actual = yOffset; } Location pos1 = - new Location(plot.getWorldName(), region.minX + xOffset, y_offset_actual, - region.minZ + zOffset); + new Location(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset, y_offset_actual, + region.getMinimumPoint().getZ() + zOffset); Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); final int p1x = pos1.getX(); final int p1z = pos1.getZ(); @@ -197,9 +214,9 @@ public abstract class SchematicHandler { ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { - ChunkLoc chunk = new ChunkLoc(value[0], value[1]); - int x = chunk.x; - int z = chunk.z; + BlockVector2 chunk = BlockVector2.at(value[0], value[1]); + int x = chunk.getX(); + int z = chunk.getZ(); int xxb = x << 4; int zzb = z << 4; int xxt = xxb + 15; @@ -313,7 +330,7 @@ public abstract class SchematicHandler { ClipboardFormat format = ClipboardFormats.findByFile(file); if (format != null) { ClipboardReader reader = format.getReader(new FileInputStream(file)); - BlockArrayClipboard clip = (BlockArrayClipboard) reader.read(); + Clipboard clip = reader.read(); return new Schematic(clip); } else { throw new UnsupportedFormatException( @@ -340,13 +357,13 @@ public abstract class SchematicHandler { try { SpongeSchematicReader schematicReader = new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))); - BlockArrayClipboard clip = (BlockArrayClipboard) schematicReader.read(); + Clipboard clip = schematicReader.read(); return new Schematic(clip); } catch (IOException ignored) { try { MCEditSchematicReader schematicReader = new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is))); - BlockArrayClipboard clip = (BlockArrayClipboard) schematicReader.read(); + Clipboard clip = schematicReader.read(); return new Schematic(clip); } catch (IOException e) { e.printStackTrace(); @@ -428,7 +445,7 @@ public abstract class SchematicHandler { return true; } - public abstract void getCompoundTag(String world, Set regions, + public abstract void getCompoundTag(String world, Set regions, RunnableVal whenDone); public void getCompoundTag(final Plot plot, final RunnableVal whenDone) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java index 60a0d778b..9967e88eb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java @@ -10,8 +10,8 @@ import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.google.common.collect.BiMap; import org.jetbrains.annotations.NotNull; - import org.jetbrains.annotations.Nullable; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java index 17ab6b5ce..b5e37ed93 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java @@ -14,8 +14,8 @@ import com.google.common.base.Charsets; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import org.jetbrains.annotations.NotNull; - import org.jetbrains.annotations.Nullable; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java index 3aaed57fb..52be1a312 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java @@ -1,13 +1,19 @@ package com.github.intellectualsites.plotsquared.plot.util; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -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.PlotPlayer; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.world.block.BlockState; import java.io.ByteArrayOutputStream; import java.io.File; @@ -44,15 +50,15 @@ public abstract class WorldUtil { public abstract void saveWorld(String world); - public abstract String getClosestMatchingName(PlotBlock plotBlock); + public abstract String getClosestMatchingName(BlockState plotBlock); - public abstract boolean isBlockSolid(PlotBlock block); + public abstract boolean isBlockSolid(BlockState block); - public abstract StringComparison.ComparisonResult getClosestBlock(String name); + public abstract StringComparison.ComparisonResult getClosestBlock(String name); public abstract String getBiome(String world, int x, int z); - public abstract PlotBlock getBlock(Location location); + public abstract BlockState getBlock(Location location); public abstract int getHighestBlock(String world, int x, int z); @@ -60,7 +66,7 @@ public abstract class WorldUtil { public abstract void setSign(String world, int x, int y, int z, String[] lines); - public abstract void setBiomes(String world, RegionWrapper region, String biome); + public abstract void setBiomes(String world, CuboidRegion region, String biome); public abstract com.sk89q.worldedit.world.World getWeWorld(String world); @@ -104,10 +110,10 @@ public abstract class WorldUtil { int brz = bot.getZ() >> 9; int trx = top.getX() >> 9; int trz = top.getZ() >> 9; - Set files = ChunkManager.manager.getChunkChunks(bot.getWorld()); - for (ChunkLoc mca : files) { - if (mca.x >= brx && mca.x <= trx && mca.z >= brz && mca.z <= trz) { - final File file = getMcr(plot.getWorldName(), mca.x, mca.z); + Set files = ChunkManager.manager.getChunkChunks(bot.getWorld()); + for (BlockVector2 mca : files) { + if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz) { + final File file = getMcr(plot.getWorldName(), mca.getX(), mca.getZ()); if (file != null) { //final String name = "r." + (x - cx) + "." + (z - cz) + ".mca"; String name = file.getName(); @@ -155,5 +161,5 @@ public abstract class WorldUtil { return null; } - public abstract boolean isBlockSame(PlotBlock block1, PlotBlock block2); + public abstract boolean isBlockSame(BlockState block1, BlockState block2); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java index 133088a2e..e016cfeea 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.util.area; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.HashSet; import java.util.Set; @@ -96,9 +97,9 @@ public class QuadMap { this.objects.add(area); return; } - RegionWrapper region = getRegion(area); - if (region.minX >= this.x) { - if (region.minZ >= this.z) { + CuboidRegion region = getRegion(area); + if (region.getMinimumPoint().getX() >= this.x) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.one == null) { this.one = newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize, @@ -107,7 +108,7 @@ public class QuadMap { this.one.add(area); recalculateSkip(); return; - } else if (region.maxZ < this.z) { + } else if (region.getMaximumPoint().getZ() < this.z) { if (this.two == null) { this.two = newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize, @@ -117,8 +118,8 @@ public class QuadMap { recalculateSkip(); return; } - } else if (region.maxX < this.x) { - if (region.minZ >= this.z) { + } else if (region.getMaximumPoint().getX() < this.x) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.four == null) { this.four = newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize, @@ -127,7 +128,7 @@ public class QuadMap { this.four.add(area); recalculateSkip(); return; - } else if (region.maxZ < this.z) { + } else if (region.getMaximumPoint().getZ() < this.z) { if (this.three == null) { this.three = newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize, @@ -144,14 +145,14 @@ public class QuadMap { this.objects.add(area); } - public RegionWrapper getRegion(T value) { + public CuboidRegion getRegion(T value) { return null; } public QuadMap newInstance(int newsize, int x, int z, int min) { try { return new QuadMap(newsize, x, z, min) { - @Override public RegionWrapper getRegion(T value) { + @Override public CuboidRegion getRegion(T value) { return QuadMap.this.getRegion(value); } }; @@ -172,9 +173,9 @@ public class QuadMap { this.skip = null; } } else { - RegionWrapper region = getRegion(area); - if (region.minX >= this.x) { - if (region.minZ >= this.z) { + CuboidRegion region = getRegion(area); + if (region.getMinimumPoint().getX() >= this.x) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.one != null) { if (this.one.remove(area)) { this.one = null; @@ -190,7 +191,7 @@ public class QuadMap { } } } else { - if (region.minZ >= this.z) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.four != null) { if (this.four.remove(area)) { this.four = null; @@ -224,11 +225,11 @@ public class QuadMap { this.skip = map.skip == null ? map : map.skip; } - public Set get(RegionWrapper region) { + public Set get(CuboidRegion region) { HashSet set = new HashSet<>(); if (this.objects != null) { for (T obj : this.objects) { - if (getRegion(obj).intersects(region)) { + if (RegionUtil.intersects(getRegion(obj), region)) { set.add(obj); } } @@ -254,15 +255,15 @@ public class QuadMap { return set; } - public boolean intersects(RegionWrapper other) { - return (other.minX <= this.x + this.size) && (other.maxX >= this.x - this.size) && ( - other.minZ <= this.z + this.size) && (other.maxZ >= this.z - this.size); + public boolean intersects(CuboidRegion other) { + return (other.getMinimumPoint().getX() <= this.x + this.size) && (other.getMaximumPoint().getX() >= this.x - this.size) && ( + other.getMinimumPoint().getZ() <= this.z + this.size) && (other.getMaximumPoint().getZ() >= this.z - this.size); } public T get(int x, int z) { if (this.objects != null) { for (T obj : this.objects) { - if (getRegion(obj).isIn(x, z)) { + if (RegionUtil.contains(getRegion(obj), x, z)) { return obj; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java index ad20a5b99..08bfab890 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java @@ -1,11 +1,11 @@ package com.github.intellectualsites.plotsquared.plot.util.block; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import org.jetbrains.annotations.NotNull; import java.util.concurrent.ConcurrentHashMap; @@ -30,7 +30,7 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { public abstract LocalChunk getLocalChunk(int x, int z); - @Override public abstract PlotBlock getBlock(int x, int y, int z); + @Override public abstract BlockState getBlock(int x, int y, int z); public abstract void setComponents(LocalChunk lc) throws ExecutionException, InterruptedException; @@ -111,11 +111,11 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { return true; } - @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { - // Trying to mix PlotBlock and BaseBlock leads to all kinds of issues. - // Since BaseBlock has more features than PlotBlock, simply convert - // all PlotBlocks to BaseBlocks - return setBlock(x, y, z, id.getBaseBlock()); + @Override public boolean setBlock(int x, int y, int z, BlockState id) { + // Trying to mix BlockState and BaseBlock leads to all kinds of issues. + // Since BaseBlock has more features than BlockState, simply convert + // all BlockStates to BaseBlocks + return setBlock(x, y, z, id.toBaseBlock()); } @Override public final boolean setBiome(int x, int z, String biome) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java index c5c17b4a4..cf695f3d6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java @@ -1,7 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.util.block; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; public class DelegateLocalBlockQueue extends LocalBlockQueue { @@ -62,11 +62,11 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue { return parent.setBlock(x, y, z, id); } - @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { + @Override public boolean setBlock(int x, int y, int z, BlockState id) { return parent.setBlock(x, y, z, id); } - @Override public PlotBlock getBlock(int x, int y, int z) { + @Override public BlockState getBlock(int x, int y, int z) { return parent.getBlock(x, y, z); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java index 04a9e2f0c..572f70228 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java @@ -1,16 +1,16 @@ package com.github.intellectualsites.plotsquared.plot.util.block; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import java.util.Map; @@ -53,7 +53,7 @@ public abstract class LocalBlockQueue { * @param z the z coordinate from 0 to 15 inclusive * @param id the id to set the block to */ - public abstract boolean setBlock(final int x, final int y, final int z, final PlotBlock id); + public abstract boolean setBlock(final int x, final int y, final int z, final BlockState id); public abstract boolean setBlock(final int x, final int y, final int z, final BaseBlock id); @@ -62,7 +62,7 @@ public abstract class LocalBlockQueue { return true; } - public abstract PlotBlock getBlock(int x, int y, int z); + public abstract BlockState getBlock(int x, int y, int z); public abstract boolean setBiome(int x, int z, String biome); @@ -83,11 +83,11 @@ public abstract class LocalBlockQueue { public final void regenChunkSafe(int x, int z) { regenChunk(x, z); fixChunkLighting(x, z); - ChunkLoc loc = new ChunkLoc(x, z); + BlockVector2 loc = BlockVector2.at(x, z); for (Map.Entry entry : UUIDHandler.getPlayers().entrySet()) { PlotPlayer pp = entry.getValue(); Location pLoc = pp.getLocation(); - if (!StringMan.isEqual(getWorld(), pLoc.getWorld()) || !pLoc.getChunkLoc() + if (!StringMan.isEqual(getWorld(), pLoc.getWorld()) || !pLoc.getBlockVector2() .equals(loc)) { continue; } @@ -100,7 +100,7 @@ public abstract class LocalBlockQueue { return GlobalBlockQueue.IMP.enqueue(this); } - public void setCuboid(Location pos1, Location pos2, PlotBlock block) { + public void setCuboid(Location pos1, Location pos2, BlockState block) { int yMin = Math.min(pos1.getY(), pos2.getY()); int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY())); int xMin = Math.min(pos1.getX(), pos2.getX()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java index 7e41887ed..416a2c36e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java @@ -4,10 +4,10 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { private final int minX; @@ -55,7 +55,7 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { .setBlock(x + minX, y + minY, z + minZ, id); } - @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { + @Override public boolean setBlock(int x, int y, int z, BlockState id) { return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super .setBlock(x + minX, y + minY, z + minZ, id); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java index 2fbcdee01..dbd9773f0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java @@ -7,13 +7,28 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java index 429a71035..484759d66 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java @@ -10,7 +10,12 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import java.lang.reflect.Array; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; public class PlotAnalysis { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java new file mode 100644 index 000000000..14ff2652c --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java @@ -0,0 +1,86 @@ +package com.github.intellectualsites.plotsquared.plot.util.world; + +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.internal.registry.InputParser; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.block.FuzzyBlockState; +import com.sk89q.worldedit.world.registry.LegacyMapper; +import lombok.NonNull; + +import java.util.Map; + +public final class BlockUtil { + private BlockUtil(){} + + private static final ParserContext PARSER_CONTEXT = new ParserContext(); + + private static final InputParser PARSER; + + static { + PARSER_CONTEXT.setRestricted(false); + PARSER_CONTEXT.setPreferringWildcard(false); + PARSER_CONTEXT.setTryLegacy(true); + PARSER = WorldEdit.getInstance().getBlockFactory().getParsers().get(0); + } + + public static final BlockState get(int id) { + return LegacyMapper.getInstance().getBlockFromLegacy(id); + } + + public static final BlockState get(int id, int data) { + return LegacyMapper.getInstance().getBlockFromLegacy(id, data); + } + + public static final BlockState get(String id) { + if (id.length() == 1 && id.charAt(0) == '*') { + return FuzzyBlockState.builder().type(BlockTypes.AIR).build(); + } + id = id.toLowerCase(); + BlockType type = BlockType.REGISTRY.get(id); + if (type != null) { + return type.getDefaultState(); + } + if (Character.isDigit(id.charAt(0))) { + String[] split = id.split(":"); + if (MathMan.isInteger(split[0])) { + if (split.length == 2) { + if (MathMan.isInteger(split[1])) { + return get(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } + } else { + return get(Integer.parseInt(split[0])); + } + } + } + try { + BaseBlock block = PARSER.parseFromInput(id, PARSER_CONTEXT); + return block.toImmutableState(); + } catch (InputParseException e) { + return null; + } + } + + public static final BlockState[] parse(String commaDelimited) { + String[] split = commaDelimited.split(",(?![^\\(\\[]*[\\]\\)])"); + BlockState[] result = new BlockState[split.length]; + for (int i = 0; i < split.length; i++) { + result[i] = get(split[i]); + } + return result; + } + + public static BlockState deserialize(@NonNull final Map map) { + if (map.containsKey("material")) { + final Object object = map.get("material"); + return get(object.toString()); + } + return null; + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java new file mode 100644 index 000000000..415df8fe1 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java @@ -0,0 +1,30 @@ +package com.github.intellectualsites.plotsquared.plot.util.world; + +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; +import com.sk89q.worldedit.world.registry.LegacyMapper; + +import java.util.Locale; + +public final class ItemUtil { + private ItemUtil(){} + + public static ItemType get(String input) { + input = input.toLowerCase(Locale.ROOT); + if (Character.isDigit(input.charAt(0))) { + String[] split = input.split(":"); + if (MathMan.isInteger(split[0])) { + if (split.length == 2) { + if (MathMan.isInteger(split[1])) { + return LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } + } else { + return LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0])); + } + } + } + if (!input.split("\\[", 2)[0].contains(":")) input = "minecraft:" + input; + return ItemTypes.get(input); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java new file mode 100644 index 000000000..05b969065 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java @@ -0,0 +1,116 @@ +package com.github.intellectualsites.plotsquared.plot.util.world; + +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; +import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.world.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.concurrent.Future; +import java.util.function.Consumer; + +public class OperationUtil { + private static final boolean ASYNC; + + static { + boolean hasFawe = true; + try { + Class.forName("com.boydti.fawe.Fawe"); + } catch (ClassNotFoundException ignore) { + hasFawe = false; + } + ASYNC = hasFawe; + } + + public Future withEditSession(@NotNull PlotPlayer plotPlayer, @NotNull Consumer consumer, @Nullable Consumer exceptionHandler) { + if (ASYNC) { + ListeningExecutorService exec = WorldEdit.getInstance().getExecutorService(); + return exec.submit( + () -> withEditSessionOnThread(plotPlayer, consumer, exceptionHandler)); + } else { + withEditSessionOnThread(plotPlayer, consumer, exceptionHandler); + } + return Futures.immediateFuture(true); + } + + private void withEditSessionOnThread(PlotPlayer plotPlayer, Consumer consumer, Consumer exceptionHandler) { + Actor actor = plotPlayer.toActor(); + World weWorld = getWorld(plotPlayer, actor); + LocalSession session = getSession(actor); + try (EditSession ess = createEditSession(weWorld, actor, session)) { + try { + consumer.accept(ess); + } finally { + ess.close(); + session.remember(ess); + } + } catch (Throwable e) { + if (exceptionHandler != null) { + exceptionHandler.accept(e); + } else { + e.printStackTrace(); + } + } + } + + private static World getWorld(String worldName) { + Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING); + List worlds = platform.getWorlds(); + for (World current : worlds) { + if (current.getName().equals(worldName)) { + return current; + } + } + return null; + } + + private static World getWorld(PlotPlayer plotPlayer, Actor actor) { + World weWorld; + if (actor instanceof Player) { + weWorld = ((Player) actor).getWorld(); + } else { + @NotNull Location loc = plotPlayer.getLocation(); + String world = loc.getWorld(); + weWorld = getWorld(world); + } + return weWorld; + } + + private static EditSession createEditSession(PlotPlayer plotPlayer) { + Actor actor = plotPlayer.toActor(); + World weWorld = getWorld(plotPlayer, actor); + return createEditSession(weWorld, actor); + } + + private static LocalSession getSession(Actor actor) { + return WorldEdit.getInstance().getSessionManager().get(actor); + } + + private static EditSession createEditSession(World world, Actor actor) { + return createEditSession(world, actor, getSession(actor)); + } + + private static EditSession createEditSession(World world, Actor actor, LocalSession session) { + EditSession editSession; + Player player = actor.isPlayer() ? (Player) actor : null; + editSession = WorldEdit.getInstance().getEditSessionFactory() + .getEditSession(world, -1, null, player); + + editSession.setFastMode(!actor.isPlayer()); + editSession.setReorderMode(EditSession.ReorderMode.FAST); + return editSession; + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java new file mode 100644 index 000000000..271f76dac --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java @@ -0,0 +1,40 @@ +package com.github.intellectualsites.plotsquared.plot.util.world; + +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; + +public class RegionUtil { + public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) { + return createRegion(pos1x, pos2x, 0, Plot.MAX_HEIGHT - 1, pos1z, pos2z); + } + + public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1y, int pos2y, int pos1z, int pos2z) { + BlockVector3 pos1 = BlockVector3.at(pos1x, pos1y, pos1z); + BlockVector3 pos2 = BlockVector3.at(pos2x, pos2y, pos2z); + return new CuboidRegion(pos1, pos2); + } + + public static boolean contains(CuboidRegion region, int x, int z) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + return x >= min.getX() && x <= max.getX() && z >= min.getZ() && z <= max.getZ(); + } + + public static boolean contains(CuboidRegion region, int x, int y, int z) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + return x >= min.getX() && x <= max.getX() && z >= min.getZ() && z <= max.getZ() && y >= min.getY() && y <= max.getY(); + } + + // Because WE (not fawe) lack this for CuboidRegion + public static boolean intersects(CuboidRegion region, CuboidRegion other) { + BlockVector3 regionMin = region.getMinimumPoint(); + BlockVector3 regionMax = region.getMaximumPoint(); + + BlockVector3 otherMin = other.getMinimumPoint(); + BlockVector3 otherMax = other.getMaximumPoint(); + + return otherMin.getX() <= regionMax.getX() && otherMax.getX() >= regionMin.getX() && otherMin.getZ() <= regionMax.getZ() && otherMax.getZ() >= regionMin.getZ(); + } +} diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java index c2b81a729..8bbc1193f 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java @@ -5,16 +5,17 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; +import com.sk89q.worldedit.world.block.BlockType; import org.junit.Before; import org.junit.Test; import java.util.Collection; -import java.util.HashSet; import java.util.Optional; +import java.util.Set; import java.util.UUID; import static org.junit.Assert.assertEquals; @@ -36,13 +37,13 @@ public class FlagTest { Optional flag = plot.getFlag(use); if (flag.isPresent()) { System.out.println(Flags.USE.valueToString(flag.get())); - testBlock = PlotBlock.get((short) 1, (byte) 0); + testBlock = BlockUtil.get((short) 1, (byte) 0); flag.get().add(testBlock); } flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection))); - Optional> flag2 = plot.getFlag(Flags.USE); + Optional> flag2 = plot.getFlag(Flags.USE); if (flag2.isPresent()) { - // assertThat(flag2.get(), (Matcher>) IsCollectionContaining.hasItem(testBlock)); + // assertThat(flag2.get(), (Matcher>) IsCollectionContaining.hasItem(testBlock)); } if (flag.isPresent() && flag2.isPresent()) { assertEquals(flag.get(), flag2.get()); diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java index 6ae75a86d..fd2a8db15 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java @@ -1,7 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.util; import com.github.intellectualsites.plotsquared.plot.flag.Flag; -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.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Rating; import java.util.List; import java.util.UUID; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/NukkitMain.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/NukkitMain.java index 1cc8b8246..c84a73b67 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/NukkitMain.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/NukkitMain.java @@ -25,19 +25,15 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.generator.*; -import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; -import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.sk89q.worldedit.WorldEdit; import java.io.File; import java.lang.reflect.Field; -import java.util.*; public final class NukkitMain extends PluginBase implements Listener, IPlotMain { diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/generator/NukkitPlotGenerator.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/generator/NukkitPlotGenerator.java index ef274cf2b..d1712993b 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/generator/NukkitPlotGenerator.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/generator/NukkitPlotGenerator.java @@ -9,7 +9,6 @@ import com.github.intellectualsites.plotsquared.nukkit.util.block.NukkitWrappedC import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/listeners/PlayerEvents.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/listeners/PlayerEvents.java index c429ba0fd..456cb97b2 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/listeners/PlayerEvents.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/listeners/PlayerEvents.java @@ -28,11 +28,8 @@ import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; import com.google.common.base.Optional; -import java.util.*; import java.util.Map.Entry; import java.util.regex.Pattern; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/object/NukkitPlayer.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/object/NukkitPlayer.java index fa6bf2a59..f53213d69 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/object/NukkitPlayer.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/object/NukkitPlayer.java @@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.nukkit.util.NukkitUtil; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.*; import java.util.Collections; import java.util.UUID; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/Metrics.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/Metrics.java index 1a41b836d..9b2ffb10c 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/Metrics.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/Metrics.java @@ -6,12 +6,10 @@ import cn.nukkit.utils.LogLevel; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import java.io.*; import java.net.Proxy; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; -import java.util.*; import java.util.zip.GZIPOutputStream; public class Metrics { diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitChunkManager.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitChunkManager.java index 5caea648f..32da16dc3 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitChunkManager.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitChunkManager.java @@ -1,8 +1,7 @@ package com.github.intellectualsites.plotsquared.nukkit.util; - import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; +import com.github.intellectualsites.plotsquared.plot.object.BlockVector2; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; @@ -16,11 +15,11 @@ public class NukkitChunkManager extends ChunkManager { return new int[0]; } - @Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) { + @Override public boolean loadChunk(String world, BlockVector2 loc, boolean force) { return true; } - @Override public void unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) { + @Override public void unloadChunk(String world, BlockVector2 loc, boolean save, boolean safe) { } diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitEventUtil.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitEventUtil.java index 532870c43..d59e45ebf 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitEventUtil.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitEventUtil.java @@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.nukkit.NukkitMain; import com.github.intellectualsites.plotsquared.nukkit.events.*; import com.github.intellectualsites.plotsquared.nukkit.object.NukkitPlayer; import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import javax.annotation.Nullable; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitSchematicHandler.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitSchematicHandler.java index 7e8fcf362..4a301101a 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitSchematicHandler.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitSchematicHandler.java @@ -6,7 +6,7 @@ import cn.nukkit.level.format.generic.BaseFullChunk; import cn.nukkit.math.Vector3; import com.github.intellectualsites.plotsquared.jnbt.*; import com.github.intellectualsites.plotsquared.nukkit.NukkitMain; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; +import com.github.intellectualsites.plotsquared.plot.object.BlockVector2; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; @@ -16,7 +16,6 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import java.io.IOException; -import java.util.*; /** * Schematic Handler. @@ -98,10 +97,10 @@ public class NukkitSchematicHandler extends SchematicHandler { final int sy = pos1.getY(); final int ey = pos2.getY(); // Generate list of chunks - final ArrayList chunks = new ArrayList<>(); + final ArrayList chunks = new ArrayList<>(); for (int x = bcx; x <= tcx; x++) { for (int z = bcz; z <= tcz; z++) { - chunks.add(new ChunkLoc(x, z)); + chunks.add(BlockVector2.at(x, z)); } } final Level worldObj = plugin.getServer().getLevelByName(world); @@ -113,7 +112,7 @@ public class NukkitSchematicHandler extends SchematicHandler { while (!chunks.isEmpty() && System.currentTimeMillis() - start < 20) { // save schematics - ChunkLoc chunk = chunks.remove(0); + BlockVector2 chunk = chunks.remove(0); BaseFullChunk bc = worldObj.getChunk(chunk.x, chunk.z); try { bc.load(false); diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitUtil.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitUtil.java index 4712d129d..ad085dca3 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitUtil.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/NukkitUtil.java @@ -20,7 +20,6 @@ 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.schematic.PlotItem; -import com.github.intellectualsites.plotsquared.plot.util.*; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitHybridGen.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitHybridGen.java index ccca6dfe8..6af270e63 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitHybridGen.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitHybridGen.java @@ -1,5 +1,7 @@ package com.github.intellectualsites.plotsquared.nukkit.util.block; +import com.sk89q.worldedit.math.BlockVector2; + import cn.nukkit.level.Level; import com.github.intellectualsites.plotsquared.nukkit.NukkitMain; import com.github.intellectualsites.plotsquared.nukkit.generator.NukkitPlotGenerator; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitLocalQueue.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitLocalQueue.java index 0a8012691..297df7c6b 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitLocalQueue.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitLocalQueue.java @@ -1,5 +1,7 @@ package com.github.intellectualsites.plotsquared.nukkit.util.block; +import com.sk89q.worldedit.math.BlockVector2; + import cn.nukkit.block.Block; import cn.nukkit.level.Level; import cn.nukkit.level.biome.EnumBiome; diff --git a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitWrappedChunk.java b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitWrappedChunk.java index 1dcb029f5..bc5182947 100644 --- a/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitWrappedChunk.java +++ b/Nukkit/src/main/java/com/github/intellectualsites/plotsquared/nukkit/util/block/NukkitWrappedChunk.java @@ -1,5 +1,7 @@ package com.github.intellectualsites.plotsquared.nukkit.util.block; +import com.sk89q.worldedit.math.BlockVector2; + import cn.nukkit.level.biome.Biome; import cn.nukkit.level.biome.EnumBiome; import cn.nukkit.level.format.generic.BaseFullChunk; diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/SpongeMain.java index 0877e42fb..07e535040 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/SpongeMain.java @@ -18,7 +18,6 @@ import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManag import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator; -import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.github.intellectualsites.plotsquared.sponge.generator.SpongePlotGenerator; diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/listener/MainListener.java index 01dcfcd16..09f500103 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/listener/MainListener.java @@ -4,8 +4,6 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.sponge.SpongeMain; import com.github.intellectualsites.plotsquared.sponge.object.SpongePlayer; import com.github.intellectualsites.plotsquared.sponge.util.SpongeUtil; @@ -35,7 +33,6 @@ import org.spongepowered.api.event.world.ExplosionEvent.Detonate; import org.spongepowered.api.text.Text; import org.spongepowered.api.world.World; -import java.util.*; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeChunkManager.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeChunkManager.java index 5de2ae309..f5a26c306 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeChunkManager.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeChunkManager.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.sponge.util; -import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; +import com.github.intellectualsites.plotsquared.plot.object.BlockVector2; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; @@ -53,12 +53,12 @@ public class SpongeChunkManager extends ChunkManager { return count; } - @Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) { + @Override public boolean loadChunk(String world, BlockVector2 loc, boolean force) { World worldObj = SpongeUtil.getWorld(world); return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent(); } - @Override public Set getChunkChunks(String world) { + @Override public Set getChunkChunks(String world) { // TODO save world; return super.getChunkChunks(world); } @@ -100,7 +100,7 @@ public class SpongeChunkManager extends ChunkManager { throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } - @Override public void unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) { + @Override public void unloadChunk(String world, BlockVector2 loc, boolean save, boolean safe) { World worldObj = SpongeUtil.getWorld(world); Optional chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4); if (chunk.isPresent()) { diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeCommand.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeCommand.java index 2c6b9b936..21ab4b19e 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeCommand.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeCommand.java @@ -16,8 +16,6 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; -import java.util.*; - public class SpongeCommand implements CommandCallable { @Override public CommandResult process(CommandSource source, String arguments) diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeEventUtil.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeEventUtil.java index d4c16e73d..a69f4c431 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeEventUtil.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeEventUtil.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.sponge.util; import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.sponge.SpongeMain; import com.github.intellectualsites.plotsquared.sponge.events.*; diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeMetrics.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeMetrics.java index 4ea1bc19d..4a221d4e9 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeMetrics.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeMetrics.java @@ -1,5 +1,24 @@ package com.github.intellectualsites.plotsquared.sponge.util; +import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.google.inject.Inject; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import org.spongepowered.api.Game; +import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.scheduler.Task; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.Proxy; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLEncoder; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.zip.GZIPOutputStream; + /* * Copyright 2011-2013 Tyler Blair. All rights reserved. * @@ -28,24 +47,6 @@ package com.github.intellectualsites.plotsquared.sponge.util; * either expressed or implied, of anybody else. */ -import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.google.inject.Inject; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; -import ninja.leaping.configurate.hocon.HoconConfigurationLoader; -import ninja.leaping.configurate.loader.ConfigurationLoader; -import org.spongepowered.api.Game; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.scheduler.Task; - -import java.io.*; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.zip.GZIPOutputStream; - public class SpongeMetrics { /** diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java index 648a3ebd2..ecfe61fe4 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java @@ -1,17 +1,16 @@ package com.github.intellectualsites.plotsquared.sponge.util; import com.github.intellectualsites.plotsquared.jnbt.*; -import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; +import com.sk89q.worldedit.math.BlockVector2; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.item.inventory.Carrier; import org.spongepowered.api.item.inventory.type.CarriedInventory; import org.spongepowered.api.world.World; -import java.util.*; import java.util.Map.Entry; public class SpongeSchematicHandler extends SchematicHandler { @@ -92,10 +91,10 @@ public class SpongeSchematicHandler extends SchematicHandler { int sy = pos1.getY(); int ey = pos2.getY(); // Generate list of chunks - ArrayList chunks = new ArrayList<>(); + ArrayList chunks = new ArrayList<>(); for (int x = bcx; x <= tcx; x++) { for (int z = bcz; z <= tcz; z++) { - chunks.add(new ChunkLoc(x, z)); + chunks.add(BlockVector2.at(x, z)); } } World worldObj = SpongeUtil.getWorld(world); @@ -106,7 +105,7 @@ public class SpongeSchematicHandler extends SchematicHandler { while (!chunks.isEmpty() && System.currentTimeMillis() - start < 20) { // save schematics - ChunkLoc chunk = chunks.remove(0); + BlockVector2 chunk = chunks.remove(0); int X = chunk.x; int Z = chunk.z; if (!worldObj.getChunk(X, 0, Z).isPresent() && !worldObj diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSetupUtils.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSetupUtils.java index 3caf627bc..7a8cfc1a6 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSetupUtils.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSetupUtils.java @@ -19,7 +19,6 @@ import org.spongepowered.api.world.gen.WorldGeneratorModifier; import org.spongepowered.api.world.storage.WorldProperties; import java.io.IOException; -import java.util.*; import java.util.Map.Entry; public class SpongeSetupUtils extends SetupUtils { diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeUtil.java index e1307f76d..404006678 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeUtil.java @@ -9,7 +9,6 @@ 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.schematic.PlotItem; -import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.sponge.SpongeMain; import com.github.intellectualsites.plotsquared.sponge.object.SpongePlayer; import net.minecraft.block.Block; @@ -39,7 +38,6 @@ import org.spongepowered.api.world.extent.Extent; import java.io.IOException; import java.lang.reflect.Field; -import java.util.*; public class SpongeUtil extends WorldUtil { diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/GenChunk.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/GenChunk.java index f88e8fa0d..698befdf8 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/GenChunk.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/GenChunk.java @@ -1,5 +1,7 @@ package com.github.intellectualsites.plotsquared.sponge.util.block; +import com.sk89q.worldedit.math.BlockVector2; + import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; diff --git a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java index 00e294138..51efceeb2 100644 --- a/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java +++ b/Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java @@ -1,5 +1,7 @@ package com.github.intellectualsites.plotsquared.sponge.util.block; +import com.sk89q.worldedit.math.BlockVector2; + import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PseudoRandom; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; diff --git a/build.gradle b/build.gradle index d7052ca6d..4a8237379 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,14 @@ version = String.format("%s.%s", rootVersion, buildNumber) description = rootProject.name +allprojects { + gradle.projectsEvaluated { + tasks.withType(JavaCompile) { + options.compilerArgs << "-Xmaxerrs" << "1000" + } + } +} + subprojects { apply(plugin: "java") apply(plugin: "maven")