Merge pull request #107 from AuthMe-Team/reload-supp

Reload supp
This commit is contained in:
DNx 2016-02-22 01:07:07 +07:00
commit 1afe41d787
9 changed files with 117 additions and 199 deletions

View File

@ -664,13 +664,19 @@ public class AuthMe extends JavaPlugin {
inventoryProtector.unregister(); inventoryProtector.unregister();
inventoryProtector = null; inventoryProtector = null;
} }
if (tabComplete == null && newSettings.getProperty(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN)) { if (newSettings.getProperty(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN) && tabComplete == null) {
tabComplete = new AuthMeTabCompletePacketAdapter(this); tabComplete = new AuthMeTabCompletePacketAdapter(this);
tabComplete.register(); tabComplete.register();
} else if (inventoryProtector != null) {
tabComplete.unregister();
tabComplete = null;
} }
if (tablistHider == null && newSettings.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN)) { if (newSettings.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && tablistHider == null) {
tablistHider = new AuthMeTablistPacketAdapter(this); tablistHider = new AuthMeTablistPacketAdapter(this);
tablistHider.register(); tablistHider.register();
} else if (inventoryProtector != null) {
tablistHider.unregister();
tablistHider = null;
} }
} }

View File

@ -1,38 +0,0 @@
package fr.xephi.authme.cache.backup;
/**
*/
public class DataFileCache {
private final String group;
private final boolean operator;
/**
* Constructor for DataFileCache.
*
* @param group String
* @param operator boolean
*/
public DataFileCache(String group, boolean operator) {
this.group = group;
this.operator = operator;
}
/**
* Method getGroup.
*
* @return String
*/
public String getGroup() {
return group;
}
/**
* Method getOperator.
*
* @return boolean
*/
public boolean getOperator() {
return operator;
}
}

View File

@ -2,7 +2,15 @@ package fr.xephi.authme.cache.backup;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.gson.*; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,8 +19,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
/**
*/
public class JsonCache { public class JsonCache {
private final Gson gson; private final Gson gson;
@ -24,19 +30,13 @@ public class JsonCache {
ConsoleLogger.showError("Failed to create cache directory."); ConsoleLogger.showError("Failed to create cache directory.");
} }
gson = new GsonBuilder() gson = new GsonBuilder()
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) .registerTypeAdapter(PlayerData.class, new PlayerDataSerializer())
.registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer()) .registerTypeAdapter(PlayerData.class, new PlayerDataDeserializer())
.setPrettyPrinting() .setPrettyPrinting()
.create(); .create();
} }
/** public void createCache(Player player, PlayerData playerData) {
* Method createCache.
*
* @param player Player
* @param playerData DataFileCache
*/
public void createCache(Player player, DataFileCache playerData) {
if (player == null) { if (player == null) {
return; return;
} }
@ -65,14 +65,7 @@ public class JsonCache {
} }
} }
/** public PlayerData readCache(Player player) {
* Method readCache.
*
* @param player Player
*
* @return DataFileCache
*/
public DataFileCache readCache(Player player) {
String path; String path;
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
@ -87,18 +80,13 @@ public class JsonCache {
try { try {
String str = Files.toString(file, Charsets.UTF_8); String str = Files.toString(file, Charsets.UTF_8);
return gson.fromJson(str, DataFileCache.class); return gson.fromJson(str, PlayerData.class);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
/**
* Method removeCache.
*
* @param player Player
*/
public void removeCache(Player player) { public void removeCache(Player player) {
String path; String path;
try { try {
@ -115,13 +103,6 @@ public class JsonCache {
} }
} }
/**
* Method doesCacheExist.
*
* @param player Player
*
* @return boolean
*/
public boolean doesCacheExist(Player player) { public boolean doesCacheExist(Player player) {
String path; String path;
try { try {
@ -133,57 +114,40 @@ public class JsonCache {
return file.exists(); return file.exists();
} }
/** private class PlayerDataDeserializer implements JsonDeserializer<PlayerData> {
*/
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
/**
* Method deserialize.
*
* @param jsonElement JsonElement
* @param type Type
* @param jsonDeserializationContext JsonDeserializationContext
*
* @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)
*/
@Override @Override
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { public PlayerData deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject == null) { if (jsonObject == null) {
return null; return null;
} }
JsonElement e;
String group = null; String group = null;
boolean operator = false; boolean operator = false;
boolean fly = false;
JsonElement e;
if ((e = jsonObject.get("group")) != null) { if ((e = jsonObject.get("group")) != null) {
group = e.getAsString(); group = e.getAsString();
} }
if ((e = jsonObject.get("operator")) != null) { if ((e = jsonObject.get("operator")) != null) {
operator = e.getAsBoolean(); operator = e.getAsBoolean();
} }
if ((e = jsonObject.get("fly")) != null) {
fly = e.getAsBoolean();
}
return new DataFileCache(group, operator); return new PlayerData(group, operator, fly);
} }
} }
/** private class PlayerDataSerializer implements JsonSerializer<PlayerData> {
*/
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
/**
* Method serialize.
*
* @param dataFileCache DataFileCache
* @param type Type
* @param jsonSerializationContext JsonSerializationContext
*
* @return JsonElement
*/
@Override @Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) { public JsonElement serialize(PlayerData playerData, Type type,
JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup()); jsonObject.addProperty("group", playerData.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator()); jsonObject.addProperty("operator", playerData.getOperator());
jsonObject.addProperty("fly", playerData.isFlyEnabled());
return jsonObject; return jsonObject;
} }
} }

