protect inventory only for registered player

This commit is contained in:
DNx5 2015-09-20 09:18:30 +07:00
parent 350ab53563
commit b1276da416
2 changed files with 26 additions and 29 deletions

View File

@ -17,14 +17,14 @@ import java.util.concurrent.ConcurrentHashMap;
public class LimboCache {
private volatile static LimboCache singleton = null;
private volatile static LimboCache singleton;
public ConcurrentHashMap<String, LimboPlayer> cache;
private JsonCache playerData;
public AuthMe plugin;
private LimboCache(AuthMe plugin) {
this.plugin = plugin;
this.cache = new ConcurrentHashMap<String, LimboPlayer>();
this.cache = new ConcurrentHashMap<>();
this.playerData = new JsonCache(plugin);
}
@ -77,7 +77,7 @@ public class LimboCache {
}
if (Settings.isForceSurvivalModeEnabled) {
if (Settings.isResetInventoryIfCreative && player.getGameMode() == GameMode.CREATIVE) {
if (Settings.isResetInventoryIfCreative && gameMode == GameMode.CREATIVE) {
ResetInventoryEvent event = new ResetInventoryEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@ -123,7 +123,7 @@ public class LimboCache {
if (this.hasLimboPlayer(player.getName().toLowerCase())) {
this.deleteLimboPlayer(player.getName().toLowerCase());
}
this.addLimboPlayer(player);
addLimboPlayer(player);
}
}

View File

@ -127,11 +127,28 @@ public class AsyncronousJoin {
}
placePlayerSafely(player, spawnLoc);
LimboCache.getInstance().updateLimboPlayer(player);
try {
DataFileCache dataFile = new DataFileCache(LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour());
playerBackup.createCache(player, dataFile);
} catch (Exception e) {
ConsoleLogger.showError("Error on creating an inventory cache for " + name + ", maybe inventory wipe in preparation...");
DataFileCache dataFile = new DataFileCache(LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour());
playerBackup.createCache(player, dataFile);
// protect inventory
if (Settings.protectInventoryBeforeLogInEnabled) {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
plugin.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
if (!Settings.noConsoleSpam)
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
} else {
final ItemStack[] inv = ev.getEmptyArmor();
final ItemStack[] armor = ev.getEmptyArmor();
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
plugin.api.setPlayerInventory(player, inv, armor);
}
});
}
}
} else {
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
@ -171,26 +188,6 @@ public class AsyncronousJoin {
}
}
if (Settings.protectInventoryBeforeLogInEnabled) {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
plugin.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
if (!Settings.noConsoleSpam)
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
} else {
final ItemStack[] inv = ev.getEmptyArmor();
final ItemStack[] armor = ev.getEmptyArmor();
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
plugin.api.setPlayerInventory(player, inv, armor);
}
});
}
}
String[] msg;
if (Settings.emailRegistration) {
msg = database.isAuthAvailable(name) ? m.send("login_msg") : m.send("reg_email_msg");