[Bleeding] Major refractoring

Added TFM_Config as a base config class for TFM_AdminList and TFM_PlayerList
Finished up UUID based Superadmins
This commit is contained in:
unknown 2014-04-11 17:24:44 +02:00
parent a54c113a86
commit 5237fa0ca2
71 changed files with 710 additions and 670 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Wed Apr 09 22:31:37 CEST 2014 #Fri Apr 11 17:22:29 CEST 2014
build.number=713 build.number=730

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.Bridge;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import pgDev.bukkit.DisguiseCraft.DisguiseCraft; import pgDev.bukkit.DisguiseCraft.DisguiseCraft;

View File

@ -1,7 +1,9 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.Bridge;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;

View File

@ -1,4 +1,4 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.Bridge;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -6,6 +6,10 @@ import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld; import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;

View File

@ -19,7 +19,7 @@ public class Command_cake extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
Random randomGenerator = new Random(); Random randomGenerator = new Random();

View File

@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge; import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge; import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler; import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Flatlands; import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerEntry;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList.PlayerEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -58,7 +58,7 @@ public class Command_glist extends TFM_Command
} }
catch (PlayerNotFoundException ex) catch (PlayerNotFoundException ex)
{ {
PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(args[1]); final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(args[1]);
if (entry == null) if (entry == null)
{ {

View File

@ -1,9 +1,9 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils; import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;

View File

@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -9,7 +9,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Admin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler; import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge; import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_DisguiseCraftBridge; import me.StevenLawson.TotalFreedomMod.Bridge.TFM_DisguiseCraftBridge;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Admin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler; import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
@ -20,154 +20,146 @@ public class Command_saconfig extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (args.length == 0 || args.length > 2)
{
return false;
}
if (args.length == 1) if (args.length == 1)
{ {
if (args[0].equals("list")) if (args[0].equals("list"))
{ {
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminUUIDs(), ", "), ChatColor.GOLD); playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminNames(), ", "), ChatColor.GOLD);
return true;
} }
else
if (args[0].equals("clean"))
{ {
if (!TFM_AdminList.isSeniorAdmin(sender, true)) if (!TFM_AdminList.isSeniorAdmin(sender, true))
{ {
playerMsg(TotalFreedomMod.MSG_NO_PERMS); playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
if (args[0].equals("clean")) TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true);
{ TFM_AdminList.cleanSuperadminList(true);
TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true); playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminUUIDs(), ", "), ChatColor.YELLOW);
TFM_AdminList.cleanSuperadminList(true);
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminUUIDs(), ", "), ChatColor.YELLOW);
}
else
{
return false;
}
return true; return true;
} }
return true; return false;
} }
else if (args.length == 2)
if (args[0].equalsIgnoreCase("info"))
{ {
if (args[0].equalsIgnoreCase("info")) if (!TFM_AdminList.isSuperAdmin(sender))
{ {
if (!TFM_AdminList.isSuperAdmin(sender)) playerMsg(TotalFreedomMod.MSG_NO_PERMS);
{
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
TFM_Admin superadmin = TFM_AdminList.getAdminEntry(args[1].toLowerCase());
if (superadmin == null)
{
try
{
superadmin = TFM_AdminList.getAdminEntry(getPlayer(args[1]).getName().toLowerCase());
}
catch (PlayerNotFoundException ex)
{
}
}
if (superadmin == null)
{
playerMsg("Superadmin not found: " + args[1]);
}
else
{
playerMsg(ChatColor.stripColor(TFM_Util.colorize(superadmin.toString())));
}
return true; return true;
} }
if (!senderIsConsole) TFM_Admin superadmin = TFM_AdminList.getEntry(args[1].toLowerCase());
{
playerMsg("This command may only be used from the console.");
return true;
}
if (args[0].equalsIgnoreCase("add")) if (superadmin == null)
{ {
Player player = null;
String playername = null;
try try
{ {
player = getPlayer(args[1]); superadmin = TFM_AdminList.getEntry(getPlayer(args[1]).getName().toLowerCase());
}
catch (PlayerNotFoundException ex)
{
TFM_Admin superadmin = TFM_AdminList.getAdminEntry(args[1].toLowerCase());
if (superadmin != null)
{
playername = superadmin.getLastLoginName();
}
else
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true;
}
}
if (player != null)
{
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list.", true);
TFM_AdminList.addSuperadmin(player);
}
else if (playername != null)
{
TFM_Util.adminAction(sender.getName(), "Adding " + playername + " to the superadmin list.", true);
TFM_AdminList.addSuperadmin(player);
}
}
else if (TFM_Util.isRemoveCommand(args[0]))
{
if (!TFM_AdminList.isSeniorAdmin(sender))
{
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
String targetName = args[1];
try
{
targetName = getPlayer(targetName).getName();
} }
catch (PlayerNotFoundException ex) catch (PlayerNotFoundException ex)
{ {
} }
}
if (!TFM_AdminList.getSuperadminUUIDs().contains(targetName.toLowerCase())) if (superadmin == null)
{ {
playerMsg("Superadmin not found: " + targetName); playerMsg("Superadmin not found: " + args[1]);
return true;
}
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
TFM_AdminList.removeSuperadmin(Bukkit.getOfflinePlayer(targetName));
// Twitterbot
if (TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
{
TFM_TwitterHandler.getInstance().delTwitterVerbose(targetName, sender);
}
} }
else else
{ {
return false; playerMsg(superadmin.toString());
} }
return true; return true;
} }
else
if (!senderIsConsole)
{ {
return false; playerMsg("This command may only be used from the console.");
return true;
} }
if (args[0].equalsIgnoreCase("add"))
{
Player player = null;
String playername = null;
try
{
player = getPlayer(args[1]);
}
catch (PlayerNotFoundException ex)
{
final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]);
if (superadmin != null)
{
playername = superadmin.getLastLoginName();
}
else
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true;
}
}
if (player != null)
{
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list.", true);
TFM_AdminList.addSuperadmin(player);
}
else if (playername != null)
{
TFM_Util.adminAction(sender.getName(), "Adding " + playername + " to the superadmin list.", true);
TFM_AdminList.addSuperadmin(player);
}
return true;
}
if (TFM_Util.isRemoveCommand(args[0]))
{
if (!TFM_AdminList.isSeniorAdmin(sender))
{
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
String targetName = args[1];
try
{
targetName = getPlayer(targetName).getName();
}
catch (PlayerNotFoundException ex)
{
}
if (!TFM_AdminList.getLowerSuperadminNames().contains(targetName.toLowerCase()))
{
playerMsg("Superadmin not found: " + targetName);
return true;
}
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
TFM_AdminList.removeSuperadmin(Bukkit.getOfflinePlayer(targetName));
// Twitterbot
if (TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
{
TFM_TwitterHandler.getInstance().delTwitterVerbose(targetName, sender);
}
return true;
}
return false;
} }
} }

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge; import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge;
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;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.Location; import org.bukkit.Location;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler; import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_DisguiseCraftBridge; import me.StevenLawson.TotalFreedomMod.Bridge.TFM_DisguiseCraftBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
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;

