forked from SteamWar/SteamWar
Add RegionSkins
This commit is contained in:
+1
-6
@@ -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 {
|
||||
|
||||
+13
-21
@@ -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<String> skinTypeMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
private TypeMapper<RegionSkins.Skin> skinTypeMapper() {
|
||||
return new TypeMapper<RegionSkins.Skin>() {
|
||||
@Override
|
||||
public List<String> 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('_', ' '));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,14 +20,17 @@
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.NonNull;
|
||||
|
||||
public interface FlagStorage {
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(Flag<T> flag);
|
||||
@NonNull
|
||||
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(@NonNull Flag<T> flag);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> boolean set(Flag<T> flag, T value);
|
||||
<T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> FlagOptional<T> get(Flag<T> flag);
|
||||
@NonNull
|
||||
<T extends Enum<T> & Flag.Value<T>> FlagOptional<T> get(@NonNull Flag<T> flag);
|
||||
|
||||
void clear();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Backup> create(BackupType backupType);
|
||||
|
||||
@NonNull
|
||||
List<Backup> list();
|
||||
|
||||
@Nullable
|
||||
Backup get(String name);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Skin> list();
|
||||
|
||||
boolean has(@NonNull String name);
|
||||
|
||||
@Nullable
|
||||
Skin get(@NonNull String name);
|
||||
}
|
||||
@@ -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<Region> getRegion(UUID id);
|
||||
@NonNull
|
||||
Region get(@NonNull Location location);
|
||||
|
||||
@CheckReturnValue
|
||||
Optional<Region> getRegion(@NonNull UUID id);
|
||||
|
||||
@NonNull
|
||||
Stream<Region> getRegions();
|
||||
|
||||
boolean isModular();
|
||||
|
||||
Reference in New Issue
Block a user