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:
+8
-15
@@ -11,7 +11,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -25,15 +24,13 @@ public class LimboCache {
|
||||
private LimboCache(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.cache = new ConcurrentHashMap<>();
|
||||
this.playerData = new JsonCache(plugin);
|
||||
this.playerData = new JsonCache();
|
||||
}
|
||||
|
||||
public void addLimboPlayer(Player player) {
|
||||
String name = player.getName().toLowerCase();
|
||||
Location loc = player.getLocation();
|
||||
GameMode gameMode = player.getGameMode();
|
||||
ItemStack[] arm;
|
||||
ItemStack[] inv;
|
||||
boolean operator = false;
|
||||
String playerGroup = "";
|
||||
boolean flying = false;
|
||||
@@ -42,12 +39,10 @@ public class LimboCache {
|
||||
final StoreInventoryEvent event = new StoreInventoryEvent(player, playerData);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
|
||||
inv = event.getInventory();
|
||||
arm = event.getArmor();
|
||||
} else {
|
||||
inv = null;
|
||||
arm = null;
|
||||
player.getInventory().setContents(event.getInventory());
|
||||
player.getInventory().setArmorContents(event.getArmor());
|
||||
}
|
||||
|
||||
DataFileCache cache = playerData.readCache(player);
|
||||
if (cache != null) {
|
||||
playerGroup = cache.getGroup();
|
||||
@@ -58,12 +53,10 @@ public class LimboCache {
|
||||
StoreInventoryEvent event = new StoreInventoryEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
|
||||
inv = event.getInventory();
|
||||
arm = event.getArmor();
|
||||
} else {
|
||||
inv = null;
|
||||
arm = null;
|
||||
player.getInventory().setContents(event.getInventory());
|
||||
player.getInventory().setArmorContents(event.getArmor());
|
||||
}
|
||||
|
||||
operator = player.isOp();
|
||||
flying = player.isFlying();
|
||||
if (plugin.permission != null) {
|
||||
@@ -93,7 +86,7 @@ public class LimboCache {
|
||||
if (player.isDead()) {
|
||||
loc = plugin.getSpawnLocation(player);
|
||||
}
|
||||
cache.put(name, new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup, flying));
|
||||
cache.put(name, new LimboPlayer(name, loc, gameMode, operator, playerGroup, flying));
|
||||
}
|
||||
|
||||
public void addLimboPlayer(Player player, String group) {
|
||||
|
||||
@@ -2,14 +2,11 @@ package fr.xephi.authme.cache.limbo;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class LimboPlayer {
|
||||
|
||||
private String name;
|
||||
private ItemStack[] inventory;
|
||||
private ItemStack[] armour;
|
||||
private Location loc = null;
|
||||
private BukkitTask timeoutTaskId = null;
|
||||
private BukkitTask messageTaskId = null;
|
||||
@@ -18,19 +15,6 @@ public class LimboPlayer {
|
||||
private String group = "";
|
||||
private boolean flying = false;
|
||||
|
||||
public LimboPlayer(String name, Location loc, ItemStack[] inventory,
|
||||
ItemStack[] armour, GameMode gameMode, boolean operator,
|
||||
String group, boolean flying) {
|
||||
this.name = name;
|
||||
this.loc = loc;
|
||||
this.inventory = inventory;
|
||||
this.armour = armour;
|
||||
this.gameMode = gameMode;
|
||||
this.operator = operator;
|
||||
this.group = group;
|
||||
this.flying = flying;
|
||||
}
|
||||
|
||||
public LimboPlayer(String name, Location loc, GameMode gameMode,
|
||||
boolean operator, String group, boolean flying) {
|
||||
this.name = name;
|
||||
@@ -54,22 +38,6 @@ public class LimboPlayer {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmour() {
|
||||
return armour;
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void setArmour(ItemStack[] armour) {
|
||||
this.armour = armour;
|
||||
}
|
||||
|
||||
public void setInventory(ItemStack[] inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
@@ -105,5 +73,4 @@ public class LimboPlayer {
|
||||
public boolean isFlying() {
|
||||
return flying;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user