!Custom blocks refactor

This commit is contained in:
Indyuce 2020-04-04 13:08:29 +02:00
parent e6e0ba341d
commit ed419d7ce8
5 changed files with 208 additions and 226 deletions

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.api;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
@ -21,58 +22,84 @@ import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
public class CustomBlock {
MushroomState state;
private final MushroomState state;
private final int id;
private String blockName = ChatColor.RESET + "Custom Block";
private String templateName = "";
private List<String> lore = new ArrayList<String>();
private int minXP = 0;
private int maxXP = 0;
private int requiredPower = 0;
private final String blockName;
private final String templateName;
private final List<String> lore = new ArrayList<String>();
private final int minExp;
private final int maxExp;
private final int requiredPower;
public CustomBlock(int id, MushroomState state, ConfigurationSection config) {
this.id = id;
this.state = state;
if(config != null) {
if(config.contains("display-name")) blockName = ChatColor.translateAlternateColorCodes('&', config.getString("display-name"));
if(config.contains("lore"))
for(String s : config.getStringList("lore"))
lore.add(ChatColor.translateAlternateColorCodes('&', s));
if(config.contains("min-xp")) minXP = config.getInt("min-xp");
if(config.contains("max-xp")) maxXP = config.getInt("max-xp");
if(config.contains("required-power")) requiredPower = config.getInt("required-power");
if(config.contains("gen-template")) {
templateName = config.getString("gen-template");
MMOItems.plugin.getWorldGen().register(this);
}
}
Validate.notNull(config, "Could not read custom block config");
blockName = ChatColor.translateAlternateColorCodes('&', config.getString("display-name", ChatColor.RESET + "Custom Block"));
if (config.contains("lore"))
for (String s : config.getStringList("lore"))
lore.add(ChatColor.translateAlternateColorCodes('&', s));
minExp = config.getInt("min-xp", 0);
maxExp = config.getInt("max-xp", 0);
requiredPower = config.getInt("required-power", 0);
templateName = config.getString("gen-template", "");
MMOItems.plugin.getWorldGen().register(this);
}
//Depending on the id, return the mushroom type this block
//is supposed to feature.
public int getId() {
return id;
}
public String getName() {
return blockName;
}
public String getTemplateName() {
return templateName;
}
public List<String> getLore() {
return lore;
}
public int getMinXPDrop() {
return minExp;
}
public int getMaxXPDrop() {
return maxExp;
}
public int getRequiredPower() {
return requiredPower;
}
// Depending on the id, return the mushroom type this block
// is supposed to feature.
public Material getType() {
return MMOItems.plugin.getCustomBlocks().getType(id);
}
//From the Id, check which sides to apply data to.
//This will return the blockstate of the blocks id.
// From the Id, check which sides to apply data to.
// This will return the blockstate of the blocks id.
public BlockData getBlockData() {
MultipleFacing mfData = (MultipleFacing) getType().createBlockData();
mfData.setFace(BlockFace.UP, state.up);
mfData.setFace(BlockFace.DOWN, state.down);
mfData.setFace(BlockFace.NORTH, state.north);
mfData.setFace(BlockFace.SOUTH, state.south);
mfData.setFace(BlockFace.EAST, state.east);
mfData.setFace(BlockFace.WEST, state.west);
return mfData;
}
//Convert block data into Item
// Convert block data into Item
public ItemStack getItem() {
ItemStack item = new ItemStack(Material.CLAY_BALL);
ItemMeta meta = item.getItemMeta();
@ -81,64 +108,24 @@ public class CustomBlock {
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.values());
if(MMOLib.plugin.getVersion().isBelowOrEqual(1, 13)) ((Damageable) meta).setDamage(id);
item.setItemMeta(meta);
if (MMOLib.plugin.getVersion().isBelowOrEqual(1, 13))
((Damageable) meta).setDamage(id);
return MMOLib.plugin.getNMS().getNBTItem(item)
.addTag(new ItemTag("MMOITEMS_DISABLE_CRAFTING", true),
new ItemTag("MMOITEMS_DISABLE_SMITHING", true),
new ItemTag("MMOITEMS_DISABLE_ENCHANTING", true),
new ItemTag("MMOITEMS_DISABLE_REPAIRING", true),
new ItemTag("MMOITEMS_BLOCK_ID", id),
new ItemTag("CustomModelData", id + 1000))
.toItem();
}
public void reload() {
ConfigurationSection config = MMOItems.plugin.getCustomBlocks().getConfig().getConfigurationSection(id + "");
lore.clear();
if(config != null) {
blockName = ChatColor.translateAlternateColorCodes('&', config.getString("display-name", "&rCustom Block"));
for(String s : config.getStringList("lore"))
lore.add(ChatColor.translateAlternateColorCodes('&', s));
minXP = config.getInt("min-xp", 0);
maxXP = config.getInt("max-xp", 0);
requiredPower = config.getInt("required-power", 0);
templateName = config.getString("gen-template", "");
}
else {
blockName = ChatColor.RESET + "Custom Block";
templateName = "";
minXP = 0; maxXP = 0; requiredPower = 0;
}
item.setItemMeta(meta);
return MMOLib.plugin.getNMS().getNBTItem(item).addTag(new ItemTag("MMOITEMS_DISABLE_CRAFTING", true), new ItemTag("MMOITEMS_DISABLE_SMITHING", true), new ItemTag("MMOITEMS_DISABLE_ENCHANTING", true), new ItemTag("MMOITEMS_DISABLE_REPAIRING", true), new ItemTag("MMOITEMS_BLOCK_ID", id), new ItemTag("CustomModelData", id + 1000)).toItem();
}
//Gets a new CustomBlock instance from a mushroom blockstate.
// Gets a new CustomBlock instance from a mushroom blockstate.
public static CustomBlock getFromData(BlockData data) {
if(!MMOItems.plugin.getCustomBlocks().isMushroomBlock(data.getMaterial())) return null;
if(!(data instanceof MultipleFacing)) return null;
if (!MMOItems.plugin.getCustomBlocks().isMushroomBlock(data.getMaterial()))
return null;
if (!(data instanceof MultipleFacing))
return null;
MultipleFacing mfData = (MultipleFacing) data;
MushroomState state = new MushroomState(data.getMaterial(), mfData.hasFace(BlockFace.UP), mfData.hasFace(BlockFace.DOWN),
mfData.hasFace(BlockFace.WEST), mfData.hasFace(BlockFace.EAST), mfData.hasFace(BlockFace.SOUTH), mfData.hasFace(BlockFace.NORTH));
MushroomState state = new MushroomState(data.getMaterial(), mfData.hasFace(BlockFace.UP), mfData.hasFace(BlockFace.DOWN), mfData.hasFace(BlockFace.WEST), mfData.hasFace(BlockFace.EAST), mfData.hasFace(BlockFace.SOUTH), mfData.hasFace(BlockFace.NORTH));
BlockManager manager = MMOItems.plugin.getCustomBlocks();
return manager.isVanilla(state) ? null : manager.getBlock(state);
}
public int getId()
{ return id; }
public String getName()
{ return blockName; }
public String getTemplateName()
{ return templateName; }
public List<String> getLore()
{ return lore; }
public int getMinXPDrop()
{ return minXP; }
public int getMaxXPDrop()
{ return maxXP; }
public int getRequiredPower()
{ return requiredPower; }
}

