From 4aeb5f459f317676bbe64a023951e420a1267515 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 20 Feb 2015 22:37:34 +1100 Subject: [PATCH] more stuff --- .../intellectualcrafters/plot/BukkitMain.java | 5 +- .../plot/generator/SquarePlotManager.java | 67 ++++++++++--------- .../util/bukkit/BukkitPlayerFunctions.java | 13 ++++ 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 9a218daab..e93ae098f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -10,6 +10,7 @@ import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.listeners.*; +import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -19,7 +20,9 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.*; import com.sk89q.worldedit.bukkit.WorldEditPlugin; + import net.milkbowl.vault.economy.Economy; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -76,7 +79,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { if (Settings.USE_PLOTME_ALIAS) { player.performCommand(message.replace("/plotme", "plots")); } else { - BukkitPlayerFunctions.sendMessage(player, C.NOT_USING_PLOTME); + MainUtil.sendMessage(new BukkitPlayer(player), C.NOT_USING_PLOTME); } event.setCancelled(true); } 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 a46acd270..610fbcf67 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -1,28 +1,29 @@ package com.intellectualcrafters.plot.generator; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.AChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.ChunkManager; -import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; +import com.intellectualcrafters.plot.util.bukkit.MainUtil; /** * A plot manager with a square grid layout, with square shaped plots */ public abstract class SquarePlotManager extends GridPlotManager { @Override - public boolean clearPlot(final World world, final PlotWorld plotworld, final Plot plot, final boolean isDelete, final Runnable whendone) { - final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1); - final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); - ChunkManager.regenerateRegion(pos1, pos2, whendone); + public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final boolean isDelete, final Runnable whenDone) { + final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id); + AChunkManager.manager.regenerateRegion(pos1, pos2, whenDone); return true; } @@ -33,15 +34,12 @@ public abstract class SquarePlotManager extends GridPlotManager { final int pz = plotid.y; final int x = (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; final int z = (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; - return new Location(Bukkit.getWorld(plotworld.worldname), x, 256, z); + return new Location(plotworld.worldname, x, 256, z); } @Override - public PlotId getPlotIdAbs(final PlotWorld plotworld, final Location loc) { + public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, int y, int z) { final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); - // get x,z loc - int x = loc.getBlockX(); - int z = loc.getBlockZ(); // get plot size final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; // get size of path on bottom part, and top part of plot @@ -78,10 +76,8 @@ public abstract class SquarePlotManager extends GridPlotManager { } @Override - public PlotId getPlotId(final PlotWorld plotworld, final Location loc) { + public PlotId getPlotId(final PlotWorld plotworld, int x, int y, int z) { final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); - int x = loc.getBlockX(); - int z = loc.getBlockZ(); if (plotworld == null) { return null; } @@ -109,47 +105,49 @@ public abstract class SquarePlotManager extends GridPlotManager { final boolean eastWest = (rx <= pathWidthLower) || (rx > end); if (northSouth && eastWest) { // This means you are in the intersection - final PlotId id = BukkitPlayerFunctions.getPlotAbs(loc.add(dpw.ROAD_WIDTH, 0, dpw.ROAD_WIDTH)); - final Plot plot = PlotSquared.getPlots(loc.getWorld()).get(id); + Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z + dpw.ROAD_WIDTH); + final PlotId id = MainUtil.getPlotAbs(loc); + final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { return null; } if ((plot.settings.getMerged(0) && plot.settings.getMerged(3))) { - return BukkitPlayerFunctions.getBottomPlot(loc.getWorld(), plot).id; + return MainUtil.getBottomPlot(plot).id; } return null; } if (northSouth) { - // You are on a road running West to East (yeah, I named the var - // poorly) - final PlotId id = BukkitPlayerFunctions.getPlotAbs(loc.add(0, 0, dpw.ROAD_WIDTH)); - final Plot plot = PlotSquared.getPlots(loc.getWorld()).get(id); + // You are on a road running West to East (yeah, I named the var poorly) + Location loc = new Location(plotworld.worldname, x, y, z + dpw.ROAD_WIDTH); + final PlotId id = MainUtil.getPlotAbs(loc); + final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { return null; } if (plot.settings.getMerged(0)) { - return BukkitPlayerFunctions.getBottomPlot(loc.getWorld(), plot).id; + return MainUtil.getBottomPlot(plot).id; } return null; } if (eastWest) { // This is the road separating an Eastern and Western plot - final PlotId id = BukkitPlayerFunctions.getPlotAbs(loc.add(dpw.ROAD_WIDTH, 0, 0)); - final Plot plot = PlotSquared.getPlots(loc.getWorld()).get(id); + Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z); + final PlotId id = MainUtil.getPlotAbs(loc); + final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { return null; } if (plot.settings.getMerged(3)) { - return BukkitPlayerFunctions.getBottomPlot(loc.getWorld(), plot).id; + return MainUtil.getBottomPlot(plot).id; } return null; } final PlotId id = new PlotId(dx + 1, dz + 1); - final Plot plot = PlotSquared.getPlots(loc.getWorld()).get(id); + final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); if (plot == null) { return id; } - return BukkitPlayerFunctions.getBottomPlot(loc.getWorld(), plot).id; + return MainUtil.getBottomPlot(plot).id; } /** @@ -162,20 +160,23 @@ public abstract class SquarePlotManager extends GridPlotManager { final int pz = plotid.y; final int x = (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; final int z = (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; - return new Location(Bukkit.getWorld(plotworld.worldname), x, 1, z); + return new Location(plotworld.worldname, x, 1, z); } /** * Set a plot biome */ @Override - public boolean setBiome(final World world, final Plot plot, final Biome biome) { - final int bottomX = MainUtil.getPlotBottomLoc(world, plot.id).getBlockX() - 1; - final int topX = MainUtil.getPlotTopLoc(world, plot.id).getBlockX() + 1; - final int bottomZ = MainUtil.getPlotBottomLoc(world, plot.id).getBlockZ() - 1; - final int topZ = MainUtil.getPlotTopLoc(world, plot.id).getBlockZ() + 1; + public boolean setBiome(final String world, final Plot plot, final Biome biome) { + final int bottomX = MainUtil.getPlotBottomLoc(world, plot.id).getX() - 1; + final int topX = MainUtil.getPlotTopLoc(world, plot.id).getX() + 1; + final int bottomZ = MainUtil.getPlotBottomLoc(world, plot.id).getZ() - 1; + final int topZ = MainUtil.getPlotTopLoc(world, plot.id).getZ() + 1; final Block block = world.getBlockAt(MainUtil.getPlotBottomLoc(world, plot.id).add(1, 1, 1)); final Biome current = block.getBiome(); + + + if (biome.equals(current)) { return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java index b59e39b85..c18c41b31 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java @@ -48,6 +48,19 @@ import java.util.UUID; * Functions involving players, plots and locations. */ public class BukkitPlayerFunctions { + + /* + * =========== NOTICE ================ + * - We will try to move as many functions as we can out of this class and into the MainUtil class + */ + + + + + + + + /** * Clear a plot. Use null player if no player is present * @param player