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")
|
@Register(value = "load", description = "BACKUP_HELP_LOAD")
|
||||||
public void backupLoad(@Validator("owner") Player p, @Mapper("backup") RegionBackups.Backup backup) {
|
public void backupLoad(@Validator("owner") Player p, @Mapper("backup") @ErrorMessage("BACKUP_LOAD_FAILURE") RegionBackups.Backup backup) {
|
||||||
Region region = Region.getRegion(p.getLocation());
|
|
||||||
if (checkGlobalRegion(region, p)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backup.load()) {
|
if (backup.load()) {
|
||||||
BauSystem.MESSAGE.send("BACKUP_LOAD", p);
|
BauSystem.MESSAGE.send("BACKUP_LOAD", p);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+13
-21
@@ -30,9 +30,9 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.features.util.SelectCommand;
|
import de.steamwar.bausystem.features.util.SelectCommand;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.RegionSkins;
|
||||||
import de.steamwar.bausystem.region.RegionUtils;
|
import de.steamwar.bausystem.region.RegionUtils;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
@@ -177,8 +177,8 @@ public class RegionCommand extends SWCommand {
|
|||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkin());
|
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkins().getCurrentSkin().getName());
|
||||||
String creator = region.getPrototype().getSkinMap().get(region.getSkin()).getCreator();
|
String creator = region.getSkins().getCurrentSkin().getCreator();
|
||||||
if (creator != null) {
|
if (creator != null) {
|
||||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator);
|
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(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN")
|
||||||
@Register("skin")
|
@Register("skin")
|
||||||
public void changeSkinCommand(@Validator Player p, @Mapper("skinTypeMapper") String s) {
|
public void changeSkinCommand(@Validator Player p, @Mapper("skinTypeMapper") @ErrorMessage("REGION_REGION_CHANGESKIN_UNKNOWN") RegionSkins.Skin skin) {
|
||||||
Region region = Region.getRegion(p.getLocation());
|
if (skin.apply()) {
|
||||||
if (checkGlobalRegion(region, p)) {
|
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, skin.getName());
|
||||||
return;
|
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"));
|
||||||
}
|
|
||||||
if (!region.getPrototype().getSkinMap().containsKey(s)) {
|
|
||||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p);
|
|
||||||
} else {
|
} else {
|
||||||
if (region.setSkin(s)) {
|
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INVALID", p);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,8 +288,8 @@ public class RegionCommand extends SWCommand {
|
|||||||
|
|
||||||
|
|
||||||
@Mapper(value = "skinTypeMapper", local = true)
|
@Mapper(value = "skinTypeMapper", local = true)
|
||||||
private TypeMapper<String> skinTypeMapper() {
|
private TypeMapper<RegionSkins.Skin> skinTypeMapper() {
|
||||||
return new TypeMapper<String>() {
|
return new TypeMapper<RegionSkins.Skin>() {
|
||||||
@Override
|
@Override
|
||||||
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||||
Player p = (Player) commandSender;
|
Player p = (Player) commandSender;
|
||||||
@@ -305,12 +297,12 @@ public class RegionCommand extends SWCommand {
|
|||||||
if (region.getType().isGlobal()) {
|
if (region.getType().isGlobal()) {
|
||||||
return Collections.emptyList();
|
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
|
@Override
|
||||||
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
public RegionSkins.Skin map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||||
return s.replace('_', ' ');
|
return Region.getRegion(((Player) commandSender).getLocation()).getSkins().get(s.replace('_', ' '));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,17 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
public interface FlagStorage {
|
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();
|
void clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ package de.steamwar.bausystem.region;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
|
import lombok.NonNull;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@@ -42,24 +44,36 @@ public interface Region {
|
|||||||
return RegionSystem.INSTANCE.getGlobalRegion();
|
return RegionSystem.INSTANCE.getGlobalRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
UUID getID();
|
UUID getID();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
RegionType getType();
|
RegionType getType();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
FlagStorage getFlags();
|
FlagStorage getFlags();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Area getArea();
|
Area getArea();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Area getBuildArea();
|
Area getBuildArea();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Area getTestblockArea();
|
Area getTestblockArea();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
RegionConfig getGameModeConfig();
|
RegionConfig getGameModeConfig();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
RegionHistory getHistory();
|
RegionHistory getHistory();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
RegionBackups getBackups();
|
RegionBackups getBackups();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
RegionSkins getSkins();
|
||||||
|
|
||||||
interface Area {
|
interface Area {
|
||||||
|
|
||||||
Area EMPTY = new Area() {
|
Area EMPTY = new Area() {
|
||||||
@@ -116,16 +130,21 @@ public interface Region {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Point getMinPoint(boolean extension);
|
Point getMinPoint(boolean extension);
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Point getMaxPoint(boolean extension);
|
Point getMaxPoint(boolean extension);
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Point getCopyPoint();
|
Point getCopyPoint();
|
||||||
|
|
||||||
boolean inRegion(Location location, boolean extension);
|
boolean inRegion(Location location, boolean extension);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
EditSession copy(boolean extension);
|
EditSession copy(boolean extension);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
File getResetFile();
|
File getResetFile();
|
||||||
|
|
||||||
void reset(PasteBuilder pasteBuilder, boolean extension);
|
void reset(PasteBuilder pasteBuilder, boolean extension);
|
||||||
|
|||||||
@@ -20,8 +20,11 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import javax.annotation.CheckReturnValue;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -33,24 +36,33 @@ public interface RegionBackups {
|
|||||||
AUTOMATIC(20),
|
AUTOMATIC(20),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int maxBackups;
|
public final int maxBackups;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
abstract class Backup {
|
abstract class Backup {
|
||||||
|
@NonNull
|
||||||
private final BackupType type;
|
private final BackupType type;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final FlagStorage flags;
|
private final FlagStorage flags;
|
||||||
|
|
||||||
|
@CheckReturnValue
|
||||||
public abstract boolean load();
|
public abstract boolean load();
|
||||||
|
|
||||||
public abstract void delete();
|
public abstract void delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckReturnValue
|
||||||
Optional<Backup> create(BackupType backupType);
|
Optional<Backup> create(BackupType backupType);
|
||||||
|
|
||||||
|
@NonNull
|
||||||
List<Backup> list();
|
List<Backup> list();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
Backup get(String name);
|
Backup get(String name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,11 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
public interface RegionHistory {
|
public interface RegionHistory {
|
||||||
|
|
||||||
void remember(EditSession editSession);
|
void remember(@NonNull EditSession editSession);
|
||||||
|
|
||||||
boolean undo();
|
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;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import javax.annotation.CheckReturnValue;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -33,11 +35,16 @@ public interface RegionSystem {
|
|||||||
void load();
|
void load();
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Region getGlobalRegion();
|
Region getGlobalRegion();
|
||||||
|
|
||||||
Region get(Location location);
|
@NonNull
|
||||||
Optional<Region> getRegion(UUID id);
|
Region get(@NonNull Location location);
|
||||||
|
|
||||||
|
@CheckReturnValue
|
||||||
|
Optional<Region> getRegion(@NonNull UUID id);
|
||||||
|
|
||||||
|
@NonNull
|
||||||
Stream<Region> getRegions();
|
Stream<Region> getRegions();
|
||||||
|
|
||||||
boolean isModular();
|
boolean isModular();
|
||||||
|
|||||||
Reference in New Issue
Block a user