From dd4406c6c46404047be48adf4bca7b1c0d6b7c5d Mon Sep 17 00:00:00 2001 From: Picono435 <57836766+Picono435@users.noreply.github.com> Date: Sat, 22 Aug 2020 15:24:54 +0100 Subject: [PATCH] Fixed minor issues & added new commands --- .../picojobs/commands/JobsAdminCommand.java | 113 ++++++++++++++++-- .../picojobs/managers/LanguageManager.java | 6 +- src/main/resources/config.yml | 1 - src/main/resources/langs/en-GB.yml | 3 +- src/main/resources/settings/jobs.yml | 20 ++-- 5 files changed, 120 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java b/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java index e094d472..581c89ca 100644 --- a/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java +++ b/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java @@ -22,14 +22,16 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; -import org.codehaus.plexus.util.FileUtils; import com.gmail.picono435.picojobs.PicoJobsPlugin; +import com.gmail.picono435.picojobs.api.JobPlayer; +import com.gmail.picono435.picojobs.api.PicoJobsAPI; import com.gmail.picono435.picojobs.managers.LanguageManager; import com.gmail.picono435.picojobs.utils.FileCreator; public class JobsAdminCommand implements CommandExecutor, TabCompleter { + @SuppressWarnings("deprecation") @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(!cmd.getName().equals("jobsadmin")) return false; @@ -48,6 +50,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String String reloadString = LanguageManager.getSubCommandAlias("reload"); String updateString = LanguageManager.getSubCommandAlias("update"); String aboutString = LanguageManager.getSubCommandAlias("about"); + String setString = LanguageManager.getSubCommandAlias("set"); + + String salaryString = LanguageManager.getSubCommandAlias("salary"); + String methodString = LanguageManager.getSubCommandAlias("method"); + Player pl = null; if(sender instanceof Player) { pl = (Player)sender; @@ -100,7 +107,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } - // UPDATE COMMAND + // ABOUT COMMAND if(subcmd.equalsIgnoreCase("about") || subcmd.equalsIgnoreCase(aboutString)) { String message = "&eHere are some information about the plugin\n" + "&ePlugin version:&6 v" + PicoJobsPlugin.getInstance().getDescription().getVersion() + "\n" @@ -111,6 +118,60 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String p.sendMessage(LanguageManager.formatMessage(message)); return true; } + + // SET COMMAND + if(subcmd.equalsIgnoreCase("set") || subcmd.equalsIgnoreCase(setString)) { + if(args.length < 2) { + p.sendMessage(LanguageManager.getMessage("no-args", pl)); + return true; + } + // /jobsadmin set salary Frankandstile 1000 + if(args[1].equalsIgnoreCase("salary") || args[1].equalsIgnoreCase(salaryString)) { + if(args.length < 4) { + p.sendMessage(LanguageManager.getMessage("no-args", pl)); + return true; + } + JobPlayer jpNew = PicoJobsAPI.getPlayersManager().getJobPlayer(args[2]); + if(jpNew == null) { + p.sendMessage(LanguageManager.getMessage("player-not-found", pl)); + return true; + } + int newSalary = 0; + try { + newSalary = Integer.parseInt(args[3]); + } catch(Exception ex) { + p.sendMessage(LanguageManager.getMessage("no-args", pl)); + return true; + } + jpNew.setSalary(newSalary); + p.sendMessage(LanguageManager.getMessage("sucefully", pl)); + return true; + } + + if(args[1].equalsIgnoreCase("method") || args[1].equalsIgnoreCase(methodString)) { + if(args.length < 4) { + p.sendMessage(LanguageManager.getMessage("no-args", pl)); + return true; + } + JobPlayer jpNew = PicoJobsAPI.getPlayersManager().getJobPlayer(args[2]); + if(jpNew == null) { + p.sendMessage(LanguageManager.getMessage("player-not-found", pl)); + return true; + } + int newMethod = 0; + try { + newMethod = Integer.parseInt(args[3]); + } catch(Exception ex) { + p.sendMessage(LanguageManager.getMessage("no-args", pl)); + return true; + } + jpNew.setMethod(newMethod); + p.sendMessage(LanguageManager.getMessage("sucefully", pl)); + return true; + } + + p.sendMessage(LanguageManager.getFormat("admin-commands", null)); + } return true; } @@ -123,18 +184,50 @@ public List onTabComplete(CommandSender sender, Command cmd, String alia String reloadString = LanguageManager.getSubCommandAlias("reload"); String updateString = LanguageManager.getSubCommandAlias("update"); String aboutString = LanguageManager.getSubCommandAlias("about"); + String setString = LanguageManager.getSubCommandAlias("set"); + + String salaryString = LanguageManager.getSubCommandAlias("salary"); + String methodString = LanguageManager.getSubCommandAlias("method"); + + if(!p.hasPermission("picojobs.admin")) return null; + + List list = new ArrayList(); if(args.length == 1) { - List list = new ArrayList(); - if(p.hasPermission("picojobs.admin")) { - list.add(helpString); - list.add(infoString); - list.add(reloadString); - list.add(updateString); - list.add(aboutString); - } + list.add(helpString); + list.add(infoString); + list.add(reloadString); + list.add(updateString); + list.add(aboutString); + list.add(setString); return list; } + + if(args.length == 2) { + if(args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase(setString)) { + list.add(salaryString); + list.add(methodString); + return list; + } + } + + if(args.length == 3) { + if(args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase(setString)) { + list.add("[]"); + return list; + } + } + + if(args.length == 4) { + if(args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase(setString)) { + if(args[1].equalsIgnoreCase("salary") || args[1].equalsIgnoreCase(salaryString)) { + list.add("[<" + salaryString + ">]"); + } else if(args[1].equalsIgnoreCase("method") || args[1].equalsIgnoreCase(methodString)) { + list.add("[<" + methodString + ">]"); + } + return list; + } + } } return null; } diff --git a/src/main/java/com/gmail/picono435/picojobs/managers/LanguageManager.java b/src/main/java/com/gmail/picono435/picojobs/managers/LanguageManager.java index 998d18f8..d7709a79 100644 --- a/src/main/java/com/gmail/picono435/picojobs/managers/LanguageManager.java +++ b/src/main/java/com/gmail/picono435/picojobs/managers/LanguageManager.java @@ -117,7 +117,11 @@ public static List getCommandAliases(String cmd) { * */ public static String getSubCommandAlias(String subcmd) { - String chat = language.getConfigurationSection("aliases").getString(subcmd).toLowerCase(); + String chat = language.getConfigurationSection("aliases").getString(subcmd); + if(chat == null) { + chat = subcmd; + } + chat = chat.toLowerCase(); return chat; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e714e669..b198de63 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,4 @@ # IMPORTANT # -# Some configurations have the ** PREMIUM ONLY ** tag, this means that the configurations are only for the premium version. # Our plugin uses PlaceholderAPI to make placeholders, it's not required but if you want to use it you need to add it # A detailed wiki of our plugin can be found here: https://github.com/Picono435/wiki # All the configurations are commented, but if you still need help check the wiki or send a message in our discord diff --git a/src/main/resources/langs/en-GB.yml b/src/main/resources/langs/en-GB.yml index 02d8adeb..cac1828d 100644 --- a/src/main/resources/langs/en-GB.yml +++ b/src/main/resources/langs/en-GB.yml @@ -30,6 +30,7 @@ admin-commands: |- &e/jobsadmin reload &6- &eReload all the possible configurations. &e/jobsadmin update &6- &eInstalls a update of the plugin &e/jobsadmin about &6- &eGets informations about the server and the plugin + &e/jobsadmin set &6- &eSets the salary/method of a player info-command: |- &6Status of the player %player_name% &eSalary: %jobplayer_salary% @@ -43,7 +44,7 @@ left-job: "&cYou are not unemployed! We recommend you choose a new job or you wi already-updated: "&cThe plugin is already in the lastest version, for more information check our WIKI." update-started: "&aThe update of the plugin PicoJobs started, please wait..." updated-sucefully: "&aThe plugin was updated sucefully, please restart the server to finish the update." - +sucefully: "&aThe action was made sucefully." ################################################################################## # # diff --git a/src/main/resources/settings/jobs.yml b/src/main/resources/settings/jobs.yml index c9fdf224..dbd5e4f5 100644 --- a/src/main/resources/settings/jobs.yml +++ b/src/main/resources/settings/jobs.yml @@ -36,9 +36,9 @@ jobs: item-data: 0 # If you want to the item be enchanted or not enchanted: false - # Set the permissions that this job should have ** PREMIUM ONLY ** + # Set the permissions that this job should have # REQUIRES VAULT - permissions: + permissions: # [SOON] - kit.use.thief # This is a example of a police job @@ -71,9 +71,9 @@ jobs: item-data: 0 # If you want to the item be enchanted or not enchanted: false - # Set the permissions that this job should have ** PREMIUM ONLY ** + # Set the permissions that this job should have # REQUIRES VAULT - permissions: + permissions: # [SOON] - kit.use.police # This is a example of a miner job @@ -108,9 +108,9 @@ jobs: item-data: 0 # If you want to the item be enchanted or not enchanted: false - # Set the permissions that this job should have ** PREMIUM ONLY ** + # Set the permissions that this job should have # REQUIRES VAULT - permissions: + permissions: # [SOON] - kit.use.miner # This is a example of a assassin job @@ -143,9 +143,9 @@ jobs: item-data: 0 # If you want to the item be enchanted or not enchanted: true - # Set the permissions that this job should have ** PREMIUM ONLY ** + # Set the permissions that this job should have # REQUIRES VAULT - permissions: + permissions: # [SOON] - kit.use.assassin # This is a example of a assassin job @@ -176,7 +176,7 @@ jobs: item-data: 0 # If you want to the item be enchanted or not enchanted: true - # Set the permissions that this job should have ** PREMIUM ONLY ** + # Set the permissions that this job should have # REQUIRES VAULT - permissions: + permissions: # [SOON] - kit.use.fisher \ No newline at end of file