[Bleeding] Revamped rank system yet again

Refractoring
Bug fixes
Mass format
This commit is contained in:
JeromSar 2016-02-29 21:48:17 +01:00
parent a0058869c9
commit 4586b7519f
33 changed files with 219 additions and 301 deletions

View File

@ -1,43 +0,0 @@
package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.component.service.AbstractService;
import net.pravian.aero.util.Ips;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class ConsoleLogger extends AbstractService<TotalFreedomMod>
{
public ConsoleLogger(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event)
{
FLog.info("[EXIT] " + event.getPlayer().getName() + " left the game.", true);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
final String ip = Ips.getIp(event.getPlayer());
FLog.info("[JOIN] " + FUtil.formatPlayer(event.getPlayer()) + " joined the game with IP address: " + ip, true);
}
}

View File

@ -129,7 +129,8 @@ public class FrontDoor extends AbstractService<TotalFreedomMod>
} }
catch (Exception ex) catch (Exception ex)
{ {
// TFM_Log.info("GAH GAH GAH"); // TODO: Fix
//FLog.warning(ex);
} }
} }

View File

@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -13,13 +14,13 @@ import org.bukkit.World;
public class GameRuleHandler extends AbstractService<TotalFreedomMod> public class GameRuleHandler extends AbstractService<TotalFreedomMod>
{ {
private final EnumMap<TFM_GameRule, TFM_GameRule_Value> rules = new EnumMap<TFM_GameRule, TFM_GameRule_Value>(TFM_GameRule.class); private final Map<GameRule, Boolean> rules = new EnumMap<GameRule, Boolean>(GameRule.class);
public GameRuleHandler(TotalFreedomMod plugin) public GameRuleHandler(TotalFreedomMod plugin)
{ {
super(plugin); super(plugin);
for (TFM_GameRule gameRule : TFM_GameRule.values()) for (GameRule gameRule : GameRule.values())
{ {
rules.put(gameRule, gameRule.getDefaultValue()); rules.put(gameRule, gameRule.getDefaultValue());
} }
@ -28,13 +29,13 @@ public class GameRuleHandler extends AbstractService<TotalFreedomMod>
@Override @Override
protected void onStart() protected void onStart()
{ {
setGameRule(TFM_GameRule.DO_DAYLIGHT_CYCLE, !ConfigEntry.DISABLE_NIGHT.getBoolean(), false); setGameRule(GameRule.DO_DAYLIGHT_CYCLE, !ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
setGameRule(TFM_GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false); setGameRule(GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
setGameRule(TFM_GameRule.DO_MOB_LOOT, false, false); setGameRule(GameRule.DO_MOB_LOOT, false, false);
setGameRule(TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false); setGameRule(GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
setGameRule(TFM_GameRule.DO_TILE_DROPS, false, false); setGameRule(GameRule.DO_TILE_DROPS, false, false);
setGameRule(TFM_GameRule.MOB_GRIEFING, false, false); setGameRule(GameRule.MOB_GRIEFING, false, false);
setGameRule(TFM_GameRule.NATURAL_REGENERATION, true, false); setGameRule(GameRule.NATURAL_REGENERATION, true, false);
commitGameRules(); commitGameRules();
} }
@ -43,14 +44,14 @@ public class GameRuleHandler extends AbstractService<TotalFreedomMod>
{ {
} }
public void setGameRule(TFM_GameRule gameRule, boolean value) public void setGameRule(GameRule gameRule, boolean value)
{ {
setGameRule(gameRule, value, true); setGameRule(gameRule, value, true);
} }
public void setGameRule(TFM_GameRule gameRule, boolean value, boolean doCommit) public void setGameRule(GameRule gameRule, boolean value, boolean doCommit)
{ {
rules.put(gameRule, TFM_GameRule_Value.fromBoolean(value)); rules.put(gameRule, value);
if (doCommit) if (doCommit)
{ {
commitGameRules(); commitGameRules();
@ -60,39 +61,43 @@ public class GameRuleHandler extends AbstractService<TotalFreedomMod>
public void commitGameRules() public void commitGameRules()
{ {
List<World> worlds = Bukkit.getWorlds(); List<World> worlds = Bukkit.getWorlds();
Iterator<Map.Entry<TFM_GameRule, TFM_GameRule_Value>> it = rules.entrySet().iterator(); Iterator<Map.Entry<GameRule, Boolean>> it = rules.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Map.Entry<TFM_GameRule, TFM_GameRule_Value> gameRuleEntry = it.next();
Map.Entry<GameRule, Boolean> gameRuleEntry = it.next();
String gameRuleName = gameRuleEntry.getKey().getGameRuleName(); String gameRuleName = gameRuleEntry.getKey().getGameRuleName();
String gameRuleValue = gameRuleEntry.getValue().toString(); String gameRuleValue = gameRuleEntry.getValue().toString();
for (World world : worlds) for (World world : worlds)
{ {
world.setGameRuleValue(gameRuleName, gameRuleValue); world.setGameRuleValue(gameRuleName, gameRuleValue);
if (gameRuleEntry.getKey() == TFM_GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue().toBoolean()) if (gameRuleEntry.getKey() == GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue())
{ {
FUtil.setWorldTime(world, 6000L); FUtil.setWorldTime(world, 6000L);
} }
} }
} }
} }
public static enum TFM_GameRule public static enum GameRule
{ {
DO_FIRE_TICK("doFireTick", TFM_GameRule_Value.TRUE), DO_FIRE_TICK("doFireTick", true),
MOB_GRIEFING("mobGriefing", TFM_GameRule_Value.TRUE), MOB_GRIEFING("mobGriefing", true),
KEEP_INVENTORY("keepInventory", TFM_GameRule_Value.FALSE), KEEP_INVENTORY("keepInventory", false),
DO_MOB_SPAWNING("doMobSpawning", TFM_GameRule_Value.TRUE), DO_MOB_SPAWNING("doMobSpawning", true),
DO_MOB_LOOT("doMobLoot", TFM_GameRule_Value.TRUE), DO_MOB_LOOT("doMobLoot", true),
DO_TILE_DROPS("doTileDrops", TFM_GameRule_Value.TRUE), DO_TILE_DROPS("doTileDrops", true),
COMMAND_BLOCK_OUTPUT("commandBlockOutput", TFM_GameRule_Value.TRUE), COMMAND_BLOCK_OUTPUT("commandBlockOutput", true),
NATURAL_REGENERATION("naturalRegeneration", TFM_GameRule_Value.TRUE), NATURAL_REGENERATION("naturalRegeneration", true),
DO_DAYLIGHT_CYCLE("doDaylightCycle", TFM_GameRule_Value.TRUE); DO_DAYLIGHT_CYCLE("doDaylightCycle", true);
//
private final String gameRuleName; private final String gameRuleName;
private final TFM_GameRule_Value defaultValue; private final boolean defaultValue;
private TFM_GameRule(String gameRuleName, TFM_GameRule_Value defaultValue) private GameRule(String gameRuleName, boolean defaultValue)
{ {
this.gameRuleName = gameRuleName; this.gameRuleName = gameRuleName;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
@ -103,38 +108,10 @@ public class GameRuleHandler extends AbstractService<TotalFreedomMod>
return gameRuleName; return gameRuleName;
} }
public TFM_GameRule_Value getDefaultValue() public boolean getDefaultValue()
{ {
return defaultValue; return defaultValue;
} }
} }
public static enum TFM_GameRule_Value
{
TRUE("true"), FALSE("false");
private final String value;
private TFM_GameRule_Value(String value)
{
this.value = value;
}
@Override
public String toString()
{
return this.value;
}
public boolean toBoolean()
{
return (this.value.equals(TFM_GameRule_Value.TRUE.value));
}
public static TFM_GameRule_Value fromBoolean(boolean in)
{
return (in ? TFM_GameRule_Value.TRUE : TFM_GameRule_Value.FALSE);
}
}
} }

View File

@ -103,11 +103,6 @@ public class LoginProcess extends AbstractService<TotalFreedomMod>
} }
} }
// Generate playerdata if it is nonexistent
plugin.pl.getData(player);
final FPlayer fPlayer = plugin.pl.getPlayer(player);
fPlayer.setSuperadminIdVerified(false);
// Check if player is admin // Check if player is admin
// Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login. // Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login.
final boolean isAdmin = plugin.al.getEntryByIp(ip) != null; final boolean isAdmin = plugin.al.getEntryByIp(ip) != null;

View File

@ -30,8 +30,6 @@ public class MovementValidator extends AbstractService<TotalFreedomMod>
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(PlayerTeleportEvent event) public void onPlayerTeleport(PlayerTeleportEvent event)
{ {
final Player player = event.getPlayer();
// Check absolute value to account for negatives // Check absolute value to account for negatives
if (Math.abs(event.getTo().getX()) >= MAX_XZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XZ_COORD) if (Math.abs(event.getTo().getX()) >= MAX_XZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XZ_COORD)
{ {

View File

@ -59,7 +59,6 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
// Services // Services
public ServiceManager<TotalFreedomMod> services; public ServiceManager<TotalFreedomMod> services;
public ServerInterface si; public ServerInterface si;
public ConsoleLogger co;
public WorldManager wm; public WorldManager wm;
public AdminList al; public AdminList al;
public EventBlocker eb; public EventBlocker eb;
@ -142,7 +141,6 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
// Start services and bridgess // Start services and bridgess
services = new ServiceManager<TotalFreedomMod>(plugin); services = new ServiceManager<TotalFreedomMod>(plugin);
si = services.registerService(ServerInterface.class); si = services.registerService(ServerInterface.class);
co = services.registerService(ConsoleLogger.class);
wm = services.registerService(WorldManager.class); wm = services.registerService(WorldManager.class);
al = services.registerService(AdminList.class); al = services.registerService(AdminList.class);
eb = services.registerService(EventBlocker.class); eb = services.registerService(EventBlocker.class);
@ -214,8 +212,8 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public void disable() public void disable()
{ {
// Stop services and bridges // Stop services and bridges
services.stop();
bridges.stop(); bridges.stop();
services.stop();
server.getScheduler().cancelTasks(plugin); server.getScheduler().cancelTasks(plugin);

View File

@ -6,6 +6,7 @@ import java.util.List;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.totalfreedom.totalfreedommod.rank.PlayerRank; import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.base.ConfigLoadable; import net.pravian.aero.base.ConfigLoadable;
import net.pravian.aero.base.ConfigSavable; import net.pravian.aero.base.ConfigSavable;
@ -80,7 +81,7 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
{ {
name = cs.getString("username", configKey); name = cs.getString("username", configKey);
activated = cs.getBoolean("active", true); activated = cs.getBoolean("active", true);
rank = PlayerRank.forString(cs.getString("rank")); rank = PlayerRank.findRank(cs.getString("rank"));
ips.clear(); ips.clear();
ips.addAll(cs.getStringList("ips")); ips.addAll(cs.getStringList("ips"));
lastLogin = FUtil.stringToDate(cs.getString("last_login")); lastLogin = FUtil.stringToDate(cs.getString("last_login"));
@ -99,9 +100,9 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
cs.set("login_message", null); cs.set("login_message", null);
} }
public boolean isMinimum(PlayerRank pRank) public boolean isAtLeast(PlayerRank pRank)
{ {
return rank.ordinal() >= pRank.ordinal(); return rank.isAtLeast(pRank);
} }
// Util IP methods // Util IP methods

View File

@ -1,8 +1,8 @@
package me.totalfreedom.totalfreedommod.commands; package me.totalfreedom.totalfreedommod.commands;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions public @interface CommandPermissions

View File

@ -8,6 +8,7 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -77,7 +78,7 @@ public class Command_glist extends FreedomCommand
{ {
FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
final Player target = getPlayer(username, true); final Player target = Bukkit.getPlayer(username);
if (target != null) if (target != null)
{ {
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + ConfigEntry.SERVER_BAN_URL.getString()); target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + ConfigEntry.SERVER_BAN_URL.getString());

View File

@ -77,7 +77,7 @@ public class Command_moblimiter extends FreedomCommand
playerMsg("Moblimiter is disabled. No mob restrictions are in effect."); playerMsg("Moblimiter is disabled. No mob restrictions are in effect.");
} }
plugin.gr.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()); plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean());
return true; return true;
} }

View File

@ -27,13 +27,15 @@ public class Command_saconfig extends FreedomCommand
} }
catch (final PermissionsException ex) catch (final PermissionsException ex)
{ {
if (ex.getMessage().isEmpty()) String msg = ex.getMessage();
if (msg != null && !msg.isEmpty())
{ {
return noPerms(); sender.sendMessage(msg);
}
sender.sendMessage(ex.getMessage());
return true; return true;
} }
return noPerms();
}
catch (final FormatException ex) catch (final FormatException ex)
{ {
playerMsg(ex.getMessage()); playerMsg(ex.getMessage());
@ -231,7 +233,7 @@ public class Command_saconfig extends FreedomCommand
Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender); Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender);
boolean isSeniorAdmin = admin != null ? admin.isMinimum(PlayerRank.SENIOR_ADMIN) : false; boolean isSeniorAdmin = admin != null ? admin.getRank().isAtLeast(PlayerRank.SENIOR_ADMIN) : false;
for (final SAConfigMode mode : values()) for (final SAConfigMode mode : values())
{ {

View File

@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.commands;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.PlayerRank; import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.GameRuleHandler.TFM_GameRule; import me.totalfreedom.totalfreedommod.GameRuleHandler.GameRule;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -68,7 +68,7 @@ public class Command_toggle extends FreedomCommand
if (args[0].equals("firespread")) if (args[0].equals("firespread"))
{ {
toggle("Fire spread is", ConfigEntry.ALLOW_FIRE_SPREAD); toggle("Fire spread is", ConfigEntry.ALLOW_FIRE_SPREAD);
plugin.gr.setGameRule(TFM_GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()); plugin.gr.setGameRule(GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean());
return true; return true;
} }

View File

@ -6,7 +6,6 @@ import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import net.pravian.aero.command.AbstractCommandBase; import net.pravian.aero.command.AbstractCommandBase;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -105,16 +104,6 @@ public abstract class FreedomCommand extends AbstractCommandBase<TotalFreedomMod
return plugin.pl.getData(player); return plugin.pl.getData(player);
} }
public Player getPlayer(String partialName, boolean exact)
{
if (exact)
{
return Bukkit.getPlayer(partialName);
}
return super.getPlayer(label);
}
public static FreedomCommand getCommand(Command command) public static FreedomCommand getCommand(Command command)
{ {
try try

View File

@ -1,12 +1,11 @@
package me.totalfreedom.totalfreedommod.commands; package me.totalfreedom.totalfreedommod.commands;
import java.util.Arrays; import java.util.Arrays;
import me.totalfreedom.totalfreedommod.rank.ConsoleRank;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import net.pravian.aero.command.AeroCommandBase; import net.pravian.aero.command.AeroCommandBase;
import net.pravian.aero.command.executor.AbstractCommandExecutor; import net.pravian.aero.command.executor.AbstractCommandExecutor;
import net.pravian.aero.command.executor.AeroCommandExecutor; import net.pravian.aero.command.executor.AeroCommandExecutor;
@ -137,12 +136,11 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
// Console permissions // Console permissions
Rank rank = TotalFreedomMod.plugin.rm.getRank(sender); Rank rank = TotalFreedomMod.plugin.rm.getRank(sender);
boolean result = rank.isAtLeast(ConsoleRank.forRank(perms.level())); boolean result = rank.isAtLeast(perms.level());
if (!result && sendMsg) if (!result && sendMsg)
{ {
sender.sendMessage(handler.getPermissionMessage()); sender.sendMessage(handler.getPermissionMessage());
} }
return result; return result;
} }

View File

@ -1,5 +1,12 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd;
import me.totalfreedom.totalfreedommod.httpd.module.Module_help;
import me.totalfreedom.totalfreedommod.httpd.module.Module_file;
import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic;
import me.totalfreedom.totalfreedommod.httpd.module.Module_permbans;
import me.totalfreedom.totalfreedommod.httpd.module.Module_players;
import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
import me.totalfreedom.totalfreedommod.httpd.module.Module_list;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -887,7 +887,7 @@ public abstract class NanoHTTPD
/** /**
* Handles one session, i.e. parses the HTTP request and returns the response. * Handles one session, i.e. parses the HTTP request and returns the response.
*/ */
protected class HTTPSession public class HTTPSession // TFM - protected -> public
{ {
public static final int BUFSIZE = 8192; public static final int BUFSIZE = 8192;
@ -1004,7 +1004,7 @@ public abstract class NanoHTTPD
} }
} }
protected void parseBody(Map<String, String> files) throws IOException, ResponseException public void parseBody(Map<String, String> files) throws IOException, ResponseException // TFM - protected -> public
{ {
RandomAccessFile randomAccessFile = null; RandomAccessFile randomAccessFile = null;
BufferedReader in = null; BufferedReader in = null;

View File

@ -1,8 +1,9 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.net.Socket; import java.net.Socket;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;

View File

@ -1,9 +1,11 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.list; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.list;
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;

View File

@ -1,4 +1,4 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -13,6 +13,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -1,4 +1,4 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Collection; import java.util.Collection;
@ -10,9 +10,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.commands.FreedomCommand; import me.totalfreedom.totalfreedommod.commands.FreedomCommand;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.heading; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.heading;
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph;
import me.totalfreedom.totalfreedommod.rank.PlayerRank; import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.rank.Rank;
import net.pravian.aero.command.CommandReflection; import net.pravian.aero.command.CommandReflection;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -76,7 +78,7 @@ public class Module_help extends HTTPDModule
responseBody.append(heading(pluginName, 2)).append("<ul>\r\n"); responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
PlayerRank lastTfmCommandLevel = null; Rank lastTfmCommandLevel = null;
for (Command command : commands) for (Command command : commands)
{ {
if (!TotalFreedomMod.pluginName.equals(pluginName)) if (!TotalFreedomMod.pluginName.equals(pluginName))
@ -85,7 +87,7 @@ public class Module_help extends HTTPDModule
continue; continue;
} }
PlayerRank tfmCommandLevel = FreedomCommand.getCommand(command).getPerms().level(); Rank tfmCommandLevel = FreedomCommand.getCommand(command).getPerms().level();
if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel) if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel)
{ {
responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getName(), 3)).append("<ul>\r\n"); responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getName(), 3)).append("<ul>\r\n");

