Skip to content

Commit

Permalink
Added MythicItem support through MythicMobs
Browse files Browse the repository at this point in the history
Addresses #63
  • Loading branch information
Codisimus committed Sep 3, 2016
1 parent e157cf2 commit 12d9be1
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 0 deletions.
Binary file added lib/MythicMobs.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions src/com/codisimus/plugins/phatloots/PhatLoots.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PhatLoots extends JavaPlugin {
public static Economy econ = null;
public static String dataFolder;
public static boolean mythicDropsSupport;
public static boolean mythicMobsSupport;
public static long autoSavePeriod;
public static CommandHandler handler;
public static final HashMap<String, RegionHook> regionHooks = new HashMap<>(); //Plugin Name -> RegionHook
Expand Down Expand Up @@ -117,6 +118,13 @@ public void onEnable () {
debug("Plugin MythicDrops could not be found, support has been turned off.");
}

mythicMobsSupport = Bukkit.getPluginManager().isPluginEnabled("MythicMobs");
if (mythicMobsSupport) {
logger.info("Enabling MythicMobs support");
} else if (isDebug()) {
debug("Plugin MythicMobs could not be found, support has been turned off.");
}

/* Register Buttons */
LootCollection.registerButton();
Experience.registerButton();
Expand All @@ -133,6 +141,9 @@ public void onEnable () {
if (mythicDropsSupport) {
handler.registerCommands(ManageMythicDropsLootCommand.class);
}
if (mythicMobsSupport) {
handler.registerCommands(ManageMythicMobsLootCommand.class);
}
handler.registerCommands(LootCommand.class);
handler.registerCommands(ManageLootCommand.class);
handler.registerCommands(VariableLootCommand.class);
Expand All @@ -157,6 +168,9 @@ public void onEnable () {
ConfigurationSerialization.registerClass(UnidentifiedItem.class, "UnidentifiedItem");
ConfigurationSerialization.registerClass(Gem.class, "Gem");
}
if (mythicMobsSupport) {
ConfigurationSerialization.registerClass(MythicMobsItem.class, "MythicMobsItem");
}

/* Load External PhatLoots Addons */
//Buttons, Tools, CodCommands, RegionHooks, and ConfigurationSerializable classes should be registered from within the Addon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.codisimus.plugins.phatloots.commands;

import com.codisimus.plugins.phatloots.commands.CommandHandler.CodCommand;
import com.codisimus.plugins.phatloots.loot.MythicMobsItem;
import org.bukkit.command.CommandSender;

/**
* Executes Player Commands for configuring MythicMobs Loot
*
* @author Codisimus
*/
public class ManageMythicMobsLootCommand {

@CodCommand(
command = "add",
subcommand = "mm",
weight = 193.2,
aliases = {"+"},
usage = {
"§e PhatLoots Manage Loot Help Page:",
"§5A Parameter starts with the 1 character §2id",
"§2p§f: §5The Name of the PhatLoot ex. §6pEpic",
"§bIf PhatLoot is not specified then all PhatLoots linked to the target Block will be affected",
"§2%§f: §5The chance of looting ex. §6%50 §5or §6%0.1 §5(default: §6100§5)",
"§2c§f: §5The name of the collection to add the loot to ex. §6cFood",
"§2#§f: §5The amount to be looted ex. §6#10 §5or §6#1-64",
"§2<command> <tier> [Parameter1] [Parameter2]...",
"§bex. §6<command> ItemA #2-3 %80",
"§bex. §6<command> ItemB %10 cWeapon",
"§bTutorial Video:",
"§1§nNone yet, Submit yours!"
},
permission = "phatloots.manage"
)
public boolean addMythicMobsItem(CommandSender sender, String itemId, String[] args) {
setMythicMobsItem(sender, true, itemId, args);
return true;
}

@CodCommand(
command = "remove",
subcommand = "md",
weight = 198.1,
aliases = {"-"},
usage = {
"§e PhatLoots Manage Loot Help Page:",
"§5A Parameter starts with the 1 character §2id",
"§2p§f: §5The Name of the PhatLoot ex. §6pEpic",
"§bIf PhatLoot is not specified then all PhatLoots linked to the target Block will be affected",
"§2%§f: §5The chance of looting ex. §6%50 §5or §6%0.1 §5(default: §6100§5)",
"§2c§f: §5The name of the collection to add the loot to ex. §6cFood",
"§2#§f: §5The amount to be looted ex. §6#10 §5or §6#1-64",
"§2<command> <tier> [Parameter1] [Parameter2]...",
"§bex. §6<command> ItemA #2-3 %80",
"§bex. §6<command> ItemB %10 cWeapon",
"§bTutorial Video:",
"§1§nNone yet, Submit yours!"
},
permission = "phatloots.manage"
)
public boolean removeMythicMobsItem(CommandSender sender, String itemId, String[] args) {
setMythicMobsItem(sender, false, itemId, args);
return true;
}

/**
* Generates the MythicDrops Item and sets it on the PhatLoot(s)
*
* @param sender The CommandSender who is setting the MythicMobs Item
* @param add True if the MythicMobs Item should be added to the PhatLoot(s)
* @param itemId The ID of the MythicMobs Item
* @param args The arguments of the MythicMobs Item
*/
private static void setMythicMobsItem(CommandSender sender, boolean add, String itemId, String[] args) {
String phatLoot = null; //The name of the PhatLoot
double percent = 100; //The chance of receiving the Loot (defaulted to 100)
String coll = null; //The Collection to add the Loot to
int amountLower = 1; //Least amount of loot items to possibly generate (defaulted to 1)
int amountUpper = 1; //Most amount of loot items to possibly generate(defaulted to 1)

//Check each parameter
int i = 0;
while (i < args.length) {
char c = args[i].charAt(0);
String s = args[i].substring(1);
switch (c) {
case 'p': //PhatLoot Name
phatLoot = s;
break;

case '%': //Probability
percent = LootCommandUtil.getPercent(sender, s);
if (percent == -1) {
sender.sendMessage("§6" + s + "§4 is not a percent");
return;
}
break;

case 'c': //Collection Name
coll = s;
break;

case '#': //Amount
amountLower = LootCommandUtil.getLowerBound(s);
amountUpper = LootCommandUtil.getUpperBound(s);
if (amountLower == -1 || amountUpper == -1) {
sender.sendMessage("§6" + s + "§4 is not a valid number or range");
return;
}
break;

default: //Invalid Parameter
sender.sendMessage("§6" + c + "§4 is not a valid parameter ID");
return;
}

i++;
}

//Construct the Loot
MythicMobsItem loot = new MythicMobsItem(itemId, amountLower, amountUpper);
loot.setProbability(percent);

LootCommandUtil.setLoot(sender, phatLoot, add, coll, loot);
}
}
Loading

0 comments on commit 12d9be1

Please sign in to comment.