diff --git a/libs/CMILib1.2.4.5.jar b/libs/CMILib1.2.4.5.jar deleted file mode 100644 index 87ecf7c5..00000000 Binary files a/libs/CMILib1.2.4.5.jar and /dev/null differ diff --git a/libs/CMILib1.4.0.0.jar b/libs/CMILib1.4.0.0.jar new file mode 100644 index 00000000..c11721ba Binary files /dev/null and b/libs/CMILib1.4.0.0.jar differ diff --git a/pom.xml b/pom.xml index c68c1da2..7d83800d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 Jobs jobs - 5.1.2.2 + 5.2.1.0 Jobs http://maven.apache.org @@ -197,7 +197,7 @@ CMILib latest system - ${basedir}/libs/CMILib1.2.4.5.jar + ${basedir}/libs/CMILib1.4.0.0.jar @@ -286,7 +286,7 @@ maven-jar-plugin 2.3.1 - D:\MC\Server 1.19\plugins\ + D:\MC\Server 1.20\plugins\ diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index 8e13b85d..980983aa 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -27,6 +27,7 @@ import net.Zrips.CMILib.GUI.CMIGuiButton; import net.Zrips.CMILib.GUI.GUIManager.GUIClickType; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Version.Version; public class GuiManager { @@ -285,6 +286,7 @@ public class GuiManager { } double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation); + income = boost.getFinalAmount(CurrencyType.MONEY, income); String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); diff --git a/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java b/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java index 9c7244ff..ab51d1e7 100644 --- a/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java +++ b/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java @@ -18,13 +18,14 @@ package com.gamingmesh.jobs; -import net.milkbowl.vault.economy.Economy; - import org.bukkit.plugin.RegisteredServiceProvider; import com.gamingmesh.jobs.economy.BlackholeEconomy; import com.gamingmesh.jobs.economy.VaultEconomy; +import net.Zrips.CMILib.Messages.CMIMessages; +import net.milkbowl.vault.economy.Economy; + public class HookEconomyTask implements Runnable { private Jobs plugin; @@ -72,7 +73,7 @@ public class HookEconomyTask implements Runnable { } Jobs.setEconomy(new VaultEconomy(provider.getProvider())); - Jobs.consoleMsg("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault. (" + provider.getProvider().getName() + ")"); + CMIMessages.consoleMessage("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault. (" + provider.getProvider().getName() + ")"); return hookResult.pass; } diff --git a/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java b/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java index 100d15fd..2f8ed29e 100644 --- a/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java +++ b/src/main/java/com/gamingmesh/jobs/ItemBoostManager.java @@ -22,6 +22,7 @@ import com.gamingmesh.jobs.container.JobItems; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Messages.CMIMessages; public final class ItemBoostManager { @@ -228,7 +229,7 @@ public final class ItemBoostManager { } cfg.save(); - Jobs.consoleMsg("&eLoaded &6" + ITEMS.size() + " &eboosted items"); + CMIMessages.consoleMessage("&eLoaded &6" + ITEMS.size() + " &eboosted items"); } /** diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index bfcc9c01..e9971e3f 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -34,7 +34,6 @@ import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -112,14 +111,12 @@ import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; import net.Zrips.CMILib.ActionBar.CMIActionBar; -import net.Zrips.CMILib.Colors.CMIChatColor; -import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public final class Jobs extends JavaPlugin { @@ -168,7 +165,7 @@ public final class Jobs extends JavaPlugin { private static boolean hasLimitedItems = false; - private static final int MAX_ENTRIES = 5; + private static final int MAX_ENTRIES = 20; public static final LinkedHashMap FASTPAYMENT = new LinkedHashMap(MAX_ENTRIES + 1, .75F, false) { protected boolean removeEldestEntry(Map.Entry eldest) { return size() > MAX_ENTRIES; @@ -268,7 +265,7 @@ public final class Jobs extends JavaPlugin { try { if (Integer.parseInt(papi .getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100 && new PlaceholderAPIHook(this).register()) { - consoleMsg("&6PlaceholderAPI &ehooked."); + CMIMessages.consoleMessage("&6PlaceholderAPI &ehooked."); } } catch (NumberFormatException ex) { return false; @@ -567,7 +564,7 @@ public final class Jobs extends JavaPlugin { getPlayerManager().addPlayerToCache(jPlayer); } if (!getPlayerManager().getPlayersCache().isEmpty()) - consoleMsg("&ePreloaded &6" + getPlayerManager().getPlayersCache().size() + " &eplayers data in &6" + ((int) ((System.currentTimeMillis() - time) / 1000.0D * 100.0D) / 100.0D)); + CMIMessages.consoleMessage("&ePreloaded &6" + getPlayerManager().getPlayersCache().size() + " &eplayers data in &6" + ((int) ((System.currentTimeMillis() - time) / 1000.0D * 100.0D) / 100.0D)); } public static void convertDatabase() { @@ -597,7 +594,7 @@ public final class Jobs extends JavaPlugin { // Jobs.getJobsDAO().saveBlockProtection(); } catch (SQLException e) { e.printStackTrace(); - Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's."); + CMIMessages.consoleMessage("&cCan't write data to data base, please send error log to dev's."); return; } @@ -767,14 +764,14 @@ public final class Jobs extends JavaPlugin { } // register economy - getServer().getScheduler().runTask(this, new HookEconomyTask(this)); + CMIScheduler.get().runTask(new HookEconomyTask(this)); dao.loadBlockProtection(); getExploreManager().load(); getCommandManager().fillCommands(); getDBManager().getDB().triggerTableIdUpdate(); - consoleMsg("&ePlugin has been enabled successfully."); + CMIMessages.consoleMessage("&ePlugin has been enabled successfully."); } catch (Throwable e) { e.printStackTrace(); System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); @@ -916,6 +913,9 @@ public final class Jobs extends JavaPlugin { } private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) { + if (!Jobs.getGCManager().DailyQuestsEnabled) { + return; + } if (!job.getQuests().isEmpty()) { for (QuestProgression one : jPlayer.getQuestProgressions(job, info.getType())) { one.processQuest(jPlayer, info); @@ -1258,7 +1258,7 @@ public final class Jobs extends JavaPlugin { jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); } catch (Throwable e) { e.printStackTrace(); - consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); + CMIMessages.consoleMessage("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); } Map payments = new HashMap<>(); @@ -1416,15 +1416,27 @@ public final class Jobs extends JavaPlugin { return 9 * level - 158; } - public static void perform(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job) { + public static void perform(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job, Block block, Entity ent, LivingEntity victim) { double expPayment = payment.get(CurrencyType.EXP); + JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, payment.get(CurrencyType.MONEY), + payment.get(CurrencyType.POINTS), block, ent, victim, info); + Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); + // If event is canceled, don't do anything + if (jobsPrePaymentEvent.isCancelled()) + return; + + payment.set(CurrencyType.MONEY, jobsPrePaymentEvent.getAmount()); + payment.set(CurrencyType.POINTS, jobsPrePaymentEvent.getPoints()); + JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, expPayment); Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); // If event is canceled, don't do anything if (jobsExpGainEvent.isCancelled()) return; + payment.set(CurrencyType.EXP, jobsExpGainEvent.getExp()); + boolean limited = true; for (CurrencyType one : CurrencyType.values()) { if (jPlayer.isUnderLimit(one, payment.get(one))) { @@ -1449,12 +1461,6 @@ public final class Jobs extends JavaPlugin { getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); } - public static void consoleMsg(String msg) { - if (msg != null) { - Bukkit.getServer().getConsoleSender().sendMessage(CMIChatColor.translate(msg)); - } - } - public static SelectionManager getSelectionManager() { return smanager; } @@ -1472,50 +1478,6 @@ public final class Jobs extends JavaPlugin { } - public void showPagination(CommandSender sender, PageInfo pi, String cmd) { - showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, null); - } - - public void showPagination(CommandSender sender, PageInfo pi, String cmd, String pagePref) { - showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, pagePref); - } - - public void showPagination(CommandSender sender, int pageCount, int currentPage, int totalEntries, String cmd, String pagePref) { - if (!(sender instanceof Player)) - return; - - if (!cmd.startsWith("/")) - cmd = "/" + cmd; - - if (pageCount == 1) - return; - - String pagePrefix = pagePref == null ? "" : pagePref; - - int nextPage = currentPage + 1; - nextPage = currentPage < pageCount ? nextPage : currentPage; - - int prevpage = currentPage - 1; - if (currentPage <= 1) { - prevpage = currentPage; - } - - RawMessage rm = new RawMessage() - .addText((currentPage > 1 ? LC.info_prevPage.getLocale() : LC.info_prevPageOff.getLocale())) - .addHover(currentPage > 1 ? LC.info_prevPageHover.getLocale() : LC.info_lastPageHover.getLocale()) - .addCommand(currentPage > 1 ? cmd + " " + pagePrefix + prevpage : cmd + " " + pagePrefix + pageCount); - - rm.addText(LC.info_pageCount.getLocale("[current]", currentPage, "[total]", pageCount)) - .addHover(LC.info_pageCountHover.getLocale("[totalEntries]", totalEntries)); - - rm.addText(pageCount > currentPage ? LC.info_nextPage.getLocale() : LC.info_nextPageOff.getLocale()) - .addHover(pageCount > currentPage ? LC.info_nextPageHover.getLocale() : LC.info_firstPageHover.getLocale()) - .addCommand(pageCount > currentPage ? cmd + " " + pagePrefix + nextPage : cmd + " " + pagePrefix + 1); - - if (pageCount != 0) - rm.show(sender); - } - public static boolean hasLimitedItems() { return hasLimitedItems; } diff --git a/src/main/java/com/gamingmesh/jobs/PermissionManager.java b/src/main/java/com/gamingmesh/jobs/PermissionManager.java index 01ee9281..459d0eaf 100644 --- a/src/main/java/com/gamingmesh/jobs/PermissionManager.java +++ b/src/main/java/com/gamingmesh/jobs/PermissionManager.java @@ -53,7 +53,9 @@ public class PermissionManager { jobs_maxblastfurnaces_AMOUNT(remade("jobs.maxblastfurnaces.%AMOUNT%"), 30), jobs_maxsmokers_AMOUNT(remade("jobs.maxsmokers.%AMOUNT%"), 30), jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 30), - jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2); + jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2), + jobs_maxquest_JOBNAME_AMOUNT(remade("jobs.maxquest.%JOBNAME%.%AMOUNT%"), 30), + jobs_maxquest_all_AMOUNT(remade("jobs.maxquest.all.%AMOUNT%"), 30); private int reload; private List perms; @@ -93,7 +95,7 @@ public class PermissionManager { } private int getDelay(String perm) { - return permDelay.getOrDefault(perm, 1); + return permDelay.getOrDefault(perm, 1000); } public PermissionManager() { @@ -165,9 +167,11 @@ public class PermissionManager { double amount = Double.NEGATIVE_INFINITY; permissionInfo permInfo = jPlayer.getPermissionsCache(perm); + if (force || getDelay(perm) + permInfo.getTime() < System.currentTimeMillis()) { + Map perms = getAll(player, perm); - for (Map.Entry permission : perms.entrySet()) { + for (Map.Entry permission : perms.entrySet()) { if (!permission.getKey().startsWith(perm) || !permission.getValue()) continue; try { @@ -176,7 +180,7 @@ public class PermissionManager { if (amount == Double.NEGATIVE_INFINITY) amount = 0D; amount += temp; - }else if (temp > amount) + } else if (temp > amount) amount = temp; } catch (NumberFormatException ex) { Jobs.getPluginLogger().log(java.util.logging.Level.WARNING, ex.getLocalizedMessage()); diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index 88427c72..e3af33ad 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -88,6 +88,7 @@ public class Placeholder { user_archived_jobs_exp_$1("jname/number"), jtop_name_$1_$2("jname/number", "[1-15]"), + jtop_displayname_$1_$2("jname/number", "[1-15]"), jtop_level_$1_$2("jname/number", "[1-15]"), maxjobs, @@ -616,6 +617,26 @@ public class Placeholder { List list = Jobs.getJobsDAO().getTopListByJob(jo, 15); + if (list.size() < place) + return ""; + + return list.get(place - 1).getPlayerInfo().getName(); + case jtop_displayname_$1_$2: + if (values.size() < 2) + return ""; + + place = 0; + try { + place = Integer.parseInt(values.get(1)); + } catch (NumberFormatException e) { + return ""; + } + + if (place < 1) + return ""; + + list = Jobs.getJobsDAO().getTopListByJob(jo, 15); + if (list.size() < place) return ""; diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index dae17e93..224963d1 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -31,8 +31,8 @@ import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.FireworkEffect; -import org.bukkit.Material; import org.bukkit.FireworkEffect.Type; +import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Firework; import org.bukkit.entity.LivingEntity; @@ -40,8 +40,6 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import com.gamingmesh.jobs.api.JobsJoinEvent; import com.gamingmesh.jobs.api.JobsLeaveEvent; @@ -62,7 +60,6 @@ import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.dao.JobsDAOData; import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.hooks.HookManager; -import com.gamingmesh.jobs.stuff.PerformCommands; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; @@ -72,6 +69,7 @@ import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class PlayerManager { @@ -336,7 +334,7 @@ public class PlayerManager { i++; if (y++ >= 1000) { - Jobs.consoleMsg("&e[Jobs] Saved " + i + "/" + total + " players data"); + CMIMessages.consoleMessage("&e[Jobs] Saved " + i + "/" + total + " players data"); y = 0; } } @@ -452,6 +450,14 @@ public class PlayerManager { return jPlayer; } + private static void performCommandsOnJoin(JobsPlayer jPlayer, Job job) { + String pName = jPlayer.getName(); + + for (String one : job.getCmdOnJoin()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", pName).replace("[jobname]", job.getName())); + } + } + /** * Causes player to join to the given job. * @@ -476,13 +482,23 @@ public class PlayerManager { Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job)); jPlayer.setLeftTime(job); - PerformCommands.performCommandsOnJoin(jPlayer, job); + performCommandsOnJoin(jPlayer, job); Jobs.takeSlot(job); Jobs.getSignUtil().updateAllSign(job); job.updateTotalPlayers(); jPlayer.maxJobsEquation = getMaxJobs(jPlayer); + + // Removing from cached item boost for recalculation + cache.remove(jPlayer.getUniqueId()); + } + + private static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) { + String pName = jPlayer.getName(); + for (String one : job.getCmdOnLeave()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", pName).replace("[jobname]", job.getName())); + } } /** @@ -510,13 +526,17 @@ public class PlayerManager { if (!Jobs.getJobsDAO().quitJob(jPlayer, job)) return false; - PerformCommands.performCommandsOnLeave(jPlayer, job); + performCommandsOnLeave(jPlayer, job); Jobs.leaveSlot(job); jPlayer.getLeftTimes().remove(jPlayer.getUniqueId()); Jobs.getSignUtil().updateAllSign(job); job.updateTotalPlayers(); + + // Removing from cached item boost for recalculation + cache.remove(jPlayer.getUniqueId()); + return true; } @@ -712,7 +732,7 @@ public class PlayerManager { } if (Jobs.getGCManager().FireworkLevelupUse && player != null) { - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { + CMIScheduler.get().runTaskLater(new Runnable() { @Override public void run() { if (!player.isOnline()) @@ -1044,6 +1064,7 @@ public class PlayerManager { continue; } } + jitems.add(getJobsItemByNbt(item)); } } @@ -1180,7 +1201,7 @@ public class PlayerManager { if (!Jobs.getGCManager().AutoJobJoinUse || player == null || player.isOp()) return; - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { + CMIScheduler.get().runTaskLater(new Runnable() { @Override public void run() { if (!player.isOnline()) @@ -1199,7 +1220,7 @@ public class PlayerManager { for (Job one : Jobs.getJobs()) { if (jPlayer.progression.size() >= playerMaxJobs) return; - + if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots()) continue; diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index ed5e1d75..949be3d8 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -21,8 +21,9 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; import net.Zrips.CMILib.FileHandler.ConfigReader; -import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class SignUtil { @@ -32,345 +33,342 @@ public class SignUtil { private Jobs plugin; public SignUtil(Jobs plugin) { - this.plugin = plugin; + this.plugin = plugin; } public Map> getSigns() { - return signsByType; + return signsByType; } public boolean removeSign(Location loc) { - jobsSign jSign = signsByLocation.remove(jobsSign.locToBlockString(loc)); - if (jSign == null) - return false; + jobsSign jSign = signsByLocation.remove(jobsSign.locToBlockString(loc)); + if (jSign == null) + return false; - Map sub = signsByType.get(jSign.getIdentifier().toLowerCase()); - if (sub != null) { - sub.remove(jSign.locToBlockString()); - } + Map sub = signsByType.get(jSign.getIdentifier().toLowerCase()); + if (sub != null) { + sub.remove(jSign.locToBlockString()); + } - return true; + return true; } public jobsSign getSign(Location loc) { - return loc == null ? null : signsByLocation.get(jobsSign.locToBlockString(loc)); + return loc == null ? null : signsByLocation.get(jobsSign.locToBlockString(loc)); } public void addSign(jobsSign jSign) { - if (jSign == null) - return; + if (jSign == null) + return; - String locToBlockString = jSign.locToBlockString(); + String locToBlockString = jSign.locToBlockString(); - signsByLocation.put(locToBlockString, jSign); + signsByLocation.put(locToBlockString, jSign); - String identifier = jSign.getIdentifier().toLowerCase(); - Map old = signsByType.get(identifier); - if (old == null) { - old = new HashMap<>(); - signsByType.put(identifier, old); - } + String identifier = jSign.getIdentifier().toLowerCase(); + Map old = signsByType.get(identifier); + if (old == null) { + old = new HashMap<>(); + signsByType.put(identifier, old); + } - old.put(locToBlockString, jSign); - signsByType.put(identifier, old); + old.put(locToBlockString, jSign); + signsByType.put(identifier, old); } public void loadSigns() { - if (!Jobs.getGCManager().SignsEnabled) - return; + if (!Jobs.getGCManager().SignsEnabled) + return; - signsByType.clear(); - signsByLocation.clear(); + signsByType.clear(); + signsByLocation.clear(); - File file = new File(Jobs.getFolder(), "Signs.yml"); - ConfigurationSection confCategory = YamlConfiguration.loadConfiguration(file).getConfigurationSection("Signs"); - if (confCategory == null) - return; + File file = new File(Jobs.getFolder(), "Signs.yml"); + ConfigurationSection confCategory = YamlConfiguration.loadConfiguration(file).getConfigurationSection("Signs"); + if (confCategory == null) + return; - List categoriesList = new ArrayList<>(confCategory.getKeys(false)); - if (categoriesList.isEmpty()) - return; + List categoriesList = new ArrayList<>(confCategory.getKeys(false)); + if (categoriesList.isEmpty()) + return; - for (String category : categoriesList) { - ConfigurationSection nameSection = confCategory.getConfigurationSection(category); - if (nameSection == null) - continue; + for (String category : categoriesList) { + ConfigurationSection nameSection = confCategory.getConfigurationSection(category); + if (nameSection == null) + continue; - jobsSign newTemp = new jobsSign(); + jobsSign newTemp = new jobsSign(); - if (nameSection.isString("World")) { - newTemp.setWorldName(nameSection.getString("World")); - newTemp.setX((int) nameSection.getDouble("X")); - newTemp.setY((int) nameSection.getDouble("Y")); - newTemp.setZ((int) nameSection.getDouble("Z")); - } else { - newTemp.setLoc(nameSection.getString("Loc")); - } - if (nameSection.isString("Type")) - newTemp.setType(SignTopType.getType(nameSection.getString("Type"))); + if (nameSection.isString("World")) { + newTemp.setWorldName(nameSection.getString("World")); + newTemp.setX((int) nameSection.getDouble("X")); + newTemp.setY((int) nameSection.getDouble("Y")); + newTemp.setZ((int) nameSection.getDouble("Z")); + } else { + newTemp.setLoc(nameSection.getString("Loc")); + } + if (nameSection.isString("Type")) + newTemp.setType(SignTopType.getType(nameSection.getString("Type"))); - newTemp.setNumber(nameSection.getInt("Number")); - if (nameSection.isString("JobName")) { - SignTopType t = SignTopType.getType(nameSection.getString("JobName")); - if (t == null) - newTemp.setJobName(nameSection.getString("JobName")); - } - newTemp.setSpecial(nameSection.getBoolean("Special")); + newTemp.setNumber(nameSection.getInt("Number")); + if (nameSection.isString("JobName")) { + SignTopType t = SignTopType.getType(nameSection.getString("JobName")); + if (t == null) + newTemp.setJobName(nameSection.getString("JobName")); + } + newTemp.setSpecial(nameSection.getBoolean("Special")); - String identifier = newTemp.getIdentifier().toLowerCase(); - Map old = signsByType.get(identifier); - if (old == null) { - old = new HashMap<>(); - signsByType.put(identifier, old); - } + String identifier = newTemp.getIdentifier().toLowerCase(); + Map old = signsByType.get(identifier); + if (old == null) { + old = new HashMap<>(); + signsByType.put(identifier, old); + } - String loc = newTemp.locToBlockString(); - old.put(loc, newTemp); - signsByLocation.put(loc, newTemp); - } + String loc = newTemp.locToBlockString(); + old.put(loc, newTemp); + signsByLocation.put(loc, newTemp); + } - if (!signsByLocation.isEmpty()) { - Jobs.consoleMsg("&e[Jobs] Loaded " + signsByLocation.size() + " top list signs"); - } + if (!signsByLocation.isEmpty()) { + CMIMessages.consoleMessage("&e[Jobs] Loaded " + signsByLocation.size() + " top list signs"); + } } public void saveSigns() { - File f = new File(Jobs.getFolder(), "Signs.yml"); - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + File f = new File(Jobs.getFolder(), "Signs.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - ConfigReader reader = null; - try { - reader = new ConfigReader(f); - } catch (Exception e1) { - e1.printStackTrace(); - } - if (reader == null) - return; - conf.options().copyDefaults(true); - reader.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!"); + ConfigReader reader = null; + try { + reader = new ConfigReader(f); + } catch (Exception e1) { + e1.printStackTrace(); + } + if (reader == null) + return; + conf.options().copyDefaults(true); + reader.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!"); - if (!conf.isConfigurationSection("Signs")) - conf.createSection("Signs"); + if (!conf.isConfigurationSection("Signs")) + conf.createSection("Signs"); - int i = 0; - for (jobsSign sign : signsByLocation.values()) { - String path = "Signs." + ++i; - reader.set(path + ".Loc", sign.locToBlockString()); - reader.set(path + ".Number", sign.getNumber()); - reader.set(path + ".Type", sign.getType().toString()); - reader.set(path + ".JobName", sign.getJobName()); - reader.set(path + ".Special", sign.isSpecial()); - } + int i = 0; + for (jobsSign sign : signsByLocation.values()) { + String path = "Signs." + ++i; + reader.set(path + ".Loc", sign.locToBlockString()); + reader.set(path + ".Number", sign.getNumber()); + reader.set(path + ".Type", sign.getType().toString()); + reader.set(path + ".JobName", sign.getJobName()); + reader.set(path + ".Special", sign.isSpecial()); + } - try { - reader.save(f); - } catch (IOException e) { - e.printStackTrace(); - } + try { + reader.save(f); + } catch (IOException e) { + e.printStackTrace(); + } } public void updateAllSign(Job job) { - for (SignTopType types : SignTopType.values()) { - if (types != SignTopType.questtoplist) - signUpdate(job, types); - } + for (SignTopType types : SignTopType.values()) { + if (types != SignTopType.questtoplist) + signUpdate(job, types); + } } public boolean signUpdate(Job job) { - return signUpdate(job, SignTopType.toplist); + return signUpdate(job, SignTopType.toplist); } public boolean signUpdate(Job job, SignTopType type) { - if (!Jobs.getGCManager().SignsEnabled) - return true; + if (!Jobs.getGCManager().SignsEnabled) + return true; - if (type == null) - type = SignTopType.toplist; + if (type == null) + type = SignTopType.toplist; - String jobNameOrType = jobsSign.getIdentifier(job, type).toLowerCase(); + String jobNameOrType = jobsSign.getIdentifier(job, type).toLowerCase(); - Map signs = signsByType.get(jobNameOrType); - if (signs == null || signs.isEmpty()) - return false; + Map signs = signsByType.get(jobNameOrType); + if (signs == null || signs.isEmpty()) + return false; - List playerList = new ArrayList<>(); + List playerList = new ArrayList<>(); - switch (type) { - case gtoplist: - playerList = Jobs.getJobsDAO().getGlobalTopList(0); - break; - case questtoplist: - playerList = Jobs.getJobsDAO().getQuestTopList(0); - break; - default: - break; - } + switch (type) { + case gtoplist: + playerList = Jobs.getJobsDAO().getGlobalTopList(0); + break; + case questtoplist: + playerList = Jobs.getJobsDAO().getQuestTopList(0); + break; + default: + break; + } - int timelapse = 1; + int timelapse = 1; - Map> temp = new HashMap<>(); + Map> temp = new HashMap<>(); - boolean save = false; - for (jobsSign jSign : new HashMap<>(signs).values()) { - Location loc = jSign.getLocation(); - if (loc == null) - continue; + boolean save = false; + for (jobsSign jSign : new HashMap<>(signs).values()) { + Location loc = jSign.getLocation(); + if (loc == null) + continue; - Block block = loc.getBlock(); - if (!(block.getState() instanceof Sign)) { - if (!jobNameOrType.isEmpty()) { - Map tt = signsByType.get(jobNameOrType); - if (tt != null) { - tt.remove(jSign.locToBlockString()); - } - } + Block block = loc.getBlock(); + if (!(block.getState() instanceof Sign)) { + if (!jobNameOrType.isEmpty()) { + Map tt = signsByType.get(jobNameOrType); + if (tt != null) { + tt.remove(jSign.locToBlockString()); + } + } - signsByLocation.remove(jSign.locToBlockString()); - save = true; - continue; - } + signsByLocation.remove(jSign.locToBlockString()); + save = true; + continue; + } - String signJobName = jSign.getJobName(); - if (type == SignTopType.toplist && (playerList = temp.get(signJobName)) == null) { - playerList = Jobs.getJobsDAO().toplist(signJobName); - temp.put(signJobName, playerList); - } + String signJobName = jSign.getJobName(); + if (type == SignTopType.toplist && (playerList = temp.get(signJobName)) == null) { + playerList = Jobs.getJobsDAO().toplist(signJobName); + temp.put(signJobName, playerList); + } - if (Jobs.getJob(jSign.getJobName()) != null) - signJobName = Jobs.getJob(jSign.getJobName()).getDisplayName(); + if (Jobs.getJob(jSign.getJobName()) != null) + signJobName = Jobs.getJob(jSign.getJobName()).getDisplayName(); - if (playerList.isEmpty()) - continue; + if (playerList.isEmpty()) + continue; - int number = jSign.getNumber() - 1; - Sign sign = (Sign) block.getState(); + int number = jSign.getNumber() - 1; + Sign sign = (Sign) block.getState(); - if (!jSign.isSpecial()) { - for (int i = 0; i < 4; i++) { - if (i + number >= playerList.size()) { - plugin.getComplement().setLine(sign, i, ""); - continue; - } + if (!jSign.isSpecial()) { + for (int i = 0; i < 4; i++) { + if (i + number >= playerList.size()) { + plugin.getComplement().setLine(sign, i, ""); + continue; + } - TopList pl = playerList.get(i + number); - String playerName = pl.getPlayerInfo().getName(); - if (playerName.length() > 15) { - // We need to split 10 char of name, because of sign rows - playerName = playerName.split("(?<=\\G.{10})", 2)[0] + "~"; - } + TopList pl = playerList.get(i + number); + String playerName = pl.getPlayerInfo().getName(); + if (playerName.length() > 15) { + // We need to split 10 char of name, because of sign rows + playerName = playerName.split("(?<=\\G.{10})", 2)[0] + "~"; + } - String line = ""; - switch (type) { - case toplist: - case gtoplist: - line = Jobs.getLanguage().getMessage("signs.List", "[number]", i + number + 1, "[player]", playerName, "[level]", pl.getLevel()); - break; - case questtoplist: - line = Jobs.getLanguage().getMessage("signs.questList", "[number]", i + number + 1, "[player]", playerName, "[quests]", pl.getLevel()); - break; - default: - break; - } + String line = ""; + switch (type) { + case toplist: + case gtoplist: + line = Jobs.getLanguage().getMessage("signs.List", "[number]", i + number + 1, "[player]", playerName, "[level]", pl.getLevel()); + break; + case questtoplist: + line = Jobs.getLanguage().getMessage("signs.questList", "[number]", i + number + 1, "[player]", playerName, "[quests]", pl.getLevel()); + break; + default: + break; + } - if (!line.isEmpty()) - sign.setLine(i, line); - } - sign.update(); - if (!updateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) { - timelapse--; - } - } else { - if (jSign.getNumber() > playerList.size()) - continue; + if (!line.isEmpty()) + sign.setLine(i, line); + } + sign.update(); + if (!updateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) { + timelapse--; + } + } else { + if (jSign.getNumber() > playerList.size()) + continue; - TopList pl = playerList.get(jSign.getNumber() - 1); - String playerName = pl.getPlayerInfo().getName(); - if (playerName.length() > 15) { - playerName = playerName.split("(?<=\\G.{10})", 2)[0] + "~"; - } + TopList pl = playerList.get(jSign.getNumber() - 1); + String playerName = pl.getPlayerInfo().getName(); + if (playerName.length() > 15) { + playerName = playerName.split("(?<=\\G.{10})", 2)[0] + "~"; + } - int no = jSign.getNumber() + number + 1; - sign.setLine(0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName)); - sign.setLine(1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName)); + int no = jSign.getNumber() + number + 1; + sign.setLine(0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName)); + sign.setLine(1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName)); - switch (type) { - case toplist: - case gtoplist: - sign.setLine(2, translateSignLine("signs.SpecialList.level", no, playerName, pl.getLevel(), signJobName)); - break; - case questtoplist: - sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); - break; - default: - break; - } + switch (type) { + case toplist: + case gtoplist: + sign.setLine(2, translateSignLine("signs.SpecialList.level", no, playerName, pl.getLevel(), signJobName)); + break; + case questtoplist: + sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); + break; + default: + break; + } - sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName)); - sign.update(); - if (!updateHead(sign, pl.getPlayerInfo().getName(), timelapse)) { - timelapse--; - } - } - timelapse++; - } + sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName)); + sign.update(); + if (!updateHead(sign, pl.getPlayerInfo().getName(), timelapse)) { + timelapse--; + } + } + timelapse++; + } - if (save) - saveSigns(); + if (save) + saveSigns(); - return true; + return true; } private static String translateSignLine(String path, int number, String playerName, int level, String jobname) { - return Jobs.getLanguage().getMessage(path, - "[number]", number, - "[player]", playerName, - "[level]", level, - "[job]", jobname); + return Jobs.getLanguage().getMessage(path, + "[number]", number, + "[player]", playerName, + "[level]", level, + "[job]", jobname); } @SuppressWarnings("deprecation") public boolean updateHead(final Sign sign, final String playerName, int timelapse) { - if (playerName == null) - return false; + if (playerName == null) + return false; - if (timelapse < 1) { - timelapse = 1; - } + if (timelapse < 1) { + timelapse = 1; + } - BlockFace directionFacing = null; - if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) { - org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData(); - directionFacing = signMat.getFacing(); - } else { - if (CMIMaterial.isWallSign(sign.getType())) { - org.bukkit.block.data.type.WallSign data = (org.bukkit.block.data.type.WallSign) sign.getBlockData(); - directionFacing = data.getFacing(); - } else { - org.bukkit.block.data.type.Sign data = (org.bukkit.block.data.type.Sign) sign.getBlockData(); - directionFacing = data.getRotation(); - } - } + BlockFace directionFacing = null; + if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) { + org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData(); + directionFacing = signMat.getFacing(); + } else { + if (sign.getBlockData() instanceof org.bukkit.block.data.type.WallSign) + directionFacing = ((org.bukkit.block.data.type.WallSign) sign.getBlockData()).getFacing(); + else if (sign.getBlockData() instanceof org.bukkit.block.data.type.Sign) + directionFacing = ((org.bukkit.block.data.type.Sign) sign.getBlockData()).getRotation(); + } - final Location loc = sign.getLocation().clone(); - loc.add(0, 1, 0); + final Location loc = sign.getLocation().clone(); + loc.add(0, 1, 0); - if (directionFacing != null && !(loc.getBlock().getState() instanceof Skull)) - loc.add(directionFacing.getOppositeFace().getModX(), 0, directionFacing.getOppositeFace().getModZ()); + if (directionFacing != null && !(loc.getBlock().getState() instanceof Skull)) + loc.add(directionFacing.getOppositeFace().getModX(), 0, directionFacing.getOppositeFace().getModZ()); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - if (!(loc.getBlock().getState() instanceof Skull)) - return; + CMIScheduler.get().runTaskLater(new Runnable() { + @Override + public void run() { + if (!(loc.getBlock().getState() instanceof Skull)) + return; - Skull skull = (Skull) loc.getBlock().getState(); - if (playerName.equalsIgnoreCase(skull.getOwner())) - return; + Skull skull = (Skull) loc.getBlock().getState(); + if (playerName.equalsIgnoreCase(skull.getOwner())) + return; - skull.setOwner(playerName); - skull.update(); - } - }, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L); - return true; + skull.setOwner(playerName); + skull.update(); + } + }, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/Cmd.java b/src/main/java/com/gamingmesh/jobs/commands/Cmd.java index 08b9f84f..f2b4e6cc 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/Cmd.java +++ b/src/main/java/com/gamingmesh/jobs/commands/Cmd.java @@ -5,5 +5,5 @@ import org.bukkit.command.CommandSender; import com.gamingmesh.jobs.Jobs; public interface Cmd { - boolean perform(Jobs plugin, CommandSender sender, String[] args); + Boolean perform(Jobs plugin, CommandSender sender, String[] args); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 8d7e2d90..70f75052 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -14,6 +14,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.list.info; +import com.gamingmesh.jobs.commands.list.playerinfo; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.Boost; import com.gamingmesh.jobs.container.CurrencyType; @@ -22,13 +24,13 @@ import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Title; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; @@ -113,7 +115,12 @@ public class JobsCommands implements CommandExecutor { return true; } - return cmdClass.perform(plugin, sender, myArgs) || help(sender, 1); + Boolean result = cmdClass.perform(plugin, sender, myArgs); + + if (result != null && !result) + sendUsage(sender, cmd); + + return result == null || !result ? false : true; } private static String[] reduceArgs(String[] args) { @@ -162,18 +169,12 @@ public class JobsCommands implements CommandExecutor { boolean pl = sender instanceof Player; - // Old format -// sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.title")); for (String one : commands) { if (!pi.isEntryOk()) continue; if (pi.isBreak()) break; - // Old format -// sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one -// + ".help.info"))); - if (pl) { rm.addText("\n" + getUsage(one)); rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info")); @@ -182,12 +183,10 @@ public class JobsCommands implements CommandExecutor { rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one + ".help.info"))); } - } - rm.show(sender); - plugin.showPagination(sender, pi, LABEL + " ?"); + pi.autoPagination(sender, LABEL + " ?"); return true; } @@ -269,7 +268,7 @@ public class JobsCommands implements CommandExecutor { public void jobInfoMessage(CommandSender sender, JobsPlayer player, Job job, String type, int page) { if (job == null) { // job doesn't exist - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); + Language.sendMessage(sender, "general.error.job"); return; } @@ -277,21 +276,24 @@ public class JobsCommands implements CommandExecutor { List message = new ArrayList<>(); - if (job.getBoost().get(CurrencyType.EXP) != 0D) - message.add(Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1)); + for (CurrencyType one : CurrencyType.values()) { + double boost = job.getBoost().get(one); + if (boost != 0D) { - if (job.getBoost().get(CurrencyType.MONEY) != 0D) - message.add(Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.MONEY)) + 1)); + String boostAmount = String.valueOf(boost + 1); + if (boost % 1 == 0) + boostAmount = String.valueOf((int) boost + 1); - if (job.getBoost().get(CurrencyType.POINTS) != 0D) - message.add(Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1)); + message.add(Jobs.getLanguage().getMessage("command.boost.output.infostats", "%boost%", boostAmount, "%type%", one.getDisplayName())); + } + } if (Jobs.getGCManager().useDynamicPayment) { - int bonus = (int) ((job.getBonus() * 100) / 100.0); + int bonus = (int) (job.getBonus() * 100); if (bonus != 0) { if (bonus < 0) - message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1)); + message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", bonus * -1)); else message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", bonus)); } @@ -315,7 +317,7 @@ public class JobsCommands implements CommandExecutor { PageInfo pi = new PageInfo(15, message.size(), page); if (page > pi.getTotalPages()) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.invalidPage")); + Language.sendMessage(sender, "general.info.invalidPage"); return; } @@ -333,9 +335,9 @@ public class JobsCommands implements CommandExecutor { String pName = player.getName(); if (sender.getName().equalsIgnoreCase(pName)) - plugin.showPagination(sender, pi, "jobs info " + job.getName() + t); + pi.autoPagination(sender, LABEL + " " + info.class.getSimpleName() + " " + job.getName() + t); else - plugin.showPagination(sender, pi, "jobs playerinfo " + pName + " " + job.getName() + t); + pi.autoPagination(sender, LABEL + " " + playerinfo.class.getSimpleName() + " " + job.getName() + t); } } @@ -356,11 +358,11 @@ public class JobsCommands implements CommandExecutor { message.append(":\n"); JobProgression prog = player.getJobProgression(job); - + if (prog == null) { - prog = player.getArchivedJobProgression(job); - } - + prog = player.getArchivedJobProgression(job); + } + int level = prog != null ? prog.getLevel() : 1; int numjobs = player.progression.size(); @@ -421,6 +423,10 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public String jobStatsMessage(JobProgression jobProg) { + return jobStatsMessage(jobProg, true); + } + + public String jobStatsMessage(JobProgression jobProg, boolean progressBar) { boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel(); String path = "command.stats.output." + (isMaxLevelReached ? "max-level" : "message"); @@ -432,7 +438,7 @@ public class JobsCommands implements CommandExecutor { "%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0, "%jobmaxxp%", jobProg.getMaxExperience(), "%titlename%", title == null ? "Unknown" : title.getName()); - return " " + (isMaxLevelReached ? "" : jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience())) + " " + message; + return " " + (isMaxLevelReached ? "" : progressBar ? jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) : "") + " " + message; } public String jobProgressMessage(double max, double current) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/archive.java b/src/main/java/com/gamingmesh/jobs/commands/list/archive.java index fe05db70..5f8dc616 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/archive.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/archive.java @@ -10,50 +10,51 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.RawMessages.RawMessage; public class archive implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - JobsPlayer jPlayer = null; - if (args.length >= 1) { - if (!Jobs.hasPermission(sender, "jobs.command.admin.archive", true)) { - return true; - } - jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + JobsPlayer jPlayer = null; + if (args.length >= 1) { + if (!Jobs.hasPermission(sender, "jobs.command.admin.archive", true)) { + return null; + } + jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - } else if (sender instanceof Player) { - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - } + } else if (sender instanceof Player) { + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + } - if (jPlayer == null) { - if (args.length >= 1) - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + if (jPlayer == null) { + if (args.length >= 1) + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return null; + } - Set allJobs = jPlayer.getArchivedJobs().getArchivedJobs(); - if (allJobs.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.archive.error.nojob")); - return true; - } - - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName())); - for (JobProgression jobInfo : allJobs) { - RawMessage rm = new RawMessage(); - if (jobInfo.canRejoin()) - rm.addText(ChatColor.GREEN + "+" + Jobs.getCommandManager().jobStatsMessageArchive(jPlayer, jobInfo)) - .addHover(Jobs.getLanguage().getMessage("command.join.rejoin")).addCommand("jobs join " + jobInfo.getJob().getName()); - else - rm.addText(ChatColor.RED + "-" + Jobs.getCommandManager().jobStatsMessageArchive(jPlayer, jobInfo)) - .addHover(Jobs.getLanguage().getMessage("command.join.error.rejoin", "[time]", jobInfo - .getRejoinTimeMessage())); - rm.show(sender); - } + Set allJobs = jPlayer.getArchivedJobs().getArchivedJobs(); + if (allJobs.isEmpty()) { + Language.sendMessage(sender, "command.archive.error.nojob"); + return null; + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); - return true; + Language.sendMessage(sender, "general.info.toplineseparator", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName()); + for (JobProgression jobInfo : allJobs) { + RawMessage rm = new RawMessage(); + if (jobInfo.canRejoin()) + rm.addText(ChatColor.GREEN + "+" + Jobs.getCommandManager().jobStatsMessageArchive(jPlayer, jobInfo)) + .addHover(Jobs.getLanguage().getMessage("command.join.rejoin")).addCommand("jobs join " + jobInfo.getJob().getName()); + else + rm.addText(ChatColor.RED + "-" + Jobs.getCommandManager().jobStatsMessageArchive(jPlayer, jobInfo)) + .addHover(Jobs.getLanguage().getMessage("command.join.error.rejoin", "[time]", jobInfo + .getRejoinTimeMessage())); + rm.show(sender); + } + + Language.sendMessage(sender, "general.info.separator"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/area.java b/src/main/java/com/gamingmesh/jobs/commands/list/area.java index 30637c39..06ce46ae 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/area.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/area.java @@ -12,6 +12,7 @@ import com.gamingmesh.jobs.config.RestrictedAreaManager; import com.gamingmesh.jobs.container.CuboidArea; import com.gamingmesh.jobs.container.RestrictedArea; import com.gamingmesh.jobs.hooks.HookManager; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; @@ -20,151 +21,151 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class area implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return false; + } - Player player = (Player) sender; + Player player = (Player) sender; - if (args.length == 3) { - if (args[0].equalsIgnoreCase("add")) { - if (!Jobs.hasPermission(player, "jobs.area.add", true)) - return true; + if (args.length == 3) { + if (args[0].equalsIgnoreCase("add")) { + if (!Jobs.hasPermission(player, "jobs.area.add", true)) + return true; - double bonus = 0D; - try { - bonus = Double.parseDouble(args[2]); - } catch (NumberFormatException e) { - return false; - } + double bonus = 0D; + try { + bonus = Double.parseDouble(args[2]); + } catch (NumberFormatException e) { + return false; + } - boolean wg = false; + boolean wg = false; - String name = args[1]; - if (name.startsWith("wg:")) { - wg = true; - name = name.substring("wg:".length(), name.length()); - } + String name = args[1]; + if (name.startsWith("wg:")) { + wg = true; + name = name.substring("wg:".length(), name.length()); + } - RestrictedAreaManager ra = Jobs.getRestrictedAreaManager(); + RestrictedAreaManager ra = Jobs.getRestrictedAreaManager(); - if (ra.isExist(name)) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.exist")); - return true; - } + if (ra.isExist(name)) { + Language.sendMessage(sender, "command.area.output.exist"); + return true; + } - if (!wg && !Jobs.getSelectionManager().hasPlacedBoth(player)) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.select", - "%tool%", CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getName())); - return true; - } - if (wg && HookManager.getWorldGuardManager() != null) { - com.sk89q.worldguard.protection.regions.ProtectedRegion protectedRegion = HookManager.getWorldGuardManager().getProtectedRegionByName(name); + if (!wg && !Jobs.getSelectionManager().hasPlacedBoth(player)) { + Language.sendMessage(sender, "command.area.output.select", + "%tool%", CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getName()); + return true; + } + if (wg && HookManager.getWorldGuardManager() != null) { + com.sk89q.worldguard.protection.regions.ProtectedRegion protectedRegion = HookManager.getWorldGuardManager().getProtectedRegionByName(name); - if (protectedRegion == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgDontExist")); - return true; - } - name = protectedRegion.getId(); - } + if (protectedRegion == null) { + Language.sendMessage(sender, "command.area.output.wgDontExist"); + return true; + } + name = protectedRegion.getId(); + } - if (!wg) - ra.addNew(new RestrictedArea(name, Jobs.getSelectionManager().getSelectionCuboid(player), bonus), true); - else - ra.addNew(new RestrictedArea(name, name, bonus), true); - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.addedNew", "%bonus%", bonus)); - return true; - } - } + if (!wg) + ra.addNew(new RestrictedArea(name, Jobs.getSelectionManager().getSelectionCuboid(player), bonus), true); + else + ra.addNew(new RestrictedArea(name, name, bonus), true); + Language.sendMessage(sender, "command.area.output.addedNew", "%bonus%", bonus); + return true; + } + } - if (args.length == 2) { - if (args[0].equalsIgnoreCase("remove")) { - if (!Jobs.hasPermission(player, "jobs.area.remove", true)) - return true; + if (args.length == 2) { + if (args[0].equalsIgnoreCase("remove")) { + if (!Jobs.hasPermission(player, "jobs.area.remove", true)) + return true; - RestrictedAreaManager ra = Jobs.getRestrictedAreaManager(); - String name = args[1]; + RestrictedAreaManager ra = Jobs.getRestrictedAreaManager(); + String name = args[1]; - if (!ra.isExist(name)) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.dontExist")); - return true; - } + if (!ra.isExist(name)) { + Language.sendMessage(sender, "command.area.output.dontExist"); + return true; + } - ra.remove(name); - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.removed", "%name%", name)); - return true; - } - } + ra.remove(name); + Language.sendMessage(sender, "command.area.output.removed", "%name%", name); + return true; + } + } - if (args.length == 1 && args[0].equalsIgnoreCase("info")) { + if (args.length == 1 && args[0].equalsIgnoreCase("info")) { - List areas = Jobs.getRestrictedAreaManager().getRestrictedAreasByLoc(player.getLocation()); + List areas = Jobs.getRestrictedAreaManager().getRestrictedAreasByLoc(player.getLocation()); - String msg = ""; + String msg = ""; - for (RestrictedArea area : areas) { - if (!msg.isEmpty()) - msg += ", "; - msg += area.getName(); - } + for (RestrictedArea area : areas) { + if (!msg.isEmpty()) + msg += ", "; + msg += area.getName(); + } - if (msg.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.noAreasByLoc")); - return true; - } - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.areaList", "%list%", msg)); - return true; - } + if (msg.isEmpty()) { + Language.sendMessage(sender, "command.area.output.noAreasByLoc"); + return true; + } + Language.sendMessage(sender, "command.area.output.areaList", "%list%", msg); + return true; + } - if (args.length == 1 && args[0].equalsIgnoreCase("list")) { + if (args.length == 1 && args[0].equalsIgnoreCase("list")) { - java.util.Map areas = Jobs.getRestrictedAreaManager().getRestrictedAreas(); - if (areas.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.noAreas")); - return true; - } + java.util.Map areas = Jobs.getRestrictedAreaManager().getRestrictedAreas(); + if (areas.isEmpty()) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.noAreas")); + return true; + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); - int i = 0; - for (Entry area : areas.entrySet()) { - i++; - CuboidArea cuboid = area.getValue().getCuboidArea(); - if (area.getValue().getWgName() == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.list", "%number%", i, - "%areaname%", area.getKey(), - "%worldname%", cuboid.getWorld().getName(), - "%x1%", cuboid.getLowLoc().getBlockX(), - "%y1%", cuboid.getLowLoc().getBlockY(), - "%z1%", cuboid.getLowLoc().getBlockZ(), - "%x2%", cuboid.getHighLoc().getBlockX(), - "%y2%", cuboid.getHighLoc().getBlockY(), - "%z2%", cuboid.getHighLoc().getBlockZ(), - "%bonus%", area.getValue().getMultiplier())); - } else { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgList", "%number%", i, - "%areaname%", area.getKey(), - "%bonus%", area.getValue().getMultiplier())); - } - } - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); - return true; - } + sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); + int i = 0; + for (Entry area : areas.entrySet()) { + i++; + CuboidArea cuboid = area.getValue().getCuboidArea(); + if (area.getValue().getWgName() == null) { + Language.sendMessage(sender, "command.area.output.list", "%number%", i, + "%areaname%", area.getKey(), + "%worldname%", cuboid.getWorld().getName(), + "%x1%", cuboid.getLowLoc().getBlockX(), + "%y1%", cuboid.getLowLoc().getBlockY(), + "%z1%", cuboid.getLowLoc().getBlockZ(), + "%x2%", cuboid.getHighLoc().getBlockX(), + "%y2%", cuboid.getHighLoc().getBlockY(), + "%z2%", cuboid.getHighLoc().getBlockZ(), + "%bonus%", area.getValue().getMultiplier()); + } else { + Language.sendMessage(sender, "command.area.output.wgList", "%number%", i, + "%areaname%", area.getKey(), + "%bonus%", area.getValue().getMultiplier()); + } + } + Language.sendMessage(sender, "general.info.separator"); + return true; + } - if (args.length > 0) { - if (args[0].equalsIgnoreCase("add")) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.help.addUsage")); - return true; - } + if (args.length > 0) { + if (args[0].equalsIgnoreCase("add")) { + Language.sendMessage(sender, "command.area.help.addUsage"); + return true; + } - if (args[0].equalsIgnoreCase("remove")) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.area.help.removeUsage")); - return true; - } - } + if (args[0].equalsIgnoreCase("remove")) { + Language.sendMessage(sender, "command.area.help.removeUsage"); + return true; + } + } - return false; + return false; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java index 2aa7c03d..20940495 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java @@ -18,15 +18,10 @@ public class blockinfo implements Cmd { @Override @SuppressWarnings("deprecation") - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { if (!(sender instanceof Player)) { CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } - - if (args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "blockinfo"); - return true; + return null; } Block block = Util.getTargetBlock((Player) sender, 15); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java index f176ed45..5b563739 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java @@ -13,6 +13,7 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.hooks.HookManager; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -21,87 +22,85 @@ import net.Zrips.CMILib.RawMessages.RawMessage; public class bonus implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - if (args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "bonus"); - return true; - } + if (args.length != 1) { + Jobs.getCommandManager().sendUsage(sender, "bonus"); + return true; + } - Player player = (Player) sender; - Job job = Jobs.getJob(args[0]); - if (job == null) { - player.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Player player = (Player) sender; + Job job = Jobs.getJob(args[0]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return false; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return false; - Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job, true, true); + Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job, true, true); - player.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline")); + Language.sendMessage(sender, "command.bonus.output.topline"); - printBoost(sender, boost, BoostOf.Permission); - printBoost(sender, boost, BoostOf.Item); - printBoost(sender, boost, BoostOf.Global); - if (Jobs.getGCManager().useDynamicPayment) - printBoost(sender, boost, BoostOf.Dynamic); - printBoost(sender, boost, BoostOf.Area); - if (Jobs.getGCManager().payNearSpawner()) - printBoost(sender, boost, BoostOf.NearSpawner); - printBoost(sender, boost, BoostOf.PetPay); + printBoost(sender, boost, BoostOf.Permission); + printBoost(sender, boost, BoostOf.Item); + printBoost(sender, boost, BoostOf.Global); + if (Jobs.getGCManager().useDynamicPayment) + printBoost(sender, boost, BoostOf.Dynamic); + printBoost(sender, boost, BoostOf.Area); + if (Jobs.getGCManager().payNearSpawner()) + printBoost(sender, boost, BoostOf.NearSpawner); + printBoost(sender, boost, BoostOf.PetPay); - if (HookManager.getMcMMOManager().mcMMOPresent || - HookManager.getMcMMOManager().mcMMOOverHaul && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D) - printBoost(sender, boost, BoostOf.McMMO); + if (HookManager.getMcMMOManager().mcMMOPresent || + HookManager.getMcMMOManager().mcMMOOverHaul && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D) + printBoost(sender, boost, BoostOf.McMMO); - player.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); + Language.sendMessage(sender, "general.info.separator"); - RawMessage rm = new RawMessage(); - String msg = Jobs.getLanguage().getMessage("command.bonus.output.final", - "%money%", formatText(boost.getFinal(CurrencyType.MONEY, true, true)), - "%points%", formatText(boost.getFinal(CurrencyType.POINTS, true, true)), - "%exp%", formatText(boost.getFinal(CurrencyType.EXP, true, true))); - - String msg2 = Jobs.getLanguage().getMessage("command.bonus.output.final", - "%money%", formatText(boost.getFinal(CurrencyType.MONEY, true, false)), - "%points%", formatText(boost.getFinal(CurrencyType.POINTS, true, false)), - "%exp%", formatText(boost.getFinal(CurrencyType.EXP, true, false))); + RawMessage rm = new RawMessage(); + String msg = Jobs.getLanguage().getMessage("command.bonus.output.final", + "%money%", formatText(boost.getFinal(CurrencyType.MONEY, true, true)), + "%points%", formatText(boost.getFinal(CurrencyType.POINTS, true, true)), + "%exp%", formatText(boost.getFinal(CurrencyType.EXP, true, true))); - rm.addText(msg).addHover(Arrays.asList(Jobs.getLanguage().getMessage("command.bonus.output.finalExplanation"), msg2)); - - - - rm.build(); - rm.show(player); + String msg2 = Jobs.getLanguage().getMessage("command.bonus.output.final", + "%money%", formatText(boost.getFinal(CurrencyType.MONEY, true, false)), + "%points%", formatText(boost.getFinal(CurrencyType.POINTS, true, false)), + "%exp%", formatText(boost.getFinal(CurrencyType.EXP, true, false))); - return true; + rm.addText(msg).addHover(Arrays.asList(Jobs.getLanguage().getMessage("command.bonus.output.finalExplanation"), msg2)); + + rm.build(); + rm.show(player); + + return true; } private static void printBoost(CommandSender sender, Boost boost, BoostOf type) { - String prefix = Jobs.getLanguage().getMessage("command.bonus.output.specialPrefix"); - if (type != BoostOf.NearSpawner && type != BoostOf.PetPay) - prefix = ""; + String prefix = Jobs.getLanguage().getMessage("command.bonus.output.specialPrefix"); + if (type != BoostOf.NearSpawner && type != BoostOf.PetPay) + prefix = ""; - String msg = Jobs.getLanguage().getMessage("command.bonus.output." + type.name().toLowerCase(), - "%money%", formatText(boost.get(type, CurrencyType.MONEY, true)), - "%points%", formatText(boost.get(type, CurrencyType.POINTS, true)), - "%exp%", formatText(boost.get(type, CurrencyType.EXP, true))); + String msg = Jobs.getLanguage().getMessage("command.bonus.output." + type.name().toLowerCase(), + "%money%", formatText(boost.get(type, CurrencyType.MONEY, true)), + "%points%", formatText(boost.get(type, CurrencyType.POINTS, true)), + "%exp%", formatText(boost.get(type, CurrencyType.EXP, true))); - if ((type == BoostOf.NearSpawner || type == BoostOf.PetPay) && msg.startsWith(" ")) - msg = msg.substring(1, msg.length()); + if ((type == BoostOf.NearSpawner || type == BoostOf.PetPay) && msg.startsWith(" ")) + msg = msg.substring(1, msg.length()); - sender.sendMessage(prefix + msg); + CMIMessages.sendMessage(sender, prefix + msg); } private static String formatText(double amount) { - return ((amount > 0 ? "+" : "") + amount + "%"); + return ((amount > 0 ? "+" : "") + amount + "%"); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/boost.java b/src/main/java/com/gamingmesh/jobs/commands/list/boost.java new file mode 100644 index 00000000..9e24e2a8 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/commands/list/boost.java @@ -0,0 +1,174 @@ +package com.gamingmesh.jobs.commands.list; + +import org.bukkit.command.CommandSender; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.container.CurrencyType; +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.i18n.Language; + +import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.RawMessages.RawMessage; +import net.Zrips.CMILib.Time.CMITimeManager; +import net.Zrips.CMILib.Time.timeModifier; + +public class boost implements Cmd { + + @Override + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + + Double rate = null; + Long timeDuration = null; + Job job = null; + boolean allJobs = false; + boolean reset = false; + CurrencyType type = null; + + for (String one : args) { + + if (type == null) { + type = CurrencyType.getByName(one); + if (type != null) + continue; + } + + if (one.equalsIgnoreCase("all")) { + allJobs = true; + continue; + } + + if (one.equalsIgnoreCase("reset")) { + reset = true; + continue; + } + + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } + + if (rate == null) { + try { + rate = Double.parseDouble(one); + continue; + } catch (NumberFormatException e) { + } + } + + try { + Long t = timeModifier.getTimeRangeFromString(one); + if (timeDuration == null && t != null) { + timeDuration = t; + continue; + } + } catch (Exception e) { + } + } + + if (job == null && rate == null && !reset) { + LC.info_Spliter.sendMessage(sender); + for (Job one : Jobs.getJobs()) { + showBoosts(sender, one); + } + return true; + } + + if (job != null && rate == null) { + LC.info_Spliter.sendMessage(sender); + showBoosts(sender, job); + return true; + } + + if (rate == null) + rate = 1D; + + if (timeDuration == null) + timeDuration = 0L; + + if (reset) { + if (job == null) { + if (type == null) { + for (Job one : Jobs.getJobs()) { + for (CurrencyType curr : CurrencyType.values()) { + one.addBoost(curr, 0); + } + } + Language.sendMessage(sender, "command.boost.output.allreset"); + } else { + for (Job one : Jobs.getJobs()) { + one.addBoost(type, 0); + } + Language.sendMessage(sender, "command.boost.output.alltypereset", "%type%", type.getDisplayName()); + } + } else { + if (type == null) { + for (CurrencyType curr : CurrencyType.values()) { + job.addBoost(curr, 0); + } + Language.sendMessage(sender, "command.moneyboost.output.jobsboostreset", "%jobname%", job.getName()); + } else { + job.addBoost(type, 0); + Language.sendMessage(sender, "command.moneyboost.output.jobstypeboostreset", "%jobname%", job.getName(), "%type%", type.getDisplayName()); + } + } + return true; + } + + if (job == null || allJobs) { + for (Job one : Jobs.getJobs()) { + if (type == null) { + for (CurrencyType curr : CurrencyType.values()) { + one.addBoost(curr, rate, timeDuration); + } + } else { + one.addBoost(type, rate, timeDuration); + } + + Language.sendMessage(sender, "command.boost.output.boostadded", "%boost%", rate, "%jobname%", one.getName()); + } + } else { + if (type == null) { + for (CurrencyType curr : CurrencyType.values()) { + job.addBoost(curr, rate, timeDuration); + } + } else { + job.addBoost(type, rate, timeDuration); + } + Language.sendMessage(sender, "command.boost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()); + } + + return true; + } + + private static void showBoosts(CommandSender sender, Job job) { + RawMessage rm = new RawMessage(); + String msg = Jobs.getLanguage().getMessage("command.boost.output.boostStats", "%jobname%", job.getDisplayName()); + String[] split = msg.split("%payments%"); + + rm.addText(split[0]); + +// String msg = Jobs.getLanguage().getMessage("command.boost.output.boostStats", "%jobname%", job.getDisplayName()); + for (CurrencyType curr : CurrencyType.values()) { + + double boost = job.getBoost().get(curr); + + String boostAmount = String.valueOf(boost); + if (boost % 1 == 0) + boostAmount = String.valueOf((int) boost); + + if (curr.isEnabled()) { + rm.addText(Jobs.getLanguage().getMessage("general.info.paymentTypeValued." + curr.toString(), "%amount%", boostAmount) + " "); + } + + if (job.getBoost().getTime(curr) != null && job.getBoost().isValid(curr)) { + rm.addHover(CMITimeManager.to24hourShort(job.getBoost().getTime(curr) - System.currentTimeMillis())); + } + } + if (split.length > 1) + rm.addText(split[1]); + rm.show(sender); + } +} diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/bp.java b/src/main/java/com/gamingmesh/jobs/commands/list/bp.java index d026c992..a8217b30 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/bp.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/bp.java @@ -13,17 +13,19 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.BlockProtection; import com.gamingmesh.jobs.container.DBAction; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class bp implements Cmd { @SuppressWarnings("deprecation") @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { if (!(sender instanceof Player)) { CMIMessages.sendMessage(sender, LC.info_Ingame); @@ -73,23 +75,24 @@ public class bp implements Cmd { } if (changedBlocks.isEmpty()) - sender.sendMessage(Jobs.getLanguage().getMessage("command.bp.output.notFound")); + Language.sendMessage(sender, "command.bp.output.notFound"); else - sender.sendMessage(Jobs.getLanguage().getMessage("command.bp.output.found", "%amount%", changedBlocks.size())); + Language.sendMessage(sender, "command.bp.output.found", "%amount%", changedBlocks.size()); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - if (Version.isCurrentEqualOrHigher(Version.v1_15_R1)) + if (!changedBlocks.isEmpty()) { + Location bloc = changedBlocks.get(0).getLocation(); + CMIScheduler.get().runAtLocationLater(bloc, () -> { + if (Version.isCurrentEqualOrHigher(Version.v1_15_R1)) { for (Block one : changedBlocks) { player.sendBlockChange(one.getLocation(), one.getBlockData()); } - else + } else { for (Block one : changedBlocks) { player.sendBlockChange(one.getLocation(), one.getType(), one.getData()); } - } - }, 120L); + } + }, 120L); + } return true; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java index 89188b3b..b68989cb 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java @@ -9,20 +9,22 @@ import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Container.PageInfo; +import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; public class browse implements Cmd { @Override - public boolean perform(Jobs plugin, CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, CommandSender sender, final String[] args) { boolean senderIsPlayer = sender instanceof Player; if (Jobs.getGCManager().BrowseUseNewLook) { if (Jobs.getJobs().isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.error.nojobs")); + Language.sendMessage(sender, "command.browse.error.nojobs"); return true; } @@ -60,7 +62,7 @@ public class browse implements Cmd { if (senderIsPlayer) { if (j == null) { PageInfo pi = new PageInfo(Jobs.getGCManager().getBrowseAmountToShow(), jobList.size(), page); - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.newHeader", "[amount]", jobList.size())); + Language.sendMessage(sender, "command.browse.output.newHeader", "[amount]", jobList.size()); for (Job one : jobList) { if (!pi.isEntryOk()) continue; @@ -113,28 +115,28 @@ public class browse implements Cmd { rm.show(sender); } - plugin.showPagination(sender, pi, "jobs browse", "-p:"); + pi.autoPagination(sender, "jobs browse", "-p:"); } else { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName())); + Language.sendMessage(sender, "command.browse.output.jobHeader", "[jobname]", j.getName()); int maxLevel = j.getMaxLevel(sender); if (maxLevel > 0) - sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.newMax", "[max]", maxLevel)); + Language.sendMessage(sender, "command.info.help.newMax", "[max]", maxLevel); if (Jobs.getGCManager().ShowTotalWorkers) - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", j.getTotalPlayers())); + Language.sendMessage(sender, "command.browse.output.totalWorkers", "[amount]", j.getTotalPlayers()); if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus) { int bonus = (int) (j.getBonus() * 100); if (bonus < 0) - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", bonus * -1)); + Language.sendMessage(sender, "command.browse.output.penalty", "[amount]", bonus * -1); else - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", bonus)); + Language.sendMessage(sender, "command.browse.output.bonus", "[amount]", bonus); } for (String one : j.getFullDescription()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one)); + Language.sendMessage(sender, "command.browse.output.description", "[description]", one); } RawMessage rm = new RawMessage(); @@ -148,7 +150,7 @@ public class browse implements Cmd { } } else { if (j == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.console.newHeader", "[amount]", jobList.size(), "\\n", "\n")); + Language.sendMessage(sender, "command.browse.output.console.newHeader", "[amount]", jobList.size(), "\\n", "\n"); for (Job one : jobList) { String msg = ""; @@ -177,14 +179,14 @@ public class browse implements Cmd { msg += Jobs.getLanguage().getMessage("command.browse.output.console.list", "[jobname]", one.getName()); - sender.sendMessage(msg); + CMIMessages.sendMessage(sender, msg); } } else { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName())); + Language.sendMessage(sender, "command.browse.output.jobHeader", "[jobname]", j.getName()); int maxLevel = j.getMaxLevel(sender); if (maxLevel > 0) - sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.newMax", "[max]", maxLevel)); + Language.sendMessage(sender, "command.info.help.newMax", "[max]", maxLevel); if (Jobs.getGCManager().ShowTotalWorkers) sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", j.getTotalPlayers())); @@ -192,13 +194,13 @@ public class browse implements Cmd { if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus) { int bonus = (int) (j.getBonus() * 100); if (bonus < 0) - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", bonus * -1)); + Language.sendMessage(sender, "command.browse.output.penalty", "[amount]", bonus * -1); else - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", bonus)); + Language.sendMessage(sender, "command.browse.output.bonus", "[amount]", bonus); } for (String one : j.getFullDescription()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one)); + Language.sendMessage(sender, "command.browse.output.description", "[description]", one); } } } @@ -245,7 +247,7 @@ public class browse implements Cmd { } if (lines.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.error.nojobs")); + Language.sendMessage(sender, "command.browse.error.nojobs"); return true; } @@ -260,9 +262,9 @@ public class browse implements Cmd { } if (Jobs.getGCManager().JobsGUIShowChatBrowse) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.header")); + Language.sendMessage(sender, "command.browse.output.header"); lines.forEach(sender::sendMessage); - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.footer")); + Language.sendMessage(sender, "command.browse.output.footer"); } } return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/clearownership.java b/src/main/java/com/gamingmesh/jobs/commands/list/clearownership.java index b1dbb7de..541b906d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/clearownership.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/clearownership.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -18,7 +19,7 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class clearownership implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { JobsPlayer jPlayer = null; String location = null; @@ -47,8 +48,8 @@ public class clearownership implements Cmd { if (args.length >= 1) CMIMessages.sendMessage(sender, LC.info_NoInformation); else - Jobs.getCommandManager().sendUsage(sender, "clearownership"); - return true; + return false; + return null; } final UUID uuid = jPlayer.getUniqueId(); @@ -64,8 +65,8 @@ public class clearownership implements Cmd { } } - sender.sendMessage(Jobs.getLanguage().getMessage("command.clearownership.output.cleared", "[furnaces]", amounts.getOrDefault(BlockTypes.FURNACE, 0), "[brewing]", amounts.getOrDefault( - BlockTypes.BREWING_STAND, 0), "[smoker]", amounts.getOrDefault(BlockTypes.SMOKER, 0), "[blast]", amounts.getOrDefault(BlockTypes.BLAST_FURNACE, 0))); + Language.sendMessage(sender,"command.clearownership.output.cleared", "[furnaces]", amounts.getOrDefault(BlockTypes.FURNACE, 0), "[brewing]", amounts.getOrDefault( + BlockTypes.BREWING_STAND, 0), "[smoker]", amounts.getOrDefault(BlockTypes.SMOKER, 0), "[blast]", amounts.getOrDefault(BlockTypes.BLAST_FURNACE, 0)); return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/convert.java b/src/main/java/com/gamingmesh/jobs/commands/list/convert.java index 0d691d78..fc6e8081 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/convert.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/convert.java @@ -1,6 +1,5 @@ package com.gamingmesh.jobs.commands.list; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,29 +9,29 @@ import com.gamingmesh.jobs.dao.JobsManager.DataBaseType; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class convert implements Cmd { @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (sender instanceof Player) { - CMIMessages.sendMessage(sender, LC.info_FromConsole); - return true; - } + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (sender instanceof Player) { + CMIMessages.sendMessage(sender, LC.info_FromConsole); + return true; + } - if (args.length > 0) { - Jobs.getCommandManager().sendUsage(sender, "convert"); - return true; - } + if (args.length > 0) { + return false; + } - String from = Jobs.getDBManager().getDbType() == DataBaseType.SqLite ? "SQLite" : "MySQL"; - String to = Jobs.getDBManager().getDbType() == DataBaseType.SqLite ? "MySQL" : "SQLite"; + String from = Jobs.getDBManager().getDbType() == DataBaseType.SqLite ? "SQLite" : "MySQL"; + String to = Jobs.getDBManager().getDbType() == DataBaseType.SqLite ? "MySQL" : "SQLite"; - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - Jobs.convertDatabase(); - Jobs.consoleMsg("&eDatabase was converted from &2" + from + " &eto &2" + to + "&e!"); - }); + CMIScheduler.get().runTaskAsynchronously(() -> { + Jobs.convertDatabase(); + CMIMessages.consoleMessage("&eDatabase was converted from &2" + from + " &eto &2" + to + "&e!"); + }); - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/demote.java b/src/main/java/com/gamingmesh/jobs/commands/list/demote.java index ce86a1ef..b87b3a7a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/demote.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/demote.java @@ -7,55 +7,54 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Colors.CMIChatColor; public class demote implements Cmd { @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length < 3) { - Jobs.getCommandManager().sendUsage(sender, "demote"); - return true; - } + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length < 3) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - try { - // check if player already has the job - if (jPlayer.isInJob(job)) { - int levelsLost = 0; - try { - levelsLost = Integer.parseInt(args[2]); - } catch (NumberFormatException ex) { - return true; - } + try { + // check if player already has the job + if (jPlayer.isInJob(job)) { + int levelsLost = 0; + try { + levelsLost = Integer.parseInt(args[2]); + } catch (NumberFormatException ex) { + return true; + } - Jobs.getPlayerManager().demoteJob(jPlayer, job, levelsLost); + Jobs.getPlayerManager().demoteJob(jPlayer, job, levelsLost); - Player player = jPlayer.getPlayer(); - if (player != null) { - String message = Jobs.getLanguage().getMessage("command.demote.output.target", - "%jobname%", job.getDisplayName() + CMIChatColor.WHITE, - "%levelslost%", levelsLost); - player.sendMessage(message); - } + Player player = jPlayer.getPlayer(); + if (player != null) { + Language.sendMessage(sender, "command.demote.output.target", + "%jobname%", job.getDisplayName() + CMIChatColor.WHITE, + "%levelslost%", levelsLost); + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } - } catch (Throwable e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - } - return true; + Language.sendMessage(sender, "general.admin.success"); + } + } catch (Throwable e) { + Language.sendMessage(sender, "general.admin.error"); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java index 19a314c4..ca132e6e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java @@ -13,6 +13,7 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Items.CMIItemStack; @@ -23,37 +24,37 @@ import net.Zrips.CMILib.NBT.CMINBT; public class edititembonus implements Cmd { private enum actions { - list, add, remove; + list, add, remove; - public static actions getByname(String name) { - for (actions one : actions.values()) { - if (one.name().equalsIgnoreCase(name)) - return one; - } - return null; - } + public static actions getByname(String name) { + for (actions one : actions.values()) { + if (one.name().equalsIgnoreCase(name)) + return one; + } + return null; + } } @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - if (args.length < 1) - return false; + if (args.length < 1) + return false; - actions action = null; + actions action = null; // Job job = null; - JobItems jobitem = null; + JobItems jobitem = null; - for (String one : args) { - if (action == null) { - action = actions.getByname(one); - if (action != null) - continue; - } + for (String one : args) { + if (action == null) { + action = actions.getByname(one); + if (action != null) + continue; + } // if (job == null) { // job = Jobs.getJob(one); // if (job != null) @@ -61,68 +62,67 @@ public class edititembonus implements Cmd { // } // if (job != null) { - jobitem = ItemBoostManager.getItemByKey(one); + jobitem = ItemBoostManager.getItemByKey(one); // } - } + } - if (action == null) - return false; + if (action == null) + return false; - Player player = (Player) sender; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return false; + Player player = (Player) sender; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return false; - ItemStack iih = CMIItemStack.getItemInMainHand(player); - if (iih == null || iih.getType() == Material.AIR) - return false; + ItemStack iih = CMIItemStack.getItemInMainHand(player); + if (iih == null || iih.getType() == Material.AIR) + return false; - switch (action) { - case add: - if (jobitem == null) - return false; - iih = (ItemStack) new CMINBT(iih).setString("JobsItemBoost", jobitem.getNode()); - CMIItemStack.setItemInMainHand(player, iih); - break; - case list: - break; - case remove: - iih = (ItemStack) new CMINBT(iih).remove("JobsItemBoost"); - CMIItemStack.setItemInMainHand(player, iih); - break; - default: - break; - } + switch (action) { + case add: + if (jobitem == null) + return false; + iih = (ItemStack) new CMINBT(iih).setString("JobsItemBoost", jobitem.getNode()); + CMIItemStack.setItemInMainHand(player, iih); + break; + case list: + break; + case remove: + iih = (ItemStack) new CMINBT(iih).remove("JobsItemBoost"); + CMIItemStack.setItemInMainHand(player, iih); + break; + default: + break; + } - sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline")); + Language.sendMessage(sender, "command.bonus.output.topline"); - Object key = new CMINBT(iih).getString("JobsItemBoost"); - if (key == null) - return true; + Object key = new CMINBT(iih).getString("JobsItemBoost"); + if (key == null) + return true; - JobItems item = ItemBoostManager.getItemByKey(key.toString()); - if (item == null) - return true; + JobItems item = ItemBoostManager.getItemByKey(key.toString()); + if (item == null) + return true; - BoostMultiplier boost = item.getBoost(); + BoostMultiplier boost = item.getBoost(); - String mc = CMIChatColor.DARK_GREEN.toString(), - pc = CMIChatColor.GOLD.toString(), - ec = CMIChatColor.YELLOW.toString(); + String mc = CMIChatColor.DARK_GREEN.toString(); + String pc = CMIChatColor.GOLD.toString(); + String ec = CMIChatColor.YELLOW.toString(); - for (Job one : item.getJobs()) { - String msg = Jobs.getLanguage().getMessage("command.itembonus.output.list", - "[jobname]", one.getName(), - "%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)), - "%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)), - "%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100))); - sender.sendMessage(msg); - } - return true; + for (Job one : item.getJobs()) { + Language.sendMessage(sender, "command.itembonus.output.list", + "[jobname]", one.getName(), + "%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)), + "%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)), + "%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100))); + } + return true; } private static String formatText(double amount) { - return ((amount > 0 ? "+" : "") + amount + "%"); + return ((amount > 0 ? "+" : "") + amount + "%"); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java index 32fe6aec..3ab29b44 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java @@ -20,6 +20,7 @@ import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.Version.Version; @@ -27,410 +28,415 @@ public class editjobs implements Cmd { @SuppressWarnings("deprecation") @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - - if (!(sender instanceof Player)) - return false; - - Player player = (Player) sender; - - if (args.length == 0) - args = new String[] { "list" }; - - switch (args[0]) { - case "list": - if (args.length == 1) { - showPath(player, null, null, null); - - for (Job one : Jobs.getJobs()) { - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.jobs", "%jobname%", one.getJobDisplayName()), one.getName(), "jobs editjobs list " + one.getName()); - rm.show(sender); - } - - Util.getJobsEditorMap().remove(player.getUniqueId()); - return true; - } - - if (args.length == 2) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - showPath(player, job, null, null); - - for (ActionType oneI : ActionType.values()) { - List action = job.getJobInfo(oneI); - if (action == null || action.isEmpty()) - continue; - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.actions", "%actionname%", oneI.getName()), oneI.getName(), "jobs editjobs list " + job.getName() + " " + oneI.getName() - + " 1"); - rm.show(sender); - } - - Util.getJobsEditorMap().remove(player.getUniqueId()); - return true; - } - - if (args.length == 4) { - Integer page = null; - try { - page = Integer.parseInt(args[3]); - } catch (NumberFormatException e) { - } - - if (page != null) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - showPath(player, job, actionT, null); - - PageInfo pi = new PageInfo(15, action.size(), page); - - for (JobInfo one : action) { - if (!pi.isEntryOk()) - continue; - - String materialName = one.getRealisticName(); - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.material", "%materialname%", materialName), one.getName(), "jobs editjobs list " + job.getName() + " " + actionT - .getName() + " " + one.getName()); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.materialRemove"), "&cRemove", "jobs editjobs remove " + job.getName() + " " + actionT.getName() + " " + one - .getName()); - rm.show(sender); - } - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.materialAdd"), "&eAdd new", "jobs editjobs add " + job.getName() + " " + actionT.getName()); - rm.show(sender); - Util.getJobsEditorMap().remove(player.getUniqueId()); - - plugin.showPagination(sender, pi, "jobs editjobs list " + job.getName() + " " + actionT.getName()); - return true; - } - - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - JobInfo jInfo = null; - for (JobInfo one : action) { - if (one.getName().equalsIgnoreCase(args[3])) { - jInfo = one; - break; - } - } - - if (jInfo == null) - return false; - - showPath(player, job, actionT, jInfo); - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.money", "%amount%", jInfo.getBaseIncome()), "&e" + jInfo.getBaseIncome(), "jobs editjobs modify " + job.getName() + " " - + actionT.getName() + " " + jInfo.getName() + " money "); - rm.show(sender); - - rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.points", "%amount%", jInfo.getBasePoints()), "&e" + jInfo.getBasePoints(), "jobs editjobs modify " + job.getName() + " " - + actionT.getName() + " " + jInfo.getName() - + " points "); - rm.show(sender); - - rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.exp", "%amount%", jInfo.getBaseXp()), "&e" + jInfo.getBaseXp(), "jobs editjobs modify " + job.getName() + " " + actionT - .getName() + " " + jInfo.getName() + " exp "); - rm.show(sender); - Util.getJobsEditorMap().remove(player.getUniqueId()); - return true; - } - break; - case "modify": - if (args.length == 5) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - JobInfo jInfo = null; - for (JobInfo one : action) { - if (one.getName().equalsIgnoreCase(args[3])) { - jInfo = one; - break; - } - } - - if (jInfo == null) - return false; - - CurrencyType type = CurrencyType.getByName(args[4]); - if (type == null) - return false; - - Util.getJobsEditorMap().put(player.getUniqueId(), "jobs editjobs modify " + job.getName() + " " + actionT.getName() + " " + jInfo.getName() + " " + type.getName() + " "); - sender.sendMessage(Jobs.getLanguage().getMessage("command.editjobs.help.modify.newValue")); - return true; - } - - if (args.length == 6) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - JobInfo jInfo = null; - for (JobInfo one : action) { - if (one.getName().equalsIgnoreCase(args[3])) { - jInfo = one; - break; - } - } - - if (jInfo == null) - return false; - - CurrencyType type = CurrencyType.getByName(args[4]); - if (type == null) - return false; - - Double value = null; - try { - value = Double.parseDouble(args[5]); - } catch (Exception e) { - return false; - } - - String sType = null; - switch (type) { - case EXP: - sType = "experience"; - jInfo.setBaseXp(value); - break; - case MONEY: - sType = "income"; - jInfo.setBaseIncome(value); - break; - case POINTS: - sType = "points"; - jInfo.setBasePoints(value); - break; - default: - break; - } - - Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/" + sType, value); - player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName()); - Util.getJobsEditorMap().remove(player.getUniqueId()); - return true; - } - - break; - case "remove": - // remove miner break stone:1 - - if (args.length == 4) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - JobInfo jInfo = null; - for (JobInfo info : action) { - if (!info.getName().equalsIgnoreCase(args[3])) - continue; - jInfo = info; - break; - } - - if (jInfo == null) { - return true; - } - - action.remove(jInfo); - Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath(), null); - player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " 1"); - Util.getJobsEditorMap().remove(player.getUniqueId()); - return true; - } - break; - case "add": - // add miner break stone:1 - - if (args.length == 3) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.enter")); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.hand"), Jobs.getLanguage().getMessage("command.editjobs.help.modify.handHover"), "jobs editjobs add " + job.getName() - + " " + actionT.getName() + " hand"); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.or")); - rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.look"), Jobs.getLanguage().getMessage("command.editjobs.help.modify.lookHover"), "jobs editjobs add " + job.getName() - + " " + actionT.getName() + " looking"); - rm.show(sender); - - Util.getJobsEditorMap().put(player.getUniqueId(), "jobs editjobs add " + job.getName() + " " + actionT.getName() + " "); - return true; - } - - if (args.length == 4) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - String key = args[3]; - switch (args[3]) { - case "hand": - ItemStack item = CMIItemStack.getItemInMainHand(player); - key = CMIMaterial.get(item).getName() + (Version.isCurrentEqualOrHigher(Version.v1_13_R1) ? "" : "-" + item.getData().getData()); - break; - case "offhand": - item = CMIItemStack.getItemInOffHand(player); - key = CMIMaterial.get(item).getName() + (Version.isCurrentEqualOrHigher(Version.v1_13_R1) ? "" : "-" + item.getData().getData()); - break; - case "looking": - case "lookingat": - Block block = Util.getTargetBlock(player, 30); - key = CMIMaterial.get(block).getName() + (Version.isCurrentEqualOrHigher(Version.v1_13_R1) ? "" : "-" + block.getData()); - break; - default: - break; - } - - KeyValues keyValue = Jobs.getConfigManager().getKeyValue(key, actionT, job.getName()); - if (keyValue == null) - return false; - - String type = keyValue.getType(), - subType = keyValue.getSubType(), - meta = keyValue.getMeta(); - int id = keyValue.getId(); - - double income = 0D, - points = 0D, - experience = 0D; - - int fromlevel = 1; - int untilLevel = -1; - - JobInfo jInfo = new JobInfo(actionT, id, meta, type + subType, income, job.getMoneyEquation(), experience, job.getXpEquation(), job.getPointsEquation(), points, fromlevel, - untilLevel, job.getName() + "/" + actionT.getName() + "/" + (type + subType).replace(":", "-")); - - for (JobInfo info : job.getJobInfo(actionT)) { - if (info.getName().equalsIgnoreCase(jInfo.getName())) { - player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName()); - return true; - } - } - - action.add(jInfo); - player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName()); - - Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/income", 0); - Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/points", 0); - Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/experience", 0); - - Util.getJobsEditorMap().remove(player.getUniqueId()); - return true; - } - - break; - default: - break; - } - - return true; + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + + if (!(sender instanceof Player)) { + LC.info_Ingame.sendMessage(sender); + return false; + } + + Player player = (Player) sender; + + if (args.length == 0) + args = new String[] { "list" }; + + switch (args[0]) { + case "list": + if (args.length == 1) { + showPath(player, null, null, null); + + for (Job one : Jobs.getJobs()) { + RawMessage rm = new RawMessage(); + rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.jobs", "%jobname%", one.getDisplayName())) + .addHover(one.getName()) + .addCommand("jobs editjobs list " + one.getName()); + rm.show(sender); + } + + Util.getJobsEditorMap().remove(player.getUniqueId()); + return true; + } + + if (args.length == 2) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + showPath(player, job, null, null); + + for (ActionType oneI : ActionType.values()) { + List action = job.getJobInfo(oneI); + if (action == null || action.isEmpty()) + continue; + + RawMessage rm = new RawMessage(); + rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.actions", "%actionname%", oneI.getName())) + .addHover(oneI.getName()) + .addCommand("jobs editjobs list " + job.getName() + " " + oneI.getName() + " 1"); + rm.show(sender); + } + + Util.getJobsEditorMap().remove(player.getUniqueId()); + return true; + } + + if (args.length == 4) { + Integer page = null; + try { + page = Integer.parseInt(args[3]); + } catch (NumberFormatException e) { + } + + if (page != null) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + showPath(player, job, actionT, null); + + PageInfo pi = new PageInfo(15, action.size(), page); + + for (JobInfo one : action) { + if (!pi.isEntryOk()) + continue; + + String materialName = one.getRealisticName(); + + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.material", "%materialname%", materialName), one.getName(), "jobs editjobs list " + job.getName() + " " + actionT + .getName() + " " + one.getName()); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.materialRemove"), "&cRemove", "jobs editjobs remove " + job.getName() + " " + actionT.getName() + " " + one + .getName()); + rm.show(sender); + } + + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.materialAdd"), "&eAdd new", "jobs editjobs add " + job.getName() + " " + actionT.getName()); + rm.show(sender); + Util.getJobsEditorMap().remove(player.getUniqueId()); + + pi.autoPagination(sender, "jobs editjobs list " + job.getName() + " " + actionT.getName()); + return true; + } + + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + JobInfo jInfo = null; + for (JobInfo one : action) { + if (one.getName().equalsIgnoreCase(args[3])) { + jInfo = one; + break; + } + } + + if (jInfo == null) + return false; + + showPath(player, job, actionT, jInfo); + + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.money", "%amount%", jInfo.getBaseIncome()), "&e" + jInfo.getBaseIncome(), "jobs editjobs modify " + job.getName() + " " + + actionT.getName() + " " + jInfo.getName() + " money "); + rm.show(sender); + + rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.points", "%amount%", jInfo.getBasePoints()), "&e" + jInfo.getBasePoints(), "jobs editjobs modify " + job.getName() + " " + + actionT.getName() + " " + jInfo.getName() + + " points "); + rm.show(sender); + + rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.list.exp", "%amount%", jInfo.getBaseXp()), "&e" + jInfo.getBaseXp(), "jobs editjobs modify " + job.getName() + " " + actionT + .getName() + " " + jInfo.getName() + " exp "); + rm.show(sender); + Util.getJobsEditorMap().remove(player.getUniqueId()); + return true; + } + break; + case "modify": + if (args.length == 5) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + JobInfo jInfo = null; + for (JobInfo one : action) { + if (one.getName().equalsIgnoreCase(args[3])) { + jInfo = one; + break; + } + } + + if (jInfo == null) + return false; + + CurrencyType type = CurrencyType.getByName(args[4]); + if (type == null) + return false; + + Util.getJobsEditorMap().put(player.getUniqueId(), "jobs editjobs modify " + job.getName() + " " + actionT.getName() + " " + jInfo.getName() + " " + type.getName() + " "); + sender.sendMessage(Jobs.getLanguage().getMessage("command.editjobs.help.modify.newValue")); + return true; + } + + if (args.length == 6) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + JobInfo jInfo = null; + for (JobInfo one : action) { + if (one.getName().equalsIgnoreCase(args[3])) { + jInfo = one; + break; + } + } + + if (jInfo == null) + return false; + + CurrencyType type = CurrencyType.getByName(args[4]); + if (type == null) + return false; + + Double value = null; + try { + value = Double.parseDouble(args[5]); + } catch (Exception e) { + return false; + } + + String sType = null; + switch (type) { + case EXP: + sType = "experience"; + jInfo.setBaseXp(value); + break; + case MONEY: + sType = "income"; + jInfo.setBaseIncome(value); + break; + case POINTS: + sType = "points"; + jInfo.setBasePoints(value); + break; + default: + break; + } + + Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/" + sType, value); + player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName()); + Util.getJobsEditorMap().remove(player.getUniqueId()); + return true; + } + + break; + case "remove": + // remove miner break stone:1 + + if (args.length == 4) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + JobInfo jInfo = null; + for (JobInfo info : action) { + if (!info.getName().equalsIgnoreCase(args[3])) + continue; + jInfo = info; + break; + } + + if (jInfo == null) { + return true; + } + + action.remove(jInfo); + Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath(), null); + player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " 1"); + Util.getJobsEditorMap().remove(player.getUniqueId()); + return true; + } + break; + case "add": + // add miner break stone:1 + + if (args.length == 3) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.enter")); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.hand"), Jobs.getLanguage().getMessage("command.editjobs.help.modify.handHover"), "jobs editjobs add " + job.getName() + + " " + actionT.getName() + " hand"); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.or")); + rm.add(Jobs.getLanguage().getMessage("command.editjobs.help.modify.look"), Jobs.getLanguage().getMessage("command.editjobs.help.modify.lookHover"), "jobs editjobs add " + job.getName() + + " " + actionT.getName() + " looking"); + rm.show(sender); + + Util.getJobsEditorMap().put(player.getUniqueId(), "jobs editjobs add " + job.getName() + " " + actionT.getName() + " "); + return true; + } + + if (args.length == 4) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + String key = args[3]; + switch (args[3]) { + case "hand": + ItemStack item = CMIItemStack.getItemInMainHand(player); + key = CMIMaterial.get(item).getName() + (Version.isCurrentEqualOrHigher(Version.v1_13_R1) ? "" : "-" + item.getData().getData()); + break; + case "offhand": + item = CMIItemStack.getItemInOffHand(player); + key = CMIMaterial.get(item).getName() + (Version.isCurrentEqualOrHigher(Version.v1_13_R1) ? "" : "-" + item.getData().getData()); + break; + case "looking": + case "lookingat": + Block block = Util.getTargetBlock(player, 30); + key = CMIMaterial.get(block).getName() + (Version.isCurrentEqualOrHigher(Version.v1_13_R1) ? "" : "-" + block.getData()); + break; + default: + break; + } + + KeyValues keyValue = Jobs.getConfigManager().getKeyValue(key, actionT, job.getName()); + if (keyValue == null) + return false; + + String type = keyValue.getType(), + subType = keyValue.getSubType(), + meta = keyValue.getMeta(); + int id = keyValue.getId(); + + double income = 0D, + points = 0D, + experience = 0D; + + int fromlevel = 1; + int untilLevel = -1; + + JobInfo jInfo = new JobInfo(actionT, id, meta, type + subType, income, job.getMoneyEquation(), experience, job.getXpEquation(), job.getPointsEquation(), points, fromlevel, + untilLevel, job.getName() + "/" + actionT.getName() + "/" + (type + subType).replace(":", "-")); + + for (JobInfo info : job.getJobInfo(actionT)) { + if (info.getName().equalsIgnoreCase(jInfo.getName())) { + player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName()); + return true; + } + } + + action.add(jInfo); + player.performCommand("jobs editjobs list " + job.getName() + " " + actionT.getName() + " " + jInfo.getName()); + + Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/income", 0); + Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/points", 0); + Jobs.getConfigManager().changeJobsSettings(args[1], jInfo.getConfigPath() + "/experience", 0); + + Util.getJobsEditorMap().remove(player.getUniqueId()); + return true; + } + + break; + default: + break; + } + + return true; } private static void showPath(Player player, Job job, ActionType action, JobInfo jInfo) { - RawMessage rm = new RawMessage(); - rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.job")).addHover("&eJob list") - .addCommand("jobs editjobs").show(player); + RawMessage rm = new RawMessage(); + rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.job")).addHover("&eJob list") + .addCommand("jobs editjobs").show(player); - if (job != null) { - rm = new RawMessage(); - rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.jobs", "%jobname%", job.getDisplayName())) - .addHover(job.getName()).addCommand("jobs editjobs list " + job.getName()); - rm.show(player); - } + if (job != null) { + rm = new RawMessage(); + rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.jobs", "%jobname%", job.getDisplayName())) + .addHover(job.getName()).addCommand("jobs editjobs list " + job.getName()); + rm.show(player); + } - if (action != null && job != null) { - rm = new RawMessage(); + if (action != null && job != null) { + rm = new RawMessage(); - rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.actions", "%actionname%", action.getName())) - .addHover(action.getName()).addCommand("jobs editjobs list " + job.getName() + " " + action.getName() + " 1") - .show(player); - } + rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.actions", "%actionname%", action.getName())) + .addHover(action.getName()).addCommand("jobs editjobs list " + job.getName() + " " + action.getName() + " 1") + .show(player); + } - if (action != null && job != null && jInfo != null) { - rm = new RawMessage(); + if (action != null && job != null && jInfo != null) { + rm = new RawMessage(); - String materialName = jInfo.getName().toLowerCase().replace('_', ' '); - materialName = Character.toUpperCase(materialName.charAt(0)) + materialName.substring(1); - materialName = Jobs.getNameTranslatorManager().translate(materialName, jInfo); - materialName = CMIChatColor.translate(materialName); + String materialName = jInfo.getName().toLowerCase().replace('_', ' '); + materialName = Character.toUpperCase(materialName.charAt(0)) + materialName.substring(1); + materialName = Jobs.getNameTranslatorManager().translate(materialName, jInfo); + materialName = CMIChatColor.translate(materialName); - rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.material", "%materialname%", jInfo.getName())) - .addHover(jInfo.getName()).addCommand("jobs editjobs list " + job.getName() + " " + action.getName() - + " " + materialName).show(player); - } + rm.addText(Jobs.getLanguage().getMessage("command.editjobs.help.list.material", "%materialname%", jInfo.getName())) + .addHover(jInfo.getName()).addCommand("jobs editjobs list " + job.getName() + " " + action.getName() + + " " + materialName).show(player); + } } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java b/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java index 05c3aed8..36ca7a53 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java @@ -5,6 +5,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.PlayerPoints; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -12,56 +13,55 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class editpoints implements Cmd { @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length != 3) { - Jobs.getCommandManager().sendUsage(sender, "editpoints"); - return true; - } + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length != 3) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[1]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[1])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[1]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[1]); + return true; + } - double amount = 0; - try { - amount = Double.parseDouble(args[2]); - } catch (NumberFormatException e) { - CMIMessages.sendMessage(sender, LC.info_UseInteger); - return true; - } + double amount = 0; + try { + amount = Double.parseDouble(args[2]); + } catch (NumberFormatException e) { + CMIMessages.sendMessage(sender, LC.info_UseInteger); + return false; + } - PlayerPoints pointInfo = jPlayer.getPointsData(); - switch (args[0].toLowerCase()) { - case "take": - pointInfo.takePoints(amount); - sender.sendMessage(Jobs.getLanguage().getMessage("command.editpoints.output.take", - "%playername%", jPlayer.getName(), - "%playerdisplayname%", jPlayer.getDisplayName(), - "%amount%", amount, - "%total%", (int) (pointInfo.getCurrentPoints() * 100) / 100D)); - break; - case "add": - pointInfo.addPoints(amount); - sender.sendMessage(Jobs.getLanguage().getMessage("command.editpoints.output.add", - "%playername%", jPlayer.getName(), - "%playerdisplayname%", jPlayer.getDisplayName(), - "%amount%", amount, - "%total%", (int) (pointInfo.getCurrentPoints() * 100) / 100D)); - break; - case "set": - pointInfo.setPoints(amount); - sender.sendMessage(Jobs.getLanguage().getMessage("command.editpoints.output.set", - "%playername%", jPlayer.getName(), - "%playerdisplayname%", jPlayer.getDisplayName(), - "%amount%", amount)); - break; - default: - break; - } + PlayerPoints pointInfo = jPlayer.getPointsData(); + switch (args[0].toLowerCase()) { + case "take": + pointInfo.takePoints(amount); + Language.sendMessage(sender, "command.editpoints.output.take", + "%playername%", jPlayer.getName(), + "%playerdisplayname%", jPlayer.getDisplayName(), + "%amount%", amount, + "%total%", (int) (pointInfo.getCurrentPoints() * 100) / 100D); + break; + case "add": + pointInfo.addPoints(amount); + Language.sendMessage(sender, "command.editpoints.output.add", + "%playername%", jPlayer.getName(), + "%playerdisplayname%", jPlayer.getDisplayName(), + "%amount%", amount, + "%total%", (int) (pointInfo.getCurrentPoints() * 100) / 100D); + break; + case "set": + pointInfo.setPoints(amount); + Language.sendMessage(sender, "command.editpoints.output.set", + "%playername%", jPlayer.getName(), + "%playerdisplayname%", jPlayer.getDisplayName(), + "%amount%", amount); + break; + default: + break; + } - Jobs.getJobsDAO().savePoints(jPlayer); - return true; + Jobs.getJobsDAO().savePoints(jPlayer); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java index e1099090..d98ce1a4 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java @@ -28,7 +28,6 @@ import net.Zrips.CMILib.Container.CMIText; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Locale.LC; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.RawMessages.RawMessageCommand; @@ -50,12 +49,17 @@ public class editquests implements Cmd { static HashMap> tempObjectives = new HashMap>(); @Override - public boolean perform(Jobs plugin, final CommandSender sender, String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, String[] args) { int page = 0; Action action = null; - + + // Only informing here and not canceling command + if (!Jobs.getGCManager().DailyQuestsEnabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + } + for (String one : args) { if (page == 0) { try { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/employ.java b/src/main/java/com/gamingmesh/jobs/commands/list/employ.java index d7e6e575..3095820f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/employ.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/employ.java @@ -7,52 +7,50 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class employ implements Cmd { @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length < 2) { - Jobs.getCommandManager().sendUsage(sender, "employ"); - return true; - } + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length < 2) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - if (jPlayer.isInJob(job)) { - // already in job message - sender.sendMessage(Jobs.getLanguage().getMessage("command.employ.error.alreadyin", "%jobname%", job.getDisplayName())); - return true; - } + if (jPlayer.isInJob(job)) { + // already in job message + Language.sendMessage(sender, "command.employ.error.alreadyin", "%jobname%", job.getDisplayName()); + return true; + } - if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) { - String message = Jobs.getLanguage().getMessage("command.employ.error.fullslots"); - message = message.replace("%jobname%", job.getDisplayName()); - sender.sendMessage(message); - return true; - } + if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) { + Language.sendMessage(sender, "command.employ.error.fullslots", "%jobname%", job.getDisplayName()); + return true; + } - try { - // check if player already has the job - Jobs.getPlayerManager().joinJob(jPlayer, job); - Player player = jPlayer.getPlayer(); - if (player != null) - player.sendMessage(Jobs.getLanguage().getMessage("command.employ.output.target", "%jobname%", job.getDisplayName())); + try { + // check if player already has the job + Jobs.getPlayerManager().joinJob(jPlayer, job); + Player player = jPlayer.getPlayer(); + if (player != null) + Language.sendMessage(player, "command.employ.output.target", "%jobname%", job.getDisplayName()); - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } catch (Throwable e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - } - return true; + Language.sendMessage(sender, "general.admin.success"); + } catch (Throwable e) { + Language.sendMessage(sender, "general.admin.error"); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java b/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java index 7c890ce4..f1ebe907 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java @@ -6,43 +6,41 @@ import org.bukkit.entity.EntityType; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; -import net.Zrips.CMILib.Colors.CMIChatColor; +import net.Zrips.CMILib.Container.CMIText; +import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Messages.CMIMessages; public class entitylist implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "entitylist"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + + StringBuilder msg = new StringBuilder(); + String c1 = "&e"; + String c2 = "&6"; - String msg = "", - c1 = "&e", - c2 = "&6"; + int i = 0; + for (EntityType type : EntityType.values()) { + if (!type.isAlive() || !type.isSpawnable()) + continue; - int i = 0; - for (EntityType type : EntityType.values()) { - if (!type.isAlive() || !type.isSpawnable()) - continue; + i++; - i++; + if (!msg.isEmpty()) + msg.append(LC.info_ListSpliter.getLocale()); - if (!msg.isEmpty()) - msg += ", "; + if (i > 1) { + msg.append(c1); + i = 0; + } else { + msg.append(c2); + } - if (i > 1) { - msg += c1; - i = 0; - } else { - msg += c2; - } + msg.append(CMIText.everyFirstToUpperCase(type.name())); + } - msg += type.name().toLowerCase(); - } - - sender.sendMessage(CMIChatColor.translate(msg)); - return true; + CMIMessages.sendMessage(sender, msg.toString()); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/exp.java b/src/main/java/com/gamingmesh/jobs/commands/list/exp.java index 4a4a1fc6..e6c3cc92 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/exp.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/exp.java @@ -21,11 +21,10 @@ public class exp implements Cmd { Random rand = new Random(); @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { if (args.length < 4) { - Jobs.getCommandManager().sendUsage(sender, "exp"); - return true; + return false; } boolean silent = false; @@ -120,20 +119,20 @@ public class exp implements Cmd { Player player = jPlayer.getPlayer(); if (player == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.give.output.notonline")); + Language.sendMessage(sender, "general.give.output.notonline"); return true; } if (!silent) - player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog - .getExperience())); + Language.sendMessage(player, "command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog + .getExperience()); if (!silentAdmin) - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); + Language.sendMessage(sender, "general.admin.success"); } catch (Exception e) { if (!silentAdmin) - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); + Language.sendMessage(sender, "general.admin.error"); e.printStackTrace(); } return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java deleted file mode 100644 index 59caf9b8..00000000 --- a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.gamingmesh.jobs.commands.list; - -import org.bukkit.command.CommandSender; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.commands.Cmd; -import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.Job; - -import net.Zrips.CMILib.Time.timeModifier; - -public class expboost implements Cmd { - - @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length > 3 || args.length <= 1) { - Jobs.getCommandManager().sendUsage(sender, "expboost"); - return true; - } - - Double rate = null; - Long timeDuration = null; - String jobName = null; - boolean reset = false; - - for (String one : args) { - if (one.equalsIgnoreCase("reset")) { - reset = true; - continue; - } - - if (jobName == null) { - jobName = one; - continue; - } - - if (rate == null) { - try { - rate = Double.parseDouble(one); - continue; - } catch (NumberFormatException e) { - } - } - - try { - Long t = timeModifier.getTimeRangeFromString(one); - if (t != null) - timeDuration = t; - continue; - } catch (Exception e) { - } - } - - if (!reset && rate == null || jobName == null) { - Jobs.getCommandManager().sendUsage(sender, "expboost"); - return false; - } - - if (rate == null) - rate = 1D; - - if (timeDuration == null) - timeDuration = 0L; - - if (!reset && jobName.equalsIgnoreCase("all")) { - for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.EXP, rate, timeDuration); - } - sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate)); - return true; - } - - if (reset) { - if (jobName.equalsIgnoreCase("all")) { - for (Job one : Jobs.getJobs()) { - one.addBoost(CurrencyType.EXP, 1.0); - } - - sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.allreset")); - } else if (args.length > 1) { - Job job = Jobs.getJob(jobName); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - - job.addBoost(CurrencyType.EXP, 1.0); - - sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.jobsboostreset", "%jobname%", job.getName())); - } - - return true; - } - - Job job = Jobs.getJob(jobName); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - - job.addBoost(CurrencyType.EXP, rate, timeDuration); - sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostadded", "%boost%", rate, - "%jobname%", job.getName())); - return true; - } -} diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java index 67cdc125..aaa046aa 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java @@ -10,51 +10,56 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.ExploreChunk; import com.gamingmesh.jobs.container.ExploreRegion; import com.gamingmesh.jobs.container.PlayerInfo; +import com.gamingmesh.jobs.i18n.Language; + +import net.Zrips.CMILib.Locale.LC; public class explored implements Cmd { @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (!(sender instanceof Player)) - return false; + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (!(sender instanceof Player)) { + LC.info_Ingame.sendMessage(sender); + return null; + } - Player player = (Player) sender; - Map exploreRegion = Jobs.getExploreManager().getWorlds().get(player.getWorld().getName()); + Player player = (Player) sender; + Map exploreRegion = Jobs.getExploreManager().getWorlds().get(player.getWorld().getName()); - if (exploreRegion == null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); - return true; - } + if (exploreRegion == null) { + Language.sendMessage(sender, "command.explored.error.noexplore"); + return true; + } - int RegionX = (int) Math.floor(player.getLocation().getChunk().getX() / 32D); - int RegionZ = (int) Math.floor(player.getLocation().getChunk().getZ() / 32D); - ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ); - if (region == null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); - return true; - } + int RegionX = (int) Math.floor(player.getLocation().getChunk().getX() / 32D); + int RegionZ = (int) Math.floor(player.getLocation().getChunk().getZ() / 32D); + ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ); + if (region == null) { + Language.sendMessage(sender, "command.explored.error.noexplore"); + return true; + } - ExploreChunk chunk = region.getChunk(player.getLocation().getChunk()); + ExploreChunk chunk = region.getChunk(player.getLocation().getChunk()); - if (chunk == null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); - return true; - } + if (chunk == null) { + Language.sendMessage(sender, "command.explored.error.noexplore"); + return true; + } - if (Jobs.getGCManager().ExploreCompact && chunk.isFullyExplored()) { - player.sendMessage(Jobs.getLanguage().getMessage("command.explored.fullExplore")); - return true; - } + if (Jobs.getGCManager().ExploreCompact && chunk.isFullyExplored()) { + Language.sendMessage(sender, "command.explored.fullExplore"); + return true; + } - java.util.List players = chunk.getPlayers(); + java.util.List players = chunk.getPlayers(); - for (int i = 0; i < players.size(); i++) { - PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i)); - if (ji != null) - player.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i + 1, "%playername%", ji.getName())); - } - player.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); + for (int i = 0; i < players.size(); i++) { + PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i)); + if (ji != null) + Language.sendMessage(sender, "command.explored.list", "%place%", i + 1, "%playername%", ji.getName()); + } + Language.sendMessage(sender, "general.info.separator"); - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/fire.java b/src/main/java/com/gamingmesh/jobs/commands/list/fire.java index 8abeed29..e211ef81 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/fire.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/fire.java @@ -7,41 +7,41 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class fire implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 2) { - Jobs.getCommandManager().sendUsage(sender, "fire"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 2) { + return false; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - if (!jPlayer.isInJob(job)) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.fire.error.nojob", "%jobname%", job.getDisplayName())); - return true; - } + if (!jPlayer.isInJob(job)) { + Language.sendMessage(sender, "command.fire.error.nojob", "%jobname%", job.getDisplayName()); + return true; + } - if (Jobs.getPlayerManager().leaveJob(jPlayer, job)) { - Player player = jPlayer.getPlayer(); - if (player != null) - player.sendMessage(Jobs.getLanguage().getMessage("command.fire.output.target", "%jobname%", job.getDisplayName())); + if (Jobs.getPlayerManager().leaveJob(jPlayer, job)) { + Player player = jPlayer.getPlayer(); + if (player != null) + Language.sendMessage(player, "command.fire.output.target", "%jobname%", job.getDisplayName()); - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } + Language.sendMessage(sender, "general.admin.success"); + } - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java b/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java index 05c5442e..26935030 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.dao.JobsDAO.DBTables; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -15,50 +16,49 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class fireall implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 1) { - Jobs.getCommandManager().sendUsage(sender, "fireall"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 1) { + return false; + } - if (args[0].equalsIgnoreCase("all")) { - if (sender instanceof Player) { - CMIMessages.sendMessage(sender, LC.info_FromConsole); - return true; - } + if (args[0].equalsIgnoreCase("all")) { + if (sender instanceof Player) { + CMIMessages.sendMessage(sender, LC.info_FromConsole); + return true; + } - Jobs.getDBManager().getDB().truncate(DBTables.JobsTable.getTableName()); + Jobs.getDBManager().getDB().truncate(DBTables.JobsTable.getTableName()); - for (JobsPlayer one : Jobs.getPlayerManager().getPlayersCache().values()) { - for (JobProgression job : one.getJobProgression()) { - Jobs.getJobsDAO().recordToArchive(one, job.getJob()); - } - one.leaveAllJobs(); - // No need to save as we are clearing database with more efficient method - one.setSaved(true); - } + for (JobsPlayer one : Jobs.getPlayerManager().getPlayersCache().values()) { + for (JobProgression job : one.getJobProgression()) { + Jobs.getJobsDAO().recordToArchive(one, job.getJob()); + } + one.leaveAllJobs(); + // No need to save as we are clearing database with more efficient method + one.setSaved(true); + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - return true; - } + Language.sendMessage(sender, "general.admin.success"); + return true; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - if (jPlayer.progression.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.fireall.error.nojobs")); - return true; - } + if (jPlayer.progression.isEmpty()) { + Language.sendMessage(sender, "command.fireall.error.nojobs"); + return true; + } - Jobs.getPlayerManager().leaveAllJobs(jPlayer); - Player player = jPlayer.getPlayer(); - if (player != null) - player.sendMessage(Jobs.getLanguage().getMessage("command.fireall.output.target")); + Jobs.getPlayerManager().leaveAllJobs(jPlayer); + Player player = jPlayer.getPlayer(); + if (player != null) + Language.sendMessage(player, "command.fireall.output.target"); - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - return true; + Language.sendMessage(sender, "general.admin.success"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/give.java b/src/main/java/com/gamingmesh/jobs/commands/list/give.java index 5ef59a05..a631bb71 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/give.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/give.java @@ -11,96 +11,98 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobLimitedItems; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.GiveItem; public class give implements Cmd { private enum actions { - items, limiteditems; - public static actions getByname(String name) { - for (actions one : actions.values()) { - if (one.name().equalsIgnoreCase(name)) - return one; - } - return null; - } + items, limiteditems; + + public static actions getByname(String name) { + for (actions one : actions.values()) { + if (one.name().equalsIgnoreCase(name)) + return one; + } + return null; + } } @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - Player player = null; - Job job = null; - actions name = null; - String itemName = null; + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + Player player = null; + Job job = null; + actions name = null; + String itemName = null; - for (String one : args) { - if (player == null) { - player = Bukkit.getPlayer(one); - if (player != null) - continue; - } + for (String one : args) { + if (player == null) { + player = Bukkit.getPlayer(one); + if (player != null) + continue; + } - if (job == null) { - job = Jobs.getJob(one); - if (job != null) - continue; - } + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } - if (name == null) { - name = actions.getByname(one); - if (name != null) - continue; - } - itemName = one; - } + if (name == null) { + name = actions.getByname(one); + if (name != null) + continue; + } + itemName = one; + } - if (player == null && sender instanceof Player) - player = (Player) sender; + if (player == null && sender instanceof Player) + player = (Player) sender; - if (player == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline")); - return true; - } + if (player == null) { + Language.sendMessage(sender, "command.give.output.notonline"); + return null; + } - if (name == null) - name = actions.items; + if (name == null) + name = actions.items; - if (itemName == null) { - Jobs.getCommandManager().sendUsage(sender, "give"); - return true; - } + if (itemName == null) { + Jobs.getCommandManager().sendUsage(sender, "give"); + return true; + } - switch (name) { - case items: - JobItems jItem = ItemBoostManager.getItemByKey(itemName); - ItemStack item = jItem == null ? null : jItem.getItemStack(player); + switch (name) { + case items: + JobItems jItem = ItemBoostManager.getItemByKey(itemName); + ItemStack item = jItem == null ? null : jItem.getItemStack(player); - if (item == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem")); - return true; - } + if (item == null) { + Language.sendMessage(sender, "command.give.output.noitem"); + return true; + } - GiveItem.giveItemForPlayer(player, item); - break; - case limiteditems: - if (job == null) { - Jobs.getCommandManager().sendUsage(sender, "give"); - return true; - } + GiveItem.giveItemForPlayer(player, item); + break; + case limiteditems: + if (job == null) { + Jobs.getCommandManager().sendUsage(sender, "give"); + return true; + } - JobLimitedItems jLItem = job.getLimitedItems().get(itemName.toLowerCase()); - ItemStack limItem = jLItem == null ? null : jLItem.getItemStack(player); + JobLimitedItems jLItem = job.getLimitedItems().get(itemName.toLowerCase()); + ItemStack limItem = jLItem == null ? null : jLItem.getItemStack(player); - if (limItem == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem")); - return true; - } + if (limItem == null) { + Language.sendMessage(sender, "command.give.output.noitem"); + return true; + } - GiveItem.giveItemForPlayer(player, limItem); - break; - default: - break; - } - return true; + GiveItem.giveItemForPlayer(player, limItem); + break; + default: + break; + } + return true; } } \ No newline at end of file diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/glog.java b/src/main/java/com/gamingmesh/jobs/commands/list/glog.java index 241bc1ad..7ef3ce0f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/glog.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/glog.java @@ -15,107 +15,109 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; import com.gamingmesh.jobs.container.LogAmounts; import com.gamingmesh.jobs.container.PlayerInfo; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.Sorting; -import com.gamingmesh.jobs.stuff.TimeManage; + +import net.Zrips.CMILib.Time.CMITimeManager; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class glog implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "glog"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length != 0) { + return false; + } - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - Map unsortMap = new HashMap<>(); - int time = TimeManage.timeInInt(); + CMIScheduler.get().runTaskAsynchronously(new Runnable() { + @Override + public void run() { + Map unsortMap = new HashMap<>(); + int time = CMITimeManager.timeInInt(); - for (Integer oneP : Jobs.getJobsDAO().getLognameList(time, time)) { - PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(oneP); - if (info == null) - continue; + for (Integer oneP : Jobs.getJobsDAO().getLognameList(time, time)) { + PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(oneP); + if (info == null) + continue; - String name = info.getName(); - if (name == null) - continue; + String name = info.getName(); + if (name == null) + continue; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(info.getUuid()); - if (jPlayer == null) - continue; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(info.getUuid()); + if (jPlayer == null) + continue; - Map logList = jPlayer.getLog(); - if (logList == null || logList.isEmpty()) - continue; + Map logList = jPlayer.getLog(); + if (logList == null || logList.isEmpty()) + continue; - for (Log l : logList.values()) { - for (LogAmounts amounts : l.getAmountList().values()) { - amounts.setUsername(name); - amounts.setAction(l.getActionType()); - unsortMap.put(amounts, amounts.get(CurrencyType.MONEY)); - } - } - } + for (Log l : logList.values()) { + for (LogAmounts amounts : l.getAmountList().values()) { + amounts.setUsername(name); + amounts.setAction(l.getActionType()); + unsortMap.put(amounts, amounts.get(CurrencyType.MONEY)); + } + } + } - unsortMap = Sorting.sortDoubleDESCByLog(unsortMap); - if (unsortMap.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.nodata")); - return; - } + unsortMap = Sorting.sortDoubleDESCByLog(unsortMap); + if (unsortMap.isEmpty()) { + Language.sendMessage(sender, "command.glog.output.nodata"); + return; + } - int count = 1, max = 10; + int count = 1, max = 10; - double totalMoney = 0, - totalExp = 0, - totalPoints = 0; + double totalMoney = 0, + totalExp = 0, + totalPoints = 0; - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.topline")); - for (LogAmounts info : unsortMap.keySet()) { - double money = info.get(CurrencyType.MONEY); - totalMoney += money; + Language.sendMessage(sender, "command.glog.output.topline"); + for (LogAmounts info : unsortMap.keySet()) { + double money = info.get(CurrencyType.MONEY); + totalMoney += money; - String moneyS = ""; - if (money != 0D) - moneyS = Jobs.getLanguage().getMessage("command.glog.output.money", "%amount%", money); + String moneyS = ""; + if (money != 0D) + moneyS = Jobs.getLanguage().getMessage("command.glog.output.money", "%amount%", money); - double exp = info.get(CurrencyType.EXP); - totalExp += exp; + double exp = info.get(CurrencyType.EXP); + totalExp += exp; - String expS = ""; - if (exp != 0D) - expS = Jobs.getLanguage().getMessage("command.glog.output.exp", "%amount%", exp); + String expS = ""; + if (exp != 0D) + expS = Jobs.getLanguage().getMessage("command.glog.output.exp", "%amount%", exp); - double points = info.get(CurrencyType.POINTS); - totalPoints += points; + double points = info.get(CurrencyType.POINTS); + totalPoints += points; - String pointsS = ""; - if (points != 0D) - pointsS = Jobs.getLanguage().getMessage("command.glog.output.points", "%amount%", points); + String pointsS = ""; + if (points != 0D) + pointsS = Jobs.getLanguage().getMessage("command.glog.output.points", "%amount%", points); - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.ls", - "%number%", count, - "%action%", info.getAction(), - "%item%", info.getItemName().replace(":0", "").replace('_', ' ').toLowerCase(), - "%qty%", info.getCount(), - "%money%", moneyS, - "%exp%", expS, - "%points%", pointsS)); + Language.sendMessage(sender, "command.glog.output.ls", + "%number%", count, + "%action%", info.getAction(), + "%item%", info.getItemName().replace(":0", "").replace('_', ' ').toLowerCase(), + "%qty%", info.getCount(), + "%money%", moneyS, + "%exp%", expS, + "%points%", pointsS); - count++; + count++; - if (count > max) - break; - } + if (count > max) + break; + } - NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.totalIncomes", "%money%", format.format(totalMoney), - "%exp%", format.format(totalExp), "%points%", format.format(totalPoints))); + NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); + Language.sendMessage(sender, "command.glog.output.totalIncomes", "%money%", format.format(totalMoney), + "%exp%", format.format(totalExp), "%points%", format.format(totalPoints)); - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.bottomline")); - } - }); - return true; + Language.sendMessage(sender, "command.glog.output.bottomline"); + } + }); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/grantxp.java b/src/main/java/com/gamingmesh/jobs/commands/list/grantxp.java index 709ada3b..9f892088 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/grantxp.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/grantxp.java @@ -8,53 +8,53 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class grantxp implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 3) { - Jobs.getCommandManager().sendUsage(sender, "grantxp"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 3) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - double xpGained; - try { - xpGained = Double.parseDouble(args[2]); - } catch (NumberFormatException e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - return true; - } - if (xpGained <= 0) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - return true; - } + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } + double xpGained; + try { + xpGained = Double.parseDouble(args[2]); + } catch (NumberFormatException e) { + Language.sendMessage(sender, "general.admin.error"); + return true; + } + if (xpGained <= 0) { + Language.sendMessage(sender, "general.admin.error"); + return true; + } - // check if player already has the job - if (jPlayer.isInJob(job)) { - Jobs.getPlayerManager().addExperience(jPlayer, job, xpGained); + // check if player already has the job + if (jPlayer.isInJob(job)) { + Jobs.getPlayerManager().addExperience(jPlayer, job, xpGained); - Player player = jPlayer.getPlayer(); - if (player != null) { - String message = Jobs.getLanguage().getMessage("command.grantxp.output.target", - "%jobname%", job.getDisplayName(), - "%xpgained%", xpGained); - player.sendMessage(message); - } + Player player = jPlayer.getPlayer(); + if (player != null) { + String message = Jobs.getLanguage().getMessage("command.grantxp.output.target", + "%jobname%", job.getDisplayName(), + "%xpgained%", xpGained); + player.sendMessage(message); + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } - return true; + Language.sendMessage(sender, "general.admin.success"); + } + return true; } } 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 b72f81c8..6eaab9cd 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java @@ -10,6 +10,7 @@ import org.bukkit.scoreboard.DisplaySlot; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.TopList; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; @@ -19,80 +20,79 @@ import net.Zrips.CMILib.Scoreboards.CMIScoreboard; public class gtop implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - if (args.length > 1) { - Jobs.getCommandManager().sendUsage(sender, "gtop"); - return true; - } + if (args.length > 1) { + return false; + } - Player player = (Player) sender; - int page = 1; - if (args.length == 1) { - if (args[0].equalsIgnoreCase("clear")) { - player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - CMIScoreboard.removeScoreBoard(player); - return true; - } + Player player = (Player) sender; + int page = 1; + if (args.length == 1) { + if (args[0].equalsIgnoreCase("clear")) { + player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + CMIScoreboard.removeScoreBoard(player); + return true; + } - try { - page = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - return true; - } - } + try { + page = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + return true; + } + } - if (page < 1) - page = 1; + if (page < 1) + page = 1; - int amount = Jobs.getGCManager().JobsTopAmount; - PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page); + int amount = Jobs.getGCManager().JobsTopAmount; + PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page); - List FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart()); - if (FullList.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.error.nojob")); - return true; - } + List FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart()); + if (FullList.isEmpty()) { + Language.sendMessage(sender, "command.gtop.error.nojob"); + return true; + } - if (!Jobs.getGCManager().ShowToplistInScoreboard) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.topline", "%amount%", amount)); + if (!Jobs.getGCManager().ShowToplistInScoreboard) { + Language.sendMessage(sender, "command.gtop.output.topline", "%amount%", amount); - int i = 0; - for (TopList One : FullList) { - if (i >= amount) - break; + int i = 0; + for (TopList One : FullList) { + if (i >= amount) + break; - sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.list", - "%number%", pi.getPositionForOutput(i), - "%playername%", One.getPlayerInfo().getName(), - "%playerdisplayname%", One.getPlayerInfo().getDisplayName(), - "%level%", One.getLevel(), - "%exp%", One.getExp())); - ++i; - } - } else { - List ls = new ArrayList<>(); - int i = 0; - for (TopList one : FullList) { - if (i >= amount) - break; + Language.sendMessage(sender, "command.gtop.output.list", + "%number%", pi.getPositionForOutput(i), + "%playername%", One.getPlayerInfo().getName(), + "%playerdisplayname%", One.getPlayerInfo().getDisplayName(), + "%level%", One.getLevel(), + "%exp%", One.getExp()); + ++i; + } + } else { + List ls = new ArrayList<>(); + int i = 0; + for (TopList one : FullList) { + if (i >= amount) + break; - ls.add(Jobs.getLanguage().getMessage("scoreboard.line", - "%number%", pi.getPositionForOutput(i), - "%playername%", one.getPlayerInfo().getName(), - "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), - "%level%", one.getLevel())); - ++i; - } + ls.add(Jobs.getLanguage().getMessage("scoreboard.line", + "%number%", pi.getPositionForOutput(i), + "%playername%", one.getPlayerInfo().getName(), + "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), + "%level%", one.getLevel())); + ++i; + } - CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.gtopline"), ls, Jobs.getGCManager().ToplistInScoreboardInterval); - } + CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.gtopline"), ls, Jobs.getGCManager().ToplistInScoreboardInterval); + } - plugin.showPagination(sender, pi, "jobs gtop"); - return true; + pi.autoPagination(sender, "jobs gtop"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/info.java b/src/main/java/com/gamingmesh/jobs/commands/list/info.java index 7143fa6d..160b1fe9 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/info.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/info.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -15,62 +16,61 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class info implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - if (args.length < 1) { - Jobs.getCommandManager().sendUsage(sender, "info"); - Jobs.getCommandManager().sendValidActions(sender); - return true; - } + if (args.length < 1) { + Jobs.getCommandManager().sendValidActions(sender); + return false; + } - Player pSender = (Player) sender; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); - if (jPlayer == null) { - pSender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", pSender.getName())); - return true; - } + Player pSender = (Player) sender; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", pSender.getName()); + return true; + } - Job job = Jobs.getJob(args[0]); - if (job == null) { - pSender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[0]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - if (Jobs.getGCManager().hideJobsInfoWithoutPermission && !Jobs.getCommandManager().hasJobPermission(pSender, job)) { - CMIMessages.sendMessage(pSender, LC.info_NoPermission); - return true; - } + if (Jobs.getGCManager().hideJobsInfoWithoutPermission && !Jobs.getCommandManager().hasJobPermission(pSender, job)) { + CMIMessages.sendMessage(pSender, LC.info_NoPermission); + return true; + } - if (Jobs.getGCManager().jobsInfoOpensBrowse) { - plugin.getGUIManager().openJobsBrowseGUI(pSender, job, true); - return true; - } + if (Jobs.getGCManager().jobsInfoOpensBrowse) { + plugin.getGUIManager().openJobsBrowseGUI(pSender, job, true); + return true; + } - int page = 1; - String type = null; + int page = 1; + String type = null; - for (int i = 1; i < args.length; i++) { - String one = args[i]; - if (type == null) { - ActionType t = ActionType.getByName(one); - if (t != null) { - type = t.getName(); - continue; - } - } - try { - page = Integer.parseInt(args[i]); - } catch (NumberFormatException e) { - } - } + for (int i = 1; i < args.length; i++) { + String one = args[i]; + if (type == null) { + ActionType t = ActionType.getByName(one); + if (t != null) { + type = t.getName(); + continue; + } + } + try { + page = Integer.parseInt(args[i]); + } catch (NumberFormatException e) { + } + } - Jobs.getCommandManager().jobInfoMessage(pSender, jPlayer, job, type, page); - return true; + Jobs.getCommandManager().jobInfoMessage(pSender, jPlayer, job, type, page); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java index 6e247260..144de83e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java @@ -27,10 +27,10 @@ import net.Zrips.CMILib.RawMessages.RawMessage; public class itembonus implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { if (!(sender instanceof Player)) { CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; + return null; } Player player = (Player) sender; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java index 3cf23e5e..c2f8f48b 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java @@ -19,15 +19,14 @@ public class iteminfo implements Cmd { @Override @SuppressWarnings("deprecation") - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { if (!(sender instanceof Player)) { CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; + return null; } if (args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "iteminfo"); - return true; + return false; } ItemStack iih = CMIItemStack.getItemInMainHand((Player) sender); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/join.java b/src/main/java/com/gamingmesh/jobs/commands/list/join.java index 048b8a8c..acee655f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/join.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/join.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -16,77 +17,76 @@ import net.Zrips.CMILib.RawMessages.RawMessage; public class join implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - if (args.length != 1 && args.length != 0 && args.length != 2) { - Jobs.getCommandManager().sendUsage(sender, "join"); - return true; - } + if (args.length != 1 && args.length != 0 && args.length != 2) { + return false; + } - if (args.length == 0) { - plugin.getServer().dispatchCommand(sender, "jobs browse"); - return true; - } + if (args.length == 0) { + plugin.getServer().dispatchCommand(sender, "jobs browse"); + return null; + } - Job job = Jobs.getJob(args[0]); - if (job == null) { - // job does not exist - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[0]); + if (job == null) { + // job does not exist + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); + return true; + } - if (!Jobs.getCommandManager().hasJobPermission(sender, job)) { - // The player do not have permission to join the job - CMIMessages.sendMessage(sender, LC.info_NoPermission); - return true; - } + if (!Jobs.getCommandManager().hasJobPermission(sender, job)) { + // The player do not have permission to join the job + CMIMessages.sendMessage(sender, LC.info_NoPermission); + return true; + } - Player pSender = (Player) sender; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); - if (jPlayer == null) { // Load player into cache - Jobs.getPlayerManager().playerJoin(pSender); - jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); - } + Player pSender = (Player) sender; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + if (jPlayer == null) { // Load player into cache + Jobs.getPlayerManager().playerJoin(pSender); + jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + } - if (jPlayer == null) { - return true; - } + if (jPlayer == null) { + return true; + } - if (jPlayer.isInJob(job)) { - // already in job message - pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.alreadyin", "%jobname%", job.getDisplayName())); - return true; - } + if (jPlayer.isInJob(job)) { + // already in job message + Language.sendMessage(sender, "command.join.error.alreadyin", "%jobname%", job.getDisplayName()); + return true; + } - if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) { - pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.fullslots", "%jobname%", job.getDisplayName())); - return true; - } + if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) { + Language.sendMessage(sender, "command.join.error.fullslots", "%jobname%", job.getDisplayName()); + return true; + } - if (!job.isIgnoreMaxJobs() && !Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.progression.size())) { - pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.maxjobs")); - return true; - } + if (!job.isIgnoreMaxJobs() && !Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.progression.size())) { + Language.sendMessage(sender, "command.join.error.maxjobs"); + return true; + } - if (args.length == 2 && args[1].equalsIgnoreCase("-needConfirmation")) { - new RawMessage().addText(Jobs.getLanguage().getMessage("command.join.confirm", "[jobname]", job.getName())) - .addHover(Jobs.getLanguage().getMessage("command.join.confirm", "[jobname]", job.getName())) - .addCommand("jobs join " + job.getName()).show(pSender); - return true; - } + if (args.length == 2 && args[1].equalsIgnoreCase("-needConfirmation")) { + new RawMessage().addText(Jobs.getLanguage().getMessage("command.join.confirm", "[jobname]", job.getName())) + .addHover(Jobs.getLanguage().getMessage("command.join.confirm", "[jobname]", job.getName())) + .addCommand("jobs join " + job.getName()).show(pSender); + return true; + } - JobProgression ajp = jPlayer.getArchivedJobProgression(job); - if (ajp != null && !ajp.canRejoin()) { - pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.rejoin", "[time]", ajp.getRejoinTimeMessage())); - return true; - } + JobProgression ajp = jPlayer.getArchivedJobProgression(job); + if (ajp != null && !ajp.canRejoin()) { + Language.sendMessage(sender, "command.join.error.rejoin", "[time]", ajp.getRejoinTimeMessage()); + return true; + } - Jobs.getPlayerManager().joinJob(jPlayer, job); - pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.success", "%jobname%", job.getDisplayName())); - return true; + Jobs.getPlayerManager().joinJob(jPlayer, job); + Language.sendMessage(sender, "command.join.success", "%jobname%", job.getDisplayName()); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/leave.java b/src/main/java/com/gamingmesh/jobs/commands/list/leave.java index b097c468..8902092f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/leave.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/leave.java @@ -7,59 +7,62 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class leave implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) - return false; + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + LC.info_Ingame.sendMessage(sender); + return null; + } - if (args.length < 1) { - Jobs.getCommandManager().sendUsage(sender, "leave"); - return true; - } + if (args.length < 1) { + return false; + } - Player pSender = (Player) sender; - Job job = Jobs.getJob(args[0]); - if (job == null) { - pSender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Player pSender = (Player) sender; + Job job = Jobs.getJob(args[0]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - if (Jobs.getGCManager().UsePerPermissionForLeaving && !pSender.hasPermission("jobs.command.leave." + args[0].toLowerCase())) { - CMIMessages.sendMessage(pSender, LC.info_NoPermission); - return true; - } + if (Jobs.getGCManager().UsePerPermissionForLeaving && !pSender.hasPermission("jobs.command.leave." + args[0].toLowerCase())) { + CMIMessages.sendMessage(sender, LC.info_NoPermission); + return true; + } - if (Jobs.getGCManager().EnableConfirmation) { - java.util.UUID uuid = pSender.getUniqueId(); + if (Jobs.getGCManager().EnableConfirmation) { + java.util.UUID uuid = pSender.getUniqueId(); - if (!Util.LEAVECONFIRM.contains(uuid)) { - Util.LEAVECONFIRM.add(uuid); + if (!Util.LEAVECONFIRM.contains(uuid)) { + Util.LEAVECONFIRM.add(uuid); - plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.LEAVECONFIRM.remove(uuid), - 20 * Jobs.getGCManager().ConfirmExpiryTime); + CMIScheduler.get().runTaskLater(() -> Util.LEAVECONFIRM.remove(uuid), + 20 * Jobs.getGCManager().ConfirmExpiryTime); - pSender.sendMessage(Jobs.getLanguage().getMessage("command.leave.confirmationNeed", "[jobname]", - job.getDisplayName(), "[time]", Jobs.getGCManager().ConfirmExpiryTime)); - return true; - } + Language.sendMessage(sender, "command.leave.confirmationNeed", "[jobname]", + job.getDisplayName(), "[time]", Jobs.getGCManager().ConfirmExpiryTime); + return true; + } - Util.LEAVECONFIRM.remove(uuid); - } + Util.LEAVECONFIRM.remove(uuid); + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); - if (Jobs.getPlayerManager().leaveJob(jPlayer, job)) - pSender.sendMessage(Jobs.getLanguage().getMessage("command.leave.success", "%jobname%", job.getDisplayName(), "[jobname]", job.getDisplayName())); - else - pSender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); + if (Jobs.getPlayerManager().leaveJob(jPlayer, job)) + Language.sendMessage(sender, "command.leave.success", "%jobname%", job.getDisplayName(), "[jobname]", job.getDisplayName()); + else + Language.sendMessage(sender, "general.error.job"); - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/leaveall.java b/src/main/java/com/gamingmesh/jobs/commands/list/leaveall.java index 7b3c9e7f..79ed8e4b 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/leaveall.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/leaveall.java @@ -9,48 +9,50 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class leaveall implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - Player pSender = (Player) sender; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + Player pSender = (Player) sender; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); - List jobs = jPlayer.getJobProgression(); - if (jobs.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.error.nojobs")); - return true; - } + List jobs = jPlayer.getJobProgression(); + if (jobs.isEmpty()) { + Language.sendMessage(sender, "command.leaveall.error.nojobs"); + return true; + } - if (Jobs.getGCManager().EnableConfirmation) { - java.util.UUID uuid = pSender.getUniqueId(); + if (Jobs.getGCManager().EnableConfirmation) { + java.util.UUID uuid = pSender.getUniqueId(); - if (!Util.LEAVECONFIRM.contains(uuid)) { - Util.LEAVECONFIRM.add(uuid); + if (!Util.LEAVECONFIRM.contains(uuid)) { + Util.LEAVECONFIRM.add(uuid); - plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.LEAVECONFIRM.remove(uuid), - 20 * Jobs.getGCManager().ConfirmExpiryTime); + CMIScheduler.get().runTaskLater(() -> Util.LEAVECONFIRM.remove(uuid), + 20 * Jobs.getGCManager().ConfirmExpiryTime); - pSender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.confirmationNeed", "[time]", - Jobs.getGCManager().ConfirmExpiryTime)); - return true; - } + Language.sendMessage(pSender, "command.leaveall.confirmationNeed", "[time]", + Jobs.getGCManager().ConfirmExpiryTime); + return true; + } - Util.LEAVECONFIRM.remove(uuid); - } + Util.LEAVECONFIRM.remove(uuid); + } - Jobs.getPlayerManager().leaveAllJobs(jPlayer); - sender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.success")); - return true; + Jobs.getPlayerManager().leaveAllJobs(jPlayer); + Language.sendMessage(sender, "command.leaveall.success"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/level.java b/src/main/java/com/gamingmesh/jobs/commands/list/level.java index e9b2d4da..f5186f9d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/level.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/level.java @@ -9,118 +9,118 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class level implements Cmd { private enum Action { - Set, Add, Take + Set, Add, Take } @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length < 4) { - Jobs.getCommandManager().sendUsage(sender, "level"); - return true; - } + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length < 4) { + return false; + } - Action action = Action.Add; - int amount = 0; - String playerName = null; - Job job = null; + Action action = Action.Add; + int amount = 0; + String playerName = null; + Job job = null; - for (String one : args) { - switch (one.toLowerCase()) { - case "set": - action = Action.Set; - continue; - case "add": - action = Action.Add; - continue; - case "take": - action = Action.Take; - continue; - default: - break; - } + for (String one : args) { + switch (one.toLowerCase()) { + case "set": + action = Action.Set; + continue; + case "add": + action = Action.Add; + continue; + case "take": + action = Action.Take; + continue; + default: + break; + } - try { - amount = Integer.parseInt(one); - continue; - } catch (NumberFormatException e) { - } + try { + amount = Integer.parseInt(one); + continue; + } catch (NumberFormatException e) { + } - if (job == null && (job = Jobs.getJob(one)) != null) - continue; + if (job == null && (job = Jobs.getJob(one)) != null) + continue; - playerName = one; - } + playerName = one; + } - if (playerName == null) - return false; + if (playerName == null) + return false; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(playerName); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(playerName); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - try { - // check if player already has the job - if (jPlayer.isInJob(job)) { - JobProgression prog = jPlayer.getJobProgression(job); - int total = 0; + try { + // check if player already has the job + if (jPlayer.isInJob(job)) { + JobProgression prog = jPlayer.getJobProgression(job); + int total = 0; - switch (action) { - case Set: - prog.setLevel(amount); - break; - case Add: - int oldLevel = prog.getLevel(); - total = (oldLevel + amount); + switch (action) { + case Set: + prog.setLevel(amount); + break; + case Add: + int oldLevel = prog.getLevel(); + total = (oldLevel + amount); - if (prog.setLevel(total)) { - JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job, prog.getLevel(), - Jobs.getTitleManager().getTitle(oldLevel, prog.getJob().getName()), - Jobs.getTitleManager().getTitle(prog.getLevel(), prog.getJob().getName()), - Jobs.getGCManager().SoundLevelupSound, - Jobs.getGCManager().SoundLevelupVolume, - Jobs.getGCManager().SoundLevelupPitch, - Jobs.getGCManager().SoundTitleChangeSound, - Jobs.getGCManager().SoundTitleChangeVolume, - Jobs.getGCManager().SoundTitleChangePitch); + if (prog.setLevel(total)) { + JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job, prog.getLevel(), + Jobs.getTitleManager().getTitle(oldLevel, prog.getJob().getName()), + Jobs.getTitleManager().getTitle(prog.getLevel(), prog.getJob().getName()), + Jobs.getGCManager().SoundLevelupSound, + Jobs.getGCManager().SoundLevelupVolume, + Jobs.getGCManager().SoundLevelupPitch, + Jobs.getGCManager().SoundTitleChangeSound, + Jobs.getGCManager().SoundTitleChangeVolume, + Jobs.getGCManager().SoundTitleChangePitch); - plugin.getServer().getPluginManager().callEvent(levelUpEvent); + plugin.getServer().getPluginManager().callEvent(levelUpEvent); - // If event is cancelled, don't do anything - if (levelUpEvent.isCancelled()) - return true; - } + // If event is cancelled, don't do anything + if (levelUpEvent.isCancelled()) + return true; + } - break; - case Take: - total = (prog.getLevel() - amount); - prog.setLevel(total); - break; - default: - break; - } + break; + case Take: + total = (prog.getLevel() - amount); + prog.setLevel(total); + break; + default: + break; + } - Player player = jPlayer.getPlayer(); - if (player != null) - player.sendMessage(Jobs.getLanguage().getMessage("command.level.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevel(), - "%exp%", String.format(Jobs.getGCManager().getDecimalPlacesExp(), prog.getExperience()))); + Player player = jPlayer.getPlayer(); + if (player != null) + Language.sendMessage(player, "command.level.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevel(), + "%exp%", String.format(Jobs.getGCManager().getDecimalPlacesExp(), prog.getExperience())); - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } else - sender.sendMessage(Jobs.getLanguage().getMessage("command.level.error.nojob")); - } catch (Exception e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - } - return true; + Language.sendMessage(sender, "general.admin.success"); + } else + Language.sendMessage(sender, "command.level.error.nojob"); + } catch (Exception e) { + Language.sendMessage(sender, "general.admin.error"); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java index 8bacf748..72d30567 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java @@ -8,64 +8,66 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.economy.PaymentData; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Time.CMITimeManager; public class limit implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0 && args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "limit"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length != 0 && args.length != 1) { + return false; + } - JobsPlayer JPlayer = null; - if (args.length >= 1) - JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - else if (sender instanceof Player) - JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + JobsPlayer JPlayer = null; + if (args.length >= 1) + JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + else if (sender instanceof Player) + JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - boolean disabled = true; - for (CurrencyType type : CurrencyType.values()) { - if (Jobs.getGCManager().getLimit(type).isEnabled()) { - disabled = false; - break; - } - } + boolean disabled = true; + for (CurrencyType type : CurrencyType.values()) { + if (Jobs.getGCManager().getLimit(type).isEnabled()) { + disabled = false; + break; + } + } - if (disabled) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.notenabled")); - return true; - } + if (disabled) { + Language.sendMessage(sender,"command.limit.output.notenabled"); + return true; + } - if (JPlayer == null) { - if (args.length >= 1) - CMIMessages.sendMessage(sender, LC.info_NoInformation); - else if (!(sender instanceof Player)) - Jobs.getCommandManager().sendUsage(sender, "limit"); - return true; - } + if (JPlayer == null) { + if (args.length >= 1) + CMIMessages.sendMessage(sender, LC.info_NoInformation); + else if (!(sender instanceof Player)) + Jobs.getCommandManager().sendUsage(sender, "limit"); + return true; + } - for (CurrencyType type : CurrencyType.values()) { - if (!Jobs.getGCManager().getLimit(type).isEnabled()) - continue; - PaymentData limit = JPlayer.getPaymentLimit(); + for (CurrencyType type : CurrencyType.values()) { + if (!Jobs.getGCManager().getLimit(type).isEnabled()) + continue; + PaymentData limit = JPlayer.getPaymentLimit(); - if (limit.getLeftTime(type) <= 0) - limit.resetLimits(type); + if (limit.getLeftTime(type) <= 0) { + limit.resetLimits(type); + } - if (limit.getLeftTime(type) > 0) { - String typeName = type.getName().toLowerCase(); + if (limit.getLeftTime(type) > 0) { + String typeName = type.getName().toLowerCase(); - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + typeName + "time", "%time%", CMITimeManager.to24hourShort(limit.getLeftTime(type)))); - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + typeName + "Limit", - "%current%", (int) (limit.getAmount(type) * 100) / 100D, - "%total%", JPlayer.getLimit(type))); - } - } - return true; + Language.sendMessage(sender, "command.limit.output." + typeName + "time", "%time%", CMITimeManager.to24hourShort(limit.getLeftTime(type))); + Language.sendMessage(sender, "command.limit.output." + typeName + "Limit", + "%current%", (int) (limit.getAmount(type) * 100) / 100D, + "%total%", JPlayer.getLimit(type)); + } + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/log.java b/src/main/java/com/gamingmesh/jobs/commands/list/log.java index 33728b09..3a83b75e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/log.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/log.java @@ -15,122 +15,122 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; import com.gamingmesh.jobs.container.LogAmounts; -import com.gamingmesh.jobs.stuff.Sorting; +import com.gamingmesh.jobs.i18n.Language; +import net.Zrips.CMILib.Container.CMISort; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; public class log implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player) && args.length != 1) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player) && args.length != 1) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - if (args.length != 1 && args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "log"); - return true; - } + if (args.length != 1 && args.length != 0) { + return false; + } - JobsPlayer JPlayer = null; - if (args.length == 0) - JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - else if (args.length == 1) { - if (!Jobs.hasPermission(sender, "jobs.command.log.others", true)) - return true; + JobsPlayer JPlayer = null; + if (args.length == 0) + JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + else if (args.length == 1) { + if (!Jobs.hasPermission(sender, "jobs.command.log.others", true)) + return null; - JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - } + JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + } - if (JPlayer == null) { - Jobs.getCommandManager().sendUsage(sender, "log"); - return true; - } + if (JPlayer == null) { + Jobs.getCommandManager().sendUsage(sender, "log"); + return true; + } - Map logList = JPlayer.getLog(); - if (logList == null || logList.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.bottomline")); - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.nodata")); - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.bottomline")); - return true; - } + Map logList = JPlayer.getLog(); + if (logList == null || logList.isEmpty()) { + Language.sendMessage(sender, "command.log.output.bottomline"); + Language.sendMessage(sender, "command.log.output.nodata"); + Language.sendMessage(sender, "command.log.output.bottomline"); + return true; + } - Map unsortMap = new HashMap<>(); + Map unsortMap = new HashMap<>(); - for (Log l : logList.values()) { - for (Entry oneMap : l.getAmountList().entrySet()) { - unsortMap.put(oneMap.getKey(), oneMap.getValue().get(CurrencyType.MONEY)); - } - } + for (Log l : logList.values()) { + for (Entry oneMap : l.getAmountList().entrySet()) { + unsortMap.put(oneMap.getKey(), oneMap.getValue().get(CurrencyType.MONEY)); + } + } - unsortMap = Sorting.sortDoubleDESC(unsortMap); - if (unsortMap.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.nodata")); - return true; - } + unsortMap = CMISort.sortDoubleDESC(unsortMap); + if (unsortMap.isEmpty()) { + Language.sendMessage(sender, "command.log.output.nodata"); + return true; + } - int count = 0; - int max = 10; + int count = 0; + int max = 10; - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.topline", "%playername%", JPlayer.getName(), "%playerdisplayname%", JPlayer.getDisplayName())); - for (Log one : logList.values()) { - double totalMoney = 0, totalExp = 0, totalPoints = 0; + Language.sendMessage(sender, "command.log.output.topline", "%playername%", JPlayer.getName(), "%playerdisplayname%", JPlayer.getDisplayName()); + for (Log one : logList.values()) { + double totalMoney = 0, totalExp = 0, totalPoints = 0; - for (String oneSorted : unsortMap.keySet()) { - for (Entry oneMap : one.getAmountList().entrySet()) { - if (oneMap.getKey().equalsIgnoreCase(oneSorted)) { - count++; + for (String oneSorted : unsortMap.keySet()) { + for (Entry oneMap : one.getAmountList().entrySet()) { + if (oneMap.getKey().equalsIgnoreCase(oneSorted)) { + count++; - LogAmounts amounts = oneMap.getValue(); + LogAmounts amounts = oneMap.getValue(); - double money = amounts.get(CurrencyType.MONEY); - totalMoney = totalMoney + money; + double money = amounts.get(CurrencyType.MONEY); + totalMoney = totalMoney + money; - String moneyS = ""; - if (money != 0D) - moneyS = Jobs.getLanguage().getMessage("command.log.output.money", "%amount%", money); + String moneyS = ""; + if (money != 0D) + moneyS = Jobs.getLanguage().getMessage("command.log.output.money", "%amount%", money); - double exp = amounts.get(CurrencyType.EXP); - totalExp = totalExp + exp; + double exp = amounts.get(CurrencyType.EXP); + totalExp = totalExp + exp; - String expS = ""; - if (exp != 0D) - expS = Jobs.getLanguage().getMessage("command.log.output.exp", "%amount%", exp); + String expS = ""; + if (exp != 0D) + expS = Jobs.getLanguage().getMessage("command.log.output.exp", "%amount%", exp); - double points = amounts.get(CurrencyType.POINTS); - totalPoints = totalPoints + points; + double points = amounts.get(CurrencyType.POINTS); + totalPoints = totalPoints + points; - String pointsS = ""; - if (points != 0D) - pointsS = Jobs.getLanguage().getMessage("command.log.output.points", "%amount%", points); + String pointsS = ""; + if (points != 0D) + pointsS = Jobs.getLanguage().getMessage("command.log.output.points", "%amount%", points); - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.ls", - "%number%", count, - "%action%", one.getActionType(), - "%item%", amounts.getItemName().replace(":0", "").replace('_', ' ').toLowerCase(), - "%qty%", amounts.getCount(), - "%money%", moneyS, - "%exp%", expS, - "%points%", pointsS)); - break; - } - } + Language.sendMessage(sender, "command.log.output.ls", + "%number%", count, + "%action%", one.getActionType(), + "%item%", amounts.getItemName().replace(":0", "").replace('_', ' ').toLowerCase(), + "%qty%", amounts.getCount(), + "%money%", moneyS, + "%exp%", expS, + "%points%", pointsS); + break; + } + } - if (count > max) - break; - } + if (count > max) + break; + } - NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.totalIncomes", "%money%", format.format(totalMoney), - "%exp%", format.format(totalExp), "%points%", format.format(totalPoints))); + NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); + Language.sendMessage(sender, "command.log.output.totalIncomes", "%money%", format.format(totalMoney), + "%exp%", format.format(totalExp), "%points%", format.format(totalPoints)); - if (count > max) - break; - } + if (count > max) + break; + } - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.bottomline")); - return true; + Language.sendMessage(sender, "command.log.output.bottomline"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java deleted file mode 100644 index 42f01588..00000000 --- a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.gamingmesh.jobs.commands.list; - -import org.bukkit.command.CommandSender; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.commands.Cmd; -import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.Job; - -import net.Zrips.CMILib.Time.timeModifier; - -public class moneyboost implements Cmd { - - @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length > 3 || args.length <= 1) { - Jobs.getCommandManager().sendUsage(sender, "moneyboost"); - return true; - } - - Double rate = null; - Long timeDuration = null; - String jobName = null; - boolean reset = false; - - for (String one : args) { - if (one.equalsIgnoreCase("reset")) { - reset = true; - continue; - } - - if (jobName == null) { - jobName = one; - continue; - } - - if (rate == null) { - try { - rate = Double.parseDouble(one); - continue; - } catch (NumberFormatException e) { - } - } - - try { - Long t = timeModifier.getTimeRangeFromString(one); - if (t != null) - timeDuration = t; - continue; - } catch (Exception e) { - } - } - - if (!reset && rate == null || jobName == null) { - Jobs.getCommandManager().sendUsage(sender, "moneyboost"); - return false; - } - - if (rate == null) - rate = 1D; - - if (timeDuration == null) - timeDuration = 0L; - - if (!reset && jobName.equalsIgnoreCase("all")) { - for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.MONEY, rate, timeDuration); - } - sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate)); - return true; - } - - if (reset) { - if (jobName.equalsIgnoreCase("all")) { - for (Job one : Jobs.getJobs()) { - one.addBoost(CurrencyType.MONEY, 1.0); - } - - sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.allreset")); - } else if (args.length > 1) { - Job job = Jobs.getJob(jobName); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - - job.addBoost(CurrencyType.MONEY, 1.0); - - sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.jobsboostreset", "%jobname%", job.getName())); - } - - return true; - } - - Job job = Jobs.getJob(jobName); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - - job.addBoost(CurrencyType.MONEY, rate, timeDuration); - sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded", "%boost%", rate, - "%jobname%", job.getName())); - return true; - } -} diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/ownedblocks.java b/src/main/java/com/gamingmesh/jobs/commands/list/ownedblocks.java index 31624d61..0e900423 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/ownedblocks.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/ownedblocks.java @@ -26,66 +26,66 @@ import net.Zrips.CMILib.RawMessages.RawMessage; public class ownedblocks implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - JobsPlayer jPlayer = null; - if (args.length >= 1) { - if (!Jobs.hasPermission(sender, "jobs.command.admin.ownedblocks", true)) - return true; - jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - } else if (sender instanceof Player) - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + JobsPlayer jPlayer = null; + if (args.length >= 1) { + if (!Jobs.hasPermission(sender, "jobs.command.admin.ownedblocks", true)) + return null; + jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + } else if (sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (jPlayer == null) { - if (args.length >= 1) - CMIMessages.sendMessage(sender, LC.info_NoInformation); - else - Jobs.getCommandManager().sendUsage(sender, "ownedblocks"); - return true; - } + if (jPlayer == null) { + if (args.length >= 1) + CMIMessages.sendMessage(sender, LC.info_NoInformation); + else + return false; + return null; + } - final JobsPlayer jp = jPlayer; + final JobsPlayer jp = jPlayer; - RawMessage rm = new RawMessage(); + RawMessage rm = new RawMessage(); - Snd snd = new Snd(); - snd.setSender(sender); - snd.setTargetName(jp.getName()); + Snd snd = new Snd(); + snd.setSender(sender); + snd.setTargetName(jp.getName()); - rm.addText(LC.info_PlayerSpliter.getLocale(snd)); + rm.addText(LC.info_PlayerSpliter.getLocale(snd)); - int i = 0; - for (BlockTypes type : BlockTypes.values()) { + int i = 0; + for (BlockTypes type : BlockTypes.values()) { - Optional ownerShip = plugin.getBlockOwnerShip(type); + Optional ownerShip = plugin.getBlockOwnerShip(type); - if (!ownerShip.isPresent()) - continue; + if (!ownerShip.isPresent()) + continue; - HashMap records = ownerShip.get().getBlockOwnerShips().get(jp.getUniqueId()); - if (records == null) - continue; + HashMap records = ownerShip.get().getBlockOwnerShips().get(jp.getUniqueId()); + if (records == null) + continue; - for (Entry record : records.entrySet()) { - i++; - rm.addText("\n"); + for (Entry record : records.entrySet()) { + i++; + rm.addText("\n"); - CMIMaterial material = CMIMaterial.get(type.toString()); + CMIMaterial material = CMIMaterial.get(type.toString()); - CMILocation loc = CMILocation.fromString(record.getKey(), ":"); + CMILocation loc = CMILocation.fromString(record.getKey(), ":"); - rm.addText(Jobs.getLanguage().getMessage("command.ownedblocks.output.list", "[place]", i, "[type]", material.getName(), "[location]", LC.Location_Full.getLocale((Location) loc))); - rm.addHover(Jobs.getLanguage().getMessage("command.ownedblocks.output.listHover", "[location]", LC.Location_Full.getLocale((Location) loc))); - rm.addCommand(JobsCommands.LABEL + " " + clearownership.class.getSimpleName() + " " + jp.getName() + " " + record.getKey()); - if (record.getValue().isDisabled()) { - rm.addText(Jobs.getLanguage().getMessage("command.ownedblocks.output.disabled")); - rm.addHover(Jobs.getLanguage().getMessage("command.ownedblocks.output.disabledHover")); - } - } - } - rm.show(sender); - if (i == 0) - LC.info_nothingToShow.sendMessage(sender); + rm.addText(Jobs.getLanguage().getMessage("command.ownedblocks.output.list", "[place]", i, "[type]", material.getName(), "[location]", LC.Location_Full.getLocale((Location) loc))); + rm.addHover(Jobs.getLanguage().getMessage("command.ownedblocks.output.listHover", "[location]", LC.Location_Full.getLocale((Location) loc))); + rm.addCommand(JobsCommands.LABEL + " " + clearownership.class.getSimpleName() + " " + jp.getName() + " " + record.getKey()); + if (record.getValue().isDisabled()) { + rm.addText(Jobs.getLanguage().getMessage("command.ownedblocks.output.disabled")); + rm.addHover(Jobs.getLanguage().getMessage("command.ownedblocks.output.disabledHover")); + } + } + } + rm.show(sender); + if (i == 0) + LC.info_nothingToShow.sendMessage(sender); - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java b/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java index 7b7e41ec..9bd47e1c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java @@ -8,86 +8,77 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Placeholders.Placeholder.JobsPlaceHolders; import com.gamingmesh.jobs.Placeholders.Placeholder.JobsPlaceholderType; import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Container.PageInfo; +import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; public class placeholders implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - boolean isPlayer = sender instanceof Player; - Player player = isPlayer ? (Player) sender : null; + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + boolean isPlayer = sender instanceof Player; + Player player = isPlayer ? (Player) sender : null; - int page = 1; - if (args.length > 0) { - if (isPlayer) { - if (args[0].startsWith("-p:")) { - try { - page = Integer.parseInt(args[0].substring("-p:".length())); - } catch (NumberFormatException e) { - } - } - } else { - player = Bukkit.getPlayer(args[0]); - if (player == null) { - Jobs.consoleMsg("&cPlayer cannot be null!"); - return false; - } - } - } + int page = 1; + if (args.length > 0) { + if (isPlayer) { + if (args[0].startsWith("-p:")) { + try { + page = Integer.parseInt(args[0].substring("-p:".length())); + } catch (NumberFormatException e) { + } + } + } else { + player = Bukkit.getPlayer(args[0]); + if (player == null) { + CMIMessages.consoleMessage("&cPlayer cannot be null!"); + return false; + } + } + } - if (args.length >= 2 && args[0].equalsIgnoreCase("parse")) { - String placeholder = args[1]; - JobsPlaceholderType type = plugin.getPlaceholderAPIManager().getPlaceHolderType(player, placeholder); + if (args.length >= 2 && args[0].equalsIgnoreCase("parse")) { + String placeholder = args[1]; + JobsPlaceholderType type = plugin.getPlaceholderAPIManager().getPlaceHolderType(player, placeholder); - sender.sendMessage(Jobs.getLanguage().getMessage("command.placeholders.output.parse", - "[placeholder]", placeholder, - "[source]", type == null ? "Unknown" : type.name(), - "[result]", plugin.getPlaceholderAPIManager().updatePlaceHolders(player, placeholder))); + Language.sendMessage(sender, "command.placeholders.output.parse", + "[placeholder]", placeholder, + "[source]", type == null ? "Unknown" : type.name(), + "[result]", plugin.getPlaceholderAPIManager().updatePlaceHolders(player, placeholder)); - return true; - } + return true; + } - JobsPlaceHolders[] values = JobsPlaceHolders.values(); - PageInfo pi = new PageInfo(isPlayer ? Jobs.getGCManager().PlaceholdersPage : values.length, values.length, page); + JobsPlaceHolders[] values = JobsPlaceHolders.values(); + PageInfo pi = new PageInfo(isPlayer ? Jobs.getGCManager().PlaceholdersPage : values.length, values.length, page); - for (JobsPlaceHolders one : values) { - if (pi.isBreak()) - break; + for (JobsPlaceHolders one : values) { + if (pi.isBreak()) + break; - if (!pi.isEntryOk()) - continue; + if (!pi.isEntryOk()) + continue; - RawMessage rm = new RawMessage(); - String extra = ""; + RawMessage rm = new RawMessage(); + String extra = ""; - if (player != null && !one.isComplex()) - extra = plugin.getPlaceholderAPIManager().updatePlaceHolders(player, Jobs.getLanguage().getMessage("command.placeholders.output.outputResult", - "[result]", plugin.getPlaceholderAPIManager().updatePlaceHolders(player, one.getFull()))); + if (player != null && !one.isComplex()) + extra = plugin.getPlaceholderAPIManager().updatePlaceHolders(player, Jobs.getLanguage().getMessage("command.placeholders.output.outputResult", + "[result]", plugin.getPlaceholderAPIManager().updatePlaceHolders(player, one.getFull()))); - String place = one.getFull(); - String hover = ""; - if (plugin.isPlaceholderAPIEnabled()) { - hover = place = one.getFull(); - } -// For MVdWPlaceholderAPI -// if (plugin.isMVdWPlaceholderAPIEnabled()) { -// if (!plugin.isPlaceholderAPIEnabled()) { -// place = one.getFull().substring(1, one.getFull().length() - 2); -// place = "{" + place + "}"; -// } -// if (hover.isEmpty()) -// hover = one.getFull(); -// else -// hover += "\n" + "{" + one.getFull().substring(1, one.getFull().length() - 2) + "}"; -// } - rm.addText(Jobs.getLanguage().getMessage("command.placeholders.output.list", "[place]", pi.getPositionForOutput(), "[placeholder]", place) + extra) - .addHover(hover).addSuggestion(one.getFull()).show(sender); - } + String place = one.getFull(); + String hover = ""; + if (plugin.isPlaceholderAPIEnabled()) { + hover = place = one.getFull(); + } + rm.addText(Jobs.getLanguage().getMessage("command.placeholders.output.list", "[place]", pi.getPositionForOutput(), "[placeholder]", place) + extra) + .addHover(hover).addSuggestion(one.getFull()).show(sender); + } - if (player != null) - plugin.showPagination(sender, pi, "jobs placeholders", "-p:"); - return true; + if (player != null) + pi.autoPagination(sender, "jobs placeholders", "-p:"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java index 3aed487b..9b8203d3 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java @@ -6,40 +6,40 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class playerinfo implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 2) { - Jobs.getCommandManager().sendUsage(sender, "playerinfo"); - Jobs.getCommandManager().sendValidActions(sender); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 2) { + Jobs.getCommandManager().sendValidActions(sender); + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - int page = 1; - String type = ""; - if (args.length >= 3) { - try { - page = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - type = args[2]; - } - } + int page = 1; + String type = ""; + if (args.length >= 3) { + try { + page = Integer.parseInt(args[2]); + } catch (NumberFormatException e) { + type = args[2]; + } + } - Jobs.getCommandManager().jobInfoMessage(sender, jPlayer, job, type, page); - return true; + Jobs.getCommandManager().jobInfoMessage(sender, jPlayer, job, type, page); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java deleted file mode 100644 index 0b9c99ea..00000000 --- a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.gamingmesh.jobs.commands.list; - -import org.bukkit.command.CommandSender; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.commands.Cmd; -import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.Job; - -import net.Zrips.CMILib.Time.timeModifier; - -public class pointboost implements Cmd { - - @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length > 3 || args.length <= 1) { - Jobs.getCommandManager().sendUsage(sender, "pointboost"); - return true; - } - - Double rate = null; - Long timeDuration = null; - String jobName = null; - boolean reset = false; - - for (String one : args) { - if (one.equalsIgnoreCase("reset")) { - reset = true; - continue; - } - - if (jobName == null) { - jobName = one; - continue; - } - - if (rate == null) { - try { - rate = Double.parseDouble(one); - continue; - } catch (NumberFormatException e) { - } - } - - try { - Long t = timeModifier.getTimeRangeFromString(one); - if (t != null) - timeDuration = t; - continue; - } catch (Exception e) { - } - } - - if (!reset && rate == null || jobName == null) { - Jobs.getCommandManager().sendUsage(sender, "moneyboost"); - return false; - } - - if (rate == null) - rate = 1D; - - if (timeDuration == null) - timeDuration = 0L; - - if (!reset && jobName.equalsIgnoreCase("all")) { - for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.POINTS, rate, timeDuration); - } - sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate)); - return true; - } - - if (reset) { - if (jobName.equalsIgnoreCase("all")) { - for (Job one : Jobs.getJobs()) { - one.addBoost(CurrencyType.POINTS, 1.0); - } - - sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.allreset")); - } else if (args.length > 1) { - Job job = Jobs.getJob(jobName); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - - job.addBoost(CurrencyType.POINTS, 1.0); - - sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.jobsboostreset", "%jobname%", job.getName())); - } - - return true; - } - - Job job = Jobs.getJob(jobName); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - - job.addBoost(CurrencyType.POINTS, rate, timeDuration); - sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.boostadded", "%boost%", rate, - "%jobname%", job.getName())); - return true; - } -} diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/points.java b/src/main/java/com/gamingmesh/jobs/commands/list/points.java index 6800b743..c53a53f2 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/points.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/points.java @@ -7,6 +7,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.PlayerPoints; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -14,37 +15,36 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class points implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0 && args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "points"); - return true; - } + if (args.length != 0 && args.length != 1) { + return false; + } - JobsPlayer jPlayer = null; - if (args.length >= 1) { - if (!Jobs.hasPermission(sender, "jobs.command.admin.points", true)) { - return true; - } - jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - } else if (sender instanceof Player) { - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - } + JobsPlayer jPlayer = null; + if (args.length >= 1) { + if (!Jobs.hasPermission(sender, "jobs.command.admin.points", true)) { + return true; + } + jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + } else if (sender instanceof Player) { + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + } - if (jPlayer == null) { - if (args.length >= 1) - CMIMessages.sendMessage(sender, LC.info_NoInformation); - else - Jobs.getCommandManager().sendUsage(sender, "points"); - return true; - } + if (jPlayer == null) { + if (args.length >= 1) + CMIMessages.sendMessage(sender, LC.info_NoInformation); + else + Jobs.getCommandManager().sendUsage(sender, "points"); + return true; + } - PlayerPoints pointInfo = jPlayer.getPointsData(); + PlayerPoints pointInfo = jPlayer.getPointsData(); - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName())); - sender.sendMessage(Jobs.getLanguage().getMessage("command.points.currentpoints", "%currentpoints%", (int) (pointInfo.getCurrentPoints() * 100) / 100D)); - sender.sendMessage(Jobs.getLanguage().getMessage("command.points.totalpoints", "%totalpoints%", (int) (pointInfo.getTotalPoints() * 100) / 100D)); - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); - return true; + Language.sendMessage(sender, "general.info.toplineseparator", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName()); + Language.sendMessage(sender, "command.points.currentpoints", "%currentpoints%", (int) (pointInfo.getCurrentPoints() * 100) / 100D); + Language.sendMessage(sender, "command.points.totalpoints", "%totalpoints%", (int) (pointInfo.getTotalPoints() * 100) / 100D); + Language.sendMessage(sender, "general.info.separator"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/promote.java b/src/main/java/com/gamingmesh/jobs/commands/list/promote.java index d588202b..0d534f53 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/promote.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/promote.java @@ -7,62 +7,62 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class promote implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 3) { - Jobs.getCommandManager().sendUsage(sender, "promote"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 3) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - // check if player already has the job - if (!jPlayer.isInJob(job)) - return false; + // check if player already has the job + if (!jPlayer.isInJob(job)) + return false; - try { + try { - int levelsGained = -1; - try { - levelsGained = Integer.parseInt(args[2]); - } catch (NumberFormatException ex) { - return false; - } + int levelsGained = -1; + try { + levelsGained = Integer.parseInt(args[2]); + } catch (NumberFormatException ex) { + return false; + } - boolean commands = false; - for (String one : args) { - if (one.equalsIgnoreCase("-cmd")) { - commands = true; - continue; - } - } + boolean commands = false; + for (String one : args) { + if (one.equalsIgnoreCase("-cmd")) { + commands = true; + continue; + } + } - Jobs.getPlayerManager().promoteJob(jPlayer, job, levelsGained, commands); + Jobs.getPlayerManager().promoteJob(jPlayer, job, levelsGained, commands); - Player player = jPlayer.getPlayer(); - if (player != null) - player.sendMessage(Jobs.getLanguage().getMessage("command.promote.output.target", - "%jobname%", job.getDisplayName(), - "%levelsgained%", levelsGained)); + Player player = jPlayer.getPlayer(); + if (player != null) + Language.sendMessage(player, "command.promote.output.target", + "%jobname%", job.getDisplayName(), + "%levelsgained%", levelsGained); - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); + Language.sendMessage(sender, "general.admin.success"); - } catch (Throwable e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - } - return true; + } catch (Throwable e) { + Language.sendMessage(sender, "general.admin.error"); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 56920dbc..871e882a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -14,7 +14,7 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Quest; import com.gamingmesh.jobs.container.QuestObjective; import com.gamingmesh.jobs.container.QuestProgression; -import com.gamingmesh.jobs.stuff.TimeManage; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -24,128 +24,134 @@ import net.Zrips.CMILib.Time.CMITimeManager; public class quests implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, String[] args) { - JobsPlayer jPlayer = null; - boolean isPlayer = sender instanceof Player; + public Boolean perform(Jobs plugin, final CommandSender sender, String[] args) { - if (args.length >= 1 && !args[0].equalsIgnoreCase("stop") && !args[0].equalsIgnoreCase("start")) { - if (!Jobs.hasPermission(sender, "jobs.command.admin.quests", true)) - return true; + if (!Jobs.getGCManager().DailyQuestsEnabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + return null; + } - jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - } else if (isPlayer) - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + JobsPlayer jPlayer = null; + boolean isPlayer = sender instanceof Player; - if (jPlayer == null) { - if (args.length >= 1) - CMIMessages.sendMessage(sender, LC.info_NoInformation); - else - Jobs.getCommandManager().sendUsage(sender, "quests"); - return true; - } + if (args.length >= 1 && !args[0].equalsIgnoreCase("stop") && !args[0].equalsIgnoreCase("start")) { + if (!Jobs.hasPermission(sender, "jobs.command.admin.quests", true)) + return null; - List questProgs = jPlayer.getQuestProgressions(); + jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + } else if (isPlayer) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (questProgs.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.error.noquests")); - return true; - } + if (jPlayer == null) { + if (args.length >= 1) + CMIMessages.sendMessage(sender, LC.info_NoInformation); + else + Jobs.getCommandManager().sendUsage(sender, "quests"); + return true; + } - if (args.length >= 1) { - Boolean stopped = null; - String cmd = args[args.length == 1 ? 0 : 1]; + List questProgs = jPlayer.getQuestProgressions(); - if (cmd.equalsIgnoreCase("stop") && Jobs.hasPermission(sender, "jobs.command.admin.quests.stop", false)) { - stopped = true; - } else if (cmd.equalsIgnoreCase("start") && Jobs.hasPermission(sender, "jobs.command.admin.quests.start", false)) { - stopped = false; - } + if (questProgs.isEmpty()) { + Language.sendMessage(sender, "command.quests.error.noquests"); + return true; + } - if (stopped != null) { - for (QuestProgression q : questProgs) { - q.getQuest().setStopped(stopped); - } + if (args.length >= 1) { + Boolean stopped = null; + String cmd = args[args.length == 1 ? 0 : 1]; - sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.status.changed", "%status%", - stopped ? Jobs.getLanguage().getMessage("command.quests.status.stopped") : Jobs.getLanguage().getMessage("command.quests.status.started"))); - return true; - } - } + if (cmd.equalsIgnoreCase("stop") && Jobs.hasPermission(sender, "jobs.command.admin.quests.stop", false)) { + stopped = true; + } else if (cmd.equalsIgnoreCase("start") && Jobs.hasPermission(sender, "jobs.command.admin.quests.start", false)) { + stopped = false; + } - sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests())); + if (stopped != null) { + for (QuestProgression q : questProgs) { + q.getQuest().setStopped(stopped); + } - for (JobProgression jobProg : jPlayer.progression) { - List list = jPlayer.getQuestProgressions(jobProg.getJob()); + Language.sendMessage(sender, "command.quests.status.changed", "%status%", + stopped ? Jobs.getLanguage().getMessage("command.quests.status.stopped") : Jobs.getLanguage().getMessage("command.quests.status.started")); + return true; + } + } - for (QuestProgression q : list) { - int totalAmountNeeded = q.getTotalAmountNeeded(); - int totalAmountDone = q.getTotalAmountDone(); + Language.sendMessage(sender, "command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests()); - String progressLine = Jobs.getCommandManager().jobProgressMessage(totalAmountNeeded, totalAmountDone); + for (JobProgression jobProg : jPlayer.progression) { + List list = jPlayer.getQuestProgressions(jobProg.getJob()); - boolean completed = q.isCompleted(); + for (QuestProgression q : list) { + int totalAmountNeeded = q.getTotalAmountNeeded(); + int totalAmountDone = q.getTotalAmountDone(); - if (completed) - progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed"); + String progressLine = Jobs.getCommandManager().jobProgressMessage(totalAmountNeeded, totalAmountDone); - Quest quest = q.getQuest(); + boolean completed = q.isCompleted(); - String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]", - progressLine, "[questName]", quest.getQuestName(), "[done]", totalAmountDone, "[required]", totalAmountNeeded); + if (completed) + progressLine = Jobs.getLanguage().getMessage("command.quests.output.completed"); - if (!isPlayer) { - sender.sendMessage(msg); - continue; - } + Quest quest = q.getQuest(); - RawMessage rm = new RawMessage(); + String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]", + progressLine, "[questName]", quest.getQuestName(), "[done]", totalAmountDone, "[required]", totalAmountNeeded); - String hoverMsg = Jobs.getLanguage().getMessage("command.quests.output.hover"); - List hoverList = new ArrayList<>(); + if (!isPlayer) { + sender.sendMessage(msg); + continue; + } - for (String current : hoverMsg.split("\n")) { - current = current.replace("[jobName]", jobProg.getJob().getName()) - .replace("[time]", CMITimeManager.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); + RawMessage rm = new RawMessage(); - if (current.contains("[desc]")) { - hoverList.addAll(quest.getDescription()); - } else { - hoverList.add(current); - } - } + String hoverMsg = Jobs.getLanguage().getMessage("command.quests.output.hover"); + List hoverList = new ArrayList<>(); - for (java.util.Map oneAction : quest.getObjectives().values()) { - for (Entry oneObjective : oneAction.entrySet()) { - hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " + - Jobs.getNameTranslatorManager().translate(oneObjective.getKey(), oneObjective.getValue().getAction(), oneObjective.getValue().getTargetId(), oneObjective.getValue() - .getTargetMeta(), oneObjective.getValue().getTargetName()) - + " " + q.getAmountDone(oneObjective.getValue()) + "/" - + oneObjective.getValue().getAmount()); - } - } + for (String current : hoverMsg.split("\n")) { + current = current.replace("[jobName]", jobProg.getJob().getName()) + .replace("[time]", CMITimeManager.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); - String hover = ""; - for (String one : hoverList) { - if (!hover.isEmpty()) - hover += "\n"; + if (current.contains("[desc]")) { + hoverList.addAll(quest.getDescription()); + } else { + hoverList.add(current); + } + } - hover += one; - } + for (java.util.Map oneAction : quest.getObjectives().values()) { + for (Entry oneObjective : oneAction.entrySet()) { + hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " + + Jobs.getNameTranslatorManager().translate(oneObjective.getKey(), oneObjective.getValue().getAction(), oneObjective.getValue().getTargetId(), oneObjective.getValue() + .getTargetMeta(), oneObjective.getValue().getTargetName()) + + " " + q.getAmountDone(oneObjective.getValue()) + "/" + + oneObjective.getValue().getAmount()); + } + } - if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests() && !completed) { - if (Jobs.getGCManager().getDailyQuestsSkips() > 0) { - hover += "\n" + Jobs.getLanguage().getMessage("command.quests.output.skip"); - hover += "\n" + Jobs.getLanguage().getMessage("command.quests.output.skips", "[skips]", (Jobs.getGCManager().getDailyQuestsSkips() - jPlayer.getSkippedQuests())); - } - rm.addText(msg).addHover(hover).addCommand("jobs skipquest " + jobProg.getJob().getName() + " " + quest.getConfigName() + " " + jPlayer.getName()); - } else - rm.addText(msg).addHover(hover); + String hover = ""; + for (String one : hoverList) { + if (!hover.isEmpty()) + hover += "\n"; - rm.show(sender); - } - } + hover += one; + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); - return true; + if (list.size() < jobProg.getJob().getQuests().size() && Jobs.getGCManager().getDailyQuestsSkips() > jPlayer.getSkippedQuests() && !completed) { + if (Jobs.getGCManager().getDailyQuestsSkips() > 0) { + hover += "\n" + Jobs.getLanguage().getMessage("command.quests.output.skip"); + hover += "\n" + Jobs.getLanguage().getMessage("command.quests.output.skips", "[skips]", (Jobs.getGCManager().getDailyQuestsSkips() - jPlayer.getSkippedQuests())); + } + rm.addText(msg).addHover(hover).addCommand("jobs skipquest " + jobProg.getJob().getName() + " " + quest.getConfigName() + " " + jPlayer.getName()); + } else + rm.addText(msg).addHover(hover); + + rm.show(sender); + } + } + + sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/reload.java b/src/main/java/com/gamingmesh/jobs/commands/list/reload.java index bc20c934..e0a5b3ba 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/reload.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/reload.java @@ -4,13 +4,14 @@ import org.bukkit.command.CommandSender; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.i18n.Language; public class reload implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - Jobs.reload(); - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - return true; + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + Jobs.reload(); + Language.sendMessage(sender, "general.admin.success"); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/removexp.java b/src/main/java/com/gamingmesh/jobs/commands/list/removexp.java index 6aaeb528..01f4cd9f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/removexp.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/removexp.java @@ -7,52 +7,52 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class removexp implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 3) { - Jobs.getCommandManager().sendUsage(sender, "removexp"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 3) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job job = Jobs.getJob(args[1]); - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } - double xpLost = 0D; - try { - xpLost = Double.parseDouble(args[2]); - } catch (NumberFormatException e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - return true; - } - if (xpLost <= 0 || xpLost > Double.MAX_VALUE) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - return true; - } - // check if player already has the job - if (jPlayer.isInJob(job)) { - Jobs.getPlayerManager().removeExperience(jPlayer, job, xpLost); + Job job = Jobs.getJob(args[1]); + if (job == null) { + Language.sendMessage(sender, "general.error.job"); + return null; + } + double xpLost = 0D; + try { + xpLost = Double.parseDouble(args[2]); + } catch (NumberFormatException e) { + Language.sendMessage(sender, "general.admin.error"); + return true; + } + if (xpLost <= 0 || xpLost > Double.MAX_VALUE) { + Language.sendMessage(sender, "general.admin.error"); + return true; + } + // check if player already has the job + if (jPlayer.isInJob(job)) { + Jobs.getPlayerManager().removeExperience(jPlayer, job, xpLost); - Player player = jPlayer.getPlayer(); - if (player != null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.removexp.output.target", - "%jobname%", job.getDisplayName(), - "%xplost%", xpLost)); - } + Player player = jPlayer.getPlayer(); + if (player != null) { + Language.sendMessage(player, "command.removexp.output.target", + "%jobname%", job.getDisplayName(), + "%xplost%", xpLost); + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } - return true; + Language.sendMessage(sender, "general.admin.success"); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java index 4eed1a05..1d08d370 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java @@ -4,6 +4,7 @@ import org.bukkit.command.CommandSender; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.i18n.Language; public class resetexploreregion implements Cmd { @@ -11,25 +12,24 @@ public class resetexploreregion implements Cmd { private static String REGEX = "^[0-9a-zA-Z_-]+$"; @Override - public boolean perform(Jobs plugin, CommandSender sender, String[] args) { - if (args.length != 2 || !WORLD.equals(args[0])) { - Jobs.getCommandManager().sendUsage(sender, "resetexploreregion"); - return true; - } + public Boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length != 2 || !WORLD.equals(args[0])) { + return false; + } - if (!Jobs.getGCManager().resetExploringData) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.notenabled")); - return true; - } + if (!Jobs.getGCManager().resetExploringData) { + Language.sendMessage(sender, "command.resetexploreregion.output.notenabled"); + return true; + } - final String worldName = args[1]; - if (!worldName.matches(REGEX)) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.invalidname")); - return true; - } + final String worldName = args[1]; + if (!worldName.matches(REGEX)) { + Language.sendMessage(sender, "command.resetexploreregion.output.invalidname"); + return true; + } - Jobs.getExploreManager().resetRegion(worldName); - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName)); - return true; + Jobs.getExploreManager().resetRegion(worldName); + Language.sendMessage(sender, "command.resetexploreregion.output.reseted", "%worldname%", worldName); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java index 6bf6d018..4ac77a30 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java @@ -4,36 +4,36 @@ import org.bukkit.command.CommandSender; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class resetlimit implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "resetlimit"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length != 1) { + return false; + } - if (args[0].equalsIgnoreCase("all")) { - for (org.bukkit.entity.Player pl : org.bukkit.Bukkit.getOnlinePlayers()) { - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pl); - if (jPlayer != null) { - jPlayer.resetPaymentLimit(); - } - } + if (args[0].equalsIgnoreCase("all")) { + for (org.bukkit.entity.Player pl : org.bukkit.Bukkit.getOnlinePlayers()) { + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pl); + if (jPlayer != null) { + jPlayer.resetPaymentLimit(); + } + } - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetlimit.output.reseted", "%playername%", "")); - return true; - } + Language.sendMessage(sender, "command.resetlimit.output.reseted", "%playername%", ""); + return true; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - jPlayer.resetPaymentLimit(); - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetlimit.output.reseted", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName())); - return true; + jPlayer.resetPaymentLimit(); + Language.sendMessage(sender, "command.resetlimit.output.reseted", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName()); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java index 75c1e0b0..2bbe8da3 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetquest.java @@ -10,48 +10,56 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.QuestProgression; +import com.gamingmesh.jobs.i18n.Language; + +import net.Zrips.CMILib.Locale.LC; public class resetquest implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0 && args.length != 1 && args.length != 2) { - Jobs.getCommandManager().sendUsage(sender, "resetquest"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - JobsPlayer jPlayer = null; - Job job = null; + if (!Jobs.getGCManager().DailyQuestsEnabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + return true; + } - for (String one : args) { - if (job == null) { - job = Jobs.getJob(one); - if (job != null) - continue; - } - jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); - } + if (args.length != 0 && args.length != 1 && args.length != 2) { + return false; + } - if (jPlayer == null && sender instanceof Player) - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + JobsPlayer jPlayer = null; + Job job = null; - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : "")); - return true; - } + for (String one : args) { + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } + jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); + } - List quests = jPlayer.getQuestProgressions(); + if (jPlayer == null && sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (job != null) - quests = jPlayer.getQuestProgressions(job); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : ""); + return true; + } - if (quests.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.noQuests")); - return true; - } + List quests = jPlayer.getQuestProgressions(); - jPlayer.resetQuests(quests); - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.reseted", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getName())); - return true; + if (job != null) + quests = jPlayer.getQuestProgressions(job); + + if (quests.isEmpty()) { + Language.sendMessage(sender, "command.resetquest.output.noQuests"); + return true; + } + + jPlayer.resetQuests(quests); + Language.sendMessage(sender, "command.resetquest.output.reseted", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getName()); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java index daaf28e4..e3b5df6e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java @@ -10,49 +10,56 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; + +import net.Zrips.CMILib.Locale.LC; public class resetquesttotal implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0 && args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "resetquesttotal"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!Jobs.getGCManager().DailyQuestsEnabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + return true; + } + + if (args.length != 0 && args.length != 1) { + return false; + } - if (args.length > 0 && args[0].equalsIgnoreCase("all")) { - for (Entry pl : Jobs.getPlayerManager().getPlayersCache().entrySet()) { - pl.getValue().setDoneQuests(0); - } - Jobs.getJobsDAO().resetDoneQuests(); - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquesttotal.output.reseted", "%playername%", Jobs.getPlayerManager().getPlayersCache().size())); - return true; - } + if (args.length > 0 && args[0].equalsIgnoreCase("all")) { + for (Entry pl : Jobs.getPlayerManager().getPlayersCache().entrySet()) { + pl.getValue().setDoneQuests(0); + } + Jobs.getJobsDAO().resetDoneQuests(); + Language.sendMessage(sender,"command.resetquesttotal.output.reseted", "%playername%", Jobs.getPlayerManager().getPlayersCache().size()); + return true; + } - JobsPlayer jPlayer = null; - Job job = null; + JobsPlayer jPlayer = null; + Job job = null; - for (String one : args) { - if (job == null) { - job = Jobs.getJob(one); - if (job != null) - continue; - } - jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); - } + for (String one : args) { + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } + jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); + } - if (jPlayer == null && sender instanceof Player) - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + if (jPlayer == null && sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : "")); - return true; - } + if (jPlayer == null) { + Language.sendMessage(sender,"general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : ""); + return true; + } - jPlayer.setDoneQuests(0); - jPlayer.setSaved(false); - jPlayer.save(); - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquesttotal.output.reseted", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName())); - return true; + jPlayer.setDoneQuests(0); + jPlayer.setSaved(false); + jPlayer.save(); + Language.sendMessage(sender,"command.resetquesttotal.output.reseted", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName()); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/schedule.java b/src/main/java/com/gamingmesh/jobs/commands/list/schedule.java index 10d5daf8..fe05fa7a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/schedule.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/schedule.java @@ -9,14 +9,15 @@ import org.bukkit.configuration.file.FileConfiguration; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.i18n.Language; public class schedule implements Cmd { @Override - public boolean perform(final Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(final Jobs plugin, final CommandSender sender, final String[] args) { if (args.length < 2) { Jobs.getCommandManager().sendUsage(sender, "schedule"); - return true; + return null; } if (args[0].equalsIgnoreCase("enable")) { @@ -32,12 +33,12 @@ public class schedule implements Cmd { ConfigurationSection path = c.getConfigurationSection("Boost." + name); if (path == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.schedule.output.noScheduleFound")); - return false; + Language.sendMessage(sender,"command.schedule.output.noScheduleFound"); + return null; } if (path.getBoolean("Enabled")) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.schedule.output.alreadyEnabled")); + Language.sendMessage(sender,"command.schedule.output.alreadyEnabled"); return true; } @@ -63,7 +64,7 @@ public class schedule implements Cmd { Jobs.getScheduleManager().load(); Jobs.getScheduleManager().start(); - sender.sendMessage(Jobs.getLanguage().getMessage("command.schedule.output.enabled", "%until%", until, "%from%", from)); + Language.sendMessage(sender,"command.schedule.output.enabled", "%until%", until, "%from%", from); } return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/shop.java b/src/main/java/com/gamingmesh/jobs/commands/list/shop.java index 2b4ceb9b..ed2b7b33 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/shop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/shop.java @@ -2,35 +2,39 @@ package com.gamingmesh.jobs.commands.list; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; + import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import net.Zrips.CMILib.Locale.LC; -import net.Zrips.CMILib.Messages.CMIMessages; public class shop implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return true; - } + if (!Jobs.getGCManager().jobsshopenabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + return null; + } - if (args.length != 0 && args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "shop"); - return true; - } + if (!(sender instanceof Player)) { + LC.info_Ingame.sendMessage(sender); + return null; + } - int page = 1; - if (args.length == 1) - try { - page = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - } + if (args.length != 0 && args.length != 1) { + return false; + } - Jobs.getShopManager().openShopGui((Player) sender, page); - return true; + int page = 1; + if (args.length == 1) + try { + page = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + } + + Jobs.getShopManager().openShopGui((Player) sender, page); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java b/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java index cc345a24..f7d94731 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java @@ -6,40 +6,43 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Signs.SignTopType; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.i18n.Language; + +import net.Zrips.CMILib.Locale.LC; public class signupdate implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!Jobs.getGCManager().SignsEnabled) - return true; + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!Jobs.getGCManager().SignsEnabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + return null; + } - if (args.length != 1) { - Jobs.getCommandManager().sendUsage(sender, "signupdate"); - return true; - } + if (args.length != 1) { + return false; + } - if (args[0].equalsIgnoreCase("all")) { - Jobs.getJobs().forEach(Jobs.getSignUtil()::signUpdate); - return true; - } + if (args[0].equalsIgnoreCase("all")) { + Jobs.getJobs().forEach(Jobs.getSignUtil()::signUpdate); + return true; + } - Job oldjob = Jobs.getJob(args[0]); - if (oldjob == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job oldjob = Jobs.getJob(args[0]); + if (oldjob == null) { + Language.sendMessage(sender, "general.error.job"); + return null; + } - if (args.length == 2) { - SignTopType type = SignTopType.getType(args[1]); - if (type != null) { - Jobs.getSignUtil().signUpdate(oldjob, type); - } + if (args.length == 2) { + SignTopType type = SignTopType.getType(args[1]); + if (type != null) { + Jobs.getSignUtil().signUpdate(oldjob, type); + } + return true; + } - return true; - } - - Jobs.getSignUtil().signUpdate(oldjob); - return true; + Jobs.getSignUtil().signUpdate(oldjob); + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java index 05ac85b0..e2c856ff 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java @@ -2,6 +2,7 @@ package com.gamingmesh.jobs.commands.list; import java.util.List; +import com.gamingmesh.jobs.stuff.Util; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,103 +13,128 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Quest; import com.gamingmesh.jobs.container.QuestProgression; import com.gamingmesh.jobs.economy.BufferedEconomy; +import com.gamingmesh.jobs.i18n.Language; + +import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class skipquest implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 2 && args.length != 3) { - Jobs.getCommandManager().sendUsage(sender, "skipquest"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!Jobs.getGCManager().DailyQuestsEnabled) { + LC.info_FeatureNotEnabled.sendMessage(sender); + return null; + } + // Needs to allow longer so multiword quest names work + if (args.length < 2) { + return false; + } - JobsPlayer jPlayer = null; - Job job = null; - String questName = ""; + JobsPlayer jPlayer = null; + Job job = null; + String questName = ""; - for (String one : args) { - if (job == null) { - job = Jobs.getJob(one); - if (job != null) - continue; - } - if (jPlayer == null) { - jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); - if (jPlayer != null) - continue; - } + for (String one : args) { + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } + if (jPlayer == null) { + jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); + if (jPlayer != null) + continue; + } - if (!questName.isEmpty()) - questName += " "; - questName += one; - } + if (!questName.isEmpty()) + questName += " "; + questName += one; + } - if (jPlayer == null && sender instanceof Player) - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + if (jPlayer == null && sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : "")); - return true; - } + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : ""); + return null; + } - List quests = jPlayer.getQuestProgressions(); + List quests = jPlayer.getQuestProgressions(); - if (job != null) - quests = jPlayer.getQuestProgressions(job); + if (job != null) + quests = jPlayer.getQuestProgressions(job); - if (quests == null || quests.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquest.output.noQuests")); - return true; - } + if (quests == null || quests.isEmpty()) { + Language.sendMessage(sender, "command.resetquest.output.noQuests"); + return null; + } - Quest old = null; + Quest old = null; - for (QuestProgression one : quests) { - Quest q = one.getQuest(); + for (QuestProgression one : quests) { + Quest q = one.getQuest(); - if (q.getQuestName().equalsIgnoreCase(questName) || q.getConfigName().equalsIgnoreCase(questName)) { - old = q; - break; - } - } + if (q.getQuestName().equalsIgnoreCase(questName) || q.getConfigName().equalsIgnoreCase(questName)) { + old = q; + break; + } + } - if (old == null) { - return false; - } + if (old == null) { + return false; + } - // Do not skip the completed quests - for (QuestProgression q : quests) { - if (q.getQuest().getQuestName().equals(old.getQuestName()) && q.isCompleted()) { - return false; - } - } + // Do not skip the completed quests + for (QuestProgression q : quests) { + if (q.getQuest().getQuestName().equals(old.getQuestName()) && q.isCompleted()) { + return false; + } + } - if (Jobs.getGCManager().getDailyQuestsSkips() <= jPlayer.getSkippedQuests()) { - return false; - } + if (Jobs.getGCManager().getDailyQuestsSkips() <= jPlayer.getSkippedQuests()) { + return false; + } - double amount = Jobs.getGCManager().skipQuestCost; - BufferedEconomy econ = Jobs.getEconomy(); - Player player = jPlayer.getPlayer(); + double amount = Jobs.getGCManager().skipQuestCost; + BufferedEconomy econ = Jobs.getEconomy(); + Player player = jPlayer.getPlayer(); - if (amount > 0 && player != null) { - if (!econ.getEconomy().hasMoney(player, amount)) { - sender.sendMessage(Jobs.getLanguage().getMessage("economy.error.nomoney")); - return false; - } + if (amount > 0 && player != null) { + if (!econ.getEconomy().hasMoney(player, amount)) { + Language.sendMessage(sender, "economy.error.nomoney"); + return null; + } - econ.getEconomy().withdrawPlayer(player, amount); - } + econ.getEconomy().withdrawPlayer(player, amount); + } + // Add confirmation if configured + if (Jobs.getGCManager().EnableConfirmation) { + java.util.UUID uuid = jPlayer.getUniqueId(); - jPlayer.replaceQuest(old); + if (!Util.SKIPCONFIRM.contains(uuid)) { + Util.SKIPCONFIRM.add(uuid); - if (player != null) - plugin.getServer().dispatchCommand(player, "jobs quests"); + CMIScheduler.get().runTaskLater(() -> Util.SKIPCONFIRM.remove(uuid), + 20 * Jobs.getGCManager().ConfirmExpiryTime); - if (amount > 0) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.skipquest.output.questSkipForCost", "%amount%", amount)); - } + Language.sendMessage(sender, "command.skipquest.confirmationNeed", "[questName]", + old.getQuestName(), "[time]", Jobs.getGCManager().ConfirmExpiryTime); + return true; + } - return true; + Util.SKIPCONFIRM.remove(uuid); + } + + jPlayer.replaceQuest(old); + + if (player != null) + plugin.getServer().dispatchCommand(player, "jobs quests"); + + if (amount > 0) { + Language.sendMessage(sender, "command.skipquest.output.questSkipForCost", "%amount%", amount); + } + + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java index 3ac24194..16d6e018 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobsCommands; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -16,42 +17,42 @@ import net.Zrips.CMILib.RawMessages.RawMessage; public class stats implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - JobsPlayer jPlayer = null; - if (args.length >= 1) { - if (!Jobs.hasPermission(sender, "jobs.command.admin.stats", true)) - return true; - jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - } else if (sender instanceof Player) - jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + JobsPlayer jPlayer = null; + if (args.length >= 1) { + if (!Jobs.hasPermission(sender, "jobs.command.admin.stats", true)) + return true; + jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + } else if (sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (jPlayer == null) { - if (args.length >= 1) - CMIMessages.sendMessage(sender, LC.info_NoInformation); - else - Jobs.getCommandManager().sendUsage(sender, "stats"); - return true; - } + if (jPlayer == null) { + if (args.length >= 1) + CMIMessages.sendMessage(sender, LC.info_NoInformation); + else + Jobs.getCommandManager().sendUsage(sender, "stats"); + return true; + } - if (jPlayer.progression.isEmpty()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.stats.error.nojob")); - return true; - } + if (jPlayer.progression.isEmpty()) { + Language.sendMessage(sender, "command.stats.error.nojob"); + return true; + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName())); + Language.sendMessage(sender, "general.info.toplineseparator", "%playername%", jPlayer.getName(), "%playerdisplayname%", jPlayer.getDisplayName()); - String leftClick = Jobs.getLanguage().getMessage("command.info.gui.leftClick"); + String leftClick = Jobs.getLanguage().getMessage("command.info.gui.leftClick"); - String pref = JobsCommands.LABEL + " " + info.class.getSimpleName() + " "; + String pref = JobsCommands.LABEL + " " + info.class.getSimpleName() + " "; - for (JobProgression jobProg : jPlayer.getJobProgression()) { - for (String msg : Jobs.getCommandManager().jobStatsMessage(jobProg).split("\n")) { - new RawMessage().addText(msg).addHover(leftClick).addCommand(pref + jobProg.getJob().getName()).show(sender); - } - } + for (JobProgression jobProg : jPlayer.getJobProgression()) { + for (String msg : Jobs.getCommandManager().jobStatsMessage(jobProg, sender instanceof Player).split("\n")) { + new RawMessage().addText(msg).addHover(leftClick).addCommand(pref + jobProg.getJob().getName()).show(sender); + } + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); - return true; + Language.sendMessage(sender, "general.info.separator"); + return true; } } 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 3aa83c9e..5fc0647e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.ToggleBarHandling; import net.Zrips.CMILib.Locale.LC; @@ -15,49 +16,48 @@ import net.Zrips.CMILib.Messages.CMIMessages; public class toggle implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { + CMIMessages.sendMessage(sender, LC.info_Ingame); + return null; + } - boolean isBossbar = false, isActionbar = false; - if (args.length != 1 || (!(isBossbar = args[0].equalsIgnoreCase("bossbar")) && !(isActionbar = args[0].equalsIgnoreCase("actionbar")))) { - Jobs.getCommandManager().sendUsage(sender, "toggle"); - return true; - } + boolean isBossbar = false, isActionbar = false; + if (args.length != 1 || (!(isBossbar = args[0].equalsIgnoreCase("bossbar")) && !(isActionbar = args[0].equalsIgnoreCase("actionbar")))) { + return false; + } - Player player = (Player) sender; - String playerUUID = player.getUniqueId().toString(); + Player player = (Player) sender; + String playerUUID = player.getUniqueId().toString(); - if (isActionbar) { - Boolean ex = ToggleBarHandling.getActionBarToggle().get(playerUUID); + if (isActionbar) { + Boolean ex = ToggleBarHandling.getActionBarToggle().get(playerUUID); - if (ex == null || ex.booleanValue()) { - ToggleBarHandling.getActionBarToggle().put(playerUUID, false); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); - } else { - ToggleBarHandling.getActionBarToggle().put(playerUUID, true); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); - } - } + if (ex == null || ex.booleanValue()) { + ToggleBarHandling.getActionBarToggle().put(playerUUID, false); + Language.sendMessage(sender, "command.toggle.output.off"); + } else { + ToggleBarHandling.getActionBarToggle().put(playerUUID, true); + Language.sendMessage(sender, "command.toggle.output.on"); + } + } - if (isBossbar) { - Boolean ex = ToggleBarHandling.getBossBarToggle().get(playerUUID); + if (isBossbar) { + Boolean ex = ToggleBarHandling.getBossBarToggle().get(playerUUID); - if (ex == null || ex.booleanValue()) { - ToggleBarHandling.getBossBarToggle().put(playerUUID, false); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); + if (ex == null || ex.booleanValue()) { + ToggleBarHandling.getBossBarToggle().put(playerUUID, false); + Language.sendMessage(sender, "command.toggle.output.off"); - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId()); - if (jPlayer != null) - jPlayer.hideBossBars(); - } else { - ToggleBarHandling.getBossBarToggle().put(playerUUID, true); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); - } - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId()); + if (jPlayer != null) + jPlayer.hideBossBars(); + } else { + ToggleBarHandling.getBossBarToggle().put(playerUUID, true); + Language.sendMessage(sender, "command.toggle.output.on"); + } + } - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/top.java b/src/main/java/com/gamingmesh/jobs/commands/list/top.java index 85c49159..09dc77b5 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/top.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/top.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; +import com.gamingmesh.jobs.i18n.Language; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; @@ -20,84 +21,81 @@ import net.Zrips.CMILib.Scoreboards.CMIScoreboard; public class top implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (!(sender instanceof Player)) { - CMIMessages.sendMessage(sender, LC.info_Ingame); - return false; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 1 && args.length != 2) { - Jobs.getCommandManager().sendUsage(sender, "top"); - return false; - } + if (args.length != 1 && args.length != 2) { + return false; + } - Player player = (Player) sender; - if (args[0].equalsIgnoreCase("clear")) { - player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - CMIScoreboard.removeScoreBoard(player); - return true; - } + Player player = sender instanceof Player ? (Player) sender : null; - int page = 1; - if (args.length == 2) { - try { - page = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - return true; - } - } - if (page < 1) - page = 1; + if (args[0].equalsIgnoreCase("clear")) { + if (player != null) { + player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + CMIScoreboard.removeScoreBoard(player); + } + return true; + } - Job job = Jobs.getJob(args[0]); - if (job == null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); - return false; - } + int page = 1; + if (args.length == 2) { + try { + page = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + return false; + } + } + if (page < 1) + page = 1; - int workingIn = Jobs.getUsedSlots(job); - PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page); + Job job = Jobs.getJob(args[0]); + if (job == null) { + Language.sendMessage(sender, "command.top.error.nojob"); + return null; + } - List fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart()); - if (fullList.isEmpty()) { - CMIMessages.sendMessage(sender, LC.info_NoInformation); - return true; - } + int workingIn = Jobs.getUsedSlots(job); + PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page); - player.sendMessage(Jobs.getLanguage().getMessage("command.top.help.info")); + List fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart()); + if (fullList.isEmpty()) { + CMIMessages.sendMessage(sender, LC.info_NoInformation); + return true; + } - int place = 1; + int place = 1; - if (!Jobs.getGCManager().ShowToplistInScoreboard) { - player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount)); - for (TopList one : fullList) { - if (place > Jobs.getGCManager().JobsTopAmount) - break; + if (!Jobs.getGCManager().ShowToplistInScoreboard || player == null) { + Language.sendMessage(sender, "command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount); - player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.list", - "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, - "%playername%", one.getPlayerInfo().getName(), - "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), - "%level%", one.getLevel(), - "%exp%", one.getExp())); - place++; - } - plugin.showPagination(sender, pi, "jobs top " + job.getName()); - } else { - List ls = new ArrayList<>(); + for (TopList one : fullList) { + if (place > Jobs.getGCManager().JobsTopAmount) + break; - for (TopList one : fullList) { - if (place > Jobs.getGCManager().JobsTopAmount) - break; - ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, - "%playername%", one.getPlayerInfo().getName(), "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), "%level%", one.getLevel())); - place++; - } + Language.sendMessage(sender, "command.top.output.list", + "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, + "%playername%", one.getPlayerInfo().getName(), + "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), + "%level%", one.getLevel(), + "%exp%", one.getExp()); + place++; + } + pi.autoPagination(sender, "jobs top " + job.getName()); + } else { + List ls = new ArrayList<>(); - CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", job.getName()), ls, Jobs.getGCManager().ToplistInScoreboardInterval); + for (TopList one : fullList) { + if (place > Jobs.getGCManager().JobsTopAmount) + break; + ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, + "%playername%", one.getPlayerInfo().getName(), "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), "%level%", one.getLevel())); + place++; + } - plugin.showPagination(sender, pi, "jobs top " + job.getName()); - } - return true; + CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", job.getName()), ls, Jobs.getGCManager().ToplistInScoreboardInterval); + + pi.autoPagination(sender, "jobs top " + job.getName()); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/transfer.java b/src/main/java/com/gamingmesh/jobs/commands/list/transfer.java index 5f8c44ad..8a8df026 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/transfer.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/transfer.java @@ -7,51 +7,50 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; public class transfer implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length < 3) { - Jobs.getCommandManager().sendUsage(sender, "transfer"); - return true; - } + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length < 3) { + return false; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); - if (jPlayer == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); - return true; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (jPlayer == null) { + Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]); + return true; + } - Job oldjob = Jobs.getJob(args[1]); - if (oldjob == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job oldjob = Jobs.getJob(args[1]); + if (oldjob == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - Job newjob = Jobs.getJob(args[2]); - if (newjob == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + Job newjob = Jobs.getJob(args[2]); + if (newjob == null) { + Language.sendMessage(sender, "general.error.job"); + return true; + } - try { - if (jPlayer.isInJob(oldjob) && !jPlayer.isInJob(newjob)) { - Jobs.getPlayerManager().transferJob(jPlayer, oldjob, newjob); + try { + if (jPlayer.isInJob(oldjob) && !jPlayer.isInJob(newjob)) { + Jobs.getPlayerManager().transferJob(jPlayer, oldjob, newjob); - Player player = jPlayer.getPlayer(); - if (player != null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.transfer.output.target", - "%oldjobname%", oldjob.getDisplayName(), - "%newjobname%", newjob.getDisplayName())); - } + Player player = jPlayer.getPlayer(); + if (player != null) { + Language.sendMessage(player, "command.transfer.output.target", + "%oldjobname%", oldjob.getDisplayName(), + "%newjobname%", newjob.getDisplayName()); + } + Language.sendMessage(sender, "general.admin.success"); + } + } catch (Exception e) { + Language.sendMessage(sender, "general.admin.error"); + } - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); - } - } catch (Exception e) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); - } - - return true; + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/version.java b/src/main/java/com/gamingmesh/jobs/commands/list/version.java index 0bca2436..80466244 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/version.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/version.java @@ -13,14 +13,15 @@ import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.Util.CMIVersionChecker; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; import net.milkbowl.vault.economy.Economy; public class version implements Cmd { @Override - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + CMIScheduler.get().runTaskAsynchronously(new Runnable() { @Override public void run() { @@ -62,7 +63,7 @@ public class version implements Cmd { final String vault = preVault; final String vaultProvider = vProvider; - Bukkit.getScheduler().runTask(plugin, new Runnable() { + CMIScheduler.get().runTask(new Runnable() { @Override public void run() { diff --git a/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java b/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java index 4d420364..c4e56e14 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java @@ -16,7 +16,7 @@ import com.gamingmesh.jobs.container.DBAction; import net.Zrips.CMILib.Container.CMIBlock; import net.Zrips.CMILib.Container.CMIBlock.Bisect; import net.Zrips.CMILib.Items.CMIMaterial; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class BlockProtectionManager { @@ -40,7 +40,7 @@ public class BlockProtectionManager { } public void add(Block block, Integer cd) { - + if (cd == null || cd == 0) return; @@ -80,9 +80,9 @@ public class BlockProtectionManager { public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) { - if (time == 0) + if (time == null || time == 0) return null; - + String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ(); HashMap>> regions = map.getOrDefault(loc.getWorld(), new HashMap<>()); @@ -98,8 +98,8 @@ public class BlockProtectionManager { Bp = new BlockProtection(DBAction.INSERT, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); else { Bp.setAction(DBAction.UPDATE); - if (Bp.getSchedId() > -1) - Bukkit.getServer().getScheduler().cancelTask(Bp.getSchedId()); + if (Bp.getScheduler() != null) + Bp.getScheduler().cancel(); } Bp.setPaid(paid); @@ -107,7 +107,7 @@ public class BlockProtectionManager { // If timer is under 2 hours, we can run scheduler to remove it when time comes if (time > -1 && (time - System.currentTimeMillis()) / 1000 < 60 * 60 * 2) - Bp.setSchedId(Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), () -> { + Bp.setScheduler(CMIScheduler.get().runTaskLater(() -> { remove(loc); }, (time - System.currentTimeMillis()) / 50)); @@ -117,7 +117,7 @@ public class BlockProtectionManager { map.put(loc.getWorld(), regions); // Only saving into save cache if timer is higher than 5 minutes - if (cache && ((time - System.currentTimeMillis()) / 1000 > 60 * 5 || time < 0) ) + if (cache && ((time - System.currentTimeMillis()) / 1000 > 60 * 5 || time < 0)) addToCache(loc, Bp); return Bp; } @@ -187,7 +187,7 @@ public class BlockProtectionManager { world.remove(locToRegion(loc)); return bp; - } + } public Long getTime(Block block) { return getTime(block.getLocation()); diff --git a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java index 95863c40..06db254a 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java @@ -13,6 +13,7 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.stuff.ToggleBarHandling; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class BossBarManager { @@ -36,7 +37,7 @@ public class BossBarManager { public void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg, double expGain) { if (Jobs.getGCManager().isBossBarAsync()) { - Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> ShowJobProgressionInTask(player, jobProg, expGain)); + CMIScheduler.get().runTaskAsynchronously(() -> ShowJobProgressionInTask(player, jobProg, expGain)); } else { ShowJobProgressionInTask(player, jobProg, expGain); } @@ -139,7 +140,7 @@ public class BossBarManager { bar.setVisible(true); if (oldOne != null) - oldOne.setId(Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + oldOne.setScheduler(CMIScheduler.get().runTaskLater(new Runnable() { @Override public void run() { for (BossBarInfo one : player.getBossBarInfo()) { diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 43e6deeb..48256ef8 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -60,7 +60,7 @@ import net.Zrips.CMILib.Equations.ParseError; import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIMaterial; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; public class ConfigManager { @@ -965,7 +965,7 @@ public class ConfigManager { Jobs.setJobs(jobs); if (!jobs.isEmpty()) { - Jobs.consoleMsg("&eLoaded &6" + jobs.size() + " &ejobs"); + CMIMessages.consoleMessage("&eLoaded &6" + jobs.size() + " &ejobs"); } ItemBoostManager.load(); @@ -1315,7 +1315,7 @@ public class ConfigManager { jobItems.put(node.toLowerCase(), new JobItems(node, CMIMaterial.get(id), 1, name, lore, enchants, b, new ArrayList())); } - Jobs.consoleMsg("&cRemove Items section from " + jobKey + " job, as of Jobs 4.10.0 version this was moved to boostedItems.yml file!"); + CMIMessages.consoleMessage("&cRemove Items section from " + jobKey + " job, as of Jobs 4.10.0 version this was moved to boostedItems.yml file!"); } // Limited Items @@ -1416,8 +1416,8 @@ public class ConfigManager { } } - for (String oneObjective : sqsection.getStringList("Objectives")) { - List objectives = QuestObjective.get(oneObjective, jobFullName); + for (String oneObjective : sqsection.getStringList("Objectives")) { + List objectives = QuestObjective.get(oneObjective, jobFullName); quest.addObjectives(objectives); } @@ -1435,13 +1435,13 @@ public class ConfigManager { quests.add(quest); } catch (Exception e) { - Jobs.consoleMsg("&cCan't load &6" + one + " &cquest for &6" + jobFullName); + CMIMessages.consoleMessage("&cCan't load &6" + one + " &cquest for &6" + jobFullName); e.printStackTrace(); } } job.setQuests(quests); - Jobs.consoleMsg("&eLoaded &6" + quests.size() + " &equests for &6" + jobFullName); + CMIMessages.consoleMessage("&eLoaded &6" + quests.size() + " &equests for &6" + jobFullName); } job.setMaxDailyQuests(jobSection.getInt("maxDailyQuests", 1)); diff --git a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java index 574e0ee4..f9cf4e75 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java @@ -17,7 +17,7 @@ import com.gamingmesh.jobs.container.JobsWorld; import com.gamingmesh.jobs.dao.JobsDAO.ExploreDataTableFields; import com.gamingmesh.jobs.stuff.Util; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Messages.CMIMessages; public class ExploreManager { @@ -48,11 +48,11 @@ public class ExploreManager { if (!exploreEnabled) return; - Jobs.consoleMsg("&eLoading explorer data"); + CMIMessages.consoleMessage("&eLoading explorer data"); Long time = System.currentTimeMillis(); Jobs.getJobsDAO().loadExplore(); int size = getSize(); - Jobs.consoleMsg("&eLoaded explorer data" + (size != 0 ? " (&6" + size + "&e)" : " ") + " in " + (System.currentTimeMillis() - time) + " ms"); + CMIMessages.consoleMessage("&eLoaded explorer data" + (size != 0 ? " (&6" + size + "&e)" : " ") + " in " + (System.currentTimeMillis() - time) + " ms"); } public Map> getWorlds() { @@ -149,17 +149,17 @@ public class ExploreManager { } public void resetRegion(String worldname) { - Jobs.consoleMsg("&eReseting explorer data. World: " + worldname); + CMIMessages.consoleMessage("&eReseting explorer data. World: " + worldname); Map> worlds = getWorlds(); worlds.put(worldname, new HashMap()); boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname); if (!r) { - Jobs.consoleMsg("&eFailed in DAO."); + CMIMessages.consoleMessage("&eFailed in DAO."); return; } - Jobs.consoleMsg("&eCompleted to reset explorer data."); + CMIMessages.consoleMessage("&eCompleted to reset explorer data."); } } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 0340dcec..a4a98967 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -40,12 +40,12 @@ import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyType; import net.Zrips.CMILib.CMILib; -import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.CMIList; import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; public class GeneralConfigManager { @@ -95,7 +95,8 @@ public class GeneralConfigManager { SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useSilkTouchProtection, UseCustomNames, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, informOnPaymentDisable, BrowseUseNewLook, payExploringWhenGliding = false, resetExploringData = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding, - boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems, boostedItemsSlotSpecific, multiplyBoostedExtraValues, addPermissionBoost, highestPermissionBoost /*, preventCropResizePayment*/, + boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems, boostedItemsSlotSpecific, multiplyBoostedExtraValues, addPermissionBoost, + highestPermissionBoost, payItemDurabilityLoss, applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useMinimumOveralExp, useBreederFinder, CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, @@ -106,9 +107,12 @@ public class GeneralConfigManager { EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, useMaxPaymentCurve, blockOwnershipTakeOver, hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers, BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse, - DisabledWorldsUse, UseAsWhiteListWorldList, PaymentMethodsMoney, PaymentMethodsPoints, PaymentMethodsExp, MythicMobsEnabled, + DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled, LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false, payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false, preventShopItemEnchanting; + + public boolean jobsshopenabled; + public boolean DailyQuestsEnabled; public ItemStack guiInfoButton; public int InfoButtonSlot = 9; @@ -419,6 +423,9 @@ public class GeneralConfigManager { c.addComment("broadcast.on-level-up.levels", "For what levels you want to broadcast message? Keep it at 0 if you want for all of them"); BroadcastingLevelUpLevels = c.getIntList("broadcast.on-level-up.levels", Arrays.asList(0)); + c.addComment("DailyQuests.Enabled", "Enables or disables daily quests"); + DailyQuestsEnabled = c.get("DailyQuests.Enabled", true); + c.addComment("DailyQuests.ResetTime", "Defines time in 24hour format when we want to give out new daily quests", "Any daily quests given before reset will be invalid and new ones will be given out"); ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4); @@ -449,6 +456,9 @@ public class GeneralConfigManager { c.addComment("prevent-shop-item-enchanting", "Prevent players to enchant items from the shop in the anvil with enchanted books"); preventShopItemEnchanting = c.get("prevent-shop-item-enchanting", true); + + c.addComment("jobs-shop-enabled", "Enables or disables jobs shop"); + jobsshopenabled = c.get("jobs-shop-enabled", true); c.addComment("enable-pay-near-spawner", "Option to allow payment to be made when killing mobs from a spawner.", @@ -543,7 +553,7 @@ public class GeneralConfigManager { CMIMaterial mat = CMIMaterial.get(mName); if (mat == CMIMaterial.NONE) { - Jobs.consoleMsg("Failed to recognize " + one + " entry from config file"); + CMIMessages.consoleMessage("Failed to recognize " + one + " entry from config file"); continue; } @@ -585,9 +595,10 @@ public class GeneralConfigManager { c.addComment("Economy.PaymentMethods", "By disabling one of these, players no longer will get particular payment.", "Useful for removing particular payment method without editing whole jobConfig file"); - PaymentMethodsMoney = c.get("Economy.PaymentMethods.Money", true); - PaymentMethodsPoints = c.get("Economy.PaymentMethods.Points", true); - PaymentMethodsExp = c.get("Economy.PaymentMethods.Exp", true); + + for (CurrencyType one : CurrencyType.values()) { + one.setEnabled(c.get("Economy.PaymentMethods." + one.getName(), true)); + } c.addComment("Economy.GeneralMulti", "Can be used to change payment amounts for all jobs and all actions if you want to readjust them", @@ -644,7 +655,7 @@ public class GeneralConfigManager { DynamicPaymentEquation.setVariable("totaljobs", 10); DynamicPaymentEquation.setVariable("jobstotalplayers", 10); } catch (Throwable e) { - Jobs.consoleMsg("&cDynamic payment equation has an invalid property. Disabling feature!"); + CMIMessages.consoleMessage("&cDynamic payment equation has an invalid property. Disabling feature!"); useDynamicPayment = false; } @@ -702,8 +713,14 @@ public class GeneralConfigManager { Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!"); limit.setEnabled(false); } + c.addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600)); + + c.addComment("Economy.Limit.Money.ResetTime", "Time in 24 hour format when limit should reset. This will override TimeLimit if defined", + "Example: '00:00:00' will reset timer at midnight, '04:30:00' will reset at 4:30 in the morning", "Set to empty field if you want to use TimeLimit"); + limit.setResetsAt(c.get("Economy.Limit.Money.ResetTime", "")); + c.addComment("Economy.Limit.Money.AnnouncementDelay", "Delay between announcements about reached money limit", "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); limit.setAnnouncementDelay(c.get("Economy.Limit.Money.AnnouncementDelay", 30)); @@ -736,6 +753,11 @@ public class GeneralConfigManager { } c.addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600)); + + c.addComment("Economy.Limit.Point.ResetTime", "Time in 24 hour format when limit should reset. This will override TimeLimit if defined", + "Example: '00:00:00' will reset timer at midnight, '04:30:00' will reset at 4:30 in the morning", "Set to empty field if you want to use TimeLimit"); + limit.setResetsAt(c.get("Economy.Limit.Point.ResetTime", "")); + c.addComment("Economy.Limit.Point.AnnouncementDelay", "Delay between announcements about reached limit", "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); limit.setAnnouncementDelay(c.get("Economy.Limit.Point.AnnouncementDelay", 30)); @@ -768,6 +790,11 @@ public class GeneralConfigManager { } c.addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600)); + + c.addComment("Economy.Limit.Exp.ResetTime", "Time in 24 hour format when limit should reset. This will override TimeLimit if defined", + "Example: '00:00:00' will reset timer at midnight, '04:30:00' will reset at 4:30 in the morning", "Set to empty field if you want to use TimeLimit"); + limit.setResetsAt(c.get("Economy.Limit.Exp.ResetTime", "")); + c.addComment("Economy.Limit.Exp.AnnouncementDelay", "Delay between announcements about reached Exp limit", "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); limit.setAnnouncementDelay(c.get("Economy.Limit.Exp.AnnouncementDelay", 30)); diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index c0071f1e..72bad4a6 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.List; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.FileHandler.ConfigReader; @@ -79,6 +80,19 @@ public class LanguageManager { c.get("limitedItem.error.levelup", "&cYou need to level up in [jobname] to use this item!"); c.get("general.info.toplineseparator", "&7*********************** &6%playerdisplayname% &7***********************"); c.get("general.info.separator", "&7*******************************************************"); + + for (CurrencyType curr : CurrencyType.values()) { + c.get("general.info.paymentType." + curr.toString(), curr.getName()); + + String color = "&2"; + if (curr.equals(CurrencyType.POINTS)) + color = "&6"; + else if (curr.equals(CurrencyType.EXP)) + color = "&e"; + + c.get("general.info.paymentTypeValued." + curr.toString(), color + curr.getName() + ": %amount%"); + } + c.get("general.info.invalidPage", "&cInvalid page"); c.get("general.info.blocks.furnace", "Furnace"); c.get("general.info.blocks.smoker", "Smoker"); @@ -107,35 +121,17 @@ public class LanguageManager { c.get("command.help.output.title", "&e-------&e ======= &6Jobs &e======= &e-------"); - c.get("command.moneyboost.help.info", "Boosts money gain for all players"); - c.get("command.moneyboost.help.args", "[jobname]/all/reset [time]/[rate]"); - Jobs.getGCManager().getCommandArgs().put("moneyboost", Arrays.asList("[jobname]%%all%%reset", "[time]%%2", "%%2")); - c.get("command.moneyboost.output.allreset", "All money boosts turned off"); - c.get("command.moneyboost.output.jobsboostreset", "Money boost has been turned off for %jobname%"); - c.get("command.moneyboost.output.nothingtoreset", "Nothing to reset"); - c.get("command.moneyboost.output.boostalladded", "Money boost of %boost% added for all jobs!"); - c.get("command.moneyboost.output.boostadded", "Money boost of &e%boost% &aadded for &e%jobname%!"); - c.get("command.moneyboost.output.infostats", "&c-----> &aMoney rate x%boost% enabled&c <-------"); - - c.get("command.pointboost.help.info", "Boosts point gain for all players"); - c.get("command.pointboost.help.args", "[jobname]/all/reset [time]/[rate]"); - Jobs.getGCManager().getCommandArgs().put("pointboost", Arrays.asList("[jobname]%%all%%reset", "[time]%%2", "%%2")); - c.get("command.pointboost.output.allreset", "All point boosts turned off"); - c.get("command.pointboost.output.jobsboostreset", "Point boost has been turned off for %jobname%"); - c.get("command.pointboost.output.nothingtoreset", "Nothing to reset"); - c.get("command.pointboost.output.boostalladded", "Points boost of %boost% added for all jobs!"); - c.get("command.pointboost.output.boostadded", "Points boost of &e%boost% &aadded for &e%jobname%!"); - c.get("command.pointboost.output.infostats", "&c-----> &aPoints rate x%boost% enabled&c <-------"); - - c.get("command.expboost.help.info", "Boosts exp gain for all players"); - c.get("command.expboost.help.args", "[jobname]/all/reset [time]/[rate]"); - Jobs.getGCManager().getCommandArgs().put("expboost", Arrays.asList("[jobname]%%all%%reset", "[time]%%2", "%%2")); - c.get("command.expboost.output.allreset", "All exp boosts turned off"); - c.get("command.expboost.output.jobsboostreset", "Exp boost has been turned off for %jobname%"); - c.get("command.expboost.output.nothingtoreset", "Nothing to reset"); - c.get("command.expboost.output.boostalladded", "Exp boost of %boost% added for all jobs!"); - c.get("command.expboost.output.boostadded", "Exp boost of &e%boost% &aadded for &e%jobname%!"); - c.get("command.expboost.output.infostats", "&c-----> &aExp rate x%boost% enabled&c <-------"); + c.get("command.boost.help.info", "Boosts jobs gains for all players"); + c.get("command.boost.help.args", "exp/money/points [jobname]/all/reset [rate] [time]"); + Jobs.getGCManager().getCommandArgs().put("boost", Arrays.asList("[jobname]", "reset%%exp%%money%%points", "[time]%%2", "%%2")); + c.get("command.boost.output.allreset", "&aAll boosts turned off"); + c.get("command.boost.output.alltypereset", "&aAll &e%type% &aboosts turned off"); + c.get("command.boost.output.jobsboostreset", "&aBoost has been turned off for &e%jobname%"); + c.get("command.boost.output.jobstypeboostreset", "&e%type% &aboost has been turned off for &e%jobname%"); + c.get("command.boost.output.nothingtoreset", "Nothing to reset"); + c.get("command.boost.output.boostadded", "&aBoost of &e%boost% &aadded for &e%jobname%!"); + c.get("command.boost.output.infostats", "&c-----> &a%type% rate x%boost% enabled&c <-------"); + c.get("command.boost.output.boostStats", "&6%payments% &e%jobname%"); c.get("command.schedule.help.info", "Enables the given scheduler"); c.get("command.schedule.help.args", "enable [scheduleName] [untilTime]"); @@ -248,9 +244,9 @@ public class LanguageManager { c.get("command.editjobs.help.modify.lookHover", "&6Press to grab info from block you are looking"); c.get("command.editquests.help.info", "Edit job quests."); - c.get("command.editquests.help.args", "(page)"); + c.get("command.editquests.help.args", "(page)"); c.get("command.editquests.help.output.list", "&6[questName] &7- &f[jobName]"); - + c.get("command.editquests.help.output.name", "&eName: &f"); c.get("command.editquests.help.output.job", " &eJob: &f"); c.get("command.editquests.help.output.chance", " &eChance: &f"); @@ -301,11 +297,11 @@ public class LanguageManager { c.get("command.shop.help.info", "Opens special jobs shop."); c.get("command.shop.help.args", ""); c.get("command.shop.info.title", "&e------- &8Jobs shop &e-------"); - + c.get("command.shop.info.haveColor", "&2"); c.get("command.shop.info.pointsPrice", "&ePoint cost: &c%currentpoints%&e/&6%price%"); c.get("command.shop.info.moneyPrice", "&eMoney cost: &c%currentbalance%&e/&6%price%"); - + c.get("command.shop.info.reqJobs", "&eRequired jobs:"); c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl"); c.get("command.shop.info.reqTotalLevel", "&6Required total level: &e%totalLevel%"); @@ -486,6 +482,7 @@ public class LanguageManager { c.get("command.skipquest.help.info", "Skip defined quest and get new one"); c.get("command.skipquest.help.args", "[jobname] [questname] (playerName)"); c.get("command.skipquest.output.questSkipForCost", "&2You skipped the quest and paid:&e %amount%$"); + c.get("command.skipquest.confirmationNeed", "&cAre you sure you want to skip&e [questName]&c quest? Type the command again within&6 [time] seconds &cto confirm!"); Jobs.getGCManager().getCommandArgs().put("skipquest", Arrays.asList("[jobname]", "[questname]", "[playername]")); c.get("command.quests.help.info", "List available quests"); diff --git a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java index 62959b50..80b8b77d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java @@ -26,7 +26,7 @@ import net.Zrips.CMILib.Container.CMIText; import net.Zrips.CMILib.Entities.CMIEntityType; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIMaterial; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Messages.CMIMessages; public class NameTranslatorManager { @@ -231,9 +231,9 @@ public class NameTranslatorManager { } if (listOfNames.size() > 0) - Jobs.consoleMsg("&eLoaded &6" + listOfNames.size() + " &ecustom item names"); + CMIMessages.consoleMessage("&eLoaded &6" + listOfNames.size() + " &ecustom item names"); } else - Jobs.consoleMsg("&cThe ItemList section not found in &6" + itemFile.fileName + " &cfile."); + CMIMessages.consoleMessage("&cThe ItemList section not found in &6" + itemFile.fileName + " &cfile."); if ((section = itemFile.getConfig().getConfigurationSection("EntityList")) != null) { listOfEntities.clear(); @@ -252,9 +252,9 @@ public class NameTranslatorManager { } if (!listOfEntities.isEmpty()) - Jobs.consoleMsg("&eLoaded &6" + listOfEntities.size() + " &ecustom entity names"); + CMIMessages.consoleMessage("&eLoaded &6" + listOfEntities.size() + " &ecustom entity names"); } else - Jobs.consoleMsg("&cThe EntityList section not found in &6" + itemFile.fileName + " &cfile."); + CMIMessages.consoleMessage("&cThe EntityList section not found in &6" + itemFile.fileName + " &cfile."); if ((section = itemFile.getConfig().getConfigurationSection("MythicEntityList")) != null) { listOfMMEntities.clear(); @@ -265,9 +265,9 @@ public class NameTranslatorManager { } if (listOfMMEntities.size() > 0) - Jobs.consoleMsg("&eLoaded &6" + listOfMMEntities.size() + " &ecustom MythicMobs names"); + CMIMessages.consoleMessage("&eLoaded &6" + listOfMMEntities.size() + " &ecustom MythicMobs names"); } else - Jobs.consoleMsg("&cThe MythicEntityList section not found in &6" + itemFile.fileName + " &cfile."); + CMIMessages.consoleMessage("&cThe MythicEntityList section not found in &6" + itemFile.fileName + " &cfile."); if ((section = itemFile.getConfig().getConfigurationSection("EnchantList")) != null) { listOfEnchants.clear(); @@ -277,9 +277,9 @@ public class NameTranslatorManager { } if (listOfEnchants.size() > 0) - Jobs.consoleMsg("&eLoaded &6" + listOfEnchants.size() + " &ecustom enchant names"); + CMIMessages.consoleMessage("&eLoaded &6" + listOfEnchants.size() + " &ecustom enchant names"); } else - Jobs.consoleMsg("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile."); + CMIMessages.consoleMessage("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile."); if ((section = itemFile.getConfig().getConfigurationSection("PotionEffects")) != null) { listOfPotionEffects.clear(); @@ -289,9 +289,9 @@ public class NameTranslatorManager { } if (listOfPotionEffects.size() > 0) - Jobs.consoleMsg("&eLoaded &6" + listOfPotionEffects.size() + " &ecustom enchant names"); + CMIMessages.consoleMessage("&eLoaded &6" + listOfPotionEffects.size() + " &ecustom enchant names"); } else - Jobs.consoleMsg("&cThe PotionEffects section not found in &6" + itemFile.fileName + " &cfile."); + CMIMessages.consoleMessage("&cThe PotionEffects section not found in &6" + itemFile.fileName + " &cfile."); if ((section = itemFile.getConfig().getConfigurationSection("ColorList")) != null) { listOfColors.clear(); @@ -304,9 +304,9 @@ public class NameTranslatorManager { } if (!listOfColors.isEmpty()) - Jobs.consoleMsg("&eLoaded &6" + listOfColors.size() + " &ecustom color names"); + CMIMessages.consoleMessage("&eLoaded &6" + listOfColors.size() + " &ecustom color names"); } else - Jobs.consoleMsg("&cThe ColorList section not found in &6" + itemFile.fileName + " &cfile."); + CMIMessages.consoleMessage("&cThe ColorList section not found in &6" + itemFile.fileName + " &cfile."); } @SuppressWarnings("deprecation") diff --git a/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java b/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java index 48196e73..47fb4e5a 100644 --- a/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/RestrictedAreaManager.java @@ -20,6 +20,8 @@ import com.gamingmesh.jobs.container.CuboidArea; import com.gamingmesh.jobs.container.RestrictedArea; import com.gamingmesh.jobs.hooks.HookManager; +import net.Zrips.CMILib.Messages.CMIMessages; + public class RestrictedAreaManager { protected final Map restrictedAreas = new HashMap<>(); @@ -27,43 +29,43 @@ public class RestrictedAreaManager { private boolean worldGuardArea = false; public boolean isExist(String name) { - for (String area : restrictedAreas.keySet()) { - if (area.equalsIgnoreCase(name)) - return true; - } - return false; + for (String area : restrictedAreas.keySet()) { + if (area.equalsIgnoreCase(name)) + return true; + } + return false; } public void addNew(RestrictedArea ra) { - addNew(ra, false); + addNew(ra, false); } public void addNew(RestrictedArea ra, boolean save) { - restrictedAreas.put(ra.getName(), ra); - if (save) - save(); + restrictedAreas.put(ra.getName(), ra); + if (save) + save(); } public void remove(String name) { - for (String area : restrictedAreas.keySet()) { - if (area.equalsIgnoreCase(name)) { - restrictedAreas.remove(area); - break; - } - } - File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); - if (f.exists()) { - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - conf.options().indent(2); - conf.options().copyDefaults(true); - addHeader(new StringBuilder()); - conf.set("restrictedareas." + name, null); - try { - conf.save(f); - } catch (IOException e) { - e.printStackTrace(); - } - } + for (String area : restrictedAreas.keySet()) { + if (area.equalsIgnoreCase(name)) { + restrictedAreas.remove(area); + break; + } + } + File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); + if (f.exists()) { + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + conf.options().indent(2); + conf.options().copyDefaults(true); + addHeader(new StringBuilder()); + conf.set("restrictedareas." + name, null); + try { + conf.save(f); + } catch (IOException e) { + e.printStackTrace(); + } + } } /** @@ -74,44 +76,44 @@ public class RestrictedAreaManager { */ @Deprecated public Map getRestrictedAres() { - return restrictedAreas; + return restrictedAreas; } public Map getRestrictedAreas() { - return restrictedAreas; + return restrictedAreas; } private void save() { - File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - conf.options().indent(2); - conf.options().copyDefaults(true); + conf.options().indent(2); + conf.options().copyDefaults(true); - addHeader(new StringBuilder()); + addHeader(new StringBuilder()); - for (Entry area : restrictedAreas.entrySet()) { - String areaKey = area.getKey(); - CuboidArea cuboid = area.getValue().getCuboidArea(); - conf.set("restrictedareas." + areaKey + ".multiplier", area.getValue().getMultiplier()); + for (Entry area : restrictedAreas.entrySet()) { + String areaKey = area.getKey(); + CuboidArea cuboid = area.getValue().getCuboidArea(); + conf.set("restrictedareas." + areaKey + ".multiplier", area.getValue().getMultiplier()); - if (area.getValue().getWgName() == null) { - conf.set("restrictedareas." + areaKey + ".world", cuboid.getWorld().getName()); - conf.set("restrictedareas." + areaKey + ".point1.x", cuboid.getLowLoc().getBlockX()); - conf.set("restrictedareas." + areaKey + ".point1.y", cuboid.getLowLoc().getBlockY()); - conf.set("restrictedareas." + areaKey + ".point1.z", cuboid.getLowLoc().getBlockZ()); - conf.set("restrictedareas." + areaKey + ".point2.x", cuboid.getHighLoc().getBlockX()); - conf.set("restrictedareas." + areaKey + ".point2.y", cuboid.getHighLoc().getBlockY()); - conf.set("restrictedareas." + areaKey + ".point2.z", cuboid.getHighLoc().getBlockZ()); - } else - conf.set("restrictedareas." + areaKey + ".WG", true); - } + if (area.getValue().getWgName() == null) { + conf.set("restrictedareas." + areaKey + ".world", cuboid.getWorld().getName()); + conf.set("restrictedareas." + areaKey + ".point1.x", cuboid.getLowLoc().getBlockX()); + conf.set("restrictedareas." + areaKey + ".point1.y", cuboid.getLowLoc().getBlockY()); + conf.set("restrictedareas." + areaKey + ".point1.z", cuboid.getLowLoc().getBlockZ()); + conf.set("restrictedareas." + areaKey + ".point2.x", cuboid.getHighLoc().getBlockX()); + conf.set("restrictedareas." + areaKey + ".point2.y", cuboid.getHighLoc().getBlockY()); + conf.set("restrictedareas." + areaKey + ".point2.z", cuboid.getHighLoc().getBlockZ()); + } else + conf.set("restrictedareas." + areaKey + ".WG", true); + } - try { - conf.save(f); - } catch (IOException e) { - e.printStackTrace(); - } + try { + conf.save(f); + } catch (IOException e) { + e.printStackTrace(); + } } /** @@ -120,74 +122,74 @@ public class RestrictedAreaManager { * @return - the multiplier */ public double getRestrictedMultiplier(Player player) { - if (player == null) - return 0D; - for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) { - if (area.inRestrictedArea(player.getLocation()) || (area.getWgName() != null && HookManager.getWorldGuardManager() != null - && HookManager.getWorldGuardManager().inArea(player.getLocation(), area.getWgName()))) - return area.getMultiplier(); - } - return 0D; + if (player == null) + return 0D; + for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) { + if (area.inRestrictedArea(player.getLocation()) || (area.getWgName() != null && HookManager.getWorldGuardManager() != null + && HookManager.getWorldGuardManager().inArea(player.getLocation(), area.getWgName()))) + return area.getMultiplier(); + } + return 0D; } public List getRestrictedAreasByLoc(Location loc) { - List areas = new ArrayList<>(); - for (RestrictedArea area : restrictedAreas.values()) { - if (area.inRestrictedArea(loc)) - areas.add(area); - } + List areas = new ArrayList<>(); + for (RestrictedArea area : restrictedAreas.values()) { + if (area.inRestrictedArea(loc)) + areas.add(area); + } - if (worldGuardArea && HookManager.getWorldGuardManager() != null) - areas.addAll(HookManager.getWorldGuardManager().getArea(loc)); + if (worldGuardArea && HookManager.getWorldGuardManager() != null) + areas.addAll(HookManager.getWorldGuardManager().getArea(loc)); - return areas; + return areas; } public List getRestrictedAreasByName(String name) { - List areas = new ArrayList<>(); - for (Entry area : restrictedAreas.entrySet()) { - if (area.getKey().equalsIgnoreCase(name)) - areas.add(area.getValue()); - } - return areas; + List areas = new ArrayList<>(); + for (Entry area : restrictedAreas.entrySet()) { + if (area.getKey().equalsIgnoreCase(name)) + areas.add(area.getValue()); + } + return areas; } private static StringBuilder addHeader(StringBuilder header) { - String sep = System.lineSeparator(); + String sep = System.lineSeparator(); - header.append("Restricted area configuration"); - header.append(sep) - .append(sep) - .append("Configures restricted areas where you cannot get experience or money").append(sep) - .append("when performing a job.").append(sep).append(sep) - .append("The multiplier changes the experience/money gains in an area.").append(sep) - .append("A multiplier of 0.0 means no bonus, while 0.5 means you will get 50% more the normal income").append(sep) - .append("While -0.5 means that you will get 50% less the normal income").append(sep) - .append(sep) - .append("restrictedareas:").append(sep) - .append(" area1:").append(sep) - .append(" world: 'world'").append(sep) - .append(" multiplier: 0.0").append(sep) - .append(" point1:").append(sep) - .append(" x: 125").append(sep) - .append(" y: 0").append(sep) - .append(" z: 125").append(sep) - .append(" point2:").append(sep) - .append(" x: 150").append(sep) - .append(" y: 100").append(sep) - .append(" z: 150").append(sep) - .append(" area2:").append(sep) - .append(" world: 'world_nether'").append(sep) - .append(" multiplier: 0.0").append(sep) - .append(" point1:").append(sep) - .append(" x: -100").append(sep) - .append(" y: 0").append(sep) - .append(" z: -100").append(sep) - .append(" point2:").append(sep) - .append(" x: -150").append(sep) - .append(" y: 100").append(sep) - .append(" z: -150"); - return header; + header.append("Restricted area configuration"); + header.append(sep) + .append(sep) + .append("Configures restricted areas where you cannot get experience or money").append(sep) + .append("when performing a job.").append(sep).append(sep) + .append("The multiplier changes the experience/money gains in an area.").append(sep) + .append("A multiplier of 0.0 means no bonus, while 0.5 means you will get 50% more the normal income").append(sep) + .append("While -0.5 means that you will get 50% less the normal income").append(sep) + .append(sep) + .append("restrictedareas:").append(sep) + .append(" area1:").append(sep) + .append(" world: 'world'").append(sep) + .append(" multiplier: 0.0").append(sep) + .append(" point1:").append(sep) + .append(" x: 125").append(sep) + .append(" y: 0").append(sep) + .append(" z: 125").append(sep) + .append(" point2:").append(sep) + .append(" x: 150").append(sep) + .append(" y: 100").append(sep) + .append(" z: 150").append(sep) + .append(" area2:").append(sep) + .append(" world: 'world_nether'").append(sep) + .append(" multiplier: 0.0").append(sep) + .append(" point1:").append(sep) + .append(" x: -100").append(sep) + .append(" y: 0").append(sep) + .append(" z: -100").append(sep) + .append(" point2:").append(sep) + .append(" x: -150").append(sep) + .append(" y: 100").append(sep) + .append(" z: -150"); + return header; } /** @@ -196,47 +198,47 @@ public class RestrictedAreaManager { * loads from Jobs/restrictedAreas.yml */ public void load() { - restrictedAreas.clear(); + restrictedAreas.clear(); - File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - conf.options().indent(2); - conf.options().copyDefaults(true); + conf.options().indent(2); + conf.options().copyDefaults(true); - StringBuilder header = addHeader(new StringBuilder()); - conf.options().header(header.toString()); + StringBuilder header = addHeader(new StringBuilder()); + conf.options().header(header.toString()); - ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas"); - if (areaSection != null) { - for (String areaKey : areaSection.getKeys(false)) { - double multiplier = areaSection.getDouble(areaKey + ".multiplier"); + ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas"); + if (areaSection != null) { + for (String areaKey : areaSection.getKeys(false)) { + double multiplier = areaSection.getDouble(areaKey + ".multiplier"); - if (areaSection.isBoolean(areaKey + ".WG")) { - addNew(new RestrictedArea(areaKey, areaKey, multiplier)); - worldGuardArea = true; - } else { - World world = Bukkit.getServer().getWorld(areaSection.getString(areaKey + ".world", "")); - if (world == null) - continue; - Location point1 = new Location(world, areaSection.getDouble(areaKey + ".point1.x"), areaSection.getDouble(areaKey - + ".point1.y"), areaSection.getDouble(areaKey + ".point1.z")); + if (areaSection.isBoolean(areaKey + ".WG")) { + addNew(new RestrictedArea(areaKey, areaKey, multiplier)); + worldGuardArea = true; + } else { + World world = Bukkit.getServer().getWorld(areaSection.getString(areaKey + ".world", "")); + if (world == null) + continue; + Location point1 = new Location(world, areaSection.getDouble(areaKey + ".point1.x"), areaSection.getDouble(areaKey + + ".point1.y"), areaSection.getDouble(areaKey + ".point1.z")); - Location point2 = new Location(world, areaSection.getDouble(areaKey + ".point2.x"), areaSection.getDouble(areaKey - + ".point2.y"), areaSection.getDouble(areaKey + ".point2.z")); - addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier)); - } - } - } + Location point2 = new Location(world, areaSection.getDouble(areaKey + ".point2.x"), areaSection.getDouble(areaKey + + ".point2.y"), areaSection.getDouble(areaKey + ".point2.z")); + addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier)); + } + } + } - int size = restrictedAreas.size(); - if (size > 0) - Jobs.consoleMsg("&e[Jobs] Loaded " + size + " restricted areas!"); + int size = restrictedAreas.size(); + if (size > 0) + CMIMessages.consoleMessage("&e[Jobs] Loaded " + size + " restricted areas!"); - try { - conf.save(f); - } catch (IOException e) { - e.printStackTrace(); - } + try { + conf.save(f); + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java b/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java index da7584d0..48d75bb3 100644 --- a/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.Jobs; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Messages.CMIMessages; public class RestrictedBlockManager { @@ -18,69 +19,69 @@ public class RestrictedBlockManager { * loads from Jobs/restrictedBlocks.yml */ public void load() { - if (!Jobs.getGCManager().useBlockProtection) - return; + if (!Jobs.getGCManager().useBlockProtection) + return; - ConfigReader cfg = null; - try { - cfg = new ConfigReader(Jobs.getInstance(), "restrictedBlocks.yml"); - } catch (Exception e) { - e.printStackTrace(); - } + ConfigReader cfg = null; + try { + cfg = new ConfigReader(Jobs.getInstance(), "restrictedBlocks.yml"); + } catch (Exception e) { + e.printStackTrace(); + } - if (cfg == null) - return; + if (cfg == null) + return; - cfg.addComment("blocksTimer", "Block protected by timer in sec", - "Category name can be any you like to be easily recognized", - "id can be actual block id (use /jobs blockinfo to get correct id) or use block name", - "By setting time to -1 will keep block protected until global cleanup, mainly used for structure blocks like diamond", - "Set to 0 if you want to disable protection on specific blocks", - "If you want to have default value for all blocks, enable GlobalBlockTimer in generalConfig file"); + cfg.addComment("blocksTimer", "Block protected by timer in sec", + "Category name can be any you like to be easily recognized", + "id can be actual block id (use /jobs blockinfo to get correct id) or use block name", + "By setting time to -1 will keep block protected until global cleanup, mainly used for structure blocks like diamond", + "Set to 0 if you want to disable protection on specific blocks", + "If you want to have default value for all blocks, enable GlobalBlockTimer in generalConfig file"); - org.bukkit.configuration.ConfigurationSection section = cfg.getC().getConfigurationSection("blocksTimer"); - if (section != null) { - for (String one : section.getKeys(false)) { - if ((section.isString(one + ".id") || section.isInt(one + ".id")) && section.isInt(one + ".cd")) { - CMIItemStack cm = CMIMaterial.get(section.getString(one + ".id")).newCMIItemStack(); - CMIMaterial mat = cm == null ? null : cm.getCMIType(); + org.bukkit.configuration.ConfigurationSection section = cfg.getC().getConfigurationSection("blocksTimer"); + if (section != null) { + for (String one : section.getKeys(false)) { + if ((section.isString(one + ".id") || section.isInt(one + ".id")) && section.isInt(one + ".cd")) { + CMIItemStack cm = CMIMaterial.get(section.getString(one + ".id")).newCMIItemStack(); + CMIMaterial mat = cm == null ? null : cm.getCMIType(); - if (mat == null || !mat.isBlock()) { - Jobs.consoleMsg("&eYour defined (&6" + one + "&e) protected block id/name is not correct!"); - continue; - } + if (mat == null || !mat.isBlock()) { + CMIMessages.consoleMessage("&eYour defined (&6" + one + "&e) protected block id/name is not correct!"); + continue; + } - int cd = section.getInt(one + ".cd"); - restrictedBlocksTimer.put(mat, cd); - cfg.set("blocksTimer." + mat.name(), cd); - } else { - CMIMaterial mat = CMIMaterial.get(one); - if (mat == CMIMaterial.NONE) - continue; + int cd = section.getInt(one + ".cd"); + restrictedBlocksTimer.put(mat, cd); + cfg.set("blocksTimer." + mat.name(), cd); + } else { + CMIMaterial mat = CMIMaterial.get(one); + if (mat == CMIMaterial.NONE) + continue; - int timer = cfg.get("blocksTimer." + one, -99); - if (timer == -99) { - cfg.set("blocksTimer." + one, null); - continue; - } + int timer = cfg.get("blocksTimer." + one, -99); + if (timer == -99) { + cfg.set("blocksTimer." + one, null); + continue; + } - cfg.set("blocksTimer." + one, null); - cfg.get("blocksTimer." + mat.name(), timer); + cfg.set("blocksTimer." + one, null); + cfg.get("blocksTimer." + mat.name(), timer); - if (!mat.isBlock()) { - Jobs.consoleMsg("&e[Jobs] Your defined (" + one + ") protected block id/name is not correct!"); - continue; - } + if (!mat.isBlock()) { + CMIMessages.consoleMessage("&e[Jobs] Your defined (" + one + ") protected block id/name is not correct!"); + continue; + } - restrictedBlocksTimer.put(mat, timer); - } - } - } + restrictedBlocksTimer.put(mat, timer); + } + } + } - int size = restrictedBlocksTimer.size(); - if (size > 0) - Jobs.consoleMsg("&eLoaded &6" + size + " &eprotected blocks timers"); + int size = restrictedBlocksTimer.size(); + if (size > 0) + CMIMessages.consoleMessage("&eLoaded &6" + size + " &eprotected blocks timers"); - cfg.save(); + cfg.save(); } } diff --git a/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java b/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java index 4c9cef7f..3c274749 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java @@ -7,26 +7,27 @@ import java.util.Calendar; import java.util.Date; import java.util.List; -import com.gamingmesh.jobs.api.JobsScheduleStartEvent; -import com.gamingmesh.jobs.api.JobsScheduleStopEvent; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.scheduler.BukkitTask; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.api.JobsScheduleStartEvent; +import com.gamingmesh.jobs.api.JobsScheduleStopEvent; import com.gamingmesh.jobs.container.BoostMultiplier; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Schedule; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; +import net.Zrips.CMILib.Version.Schedulers.CMITask; public class ScheduleManager { private Jobs plugin; - private BukkitTask timer; + private CMITask timer; private YmlMaker jobSchedule; public static final List BOOSTSCHEDULE = new ArrayList<>(); @@ -44,7 +45,7 @@ public class ScheduleManager { return; cancel(); - timer = Bukkit.getScheduler().runTaskTimer(plugin, this::scheduler, 20, 30 * 20L); + timer = CMIScheduler.get().scheduleSyncRepeatingTask(this::scheduler, 20, 30 * 20L); } public void cancel() { @@ -180,7 +181,7 @@ public class ScheduleManager { !path.isList("Days") && !path.isString("Days") || !path.isList("Jobs") && !path.isString("Jobs")) { - Jobs.consoleMsg("&cIncorect scheduler format detected for " + oneSection + " scheduler!"); + CMIMessages.consoleMessage("&cIncorect scheduler format detected for " + oneSection + " scheduler!"); continue; } @@ -228,6 +229,6 @@ public class ScheduleManager { } if (!BOOSTSCHEDULE.isEmpty()) - Jobs.consoleMsg("&eLoaded " + BOOSTSCHEDULE.size() + " schedulers!"); + CMIMessages.consoleMessage("&eLoaded " + BOOSTSCHEDULE.size() + " schedulers!"); } } diff --git a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java index b0894df1..d60a04c4 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java @@ -113,11 +113,14 @@ public class ShopManager { List lore = new ArrayList<>(); CMIMaterial mat = CMIMaterial.get(item.getIconMaterial()); + boolean hiddenLore = false; + if (item.isHideWithoutPerm()) { for (String onePerm : item.getRequiredPerm()) { if (!player.hasPermission(onePerm)) { mat = CMIMaterial.STONE_BUTTON; lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPermToBuy")); + hiddenLore = true; break; } } @@ -127,6 +130,7 @@ public class ShopManager { jPlayer.getTotalLevels() < item.getRequiredTotalLevels()) { mat = CMIMaterial.STONE_BUTTON; lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPoints")); + hiddenLore = true; } if (mat == CMIMaterial.NONE) @@ -142,48 +146,50 @@ public class ShopManager { if (item.getIconName() != null) meta.setDisplayName(item.getIconName()); - lore.addAll(item.getIconLore()); + if (!hiddenLore) { + lore.addAll(item.getIconLore()); - if (item.getPointPrice() > 0) { - String color = item.getPointPrice() >= points ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor"); - lore.add(Jobs.getLanguage().getMessage("command.shop.info.pointsPrice", "%currentpoints%", color + points, "%price%", item.getPointPrice())); - } - - if (item.getVaultPrice() > 0) { - String color = item.getVaultPrice() >= balance ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor"); - lore.add(Jobs.getLanguage().getMessage("command.shop.info.moneyPrice", "%currentbalance%", color + Jobs.getEconomy().getEconomy().format(balance), "%price%", item.getVaultPrice())); - } - - if (!item.getRequiredJobs().isEmpty()) { - lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobs")); - - for (Entry one : item.getRequiredJobs().entrySet()) { - Job job = Jobs.getJob(one.getKey()); - if (job == null) { - continue; - } - - String jobColor = ""; - String levelColor = ""; - - JobProgression prog = jPlayer.getJobProgression(job); - if (prog == null) { - jobColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsColor"); - levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor"); - } - - if (prog != null && prog.getLevel() < one.getValue()) - levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor"); - - lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobsList", "%jobsname%", - jobColor + one.getKey(), "%level%", levelColor + one.getValue())); + if (item.getPointPrice() > 0) { + String color = item.getPointPrice() >= points ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor"); + lore.add(Jobs.getLanguage().getMessage("command.shop.info.pointsPrice", "%currentpoints%", color + points, "%price%", item.getPointPrice())); } - } - if (item.getRequiredTotalLevels() != -1) { - lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevel", - "%totalLevel%", (jPlayer.getTotalLevels() < item.getRequiredTotalLevels() - ? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels())); + if (item.getVaultPrice() > 0) { + String color = item.getVaultPrice() >= balance ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor"); + lore.add(Jobs.getLanguage().getMessage("command.shop.info.moneyPrice", "%currentbalance%", color + Jobs.getEconomy().getEconomy().format(balance), "%price%", item.getVaultPrice())); + } + + if (!item.getRequiredJobs().isEmpty()) { + lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobs")); + + for (Entry one : item.getRequiredJobs().entrySet()) { + Job job = Jobs.getJob(one.getKey()); + if (job == null) { + continue; + } + + String jobColor = ""; + String levelColor = ""; + + JobProgression prog = jPlayer.getJobProgression(job); + if (prog == null) { + jobColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsColor"); + levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor"); + } + + if (prog != null && prog.getLevel() < one.getValue()) + levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor"); + + lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobsList", "%jobsname%", + jobColor + one.getKey(), "%level%", levelColor + one.getValue())); + } + } + + if (item.getRequiredTotalLevels() != -1) { + lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevel", + "%totalLevel%", (jPlayer.getTotalLevels() < item.getRequiredTotalLevels() + ? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels())); + } } meta.setLore(lore); @@ -497,6 +503,6 @@ public class ShopManager { } if (!list.isEmpty()) - Jobs.consoleMsg("&eLoaded &6" + list.size() + " &eshop items"); + CMIMessages.consoleMessage("&eLoaded &6" + list.size() + " &eshop items"); } } diff --git a/src/main/java/com/gamingmesh/jobs/config/TitleManager.java b/src/main/java/com/gamingmesh/jobs/config/TitleManager.java index d46b0293..cdae3322 100644 --- a/src/main/java/com/gamingmesh/jobs/config/TitleManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/TitleManager.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.container.Title; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.FileHandler.ConfigReader; +import net.Zrips.CMILib.Messages.CMIMessages; public class TitleManager { @@ -157,6 +158,6 @@ public class TitleManager { int size = titles.size(); if (size > 0) - Jobs.consoleMsg("&eLoaded &6" + size + " &etitles"); + CMIMessages.consoleMessage("&eLoaded &6" + size + " &etitles"); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java index b3f0a4b4..561e9aa3 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java +++ b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java @@ -2,13 +2,15 @@ package com.gamingmesh.jobs.container; import org.bukkit.util.Vector; +import net.Zrips.CMILib.Version.Schedulers.CMITask; + public class BlockProtection { private static long pre = (int) (System.currentTimeMillis() / 10000000000L) * 10000000000L; private int id = -1; - private int schedId = - 1; - private int time = -1; + private CMITask scheduler = null; + private int time = -1; private int recorded = -1; private DBAction action; private boolean paid = false; @@ -17,109 +19,109 @@ public class BlockProtection { private int z = 0; public BlockProtection(Vector pos) { - this(DBAction.INSERT, pos); + this(DBAction.INSERT, pos); } @Deprecated public BlockProtection(DBAction action, Vector pos) { - this(action, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + this(action, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); } public BlockProtection(DBAction action, int x, int y, int z) { - this.action = action; - if (action == DBAction.NONE) - action = null; - this.x = x; - this.y = y; - this.z = z; + this.action = action; + if (action == DBAction.NONE) + action = null; + this.x = x; + this.y = y; + this.z = z; } public long getTime() { - return deconvert(time); + return deconvert(time); } private static int convert(long time) { - return time == -1L ? -1 : (int) ((time - pre) / 1000L); + return time == -1L ? -1 : (int) ((time - pre) / 1000L); } private static long deconvert(int time) { - return time == -1 ? -1 : (time * 1000L) + pre; + return time == -1 ? -1 : (time * 1000L) + pre; } public void setTime(long time) { - this.time = time == -1 ? -1 : convert(time); - this.recorded = convert(System.currentTimeMillis()); + this.time = time == -1 ? -1 : convert(time); + this.recorded = convert(System.currentTimeMillis()); } public DBAction getAction() { - return action == null ? DBAction.NONE : action; + return action == null ? DBAction.NONE : action; } public void setAction(DBAction action) { - if (action == DBAction.NONE) - action = null; - this.action = action; + if (action == DBAction.NONE) + action = null; + this.action = action; } public long getRecorded() { - return deconvert(recorded); + return deconvert(recorded); } public boolean isPaid() { - return paid; + return paid; } public void setPaid(boolean paid) { - this.paid = paid; + this.paid = paid; } public void setRecorded(long recorded) { - this.recorded = convert(recorded); + this.recorded = convert(recorded); } public int getId() { - return id; + return id; } public void setId(int id) { - this.id = id; + this.id = id; } @Deprecated public Vector getPos() { - return new Vector(x, y, z); + return new Vector(x, y, z); } @Deprecated public void setPos(Vector pos) { - x = pos.getBlockX(); - y = pos.getBlockY(); - z = pos.getBlockZ(); + x = pos.getBlockX(); + y = pos.getBlockY(); + z = pos.getBlockZ(); } public void setPos(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; + this.x = x; + this.y = y; + this.z = z; } public int getX() { - return x; + return x; } public int getY() { - return y; + return y; } public int getZ() { - return z; + return z; } - public int getSchedId() { - return schedId; + public CMITask getScheduler() { + return scheduler; } - public void setSchedId(int schedId) { - this.schedId = schedId; + public void setScheduler(CMITask cmiTask) { + this.scheduler = cmiTask; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/Boost.java b/src/main/java/com/gamingmesh/jobs/container/Boost.java index 6a190d71..44e6b747 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Boost.java +++ b/src/main/java/com/gamingmesh/jobs/container/Boost.java @@ -12,94 +12,95 @@ public class Boost { private java.util.Map map = new HashMap<>(); public Boost() { - for (BoostOf one : BoostOf.values()) { - map.put(one, new BoostMultiplier()); - } + for (BoostOf one : BoostOf.values()) { + map.put(one, new BoostMultiplier()); + } } public void add(BoostOf boostoff, BoostMultiplier multiplier) { - map.put(boostoff, multiplier); + map.put(boostoff, multiplier); } public BoostMultiplier get(BoostOf boostOf) { - return map.getOrDefault(boostOf, new BoostMultiplier()); + return map.getOrDefault(boostOf, new BoostMultiplier()); } public double get(BoostOf boostOf, CurrencyType type) { - return get(boostOf, type, false); + return get(boostOf, type, false); } public double get(BoostOf boostOf, CurrencyType type, boolean percent) { - BoostMultiplier bm = map.get(boostOf); - if (bm == null) - return 0D; + BoostMultiplier bm = map.get(boostOf); + if (bm == null) + return 0D; - double r = bm.get(type); - if (r < -1) - r = -1; + double r = bm.get(type); + if (r < -1) + r = -1; - return percent ? (int) (r * 100) : r; + return percent ? (int) (r * 100) : r; } public double getFinal(CurrencyType type) { - return getFinal(type, false, false); + return getFinal(type, false, false); } public double getFinalAmount(CurrencyType type, double income) { - double f = income; + double f = income; - if (income > 0 || (income < 0 && Jobs.getGCManager().applyToNegativeIncome)) - f = income + income * getFinal(type, false, false); + if (income > 0 || (income < 0 && Jobs.getGCManager().applyToNegativeIncome)) + f = income + income * getFinal(type, false, false); - if (income > 0 && f < 0 || income < 0 && f > 0) - f = 0; + if (income > 0 && f < 0 || income < 0 && f > 0) + f = 0; - return f; + return f; } public double getFinal(CurrencyType type, boolean percent, boolean excludeExtra) { - double r = 0D; + double r = 0D; - for (BoostOf one : BoostOf.values()) { - BoostMultiplier bm = map.get(one); - if (bm == null) - continue; + for (BoostOf one : BoostOf.values()) { + BoostMultiplier bm = map.get(one); + if (bm == null) + continue; - if (one == BoostOf.NearSpawner || one == BoostOf.PetPay) - continue; + if (one == BoostOf.NearSpawner || one == BoostOf.PetPay) + continue; - if (bm.isValid(type)) - r += bm.get(type); - } + if (bm.isValid(type)) { + r += bm.get(type); + } + } - if (!excludeExtra) { - if (Jobs.getGCManager().multiplyBoostedExtraValues) { - BoostMultiplier bm = map.get(BoostOf.NearSpawner); - if (bm != null && bm.isValid(type) && bm.get(type) != 0) { - r = (r + 1) * (bm.get(type) + 1); - r -= 1; - } + if (!excludeExtra) { + if (Jobs.getGCManager().multiplyBoostedExtraValues) { + BoostMultiplier bm = map.get(BoostOf.NearSpawner); + if (bm != null && bm.isValid(type) && bm.get(type) != 0) { + r = (r + 1) * (bm.get(type) + 1); + r -= 1; + } - bm = map.get(BoostOf.PetPay); - if (bm != null && bm.isValid(type) && bm.get(type) != 0) { - r = (r + 1) * (bm.get(type) + 1); - r -= 1; - } - } else { - BoostMultiplier bm = map.get(BoostOf.NearSpawner); - if (bm != null && bm.isValid(type)) { - r += bm.get(type); - } - bm = map.get(BoostOf.PetPay); - if (bm != null && bm.isValid(type)) { - r += bm.get(type); - } - } - } + bm = map.get(BoostOf.PetPay); + if (bm != null && bm.isValid(type) && bm.get(type) != 0) { + r = (r + 1) * (bm.get(type) + 1); + r -= 1; + } + } else { + BoostMultiplier bm = map.get(BoostOf.NearSpawner); + if (bm != null && bm.isValid(type)) { + r += bm.get(type); + } + bm = map.get(BoostOf.PetPay); + if (bm != null && bm.isValid(type)) { + r += bm.get(type); + } + } + } - if (r < -1) - r = -1; + if (r < -1) + r = -1; - return percent ? (int) (r * 100) : r; + return percent ? (int) (r * 100) : r; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java b/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java index da6a834a..cf0edc26 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java +++ b/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java @@ -9,65 +9,68 @@ public class BoostMultiplier implements Cloneable { @Override public BoostMultiplier clone() { - BoostMultiplier boost = new BoostMultiplier(); - for (CurrencyType type : CurrencyType.values()) { - boost.add(type, map.get(type)); - } - return boost; + BoostMultiplier boost = new BoostMultiplier(); + for (CurrencyType type : CurrencyType.values()) { + boost.add(type, map.get(type)); + } + return boost; } public BoostMultiplier() { - for (CurrencyType one : CurrencyType.values()) { - map.put(one, 0D); - } + for (CurrencyType one : CurrencyType.values()) { + map.put(one, 0D); + } } public BoostMultiplier add(CurrencyType type, double amount) { - map.put(type, amount); - return this; + if (!Double.isNaN(amount)) + map.put(type, amount); + timers.remove(type); + return this; } public BoostMultiplier add(CurrencyType type, double amount, long time) { - timers.put(type, time); - return add(type, amount); + add(type, amount); + timers.put(type, time); + return this; } public BoostMultiplier add(double amount) { - if (amount != 0) { - for (CurrencyType one : CurrencyType.values()) { - map.put(one, amount); - } - } - return this; + if (amount != 0 && !Double.isNaN(amount)) { + for (CurrencyType one : CurrencyType.values()) { + map.put(one, amount); + } + } + return this; } public double get(CurrencyType type) { - if (!isValid(type)) - return 0D; - return map.getOrDefault(type, 0D); + if (!isValid(type)) + return 0D; + return map.getOrDefault(type, 0D); } public Long getTime(CurrencyType type) { - return timers.get(type); + return timers.get(type); } public boolean isValid(CurrencyType type) { - Long time = getTime(type); - if (time == null) - return true; + Long time = getTime(type); + if (time == null) + return true; - if (time < System.currentTimeMillis()) { - map.remove(type); - timers.remove(type); - return false; - } + if (time < System.currentTimeMillis()) { + map.remove(type); + timers.remove(type); + return false; + } - return true; + return true; } public void add(BoostMultiplier armorboost) { - for (CurrencyType one : CurrencyType.values()) { - map.put(one, get(one) + armorboost.get(one)); - } + for (CurrencyType one : CurrencyType.values()) { + map.put(one, get(one) + armorboost.get(one)); + } } } diff --git a/src/main/java/com/gamingmesh/jobs/container/BossBarInfo.java b/src/main/java/com/gamingmesh/jobs/container/BossBarInfo.java index e7ba1994..bb98e0ca 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BossBarInfo.java +++ b/src/main/java/com/gamingmesh/jobs/container/BossBarInfo.java @@ -1,13 +1,14 @@ package com.gamingmesh.jobs.container; -import org.bukkit.Bukkit; import org.bukkit.boss.BossBar; +import net.Zrips.CMILib.Version.Schedulers.CMITask; + public class BossBarInfo { private String jobName; private String PlayerName; private BossBar bar; - private int id = -1; + private CMITask scheduler = null; public BossBarInfo(String PlayerName, String jobName, BossBar bar) { this.PlayerName = PlayerName; @@ -15,14 +16,14 @@ public class BossBarInfo { this.bar = bar; } - public void setId(int id) { + public void setScheduler(CMITask cmiTask) { cancel(); - this.id = id; + this.scheduler = cmiTask; } public void cancel() { - if (id != -1) - Bukkit.getScheduler().cancelTask(this.id); + if (scheduler != null) + scheduler.cancel(); } public String getPlayerName() { diff --git a/src/main/java/com/gamingmesh/jobs/container/CurrencyLimit.java b/src/main/java/com/gamingmesh/jobs/container/CurrencyLimit.java index 5da39948..7d71d8dc 100644 --- a/src/main/java/com/gamingmesh/jobs/container/CurrencyLimit.java +++ b/src/main/java/com/gamingmesh/jobs/container/CurrencyLimit.java @@ -4,66 +4,104 @@ import java.util.ArrayList; import java.util.List; import net.Zrips.CMILib.Equations.Parser; +import net.Zrips.CMILib.Messages.CMIMessages; public class CurrencyLimit { private boolean enabled; private List stopWith; - private int timeLimit; + private int timeLimit = 0; + private resetTime resetsAt = null; private int announcementDelay; private Parser maxEquation; public CurrencyLimit(boolean enabled, List stopWith, int timeLimit, int announcementDelay, Parser maxEquation) { - this.enabled = enabled; - setStopWith(stopWith); - this.timeLimit = timeLimit; - this.announcementDelay = announcementDelay; + this.enabled = enabled; + setStopWith(stopWith); + this.timeLimit = timeLimit; + this.announcementDelay = announcementDelay; - setMaxEquation(maxEquation); + setMaxEquation(maxEquation); } public CurrencyLimit() { } public boolean isEnabled() { - return enabled; + return enabled; } public void setEnabled(boolean enabled) { - this.enabled = enabled; + this.enabled = enabled; } public List getStopWith() { - return stopWith; + return stopWith; } public void setStopWith(List stopWith) { - this.stopWith = stopWith == null ? new ArrayList<>() : stopWith; + this.stopWith = stopWith == null ? new ArrayList<>() : stopWith; } public int getTimeLimit() { - return timeLimit; + return timeLimit; } public void setTimeLimit(int timeLimit) { - this.timeLimit = timeLimit; + this.timeLimit = timeLimit; } public int getAnnouncementDelay() { - return announcementDelay; + return announcementDelay; } public void setAnnouncementDelay(int announcementDelay) { - this.announcementDelay = announcementDelay; + this.announcementDelay = announcementDelay; } public Parser getMaxEquation() { - return maxEquation; + return maxEquation; } public void setMaxEquation(Parser maxEquation) { - if (maxEquation != null) - this.maxEquation = maxEquation; + if (maxEquation != null) + this.maxEquation = maxEquation; } + public resetTime getResetsAt() { + + return resetsAt; + } + + public void setResetsAt(int hour, int minute, int second) { + this.resetsAt = new resetTime(hour, minute, second); + } + + public void setResetsAt(String resetsAt) { + + if (resetsAt.isEmpty()) + return; + + int hour = 0; + int minute = 0; + int second = 0; + + String[] split = resetsAt.split(":"); + try { + hour = Integer.parseInt(split[0]); + + if (split.length >= 2) { + minute = Integer.parseInt(split[1]); + } + if (split.length >= 3) { + second = Integer.parseInt(split[2]); + } + + } catch (Throwable e) { + CMIMessages.consoleMessage("Failed to recognize reset time as " + resetsAt); + return; + } + + setResetsAt(hour, minute, second); + } } diff --git a/src/main/java/com/gamingmesh/jobs/container/CurrencyType.java b/src/main/java/com/gamingmesh/jobs/container/CurrencyType.java index 88484c0d..a1537f35 100644 --- a/src/main/java/com/gamingmesh/jobs/container/CurrencyType.java +++ b/src/main/java/com/gamingmesh/jobs/container/CurrencyType.java @@ -18,6 +18,8 @@ package com.gamingmesh.jobs.container; +import com.gamingmesh.jobs.Jobs; + public enum CurrencyType { MONEY("Money", 1), EXP("Exp", 2), @@ -25,33 +27,46 @@ public enum CurrencyType { private String name; private int id = 0; + private boolean enabled = true; CurrencyType(String name, int id) { - this.name = name; - this.id = id; + this.name = name; + this.id = id; } public String getName() { - return name; + return name; } public static CurrencyType getByName(String name) { - for (CurrencyType one : values()) { - if (one.getName().equalsIgnoreCase(name)) - return one; - } - return null; + for (CurrencyType one : values()) { + if (one.getName().equalsIgnoreCase(name)) + return one; + } + return null; } public static CurrencyType get(int id) { - for (CurrencyType one : values()) { - if (one.getId() == id) - return one; - } - return null; + for (CurrencyType one : values()) { + if (one.getId() == id) + return one; + } + return null; } public int getId() { - return id; + return id; + } + + public String getDisplayName() { + return Jobs.getLanguage().getMessage("general.info.paymentType." + this.toString()); + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index 0d213fdb..cdf3a685 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -101,41 +101,41 @@ public class Job { @Deprecated public Job(String jobName, String jobDisplayName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, - int vipmaxLevel, Integer maxSlots, List jobPermissions, List jobCommands, List jobConditions, Map jobItems, - Map jobLimitedItems, List cmdOnJoin, List cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List worldBlacklist) { - this(jobName, jobDisplayName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel, - vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions, - jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, worldBlacklist); + int vipmaxLevel, Integer maxSlots, List jobPermissions, List jobCommands, List jobConditions, Map jobItems, + Map jobLimitedItems, List cmdOnJoin, List cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List worldBlacklist) { + this(jobName, jobDisplayName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel, + vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions, + jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, worldBlacklist); - this.jobItems = jobItems; - this.description = description; + this.jobItems = jobItems; + this.description = description; } public Job(String jobName, String jobDisplayName, String fullName, String jobShortName, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, - int vipmaxLevel, Integer maxSlots, List jobPermissions, List jobCommands, List jobConditions, - Map jobLimitedItems, List cmdOnJoin, List cmdOnLeave, ItemStack guiItem, int guiSlot, List worldBlacklist) { - this.jobName = jobName == null ? "" : jobName; - this.fullName = fullName == null ? "" : fullName; - this.jobShortName = jobShortName; - this.jobColour = jobColour; - this.maxExpEquation = maxExpEquation; - this.displayMethod = displayMethod; - this.maxLevel = maxLevel; - this.vipmaxLevel = vipmaxLevel; - this.maxSlots = maxSlots; - this.jobPermissions = jobPermissions; - this.jobCommands = jobCommands; - this.jobConditions = jobConditions; - this.jobLimitedItems = jobLimitedItems; - this.cmdOnJoin = cmdOnJoin; - this.cmdOnLeave = cmdOnLeave; - this.guiItem = guiItem; - this.guiSlot = guiSlot; - this.jobDisplayName = CMIChatColor.translate(jobDisplayName); + int vipmaxLevel, Integer maxSlots, List jobPermissions, List jobCommands, List jobConditions, + Map jobLimitedItems, List cmdOnJoin, List cmdOnLeave, ItemStack guiItem, int guiSlot, List worldBlacklist) { + this.jobName = jobName == null ? "" : jobName; + this.fullName = fullName == null ? "" : fullName; + this.jobShortName = jobShortName; + this.jobColour = jobColour; + this.maxExpEquation = maxExpEquation; + this.displayMethod = displayMethod; + this.maxLevel = maxLevel; + this.vipmaxLevel = vipmaxLevel; + this.maxSlots = maxSlots; + this.jobPermissions = jobPermissions; + this.jobCommands = jobCommands; + this.jobConditions = jobConditions; + this.jobLimitedItems = jobLimitedItems; + this.cmdOnJoin = cmdOnJoin; + this.cmdOnLeave = cmdOnLeave; + this.guiItem = guiItem; + this.guiSlot = guiSlot; + this.jobDisplayName = CMIChatColor.translate(jobDisplayName); - if (worldBlacklist != null) { - this.worldBlacklist = worldBlacklist; - } + if (worldBlacklist != null) { + this.worldBlacklist = worldBlacklist; + } } /** @@ -146,7 +146,7 @@ public class Job { * @param point the amount of boost to add */ public void addBoost(CurrencyType type, double point) { - boost.add(type, point); + boost.add(type, point); } /** @@ -163,20 +163,20 @@ public class Job { */ public void addBoost(CurrencyType type, double point, long duration) { - if (duration <= 0) { - addBoost(type, point); - return; - } + if (duration <= 0) { + addBoost(type, point); + return; + } - boost.add(type, point, System.currentTimeMillis() + (duration * 1000L)); + boost.add(type, point, System.currentTimeMillis() + (duration * 1000L)); } public void setBoost(BoostMultiplier boost) { - this.boost = boost; + this.boost = boost; } public BoostMultiplier getBoost() { - return boost; + return boost; } /** @@ -186,8 +186,8 @@ public class Job { * @return true if same */ public boolean isSame(Job job) { - return job != null && (id == job.getId() || jobName.equalsIgnoreCase(job.getName()) - || fullName.equalsIgnoreCase(job.getJobFullName()) || fullName.equalsIgnoreCase(job.getName())); + return job != null && (id == job.getId() || jobName.equalsIgnoreCase(job.getName()) + || fullName.equalsIgnoreCase(job.getJobFullName()) || fullName.equalsIgnoreCase(job.getName())); } /** @@ -196,66 +196,75 @@ public class Job { * @return the amount of total players in this job */ public int getTotalPlayers() { - if (totalPlayers == -1) { - updateTotalPlayers(); - } + if (totalPlayers == -1) { + updateTotalPlayers(); + } - return totalPlayers; + return totalPlayers; } /** * Updates the total players property from database synchronously. */ public void updateTotalPlayers() { - totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(jobName); + totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(jobName); - if (totalPlayers <= 0) { - totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(fullName); - } + if (totalPlayers <= 0) { + totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(fullName); + } - updateBonus(); + updateBonus(); } public void updateBonus() { - if (!Jobs.getGCManager().useDynamicPayment) - return; + if (!Jobs.getGCManager().useDynamicPayment) + return; - Parser eq = Jobs.getGCManager().DynamicPaymentEquation; - eq.setVariable("totalworkers", Jobs.getJobsDAO().getTotalPlayers()); - eq.setVariable("totaljobs", Jobs.getJobs().size()); - eq.setVariable("jobstotalplayers", getTotalPlayers()); + Parser eq = Jobs.getGCManager().DynamicPaymentEquation; + eq.setVariable("totalworkers", Jobs.getJobsDAO().getTotalPlayers()); + eq.setVariable("totaljobs", Jobs.getJobs().size()); + eq.setVariable("jobstotalplayers", getTotalPlayers()); - double now = eq.getValue(); - if (now > Jobs.getGCManager().DynamicPaymentMaxBonus) - now = Jobs.getGCManager().DynamicPaymentMaxBonus; + double now = 0D; + try { + now = eq.getValue(); + } catch (Throwable e) { + e.printStackTrace(); + } - if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty) - now = Jobs.getGCManager().DynamicPaymentMaxPenalty; + if (now > Jobs.getGCManager().DynamicPaymentMaxBonus) + now = Jobs.getGCManager().DynamicPaymentMaxBonus; - this.bonus = now; + if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty) + now = Jobs.getGCManager().DynamicPaymentMaxPenalty; + + if (Double.isNaN(now)) + now = 0; + + this.bonus = now; } public double getBonus() { - if (bonus == null) - updateBonus(); + if (bonus == null) + updateBonus(); - return bonus == null ? 0D : bonus; + return bonus == null ? 0D : bonus; } public List getCmdOnJoin() { - return cmdOnJoin; + return cmdOnJoin; } public List getCmdOnLeave() { - return cmdOnLeave; + return cmdOnLeave; } public ItemStack getGuiItem() { - return guiItem; + return guiItem; } public int getGuiSlot() { - return guiSlot; + return guiSlot; } /** @@ -264,7 +273,7 @@ public class Job { * @param info - the job info */ public void setJobInfo(ActionType type, List info) { - jobInfo.put(type, info); + jobInfo.put(type, info); } /** @@ -273,7 +282,7 @@ public class Job { * @return Job info list */ public List getJobInfo(ActionType type) { - return jobInfo.get(type); + return jobInfo.get(type); } /** @@ -281,41 +290,42 @@ public class Job { * @return Job info list */ public Map> getJobInfoList() { - return jobInfo; + return jobInfo; } public JobInfo getJobInfo(ActionInfo action, int level) { - BiPredicate condition = (jobInfo, actionInfo) -> { - if (actionInfo instanceof PotionItemActionInfo) { - String subName = ((PotionItemActionInfo) action).getNameWithSub(); - return jobInfo.getName().equalsIgnoreCase(subName) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(subName); - } + BiPredicate condition = (jobInfo, actionInfo) -> { + if (actionInfo instanceof PotionItemActionInfo) { + String subName = ((PotionItemActionInfo) action).getNameWithSub(); + return jobInfo.getName().equalsIgnoreCase(subName) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(subName); + } - if (actionInfo instanceof EnchantActionInfo) { - return Util.enchantMatchesActionInfo(jobInfo.getName(), (EnchantActionInfo) actionInfo); - } + if (actionInfo instanceof EnchantActionInfo) { + return Util.enchantMatchesActionInfo(jobInfo.getName(), (EnchantActionInfo) actionInfo); + } - return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) || - (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) || - jobInfo.getName().equalsIgnoreCase(action.getName()); - }; + return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) || + (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) || + jobInfo.getName().equalsIgnoreCase(action.getName()); + }; - String shortActionName = CMIMaterial.getGeneralMaterialName(action.getName()); - for (JobInfo info : getJobInfo(action.getType())) { - if (condition.test(info, action)) { - if (!info.isInLevelRange(level)) { - break; - } + String shortActionName = CMIMaterial.getGeneralMaterialName(action.getName()); + + for (JobInfo info : getJobInfo(action.getType())) { + if (condition.test(info, action)) { + if (!info.isInLevelRange(level)) { + break; + } - return info; - } + return info; + } - if ((shortActionName + ":ALL").equalsIgnoreCase(info.getName())) { - return info; - } - } + if ((shortActionName + ":ALL").equalsIgnoreCase(info.getName())) { + return info; + } + } - return null; + return null; } /** @@ -324,20 +334,20 @@ public class Job { * @return the name of this job */ public String getName() { - return jobName; + return jobName; } public String getJobFullName() { - return fullName; + return fullName; } @Deprecated public String getJobDisplayName() { - return getDisplayName(); + return getDisplayName(); } public String getDisplayName() { - return jobDisplayName == null ? jobColour + fullName : jobDisplayName; + return jobDisplayName == null ? jobColour + fullName : jobDisplayName; } /** @@ -348,7 +358,7 @@ public class Job { */ @Deprecated public String getNameWithColor() { - return jobColour + fullName; + return jobColour + fullName; } /** @@ -357,7 +367,7 @@ public class Job { * @return the shortened version of the jobName */ public String getShortName() { - return jobShortName; + return jobShortName; } /** @@ -369,7 +379,7 @@ public class Job { */ @Deprecated public String getDescription() { - return description; + return description; } /** @@ -377,7 +387,7 @@ public class Job { * @return the Color of the job for chat */ public CMIChatColor getChatColor() { - return jobColour; + return jobColour; } /** @@ -385,7 +395,7 @@ public class Job { * @return the MaxExpEquation of the job */ public Parser getMaxExpEquation() { - return maxExpEquation; + return maxExpEquation; } /** @@ -394,10 +404,10 @@ public class Job { * @return the correct max exp for this level */ public double getMaxExp(Map level) { - for (Map.Entry temp : level.entrySet()) { - maxExpEquation.setVariable(temp.getKey(), temp.getValue()); - } - return maxExpEquation.getValue(); + for (Map.Entry temp : level.entrySet()) { + maxExpEquation.setVariable(temp.getKey(), temp.getValue()); + } + return maxExpEquation.getValue(); } /** @@ -405,7 +415,7 @@ public class Job { * @return the display method */ public DisplayMethod getDisplayMethod() { - return displayMethod; + return displayMethod; } /** @@ -414,7 +424,7 @@ public class Job { * @return the max level */ public int getMaxLevel() { - return maxLevel; + return maxLevel; } /** @@ -424,20 +434,20 @@ public class Job { * @return the max level of player */ public int getMaxLevel(JobsPlayer player) { - return player == null ? maxLevel : player.getMaxJobLevelAllowed(this); + return player == null ? maxLevel : player.getMaxJobLevelAllowed(this); } public int getMaxLevel(CommandSender sender) { - if (sender == null) - return maxLevel; + if (sender == null) + return maxLevel; - if (sender instanceof Player) { - JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - if (player != null) - return player.getMaxJobLevelAllowed(this); - } + if (sender instanceof Player) { + JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + if (player != null) + return player.getMaxJobLevelAllowed(this); + } - return maxLevel > vipmaxLevel ? maxLevel : vipmaxLevel; + return maxLevel > vipmaxLevel ? maxLevel : vipmaxLevel; } /** @@ -446,7 +456,7 @@ public class Job { * @return null - no max level */ public int getVipMaxLevel() { - return vipmaxLevel; + return vipmaxLevel; } /** @@ -455,7 +465,7 @@ public class Job { * @return null - no max slots */ public Integer getMaxSlots() { - return maxSlots; + return maxSlots; } /** @@ -463,7 +473,7 @@ public class Job { * @return Permissions for this job */ public List getPermissions() { - return Collections.unmodifiableList(jobPermissions); + return Collections.unmodifiableList(jobPermissions); } /** @@ -471,7 +481,7 @@ public class Job { * @return Commands for this job */ public List getCommands() { - return Collections.unmodifiableList(jobCommands); + return Collections.unmodifiableList(jobCommands); } /** @@ -479,7 +489,7 @@ public class Job { * @return Conditions for this job */ public List getConditions() { - return Collections.unmodifiableList(jobConditions); + return Collections.unmodifiableList(jobConditions); } /** @@ -488,14 +498,14 @@ public class Job { */ @Deprecated public Map getItemBonus() { - if (jobItems == null) - jobItems = new HashMap(); - return jobItems; + if (jobItems == null) + jobItems = new HashMap(); + return jobItems; } @Deprecated public JobItems getItemBonus(String key) { - return jobItems.get(key.toLowerCase()); + return jobItems.get(key.toLowerCase()); } /** @@ -503,192 +513,192 @@ public class Job { * @return Limited items for this job */ public Map getLimitedItems() { - return jobLimitedItems; + return jobLimitedItems; } public JobLimitedItems getLimitedItems(String key) { - return jobLimitedItems.get(key.toLowerCase()); + return jobLimitedItems.get(key.toLowerCase()); } public String getBossbar() { - return bossbar; + return bossbar; } public void setBossbar(String bossbar) { - this.bossbar = bossbar; + this.bossbar = bossbar; } public Parser getMoneyEquation() { - return moneyEquation; + return moneyEquation; } public void setMoneyEquation(Parser moneyEquation) { - this.moneyEquation = moneyEquation; + this.moneyEquation = moneyEquation; } public Parser getXpEquation() { - return xpEquation; + return xpEquation; } public void setXpEquation(Parser xpEquation) { - this.xpEquation = xpEquation; + this.xpEquation = xpEquation; } public Parser getPointsEquation() { - return pointsEquation; + return pointsEquation; } public void setPointsEquation(Parser pointsEquation) { - this.pointsEquation = pointsEquation; + this.pointsEquation = pointsEquation; } public Long getRejoinCd() { - return rejoinCd; + return rejoinCd; } public void setRejoinCd(Long rejoinCd) { - this.rejoinCd = rejoinCd; + this.rejoinCd = rejoinCd; } public List getFullDescription() { - return fDescription; + return fDescription; } public void setFullDescription(List fDescription) { - this.fDescription.clear(); + this.fDescription.clear(); - if (fDescription != null) { - this.fDescription.addAll(fDescription); - this.description = String.join("\n", this.fDescription); - } + if (fDescription != null) { + this.fDescription.addAll(fDescription); + this.description = String.join("\n", this.fDescription); + } } public void setMaxLevelCommands(List commands) { - maxLevelCommands.clear(); + maxLevelCommands.clear(); - if (commands != null) { - maxLevelCommands.addAll(commands); - } + if (commands != null) { + maxLevelCommands.addAll(commands); + } } public List getMaxLevelCommands() { - return maxLevelCommands; + return maxLevelCommands; } public List getQuests() { - return quests; + return quests; } public Quest getQuest(String name) { - if (name == null || name.trim().isEmpty()) { - return null; - } + if (name == null || name.trim().isEmpty()) { + return null; + } - for (Quest one : quests) { - if (one.getConfigName().equalsIgnoreCase(name)) - return one; - } + for (Quest one : quests) { + if (one.getConfigName().equalsIgnoreCase(name)) + return one; + } - return null; + return null; } public void setQuests(List quests) { - this.quests.clear(); + this.quests.clear(); - if (quests != null) { - this.quests.addAll(quests); - } + if (quests != null) { + this.quests.addAll(quests); + } } public Quest getNextQuest(List excludeQuests, Integer level) { - List ls = new ArrayList<>(quests); - Collections.shuffle(ls); + List ls = new ArrayList<>(quests); + Collections.shuffle(ls); - int i = 0; - while (true) { - i++; + int i = 0; + while (true) { + i++; - int target = new Random(System.nanoTime()).nextInt(100); - for (Quest one : ls) { - if (one.isEnabled() && one.getChance() >= target && (excludeQuests == null || !excludeQuests.contains(one.getConfigName().toLowerCase())) - && one.isInLevelRange(level)) { - return one; - } - } + int target = new Random(System.nanoTime()).nextInt(100); + for (Quest one : ls) { + if (one.isEnabled() && one.getChance() >= target && (excludeQuests == null || !excludeQuests.contains(one.getConfigName().toLowerCase())) + && one.isInLevelRange(level)) { + return one; + } + } - if (i > 20) - return null; - } + if (i > 20) + return null; + } } public int getMaxDailyQuests() { - return maxDailyQuests; + return maxDailyQuests; } public void setMaxDailyQuests(int maxDailyQuests) { - this.maxDailyQuests = maxDailyQuests; + this.maxDailyQuests = maxDailyQuests; } public int getId() { - return id; + return id; } public void setId(int id) { - this.id = id; + this.id = id; } public List getWorldBlacklist() { - return worldBlacklist; + return worldBlacklist; } public boolean isWorldBlackListed(Entity ent) { - return isWorldBlackListed(null, ent); + return isWorldBlackListed(null, ent); } public boolean isWorldBlackListed(Block block) { - return isWorldBlackListed(block, null); + return isWorldBlackListed(block, null); } public boolean isWorldBlackListed(Block block, Entity ent) { - if (worldBlacklist.isEmpty()) - return reversedWorldBlacklist; + if (worldBlacklist.isEmpty()) + return reversedWorldBlacklist; - if (block != null) - return worldBlacklist.contains(block.getWorld().getName()) != reversedWorldBlacklist; + if (block != null) + return worldBlacklist.contains(block.getWorld().getName()) != reversedWorldBlacklist; - return ent != null && worldBlacklist.contains(ent.getWorld().getName()) != reversedWorldBlacklist; + return ent != null && worldBlacklist.contains(ent.getWorld().getName()) != reversedWorldBlacklist; } public boolean isReversedWorldBlacklist() { - return reversedWorldBlacklist; + return reversedWorldBlacklist; } public void setReversedWorldBlacklist(boolean reversedWorldBlacklist) { - this.reversedWorldBlacklist = reversedWorldBlacklist; + this.reversedWorldBlacklist = reversedWorldBlacklist; } public boolean isIgnoreMaxJobs() { - return ignoreMaxJobs; + return ignoreMaxJobs; } public void setIgnoreMaxJobs(boolean ignoreMaxJobs) { - this.ignoreMaxJobs = ignoreMaxJobs; + this.ignoreMaxJobs = ignoreMaxJobs; } @Override public boolean equals(Object obj) { - return obj instanceof Job && isSame((Job) obj); + return obj instanceof Job && isSame((Job) obj); } public void setJobDisplayName(String jobDisplayName) { - this.jobDisplayName = jobDisplayName; + this.jobDisplayName = jobDisplayName; } public int getLegacyId() { - return legacyId; + return legacyId; } public void setLegacyId(int legacyId) { - this.legacyId = legacyId; + this.legacyId = legacyId; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobInfo.java b/src/main/java/com/gamingmesh/jobs/container/JobInfo.java index 4e2c639b..4c8cc33c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobInfo.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobInfo.java @@ -38,127 +38,127 @@ public class JobInfo { private Integer softIncomeLevelLimit, softExpLevelLimit, softPointsLevelLimit; public JobInfo(ActionType actionType, int id, String meta, String name, double baseIncome, Parser moneyEquation, double baseXp, Parser xpEquation, - Parser pointsEquation, double basePoints, int fromLevel, int untilLevel, String configPath) { - this(actionType, id, meta, name, baseIncome, moneyEquation, baseXp, xpEquation, pointsEquation, basePoints, fromLevel, untilLevel, configPath, null, null, null); + Parser pointsEquation, double basePoints, int fromLevel, int untilLevel, String configPath) { + this(actionType, id, meta, name, baseIncome, moneyEquation, baseXp, xpEquation, pointsEquation, basePoints, fromLevel, untilLevel, configPath, null, null, null); } public JobInfo(ActionType actionType, int id, String meta, String name, double baseIncome, Parser moneyEquation, double baseXp, Parser xpEquation, - Parser pointsEquation, double basePoints, int fromLevel, int untilLevel, String configPath, Integer softIncomeLevelLimit, Integer softExpLevelLimit, Integer softPointsLevelLimit) { - this.actionType = actionType; - this.id = id; - this.meta = meta; - this.name = name; - this.baseIncome = baseIncome; - this.moneyEquation = moneyEquation; - this.pointsEquation = pointsEquation; - this.basePoints = basePoints; - this.baseXp = baseXp; - this.xpEquation = xpEquation; - this.fromLevel = fromLevel; - this.untilLevel = untilLevel; - this.configPath = configPath; - this.softIncomeLevelLimit = softIncomeLevelLimit; - this.softExpLevelLimit = softExpLevelLimit; - this.softPointsLevelLimit = softPointsLevelLimit; + Parser pointsEquation, double basePoints, int fromLevel, int untilLevel, String configPath, Integer softIncomeLevelLimit, Integer softExpLevelLimit, Integer softPointsLevelLimit) { + this.actionType = actionType; + this.id = id; + this.meta = meta; + this.name = name; + this.baseIncome = baseIncome; + this.moneyEquation = moneyEquation; + this.pointsEquation = pointsEquation; + this.basePoints = basePoints; + this.baseXp = baseXp; + this.xpEquation = xpEquation; + this.fromLevel = fromLevel; + this.untilLevel = untilLevel; + this.configPath = configPath; + this.softIncomeLevelLimit = softIncomeLevelLimit; + this.softExpLevelLimit = softExpLevelLimit; + this.softPointsLevelLimit = softPointsLevelLimit; } public int getFromLevel() { - return fromLevel; + return fromLevel; } public int getUntilLevel() { - return untilLevel; + return untilLevel; } public boolean isInLevelRange(int level) { - return level >= fromLevel && (level <= untilLevel || untilLevel == -1); + return level >= fromLevel && (level <= untilLevel || untilLevel == -1); } public String getName() { - return name; + return name; } public String getRealisticName() { - String materialName = name.toLowerCase().replace('_', ' '); - materialName = Character.toUpperCase(materialName.charAt(0)) + materialName.substring(1); - materialName = Jobs.getNameTranslatorManager().translate(actionType == ActionType.MMKILL ? name : materialName, this); - materialName = CMIChatColor.translate(materialName); - return materialName; + String materialName = name.toLowerCase().replace('_', ' '); + materialName = Character.toUpperCase(materialName.charAt(0)) + materialName.substring(1); + materialName = Jobs.getNameTranslatorManager().translate(actionType == ActionType.MMKILL ? name : materialName, this); + materialName = CMIChatColor.translate(materialName); + return materialName; } public int getId() { - return id; + return id; } public ActionType getActionType() { - return actionType; + return actionType; } public String getMeta() { - return meta; + return meta; } public double getBaseIncome() { - return baseIncome; + return baseIncome; } public double getBaseXp() { - return baseXp; + return baseXp; } public double getBasePoints() { - return basePoints; + return basePoints; } public double getIncome(double level, int numjobs, int maxJobs) { - if (softIncomeLevelLimit != null && level > softIncomeLevelLimit) - level = softIncomeLevelLimit; - if (baseIncome == 0 || !Jobs.getGCManager().PaymentMethodsMoney) - return 0; - moneyEquation.setVariable("joblevel", level); - moneyEquation.setVariable("numjobs", numjobs); - moneyEquation.setVariable("maxjobs", maxJobs); - moneyEquation.setVariable("baseincome", baseIncome); - return moneyEquation.getValue(); + if (softIncomeLevelLimit != null && level > softIncomeLevelLimit) + level = softIncomeLevelLimit; + if (baseIncome == 0 || !CurrencyType.MONEY.isEnabled()) + return 0; + moneyEquation.setVariable("joblevel", level); + moneyEquation.setVariable("numjobs", numjobs); + moneyEquation.setVariable("maxjobs", maxJobs); + moneyEquation.setVariable("baseincome", baseIncome); + return moneyEquation.getValue(); } public double getExperience(double level, int numjobs, int maxJobs) { - if (softExpLevelLimit != null && level > softExpLevelLimit) - level = softExpLevelLimit; - if (baseXp == 0 || !Jobs.getGCManager().PaymentMethodsExp) - return 0; - xpEquation.setVariable("joblevel", level); - xpEquation.setVariable("numjobs", numjobs); - xpEquation.setVariable("maxjobs", maxJobs); - xpEquation.setVariable("baseexperience", baseXp); - return xpEquation.getValue(); + if (softExpLevelLimit != null && level > softExpLevelLimit) + level = softExpLevelLimit; + if (baseXp == 0 || !CurrencyType.EXP.isEnabled()) + return 0; + xpEquation.setVariable("joblevel", level); + xpEquation.setVariable("numjobs", numjobs); + xpEquation.setVariable("maxjobs", maxJobs); + xpEquation.setVariable("baseexperience", baseXp); + return xpEquation.getValue(); } public double getPoints(double level, int numjobs, int maxJobs) { - if (softPointsLevelLimit != null && level > softPointsLevelLimit) - level = softPointsLevelLimit; - if (basePoints == 0 || !Jobs.getGCManager().PaymentMethodsPoints) - return 0; - pointsEquation.setVariable("joblevel", level); - pointsEquation.setVariable("numjobs", numjobs); - pointsEquation.setVariable("maxjobs", maxJobs); - pointsEquation.setVariable("basepoints", basePoints); - return pointsEquation.getValue(); + if (softPointsLevelLimit != null && level > softPointsLevelLimit) + level = softPointsLevelLimit; + if (basePoints == 0 || !CurrencyType.POINTS.isEnabled()) + return 0; + pointsEquation.setVariable("joblevel", level); + pointsEquation.setVariable("numjobs", numjobs); + pointsEquation.setVariable("maxjobs", maxJobs); + pointsEquation.setVariable("basepoints", basePoints); + return pointsEquation.getValue(); } public String getConfigPath() { - return configPath; + return configPath; } public void setBaseIncome(double baseIncome) { - this.baseIncome = baseIncome; + this.baseIncome = baseIncome; } public void setBaseXp(double baseXp) { - this.baseXp = baseXp; + this.baseXp = baseXp; } public void setBasePoints(double basePoints) { - this.basePoints = basePoints; + this.basePoints = basePoints; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobProgression.java b/src/main/java/com/gamingmesh/jobs/container/JobProgression.java index 6cce09dc..247e3ac9 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobProgression.java @@ -22,9 +22,9 @@ import java.util.HashMap; import java.util.Map; import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.Util; +import net.Zrips.CMILib.Container.CMINumber; import net.Zrips.CMILib.Time.CMITimeManager; public class JobProgression { @@ -146,7 +146,7 @@ public class JobProgression { */ public String getLevelFormatted() { if (Jobs.getGCManager().RomanNumbers) - return Util.toRoman(level); + return CMINumber.toRoman(level); return String.valueOf(level); } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 126fc30a..0a51170f 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -47,6 +47,8 @@ import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Time.CMITimeManager; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; +import net.Zrips.CMILib.Version.Schedulers.CMITask; public class JobsPlayer { @@ -1347,14 +1349,14 @@ public class JobsPlayer { this.doneQuests = doneQuests; } - private Integer questSignUpdateShed; + private CMITask questSignUpdateShed; public void addDoneQuest(final Job job) { doneQuests++; setSaved(false); if (questSignUpdateShed == null) { - questSignUpdateShed = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { + questSignUpdateShed = CMIScheduler.get().runTaskLater(() -> { Jobs.getSignUtil().signUpdate(job, SignTopType.questtoplist); questSignUpdateShed = null; }, Jobs.getGCManager().getSavePeriod() * 60 * 20L); diff --git a/src/main/java/com/gamingmesh/jobs/container/Log.java b/src/main/java/com/gamingmesh/jobs/container/Log.java index cec97c5a..998c54b8 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Log.java +++ b/src/main/java/com/gamingmesh/jobs/container/Log.java @@ -3,7 +3,7 @@ package com.gamingmesh.jobs.container; import java.util.HashMap; import java.util.Map; -import com.gamingmesh.jobs.stuff.TimeManage; +import net.Zrips.CMILib.Time.CMITimeManager; public final class Log { @@ -36,7 +36,7 @@ public final class Log { } public void setDate() { - this.day = TimeManage.timeInInt(); + this.day = CMITimeManager.timeInInt(); } public int getDate() { diff --git a/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java b/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java index 77258061..c7c886d9 100644 --- a/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java +++ b/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java @@ -26,6 +26,7 @@ public class PlayerPoints { public void takePoints(double points) { current -= points; + total -= points; } public boolean havePoints(double points) { diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index 4e59859e..687bb535 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -4,15 +4,12 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import com.gamingmesh.jobs.actions.EnchantActionInfo; -import com.gamingmesh.jobs.stuff.Util; - -import net.Zrips.CMILib.Logs.CMIDebug; - import org.bukkit.Bukkit; import org.bukkit.event.server.ServerCommandEvent; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.actions.EnchantActionInfo; +import com.gamingmesh.jobs.stuff.Util; public class QuestProgression { @@ -160,22 +157,24 @@ public class QuestProgression { } } + boolean completed = isCompleted(); + Job questJob = quest.getJob(); - if (questJob != null) { + if (questJob != null && completed) { int maxQuest = jPlayer.getPlayerMaxQuest(questJob.getName()); if (maxQuest > 0 && jPlayer.getDoneQuests() >= maxQuest) { return; } } - if (!isCompleted() && - objective != null) { + if (!completed && objective != null) { Integer old = done.getOrDefault(objective, 0); done.put(objective, old < objective.getAmount() ? old + 1 : objective.getAmount()); } jPlayer.setSaved(false); + //needs to re-call isCompleted() because it might have changed above. if (!isCompleted() || !player.isOnline() || givenReward) return; diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index 8ae0fbe3..2717f1d5 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -24,6 +24,7 @@ import com.gamingmesh.jobs.stuff.blockLoc; import net.Zrips.CMILib.Container.CMILocation; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Messages.CMIMessages; public class BlockOwnerShip { @@ -380,7 +381,7 @@ public class BlockOwnerShip { } if (total > 0) { - Jobs.consoleMsg("&eLoaded &6" + total + " " + path.toLowerCase() + " &efor reassigning."); + CMIMessages.consoleMessage("&eLoaded &6" + total + " " + path.toLowerCase() + " &efor reassigning."); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/resetTime.java b/src/main/java/com/gamingmesh/jobs/container/resetTime.java new file mode 100644 index 00000000..614e4a7c --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/container/resetTime.java @@ -0,0 +1,58 @@ +package com.gamingmesh.jobs.container; + +import java.util.Calendar; +import java.util.Date; + +public class resetTime { + + private int hour = 0; + private int minute = 0; + private int second = 0; + + public resetTime(int hour, int minute, int second) { + this.hour = hour % 24; + this.minute = minute % 60; + this.second = second % 60; + } + + public int getHour() { + return hour; + } + + public void setHour(int hour) { + this.hour = hour; + } + + public int getMinute() { + return minute; + } + + public void setMinute(int minute) { + this.minute = minute; + } + + public int getSecond() { + return second; + } + + public void setSecond(int second) { + this.second = second; + } + + public long toMili() { + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + calendar.set(Calendar.SECOND, second); + + if (calendar.getTimeInMillis() < System.currentTimeMillis()) { + calendar.add(Calendar.DAY_OF_YEAR, 1); + } + + return calendar.getTimeInMillis(); + } + +} diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 191832f7..d5ab5b50 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -41,10 +41,11 @@ import com.gamingmesh.jobs.container.PlayerPoints; import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.dao.JobsManager.DataBaseType; import com.gamingmesh.jobs.economy.PaymentData; -import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.Time.CMITimeManager; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public abstract class JobsDAO { @@ -819,7 +820,7 @@ public abstract class JobsDAO { PreparedStatement prest = null; ResultSet res = null; try { - int time = TimeManage.timeInInt(); + int time = CMITimeManager.timeInInt(); prest = conn.prepareStatement("SELECT * FROM `" + DBTables.LogTable.getTableName() + "` WHERE `" + LogTableFields.time.getCollumn() + "` = ? ;"); prest.setInt(1, time); res = prest.executeQuery(); @@ -1016,10 +1017,10 @@ public abstract class JobsDAO { public void triggerTableIdUpdate() { // Lets convert old fields if (!converted) { - Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> { - Jobs.consoleMsg("&6[Jobs] Converting to new database format"); + CMIScheduler.get().runTaskLater(() -> { + CMIMessages.consoleMessage("&6[Jobs] Converting to new database format"); convertID(); - Jobs.consoleMsg("&6[Jobs] Converted to new database format"); + CMIMessages.consoleMessage("&6[Jobs] Converted to new database format"); converted = true; }, 60L); } @@ -2311,7 +2312,7 @@ public abstract class JobsDAO { PreparedStatement prest = null; ResultSet res = null; try { - int time = TimeManage.timeInInt(); + int time = CMITimeManager.timeInInt(); prest = conn.prepareStatement("SELECT * FROM `" + DBTables.LogTable.getTableName() + "` WHERE `" + LogTableFields.userid.getCollumn() + "` = ? AND `" + LogTableFields.time.getCollumn() + "` = ? ;"); prest.setInt(1, player.getUserId()); @@ -2508,12 +2509,12 @@ public abstract class JobsDAO { i++; if (ii++ >= 100000) { - Jobs.consoleMsg("&6[Jobs] Loading (" + i + ") BP"); + CMIMessages.consoleMessage("&6[Jobs] Loading (" + i + ") BP"); ii = 0; } } if (i > 0) { - Jobs.consoleMsg("&e[Jobs] Loaded " + i + " block protection entries. " + (System.currentTimeMillis() - timer) + "ms"); + CMIMessages.consoleMessage("&e[Jobs] Loaded " + i + " block protection entries. " + (System.currentTimeMillis() - timer) + "ms"); } } catch (SQLException e) { e.printStackTrace(); @@ -2577,7 +2578,7 @@ public abstract class JobsDAO { conn.setAutoCommit(true); if (i > 0) - Jobs.consoleMsg("&e[Jobs] Saved " + i + " new explorer entries."); + CMIMessages.consoleMessage("&e[Jobs] Saved " + i + " new explorer entries."); } catch (SQLException e) { e.printStackTrace(); } finally { @@ -2624,7 +2625,7 @@ public abstract class JobsDAO { conn.setAutoCommit(true); if (i > 0) - Jobs.consoleMsg("&e[Jobs] Updated " + i + " explorer entries."); + CMIMessages.consoleMessage("&e[Jobs] Updated " + i + " explorer entries."); } catch (SQLException e) { e.printStackTrace(); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java b/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java index 5071a0c3..cb47de79 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java @@ -6,7 +6,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.LoadStatus; import net.Zrips.CMILib.FileHandler.ConfigReader; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Messages.CMIMessages; public class JobsManager { private JobsDAO dao; @@ -70,9 +70,9 @@ public class JobsManager { public void start() { if (Jobs.getJobsDAO() != null) { - Jobs.consoleMsg("&eClosing existing database connection..."); + CMIMessages.consoleMessage("&eClosing existing database connection..."); Jobs.getJobsDAO().closeConnections(); - Jobs.consoleMsg("&eClosed"); + CMIMessages.consoleMessage("&eClosed"); } ConfigReader c = Jobs.getGCManager().getConfig(); @@ -100,7 +100,7 @@ public class JobsManager { } } else { if (!storageMethod.equalsIgnoreCase("sqlite")) { - Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!"); + CMIMessages.consoleMessage("&cInvalid storage method! Changing method to sqlite!"); c.set("storage.method", "sqlite"); } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java index fa84c7c6..61856d49 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java @@ -8,7 +8,7 @@ import java.sql.Statement; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.dao.JobsManager.DataBaseType; -import net.Zrips.CMILib.Logs.CMIDebug; +import net.Zrips.CMILib.Messages.CMIMessages; public class JobsMySQL extends JobsDAO { @@ -52,7 +52,7 @@ public class JobsMySQL extends JobsDAO { protected void checkUpdate() throws SQLException { JobsConnection conn = getConnection(); if (conn == null) { - Jobs.consoleMsg("&cCould not run database updates! Could not connect to MySQL!"); + CMIMessages.consoleMessage("&cCould not run database updates! Could not connect to MySQL!"); return; } @@ -77,7 +77,7 @@ public class JobsMySQL extends JobsDAO { @Override public boolean createTable(String query) { if (query == null || query.isEmpty()) { - Jobs.consoleMsg("&cCould not create table: query is empty or null."); + CMIMessages.consoleMessage("&cCould not create table: query is empty or null."); return false; } JobsConnection conn = getConnection(); @@ -88,7 +88,7 @@ public class JobsMySQL extends JobsDAO { statement = conn.createStatement(); statement.execute(query); } catch (SQLException e) { - Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not create table, SQLException: " + e.getMessage()); return false; } finally { close(statement); @@ -111,7 +111,7 @@ public class JobsMySQL extends JobsDAO { tables.close(); return false; } catch (SQLException e) { - Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|"); + CMIMessages.consoleMessage("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|"); } PreparedStatement insert = null; @@ -125,7 +125,7 @@ public class JobsMySQL extends JobsDAO { return true; } } catch (SQLException e) { - Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|"); + CMIMessages.consoleMessage("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|"); } finally { close(res); close(insert); @@ -140,14 +140,14 @@ public class JobsMySQL extends JobsDAO { try { statement = getConnection().createStatement(); } catch (SQLException e) { - Jobs.consoleMsg("&cCould not check if its collumn, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not check if its collumn, SQLException: " + e.getMessage()); return false; } try { statement.executeQuery("SELECT `" + collumn + "` FROM `" + table + "`;"); return true; } catch (SQLException e) { - Jobs.consoleMsg("Not a collumn |" + "SELECT " + collumn + " FROM " + table + "|"); + CMIMessages.consoleMessage("Not a collumn |" + "SELECT " + collumn + " FROM " + table + "|"); return false; } finally { close(statement); @@ -160,11 +160,11 @@ public class JobsMySQL extends JobsDAO { try { statement = getConnection().createStatement(); } catch (SQLException e) { - Jobs.consoleMsg("&cCould not add new collumn, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not add new collumn, SQLException: " + e.getMessage()); return false; } try { - Jobs.consoleMsg("Creating collumn |" + "ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";" + "|"); + CMIMessages.consoleMessage("Creating collumn |" + "ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";" + "|"); statement.executeUpdate("ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";"); return true; } catch (SQLException e) { @@ -179,14 +179,14 @@ public class JobsMySQL extends JobsDAO { Statement statement = null; try { if (!isTable(table)) { - Jobs.consoleMsg("&cTable \"" + table + "\" does not exist."); + CMIMessages.consoleMessage("&cTable \"" + table + "\" does not exist."); return false; } statement = getConnection().createStatement(); statement.executeUpdate("DELETE FROM " + table + ";"); return true; } catch (SQLException e) { - Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not wipe table, SQLException: " + e.getMessage()); e.printStackTrace(); return false; } finally { @@ -199,14 +199,14 @@ public class JobsMySQL extends JobsDAO { Statement statement = null; try { if (!isTable(table)) { - Jobs.consoleMsg("&cTable \"" + table + "\" does not exist."); + CMIMessages.consoleMessage("&cTable \"" + table + "\" does not exist."); return false; } statement = getConnection().createStatement(); statement.executeUpdate("DROP TABLE IF EXISTS `" + table + "`;"); return true; } catch (SQLException e) { - Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not wipe table, SQLException: " + e.getMessage()); e.printStackTrace(); return false; } finally { diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java b/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java index aafc7d59..537931f6 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java @@ -8,6 +8,8 @@ import java.sql.Statement; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.dao.JobsManager.DataBaseType; +import net.Zrips.CMILib.Messages.CMIMessages; + public class JobsSQLite extends JobsDAO { public void initialize() { @@ -32,7 +34,7 @@ public class JobsSQLite extends JobsDAO { protected void checkUpdate() throws SQLException { JobsConnection conn = getConnection(); if (conn == null) { - Jobs.consoleMsg("&cCould not run database updates! Could not connect to MySQL!"); + CMIMessages.consoleMessage("&cCould not run database updates! Could not connect to MySQL!"); return; } @@ -59,7 +61,7 @@ public class JobsSQLite extends JobsDAO { Statement statement = null; try { if (query == null || query.isEmpty()) { - Jobs.consoleMsg("&cCould not create table: query is empty or null."); + CMIMessages.consoleMessage("&cCould not create table: query is empty or null."); return false; } @@ -67,7 +69,7 @@ public class JobsSQLite extends JobsDAO { statement.execute(query); return true; } catch (SQLException e) { - Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not create table, SQLException: " + e.getMessage()); return false; } finally { close(statement); @@ -85,7 +87,7 @@ public class JobsSQLite extends JobsDAO { tables.close(); return false; } catch (SQLException e) { - Jobs.consoleMsg("&cCould not check if table \"" + table + "\" exists, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not check if table \"" + table + "\" exists, SQLException: " + e.getMessage()); return false; } } @@ -101,7 +103,7 @@ public class JobsSQLite extends JobsDAO { tables.close(); return false; } catch (SQLException e) { - Jobs.consoleMsg("&cCould not check if table \"" + table + "\" exists, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not check if table \"" + table + "\" exists, SQLException: " + e.getMessage()); return false; } } @@ -112,7 +114,7 @@ public class JobsSQLite extends JobsDAO { try { statement = getConnection().createStatement(); } catch (SQLException e) { - Jobs.consoleMsg("&cCould not add new collumn, SQLException: " + e.getMessage()); + CMIMessages.consoleMessage("&cCould not add new collumn, SQLException: " + e.getMessage()); return false; } try { @@ -130,7 +132,7 @@ public class JobsSQLite extends JobsDAO { Statement statement = null; try { if (!isTable(table)) { - Jobs.consoleMsg("&cTable \"" + table + "\" does not exist."); + CMIMessages.consoleMessage("&cTable \"" + table + "\" does not exist."); return false; } statement = getConnection().createStatement(); @@ -139,7 +141,7 @@ public class JobsSQLite extends JobsDAO { } catch (SQLException e) { if (!(e.getMessage().toLowerCase().contains("locking") || e.getMessage().toLowerCase().contains("locked")) && !e.toString().contains("not return ResultSet")) - Jobs.consoleMsg("&cError in wipeTable() query: " + e); + CMIMessages.consoleMessage("&cError in wipeTable() query: " + e); return false; } finally { close(statement); @@ -151,7 +153,7 @@ public class JobsSQLite extends JobsDAO { Statement statement = null; try { if (!isTable(table)) { - Jobs.consoleMsg("&cTable \"" + table + "\" does not exist."); + CMIMessages.consoleMessage("&cTable \"" + table + "\" does not exist."); return false; } statement = getConnection().createStatement(); @@ -160,7 +162,7 @@ public class JobsSQLite extends JobsDAO { } catch (SQLException e) { if (!(e.getMessage().toLowerCase().contains("locking") || e.getMessage().toLowerCase().contains("locked")) && !e.toString().contains("not return ResultSet")) - Jobs.consoleMsg("&cError in dropTable() query: " + e); + CMIMessages.consoleMessage("&cError in dropTable() query: " + e); return false; } finally { close(statement); diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 2658850b..bc74333d 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -38,6 +38,7 @@ import com.gamingmesh.jobs.tasks.BufferedPaymentTask; import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class BufferedEconomy { @@ -208,9 +209,9 @@ public class BufferedEconomy { } if (Jobs.getGCManager().isEconomyAsync()) - Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i); + CMIScheduler.get().runLaterAsync(new BufferedPaymentTask(this, economy, payment), i); else - Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i); + CMIScheduler.get().runTaskLater(new BufferedPaymentTask(this, economy, payment), i); // Show players payment stuff showPayment(payment); diff --git a/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java b/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java index a86babe4..073c028c 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java @@ -1,57 +1,94 @@ package com.gamingmesh.jobs.economy; +import java.util.Calendar; +import java.util.Date; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyType; public class LimitsData { private CurrencyType type = null; private double amount = 0D; private long paymentsTime = 0L; + private long resetsAt = 0L; private boolean reseted = false; + @Deprecated public LimitsData(CurrencyType type, long paymentsTime) { - this(type, paymentsTime, 0D); + this(type, paymentsTime, 0D); } + @Deprecated public LimitsData(CurrencyType type, long paymentsTime, double payment) { - this.type = type; - this.paymentsTime = paymentsTime; - this.amount = payment; + this.type = type; + this.paymentsTime = paymentsTime; + CurrencyLimit limit = Jobs.getGCManager().getLimit(type); + if (limit.getResetsAt() != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + resetsAt = limit.getResetsAt().toMili(); + } else + resetsAt = (limit.getTimeLimit() * 100L) + System.currentTimeMillis(); + this.amount = payment; + } + + public LimitsData(CurrencyType type, double payment) { + this.type = type; + this.paymentsTime = System.currentTimeMillis(); + CurrencyLimit limit = Jobs.getGCManager().getLimit(type); + + if (limit.getResetsAt() != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + resetsAt = limit.getResetsAt().toMili(); + } else + resetsAt = (limit.getTimeLimit() * 100L) + System.currentTimeMillis(); + this.amount = payment; } public boolean isReseted() { - return reseted; + return reseted; } public void setReseted(boolean reseted) { - this.reseted = reseted; + this.reseted = reseted; } public CurrencyType getType() { - return type; + return type; } public void setType(CurrencyType type) { - this.type = type; + this.type = type; } public double getAmount() { - return this.amount; + return this.amount; } public double addAmount(double amount) { - return this.amount += amount; + return this.amount += amount; } public void setAmount(double payment) { - this.amount = payment; + this.amount = payment; } public long getPaymentsTime() { - return paymentsTime; + return paymentsTime; } public void setPaymentsTime(long paymentsTime) { - this.paymentsTime = paymentsTime; + this.paymentsTime = paymentsTime; + } + + public long getResetsAt() { + return resetsAt; + } + + public void setResetsAt(long resetsAt) { + this.resetsAt = resetsAt; } } diff --git a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java index c73702f4..390dd924 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java @@ -3,6 +3,7 @@ package com.gamingmesh.jobs.economy; import java.util.HashMap; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyType; public class PaymentData { @@ -13,119 +14,136 @@ public class PaymentData { private boolean informed = false; - public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) { - payments.put(CurrencyType.EXP, new LimitsData(CurrencyType.EXP, time, Exp)); - payments.put(CurrencyType.MONEY, new LimitsData(CurrencyType.MONEY, time, Payment)); - payments.put(CurrencyType.POINTS, new LimitsData(CurrencyType.POINTS, time, Points)); - this.lastAnnouced = lastAnnouced; - this.informed = Informed; - } +// public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) { +// payments.put(CurrencyType.EXP, new LimitsData(CurrencyType.EXP, time, Exp)); +// payments.put(CurrencyType.MONEY, new LimitsData(CurrencyType.MONEY, time, Payment)); +// payments.put(CurrencyType.POINTS, new LimitsData(CurrencyType.POINTS, time, Points)); +// this.lastAnnouced = lastAnnouced; +// this.informed = Informed; +// } public PaymentData(CurrencyType type, Double amount) { - for (CurrencyType one : CurrencyType.values()) { - if (one != type) - payments.put(one, new LimitsData(one, System.currentTimeMillis(), 0D)); - } - payments.put(type, new LimitsData(type, System.currentTimeMillis(), amount)); + for (CurrencyType one : CurrencyType.values()) { + if (one != type) + payments.put(one, new LimitsData(one, 0D)); + } + payments.put(type, new LimitsData(type, amount)); } public PaymentData() { - resetLimits(); + resetLimits(); } public Long getTime(CurrencyType type) { - return payments.get(type).getPaymentsTime(); + return payments.get(type).getPaymentsTime(); } public void setReseted(CurrencyType type, boolean reseted) { - payments.get(type).setReseted(reseted); + payments.get(type).setReseted(reseted); } public boolean isReseted(CurrencyType type) { - return payments.get(type).isReseted(); + return payments.get(type).isReseted(); } public double getAmount(CurrencyType type) { - if (type == null) - return 0D; + if (type == null) + return 0D; - LimitsData data = payments.get(type); - return data == null ? 0D : (int) (data.getAmount() * 100) / 100D; + LimitsData data = payments.get(type); + return data == null ? 0D : (int) (data.getAmount() * 100) / 100D; } public long getLastAnnounced() { - return lastAnnouced; + return lastAnnouced; } public boolean isAnnounceTime(int t) { - if (lastAnnouced + (t * 1000) > System.currentTimeMillis()) - return false; + if (lastAnnouced + (t * 1000) > System.currentTimeMillis()) + return false; - setAnnouncementTime(); - return true; + setAnnouncementTime(); + return true; } public void setAnnouncementTime() { - this.lastAnnouced = System.currentTimeMillis(); + this.lastAnnouced = System.currentTimeMillis(); } public void addNewAmount(CurrencyType type, Double Payment) { - addNewAmount(type, Payment, null); + addNewAmount(type, Payment, null); } public void addNewAmount(CurrencyType type, Double Payment, Long time) { - payments.put(type, new LimitsData(type, time == null ? System.currentTimeMillis() : time, Payment)); + +// payments.put(type, new LimitsData(type, time == null ? System.currentTimeMillis() : time, Payment)); + + LimitsData data = new LimitsData(type, Payment); + + if (time != null) + data.setPaymentsTime(time); + + payments.put(type, data); } public void addAmount(CurrencyType type, double payment) { - payments.get(type).addAmount(payment); + payments.get(type).addAmount(payment); } public long getLeftTime(CurrencyType type) { - long left = getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000); - return left > System.currentTimeMillis() ? left - System.currentTimeMillis() : 0L; + + CurrencyLimit limit = Jobs.getGCManager().getLimit(type); + if (limit.getResetsAt() != null) { + LimitsData data = payments.get(type); + if (data.getResetsAt() < System.currentTimeMillis()) + return 0L; + return data.getResetsAt() - System.currentTimeMillis(); + } + + long left = getTime(type) + (limit.getTimeLimit() * 1000); + return left > System.currentTimeMillis() ? left - System.currentTimeMillis() : 0L; } public boolean isOverLimit(CurrencyType type, int limit) { - return payments.get(type).getAmount() >= limit; + return payments.get(type).getAmount() >= limit; } public double percentOverLimit(CurrencyType type, int limit) { - return ((payments.get(type).getAmount() / limit) - 1) * 100; + return ((payments.get(type).getAmount() / limit) - 1) * 100; } public boolean isOverTimeLimit(CurrencyType type) { - if (getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) { - return false; - } - if (informed) - informed = false; - resetLimits(); - return true; + if (getLeftTime(type) > 0) { + return false; + } + if (informed) + informed = false; + resetLimits(); + return true; } public void resetLimits() { - for (CurrencyType type : CurrencyType.values()) { - addNewAmount(type, 0D); - setReseted(type, true); - } + for (CurrencyType type : CurrencyType.values()) { + addNewAmount(type, 0D); + setReseted(type, true); + } } public void resetLimits(CurrencyType type) { - addNewAmount(type, 0D); - setReseted(type, true); + addNewAmount(type, 0D); + setReseted(type, true); } public boolean isReachedLimit(CurrencyType type, int money) { - isOverTimeLimit(type); - return isOverLimit(type, money); + isOverTimeLimit(type); + return isOverLimit(type, money); } public boolean isInformed() { - return informed; + return informed; } public void setInformed(boolean informed) { - this.informed = informed; + this.informed = informed; } } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java b/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java index 3f6c8868..7f5c65c1 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java @@ -15,6 +15,8 @@ import com.gamingmesh.jobs.hooks.WorldGuard.WorldGuardManager; import com.gamingmesh.jobs.hooks.stackMob.StackMobHandler; import com.gamingmesh.jobs.hooks.wildStacker.WildStackerHandler; +import net.Zrips.CMILib.Messages.CMIMessages; + public class HookManager { private static McMMOManager McMMOManager; @@ -88,7 +90,7 @@ public class HookManager { private static boolean setWorldGuard() { if (JobsHook.WorldGuard.isEnabled()) { worldGuardManager = new WorldGuardManager(); - Jobs.consoleMsg("&eWorldGuard detected."); + CMIMessages.consoleMessage("&eWorldGuard detected."); return true; } @@ -102,14 +104,14 @@ public class HookManager { try { Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper"); MythicManager = new MythicMobs4(PLUGIN); - Jobs.consoleMsg("&eMythicMobs 4.x detected."); + CMIMessages.consoleMessage("&eMythicMobs 4.x detected."); } catch (ClassNotFoundException ex) { try { Class.forName("io.lumine.mythic.bukkit.BukkitAPIHelper"); MythicManager = new MythicMobs5(PLUGIN); - Jobs.consoleMsg("&eMythicMobs 5.x detected."); + CMIMessages.consoleMessage("&eMythicMobs 5.x detected."); } catch (ClassNotFoundException e) { - Jobs.consoleMsg("&cYour MythicMobs version is not supported by Jobs! Supported versions: 4.9.1+"); + CMIMessages.consoleMessage("&cYour MythicMobs version is not supported by Jobs! Supported versions: 4.9.1+"); } } } @@ -118,17 +120,17 @@ public class HookManager { try { Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType"); pm.registerEvents(new McMMO2_X_listener(), PLUGIN); - Jobs.consoleMsg("&eRegistered McMMO 2.x listener"); + CMIMessages.consoleMessage("&eRegistered McMMO 2.x listener"); } catch (ClassNotFoundException e) { pm.registerEvents(new McMMO1_X_listener(), PLUGIN); - Jobs.consoleMsg("&eRegistered McMMO 1.x listener"); + CMIMessages.consoleMessage("&eRegistered McMMO 1.x listener"); } } private static void setMyPetManager() { if (JobsHook.MyPet.isEnabled()) { myPetManager = new MyPetManager(); - Jobs.consoleMsg("&eMyPet detected."); + CMIMessages.consoleMessage("&eMyPet detected."); } } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMOManager.java b/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMOManager.java index e73576cf..3044e189 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMOManager.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMOManager.java @@ -10,6 +10,8 @@ import org.bukkit.plugin.Plugin; import com.gamingmesh.jobs.Jobs; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; +import net.Zrips.CMILib.Messages.CMIMessages; + public class McMMOManager { public boolean mcMMOPresent = false; @@ -100,13 +102,13 @@ public class McMMOManager { mcMMOPresent = false; } if (!mcMMOPresent) - Jobs.consoleMsg("&6mcMMO was found - &cBut your McMMO version is outdated, please update for full support."); + CMIMessages.consoleMessage("&6mcMMO was found - &cBut your McMMO version is outdated, please update for full support."); // Still enabling event listener for repair return true; } - Jobs.consoleMsg("&6mcMMO" + McMMO.getDescription().getVersion() + " was found - Enabling capabilities."); + CMIMessages.consoleMessage("&6mcMMO" + McMMO.getDescription().getVersion() + " was found - Enabling capabilities."); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java index f189e022..13818813 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.Jobs; import io.lumine.xikage.mythicmobs.MythicMobs; import io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper; import io.lumine.xikage.mythicmobs.mobs.MythicMob; +import net.Zrips.CMILib.Messages.CMIMessages; public class MythicMobs4 implements MythicMobInterface { @@ -40,12 +41,12 @@ public class MythicMobs4 implements MythicMobInterface { Class.forName("io.lumine.xikage.mythicmobs.MythicMobs"); } catch (ClassNotFoundException e) { // Disabling - Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support."); + CMIMessages.consoleMessage("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support."); return false; } apiHelper = ((MythicMobs) mm).getAPIHelper(); - Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - Enabling capabilities."); + CMIMessages.consoleMessage("&e[Jobs] &6MythicMobs was found - Enabling capabilities."); return true; } @@ -64,7 +65,7 @@ public class MythicMobs4 implements MythicMobInterface { if (!failed) { failed = true; e.printStackTrace(); - Jobs.consoleMsg("&cEncountered error when checking MythicMob entity name. Support for mythicMobs will be suspended for time beying. Please report this issue."); + CMIMessages.consoleMessage("&cEncountered error when checking MythicMob entity name. Support for mythicMobs will be suspended for time beying. Please report this issue."); } } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs5.java b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs5.java index b842ab2d..21b17a48 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs5.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs5.java @@ -8,6 +8,7 @@ import com.gamingmesh.jobs.Jobs; import io.lumine.mythic.api.mobs.MythicMob; import io.lumine.mythic.bukkit.BukkitAPIHelper; import io.lumine.mythic.bukkit.MythicBukkit; +import net.Zrips.CMILib.Messages.CMIMessages; //import io.lumine.xikage.mythicmobs.MythicMobs; //import io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper; @@ -44,12 +45,12 @@ public class MythicMobs5 implements MythicMobInterface { Class.forName("io.lumine.mythic.bukkit.events.MythicMobDeathEvent"); } catch (ClassNotFoundException e) { // Disabling - Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support."); + CMIMessages.consoleMessage("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support."); return false; } apiHelper = ((MythicBukkit) mm).getAPIHelper(); - Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - Enabling capabilities."); + CMIMessages.consoleMessage("&e[Jobs] &6MythicMobs was found - Enabling capabilities."); return true; } @@ -68,7 +69,7 @@ public class MythicMobs5 implements MythicMobInterface { if (!failed) { failed = true; e.printStackTrace(); - Jobs.consoleMsg("&cEncountered error when checking MythicMob entity name. Support for mythicMobs will be suspended for time beying. Please report this issue."); + CMIMessages.consoleMessage("&cEncountered error when checking MythicMob entity name. Support for mythicMobs will be suspended for time beying. Please report this issue."); } } diff --git a/src/main/java/com/gamingmesh/jobs/i18n/Language.java b/src/main/java/com/gamingmesh/jobs/i18n/Language.java index 2b3b9420..09a28ad0 100644 --- a/src/main/java/com/gamingmesh/jobs/i18n/Language.java +++ b/src/main/java/com/gamingmesh/jobs/i18n/Language.java @@ -31,6 +31,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.config.YmlMaker; import net.Zrips.CMILib.Colors.CMIChatColor; +import net.Zrips.CMILib.Messages.CMIMessages; public class Language { @@ -71,8 +72,8 @@ public class Language { else msg = customlocale.isString(key) ? CMIChatColor.translate(customlocale.getString(key)) : missing; } catch (Exception e) { - Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key); - Jobs.consoleMsg(e.getLocalizedMessage()); + CMIMessages.consoleMessage("&e[Jobs] &2Can't read language file for: " + key); + CMIMessages.consoleMessage(e.getLocalizedMessage()); return ""; } @@ -96,8 +97,8 @@ public class Language { msg += one; } } catch (Exception e) { - Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key); - Jobs.consoleMsg(e.getLocalizedMessage()); + CMIMessages.consoleMessage("&e[Jobs] &2Can't read language file for: " + key); + CMIMessages.consoleMessage(e.getLocalizedMessage()); return ""; } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 94fbb087..ed1a91b7 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -87,9 +87,11 @@ import net.Zrips.CMILib.Items.ArmorTypes; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public class JobsListener implements Listener { @@ -98,78 +100,79 @@ public class JobsListener implements Listener { private final Map interactDelay = new HashMap<>(); public JobsListener(Jobs plugin) { - this.plugin = plugin; + this.plugin = plugin; } private boolean isInteractOk(Player player) { - Long delay = interactDelay.get(player.getUniqueId()); - if (delay == null) { - interactDelay.put(player.getUniqueId(), System.currentTimeMillis()); - return true; - } + Long delay = interactDelay.get(player.getUniqueId()); + if (delay == null) { + interactDelay.put(player.getUniqueId(), System.currentTimeMillis()); + return true; + } - long time = System.currentTimeMillis() - delay; - interactDelay.put(player.getUniqueId(), System.currentTimeMillis()); - return time > 100; + long time = System.currentTimeMillis() - delay; + interactDelay.put(player.getUniqueId(), System.currentTimeMillis()); + return time > 100; } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockFromToEvent(BlockFromToEvent event) { - if (!Jobs.getGCManager().useBlockProtection) - return; - if (!Jobs.getGCManager().ignoreOreGenerators) - return; - if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) - return; - Jobs.getBpManager().remove(event.getToBlock()); + if (!Jobs.getGCManager().useBlockProtection) + return; + if (!Jobs.getGCManager().ignoreOreGenerators) + return; + if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) + return; + Jobs.getBpManager().remove(event.getToBlock()); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onJoin(PlayerJoinEvent event) { - if (Jobs.getGCManager().isShowNewVersion() && event.getPlayer().hasPermission("jobs.versioncheck")) - Jobs.getVersionCheckManager().VersionCheck(event.getPlayer()); + if (Jobs.getGCManager().isShowNewVersion() && event.getPlayer().hasPermission("jobs.versioncheck")) + Jobs.getVersionCheckManager().VersionCheck(event.getPlayer()); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onSelection(PlayerInteractEvent event) { - if (event.getClickedBlock() == null || event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) - return; + if (event.getClickedBlock() == null || event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; - Player player = event.getPlayer(); - if (CMIItemStack.getItemInMainHand(player).getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial()) - return; + Player player = event.getPlayer(); - if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()) || !player.hasPermission("jobs.area.select")) - return; + if (CMIItemStack.getItemInMainHand(player).getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial()) + return; - if (player.getGameMode() == GameMode.CREATIVE) - event.setCancelled(true); + if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()) || !player.hasPermission("jobs.area.select")) + return; - Location loc = event.getClickedBlock().getLocation(); + if (player.getGameMode() == GameMode.CREATIVE) + event.setCancelled(true); - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - Jobs.getSelectionManager().placeLoc1(player, loc); - player.sendMessage(Jobs.getLanguage().getMessage("command.area.output.selected1", "%x%", loc.getBlockX(), "%y%", loc.getBlockY(), "%z%", loc.getBlockZ())); - event.setCancelled(true); - } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - Jobs.getSelectionManager().placeLoc2(player, loc); - player.sendMessage(Jobs.getLanguage().getMessage("command.area.output.selected2", "%x%", loc.getBlockX(), "%y%", loc.getBlockY(), "%z%", loc.getBlockZ())); - event.setCancelled(true); - } + Location loc = event.getClickedBlock().getLocation(); - if (Jobs.getSelectionManager().hasPlacedBoth(player)) { - plugin.getServer().getPluginManager().callEvent(new JobsAreaSelectionEvent(player, Jobs.getSelectionManager().getSelectionCuboid(player))); - } + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + Jobs.getSelectionManager().placeLoc1(player, loc); + player.sendMessage(Jobs.getLanguage().getMessage("command.area.output.selected1", "%x%", loc.getBlockX(), "%y%", loc.getBlockY(), "%z%", loc.getBlockZ())); + event.setCancelled(true); + } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Jobs.getSelectionManager().placeLoc2(player, loc); + player.sendMessage(Jobs.getLanguage().getMessage("command.area.output.selected2", "%x%", loc.getBlockX(), "%y%", loc.getBlockY(), "%z%", loc.getBlockZ())); + event.setCancelled(true); + } + + if (Jobs.getSelectionManager().hasPlacedBoth(player)) { + plugin.getServer().getPluginManager().callEvent(new JobsAreaSelectionEvent(player, Jobs.getSelectionManager().getSelectionCuboid(player))); + } } @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(final PlayerJoinEvent event) { - if (!Jobs.getGCManager().MultiServerCompatability()) - Jobs.getPlayerManager().playerJoin(event.getPlayer()); - else { - plugin.getServer().getScheduler().runTaskLater(plugin, () -> Jobs.getPlayerManager().playerJoin(event.getPlayer()), 40L); - } + if (!Jobs.getGCManager().MultiServerCompatability()) + Jobs.getPlayerManager().playerJoin(event.getPlayer()); + else { + CMIScheduler.get().runTaskLater(() -> Jobs.getPlayerManager().playerJoin(event.getPlayer()), 40L); + } } // @EventHandler(priority = EventPriority.MONITOR) @@ -186,539 +189,537 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { - Jobs.getPlayerManager().playerQuit(event.getPlayer()); + Jobs.getPlayerManager().playerQuit(event.getPlayer()); } @EventHandler(priority = EventPriority.MONITOR) public void onPlayerWorldChange(PlayerChangedWorldEvent event) { - Jobs.getPermissionHandler().recalculatePermissions(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer())); + Jobs.getPermissionHandler().recalculatePermissions(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer())); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSignInteract(PlayerInteractEvent event) { - if (!Jobs.getGCManager().SignsEnabled || event.getAction() != Action.RIGHT_CLICK_BLOCK) - return; + if (!Jobs.getGCManager().SignsEnabled || event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; - Block block = event.getClickedBlock(); - if (block == null || !(block.getState() instanceof Sign)) - return; + Block block = event.getClickedBlock(); + if (block == null || !(block.getState() instanceof Sign)) + return; - Player player = event.getPlayer(); - if (!isInteractOk(player)) - return; + Player player = event.getPlayer(); + if (!isInteractOk(player)) + return; - Sign sign = (Sign) block.getState(); + Sign sign = (Sign) block.getState(); - if (!CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 0)).equalsIgnoreCase( - CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline")))) - return; + if (!CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 0)).equalsIgnoreCase( + CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline")))) + return; - String command = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 1)); - for (String key : Jobs.getLanguageManager().signKeys) { - if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { - command = key; - break; - } - } + String command = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 1)); + for (String key : Jobs.getLanguageManager().signKeys) { + if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { + command = key; + break; + } + } - player.performCommand("jobs " + command + " " + CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)) - + " " + CMIChatColor.stripColor(plugin.getComplement() - .getLine(sign, 3)).replace(" ", "")); // Replace trailing spaces at 3rd line to parse command + player.performCommand("jobs " + command + " " + CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)) + + " " + CMIChatColor.stripColor(plugin.getComplement() + .getLine(sign, 3)).replace(" ", "")); // Replace trailing spaces at 3rd line to parse command } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onSignDestroy(BlockBreakEvent event) { - if (!Jobs.getGCManager().SignsEnabled) - return; + if (!Jobs.getGCManager().SignsEnabled) + return; - Block block = event.getBlock(); - if (!(block.getState() instanceof Sign)) - return; + Block block = event.getBlock(); + if (!(block.getState() instanceof Sign)) + return; - Player player = event.getPlayer(); - if (plugin.getComplement().getLine((Sign) block.getState(), 0).contains(Jobs.getLanguage().getMessage("signs.topline")) - && !player.hasPermission("jobs.command.signs")) { - event.setCancelled(true); - player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); - return; - } + Player player = event.getPlayer(); + if (plugin.getComplement().getLine((Sign) block.getState(), 0).contains(Jobs.getLanguage().getMessage("signs.topline")) + && !player.hasPermission("jobs.command.signs")) { + event.setCancelled(true); + player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); + return; + } - if (Jobs.getSignUtil().getSign(block.getLocation()) == null) - return; + if (Jobs.getSignUtil().getSign(block.getLocation()) == null) + return; - if (!player.hasPermission("jobs.command.signs")) { - event.setCancelled(true); - player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); - return; - } + if (!player.hasPermission("jobs.command.signs")) { + event.setCancelled(true); + player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); + return; + } - if (Jobs.getSignUtil().removeSign(block.getLocation())) - Jobs.getSignUtil().saveSigns(); + if (Jobs.getSignUtil().removeSign(block.getLocation())) + Jobs.getSignUtil().saveSigns(); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onSignTopListCreate(SignChangeEvent event) { - if (!Jobs.getGCManager().SignsEnabled) - return; + if (!Jobs.getGCManager().SignsEnabled) + return; - Block block = event.getBlock(); - if (!(block.getState() instanceof Sign)) - return; + Block block = event.getBlock(); + if (!(block.getState() instanceof Sign)) + return; - if (!CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0)).equalsIgnoreCase("[Jobs]")) - return; + if (!CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0)).equalsIgnoreCase("[Jobs]")) + return; - final SignTopType type = SignTopType.getType(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1))); - if (type == null) - return; + final SignTopType type = SignTopType.getType(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1))); + if (type == null) + return; - Player player = event.getPlayer(); - if (!player.hasPermission("jobs.command.signs")) { - event.setCancelled(true); - player.sendMessage(Jobs.getLanguage().getMessage("signs.cantcreate")); - return; - } + Player player = event.getPlayer(); + if (!player.hasPermission("jobs.command.signs")) { + event.setCancelled(true); + player.sendMessage(Jobs.getLanguage().getMessage("signs.cantcreate")); + return; + } - final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 2)).toLowerCase()); - if (type == SignTopType.toplist && job == null) { - player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); - return; - } + final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 2)).toLowerCase()); + if (type == SignTopType.toplist && job == null) { + player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); + return; + } - boolean special = false; - String numberString = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 3)).toLowerCase(); - if (numberString.contains("s")) { - numberString = numberString.replace("s", ""); - special = true; - } + boolean special = false; + String numberString = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 3)).toLowerCase(); + if (numberString.contains("s")) { + numberString = numberString.replace("s", ""); + special = true; + } - int number = 0; - try { - number = Integer.parseInt(numberString); - } catch (NumberFormatException e) { - CMIMessages.sendMessage(player, LC.info_UseInteger); - return; - } + int number = 0; + try { + number = Integer.parseInt(numberString); + } catch (NumberFormatException e) { + CMIMessages.sendMessage(player, LC.info_UseInteger); + return; + } - jobsSign signInfo = new jobsSign(); + jobsSign signInfo = new jobsSign(); - signInfo.setLoc(block.getLocation()); - signInfo.setNumber(number); - if (job != null) - signInfo.setJobName(job.getName()); - signInfo.setType(type); - signInfo.setSpecial(special); + signInfo.setLoc(block.getLocation()); + signInfo.setNumber(number); + if (job != null) + signInfo.setJobName(job.getName()); + signInfo.setType(type); + signInfo.setSpecial(special); - final SignUtil signUtil = Jobs.getSignUtil(); - signUtil.addSign(signInfo); - signUtil.saveSigns(); + final SignUtil signUtil = Jobs.getSignUtil(); + signUtil.addSign(signInfo); + signUtil.saveSigns(); - event.setCancelled(true); + event.setCancelled(true); - plugin.getServer().getScheduler().runTaskLater(plugin, () -> signUtil.signUpdate(job, type), 1L); + CMIScheduler.get().runTaskLater(() -> signUtil.signUpdate(job, type), 1L); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onSignChange(SignChangeEvent event) { - if (!Jobs.getGCManager().SignsEnabled) - return; + if (!Jobs.getGCManager().SignsEnabled) + return; - String line1 = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)); + String line1 = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)); - if (CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0)) - .equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !line1.equalsIgnoreCase("toplist")) - event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline"))); - else - return; + if (CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0)) + .equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !line1.equalsIgnoreCase("toplist")) + event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline"))); + else + return; - if (!event.getPlayer().hasPermission("jobs.command.signs")) { - event.setCancelled(true); - event.getPlayer().sendMessage(Jobs.getLanguage().getMessage("signs.cantcreate")); - return; - } + if (!event.getPlayer().hasPermission("jobs.command.signs")) { + event.setCancelled(true); + event.getPlayer().sendMessage(Jobs.getLanguage().getMessage("signs.cantcreate")); + return; + } - for (String key : Jobs.getLanguageManager().signKeys) { - String secondLine = Jobs.getLanguage().getMessage("signs.secondline." + key); + for (String key : Jobs.getLanguageManager().signKeys) { + String secondLine = Jobs.getLanguage().getMessage("signs.secondline." + key); - if (line1.equalsIgnoreCase(CMIChatColor.stripColor(secondLine))) { - event.setLine(1, convert(secondLine)); - break; - } - } + if (line1.equalsIgnoreCase(CMIChatColor.stripColor(secondLine))) { + event.setLine(1, convert(secondLine)); + break; + } + } - Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 2))); - if (job == null) - return; + Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 2))); + if (job == null) + return; - String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; - event.setLine(2, convert(color + job.getDisplayName())); + String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; + event.setLine(2, convert(color + job.getDisplayName())); } private final Pattern pattern = Pattern.compile("&([0-9a-fk-or])"); private String convert(String line) { - return pattern.matcher(CMIChatColor.translate(line)).replaceAll("\u00a7$1"); + return pattern.matcher(CMIChatColor.translate(line)).replaceAll("\u00a7$1"); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onWorldLoad(WorldLoadEvent event) { - PluginManager pm = plugin.getServer().getPluginManager(); - String name = event.getWorld().getName().toLowerCase(); - if (pm.getPermission("jobs.world." + name) == null && !PermissionHandler.worldsRegistered.contains(name)) { - pm.addPermission(new Permission("jobs.world." + name, PermissionDefault.TRUE)); - PermissionHandler.worldsRegistered.add(name); - } + PluginManager pm = plugin.getServer().getPluginManager(); + String name = event.getWorld().getName().toLowerCase(); + if (pm.getPermission("jobs.world." + name) == null && !PermissionHandler.worldsRegistered.contains(name)) { + pm.addPermission(new Permission("jobs.world." + name, PermissionDefault.TRUE)); + PermissionHandler.worldsRegistered.add(name); + } } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onCropGrown(final BlockGrowEvent event) { - if (Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) { - plugin.getServer().getScheduler().runTaskLater(plugin, () -> Jobs.getBpManager().remove(event.getBlock()), 1L); - } + if (Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) { + CMIScheduler.get().runAtLocationLater(event.getBlock().getLocation(), () -> Jobs.getBpManager().remove(event.getBlock()), 1L); + } } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onTreeGrown(final StructureGrowEvent event) { - if (!event.getBlocks().isEmpty() && Jobs.getGCManager().canPerformActionInWorld(event.getBlocks().get(0).getWorld())) { - plugin.getServer().getScheduler().runTaskLater(plugin, () -> event.getBlocks().forEach(blockState -> Jobs.getBpManager().remove(blockState.getBlock())), 1L); - } + if (!event.getBlocks().isEmpty() && Jobs.getGCManager().canPerformActionInWorld(event.getBlocks().get(0).getWorld())) { + CMIScheduler.get().runAtLocationLater(event.getBlocks().get(0).getLocation(), () -> event.getBlocks().forEach(blockState -> Jobs.getBpManager().remove(blockState.getBlock())), 1L); + } } private static boolean usingLimitedItem(ItemStack iih, JobsPlayer jPlayer) { - CMINBT nbt = new CMINBT(iih); - Integer i = nbt.getInt("JobsLimited"); + CMINBT nbt = new CMINBT(iih); + Integer i = nbt.getInt("JobsLimited"); - if (i == null) - return false; + if (i == null) + return false; - Job job = Jobs.getJob(i); - if (job == null) - return false; + Job job = Jobs.getJob(i); + if (job == null) + return false; - JobProgression prog = jPlayer.getJobProgression(job); - if (prog == null) - return false; + JobProgression prog = jPlayer.getJobProgression(job); + if (prog == null) + return false; - String node = nbt.getString("JobsLimitedNode"); - if (node == null) - return false; + String node = nbt.getString("JobsLimitedNode"); + if (node == null) + return false; - for (JobLimitedItems oneItem : job.getLimitedItems().values()) { - if (prog.getLevel() >= oneItem.getLevel() || !oneItem.getNode().equalsIgnoreCase(node)) - continue; + for (JobLimitedItems oneItem : job.getLimitedItems().values()) { + if (prog.getLevel() >= oneItem.getLevel() || !oneItem.getNode().equalsIgnoreCase(node)) + continue; - CMIActionBar.send(jPlayer.getPlayer(), Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", job.getDisplayName())); - return true; - } + CMIActionBar.send(jPlayer.getPlayer(), Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", job.getDisplayName())); + return true; + } - return false; + return false; } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onLimitedItemInteract(PlayerInteractEvent event) { - if (!Jobs.hasLimitedItems()) { - return; - } + if (!Jobs.hasLimitedItems()) { + return; + } - Player player = event.getPlayer(); - ItemStack iih = null; - try { - if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { - iih = CMIItemStack.getItemInOffHand(player); - } else { - iih = CMIItemStack.getItemInMainHand(player); - } - } catch (Exception e) { - iih = CMIItemStack.getItemInMainHand(player); - } + Player player = event.getPlayer(); + ItemStack iih = null; + try { + if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { + iih = CMIItemStack.getItemInOffHand(player); + } else { + iih = CMIItemStack.getItemInMainHand(player); + } + } catch (Exception e) { + iih = CMIItemStack.getItemInMainHand(player); + } - if (iih == null || iih.getType() == Material.AIR) - return; + if (iih == null || iih.getType() == Material.AIR) + return; - if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld())) - return; + if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld())) + return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return; - Map enchants = new HashMap<>(iih.getEnchantments()); - if (enchants.isEmpty()) { - return; - } + Map enchants = new HashMap<>(iih.getEnchantments()); + if (enchants.isEmpty()) { + return; + } - if (usingLimitedItem(iih, jPlayer)) { - event.setCancelled(true); - } + if (usingLimitedItem(iih, jPlayer)) { + event.setCancelled(true); + } - String name = null; - List lore = new ArrayList<>(); + String name = null; + List lore = new ArrayList<>(); - if (iih.hasItemMeta()) { - ItemMeta meta = iih.getItemMeta(); - if (meta.hasDisplayName()) - name = meta.getDisplayName(); - if (meta.hasLore()) - lore = meta.getLore(); - } + if (iih.hasItemMeta()) { + ItemMeta meta = iih.getItemMeta(); + if (meta.hasDisplayName()) + name = meta.getDisplayName(); + if (meta.hasLore()) + lore = meta.getLore(); + } - String meinOk = null; - String itemNode = null; - CMIMaterial mat = CMIMaterial.get(iih); + String meinOk = null; + String itemNode = null; + CMIMaterial mat = CMIMaterial.get(iih); - Integer jobId = null; - mein: for (JobProgression one : jPlayer.getJobProgression()) { - for (JobLimitedItems oneItem : one.getJob().getLimitedItems().values()) { - if (one.getLevel() >= oneItem.getLevel() || !isThisItem(oneItem, mat, name, lore, enchants)) - continue; - jobId = one.getJob().getId(); - meinOk = one.getJob().getDisplayName(); - itemNode = oneItem.getNode(); - break mein; - } - } + Integer jobId = null; + mein: for (JobProgression one : jPlayer.getJobProgression()) { + for (JobLimitedItems oneItem : one.getJob().getLimitedItems().values()) { + if (one.getLevel() >= oneItem.getLevel() || !isThisItem(oneItem, mat, name, lore, enchants)) + continue; + jobId = one.getJob().getId(); + meinOk = one.getJob().getDisplayName(); + itemNode = oneItem.getNode(); + break mein; + } + } - if (meinOk != null) { - event.setCancelled(true); - CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk)); + if (meinOk != null) { + event.setCancelled(true); + CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk)); - CMINBT nbt = new CMINBT(iih); - nbt.setInt("JobsLimited", jobId); - iih = (ItemStack) nbt.setString("JobsLimitedNode", itemNode); - try { - if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { - CMIItemStack.setItemInOffHand(player, iih); - } else { - CMIItemStack.setItemInMainHand(player, iih); - } - } catch (Exception e) { - CMIItemStack.setItemInMainHand(player, iih); - } - } + CMINBT nbt = new CMINBT(iih); + nbt.setInt("JobsLimited", jobId); + iih = (ItemStack) nbt.setString("JobsLimitedNode", itemNode); + try { + if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { + CMIItemStack.setItemInOffHand(player, iih); + } else { + CMIItemStack.setItemInMainHand(player, iih); + } + } catch (Exception e) { + CMIItemStack.setItemInMainHand(player, iih); + } + } } private static boolean isThisItem(JobLimitedItems oneItem, CMIMaterial mat, String name, List lore, Map enchants) { - if (oneItem.getType() != mat) - return false; + if (oneItem.getType() != mat) + return false; - if (oneItem.getName() != null && !CMIChatColor.translate(oneItem.getName()).equalsIgnoreCase(name)) { - return false; - } + if (oneItem.getName() != null && !CMIChatColor.translate(oneItem.getName()).equalsIgnoreCase(name)) { + return false; + } - for (String onelore : oneItem.getLore()) { - if (!lore.contains(onelore)) { - return false; - } - } + for (String onelore : oneItem.getLore()) { + if (!lore.contains(onelore)) { + return false; + } + } - for (Entry oneE : enchants.entrySet()) { - Integer value = oneItem.getEnchants().get(oneE.getKey()); + for (Entry oneE : enchants.entrySet()) { + Integer value = oneItem.getEnchants().get(oneE.getKey()); - if (value != null && value <= oneE.getValue()) { - return true; - } - } + if (value != null && value <= oneE.getValue()) { + return true; + } + } - return false; + return false; } @EventHandler(ignoreCancelled = true) public void onChunkChangeMove(PlayerMoveEvent event) { - if (!event.getPlayer().isOnline() || !Jobs.getGCManager().canPerformActionInWorld(event.getTo().getWorld())) - return; + if (!event.getPlayer().isOnline() || !Jobs.getGCManager().canPerformActionInWorld(event.getTo().getWorld())) + return; - Chunk from = event.getFrom().getChunk(); - Chunk to = event.getTo().getChunk(); - if (from != to) { - plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to)); - } + Chunk from = event.getFrom().getChunk(); + Chunk to = event.getTo().getChunk(); + if (!from.equals(to)) { + plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to)); + } } @EventHandler(ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent event) { - boolean shift = false, numberkey = false; - if (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT) - shift = true; + SlotType slotType = event.getSlotType(); - if (event.getClick() == ClickType.NUMBER_KEY) - numberkey = true; + if ((slotType != SlotType.ARMOR || slotType != SlotType.QUICKBAR) && event.getInventory().getType() != InventoryType.CRAFTING) + return; - SlotType slotType = event.getSlotType(); + if (!(event.getWhoClicked() instanceof Player) || event.getCurrentItem() == null) + return; - if ((slotType != SlotType.ARMOR || slotType != SlotType.QUICKBAR) && event.getInventory().getType() != InventoryType.CRAFTING) - return; + boolean shift = event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT; - if (!(event.getWhoClicked() instanceof Player) || event.getCurrentItem() == null) - return; + ArmorTypes newArmorType = ArmorTypes.matchType(shift ? event.getCurrentItem() : event.getCursor()); + if (!shift && newArmorType != null && event.getRawSlot() != newArmorType.getSlot()) + return; - ArmorTypes newArmorType = ArmorTypes.matchType(shift ? event.getCurrentItem() : event.getCursor()); - if (!shift && newArmorType != null && event.getRawSlot() != newArmorType.getSlot()) - return; + if (shift) { + newArmorType = ArmorTypes.matchType(event.getCurrentItem()); + if (newArmorType == null) + return; - if (shift) { - newArmorType = ArmorTypes.matchType(event.getCurrentItem()); - if (newArmorType == null) - return; + boolean equipping = true; + if (event.getRawSlot() == newArmorType.getSlot()) + equipping = false; - boolean equipping = true; - if (event.getRawSlot() == newArmorType.getSlot()) - equipping = false; + Player player = (Player) event.getWhoClicked(); + PlayerInventory inv = player.getInventory(); - Player player = (Player) event.getWhoClicked(); - PlayerInventory inv = player.getInventory(); + if (newArmorType == ArmorTypes.HELMET && + (equipping ? inv.getHelmet() == null : inv.getHelmet() != null) || + (newArmorType == ArmorTypes.CHESTPLATE || newArmorType == ArmorTypes.ELYTRA) && + (equipping ? inv.getChestplate() == null : inv.getChestplate() != null) || + newArmorType == ArmorTypes.LEGGINGS && + (equipping ? inv.getLeggings() == null : inv.getLeggings() != null) || + newArmorType == ArmorTypes.BOOTS && + (equipping ? inv.getBoots() == null : inv.getBoots() != null)) { + JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : event + .getCurrentItem(), equipping ? event.getCurrentItem() : null); + plugin.getServer().getPluginManager().callEvent(armorEquipEvent); + if (armorEquipEvent.isCancelled()) { + event.setCancelled(true); + } + } + } else { - if (newArmorType == ArmorTypes.HELMET && - (equipping ? inv.getHelmet() == null : inv.getHelmet() != null) || - (newArmorType == ArmorTypes.CHESTPLATE || newArmorType == ArmorTypes.ELYTRA) && - (equipping ? inv.getChestplate() == null : inv.getChestplate() != null) || - newArmorType == ArmorTypes.LEGGINGS && - (equipping ? inv.getLeggings() == null : inv.getLeggings() != null) || - newArmorType == ArmorTypes.BOOTS && - (equipping ? inv.getBoots() == null : inv.getBoots() != null)) { - JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : event - .getCurrentItem(), equipping ? event.getCurrentItem() : null); - plugin.getServer().getPluginManager().callEvent(armorEquipEvent); - if (armorEquipEvent.isCancelled()) { - event.setCancelled(true); - } - } - } else { - ItemStack newArmorPiece = event.getCursor(); - ItemStack oldArmorPiece = event.getCurrentItem(); - if (numberkey) { - org.bukkit.inventory.Inventory clicked = Version.isCurrentHigher(Version.v1_8_R1) ? event.getInventory() : event.getClickedInventory(); - if (clicked != null && clicked.getType() == InventoryType.PLAYER) { - ItemStack hotbarItem = clicked.getItem(event.getHotbarButton()); - if (hotbarItem != null) { - newArmorType = ArmorTypes.matchType(hotbarItem); - newArmorPiece = hotbarItem; - oldArmorPiece = clicked.getItem(event.getSlot()); - } else - newArmorType = ArmorTypes.matchType(oldArmorPiece != null && oldArmorPiece.getType() != Material.AIR ? oldArmorPiece : event.getCursor()); - } - } else - newArmorType = ArmorTypes.matchType(oldArmorPiece != null && oldArmorPiece.getType() != Material.AIR ? oldArmorPiece : event.getCursor()); + boolean numberkey = event.getClick() == ClickType.NUMBER_KEY; - if (newArmorType != null && event.getRawSlot() == newArmorType.getSlot()) { - EquipMethod method = EquipMethod.DRAG; - if (event.getAction() == InventoryAction.HOTBAR_SWAP || numberkey) - method = EquipMethod.HOTBAR_SWAP; - JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece); - plugin.getServer().getPluginManager().callEvent(armorEquipEvent); - if (armorEquipEvent.isCancelled()) - event.setCancelled(true); - } - } + ItemStack newArmorPiece = event.getCursor(); + ItemStack oldArmorPiece = event.getCurrentItem(); + if (numberkey) { + org.bukkit.inventory.Inventory clicked = Version.isCurrentHigher(Version.v1_8_R1) ? event.getInventory() : event.getClickedInventory(); + if (clicked != null && clicked.getType() == InventoryType.PLAYER) { + ItemStack hotbarItem = clicked.getItem(event.getHotbarButton()); + if (hotbarItem != null) { + newArmorType = ArmorTypes.matchType(hotbarItem); + newArmorPiece = hotbarItem; + oldArmorPiece = clicked.getItem(event.getSlot()); + } else + newArmorType = ArmorTypes.matchType(oldArmorPiece != null && oldArmorPiece.getType() != Material.AIR ? oldArmorPiece : event.getCursor()); + } + } else + newArmorType = ArmorTypes.matchType(oldArmorPiece != null && oldArmorPiece.getType() != Material.AIR ? oldArmorPiece : event.getCursor()); + + if (newArmorType != null && event.getRawSlot() == newArmorType.getSlot()) { + EquipMethod method = EquipMethod.DRAG; + if (event.getAction() == InventoryAction.HOTBAR_SWAP || numberkey) + method = EquipMethod.HOTBAR_SWAP; + JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece); + plugin.getServer().getPluginManager().callEvent(armorEquipEvent); + if (armorEquipEvent.isCancelled()) + event.setCancelled(true); + } + } } @EventHandler public void playerInteractEvent(PlayerInteractEvent event) { - if (event.getAction() == Action.PHYSICAL) - return; + if (event.getAction() == Action.PHYSICAL) + return; - if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) - return; + if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; - ArmorTypes newArmorType = ArmorTypes.matchType(event.getItem()); - if (newArmorType == null) - return; + ArmorTypes newArmorType = ArmorTypes.matchType(event.getItem()); + if (newArmorType == null) + return; - PlayerInventory inv = event.getPlayer().getInventory(); + PlayerInventory inv = event.getPlayer().getInventory(); - if (newArmorType == ArmorTypes.HELMET && - inv.getHelmet() == null || - (newArmorType == ArmorTypes.CHESTPLATE || newArmorType == ArmorTypes.ELYTRA) && - inv.getChestplate() == null || - newArmorType == ArmorTypes.LEGGINGS && - inv.getLeggings() == null || - newArmorType == ArmorTypes.BOOTS && - inv.getBoots() == null) { - JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(event.getPlayer(), EquipMethod.HOTBAR, ArmorTypes.matchType(event.getItem()), null, event - .getItem()); - plugin.getServer().getPluginManager().callEvent(armorEquipEvent); - if (armorEquipEvent.isCancelled()) { - event.setCancelled(true); - event.getPlayer().updateInventory(); - } - } + if (newArmorType == ArmorTypes.HELMET && + inv.getHelmet() == null || + (newArmorType == ArmorTypes.CHESTPLATE || newArmorType == ArmorTypes.ELYTRA) && + inv.getChestplate() == null || + newArmorType == ArmorTypes.LEGGINGS && + inv.getLeggings() == null || + newArmorType == ArmorTypes.BOOTS && + inv.getBoots() == null) { + JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(event.getPlayer(), EquipMethod.HOTBAR, ArmorTypes.matchType(event.getItem()), null, event + .getItem()); + plugin.getServer().getPluginManager().callEvent(armorEquipEvent); + if (armorEquipEvent.isCancelled()) { + event.setCancelled(true); + event.getPlayer().updateInventory(); + } + } } @EventHandler(ignoreCancelled = true) public void dispenserFireEvent(BlockDispenseEvent event) { - ItemStack item = event.getItem(); - ArmorTypes type = ArmorTypes.matchType(item); - if (type == null) - return; + ItemStack item = event.getItem(); + ArmorTypes type = ArmorTypes.matchType(item); + if (type == null) + return; - Location loc = event.getBlock().getLocation(); - for (Player p : loc.getWorld().getPlayers()) { - Location ploc = p.getLocation(); - if (loc.getBlockY() - ploc.getBlockY() >= -1 && loc.getBlockY() - ploc.getBlockY() <= 1) { + Location loc = event.getBlock().getLocation(); + for (Player p : loc.getWorld().getPlayers()) { + Location ploc = p.getLocation(); + if (loc.getBlockY() - ploc.getBlockY() >= -1 && loc.getBlockY() - ploc.getBlockY() <= 1) { - if (p.getInventory().getHelmet() == null && type == ArmorTypes.HELMET || - p.getInventory().getChestplate() == null && (type == ArmorTypes.CHESTPLATE || type == ArmorTypes.ELYTRA) || - p.getInventory().getLeggings() == null && type == ArmorTypes.LEGGINGS || - p.getInventory().getBoots() == null && type == ArmorTypes.BOOTS) { + if (p.getInventory().getHelmet() == null && type == ArmorTypes.HELMET || + p.getInventory().getChestplate() == null && (type == ArmorTypes.CHESTPLATE || type == ArmorTypes.ELYTRA) || + p.getInventory().getLeggings() == null && type == ArmorTypes.LEGGINGS || + p.getInventory().getBoots() == null && type == ArmorTypes.BOOTS) { - if (!(event.getBlock().getState() instanceof Dispenser)) - continue; + if (!(event.getBlock().getState() instanceof Dispenser)) + continue; - Dispenser dispenser = (Dispenser) event.getBlock().getState(); - BlockFace directionFacing = null; - if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) { - org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData(); - directionFacing = dis.getFacing(); - } else { - org.bukkit.block.data.type.Dispenser dis = (org.bukkit.block.data.type.Dispenser) dispenser.getBlockData(); - directionFacing = dis.getFacing(); - } + Dispenser dispenser = (Dispenser) event.getBlock().getState(); + BlockFace directionFacing = null; + if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) { + org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData(); + directionFacing = dis.getFacing(); + } else { + org.bukkit.block.data.type.Dispenser dis = (org.bukkit.block.data.type.Dispenser) dispenser.getBlockData(); + directionFacing = dis.getFacing(); + } - if (directionFacing == BlockFace.EAST && - ploc.getBlockX() != loc.getBlockX() && - ploc.getX() <= loc.getX() + 2.3 && - ploc.getX() >= loc.getX() || - directionFacing == BlockFace.WEST && - ploc.getX() >= loc.getX() - 1.3 && - ploc.getX() <= loc.getX() || - directionFacing == BlockFace.SOUTH && - ploc.getBlockZ() != loc.getBlockZ() && - ploc.getZ() <= loc.getZ() + 2.3 && - ploc.getZ() >= loc.getZ() || - directionFacing == BlockFace.NORTH && - ploc.getZ() >= loc.getZ() - 1.3 && - ploc.getZ() <= loc.getZ()) { + if (directionFacing == BlockFace.EAST && + ploc.getBlockX() != loc.getBlockX() && + ploc.getX() <= loc.getX() + 2.3 && + ploc.getX() >= loc.getX() || + directionFacing == BlockFace.WEST && + ploc.getX() >= loc.getX() - 1.3 && + ploc.getX() <= loc.getX() || + directionFacing == BlockFace.SOUTH && + ploc.getBlockZ() != loc.getBlockZ() && + ploc.getZ() <= loc.getZ() + 2.3 && + ploc.getZ() >= loc.getZ() || + directionFacing == BlockFace.NORTH && + ploc.getZ() >= loc.getZ() - 1.3 && + ploc.getZ() <= loc.getZ()) { - JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(p, EquipMethod.DISPENSER, type, null, item); - plugin.getServer().getPluginManager().callEvent(armorEquipEvent); - if (armorEquipEvent.isCancelled()) { - event.setCancelled(true); - return; - } - } - } - } - } + JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(p, EquipMethod.DISPENSER, type, null, item); + plugin.getServer().getPluginManager().callEvent(armorEquipEvent); + if (armorEquipEvent.isCancelled()) { + event.setCancelled(true); + return; + } + } + } + } + } } @EventHandler public void jobsArmorChangeEvent(JobsArmorChangeEvent event) { - Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); + Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); } @EventHandler public void playerItemHeldEvent(PlayerItemHeldEvent event) { - Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); + Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); } @EventHandler public void playerItemBreakEvent(PlayerItemBreakEvent event) { - Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); + Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); } @EventHandler public void playerItemBreakEvent(InventoryClickEvent event) { - Jobs.getPlayerManager().resetItemBonusCache(((Player) event.getWhoClicked()).getUniqueId()); + Jobs.getPlayerManager().resetItemBonusCache(((Player) event.getWhoClicked()).getUniqueId()); } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java index 9ecff662..9e2729ed 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java @@ -24,8 +24,6 @@ import com.gamingmesh.jobs.actions.ItemActionInfo; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.PlayerCamp; -import net.Zrips.CMILib.Logs.CMIDebug; - public final class JobsPayment14Listener implements Listener { // BlockCookEvent does not have "cooking owner" diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 08454653..f34ca05e 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -26,7 +26,6 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.TimeUnit; -import com.gamingmesh.jobs.config.GeneralConfigManager; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -72,8 +71,8 @@ import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.event.inventory.InventoryType.SlotType; +import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -91,7 +90,6 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; import org.bukkit.permissions.PermissionAttachmentInfo; -import org.checkerframework.checker.nullness.qual.Nullable; import com.bgsoftware.wildstacker.api.enums.StackSplit; import com.gamingmesh.jobs.ItemBoostManager; @@ -136,6 +134,7 @@ import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; public final class JobsPaymentListener implements Listener { @@ -402,7 +401,7 @@ public final class JobsPaymentListener implements Listener { if (player == null) return; - if (Jobs.getGCManager().blockOwnershipRange > 0 && Util.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange) + if (Jobs.getGCManager().blockOwnershipRange > 0 && CMILocation.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange) return; if (!Jobs.getPermissionHandler().hasWorldPermission(player)) @@ -448,9 +447,10 @@ public final class JobsPaymentListener implements Listener { if (fp != null) { if (fp.getTime() > System.currentTimeMillis() && (fp.getInfo().getName().equalsIgnoreCase(bInfo.getName()) || fp.getInfo().getNameWithSub().equalsIgnoreCase(bInfo.getNameWithSub()))) { - Jobs.perform(fp.getPlayer(), fp.getInfo(), fp.getPayment(), fp.getJob()); + Jobs.perform(fp.getPlayer(), fp.getInfo(), fp.getPayment(), fp.getJob(), block, null, null); return; } + Jobs.FASTPAYMENT.remove(player.getUniqueId()); } if (!payForItemDurabilityLoss(player)) @@ -489,7 +489,8 @@ public final class JobsPaymentListener implements Listener { return; // A tool should not trigger a BlockPlaceEvent (fixes stripping logs bug #940) - if (CMIMaterial.get(event.getItemInHand().getType()).isTool()) + // Allow this to trigger with a hoe so players can get paid for farmland. + if (CMIMaterial.get(event.getItemInHand().getType()).isTool() && !event.getItemInHand().getType().toString().endsWith("_HOE")) return; Block block = event.getBlock(); @@ -796,7 +797,7 @@ public final class JobsPaymentListener implements Listener { preInv[i] = preInv[i].clone(); } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + CMIScheduler.get().runTaskLater(new Runnable() { @Override public void run() { final ItemStack[] postInv = player.getInventory().getContents(); @@ -1225,7 +1226,7 @@ public final class JobsPaymentListener implements Listener { if (bos.isDisabled(uuid, block.getLocation())) return; - if (Jobs.getGCManager().blockOwnershipRange > 0 && Util.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange) + if (Jobs.getGCManager().blockOwnershipRange > 0 && CMILocation.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange) return; if (!Jobs.getPermissionHandler().hasWorldPermission(player)) @@ -1316,7 +1317,7 @@ public final class JobsPaymentListener implements Listener { // So lets remove meta in case some plugin removes entity in wrong way. // Need to delay action for other function to properly check for existing meta data relating to this entity before clearing it out // Longer delay is needed due to mob split event being fired few seconds after mob dies and not at same time - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { + CMIScheduler.get().runTaskLater(() -> { lVictim.removeMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata(), plugin); }, 200L); } catch (Throwable ignored) { @@ -1645,7 +1646,7 @@ public final class JobsPaymentListener implements Listener { Player player = (Player) human; - if (!player.isOnline() || event.getFoodLevel() <= player.getFoodLevel()) + if (!player.isOnline() || event.getFoodLevel() <= player.getFoodLevel() || player.getFoodLevel() == 20) return; // check if in creative @@ -1753,12 +1754,15 @@ public final class JobsPaymentListener implements Listener { if (level.getLevel() == level.getMaximumLevel()) { Jobs.action(jPlayer, new BlockCollectInfo(CMIMaterial.BONE_MEAL, ActionType.COLLECT), block); } - } else if ((cmat == CMIMaterial.SWEET_BERRY_BUSH || cmat == CMIMaterial.CAVE_VINES_PLANT || cmat == CMIMaterial.CAVE_VINES) && hand != CMIMaterial.BONE_MEAL.getMaterial()) { + } else if ((cmat == CMIMaterial.SWEET_BERRY_BUSH || cmat == CMIMaterial.CAVE_VINES_PLANT || cmat == CMIMaterial.CAVE_VINES)) { if (cmat == CMIMaterial.SWEET_BERRY_BUSH) { Ageable age = (Ageable) block.getBlockData(); - if (age.getAge() >= 2) + if (age.getAge() == 2 && hand != CMIMaterial.BONE_MEAL.getMaterial()) { Jobs.action(jPlayer, new BlockCollectInfo(CMIMaterial.SWEET_BERRIES, ActionType.COLLECT, age.getAge()), block); + } else if (age.getAge() == 3) { + Jobs.action(jPlayer, new BlockCollectInfo(CMIMaterial.SWEET_BERRIES, ActionType.COLLECT, age.getAge()), block); + } } else { org.bukkit.block.data.type.CaveVinesPlant caveVines = (org.bukkit.block.data.type.CaveVinesPlant) block.getBlockData(); if (caveVines.isBerries()) { @@ -1836,8 +1840,9 @@ public final class JobsPaymentListener implements Listener { // either it's version 1.13+ and we're trying to strip a normal log like oak, // or it's 1.16+ and we're trying to strip a fungi like warped stem if ((Version.isCurrentEqualOrHigher(Version.v1_13_R1) && (block.getType().toString().endsWith("_LOG") || block.getType().toString().endsWith("_WOOD"))) || - (Version.isCurrentEqualOrHigher(Version.v1_16_R1) && (block.getType().toString().endsWith("_STEM") || block.getType().toString().endsWith("_HYPHAE")))) - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.STRIPLOGS), block), 1); + (Version.isCurrentEqualOrHigher(Version.v1_16_R1) && (block.getType().toString().endsWith("_STEM") || block.getType().toString().endsWith("_HYPHAE")))) { + CMIScheduler.get().runTaskLater(() -> Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.STRIPLOGS), block), 1); + } } } @@ -1975,7 +1980,7 @@ public final class JobsPaymentListener implements Listener { if (fp.getTime() > System.currentTimeMillis() - 50L && (fp.getInfo().getName().equalsIgnoreCase(bInfo.getName()) || fp.getInfo().getNameWithSub().equalsIgnoreCase(bInfo.getNameWithSub()))) { - Jobs.perform(fp.getPlayer(), fp.getInfo(), fp.getPayment(), fp.getJob()); + Jobs.perform(fp.getPlayer(), fp.getInfo(), fp.getPayment(), fp.getJob(), block, null, null); breakCache.put(CMILocation.toString(block.getLocation(), ":", true, true), uuid); fp.setTime(System.currentTimeMillis() + 45); } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Loging.java b/src/main/java/com/gamingmesh/jobs/stuff/Loging.java index a2c8f9e6..9b36a9db 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Loging.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Loging.java @@ -8,6 +8,8 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; +import net.Zrips.CMILib.Time.CMITimeManager; + public class Loging { public void recordToLog(JobsPlayer jPlayer, ActionInfo info, Map amounts) { @@ -17,7 +19,7 @@ public class Loging { public void recordToLog(JobsPlayer jPlayer, String actionName, String item, Map amounts) { Map logList = jPlayer.getLog(); Log l = logList.values().stream().findFirst().orElse(null); - if (l != null && TimeManage.timeInInt() != l.getDate()) { + if (l != null && CMITimeManager.timeInInt() != l.getDate()) { Jobs.getJobsDAO().saveLog(jPlayer); jPlayer.getLog().clear(); } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/PerformCommands.java b/src/main/java/com/gamingmesh/jobs/stuff/PerformCommands.java deleted file mode 100644 index c459b53a..00000000 --- a/src/main/java/com/gamingmesh/jobs/stuff/PerformCommands.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gamingmesh.jobs.stuff; - -import org.bukkit.Bukkit; - -import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.container.JobsPlayer; - -public final class PerformCommands { - - public static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) { - String pName = jPlayer.getName(); - - for (String one : job.getCmdOnLeave()) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", pName).replace("[jobname]", job.getName())); - } - } - - public static void performCommandsOnJoin(JobsPlayer jPlayer, Job job) { - String pName = jPlayer.getName(); - - for (String one : job.getCmdOnJoin()) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", pName).replace("[jobname]", job.getName())); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Sorting.java b/src/main/java/com/gamingmesh/jobs/stuff/Sorting.java index cea5046d..8ef7f12f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Sorting.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Sorting.java @@ -11,49 +11,6 @@ import java.util.Map; import com.gamingmesh.jobs.container.LogAmounts; public class Sorting { - public static Map sortDESC(Map unsortMap) { - - // Convert Map to List - List> list = new LinkedList<>(unsortMap.entrySet()); - - // Sort list with comparator, to compare the Map values - Collections.sort(list, new Comparator>() { - @Override - public int compare(Map.Entry o1, Map.Entry o2) { - return (o2.getValue()).compareTo(o1.getValue()); - } - }); - - // Convert sorted map back to a Map - Map sortedMap = new LinkedHashMap<>(); - for (Iterator> it = list.iterator(); it.hasNext();) { - Map.Entry entry = it.next(); - sortedMap.put(entry.getKey(), entry.getValue()); - } - return sortedMap; - } - - public static Map sortDoubleDESC(Map unsortMap) { - - // Convert Map to List - List> list = new LinkedList<>(unsortMap.entrySet()); - - // Sort list with comparator, to compare the Map values - Collections.sort(list, new Comparator>() { - @Override - public int compare(Map.Entry o1, Map.Entry o2) { - return (o2.getValue()).compareTo(o1.getValue()); - } - }); - - // Convert sorted map back to a Map - Map sortedMap = new LinkedHashMap<>(); - for (Iterator> it = list.iterator(); it.hasNext();) { - Map.Entry entry = it.next(); - sortedMap.put(entry.getKey(), entry.getValue()); - } - return sortedMap; - } public static Map sortDoubleDESCByLog(Map unsortMap) { diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java index 7bba46c2..7c210025 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java @@ -60,7 +60,7 @@ public final class TabComplete implements TabCompleter { temp.addAll(Jobs.getScheduleManager().getConf().getConfig().getConfigurationSection("Boost").getKeys(false)); break; case "[time]": - temp.add("1hour10minute20s"); + temp.add("1h10m20s"); break; case "[questname]": case "[quest]": diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TimeManage.java b/src/main/java/com/gamingmesh/jobs/stuff/TimeManage.java deleted file mode 100644 index 9410d2d5..00000000 --- a/src/main/java/com/gamingmesh/jobs/stuff/TimeManage.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gamingmesh.jobs.stuff; - -import java.text.SimpleDateFormat; -import java.util.Calendar; - -public class TimeManage { - - public static int timeInInt() { - return timeInInt(System.currentTimeMillis()); - } - - public static int timeInInt(Long time) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(time); - return Integer.valueOf(new SimpleDateFormat("YYMMdd").format(calendar.getTime())); - } -} diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 50f47a2b..5e82a31f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -9,19 +9,15 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.TreeMap; import java.util.UUID; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import com.gamingmesh.jobs.CMILib.CMIEnchantment; -import com.gamingmesh.jobs.actions.EnchantActionInfo; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.World; import org.bukkit.attribute.Attribute; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -38,6 +34,8 @@ import org.bukkit.potion.PotionType; import org.bukkit.util.BlockIterator; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIEnchantment; +import com.gamingmesh.jobs.actions.EnchantActionInfo; import com.gamingmesh.jobs.container.JobsWorld; import net.Zrips.CMILib.Items.CMIMaterial; @@ -46,37 +44,14 @@ import net.Zrips.CMILib.Version.Version; @SuppressWarnings("deprecation") public final class Util { - private static Map jobsEditorMap = new HashMap<>(), questsEditorMap = new HashMap<>(); - + private static Map jobsEditorMap = new HashMap<>(); + private static Map questsEditorMap = new HashMap<>(); private static Map jobsWorlds = new HashMap<>(); public static final List LEAVECONFIRM = new ArrayList<>(); - private final static TreeMap map = new TreeMap(); - - static { - map.put(1000, "M"); - map.put(900, "CM"); - map.put(500, "D"); - map.put(400, "CD"); - map.put(100, "C"); - map.put(90, "XC"); - map.put(50, "L"); - map.put(40, "XL"); - map.put(10, "X"); - map.put(9, "IX"); - map.put(5, "V"); - map.put(4, "IV"); - map.put(1, "I"); - } - - public final static String toRoman(int number) { - int l = map.floorKey(number); - if (number == l) { - return map.get(number); - } - return map.get(l) + toRoman(number - l); - } + // for confirmation of skipping quest + public static final List SKIPCONFIRM = new ArrayList<>(); public static List getPistonRetractBlocks(BlockPistonRetractEvent event) { if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) { @@ -88,17 +63,6 @@ public final class Util { return blocks; } - public static double getDistance(Location loc1, Location loc2) { - if (loc1 == null || loc2 == null || loc1.getWorld() != loc2.getWorld()) - return Integer.MAX_VALUE; - - try { - return loc1.distance(loc2); - } catch (Throwable e) { - return Integer.MAX_VALUE; - } - } - public static String getRealType(Entity entity) { if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) { return entity.getType().name(); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/VersionChecker.java b/src/main/java/com/gamingmesh/jobs/stuff/VersionChecker.java index 58fbf75c..d71b702e 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/VersionChecker.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/VersionChecker.java @@ -12,52 +12,55 @@ import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; + public final class VersionChecker { private Jobs plugin; public VersionChecker(Jobs plugin) { - this.plugin = plugin; + this.plugin = plugin; } public void VersionCheck(final Player player) { - if (!Jobs.getGCManager().isShowNewVersion()) - return; + if (!Jobs.getGCManager().isShowNewVersion()) + return; - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { - String newVersion = getNewVersion(); - if (newVersion == null) - return; + CMIScheduler.get().runTaskAsynchronously(() -> { + String newVersion = getNewVersion(); + if (newVersion == null) + return; - int currentVersion = Integer.parseInt(plugin.getDescription().getVersion().replace(".", "")); - int newVer = Integer.parseInt(newVersion.replace(".", "")); + int currentVersion = Integer.parseInt(plugin.getDescription().getVersion().replace(".", "")); + int newVer = Integer.parseInt(newVersion.replace(".", "")); - if (newVer <= currentVersion || currentVersion >= newVer) - return; + if (newVer <= currentVersion || currentVersion >= newVer) + return; - List msg = Arrays.asList( - ChatColor.GREEN + "*********************** " + plugin.getDescription().getName() + " **************************", - ChatColor.GREEN + "* " + newVersion + " is now available! Your version: " + currentVersion, - ChatColor.GREEN + "* " + ChatColor.DARK_GREEN + plugin.getDescription().getWebsite(), - ChatColor.GREEN + "************************************************************"); - for (String one : msg) - if (player != null) - player.sendMessage(one); - else - Jobs.consoleMsg(one); - }); + List msg = Arrays.asList( + ChatColor.GREEN + "*********************** " + plugin.getDescription().getName() + " **************************", + ChatColor.GREEN + "* " + newVersion + " is now available! Your version: " + currentVersion, + ChatColor.GREEN + "* " + ChatColor.DARK_GREEN + plugin.getDescription().getWebsite(), + ChatColor.GREEN + "************************************************************"); + for (String one : msg) + if (player != null) + player.sendMessage(one); + else + CMIMessages.consoleMessage(one); + }); } public String getNewVersion() { - try { - URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=4216").openConnection(); - String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); - if (version.length() <= 8) - return version; - } catch (Throwable t) { - Jobs.consoleMsg("&cFailed to check for " + plugin.getDescription().getName() + " update on spigot web page."); - } - return null; + try { + URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=4216").openConnection(); + String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); + if (version.length() <= 8) + return version; + } catch (Throwable t) { + CMIMessages.consoleMessage("&cFailed to check for " + plugin.getDescription().getName() + " update on spigot web page."); + } + return null; } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java index d50e8301..c6206c58 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java @@ -9,6 +9,8 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.stuff.Util; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; + @SuppressWarnings("deprecation") public class JobsChatEvent implements Listener { @@ -25,8 +27,7 @@ public class JobsChatEvent implements Listener { final String msg = Util.getJobsEditorMap().remove(event.getPlayer().getUniqueId()); if (msg != null) { - plugin.getServer().getScheduler().runTask(plugin, - () -> event.getPlayer().performCommand(msg + event.getMessage())); + CMIScheduler.get().runTask(() -> event.getPlayer().performCommand(msg + event.getMessage())); event.setCancelled(true); } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/KyoriChatEvent.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/KyoriChatEvent.java index bb223640..f3b5242c 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/KyoriChatEvent.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/KyoriChatEvent.java @@ -10,6 +10,7 @@ import com.gamingmesh.jobs.stuff.Util; import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.event.player.AsyncChatEvent; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; import net.kyori.adventure.text.TextReplacementConfig; public final class KyoriChatEvent extends Complement2 implements Listener { @@ -17,45 +18,44 @@ public final class KyoriChatEvent extends Complement2 implements Listener { private Jobs plugin; public KyoriChatEvent(Jobs plugin) { - this.plugin = plugin; + this.plugin = plugin; } @EventHandler(priority = EventPriority.NORMAL) public void asyncChatEvent(final AsyncChatEvent event) { - if (event.isCancelled() || Util.getJobsEditorMap().isEmpty()) - return; + if (event.isCancelled() || Util.getJobsEditorMap().isEmpty()) + return; - final String msg = Util.getJobsEditorMap().remove(event.getPlayer().getUniqueId()); - if (msg != null) { - plugin.getServer().getScheduler().runTask(plugin, - () -> event.getPlayer().performCommand(msg + serialize(event.message()))); - event.setCancelled(true); - } + final String msg = Util.getJobsEditorMap().remove(event.getPlayer().getUniqueId()); + if (msg != null) { + CMIScheduler.get().runTask(() -> event.getPlayer().performCommand(msg + serialize(event.message()))); + event.setCancelled(true); + } } // Adding to chat prefix job name @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerChat(AsyncChatEvent event) { - if (!Jobs.getGCManager().getModifyChat()) - return; + if (!Jobs.getGCManager().getModifyChat()) + return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); - String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equals(" ")) - honorific = ""; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); + String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; + if (honorific.equals(" ")) + honorific = ""; - // TODO displayName returns the player display name not the chat component from - // chat plugins, like Essentials - // Now there is a parameter "player", so literally we need to add 800+ chat plugins - // to this plugin as dependency? - // 3rd attempt: now we tried to use text replacement config builder to match the variable - // result: instead of replacing the variable, now the chat message never been sent - //event.composer((player, displayName, msg) -> msg - //.replaceText(TextReplacementConfig.builder().match("{jobs}").once().replacement(h).build())); + // TODO displayName returns the player display name not the chat component from + // chat plugins, like Essentials + // Now there is a parameter "player", so literally we need to add 800+ chat plugins + // to this plugin as dependency? + // 3rd attempt: now we tried to use text replacement config builder to match the variable + // result: instead of replacing the variable, now the chat message never been sent + //event.composer((player, displayName, msg) -> msg + //.replaceText(TextReplacementConfig.builder().match("{jobs}").once().replacement(h).build())); - event.message(ChatRenderer.defaultRenderer().render(event.getPlayer(), event.getPlayer().displayName(), event.message(), event.getPlayer()).replaceText(TextReplacementConfig.builder().match( - "\\{jobs\\}").replacement(honorific).build())); - // 4th attempt: composeChat -> doing nothing + event.message(ChatRenderer.defaultRenderer().render(event.getPlayer(), event.getPlayer().displayName(), event.message(), event.getPlayer()).replaceText(TextReplacementConfig.builder().match( + "\\{jobs\\}").replacement(honorific).build())); + // 4th attempt: composeChat -> doing nothing // event.message(ChatComposer.DEFAULT.composeChat(event.getPlayer(), event.getPlayer().displayName(), event.message()) // .replaceText(TextReplacementConfig.builder().match("\\{jobs\\}").replacement(honorific).build())); } @@ -63,22 +63,22 @@ public final class KyoriChatEvent extends Complement2 implements Listener { // Changing chat prefix variable to job name @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerChatLow(AsyncChatEvent event) { - onPlayerChatHigh(event); + onPlayerChatHigh(event); } // Changing chat prefix variable to job name @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerChatHigh(AsyncChatEvent event) { - if (Jobs.getGCManager().getModifyChat()) - return; + if (Jobs.getGCManager().getModifyChat()) + return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); - String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equals(" ")) - honorific = ""; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); + String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; + if (honorific.equals(" ")) + honorific = ""; - event.message(ChatRenderer.defaultRenderer().render(event.getPlayer(), event.getPlayer().displayName(), event.message(), event.getPlayer()).replaceText(TextReplacementConfig.builder().match( - "\\{jobs\\}").replacement(honorific).build())); + event.message(ChatRenderer.defaultRenderer().render(event.getPlayer(), event.getPlayer().displayName(), event.message(), event.getPlayer()).replaceText(TextReplacementConfig.builder().match( + "\\{jobs\\}").replacement(honorific).build())); // event.message(ChatComposer.DEFAULT // .composeChat(event.getPlayer(), event.getPlayer().displayName(), event.message()) diff --git a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java index 11ce1ae2..c5afd8a1 100644 --- a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java +++ b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java @@ -24,6 +24,8 @@ import com.gamingmesh.jobs.economy.BufferedEconomy; import com.gamingmesh.jobs.economy.BufferedPayment; import com.gamingmesh.jobs.economy.Economy; +import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; + public class BufferedPaymentTask implements Runnable { private BufferedEconomy bufferedEconomy; @@ -41,7 +43,7 @@ public class BufferedPaymentTask implements Runnable { double money = payment.get(CurrencyType.MONEY); if (money > 0) { if (Jobs.getGCManager().isEconomyAsync()) { - org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(bufferedEconomy.getPlugin(), () -> economy.depositPlayer(payment.getOfflinePlayer(), money)); + CMIScheduler.get().runTaskAsynchronously(() -> economy.depositPlayer(payment.getOfflinePlayer(), money)); } else { economy.depositPlayer(payment.getOfflinePlayer(), money); } diff --git a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentThread.java b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentThread.java index 2bf41829..a5fe6949 100644 --- a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentThread.java +++ b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentThread.java @@ -21,6 +21,8 @@ package com.gamingmesh.jobs.tasks; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.economy.BufferedEconomy; +import net.Zrips.CMILib.Messages.CMIMessages; + public class BufferedPaymentThread extends Thread { private volatile boolean running = true; private int sleep; @@ -35,7 +37,7 @@ public class BufferedPaymentThread extends Thread { @Override public void run() { - Jobs.consoleMsg("&eStarted buffered payment thread."); + CMIMessages.consoleMessage("&eStarted buffered payment thread."); while (running) { try { @@ -50,11 +52,11 @@ public class BufferedPaymentThread extends Thread { economy.payAll(); } catch (Throwable t) { t.printStackTrace(); - Jobs.consoleMsg("&c[Jobs] Exception in BufferedPaymentThread, stopping economy payments!"); + CMIMessages.consoleMessage("&c[Jobs] Exception in BufferedPaymentThread, stopping economy payments!"); running = false; } } - Jobs.consoleMsg("&eBuffered payment thread shutdown."); + CMIMessages.consoleMessage("&eBuffered payment thread shutdown."); } public void shutdown() { diff --git a/src/main/java/com/gamingmesh/jobs/tasks/DatabaseSaveThread.java b/src/main/java/com/gamingmesh/jobs/tasks/DatabaseSaveThread.java index d53325e0..0c4994fd 100644 --- a/src/main/java/com/gamingmesh/jobs/tasks/DatabaseSaveThread.java +++ b/src/main/java/com/gamingmesh/jobs/tasks/DatabaseSaveThread.java @@ -20,6 +20,8 @@ package com.gamingmesh.jobs.tasks; import com.gamingmesh.jobs.Jobs; +import net.Zrips.CMILib.Messages.CMIMessages; + public class DatabaseSaveThread extends Thread { private volatile boolean running = true; @@ -33,7 +35,7 @@ public class DatabaseSaveThread extends Thread { @Override public void run() { - Jobs.consoleMsg("&eStarted database save task."); + CMIMessages.consoleMessage("&eStarted database save task."); while (running) { try { @@ -46,12 +48,12 @@ public class DatabaseSaveThread extends Thread { Jobs.getPlayerManager().saveAll(); } catch (Throwable t) { t.printStackTrace(); - Jobs.consoleMsg("&c[Jobs] Exception in DatabaseSaveTask, stopping auto save!"); + CMIMessages.consoleMessage("&c[Jobs] Exception in DatabaseSaveTask, stopping auto save!"); running = false; } } - Jobs.consoleMsg("&eDatabase save task shutdown!"); + CMIMessages.consoleMessage("&eDatabase save task shutdown!"); } diff --git a/src/main/resources/jobs/builder.yml b/src/main/resources/jobs/builder.yml index ce098582..5bc92a8b 100644 --- a/src/main/resources/jobs/builder.yml +++ b/src/main/resources/jobs/builder.yml @@ -382,6 +382,10 @@ Builder: income: 1.5 points: 1.5 experience: 2 + tinted_glass: + income: 1.5 + points: 1.5 + experience: 2 iron_trapdoor: income: 1.5 points: 1.5 diff --git a/src/main/resources/jobs/miner.yml b/src/main/resources/jobs/miner.yml index f2dd32f5..4cdbcdfa 100644 --- a/src/main/resources/jobs/miner.yml +++ b/src/main/resources/jobs/miner.yml @@ -55,6 +55,10 @@ Miner: income: 1 points: 1 experience: 1 + deepslate: + income: 1.25 + points: 1.25 + experience: 1.25 granite: income: 1 points: 1 diff --git a/src/main/resources/locale/messages_de.yml b/src/main/resources/locale/messages_de.yml index 02470050..2dd340b4 100644 --- a/src/main/resources/locale/messages_de.yml +++ b/src/main/resources/locale/messages_de.yml @@ -318,6 +318,7 @@ command: actions: '&eMögliche Optionen:' leftClick: '&eLinksklick für mehr Informationen.' middleClick: '&eMittelklick um den Job zu verlassen.' + qClick: '&eQ Taste um den Job zu verlassen.' rightClick: '&eRechtsklick um den Job anzunehmen.' leftSlots: '&eOffene Stellen:&f ' working: '&2Ausgewählt' diff --git a/src/main/resources/locale/messages_it_IT.yml b/src/main/resources/locale/messages_it_IT.yml index 9be29aca..399bea74 100644 --- a/src/main/resources/locale/messages_it_IT.yml +++ b/src/main/resources/locale/messages_it_IT.yml @@ -470,6 +470,7 @@ command: args: '[jobname] [questname] (playerName)' output: questSkipForCost: '&2You skipped the quest and paid:&e %amount%$' + confirmationNeed: '&cAre you sure you want to skip&e [questName]&c quest? Type the command again within&6 [time] seconds &cto confirm!' quests: help: info: List available quests diff --git a/src/main/resources/locale/messages_nl_NL.yml b/src/main/resources/locale/messages_nl_NL.yml index 99f573e5..125b8265 100644 --- a/src/main/resources/locale/messages_nl_NL.yml +++ b/src/main/resources/locale/messages_nl_NL.yml @@ -4,7 +4,7 @@ economy: nomoney: '&cSorry, geen geld over in de nationale bank.' limitedItem: error: - levelup: '&cJe moet levelen in [jobname] om deze item te gebruiken!' + levelup: '&cJe moet niveaus omhoog in [jobname] om deze item te gebruiken!' general: info: toplineseparator: '&7*********************** &6%playername% &7***********************' @@ -18,10 +18,10 @@ general: 'true': '&2True' 'false': '&cFalse' blocks: - furnace: Furnace - smoker: Smoker - blastfurnace: Blast furnace - brewingstand: Brewing stand + furnace: Oven + smoker: Roker + blastfurnace: Hoogoven + brewingstand: Brouwstand admin: error: '&cEr is een fout opgetreden in de command.' success: '&eJe command is uitgevoerd.' @@ -36,8 +36,8 @@ general: ingame: '&cJe kan deze command alleen uitvoeren in game!' fromconsole: '&cJe kan deze command alleen uitvoeren in console!' worldisdisabled: '&cJe kan deze command niet uitvoeren in deze wereld' - newRegistration: '&eRegistered new ownership for [block] &7[current]&e/&f[max]' - noRegistration: '&cYou''ve reached max [block] count!' + newRegistration: '&eGeregistreerd nieuw eigendom voor [block] &7[current]&e/&f[max]' + noRegistration: '&cJe hebt de maximale registraties voor [block] bereikt!' command: help: output: @@ -56,8 +56,8 @@ command: nextPageOff: '&7 Volgende >>----' pageCount: '&2[current]/[total]' pageCountHover: '&e[totalEntries] entries' - prevPageGui: '&6Previous page ' - nextPageGui: '&6Next Page' + prevPageGui: '&6Vorige Pagina ' + nextPageGui: '&6Volgende Pagina' moneyboost: help: info: Verhoogt de geldwinst voor alle spelers @@ -93,12 +93,12 @@ command: infostats: '&c-----> &aExptarief x%boost% ingeschakeld&c <-------' schedule: help: - info: Enables the given scheduler + info: Zet het gegeven schema aan args: enable [scheduleName] [untilTime] output: - noScheduleFound: '&cSchedule with this name not found.' - alreadyEnabled: '&cThis schedule already enabled.' - enabled: '&eSchedule have been enabled from&a %from%&e until&a %until%' + noScheduleFound: '&cSchema met deze naam niet gevonden.' + alreadyEnabled: '&cDit schema en al aangezet.' + enabled: '&eSchema is aangezet vanm&a %from%&e tot&a %until%' itembonus: help: info: Controleer de itembonus @@ -107,7 +107,7 @@ command: list: '&e[jobname]: %money% %points% %exp%' notAplyingList: '&7[jobname]: %money% %points% %exp%' hover: '&7%itemtype%' - hoverLevelLimits: "&7From level: %from% \n&7Until level: %until%" + hoverLevelLimits: "&7Vanaf niveau: %from% \n&7Tot niveau: %until%" edititembonus: help: info: Verander de itembonus @@ -134,7 +134,7 @@ command: args: '' limit: help: - info: Laat betalingslimieten zien voor banen + info: Toon betalingslimieten voor banen args: '[playername]' output: moneytime: '&eResterende tijd totdat geldlimiet opnieuw wordt ingesteld: &2%time%' @@ -166,7 +166,7 @@ command: noQuests: '&eKan geen zoektoch vinden' points: help: - info: Laat zien hoeveel punten een speler heeft + info: Toon het puntentotaal van een speler args: '[playername]' currentpoints: ' &eHuidige puntbedrag: &6%currentpoints%' totalpoints: ' &eTotaal aantal verzamelde punten tot nu toe: &6%totalpoints%' @@ -202,7 +202,7 @@ command: lookHover: '&6Druk op om informatie te zoeken van blok dat je zoekt' editquests: help: - info: Edit current quests. + info: Wijzig huidige quests. args: '' list: quest: '&eQuests:' @@ -213,13 +213,13 @@ command: objectiveRemove: '&c[X]' objectiveAdd: ' -> &e[&2+&e]' modify: - newValue: '&eEnter new value' - enter: '&eEnter new name or press ' + newValue: '&eVul een nieuwe waarde in' + enter: '&eVul een nieuwe naam in of druk op ' hand: '&6HAND ' - handHover: '&6Press to grab info from item in your hand' - or: '&eor ' - look: '&6LOOKING AT' - lookHover: '&6Press to grab info from block you are looking' + handHover: '&6druk om de info te verkrijgen van het item in je hand' + or: '&eof ' + look: '&6KIJKEN NAAR' + lookHover: '&6Druk om de info te krijgen van het blok waar je naar kijkt' blockinfo: help: info: Toont blokinformatie waar u naar kijkt. @@ -240,26 +240,26 @@ command: usage: ' &eGebruik: &6%first% &eor &6%second%' placeholders: help: - info: List out all placeholders + info: Lijst van alle placeholders args: (parse) (placeholder) output: list: '&e[place]. &7[placeholder]' - outputResult: ' &eresult: &7[result]' - parse: '&6[placeholder] &7by [source] &6result &8|&f[result]&8|' + outputResult: ' &eresultaat: &7[result]' + parse: '&6[placeholder] &7door [source] &6resultaat &8|&f[result]&8|' entitylist: help: info: Toont alle mogelijke entities kunnen worden gebruikt met een plugin. args: '' stats: help: - info: Toont de level die je bent in elke baan. + info: Toont het niveau dat je bent in elke baan. args: '[playername]' error: nojob: Sluit eerst aan bij een baan. output: - message: 'Level %joblevel% for %jobname%: %jobxp%/%jobmaxxp% xp' - max-level: ' &cMax level - %jobname%' - bossBarOutput: 'Lvl %joblevel% %jobname%: %jobxp%/%jobmaxxp% xp%gain%' + message: 'Niveau %joblevel% voor %jobname%: %jobxp%/%jobmaxxp% xp' + max-level: ' &cMax niveau - %jobname%' + bossBarOutput: 'Niveau %joblevel% %jobname%: %jobxp%/%jobmaxxp% xp%gain%' bossBarGain: ' &7(&f%gain%&7)' shop: help: @@ -270,8 +270,8 @@ command: currentPoints: '&eJe hebt: &6%currentpoints%' price: '&ePrijs: &6%price%' reqJobs: '&eBenodigde baan:' - reqJobsList: ' &6%jobsname%&e: &e%level% lvl' - reqTotalLevel: '&6Benodigde level: &e%totalLevel%' + reqJobsList: ' &6%jobsname%&e: &eniveau %level%' + reqTotalLevel: '&6Benodigde niveau: &e%totalLevel%' reqJobsColor: '&c' reqJobsLevelColor: '&4' reqTotalLevelColor: '&4' @@ -280,7 +280,7 @@ command: NoPermToBuy: '&cGeen permissies om dit te kopen' NoJobReqForitem: '&cJe hebt niet de benodigde baan (&6%jobname%&e) met de benodigde (&6%joblevel%&e) level' NoPoints: '&cJe hebt niet genoeg punten' - NoTotalLevel: '&cTotale banen level is te laag (%totalLevel%)' + NoTotalLevel: '&cTotale banen niveau is te laag (%totalLevel%)' Paid: '&eJe hebt &6%amount% &ebetaald voor dit item' archive: help: @@ -298,17 +298,17 @@ command: info: help: title: '&2*** &eBanen&2 ***' - info: Laat zien hoeveel een baan wordt betaald en voor wat. + info: Toon hoeveel een baan betaald en voor wat. penalty: '&eDeze baan heeft &c[penalty]% &eboete vanwege te veel spelers die erin werken.' bonus: '&eDeze baan heeft &2[bonus]% &ebonus omdat er weinig spelers erin werken.' args: '[jobname] [action]' actions: '&eGeldige acties zijn: &f%actions%' - max: ' - &emaximale level:&f ' - newMax: ' &eMaximale level: &f[max]' + max: ' - &emaximale niveau:&f ' + newMax: ' &eMaximale niveau: &f[max]' material: '&7%material%' - levelRange: ' &a(&e%levelFrom% &a- &e%levelUntil% &alevels)' - levelFrom: ' &a(van &e%levelFrom% &alevel)' - levelUntil: ' &a(tot &e%levelUntil% &alevel)' + levelRange: ' &a(&e%levelFrom% &a- &e%levelUntil% &aniveau)' + levelFrom: ' &a(van &e%levelFrom% &aniveau)' + levelUntil: ' &a(tot &e%levelUntil% &aniveau)' money: ' &2%money%$' points: ' &6%points%pts' exp: ' &e%exp%xp' @@ -317,14 +317,14 @@ command: jobinfo: '&e[jobname] informatie!' actions: '&eGeldige acties zijn:' leftClick: '&eLinker Muisknop voor meer info' - middleClick: '&eMiddle Click to leave this job' + middleClick: '&eMiddelste Muisknop om deze baan te verlaten' rightClick: '&eRechter Muisknop om aan te sluiten bij de baan' leftSlots: '&eOpen plaatsen:&f ' working: '&2&nal aan het werken' - cantJoin: '&cYou can''t join to the selected job.' - max: '&eMaximale level:&f ' + cantJoin: '&cJe kan je niet aansluiten bij de geselecteerde baan.' + max: '&eMaximale niveau:&f ' back: '&e<<< Terug' - next: '&eNext >>>' + next: '&eVolgende >>>' output: break: info: '&eBreken' @@ -391,13 +391,13 @@ command: none: '%jobname% geeft geen geld voor custom-spelers slachten.' collect: info: '&eCollect' - none: '%jobname% does not get money for collecting blocks.' + none: '%jobname% geeft geen geld voor het verzamelen van blokken.' bake: info: '&eBake' - none: '%jobname% does not get money for cooking foods.' + none: '%jobname% geeft geen geld voor het koken van voedsel.' playerinfo: help: - info: Laat zien hoeveel elke baan wordt betaald en voor wat op een andere speler. + info: Toon hoeveel elke baan betaald en voor wat op een andere speler. args: '[playername] [jobname] [action]' join: help: @@ -410,30 +410,30 @@ command: rejoin: '&cJe kan niet opnieuw aansluiten. Wacht [time]' rejoin: '&aKlik hier om opnieuw aan te sluiten: ' success: Je bent bij de baan %jobname% aangesloten. - confirm: '&2Klik om de actie voor &7[jobname] &2baan te verifiëren.' + confirm: '&2Klik om de actie voor &7[jobname] &2baan te bevestigen.' leave: help: info: Verlaat de geselecteerde baan. args: '[oldplayerjob]' success: Je hebt de baan %jobname% verlaten. - confirmationNeed: '&cAre you sure you want to leave from&e [jobname]&c job? Type the command again within&6 [time] seconds &cto confirm!' + confirmationNeed: '&cWeet je zeker dat je de baan &e [jobname]&c wilt verlaten? Typ het commando opnieuw binnen&6 [time] secondes &com te bevestigen!' leaveall: help: info: Verlaat al je banen. error: nojobs: Je hebt geen baan om te verlaten! success: Je hebt al je banen verlaten. - confirmationNeed: '&cAre you sure you want to leave from all jobs? Type the command again within&6 [time] seconds &cto confirm!' + confirmationNeed: '&cWeet je zeker dat je all je banen wilt verlaten? Typ het commando opnieuw binnen&6 [time] secondes &com te bevestigen!' explored: help: info: Bekijk wie allemaal deze chunk heeft bezocht error: noexplore: Niemand heeft deze chunk bezocht - fullExplore: '&aThis chunk is fully explored' + fullExplore: '&aDeze chunk is al volledig onderzocht' list: '&e%place%. %playername%' browse: help: - info: Laat alle banen zien die jij kan joinen. + info: Toon alle banen die jij kan joinen. error: nojobs: Er zijn geen banen die je kan joinen. output: @@ -463,13 +463,13 @@ command: info: Blok van eigenaar wissen args: '[playername]' output: - cleared: '&2Removed &7[furnaces] &2furnaces, &7[brewing] &2brewing stands, &7[smoker]&2 smokers and &7[blast]&2 blast furnaces.' + cleared: '&2Verwijderd &7[furnaces] &2Ovens, &7[brewing] &2Brouwerijen, &7[smoker]&2 Rokers and &7[blast]&2 Hoogovens.' skipquest: help: - info: Skip defined quest and get new one + info: sla de gedefineerde quest over en krijg een nieuwe args: '[jobname] [questname] (playerName)' output: - questSkipForCost: '&2You skipped the quest and paid:&e %amount%$' + questSkipForCost: '&2Je hebt de quest overgeslagen en betaalde:&e %amount%$' quests: help: info: Lijst van beschikbare zoektochten @@ -478,233 +478,233 @@ command: noquests: '&cEr zijn geen zoektochten' toplineseparator: '&7*********************** &6[playerName] &2(&f[questsDone]&2) &7***********************' status: - changed: '&2The quests status has been changed to&r %status%' - started: '&aStarted' - stopped: '&cStopped' + changed: '&2De quests status is veranderd naar&r %status%' + started: '&aGestart' + stopped: '&cGestopt' output: completed: '&2 !Voltooid!&r ' questLine: '[progress] &7[questName] &f[done]&7/&8[required]' - skip: '&7Click to skip this quest' - skips: '&7Left skips: &f[skips]' - hover: "&f[jobName] \n[desc] \n&7New quest in: [time]" + skip: '&7Klik op deze quest over te slaan' + skips: '&7hoeveelheid overslaan: &f[skips]' + hover: "&f[jobName] \n[desc] \n&7Nieuwe quest na: [time]" fire: help: - info: Fire the player from the job. + info: Ontsla de speler van de baan. args: '[playername] [jobname]' error: - nojob: Player does not have the job %jobname%. + nojob: Speler werkt niet als %jobname%. output: - target: You have been fired from %jobname%. + target: Je bent ontslagen van %jobname%. fireall: help: - info: Fire player from all their jobs. + info: Ontsla speler van alle banen. args: '[playername]/all' error: - nojobs: Player does not have any jobs to be fired from! + nojobs: Speler heeft geeb banen om van ontslagen te worden! output: - target: You have been fired from all your jobs. + target: Je bent ontslagen van al je banen. employ: help: - info: Employ the player to the job. + info: Neem de speler in dienst. args: '[playername] [jobname]' error: - alreadyin: Player is already in the job %jobname%. - fullslots: You cannot join the job %jobname%, there are no slots available. + alreadyin: Speler is al in dienst van %jobname%. + fullslots: Je kan niet aangenomen worden als %jobname%, er zijn geen vrije plekken over. output: - target: You have been employed as a %jobname%. + target: Je bent aangenomen als een %jobname%. top: help: - info: Shows top players by jobs name. + info: Geeft de top spelers weer bij baan. args: '[jobname]/clear pageNumber' error: - nojob: Can't find any job with this name. + nojob: Kan geen banen vinden met deze naam. output: - topline: '&aTop&e %amount% &aplayers by &e%jobname% &ajob' - list: '&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp' - prev: '&e<<<<< Prev page &2|' - next: '&2|&e Next Page >>>>' - show: '&2Show from &e[from] &2until &e[until] &2top list' + topline: '&aTop&e %amount% &aspelers bij &e%jobname% &abaan' + list: '&e%number%&a. &e%playername% &aniveau &e%level% &amet&e %exp% &aexp' + prev: '&e<<<<< Vorige Pagina &2|' + next: '&2|&e Volgende Pagina >>>>' + show: '&2Toon van &e[from] &2tot &e[until] &2top lijst' gtop: help: - info: Shows top players by global jobs level. + info: Geef top players weer bij globale baan niveaus. args: clear/pageNumber error: - nojob: Can't find any information. + nojob: Kan geen informatie vinden. output: - topline: '&aTop&e %amount% &aplayers by global job level' - list: '&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp' - prev: '&e<<<<< Prev page &2|' - next: '&2|&e Next Page >>>>' - show: '&2Show from &e[from] &2until &e[until] &2global top list' + topline: '&aTop&e %amount% &aspelers bij globale baan niveau' + list: '&e%number%&a. &e%playername% &aniveau &e%level% &amet&e %exp% &aexp' + prev: '&e<<<<< Vorige Pagina &2|' + next: '&2|&e Volgende Pagina >>>>' + show: '&2Toon van &e[from] &2tot &e[until] &2globale top lijst' area: help: - info: Modify restricted areas. + info: Beperkte gebieden wijzigen. args: add/remove/info/list - addUsage: '&eUsage: &6/Jobs area add [areaName/wg:worldGuardAreaName] [bonus]' - removeUsage: '&eUsage: &6/Jobs area remove [areaName]' + addUsage: '&eGebruik: &6/Jobs area add [areaName/wg:worldGuardAreaNaam] [bonus]' + removeUsage: '&eGebruik: &6/Jobs area remove [areaNaam]' output: - addedNew: '&eAdded a new restricted area with &6%bonus% &ebonus' - removed: '&eRemoved the restricted area &6%name%' + addedNew: '&eNieuw beperkt gebied toegevoegd met &6%bonus% &ebonus' + removed: '&eBeperkt gebied &6%name% &everwijderd' list: '&e%number%&a. &e%areaname% &e%worldname% (&a%x1%:%y1%:%z1%/&e%x2%:%y2%:%z2%) &6%bonus%' wgList: '&e%number%&a. WorldGuard: &e%areaname% &6%bonus%' - noAreas: '&eThere are no saved restricted areas' - noAreasByLoc: '&eThere are no restricted areas in this location' - areaList: '&eRestricted areas by your location: &6%list%' - selected1: '&eSelected the first point: &6%x%:%y%:%z%' - selected2: '&eSelected the second point: &6%x%:%y%:%z%' - select: '&eSelect 2 points with the selection tool (%tool%)' - exist: '&eRestriction area by this name already exists' - dontExist: '&eRestriction area by this name does not exist' - wgDontExist: '&eWorldGuard area by this name does not exist' + noAreas: '&eEr zijn geen opgeslagen beperkte gebieden' + noAreasByLoc: '&eEr zijn geen beperkte gebieden op deze locatie' + areaList: '&eBepwerkt gebied op jouw locatie: &6%list%' + selected1: '&eEerste punt geselecteerd: &6%x%:%y%:%z%' + selected2: '&eTweede punt geselecteerd: &6%x%:%y%:%z%' + select: '&e2 punten geselecteerd met de selectie tool (%tool%)' + exist: '&Beperkt gebied met deze naam bestaat al' + dontExist: '&Beperkt gebied met deze naam bestaat niet' + wgDontExist: '&eWorldGuard gebied met deze naam bestaat niet' log: help: - info: Shows statistics. + info: Toon statistieken. args: '[playername]' output: topline: '&7************************* &6%playername% &7*************************' ls: '&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%' - money: '&6money: %amount% ' + money: '&6geld: %amount% ' exp: '&eexp: %amount% ' - points: '&6points: %amount%' - totalIncomes: ' &6Total money:&2 %money%&6, Total exp:&2 %exp%&6, Total points:&2 %points%' + points: '&6punten: %amount%' + totalIncomes: ' &6Totaalbedrag:&2 %money%&6, Exp totaal:&2 %exp%&6, Puntentotaal:&2 %points%' bottomline: '&7***********************************************************' - prev: '&e<<<<< Prev page &2|' - next: '&2|&e Next Page >>>>' - nodata: '&cData not found' + prev: '&e<<<<< Vorige Pagina &2|' + next: '&2|&e Volgende Pagina >>>>' + nodata: '&cData niet gevonden' glog: help: - info: Shows global statistics. + info: Toon globale statestieken. args: '' output: - topline: '&7*********************** &6Global statistics &7***********************' + topline: '&7*********************** &6Globale statestieken &7***********************' ls: '&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%' - money: '&6money: %amount% ' + money: '&6geld: %amount% ' exp: '&eexp: %amount% ' - points: '&6points: %amount%' - totalIncomes: ' &6Total money:&2 %money%&6, Total exp:&2 %exp%&6, Total points:&2 %points%' + points: '&6punten: %amount%' + totalIncomes: ' &6Totaalbedrag:&2 %money%&6, Exp totaal:&2 %exp%&6, Puntentotaal:&2 %points%' bottomline: '&7**************************************************************' - nodata: '&cData not found' + nodata: '&cData niet gevonden' transfer: help: - info: Transfer a player's job from an old job to a new job. + info: Plaats de speler over een oude baan naar een nieuwe baan. args: '[playername] [oldjob] [newjob]' output: - target: You have been transferred from %oldjobname% to %newjobname%. + target: Je bent overgeplaatst van %oldjobname% naar %newjobname%. promote: help: - info: Promote the player X levels in a job. + info: Promoveer de player X niveaus in een baan. args: '[playername] [jobname] [levels]' output: - target: You have been promoted %levelsgained% levels in %jobname%. + target: Je bent %levelsgained% gestegen in %jobname%. exp: help: - info: Change the player exp for job. + info: Verander de speler exp voor een baan. args: '[playername] [jobname] set/add/take [amount]' error: - nojob: '&cThis player must first join a job.' + nojob: '&cDeze speler moet eerst een baan hebben.' output: - target: '&eYour exp was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp.' + target: '&eJouw exp was veranderd voor %jobname% &een nu heb je &6niveau %level% &emet &6%exp%exp.' level: help: - info: Change the player's level in a job. + info: Verander het level van de speler in een baan. args: '[playername] [jobname] set/add/take [amount]' error: - nojob: '&cThis player must first join a job.' + nojob: '&cDeze speler moet eerst een baan hebben.' output: - target: '&eYour level was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp.' + target: '&eJouw niveau was veranders voor %jobname% &een nu zit je op &6niveau %level% &emet &6%exp%exp.' demote: help: - info: Demote the player X levels in a job. + info: Degradeer de speler X niveaus in een baan. args: '[playername] [jobname] [levels]' output: - target: You have been demoted %levelslost% levels in %jobname%. + target: Je bent %levelslost% niveaus gezakt in %jobname%. grantxp: help: - info: Grants the player X experience in a job. + info: Geef de speler X ervaring in een baan. args: '[playername] [jobname] [xp]' output: - target: You have been granted %xpgained% experience in %jobname%. + target: Je hebt %xpgained% ervaring verkregen in %jobname%. removexp: help: - info: Remove X experience from the player in a job. + info: Haal X ervaring weg van de speler in een baan. args: '[playername] [jobname] [xp]' output: - target: You have lost %xplost% experience in %jobname%. + target: Je bent %xplost% ervaring verloren in %jobname%. signupdate: help: - info: Manually updates a sign by its name + info: Update handmatig een bord bij naam args: '[jobname]' bp: help: - info: Shows block protections around you in 10 block radius + info: Toon alle beschermde blokken in een 10 blokken radius rond jouw locatie args: '' output: - found: '&eFound &6%amount% &eprotected blocks around you' - notFound: '&eNo protected blocks found around you' + found: '&e&6%amount% &ebeschermde blokken gevonden rondom jou' + notFound: '&eGeen beschermde blokken gevonden rondom jou' reload: help: - info: Reload configurations. + info: Herlaad configuraties. toggle: help: - info: Toggles payment output on action bar or bossbar. + info: Schakel betalingen aan of uit in de action bar of bossbar. args: actionbar/bossbar output: - turnedoff: '&4This feature is turned off!' + turnedoff: '&4Deze functionaliteit staat uit!' paid: - main: '&aYou got:' - money: '&e[amount] money' + main: '&aJe hebt:' + money: '&e[amount] geld' exp: '&7[exp] exp' - points: '&6[points] points' - 'on': '&aToggled: &aON' - 'off': '&aToggled: &4OFF' + points: '&6[points] punten' + 'on': '&aStatus: &aAAN' + 'off': '&aStatus: &4UIT' message: skillup: - broadcast: '%playername% has been promoted to a %titlename% %jobname%.' - nobroadcast: Congratulations, you have been promoted to a %titlename% %jobname%. + broadcast: '%playername% is gepromoveerd naar %titlename% %jobname%.' + nobroadcast: Gefeliciteerd, je bent gepromoveerd naar %titlename% %jobname%. levelup: - broadcast: '%playername% is now a level %joblevel% %jobname%.' - nobroadcast: You are now level %joblevel% %jobname%. + broadcast: '%playername% is nu niveau %joblevel% %jobname%.' + nobroadcast: Jij bent nu niveau %joblevel% %jobname%. leveldown: - message: '&cYou lost level&e %lostLevel%&c in&e %jobname%&c job! Level:&6 %joblevel%&c.' - cowtimer: '&eYou still need to wait &6%time% &esec to get paid for this job.' - blocktimer: '&eYou need to wait &3[time] &esec more to get paid for this!' - taxes: '&3[amount] &eserver taxes were transferred to this account' - boostStarted: '&eJobs boost time have been started!' - boostStoped: '&eJobs boost time have been ended!' + message: '&cJe bent &e %lostLevel% &cniveaus gedaalt in&e %jobname%&c! Niveau:&6 %joblevel%&c.' + cowtimer: '&eJe moet nog &6%time% &esec wachten om betaald te worden voor deze baan.' + blocktimer: '&eJe moet nog &3[time] &esec langer wachten om uitbetaald te krijgen voor dit!' + taxes: '&3[amount] &eserver belastingen zijn overgemaakt naar dit account' + boostStarted: '&eBaan boost tijd is gestart!' + boostStoped: '&eBaan boost tijd is afgelopen!' crafting: - fullinventory: '&cYour inventory is full!' + fullinventory: '&cJouw inventaris zit vol!' signs: List: '&0[number].&8[player]&7:&4[level]' questList: '&0[number].&8[player]&7:&4[quests]' SpecialList: - p1: '&b** &8First &b**' - p2: '&b** &8Second &b**' - p3: '&b** &8Third &b**' - p4: '&b** &8Fourth &b**' - p5: '&b** &8Fifth &b**' - p6: '&b** &8Sixth &b**' - p7: '&b** &8Seventh &b**' - p8: '&b** &8Eight &b**' - p9: '&b** &8Ninth &b**' - p10: '&b** &8Tenth &b**' + p1: '&b** &8Eerste &b**' + p2: '&b** &8Tweede &b**' + p3: '&b** &8Derde &b**' + p4: '&b** &8Vierde &b**' + p5: '&b** &8Vijfde &b**' + p6: '&b** &8Zesde &b**' + p7: '&b** &8Zevende &b**' + p8: '&b** &8Achtste &b**' + p9: '&b** &8Negende &b**' + p10: '&b** &8Tiende &b**' name: '&9[player]' - level: '&8[level] level' + level: '&8Niveau [level]' quests: '&8[quests] quests' bottom: '&b************' - cantcreate: '&4You can''t create this sign!' - cantdestroy: '&4You can''t destroy this sign!' + cantcreate: '&4Je kan dit bord niet maken!' + cantdestroy: '&4JE kan dit bord niet verwijderen!' topline: '&0[Jobs]' secondline: - join: '&0Join' - leave: '&0Leave' - toggle: '&0Toggle' + join: '&0Toetreden' + leave: '&0Verlaten' + toggle: '&0Schakelen' top: '&0Top' - browse: '&0Browse' + browse: '&0Bladeren' stats: '&0Stats' - limit: '&0Limit' + limit: '&0Limiet' info: '&0Info' - archive: '&0Archive' + archive: '&0Archief' scoreboard: topline: '&2Top &e%jobname%' - gtopline: '&2Global top list' + gtopline: '&2Globale top lijst' line: '&2%number%. &e%playername% (&6%level%&e)' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7e9020dc..b3c422a8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,11 +3,12 @@ description: Jobs plugin for the BukkitAPI main: com.gamingmesh.jobs.Jobs version: ${project.version} api-version: "1.13" +folia-supported: true website: https://www.spigotmc.org/resources/4216/ authors: [Zrips] contributors: [montlikadani] depend: [CMILib] -softdepend: [Vault, Essentials, MythicMobs, McMMO, mcMMO, WorldGuard, MyPet, PlaceholderAPI, EcoEnchants, WildStacker, StackMob] +softdepend: [Vault, Essentials, MythicMobs, WorldGuard, MyPet, PlaceholderAPI, EcoEnchants, WildStacker, StackMob] commands: jobs: description: Jobs