Add RegionConfig

This commit is contained in:
2025-07-31 13:53:10 +02:00
parent 6a78499193
commit ad87ad7495
8 changed files with 146 additions and 60 deletions
@@ -31,8 +31,6 @@ import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.type.Chest;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -41,7 +39,6 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -132,17 +129,10 @@ 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 = getPreFightDurationInSeconds(region);
long preFightDurationInSeconds = region.getGameModeConfig().getTimes().getPreFightDuration();
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff);
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff));
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3");
});
}
private int getPreFightDurationInSeconds(Region region) {
File file = region.getGameModeConfig().orElse(null);
if (file == null) return 30;
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
return config.getInt("Times.PreFightDuration", 30);
}
}
@@ -33,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.stream.Collectors;
public class DesignEndStone {
@@ -42,7 +43,7 @@ public class DesignEndStone {
private REntityServer entityServer = new REntityServer();
private List<REntity> entities = new ArrayList<>();
private Set<Location> locations = new HashSet<>();
private Set<Material> limited = new HashSet<>();
private Set<Material> limited;
private boolean calculateFromBottom;
public DesignEndStone(Region region) {
@@ -53,17 +54,15 @@ public class DesignEndStone {
this.maxY = region.getBuildArea().getMaxPoint(false).getY();
this.maxZ = region.getBuildArea().getMaxPoint(false).getZ();
YamlConfiguration config = YamlConfiguration.loadConfiguration(region.getGameModeConfig().get());
for(Map<?, ?> entry : config.getMapList("Schematic.Limited")) {
int amount = (Integer) entry.get("Amount");
Set<String> materials = new HashSet<>((List<String>) entry.get("Materials"));
if(amount == 0) {
materials.forEach(s -> {
limited.add(Material.getMaterial(s));
});
}
}
calculateFromBottom = config.getBoolean("Arena.NoFloor", false);
limited = region.getGameModeConfig()
.getSchematic()
.getLimited()
.entrySet()
.stream()
.filter(entry -> entry.getValue() == 0)
.flatMap(entry -> entry.getKey().stream())
.collect(Collectors.toSet());
calculateFromBottom = region.getGameModeConfig().getArena().isNoFloor();
entityServer.setCallback((player, rEntity, entityAction) -> {
if (entityAction != REntityServer.EntityAction.ATTACK) return;
@@ -52,7 +52,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener {
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
return;
}
if (region.getGameModeConfig().isEmpty()) {
if (!region.getGameModeConfig().isLoaded()) {
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
return;
}
@@ -46,11 +46,8 @@ public class RegionScoreboardElement implements ScoreboardElement {
@Override
public String get(Region region, Player p) {
if (region.getType().isGlobal()) return null;
// TODO: Improve this!
Optional<File> gameModeConfig = region.getGameModeConfig();
if (gameModeConfig.isEmpty()) return null;
YamlConfiguration config = YamlConfiguration.loadConfiguration(region.getGameModeConfig().get());
List<String> names = config.getStringList("Server.ChatNames");
if (!region.getGameModeConfig().isLoaded()) return null;
List<String> names = region.getGameModeConfig().getServer().getChatNames();
if (names.isEmpty()) return null;
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + names.get(0);
}
@@ -69,26 +69,16 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
}
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
File file = rg.getGameModeConfig().orElse(null);
if (file == null) {
return Optional.empty();
}
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
if (!config.getBoolean("Techhider.Active", false)) {
if (!region.getGameModeConfig().getTechhider().isActive()) {
return Optional.empty();
}
hidden.put(rg, new HashSet<>());
String obfuscateWith = config.getString("Techhider.ObfuscateWith", "end_stone");
Set<String> hiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks")));
Set<String> hiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities")));
TechHider current = new TechHider((p, cX, cY) -> {
if (rg.getBuildArea().isChunkOutside(cX, cY)) return true;
return !hidden.get(rg).contains(p);
}, Material.valueOf(obfuscateWith.toUpperCase()), hiddenBlocks.stream().map(String::toUpperCase).map(Material::valueOf).collect(Collectors.toSet()), hiddenBlockEntities);
}, region.getGameModeConfig().getTechhider().getObfuscateWith(), region.getGameModeConfig().getTechhider().getHiddenBlocks(), region.getGameModeConfig().getTechhider().getHiddenBlockEntities());
current.enable();
return Optional.of(current);
@@ -19,8 +19,8 @@
package de.steamwar.bausystem.features.xray;
import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.Reflection;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.techhider.TechHiderCommand;
import de.steamwar.bausystem.region.Region;
@@ -34,8 +34,6 @@ import de.steamwar.techhider.TechHider;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -43,7 +41,6 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.io.File;
import java.util.*;
import java.util.function.BiFunction;
@@ -70,24 +67,14 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
}
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
File file = rg.getGameModeConfig().orElse(null);
if (file == null) {
if (!region.getGameModeConfig().getTechhider().isActive()) {
return Optional.empty();
}
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
if (!config.getBoolean("Techhider.Active", false)) {
Set<Material> blocks = new HashSet<>(Arrays.asList(Material.END_STONE, Material.IRON_BLOCK));
xrayedBlocks.put(region, blocks);
return Optional.of(createXray(rg, blocks));
}
hidden.put(rg, new HashSet<>());
String obfuscateWith = config.getString("Techhider.ObfuscateWith", "end_stone");
Set<Material> blocks = new HashSet<>(Arrays.asList(Material.getMaterial(obfuscateWith.toUpperCase())));
if (obfuscateWith.equals("end_stone")) blocks.add(Material.END_STONE_BRICKS);
Set<Material> blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().getTechhider().getObfuscateWith()));
if (blocks.contains(Material.END_STONE)) blocks.add(Material.END_STONE_BRICKS);
xrayedBlocks.put(region, blocks);
return Optional.of(createXray(rg, blocks));
});