16 changes: 8 additions & 8 deletions src/main/java/me/totalfreedom/totalfreedommod/Pterodactyl.java
Expand Up @@ -71,7 +71,7 @@ public String createAccount(String username, String password)
}
catch (IOException | ParseException e)
{
FLog.severe(e);
FLog.fatal(e);
return null;
}

Expand All @@ -88,7 +88,7 @@ public boolean deleteAccount(String id)
}
catch (IOException e)
{
FLog.severe(e);
FLog.fatal(e);
return false;
}
}
Expand All @@ -101,7 +101,7 @@ public void addAccountToServer(String id)
JSONObject userData = getUserData(id);
if (userData == null)
{
FLog.severe("The Pterodactyl user with the ID of " + id + " was not found");
FLog.fatal("The Pterodactyl user with the ID of " + id + " was not found");
return;
}

Expand All @@ -115,7 +115,7 @@ public void addAccountToServer(String id)
}
catch (IOException e)
{
FLog.severe(e);
FLog.fatal(e);
}
}

Expand All @@ -124,7 +124,7 @@ public void removeAccountFromServer(String id)
JSONObject userData = getUserData(id);
if (userData == null)
{
FLog.severe("The Pterodactyl user with the ID of " + id + " was not found");
FLog.fatal("The Pterodactyl user with the ID of " + id + " was not found");
return;
}

Expand All @@ -136,7 +136,7 @@ public void removeAccountFromServer(String id)
}
catch (IOException e)
{
FLog.severe(e);
FLog.fatal(e);
}
}

Expand All @@ -152,7 +152,7 @@ public JSONObject getUserData(String id)
}
catch (IOException | ParseException e)
{
FLog.severe(e);
FLog.fatal(e);
return null;
}

Expand All @@ -173,7 +173,7 @@ public void setPassword(String id, String password)
}
catch (IOException e)
{
FLog.severe(e);
FLog.fatal(e);
}
}

Expand Down
32 changes: 14 additions & 18 deletions src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
Expand Up @@ -13,7 +13,6 @@
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
import me.totalfreedom.totalfreedommod.blocking.PVPBlocker;
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
import me.totalfreedom.totalfreedommod.blocking.SignBlocker;
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
import me.totalfreedom.totalfreedommod.bridge.*;
import me.totalfreedom.totalfreedommod.caging.Cager;
Expand Down Expand Up @@ -42,9 +41,7 @@
import me.totalfreedom.totalfreedommod.world.WorldManager;
import me.totalfreedom.totalfreedommod.world.WorldRestrictions;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -111,7 +108,6 @@ public class TotalFreedomMod extends JavaPlugin
public Trailer tr;
public HTTPDaemon hd;
public WorldRestrictions wr;
public SignBlocker snp;
public EntityWiper ew;
public VanishHandler vh;
public Pterodactyl ptero;
Expand All @@ -125,21 +121,25 @@ public class TotalFreedomMod extends JavaPlugin
public WorldEditBridge web;
public WorldGuardBridge wgb;

/**
* Returns an instance of the TotalFreedomMod if present.
* @return TotalFreedomMod
*/
public static TotalFreedomMod getPlugin()
{
return plugin;
}

/**
* Returns an instance of the TotalFreedomMod if present.
* @deprecated This method is no longer used internally, but for compatibility reasons will not be removed.
* @return TotalFreedomMod
* @see TotalFreedomMod#getPlugin() for what to use instead
*/
@Deprecated
public static TotalFreedomMod plugin()
{
for (Plugin plugin : Bukkit.getPluginManager().getPlugins())
{
if (plugin.getName().equalsIgnoreCase(pluginName))
{
return (TotalFreedomMod)plugin;
}
}
return null;
return getPlugin();
}

@Override
Expand All @@ -149,9 +149,6 @@ public void onLoad()
TotalFreedomMod.pluginName = plugin.getDescription().getName();
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();

FLog.setPluginLogger(plugin.getLogger());
FLog.setServerLogger(getServer().getLogger());

build.load(plugin);
}

Expand Down Expand Up @@ -251,8 +248,8 @@ public void load(TotalFreedomMod plugin)
}
catch (Exception ex)
{
FLog.severe("Could not load build properties! Did you compile with NetBeans/Maven?");
FLog.severe(ex);
FLog.fatal("Could not load build properties! Did you compile with NetBeans/Maven?");
FLog.fatal(ex);
}
}

Expand Down Expand Up @@ -305,7 +302,6 @@ private void initServices()
im = new IndefiniteBanList();
pem = new PermissionManager();
gr = new GameRuleHandler();
snp = new SignBlocker();
ew = new EntityWiper();
vh = new VanishHandler();
ptero = new Pterodactyl();
Expand Down
Expand Up @@ -50,7 +50,7 @@ public Admin(ResultSet resultSet)
}
catch (SQLException e)
{
FLog.severe("Failed to load admin: " + e.getMessage());
FLog.fatal("Failed to load admin: " + e.getMessage());
}
}

Expand Down
Expand Up @@ -12,7 +12,6 @@
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -59,15 +58,15 @@ public void load()
}
catch (Exception ex)
{
FLog.warning("Failed to load admin entry");
FLog.warning(ex);
FLog.warn("Failed to load admin entry");
FLog.warn(ex);
}
}
}
}
catch (SQLException e)
{
FLog.severe("Failed to load admin list: " + e.getMessage());
FLog.fatal("Failed to load admin list: " + e.getMessage());
}

updateTables();
Expand Down Expand Up @@ -224,7 +223,7 @@ public boolean addAdmin(Admin admin)
{
if (!admin.isValid())
{
FLog.warning("Could not add admin: " + admin.getName() + ". Admin is missing details!");
FLog.warn("Could not add admin: " + admin.getName() + ". Admin is missing details!");
return false;
}

Expand Down Expand Up @@ -311,7 +310,7 @@ public void save(Admin admin)
}
catch (SQLException e)
{
FLog.severe("Failed to save admin: " + e.getMessage());
FLog.fatal("Failed to save admin: " + e.getMessage());
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
Expand Up @@ -121,17 +121,6 @@ public static Ban forPlayer(Player player, CommandSender by, Date expiry, String
reason);
}

public static Ban forPlayerFuzzy(Player player, CommandSender by, Date expiry, String reason)
{
return new Ban(player.getName(),
player.getUniqueId(),
FUtil.getFuzzyIp(FUtil.getIp(player)),
by.getName(),
Date.from(Instant.now()),
expiry,
reason);
}

public static SimpleDateFormat getDateFormat()
{
return DATE_FORMAT;
Expand Down
Expand Up @@ -63,7 +63,7 @@ public void onStart()
}
catch (SQLException e)
{
FLog.severe("Failed to load ban list: " + e.getMessage());
FLog.fatal("Failed to load ban list: " + e.getMessage());
}

// Remove expired bans, repopulate ipBans and nameBans,
Expand Down Expand Up @@ -105,28 +105,6 @@ public Ban getByIp(String ip)
return directBan;
}

// Match fuzzy IP
for (Ban loopBan : ipBans.values())
{
if (loopBan.isExpired())
{
continue;
}

for (String loopIp : loopBan.getIps())
{
if (!loopIp.contains("*"))
{
continue;
}

if (FUtil.fuzzyIpMatch(ip, loopIp, 4))
{
return loopBan;
}
}
}

return null;
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ public void loadFrom(ConfigurationSection cs)
}
catch (IllegalArgumentException e)
{
FLog.warning("Failed to load indefinite banned UUID for " + this.username + ". Make sure the UUID is in the correct format with dashes.");
FLog.warn("Failed to load indefinite banned UUID for " + this.username + ". Make sure the UUID is in the correct format with dashes.");
}
this.ips.clear();
this.ips.addAll(cs.getStringList("ips"));
Expand Down
Expand Up @@ -49,7 +49,7 @@ public void onStart()
{
if (!config.isConfigurationSection(name))
{
FLog.warning("Could not load indefinite ban for " + name + ": Invalid format!");
FLog.warn("Could not load indefinite ban for " + name + ": Invalid format!");
continue;
}

Expand All @@ -60,7 +60,7 @@ public void onStart()

if (!indefBan.isValid())
{
FLog.warning("Not adding indefinite ban for " + name + ": Missing information.");
FLog.warn("Not adding indefinite ban for " + name + ": Missing information.");
continue;
}

Expand Down
Expand Up @@ -53,10 +53,12 @@ public class EventBlocker extends FreedomService

// TODO: Revert back to old redstone block system when (or if) it is fixed in Bukkit, Spigot or Paper.
private final ArrayList<Material> redstoneBlocks = new ArrayList<>(Arrays.asList(Material.REDSTONE, Material.DISPENSER, Material.DROPPER, Material.REDSTONE_LAMP));
private int max_death_message_size = 96;

@Override
public void onStart()
{
max_death_message_size = ConfigEntry.DEATH_MESSAGES_MAX.getInteger();
}

@Override
Expand Down Expand Up @@ -127,7 +129,7 @@ public void onEntityCombust(EntityCombustEvent event)
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event)
{
if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
if (ConfigEntry.ENTITY_WIPER_ENABLED.getBoolean())
{
event.setDroppedExp(0);
}
Expand Down Expand Up @@ -164,7 +166,7 @@ public void onPlayerDropItem(PlayerDropItemEvent event)
event.setCancelled(true);
}

