From f53696aa9ecfd603af009512e65e70c1dc4611cd Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Thu, 16 Feb 2023 20:28:38 -0600 Subject: [PATCH] dissc --- .../totalfreedommod/FreedomService.java | 2 +- .../totalfreedommod/TotalFreedomMod.java | 10 ++--- .../bridge/EXDiscordBridge.java | 44 +++++++++++++++++++ .../bridge/EssentialsBridge.java | 6 ++- .../command/FreedomCommand.java | 2 +- .../discord/DiscordToMinecraftListener.java | 2 +- 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/bridge/EXDiscordBridge.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java b/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java index 7b66bbe5..f8c8aaa4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java @@ -11,7 +11,7 @@ public abstract class FreedomService implements Listener protected final Server server; protected final Logger logger; - public FreedomService() + protected FreedomService() { plugin = TotalFreedomMod.getPlugin(); server = plugin.getServer(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 9517e4dd..68588f94 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -236,6 +236,7 @@ public class TotalFreedomMod extends JavaPlugin try { final Properties props; + final String unknown = "unknown"; try (InputStream in = plugin.getResource("build.properties")) { @@ -243,13 +244,12 @@ public class TotalFreedomMod extends JavaPlugin props.load(in); } - author = props.getProperty("buildAuthor", "unknown"); - codename = props.getProperty("buildCodeName", "unknown"); + author = props.getProperty("buildAuthor", unknown); + codename = props.getProperty("buildCodeName", unknown); version = props.getProperty("buildVersion", pluginVersion); number = props.getProperty("buildNumber", "1"); - date = props.getProperty("buildDate", "unknown"); - // Need to do this or it will display ${git.commit.id.abbrev} - head = props.getProperty("buildHead", "unknown").replace("${git.commit.id.abbrev}", "unknown"); + date = props.getProperty("buildDate", unknown); + head = props.getProperty("buildHead", unknown).replace("${git.commit.id.abbrev}", unknown); } catch (Exception ex) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EXDiscordBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EXDiscordBridge.java new file mode 100644 index 00000000..ac0146e9 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EXDiscordBridge.java @@ -0,0 +1,44 @@ +package me.totalfreedom.totalfreedommod.bridge; + +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.util.FLog; +import net.essentialsx.discord.EssentialsDiscord; +import org.bukkit.plugin.Plugin; + +public class EXDiscordBridge extends FreedomService +{ + private EssentialsDiscord essentialsDiscord = null; + + @Override + public void onStart() + { + // This is completely useless, but it's here to make sure the service is loaded. + } + + @Override + public void onStop() + { + essentialsDiscord = null; + } + + public EssentialsDiscord getEssentialsDiscord() + { + if (essentialsDiscord == null) + { + try + { + final Plugin xDiscord = server.getPluginManager().getPlugin("EssentialsXDiscord"); + assert xDiscord != null; + if (xDiscord instanceof EssentialsDiscord e) + { + essentialsDiscord = e; + } + } + catch (Exception ex) + { + FLog.severe(ex); + } + } + return essentialsDiscord; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java index 8764c915..fc25b54f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java @@ -28,11 +28,13 @@ public class EssentialsBridge extends FreedomService @Override public void onStart() { + // This is completely useless, but it's here to make sure the service is loaded. } @Override public void onStop() { + essentialsPlugin = null; } public Essentials getEssentialsPlugin() @@ -43,9 +45,9 @@ public class EssentialsBridge extends FreedomService { final Plugin essentials = server.getPluginManager().getPlugin("Essentials"); assert essentials != null; - if (essentials instanceof Essentials) + if (essentials instanceof Essentials e) { - essentialsPlugin = (Essentials)essentials; + essentialsPlugin = e; } } catch (Exception ex) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index b718a826..dc2ecfec 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -32,7 +32,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter public static final String ONLY_IN_GAME = ChatColor.RED + "Only in-game players may execute this command!"; public static final String NO_PERMISSION = ChatColor.RED + "You do not have permission to execute this command."; public static final Timer timer = new Timer(); - public static final Map COOLDOWN_TIMERS = new HashMap<>(); + protected static final Map COOLDOWN_TIMERS = new HashMap<>(); protected final TotalFreedomMod plugin = TotalFreedomMod.getPlugin(); protected final Server server = plugin.getServer(); private final String name; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index bd8d849d..01c1c638 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -121,7 +121,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter } } - FLog.info(TextComponent.toLegacyText(components), true); + FLog.info(BaseComponent.toLegacyText(components), true); }