mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
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:
parent
6cbf87b52c
commit
5645bf7982
@ -8,6 +8,7 @@ Key:
|
||||
- Removal
|
||||
|
||||
Version 1.3.07
|
||||
+ Added ability to gain XP from custom blocks. Enable custom blocks in the config file, then enter the data in the blocks.yml file.
|
||||
+ Added ability to gain XP with custom tools. Enable custom tools in the config file, then enter the data in the tools.yml file.
|
||||
+ Added ability to repair custom tools. Enable custom tools in the config file, then enter the data in the tools.yml file.
|
||||
+ Added ability to repair custom armor. Enable custom armor in the config file, then enter the data in the armor.yml file.
|
||||
|
@ -0,0 +1,103 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||
|
||||
public class CustomBlocksConfig extends ModConfigLoader{
|
||||
private static CustomBlocksConfig instance;
|
||||
|
||||
public static CustomBlocksConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new CustomBlocksConfig(mcMMO.p);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
|
||||
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
|
||||
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
|
||||
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
|
||||
|
||||
public List<ItemStack> customItems = new ArrayList<ItemStack>();
|
||||
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
|
||||
|
||||
public CustomBlocksConfig(mcMMO plugin) {
|
||||
super(plugin, "blocks.yml");
|
||||
config = plugin.getBlocksConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveBlocksConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
plugin.getLogger().info("Loading mcMMO blocks.yml File...");
|
||||
|
||||
loadBlocks("Excavation", customExcavationBlocks);
|
||||
loadBlocks("Herbalism", customHerbalismBlocks);
|
||||
loadBlocks("Mining", customMiningBlocks);
|
||||
loadBlocks("Woodcutting", customWoodcuttingBlocks);
|
||||
}
|
||||
|
||||
private void loadBlocks(String skillType, List<ItemStack> blockList) {
|
||||
ConfigurationSection skillSection = config.getConfigurationSection(skillType);
|
||||
Set<String> skillConfigSet = skillSection.getKeys(false);
|
||||
Iterator<String> iterator = skillConfigSet.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String blockName = iterator.next();
|
||||
|
||||
int id = config.getInt(skillType + "." + blockName + ".ID", 0);
|
||||
byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
|
||||
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0);
|
||||
boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
|
||||
int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
|
||||
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
|
||||
|
||||
if (id == 0) {
|
||||
plugin.getLogger().warning("Missing ID. This block will be skipped.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dropItem && dropID == 0) {
|
||||
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
|
||||
dropItem = false;
|
||||
}
|
||||
|
||||
CustomBlock block;
|
||||
ItemStack itemDrop;
|
||||
ItemStack blockItem;
|
||||
|
||||
if (dropItem) {
|
||||
itemDrop = new ItemStack(dropID, 1, (short) 0, dropData);
|
||||
}
|
||||
else {
|
||||
itemDrop = new ItemStack(id, 1, (short) 0, data);
|
||||
}
|
||||
|
||||
block = new CustomBlock(itemDrop, xp, data, id);
|
||||
blockItem = new ItemStack(id, 1, (short) 0, data);
|
||||
|
||||
blockList.add(blockItem);
|
||||
customItems.add(blockItem);
|
||||
customBlocks.add(block);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,9 @@ public class LoadCustomArmor extends ModConfigLoader{
|
||||
public List<Integer> customHelmetIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
|
||||
|
||||
public List<Integer> customIDs = new ArrayList<Integer>();
|
||||
public List<CustomItem> customItems = new ArrayList<CustomItem>();
|
||||
|
||||
public LoadCustomArmor(mcMMO plugin) {
|
||||
super(plugin, "armor.yml");
|
||||
config = plugin.getArmorConfig();
|
||||
|
@ -9,6 +9,7 @@ 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 LoadCustomTools extends ModConfigLoader {
|
||||
@ -29,6 +30,9 @@ public class LoadCustomTools extends ModConfigLoader {
|
||||
public List<Integer> customShovelIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customSwordIDs = new ArrayList<Integer>();
|
||||
|
||||
public List<Integer> customIDs = new ArrayList<Integer>();
|
||||
public List<CustomItem> customItems = new ArrayList<CustomItem>();
|
||||
|
||||
private LoadCustomTools(mcMMO plugin) {
|
||||
super(plugin, "tools.yml");
|
||||
config = plugin.getToolsConfig();
|
||||
|
@ -1,16 +1,11 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomItem;
|
||||
|
||||
public abstract class ModConfigLoader extends ConfigLoader{
|
||||
public List<Integer> customIDs = new ArrayList<Integer>();
|
||||
public List<CustomItem> customItems = new ArrayList<CustomItem>();
|
||||
|
||||
public ModConfigLoader(mcMMO plugin, String fileName) {
|
||||
super(plugin, "ModConfigs" + File.separator + fileName);
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.gmail.nossr50.datatypes.mods;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CustomBlock {
|
||||
private int itemID;
|
||||
private byte dataValue;
|
||||
private int xpGain;
|
||||
private ItemStack itemDrop;
|
||||
|
||||
public CustomBlock(ItemStack itemDrop, int xpGain, byte dataValue, int itemID) {
|
||||
this.itemID = itemID;
|
||||
this.dataValue = dataValue;
|
||||
this.xpGain = xpGain;
|
||||
this.itemDrop = itemDrop;
|
||||
}
|
||||
|
||||
public int getItemID() {
|
||||
return itemID;
|
||||
}
|
||||
|
||||
public void setItemID(int itemID) {
|
||||
this.itemID = itemID;
|
||||
}
|
||||
|
||||
public byte getDataValue() {
|
||||
return dataValue;
|
||||
}
|
||||
|
||||
public void setDataValue(byte dataValue) {
|
||||
this.dataValue = dataValue;
|
||||
}
|
||||
|
||||
public int getXpGain() {
|
||||
return xpGain;
|
||||
}
|
||||
|
||||
public void setXpGain(int xpGain) {
|
||||
this.xpGain = xpGain;
|
||||
}
|
||||
|
||||
public ItemStack getItemDrop() {
|
||||
return itemDrop;
|
||||
}
|
||||
|
||||
public void setItemDrop(ItemStack itemDrop) {
|
||||
this.itemDrop = itemDrop;
|
||||
}
|
||||
}
|
@ -115,7 +115,7 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
|
||||
if (BlockChecks.shouldBeWatched(mat)) {
|
||||
if (BlockChecks.shouldBeWatched(block)) {
|
||||
mcMMO.placeStore.setTrue(block);
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ public class BlockListener implements Listener {
|
||||
|
||||
if (PP.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.getInstance().treeFeller(player) && ItemChecks.isAxe(inhand)) {
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.toolAbilityEnabled(inhand)) || !ItemChecks.isCustomTool(inhand)) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
|
||||
WoodCutting.treeFeller(event);
|
||||
}
|
||||
}
|
||||
@ -210,7 +210,7 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
//Remove metadata when broken
|
||||
if (mcMMO.placeStore.isTrue(block) && BlockChecks.shouldBeWatched(mat)) {
|
||||
if (mcMMO.placeStore.isTrue(block) && BlockChecks.shouldBeWatched(block)) {
|
||||
mcMMO.placeStore.setFalse(block);
|
||||
}
|
||||
}
|
||||
@ -261,7 +261,7 @@ public class BlockListener implements Listener {
|
||||
*/
|
||||
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && Permissions.getInstance().greenTerra(player) && BlockChecks.makeMossy(block)) {
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.toolAbilityEnabled(inhand)) || !ItemChecks.isCustomTool(inhand)) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
|
||||
Herbalism.greenTerra(player, block);
|
||||
}
|
||||
}
|
||||
@ -272,7 +272,7 @@ public class BlockListener implements Listener {
|
||||
else if (PP.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) {
|
||||
if (Config.getInstance().getExcavationRequiresTool() && ItemChecks.isShovel(inhand)) {
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.toolAbilityEnabled(inhand)) || !ItemChecks.isCustomTool(inhand)) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
|
||||
event.setInstaBreak(true);
|
||||
Excavation.gigaDrillBreaker(player, block);
|
||||
}
|
||||
@ -303,7 +303,7 @@ public class BlockListener implements Listener {
|
||||
if (!player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { //TODO: Why are we checking this?
|
||||
if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isPickaxe(inhand)) {
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.toolAbilityEnabled(inhand)) || !ItemChecks.isCustomTool(inhand)) {
|
||||
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
|
||||
event.setInstaBreak(true);
|
||||
Mining.SuperBreakerBlockCheck(player, block);
|
||||
}
|
||||
|
@ -498,4 +498,57 @@ public class mcMMO extends JavaPlugin {
|
||||
getLogger().severe("Could not save config to " + armorConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Boilerplate Custom Config Stuff (Blocks)
|
||||
*/
|
||||
|
||||
private FileConfiguration blocksConfig = null;
|
||||
private File blocksConfigFile = null;
|
||||
|
||||
/**
|
||||
* Reload the Blocks.yml file.
|
||||
*/
|
||||
public void reloadBlocksConfig() {
|
||||
if (blocksConfigFile == null) {
|
||||
blocksConfigFile = new File(modDirectory, "blocks.yml");
|
||||
}
|
||||
|
||||
blocksConfig = YamlConfiguration.loadConfiguration(blocksConfigFile);
|
||||
InputStream defConfigStream = getResource("blocks.yml"); // Look for defaults in the jar
|
||||
|
||||
if (defConfigStream != null) {
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
blocksConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Blocks config information.
|
||||
*
|
||||
* @return the configuration object for blocks.yml
|
||||
*/
|
||||
public FileConfiguration getBlocksConfig() {
|
||||
if (blocksConfig == null) {
|
||||
reloadBlocksConfig();
|
||||
}
|
||||
|
||||
return blocksConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Blocks config informtion.
|
||||
*/
|
||||
public void saveBlocksConfig() {
|
||||
if (blocksConfig == null || blocksConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
blocksConfig.save(blocksConfigFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
getLogger().severe("Could not save config to " + blocksConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,14 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.spout.SpoutSounds;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModChecks;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.LoadTreasures;
|
||||
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||
@ -45,7 +47,14 @@ public class Excavation {
|
||||
|
||||
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
|
||||
|
||||
int xp = Config.getInstance().getExcavationBaseXP();
|
||||
int xp;
|
||||
|
||||
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
xp = ModChecks.getCustomBlock(block).getXpGain();
|
||||
}
|
||||
else {
|
||||
xp = Config.getInstance().getExcavationBaseXP();
|
||||
}
|
||||
|
||||
if (Permissions.getInstance().excavationTreasures(player)) {
|
||||
switch (type) {
|
||||
|
@ -13,12 +13,14 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
||||
import com.gmail.nossr50.datatypes.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.GreenThumbTimer;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModChecks;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
@ -82,10 +84,13 @@ public class Herbalism {
|
||||
Byte data = block.getData();
|
||||
Location loc = block.getLocation();
|
||||
Material mat = null;
|
||||
|
||||
int xp = 0;
|
||||
int catciDrops = 0;
|
||||
int caneDrops = 0;
|
||||
|
||||
boolean customPlant = false;
|
||||
|
||||
switch (type) {
|
||||
case BROWN_MUSHROOM:
|
||||
case RED_MUSHROOM:
|
||||
@ -181,15 +186,26 @@ public class Herbalism {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
customPlant = true;
|
||||
xp = ModChecks.getCustomBlock(block).getXpGain();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (mat == null) {
|
||||
if (mat == null && !customPlant) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.getInstance().herbalismDoubleDrops(player)) {
|
||||
ItemStack is = new ItemStack(mat);
|
||||
ItemStack is = null;
|
||||
|
||||
if (customPlant) {
|
||||
is = new ItemStack(ModChecks.getCustomBlock(block).getItemDrop());
|
||||
}
|
||||
else {
|
||||
is = new ItemStack(mat);
|
||||
}
|
||||
|
||||
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
|
||||
Config configInstance = Config.getInstance();
|
||||
@ -264,6 +280,9 @@ public class Herbalism {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (customPlant) {
|
||||
Misc.mcDropItem(loc, is);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,12 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.spout.SpoutSounds;
|
||||
import com.gmail.nossr50.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModChecks;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
@ -128,6 +130,10 @@ public class Mining {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
item = ModChecks.getCustomBlock(block).getItemDrop();
|
||||
Misc.mcDropItem(loc, item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -198,6 +204,9 @@ public class Mining {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
xp += ModChecks.getCustomBlock(block).getXpGain();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
75
src/main/resources/blocks.yml
Normal file
75
src/main/resources/blocks.yml
Normal file
@ -0,0 +1,75 @@
|
||||
#
|
||||
# Settings for Custom Excavation Blocks
|
||||
###
|
||||
Excavation:
|
||||
Block_1:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
Block_2:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
|
||||
#
|
||||
# Settings for Custom Herbalism Blocks
|
||||
###
|
||||
Herbalism:
|
||||
Block_1:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
Block_2:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
|
||||
#
|
||||
# Settings for Custom Mining Blocks
|
||||
###
|
||||
Mining:
|
||||
Block_1:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
Block_2:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
|
||||
#
|
||||
# Settings for Custom Woodcutting Blocks
|
||||
###
|
||||
Woodcutting:
|
||||
Block_1:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
||||
Block_2:
|
||||
ID: 999
|
||||
Data_Value: 0
|
||||
XP_Gain: 99
|
||||
Drop_Item: false
|
||||
Drop_Item_ID: 999
|
||||
Drop_Item_Data_Value: 0
|
Loading…
Reference in New Issue
Block a user