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

Various NullPointerException errors fixed

Players will now be teleported to ground level instead of underground or in the air when not logged in
Added configuration node to turn on/off location protection (misc.protect-locaton)
MineQuest entity interaction fixed
This commit is contained in:
CypherX 2011-05-12 17:39:11 -04:00
parent 98f4fd015c
commit 88f74bfe41
7 changed files with 60 additions and 41 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.cypherx</groupId>
<artifactId>xauth</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<name>xAuth</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -152,8 +152,7 @@ public class CommandHandler
if (target != null)
{
if (plugin.mustRegister(target)) {
plugin.loginLocation.put(target, target.getLocation());
target.teleport(target.getWorld().getSpawnLocation());
plugin.saveLocation(target);
plugin.saveInventory(target);
}
target.sendMessage(xAuth.strings.getString("unregister.target"));
@ -232,8 +231,7 @@ public class CommandHandler
if (pTarget != null)
{
plugin.loginLocation.put(pTarget, pTarget.getLocation());
pTarget.teleport(pTarget.getWorld().getSpawnLocation());
plugin.saveLocation(pTarget);
plugin.saveInventory(pTarget);
pTarget.sendMessage(xAuth.strings.getString("logout.success.ended"));
}
@ -285,8 +283,7 @@ public class CommandHandler
if (target != null)
{
if (plugin.mustRegister(target)) {
plugin.loginLocation.put(target, target.getLocation());
target.teleport(target.getWorld().getSpawnLocation());
plugin.saveLocation(target);
plugin.saveInventory(target);
}
target.sendMessage(xAuth.strings.getString("unregister.target"));
@ -349,8 +346,7 @@ public class CommandHandler
if (pTarget != null)
{
plugin.loginLocation.put(pTarget, pTarget.getLocation());
pTarget.teleport(pTarget.getWorld().getSpawnLocation());
plugin.saveLocation(pTarget);
plugin.saveInventory(pTarget);
pTarget.sendMessage(xAuth.strings.getString("logout.success.ended"));
}

View File

@ -19,6 +19,7 @@ public class Settings
"session.verifyip",
"notify.limit",
"misc.allowed-cmds",
"misc.protect-location",
"login.strikes.enabled",
"login.strikes.amount",
"login.strikes.action",
@ -79,6 +80,7 @@ public class Settings
defaults.put("misc.allow-changepw", true);
defaults.put("misc.allowed-cmds", Arrays.asList(new String[]{"/register", "/login"}));
defaults.put("misc.autosave", true);
defaults.put("misc.protect-location", true);
defaults.put("login.strikes.enabled", true);
defaults.put("login.strikes.amount", 5);
defaults.put("login.strikes.action", "kick");

View File

@ -6,7 +6,6 @@ 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;
@ -60,7 +59,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 ConcurrentHashMap<Player, Location> locations = new ConcurrentHashMap<Player, Location>();
private ArrayList<String> illegalNames = new ArrayList<String>();
public void onEnable()
@ -105,10 +104,9 @@ public class xAuth extends JavaPlugin
{
for (Player player : players)
{
if (mustRegister(player))
if (mustRegister(player) || isRegistered(player.getName()))
{
loginLocation.put(player, player.getLocation());
player.teleport(player.getWorld().getSpawnLocation());
saveLocation(player);
saveInventory(player);
player.sendMessage(strings.getString("misc.reloaded"));
}
@ -171,8 +169,7 @@ public class xAuth extends JavaPlugin
{
for (Player player : players) {
if (!sessionExists(player.getName())) {
player.teleport(loginLocation.get(player));
loginLocation.remove(player);
restoreLocation(player);
restoreInventory(player);
}
}
@ -293,9 +290,8 @@ public class xAuth extends JavaPlugin
//LOGIN / LOGOUT FUNCTIONS
public void login(Player player)
{
player.teleport(loginLocation.get(player));
loginLocation.remove(player);
startSession(player);
restoreLocation(player);
restoreInventory(player);
}
@ -334,8 +330,7 @@ public class xAuth extends JavaPlugin
removeSession(pName);
}
else {
player.teleport(loginLocation.get(player));
loginLocation.remove(player);
restoreLocation(player);
restoreInventory(player);
}
}
@ -399,11 +394,11 @@ public class xAuth extends JavaPlugin
{
if (lastNotifyTimes.get(player) == null)
return true;
Date nextNotifyTime = new Date(lastNotifyTimes.get(player).getTime() + (settings.getInt("notify.limit") * 1000));
if (nextNotifyTime.compareTo(new Date()) < 0)
return true;
return false;
}
@ -418,7 +413,26 @@ public class xAuth extends JavaPlugin
lastNotifyTimes.remove(player);
lastNotifyTimes.put(player, date);
}
public void saveLocation(Player player) {
if (!settings.getBool("misc.protect-location"))
return;
locations.put(player, player.getLocation());
player.teleport(player.getWorld().getSpawnLocation());
}
public void restoreLocation(Player player) {
if (!settings.getBool("misc.protect-location"))
return;
Location loc = locations.get(player);
if (loc != null) {
player.teleport(loc);
locations.remove(player);
}
}
//INVENTORY FUNCTIONS
public void saveInventory(Player player)
{
@ -525,8 +539,7 @@ public class xAuth extends JavaPlugin
if (player != null)
{
loginLocation.put(player, player.getLocation());
player.teleport(player.getWorld().getSpawnLocation());
saveLocation(player);
saveInventory(player);
player.sendMessage(strings.getString("logout.success.ended"));
}

View File

@ -25,7 +25,7 @@ public class xAuthEntityListener extends EntityListener
Entity entity = event.getEntity();
//Player taking damage
if (entity instanceof Player)
if (entity instanceof Player && ((Player)entity).isOnline())
plugin.handleEvent((Player)entity, event);
//Player dealing damage to other entity
else if (event instanceof EntityDamageByEntityEvent)

View File

@ -1,6 +1,7 @@
package com.cypherx.xauth;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.player.*;
@ -37,14 +38,12 @@ 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))
return;
plugin.saveLocation(player);
plugin.saveInventory(player);
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() {
public void run() {
@ -54,6 +53,7 @@ public class xAuthPlayerListener extends PlayerListener
}
else
{
plugin.saveLocation(player);
plugin.saveInventory(player);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
@ -120,21 +120,29 @@ public class xAuthPlayerListener extends PlayerListener
if (event.isCancelled())
return;
/*Location from = event.getFrom();
Location to = event.getTo();
if (from.getX() == to.getX() && from.getZ() == to.getZ())
{
if (from.getY() > to.getY())
return;
}*/
Player player = event.getPlayer();
plugin.handleEvent(player, event);
Location loc = player.getWorld().getSpawnLocation();
if (event.isCancelled()) {
Location loc;
if (event.isCancelled() && player.teleport(loc)) {
//protect location by teleporting user to spawn
if (xAuth.settings.getBool("misc.protect-location")) {
World w = player.getWorld();
loc = w.getSpawnLocation();
//underground, go up 1 block until air is reached
while (w.getBlockTypeIdAt(loc) != 0)
loc = new Location(w, loc.getX(), loc.getY() + 1, loc.getZ());
//in the air, go down 1 block until the ground is reached
while (w.getBlockTypeIdAt((int) loc.getX(), (int) loc.getY() - 1, (int) loc.getZ()) == 0)
loc = new Location(w, loc.getX(), loc.getY() - 1, loc.getZ());
}
else
loc = event.getFrom();
player.teleport(loc);
event.setTo(loc);
event.setFrom(loc);
}

View File

@ -1,6 +1,6 @@
name: xAuth
main: com.cypherx.xauth.xAuth
version: 1.2.4
version: 1.2.5
description: Allows players to register and maintain an account while the server is in offline-mode.
author: CypherX