From a43cf8833c48a4eccc798563e3c853f874e4b2a6 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 28 Feb 2015 11:55:52 +1100 Subject: [PATCH] Fixed plot merging and made some optimizations to move events and plot lookups --- .../plot/generator/SquarePlotManager.java | 79 +++++++++++-------- .../plot/listeners/ForceFieldListener.java | 7 +- .../plot/listeners/PlayerEvents.java | 20 ----- 3 files changed, 47 insertions(+), 59 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index a528b29e1..b076e505f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -34,39 +34,39 @@ public abstract class SquarePlotManager extends GridPlotManager { @Override public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, final int y, int z) { final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); - // get plot size - final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; - // get size of path on bottom part, and top part of plot - // (As 0,0 is in the middle of a road, not the very start) int pathWidthLower; if ((dpw.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1); + pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; } else { - pathWidthLower = (int) Math.floor(dpw.ROAD_WIDTH / 2); + pathWidthLower = dpw.ROAD_WIDTH / 2; } - // calulating how many shifts need to be done - int dx = x / size; - int dz = z / size; + final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; + int idx; + int idz; + if (x < 0) { - dx--; - x += ((-dx) * size); + idx = (x/size); + x = size + (x % size); + } + else { + idx = (x/size) + 1; + x = (x % size); } if (z < 0) { - dz--; - z += ((-dz) * size); + idz = (z/size); + z = size + (z % size); + } + else { + idz = (z/size) + 1; + z = (z % size); } - // reducing to first plot - final int rx = (x) % size; - final int rz = (z) % size; - // checking if road (return null if so) final int end = pathWidthLower + dpw.PLOT_WIDTH; - final boolean northSouth = (rz <= pathWidthLower) || (rz > end); - final boolean eastWest = (rx <= pathWidthLower) || (rx > end); + final boolean northSouth = (z <= pathWidthLower) || (z > end); + final boolean eastWest = (x <= pathWidthLower) || (x > end); if (northSouth || eastWest) { return null; } - // returning the plot id (based on the number of shifts required) - return new PlotId(dx + 1, dz + 1); + return new PlotId(idx, idz); } @Override @@ -78,28 +78,37 @@ public abstract class SquarePlotManager extends GridPlotManager { final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; int pathWidthLower; if ((dpw.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1); + pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; } else { - pathWidthLower = (int) Math.floor(dpw.ROAD_WIDTH / 2); + pathWidthLower = dpw.ROAD_WIDTH / 2; } - int dx = x / size; - int dz = z / size; + int dx; + int dz; + int rx; + int rz; + if (x < 0) { - dx--; - x += ((-dx) * size); + dx = (x/size); + rx = size + (x % size); + } + else { + dx = (x/size) + 1; + rx = (x % size); } if (z < 0) { - dz--; - z += ((-dz) * size); + dz = (z/size); + rz = size + (z % size); + } + else { + dz = (z/size) + 1; + rz = (z % size); } - final int rx = (x) % size; - final int rz = (z) % size; final int end = pathWidthLower + dpw.PLOT_WIDTH; final boolean northSouth = (rz <= pathWidthLower) || (rz > end); final boolean eastWest = (rx <= pathWidthLower) || (rx > end); if (northSouth && eastWest) { // This means you are in the intersection - final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z + dpw.ROAD_WIDTH); + final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, 0, z + dpw.ROAD_WIDTH); final PlotId id = MainUtil.getPlotAbs(loc); final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { @@ -112,7 +121,7 @@ public abstract class SquarePlotManager extends GridPlotManager { } if (northSouth) { // You are on a road running West to East (yeah, I named the var poorly) - final Location loc = new Location(plotworld.worldname, x, y, z + dpw.ROAD_WIDTH); + final Location loc = new Location(plotworld.worldname, x, 0, z + dpw.ROAD_WIDTH); final PlotId id = MainUtil.getPlotAbs(loc); final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { @@ -125,7 +134,7 @@ public abstract class SquarePlotManager extends GridPlotManager { } if (eastWest) { // This is the road separating an Eastern and Western plot - final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z); + final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, 0, z); final PlotId id = MainUtil.getPlotAbs(loc); final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { @@ -136,7 +145,7 @@ public abstract class SquarePlotManager extends GridPlotManager { } return null; } - final PlotId id = new PlotId(dx + 1, dz + 1); + final PlotId id = new PlotId(dx, dz); final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { return id; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java index ce3278a4b..1c1ca51e0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java @@ -28,14 +28,13 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; +import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -97,11 +96,11 @@ public class ForceFieldListener implements Listener { } @EventHandler - public void onPlotEntry(final PlayerMoveEvent event) { + public void onPlotEntry(final PlayerEnterPlotEvent event) { final Player player = event.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(player); final Location loc = pp.getLocation(); - final Plot plot = MainUtil.getPlot(loc); + final Plot plot = event.getPlot(); if (plot == null) { return; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index af4f774f1..17ebf1b57 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -1,23 +1,3 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 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.listeners; import java.util.Collection;