diff --git a/pom.xml b/pom.xml index 1cb9cd2..fb5616f 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.cypherx xauth - 1.2.3 + 1.2.4 xAuth UTF-8 @@ -16,13 +16,6 @@ jar compile - - org.bukkit - craftbukkit - 0.0.1-SNAPSHOT - jar - compile - com.nijikokun.bukkit Permissions @@ -30,6 +23,13 @@ jar compile + + org.bukkit + craftbukkit + 0.0.1-SNAPSHOT + jar + compile + ${project.name} diff --git a/src/main/java/com/cypherx/xauth/CommandHandler.java b/src/main/java/com/cypherx/xauth/CommandHandler.java index c158194..df6be96 100644 --- a/src/main/java/com/cypherx/xauth/CommandHandler.java +++ b/src/main/java/com/cypherx/xauth/CommandHandler.java @@ -1,10 +1,9 @@ package com.cypherx.xauth; -import org.bukkit.Server; import org.bukkit.command.Command; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.craftbukkit.CraftServer; public class CommandHandler { @@ -67,12 +66,20 @@ public class CommandHandler if (plugin.getStrikes(player) >= xAuth.settings.getInt("login.strikes.amount")) { - String addr = player.getAddress().getAddress().getHostAddress(); - Server server = plugin.getServer(); - server.dispatchCommand(((CraftServer)server).getServer().console, "ban-ip " + addr); + String action; + + if (xAuth.settings.getStr("login.strikes.action").equals("banip")) + { + String addr = player.getAddress().getAddress().getHostAddress(); + plugin.getServer().dispatchCommand(new ConsoleCommandSender(plugin.getServer()), "ban-ip " + addr); + action = addr + " banned"; + } + else + action = player.getName() + " kicked"; + player.kickPlayer(xAuth.strings.getString("login.err.kick")); plugin.clearStrikes(player); - System.out.println("[" + pdfFile.getName() + "] " + addr + " banned by Strike system"); + System.out.println("[" + pdfFile.getName() + "] " + action + " by strike system"); } } } @@ -144,8 +151,11 @@ public class CommandHandler if (target != null) { - if (plugin.mustRegister(target)) + if (plugin.mustRegister(target)) { + plugin.loginLocation.put(target, target.getLocation()); + target.teleport(target.getWorld().getSpawnLocation()); plugin.saveInventory(target); + } target.sendMessage(xAuth.strings.getString("unregister.target")); } @@ -222,6 +232,8 @@ public class CommandHandler if (pTarget != null) { + plugin.loginLocation.put(pTarget, pTarget.getLocation()); + pTarget.teleport(pTarget.getWorld().getSpawnLocation()); plugin.saveInventory(pTarget); pTarget.sendMessage(xAuth.strings.getString("logout.success.ended")); } @@ -272,8 +284,11 @@ public class CommandHandler if (target != null) { - if (plugin.mustRegister(target)) + if (plugin.mustRegister(target)) { + plugin.loginLocation.put(target, target.getLocation()); + target.teleport(target.getWorld().getSpawnLocation()); plugin.saveInventory(target); + } target.sendMessage(xAuth.strings.getString("unregister.target")); } @@ -334,6 +349,8 @@ public class CommandHandler if (pTarget != null) { + plugin.loginLocation.put(pTarget, pTarget.getLocation()); + pTarget.teleport(pTarget.getWorld().getSpawnLocation()); plugin.saveInventory(pTarget); pTarget.sendMessage(xAuth.strings.getString("logout.success.ended")); } diff --git a/src/main/java/com/cypherx/xauth/Settings.java b/src/main/java/com/cypherx/xauth/Settings.java index 1bb92bb..b0d4fda 100644 --- a/src/main/java/com/cypherx/xauth/Settings.java +++ b/src/main/java/com/cypherx/xauth/Settings.java @@ -21,6 +21,7 @@ public class Settings "misc.allowed-cmds", "login.strikes.enabled", "login.strikes.amount", + "login.strikes.action", "filter.enabled", "filter.allowed", "filter.block-blankname", @@ -80,6 +81,7 @@ public class Settings defaults.put("misc.autosave", true); defaults.put("login.strikes.enabled", true); defaults.put("login.strikes.amount", 5); + defaults.put("login.strikes.action", "kick"); defaults.put("filter.enabled", true); defaults.put("filter.allowed", "abcdefghijklmnopqrstuvwxyz0123456789_- ()[]{}"); defaults.put("filter.block-blankname", true); @@ -111,10 +113,8 @@ public class Settings private void removeKeys() { for (String key : keyRemovals) - { if (config.getProperty(key) != null) config.removeProperty(key); - } } public void load() @@ -164,22 +164,11 @@ public class Settings if (!(settings.get(key) instanceof List)) { System.out.println("[xAuth] COMMAND_PREPROCESS Error: Report this in the xAuth thread."); - System.out.println("[xAuth] Value:" + settings.get(key)); + System.out.println("[xAuth] Value: " + settings.get(key)); System.out.println("[xAuth] Attempting to autocorrect.."); xAuth.settings = new Settings(file); } - /*Object value = settings.get(key); - - if (value instanceof String[]) - System.out.println("string array"); - else if (value instanceof String) - System.out.println("string"); - else if (value instanceof List) - System.out.println("list"); - - System.out.println(value);*/ - return (List)settings.get(key); } } \ No newline at end of file diff --git a/src/main/java/com/cypherx/xauth/xAuth.java b/src/main/java/com/cypherx/xauth/xAuth.java index 7b1f48b..9c6b1b4 100644 --- a/src/main/java/com/cypherx/xauth/xAuth.java +++ b/src/main/java/com/cypherx/xauth/xAuth.java @@ -1,6 +1,3 @@ -//xAuth 1.2.3 -//Built against Bukkit #660, CraftBukkit #703, and Permissions v2.7 - package com.cypherx.xauth; import java.io.*; @@ -9,10 +6,13 @@ import java.security.MessageDigest; import java.util.concurrent.ConcurrentHashMap; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.minecraft.server.PropertyManager; + +import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -60,6 +60,7 @@ public class xAuth extends JavaPlugin private ConcurrentHashMap sessions = new ConcurrentHashMap(); private ConcurrentHashMap lastNotifyTimes = new ConcurrentHashMap(); private ConcurrentHashMap strikes = new ConcurrentHashMap(); + public HashMap loginLocation = new HashMap(); private ArrayList illegalNames = new ArrayList(); public void onEnable() @@ -104,8 +105,10 @@ public class xAuth extends JavaPlugin { for (Player player : players) { - if (isRegistered(player.getName())) + if (mustRegister(player)) { + loginLocation.put(player, player.getLocation()); + player.teleport(player.getWorld().getSpawnLocation()); saveInventory(player); player.sendMessage(strings.getString("misc.reloaded")); } @@ -118,10 +121,10 @@ public class xAuth extends JavaPlugin pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Event.Priority.Lowest, this); pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, playerListener, Event.Priority.Lowest, this); pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Lowest, this); - pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Lowest, this); + pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this); pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Event.Priority.Lowest, this); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Lowest, this); - pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Lowest, this); + pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Monitor, this); pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Lowest, this); pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Lowest, this); @@ -142,7 +145,7 @@ public class xAuth extends JavaPlugin try { BufferedReader authReader = new BufferedReader(new FileReader(DIR + AUTH_FILE)); - + String line; while ((line = authReader.readLine()) != null) { @@ -162,13 +165,17 @@ public class xAuth extends JavaPlugin { getServer().getScheduler().cancelAllTasks(); - //Restore players inventories so they are not lost + //Restore players inventories and locations so they are not lost Player[] players = getServer().getOnlinePlayers(); if (players.length > 0) { - for (Player player : players) - if (!sessionExists(player.getName())) + for (Player player : players) { + if (!sessionExists(player.getName())) { + player.teleport(loginLocation.get(player)); + loginLocation.remove(player); restoreInventory(player); + } + } } if (fullyEnabled) @@ -286,6 +293,8 @@ public class xAuth extends JavaPlugin //LOGIN / LOGOUT FUNCTIONS public void login(Player player) { + player.teleport(loginLocation.get(player)); + loginLocation.remove(player); startSession(player); restoreInventory(player); } @@ -324,8 +333,11 @@ public class xAuth extends JavaPlugin if (session.isExpired(new Date(session.getLoginTime() + (settings.getInt("session.timeout") * 1000)))) removeSession(pName); } - else + else { + player.teleport(loginLocation.get(player)); + loginLocation.remove(player); restoreInventory(player); + } } public void addStrike(Player player) @@ -374,6 +386,9 @@ public class xAuth extends JavaPlugin public Boolean isCmdAllowed(String cmd) { + if (cmd.equals("/register") || cmd.equals("/login") || cmd.equals("/l")) + return true; + if (settings.getStrList("misc.allowed-cmds").contains(cmd)) return true; @@ -415,6 +430,10 @@ public class xAuth extends JavaPlugin playerInv.setChestplate(null); playerInv.setLeggings(null); playerInv.setBoots(null); + + //Backpack fix + player.saveData(); + //end Backpack fix } public void restoreInventory(Player player) @@ -423,7 +442,21 @@ public class xAuth extends JavaPlugin if (inventory.containsKey(player)) { - playerInv.setContents(inventory.get(player)); + ItemStack[] inv = inventory.get(player); + + //Backpack fix + if (playerInv.getSize() > inv.length) + { + ItemStack[] newInv = new ItemStack[playerInv.getSize()]; + + for(int i = 0; i < inv.length; i++) + newInv[i] = inv[i]; + + inv = newInv; + } + //end Backpack fix + + playerInv.setContents(inv); inventory.remove(player); } @@ -492,6 +525,8 @@ public class xAuth extends JavaPlugin if (player != null) { + loginLocation.put(player, player.getLocation()); + player.teleport(player.getWorld().getSpawnLocation()); saveInventory(player); player.sendMessage(strings.getString("logout.success.ended")); } diff --git a/src/main/java/com/cypherx/xauth/xAuthPlayerListener.java b/src/main/java/com/cypherx/xauth/xAuthPlayerListener.java index df0ad67..ae2e18e 100644 --- a/src/main/java/com/cypherx/xauth/xAuthPlayerListener.java +++ b/src/main/java/com/cypherx/xauth/xAuthPlayerListener.java @@ -1,6 +1,6 @@ package com.cypherx.xauth; -//import org.bukkit.Location; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.player.*; @@ -37,6 +37,9 @@ public class xAuthPlayerListener extends PlayerListener if (!plugin.isLoggedIn(player)) { + plugin.loginLocation.put(player, player.getLocation()); + player.teleport(player.getWorld().getSpawnLocation()); + if (!plugin.isRegistered(player.getName())) { if (!plugin.mustRegister(player)) @@ -129,8 +132,12 @@ public class xAuthPlayerListener extends PlayerListener Player player = event.getPlayer(); plugin.handleEvent(player, event); - if (event.isCancelled()) - player.teleport(event.getFrom()); + Location loc = player.getWorld().getSpawnLocation(); + + if (event.isCancelled() && player.teleport(loc)) { + event.setTo(loc); + event.setFrom(loc); + } } //Prevents player from picking up items diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 95db097..35f6b73 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,15 +1,15 @@ name: xAuth main: com.cypherx.xauth.xAuth -version: 1.2.3 +version: 1.2.4 description: Allows players to register and maintain an account while the server is in offline-mode. -authors: - - CypherX +author: CypherX commands: register: description: Register your player name usage: /register login: + aliases: [l] description: Authenticate yourself usage: /login changepw: