Redo blocks.yml

** YOU WILL NEED TO UPDATE THIS FILE **
This commit is contained in:
GJ 2013-09-24 09:10:33 -04:00 committed by TfT_02
parent fc6c7bb1de
commit cf90236e57
4 changed files with 101 additions and 237 deletions

View File

@ -1,9 +1,11 @@
package com.gmail.nossr50.config.mods; package com.gmail.nossr50.config.mods;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
@ -14,17 +16,17 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlockConfig extends ConfigLoader { public class CustomBlockConfig extends ConfigLoader {
private static CustomBlockConfig instance; private static CustomBlockConfig instance;
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>(); public List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>(); public List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>(); public List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>(); public List<MaterialData> customWoodcuttingBlocks = new ArrayList<MaterialData>();
public List<ItemStack> customOres = new ArrayList<ItemStack>(); public List<MaterialData> customOres = new ArrayList<MaterialData>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>(); public List<MaterialData> customLogs = new ArrayList<MaterialData>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>(); public List<MaterialData> customLeaves = new ArrayList<MaterialData>();
public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>(); public List<MaterialData> customAbilityBlocks = new ArrayList<MaterialData>();
public List<ItemStack> customItems = new ArrayList<ItemStack>(); public List<MaterialData> customItems = new ArrayList<MaterialData>();
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>(); public HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
public CustomBlockConfig() { public CustomBlockConfig() {
super("ModConfigs", "blocks.yml"); super("ModConfigs", "blocks.yml");
@ -48,7 +50,7 @@ public class CustomBlockConfig extends ConfigLoader {
loadBlocks("Ability_Blocks", customAbilityBlocks); loadBlocks("Ability_Blocks", customAbilityBlocks);
} }
private void loadBlocks(String skillType, List<ItemStack> blockList) { private void loadBlocks(String skillType, List<MaterialData> blockList) {
ConfigurationSection skillSection = config.getConfigurationSection(skillType); ConfigurationSection skillSection = config.getConfigurationSection(skillType);
if (skillSection == null) { if (skillSection == null) {
@ -58,63 +60,65 @@ public class CustomBlockConfig extends ConfigLoader {
Set<String> skillConfigSet = skillSection.getKeys(false); Set<String> skillConfigSet = skillSection.getKeys(false);
for (String blockName : skillConfigSet) { for (String blockName : skillConfigSet) {
int id = config.getInt(skillType + "." + blockName + ".ID", 0); String[] blockInfo = blockName.split("[|]");
byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0); Material blockMaterial = Material.matchMaterial(blockInfo[0]);
if (blockMaterial == null) {
plugin.getLogger().warning("Invalid material name. This item will be skipped.");
continue;
}
byte blockData = Byte.valueOf(blockInfo[1]);
MaterialData blockMaterialData = new MaterialData(blockMaterial, blockData);
blockList.add(blockMaterialData);
if (skillType.equals("Ability_Blocks")) {
continue;
}
customItems.add(blockMaterialData);
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain");
int tier = config.getInt(skillType + "." + blockName + ".Tier", 1); int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0); boolean shouldDropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item");
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0); Material dropMaterial = Material.matchMaterial(config.getString(skillType + "." + blockName + ".Drop_Item_Name"));
if (shouldDropItem && dropMaterial == null) {
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
shouldDropItem = false;
}
ItemStack itemDrop;
if (shouldDropItem) {
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value");
itemDrop = (new MaterialData(dropMaterial, dropData)).toItemStack(1);
}
else {
itemDrop = blockMaterialData.toItemStack(1);
}
int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1); int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1); int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
CustomBlock block; CustomBlock block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, blockData, blockMaterial);
ItemStack itemDrop;
ItemStack blockItem;
if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped.");
continue;
}
if (skillType.equals("Ability_Blocks")) {
blockItem = (new MaterialData(id, data)).toItemStack(1);
blockList.add(blockItem);
continue;
}
if (dropItem && dropID == 0) {
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
dropItem = false;
}
if (dropItem) {
itemDrop = (new MaterialData(dropID, dropData)).toItemStack(1);
}
else {
itemDrop = (new MaterialData(id, data)).toItemStack(1);
}
block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id);
blockItem = (new MaterialData(id, data)).toItemStack(1);
if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
customOres.add(blockItem); customOres.add(blockMaterialData);
} }
else if (skillType.equals("Woodcutting")) { else if (skillType.equals("Woodcutting")) {
if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) {
customLogs.add(blockItem); customLogs.add(blockMaterialData);
} }
else { else {
customLeaves.add(blockItem); customLeaves.add(blockMaterialData);
block.setXpGain(0); // Leaves don't grant XP block.setXpGain(0); // Leaves don't grant XP
} }
} }
blockList.add(blockItem); customBlockMap.put(blockMaterialData, block);
customItems.add(blockItem);
customBlocks.add(block);
} }
} }
} }

