cache player's flying enabled state.

This commit is contained in:
DNx5 2016-02-20 08:56:08 +07:00
parent 760d2a9fe6
commit 2f75e03275
4 changed files with 38 additions and 93 deletions

View File

@ -6,6 +6,7 @@ public class DataFileCache {
private final String group;
private final boolean operator;
private final boolean flyEnabled;
/**
* Constructor for DataFileCache.
@ -13,9 +14,10 @@ public class DataFileCache {
* @param group String
* @param operator boolean
*/
public DataFileCache(String group, boolean operator) {
public DataFileCache(String group, boolean operator, boolean flyEnabled) {
this.group = group;
this.operator = operator;
this.flyEnabled = flyEnabled;
}
/**
@ -35,4 +37,8 @@ public class DataFileCache {
public boolean getOperator() {
return operator;
}
public boolean isFlyEnabled() {
return flyEnabled;
}
}

View File

@ -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;
@ -30,12 +38,6 @@ public class JsonCache {
.create();
}
/**
* Method createCache.
*
* @param player Player
* @param playerData DataFileCache
*/
public void createCache(Player player, DataFileCache playerData) {
if (player == null) {
return;
@ -65,13 +67,6 @@ public class JsonCache {
}
}
/**
* Method readCache.
*
* @param player Player
*
* @return DataFileCache
*/
public DataFileCache readCache(Player player) {
String path;
try {
@ -94,11 +89,6 @@ public class JsonCache {
}
}
/**
* Method removeCache.
*
* @param player Player
*/
public void removeCache(Player player) {
String path;
try {
@ -115,13 +105,6 @@ public class JsonCache {
}
}
/**
* Method doesCacheExist.
*
* @param player Player
*
* @return boolean
*/
public boolean doesCacheExist(Player player) {
String path;
try {
@ -133,57 +116,39 @@ 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<DataFileCache> {
@Override
public DataFileCache 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 DataFileCache(group, operator, fly);
}
}
/**
*/
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
/**
* Method serialize.
*
* @param dataFileCache DataFileCache
* @param type Type
* @param jsonSerializationContext JsonSerializationContext
*
* @return JsonElement
*/
@Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator());
jsonObject.addProperty("fly", dataFileCache.isFlyEnabled());
return jsonObject;
}
}

View File

@ -53,6 +53,7 @@ public class LimboCache {
String name = player.getName().toLowerCase();
Location loc = player.getLocation();
boolean operator = false;
boolean flyEnabled = false;
String playerGroup = "";
// Get the permissions manager, and make sure it's valid
@ -66,30 +67,22 @@ public class LimboCache {
if (cache != null) {
playerGroup = cache.getGroup();
operator = cache.getOperator();
flyEnabled = cache.isFlyEnabled();
}
} else {
operator = player.isOp();
// Check whether groups are supported
if (permsMan.hasGroupSupport())
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));
}
/**

View File

@ -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) {