|
| 1 | +package com.codisimus.plugins.phatloots.commands; |
| 2 | + |
| 3 | +import com.codisimus.plugins.phatloots.commands.CommandHandler.CodCommand; |
| 4 | +import com.codisimus.plugins.phatloots.loot.MythicMobsItem; |
| 5 | +import org.bukkit.command.CommandSender; |
| 6 | + |
| 7 | +/** |
| 8 | + * Executes Player Commands for configuring MythicMobs Loot |
| 9 | + * |
| 10 | + * @author Codisimus |
| 11 | + */ |
| 12 | +public class ManageMythicMobsLootCommand { |
| 13 | + |
| 14 | + @CodCommand( |
| 15 | + command = "add", |
| 16 | + subcommand = "mm", |
| 17 | + weight = 193.2, |
| 18 | + aliases = {"+"}, |
| 19 | + usage = { |
| 20 | + "§e PhatLoots Manage Loot Help Page:", |
| 21 | + "§5A Parameter starts with the 1 character §2id", |
| 22 | + "§2p§f: §5The Name of the PhatLoot ex. §6pEpic", |
| 23 | + "§bIf PhatLoot is not specified then all PhatLoots linked to the target Block will be affected", |
| 24 | + "§2%§f: §5The chance of looting ex. §6%50 §5or §6%0.1 §5(default: §6100§5)", |
| 25 | + "§2c§f: §5The name of the collection to add the loot to ex. §6cFood", |
| 26 | + "§2#§f: §5The amount to be looted ex. §6#10 §5or §6#1-64", |
| 27 | + "§2<command> <tier> [Parameter1] [Parameter2]...", |
| 28 | + "§bex. §6<command> ItemA #2-3 %80", |
| 29 | + "§bex. §6<command> ItemB %10 cWeapon", |
| 30 | + "§bTutorial Video:", |
| 31 | + "§1§nNone yet, Submit yours!" |
| 32 | + }, |
| 33 | + permission = "phatloots.manage" |
| 34 | + ) |
| 35 | + public boolean addMythicMobsItem(CommandSender sender, String itemId, String[] args) { |
| 36 | + setMythicMobsItem(sender, true, itemId, args); |
| 37 | + return true; |
| 38 | + } |
| 39 | + |
| 40 | + @CodCommand( |
| 41 | + command = "remove", |
| 42 | + subcommand = "md", |
| 43 | + weight = 198.1, |
| 44 | + aliases = {"-"}, |
| 45 | + usage = { |
| 46 | + "§e PhatLoots Manage Loot Help Page:", |
| 47 | + "§5A Parameter starts with the 1 character §2id", |
| 48 | + "§2p§f: §5The Name of the PhatLoot ex. §6pEpic", |
| 49 | + "§bIf PhatLoot is not specified then all PhatLoots linked to the target Block will be affected", |
| 50 | + "§2%§f: §5The chance of looting ex. §6%50 §5or §6%0.1 §5(default: §6100§5)", |
| 51 | + "§2c§f: §5The name of the collection to add the loot to ex. §6cFood", |
| 52 | + "§2#§f: §5The amount to be looted ex. §6#10 §5or §6#1-64", |
| 53 | + "§2<command> <tier> [Parameter1] [Parameter2]...", |
| 54 | + "§bex. §6<command> ItemA #2-3 %80", |
| 55 | + "§bex. §6<command> ItemB %10 cWeapon", |
| 56 | + "§bTutorial Video:", |
| 57 | + "§1§nNone yet, Submit yours!" |
| 58 | + }, |
| 59 | + permission = "phatloots.manage" |
| 60 | + ) |
| 61 | + public boolean removeMythicMobsItem(CommandSender sender, String itemId, String[] args) { |
| 62 | + setMythicMobsItem(sender, false, itemId, args); |
| 63 | + return true; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Generates the MythicDrops Item and sets it on the PhatLoot(s) |
| 68 | + * |
| 69 | + * @param sender The CommandSender who is setting the MythicMobs Item |
| 70 | + * @param add True if the MythicMobs Item should be added to the PhatLoot(s) |
| 71 | + * @param itemId The ID of the MythicMobs Item |
| 72 | + * @param args The arguments of the MythicMobs Item |
| 73 | + */ |
| 74 | + private static void setMythicMobsItem(CommandSender sender, boolean add, String itemId, String[] args) { |
| 75 | + String phatLoot = null; //The name of the PhatLoot |
| 76 | + double percent = 100; //The chance of receiving the Loot (defaulted to 100) |
| 77 | + String coll = null; //The Collection to add the Loot to |
| 78 | + int amountLower = 1; //Least amount of loot items to possibly generate (defaulted to 1) |
| 79 | + int amountUpper = 1; //Most amount of loot items to possibly generate(defaulted to 1) |
| 80 | + |
| 81 | + //Check each parameter |
| 82 | + int i = 0; |
| 83 | + while (i < args.length) { |
| 84 | + char c = args[i].charAt(0); |
| 85 | + String s = args[i].substring(1); |
| 86 | + switch (c) { |
| 87 | + case 'p': //PhatLoot Name |
| 88 | + phatLoot = s; |
| 89 | + break; |
| 90 | + |
| 91 | + case '%': //Probability |
| 92 | + percent = LootCommandUtil.getPercent(sender, s); |
| 93 | + if (percent == -1) { |
| 94 | + sender.sendMessage("§6" + s + "§4 is not a percent"); |
| 95 | + return; |
| 96 | + } |
| 97 | + break; |
| 98 | + |
| 99 | + case 'c': //Collection Name |
| 100 | + coll = s; |
| 101 | + break; |
| 102 | + |
| 103 | + case '#': //Amount |
| 104 | + amountLower = LootCommandUtil.getLowerBound(s); |
| 105 | + amountUpper = LootCommandUtil.getUpperBound(s); |
| 106 | + if (amountLower == -1 || amountUpper == -1) { |
| 107 | + sender.sendMessage("§6" + s + "§4 is not a valid number or range"); |
| 108 | + return; |
| 109 | + } |
| 110 | + break; |
| 111 | + |
| 112 | + default: //Invalid Parameter |
| 113 | + sender.sendMessage("§6" + c + "§4 is not a valid parameter ID"); |
| 114 | + return; |
| 115 | + } |
| 116 | + |
| 117 | + i++; |
| 118 | + } |
| 119 | + |
| 120 | + //Construct the Loot |
| 121 | + MythicMobsItem loot = new MythicMobsItem(itemId, amountLower, amountUpper); |
| 122 | + loot.setProbability(percent); |
| 123 | + |
| 124 | + LootCommandUtil.setLoot(sender, phatLoot, add, coll, loot); |
| 125 | + } |
| 126 | +} |
0 commit comments