forked from SteamWar/SteamWar
Merge pull request 'Remove some strain on the Database' (#185) from BauSystem/RemoveDatabaseStrain into main
Reviewed-on: SteamWar/SteamWar#185 Reviewed-by: Chaoscaot <max@chaoscaot.de>
This commit is contained in:
+28
-15
@@ -23,15 +23,40 @@ 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.core.CRIUWakeupEvent;
|
||||
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;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@Linked
|
||||
public class BauLockStateScoreboard implements ScoreboardElement {
|
||||
public class BauLockStateScoreboard extends PacketHandler implements ScoreboardElement, Listener {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCRIUWakeup(CRIUWakeupEvent event) {
|
||||
lockState = loadLockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreboardGroup getGroup() {
|
||||
return ScoreboardGroup.FOOTER;
|
||||
@@ -47,23 +72,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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.velocitycore.util;
|
||||
package de.steamwar.data;
|
||||
|
||||
public enum BauLockState {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.network.packets.server;
|
||||
|
||||
import de.steamwar.network.packets.NetworkPacket;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BaulockUpdatePacket extends NetworkPacket {
|
||||
private static final long serialVersionUID = 6863118892424244051L;
|
||||
|
||||
}
|
||||
@@ -24,18 +24,36 @@ import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.type.Light;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class WorldEditRendererCUIEditor implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
for (Type type : Type.values()) {
|
||||
type.materialCache.remove(event.getPlayer());
|
||||
type.widthCache.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCRIUSleep(CRIUSleepEvent event) {
|
||||
for (Type type : Type.values()) {
|
||||
type.materialCache.clear();
|
||||
type.widthCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class WorldEditRendererCUIEditor {
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum Type {
|
||||
@@ -43,34 +61,43 @@ public class WorldEditRendererCUIEditor {
|
||||
CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.SLIM),
|
||||
;
|
||||
|
||||
private final Map<Player, Material> materialCache = new HashMap<>();
|
||||
private final Map<Player, Width> widthCache = new HashMap<>();
|
||||
|
||||
private final String configMaterial;
|
||||
private final String configWidth;
|
||||
private final Material defaultMaterial;
|
||||
private final Width defaultWidth;
|
||||
|
||||
public Material getMaterial(Player player) {
|
||||
String material = UserConfig.getConfig(player.getUniqueId(), configMaterial);
|
||||
if (material == null) {
|
||||
return defaultMaterial;
|
||||
} else {
|
||||
return Material.valueOf(material);
|
||||
}
|
||||
return materialCache.computeIfAbsent(player, p -> {
|
||||
String material = UserConfig.getConfig(p.getUniqueId(), configMaterial);
|
||||
if (material == null) {
|
||||
return defaultMaterial;
|
||||
} else {
|
||||
return Material.valueOf(material);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setMaterial(Player player, Material material) {
|
||||
materialCache.put(player, material);
|
||||
UserConfig.updatePlayerConfig(player.getUniqueId(), configMaterial, material.name());
|
||||
}
|
||||
|
||||
public Width getWidth(Player player) {
|
||||
String width = UserConfig.getConfig(player.getUniqueId(), configWidth);
|
||||
if (width == null) {
|
||||
return defaultWidth;
|
||||
} else {
|
||||
return Width.valueOf(width);
|
||||
}
|
||||
return widthCache.computeIfAbsent(player, p -> {
|
||||
String width = UserConfig.getConfig(p.getUniqueId(), configWidth);
|
||||
if (width == null) {
|
||||
return defaultWidth;
|
||||
} else {
|
||||
return Width.valueOf(width);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setWidth(Player player, Width width) {
|
||||
widthCache.put(player, width);
|
||||
UserConfig.updatePlayerConfig(player.getUniqueId(), configWidth, width.name());
|
||||
}
|
||||
}
|
||||
@@ -88,6 +115,7 @@ public class WorldEditRendererCUIEditor {
|
||||
}
|
||||
|
||||
public WorldEditRendererCUIEditor() {
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
if (Core.getVersion() >= 20) {
|
||||
new Command();
|
||||
}
|
||||
|
||||
@@ -33,14 +33,13 @@ import de.steamwar.messages.PlayerChatter;
|
||||
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
|
||||
import de.steamwar.persistent.Bauserver;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.velocitycore.*;
|
||||
import de.steamwar.velocitycore.inventory.SWInventory;
|
||||
import de.steamwar.velocitycore.inventory.SWItem;
|
||||
import de.steamwar.velocitycore.network.NetworkSender;
|
||||
import de.steamwar.velocitycore.util.BauLock;
|
||||
import de.steamwar.velocitycore.util.BauLockState;
|
||||
import de.steamwar.data.BauLockState;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -19,11 +19,15 @@
|
||||
|
||||
package de.steamwar.velocitycore.util;
|
||||
|
||||
import de.steamwar.data.BauLockState;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.network.packets.server.BaulockUpdatePacket;
|
||||
import de.steamwar.persistent.Bauserver;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import de.steamwar.velocitycore.network.NetworkSender;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
@@ -33,6 +37,10 @@ public class BauLock {
|
||||
public static void setLocked(Chatter owner, BauLockState state) {
|
||||
UserConfig.updatePlayerConfig(owner.user().getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name());
|
||||
owner.system("BAU_LOCKED_" + state.name());
|
||||
|
||||
Bauserver bauserver = Bauserver.get(owner.user().getUUID());
|
||||
if(bauserver != null)
|
||||
bauserver.getRegisteredServer().getPlayersConnected().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaulockUpdatePacket()));
|
||||
}
|
||||
|
||||
public static boolean isLocked(SteamwarUser owner, SteamwarUser target) {
|
||||
|
||||
Reference in New Issue
Block a user