View File

@ -1,9 +1,10 @@
package com.gmail.nossr50.datatypes.mods; package com.gmail.nossr50.datatypes.mods;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class CustomBlock { public class CustomBlock {
private int itemID; private Material type;
private byte dataValue; private byte dataValue;
private int xpGain; private int xpGain;
private int tier; private int tier;
@ -11,8 +12,8 @@ public class CustomBlock {
private int minimumDropAmount; private int minimumDropAmount;
private int maximumDropAmount; private int maximumDropAmount;
public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int tier, int xpGain, byte dataValue, int itemID) { public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int tier, int xpGain, byte dataValue, Material type) {
this.itemID = itemID; this.type = type;
this.dataValue = dataValue; this.dataValue = dataValue;
this.xpGain = xpGain; this.xpGain = xpGain;
this.tier = tier; this.tier = tier;
@ -21,12 +22,12 @@ public class CustomBlock {
this.maximumDropAmount = maximumDropAmount; this.maximumDropAmount = maximumDropAmount;
} }
public int getItemID() { public Material getType() {
return itemID; return type;
} }
public void setItemID(int itemID) { public void setType(Material type) {
this.itemID = itemID; this.type = type;
} }
public byte getDataValue() { public byte getDataValue() {

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.util;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomArmorConfig; import com.gmail.nossr50.config.mods.CustomArmorConfig;
@ -41,19 +40,7 @@ public final class ModUtils {
* @return the block if it exists, null otherwise * @return the block if it exists, null otherwise
*/ */
public static CustomBlock getCustomBlock(BlockState blockState) { public static CustomBlock getCustomBlock(BlockState blockState) {
if (customBlocksEnabled) { return CustomBlockConfig.getInstance().customBlockMap.get(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customItems.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return block;
}
}
}
}
return null;
} }
public static CustomEntity getCustomEntity(Entity entity) { public static CustomEntity getCustomEntity(Entity entity) {
@ -74,22 +61,10 @@ public final class ModUtils {
* Check if a custom block is a woodcutting block. * Check if a custom block is a woodcutting block.
* *
* @param blockState The BlockState of the block to check * @param blockState The BlockState of the block to check
* @return true if the block represents a log, false otherwise * @return true if the block represents a custom woodcutting block, false otherwise
*/ */
public static boolean isCustomWoodcuttingBlock(BlockState blockState) { public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customWoodcuttingBlocks.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
@ -99,85 +74,37 @@ public final class ModUtils {
* @return true if the block represents an ability block, false otherwise * @return true if the block represents an ability block, false otherwise
*/ */
public static boolean isCustomAbilityBlock(BlockState blockState) { public static boolean isCustomAbilityBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customAbilityBlocks.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customAbilityBlocks.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
* Check if a custom block is a mining block. * Check if a custom block is a mining block.
* *
* @param blockState The BlockState of the block to check * @param blockState The BlockState of the block to check
* @return true if the block is custom, false otherwise * @return true if the block represents a custom mining block, false otherwise
*/ */
public static boolean isCustomMiningBlock(BlockState blockState) { public static boolean isCustomMiningBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customMiningBlocks.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customMiningBlocks.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
* Check if a custom block is an excavation block. * Check if a custom block is an excavation block.
* *
* @param blockState The BlockState of the block to check * @param blockState The BlockState of the block to check
* @return true if the block is custom, false otherwise * @return true if the block represents a custom excavation block, false otherwise
*/ */
public static boolean isCustomExcavationBlock(BlockState blockState) { public static boolean isCustomExcavationBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customExcavationBlocks.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customExcavationBlocks.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
* Check if a custom block is an herbalism block. * Check if a custom block is an herbalism block.
* *
* @param blockState The block to check * @param blockState The BlockState of the block to check
* @return true if the block is custom, false otherwise * @return true if the block represents a custom herbalism block, false otherwise
*/ */
public static boolean isCustomHerbalismBlock(BlockState blockState) { public static boolean isCustomHerbalismBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customHerbalismBlocks.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customHerbalismBlocks.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
@ -187,19 +114,7 @@ public final class ModUtils {
* @return true if the block represents leaves, false otherwise * @return true if the block represents leaves, false otherwise
*/ */
public static boolean isCustomLeafBlock(BlockState blockState) { public static boolean isCustomLeafBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customLeaves.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customLeaves.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
@ -209,41 +124,17 @@ public final class ModUtils {
* @return true if the block represents a log, false otherwise * @return true if the block represents a log, false otherwise
*/ */
public static boolean isCustomLogBlock(BlockState blockState) { public static boolean isCustomLogBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customLogs.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customLogs.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
* Check if a custom block is an ore block. * Check if a custom block is an ore block.
* *
* @param blockState The block to check * @param blockState The BlockState of the block to check
* @return true if the block represents an ore, false otherwise * @return true if the block represents an ore, false otherwise
*/ */
public static boolean isCustomOreBlock(BlockState blockState) { public static boolean isCustomOreBlock(BlockState blockState) {
if (customBlocksEnabled) { return customBlocksEnabled && CustomBlockConfig.getInstance().customOres.contains(blockState.getData());
ItemStack item = blockState.getData().toItemStack(1);
if (CustomBlockConfig.getInstance().customOres.contains(item)) {
for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
return true;
}
}
}
}
return false;
} }
/** /**
@ -253,11 +144,7 @@ public final class ModUtils {
* @return true if the item is a custom tool, false otherwise * @return true if the item is a custom tool, false otherwise
*/ */
public static boolean isCustomTool(ItemStack item) { public static boolean isCustomTool(ItemStack item) {
if (customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType())) { return customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType());
return true;
}
return false;
} }
/** /**
@ -267,19 +154,11 @@ public final class ModUtils {
* @return true if the item is custom armor, false otherwise * @return true if the item is custom armor, false otherwise
*/ */
public static boolean isCustomArmor(ItemStack item) { public static boolean isCustomArmor(ItemStack item) {
if (customArmorEnabled && CustomArmorConfig.getInstance().customArmor.contains(item.getType())) { return customArmorEnabled && CustomArmorConfig.getInstance().customArmor.contains(item.getType());
return true;
}
return false;
} }
public static boolean isCustomEntity(Entity entity) { public static boolean isCustomEntity(Entity entity) {
if (customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId())) { return customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId());
return true;
}
return false;
} }
/** /**

View File

@ -2,21 +2,17 @@
# Settings for Custom Excavation Blocks # Settings for Custom Excavation Blocks
### ###
Excavation: Excavation:
Block_1: Block_1|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
Block_2: Block_2|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
@ -25,21 +21,17 @@ Excavation:
# Settings for Custom Herbalism Blocks # Settings for Custom Herbalism Blocks
### ###
Herbalism: Herbalism:
Block_1: Block_1|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
Block_2: Block_2|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
@ -48,25 +40,21 @@ Herbalism:
# Settings for Custom Mining Blocks # Settings for Custom Mining Blocks
### ###
Mining: Mining:
Block_1: Block_1|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Is_Ore: true Is_Ore: true
Tier: 1 Tier: 1
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
Block_2: Block_2|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Is_Ore: true Is_Ore: true
Tier: 1 Tier: 1
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
@ -75,23 +63,19 @@ Mining:
# Settings for Custom Woodcutting Blocks # Settings for Custom Woodcutting Blocks
### ###
Woodcutting: Woodcutting:
Block_1: Block_1|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Is_Log: true Is_Log: true
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
Block_2: Block_2|0:
ID: 999
Data_Value: 0
XP_Gain: 99 XP_Gain: 99
Is_Log: true Is_Log: true
Drop_Item: false Drop_Item: false
Drop_Item_ID: 999 Drop_Item_Name: BLOCK_DROP
Drop_Item_Data_Value: 0 Drop_Item_Data_Value: 0
Min_Drop_Item_Amount: 1 Min_Drop_Item_Amount: 1
Max_Drop_Item_Amount: 1 Max_Drop_Item_Amount: 1
@ -101,9 +85,5 @@ Woodcutting:
# (These blocks don't trigger abilities) # (These blocks don't trigger abilities)
### ###
Ability_Blocks: Ability_Blocks:
Block_1: Block_1|0:
ID: 999 Block_2|0:
Data_Value: 0
Block_2:
ID: 999
Data_Value: 0