Skip to content

Commit

Permalink
Split gcmd sub cmds out n other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
script-head committed Aug 1, 2020
1 parent 891e5c2 commit 76bb2d0
Show file tree
Hide file tree
Showing 21 changed files with 430 additions and 254 deletions.
11 changes: 9 additions & 2 deletions pom.xml
Expand Up @@ -240,9 +240,16 @@
<dependency>
<groupId>com.github.speedxx</groupId>
<artifactId>TFGuilds</artifactId>
<version>master-SNAPSHOT</version>
<version>master</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
</dependency>


</dependencies>

<build>
Expand Down Expand Up @@ -418,7 +425,7 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.17</version>
<version>3.1.1</version>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>checkstyle.xml</configLocation>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java
Expand Up @@ -2,7 +2,10 @@

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;
Expand All @@ -25,6 +28,15 @@ public void createBackups(String file)
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];
Expand Down
31 changes: 9 additions & 22 deletions src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
Expand Up @@ -181,33 +181,20 @@ public void onEnable()
FUtil.deleteFolder(new File("./_deleteme"));

fsh = new FreedomServiceHandler();
cl = new CommandLoader();

Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command");

Set<Class<? extends FreedomCommand>> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
config = new MainConfig();
config.load();

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 = new CommandLoader();
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();
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
Expand Up @@ -166,7 +166,20 @@ public String bakeKickMessage()
{
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());

Expand Down
Expand Up @@ -3,14 +3,13 @@
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()
Expand All @@ -22,31 +21,39 @@ public void onStop()
{
}

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);
}
}
Expand Up @@ -3,8 +3,11 @@
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
{
Expand Down Expand Up @@ -52,6 +55,26 @@ public boolean isAlias(String alias)
return false;
}

public void loadCommands()
{
Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command");

Set<Class<? extends FreedomCommand>> 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();
Expand Down
@@ -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 = "/<command> <ip> [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;
}
}
@@ -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 = "/<command> <name> [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;
}
}

0 comments on commit 76bb2d0

Please sign in to comment.