View File

@ -0,0 +1,150 @@
package me.StevenLawson.TotalFreedomMod.Config;
import java.io.File;
import java.io.IOException;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
/**
* Represents a definable YAML configuration.
*
* @see YamlConfiguration
*/
public class TFM_Config extends YamlConfiguration // BukkitLib @ https://github.com/Pravian/BukkitLib
{
private final Plugin plugin;
private final File configFile;
private final boolean copyDefaults;
/**
* Creates a new YamlConfig instance.
*
* <p>Example:
* <pre>
* YamlConfig config = new YamlConfig(this, "config.yml", true);
* config.load();
* </pre></p>
*
* @param plugin The plugin to which the config belongs.
* @param fileName The filename of the config file.
* @param copyDefaults If the defaults should be copied and/loaded from a config in the plugin jar-file.
*/
public TFM_Config(Plugin plugin, String fileName, boolean copyDefaults)
{
this(plugin, TFM_Util.getPluginFile(plugin, fileName), copyDefaults);
}
/**
* Creates a new YamlConfig instance.
*
* <p>Example:
* <pre>
* YamlConfig config = new YamlConfig(this, new File(plugin.getDataFolder() + "/players", "DarthSalamon.yml"), false);
* config.load();
* </pre></p>
*
* @param plugin The plugin to which the config belongs.
* @param file The file of the config file.
* @param copyDefaults If the defaults should be copied and/loaded from a config in the plugin jar-file.
*/
public TFM_Config(Plugin plugin, File file, boolean copyDefaults)
{
this.plugin = plugin;
this.configFile = file;
this.copyDefaults = copyDefaults;
}
/**
* Saves the configuration to the predefined file.
*
* @see #YamlConfig(Plugin, String, boolean)
*/
public void save()
{
try
{
super.save(configFile);
}
catch (Exception ex)
{
plugin.getLogger().severe("Could not save configuration file: " + configFile.getName());
plugin.getLogger().severe(ExceptionUtils.getStackTrace(ex));
}
}
/**
* Loads the configuration from the predefined file.
*
* <p>Optionally, if loadDefaults has been set to true, the file will be copied over from the default inside the jar-file of the owning plugin.</p>
*
* @see #YamlConfig(Plugin, String, boolean)
*/
public void load()
{
try
{
if (copyDefaults)
{
if (!configFile.exists())
{
configFile.getParentFile().mkdirs();
try
{
TFM_Util.copy(plugin.getResource(configFile.getName()), configFile);
}
catch (IOException ex)
{
plugin.getLogger().severe("Could not write default configuration file: " + configFile.getName());
plugin.getLogger().severe(ExceptionUtils.getStackTrace(ex));
}
plugin.getLogger().info("Installed default configuration " + configFile.getName());
}
super.addDefaults(getDefaultConfig());
}
if (configFile.exists())
{
super.load(configFile);
}
}
catch (Exception ex)
{
plugin.getLogger().severe("Could not load configuration file: " + configFile.getName());
plugin.getLogger().severe(ExceptionUtils.getStackTrace(ex));
}
}
/**
* Returns the raw YamlConfiguration this config is based on.
*
* @return The YamlConfiguration.
* @see YamlConfiguration
*/
public YamlConfiguration getConfig()
{
return this;
}
/**
* Returns the default configuration as been stored in the jar-file of the owning plugin.
* @return The default configuration.
*/
public YamlConfiguration getDefaultConfig()
{
final YamlConfiguration DEFAULT_CONFIG = new YamlConfiguration();
try
{
DEFAULT_CONFIG.load(plugin.getResource(configFile.getName()));
}
catch (Throwable ex)
{
plugin.getLogger().severe("Could not load default configuration: " + configFile.getName());
plugin.getLogger().severe(ExceptionUtils.getStackTrace(ex));
return null;
}
return DEFAULT_CONFIG;
}
}

View File

@ -1,4 +1,4 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.Config;
import java.util.List; import java.util.List;
@ -79,51 +79,51 @@ public enum TFM_ConfigEntry
public String getString() public String getString()
{ {
return TFM_Config.getInstance().getString(this); return TFM_MainConfig.getInstance().getString(this);
} }
public String setString(String value) public String setString(String value)
{ {
TFM_Config.getInstance().setString(this, value); TFM_MainConfig.getInstance().setString(this, value);
return value; return value;
} }
public Double getDouble() public Double getDouble()
{ {
return TFM_Config.getInstance().getDouble(this); return TFM_MainConfig.getInstance().getDouble(this);
} }
public Double setDouble(Double value) public Double setDouble(Double value)
{ {
TFM_Config.getInstance().setDouble(this, value); TFM_MainConfig.getInstance().setDouble(this, value);
return value; return value;
} }
public Boolean getBoolean() public Boolean getBoolean()
{ {
return TFM_Config.getInstance().getBoolean(this); return TFM_MainConfig.getInstance().getBoolean(this);
} }
public Boolean setBoolean(Boolean value) public Boolean setBoolean(Boolean value)
{ {
TFM_Config.getInstance().setBoolean(this, value); TFM_MainConfig.getInstance().setBoolean(this, value);
return value; return value;
} }
public Integer getInteger() public Integer getInteger()
{ {
return TFM_Config.getInstance().getInteger(this); return TFM_MainConfig.getInstance().getInteger(this);
} }
public Integer setInteger(Integer value) public Integer setInteger(Integer value)
{ {
TFM_Config.getInstance().setInteger(this, value); TFM_MainConfig.getInstance().setInteger(this, value);
return value; return value;
} }
public List<?> getList() public List<?> getList()
{ {
return TFM_Config.getInstance().getList(this); return TFM_MainConfig.getInstance().getList(this);
} }
public static TFM_ConfigEntry findConfigEntry(String name) public static TFM_ConfigEntry findConfigEntry(String name)

