Replacing old inventory protecting with safe packet modifications using ProtocolLib.
Instead of clearing the inventory of players and storing it's contents in a file, we now prevent the server from sending the inventory packet if the player is not logged in. The player will see a empty inventory, but has still his items stored on the server. Therefore we don't need to modify the player's inventory and we won't make any inventory corrupted. Fixes Xephi/AuthMeReloaded#203, Fixes Xephi/AuthMeReloaded#193, Fixes Xephi/AuthMeReloaded#191, Fixes Xephi/AuthMeReloaded#148 Remove dead code + Fix empty inventory on the unregister command Fix NPE if ProtocolLib isn't enabled or installed
This commit is contained in:
@@ -1,110 +1,93 @@
|
||||
package fr.xephi.authme.process.quit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class AsyncronousQuit {
|
||||
|
||||
protected AuthMe plugin;
|
||||
protected DataSource database;
|
||||
protected Player player;
|
||||
private String name;
|
||||
private ItemStack[] armor = null;
|
||||
private ItemStack[] inv = null;
|
||||
private boolean isOp = false;
|
||||
private boolean isFlying = false;
|
||||
private boolean needToChange = false;
|
||||
private boolean isKick = false;
|
||||
|
||||
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
|
||||
boolean isKick) {
|
||||
this.player = p;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.name = p.getName().toLowerCase();
|
||||
this.isKick = isKick;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
if (player == null)
|
||||
return;
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String ip = plugin.getIP(player);
|
||||
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) {
|
||||
Location loc = player.getLocation();
|
||||
PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName(), player.getName());
|
||||
database.updateQuitLoc(auth);
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis(), player.getName());
|
||||
database.updateSession(auth);
|
||||
}
|
||||
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||
if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) {
|
||||
inv = limbo.getInventory();
|
||||
armor = limbo.getArmour();
|
||||
}
|
||||
if (limbo.getGroup() != null && !limbo.getGroup().equals(""))
|
||||
Utils.addNormal(player, limbo.getGroup());
|
||||
needToChange = true;
|
||||
isOp = limbo.getOperator();
|
||||
isFlying = limbo.isFlying();
|
||||
if (limbo.getTimeoutTaskId() != null)
|
||||
limbo.getTimeoutTaskId().cancel();
|
||||
if (limbo.getMessageTaskId() != null)
|
||||
limbo.getMessageTaskId().cancel();
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
if (Settings.isSessionsEnabled && !isKick) {
|
||||
if (Settings.getSessionTimeout != 0) {
|
||||
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
if (database.isLogged(name))
|
||||
database.setUnlogged(name);
|
||||
plugin.sessions.remove(name);
|
||||
}
|
||||
|
||||
}, Settings.getSessionTimeout * 20 * 60);
|
||||
plugin.sessions.put(name, task);
|
||||
}
|
||||
} else {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
}
|
||||
AuthMePlayerListener.gameMode.remove(name);
|
||||
final Player p = player;
|
||||
RestoreInventoryEvent ev = new RestoreInventoryEvent(player, inv, armor, true);
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
if (ev.isCancelled()) {
|
||||
inv = null;
|
||||
armor = null;
|
||||
} else {
|
||||
inv = ev.getInventory();
|
||||
armor = ev.getArmor();
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, p, inv, armor, isOp, isFlying, needToChange));
|
||||
}
|
||||
}
|
||||
package fr.xephi.authme.process.quit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class AsyncronousQuit {
|
||||
|
||||
protected AuthMe plugin;
|
||||
protected DataSource database;
|
||||
protected Player player;
|
||||
private String name;
|
||||
private boolean isOp = false;
|
||||
private boolean isFlying = false;
|
||||
private boolean needToChange = false;
|
||||
private boolean isKick = false;
|
||||
|
||||
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
|
||||
boolean isKick) {
|
||||
this.player = p;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.name = p.getName().toLowerCase();
|
||||
this.isKick = isKick;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
if (player == null)
|
||||
return;
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String ip = plugin.getIP(player);
|
||||
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) {
|
||||
Location loc = player.getLocation();
|
||||
PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName(), player.getName());
|
||||
database.updateQuitLoc(auth);
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis(), player.getName());
|
||||
database.updateSession(auth);
|
||||
}
|
||||
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||
if (limbo.getGroup() != null && !limbo.getGroup().equals(""))
|
||||
Utils.addNormal(player, limbo.getGroup());
|
||||
needToChange = true;
|
||||
isOp = limbo.getOperator();
|
||||
isFlying = limbo.isFlying();
|
||||
if (limbo.getTimeoutTaskId() != null)
|
||||
limbo.getTimeoutTaskId().cancel();
|
||||
if (limbo.getMessageTaskId() != null)
|
||||
limbo.getMessageTaskId().cancel();
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
if (Settings.isSessionsEnabled && !isKick) {
|
||||
if (Settings.getSessionTimeout != 0) {
|
||||
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
if (database.isLogged(name))
|
||||
database.setUnlogged(name);
|
||||
plugin.sessions.remove(name);
|
||||
}
|
||||
|
||||
}, Settings.getSessionTimeout * 20 * 60);
|
||||
plugin.sessions.put(name, task);
|
||||
}
|
||||
} else {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
}
|
||||
|
||||
AuthMePlayerListener.gameMode.remove(name);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, isFlying, needToChange));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,49 @@
|
||||
package fr.xephi.authme.process.quit;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||
|
||||
protected AuthMe plugin;
|
||||
protected Player player;
|
||||
protected boolean isOp;
|
||||
protected boolean isFlying;
|
||||
protected ItemStack[] inv;
|
||||
protected ItemStack[] armor;
|
||||
protected boolean needToChange;
|
||||
|
||||
public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player,
|
||||
ItemStack[] inv, ItemStack[] armor, boolean isOp, boolean isFlying,
|
||||
boolean needToChange) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.isOp = isOp;
|
||||
this.isFlying = isFlying;
|
||||
this.armor = armor;
|
||||
this.inv = inv;
|
||||
this.needToChange = needToChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (inv != null && armor != null)
|
||||
plugin.api.setPlayerInventory(player, inv, armor);
|
||||
if (needToChange) {
|
||||
player.setOp(isOp);
|
||||
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
||||
player.setAllowFlight(isFlying);
|
||||
player.setFlying(isFlying);
|
||||
}
|
||||
}
|
||||
try {
|
||||
player.getVehicle().eject();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
package fr.xephi.authme.process.quit;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||
|
||||
protected AuthMe plugin;
|
||||
protected Player player;
|
||||
protected boolean isOp;
|
||||
protected boolean isFlying;
|
||||
protected boolean needToChange;
|
||||
|
||||
public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player
|
||||
, boolean isOp, boolean isFlying
|
||||
, boolean needToChange) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.isOp = isOp;
|
||||
this.isFlying = isFlying;
|
||||
this.needToChange = needToChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
RestoreInventoryEvent ev = new RestoreInventoryEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
if (!ev.isCancelled()) {
|
||||
plugin.api.setPlayerInventory(player, ev.getInventory(), ev.getArmor());
|
||||
}
|
||||
|
||||
if (needToChange) {
|
||||
player.setOp(isOp);
|
||||
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
||||
player.setAllowFlight(isFlying);
|
||||
player.setFlying(isFlying);
|
||||
}
|
||||
}
|
||||
try {
|
||||
player.getVehicle().eject();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user