mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-10 10:27:44 +01:00
Command Fix
Invalid command arguments caused a crash
This commit is contained in:
parent
e12bc92019
commit
cc18166743
@ -67,48 +67,50 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
|
||||
Player player = (Player) sender;
|
||||
if(args != null && args.length > 0) {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())){
|
||||
try {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())) {
|
||||
case HELP:
|
||||
for(OPTIONS option : OPTIONS.values()){
|
||||
if(!option.equals(OPTIONS.HELP)) {
|
||||
for (OPTIONS option : OPTIONS.values()) {
|
||||
if (!option.equals(OPTIONS.HELP)) {
|
||||
player.sendMessage(ChatColor.RED + option.commandHelp);
|
||||
player.sendMessage(ChatColor.WHITE + option.description);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case ADD:
|
||||
if(args.length > 1){
|
||||
if (args.length > 1) {
|
||||
if (player.hasPermission(Permissions.AUTOCRAFT_ADD) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
Block targetBlock = player.getTargetBlockExact(5);
|
||||
if (targetBlock != null) Config.getAutoCraft().createStorage(player, targetBlock, args[1],true);
|
||||
if (targetBlock != null)
|
||||
Config.getAutoCraft().createStorage(player, targetBlock, args[1], true);
|
||||
else Config.getAutoCraft().getMessages().mustLookAtBlock(player);
|
||||
} else {
|
||||
Messages.NO_PERMISSION(player);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.ADD.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.ADD.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.ADD.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.ADD.description);
|
||||
return true;
|
||||
}
|
||||
case OPEN:
|
||||
if(args.length > 1){
|
||||
if(sender.hasPermission(Permissions.AUTOCRAFT_OPEN) && sender.hasPermission(Permissions.AUTOCRAFT_OPEN_REMOTE) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission(Permissions.AUTOCRAFT_OPEN) && sender.hasPermission(Permissions.AUTOCRAFT_OPEN_REMOTE) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
AutoCraftingStorage invs;
|
||||
if(args[1].contains(":")){
|
||||
invs = Config.getAutoCraft().getStorage(player,args[1]);
|
||||
if (args[1].contains(":")) {
|
||||
invs = Config.getAutoCraft().getStorage(player, args[1]);
|
||||
} else {
|
||||
invs = Config.getAutoCraft().getStorage(player.getUniqueId(), args[1]);
|
||||
}
|
||||
if(invs != null) player.openInventory(invs.getInventory());
|
||||
if (invs != null) player.openInventory(invs.getInventory());
|
||||
return true;
|
||||
} else {
|
||||
Messages.NO_PERMISSION(player);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.OPEN.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.OPEN.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.OPEN.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.OPEN.description);
|
||||
return true;
|
||||
}
|
||||
// case MENU:
|
||||
@ -125,7 +127,7 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
Config.getAutoCraft().getMessages().listStorageGroups(player);
|
||||
return true;
|
||||
case REMOVE:
|
||||
if(args.length > 1) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission(Permissions.AUTOCRAFT_REMOVE)) {
|
||||
Config.getAutoCraft().removeStorage(player, args[1]);
|
||||
return true;
|
||||
@ -134,8 +136,8 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.REMOVE.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.REMOVE.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.REMOVE.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.REMOVE.description);
|
||||
return true;
|
||||
}
|
||||
case MEMBER:
|
||||
@ -158,10 +160,10 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
}
|
||||
}
|
||||
case RENAME: {
|
||||
if(args.length > 2){
|
||||
if (args.length > 2) {
|
||||
String group = args[1];
|
||||
String newIdentifier = args[2];
|
||||
if(!Config.getAutoCraft().renameStorage(player,group,newIdentifier)){
|
||||
if (!Config.getAutoCraft().renameStorage(player, group, newIdentifier)) {
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.RENAME.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.RENAME.description);
|
||||
}
|
||||
@ -169,6 +171,9 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException exception){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -70,20 +70,22 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
|
||||
Player player = (Player) sender;
|
||||
if(args != null && args.length > 0) {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())){
|
||||
try {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())) {
|
||||
case HELP:
|
||||
for(OPTIONS option : OPTIONS.values()){
|
||||
if(!option.equals(OPTIONS.HELP)) {
|
||||
for (OPTIONS option : OPTIONS.values()) {
|
||||
if (!option.equals(OPTIONS.HELP)) {
|
||||
player.sendMessage(ChatColor.RED + option.commandHelp);
|
||||
player.sendMessage(ChatColor.WHITE + option.description);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case ADD:
|
||||
if(args.length > 1){
|
||||
if(sender.hasPermission(Permissions.ADD) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission(Permissions.ADD) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
Block targetBlock = player.getTargetBlockExact(5);
|
||||
if (targetBlock != null) Config.getChestLink().createStorage(player,targetBlock,args[1],true);
|
||||
if (targetBlock != null)
|
||||
Config.getChestLink().createStorage(player, targetBlock, args[1], true);
|
||||
else Config.getChestLink().getMessages().mustLookAtBlock(player);
|
||||
return true;
|
||||
} else {
|
||||
@ -91,32 +93,32 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.ADD.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.ADD.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.ADD.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.ADD.description);
|
||||
return true;
|
||||
}
|
||||
case OPEN:
|
||||
if(args.length > 1){
|
||||
if(sender.hasPermission(Permissions.OPEN) && sender.hasPermission(Permissions.OPEN_REMOTE) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission(Permissions.OPEN) && sender.hasPermission(Permissions.OPEN_REMOTE) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
ChestLinkStorage invs;
|
||||
if(args[1].contains(":")){
|
||||
invs = Config.getChestLink().getStorage(player,args[1]);
|
||||
if (args[1].contains(":")) {
|
||||
invs = Config.getChestLink().getStorage(player, args[1]);
|
||||
} else {
|
||||
invs = Config.getChestLink().getStorage(player.getUniqueId(), args[1]);
|
||||
}
|
||||
if(invs != null) Utils.openChestInventory(player, invs.getInventory());
|
||||
if (invs != null) Utils.openChestInventory(player, invs.getInventory());
|
||||
return true;
|
||||
} else {
|
||||
Messages.NO_PERMISSION(player);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.OPEN.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.OPEN.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.OPEN.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.OPEN.description);
|
||||
return true;
|
||||
}
|
||||
case MENU:
|
||||
if(sender.hasPermission(Permissions.MENU) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
if (sender.hasPermission(Permissions.MENU) && !Settings.isBlacklistedWorld(player.getWorld())) {
|
||||
ChestLinkMenu.getMenu(player).open(player);
|
||||
return true;
|
||||
} else {
|
||||
@ -127,7 +129,7 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
Config.getChestLink().getMessages().listStorageGroups(player);
|
||||
return true;
|
||||
case REMOVE:
|
||||
if(args.length > 1) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission(Permissions.REMOVE)) {
|
||||
Config.getChestLink().removeStorage(player, args[1]);
|
||||
return true;
|
||||
@ -136,18 +138,18 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.REMOVE.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.REMOVE.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.REMOVE.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.REMOVE.description);
|
||||
return true;
|
||||
}
|
||||
case SORT:
|
||||
if(args.length > 1) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission(Permissions.SORT)) {
|
||||
ChestLinkStorage storage = Config.getChestLink().getStorage(player.getUniqueId(),args[1]);
|
||||
if(storage != null) {
|
||||
ChestLinkStorage storage = Config.getChestLink().getStorage(player.getUniqueId(), args[1]);
|
||||
if (storage != null) {
|
||||
storage.setSortMethod(Enum.valueOf(SortMethod.class, args[2]));
|
||||
storage.sort();
|
||||
Messages.SORT(player,storage);
|
||||
Messages.SORT(player, storage);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@ -155,8 +157,8 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.SORT.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.SORT.description);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.SORT.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.SORT.description);
|
||||
return true;
|
||||
}
|
||||
case MEMBER:
|
||||
@ -179,10 +181,10 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
}
|
||||
}
|
||||
case RENAME: {
|
||||
if(args.length > 2){
|
||||
if (args.length > 2) {
|
||||
String group = args[1];
|
||||
String newIdentifier = args[2];
|
||||
if(!Config.getChestLink().renameStorage(player,group,newIdentifier)){
|
||||
if (!Config.getChestLink().renameStorage(player, group, newIdentifier)) {
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.RENAME.commandHelp);
|
||||
player.sendMessage(ChatColor.RED + OPTIONS.RENAME.description);
|
||||
}
|
||||
@ -190,6 +192,9 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException exception){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user