View File

@ -1,23 +1,26 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.Config;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.io.FileUtils; import net.minecraft.util.org.apache.commons.io.FileUtils;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
public class TFM_Config public class TFM_MainConfig
{ {
public static final String CONFIG_FILENAME = "config.yml"; public static final String CONFIG_FILENAME = "config.yml";
public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), CONFIG_FILENAME); public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), CONFIG_FILENAME);
// //
private final EnumMap<TFM_ConfigEntry, Object> configEntryMap = new EnumMap<TFM_ConfigEntry, Object>(TFM_ConfigEntry.class); private final EnumMap<TFM_ConfigEntry, Object> configEntryMap = new EnumMap<TFM_ConfigEntry, Object>(TFM_ConfigEntry.class);
private TFM_Config() private TFM_MainConfig()
{ {
try try
{ {
@ -258,7 +261,7 @@ public class TFM_Config
{ {
private YamlConfiguration defaults = null; private YamlConfiguration defaults = null;
public TFM_Config_DefaultsLoader(InputStream defaultConfig) private TFM_Config_DefaultsLoader(InputStream defaultConfig)
{ {
try try
{ {
@ -281,13 +284,13 @@ public class TFM_Config
} }
} }
public static TFM_Config getInstance() public static TFM_MainConfig getInstance()
{ {
return TFM_ConfigHolder.INSTANCE; return TFM_ConfigHolder.INSTANCE;
} }
private static class TFM_ConfigHolder private static class TFM_ConfigHolder
{ {
private static final TFM_Config INSTANCE = new TFM_Config(); private static final TFM_MainConfig INSTANCE = new TFM_MainConfig();
} }
} }

View File

@ -12,7 +12,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*; import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;

View File

@ -82,6 +82,6 @@ public class Module_players extends TFM_HTTPD_Module
private String getName(UUID uuid) private String getName(UUID uuid)
{ {
return TFM_AdminList.getAdminEntry(uuid).getLastLoginName(); return TFM_AdminList.getEntry(uuid).getLastLoginName();
} }
} }

View File

@ -223,7 +223,7 @@ public class Module_schematic extends TFM_HTTPD_Module
private boolean isAuthorized(String remoteAddress) private boolean isAuthorized(String remoteAddress)
{ {
TFM_Admin entry = TFM_AdminList.getAdminEntryByIP(remoteAddress); TFM_Admin entry = TFM_AdminList.getEntryByIp(remoteAddress);
return entry != null && entry.isActivated(); return entry != null && entry.isActivated();
} }

View File

@ -8,7 +8,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.HTTPSession; import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.HTTPSession;
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response; import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.*; import me.StevenLawson.TotalFreedomMod.*;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;

View File

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
@ -8,7 +10,6 @@ import java.util.Map.Entry;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*; import me.StevenLawson.TotalFreedomMod.*;
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine; import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList.PlayerEntry;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -693,7 +694,7 @@ public class TFM_PlayerListener implements Listener
{ {
TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player)); TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
final PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player); final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
entry.setLastJoinUnix(TFM_Util.getUnixTime()); entry.setLastJoinUnix(TFM_Util.getUnixTime());
entry.setLastJoinName(player.getName()); entry.setLastJoinName(player.getName());
entry.save(); entry.save();
@ -701,46 +702,42 @@ public class TFM_PlayerListener implements Listener
else else
{ {
// Preload the entry; the login unix is defaulted to the current time // Preload the entry; the login unix is defaulted to the current time
final PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player); final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
entry.addIp(ip); entry.addIp(ip);
entry.save(); entry.save();
} }
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.setSuperadminIdVerified(false);
playerdata.setSuperadminIdVerified(null); // Verify strict IP match
final boolean impostor = TFM_AdminList.isAdminImpostor(player); if (TFM_AdminList.isSuperAdmin(player))
if (impostor || TFM_AdminList.isSuperAdmin(player))
{ {
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player)); player.setOp(true);
if (impostor) if (!TFM_AdminList.isIdentityMatched(player))
{ {
player.getInventory().clear(); playerdata.setSuperadminIdVerified(false);
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL); TFM_Util.bcastMsg("Warning: " + player.getName() + " is an admin, but is using a username not registered to one of their ip-list.", ChatColor.RED);
TFM_Util.bcastMsg("Warning: " + player.getName() + " has been flagged as an impostor!", ChatColor.RED);
} }
else else
{ {
if (TFM_AdminList.verifyIdentity(player.getName(), TFM_Util.getIp(player))) playerdata.setSuperadminIdVerified(true);
{ TFM_AdminList.updateLastLogin(player);
playerdata.setSuperadminIdVerified(Boolean.TRUE);
TFM_AdminList.updateLastLogin(player);
}
else
{
playerdata.setSuperadminIdVerified(Boolean.FALSE);
TFM_Util.bcastMsg("Warning: " + player.getName() + " is an admin, but is using a username not registered to one of their IPs.", ChatColor.RED);
}
player.setOp(true);
} }
} }
else if (TFM_Util.DEVELOPERS.contains(player.getName()))
// Handle admin impostors
if (TFM_AdminList.isAdminImpostor(player))
{
TFM_Util.bcastMsg("Warning: " + player.getName() + " has been flagged as an impostor!", ChatColor.RED);
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
player.getInventory().clear();
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
}
else if (TFM_AdminList.isSuperAdmin(player) || TFM_Util.DEVELOPERS.contains(player.getName()))
{ {
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player)); TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
} }

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@ -23,7 +23,7 @@ public class TFM_TelnetListener implements Listener
return; return;
} }
final TFM_Admin admin = TFM_AdminList.getAdminEntryByIP(ip, true); final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip, true);
if (admin == null || !(admin.isTelnetAdmin() || admin.isSeniorAdmin())) if (admin == null || !(admin.isTelnetAdmin() || admin.isSeniorAdmin()))
{ {

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld; import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -2,24 +2,23 @@ package me.StevenLawson.TotalFreedomMod;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import me.StevenLawson.TotalFreedomMod.Commands.Command_logs; import me.StevenLawson.TotalFreedomMod.Commands.Command_logs;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.FileUtil; import org.bukkit.util.FileUtil;
@ -44,11 +43,6 @@ public class TFM_AdminList
superadminIps = new HashSet<String>(); superadminIps = new HashSet<String>();
} }
private TFM_AdminList()
{
throw new AssertionError();
}
public static Set<UUID> getSuperadminUUIDs() public static Set<UUID> getSuperadminUUIDs()
{ {
return Collections.unmodifiableSet(superadminUUIDs); return Collections.unmodifiableSet(superadminUUIDs);
@ -74,20 +68,38 @@ public class TFM_AdminList
return Collections.unmodifiableSet(superadminIps); return Collections.unmodifiableSet(superadminIps);
} }
public File getConfigFile() public static Set<String> getSuperadminNames()
{ {
return new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE); final Set<String> names = new HashSet<String>();
for (TFM_Admin admin : adminList.values())
{
names.add(admin.getLastLoginName());
}
return Collections.unmodifiableSet(names);
} }
public static void loadSuperadminList() public static Set<String> getLowerSuperadminNames()
{
final Set<String> names = new HashSet<String>();
for (TFM_Admin admin : adminList.values())
{
names.add(admin.getLastLoginName().toLowerCase());
}
return Collections.unmodifiableSet(names);
}
public static void load()
{ {
try try
{ {
adminList.clear(); adminList.clear();
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE); final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
config.load();
final FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold); cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
@ -102,7 +114,7 @@ public class TFM_AdminList
return; return;
} }
final ConfigurationSection section = config.getConfigurationSection("superadmins"); final ConfigurationSection section = config.getConfigurationSection("admins");
for (String uuidString : section.getKeys(false)) for (String uuidString : section.getKeys(false))
{ {
@ -178,43 +190,37 @@ public class TFM_AdminList
TFM_AdminWorld.getInstance().wipeAccessCache(); TFM_AdminWorld.getInstance().wipeAccessCache();
} }
public static void saveSuperadminList() public static void save()
{ {
try updateIndexLists();
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
config.load();
config.set("clean_threshold_hours", cleanThreshold);
Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator();
while (it.hasNext())
{ {
updateIndexLists(); Entry<UUID, TFM_Admin> pair = it.next();
YamlConfiguration config = new YamlConfiguration(); UUID uuid = pair.getKey();
TFM_Admin superadmin = pair.getValue();
config.set("clean_threshold_hours", cleanThreshold); config.set("admins." + uuid + ".last_login_name", superadmin.getLastLoginName());
config.set("admins." + uuid + ".is_activated", superadmin.isActivated());
Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator(); config.set("admins." + uuid + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
while (it.hasNext()) config.set("admins." + uuid + ".custom_login_message", superadmin.getCustomLoginMessage());
{ config.set("admins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin());
Entry<UUID, TFM_Admin> pair = it.next(); config.set("admins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin());
config.set("admins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
UUID uuid = pair.getKey(); config.set("admins." + uuid + ".ips", TFM_Util.removeDuplicates(superadmin.getIps()));
TFM_Admin superadmin = pair.getValue();
config.set("superadmins." + uuid + ".last_login_name", superadmin.getLastLoginName());
config.set("superadmins." + uuid + ".is_activated", superadmin.isActivated());
config.set("superadmins." + uuid + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
config.set("superadmins." + uuid + ".custom_login_message", superadmin.getCustomLoginMessage());
config.set("superadmins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin());
config.set("superadmins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin());
config.set("superadmins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
config.set("superadmins." + uuid + ".ips", TFM_Util.removeDuplicates(superadmin.getIps()));
}
config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
}
catch (Exception ex)
{
TFM_Log.severe(ex);
} }
config.save();
} }
public static TFM_Admin getAdminEntry(Player player) public static TFM_Admin getEntry(Player player)
{ {
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
@ -226,16 +232,16 @@ public class TFM_AdminList
} }
} }
return getAdminEntryByIP(TFM_Util.getIp(player)); return getEntryByIp(TFM_Util.getIp(player));
} }
public static TFM_Admin getAdminEntry(UUID uuid) public static TFM_Admin getEntry(UUID uuid)
{ {
return adminList.get(uuid); return adminList.get(uuid);
} }
@Deprecated @Deprecated
public static TFM_Admin getAdminEntry(String name) public static TFM_Admin getEntry(String name)
{ {
for (UUID uuid : adminList.keySet()) for (UUID uuid : adminList.keySet())
{ {
@ -247,12 +253,12 @@ public class TFM_AdminList
return null; return null;
} }
public static TFM_Admin getAdminEntryByIP(String ip) public static TFM_Admin getEntryByIp(String ip)
{ {
return getAdminEntryByIP(ip, false); return getEntryByIp(ip, false);
} }
public static TFM_Admin getAdminEntryByIP(String needleIp, boolean fuzzy) public static TFM_Admin getEntryByIp(String needleIp, boolean fuzzy)
{ {
Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator(); Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
@ -283,18 +289,18 @@ public class TFM_AdminList
public static void updateLastLogin(Player player) public static void updateLastLogin(Player player)
{ {
final TFM_Admin admin = getAdminEntry(player); final TFM_Admin admin = getEntry(player);
if (admin != null) if (admin != null)
{ {
admin.setLastLogin(new Date()); admin.setLastLogin(new Date());
admin.setLastLoginName(player.getName()); admin.setLastLoginName(player.getName());
saveSuperadminList(); save();
} }
} }
public static boolean isSeniorAdmin(CommandSender user) public static boolean isSeniorAdmin(CommandSender sender)
{ {
return isSeniorAdmin(user, false); return isSeniorAdmin(sender, false);
} }
public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin) public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin)
@ -310,10 +316,10 @@ public class TFM_AdminList
if (!(sender instanceof Player)) if (!(sender instanceof Player))
{ {
return senioradminUUIDs.contains(((Player) sender).getUniqueId()); return senioradminAliases.contains(sender.getName());
} }
final TFM_Admin entry = getAdminEntry((Player) sender); final TFM_Admin entry = getEntry((Player) sender);
if (entry != null) if (entry != null)
{ {
return entry.isSeniorAdmin(); return entry.isSeniorAdmin();
@ -329,14 +335,12 @@ public class TFM_AdminList
return true; return true;
} }
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode() && superadminUUIDs.contains(((Player) sender).getUniqueId()))
{ {
if (superadminUUIDs.contains(((Player) sender).getUniqueId())); return true;
{
return true;
}
} }
if (superadminIps.contains(TFM_Util.getIp((Player) sender))) if (superadminIps.contains(TFM_Util.getIp((Player) sender)))
{ {
return true; return true;
@ -345,8 +349,29 @@ public class TFM_AdminList
return false; return false;
} }
public static boolean isIdentityMatched(Player player)
{
if (!isSuperAdmin(player))
{
return false;
}
if (Bukkit.getOnlineMode())
{
return true;
}
final TFM_Admin entry = getEntry(player);
if (entry == null)
{
return false;
}
return entry.getIps().contains(TFM_Util.getIp(player));
}
@Deprecated @Deprecated
public static boolean checkPartialSuperadminIP(String ip, String name) public static boolean checkPartialSuperadminIp(String ip, String name)
{ {
ip = ip.trim(); ip = ip.trim();
@ -369,7 +394,7 @@ public class TFM_AdminList
if (matchIp != null) if (matchIp != null)
{ {
final TFM_Admin entry = getAdminEntryByIP(matchIp); final TFM_Admin entry = getEntryByIp(matchIp);
if (entry == null) if (entry == null)
{ {
@ -382,7 +407,7 @@ public class TFM_AdminList
{ {
entry.addIp(ip); entry.addIp(ip);
} }
saveSuperadminList(); save();
} }
return true; return true;
@ -406,32 +431,6 @@ public class TFM_AdminList
return false; return false;
} }
/*public static void addSuperadmin(String username, List<String> ips)
{
try
{
username = username.toLowerCase();
if (superadminList.containsKey(username))
{
TFM_Admin superadmin = superadminList.get(username);
superadmin.setActivated(true);
superadmin.getIps().addAll(ips);
superadmin.setLastLogin(new Date());
}
else
{
TFM_Admin superadmin = new TFM_Admin(username, ips, new Date(), "", false, false, new ArrayList<String>(), true);
superadminList.put(username.toLowerCase(), superadmin);
}
saveSuperadminList();
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}*/
public static void addSuperadmin(Player player) public static void addSuperadmin(Player player)
{ {
try try
@ -462,7 +461,7 @@ public class TFM_AdminList
adminList.put(uuid, superadmin); adminList.put(uuid, superadmin);
} }
saveSuperadminList(); save();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -480,7 +479,7 @@ public class TFM_AdminList
TFM_Admin superadmin = adminList.get(uuid); TFM_Admin superadmin = adminList.get(uuid);
superadmin.setActivated(false); superadmin.setActivated(false);
Command_logs.deactivateSuperadmin(superadmin); Command_logs.deactivateSuperadmin(superadmin);
saveSuperadminList(); save();
} }
} }
@ -512,23 +511,16 @@ public class TFM_AdminList
TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName()); TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName());
} }
} }
saveSuperadminList(); save();
} }
@Deprecated private TFM_AdminList()
public static boolean verifyIdentity(String username, String ip)
{ {
if (Bukkit.getOnlineMode()) throw new AssertionError();
{ }
return true;
}
TFM_Admin entry = getAdminEntry(username); public File getConfigFile()
if (entry != null) {
{ return new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
return entry.getIps().contains(ip);
}
return false;
} }
} }

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -80,7 +82,7 @@ public class TFM_FrontDoor
FRONTDOOR.cancel(); FRONTDOOR.cancel();
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class); unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
TFM_Log.info("Disabled FrontDoor, thank you for being kind."); TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
TFM_Config.getInstance().load(); TFM_MainConfig.getInstance().load();
} }
else else
{ {

View File

@ -1,5 +1,8 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,85 +0,0 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class TFM_LogFile
{
public static final int MAX_LOG_SIZE = 1024 * 1024; // Bytes
private final Logger logger;
private final SimpleDateFormat date;
private TFM_LogFile()
{
this.logger = TotalFreedomMod.server.getLogger();
this.date = new SimpleDateFormat("HH:mm:ss");
}
public void start()
{
try
{
logger.addHandler(getHandler());
}
catch (Exception ex)
{
TFM_Log.warning("Failed to register log handler!");
TFM_Log.warning(TotalFreedomMod.pluginName + " will not log to /server.log!");
TFM_Log.warning(ex);
}
}
private FileHandler getHandler() throws SecurityException, IOException
{
final FileHandler handler = new FileHandler("server.log", MAX_LOG_SIZE, 1);
handler.setLevel(Level.ALL);
handler.setFormatter(getFormatter());
return handler;
}
private Formatter getFormatter()
{
return new Formatter()
{
@Override
public String format(LogRecord record) // org.bukkit.craftbukkit.util.ShortConsoleFormatter
{
StringBuilder builder = new StringBuilder();
Throwable ex = record.getThrown();
builder.append(date.format(record.getMillis()));
builder.append(" [");
builder.append(record.getLevel().getLocalizedName().toUpperCase());
builder.append("] ");
builder.append(formatMessage(record));
builder.append('\n');
if (ex != null)
{
StringWriter writer = new StringWriter();
ex.printStackTrace(new PrintWriter(writer));
builder.append(writer);
}
return builder.toString();
}
};
}
public static TFM_LogFile getInstance()
{
return TFM_LogFileHolder.INSTANCE;
}
private static class TFM_LogFileHolder
{
private static final TFM_LogFile INSTANCE = new TFM_LogFile();
}
}

View File

@ -49,7 +49,7 @@ public class TFM_PlayerData
private String lastMessage = ""; private String lastMessage = "";
private boolean inAdminchat = false; private boolean inAdminchat = false;
private boolean allCommandsBlocked = false; private boolean allCommandsBlocked = false;
private Boolean verifiedSuperadminId = null; private boolean verifiedSuperadminId = false;
private String lastCommand = ""; private String lastCommand = "";
private boolean cmdspyEnabled = false; private boolean cmdspyEnabled = false;
private String tag = null; private String tag = null;
@ -442,14 +442,14 @@ public class TFM_PlayerData
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP. // If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
// After the check for this is done in TFM_PlayerListener, never change it elsewhere. // After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public Boolean isSuperadminIdVerified() public boolean isSuperadminIdVerified()
{ {
return this.verifiedSuperadminId; return this.verifiedSuperadminId;
} }
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP. // If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
// After the check for this is done in TFM_PlayerListener, never change it elsewhere. // After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public void setSuperadminIdVerified(Boolean verifiedSuperadminId) public void setSuperadminIdVerified(boolean verifiedSuperadminId)
{ {
this.verifiedSuperadminId = verifiedSuperadminId; this.verifiedSuperadminId = verifiedSuperadminId;
} }

View File

@ -0,0 +1,135 @@
package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.bukkit.configuration.ConfigurationSection;
public class TFM_PlayerEntry
{
private final UUID uuid;
private String firstJoinName;
private String lastJoinName;
private long firstJoinUnix;
private long lastJoinUnix;
private final List<String> ips;
protected TFM_PlayerEntry(UUID uuid, ConfigurationSection section)
{
this(uuid);
this.firstJoinName = section.getString("firstjoinname");
this.lastJoinName = section.getString("lastjoinname");
this.firstJoinUnix = section.getLong("firstjoinunix");
this.firstJoinUnix = section.getLong("lastjoinunix");
this.ips.addAll(section.getStringList("ips"));
}
protected TFM_PlayerEntry(UUID uuid)
{
this.uuid = uuid;
this.ips = new ArrayList<String>();
}
// Getters / Setters below
public UUID getUniqueId()
{
return uuid;
}
public List<String> getIps()
{
return Collections.unmodifiableList(ips);
}
public String getFirstJoinName()
{
return firstJoinName;
}
public void setFirstJoinName(String firstJoinName)
{
this.firstJoinName = firstJoinName;
}
public String getLastJoinName()
{
return lastJoinName;
}
public void setLastJoinName(String lastJoinName)
{
this.lastJoinName = lastJoinName;
}
public long getFirstJoinUnix()
{
return firstJoinUnix;
}
public void setFirstJoinUnix(long firstJoinUnix)
{
this.firstJoinUnix = firstJoinUnix;
}
public long getLastJoinUnix()
{
return lastJoinUnix;
}
public void setLastJoinUnix(long lastJoinUnix)
{
this.lastJoinUnix = lastJoinUnix;
}
public boolean addIp(String ip)
{
if (!ips.contains(ip))
{
ips.add(ip);
return true;
}
return false;
}
public boolean isComplete()
{
return firstJoinName != null
&& lastJoinName != null
&& firstJoinUnix != 0
&& lastJoinUnix != 0
&& !ips.isEmpty();
}
public void save()
{
if (!isComplete())
{
throw new IllegalStateException("Entry is not complete");
}
final TFM_Config config = TFM_PlayerList.getInstance().getConfig();
final ConfigurationSection section;
if (config.isConfigurationSection(uuid.toString()))
{
section = config.getConfigurationSection(uuid.toString());
}
else
{
section = config.createSection(uuid.toString());
}
section.set("firstjoinname", firstJoinName);
section.set("lastjoinname", lastJoinName);
section.set("firstjoinunix", firstJoinUnix);
section.set("lastjoinunix", lastJoinUnix);
section.set("ips", ips);
config.save();
}
}

View File

@ -1,82 +1,64 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import java.io.File; import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import net.pravian.bukkitlib.YamlConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class TFM_PlayerList public class TFM_PlayerList
{ {
private static final TFM_PlayerList INSTANCE = new TFM_PlayerList(); private static final TFM_PlayerList INSTANCE;
private static final String USERLIST_FILENAME = "playerlist.yml"; private final Map<UUID, TFM_PlayerEntry> playerList;
private final Map<UUID, PlayerEntry> playerList; private TFM_Config config;
private File configFile;
static
{
INSTANCE = new TFM_PlayerList();
}
private TFM_PlayerList() private TFM_PlayerList()
{ {
this.playerList = new HashMap<UUID, PlayerEntry>(); this.playerList = new HashMap<UUID, TFM_PlayerEntry>();
this.configFile = new File(TotalFreedomMod.plugin.getDataFolder(), USERLIST_FILENAME);
} }
public File getConfigFile() public TFM_Config getConfig()
{ {
return new File(TotalFreedomMod.plugin.getDataFolder(), USERLIST_FILENAME); return config;
} }
public void load() public void load()
{ {
playerList.clear(); playerList.clear();
configFile = getConfigFile(); if (config == null)
final YamlConfiguration config = new YamlConfiguration();
if (configFile.exists())
{ {
try config = new TFM_Config(TotalFreedomMod.plugin, "playerlist.yml", false);
}
config.load();
// Load players from config
for (String uuidString : config.getKeys(false))
{
if (!TFM_Util.isUniqueId(uuidString))
{ {
config.load(configFile); TFM_Log.warning("Invalid playerlist UUID: " + uuidString + ", Skipping...");
} continue;
catch (Exception ex)
{
TFM_Log.warning("Could not load player config file: " + ex.getMessage());
TFM_Log.warning("Purging...");
purgeAll();
return;
} }
// Load players from config final UUID uuid = UUID.fromString(uuidString);
for (String uuidString : config.getKeys(false))
final TFM_PlayerEntry entry = new TFM_PlayerEntry(uuid, config.getConfigurationSection(uuidString));
if (!entry.isComplete())
{ {
final UUID uuid; TFM_Log.warning("Incomplete playerlist entry: " + uuidString + ", Skipping...");
try continue;
{
uuid = UUID.fromString(uuidString);
}
catch (IllegalArgumentException ex)
{
TFM_Log.warning("Invalid playerlist UUID: " + uuidString + ", Skipping...");
continue;
}
final PlayerEntry entry = new PlayerEntry(uuid, config.getConfigurationSection(uuidString));
if (!entry.isComplete())
{
TFM_Log.warning("Incomplete playerlist entry: " + uuidString + ", Skipping...");
continue;
}
playerList.put(uuid, entry);
} }
playerList.put(uuid, entry);
} }
// Load online players // Load online players
@ -92,16 +74,16 @@ public class TFM_PlayerList
private void saveAll() private void saveAll()
{ {
// Put entries // Put entries
for (PlayerEntry entry : playerList.values()) for (TFM_PlayerEntry entry : playerList.values())
{ {
entry.save(); entry.save();
} }
} }
public PlayerEntry getEntry(String player) public TFM_PlayerEntry getEntry(String player)
{ {
for (PlayerEntry entry : playerList.values()) for (TFM_PlayerEntry entry : playerList.values())
{ {
if (entry.getLastJoinName().equalsIgnoreCase(player)) if (entry.getLastJoinName().equalsIgnoreCase(player))
{ {
@ -117,7 +99,7 @@ public class TFM_PlayerList
return playerList.containsKey(player.getUniqueId()); return playerList.containsKey(player.getUniqueId());
} }
public PlayerEntry getEntry(Player player) public TFM_PlayerEntry getEntry(Player player)
{ {
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
@ -126,7 +108,7 @@ public class TFM_PlayerList
return playerList.get(uuid); return playerList.get(uuid);
} }
final PlayerEntry entry = new PlayerEntry(uuid); final TFM_PlayerEntry entry = new TFM_PlayerEntry(uuid);
entry.setFirstJoinName(player.getName()); entry.setFirstJoinName(player.getName());
entry.setLastJoinName(player.getName()); entry.setLastJoinName(player.getName());
@ -145,203 +127,20 @@ public class TFM_PlayerList
public void purgeAll() public void purgeAll()
{ {
final YamlConfiguration config = loadConfig();
// Clear the config entries // Clear the config entries
for (String key : config.getKeys(false)) for (String key : config.getKeys(false))
{ {
config.set(key, null); config.set(key, null);
} }
// Save the config config.save();
try
{
config.save(configFile);
}
catch (IOException ex)
{
TFM_Log.severe("Could not purge config file: " + ex.getMessage());
TFM_Log.severe(ex);
}
// Load online players // Load online players
load(); load();
} }
private YamlConfiguration loadConfig()
{
final YamlConfiguration config = new YamlConfiguration();
try
{
config.load(configFile);
}
catch (Exception ex)
{
TFM_Log.severe("Could not load player config file: " + ex.getMessage());
TFM_Log.severe(ex);
purgeAll();
return null;
}
return config;
}
/*public String searchByPartialName(String needle)
{
needle = needle.toLowerCase().trim();
Integer minEditDistance = null;
String minEditMatch = null;
Iterator<UUID> it = playerList.keySet().iterator();
while (it.hasNext())
{
String haystack = it.next();
int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase());
if (minEditDistance == null || minEditDistance.intValue() > editDistance)
{
minEditDistance = editDistance;
minEditMatch = haystack;
}
}
return minEditMatch;
}*/
public static TFM_PlayerList getInstance() public static TFM_PlayerList getInstance()
{ {
return INSTANCE; return INSTANCE;
} }
public final class PlayerEntry
{
private final UUID uuid;
private String firstJoinName;
private String lastJoinName;
private long firstJoinUnix;
private long lastJoinUnix;
private final List<String> ips;
protected PlayerEntry(UUID uuid, ConfigurationSection section)
{
this(uuid);
this.firstJoinName = section.getString("firstjoinname");
this.lastJoinName = section.getString("lastjoinname");
this.firstJoinUnix = section.getLong("firstjoinunix");
this.firstJoinUnix = section.getLong("lastjoinunix");
this.ips.addAll(section.getStringList("ips"));
}
protected PlayerEntry(UUID uuid)
{
this.uuid = uuid;
this.ips = new ArrayList<String>();
}
// Getters / Setters below
public UUID getUniqueId()
{
return uuid;
}
public List<String> getIps()
{
return Collections.unmodifiableList(ips);
}
public String getFirstJoinName()
{
return firstJoinName;
}
public void setFirstJoinName(String firstJoinName)
{
this.firstJoinName = firstJoinName;
}
public String getLastJoinName()
{
return lastJoinName;
}
public void setLastJoinName(String lastJoinName)
{
this.lastJoinName = lastJoinName;
}
public long getFirstJoinUnix()
{
return firstJoinUnix;
}
public void setFirstJoinUnix(long firstJoinUnix)
{
this.firstJoinUnix = firstJoinUnix;
}
public long getLastJoinUnix()
{
return lastJoinUnix;
}
public void setLastJoinUnix(long lastJoinUnix)
{
this.lastJoinUnix = lastJoinUnix;
}
public boolean addIp(String ip)
{
if (!ips.contains(ip))
{
ips.add(ip);
return true;
}
return false;
}
private boolean isComplete()
{
return firstJoinName != null
&& lastJoinName != null
&& firstJoinUnix != 0
&& lastJoinUnix != 0
&& !ips.isEmpty();
}
public void save()
{
if (!isComplete())
{
throw new IllegalStateException("Entry is not complete");
}
final YamlConfiguration config = loadConfig();
final ConfigurationSection section;
if (config.isConfigurationSection(uuid.toString()))
{
section = config.getConfigurationSection(uuid.toString());
}
else
{
section = config.createSection(uuid.toString());
}
section.set("firstjoinname", firstJoinName);
section.set("lastjoinname", lastJoinName);
section.set("firstjoinunix", firstJoinUnix);
section.set("lastjoinunix", lastJoinUnix);
section.set("ips", ips);
// Save config
try
{
config.save(configFile);
}
catch (IOException ex)
{
TFM_Log.severe("Could not save player entry: " + uuid.toString() + " (" + lastJoinName + ")");
TFM_Log.severe(ex);
}
}
}
} }

View File

@ -27,28 +27,29 @@ public enum TFM_PlayerRank
public static String getLoginMessage(CommandSender sender) public static String getLoginMessage(CommandSender sender)
{ {
// Handle console
if (!(sender instanceof Player)) if (!(sender instanceof Player))
{ {
return fromSender(sender).getLoginMessage(); return fromSender(sender).getLoginMessage();
} }
final TFM_Admin entry = TFM_AdminList.getAdminEntry((Player) sender); // Handle admins
final TFM_Admin entry = TFM_AdminList.getEntry((Player) sender);
if (entry == null) if (entry == null)
{ {
// Player is not an admin
return fromSender(sender).getLoginMessage(); return fromSender(sender).getLoginMessage();
} }
// Custom login message
final String loginMessage = entry.getCustomLoginMessage(); final String loginMessage = entry.getCustomLoginMessage();
if (loginMessage != null && !loginMessage.isEmpty()) if (loginMessage == null || loginMessage.isEmpty())
{
return ChatColor.translateAlternateColorCodes('&', loginMessage);
}
else
{ {
return fromSender(sender).getLoginMessage(); return fromSender(sender).getLoginMessage();
} }
return ChatColor.translateAlternateColorCodes('&', loginMessage);
} }
public static TFM_PlayerRank fromSender(CommandSender sender) public static TFM_PlayerRank fromSender(CommandSender sender)
@ -58,7 +59,7 @@ public enum TFM_PlayerRank
return CONSOLE; return CONSOLE;
} }
if (sender instanceof Player && TFM_AdminList.isAdminImpostor((Player) sender)) if (TFM_AdminList.isAdminImpostor((Player) sender))
{ {
return IMPOSTOR; return IMPOSTOR;
} }
@ -69,7 +70,7 @@ public enum TFM_PlayerRank
} }
final TFM_Admin entry = TFM_AdminList.getAdminEntry((Player) sender); final TFM_Admin entry = TFM_AdminList.getEntry((Player) sender);
final TFM_PlayerRank rank; final TFM_PlayerRank rank;

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
@ -172,7 +173,7 @@ public class TFM_ServerInterface
} }
else else
{ {
isSuperadmin = TFM_AdminList.checkPartialSuperadminIP(ip, username.toLowerCase()); isSuperadmin = TFM_AdminList.checkPartialSuperadminIp(ip, username.toLowerCase());
} }
// Validation below this point // Validation below this point

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
@ -38,6 +39,7 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.Minecart; import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.plugin.Plugin;
public class TFM_Util public class TFM_Util
{ {
@ -322,19 +324,41 @@ public class TFM_Util
return TFM_Util.mobtypes.get(mobname); return TFM_Util.mobtypes.get(mobname);
} }
@Deprecated /**
private static void copy(InputStream in, OutputStream out) throws IOException * Write the specified InputStream to a file.
*
* @param in The InputStream from which to read.
* @param file The File to write to.
* @throws IOException
*/
public static void copy(InputStream in, File file) throws IOException // BukkitLib @ https://github.com/Pravian/BukkitLib
{ {
byte[] buffer = new byte[1024]; if (!file.exists())
while (true)
{ {
int readCount = in.read(buffer); file.getParentFile().mkdirs();
if (readCount < 0)
{
break;
}
out.write(buffer, 0, readCount);
} }
final OutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
out.close();
in.close();
}
/**
* Returns a file at located at the Plugins Data folder.
*
* @param plugin The plugin to use
* @param name The name of the file.
* @return The requested file.
*/
public static File getPluginFile(Plugin plugin, String name) // BukkitLib @ https://github.com/Pravian/BukkitLib
{
return new File(plugin.getDataFolder(), name);
} }
public static boolean isStopCommand(String command) public static boolean isStopCommand(String command)

View File

@ -1,5 +1,8 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -168,7 +171,6 @@ public class TotalFreedomMod extends JavaPlugin
TFM_ServiceChecker.getInstance().start(); TFM_ServiceChecker.getInstance().start();
TFM_HTTPD_Manager.getInstance().start(); TFM_HTTPD_Manager.getInstance().start();
TFM_FrontDoor.getInstance().start(); TFM_FrontDoor.getInstance().start();
TFM_LogFile.getInstance().start();
TFM_Log.info("Version " + pluginVersion + " enabled"); TFM_Log.info("Version " + pluginVersion + " enabled");
@ -265,7 +267,7 @@ public class TotalFreedomMod extends JavaPlugin
try try
{ {
TFM_AdminList.backupSavedList(); TFM_AdminList.backupSavedList();
TFM_AdminList.loadSuperadminList(); TFM_AdminList.load();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.World;
import java.util.Random; import java.util.Random;
import org.bukkit.Chunk; import org.bukkit.Chunk;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.World;
import static java.lang.System.arraycopy; import static java.lang.System.arraycopy;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,11 +1,17 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.World;
import me.StevenLawson.TotalFreedomMod.World.TFM_CustomWorld;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; 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;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;

View File

@ -1,4 +1,4 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.World;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;

View File

@ -1,6 +1,11 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod.World;
import me.StevenLawson.TotalFreedomMod.World.TFM_CustomWorld;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.File; import java.io.File;
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.io.FileUtils; import net.minecraft.util.org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;

View File

@ -4,13 +4,14 @@ clean_threshold_hours: 168
admins: admins:
b3c3b05a-a52d-33a6-a9c6-6e5063e00f0a: b3c3b05a-a52d-33a6-a9c6-6e5063e00f0a:
last_login_name: DarthSalamon last_login_name: DarthSalamon
- 127.0.0.1 is_activated: true
last_login: Fri, 9 Nov 2012 03:09:14 -0500
custom_login_message: the &5Lead Executive Developer&b.
is_senior_admin: true is_senior_admin: true
is_telnet_admin: true is_telnet_admin: true
last_login: Fri, 9 Nov 2012 03:09:14 -0500
custom_login_message: the &5Lead Executive Developer&b.
ips:
- 127.0.0.1
console_aliases: console_aliases:
- darth - darth
is_activated: true
# Todo: Add mark and madgeek # Todo: Add mark and madgeek