From c333a6ee39c74d677158cd9fc6f5442818dcb736 Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Mon, 6 Jul 2020 22:21:35 -0700 Subject: [PATCH] 2 bug fixes - Fix votifier being non-existent breaking shop - Fix plugin breaking error --- .gitignore | 2 - .../totalfreedommod/TotalFreedomMod.java | 3 + .../totalfreedommod/discord/Discord.java | 4 +- .../permissions/PermissionManager.java | 4 +- .../totalfreedommod/shop/Shop.java | 41 ++------------ .../totalfreedommod/shop/Votifier.java | 56 +++++++++++++++++++ 6 files changed, 68 insertions(+), 42 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/shop/Votifier.java diff --git a/.gitignore b/.gitignore index b63d0ccc..79f43f9b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,3 @@ manifest.mf .Trashes ehthumbs.db Thumbs.db - -TotalFreedomMod\.iml diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 498b3b2b..1b3c5924 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -42,6 +42,7 @@ import me.totalfreedom.totalfreedommod.player.PlayerList; import me.totalfreedom.totalfreedommod.punishments.PunishmentList; import me.totalfreedom.totalfreedommod.rank.RankManager; import me.totalfreedom.totalfreedommod.shop.Shop; +import me.totalfreedom.totalfreedommod.shop.Votifier; import me.totalfreedom.totalfreedommod.sql.SQLite; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -98,6 +99,7 @@ public class TotalFreedomMod extends JavaPlugin public AntiSpam as; public PlayerList pl; public Shop sh; + public Votifier vo; public SQLite sql; public Announcer an; public ChatManager cm; @@ -224,6 +226,7 @@ public class TotalFreedomMod extends JavaPlugin wr = new WorldRestrictions(); pl = new PlayerList(); sh = new Shop(); + vo = new Votifier(); an = new Announcer(); cm = new ChatManager(); dc = new Discord(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index fdf2b8bc..f579382a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -68,7 +68,8 @@ public class Discord extends FreedomService } if (bot != null) { - RATELIMIT_EXECUTOR = new ScheduledThreadPoolExecutor(5, new CountingThreadFactory(this::poolIdentifier, "RateLimit")); // To avoid ClassNotFoundException as net.dv8tion.jda.internal.utils.concurrent.CountingThreadFactory doesn't exist. + RATELIMIT_EXECUTOR = new ScheduledThreadPoolExecutor(5, new CountingThreadFactory(this::poolIdentifier, "RateLimit")); + RATELIMIT_EXECUTOR.setRemoveOnCancelPolicy(true); for (Object object : bot.getRegisteredListeners()) { bot.removeEventListener(object); @@ -76,7 +77,6 @@ public class Discord extends FreedomService } try { - RATELIMIT_EXECUTOR.setRemoveOnCancelPolicy(true); bot = new JDABuilder(AccountType.BOT) .setToken(ConfigEntry.DISCORD_TOKEN.getString()) .addEventListeners(new PrivateMessageListener()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java b/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java index 83657f58..63fe27af 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java @@ -66,7 +66,9 @@ public class PermissionManager extends FreedomService seniorAdminPermissions.addAll(telnetAdminPermissions); permissions.put(Rank.SENIOR_ADMIN, seniorAdminPermissions); - FLog.info("Loaded " + permissions.values().size() + " permission nodes"); + int count = operatorPermissions.size() + masterBuilderPermissions.size() + masterBuilderPermissions.size() + superAdminPermissions.size() + telnetAdminPermissions.size() + seniorAdminPermissions.size(); + + FLog.info("Loaded " + count + " permission nodes"); } public void setPermissions(Player player) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java index d69d879e..511b2cd8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java @@ -26,8 +26,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -; - public class Shop extends FreedomService { private BukkitTask reactions; @@ -73,7 +71,7 @@ public class Shop extends FreedomService { reactionString = FUtil.randomString(ConfigEntry.SHOP_REACTIONS_STRING_LENGTH.getInteger()); - FUtil.bcastMsg(prefix + ChatColor.AQUA + "Enter the code above to win " + ChatColor.GOLD + plugin.sh.coinsPerReactionWin + ChatColor.AQUA + " coins!", false); + FUtil.bcastMsg(prefix + ChatColor.AQUA + "Enter the code above to win " + ChatColor.GOLD + coinsPerReactionWin + ChatColor.AQUA + " coins!", false); reactionStartTime = new Date(); @@ -290,7 +288,7 @@ public class Shop extends FreedomService } Inventory inventory = event.getInventory(); - if (inventory.getSize() != 36 || !event.getView().getTitle().equals(plugin.sh.getShopTitle())) + if (inventory.getSize() != 36 || !event.getView().getTitle().equals(getShopTitle())) { return; } @@ -307,7 +305,7 @@ public class Shop extends FreedomService int price = shopItem.getCost(); int coins = playerData.getCoins(); - if (playerData.hasItem(shopItem) || !plugin.sh.canAfford(price, coins)) + if (playerData.hasItem(shopItem) || !canAfford(price, coins)) { return; } @@ -318,7 +316,7 @@ public class Shop extends FreedomService player.closeInventory(); - player.sendMessage(plugin.sh.getShopPrefix() + " " + ChatColor.GREEN + "Successfully purchased the \"" + shopItem.getColoredName() + ChatColor.GREEN + "\" for " + ChatColor.GOLD + price + ChatColor.GREEN + "!"); + player.sendMessage(getShopPrefix() + " " + ChatColor.GREEN + "Successfully purchased the \"" + shopItem.getColoredName() + ChatColor.GREEN + "\" for " + ChatColor.GOLD + price + ChatColor.GREEN + "!"); if (shopItem.equals(ShopItem.GRAPPLING_HOOK)) { @@ -354,35 +352,4 @@ public class Shop extends FreedomService } return null; } - - @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerVote(VotifierEvent event) - { - Vote vote = event.getVote(); - String name = vote.getUsername(); - int coinsPerVote = ConfigEntry.SHOP_COINS_PER_VOTE.getInteger(); - Player player = server.getPlayer(name); - PlayerData data = null; - if (player != null) - { - data = plugin.pl.getData(player); - } - else - { - data = plugin.pl.getData(name); - } - - if (data != null) - { - data.setCoins(data.getCoins() + coinsPerVote); - data.setTotalVotes(data.getTotalVotes() + 1); - plugin.pl.save(data); - FUtil.bcastMsg(ChatColor.GREEN + name + ChatColor.AQUA + " has voted for us on " + ChatColor.GREEN + vote.getServiceName() + ChatColor.AQUA + "!"); - } - - if (player != null) - { - player.sendMessage(ChatColor.GREEN + "Thank you for voting for us! Here are " + coinsPerVote + " coins!"); - } - } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Votifier.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Votifier.java new file mode 100644 index 00000000..888989bb --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Votifier.java @@ -0,0 +1,56 @@ +package me.totalfreedom.totalfreedommod.shop; + +import com.vexsoftware.votifier.model.Vote; +import com.vexsoftware.votifier.model.VotifierEvent; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.player.PlayerData; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +public class Votifier extends FreedomService +{ + @Override + public void onStart() + { + } + + @Override + public void onStop() + { + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerVote(VotifierEvent event) + { + Vote vote = event.getVote(); + String name = vote.getUsername(); + int coinsPerVote = ConfigEntry.SHOP_COINS_PER_VOTE.getInteger(); + Player player = server.getPlayer(name); + PlayerData data = null; + if (player != null) + { + data = plugin.pl.getData(player); + } + else + { + data = plugin.pl.getData(name); + } + + if (data != null) + { + data.setCoins(data.getCoins() + coinsPerVote); + data.setTotalVotes(data.getTotalVotes() + 1); + plugin.pl.save(data); + FUtil.bcastMsg(ChatColor.GREEN + name + ChatColor.AQUA + " has voted for us on " + ChatColor.GREEN + vote.getServiceName() + ChatColor.AQUA + "!"); + } + + if (player != null) + { + player.sendMessage(ChatColor.GREEN + "Thank you for voting for us! Here are " + coinsPerVote + " coins!"); + } + } +}