More cleanup.

This commit is contained in:
GJ 2012-05-18 14:29:53 -04:00
parent 146f832919
commit f3074461ed
10 changed files with 87 additions and 129 deletions

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.config.mods;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -28,7 +29,8 @@ public class CustomArmorConfig extends ModConfigLoader{
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customItems = new ArrayList<CustomItem>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
public CustomArmorConfig(mcMMO plugin) {
super(plugin, "armor.yml");
@ -93,7 +95,8 @@ public class CustomArmorConfig extends ModConfigLoader{
idList.add(id);
customIDs.add(id);
customItems.add(armor);
customArmorList.add(armor);
customArmor.put(id, armor);
}
}
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.config.mods;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -9,7 +10,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.datatypes.mods.CustomTool;
public class CustomToolsConfig extends ModConfigLoader {
@ -31,7 +31,8 @@ public class CustomToolsConfig extends ModConfigLoader {
public List<Integer> customSwordIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customItems = new ArrayList<CustomItem>();
public List<CustomTool> customToolList = new ArrayList<CustomTool>();
public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
private CustomToolsConfig(mcMMO plugin) {
super(plugin, "tools.yml");
@ -101,7 +102,8 @@ public class CustomToolsConfig extends ModConfigLoader {
idList.add(id);
customIDs.add(id);
customItems.add(tool);
customToolList.add(tool);
customTools.put(id, tool);
}
}
}

View File

@ -12,9 +12,9 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users;
@ -1032,9 +1032,10 @@ public class PlayerProfile {
if (Config.getInstance().getToolModsEnabled()) {
ItemStack item = player.getItemInHand();
CustomTool tool = ModChecks.getToolFromItemStack(item);
if (ItemChecks.isCustomTool(item)) {
xp = (int) (xp * ModChecks.getToolFromItemStack(item).getXpMultiplier());
if (tool != null) {
xp = (int) (xp * tool.getXpMultiplier());
}
}

View File

@ -181,7 +181,7 @@ public class BlockListener implements Listener {
}
if (PP.getAbilityMode(AbilityType.TREE_FELLER) && permInstance.treeFeller(player) && ItemChecks.isAxe(inHand)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
WoodCutting.treeFeller(event);
}
@ -255,7 +255,7 @@ public class BlockListener implements Listener {
* ABILITY TRIGGER CHECKS
*/
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && permInstance.greenTerra(player) && BlockChecks.makeMossy(block)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
Herbalism.greenTerra(player, block);
}
@ -267,7 +267,7 @@ public class BlockListener implements Listener {
else if (PP.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) {
if (configInstance.getExcavationRequiresTool()) {
if (ItemChecks.isShovel(inHand)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
@ -299,7 +299,7 @@ public class BlockListener implements Listener {
else if (PP.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
event.setInstaBreak(true);
Mining.superBreakerBlockCheck(player, block);

View File

@ -209,12 +209,12 @@ public class PlayerListener implements Listener {
event.setCancelled(true);
player.updateInventory();
}
else if (ItemChecks.isCustomTool(is) && ModChecks.getToolFromItemStack(is).isRepairable()) {
else if (ModChecks.isCustomTool(is) && ModChecks.getToolFromItemStack(is).isRepairable()) {
Repair.repairCheck(player, is);
event.setCancelled(true);
player.updateInventory();
}
else if (ItemChecks.isCustomArmor(is) && ModChecks.getArmorFromItemStack(is).isRepairable()) {
else if (ModChecks.isCustomArmor(is) && ModChecks.getArmorFromItemStack(is).isRepairable()) {
Repair.repairCheck(player, is);
event.setCancelled(true);
player.updateInventory();

View File

@ -16,8 +16,6 @@ import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomToolsConfig;
import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
@ -28,6 +26,7 @@ import com.gmail.nossr50.util.Users;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader;
@ -112,12 +111,8 @@ public class Repair {
/*
* REPAIR CUSTOM TOOLS
*/
else if (ItemChecks.isCustomTool(is) && permInstance.toolRepair(player)) {
CustomToolsConfig toolsInstance = CustomToolsConfig.getInstance();
for (CustomItem tool : toolsInstance.customItems) {
if (tool.getItemID() == is.getTypeId()) {
ItemStack repairMaterial = tool.getRepairMaterial();
else if (ModChecks.isCustomTool(is) && permInstance.toolRepair(player)) {
ItemStack repairMaterial = ModChecks.getToolFromItemStack(is).getRepairMaterial();
if (inventory.contains(repairMaterial)) {
repairCustomItem(player, is, repairMaterial);
@ -126,21 +121,13 @@ public class Repair {
else {
needMoreVespeneGas(is, player);
}
break;
}
}
}
/*
* REPAIR CUSTOM ARMOR
*/
else if (ItemChecks.isCustomArmor(is) && permInstance.armorRepair(player)) {
CustomArmorConfig armorInstance = CustomArmorConfig.getInstance();
for (CustomItem armor : armorInstance.customItems) {
if (armor.getItemID() == is.getTypeId()) {
ItemStack repairMaterial = armor.getRepairMaterial();
else if (ModChecks.isCustomArmor(is) && permInstance.armorRepair(player)) {
ItemStack repairMaterial = ModChecks.getArmorFromItemStack(is).getRepairMaterial();
if (inventory.contains(repairMaterial)) {
repairCustomItem(player, is, repairMaterial);
@ -149,10 +136,6 @@ public class Repair {
else {
needMoreVespeneGas(is, player);
}
break;
}
}
}
}
else {
@ -406,26 +389,16 @@ public class Repair {
int materialsRequired = 0;
int repairAmount = 0;
CustomToolsConfig toolInstance = CustomToolsConfig.getInstance();
CustomArmorConfig armorInstance = CustomArmorConfig.getInstance();
CustomTool tool = ModChecks.getToolFromItemStack(is);
CustomItem armor = ModChecks.getArmorFromItemStack(is);
if (ModChecks.getToolFromItemStack(is) != null) {
for (CustomItem tool : toolInstance.customItems) {
if (tool.getItemID() == is.getTypeId()) {
if (tool != null) {
maxDurability = tool.getDurability();
materialsRequired = tool.getRepairQuantity();
break;
}
}
}
else if (ModChecks.getArmorFromItemStack(is) != null) {
for (CustomItem armor : armorInstance.customItems) {
if (armor.getItemID() == is.getTypeId()) {
else if (armor != null) {
maxDurability = armor.getDurability();
materialsRequired = armor.getRepairQuantity();
break;
}
}
}
repairAmount = maxDurability / materialsRequired;

View File

@ -368,11 +368,9 @@ public class Combat {
private static void applyAbilityAoE(Player attacker, LivingEntity target, int damage, mcMMO plugin, SkillType type) {
ItemStack inHand = attacker.getItemInHand();
if (Config.getInstance().getToolModsEnabled()) {
if (ItemChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
if (ModChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
return;
}
}
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); //The higher the weapon tier, the more targets you hit
int damageAmount = damage;

View File

@ -242,21 +242,6 @@ public class ItemChecks {
return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is);
}
/**
* Checks to see if an item is custom armor.
*
* @param is Item to check
* @return true if the item is custom armor, false otherwise
*/
public static boolean isCustomArmor(ItemStack is) {
if (customArmorEnabled && CustomArmorConfig.getInstance().customIDs.contains(is.getTypeId())) {
return true;
}
else {
return false;
}
}
/**
* Checks to see if an item is a leather armor piece.
*
@ -343,21 +328,6 @@ public class ItemChecks {
return isStoneTool(is) || isWoodTool(is) || isGoldTool(is) || isIronTool(is) || isDiamondTool(is) || isStringTool(is);
}
/**
* Checks to see if an item is a custom tool.
*
* @param is Item to check
* @return true if the item is a custom tool, false otherwise
*/
public static boolean isCustomTool(ItemStack is) {
if (customToolsEnabled && CustomToolsConfig.getInstance().customIDs.contains(is.getTypeId())) {
return true;
}
else {
return false;
}
}
/**
* Checks to see if an item is a stone tool.
*

View File

@ -146,7 +146,7 @@ public class Misc {
else if (ItemChecks.isDiamondTool(inHand)) {
tier = 4;
}
else if (ItemChecks.isCustomTool(inHand)) {
else if (ModChecks.isCustomTool(inHand)) {
tier = ModChecks.getToolFromItemStack(inHand).getTier();
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.util;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomToolsConfig;
@ -11,6 +12,10 @@ import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.datatypes.mods.CustomTool;
public class ModChecks {
private static Config configInstance = Config.getInstance();
private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
private static CustomToolsConfig toolInstance = CustomToolsConfig.getInstance();
private static CustomArmorConfig armorInstance = CustomArmorConfig.getInstance();
private static CustomBlocksConfig blocksInstance = CustomBlocksConfig.getInstance();
@ -19,44 +24,20 @@ public class ModChecks {
* Get the custom armor associated with an item.
*
* @param item The item to check
* @return the ay if it exists, null otherwise
* @return the armor if it exists, null otherwise
*/
public static CustomItem getArmorFromItemStack(ItemStack item) {
int id = item.getTypeId();
if (!armorInstance.customIDs.contains(id)) {
return null;
}
for (CustomItem armor : armorInstance.customItems) {
if (armor.getItemID() == id) {
return armor;
}
}
return null;
return armorInstance.customArmor.get(item.getTypeId());
}
/**
* Get the custom tool associated with an item.
*
* @param item The item to check
* @return the armor if it exists, null otherwise
* @return the tool if it exists, null otherwise
*/
public static CustomTool getToolFromItemStack(ItemStack item) {
int id = item.getTypeId();
if (!toolInstance.customIDs.contains(id)) {
return null;
}
for (CustomItem tool : toolInstance.customItems) {
if (tool.getItemID() == id) {
return (CustomTool) tool;
}
}
return null;
return toolInstance.customTools.get(item.getTypeId());
}
/**
@ -123,4 +104,34 @@ public class ModChecks {
return false;
}
}
/**
* Checks to see if an item is a custom tool.
*
* @param is Item to check
* @return true if the item is a custom tool, false otherwise
*/
public static boolean isCustomTool(ItemStack item) {
if (customToolsEnabled && toolInstance.customTools.containsKey(item.getTypeId())) {
return true;
}
else {
return false;
}
}
/**
* Checks to see if an item is custom armor.
*
* @param is Item to check
* @return true if the item is custom armor, false otherwise
*/
public static boolean isCustomArmor(ItemStack item) {
if (customArmorEnabled && armorInstance.customArmor.containsKey(item.getTypeId())) {
return true;
}
else {
return false;
}
}
}