2 bug fixes

- Fix votifier being non-existent breaking shop
- Fix plugin breaking error
This commit is contained in:
Seth 2020-07-06 22:21:35 -07:00
parent 3fd7147fc2
commit c333a6ee39
No known key found for this signature in database
GPG Key ID: A7BAB4E14F089CF3
6 changed files with 68 additions and 42 deletions

2
.gitignore vendored
View File

@ -32,5 +32,3 @@ manifest.mf
.Trashes
ehthumbs.db
Thumbs.db
TotalFreedomMod\.iml

View File

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

View File

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

View File

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

View File

@ -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!");
}
}
}

View File

@ -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!");
}
}
}