Adding Caches
Dieser Commit ist enthalten in:
Ursprung
dd0829ece5
Commit
cecd3edfe5
@ -2,6 +2,10 @@ package de.warking.hunjy;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sun.net.httpserver.BasicAuthenticator;
|
||||
import de.warking.hunjy.MySQL.Bauwelt;
|
||||
import de.warking.hunjy.MySQL.BauweltMember;
|
||||
import de.warking.hunjy.MySQL.WarkingUser;
|
||||
import de.warking.hunjy.PlayerManager.PlayerManager;
|
||||
import de.warking.hunjy.PlayerManager.events.ChattingEvent;
|
||||
import de.warking.hunjy.PlayerManager.events.PlayerJoin;
|
||||
@ -54,6 +58,12 @@ public class Core extends JavaPlugin{
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
||||
WarkingUser.clearCache();
|
||||
Bauwelt.clearCache();
|
||||
BauweltMember.clearCache();
|
||||
}, 72000, 72000);
|
||||
}
|
||||
|
||||
public static Core getInstance() {
|
||||
|
@ -2,6 +2,8 @@ package de.warking.hunjy.MySQL;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.warking.hunjy.Core.sql;
|
||||
@ -11,11 +13,13 @@ public class Bauwelt {
|
||||
private final int UserID;
|
||||
private boolean TNTDmg;
|
||||
private boolean FireDmg;
|
||||
private static final List<Bauwelt> bauweltCache = new ArrayList<>();
|
||||
|
||||
private Bauwelt(int userID, boolean tntDmg, boolean fireDmg, boolean updateDB){
|
||||
UserID = userID;
|
||||
TNTDmg = tntDmg;
|
||||
FireDmg = fireDmg;
|
||||
bauweltCache.add(this);
|
||||
if(updateDB)
|
||||
updateDB();
|
||||
}
|
||||
@ -42,6 +46,9 @@ public class Bauwelt {
|
||||
}
|
||||
|
||||
public static Bauwelt getBauwelt(int userId){
|
||||
for(Bauwelt b : bauweltCache)
|
||||
if(b.UserID == userId)
|
||||
return b;
|
||||
ResultSet bauwelt = sql.select("SELECT * FROM Bauwelt WHERE UserID = '" + userId + "'");
|
||||
try {
|
||||
if(bauwelt == null || !bauwelt.next()){
|
||||
@ -81,4 +88,8 @@ public class Bauwelt {
|
||||
FireDmg = fireDmg;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public static void clearCache(){
|
||||
bauweltCache.clear();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ public class BauweltMember{
|
||||
private boolean WorldEdit;
|
||||
private boolean Testblock;
|
||||
|
||||
private static List<BauweltMember> memberCache = new ArrayList<>();
|
||||
|
||||
private BauweltMember(int bauweltID, int memberID, boolean build, boolean changeGM, boolean teleport, boolean worldEdit, boolean testblock, boolean updateDB){
|
||||
BauweltID = bauweltID;
|
||||
MemberID = memberID;
|
||||
@ -25,6 +27,7 @@ public class BauweltMember{
|
||||
Teleport = teleport;
|
||||
WorldEdit = worldEdit;
|
||||
Testblock = testblock;
|
||||
memberCache.add(this);
|
||||
if(updateDB)
|
||||
updateDB();
|
||||
}
|
||||
@ -144,4 +147,8 @@ public class BauweltMember{
|
||||
Testblock = testblock;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public static void clearCache(){
|
||||
memberCache.clear();
|
||||
}
|
||||
}
|
||||
|
@ -90,11 +90,7 @@ public class WarkingUser {
|
||||
return offline;
|
||||
}
|
||||
|
||||
public static void remove(Player player){
|
||||
for(int i = 0; i < allUsers.size(); i++)
|
||||
if(allUsers.get(i).UUID.equals(player.getUniqueId())){
|
||||
allUsers.remove(i);
|
||||
return;
|
||||
}
|
||||
public static void clearCache(){
|
||||
allUsers.clear();
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public class PlayerJoin implements Listener{
|
||||
@EventHandler
|
||||
private void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
WarkingUser.remove(player);
|
||||
|
||||
event.setQuitMessage("§c§l« §r" + player.getDisplayName());
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren