Cyclic Dependency Patch

- Fixed cyclic dependencies
- Added a TFShoppe class for effective plugin initialization
- Registered discord commands, did not before
- Added SLF4J loggers for module logging.
This commit is contained in:
Paul Reilly
2023-03-10 19:21:03 -06:00
parent b5804c7eb1
commit 3a96c853d2
38 changed files with 721 additions and 418 deletions

View File

@ -46,22 +46,6 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.totalfreedom</groupId>
<artifactId>discord</artifactId>
<version>2023.02</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.totalfreedom</groupId>
<artifactId>shop</artifactId>
<version>2023.02</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>

View File

@ -151,7 +151,7 @@ public class ChatManager extends FreedomService
FLog.info("[ADMIN] " + sender.getName() + " " + display.getTag() + ": " + message, true);
if (plugin.dc != null) {
plugin.dc.getUtils().messageAdminChatChannel(sender.getName() + " \u00BB " + message);
plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message);
}
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player ->

View File

@ -4,9 +4,12 @@ import java.io.File;
import java.io.InputStream;
import java.util.Properties;
import me.totalfreedom.discord.TFM_Accessor;
import me.totalfreedom.totalfreedommod.admin.ActivityLog;
import me.totalfreedom.totalfreedommod.admin.AdminList;
import me.totalfreedom.totalfreedommod.api.Aggregator;
import me.totalfreedom.totalfreedommod.api.ShoppeCommons;
import me.totalfreedom.totalfreedommod.api.TFD4JCommons;
import me.totalfreedom.totalfreedommod.api.VotifierCommons;
import me.totalfreedom.totalfreedommod.banning.BanManager;
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
@ -74,8 +77,8 @@ public class TotalFreedomMod extends JavaPlugin
public CommandLoader cl;
// Services
public WorldManager wm;
public AdminList al;
public ActivityLog acl;
public AdminList al;
public RankManager rm;
public CommandBlocker cb;
public EventBlocker eb;
@ -87,12 +90,12 @@ public class TotalFreedomMod extends JavaPlugin
public AntiNuke nu;
public AntiSpam as;
public PlayerList pl;
public Shop sh;
public Votifier vo;
public ShoppeCommons sh;
public SQLite sql;
public Announcer an;
public ChatManager cm;
public TFD4J dc;
public TFD4JCommons dc;
public Aggregator ag;
public PunishmentList pul;
public BanManager bm;
public IndefiniteBanList im;
@ -266,6 +269,18 @@ public class TotalFreedomMod extends JavaPlugin
}
}
public void registerDiscord() {
if (Bukkit.getPluginManager().isPluginEnabled("TFD4J")) {
dc = ag.getDiscordContext().getValue();
}
}
public void registerShoppe() {
if (Bukkit.getPluginManager().isPluginEnabled("TF-Shoppe")) {
sh = ag.getShoppeContext().getValue();
}
}
/**
* This class is provided to please Codacy.
*/
@ -299,18 +314,11 @@ public class TotalFreedomMod extends JavaPlugin
as = new AntiSpam();
wr = new WorldRestrictions();
pl = new PlayerList();
if (Bukkit.getPluginManager().isPluginEnabled("TF-Shoppe")) {
sh = new Shop();
vo = new Votifier();
}
ag = new Aggregator();
an = new Announcer();
cm = new ChatManager();
if (Bukkit.getPluginManager().isPluginEnabled("TFD4J")) {
dc = new TFM_Accessor().botAccessor();
}
pul = new PunishmentList();
bm = new BanManager();

View File

@ -0,0 +1,27 @@
package me.totalfreedom.totalfreedommod.api;
public class Aggregator
{
private Context<TFD4JCommons> discord;
private Context<ShoppeCommons> shoppe;
public Context<TFD4JCommons> getDiscordContext()
{
return discord;
}
public void setDiscordContext(Context<TFD4JCommons> discord)
{
this.discord = discord;
}
public Context<ShoppeCommons> getShoppeContext()
{
return shoppe;
}
public void setShoppeContext(Context<ShoppeCommons> shoppe)
{
this.shoppe = shoppe;
}
}

View File

@ -0,0 +1,16 @@
package me.totalfreedom.totalfreedommod.api;
public class Context<T>
{
private final T value;
public Context(T value)
{
this.value = value;
}
public T getValue()
{
return value;
}
}

View File

@ -0,0 +1,116 @@
package me.totalfreedom.totalfreedommod.api;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import org.bukkit.ChatColor;
import org.bukkit.Material;
public enum ShopItem
{
GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 10, ConfigEntry.SHOP_PRICES_GRAPPLING_HOOK, ChatColor.GREEN, "grapplingHook", "/grapplinghook"),
LIGHTNING_ROD("Lightning Rod", Material.BLAZE_ROD, 12, ConfigEntry.SHOP_PRICES_LIGHTNING_ROD, ChatColor.LIGHT_PURPLE, "lightningRod", "/lightningrod"),
FIRE_BALL("Fire Ball", Material.FIRE_CHARGE, 14, ConfigEntry.SHOP_PRICES_FIRE_BALL, ChatColor.RED, "fireBall", "/fireball"),
RIDEABLE_PEARL("Rideable Ender Pearl", Material.ENDER_PEARL, 16, ConfigEntry.SHOP_PRICES_RIDEABLE_PEARL, ChatColor.DARK_PURPLE, "rideablePearl", "/rideablepearl"),
STACKING_POTATO("Stacking Potato", Material.POTATO, 19, ConfigEntry.SHOP_PRICES_STACKING_POTATO, ChatColor.YELLOW, "stackingPotato", "/stackingpotato"),
CLOWN_FISH("Clown Fish", Material.TROPICAL_FISH, 21, ConfigEntry.SHOP_PRICES_CLOWN_FISH, ChatColor.GOLD, "clownFish", "/clownfish"),
LOGIN_MESSAGES("Login Messages", Material.NAME_TAG, 23, ConfigEntry.SHOP_PRICES_LOGIN_MESSAGES, ChatColor.DARK_GREEN, "loginMessages", "/loginmessage"),
RAINBOW_TRAIL("Rainbow Trail", Material.RED_WOOL, 25, ConfigEntry.SHOP_PRICES_RAINBOW_TRAIL, ChatColor.DARK_RED, "rainbowTrail", "/trail");
/*
Shop GUI Layout:
Dimensions: 9x4 = 36
Key:
g = Grappling Hook,
l = Lightning Rod
f = Fire Ball
r = Rideable Ender Pearl
s = Stacking Potato
c = Clown Fish
x = Login Messages
t = Rainbow Trail
$ = Coins
---------
-g-l-f-r-
-s-c-x-t-
--------$
*/
private final String name;
private final Material icon;
private final int slot;
private final ConfigEntry cost;
private final ChatColor color;
private final String dataName;
private final String command;
ShopItem(String name, Material icon, int slot, ConfigEntry cost, ChatColor color, String dataName, String command)
{
this.name = name;
this.icon = icon;
this.slot = slot;
this.cost = cost;
this.color = color;
this.dataName = dataName;
this.command = command;
}
public static ShopItem findItem(String string)
{
try
{
return ShopItem.valueOf(string.toUpperCase());
}
catch (Exception ignored)
{
}
return null;
}
public String getColoredName()
{
return color + name;
}
public int getCost()
{
return cost.getInteger();
}
public String getName()
{
return name;
}
public Material getIcon()
{
return icon;
}
public int getSlot()
{
return slot;
}
public ChatColor getColor()
{
return color;
}
public String getDataName()
{
return dataName;
}
public String getCommand()
{
return command;
}
}

View File

@ -0,0 +1,55 @@
package me.totalfreedom.totalfreedommod.api;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public interface ShoppeCommons
{
int getCoinsPerReactionWin();
void startReactionTimer();
void forceStartReaction();
void startReaction();
void endReaction(String winner);
String getShopPrefix();
String getShopTitle();
Inventory generateShopGUI(PlayerData playerData);
Inventory generateLoginMessageGUI(Player player);
boolean isRealItem(PlayerData data, ShopItem shopItem, PlayerInventory inventory, ItemStack realItem);
boolean isRealItem(PlayerData data, ShopItem shopItem, ItemStack givenItem, ItemStack realItem);
ItemStack getLightningRod();
ItemStack getGrapplingHook();
ItemStack getFireBall();
ItemStack getRideablePearl();
ItemStack getStackingPotato();
ItemStack getClownFish();
boolean canAfford(int price, int coins);
int amountNeeded(int price, int coins);
ItemStack shopGUIItem(ShopItem item, PlayerData data);
ShopItem getShopItem(int slot);
String getReactionString();
}

View File

@ -0,0 +1,33 @@
package me.totalfreedom.totalfreedommod.api;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public interface TFD4JCommons
{
void messageAdminChatChannel(String message);
void clearQueue();
void messageChatChannel(String message, boolean system);
boolean syncRoles(Admin admin, String id);
String getCode(PlayerData playerData);
String generateCode(int size);
Map<String, PlayerData> getLinkCodes();
String formatBotTag();
boolean sendReportOffline(Player reporter, OfflinePlayer reported, String reason);
boolean sendReport(Player reporter, Player reported, String reason);
boolean isEnabled();
}

View File

@ -18,7 +18,7 @@ public class Command_cleardiscordqueue extends FreedomCommand
return true;
}
plugin.dc.getUtils().clearQueue();
plugin.dc.clearQueue();
msg("Cleared the discord message queue.");
return true;
}

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;

View File

