forked from Upstream/CitizensCMD
Code cleanup.
This commit is contained in:
parent
76b30b65ec
commit
ae41395e5f
@ -25,7 +25,12 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.notDouble;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
|
|
||||||
public class CMDAdd extends CommandBase {
|
public class CMDAdd extends CommandBase {
|
||||||
|
|
||||||
|
@ -23,7 +23,11 @@ import me.mattstudios.citizenscmd.commands.base.CommandBase;
|
|||||||
import me.mattstudios.citizenscmd.paths.Path;
|
import me.mattstudios.citizenscmd.paths.Path;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.notInteger;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
public class CMDCooldown extends CommandBase {
|
public class CMDCooldown extends CommandBase {
|
||||||
|
|
||||||
|
@ -26,7 +26,12 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.notInteger;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
|
|
||||||
public class CMDEdit extends CommandBase {
|
public class CMDEdit extends CommandBase {
|
||||||
|
|
||||||
|
@ -28,7 +28,10 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
public class CMDList extends CommandBase {
|
public class CMDList extends CommandBase {
|
||||||
|
|
||||||
|
@ -23,7 +23,10 @@ import me.mattstudios.citizenscmd.commands.base.CommandBase;
|
|||||||
import me.mattstudios.citizenscmd.paths.Path;
|
import me.mattstudios.citizenscmd.paths.Path;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
public class CMDPermission extends CommandBase {
|
public class CMDPermission extends CommandBase {
|
||||||
|
|
||||||
|
@ -23,7 +23,12 @@ import me.mattstudios.citizenscmd.commands.base.CommandBase;
|
|||||||
import me.mattstudios.citizenscmd.paths.Path;
|
import me.mattstudios.citizenscmd.paths.Path;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.notDouble;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
|
|
||||||
public class CMDPrice extends CommandBase {
|
public class CMDPrice extends CommandBase {
|
||||||
|
|
||||||
|
@ -24,7 +24,12 @@ import me.mattstudios.citizenscmd.paths.Path;
|
|||||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.notInteger;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||||
|
|
||||||
|
|
||||||
public class CMDRemove extends CommandBase {
|
public class CMDRemove extends CommandBase {
|
||||||
|
|
||||||
|
@ -69,19 +69,19 @@ public abstract class CommandBase {
|
|||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean allowConsole() {
|
public boolean allowConsole() {
|
||||||
return allowConsole;
|
return allowConsole;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getAliases() {
|
public List<String> getAliases() {
|
||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMinimumArguments() {
|
public int getMinimumArguments() {
|
||||||
return minimumArguments;
|
return minimumArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMaximumArguments() {
|
public int getMaximumArguments() {
|
||||||
return maximumArguments;
|
return maximumArguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,10 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.*;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.getTabCompleteArgs;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelectedNM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thank you GlareMasters for creating this class!
|
* Thank you GlareMasters for creating this class!
|
||||||
@ -70,9 +73,9 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 0 || args[0].isEmpty()) {
|
if (args.length == 0 || args[0].isEmpty()) {
|
||||||
if (sender.hasPermission("citizenscmd.npcmd"))
|
if (sender.hasPermission("citizenscmd.npcmd") && sender instanceof Player) {
|
||||||
if (sender instanceof Player)
|
getCommand().execute((Player) sender, args);
|
||||||
getCommand().execute((Player) sender, args);
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,9 +193,8 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
|||||||
else if (args[2].equalsIgnoreCase("right"))
|
else if (args[2].equalsIgnoreCase("right"))
|
||||||
return getCommandNames(subCMD, args, 4, (Player) sender);
|
return getCommandNames(subCMD, args, 4, (Player) sender);
|
||||||
}
|
}
|
||||||
if (args.length == 5) {
|
if (args.length == 5 && args[1].equalsIgnoreCase("perm")) {
|
||||||
if (args[1].equalsIgnoreCase("perm"))
|
return getCommandNames(subCMD, args, 5, (Player) sender);
|
||||||
return getCommandNames(subCMD, args, 5, (Player) sender);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -213,7 +215,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
|||||||
*/
|
*/
|
||||||
private List<String> getCommandNames(String subCMD, String[] args, int arg, Player player) {
|
private List<String> getCommandNames(String subCMD, String[] args, int arg, Player player) {
|
||||||
List<String> commandNames = new ArrayList<>();
|
List<String> commandNames = new ArrayList<>();
|
||||||
String[][] argsComplete = getTabCompleteArgs(plugin, subCMD, player);
|
String[][] argsComplete = getTabCompleteArgs(plugin, subCMD.toLowerCase(), player);
|
||||||
|
|
||||||
if (!args[arg - 1].equals("")) {
|
if (!args[arg - 1].equals("")) {
|
||||||
for (String commandName : argsComplete[arg - 1]) {
|
for (String commandName : argsComplete[arg - 1]) {
|
||||||
|
@ -71,16 +71,11 @@ public class TimeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case SHORT:
|
|
||||||
dayFormat = shorts[3];
|
|
||||||
hourFormat = shorts[2];
|
|
||||||
minuteFormat = shorts[1];
|
|
||||||
secondFormat = shorts[0];
|
|
||||||
break;
|
|
||||||
case MEDIUM:
|
case MEDIUM:
|
||||||
String[] mediumsAfter = new String[4];
|
String[] mediumsAfter = new String[4];
|
||||||
String[] mediumsPlurals = new String[4];
|
String[] mediumsPlurals = new String[4];
|
||||||
Pattern patternMediums = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
Pattern patternMediums = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
||||||
|
|
||||||
for (int i = 0; i < mediums.length; i++) {
|
for (int i = 0; i < mediums.length; i++) {
|
||||||
if (mediums[i].contains("(") && mediums[i].contains(")")) {
|
if (mediums[i].contains("(") && mediums[i].contains(")")) {
|
||||||
Matcher matcher = patternMediums.matcher(mediums[i]);
|
Matcher matcher = patternMediums.matcher(mediums[i]);
|
||||||
@ -93,6 +88,7 @@ public class TimeUtil {
|
|||||||
mediumsPlurals[i] = "";
|
mediumsPlurals[i] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dayFormat = " " + mediumsAfter[3];
|
dayFormat = " " + mediumsAfter[3];
|
||||||
dayPlural = mediumsPlurals[3];
|
dayPlural = mediumsPlurals[3];
|
||||||
hourFormat = " " + mediumsAfter[2];
|
hourFormat = " " + mediumsAfter[2];
|
||||||
@ -102,10 +98,12 @@ public class TimeUtil {
|
|||||||
secondFormat = " " + mediumsAfter[0];
|
secondFormat = " " + mediumsAfter[0];
|
||||||
secondPlural = mediumsPlurals[0];
|
secondPlural = mediumsPlurals[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FULL:
|
case FULL:
|
||||||
String[] fullsAfter = new String[4];
|
String[] fullsAfter = new String[4];
|
||||||
String[] fullsPlurals = new String[4];
|
String[] fullsPlurals = new String[4];
|
||||||
Pattern patternFulls = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
Pattern patternFulls = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
||||||
|
|
||||||
for (int i = 0; i < fulls.length; i++) {
|
for (int i = 0; i < fulls.length; i++) {
|
||||||
if (fulls[i].contains("(") && fulls[i].contains(")")) {
|
if (fulls[i].contains("(") && fulls[i].contains(")")) {
|
||||||
Matcher matcher = patternFulls.matcher(fulls[i]);
|
Matcher matcher = patternFulls.matcher(fulls[i]);
|
||||||
@ -118,6 +116,7 @@ public class TimeUtil {
|
|||||||
fullsPlurals[i] = "";
|
fullsPlurals[i] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dayFormat = " " + fullsAfter[3];
|
dayFormat = " " + fullsAfter[3];
|
||||||
dayPlural = fullsPlurals[3];
|
dayPlural = fullsPlurals[3];
|
||||||
hourFormat = " " + fullsAfter[2];
|
hourFormat = " " + fullsAfter[2];
|
||||||
@ -127,6 +126,13 @@ public class TimeUtil {
|
|||||||
secondFormat = " " + fullsAfter[0];
|
secondFormat = " " + fullsAfter[0];
|
||||||
secondPlural = fullsPlurals[0];
|
secondPlural = fullsPlurals[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
dayFormat = shorts[3];
|
||||||
|
hourFormat = shorts[2];
|
||||||
|
minuteFormat = shorts[1];
|
||||||
|
secondFormat = shorts[0];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seconds < 60) {
|
if (seconds < 60) {
|
||||||
|
@ -157,7 +157,7 @@ public class Util {
|
|||||||
public static String[][] getTabCompleteArgs(CitizensCMD plugin, String subCMD, Player player) {
|
public static String[][] getTabCompleteArgs(CitizensCMD plugin, String subCMD, Player player) {
|
||||||
String[][] argComplete = new String[5][];
|
String[][] argComplete = new String[5][];
|
||||||
|
|
||||||
switch (subCMD.toLowerCase()) {
|
switch (subCMD) {
|
||||||
case "add":
|
case "add":
|
||||||
argComplete[0] = new String[]{"console", "none", "permission", "server", "message", "sound"};
|
argComplete[0] = new String[]{"console", "none", "permission", "server", "message", "sound"};
|
||||||
argComplete[1] = getSoundsList();
|
argComplete[1] = getSoundsList();
|
||||||
@ -360,10 +360,8 @@ public class Util {
|
|||||||
getScheduler().runTaskLater(plugin, () -> {
|
getScheduler().runTaskLater(plugin, () -> {
|
||||||
Pattern pattern = Pattern.compile("(\\w+)\\s([\\d.]+)\\s([\\d.]+)");
|
Pattern pattern = Pattern.compile("(\\w+)\\s([\\d.]+)\\s([\\d.]+)");
|
||||||
Matcher matcher = pattern.matcher(commands.get(finalI));
|
Matcher matcher = pattern.matcher(commands.get(finalI));
|
||||||
if (matcher.find()) {
|
if (matcher.find() && soundExists(matcher.group(1))) {
|
||||||
if (soundExists(matcher.group(1))) {
|
player.playSound(player.getLocation(), Sound.valueOf(matcher.group(1)), Float.parseFloat(matcher.group(2)), Float.parseFloat(matcher.group(3)));
|
||||||
player.playSound(player.getLocation(), Sound.valueOf(matcher.group(1)), Float.parseFloat(matcher.group(2)), Float.parseFloat(matcher.group(3)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, (int) delay * 20);
|
}, (int) delay * 20);
|
||||||
break;
|
break;
|
||||||
@ -374,6 +372,7 @@ public class Util {
|
|||||||
player.chat("/" + commands.get(finalI));
|
player.chat("/" + commands.get(finalI));
|
||||||
plugin.getPermissionsManager().unsetPermission(player, permissions.get(finalI));
|
plugin.getPermissionsManager().unsetPermission(player, permissions.get(finalI));
|
||||||
}, (int) delay * 20);
|
}, (int) delay * 20);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user