diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 65917e27..45558f85 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -103,11 +103,11 @@ import com.gamingmesh.jobs.listeners.JobsPaymentListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.selection.SelectionManager; import com.gamingmesh.jobs.stuff.CMIScoreboardManager; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; import com.gamingmesh.jobs.stuff.Loging; import com.gamingmesh.jobs.stuff.PageInfo; import com.gamingmesh.jobs.stuff.TabComplete; +import com.gamingmesh.jobs.stuff.ToggleBarHandling; import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; @@ -151,7 +151,17 @@ public class Jobs extends JavaPlugin { private static List jobs = null; private static Job noneJob = null; private static WeakHashMap usedSlots = new WeakHashMap<>(); + /** + * Gets the actionbar toggle map + * @deprecated Moved to {@link ToggleBarHandling} + */ + @Deprecated public static WeakHashMap actionbartoggle = new WeakHashMap<>(); + /** + * Gets the bossbar toggle map + * @deprecated Moved to {@link ToggleBarHandling} + */ + @Deprecated public static WeakHashMap BossBartoggle = new WeakHashMap<>(); // public static WeakHashMap GlobalBoost = new WeakHashMap(); private static BufferedEconomy economy = null; @@ -392,10 +402,20 @@ public class Jobs extends JavaPlugin { return BBManager; } + /** + * Gets the actionbar toggle map + * @deprecated Moved to {@link ToggleBarHandling} + */ + @Deprecated public static WeakHashMap getActionbarToggleList() { return actionbartoggle; } + /** + * Gets the bossbar toggle map + * @deprecated Moved to {@link ToggleBarHandling} + */ + @Deprecated public static WeakHashMap getBossBarToggleList() { return BossBartoggle; } @@ -624,8 +644,8 @@ public class Jobs extends JavaPlugin { dao.getMap().clear(); if (getPlayerManager().getPlayersCache().size() != 0) - consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time) - / 1000d) * 100) / 100D)); + consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " + + ((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D)); } /** @@ -633,7 +653,6 @@ public class Jobs extends JavaPlugin { * @throws IOException */ public static void reload() throws IOException { - if (saveTask != null) { saveTask.shutdown(); saveTask = null; @@ -653,6 +672,7 @@ public class Jobs extends JavaPlugin { configManager.reload(); FurnaceBrewingHandling.load(); + ToggleBarHandling.load(); usedSlots.clear(); for (Job job : jobs) { usedSlots.put(job, dao.getSlotsTaken(job)); @@ -889,7 +909,7 @@ public class Jobs extends JavaPlugin { setWorldGuard(); setMythicManager(); - if (MythicManager != null && MythicManager.Check() && GconfigManager.MythicMobsEnabled) + if (GconfigManager.MythicMobsEnabled && MythicManager != null && MythicManager.Check()) MythicManager.registerListener(); setPistonProtectionListener(); @@ -926,6 +946,7 @@ public class Jobs extends JavaPlugin { dao.saveExplore(); dao.saveBlockProtection(); FurnaceBrewingHandling.save(); + ToggleBarHandling.save(); } catch (Throwable e) { e.printStackTrace(); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java index 9396b3bb..93e1ce11 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java @@ -5,7 +5,6 @@ import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; @@ -18,7 +17,6 @@ public class gtop implements Cmd { @Override @JobCommand(600) public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 1 && args.length != 0) { sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.help.info", "%amount%", Jobs.getGCManager().JobsTopAmount)); return true; @@ -26,11 +24,14 @@ public class gtop implements Cmd { if (!(sender instanceof Player)) return false; - Player player = (Player) sender; - if (args.length > 0 && args[0].equalsIgnoreCase("clear")) { - player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - return true; + Player player = (Player) sender; + if (args.length == 1) { + if (args[0].equalsIgnoreCase("clear")) { + //player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.getCMIScoreboardManager().removeScoreBoard(player); + return true; + } } int page = 1; @@ -59,7 +60,7 @@ public class gtop implements Cmd { String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.list", "%number%", i, - "%playername%", PlayerName, + "%playername%", PlayerName, "%level%", One.getLevel(), "%exp%", One.getExp())); } @@ -73,9 +74,9 @@ public class gtop implements Cmd { for (TopList one : FullList) { i++; String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown"; - ls.add(Jobs.getLanguage().getMessage("scoreboard.line", - "%number%", i, - "%playername%", playername, + ls.add(Jobs.getLanguage().getMessage("scoreboard.line", + "%number%", i, + "%playername%", playername, "%level%", one.getLevel())); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java index cf1e18a0..20a96a9c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java @@ -8,13 +8,13 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.ToggleBarHandling; public class toggle implements Cmd { @Override @JobCommand(1000) public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame")); return false; @@ -24,49 +24,48 @@ public class toggle implements Cmd { Jobs.getCommandManager().sendUsage(sender, "toggle"); return true; } - + Player player = (Player) sender; - String PlayerName = player.getName(); - if (PlayerName == null || !args[0].equalsIgnoreCase("bossbar") && !args[0].equalsIgnoreCase("actionbar")) { Jobs.getCommandManager().sendUsage(sender, "toggle"); return true; } - if (args[0].equalsIgnoreCase("actionbar")) - if (Jobs.getActionbarToggleList().containsKey(PlayerName)) - if (Jobs.getActionbarToggleList().get(PlayerName)) { - Jobs.getActionbarToggleList().put(PlayerName, false); + if (args[0].equalsIgnoreCase("actionbar")) { + if (ToggleBarHandling.getActionBarToggle().containsKey(PlayerName)) { + if (ToggleBarHandling.getActionBarToggle().get(PlayerName)) { + ToggleBarHandling.getActionBarToggle().put(PlayerName, false); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); } else { - Jobs.getActionbarToggleList().put(PlayerName, true); + ToggleBarHandling.getActionBarToggle().put(PlayerName, true); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); } - else { - Jobs.getActionbarToggleList().put(PlayerName, true); + } else { + ToggleBarHandling.getActionBarToggle().put(PlayerName, true); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); } + } - if (args[0].equalsIgnoreCase("bossbar")) - if (Jobs.getBossBarToggleList().containsKey(PlayerName)) - if (Jobs.getBossBarToggleList().get(PlayerName)) { - Jobs.getBossBarToggleList().put(PlayerName, false); + if (args[0].equalsIgnoreCase("bossbar")) { + if (ToggleBarHandling.getBossBarToggle().containsKey(PlayerName)) { + if (ToggleBarHandling.getBossBarToggle().get(PlayerName)) { + ToggleBarHandling.getBossBarToggle().put(PlayerName, false); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId()); - if (jPlayer != null) jPlayer.hideBossBars(); } else { - Jobs.getBossBarToggleList().put(PlayerName, true); + ToggleBarHandling.getBossBarToggle().put(PlayerName, true); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); } - else { - Jobs.getBossBarToggleList().put(PlayerName, true); + } else { + ToggleBarHandling.getBossBarToggle().put(PlayerName, true); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); } + } return true; } diff --git a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java index 4f154173..855b0165 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java @@ -17,6 +17,7 @@ import com.gamingmesh.jobs.container.BossBarInfo; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.ToggleBarHandling; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; public class BossBarManager { @@ -35,7 +36,6 @@ public class BossBarManager { return; List temp = new ArrayList<>(); - temp.addAll(player.getUpdateBossBarFor()); for (String one : temp) { @@ -50,14 +50,15 @@ public class BossBarManager { public synchronized void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg) { if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) return; - String playername = player.getUserName(); - if (!Jobs.getBossBarToggleList().containsKey(playername) && Jobs.getGCManager().BossBarsMessageByDefault) - Jobs.getBossBarToggleList().put(playername, true); - if (!Jobs.getBossBarToggleList().containsKey(playername)) + String playername = player.getUserName(); + if (!ToggleBarHandling.getBossBarToggle().containsKey(playername) && Jobs.getGCManager().BossBarsMessageByDefault) + ToggleBarHandling.getBossBarToggle().put(playername, true); + + if (!ToggleBarHandling.getBossBarToggle().containsKey(playername)) return; - Boolean show = Jobs.getBossBarToggleList().get(playername); + Boolean show = ToggleBarHandling.getBossBarToggle().get(playername); if (!show) return; @@ -133,7 +134,6 @@ public class BossBarManager { OldOne.setId(Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - for (BossBarInfo one : player.getBossBarInfo()) { if (!one.getPlayerName().equalsIgnoreCase(player.getUserName())) continue; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 25813d35..f1296228 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -100,7 +100,7 @@ public class GeneralConfigManager { public boolean useBreederFinder = false; private boolean useTnTFinder = false; public boolean CancelCowMilking; - public boolean fixAtMaxLevel, ToggleActionBar, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, + public boolean fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAccountChat, EmptyServerAccountActionBar, ActionBarsMessageByDefault, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, JobsGUIOpenOnJoin; @@ -285,14 +285,32 @@ public class GeneralConfigManager { return modifyChat; } + /** + * Get the chat prefix string from file + * @deprecated Use {@link #modifyChatPrefix} + * @return + */ + @Deprecated public String getModifyChatPrefix() { return modifyChatPrefix; } + /** + * Get the chat suffix string from file + * @deprecated Use {@link #modifyChatSuffix} + * @return + */ + @Deprecated public String getModifyChatSuffix() { return modifyChatSuffix; } + /** + * Get the chat separator string from file + * @deprecated Use {@link #modifyChatSeparator} + * @return + */ + @Deprecated public String getModifyChatSeparator() { return modifyChatSeparator; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 288e3717..7a572c96 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -621,7 +621,7 @@ public class JobsPlayer { if (method.equals(DisplayMethod.NONE)) continue; if (gotTitle) { - builder.append(Jobs.getGCManager().getModifyChatSeparator()); + builder.append(Jobs.getGCManager().modifyChatSeparator); gotTitle = false; } Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName()); @@ -691,7 +691,7 @@ public class JobsPlayer { honorific = builder.toString().trim(); if (honorific.length() > 0) honorific = org.bukkit.ChatColor.translateAlternateColorCodes('&', - Jobs.getGCManager().getModifyChatPrefix() + honorific + Jobs.getGCManager().getModifyChatSuffix()); + Jobs.getGCManager().modifyChatPrefix + honorific + Jobs.getGCManager().modifyChatSuffix); } diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 412c9348..eeb92bfb 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.api.JobsPaymentEvent; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.ToggleBarHandling; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.tasks.BufferedPaymentTask; @@ -144,9 +145,9 @@ public class BufferedEconomy { economy.depositPlayer(ServerTaxesAccount, TaxesAmount); if (ServerTaxesAccount.isOnline()) { - if (!Jobs.getActionbarToggleList().containsKey(ServerTaxesAccountname) && Jobs.getGCManager().ActionBarsMessageByDefault) - Jobs.getActionbarToggleList().put(ServerTaxesAccountname, true); - if (Jobs.getActionbarToggleList().containsKey(ServerTaxesAccountname) && Jobs.getActionbarToggleList().get(ServerTaxesAccountname)) + if (!ToggleBarHandling.getActionBarToggle().containsKey(ServerTaxesAccountname) && Jobs.getGCManager().ActionBarsMessageByDefault) + ToggleBarHandling.getActionBarToggle().put(ServerTaxesAccountname, true); + if (ToggleBarHandling.getActionBarToggle().containsKey(ServerTaxesAccountname) && ToggleBarHandling.getActionBarToggle().get(ServerTaxesAccountname)) Jobs.getActionBar().send(Bukkit.getPlayer(ServerAccountname), Jobs.getLanguage().getMessage("message.taxes", "[amount]", (int) (TotalAmount * 100) / 100.0)); } @@ -213,16 +214,16 @@ public class BufferedEconomy { return; String playername = payment.getOfflinePlayer().getName(); - if ((!Jobs.getActionbarToggleList().containsKey(playername)) && (Jobs.getGCManager().ActionBarsMessageByDefault)) - Jobs.getActionbarToggleList().put(playername, Boolean.valueOf(true)); + if ((!ToggleBarHandling.getActionBarToggle().containsKey(playername)) && (Jobs.getGCManager().ActionBarsMessageByDefault)) + ToggleBarHandling.getActionBarToggle().put(playername, Boolean.valueOf(true)); if (playername == null) return; - if (!Jobs.getActionbarToggleList().containsKey(playername)) + if (!ToggleBarHandling.getActionBarToggle().containsKey(playername)) return; - Boolean show = Jobs.getActionbarToggleList().get(playername); + Boolean show = ToggleBarHandling.getActionBarToggle().get(playername); Player abp = Bukkit.getPlayer(payment.getOfflinePlayer().getUniqueId()); if ((abp != null) && (show.booleanValue())) { String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main"); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 6c888603..de955415 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -49,7 +49,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockCookEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -103,7 +102,6 @@ import com.gamingmesh.jobs.container.ExploreRespond; import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback; import com.google.common.base.Objects; @@ -570,7 +568,6 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryCraft(CraftItemEvent event) { - // make sure plugin is enabled if (!plugin.isEnabled()) return; @@ -1311,19 +1308,22 @@ public class JobsPaymentListener implements Listener { if (!ent.getType().toString().equalsIgnoreCase("ARMOR_STAND")) return; Location loc = event.getLocation(); - Collection ents = loc.getWorld().getNearbyEntities(loc, 4, 4, 4); + Collection ents = Version.isCurrentEqualOrLower(Version.v1_8_R1) + ? null : loc.getWorld().getNearbyEntities(loc, 4, 4, 4); double dis = Double.MAX_VALUE; Player player = null; - for (Entity one : ents) { - if (!(one instanceof Player)) - continue; - Player p = (Player) one; - if (!Jobs.getNms().getItemInMainHand(p).getType().toString().equalsIgnoreCase("ARMOR_STAND")) - continue; - double d = p.getLocation().distance(loc); - if (d < dis) { - dis = d; - player = p; + if (ents != null) { + for (Entity one : ents) { + if (!(one instanceof Player)) + continue; + Player p = (Player) one; + if (!Jobs.getNms().getItemInMainHand(p).getType().toString().equalsIgnoreCase("ARMOR_STAND")) + continue; + double d = p.getLocation().distance(loc); + if (d < dis) { + dis = d; + player = p; + } } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java b/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java new file mode 100644 index 00000000..c0be472e --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java @@ -0,0 +1,83 @@ +package com.gamingmesh.jobs.stuff; + +import java.util.WeakHashMap; +import java.util.Map.Entry; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.config.YmlMaker; + +public class ToggleBarHandling { + + static WeakHashMap actionBarToggle = new WeakHashMap<>(); + static WeakHashMap bossBarToggle = new WeakHashMap<>(); + + public static void load() { + YmlMaker f = new YmlMaker(Jobs.getInstance(), "actionBarBossbar.yml"); + if (!f.exists()) + return; + + FileConfiguration config = f.getConfig(); + + if (Jobs.getGCManager().BossBarEnabled) { + ConfigurationSection section = config.getConfigurationSection("bossBar"); + + if (section != null) { + for (String one : section.getKeys(false)) { + bossBarToggle.put(one, section.getBoolean(one)); + } + } + } + + if (Jobs.getGCManager().ActionBarsMessageByDefault) { + ConfigurationSection section = config.getConfigurationSection("actionBar"); + + if (section != null) { + for (String one : section.getKeys(false)) { + actionBarToggle.put(one, section.getBoolean(one)); + } + } + } + } + + public static void save() { + YmlMaker f = new YmlMaker(Jobs.getInstance(), "actionBarBossbar.yml"); + if (!f.exists()) + f.createNewFile(); + + f.saveDefaultConfig(); + + FileConfiguration config = f.getConfig(); + + if (Jobs.getGCManager().BossBarEnabled) { + config.set("bossBar", null); + + for (Entry one : bossBarToggle.entrySet()) { + config.set("bossBar." + one.getKey(), one.getValue()); + } + } + + if (Jobs.getGCManager().ActionBarsMessageByDefault) { + config.set("actionBar", null); + + for (Entry one : actionBarToggle.entrySet()) { + config.set("actionBar." + one.getKey(), one.getValue()); + } + } + + bossBarToggle.clear(); + actionBarToggle.clear(); + + f.saveConfig(); + } + + public static WeakHashMap getActionBarToggle() { + return actionBarToggle; + } + + public static WeakHashMap getBossBarToggle() { + return bossBarToggle; + } +}