From 90b4813a013be99569715c0b798f6f268a2ce643 Mon Sep 17 00:00:00 2001 From: Zrips Date: Thu, 17 Dec 2015 14:04:34 +0200 Subject: [PATCH] GUI fixes --- com/gamingmesh/jobs/Gui/GuiTools.java | 26 ++++++- com/gamingmesh/jobs/JobsPlugin.java | 3 +- com/gamingmesh/jobs/PlayerManager.java | 2 +- .../jobs/commands/JobsCommands.java | 15 ++++ .../jobs/config/JobsConfiguration.java | 4 + com/gamingmesh/jobs/dao/.gitignore | 1 + com/gamingmesh/jobs/dao/JobsDAO.java | 76 ++++++++++++++++++- com/gamingmesh/jobs/i18n/Language.java | 2 +- .../jobs/listeners/JobsListener.java | 16 ++-- plugin.yml | 6 +- 10 files changed, 134 insertions(+), 17 deletions(-) diff --git a/com/gamingmesh/jobs/Gui/GuiTools.java b/com/gamingmesh/jobs/Gui/GuiTools.java index 6b3e299f..ac96d562 100644 --- a/com/gamingmesh/jobs/Gui/GuiTools.java +++ b/com/gamingmesh/jobs/Gui/GuiTools.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -27,6 +28,15 @@ public class GuiTools { public static HashMap GuiList = new HashMap(); + public static void CloseInventories() { + for (Entry one : GuiList.entrySet()) { + Player player = Bukkit.getPlayer(one.getKey()); + if (player != null) { + player.closeInventory(); + } + } + } + public static Inventory CreateJobsGUI(Player player) { ArrayList JobsList = new ArrayList(); @@ -62,7 +72,11 @@ public class GuiTools { List pJobs = JPlayer.getJobProgression(); - Inventory GuiInv = Bukkit.createInventory(null, GuiSize, Language.getMessage("command.info.gui.pickjob")); + String title = Language.getMessage("command.info.gui.pickjob"); + if (title.length() > 32) + title = title.substring(0, 30) + ".."; + + Inventory GuiInv = Bukkit.createInventory(null, GuiSize, title); for (int i = 0; i < JobsList.size(); i++) { @@ -103,7 +117,8 @@ public class GuiTools { for (ActionType actionType : ActionType.values()) { List info = job.getJobInfo(actionType); if (info != null && !info.isEmpty()) { - Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + Language.getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"))); + Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + Language.getMessage("command.info.output." + actionType.getName().toLowerCase() + + ".info"))); } } @@ -229,7 +244,10 @@ public class GuiTools { // backButton = 53; // } - Inventory GuiInv = Bukkit.createInventory(null, GuiSize, Language.getMessage("command.info.gui.jobinfo").replace("[jobname]", job.getName())); + String title = Language.getMessage("command.info.gui.jobinfo").replace("[jobname]", job.getName()); + if (title.length() > 32) + title = title.substring(0, 30) + ".."; + Inventory GuiInv = Bukkit.createInventory(null, GuiSize, title); for (int i1 = 0; i1 < items.size(); i1++) { GuiInv.setItem(i1, items.get(i1)); @@ -238,7 +256,7 @@ public class GuiTools { ItemStack skull = new ItemStack(Material.JACK_O_LANTERN, 1, (byte) 0); ItemMeta skullMeta = skull.getItemMeta(); - skullMeta.setDisplayName("<<< Back"); + skullMeta.setDisplayName(Language.getMessage("command.info.gui.back")); skull.setItemMeta(skullMeta); diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java index 3ed51d02..249f8b72 100644 --- a/com/gamingmesh/jobs/JobsPlugin.java +++ b/com/gamingmesh/jobs/JobsPlugin.java @@ -20,7 +20,6 @@ package com.gamingmesh.jobs; import java.io.IOException; import java.lang.reflect.InvocationTargetException; - import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; import net.elseland.xikage.MythicMobs.MythicMobs; @@ -32,6 +31,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.ChatColor; +import com.gamingmesh.jobs.Gui.GuiTools; import com.gamingmesh.jobs.commands.JobsCommands; import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.JobConfig; @@ -164,6 +164,7 @@ public class JobsPlugin extends JavaPlugin { @Override public void onDisable() { + GuiTools.CloseInventories(); Jobs.shutdown(); String message = ChatColor.translateAlternateColorCodes('&', "&2Plugin has been disabled succesfully."); ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 6165bd76..c4973a12 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -536,7 +536,7 @@ public class PlayerManager { } private boolean Perm(Player player, String permission) { - return player.isPermissionSet(permission); + return player.hasPermission(permission); } /** diff --git a/com/gamingmesh/jobs/commands/JobsCommands.java b/com/gamingmesh/jobs/commands/JobsCommands.java index 44a6301a..e1e75b8b 100644 --- a/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/com/gamingmesh/jobs/commands/JobsCommands.java @@ -165,6 +165,21 @@ public class JobsCommands implements CommandExecutor { return true; } + @JobCommand + public boolean fixnames(CommandSender sender, String[] args) throws IOException { + + if (args.length > 0) { + sendUsage(sender, "fixnames"); + return true; + } + + Jobs.getJobsDAO().fixName(sender); + + sender.sendMessage(ChatColor.GOLD + "[Jobs] Starting name fix proccess, this can take up to minute depending on your data base size."); + + return true; + } + @JobCommand public boolean convert(CommandSender sender, String[] args) throws IOException { diff --git a/com/gamingmesh/jobs/config/JobsConfiguration.java b/com/gamingmesh/jobs/config/JobsConfiguration.java index 045ec42a..176222f1 100644 --- a/com/gamingmesh/jobs/config/JobsConfiguration.java +++ b/com/gamingmesh/jobs/config/JobsConfiguration.java @@ -1262,6 +1262,7 @@ public class JobsConfiguration { GetConfigString("command.info.gui.leftSlots", "&eLeft slots:&f ", writer, conf, true); GetConfigString("command.info.gui.working", "&2&nAlready working", writer, conf, true); GetConfigString("command.info.gui.max", "&eMax level:&f ", writer, conf, true); + GetConfigString("command.info.gui.back", "&e<<< Back", writer, conf, true); GetConfigString("command.info.output.break.info", "Break", writer, conf, true); GetConfigString("command.info.output.break.none", "%jobname% does not get money for breaking blocks.", writer, conf, true); @@ -1307,6 +1308,9 @@ public class JobsConfiguration { GetConfigString("command.leave.help.info", "Leave the selected job.", writer, conf, true); GetConfigString("command.leave.help.args", "[jobname]", writer, conf, true); GetConfigString("command.leave.success", "You have left the job %jobname%.", writer, conf, true); + + GetConfigString("command.fixnames.help.info", "Tries to fix NULL player names in data base.", writer, conf, true); + GetConfigString("command.fixnames.help.args", "", writer, conf, true); GetConfigString("command.leaveall.help.info", "Leave all your jobs.", writer, conf, true); GetConfigString("command.leaveall.error.nojobs", "You do not have any jobs to leave!", writer, conf, true); diff --git a/com/gamingmesh/jobs/dao/.gitignore b/com/gamingmesh/jobs/dao/.gitignore index bcd7d30a..ea18264e 100644 --- a/com/gamingmesh/jobs/dao/.gitignore +++ b/com/gamingmesh/jobs/dao/.gitignore @@ -8,3 +8,4 @@ /JobsDAOSQLite.class /JobsDriver.class /JobsDrivers.class +/JobsDAO$1.class diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 09ca4a70..72a6aff4 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -23,15 +23,18 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.container.Convert; import com.gamingmesh.jobs.container.Job; @@ -40,7 +43,9 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; import com.gamingmesh.jobs.container.LogAmounts; import com.gamingmesh.jobs.container.TopList; +import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.Loging; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.UUIDUtil; @@ -486,6 +491,70 @@ public abstract class JobsDAO { return null; } + public void fixName(final CommandSender sender) { + Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() { + @Override + public void run() { + JobsConnection conn = getConnection(); + if (conn == null) + return; + try { + PreparedStatement prest = conn.prepareStatement("SELECT `player_uuid`, `username` FROM `" + prefix + "jobs` WHERE `username` IS NULL;"); + ResultSet res = prest.executeQuery(); + HashMap convert = new HashMap(); + int failed = 0; + while (res.next()) { + + String uuidString = res.getString("player_uuid"); + if (uuidString == null) + continue; + + UUID uuid = UUID.fromString(uuidString); + if (uuid == null) + continue; + + OfflinePlayer player = OfflinePlayerList.getPlayer(uuid); + + if (player == null) + player = Bukkit.getOfflinePlayer(uuid); + + if (player == null) + continue; + + if (player.getName() == null) { + failed++; + continue; + } + + convert.put(uuidString, player.getName()); + } + res.close(); + prest.close(); + + prest = conn.prepareStatement("UPDATE `" + prefix + "jobs` SET `username` = ? WHERE `player_uuid` = ?;"); + + for (Entry oneEntry : convert.entrySet()) { + prest.setString(1, oneEntry.getValue()); + prest.setString(2, oneEntry.getKey()); + prest.execute(); + } + if (prest != null) + prest.close(); + + sender.sendMessage(ChatColor.GOLD + "[Jobs] Converted " + ChatColor.YELLOW + convert.size() + ChatColor.GOLD + " user names and failed " + + ChatColor.YELLOW + failed + ChatColor.GOLD + " to do so, most likely user data no longer exists in your player data folder"); + + return; + } catch (SQLException e) { + e.printStackTrace(); + } + + return; + } + }); + return; + } + /** * Delete job from archive * @param player - player that wishes to quit the job @@ -658,7 +727,12 @@ public abstract class JobsDAO { ResultSet res = prest.executeQuery(); while (res.next()) { - Player player = Bukkit.getPlayer(res.getString(1)); + String name = res.getString(1); + + if (name == null) + continue; + + Player player = Bukkit.getPlayer(name); if (player != null) { JobsPlayer jobsinfo = Jobs.getPlayerManager().getJobsPlayer(player); diff --git a/com/gamingmesh/jobs/i18n/Language.java b/com/gamingmesh/jobs/i18n/Language.java index 49ded51b..b185997a 100644 --- a/com/gamingmesh/jobs/i18n/Language.java +++ b/com/gamingmesh/jobs/i18n/Language.java @@ -56,7 +56,7 @@ public class Language { * @param key - the key of the message * @return the message */ - public static String getMessage(String key) { + public static String getMessage(String key) { if (customlocale == null || !customlocale.contains(key)) return enlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', enlocale.getString(key)) : "Cant find locale"; return customlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', customlocale.getString(key)) : "Cant find locale"; diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index bce9b731..1091b7a6 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -83,16 +83,16 @@ public class JobsListener implements Listener { int slot = event.getRawSlot(); if (slot >= 0) { - if (!ConfigManager.getJobsConfiguration().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT || - ConfigManager.getJobsConfiguration().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT) { - if (!joblist.isJobInfo() && slot < joblist.getJobList().size()) { + if (!joblist.isJobInfo() && (!ConfigManager.getJobsConfiguration().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT || + ConfigManager.getJobsConfiguration().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT)) { + if (slot < joblist.getJobList().size()) { player.closeInventory(); player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot))); - } else { - if (slot == joblist.getbackButton()) { - player.closeInventory(); - player.openInventory(GuiTools.CreateJobsGUI(player)); - } + } + } else if (joblist.isJobInfo()) { + if (slot == joblist.getbackButton()) { + player.closeInventory(); + player.openInventory(GuiTools.CreateJobsGUI(player)); } } else if (!ConfigManager.getJobsConfiguration().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT || ConfigManager.getJobsConfiguration().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT) { diff --git a/plugin.yml b/plugin.yml index 56de266c..eef90695 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.JobsPlugin -version: 2.54.1 +version: 2.54.3 author: phrstbrn softdepend: [Vault, CoreProtect, MythicMobs, McMMO] commands: @@ -52,6 +52,7 @@ permissions: jobs.command.limit: true jobs.command.give: true jobs.command.signs: true + jobs.command.fixnames: true jobs.command.signupdate: true jobs.command.moneyboost: true jobs.command.expboost: true @@ -139,6 +140,9 @@ permissions: jobs.command.limit: description: Grants access to the limit command default: true + jobs.command.fixnames: + description: Grants access to the fixnames command + default: true jobs.command.log: description: Grants access to the log command default: true