mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Merge remote-tracking branch 'origin/master'
Conflicts: PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java PlotSquared/src/main/java/com/intellectualcrafters/plot/StringComparsion.java
This commit is contained in:
commit
487aa93986
@ -9,20 +9,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.bukkit.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions involving players, plots and locations.
|
* Functions involving players, plots and locations.
|
||||||
*
|
*
|
||||||
@ -32,8 +24,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class PlayerFunctions {
|
public class PlayerFunctions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player
|
* @param player player
|
||||||
* player
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isInPlot(final Player player) {
|
public static boolean isInPlot(final Player player) {
|
||||||
@ -41,8 +32,7 @@ public class PlayerFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot
|
* @param plot plot
|
||||||
* plot
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean hasExpired(final Plot plot) {
|
public static boolean hasExpired(final Plot plot) {
|
||||||
@ -173,9 +163,8 @@ public class PlayerFunctions {
|
|||||||
/**
|
/**
|
||||||
* Updates a given plot with another instance
|
* Updates a given plot with another instance
|
||||||
*
|
*
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param plot
|
* @param plot
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void set(final Plot plot) {
|
public static void set(final Plot plot) {
|
||||||
@ -237,8 +226,7 @@ public class PlayerFunctions {
|
|||||||
* \\previous\\
|
* \\previous\\
|
||||||
*
|
*
|
||||||
* @param plr
|
* @param plr
|
||||||
* @param msg
|
* @param msg Was used to wrap the chat client length (Packets out--)
|
||||||
* Was used to wrap the chat client length (Packets out--)
|
|
||||||
*/
|
*/
|
||||||
public static void sendMessageWrapped(final Player plr, final String msg) {
|
public static void sendMessageWrapped(final Player plr, final String msg) {
|
||||||
plr.sendMessage(msg);
|
plr.sendMessage(msg);
|
||||||
@ -247,12 +235,21 @@ public class PlayerFunctions {
|
|||||||
/**
|
/**
|
||||||
* Send a message to the player
|
* Send a message to the player
|
||||||
*
|
*
|
||||||
* @param plr
|
* @param plr Player to recieve message
|
||||||
* Player to recieve message
|
* @param msg Message to send
|
||||||
* @param msg
|
* @return true
|
||||||
* Message to send
|
* Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(final Player plr, final String msg) {
|
public static boolean sendMessage(final Player plr, final String msg) {
|
||||||
|
if (msg.length() > 0 && !msg.equals("")) {
|
||||||
|
if (plr == null) {
|
||||||
|
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + msg);
|
||||||
|
} else {
|
||||||
|
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
/*
|
||||||
if ((msg.length() == 0) || msg.equalsIgnoreCase("")) {
|
if ((msg.length() == 0) || msg.equalsIgnoreCase("")) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@ -263,17 +260,37 @@ public class PlayerFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the player
|
* Send a message to the player
|
||||||
*
|
*
|
||||||
* @param plr
|
* @param plr Player to recieve message
|
||||||
* Player to recieve message
|
* @param c Caption to send
|
||||||
* @param c
|
* @return
|
||||||
* Caption to send
|
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(final Player plr, final C c, final String... args) {
|
public static boolean sendMessage(final Player plr, final C c, final String... args) {
|
||||||
|
if (c.s().length() > 1) {
|
||||||
|
if (plr == null)
|
||||||
|
PlotMain.sendConsoleSenderMessage(c);
|
||||||
|
else {
|
||||||
|
String msg = c.s();
|
||||||
|
if ((args != null) && (args.length > 0)) {
|
||||||
|
for (final String str : args)
|
||||||
|
msg = msg.replaceFirst("%s", str);
|
||||||
|
}
|
||||||
|
sendMessage(plr, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
/*
|
||||||
|
if (plr == null) {
|
||||||
|
PlotMain.sendConsoleSenderMessage(c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
>>>>>>> origin/master
|
||||||
if (c.s().length() < 1) {
|
if (c.s().length() < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -288,5 +305,6 @@ public class PlayerFunctions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendMessage(plr, msg);
|
sendMessage(plr, msg);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,4 +277,23 @@ public class Plot implements Cloneable {
|
|||||||
PlotHelper.clear(plr, this);
|
PlotHelper.clear(plr, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the plot hashcode
|
||||||
|
*
|
||||||
|
* @return integer. You can easily make this a character array <br>
|
||||||
|
* xI = c[0]
|
||||||
|
* x = c[1 -> xI...]
|
||||||
|
* yI = c[xI ... + 1]
|
||||||
|
* y = c[xI ... + 2 -> yI ...]
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int
|
||||||
|
x = getId().x,
|
||||||
|
z = getId().y;
|
||||||
|
String
|
||||||
|
xL = (x + "").length() + "",
|
||||||
|
zL = (z + "").length() + "";
|
||||||
|
return Integer.parseInt(xL + x + zL + z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public class StringComparsion {
|
|||||||
|
|
||||||
private String bestMatch;
|
private String bestMatch;
|
||||||
private double match = 0;
|
private double match = 0;
|
||||||
|
private Object bestMatchObject;
|
||||||
|
|
||||||
public StringComparsion(final String input, final Object[] objects) {
|
public StringComparsion(final String input, final Object[] objects) {
|
||||||
double c = 0;
|
double c = 0;
|
||||||
@ -19,10 +20,14 @@ public class StringComparsion {
|
|||||||
if ((c = compare(input, o.toString())) > this.match) {
|
if ((c = compare(input, o.toString())) > this.match) {
|
||||||
this.match = c;
|
this.match = c;
|
||||||
this.bestMatch = o.toString();
|
this.bestMatch = o.toString();
|
||||||
|
this.bestMatchObject = o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getMatchObject() {
|
||||||
|
return this.bestMatchObject;
|
||||||
|
}
|
||||||
public String getBestMatch() {
|
public String getBestMatch() {
|
||||||
return this.bestMatch;
|
return this.bestMatch;
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.intellectualcrafters.plot.C;
|
||||||
import java.util.Arrays;
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||||
import java.util.List;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
|
import com.intellectualcrafters.plot.StringComparsion;
|
||||||
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;
|
||||||
@ -20,10 +20,9 @@ import org.bukkit.command.TabCompleter;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.ChatPaginator;
|
import org.bukkit.util.ChatPaginator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.C;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
import java.util.Arrays;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import java.util.List;
|
||||||
import com.intellectualcrafters.plot.StringComparsion;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotMain command class
|
* PlotMain command class
|
||||||
@ -32,6 +31,9 @@ import com.intellectualcrafters.plot.StringComparsion;
|
|||||||
*/
|
*/
|
||||||
public class MainCommand implements CommandExecutor, TabCompleter {
|
public class MainCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
public static final String
|
||||||
|
MAIN_PERMISSION = "plots.use";
|
||||||
|
|
||||||
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand() };
|
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand() };
|
||||||
|
|
||||||
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||||
@ -49,9 +51,8 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
||||||
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||||
|
|
||||||
if (!PlotMain.hasPermission(player, "plots.use")) {
|
if (!PlotMain.hasPermission(player, MAIN_PERMISSION))
|
||||||
return no_permission(player, "plots.use");
|
return no_permission(player, MAIN_PERMISSION);
|
||||||
}
|
|
||||||
|
|
||||||
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@ -60,8 +61,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()));
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, builder.toString());
|
return PlayerFunctions.sendMessage(player, builder.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
final String cat = args[1];
|
final String cat = args[1];
|
||||||
SubCommand.CommandCategory cato = null;
|
SubCommand.CommandCategory cato = null;
|
||||||
@ -77,8 +77,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()));
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, builder.toString());
|
return PlayerFunctions.sendMessage(player, builder.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
final StringBuilder help = new StringBuilder();
|
final StringBuilder help = new StringBuilder();
|
||||||
int page = 0;
|
int page = 0;
|
||||||
@ -110,8 +109,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
help.append(string).append("\n");
|
help.append(string).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerFunctions.sendMessage(player, help.toString());
|
return PlayerFunctions.sendMessage(player, help.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (final SubCommand command : subCommands) {
|
for (final SubCommand command : subCommands) {
|
||||||
@ -123,8 +121,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
return command.execute(player, arguments);
|
return command.execute(player, arguments);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -139,9 +136,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
commands[x] = subCommands.get(x).cmd;
|
commands[x] = subCommands.get(x).cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
/* Let's try to get a proper usage string */
|
||||||
|
SubCommand command = (SubCommand) new StringComparsion(args[0], commands).getMatchObject();
|
||||||
|
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, command.usage.contains("plot") ? command.usage : "/plot " + command.usage);
|
||||||
|
//PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
||||||
@ -154,34 +153,6 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
return cmds;
|
return cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* // Current page
|
|
||||||
* int page = 0;
|
|
||||||
* //is a page specified? else use 0
|
|
||||||
* if(args.length > 1) {
|
|
||||||
* try {
|
|
||||||
* page = Integer.parseInt(args[1]);
|
|
||||||
* } catch(Exception e) {
|
|
||||||
* page = 0;
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* //Get the total pages
|
|
||||||
* int totalPages = ((int) Math.ceil(12 * (PlotMain.getPlotsSorted().size())
|
|
||||||
* / 100));
|
|
||||||
* if(page > totalPages)
|
|
||||||
* page = totalPages;
|
|
||||||
* //Only display 12!
|
|
||||||
* int max = (page * 12) + 12;
|
|
||||||
* if(max > PlotMain.getPlotsSorted().size())
|
|
||||||
* max = PlotMain.getPlotsSorted().size();
|
|
||||||
* StringBuilder string = new StringBuilder();
|
|
||||||
* string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 +
|
|
||||||
* "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all") +
|
|
||||||
* "\n");
|
|
||||||
* Plot p;
|
|
||||||
* //This might work xD
|
|
||||||
* for (int x = (page * 12); x < max; x++) {
|
|
||||||
*/
|
|
||||||
public static ArrayList<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
public static ArrayList<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
||||||
final List<SubCommand> commands = getCommands(category, player);
|
final List<SubCommand> commands = getCommands(category, player);
|
||||||
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
||||||
@ -238,7 +209,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
if (strings.length < 1) {
|
if (strings.length < 1) {
|
||||||
if ((strings.length == 0) || "plots".startsWith(s)) {
|
if ((strings.length == 0) || "plots".startsWith(s)) {
|
||||||
return Arrays.asList(new String[] { "plots" });
|
return Arrays.asList("plots");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strings.length > 1) {
|
if (strings.length > 1) {
|
||||||
@ -247,7 +218,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<String> tabOptions = new ArrayList<String>();
|
final List<String> tabOptions = new ArrayList<>();
|
||||||
final String arg = strings[0].toLowerCase();
|
final String arg = strings[0].toLowerCase();
|
||||||
for (final SubCommand cmd : subCommands) {
|
for (final SubCommand cmd : subCommands) {
|
||||||
if (cmd.permission.hasPermission(player)) {
|
if (cmd.permission.hasPermission(player)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user