@ -25,7 +25,7 @@ public class Command_consolesay extends FreedomCommand
FUtil.bcastMsg(String.format("§7[CONSOLE] §c%s §8» §f%s", sender.getName(), StringUtils.join(args, " ")));
if (plugin.dc != null) {
plugin.dc.getUtils().messageChatChannel("[CONSOLE] " + sender.getName() + " \u00BB " + ChatColor.stripColor(message), true);
plugin.dc.messageChatChannel("[CONSOLE] " + sender.getName() + " \u00BB " + ChatColor.stripColor(message), true);
}

View File

@ -53,7 +53,7 @@ public class Command_doom extends FreedomCommand
plugin.al.updateTables();
if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
plugin.dc.getBot().syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
plugin.dc.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
}
}

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@ -44,16 +44,16 @@ public class Command_linkdiscord extends FreedomCommand
return true;
}
if (plugin.dc.getBot().getLinkCodes().containsValue(data))
if (plugin.dc.getLinkCodes().containsValue(data))
{
code = plugin.dc.getBot().getCode(data);
code = plugin.dc.getCode(data);
} else
{
code = plugin.dc.getBot().generateCode(5);
plugin.dc.getBot().getLinkCodes().put(code, data);
code = plugin.dc.generateCode(5);
plugin.dc.getLinkCodes().put(code, data);
}
msg("Your linking code is " + ChatColor.AQUA + code, ChatColor.GREEN);
msg("Take this code and DM the server bot (" + plugin.dc.getBot().formatBotTag() + ") the code (do not put anything else in the message, only the code)");
msg("Take this code and DM the server bot (" + plugin.dc.formatBotTag() + ") the code (do not put anything else in the message, only the code)");
return true;
}
}

View File

@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;

View File

@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;

View File

@ -173,7 +173,7 @@ public class Command_myadmin extends FreedomCommand
msg("Please run /linkdiscord first!", ChatColor.RED);
return true;
}
boolean synced = plugin.dc.getBot().syncRoles(target, playerData.getDiscordID());
boolean synced = plugin.dc.syncRoles(target, playerData.getDiscordID());
if (synced)
{
msg("Successfully synced your roles.", ChatColor.GREEN);

View File

@ -56,7 +56,7 @@ public class Command_report extends FreedomCommand
if (plugin.dc != null && plugin.dc.isEnabled())
{
logged = (player == null) ? plugin.dc.getUtils().sendReportOffline(playerSender, offlinePlayer, report) : plugin.dc.getUtils().sendReport(playerSender, player, report);
logged = (player == null) ? plugin.dc.sendReportOffline(playerSender, offlinePlayer, report) : plugin.dc.sendReport(playerSender, player, report);
}
msg(ChatColor.GREEN + "Thank you, your report has been successfully logged."

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@ -108,7 +108,7 @@ public class Command_saconfig extends FreedomCommand
if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
plugin.dc.getBot().syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
plugin.dc.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
}
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
@ -204,7 +204,7 @@ public class Command_saconfig extends FreedomCommand
if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
plugin.dc.getBot().syncRoles(admin, plugin.pl.getData(player).getDiscordID());
plugin.dc.syncRoles(admin, plugin.pl.getData(player).getDiscordID());
}
}
@ -258,7 +258,7 @@ public class Command_saconfig extends FreedomCommand
if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
plugin.dc.getBot().syncRoles(admin, plugin.pl.getData(adminName).getDiscordID());
plugin.dc.syncRoles(admin, plugin.pl.getData(adminName).getDiscordID());
}
return true;

View File

@ -43,7 +43,7 @@ public class Command_say extends FreedomCommand
FUtil.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE);
if (plugin.dc != null) {
plugin.dc.getUtils().messageChatChannel(String.format("[Server:%s] \u00BB %s", sender.getName(), message), true);
plugin.dc.messageChatChannel(String.format("[Server:%s] \u00BB %s", sender.getName(), message), true);
}
return true;

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@ -48,7 +48,7 @@ public class Command_vanish extends FreedomCommand
.color(NamedTextColor.YELLOW));
if (plugin.dc != null) {
plugin.dc.getUtils().messageChatChannel("**" + playerSender.getName() + " joined the server" + "**", true);
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**", true);
}
}
@ -101,7 +101,7 @@ public class Command_vanish extends FreedomCommand
server.broadcast(Component.translatable("multiplayer.player.left", Component.text(playerSender.getName()))
.color(NamedTextColor.YELLOW));
if (plugin.dc != null) {
plugin.dc.getUtils().messageChatChannel("**" + playerSender.getName() + " left the server" + "**", true);
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**", true);
}
}

View File

@ -1,6 +1,6 @@
package me.totalfreedom.totalfreedommod.fun;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;

View File

@ -7,7 +7,7 @@ import java.util.SplittableRandom;
import java.util.UUID;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@ -5,7 +5,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import me.totalfreedom.shop.ShopItem;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;