if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
if (!ConfigEntry.ENTITY_WIPER_ENABLED.getBoolean())
{
return;
}
Expand Down Expand Up @@ -263,6 +265,12 @@ public void onBlockDispense(BlockDispenseEvent event)
public void onPlayerDeath(PlayerDeathEvent event)
{
FUtil.fixCommandVoid(event.getEntity());
event.setDeathMessage(event.getDeathMessage());

// Death messages have the potential of being used to spam the chat. This fixes that.
if (ConfigEntry.DEATH_MESSAGES_LIMIT.getBoolean())
{
String deathMessage = event.getDeathMessage();
event.setDeathMessage(deathMessage.substring(0, Math.min(deathMessage.length(), max_death_message_size)));
}
}
}

This file was deleted.

Expand Up @@ -2,11 +2,12 @@

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
Expand All @@ -16,11 +17,9 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.SimplePluginManager;

public class CommandBlocker extends FreedomService
{
Expand All @@ -30,24 +29,6 @@ public class CommandBlocker extends FreedomService
private final Map<String, CommandBlockerEntry> entryList = Maps.newHashMap();
private final List<String> unknownCommands = Lists.newArrayList();

public static CommandMap getCommandMap()
{
try
{
SimplePluginManager simplePluginManager = (SimplePluginManager)Bukkit.getServer().getPluginManager();

Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap");
commandMapField.setAccessible(true);

return (SimpleCommandMap)commandMapField.get(simplePluginManager);
}
catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e)
{
FLog.severe("Failed to get command map field (" + e.getMessage() + ")");
}
return null;
}

@Override
public void onStart()
{
Expand All @@ -65,7 +46,7 @@ public void load()
entryList.clear();
unknownCommands.clear();

final CommandMap commandMap = getCommandMap();
final CommandMap commandMap = server.getCommandMap();

@SuppressWarnings("unchecked")
List<String> blockedCommands = (List<String>)ConfigEntry.BLOCKED_COMMANDS.getList();
Expand All @@ -74,7 +55,7 @@ public void load()
final String[] parts = rawEntry.split(":");
if (parts.length < 3 || parts.length > 4)
{
FLog.warning("Invalid command blocker entry: " + rawEntry);
FLog.warn("Invalid command blocker entry: " + rawEntry);
continue;
}

Expand All @@ -85,7 +66,7 @@ public void load()

if (rank == null || action == null || commandName.isEmpty())
{
FLog.warning("Invalid command blocker entry: " + rawEntry);
FLog.warn("Invalid command blocker entry: " + rawEntry);
continue;
}

Expand All @@ -97,7 +78,6 @@ public void load()
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
}

assert commandMap != null;
final Command command = commandMap.getCommand(commandName);

// Obtain command from alias
Expand All @@ -112,7 +92,7 @@ public void load()

if (entryList.containsKey(commandName))
{
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
FLog.warn("Not blocking: /" + commandName + " - Duplicate entry exists!");
continue;
}

Expand Down Expand Up @@ -142,6 +122,12 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
}
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerClickSign(PlayerSignCommandPreprocessEvent event)
{
event.setCancelled(true);
}

public boolean isCommandBlocked(String command, CommandSender sender)
{
return isCommandBlocked(command, sender, false);
Expand Down
Expand Up @@ -117,7 +117,7 @@ public BukkitTelnet getBukkitTelnetPlugin()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public void killTelnetSessions(final String name)
}
catch (Exception ex)
{
FLog.severe("Error removing single telnet session: " + ex.getMessage());
FLog.fatal("Error removing single telnet session: " + ex.getMessage());
}
}

Expand All @@ -177,7 +177,7 @@ public void killTelnetSessions(final String name)
}
catch (Exception ex)
{
FLog.severe("Error removing telnet sessions: " + ex.getMessage());
FLog.fatal("Error removing telnet sessions: " + ex.getMessage());
}
}
}
Expand Up @@ -89,7 +89,7 @@ public CoreProtect getCoreProtect()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return coreProtect;
}
Expand All @@ -112,7 +112,7 @@ public CoreProtectAPI getCoreProtectAPI()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down
Expand Up @@ -6,7 +6,6 @@
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -50,7 +49,7 @@ public Essentials getEssentialsPlugin()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}
return essentialsPlugin;
Expand All @@ -68,7 +67,7 @@ public User getEssentialsUser(String username)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand All @@ -86,7 +85,7 @@ public void setNickname(String username, String nickname)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -102,7 +101,7 @@ public String getNickname(String username)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand All @@ -114,13 +113,12 @@ public long getLastActivity(String username)
User user = getEssentialsUser(username);
if (user != null)
{
Long l = FUtil.getField(user, "lastActivity");
return (l != null) ? l : 0L;
return user.getLastLogin();
}
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return 0L;
}
Expand All @@ -137,7 +135,7 @@ public void setVanished(String username, boolean vanished)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down
Expand Up @@ -39,7 +39,7 @@ public LibsDisguises getLibsDisguisesPlugin()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down Expand Up @@ -71,7 +71,7 @@ public void undisguiseAll(boolean admin)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down
@@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod.bridge;

import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.util.FLog;
Expand Down Expand Up @@ -40,7 +39,7 @@ public static WorldEditPlugin getWorldEditPlugin()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -59,7 +58,7 @@ public void setLimit(Player player, int limit)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}

}
Expand Down Expand Up @@ -102,7 +101,7 @@ private static LocalSession getPlayerSession(Player player)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
return null;
}
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ public void loadCommands()
// If a plugin required by the command isn't present, the command is ignored
if (!server.getPluginManager().isPluginEnabled(pl))
{
FLog.warning("Ignoring command with unmet dependencies (" + pl + "):" + " /" + cmdName);
FLog.warn("Ignoring command with unmet dependencies (" + pl + "):" + " /" + cmdName);
continue registerer;
}
}
Expand All @@ -100,7 +100,7 @@ public void loadCommands()
}
catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex)
{
FLog.warning("Failed to register command: /" + cmdName);
FLog.warn("Failed to register command: /" + cmdName);
}
}

Expand Down
@@ -1,5 +1,7 @@
package me.totalfreedom.totalfreedommod.command;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.earth2me.essentials.User;
Expand Down Expand Up @@ -63,6 +65,8 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
final String ip;

final Player player = getPlayer(args[0]);

// Player is not online
if (player == null)
{
// Gets the IP using Essentials data if available
Expand Down Expand Up @@ -116,10 +120,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
}
}
}
else
{
msg("Banned " + player.getName() + " quietly.");
}

// Kill player
player.setHealth(0.0);
}
Expand All @@ -130,11 +131,6 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
plugin.cpb.rollback(username);
}

if (player != null && !silent)
{
FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
}

// Ban player
Ban ban;
if (player != null)
Expand All @@ -145,41 +141,48 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
{
ban = Ban.forPlayerName(username, sender, null, reason);
}
ban.addIp(ip);

ban.addIp(ip);
plugin.bm.addBan(ban);


if (!silent)
{
// Broadcast
if (player != null)
{
FUtil.bcastMsg(username + " has been a VERY naughty, naughty boy.", ChatColor.RED);
}

final StringBuilder bcast = new StringBuilder()
.append("Banning: ")
.append(username);
if (reason != null)
{
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
}
msg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + ip);
FUtil.adminAction(sender.getName(), bcast.toString(), true);
}

List<Player> collat = new ArrayList<>();

// Kick player and handle others on IP
if (player != null)
{
player.kickPlayer(ban.bakeKickMessage());
for (Player p : Bukkit.getOnlinePlayers())
{
if (FUtil.getIp(p).equals(FUtil.getIp(player)))
{
p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned.");
}
}
Bukkit.getOnlinePlayers().stream().filter((p) -> FUtil.getIp(p).trim().equals(FUtil.getIp(player).trim()) && plugin.al.isAdmin(p)).forEach((p) -> {
p.kickPlayer(ChatColor.RED + "You've been kicked because someone with your IP address has been banned.");
collat.add(p);
});
}

msg(username + " has been " + (silent ? "quietly " : "") + "banned, their IP is: " + ip);
if (collat.size() > 0)
{
msg(collat.size() + " additional player" + (collat.size() > 1 ? "s were" : " was") + " kicked as they were on a matching IP address.");
}

// Log ban
plugin.pul.logPunishment(new Punishment(username, ip, sender.getName(), PunishmentType.BAN, reason));

return true;
}
}
Expand Up @@ -64,7 +64,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -27,7 +27,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -23,8 +23,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{

msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -59,7 +59,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -62,7 +62,7 @@ public void run()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}
}.runTaskAsynchronously(plugin);
Expand Down
Expand Up @@ -24,7 +24,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
targetPlayer = getPlayer(args[1]);
if (targetPlayer == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -80,7 +80,7 @@ public void run()
}
catch (FileNotFoundException ex)
{
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
FSync.playerMsg(sender, PLAYER_NOT_FOUND);
}
catch (Exception ex)
{
Expand Down
Expand Up @@ -55,7 +55,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
player.setOp(false);
if (player.isOnline())
{
msg(Objects.requireNonNull(player.getPlayer()), FreedomCommand.YOU_ARE_NOT_OP);
msg(Objects.requireNonNull(player.getPlayer()), YOU_ARE_NOT_OP);
}
}
return true;
Expand Down
Expand Up @@ -30,7 +30,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -86,7 +86,7 @@ else if (args[0].equalsIgnoreCase("clearall"))

if (target == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -118,7 +118,7 @@ else if (args[0].equalsIgnoreCase("banners") || args[0].equalsIgnoreCase("banner
targetPlayer = getPlayer(args[2]);
if (targetPlayer == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}
}
Expand Down
Expand Up @@ -165,7 +165,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand All @@ -176,11 +176,10 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
}

// Find the old admin entry
String name = player.getName();
Admin admin = null;
for (Admin loopAdmin : plugin.al.getAllAdmins())
{
if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player)))
if (loopAdmin.getUuid().equals(player.getUniqueId()))
{
admin = loopAdmin;
break;
Expand Down
Expand Up @@ -33,7 +33,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
return true;
}

if (x > 29999998 || x < -29999998 || y > 29999998 || y < -29999998 || z > 29999998 || z < -29999998)
if (Math.abs(x) > 29999998 || Math.abs(y) > 29999998 || Math.abs(z) > 29999998)
{
msg("Coordinates cannot be larger than 29999998 or smaller than -29999998 blocks.");
return true;
Expand Down
Expand Up @@ -128,7 +128,7 @@ else if (args.length >= 2)

if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
msg(PLAYER_NOT_FOUND);
return true;
}

Expand Down
Expand Up @@ -22,7 +22,7 @@ public class Command_toggle extends FreedomCommand
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke [range] [count]",
"explosives [radius]", "unsafeenchs", "bells", "armorstands", "structureblocks", "jigsaws", "grindstones",
"jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", "mp44",
"landmines", "tossmob", "gravity", "redstone");
"landmines", "tossmob", "gravity", "redstone", "chat");

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
Expand Down Expand Up @@ -104,7 +104,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin

case "entitywipe":
{
toggle("Automatic entity wiping is", ConfigEntry.AUTO_ENTITY_WIPE);
toggle("Automatic entity wiping is", ConfigEntry.ENTITY_WIPER_ENABLED);
break;
}

Expand Down Expand Up @@ -305,6 +305,13 @@ public void run()
break;
}

case "chat":
{
FUtil.adminAction(sender.getName(), (!ConfigEntry.TOGGLE_CHAT.getBoolean() ? "Enabling" : "Disabling") + " global chat", true);
toggle("The chat is", ConfigEntry.TOGGLE_CHAT);
break;
}

default:
{
msg("Available toggles: ");
Expand Down Expand Up @@ -337,7 +344,7 @@ public List<String> getTabCompleteOptions(CommandSender sender, Command command,
"waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk",
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs",
"bells", "armorstands", "structureblocks", "jigsaws", "grindstones", "jukeboxes", "spawners", "4chan", "beehives",
"respawnanchors", "autotp", "autoclear", "minecarts", "mp44", "landmines", "tossmob", "gravity", "redstone");
"respawnanchors", "autotp", "autoclear", "minecarts", "mp44", "landmines", "tossmob", "gravity", "redstone", "chat");
}
return Collections.emptyList();
}
Expand Down

This file was deleted.

Expand Up @@ -39,8 +39,8 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
plugin.fsh.startServices();

final String message = String.format("%s v%s reloaded.",
TotalFreedomMod.pluginName,
TotalFreedomMod.pluginVersion);
plugin.getName(),
plugin.getDescription().getVersion());

msg(message);
FLog.info(message);
Expand Down
@@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod.command;

import com.google.common.collect.Lists;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -13,19 +12,15 @@
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;

Expand All @@ -34,13 +29,12 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
public static final String COMMAND_PREFIX = "Command_";
public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!";
public static final String PLAYER_NOT_FOUND = ChatColor.RED + "Player not found!";
public static final String ONLY_CONSOLE = ChatColor.RED + "Only console senders may execute this command!";
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<CommandSender, FreedomCommand> COOLDOWN_TIMERS = new HashMap<>();
private static CommandMap commandMap;
protected final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
protected final Server server = plugin.getServer();
private final String name;
Expand Down Expand Up @@ -69,34 +63,21 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
this.cooldown = perms.cooldown();
}

public static CommandMap getCommandMap()
{
if (commandMap == null)
{
try
{
final Field f = Bukkit.getServer().getPluginManager().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
commandMap = (CommandMap)f.get(Bukkit.getServer().getPluginManager());
}
catch (Exception e)
{
e.printStackTrace();
}
}
return commandMap;
}

public static FreedomCommand getFrom(Command command)
{
try
{
return (FreedomCommand)(((PluginCommand)command).getExecutor());
if (command instanceof FCommand)
{
return ((FCommand) command).getExecutor();
}
}
catch (Exception ex)
{
return null;
FLog.fatal(ex);
}

return null;
}

public static String getCommandPrefix()
Expand All @@ -119,7 +100,7 @@ public void register()
{
cmd.setUsage(this.usage);
}
getCommandMap().register("totalfreedommod", cmd);
Bukkit.getCommandMap().register("totalfreedommod", cmd);
cmd.setExecutor(this);
}

Expand Down Expand Up @@ -316,7 +297,7 @@ public CommandPermissions getPerms()
return perms;
}

private final class FCommand extends Command
public final class FCommand extends Command implements PluginIdentifiableCommand
{
private FreedomCommand cmd = null;

Expand All @@ -325,6 +306,11 @@ private FCommand(String command)
super(command);
}

public final FreedomCommand getExecutor()
{
return cmd;
}

public void setExecutor(FreedomCommand cmd)
{
this.cmd = cmd;
Expand Down Expand Up @@ -427,5 +413,11 @@ public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String a
}
return new ArrayList<>();
}

@Override
public @NotNull Plugin getPlugin()
{
return plugin;
}
}
}
Expand Up @@ -155,6 +155,8 @@ public enum ConfigEntry
BLOCKED_COMMANDS(List.class, "blocked_commands.global"),
MUTED_BLOCKED_COMMANDS(List.class, "blocked_commands.muted"),
WILDCARD_BLOCKED_COMMANDS(List.class, "blocked_commands.wildcard"),
DEATH_MESSAGES_LIMIT(Boolean.class, "death_messages.limit"),
DEATH_MESSAGES_MAX(Integer.class, "death_messages.max"),
FORBIDDEN_WORDS(List.class, "forbidden_words"),
HOST_SENDER_NAMES(List.class, "host_sender_names"),
FAMOUS_PLAYERS(List.class, "famous_players"),
Expand All @@ -164,7 +166,12 @@ public enum ConfigEntry
MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"),
FIRST_JOIN_INFO(List.class, "first_join_info.text"),
FIRST_JOIN_INFO_ENABLED(Boolean.class, "first_join_info.enabled"),
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),
//
ENTITY_WIPER_ENABLED(Boolean.class, "entity_wiper.enabled"),
ENTITY_WIPER_DELAY(Integer.class, "entity_wiper.delay"),
ENTITY_WIPER_INTERVAL(Integer.class, "entity_wiper.interval"),
ENTITY_WIPER_BLACKLIST(List.class, "entity_wiper.blacklist"),
//
TOGGLE_CHAT(Boolean.class, "toggle_chat"),
DEVELOPER_MODE(Boolean.class, "developer_mode"),
ANTISPAM_MINUTES(Integer.class, "antispam_minutes");
Expand Down
Expand Up @@ -42,7 +42,7 @@ public MainConfig()
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}