View File

@ -0,0 +1,26 @@
package fr.xephi.authme.cache.backup;
public class PlayerData {
private final String group;
private final boolean operator;
private final boolean flyEnabled;
public PlayerData(String group, boolean operator, boolean flyEnabled) {
this.group = group;
this.operator = operator;
this.flyEnabled = flyEnabled;
}
public String getGroup() {
return group;
}
public boolean getOperator() {
return operator;
}
public boolean isFlyEnabled() {
return flyEnabled;
}
}

View File

@ -1,9 +1,8 @@
package fr.xephi.authme.cache.limbo; package fr.xephi.authme.cache.limbo;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.backup.DataFileCache;
import fr.xephi.authme.cache.backup.JsonCache; import fr.xephi.authme.cache.backup.JsonCache;
import fr.xephi.authme.cache.backup.PlayerData;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -19,7 +18,7 @@ public class LimboCache {
private volatile static LimboCache singleton; private volatile static LimboCache singleton;
public final ConcurrentHashMap<String, LimboPlayer> cache; public final ConcurrentHashMap<String, LimboPlayer> cache;
public final AuthMe plugin; public final AuthMe plugin;
private final JsonCache playerData; private final JsonCache jsonCache;
/** /**
* Constructor for LimboCache. * Constructor for LimboCache.
@ -29,7 +28,7 @@ public class LimboCache {
private LimboCache(AuthMe plugin) { private LimboCache(AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
this.cache = new ConcurrentHashMap<>(); this.cache = new ConcurrentHashMap<>();
this.playerData = new JsonCache(); this.jsonCache = new JsonCache();
} }
/** /**
@ -52,44 +51,28 @@ public class LimboCache {
public void addLimboPlayer(Player player) { public void addLimboPlayer(Player player) {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
Location loc = player.getLocation(); Location loc = player.getLocation();
boolean operator = false; boolean operator = player.isOp();
boolean flyEnabled = player.getAllowFlight();
String playerGroup = ""; String playerGroup = "";
PermissionsManager permsMan = plugin.getPermissionsManager();
if (permsMan.hasGroupSupport()) {
playerGroup = permsMan.getPrimaryGroup(player);
}
// Get the permissions manager, and make sure it's valid if (jsonCache.doesCacheExist(player)) {
PermissionsManager permsMan = this.plugin.getPermissionsManager(); PlayerData cache = jsonCache.readCache(player);
if (permsMan == null)
ConsoleLogger.showError("Unable to access permissions manager!");
assert permsMan != null;
if (playerData.doesCacheExist(player)) {
DataFileCache cache = playerData.readCache(player);
if (cache != null) { if (cache != null) {
playerGroup = cache.getGroup(); playerGroup = cache.getGroup();
operator = cache.getOperator(); operator = cache.getOperator();
flyEnabled = cache.isFlyEnabled();
} }
} else {
operator = player.isOp();
// Check whether groups are supported
if (permsMan.hasGroupSupport())
playerGroup = permsMan.getPrimaryGroup(player);
} }
if (player.isDead()) { if (player.isDead()) {
loc = plugin.getSpawnLocation(player); loc = plugin.getSpawnLocation(player);
} }
cache.put(name, new LimboPlayer(name, loc, operator, playerGroup)); cache.put(name, new LimboPlayer(name, loc, operator, playerGroup, flyEnabled));
}
/**
* Method addLimboPlayer.
*
* @param player Player
* @param group String
*/
public void addLimboPlayer(Player player, String group) {
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
} }
/** /**
@ -99,7 +82,11 @@ public class LimboCache {
*/ */
public void deleteLimboPlayer(String name) { public void deleteLimboPlayer(String name) {
checkNotNull(name); checkNotNull(name);
cache.remove(name.toLowerCase()); name = name.toLowerCase();
if (cache.containsKey(name)) {
cache.get(name).clearTask();
cache.remove(name);
}
} }
/** /**

View File

@ -8,37 +8,20 @@ import org.bukkit.scheduler.BukkitTask;
public class LimboPlayer { public class LimboPlayer {
private final String name; private final String name;
private final boolean fly;
private Location loc = null; private Location loc = null;
private BukkitTask timeoutTaskId = null; private BukkitTask timeoutTaskId = null;
private BukkitTask messageTaskId = null; private BukkitTask messageTaskId = null;
private boolean operator = false; private boolean operator = false;
private String group = ""; private String group;
/** public LimboPlayer(String name, Location loc, boolean operator,
* Constructor for LimboPlayer. String group, boolean fly) {
*
* @param name String
* @param loc Location
* @param operator boolean
* @param group String
*/
public LimboPlayer(String name, Location loc,
boolean operator, String group) {
this.name = name; this.name = name;
this.loc = loc; this.loc = loc;
this.operator = operator; this.operator = operator;
this.group = group; this.group = group;
} this.fly = fly;
/**
* Constructor for LimboPlayer.
*
* @param name String
* @param group String
*/
public LimboPlayer(String name, String group) {
this.name = name;
this.group = group;
} }
/** /**
@ -77,11 +60,10 @@ public class LimboPlayer {
return group; return group;
} }
/** public boolean isFly() {
* Method getTimeoutTaskId. return fly;
* }
* @return BukkitTask
*/
public BukkitTask getTimeoutTaskId() { public BukkitTask getTimeoutTaskId() {
return timeoutTaskId; return timeoutTaskId;
} }
@ -121,7 +103,6 @@ public class LimboPlayer {
/** /**
* Method clearTask. * Method clearTask.
*
*/ */
public void clearTask() { public void clearTask() {
if (messageTaskId != null) { if (messageTaskId != null) {

View File

@ -81,6 +81,8 @@ public class AuthMeServerListener implements Listener {
} }
if (pluginName.equalsIgnoreCase("ProtocolLib")) { if (pluginName.equalsIgnoreCase("ProtocolLib")) {
plugin.inventoryProtector = null; plugin.inventoryProtector = null;
plugin.tablistHider = null;
plugin.tabComplete = null;
ConsoleLogger.showError("ProtocolLib has been disabled, unhook packet inventory protection!"); ConsoleLogger.showError("ProtocolLib has been disabled, unhook packet inventory protection!");
} }
} }

View File

@ -6,32 +6,27 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
public class AuthMeTabCompletePacketAdapter extends PacketAdapter { public class AuthMeTabCompletePacketAdapter extends PacketAdapter {
public AuthMeTabCompletePacketAdapter(AuthMe plugin) { public AuthMeTabCompletePacketAdapter(AuthMe plugin) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE); super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE);
} }
@Override @Override
public void onPacketReceiving(PacketEvent event) public void onPacketReceiving(PacketEvent event) {
{ if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) { try {
try if (!PlayerCache.getInstance().isAuthenticated(event.getPlayer().getName().toLowerCase())) {
{ event.setCancelled(true);
if (!PlayerCache.getInstance().isAuthenticated(event.getPlayer().getName().toLowerCase())) { }
event.setCancelled(true); } catch (FieldAccessException e) {
} ConsoleLogger.showError("Couldn't access field.");
}
} }
catch (FieldAccessException e)
{
ConsoleLogger.showError("Couldn't access field.");
}
}
} }
public void register() { public void register() {

View File

@ -6,32 +6,27 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
public class AuthMeTablistPacketAdapter extends PacketAdapter { public class AuthMeTablistPacketAdapter extends PacketAdapter {
public AuthMeTablistPacketAdapter(AuthMe plugin) { public AuthMeTablistPacketAdapter(AuthMe plugin) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO); super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO);
} }
@Override @Override
public void onPacketSending(PacketEvent event) public void onPacketSending(PacketEvent event) {
{ if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) { try {
try if (!PlayerCache.getInstance().isAuthenticated(event.getPlayer().getName().toLowerCase())) {
{ event.setCancelled(true);
if (!PlayerCache.getInstance().isAuthenticated(event.getPlayer().getName().toLowerCase())) { }
event.setCancelled(true); } catch (FieldAccessException e) {
} ConsoleLogger.showError("Couldn't access field.");
}
} }
catch (FieldAccessException e)
{
ConsoleLogger.showError("Couldn't access field.");
}
}
} }
public void register() { public void register() {