Add KillAllCommand
Add BauScoreboard Remove TestRegion.java Add RegionSelectionType Fix saving of FlagStorage
Dieser Commit ist enthalten in:
Ursprung
47e6a8bbcd
Commit
686263327e
@ -25,6 +25,7 @@ import de.steamwar.bausystem.config.ColorConfig;
|
||||
import de.steamwar.bausystem.features.loader.activations.AbstractLoaderActivation;
|
||||
import de.steamwar.bausystem.features.loader.activations.BlockPlaceLoaderActivation;
|
||||
import de.steamwar.bausystem.features.loader.activations.InteractionActivation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -40,28 +41,28 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Loader implements Listener {
|
||||
|
||||
private static final Map<Player, Loader> LOADER_MAP = new HashMap<>();
|
||||
@Getter
|
||||
private final Player p;
|
||||
@Getter
|
||||
private final List<AbstractLoaderActivation> actions = new LinkedList<>();
|
||||
private final BukkitTask task;
|
||||
@Getter
|
||||
@Setter
|
||||
private int ticksBetweenShots = 80;
|
||||
@Getter
|
||||
@Setter
|
||||
private int ticksBetweenBlocks = 1;
|
||||
@Getter
|
||||
private Stage stage;
|
||||
@Getter
|
||||
private int lastActivation = -1;
|
||||
@Getter
|
||||
@Setter
|
||||
private int countdown = 0;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final BukkitTask task;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
@Setter(AccessLevel.PRIVATE)
|
||||
private AbstractLoaderActivation current;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
@Setter(AccessLevel.PRIVATE)
|
||||
private ListIterator<AbstractLoaderActivation> iterator;
|
||||
|
||||
private Loader(Player p) {
|
||||
@ -203,7 +204,7 @@ public class Loader implements Listener {
|
||||
stop();
|
||||
}
|
||||
|
||||
private enum Stage {
|
||||
public enum Stage {
|
||||
SETUP,
|
||||
RUNNING,
|
||||
PAUSE,
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.features.other;
|
||||
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionUtils;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionSelectionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked(LinkageType.COMMAND)
|
||||
public class KillAllCommand extends SWCommand {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
public KillAllCommand() {
|
||||
super("killall", "removeall");
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
public void genericHelp(Player player, String... args) {
|
||||
player.sendMessage("§8/§ekillall §8- §7Entferne alle Entities aus deiner Region");
|
||||
player.sendMessage("§8/§ekillall §8[§7Global§8/Local§7] §8- §7Entferne alle Entities aus deiner Region oder global");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
genericCommand(player, RegionSelectionType.LOCAL);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player, RegionSelectionType regionSelectionType) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.getInstance() == region) {
|
||||
long removedEntities = WORLD.getEntities()
|
||||
.stream()
|
||||
.filter(e -> !(e instanceof Player))
|
||||
.peek(Entity::remove).count();
|
||||
RegionUtils.actionBar(GlobalRegion.getInstance(), "§a" + removedEntities + " Entities aus der Welt entfernt");
|
||||
} else {
|
||||
long removedEntities = WORLD.getEntities()
|
||||
.stream()
|
||||
.filter(e -> !(e instanceof Player))
|
||||
.filter(e -> region.inRegion(e.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.peek(Entity::remove).count();
|
||||
RegionUtils.actionBar(region, "§a" + removedEntities + " Entities aus der Region entfernt");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -24,11 +24,11 @@ public class TNTListener implements Listener {
|
||||
if (value == TNTMode.ALLOW) {
|
||||
return false;
|
||||
}
|
||||
if (region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.NORMAL)) {
|
||||
if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.NORMAL)) {
|
||||
RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört");
|
||||
return true;
|
||||
}
|
||||
if (region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) {
|
||||
if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) {
|
||||
RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört");
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
package de.steamwar.bausystem.features.world;
|
||||
|
||||
import de.steamwar.bausystem.features.loader.Loader;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils;
|
||||
import de.steamwar.bausystem.features.tracer.record.RecordStateMachine;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Linked(LinkageType.LISTENER)
|
||||
public class BauScoreboard implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void handlePlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
SWScoreboard.createScoreboard(player, new ScoreboardCallback() {
|
||||
@Override
|
||||
public HashMap<String, Integer> getData() {
|
||||
return sidebar(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "§eSteam§8War";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private HashMap<String, Integer> sidebar(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
|
||||
List<String> strings = new ArrayList<>();
|
||||
strings.add("§1");
|
||||
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||
if (GlobalRegion.getInstance() != region) {
|
||||
strings.add("§eRegion§8: §7" + region.getDisplayName());
|
||||
}
|
||||
strings.add("§2");
|
||||
strings.add("§eTNT§8: " + region.get(Flag.TNT).getChatValue());
|
||||
strings.add("§eFreeze§8: " + region.get(Flag.FREEZE).getChatValue());
|
||||
strings.add("§eFire§8: " + region.get(Flag.FIRE).getChatValue());
|
||||
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
||||
Loader loader = Loader.getLoader(p);
|
||||
strings.add("§eLoader§8: " + (loader != null ? ("§a" + loader.getStage().name().toLowerCase()) : "§caus"));
|
||||
if (region.getFloorLevel() != 0) {
|
||||
strings.add("§eProtect§8: " + region.get(Flag.PROTECT).getChatValue());
|
||||
}
|
||||
|
||||
if (RecordStateMachine.getRecordStatus().isTracing()) {
|
||||
strings.add("§3");
|
||||
strings.add("§eTicks§8: §7" + traceTicks());
|
||||
strings.add("§eAnzahl TNT§8: §7" + RecordStateMachine.size());
|
||||
}
|
||||
|
||||
strings.add("§4");
|
||||
strings.add("§eTPS§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit());
|
||||
|
||||
int i = strings.size();
|
||||
HashMap<String, Integer> result = new HashMap<>();
|
||||
for (String s : strings) {
|
||||
result.put(s, i--);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private long traceTicks() {
|
||||
return (System.currentTimeMillis() - RecordStateMachine.getStartTime()) / 50;
|
||||
}
|
||||
|
||||
private String tpsColor() {
|
||||
double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND);
|
||||
if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) {
|
||||
return "§a";
|
||||
}
|
||||
if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) {
|
||||
return "§e";
|
||||
}
|
||||
return "§c";
|
||||
}
|
||||
|
||||
private String tpsLimit() {
|
||||
if (TPSLimitUtils.getCurrentTPSLimit() == 20) {
|
||||
return "";
|
||||
}
|
||||
return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit();
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 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.features.world;
|
||||
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
@Linked(LinkageType.LISTENER)
|
||||
public class TestRegion implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
SWUtils.sendToActionbar(event.getPlayer(), Region.getRegion(event.getTo()).getDisplayName());
|
||||
}
|
||||
|
||||
}
|
@ -20,15 +20,34 @@
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import yapion.annotations.object.YAPIONData;
|
||||
import yapion.annotations.object.YAPIONPreDeserialization;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
@YAPIONData
|
||||
public class FlagStorage {
|
||||
|
||||
public static FlagStorage createStorage(YAPIONObject yapionObject) {
|
||||
FlagStorage flagStorage = new FlagStorage();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
try {
|
||||
String s = yapionObject.getPlainValue(flag.name());
|
||||
flagStorage.set(flag, flag.getFlagValueOf(s));
|
||||
} catch (Exception e) {
|
||||
flagStorage.set(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
return flagStorage;
|
||||
}
|
||||
|
||||
public static YAPIONObject toYAPION(FlagStorage flagStorage) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
|
||||
}
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
protected Map<Flag, Flag.Value<?>> flags;
|
||||
|
||||
public FlagStorage() {
|
||||
@ -36,12 +55,6 @@ public class FlagStorage {
|
||||
readKeys();
|
||||
}
|
||||
|
||||
@YAPIONPreDeserialization
|
||||
private void preDeserializer() {
|
||||
flags = new EnumMap<>(Flag.class);
|
||||
readKeys();
|
||||
}
|
||||
|
||||
public boolean set(final Flag flagType, final Flag.Value<?> value) {
|
||||
return flags.put(flagType, value) != value;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import lombok.Getter;
|
||||
@ -32,7 +34,6 @@ public class GlobalRegion extends Region {
|
||||
|
||||
public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
super("global", null, new YAPIONObject(), flagStorage, regionData);
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class Prototype {
|
||||
}
|
||||
FlagStorage flagStorage;
|
||||
if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
flagStorage = (FlagStorage) YAPIONDeserializer.deserialize(regionData.getObject("flagStorage"));
|
||||
flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
|
||||
} else {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
||||
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
@ -31,7 +32,6 @@ import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
import yapion.serializing.YAPIONSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -110,6 +110,10 @@ public class Region {
|
||||
point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ"));
|
||||
}
|
||||
generatePrototypeData(prototype, point);
|
||||
|
||||
if (!hasType(RegionType.BUILD)) {
|
||||
flagStorage.set(Flag.TNT, TNTMode.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePrototypeData(Prototype prototype, Point point) {
|
||||
@ -226,7 +230,7 @@ public class Region {
|
||||
|
||||
public void set(Flag flagType, Flag.Value<?> value) {
|
||||
if (flagStorage.set(flagType, value)) {
|
||||
regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage));
|
||||
regionData.add("flagStorage", FlagStorage.toYAPION(flagStorage));
|
||||
RegionLoader.save();
|
||||
}
|
||||
setLinkedRegion(region -> region.set(flagType, value));
|
||||
|
@ -28,11 +28,10 @@ import lombok.Getter;
|
||||
public enum Flag {
|
||||
|
||||
COLOR(ColorMode.class, ColorMode.YELLOW),
|
||||
TNT(TNTMode.class, TNTMode.ALLOW),
|
||||
TNT(TNTMode.class, TNTMode.ONLY_TB),
|
||||
FIRE(FireMode.class, FireMode.ALLOW),
|
||||
FREEZE(FreezeMode.class, FreezeMode.INACTIVE),
|
||||
PROTECT(ProtectMode.class, ProtectMode.INACTIVE),
|
||||
DAMAGE(DamageMode.class, DamageMode.ALLOW);
|
||||
PROTECT(ProtectMode.class, ProtectMode.INACTIVE);
|
||||
|
||||
@Getter
|
||||
private static final Set<Flag> flags;
|
||||
|
@ -94,7 +94,7 @@ public class RegionLoader {
|
||||
}
|
||||
FlagStorage flagStorage;
|
||||
if (globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
flagStorage = (FlagStorage) YAPIONDeserializer.deserialize(globalOptions.getObject("flagStorage"));
|
||||
flagStorage = FlagStorage.createStorage(globalOptions.getObject("flagStorage"));
|
||||
} else {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package de.steamwar.bausystem.region.utils;
|
||||
|
||||
public enum RegionSelectionType {
|
||||
LOCAL,
|
||||
GLOBAL
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren