forked from SteamWar/SteamWar
Update Region System of BauSystem
This commit is contained in:
@@ -42,7 +42,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
+3
-5
@@ -44,7 +44,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Linked
|
||||
@@ -106,11 +105,11 @@ public class AutostartListener implements Listener {
|
||||
|
||||
public void activate(Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region.isGlobal()) {
|
||||
if (region.getType().isGlobal()) {
|
||||
BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_NO_REGION", player);
|
||||
return;
|
||||
}
|
||||
if (!region.hasType(RegionType.TESTBLOCK)) {
|
||||
if (region.getTestblockArea().isPresent()) {
|
||||
BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_NO_REGION", player);
|
||||
return;
|
||||
}
|
||||
@@ -131,8 +130,7 @@ public class AutostartListener implements Listener {
|
||||
event.blockList().forEach(block -> {
|
||||
Region region = Region.getRegion(block.getLocation());
|
||||
if (!regionStartTime.containsKey(region)) return;
|
||||
if (!region.hasType(RegionType.TESTBLOCK)) return;
|
||||
if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return;
|
||||
if (!region.getTestblockArea().inRegion(block.getLocation(), true)) return;
|
||||
long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region);
|
||||
long preFightDurationInSeconds = getPreFightDurationInSeconds(region);
|
||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff);
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.backup;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
@@ -49,7 +49,7 @@ public class BackupCommand extends SWCommand {
|
||||
}
|
||||
|
||||
static boolean checkGlobalRegion(Region region, Player p) {
|
||||
if (region.isGlobal()) {
|
||||
if (region.getType().isGlobal()) {
|
||||
BauSystem.MESSAGE.send("BACKUP_REGION_NO_REGION", p);
|
||||
return true;
|
||||
}
|
||||
@@ -62,11 +62,11 @@ public class BackupCommand extends SWCommand {
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
if (!region.get(Tag.CHANGED)) {
|
||||
if (region.getFlag(Flag.CHANGED).isPresent()) {
|
||||
BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p);
|
||||
return;
|
||||
}
|
||||
if (region.backup()) {
|
||||
if (region.backup(false)) {
|
||||
BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p);
|
||||
} else {
|
||||
BauSystem.MESSAGE.send("BACKUP_CREATE_FAILURE", p);
|
||||
|
||||
+2
-3
@@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.cannon.depth.Depth;
|
||||
import de.steamwar.bausystem.features.cannon.depth.DepthManager;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
@@ -85,8 +84,8 @@ public class CannonDetector implements Listener {
|
||||
grouped.forEach((cannonKey, tntPrimeds) -> {
|
||||
if (tntPrimeds.size() <= 5) return;
|
||||
Region region = Region.getRegion(tntPrimeds.get(0).getLocation());
|
||||
if (region.isGlobal()) return;
|
||||
if (!region.hasType(RegionType.TESTBLOCK)) return;
|
||||
if (region.getType().isGlobal()) return;
|
||||
if (region.getTestblockArea().isEmpty()) return;
|
||||
Depth depth = new Depth(region);
|
||||
DepthManager.init(tntPrimeds, depth);
|
||||
});
|
||||
|
||||
@@ -23,8 +23,6 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
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.RegionType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@@ -50,7 +48,7 @@ public class Depth {
|
||||
|
||||
public void update(List<Block> blocks) {
|
||||
List<Block> blocksList = blocks.stream()
|
||||
.filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION))
|
||||
.filter(block -> region.getTestblockArea().inRegion(block.getLocation(), true))
|
||||
.collect(Collectors.toList());
|
||||
tntCount++;
|
||||
for (Block block : blocksList) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.bausystem.features.countingwand;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.countingwand;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.design.endstone;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
@@ -49,7 +48,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener {
|
||||
@Register(description = "DESIGN_ENDSTONE_COMMAND_HELP")
|
||||
public void genericCommand(@Validator Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (!region.hasType(RegionType.BUILD)) {
|
||||
if (region.getBuildArea().isEmpty()) {
|
||||
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.bausystem.features.killchecker;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.bausystem.features.observer;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.util.SelectCommand;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionUtils;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.region.items;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||
import de.steamwar.bausystem.regionnew.Color;
|
||||
import de.steamwar.bausystem.region.Color;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.luaj.vm2.*;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.script.lua.libs;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+1
-2
@@ -23,7 +23,6 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -65,7 +64,7 @@ public final class TNTPhase extends SimulatorPhase {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
Location location = position.toLocation(world);
|
||||
if (Region.getRegion(location).get(Flag.FREEZE) == FreezeMode.ACTIVE) return;
|
||||
if (Region.getRegion(location).getFlag(Flag.FREEZE).isPresent()) return;
|
||||
TNTPrimed tnt = world.spawn(location, TNTPrimed.class);
|
||||
if (!xJump) tnt.setVelocity(tnt.getVelocity().setX(0));
|
||||
if (!yJump) tnt.setVelocity(tnt.getVelocity().setY(0));
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.slaves.laufbau;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
|
||||
import de.steamwar.bausystem.features.tracer.TNTPoint;
|
||||
import de.steamwar.bausystem.features.tracer.Trace;
|
||||
import de.steamwar.bausystem.features.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
@@ -21,9 +21,7 @@ package de.steamwar.bausystem.features.team;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.team.boundary.BoundaryViewer;
|
||||
import de.steamwar.bausystem.region.Prototype;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
@@ -69,14 +67,14 @@ public class SkinCommand extends SWCommand {
|
||||
return;
|
||||
}
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (region.isGlobal()) {
|
||||
if (region.getType().isGlobal()) {
|
||||
BauSystem.MESSAGE.send("SKIN_NO_REGION", p);
|
||||
return;
|
||||
}
|
||||
|
||||
String name = String.join(" ", names);
|
||||
File arenaFile = new File("sections19/" + name + "/" + typeKuerzel + "Arena.schem");
|
||||
File testblockFile = region.hasType(RegionType.TESTBLOCK) ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null;
|
||||
File testblockFile = region.getTestblockArea().isPresent() ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null;
|
||||
|
||||
arenaFile.getParentFile().mkdirs();
|
||||
if (testblockFile != null) {
|
||||
|
||||
+3
-6
@@ -48,21 +48,18 @@ public class BoundaryViewer implements Listener {
|
||||
}
|
||||
viewers.forEach(player -> {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region.isGlobal()) return;
|
||||
if (region.getType().isGlobal()) return;
|
||||
showRegion(region, player);
|
||||
if (region.getLinkedRegion() != null) {
|
||||
showRegion(region.getLinkedRegion(), player);
|
||||
}
|
||||
});
|
||||
}, 20, 20);
|
||||
}
|
||||
|
||||
private void showRegion(Region region, Player player) {
|
||||
drawCuboid(player, TrickyParticleWrapper.impl.getVillagerHappy(), region.getMinPoint(), region.getMaxPoint());
|
||||
if (region.hasType(RegionType.TESTBLOCK)) {
|
||||
if (region.getTestblockArea().isPresent()) {
|
||||
drawCuboid(player, Particle.END_ROD, region.getMinPointTestblockExtension(), region.getMaxPointTestblockExtension());
|
||||
}
|
||||
if (region.hasType(RegionType.BUILD)) {
|
||||
if (region.getBuildArea().isPresent()) {
|
||||
drawCuboid(player, Particle.END_ROD, region.getMinPointBuildExtension(), region.getMaxPointBuildExtension());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,8 +20,6 @@
|
||||
package de.steamwar.bausystem.features.testblock.blockcounter;
|
||||
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -37,11 +35,13 @@ public class BlockCounterListener implements Listener {
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Region region = Region.getRegion(event.getLocation());
|
||||
if (region.isGlobal()) {
|
||||
if (region.getType().isGlobal()) {
|
||||
return;
|
||||
}
|
||||
List<Block> blockList = event.blockList();
|
||||
blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList());
|
||||
blockList = blockList.stream()
|
||||
.filter(block -> region.getTestblockArea().inRegion(block.getLocation(), true))
|
||||
.collect(Collectors.toList());
|
||||
if (blockList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -39,7 +37,7 @@ import java.util.Optional;
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
@Getter
|
||||
public class TNTPoint{
|
||||
public class TNTPoint {
|
||||
/**
|
||||
* Unique number to identify records being of the same tnt
|
||||
*/
|
||||
@@ -99,7 +97,7 @@ public class TNTPoint{
|
||||
* Constructor for object creation in trace recording
|
||||
*/
|
||||
protected TNTPoint(int tntId, TNTPrimed tnt, boolean explosion, boolean afterFirstExplosion, long ticksSinceStart,
|
||||
List<TNTPoint> history, List<Block> destroyedBlocks) {
|
||||
List<TNTPoint> history, List<Block> destroyedBlocks) {
|
||||
this.tntId = tntId;
|
||||
this.explosion = explosion;
|
||||
if (Core.getVersion() > 15) {
|
||||
@@ -117,12 +115,10 @@ public class TNTPoint{
|
||||
boolean buildDestroy = false;
|
||||
boolean testblockDestroy = false;
|
||||
for (Block destroyedBlock : destroyedBlocks) {
|
||||
if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(), RegionType.BUILD,
|
||||
RegionExtensionType.EXTENSION)) {
|
||||
if (Region.getRegion(destroyedBlock.getLocation()).getBuildArea().inRegion(destroyedBlock.getLocation(), true)) {
|
||||
buildDestroy = true;
|
||||
}
|
||||
if (Region.getRegion(destroyedBlock.getLocation()).inRegion(destroyedBlock.getLocation(),
|
||||
RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) {
|
||||
if (Region.getRegion(destroyedBlock.getLocation()).getTestblockArea().inRegion(destroyedBlock.getLocation(), true)) {
|
||||
testblockDestroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -21,12 +21,9 @@ package de.steamwar.bausystem.features.util;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
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.bausystem.region.RegionUtils;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -53,7 +50,7 @@ public class KillAllCommand extends SWCommand {
|
||||
public void genericCommand(@Validator Player player, RegionSelectionType regionSelectionType) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
AtomicLong count = new AtomicLong(0);
|
||||
if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.getInstance() == region) {
|
||||
if (regionSelectionType == RegionSelectionType.GLOBAL || region.getType().isGlobal()) {
|
||||
WORLD.getEntities()
|
||||
.stream()
|
||||
.filter(e -> !(e instanceof Player))
|
||||
@@ -66,7 +63,7 @@ public class KillAllCommand extends SWCommand {
|
||||
WORLD.getEntities()
|
||||
.stream()
|
||||
.filter(e -> !(e instanceof Player))
|
||||
.filter(e -> region.inRegion(e.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(e -> region.inRegion(e.getLocation()))
|
||||
.forEach(entity -> {
|
||||
entity.remove();
|
||||
count.incrementAndGet();
|
||||
@@ -74,5 +71,4 @@ public class KillAllCommand extends SWCommand {
|
||||
RegionUtils.actionBar(region, "OTHER_KILLALL_REGION", count.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.steamwar.bausystem.features.util;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
|
||||
+5
-4
@@ -1,7 +1,5 @@
|
||||
package de.steamwar.bausystem.features.world;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
@@ -101,8 +99,11 @@ public class BauScoreboard implements Listener {
|
||||
@Override
|
||||
public String getTitle() {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (GlobalRegion.getInstance() == region) return "§eSteam§8War";
|
||||
String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), player).substring(0, 2);
|
||||
if (region.getType().isGlobal()) return "§eSteam§8War";
|
||||
String colorCode = "§e";
|
||||
if (region.hasFlag(Flag.COLOR).isReadable()) {
|
||||
colorCode = "§" + region.getFlag(Flag.COLOR).get().getColor().getColorCode();
|
||||
}
|
||||
return colorCode + "■ §eSteam§8War " + colorCode + "■"; // ■
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import de.steamwar.bausystem.features.world.WorldEditListener;
|
||||
import de.steamwar.bausystem.features.worldedit.utils.SpecialReplace;
|
||||
import de.steamwar.bausystem.regionnew.Color;
|
||||
import de.steamwar.bausystem.region.Color;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
|
||||
@@ -1,33 +1,14 @@
|
||||
/*
|
||||
* 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.region;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import de.steamwar.bausystem.region.flags.ChangedMode;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
@Linked
|
||||
public class BackupScheduler implements Enable {
|
||||
|
||||
@@ -39,26 +20,29 @@ public class BackupScheduler implements Enable {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Iterator<Region> regions = Region.getREGION_MAP().values().stream().filter(region -> region.get(Tag.CHANGED)).iterator();
|
||||
BackupScheduler.this.doBackup(regions);
|
||||
Iterator<Region> regionsToBackup = RegionSystem.INSTANCE.getRegions()
|
||||
.filter(region -> region.isFlag(Flag.CHANGED, ChangedMode.HAS_CHANGE))
|
||||
.iterator();
|
||||
if (!regionsToBackup.hasNext()) return;
|
||||
doBackup(regionsToBackup);
|
||||
}
|
||||
}.runTaskTimer(BauSystem.getInstance(), INITIAL, PERIOD);
|
||||
}
|
||||
|
||||
public void doBackup(final Iterator<Region> regionIterator) {
|
||||
private void doBackup(Iterator<Region> regionsToBackup) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!regionIterator.hasNext()) {
|
||||
if (!regionsToBackup.hasNext()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
final Region region = regionIterator.next();
|
||||
if (region.backup()) {
|
||||
region.remove(Tag.CHANGED);
|
||||
Region region = regionsToBackup.next();
|
||||
if (region.backup(true)) {
|
||||
region.setFlag(Flag.CHANGED, ChangedMode.NO_CHANGE);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(BauSystem.getInstance(), 0, 20 * 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-17
@@ -17,23 +17,30 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum Color {
|
||||
WHITE,
|
||||
ORANGE,
|
||||
MAGENTA,
|
||||
LIGHT_BLUE,
|
||||
YELLOW,
|
||||
LIME,
|
||||
PINK,
|
||||
GRAY,
|
||||
LIGHT_GRAY,
|
||||
CYAN,
|
||||
PURPLE,
|
||||
BLUE,
|
||||
BROWN,
|
||||
GREEN,
|
||||
RED,
|
||||
BLACK;
|
||||
WHITE('f'),
|
||||
ORANGE('6'),
|
||||
MAGENTA('5'),
|
||||
LIGHT_BLUE('b'),
|
||||
YELLOW('e'),
|
||||
LIME('a'),
|
||||
PINK('d'),
|
||||
GRAY('8'),
|
||||
LIGHT_GRAY('7'),
|
||||
CYAN('3'),
|
||||
PURPLE('5'),
|
||||
BLUE('9'),
|
||||
BROWN('e'),
|
||||
GREEN('2'),
|
||||
RED('c'),
|
||||
BLACK('1');
|
||||
|
||||
private final char colorCode;
|
||||
}
|
||||
@@ -1,107 +1,29 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2024 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 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.
|
||||
* 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/>.
|
||||
* 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 de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
public interface FlagStorage {
|
||||
|
||||
/**
|
||||
* Tags and Flags are not allowed to have overlaping names.
|
||||
*/
|
||||
public class FlagStorage {
|
||||
<T extends Enum<T> & Flag.Value<T>> boolean set(Flag<T> flag, T value);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
for (final Tag tag : Tag.values()) {
|
||||
if (yapionObject.containsKey(tag.name())) {
|
||||
flagStorage.set(tag);
|
||||
}
|
||||
}
|
||||
return flagStorage;
|
||||
}
|
||||
|
||||
public static YAPIONObject toYAPION(FlagStorage flagStorage) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
if (flag.getDefaultValue() == flagStorage.flags.getOrDefault(flag, flag.getDefaultValue())) {
|
||||
yapionObject.remove(flag.name());
|
||||
} else {
|
||||
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
|
||||
}
|
||||
}
|
||||
for (Tag tag : Tag.values()) {
|
||||
if (flagStorage.tagSet.contains(tag)) {
|
||||
yapionObject.add(tag.name(), "");
|
||||
} else {
|
||||
yapionObject.remove(tag.name());
|
||||
}
|
||||
}
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
protected Map<Flag, Flag.Value<?>> flags;
|
||||
protected Set<Tag> tagSet;
|
||||
|
||||
public FlagStorage() {
|
||||
flags = new EnumMap<>(Flag.class);
|
||||
tagSet = new HashSet<>();
|
||||
readKeys();
|
||||
}
|
||||
|
||||
public boolean set(final Flag flagType, final Flag.Value<?> value) {
|
||||
return flags.put(flagType, value) != value;
|
||||
}
|
||||
|
||||
public Flag.Value<?> get(final Flag flagType) {
|
||||
return flags.getOrDefault(flagType, flagType.getDefaultValue());
|
||||
}
|
||||
|
||||
public boolean set(final Tag tag) {
|
||||
return tagSet.add(tag);
|
||||
}
|
||||
|
||||
public boolean remove(final Tag tag) {
|
||||
return tagSet.remove(tag);
|
||||
}
|
||||
|
||||
public boolean is(final Tag tag) {
|
||||
return tagSet.contains(tag);
|
||||
}
|
||||
|
||||
private void readKeys() {
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
flags.put(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
<T extends Enum<T> & Flag.Value<T>> T get(Flag<T> flag);
|
||||
}
|
||||
|
||||
@@ -1,42 +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.region;
|
||||
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
public class GlobalRegion extends Region {
|
||||
|
||||
@Getter
|
||||
static GlobalRegion instance;
|
||||
|
||||
public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
super("global", null, new YAPIONObject(), flagStorage, regionData);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -1,585 +1,128 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2024 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 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.
|
||||
* 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/>.
|
||||
* 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 com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.shared.SizedStack;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.ObjIntConsumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
public class Region {
|
||||
public interface Region {
|
||||
|
||||
@Getter
|
||||
private static final Map<String, Region> REGION_MAP = new HashMap<>();
|
||||
private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup");
|
||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd' 'HH:mm:ss");
|
||||
|
||||
public static Region getRegion(Location location) {
|
||||
return REGION_MAP.values().stream()
|
||||
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
|
||||
.findFirst()
|
||||
.orElse(GlobalRegion.instance);
|
||||
static Region getRegion(Location location) {
|
||||
return RegionSystem.INSTANCE.get(location);
|
||||
}
|
||||
|
||||
public static Set<Region> getRegion(Prototype prototype) {
|
||||
return REGION_MAP.values().stream()
|
||||
.filter(r -> r.getPrototype() == prototype)
|
||||
.collect(Collectors.toSet());
|
||||
RegionType getType();
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy hasFlag(@NonNull Flag<T> flag);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, T value);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> Optional<T> getFlag(@NonNull Flag<T> flag);
|
||||
|
||||
default <T extends Enum<T> & Flag.Value<T>> boolean isFlag(@NonNull Flag<T> flag, T value) {
|
||||
if (hasFlag(flag).isReadable()) {
|
||||
Optional<T> optional = getFlag(flag);
|
||||
return optional.isPresent() && optional.get() == value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setGlobal(Flag flagType, Flag.Value<?> value) {
|
||||
REGION_MAP.values().forEach(region -> region.set(flagType, value));
|
||||
}
|
||||
Point getMinPoint();
|
||||
|
||||
YAPIONObject regionData;
|
||||
Point getMaxPoint();
|
||||
|
||||
private String name;
|
||||
private Prototype prototype;
|
||||
private Set<String> prototypes;
|
||||
private String skin;
|
||||
boolean inRegion(Location location);
|
||||
|
||||
private Point minPoint;
|
||||
private Point maxPoint;
|
||||
Inner getBuildArea();
|
||||
|
||||
private Point minPointTestblock;
|
||||
private Point maxPointTestblock;
|
||||
Inner getTestblockArea();
|
||||
|
||||
private Point minPointTestblockExtension;
|
||||
private Point maxPointTestblockExtension;
|
||||
// TODO: Add forEachChunk and getChunkOutsidePredicate
|
||||
|
||||
private Point minPointBuild;
|
||||
private Point maxPointBuild;
|
||||
Optional<File> getGameModeConfig();
|
||||
|
||||
private Point minPointBuildExtension;
|
||||
private Point maxPointBuildExtension;
|
||||
boolean backup(boolean automatic);
|
||||
|
||||
private int floorLevel;
|
||||
private int waterLevel;
|
||||
Optional<EditSession> copy();
|
||||
|
||||
private Point copyPoint; // Nullable
|
||||
private Point testBlockPoint; // Nullable
|
||||
void reset();
|
||||
|
||||
private String linkedRegionName = null; // Nullable
|
||||
private Region linkedRegion = null; // Nullable
|
||||
void remember(EditSession editSession);
|
||||
|
||||
private FlagStorage flagStorage;
|
||||
boolean undo();
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> undoSessions;
|
||||
boolean redo();
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> redoSessions;
|
||||
interface Inner {
|
||||
|
||||
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
this.name = name;
|
||||
this.regionData = regionData;
|
||||
if (prototype != null) {
|
||||
REGION_MAP.put(name, this);
|
||||
}
|
||||
Inner EMPTY = new Inner() {
|
||||
private static final Point ZERO = new Point(0, 0, 0);
|
||||
|
||||
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
||||
|
||||
prototypes = new HashSet<>();
|
||||
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
|
||||
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
|
||||
if (yapionAnyType instanceof YAPIONValue) {
|
||||
prototypes.add(((YAPIONValue<String>) yapionAnyType).get());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (regionConfig.containsKey("prototype")) {
|
||||
prototypes.add(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
|
||||
this.flagStorage = flagStorage;
|
||||
Point point = null;
|
||||
if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) {
|
||||
point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ"));
|
||||
}
|
||||
if (prototype != null && prototypes.contains(prototype.getName())) {
|
||||
generatePrototypeData(prototype, point);
|
||||
} else if (regionConfig.containsKey("prototype")) {
|
||||
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
|
||||
}
|
||||
if (prototype != null) {
|
||||
skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
|
||||
if (!prototype.getSkinMap().containsKey(skin)) {
|
||||
skin = prototype.getDefaultSkin();
|
||||
@Override
|
||||
public Point getMinPoint(boolean extension) {
|
||||
return ZERO;
|
||||
}
|
||||
}
|
||||
regionData.add("skin", skin);
|
||||
|
||||
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
|
||||
flagStorage.set(Flag.TNT, TNTMode.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePrototypeData(Prototype prototype, Point point) {
|
||||
if (prototype == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.prototype = prototype;
|
||||
this.skin = prototype.getDefaultSkin();
|
||||
|
||||
this.minPoint = point;
|
||||
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
||||
|
||||
if (prototype.getTestblock() != null) {
|
||||
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
|
||||
this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
||||
|
||||
this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
||||
this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
||||
|
||||
if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) {
|
||||
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
|
||||
} else {
|
||||
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1);
|
||||
@Override
|
||||
public Point getMaxPoint(boolean extension) {
|
||||
return ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
if (prototype.getBuild() != null) {
|
||||
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
|
||||
this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
||||
|
||||
this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
||||
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
||||
|
||||
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
||||
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
} else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) {
|
||||
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
|
||||
} else {
|
||||
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
|
||||
}
|
||||
} else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) {
|
||||
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
}
|
||||
|
||||
if (prototype.getFloorOffset() != 0) {
|
||||
floorLevel = minPoint.getY() + prototype.getFloorOffset();
|
||||
} else {
|
||||
floorLevel = 0;
|
||||
}
|
||||
|
||||
if (prototype.getWaterOffset() != 0) {
|
||||
waterLevel = minPoint.getY() + prototype.getWaterOffset();
|
||||
} else {
|
||||
waterLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
Point minBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointBuildExtension : minPointBuild;
|
||||
Point maxBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointBuildExtension : maxPointBuild;
|
||||
return inRegion(location, minBPoint, maxBPoint);
|
||||
case TESTBLOCK:
|
||||
Point minTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointTestblockExtension : minPointTestblock;
|
||||
Point maxTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointTestblockExtension : maxPointTestblock;
|
||||
return inRegion(location, minTBPoint, maxTBPoint);
|
||||
default:
|
||||
case NORMAL:
|
||||
return inRegion(location, minPoint, maxPoint);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inRegion(Location location, Point minPoint, Point maxPoint) {
|
||||
int blockX = location.getBlockX();
|
||||
int blockY = location.getBlockY();
|
||||
int blockZ = location.getBlockZ();
|
||||
return blockX >= minPoint.getX() && blockX <= maxPoint.getX() &&
|
||||
blockY >= minPoint.getY() && blockY <= maxPoint.getY() &&
|
||||
blockZ >= minPoint.getZ() && blockZ <= maxPoint.getZ();
|
||||
}
|
||||
|
||||
public boolean hasType(RegionType regionType) {
|
||||
if (prototype == null) {
|
||||
return false;
|
||||
}
|
||||
if (regionType == null) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.getBuild() != null;
|
||||
case TESTBLOCK:
|
||||
return prototype.getTestblock() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasExtensionType(RegionType regionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.getBuild().isExtensionRegistered();
|
||||
case TESTBLOCK:
|
||||
return prototype.getTestblock().isExtensionRegistered();
|
||||
default:
|
||||
case NORMAL:
|
||||
@Override
|
||||
public boolean inRegion(Location location, boolean extension) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return prototype != null ? prototype.getSkinMap().get(skin).getName() : "";
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Predicate<Region> regionConsumer) {
|
||||
if (linkedRegionName == null) {
|
||||
return;
|
||||
}
|
||||
if (linkedRegion != null) {
|
||||
if (regionConsumer.test(linkedRegion)) {
|
||||
RegionUtils.save(linkedRegion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (Region region : REGION_MAP.values()) {
|
||||
if (region.name.equals(linkedRegionName)) {
|
||||
linkedRegion = region;
|
||||
if (regionConsumer.test(linkedRegion)) {
|
||||
RegionUtils.save(linkedRegion);
|
||||
}
|
||||
return;
|
||||
|
||||
@Override
|
||||
public Optional<EditSession> copy(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Region getLinkedRegion() {
|
||||
if (linkedRegion == null && linkedRegionName != null) {
|
||||
setLinkedRegion(region -> false);
|
||||
}
|
||||
return linkedRegion;
|
||||
}
|
||||
|
||||
public boolean setPrototype(@NonNull Prototype prototype) {
|
||||
if (!prototypes.contains(prototype.getName())) {
|
||||
return false;
|
||||
}
|
||||
return _setPrototype(prototype);
|
||||
}
|
||||
|
||||
boolean _setPrototype(@NonNull Prototype prototype) {
|
||||
generatePrototypeData(prototype, minPoint);
|
||||
RegionUtils.save(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setSkin(@NonNull String skinName) {
|
||||
if (!prototype.getSkinMap().containsKey(skinName)) {
|
||||
return false;
|
||||
}
|
||||
this.skin = skinName;
|
||||
setLinkedRegion(region -> {
|
||||
region.skin = skinName;
|
||||
return true;
|
||||
});
|
||||
regionData.add("skin", skin);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void set(Flag flagType, Flag.Value<?> value) {
|
||||
if (flagStorage.set(flagType, value)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(flagType, value));
|
||||
}
|
||||
|
||||
public void set(Tag tag) {
|
||||
if (flagStorage.set(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(tag));
|
||||
}
|
||||
|
||||
public void remove(Tag tag) {
|
||||
if (flagStorage.remove(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Flag.Value<?> get(Flag flagType) {
|
||||
return flagStorage.get(flagType);
|
||||
}
|
||||
|
||||
public boolean get(Tag tagType) {
|
||||
return flagStorage.is(tagType);
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) {
|
||||
return (T) flagStorage.get(flagType).getValue();
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) {
|
||||
return (T) flagStorage.get(flagType).getValue();
|
||||
}
|
||||
|
||||
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointTestblock : minPointTestblockExtension;
|
||||
case BUILD:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointBuild : minPointBuildExtension;
|
||||
default:
|
||||
case NORMAL:
|
||||
return minPoint;
|
||||
}
|
||||
}
|
||||
|
||||
public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointTestblock : maxPointTestblockExtension;
|
||||
case BUILD:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointBuild : maxPointBuildExtension;
|
||||
default:
|
||||
case NORMAL:
|
||||
return maxPoint;
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasReset(RegionType regionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null;
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile() != null;
|
||||
}
|
||||
}
|
||||
|
||||
public File getResetFile(RegionType regionType) {
|
||||
if (!hasReset(regionType)) {
|
||||
return null;
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile();
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile();
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(PasteBuilder pasteBuilder, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
if (!hasReset(regionType)) {
|
||||
return;
|
||||
}
|
||||
if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) {
|
||||
regionExtensionType = RegionExtensionType.NORMAL;
|
||||
}
|
||||
|
||||
pasteBuilder.reset(regionExtensionType == RegionExtensionType.EXTENSION)
|
||||
.minPoint(getMinPoint(regionType, regionExtensionType))
|
||||
.maxPoint(getMaxPoint(regionType, regionExtensionType))
|
||||
.waterLevel(waterLevel);
|
||||
if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) {
|
||||
SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype();
|
||||
pasteBuilder.rotate(schematicType.fightType() || schematicType.check());
|
||||
}
|
||||
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
pasteBuilder.pastePoint(minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2));
|
||||
break;
|
||||
case TESTBLOCK:
|
||||
Point pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, prototype.getTestblock().getSizeZ() / 2);
|
||||
if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) {
|
||||
SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype();
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("wg")) {
|
||||
pastePoint = pastePoint.add(0, 0, 1);
|
||||
}
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("ws")) {
|
||||
pastePoint = pastePoint.add(-1, 0, 1);
|
||||
}
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("as")) {
|
||||
pastePoint = pastePoint.add(-1, 0, 1);
|
||||
}
|
||||
}
|
||||
pasteBuilder.pastePoint(pastePoint);
|
||||
break;
|
||||
default:
|
||||
case NORMAL:
|
||||
pasteBuilder.pastePoint(minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2));
|
||||
break;
|
||||
}
|
||||
|
||||
initSessions();
|
||||
undoSessions.push(pasteBuilder.run());
|
||||
}
|
||||
|
||||
public void remember(EditSession editSession) {
|
||||
initSessions();
|
||||
undoSessions.push(editSession);
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return this == GlobalRegion.getInstance();
|
||||
}
|
||||
|
||||
private void initSessions() {
|
||||
if (undoSessions == null) {
|
||||
undoSessions = new SizedStack<>(20);
|
||||
redoSessions = new SizedStack<>(20);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean undo() {
|
||||
initSessions();
|
||||
EditSession session = undoSessions.pop();
|
||||
if (session == null)
|
||||
return false;
|
||||
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.undo(e);
|
||||
redoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean redo() {
|
||||
initSessions();
|
||||
EditSession session = redoSessions.pop();
|
||||
if (session == null)
|
||||
return false;
|
||||
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.redo(e);
|
||||
undoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean backup() {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
|
||||
File[] currentBackups = definedBackupFolder.listFiles();
|
||||
if (currentBackups != null && currentBackups.length >= 20) {
|
||||
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
||||
files.sort(Comparator.comparingLong(File::lastModified));
|
||||
while (files.size() >= 20) files.remove(0).delete();
|
||||
}
|
||||
|
||||
final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem");
|
||||
return FlatteningWrapper.impl.backup(minPoint, maxPoint, backupFile);
|
||||
}
|
||||
|
||||
public static boolean copy(Point minPoint, Point maxPoint, File file) {
|
||||
return FlatteningWrapper.impl.backup(minPoint, maxPoint, file);
|
||||
}
|
||||
|
||||
public List<String> listBackup() {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
|
||||
File[] currentBackups = definedBackupFolder.listFiles();
|
||||
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
||||
files.sort(Comparator.comparingLong(File::lastModified));
|
||||
return files.stream().map(File::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public File getBackupFile(String backupName) {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
File[] files = definedBackupFolder.listFiles((dir, name) -> name.equals(backupName + ".schem"));
|
||||
if (files == null || files.length == 0) return null;
|
||||
return files[0];
|
||||
}
|
||||
|
||||
public void forEachChunk(ObjIntConsumer<Integer> executor) {
|
||||
for (int x = (int) Math.floor(minPoint.getX() / 16.0); x <= (int) Math.ceil(maxPoint.getX() / 16.0); x++) {
|
||||
for (int z = (int) Math.floor(minPoint.getZ() / 16.0); z <= (int) Math.ceil(maxPoint.getZ() / 16.0); z++) {
|
||||
executor.accept(x, z);
|
||||
@Override
|
||||
public void reset(@Nullable SchematicNode schematicNode, boolean extension) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public boolean buildChunkOutside(int chunkX, int chunkY) {
|
||||
if (!hasType(RegionType.BUILD)) {
|
||||
return Math.floor(minPoint.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPoint.getX() / 16.0) ||
|
||||
Math.floor(minPoint.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPoint.getZ() / 16.0);
|
||||
default boolean isEmpty() {
|
||||
return this == EMPTY;
|
||||
}
|
||||
if (!hasExtensionType(RegionType.BUILD)) {
|
||||
return Math.floor(minPointBuild.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuild.getX() / 16.0) ||
|
||||
Math.floor(minPointBuild.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuild.getZ() / 16.0);
|
||||
}
|
||||
return Math.floor(minPointBuildExtension.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuildExtension.getX() / 16.0) ||
|
||||
Math.floor(minPointBuildExtension.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuildExtension.getZ() / 16.0);
|
||||
}
|
||||
|
||||
public File gameModeConfig() {
|
||||
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
for (int version = Core.getVersion(); version >= 15; version--) {
|
||||
File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml");
|
||||
if (specific.exists()) return specific;
|
||||
default boolean isPresent() {
|
||||
return this != EMPTY;
|
||||
}
|
||||
return null;
|
||||
|
||||
Point getMinPoint(boolean extension);
|
||||
|
||||
Point getMaxPoint(boolean extension);
|
||||
|
||||
boolean inRegion(Location location, boolean extension);
|
||||
|
||||
Optional<EditSession> copy(boolean extension);
|
||||
|
||||
void reset(@Nullable SchematicNode schematicNode, boolean extension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -31,4 +31,8 @@ public enum RegionFlagPolicy {
|
||||
|
||||
private final boolean readable;
|
||||
private final boolean writable;
|
||||
|
||||
public boolean isApplicable() {
|
||||
return readable || writable;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public interface RegionSystem {
|
||||
|
||||
RegionSystem REGION_SYSTEM = init();
|
||||
RegionSystem INSTANCE = init();
|
||||
|
||||
void load();
|
||||
void save();
|
||||
@@ -43,7 +43,7 @@ public interface RegionSystem {
|
||||
|
||||
private static RegionSystem init() {
|
||||
try {
|
||||
return (RegionSystem) Class.forName("de.steamwar.bausystem.regionnew.FixedRegionSystem").getConstructor().newInstance();
|
||||
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.FixedRegionSystem").getConstructor().newInstance();
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException e) {
|
||||
return new RegionSystem() {
|
||||
+3
-1
@@ -17,11 +17,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum RegionType {
|
||||
|
||||
GLOBAL(true),
|
||||
@@ -1,92 +1,48 @@
|
||||
/*
|
||||
* 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.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class RegionUtils {
|
||||
|
||||
public void actionBar(Region region, String s, Object... objects) {
|
||||
forEachInRegion(region, player -> {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse(s, player, objects)));
|
||||
});
|
||||
}
|
||||
|
||||
public void message(Region region, String s, Object... objects) {
|
||||
forEachInRegion(region, player -> BauSystem.MESSAGE.send(s, player, objects));
|
||||
}
|
||||
|
||||
public void message(Region region, Function<Player, String> function) {
|
||||
forEachInRegion(region, player -> {
|
||||
String message = function.apply(player);
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public void message(Region region, Consumer<Player> consumer) {
|
||||
forEachInRegion(region, consumer);
|
||||
}
|
||||
|
||||
public void forEachInRegion(Region region, Consumer<Player> consumer) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse(s, player, objects))));
|
||||
.filter(player -> region.inRegion(player.getLocation()))
|
||||
.filter(player -> !region.getType().isGlobal() || Region.getRegion(player.getLocation()).getType().isGlobal())
|
||||
.forEach(consumer);
|
||||
}
|
||||
|
||||
public static void message(Region region, String message, Object... objects) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> BauSystem.MESSAGE.send(message, player, objects));
|
||||
}
|
||||
|
||||
public static void message(Region region, Function<Player, String> function) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> {
|
||||
String message = function.apply(player);
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public static void message(Region region, Consumer<Player> function) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
|
||||
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
|
||||
.forEach(player -> {
|
||||
function.accept(player);
|
||||
});
|
||||
}
|
||||
|
||||
static void save(Region region) {
|
||||
if (region.getPrototype() != null) {
|
||||
region.regionData.add("prototype", region.getPrototype().getName());
|
||||
}
|
||||
region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage()));
|
||||
WorldData.write();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.Color;
|
||||
import de.steamwar.bausystem.region.Color;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -1,85 +1,103 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.flags;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.*;
|
||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Flag implements EnumDisplay {
|
||||
public final class Flag<T extends Enum<T> & Flag.Value<T>> implements EnumDisplay {
|
||||
|
||||
COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW, false),
|
||||
TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB, true),
|
||||
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, true),
|
||||
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, true),
|
||||
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, true),
|
||||
ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE, true),
|
||||
NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE, true),
|
||||
;
|
||||
public static final Flag<ColorMode> COLOR = new Flag<>("COLOR", "FLAG_COLOR", ColorMode.class, ColorMode.YELLOW);
|
||||
public static final Flag<TNTMode> TNT = new Flag<>("TNT", "FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB);
|
||||
public static final Flag<FireMode> FIRE = new Flag<>("FIRE", "FLAG_FIRE", FireMode.class, FireMode.ALLOW);
|
||||
public static final Flag<FreezeMode> FREEZE = new Flag<>("FREEZE", "FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE);
|
||||
public static final Flag<ProtectMode> PROTECT = new Flag<>("PROTECT", "FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE);
|
||||
public static final Flag<ItemMode> ITEMS = new Flag<>("ITEMS", "FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE);
|
||||
public static final Flag<NoGravityMode> NO_GRAVITY = new Flag<>("NO_GRAVITY", "FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE);
|
||||
public static final Flag<TestblockMode> TESTBLOCK = new Flag<>("TESTBLOCK", "FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE);
|
||||
public static final Flag<ChangedMode> CHANGED = new Flag<>("CHANGED", "FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE);
|
||||
|
||||
@Getter
|
||||
private static final Set<Flag> flags;
|
||||
@Getter
|
||||
private static final Set<Flag> resetFlags;
|
||||
@Getter
|
||||
private static final Set<Flag> flags = new HashSet<>();
|
||||
|
||||
static {
|
||||
flags = EnumSet.allOf(Flag.class);
|
||||
resetFlags = flags.stream().filter(flag -> flag.reset).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
private static AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
private final String chatValue;
|
||||
private final Class<? extends Value<?>> valueType;
|
||||
private final Flag.Value<?> defaultValue;
|
||||
private final boolean reset;
|
||||
private String name;
|
||||
private int ordinal;
|
||||
|
||||
public Value<?> getFlagValueOf(final String name) {
|
||||
return this.defaultValue.getValueOf(name);
|
||||
}
|
||||
@Getter
|
||||
private String chatValue;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
@Getter
|
||||
private final Class<? extends Flag.Value<T>> valueType;
|
||||
|
||||
@Override
|
||||
public String getChatValue() {
|
||||
return chatValue;
|
||||
}
|
||||
@Getter
|
||||
private final Flag.Value<?> defaultValue;
|
||||
|
||||
public interface Value<T extends Enum<T> & Value<T>> extends EnumDisplay {
|
||||
@Getter
|
||||
private final Flag.Value<?>[] values;
|
||||
|
||||
T getValue();
|
||||
private Flag(String name, String chatValue, Class<? extends Flag.Value<T>> valueType, Value<T> defaultValue) {
|
||||
flags.add(this);
|
||||
|
||||
T getValueOf(final String name);
|
||||
this.name = name;
|
||||
this.ordinal = counter.getAndIncrement();
|
||||
this.chatValue = chatValue;
|
||||
|
||||
T[] getValues();
|
||||
this.valueType = valueType;
|
||||
this.defaultValue = defaultValue;
|
||||
this.values = defaultValue.getValues();
|
||||
}
|
||||
|
||||
default String getName() {
|
||||
return this.getValue().name().toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int ordinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public boolean oneOf(Flag<?>... flags) {
|
||||
for (Flag<?> flag : flags) {
|
||||
if (flag == this) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface Value<T extends Enum<T> & Value<T>> extends EnumDisplay {
|
||||
|
||||
T getValue();
|
||||
|
||||
T getValueOf(final String name);
|
||||
|
||||
T[] getValues();
|
||||
|
||||
default String getName() {
|
||||
return this.getValue().name().toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew.flags;
|
||||
package de.steamwar.bausystem.region.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
-72
@@ -1,72 +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.region.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.Color;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ColorMode implements Flag.Value<ColorMode> {
|
||||
WHITE("FLAG_COLOR_WHITE", Color.WHITE),
|
||||
ORANGE("FLAG_COLOR_ORANGE", Color.ORANGE),
|
||||
MAGENTA("FLAG_COLOR_MAGENTA", Color.MAGENTA),
|
||||
LIGHT_BLUE("FLAG_COLOR_LIGHT_BLUE", Color.LIGHT_BLUE),
|
||||
YELLOW("FLAG_COLOR_YELLOW", Color.YELLOW),
|
||||
LIME("FLAG_COLOR_LIME", Color.LIME),
|
||||
PINK("FLAG_COLOR_PINK", Color.PINK),
|
||||
GRAY("FLAG_COLOR_GRAY", Color.GRAY),
|
||||
LIGHT_GRAY("FLAG_COLOR_LIGHT_GRAY", Color.LIGHT_GRAY),
|
||||
CYAN("FLAG_COLOR_CYAN", Color.CYAN),
|
||||
PURPLE("FLAG_COLOR_PURPLE", Color.PURPLE),
|
||||
BLUE("FLAG_COLOR_BLUE", Color.BLUE),
|
||||
BROWN("FLAG_COLOR_BROWN", Color.BROWN),
|
||||
GREEN("FLAG_COLOR_GREEN", Color.GREEN),
|
||||
RED("FLAG_COLOR_RED", Color.RED),
|
||||
BLACK("FLAG_COLOR_BLACK", Color.BLACK);
|
||||
|
||||
private static ColorMode[] values;
|
||||
private final String chatValue;
|
||||
private final Color color;
|
||||
|
||||
@Override
|
||||
public ColorMode[] getValues() {
|
||||
if (ColorMode.values == null) {
|
||||
ColorMode.values = ColorMode.values(); //NOSONAR
|
||||
}
|
||||
return ColorMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorMode getValueOf(final String name) {
|
||||
try {
|
||||
return ColorMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ColorMode.YELLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +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.region.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum FireMode implements Flag.Value<FireMode> {
|
||||
|
||||
ALLOW("FLAG_FIRE_ALLOW"),
|
||||
DENY("FLAG_FIRE_DENY");
|
||||
|
||||
private static FireMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public FireMode[] getValues() {
|
||||
if (FireMode.values == null) {
|
||||
FireMode.values = FireMode.values(); //NOSONAR
|
||||
}
|
||||
return FireMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireMode getValueOf(final String name) {
|
||||
try {
|
||||
return FireMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return FireMode.DENY;
|
||||
}
|
||||
return FireMode.ALLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
-61
@@ -1,61 +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.region.flags.flagvalues;
|
||||
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum FreezeMode implements Flag.Value<FreezeMode> {
|
||||
|
||||
ACTIVE("FLAG_FREEZE_ACTIVE"),
|
||||
INACTIVE("FLAG_FREEZE_INACTIVE");
|
||||
|
||||
private static FreezeMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public FreezeMode[] getValues() {
|
||||
if (FreezeMode.values == null) {
|
||||
FreezeMode.values = FreezeMode.values(); //NOSONAR
|
||||
}
|
||||
return FreezeMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FreezeMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FreezeMode getValueOf(final String name) {
|
||||
try {
|
||||
return FreezeMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return FreezeMode.INACTIVE;
|
||||
}
|
||||
return FreezeMode.INACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +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.region.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ItemMode implements Flag.Value<ItemMode> {
|
||||
|
||||
ACTIVE("FLAG_ITEMS_ACTIVE"),
|
||||
INACTIVE("FLAG_ITEMS_INACTIVE");
|
||||
|
||||
private static ItemMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public ItemMode[] getValues() {
|
||||
if (ItemMode.values == null) {
|
||||
ItemMode.values = ItemMode.values(); //NOSONAR
|
||||
}
|
||||
return ItemMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMode getValueOf(final String name) {
|
||||
try {
|
||||
return ItemMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return ItemMode.INACTIVE;
|
||||
}
|
||||
return ItemMode.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +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.region.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum NoGravityMode implements Flag.Value<NoGravityMode> {
|
||||
|
||||
ACTIVE("FLAG_NO_GRAVITY_ACTIVE"),
|
||||
INACTIVE("FLAG_NO_GRAVITY_INACTIVE");
|
||||
|
||||
private static NoGravityMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public NoGravityMode[] getValues() {
|
||||
if (NoGravityMode.values == null) {
|
||||
NoGravityMode.values = NoGravityMode.values(); //NOSONAR
|
||||
}
|
||||
return NoGravityMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoGravityMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoGravityMode getValueOf(final String name) {
|
||||
try {
|
||||
return NoGravityMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return NoGravityMode.INACTIVE;
|
||||
}
|
||||
return NoGravityMode.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +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.region.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProtectMode implements Flag.Value<ProtectMode> {
|
||||
|
||||
ACTIVE("FLAG_PROTECT_ACTIVE"),
|
||||
INACTIVE("FLAG_PROTECT_INACTIVE");
|
||||
|
||||
private static ProtectMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public ProtectMode[] getValues() {
|
||||
if (ProtectMode.values == null) {
|
||||
ProtectMode.values = ProtectMode.values(); //NOSONAR
|
||||
}
|
||||
return ProtectMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectMode getValueOf(final String name) {
|
||||
try {
|
||||
return ProtectMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (name.equalsIgnoreCase("false")) {
|
||||
return ProtectMode.INACTIVE;
|
||||
}
|
||||
return ProtectMode.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +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.region.flags.flagvalues;
|
||||
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TNTMode implements Flag.Value<TNTMode> {
|
||||
|
||||
ALLOW("FLAG_TNT_ALLOW"),
|
||||
DENY("FLAG_TNT_DENY"),
|
||||
ONLY_TB("FLAG_TNT_ONLY_TB"),
|
||||
ONLY_BUILD("FLAG_TNT_ONLY_BUILD");
|
||||
|
||||
private static TNTMode[] values;
|
||||
private final String chatValue;
|
||||
|
||||
@Override
|
||||
public TNTMode[] getValues() {
|
||||
if (TNTMode.values == null) {
|
||||
TNTMode.values = TNTMode.values(); //NOSONAR
|
||||
}
|
||||
return TNTMode.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TNTMode getValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TNTMode getValueOf(final String name) {
|
||||
try {
|
||||
return TNTMode.valueOf(name.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return TNTMode.ALLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +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.region.tags;
|
||||
|
||||
public enum Tag {
|
||||
CHANGED,
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* 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.utils;
|
||||
|
||||
public enum RegionExtensionType {
|
||||
NORMAL,
|
||||
EXTENSION
|
||||
}
|
||||
+2
-1
@@ -2,5 +2,6 @@ package de.steamwar.bausystem.region.utils;
|
||||
|
||||
public enum RegionSelectionType {
|
||||
LOCAL,
|
||||
GLOBAL
|
||||
GLOBAL,
|
||||
;
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.utils;
|
||||
|
||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum RegionType implements EnumDisplay {
|
||||
NORMAL("REGION_TYPE_NORMAL"),
|
||||
BUILD("REGION_TYPE_BUILD"),
|
||||
TESTBLOCK("REGION_TYPE_ONLY_TB");
|
||||
|
||||
@Getter
|
||||
private String chatValue;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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.regionnew;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.flags.Flag;
|
||||
|
||||
public interface FlagStorage {
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> boolean set(Flag<T> flag, Flag.Value<T> value);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag<T> flag);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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.regionnew;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.regionnew.flags.Flag;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface Region {
|
||||
|
||||
static Region getRegion(Location location) {
|
||||
return RegionSystem.REGION_SYSTEM.get(location);
|
||||
}
|
||||
|
||||
RegionType getType();
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy hasFlag(@NonNull Flag<T> flag);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, Flag.Value<T> value);
|
||||
|
||||
<T extends Enum<T> & Flag.Value<T>> Optional<Flag.Value<T>> getFlag(@NonNull Flag<T> flag);
|
||||
|
||||
Point getMinPoint();
|
||||
|
||||
Point getMaxPoint();
|
||||
|
||||
boolean inRegion(Location location);
|
||||
|
||||
Optional<Point> getBuildMinPoint(boolean extension);
|
||||
|
||||
Optional<Point> getBuildMaxPoint(boolean extension);
|
||||
|
||||
boolean inBuildRegion(Location location, boolean extension);
|
||||
|
||||
Optional<Point> getTestblockMinPoint(boolean extension);
|
||||
|
||||
Optional<Point> getTestblockMaxPoint(boolean extension);
|
||||
|
||||
boolean inTestblockRegion(Location location, boolean extension);
|
||||
|
||||
// TODO: Add forEachChunk and getChunkOutsidePredicate
|
||||
|
||||
Optional<File> getGameModeConfig();
|
||||
|
||||
Optional<EditSession> copy();
|
||||
|
||||
Optional<EditSession> copyBuild();
|
||||
|
||||
Optional<EditSession> copyTestblock();
|
||||
|
||||
void reset();
|
||||
|
||||
void resetBuild(@Nullable SchematicNode schematicNode, boolean extension);
|
||||
|
||||
void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension);
|
||||
|
||||
void remember(EditSession editSession);
|
||||
|
||||
boolean undo();
|
||||
|
||||
boolean redo();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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.regionnew;
|
||||
|
||||
public enum RegionSide {
|
||||
NORTH,
|
||||
SOUTH
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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.regionnew.flags;
|
||||
|
||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Flag<T extends Enum<T> & Flag.Value<T>> implements EnumDisplay {
|
||||
|
||||
public static final Flag<ColorMode> COLOR = new Flag<>("COLOR", "FLAG_COLOR", ColorMode.class, ColorMode.YELLOW);
|
||||
public static final Flag<TNTMode> TNT = new Flag<>("TNT", "FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB);
|
||||
public static final Flag<FireMode> FIRE = new Flag<>("FIRE", "FLAG_FIRE", FireMode.class, FireMode.ALLOW);
|
||||
public static final Flag<FreezeMode> FREEZE = new Flag<>("FREEZE", "FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE);
|
||||
public static final Flag<ProtectMode> PROTECT = new Flag<>("PROTECT", "FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE);
|
||||
public static final Flag<ItemMode> ITEMS = new Flag<>("ITEMS", "FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE);
|
||||
public static final Flag<NoGravityMode> NO_GRAVITY = new Flag<>("NO_GRAVITY", "FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE);
|
||||
public static final Flag<TestblockMode> TESTBLOCK = new Flag<>("TESTBLOCK", "FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE);
|
||||
public static final Flag<ChangedMode> CHANGED = new Flag<>("CHANGED", "FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE);
|
||||
|
||||
@Getter
|
||||
private static final Set<Flag> flags = new HashSet<>();
|
||||
|
||||
private static AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
private String name;
|
||||
private int ordinal;
|
||||
|
||||
@Getter
|
||||
private String chatValue;
|
||||
|
||||
@Getter
|
||||
private final Class<? extends Flag.Value<?>> valueType;
|
||||
|
||||
@Getter
|
||||
private final Flag.Value<?> defaultValue;
|
||||
|
||||
@Getter
|
||||
private final Flag.Value<?>[] values;
|
||||
|
||||
private Flag(String name, String chatValue, Class<? extends Flag.Value<T>> valueType, Value<T> defaultValue) {
|
||||
flags.add(this);
|
||||
|
||||
this.name = name;
|
||||
this.ordinal = counter.getAndIncrement();
|
||||
this.chatValue = chatValue;
|
||||
|
||||
this.valueType = valueType;
|
||||
this.defaultValue = defaultValue;
|
||||
this.values = defaultValue.getValues();
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int ordinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public boolean oneOff(Flag<?>... flags) {
|
||||
for (Flag<?> flag : flags) {
|
||||
if (flag == this) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface Value<T extends Enum<T> & Flag.Value<T>> extends EnumDisplay {
|
||||
|
||||
T getValue();
|
||||
|
||||
T getValueOf(final String name);
|
||||
|
||||
T[] getValues();
|
||||
|
||||
default String getName() {
|
||||
return this.getValue().name().toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
/*
|
||||
* 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.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.shared.SizedStack;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.ObjIntConsumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class Region {
|
||||
|
||||
@Getter
|
||||
private static final Map<String, Region> REGION_MAP = new HashMap<>();
|
||||
private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup");
|
||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd' 'HH:mm:ss");
|
||||
|
||||
public static Region getRegion(Location location) {
|
||||
return REGION_MAP.values().stream()
|
||||
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
|
||||
.findFirst()
|
||||
.orElse(GlobalRegion.instance);
|
||||
}
|
||||
|
||||
public static Set<Region> getRegion(Prototype prototype) {
|
||||
return REGION_MAP.values().stream()
|
||||
.filter(r -> r.getPrototype() == prototype)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static void setGlobal(Flag flagType, Flag.Value<?> value) {
|
||||
REGION_MAP.values().forEach(region -> region.set(flagType, value));
|
||||
}
|
||||
|
||||
YAPIONObject regionData;
|
||||
|
||||
private String name;
|
||||
private Prototype prototype;
|
||||
private Set<String> prototypes;
|
||||
private String skin;
|
||||
|
||||
private Point minPoint;
|
||||
private Point maxPoint;
|
||||
|
||||
private Point minPointTestblock;
|
||||
private Point maxPointTestblock;
|
||||
|
||||
private Point minPointTestblockExtension;
|
||||
private Point maxPointTestblockExtension;
|
||||
|
||||
private Point minPointBuild;
|
||||
private Point maxPointBuild;
|
||||
|
||||
private Point minPointBuildExtension;
|
||||
private Point maxPointBuildExtension;
|
||||
|
||||
private int floorLevel;
|
||||
private int waterLevel;
|
||||
|
||||
private Point copyPoint; // Nullable
|
||||
private Point testBlockPoint; // Nullable
|
||||
|
||||
private String linkedRegionName = null; // Nullable
|
||||
private Region linkedRegion = null; // Nullable
|
||||
|
||||
private FlagStorage flagStorage;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> undoSessions;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> redoSessions;
|
||||
|
||||
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
this.name = name;
|
||||
this.regionData = regionData;
|
||||
if (prototype != null) {
|
||||
REGION_MAP.put(name, this);
|
||||
}
|
||||
|
||||
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
||||
|
||||
prototypes = new HashSet<>();
|
||||
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
|
||||
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
|
||||
if (yapionAnyType instanceof YAPIONValue) {
|
||||
prototypes.add(((YAPIONValue<String>) yapionAnyType).get());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (regionConfig.containsKey("prototype")) {
|
||||
prototypes.add(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
|
||||
this.flagStorage = flagStorage;
|
||||
Point point = null;
|
||||
if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) {
|
||||
point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ"));
|
||||
}
|
||||
if (prototype != null && prototypes.contains(prototype.getName())) {
|
||||
generatePrototypeData(prototype, point);
|
||||
} else if (regionConfig.containsKey("prototype")) {
|
||||
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
|
||||
}
|
||||
if (prototype != null) {
|
||||
skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
|
||||
if (!prototype.getSkinMap().containsKey(skin)) {
|
||||
skin = prototype.getDefaultSkin();
|
||||
}
|
||||
}
|
||||
regionData.add("skin", skin);
|
||||
|
||||
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
|
||||
flagStorage.set(Flag.TNT, TNTMode.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePrototypeData(Prototype prototype, Point point) {
|
||||
if (prototype == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.prototype = prototype;
|
||||
this.skin = prototype.getDefaultSkin();
|
||||
|
||||
this.minPoint = point;
|
||||
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
||||
|
||||
if (prototype.getTestblock() != null) {
|
||||
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
|
||||
this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
||||
|
||||
this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
||||
this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
||||
|
||||
if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) {
|
||||
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
|
||||
} else {
|
||||
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (prototype.getBuild() != null) {
|
||||
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
|
||||
this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
||||
|
||||
this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
||||
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
||||
|
||||
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
||||
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
} else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) {
|
||||
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
|
||||
} else {
|
||||
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
|
||||
}
|
||||
} else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) {
|
||||
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
}
|
||||
|
||||
if (prototype.getFloorOffset() != 0) {
|
||||
floorLevel = minPoint.getY() + prototype.getFloorOffset();
|
||||
} else {
|
||||
floorLevel = 0;
|
||||
}
|
||||
|
||||
if (prototype.getWaterOffset() != 0) {
|
||||
waterLevel = minPoint.getY() + prototype.getWaterOffset();
|
||||
} else {
|
||||
waterLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
Point minBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointBuildExtension : minPointBuild;
|
||||
Point maxBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointBuildExtension : maxPointBuild;
|
||||
return inRegion(location, minBPoint, maxBPoint);
|
||||
case TESTBLOCK:
|
||||
Point minTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? minPointTestblockExtension : minPointTestblock;
|
||||
Point maxTBPoint = regionExtensionType == RegionExtensionType.EXTENSION ? maxPointTestblockExtension : maxPointTestblock;
|
||||
return inRegion(location, minTBPoint, maxTBPoint);
|
||||
default:
|
||||
case NORMAL:
|
||||
return inRegion(location, minPoint, maxPoint);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inRegion(Location location, Point minPoint, Point maxPoint) {
|
||||
int blockX = location.getBlockX();
|
||||
int blockY = location.getBlockY();
|
||||
int blockZ = location.getBlockZ();
|
||||
return blockX >= minPoint.getX() && blockX <= maxPoint.getX() &&
|
||||
blockY >= minPoint.getY() && blockY <= maxPoint.getY() &&
|
||||
blockZ >= minPoint.getZ() && blockZ <= maxPoint.getZ();
|
||||
}
|
||||
|
||||
public boolean hasType(RegionType regionType) {
|
||||
if (prototype == null) {
|
||||
return false;
|
||||
}
|
||||
if (regionType == null) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.getBuild() != null;
|
||||
case TESTBLOCK:
|
||||
return prototype.getTestblock() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasExtensionType(RegionType regionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
return prototype.getBuild().isExtensionRegistered();
|
||||
case TESTBLOCK:
|
||||
return prototype.getTestblock().isExtensionRegistered();
|
||||
default:
|
||||
case NORMAL:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return prototype != null ? prototype.getSkinMap().get(skin).getName() : "";
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Predicate<Region> regionConsumer) {
|
||||
if (linkedRegionName == null) {
|
||||
return;
|
||||
}
|
||||
if (linkedRegion != null) {
|
||||
if (regionConsumer.test(linkedRegion)) {
|
||||
RegionUtils.save(linkedRegion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (Region region : REGION_MAP.values()) {
|
||||
if (region.name.equals(linkedRegionName)) {
|
||||
linkedRegion = region;
|
||||
if (regionConsumer.test(linkedRegion)) {
|
||||
RegionUtils.save(linkedRegion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Region getLinkedRegion() {
|
||||
if (linkedRegion == null && linkedRegionName != null) {
|
||||
setLinkedRegion(region -> false);
|
||||
}
|
||||
return linkedRegion;
|
||||
}
|
||||
|
||||
public boolean setPrototype(@NonNull Prototype prototype) {
|
||||
if (!prototypes.contains(prototype.getName())) {
|
||||
return false;
|
||||
}
|
||||
return _setPrototype(prototype);
|
||||
}
|
||||
|
||||
boolean _setPrototype(@NonNull Prototype prototype) {
|
||||
generatePrototypeData(prototype, minPoint);
|
||||
RegionUtils.save(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setSkin(@NonNull String skinName) {
|
||||
if (!prototype.getSkinMap().containsKey(skinName)) {
|
||||
return false;
|
||||
}
|
||||
this.skin = skinName;
|
||||
setLinkedRegion(region -> {
|
||||
region.skin = skinName;
|
||||
return true;
|
||||
});
|
||||
regionData.add("skin", skin);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void set(Flag flagType, Flag.Value<?> value) {
|
||||
if (flagStorage.set(flagType, value)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(flagType, value));
|
||||
}
|
||||
|
||||
public void set(Tag tag) {
|
||||
if (flagStorage.set(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(tag));
|
||||
}
|
||||
|
||||
public void remove(Tag tag) {
|
||||
if (flagStorage.remove(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Flag.Value<?> get(Flag flagType) {
|
||||
return flagStorage.get(flagType);
|
||||
}
|
||||
|
||||
public boolean get(Tag tagType) {
|
||||
return flagStorage.is(tagType);
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) {
|
||||
return (T) flagStorage.get(flagType).getValue();
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) {
|
||||
return (T) flagStorage.get(flagType).getValue();
|
||||
}
|
||||
|
||||
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointTestblock : minPointTestblockExtension;
|
||||
case BUILD:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointBuild : minPointBuildExtension;
|
||||
default:
|
||||
case NORMAL:
|
||||
return minPoint;
|
||||
}
|
||||
}
|
||||
|
||||
public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointTestblock : maxPointTestblockExtension;
|
||||
case BUILD:
|
||||
return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointBuild : maxPointBuildExtension;
|
||||
default:
|
||||
case NORMAL:
|
||||
return maxPoint;
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasReset(RegionType regionType) {
|
||||
if (!hasType(regionType)) {
|
||||
return false;
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null;
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile() != null;
|
||||
}
|
||||
}
|
||||
|
||||
public File getResetFile(RegionType regionType) {
|
||||
if (!hasReset(regionType)) {
|
||||
return null;
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile();
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile();
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(PasteBuilder pasteBuilder, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
if (!hasReset(regionType)) {
|
||||
return;
|
||||
}
|
||||
if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) {
|
||||
regionExtensionType = RegionExtensionType.NORMAL;
|
||||
}
|
||||
|
||||
pasteBuilder.reset(regionExtensionType == RegionExtensionType.EXTENSION)
|
||||
.minPoint(getMinPoint(regionType, regionExtensionType))
|
||||
.maxPoint(getMaxPoint(regionType, regionExtensionType))
|
||||
.waterLevel(waterLevel);
|
||||
if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) {
|
||||
SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype();
|
||||
pasteBuilder.rotate(schematicType.fightType() || schematicType.check());
|
||||
}
|
||||
|
||||
switch (regionType) {
|
||||
case BUILD:
|
||||
pasteBuilder.pastePoint(minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2));
|
||||
break;
|
||||
case TESTBLOCK:
|
||||
Point pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, prototype.getTestblock().getSizeZ() / 2);
|
||||
if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) {
|
||||
SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype();
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("wg")) {
|
||||
pastePoint = pastePoint.add(0, 0, 1);
|
||||
}
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("ws")) {
|
||||
pastePoint = pastePoint.add(-1, 0, 1);
|
||||
}
|
||||
if (schematicType.getKuerzel().equalsIgnoreCase("as")) {
|
||||
pastePoint = pastePoint.add(-1, 0, 1);
|
||||
}
|
||||
}
|
||||
pasteBuilder.pastePoint(pastePoint);
|
||||
break;
|
||||
default:
|
||||
case NORMAL:
|
||||
pasteBuilder.pastePoint(minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2));
|
||||
break;
|
||||
}
|
||||
|
||||
initSessions();
|
||||
undoSessions.push(pasteBuilder.run());
|
||||
}
|
||||
|
||||
public void remember(EditSession editSession) {
|
||||
initSessions();
|
||||
undoSessions.push(editSession);
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return this == GlobalRegion.getInstance();
|
||||
}
|
||||
|
||||
private void initSessions() {
|
||||
if (undoSessions == null) {
|
||||
undoSessions = new SizedStack<>(20);
|
||||
redoSessions = new SizedStack<>(20);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean undo() {
|
||||
initSessions();
|
||||
EditSession session = undoSessions.pop();
|
||||
if (session == null)
|
||||
return false;
|
||||
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.undo(e);
|
||||
redoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean redo() {
|
||||
initSessions();
|
||||
EditSession session = redoSessions.pop();
|
||||
if (session == null)
|
||||
return false;
|
||||
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.redo(e);
|
||||
undoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean backup() {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
|
||||
File[] currentBackups = definedBackupFolder.listFiles();
|
||||
if (currentBackups != null && currentBackups.length >= 20) {
|
||||
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
||||
files.sort(Comparator.comparingLong(File::lastModified));
|
||||
while (files.size() >= 20) files.remove(0).delete();
|
||||
}
|
||||
|
||||
final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem");
|
||||
return FlatteningWrapper.impl.backup(minPoint, maxPoint, backupFile);
|
||||
}
|
||||
|
||||
public static boolean copy(Point minPoint, Point maxPoint, File file) {
|
||||
return FlatteningWrapper.impl.backup(minPoint, maxPoint, file);
|
||||
}
|
||||
|
||||
public List<String> listBackup() {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
|
||||
File[] currentBackups = definedBackupFolder.listFiles();
|
||||
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
|
||||
files.sort(Comparator.comparingLong(File::lastModified));
|
||||
return files.stream().map(File::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public File getBackupFile(String backupName) {
|
||||
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
definedBackupFolder.mkdirs();
|
||||
File[] files = definedBackupFolder.listFiles((dir, name) -> name.equals(backupName + ".schem"));
|
||||
if (files == null || files.length == 0) return null;
|
||||
return files[0];
|
||||
}
|
||||
|
||||
public void forEachChunk(ObjIntConsumer<Integer> executor) {
|
||||
for (int x = (int) Math.floor(minPoint.getX() / 16.0); x <= (int) Math.ceil(maxPoint.getX() / 16.0); x++) {
|
||||
for (int z = (int) Math.floor(minPoint.getZ() / 16.0); z <= (int) Math.ceil(maxPoint.getZ() / 16.0); z++) {
|
||||
executor.accept(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean buildChunkOutside(int chunkX, int chunkY) {
|
||||
if (!hasType(RegionType.BUILD)) {
|
||||
return Math.floor(minPoint.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPoint.getX() / 16.0) ||
|
||||
Math.floor(minPoint.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPoint.getZ() / 16.0);
|
||||
}
|
||||
if (!hasExtensionType(RegionType.BUILD)) {
|
||||
return Math.floor(minPointBuild.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuild.getX() / 16.0) ||
|
||||
Math.floor(minPointBuild.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuild.getZ() / 16.0);
|
||||
}
|
||||
return Math.floor(minPointBuildExtension.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPointBuildExtension.getX() / 16.0) ||
|
||||
Math.floor(minPointBuildExtension.getZ() / 16.0) > chunkY || chunkY >= Math.ceil(maxPointBuildExtension.getZ() / 16.0);
|
||||
}
|
||||
|
||||
public File gameModeConfig() {
|
||||
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
for (int version = Core.getVersion(); version >= 15; version--) {
|
||||
File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml");
|
||||
if (specific.exists()) return specific;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ package de.steamwar.bausystem.utils;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.core.VersionDependent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
@@ -26,8 +26,8 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import de.steamwar.bausystem.regionnew.Color;
|
||||
import de.steamwar.bausystem.regionnew.Point;
|
||||
import de.steamwar.bausystem.region.Color;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.sql.SchematicData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package de.steamwar.bausystem.utils.bossbar;
|
||||
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionSystem;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarFlag;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
@@ -101,7 +101,7 @@ public class GlobalBossbar implements BauSystemBossbar {
|
||||
|
||||
@Override
|
||||
public Region getRegion() {
|
||||
return GlobalRegion.getInstance();
|
||||
return RegionSystem.INSTANCE.getGlobalRegion();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -17,9 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.regionnew.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@@ -44,12 +44,12 @@ public class FixedFlagStorage implements FlagStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean set(Flag<T> flag, Flag.Value<T> value) {
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean set(Flag<T> flag, T value) {
|
||||
return flagMap.put(flag, value) != value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag<T> flag) {
|
||||
return (Flag.Value<T>) flagMap.get(flag);
|
||||
public <T extends Enum<T> & Flag.Value<T>> T get(Flag<T> flag) {
|
||||
return (T) flagMap.get(flag);
|
||||
}
|
||||
}
|
||||
+13
-49
@@ -17,15 +17,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.regionnew.flags.Flag;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -35,6 +33,7 @@ public final class FixedGlobalRegion implements Region {
|
||||
|
||||
private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
private final FlagStorage FLAG_STORAGE = FixedFlagStorage.createFromRegion(this); // TODO: Update to either File or Region creation!
|
||||
|
||||
private FixedGlobalRegion() {
|
||||
@@ -47,21 +46,21 @@ public final class FixedGlobalRegion implements Region {
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy hasFlag(@NonNull Flag<T> flag) {
|
||||
if (flag.oneOff(Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.ITEMS)) {
|
||||
if (flag.oneOf(Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.ITEMS, Flag.NO_GRAVITY)) {
|
||||
return RegionFlagPolicy.WRITABLE;
|
||||
}
|
||||
return RegionFlagPolicy.NOT_APPLICABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, Flag.Value<T> value) {
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, T value) {
|
||||
return hasFlag(flag).isWritable() && FLAG_STORAGE.set(flag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> Optional<Flag.Value<T>> getFlag(@NonNull Flag<T> flag) {
|
||||
public <T extends Enum<T> & Flag.Value<T>> Optional<T> getFlag(@NonNull Flag<T> flag) {
|
||||
if (hasFlag(flag).isReadable()) {
|
||||
return Optional.of(FLAG_STORAGE.get(flag));
|
||||
return Optional.ofNullable(FLAG_STORAGE.get(flag));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -83,33 +82,13 @@ public final class FixedGlobalRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getBuildMinPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
public Inner getBuildArea() {
|
||||
return Inner.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getBuildMaxPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inBuildRegion(Location location, boolean extension) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getTestblockMinPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getTestblockMaxPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inTestblockRegion(Location location, boolean extension) {
|
||||
return false;
|
||||
public Inner getTestblockArea() {
|
||||
return Inner.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,13 +102,8 @@ public final class FixedGlobalRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EditSession> copyBuild() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EditSession> copyTestblock() {
|
||||
return Optional.empty();
|
||||
public boolean backup(boolean automatic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,16 +111,6 @@ public final class FixedGlobalRegion implements Region {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remember(EditSession editSession) {
|
||||
|
||||
+13
-50
@@ -17,15 +17,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.regionnew.flags.Flag;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -42,12 +40,12 @@ public class FixedRegion implements Region { // TODO: Implement!
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, Flag.Value<T> value) {
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean setFlag(@NonNull Flag<T> flag, T value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> Optional<Flag.Value<T>> getFlag(@NonNull Flag<T> flag) {
|
||||
public <T extends Enum<T> & Flag.Value<T>> Optional<T> getFlag(@NonNull Flag<T> flag) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -67,33 +65,13 @@ public class FixedRegion implements Region { // TODO: Implement!
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getBuildMinPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
public Inner getBuildArea() {
|
||||
return Inner.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getBuildMaxPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inBuildRegion(Location location, boolean extension) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getTestblockMinPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Point> getTestblockMaxPoint(boolean extension) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inTestblockRegion(Location location, boolean extension) {
|
||||
return false;
|
||||
public Inner getTestblockArea() {
|
||||
return Inner.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,36 +79,21 @@ public class FixedRegion implements Region { // TODO: Implement!
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean backup(boolean automatic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EditSession> copy() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EditSession> copyBuild() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EditSession> copyTestblock() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remember(EditSession editSession) {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.regionnew;
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
Reference in New Issue
Block a user