From 698f9178282be6082e2999f27b5ceedaa659573b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 14:11:03 +0200 Subject: [PATCH] Add RegionSkins --- .../features/backup/BackupCommand.java | 7 +-- .../features/region/RegionCommand.java | 34 +++++------- .../bausystem/region/FlagStorage.java | 9 ++- .../de/steamwar/bausystem/region/Region.java | 19 +++++++ .../bausystem/region/RegionBackups.java | 14 ++++- .../bausystem/region/RegionHistory.java | 3 +- .../bausystem/region/RegionSkins.java | 55 +++++++++++++++++++ .../bausystem/region/RegionSystem.java | 11 +++- 8 files changed, 118 insertions(+), 34 deletions(-) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index b2671e84..6c7708c9 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -72,12 +72,7 @@ public class BackupCommand extends SWCommand { } @Register(value = "load", description = "BACKUP_HELP_LOAD") - public void backupLoad(@Validator("owner") Player p, @Mapper("backup") RegionBackups.Backup backup) { - Region region = Region.getRegion(p.getLocation()); - if (checkGlobalRegion(region, p)) { - return; - } - + public void backupLoad(@Validator("owner") Player p, @Mapper("backup") @ErrorMessage("BACKUP_LOAD_FAILURE") RegionBackups.Backup backup) { if (backup.load()) { BauSystem.MESSAGE.send("BACKUP_LOAD", p); } else { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index ccf62cdb..a0f2ca1c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -30,9 +30,9 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.util.SelectCommand; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionSkins; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.PasteBuilder; @@ -177,8 +177,8 @@ public class RegionCommand extends SWCommand { if (checkGlobalRegion(region, p)) { return; } - BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkin()); - String creator = region.getPrototype().getSkinMap().get(region.getSkin()).getCreator(); + BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkins().getCurrentSkin().getName()); + String creator = region.getSkins().getCurrentSkin().getCreator(); if (creator != null) { BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator); } @@ -186,20 +186,12 @@ public class RegionCommand extends SWCommand { @Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN") @Register("skin") - public void changeSkinCommand(@Validator Player p, @Mapper("skinTypeMapper") String s) { - Region region = Region.getRegion(p.getLocation()); - if (checkGlobalRegion(region, p)) { - return; - } - if (!region.getPrototype().getSkinMap().containsKey(s)) { - BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p); + public void changeSkinCommand(@Validator Player p, @Mapper("skinTypeMapper") @ErrorMessage("REGION_REGION_CHANGESKIN_UNKNOWN") RegionSkins.Skin skin) { + if (skin.apply()) { + BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, skin.getName()); + BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGESKIN_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset")); } else { - if (region.setSkin(s)) { - BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, s); - BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGESKIN_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset")); - } else { - BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INVALID", p); - } + BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INVALID", p); } } @@ -296,8 +288,8 @@ public class RegionCommand extends SWCommand { @Mapper(value = "skinTypeMapper", local = true) - private TypeMapper skinTypeMapper() { - return new TypeMapper() { + private TypeMapper skinTypeMapper() { + return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Player p = (Player) commandSender; @@ -305,12 +297,12 @@ public class RegionCommand extends SWCommand { if (region.getType().isGlobal()) { return Collections.emptyList(); } - return region.getPrototype().getSkinMap().keySet().stream().map(c -> c.replace(' ', '_')).collect(Collectors.toList()); + return region.getSkins().list().stream().map(skin -> skin.getName().replace(' ', '_')).collect(Collectors.toList()); } @Override - public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - return s.replace('_', ' '); + public RegionSkins.Skin map(CommandSender commandSender, PreviousArguments previousArguments, String s) { + return Region.getRegion(((Player) commandSender).getLocation()).getSkins().get(s.replace('_', ' ')); } }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java index 6d51e2ef..d6f1afd5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -20,14 +20,17 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.region.flags.Flag; +import lombok.NonNull; public interface FlagStorage { - & Flag.Value> RegionFlagPolicy has(Flag flag); + @NonNull + & Flag.Value> RegionFlagPolicy has(@NonNull Flag flag); - & Flag.Value> boolean set(Flag flag, T value); + & Flag.Value> boolean set(@NonNull Flag flag, @NonNull T value); - & Flag.Value> FlagOptional get(Flag flag); + @NonNull + & Flag.Value> FlagOptional get(@NonNull Flag flag); void clear(); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index fb6d0f55..d2d97ecf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -21,8 +21,10 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.utils.PasteBuilder; +import lombok.NonNull; import org.bukkit.Location; +import javax.annotation.Nullable; import java.io.File; import java.util.UUID; import java.util.function.BiConsumer; @@ -42,24 +44,36 @@ public interface Region { return RegionSystem.INSTANCE.getGlobalRegion(); } + @NonNull UUID getID(); + @NonNull RegionType getType(); + @NonNull FlagStorage getFlags(); + @NonNull Area getArea(); + @NonNull Area getBuildArea(); + @NonNull Area getTestblockArea(); + @NonNull RegionConfig getGameModeConfig(); + @NonNull RegionHistory getHistory(); + @NonNull RegionBackups getBackups(); + @NonNull + RegionSkins getSkins(); + interface Area { Area EMPTY = new Area() { @@ -116,16 +130,21 @@ public interface Region { return false; } + @NonNull Point getMinPoint(boolean extension); + @NonNull Point getMaxPoint(boolean extension); + @NonNull Point getCopyPoint(); boolean inRegion(Location location, boolean extension); + @Nullable EditSession copy(boolean extension); + @Nullable File getResetFile(); void reset(PasteBuilder pasteBuilder, boolean extension); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java index af4bf23b..53b3b8a7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java @@ -20,8 +20,11 @@ package de.steamwar.bausystem.region; import lombok.Getter; +import lombok.NonNull; import lombok.RequiredArgsConstructor; +import javax.annotation.CheckReturnValue; +import javax.annotation.Nullable; import java.util.List; import java.util.Optional; @@ -33,24 +36,33 @@ public interface RegionBackups { AUTOMATIC(20), ; - private final int maxBackups; + public final int maxBackups; } @RequiredArgsConstructor @Getter abstract class Backup { + @NonNull private final BackupType type; + + @NonNull private final String name; + + @NonNull private final FlagStorage flags; + @CheckReturnValue public abstract boolean load(); public abstract void delete(); } + @CheckReturnValue Optional create(BackupType backupType); + @NonNull List list(); + @Nullable Backup get(String name); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java index 17ff9c19..9732b325 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java @@ -20,10 +20,11 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; +import lombok.NonNull; public interface RegionHistory { - void remember(EditSession editSession); + void remember(@NonNull EditSession editSession); boolean undo(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java new file mode 100644 index 00000000..e12f2221 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.region; + +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +import javax.annotation.CheckReturnValue; +import javax.annotation.Nullable; +import java.util.List; + +public interface RegionSkins { + + @RequiredArgsConstructor + @Getter + abstract class Skin { + @NonNull + private final String name; + + @NonNull + private final String creator; + + @CheckReturnValue + public abstract boolean apply(); + } + + @NonNull + Skin getCurrentSkin(); + + @NonNull + List list(); + + boolean has(@NonNull String name); + + @Nullable + Skin get(@NonNull String name); +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java index 26ee4bc6..5222a415 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSystem.java @@ -19,8 +19,10 @@ package de.steamwar.bausystem.region; +import lombok.NonNull; import org.bukkit.Location; +import javax.annotation.CheckReturnValue; import java.lang.reflect.InvocationTargetException; import java.util.Optional; import java.util.UUID; @@ -33,11 +35,16 @@ public interface RegionSystem { void load(); void save(); + @NonNull Region getGlobalRegion(); - Region get(Location location); - Optional getRegion(UUID id); + @NonNull + Region get(@NonNull Location location); + @CheckReturnValue + Optional getRegion(@NonNull UUID id); + + @NonNull Stream getRegions(); boolean isModular();