Xephi 10b4eaeca7 AuthMe 3.0
//Changes 3.0://
* Repackaging from uk.org.whoami.authme to fr.xephi.authme, please
developpers, update!
* Rewrite some of parts of the plugin
* Some code was already perfect , also did not change it :p
* Full support for phpbb3
* Add full support for WordPress + passwordHash: WORDPRESS
* Completely rewrite Management system for inventories and tp issues,
Thanks to : [[http://dev.bukkit.org/profiles/Possible/|Possible]]
* Rework on /passpartu command
* Completely rewrite the password encryption method
* Add a way for developers to add their own Password Encryption Method
on AuthMe via event way (please see
fr.xephi.authme.events.PasswordEncryptionEvent)
* Add an auto purge with players.dat removing method and essentials
files removing ( if you want authme to hook with an another plugin let
me know )
* Complete Hook with BungeeCord by removing the /server command before
login
* message_lang.yml will never be overwritten with English Strings , but
correctly update the message_lang.yml when needed to
* Fix a lot of issues mentioned in tickets , commants , or by mp, Thanks
for all your reports!
2013-10-17 05:14:46 +02:00

126 lines
4.1 KiB
Java

package fr.xephi.authme.cache.limbo;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.api.API;
import fr.xephi.authme.cache.backup.FileCache;
import fr.xephi.authme.events.ResetInventoryEvent;
import fr.xephi.authme.events.StoreInventoryEvent;
import fr.xephi.authme.settings.Settings;
public class LimboCache {
private static LimboCache singleton = null;
public HashMap<String, LimboPlayer> cache;
private FileCache playerData = new FileCache();
public AuthMe plugin;
private LimboCache(AuthMe plugin) {
this.plugin = plugin;
this.cache = new HashMap<String, LimboPlayer>();
}
public void addLimboPlayer(Player player) {
String name = player.getName().toLowerCase();
Location loc = player.getLocation();
int gameMode = player.getGameMode().getValue();
ItemStack[] arm;
ItemStack[] inv;
boolean operator;
String playerGroup = "";
boolean flying;
if (playerData.doesCacheExist(name)) {
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;
}
playerGroup = playerData.readCache(name).getGroup();
operator = playerData.readCache(name).getOperator();
flying = playerData.readCache(name).isFlying();
} else {
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;
}
if(player.isOp())
operator = true;
else operator = false;
if(player.isFlying())
flying = true;
else flying = false;
}
if(Settings.isForceSurvivalModeEnabled) {
if(Settings.isResetInventoryIfCreative && gameMode != 0 ) {
ResetInventoryEvent event = new ResetInventoryEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
API.setPlayerInventory(player, new ItemStack[36], new ItemStack[4]);
player.sendMessage("Your inventory has been cleaned!");
}
}
gameMode = 0;
}
if(player.isDead()) {
loc = plugin.getSpawnLocation(player.getWorld());
}
try {
if(cache.containsKey(name) && playerGroup.isEmpty()) {
LimboPlayer groupLimbo = cache.get(name);
playerGroup = groupLimbo.getGroup();
}
} catch (NullPointerException ex) {
}
cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup, flying));
}
public void addLimboPlayer(Player player, String group) {
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
}
public void deleteLimboPlayer(String name) {
cache.remove(name);
}
public LimboPlayer getLimboPlayer(String name) {
return cache.get(name);
}
public boolean hasLimboPlayer(String name) {
return cache.containsKey(name);
}
public static LimboCache getInstance() {
if (singleton == null) {
singleton = new LimboCache(AuthMe.getInstance());
}
return singleton;
}
public void updateLimboPlayer(Player player) {
if (this.hasLimboPlayer(player.getName().toLowerCase())) {
this.deleteLimboPlayer(player.getName().toLowerCase());
}
this.addLimboPlayer(player);
}
}