View File

@ -1,7 +1,8 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.util.Collection; import java.util.Collection;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,7 +1,8 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File; import java.io.File;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
public class Module_logs extends Module_file public class Module_logs extends Module_file
{ {

View File

@ -1,7 +1,9 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File; import java.io.File;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
public class Module_permbans extends HTTPDModule public class Module_permbans extends HTTPDModule
{ {

View File

@ -1,8 +1,9 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;

View File

@ -1,4 +1,4 @@
package me.totalfreedom.totalfreedommod.httpd; package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -14,6 +14,10 @@ import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -1,6 +1,10 @@
package me.totalfreedom.totalfreedommod.player; package me.totalfreedom.totalfreedommod.player;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -23,8 +27,7 @@ public class PlayerData implements ConfigLoadable, ConfigSavable, Validatable
@Getter @Getter
@Setter @Setter
private long lastJoinUnix; private long lastJoinUnix;
@Getter private final List<String> ips = Lists.newArrayList();
private final Set<String> ips = Sets.newHashSet();
public PlayerData(Player player) public PlayerData(Player player)
{ {
@ -56,10 +59,15 @@ public class PlayerData implements ConfigLoadable, ConfigSavable, Validatable
cs.set("last_join", lastJoinUnix); cs.set("last_join", lastJoinUnix);
} }
public List<String> getIps()
{
return Collections.unmodifiableList(ips);
}
// IP utils // IP utils
public boolean addIp(String ip) public boolean addIp(String ip)
{ {
return ips.add(ip); return ips.contains(ip) ? false : ips.add(ip);
} }
public boolean removeIp(String ip) public boolean removeIp(String ip)

View File

@ -1,97 +0,0 @@
package me.totalfreedom.totalfreedommod.rank;
import org.bukkit.ChatColor;
public enum ConsoleRank implements Rank
{
TELNET_CONSOLE(PlayerRank.TELNET_ADMIN),
SENIOR_CONSOLE(PlayerRank.SENIOR_ADMIN);
//
private final PlayerRank appliedRank;
//
private ConsoleRank(PlayerRank appliedRank)
{
this.appliedRank = appliedRank;
}
@Override
public String getName()
{
return "Console";
}
@Override
public ChatColor getColor()
{
return ChatColor.DARK_PURPLE;
}
@Override
public String getColorString()
{
return ChatColor.DARK_PURPLE.toString();
}
@Override
public String getColoredName()
{
return getColor() + getName();
}
@Override
public String getTag()
{
return "[Console]";
}
@Override
public String getColoredTag()
{
return getColorString() + getTag();
}
@Override
public String getColoredLoginMessage()
{
return "the " + getColorString() + " Console";
}
@Override
public int getLevel()
{
return ordinal();
}
@Override
public boolean isAtLeast(Rank rank)
{
return getLevel() >= rank.getLevel();
}
public static boolean hasConsole(PlayerRank playerRank)
{
for (ConsoleRank consoleRank : values())
{
if (consoleRank.appliedRank == playerRank)
{
return true;
}
}
return false;
}
public static ConsoleRank forRank(PlayerRank playerRank)
{
for (ConsoleRank consoleRank : values())
{
if (consoleRank.appliedRank == playerRank)
{
return consoleRank;
}
}
return TELNET_CONSOLE;
}
}

View File

@ -5,7 +5,7 @@ public class CustomLoginRank extends RankProxy
private String loginMessage; private String loginMessage;
public CustomLoginRank(PlayerRank rank, String loginMessage) public CustomLoginRank(Rank rank, String loginMessage)
{ {
super(rank); super(rank);
} }

View File

@ -6,30 +6,35 @@ import org.bukkit.ChatColor;
public enum PlayerRank implements Rank public enum PlayerRank implements Rank
{ {
// Order is important here IMPOSTOR(Type.PLAYER, "an", "Imp", ChatColor.YELLOW),
IMPOSTOR(false, "an", "Imp", ChatColor.YELLOW, ChatColor.UNDERLINE), NON_OP(Type.PLAYER, "a", "", ChatColor.GREEN),
NON_OP(false, "a", "", ChatColor.GREEN), OP(Type.PLAYER, "an", "OP", ChatColor.RED),
OP(false, "an", "OP", ChatColor.RED), SUPER_ADMIN(Type.ADMIN, "a", "SA", ChatColor.GOLD),
SUPER_ADMIN(true, "a", "SA", ChatColor.GOLD), TELNET_ADMIN(Type.ADMIN, "a", "StA", ChatColor.DARK_GREEN),
TELNET_ADMIN(true, "a", "StA", ChatColor.DARK_GREEN), SENIOR_ADMIN(Type.ADMIN, "a", "SrA", ChatColor.LIGHT_PURPLE),
SENIOR_ADMIN(true, "a", "SrA", ChatColor.LIGHT_PURPLE); TELNET_CONSOLE(),
SENIOR_CONSOLE();
// //
@Getter @Getter
private final Type type;
@Getter
private final String name; private final String name;
private final String determiner; private final String determiner;
@Getter @Getter
private final String tag; private final String tag;
@Getter @Getter
private final ChatColor color; private final ChatColor color;
@Getter
private final String colorString;
@Getter
private final boolean admin;
private PlayerRank(boolean admin, String determiner, String tag, ChatColor... colors) private PlayerRank()
{ {
this.admin = admin; this("Console", Type.ADMIN_CONSOLE, "the", "Console", ChatColor.DARK_PURPLE);
}
private PlayerRank(Type type, String determiner, String tag, ChatColor color)
{
this.type = type;
// Name
final String[] nameParts = name().toLowerCase().split("_"); final String[] nameParts = name().toLowerCase().split("_");
String tempName = ""; String tempName = "";
for (String part : nameParts) for (String part : nameParts)
@ -41,19 +46,23 @@ public enum PlayerRank implements Rank
this.determiner = determiner; this.determiner = determiner;
this.tag = "[" + tag + "]"; this.tag = "[" + tag + "]";
this.color = colors[0]; // Colors
String tColor = ""; this.color = color;
for (ChatColor lColor : colors)
{
tColor += lColor.toString();
} }
colorString = tColor;
private PlayerRank(String name, Type type, String determiner, String tag, ChatColor color)
{
this.type = type;
this.name = name;
this.determiner = determiner;
this.tag = "[" + tag + "]";
this.color = color;
} }
@Override @Override
public String getColoredName() public String getColoredName()
{ {
return getColorString() + getName(); return getColor() + getName();
} }
@Override @Override
@ -68,9 +77,9 @@ public enum PlayerRank implements Rank
return determiner + " " + getColoredName(); return determiner + " " + getColoredName();
} }
public boolean hasConsole() public boolean isConsole()
{ {
return ConsoleRank.hasConsole(this); return getType() == Type.ADMIN_CONSOLE;
} }
@Override @Override
@ -85,7 +94,47 @@ public enum PlayerRank implements Rank
return getLevel() >= rank.getLevel(); return getLevel() >= rank.getLevel();
} }
public static PlayerRank forString(String string) public boolean isAdmin()
{
return getType() == Type.ADMIN || getType() == Type.ADMIN_CONSOLE;
}
public boolean hasConsole()
{
return getConsoleVariant() != null;
}
public PlayerRank getConsoleVariant()
{
switch (this)
{
case TELNET_ADMIN:
case TELNET_CONSOLE:
return TELNET_CONSOLE;
case SENIOR_ADMIN:
case SENIOR_CONSOLE:
return SENIOR_CONSOLE;
default:
return null;
}
}
public PlayerRank getPlayerVariant()
{
switch (this)
{
case TELNET_ADMIN:
case TELNET_CONSOLE:
return TELNET_ADMIN;
case SENIOR_ADMIN:
case SENIOR_CONSOLE:
return SENIOR_ADMIN;
default:
return null;
}
}
public static PlayerRank findRank(String string)
{ {
try try
{ {
@ -97,4 +146,17 @@ public enum PlayerRank implements Rank
return PlayerRank.NON_OP; return PlayerRank.NON_OP;
} }
public static enum Type
{
PLAYER,
ADMIN,
ADMIN_CONSOLE;
public boolean isAdmin()
{
return this != PLAYER;
}
}
} }

View File

@ -11,8 +11,6 @@ public interface Rank
public ChatColor getColor(); public ChatColor getColor();
public String getColorString();
public String getColoredName(); public String getColoredName();
public String getColoredTag(); public String getColoredTag();

View File

@ -45,46 +45,61 @@ public class RankManager extends AbstractService<TotalFreedomMod>
final Player player = (Player) sender; final Player player = (Player) sender;
// Display impostors
if (plugin.al.isAdminImpostor(player))
{
return PlayerRank.IMPOSTOR;
}
// Developers always show up // Developers always show up
if (FUtil.DEVELOPERS.contains(player.getName())) if (FUtil.DEVELOPERS.contains(player.getName()))
{ {
return TitleRank.DEVELOPER; return TitleRank.DEVELOPER;
} }
final PlayerRank playerRank = getRank((Player) sender); final PlayerRank rank = getRank(player);
final Admin admin = playerRank.isAdmin() ? plugin.al.getAdmin(sender) : null; final Admin admin = rank.isAdmin() ? plugin.al.getAdmin(sender) : null;
// Titles except developer are only for admins // Non-admins don't have titles, display actual rank
if (admin == null) if (admin == null)
{ {
return playerRank; return rank;
} }
// If the player's an owner, display that
if (MainConfig.get(ConfigEntry.SERVER_OWNERS, List.class).contains(player.getName())) if (MainConfig.get(ConfigEntry.SERVER_OWNERS, List.class).contains(player.getName()))
{ {
return TitleRank.OWNER; return TitleRank.OWNER;
} }
final String loginMessage = admin.getLoginMessage(); final String loginMessage = admin.getLoginMessage();
return loginMessage == null ? playerRank : new CustomLoginRank(playerRank, ChatUtils.colorize(loginMessage));
// If we don't have a custom login message, use the actual rank
if (loginMessage == null)
{
return rank;
} }
public Rank getRank(CommandSender sender) return new CustomLoginRank(rank, ChatUtils.colorize(loginMessage));
}
public PlayerRank getRank(CommandSender sender)
{ {
if (sender instanceof Player) if (sender instanceof Player)
{ {
return getRank((Player) sender); return getRank((Player) sender);
} }
// Console admin, get by name
Admin admin = plugin.al.getEntryByName(sender.getName()); Admin admin = plugin.al.getEntryByName(sender.getName());
// Unknown console: RCON, CONSOLE?
if (admin == null) if (admin == null)
{ // Unknown console, RCon, CONSOLE? {
return ConsoleRank.SENIOR_CONSOLE; return PlayerRank.SENIOR_CONSOLE;
} }
return ConsoleRank.forRank(admin.getRank()); return admin.getRank();
} }
public PlayerRank getRank(Player player) public PlayerRank getRank(Player player)
@ -107,17 +122,17 @@ public class RankManager extends AbstractService<TotalFreedomMod>
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerJoin(PlayerJoinEvent event)
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final PlayerData data = plugin.pl.getData(player); //plugin.pl.getData(player);
final FPlayer fPlayer = plugin.pl.getPlayer(player); final FPlayer fPlayer = plugin.pl.getPlayer(player);
// Unban admins // Unban admins
boolean isAdmin = plugin.al.isAdmin(player); boolean isAdmin = plugin.al.isAdmin(player);
fPlayer.setSuperadminIdVerified(false);
if (isAdmin) if (isAdmin)
{ {
// Verify strict IP match // Verify strict IP match
if (!plugin.al.isIdentityMatched(player)) if (!plugin.al.isIdentityMatched(player))
{ {
fPlayer.setSuperadminIdVerified(false);
FUtil.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED); FUtil.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED);
} }
else else
@ -146,8 +161,8 @@ public class RankManager extends AbstractService<TotalFreedomMod>
plugin.pl.getPlayer(player).setTag(display.getColoredTag()); plugin.pl.getPlayer(player).setTag(display.getColoredTag());
try try
{ {
String displayName = display.getColorString() + player.getName(); String displayName = display.getColor() + player.getName();
player.setPlayerListName(displayName.substring(0, 16)); player.setPlayerListName(displayName.substring(0, Math.min(displayName.length(), 16)));
} }
catch (IllegalArgumentException ex) catch (IllegalArgumentException ex)
{ {

View File

@ -32,12 +32,6 @@ public abstract class RankProxy implements Rank
return proxy.getColor(); return proxy.getColor();
} }
@Override
public String getColorString()
{
return proxy.getColorString();
}
@Override @Override
public String getColoredName() public String getColoredName()
{ {
@ -59,7 +53,7 @@ public abstract class RankProxy implements Rank
@Override @Override
public boolean isAtLeast(Rank rank) public boolean isAtLeast(Rank rank)
{ {
return rank.isAtLeast(rank); return proxy.isAtLeast(rank);
} }
@Override @Override

View File

@ -1,7 +1,5 @@
package me.totalfreedom.totalfreedommod.util; package me.totalfreedom.totalfreedommod.util;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -60,7 +58,7 @@ public class FUtil
private static final Map<String, Integer> ejectTracker = new HashMap<String, Integer>(); private static final Map<String, Integer> ejectTracker = new HashMap<String, Integer>();
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>(); public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
// See https://github.com/TotalFreedom/License - None of the listed names may be removed. // See https://github.com/TotalFreedom/License - None of the listed names may be removed.
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "DarthSalmon", "AcidicCyanide", "Wild1145", "WickedGamingUK"); public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "Wild1145", "WickedGamingUK");
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<String, ChatColor>(); public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<String, ChatColor>();