Mod support - XP gain & double drops should now work for custom blocks

EXCEPT Woodcutting. Custom excavation blocks will also never drop
treasures.
This commit is contained in:
GJ
2012-05-17 00:24:33 -04:00
parent 6cbf87b52c
commit 5645bf7982
15 changed files with 395 additions and 45 deletions

View File

@ -1,11 +1,14 @@
package com.gmail.nossr50.util;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
public class BlockChecks {
private static Config configInstance = Config.getInstance();
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
/**
* Checks to see if a block type awards XP.
@ -13,8 +16,8 @@ public class BlockChecks {
* @param block Block to check
* @return true if the block type awards XP, false otherwise
*/
public static boolean shouldBeWatched(Material material) {
switch (material) {
public static boolean shouldBeWatched(Block block) {
switch (block.getType()) {
case BROWN_MUSHROOM:
case CACTUS:
case CLAY:
@ -50,7 +53,12 @@ public class BlockChecks {
return true;
default:
return false;
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return true;
}
else {
return false;
}
}
}
@ -158,7 +166,12 @@ public class BlockChecks {
return true;
default:
return false;
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return true;
}
else {
return false;
}
}
}
@ -187,7 +200,12 @@ public class BlockChecks {
return true;
default:
return false;
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return true;
}
else {
return false;
}
}
}
@ -209,7 +227,12 @@ public class BlockChecks {
return true;
default:
return false;
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return true;
}
else {
return false;
}
}
}
@ -227,7 +250,12 @@ public class BlockChecks {
return true;
default:
return false;
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return true;
}
else {
return false;
}
}
}
}

View File

@ -369,7 +369,7 @@ public class Combat {
ItemStack inHand = attacker.getItemInHand();
if (Config.getInstance().getToolModsEnabled()) {
if (ItemChecks.isCustomTool(inHand) && !ModChecks.toolAbilityEnabled(inHand)) {
if (ItemChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
return;
}
}

View File

@ -1,37 +1,19 @@
package com.gmail.nossr50.util;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
import com.gmail.nossr50.config.mods.LoadCustomArmor;
import com.gmail.nossr50.config.mods.LoadCustomTools;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.datatypes.mods.CustomTool;
public class ModChecks {
private static LoadCustomTools toolInstance = LoadCustomTools.getInstance();
private static LoadCustomArmor armorInstance = LoadCustomArmor.getInstance();
/**
* Check if this custom tool can use abilities.
*
* @param item The custom item to check
* @return true if the tool can use abilities, false otherwise
*/
public static boolean toolAbilityEnabled(ItemStack item) {
int id = item.getTypeId();
if (!toolInstance.customIDs.contains(id)) {
return false;
}
for (CustomItem tool : toolInstance.customItems) {
if (tool.getItemID() == id) {
return ((CustomTool) tool).isAbilityEnabled();
}
}
return false;
}
private static CustomBlocksConfig blocksInstance = CustomBlocksConfig.getInstance();
/**
* Get the custom armor associated with an item.
@ -76,4 +58,24 @@ public class ModChecks {
return null;
}
/**
* Get the custom block associated with an block.
*
* @param block The block to check
* @return the armor if it exists, null otherwise
*/
public static CustomBlock getCustomBlock(Block block) {
if (!blocksInstance.customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return null;
}
for (CustomBlock b : blocksInstance.customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return b;
}
}
return null;
}
}