diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle
new file mode 100644
index 000000000..bf5ea7e95
--- /dev/null
+++ b/Bukkit/build.gradle
@@ -0,0 +1,26 @@
+apply plugin: 'eclipse'
+apply plugin: 'idea'
+
+dependencies {
+ compile project(':Core')
+ compile 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'
+ compile 'net.milkbowl.vault:VaultAPI:1.5'
+}
+
+processResources {
+ from('src/main/resources') {
+ include 'plugin.yml'
+ expand(
+ name: project.parent.name,
+ version: project.parent.version
+ )
+ }
+}
+
+shadowJar {
+ dependencies {
+ include(dependency(':Core'))
+ }
+}
+
+build.dependsOn(shadowJar)
\ No newline at end of file
diff --git a/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
similarity index 96%
rename from src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
rename to Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
index 89849909e..8583e3dd3 100644
--- a/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
+++ b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
@@ -1,758 +1,758 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// PlotSquared - A plot manager and world generator for the Bukkit API /
-// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
-// /
-// This program is free software; you can redistribute it and/or modify /
-// it under the terms of the GNU General Public License as published by /
-// the Free Software Foundation; either version 3 of the License, or /
-// (at your option) any later version. /
-// /
-// This program is distributed in the hope that it will be useful, /
-// but WITHOUT ANY WARRANTY; without even the implied warranty of /
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
-// GNU General Public License for more details. /
-// /
-// You should have received a copy of the GNU General Public License /
-// along with this program; if not, write to the Free Software Foundation, /
-// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
-// /
-// You can contact us via: support@intellectualsites.com /
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package com.intellectualcrafters.plot.api;
-
-import com.intellectualcrafters.configuration.file.YamlConfiguration;
-import com.intellectualcrafters.plot.PS;
-import com.intellectualcrafters.plot.commands.MainCommand;
-import com.intellectualcrafters.plot.commands.SubCommand;
-import com.intellectualcrafters.plot.config.C;
-import com.intellectualcrafters.plot.flag.AbstractFlag;
-import com.intellectualcrafters.plot.flag.FlagManager;
-import com.intellectualcrafters.plot.object.Plot;
-import com.intellectualcrafters.plot.object.PlotArea;
-import com.intellectualcrafters.plot.object.PlotId;
-import com.intellectualcrafters.plot.object.PlotManager;
-import com.intellectualcrafters.plot.object.PlotPlayer;
-import com.intellectualcrafters.plot.util.ChunkManager;
-import com.intellectualcrafters.plot.util.MainUtil;
-import com.intellectualcrafters.plot.util.SchematicHandler;
-import com.intellectualcrafters.plot.util.SetQueue;
-import com.intellectualcrafters.plot.util.UUIDHandler;
-import com.intellectualcrafters.plot.uuid.UUIDWrapper;
-import com.plotsquared.bukkit.util.BukkitUtil;
-import org.bukkit.Location;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.java.JavaPlugin;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.UUID;
-
-/**
- * PlotSquared API
- *
-
-
- * @version API 2.0
- *
- */
-
-public class PlotAPI {
-
- /**
- * Permission that allows for admin access, this permission node will allow the player to use any part of the
- * plugin, without limitations.
- * @deprecated Use C.PERMISSION_ADMIN.s() instead
- */
- @Deprecated
- public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s();
-
- /**
- * @deprecated Use new PlotAPI() instead
- */
- @Deprecated
- public PlotAPI(final JavaPlugin plugin) {}
-
- /**
- * @see PS
- *
- * @deprecated Use this class if you just want to do a few simple things.
- * - It will remain stable for future versions of the plugin
- * - The PlotPlayer and Plot class should be considered relatively safe
- * - For more advanced/intensive tasks you should consider using other classes
- *
- *
- */
- @Deprecated
- public PlotAPI() {}
-
- /**
- * Get all plots
- *
- * @return all plots
- *
- * @see PS#getPlots()
- */
- public Set getAllPlots() {
- return PS.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(final Player player) {
- return PS.get().getPlots(BukkitUtil.getPlayer(player));
- }
-
- /**
- * Add a plot world
- *
- * @param plotArea Plot World Object
- * @see PS#addPlotArea(PlotArea)
- */
- public void addPlotArea(final PlotArea plotArea) {
- PS.get().addPlotArea(plotArea);
- }
-
- /**
- * @return main configuration
- *
- * @see PS#config
- */
- public YamlConfiguration getConfig() {
- return PS.get().config;
- }
-
- /**
- * @return storage configuration
- *
- * @see PS#storage
- */
- public YamlConfiguration getStorage() {
- return PS.get().storage;
- }
-
- /**
- * Get the main class for this plugin
- Contains a lot of fields and methods - not very well organized
- * Only use this if you really need it
- *
- * @return PlotSquared PlotSquared Main Class
- *
- * @see PS
- */
- public PS getMain() {
- return PS.get();
- }
-
- /**
- * ChunkManager class contains several useful methods
- * - Chunk deletion
- * - Moving or copying regions
- * - plot swapping
- * - Entity tracking
- * - region regeneration
- *
- * @return ChunkManager
- *
- * @see com.intellectualcrafters.plot.util.ChunkManager
- */
- public ChunkManager getChunkManager() {
- return ChunkManager.manager;
- }
-
- /**
- * Get the block/biome set queue
- * @return SetQueue.IMP
- */
- public SetQueue getSetQueue() {
- return SetQueue.IMP;
- }
-
- /**
- * UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead)
- *
- * @return UUIDWrapper
- *
- * @see com.intellectualcrafters.plot.uuid.UUIDWrapper
- */
- public UUIDWrapper getUUIDWrapper() {
- return UUIDHandler.getUUIDWrapper();
- }
-
- /**
- * Do not use this. Instead use FlagManager.[method] in your code.
- * - Flag related stuff
- *
- * @return FlagManager
- *
- * @see com.intellectualcrafters.plot.flag.FlagManager
- */
- @Deprecated
- public FlagManager getFlagManager() {
- return new FlagManager();
- }
-
- /**
- * Do not use this. Instead use MainUtil.[method] in your code.
- * - Basic plot management stuff
- *
- * @return MainUtil
- *
- * @see MainUtil
- */
- @Deprecated
- public MainUtil getMainUtil() {
- return new MainUtil();
- }
-
- /**
- * Do not use this. Instead use C.PERMISSION_[method] in your code.
- * - Basic permission management stuff
- *
- * @return Array of strings
- *
- * @see com.intellectualcrafters.plot.util.Permissions
- */
- @Deprecated
- public String[] getPermissions() {
- final ArrayList perms = new ArrayList<>();
- for (final C c : C.values()) {
- if ("static.permissions".equals(c.getCat())) {
- perms.add(c.s());
- }
- }
- return perms.toArray(new String[perms.size()]);
- }
-
- /**
- * SchematicHandler class contains methods related to pasting, reading and writing schematics
- *
- * @return SchematicHandler
- *
- * @see com.intellectualcrafters.plot.util.SchematicHandler
- */
- public SchematicHandler getSchematicHandler() {
- return SchematicHandler.manager;
- }
-
- /**
- * Use C.[caption] instead
- *
- * @return C
- *
- * @see com.intellectualcrafters.plot.config.C
- */
- @Deprecated
- public C[] getCaptions() {
- return C.values();
- }
-
- /**
- * Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil
- *
- * @param world Which manager to get
- *
- * @return PlotManager
- *
- * @see com.intellectualcrafters.plot.object.PlotManager
- * @see PS#getPlotManager(Plot)
- */
- @Deprecated
- public PlotManager getPlotManager(final World world) {
- if (world == null) {
- return null;
- }
- return getPlotManager(world.getName());
- }
-
- public Set getPlotAreas(World world) {
- if (world == null) {
- return new HashSet<>();
- }
- return PS.get().getPlotAreas(world.getName());
- }
-
- /**
- * Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
- * tessellation
- *
- * @param world
- *
- * @return PlotManager
- *
- * @see PS#getPlotManager(Plot)
- * @see com.intellectualcrafters.plot.object.PlotManager
- */
- @Deprecated
- public PlotManager getPlotManager(final String world) {
- Set areas = PS.get().getPlotAreas(world);
- switch (areas.size()) {
- case 0:
- return null;
- case 1:
- return areas.iterator().next().manager;
- default:
- PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
- return null;
- }
- }
-
- /**
- * Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific
- * settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea
- *
- * @param world (to get settings of)
- *
- * @return PlotArea class for that world ! will return null if not a plot world world
- *
- * @see #getPlotAreas(World)
- * @see com.intellectualcrafters.plot.object.PlotArea
- */
- @Deprecated
- public PlotArea getWorldSettings(final World world) {
- if (world == null) {
- return null;
- }
- return getWorldSettings(world.getName());
- }
-
- /**
- * Get the settings for a world (settings bundled in PlotArea class)
- *
- * @param world (to get settings of)
- *
- * @return PlotArea class for that world ! will return null if not a plot world world
- *
- * @see PS#getPlotArea(String, String)
- * @see com.intellectualcrafters.plot.object.PlotArea
- */
- @Deprecated
- public PlotArea getWorldSettings(final String world) {
- if (world == null) {
- return null;
- }
- Set areas = PS.get().getPlotAreas(world);
- switch (areas.size()) {
- case 0:
- return null;
- case 1:
- return areas.iterator().next();
- default:
- PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
- return null;
- }
- }
-
- /**
- * Send a message to a player.
- *
- * @param player Player that will receive the message
- * @param c (Caption)
- *
- * @see MainUtil#sendMessage(PlotPlayer, C, String...)
- * com.intellectualcrafters.plot.config.C, String...)
- */
- public void sendMessage(final Player player, final C c) {
- MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
- }
-
- /**
- * Send a message to a player. - Supports color codes
- *
- * @param player Player that will receive the message
- * @param string The message
- *
- * @see MainUtil#sendMessage(PlotPlayer, String)
- */
- public void sendMessage(final Player player, final String string) {
- MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
- }
-
- /**
- * Send a message to the console. - Supports color codes
- *
- * @param msg Message that should be sent to the console
- *
- * @see MainUtil#sendConsoleMessage(C, String...)
- */
- public void sendConsoleMessage(final String msg) {
- PS.log(msg);
- }
-
- /**
- * Send a message to the console
- *
- * @param c (Caption)
- *
- * @see #sendConsoleMessage(String)
- * @see com.intellectualcrafters.plot.config.C
- */
- public void sendConsoleMessage(final C c) {
- sendConsoleMessage(c.s());
- }
-
- /**
- * Register a flag for use in plots
- *
- * @param flag Flag that should be registered
- *
- * @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
- * @see com.intellectualcrafters.plot.flag.AbstractFlag
- */
- public void addFlag(final AbstractFlag flag) {
- FlagManager.addFlag(flag);
- }
-
- /**
- * get all the currently registered flags
- *
- * @return array of Flag[]
- *
- * @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
- * @see com.intellectualcrafters.plot.flag.AbstractFlag
- */
- public AbstractFlag[] getFlags() {
- return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
- }
-
- /**
- * Get a plot based on the ID
- *
- * @param world World in which the plot is located
- * @param x Plot Location X Co-ord
- * @param z Plot Location Z Co-ord
- *
- * @return plot, null if ID is wrong
- *
- * @see PlotArea#getPlot(PlotId)
- */
- @Deprecated
- public Plot getPlot(final World world, final int x, final int z) {
- if (world == null) {
- return null;
- }
- PlotArea area = getWorldSettings(world);
- if (area == null) {
- return null;
- }
- return area.getPlot(new PlotId(x, z));
- }
-
- /**
- * Get a plot based on the location
- *
- * @param l The location that you want to to retrieve the plot from
- *
- * @return plot if found, otherwise it creates a temporary plot-
- *
- * @see Plot
- */
- public Plot getPlot(final Location l) {
- if (l == null) {
- return null;
- }
- return BukkitUtil.getLocation(l).getPlot();
- }
-
- /**
- * Get a plot based on the player location
- *
- * @param player Get the current plot for the player location
- *
- * @return plot if found, otherwise it creates a temporary plot
- *
- * @see #getPlot(org.bukkit.Location)
- * @see Plot
- */
- public Plot getPlot(final Player player) {
- return this.getPlot(player.getLocation());
- }
-
- /**
- * Check whether or not a player has a plot
- *
- * @param player Player that you want to check for
- *
- * @return true if player has a plot, false if not.
- *
- * @see #getPlots(World, Player, boolean)
- */
- @Deprecated
- public boolean hasPlot(final World world, final Player player) {
- return getPlots(world, player, true) != null && getPlots(world, player, true).length > 0;
- }
-
- /**
- * Get all plots for the player
- *
- * @param plr to search for
- * @param just_owner should we just search for owner? Or with rights?
- */
- @Deprecated
- public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
- final ArrayList pPlots = new ArrayList<>();
- UUID uuid = BukkitUtil.getPlayer(plr).getUUID();
- for (final Plot plot : PS.get().getPlots(world.getName())) {
- if (just_owner) {
- if (plot.hasOwner() && plot.isOwner(uuid)) {
- pPlots.add(plot);
- }
- } else {
- if (plot.isAdded(uuid)) {
- pPlots.add(plot);
- }
- }
- }
- return pPlots.toArray(new Plot[pPlots.size()]);
- }
-
- /**
- * Get all plots for the world
- *
- * @param world to get plots of
- *
- * @return Plot[] - array of plot objects in world
- *
- * @see PS#getPlots(String)
- * @see Plot
- */
- @Deprecated
- public Plot[] getPlots(final World world) {
- if (world == null) {
- return new Plot[0];
- }
- Collection plots = PS.get().getPlots(world.getName());
- return plots.toArray(new Plot[plots.size()]);
- }
-
- /**
- * Get all plot worlds
- *
- * @return World[] - array of plot worlds
- *
- */
- @Deprecated
- public String[] getPlotWorlds() {
- Set plotWorldStrings = PS.get().getPlotWorldStrings();
- return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
- }
-
- /**
- * Get if plot world
- *
- * @param world (to check if plot world)
- *
- * @return boolean (if plot world or not)
- *
- * @see PS#hasPlotArea(String)
- */
- @Deprecated
- public boolean isPlotWorld(final World world) {
- return PS.get().hasPlotArea(world.getName());
- }
-
- /**
- * Get plot locations
- *
- * @param p Plot that you want to get the locations for
- *
- * @return [0] = bottomLc, [1] = topLoc, [2] = home
- *
- * @deprecated As merged plots may not have a rectangular shape
- *
- * @see Plot
- */
- @Deprecated
- public Location[] getLocations(final Plot p) {
- return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) };
- }
-
- /**
- * Get home location
- *
- * @param p Plot that you want to get the location for
- *
- * @return plot bottom location
- *
- * @see Plot
- */
- public Location getHomeLocation(final Plot p) {
- return BukkitUtil.getLocation(p.getHome());
- }
-
- /**
- * Get Bottom Location (min, min, min)
- *
- * @param p Plot that you want to get the location for
- *
- * @return plot bottom location
- *
- * @deprecated As merged plots may not have a rectangular shape
- *
- * @see Plot
- */
- @Deprecated
- public Location getBottomLocation(final Plot p) {
- return BukkitUtil.getLocation(p.getBottom());
- }
-
- /**
- * Get Top Location (max, max, max)
- *
- * @param p Plot that you want to get the location for
- *
- * @return plot top location
- *
- * @deprecated As merged plots may not have a rectangular shape
- *
- * @see Plot
- */
- @Deprecated
- public Location getTopLocation(final Plot p) {
- return BukkitUtil.getLocation(p.getTop());
- }
-
- /**
- * Check whether or not a player is in a plot
- *
- * @param player who we're checking for
- *
- * @return true if the player is in a plot, false if not-
- *
- */
- public boolean isInPlot(final Player player) {
- return getPlot(player) != null;
- }
-
- /**
- * Register a subcommand
- *
- * @param c SubCommand, that we want to register
- *
- * @see com.intellectualcrafters.plot.commands.SubCommand
- */
- public void registerCommand(final SubCommand c) {
- if (c.getCommand() != null) {
- MainCommand.getInstance().addCommand(c);
- } else {
- MainCommand.getInstance().createCommand(c);
- }
- }
-
- /**
- * Get the PlotSquared class
- *
- * @return PlotSquared Class
- *
- * @see PS
- */
- public PS getPlotSquared() {
- return PS.get();
- }
-
- /**
- * Get the player plot count
- *
- * @param world Specify the world we want to select the plots from
- * @param player Player, for whom we're getting the plot count
- *
- * @return the number of plots the player has
- *
- */
- public int getPlayerPlotCount(final World world, final Player player) {
- if (world == null) {
- return 0;
- }
- return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
- }
-
- /**
- * Get a collection containing the players plots
- *
- * @param world Specify the world we want to select the plots from
- * @param player Player, for whom we're getting the plots
- *
- * @return a set containing the players plots
- *
- * @see PS#getPlots(String, PlotPlayer)
- *
- * @see Plot
- */
- public Set getPlayerPlots(final World world, final Player player) {
- if (world == null) {
- return new HashSet<>();
- }
- return BukkitUtil.getPlayer(player).getPlots(world.getName());
- }
-
- /**
- * Get the numbers of plots, which the player is able to build in
- *
- * @param player Player, for whom we're getting the plots (trusted, member and owner)
- *
- * @return the number of allowed plots
- *
- */
- public int getAllowedPlots(final Player player) {
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- return pp.getAllowedPlots();
- }
-
- /**
- * Get the PlotPlayer for a player
- * - The PlotPlayer is usually cached and will provide useful functions relating to players
- *
- * @see PlotPlayer#wrap(Object)
- *
- * @param player
- * @return
- */
- public PlotPlayer wrapPlayer(final Player player) {
- return PlotPlayer.wrap(player);
- }
-
- /**
- * Get the PlotPlayer for a UUID (Please note that PlotSquared can be configured to provide different UUIDs than bukkit)
- *
- * @see PlotPlayer#wrap(Object)
- *
- * @param uuid
- * @return
- */
- public PlotPlayer wrapPlayer(final UUID uuid) {
- return PlotPlayer.wrap(uuid);
- }
-
- /**
- * Get the PlotPlayer for a username
- *
- * @see PlotPlayer#wrap(Object)
- *
- * @param player
- * @return
- */
- public PlotPlayer wrapPlayer(final String player) {
- return PlotPlayer.wrap(player);
- }
-
- /**
- * Get the PlotPlayer for an offline player
- * Note that this will work if the player is offline, however not all functionality will work
- *
- * @see PlotPlayer#wrap(Object)
- *
- * @param player
- * @return
- */
- public PlotPlayer wrapPlayer(final OfflinePlayer player) {
- return PlotPlayer.wrap(player);
- }
-}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// PlotSquared - A plot manager and world generator for the Bukkit API /
+// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
+// /
+// This program is free software; you can redistribute it and/or modify /
+// it under the terms of the GNU General Public License as published by /
+// the Free Software Foundation; either version 3 of the License, or /
+// (at your option) any later version. /
+// /
+// This program is distributed in the hope that it will be useful, /
+// but WITHOUT ANY WARRANTY; without even the implied warranty of /
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
+// GNU General Public License for more details. /
+// /
+// You should have received a copy of the GNU General Public License /
+// along with this program; if not, write to the Free Software Foundation, /
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
+// /
+// You can contact us via: support@intellectualsites.com /
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+package com.intellectualcrafters.plot.api;
+
+import com.intellectualcrafters.configuration.file.YamlConfiguration;
+import com.intellectualcrafters.plot.PS;
+import com.intellectualcrafters.plot.commands.MainCommand;
+import com.intellectualcrafters.plot.commands.SubCommand;
+import com.intellectualcrafters.plot.config.C;
+import com.intellectualcrafters.plot.flag.AbstractFlag;
+import com.intellectualcrafters.plot.flag.FlagManager;
+import com.intellectualcrafters.plot.object.Plot;
+import com.intellectualcrafters.plot.object.PlotArea;
+import com.intellectualcrafters.plot.object.PlotId;
+import com.intellectualcrafters.plot.object.PlotManager;
+import com.intellectualcrafters.plot.object.PlotPlayer;
+import com.intellectualcrafters.plot.util.ChunkManager;
+import com.intellectualcrafters.plot.util.MainUtil;
+import com.intellectualcrafters.plot.util.SchematicHandler;
+import com.intellectualcrafters.plot.util.SetQueue;
+import com.intellectualcrafters.plot.util.UUIDHandler;
+import com.intellectualcrafters.plot.uuid.UUIDWrapper;
+import com.plotsquared.bukkit.util.BukkitUtil;
+import org.bukkit.Location;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+/**
+ * PlotSquared API
+ *
+
+
+ * @version API 2.0
+ *
+ */
+
+public class PlotAPI {
+
+ /**
+ * Permission that allows for admin access, this permission node will allow the player to use any part of the
+ * plugin, without limitations.
+ * @deprecated Use C.PERMISSION_ADMIN.s() instead
+ */
+ @Deprecated
+ public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s();
+
+ /**
+ * @deprecated Use new PlotAPI() instead
+ */
+ @Deprecated
+ public PlotAPI(final JavaPlugin plugin) {}
+
+ /**
+ * @see PS
+ *
+ * @deprecated Use this class if you just want to do a few simple things.
+ * - It will remain stable for future versions of the plugin
+ * - The PlotPlayer and Plot class should be considered relatively safe
+ * - For more advanced/intensive tasks you should consider using other classes
+ *
+ *
+ */
+ @Deprecated
+ public PlotAPI() {}
+
+ /**
+ * Get all plots
+ *
+ * @return all plots
+ *
+ * @see PS#getPlots()
+ */
+ public Set getAllPlots() {
+ return PS.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(final Player player) {
+ return PS.get().getPlots(BukkitUtil.getPlayer(player));
+ }
+
+ /**
+ * Add a plot world
+ *
+ * @param plotArea Plot World Object
+ * @see PS#addPlotArea(PlotArea)
+ */
+ public void addPlotArea(final PlotArea plotArea) {
+ PS.get().addPlotArea(plotArea);
+ }
+
+ /**
+ * @return main configuration
+ *
+ * @see PS#config
+ */
+ public YamlConfiguration getConfig() {
+ return PS.get().config;
+ }
+
+ /**
+ * @return storage configuration
+ *
+ * @see PS#storage
+ */
+ public YamlConfiguration getStorage() {
+ return PS.get().storage;
+ }
+
+ /**
+ * Get the main class for this plugin
- Contains a lot of fields and methods - not very well organized
+ * Only use this if you really need it
+ *
+ * @return PlotSquared PlotSquared Main Class
+ *
+ * @see PS
+ */
+ public PS getMain() {
+ return PS.get();
+ }
+
+ /**
+ * ChunkManager class contains several useful methods
+ * - Chunk deletion
+ * - Moving or copying regions
+ * - plot swapping
+ * - Entity tracking
+ * - region regeneration
+ *
+ * @return ChunkManager
+ *
+ * @see com.intellectualcrafters.plot.util.ChunkManager
+ */
+ public ChunkManager getChunkManager() {
+ return ChunkManager.manager;
+ }
+
+ /**
+ * Get the block/biome set queue
+ * @return SetQueue.IMP
+ */
+ public SetQueue getSetQueue() {
+ return SetQueue.IMP;
+ }
+
+ /**
+ * UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead)
+ *
+ * @return UUIDWrapper
+ *
+ * @see com.intellectualcrafters.plot.uuid.UUIDWrapper
+ */
+ public UUIDWrapper getUUIDWrapper() {
+ return UUIDHandler.getUUIDWrapper();
+ }
+
+ /**
+ * Do not use this. Instead use FlagManager.[method] in your code.
+ * - Flag related stuff
+ *
+ * @return FlagManager
+ *
+ * @see com.intellectualcrafters.plot.flag.FlagManager
+ */
+ @Deprecated
+ public FlagManager getFlagManager() {
+ return new FlagManager();
+ }
+
+ /**
+ * Do not use this. Instead use MainUtil.[method] in your code.
+ * - Basic plot management stuff
+ *
+ * @return MainUtil
+ *
+ * @see MainUtil
+ */
+ @Deprecated
+ public MainUtil getMainUtil() {
+ return new MainUtil();
+ }
+
+ /**
+ * Do not use this. Instead use C.PERMISSION_[method] in your code.
+ * - Basic permission management stuff
+ *
+ * @return Array of strings
+ *
+ * @see com.intellectualcrafters.plot.util.Permissions
+ */
+ @Deprecated
+ public String[] getPermissions() {
+ final ArrayList perms = new ArrayList<>();
+ for (final C c : C.values()) {
+ if ("static.permissions".equals(c.getCat())) {
+ perms.add(c.s());
+ }
+ }
+ return perms.toArray(new String[perms.size()]);
+ }
+
+ /**
+ * SchematicHandler class contains methods related to pasting, reading and writing schematics
+ *
+ * @return SchematicHandler
+ *
+ * @see com.intellectualcrafters.plot.util.SchematicHandler
+ */
+ public SchematicHandler getSchematicHandler() {
+ return SchematicHandler.manager;
+ }
+
+ /**
+ * Use C.[caption] instead
+ *
+ * @return C
+ *
+ * @see com.intellectualcrafters.plot.config.C
+ */
+ @Deprecated
+ public C[] getCaptions() {
+ return C.values();
+ }
+
+ /**
+ * Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil
+ *
+ * @param world Which manager to get
+ *
+ * @return PlotManager
+ *
+ * @see com.intellectualcrafters.plot.object.PlotManager
+ * @see PS#getPlotManager(Plot)
+ */
+ @Deprecated
+ public PlotManager getPlotManager(final World world) {
+ if (world == null) {
+ return null;
+ }
+ return getPlotManager(world.getName());
+ }
+
+ public Set getPlotAreas(World world) {
+ if (world == null) {
+ return new HashSet<>();
+ }
+ return PS.get().getPlotAreas(world.getName());
+ }
+
+ /**
+ * Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
+ * tessellation
+ *
+ * @param world
+ *
+ * @return PlotManager
+ *
+ * @see PS#getPlotManager(Plot)
+ * @see com.intellectualcrafters.plot.object.PlotManager
+ */
+ @Deprecated
+ public PlotManager getPlotManager(final String world) {
+ Set areas = PS.get().getPlotAreas(world);
+ switch (areas.size()) {
+ case 0:
+ return null;
+ case 1:
+ return areas.iterator().next().manager;
+ default:
+ PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
+ return null;
+ }
+ }
+
+ /**
+ * Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific
+ * settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea
+ *
+ * @param world (to get settings of)
+ *
+ * @return PlotArea class for that world ! will return null if not a plot world world
+ *
+ * @see #getPlotAreas(World)
+ * @see com.intellectualcrafters.plot.object.PlotArea
+ */
+ @Deprecated
+ public PlotArea getWorldSettings(final World world) {
+ if (world == null) {
+ return null;
+ }
+ return getWorldSettings(world.getName());
+ }
+
+ /**
+ * Get the settings for a world (settings bundled in PlotArea class)
+ *
+ * @param world (to get settings of)
+ *
+ * @return PlotArea class for that world ! will return null if not a plot world world
+ *
+ * @see PS#getPlotArea(String, String)
+ * @see com.intellectualcrafters.plot.object.PlotArea
+ */
+ @Deprecated
+ public PlotArea getWorldSettings(final String world) {
+ if (world == null) {
+ return null;
+ }
+ Set areas = PS.get().getPlotAreas(world);
+ switch (areas.size()) {
+ case 0:
+ return null;
+ case 1:
+ return areas.iterator().next();
+ default:
+ PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
+ return null;
+ }
+ }
+
+ /**
+ * Send a message to a player.
+ *
+ * @param player Player that will receive the message
+ * @param c (Caption)
+ *
+ * @see MainUtil#sendMessage(PlotPlayer, C, String...)
+ * com.intellectualcrafters.plot.config.C, String...)
+ */
+ public void sendMessage(final Player player, final C c) {
+ MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
+ }
+
+ /**
+ * Send a message to a player. - Supports color codes
+ *
+ * @param player Player that will receive the message
+ * @param string The message
+ *
+ * @see MainUtil#sendMessage(PlotPlayer, String)
+ */
+ public void sendMessage(final Player player, final String string) {
+ MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
+ }
+
+ /**
+ * Send a message to the console. - Supports color codes
+ *
+ * @param msg Message that should be sent to the console
+ *
+ * @see MainUtil#sendConsoleMessage(C, String...)
+ */
+ public void sendConsoleMessage(final String msg) {
+ PS.log(msg);
+ }
+
+ /**
+ * Send a message to the console
+ *
+ * @param c (Caption)
+ *
+ * @see #sendConsoleMessage(String)
+ * @see com.intellectualcrafters.plot.config.C
+ */
+ public void sendConsoleMessage(final C c) {
+ sendConsoleMessage(c.s());
+ }
+
+ /**
+ * Register a flag for use in plots
+ *
+ * @param flag Flag that should be registered
+ *
+ * @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
+ * @see com.intellectualcrafters.plot.flag.AbstractFlag
+ */
+ public void addFlag(final AbstractFlag flag) {
+ FlagManager.addFlag(flag);
+ }
+
+ /**
+ * get all the currently registered flags
+ *
+ * @return array of Flag[]
+ *
+ * @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
+ * @see com.intellectualcrafters.plot.flag.AbstractFlag
+ */
+ public AbstractFlag[] getFlags() {
+ return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
+ }
+
+ /**
+ * Get a plot based on the ID
+ *
+ * @param world World in which the plot is located
+ * @param x Plot Location X Co-ord
+ * @param z Plot Location Z Co-ord
+ *
+ * @return plot, null if ID is wrong
+ *
+ * @see PlotArea#getPlot(PlotId)
+ */
+ @Deprecated
+ public Plot getPlot(final World world, final int x, final int z) {
+ if (world == null) {
+ return null;
+ }
+ PlotArea area = getWorldSettings(world);
+ if (area == null) {
+ return null;
+ }
+ return area.getPlot(new PlotId(x, z));
+ }
+
+ /**
+ * Get a plot based on the location
+ *
+ * @param l The location that you want to to retrieve the plot from
+ *
+ * @return plot if found, otherwise it creates a temporary plot-
+ *
+ * @see Plot
+ */
+ public Plot getPlot(final Location l) {
+ if (l == null) {
+ return null;
+ }
+ return BukkitUtil.getLocation(l).getPlot();
+ }
+
+ /**
+ * Get a plot based on the player location
+ *
+ * @param player Get the current plot for the player location
+ *
+ * @return plot if found, otherwise it creates a temporary plot
+ *
+ * @see #getPlot(org.bukkit.Location)
+ * @see Plot
+ */
+ public Plot getPlot(final Player player) {
+ return this.getPlot(player.getLocation());
+ }
+
+ /**
+ * Check whether or not a player has a plot
+ *
+ * @param player Player that you want to check for
+ *
+ * @return true if player has a plot, false if not.
+ *
+ * @see #getPlots(World, Player, boolean)
+ */
+ @Deprecated
+ public boolean hasPlot(final World world, final Player player) {
+ return getPlots(world, player, true) != null && getPlots(world, player, true).length > 0;
+ }
+
+ /**
+ * Get all plots for the player
+ *
+ * @param plr to search for
+ * @param just_owner should we just search for owner? Or with rights?
+ */
+ @Deprecated
+ public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
+ final ArrayList pPlots = new ArrayList<>();
+ UUID uuid = BukkitUtil.getPlayer(plr).getUUID();
+ for (final Plot plot : PS.get().getPlots(world.getName())) {
+ if (just_owner) {
+ if (plot.hasOwner() && plot.isOwner(uuid)) {
+ pPlots.add(plot);
+ }
+ } else {
+ if (plot.isAdded(uuid)) {
+ pPlots.add(plot);
+ }
+ }
+ }
+ return pPlots.toArray(new Plot[pPlots.size()]);
+ }
+
+ /**
+ * Get all plots for the world
+ *
+ * @param world to get plots of
+ *
+ * @return Plot[] - array of plot objects in world
+ *
+ * @see PS#getPlots(String)
+ * @see Plot
+ */
+ @Deprecated
+ public Plot[] getPlots(final World world) {
+ if (world == null) {
+ return new Plot[0];
+ }
+ Collection plots = PS.get().getPlots(world.getName());
+ return plots.toArray(new Plot[plots.size()]);
+ }
+
+ /**
+ * Get all plot worlds
+ *
+ * @return World[] - array of plot worlds
+ *
+ */
+ @Deprecated
+ public String[] getPlotWorlds() {
+ Set plotWorldStrings = PS.get().getPlotWorldStrings();
+ return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
+ }
+
+ /**
+ * Get if plot world
+ *
+ * @param world (to check if plot world)
+ *
+ * @return boolean (if plot world or not)
+ *
+ * @see PS#hasPlotArea(String)
+ */
+ @Deprecated
+ public boolean isPlotWorld(final World world) {
+ return PS.get().hasPlotArea(world.getName());
+ }
+
+ /**
+ * Get plot locations
+ *
+ * @param p Plot that you want to get the locations for
+ *
+ * @return [0] = bottomLc, [1] = topLoc, [2] = home
+ *
+ * @deprecated As merged plots may not have a rectangular shape
+ *
+ * @see Plot
+ */
+ @Deprecated
+ public Location[] getLocations(final Plot p) {
+ return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) };
+ }
+
+ /**
+ * Get home location
+ *
+ * @param p Plot that you want to get the location for
+ *
+ * @return plot bottom location
+ *
+ * @see Plot
+ */
+ public Location getHomeLocation(final Plot p) {
+ return BukkitUtil.getLocation(p.getHome());
+ }
+
+ /**
+ * Get Bottom Location (min, min, min)
+ *
+ * @param p Plot that you want to get the location for
+ *
+ * @return plot bottom location
+ *
+ * @deprecated As merged plots may not have a rectangular shape
+ *
+ * @see Plot
+ */
+ @Deprecated
+ public Location getBottomLocation(final Plot p) {
+ return BukkitUtil.getLocation(p.getBottom());
+ }
+
+ /**
+ * Get Top Location (max, max, max)
+ *
+ * @param p Plot that you want to get the location for
+ *
+ * @return plot top location
+ *
+ * @deprecated As merged plots may not have a rectangular shape
+ *
+ * @see Plot
+ */
+ @Deprecated
+ public Location getTopLocation(final Plot p) {
+ return BukkitUtil.getLocation(p.getTop());
+ }
+
+ /**
+ * Check whether or not a player is in a plot
+ *
+ * @param player who we're checking for
+ *
+ * @return true if the player is in a plot, false if not-
+ *
+ */
+ public boolean isInPlot(final Player player) {
+ return getPlot(player) != null;
+ }
+
+ /**
+ * Register a subcommand
+ *
+ * @param c SubCommand, that we want to register
+ *
+ * @see com.intellectualcrafters.plot.commands.SubCommand
+ */
+ public void registerCommand(final SubCommand c) {
+ if (c.getCommand() != null) {
+ MainCommand.getInstance().addCommand(c);
+ } else {
+ MainCommand.getInstance().createCommand(c);
+ }
+ }
+
+ /**
+ * Get the PlotSquared class
+ *
+ * @return PlotSquared Class
+ *
+ * @see PS
+ */
+ public PS getPlotSquared() {
+ return PS.get();
+ }
+
+ /**
+ * Get the player plot count
+ *
+ * @param world Specify the world we want to select the plots from
+ * @param player Player, for whom we're getting the plot count
+ *
+ * @return the number of plots the player has
+ *
+ */
+ public int getPlayerPlotCount(final World world, final Player player) {
+ if (world == null) {
+ return 0;
+ }
+ return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
+ }
+
+ /**
+ * Get a collection containing the players plots
+ *
+ * @param world Specify the world we want to select the plots from
+ * @param player Player, for whom we're getting the plots
+ *
+ * @return a set containing the players plots
+ *
+ * @see PS#getPlots(String, PlotPlayer)
+ *
+ * @see Plot
+ */
+ public Set getPlayerPlots(final World world, final Player player) {
+ if (world == null) {
+ return new HashSet<>();
+ }
+ return BukkitUtil.getPlayer(player).getPlots(world.getName());
+ }
+
+ /**
+ * Get the numbers of plots, which the player is able to build in
+ *
+ * @param player Player, for whom we're getting the plots (trusted, member and owner)
+ *
+ * @return the number of allowed plots
+ *
+ */
+ public int getAllowedPlots(final Player player) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ return pp.getAllowedPlots();
+ }
+
+ /**
+ * Get the PlotPlayer for a player
+ * - The PlotPlayer is usually cached and will provide useful functions relating to players
+ *
+ * @see PlotPlayer#wrap(Object)
+ *
+ * @param player
+ * @return
+ */
+ public PlotPlayer wrapPlayer(final Player player) {
+ return PlotPlayer.wrap(player);
+ }
+
+ /**
+ * Get the PlotPlayer for a UUID (Please note that PlotSquared can be configured to provide different UUIDs than bukkit)
+ *
+ * @see PlotPlayer#wrap(Object)
+ *
+ * @param uuid
+ * @return
+ */
+ public PlotPlayer wrapPlayer(final UUID uuid) {
+ return PlotPlayer.wrap(uuid);
+ }
+
+ /**
+ * Get the PlotPlayer for a username
+ *
+ * @see PlotPlayer#wrap(Object)
+ *
+ * @param player
+ * @return
+ */
+ public PlotPlayer wrapPlayer(final String player) {
+ return PlotPlayer.wrap(player);
+ }
+
+ /**
+ * Get the PlotPlayer for an offline player
+ * Note that this will work if the player is offline, however not all functionality will work
+ *
+ * @see PlotPlayer#wrap(Object)
+ *
+ * @param player
+ * @return
+ */
+ public PlotPlayer wrapPlayer(final OfflinePlayer player) {
+ return PlotPlayer.wrap(player);
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/BukkitMain.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/ArrayWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/ArrayWrapper.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/ArrayWrapper.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/ArrayWrapper.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/JsonRepresentedObject.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/JsonRepresentedObject.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/JsonRepresentedObject.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/JsonRepresentedObject.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/JsonString.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/JsonString.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/JsonString.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/JsonString.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/MessagePart.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/Reflection.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/Reflection.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java
diff --git a/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java
diff --git a/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java
diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java
diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java
diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java
similarity index 98%
rename from src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java
index 5f6fd9b09..2028d2db0 100644
--- a/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java
@@ -1,404 +1,404 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// PlotSquared - A plot manager and world generator for the Bukkit API /
-// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
-// /
-// This program is free software; you can redistribute it and/or modify /
-// it under the terms of the GNU General Public License as published by /
-// the Free Software Foundation; either version 3 of the License, or /
-// (at your option) any later version. /
-// /
-// This program is distributed in the hope that it will be useful, /
-// but WITHOUT ANY WARRANTY; without even the implied warranty of /
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
-// GNU General Public License for more details. /
-// /
-// You should have received a copy of the GNU General Public License /
-// along with this program; if not, write to the Free Software Foundation, /
-// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
-// /
-// You can contact us via: support@intellectualsites.com /
-////////////////////////////////////////////////////////////////////////////////////////////////////
-package com.plotsquared.bukkit.database.plotme;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-import org.bukkit.WorldCreator;
-
-import com.intellectualcrafters.configuration.file.FileConfiguration;
-import com.intellectualcrafters.configuration.file.YamlConfiguration;
-import com.intellectualcrafters.plot.PS;
-import com.intellectualcrafters.plot.config.Settings;
-import com.intellectualcrafters.plot.database.DBFunc;
-import com.intellectualcrafters.plot.generator.HybridGen;
-import com.intellectualcrafters.plot.object.Plot;
-import com.intellectualcrafters.plot.object.PlotArea;
-import com.intellectualcrafters.plot.object.PlotId;
-import com.intellectualcrafters.plot.util.TaskManager;
-import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
-
-/**
- * Created 2014-08-17 for PlotSquared
- *
-
-
- */
-public class LikePlotMeConverter {
- private final String plugin;
-
- /**
- * Constructor
- *
- * @param plugin Plugin Used to run the converter
- */
- public LikePlotMeConverter(final String plugin) {
- this.plugin = plugin;
- }
-
- public static String getWorld(final String world) {
- for (final World newworld : Bukkit.getWorlds()) {
- if (newworld.getName().equalsIgnoreCase(world)) {
- return newworld.getName();
- }
- }
- return world;
- }
-
- private void sendMessage(final String message) {
- PS.debug("&3PlotMe&8->&3PlotSquared&8: &7" + message);
- }
-
- public String getPlotMePath() {
- return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
- }
-
- public String getAthionPlotsPath() {
- return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
- }
-
- public FileConfiguration getPlotMeConfig(final String dataFolder) {
- final File plotMeFile = new File(dataFolder + "config.yml");
- if (!plotMeFile.exists()) {
- return null;
- }
- return YamlConfiguration.loadConfiguration(plotMeFile);
- }
-
- public Set getPlotMeWorlds(final FileConfiguration plotConfig) {
- return plotConfig.getConfigurationSection("worlds").getKeys(false);
- }
-
- public void mergeWorldYml(final String plugin, FileConfiguration plotConfig) {
- try {
- File genConfig = new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
- if (genConfig.exists()) {
- YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
- for (String key : yml.getKeys(true)) {
- if (!plotConfig.contains(key)) {
- plotConfig.set(key, yml.get(key));
- }
- }
- genConfig.delete();
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void updateWorldYml(final String plugin, final String location) {
- try {
- final Path path = Paths.get(location);
- final File file = new File(location);
- if (!file.exists()) {
- return;
- }
- final Charset charset = StandardCharsets.UTF_8;
- String content = new String(Files.readAllBytes(path), charset);
- content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
- content = content.replaceAll(plugin, "PlotSquared");
- Files.write(path, content.getBytes(charset));
- } catch (IOException e) {
- }
- }
-
- public boolean run(final APlotMeConnector connector) {
- try {
- final String dataFolder = getPlotMePath();
- final FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
- if (plotConfig == null) {
- return false;
- }
-
- String version = plotConfig.getString("Version");
- if (version == null) {
- version = plotConfig.getString("version");
- }
- if (!connector.accepts(version)) {
- return false;
- }
-
- PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
-
- final Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
-
- if (!connector.isValidConnection(connection)) {
- sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
- return false;
- }
-
- sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
-
- mergeWorldYml(plugin, plotConfig);
-
- sendMessage("Connecting to " + plugin + " DB");
-
- int plotCount = 0;
- final ArrayList createdPlots = new ArrayList<>();
-
- sendMessage("Collecting plot data");
-
- final String dbPrefix = plugin.toLowerCase();
- sendMessage(" - " + dbPrefix + "Plots");
- final Set worlds = getPlotMeWorlds(plotConfig);
-
- if (Settings.CONVERT_PLOTME) {
- sendMessage("Updating bukkit.yml");
- updateWorldYml(plugin, "bukkit.yml");
- updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
- for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
- sendMessage("Copying config for: " + world);
- try {
- final String actualWorldName = getWorld(world);
- connector.copyConfig(plotConfig, world, actualWorldName);
- PS.get().config.save(PS.get().configFile);
- } catch (final Exception e) {
- e.printStackTrace();
- sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
- }
- }
- }
- final HashMap> plots = connector.getPlotMePlots(connection);
- for (final Entry> entry : plots.entrySet()) {
- plotCount += entry.getValue().size();
- }
- if (!Settings.CONVERT_PLOTME) {
- return false;
- }
-
- sendMessage(" - " + dbPrefix + "Allowed");
-
- sendMessage("Collected " + plotCount + " plots from PlotMe");
- final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
- if (PLOTME_DG_FILE.exists()) {
- final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
- try {
- for (final String world : plots.keySet()) {
- final String actualWorldName = getWorld(world);
- final String plotMeWorldName = world.toLowerCase();
- Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
- /*
- * TODO: dead code
- *
- if (pathwidth == null) {
- pathwidth = 7;
- }
- */
- PS.get().config.set("worlds." + world + ".road.width", pathwidth);
-
- Integer pathheight = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
- if ((pathheight == null) || (pathheight == 0)) {
- pathheight = 64;
- }
- PS.get().config.set("worlds." + world + ".road.height", pathheight);
- PS.get().config.set("worlds." + world + ".wall.height", pathheight);
- PS.get().config.set("worlds." + world + ".plot.height", pathheight);
- Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
- if ((plotsize == null) || (plotsize == 0)) {
- plotsize = 32;
- }
- PS.get().config.set("worlds." + world + ".plot.size", plotsize);
- String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
- if (wallblock == null) {
- wallblock = "44";
- }
- PS.get().config.set("worlds." + world + ".wall.block", wallblock);
- String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
- if (floor == null) {
- floor = "2";
- }
- PS.get().config.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
- String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
- if (filling == null) {
- filling = "3";
- }
- PS.get().config.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
- String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
- if (road == null) {
- road = "5";
- }
- PS.get().config.set("worlds." + world + ".road.block", road);
- Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
- if (height == 0) {
- height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
- if (height == 0) {
- height = 64;
- }
- }
- PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
- PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
- PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
- PS.get().config.save(PS.get().configFile);
- }
- } catch (IOException e) {
- }
- }
- for (Entry> entry : plots.entrySet()) {
- String world = entry.getKey();
- PlotArea area = PS.get().getPlotArea(world, null);
- int duplicate = 0;
- if (area != null) {
- for (Entry entry2 : entry.getValue().entrySet()) {
- if (area.getOwnedPlotAbs(entry2.getKey()) != null) {
- duplicate++;
- } else {
- createdPlots.add(entry2.getValue());
- }
- }
- if (duplicate > 0) {
- PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
- }
- } else {
- if (PS.get().plots_tmp != null) {
- HashMap map = PS.get().plots_tmp.get(world);
- if (map != null) {
- for (Entry entry2 : entry.getValue().entrySet()) {
- if (map.containsKey(entry2.getKey())) {
- duplicate++;
- } else {
- createdPlots.add(entry2.getValue());
- }
- }
- if (duplicate > 0) {
- PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
- }
- continue;
- }
- }
- createdPlots.addAll(entry.getValue().values());
- }
- }
- sendMessage("Creating plot DB");
- Thread.sleep(1000);
- final AtomicBoolean done = new AtomicBoolean(false);
- DBFunc.createPlotsAndData(createdPlots, new Runnable() {
- @Override
- public void run() {
- if (done.get()) {
- done();
- sendMessage("&aDatabase conversion is now complete!");
- PS.debug("&c - Stop the server");
- PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
- PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
- PS.debug("&c - Start the server");
- PS.get().setPlots(DBFunc.getPlots());
- } else {
- sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
- done.set(true);
- }
- }
- });
- sendMessage("Saving configuration...");
- try {
- PS.get().config.save(PS.get().configFile);
- } catch (final IOException e) {
- sendMessage(" - &cFailed to save configuration.");
- }
- TaskManager.runTask(new Runnable() {
- @Override
- public void run() {
- try {
- boolean MV = false;
- boolean MW = false;
- if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
- MV = true;
- } else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
- MW = true;
- }
- for (final String worldname : worlds) {
- final World world = Bukkit.getWorld(getWorld(worldname));
- if (world == null) {
- sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
- }
- final String actualWorldName = world.getName();
- sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
- PS.get().removePlotAreas(actualWorldName);
- if (MV) {
- // unload world with MV
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
- try {
- Thread.sleep(1000);
- } catch (final InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- // load world with MV
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
- } else if (MW) {
- // unload world with MW
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
- try {
- Thread.sleep(1000);
- } catch (final InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- // load world with MW
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
- } else {
- // Load using Bukkit API
- // - User must set generator manually
- Bukkit.getServer().unloadWorld(world, true);
- final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
- myworld.save();
- }
- }
- } catch (final Exception e) {
- e.printStackTrace();
- }
- if (done.get()) {
- done();
- sendMessage("&aDatabase conversion is now complete!");
- PS.debug("&c - Stop the server");
- PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
- PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
- PS.debug("&c - Start the server");
- } else {
- sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
- done.set(true);
- }
- }
- });
- } catch (final Exception e) {
- e.printStackTrace();
- PS.debug("&/end/");
- }
- return true;
- }
-
- public void done() {
- PS.get().setPlots(DBFunc.getPlots());
- }
-}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// PlotSquared - A plot manager and world generator for the Bukkit API /
+// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
+// /
+// This program is free software; you can redistribute it and/or modify /
+// it under the terms of the GNU General Public License as published by /
+// the Free Software Foundation; either version 3 of the License, or /
+// (at your option) any later version. /
+// /
+// This program is distributed in the hope that it will be useful, /
+// but WITHOUT ANY WARRANTY; without even the implied warranty of /
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
+// GNU General Public License for more details. /
+// /
+// You should have received a copy of the GNU General Public License /
+// along with this program; if not, write to the Free Software Foundation, /
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
+// /
+// You can contact us via: support@intellectualsites.com /
+////////////////////////////////////////////////////////////////////////////////////////////////////
+package com.plotsquared.bukkit.database.plotme;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.WorldCreator;
+
+import com.intellectualcrafters.configuration.file.FileConfiguration;
+import com.intellectualcrafters.configuration.file.YamlConfiguration;
+import com.intellectualcrafters.plot.PS;
+import com.intellectualcrafters.plot.config.Settings;
+import com.intellectualcrafters.plot.database.DBFunc;
+import com.intellectualcrafters.plot.generator.HybridGen;
+import com.intellectualcrafters.plot.object.Plot;
+import com.intellectualcrafters.plot.object.PlotArea;
+import com.intellectualcrafters.plot.object.PlotId;
+import com.intellectualcrafters.plot.util.TaskManager;
+import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
+
+/**
+ * Created 2014-08-17 for PlotSquared
+ *
+
+
+ */
+public class LikePlotMeConverter {
+ private final String plugin;
+
+ /**
+ * Constructor
+ *
+ * @param plugin Plugin Used to run the converter
+ */
+ public LikePlotMeConverter(final String plugin) {
+ this.plugin = plugin;
+ }
+
+ public static String getWorld(final String world) {
+ for (final World newworld : Bukkit.getWorlds()) {
+ if (newworld.getName().equalsIgnoreCase(world)) {
+ return newworld.getName();
+ }
+ }
+ return world;
+ }
+
+ private void sendMessage(final String message) {
+ PS.debug("&3PlotMe&8->&3PlotSquared&8: &7" + message);
+ }
+
+ public String getPlotMePath() {
+ return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
+ }
+
+ public String getAthionPlotsPath() {
+ return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
+ }
+
+ public FileConfiguration getPlotMeConfig(final String dataFolder) {
+ final File plotMeFile = new File(dataFolder + "config.yml");
+ if (!plotMeFile.exists()) {
+ return null;
+ }
+ return YamlConfiguration.loadConfiguration(plotMeFile);
+ }
+
+ public Set getPlotMeWorlds(final FileConfiguration plotConfig) {
+ return plotConfig.getConfigurationSection("worlds").getKeys(false);
+ }
+
+ public void mergeWorldYml(final String plugin, FileConfiguration plotConfig) {
+ try {
+ File genConfig = new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
+ if (genConfig.exists()) {
+ YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
+ for (String key : yml.getKeys(true)) {
+ if (!plotConfig.contains(key)) {
+ plotConfig.set(key, yml.get(key));
+ }
+ }
+ genConfig.delete();
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void updateWorldYml(final String plugin, final String location) {
+ try {
+ final Path path = Paths.get(location);
+ final File file = new File(location);
+ if (!file.exists()) {
+ return;
+ }
+ final Charset charset = StandardCharsets.UTF_8;
+ String content = new String(Files.readAllBytes(path), charset);
+ content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
+ content = content.replaceAll(plugin, "PlotSquared");
+ Files.write(path, content.getBytes(charset));
+ } catch (IOException e) {
+ }
+ }
+
+ public boolean run(final APlotMeConnector connector) {
+ try {
+ final String dataFolder = getPlotMePath();
+ final FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
+ if (plotConfig == null) {
+ return false;
+ }
+
+ String version = plotConfig.getString("Version");
+ if (version == null) {
+ version = plotConfig.getString("version");
+ }
+ if (!connector.accepts(version)) {
+ return false;
+ }
+
+ PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
+
+ final Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
+
+ if (!connector.isValidConnection(connection)) {
+ sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
+ return false;
+ }
+
+ sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
+
+ mergeWorldYml(plugin, plotConfig);
+
+ sendMessage("Connecting to " + plugin + " DB");
+
+ int plotCount = 0;
+ final ArrayList createdPlots = new ArrayList<>();
+
+ sendMessage("Collecting plot data");
+
+ final String dbPrefix = plugin.toLowerCase();
+ sendMessage(" - " + dbPrefix + "Plots");
+ final Set worlds = getPlotMeWorlds(plotConfig);
+
+ if (Settings.CONVERT_PLOTME) {
+ sendMessage("Updating bukkit.yml");
+ updateWorldYml(plugin, "bukkit.yml");
+ updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
+ for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
+ sendMessage("Copying config for: " + world);
+ try {
+ final String actualWorldName = getWorld(world);
+ connector.copyConfig(plotConfig, world, actualWorldName);
+ PS.get().config.save(PS.get().configFile);
+ } catch (final Exception e) {
+ e.printStackTrace();
+ sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
+ }
+ }
+ }
+ final HashMap> plots = connector.getPlotMePlots(connection);
+ for (final Entry> entry : plots.entrySet()) {
+ plotCount += entry.getValue().size();
+ }
+ if (!Settings.CONVERT_PLOTME) {
+ return false;
+ }
+
+ sendMessage(" - " + dbPrefix + "Allowed");
+
+ sendMessage("Collected " + plotCount + " plots from PlotMe");
+ final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
+ if (PLOTME_DG_FILE.exists()) {
+ final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
+ try {
+ for (final String world : plots.keySet()) {
+ final String actualWorldName = getWorld(world);
+ final String plotMeWorldName = world.toLowerCase();
+ Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
+ /*
+ * TODO: dead code
+ *
+ if (pathwidth == null) {
+ pathwidth = 7;
+ }
+ */
+ PS.get().config.set("worlds." + world + ".road.width", pathwidth);
+
+ Integer pathheight = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
+ if ((pathheight == null) || (pathheight == 0)) {
+ pathheight = 64;
+ }
+ PS.get().config.set("worlds." + world + ".road.height", pathheight);
+ PS.get().config.set("worlds." + world + ".wall.height", pathheight);
+ PS.get().config.set("worlds." + world + ".plot.height", pathheight);
+ Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
+ if ((plotsize == null) || (plotsize == 0)) {
+ plotsize = 32;
+ }
+ PS.get().config.set("worlds." + world + ".plot.size", plotsize);
+ String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
+ if (wallblock == null) {
+ wallblock = "44";
+ }
+ PS.get().config.set("worlds." + world + ".wall.block", wallblock);
+ String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
+ if (floor == null) {
+ floor = "2";
+ }
+ PS.get().config.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
+ String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
+ if (filling == null) {
+ filling = "3";
+ }
+ PS.get().config.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
+ String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
+ if (road == null) {
+ road = "5";
+ }
+ PS.get().config.set("worlds." + world + ".road.block", road);
+ Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
+ if (height == 0) {
+ height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
+ if (height == 0) {
+ height = 64;
+ }
+ }
+ PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
+ PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
+ PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
+ PS.get().config.save(PS.get().configFile);
+ }
+ } catch (IOException e) {
+ }
+ }
+ for (Entry> entry : plots.entrySet()) {
+ String world = entry.getKey();
+ PlotArea area = PS.get().getPlotArea(world, null);
+ int duplicate = 0;
+ if (area != null) {
+ for (Entry entry2 : entry.getValue().entrySet()) {
+ if (area.getOwnedPlotAbs(entry2.getKey()) != null) {
+ duplicate++;
+ } else {
+ createdPlots.add(entry2.getValue());
+ }
+ }
+ if (duplicate > 0) {
+ PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
+ }
+ } else {
+ if (PS.get().plots_tmp != null) {
+ HashMap map = PS.get().plots_tmp.get(world);
+ if (map != null) {
+ for (Entry entry2 : entry.getValue().entrySet()) {
+ if (map.containsKey(entry2.getKey())) {
+ duplicate++;
+ } else {
+ createdPlots.add(entry2.getValue());
+ }
+ }
+ if (duplicate > 0) {
+ PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
+ }
+ continue;
+ }
+ }
+ createdPlots.addAll(entry.getValue().values());
+ }
+ }
+ sendMessage("Creating plot DB");
+ Thread.sleep(1000);
+ final AtomicBoolean done = new AtomicBoolean(false);
+ DBFunc.createPlotsAndData(createdPlots, new Runnable() {
+ @Override
+ public void run() {
+ if (done.get()) {
+ done();
+ sendMessage("&aDatabase conversion is now complete!");
+ PS.debug("&c - Stop the server");
+ PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
+ PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
+ PS.debug("&c - Start the server");
+ PS.get().setPlots(DBFunc.getPlots());
+ } else {
+ sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
+ done.set(true);
+ }
+ }
+ });
+ sendMessage("Saving configuration...");
+ try {
+ PS.get().config.save(PS.get().configFile);
+ } catch (final IOException e) {
+ sendMessage(" - &cFailed to save configuration.");
+ }
+ TaskManager.runTask(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ boolean MV = false;
+ boolean MW = false;
+ if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
+ MV = true;
+ } else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
+ MW = true;
+ }
+ for (final String worldname : worlds) {
+ final World world = Bukkit.getWorld(getWorld(worldname));
+ if (world == null) {
+ sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
+ }
+ final String actualWorldName = world.getName();
+ sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
+ PS.get().removePlotAreas(actualWorldName);
+ if (MV) {
+ // unload world with MV
+ Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
+ try {
+ Thread.sleep(1000);
+ } catch (final InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ // load world with MV
+ Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
+ } else if (MW) {
+ // unload world with MW
+ Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
+ try {
+ Thread.sleep(1000);
+ } catch (final InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ // load world with MW
+ Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
+ } else {
+ // Load using Bukkit API
+ // - User must set generator manually
+ Bukkit.getServer().unloadWorld(world, true);
+ final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
+ myworld.save();
+ }
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ if (done.get()) {
+ done();
+ sendMessage("&aDatabase conversion is now complete!");
+ PS.debug("&c - Stop the server");
+ PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
+ PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
+ PS.debug("&c - Start the server");
+ } else {
+ sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
+ done.set(true);
+ }
+ }
+ });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ PS.debug("&/end/");
+ }
+ return true;
+ }
+
+ public void done() {
+ PS.get().setPlots(DBFunc.getPlots());
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/ClusterFlagRemoveEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/ClusterFlagRemoveEvent.java
similarity index 97%
rename from src/main/java/com/plotsquared/bukkit/events/ClusterFlagRemoveEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/ClusterFlagRemoveEvent.java
index b4ff0f900..c8cf638c9 100644
--- a/src/main/java/com/plotsquared/bukkit/events/ClusterFlagRemoveEvent.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/events/ClusterFlagRemoveEvent.java
@@ -1,89 +1,89 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// PlotSquared - A plot manager and world generator for the Bukkit API /
-// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
-// /
-// This program is free software; you can redistribute it and/or modify /
-// it under the terms of the GNU General Public License as published by /
-// the Free Software Foundation; either version 3 of the License, or /
-// (at your option) any later version. /
-// /
-// This program is distributed in the hope that it will be useful, /
-// but WITHOUT ANY WARRANTY; without even the implied warranty of /
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
-// GNU General Public License for more details. /
-// /
-// You should have received a copy of the GNU General Public License /
-// along with this program; if not, write to the Free Software Foundation, /
-// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
-// /
-// You can contact us via: support@intellectualsites.com /
-////////////////////////////////////////////////////////////////////////////////////////////////////
-package com.plotsquared.bukkit.events;
-
-import org.bukkit.event.Cancellable;
-import org.bukkit.event.Event;
-import org.bukkit.event.HandlerList;
-
-import com.intellectualcrafters.plot.flag.Flag;
-import com.intellectualcrafters.plot.object.PlotCluster;
-
-/**
- * Called when a flag is removed from a plot
- *
-
-
- */
-public class ClusterFlagRemoveEvent extends Event implements Cancellable {
- private static HandlerList handlers = new HandlerList();
- private final PlotCluster cluster;
- private final Flag flag;
- private boolean cancelled;
-
- /**
- * PlotFlagRemoveEvent: Called when a flag is removed from a plot
- *
- * @param flag Flag that was removed
- * @param cluster PlotCluster from which the flag was removed
- */
- public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
- this.cluster = cluster;
- this.flag = flag;
- }
-
- public static HandlerList getHandlerList() {
- return handlers;
- }
-
- /**
- * Get the cluster involved
- *
- * @return PlotCluster
- */
- public PlotCluster getCluster() {
- return cluster;
- }
-
- /**
- * Get the flag involved
- *
- * @return Flag
- */
- public Flag getFlag() {
- return flag;
- }
-
- @Override
- public HandlerList getHandlers() {
- return handlers;
- }
-
- @Override
- public boolean isCancelled() {
- return cancelled;
- }
-
- @Override
- public void setCancelled(final boolean b) {
- cancelled = b;
- }
-}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// PlotSquared - A plot manager and world generator for the Bukkit API /
+// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
+// /
+// This program is free software; you can redistribute it and/or modify /
+// it under the terms of the GNU General Public License as published by /
+// the Free Software Foundation; either version 3 of the License, or /
+// (at your option) any later version. /
+// /
+// This program is distributed in the hope that it will be useful, /
+// but WITHOUT ANY WARRANTY; without even the implied warranty of /
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
+// GNU General Public License for more details. /
+// /
+// You should have received a copy of the GNU General Public License /
+// along with this program; if not, write to the Free Software Foundation, /
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
+// /
+// You can contact us via: support@intellectualsites.com /
+////////////////////////////////////////////////////////////////////////////////////////////////////
+package com.plotsquared.bukkit.events;
+
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+
+import com.intellectualcrafters.plot.flag.Flag;
+import com.intellectualcrafters.plot.object.PlotCluster;
+
+/**
+ * Called when a flag is removed from a plot
+ *
+
+
+ */
+public class ClusterFlagRemoveEvent extends Event implements Cancellable {
+ private static HandlerList handlers = new HandlerList();
+ private final PlotCluster cluster;
+ private final Flag flag;
+ private boolean cancelled;
+
+ /**
+ * PlotFlagRemoveEvent: Called when a flag is removed from a plot
+ *
+ * @param flag Flag that was removed
+ * @param cluster PlotCluster from which the flag was removed
+ */
+ public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
+ this.cluster = cluster;
+ this.flag = flag;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ /**
+ * Get the cluster involved
+ *
+ * @return PlotCluster
+ */
+ public PlotCluster getCluster() {
+ return cluster;
+ }
+
+ /**
+ * Get the flag involved
+ *
+ * @return Flag
+ */
+ public Flag getFlag() {
+ return flag;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(final boolean b) {
+ cancelled = b;
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerClaimPlotEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerClaimPlotEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerClaimPlotEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerClaimPlotEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerEnterPlotEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerEnterPlotEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerEnterPlotEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerEnterPlotEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerLeavePlotEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerLeavePlotEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerLeavePlotEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerLeavePlotEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerPlotDeniedEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerPlotDeniedEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerPlotDeniedEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerPlotDeniedEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerPlotHelperEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerPlotHelperEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerPlotHelperEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerPlotHelperEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlayerTeleportToPlotEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerTeleportToPlotEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlayerTeleportToPlotEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlayerTeleportToPlotEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotFlagAddEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotFlagAddEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotFlagAddEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotFlagAddEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotFlagRemoveEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotFlagRemoveEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotFlagRemoveEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotFlagRemoveEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotMergeEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotMergeEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotMergeEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotMergeEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotRateEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotRateEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotRateEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotRateEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/events/PlotUnlinkEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotUnlinkEvent.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/events/PlotUnlinkEvent.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotUnlinkEvent.java
diff --git a/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java
diff --git a/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java
similarity index 97%
rename from src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java
index 7f6023daf..2bf04f751 100644
--- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java
@@ -1,2190 +1,2190 @@
-package com.plotsquared.bukkit.listeners;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-import java.util.UUID;
-import java.util.regex.Pattern;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
-import org.bukkit.block.BlockState;
-import org.bukkit.command.PluginCommand;
-import org.bukkit.entity.Animals;
-import org.bukkit.entity.Arrow;
-import org.bukkit.entity.Creature;
-import org.bukkit.entity.EnderDragon;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Hanging;
-import org.bukkit.entity.HumanEntity;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Monster;
-import org.bukkit.entity.Player;
-import org.bukkit.entity.Projectile;
-import org.bukkit.entity.TNTPrimed;
-import org.bukkit.entity.Tameable;
-import org.bukkit.entity.ThrownPotion;
-import org.bukkit.entity.Vehicle;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.Action;
-import org.bukkit.event.block.BlockBreakEvent;
-import org.bukkit.event.block.BlockDamageEvent;
-import org.bukkit.event.block.BlockDispenseEvent;
-import org.bukkit.event.block.BlockFadeEvent;
-import org.bukkit.event.block.BlockFormEvent;
-import org.bukkit.event.block.BlockFromToEvent;
-import org.bukkit.event.block.BlockGrowEvent;
-import org.bukkit.event.block.BlockIgniteEvent;
-import org.bukkit.event.block.BlockPhysicsEvent;
-import org.bukkit.event.block.BlockPistonExtendEvent;
-import org.bukkit.event.block.BlockPistonRetractEvent;
-import org.bukkit.event.block.BlockPlaceEvent;
-import org.bukkit.event.block.BlockRedstoneEvent;
-import org.bukkit.event.block.BlockSpreadEvent;
-import org.bukkit.event.block.EntityBlockFormEvent;
-import org.bukkit.event.entity.CreatureSpawnEvent;
-import org.bukkit.event.entity.EntityChangeBlockEvent;
-import org.bukkit.event.entity.EntityDamageByEntityEvent;
-import org.bukkit.event.entity.EntityExplodeEvent;
-import org.bukkit.event.entity.ExplosionPrimeEvent;
-import org.bukkit.event.entity.PotionSplashEvent;
-import org.bukkit.event.entity.ProjectileHitEvent;
-import org.bukkit.event.hanging.HangingBreakByEntityEvent;
-import org.bukkit.event.hanging.HangingPlaceEvent;
-import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.event.inventory.InventoryCloseEvent;
-import org.bukkit.event.player.AsyncPlayerChatEvent;
-import org.bukkit.event.player.PlayerBucketEmptyEvent;
-import org.bukkit.event.player.PlayerBucketFillEvent;
-import org.bukkit.event.player.PlayerChangedWorldEvent;
-import org.bukkit.event.player.PlayerCommandPreprocessEvent;
-import org.bukkit.event.player.PlayerEggThrowEvent;
-import org.bukkit.event.player.PlayerInteractEntityEvent;
-import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.event.player.PlayerMoveEvent;
-import org.bukkit.event.player.PlayerQuitEvent;
-import org.bukkit.event.player.PlayerTeleportEvent;
-import org.bukkit.event.vehicle.VehicleCreateEvent;
-import org.bukkit.event.vehicle.VehicleDestroyEvent;
-import org.bukkit.event.world.StructureGrowEvent;
-import org.bukkit.help.HelpTopic;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.metadata.FixedMetadataValue;
-import org.bukkit.metadata.MetadataValue;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.projectiles.BlockProjectileSource;
-import org.bukkit.projectiles.ProjectileSource;
-import org.bukkit.util.Vector;
-
-import com.intellectualcrafters.plot.PS;
-import com.intellectualcrafters.plot.config.C;
-import com.intellectualcrafters.plot.config.Settings;
-import com.intellectualcrafters.plot.flag.Flag;
-import com.intellectualcrafters.plot.flag.FlagManager;
-import com.intellectualcrafters.plot.object.Location;
-import com.intellectualcrafters.plot.object.Plot;
-import com.intellectualcrafters.plot.object.PlotArea;
-import com.intellectualcrafters.plot.object.PlotBlock;
-import com.intellectualcrafters.plot.object.PlotHandler;
-import com.intellectualcrafters.plot.object.PlotId;
-import com.intellectualcrafters.plot.object.PlotInventory;
-import com.intellectualcrafters.plot.object.PlotPlayer;
-import com.intellectualcrafters.plot.object.StringWrapper;
-import com.intellectualcrafters.plot.util.EventUtil;
-import com.intellectualcrafters.plot.util.ExpireManager;
-import com.intellectualcrafters.plot.util.MainUtil;
-import com.intellectualcrafters.plot.util.MathMan;
-import com.intellectualcrafters.plot.util.Permissions;
-import com.intellectualcrafters.plot.util.RegExUtil;
-import com.intellectualcrafters.plot.util.StringMan;
-import com.intellectualcrafters.plot.util.TaskManager;
-import com.intellectualcrafters.plot.util.UUIDHandler;
-import com.plotsquared.bukkit.BukkitMain;
-import com.plotsquared.bukkit.object.BukkitLazyBlock;
-import com.plotsquared.bukkit.object.BukkitPlayer;
-import com.plotsquared.bukkit.util.BukkitUtil;
-import com.plotsquared.listener.PlayerBlockEventType;
-
-/**
- * Player Events involving plots
- *
- */
-@SuppressWarnings({ "deprecation", "unchecked" })
-public class PlayerEvents extends com.plotsquared.listener.PlotListener implements Listener {
-
- private boolean pistonBlocks = true;
- private float lastRadius;
- // To prevent recursion
- private boolean tmp_teleport = true;
-
- public static void sendBlockChange(final org.bukkit.Location bloc, final Material type, final byte data) {
- TaskManager.runTaskLater(new Runnable() {
- @Override
- public void run() {
- final String world = bloc.getWorld().getName();
- final int x = bloc.getBlockX();
- final int z = bloc.getBlockZ();
- final int distance = Bukkit.getViewDistance() * 16;
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer player = entry.getValue();
- final 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, type, data);
- }
- }
- }
- }, 3);
- }
-
- @EventHandler
- public void onRedstoneEvent(final BlockRedstoneEvent event) {
- final Block block = event.getBlock();
- switch (block.getType()) {
- case REDSTONE_LAMP_OFF:
- case REDSTONE_WIRE:
- case REDSTONE_LAMP_ON:
- case PISTON_BASE:
- case PISTON_STICKY_BASE:
- case IRON_DOOR_BLOCK:
- case LEVER:
- case WOODEN_DOOR:
- case FENCE_GATE:
- case WOOD_BUTTON:
- case STONE_BUTTON:
- case IRON_PLATE:
- case WOOD_PLATE:
- case STONE_PLATE:
- case GOLD_PLATE:
- case SPRUCE_DOOR:
- case BIRCH_DOOR:
- case JUNGLE_DOOR:
- case ACACIA_DOOR:
- case DARK_OAK_DOOR:
- case IRON_TRAPDOOR:
- case SPRUCE_FENCE_GATE:
- case BIRCH_FENCE_GATE:
- case JUNGLE_FENCE_GATE:
- case ACACIA_FENCE_GATE:
- case DARK_OAK_FENCE_GATE:
- case POWERED_RAIL:
- return;
- default:
- final Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- return;
- }
- final Flag redstone = FlagManager.getPlotFlagRaw(plot, "redstone");
- if (redstone != null) {
- if ((Boolean) redstone.getValue()) {
- return;
- } else {
- event.setNewCurrent(0);
- return;
- }
- }
- if (Settings.REDSTONE_DISABLER) {
- if (UUIDHandler.getPlayer(plot.owner) == null) {
- boolean disable = true;
- for (final UUID trusted : plot.getTrusted()) {
- if (UUIDHandler.getPlayer(trusted) != null) {
- disable = false;
- break;
- }
- }
- if (disable) {
- event.setNewCurrent(0);
- return;
- }
- }
- }
- if (Settings.REDSTONE_DISABLER_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(final BlockPhysicsEvent event) {
- switch (event.getChangedType()) {
- case REDSTONE_COMPARATOR_OFF:
- case REDSTONE_COMPARATOR_ON: {
- final Block block = event.getBlock();
- final Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- return;
- }
- if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
- event.setCancelled(true);
- }
- return;
- }
- case DRAGON_EGG:
- case ANVIL:
- case SAND:
- case GRAVEL:
- final Block block = event.getBlock();
- final Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Plot plot = area.getOwnedPlotAbs(loc);
- if (plot != null && FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
- event.setCancelled(true);
- return;
- }
- return;
- default:
- break;
- }
- }
-
- @EventHandler
- public void onProjectileHit(final ProjectileHitEvent event) {
- final Projectile entity = event.getEntity();
- final Location loc = BukkitUtil.getLocation(entity);
- if (!PS.get().hasPlotArea(loc.getWorld())) {
- return;
- }
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getPlotAbs(loc);
- //
- final ProjectileSource shooter = entity.getShooter();
- if (shooter instanceof Player) {
- final PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) {
- entity.remove();
- }
- return;
- }
- if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) {
- return;
- }
- entity.remove();
- } else if (!(shooter instanceof Entity) && shooter != null) {
- if (plot == null) {
- entity.remove();
- return;
- }
- final Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
- if (!area.contains(sLoc.getX(), sLoc.getZ())) {
- entity.remove();
- return;
- }
- final Plot sPlot = area.getOwnedPlotAbs(sLoc);
- if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
- entity.remove();
- }
- }
- }
-
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
- String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim();
- if (msg.isEmpty()) {
- return;
- }
- final String[] split = msg.split(" ");
- final PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
- if (cmd == null) {
- if (split[0].equals("plotme") || split[0].equals("ap")) {
- final Player player = event.getPlayer();
- if (Settings.USE_PLOTME_ALIAS) {
- player.performCommand("plots " + StringMan.join(Arrays.copyOfRange(split, 1, split.length), " "));
- } else {
- MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
- }
- event.setCancelled(true);
- return;
- }
- }
- final Player player = event.getPlayer();
- final BukkitPlayer pp = (BukkitPlayer) BukkitUtil.getPlayer(player);
- Plot plot = pp.getCurrentPlot();
- if (plot == null) {
- return;
- }
- Flag flag = FlagManager.getPlotFlagRaw(plot, "blocked-cmds");
- if (flag == null || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
- return;
- }
- final List v = (List) flag.getValue();
- final String[] parts = msg.split(" ");
- String c = parts[0];
- if (parts[0].contains(":")) {
- c = parts[0].split(":")[1];
- msg = msg.replace(parts[0].split(":")[0] + ":", "");
- }
- final String l = c;
- final List aliases = new ArrayList<>();
- for (final HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) {
- if (c.equals(cmdLabel.getName())) {
- break;
- }
- PluginCommand p;
- final String label = cmdLabel.getName().replaceFirst("/", "");
- if (aliases.contains(label)) {
- continue;
- }
- 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 (final String s : v) {
- 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()) {
- MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
- 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)) {
- event.setCancelled(true);
- }
- return;
- }
- }
- }
-
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onConnect(final PlayerJoinEvent event) {
- final Player player = event.getPlayer();
- BukkitUtil.getPlayer(event.getPlayer()).unregister();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Now
- String name = pp.getName();
- StringWrapper sw = new StringWrapper(name);
- final UUID uuid = pp.getUUID();
- UUIDHandler.add(sw, uuid);
-
- Location loc = pp.getLocation();
- PlotArea area = loc.getPlotArea();
- final Plot plot;
- if (area != null) {
- plot = area.getPlot(loc);
- if (plot != null) {
- plotEntry(pp, plot);
- }
- } else {
- plot = null;
- }
- // Delayed
-
- // Async
- TaskManager.runTaskLaterAsync(new Runnable() {
- @Override
- public void run() {
- if (!player.hasPlayedBefore() && player.isOnline()) {
- player.saveData();
- }
- ExpireManager.dates.put(uuid, System.currentTimeMillis());
- if (BukkitMain.worldEdit != null) {
- if (pp.getAttribute("worldedit")) {
- MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASSED);
- }
- }
- if (PS.get().update != null && Permissions.hasPermission(pp, C.PERMISSION_ADMIN_UPDATE) && Settings.UPDATE_NOTIFICATIONS) {
- MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update");
- }
- if (Settings.TELEPORT_ON_LOGIN && plot != null) {
- TaskManager.runTask(new Runnable() {
- @Override
- public void run() {
- plot.teleportPlayer(pp);
- }
- });
- MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
- }
- }
- }, 20);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void PlayerMove(final PlayerMoveEvent event) {
- final org.bukkit.Location from = event.getFrom();
- final org.bukkit.Location to = event.getTo();
- int x2;
- if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
-
- // Cancel teleport
- TaskManager.TELEPORT_QUEUE.remove(pp.getName());
-
- // Set last location
- Location loc = BukkitUtil.getLocation(to);
- pp.setMeta("location", loc);
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- pp.deleteMeta("lastplot");
- return;
- }
- Plot now = area.getPlotAbs(loc);
- final Plot lastPlot = pp.getMeta("lastplot");
- if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
- if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
- player.teleport(from);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
- }
- event.setCancelled(true);
- return;
- }
- } else if (now.equals(lastPlot)) {
- return;
- } else if (!plotEntry(pp, now)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- player.teleport(from);
- event.setCancelled(true);
- return;
- }
- final Integer border = area.getBorder();
- if (x2 > border) {
- to.setX(border - 4);
- player.teleport(event.getTo());
- MainUtil.sendMessage(pp, C.BORDER);
- return;
- } else if (x2 < -border) {
- to.setX(-border + 4);
- player.teleport(event.getTo());
- MainUtil.sendMessage(pp, C.BORDER);
- return;
- }
- return;
- }
- int z2;
- if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
-
- // Cancel teleport
- TaskManager.TELEPORT_QUEUE.remove(pp.getName());
-
- // Set last location
- Location loc = BukkitUtil.getLocation(to);
- pp.setMeta("location", loc);
-
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- pp.deleteMeta("lastplot");
- return;
- }
- Plot now = area.getPlotAbs(loc);
- final Plot lastPlot = pp.getMeta("lastplot");
- if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
- if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
- player.teleport(from);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
- }
- event.setCancelled(true);
- return;
- }
- } else if (now.equals(lastPlot)) {
- return;
- } else if (!plotEntry(pp, now)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- player.teleport(from);
- event.setCancelled(true);
- return;
- }
- final Integer border = area.getBorder();
- if (z2 > border) {
- to.setZ(border - 4);
- player.teleport(event.getTo());
- MainUtil.sendMessage(pp, C.BORDER);
- } else if (z2 < -border) {
- to.setZ(-border + 4);
- player.teleport(event.getTo());
- MainUtil.sendMessage(pp, C.BORDER);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
- public void onChat(final AsyncPlayerChatEvent event) {
- final Player player = event.getPlayer();
- final PlotPlayer plr = BukkitUtil.getPlayer(player);
- Location loc = plr.getLocation();
- PlotArea area = loc.getPlotArea();
- if (area == null || !area.PLOT_CHAT && !plr.getAttribute("chat")) {
- return;
- }
- final Plot plot = area.getPlotAbs(loc);
- if (plot == null) {
- return;
- }
- final String message = event.getMessage();
- String format = C.PLOT_CHAT_FORMAT.s();
- final String sender = event.getPlayer().getDisplayName();
- final PlotId id = plot.getId();
- final Set recipients = event.getRecipients();
- recipients.clear();
- for (final Player p : Bukkit.getOnlinePlayers()) {
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- if (pp.getAttribute("chatspy")) {
- String spy = event.getFormat();
- spy = String.format(spy, sender, message);
- pp.sendMessage(spy);
- } else if (plot.equals(pp.getCurrentPlot())) {
- recipients.add(p);
- }
- }
- format = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", "%s").replaceAll("%msg%", "%s");
- format = ChatColor.translateAlternateColorCodes('&', format);
- event.setFormat(format);
- }
-
- @EventHandler(priority = EventPriority.LOWEST)
- public void BlockDestroy(final BlockBreakEvent event) {
- final Player player = event.getPlayer();
- final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Plot plot = area.getPlotAbs(loc);
- if (plot != null) {
- if (event.getBlock().getY() == 0) {
- event.setCancelled(true);
- return;
- }
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (!plot.hasOwner()) {
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
- event.setCancelled(true);
- return;
- } else if (!plot.isAdded(pp.getUUID())) {
- final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
- final Block block = event.getBlock();
- if (destroy != null && ((HashSet) destroy.getValue())
- .contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
- return;
- }
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
- event.setCancelled(true);
- } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("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;
- }
- }
- return;
- }
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
- 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(final EntityExplodeEvent event) {
- Location loc = BukkitUtil.getLocation(event.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- if (!PS.get().hasPlotArea(loc.getWorld())) {
- return;
- }
- final Iterator iter = event.blockList().iterator();
- while (iter.hasNext()) {
- iter.next();
- if (loc.getPlotArea() != null) {
- iter.remove();
- }
- }
- } else {
- Plot plot = area.getOwnedPlot(loc);
- if (plot != null) {
- if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
- List meta = event.getEntity().getMetadata("plot");
- Plot origin;
- if (meta.isEmpty()) {
- origin = plot;
- } else {
- origin = (Plot) meta.get(0).value();
- }
- if (lastRadius != 0) {
- final List nearby = event.getEntity().getNearbyEntities(lastRadius, lastRadius, lastRadius);
- for (final Entity near : nearby) {
- if (near instanceof TNTPrimed || near.getType() == EntityType.MINECART_TNT) {
- if (!near.hasMetadata("plot")) {
- near.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
- }
- }
- }
- lastRadius = 0;
- }
- final Iterator iter = event.blockList().iterator();
- while (iter.hasNext()) {
- final Block b = iter.next();
- loc = BukkitUtil.getLocation(b.getLocation());
- if (!area.contains(loc.getX(), loc.getZ()) || !origin.equals(area.getOwnedPlot(loc))) {
- iter.remove();
- }
- }
- }
- } else {
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onWorldChanged(final PlayerChangedWorldEvent event) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
-
-
- // Delete last location
- pp.deleteMeta("location");
- Plot plot = (Plot) pp.deleteMeta("lastplot");
- if (plot != null) {
- plotExit(pp, plot);
- }
-
- if (BukkitMain.worldEdit != null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
- if (pp.getAttribute("worldedit")) {
- pp.removeAttribute("worldedit");
- }
- }
- }
- if (Settings.PERMISSION_CACHING) {
- pp.deleteMeta("perm");
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) {
- final String world = event.getBlock().getWorld().getName();
- if (!PS.get().hasPlotArea(world)) {
- return;
- }
- final Entity e = event.getEntity();
- if (!(e instanceof org.bukkit.entity.FallingBlock)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onEntityBlockForm(final EntityBlockFormEvent e) {
- final String world = e.getBlock().getWorld().getName();
- if (!PS.get().hasPlotArea(world)) {
- return;
- }
- if (BukkitUtil.getLocation(e.getBlock().getLocation()).getPlotArea() != null) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBS(final BlockSpreadEvent e) {
- final Block b = e.getBlock();
- final Location loc = BukkitUtil.getLocation(b.getLocation());
- if (loc.isPlotRoad()) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBF(final BlockFormEvent e) {
- final Block b = e.getBlock();
- final Location loc = BukkitUtil.getLocation(b.getLocation());
- if (loc.isPlotRoad()) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBD(final BlockDamageEvent event) {
- final Player player = event.getPlayer();
- Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
- if (player == null) {
- if (loc.isPlotRoad()) {
- event.setCancelled(true);
- return;
- }
- }
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Plot plot = area.getPlotAbs(loc);
- if (plot != null) {
- if (loc.getY() == 0) {
- event.setCancelled(true);
- return;
- }
- if (!plot.hasOwner()) {
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
- return;
- }
- event.setCancelled(true);
- return;
- }
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (!plot.isAdded(pp.getUUID())) {
- final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
- final Block block = event.getBlock();
- if (destroy != null && ((HashSet) destroy.getValue())
- .contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
- return;
- }
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- return;
- }
- event.setCancelled(true);
- return;
- }
- return;
- }
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
- return;
- }
- event.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onFade(final BlockFadeEvent e) {
- final Block b = e.getBlock();
- Location loc = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- if (area.getOwnedPlot(loc) == null) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onChange(final BlockFromToEvent e) {
- final Block b = e.getBlock();
- Location loc = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlot(loc);
- if (plot == null || FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onGrow(final BlockGrowEvent e) {
- final Block b = e.getBlock();
- final Location loc = BukkitUtil.getLocation(b.getLocation());
- if (loc.isUnownedPlotArea()) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
- final Block block = event.getBlock();
- final Location loc = BukkitUtil.getLocation(block.getLocation());
- final BlockFace face = event.getDirection();
- final Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- if (!PS.get().hasPlotArea(loc.getWorld())) {
- return;
- }
- for (final Block b : event.getBlocks()) {
- if (BukkitUtil.getLocation(b.getLocation().add(relative)).getPlotArea() != null) {
- event.setCancelled(true);
- return;
- }
- }
- }
- final Plot plot = area.getOwnedPlot(loc);
- if (plot == null) {
- event.setCancelled(true);
- return;
- }
- final List blocks = event.getBlocks();
- for (final Block b : blocks) {
- final Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative));
- if (!area.contains(bloc.getX(), bloc.getZ())) {
- event.setCancelled(true);
- return;
- }
- if (!plot.equals(area.getOwnedPlot(bloc))) {
- event.setCancelled(true);
- return;
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
- final Block block = event.getBlock();
- Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- if (!PS.get().hasPlotArea(loc.getWorld())) {
- return;
- }
- if (pistonBlocks) {
- try {
- for (final Block pulled : event.getBlocks()) {
- loc = BukkitUtil.getLocation(pulled.getLocation());
- if (loc.getPlotArea() != null) {
- event.setCancelled(true);
- return;
- }
- }
- } catch (final Throwable e) {
- pistonBlocks = false;
- }
- }
- if (!pistonBlocks && block.getType() != Material.PISTON_BASE) {
- final BlockFace dir = event.getDirection();
- loc = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
- if (loc.getPlotArea() != null) {
- event.setCancelled(true);
- return;
- }
- }
- return;
- }
- Plot plot = area.getOwnedPlot(loc);
- if (pistonBlocks) {
- try {
- for (final Block pulled : event.getBlocks()) {
- loc = BukkitUtil.getLocation(pulled.getLocation());
- if (!area.contains(loc.getX(), loc.getZ())) {
- event.setCancelled(true);
- return;
- }
- Plot newPlot = area.getOwnedPlot(loc);
- if (!Objects.equals(plot, newPlot)) {
- event.setCancelled(true);
- return;
- }
- }
- } catch (final Throwable e) {
- pistonBlocks = false;
- }
- }
- if (!pistonBlocks && block.getType() != Material.PISTON_BASE) {
- final BlockFace dir = event.getDirection();
- loc = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
- if (!area.contains(loc)) {
- event.setCancelled(true);
- return;
- }
- Plot newPlot = area.getOwnedPlot(loc);
- if (!Objects.equals(plot, newPlot)) {
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockDispense(final BlockDispenseEvent e) {
- Material type = e.getItem().getType();
- if (type != Material.WATER_BUCKET && type != Material.LAVA_BUCKET) {
- return;
- }
- final Location loc = BukkitUtil.getLocation(e.getVelocity().toLocation(e.getBlock().getWorld()));
- if (loc.isPlotRoad()) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onStructureGrow(final StructureGrowEvent e) {
- if (!PS.get().hasPlotArea(e.getWorld().getName())) {
- return;
- }
- final List blocks = e.getBlocks();
- if (blocks.isEmpty()) {
- return;
- }
- Location loc = BukkitUtil.getLocation(blocks.get(0).getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- for (int i = blocks.size() - 1; i >= 0; i--) {
- loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
- if (loc.getPlotArea() != null) {
- blocks.remove(i);
- }
- }
- } else {
- Plot origin = area.getOwnedPlot(loc);
- if (origin == null) {
- e.setCancelled(true);
- return;
- }
- for (int i = blocks.size() - 1; i >= 0; i--) {
- loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
- if (!area.contains(loc.getX(), loc.getZ())) {
- blocks.remove(i);
- continue;
- }
- final Plot plot = area.getOwnedPlot(loc);
- if (!Objects.equals(plot, origin)) {
- e.getBlocks().remove(i);
- }
- }
- }
- final Plot origin = area.getPlotAbs(loc);
- if (origin == null) {
- e.setCancelled(true);
- return;
- }
- for (int i = blocks.size() - 1; i >= 0; i--) {
- loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
- final Plot plot = area.getOwnedPlot(loc);
- if (!Objects.equals(plot, origin)) {
- e.getBlocks().remove(i);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
- public void onInteract(final PlayerInteractEvent event) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- PlotArea area = pp.getPlotAreaAbs();
- if (area == null) {
- return;
- }
- PlayerBlockEventType eventType = null;
- BukkitLazyBlock lb;
- Location loc;
- final Action action = event.getAction();
- switch (action) {
- case PHYSICAL: {
- eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
- Block block = event.getClickedBlock();
- lb = new BukkitLazyBlock(block);
- loc = BukkitUtil.getLocation(block.getLocation());
- break;
- }
- case RIGHT_CLICK_BLOCK: {
- Block block = event.getClickedBlock();
- loc = BukkitUtil.getLocation(block.getLocation());
- final Material blockType = block.getType();
- final int blockId = blockType.getId();
- switch (blockType) {
- case ANVIL:
- case ACACIA_DOOR:
- case BIRCH_DOOR:
- case DARK_OAK_DOOR:
- case IRON_DOOR:
- case JUNGLE_DOOR:
- case SPRUCE_DOOR:
- case TRAP_DOOR:
- case IRON_TRAPDOOR:
- case WOOD_DOOR:
- case WOODEN_DOOR:
- case TRAPPED_CHEST:
- case ENDER_CHEST:
- case CHEST:
- case ACACIA_FENCE_GATE:
- case BIRCH_FENCE_GATE:
- case DARK_OAK_FENCE_GATE:
- case FENCE_GATE:
- case JUNGLE_FENCE_GATE:
- case SPRUCE_FENCE_GATE:
- case LEVER:
- case DIODE:
- case DIODE_BLOCK_OFF:
- case DIODE_BLOCK_ON:
- case COMMAND:
- case REDSTONE_COMPARATOR:
- case REDSTONE_COMPARATOR_OFF:
- case REDSTONE_COMPARATOR_ON:
- case REDSTONE_ORE:
- case WOOD_BUTTON:
- case STONE_BUTTON:
- case BEACON:
- case BED_BLOCK:
- case SIGN:
- case WALL_SIGN:
- case SIGN_POST:
- case ENCHANTMENT_TABLE:
- case BREWING_STAND:
- case STANDING_BANNER:
- case BURNING_FURNACE:
- case FURNACE:
- case CAKE_BLOCK:
- case DISPENSER:
- case DROPPER:
- case HOPPER:
- case NOTE_BLOCK:
- case JUKEBOX:
- case WORKBENCH:
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
- break;
- case DRAGON_EGG:
- eventType = PlayerBlockEventType.TELEPORT_OBJECT;
- break;
- default:
- if (blockId > 197) {
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
- }
- break;
- }
- lb = new BukkitLazyBlock(blockId, block);
- final ItemStack hand = player.getItemInHand();
- if (eventType != null && !player.isSneaking()) {
- break;
- }
- Material type = hand == null ? null : hand.getType();
- int id = type == null ? 0 : type.getId();
- if (id == 0) {
- eventType = PlayerBlockEventType.INTERACT_BLOCK;
- lb = new BukkitLazyBlock(id, block);
- break;
- } else if (id < 198) {
- loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation());
- eventType = PlayerBlockEventType.PLACE_BLOCK;
- lb = new BukkitLazyBlock(id, block);
- break;
- }
- Material handType = hand.getType();
- lb = new BukkitLazyBlock(new PlotBlock((short) handType.getId(), (byte) 0));
- switch (handType) {
- case MONSTER_EGG:
- case MONSTER_EGGS:
- eventType = PlayerBlockEventType.SPAWN_MOB;
- break;
-
- case ARMOR_STAND:
- loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation());
- eventType = PlayerBlockEventType.PLACE_MISC;
- break;
-
- case WRITTEN_BOOK:
- case BOOK_AND_QUILL:
- case BOOK:
- eventType = PlayerBlockEventType.READ;
- break;
-
- case APPLE:
- case BAKED_POTATO:
- case MUSHROOM_SOUP:
- case BREAD:
- case CARROT:
- case CARROT_ITEM:
- case COOKIE:
- case GRILLED_PORK:
- case POISONOUS_POTATO:
- case MUTTON:
- case PORK:
- case POTATO:
- case POTATO_ITEM:
- case POTION:
- case PUMPKIN_PIE:
- case RABBIT:
- case RABBIT_FOOT:
- case RABBIT_STEW:
- case RAW_BEEF:
- case RAW_FISH:
- case RAW_CHICKEN:
- eventType = PlayerBlockEventType.EAT;
- break;
- case MINECART:
- case STORAGE_MINECART:
- case POWERED_MINECART:
- case HOPPER_MINECART:
- case EXPLOSIVE_MINECART:
- case COMMAND_MINECART:
- case BOAT:
- eventType = PlayerBlockEventType.PLACE_VEHICLE;
- break;
- case PAINTING:
- case ITEM_FRAME:
- loc = 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();
- loc = BukkitUtil.getLocation(block.getLocation());
- eventType = PlayerBlockEventType.BREAK_BLOCK;
- lb = new BukkitLazyBlock(block);
- break;
- default:
- return;
- }
- if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, loc, lb, true)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void MobSpawn(final CreatureSpawnEvent event) {
- final Entity entity = event.getEntity();
- if (entity instanceof Player) {
- return;
- }
- final Location loc = BukkitUtil.getLocation(entity.getLocation());
- final PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
- switch (reason) {
- case SPAWNER_EGG:
- case DISPENSE_EGG:
- if (!area.SPAWN_EGGS) {
- event.setCancelled(true);
- return;
- }
- break;
- case BREEDING:
- if (!area.SPAWN_BREEDING) {
- event.setCancelled(true);
- return;
- }
- break;
- case CUSTOM:
- if (!area.SPAWN_CUSTOM && entity.getType().getTypeId() != 30) {
- event.setCancelled(true);
- return;
- }
- break;
- }
- final Plot plot = area.getOwnedPlotAbs(loc);
- 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(final EntityChangeBlockEvent event) {
- if (event.getEntityType() != EntityType.FALLING_BLOCK) {
- return;
- }
- final Block block = event.getBlock();
- final World world = block.getWorld();
- final String worldname = world.getName();
- if (!PS.get().hasPlotArea(worldname)) {
- return;
- }
- final Location loc = BukkitUtil.getLocation(block.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- event.setCancelled(true);
- return;
- }
- if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
- 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) PS.get().IMP, plot));
- }
- }
-
- @EventHandler
- public void onPrime(final ExplosionPrimeEvent event) {
- lastRadius = event.getRadius() + 1;
- }
-
- public boolean checkEntity(Plot plot, String... flags) {
- int[] mobs = null;
- for (String flag : flags) {
- int i;
- switch (flag) {
- case "entity-cap":
- i = 0;
- break;
- case "mob-cap":
- i = 3;
- break;
- case "hostile-cap":
- i = 2;
- break;
- case "animal-cap":
- i = 1;
- break;
- case "vehicle-cap":
- i = 4;
- break;
- case "misc-cap":
- i = 5;
- break;
- default:
- i = 0;
- }
- final Flag plotFlag = FlagManager.getPlotFlagRaw(plot, flag);
- if (plotFlag == null) {
- continue;
- }
- if (mobs == null) {
- mobs = plot.countEntities();
- }
- if (mobs[i] >= (Integer) plotFlag.getValue()) {
- return true;
- }
- }
- return false;
- }
-
- public boolean checkEntity(final Entity entity, final Plot plot) {
- if (plot == null || plot.owner == null || plot.settings == null || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS
- .isEmpty
- ()) {
- return false;
- }
- switch (entity.getType()) {
- case PLAYER:
- return false;
- case SMALL_FIREBALL:
- case FIREBALL:
- case DROPPED_ITEM:
- case EGG:
- case THROWN_EXP_BOTTLE:
- case SPLASH_POTION:
- case SNOWBALL:
- case ENDER_PEARL:
- case ARROW:
- // projectile
- case PRIMED_TNT:
- case FALLING_BLOCK:
- // Block entities
- case ENDER_CRYSTAL:
- case COMPLEX_PART:
- case FISHING_HOOK:
- case ENDER_SIGNAL:
- case EXPERIENCE_ORB:
- case LEASH_HITCH:
- case FIREWORK:
- case WEATHER:
- case LIGHTNING:
- case WITHER_SKULL:
- case UNKNOWN:
- // non moving / unremovable
- return checkEntity(plot, "entity-cap");
- case ITEM_FRAME:
- case PAINTING:
- case ARMOR_STAND:
- return checkEntity(plot, "entity-cap", "misc-cap");
- // misc
- case MINECART:
- case MINECART_CHEST:
- case MINECART_COMMAND:
- case MINECART_FURNACE:
- case MINECART_HOPPER:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT:
- case BOAT:
- return checkEntity(plot, "entity-cap", "vehicle-cap");
- case RABBIT:
- case SHEEP:
- case MUSHROOM_COW:
- case OCELOT:
- case PIG:
- case HORSE:
- case SQUID:
- case VILLAGER:
- case IRON_GOLEM:
- case WOLF:
- case CHICKEN:
- case COW:
- case SNOWMAN:
- case BAT:
- // animal
- return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap");
- case BLAZE:
- case CAVE_SPIDER:
- case CREEPER:
- case ENDERMAN:
- case ENDERMITE:
- case ENDER_DRAGON:
- case GHAST:
- case GIANT:
- case GUARDIAN:
- case MAGMA_CUBE:
- case PIG_ZOMBIE:
- case SILVERFISH:
- case SKELETON:
- case SLIME:
- case SPIDER:
- case WITCH:
- case WITHER:
- case ZOMBIE:
- // monster
- return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap");
- default:
- String[] types;
- if (entity instanceof LivingEntity) {
- if (entity instanceof Animals) {
- types = new String[] { "entity-cap", "mob-cap", "animal-cap" };
- } else if (entity instanceof Monster) {
- types = new String[] { "entity-cap", "mob-cap", "hostile-cap" };
- } else {
- types = new String[] { "entity-cap", "mob-cap" };
- }
- } else if (entity instanceof Vehicle) {
- types = new String[] { "entity-cap", "vehicle-cap" };
- } else if (entity instanceof Hanging) {
- types = new String[] { "entity-cap", "misc-cap" };
- } else {
- types = new String[] { "entity-cap" };
- }
- return checkEntity(plot, types);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBlockIgnite(final BlockIgniteEvent e) {
- final Player player = e.getPlayer();
- final Block b = e.getBlock();
- final Location loc;
- if (b != null) {
- loc = BukkitUtil.getLocation(b.getLocation());
- } else {
- final Entity ent = e.getIgnitingEntity();
- if (ent != null) {
- loc = BukkitUtil.getLocation(ent);
- } else {
- if (player != null) {
- loc = BukkitUtil.getLocation(player);
- } else {
- return;
- }
- }
- }
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- if (e.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) {
- e.setCancelled(true);
- return;
- }
- if (player == null) {
- e.setCancelled(true);
- return;
- }
- final Player p = e.getPlayer();
- final Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- e.setCancelled(true);
- }
- } else {
- if (!plot.hasOwner()) {
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
- e.setCancelled(true);
- }
- } else {
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- 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);
- e.setCancelled(true);
- }
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onTeleport(final PlayerTeleportEvent event) {
- if (event.getTo() == null || event.getFrom() == null) {
- BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("location");
- BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("lastplot");
- return;
- }
- final org.bukkit.Location from = event.getFrom();
- final org.bukkit.Location to = event.getTo();
- int x2;
- if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- Location loc = BukkitUtil.getLocation(to);
- pp.setMeta("location", loc);
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot now = area.getPlotAbs(loc);
- final Plot lastPlot = pp.getMeta("lastplot");
- if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot) && tmp_teleport) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
- if (lastPlot.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
- tmp_teleport = false;
- player.teleport(from);
- tmp_teleport = true;
- } else {
- Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
- if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
- tmp_teleport = false;
- player.teleport(player.getWorld().getSpawnLocation());
- tmp_teleport = true;
- }
- }
- event.setCancelled(true);
- return;
- }
- } else if (lastPlot != null && now.equals(lastPlot)) {
- return;
- } else {
- if (!plotEntry(pp, now) && tmp_teleport) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
- tmp_teleport = false;
- player.teleport(from);
- tmp_teleport = true;
- } else {
- Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
- if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
- tmp_teleport = false;
- player.teleport(player.getWorld().getSpawnLocation());
- tmp_teleport = true;
- }
- }
- event.setCancelled(true);
- return;
- }
- }
- final Integer border = area.getBorder();
- if (tmp_teleport) {
- if (x2 > border) {
- to.setX(border - 4);
- tmp_teleport = false;
- player.teleport(event.getTo());
- tmp_teleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- return;
- } else if (x2 < -border) {
- to.setX(-border + 4);
- tmp_teleport = false;
- player.teleport(event.getTo());
- tmp_teleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- return;
- }
- }
- return;
- }
- int z2;
- if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Set last location
- Location loc = BukkitUtil.getLocation(to);
- pp.setMeta("location", loc);
- final PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot now = area.getPlotAbs(loc);
- final Plot lastPlot = pp.getMeta("lastplot");
- if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot) && tmp_teleport) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
- if (lastPlot.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
- tmp_teleport = false;
- player.teleport(from);
- tmp_teleport = true;
- } else {
- Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
- if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
- tmp_teleport = false;
- player.teleport(player.getWorld().getSpawnLocation());
- tmp_teleport = true;
- }
- }
- event.setCancelled(true);
- return;
- }
- } else if (lastPlot != null && now.equals(lastPlot)) {
- return;
- } else {
- if (!plotEntry(pp, now) && tmp_teleport) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
- if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
- tmp_teleport = false;
- player.teleport(from);
- tmp_teleport = true;
- } else {
- Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
- if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
- tmp_teleport = false;
- player.teleport(player.getWorld().getSpawnLocation());
- tmp_teleport = true;
- }
- }
- event.setCancelled(true);
- return;
- }
- }
- final Integer border = area.getBorder();
- if (tmp_teleport) {
- if (z2 > border) {
- to.setZ(border - 4);
- tmp_teleport = false;
- player.teleport(event.getTo());
- tmp_teleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- } else if (z2 < -border) {
- to.setZ(-border + 4);
- tmp_teleport = false;
- player.teleport(event.getTo());
- tmp_teleport = true;
- MainUtil.sendMessage(pp, C.BORDER);
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBucketEmpty(final PlayerBucketEmptyEvent e) {
- final BlockFace bf = e.getBlockFace();
- final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock();
- final Location loc = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
- final Plot plot = area.getPlotAbs(loc);
- 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);
- e.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);
- e.setCancelled(true);
- } else if (!plot.isAdded(pp.getUUID())) {
- final Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s());
- if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) e.getBucket().getId(), (byte) 0))) {
- return;
- }
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- e.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onInventoryClick(final InventoryClickEvent event) {
- final HumanEntity clicker = event.getWhoClicked();
- if (!(clicker instanceof Player)) {
- return;
- }
- final Player player = (Player) clicker;
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- final PlotInventory inv = pp.getMeta("inventory");
- if (inv != null && event.getRawSlot() == event.getSlot()) {
- if (!inv.onClick(event.getSlot())) {
- event.setCancelled(true);
- inv.close();
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onInventoryClose(final InventoryCloseEvent event) {
- final HumanEntity closer = event.getPlayer();
- if (!(closer instanceof Player)) {
- return;
- }
- final Player player = (Player) closer;
- BukkitUtil.getPlayer(player).deleteMeta("inventory");
- }
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void onLeave(final PlayerQuitEvent event) {
- final PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
- pp.unregister();
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBucketFill(final PlayerBucketFillEvent e) {
- final Block b = e.getBlockClicked();
- final Location loc = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Player p = e.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- final Plot plot = area.getPlotAbs(loc);
- 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);
- e.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);
- e.setCancelled(true);
- } else if (!plot.isAdded(pp.getUUID())) {
- final Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s());
- final Block block = e.getBlockClicked();
- if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
- return;
- }
- if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- return;
- }
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- e.setCancelled(true);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onVehicleCreate(final VehicleCreateEvent event) {
- final Vehicle entity = event.getVehicle();
- final Location loc = BukkitUtil.getLocation(entity);
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = area.getOwnedPlotAbs(loc);
- if (plot == null) {
- entity.remove();
- return;
- }
- if (checkEntity(entity, plot)) {
- entity.remove();
- return;
- }
- if (Settings.KILL_ROAD_VEHICLES) {
- entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onHangingPlace(final HangingPlaceEvent e) {
- final Block b = e.getBlock().getRelative(e.getBlockFace());
- final Location loc = BukkitUtil.getLocation(b.getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Player p = e.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- final Plot plot = area.getPlotAbs(loc);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- e.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);
- e.setCancelled(true);
- }
- return;
- } else if (!plot.isAdded(pp.getUUID())) {
- if (!FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_PLACE.s())) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
- e.setCancelled(true);
- }
- return;
- }
- }
- if (checkEntity(e.getEntity(), plot)) {
- e.setCancelled(true);
- }
-
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onHangingBreakByEntity(final HangingBreakByEntityEvent e) {
- final Entity r = e.getRemover();
- if (r instanceof Player) {
- final Player p = (Player) r;
- final Location l = BukkitUtil.getLocation(e.getEntity());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- final Plot plot = area.getPlotAbs(l);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
- e.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);
- e.setCancelled(true);
- }
- } else if (!plot.isAdded(pp.getUUID())) {
- if (FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_BREAK.s())) {
- return;
- }
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
- e.setCancelled(true);
- }
- }
- }
- } else if (r instanceof Projectile) {
- final Projectile p = (Projectile) r;
- if (p.getShooter() instanceof Player) {
- final Player shooter = (Player) p.getShooter();
- Location loc = BukkitUtil.getLocation(e.getEntity());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final PlotPlayer player = BukkitUtil.getPlayer(shooter);
- final Plot plot = area.getPlotAbs(BukkitUtil.getLocation(e.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);
- e.setCancelled(true);
- }
- } else if (!plot.isAdded(player.getUUID())) {
- if (!FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_BREAK.s())) {
- if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
- MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
- e.setCancelled(true);
- }
- }
- }
- }
- }
- } else {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerInteractEntity(final PlayerInteractEntityEvent e) {
- final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- final Player p = e.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- final Plot plot = area.getPlotAbs(l);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_ROAD);
- e.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);
- e.setCancelled(true);
- }
- } else if (!plot.isAdded(pp.getUUID())) {
- final Entity entity = e.getRightClicked();
- if (entity instanceof Monster && FlagManager.isPlotFlagTrue(plot, C.FLAG_HOSTILE_INTERACT.s())) {
- return;
- }
- if (entity instanceof Animals && FlagManager.isPlotFlagTrue(plot, C.FLAG_ANIMAL_INTERACT.s())) {
- return;
- }
- if (entity instanceof Tameable && ((Tameable) entity).isTamed() && FlagManager.isPlotFlagTrue(plot, C.FLAG_TAMED_INTERACT.s())) {
- return;
- }
- if (entity instanceof Vehicle && FlagManager.isPlotFlagTrue(plot, C.FLAG_VEHICLE_USE.s())) {
- return;
- }
- if (entity instanceof Player && FlagManager.isPlotFlagTrue(plot, C.FLAG_PLAYER_INTERACT.s())) {
- return;
- }
- if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
- e.setCancelled(true);
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onVehicleDestroy(final VehicleDestroyEvent e) {
- final Location l = BukkitUtil.getLocation(e.getVehicle());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- final Entity d = e.getAttacker();
- if (d instanceof Player) {
- final Player p = (Player) d;
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- final Plot plot = area.getPlotAbs(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");
- e.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");
- e.setCancelled(true);
- return;
- }
- return;
- }
- if (!plot.isAdded(pp.getUUID())) {
- if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) {
- return;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.other");
- e.setCancelled(true);
- }
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPotionSplash(final PotionSplashEvent event) {
- final ThrownPotion damager = event.getPotion();
- final Location l = BukkitUtil.getLocation(damager);
- if (!PS.get().hasPlotArea(l.getWorld())) {
- return;
- }
- for (final LivingEntity victim : event.getAffectedEntities()) {
- if (!entityDamage(l, damager, victim)) {
- event.setIntensity(victim, 0);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) {
- final Entity damager = e.getDamager();
- final Location l = BukkitUtil.getLocation(damager);
- if (!PS.get().hasPlotArea(l.getWorld())) {
- return;
- }
- final Entity victim = e.getEntity();
- if (!entityDamage(l, damager, victim)) {
- e.setCancelled(true);
- }
- }
-
- public boolean entityDamage(final Location l, final Entity damager, final Entity victim) {
- final Location dloc = BukkitUtil.getLocation(damager);
- final 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;
- }
-
- final Plot dplot = dArea != null ? dArea.getPlot(dloc) : null;
- final 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 {
- // Priorize plots for close to seamless pvp zones
- plot = vplot == null ? dplot : dplot == null || !(victim instanceof Player) ? vplot :
- victim.getTicksLived() > damager.getTicksLived() ? dplot : vplot;
- stub = plot.hasOwner() ? "other" : "unowned";
- }
-
- Player player;
- if (damager instanceof Player) { // attacker is player
- player = (Player) damager;
- } else if (damager instanceof Projectile) {
- final Projectile projectile = (Projectile) damager;
- final ProjectileSource shooter = projectile.getShooter();
- if (shooter instanceof Player) { // shooter is player
- player = (Player) shooter;
- } else { // shooter is not player
- player = null;
- }
- } else { // Attacker is not player
- player = null;
- }
- if (player != null) {
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- if (victim instanceof Hanging) { // hanging
- if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hanging-break") || plot.isAdded(pp.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.destroy." + stub);
- return false;
- }
- } else if (victim.getEntityId() == 30) {
- if (plot != null && (FlagManager.isPlotFlagTrue(plot, "misc-break") || plot.isAdded(pp.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.destroy." + stub);
- return false;
- }
- } else if (victim instanceof Monster || victim instanceof EnderDragon) { // victim is monster
- if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hostile-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot
- .isAdded(pp.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
- }
- } else if (victim instanceof Tameable) { // victim is tameable
- if (plot != null && (FlagManager.isPlotFlagTrue(plot, "tamed-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot
- .isAdded(pp.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
- }
- } else if (victim instanceof Player) {
- if (plot != null) {
- final Flag pvp = FlagManager.getPlotFlagRaw(plot, C.FLAG_PVP.s());
- if (pvp == null) {
- return true;
- } else {
- if ((Boolean) pvp.getValue()) {
- return true;
- } else if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
- }
- }
- }
- if (!Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub);
- return false;
- }
- } else if (victim instanceof Creature) { // victim is animal
- if (plot != null && (FlagManager.isPlotFlagTrue(plot, "animal-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot
- .isAdded(pp.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(pp, 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 && (FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) {
- return true;
- }
- if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
- return false;
- }
- }
- return true;
- }
- // player is null
- return !(damager instanceof Arrow && !(victim instanceof Creature));
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerEggThrow(final PlayerEggThrowEvent e) {
- final Location l = BukkitUtil.getLocation(e.getEgg().getLocation());
- PlotArea area = l.getPlotArea();
- if (area == null) {
- return;
- }
- final Player p = e.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(p);
- final Plot plot = area.getPlot(l);
- if (plot == null) {
- if (!Permissions.hasPermission(pp, "plots.admin.projectile.road")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.road");
- e.setHatching(false);
- }
- } else {
- if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, "plots.admin.projectile.unowned")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.unowned");
- e.setHatching(false);
- }
- } else if (!plot.isAdded(pp.getUUID())) {
- if (!Permissions.hasPermission(pp, "plots.admin.projectile.other")) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.other");
- e.setHatching(false);
- }
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void BlockCreate(final BlockPlaceEvent event) {
- final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = loc.getPlotArea();
- if (area == null) {
- return;
- }
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- final Plot plot = area.getPlotAbs(loc);
- if (plot != null) {
- 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())) {
- final Flag place = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
- final Block block = event.getBlock();
- if ((place == null || !((HashSet) place.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData())))
- && !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_RESTRICTS_BUILDING && plot.getFlags().containsKey("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 (FlagManager.isPlotFlagTrue(plot, C.FLAG_DISABLE_PHYSICS.s())) {
- final Block block = event.getBlockPlaced();
- if (block.getType().hasGravity()) {
- sendBlockChange(block.getLocation(), block.getType(), block.getData());
- }
- }
- if (loc.getY() > area.MAX_BUILD_HEIGHT && loc.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}", "" + area.MAX_BUILD_HEIGHT));
- }
- } else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
- }
- }
-}
+package com.plotsquared.bukkit.listeners;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
+import org.bukkit.command.PluginCommand;
+import org.bukkit.entity.Animals;
+import org.bukkit.entity.Arrow;
+import org.bukkit.entity.Creature;
+import org.bukkit.entity.EnderDragon;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Hanging;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Monster;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Projectile;
+import org.bukkit.entity.TNTPrimed;
+import org.bukkit.entity.Tameable;
+import org.bukkit.entity.ThrownPotion;
+import org.bukkit.entity.Vehicle;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.BlockDamageEvent;
+import org.bukkit.event.block.BlockDispenseEvent;
+import org.bukkit.event.block.BlockFadeEvent;
+import org.bukkit.event.block.BlockFormEvent;
+import org.bukkit.event.block.BlockFromToEvent;
+import org.bukkit.event.block.BlockGrowEvent;
+import org.bukkit.event.block.BlockIgniteEvent;
+import org.bukkit.event.block.BlockPhysicsEvent;
+import org.bukkit.event.block.BlockPistonExtendEvent;
+import org.bukkit.event.block.BlockPistonRetractEvent;
+import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.event.block.BlockRedstoneEvent;
+import org.bukkit.event.block.BlockSpreadEvent;
+import org.bukkit.event.block.EntityBlockFormEvent;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityChangeBlockEvent;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.event.entity.ExplosionPrimeEvent;
+import org.bukkit.event.entity.PotionSplashEvent;
+import org.bukkit.event.entity.ProjectileHitEvent;
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
+import org.bukkit.event.player.PlayerEggThrowEvent;
+import org.bukkit.event.player.PlayerInteractEntityEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.vehicle.VehicleCreateEvent;
+import org.bukkit.event.vehicle.VehicleDestroyEvent;
+import org.bukkit.event.world.StructureGrowEvent;
+import org.bukkit.help.HelpTopic;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.metadata.FixedMetadataValue;
+import org.bukkit.metadata.MetadataValue;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.projectiles.BlockProjectileSource;
+import org.bukkit.projectiles.ProjectileSource;
+import org.bukkit.util.Vector;
+
+import com.intellectualcrafters.plot.PS;
+import com.intellectualcrafters.plot.config.C;
+import com.intellectualcrafters.plot.config.Settings;
+import com.intellectualcrafters.plot.flag.Flag;
+import com.intellectualcrafters.plot.flag.FlagManager;
+import com.intellectualcrafters.plot.object.Location;
+import com.intellectualcrafters.plot.object.Plot;
+import com.intellectualcrafters.plot.object.PlotArea;
+import com.intellectualcrafters.plot.object.PlotBlock;
+import com.intellectualcrafters.plot.object.PlotHandler;
+import com.intellectualcrafters.plot.object.PlotId;
+import com.intellectualcrafters.plot.object.PlotInventory;
+import com.intellectualcrafters.plot.object.PlotPlayer;
+import com.intellectualcrafters.plot.object.StringWrapper;
+import com.intellectualcrafters.plot.util.EventUtil;
+import com.intellectualcrafters.plot.util.ExpireManager;
+import com.intellectualcrafters.plot.util.MainUtil;
+import com.intellectualcrafters.plot.util.MathMan;
+import com.intellectualcrafters.plot.util.Permissions;
+import com.intellectualcrafters.plot.util.RegExUtil;
+import com.intellectualcrafters.plot.util.StringMan;
+import com.intellectualcrafters.plot.util.TaskManager;
+import com.intellectualcrafters.plot.util.UUIDHandler;
+import com.plotsquared.bukkit.BukkitMain;
+import com.plotsquared.bukkit.object.BukkitLazyBlock;
+import com.plotsquared.bukkit.object.BukkitPlayer;
+import com.plotsquared.bukkit.util.BukkitUtil;
+import com.plotsquared.listener.PlayerBlockEventType;
+
+/**
+ * Player Events involving plots
+ *
+ */
+@SuppressWarnings({ "deprecation", "unchecked" })
+public class PlayerEvents extends com.plotsquared.listener.PlotListener implements Listener {
+
+ private boolean pistonBlocks = true;
+ private float lastRadius;
+ // To prevent recursion
+ private boolean tmp_teleport = true;
+
+ public static void sendBlockChange(final org.bukkit.Location bloc, final Material type, final byte data) {
+ TaskManager.runTaskLater(new Runnable() {
+ @Override
+ public void run() {
+ final String world = bloc.getWorld().getName();
+ final int x = bloc.getBlockX();
+ final int z = bloc.getBlockZ();
+ final int distance = Bukkit.getViewDistance() * 16;
+ for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
+ PlotPlayer player = entry.getValue();
+ final 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, type, data);
+ }
+ }
+ }
+ }, 3);
+ }
+
+ @EventHandler
+ public void onRedstoneEvent(final BlockRedstoneEvent event) {
+ final Block block = event.getBlock();
+ switch (block.getType()) {
+ case REDSTONE_LAMP_OFF:
+ case REDSTONE_WIRE:
+ case REDSTONE_LAMP_ON:
+ case PISTON_BASE:
+ case PISTON_STICKY_BASE:
+ case IRON_DOOR_BLOCK:
+ case LEVER:
+ case WOODEN_DOOR:
+ case FENCE_GATE:
+ case WOOD_BUTTON:
+ case STONE_BUTTON:
+ case IRON_PLATE:
+ case WOOD_PLATE:
+ case STONE_PLATE:
+ case GOLD_PLATE:
+ case SPRUCE_DOOR:
+ case BIRCH_DOOR:
+ case JUNGLE_DOOR:
+ case ACACIA_DOOR:
+ case DARK_OAK_DOOR:
+ case IRON_TRAPDOOR:
+ case SPRUCE_FENCE_GATE:
+ case BIRCH_FENCE_GATE:
+ case JUNGLE_FENCE_GATE:
+ case ACACIA_FENCE_GATE:
+ case DARK_OAK_FENCE_GATE:
+ case POWERED_RAIL:
+ return;
+ default:
+ final Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ return;
+ }
+ final Flag redstone = FlagManager.getPlotFlagRaw(plot, "redstone");
+ if (redstone != null) {
+ if ((Boolean) redstone.getValue()) {
+ return;
+ } else {
+ event.setNewCurrent(0);
+ return;
+ }
+ }
+ if (Settings.REDSTONE_DISABLER) {
+ if (UUIDHandler.getPlayer(plot.owner) == null) {
+ boolean disable = true;
+ for (final UUID trusted : plot.getTrusted()) {
+ if (UUIDHandler.getPlayer(trusted) != null) {
+ disable = false;
+ break;
+ }
+ }
+ if (disable) {
+ event.setNewCurrent(0);
+ return;
+ }
+ }
+ }
+ if (Settings.REDSTONE_DISABLER_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(final BlockPhysicsEvent event) {
+ switch (event.getChangedType()) {
+ case REDSTONE_COMPARATOR_OFF:
+ case REDSTONE_COMPARATOR_ON: {
+ final Block block = event.getBlock();
+ final Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ return;
+ }
+ if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
+ event.setCancelled(true);
+ }
+ return;
+ }
+ case DRAGON_EGG:
+ case ANVIL:
+ case SAND:
+ case GRAVEL:
+ final Block block = event.getBlock();
+ final Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot != null && FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
+ event.setCancelled(true);
+ return;
+ }
+ return;
+ default:
+ break;
+ }
+ }
+
+ @EventHandler
+ public void onProjectileHit(final ProjectileHitEvent event) {
+ final Projectile entity = event.getEntity();
+ final Location loc = BukkitUtil.getLocation(entity);
+ if (!PS.get().hasPlotArea(loc.getWorld())) {
+ return;
+ }
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getPlotAbs(loc);
+ //
+ final ProjectileSource shooter = entity.getShooter();
+ if (shooter instanceof Player) {
+ final PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) {
+ entity.remove();
+ }
+ return;
+ }
+ if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) {
+ return;
+ }
+ entity.remove();
+ } else if (!(shooter instanceof Entity) && shooter != null) {
+ if (plot == null) {
+ entity.remove();
+ return;
+ }
+ final Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
+ if (!area.contains(sLoc.getX(), sLoc.getZ())) {
+ entity.remove();
+ return;
+ }
+ final Plot sPlot = area.getOwnedPlotAbs(sLoc);
+ if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
+ entity.remove();
+ }
+ }
+ }
+
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+ public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
+ String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim();
+ if (msg.isEmpty()) {
+ return;
+ }
+ final String[] split = msg.split(" ");
+ final PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
+ if (cmd == null) {
+ if (split[0].equals("plotme") || split[0].equals("ap")) {
+ final Player player = event.getPlayer();
+ if (Settings.USE_PLOTME_ALIAS) {
+ player.performCommand("plots " + StringMan.join(Arrays.copyOfRange(split, 1, split.length), " "));
+ } else {
+ MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
+ }
+ event.setCancelled(true);
+ return;
+ }
+ }
+ final Player player = event.getPlayer();
+ final BukkitPlayer pp = (BukkitPlayer) BukkitUtil.getPlayer(player);
+ Plot plot = pp.getCurrentPlot();
+ if (plot == null) {
+ return;
+ }
+ Flag flag = FlagManager.getPlotFlagRaw(plot, "blocked-cmds");
+ if (flag == null || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
+ return;
+ }
+ final List v = (List) flag.getValue();
+ final String[] parts = msg.split(" ");
+ String c = parts[0];
+ if (parts[0].contains(":")) {
+ c = parts[0].split(":")[1];
+ msg = msg.replace(parts[0].split(":")[0] + ":", "");
+ }
+ final String l = c;
+ final List aliases = new ArrayList<>();
+ for (final HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) {
+ if (c.equals(cmdLabel.getName())) {
+ break;
+ }
+ PluginCommand p;
+ final String label = cmdLabel.getName().replaceFirst("/", "");
+ if (aliases.contains(label)) {
+ continue;
+ }
+ 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 (final String s : v) {
+ 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()) {
+ MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
+ 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)) {
+ event.setCancelled(true);
+ }
+ return;
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onConnect(final PlayerJoinEvent event) {
+ final Player player = event.getPlayer();
+ BukkitUtil.getPlayer(event.getPlayer()).unregister();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ // Now
+ String name = pp.getName();
+ StringWrapper sw = new StringWrapper(name);
+ final UUID uuid = pp.getUUID();
+ UUIDHandler.add(sw, uuid);
+
+ Location loc = pp.getLocation();
+ PlotArea area = loc.getPlotArea();
+ final Plot plot;
+ if (area != null) {
+ plot = area.getPlot(loc);
+ if (plot != null) {
+ plotEntry(pp, plot);
+ }
+ } else {
+ plot = null;
+ }
+ // Delayed
+
+ // Async
+ TaskManager.runTaskLaterAsync(new Runnable() {
+ @Override
+ public void run() {
+ if (!player.hasPlayedBefore() && player.isOnline()) {
+ player.saveData();
+ }
+ ExpireManager.dates.put(uuid, System.currentTimeMillis());
+ if (BukkitMain.worldEdit != null) {
+ if (pp.getAttribute("worldedit")) {
+ MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASSED);
+ }
+ }
+ if (PS.get().update != null && Permissions.hasPermission(pp, C.PERMISSION_ADMIN_UPDATE) && Settings.UPDATE_NOTIFICATIONS) {
+ MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update");
+ }
+ if (Settings.TELEPORT_ON_LOGIN && plot != null) {
+ TaskManager.runTask(new Runnable() {
+ @Override
+ public void run() {
+ plot.teleportPlayer(pp);
+ }
+ });
+ MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
+ }
+ }
+ }, 20);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void PlayerMove(final PlayerMoveEvent event) {
+ final org.bukkit.Location from = event.getFrom();
+ final org.bukkit.Location to = event.getTo();
+ int x2;
+ if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+
+ // Cancel teleport
+ TaskManager.TELEPORT_QUEUE.remove(pp.getName());
+
+ // Set last location
+ Location loc = BukkitUtil.getLocation(to);
+ pp.setMeta("location", loc);
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ pp.deleteMeta("lastplot");
+ return;
+ }
+ Plot now = area.getPlotAbs(loc);
+ final Plot lastPlot = pp.getMeta("lastplot");
+ if (now == null) {
+ if (lastPlot != null && !plotExit(pp, lastPlot)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
+ if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
+ player.teleport(from);
+ } else {
+ player.teleport(player.getWorld().getSpawnLocation());
+ }
+ event.setCancelled(true);
+ return;
+ }
+ } else if (now.equals(lastPlot)) {
+ return;
+ } else if (!plotEntry(pp, now)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
+ player.teleport(from);
+ event.setCancelled(true);
+ return;
+ }
+ final Integer border = area.getBorder();
+ if (x2 > border) {
+ to.setX(border - 4);
+ player.teleport(event.getTo());
+ MainUtil.sendMessage(pp, C.BORDER);
+ return;
+ } else if (x2 < -border) {
+ to.setX(-border + 4);
+ player.teleport(event.getTo());
+ MainUtil.sendMessage(pp, C.BORDER);
+ return;
+ }
+ return;
+ }
+ int z2;
+ if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+
+ // Cancel teleport
+ TaskManager.TELEPORT_QUEUE.remove(pp.getName());
+
+ // Set last location
+ Location loc = BukkitUtil.getLocation(to);
+ pp.setMeta("location", loc);
+
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ pp.deleteMeta("lastplot");
+ return;
+ }
+ Plot now = area.getPlotAbs(loc);
+ final Plot lastPlot = pp.getMeta("lastplot");
+ if (now == null) {
+ if (lastPlot != null && !plotExit(pp, lastPlot)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
+ if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
+ player.teleport(from);
+ } else {
+ player.teleport(player.getWorld().getSpawnLocation());
+ }
+ event.setCancelled(true);
+ return;
+ }
+ } else if (now.equals(lastPlot)) {
+ return;
+ } else if (!plotEntry(pp, now)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
+ player.teleport(from);
+ event.setCancelled(true);
+ return;
+ }
+ final Integer border = area.getBorder();
+ if (z2 > border) {
+ to.setZ(border - 4);
+ player.teleport(event.getTo());
+ MainUtil.sendMessage(pp, C.BORDER);
+ } else if (z2 < -border) {
+ to.setZ(-border + 4);
+ player.teleport(event.getTo());
+ MainUtil.sendMessage(pp, C.BORDER);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
+ public void onChat(final AsyncPlayerChatEvent event) {
+ final Player player = event.getPlayer();
+ final PlotPlayer plr = BukkitUtil.getPlayer(player);
+ Location loc = plr.getLocation();
+ PlotArea area = loc.getPlotArea();
+ if (area == null || !area.PLOT_CHAT && !plr.getAttribute("chat")) {
+ return;
+ }
+ final Plot plot = area.getPlotAbs(loc);
+ if (plot == null) {
+ return;
+ }
+ final String message = event.getMessage();
+ String format = C.PLOT_CHAT_FORMAT.s();
+ final String sender = event.getPlayer().getDisplayName();
+ final PlotId id = plot.getId();
+ final Set recipients = event.getRecipients();
+ recipients.clear();
+ for (final Player p : Bukkit.getOnlinePlayers()) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ if (pp.getAttribute("chatspy")) {
+ String spy = event.getFormat();
+ spy = String.format(spy, sender, message);
+ pp.sendMessage(spy);
+ } else if (plot.equals(pp.getCurrentPlot())) {
+ recipients.add(p);
+ }
+ }
+ format = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", "%s").replaceAll("%msg%", "%s");
+ format = ChatColor.translateAlternateColorCodes('&', format);
+ event.setFormat(format);
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void BlockDestroy(final BlockBreakEvent event) {
+ final Player player = event.getPlayer();
+ final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Plot plot = area.getPlotAbs(loc);
+ if (plot != null) {
+ if (event.getBlock().getY() == 0) {
+ event.setCancelled(true);
+ return;
+ }
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (!plot.hasOwner()) {
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
+ event.setCancelled(true);
+ return;
+ } else if (!plot.isAdded(pp.getUUID())) {
+ final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
+ final Block block = event.getBlock();
+ if (destroy != null && ((HashSet) destroy.getValue())
+ .contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
+ return;
+ }
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
+ event.setCancelled(true);
+ } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("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;
+ }
+ }
+ return;
+ }
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
+ 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(final EntityExplodeEvent event) {
+ Location loc = BukkitUtil.getLocation(event.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ if (!PS.get().hasPlotArea(loc.getWorld())) {
+ return;
+ }
+ final Iterator iter = event.blockList().iterator();
+ while (iter.hasNext()) {
+ iter.next();
+ if (loc.getPlotArea() != null) {
+ iter.remove();
+ }
+ }
+ } else {
+ Plot plot = area.getOwnedPlot(loc);
+ if (plot != null) {
+ if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
+ List meta = event.getEntity().getMetadata("plot");
+ Plot origin;
+ if (meta.isEmpty()) {
+ origin = plot;
+ } else {
+ origin = (Plot) meta.get(0).value();
+ }
+ if (lastRadius != 0) {
+ final List nearby = event.getEntity().getNearbyEntities(lastRadius, lastRadius, lastRadius);
+ for (final Entity near : nearby) {
+ if (near instanceof TNTPrimed || near.getType() == EntityType.MINECART_TNT) {
+ if (!near.hasMetadata("plot")) {
+ near.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
+ }
+ }
+ }
+ lastRadius = 0;
+ }
+ final Iterator iter = event.blockList().iterator();
+ while (iter.hasNext()) {
+ final Block b = iter.next();
+ loc = BukkitUtil.getLocation(b.getLocation());
+ if (!area.contains(loc.getX(), loc.getZ()) || !origin.equals(area.getOwnedPlot(loc))) {
+ iter.remove();
+ }
+ }
+ }
+ } else {
+ event.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onWorldChanged(final PlayerChangedWorldEvent event) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+
+
+ // Delete last location
+ pp.deleteMeta("location");
+ Plot plot = (Plot) pp.deleteMeta("lastplot");
+ if (plot != null) {
+ plotExit(pp, plot);
+ }
+
+ if (BukkitMain.worldEdit != null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
+ if (pp.getAttribute("worldedit")) {
+ pp.removeAttribute("worldedit");
+ }
+ }
+ }
+ if (Settings.PERMISSION_CACHING) {
+ pp.deleteMeta("perm");
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) {
+ final String world = event.getBlock().getWorld().getName();
+ if (!PS.get().hasPlotArea(world)) {
+ return;
+ }
+ final Entity e = event.getEntity();
+ if (!(e instanceof org.bukkit.entity.FallingBlock)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onEntityBlockForm(final EntityBlockFormEvent e) {
+ final String world = e.getBlock().getWorld().getName();
+ if (!PS.get().hasPlotArea(world)) {
+ return;
+ }
+ if (BukkitUtil.getLocation(e.getBlock().getLocation()).getPlotArea() != null) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBS(final BlockSpreadEvent e) {
+ final Block b = e.getBlock();
+ final Location loc = BukkitUtil.getLocation(b.getLocation());
+ if (loc.isPlotRoad()) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBF(final BlockFormEvent e) {
+ final Block b = e.getBlock();
+ final Location loc = BukkitUtil.getLocation(b.getLocation());
+ if (loc.isPlotRoad()) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBD(final BlockDamageEvent event) {
+ final Player player = event.getPlayer();
+ Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
+ if (player == null) {
+ if (loc.isPlotRoad()) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Plot plot = area.getPlotAbs(loc);
+ if (plot != null) {
+ if (loc.getY() == 0) {
+ event.setCancelled(true);
+ return;
+ }
+ if (!plot.hasOwner()) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
+ return;
+ }
+ event.setCancelled(true);
+ return;
+ }
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (!plot.isAdded(pp.getUUID())) {
+ final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
+ final Block block = event.getBlock();
+ if (destroy != null && ((HashSet) destroy.getValue())
+ .contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
+ return;
+ }
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ return;
+ }
+ event.setCancelled(true);
+ return;
+ }
+ return;
+ }
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
+ return;
+ }
+ event.setCancelled(true);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onFade(final BlockFadeEvent e) {
+ final Block b = e.getBlock();
+ Location loc = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ if (area.getOwnedPlot(loc) == null) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onChange(final BlockFromToEvent e) {
+ final Block b = e.getBlock();
+ Location loc = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlot(loc);
+ if (plot == null || FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onGrow(final BlockGrowEvent e) {
+ final Block b = e.getBlock();
+ final Location loc = BukkitUtil.getLocation(b.getLocation());
+ if (loc.isUnownedPlotArea()) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
+ final Block block = event.getBlock();
+ final Location loc = BukkitUtil.getLocation(block.getLocation());
+ final BlockFace face = event.getDirection();
+ final Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ if (!PS.get().hasPlotArea(loc.getWorld())) {
+ return;
+ }
+ for (final Block b : event.getBlocks()) {
+ if (BukkitUtil.getLocation(b.getLocation().add(relative)).getPlotArea() != null) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+ final Plot plot = area.getOwnedPlot(loc);
+ if (plot == null) {
+ event.setCancelled(true);
+ return;
+ }
+ final List blocks = event.getBlocks();
+ for (final Block b : blocks) {
+ final Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative));
+ if (!area.contains(bloc.getX(), bloc.getZ())) {
+ event.setCancelled(true);
+ return;
+ }
+ if (!plot.equals(area.getOwnedPlot(bloc))) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
+ final Block block = event.getBlock();
+ Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ if (!PS.get().hasPlotArea(loc.getWorld())) {
+ return;
+ }
+ if (pistonBlocks) {
+ try {
+ for (final Block pulled : event.getBlocks()) {
+ loc = BukkitUtil.getLocation(pulled.getLocation());
+ if (loc.getPlotArea() != null) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ } catch (final Throwable e) {
+ pistonBlocks = false;
+ }
+ }
+ if (!pistonBlocks && block.getType() != Material.PISTON_BASE) {
+ final BlockFace dir = event.getDirection();
+ loc = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
+ if (loc.getPlotArea() != null) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ return;
+ }
+ Plot plot = area.getOwnedPlot(loc);
+ if (pistonBlocks) {
+ try {
+ for (final Block pulled : event.getBlocks()) {
+ loc = BukkitUtil.getLocation(pulled.getLocation());
+ if (!area.contains(loc.getX(), loc.getZ())) {
+ event.setCancelled(true);
+ return;
+ }
+ Plot newPlot = area.getOwnedPlot(loc);
+ if (!Objects.equals(plot, newPlot)) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ } catch (final Throwable e) {
+ pistonBlocks = false;
+ }
+ }
+ if (!pistonBlocks && block.getType() != Material.PISTON_BASE) {
+ final BlockFace dir = event.getDirection();
+ loc = BukkitUtil.getLocation(block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
+ if (!area.contains(loc)) {
+ event.setCancelled(true);
+ return;
+ }
+ Plot newPlot = area.getOwnedPlot(loc);
+ if (!Objects.equals(plot, newPlot)) {
+ event.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockDispense(final BlockDispenseEvent e) {
+ Material type = e.getItem().getType();
+ if (type != Material.WATER_BUCKET && type != Material.LAVA_BUCKET) {
+ return;
+ }
+ final Location loc = BukkitUtil.getLocation(e.getVelocity().toLocation(e.getBlock().getWorld()));
+ if (loc.isPlotRoad()) {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onStructureGrow(final StructureGrowEvent e) {
+ if (!PS.get().hasPlotArea(e.getWorld().getName())) {
+ return;
+ }
+ final List blocks = e.getBlocks();
+ if (blocks.isEmpty()) {
+ return;
+ }
+ Location loc = BukkitUtil.getLocation(blocks.get(0).getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ for (int i = blocks.size() - 1; i >= 0; i--) {
+ loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
+ if (loc.getPlotArea() != null) {
+ blocks.remove(i);
+ }
+ }
+ } else {
+ Plot origin = area.getOwnedPlot(loc);
+ if (origin == null) {
+ e.setCancelled(true);
+ return;
+ }
+ for (int i = blocks.size() - 1; i >= 0; i--) {
+ loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
+ if (!area.contains(loc.getX(), loc.getZ())) {
+ blocks.remove(i);
+ continue;
+ }
+ final Plot plot = area.getOwnedPlot(loc);
+ if (!Objects.equals(plot, origin)) {
+ e.getBlocks().remove(i);
+ }
+ }
+ }
+ final Plot origin = area.getPlotAbs(loc);
+ if (origin == null) {
+ e.setCancelled(true);
+ return;
+ }
+ for (int i = blocks.size() - 1; i >= 0; i--) {
+ loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
+ final Plot plot = area.getOwnedPlot(loc);
+ if (!Objects.equals(plot, origin)) {
+ e.getBlocks().remove(i);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
+ public void onInteract(final PlayerInteractEvent event) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ PlotArea area = pp.getPlotAreaAbs();
+ if (area == null) {
+ return;
+ }
+ PlayerBlockEventType eventType = null;
+ BukkitLazyBlock lb;
+ Location loc;
+ final Action action = event.getAction();
+ switch (action) {
+ case PHYSICAL: {
+ eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
+ Block block = event.getClickedBlock();
+ lb = new BukkitLazyBlock(block);
+ loc = BukkitUtil.getLocation(block.getLocation());
+ break;
+ }
+ case RIGHT_CLICK_BLOCK: {
+ Block block = event.getClickedBlock();
+ loc = BukkitUtil.getLocation(block.getLocation());
+ final Material blockType = block.getType();
+ final int blockId = blockType.getId();
+ switch (blockType) {
+ case ANVIL:
+ case ACACIA_DOOR:
+ case BIRCH_DOOR:
+ case DARK_OAK_DOOR:
+ case IRON_DOOR:
+ case JUNGLE_DOOR:
+ case SPRUCE_DOOR:
+ case TRAP_DOOR:
+ case IRON_TRAPDOOR:
+ case WOOD_DOOR:
+ case WOODEN_DOOR:
+ case TRAPPED_CHEST:
+ case ENDER_CHEST:
+ case CHEST:
+ case ACACIA_FENCE_GATE:
+ case BIRCH_FENCE_GATE:
+ case DARK_OAK_FENCE_GATE:
+ case FENCE_GATE:
+ case JUNGLE_FENCE_GATE:
+ case SPRUCE_FENCE_GATE:
+ case LEVER:
+ case DIODE:
+ case DIODE_BLOCK_OFF:
+ case DIODE_BLOCK_ON:
+ case COMMAND:
+ case REDSTONE_COMPARATOR:
+ case REDSTONE_COMPARATOR_OFF:
+ case REDSTONE_COMPARATOR_ON:
+ case REDSTONE_ORE:
+ case WOOD_BUTTON:
+ case STONE_BUTTON:
+ case BEACON:
+ case BED_BLOCK:
+ case SIGN:
+ case WALL_SIGN:
+ case SIGN_POST:
+ case ENCHANTMENT_TABLE:
+ case BREWING_STAND:
+ case STANDING_BANNER:
+ case BURNING_FURNACE:
+ case FURNACE:
+ case CAKE_BLOCK:
+ case DISPENSER:
+ case DROPPER:
+ case HOPPER:
+ case NOTE_BLOCK:
+ case JUKEBOX:
+ case WORKBENCH:
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ break;
+ case DRAGON_EGG:
+ eventType = PlayerBlockEventType.TELEPORT_OBJECT;
+ break;
+ default:
+ if (blockId > 197) {
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ }
+ break;
+ }
+ lb = new BukkitLazyBlock(blockId, block);
+ final ItemStack hand = player.getItemInHand();
+ if (eventType != null && !player.isSneaking()) {
+ break;
+ }
+ Material type = hand == null ? null : hand.getType();
+ int id = type == null ? 0 : type.getId();
+ if (id == 0) {
+ eventType = PlayerBlockEventType.INTERACT_BLOCK;
+ lb = new BukkitLazyBlock(id, block);
+ break;
+ } else if (id < 198) {
+ loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation());
+ eventType = PlayerBlockEventType.PLACE_BLOCK;
+ lb = new BukkitLazyBlock(id, block);
+ break;
+ }
+ Material handType = hand.getType();
+ lb = new BukkitLazyBlock(new PlotBlock((short) handType.getId(), (byte) 0));
+ switch (handType) {
+ case MONSTER_EGG:
+ case MONSTER_EGGS:
+ eventType = PlayerBlockEventType.SPAWN_MOB;
+ break;
+
+ case ARMOR_STAND:
+ loc = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation());
+ eventType = PlayerBlockEventType.PLACE_MISC;
+ break;
+
+ case WRITTEN_BOOK:
+ case BOOK_AND_QUILL:
+ case BOOK:
+ eventType = PlayerBlockEventType.READ;
+ break;
+
+ case APPLE:
+ case BAKED_POTATO:
+ case MUSHROOM_SOUP:
+ case BREAD:
+ case CARROT:
+ case CARROT_ITEM:
+ case COOKIE:
+ case GRILLED_PORK:
+ case POISONOUS_POTATO:
+ case MUTTON:
+ case PORK:
+ case POTATO:
+ case POTATO_ITEM:
+ case POTION:
+ case PUMPKIN_PIE:
+ case RABBIT:
+ case RABBIT_FOOT:
+ case RABBIT_STEW:
+ case RAW_BEEF:
+ case RAW_FISH:
+ case RAW_CHICKEN:
+ eventType = PlayerBlockEventType.EAT;
+ break;
+ case MINECART:
+ case STORAGE_MINECART:
+ case POWERED_MINECART:
+ case HOPPER_MINECART:
+ case EXPLOSIVE_MINECART:
+ case COMMAND_MINECART:
+ case BOAT:
+ eventType = PlayerBlockEventType.PLACE_VEHICLE;
+ break;
+ case PAINTING:
+ case ITEM_FRAME:
+ loc = 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();
+ loc = BukkitUtil.getLocation(block.getLocation());
+ eventType = PlayerBlockEventType.BREAK_BLOCK;
+ lb = new BukkitLazyBlock(block);
+ break;
+ default:
+ return;
+ }
+ if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, loc, lb, true)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void MobSpawn(final CreatureSpawnEvent event) {
+ final Entity entity = event.getEntity();
+ if (entity instanceof Player) {
+ return;
+ }
+ final Location loc = BukkitUtil.getLocation(entity.getLocation());
+ final PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
+ switch (reason) {
+ case SPAWNER_EGG:
+ case DISPENSE_EGG:
+ if (!area.SPAWN_EGGS) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ case BREEDING:
+ if (!area.SPAWN_BREEDING) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ case CUSTOM:
+ if (!area.SPAWN_CUSTOM && entity.getType().getTypeId() != 30) {
+ event.setCancelled(true);
+ return;
+ }
+ break;
+ }
+ final Plot plot = area.getOwnedPlotAbs(loc);
+ 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(final EntityChangeBlockEvent event) {
+ if (event.getEntityType() != EntityType.FALLING_BLOCK) {
+ return;
+ }
+ final Block block = event.getBlock();
+ final World world = block.getWorld();
+ final String worldname = world.getName();
+ if (!PS.get().hasPlotArea(worldname)) {
+ return;
+ }
+ final Location loc = BukkitUtil.getLocation(block.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ event.setCancelled(true);
+ return;
+ }
+ if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
+ 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) PS.get().IMP, plot));
+ }
+ }
+
+ @EventHandler
+ public void onPrime(final ExplosionPrimeEvent event) {
+ lastRadius = event.getRadius() + 1;
+ }
+
+ public boolean checkEntity(Plot plot, String... flags) {
+ int[] mobs = null;
+ for (String flag : flags) {
+ int i;
+ switch (flag) {
+ case "entity-cap":
+ i = 0;
+ break;
+ case "mob-cap":
+ i = 3;
+ break;
+ case "hostile-cap":
+ i = 2;
+ break;
+ case "animal-cap":
+ i = 1;
+ break;
+ case "vehicle-cap":
+ i = 4;
+ break;
+ case "misc-cap":
+ i = 5;
+ break;
+ default:
+ i = 0;
+ }
+ final Flag plotFlag = FlagManager.getPlotFlagRaw(plot, flag);
+ if (plotFlag == null) {
+ continue;
+ }
+ if (mobs == null) {
+ mobs = plot.countEntities();
+ }
+ if (mobs[i] >= (Integer) plotFlag.getValue()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean checkEntity(final Entity entity, final Plot plot) {
+ if (plot == null || plot.owner == null || plot.settings == null || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS
+ .isEmpty
+ ()) {
+ return false;
+ }
+ switch (entity.getType()) {
+ case PLAYER:
+ return false;
+ case SMALL_FIREBALL:
+ case FIREBALL:
+ case DROPPED_ITEM:
+ case EGG:
+ case THROWN_EXP_BOTTLE:
+ case SPLASH_POTION:
+ case SNOWBALL:
+ case ENDER_PEARL:
+ case ARROW:
+ // projectile
+ case PRIMED_TNT:
+ case FALLING_BLOCK:
+ // Block entities
+ case ENDER_CRYSTAL:
+ case COMPLEX_PART:
+ case FISHING_HOOK:
+ case ENDER_SIGNAL:
+ case EXPERIENCE_ORB:
+ case LEASH_HITCH:
+ case FIREWORK:
+ case WEATHER:
+ case LIGHTNING:
+ case WITHER_SKULL:
+ case UNKNOWN:
+ // non moving / unremovable
+ return checkEntity(plot, "entity-cap");
+ case ITEM_FRAME:
+ case PAINTING:
+ case ARMOR_STAND:
+ return checkEntity(plot, "entity-cap", "misc-cap");
+ // misc
+ case MINECART:
+ case MINECART_CHEST:
+ case MINECART_COMMAND:
+ case MINECART_FURNACE:
+ case MINECART_HOPPER:
+ case MINECART_MOB_SPAWNER:
+ case MINECART_TNT:
+ case BOAT:
+ return checkEntity(plot, "entity-cap", "vehicle-cap");
+ case RABBIT:
+ case SHEEP:
+ case MUSHROOM_COW:
+ case OCELOT:
+ case PIG:
+ case HORSE:
+ case SQUID:
+ case VILLAGER:
+ case IRON_GOLEM:
+ case WOLF:
+ case CHICKEN:
+ case COW:
+ case SNOWMAN:
+ case BAT:
+ // animal
+ return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap");
+ case BLAZE:
+ case CAVE_SPIDER:
+ case CREEPER:
+ case ENDERMAN:
+ case ENDERMITE:
+ case ENDER_DRAGON:
+ case GHAST:
+ case GIANT:
+ case GUARDIAN:
+ case MAGMA_CUBE:
+ case PIG_ZOMBIE:
+ case SILVERFISH:
+ case SKELETON:
+ case SLIME:
+ case SPIDER:
+ case WITCH:
+ case WITHER:
+ case ZOMBIE:
+ // monster
+ return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap");
+ default:
+ String[] types;
+ if (entity instanceof LivingEntity) {
+ if (entity instanceof Animals) {
+ types = new String[] { "entity-cap", "mob-cap", "animal-cap" };
+ } else if (entity instanceof Monster) {
+ types = new String[] { "entity-cap", "mob-cap", "hostile-cap" };
+ } else {
+ types = new String[] { "entity-cap", "mob-cap" };
+ }
+ } else if (entity instanceof Vehicle) {
+ types = new String[] { "entity-cap", "vehicle-cap" };
+ } else if (entity instanceof Hanging) {
+ types = new String[] { "entity-cap", "misc-cap" };
+ } else {
+ types = new String[] { "entity-cap" };
+ }
+ return checkEntity(plot, types);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockIgnite(final BlockIgniteEvent e) {
+ final Player player = e.getPlayer();
+ final Block b = e.getBlock();
+ final Location loc;
+ if (b != null) {
+ loc = BukkitUtil.getLocation(b.getLocation());
+ } else {
+ final Entity ent = e.getIgnitingEntity();
+ if (ent != null) {
+ loc = BukkitUtil.getLocation(ent);
+ } else {
+ if (player != null) {
+ loc = BukkitUtil.getLocation(player);
+ } else {
+ return;
+ }
+ }
+ }
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ if (e.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) {
+ e.setCancelled(true);
+ return;
+ }
+ if (player == null) {
+ e.setCancelled(true);
+ return;
+ }
+ final Player p = e.getPlayer();
+ final Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ e.setCancelled(true);
+ }
+ } else {
+ if (!plot.hasOwner()) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
+ e.setCancelled(true);
+ }
+ } else {
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ 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);
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onTeleport(final PlayerTeleportEvent event) {
+ if (event.getTo() == null || event.getFrom() == null) {
+ BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("location");
+ BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("lastplot");
+ return;
+ }
+ final org.bukkit.Location from = event.getFrom();
+ final org.bukkit.Location to = event.getTo();
+ int x2;
+ if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ Location loc = BukkitUtil.getLocation(to);
+ pp.setMeta("location", loc);
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot now = area.getPlotAbs(loc);
+ final Plot lastPlot = pp.getMeta("lastplot");
+ if (now == null) {
+ if (lastPlot != null && !plotExit(pp, lastPlot) && tmp_teleport) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
+ if (lastPlot.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
+ tmp_teleport = false;
+ player.teleport(from);
+ tmp_teleport = true;
+ } else {
+ Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
+ if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
+ tmp_teleport = false;
+ player.teleport(player.getWorld().getSpawnLocation());
+ tmp_teleport = true;
+ }
+ }
+ event.setCancelled(true);
+ return;
+ }
+ } else if (lastPlot != null && now.equals(lastPlot)) {
+ return;
+ } else {
+ if (!plotEntry(pp, now) && tmp_teleport) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
+ if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
+ tmp_teleport = false;
+ player.teleport(from);
+ tmp_teleport = true;
+ } else {
+ Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
+ if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
+ tmp_teleport = false;
+ player.teleport(player.getWorld().getSpawnLocation());
+ tmp_teleport = true;
+ }
+ }
+ event.setCancelled(true);
+ return;
+ }
+ }
+ final Integer border = area.getBorder();
+ if (tmp_teleport) {
+ if (x2 > border) {
+ to.setX(border - 4);
+ tmp_teleport = false;
+ player.teleport(event.getTo());
+ tmp_teleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ return;
+ } else if (x2 < -border) {
+ to.setX(-border + 4);
+ tmp_teleport = false;
+ player.teleport(event.getTo());
+ tmp_teleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ return;
+ }
+ }
+ return;
+ }
+ int z2;
+ if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ // Set last location
+ Location loc = BukkitUtil.getLocation(to);
+ pp.setMeta("location", loc);
+ final PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot now = area.getPlotAbs(loc);
+ final Plot lastPlot = pp.getMeta("lastplot");
+ if (now == null) {
+ if (lastPlot != null && !plotExit(pp, lastPlot) && tmp_teleport) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
+ if (lastPlot.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
+ tmp_teleport = false;
+ player.teleport(from);
+ tmp_teleport = true;
+ } else {
+ Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
+ if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
+ tmp_teleport = false;
+ player.teleport(player.getWorld().getSpawnLocation());
+ tmp_teleport = true;
+ }
+ }
+ event.setCancelled(true);
+ return;
+ }
+ } else if (lastPlot != null && now.equals(lastPlot)) {
+ return;
+ } else {
+ if (!plotEntry(pp, now) && tmp_teleport) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
+ if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
+ tmp_teleport = false;
+ player.teleport(from);
+ tmp_teleport = true;
+ } else {
+ Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
+ if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
+ tmp_teleport = false;
+ player.teleport(player.getWorld().getSpawnLocation());
+ tmp_teleport = true;
+ }
+ }
+ event.setCancelled(true);
+ return;
+ }
+ }
+ final Integer border = area.getBorder();
+ if (tmp_teleport) {
+ if (z2 > border) {
+ to.setZ(border - 4);
+ tmp_teleport = false;
+ player.teleport(event.getTo());
+ tmp_teleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ } else if (z2 < -border) {
+ to.setZ(-border + 4);
+ tmp_teleport = false;
+ player.teleport(event.getTo());
+ tmp_teleport = true;
+ MainUtil.sendMessage(pp, C.BORDER);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBucketEmpty(final PlayerBucketEmptyEvent e) {
+ final BlockFace bf = e.getBlockFace();
+ final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock();
+ final Location loc = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
+ final Plot plot = area.getPlotAbs(loc);
+ 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);
+ e.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);
+ e.setCancelled(true);
+ } else if (!plot.isAdded(pp.getUUID())) {
+ final Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s());
+ if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) e.getBucket().getId(), (byte) 0))) {
+ return;
+ }
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ e.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onInventoryClick(final InventoryClickEvent event) {
+ final HumanEntity clicker = event.getWhoClicked();
+ if (!(clicker instanceof Player)) {
+ return;
+ }
+ final Player player = (Player) clicker;
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ final PlotInventory inv = pp.getMeta("inventory");
+ if (inv != null && event.getRawSlot() == event.getSlot()) {
+ if (!inv.onClick(event.getSlot())) {
+ event.setCancelled(true);
+ inv.close();
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onInventoryClose(final InventoryCloseEvent event) {
+ final HumanEntity closer = event.getPlayer();
+ if (!(closer instanceof Player)) {
+ return;
+ }
+ final Player player = (Player) closer;
+ BukkitUtil.getPlayer(player).deleteMeta("inventory");
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onLeave(final PlayerQuitEvent event) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
+ pp.unregister();
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBucketFill(final PlayerBucketFillEvent e) {
+ final Block b = e.getBlockClicked();
+ final Location loc = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Player p = e.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ final Plot plot = area.getPlotAbs(loc);
+ 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);
+ e.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);
+ e.setCancelled(true);
+ } else if (!plot.isAdded(pp.getUUID())) {
+ final Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s());
+ final Block block = e.getBlockClicked();
+ if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
+ return;
+ }
+ if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ return;
+ }
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ e.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onVehicleCreate(final VehicleCreateEvent event) {
+ final Vehicle entity = event.getVehicle();
+ final Location loc = BukkitUtil.getLocation(entity);
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Plot plot = area.getOwnedPlotAbs(loc);
+ if (plot == null) {
+ entity.remove();
+ return;
+ }
+ if (checkEntity(entity, plot)) {
+ entity.remove();
+ return;
+ }
+ if (Settings.KILL_ROAD_VEHICLES) {
+ entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onHangingPlace(final HangingPlaceEvent e) {
+ final Block b = e.getBlock().getRelative(e.getBlockFace());
+ final Location loc = BukkitUtil.getLocation(b.getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Player p = e.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ final Plot plot = area.getPlotAbs(loc);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ e.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);
+ e.setCancelled(true);
+ }
+ return;
+ } else if (!plot.isAdded(pp.getUUID())) {
+ if (!FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_PLACE.s())) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
+ e.setCancelled(true);
+ }
+ return;
+ }
+ }
+ if (checkEntity(e.getEntity(), plot)) {
+ e.setCancelled(true);
+ }
+
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onHangingBreakByEntity(final HangingBreakByEntityEvent e) {
+ final Entity r = e.getRemover();
+ if (r instanceof Player) {
+ final Player p = (Player) r;
+ final Location l = BukkitUtil.getLocation(e.getEntity());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ final Plot plot = area.getPlotAbs(l);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
+ e.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);
+ e.setCancelled(true);
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ if (FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_BREAK.s())) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
+ e.setCancelled(true);
+ }
+ }
+ }
+ } else if (r instanceof Projectile) {
+ final Projectile p = (Projectile) r;
+ if (p.getShooter() instanceof Player) {
+ final Player shooter = (Player) p.getShooter();
+ Location loc = BukkitUtil.getLocation(e.getEntity());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final PlotPlayer player = BukkitUtil.getPlayer(shooter);
+ final Plot plot = area.getPlotAbs(BukkitUtil.getLocation(e.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);
+ e.setCancelled(true);
+ }
+ } else if (!plot.isAdded(player.getUUID())) {
+ if (!FlagManager.isPlotFlagTrue(plot, C.FLAG_HANGING_BREAK.s())) {
+ if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
+ MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPlayerInteractEntity(final PlayerInteractEntityEvent e) {
+ final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Player p = e.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ final Plot plot = area.getPlotAbs(l);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_ROAD);
+ e.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);
+ e.setCancelled(true);
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ final Entity entity = e.getRightClicked();
+ if (entity instanceof Monster && FlagManager.isPlotFlagTrue(plot, C.FLAG_HOSTILE_INTERACT.s())) {
+ return;
+ }
+ if (entity instanceof Animals && FlagManager.isPlotFlagTrue(plot, C.FLAG_ANIMAL_INTERACT.s())) {
+ return;
+ }
+ if (entity instanceof Tameable && ((Tameable) entity).isTamed() && FlagManager.isPlotFlagTrue(plot, C.FLAG_TAMED_INTERACT.s())) {
+ return;
+ }
+ if (entity instanceof Vehicle && FlagManager.isPlotFlagTrue(plot, C.FLAG_VEHICLE_USE.s())) {
+ return;
+ }
+ if (entity instanceof Player && FlagManager.isPlotFlagTrue(plot, C.FLAG_PLAYER_INTERACT.s())) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onVehicleDestroy(final VehicleDestroyEvent e) {
+ final Location l = BukkitUtil.getLocation(e.getVehicle());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Entity d = e.getAttacker();
+ if (d instanceof Player) {
+ final Player p = (Player) d;
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ final Plot plot = area.getPlotAbs(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");
+ e.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");
+ e.setCancelled(true);
+ return;
+ }
+ return;
+ }
+ if (!plot.isAdded(pp.getUUID())) {
+ if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) {
+ return;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.other");
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPotionSplash(final PotionSplashEvent event) {
+ final ThrownPotion damager = event.getPotion();
+ final Location l = BukkitUtil.getLocation(damager);
+ if (!PS.get().hasPlotArea(l.getWorld())) {
+ return;
+ }
+ for (final LivingEntity victim : event.getAffectedEntities()) {
+ if (!entityDamage(l, damager, victim)) {
+ event.setIntensity(victim, 0);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) {
+ final Entity damager = e.getDamager();
+ final Location l = BukkitUtil.getLocation(damager);
+ if (!PS.get().hasPlotArea(l.getWorld())) {
+ return;
+ }
+ final Entity victim = e.getEntity();
+ if (!entityDamage(l, damager, victim)) {
+ e.setCancelled(true);
+ }
+ }
+
+ public boolean entityDamage(final Location l, final Entity damager, final Entity victim) {
+ final Location dloc = BukkitUtil.getLocation(damager);
+ final 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;
+ }
+
+ final Plot dplot = dArea != null ? dArea.getPlot(dloc) : null;
+ final 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 {
+ // Priorize plots for close to seamless pvp zones
+ plot = vplot == null ? dplot : dplot == null || !(victim instanceof Player) ? vplot :
+ victim.getTicksLived() > damager.getTicksLived() ? dplot : vplot;
+ stub = plot.hasOwner() ? "other" : "unowned";
+ }
+
+ Player player;
+ if (damager instanceof Player) { // attacker is player
+ player = (Player) damager;
+ } else if (damager instanceof Projectile) {
+ final Projectile projectile = (Projectile) damager;
+ final ProjectileSource shooter = projectile.getShooter();
+ if (shooter instanceof Player) { // shooter is player
+ player = (Player) shooter;
+ } else { // shooter is not player
+ player = null;
+ }
+ } else { // Attacker is not player
+ player = null;
+ }
+ if (player != null) {
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ if (victim instanceof Hanging) { // hanging
+ if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hanging-break") || plot.isAdded(pp.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.destroy." + stub);
+ return false;
+ }
+ } else if (victim.getEntityId() == 30) {
+ if (plot != null && (FlagManager.isPlotFlagTrue(plot, "misc-break") || plot.isAdded(pp.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.destroy." + stub);
+ return false;
+ }
+ } else if (victim instanceof Monster || victim instanceof EnderDragon) { // victim is monster
+ if (plot != null && (FlagManager.isPlotFlagTrue(plot, "hostile-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot
+ .isAdded(pp.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ } else if (victim instanceof Tameable) { // victim is tameable
+ if (plot != null && (FlagManager.isPlotFlagTrue(plot, "tamed-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot
+ .isAdded(pp.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ } else if (victim instanceof Player) {
+ if (plot != null) {
+ final Flag pvp = FlagManager.getPlotFlagRaw(plot, C.FLAG_PVP.s());
+ if (pvp == null) {
+ return true;
+ } else {
+ if ((Boolean) pvp.getValue()) {
+ return true;
+ } else if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ }
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub);
+ return false;
+ }
+ } else if (victim instanceof Creature) { // victim is animal
+ if (plot != null && (FlagManager.isPlotFlagTrue(plot, "animal-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot
+ .isAdded(pp.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(pp, 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 && (FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID()))) {
+ return true;
+ }
+ if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub);
+ return false;
+ }
+ }
+ return true;
+ }
+ // player is null
+ return !(damager instanceof Arrow && !(victim instanceof Creature));
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPlayerEggThrow(final PlayerEggThrowEvent e) {
+ final Location l = BukkitUtil.getLocation(e.getEgg().getLocation());
+ PlotArea area = l.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Player p = e.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(p);
+ final Plot plot = area.getPlot(l);
+ if (plot == null) {
+ if (!Permissions.hasPermission(pp, "plots.admin.projectile.road")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.road");
+ e.setHatching(false);
+ }
+ } else {
+ if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, "plots.admin.projectile.unowned")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.unowned");
+ e.setHatching(false);
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ if (!Permissions.hasPermission(pp, "plots.admin.projectile.other")) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.other");
+ e.setHatching(false);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void BlockCreate(final BlockPlaceEvent event) {
+ final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = loc.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ final Plot plot = area.getPlotAbs(loc);
+ if (plot != null) {
+ 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())) {
+ final Flag place = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
+ final Block block = event.getBlock();
+ if ((place == null || !((HashSet) place.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData())))
+ && !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_RESTRICTS_BUILDING && plot.getFlags().containsKey("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 (FlagManager.isPlotFlagTrue(plot, C.FLAG_DISABLE_PHYSICS.s())) {
+ final Block block = event.getBlockPlaced();
+ if (block.getType().hasGravity()) {
+ sendBlockChange(block.getLocation(), block.getType(), block.getData());
+ }
+ }
+ if (loc.getY() > area.MAX_BUILD_HEIGHT && loc.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}", "" + area.MAX_BUILD_HEIGHT));
+ }
+ } else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
+ event.setCancelled(true);
+ }
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8_3.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8_3.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8_3.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8_3.java
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java
similarity index 97%
rename from src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java
index f1f1309ec..d0d616d18 100644
--- a/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java
@@ -1,251 +1,251 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// PlotSquared - A plot manager and world generator for the Bukkit API /
-// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
-// /
-// This program is free software; you can redistribute it and/or modify /
-// it under the terms of the GNU General Public License as published by /
-// the Free Software Foundation; either version 3 of the License, or /
-// (at your option) any later version. /
-// /
-// This program is distributed in the hope that it will be useful, /
-// but WITHOUT ANY WARRANTY; without even the implied warranty of /
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
-// GNU General Public License for more details. /
-// /
-// You should have received a copy of the GNU General Public License /
-// along with this program; if not, write to the Free Software Foundation, /
-// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
-// /
-// You can contact us via: support@intellectualsites.com /
-////////////////////////////////////////////////////////////////////////////////////////////////////
-package com.plotsquared.bukkit.listeners;
-
-import com.intellectualcrafters.plot.flag.Flag;
-import com.intellectualcrafters.plot.flag.FlagManager;
-import com.intellectualcrafters.plot.object.Plot;
-import com.intellectualcrafters.plot.object.PlotPlayer;
-import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
-import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
-import com.plotsquared.bukkit.util.BukkitUtil;
-import com.plotsquared.listener.PlotListener;
-import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
-import org.bukkit.Material;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.BlockDamageEvent;
-import org.bukkit.event.entity.EntityDamageEvent;
-import org.bukkit.event.player.PlayerDropItemEvent;
-import org.bukkit.event.player.PlayerPickupItemEvent;
-import org.bukkit.event.player.PlayerQuitEvent;
-import org.bukkit.plugin.java.JavaPlugin;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.UUID;
-
-/**
- * Created 2014-10-30 for PlotSquared
- *
-
- */
-@SuppressWarnings({ "deprecation" })
-public class PlotPlusListener extends PlotListener implements Listener {
- private final static HashMap feedRunnable = new HashMap<>();
- private final static HashMap healRunnable = new HashMap<>();
-
- public static void startRunnable(final JavaPlugin plugin) {
- plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
- @Override
- public void run() {
- if (!healRunnable.isEmpty()) {
- for (final Iterator> iter = healRunnable.entrySet().iterator(); iter.hasNext();) {
- final Entry entry = iter.next();
- final Interval value = entry.getValue();
- ++value.count;
- if (value.count == value.interval) {
- value.count = 0;
- final Player player = Bukkit.getPlayer(entry.getKey());
- if (player == null) {
- iter.remove();
- continue;
- }
- final double level = player.getHealth();
- if (level != value.max) {
- player.setHealth(Math.min(level + value.amount, value.max));
- }
- }
- }
- }
- if (!feedRunnable.isEmpty()) {
- for (final Iterator> iter = feedRunnable.entrySet().iterator(); iter.hasNext();) {
- final Entry entry = iter.next();
- final Interval value = entry.getValue();
- ++value.count;
- if (value.count == value.interval) {
- value.count = 0;
- final Player player = Bukkit.getPlayer(entry.getKey());
- if (player == null) {
- iter.remove();
- continue;
- }
- final int level = player.getFoodLevel();
- if (level != value.max) {
- player.setFoodLevel(Math.min(level + value.amount, value.max));
- }
- }
- }
- }
- }
- }, 0l, 20l);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onInteract(final BlockDamageEvent event) {
- final Player player = event.getPlayer();
- if (player.getGameMode() != GameMode.SURVIVAL) {
- return;
- }
- final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
- if (plot == null) {
- return;
- }
- if (FlagManager.isBooleanFlag(plot, "instabreak", false)) {
- event.getBlock().breakNaturally();
- }
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onDamage(final EntityDamageEvent event) {
- if (event.getEntityType() != EntityType.PLAYER) {
- return;
- }
- final Player player = (Player) event.getEntity();
- final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
- if (plot == null) {
- return;
- }
- if (FlagManager.isBooleanFlag(plot, "invincible", false)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler
- public void onItemPickup(final PlayerPickupItemEvent event) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
- if (plot == null) {
- return;
- }
- final UUID uuid = pp.getUUID();
- if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler
- public void onItemDrop(final PlayerDropItemEvent event) {
- final Player player = event.getPlayer();
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
- if (plot == null) {
- return;
- }
- final UUID uuid = pp.getUUID();
- if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler
- public void onPlotEnter(final PlayerEnterPlotEvent event) {
- final Player player = event.getPlayer();
- final Plot plot = event.getPlot();
- final Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
- if (feed != null) {
- final Integer[] value = (Integer[]) feed.getValue();
- feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
- }
- final Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
- if (heal != null) {
- final Integer[] value = (Integer[]) heal.getValue();
- healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
- }
- }
-
- @EventHandler
- public void onPlayerQuit(final PlayerQuitEvent event) {
- final Player player = event.getPlayer();
- final String name = player.getName();
- feedRunnable.remove(name);
- healRunnable.remove(name);
- }
-
- @EventHandler
- public void onPlotLeave(final PlayerLeavePlotEvent event) {
- final Player leaver = event.getPlayer();
- final Plot plot = event.getPlot();
- if (!plot.hasOwner()) {
- return;
- }
- BukkitUtil.getPlayer(leaver);
- final String name = leaver.getName();
- feedRunnable.remove(name);
- healRunnable.remove(name);
- }
-
- public static class Interval {
- public final int interval;
- public final int amount;
- public final int max;
- public int count = 0;
-
- public Interval(final int interval, final int amount, final int max) {
- this.interval = interval;
- this.amount = amount;
- this.max = max;
- }
- }
-
- /**
- * Record Meta Class
- *
-
- */
- public static class RecordMeta {
- public final static List metaList = new ArrayList<>();
- static {
- for (int x = 3; x < 12; x++) {
- metaList.add(new RecordMeta(x + "", Material.valueOf("RECORD_" + x)));
- }
- }
- private final String name;
- private final Material material;
-
- public RecordMeta(final String name, final Material material) {
- this.name = name;
- this.material = material;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- @Override
- public int hashCode() {
- return name.hashCode();
- }
-
- public Material getMaterial() {
- return material;
- }
- }
-}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// PlotSquared - A plot manager and world generator for the Bukkit API /
+// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
+// /
+// This program is free software; you can redistribute it and/or modify /
+// it under the terms of the GNU General Public License as published by /
+// the Free Software Foundation; either version 3 of the License, or /
+// (at your option) any later version. /
+// /
+// This program is distributed in the hope that it will be useful, /
+// but WITHOUT ANY WARRANTY; without even the implied warranty of /
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
+// GNU General Public License for more details. /
+// /
+// You should have received a copy of the GNU General Public License /
+// along with this program; if not, write to the Free Software Foundation, /
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
+// /
+// You can contact us via: support@intellectualsites.com /
+////////////////////////////////////////////////////////////////////////////////////////////////////
+package com.plotsquared.bukkit.listeners;
+
+import com.intellectualcrafters.plot.flag.Flag;
+import com.intellectualcrafters.plot.flag.FlagManager;
+import com.intellectualcrafters.plot.object.Plot;
+import com.intellectualcrafters.plot.object.PlotPlayer;
+import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
+import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
+import com.plotsquared.bukkit.util.BukkitUtil;
+import com.plotsquared.listener.PlotListener;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Material;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockDamageEvent;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerPickupItemEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.UUID;
+
+/**
+ * Created 2014-10-30 for PlotSquared
+ *
+
+ */
+@SuppressWarnings({ "deprecation" })
+public class PlotPlusListener extends PlotListener implements Listener {
+ private final static HashMap feedRunnable = new HashMap<>();
+ private final static HashMap healRunnable = new HashMap<>();
+
+ public static void startRunnable(final JavaPlugin plugin) {
+ plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
+ @Override
+ public void run() {
+ if (!healRunnable.isEmpty()) {
+ for (final Iterator> iter = healRunnable.entrySet().iterator(); iter.hasNext();) {
+ final Entry entry = iter.next();
+ final Interval value = entry.getValue();
+ ++value.count;
+ if (value.count == value.interval) {
+ value.count = 0;
+ final Player player = Bukkit.getPlayer(entry.getKey());
+ if (player == null) {
+ iter.remove();
+ continue;
+ }
+ final double level = player.getHealth();
+ if (level != value.max) {
+ player.setHealth(Math.min(level + value.amount, value.max));
+ }
+ }
+ }
+ }
+ if (!feedRunnable.isEmpty()) {
+ for (final Iterator> iter = feedRunnable.entrySet().iterator(); iter.hasNext();) {
+ final Entry entry = iter.next();
+ final Interval value = entry.getValue();
+ ++value.count;
+ if (value.count == value.interval) {
+ value.count = 0;
+ final Player player = Bukkit.getPlayer(entry.getKey());
+ if (player == null) {
+ iter.remove();
+ continue;
+ }
+ final int level = player.getFoodLevel();
+ if (level != value.max) {
+ player.setFoodLevel(Math.min(level + value.amount, value.max));
+ }
+ }
+ }
+ }
+ }
+ }, 0l, 20l);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onInteract(final BlockDamageEvent event) {
+ final Player player = event.getPlayer();
+ if (player.getGameMode() != GameMode.SURVIVAL) {
+ return;
+ }
+ final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
+ if (plot == null) {
+ return;
+ }
+ if (FlagManager.isBooleanFlag(plot, "instabreak", false)) {
+ event.getBlock().breakNaturally();
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onDamage(final EntityDamageEvent event) {
+ if (event.getEntityType() != EntityType.PLAYER) {
+ return;
+ }
+ final Player player = (Player) event.getEntity();
+ final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
+ if (plot == null) {
+ return;
+ }
+ if (FlagManager.isBooleanFlag(plot, "invincible", false)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onItemPickup(final PlayerPickupItemEvent event) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
+ if (plot == null) {
+ return;
+ }
+ final UUID uuid = pp.getUUID();
+ if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onItemDrop(final PlayerDropItemEvent event) {
+ final Player player = event.getPlayer();
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
+ final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
+ if (plot == null) {
+ return;
+ }
+ final UUID uuid = pp.getUUID();
+ if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler
+ public void onPlotEnter(final PlayerEnterPlotEvent event) {
+ final Player player = event.getPlayer();
+ final Plot plot = event.getPlot();
+ final Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
+ if (feed != null) {
+ final Integer[] value = (Integer[]) feed.getValue();
+ feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
+ }
+ final Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
+ if (heal != null) {
+ final Integer[] value = (Integer[]) heal.getValue();
+ healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
+ }
+ }
+
+ @EventHandler
+ public void onPlayerQuit(final PlayerQuitEvent event) {
+ final Player player = event.getPlayer();
+ final String name = player.getName();
+ feedRunnable.remove(name);
+ healRunnable.remove(name);
+ }
+
+ @EventHandler
+ public void onPlotLeave(final PlayerLeavePlotEvent event) {
+ final Player leaver = event.getPlayer();
+ final Plot plot = event.getPlot();
+ if (!plot.hasOwner()) {
+ return;
+ }
+ BukkitUtil.getPlayer(leaver);
+ final String name = leaver.getName();
+ feedRunnable.remove(name);
+ healRunnable.remove(name);
+ }
+
+ public static class Interval {
+ public final int interval;
+ public final int amount;
+ public final int max;
+ public int count = 0;
+
+ public Interval(final int interval, final int amount, final int max) {
+ this.interval = interval;
+ this.amount = amount;
+ this.max = max;
+ }
+ }
+
+ /**
+ * Record Meta Class
+ *
+
+ */
+ public static class RecordMeta {
+ public final static List metaList = new ArrayList<>();
+ static {
+ for (int x = 3; x < 12; x++) {
+ metaList.add(new RecordMeta(x + "", Material.valueOf("RECORD_" + x)));
+ }
+ }
+ private final String name;
+ private final Material material;
+
+ public RecordMeta(final String name, final Material material) {
+ this.name = name;
+ this.material = material;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ public Material getMaterial() {
+ return material;
+ }
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java
diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitOfflinePlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitOfflinePlayer.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/BukkitOfflinePlayer.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitOfflinePlayer.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/AgeableStats.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/AgeableStats.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/AgeableStats.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/AgeableStats.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/ArmorStandStats.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/ArmorStandStats.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/ArmorStandStats.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/ArmorStandStats.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/EntityBaseStats.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityBaseStats.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/EntityBaseStats.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityBaseStats.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/HorseStats.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/HorseStats.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/HorseStats.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/HorseStats.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/LivingEntityStats.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/LivingEntityStats.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/LivingEntityStats.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/LivingEntityStats.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/entity/TameableStats.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/TameableStats.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/entity/TameableStats.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/TameableStats.java
diff --git a/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java
diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java
diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java
diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java
diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java
diff --git a/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/titles/HackTitle.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java
diff --git a/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java
similarity index 97%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java
index d056ca211..f24dbd247 100644
--- a/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java
@@ -1,108 +1,108 @@
-package com.plotsquared.bukkit.util;
-
-import com.intellectualcrafters.plot.commands.MainCommand;
-import com.intellectualcrafters.plot.object.ConsolePlayer;
-import com.intellectualcrafters.plot.object.PlotPlayer;
-import com.intellectualcrafters.plot.util.Permissions;
-import com.intellectualcrafters.plot.util.StringComparison;
-import com.plotsquared.bukkit.commands.DebugUUID;
-import com.plotsquared.general.commands.Command;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabCompleter;
-import org.bukkit.entity.Player;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Created 2015-02-20 for PlotSquared
- *
-
- */
-public class BukkitCommand implements CommandExecutor, TabCompleter {
-
- public BukkitCommand() {
- MainCommand.getInstance().addCommand(new DebugUUID());
- }
-
- @Override
- public boolean onCommand(final CommandSender commandSender, final org.bukkit.command.Command command, final String commandLabel,
- final String[] args) {
- if (commandSender instanceof Player) {
- return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
- }
- if (commandSender == null || commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
- return MainCommand.onCommand(ConsolePlayer.getConsole(), commandLabel, args);
- }
- @SuppressWarnings("deprecation")
- ConsolePlayer sender = new ConsolePlayer() {
- @Override
- public void sendMessage(String message) {
- commandSender.sendMessage(commandLabel);
- }
-
- @Override
- public boolean hasPermission(String perm) {
- return commandSender.hasPermission(commandLabel);
- }
-
- @Override
- public String getName() {
- if (commandSender.getName().equals("CONSOLE")) {
- return "*";
- }
- return commandSender.getName();
- }
- };
- sender.teleport(ConsolePlayer.getConsole().getLocationFull());
- boolean result = MainCommand.onCommand(sender, commandLabel, args);
- ConsolePlayer.getConsole().teleport(sender.getLocationFull());
- return result;
- }
-
- @Override
- public List onTabComplete(final CommandSender commandSender, final org.bukkit.command.Command command, final String s,
- final String[] strings) {
- if (!(commandSender instanceof Player)) {
- return null;
- }
- final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
- if (strings.length < 1) {
- if ((strings.length == 0) || "plots".startsWith(s)) {
- return Collections.singletonList("plots");
- }
- }
- if (strings.length > 1) {
- return null;
- }
- final Set tabOptions = new HashSet<>();
- final String arg = strings[0].toLowerCase();
- ArrayList labels = new ArrayList<>();
- for (final Command cmd : MainCommand.getInstance().getCommands()) {
- final String label = cmd.getCommand();
- HashSet aliases = new HashSet<>(cmd.getAliases());
- aliases.add(label);
- for (String alias : aliases) {
- labels.add(alias);
- if (alias.startsWith(arg)) {
- if (Permissions.hasPermission(player, cmd.getPermission())) {
- tabOptions.add(label);
- } else {
- break;
- }
- }
- }
- }
- String best = new StringComparison<>(arg, labels).getBestMatch();
- tabOptions.add(best);
- if (!tabOptions.isEmpty()) {
- return new ArrayList<>(tabOptions);
- }
- return null;
- }
-}
+package com.plotsquared.bukkit.util;
+
+import com.intellectualcrafters.plot.commands.MainCommand;
+import com.intellectualcrafters.plot.object.ConsolePlayer;
+import com.intellectualcrafters.plot.object.PlotPlayer;
+import com.intellectualcrafters.plot.util.Permissions;
+import com.intellectualcrafters.plot.util.StringComparison;
+import com.plotsquared.bukkit.commands.DebugUUID;
+import com.plotsquared.general.commands.Command;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created 2015-02-20 for PlotSquared
+ *
+
+ */
+public class BukkitCommand implements CommandExecutor, TabCompleter {
+
+ public BukkitCommand() {
+ MainCommand.getInstance().addCommand(new DebugUUID());
+ }
+
+ @Override
+ public boolean onCommand(final CommandSender commandSender, final org.bukkit.command.Command command, final String commandLabel,
+ final String[] args) {
+ if (commandSender instanceof Player) {
+ return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
+ }
+ if (commandSender == null || commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
+ return MainCommand.onCommand(ConsolePlayer.getConsole(), commandLabel, args);
+ }
+ @SuppressWarnings("deprecation")
+ ConsolePlayer sender = new ConsolePlayer() {
+ @Override
+ public void sendMessage(String message) {
+ commandSender.sendMessage(commandLabel);
+ }
+
+ @Override
+ public boolean hasPermission(String perm) {
+ return commandSender.hasPermission(commandLabel);
+ }
+
+ @Override
+ public String getName() {
+ if (commandSender.getName().equals("CONSOLE")) {
+ return "*";
+ }
+ return commandSender.getName();
+ }
+ };
+ sender.teleport(ConsolePlayer.getConsole().getLocationFull());
+ boolean result = MainCommand.onCommand(sender, commandLabel, args);
+ ConsolePlayer.getConsole().teleport(sender.getLocationFull());
+ return result;
+ }
+
+ @Override
+ public List onTabComplete(final CommandSender commandSender, final org.bukkit.command.Command command, final String s,
+ final String[] strings) {
+ if (!(commandSender instanceof Player)) {
+ return null;
+ }
+ final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
+ if (strings.length < 1) {
+ if ((strings.length == 0) || "plots".startsWith(s)) {
+ return Collections.singletonList("plots");
+ }
+ }
+ if (strings.length > 1) {
+ return null;
+ }
+ final Set tabOptions = new HashSet<>();
+ final String arg = strings[0].toLowerCase();
+ ArrayList labels = new ArrayList<>();
+ for (final Command cmd : MainCommand.getInstance().getCommands()) {
+ final String label = cmd.getCommand();
+ HashSet aliases = new HashSet<>(cmd.getAliases());
+ aliases.add(label);
+ for (String alias : aliases) {
+ labels.add(alias);
+ if (alias.startsWith(arg)) {
+ if (Permissions.hasPermission(player, cmd.getPermission())) {
+ tabOptions.add(label);
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ String best = new StringComparison<>(arg, labels).getBestMatch();
+ tabOptions.add(best);
+ if (!tabOptions.isEmpty()) {
+ return new ArrayList<>(tabOptions);
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java
similarity index 98%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java
index a0d333cbe..eaa63d6a7 100644
--- a/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java
@@ -1,340 +1,340 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// PlotSquared - A plot manager and world generator for the Bukkit API /
-// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
-// /
-// This program is free software; you can redistribute it and/or modify /
-// it under the terms of the GNU General Public License as published by /
-// the Free Software Foundation; either version 3 of the License, or /
-// (at your option) any later version. /
-// /
-// This program is distributed in the hope that it will be useful, /
-// but WITHOUT ANY WARRANTY; without even the implied warranty of /
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
-// GNU General Public License for more details. /
-// /
-// You should have received a copy of the GNU General Public License /
-// along with this program; if not, write to the Free Software Foundation, /
-// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
-// /
-// You can contact us via: support@intellectualsites.com /
-////////////////////////////////////////////////////////////////////////////////////////////////////
-package com.plotsquared.bukkit.util;
-
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.bukkit.Bukkit;
-import org.bukkit.Chunk;
-import org.bukkit.World;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockState;
-
-import com.intellectualcrafters.jnbt.ByteArrayTag;
-import com.intellectualcrafters.jnbt.CompoundTag;
-import com.intellectualcrafters.jnbt.IntTag;
-import com.intellectualcrafters.jnbt.ListTag;
-import com.intellectualcrafters.jnbt.ShortTag;
-import com.intellectualcrafters.jnbt.StringTag;
-import com.intellectualcrafters.jnbt.Tag;
-import com.intellectualcrafters.plot.object.ChunkLoc;
-import com.intellectualcrafters.plot.object.Location;
-import com.intellectualcrafters.plot.object.RegionWrapper;
-import com.intellectualcrafters.plot.object.RunnableVal;
-import com.intellectualcrafters.plot.util.MainUtil;
-import com.intellectualcrafters.plot.util.SchematicHandler;
-import com.intellectualcrafters.plot.util.TaskManager;
-import com.plotsquared.bukkit.object.schematic.StateWrapper;
-
-/**
- * Schematic Handler
- *
-
-
- */
-public class BukkitSchematicHandler extends SchematicHandler {
-
- @Override
- public void getCompoundTag(final String world, final Set regions, final RunnableVal whenDone) {
- // async
- TaskManager.runTaskAsync(new Runnable() {
- @Override
- public void run() {
- // Main positions
- Location[] corners = MainUtil.getCorners(world, regions);
- final Location bot = corners[0];
- final Location top = corners[1];
-
- final int width = (top.getX() - bot.getX()) + 1;
- final int height = (top.getY() - bot.getY()) + 1;
- final int length = (top.getZ() - bot.getZ()) + 1;
- // Main Schematic tag
- final HashMap schematic = new HashMap<>();
- schematic.put("Width", new ShortTag("Width", (short) width));
- schematic.put("Length", new ShortTag("Length", (short) length));
- schematic.put("Height", new ShortTag("Height", (short) height));
- schematic.put("Materials", new StringTag("Materials", "Alpha"));
- schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
- schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
- schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
- schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
- schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
- schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
- // Arrays of data types
- final List tileEntities = new ArrayList<>();
- final byte[] blocks = new byte[width * height * length];
- final byte[] blockData = new byte[width * height * length];
- // Queue
- final ArrayDeque queue = new ArrayDeque<>(regions);
- TaskManager.runTask(new Runnable() {
- @Override
- public void run() {
- if (queue.isEmpty()) {
- TaskManager.runTaskAsync(new Runnable() {
- @Override
- public void run() {
- schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
- schematic.put("Data", new ByteArrayTag("Data", blockData));
- schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList()));
- schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
- whenDone.value = new CompoundTag("Schematic", schematic);
- TaskManager.runTask(whenDone);
- System.gc();
- System.gc();
- }
- });
- return;
- }
- final Runnable regionTask = this;
- RegionWrapper region = queue.poll();
- Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
- Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
- final int bx = bot.getX();
- final int bz = bot.getZ();
- final int p1x = pos1.getX();
- final int p1z = pos1.getZ();
- final int p2x = pos2.getX();
- final int p2z = pos2.getZ();
- final int bcx = p1x >> 4;
- final int bcz = p1z >> 4;
- final int tcx = p2x >> 4;
- final int tcz = p2z >> 4;
- final int sy = pos1.getY();
- final int ey = pos2.getY();
- // Generate list of chunks
- final ArrayList chunks = new ArrayList<>();
- for (int x = bcx; x <= tcx; x++) {
- for (int z = bcz; z <= tcz; z++) {
- chunks.add(new ChunkLoc(x, z));
- }
- }
- final World worldObj = Bukkit.getWorld(world);
- // Main thread
- TaskManager.runTask(new Runnable() {
- @Override
- public void run() {
- final long start = System.currentTimeMillis();
- while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) {
- // save schematics
- final ChunkLoc chunk = chunks.remove(0);
- final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
- if (!bc.load(false)) {
- continue;
- }
- final int X = chunk.x;
- final int Z = chunk.z;
- int xxb = X << 4;
- int zzb = Z << 4;
- int xxt = xxb + 15;
- int zzt = zzb + 15;
-
- if (X == bcx) {
- xxb = p1x;
- }
- if (X == tcx) {
- xxt = p2x;
- }
- if (Z == bcz) {
- zzb = p1z;
- }
- if (Z == tcz) {
- zzt = p2z;
- }
- for (int y = sy; y <= Math.min(255, ey); y++) {
- final int ry = y - sy;
- final int i1 = (ry * width * length);
- for (int z = zzb; z <= zzt; z++) {
- final int rz = z - bz;
- final int i2 = i1 + (rz * width);
- for (int x = xxb; x <= xxt; x++) {
- final int rx = x - bx;
- final int index = i2 + rx;
- final Block block = worldObj.getBlockAt(x, y, z);
- final int id = block.getTypeId();
- switch (id) {
- case 0:
- case 2:
- case 4:
- case 13:
- case 14:
- case 15:
- case 20:
- case 21:
- case 22:
- case 24:
- case 30:
- case 32:
- case 37:
- case 39:
- case 40:
- case 41:
- case 42:
- case 45:
- case 46:
- case 47:
- case 48:
- case 49:
- case 51:
- case 55:
- case 56:
- case 57:
- case 58:
- case 60:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 73:
- case 74:
- case 78:
- case 79:
- case 80:
- case 81:
- case 82:
- case 83:
- case 85:
- case 87:
- case 88:
- case 101:
- case 102:
- case 103:
- case 110:
- case 112:
- case 113:
- case 121:
- case 122:
- case 129:
- case 133:
- case 165:
- case 166:
- case 169:
- case 170:
- case 172:
- case 173:
- case 174:
- case 181:
- case 182:
- case 188:
- case 189:
- case 190:
- case 191:
- case 192: {
- break;
- }
- case 54:
- case 130:
- case 142:
- case 27:
- case 137:
- case 52:
- case 154:
- case 84:
- case 25:
- case 144:
- case 138:
- case 176:
- case 177:
- case 63:
- case 68:
- case 323:
- case 117:
- case 116:
- case 28:
- case 66:
- case 157:
- case 61:
- case 62:
- case 140:
- case 146:
- case 149:
- case 150:
- case 158:
- case 23:
- case 123:
- case 124:
- case 29:
- case 33:
- case 151:
- case 178: {
- // TODO implement fully
- final BlockState state = block.getState();
- if (state != null) {
- final StateWrapper wrapper = new StateWrapper(state);
- final CompoundTag rawTag = wrapper.getTag();
- if (rawTag != null) {
- final Map values = new HashMap();
- for (final Entry entry : rawTag.getValue().entrySet()) {
- values.put(entry.getKey(), entry.getValue());
- }
- values.put("id", new StringTag("id", wrapper.getId()));
- values.put("x", new IntTag("x", x));
- values.put("y", new IntTag("y", y));
- values.put("z", new IntTag("z", z));
- final CompoundTag tileEntityTag = new CompoundTag(values);
- tileEntities.add(tileEntityTag);
- }
- }
- }
- default: {
- blockData[index] = block.getData();
- }
- }
- // For optimization reasons, we are not supporting custom data types
- // Especially since the most likely reason beyond this range is modded servers in which the blocks
- // have NBT
- // if (type > 255) {
- // if (addBlocks == null) {
- // addBlocks = new byte[(blocks.length >> 1) + 1];
- // }
- // addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
- // (addBlocks[index >> 1] & 0xF0) | ((type >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((type
- // >> 8) & 0xF) << 4));
- // }
- blocks[index] = (byte) id;
- }
- }
- }
- }
- if (!chunks.isEmpty()) {
- TaskManager.runTaskLater(this, 1);
- } else {
- regionTask.run();
- }
- }
- });
- }
- });
- }
- });
- }
-
- @Override
- public void restoreTag(CompoundTag ct, short x, short y, short z, Schematic schem) {
- new StateWrapper(ct).restoreTag(x, y, z, schem);
- }
-}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// PlotSquared - A plot manager and world generator for the Bukkit API /
+// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
+// /
+// This program is free software; you can redistribute it and/or modify /
+// it under the terms of the GNU General Public License as published by /
+// the Free Software Foundation; either version 3 of the License, or /
+// (at your option) any later version. /
+// /
+// This program is distributed in the hope that it will be useful, /
+// but WITHOUT ANY WARRANTY; without even the implied warranty of /
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
+// GNU General Public License for more details. /
+// /
+// You should have received a copy of the GNU General Public License /
+// along with this program; if not, write to the Free Software Foundation, /
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
+// /
+// You can contact us via: support@intellectualsites.com /
+////////////////////////////////////////////////////////////////////////////////////////////////////
+package com.plotsquared.bukkit.util;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Chunk;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockState;
+
+import com.intellectualcrafters.jnbt.ByteArrayTag;
+import com.intellectualcrafters.jnbt.CompoundTag;
+import com.intellectualcrafters.jnbt.IntTag;
+import com.intellectualcrafters.jnbt.ListTag;
+import com.intellectualcrafters.jnbt.ShortTag;
+import com.intellectualcrafters.jnbt.StringTag;
+import com.intellectualcrafters.jnbt.Tag;
+import com.intellectualcrafters.plot.object.ChunkLoc;
+import com.intellectualcrafters.plot.object.Location;
+import com.intellectualcrafters.plot.object.RegionWrapper;
+import com.intellectualcrafters.plot.object.RunnableVal;
+import com.intellectualcrafters.plot.util.MainUtil;
+import com.intellectualcrafters.plot.util.SchematicHandler;
+import com.intellectualcrafters.plot.util.TaskManager;
+import com.plotsquared.bukkit.object.schematic.StateWrapper;
+
+/**
+ * Schematic Handler
+ *
+
+
+ */
+public class BukkitSchematicHandler extends SchematicHandler {
+
+ @Override
+ public void getCompoundTag(final String world, final Set regions, final RunnableVal whenDone) {
+ // async
+ TaskManager.runTaskAsync(new Runnable() {
+ @Override
+ public void run() {
+ // Main positions
+ Location[] corners = MainUtil.getCorners(world, regions);
+ final Location bot = corners[0];
+ final Location top = corners[1];
+
+ final int width = (top.getX() - bot.getX()) + 1;
+ final int height = (top.getY() - bot.getY()) + 1;
+ final int length = (top.getZ() - bot.getZ()) + 1;
+ // Main Schematic tag
+ final HashMap schematic = new HashMap<>();
+ schematic.put("Width", new ShortTag("Width", (short) width));
+ schematic.put("Length", new ShortTag("Length", (short) length));
+ schematic.put("Height", new ShortTag("Height", (short) height));
+ schematic.put("Materials", new StringTag("Materials", "Alpha"));
+ schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
+ schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
+ schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
+ schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
+ schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
+ schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
+ // Arrays of data types
+ final List tileEntities = new ArrayList<>();
+ final byte[] blocks = new byte[width * height * length];
+ final byte[] blockData = new byte[width * height * length];
+ // Queue
+ final ArrayDeque queue = new ArrayDeque<>(regions);
+ TaskManager.runTask(new Runnable() {
+ @Override
+ public void run() {
+ if (queue.isEmpty()) {
+ TaskManager.runTaskAsync(new Runnable() {
+ @Override
+ public void run() {
+ schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
+ schematic.put("Data", new ByteArrayTag("Data", blockData));
+ schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList()));
+ schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
+ whenDone.value = new CompoundTag("Schematic", schematic);
+ TaskManager.runTask(whenDone);
+ System.gc();
+ System.gc();
+ }
+ });
+ return;
+ }
+ final Runnable regionTask = this;
+ RegionWrapper region = queue.poll();
+ Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
+ Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
+ final int bx = bot.getX();
+ final int bz = bot.getZ();
+ final int p1x = pos1.getX();
+ final int p1z = pos1.getZ();
+ final int p2x = pos2.getX();
+ final int p2z = pos2.getZ();
+ final int bcx = p1x >> 4;
+ final int bcz = p1z >> 4;
+ final int tcx = p2x >> 4;
+ final int tcz = p2z >> 4;
+ final int sy = pos1.getY();
+ final int ey = pos2.getY();
+ // Generate list of chunks
+ final ArrayList chunks = new ArrayList<>();
+ for (int x = bcx; x <= tcx; x++) {
+ for (int z = bcz; z <= tcz; z++) {
+ chunks.add(new ChunkLoc(x, z));
+ }
+ }
+ final World worldObj = Bukkit.getWorld(world);
+ // Main thread
+ TaskManager.runTask(new Runnable() {
+ @Override
+ public void run() {
+ final long start = System.currentTimeMillis();
+ while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) {
+ // save schematics
+ final ChunkLoc chunk = chunks.remove(0);
+ final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
+ if (!bc.load(false)) {
+ continue;
+ }
+ final int X = chunk.x;
+ final int Z = chunk.z;
+ int xxb = X << 4;
+ int zzb = Z << 4;
+ int xxt = xxb + 15;
+ int zzt = zzb + 15;
+
+ if (X == bcx) {
+ xxb = p1x;
+ }
+ if (X == tcx) {
+ xxt = p2x;
+ }
+ if (Z == bcz) {
+ zzb = p1z;
+ }
+ if (Z == tcz) {
+ zzt = p2z;
+ }
+ for (int y = sy; y <= Math.min(255, ey); y++) {
+ final int ry = y - sy;
+ final int i1 = (ry * width * length);
+ for (int z = zzb; z <= zzt; z++) {
+ final int rz = z - bz;
+ final int i2 = i1 + (rz * width);
+ for (int x = xxb; x <= xxt; x++) {
+ final int rx = x - bx;
+ final int index = i2 + rx;
+ final Block block = worldObj.getBlockAt(x, y, z);
+ final int id = block.getTypeId();
+ switch (id) {
+ case 0:
+ case 2:
+ case 4:
+ case 13:
+ case 14:
+ case 15:
+ case 20:
+ case 21:
+ case 22:
+ case 24:
+ case 30:
+ case 32:
+ case 37:
+ case 39:
+ case 40:
+ case 41:
+ case 42:
+ case 45:
+ case 46:
+ case 47:
+ case 48:
+ case 49:
+ case 51:
+ case 55:
+ case 56:
+ case 57:
+ case 58:
+ case 60:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 73:
+ case 74:
+ case 78:
+ case 79:
+ case 80:
+ case 81:
+ case 82:
+ case 83:
+ case 85:
+ case 87:
+ case 88:
+ case 101:
+ case 102:
+ case 103:
+ case 110:
+ case 112:
+ case 113:
+ case 121:
+ case 122:
+ case 129:
+ case 133:
+ case 165:
+ case 166:
+ case 169:
+ case 170:
+ case 172:
+ case 173:
+ case 174:
+ case 181:
+ case 182:
+ case 188:
+ case 189:
+ case 190:
+ case 191:
+ case 192: {
+ break;
+ }
+ case 54:
+ case 130:
+ case 142:
+ case 27:
+ case 137:
+ case 52:
+ case 154:
+ case 84:
+ case 25:
+ case 144:
+ case 138:
+ case 176:
+ case 177:
+ case 63:
+ case 68:
+ case 323:
+ case 117:
+ case 116:
+ case 28:
+ case 66:
+ case 157:
+ case 61:
+ case 62:
+ case 140:
+ case 146:
+ case 149:
+ case 150:
+ case 158:
+ case 23:
+ case 123:
+ case 124:
+ case 29:
+ case 33:
+ case 151:
+ case 178: {
+ // TODO implement fully
+ final BlockState state = block.getState();
+ if (state != null) {
+ final StateWrapper wrapper = new StateWrapper(state);
+ final CompoundTag rawTag = wrapper.getTag();
+ if (rawTag != null) {
+ final Map values = new HashMap();
+ for (final Entry entry : rawTag.getValue().entrySet()) {
+ values.put(entry.getKey(), entry.getValue());
+ }
+ values.put("id", new StringTag("id", wrapper.getId()));
+ values.put("x", new IntTag("x", x));
+ values.put("y", new IntTag("y", y));
+ values.put("z", new IntTag("z", z));
+ final CompoundTag tileEntityTag = new CompoundTag(values);
+ tileEntities.add(tileEntityTag);
+ }
+ }
+ }
+ default: {
+ blockData[index] = block.getData();
+ }
+ }
+ // For optimization reasons, we are not supporting custom data types
+ // Especially since the most likely reason beyond this range is modded servers in which the blocks
+ // have NBT
+ // if (type > 255) {
+ // if (addBlocks == null) {
+ // addBlocks = new byte[(blocks.length >> 1) + 1];
+ // }
+ // addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
+ // (addBlocks[index >> 1] & 0xF0) | ((type >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((type
+ // >> 8) & 0xF) << 4));
+ // }
+ blocks[index] = (byte) id;
+ }
+ }
+ }
+ }
+ if (!chunks.isEmpty()) {
+ TaskManager.runTaskLater(this, 1);
+ } else {
+ regionTask.run();
+ }
+ }
+ });
+ }
+ });
+ }
+ });
+ }
+
+ @Override
+ public void restoreTag(CompoundTag ct, short x, short y, short z, Schematic schem) {
+ new StateWrapper(ct).restoreTag(x, y, z, schem);
+ }
+}
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/Metrics.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/Metrics.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/NbtFactory.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java
similarity index 100%
rename from src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java
diff --git a/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java
similarity index 97%
rename from src/main/java/com/plotsquared/bukkit/util/SendChunk.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java
index a244a3c6b..e499b1bba 100644
--- a/src/main/java/com/plotsquared/bukkit/util/SendChunk.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java
@@ -1,193 +1,193 @@
-package com.plotsquared.bukkit.util;
-
-import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
-
-import com.intellectualcrafters.plot.PS;
-import com.intellectualcrafters.plot.object.ChunkLoc;
-import com.intellectualcrafters.plot.object.Location;
-import com.intellectualcrafters.plot.object.Plot;
-import com.intellectualcrafters.plot.object.PlotPlayer;
-import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
-import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
-import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
-import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
-import com.intellectualcrafters.plot.util.TaskManager;
-import com.intellectualcrafters.plot.util.UUIDHandler;
-import com.plotsquared.bukkit.object.BukkitPlayer;
-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.List;
-import java.util.Map.Entry;
-
-/**
- * An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
- *
-
- */
-public class SendChunk {
-
- // // Ref Class
- private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
- private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
- private final RefClass classPacket = getRefClass("{nms}.Packet");
- private final RefClass classConnection = getRefClass("{nms}.PlayerConnection");
- private final RefClass classChunk = getRefClass("{nms}.Chunk");
- private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
- private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
- 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() {
- methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
- methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
- methodInitLighting = classChunk.getMethod("initLighting");
- MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
- connection = classEntityPlayer.getField("playerConnection");
- send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
- }
-
- public void sendChunk(final Collection input) {
- final HashSet chunks = new HashSet(input);
- final HashMap> map = new HashMap<>();
- final int view = Bukkit.getServer().getViewDistance();
- for (final Chunk chunk : chunks) {
- final String world = chunk.getWorld().getName();
- ArrayList list = map.get(world);
- if (list == null) {
- list = new ArrayList<>();
- map.put(world, list);
- }
- list.add(chunk);
- final Object c = methodGetHandleChunk.of(chunk).call();
- methodInitLighting.of(c).call();
- }
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer pp = entry.getValue();
- final Plot plot = pp.getCurrentPlot();
- Location loc = null;
- String world;
- if (plot != null) {
- world = plot.getArea().worldname;
- } else {
- loc = pp.getLocation();
- world = loc.getWorld();
- }
- final ArrayList list = map.get(world);
- if (list == null) {
- continue;
- }
- if (loc == null) {
- loc = pp.getLocation();
- }
- final int cx = loc.getX() >> 4;
- final int cz = loc.getZ() >> 4;
- final Player player = ((BukkitPlayer) pp).player;
- final Object entity = methodGetHandlePlayer.of(player).call();
-
- for (final Chunk chunk : list) {
- final int dx = Math.abs(cx - chunk.getX());
- final int dz = Math.abs(cz - chunk.getZ());
- if ((dx > view) || (dz > view)) {
- continue;
- }
- final Object c = methodGetHandleChunk.of(chunk).call();
- chunks.remove(chunk);
- final Object con = connection.of(entity).get();
- // if (dx != 0 || dz != 0) {
- // Object packet = MapChunk.create(c, true, 0);
- // send.of(con).call(packet);
- // }
- final Object packet = MapChunk.create(c, true, 65535);
- send.of(con).call(packet);
- }
- }
- for (final Chunk chunk : chunks) {
- TaskManager.runTask(new Runnable() {
- @Override
- public void run() {
- try {
- chunk.unload(true, false);
- } catch (final Throwable e) {
- final String worldname = chunk.getWorld().getName();
- PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
- PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
- PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname
- + "/level_old.dat may be corrupt (try repairing or removing these)");
- }
- }
- });
- }
- //
- //
- // int diffx, diffz;
- // << 4;
- // for (final Chunk chunk : chunks) {
- // if (!chunk.isLoaded()) {
- // continue;
- // }
- // boolean unload = true;
- // final Object c = methodGetHandle.of(chunk).call();
- // final Object w = world.of(c).get();
- // final Object p = players.of(w).get();
- // for (final Object ep : (List