copyDefaultConfig(getConfigFile());
Expand All @@ -51,7 +51,7 @@ public MainConfig()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}

defaults = tempDefaults;
Expand Down Expand Up @@ -91,19 +91,19 @@ public void load()
}
else
{
FLog.warning("Value for " + entry.getConfigName() + " is of type "
FLog.warn("Value for " + entry.getConfigName() + " is of type "
+ value.getClass().getSimpleName() + ". Needs to be " + entry.getType().getSimpleName() + ". Using default value.");
}
}
else
{
FLog.warning("Missing configuration entry " + entry.getConfigName() + ". Using default value.");
FLog.warn("Missing configuration entry " + entry.getConfigName() + ". Using default value.");
}
}
}
catch (IOException | InvalidConfigurationException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -120,7 +120,7 @@ public String getString(ConfigEntry entry)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand All @@ -133,7 +133,7 @@ public void setString(ConfigEntry entry, String value)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -145,7 +145,7 @@ public Double getDouble(ConfigEntry entry)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand All @@ -158,7 +158,7 @@ public void setDouble(ConfigEntry entry, Double value)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -170,7 +170,7 @@ public Boolean getBoolean(ConfigEntry entry)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand All @@ -183,7 +183,7 @@ public void setBoolean(ConfigEntry entry, Boolean value)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -195,7 +195,7 @@ public Integer getInteger(ConfigEntry entry)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand All @@ -208,7 +208,7 @@ public void setInteger(ConfigEntry entry, Integer value)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -220,7 +220,7 @@ public List<?> getList(ConfigEntry entry)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand Down Expand Up @@ -269,7 +269,7 @@ private void copyDefaultConfig(File targetFile)
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ private ConfigDefaults(InputStream defaultConfig)
}
catch (IOException | InvalidConfigurationException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java
Expand Up @@ -83,7 +83,7 @@ public static boolean syncRoles(Admin admin, String discordID)
Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
if (server == null)
{
FLog.severe("The Discord server ID specified is invalid, or the bot is not on the server.");
FLog.fatal("The Discord server ID specified is invalid, or the bot is not on the server.");
return false;
}

Expand All @@ -96,14 +96,14 @@ public static boolean syncRoles(Admin admin, String discordID)
Role adminRole = server.getRoleById(ConfigEntry.DISCORD_NEW_ADMIN_ROLE_ID.getString());
if (adminRole == null)
{
FLog.severe("The specified Admin role does not exist!");
FLog.fatal("The specified Admin role does not exist!");
return false;
}

Role senioradminRole = server.getRoleById(ConfigEntry.DISCORD_SENIOR_ADMIN_ROLE_ID.getString());
if (senioradminRole == null)
{
FLog.severe("The specified Senior Admin role does not exist!");
FLog.fatal("The specified Senior Admin role does not exist!");
return false;
}

Expand Down Expand Up @@ -189,18 +189,18 @@ public void onReady(@NotNull ReadyEvent event)
}
catch (LoginException e)
{
FLog.warning("An invalid token for the Discord integration bot was provided, the bot will not enable.");
FLog.warn("An invalid token for the Discord integration bot was provided, the bot will not enable.");
enabled = false;
}
catch (IllegalArgumentException e)
{
FLog.warning("Discord integration bot failed to start.");
FLog.warn("Discord integration bot failed to start.");
enabled = false;
}
catch (NoClassDefFoundError e)
{
FLog.warning("The JDA plugin is not installed, therefore the Discord bot cannot start.");
FLog.warning("To resolve this error, please download the latest JDA from: https://github.com/TFPatches/Minecraft-JDA/releases");
FLog.warn("The JDA plugin is not installed, therefore the Discord bot cannot start.");
FLog.warn("To resolve this error, please download the latest JDA from: https://github.com/TFPatches/Minecraft-JDA/releases");
enabled = false;
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public User getUser(String id)
Guild guild = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
if (guild == null)
{
FLog.severe("Either the bot is not in the Discord server or it doesn't exist. Check the server ID.");
FLog.fatal("Either the bot is not in the Discord server or it doesn't exist. Check the server ID.");
return null;
}

Expand Down Expand Up @@ -413,21 +413,21 @@ public void onPlayerReport(PlayerReportEvent event)

if (ConfigEntry.DISCORD_SERVER_ID.getString().isEmpty())
{
FLog.severe("No Discord server ID was specified in the config, but there is a report channel ID.");
FLog.fatal("No Discord server ID was specified in the config, but there is a report channel ID.");
return;
}

Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
if (server == null)
{
FLog.severe("The Discord server ID specified is invalid, or the bot is not on the server.");
FLog.fatal("The Discord server ID specified is invalid, or the bot is not on the server.");
return;
}

TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString());
if (channel == null)
{
FLog.severe("The report channel ID specified in the config is invalid.");
FLog.fatal("The report channel ID specified in the config is invalid.");
return;
}

Expand Down
@@ -1,6 +1,8 @@
package me.totalfreedom.totalfreedommod.freeze;

import java.util.Objects;

import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.event.freeze.FreezeEvent;
import me.totalfreedom.totalfreedommod.event.freeze.PlayerFreezeEvent;
import me.totalfreedom.totalfreedommod.event.freeze.PlayerUnfreezeEvent;
Expand All @@ -13,7 +15,6 @@
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import static me.totalfreedom.totalfreedommod.TotalFreedomMod.plugin;
import static me.totalfreedom.totalfreedommod.player.FPlayer.AUTO_PURGE_TICKS;

public class FreezeData
Expand Down Expand Up @@ -77,7 +78,7 @@ public void run()
setFrozen(false);
}

}.runTaskLater(Objects.requireNonNull(plugin()), AUTO_PURGE_TICKS);
}.runTaskLater(Objects.requireNonNull(TotalFreedomMod.getPlugin()), AUTO_PURGE_TICKS);
}

public Location getLocation()
Expand Down
Expand Up @@ -11,9 +11,16 @@ public static String paragraph(String data)
return "<p>" + escapeHtml4(data) + "</p>\r\n";
}

public static String heading(String data, String id, int level)
{
return "<h" + level + (id != null ? " id=\"" + id + "\"" : "") + ">" + escapeHtml4(data)
+ "</h" + level + ">\r\n";
}

public static String heading(String data, int level)
{
return "<h" + level + ">" + escapeHtml4(data) + "</h" + level + ">\r\n";
//return "<h" + level + ">" + escapeHtml4(data) + "</h" + level + ">\r\n";
return heading(data, null, level);
}

public static <K, V> String list(Map<K, V> map)
Expand Down
Expand Up @@ -70,7 +70,7 @@ public static Response serveFileBasic(File file)
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}
return response;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void onStart()
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public Response serve(HTTPSession session)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getStackTrace(ex));
}
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
return null;
}
}
Expand All @@ -60,7 +60,7 @@ public NanoHTTPD.Response execute(final NanoHTTPD.HTTPSession session)
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand Down
Expand Up @@ -220,7 +220,7 @@ public void start() throws IOException
// to break the "keep alive" loop above.
if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage())))
{
FLog.severe(e);
FLog.fatal(e);
}
}
finally
Expand Down Expand Up @@ -259,7 +259,7 @@ public void stop()
}
catch (Exception e)
{
FLog.severe(e);
FLog.fatal(e);
}
}

Expand Down Expand Up @@ -1473,7 +1473,7 @@ private String saveTmpFile(ByteBuffer b, int offset, int len)
}
catch (Exception e)
{ // Catch exception if any
FLog.severe(e);
FLog.fatal(e);
}
finally
{
Expand All @@ -1492,7 +1492,7 @@ private RandomAccessFile getTmpBucket()
}
catch (Exception e)
{
FLog.severe(e);
FLog.fatal(e);
}
return null;
}
Expand Down
Expand Up @@ -75,7 +75,7 @@ protected final Map<String, String> getFiles()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}

return files;
Expand Down
@@ -1,72 +1,83 @@
package me.totalfreedom.totalfreedommod.httpd.module;

import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.command.SimpleCommandMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.heading;
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;

public class Module_help extends HTTPDModule
{

public Module_help(NanoHTTPD.HTTPSession session)
{
super(session);
}

private static String buildDescription(Command command)
private static String buildDescription(@NotNull Command command)
{
return buildDescription(command.getName(), command.getDescription(), command.getUsage(), StringUtils.join(command.getAliases(), ", "));
}

private static String buildDescription(@NotNull FreedomCommand command)
{
return buildDescription(command.getName(), command.getDescription(), command.getUsage(), command.getAliases());
}

private static String buildDescription(@NotNull String name, @Nullable String description, @NotNull String usage, @NotNull String aliases)
{
StringBuilder sb = new StringBuilder();

sb.append(
"<li><span class=\"commandName\">{$CMD_NAME}</span> - Usage: <span class=\"commandUsage\">{$CMD_USAGE}</span>"
.replace("{$CMD_NAME}", escapeHtml4(command.getName().trim()))
.replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim())));
.replace("{$CMD_NAME}", escapeHtml4(name.trim()))
.replace("{$CMD_USAGE}", escapeHtml4(usage.trim())));

