From 30f1f829cb9a0a68d71c7bbf87ae46826279b53b Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 7 Oct 2014 22:34:57 +1100 Subject: [PATCH] further bug fixes --- .../com/intellectualcrafters/plot/PWE.java | 7 ++--- .../plot/PlayerFunctions.java | 5 ++-- .../com/intellectualcrafters/plot/Plot.java | 1 + .../intellectualcrafters/plot/PlotHelper.java | 1 - .../intellectualcrafters/plot/PlotMain.java | 9 +++++- .../plot/commands/Home.java | 6 ++-- .../plot/commands/Set.java | 2 +- .../plot/database/DBFunc.java | 20 ++++++++++--- .../plot/listeners/PlayerEvents.java | 29 +++++++++++++++---- .../plot/listeners/WorldEditListener.java | 2 +- 10 files changed, 58 insertions(+), 24 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PWE.java b/PlotSquared/src/com/intellectualcrafters/plot/PWE.java index fe3789d37..5ad94b742 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PWE.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PWE.java @@ -19,7 +19,6 @@ import com.sk89q.worldedit.regions.CuboidRegion; */ public class PWE { - @SuppressWarnings("unused") public static void setMask(Player p, Location l) { try { LocalSession s; @@ -37,7 +36,7 @@ public class PWE { r = (plot.getOwner() != null) && plot.getOwner().equals(p.getUniqueId()); if (!r) { - if (p.hasPermission("plots.worldedit.member") && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { + if ((plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { r = true; } else if (p.hasPermission("plots.worldedit.bypass")) { removeMask(p, s); @@ -70,7 +69,7 @@ public class PWE { s.setMask(new com.sk89q.worldedit.masks.RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); } } catch (Exception e) { - throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); +// throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); } } @@ -102,7 +101,7 @@ public class PWE { } removeMask(p, s); } catch (Exception e) { - throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); +// throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); } } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index a22a0b9ab..49f81e9ef 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -122,7 +122,7 @@ public class PlayerFunctions { int rz = (z) % size; int end = pathWidthLower + plotworld.PLOT_WIDTH; - boolean northSouth = (rz <= pathWidthLower) || (rz > (pathWidthLower + plotworld.PLOT_WIDTH)); + boolean northSouth = (rz <= pathWidthLower) || (rz > end); boolean eastWest = (rx <= pathWidthLower) || (rx > end); if (northSouth || eastWest) { @@ -165,9 +165,8 @@ public class PlayerFunctions { int end = pathWidthLower + plotworld.PLOT_WIDTH; - boolean northSouth = (rz <= pathWidthLower) || (rz > (pathWidthLower + plotworld.PLOT_WIDTH)); + boolean northSouth = (rz <= pathWidthLower) || (rz > end); boolean eastWest = (rx <= pathWidthLower) || (rx > end); - if (northSouth && eastWest) { // This means you are in the intersection PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, plotworld.ROAD_WIDTH)); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index beeb81be1..2d19fb0ef 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -86,6 +86,7 @@ public class Plot implements Cloneable { this.deny_entry = this.owner == null; this.helpers = helpers; this.denied = denied; + this.trusted = new ArrayList(); this.settings.setTime(8000l); this.settings.setRain(false); this.settings.setTimeChange(false); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index 8907d2954..2f1cdaf18 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -421,7 +421,6 @@ public class PlotHelper { } public static boolean createPlot(Player player, Plot plot) { - @SuppressWarnings("deprecation") World w = plot.getWorld(); Plot p = new Plot(plot.id, player.getUniqueId(), plot.settings.getBiome(), new ArrayList(), new ArrayList(), w.getName()); PlotMain.updatePlot(p); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 9a750a0ba..3da561b15 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -353,6 +353,7 @@ public class PlotMain extends JavaPlugin { * @return */ public static Set getPlots(World world, Player player) { + int i = 0; UUID uuid = player.getUniqueId(); ArrayList myplots = new ArrayList(); for (Plot plot : getPlots(world).values()) { @@ -1093,7 +1094,13 @@ public class PlotMain extends JavaPlugin { if (world == null) { return; } - Set worlds = config.getConfigurationSection("worlds").getKeys(false); + Set worlds; + if (config.contains("worlds")) { + worlds = config.getConfigurationSection("worlds").getKeys(false); + } + else { + worlds = new HashSet(); + } if (worlds.contains(world.getName())) { ChunkGenerator gen = world.getGenerator(); if ((gen == null) || !gen.getClass().getSimpleName().equals("PlotSquaredGen")) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java index f95a23fb7..290e944fe 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java @@ -9,6 +9,8 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; + import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; @@ -44,14 +46,12 @@ public class Home extends SubCommand { return true; } else if (plots.length > 1) { if (args.length < 1) { - PlayerFunctions.sendMessage(plr, C.NEED_PLOT_NUMBER); - return true; + args = new String[] {"1"}; } int id = 0; try { id = Integer.parseInt(args[0]); } catch (Exception e) { - Plot temp; if ((temp = isAlias(args[0])) != null) { if (temp.hasOwner()) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index bed151b16..e382596d4 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -75,7 +75,7 @@ public class Set extends SubCommand { } } /* TODO: Implement option */ - boolean advanced_permissions = false; + boolean advanced_permissions = true; if (advanced_permissions) { if (!plr.hasPermission("plots.set." + args[0].toLowerCase())) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 17e9742b0..7ce481684 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -18,6 +18,8 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import org.bukkit.Bukkit; @@ -366,9 +368,14 @@ public class DBFunc { e.printStackTrace(); } HashMap> plots = new HashMap>(); - new HashMap(); Statement stmt = null; try { + + Set worlds = new HashSet(); + if (PlotMain.config.contains("worlds")) { + worlds = PlotMain.config.getConfigurationSection("worlds").getKeys(false); + } + stmt = connection.createStatement(); ResultSet r = stmt.executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world` FROM `plot`"); PlotId plot_id; @@ -441,9 +448,14 @@ public class DBFunc { if (plots.containsKey(worldname)) { plots.get(worldname).put((plot_id), p); } else { - HashMap map = new HashMap(); - map.put((plot_id), p); - plots.put(worldname, map); + if (worlds.contains(p.world)) { + HashMap map = new HashMap(); + map.put((plot_id), p); + plots.put(worldname, map); + } + else { + PlotMain.sendConsoleSenderMessage("&cPlot '"+p.id+"' in DB for world '"+p.world+"' does not exist! Please create this world, or remove the plots from the DB!"); + } } } stmt.close(); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java index e90e4596c..68db79abe 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -65,6 +65,7 @@ import org.bukkit.event.world.WorldLoadEvent; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; @@ -90,11 +91,27 @@ public class PlayerEvents implements Listener { } public boolean enteredPlot(Location l1, Location l2) { - return !isInPlot(l1) && isInPlot(l2); + PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(),l1.getBlockX(),64,l1.getBlockZ())); + PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(),l2.getBlockX(),64,l2.getBlockZ())); + if (p2==null) + return false; + if (p1==null) + return true; + if (p1.equals(p2)) + return false; + return true; } public boolean leftPlot(Location l1, Location l2) { - return isInPlot(l1) && !isInPlot(l2); + PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(),l1.getBlockX(),64,l1.getBlockZ())); + PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(),l2.getBlockX(),64,l2.getBlockZ())); + if (p1==null) + return false; + if (p2==null) + return true; + if (p1.equals(p2)) + return false; + return true; } private boolean isPlotWorld(Location l) { @@ -149,7 +166,7 @@ public class PlayerEvents implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void PlayerMove(PlayerMoveEvent event) { try { Player player = event.getPlayer(); @@ -159,7 +176,7 @@ public class PlayerEvents implements Listener { if (!isPlotWorld(player.getWorld())) { return; } - if (enteredPlot(event.getFrom(), event.getTo())) { + if (enteredPlot(from,to)) { Plot plot = getCurrentPlot(event.getTo()); if (plot.hasOwner()) { if (C.TITLE_ENTERED_PLOT.s().length() > 2) { @@ -501,7 +518,7 @@ public class PlayerEvents implements Listener { if (!isPlotWorld(world)) { return; } - if ((event.getSpawnReason() != SpawnReason.SPAWNER_EGG) || !isInPlot(event.getLocation())) { + if (!isInPlot(event.getLocation())) { event.setCancelled(true); } } @@ -611,7 +628,7 @@ public class PlayerEvents implements Listener { Block b = e.getBlock(); if (isPlotWorld(b.getLocation())) { Player p = e.getPlayer(); - if (isInPlot(b.getLocation())) { + if (!isInPlot(b.getLocation())) { if (!p.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION); e.setCancelled(true); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java index 398d21e78..e5ef8b734 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -98,7 +98,7 @@ public class WorldEditListener implements Listener { } } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(final PlayerMoveEvent e) { Location t = e.getTo(); if (!isPlotWorld(t)) {