1
0
mirror of https://github.com/moparisthebest/xAuth synced 2024-12-21 22:58:51 -05:00

Players are now teleported to the spawn until they have logged in (this should fix falling into the void)

Compatibility for MultiInv, Backpack, and iZone
Strike system can now be toggled between kicking and banning the player's IP
Added alias /l (L) for /login
This commit is contained in:
CypherX 2011-04-30 21:01:21 -04:00
parent 5b5e11e372
commit 98f4fd015c
6 changed files with 96 additions and 48 deletions

16
pom.xml
View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.cypherx</groupId>
<artifactId>xauth</artifactId>
<version>1.2.3</version>
<version>1.2.4</version>
<name>xAuth</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -16,13 +16,6 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nijikokun.bukkit</groupId>
<artifactId>Permissions</artifactId>
@ -30,6 +23,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.name}</finalName>

View File

@ -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"));
}

View File

@ -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<String>)settings.get(key);
}
}

View File

@ -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<String, Session> sessions = new ConcurrentHashMap<String, Session>();
private ConcurrentHashMap<Player, Date> lastNotifyTimes = new ConcurrentHashMap<Player, Date>();
private ConcurrentHashMap<String, Integer> strikes = new ConcurrentHashMap<String, Integer>();
public HashMap<Player, Location> loginLocation = new HashMap<Player, Location>();
private ArrayList<String> illegalNames = new ArrayList<String>();
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"));
}

View File

@ -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

View File

@ -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 <password>
login:
aliases: [l]
description: Authenticate yourself
usage: /login <password>
changepw: