diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 28cdfdb8..e9964c3f 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -9,6 +9,7 @@ import java.util.UUID; import java.util.logging.Level; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.attribute.Attribute; import org.bukkit.command.CommandMap; import org.bukkit.configuration.file.FileConfiguration; @@ -95,7 +96,6 @@ import net.Indyuce.mmocore.manager.social.PartyManager; import net.Indyuce.mmocore.manager.social.RequestManager; import net.Indyuce.mmocore.version.ServerVersion; import net.Indyuce.mmocore.version.nms.NMSHandler; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -217,7 +217,7 @@ public class MMOCore extends JavaPlugin { Bukkit.getServer().getPluginManager().registerEvents(new MythicMobsDrops(), this); getLogger().log(Level.INFO, "Hooked onto MythicMobs"); } - + /* * resource regeneration. must check if entity is dead otherwise regen * will make the 'respawn' button glitched plus HURT entity effect bug @@ -240,49 +240,50 @@ public class MMOCore extends JavaPlugin { } } }.runTaskTimerAsynchronously(MMOCore.plugin, 100, 20); - - //For the sake of the lord, make sure they aren't using MMOItems Mana and Stamina Addon... - //This should prevent a couple error reports produced by people not reading the installation guide... - if(Bukkit.getPluginManager().getPlugin("MMOItemsMana") != null) { - new BukkitRunnable() { - public void run() { - Bukkit.broadcastMessage(ChatColor.DARK_RED + "MMOCore is not compatible with the Mana and Stamina addon of MMOItems!!!"); - Bukkit.broadcastMessage(ChatColor.DARK_RED + "Please read the installation guide!"); - } - }.runTaskTimer(MMOCore.plugin, 1200, 1200); + + /* + * For the sake of the lord, make sure they aren't using MMOItems Mana + * and Stamina Addon...This should prevent a couple error reports + * produced by people not reading the installation guide... + */ + if (Bukkit.getPluginManager().getPlugin("MMOItemsMana") != null) { + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with the Mana & Stamina MMOItems!!!"); + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!"); + Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with the Mana & Stamina MMOItems!!!"); + Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!"); + return; } - + saveDefaultConfig(); reloadPlugin(); /* - * default action bar. - * only ran if the action bar is enabled + * default action bar. only ran if the action bar is enabled */ - if(getConfig().getBoolean("action-bar.enabled")) { + if (getConfig().getBoolean("action-bar.enabled")) { DecimalFormat format = new DecimalFormat(getConfig().getString("action-bar.decimal"), configManager.formatSymbols); int ticks = getConfig().getInt("action-bar.ticks-to-update"); - + new BukkitRunnable() { public void run() { - //System.out.println("Tick!"); - for (PlayerData data : PlayerData.getAll()) { - if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && !pausePlayers.contains(data.getUniqueId())) { - //System.out.println("Display!"); - data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(placeholderParser.parse(data.getPlayer(), ChatColor.translateAlternateColorCodes('&', getConfig().getString("action-bar.format") - .replace("{health}", format.format(data.getPlayer().getHealth())).replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getStats().getStat(StatType.MAX_HEALTH))) - .replace("{mana}", format.format(data.getMana())).replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA))) - .replace("{stamina}", format.format(data.getStamina())).replace("{max_stamina}", "" + StatType.MAX_STAMINA.format(data.getStats().getStat(StatType.MAX_STAMINA))) - .replace("{stellium}", format.format(data.getStellium())).replace("{max_stellium}", "" + StatType.MAX_STELLIUM.format(data.getStats().getStat(StatType.MAX_STELLIUM))) - .replace("{class}", data.getProfess().getName()).replace("{xp}", "" + data.getExperience()).replace("{armor}", "" + StatType.ARMOR.format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())) - .replace("{level}", "" + data.getLevel()).replace("{name}", data.getPlayer().getDisplayName()))))); + if (!data.isCasting() && !pausePlayers.contains(data.getUniqueId())) { + data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(placeholderParser.parse(data.getPlayer(), + ChatColor.translateAlternateColorCodes('&', getConfig().getString("action-bar.format").replace("{health}", format.format(data.getPlayer().getHealth())) + .replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getStats().getStat(StatType.MAX_HEALTH))).replace("{mana}", format.format(data.getMana())) + .replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA))).replace("{stamina}", format.format(data.getStamina())) + .replace("{max_stamina}", "" + StatType.MAX_STAMINA.format(data.getStats().getStat(StatType.MAX_STAMINA))) + .replace("{stellium}", format.format(data.getStellium())) + .replace("{max_stellium}", "" + StatType.MAX_STELLIUM.format(data.getStats().getStat(StatType.MAX_STELLIUM))) + .replace("{class}", data.getProfess().getName()).replace("{xp}", "" + data.getExperience()) + .replace("{armor}", "" + StatType.ARMOR.format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())).replace("{level}", "" + data.getLevel()) + .replace("{name}", data.getPlayer().getDisplayName()))))); } } } }.runTaskTimerAsynchronously(MMOCore.plugin, 100, ticks); } - + /* * enable debug mode for extra debug tools. */ @@ -324,28 +325,38 @@ public class MMOCore extends JavaPlugin { // commands try { final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); - + bukkitCommandMap.setAccessible(true); CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); - + FileConfiguration config = new ConfigFile("commands").getConfig(); - - if(config.contains("player")) commandMap.register("mmocore", new PlayerStatsCommand(config.getConfigurationSection("player"))); - if(config.contains("attributes")) commandMap.register("mmocore", new AttributesCommand(config.getConfigurationSection("attributes"))); - if(config.contains("class")) commandMap.register("mmocore", new ClassCommand(config.getConfigurationSection("class"))); - if(config.contains("waypoints")) commandMap.register("mmocore", new WaypointsCommand(config.getConfigurationSection("waypoints"))); - if(config.contains("quests")) commandMap.register("mmocore", new QuestsCommand(config.getConfigurationSection("quests"))); - if(config.contains("skills")) commandMap.register("mmocore", new SkillsCommand(config.getConfigurationSection("skills"))); - if(config.contains("friends")) commandMap.register("mmocore", new FriendsCommand(config.getConfigurationSection("friends"))); - if(config.contains("party")) commandMap.register("mmocore", new PartyCommand(config.getConfigurationSection("party"))); - if(config.contains("guild")) commandMap.register("mmocore", new GuildCommand(config.getConfigurationSection("guild"))); + + if (config.contains("player")) + commandMap.register("mmocore", new PlayerStatsCommand(config.getConfigurationSection("player"))); + if (config.contains("attributes")) + commandMap.register("mmocore", new AttributesCommand(config.getConfigurationSection("attributes"))); + if (config.contains("class")) + commandMap.register("mmocore", new ClassCommand(config.getConfigurationSection("class"))); + if (config.contains("waypoints")) + commandMap.register("mmocore", new WaypointsCommand(config.getConfigurationSection("waypoints"))); + if (config.contains("quests")) + commandMap.register("mmocore", new QuestsCommand(config.getConfigurationSection("quests"))); + if (config.contains("skills")) + commandMap.register("mmocore", new SkillsCommand(config.getConfigurationSection("skills"))); + if (config.contains("friends")) + commandMap.register("mmocore", new FriendsCommand(config.getConfigurationSection("friends"))); + if (config.contains("party")) + commandMap.register("mmocore", new PartyCommand(config.getConfigurationSection("party"))); + if (config.contains("guild")) + commandMap.register("mmocore", new GuildCommand(config.getConfigurationSection("guild"))); if (hasEconomy() && economy.isValid()) { - if(config.contains("withdraw")) commandMap.register("mmocore", new WithdrawCommand(config.getConfigurationSection("withdraw"))); - if(config.contains("deposit")) commandMap.register("mmocore", new DepositCommand(config.getConfigurationSection("deposit"))); + if (config.contains("withdraw")) + commandMap.register("mmocore", new WithdrawCommand(config.getConfigurationSection("withdraw"))); + if (config.contains("deposit")) + commandMap.register("mmocore", new DepositCommand(config.getConfigurationSection("deposit"))); } - } - catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) { + } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) { ex.printStackTrace(); } @@ -430,7 +441,7 @@ public class MMOCore extends JavaPlugin { public void pauseDefaultActionBar(UUID uuid, int ticks) { pausePlayers.add(uuid); - + new BukkitRunnable() { @Override public void run() { diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index f5175673..4f284a21 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -25,10 +25,10 @@ import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions; public class BlockListener implements Listener { private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH }; - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(BlockBreakEvent event) { Player player = event.getPlayer(); - if (player.getGameMode() == GameMode.CREATIVE || event.isCancelled()) + if (player.getGameMode() == GameMode.CREATIVE) return; String savedData = event.getBlock().getBlockData().getAsString(); @@ -38,7 +38,7 @@ public class BlockListener implements Listener { */ boolean customMine = MMOCore.plugin.mineManager.isEnabled(player, block.getLocation()); ItemStack item = player.getInventory().getItemInMainHand(); - + if (customMine) { BlockInfo info = MMOCore.plugin.mineManager.getInfo(block); @@ -56,7 +56,7 @@ public class BlockListener implements Listener { event.setCancelled(true); return; } - + BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType()); if (perms == null) { event.setCancelled(true); @@ -68,7 +68,6 @@ public class BlockListener implements Listener { event.setCancelled(true); return; } - /* * remove vanilla drops if needed @@ -79,19 +78,20 @@ public class BlockListener implements Listener { } /* - * apply triggers, add experience info to the event so the other events - * can give exp to other TOOLS and display HOLOGRAMS + * apply triggers, add experience info to the event so the other + * events can give exp to other TOOLS and display HOLOGRAMS */ if (info.hasTriggers()) { PlayerData playerData = PlayerData.get(player); info.getTriggers().forEach(trigger -> { - if(!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger) - trigger.apply(playerData); + if (!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger) + trigger.apply(playerData); }); - if(!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms()) - MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player); + if (!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms()) + MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5), + MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player); } - + /* * apply drop tables */ @@ -101,7 +101,7 @@ public class BlockListener implements Listener { if (drop.getType() != Material.AIR && drop.getAmount() > 0) block.getWorld().dropItemNaturally(dropLocation, drop); } - + /* * enable block regen. */