if (!command.getAliases().isEmpty())
if (!aliases.isEmpty())
{
sb.append(
" - Aliases: <span class=\"commandAliases\">{$CMD_ALIASES}</span>"
.replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", "))));
.replace("{$CMD_ALIASES}", escapeHtml4(aliases.trim())));
}

sb.append(
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
.replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim())));
if (description != null)
{
sb.append(
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
.replace("{$CMD_DESC}", escapeHtml4(description.trim())));
}

return sb.toString();
}

@Override
public String getBody()
{
final CommandMap map = FreedomCommand.getCommandMap();
if (!(map instanceof SimpleCommandMap))
{
return paragraph("Error loading commands.");
}
final CommandMap map = Bukkit.getCommandMap();

final StringBuilder responseBody = new StringBuilder()
.append(heading("Command Help", 1))
.append(paragraph(
"This page is an automatically generated listing of all plugin commands that are currently live on the server. "
+ "Please note that it does not include vanilla server commands."));

final Collection<Command> knownCommands = ((SimpleCommandMap)map).getCommands();
final Collection<Command> knownCommands = map.getKnownCommands().values();
final Map<String, List<Command>> commandsByPlugin = new HashMap<>();

for (Command command : knownCommands)
Expand All @@ -79,34 +90,47 @@ public String getBody()

List<Command> pluginCommands = commandsByPlugin.computeIfAbsent(pluginName, k -> Lists.newArrayList());

pluginCommands.add(command);
if (!pluginCommands.contains(command))
{
pluginCommands.add(command);
}
}

final CommandComparator comparator = new CommandComparator();

// For every plugin...
for (Map.Entry<String, List<Command>> entry : commandsByPlugin.entrySet())
{
final String pluginName = entry.getKey();
final List<Command> commands = entry.getValue();

commands.sort(new CommandComparator());
// Sort them alphabetically
commands.sort(comparator);

responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
responseBody.append(heading(pluginName, pluginName, 2)).append("<ul>\r\n");

Displayable lastTfmCommandLevel = null;
for (Command command : commands)
if (!plugin.getName().equals(pluginName))
{
if (!TotalFreedomMod.pluginName.equals(pluginName))
{
responseBody.append(buildDescription(command));
continue;
}

Displayable tfmCommandLevel = Objects.requireNonNull(FreedomCommand.getFrom(command)).getPerms().level();
if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel)
{
responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getName(), 3)).append("<ul>\r\n");
}
lastTfmCommandLevel = tfmCommandLevel;
responseBody.append(buildDescription(command));
commands.forEach((command) -> responseBody.append(buildDescription(command)));
}
else
{
Map<Rank, List<FreedomCommand>> freedomCommands = new HashMap<>();

// Filters out non-TFM commands
commands.stream().filter((cmd) -> cmd instanceof FreedomCommand.FCommand).forEach((tfmCmd) -> {
Rank rank = FreedomCommand.getFrom(tfmCmd).getLevel();
if (!freedomCommands.containsKey(rank))
freedomCommands.put(rank, new ArrayList<>());
freedomCommands.get(rank).add(FreedomCommand.getFrom(tfmCmd));
});

// Finally dumps them to HTML
Arrays.stream(Rank.values()).filter(freedomCommands::containsKey)
.sorted(comparator::compare).forEach((rank -> {
responseBody.append("</ul>\r\n").append(heading(rank.getName(), 3)).append("<ul>\r\n");
freedomCommands.get(rank).stream().sorted(comparator::compare).forEach((command) -> responseBody.append(buildDescription(command)));
}));
}

responseBody.append("</ul>\r\n");
Expand All @@ -118,7 +142,7 @@ public String getBody()
@Override
public String getTitle()
{
return "TotalFreedomMod :: Command Help";
return plugin.getName() + " :: Command Help";
}

@Override
Expand All @@ -129,23 +153,23 @@ public String getStyle()

public static class CommandComparator implements Comparator<Command>
{

@Override
public int compare(Command a, Command b)
{
FreedomCommand ca = FreedomCommand.getFrom(a);
FreedomCommand cb = FreedomCommand.getFrom(b);
return a.getName().compareTo(b.getName());
}

public int compare(FreedomCommand a, FreedomCommand b)
{
return a.getName().compareTo(b.getName());
}

if (ca == null
|| cb == null
|| ca.getPerms() == null
|| cb.getPerms() == null)
{
return a.getName().compareTo(b.getName());
}
public int compare(Rank a, Rank b)
{
Integer levelA = a.getLevel();
Integer levelB = b.getLevel();

return ca.getPerms().level().getName().compareTo(cb.getPerms().level().getName());
return levelB.compareTo(levelA);
}
}

}
Expand Up @@ -60,7 +60,7 @@ public String body() throws ResponseOverrideException
{
if (!LOG_FOLDER.exists())
{
FLog.warning("The logfile module failed to find the logs folder.");
FLog.warn("The logfile module failed to find the logs folder.");
return HTMLGenerationTools.paragraph("Can't find the logs folder.");
}

Expand Down
Expand Up @@ -19,7 +19,6 @@
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringEscapeUtils;
Expand Down Expand Up @@ -260,7 +259,7 @@ private void func2(File tempFile, File targetFile, String remoteAddress) throws
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
throw new SchematicTransferException();
}
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ public PermissionConfig()
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}

copyDefaultConfig(getConfigFile());
Expand All @@ -48,7 +48,7 @@ public PermissionConfig()
}
catch (Exception ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down Expand Up @@ -85,13 +85,13 @@ public void load()
}
else
{
FLog.warning("Missing permission entry " + entry.getConfigName() + ". Using default value.");
FLog.warn("Missing permission entry " + entry.getConfigName() + ". Using default value.");
}
}
}
catch (IOException | InvalidConfigurationException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -108,7 +108,7 @@ public List<?> getList(PermissionEntry entry)
}
catch (IllegalArgumentException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
return null;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ private void copyDefaultConfig(File targetFile)
}
catch (IOException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand All @@ -173,7 +173,7 @@ private PermissionDefaults(InputStream defaultConfig)
}
catch (IOException | InvalidConfigurationException ex)
{
FLog.severe(ex);
FLog.fatal(ex);
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java
Expand Up @@ -16,6 +16,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class FPlayer
{
Expand All @@ -25,6 +26,7 @@ public class FPlayer

private final TotalFreedomMod plugin;

private final UUID uuid;
private final String name;

private final String ip;
Expand Down Expand Up @@ -68,12 +70,13 @@ public class FPlayer

public FPlayer(TotalFreedomMod plugin, Player player)
{
this(plugin, player.getName(), FUtil.getIp(player));
this(plugin, player.getUniqueId(), player.getName(), FUtil.getIp(player));
}

private FPlayer(TotalFreedomMod plugin, String name, String ip)
private FPlayer(TotalFreedomMod plugin, UUID uuid, String name, String ip)
{
this.plugin = plugin;
this.uuid = uuid;
this.name = name;
this.ip = ip;
}
Expand Down Expand Up @@ -267,7 +270,7 @@ public void setMuted(boolean muted, int minutes)
return;
}

plugin.mu.MUTED_PLAYERS.add(getPlayer().getName());
plugin.mu.MUTED_PLAYERS.add(getPlayer().getUniqueId());

// TODO: Simplify this into a Consumer<BukkitTask> lambda?
unmuteTask = new BukkitRunnable()
Expand All @@ -283,7 +286,7 @@ public void run()
else
{
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Unmuting " + getName(), false);
plugin.mu.MUTED_PLAYERS.remove(getName());
plugin.mu.MUTED_PLAYERS.remove(getUuid());
}
}
}.runTaskLater(plugin, minutes * (60L * 20L));
Expand Down Expand Up @@ -378,6 +381,11 @@ public void incrementWarnings(boolean quiet)
}
}

public UUID getUuid()
{
return uuid;
}

public String getName()
{
return name;
Expand Down
Expand Up @@ -63,7 +63,7 @@ public PlayerData(ResultSet resultSet)
}
catch (SQLException e)
{
FLog.severe("Failed to load player: " + e.getMessage());
FLog.fatal("Failed to load player: " + e.getMessage());
}

TotalFreedomMod.getPlugin().pl.save(this);
Expand Down
Expand Up @@ -12,13 +12,11 @@
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

