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