From 76bb2d08acb9a56a845377e2106a8f7e2d8a0750 Mon Sep 17 00:00:00 2001
From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com>
Date: Fri, 31 Jul 2020 21:10:44 -0700
Subject: [PATCH] Split gcmd sub cmds out n other stuff
---
pom.xml | 11 +-
.../totalfreedommod/BackupManager.java | 12 ++
.../totalfreedommod/TotalFreedomMod.java | 33 +--
.../totalfreedommod/banning/Ban.java | 15 +-
.../bridge/TFGuildsBridge.java | 39 ++--
.../command/CommandLoader.java | 23 +++
.../command/Command_banip.java | 82 ++++++++
.../command/Command_banname.java | 68 +++++++
.../totalfreedommod/command/Command_doom.java | 16 +-
.../command/Command_glist.java | 188 ------------------
.../totalfreedommod/command/Command_kick.java | 35 +++-
.../command/Command_linkdiscord.java | 2 +-
.../command/Command_unbanip.java | 62 ++++++
.../command/Command_unbanname.java | 56 ++++++
.../command/FreedomCommand.java | 2 +-
.../totalfreedommod/config/ConfigEntry.java | 3 +-
.../totalfreedommod/config/MainConfig.java | 2 +-
.../totalfreedommod/util/FLog.java | 9 +
.../totalfreedommod/util/FUtil.java | 21 +-
src/main/resources/config.yml | 3 +
src/main/resources/plugin.yml | 4 +-
21 files changed, 431 insertions(+), 255 deletions(-)
create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java
create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java
delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java
create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java
create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java
diff --git a/pom.xml b/pom.xml
index d099db34..db8a40af 100644
--- a/pom.xml
+++ b/pom.xml
@@ -240,9 +240,16 @@
com.github.speedxx
TFGuilds
- master-SNAPSHOT
+ master
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.1.1
+
+
+
@@ -418,7 +425,7 @@
org.apache.maven.plugins
- 2.17
+ 3.1.1
maven-checkstyle-plugin
checkstyle.xml
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java b/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java
index 5c798087..e70033d3 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java
@@ -2,7 +2,10 @@ package me.totalfreedom.totalfreedommod;
import com.sk89q.worldedit.bukkit.BukkitConfiguration;
import java.io.File;
+import me.totalfreedom.totalfreedommod.banning.PermbanList;
import me.totalfreedom.totalfreedommod.config.YamlConfig;
+import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
+import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.util.FileUtil;
@@ -25,6 +28,15 @@ public class BackupManager extends FreedomService
createBackups(file, false);
}
+ public void createAllBackups()
+ {
+ createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
+ createBackups(PermbanList.CONFIG_FILENAME);
+ createBackups(PermissionConfig.PERMISSIONS_FILENAME, true);
+ createBackups(PunishmentList.CONFIG_FILENAME);
+ createBackups("database.db");
+ }
+
public void createBackups(String file, boolean onlyWeekly)
{
final String save = file.split("\\.")[0];
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
index d3d0624e..c14763a0 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
@@ -181,33 +181,20 @@ public class TotalFreedomMod extends JavaPlugin
FUtil.deleteFolder(new File("./_deleteme"));
fsh = new FreedomServiceHandler();
+
+ config = new MainConfig();
+ config.load();
+
cl = new CommandLoader();
-
- Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command");
-
- Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
-
- for (Class extends FreedomCommand> commandClass : commandClasses)
- {
- try
- {
- cl.add(commandClass.newInstance());
- }
- catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex)
- {
- FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_" , ""));
- }
- }
+ cl.loadCommands();
BackupManager backups = new BackupManager();
- backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
- backups.createBackups(PermbanList.CONFIG_FILENAME);
- backups.createBackups(PermissionConfig.PERMISSIONS_FILENAME, true);
- backups.createBackups(PunishmentList.CONFIG_FILENAME);
- backups.createBackups("database.db");
+ backups.createAllBackups();
- config = new MainConfig(this);
- config.load();
+ if (FUtil.inDeveloperMode())
+ {
+ FLog.debug("Developer mode enabled.");
+ }
permissions = new PermissionConfig(this);
permissions.load();
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
index 1c5b7a23..11a56c04 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
@@ -166,7 +166,20 @@ public class Ban implements IConfig
{
final StringBuilder message = new StringBuilder(ChatColor.GOLD + "You");
- message.append(!hasUsername() ? "r IP address is" : " are").append(" temporarily banned from this server.");
+ if (!hasUsername())
+ {
+ message.append("r IP address is");
+ }
+ else if (!hasIps())
+ {
+ message.append("r username is");
+ }
+ else
+ {
+ message.append(" are");
+ }
+
+ message.append(" temporarily banned from this server.");
message.append("\nAppeal at ").append(ChatColor.BLUE)
.append(ConfigEntry.SERVER_BAN_URL.getString());
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/TFGuildsBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/TFGuildsBridge.java
index f1cd15c3..6b7dd993 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/TFGuildsBridge.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/TFGuildsBridge.java
@@ -3,14 +3,13 @@ package me.totalfreedom.totalfreedommod.bridge;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.totalfreedommod.FreedomService;
-import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class TFGuildsBridge extends FreedomService
{
- private TFGuilds tfGuildsPlugin = null;
+ public boolean enabled = false;
@Override
public void onStart()
@@ -22,31 +21,39 @@ public class TFGuildsBridge extends FreedomService
{
}
- public TFGuilds getTfGuildsPlugin()
+ public boolean isTFGuildsEnabled()
{
- if (tfGuildsPlugin == null)
+ if (enabled)
{
- try
+ return true;
+ }
+
+ try
+ {
+ final Plugin tfGuilds = server.getPluginManager().getPlugin("TFGuilds");
+ if (tfGuilds != null && tfGuilds.isEnabled())
{
- final Plugin tfGuilds = server.getPluginManager().getPlugin("TFGuilds");
- if (tfGuilds != null)
+ if (tfGuilds instanceof TFGuilds)
{
- if (tfGuilds instanceof TFGuilds)
- {
- tfGuildsPlugin = (TFGuilds)tfGuilds;
- }
+ enabled = true;
+ return true;
}
}
- catch (Exception ex)
- {
- FLog.severe(ex);
- }
}
- return tfGuildsPlugin;
+ catch (NoClassDefFoundError ex)
+ {
+ return false;
+ }
+
+ return false;
}
public boolean inGuildChat(Player player)
{
+ if (!isTFGuildsEnabled())
+ {
+ return false;
+ }
return Common.IN_GUILD_CHAT.contains(player);
}
}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java
index 02892679..9da62dee 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java
@@ -3,8 +3,11 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
import lombok.Getter;
import me.totalfreedom.totalfreedommod.FreedomService;
+import me.totalfreedom.totalfreedommod.util.FLog;
+import org.reflections.Reflections;
public class CommandLoader extends FreedomService
{
@@ -52,6 +55,26 @@ public class CommandLoader extends FreedomService
return false;
}
+ public void loadCommands()
+ {
+ Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command");
+
+ Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
+
+ for (Class extends FreedomCommand> commandClass : commandClasses)
+ {
+ try
+ {
+ FLog.debug("Loading command class " + commandClass.getSimpleName());
+ add(commandClass.newInstance());
+ }
+ catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex)
+ {
+ FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_" , ""));
+ }
+ }
+ }
+
public int getCommandAmount()
{
return commands.size();
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java
new file mode 100644
index 00000000..272960cc
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java
@@ -0,0 +1,82 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.banning.Ban;
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.util.FLog;
+import me.totalfreedom.totalfreedommod.util.FUtil;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
+@CommandParameters(description = "Bans the specified ip.", usage = "/ [reason] [-q]")
+public class Command_banip extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (args.length == 0)
+ {
+ return false;
+ }
+
+ boolean silent = false;
+
+ String reason = null;
+
+ String ip = args[0];
+
+ if (!FUtil.isValidIPv4(ip))
+ {
+ msg(ip + " is not a valid IP address", ChatColor.RED);
+ return true;
+ }
+
+ if (plugin.bm.getByIp(ip) != null)
+ {
+ msg("The IP " + ip + " is already banned", ChatColor.RED);
+ return true;
+ }
+
+ if (args[args.length - 1].equalsIgnoreCase("-q"))
+ {
+ silent = true;
+
+ if (args.length >= 2)
+ {
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
+ }
+ }
+ else if (args.length > 1)
+ {
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
+ }
+
+ // Ban player
+ Ban ban = Ban.forPlayerIp(ip, sender, null, reason);
+ plugin.bm.addBan(ban);
+
+ // Kick player and handle others on IP
+ for (Player player : server.getOnlinePlayers())
+ {
+ if (FUtil.getIp(player).equals(ip))
+ {
+ player.kickPlayer(ban.bakeKickMessage());
+ }
+
+ if (!silent)
+ {
+ // Broadcast
+ FLog.info(ChatColor.RED + sender.getName() + " - Banned the IP " + ip);
+ String message = ChatColor.RED + sender.getName() + " - Banned " + (plugin.al.isAdmin(player) ? "the IP " + ip : "an IP");
+ player.sendMessage(message);
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java
new file mode 100644
index 00000000..2c6c977d
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java
@@ -0,0 +1,68 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.banning.Ban;
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.util.FUtil;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
+@CommandParameters(description = "Bans the specified name.", usage = "/ [reason] [-q]")
+public class Command_banname extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (args.length == 0)
+ {
+ return false;
+ }
+
+ boolean silent = false;
+
+ String reason = null;
+
+ String name = args[0];;
+
+ if (plugin.bm.getByUsername(name) != null)
+ {
+ msg("The name " + name + " is already banned", ChatColor.RED);
+ return true;
+ }
+
+ if (args[args.length - 1].equalsIgnoreCase("-q"))
+ {
+ silent = true;
+
+ if (args.length >= 2)
+ {
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
+ }
+ }
+ else if (args.length > 1)
+ {
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
+ }
+
+ // Ban player
+ Ban ban = Ban.forPlayerName(name, sender, null, reason);
+ plugin.bm.addBan(ban);
+
+ if (!silent)
+ {
+ FUtil.adminAction(sender.getName(), "Banned the name " + name, true);
+ }
+
+ Player player = getPlayer(name);
+ if (player != null)
+ {
+ player.kickPlayer(ban.bakeKickMessage());
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java
index dbcac1e9..741c7c67 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java
@@ -63,9 +63,16 @@ public class Command_doom extends FreedomCommand
// Deop
player.setOp(false);
+ String reason = null;
+
+ if (args.length > 1)
+ {
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
+ }
+
// Ban player
Ban ban = Ban.forPlayer(player, sender);
- ban.setReason("&cFUCKOFF");
+ ban.setReason((reason == null ? "FUCKOFF" : reason));
for (String playerIp : plugin.pl.getData(player).getIps())
{
ban.addIp(playerIp);
@@ -88,13 +95,6 @@ public class Command_doom extends FreedomCommand
// Shoot the player in the sky
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));
- String reason = null;
-
- if (args.length > 1)
- {
- reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
- }
-
final String kickReason = (reason == null ? "FUCKOFF, and get your shit together!" : reason);
// Log doom
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java
deleted file mode 100644
index cf634396..00000000
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java
+++ /dev/null
@@ -1,188 +0,0 @@
-package me.totalfreedom.totalfreedommod.command;
-
-import java.util.ArrayList;
-import java.util.List;
-import me.totalfreedom.totalfreedommod.banning.Ban;
-import me.totalfreedom.totalfreedommod.player.PlayerData;
-import me.totalfreedom.totalfreedommod.punishments.Punishment;
-import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
-import me.totalfreedom.totalfreedommod.rank.Rank;
-import me.totalfreedom.totalfreedommod.util.FUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
-
-
-@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
-@CommandParameters(description = "Bans or unbans any player, including those offline.", usage = "/ [reason] | unban | banip | unbanip | nameban | unbanname >")
-public class Command_glist extends FreedomCommand
-{
-
- @Override
- public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
- {
- if (args.length < 2)
- {
- return false;
- }
-
- String username = null;
- final List ips = new ArrayList<>();
- boolean usingIp = false;
- String banIp = null;
- if (args[1].matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$") || args[1].matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([*])\\.([*])$"))
- {
- usingIp = true;
- banIp = args[1];
- }
- final Player player = getPlayer(args[1]);
- if (!usingIp)
- {
- if (player == null)
- {
- final PlayerData entry = plugin.pl.getData(args[1]);
-
- if (entry == null)
- {
- msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
- return true;
- }
-
- username = entry.getName();
- ips.addAll(entry.getIps());
- }
- else
- {
- final PlayerData entry = plugin.pl.getData(player);
- username = entry.getName();
- ips.addAll(entry.getIps());
- }
- }
- switch (args[0])
- {
- case "ban":
- case "gtfo":
- if (usingIp)
- {
- msg("Please specify a player, not an ip.");
- return true;
- }
- final String playerBanReason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null;
- Ban playerBan = Ban.forPlayerName(username, sender, null, playerBanReason);
- for (String ip : ips)
- {
- playerBan.addIp(ip);
- playerBan.addIp(FUtil.getFuzzyIp(ip));
- }
- FUtil.adminAction(sender.getName(), "Banning " + username, true);
- playerMsg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + StringUtils.join(ips, ", "));
-
- plugin.bm.addBan(playerBan);
-
- if (player != null)
- {
- player.kickPlayer(playerBan.bakeKickMessage());
- }
-
- plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.BAN, null));
-
- return true;
- case "unban":
- case "pardon":
- if (usingIp)
- {
- msg("Please specify a player, not an ip.");
- return true;
- }
- FUtil.adminAction(sender.getName(), "Unbanning " + username, true);
- playerMsg(sender, ChatColor.GRAY + username + " has been unbanned and IP is: " + StringUtils.join(ips, ", "));
- plugin.bm.removeBan(plugin.bm.getByUsername(username));
-
- for (String ip : ips)
- {
- Ban playerUnban = plugin.bm.getByIp(ip);
- if (playerUnban != null)
- {
- plugin.bm.removeBan(playerUnban);
- }
- playerUnban = plugin.bm.getByIp(FUtil.getFuzzyIp(ip));
- if (playerUnban != null)
- {
- plugin.bm.removeBan(playerUnban);
- }
- }
- return true;
- case "nameban":
- case "banname":
- if (usingIp)
- {
- msg("Please specify a name, not an ip.");
- return true;
- }
- final String nameBanReason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null;
- Ban nameBan = Ban.forPlayerName(username, sender, null, nameBanReason);
- FUtil.adminAction(sender.getName(), "Banning IGN: " + username, true);
- plugin.bm.addBan(nameBan);
-
- if (player != null)
- {
- player.kickPlayer(nameBan.bakeKickMessage());
- }
-
- return true;
- case "unbanname":
- case "nameunban":
- if (usingIp)
- {
- msg("Please specify a name, not an ip.");
- return true;
- }
- FUtil.adminAction(sender.getName(), "Unbanning IGN: " + username, true);
- plugin.bm.removeBan(plugin.bm.getByUsername(username));
- return true;
- case "banip":
- case "ipban":
- if (!usingIp)
- {
- msg("Please specify an IP.");
- return true;
- }
-
- final String ipBanReason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null;
- Ban ipBan = Ban.forPlayerIp(banIp, sender, null, ipBanReason);
- plugin.bm.addBan(ipBan);
- FUtil.adminAction(sender.getName(), "Banned an IP", true);
- playerMsg(sender, ChatColor.GRAY + "Banned IP: " + banIp);
- return true;
- case "unbanip":
- case "pardonip":
- if (!usingIp)
- {
- msg("Please specify an IP.");
- return true;
- }
-
- FUtil.adminAction(sender.getName(), "Unbanned an IP", true);
- playerMsg(sender, ChatColor.GRAY + "Unbanned IP: " + banIp);
- Ban ipUnban = plugin.bm.getByIp(banIp);
- if (ipUnban != null)
- {
- plugin.bm.removeBan(ipUnban);
- plugin.bm.unbanIp(banIp);
- }
- ipUnban = plugin.bm.getByIp(FUtil.getFuzzyIp(banIp));
- if (ipUnban != null)
- {
- plugin.bm.removeBan(ipUnban);
- plugin.bm.unbanIp(banIp);
- }
- return true;
- default:
- return false;
- }
- }
-}
-
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java
index 4b8edaf2..c18f503b 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java
@@ -3,7 +3,9 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@@ -11,7 +13,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
-@CommandParameters(description = "Kick the specified player.", usage = "/ [reason]", aliases = "k")
+@CommandParameters(description = "Kick the specified player.", usage = "/ [reason] [-q]")
public class Command_kick extends FreedomCommand
{
@Override
@@ -30,10 +32,24 @@ public class Command_kick extends FreedomCommand
return true;
}
+ boolean silent = false;
+
String reason = null;
- if (args.length > 1)
+ if (args[args.length - 1].equalsIgnoreCase("-q"))
{
- reason = StringUtils.join(args, " ", 1, args.length);
+ silent = true;
+ FLog.debug("silent");
+
+ if (args.length >= 2)
+ {
+ FLog.debug("set reason (silent)");
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
+ }
+ }
+ else if (args.length > 1)
+ {
+ FLog.debug("set reason");
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
}
StringBuilder builder = new StringBuilder()
@@ -43,11 +59,18 @@ public class Command_kick extends FreedomCommand
if (reason != null)
{
builder.append("\n").append(ChatColor.RED).append("Reason: ").append(ChatColor.GOLD).append(reason);
- FUtil.adminAction(sender.getName(), "Kicking " + player.getName() + " - Reason: " + reason, true);
}
- else
+
+ if (!silent)
{
- FUtil.adminAction(sender.getName(), "Kicking " + player.getName(), true);
+ if (reason != null)
+ {
+ FUtil.adminAction(sender.getName(), "Kicking " + player.getName() + " - Reason: " + reason, true);
+ }
+ else
+ {
+ FUtil.adminAction(sender.getName(), "Kicking " + player.getName(), true);
+ }
}
player.kickPlayer(builder.toString());
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java
index 41d9d809..a6510fc0 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java
@@ -47,7 +47,7 @@ public class Command_linkdiscord extends FreedomCommand
if (Discord.LINK_CODES.containsValue(data))
{
- code = Discord.getCode(data);
+ code = plugin.dc.getCode(data);
}
else
{
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java
new file mode 100644
index 00000000..4ea8e07e
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java
@@ -0,0 +1,62 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.banning.Ban;
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.util.FUtil;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
+@CommandParameters(description = "Unbans the specified ip.", usage = "/ [-q]")
+public class Command_unbanip extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (args.length == 0)
+ {
+ return false;
+ }
+
+ boolean silent = false;
+
+ String ip = args[0];
+
+ if (!FUtil.isValidIPv4(ip))
+ {
+ msg(ip + " is not a valid IP address", ChatColor.RED);
+ return true;
+ }
+
+ Ban ban = plugin.bm.getByIp(ip);
+
+ if (ban == null)
+ {
+ msg("The ip " + ip + " is not banned", ChatColor.RED);
+ return true;
+ }
+
+ if (ban.hasUsername())
+ {
+ msg("This ban is not an ip-only ban.");
+ return true;
+ }
+
+ if (args.length > 1 && args[1].equals("-q"))
+ {
+ silent = true;
+ }
+
+ plugin.bm.removeBan(ban);
+
+ if (!silent)
+ {
+ FUtil.adminAction(sender.getName(), "Unbanned the ip " + ip, true);
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java
new file mode 100644
index 00000000..f2e91b4f
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java
@@ -0,0 +1,56 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.banning.Ban;
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.util.FUtil;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
+@CommandParameters(description = "Unbans the specified name.", usage = "/ [-q]")
+public class Command_unbanname extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (args.length == 0)
+ {
+ return false;
+ }
+
+ boolean silent = false;
+
+ String name = args[0];
+
+ Ban ban = plugin.bm.getByUsername(name);
+
+ if (ban == null)
+ {
+ msg("The name " + name + " is not banned", ChatColor.RED);
+ return true;
+ }
+
+ if (ban.hasIps())
+ {
+ msg("This ban is not a name-only ban.");
+ return true;
+ }
+
+ if (args.length > 1 && args[1].equals("-q"))
+ {
+ silent = true;
+ }
+
+ plugin.bm.removeBan(ban);
+
+ if (!silent)
+ {
+ FUtil.adminAction(sender.getName(), "Unbanned the name " + name, true);
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java
index f0c188b9..51194d31 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java
@@ -131,7 +131,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
return true;
}
- if (perms.blockHostConsole() && FUtil.isFromHostConsole(sender.getName()))
+ if (perms.blockHostConsole() && FUtil.isFromHostConsole(sender.getName()) && !FUtil.inDeveloperMode())
{
msg(ChatColor.RED + "Host console is not allowed to use this command!");
return true;
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java
index 3cfe0c97..7094625e 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java
@@ -161,7 +161,8 @@ public enum ConfigEntry
VOTING_INFO(List.class, "votinginfo"),
MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"),
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),
- TOGGLE_CHAT(Boolean.class, "toggle_chat");
+ TOGGLE_CHAT(Boolean.class, "toggle_chat"),
+ DEVELOPER_MODE(Boolean.class, "developer_mode");
//
private final Class> type;
private final String configName;
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java b/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java
index bfcf6cba..c6e7be31 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java
@@ -34,7 +34,7 @@ public class MainConfig extends FreedomService
}
- public MainConfig(TotalFreedomMod plugin)
+ public MainConfig()
{
entries = new EnumMap<>(ConfigEntry.class);
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java
index 0be5c19f..b8529720 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java
@@ -26,6 +26,15 @@ public class FLog
log(Level.INFO, ex);
}
+ // Fuck spigot for not using log4j, we would of had a debug log level if they did
+ public static void debug(String message)
+ {
+ if (FUtil.inDeveloperMode())
+ {
+ log(Level.INFO, "\u001B[35m[TotalFreedomMod | DEBUG] " + message + "\u001B[0m", true);
+ }
+ }
+
// Level.WARNING:
public static void warning(String message)
{
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
index 42c141e0..ca1c768c 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
@@ -126,6 +126,11 @@ public class FUtil
return FUtil.DEVELOPERS.contains(name);
}
+ public static boolean inDeveloperMode()
+ {
+ return ConfigEntry.DEVELOPER_MODE.getBoolean();
+ }
+
public static String formatName(String name)
{
return WordUtils.capitalizeFully(name.replace("_", " "));
@@ -133,11 +138,7 @@ public class FUtil
public static String showS(int count)
{
- if (count == 1)
- {
- return "";
- }
- return "s";
+ return (count == 1 ? "" : "s");
}
public static List getPlayerList()
@@ -760,6 +761,16 @@ public class FUtil
return Color.fromRGB((int) c1values[0], (int) c1values[1], (int) c1values[2]);
}
+ public static boolean isValidIPv4(String ip)
+ {
+ if (ip.matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$")
+ || ip.matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([*])\\.([*])$"))
+ {
+ return true;
+ }
+ return false;
+ }
+
public static List createColorGradient(Color c1, Color c2, int steps)
{
double factor = 1.0 / (steps - 1.0);
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 1556ce7a..ec06bb09 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -486,3 +486,6 @@ autokick:
# Blocked Chat Codes - Use &code,&code2,&code3 (No spaces)
blocked_chatcodes: '&0,&k,&m,&n'
+
+# Enables certain things like debug logs and console bypasses
+developer_mode: false
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 7229c243..b3400b4f 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,6 +2,6 @@ name: TotalFreedomMod
main: me.totalfreedom.totalfreedommod.TotalFreedomMod
version: ${project.version}
description: Plugin for the Total Freedom server.
-softdepend: [BukkitTelnet, Essentials, LibsDisguises, WorldEdit]
+softdepend: [BukkitTelnet, Essentials, LibsDisguises, WorldEdit, WorldGuard, WorldGuardExtraFlags, TFGuilds]
authors: [Madgeek1450, Prozza]
-api-version: 1.15
\ No newline at end of file
+api-version: 1.16
\ No newline at end of file