mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-28 05:05:14 +01:00
cache player's flying enabled state.
This commit is contained in:
parent
760d2a9fe6
commit
2f75e03275
@ -6,6 +6,7 @@ public class DataFileCache {
|
|||||||
|
|
||||||
private final String group;
|
private final String group;
|
||||||
private final boolean operator;
|
private final boolean operator;
|
||||||
|
private final boolean flyEnabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for DataFileCache.
|
* Constructor for DataFileCache.
|
||||||
@ -13,9 +14,10 @@ public class DataFileCache {
|
|||||||
* @param group String
|
* @param group String
|
||||||
* @param operator boolean
|
* @param operator boolean
|
||||||
*/
|
*/
|
||||||
public DataFileCache(String group, boolean operator) {
|
public DataFileCache(String group, boolean operator, boolean flyEnabled) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
|
this.flyEnabled = flyEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,4 +37,8 @@ public class DataFileCache {
|
|||||||
public boolean getOperator() {
|
public boolean getOperator() {
|
||||||
return operator;
|
return operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFlyEnabled() {
|
||||||
|
return flyEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -30,12 +38,6 @@ public class JsonCache {
|
|||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method createCache.
|
|
||||||
*
|
|
||||||
* @param player Player
|
|
||||||
* @param playerData DataFileCache
|
|
||||||
*/
|
|
||||||
public void createCache(Player player, DataFileCache playerData) {
|
public void createCache(Player player, DataFileCache playerData) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
@ -65,13 +67,6 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method readCache.
|
|
||||||
*
|
|
||||||
* @param player Player
|
|
||||||
*
|
|
||||||
* @return DataFileCache
|
|
||||||
*/
|
|
||||||
public DataFileCache readCache(Player player) {
|
public DataFileCache readCache(Player player) {
|
||||||
String path;
|
String path;
|
||||||
try {
|
try {
|
||||||
@ -94,11 +89,6 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method removeCache.
|
|
||||||
*
|
|
||||||
* @param player Player
|
|
||||||
*/
|
|
||||||
public void removeCache(Player player) {
|
public void removeCache(Player player) {
|
||||||
String path;
|
String path;
|
||||||
try {
|
try {
|
||||||
@ -115,13 +105,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 +116,39 @@ public class JsonCache {
|
|||||||
return file.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
|
||||||
*/
|
|
||||||
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 DataFileCache 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 DataFileCache(group, operator, fly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
|
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(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("group", dataFileCache.getGroup());
|
jsonObject.addProperty("group", dataFileCache.getGroup());
|
||||||
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
||||||
|
jsonObject.addProperty("fly", dataFileCache.isFlyEnabled());
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ public class LimboCache {
|
|||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
boolean operator = false;
|
boolean operator = false;
|
||||||
|
boolean flyEnabled = false;
|
||||||
String playerGroup = "";
|
String playerGroup = "";
|
||||||
|
|
||||||
// Get the permissions manager, and make sure it's valid
|
// Get the permissions manager, and make sure it's valid
|
||||||
@ -66,30 +67,22 @@ public class LimboCache {
|
|||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
playerGroup = cache.getGroup();
|
playerGroup = cache.getGroup();
|
||||||
operator = cache.getOperator();
|
operator = cache.getOperator();
|
||||||
|
flyEnabled = cache.isFlyEnabled();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
operator = player.isOp();
|
operator = player.isOp();
|
||||||
|
|
||||||
// Check whether groups are supported
|
// Check whether groups are supported
|
||||||
if (permsMan.hasGroupSupport())
|
if (permsMan.hasGroupSupport()) {
|
||||||
playerGroup = permsMan.getPrimaryGroup(player);
|
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user