1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-29 04:18:07 +01:00

GUI fixes

This commit is contained in:
Zrips 2015-12-17 14:04:34 +02:00
parent 8f129bc217
commit 90b4813a01
10 changed files with 134 additions and 17 deletions

View File

@ -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<String, GuiInfoList> GuiList = new HashMap<String, GuiInfoList>();
public static void CloseInventories() {
for (Entry<String, GuiInfoList> one : GuiList.entrySet()) {
Player player = Bukkit.getPlayer(one.getKey());
if (player != null) {
player.closeInventory();
}
}
}
public static Inventory CreateJobsGUI(Player player) {
ArrayList<Job> JobsList = new ArrayList<Job>();
@ -62,7 +72,11 @@ public class GuiTools {
List<JobProgression> 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<JobInfo> 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);

View File

@ -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();

View File

@ -536,7 +536,7 @@ public class PlayerManager {
}
private boolean Perm(Player player, String permission) {
return player.isPermissionSet(permission);
return player.hasPermission(permission);
}
/**

View File

@ -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 {

View File

@ -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);

View File

@ -8,3 +8,4 @@
/JobsDAOSQLite.class
/JobsDriver.class
/JobsDrivers.class
/JobsDAO$1.class

View File

@ -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<String, String> convert = new HashMap<String, String>();
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<String, String> 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);

View File

@ -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";

View File

@ -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) {

View File

@ -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