mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-28 05:05:14 +01:00
commit
1afe41d787
@ -664,13 +664,19 @@ public class AuthMe extends JavaPlugin {
|
||||
inventoryProtector.unregister();
|
||||
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.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.register();
|
||||
} else if (inventoryProtector != null) {
|
||||
tablistHider.unregister();
|
||||
tablistHider = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -2,7 +2,15 @@ package fr.xephi.authme.cache.backup;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
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.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,8 +19,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class JsonCache {
|
||||
|
||||
private final Gson gson;
|
||||
@ -24,19 +30,13 @@ public class JsonCache {
|
||||
ConsoleLogger.showError("Failed to create cache directory.");
|
||||
}
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer())
|
||||
.registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer())
|
||||
.registerTypeAdapter(PlayerData.class, new PlayerDataSerializer())
|
||||
.registerTypeAdapter(PlayerData.class, new PlayerDataDeserializer())
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method createCache.
|
||||
*
|
||||
* @param player Player
|
||||
* @param playerData DataFileCache
|
||||
*/
|
||||
public void createCache(Player player, DataFileCache playerData) {
|
||||
public void createCache(Player player, PlayerData playerData) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
@ -65,14 +65,7 @@ public class JsonCache {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method readCache.
|
||||
*
|
||||
* @param player Player
|
||||
*
|
||||
* @return DataFileCache
|
||||
*/
|
||||
public DataFileCache readCache(Player player) {
|
||||
public PlayerData readCache(Player player) {
|
||||
String path;
|
||||
try {
|
||||
path = player.getUniqueId().toString();
|
||||
@ -87,18 +80,13 @@ public class JsonCache {
|
||||
|
||||
try {
|
||||
String str = Files.toString(file, Charsets.UTF_8);
|
||||
return gson.fromJson(str, DataFileCache.class);
|
||||
return gson.fromJson(str, PlayerData.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method removeCache.
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void removeCache(Player player) {
|
||||
String path;
|
||||
try {
|
||||
@ -115,13 +103,6 @@ public class JsonCache {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method doesCacheExist.
|
||||
*
|
||||
* @param player Player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean doesCacheExist(Player player) {
|
||||
String path;
|
||||
try {
|
||||
@ -133,57 +114,40 @@ public class JsonCache {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
private class PlayerDataDeserializer implements JsonDeserializer<PlayerData> {
|
||||
@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();
|
||||
if (jsonObject == null) {
|
||||
return null;
|
||||
}
|
||||
JsonElement e;
|
||||
String group = null;
|
||||
boolean operator = false;
|
||||
boolean fly = false;
|
||||
|
||||
JsonElement e;
|
||||
if ((e = jsonObject.get("group")) != null) {
|
||||
group = e.getAsString();
|
||||
}
|
||||
if ((e = jsonObject.get("operator")) != null) {
|
||||
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<DataFileCache> {
|
||||
/**
|
||||
* Method serialize.
|
||||
*
|
||||
* @param dataFileCache DataFileCache
|
||||
* @param type Type
|
||||
* @param jsonSerializationContext JsonSerializationContext
|
||||
*
|
||||
* @return JsonElement
|
||||
*/
|
||||
private class PlayerDataSerializer implements JsonSerializer<PlayerData> {
|
||||
@Override
|
||||
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
public JsonElement serialize(PlayerData playerData, Type type,
|
||||
JsonSerializationContext jsonSerializationContext) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("group", dataFileCache.getGroup());
|
||||
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
||||
|
||||
jsonObject.addProperty("group", playerData.getGroup());
|
||||
jsonObject.addProperty("operator", playerData.getOperator());
|
||||
jsonObject.addProperty("fly", playerData.isFlyEnabled());
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
26
src/main/java/fr/xephi/authme/cache/backup/PlayerData.java
vendored
Normal file
26
src/main/java/fr/xephi/authme/cache/backup/PlayerData.java
vendored
Normal 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;
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package fr.xephi.authme.cache.limbo;
|
||||
|
||||
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.PlayerData;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -19,7 +18,7 @@ public class LimboCache {
|
||||
private volatile static LimboCache singleton;
|
||||
public final ConcurrentHashMap<String, LimboPlayer> cache;
|
||||
public final AuthMe plugin;
|
||||
private final JsonCache playerData;
|
||||
private final JsonCache jsonCache;
|
||||
|
||||
/**
|
||||
* Constructor for LimboCache.
|
||||
@ -29,7 +28,7 @@ public class LimboCache {
|
||||
private LimboCache(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.cache = new ConcurrentHashMap<>();
|
||||
this.playerData = new JsonCache();
|
||||
this.jsonCache = new JsonCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,44 +51,28 @@ public class LimboCache {
|
||||
public void addLimboPlayer(Player player) {
|
||||
String name = player.getName().toLowerCase();
|
||||
Location loc = player.getLocation();
|
||||
boolean operator = false;
|
||||
boolean operator = player.isOp();
|
||||
boolean flyEnabled = player.getAllowFlight();
|
||||
String playerGroup = "";
|
||||
PermissionsManager permsMan = plugin.getPermissionsManager();
|
||||
if (permsMan.hasGroupSupport()) {
|
||||
playerGroup = permsMan.getPrimaryGroup(player);
|
||||
}
|
||||
|
||||
// Get the permissions manager, and make sure it's valid
|
||||
PermissionsManager permsMan = this.plugin.getPermissionsManager();
|
||||
if (permsMan == null)
|
||||
ConsoleLogger.showError("Unable to access permissions manager!");
|
||||
assert permsMan != null;
|
||||
|
||||
if (playerData.doesCacheExist(player)) {
|
||||
DataFileCache cache = playerData.readCache(player);
|
||||
if (jsonCache.doesCacheExist(player)) {
|
||||
PlayerData cache = jsonCache.readCache(player);
|
||||
if (cache != null) {
|
||||
playerGroup = cache.getGroup();
|
||||
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()) {
|
||||
loc = plugin.getSpawnLocation(player);
|
||||
}
|
||||
|
||||
cache.put(name, new LimboPlayer(name, loc, operator, playerGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
cache.put(name, new LimboPlayer(name, loc, operator, playerGroup, flyEnabled));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,7 +82,11 @@ public class LimboCache {
|
||||
*/
|
||||
public void deleteLimboPlayer(String name) {
|
||||
checkNotNull(name);
|
||||
cache.remove(name.toLowerCase());
|
||||
name = name.toLowerCase();
|
||||
if (cache.containsKey(name)) {
|
||||
cache.get(name).clearTask();
|
||||
cache.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,37 +8,20 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
public class LimboPlayer {
|
||||
|
||||
private final String name;
|
||||
private final boolean fly;
|
||||
private Location loc = null;
|
||||
private BukkitTask timeoutTaskId = null;
|
||||
private BukkitTask messageTaskId = null;
|
||||
private boolean operator = false;
|
||||
private String group = "";
|
||||
private String group;
|
||||
|
||||
/**
|
||||
* Constructor for LimboPlayer.
|
||||
*
|
||||
* @param name String
|
||||
* @param loc Location
|
||||
* @param operator boolean
|
||||
* @param group String
|
||||
*/
|
||||
public LimboPlayer(String name, Location loc,
|
||||
boolean operator, String group) {
|
||||
public LimboPlayer(String name, Location loc, boolean operator,
|
||||
String group, boolean fly) {
|
||||
this.name = name;
|
||||
this.loc = loc;
|
||||
this.operator = operator;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for LimboPlayer.
|
||||
*
|
||||
* @param name String
|
||||
* @param group String
|
||||
*/
|
||||
public LimboPlayer(String name, String group) {
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.fly = fly;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,11 +60,10 @@ public class LimboPlayer {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getTimeoutTaskId.
|
||||
*
|
||||
* @return BukkitTask
|
||||
*/
|
||||
public boolean isFly() {
|
||||
return fly;
|
||||
}
|
||||
|
||||
public BukkitTask getTimeoutTaskId() {
|
||||
return timeoutTaskId;
|
||||
}
|
||||
@ -121,7 +103,6 @@ public class LimboPlayer {
|
||||
|
||||
/**
|
||||
* Method clearTask.
|
||||
*
|
||||
*/
|
||||
public void clearTask() {
|
||||
if (messageTaskId != null) {
|
||||
|
@ -81,6 +81,8 @@ public class AuthMeServerListener implements Listener {
|
||||
}
|
||||
if (pluginName.equalsIgnoreCase("ProtocolLib")) {
|
||||
plugin.inventoryProtector = null;
|
||||
plugin.tablistHider = null;
|
||||
plugin.tabComplete = null;
|
||||
ConsoleLogger.showError("ProtocolLib has been disabled, unhook packet inventory protection!");
|
||||
}
|
||||
}
|
||||
|
@ -6,32 +6,27 @@ import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
|
||||
public class AuthMeTabCompletePacketAdapter extends PacketAdapter {
|
||||
|
||||
public AuthMeTabCompletePacketAdapter(AuthMe plugin) {
|
||||
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE);
|
||||
}
|
||||
public AuthMeTabCompletePacketAdapter(AuthMe plugin) {
|
||||
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event)
|
||||
{
|
||||
if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
|
||||
try
|
||||
{
|
||||
if (!PlayerCache.getInstance().isAuthenticated(event.getPlayer().getName().toLowerCase())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
|
||||
try {
|
||||
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() {
|
||||
|
@ -6,32 +6,27 @@ import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
|
||||
public class AuthMeTablistPacketAdapter extends PacketAdapter {
|
||||
|
||||
public AuthMeTablistPacketAdapter(AuthMe plugin) {
|
||||
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO);
|
||||
}
|
||||
public AuthMeTablistPacketAdapter(AuthMe plugin) {
|
||||
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
|
||||
try
|
||||
{
|
||||
if (!PlayerCache.getInstance().isAuthenticated(event.getPlayer().getName().toLowerCase())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
|
||||
try {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user