-- Some minor changed && Prep. for porting

* Added prefix for "greeting" & "farewell" flags
* Added custom location class
* Added "all" category (/plot help)
This commit is contained in:
Sauilitired 2015-02-11 14:54:31 +01:00
parent e880d79720
commit 5b3a2d58b4
4 changed files with 191 additions and 40 deletions

View File

@ -21,10 +21,10 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import com.intellectualcrafters.plot.PlotMain;
import java.util.Arrays; import com.intellectualcrafters.plot.config.C;
import java.util.List; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.StringComparison;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -32,10 +32,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlotMain; import java.util.ArrayList;
import com.intellectualcrafters.plot.config.C; import java.util.Arrays;
import com.intellectualcrafters.plot.util.PlayerFunctions; import java.util.List;
import com.intellectualcrafters.plot.util.StringComparison;
/** /**
* PlotMain command class * PlotMain command class
@ -75,7 +74,12 @@ public class MainCommand implements CommandExecutor, TabCompleter {
} }
public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
final List<SubCommand> commands = getCommands(category, player); List<SubCommand> commands;
if (category != null) {
commands = getCommands(category, player);
} else {
commands = subCommands;
}
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) / // final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
// 100)); // 100));
final int perPage = 5; final int perPage = 5;
@ -92,7 +96,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
help.add(C.HELP_HEADER.s()); 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_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; SubCommand cmd;
@ -128,6 +132,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { 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%", 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()); return PlayerFunctions.sendMessage(player, builder.toString());
} }
final String cat = args[1]; final String cat = args[1];
@ -138,7 +143,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
break; break;
} }
} }
if (cato == null) { if (cato == null && !cat.equalsIgnoreCase("all")) {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
builder.append(C.HELP_INFO.s()); builder.append(C.HELP_INFO.s());
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {

View File

@ -21,15 +21,10 @@
package com.intellectualcrafters.plot.config; package com.intellectualcrafters.plot.config;
import org.bukkit.ChatColor;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualsites.translation.TranslationFile; import com.intellectualsites.translation.*;
import com.intellectualsites.translation.TranslationLanguage;
import com.intellectualsites.translation.TranslationManager;
import com.intellectualsites.translation.TranslationObject;
import com.intellectualsites.translation.YamlTranslationFile;
import com.intellectualsites.translation.bukkit.BukkitTranslation; import com.intellectualsites.translation.bukkit.BukkitTranslation;
import org.bukkit.ChatColor;
/** /**
* Captions class. * Captions class.
@ -158,6 +153,8 @@ public enum C {
TITLE_LEFT_PLOT_COLOR("GOLD"), TITLE_LEFT_PLOT_COLOR("GOLD"),
TITLE_LEFT_PLOT_SUB("Owned by %s"), TITLE_LEFT_PLOT_SUB("Owned by %s"),
TITLE_LEFT_PLOT_SUB_COLOR("RED"), TITLE_LEFT_PLOT_SUB_COLOR("RED"),
PREFIX_GREETING("&6%id%&c> "),
PREFIX_FAREWELL("&c%id%&c> "),
/* /*
* Core Stuff * Core Stuff
*/ */

View File

@ -21,18 +21,15 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import java.util.ArrayList; import com.intellectualcrafters.plot.PlotMain;
import java.util.HashMap; import com.intellectualcrafters.plot.config.C;
import java.util.HashSet; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import java.util.List; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import java.util.Map; import com.intellectualcrafters.plot.flag.FlagManager;
import java.util.Set; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import org.bukkit.Bukkit; import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.ChatColor; import org.bukkit.*;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -46,14 +43,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.PlotMain; import java.util.*;
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;
/** /**
* Created 2014-10-30 for PlotSquared * Created 2014-10-30 for PlotSquared
@ -183,7 +173,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
public void onPlotEnter(final PlayerEnterPlotEvent event) { public void onPlotEnter(final PlayerEnterPlotEvent event) {
final Plot plot = event.getPlot(); final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "greeting") != null) { 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 (booleanFlag(plot, "notify-enter", false)) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -220,7 +210,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.RECORD_PLAY, 0); event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.RECORD_PLAY, 0);
final Plot plot = event.getPlot(); final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "farewell") != null) { 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())) { if (feedRunnable.containsKey(event.getPlayer().getName())) {
feedRunnable.remove(event.getPlayer().getName()); feedRunnable.remove(event.getPlayer().getName());

View File

@ -0,0 +1,159 @@
package com.intellectualcrafters.plot.object;
/**
* Created 2015-02-11 for PlotSquared
*
* @author Citymonstret
*/
public class Location implements Cloneable, Comparable<Location> {
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 + "\"}";
}
}