From f4aa3bd3b9b52fac085067b1c772a3e101eda6c4 Mon Sep 17 00:00:00 2001
From: Telesphoreo <me@telesphoreo.me>
Date: Sun, 20 Jun 2021 03:02:07 -0500
Subject: [PATCH] Some updates

---
 pom.xml                                       | 24 ++++++----
 .../exception/ConsoleOnlyException.java       | 11 +++++
 .../java/dev/plex/command/impl/AdminCMD.java  | 20 ++++----
 .../dev/plex/command/impl/AdminworldCMD.java  | 48 +++++++++++++++++++
 .../java/dev/plex/command/impl/BanCMD.java    |  2 +-
 .../dev/plex/command/impl/FlatlandsCMD.java   | 47 ++++++++++++++++++
 .../command/impl/MasterbuilderworldCMD.java   | 48 +++++++++++++++++++
 .../java/dev/plex/command/impl/PlexCMD.java   |  5 +-
 .../dev/plex/handlers/CommandHandler.java     |  9 +++-
 .../dev/plex/handlers/ListenerHandler.java    |  2 +-
 .../dev/plex/listener/impl/AdminListener.java |  7 +--
 .../dev/plex/listener/impl/ChatListener.java  |  5 +-
 .../plex/listener/impl/FreezeListener.java    |  1 -
 .../dev/plex/listener/impl/LoginListener.java |  3 +-
 src/main/java/dev/plex/util/PlexUtils.java    |  2 +-
 src/main/resources/messages.yml               |  9 +++-
 16 files changed, 209 insertions(+), 34 deletions(-)
 create mode 100644 src/main/java/dev/plex/command/exception/ConsoleOnlyException.java
 create mode 100644 src/main/java/dev/plex/command/impl/AdminworldCMD.java
 create mode 100644 src/main/java/dev/plex/command/impl/FlatlandsCMD.java
 create mode 100644 src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java

diff --git a/pom.xml b/pom.xml
index 3b07ec1..4eaf873 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,21 +27,27 @@
         <dependency>
             <groupId>com.destroystokyo.paper</groupId>
             <artifactId>paper-api</artifactId>
-            <version>1.16.4-R0.1-SNAPSHOT</version>
+            <version>1.16.5-R0.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>io.papermc</groupId>
+            <artifactId>paperlib</artifactId>
+            <version>1.0.6</version>
+            <scope>compile</scope>
+        </dependency>
 
         <!-- UTILITIES -->
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
-            <version>1.18.16</version>
+            <version>1.18.20</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.json</groupId>
             <artifactId>json</artifactId>
-            <version>20201115</version>
+            <version>20210307</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
@@ -56,19 +62,19 @@
         <dependency>
             <groupId>dev.morphia.morphia</groupId>
             <artifactId>morphia-core</artifactId>
-            <version>2.1.3</version>
+            <version>2.1.7</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>redis.clients</groupId>
             <artifactId>jedis</artifactId>
-            <version>3.4.1</version>
+            <version>3.6.1</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.mariadb.jdbc</groupId>
             <artifactId>mariadb-java-client</artifactId>
-            <version>2.7.1</version>
+            <version>2.7.3</version>
             <scope>compile</scope>
         </dependency>
     </dependencies>
@@ -86,14 +92,14 @@
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.8.1</version>
                 <configuration>
-                    <source>11</source>
-                    <target>11</target>
+                    <source>16</source>
+                    <target>16</target>
                 </configuration>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
-                <version>3.2.4</version>
+                <version>3.3.0-SNAPSHOT</version>
                 <executions>
                     <execution>
                         <phase>package</phase>
