mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-02 11:21:20 +01:00
Added 'giveall' command + small code optimization
This commit is contained in:
parent
2a8ce9bef2
commit
b3e838e11a
@ -58,7 +58,7 @@ public class MMOItemIngredient extends Ingredient {
|
||||
|
||||
@Override
|
||||
public boolean isValid(NBTItem item) {
|
||||
return item.hasTag("MMOITEMS_ITEM_TYPE");
|
||||
return item.hasType();
|
||||
}
|
||||
|
||||
private String findName() {
|
||||
|
@ -829,6 +829,81 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
PlayerData.get(target).cast(ability);
|
||||
}
|
||||
// ==================================================================================================================================
|
||||
else if (args[0].equalsIgnoreCase("giveall")) {
|
||||
if (args.length != 5) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + "Usage: /mi giveall <type> <item-id> <[min]-[max]> <unidentified-chance>");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Type.isValid(args[1])) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.RED + "to see all the available item types.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Type type = Type.get(args[1]);
|
||||
String name = args[2].toUpperCase().replace("-", "_");
|
||||
FileConfiguration config = type.getConfigFile().getConfig();
|
||||
if (!config.contains(name)) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item called " + name + ".");
|
||||
return true;
|
||||
}
|
||||
double unidentifiedChance;
|
||||
int min, max;
|
||||
|
||||
try {
|
||||
unidentifiedChance = Double.parseDouble(args[4]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[4] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] splitAmount = args[3].split("\\-");
|
||||
if (splitAmount.length != 2) {
|
||||
try {
|
||||
min = Integer.parseInt(args[3]);
|
||||
max = Integer.parseInt(args[3]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "The quantity format is incorrect,");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "or " + args[3] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Format: [min]-[max]");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
min = Integer.parseInt(splitAmount[0]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[0] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
max = Integer.parseInt(splitAmount[1]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[1] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack item = new DropItem(type, name, 1, unidentifiedChance / 100, min, max).getItem();
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
return true;
|
||||
}
|
||||
|
||||
for(Player target : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (target.getInventory().firstEmpty() == -1) {
|
||||
target.getWorld().dropItem(target.getLocation(), item);
|
||||
return true;
|
||||
}
|
||||
target.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
// ==================================================================================================================================
|
||||
else if (args.length > 1) {
|
||||
if (args.length < 3 && !(sender instanceof Player)) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Please specify a player to use this command.");
|
||||
|
@ -44,6 +44,7 @@ public class MMOItemsCompletion implements TabCompleter {
|
||||
list.add("allitems");
|
||||
list.add("update");
|
||||
list.add("stations");
|
||||
list.add("giveall");
|
||||
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("help"))
|
||||
@ -72,7 +73,7 @@ public class MMOItemsCompletion implements TabCompleter {
|
||||
list.add("spirit");
|
||||
}
|
||||
|
||||
else if (args[0].equalsIgnoreCase("browse") || args[0].equalsIgnoreCase("itemlist") || args[0].equalsIgnoreCase("drop") || args[0].equalsIgnoreCase("create") || args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("edit") || args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("load"))
|
||||
else if (args[0].equalsIgnoreCase("browse") || args[0].equalsIgnoreCase("itemlist") || args[0].equalsIgnoreCase("drop") || args[0].equalsIgnoreCase("create") || args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("edit") || args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("load") || args[0].equalsIgnoreCase("giveall"))
|
||||
for (Type type : MMOItems.plugin.getTypes().getAll())
|
||||
list.add(type.getId());
|
||||
|
||||
@ -89,7 +90,7 @@ public class MMOItemsCompletion implements TabCompleter {
|
||||
else if (args[0].equalsIgnoreCase("stations") && args[1].equalsIgnoreCase("open"))
|
||||
MMOItems.plugin.getCrafting().getAll().forEach(station -> list.add(station.getId()));
|
||||
|
||||
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("edit") || args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("drop"))
|
||||
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("edit") || args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("drop") || args[0].equalsIgnoreCase("giveall"))
|
||||
if (Type.isValid(args[1]))
|
||||
Type.get(args[1]).getConfigFile().getConfig().getKeys(false).forEach(key -> list.add(key.toUpperCase()));
|
||||
|
||||
@ -128,7 +129,14 @@ public class MMOItemsCompletion implements TabCompleter {
|
||||
for (int j = 0; j < 10; j++)
|
||||
list.add("" + j);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("giveall")) {
|
||||
if (args.length == 4)
|
||||
for (String str : new String[] { "1", "16", "64", "1-5", "1-10", "4-16" })
|
||||
list.add(str);
|
||||
|
||||
if (args.length == 5)
|
||||
for (int j : new int[] { 0, 10, 25, 50, 75, 100 })
|
||||
list.add("" + j);
|
||||
} else if (Type.isValid(args[0])) {
|
||||
if (args.length == 4)
|
||||
for (String str : new String[] { "1", "16", "64", "1-5", "1-10", "4-16" })
|
||||
|
Loading…
Reference in New Issue
Block a user