- *
- * @version 3.3.3
- */
-@SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI {
-
- /**
- * Get all plots.
- *
- * @return all plots
- * @see PlotSquared#getPlots()
- */
- public Set getAllPlots() {
- return PlotSquared.get().getPlots();
- }
-
- /**
- * Return all plots for a player.
- *
- * @param player Player, whose plots to search for
- * @return all plots that a player owns
- */
- public Set getPlayerPlots(PlotPlayer player) {
- return PlotSquared.get().getPlots(player);
- }
-
- /**
- * Add a plot world.
- *
- * @param plotArea Plot World Object
- * @see PlotSquared#addPlotArea(PlotArea)
- */
- public void addPlotArea(PlotArea plotArea) {
- PlotSquared.get().addPlotArea(plotArea);
- }
-
- /**
- * Returns the PlotSquared configurations file.
- *
- * @return main configuration
- * @see PlotSquared#config
- */
- public YamlConfiguration getConfig() {
- return PlotSquared.get().config;
- }
-
- /**
- * Get the PlotSquared storage file.
- *
- * @return storage configuration
- * @see PlotSquared#storage
- */
- public YamlConfiguration getStorage() {
- return PlotSquared.get().storage;
- }
-
- /**
- * Get the main class for this plugin. Only use this if you really need it.
- *
- * @return PlotSquared PlotSquared Main Class
- * @see PlotSquared
- */
- public PlotSquared getMain() {
- return PlotSquared.get();
- }
-
- /**
- * ChunkManager class contains several useful methods.
- *
- *
Chunk deletion
- *
Moving or copying regions
- *
Plot swapping
- *
Entity Tracking
- *
Region Regeneration
- *
- *
- * @return ChunkManager
- * @see ChunkManager
- */
- public ChunkManager getChunkManager() {
- return ChunkManager.manager;
- }
-
- /**
- * Get the block/biome set queue
- *
- * @return GlobalBlockQueue.IMP
- */
- public GlobalBlockQueue getBlockQueue() {
- return GlobalBlockQueue.IMP;
- }
-
- /**
- * UUIDWrapper class has basic methods for getting UUIDS. It's recommended
- * to use the UUIDHandler class instead.
- *
- * @return UUIDWrapper
- * @see UUIDWrapper
- */
- public UUIDWrapper getUUIDWrapper() {
- return UUIDHandler.getUUIDWrapper();
- }
-
- /**
- * SchematicHandler class contains methods related to pasting, reading
- * and writing schematics.
- *
- * @return SchematicHandler
- * @see SchematicHandler
- */
- public SchematicHandler getSchematicHandler() {
- return SchematicHandler.manager;
- }
-
- /**
- * Get a list of PlotAreas in the world.
- *
- * @param world The world to check for plot areas
- * @return A set of PlotAreas
- */
- public Set getPlotAreas(String world) {
- if (world == null) {
- return Collections.emptySet();
- }
- return PlotSquared.get().getPlotAreas(world);
- }
-
- /**
- * Send a message to the console. The message supports color codes.
- *
- * @param message the message
- * @see MainUtil#sendConsoleMessage(C, String...)
- */
- public void sendConsoleMessage(String message) {
- PlotSquared.log(message);
- }
-
- /**
- * Send a message to the console.
- *
- * @param caption the message
- * @see #sendConsoleMessage(String)
- * @see C
- */
- public void sendConsoleMessage(C caption) {
- sendConsoleMessage(caption.s());
- }
-
- /**
- * Registers a flag for use in plots.
- *
- * @param flag the flag to register
- */
- public void addFlag(Flag> flag) {
- Flags.registerFlag(flag);
- }
-
- /**
- * Gets the PlotSquared class.
- *
- * @return PlotSquared Class
- * @see PlotSquared
- */
- public PlotSquared getPlotSquared() {
- return PlotSquared.get();
- }
-
- /**
- * Get the PlotPlayer for a UUID.
- *
- *
Please note that PlotSquared can be configured to provide
- * different UUIDs than bukkit
- *
- * @param uuid the uuid of the player to wrap
- * @return a {@code PlotPlayer}
- * @see PlotPlayer#wrap(Object)
- */
- public PlotPlayer wrapPlayer(UUID uuid) {
- return PlotPlayer.wrap(uuid);
- }
-
- /**
- * Get the PlotPlayer for a username.
- *
- * @param player the player to wrap
- * @return a {@code PlotPlayer}
- * @see PlotPlayer#wrap(Object)
- */
- public PlotPlayer wrapPlayer(String player) {
- return PlotPlayer.wrap(player);
- }
-}
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 ab1894a9d..e1006b056 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
@@ -1,36 +1,11 @@
package com.github.intellectualsites.plotsquared.bukkit;
-import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
-
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
-import com.github.intellectualsites.plotsquared.bukkit.listeners.ChunkListener;
-import com.github.intellectualsites.plotsquared.bukkit.listeners.EntitySpawnListener;
-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.listeners.*;
import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111;
-import com.github.intellectualsites.plotsquared.bukkit.util.BukkitBlockRegistry;
-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.BukkitLegacyMappings;
-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.SendChunk;
-import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB;
+import com.github.intellectualsites.plotsquared.bukkit.util.*;
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;
-import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
-import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
-import com.github.intellectualsites.plotsquared.bukkit.uuid.SQLUUIDHandler;
+import com.github.intellectualsites.plotsquared.bukkit.uuid.*;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.IPlotMain;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
@@ -41,57 +16,22 @@ 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;
-import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
-import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
-import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
+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.object.worlds.SingleWorldGenerator;
-import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
-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.LegacyMappings;
-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.WorldUtil;
+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.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Capability;
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.UUID;
-import javax.annotation.Nullable;
import lombok.Getter;
import lombok.NonNull;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Chunk;
+import org.bukkit.*;
import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@@ -104,6 +44,13 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
+import javax.annotation.Nullable;
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.*;
+
+import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
+
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Getter private static WorldEdit worldEdit;
@@ -319,8 +266,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return getDescription().getVersion();
}
- @Override
- public String getPluginName() {
+ @Override public String getPluginName() {
return pluginName;
}
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 69b168b3d..5e87231df 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
@@ -5,7 +5,10 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;
-import org.bukkit.*;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.Statistic;
import org.bukkit.Statistic.Type;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
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 7b56cabfd..a57a8dbe3 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,5 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
-import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
-
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
@@ -11,8 +9,6 @@ import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefCla
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefField;
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefMethod;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
-import java.lang.reflect.Method;
-import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@@ -31,8 +27,12 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
-@SuppressWarnings("unused")
-public class ChunkListener implements Listener {
+import java.lang.reflect.Method;
+import java.util.HashSet;
+
+import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
+
+@SuppressWarnings("unused") public class ChunkListener implements Listener {
private RefMethod methodGetHandleChunk;
private RefField mustSave;
@@ -48,7 +48,7 @@ public class ChunkListener implements Listener {
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
} catch (Throwable ignored) {
PlotSquared.debug(PlotSquared.get().IMP.getPluginName()
- + "/Server not compatible for chunk processor trim/gc");
+ + "/Server not compatible for chunk processor trim/gc");
Settings.Chunk_Processor.AUTO_TRIM = false;
}
@@ -68,10 +68,9 @@ public class ChunkListener implements Listener {
continue;
}
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
- Object chunkMap =
- w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
- Method methodIsChunkInUse = chunkMap.getClass()
- .getDeclaredMethod("isChunkInUse", int.class, int.class);
+ Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
+ Method methodIsChunkInUse =
+ chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
Chunk[] chunks = world.getLoadedChunks();
for (Chunk chunk : chunks) {
if ((boolean) methodIsChunkInUse
@@ -145,8 +144,7 @@ public class ChunkListener implements Listener {
return plot != null && plot.hasOwner();
}
- @EventHandler
- public void onChunkUnload(ChunkUnloadEvent event) {
+ @EventHandler public void onChunkUnload(ChunkUnloadEvent event) {
if (ignoreUnload) {
return;
}
@@ -164,13 +162,11 @@ public class ChunkListener implements Listener {
}
}
- @EventHandler
- public void onChunkLoad(ChunkLoadEvent event) {
+ @EventHandler public void onChunkLoad(ChunkLoadEvent event) {
processChunk(event.getChunk(), false);
}
- @EventHandler(priority = EventPriority.LOWEST)
- public void onItemSpawn(ItemSpawnEvent event) {
+ @EventHandler(priority = EventPriority.LOWEST) public void onItemSpawn(ItemSpawnEvent event) {
Item entity = event.getEntity();
Chunk chunk = entity.getLocation().getChunk();
if (chunk == this.lastChunk) {
@@ -227,8 +223,7 @@ public class ChunkListener implements Listener {
if (!chunk.isLoaded()) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
- PlotSquared
- .debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
+ PlotSquared.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true);
return;
}
@@ -236,8 +231,7 @@ public class ChunkListener implements Listener {
if (tiles.length == 0) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
- PlotSquared
- .debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
+ PlotSquared.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true);
return;
}
@@ -272,14 +266,14 @@ public class ChunkListener implements Listener {
}
}
PlotSquared.debug(
- C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4)
- + "," + (chunk.getX() << 4));
+ C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4)
+ + "," + (chunk.getX() << 4));
}
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
if (unload) {
PlotSquared.debug(
- C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
- chunk.getX() << 4));
+ C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
+ chunk.getX() << 4));
cleanChunk(chunk);
return true;
}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java
index bf33577a1..97d1bb7d7 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/ForceFieldListener.java
@@ -16,90 +16,89 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
-@SuppressWarnings("unused")
-public class ForceFieldListener {
+@SuppressWarnings("unused") public class ForceFieldListener {
- private static Set getNearbyPlayers(Player player, Plot plot) {
- Set players = new HashSet<>();
- for (Player nearPlayer : Iterables
- .filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
- PlotPlayer plotPlayer;
- if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
- .equals(plotPlayer.getCurrentPlot())) {
- continue;
- }
- if (!plot.isAdded(plotPlayer.getUUID())) {
- players.add(plotPlayer);
- }
- }
- return players;
- }
-
- private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
- for (Player nearPlayer : Iterables
- .filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
- PlotPlayer plotPlayer;
- if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
- .equals(plotPlayer.getCurrentPlot())) {
- continue;
- }
- if (plot.isAdded(plotPlayer.getUUID())) {
- return plotPlayer;
- }
- }
- return null;
- }
-
- private static Vector calculateVelocity(PlotPlayer player, PlotPlayer e) {
- Location playerLocation = player.getLocationFull();
- Location oPlayerLocation = e.getLocation();
- double playerX = playerLocation.getX();
- double playerY = playerLocation.getY();
- double playerZ = playerLocation.getZ();
- double oPlayerX = oPlayerLocation.getX();
- double oPlayerY = oPlayerLocation.getY();
- double oPlayerZ = oPlayerLocation.getZ();
- double x = 0d;
- if (playerX < oPlayerX) {
- x = 1.0d;
- } else if (playerX > oPlayerX) {
- x = -1.0d;
- }
- double y = 0d;
- if (playerY < oPlayerY) {
- y = 0.5d;
- } else if (playerY > oPlayerY) {
- y = -0.5d;
- }
- double z = 0d;
- if (playerZ < oPlayerZ) {
- z = 1.0d;
- } else if (playerZ > oPlayerZ) {
- z = -1.0d;
- }
- return new Vector(x, y, z);
- }
-
- public static void handleForcefield(Player player, PlotPlayer plotPlayer, Plot plot) {
- if (Flags.FORCEFIELD.isTrue(plot)) {
- UUID uuid = plotPlayer.getUUID();
- if (plot.isAdded(uuid)) {
- Set players = getNearbyPlayers(player, plot);
- for (PlotPlayer oPlayer : players) {
- if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
- ((BukkitPlayer) oPlayer).player
- .setVelocity(calculateVelocity(plotPlayer, oPlayer));
- }
+ private static Set getNearbyPlayers(Player player, Plot plot) {
+ Set players = new HashSet<>();
+ for (Player nearPlayer : Iterables
+ .filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
+ PlotPlayer plotPlayer;
+ if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
+ .equals(plotPlayer.getCurrentPlot())) {
+ continue;
+ }
+ if (!plot.isAdded(plotPlayer.getUUID())) {
+ players.add(plotPlayer);
+ }
+ }
+ return players;
+ }
+
+ private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
+ for (Player nearPlayer : Iterables
+ .filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
+ PlotPlayer plotPlayer;
+ if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
+ .equals(plotPlayer.getCurrentPlot())) {
+ continue;
+ }
+ if (plot.isAdded(plotPlayer.getUUID())) {
+ return plotPlayer;
+ }
+ }
+ return null;
+ }
+
+ private static Vector calculateVelocity(PlotPlayer player, PlotPlayer e) {
+ Location playerLocation = player.getLocationFull();
+ Location oPlayerLocation = e.getLocation();
+ double playerX = playerLocation.getX();
+ double playerY = playerLocation.getY();
+ double playerZ = playerLocation.getZ();
+ double oPlayerX = oPlayerLocation.getX();
+ double oPlayerY = oPlayerLocation.getY();
+ double oPlayerZ = oPlayerLocation.getZ();
+ double x = 0d;
+ if (playerX < oPlayerX) {
+ x = 1.0d;
+ } else if (playerX > oPlayerX) {
+ x = -1.0d;
+ }
+ double y = 0d;
+ if (playerY < oPlayerY) {
+ y = 0.5d;
+ } else if (playerY > oPlayerY) {
+ y = -0.5d;
+ }
+ double z = 0d;
+ if (playerZ < oPlayerZ) {
+ z = 1.0d;
+ } else if (playerZ > oPlayerZ) {
+ z = -1.0d;
+ }
+ return new Vector(x, y, z);
+ }
+
+ public static void handleForcefield(Player player, PlotPlayer plotPlayer, Plot plot) {
+ if (Flags.FORCEFIELD.isTrue(plot)) {
+ UUID uuid = plotPlayer.getUUID();
+ if (plot.isAdded(uuid)) {
+ Set players = getNearbyPlayers(player, plot);
+ for (PlotPlayer oPlayer : players) {
+ if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
+ ((BukkitPlayer) oPlayer).player
+ .setVelocity(calculateVelocity(plotPlayer, oPlayer));
+ }
+ }
+ } else {
+ PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
+ if (oPlayer == null) {
+ return;
+ }
+ if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
+ player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
+ }
+ }
}
- } else {
- PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
- if (oPlayer == null) {
- return;
- }
- if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
- player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
- }
- }
}
- }
}
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 ecb6b50ef..d0511aaa7 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
@@ -58,188 +58,186 @@ import java.util.regex.Pattern;
/**
* Player Events involving plots.
*/
-@SuppressWarnings("unused")
-public class PlayerEvents extends PlotListener implements Listener {
+@SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener {
- private boolean pistonBlocks = true;
- private float lastRadius;
- // To prevent recursion
- private boolean tmpTeleport = true;
- private Field fieldPlayer;
- private PlayerMoveEvent moveTmp;
+ private boolean pistonBlocks = true;
+ private float lastRadius;
+ // To prevent recursion
+ private boolean tmpTeleport = true;
+ private Field fieldPlayer;
+ private PlayerMoveEvent moveTmp;
- {
- try {
- fieldPlayer = PlayerEvent.class.getDeclaredField("player");
- fieldPlayer.setAccessible(true);
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
+ {
+ try {
+ fieldPlayer = PlayerEvent.class.getDeclaredField("player");
+ fieldPlayer.setAccessible(true);
+ } catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ }
}
- }
- public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) {
- TaskManager.runTaskLater(() -> {
- String world = bloc.getWorld().getName();
- int x = bloc.getBlockX();
- int z = bloc.getBlockZ();
- int distance = Bukkit.getViewDistance() * 16;
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer player = entry.getValue();
- Location loc = player.getLocation();
- if (loc.getWorld().equals(world)) {
- if (16 * Math.abs(loc.getX() - x) / 16 > distance
- || 16 * Math.abs(loc.getZ() - z) / 16 > distance) {
- continue;
- }
- ((BukkitPlayer) player).player.sendBlockChange(bloc, data);
- }
- }
- }, 3);
- }
-
- public static boolean checkEntity(Entity entity, Plot plot) {
- if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot
- .getArea().DEFAULT_FLAGS.isEmpty()) {
- return false;
+ public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) {
+ TaskManager.runTaskLater(() -> {
+ String world = bloc.getWorld().getName();
+ int x = bloc.getBlockX();
+ int z = bloc.getBlockZ();
+ int distance = Bukkit.getViewDistance() * 16;
+ for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
+ PlotPlayer player = entry.getValue();
+ Location loc = player.getLocation();
+ if (loc.getWorld().equals(world)) {
+ if (16 * Math.abs(loc.getX() - x) / 16 > distance
+ || 16 * Math.abs(loc.getZ() - z) / 16 > distance) {
+ continue;
+ }
+ ((BukkitPlayer) player).player.sendBlockChange(bloc, data);
+ }
+ }
+ }, 3);
}
- switch (entity.getType()) {
- case PLAYER:
- return false;
- case ARROW:
- case DRAGON_FIREBALL:
- case DROPPED_ITEM:
- case EGG:
- case ENDER_PEARL:
- case FIREBALL:
- case LINGERING_POTION:
- case LLAMA_SPIT:
- case SHULKER_BULLET:
- case SMALL_FIREBALL:
- case SNOWBALL:
- case SPECTRAL_ARROW:
- case SPLASH_POTION:
- case THROWN_EXP_BOTTLE:
- case TIPPED_ARROW:
- // projectile
- case FALLING_BLOCK:
- case PRIMED_TNT:
- // Block entities
- case AREA_EFFECT_CLOUD:
- case COMPLEX_PART:
- case ENDER_CRYSTAL:
- case ENDER_SIGNAL:
- case EVOKER_FANGS:
- case EXPERIENCE_ORB:
- case FIREWORK:
- case FISHING_HOOK:
- case LEASH_HITCH:
- case LIGHTNING:
- case UNKNOWN:
- case WEATHER:
- case WITHER_SKULL:
- // non moving / unmovable
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP);
- case ARMOR_STAND:
- case ITEM_FRAME:
- case PAINTING:
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP);
- // misc
- case BOAT:
- case MINECART:
- case MINECART_CHEST:
- case MINECART_COMMAND:
- case MINECART_FURNACE:
- case MINECART_HOPPER:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT:
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
- case BAT:
- case CHICKEN:
- case COD:
- case COW:
- case DOLPHIN:
- case DONKEY:
- case HORSE:
- case IRON_GOLEM:
- case LLAMA:
- case MULE:
- case MUSHROOM_COW:
- case OCELOT:
- case PARROT:
- case PIG:
- case POLAR_BEAR:
- case PUFFERFISH:
- case RABBIT:
- case SALMON:
- case SHEEP:
- case SKELETON_HORSE:
- case SNOWMAN:
- case SQUID:
- case TROPICAL_FISH:
- case TURTLE:
- case VILLAGER:
- case WOLF:
- case ZOMBIE_HORSE:
- // animal
- return EntityUtil
- .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
- case BLAZE:
- case CAVE_SPIDER:
- case CREEPER:
- case DROWNED:
- case ELDER_GUARDIAN:
- case ENDERMAN:
- case ENDERMITE:
- case ENDER_DRAGON:
- case EVOKER:
- case GHAST:
- case GIANT:
- case GUARDIAN:
- case HUSK:
- case ILLUSIONER:
- case MAGMA_CUBE:
- case PIG_ZOMBIE:
- case SHULKER:
- case SILVERFISH:
- case SKELETON:
- case SLIME:
- case SPIDER:
- case STRAY:
- case VEX:
- case VINDICATOR:
- case WITCH:
- case WITHER:
- case WITHER_SKELETON:
- case ZOMBIE:
- case ZOMBIE_VILLAGER:
- // monster
- return EntityUtil
- .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
- default:
- if (entity instanceof LivingEntity) {
- if (entity instanceof Animals || entity instanceof WaterMob) {
- return EntityUtil
- .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
- } else if (entity instanceof Monster) {
- return EntityUtil
- .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
- } else {
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP);
- }
- }
- if (entity instanceof Vehicle) {
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
- }
- if (entity instanceof Hanging) {
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP);
- }
- return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP);
- }
- }
- @EventHandler
- public void onRedstoneEvent(BlockRedstoneEvent event) {
- Block block = event.getBlock();
+ public static boolean checkEntity(Entity entity, Plot plot) {
+ if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot
+ .getArea().DEFAULT_FLAGS.isEmpty()) {
+ return false;
+ }
+ switch (entity.getType()) {
+ case PLAYER:
+ return false;
+ case ARROW:
+ case DRAGON_FIREBALL:
+ case DROPPED_ITEM:
+ case EGG:
+ case ENDER_PEARL:
+ case FIREBALL:
+ case LINGERING_POTION:
+ case LLAMA_SPIT:
+ case SHULKER_BULLET:
+ case SMALL_FIREBALL:
+ case SNOWBALL:
+ case SPECTRAL_ARROW:
+ case SPLASH_POTION:
+ case THROWN_EXP_BOTTLE:
+ case TIPPED_ARROW:
+ // projectile
+ case FALLING_BLOCK:
+ case PRIMED_TNT:
+ // Block entities
+ case AREA_EFFECT_CLOUD:
+ case COMPLEX_PART:
+ case ENDER_CRYSTAL:
+ case ENDER_SIGNAL:
+ case EVOKER_FANGS:
+ case EXPERIENCE_ORB:
+ case FIREWORK:
+ case FISHING_HOOK:
+ case LEASH_HITCH:
+ case LIGHTNING:
+ case UNKNOWN:
+ case WEATHER:
+ case WITHER_SKULL:
+ // non moving / unmovable
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP);
+ case ARMOR_STAND:
+ case ITEM_FRAME:
+ case PAINTING:
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP);
+ // misc
+ case BOAT:
+ case MINECART:
+ case MINECART_CHEST:
+ case MINECART_COMMAND:
+ case MINECART_FURNACE:
+ case MINECART_HOPPER:
+ case MINECART_MOB_SPAWNER:
+ case MINECART_TNT:
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
+ case BAT:
+ case CHICKEN:
+ case COD:
+ case COW:
+ case DOLPHIN:
+ case DONKEY:
+ case HORSE:
+ case IRON_GOLEM:
+ case LLAMA:
+ case MULE:
+ case MUSHROOM_COW:
+ case OCELOT:
+ case PARROT:
+ case PIG:
+ case POLAR_BEAR:
+ case PUFFERFISH:
+ case RABBIT:
+ case SALMON:
+ case SHEEP:
+ case SKELETON_HORSE:
+ case SNOWMAN:
+ case SQUID:
+ case TROPICAL_FISH:
+ case TURTLE:
+ case VILLAGER:
+ case WOLF:
+ case ZOMBIE_HORSE:
+ // animal
+ return EntityUtil
+ .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
+ case BLAZE:
+ case CAVE_SPIDER:
+ case CREEPER:
+ case DROWNED:
+ case ELDER_GUARDIAN:
+ case ENDERMAN:
+ case ENDERMITE:
+ case ENDER_DRAGON:
+ case EVOKER:
+ case GHAST:
+ case GIANT:
+ case GUARDIAN:
+ case HUSK:
+ case ILLUSIONER:
+ case MAGMA_CUBE:
+ case PIG_ZOMBIE:
+ case SHULKER:
+ case SILVERFISH:
+ case SKELETON:
+ case SLIME:
+ case SPIDER:
+ case STRAY:
+ case VEX:
+ case VINDICATOR:
+ case WITCH:
+ case WITHER:
+ case WITHER_SKELETON:
+ case ZOMBIE:
+ case ZOMBIE_VILLAGER:
+ // monster
+ return EntityUtil
+ .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
+ default:
+ if (entity instanceof LivingEntity) {
+ if (entity instanceof Animals || entity instanceof WaterMob) {
+ return EntityUtil
+ .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
+ } else if (entity instanceof Monster) {
+ return EntityUtil
+ .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
+ } else {
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP);
+ }
+ }
+ if (entity instanceof Vehicle) {
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
+ }
+ if (entity instanceof Hanging) {
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP);
+ }
+ return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP);
+ }
+ }
+
+ @EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) {
+ Block block = event.getBlock();
/* switch (block.getType()) {
case OBSERVER:
case REDSTONE:
@@ -287,2575 +285,2570 @@ public class PlayerEvents extends PlotListener implements Listener {
case POWERED_RAIL:
return;
default:*/
- Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(loc);
- if (plot == null) {
- return;
- }
- if (Flags.REDSTONE.isFalse(plot)) {
- event.setNewCurrent(0);
- return;
- }
- if (Settings.Redstone.DISABLE_OFFLINE) {
- boolean disable;
- if (plot.isMerged()) {
- disable = true;
- for (UUID owner : plot.getOwners()) {
- if (UUIDHandler.getPlayer(owner) != null) {
- disable = false;
- break;
- }
- }
- } else {
- disable = UUIDHandler.getPlayer(plot.guessOwner()) == null;
- }
- if (disable) {
- for (UUID trusted : plot.getTrusted()) {
- if (UUIDHandler.getPlayer(trusted) != null) {
- disable = false;
- break;
- }
- }
- if (disable) {
- event.setNewCurrent(0);
- return;
- }
- }
- }
- if (Settings.Redstone.DISABLE_UNOCCUPIED) {
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- if (plot.equals(entry.getValue().getCurrentPlot())) {
- return;
- }
- }
- event.setNewCurrent(0);
- }
- //}
- }
-
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void onPhysicsEvent(BlockPhysicsEvent event) {
- switch (event.getChangedType()) {
- case COMPARATOR: {
- Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea();
if (area == null) {
- return;
+ return;
}
- Plot plot = area.getOwnedPlotAbs(loc);
+ Plot plot = area.getOwnedPlot(loc);
if (plot == null) {
- return;
+ return;
}
if (Flags.REDSTONE.isFalse(plot)) {
- event.setCancelled(true);
+ event.setNewCurrent(0);
+ return;
+ }
+ if (Settings.Redstone.DISABLE_OFFLINE) {
+ boolean disable;
+ if (plot.isMerged()) {
+ disable = true;
+ for (UUID owner : plot.getOwners()) {
+ if (UUIDHandler.getPlayer(owner) != null) {
+ disable = false;
+ break;
+ }
+ }
+ } else {
+ disable = UUIDHandler.getPlayer(plot.guessOwner()) == null;
+ }
+ if (disable) {
+ for (UUID trusted : plot.getTrusted()) {
+ if (UUIDHandler.getPlayer(trusted) != null) {
+ disable = false;
+ break;
+ }
+ }
+ if (disable) {
+ event.setNewCurrent(0);
+ return;
+ }
+ }
+ }
+ if (Settings.Redstone.DISABLE_UNOCCUPIED) {
+ for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
+ if (plot.equals(entry.getValue().getCurrentPlot())) {
+ return;
+ }
+ }
+ event.setNewCurrent(0);
+ }
+ //}
+ }
+
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+ public void onPhysicsEvent(BlockPhysicsEvent event) {
+ switch (event.getChangedType()) {
+ case COMPARATOR: {
+ Block block = event.getBlock();
+ Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ return;
+ }
+ if (Flags.REDSTONE.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ return;
+ }
+ case ANVIL:
+ case DRAGON_EGG:
+ case GRAVEL:
+ case SAND:
+ case TURTLE_EGG:
+ case TURTLE_HELMET:
+ case TURTLE_SPAWN_EGG: {
+ Block block = event.getBlock();
+ Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ return;
+ }
+ if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ return;
+ }
+ default:
+ if (Settings.Redstone.DETECT_INVALID_EDGE_PISTONS) {
+ Block block = event.getBlock();
+ switch (block.getType()) {
+ case PISTON:
+ case STICKY_PISTON:
+ Piston piston = (Piston) block.getBlockData();
+ Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ return;
+ }
+ switch (piston.getFacing()) {
+ case EAST:
+ loc.setX(loc.getX() + 1);
+ break;
+ case SOUTH:
+ loc.setX(loc.getX() - 1);
+ break;
+ case WEST:
+ loc.setZ(loc.getZ() + 1);
+ break;
+ case NORTH:
+ loc.setZ(loc.getZ() - 1);
+ break;
+ }
+ Plot newPlot = area.getOwnedPlotAbs(loc);
+ if (!plot.equals(newPlot)) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) {
+ Projectile entity = event.getEntity();
+ if (!(entity instanceof ThrownPotion)) {
+ return;
+ }
+ ProjectileSource shooter = entity.getShooter();
+ if (!(shooter instanceof Player)) {
+ return;
+ }
+ Location l = BukkitUtil.getLocation(entity);
+ if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
+ return;
+ }
+ PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
+ Plot plot = l.getOwnedPlot();
+ if (plot != null && !plot.isAdded(pp.getUUID())) {
+ entity.remove();
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler public boolean onProjectileHit(ProjectileHitEvent event) {
+ Projectile entity = event.getEntity();
+ Location loc = BukkitUtil.getLocation(entity);
+ if (!PlotSquared.get().hasPlotArea(loc.getWorld())) {
+ return true;
}
- return;
- }
- case ANVIL:
- case DRAGON_EGG:
- case GRAVEL:
- case SAND:
- case TURTLE_EGG:
- case TURTLE_HELMET:
- case TURTLE_SPAWN_EGG: {
- Block block = event.getBlock();
- Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea();
if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- return;
- }
- if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
- event.setCancelled(true);
- }
- return;
- }
- default:
- if (Settings.Redstone.DETECT_INVALID_EDGE_PISTONS) {
- Block block = event.getBlock();
- switch (block.getType()) {
- case PISTON:
- case STICKY_PISTON:
- Piston piston = (Piston) block.getBlockData();
- Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- return;
- }
- switch (piston.getFacing()) {
- case EAST:
- loc.setX(loc.getX() + 1);
- break;
- case SOUTH:
- loc.setX(loc.getX() - 1);
- break;
- case WEST:
- loc.setZ(loc.getZ() + 1);
- break;
- case NORTH:
- loc.setZ(loc.getZ() - 1);
- break;
- }
- Plot newPlot = area.getOwnedPlotAbs(loc);
- if (!plot.equals(newPlot)) {
- event.setCancelled(true);
- return;
- }
- }
- }
- break;
- }
- }
-
- @EventHandler
- public void onProjectileLaunch(ProjectileLaunchEvent event) {
- Projectile entity = event.getEntity();
- if (!(entity instanceof ThrownPotion)) {
- return;
- }
- ProjectileSource shooter = entity.getShooter();
- if (!(shooter instanceof Player)) {
- return;
- }
- Location l = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
- return;
- }
- PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
- Plot plot = l.getOwnedPlot();
- if (plot != null && !plot.isAdded(pp.getUUID())) {
- entity.remove();
- event.setCancelled(true);
- }
- }
-
- @EventHandler
- public boolean onProjectileHit(ProjectileHitEvent event) {
- Projectile entity = event.getEntity();
- Location loc = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(loc.getWorld())) {
- return true;
- }
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return true;
- }
- Plot plot = area.getPlot(loc);
- ProjectileSource shooter = entity.getShooter();
- if (shooter instanceof Player) {
- PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) {
- entity.remove();
- return false;
- }
- return true;
- }
- if (plot.isAdded(pp.getUUID()) || Permissions
- .hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) {
- return true;
- }
- entity.remove();
- return false;
- }
- if (!(shooter instanceof Entity) && shooter != null) {
- if (plot == null) {
- entity.remove();
- return false;
- }
- Location sLoc =
- BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
- if (!area.contains(sLoc.getX(), sLoc.getZ())) {
- entity.remove();
- return false;
- }
- Plot sPlot = area.getOwnedPlotAbs(sLoc);
- if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
- entity.remove();
- return false;
- }
- }
- return true;
- }
-
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void playerCommand(PlayerCommandPreprocessEvent event) {
- String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim();
- if (msg.isEmpty()) {
- return;
- }
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- Location loc = pp.getLocation();
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- String[] parts = msg.split(" ");
- Plot plot = pp.getCurrentPlot();
- if (BukkitMain.getWorldEdit() != null) { // Check WorldEdit
- switch (parts[0].toLowerCase()) {
- case "up":
- case "/up":
- case "worldedit:up":
- case "worldedit:/up":
- if (plot == null || (!plot.isAdded(pp.getUUID()) && !Permissions
- .hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER, true))) {
- event.setCancelled(true);
- return;
- }
- }
- }
- if (plot == null) {
- return;
- }
- Optional> flag = plot.getFlag(Flags.BLOCKED_CMDS);
- if (flag.isPresent() && !Permissions
- .hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
- List blocked_cmds = flag.get();
- String c = parts[0];
- if (parts[0].contains(":")) {
- c = parts[0].split(":")[1];
- msg = msg.replace(parts[0].split(":")[0] + ':', "");
- }
- String l = c;
- List aliases = new ArrayList<>();
- for (HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) {
- if (c.equals(cmdLabel.getName())) {
- break;
- }
- String label = cmdLabel.getName().replaceFirst("/", "");
- if (aliases.contains(label)) {
- continue;
- }
- PluginCommand p;
- if ((p = Bukkit.getPluginCommand(label)) != null) {
- for (String a : p.getAliases()) {
- if (aliases.contains(a)) {
- continue;
- }
- aliases.add(a);
- a = a.replaceFirst("/", "");
- if (!a.equals(label) && a.equals(c)) {
- c = label;
- break;
- }
- }
- }
- }
- if (!l.equals(c)) {
- msg = msg.replace(l, c);
- }
- for (String s : blocked_cmds) {
- Pattern pattern;
- if (!RegExUtil.compiledPatterns.containsKey(s)) {
- RegExUtil.compiledPatterns.put(s, pattern = Pattern.compile(s));
- } else {
- pattern = RegExUtil.compiledPatterns.get(s);
- }
- if (pattern.matcher(msg).matches()) {
- String perm;
- if (plot.isAdded(pp.getUUID())) {
- perm = "plots.admin.command.blocked-cmds.shared";
- } else {
- perm = "plots.admin.command.blocked-cmds.other";
- }
- if (!Permissions.hasPermission(pp, perm)) {
- MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
- event.setCancelled(true);
- }
- return;
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
- public void onConnect(PlayerJoinEvent event) {
- final Player player = event.getPlayer();
- UUIDHandler.getPlayers().remove(player.getName());
- BukkitUtil.removePlayer(player.getName());
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Now
- String name = pp.getName();
- StringWrapper sw = new StringWrapper(name);
- UUID uuid = pp.getUUID();
- UUIDHandler.add(sw, uuid);
-
- Location loc = pp.getLocation();
- PlotArea area = loc.getPlotArea();
- if (area != null) {
- Plot plot = area.getPlot(loc);
- if (plot != null) {
- plotEntry(pp, plot);
- }
- }
- // Delayed
-
- // Async
- TaskManager.runTaskLaterAsync(() -> {
- if (!player.hasPlayedBefore() && player.isOnline()) {
- player.saveData();
- }
- EventUtil.manager.doJoinTask(pp);
- }, 20);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void playerRespawn(PlayerRespawnEvent event) {
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- EventUtil.manager.doRespawnTask(pp);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onTeleport(PlayerTeleportEvent event) {
- if (event.getTo() == null || event.getFrom() == null || !event.getFrom().getWorld()
- .equals(event.getTo().getWorld())) {
- final Object lastLoc = BukkitUtil.getPlayer(event.getPlayer())
- .deleteMeta(PlotPlayer.META_LOCATION);
- final Object lastPlot = BukkitUtil.getPlayer(event.getPlayer())
- .deleteMeta(PlotPlayer.META_LAST_PLOT);
- org.bukkit.Location to = event.getTo();
- if (to != null) {
- Player player = event.getPlayer();
- PlotPlayer pp = PlotPlayer.wrap(player);
- Location loc = BukkitUtil.getLocation(to);
- PlotArea area = PlotSquared.get().getPlotAreaAbs(loc);
- if (area == null) {
- return;
+ return true;
}
Plot plot = area.getPlot(loc);
- if (plot != null) {
- final boolean result = Flags.DENY_TELEPORT.allowsTeleport(pp, plot);
- if (!result) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- event.setCancelled(true);
- if (lastLoc != null) {
- pp.setMeta(PlotPlayer.META_LOCATION, lastLoc);
- }
- if (lastPlot != null) {
- pp.setMeta(PlotPlayer.META_LAST_PLOT, lastPlot);
- }
- } else {
- plotEntry(pp, plot);
- }
- }
- }
- return;
- }
- playerMove(event);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
- final org.bukkit.Location from = event.getFrom();
- final org.bukkit.Location to = event.getTo();
-
- int toX, toZ;
- if ((toX = MathMan.roundInt(to.getX())) != MathMan.roundInt(from.getX())
- | (toZ = MathMan.roundInt(to.getZ())) != MathMan.roundInt(from.getZ())) {
- Vehicle vehicle = event.getVehicle();
-
- // Check allowed
- if (!vehicle.getPassengers().isEmpty()) {
- Entity passenger = vehicle.getPassengers().get(0);
-
- if (passenger instanceof Player) {
- final Player player = (Player) passenger;
- // reset
- if (moveTmp == null) {
- moveTmp = new PlayerMoveEvent(null, from, to);
- }
- moveTmp.setFrom(from);
- moveTmp.setTo(to);
- moveTmp.setCancelled(false);
- fieldPlayer.set(moveTmp, player);
-
- List passengers = vehicle.getPassengers();
-
- this.playerMove(moveTmp);
- org.bukkit.Location dest;
- if (moveTmp.isCancelled()) {
- dest = from;
- } else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
- || MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
- dest = to;
- } else {
- dest = null;
- }
- if (dest != null) {
- if (passengers != null) {
- vehicle.eject();
- vehicle.setVelocity(new Vector(0d, 0d, 0d));
- vehicle.teleport(dest);
- passengers.forEach(vehicle::addPassenger);
- } else {
- vehicle.eject();
- vehicle.setVelocity(new Vector(0d, 0d, 0d));
- vehicle.teleport(dest);
- vehicle.addPassenger(player);
- }
- return;
- }
- }
- if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
- switch (vehicle.getType()) {
- case BOAT:
- case ENDER_CRYSTAL:
- case MINECART:
- case MINECART_CHEST:
- case MINECART_COMMAND:
- case MINECART_FURNACE:
- case MINECART_HOPPER:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT: {
- List meta = vehicle.getMetadata("plot");
- Plot toPlot = BukkitUtil.getLocation(to).getPlot();
- if (!meta.isEmpty()) {
- Plot origin = (Plot) meta.get(0).value();
- if (!origin.getBasePlot(false).equals(toPlot)) {
- vehicle.remove();
+ ProjectileSource shooter = entity.getShooter();
+ if (shooter instanceof Player) {
+ PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) {
+ entity.remove();
+ return false;
}
- } else if (toPlot != null) {
- vehicle.setMetadata("plot",
- new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
- }
+ return true;
}
- }
- }
- }
-
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void playerMove(PlayerMoveEvent event) {
- org.bukkit.Location from = event.getFrom();
- org.bukkit.Location to = event.getTo();
- int x2;
- if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Cancel teleport
- TaskManager.TELEPORT_QUEUE.remove(pp.getName());
- // Set last location
- Location loc = BukkitUtil.getLocation(to);
- pp.setMeta(PlotPlayer.META_LOCATION, loc);
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
- return;
- }
- Plot now = area.getPlot(loc);
- Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
- if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
- .getMeta("kick", false)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
- this.tmpTeleport = false;
- if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
- player.teleport(from);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
- }
- this.tmpTeleport = true;
- event.setCancelled(true);
- return;
- }
- } else if (now.equals(lastPlot)) {
- ForceFieldListener.handleForcefield(player, pp, now);
- return;
- } else if (!plotEntry(pp, now) && this.tmpTeleport) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- this.tmpTeleport = false;
- to.setX(from.getBlockX());
- to.setY(from.getBlockY());
- to.setZ(from.getBlockZ());
- player.teleport(event.getTo());
- this.tmpTeleport = true;
- return;
- }
- int border = area.getBorder();
- if (x2 > border && this.tmpTeleport) {
- to.setX(x2 - 1);
- this.tmpTeleport = false;
- player.teleport(event.getTo());
- this.tmpTeleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- return;
- }
- if (x2 < -border && this.tmpTeleport) {
- to.setX(x2 + 1);
- this.tmpTeleport = false;
- player.teleport(event.getTo());
- this.tmpTeleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- return;
- }
- return;
- }
- int z2;
- if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Cancel teleport
- TaskManager.TELEPORT_QUEUE.remove(pp.getName());
- // Set last location
- Location loc = BukkitUtil.getLocation(to);
- pp.setMeta(PlotPlayer.META_LOCATION, loc);
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
- return;
- }
- Plot now = area.getPlot(loc);
- Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
- if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
- .getMeta("kick", false)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
- this.tmpTeleport = false;
- if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
- player.teleport(from);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
- }
- this.tmpTeleport = true;
- event.setCancelled(true);
- return;
- }
- } else if (now.equals(lastPlot)) {
- ForceFieldListener.handleForcefield(player, pp, now);
- return;
- } else if (!plotEntry(pp, now) && this.tmpTeleport) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- this.tmpTeleport = false;
- player.teleport(from);
- to.setX(from.getBlockX());
- to.setY(from.getBlockY());
- to.setZ(from.getBlockZ());
- player.teleport(event.getTo());
- this.tmpTeleport = true;
- return;
- }
- int border = area.getBorder();
- if (z2 > border && this.tmpTeleport) {
- to.setZ(z2 - 1);
- this.tmpTeleport = false;
- player.teleport(event.getTo());
- this.tmpTeleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- } else if (z2 < -border && this.tmpTeleport) {
- to.setZ(z2 + 1);
- this.tmpTeleport = false;
- player.teleport(event.getTo());
- this.tmpTeleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.LOW)
- public void onChat(AsyncPlayerChatEvent event) {
- if (event.isCancelled()) {
- return;
- }
-
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
- Location location = plotPlayer.getLocation();
- PlotArea area = location.getPlotArea();
- if (area == null || (area.PLOT_CHAT == plotPlayer.getAttribute("chat"))) {
- return;
- }
- Plot plot = area.getPlot(location);
- if (plot == null) {
- return;
- }
- event.setCancelled(true);
- String message = event.getMessage();
- String format = C.PLOT_CHAT_FORMAT.s();
- String sender = event.getPlayer().getDisplayName();
- PlotId id = plot.getId();
- Set recipients = event.getRecipients();
- Set spies = new HashSet<>();
- recipients.clear();
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer pp = entry.getValue();
- if (pp.getAttribute("chatspy")) {
- spies.add(((BukkitPlayer) pp).player);
- } else {
- Plot current = pp.getCurrentPlot();
- if (current != null && current.getBasePlot(false).equals(plot)) {
- recipients.add(((BukkitPlayer) pp).player);
- }
- }
- }
- String partial = ChatColor.translateAlternateColorCodes('&',
- format.replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender));
- if (plotPlayer.hasPermission("plots.chat.color")) {
- message = C.color(message);
- }
- String full = partial.replace("%msg%", message);
- for (Player receiver : recipients) {
- receiver.sendMessage(full);
- }
- if (!spies.isEmpty()) {
- String spyMessage = C.PLOT_CHAT_SPY_FORMAT.s().replace("%plot_id%", id.x + ";" + id.y)
- .replace("%sender%", sender).replace("%msg%", message);
- for (Player player : spies) {
- player.sendMessage(spyMessage);
- }
- }
- PlotSquared.debug(full);
- }
-
- @EventHandler(priority = EventPriority.LOWEST)
- public void blockDestroy(BlockBreakEvent event) {
- Player player = event.getPlayer();
- Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getPlot(location);
- if (plot != null) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (event.getBlock().getY() == 0) {
- if (!Permissions
- .hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- C.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL);
- event.setCancelled(true);
- return;
- }
- } else if (
- (location.getY() > area.MAX_BUILD_HEIGHT || location.getY() < area.MIN_BUILD_HEIGHT)
- && !Permissions
- .hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) {
- event.setCancelled(true);
- MainUtil.sendMessage(plotPlayer,
- C.HEIGHT_LIMIT.s().replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
- }
- if (!plot.hasOwner()) {
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
- return;
- }
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- C.PERMISSION_ADMIN_DESTROY_UNOWNED);
- event.setCancelled(true);
- return;
- }
- if (!plot.isAdded(plotPlayer.getUUID())) {
- Optional> destroy = plot.getFlag(Flags.BREAK);
- Block block = event.getBlock();
- if (destroy.isPresent() && destroy.get()
- .contains(PlotBlock.get(block.getType().name()))) {
- return;
- }
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- return;
- }
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- C.PERMISSION_ADMIN_DESTROY_OTHER);
- event.setCancelled(true);
- } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
- if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- return;
- }
- }
- return;
- }
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
- return;
- }
- if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
- if (player.getInventory().getItemInMainHand().getType() == Material
- .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
- return;
- }
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
- event.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBigBoom(EntityExplodeEvent event) {
- Location location = BukkitUtil.getLocation(event.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
- return;
- }
- Iterator iterator = event.blockList().iterator();
- while (iterator.hasNext()) {
- iterator.next();
- if (location.getPlotArea() != null) {
- iterator.remove();
- }
- }
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot != null) {
- if (Flags.EXPLOSION.isTrue(plot)) {
- List meta = event.getEntity().getMetadata("plot");
- Plot origin;
- if (meta.isEmpty()) {
- origin = plot;
- } else {
- origin = (Plot) meta.get(0).value();
- }
- if (this.lastRadius != 0) {
- List nearby = event.getEntity()
- .getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
- for (Entity near : nearby) {
- if (near instanceof TNTPrimed || near.getType()
- .equals(EntityType.MINECART_TNT)) {
- if (!near.hasMetadata("plot")) {
- near.setMetadata("plot",
- new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
- }
+ if (plot.isAdded(pp.getUUID()) || Permissions
+ .hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) {
+ return true;
}
- }
- this.lastRadius = 0;
+ entity.remove();
+ return false;
}
- Iterator iterator = event.blockList().iterator();
- while (iterator.hasNext()) {
- Block block = iterator.next();
- location = BukkitUtil.getLocation(block.getLocation());
- if (!area.contains(location.getX(), location.getZ()) || !origin
- .equals(area.getOwnedPlot(location))) {
- iterator.remove();
- }
+ if (!(shooter instanceof Entity) && shooter != null) {
+ if (plot == null) {
+ entity.remove();
+ return false;
+ }
+ Location sLoc =
+ BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
+ if (!area.contains(sLoc.getX(), sLoc.getZ())) {
+ entity.remove();
+ return false;
+ }
+ Plot sPlot = area.getOwnedPlotAbs(sLoc);
+ if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
+ entity.remove();
+ return false;
+ }
}
- return;
- }
+ return true;
}
- event.setCancelled(true);
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onWorldChanged(PlayerChangedWorldEvent event) {
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Delete last location
- pp.deleteMeta(PlotPlayer.META_LOCATION);
- Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
- if (plot != null) {
- plotExit(pp, plot);
- }
- if (PlotSquared.get().worldedit != null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
- if (pp.getAttribute("worldedit")) {
- pp.removeAttribute("worldedit");
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+ public void playerCommand(PlayerCommandPreprocessEvent event) {
+ String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim();
+ if (msg.isEmpty()) {
+ return;
+ }
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ Location loc = pp.getLocation();
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ String[] parts = msg.split(" ");
+ Plot plot = pp.getCurrentPlot();
+ if (BukkitMain.getWorldEdit() != null) { // Check WorldEdit
+ switch (parts[0].toLowerCase()) {
+ case "up":
+ case "/up":
+ case "worldedit:up":
+ case "worldedit:/up":
+ if (plot == null || (!plot.isAdded(pp.getUUID()) && !Permissions
+ .hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER, true))) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+ if (plot == null) {
+ return;
+ }
+ Optional> flag = plot.getFlag(Flags.BLOCKED_CMDS);
+ if (flag.isPresent() && !Permissions
+ .hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
+ List blocked_cmds = flag.get();
+ String c = parts[0];
+ if (parts[0].contains(":")) {
+ c = parts[0].split(":")[1];
+ msg = msg.replace(parts[0].split(":")[0] + ':', "");
+ }
+ String l = c;
+ List aliases = new ArrayList<>();
+ for (HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) {
+ if (c.equals(cmdLabel.getName())) {
+ break;
+ }
+ String label = cmdLabel.getName().replaceFirst("/", "");
+ if (aliases.contains(label)) {
+ continue;
+ }
+ PluginCommand p;
+ if ((p = Bukkit.getPluginCommand(label)) != null) {
+ for (String a : p.getAliases()) {
+ if (aliases.contains(a)) {
+ continue;
+ }
+ aliases.add(a);
+ a = a.replaceFirst("/", "");
+ if (!a.equals(label) && a.equals(c)) {
+ c = label;
+ break;
+ }
+ }
+ }
+ }
+ if (!l.equals(c)) {
+ msg = msg.replace(l, c);
+ }
+ for (String s : blocked_cmds) {
+ Pattern pattern;
+ if (!RegExUtil.compiledPatterns.containsKey(s)) {
+ RegExUtil.compiledPatterns.put(s, pattern = Pattern.compile(s));
+ } else {
+ pattern = RegExUtil.compiledPatterns.get(s);
+ }
+ if (pattern.matcher(msg).matches()) {
+ String perm;
+ if (plot.isAdded(pp.getUUID())) {
+ perm = "plots.admin.command.blocked-cmds.shared";
+ } else {
+ perm = "plots.admin.command.blocked-cmds.other";
+ }
+ if (!Permissions.hasPermission(pp, perm)) {
+ MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
+ event.setCancelled(true);
+ }
+ return;
+ }
+ }
}
- }
}
- if (Settings.Enabled_Components.PERMISSION_CACHE) {
- pp.deleteMeta("perm");
- }
- Location loc = pp.getLocation();
- PlotArea area = PlotSquared.get().getPlotAreaAbs(loc);
- if (area == null) {
- return;
- }
- plot = area.getPlot(loc);
- if (plot != null) {
- plotEntry(pp, plot);
- }
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
- Entity e = event.getEntity();
- if (!(e instanceof FallingBlock)) {
- Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = location.getPlotArea();
- if (area != null) {
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
+ public void onConnect(PlayerJoinEvent event) {
+ final Player player = event.getPlayer();
+ UUIDHandler.getPlayers().remove(player.getName());
+ BukkitUtil.removePlayer(player.getName());
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ // Now
+ String name = pp.getName();
+ StringWrapper sw = new StringWrapper(name);
+ UUID uuid = pp.getUUID();
+ UUIDHandler.add(sw, uuid);
+
+ Location loc = pp.getLocation();
+ PlotArea area = loc.getPlotArea();
+ if (area != null) {
+ Plot plot = area.getPlot(loc);
+ if (plot != null) {
+ plotEntry(pp, plot);
+ }
+ }
+ // Delayed
+
+ // Async
+ TaskManager.runTaskLaterAsync(() -> {
+ if (!player.hasPlayedBefore() && player.isOnline()) {
+ player.saveData();
+ }
+ EventUtil.manager.doJoinTask(pp);
+ }, 20);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void playerRespawn(PlayerRespawnEvent event) {
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ EventUtil.manager.doRespawnTask(pp);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onTeleport(PlayerTeleportEvent event) {
+ if (event.getTo() == null || event.getFrom() == null || !event.getFrom().getWorld()
+ .equals(event.getTo().getWorld())) {
+ final Object lastLoc =
+ BukkitUtil.getPlayer(event.getPlayer()).deleteMeta(PlotPlayer.META_LOCATION);
+ final Object lastPlot =
+ BukkitUtil.getPlayer(event.getPlayer()).deleteMeta(PlotPlayer.META_LAST_PLOT);
+ org.bukkit.Location to = event.getTo();
+ if (to != null) {
+ Player player = event.getPlayer();
+ PlotPlayer pp = PlotPlayer.wrap(player);
+ Location loc = BukkitUtil.getLocation(to);
+ PlotArea area = PlotSquared.get().getPlotAreaAbs(loc);
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getPlot(loc);
+ if (plot != null) {
+ final boolean result = Flags.DENY_TELEPORT.allowsTeleport(pp, plot);
+ if (!result) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_ENTRY_DENIED);
+ event.setCancelled(true);
+ if (lastLoc != null) {
+ pp.setMeta(PlotPlayer.META_LOCATION, lastLoc);
+ }
+ if (lastPlot != null) {
+ pp.setMeta(PlotPlayer.META_LAST_PLOT, lastPlot);
+ }
+ } else {
+ plotEntry(pp, plot);
+ }
+ }
+ }
+ return;
+ }
+ playerMove(event);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
+ final org.bukkit.Location from = event.getFrom();
+ final org.bukkit.Location to = event.getTo();
+
+ int toX, toZ;
+ if ((toX = MathMan.roundInt(to.getX())) != MathMan.roundInt(from.getX())
+ | (toZ = MathMan.roundInt(to.getZ())) != MathMan.roundInt(from.getZ())) {
+ Vehicle vehicle = event.getVehicle();
+
+ // Check allowed
+ if (!vehicle.getPassengers().isEmpty()) {
+ Entity passenger = vehicle.getPassengers().get(0);
+
+ if (passenger instanceof Player) {
+ final Player player = (Player) passenger;
+ // reset
+ if (moveTmp == null) {
+ moveTmp = new PlayerMoveEvent(null, from, to);
+ }
+ moveTmp.setFrom(from);
+ moveTmp.setTo(to);
+ moveTmp.setCancelled(false);
+ fieldPlayer.set(moveTmp, player);
+
+ List passengers = vehicle.getPassengers();
+
+ this.playerMove(moveTmp);
+ org.bukkit.Location dest;
+ if (moveTmp.isCancelled()) {
+ dest = from;
+ } else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
+ || MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
+ dest = to;
+ } else {
+ dest = null;
+ }
+ if (dest != null) {
+ if (passengers != null) {
+ vehicle.eject();
+ vehicle.setVelocity(new Vector(0d, 0d, 0d));
+ vehicle.teleport(dest);
+ passengers.forEach(vehicle::addPassenger);
+ } else {
+ vehicle.eject();
+ vehicle.setVelocity(new Vector(0d, 0d, 0d));
+ vehicle.teleport(dest);
+ vehicle.addPassenger(player);
+ }
+ return;
+ }
+ }
+ if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
+ switch (vehicle.getType()) {
+ case BOAT:
+ case ENDER_CRYSTAL:
+ case MINECART:
+ case MINECART_CHEST:
+ case MINECART_COMMAND:
+ case MINECART_FURNACE:
+ case MINECART_HOPPER:
+ case MINECART_MOB_SPAWNER:
+ case MINECART_TNT: {
+ List meta = vehicle.getMetadata("plot");
+ Plot toPlot = BukkitUtil.getLocation(to).getPlot();
+ if (!meta.isEmpty()) {
+ Plot origin = (Plot) meta.get(0).value();
+ if (!origin.getBasePlot(false).equals(toPlot)) {
+ vehicle.remove();
+ }
+ } else if (toPlot != null) {
+ vehicle.setMetadata("plot",
+ new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
+ }
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void playerMove(PlayerMoveEvent event) {
+ org.bukkit.Location from = event.getFrom();
+ org.bukkit.Location to = event.getTo();
+ int x2;
+ if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ // Cancel teleport
+ TaskManager.TELEPORT_QUEUE.remove(pp.getName());
+ // Set last location
+ Location loc = BukkitUtil.getLocation(to);
+ pp.setMeta(PlotPlayer.META_LOCATION, loc);
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
+ return;
+ }
+ Plot now = area.getPlot(loc);
+ Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
+ if (now == null) {
+ if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
+ .getMeta("kick", false)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
+ this.tmpTeleport = false;
+ if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
+ player.teleport(from);
+ } else {
+ player.teleport(player.getWorld().getSpawnLocation());
+ }
+ this.tmpTeleport = true;
+ event.setCancelled(true);
+ return;
+ }
+ } else if (now.equals(lastPlot)) {
+ ForceFieldListener.handleForcefield(player, pp, now);
+ return;
+ } else if (!plotEntry(pp, now) && this.tmpTeleport) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
+ this.tmpTeleport = false;
+ to.setX(from.getBlockX());
+ to.setY(from.getBlockY());
+ to.setZ(from.getBlockZ());
+ player.teleport(event.getTo());
+ this.tmpTeleport = true;
+ return;
+ }
+ int border = area.getBorder();
+ if (x2 > border && this.tmpTeleport) {
+ to.setX(x2 - 1);
+ this.tmpTeleport = false;
+ player.teleport(event.getTo());
+ this.tmpTeleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ return;
+ }
+ if (x2 < -border && this.tmpTeleport) {
+ to.setX(x2 + 1);
+ this.tmpTeleport = false;
+ player.teleport(event.getTo());
+ this.tmpTeleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ return;
+ }
+ return;
+ }
+ int z2;
+ if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ // Cancel teleport
+ TaskManager.TELEPORT_QUEUE.remove(pp.getName());
+ // Set last location
+ Location loc = BukkitUtil.getLocation(to);
+ pp.setMeta(PlotPlayer.META_LOCATION, loc);
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
+ return;
+ }
+ Plot now = area.getPlot(loc);
+ Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
+ if (now == null) {
+ if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
+ .getMeta("kick", false)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
+ this.tmpTeleport = false;
+ if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
+ player.teleport(from);
+ } else {
+ player.teleport(player.getWorld().getSpawnLocation());
+ }
+ this.tmpTeleport = true;
+ event.setCancelled(true);
+ return;
+ }
+ } else if (now.equals(lastPlot)) {
+ ForceFieldListener.handleForcefield(player, pp, now);
+ return;
+ } else if (!plotEntry(pp, now) && this.tmpTeleport) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
+ this.tmpTeleport = false;
+ player.teleport(from);
+ to.setX(from.getBlockX());
+ to.setY(from.getBlockY());
+ to.setZ(from.getBlockZ());
+ player.teleport(event.getTo());
+ this.tmpTeleport = true;
+ return;
+ }
+ int border = area.getBorder();
+ if (z2 > border && this.tmpTeleport) {
+ to.setZ(z2 - 1);
+ this.tmpTeleport = false;
+ player.teleport(event.getTo());
+ this.tmpTeleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ } else if (z2 < -border && this.tmpTeleport) {
+ to.setZ(z2 + 1);
+ this.tmpTeleport = false;
+ player.teleport(event.getTo());
+ this.tmpTeleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW) public void onChat(AsyncPlayerChatEvent event) {
+ if (event.isCancelled()) {
+ return;
+ }
+
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
+ Location location = plotPlayer.getLocation();
+ PlotArea area = location.getPlotArea();
+ if (area == null || (area.PLOT_CHAT == plotPlayer.getAttribute("chat"))) {
+ return;
+ }
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ return;
+ }
+ event.setCancelled(true);
+ String message = event.getMessage();
+ String format = C.PLOT_CHAT_FORMAT.s();
+ String sender = event.getPlayer().getDisplayName();
+ PlotId id = plot.getId();
+ Set recipients = event.getRecipients();
+ Set spies = new HashSet<>();
+ recipients.clear();
+ for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
+ PlotPlayer pp = entry.getValue();
+ if (pp.getAttribute("chatspy")) {
+ spies.add(((BukkitPlayer) pp).player);
+ } else {
+ Plot current = pp.getCurrentPlot();
+ if (current != null && current.getBasePlot(false).equals(plot)) {
+ recipients.add(((BukkitPlayer) pp).player);
+ }
+ }
+ }
+ String partial = ChatColor.translateAlternateColorCodes('&',
+ format.replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender));
+ if (plotPlayer.hasPermission("plots.chat.color")) {
+ message = C.color(message);
+ }
+ String full = partial.replace("%msg%", message);
+ for (Player receiver : recipients) {
+ receiver.sendMessage(full);
+ }
+ if (!spies.isEmpty()) {
+ String spyMessage = C.PLOT_CHAT_SPY_FORMAT.s().replace("%plot_id%", id.x + ";" + id.y)
+ .replace("%sender%", sender).replace("%msg%", message);
+ for (Player player : spies) {
+ player.sendMessage(spyMessage);
+ }
+ }
+ PlotSquared.debug(full);
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) {
+ Player player = event.getPlayer();
+ Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getPlot(location);
+ if (plot != null) {
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (event.getBlock().getY() == 0) {
+ if (!Permissions
+ .hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL);
+ event.setCancelled(true);
+ return;
+ }
+ } else if (
+ (location.getY() > area.MAX_BUILD_HEIGHT || location.getY() < area.MIN_BUILD_HEIGHT)
+ && !Permissions
+ .hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) {
+ event.setCancelled(true);
+ MainUtil.sendMessage(plotPlayer,
+ C.HEIGHT_LIMIT.s().replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
+ }
+ if (!plot.hasOwner()) {
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
+ return;
+ }
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_DESTROY_UNOWNED);
+ event.setCancelled(true);
+ return;
+ }
+ if (!plot.isAdded(plotPlayer.getUUID())) {
+ Optional> destroy = plot.getFlag(Flags.BREAK);
+ Block block = event.getBlock();
+ if (destroy.isPresent() && destroy.get()
+ .contains(PlotBlock.get(block.getType().name()))) {
+ return;
+ }
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ return;
+ }
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_DESTROY_OTHER);
+ event.setCancelled(true);
+ } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
+ if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ return;
+ }
+ }
+ return;
+ }
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
+ return;
+ }
+ if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
+ if (player.getInventory().getItemInMainHand().getType() == Material
+ .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
+ return;
+ }
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
+ event.setCancelled(true);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBigBoom(EntityExplodeEvent event) {
+ Location location = BukkitUtil.getLocation(event.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ return;
+ }
+ Iterator iterator = event.blockList().iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ if (location.getPlotArea() != null) {
+ iterator.remove();
+ }
+ }
+ return;
+ }
Plot plot = area.getOwnedPlot(location);
- if (plot != null && Flags.MOB_BREAK.isTrue(plot)) {
- return;
- }
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onEntityBlockForm(EntityBlockFormEvent event) {
- String world = event.getBlock().getWorld().getName();
- if (!PlotSquared.get().hasPlotArea(world)) {
- return;
- }
- Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot == null) {
- event.setCancelled(true);
- return;
- }
- Entity entity = event.getEntity();
- if (entity instanceof Player) {
- Player player = (Player) entity;
- if (!plot.hasOwner()) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (Flags.ICE_FORM.isTrue(plot)) {
- return;
- }
- event.setCancelled(true);
- return;
- }
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (!plot.isAdded(plotPlayer.getUUID())) {
- if (Flags.ICE_FORM.isTrue(plot)) {
- return;
- }
- event.setCancelled(true);
- return;
- }
- return;
- }
- if (!Flags.ICE_FORM.isTrue(plot)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockSpread(BlockSpreadEvent event) {
- Block block = event.getBlock();
- Location location = BukkitUtil.getLocation(block.getLocation());
- if (location.isPlotRoad()) {
- event.setCancelled(true);
- return;
- }
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot == null) {
- return;
- }
- switch (event.getSource().getType()) {
- case GRASS:
- if (Flags.GRASS_GROW.isFalse(plot)) {
- event.setCancelled(true);
- }
- break;
- case MYCELIUM:
- if (Flags.MYCEL_GROW.isFalse(plot)) {
- event.setCancelled(true);
- }
- break;
- case VINE:
- if (Flags.VINE_GROW.isFalse(plot)) {
- event.setCancelled(true);
- }
- break;
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockForm(BlockFormEvent event) {
- Block block = event.getBlock();
- Location location = BukkitUtil.getLocation(block.getLocation());
- if (location.isPlotRoad()) {
- event.setCancelled(true);
- return;
- }
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot == null) {
- return;
- }
- switch (event.getNewState().getType()) {
- case SNOW:
- case SNOW_BLOCK:
- if (Flags.SNOW_FORM.isFalse(plot)) {
- event.setCancelled(true);
- }
- return;
- case ICE:
- case FROSTED_ICE:
- case PACKED_ICE:
- if (Flags.ICE_FORM.isFalse(plot)) {
- event.setCancelled(true);
- }
- return;
- case STONE:
- case OBSIDIAN:
- case COBBLESTONE:
- // TODO event ?
- return;
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockDamage(BlockDamageEvent event) {
- Player player = event.getPlayer();
- Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
- if (player == null) {
- if (location.isPlotRoad()) {
- event.setCancelled(true);
- return;
- }
- }
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getPlot(location);
- if (plot != null) {
- if (location.getY() == 0) {
- event.setCancelled(true);
- return;
- }
- if (!plot.hasOwner()) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
- return;
- }
- event.setCancelled(true);
- return;
- }
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (!plot.isAdded(plotPlayer.getUUID())) {
- Optional> destroy = plot.getFlag(Flags.BREAK);
- Block block = event.getBlock();
- if (destroy.isPresent() && destroy.get()
- .contains(PlotBlock.get(block.getType().name())) || Permissions
- .hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- return;
- }
- event.setCancelled(true);
- return;
- }
- return;
- }
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
- return;
- }
- event.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onFade(BlockFadeEvent event) {
- Block b = event.getBlock();
- Location location = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot == null) {
- event.setCancelled(true);
- return;
- }
- switch (b.getType()) {
- case ICE:
- if (Flags.ICE_MELT.isFalse(plot)) {
- event.setCancelled(true);
- }
- break;
- case SNOW:
- if (Flags.SNOW_MELT.isFalse(plot)) {
- event.setCancelled(true);
- }
- break;
- case FARMLAND:
- if (Flags.SOIL_DRY.isFalse(plot)) {
- event.setCancelled(true);
- }
- break;
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onChange(BlockFromToEvent event) {
- Block from = event.getBlock();
- Block to = event.getToBlock();
- Location tLocation = BukkitUtil.getLocation(to.getLocation());
- PlotArea area = tLocation.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(tLocation);
- Location fLocation = BukkitUtil.getLocation(from.getLocation());
- if (plot != null) {
- if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
- event.setCancelled(true);
- return;
- } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
- .equals(plot, area.getOwnedPlot(fLocation))) {
- event.setCancelled(true);
- return;
- }
- if (Flags.LIQUID_FLOW.isFalse(plot)) {
- switch (to.getType()) {
- case WATER:
- case LAVA:
- event.setCancelled(true);
- }
- }
- } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
- .equals(null, area.getOwnedPlot(fLocation))) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onGrow(BlockGrowEvent event) {
- Block b = event.getBlock();
- Location location = BukkitUtil.getLocation(b.getLocation());
- if (location.isUnownedPlotArea()) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockPistonExtend(BlockPistonExtendEvent event) {
- Block block = event.getBlock();
- Location location = BukkitUtil.getLocation(block.getLocation());
- BlockFace face = event.getDirection();
- Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
- return;
- }
- for (Block b : event.getBlocks()) {
- if (BukkitUtil.getLocation(b.getLocation().add(relative)).getPlotArea() != null) {
- event.setCancelled(true);
- return;
- }
- }
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot == null) {
- event.setCancelled(true);
- return;
- }
- List blocks = event.getBlocks();
- for (Block b : blocks) {
- Location bloc = BukkitUtil.getLocation(b.getLocation());
- if (!area.contains(bloc.getX(), bloc.getZ()) || !area
- .contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
- event.setCancelled(true);
- return;
- }
- if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot(
- bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
- event.setCancelled(true);
- return;
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockPistonRetract(BlockPistonRetractEvent event) {
- Block block = event.getBlock();
- Location location = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
- return;
- }
- if (this.pistonBlocks) {
- try {
- for (Block pulled : event.getBlocks()) {
- location = BukkitUtil.getLocation(pulled.getLocation());
- if (location.getPlotArea() != null) {
- event.setCancelled(true);
- return;
+ if (plot != null) {
+ if (Flags.EXPLOSION.isTrue(plot)) {
+ List meta = event.getEntity().getMetadata("plot");
+ Plot origin;
+ if (meta.isEmpty()) {
+ origin = plot;
+ } else {
+ origin = (Plot) meta.get(0).value();
+ }
+ if (this.lastRadius != 0) {
+ List nearby = event.getEntity()
+ .getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
+ for (Entity near : nearby) {
+ if (near instanceof TNTPrimed || near.getType()
+ .equals(EntityType.MINECART_TNT)) {
+ if (!near.hasMetadata("plot")) {
+ near.setMetadata("plot",
+ new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
+ }
+ }
+ }
+ this.lastRadius = 0;
+ }
+ Iterator iterator = event.blockList().iterator();
+ while (iterator.hasNext()) {
+ Block block = iterator.next();
+ location = BukkitUtil.getLocation(block.getLocation());
+ if (!area.contains(location.getX(), location.getZ()) || !origin
+ .equals(area.getOwnedPlot(location))) {
+ iterator.remove();
+ }
+ }
+ return;
}
- }
- } catch (Throwable ignored) {
- this.pistonBlocks = false;
}
- }
- if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
- BlockFace dir = event.getDirection();
- location = BukkitUtil.getLocation(block.getLocation()
- .add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
- if (location.getPlotArea() != null) {
- event.setCancelled(true);
- return;
- }
- }
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- BlockFace dir = event.getDirection();
- // Location head = location.add(-dir.getModX(), -dir.getModY(), -dir.getModZ());
- //
- // if (!Objects.equals(plot, area.getOwnedPlot(head))) {
- // // FIXME: cancelling the event doesn't work here. See issue #1484
- // event.setCancelled(true);
- // return;
- // }
- if (this.pistonBlocks) {
- try {
- for (Block pulled : event.getBlocks()) {
- Location from = BukkitUtil.getLocation(
- pulled.getLocation().add(dir.getModX(), dir.getModY(), dir.getModZ()));
- Location to = BukkitUtil.getLocation(pulled.getLocation());
- if (!area.contains(to.getX(), to.getZ())) {
- event.setCancelled(true);
- return;
- }
- Plot fromPlot = area.getOwnedPlot(from);
- Plot toPlot = area.getOwnedPlot(to);
- if (!Objects.equals(fromPlot, toPlot)) {
- event.setCancelled(true);
- return;
- }
- }
- } catch (Throwable ignored) {
- this.pistonBlocks = false;
- }
- }
- if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
- location = BukkitUtil.getLocation(
- block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
- if (!area.contains(location)) {
event.setCancelled(true);
- return;
- }
- Plot newPlot = area.getOwnedPlot(location);
- if (!Objects.equals(plot, newPlot)) {
- event.setCancelled(true);
- }
}
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockDispense(BlockDispenseEvent event) {
- Material type = event.getItem().getType();
- switch (type) {
- case WATER_BUCKET:
- case LAVA_BUCKET: {
- if (event.getBlock().getType() == Material.DROPPER) {
- return;
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onWorldChanged(PlayerChangedWorldEvent event) {
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ // Delete last location
+ pp.deleteMeta(PlotPlayer.META_LOCATION);
+ Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
+ if (plot != null) {
+ plotExit(pp, plot);
}
- BlockFace targetFace =
- ((Directional) event.getBlock().getState().getData()).getFacing();
- Location location =
- BukkitUtil.getLocation(event.getBlock().getRelative(targetFace).getLocation());
+ if (PlotSquared.get().worldedit != null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
+ if (pp.getAttribute("worldedit")) {
+ pp.removeAttribute("worldedit");
+ }
+ }
+ }
+ if (Settings.Enabled_Components.PERMISSION_CACHE) {
+ pp.deleteMeta("perm");
+ }
+ Location loc = pp.getLocation();
+ PlotArea area = PlotSquared.get().getPlotAreaAbs(loc);
+ if (area == null) {
+ return;
+ }
+ plot = area.getPlot(loc);
+ if (plot != null) {
+ plotEntry(pp, plot);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
+ Entity e = event.getEntity();
+ if (!(e instanceof FallingBlock)) {
+ Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area != null) {
+ Plot plot = area.getOwnedPlot(location);
+ if (plot != null && Flags.MOB_BREAK.isTrue(plot)) {
+ return;
+ }
+ event.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onEntityBlockForm(EntityBlockFormEvent event) {
+ String world = event.getBlock().getWorld().getName();
+ if (!PlotSquared.get().hasPlotArea(world)) {
+ return;
+ }
+ Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ if (plot == null) {
+ event.setCancelled(true);
+ return;
+ }
+ Entity entity = event.getEntity();
+ if (entity instanceof Player) {
+ Player player = (Player) entity;
+ if (!plot.hasOwner()) {
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (Flags.ICE_FORM.isTrue(plot)) {
+ return;
+ }
+ event.setCancelled(true);
+ return;
+ }
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (!plot.isAdded(plotPlayer.getUUID())) {
+ if (Flags.ICE_FORM.isTrue(plot)) {
+ return;
+ }
+ event.setCancelled(true);
+ return;
+ }
+ return;
+ }
+ if (!Flags.ICE_FORM.isTrue(plot)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockSpread(BlockSpreadEvent event) {
+ Block block = event.getBlock();
+ Location location = BukkitUtil.getLocation(block.getLocation());
if (location.isPlotRoad()) {
- event.setCancelled(true);
+ event.setCancelled(true);
+ return;
}
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onStructureGrow(StructureGrowEvent event) {
- if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) {
- return;
- }
- List blocks = event.getBlocks();
- if (blocks.isEmpty()) {
- return;
- }
- Location location = BukkitUtil.getLocation(blocks.get(0).getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- for (int i = blocks.size() - 1; i >= 0; i--) {
- location = BukkitUtil.getLocation(blocks.get(i).getLocation());
- if (location.getPlotArea() != null) {
- blocks.remove(i);
- }
- }
- return;
- } else {
- Plot origin = area.getOwnedPlot(location);
- if (origin == null) {
- event.setCancelled(true);
- return;
- }
- for (int i = blocks.size() - 1; i >= 0; i--) {
- location = BukkitUtil.getLocation(blocks.get(i).getLocation());
- if (!area.contains(location.getX(), location.getZ())) {
- blocks.remove(i);
- continue;
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
}
Plot plot = area.getOwnedPlot(location);
- if (!Objects.equals(plot, origin)) {
- event.getBlocks().remove(i);
+ if (plot == null) {
+ return;
+ }
+ switch (event.getSource().getType()) {
+ case GRASS:
+ if (Flags.GRASS_GROW.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ break;
+ case MYCELIUM:
+ if (Flags.MYCEL_GROW.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ break;
+ case VINE:
+ if (Flags.VINE_GROW.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ break;
}
- }
}
- Plot origin = area.getPlot(location);
- if (origin == null) {
- event.setCancelled(true);
- return;
- }
- for (int i = blocks.size() - 1; i >= 0; i--) {
- location = BukkitUtil.getLocation(blocks.get(i).getLocation());
- Plot plot = area.getOwnedPlot(location);
- /*
- * plot -> the base plot of the merged area
- * origin -> the plot where the event gets called
- */
- // Are plot and origin not the same AND are both plots merged
- if (!Objects.equals(plot, origin) && (!plot.isMerged() && !origin.isMerged())) {
- event.getBlocks().remove(i);
- }
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockForm(BlockFormEvent event) {
+ Block block = event.getBlock();
+ Location location = BukkitUtil.getLocation(block.getLocation());
+ if (location.isPlotRoad()) {
+ event.setCancelled(true);
+ return;
+ }
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ if (plot == null) {
+ return;
+ }
+ switch (event.getNewState().getType()) {
+ case SNOW:
+ case SNOW_BLOCK:
+ if (Flags.SNOW_FORM.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ return;
+ case ICE:
+ case FROSTED_ICE:
+ case PACKED_ICE:
+ if (Flags.ICE_FORM.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ return;
+ case STONE:
+ case OBSIDIAN:
+ case COBBLESTONE:
+ // TODO event ?
+ return;
+ }
}
- }
- @SuppressWarnings("deprecation")
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onInventoryClick(InventoryClickEvent event) {
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockDamage(BlockDamageEvent event) {
+ Player player = event.getPlayer();
+ Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
+ if (player == null) {
+ if (location.isPlotRoad()) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getPlot(location);
+ if (plot != null) {
+ if (location.getY() == 0) {
+ event.setCancelled(true);
+ return;
+ }
+ if (!plot.hasOwner()) {
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
+ return;
+ }
+ event.setCancelled(true);
+ return;
+ }
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (!plot.isAdded(plotPlayer.getUUID())) {
+ Optional> destroy = plot.getFlag(Flags.BREAK);
+ Block block = event.getBlock();
+ if (destroy.isPresent() && destroy.get()
+ .contains(PlotBlock.get(block.getType().name())) || Permissions
+ .hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ return;
+ }
+ event.setCancelled(true);
+ return;
+ }
+ return;
+ }
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
+ return;
+ }
+ event.setCancelled(true);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onFade(BlockFadeEvent event) {
+ Block b = event.getBlock();
+ Location location = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ if (plot == null) {
+ event.setCancelled(true);
+ return;
+ }
+ switch (b.getType()) {
+ case ICE:
+ if (Flags.ICE_MELT.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ break;
+ case SNOW:
+ if (Flags.SNOW_MELT.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ break;
+ case FARMLAND:
+ if (Flags.SOIL_DRY.isFalse(plot)) {
+ event.setCancelled(true);
+ }
+ break;
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onChange(BlockFromToEvent event) {
+ Block from = event.getBlock();
+ Block to = event.getToBlock();
+ Location tLocation = BukkitUtil.getLocation(to.getLocation());
+ PlotArea area = tLocation.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlot(tLocation);
+ Location fLocation = BukkitUtil.getLocation(from.getLocation());
+ if (plot != null) {
+ if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
+ event.setCancelled(true);
+ return;
+ } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
+ .equals(plot, area.getOwnedPlot(fLocation))) {
+ event.setCancelled(true);
+ return;
+ }
+ if (Flags.LIQUID_FLOW.isFalse(plot)) {
+ switch (to.getType()) {
+ case WATER:
+ case LAVA:
+ event.setCancelled(true);
+ }
+ }
+ } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
+ .equals(null, area.getOwnedPlot(fLocation))) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onGrow(BlockGrowEvent event) {
+ Block b = event.getBlock();
+ Location location = BukkitUtil.getLocation(b.getLocation());
+ if (location.isUnownedPlotArea()) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
+ Block block = event.getBlock();
+ Location location = BukkitUtil.getLocation(block.getLocation());
+ BlockFace face = event.getDirection();
+ Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ return;
+ }
+ for (Block b : event.getBlocks()) {
+ if (BukkitUtil.getLocation(b.getLocation().add(relative)).getPlotArea() != null) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ return;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ if (plot == null) {
+ event.setCancelled(true);
+ return;
+ }
+ List blocks = event.getBlocks();
+ for (Block b : blocks) {
+ Location bloc = BukkitUtil.getLocation(b.getLocation());
+ if (!area.contains(bloc.getX(), bloc.getZ()) || !area
+ .contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
+ event.setCancelled(true);
+ return;
+ }
+ if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot(
+ bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
+ Block block = event.getBlock();
+ Location location = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ return;
+ }
+ if (this.pistonBlocks) {
+ try {
+ for (Block pulled : event.getBlocks()) {
+ location = BukkitUtil.getLocation(pulled.getLocation());
+ if (location.getPlotArea() != null) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ } catch (Throwable ignored) {
+ this.pistonBlocks = false;
+ }
+ }
+ if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
+ BlockFace dir = event.getDirection();
+ location = BukkitUtil.getLocation(block.getLocation()
+ .add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
+ if (location.getPlotArea() != null) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ return;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ BlockFace dir = event.getDirection();
+ // Location head = location.add(-dir.getModX(), -dir.getModY(), -dir.getModZ());
+ //
+ // if (!Objects.equals(plot, area.getOwnedPlot(head))) {
+ // // FIXME: cancelling the event doesn't work here. See issue #1484
+ // event.setCancelled(true);
+ // return;
+ // }
+ if (this.pistonBlocks) {
+ try {
+ for (Block pulled : event.getBlocks()) {
+ Location from = BukkitUtil.getLocation(
+ pulled.getLocation().add(dir.getModX(), dir.getModY(), dir.getModZ()));
+ Location to = BukkitUtil.getLocation(pulled.getLocation());
+ if (!area.contains(to.getX(), to.getZ())) {
+ event.setCancelled(true);
+ return;
+ }
+ Plot fromPlot = area.getOwnedPlot(from);
+ Plot toPlot = area.getOwnedPlot(to);
+ if (!Objects.equals(fromPlot, toPlot)) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ } catch (Throwable ignored) {
+ this.pistonBlocks = false;
+ }
+ }
+ if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
+ location = BukkitUtil.getLocation(
+ block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
+ if (!area.contains(location)) {
+ event.setCancelled(true);
+ return;
+ }
+ Plot newPlot = area.getOwnedPlot(location);
+ if (!Objects.equals(plot, newPlot)) {
+ event.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockDispense(BlockDispenseEvent event) {
+ Material type = event.getItem().getType();
+ switch (type) {
+ case WATER_BUCKET:
+ case LAVA_BUCKET: {
+ if (event.getBlock().getType() == Material.DROPPER) {
+ return;
+ }
+ BlockFace targetFace =
+ ((Directional) event.getBlock().getState().getData()).getFacing();
+ Location location =
+ BukkitUtil.getLocation(event.getBlock().getRelative(targetFace).getLocation());
+ if (location.isPlotRoad()) {
+ event.setCancelled(true);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onStructureGrow(StructureGrowEvent event) {
+ if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) {
+ return;
+ }
+ List blocks = event.getBlocks();
+ if (blocks.isEmpty()) {
+ return;
+ }
+ Location location = BukkitUtil.getLocation(blocks.get(0).getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ for (int i = blocks.size() - 1; i >= 0; i--) {
+ location = BukkitUtil.getLocation(blocks.get(i).getLocation());
+ if (location.getPlotArea() != null) {
+ blocks.remove(i);
+ }
+ }
+ return;
+ } else {
+ Plot origin = area.getOwnedPlot(location);
+ if (origin == null) {
+ event.setCancelled(true);
+ return;
+ }
+ for (int i = blocks.size() - 1; i >= 0; i--) {
+ location = BukkitUtil.getLocation(blocks.get(i).getLocation());
+ if (!area.contains(location.getX(), location.getZ())) {
+ blocks.remove(i);
+ continue;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ if (!Objects.equals(plot, origin)) {
+ event.getBlocks().remove(i);
+ }
+ }
+ }
+ Plot origin = area.getPlot(location);
+ if (origin == null) {
+ event.setCancelled(true);
+ return;
+ }
+ for (int i = blocks.size() - 1; i >= 0; i--) {
+ location = BukkitUtil.getLocation(blocks.get(i).getLocation());
+ Plot plot = area.getOwnedPlot(location);
+ /*
+ * plot -> the base plot of the merged area
+ * origin -> the plot where the event gets called
+ */
+
+ // Are plot and origin not the same AND are both plots merged
+ if (!Objects.equals(plot, origin) && (!plot.isMerged() && !origin.isMerged())) {
+ event.getBlocks().remove(i);
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onInventoryClick(InventoryClickEvent event) {
/*if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
.isShiftClick()) {
return;
}*/
- HumanEntity entity = event.getWhoClicked();
- if (!(entity instanceof Player) || !PlotSquared.get()
- .hasPlotArea(entity.getWorld().getName())) {
- return;
- }
-
- HumanEntity clicker = event.getWhoClicked();
- if (!(clicker instanceof Player)) {
- return;
- }
- Player player = (Player) clicker;
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp);
- if (inventory != null && event.getRawSlot() == event.getSlot()) {
- if (!inventory.onClick(event.getSlot())) {
- event.setResult(Event.Result.DENY);
- event.setCancelled(true);
- inventory.close();
- }
- }
- PlayerInventory inv = player.getInventory();
- int slot = inv.getHeldItemSlot();
- if ((slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
- return;
- }
- ItemStack current = inv.getItemInHand();
- ItemStack newItem = event.getCursor();
- ItemMeta newMeta = newItem.getItemMeta();
- ItemMeta oldMeta = newItem.getItemMeta();
- String newLore = "";
- if (newMeta != null) {
- List lore = newMeta.getLore();
- if (lore != null) {
- newLore = lore.toString();
- }
- }
- String oldLore = "";
- if (oldMeta != null) {
- List lore = oldMeta.getLore();
- if (lore != null) {
- oldLore = lore.toString();
- }
- }
- if (!"[(+NBT)]".equals(newLore) || (current.equals(newItem) && newLore.equals(oldLore))) {
- switch (newItem.getType()) {
- case LEGACY_BANNER:
- case PLAYER_HEAD:
- if (newMeta != null) {
- break;
- }
- default:
- return;
- }
- }
- Block block = player.getTargetBlock(null, 7);
- BlockState state = block.getState();
- if (state == null) {
- return;
- }
- Material stateType = state.getType();
- Material itemType = newItem.getType();
- if (stateType != itemType) {
- switch (stateType) {
- case LEGACY_STANDING_BANNER:
- case LEGACY_WALL_BANNER:
- if (itemType == Material.LEGACY_BANNER) {
- break;
- }
- case LEGACY_SKULL:
- if (itemType == Material.LEGACY_SKULL_ITEM) {
- break;
- }
- default:
- return;
- }
- }
- Location l = BukkitUtil.getLocation(state.getLocation());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getPlotAbs(l);
- boolean cancelled = false;
- if (plot == null) {
- if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
- cancelled = true;
- }
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
- cancelled = true;
- }
- } else {
- UUID uuid = pp.getUUID();
- if (!plot.isAdded(uuid)) {
- if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
- cancelled = true;
+ HumanEntity entity = event.getWhoClicked();
+ if (!(entity instanceof Player) || !PlotSquared.get()
+ .hasPlotArea(entity.getWorld().getName())) {
+ return;
}
- }
- }
- if (cancelled) {
- if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
- .getDurability())) {
- event.setCursor(
- new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
- event.setCancelled(true);
- return;
- }
- event.setCursor(
- new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
- }
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPotionSplash(LingeringPotionSplashEvent event) {
- LingeringPotion entity = event.getEntity();
- Location l = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
- return;
- }
- if (!this.onProjectileHit(event)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onInteract(PlayerInteractAtEntityEvent e) {
- Entity entity = e.getRightClicked();
- if (!(entity instanceof ArmorStand)) {
- return;
- }
- Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
-
- EntitySpawnListener.test(entity);
-
- Plot plot = area.getPlotAbs(l);
- PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
- if (plot == null) {
- if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
- e.setCancelled(true);
- }
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
- e.setCancelled(true);
- }
- } else {
- UUID uuid = pp.getUUID();
- if (!plot.isAdded(uuid)) {
- if (Flags.MISC_INTERACT.isTrue(plot)) {
- return;
+ HumanEntity clicker = event.getWhoClicked();
+ if (!(clicker instanceof Player)) {
+ return;
}
- if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
- e.setCancelled(true);
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBigBoom(BlockExplodeEvent event) {
- Block block = event.getBlock();
- Location location = BukkitUtil.getLocation(block.getLocation());
- String world = location.getWorld();
- if (!PlotSquared.get().hasPlotArea(world)) {
- return;
- }
- PlotArea area = location.getPlotArea();
- if (area == null) {
- Iterator iterator = event.blockList().iterator();
- while (iterator.hasNext()) {
- location = BukkitUtil.getLocation(iterator.next().getLocation());
- if (location.getPlotArea() != null) {
- iterator.remove();
- }
- }
- return;
- }
- Plot plot = area.getOwnedPlot(location);
- if (plot == null || !plot.getFlag(Flags.EXPLOSION).orElse(false)) {
- event.setCancelled(true);
- }
- event.blockList().removeIf(
- b -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation()))));
- }
-
- @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
- public void onInteract(PlayerInteractEvent event) {
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- PlotArea area = pp.getPlotAreaAbs();
- if (area == null) {
- return;
- }
- PlayerBlockEventType eventType = null;
- BukkitLazyBlock lb;
- Location location;
- Action action = event.getAction();
- switch (action) {
- case PHYSICAL: {
- eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
- Block block = event.getClickedBlock();
- lb = new BukkitLazyBlock(block);
- location = BukkitUtil.getLocation(block.getLocation());
- break;
- }
- case RIGHT_CLICK_BLOCK: {
- Block block = event.getClickedBlock();
- location = BukkitUtil.getLocation(block.getLocation());
- Material blockType = block.getType();
- switch (blockType) {
- case ACACIA_DOOR:
- case BIRCH_DOOR:
- case DARK_OAK_DOOR:
- case IRON_DOOR:
- case JUNGLE_DOOR:
- case OAK_DOOR:
- case SPRUCE_DOOR:
-
- case ACACIA_TRAPDOOR:
- case BIRCH_TRAPDOOR:
- case DARK_OAK_TRAPDOOR:
- case IRON_TRAPDOOR:
- case JUNGLE_TRAPDOOR:
- case OAK_TRAPDOOR:
- case SPRUCE_TRAPDOOR:
-
- case CHEST:
- case ENDER_CHEST:
- case TRAPPED_CHEST:
-
- case ACACIA_FENCE_GATE:
- case BIRCH_FENCE_GATE:
- case DARK_OAK_FENCE_GATE:
- case OAK_FENCE_GATE:
- case JUNGLE_FENCE_GATE:
- case SPRUCE_FENCE_GATE:
-
- case ACACIA_BUTTON:
- case BIRCH_BUTTON:
- case DARK_OAK_BUTTON:
- case JUNGLE_BUTTON:
- case OAK_BUTTON:
- case SPRUCE_BUTTON:
- case STONE_BUTTON:
-
- case BLACK_BED:
- case BLUE_BED:
- case BROWN_BED:
- case CYAN_BED:
- case GRAY_BED:
- case GREEN_BED:
- case LIGHT_BLUE_BED:
- case LIGHT_GRAY_BED:
- case LIME_BED:
- case MAGENTA_BED:
- case ORANGE_BED:
- case PINK_BED:
- case PURPLE_BED:
- case RED_BED:
- case WHITE_BED:
- case YELLOW_BED:
-
- case BLACK_BANNER:
- case BLACK_WALL_BANNER:
- case BLUE_BANNER:
- case BLUE_WALL_BANNER:
- case BROWN_BANNER:
- case BROWN_WALL_BANNER:
- case CYAN_BANNER:
- case CYAN_WALL_BANNER:
- case GRAY_BANNER:
- case GRAY_WALL_BANNER:
- case GREEN_BANNER:
- case GREEN_WALL_BANNER:
- case LIGHT_BLUE_BANNER:
- case LIGHT_BLUE_WALL_BANNER:
- case LIGHT_GRAY_BANNER:
- case LIGHT_GRAY_WALL_BANNER:
- case LIME_BANNER:
- case LIME_WALL_BANNER:
- case MAGENTA_BANNER:
- case MAGENTA_WALL_BANNER:
- case ORANGE_BANNER:
- case ORANGE_WALL_BANNER:
- case PINK_BANNER:
- case PINK_WALL_BANNER:
- case PURPLE_BANNER:
- case PURPLE_WALL_BANNER:
- case RED_BANNER:
- case RED_WALL_BANNER:
- case WHITE_BANNER:
- case WHITE_WALL_BANNER:
- case YELLOW_BANNER:
- case YELLOW_WALL_BANNER:
-
- case BLACK_SHULKER_BOX:
- case BLUE_SHULKER_BOX:
- case BROWN_SHULKER_BOX:
- case CYAN_SHULKER_BOX:
- case GRAY_SHULKER_BOX:
- case GREEN_SHULKER_BOX:
- case LIGHT_BLUE_SHULKER_BOX:
- case LIGHT_GRAY_SHULKER_BOX:
- case LIME_SHULKER_BOX:
- case MAGENTA_SHULKER_BOX:
- case ORANGE_SHULKER_BOX:
- case PINK_SHULKER_BOX:
- case PURPLE_SHULKER_BOX:
- case RED_SHULKER_BOX:
- case WHITE_SHULKER_BOX:
- case YELLOW_SHULKER_BOX:
-
- case CHAIN_COMMAND_BLOCK:
- case REPEATING_COMMAND_BLOCK:
-
- case SIGN:
- case WALL_SIGN:
-
- case REDSTONE_TORCH:
- case REDSTONE_WALL_TORCH:
-
- case TURTLE_EGG:
- case TURTLE_HELMET:
- case TURTLE_SPAWN_EGG:
-
- case ANVIL:
- case BEACON:
- case BREWING_STAND:
- case CAKE:
- case COMMAND_BLOCK:
- case COMPARATOR:
- case CRAFTING_TABLE:
- case DISPENSER:
- case DROPPER:
- case ENCHANTING_TABLE:
- case FURNACE:
- case HOPPER:
- case JUKEBOX:
- case LEVER:
- case NOTE_BLOCK:
- case REDSTONE_ORE:
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
- break;
- case DRAGON_EGG:
- eventType = PlayerBlockEventType.TELEPORT_OBJECT;
- break;
- default:
- int blockId = ((LegacyPlotBlock) PlotSquared.get().IMP.getLegacyMappings()
- .fromStringToLegacy(blockType.name())).id;
- if (blockId > 197) {
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ Player player = (Player) clicker;
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp);
+ if (inventory != null && event.getRawSlot() == event.getSlot()) {
+ if (!inventory.onClick(event.getSlot())) {
+ event.setResult(Event.Result.DENY);
+ event.setCancelled(true);
+ inventory.close();
}
- break;
}
- lb = new BukkitLazyBlock(PlotBlock.get(block.getType().toString()));
- ItemStack hand = player.getInventory().getItemInMainHand();
- if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK
- || !player.isSneaking())) {
- break;
+ PlayerInventory inv = player.getInventory();
+ int slot = inv.getHeldItemSlot();
+ if ((slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
+ return;
}
- Material type = (hand == null) ? null : hand.getType();
- if (type == Material.AIR) {
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
- break;
+ ItemStack current = inv.getItemInHand();
+ ItemStack newItem = event.getCursor();
+ ItemMeta newMeta = newItem.getItemMeta();
+ ItemMeta oldMeta = newItem.getItemMeta();
+ String newLore = "";
+ if (newMeta != null) {
+ List lore = newMeta.getLore();
+ if (lore != null) {
+ newLore = lore.toString();
+ }
}
- if (type == null || type.isBlock()) {
- location = BukkitUtil
- .getLocation(block.getRelative(event.getBlockFace()).getLocation());
- eventType = PlayerBlockEventType.PLACE_BLOCK;
- break;
+ String oldLore = "";
+ if (oldMeta != null) {
+ List lore = oldMeta.getLore();
+ if (lore != null) {
+ oldLore = lore.toString();
+ }
}
- Material handType = hand.getType();
- lb = new BukkitLazyBlock(PlotBlock.get(handType.toString()));
- if (handType.toString().endsWith("egg")) {
- eventType = PlayerBlockEventType.SPAWN_MOB;
+ if (!"[(+NBT)]".equals(newLore) || (current.equals(newItem) && newLore.equals(oldLore))) {
+ switch (newItem.getType()) {
+ case LEGACY_BANNER:
+ case PLAYER_HEAD:
+ if (newMeta != null) {
+ break;
+ }
+ default:
+ return;
+ }
+ }
+ Block block = player.getTargetBlock(null, 7);
+ BlockState state = block.getState();
+ if (state == null) {
+ return;
+ }
+ Material stateType = state.getType();
+ Material itemType = newItem.getType();
+ if (stateType != itemType) {
+ switch (stateType) {
+ case LEGACY_STANDING_BANNER:
+ case LEGACY_WALL_BANNER:
+ if (itemType == Material.LEGACY_BANNER) {
+ break;
+ }
+ case LEGACY_SKULL:
+ if (itemType == Material.LEGACY_SKULL_ITEM) {
+ break;
+ }
+ default:
+ return;
+ }
+ }
+ Location l = BukkitUtil.getLocation(state.getLocation());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getPlotAbs(l);
+ boolean cancelled = false;
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
+ cancelled = true;
+ }
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
+ cancelled = true;
+ }
} else {
- switch (handType) {
- case FIREWORK_ROCKET:
- case FIREWORK_STAR:
- eventType = PlayerBlockEventType.SPAWN_MOB;
- break;
- case ARMOR_STAND:
- location = BukkitUtil
- .getLocation(block.getRelative(event.getBlockFace()).getLocation());
- eventType = PlayerBlockEventType.PLACE_MISC;
- break;
- case BOOK:
- case ENCHANTED_BOOK:
- case KNOWLEDGE_BOOK:
- case WRITABLE_BOOK:
- case WRITTEN_BOOK:
- eventType = PlayerBlockEventType.READ;
- break;
- case APPLE:
- case BAKED_POTATO:
- case BEEF:
- case BREAD:
- case CARROT:
- case CHICKEN:
- case COD:
- case COOKED_BEEF:
- case COOKED_CHICKEN:
- case COOKED_COD:
- case COOKED_MUTTON:
- case COOKED_PORKCHOP:
- case COOKED_RABBIT:
- case COOKED_SALMON:
- case COOKIE:
- case GOLDEN_CARROT:
- case MUSHROOM_STEW:
- case MUTTON:
- case POISONOUS_POTATO:
- case PORKCHOP:
- case POTATO:
- case POTION:
- case PUFFERFISH:
- case PUMPKIN_PIE:
- case RABBIT:
- case RABBIT_FOOT:
- case RABBIT_STEW:
- case SALMON:
- case TROPICAL_FISH:
- eventType = PlayerBlockEventType.EAT;
- break;
- case ACACIA_BOAT:
- case BIRCH_BOAT:
- case CHEST_MINECART:
- case COMMAND_BLOCK_MINECART:
- case DARK_OAK_BOAT:
- case FURNACE_MINECART:
- case HOPPER_MINECART:
- case JUNGLE_BOAT:
- case MINECART:
- case OAK_BOAT:
- case SPRUCE_BOAT:
- case TNT_MINECART:
- eventType = PlayerBlockEventType.PLACE_VEHICLE;
- break;
- case ITEM_FRAME:
- case PAINTING:
- location = BukkitUtil
- .getLocation(block.getRelative(event.getBlockFace()).getLocation());
- eventType = PlayerBlockEventType.PLACE_HANGING;
- break;
- default:
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
- break;
- }
- }
- break;
- }
- case LEFT_CLICK_BLOCK:
- Block block = event.getClickedBlock();
- location = BukkitUtil.getLocation(block.getLocation());
- eventType = PlayerBlockEventType.BREAK_BLOCK;
- lb = new BukkitLazyBlock(block);
- break;
- default:
- return;
- }
- if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
- if (player.getInventory().getItemInMainHand().getType() == Material
- .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
- return;
- }
- }
- if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void creatureSpawnEvent(CreatureSpawnEvent event) {
- Entity entity = event.getEntity();
- Location location = BukkitUtil.getLocation(entity.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
- //TODO needs an overhaul for the increased number of spawn reasons added to this event.
- //I can't believe they waited so damn long to expand this API set.
- switch (reason) {
- case DISPENSE_EGG:
- case EGG:
- case OCELOT_BABY:
- case SPAWNER_EGG:
- if (!area.SPAWN_EGGS) {
- event.setCancelled(true);
- return;
- }
- break;
- case REINFORCEMENTS:
- case NATURAL:
- case CHUNK_GEN:
- if (!area.MOB_SPAWNING) {
- event.setCancelled(true);
- return;
- }
- case BREEDING:
- if (!area.SPAWN_BREEDING) {
- event.setCancelled(true);
- return;
- }
- break;
- case BUILD_IRONGOLEM:
- case BUILD_SNOWMAN:
- case BUILD_WITHER:
- case CUSTOM:
- if (!area.SPAWN_CUSTOM && entity.getType() != EntityType.ARMOR_STAND) {
- event.setCancelled(true);
- return;
- }
- break;
- case SPAWNER:
- if (!area.MOB_SPAWNER_SPAWNING) {
- event.setCancelled(true);
- return;
- }
- break;
- }
- Plot plot = area.getOwnedPlotAbs(location);
- if (plot == null) {
- if (!area.MOB_SPAWNING) {
- event.setCancelled(true);
- }
- return;
- }
- if (checkEntity(entity, plot)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void onEntityFall(EntityChangeBlockEvent event) {
- if (event.getEntityType() != EntityType.FALLING_BLOCK) {
- return;
- }
- Block block = event.getBlock();
- World world = block.getWorld();
- String worldName = world.getName();
- if (!PlotSquared.get().hasPlotArea(worldName)) {
- return;
- }
- Location location = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlotAbs(location);
- if (plot == null || plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
- event.setCancelled(true);
- return;
- }
- if (event.getTo().hasGravity()) {
- Entity entity = event.getEntity();
- List meta = entity.getMetadata("plot");
- if (meta.isEmpty()) {
- return;
- }
- Plot origin = (Plot) meta.get(0).value();
- if (origin != null && !origin.equals(plot)) {
- event.setCancelled(true);
- entity.remove();
- }
- } else if (event.getTo() == Material.AIR) {
- event.getEntity()
- .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
- }
- }
-
- @EventHandler
- public void onPrime(ExplosionPrimeEvent event) {
- this.lastRadius = event.getRadius() + 1;
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockBurn(BlockBurnEvent event) {
- Block b = event.getBlock();
- Location location = BukkitUtil.getLocation(b.getLocation());
-
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
-
- Plot plot = location.getOwnedPlot();
- if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) {
- event.setCancelled(true);
- return;
- }
-
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockIgnite(BlockIgniteEvent event) {
- Player player = event.getPlayer();
- Entity ignitingEntity = event.getIgnitingEntity();
- Block block = event.getBlock();
- BlockIgniteEvent.IgniteCause igniteCause = event.getCause();
- Location loc;
- if (block != null) {
- loc = BukkitUtil.getLocation(block.getLocation());
- } else if (ignitingEntity != null) {
- loc = BukkitUtil.getLocation(ignitingEntity);
- } else if (player != null) {
- loc = BukkitUtil.getLocation(player);
- } else {
- return;
- }
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- if (igniteCause == BlockIgniteEvent.IgniteCause.LIGHTNING) {
- event.setCancelled(true);
- return;
- }
-
- Plot plot = area.getOwnedPlotAbs(loc);
- if (player != null) {
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
- }
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
- event.setCancelled(true);
- }
- } else if (!plot.isAdded(pp.getUUID())) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- }
- } else if (Flags.BLOCK_IGNITION.isFalse(plot)) {
- event.setCancelled(true);
- }
- } else {
- if (plot == null) {
- event.setCancelled(true);
- return;
- }
- if (ignitingEntity != null) {
- if (!plot.getFlag(Flags.BLOCK_IGNITION, false)) {
- event.setCancelled(true);
- return;
- }
- if (igniteCause == BlockIgniteEvent.IgniteCause.FIREBALL) {
- if (ignitingEntity instanceof Fireball) {
- Projectile fireball = (Projectile) ignitingEntity;
- Location location = null;
- if (fireball.getShooter() instanceof Entity) {
- Entity shooter = (Entity) fireball.getShooter();
- location = BukkitUtil.getLocation(shooter.getLocation());
- } else if (fireball.getShooter() instanceof BlockProjectileSource) {
- Block shooter =
- ((BlockProjectileSource) fireball.getShooter()).getBlock();
- location = BukkitUtil.getLocation(shooter.getLocation());
+ UUID uuid = pp.getUUID();
+ if (!plot.isAdded(uuid)) {
+ if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
+ cancelled = true;
+ }
}
- if (location != null && !plot.equals(location.getPlot())) {
- event.setCancelled(true);
+ }
+ if (cancelled) {
+ if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
+ .getDurability())) {
+ event.setCursor(
+ new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
+ event.setCancelled(true);
+ return;
}
- }
+ event.setCursor(
+ new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
}
+ }
- } else if (event.getIgnitingBlock() != null) {
- Block ignitingBlock = event.getIgnitingBlock();
- Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot();
- if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (
- !plot.getFlag(Flags.BLOCK_IGNITION, false) || plotIgnited == null
- || !plotIgnited.equals(plot)) ||
- (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
- || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && (
- !plot.getFlag(Flags.BLOCK_IGNITION).orElse(false) || plotIgnited == null
- || !plotIgnited.equals(plot))) {
- event.setCancelled(true);
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPotionSplash(LingeringPotionSplashEvent event) {
+ LingeringPotion entity = event.getEntity();
+ Location l = BukkitUtil.getLocation(entity);
+ if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
+ return;
}
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBucketEmpty(PlayerBucketEmptyEvent event) {
- BlockFace bf = event.getBlockFace();
- Block b =
- event.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ())
- .getBlock();
- Location location = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
- Plot plot = area.getPlot(location);
- if (plot == null) {
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
- } else if (!plot.hasOwner()) {
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
- event.setCancelled(true);
- } else if (!plot.isAdded(pp.getUUID())) {
- if (Flags.USE.contains(plot, PlotBlock.get(event.getBucket().getId(), 0))) {
- return;
- }
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onInventoryClose(InventoryCloseEvent event) {
- HumanEntity closer = event.getPlayer();
- if (!(closer instanceof Player)) {
- return;
- }
- Player player = (Player) closer;
- PlotInventory.removePlotInventoryOpen(BukkitUtil.getPlayer(player));
- }
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void onLeave(PlayerQuitEvent event) {
- TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
- PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
- pp.unregister();
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBucketFill(PlayerBucketFillEvent event) {
- Block b = event.getBlockClicked();
- Location location = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Player player = event.getPlayer();
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- Plot plot = area.getPlot(location);
- if (plot == null) {
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- return;
- }
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
- } else if (!plot.hasOwner()) {
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- return;
- }
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
- event.setCancelled(true);
- } else if (!plot.isAdded(plotPlayer.getUUID())) {
- Optional> use = plot.getFlag(Flags.USE);
- Block block = event.getBlockClicked();
- if (use.isPresent() && use.get().contains(PlotBlock.get(block.getType().name()))) {
- return;
- }
- if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- return;
- }
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
- if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onVehicleCreate(VehicleCreateEvent event) {
- Vehicle entity = event.getVehicle();
- Location location = BukkitUtil.getLocation(entity);
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlotAbs(location);
- if (plot == null || checkEntity(entity, plot)) {
- entity.remove();
- return;
- }
- if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
- entity
- .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onHangingPlace(HangingPlaceEvent event) {
- Block b = event.getBlock().getRelative(event.getBlockFace());
- Location location = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Player p = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(p);
- Plot plot = area.getPlot(location);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
- }
- } else {
- if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
- event.setCancelled(true);
- }
- return;
- }
- if (!plot.isAdded(pp.getUUID())) {
- if (!plot.getFlag(Flags.HANGING_PLACE, false)) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ if (!this.onProjectileHit(event)) {
event.setCancelled(true);
- }
- return;
}
- }
- if (checkEntity(event.getEntity(), plot)) {
- event.setCancelled(true);
- }
-
}
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
- Entity remover = event.getRemover();
- if (remover instanceof Player) {
- Player p = (Player) remover;
- Location location = BukkitUtil.getLocation(event.getEntity());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- PlotPlayer pp = BukkitUtil.getPlayer(p);
- Plot plot = area.getPlot(location);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
- event.setCancelled(true);
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onInteract(PlayerInteractAtEntityEvent e) {
+ Entity entity = e.getRightClicked();
+ if (!(entity instanceof ArmorStand)) {
+ return;
}
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
- event.setCancelled(true);
+ Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
}
- } else if (!plot.isAdded(pp.getUUID())) {
- if (plot.getFlag(Flags.HANGING_BREAK, false)) {
- return;
+
+ EntitySpawnListener.test(entity);
+
+ Plot plot = area.getPlotAbs(l);
+ PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
+ e.setCancelled(true);
+ }
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
+ e.setCancelled(true);
+ }
+ } else {
+ UUID uuid = pp.getUUID();
+ if (!plot.isAdded(uuid)) {
+ if (Flags.MISC_INTERACT.isTrue(plot)) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
+ e.setCancelled(true);
+ }
+ }
}
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
- event.setCancelled(true);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBigBoom(BlockExplodeEvent event) {
+ Block block = event.getBlock();
+ Location location = BukkitUtil.getLocation(block.getLocation());
+ String world = location.getWorld();
+ if (!PlotSquared.get().hasPlotArea(world)) {
+ return;
}
- }
- } else if (remover instanceof Projectile) {
- Projectile p = (Projectile) remover;
- if (p.getShooter() instanceof Player) {
- Player shooter = (Player) p.getShooter();
- Location location = BukkitUtil.getLocation(event.getEntity());
PlotArea area = location.getPlotArea();
if (area == null) {
- return;
- }
- PlotPlayer player = BukkitUtil.getPlayer(shooter);
- Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity()));
- if (plot != null) {
- if (!plot.hasOwner()) {
- if (!Permissions
- .hasPermission(player, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
- MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT,
- C.PERMISSION_ADMIN_DESTROY_UNOWNED);
- event.setCancelled(true);
+ Iterator iterator = event.blockList().iterator();
+ while (iterator.hasNext()) {
+ location = BukkitUtil.getLocation(iterator.next().getLocation());
+ if (location.getPlotArea() != null) {
+ iterator.remove();
+ }
}
- } else if (!plot.isAdded(player.getUUID())) {
- if (!plot.getFlag(Flags.HANGING_BREAK, false)) {
- if (!Permissions
- .hasPermission(player, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT,
- C.PERMISSION_ADMIN_DESTROY_OTHER);
+ return;
+ }
+ Plot plot = area.getOwnedPlot(location);
+ if (plot == null || !plot.getFlag(Flags.EXPLOSION).orElse(false)) {
+ event.setCancelled(true);
+ }
+ event.blockList().removeIf(
+ b -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation()))));
+ }
+
+ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
+ public void onInteract(PlayerInteractEvent event) {
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ PlotArea area = pp.getPlotAreaAbs();
+ if (area == null) {
+ return;
+ }
+ PlayerBlockEventType eventType = null;
+ BukkitLazyBlock lb;
+ Location location;
+ Action action = event.getAction();
+ switch (action) {
+ case PHYSICAL: {
+ eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
+ Block block = event.getClickedBlock();
+ lb = new BukkitLazyBlock(block);
+ location = BukkitUtil.getLocation(block.getLocation());
+ break;
+ }
+ case RIGHT_CLICK_BLOCK: {
+ Block block = event.getClickedBlock();
+ location = BukkitUtil.getLocation(block.getLocation());
+ Material blockType = block.getType();
+ switch (blockType) {
+ case ACACIA_DOOR:
+ case BIRCH_DOOR:
+ case DARK_OAK_DOOR:
+ case IRON_DOOR:
+ case JUNGLE_DOOR:
+ case OAK_DOOR:
+ case SPRUCE_DOOR:
+
+ case ACACIA_TRAPDOOR:
+ case BIRCH_TRAPDOOR:
+ case DARK_OAK_TRAPDOOR:
+ case IRON_TRAPDOOR:
+ case JUNGLE_TRAPDOOR:
+ case OAK_TRAPDOOR:
+ case SPRUCE_TRAPDOOR:
+
+ case CHEST:
+ case ENDER_CHEST:
+ case TRAPPED_CHEST:
+
+ case ACACIA_FENCE_GATE:
+ case BIRCH_FENCE_GATE:
+ case DARK_OAK_FENCE_GATE:
+ case OAK_FENCE_GATE:
+ case JUNGLE_FENCE_GATE:
+ case SPRUCE_FENCE_GATE:
+
+ case ACACIA_BUTTON:
+ case BIRCH_BUTTON:
+ case DARK_OAK_BUTTON:
+ case JUNGLE_BUTTON:
+ case OAK_BUTTON:
+ case SPRUCE_BUTTON:
+ case STONE_BUTTON:
+
+ case BLACK_BED:
+ case BLUE_BED:
+ case BROWN_BED:
+ case CYAN_BED:
+ case GRAY_BED:
+ case GREEN_BED:
+ case LIGHT_BLUE_BED:
+ case LIGHT_GRAY_BED:
+ case LIME_BED:
+ case MAGENTA_BED:
+ case ORANGE_BED:
+ case PINK_BED:
+ case PURPLE_BED:
+ case RED_BED:
+ case WHITE_BED:
+ case YELLOW_BED:
+
+ case BLACK_BANNER:
+ case BLACK_WALL_BANNER:
+ case BLUE_BANNER:
+ case BLUE_WALL_BANNER:
+ case BROWN_BANNER:
+ case BROWN_WALL_BANNER:
+ case CYAN_BANNER:
+ case CYAN_WALL_BANNER:
+ case GRAY_BANNER:
+ case GRAY_WALL_BANNER:
+ case GREEN_BANNER:
+ case GREEN_WALL_BANNER:
+ case LIGHT_BLUE_BANNER:
+ case LIGHT_BLUE_WALL_BANNER:
+ case LIGHT_GRAY_BANNER:
+ case LIGHT_GRAY_WALL_BANNER:
+ case LIME_BANNER:
+ case LIME_WALL_BANNER:
+ case MAGENTA_BANNER:
+ case MAGENTA_WALL_BANNER:
+ case ORANGE_BANNER:
+ case ORANGE_WALL_BANNER:
+ case PINK_BANNER:
+ case PINK_WALL_BANNER:
+ case PURPLE_BANNER:
+ case PURPLE_WALL_BANNER:
+ case RED_BANNER:
+ case RED_WALL_BANNER:
+ case WHITE_BANNER:
+ case WHITE_WALL_BANNER:
+ case YELLOW_BANNER:
+ case YELLOW_WALL_BANNER:
+
+ case BLACK_SHULKER_BOX:
+ case BLUE_SHULKER_BOX:
+ case BROWN_SHULKER_BOX:
+ case CYAN_SHULKER_BOX:
+ case GRAY_SHULKER_BOX:
+ case GREEN_SHULKER_BOX:
+ case LIGHT_BLUE_SHULKER_BOX:
+ case LIGHT_GRAY_SHULKER_BOX:
+ case LIME_SHULKER_BOX:
+ case MAGENTA_SHULKER_BOX:
+ case ORANGE_SHULKER_BOX:
+ case PINK_SHULKER_BOX:
+ case PURPLE_SHULKER_BOX:
+ case RED_SHULKER_BOX:
+ case WHITE_SHULKER_BOX:
+ case YELLOW_SHULKER_BOX:
+
+ case CHAIN_COMMAND_BLOCK:
+ case REPEATING_COMMAND_BLOCK:
+
+ case SIGN:
+ case WALL_SIGN:
+
+ case REDSTONE_TORCH:
+ case REDSTONE_WALL_TORCH:
+
+ case TURTLE_EGG:
+ case TURTLE_HELMET:
+ case TURTLE_SPAWN_EGG:
+
+ case ANVIL:
+ case BEACON:
+ case BREWING_STAND:
+ case CAKE:
+ case COMMAND_BLOCK:
+ case COMPARATOR:
+ case CRAFTING_TABLE:
+ case DISPENSER:
+ case DROPPER:
+ case ENCHANTING_TABLE:
+ case FURNACE:
+ case HOPPER:
+ case JUKEBOX:
+ case LEVER:
+ case NOTE_BLOCK:
+ case REDSTONE_ORE:
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ break;
+ case DRAGON_EGG:
+ eventType = PlayerBlockEventType.TELEPORT_OBJECT;
+ break;
+ default:
+ int blockId = ((LegacyPlotBlock) PlotSquared.get().IMP.getLegacyMappings()
+ .fromStringToLegacy(blockType.name())).id;
+ if (blockId > 197) {
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ }
+ break;
+ }
+ lb = new BukkitLazyBlock(PlotBlock.get(block.getType().toString()));
+ ItemStack hand = player.getInventory().getItemInMainHand();
+ if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK
+ || !player.isSneaking())) {
+ break;
+ }
+ Material type = (hand == null) ? null : hand.getType();
+ if (type == Material.AIR) {
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ break;
+ }
+ if (type == null || type.isBlock()) {
+ location = BukkitUtil
+ .getLocation(block.getRelative(event.getBlockFace()).getLocation());
+ eventType = PlayerBlockEventType.PLACE_BLOCK;
+ break;
+ }
+ Material handType = hand.getType();
+ lb = new BukkitLazyBlock(PlotBlock.get(handType.toString()));
+ if (handType.toString().endsWith("egg")) {
+ eventType = PlayerBlockEventType.SPAWN_MOB;
+ } else {
+ switch (handType) {
+ case FIREWORK_ROCKET:
+ case FIREWORK_STAR:
+ eventType = PlayerBlockEventType.SPAWN_MOB;
+ break;
+ case ARMOR_STAND:
+ location = BukkitUtil
+ .getLocation(block.getRelative(event.getBlockFace()).getLocation());
+ eventType = PlayerBlockEventType.PLACE_MISC;
+ break;
+ case BOOK:
+ case ENCHANTED_BOOK:
+ case KNOWLEDGE_BOOK:
+ case WRITABLE_BOOK:
+ case WRITTEN_BOOK:
+ eventType = PlayerBlockEventType.READ;
+ break;
+ case APPLE:
+ case BAKED_POTATO:
+ case BEEF:
+ case BREAD:
+ case CARROT:
+ case CHICKEN:
+ case COD:
+ case COOKED_BEEF:
+ case COOKED_CHICKEN:
+ case COOKED_COD:
+ case COOKED_MUTTON:
+ case COOKED_PORKCHOP:
+ case COOKED_RABBIT:
+ case COOKED_SALMON:
+ case COOKIE:
+ case GOLDEN_CARROT:
+ case MUSHROOM_STEW:
+ case MUTTON:
+ case POISONOUS_POTATO:
+ case PORKCHOP:
+ case POTATO:
+ case POTION:
+ case PUFFERFISH:
+ case PUMPKIN_PIE:
+ case RABBIT:
+ case RABBIT_FOOT:
+ case RABBIT_STEW:
+ case SALMON:
+ case TROPICAL_FISH:
+ eventType = PlayerBlockEventType.EAT;
+ break;
+ case ACACIA_BOAT:
+ case BIRCH_BOAT:
+ case CHEST_MINECART:
+ case COMMAND_BLOCK_MINECART:
+ case DARK_OAK_BOAT:
+ case FURNACE_MINECART:
+ case HOPPER_MINECART:
+ case JUNGLE_BOAT:
+ case MINECART:
+ case OAK_BOAT:
+ case SPRUCE_BOAT:
+ case TNT_MINECART:
+ eventType = PlayerBlockEventType.PLACE_VEHICLE;
+ break;
+ case ITEM_FRAME:
+ case PAINTING:
+ location = BukkitUtil
+ .getLocation(block.getRelative(event.getBlockFace()).getLocation());
+ eventType = PlayerBlockEventType.PLACE_HANGING;
+ break;
+ default:
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ break;
+ }
+ }
+ break;
+ }
+ case LEFT_CLICK_BLOCK:
+ Block block = event.getClickedBlock();
+ location = BukkitUtil.getLocation(block.getLocation());
+ eventType = PlayerBlockEventType.BREAK_BLOCK;
+ lb = new BukkitLazyBlock(block);
+ break;
+ default:
+ return;
+ }
+ if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
+ if (player.getInventory().getItemInMainHand().getType() == Material
+ .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
+ return;
+ }
+ }
+ if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void creatureSpawnEvent(CreatureSpawnEvent event) {
+ Entity entity = event.getEntity();
+ Location location = BukkitUtil.getLocation(entity.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
+ //TODO needs an overhaul for the increased number of spawn reasons added to this event.
+ //I can't believe they waited so damn long to expand this API set.
+ switch (reason) {
+ case DISPENSE_EGG:
+ case EGG:
+ case OCELOT_BABY:
+ case SPAWNER_EGG:
+ if (!area.SPAWN_EGGS) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ case REINFORCEMENTS:
+ case NATURAL:
+ case CHUNK_GEN:
+ if (!area.MOB_SPAWNING) {
+ event.setCancelled(true);
+ return;
+ }
+ case BREEDING:
+ if (!area.SPAWN_BREEDING) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ case BUILD_IRONGOLEM:
+ case BUILD_SNOWMAN:
+ case BUILD_WITHER:
+ case CUSTOM:
+ if (!area.SPAWN_CUSTOM && entity.getType() != EntityType.ARMOR_STAND) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ case SPAWNER:
+ if (!area.MOB_SPAWNER_SPAWNING) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ }
+ Plot plot = area.getOwnedPlotAbs(location);
+ if (plot == null) {
+ if (!area.MOB_SPAWNING) {
event.setCancelled(true);
- }
}
- }
+ return;
}
- }
- } else {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
- Location location = BukkitUtil.getLocation(event.getRightClicked().getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Player p = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(p);
- Plot plot = area.getPlot(location);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_ROAD);
- event.setCancelled(true);
- }
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED);
- event.setCancelled(true);
- }
- } else if (!plot.isAdded(pp.getUUID())) {
- Entity entity = event.getRightClicked();
- if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT, false)) {
- return;
- }
- if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT, false)) {
- return;
- }
- if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot
- .getFlag(Flags.TAMED_INTERACT, false)) {
- return;
- }
- if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE, false)) {
- return;
- }
- if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT, false)) {
- return;
- }
- if (entity instanceof Villager && plot.getFlag(Flags.VILLAGER_INTERACT, false)) {
- return;
- }
- if (entity instanceof ItemFrame && plot.getFlag(Flags.MISC_INTERACT, false)) {
- return;
- }
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onVehicleDestroy(VehicleDestroyEvent event) {
- Location l = BukkitUtil.getLocation(event.getVehicle());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- Entity d = event.getAttacker();
- if (d instanceof Player) {
- Player p = (Player) d;
- PlotPlayer pp = BukkitUtil.getPlayer(p);
- Plot plot = area.getPlot(l);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.road");
- event.setCancelled(true);
+ if (checkEntity(entity, plot)) {
+ event.setCancelled(true);
}
- } else {
- if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.unowned")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT,
- "plots.admin.vehicle.break.unowned");
+ }
+
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+ public void onEntityFall(EntityChangeBlockEvent event) {
+ if (event.getEntityType() != EntityType.FALLING_BLOCK) {
+ return;
+ }
+ Block block = event.getBlock();
+ World world = block.getWorld();
+ String worldName = world.getName();
+ if (!PlotSquared.get().hasPlotArea(worldName)) {
+ return;
+ }
+ Location location = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlotAbs(location);
+ if (plot == null || plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
event.setCancelled(true);
return;
- }
- return;
}
- if (!plot.isAdded(pp.getUUID())) {
- if (plot.getFlag(Flags.VEHICLE_BREAK, false)) {
+ if (event.getTo().hasGravity()) {
+ Entity entity = event.getEntity();
+ List meta = entity.getMetadata("plot");
+ if (meta.isEmpty()) {
+ return;
+ }
+ Plot origin = (Plot) meta.get(0).value();
+ if (origin != null && !origin.equals(plot)) {
+ event.setCancelled(true);
+ entity.remove();
+ }
+ } else if (event.getTo() == Material.AIR) {
+ event.getEntity()
+ .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
+ }
+ }
+
+ @EventHandler public void onPrime(ExplosionPrimeEvent event) {
+ this.lastRadius = event.getRadius() + 1;
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockBurn(BlockBurnEvent event) {
+ Block b = event.getBlock();
+ Location location = BukkitUtil.getLocation(b.getLocation());
+
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
return;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT,
- "plots.admin.vehicle.break.other");
+ }
+
+ Plot plot = location.getOwnedPlot();
+ if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) {
event.setCancelled(true);
- }
+ return;
}
- }
- }
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPotionSplash(PotionSplashEvent event) {
- ThrownPotion damager = event.getPotion();
- Location l = BukkitUtil.getLocation(damager);
- if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
- return;
- }
- int count = 0;
- for (LivingEntity victim : event.getAffectedEntities()) {
- if (!entityDamage(damager, victim)) {
- event.setIntensity(victim, 0);
- count++;
- }
- }
- if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
- EntityDamageByEntityEvent eventChange = new EntityDamageByEntityEvent(event.getCombuster(),
- event.getEntity(),
- EntityDamageEvent.DamageCause.FIRE_TICK, (double) event.getDuration());
- onEntityDamageByEntityEvent(eventChange);
- if (eventChange.isCancelled()) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
- Entity damager = event.getDamager();
- Location l = BukkitUtil.getLocation(damager);
- if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
- return;
- }
- Entity victim = event.getEntity();
- if (!entityDamage(damager, victim)) {
- if (event.isCancelled()) {
- if (victim instanceof Ageable) {
- Ageable ageable = (Ageable) victim;
- if (ageable.getAge() == -24000) {
- ageable.setAge(0);
- ageable.setAdult();
- }
- }
- }
- event.setCancelled(true);
- }
- }
-
- public boolean entityDamage(Entity damager, Entity victim) {
- Location dloc = BukkitUtil.getLocation(damager);
- Location vloc = BukkitUtil.getLocation(victim);
- PlotArea dArea = dloc.getPlotArea();
- PlotArea vArea =
- dArea != null && dArea.contains(vloc.getX(), vloc.getZ()) ? dArea : vloc.getPlotArea();
- if (dArea == null && vArea == null) {
- return true;
}
- Plot dplot = dArea != null ? dArea.getPlot(dloc) : null;
- Plot vplot = vArea != null ? vArea.getPlot(vloc) : null;
-
- Plot plot;
- String stub;
- if (dplot == null && vplot == null) {
- if (dArea == null) {
- return true;
- }
- plot = null;
- stub = "road";
- } else {
- // Prioritize plots for close to seamless pvp zones
- if (victim.getTicksLived() > damager.getTicksLived()) {
- if (dplot == null || !(victim instanceof Player)) {
- if (vplot == null) {
- plot = dplot;
- } else {
- plot = vplot;
- }
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockIgnite(BlockIgniteEvent event) {
+ Player player = event.getPlayer();
+ Entity ignitingEntity = event.getIgnitingEntity();
+ Block block = event.getBlock();
+ BlockIgniteEvent.IgniteCause igniteCause = event.getCause();
+ Location loc;
+ if (block != null) {
+ loc = BukkitUtil.getLocation(block.getLocation());
+ } else if (ignitingEntity != null) {
+ loc = BukkitUtil.getLocation(ignitingEntity);
+ } else if (player != null) {
+ loc = BukkitUtil.getLocation(player);
} else {
- plot = dplot;
+ return;
}
- } else if (dplot == null || !(victim instanceof Player)) {
- if (vplot == null) {
- plot = dplot;
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ if (igniteCause == BlockIgniteEvent.IgniteCause.LIGHTNING) {
+ event.setCancelled(true);
+ return;
+ }
+
+ Plot plot = area.getOwnedPlotAbs(loc);
+ if (player != null) {
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ event.setCancelled(true);
+ }
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
+ event.setCancelled(true);
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ }
+ } else if (Flags.BLOCK_IGNITION.isFalse(plot)) {
+ event.setCancelled(true);
+ }
} else {
- plot = vplot;
+ if (plot == null) {
+ event.setCancelled(true);
+ return;
+ }
+ if (ignitingEntity != null) {
+ if (!plot.getFlag(Flags.BLOCK_IGNITION, false)) {
+ event.setCancelled(true);
+ return;
+ }
+ if (igniteCause == BlockIgniteEvent.IgniteCause.FIREBALL) {
+ if (ignitingEntity instanceof Fireball) {
+ Projectile fireball = (Projectile) ignitingEntity;
+ Location location = null;
+ if (fireball.getShooter() instanceof Entity) {
+ Entity shooter = (Entity) fireball.getShooter();
+ location = BukkitUtil.getLocation(shooter.getLocation());
+ } else if (fireball.getShooter() instanceof BlockProjectileSource) {
+ Block shooter =
+ ((BlockProjectileSource) fireball.getShooter()).getBlock();
+ location = BukkitUtil.getLocation(shooter.getLocation());
+ }
+ if (location != null && !plot.equals(location.getPlot())) {
+ event.setCancelled(true);
+ }
+ }
+ }
+
+ } else if (event.getIgnitingBlock() != null) {
+ Block ignitingBlock = event.getIgnitingBlock();
+ Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot();
+ if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (
+ !plot.getFlag(Flags.BLOCK_IGNITION, false) || plotIgnited == null
+ || !plotIgnited.equals(plot)) ||
+ (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
+ || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && (
+ !plot.getFlag(Flags.BLOCK_IGNITION).orElse(false) || plotIgnited == null
+ || !plotIgnited.equals(plot))) {
+ event.setCancelled(true);
+ }
+ }
}
- } else if (vplot == null) {
- plot = dplot;
- } else {
- plot = vplot;
- }
- if (plot.hasOwner()) {
- stub = "other";
- } else {
- stub = "unowned";
- }
}
- Player player;
- if (damager instanceof Player) { // attacker is player
- player = (Player) damager;
- } else if (damager instanceof Projectile) {
- Projectile projectile = (Projectile) damager;
- ProjectileSource shooter = projectile.getShooter();
- if (shooter instanceof Player) { // shooter is player
- player = (Player) shooter;
- } else { // shooter is not player
- if (shooter instanceof BlockProjectileSource) {
- Location sLoc = BukkitUtil
- .getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
- dplot = dArea.getPlot(sLoc);
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBucketEmpty(PlayerBucketEmptyEvent event) {
+ BlockFace bf = event.getBlockFace();
+ Block b =
+ event.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ())
+ .getBlock();
+ Location location = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ event.setCancelled(true);
+ } else if (!plot.hasOwner()) {
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
+ event.setCancelled(true);
+ } else if (!plot.isAdded(pp.getUUID())) {
+ if (Flags.USE.contains(plot, PlotBlock.get(event.getBucket().getId(), 0))) {
+ return;
+ }
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ }
}
- player = null;
- }
- } else { // Attacker is not player
- player = null;
}
- if (player != null) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- if (victim instanceof Hanging) { // hanging
- if (plot != null && (plot.getFlag(Flags.HANGING_BREAK, false) || plot
- .isAdded(plotPlayer.getUUID()))) {
- return true;
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onInventoryClose(InventoryCloseEvent event) {
+ HumanEntity closer = event.getPlayer();
+ if (!(closer instanceof Player)) {
+ return;
}
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- "plots.admin.destroy." + stub);
- return false;
+ Player player = (Player) closer;
+ PlotInventory.removePlotInventoryOpen(BukkitUtil.getPlayer(player));
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
+ TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
+ PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
+ pp.unregister();
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBucketFill(PlayerBucketFillEvent event) {
+ Block b = event.getBlockClicked();
+ Location location = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
}
- } else if (victim.getEntityId() == 30) {
- if (plot != null && (plot.getFlag(Flags.MISC_BREAK, false) || plot
- .isAdded(plotPlayer.getUUID()))) {
- return true;
+ Player player = event.getPlayer();
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ return;
+ }
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ event.setCancelled(true);
+ } else if (!plot.hasOwner()) {
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ return;
+ }
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
+ event.setCancelled(true);
+ } else if (!plot.isAdded(plotPlayer.getUUID())) {
+ Optional> use = plot.getFlag(Flags.USE);
+ Block block = event.getBlockClicked();
+ if (use.isPresent() && use.get().contains(PlotBlock.get(block.getType().name()))) {
+ return;
+ }
+ if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ return;
+ }
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
+ if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ }
}
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- "plots.admin.destroy." + stub);
- return false;
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onVehicleCreate(VehicleCreateEvent event) {
+ Vehicle entity = event.getVehicle();
+ Location location = BukkitUtil.getLocation(entity);
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
}
- } else if (victim instanceof Monster
- || victim instanceof EnderDragon) { // victim is monster
- if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK, false) || plot
- .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
- return true;
+ Plot plot = area.getOwnedPlotAbs(location);
+ if (plot == null || checkEntity(entity, plot)) {
+ entity.remove();
+ return;
}
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
+ if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
+ entity
+ .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
}
- } else if (victim instanceof Tameable) { // victim is tameable
- if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK, false) || plot
- .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
- return true;
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onHangingPlace(HangingPlaceEvent event) {
+ Block b = event.getBlock().getRelative(event.getBlockFace());
+ Location location = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
}
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
+ Player p = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(p);
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ event.setCancelled(true);
+ }
+ } else {
+ if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
+ event.setCancelled(true);
+ }
+ return;
+ }
+ if (!plot.isAdded(pp.getUUID())) {
+ if (!plot.getFlag(Flags.HANGING_PLACE, false)) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ }
+ return;
+ }
+ }
+ if (checkEntity(event.getEntity(), plot)) {
+ event.setCancelled(true);
+ }
+
}
- } else if (victim instanceof Player) {
- if (plot != null) {
- if (Flags.PVP.isFalse(plot) && !Permissions
- .hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- "plots.admin.pvp." + stub);
- return false;
- } else {
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
+ Entity remover = event.getRemover();
+ if (remover instanceof Player) {
+ Player p = (Player) remover;
+ Location location = BukkitUtil.getLocation(event.getEntity());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ PlotPlayer pp = BukkitUtil.getPlayer(p);
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
+ event.setCancelled(true);
+ }
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
+ event.setCancelled(true);
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ if (plot.getFlag(Flags.HANGING_BREAK, false)) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
+ event.setCancelled(true);
+ }
+ }
+ } else if (remover instanceof Projectile) {
+ Projectile p = (Projectile) remover;
+ if (p.getShooter() instanceof Player) {
+ Player shooter = (Player) p.getShooter();
+ Location location = BukkitUtil.getLocation(event.getEntity());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ PlotPlayer player = BukkitUtil.getPlayer(shooter);
+ Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity()));
+ if (plot != null) {
+ if (!plot.hasOwner()) {
+ if (!Permissions
+ .hasPermission(player, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
+ MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_DESTROY_UNOWNED);
+ event.setCancelled(true);
+ }
+ } else if (!plot.isAdded(player.getUUID())) {
+ if (!plot.getFlag(Flags.HANGING_BREAK, false)) {
+ if (!Permissions
+ .hasPermission(player, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT,
+ C.PERMISSION_ADMIN_DESTROY_OTHER);
+ event.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
+ Location location = BukkitUtil.getLocation(event.getRightClicked().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Player p = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(p);
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_ROAD);
+ event.setCancelled(true);
+ }
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED);
+ event.setCancelled(true);
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ Entity entity = event.getRightClicked();
+ if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT, false)) {
+ return;
+ }
+ if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT, false)) {
+ return;
+ }
+ if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot
+ .getFlag(Flags.TAMED_INTERACT, false)) {
+ return;
+ }
+ if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE, false)) {
+ return;
+ }
+ if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT, false)) {
+ return;
+ }
+ if (entity instanceof Villager && plot.getFlag(Flags.VILLAGER_INTERACT, false)) {
+ return;
+ }
+ if (entity instanceof ItemFrame && plot.getFlag(Flags.MISC_INTERACT, false)) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
+ event.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onVehicleDestroy(VehicleDestroyEvent event) {
+ Location l = BukkitUtil.getLocation(event.getVehicle());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Entity d = event.getAttacker();
+ if (d instanceof Player) {
+ Player p = (Player) d;
+ PlotPlayer pp = BukkitUtil.getPlayer(p);
+ Plot plot = area.getPlot(l);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.road");
+ event.setCancelled(true);
+ }
+ } else {
+ if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.unowned")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT,
+ "plots.admin.vehicle.break.unowned");
+ event.setCancelled(true);
+ return;
+ }
+ return;
+ }
+ if (!plot.isAdded(pp.getUUID())) {
+ if (plot.getFlag(Flags.VEHICLE_BREAK, false)) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT,
+ "plots.admin.vehicle.break.other");
+ event.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPotionSplash(PotionSplashEvent event) {
+ ThrownPotion damager = event.getPotion();
+ Location l = BukkitUtil.getLocation(damager);
+ if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
+ return;
+ }
+ int count = 0;
+ for (LivingEntity victim : event.getAffectedEntities()) {
+ if (!entityDamage(damager, victim)) {
+ event.setIntensity(victim, 0);
+ count++;
+ }
+ }
+ if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
+ EntityDamageByEntityEvent eventChange =
+ new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
+ EntityDamageEvent.DamageCause.FIRE_TICK, (double) event.getDuration());
+ onEntityDamageByEntityEvent(eventChange);
+ if (eventChange.isCancelled()) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
+ Entity damager = event.getDamager();
+ Location l = BukkitUtil.getLocation(damager);
+ if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
+ return;
+ }
+ Entity victim = event.getEntity();
+ if (!entityDamage(damager, victim)) {
+ if (event.isCancelled()) {
+ if (victim instanceof Ageable) {
+ Ageable ageable = (Ageable) victim;
+ if (ageable.getAge() == -24000) {
+ ageable.setAge(0);
+ ageable.setAdult();
+ }
+ }
+ }
+ event.setCancelled(true);
+ }
+ }
+
+ public boolean entityDamage(Entity damager, Entity victim) {
+ Location dloc = BukkitUtil.getLocation(damager);
+ Location vloc = BukkitUtil.getLocation(victim);
+ PlotArea dArea = dloc.getPlotArea();
+ PlotArea vArea =
+ dArea != null && dArea.contains(vloc.getX(), vloc.getZ()) ? dArea : vloc.getPlotArea();
+ if (dArea == null && vArea == null) {
return true;
- }
}
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub);
- return false;
- }
- } else if (victim instanceof Creature) { // victim is animal
- if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK, false) || plot
- .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
- }
- } else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event
- return true;
- } else { // victim is something else
- if (plot != null && (plot.getFlag(Flags.PVE, false) || plot
- .isAdded(plotPlayer.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
- }
- }
- return true;
- } else if (dplot != null && (!dplot.equals(vplot) || Objects
- .equals(dplot.guessOwner(), vplot.guessOwner()))) {
- return vplot != null && Flags.PVE.isTrue(vplot);
- }
- return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow
- && !(victim instanceof Creature)));
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerEggThrow(PlayerEggThrowEvent event) {
- Location l = BukkitUtil.getLocation(event.getEgg().getLocation());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- Player player = event.getPlayer();
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- Plot plot = area.getPlot(l);
- if (plot == null) {
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.projectile.road");
- event.setHatching(false);
- }
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.unowned")) {
- MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
- "plots.admin.projectile.unowned");
- event.setHatching(false);
- }
- } else if (!plot.isAdded(plotPlayer.getUUID())) {
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.other")) {
- MainUtil
- .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.projectile.other");
- event.setHatching(false);
- }
- }
- }
+ Plot dplot = dArea != null ? dArea.getPlot(dloc) : null;
+ Plot vplot = vArea != null ? vArea.getPlot(vloc) : null;
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void blockCreate(BlockPlaceEvent event) {
- Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- Plot plot = area.getPlot(location);
- if (plot != null) {
- if ((location.getY() > area.MAX_BUILD_HEIGHT || location.getY() < area.MIN_BUILD_HEIGHT)
- && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) {
- event.setCancelled(true);
- MainUtil.sendMessage(pp,
- C.HEIGHT_LIMIT.s().replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
- }
- if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- MainUtil
- .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
- event.setCancelled(true);
- return;
+ Plot plot;
+ String stub;
+ if (dplot == null && vplot == null) {
+ if (dArea == null) {
+ return true;
+ }
+ plot = null;
+ stub = "road";
+ } else {
+ // Prioritize plots for close to seamless pvp zones
+ if (victim.getTicksLived() > damager.getTicksLived()) {
+ if (dplot == null || !(victim instanceof Player)) {
+ if (vplot == null) {
+ plot = dplot;
+ } else {
+ plot = vplot;
+ }
+ } else {
+ plot = dplot;
+ }
+ } else if (dplot == null || !(victim instanceof Player)) {
+ if (vplot == null) {
+ plot = dplot;
+ } else {
+ plot = vplot;
+ }
+ } else if (vplot == null) {
+ plot = dplot;
+ } else {
+ plot = vplot;
+ }
+ if (plot.hasOwner()) {
+ stub = "other";
+ } else {
+ stub = "unowned";
+ }
}
- } else if (!plot.isAdded(pp.getUUID())) {
- Set place = plot.getFlag(Flags.PLACE, null);
- if (place != null) {
- Block block = event.getBlock();
- if (place.contains(PlotBlock.get(block.getType().name()))) {
+
+ Player player;
+ if (damager instanceof Player) { // attacker is player
+ player = (Player) damager;
+ } else if (damager instanceof Projectile) {
+ Projectile projectile = (Projectile) damager;
+ ProjectileSource shooter = projectile.getShooter();
+ if (shooter instanceof Player) { // shooter is player
+ player = (Player) shooter;
+ } else { // shooter is not player
+ if (shooter instanceof BlockProjectileSource) {
+ Location sLoc = BukkitUtil
+ .getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
+ dplot = dArea.getPlot(sLoc);
+ }
+ player = null;
+ }
+ } else { // Attacker is not player
+ player = null;
+ }
+ if (player != null) {
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ if (victim instanceof Hanging) { // hanging
+ if (plot != null && (plot.getFlag(Flags.HANGING_BREAK, false) || plot
+ .isAdded(plotPlayer.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ "plots.admin.destroy." + stub);
+ return false;
+ }
+ } else if (victim.getEntityId() == 30) {
+ if (plot != null && (plot.getFlag(Flags.MISC_BREAK, false) || plot
+ .isAdded(plotPlayer.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ "plots.admin.destroy." + stub);
+ return false;
+ }
+ } else if (victim instanceof Monster
+ || victim instanceof EnderDragon) { // victim is monster
+ if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK, false) || plot
+ .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ } else if (victim instanceof Tameable) { // victim is tameable
+ if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK, false) || plot
+ .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ } else if (victim instanceof Player) {
+ if (plot != null) {
+ if (Flags.PVP.isFalse(plot) && !Permissions
+ .hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ "plots.admin.pvp." + stub);
+ return false;
+ } else {
+ return true;
+ }
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub);
+ return false;
+ }
+ } else if (victim instanceof Creature) { // victim is animal
+ if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK, false) || plot
+ .getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ } else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event
+ return true;
+ } else { // victim is something else
+ if (plot != null && (plot.getFlag(Flags.PVE, false) || plot
+ .isAdded(plotPlayer.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ }
+ return true;
+ } else if (dplot != null && (!dplot.equals(vplot) || Objects
+ .equals(dplot.guessOwner(), vplot.guessOwner()))) {
+ return vplot != null && Flags.PVE.isTrue(vplot);
+ }
+ return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow
+ && !(victim instanceof Creature)));
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPlayerEggThrow(PlayerEggThrowEvent event) {
+ Location l = BukkitUtil.getLocation(event.getEgg().getLocation());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
return;
- }
}
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- return;
+ Player player = event.getPlayer();
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ Plot plot = area.getPlot(l);
+ if (plot == null) {
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.projectile.road");
+ event.setHatching(false);
+ }
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.unowned")) {
+ MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT,
+ "plots.admin.projectile.unowned");
+ event.setHatching(false);
+ }
+ } else if (!plot.isAdded(plotPlayer.getUUID())) {
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.other")) {
+ MainUtil
+ .sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.projectile.other");
+ event.setHatching(false);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void blockCreate(BlockPlaceEvent event) {
+ Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Player player = event.getPlayer();
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
+ Plot plot = area.getPlot(location);
+ if (plot != null) {
+ if ((location.getY() > area.MAX_BUILD_HEIGHT || location.getY() < area.MIN_BUILD_HEIGHT)
+ && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) {
+ event.setCancelled(true);
+ MainUtil.sendMessage(pp,
+ C.HEIGHT_LIMIT.s().replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
+ }
+ if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ MainUtil
+ .sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
+ event.setCancelled(true);
+ return;
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ Set place = plot.getFlag(Flags.PLACE, null);
+ if (place != null) {
+ Block block = event.getBlock();
+ if (place.contains(PlotBlock.get(block.getType().name()))) {
+ return;
+ }
+ }
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ return;
+ }
+ } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ return;
+ }
+ }
+ if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
+ Block block = event.getBlockPlaced();
+ if (block.getType().hasGravity()) {
+ sendBlockChange(block.getLocation(), block.getBlockData());
+ }
+ }
+ } else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ event.setCancelled(true);
}
- } else if (Settings.Done.RESTRICT_BUILDING && plot.getFlags().containsKey(Flags.DONE)) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- return;
- }
- }
- if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
- Block block = event.getBlockPlaced();
- if (block.getType().hasGravity()) {
- sendBlockChange(block.getLocation(), block.getBlockData());
- }
- }
- } else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
}
- }
}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java
index 19cd4c554..33a63dbde 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java
@@ -31,8 +31,7 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
-@SuppressWarnings("unused")
-public class PlotPlusListener extends PlotListener implements Listener {
+@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
private static final HashMap feedRunnable = new HashMap<>();
private static final HashMap healRunnable = new HashMap<>();
@@ -82,8 +81,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
}, 0L, 20L);
}
- @EventHandler(priority = EventPriority.HIGH)
- public void onInteract(BlockDamageEvent event) {
+ @EventHandler(priority = EventPriority.HIGH) public void onInteract(BlockDamageEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.SURVIVAL) {
return;
@@ -102,8 +100,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
}
}
- @EventHandler(priority = EventPriority.HIGH)
- public void onDamage(EntityDamageEvent event) {
+ @EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
return;
}
@@ -117,8 +114,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
}
}
- @EventHandler
- public void onItemDrop(PlayerDropItemEvent event) {
+ @EventHandler public void onItemDrop(PlayerDropItemEvent event) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
@@ -133,27 +129,24 @@ public class PlotPlusListener extends PlotListener implements Listener {
}
}
- @EventHandler
- public void onPlotEnter(PlayerEnterPlotEvent event) {
+ @EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
Player player = event.getPlayer();
Plot plot = event.getPlot();
Optional feed = plot.getFlag(Flags.FEED);
- feed.ifPresent( value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))
- );
+ feed.ifPresent(
+ value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)));
Optional heal = plot.getFlag(Flags.HEAL);
- heal.ifPresent( value -> healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))
- );
+ heal.ifPresent(
+ value -> healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)));
}
- @EventHandler
- public void onPlayerQuit(PlayerQuitEvent event) {
+ @EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
feedRunnable.remove(player.getUniqueId());
healRunnable.remove(player.getUniqueId());
}
- @EventHandler
- public void onPlotLeave(PlayerLeavePlotEvent event) {
+ @EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) {
Player leaver = event.getPlayer();
Plot plot = event.getPlot();
if (!plot.hasOwner()) {
@@ -164,8 +157,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
healRunnable.remove(leaver.getUniqueId());
}
- @EventHandler
- public void onItemPickup(EntityPickupItemEvent event) {
+ @EventHandler public void onItemPickup(EntityPickupItemEvent event) {
LivingEntity ent = event.getEntity();
if (ent instanceof Player) {
Player player = (Player) ent;
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java
index 321dde939..b0912fea2 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java
@@ -1,13 +1,9 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
-import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
-
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
@@ -18,6 +14,11 @@ import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.Plugin;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
+
@SuppressWarnings("unused") public class SingleWorldListener implements Listener {
private Method methodGetHandleChunk;
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 7aecb854c..dddf43738 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
@@ -7,7 +7,10 @@ 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.*;
-import org.bukkit.*;
+import org.bukkit.GameMode;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
@@ -255,14 +258,15 @@ public class BukkitPlayer extends PlotPlayer {
@Override public void playMusic(Location location, PlotBlock id) {
if (PlotBlock.isEverything(id) || id.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())) {
+ for (final Sound sound : Arrays.stream(Sound.values())
+ .filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) {
player.stopSound(sound);
}
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
} 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);
+ this.player.playSound(BukkitUtil.getLocation(location),
+ Sound.valueOf(id.to(Material.class).name()), Float.MAX_VALUE, 1f);
}
}
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 c06b66b71..0b6921f88 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
@@ -12,697 +12,694 @@ import org.bukkit.util.Vector;
public final class ReplicatingEntityWrapper extends EntityWrapper {
- private final short depth;
- private final int hash;
- private final EntityBaseStats base = new EntityBaseStats();
+ private final short depth;
+ private final int hash;
+ private final EntityBaseStats base = new EntityBaseStats();
- public ItemStack[] inventory;
- // Extended
- private ItemStack stack;
- private byte dataByte;
- private byte dataByte2;
- private String dataString;
- private LivingEntityStats lived;
- private AgeableStats aged;
- private TameableStats tamed;
- private ArmorStandStats stand;
- private HorseStats horse;
- private boolean noGravity;
+ public ItemStack[] inventory;
+ // Extended
+ private ItemStack stack;
+ private byte dataByte;
+ private byte dataByte2;
+ private String dataString;
+ private LivingEntityStats lived;
+ private AgeableStats aged;
+ private TameableStats tamed;
+ private ArmorStandStats stand;
+ private HorseStats horse;
+ private boolean noGravity;
- public ReplicatingEntityWrapper(Entity entity, short depth) {
- super(entity);
+ public ReplicatingEntityWrapper(Entity entity, short depth) {
+ super(entity);
- this.hash = entity.getEntityId();
- this.depth = depth;
+ this.hash = entity.getEntityId();
+ this.depth = depth;
- if (depth == 0) {
- return;
+ if (depth == 0) {
+ return;
+ }
+ Entity passenger = entity.getPassenger();
+ if (passenger != null) {
+ this.base.passenger = new ReplicatingEntityWrapper(passenger, depth);
+ }
+ this.base.fall = entity.getFallDistance();
+ this.base.fire = (short) entity.getFireTicks();
+ this.base.age = entity.getTicksLived();
+ Vector velocity = entity.getVelocity();
+ this.base.vX = velocity.getX();
+ this.base.vY = velocity.getY();
+ this.base.vZ = velocity.getZ();
+ if (depth == 1) {
+ return;
+ }
+ if (!entity.hasGravity()) {
+ this.noGravity = true;
+ }
+ switch (entity.getType()) {
+ case BOAT:
+ Boat boat = (Boat) entity;
+ this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
+ return;
+ case ARROW:
+ case COMPLEX_PART:
+ case EGG:
+ case ENDER_CRYSTAL:
+ case ENDER_PEARL:
+ case ENDER_SIGNAL:
+ case EXPERIENCE_ORB:
+ case FALLING_BLOCK:
+ case FIREBALL:
+ case FIREWORK:
+ case FISHING_HOOK:
+ case LEASH_HITCH:
+ case LIGHTNING:
+ case MINECART:
+ case MINECART_COMMAND:
+ case MINECART_MOB_SPAWNER:
+ case MINECART_TNT:
+ case PLAYER:
+ case PRIMED_TNT:
+ case SLIME:
+ case SMALL_FIREBALL:
+ case SNOWBALL:
+ case MINECART_FURNACE:
+ case SPLASH_POTION:
+ case THROWN_EXP_BOTTLE:
+ case WEATHER:
+ case WITHER_SKULL:
+ case UNKNOWN:
+ case TIPPED_ARROW:
+ case SPECTRAL_ARROW:
+ case SHULKER_BULLET:
+ case DRAGON_FIREBALL:
+ case LINGERING_POTION:
+ case AREA_EFFECT_CLOUD:
+ // Do this stuff later
+ return;
+ // MISC //
+ case DROPPED_ITEM:
+ Item item = (Item) entity;
+ this.stack = item.getItemStack();
+ return;
+ case ITEM_FRAME:
+ this.x = Math.floor(this.x);
+ this.y = Math.floor(this.y);
+ this.z = Math.floor(this.z);
+ ItemFrame itemFrame = (ItemFrame) entity;
+ this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
+ this.stack = itemFrame.getItem().clone();
+ return;
+ case PAINTING:
+ this.x = Math.floor(this.x);
+ this.y = Math.floor(this.y);
+ this.z = Math.floor(this.z);
+ Painting painting = (Painting) entity;
+ Art art = painting.getArt();
+ this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
+ int h = art.getBlockHeight();
+ if (h % 2 == 0) {
+ this.y -= 1;
+ }
+ this.dataString = art.name();
+ return;
+ // END MISC //
+ // INVENTORY HOLDER //
+ case MINECART_CHEST:
+ case MINECART_HOPPER:
+ storeInventory((InventoryHolder) entity);
+ return;
+ // START LIVING ENTITY //
+ // START AGEABLE //
+ // START TAMEABLE //
+ case HORSE:
+ Horse horse = (Horse) entity;
+ this.horse = new HorseStats();
+ this.horse.jump = horse.getJumpStrength();
+ if (horse instanceof ChestedHorse) {
+ this.horse.chest = ((ChestedHorse) horse).isCarryingChest();
+ } else {
+ this.horse.chest = false;
+ }
+ this.horse.variant = horse.getVariant();
+ this.horse.style = horse.getStyle();
+ this.horse.color = horse.getColor();
+ storeTameable(horse);
+ storeAgeable(horse);
+ storeLiving(horse);
+ storeInventory(horse);
+ return;
+ // END INVENTORY HOLDER //
+ case WOLF:
+ case OCELOT:
+ storeTameable((Tameable) entity);
+ storeAgeable((Ageable) entity);
+ storeLiving((LivingEntity) entity);
+ return;
+ // END TAMEABLE //
+ case SHEEP:
+ Sheep sheep = (Sheep) entity;
+ this.dataByte = (byte) (sheep.isSheared() ? 1 : 0);
+ this.dataByte2 = sheep.getColor().getDyeData();
+ storeAgeable(sheep);
+ storeLiving(sheep);
+ return;
+ case VILLAGER:
+ case CHICKEN:
+ case COW:
+ case MUSHROOM_COW:
+ case PIG:
+ case POLAR_BEAR:
+ storeAgeable((Ageable) entity);
+ storeLiving((LivingEntity) entity);
+ return;
+ case RABBIT:
+ this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
+ storeAgeable((Ageable) entity);
+ storeLiving((LivingEntity) entity);
+ return;
+ // END AGEABLE //
+ case GUARDIAN:
+ //todo no longer works (possible exception thrown)
+ this.dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
+ storeLiving((LivingEntity) entity);
+ return;
+ case SKELETON:
+ //todo no longer works (possible exception thrown)
+ this.dataByte = getOrdinal(Skeleton.SkeletonType.values(),
+ ((Skeleton) entity).getSkeletonType());
+ storeLiving((LivingEntity) entity);
+ return;
+ case ARMOR_STAND:
+ ArmorStand stand = (ArmorStand) entity;
+ this.inventory =
+ new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(),
+ stand.getChestplate().clone(), stand.getLeggings().clone(),
+ stand.getBoots().clone()};
+ storeLiving(stand);
+ this.stand = new ArmorStandStats();
+
+ EulerAngle head = stand.getHeadPose();
+ this.stand.head[0] = (float) head.getX();
+ this.stand.head[1] = (float) head.getY();
+ this.stand.head[2] = (float) head.getZ();
+
+ EulerAngle body = stand.getBodyPose();
+ this.stand.body[0] = (float) body.getX();
+ this.stand.body[1] = (float) body.getY();
+ this.stand.body[2] = (float) body.getZ();
+
+ EulerAngle leftLeg = stand.getLeftLegPose();
+ this.stand.leftLeg[0] = (float) leftLeg.getX();
+ this.stand.leftLeg[1] = (float) leftLeg.getY();
+ this.stand.leftLeg[2] = (float) leftLeg.getZ();
+
+ EulerAngle rightLeg = stand.getRightLegPose();
+ this.stand.rightLeg[0] = (float) rightLeg.getX();
+ this.stand.rightLeg[1] = (float) rightLeg.getY();
+ this.stand.rightLeg[2] = (float) rightLeg.getZ();
+
+ EulerAngle leftArm = stand.getLeftArmPose();
+ this.stand.leftArm[0] = (float) leftArm.getX();
+ this.stand.leftArm[1] = (float) leftArm.getY();
+ this.stand.leftArm[2] = (float) leftArm.getZ();
+
+ EulerAngle rightArm = stand.getRightArmPose();
+ this.stand.rightArm[0] = (float) rightArm.getX();
+ this.stand.rightArm[1] = (float) rightArm.getY();
+ this.stand.rightArm[2] = (float) rightArm.getZ();
+
+ if (stand.hasArms()) {
+ this.stand.arms = true;
+ }
+ if (!stand.hasBasePlate()) {
+ this.stand.noPlate = true;
+ }
+ if (!stand.isVisible()) {
+ this.stand.invisible = true;
+ }
+ if (stand.isSmall()) {
+ this.stand.small = true;
+ }
+ return;
+ case ENDERMITE:
+ return;
+ case BAT:
+ if (((Bat) entity).isAwake()) {
+ this.dataByte = (byte) 1;
+ } else {
+ this.dataByte = (byte) 0;
+ }
+ return;
+ case ENDER_DRAGON:
+ EnderDragon entity1 = (EnderDragon) entity;
+ this.dataByte = (byte) entity1.getPhase().ordinal();
+ return;
+ case GHAST:
+ case MAGMA_CUBE:
+ case SQUID:
+ case PIG_ZOMBIE:
+ case ZOMBIE:
+ case WITHER:
+ case WITCH:
+ case SPIDER:
+ case CAVE_SPIDER:
+ case SILVERFISH:
+ case GIANT:
+ case ENDERMAN:
+ case CREEPER:
+ case BLAZE:
+ case SHULKER:
+ case SNOWMAN:
+ storeLiving((LivingEntity) entity);
+ return;
+ case IRON_GOLEM:
+ if (((IronGolem) entity).isPlayerCreated()) {
+ this.dataByte = (byte) 1;
+ } else {
+ this.dataByte = (byte) 0;
+ }
+ storeLiving((LivingEntity) entity);
+ // END LIVING //
+ default:
+ PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
+ }
}
- Entity passenger = entity.getPassenger();
- if (passenger != null) {
- this.base.passenger = new ReplicatingEntityWrapper(passenger, depth);
- }
- this.base.fall = entity.getFallDistance();
- this.base.fire = (short) entity.getFireTicks();
- this.base.age = entity.getTicksLived();
- Vector velocity = entity.getVelocity();
- this.base.vX = velocity.getX();
- this.base.vY = velocity.getY();
- this.base.vZ = velocity.getZ();
- if (depth == 1) {
- return;
- }
- if (!entity.hasGravity()) {
- this.noGravity = true;
- }
- switch (entity.getType()) {
- case BOAT:
- Boat boat = (Boat) entity;
- this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
- return;
- case ARROW:
- case COMPLEX_PART:
- case EGG:
- case ENDER_CRYSTAL:
- case ENDER_PEARL:
- case ENDER_SIGNAL:
- case EXPERIENCE_ORB:
- case FALLING_BLOCK:
- case FIREBALL:
- case FIREWORK:
- case FISHING_HOOK:
- case LEASH_HITCH:
- case LIGHTNING:
- case MINECART:
- case MINECART_COMMAND:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT:
- case PLAYER:
- case PRIMED_TNT:
- case SLIME:
- case SMALL_FIREBALL:
- case SNOWBALL:
- case MINECART_FURNACE:
- case SPLASH_POTION:
- case THROWN_EXP_BOTTLE:
- case WEATHER:
- case WITHER_SKULL:
- case UNKNOWN:
- case TIPPED_ARROW:
- case SPECTRAL_ARROW:
- case SHULKER_BULLET:
- case DRAGON_FIREBALL:
- case LINGERING_POTION:
- case AREA_EFFECT_CLOUD:
- // Do this stuff later
- return;
- // MISC //
- case DROPPED_ITEM:
- Item item = (Item) entity;
- this.stack = item.getItemStack();
- return;
- case ITEM_FRAME:
- this.x = Math.floor(this.x);
- this.y = Math.floor(this.y);
- this.z = Math.floor(this.z);
- ItemFrame itemFrame = (ItemFrame) entity;
- this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
- this.stack = itemFrame.getItem().clone();
- return;
- case PAINTING:
- this.x = Math.floor(this.x);
- this.y = Math.floor(this.y);
- this.z = Math.floor(this.z);
- Painting painting = (Painting) entity;
- Art art = painting.getArt();
- this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
- int h = art.getBlockHeight();
- if (h % 2 == 0) {
- this.y -= 1;
- }
- this.dataString = art.name();
- return;
- // END MISC //
- // INVENTORY HOLDER //
- case MINECART_CHEST:
- case MINECART_HOPPER:
- storeInventory((InventoryHolder) entity);
- return;
- // START LIVING ENTITY //
- // START AGEABLE //
- // START TAMEABLE //
- case HORSE:
- Horse horse = (Horse) entity;
- this.horse = new HorseStats();
- this.horse.jump = horse.getJumpStrength();
- if (horse instanceof ChestedHorse) {
- this.horse.chest = ((ChestedHorse) horse).isCarryingChest();
- } else {
- this.horse.chest = false;
- }
- this.horse.variant = horse.getVariant();
- this.horse.style = horse.getStyle();
- this.horse.color = horse.getColor();
- storeTameable(horse);
- storeAgeable(horse);
- storeLiving(horse);
- storeInventory(horse);
- return;
- // END INVENTORY HOLDER //
- case WOLF:
- case OCELOT:
- storeTameable((Tameable) entity);
- storeAgeable((Ageable) entity);
- storeLiving((LivingEntity) entity);
- return;
- // END TAMEABLE //
- case SHEEP:
- Sheep sheep = (Sheep) entity;
- this.dataByte = (byte) (sheep.isSheared() ? 1 : 0);
- this.dataByte2 = sheep.getColor().getDyeData();
- storeAgeable(sheep);
- storeLiving(sheep);
- return;
- case VILLAGER:
- case CHICKEN:
- case COW:
- case MUSHROOM_COW:
- case PIG:
- case POLAR_BEAR:
- storeAgeable((Ageable) entity);
- storeLiving((LivingEntity) entity);
- return;
- case RABBIT:
- this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
- storeAgeable((Ageable) entity);
- storeLiving((LivingEntity) entity);
- return;
- // END AGEABLE //
- case GUARDIAN:
- //todo no longer works (possible exception thrown)
- this.dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
- storeLiving((LivingEntity) entity);
- return;
- case SKELETON:
- //todo no longer works (possible exception thrown)
- this.dataByte = getOrdinal(Skeleton.SkeletonType.values(),
- ((Skeleton) entity).getSkeletonType());
- storeLiving((LivingEntity) entity);
- return;
- case ARMOR_STAND:
- ArmorStand stand = (ArmorStand) entity;
- this.inventory =
- new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(),
- stand.getChestplate().clone(), stand.getLeggings().clone(),
- stand.getBoots().clone()};
- storeLiving(stand);
- this.stand = new ArmorStandStats();
- EulerAngle head = stand.getHeadPose();
- this.stand.head[0] = (float) head.getX();
- this.stand.head[1] = (float) head.getY();
- this.stand.head[2] = (float) head.getZ();
-
- EulerAngle body = stand.getBodyPose();
- this.stand.body[0] = (float) body.getX();
- this.stand.body[1] = (float) body.getY();
- this.stand.body[2] = (float) body.getZ();
-
- EulerAngle leftLeg = stand.getLeftLegPose();
- this.stand.leftLeg[0] = (float) leftLeg.getX();
- this.stand.leftLeg[1] = (float) leftLeg.getY();
- this.stand.leftLeg[2] = (float) leftLeg.getZ();
-
- EulerAngle rightLeg = stand.getRightLegPose();
- this.stand.rightLeg[0] = (float) rightLeg.getX();
- this.stand.rightLeg[1] = (float) rightLeg.getY();
- this.stand.rightLeg[2] = (float) rightLeg.getZ();
-
- EulerAngle leftArm = stand.getLeftArmPose();
- this.stand.leftArm[0] = (float) leftArm.getX();
- this.stand.leftArm[1] = (float) leftArm.getY();
- this.stand.leftArm[2] = (float) leftArm.getZ();
-
- EulerAngle rightArm = stand.getRightArmPose();
- this.stand.rightArm[0] = (float) rightArm.getX();
- this.stand.rightArm[1] = (float) rightArm.getY();
- this.stand.rightArm[2] = (float) rightArm.getZ();
-
- if (stand.hasArms()) {
- this.stand.arms = true;
- }
- if (!stand.hasBasePlate()) {
- this.stand.noPlate = true;
- }
- if (!stand.isVisible()) {
- this.stand.invisible = true;
- }
- if (stand.isSmall()) {
- this.stand.small = true;
- }
- return;
- case ENDERMITE:
- return;
- case BAT:
- if (((Bat) entity).isAwake()) {
- this.dataByte = (byte) 1;
- } else {
- this.dataByte = (byte) 0;
- }
- return;
- case ENDER_DRAGON:
- EnderDragon entity1 = (EnderDragon) entity;
- this.dataByte = (byte) entity1.getPhase().ordinal();
- return;
- case GHAST:
- case MAGMA_CUBE:
- case SQUID:
- case PIG_ZOMBIE:
- case ZOMBIE:
- case WITHER:
- case WITCH:
- case SPIDER:
- case CAVE_SPIDER:
- case SILVERFISH:
- case GIANT:
- case ENDERMAN:
- case CREEPER:
- case BLAZE:
- case SHULKER:
- case SNOWMAN:
- storeLiving((LivingEntity) entity);
- return;
- case IRON_GOLEM:
- if (((IronGolem) entity).isPlayerCreated()) {
- this.dataByte = (byte) 1;
- } else {
- this.dataByte = (byte) 0;
- }
- storeLiving((LivingEntity) entity);
- // END LIVING //
- default:
- PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
+ @Override public boolean equals(Object obj) {
+ return this.hash == obj.hashCode();
}
- }
- @Override
- public boolean equals(Object obj) {
- return this.hash == obj.hashCode();
- }
+ @Override public int hashCode() {
+ return this.hash;
+ }
- @Override
- public int hashCode() {
- return this.hash;
- }
+ public void storeInventory(InventoryHolder held) {
+ this.inventory = held.getInventory().getContents().clone();
+ }
- public void storeInventory(InventoryHolder held) {
- this.inventory = held.getInventory().getContents().clone();
- }
+ void restoreLiving(LivingEntity entity) {
+ entity.setCanPickupItems(this.lived.loot);
+ if (this.lived.name != null) {
+ entity.setCustomName(this.lived.name);
+ entity.setCustomNameVisible(this.lived.visible);
+ }
+ if (this.lived.potions != null && !this.lived.potions.isEmpty()) {
+ entity.addPotionEffects(this.lived.potions);
+ }
+ entity.setRemainingAir(this.lived.air);
+ entity.setRemoveWhenFarAway(this.lived.persistent);
+ if (this.lived.equipped) {
+ this.restoreEquipment(entity);
+ }
+ if (this.lived.leashed) {
+ // TODO leashes
+ // World world = entity.getWorld();
+ // Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leashX, Math.floor(y) + lived.leashY, Math
+ // .floor(z) + lived.leashZ), EntityType.LEASH_HITCH);
+ // entity.setLeashHolder(leash);
+ }
+ }
- void restoreLiving(LivingEntity entity) {
- entity.setCanPickupItems(this.lived.loot);
- if (this.lived.name != null) {
- entity.setCustomName(this.lived.name);
- entity.setCustomNameVisible(this.lived.visible);
+ void restoreEquipment(LivingEntity entity) {
+ EntityEquipment equipment = entity.getEquipment();
+ equipment.setItemInMainHand(this.lived.mainHand);
+ equipment.setItemInOffHand(this.lived.offHand);
+ equipment.setHelmet(this.lived.helmet);
+ equipment.setChestplate(this.lived.chestplate);
+ equipment.setLeggings(this.lived.leggings);
+ equipment.setBoots(this.lived.boots);
}
- if (this.lived.potions != null && !this.lived.potions.isEmpty()) {
- entity.addPotionEffects(this.lived.potions);
- }
- entity.setRemainingAir(this.lived.air);
- entity.setRemoveWhenFarAway(this.lived.persistent);
- if (this.lived.equipped) {
- this.restoreEquipment(entity);
- }
- if (this.lived.leashed) {
- // TODO leashes
- // World world = entity.getWorld();
- // Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leashX, Math.floor(y) + lived.leashY, Math
- // .floor(z) + lived.leashZ), EntityType.LEASH_HITCH);
- // entity.setLeashHolder(leash);
- }
- }
- void restoreEquipment(LivingEntity entity) {
- EntityEquipment equipment = entity.getEquipment();
- equipment.setItemInMainHand(this.lived.mainHand);
- equipment.setItemInOffHand(this.lived.offHand);
- equipment.setHelmet(this.lived.helmet);
- equipment.setChestplate(this.lived.chestplate);
- equipment.setLeggings(this.lived.leggings);
- equipment.setBoots(this.lived.boots);
- }
+ private void restoreInventory(InventoryHolder entity) {
+ try {
+ entity.getInventory().setContents(this.inventory);
+ } catch (IllegalArgumentException e) {
+ PlotSquared.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
+ }
+ }
- private void restoreInventory(InventoryHolder entity) {
- try {
- entity.getInventory().setContents(this.inventory);
- } catch (IllegalArgumentException e) {
- PlotSquared.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
+ public void storeLiving(LivingEntity lived) {
+ this.lived = new LivingEntityStats();
+ this.lived.potions = lived.getActivePotionEffects();
+ this.lived.loot = lived.getCanPickupItems();
+ this.lived.name = lived.getCustomName();
+ this.lived.visible = lived.isCustomNameVisible();
+ this.lived.health = (float) lived.getHealth();
+ this.lived.air = (short) lived.getRemainingAir();
+ this.lived.persistent = lived.getRemoveWhenFarAway();
+ this.lived.leashed = lived.isLeashed();
+ if (this.lived.leashed) {
+ Location location = lived.getLeashHolder().getLocation();
+ this.lived.leashX = (short) (this.x - location.getBlockX());
+ this.lived.leashY = (short) (this.y - location.getBlockY());
+ this.lived.leashZ = (short) (this.z - location.getBlockZ());
+ }
+ EntityEquipment equipment = lived.getEquipment();
+ this.lived.equipped = equipment != null;
+ if (this.lived.equipped) {
+ storeEquipment(equipment);
+ }
}
- }
- public void storeLiving(LivingEntity lived) {
- this.lived = new LivingEntityStats();
- this.lived.potions = lived.getActivePotionEffects();
- this.lived.loot = lived.getCanPickupItems();
- this.lived.name = lived.getCustomName();
- this.lived.visible = lived.isCustomNameVisible();
- this.lived.health = (float) lived.getHealth();
- this.lived.air = (short) lived.getRemainingAir();
- this.lived.persistent = lived.getRemoveWhenFarAway();
- this.lived.leashed = lived.isLeashed();
- if (this.lived.leashed) {
- Location location = lived.getLeashHolder().getLocation();
- this.lived.leashX = (short) (this.x - location.getBlockX());
- this.lived.leashY = (short) (this.y - location.getBlockY());
- this.lived.leashZ = (short) (this.z - location.getBlockZ());
+ void storeEquipment(EntityEquipment equipment) {
+ this.lived.mainHand = equipment.getItemInMainHand().clone();
+ this.lived.offHand = equipment.getItemInOffHand().clone();
+ this.lived.boots = equipment.getBoots().clone();
+ this.lived.leggings = equipment.getLeggings().clone();
+ this.lived.chestplate = equipment.getChestplate().clone();
+ this.lived.helmet = equipment.getHelmet().clone();
}
- EntityEquipment equipment = lived.getEquipment();
- this.lived.equipped = equipment != null;
- if (this.lived.equipped) {
- storeEquipment(equipment);
- }
- }
- void storeEquipment(EntityEquipment equipment) {
- this.lived.mainHand = equipment.getItemInMainHand().clone();
- this.lived.offHand = equipment.getItemInOffHand().clone();
- this.lived.boots = equipment.getBoots().clone();
- this.lived.leggings = equipment.getLeggings().clone();
- this.lived.chestplate = equipment.getChestplate().clone();
- this.lived.helmet = equipment.getHelmet().clone();
- }
+ private void restoreTameable(Tameable entity) {
+ if (this.tamed.tamed) {
+ if (this.tamed.owner != null) {
+ entity.setTamed(true);
+ entity.setOwner(this.tamed.owner);
+ }
+ }
+ }
- private void restoreTameable(Tameable entity) {
- if (this.tamed.tamed) {
- if (this.tamed.owner != null) {
- entity.setTamed(true);
- entity.setOwner(this.tamed.owner);
- }
+ private void restoreAgeable(Ageable entity) {
+ if (!this.aged.adult) {
+ entity.setBaby();
+ }
+ entity.setAgeLock(this.aged.locked);
+ if (this.aged.age > 0) {
+ entity.setAge(this.aged.age);
+ }
}
- }
- private void restoreAgeable(Ageable entity) {
- if (!this.aged.adult) {
- entity.setBaby();
+ public void storeAgeable(Ageable aged) {
+ this.aged = new AgeableStats();
+ this.aged.age = aged.getAge();
+ this.aged.locked = aged.getAgeLock();
+ this.aged.adult = aged.isAdult();
}
- entity.setAgeLock(this.aged.locked);
- if (this.aged.age > 0) {
- entity.setAge(this.aged.age);
- }
- }
- public void storeAgeable(Ageable aged) {
- this.aged = new AgeableStats();
- this.aged.age = aged.getAge();
- this.aged.locked = aged.getAgeLock();
- this.aged.adult = aged.isAdult();
- }
+ public void storeTameable(Tameable tamed) {
+ this.tamed = new TameableStats();
+ this.tamed.owner = tamed.getOwner();
+ this.tamed.tamed = tamed.isTamed();
+ }
- public void storeTameable(Tameable tamed) {
- this.tamed = new TameableStats();
- this.tamed.owner = tamed.getOwner();
- this.tamed.tamed = tamed.isTamed();
- }
+ @Override public Entity spawn(World world, int xOffset, int zOffset) {
+ Location location = new Location(world, this.x + xOffset, this.y, this.z + zOffset);
+ location.setYaw(this.yaw);
+ location.setPitch(this.pitch);
+ if (!this.getType().isSpawnable()) {
+ return null;
+ }
+ Entity entity;
+ switch (this.getType()) {
+ case DROPPED_ITEM:
+ return world.dropItem(location, this.stack);
+ case PLAYER:
+ case LEASH_HITCH:
+ return null;
+ case ITEM_FRAME:
+ entity = world.spawn(location, ItemFrame.class);
+ break;
+ case PAINTING:
+ entity = world.spawn(location, Painting.class);
+ break;
+ default:
+ entity = world.spawnEntity(location, this.getType());
+ break;
+ }
+ if (this.depth == 0) {
+ return entity;
+ }
+ if (this.base.passenger != null) {
+ entity.addPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
+ }
+ if (this.base.fall != 0) {
+ entity.setFallDistance(this.base.fall);
+ }
+ if (this.base.fire != 0) {
+ entity.setFireTicks(this.base.fire);
+ }
+ if (this.base.age != 0) {
+ entity.setTicksLived(this.base.age);
+ }
+ entity.setVelocity(new Vector(this.base.vX, this.base.vY, this.base.vZ));
+ if (this.depth == 1) {
+ return entity;
+ }
+ if (this.noGravity) {
+ entity.setGravity(false);
+ }
+ switch (entity.getType()) {
+ case BOAT:
+ Boat boat = (Boat) entity;
+ boat.setWoodType(TreeSpecies.values()[dataByte]);
+ return entity;
+ case SLIME:
+ ((Slime) entity).setSize(this.dataByte);
+ return entity;
+ case ARROW:
+ case COMPLEX_PART:
+ case EGG:
+ case ENDER_CRYSTAL:
+ case ENDER_PEARL:
+ case ENDER_SIGNAL:
+ case DROPPED_ITEM:
+ case EXPERIENCE_ORB:
+ case FALLING_BLOCK:
+ case FIREBALL:
+ case FIREWORK:
+ case FISHING_HOOK:
+ case LEASH_HITCH:
+ case LIGHTNING:
+ case MINECART:
+ case MINECART_COMMAND:
+ case MINECART_MOB_SPAWNER:
+ case MINECART_TNT:
+ case PLAYER:
+ case PRIMED_TNT:
+ case SMALL_FIREBALL:
+ case SNOWBALL:
+ case SPLASH_POTION:
+ case THROWN_EXP_BOTTLE:
+ case WEATHER:
+ case TIPPED_ARROW:
+ case SPECTRAL_ARROW:
+ case SHULKER_BULLET:
+ case LINGERING_POTION:
+ case AREA_EFFECT_CLOUD:
+ case DRAGON_FIREBALL:
+ case WITHER_SKULL:
+ case MINECART_FURNACE:
+ case UNKNOWN:
+ // Do this stuff later
+ return entity;
+ // MISC //
+ case ITEM_FRAME:
+ ItemFrame itemframe = (ItemFrame) entity;
+ itemframe.setRotation(Rotation.values()[this.dataByte]);
+ itemframe.setItem(this.stack);
+ return entity;
+ case PAINTING:
+ Painting painting = (Painting) entity;
+ painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
+ painting.setArt(Art.getByName(this.dataString), true);
+ return entity;
+ // END MISC //
+ // INVENTORY HOLDER //
+ case MINECART_CHEST:
+ case MINECART_HOPPER:
+ restoreInventory((InventoryHolder) entity);
+ return entity;
+ // START LIVING ENTITY //
+ // START AGEABLE //
+ // START TAMEABLE //
+ case HORSE:
+ Horse horse = (Horse) entity;
+ horse.setJumpStrength(this.horse.jump);
+ if (horse instanceof ChestedHorse && this.horse.chest) {
+ ((ChestedHorse) horse).setCarryingChest(true);
+ }
+ //todo broken in 1.13 possible exception thrown
+ horse.setVariant(this.horse.variant);
+ horse.setStyle(this.horse.style);
+ horse.setColor(this.horse.color);
+ restoreTameable(horse);
+ restoreAgeable(horse);
+ restoreLiving(horse);
+ restoreInventory(horse);
+ return entity;
+ // END INVENTORY HOLDER //
+ case WOLF:
+ case OCELOT:
+ restoreTameable((Tameable) entity);
+ restoreAgeable((Ageable) entity);
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ // END AGEABLE //
+ case SHEEP:
+ Sheep sheep = (Sheep) entity;
+ if (this.dataByte == 1) {
+ sheep.setSheared(true);
+ }
+ if (this.dataByte2 != 0) {
+ sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
+ }
+ restoreAgeable(sheep);
+ restoreLiving(sheep);
+ return sheep;
+ case VILLAGER:
+ case CHICKEN:
+ case COW:
+ case POLAR_BEAR:
+ case MUSHROOM_COW:
+ case PIG:
+ restoreAgeable((Ageable) entity);
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ // END AGEABLE //
+ case RABBIT:
+ if (this.dataByte != 0) {
+ ((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
+ }
+ restoreAgeable((Ageable) entity);
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ case GUARDIAN:
+ if (this.dataByte != 0) {
+ //todo broken in 1.13 possible exception thrown
- @Override
- public Entity spawn(World world, int xOffset, int zOffset) {
- Location location = new Location(world, this.x + xOffset, this.y, this.z + zOffset);
- location.setYaw(this.yaw);
- location.setPitch(this.pitch);
- if (!this.getType().isSpawnable()) {
- return null;
- }
- Entity entity;
- switch (this.getType()) {
- case DROPPED_ITEM:
- return world.dropItem(location, this.stack);
- case PLAYER:
- case LEASH_HITCH:
- return null;
- case ITEM_FRAME:
- entity = world.spawn(location, ItemFrame.class);
- break;
- case PAINTING:
- entity = world.spawn(location, Painting.class);
- break;
- default:
- entity = world.spawnEntity(location, this.getType());
- break;
- }
- if (this.depth == 0) {
- return entity;
- }
- if (this.base.passenger != null) {
- entity.addPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
- }
- if (this.base.fall != 0) {
- entity.setFallDistance(this.base.fall);
- }
- if (this.base.fire != 0) {
- entity.setFireTicks(this.base.fire);
- }
- if (this.base.age != 0) {
- entity.setTicksLived(this.base.age);
- }
- entity.setVelocity(new Vector(this.base.vX, this.base.vY, this.base.vZ));
- if (this.depth == 1) {
- return entity;
- }
- if (this.noGravity) {
- entity.setGravity(false);
- }
- switch (entity.getType()) {
- case BOAT:
- Boat boat = (Boat) entity;
- boat.setWoodType(TreeSpecies.values()[dataByte]);
- return entity;
- case SLIME:
- ((Slime) entity).setSize(this.dataByte);
- return entity;
- case ARROW:
- case COMPLEX_PART:
- case EGG:
- case ENDER_CRYSTAL:
- case ENDER_PEARL:
- case ENDER_SIGNAL:
- case DROPPED_ITEM:
- case EXPERIENCE_ORB:
- case FALLING_BLOCK:
- case FIREBALL:
- case FIREWORK:
- case FISHING_HOOK:
- case LEASH_HITCH:
- case LIGHTNING:
- case MINECART:
- case MINECART_COMMAND:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT:
- case PLAYER:
- case PRIMED_TNT:
- case SMALL_FIREBALL:
- case SNOWBALL:
- case SPLASH_POTION:
- case THROWN_EXP_BOTTLE:
- case WEATHER:
- case TIPPED_ARROW:
- case SPECTRAL_ARROW:
- case SHULKER_BULLET:
- case LINGERING_POTION:
- case AREA_EFFECT_CLOUD:
- case DRAGON_FIREBALL:
- case WITHER_SKULL:
- case MINECART_FURNACE:
- case UNKNOWN:
- // Do this stuff later
- return entity;
- // MISC //
- case ITEM_FRAME:
- ItemFrame itemframe = (ItemFrame) entity;
- itemframe.setRotation(Rotation.values()[this.dataByte]);
- itemframe.setItem(this.stack);
- return entity;
- case PAINTING:
- Painting painting = (Painting) entity;
- painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
- painting.setArt(Art.getByName(this.dataString), true);
- return entity;
- // END MISC //
- // INVENTORY HOLDER //
- case MINECART_CHEST:
- case MINECART_HOPPER:
- restoreInventory((InventoryHolder) entity);
- return entity;
- // START LIVING ENTITY //
- // START AGEABLE //
- // START TAMEABLE //
- case HORSE:
- Horse horse = (Horse) entity;
- horse.setJumpStrength(this.horse.jump);
- if (horse instanceof ChestedHorse && this.horse.chest) {
- ((ChestedHorse) horse).setCarryingChest(true);
+ ((Guardian) entity).setElder(true);
+ }
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ case SKELETON:
+ if (this.dataByte != 0) {
+ //todo broken in 1.13 possible exception thrown
+ ((Skeleton) entity)
+ .setSkeletonType(Skeleton.SkeletonType.values()[this.dataByte]);
+ }
+ storeLiving((LivingEntity) entity);
+ return entity;
+ case ARMOR_STAND:
+ // CHECK positions
+ ArmorStand stand = (ArmorStand) entity;
+ if (this.inventory[0] != null) {
+ stand.setItemInHand(this.inventory[0]);
+ }
+ if (this.inventory[1] != null) {
+ stand.setHelmet(this.inventory[1]);
+ }
+ if (this.inventory[2] != null) {
+ stand.setChestplate(this.inventory[2]);
+ }
+ if (this.inventory[3] != null) {
+ stand.setLeggings(this.inventory[3]);
+ }
+ if (this.inventory[4] != null) {
+ stand.setBoots(this.inventory[4]);
+ }
+ if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
+ EulerAngle pose =
+ new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
+ stand.setHeadPose(pose);
+ }
+ if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
+ EulerAngle pose =
+ new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
+ stand.setBodyPose(pose);
+ }
+ if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0
+ || this.stand.leftLeg[2] != 0) {
+ EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
+ this.stand.leftLeg[2]);
+ stand.setLeftLegPose(pose);
+ }
+ if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0
+ || this.stand.rightLeg[2] != 0) {
+ EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
+ this.stand.rightLeg[2]);
+ stand.setRightLegPose(pose);
+ }
+ if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0
+ || this.stand.leftArm[2] != 0) {
+ EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
+ this.stand.leftArm[2]);
+ stand.setLeftArmPose(pose);
+ }
+ if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0
+ || this.stand.rightArm[2] != 0) {
+ EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
+ this.stand.rightArm[2]);
+ stand.setRightArmPose(pose);
+ }
+ if (this.stand.invisible) {
+ stand.setVisible(false);
+ }
+ if (this.stand.arms) {
+ stand.setArms(true);
+ }
+ if (this.stand.noPlate) {
+ stand.setBasePlate(false);
+ }
+ if (this.stand.small) {
+ stand.setSmall(true);
+ }
+ restoreLiving(stand);
+ return stand;
+ case BAT:
+ if (this.dataByte != 0) {
+ ((Bat) entity).setAwake(true);
+ }
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ case ENDER_DRAGON:
+ if (this.dataByte != 0) {
+ ((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
+ }
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ case ENDERMITE:
+ case GHAST:
+ case MAGMA_CUBE:
+ case SQUID:
+ case PIG_ZOMBIE:
+ case ZOMBIE:
+ case WITHER:
+ case WITCH:
+ case SPIDER:
+ case CAVE_SPIDER:
+ case SILVERFISH:
+ case GIANT:
+ case ENDERMAN:
+ case CREEPER:
+ case BLAZE:
+ case SNOWMAN:
+ case SHULKER:
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ case IRON_GOLEM:
+ if (this.dataByte != 0) {
+ ((IronGolem) entity).setPlayerCreated(true);
+ }
+ restoreLiving((LivingEntity) entity);
+ return entity;
+ default:
+ PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
+ return entity;
+ // END LIVING
}
- //todo broken in 1.13 possible exception thrown
- horse.setVariant(this.horse.variant);
- horse.setStyle(this.horse.style);
- horse.setColor(this.horse.color);
- restoreTameable(horse);
- restoreAgeable(horse);
- restoreLiving(horse);
- restoreInventory(horse);
- return entity;
- // END INVENTORY HOLDER //
- case WOLF:
- case OCELOT:
- restoreTameable((Tameable) entity);
- restoreAgeable((Ageable) entity);
- restoreLiving((LivingEntity) entity);
- return entity;
- // END AGEABLE //
- case SHEEP:
- Sheep sheep = (Sheep) entity;
- if (this.dataByte == 1) {
- sheep.setSheared(true);
- }
- if (this.dataByte2 != 0) {
- sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
- }
- restoreAgeable(sheep);
- restoreLiving(sheep);
- return sheep;
- case VILLAGER:
- case CHICKEN:
- case COW:
- case POLAR_BEAR:
- case MUSHROOM_COW:
- case PIG:
- restoreAgeable((Ageable) entity);
- restoreLiving((LivingEntity) entity);
- return entity;
- // END AGEABLE //
- case RABBIT:
- if (this.dataByte != 0) {
- ((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
- }
- restoreAgeable((Ageable) entity);
- restoreLiving((LivingEntity) entity);
- return entity;
- case GUARDIAN:
- if (this.dataByte != 0) {
- //todo broken in 1.13 possible exception thrown
+ }
- ((Guardian) entity).setElder(true);
- }
- restoreLiving((LivingEntity) entity);
- return entity;
- case SKELETON:
- if (this.dataByte != 0) {
- //todo broken in 1.13 possible exception thrown
- ((Skeleton) entity)
- .setSkeletonType(Skeleton.SkeletonType.values()[this.dataByte]);
- }
- storeLiving((LivingEntity) entity);
- return entity;
- case ARMOR_STAND:
- // CHECK positions
- ArmorStand stand = (ArmorStand) entity;
- if (this.inventory[0] != null) {
- stand.setItemInHand(this.inventory[0]);
- }
- if (this.inventory[1] != null) {
- stand.setHelmet(this.inventory[1]);
- }
- if (this.inventory[2] != null) {
- stand.setChestplate(this.inventory[2]);
- }
- if (this.inventory[3] != null) {
- stand.setLeggings(this.inventory[3]);
- }
- if (this.inventory[4] != null) {
- stand.setBoots(this.inventory[4]);
- }
- if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
- EulerAngle pose =
- new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
- stand.setHeadPose(pose);
- }
- if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
- EulerAngle pose =
- new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
- stand.setBodyPose(pose);
- }
- if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0
- || this.stand.leftLeg[2] != 0) {
- EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
- this.stand.leftLeg[2]);
- stand.setLeftLegPose(pose);
- }
- if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0
- || this.stand.rightLeg[2] != 0) {
- EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
- this.stand.rightLeg[2]);
- stand.setRightLegPose(pose);
- }
- if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0
- || this.stand.leftArm[2] != 0) {
- EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
- this.stand.leftArm[2]);
- stand.setLeftArmPose(pose);
- }
- if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0
- || this.stand.rightArm[2] != 0) {
- EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
- this.stand.rightArm[2]);
- stand.setRightArmPose(pose);
- }
- if (this.stand.invisible) {
- stand.setVisible(false);
- }
- if (this.stand.arms) {
- stand.setArms(true);
- }
- if (this.stand.noPlate) {
- stand.setBasePlate(false);
- }
- if (this.stand.small) {
- stand.setSmall(true);
- }
- restoreLiving(stand);
- return stand;
- case BAT:
- if (this.dataByte != 0) {
- ((Bat) entity).setAwake(true);
- }
- restoreLiving((LivingEntity) entity);
- return entity;
- case ENDER_DRAGON:
- if (this.dataByte != 0) {
- ((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
- }
- restoreLiving((LivingEntity) entity);
- return entity;
- case ENDERMITE:
- case GHAST:
- case MAGMA_CUBE:
- case SQUID:
- case PIG_ZOMBIE:
- case ZOMBIE:
- case WITHER:
- case WITCH:
- case SPIDER:
- case CAVE_SPIDER:
- case SILVERFISH:
- case GIANT:
- case ENDERMAN:
- case CREEPER:
- case BLAZE:
- case SNOWMAN:
- case SHULKER:
- restoreLiving((LivingEntity) entity);
- return entity;
- case IRON_GOLEM:
- if (this.dataByte != 0) {
- ((IronGolem) entity).setPlayerCreated(true);
- }
- restoreLiving((LivingEntity) entity);
- return entity;
- default:
- PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
- return entity;
- // END LIVING
+ public void saveEntity() {
}
- }
- public void saveEntity() {
- }
-
- private byte getOrdinal(Object[] list, Object value) {
- for (byte i = 0; i < list.length; i++) {
- if (list[i].equals(value)) {
- return i;
- }
+ private byte getOrdinal(Object[] list, Object value) {
+ for (byte i = 0; i < list.length; i++) {
+ if (list[i].equals(value)) {
+ return i;
+ }
+ }
+ return 0;
}
- return 0;
- }
}
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 d1eaa9081..4815c2e01 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
@@ -14,13 +14,13 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.Damageable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.bukkit.inventory.meta.Damageable;
public class StateWrapper {
@@ -242,7 +242,7 @@ public class StateWrapper {
public Map serializeItem(ItemStack item) {
Map data = new HashMap<>();
data.put("id", new StringTag(item.getType().name()));
- data.put("Damage", new ShortTag((short) ((Damageable)item.getItemMeta()).getDamage()));
+ data.put("Damage", new ShortTag((short) ((Damageable) item.getItemMeta()).getDamage()));
data.put("Count", new ByteTag((byte) item.getAmount()));
if (!item.getEnchantments().isEmpty()) {
List enchantmentList = new 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 34e392a27..5a4cf885a 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
@@ -61,11 +61,13 @@ public final class BukkitEventUtil extends EventUtil {
}
@Override public boolean callMerge(Plot plot, int dir, int max) {
- return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, dir, max));
+ return callEvent(
+ new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, dir, max));
}
@Override public boolean callAutoMerge(Plot plot, List plots) {
- return callEvent(new PlotAutoMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
+ return callEvent(
+ new PlotAutoMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
}
@Override public boolean callUnlink(PlotArea area, List plots) {
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 452d04c35..395523f35 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
@@ -110,7 +110,7 @@ public class BukkitHybridUtils extends HybridUtils {
rz[i] = v;
}
int minY;
- if ( Settings.Schematics.PASTE_ON_TOP) {
+ if (Settings.Schematics.PASTE_ON_TOP) {
minY = Math.min(hpw.PLOT_HEIGHT, hpw.ROAD_HEIGHT);
} else {
minY = 1;
@@ -162,9 +162,7 @@ public class BukkitHybridUtils extends HybridUtils {
continue;
}
int y = MainUtil.y_loc[i][j];
- oldBlocks[y][x][z] = result[i][j] != null ?
- result[i][j] :
- airBucket;
+ oldBlocks[y][x][z] = result[i][j] != null ? result[i][j] : airBucket;
}
}
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
index e9ec7742f..bc5265114 100644
--- 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
@@ -1,6 +1,5 @@
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;
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 41e515cc7..6be193778 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
@@ -1,7 +1,5 @@
package com.github.intellectualsites.plotsquared.bukkit.util;
-import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
-
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc;
@@ -14,15 +12,18 @@ 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 org.bukkit.Bukkit;
+import org.bukkit.Chunk;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
-import org.bukkit.Bukkit;
-import org.bukkit.Chunk;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
+
+import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
/**
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy
@@ -30,33 +31,33 @@ import org.bukkit.entity.Player;
*/
public class SendChunk {
- private final RefMethod methodGetHandlePlayer;
- private final RefMethod methodGetHandleChunk;
- private final RefConstructor mapChunk;
- private final RefField connection;
- private final RefMethod send;
- private final RefMethod methodInitLighting;
+ private final RefMethod methodGetHandlePlayer;
+ private final RefMethod methodGetHandleChunk;
+ private final RefConstructor mapChunk;
+ private final RefField connection;
+ private final RefMethod send;
+ private final RefMethod methodInitLighting;
- /**
- * Constructor.
- */
- public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
- RefConstructor tempMapChunk;
- RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
- this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
- RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
- this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
- RefClass classChunk = getRefClass("{nms}.Chunk");
- this.methodInitLighting = classChunk.getMethod("initLighting");
- RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
- tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
- this.mapChunk = tempMapChunk;
- RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
- this.connection = classEntityPlayer.getField("playerConnection");
- RefClass classPacket = getRefClass("{nms}.Packet");
- RefClass classConnection = getRefClass("{nms}.PlayerConnection");
- this.send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
- }
+ /**
+ * Constructor.
+ */
+ public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
+ RefConstructor tempMapChunk;
+ RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
+ this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
+ RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
+ this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
+ RefClass classChunk = getRefClass("{nms}.Chunk");
+ this.methodInitLighting = classChunk.getMethod("initLighting");
+ RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
+ tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
+ this.mapChunk = tempMapChunk;
+ RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
+ this.connection = classEntityPlayer.getField("playerConnection");
+ RefClass classPacket = getRefClass("{nms}.Packet");
+ RefClass classConnection = getRefClass("{nms}.PlayerConnection");
+ this.send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
+ }
public void sendChunk(Collection input) {
HashSet chunks = new HashSet<>(input);
@@ -96,52 +97,51 @@ public class SendChunk {
Player player = ((BukkitPlayer) pp).player;
Object entity = this.methodGetHandlePlayer.of(player).call();
- for (Chunk chunk : list) {
- int dx = Math.abs(cx - chunk.getX());
- int dz = Math.abs(cz - chunk.getZ());
- if ((dx > view) || (dz > view)) {
- continue;
+ for (Chunk chunk : list) {
+ int dx = Math.abs(cx - chunk.getX());
+ int dz = Math.abs(cz - chunk.getZ());
+ if ((dx > view) || (dz > view)) {
+ continue;
+ }
+ Object c = this.methodGetHandleChunk.of(chunk).call();
+ chunks.remove(chunk);
+ Object con = this.connection.of(entity).get();
+ Object packet = null;
+ try {
+ packet = this.mapChunk.create(c, 65535);
+ } catch (Exception ignored) {
+ }
+ if (packet == null) {
+ PlotSquared.debug("Error with PacketPlayOutMapChunk reflection.");
+ }
+ this.send.of(con).call(packet);
+ }
}
- Object c = this.methodGetHandleChunk.of(chunk).call();
- chunks.remove(chunk);
- Object con = this.connection.of(entity).get();
- Object packet = null;
- try {
- packet = this.mapChunk.create(c, 65535);
- } catch (Exception ignored) {
+ for (final Chunk chunk : chunks) {
+ TaskManager.runTask(() -> {
+ try {
+ chunk.unload(true, false);
+ } catch (Throwable ignored) {
+ String worldName = chunk.getWorld().getName();
+ PlotSquared.debug(
+ "$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";" + chunk
+ .getZ());
+ PlotSquared.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
+ PlotSquared.debug("$3 - $4" + worldName + "/level.dat or " + worldName
+ + "/level_old.dat may be corrupt (try repairing or removing these)");
+ }
+ });
}
- if (packet == null) {
- PlotSquared.debug("Error with PacketPlayOutMapChunk reflection.");
- }
- this.send.of(con).call(packet);
- }
}
- for (final Chunk chunk : chunks) {
- TaskManager.runTask(() -> {
- try {
- chunk.unload(true, false);
- } catch (Throwable ignored) {
- String worldName = chunk.getWorld().getName();
- PlotSquared.debug(
- "$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";"
- + chunk.getZ());
- PlotSquared
- .debug("$3 - $4File may be open in another process (e.g. MCEdit)");
- PlotSquared.debug("$3 - $4" + worldName + "/level.dat or " + worldName
- + "/level_old.dat may be corrupt (try repairing or removing these)");
- }
- });
- }
- }
- 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)) {
- chunks.add(myWorld.getChunkAt(loc.x, loc.z));
- }
+ 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)) {
+ chunks.add(myWorld.getChunkAt(loc.x, loc.z));
+ }
+ }
+ sendChunk(chunks);
}
- sendChunk(chunks);
- }
}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java
index aaa94dbeb..40305cca5 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java
@@ -5,10 +5,10 @@ import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
-import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
+import java.util.Arrays;
import java.util.UUID;
public class DefaultUUIDWrapper implements UUIDWrapper {
@@ -31,8 +31,7 @@ public class DefaultUUIDWrapper implements UUIDWrapper {
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
- return Arrays.stream(ops).map(BukkitOfflinePlayer::new)
- .toArray(BukkitOfflinePlayer[]::new);
+ return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
}
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/FileUUIDHandler.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/FileUUIDHandler.java
index a8e2278b4..42a83f466 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/FileUUIDHandler.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/FileUUIDHandler.java
@@ -80,13 +80,11 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
e.printStackTrace();
}
}
- HashBiMap toAdd =
- HashBiMap.create(new HashMap<>());
+ HashBiMap toAdd = HashBiMap.create(new HashMap<>());
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
HashSet all = UUIDHandler.getAllUUIDS();
PlotSquared.debug("&aFast mode UUID caching enabled!");
- File playerDataFolder =
- new File(container, world + File.separator + "playerdata");
+ File playerDataFolder = new File(container, world + File.separator + "playerdata");
String[] dat = playerDataFolder.list(new DatFileFilter());
boolean check = all.isEmpty();
if (dat != null) {
@@ -128,8 +126,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
}
return;
} else {
- PlotSquared.debug("Failed to cache: " + all.size()
- + " uuids - slowly processing all files");
+ PlotSquared.debug(
+ "Failed to cache: " + all.size() + " uuids - slowly processing all files");
}
}
HashSet worlds1 = Sets.newHashSet(world, "world");
@@ -138,8 +136,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
File playerDataFolder = null;
for (String worldName : worlds1) {
// Getting UUIDs
- playerDataFolder =
- new File(container, worldName + File.separator + "playerdata");
+ playerDataFolder = new File(container, worldName + File.separator + "playerdata");
String[] dat = playerDataFolder.list(new DatFileFilter());
if ((dat != null) && (dat.length != 0)) {
for (String current : dat) {
@@ -213,8 +210,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
}
if (getUUIDMap().isEmpty()) {
- for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper
- .getOfflinePlayers()) {
+ for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper.getOfflinePlayers()) {
long last = op.getLastPlayed();
if (last != 0) {
String name = op.getName();
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java
index c06c7a3cc..0f3b4d5ea 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java
@@ -9,7 +9,6 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
-import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
@@ -17,6 +16,7 @@ import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
@@ -93,8 +93,7 @@ public class OfflineUUIDWrapper implements UUIDWrapper {
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
- return Arrays.stream(ops).map(BukkitOfflinePlayer::new)
- .toArray(BukkitOfflinePlayer[]::new);
+ return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
}
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/SQLUUIDHandler.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/SQLUUIDHandler.java
index 04f0b146c..234059e02 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/SQLUUIDHandler.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/SQLUUIDHandler.java
@@ -73,14 +73,12 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
}
TaskManager.runTaskAsync(() -> {
try {
- HashBiMap toAdd =
- HashBiMap.create(new HashMap<>());
+ HashBiMap toAdd = HashBiMap.create(new HashMap<>());
try (PreparedStatement statement = getConnection()
.prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
- StringWrapper username =
- new StringWrapper(resultSet.getString("username"));
+ StringWrapper username = new StringWrapper(resultSet.getString("username"));
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
toAdd.put(new StringWrapper(username.value), uuid);
}
@@ -99,8 +97,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
}
return;
}
- FileUUIDHandler fileHandler =
- new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
+ FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
fileHandler.startCaching(() -> {
// If the file based UUID handler didn't cache it, then we can't cache offline mode
// Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
@@ -114,18 +111,13 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
TaskManager.runTaskAsync(() -> {
while (!toFetch.isEmpty()) {
try {
- for (int i = 0;
- i < Math.min(500, toFetch.size()); i++) {
+ for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
UUID uuid = toFetch.pop();
- HttpURLConnection connection =
- (HttpURLConnection) new URL(
- SQLUUIDHandler.this.PROFILE_URL + uuid
- .toString().replace("-", ""))
- .openConnection();
- try (InputStream con = connection
- .getInputStream()) {
- InputStreamReader reader =
- new InputStreamReader(con);
+ HttpURLConnection connection = (HttpURLConnection) new URL(
+ SQLUUIDHandler.this.PROFILE_URL + uuid.toString()
+ .replace("-", "")).openConnection();
+ try (InputStream con = connection.getInputStream()) {
+ InputStreamReader reader = new InputStreamReader(con);
JSONObject response =
(JSONObject) SQLUUIDHandler.this.jsonParser
.parse(reader);
@@ -208,13 +200,12 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
// Ignoring duplicates
if (super.add(name, uuid)) {
TaskManager.runTaskAsync(() -> {
- try (PreparedStatement statement = getConnection().prepareStatement(
- "REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
+ try (PreparedStatement statement = getConnection()
+ .prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
statement.setString(1, uuid.toString());
statement.setString(2, name.toString());
statement.execute();
- PlotSquared
- .debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
+ PlotSquared.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
} catch (SQLException e) {
e.printStackTrace();
}
@@ -235,8 +226,8 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
statement.setString(1, name.value);
statement.setString(2, uuid.toString());
statement.execute();
- PlotSquared.debug(
- C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
+ PlotSquared
+ .debug(C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
} catch (SQLException e) {
e.printStackTrace();
}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/Argument.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/Argument.java
deleted file mode 100644
index dd5221a3a..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/Argument.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.github.intellectualsites.plotsquared.commands;
-
-import com.github.intellectualsites.plotsquared.plot.object.PlotId;
-
-public abstract class Argument {
-
- public static final Argument Integer = new Argument("int", 16) {
- @Override public Integer parse(String in) {
- Integer value = null;
- try {
- value = java.lang.Integer.parseInt(in);
- } catch (Exception ignored) {
- }
- return value;
- }
- };
- public static final Argument Boolean = new Argument("boolean", true) {
- @Override public Boolean parse(String in) {
- Boolean value = null;
- if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in
- .equalsIgnoreCase("1")) {
- value = true;
- } else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in
- .equalsIgnoreCase("0")) {
- value = false;
- }
- return value;
- }
- };
- public static final Argument String = new Argument("String", "Example") {
- @Override public String parse(String in) {
- return in;
- }
- };
- public static final Argument PlayerName =
- new Argument("PlayerName", "Dinnerbone") {
- @Override public String parse(String in) {
- return in.length() <= 16 ? in : null;
- }
- };
- public static final Argument PlotID =
- new Argument("PlotID", new PlotId(-6, 3)) {
- @Override public PlotId parse(String in) {
- return PlotId.fromString(in);
- }
- };
- private final String name;
- private final T example;
-
- public Argument(String name, T example) {
- this.name = name;
- this.example = example;
- }
-
- public abstract T parse(String in);
-
- @Override public final String toString() {
- return this.getName();
- }
-
- public final String getName() {
- return this.name;
- }
-
- public final T getExample() {
- return this.example;
- }
-}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java
deleted file mode 100644
index 6bac09a26..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java
+++ /dev/null
@@ -1,596 +0,0 @@
-package com.github.intellectualsites.plotsquared.commands;
-
-import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
-import com.github.intellectualsites.plotsquared.plot.PlotSquared;
-import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
-import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
-import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
-import com.github.intellectualsites.plotsquared.plot.config.C;
-import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
-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.*;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.*;
-
-public abstract class Command {
-
- // May be none
- private final ArrayList allCommands = new ArrayList<>();
- private final ArrayList dynamicCommands = new ArrayList<>();
- private final HashMap staticCommands = new HashMap<>();
-
- // Parent command (may be null)
- private final Command parent;
- private final boolean isStatic;
- // The command ID
- private String id;
- private List aliases;
- private RequiredType required;
- private String usage;
- private String description;
- private String perm;
- private boolean confirmation;
- private CommandCategory category;
- private Argument[] arguments;
-
- public Command(Command parent, boolean isStatic, String id, String perm, RequiredType required,
- CommandCategory cat) {
- this.parent = parent;
- this.isStatic = isStatic;
- this.id = id;
- this.perm = perm;
- this.required = required;
- this.category = cat;
- this.aliases = Arrays.asList(id);
- if (this.parent != null) {
- this.parent.register(this);
- }
- }
-
- public Command(Command parent, boolean isStatic) {
- this.parent = parent;
- this.isStatic = isStatic;
- Annotation cdAnnotation = getClass().getAnnotation(CommandDeclaration.class);
- if (cdAnnotation != null) {
- CommandDeclaration declaration = (CommandDeclaration) cdAnnotation;
- init(declaration);
- }
- for (final Method method : getClass().getDeclaredMethods()) {
- if (method.isAnnotationPresent(CommandDeclaration.class)) {
- Class>[] types = method.getParameterTypes();
- // final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2
- // whenDone
- if (types.length == 5 && types[0] == Command.class && types[1] == PlotPlayer.class
- && types[2] == String[].class && types[3] == RunnableVal3.class
- && types[4] == RunnableVal2.class) {
- Command tmp = new Command(this, true) {
- @Override public void execute(PlotPlayer player, String[] args,
- RunnableVal3 confirm,
- RunnableVal2 whenDone) {
- try {
- method.invoke(Command.this, this, player, args, confirm, whenDone);
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- };
- tmp.init(method.getAnnotation(CommandDeclaration.class));
- }
- }
- }
- }
-
- public Command getParent() {
- return this.parent;
- }
-
- public String getId() {
- return this.id;
- }
-
- public String getFullId() {
- if (this.parent != null && this.parent.getParent() != null) {
- return this.parent.getFullId() + "." + this.id;
- }
- return this.id;
- }
-
- public List getCommands(PlotPlayer player) {
- List commands = new ArrayList<>();
- for (Command cmd : this.allCommands) {
- if (cmd.canExecute(player, false)) {
- commands.add(cmd);
- }
- }
- return commands;
- }
-
- public List getCommands(CommandCategory cat, PlotPlayer player) {
- List commands = getCommands(player);
- if (cat != null) {
- Iterator iterator = commands.iterator();
- while (iterator.hasNext()) {
- if (iterator.next().category != cat) {
- iterator.remove();
- }
- }
- }
- return commands;
- }
-
- public List getCommands() {
- return this.allCommands;
- }
-
- public boolean hasConfirmation(PlotPlayer player) {
- return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
- }
-
- public List getAliases() {
- return this.aliases;
- }
-
- public String getDescription() {
- return this.description;
- }
-
- public RequiredType getRequiredType() {
- return this.required;
- }
-
- public Argument[] getRequiredArguments() {
- return this.arguments;
- }
-
- public void setRequiredArguments(Argument[] arguments) {
- this.arguments = arguments;
- }
-
- public void init(CommandDeclaration declaration) {
- this.id = declaration.command();
- this.perm = declaration.permission();
- this.required = declaration.requiredType();
- this.category = declaration.category();
- HashMap options = new HashMap<>();
- List aliasOptions = new ArrayList<>();
- aliasOptions.add(this.id);
- aliasOptions.addAll(Arrays.asList(declaration.aliases()));
- options.put("aliases", aliasOptions);
- options.put("description", declaration.description());
- options.put("usage", declaration.usage());
- options.put("confirmation", declaration.confirmation());
- boolean set = false;
- YamlConfiguration commands =
- PlotSquared.get() == null ? new YamlConfiguration() : PlotSquared.get().commands;
- for (Map.Entry entry : options.entrySet()) {
- String key = this.getFullId() + "." + entry.getKey();
- if (!commands.contains(key)) {
- commands.set(key, entry.getValue());
- set = true;
- }
- }
- if (set && PlotSquared.get() != null) {
- try {
- commands.save(PlotSquared.get().commandsFile);
- } catch (IOException e) {
- e.printStackTrace();
-
- }
- }
- this.aliases = commands.getStringList(this.getFullId() + ".aliases");
- this.description = commands.getString(this.getFullId() + ".description");
- this.usage = commands.getString(this.getFullId() + ".usage");
- this.confirmation = commands.getBoolean(this.getFullId() + ".confirmation");
- if (this.parent != null) {
- this.parent.register(this);
- }
- }
-
- public void register(Command command) {
- if (command.isStatic) {
- for (String alias : command.aliases) {
- this.staticCommands.put(alias.toLowerCase(), command);
- }
- } else {
- this.dynamicCommands.add(command);
- }
- this.allCommands.add(command);
- }
-
- public String getPermission() {
- if (this.perm != null && !this.perm.isEmpty()) {
- return this.perm;
- }
- if (this.parent == null) {
- return "plots.use";
- }
- return "plots." + getFullId();
- }
-
- public void paginate(PlotPlayer player, List c, int size, int page,
- RunnableVal3 add, String baseCommand, String header) {
- // Calculate pages & index
- if (page < 0) {
- page = 0;
- }
- int totalPages = (int) Math.ceil(c.size() / size);
- if (page > totalPages) {
- page = totalPages;
- }
- int max = page * size + size;
- if (max > c.size()) {
- max = c.size();
- }
- // Send the header
- header = header.replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "")
- .replaceAll("%amount%", c.size() + "").replaceAll("%word%", "all");
- MainUtil.sendMessage(player, header);
- // Send the page content
- List subList = c.subList(page * size, max);
- int i = page * size;
- for (T obj : subList) {
- i++;
- PlotMessage msg = new PlotMessage();
- add.run(i, obj, msg);
- msg.send(player);
- }
- // Send the footer
- if (page < totalPages && page > 0) { // Back | Next
- new PlotMessage().text("<-").color("$1").command(baseCommand + " " + page).text(" | ")
- .color("$3").text("->").color("$1").command(baseCommand + " " + (page + 2))
- .text(C.CLICKABLE.s()).color("$2").send(player);
- return;
- }
- if (page == 0 && totalPages != 0) { // Next
- new PlotMessage().text("<-").color("$3").text(" | ").color("$3").text("->").color("$1")
- .command(baseCommand + " " + (0 + 2)).text(C.CLICKABLE.s()).color("$2")
- .send(player);
- return;
- }
- if (page == totalPages && totalPages != 0) { // Back
- new PlotMessage().text("<-").color("$1").command(baseCommand + " " + page).text(" | ")
- .color("$3").text("->").color("$3").text(C.CLICKABLE.s()).color("$2").send(player);
- }
- }
-
- /**
- * @param player Caller
- * @param args Arguments
- * @param confirm Instance, Success, Failure
- * @return
- */
- public void execute(PlotPlayer player, String[] args,
- RunnableVal3 confirm,
- RunnableVal2 whenDone) throws CommandException {
- if (args.length == 0 || args[0] == null) {
- if (this.parent == null) {
- MainCommand.getInstance().help.displayHelp(player, null, 0);
- } else {
- C.COMMAND_SYNTAX.send(player, getUsage());
- }
- return;
- }
- if (this.allCommands == null || this.allCommands.isEmpty()) {
- player.sendMessage(
- "Not Implemented: https://github.com/IntellectualSites/PlotSquared/issues/new");
- return;
- }
- Command cmd = getCommand(args[0]);
- if (cmd == null) {
- if (this.parent != null) {
- C.COMMAND_SYNTAX.send(player, getUsage());
- return;
- }
- // Help command
- try {
- if (args.length == 0 || MathMan.isInteger(args[0])
- || CommandCategory.valueOf(args[0].toUpperCase()) != null) {
- // This will default certain syntax to the help command
- // e.g. /plot, /plot 1, /plot claiming
- MainCommand.getInstance().help.execute(player, args, null, null);
- return;
- }
- } catch (IllegalArgumentException ignored) {
- }
- // Command recommendation
- MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
- List commands = getCommands(player);
- if (commands.isEmpty()) {
- MainUtil
- .sendMessage(player, C.DID_YOU_MEAN, MainCommand.getInstance().help.getUsage());
- return;
- }
- HashSet setargs = new HashSet<>(args.length);
- for (String arg : args) {
- setargs.add(arg.toLowerCase());
- }
- String[] allargs = setargs.toArray(new String[setargs.size()]);
- int best = 0;
- for (Command current : commands) {
- int match = getMatch(allargs, current);
- if (match > best) {
- cmd = current;
- }
- }
- if (cmd == null) {
- cmd = new StringComparison<>(args[0], this.allCommands).getMatchObject();
- }
- MainUtil.sendMessage(player, C.DID_YOU_MEAN, cmd.getUsage());
- return;
- }
- String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
- if (!cmd.checkArgs(player, newArgs) || !cmd.canExecute(player, true)) {
- return;
- }
- try {
- cmd.execute(player, newArgs, confirm, whenDone);
- } catch (CommandException e) {
- e.perform(player);
- }
- }
-
- public boolean checkArgs(PlotPlayer player, String[] args) {
- Argument>[] reqArgs = getRequiredArguments();
- if (reqArgs != null && reqArgs.length > 0) {
- boolean failed = args.length < reqArgs.length;
- String[] baseSplit = getCommandString().split(" ");
- String[] fullSplit = getUsage().split(" ");
- String base = getCommandString();
- if (fullSplit.length - baseSplit.length < reqArgs.length) {
- String[] tmp = new String[baseSplit.length + reqArgs.length];
- System.arraycopy(fullSplit, 0, tmp, 0, fullSplit.length);
- fullSplit = tmp;
- }
- for (int i = 0; i < reqArgs.length; i++) {
- fullSplit[i + baseSplit.length] = reqArgs[i].getExample().toString();
- failed = failed || reqArgs[i].parse(args[i]) == null;
- }
- if (failed) {
- C.COMMAND_SYNTAX.send(player, StringMan.join(fullSplit, " "));
- return false;
- }
- }
- return true;
- }
-
- public int getMatch(String[] args, Command cmd) {
- int count = 0;
- String perm = cmd.getPermission();
- HashSet desc = new HashSet<>();
- for (String alias : cmd.getAliases()) {
- if (alias.startsWith(args[0])) {
- count += 5;
- }
- }
- Collections.addAll(desc, cmd.getDescription().split(" "));
- for (String arg : args) {
- if (perm.startsWith(arg)) {
- count++;
- }
- if (desc.contains(arg)) {
- count++;
- }
- }
- String[] usage = cmd.getUsage().split(" ");
- for (int i = 0; i < Math.min(4, usage.length); i++) {
- int require;
- if (usage[i].startsWith("<")) {
- require = 1;
- } else {
- require = 0;
- }
- String[] split = usage[i].split("\\|| |\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/");
- for (String aSplit : split) {
- for (String arg : args) {
- if (StringMan.isEqualIgnoreCase(arg, aSplit)) {
- count += 5 - i + require;
- }
- }
- }
- }
- count += StringMan.intersection(desc, args);
- return count;
- }
-
- public Command getCommand(String arg) {
- Command cmd = this.staticCommands.get(arg.toLowerCase());
- if (cmd == null) {
- for (Command command : this.dynamicCommands) {
- if (command.matches(arg)) {
- return command;
- }
- }
- }
- return cmd;
- }
-
- public Command getCommand(Class clazz) {
- for (Command cmd : this.allCommands) {
- if (cmd.getClass() == clazz) {
- return cmd;
- }
- }
- return null;
- }
-
- public Command getCommandById(String id) {
- Command exact = this.staticCommands.get(id);
- if (exact != null) {
- return exact;
- }
- for (Command cmd : this.allCommands) {
- if (cmd.getId().equals(id)) {
- return cmd;
- }
- }
- return null;
- }
-
- public boolean canExecute(PlotPlayer player, boolean message) {
- if (player == null) {
- return true;
- }
- if (!this.required.allows(player)) {
- if (message) {
- MainUtil.sendMessage(player,
- this.required == RequiredType.PLAYER ? C.IS_CONSOLE : C.NOT_CONSOLE);
- }
- } else if (!Permissions.hasPermission(player, getPermission())) {
- if (message) {
- C.NO_PERMISSION.send(player, getPermission());
- }
- } else {
- return true;
- }
- return false;
- }
-
- public boolean matches(String arg) {
- arg = arg.toLowerCase();
- return StringMan.isEqual(arg, this.id) || this.aliases.contains(arg);
- }
-
- public String getCommandString() {
- String base;
- if (this.parent == null) {
- return "/" + toString();
- } else {
- return this.parent.getCommandString() + " " + toString();
- }
- }
-
- public String getUsage() {
- if (this.usage != null && !this.usage.isEmpty()) {
- if (this.usage.startsWith("/")) {
- return this.usage;
- }
- return getCommandString() + " " + this.usage;
- }
- if (this.allCommands.isEmpty()) {
- return getCommandString();
- }
- StringBuilder args = new StringBuilder("[");
- String prefix = "";
- for (Command cmd : this.allCommands) {
- args.append(prefix).append(cmd.isStatic ? cmd.toString() : "<" + cmd + ">");
- prefix = "|";
- }
- return getCommandString() + " " + args + "]";
- }
-
- public Collection tabOf(PlotPlayer player, String[] input, boolean space,
- String... args) {
- if (!space) {
- return null;
- }
- List result = new ArrayList<>();
- int index = input.length - (space ? 0 : 1);
- for (String arg : args) {
- arg = arg.replace(getCommandString() + " ", "");
- String[] split = arg.split(" ");
- if (split.length <= index) {
- continue;
- }
- arg = StringMan.join(Arrays.copyOfRange(split, index, split.length), " ");
- Command cmd = new Command(null, false, arg, getPermission(), getRequiredType(), null) {
- };
- result.add(cmd);
- }
- return result;
- }
-
- public Collection tab(PlotPlayer player, String[] args, boolean space) {
- switch (args.length) {
- case 0:
- return this.allCommands;
- case 1:
- String arg = args[0].toLowerCase();
- if (space) {
- Command cmd = getCommand(arg);
- if (cmd != null && cmd.canExecute(player, false)) {
- return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space);
- } else {
- return null;
- }
- } else {
- Set commands = new HashSet();
- for (Map.Entry entry : this.staticCommands.entrySet()) {
- if (entry.getKey().startsWith(arg) && entry.getValue()
- .canExecute(player, false)) {
- commands.add(entry.getValue());
- }
- }
- return commands;
- }
- default:
- Command cmd = getCommand(args[0]);
- if (cmd != null) {
- return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space);
- } else {
- return null;
- }
- }
- }
-
- @Override public String toString() {
- return !this.aliases.isEmpty() ? this.aliases.get(0) : this.id;
- }
-
- @Override public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Command other = (Command) obj;
- if (this.hashCode() != other.hashCode()) {
- return false;
- }
- return this.getFullId().equals(other.getFullId());
- }
-
- @Override public int hashCode() {
- return this.getFullId().hashCode();
- }
-
- public void checkTrue(boolean mustBeTrue, C message, Object... args) {
- if (!mustBeTrue) {
- throw new CommandException(message, args);
- }
- }
-
- public T check(T object, C message, Object... args) {
- if (object == null) {
- throw new CommandException(message, args);
- }
- return object;
- }
-
- public enum CommandResult {
- FAILURE, SUCCESS
- }
-
-
- public static class CommandException extends RuntimeException {
- private final Object[] args;
- private final C message;
-
- public CommandException(C message, Object... args) {
- this.message = message;
- this.args = args;
- }
-
- public void perform(PlotPlayer player) {
- if (player != null && message != null) {
- message.send(player, args);
- }
- }
- }
-}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/CommandCaller.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/CommandCaller.java
deleted file mode 100644
index 3b5ee295e..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/CommandCaller.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.github.intellectualsites.plotsquared.commands;
-
-import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
-
-public interface CommandCaller {
-
- /**
- * Send the player a message.
- *
- * @param message the message to send
- */
- void sendMessage(String message);
-
- /**
- * Check the player's permissions. Will be cached if permission caching is enabled.
- *
- * @param permission the name of the permission
- */
- boolean hasPermission(String permission);
-
- boolean isPermissionSet(String permission);
-
- RequiredType getSuperCaller();
-}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/CommandDeclaration.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/CommandDeclaration.java
deleted file mode 100644
index 851a03174..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/commands/CommandDeclaration.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.github.intellectualsites.plotsquared.commands;
-
-import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
-import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME)
-public @interface CommandDeclaration {
-
- String command();
-
- String[] aliases() default {};
-
- String permission() default "";
-
- String usage() default "";
-
- String description() default "";
-
- RequiredType requiredType() default RequiredType.NONE;
-
- CommandCategory category() default CommandCategory.INFO;
-
- boolean confirmation() default false;
-}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/Configuration.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/Configuration.java
deleted file mode 100644
index 9d694c1ec..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/Configuration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.github.intellectualsites.plotsquared.configuration;
-
-import javax.annotation.Nonnull;
-import java.util.Map;
-
-/**
- * Represents a source of configurable options and settings.
- */
-public interface Configuration extends ConfigurationSection {
- /**
- * Sets the default value of the given path as provided.
- *
- *
If no source {@link Configuration} was provided as a default
- * collection, then a new {@link MemoryConfiguration} will be created to
- * hold the new default value.
- *
- *
If value is null, the value will be removed from the default
- * Configuration source.
- *
- * @param path Path of the value to set.
- * @param value Value to set the default to.
- * @throws IllegalArgumentException Thrown if path is null.
- */
- @Override void addDefault(@Nonnull String path, Object value);
-
- /**
- * Sets the default values of the given paths as provided.
- *
- *
If no source {@link Configuration} was provided as a default
- * collection, then a new {@link MemoryConfiguration} will be created to
- * hold the new default values.
- *
- * @param defaults A map of Path->Values to add to defaults.
- * @throws IllegalArgumentException Thrown if defaults is null.
- */
- void addDefaults(Map defaults);
-
- /**
- * Sets the default values of the given paths as provided.
- *
- *
If no source {@link Configuration} was provided as a default
- * collection, then a new {@link MemoryConfiguration} will be created to
- * hold the new default value.
- *
- *
This method will not hold a reference to the specified Configuration,
- * nor will it automatically update if that Configuration ever changes. If
- * you check this, you should set the default source with {@link
- * #setDefaults(Configuration)}.
- *
- * @param defaults A configuration holding a list of defaults to copy.
- * @throws IllegalArgumentException Thrown if defaults is null or this.
- */
- void addDefaults(Configuration defaults);
-
- /**
- * Gets the source {@link Configuration} for this configuration.
- *
- *
- * If no configuration source was set, but default values were added, then
- * a {@link MemoryConfiguration} will be returned. If no source was set
- * and no defaults were set, then this method will return null.
- *
- * @return Configuration source for default values, or null if none exist.
- */
- Configuration getDefaults();
-
- /**
- * Sets the source of all default values for this {@link Configuration}.
- *
- *
- * If a previous source was set, or previous default values were defined,
- * then they will not be copied to the new source.
- *
- * @param defaults New source of default values for this configuration.
- * @throws IllegalArgumentException Thrown if defaults is null or this.
- */
- void setDefaults(Configuration defaults);
-
- /**
- * Gets the {@link ConfigurationOptions} for this {@link Configuration}.
- *
- *
All setters through this method are chainable.
- *
- * @return Options for this configuration
- */
- ConfigurationOptions options();
-}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/ConfigurationOptions.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/ConfigurationOptions.java
deleted file mode 100644
index f86016031..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/ConfigurationOptions.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package com.github.intellectualsites.plotsquared.configuration;
-
-/**
- * Various settings for controlling the input and output of a {@link
- * Configuration}.
- */
-class ConfigurationOptions {
- private final Configuration configuration;
- private char pathSeparator = '.';
- private boolean copyDefaults = false;
-
- protected ConfigurationOptions(Configuration configuration) {
- this.configuration = configuration;
- }
-
- /**
- * Returns the {@link Configuration} that this object is responsible for.
- *
- * @return Parent configuration
- */
- public Configuration configuration() {
- return configuration;
- }
-
- /**
- * Gets the char that will be used to separate {@link
- * ConfigurationSection}s.
- *
- *
This value does not affect how the {@link Configuration} is stored,
- * only in how you access the data. The default value is '.'.
- *
- * @return Path separator
- */
- char pathSeparator() {
- return pathSeparator;
- }
-
- /**
- * Sets the char that will be used to separate {@link
- * ConfigurationSection}s.
- *
- *
This value does not affect how the {@link Configuration} is stored,
- * only in how you access the data. The default value is '.'.
- *
- * @param value Path separator
- * @return This object, for chaining
- */
- public ConfigurationOptions pathSeparator(char value) {
- pathSeparator = value;
- return this;
- }
-
- /**
- * Checks if the {@link Configuration} should copy values from its default
- * {@link Configuration} directly.
- *
- *
If this is true, all values in the default Configuration will be
- * directly copied, making it impossible to distinguish between values
- * that were set and values that are provided by default. As a result,
- * {@link ConfigurationSection#contains(String)} will always
- * return the same value as {@link
- * ConfigurationSection#isSet(String)}. The default value is
- * false.
- *
- * @return Whether or not defaults are directly copied
- */
- boolean copyDefaults() {
- return copyDefaults;
- }
-
- /**
- * Sets if the {@link Configuration} should copy values from its default
- * {@link Configuration} directly.
- *
- *
If this is true, all values in the default Configuration will be
- * directly copied, making it impossible to distinguish between values
- * that were set and values that are provided by default. As a result,
- * {@link ConfigurationSection#contains(String)} will always
- * return the same value as {@link
- * ConfigurationSection#isSet(String)}. The default value is
- * false.
- *
- * @param value Whether or not defaults are directly copied
- * @return This object, for chaining
- */
- public ConfigurationOptions copyDefaults(boolean value) {
- copyDefaults = value;
- return this;
- }
-}
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/ConfigurationSection.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/ConfigurationSection.java
deleted file mode 100644
index 9e15a9030..000000000
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/configuration/ConfigurationSection.java
+++ /dev/null
@@ -1,649 +0,0 @@
-package com.github.intellectualsites.plotsquared.configuration;
-
-import javax.annotation.Nonnull;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Represents a section of a {@link Configuration}.
- */
-public interface ConfigurationSection {
-
- /**
- * Gets a set containing all keys in this section.
- *
- *
If deep is set to true, then this will contain all the keys within any
- * child {@link ConfigurationSection}s (and their children, etc). These
- * will be in a valid path notation for you to use.
- *
- *
If deep is set to false, then this will contain only the keys of any
- * direct children, and not their own children.
- *
- * @param deep Whether or not to get a deep list, as opposed to a shallow
- * list.
- * @return Set of keys contained within this ConfigurationSection.
- */
- Set getKeys(boolean deep);
-
- /**
- * Gets a Map containing all keys and their values for this section.
- *
- *
If deep is set to true, then this will contain all the keys and values
- * within any child {@link ConfigurationSection}s (and their children,
- * etc). These keys will be in a valid path notation for you to use.
- *
- *
If deep is set to false, then this will contain only the keys and
- * values of any direct children, and not their own children.
- *
- * @param deep Whether or not to get a deep list, as opposed to a shallow
- * list.
- * @return Map of keys and values of this section.
- */
- Map getValues(boolean deep);
-
- /**
- * Checks if this {@link ConfigurationSection} contains the given path.
- *
- *
If the value for the requested path does not exist but a default value
- * has been specified, this will return true.
- *
- * @param path Path to check for existence.
- * @return True if this section contains the requested path, either via
- * default or being set.
- * @throws IllegalArgumentException Thrown when path is {@code null}.
- */
- boolean contains(@Nonnull String path);
-
- /**
- * Checks if this {@link ConfigurationSection} has a value set for the
- * given path.
- *
- *
If the value for the requested path does not exist but a default value
- * has been specified, this will still return false.
- *
- * @param path Path to check for existence.
- * @return True if this section contains the requested path, regardless of
- * having a default.
- * @throws IllegalArgumentException Thrown when path is {@code null}.
- */
- boolean isSet(@Nonnull String path);
-
- /**
- * Gets the path of this {@link ConfigurationSection} from its root {@link
- * Configuration}.
- *
- *
For any {@link Configuration} themselves, this will return an empty
- * string.
- *
- *
If the section is no longer contained within its root for any reason,
- * such as being replaced with a different value,
- * this may return {@code null}.
- *
- *
To retrieve the single name of this section, that is, the final part
- * of the path returned by this method, you may use {@link #getName()}.
- *
- * @return Path of this section relative to its root
- */
- String getCurrentPath();
-
- /**
- * Gets the name of this individual {@link ConfigurationSection}, in the
- * path.
- *
- *
This will always be the final part of {@link #getCurrentPath()}, unless
- * the section is orphaned.
- *
- * @return Name of this section
- */
- String getName();
-
- /**
- * Gets the root {@link Configuration} that contains this {@link
- * ConfigurationSection}
- *
- *
For any {@link Configuration} themselves, this will return its own
- * object.
- *
- *
If the section is no longer contained within its root for any reason,
- * such as being replaced with a different value,
- * this may return {@code null}.
- *
- * @return Root configuration containing this section.
- */
- Configuration getRoot();
-
- /**
- * Gets the parent {@link ConfigurationSection} that directly contains
- * this {@link ConfigurationSection}.
- *
- *
For any {@link Configuration} themselves, this will return
- * {@code null}.
- *
- *
If the section is no longer contained within its parent for any
- * reason, such as being replaced with a different value, this may
- * return {@code null}.
- *
- * @return Parent section containing this section.
- */
- ConfigurationSection getParent();
-
- /**
- * Gets the requested Object by path.
- *
- *
If the Object does not exist but a default value has been specified,
- * this will return the default value. If the Object does not exist and no
- * default value was specified, this will return {@code null}.
- *
- * @param path Path of the Object to get.
- * @return Requested Object.
- */
- Object get(String path);
-
- /**
- * Gets the requested Object by path, returning a default value if not
- * found.
- *
- *
If the Object does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the Object to get.
- * @param defaultValue The default value to return if the path is not found.
- * @return Requested Object.
- */
- Object getOrDefault(@Nonnull String path, Object defaultValue);
-
- /**
- * Sets the specified path to the given value.
- *
- *
If value is {@code null}, the entry will be removed. Any
- * existing entry will be replaced, regardless of what the new value is.
- *
- *
Some implementations may have limitations on what you may store. See
- * their individual javadoc for details. No implementations should allow
- * you to store {@link Configuration}s or {@link ConfigurationSection}s,
- * please use {@link #createSection(String)} for that.
- *
- * @param path Path of the object to set.
- * @param value New value to set the path to.
- */
- void set(String path, Object value);
-
- /**
- * Creates an empty {@link ConfigurationSection} at the specified path.
- *
- *
Any value that was previously set at this path will be overwritten. If
- * the previous value was itself a {@link ConfigurationSection}, it will
- * be orphaned.
- *
- * @param path Path to create the section at.
- * @return Newly created section
- */
- ConfigurationSection createSection(String path);
-
- /**
- * Creates a {@link ConfigurationSection} at the specified path, with
- * specified values.
- *
- *
Any value that was previously set at this path will be overwritten. If
- * the previous value was itself a {@link ConfigurationSection}, it will
- * be orphaned.
- *
- * @param path Path to create the section at.
- * @param map The values to used.
- * @return Newly created section
- */
- ConfigurationSection createSection(String path, Map, ?> map);
-
- // Primitives
-
- /**
- * Gets the requested String by path.
- *
- *
If the String does not exist but a default value has been specified,
- * this will return the default value. If the String does not exist and no
- * default value was specified, this will return {@code null}.
- *
- * @param path Path of the String to get.
- * @return Requested String.
- */
- String getString(String path);
-
- /**
- * Gets the requested String by path, returning a default value if not
- * found.
- *
- *
If the String does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the String to get.
- * @param def The default value to return if the path is not found or is
- * not a String.
- * @return Requested String.
- */
- String getString(String path, String def);
-
- /**
- * Checks if the specified path is a String.
- *
- *
If the path exists but is not a String, this will return false. If
- * the path does not exist, this will return false. If the path does not
- * exist but a default value has been specified, this will check if that
- * defaultvalue is a String and return appropriately.
- *
- * @param path Path of the String to check.
- * @return Whether or not the specified path is a String.
- */
- boolean isString(String path);
-
- /**
- * Gets the requested int by path.
- *
- *
If the int does not exist but a default value has been specified, this
- * will return the default value. If the int does not exist and no default
- * value was specified, this will return 0.
- *
- * @param path Path of the int to get.
- * @return Requested int.
- */
- int getInt(String path);
-
- /**
- * Gets the requested int by path, returning a default value if not found.
- *
- *
If the int does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the int to get.
- * @param def The default value to return if the path is not found or is
- * not an int.
- * @return Requested int.
- */
- int getInt(String path, int def);
-
- /**
- * Checks if the specified path is an int.
- *
- *
If the path exists but is not a int, this will return false. If the
- * path does not exist, this will return false. If the path does not exist
- * but a default value has been specified, this will check if that default
- * value is a int and return appropriately.
- *
- * @param path Path of the int to check.
- * @return Whether or not the specified path is an int.
- */
- boolean isInt(String path);
-
- /**
- * Gets the requested boolean by path.
- *
- *
If the boolean does not exist but a default value has been specified,
- * this will return the default value. If the boolean does not exist and
- * no default value was specified, this will return false.
- *
- * @param path Path of the boolean to get.
- * @return Requested boolean.
- */
- boolean getBoolean(String path);
-
- /**
- * Gets the requested boolean by path, returning a default value if not
- * found.
- *
- *
If the boolean does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the boolean to get.
- * @param defaultValue The default value to return if the path is not found or is
- * not a boolean.
- * @return Requested boolean.
- */
- boolean getBoolean(String path, boolean defaultValue);
-
- /**
- * Checks if the specified path is a boolean.
- *
- *
If the path exists but is not a boolean, this will return false. If the
- * path does not exist, this will return false. If the path does not exist
- * but a default value has been specified, this will check if that default
- * value is a boolean and return appropriately.
- *
- * @param path Path of the boolean to check.
- * @return Whether or not the specified path is a boolean.
- */
- boolean isBoolean(String path);
-
- /**
- * Gets the requested double by path.
- *
- *
If the double does not exist but a default value has been specified,
- * this will return the default value. If the double does not exist and no
- * default value was specified, this will return 0.
- *
- * @param path Path of the double to get.
- * @return Requested double.
- */
- double getDouble(String path);
-
- /**
- * Gets the requested double by path, returning a default value if not
- * found.
- *
- *
If the double does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the double to get.
- * @param defaultValue The default value to return if the path is not found or is
- * not a double.
- * @return Requested double.
- */
- double getDouble(String path, double defaultValue);
-
- /**
- * Checks if the specified path is a double.
- *
- *
If the path exists but is not a double, this will return false. If the
- * path does not exist, this will return false. If the path does not exist
- * but a default value has been specified, this will check if that default
- * value is a double and return appropriately.
- *
- * @param path Path of the double to check.
- * @return Whether or not the specified path is a double.
- */
- boolean isDouble(String path);
-
- /**
- * Gets the requested long by path.
- *
- *
If the long does not exist but a default value has been specified, this
- * will return the default value. If the long does not exist and no
- * default value was specified, this will return 0.
- *
- * @param path Path of the long to get.
- * @return Requested long.
- */
- long getLong(String path);
-
- /**
- * Gets the requested long by path, returning a default value if not
- * found.
- *
- *
If the long does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the long to get.
- * @param def The default value to return if the path is not found or is
- * not a long.
- * @return Requested long.
- */
- long getLong(String path, long def);
-
- /**
- * Checks if the specified path is a long.
- *
- *
If the path exists but is not a long, this will return false. If the
- * path does not exist, this will return false. If the path does not exist
- * but a default value has been specified, this will check if that default
- * value is a long and return appropriately.
- *
- * @param path Path of the long to check.
- * @return Whether or not the specified path is a long.
- */
- boolean isLong(String path);
-
- // Java
-
- /**
- * Gets the requested List by path.
- *
- *
If the List does not exist but a default value has been specified, this
- * will return the default value. If the List does not exist and no
- * default value was specified, this will return null.
- *
- * @param path Path of the List to get.
- * @return Requested List.
- */
- List> getList(String path);
-
- /**
- * Gets the requested List by path, returning a default value if not
- * found.
- *
- *
If the List does not exist then the specified default value will
- * returned regardless of if a default has been identified in the root
- * {@link Configuration}.
- *
- * @param path Path of the List to get.
- * @param def The default value to return if the path is not found or is
- * not a List.
- * @return Requested List.
- */
- List> getList(String path, List> def);
-
- /**
- * Checks if the specified path is a List.
- *
- *
If the path exists but is not a List, this will return false. If the
- * path does not exist, this will return false. If the path does not exist
- * but a default value has been specified, this will check if that default
- * value is a List and return appropriately.
- *
- * @param path Path of the List to check.
- * @return Whether or not the specified path is a List.
- */
- boolean isList(String path);
-
- /**
- * Gets the requested List of String by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a String if possible,
- * but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of String.
- */
- List getStringList(String path);
-
- /**
- * Gets the requested List of Integer by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Integer if
- * possible, but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Integer.
- */
- List getIntegerList(String path);
-
- /**
- * Gets the requested List of Boolean by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Boolean if
- * possible, but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Boolean.
- */
- List getBooleanList(String path);
-
- /**
- * Gets the requested List of Double by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Double if possible,
- * but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Double.
- */
- List getDoubleList(String path);
-
- /**
- * Gets the requested List of Float by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Float if possible,
- * but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Float.
- */
- List getFloatList(String path);
-
- /**
- * Gets the requested List of Long by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Long if possible,
- * but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Long.
- */
- List getLongList(String path);
-
- /**
- * Gets the requested List of Byte by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Byte if possible,
- * but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Byte.
- */
- List getByteList(String path);
-
- /**
- * Gets the requested List of Character by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Character if
- * possible, but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Character.
- */
- List getCharacterList(String path);
-
- /**
- * Gets the requested List of Short by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
- *
This method will attempt to cast any values into a Short if
- * possible, but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Short.
- */
- List getShortList(String path);
-
- /**
- * Gets the requested List of Maps by path.
- *
- *
If the List does not exist but a default value has been specified,
- * this will return the default value. If the List does not exist and no
- * default value was specified, this will return an empty List.
- *
This method will attempt to cast any values into a Map if possible,
- * but may miss any values out if they are not compatible.
- *
- * @param path Path of the List to get.
- * @return Requested List of Maps.
- */
- List