diff --git a/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java b/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java
new file mode 100644
index 0000000..0cf2a73
--- /dev/null
+++ b/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java
@@ -0,0 +1,11 @@
+package dev.plex.command.exception;
+
+import static dev.plex.util.PlexUtils.tl;
+
+public class ConsoleOnlyException extends RuntimeException
+{
+    public ConsoleOnlyException()
+    {
+        super(tl("consoleOnly"));
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/dev/plex/command/impl/AdminCMD.java b/src/main/java/dev/plex/command/impl/AdminCMD.java
index ddd95f9..95aa19a 100644
--- a/src/main/java/dev/plex/command/impl/AdminCMD.java
+++ b/src/main/java/dev/plex/command/impl/AdminCMD.java
@@ -3,6 +3,7 @@ package dev.plex.command.impl;
 import com.google.common.collect.ImmutableList;
 import dev.plex.command.annotation.CommandParameters;
 import dev.plex.command.annotation.CommandPermissions;
+import dev.plex.command.exception.ConsoleOnlyException;
 import dev.plex.command.exception.PlayerNotFoundException;
 import dev.plex.command.source.CommandSource;
 import dev.plex.command.source.RequiredCommandSource;
@@ -50,8 +51,7 @@ public class AdminCMD extends PlexCommand
 
             if (!sender.isConsoleSender())
             {
-                sender.send("Console only");
-                return;
+                throw new ConsoleOnlyException();
             }
 
             UUID targetUUID = PlexUtils.getFromName(args[1]);
@@ -64,7 +64,7 @@ public class AdminCMD extends PlexCommand
 
             if (isAdmin(plexPlayer))
             {
-                sender.send("Player is an admin");
+                sender.send(tl("playerIsAdmin"));
                 return;
             }
 
@@ -83,8 +83,7 @@ public class AdminCMD extends PlexCommand
 
             if (!sender.isConsoleSender())
             {
-                sender.send("Console only");
-                return;
+                throw new ConsoleOnlyException();
             }
 
             UUID targetUUID = PlexUtils.getFromName(args[1]);
@@ -97,7 +96,7 @@ public class AdminCMD extends PlexCommand
 
             if (!isAdmin(plexPlayer))
             {
-                sender.send("Player is not an admin");
+                sender.send(tl("playerNotAdmin"));
                 return;
             }
 
@@ -117,8 +116,7 @@ public class AdminCMD extends PlexCommand
 
             if (!sender.isConsoleSender())
             {
-                sender.send("Console only");
-                return;
+                throw new ConsoleOnlyException();
             }
 
             UUID targetUUID = PlexUtils.getFromName(args[1]);
@@ -130,7 +128,7 @@ public class AdminCMD extends PlexCommand
 
             if (!rankExists(args[2]))
             {
-                sender.send("Rank not found");
+                sender.send(tl("rankNotFound"));
                 return;
             }
 
@@ -138,7 +136,7 @@ public class AdminCMD extends PlexCommand
 
             if (!rank.isAtLeast(Rank.ADMIN))
             {
-                sender.send("Must be admin+");
+                sender.send(tl("rankMustBeHigherThanAdmin"));
                 return;
             }
 
@@ -146,7 +144,7 @@ public class AdminCMD extends PlexCommand
 
             if (!isAdmin(plexPlayer))
             {
-                sender.send("Player is not an admin");
+                sender.send(tl("playerNotAdmin"));
                 return;
             }
 
diff --git a/src/main/java/dev/plex/command/impl/AdminworldCMD.java b/src/main/java/dev/plex/command/impl/AdminworldCMD.java
new file mode 100644
index 0000000..a5888a0
--- /dev/null
+++ b/src/main/java/dev/plex/command/impl/AdminworldCMD.java
@@ -0,0 +1,48 @@
+package dev.plex.command.impl;
+
+import dev.plex.command.annotation.CommandParameters;
+import dev.plex.command.annotation.CommandPermissions;
+import dev.plex.command.exception.CommandFailException;
+import dev.plex.command.source.CommandSource;
+import dev.plex.command.source.RequiredCommandSource;
+import io.papermc.lib.PaperLib;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import dev.plex.command.PlexCommand;
+import dev.plex.rank.enums.Rank;
+import dev.plex.util.PlexUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
+@CommandParameters(aliases = "aw", description = "Teleport to the adminworld")
+public class AdminworldCMD extends PlexCommand
+{
+    public AdminworldCMD()
+    {
+        super("adminworld");
+    }
+
+    @Override
+    public void execute(CommandSource sender, String[] args)
+    {
+        // TODO: Add adminworld settings
+        if (args.length == 0)
+        {
+            Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0);
+            PaperLib.teleportAsync(sender.getPlayer(), loc);
+            send(tl("teleportedToWorld", "adminworld"));
+        }
+    }
+
+    @Override
+    public List<String> onTabComplete(CommandSource sender, String[] args)
+    {
+        return Collections.emptyList();
+    }
+}
diff --git a/src/main/java/dev/plex/command/impl/BanCMD.java b/src/main/java/dev/plex/command/impl/BanCMD.java
index 49698ae..7a4befe 100644
--- a/src/main/java/dev/plex/command/impl/BanCMD.java
+++ b/src/main/java/dev/plex/command/impl/BanCMD.java
@@ -57,7 +57,7 @@ public class BanCMD extends PlexCommand
                     PlexPlayer plexPlayer1 = sender.getPlexPlayer();
                     if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
                     {
-                        sender.send("This player is an admin and a higher rank than you.");
+                        sender.send(tl("higherRankThanYou"));
                         return;
                     }
                 }
