forked from SteamWar/SteamWar
Remove some strain on the Database
This commit is contained in:
+20
-15
@@ -23,15 +23,32 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.BauServer;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.data.BauLockState;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.network.packets.PacketHandler;
|
||||
import de.steamwar.network.packets.server.BaulockUpdatePacket;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class BauLockStateScoreboard implements ScoreboardElement {
|
||||
public class BauLockStateScoreboard extends PacketHandler implements ScoreboardElement {
|
||||
|
||||
private static final String BAU_LOCK_CONFIG_NAME = "baulockstate";
|
||||
|
||||
@Getter
|
||||
private BauLockState lockState = loadLockState();
|
||||
|
||||
private BauLockState loadLockState() {
|
||||
String state = UserConfig.getConfig(BauServer.getInstance().getOwner(), BAU_LOCK_CONFIG_NAME);
|
||||
return state == null ? BauLockState.OPEN : BauLockState.valueOf(state);
|
||||
}
|
||||
|
||||
@Handler
|
||||
public void handleBaulockUpdatePacket(BaulockUpdatePacket packet) {
|
||||
lockState = loadLockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreboardGroup getGroup() {
|
||||
return ScoreboardGroup.FOOTER;
|
||||
@@ -47,23 +64,11 @@ public class BauLockStateScoreboard implements ScoreboardElement {
|
||||
if (!BauServer.getInstance().getOwner().equals(p.getUniqueId())) {
|
||||
return null;
|
||||
}
|
||||
String state = UserConfig.getConfig(p.getUniqueId(), BAU_LOCK_CONFIG_NAME);
|
||||
switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) {
|
||||
switch (lockState) {
|
||||
case OPEN:
|
||||
return null;
|
||||
default:
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOCK_" + state.toUpperCase(), p);
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOCK_" + lockState.name(), p);
|
||||
}
|
||||
}
|
||||
|
||||
public enum BauLockState {
|
||||
|
||||
NOBODY,
|
||||
SUPERVISOR,
|
||||
SERVERTEAM,
|
||||
TEAM_AND_SERVERTEAM,
|
||||
TEAM,
|
||||
OPEN
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user