mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 04:35:12 +01:00
Begin rework of Cache
This commit is contained in:
parent
4193806c82
commit
e9032d1739
@ -562,8 +562,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
this.plugin.getServer().getScheduler()
|
this.plugin.getServer().getScheduler()
|
||||||
.cancelTask(limbo.getTimeoutTaskId());
|
.cancelTask(limbo.getTimeoutTaskId());
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
if (this.playerBackup.doesCacheExist(name)) {
|
if (this.playerBackup.doesCacheExist(player)) {
|
||||||
this.playerBackup.removeCache(name);
|
this.playerBackup.removeCache(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
|
@ -2,13 +2,13 @@ package fr.xephi.authme.cache.backup;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
@ -26,8 +26,9 @@ public class FileCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createCache(String playername, DataFileCache playerData,
|
public void createCache(Player player, DataFileCache playerData,
|
||||||
String group, boolean operator, boolean flying) {
|
String group, boolean operator, boolean flying) {
|
||||||
|
String playername = player.getName();
|
||||||
final File file = new File("cache/" + playername + ".cache");
|
final File file = new File("cache/" + playername + ".cache");
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -132,8 +133,13 @@ public class FileCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataFileCache readCache(String playername) {
|
public DataFileCache readCache(Player player) {
|
||||||
final File file = new File("cache/" + playername + ".cache");
|
String playername = player.getName();
|
||||||
|
File file = new File("cache/" + playername + ".cache");
|
||||||
|
if (!file.exists()) {
|
||||||
|
playername = player.getName().toLowerCase();
|
||||||
|
file = new File("cache/" + playername + ".cache");
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack[] stacki = new ItemStack[36];
|
ItemStack[] stacki = new ItemStack[36];
|
||||||
ItemStack[] stacka = new ItemStack[4];
|
ItemStack[] stacka = new ItemStack[4];
|
||||||
@ -252,16 +258,26 @@ public class FileCache {
|
|||||||
return new DataFileCache(stacki, stacka, group, op, flying);
|
return new DataFileCache(stacki, stacka, group, op, flying);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCache(String playername) {
|
public void removeCache(Player player) {
|
||||||
final File file = new File("cache/" + playername + ".cache");
|
String playername = player.getName();
|
||||||
|
File file = new File("cache/" + playername + ".cache");
|
||||||
|
if (!file.exists()) {
|
||||||
|
playername = player.getName().toLowerCase();
|
||||||
|
file = new File("cache/" + playername + ".cache");
|
||||||
|
}
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesCacheExist(String playername) {
|
public boolean doesCacheExist(Player player) {
|
||||||
final File file = new File("cache/" + playername + ".cache");
|
String playername = player.getName();
|
||||||
|
File file = new File("cache/" + playername + ".cache");
|
||||||
|
if (!file.exists()) {
|
||||||
|
playername = player.getName().toLowerCase();
|
||||||
|
file = new File("cache/" + playername + ".cache");
|
||||||
|
}
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,7 +37,7 @@ public class LimboCache {
|
|||||||
String playerGroup = "";
|
String playerGroup = "";
|
||||||
boolean flying;
|
boolean flying;
|
||||||
|
|
||||||
if (playerData.doesCacheExist(name)) {
|
if (playerData.doesCacheExist(player)) {
|
||||||
StoreInventoryEvent event = new StoreInventoryEvent(player,
|
StoreInventoryEvent event = new StoreInventoryEvent(player,
|
||||||
playerData);
|
playerData);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
@ -49,9 +49,9 @@ public class LimboCache {
|
|||||||
inv = null;
|
inv = null;
|
||||||
arm = null;
|
arm = null;
|
||||||
}
|
}
|
||||||
playerGroup = playerData.readCache(name).getGroup();
|
playerGroup = playerData.readCache(player).getGroup();
|
||||||
operator = playerData.readCache(name).getOperator();
|
operator = playerData.readCache(player).getOperator();
|
||||||
flying = playerData.readCache(name).isFlying();
|
flying = playerData.readCache(player).isFlying();
|
||||||
} else {
|
} else {
|
||||||
StoreInventoryEvent event = new StoreInventoryEvent(player);
|
StoreInventoryEvent event = new StoreInventoryEvent(player);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
@ -92,7 +92,7 @@ public class LogoutCommand implements CommandExecutor {
|
|||||||
DataFileCache playerData = new DataFileCache(LimboCache
|
DataFileCache playerData = new DataFileCache(LimboCache
|
||||||
.getInstance().getLimboPlayer(name).getInventory(),
|
.getInstance().getLimboPlayer(name).getInventory(),
|
||||||
LimboCache.getInstance().getLimboPlayer(name).getArmour());
|
LimboCache.getInstance().getLimboPlayer(name).getArmour());
|
||||||
playerBackup.createCache(name, playerData, LimboCache.getInstance()
|
playerBackup.createCache(player, playerData, LimboCache.getInstance()
|
||||||
.getLimboPlayer(name).getGroup(), LimboCache.getInstance()
|
.getLimboPlayer(name).getGroup(), LimboCache.getInstance()
|
||||||
.getLimboPlayer(name).getOperator(), LimboCache
|
.getLimboPlayer(name).getOperator(), LimboCache
|
||||||
.getInstance().getLimboPlayer(name).isFlying());
|
.getInstance().getLimboPlayer(name).isFlying());
|
||||||
|
@ -128,8 +128,8 @@ public class UnregisterCommand implements CommandExecutor {
|
|||||||
player.getName().toLowerCase());
|
player.getName().toLowerCase());
|
||||||
// check if Player cache File Exist and delete it, preventing
|
// check if Player cache File Exist and delete it, preventing
|
||||||
// duplication of items
|
// duplication of items
|
||||||
if (playerCache.doesCacheExist(name)) {
|
if (playerCache.doesCacheExist(player)) {
|
||||||
playerCache.removeCache(name);
|
playerCache.removeCache(player);
|
||||||
}
|
}
|
||||||
if (Settings.applyBlindEffect) player
|
if (Settings.applyBlindEffect) player
|
||||||
.addPotionEffect(new PotionEffect(
|
.addPotionEffect(new PotionEffect(
|
||||||
|
@ -23,9 +23,9 @@ public class StoreInventoryEvent extends CustomEvent {
|
|||||||
|
|
||||||
public StoreInventoryEvent(Player player, FileCache fileCache) {
|
public StoreInventoryEvent(Player player, FileCache fileCache) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.inventory = fileCache.readCache(player.getName().toLowerCase())
|
this.inventory = fileCache.readCache(player)
|
||||||
.getInventory();
|
.getInventory();
|
||||||
this.armor = fileCache.readCache(player.getName().toLowerCase())
|
this.armor = fileCache.readCache(player)
|
||||||
.getArmour();
|
.getArmour();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
DataFileCache dataFile = new DataFileCache(LimboCache.getInstance()
|
DataFileCache dataFile = new DataFileCache(LimboCache.getInstance()
|
||||||
.getLimboPlayer(name).getInventory(), LimboCache
|
.getLimboPlayer(name).getInventory(), LimboCache
|
||||||
.getInstance().getLimboPlayer(name).getArmour());
|
.getInstance().getLimboPlayer(name).getArmour());
|
||||||
playerBackup.createCache(name, dataFile, LimboCache.getInstance()
|
playerBackup.createCache(player, dataFile, LimboCache.getInstance()
|
||||||
.getLimboPlayer(name).getGroup(), LimboCache.getInstance()
|
.getLimboPlayer(name).getGroup(), LimboCache.getInstance()
|
||||||
.getLimboPlayer(name).getOperator(), LimboCache
|
.getLimboPlayer(name).getOperator(), LimboCache
|
||||||
.getInstance().getLimboPlayer(name).isFlying());
|
.getInstance().getLimboPlayer(name).isFlying());
|
||||||
@ -848,8 +848,8 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
this.plugin.getServer().getScheduler()
|
this.plugin.getServer().getScheduler()
|
||||||
.cancelTask(limbo.getMessageTaskId());
|
.cancelTask(limbo.getMessageTaskId());
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
if (playerBackup.doesCacheExist(name)) {
|
if (playerBackup.doesCacheExist(player)) {
|
||||||
playerBackup.removeCache(name);
|
playerBackup.removeCache(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
@ -950,8 +950,8 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
this.plugin.getServer().getScheduler()
|
this.plugin.getServer().getScheduler()
|
||||||
.cancelTask(limbo.getMessageTaskId());
|
.cancelTask(limbo.getMessageTaskId());
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
if (this.playerBackup.doesCacheExist(name)) {
|
if (this.playerBackup.doesCacheExist(player)) {
|
||||||
this.playerBackup.removeCache(name);
|
this.playerBackup.removeCache(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
|
@ -179,8 +179,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
|||||||
|
|
||||||
// Cleanup no longer used temporary data
|
// Cleanup no longer used temporary data
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
if (playerCache.doesCacheExist(name)) {
|
if (playerCache.doesCacheExist(player)) {
|
||||||
playerCache.removeCache(name);
|
playerCache.removeCache(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ public class TimeoutTask implements Runnable {
|
|||||||
.cancelTask(inv.getMessageTaskId());
|
.cancelTask(inv.getMessageTaskId());
|
||||||
player.getServer().getScheduler()
|
player.getServer().getScheduler()
|
||||||
.cancelTask(inv.getTimeoutTaskId());
|
.cancelTask(inv.getTimeoutTaskId());
|
||||||
if (playerCache.doesCacheExist(name)) {
|
if (playerCache.doesCacheExist(player)) {
|
||||||
playerCache.removeCache(name);
|
playerCache.removeCache(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameMode gm = AuthMePlayerListener.gameMode.get(name);
|
GameMode gm = AuthMePlayerListener.gameMode.get(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user