public class PlayerList extends FreedomService
{
public final Map<String, FPlayer> playerMap = Maps.newHashMap(); // ip,dataMap
public final Map<UUID, FPlayer> playerMap = Maps.newHashMap(); // uuid, fplayer
public final Map<UUID, PlayerData> dataMap = Maps.newHashMap(); // uuid, data

@Override
Expand Down Expand Up @@ -60,7 +58,7 @@ public void loadMasterBuilders()
}
catch (SQLException e)
{
FLog.severe("Failed to parse master builders: " + e.getMessage());
FLog.fatal("Failed to parse master builders: " + e.getMessage());
}
}

Expand Down Expand Up @@ -96,14 +94,14 @@ public boolean isTelnetMasterBuilder(PlayerData playerData)
// May not return null
public FPlayer getPlayer(Player player)
{
FPlayer tPlayer = playerMap.get(FUtil.getIp(player));
FPlayer tPlayer = playerMap.get(player.getUniqueId());
if (tPlayer != null)
{
return tPlayer;
}

tPlayer = new FPlayer(plugin, player);
playerMap.put(FUtil.getIp(player), tPlayer);
playerMap.put(player.getUniqueId(), tPlayer);

return tPlayer;
}
Expand Down Expand Up @@ -135,19 +133,6 @@ public void syncIps(Admin admin)
plugin.pl.save(playerData);
}

public void syncIps(PlayerData playerData)
{
Admin admin = plugin.al.getEntryByName(playerData.getName());

if (admin != null && admin.isActive())
{
admin.clearIPs();
admin.addIps(playerData.getIps());
plugin.al.updateTables();
plugin.al.save(admin);
}
}

public void save(PlayerData player)
{
try
Expand All @@ -164,7 +149,7 @@ public void save(PlayerData player)
}
catch (SQLException e)
{
FLog.severe("Failed to save player: " + e.getMessage());
FLog.fatal("Failed to save player: " + e.getMessage());
}
}

Expand Down Expand Up @@ -254,7 +239,7 @@ public PlayerData getData(String username)
return null;
}

public Map<String, FPlayer> getPlayerMap()
public Map<UUID, FPlayer> getPlayerMap()
{
return playerMap;
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public void onStart()
{
if (!config.isConfigurationSection(id))
{
FLog.warning("Failed to load punishment number " + id + "!");
FLog.warn("Failed to load punishment number " + id + "!");
continue;
}

Expand All @@ -41,7 +41,7 @@ public void onStart()

if (!punishment.isValid())
{
FLog.warning("Not adding punishment number " + id + ". Missing information.");
FLog.warn("Not adding punishment number " + id + ". Missing information.");
continue;
}

Expand Down
10 changes: 0 additions & 10 deletions src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java
Expand Up @@ -181,16 +181,6 @@ public org.bukkit.ChatColor getTeamColor()
return teamColor;
}

public boolean isHasTeam()
{
return hasTeam;
}

public boolean isHasDefaultLoginMessage()
{
return hasDefaultLoginMessage;
}

public enum Type
{
PLAYER,
Expand Down
Expand Up @@ -70,28 +70,6 @@ public Displayable getDisplay(CommandSender sender)
return getRank(player);
}

public Displayable getDisplay(Admin admin)
{
// If the player's an owner, display that
if (ConfigEntry.SERVER_OWNERS.getList().contains(admin.getName()))
{
return Title.OWNER;
}

// Developers always show up
if (FUtil.isDeveloper((Player)admin))
{
return Title.DEVELOPER;
}

if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(admin.getName()))
{
return Title.EXECUTIVE;
}

return admin.getRank();
}

public Rank getRank(CommandSender sender)
{
if (sender instanceof Player)
Expand Down
60 changes: 30 additions & 30 deletions src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java
Expand Up @@ -44,7 +44,7 @@ public void connect()
}
catch (SQLException e)
{
FLog.severe("Failed to connect to the database: " + e.getMessage());
FLog.fatal("Failed to connect to the database: " + e.getMessage());
}
}

Expand All @@ -59,7 +59,7 @@ public void disconnect()
}
catch (SQLException e)
{
FLog.severe("Failed to disconnect from the database: " + e.getMessage());
FLog.fatal("Failed to disconnect from the database: " + e.getMessage());
}
}

Expand All @@ -76,7 +76,7 @@ public void checkTables()
}
catch (SQLException e)
{
FLog.severe("Failed to create the bans table: " + e.getMessage());
FLog.fatal("Failed to create the bans table: " + e.getMessage());
}
}

Expand All @@ -88,7 +88,7 @@ public void checkTables()
}
catch (SQLException e)
{
FLog.severe("Failed to create the admins table: " + e.getMessage());
FLog.fatal("Failed to create the admins table: " + e.getMessage());
}
}
if (tableExists(meta, "players"))
Expand All @@ -99,13 +99,13 @@ public void checkTables()
}
catch (SQLException e)
{
FLog.severe("Failed to create the players table: " + e.getMessage());
FLog.fatal("Failed to create the players table: " + e.getMessage());
}
}
}
catch (SQLException e)
{
FLog.severe("Failed to check tables on database: " + e.getMessage());
FLog.fatal("Failed to check tables on database: " + e.getMessage());
}
}

Expand All @@ -117,7 +117,7 @@ public void truncate(String table)
}
catch (SQLException e)
{
FLog.severe("Failed to truncate " + table + ": " + e.getMessage());
FLog.fatal("Failed to truncate " + table + ": " + e.getMessage());
}
}

Expand All @@ -143,12 +143,12 @@ public void setAdminValue(Admin admin, String key, Object value)
}
catch (SQLException e)
{
FLog.severe("Failed to update admin value:");
FLog.severe(e);
FLog.severe("--- DUMP ---");
FLog.severe("UUID: " + admin.getUuid().toString());
FLog.severe("Key: " + key);
FLog.severe("Value: " + value);
FLog.fatal("Failed to update admin value:");
FLog.fatal(e);
FLog.fatal("--- DUMP ---");
FLog.fatal("UUID: " + admin.getUuid().toString());
FLog.fatal("Key: " + key);
FLog.fatal("Value: " + value);
}
}

Expand All @@ -164,7 +164,7 @@ public void setPlayerValue(PlayerData player, String key, Object value)
}
catch (SQLException e)
{
FLog.severe("Failed to update player value: " + e.getMessage());
FLog.fatal("Failed to update player value: " + e.getMessage());
}
}

Expand Down Expand Up @@ -237,8 +237,8 @@ public void addAdmin(Admin admin)
}
catch (SQLException e)
{
FLog.severe("Failed to add admin:");
FLog.severe(e);
FLog.fatal("Failed to add admin:");
FLog.fatal(e);
}
}

Expand All @@ -264,8 +264,8 @@ public void addPlayer(PlayerData player)
}
catch (SQLException e)
{
FLog.severe("Failed to add player:");
FLog.severe(e);
FLog.fatal("Failed to add player:");
FLog.fatal(e);
}
}

Expand All @@ -281,8 +281,8 @@ public ResultSet getAdminByUuid(UUID uuid)
}
catch (SQLException e)
{
FLog.severe("Failed to get admin by uuid:");
FLog.severe(e);
FLog.fatal("Failed to get admin by uuid:");
FLog.fatal(e);
}

return null;
Expand All @@ -300,8 +300,8 @@ public ResultSet getPlayerByUuid(UUID uuid)
}
catch (SQLException e)
{
FLog.severe("Failed to get player by uuid:");
FLog.severe(e);
FLog.fatal("Failed to get player by uuid:");
FLog.fatal(e);
}

return null;
Expand All @@ -315,8 +315,8 @@ public ResultSet getMasterBuilders()
}
catch (SQLException e)
{
FLog.severe("Failed to get Master Builders:");
FLog.severe(e);
FLog.fatal("Failed to get Master Builders:");
FLog.fatal(e);
}

return null;
Expand All @@ -334,8 +334,8 @@ public ResultSet getPlayerByIp(String ip)
}
catch (SQLException e)
{
FLog.severe("Failed to get player by ip:");
FLog.severe(e);
FLog.fatal("Failed to get player by ip:");
FLog.fatal(e);
}

return null;
Expand All @@ -349,8 +349,8 @@ public void removeAdmin(Admin admin)
}
catch (SQLException e)
{
FLog.severe("Failed to remove admin:");
FLog.severe(e);
FLog.fatal("Failed to remove admin:");
FLog.fatal(e);
}
}

Expand All @@ -375,7 +375,7 @@ public void addBan(Ban ban)
}
catch (SQLException e)
{
FLog.severe("Failed to add ban: " + e.getMessage());
FLog.fatal("Failed to add ban: " + e.getMessage());
}
}

