forked from SteamWar/SteamWar
Merge pull request 'Add Unified GameModeConfig' (#176) from UnifiedGameModeConfig into main
Reviewed-on: SteamWar/SteamWar#176 Reviewed-by: D4rkr34lm <dark@steamwar.de> Reviewed-by: Chaoscaot <max@chaoscaot.de>
This commit is contained in:
+1
-1
@@ -129,7 +129,7 @@ public class AutostartListener implements Listener {
|
||||
if (!regionStartTime.containsKey(region)) return;
|
||||
if (!region.getTestblockArea().inRegion(block.getLocation(), true)) return;
|
||||
long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region);
|
||||
long preFightDurationInSeconds = region.getGameModeConfig().getTimes().getPreFightDuration();
|
||||
long preFightDurationInSeconds = region.getGameModeConfig().Times.PreFightDuration;
|
||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff);
|
||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff));
|
||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3");
|
||||
|
||||
+6
-6
@@ -29,10 +29,12 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DesignEndStone {
|
||||
@@ -54,15 +56,13 @@ public class DesignEndStone {
|
||||
this.maxY = region.getBuildArea().getMaxPoint(false).getY();
|
||||
this.maxZ = region.getBuildArea().getMaxPoint(false).getZ();
|
||||
|
||||
limited = region.getGameModeConfig()
|
||||
.getSchematic()
|
||||
.getLimited()
|
||||
limited = region.getGameModeConfig().Schematic.Limited
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue() == 0)
|
||||
.flatMap(entry -> entry.getKey().stream())
|
||||
.collect(Collectors.toSet());
|
||||
calculateFromBottom = region.getGameModeConfig().getArena().isNoFloor();
|
||||
calculateFromBottom = region.getGameModeConfig().Arena.NoFloor;
|
||||
|
||||
entityServer.setCallback((player, rEntity, entityAction) -> {
|
||||
if (entityAction != REntityServer.EntityAction.ATTACK) return;
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener {
|
||||
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
||||
return;
|
||||
}
|
||||
if (!region.getGameModeConfig().isLoaded()) {
|
||||
if (!region.getGameModeConfig().loaded) {
|
||||
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-2
@@ -43,8 +43,8 @@ public class RegionScoreboardElement implements ScoreboardElement {
|
||||
@Override
|
||||
public String get(Region region, Player p) {
|
||||
if (region.getType().isGlobal()) return null;
|
||||
if (!region.getGameModeConfig().isLoaded()) return null;
|
||||
List<String> names = region.getGameModeConfig().getServer().getChatNames();
|
||||
if (!region.getGameModeConfig().loaded) return null;
|
||||
List<String> names = region.getGameModeConfig().Server.ChatNames;
|
||||
if (names.isEmpty()) return null;
|
||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + names.get(0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class RegionLib implements LuaLib {
|
||||
if (rg.getType().isGlobal()) {
|
||||
return "global";
|
||||
}
|
||||
List<String> chatNames = rg.getGameModeConfig().getServer().getChatNames();
|
||||
List<String> chatNames = rg.getGameModeConfig().Server.ChatNames;
|
||||
if (chatNames.isEmpty()) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
|
||||
}
|
||||
|
||||
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
|
||||
if (!region.getGameModeConfig().getTechhider().isActive()) {
|
||||
if (!region.getGameModeConfig().Techhider.Active) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
|
||||
TechHider current = new TechHider((p, cX, cY) -> {
|
||||
if (rg.getBuildArea().isChunkOutside(cX, cY)) return true;
|
||||
return !hidden.get(rg).contains(p);
|
||||
}, region.getGameModeConfig().getTechhider().getObfuscateWith(), region.getGameModeConfig().getTechhider().getHiddenBlocks(), region.getGameModeConfig().getTechhider().getHiddenBlockEntities());
|
||||
}, region.getGameModeConfig().Techhider.ObfuscateWith, region.getGameModeConfig().Techhider.HiddenBlocks, region.getGameModeConfig().Techhider.HiddenBlockEntities);
|
||||
current.enable();
|
||||
|
||||
return Optional.of(current);
|
||||
|
||||
@@ -67,13 +67,13 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
|
||||
}
|
||||
|
||||
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
|
||||
if (!region.getGameModeConfig().getTechhider().isActive()) {
|
||||
if (!region.getGameModeConfig().Techhider.Active) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
hidden.put(rg, new HashSet<>());
|
||||
|
||||
Set<Material> blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().getTechhider().getObfuscateWith()));
|
||||
Set<Material> blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().Techhider.ObfuscateWith));
|
||||
if (blocks.contains(Material.END_STONE)) blocks.add(Material.END_STONE_BRICKS);
|
||||
xrayedBlocks.put(region, blocks);
|
||||
return Optional.of(createXray(rg, blocks));
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* 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.bausystem.region;
|
||||
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class GameModeConfig {
|
||||
|
||||
private final boolean loaded;
|
||||
|
||||
/**
|
||||
* See gamemode config Times key
|
||||
*/
|
||||
private Times Times = new Times();
|
||||
private Schematic Schematic = new Schematic();
|
||||
private Arena Arena = new Arena();
|
||||
private Server Server = new Server();
|
||||
private Techhider Techhider = new Techhider();
|
||||
|
||||
public GameModeConfig(File file) {
|
||||
if (file == null || !file.exists()) {
|
||||
loaded = false;
|
||||
return;
|
||||
}
|
||||
loaded = true;
|
||||
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
Times.load(config.getConfigurationSection("Times"));
|
||||
Schematic.load(config.getConfigurationSection("Schematic"));
|
||||
Arena.load(config.getConfigurationSection("Arena"));
|
||||
Server.load(config.getConfigurationSection("Server"));
|
||||
Techhider.load(config.getConfigurationSection("Techhider"));
|
||||
}
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public static class Times {
|
||||
private int PreFightDuration = 30;
|
||||
|
||||
private void load(ConfigurationSection section) {
|
||||
PreFightDuration = section.getInt("PreFightDuration", 30);
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public static class Schematic {
|
||||
private Map<Set<Material>, Integer> Limited = new HashMap<>();
|
||||
|
||||
private void load(ConfigurationSection section) {
|
||||
for(Map<?, ?> entry : section.getMapList("Limited")) {
|
||||
int amount = (Integer) entry.get("Amount");
|
||||
Set<String> materials = new HashSet<>((List<String>) entry.get("Materials"));
|
||||
if (amount == 0) {
|
||||
materials.forEach(material -> Limited.put(Collections.singleton(Material.getMaterial(material)), 0));
|
||||
} else {
|
||||
Limited.put(materials.stream().map(Material::getMaterial).collect(Collectors.toSet()), amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public static class Arena {
|
||||
private boolean NoFloor = false;
|
||||
|
||||
private void load(ConfigurationSection section) {
|
||||
NoFloor = section.getBoolean("NoFloor", false);
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public static class Server {
|
||||
private List<String> ChatNames;
|
||||
|
||||
private void load(ConfigurationSection section) {
|
||||
ChatNames = section.getStringList("ChatNames");
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public static class Techhider {
|
||||
private boolean Active = false;
|
||||
private Material ObfuscateWith = Material.END_STONE;
|
||||
private Set<Material> HiddenBlocks = new HashSet<>();
|
||||
private Set<String> HiddenBlockEntities = new HashSet<>();
|
||||
|
||||
private void load(ConfigurationSection section) {
|
||||
Active = section.getBoolean("Active", false);
|
||||
ObfuscateWith = Material.getMaterial(section.getString("ObfuscateWith", "END_STONE"));
|
||||
HiddenBlocks = section.getStringList("HiddenBlocks").stream().map(String::toUpperCase).map(FlatteningWrapper.impl::getMaterial).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet());
|
||||
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(section.getStringList("HiddenBlockEntities")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,11 @@ package de.steamwar.bausystem.region;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.sql.GameModeConfig;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
@@ -64,7 +67,7 @@ public interface Region {
|
||||
Area getTestblockArea();
|
||||
|
||||
@NonNull
|
||||
GameModeConfig getGameModeConfig();
|
||||
GameModeConfig<Material, String> getGameModeConfig();
|
||||
|
||||
@NonNull
|
||||
RegionHistory getHistory();
|
||||
|
||||
+4
-4
@@ -22,9 +22,11 @@ package de.steamwar.bausystem.region.fixed;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.region.*;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.sql.GameModeConfig;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
@@ -90,8 +92,6 @@ public final class FixedGlobalRegion implements Region {
|
||||
}
|
||||
};
|
||||
|
||||
private static final GameModeConfig GLOBAL_CONFIG = new GameModeConfig(null);
|
||||
|
||||
private FixedGlobalRegion() {
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ public final class FixedGlobalRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull GameModeConfig getGameModeConfig() {
|
||||
return GLOBAL_CONFIG;
|
||||
public @NonNull GameModeConfig<Material, String> getGameModeConfig() {
|
||||
return GameModeConfig.getDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-3
@@ -28,9 +28,11 @@ import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.GameModeConfig;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -57,7 +59,7 @@ public class FixedRegion implements Region {
|
||||
private final Area testblock;
|
||||
private final int floorLevel;
|
||||
private final int waterLevel;
|
||||
private final GameModeConfig gameModeConfig;
|
||||
private final GameModeConfig<Material, String> gameModeConfig;
|
||||
private final RegionData regionData;
|
||||
private final RegionHistory regionHistory = new RegionHistory.Impl(20);
|
||||
|
||||
@@ -336,7 +338,11 @@ public class FixedRegion implements Region {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.gameModeConfig = new GameModeConfig(found);
|
||||
if (found == null) {
|
||||
this.gameModeConfig = GameModeConfig.getDefaults();
|
||||
} else {
|
||||
this.gameModeConfig = GameModeConfig.getByFileName(found);
|
||||
}
|
||||
this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write);
|
||||
}
|
||||
|
||||
@@ -371,7 +377,7 @@ public class FixedRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull GameModeConfig getGameModeConfig() {
|
||||
public @NonNull GameModeConfig<Material, String> getGameModeConfig() {
|
||||
return gameModeConfig;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user