forked from SteamWar/SteamWar
Add RegionConfig
This commit is contained in:
+1
-11
@@ -31,8 +31,6 @@ import lombok.Getter;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.type.Chest;
|
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.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -41,7 +39,6 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -132,17 +129,10 @@ public class AutostartListener implements Listener {
|
|||||||
if (!regionStartTime.containsKey(region)) return;
|
if (!regionStartTime.containsKey(region)) return;
|
||||||
if (!region.getTestblockArea().inRegion(block.getLocation(), true)) return;
|
if (!region.getTestblockArea().inRegion(block.getLocation(), true)) return;
|
||||||
long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region);
|
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_RESULT1", tickDiff);
|
||||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff));
|
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff));
|
||||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3");
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-12
@@ -33,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DesignEndStone {
|
public class DesignEndStone {
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ public class DesignEndStone {
|
|||||||
private REntityServer entityServer = new REntityServer();
|
private REntityServer entityServer = new REntityServer();
|
||||||
private List<REntity> entities = new ArrayList<>();
|
private List<REntity> entities = new ArrayList<>();
|
||||||
private Set<Location> locations = new HashSet<>();
|
private Set<Location> locations = new HashSet<>();
|
||||||
private Set<Material> limited = new HashSet<>();
|
private Set<Material> limited;
|
||||||
private boolean calculateFromBottom;
|
private boolean calculateFromBottom;
|
||||||
|
|
||||||
public DesignEndStone(Region region) {
|
public DesignEndStone(Region region) {
|
||||||
@@ -53,17 +54,15 @@ public class DesignEndStone {
|
|||||||
this.maxY = region.getBuildArea().getMaxPoint(false).getY();
|
this.maxY = region.getBuildArea().getMaxPoint(false).getY();
|
||||||
this.maxZ = region.getBuildArea().getMaxPoint(false).getZ();
|
this.maxZ = region.getBuildArea().getMaxPoint(false).getZ();
|
||||||
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(region.getGameModeConfig().get());
|
limited = region.getGameModeConfig()
|
||||||
for(Map<?, ?> entry : config.getMapList("Schematic.Limited")) {
|
.getSchematic()
|
||||||
int amount = (Integer) entry.get("Amount");
|
.getLimited()
|
||||||
Set<String> materials = new HashSet<>((List<String>) entry.get("Materials"));
|
.entrySet()
|
||||||
if(amount == 0) {
|
.stream()
|
||||||
materials.forEach(s -> {
|
.filter(entry -> entry.getValue() == 0)
|
||||||
limited.add(Material.getMaterial(s));
|
.flatMap(entry -> entry.getKey().stream())
|
||||||
});
|
.collect(Collectors.toSet());
|
||||||
}
|
calculateFromBottom = region.getGameModeConfig().getArena().isNoFloor();
|
||||||
}
|
|
||||||
calculateFromBottom = config.getBoolean("Arena.NoFloor", false);
|
|
||||||
|
|
||||||
entityServer.setCallback((player, rEntity, entityAction) -> {
|
entityServer.setCallback((player, rEntity, entityAction) -> {
|
||||||
if (entityAction != REntityServer.EntityAction.ATTACK) return;
|
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);
|
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (region.getGameModeConfig().isEmpty()) {
|
if (!region.getGameModeConfig().isLoaded()) {
|
||||||
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -46,11 +46,8 @@ public class RegionScoreboardElement implements ScoreboardElement {
|
|||||||
@Override
|
@Override
|
||||||
public String get(Region region, Player p) {
|
public String get(Region region, Player p) {
|
||||||
if (region.getType().isGlobal()) return null;
|
if (region.getType().isGlobal()) return null;
|
||||||
// TODO: Improve this!
|
if (!region.getGameModeConfig().isLoaded()) return null;
|
||||||
Optional<File> gameModeConfig = region.getGameModeConfig();
|
List<String> names = region.getGameModeConfig().getServer().getChatNames();
|
||||||
if (gameModeConfig.isEmpty()) return null;
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(region.getGameModeConfig().get());
|
|
||||||
List<String> names = config.getStringList("Server.ChatNames");
|
|
||||||
if (names.isEmpty()) return null;
|
if (names.isEmpty()) return null;
|
||||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + names.get(0);
|
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + names.get(0);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-12
@@ -69,26 +69,16 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
|
|||||||
}
|
}
|
||||||
|
|
||||||
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
|
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
|
||||||
File file = rg.getGameModeConfig().orElse(null);
|
if (!region.getGameModeConfig().getTechhider().isActive()) {
|
||||||
if (file == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
|
||||||
if (!config.getBoolean("Techhider.Active", false)) {
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
hidden.put(rg, new HashSet<>());
|
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) -> {
|
TechHider current = new TechHider((p, cX, cY) -> {
|
||||||
if (rg.getBuildArea().isChunkOutside(cX, cY)) return true;
|
if (rg.getBuildArea().isChunkOutside(cX, cY)) return true;
|
||||||
return !hidden.get(rg).contains(p);
|
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();
|
current.enable();
|
||||||
|
|
||||||
return Optional.of(current);
|
return Optional.of(current);
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.xray;
|
package de.steamwar.bausystem.features.xray;
|
||||||
|
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import de.steamwar.Reflection;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.techhider.TechHiderCommand;
|
import de.steamwar.bausystem.features.techhider.TechHiderCommand;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
@@ -34,8 +34,6 @@ import de.steamwar.techhider.TechHider;
|
|||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
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.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -70,24 +67,14 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
|
Optional<TechHider> techHider = techHiders.computeIfAbsent(region, rg -> {
|
||||||
File file = rg.getGameModeConfig().orElse(null);
|
if (!region.getGameModeConfig().getTechhider().isActive()) {
|
||||||
if (file == null) {
|
|
||||||
return Optional.empty();
|
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<>());
|
hidden.put(rg, new HashSet<>());
|
||||||
|
|
||||||
String obfuscateWith = config.getString("Techhider.ObfuscateWith", "end_stone");
|
Set<Material> blocks = new HashSet<>(Arrays.asList(region.getGameModeConfig().getTechhider().getObfuscateWith()));
|
||||||
|
if (blocks.contains(Material.END_STONE)) blocks.add(Material.END_STONE_BRICKS);
|
||||||
Set<Material> blocks = new HashSet<>(Arrays.asList(Material.getMaterial(obfuscateWith.toUpperCase())));
|
|
||||||
if (obfuscateWith.equals("end_stone")) blocks.add(Material.END_STONE_BRICKS);
|
|
||||||
xrayedBlocks.put(region, blocks);
|
xrayedBlocks.put(region, blocks);
|
||||||
return Optional.of(createXray(rg, blocks));
|
return Optional.of(createXray(rg, blocks));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import de.steamwar.bausystem.utils.PasteBuilder;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -55,7 +54,7 @@ public interface Region {
|
|||||||
|
|
||||||
Area getTestblockArea();
|
Area getTestblockArea();
|
||||||
|
|
||||||
Optional<File> getGameModeConfig();
|
RegionConfig getGameModeConfig();
|
||||||
|
|
||||||
RegionHistory getHistory();
|
RegionHistory getHistory();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 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 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 RegionConfig {
|
||||||
|
|
||||||
|
private final boolean loaded;
|
||||||
|
|
||||||
|
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 RegionConfig(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(Material::getMaterial).collect(Collectors.toUnmodifiableSet());
|
||||||
|
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(section.getStringList("HiddenBlockEntities")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user