diff --git a/lib/MMOItems Premium.jar b/lib/MMOItems Premium.jar index f989f6c0..f0a93313 100644 Binary files a/lib/MMOItems Premium.jar and b/lib/MMOItems Premium.jar differ diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 556714af..4d0dd3a8 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -136,6 +136,7 @@ public class MMOCore extends JavaPlugin { public final MMOLoadManager loadManager = new MMOLoadManager(); public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler(); + private boolean miLoaded; public void onLoad() { plugin = this; @@ -354,6 +355,8 @@ public class MMOCore extends JavaPlugin { } }.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave); } + + miLoaded = Bukkit.getPluginManager().isPluginEnabled("MMOItems"); } public void onDisable() { @@ -431,4 +434,8 @@ public class MMOCore extends JavaPlugin { public boolean hasEconomy() { return economy != null && economy.isValid(); } + + public boolean isMILoaded() { + return miLoaded; + } } diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 1bfda7fb..d05247b0 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -20,6 +20,8 @@ import net.Indyuce.mmocore.api.event.CustomBlockMineEvent; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo; import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.CustomBlock; public class BlockListener implements Listener { private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH }; @@ -62,7 +64,7 @@ public class BlockListener implements Listener { return; } - if (!perms.canMine(block.getType())) { + if (!perms.canMine(getBlockName(block))) { MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player); event.setCancelled(true); return; @@ -105,6 +107,17 @@ public class BlockListener implements Listener { } } + private String getBlockName(Block block) { + if(MMOCore.plugin.isMILoaded()) + if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) { + CustomBlock cblock = CustomBlock.getFromData(block.getBlockData()); + if(cblock != null) + return "MICUSTOM_" + cblock.getId(); + } + + return block.getType().toString(); + } + @EventHandler(priority = EventPriority.HIGH) public void b(BlockPlaceEvent event) { event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true)); diff --git a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index 6388ddc7..ed2be513 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -1,7 +1,6 @@ package net.Indyuce.mmocore.listener; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -15,6 +14,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import com.codingforcookies.armorequip.ArmorEquipEvent; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.event.PlayerAttackEvent; import net.Indyuce.mmocore.api.event.PlayerCombatEvent; import net.Indyuce.mmocore.api.player.PlayerData; @@ -102,7 +102,7 @@ public class PlayerListener implements Listener { double damage = event.getDamage(); double d = 1, s = 1; - if(Bukkit.getPluginManager().isPluginEnabled("MMOItems")) + if(MMOCore.plugin.isMILoaded()) for (DamageType type : event.getDamageInfo().getTypes()) s += (net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayer()).getStats() .getStat(AttackResult.DamageType.valueOf(type.name()).getStat()) / 100); diff --git a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java index 633efa9d..c292f304 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java @@ -28,6 +28,8 @@ import net.Indyuce.mmocore.api.load.MMOLoadException; import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.version.VersionMaterial; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.CustomBlock; public class CustomBlockManager extends MMOManager { private final Map map = new HashMap<>(); @@ -40,7 +42,7 @@ public class CustomBlockManager extends MMOManager { for (String key : config.getKeys(false)) try { BlockInfo info = new BlockInfo(config.getConfigurationSection(key)); - register(info.getHeadValue().isEmpty() ? info.getBlock().name() : info.getHeadValue(), info); + register(info.getHeadValue().isEmpty() ? info.getCustomBlockID() > 0 ? "mi-custom-" + info.getCustomBlockID() : info.getBlock().name() : info.getHeadValue(), info); } catch (IllegalArgumentException exception) { MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage()); } @@ -55,7 +57,13 @@ public class CustomBlockManager extends MMOManager { String skullValue = MMOCore.plugin.nms.getSkullValue(block); return map.getOrDefault(skullValue, map.getOrDefault(block.getType().name(), null)); } - + if(MMOCore.plugin.isMILoaded()) + if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) { + CustomBlock cblock = CustomBlock.getFromData(block.getBlockData()); + if(block != null) + return map.getOrDefault("mi-custom-" + cblock.getId(), map.getOrDefault(block.getType().name(), null)); + } + return map.getOrDefault(block.getType().name(), null); } @@ -70,7 +78,12 @@ public class CustomBlockManager extends MMOManager { public void initialize(RegenInfo info) { active.add(info); - info.getLocation().getBlock().setType(info.getRegen().getTemporaryBlock()); + if(MMOCore.plugin.isMILoaded() && info.getRegen().getCustomRegenBlockID() != 0) { + CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(info.getRegen().getCustomRegenBlockID()); + info.getLocation().getBlock().setType(block.getType()); + info.getLocation().getBlock().setBlockData(block.getBlockData()); + } + else info.getLocation().getBlock().setType(info.getRegen().getTemporaryBlock()); if(isPlayerSkull(info.getLocation().getBlock().getType())) { if(isPlayerSkull(info.getRegen().getBlock())) info.getLocation().getBlock().setBlockData(info.getBlockData()); MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getRegenHeadValue()); @@ -116,23 +129,27 @@ public class CustomBlockManager extends MMOManager { private final List triggers = new ArrayList<>(); private final ExperienceTrigger experience; + private final int customBlockId; /* * options for block regen. */ private Material temporary; private int regenTime = -1; + private int regenCustomBlockId; private String regenHeadValue; public BlockInfo(ConfigurationSection config) { Validate.notNull(config, "Could not load config"); block = Material.valueOf(config.getString("material", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_")); + customBlockId = config.getInt("mi-custom-block", 0); headValue = config.getString("head-value", ""); table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null; vanillaDrops = config.getBoolean("vanilla-drops", true); if (config.contains("regen")) { temporary = Material.valueOf(config.getString("regen.temp-block", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_")); + regenCustomBlockId = config.getInt("regen.mi-custom-block", 0); regenHeadValue = config.getString("regen.head-value", ""); regenTime = config.getInt("regen.time"); @@ -197,6 +214,14 @@ public class CustomBlockManager extends MMOManager { public RegenInfo generateRegenInfo(BlockData data, Location loc) { return new RegenInfo(data, loc, this); } + + public int getCustomBlockID() { + return customBlockId; + } + + public int getCustomRegenBlockID() { + return regenCustomBlockId; + } public boolean hasExperience() { return experience != null; diff --git a/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java b/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java index 24f488c6..71f01263 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java @@ -14,7 +14,7 @@ import org.bukkit.configuration.file.FileConfiguration; import net.Indyuce.mmocore.MMOCore; public class RestrictionManager { - private Set breakBlackList = new HashSet<>(); + private Set breakBlackList = new HashSet<>(); private Map map = new HashMap<>(); public RestrictionManager(FileConfiguration config) { @@ -41,8 +41,8 @@ public class RestrictionManager { } } - public boolean isBlackListed(Material material) { - return breakBlackList.contains(material); + public boolean isBlackListed(String s) { + return breakBlackList.contains(s); } public BlockPermissions getPermissions(Material tool) { @@ -50,7 +50,7 @@ public class RestrictionManager { } public class BlockPermissions { - private final Set canMine = new HashSet<>(); + private final Set canMine = new HashSet<>(); private final Material tool; private BlockPermissions parent; @@ -80,7 +80,7 @@ public class RestrictionManager { } for (String key : loaded.getStringList("can-mine")) - canMine.add(Material.valueOf(key.toUpperCase().replace("-", "_"))); + canMine.add(key.toUpperCase().replace("-", "_")); loaded = null; } @@ -89,17 +89,17 @@ public class RestrictionManager { this.parent = parent; } - public void addPermission(Material material) { - canMine.add(material); + public void addPermission(String s) { + canMine.add(s); } // recursive function to check for parent permissions - public boolean canMine(Material material) { + public boolean canMine(String material) { return canMine.contains(material) || (parent != null && parent.canMine(material)); } - public Set getMinable() { - Set total = new HashSet<>(canMine); + public Set getMinable() { + Set total = new HashSet<>(canMine); if (parent != null) total.addAll(parent.getMinable()); return total;