Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2020
1,679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.28 KB | None | 0 0
  1. package me.raginox.xpboost;
  2.  
  3. import com.gmail.filoghost.holographicdisplays.api.Hologram;
  4. import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
  5. import me.raginox.xpboost.command.BoosterCommand;
  6. import me.raginox.xpboost.event.*;
  7. import me.raginox.xpboost.inventory.BoosterGUI;
  8. import me.raginox.xpboost.util.Booster;
  9. import me.raginox.xpboost.util.BoosterType;
  10. import me.raginox.xpboost.util.UtilTime;
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.Material;
  14. import org.bukkit.Sound;
  15. import org.bukkit.boss.BarColor;
  16. import org.bukkit.boss.BarStyle;
  17. import org.bukkit.boss.BossBar;
  18. import org.bukkit.command.CommandSender;
  19. import org.bukkit.configuration.InvalidConfigurationException;
  20. import org.bukkit.configuration.file.FileConfiguration;
  21. import org.bukkit.configuration.file.YamlConfiguration;
  22. import org.bukkit.entity.Player;
  23. import org.bukkit.event.Listener;
  24. import org.bukkit.plugin.Plugin;
  25. import org.bukkit.plugin.PluginManager;
  26. import org.bukkit.plugin.java.JavaPlugin;
  27.  
  28. import java.io.File;
  29. import java.io.IOException;
  30. import java.util.*;
  31.  
  32. public class Main extends JavaPlugin implements Listener {
  33.  
  34.     public BoosterGUI boostergui;
  35.     public UtilTime utilTime = new UtilTime(this);
  36.     public List<UUID> openInventories = new ArrayList<>();
  37.     public Map<UUID, Long> clickCooldown = new HashMap<>();
  38.     public boolean spawnHolos = true;
  39.     private File storagef;
  40.     private FileConfiguration storage;
  41.     private FileConfiguration messages;
  42.     private BossBar bar_minecraft = null;
  43.     private BossBar bar_skillapi = null;
  44.     private BossBar bar_mcmmo = null;
  45.     // Future add bar here.
  46.     private BossBar bar_jobs = null;
  47.     private List<Booster> activeBoosters = new ArrayList<>();
  48.  
  49.     public void onEnable() {
  50.         saveDefaultConfig();
  51.         createFiles();
  52.         PluginManager pm = Bukkit.getPluginManager();
  53.         if (pm.getPlugin("HolographicDisplays") == null) {
  54.             spawnHolos = false;
  55.             getLogger().warning("----------------------------------------------------------------------------");
  56.             getLogger().warning("HolographicDisplays dependency is missing!");
  57.             getLogger().warning("Please install the latest version of HolographicDisplays. It can be gotten");
  58.             getLogger().warning("from: https://dev.bukkit.org/projects/holographic-displays");
  59.             getLogger().warning(" ");
  60.             getLogger().warning("[IMPORTANT] No holograms will be shown without this plugin!");
  61.             getLogger().warning("----------------------------------------------------------------------------");
  62.         }
  63.         if (getConfig().getDouble("version") < 0.7) {
  64.             getLogger().severe("----------------------------------------------------------------------------");
  65.             getLogger().severe("Your configuration file for this plugin is to old!");
  66.             getLogger().severe("Delete the current plugins/ExperienceBooster folder to enable this plugin!");
  67.             getLogger().severe("----------------------------------------------------------------------------");
  68.             pm.disablePlugin(this);
  69.             return;
  70.         }
  71.         pm.registerEvents(new InventoryListener(this), this);
  72.         pm.registerEvents(new HologramListener(this), this);
  73.         pm.registerEvents(new BottleListener(this), this);
  74.         if (isBoosterEnabled(BoosterType.MINECRAFT)) {
  75.             pm.registerEvents(new ExperienceListener(this), this);
  76.             debug("Activated MC Listener");
  77.         }
  78.         if (isBoosterEnabled(BoosterType.SKILLAPI)) {
  79.             Plugin skill = pm.getPlugin("SkillAPI");
  80.             if (skill != null) {
  81.                 pm.registerEvents(new SkillAPIListener(this), this);
  82.                 debug("Activated SkillAPI Listener");
  83.             } else {
  84.                 getLogger().warning(
  85.                         "You cannot enable 'SkillAPI' multiplication if you do not have 'SkillAPI' installed!");
  86.             }
  87.         }
  88.         if (isBoosterEnabled(BoosterType.MCMMO)) {
  89.             Plugin skill = pm.getPlugin("mcMMO");
  90.             if (skill != null) {
  91.                 pm.registerEvents(new mcMMOListener(this), this);
  92.                 debug("Activated mcMMO Listener");
  93.             } else {
  94.                 getLogger().warning("You cannot enable 'mcMMO' multiplication if you do not have 'mcMMO' installed!");
  95.             }
  96.         }
  97.         // Future Add enabled check here
  98.         if (isBoosterEnabled(BoosterType.JOBS)) {
  99.             Plugin skill = pm.getPlugin("Jobs");
  100.             if (skill != null) {
  101.                 pm.registerEvents(new JobsListener(this), this);
  102.                 debug("Activated Jobs Listener");
  103.             } else {
  104.                 getLogger().warning("You cannot enable 'Jobs' multiplication if you do not have 'Jobs' installed!");
  105.             }
  106.         }
  107.         getCommand("xpboost").setExecutor(new BoosterCommand(this));
  108.         boostergui = new BoosterGUI(this);
  109.  
  110.         Bukkit.getScheduler().runTaskTimer(this, () -> {
  111.             // Clear inventory cooldown list, incase someone disapears.
  112.             clickCooldown.entrySet().removeIf(pair -> System.currentTimeMillis() > pair.getValue());
  113.         }, 60 * 20L, 60 * 20L);
  114.  
  115.         Bukkit.getScheduler().runTaskTimer(this, () -> {
  116.             FileConfiguration config = getConfig();
  117.             // MINECRAFT
  118.             if (isBoosted(BoosterType.MINECRAFT)) {
  119.                 if (bar_minecraft == null) {
  120.                     try {
  121.                         bar_minecraft = Bukkit.createBossBar(ChatColor.translateAlternateColorCodes('&',
  122.                                 config.getString("Boosters.MINECRAFT.bossbar-message")
  123.                                         .replace("{player}", getWhoIsBoosting(BoosterType.MINECRAFT))
  124.                                         .replace("{time}", getTimeLeft(BoosterType.MINECRAFT))
  125.                                         .replace("{current-multiplier}", getMultiplierName(BoosterType.MINECRAFT))),
  126.                                 BarColor.valueOf(config.getString("Boosters.MINECRAFT.bossbar-color").toUpperCase()),
  127.                                 BarStyle.SOLID);
  128.                     } catch (NullPointerException ex) {
  129.                         ex.printStackTrace();
  130.                     }
  131.                 }
  132.                 try {
  133.                     bar_minecraft.setTitle(ChatColor.translateAlternateColorCodes('&',
  134.                             config.getString("Boosters.MINECRAFT.bossbar-message")
  135.                                     .replace("{player}", getWhoIsBoosting(BoosterType.MINECRAFT))
  136.                                     .replace("{time}", getTimeLeft(BoosterType.MINECRAFT))
  137.                                     .replace("{current-multiplier}", getMultiplierName(BoosterType.MINECRAFT))));
  138.                     for (Player online : Bukkit.getOnlinePlayers()) {
  139.                         if (!bar_minecraft.getPlayers().contains(online)) {
  140.                             bar_minecraft.addPlayer(online);
  141.                         }
  142.                     }
  143.                 } catch (NullPointerException ex) {
  144.                     debug("Bar task created a NPE (MINECRAFT). It was silenced.");
  145.                 }
  146.             }
  147.             // SKILLAPI
  148.             if (isBoosted(BoosterType.SKILLAPI)) {
  149.                 if (bar_skillapi == null) {
  150.                     bar_skillapi = Bukkit.createBossBar(ChatColor.translateAlternateColorCodes('&',
  151.                             config.getString("Boosters.SKILLAPI.bossbar-message")
  152.                                     .replace("{player}", getWhoIsBoosting(BoosterType.SKILLAPI))
  153.                                     .replace("{time}", getTimeLeft(BoosterType.SKILLAPI))
  154.                                     .replace("{current-multiplier}", getMultiplierName(BoosterType.SKILLAPI))),
  155.                             BarColor.valueOf(config.getString("Boosters.SKILLAPI.bossbar-color").toUpperCase()),
  156.                             BarStyle.SOLID);
  157.                 }
  158.                 try {
  159.                     bar_skillapi.setTitle(ChatColor.translateAlternateColorCodes('&',
  160.                             config.getString("Boosters.SKILLAPI.bossbar-message")
  161.                                     .replace("{player}", getWhoIsBoosting(BoosterType.SKILLAPI))
  162.                                     .replace("{time}", getTimeLeft(BoosterType.SKILLAPI))
  163.                                     .replace("{current-multiplier}", getMultiplierName(BoosterType.SKILLAPI))));
  164.                     for (Player online : Bukkit.getOnlinePlayers()) {
  165.                         if (!bar_skillapi.getPlayers().contains(online)) {
  166.                             bar_skillapi.addPlayer(online);
  167.                         }
  168.                     }
  169.                 } catch (NullPointerException ex) {
  170.                     debug("Bar task created a NPE (SKILLAPI). It was silenced.");
  171.                 }
  172.             }
  173.             // MCMMO
  174.             if (isBoosted(BoosterType.MCMMO)) {
  175.                 if (bar_mcmmo == null) {
  176.                     bar_mcmmo = Bukkit.createBossBar(
  177.                             ChatColor.translateAlternateColorCodes('&',
  178.                                     config.getString("Boosters.MCMMO.bossbar-message")
  179.                                             .replace("{player}", getWhoIsBoosting(BoosterType.MCMMO))
  180.                                             .replace("{time}", getTimeLeft(BoosterType.MCMMO))
  181.                                             .replace("{current-multiplier}", getMultiplierName(BoosterType.MCMMO))),
  182.                             BarColor.valueOf(config.getString("Boosters.MCMMO.bossbar-color").toUpperCase()),
  183.                             BarStyle.SOLID);
  184.                 }
  185.                 try {
  186.                     bar_mcmmo.setTitle(ChatColor.translateAlternateColorCodes('&',
  187.                             config.getString("Boosters.MCMMO.bossbar-message")
  188.                                     .replace("{player}", getWhoIsBoosting(BoosterType.MCMMO))
  189.                                     .replace("{time}", getTimeLeft(BoosterType.MCMMO))
  190.                                     .replace("{current-multiplier}", getMultiplierName(BoosterType.MCMMO))));
  191.                     for (Player online : Bukkit.getOnlinePlayers()) {
  192.                         if (!bar_mcmmo.getPlayers().contains(online)) {
  193.                             bar_mcmmo.addPlayer(online);
  194.                         }
  195.                     }
  196.                 } catch (NullPointerException ex) {
  197.                     debug("Bar task created a NPE (MCMMO). It was silenced.");
  198.                 }
  199.             }
  200.             // Future add bar task here.
  201.             // JOBS
  202.             if (isBoosted(BoosterType.JOBS)) {
  203.                 if (bar_jobs == null) {
  204.                     bar_jobs = Bukkit.createBossBar(
  205.                             ChatColor.translateAlternateColorCodes('&',
  206.                                     config.getString("Boosters.JOBS.bossbar-message")
  207.                                             .replace("{player}", getWhoIsBoosting(BoosterType.JOBS))
  208.                                             .replace("{time}", getTimeLeft(BoosterType.JOBS))
  209.                                             .replace("{current-multiplier}", getMultiplierName(BoosterType.JOBS))),
  210.                             BarColor.valueOf(config.getString("Boosters.JOBS.bossbar-color").toUpperCase()),
  211.                             BarStyle.SOLID);
  212.                 }
  213.                 try {
  214.                     bar_jobs.setTitle(ChatColor.translateAlternateColorCodes('&',
  215.                             config.getString("Boosters.JOBS.bossbar-message")
  216.                                     .replace("{player}", getWhoIsBoosting(BoosterType.JOBS))
  217.                                     .replace("{time}", getTimeLeft(BoosterType.JOBS))
  218.                                     .replace("{current-multiplier}", getMultiplierName(BoosterType.JOBS))));
  219.                     for (Player online : Bukkit.getOnlinePlayers()) {
  220.                         if (!bar_jobs.getPlayers().contains(online)) {
  221.                             bar_jobs.addPlayer(online);
  222.                         }
  223.                     }
  224.                 } catch (NullPointerException ex) {
  225.                     debug("Bar task created a NPE (JOBS). It was silenced.");
  226.                 }
  227.             }
  228.             // Despawn hologram task
  229.             if (spawnHolos) {
  230.                 for (Hologram holo : HologramsAPI.getHolograms(this)) {
  231.                     if (holo.getCreationTimestamp() + 1750 < System.currentTimeMillis()) {
  232.                         holo.delete();
  233.                     }
  234.                 }
  235.             }
  236.         }, 20L, 20L);
  237.     }
  238.  
  239.     public void onDisable() {
  240.         boostergui = null;
  241.         // Closing all open inventories
  242.         for (Player player : Bukkit.getOnlinePlayers()) {
  243.             if (openInventories.contains(player.getUniqueId())) {
  244.                 player.closeInventory();
  245.                 player.sendMessage(getMessage("event-plugin-disabled"));
  246.                 player.sendMessage(getMessage("event-force-close-inventory"));
  247.             }
  248.         }
  249.         openInventories.clear();
  250.         clickCooldown.clear();
  251.         // Cleaning all boss bars
  252.         if (bar_minecraft != null) {
  253.             bar_minecraft.removeAll();
  254.             bar_minecraft = null;
  255.         }
  256.         if (bar_skillapi != null) {
  257.             bar_skillapi.removeAll();
  258.             bar_skillapi = null;
  259.         }
  260.         if (bar_mcmmo != null) {
  261.             bar_mcmmo.removeAll();
  262.             bar_mcmmo = null;
  263.         }
  264.         // Future add cleaning task here
  265.         if (bar_jobs != null) {
  266.             bar_jobs.removeAll();
  267.             bar_jobs = null;
  268.         }
  269.         // Despawning the active holograms
  270.         if (spawnHolos) {
  271.             for (Hologram holo : HologramsAPI.getHolograms(this)) {
  272.                 holo.delete();
  273.             }
  274.         }
  275.     }
  276.  
  277.     @SuppressWarnings("ResultOfMethodCallIgnored")
  278.     private void createFiles() {
  279.         storagef = new File(getDataFolder(), "playerdata.yml");
  280.         File messagesf = new File(getDataFolder(), "language.yml");
  281.         if (!storagef.exists()) {
  282.             storagef.getParentFile().mkdirs();
  283.             saveResource("playerdata.yml", false);
  284.         }
  285.         if (!messagesf.exists()) {
  286.             messagesf.getParentFile().mkdirs();
  287.             saveResource("language.yml", false);
  288.         }
  289.         storage = new YamlConfiguration();
  290.         messages = new YamlConfiguration();
  291.         try {
  292.             storage.load(storagef);
  293.         } catch (IOException | InvalidConfigurationException e) {
  294.             e.printStackTrace();
  295.         }
  296.         try {
  297.             messages.load(messagesf);
  298.         } catch (IOException | InvalidConfigurationException e) {
  299.             e.printStackTrace();
  300.         }
  301.     }
  302.  
  303.     public void endActiveBooster(Booster booster) {
  304.         Bukkit.broadcastMessage(getMessage("booster-ended").replace("{player}", booster.getPlayerName())
  305.                 .replace("{type}", getConfig().getString("Boosters." + booster.getType().name() + ".type")));
  306.         activeBoosters.remove(booster);
  307.         if (isBoosted(booster.getType())) {
  308.             debug("A booster finished. Since there was however still a booster of this type active, the bar will remain.");
  309.         } else {
  310.             debug("A booster finished. The bar was cleared.");
  311.             switch (booster.getType()) {
  312.                 case MCMMO:
  313.                     bar_mcmmo.removeAll();
  314.                     bar_mcmmo = null;
  315.                     return;
  316.                 case MINECRAFT:
  317.                     bar_minecraft.removeAll();
  318.                     bar_minecraft = null;
  319.                     return;
  320.                 case SKILLAPI:
  321.                     bar_skillapi.removeAll();
  322.                     bar_skillapi = null;
  323.                     return;
  324.                 // Future Add type here
  325.                 case JOBS:
  326.                     bar_jobs.removeAll();
  327.                     bar_jobs = null;
  328.             }
  329.         }
  330.     }
  331.  
  332.     public void addBooster(Player giveTo, int a, CommandSender cmd, BoosterType type) {
  333.         String boostername = getConfig().getString("Boosters." + type.name() + ".type");
  334.         String s = "";
  335.         if (a != 1) {
  336.             s = "s";
  337.         }
  338.         String uuid = giveTo.getUniqueId().toString();
  339.         if (storage.contains(uuid + "." + type.name())) {
  340.             int amount = storage.getInt(uuid + "." + type.name()) + a;
  341.             String sa = "";
  342.             if (amount != 1) {
  343.                 sa = "s";
  344.             }
  345.             storage.set(uuid + "." + type.name(), amount);
  346.             cmd.sendMessage(getMessage("command-give").replace("{player}", giveTo.getName())
  347.                     .replace("{type}", boostername).replace("{amount}", a + "").replace("{s}", s));
  348.             cmd.sendMessage(getMessage("command-current-amount").replace("{amount}", amount + ""));
  349.             giveTo.sendMessage(getMessage("booster-receive").replace("{amount}", a + "").replace("{type}", boostername)
  350.                     .replace("{s}", sa));
  351.             try {
  352.                 storage.save(storagef);
  353.             } catch (IOException e) {
  354.                 cmd.sendMessage(getMessage("command-error-save"));
  355.                 debug("IOException whilst saving player data.");
  356.                 e.printStackTrace();
  357.             }
  358.         } else {
  359.             storage.set(uuid + "." + type.name(), a);
  360.             cmd.sendMessage(getMessage("command-give").replace("{player}", giveTo.getName())
  361.                     .replace("{type}", boostername).replace("{amount}", a + "").replace("{s}", s));
  362.             cmd.sendMessage(getMessage("command-current-amount").replace("{amount}", a + ""));
  363.             giveTo.sendMessage(getMessage("booster-receive").replace("{amount}", a + "").replace("{type}", boostername)
  364.                     .replace("{s}", s));
  365.             try {
  366.                 storage.save(storagef);
  367.             } catch (IOException e) {
  368.                 cmd.sendMessage(getMessage("command-error-save"));
  369.                 debug("IOException whilst saving player data.");
  370.                 e.printStackTrace();
  371.             }
  372.         }
  373.     }
  374.  
  375.     public void takeBooster(Player takeFrom, int a, CommandSender cmd, BoosterType type) {
  376.         String boostername = getConfig().getString("Boosters." + type.name() + ".type");
  377.         String s = "";
  378.         if (a != 1) {
  379.             s = "s";
  380.         }
  381.         String uuid = takeFrom.getUniqueId().toString();
  382.         if (storage.contains(uuid + "." + type.name())) {
  383.             int amount = storage.getInt(uuid + "." + type.name());
  384.             int subtracted = amount - a;
  385.             if (subtracted < 1) {
  386.                 storage.set(uuid + "." + type.name(), null);
  387.                 cmd.sendMessage(getMessage("command-reset").replace("{player}", takeFrom.getName()).replace("{type}",
  388.                         boostername));
  389.                 cmd.sendMessage(getMessage("command-current-amount").replace("{amount}", "0"));
  390.             } else {
  391.                 storage.set(uuid + "." + type.name(), subtracted);
  392.                 cmd.sendMessage(getMessage("command-take").replace("{amount}", a + "").replace("{type}", boostername)
  393.                         .replace("player", takeFrom.getName()).replace("{s}", s));
  394.                 cmd.sendMessage(getMessage("command-current-amount").replace("{amount}", subtracted + ""));
  395.             }
  396.             try {
  397.                 storage.save(storagef);
  398.             } catch (IOException e) {
  399.                 cmd.sendMessage(getMessage("command-error-save"));
  400.                 debug("IOException whilst saving player data.");
  401.                 e.printStackTrace();
  402.             }
  403.         } else {
  404.             cmd.sendMessage(getMessage("command-error-no-boosters").replace("{player}", takeFrom.getName())
  405.                     .replace("{type}", boostername));
  406.         }
  407.     }
  408.  
  409.     public void resetBooster(Player reset, CommandSender cmd, BoosterType type) {
  410.         String boostername = getConfig().getString("Boosters." + type.name() + ".type");
  411.         String uuid = reset.getUniqueId().toString();
  412.         if (storage.contains(uuid + "." + type.name())) {
  413.             storage.set(uuid + "." + type.name(), null);
  414.             cmd.sendMessage(
  415.                     getMessage("command-reset").replace("{player}", reset.getName()).replace("{type}", boostername));
  416.             try {
  417.                 storage.save(storagef);
  418.             } catch (IOException e) {
  419.                 cmd.sendMessage(getMessage("command-error-save"));
  420.                 debug("IOException whilst saving player data.");
  421.                 e.printStackTrace();
  422.             }
  423.         } else {
  424.             cmd.sendMessage(getMessage("command-error-no-boosters").replace("{player}", reset.getName())
  425.                     .replace("{type}", boostername));
  426.         }
  427.     }
  428.  
  429.     public void cmdActivate(Player sender, BoosterType type) {
  430.         String boostername = getConfig().getString("Boosters." + type.name() + ".type");
  431.         int multi = getConfig().getInt("Boosters." + type.name() + ".multiplier");
  432.         if (isBoosted(type) && isBoosterNotStackable(type)) {
  433.             sender.sendMessage(getMessage("command-booster-active"));
  434.             return;
  435.         }
  436.         if (isPlayerAlreadyUsingThisBooster(type, sender.getName())) {
  437.             sender.sendMessage(getMessage("command-booster-this-type-active"));
  438.             return;
  439.         }
  440.         if (isBoosterMaxed(type, multi)) {
  441.             sender.sendMessage(getMessage("command-booster-maxed"));
  442.             return;
  443.         }
  444.  
  445.         Bukkit.broadcastMessage(
  446.                 getMessage("booster-activated").replace("{player}", sender.getName()).replace("{type}", boostername));
  447.         for (Player online : Bukkit.getOnlinePlayers()) {
  448.             online.playSound(online.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1f, 1f);
  449.         }
  450.         activeBoosters.add(new Booster(sender.getUniqueId(), this, type, multi));
  451.  
  452.     }
  453.  
  454.     public void tryActivateBooster(Player activator, BoosterType type) {
  455.         String boostername = getConfig().getString("Boosters." + type.name() + ".type");
  456.         int multi = getConfig().getInt("Boosters." + type.name() + ".multiplier");
  457.         if (isBoosted(type) && isBoosterNotStackable(type)) {
  458.             activator.sendMessage(getMessage("command-booster-active"));
  459.             return;
  460.         }
  461.         if (isPlayerAlreadyUsingThisBooster(type, activator.getName())) {
  462.             activator.sendMessage(getMessage("command-booster-this-type-active"));
  463.             return;
  464.         }
  465.         if (isBoosterMaxed(type, multi)) {
  466.             activator.sendMessage(getMessage("command-booster-maxed"));
  467.             return;
  468.         }
  469.         String uuid = activator.getUniqueId().toString();
  470.         boolean activate = false;
  471.         if (storage.contains(uuid + "." + type.name())) {
  472.             int amount = storage.getInt(uuid + "." + type.name());
  473.             int subtracted = amount - 1;
  474.             if (subtracted < 1) {
  475.                 storage.set(uuid + "." + type.name(), null);
  476.                 activate = true;
  477.             } else {
  478.                 storage.set(uuid + "." + type.name(), subtracted);
  479.                 activate = true;
  480.             }
  481.             try {
  482.                 storage.save(storagef);
  483.             } catch (IOException e) {
  484.                 activator.sendMessage(getMessage("command-error-save"));
  485.                 activate = false;
  486.                 e.printStackTrace();
  487.             }
  488.         } else {
  489.             activator.sendMessage(getMessage("command-no-booster"));
  490.         }
  491.         if (activate) {
  492.             Bukkit.broadcastMessage(getMessage("booster-activated").replace("{player}", activator.getName())
  493.                     .replace("{type}", boostername));
  494.             for (Player online : Bukkit.getOnlinePlayers()) {
  495.                 online.playSound(online.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1f, 1f);
  496.             }
  497.             activeBoosters.add(new Booster(activator.getUniqueId(), this, type, multi));
  498.         }
  499.     }
  500.  
  501.     private boolean isPlayerAlreadyUsingThisBooster(BoosterType type, String name) {
  502.         for (Booster b : activeBoosters) {
  503.             if (b.getType() == type) {
  504.                 if (b.getPlayerName().equals(name)) {
  505.                     return true;
  506.                 }
  507.             }
  508.         }
  509.         return false;
  510.     }
  511.  
  512.     private boolean isBoosterMaxed(BoosterType type, int multi) {
  513.         int max = getConfig().getInt("Boosters." + type.name() + ".max-active-multiplier");
  514.         return (getMultiplier(type) + multi) > max;
  515.     }
  516.  
  517.     private boolean isBoosterNotStackable(BoosterType type) {
  518.         return !getConfig().getBoolean("Boosters." + type.name() + ".canStack");
  519.     }
  520.  
  521.     public Integer getBoosterAmount(Player player, BoosterType type) {
  522.         String uuid = player.getUniqueId().toString();
  523.         if (storage.contains(uuid + "." + type.name())) {
  524.             int stored = storage.getInt(uuid + "." + type.name());
  525.             debug("The value " + uuid + "." + type.name() + " was fetched to be " + stored);
  526.             return stored;
  527.         }
  528.         debug("The player " + player.getName() + " does not have the type " + type.name());
  529.         return 0;
  530.     }
  531.  
  532.     public void debug(String string) {
  533.         if (getConfig().getBoolean("debug")) {
  534.             getLogger().warning("[Debug] " + string);
  535.         }
  536.     }
  537.  
  538.     public int getMultiplier(BoosterType type) {
  539.         int booster = 0;
  540.         for (Booster b : activeBoosters) {
  541.             if (b.getType() == type) {
  542.                 booster += b.getMultiplier();
  543.             }
  544.         }
  545.         int max = getConfig().getInt("Boosters." + type.name() + ".max-active-multiplier");
  546.         if (booster > max) {
  547.             booster = max;
  548.         }
  549.         if (booster == 0) {
  550.             booster = 1;
  551.         }
  552.         return booster;
  553.     }
  554.  
  555.     public boolean isBoosted(BoosterType type) {
  556.         for (Booster b : activeBoosters) {
  557.             if (b.getType() == type) {
  558.                 return true;
  559.             }
  560.         }
  561.         return false;
  562.     }
  563.  
  564.     private String getWhoIsBoosting(BoosterType type) {
  565.         String name = getMessage("server");
  566.         for (Booster b : activeBoosters) {
  567.             if (b.getType() == type) {
  568.                 if (name.equalsIgnoreCase(getMessage("server"))) {
  569.                     name = b.getPlayerName();
  570.                 } else {
  571.                     return getMessage("multiple-players");
  572.                 }
  573.             }
  574.         }
  575.         return name;
  576.     }
  577.  
  578.     public String getMultiplierName(BoosterType type) {
  579.         int multi = getMultiplier(type);
  580.         if (messages.contains("Name-of-the-multiplier." + multi)) {
  581.             return messages.getString("Name-of-the-multiplier." + multi);
  582.         }
  583.         return messages.getString("Name-of-the-multiplier.other");
  584.     }
  585.  
  586.     private String getTimeLeft(BoosterType type) {
  587.         Booster firstOneToRunOut = null;
  588.         Long time = 1000L * getConfig().getInt("Boosters." + type.name() + ".time");
  589.         for (Booster b : activeBoosters) {
  590.             if (b.getType() == type) {
  591.                 if (b.getRawTimeLeft() < time) {
  592.                     firstOneToRunOut = b;
  593.                     time = b.getRawTimeLeft();
  594.                 }
  595.             }
  596.         }
  597.         if (firstOneToRunOut == null) {
  598.             return getMessage("not-active");
  599.         }
  600.         return firstOneToRunOut.getTimeLeft();
  601.     }
  602.  
  603.     public boolean isBoosterEnabled(BoosterType type) {
  604.         return getConfig().getBoolean("Boosters." + type.name() + ".enabled");
  605.     }
  606.  
  607.  
  608.     public String getMessage(String path) {
  609.         if (!messages.contains(path)) {
  610.             debug("Messages file does not contain: " + path);
  611.             return "§4Error: §cMissing message §4" + path;
  612.         }
  613.         return ChatColor.translateAlternateColorCodes('&', messages.getString(path));
  614.     }
  615.  
  616.     public Material getGuiMaterial(String path) {
  617.         if (!messages.contains(path)) {
  618.             debug("Messages file does not contain material: " + path);
  619.             return Material.BEDROCK;
  620.         }
  621.         try {
  622.             return Material.valueOf(messages.getString(path).toUpperCase());
  623.         } catch (Exception ex) {
  624.             debug("Messages file contained an invalid material for: " + path);
  625.             return Material.BEDROCK;
  626.         }
  627.     }
  628.  
  629.     public Integer getGuiAmount(String path) {
  630.         if (!messages.contains(path)) {
  631.             debug("Messages file does not contain amount: " + path);
  632.             return -1;
  633.         }
  634.         try {
  635.             return messages.getInt(path);
  636.         } catch (Exception ex) {
  637.             debug("Messages file contained an invalid amount for: " + path);
  638.             return -1;
  639.         }
  640.     }
  641.  
  642.     public Short getGuiData(String path) {
  643.         if (!messages.contains(path)) {
  644.             debug("Messages file does not contain data: " + path);
  645.             return 0;
  646.         }
  647.         try {
  648.             return (short) messages.getInt(path);
  649.         } catch (Exception ex) {
  650.             debug("Messages file contained an invalid durability (data) for: " + path);
  651.             return 0;
  652.         }
  653.     }
  654.  
  655.     public String getGuiName(String path) {
  656.         if (!messages.contains(path)) {
  657.             debug("Messages file does not contain item name: " + path);
  658.             return "§4Error: §cMissing name for " + path;
  659.         }
  660.         return getMessage(path);
  661.     }
  662.  
  663.     public List<String> getGuiLore(String path) {
  664.         List<String> lore = new ArrayList<>();
  665.         if (!messages.contains(path)) {
  666.             lore.add("§7Invalid lore from " + path);
  667.             debug("Messages file does not contain item lore: " + path);
  668.             return lore;
  669.         }
  670.         List<String> retrieved = messages.getStringList(path);
  671.         for (String s : retrieved) {
  672.             lore.add(ChatColor.translateAlternateColorCodes('&', s));
  673.         }
  674.         return lore;
  675.     }
  676.  
  677.     public Boolean getGuiGlowing(String path) {
  678.         if (!messages.contains(path)) {
  679.             debug("Messages file does not contain item glow: " + path);
  680.             return false;
  681.         }
  682.         try {
  683.             return messages.getBoolean(path);
  684.         } catch (Exception ex) {
  685.             debug("Messages file contained an invalid boolean for: " + path);
  686.             return false;
  687.         }
  688.     }
  689. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement