Skip to content

Commit 12d9be1

Browse files
committed
Added MythicItem support through MythicMobs
Addresses #63
1 parent e157cf2 commit 12d9be1

File tree

4 files changed

+384
-0
lines changed

4 files changed

+384
-0
lines changed

lib/MythicMobs.jar

1.42 MB
Binary file not shown.

src/com/codisimus/plugins/phatloots/PhatLoots.java

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class PhatLoots extends JavaPlugin {
4040
public static Economy econ = null;
4141
public static String dataFolder;
4242
public static boolean mythicDropsSupport;
43+
public static boolean mythicMobsSupport;
4344
public static long autoSavePeriod;
4445
public static CommandHandler handler;
4546
public static final HashMap<String, RegionHook> regionHooks = new HashMap<>(); //Plugin Name -> RegionHook
@@ -117,6 +118,13 @@ public void onEnable () {
117118
debug("Plugin MythicDrops could not be found, support has been turned off.");
118119
}
119120

121+
mythicMobsSupport = Bukkit.getPluginManager().isPluginEnabled("MythicMobs");
122+
if (mythicMobsSupport) {
123+
logger.info("Enabling MythicMobs support");
124+
} else if (isDebug()) {
125+
debug("Plugin MythicMobs could not be found, support has been turned off.");
126+
}
127+
120128
/* Register Buttons */
121129
LootCollection.registerButton();
122130
Experience.registerButton();
@@ -133,6 +141,9 @@ public void onEnable () {
133141
if (mythicDropsSupport) {
134142
handler.registerCommands(ManageMythicDropsLootCommand.class);
135143
}
144+
if (mythicMobsSupport) {
145+
handler.registerCommands(ManageMythicMobsLootCommand.class);
146+
}
136147
handler.registerCommands(LootCommand.class);
137148
handler.registerCommands(ManageLootCommand.class);
138149
handler.registerCommands(VariableLootCommand.class);
@@ -157,6 +168,9 @@ public void onEnable () {
157168
ConfigurationSerialization.registerClass(UnidentifiedItem.class, "UnidentifiedItem");
158169
ConfigurationSerialization.registerClass(Gem.class, "Gem");
159170
}
171+
if (mythicMobsSupport) {
172+
ConfigurationSerialization.registerClass(MythicMobsItem.class, "MythicMobsItem");
173+
}
160174

161175
/* Load External PhatLoots Addons */
162176
//Buttons, Tools, CodCommands, RegionHooks, and ConfigurationSerializable classes should be registered from within the Addon
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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

Comments
 (0)