diff --git a/src/main/java/dev/plex/command/impl/FlatlandsCMD.java b/src/main/java/dev/plex/command/impl/FlatlandsCMD.java
new file mode 100644
index 0000000..ce23b87
--- /dev/null
+++ b/src/main/java/dev/plex/command/impl/FlatlandsCMD.java
@@ -0,0 +1,47 @@
+package dev.plex.command.impl;
+
+import dev.plex.command.annotation.CommandParameters;
+import dev.plex.command.annotation.CommandPermissions;
+import dev.plex.command.exception.CommandFailException;
+import dev.plex.command.source.CommandSource;
+import dev.plex.command.source.RequiredCommandSource;
+import io.papermc.lib.PaperLib;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import dev.plex.command.PlexCommand;
+import dev.plex.rank.enums.Rank;
+import dev.plex.util.PlexUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
+@CommandParameters(description = "Teleport to the flatlands")
+public class FlatlandsCMD extends PlexCommand
+{
+    public FlatlandsCMD()
+    {
+        super("flatlands");
+    }
+
+    @Override
+    public void execute(CommandSource sender, String[] args)
+    {
+        if (args.length == 0)
+        {
+            Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0);
+            PaperLib.teleportAsync(sender.getPlayer(), loc);
+            send(tl("teleportedToWorld", "flatlands"));
+        }
+    }
+
+    @Override
+    public List<String> onTabComplete(CommandSource sender, String[] args)
+    {
+        return Collections.emptyList();
+    }
+}
diff --git a/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java b/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java
new file mode 100644
index 0000000..4ddc724
--- /dev/null
+++ b/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java
@@ -0,0 +1,48 @@
+package dev.plex.command.impl;
+
+import dev.plex.command.annotation.CommandParameters;
+import dev.plex.command.annotation.CommandPermissions;
+import dev.plex.command.exception.CommandFailException;
+import dev.plex.command.source.CommandSource;
+import dev.plex.command.source.RequiredCommandSource;
+import io.papermc.lib.PaperLib;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import dev.plex.command.PlexCommand;
+import dev.plex.rank.enums.Rank;
+import dev.plex.util.PlexUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
+@CommandParameters(aliases = "mbw", description = "Teleport to the Master Builder world")
+public class MasterbuilderworldCMD extends PlexCommand
+{
+    public MasterbuilderworldCMD()
+    {
+        super("masterbuilderworld");
+    }
+
+    @Override
+    public void execute(CommandSource sender, String[] args)
+    {
+        // TODO: Add adminworld settings
+        if (args.length == 0)
+        {
+            Location loc = new Location(Bukkit.getWorld("masterbuilderworld"), 0, 50, 0);
+            PaperLib.teleportAsync(sender.getPlayer(), loc);
+            send(tl("teleportedToWorld", "Master Builder world"));
+        }
+    }
+
+    @Override
+    public List<String> onTabComplete(CommandSource sender, String[] args)
+    {
+        return Collections.emptyList();
+    }
+}
diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java
index da7a3b5..3d505b6 100644
--- a/src/main/java/dev/plex/command/impl/PlexCMD.java
+++ b/src/main/java/dev/plex/command/impl/PlexCMD.java
@@ -1,5 +1,6 @@
 package dev.plex.command.impl;
 
+import dev.plex.Plex;
 import dev.plex.command.annotation.CommandParameters;
 import dev.plex.command.annotation.CommandPermissions;
 import dev.plex.command.source.CommandSource;
@@ -8,6 +9,7 @@ import java.util.Arrays;
 import java.util.List;
 import dev.plex.command.PlexCommand;
 import dev.plex.rank.enums.Rank;
+import org.bukkit.ChatColor;
 
 @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
 @CommandParameters(aliases = "plexhelp", description = "Help with plex")
