From 5b3a2d58b4ccad9dc536f065925460c845f7ea7a Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Wed, 11 Feb 2015 14:54:31 +0100 Subject: [PATCH] -- Some minor changed && Prep. for porting * Added prefix for "greeting" & "farewell" flags * Added custom location class * Added "all" category (/plot help) --- .../plot/commands/MainCommand.java | 27 +-- .../intellectualcrafters/plot/config/C.java | 11 +- .../plot/listeners/PlotPlusListener.java | 34 ++-- .../plot/object/Location.java | 159 ++++++++++++++++++ 4 files changed, 191 insertions(+), 40 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Location.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 0e0ccb1c1..ce4a707c9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -21,10 +21,10 @@ package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.StringComparison; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -32,10 +32,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.StringComparison; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * PlotMain command class @@ -75,7 +74,12 @@ public class MainCommand implements CommandExecutor, TabCompleter { } public static List helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { - final List commands = getCommands(category, player); + List commands; + if (category != null) { + commands = getCommands(category, player); + } else { + commands = subCommands; + } // final int totalPages = ((int) Math.ceil(12 * (commands.size()) / // 100)); final int perPage = 5; @@ -92,7 +96,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { help.add(C.HELP_HEADER.s()); // HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"), - help.add(C.HELP_CATEGORY.s().replace("%category%", category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages + 1)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size())); + help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages + 1)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size())); SubCommand cmd; @@ -128,6 +132,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString())); } + builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands")); return PlayerFunctions.sendMessage(player, builder.toString()); } final String cat = args[1]; @@ -138,7 +143,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { break; } } - if (cato == null) { + if (cato == null && !cat.equalsIgnoreCase("all")) { final StringBuilder builder = new StringBuilder(); builder.append(C.HELP_INFO.s()); for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 08099f3de..c6dfb7a5f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -21,15 +21,10 @@ package com.intellectualcrafters.plot.config; -import org.bukkit.ChatColor; - import com.intellectualcrafters.plot.PlotMain; -import com.intellectualsites.translation.TranslationFile; -import com.intellectualsites.translation.TranslationLanguage; -import com.intellectualsites.translation.TranslationManager; -import com.intellectualsites.translation.TranslationObject; -import com.intellectualsites.translation.YamlTranslationFile; +import com.intellectualsites.translation.*; import com.intellectualsites.translation.bukkit.BukkitTranslation; +import org.bukkit.ChatColor; /** * Captions class. @@ -158,6 +153,8 @@ public enum C { TITLE_LEFT_PLOT_COLOR("GOLD"), TITLE_LEFT_PLOT_SUB("Owned by %s"), TITLE_LEFT_PLOT_SUB_COLOR("RED"), + PREFIX_GREETING("&6%id%&c> "), + PREFIX_FAREWELL("&c%id%&c> "), /* * Core Stuff */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index 99805f3fd..5d60164a8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -21,18 +21,15 @@ package com.intellectualcrafters.plot.listeners; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Effect; -import org.bukkit.GameMode; -import org.bukkit.Material; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; +import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.UUIDHandler; +import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -46,14 +43,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; -import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import java.util.*; /** * Created 2014-10-30 for PlotSquared @@ -183,7 +173,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler; public void onPlotEnter(final PlayerEnterPlotEvent event) { final Plot plot = event.getPlot(); if (FlagManager.getPlotFlag(plot, "greeting") != null) { - event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FlagManager.getPlotFlag(plot, "greeting").getValueString())); + event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_GREETING.s() + FlagManager.getPlotFlag(plot, "greeting").getValueString())); } if (booleanFlag(plot, "notify-enter", false)) { if (plot.hasOwner()) { @@ -220,7 +210,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler; event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.RECORD_PLAY, 0); final Plot plot = event.getPlot(); if (FlagManager.getPlotFlag(plot, "farewell") != null) { - event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FlagManager.getPlotFlag(plot, "farewell").getValueString())); + event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s() + FlagManager.getPlotFlag(plot, "farewell").getValueString())); } if (feedRunnable.containsKey(event.getPlayer().getName())) { feedRunnable.remove(event.getPlayer().getName()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Location.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Location.java new file mode 100644 index 000000000..25797f6ad --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Location.java @@ -0,0 +1,159 @@ +package com.intellectualcrafters.plot.object; + +/** + * Created 2015-02-11 for PlotSquared + * + * @author Citymonstret + */ +public class Location implements Cloneable, Comparable { + + private double x, y, z; + private float yaw, pitch; + private String world; + + public Location(final String world, final double x, final double y, final double z, final float yaw, final float pitch) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + public Location() { + this("", 0d, 0d, 0d, 0f, 0f); + } + + public Location(final String world, final double x, final double y, final double z) { + this(world, x, y, z, 0f, 0f); + } + + public double getX() { + return this.x; + } + + public void setX(final double x) { + this.x = x; + } + + public double getY() { + return this.y; + } + + public void setY(final double y) { + this.y = y; + } + + public double getZ() { + return this.z; + } + + public void setZ(final double z) { + this.z = z; + } + + public String getWorld() { + return this.world; + } + + public void setWorld(final String world) { + this.world = world; + } + + public float getYaw() { + return this.yaw; + } + + public void setYaw(final float yaw) { + this.yaw = yaw; + } + + public float getPitch() { + return this.pitch; + } + + public void setPitch(final float pitch) { + this.pitch = pitch; + } + + public void add(double x, double y, double z) { + this.x += x; + this.y += y; + this.z += z; + } + + public double getEuclideanDistanceSquared(final Location l2) { + double x = getX() - l2.getX(); + double y = getY() - l2.getY(); + double z = getZ() - l2.getZ(); + return (x * x) + (y * y) + (z * z); + } + + public double getEuclideanDistance(final Location l2) { + return Math.sqrt(getEuclideanDistanceSquared(l2)); + } + + public boolean isInSphere(final Location origin, final int radius) { + return getEuclideanDistanceSquared(origin) < radius * radius; + } + + @Override + public int hashCode() { + int hash = 127; + hash = hash * 31 + (int) x; + hash = hash * 31 + (int) y; + hash = hash * 31 + (int) z; + hash = (int) (hash * 31 + getYaw()); + hash = (int) (hash * 31 + getPitch()); + return hash * 31 + (world == null ? 127 : world.hashCode()); + } + + public boolean isInAABB(final Location min, final Location max) { + return x >= min.getX() && x <= max.getX() && y >= min.getY() && + y <= max.getY() && z >= min.getX() && z < max.getZ(); + } + + public void lookTowards(double x, double y) { + double l = this.x - x; + double w = this.z - z; + double c = Math.sqrt(l * l + w * w); + if ((Math.asin(w / c) / Math.PI * 180) > 90) { + setYaw((float) (180 - (-Math.asin(l / c) / Math.PI * 180))); + } else { + setYaw((float) (-Math.asin(l / c) / Math.PI * 180)); + } + } + + public void subtract(double x, double y, double z) { + this.x -= x; + this.y -= y; + this.z -= z; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Location)) + return false; + Location l = (Location) o; + return x == l.getX() && y == l.getY() && + z == l.getZ() && world.equals(l.getWorld()) && + yaw == l.getY() && pitch == l.getPitch(); + } + + @Override + public int compareTo(final Location o) { + if (o == null) { + throw new NullPointerException("Specified object was null"); + } + if (x == o.getX() && y == o.getY() || z == o.getZ()) + return 0; + if (x < o.getX() && y < o.getY() && z < o.getZ()) + return -1; + return 1; + } + + @Override + public String toString() { + return "\"plotsquaredlocation\":{" + "\"x\":" + x + ",\"y\":" + y + ",\"z\":" + z + ",\"yaw\":" + yaw + ",\"pitch\":" + pitch + ",\"world\":\"" + world + "\"}"; + } +}