mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02: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:
@ -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);
|
||||
|
Reference in New Issue
Block a user