Expand All @@ -391,7 +391,7 @@ public void removeBan(Ban ban)
}
catch (SQLException e)
{
FLog.severe("Failed to remove ban: " + e.getMessage());
FLog.fatal("Failed to remove ban: " + e.getMessage());
}
}

Expand Down
139 changes: 85 additions & 54 deletions src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java
@@ -1,112 +1,143 @@
package me.totalfreedom.totalfreedommod.util;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FLog
{
private static Logger logger = LogManager.getLogger("TotalFreedomMod");
private static Logger raw = LogManager.getLogger("Minecraft");

private static final Logger FALLBACK_LOGGER = Logger.getLogger("Minecraft-Server");
private static Logger serverLogger = null;
private static Logger pluginLogger = null;

// Level.INFO:
public static void info(String message)
{
info(message, false);
info(message, null, false);
}

public static void info(String message, Boolean raw)
public static void info(String message, boolean raw)
{
log(Level.INFO, message, raw);
info(message, null, raw);
}

public static void info(Throwable ex)
public static void info(String message, Throwable ex)
{
log(Level.INFO, ex);
info(message, ex, false);
}

// Fuck spigot for not using log4j, we would of had a debug log level if they did
public static void debug(String message)
public static void info(String message, Throwable ex, boolean raw)
{
log(Level.INFO, message, ex, raw);
}

public static void warn(Throwable ex)
{
warn(ex, false);
}

public static void warn(Throwable ex, boolean raw)
{
if (FUtil.inDeveloperMode())
{
log(Level.INFO, "\u001B[35m[TotalFreedomMod | DEBUG] " + message + "\u001B[0m", true);
}
warn(null, ex, raw);
}

// Level.WARNING:
public static void warning(String message)
public static void warn(String message)
{
warning(message, false);
warn(message, false);
}

public static void warning(String message, Boolean raw)
public static void warn(String message, boolean raw)
{
log(Level.WARNING, message, raw);
warn(message, null, raw);
}

public static void warning(Throwable ex)
public static void warn(String message, Throwable ex)
{
log(Level.WARNING, ex);
warn(message, ex, false);
}

// Level.SEVERE:
public static void severe(String message)
public static void warn(String message, Throwable ex, boolean raw)
{
severe(message, false);
log(Level.WARN, message, ex, raw);
}

public static void severe(String message, Boolean raw)
public static void error(Throwable ex)
{
log(Level.SEVERE, message, raw);
error(null, ex);
}

public static void severe(Throwable ex)
public static void error(Throwable ex, boolean raw)
{
log(Level.SEVERE, ex);
error(null, ex, raw);
}

// Utility
private static void log(Level level, String message, boolean raw)
public static void error(String message)
{
getLogger(raw).log(level, message);
error(message, false);
}

private static void log(Level level, Throwable throwable)
public static void error(String message, boolean raw)
{
getLogger(false).log(level, null, throwable);
error(message, null, raw);
}

private static Logger getLogger(boolean raw)
public static void error(String message, Throwable ex)
{
if (raw || pluginLogger == null)
{
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
}
else
{
return pluginLogger;
}
error(message, ex, false);
}

public static Logger getPluginLogger()
public static void error(String message, Throwable ex, boolean raw)
{
return (pluginLogger != null ? pluginLogger : FALLBACK_LOGGER);
log(Level.ERROR, message, ex, raw);
}

public static void setPluginLogger(Logger logger)
public static void fatal(Throwable ex)
{
pluginLogger = logger;
fatal(null, ex);
}

public static Logger getServerLogger()
public static void fatal(Throwable ex, boolean raw)
{
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
fatal(null, ex, raw);
}

public static void setServerLogger(Logger logger)
public static void fatal(String message)
{
serverLogger = logger;
fatal(message, false);
}

public static void fatal(String message, boolean raw)
{
fatal(message, null, raw);
}

public static void fatal(String message, Throwable ex)
{
fatal(message, ex, false);
}

public static void fatal(String message, Throwable ex, boolean raw)
{
log(Level.FATAL, message, ex, raw);
}

public static void debug(String message, Throwable ex)
{
log(Level.DEBUG, message, ex, false);
}

public static void debug(String message)
{
log(Level.DEBUG, message, false);
}

private static void log(Level level, String message, boolean isRaw)
{
log(level, message, null, isRaw);
}

private static void log(Level level, String message, Throwable exception, boolean isRaw)
{
Logger log = isRaw ? raw : logger;

log.log(level, message, exception);
}
}
86 changes: 1 addition & 85 deletions src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
Expand Up @@ -20,19 +20,15 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.json.simple.JSONArray;

import java.io.*;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static org.bukkit.Bukkit.getServer;

Expand Down Expand Up @@ -135,14 +131,7 @@ public static boolean isExecutive(String name)

public static boolean isDeveloper(Player player)
{
if (Bukkit.getOnlineMode())
{
return DEVELOPERS.contains(player.getUniqueId().toString());
}
else
{
return DEVELOPER_NAMES.contains(player.getName());
}
return DEVELOPERS.contains(player.getUniqueId().toString());
}

public static boolean inDeveloperMode()
Expand Down Expand Up @@ -458,79 +447,6 @@ public static boolean isFromHostConsole(String senderName)
return ConfigEntry.HOST_SENDER_NAMES.getList().contains(senderName.toLowerCase());
}

public static boolean fuzzyIpMatch(String a, String b, int octets)
{
boolean match = true;

String[] aParts = a.split("\\.");
String[] bParts = b.split("\\.");

if (aParts.length != 4 || bParts.length != 4)
{
return false;
}

if (octets > 4)
{
octets = 4;
}
else if (octets < 1)
{
octets = 1;
}

for (int i = 0; i < octets; i++)
{
if (aParts[i].equals("*") || bParts[i].equals("*"))
{
continue;
}

if (!aParts[i].equals(bParts[i]))
{
match = false;
break;
}
}

return match;
}

public static String getFuzzyIp(String ip)
{
final String[] ipParts = ip.split("\\.");
if (ipParts.length == 4)
{
return String.format("%s.%s.*.*", ipParts[0], ipParts[1]);
}

return ip;
}

//getField: Borrowed from WorldEdit
@SuppressWarnings("unchecked")
public static <T> T getField(Object from, String name)
{
Class<?> checkClass = from.getClass();
do
{
try
{
Field field = checkClass.getDeclaredField(name);
field.setAccessible(true);
return (T) field.get(from);

}
catch (NoSuchFieldException | IllegalAccessException ignored)
{
}
}
while (checkClass.getSuperclass() != Object.class
&& ((checkClass = checkClass.getSuperclass()) != null));

return null;
}