@@ -21,7 +23,8 @@ public class PlexCMD extends PlexCommand
     @Override
     public void execute(CommandSource sender, String[] args)
     {
-        send("HI");
+        send(ChatColor.LIGHT_PURPLE + "Plex. The long awaited TotalFreedomMod rewrite starts here...");
+        send(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + "1.0");
     }
 
     @Override
diff --git a/src/main/java/dev/plex/handlers/CommandHandler.java b/src/main/java/dev/plex/handlers/CommandHandler.java
index fee5e3a..75bc118 100644
--- a/src/main/java/dev/plex/handlers/CommandHandler.java
+++ b/src/main/java/dev/plex/handlers/CommandHandler.java
@@ -2,11 +2,14 @@ package dev.plex.handlers;
 
 import com.google.common.collect.Lists;
 import dev.plex.command.impl.AdminCMD;
+import dev.plex.command.impl.AdminworldCMD;
 import dev.plex.command.impl.AdventureCMD;
 import dev.plex.command.impl.BanCMD;
 import dev.plex.command.impl.CreativeCMD;
 import dev.plex.command.impl.FionnCMD;
+import dev.plex.command.impl.FlatlandsCMD;
 import dev.plex.command.impl.FreezeCMD;
+import dev.plex.command.impl.MasterbuilderworldCMD;
 import dev.plex.command.impl.NameHistoryCMD;
 import dev.plex.command.impl.OpAllCMD;
 import dev.plex.command.impl.OpCMD;
@@ -22,10 +25,9 @@ import dev.plex.util.PlexLog;
 
 public class CommandHandler
 {
-    private List<PlexCommand> commands = Lists.newArrayList();
-
     public CommandHandler()
     {
+        List<PlexCommand> commands = Lists.newArrayList();
         commands.add(new TestCMD());
         commands.add(new PlexCMD());
         commands.add(new FionnCMD());
@@ -41,6 +43,9 @@ public class CommandHandler
         commands.add(new SpectatorCMD());
         commands.add(new BanCMD());
         commands.add(new PunishmentsCMD());
+        commands.add(new FlatlandsCMD());
+        commands.add(new AdminworldCMD());
+        commands.add(new MasterbuilderworldCMD());
         PlexLog.log(String.format("Registered %s commands!", commands.size()));
     }
 }
diff --git a/src/main/java/dev/plex/handlers/ListenerHandler.java b/src/main/java/dev/plex/handlers/ListenerHandler.java
index 4c9cb4a..4aa3888 100644
--- a/src/main/java/dev/plex/handlers/ListenerHandler.java
+++ b/src/main/java/dev/plex/handlers/ListenerHandler.java
@@ -14,9 +14,9 @@ import dev.plex.util.PlexLog;
 
 public class ListenerHandler
 {
-    List<PlexListener> listeners = Lists.newArrayList();
     public ListenerHandler()
     {
+        List<PlexListener> listeners = Lists.newArrayList();
         listeners.add(new ServerListener());
         listeners.add(new ChatListener());
         listeners.add(new PlayerListener());
diff --git a/src/main/java/dev/plex/listener/impl/AdminListener.java b/src/main/java/dev/plex/listener/impl/AdminListener.java
index 9ac8fed..e00f201 100644
--- a/src/main/java/dev/plex/listener/impl/AdminListener.java
+++ b/src/main/java/dev/plex/listener/impl/AdminListener.java
@@ -7,6 +7,7 @@ import dev.plex.listener.PlexListener;
 import dev.plex.player.PlexPlayer;
 import dev.plex.rank.enums.Rank;
 import static dev.plex.util.PlexUtils.tl;
+import dev.plex.util.PlexUtils;
 import org.bukkit.Bukkit;
 import org.bukkit.event.EventHandler;
 
@@ -18,7 +19,7 @@ public class AdminListener extends PlexListener
         String userSender = event.getSender().getName();
         PlexPlayer target = event.getPlexPlayer();
 
-        Bukkit.broadcastMessage(tl("newAdminAdded", userSender, target.getName()));
+        PlexUtils.broadcast(tl("newAdminAdded", userSender, target.getName()));
     }
 
     @EventHandler
@@ -27,7 +28,7 @@ public class AdminListener extends PlexListener
         String userSender = event.getSender().getName();
         PlexPlayer target = event.getPlexPlayer();
 
-        Bukkit.broadcastMessage(tl("adminRemoved", userSender, target.getName()));
+        PlexUtils.broadcast(tl("adminRemoved", userSender, target.getName()));
     }
 
     @EventHandler