View File

@ -3,27 +3,30 @@ package net.Indyuce.mmoitems.api.util;
import org.bukkit.Material;
public class MushroomState {
public Material id;
public boolean up, down, west, east, south, north;
public final Material id;
public final boolean up, down, west, east, south, north;
/*
* help generate an unique identifier that only depends on the parameters of
* a mushroom block. ids are unique because they correspond to one specific
* mushroom state
*/
public MushroomState(Material id, boolean up, boolean down, boolean west, boolean east, boolean south, boolean north) {
this.id = id;
this.up = up; this.down = down; this.west = west;
this.east = east; this.south = south; this.north = north;
this.up = up;
this.down = down;
this.west = west;
this.east = east;
this.south = south;
this.north = north;
}
public boolean equals(MushroomState state) {
return up == state.up && down == state.down && west == state.west &&
east == state.east && south == state.south && north == state.north;
}
public int getUniqueId() {
String i;
if(id == Material.BROWN_MUSHROOM_BLOCK) i = "0";
else if(id == Material.RED_MUSHROOM_BLOCK) i = "1";
else i = "2";
return Integer.parseInt(i + (up ? "1" : "0") + (down ? "1" : "0") + (west ? "1" : "0") +
(east ? "1" : "0") + (south ? "1" : "0") + (north ? "1" : "0"));
String first = id == Material.BROWN_MUSHROOM_BLOCK ? "0" : id == Material.RED_MUSHROOM_BLOCK ? "1" : "2";
return Integer.parseInt(first + (up ? "1" : "0") + (down ? "1" : "0") + (west ? "1" : "0") + (east ? "1" : "0") + (south ? "1" : "0") + (north ? "1" : "0"));
}
public boolean equals(MushroomState state) {
return up == state.up && down == state.down && west == state.west && east == state.east && south == state.south && north == state.north;
}
}

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmoitems.gui.edition;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -10,7 +8,6 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -21,6 +18,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.CustomBlock;
import net.Indyuce.mmoitems.api.edition.BlockChatEdition;
import net.Indyuce.mmoitems.api.item.plugin.ConfigItem;
@ -29,26 +27,25 @@ import net.Indyuce.mmoitems.gui.BlockBrowser;
import net.Indyuce.mmoitems.gui.PluginInventory;
public class BlockEdition extends PluginInventory {
public static Map<Integer, ConfigOptions> correspondingSlot = new HashMap<>();
FileConfiguration config;
CustomBlock block;
private final ConfigFile config = new ConfigFile("custom-blocks");
private final CustomBlock block;
private static Map<Integer, ConfigOptions> correspondingSlot = new HashMap<>();
static {
for (ConfigOptions configOptions : ConfigOptions.values())
correspondingSlot.put(configOptions.getSlot(), configOptions);
}
public BlockEdition(Player player, CustomBlock block) {
super(player);
this.block = block;
config = MMOItems.plugin.getCustomBlocks().getConfig();
if (correspondingSlot.isEmpty()) {
for (ConfigOptions configOptions : ConfigOptions.values()) {
correspondingSlot.put(configOptions.getSlot(), configOptions);
}
}
}
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, 54, ChatColor.UNDERLINE + "Block Edition: " );
Inventory inv = Bukkit.createInventory(this, 54, ChatColor.UNDERLINE + "Block Edition: ");
for (ConfigOptions configOptions : ConfigOptions.values()) {
ItemStack blockItem = new ItemStack(configOptions.getItem());
ItemMeta meta = blockItem.getItemMeta();
@ -56,16 +53,17 @@ public class BlockEdition extends PluginInventory {
meta.addItemFlags(ItemFlag.values());
List<String> eventLore = new ArrayList<String>();
eventLore.add("");
if(configOptions.path.equals("lore")) {
if (configOptions.path.equals("lore")) {
eventLore.add(ChatColor.GRAY + "- Current Value:");
List<String> loreList = config.getStringList(block.getId() + ".lore");
if(loreList.isEmpty()) eventLore.add(ChatColor.RED + "No lore.");
for(String lore : loreList)
List<String> loreList = config.getConfig().getStringList(block.getId() + ".lore");
if (loreList.isEmpty())
eventLore.add(ChatColor.RED + "No lore.");
for (String lore : loreList)
eventLore.add(ChatColor.GREEN + ChatColor.translateAlternateColorCodes('&', lore));
}
else eventLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN + (configOptions.format.equals("int") ? config.contains(block.getId() + "." + configOptions.path) ? ChatColor.GREEN + config.getString(block.getId() + "." + configOptions.path) : ChatColor.RED + "0" : ChatColor.translateAlternateColorCodes('&', config.getString(block.getId() + "." + configOptions.path, ChatColor.RED + "Default"))));
} else
eventLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN + (configOptions.format.equals("int") ? config.getConfig().contains(block.getId() + "." + configOptions.path) ? ChatColor.GREEN + config.getConfig().getString(block.getId() + "." + configOptions.path) : ChatColor.RED + "0" : ChatColor.translateAlternateColorCodes('&', config.getConfig().getString(block.getId() + "." + configOptions.path, ChatColor.RED + "Default"))));
eventLore.add("");
eventLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
eventLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove this value.");
@ -74,10 +72,10 @@ public class BlockEdition extends PluginInventory {
inv.setItem(configOptions.slot, blockItem);
}
ItemStack back = ConfigItem.BACK.getItem();
inv.setItem(40, back);
return inv;
}
@ -89,20 +87,19 @@ public class BlockEdition extends PluginInventory {
if (event.getInventory() != event.getClickedInventory() || !MMOUtils.isMetaItem(item, false))
return;
if(event.getSlot() == 40)
if (event.getSlot() == 40)
new BlockBrowser(player).open();
if (correspondingSlot.containsKey(event.getSlot())) {
if (event.getAction() == InventoryAction.PICKUP_ALL) {
ConfigOptions co = correspondingSlot.get(event.getSlot());
new BlockChatEdition(this, co, block.getId()).enable("Write in the chat the " + co.getChatFormat());
}
if (event.getAction() == InventoryAction.PICKUP_HALF) {
String path = correspondingSlot.get(event.getSlot()).getConfigPath();
config.set(block.getId() + "." + path, null);
try { config.save(new File(MMOItems.plugin.getDataFolder(), "custom-blocks.yml"));
} catch (IOException e) { e.printStackTrace(); }
config.getConfig().set(block.getId() + "." + path, null);
config.save();
MMOItems.plugin.getCustomBlocks().reload();
new BlockEdition(player, block).open();
@ -110,39 +107,44 @@ public class BlockEdition extends PluginInventory {
}
}
}
public enum ConfigOptions {
DISPLAY_NAME("display-name", Material.WRITABLE_BOOK, 11, "string"),
LORE("lore", Material.MAP, 13, "line"),
REQUIRED_PICKAXE_POWER("required-power", Material.IRON_PICKAXE, 15, "int"),
MIN_XP("min-xp", Material.EXPERIENCE_BOTTLE, 21, "int"),
MAX_XP("max-xp", Material.EXPERIENCE_BOTTLE, 23, "int"),
WORLD_GEN_TEMPLATE("gen-template", Material.GRASS_BLOCK, 31, "string"),
;
private final String path;
private final String format;
WORLD_GEN_TEMPLATE("gen-template", Material.GRASS_BLOCK, 31, "string"),;
private final String path, format;
private final Material item;
private final int slot;
ConfigOptions(String s1, Material m, int i, String s2) {
path = s1;
item = m;
slot = i;
format = s2;
ConfigOptions(String path, Material item, int slot, String format) {
this.path = path;
this.item = item;
this.slot = slot;
this.format = format;
}
public String getConfigPath() {
return path;
}
public String getFormat() {
return format;
}
public Material getItem() {
return item;
}
public int getSlot() {
return slot;
}
public String getConfigPath()
{ return path; }
public String getFormat()
{ return format; }
public Material getItem()
{ return item; }
public int getSlot()
{ return slot; }
public String getChatFormat() {
switch(format) {
switch (format) {
case "int":
return "desired number for this field.";
case "line":
@ -151,9 +153,9 @@ public class BlockEdition extends PluginInventory {
return "new value.";
}
}
public boolean whenInput(PluginInventory inv, String message, String path) {
switch(format) {
switch (format) {
case "int":
int value = 0;
try {
@ -162,31 +164,31 @@ public class BlockEdition extends PluginInventory {
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + message + " is not a valid number.");
return false;
}
setConfigValue(value, path);
setConfigValue(new ConfigFile("custom-blocks"), path, value);
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + name().replace("_", " ") + " successfully changed to " + value + ".");
break;
case "line":
FileConfiguration config = MMOItems.plugin.getCustomBlocks().getConfig();
List<String> lore = config.contains(path) ? config.getStringList(path) : new ArrayList<>();
ConfigFile config = new ConfigFile("custom-blocks");
List<String> lore = config.getConfig().contains(path) ? config.getConfig().getStringList(path) : new ArrayList<>();
lore.add(message);
setConfigValue(lore, path);
setConfigValue(config, path, lore);
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully added to " + message + " to block lore.");
break;
default:
setConfigValue(message, path);
setConfigValue(new ConfigFile("custom-blocks"), path, message);
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully changed value to " + message + ".");
break;
}
return true;
};
public void setConfigValue(Object value, String path) {
FileConfiguration config = MMOItems.plugin.getCustomBlocks().getConfig();
config.set(path, value);
try { config.save(new File(MMOItems.plugin.getDataFolder(), "custom-blocks.yml"));
} catch (IOException e) { e.printStackTrace(); }
/*
* handles config save and custom block manager reloading
*/
public void setConfigValue(ConfigFile config, String path, Object value) {
config.getConfig().set(path, value);
config.save();
MMOItems.plugin.getCustomBlocks().reload();
}
}

View File

@ -31,7 +31,9 @@ import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
public class CustomBlockListener implements Listener {
Random rnd = new Random();
private static final Random random = new Random();
private static final List<Material> mat = Arrays.asList(Material.GRASS, Material.TALL_GRASS, Material.SEAGRASS, Material.TALL_SEAGRASS, Material.FERN, Material.LARGE_FERN, Material.DEAD_BUSH, Material.SNOW);
public CustomBlockListener() {
if (MMOItems.plugin.getLanguage().replaceMushroomDrops)
@ -54,7 +56,7 @@ public class CustomBlockListener implements Listener {
CustomBlock block = CustomBlock.getFromData(event.getBlock().getBlockData());
if (block != null) {
event.setDropItems(false);
event.setExpToDrop(event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 : CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ? block.getMaxXPDrop() == 0 && block.getMinXPDrop() == 0 ? 0 : rnd.nextInt((block.getMaxXPDrop() - block.getMinXPDrop()) + 1) + block.getMinXPDrop() : 0);
event.setExpToDrop(event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 : CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ? block.getMaxXPDrop() == 0 && block.getMinXPDrop() == 0 ? 0 : random.nextInt((block.getMaxXPDrop() - block.getMinXPDrop()) + 1) + block.getMinXPDrop() : 0);
}
}
}
@ -70,8 +72,6 @@ public class CustomBlockListener implements Listener {
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(nbtItem.getInteger("MMOITEMS_BLOCK_ID"));
List<Material> mat = Arrays.asList(Material.GRASS, Material.TALL_GRASS, Material.SEAGRASS, Material.TALL_SEAGRASS, Material.FERN, Material.LARGE_FERN, Material.DEAD_BUSH, Material.SNOW);
Block modify = mat.contains(event.getClickedBlock().getType()) ? event.getClickedBlock() : event.getClickedBlock().getRelative(event.getBlockFace());
if (isStandingInside(event.getPlayer().getLocation(), modify.getLocation()))

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
@ -16,76 +17,65 @@ import net.Indyuce.mmoitems.api.CustomBlock;
import net.Indyuce.mmoitems.api.util.MushroomState;
public class BlockManager {
final static List<Integer> downIds = Arrays.asList(new Integer[] {23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,130,131,132,133,134,135,
136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160});
final static List<Integer> eastIds = Arrays.asList(new Integer[] {10,11,12,13,14,15,16,17,18,19,20,21,22,39,40,41,42,43,44,45,46,47,48,49,50,
51,52,53,59,60,61,62,63,64,65,66,67,68,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,115,116,117,118,119,120,121,122,123,124,125,126,
127,128,129,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160});
final static List<Integer> northIds = Arrays.asList(new Integer[] {4,5,6,7,8,9,16,17,18,19,20,21,22,31,32,33,34,35,36,37,38,47,48,49,50,51,52,
53,55,56,57,58,63,64,65,66,67,68,77,78,79,80,81,82,83,84,93,94,95,96,97,98,99,107,108,109,110,111,112,113,114,123,124,125,126,127,
128,129,138,139,140,141,142,143,144,145,154,155,156,157,158,159,160});
final static List<Integer> southIds = Arrays.asList(new Integer[] {2,3,6,7,8,9,13,14,15,19,20,21,22,27,28,29,30,35,36,37,38,43,44,45,46,51,52,
53,55,56,57,58,61,62,65,66,67,68,73,74,75,76,81,82,83,84,89,90,91,92,97,98,99,103,104,105,106,111,112,113,114,119,120,121,122,127,
128,129,134,135,136,137,142,143,144,145,150,151,152,153,158,159,160});
final static List<Integer> upIds = Arrays.asList(new Integer[] {8,9,12,15,18,21,22,25,26,29,30,33,34,37,38,41,42,45,46,49,50,53,57,58,60,62,
64,67,68,71,72,75,76,79,80,83,84,87,88,91,92,95,96,99,101,102,105,106,109,110,113,114,117,118,121,122,125,126,128,129,132,133,
136,137,140,141,144,145,148,149,152,153,156,157,160});
final static List<Integer> westIds = Arrays.asList(new Integer[] {1,3,5,7,9,11,12,14,15,17,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,
50,52,56,58,59,60,61,62,63,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,
124,126,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159});
FileConfiguration config;
private final static List<Integer> downIds = Arrays.asList(new Integer[] { 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> eastIds = Arrays.asList(new Integer[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> northIds = Arrays.asList(new Integer[] { 4, 5, 6, 7, 8, 9, 16, 17, 18, 19, 20, 21, 22, 31, 32, 33, 34, 35, 36, 37, 38, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 63, 64, 65, 66, 67, 68, 77, 78, 79, 80, 81, 82, 83, 84, 93, 94, 95, 96, 97, 98, 99, 107, 108, 109, 110, 111, 112, 113, 114, 123, 124, 125, 126, 127, 128, 129, 138, 139, 140, 141, 142, 143, 144, 145, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> southIds = Arrays.asList(new Integer[] { 2, 3, 6, 7, 8, 9, 13, 14, 15, 19, 20, 21, 22, 27, 28, 29, 30, 35, 36, 37, 38, 43, 44, 45, 46, 51, 52, 53, 55, 56, 57, 58, 61, 62, 65, 66, 67, 68, 73, 74, 75, 76, 81, 82, 83, 84, 89, 90, 91, 92, 97, 98, 99, 103, 104, 105, 106, 111, 112, 113, 114, 119, 120, 121, 122, 127, 128, 129, 134, 135, 136, 137, 142, 143, 144, 145, 150, 151, 152, 153, 158, 159, 160 });
private final static List<Integer> upIds = Arrays.asList(new Integer[] { 8, 9, 12, 15, 18, 21, 22, 25, 26, 29, 30, 33, 34, 37, 38, 41, 42, 45, 46, 49, 50, 53, 57, 58, 60, 62, 64, 67, 68, 71, 72, 75, 76, 79, 80, 83, 84, 87, 88, 91, 92, 95, 96, 99, 101, 102, 105, 106, 109, 110, 113, 114, 117, 118, 121, 122, 125, 126, 128, 129, 132, 133, 136, 137, 140, 141, 144, 145, 148, 149, 152, 153, 156, 157, 160 });
private final static List<Integer> westIds = Arrays.asList(new Integer[] { 1, 3, 5, 7, 9, 11, 12, 14, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 56, 58, 59, 60, 61, 62, 63, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159 });
private final Map<Integer, CustomBlock> customBlocks = new HashMap<>();
private final Map<Integer, Integer> mushroomStateValue = new HashMap<>();
public BlockManager() {
config = new ConfigFile("custom-blocks").getConfig();
for(int i = 1; i < 161; i++) {
if(i != 54) {
MushroomState state = new MushroomState(getType(i), upIds.contains(i), downIds.contains(i), westIds.contains(i),
eastIds.contains(i), southIds.contains(i), northIds.contains(i));
customBlocks.put(i, new CustomBlock(i, state, config.getConfigurationSection("" + i)));
mushroomStateValue.put(state.getUniqueId(), i);
}
}
}
public Material getType(int id) {
if(id < 54) return Material.BROWN_MUSHROOM_BLOCK;
else if(id > 99) return Material.MUSHROOM_STEM;
else return Material.RED_MUSHROOM_BLOCK;
reload();
}
public CustomBlock getBlock(int id) {
if(id > 0 && id < 161 && id != 54)
if (id > 0 && id < 161 && id != 54)
return customBlocks.get(id);
MMOItems.plugin.getLogger().warning("Invalid CustomBlock Id! " + id);
return null;
}
public CustomBlock getBlock(MushroomState state)
{ return customBlocks.get(mushroomStateValue.get(state.getUniqueId())); }
public void reload() {
for(CustomBlock block : customBlocks.values())
block.reload();
public CustomBlock getBlock(MushroomState state) {
return customBlocks.get(mushroomStateValue.get(state.getUniqueId()));
}
public Collection<CustomBlock> getAll()
{ return customBlocks.values(); }
public Set<Integer> getBlockIds()
{ return customBlocks.keySet(); }
public void reload() {
customBlocks.clear();
FileConfiguration config = new ConfigFile("custom-blocks").getConfig();
public FileConfiguration getConfig()
{ return config; }
for (int id = 1; id < 161; id++)
if (id != 54)
try {
MushroomState state = new MushroomState(getType(id), upIds.contains(id), downIds.contains(id), westIds.contains(id), eastIds.contains(id), southIds.contains(id), northIds.contains(id));
customBlocks.put(id, new CustomBlock(id, state, config.getConfigurationSection("" + id)));
mushroomStateValue.put(state.getUniqueId(), id);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load custom block " + id + ": " + exception.getMessage());
}
}
public Collection<CustomBlock> getAll() {
return customBlocks.values();
}
public Set<Integer> getBlockIds() {
return customBlocks.keySet();
}
public boolean isVanilla(MushroomState state) {
return !mushroomStateValue.containsKey(state.getUniqueId());
}
public boolean isMushroomBlock(Material type) {
return (type == Material.BROWN_MUSHROOM_BLOCK || type == Material.MUSHROOM_STEM || type == Material.RED_MUSHROOM_BLOCK);
return type == Material.BROWN_MUSHROOM_BLOCK || type == Material.MUSHROOM_STEM || type == Material.RED_MUSHROOM_BLOCK;
}
public Material getType(int id) {
return id < 54 ? Material.BROWN_MUSHROOM_BLOCK : id > 99 ? Material.MUSHROOM_STEM : Material.RED_MUSHROOM_BLOCK;
}
}