public static ChatColor randomChatColor()
{
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
Expand Down
@@ -1,10 +1,6 @@
package me.totalfreedom.totalfreedommod.world;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -13,18 +9,13 @@
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;

public final class AdminWorld extends CustomWorld
{

private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds
private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds
private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
//
private final Map<Player, Long> teleportCooldown = new HashMap<>();
//
private WorldWeather weather = WorldWeather.OFF;
private WorldTime time = WorldTime.INHERIT;

Expand All @@ -39,7 +30,6 @@ public void sendToWorld(Player player)
super.sendToWorld(player);
}

@SuppressWarnings("deprecation")
@Override
protected World generateWorld()
{
Expand All @@ -59,8 +49,8 @@ protected World generateWorld()
welcomeSignBlock.setType(Material.OAK_SIGN);
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState();

org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData();
signData.setFacingDirection(BlockFace.NORTH);
Sign signData = (Sign) welcomeSign.getBlockData();
signData.setRotation(BlockFace.NORTH);

welcomeSign.setLine(0, ChatColor.GREEN + "AdminWorld");
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
Expand All @@ -72,37 +62,6 @@ protected World generateWorld()
return world;
}

public boolean validateMovement(PlayerMoveEvent event)
{
World world;
try
{
world = getWorld();
}
catch (Exception ex)
{
return true;
}

if (world == null || !Objects.equals(Objects.requireNonNull(event.getTo()).getWorld(), world))
{
return true;
}

final Player player = event.getPlayer();

Long lastTP = teleportCooldown.get(player);

long currentTimeMillis = System.currentTimeMillis();
if (lastTP == null || lastTP + TP_COOLDOWN_TIME <= currentTimeMillis)
{
teleportCooldown.put(player, currentTimeMillis);
FLog.info(player.getName() + " attempted to access the AdminWorld.");
event.setTo(Bukkit.getWorlds().get(0).getSpawnLocation());
}
return false;
}

public WorldWeather getWeatherMode()
{
return weather;
Expand Down
Expand Up @@ -30,7 +30,7 @@

public class CleanroomChunkGenerator extends ChunkGenerator
{
private final Logger log = Logger.getLogger("Minecraft");
private final Logger log = Logger.getLogger("CleanroomGenerator");

private Material[] materials;

Expand Down Expand Up @@ -64,27 +64,27 @@ public CleanroomChunkGenerator(String id)
int height = Integer.parseInt(tokens[i]);
if (height <= 0)
{
log.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead.");
log.warning("Invalid height '" + tokens[i] + "'. Using 64 instead.");
height = 64;
}

String[] materialTokens = tokens[i + 1].split("[:]", 2);

if (materialTokens.length == 2)
{
log.warning("[CleanroomGenerator] Data values are no longer supported in 1.13. Defaulting to the base material for " + materialTokens[0]);
log.warning("Data values are no longer supported in 1.13. Defaulting to the base material for " + materialTokens[0]);
}

Material mat = Material.matchMaterial(materialTokens[0]);
if (mat == null)
{
log.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone. (Integer IDs were removed in 1.13)");
log.warning("Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone. (Integer IDs were removed in 1.13)");
mat = Material.STONE;
}

if (!mat.isBlock())
{
log.warning("[CleanroomGenerator] Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone.");
log.warning("Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone.");
mat = Material.STONE;
}

Expand All @@ -111,7 +111,7 @@ public CleanroomChunkGenerator(String id)
}
catch (Exception e)
{
log.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString());
log.severe("Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e);
e.printStackTrace();

materials = new Material[65];
Expand Down
Expand Up @@ -37,7 +37,7 @@ public final World getWorld()

if (world == null)
{
FLog.warning("Could not load world: " + name);
FLog.warn("Could not load world: " + name);
}

return world;
Expand Down
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Sign;

public class Flatlands extends CustomWorld
{
Expand All @@ -20,7 +21,6 @@ public Flatlands()
super("flatlands");
}

@SuppressWarnings("deprecation")
@Override
protected World generateWorld()
{
Expand All @@ -34,7 +34,6 @@ protected World generateWorld()
worldCreator.type(WorldType.NORMAL);
worldCreator.environment(World.Environment.NORMAL);
worldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS));

final World world = Bukkit.getServer().createWorld(worldCreator);

assert world != null;
Expand All @@ -45,8 +44,8 @@ protected World generateWorld()
welcomeSignBlock.setType(Material.OAK_SIGN);
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState();

org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData();
signData.setFacingDirection(BlockFace.NORTH);
Sign signData = (Sign) welcomeSign.getBlockData();
signData.setRotation(BlockFace.NORTH);

welcomeSign.setLine(0, ChatColor.GREEN + "Flatlands");
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
Expand All @@ -55,7 +54,6 @@ protected World generateWorld()
welcomeSign.update();

plugin.gr.commitGameRules();

return world;
}
}
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Sign;
import org.bukkit.entity.Player;

public final class MasterBuilderWorld extends CustomWorld
Expand All @@ -29,8 +30,6 @@ public void sendToWorld(Player player)
super.sendToWorld(player);
}

// TODO: Replace org.bukkit.Sign with a non deprecated version. This may require extra boilerplate.
@SuppressWarnings("deprecation")
@Override
protected World generateWorld()
{
Expand All @@ -50,8 +49,8 @@ protected World generateWorld()
welcomeSignBlock.setType(Material.OAK_SIGN);
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState();

org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData();
signData.setFacingDirection(BlockFace.NORTH);
Sign signData = (Sign) welcomeSign.getBlockData();
signData.setRotation(BlockFace.NORTH);

welcomeSign.setLine(0, ChatColor.GREEN + "MB World");
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
Expand Down
32 changes: 29 additions & 3 deletions src/main/resources/config.yml
Expand Up @@ -457,6 +457,35 @@ blocked_commands:
- slconfig
- smite

# Death Messages
death_messages:
# Should we limit the output?
limit: true

# Maximum amount of text to show before getting cut off.
max: 96

# Entity Wiper
entity_wiper:
# Should the EntityWiper even kick in?
enabled: true

# How many ticks until the entity wiper starts wiping entities
delay: 600

# How many ticks there should be between each automatic wipe
interval: 600

# Entities that the entity wiper will not wipe during its periodic tasks
# See https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html for a complete list of entities
blacklist:
- ARMOR_STAND
- BOAT
- ITEM_FRAME
- LEASH_HITCH
- PAINTING
- MINECART

# Words that cannot be used in tags
forbidden_words:
- admin
Expand All @@ -472,9 +501,6 @@ forbidden_words:
- sta
- sa

# Automatically wipe dropped objects
auto_wipe: true

# Nuking prevention
nukemonitor:
enabled: true
Expand Down
51 changes: 39 additions & 12 deletions src/main/resources/permissions.yml
@@ -1,19 +1,28 @@
#
# TotalFreedomMod 5.5 Permissions
# TotalFreedomMod Permissions
# by ZeroEpoch1969
#

# Note that every group inherits the previous groups' permissions
# Meaning Telnet Admins have the permissions of Operators and Super Admins, and etc
# Note that every group inherits their preceding groups' permissions. This means that Senior Admins have the permissions
# that operators and and Admins have along with their own set of permission nodes.

# This is used to remove all permission begging with the root node
# This is useful when a plugin gives all permissions to a player because they are opped
# This section is used to remove all permissions beginning with the root node. Handy for dealing with plugins that give
# players every permission because of their operator statuses.
remove:
# VoxelSniper
- "voxelsniper"

# ProjectKorra
- "bending.admin"
- "bending.ability.Cleanse"

# WorldEdit
- "worldedit.brush.apply"

# Essentials
- "essentials.near.exclude"

# PlotSquared
- "plots.admin"
- "plots.debugroadregen"
- "plots.debugclaimtest"
Expand All @@ -22,9 +31,11 @@ remove:
- "plots.debugloadtest"
- "plots.debugsavetest"
- "plots.cluster"
#Crackshot

# Crackshot
- "crackshot.bypass.all"
#NetworkManager

# NetworkManager
- "networkmanager.*"
- "networkmanager.notify.joinbanned"
- "networkmanager.notify.*"
Expand All @@ -45,7 +56,6 @@ remove:
- "networkmanager.commandblocker.bypass"
- "networkmanager.tags.*"


# Operator permission nodes
operators:
# WorldEdit
Expand Down Expand Up @@ -74,6 +84,7 @@ operators:
- "worldedit.global-mask"
- "worldedit.fill"
- "worldedit.fill.recursive"

# LibsDisguises
- "libsdisguises.noactionbar"

Expand All @@ -83,7 +94,7 @@ operators:
- "worldguard.region.removemember.own.*"
- "worldguard.region.info.*"

# Bending
# ProjectKorra
- "bending.command.add"
- "bending.command.bind"
- "bending.command.check"
Expand Down Expand Up @@ -133,6 +144,7 @@ operators:
- "bending.earth.passive"
- "bending.fire.passive"
- "bending.water.passive"

# NetworkManager
- "networkmanager.chatlog"
- "networkmanager.find"
Expand All @@ -145,36 +157,51 @@ operators:

# Master Builder permission nodes
master_builders:
# WorldEdit
- "worldedit.tool.*"
- "worldedit.brush.*"
- "worldedit.snow"
- "worldedit.green"
- "worldedit.extinguish"
- "worldedit.thaw"
- "worldguard.region.bypass.hubworld"

# WorldGuard
- "worldguard.region.bypass.masterbuilderworld"

# VoxelSniper
- "voxelsniper.sniper"
- "voxelsniper.goto"
- "voxelsniper.brush.*"

# Admin permission nodes
admins:
# WorldEdit
- "worldedit.*"

# WorldGuard
- "worldguard.*"

# ProjectKorra
- "bending.admin.remove"
- "bending.command.toggle.all"
- "bending.admin.toggle"
- "bending.command.reload"

# PlotSquared
- "plots.cluster"

# NetworkManager
- "networkmanager.adminchat"
- "networkmanager.announce.server"
- "networkmanager.socialspy"
- "networkmanager.fullproxy.bypass"
- "networkmanager.lookup.ip"
#Crackshot

# Crackshot
- "crackshot.bypass.all"

# Senior Admin permission nodes
senior_admins:
senior_admins:
# ProjectKorra
- "bending.admin.permaremove"
- "bending.ability.Cleanse"
7 changes: 6 additions & 1 deletion src/main/resources/plugin.yml
Expand Up @@ -14,4 +14,9 @@ softdepend:
- JDA
- Votifier
authors: [Madgeek1450, Prozza]
api-version: 1.16
api-version: 1.16
libraries:
- org.apache.commons:commons-lang3:3.12.0
- commons-io:commons-io:2.11.0
- org.jetbrains:annotations:22.0.0
- org.javassist:javassist:3.28.0-GA