From dc22514809d2777d660426d9c83333181843730b Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sat, 16 Jan 2016 13:14:18 +0100 Subject: [PATCH] Implements #752 and gives credits to manuelgu :) --- .../plot/commands/MainCommand.java | 1 + .../plot/commands/Middle.java | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/com/intellectualcrafters/plot/commands/Middle.java diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index fc3f27849..e7973c086 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -128,6 +128,7 @@ public class MainCommand extends CommandManager { createCommand(new Done()); createCommand(new Continue()); createCommand(new BO3()); + createCommand(new Middle()); // set commands createCommand(new Owner()); createCommand(new Desc()); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Middle.java b/src/main/java/com/intellectualcrafters/plot/commands/Middle.java new file mode 100644 index 000000000..5c17eda5f --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/commands/Middle.java @@ -0,0 +1,48 @@ +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.MainUtil; +import com.plotsquared.general.commands.CommandDeclaration; + +/** + * Legally stolen from https://github.com/manuelgu/PlotSquaredMiddle + * + * @author manuelgu, altered by Citymonstret + */ +@CommandDeclaration( + command = "middle", + aliases = { "center" }, + description = "Teleports you to the center of the current plot", + usage = "/plot middle", + category = CommandCategory.TELEPORT, + requiredType = RequiredType.PLAYER +) +public class Middle extends SubCommand { + + @Override + public boolean onCommand(PlotPlayer player, String[] arguments) { + final Location location = player.getLocation(); + final Plot plot = MainUtil.getPlotAbs(location); + if (plot == null) { + return sendMessage(player, C.NOT_IN_PLOT); + } + if (!plot.hasOwner()) { + return sendMessage(player, C.PLOT_UNOWNED); + } + if (!player.hasPermission("plots.middle")) { + return sendMessage(player, C.NO_PERMISSION, "plots.middle"); + } + + RegionWrapper largestRegion = MainUtil.getLargestRegion(plot); + final int x = ((largestRegion.maxX - largestRegion.minX) / 2) + largestRegion.minX; + final int z = ((largestRegion.maxZ - largestRegion.minZ) / 2) + largestRegion.minZ; + final int y = MainUtil.getHeighestBlock(plot.getWorld().worldname, x, z) + 1; + + player.teleport(new Location(plot.getWorld().worldname, x, y, z)); + return true; + } +}