diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 0151f0af6..00c2721eb 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -6,7 +6,7 @@ com.intellectualcrafters PlotSquared - 2.4.0 + 2.4.1 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index a6c21a44b..84c234e1b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -902,7 +902,6 @@ import java.util.concurrent.TimeUnit; * * @param plotworld World to create the section for */ - @SuppressWarnings("unused") public static void createConfiguration(final PlotWorld plotworld) { final Map options = new HashMap<>(); @@ -930,7 +929,6 @@ import java.util.concurrent.TimeUnit; final Set worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet()); - // Let's create these here instead final PlotWorld plotWorld; final PlotGenerator plotGenerator; final PlotManager plotManager; @@ -948,7 +946,7 @@ import java.util.concurrent.TimeUnit; if (!config.contains(path)) { config.createSection(path); } - + plotWorld.saveConfiguration(config.getConfigurationSection(path)); plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index a4908a720..7c43ffb1b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -125,9 +125,9 @@ import org.bukkit.entity.Player; return false; } final int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr); - if ((diff + (size_x * size_z)) >= 0) { + if ((diff + (size_x * size_z)) > 0) { if (diff < 0) { - PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff - 1) + ""); + PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + ""); } else { PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index e6555b0de..8ad5f5517 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -28,10 +28,12 @@ import com.intellectualcrafters.plot.generator.DefaultPlotWorld; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.generator.ChunkGenerator; @@ -75,7 +77,8 @@ public class Setup extends SubCommand implements Listener { } try { PlotMain.config.save(PlotMain.configFile); - } catch (final IOException e) { + PlotMain.config.load(PlotMain.configFile); + } catch (final IOException | InvalidConfigurationException e) { e.printStackTrace(); } @@ -104,6 +107,12 @@ public class Setup extends SubCommand implements Listener { } } } + } + try { + plr.teleport(Bukkit.getWorld(world).getSpawnLocation()); + } + catch (Exception e) { + } sendMessage(plr, C.SETUP_FINISHED, object.world); @@ -196,6 +205,7 @@ public class Setup extends SubCommand implements Listener { } else { plotworld = new DefaultPlotWorld(world); } + PlotMain.removePlotWorld(world); setupMap.put(plrname, new SetupObject(world, plotworld, args[1])); sendMessage(plr, C.SETUP_INIT); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java index 3af8368d5..098b2f540 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java @@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.config; import com.intellectualcrafters.plot.object.PlotBlock; + import org.bukkit.block.Biome; import java.util.ArrayList; @@ -165,7 +166,7 @@ import java.util.List; @Override public Object parseObject(final Object object) { - return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data; + return object; } }; public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { @@ -235,11 +236,7 @@ import java.util.List; @Override public Object parseObject(final Object object) { - final List list = new ArrayList<>(); - for (final PlotBlock block : (PlotBlock[]) object) { - list.add((block.id + ":" + (block.data))); - } - return list; + return object; } }; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java index 0f79f2d0e..b35da4ff9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java @@ -22,9 +22,13 @@ package com.intellectualcrafters.plot.config; import com.intellectualcrafters.plot.config.Configuration.SettingValue; +import com.intellectualcrafters.plot.object.PlotBlock; + import org.apache.commons.lang.StringUtils; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; /** * Configuration Node @@ -71,6 +75,16 @@ public class ConfigurationNode { if (this.value instanceof String[]) { return Arrays.asList((String[]) this.value); } + else if (this.value instanceof Object[]) { + List values = new ArrayList(); + for (Object value : (Object[]) this.value) { + values.add(value.toString()); + } + return values; + } + else if (this.value instanceof PlotBlock) { + return this.value.toString(); + } return this.value; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java index 0c0e08b91..285899848 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java @@ -159,12 +159,11 @@ public class DefaultPlotWorld extends PlotWorld { */ @Override public void loadConfiguration(final ConfigurationSection config) { - this.PLOT_HEIGHT = config.getInt("plot.height"); - if (!config.contains("plot.height")) { PlotMain.sendConsoleSenderMessage(" - &cConfiguration is null? (" + config.getCurrentPath() + ")"); } - + + this.PLOT_HEIGHT = config.getInt("plot.height"); this.PLOT_WIDTH = config.getInt("plot.size"); this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.filling"), ',')); this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.floor"), ',')); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java index 688a9bbaa..bbee29d29 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java @@ -86,7 +86,6 @@ public class WorldGenerator extends PlotGenerator { if (this.plotworld == null) { this.plotworld = (DefaultPlotWorld) PlotMain.getWorldSettings(world); } - this.plotsize = this.plotworld.PLOT_WIDTH; this.pathsize = this.plotworld.ROAD_WIDTH; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java index e3ebf549b..fc19d12b7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -23,6 +23,8 @@ package com.intellectualcrafters.plot.listeners; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; +import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent; +import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent; import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.events.PlotMergeEvent; import com.intellectualcrafters.plot.events.PlotUnlinkEvent; @@ -37,6 +39,7 @@ import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -69,29 +72,15 @@ public class WorldGuardListener implements Listener { this.flags.add(flag); } } - + public void changeOwner(final Player requester, final UUID owner, final World world, final Plot plot) { - // boolean op = requester.isOp(); - // requester.setOp(true); - - // 10 ticks should be enough - final PermissionAttachment add = requester.addAttachment(PlotMain.getMain(), 10); - add.setPermission("worldguard.region.addowner.own.*", true); - - final PermissionAttachment remove = requester.addAttachment(PlotMain.getMain(), 10); - remove.setPermission("worldguard.region.removeowner.own.*", true); - try { - final RegionManager manager = PlotMain.worldGuard.getRegionManager(world); - manager.getRegion(plot.id.x + "-" + plot.id.y); - requester.performCommand("region setowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(owner)); - requester.performCommand("region removeowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(plot.getOwner())); + final RegionManager manager = PlotMain.worldGuard.getRegionManager(world); + ProtectedRegion region = manager.getRegion(plot.id.x + "-" + plot.id.y); + DefaultDomain owners = new DefaultDomain(); + owners.addPlayer(UUIDHandler.getName(owner)); + region.setOwners(owners); } catch (final Exception e) { - // requester.setOp(op); - - } finally { - add.remove(); - remove.remove(); } } @@ -131,7 +120,6 @@ public class WorldGuardListener implements Listener { } } - @SuppressWarnings("unused") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onMerge(final PlotMergeEvent event) { final Plot main = event.getPlot(); @@ -165,7 +153,6 @@ public class WorldGuardListener implements Listener { manager.addRegion(rg); } - @SuppressWarnings("unused") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onUnlink(final PlotUnlinkEvent event) { try { @@ -199,11 +186,9 @@ public class WorldGuardListener implements Listener { manager.addRegion(rg); } } catch (final Exception e) { - // } } - @SuppressWarnings("unused") @EventHandler public void onPlotClaim(final PlayerClaimPlotEvent event) { try { @@ -226,11 +211,9 @@ public class WorldGuardListener implements Listener { manager.addRegion(region); } catch (final Exception e) { - // } } - @SuppressWarnings("unused") @EventHandler public void onPlotDelete(final PlotDeleteEvent event) { try { @@ -240,7 +223,49 @@ public class WorldGuardListener implements Listener { final RegionManager manager = PlotMain.worldGuard.getRegionManager(world); manager.removeRegion(plot.x + "-" + plot.y); } catch (final Exception e) { - // + } + } + + public void addUser(final Player requester, final UUID user, final World world, final Plot plot) { + final RegionManager manager = PlotMain.worldGuard.getRegionManager(world); + ProtectedRegion region = manager.getRegion(plot.id.x + "-" + plot.id.y); + DefaultDomain members = region.getMembers(); + members.addPlayer(UUIDHandler.getName(user)); + region.setMembers(members); + } + + public void removeUser(final Player requester, final UUID user, final World world, final Plot plot) { + final RegionManager manager = PlotMain.worldGuard.getRegionManager(world); + ProtectedRegion region = manager.getRegion(plot.id.x + "-" + plot.id.y); + DefaultDomain members = region.getMembers(); + members.removePlayer(UUIDHandler.getName(user)); + region.setMembers(members); + } + + @EventHandler + public void onPlotHelper(final PlayerPlotHelperEvent event) { + if (event.wasAdded()) { + addUser(event.getInitiator(), event.getPlayer(), event.getInitiator().getWorld(), event.getPlot()); + } + else { + removeUser(event.getInitiator(), event.getPlayer(), event.getInitiator().getWorld(), event.getPlot()); + } + } + + @EventHandler + public void onPlotTrusted(final PlayerPlotTrustedEvent event) { + if (event.wasAdded()) { + addUser(event.getInitiator(), event.getPlayer(), event.getInitiator().getWorld(), event.getPlot()); + } + else { + removeUser(event.getInitiator(), event.getPlayer(), event.getInitiator().getWorld(), event.getPlot()); + } + } + + @EventHandler + public void onPlotDenied(final PlayerPlotTrustedEvent event) { + if (event.wasAdded()) { + removeUser(event.getInitiator(), event.getPlayer(), event.getInitiator().getWorld(), event.getPlot()); } } }