@@ -37,6 +38,6 @@ public class AdminListener extends PlexListener
         PlexPlayer target = event.getPlexPlayer();
         Rank newRank = event.getRank();
 
-        Bukkit.broadcastMessage(tl("adminSetRank", userSender, target.getName(), newRank.name().toUpperCase()));
+        PlexUtils.broadcast(tl("adminSetRank", userSender, target.getName(), newRank.name().toUpperCase()));
     }
 }
diff --git a/src/main/java/dev/plex/listener/impl/ChatListener.java b/src/main/java/dev/plex/listener/impl/ChatListener.java
index 3f7c58e..95e26f1 100644
--- a/src/main/java/dev/plex/listener/impl/ChatListener.java
+++ b/src/main/java/dev/plex/listener/impl/ChatListener.java
@@ -23,6 +23,9 @@ public class ChatListener extends PlexListener
         {
             event.setFormat(String.format("%s %s §7» %s", plexPlayer.getRankFromString().getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage()));
         }
+        else
+        {
+            event.setFormat(String.format("%s §7» %s", ChatColor.RESET + plexPlayer.getName(), event.getMessage()));
+        }
     }
-
 }
diff --git a/src/main/java/dev/plex/listener/impl/FreezeListener.java b/src/main/java/dev/plex/listener/impl/FreezeListener.java
index 656e07d..6681e6d 100644
--- a/src/main/java/dev/plex/listener/impl/FreezeListener.java
+++ b/src/main/java/dev/plex/listener/impl/FreezeListener.java
@@ -17,5 +17,4 @@ public class FreezeListener extends PlexListener
             e.setCancelled(true);
         }
     }
-
 }
\ No newline at end of file
diff --git a/src/main/java/dev/plex/listener/impl/LoginListener.java b/src/main/java/dev/plex/listener/impl/LoginListener.java
index 9ac83a7..8b8fbde 100644
--- a/src/main/java/dev/plex/listener/impl/LoginListener.java
+++ b/src/main/java/dev/plex/listener/impl/LoginListener.java
@@ -7,7 +7,6 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
 
 public class LoginListener extends PlexListener
 {
-
     //TODO: Customizable MSGS
 
     @EventHandler
@@ -16,7 +15,7 @@ public class LoginListener extends PlexListener
         PlexLog.log(String.valueOf(plugin.getBanManager().isBanned(event.getUniqueId())));
         if (plugin.getBanManager().isBanned(event.getUniqueId()))
         {
-            event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, "§cYou're currently banned from this server.\n§cPlease appeal at §6https://forums.telesphoreo.me");
+            event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, "§cYou're currently banned from this server.\n§cPlease appeal at §6https://forum.telesphoreo.me");
         }
     }
 
diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java
index e26b3c9..e21796f 100644
--- a/src/main/java/dev/plex/util/PlexUtils.java
+++ b/src/main/java/dev/plex/util/PlexUtils.java
@@ -29,7 +29,7 @@ public class PlexUtils
 {
     public static Map<String, ChatColor> CHAT_COLOR_NAMES;
     public static List<ChatColor> CHAT_COLOR_POOL;
-    private static Random RANDOM;
+    private static final Random RANDOM;
 
     static
     {
diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml
index 2748834..9eeb74d 100644
--- a/src/main/resources/messages.yml
+++ b/src/main/resources/messages.yml
@@ -57,4 +57,11 @@ playerSetOtherGameMode: <v> set your gamemode to <v>.
 consoleMustDefinePlayer: You must define a player since you are running this command from console.
 newAdminAdded: <b><v> - Adding <v> to the admin list
 adminRemoved: <c><v> - Removing <v> from the admin list
-adminSetRank: <b><v> - Setting <v>'s rank to <v>
\ No newline at end of file
+adminSetRank: <b><v> - Setting <v>'s rank to <v>
+teleportedToWorld: <b>You have been teleported to the <v>.
+higherRankThanYou: <b>This player is an admin and a higher rank than you.
+playerNotAdmin: <b>That player is not an admin.
+playerIsAdmin: <b>That player is already an admin.
+rankNotFound: <b>The rank you entered was not found.
+rankMustBeHigherThanAdmin: <b>The rank you entered must be higher than Admin.
+consoleOnly: <b>This command can only be executed by the console.
\ No newline at end of file