SteamWar/BauSystem2.0
Archiviert
12
0

Commits vergleichen

..

3 Commits

Autor SHA1 Nachricht Datum
yoyosource
6bd8350fa5 Fix things!
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2024-04-21 16:15:32 +02:00
yoyosource
11a0bdbe8d Add FixedRegionSystem and ModularRegionSystem 2024-04-21 16:13:39 +02:00
yoyosource
5c48983375 TYPEREPLACE_HELPAdd initial modular bau impl 2024-04-21 16:13:33 +02:00
39 geänderte Dateien mit 2450 neuen und 1429 gelöschten Zeilen

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -23,9 +23,12 @@ import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils;
import de.steamwar.bausystem.linkage.LinkageUtils;
import de.steamwar.bausystem.region.FlagStorage;
import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.loader.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.utils.TickListener;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.AbstractValidator;
@ -33,6 +36,7 @@ import de.steamwar.command.SWCommandUtils;
import de.steamwar.message.Message;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
@ -40,6 +44,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import yapion.hierarchy.types.YAPIONObject;
import java.io.IOException;
import java.io.OutputStream;
@ -52,7 +57,6 @@ public class BauSystem extends JavaPlugin implements Listener {
// This should be treated as final!
public static Message MESSAGE;
public static final boolean DEV_SERVER = !System.getProperty("user.home").endsWith("minecraft");
@Getter
private static BauSystem instance;
@ -67,32 +71,31 @@ public class BauSystem extends JavaPlugin implements Listener {
instance = this;
SWUtils.setBausystem(instance);
new GlobalRegion(new FlagStorage(), new YAPIONObject());
/*
try {
PrototypeLoader.load();
RegionLoader.load();
} catch (SecurityException e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
Bukkit.shutdown();
System.exit(1);
return;
}
new Updater(PrototypeLoader.file, PrototypeLoader::load);
new Updater(RegionLoader.file, RegionLoader::load);
*/
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
Region.get(new Location(Bukkit.getWorlds().get(0), 0, 0, 0));
}, 10);
SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD));
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));
SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR));
SWCommandUtils.addValidator("owner", validator(Permission.OWNER));
try {
LinkageUtils.link();
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
Bukkit.shutdown();
System.exit(1);
return;
}
LinkageUtils.link();
TickListener.impl.init();
}

Datei anzeigen

@ -44,8 +44,6 @@ public class DesignEndStone {
private REntityServer entityServer = new REntityServer();
private List<REntity> entities = new ArrayList<>();
private Set<Location> locations = new HashSet<>();
private boolean wsOrAs;
private double maxBlastResistance;
public DesignEndStone(Region region) {
this.minX = region.getMinPointBuild().getX();
@ -54,17 +52,6 @@ public class DesignEndStone {
this.maxX = region.getMaxPointBuild().getX();
this.maxY = region.getMaxPointBuild().getY();
this.maxZ = region.getMaxPointBuild().getZ();
wsOrAs = region.getName().startsWith("ws") || region.getName().startsWith("as");
maxBlastResistance = wsOrAs ? 6.1 : 9.0;
entityServer.setCallback((player, rEntity, entityAction) -> {
if (entityAction != REntityServer.EntityAction.ATTACK) return;
Location location = new Location(WORLD, rEntity.getX(), rEntity.getY(), rEntity.getZ());
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
location.getBlock().breakNaturally();
calc();
}, 1);
});
}
public void calc() {
@ -76,24 +63,8 @@ public class DesignEndStone {
calc(minX, minY, maxZ, maxX, maxY, maxZ, 0, 0, -1, maxZ - minZ);
calc(minX, minY, minZ, minX, maxY, maxZ, 1, 0, 0, maxX - minX);
calc(maxX, minY, minZ, maxX, maxY, maxZ, -1, 0, 0, maxX - minX);
if (wsOrAs) {
calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY + 1);
} else {
int airBlocks = 0;
double minAirBlocks = (maxX - minX) * (maxZ - minZ) * 0.1;
for (int x = minX; x < maxX; x++) {
for (int z = minZ; z < maxZ; z++) {
if (WORLD.getBlockAt(x, minY, z).getType().isAir()) {
airBlocks++;
if (airBlocks > minAirBlocks) break;
}
}
}
if (airBlocks > minAirBlocks) {
calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY + 1);
}
}
calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY + 1);
// calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY);
calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY);
}
private void calc(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dirX, int dirY, int dirZ, int steps) {
@ -105,16 +76,15 @@ public class DesignEndStone {
int cy = y + step * dirY;
int cz = z + step * dirZ;
Material material = WORLD.getBlockAt(cx, cy, cz).getType();
if (material != Material.WATER && material != Material.LAVA && material.getBlastResistance() >= maxBlastResistance) {
if (material == Material.END_STONE || material == Material.END_STONE_BRICKS || material == Material.END_STONE_BRICK_SLAB || material == Material.END_STONE_BRICK_STAIRS || material == Material.END_STONE_BRICK_WALL) {
Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5);
if (!locations.add(location)) break;
if (locations.contains(location)) break;
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.RED_STAINED_GLASS);
entity.setNoGravity(true);
entity.setGlowing(true);
entities.add(entity);
break;
} else if (!material.isAir() && material != Material.WATER && material != Material.LAVA) {
} else if (!material.isAir()) {
break;
}
}

Datei anzeigen

@ -1,66 +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.features.region;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.NoGravityMode;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@Linked
public class NoGravityCommand extends SWCommand {
public NoGravityCommand() {
super("nogravity");
}
@Register(description = "REGION_NO_GRAVITY_HELP")
public void toggleCommand(@Validator Player p) {
Region region = Region.getRegion(p.getLocation());
if (toggle(region)) {
RegionUtils.actionBar(region, getEnableMessage());
} else {
RegionUtils.actionBar(region, getDisableMessage());
}
}
private String getEnableMessage() {
return "REGION_NO_GRAVITY_ENABLED";
}
private String getDisableMessage() {
return "REGION_NO_GRAVITY_DISABLED";
}
private boolean toggle(Region region) {
switch (region.getPlain(Flag.NO_GRAVITY, NoGravityMode.class)) {
case ACTIVE:
region.set(Flag.NO_GRAVITY, NoGravityMode.INACTIVE);
return false;
default:
case INACTIVE:
region.set(Flag.NO_GRAVITY, NoGravityMode.ACTIVE);
return true;
}
}
}

Datei anzeigen

@ -1,64 +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.features.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.NoGravityMode;
import de.steamwar.bausystem.utils.ScoreboardElement;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
@Linked
public class NoGravityListener implements Listener, ScoreboardElement {
private static NoGravityMode getMode(Region region) {
return region.getPlain(Flag.NO_GRAVITY, NoGravityMode.class);
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() == EntityType.PLAYER) return;
if (getMode(Region.getRegion(event.getLocation())) == NoGravityMode.ACTIVE) {
event.getEntity().setGravity(false);
}
}
@Override
public ScoreboardGroup getGroup() {
return ScoreboardGroup.REGION;
}
@Override
public int order() {
return 4;
}
@Override
public String get(Region region, Player p) {
if (region.get(Flag.NO_GRAVITY) == Flag.NO_GRAVITY.getDefaultValue()) return null;
return "§e" + BauSystem.MESSAGE.parse(Flag.NO_GRAVITY.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.NO_GRAVITY).getChatValue(), p);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.shieldprinting;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.shieldprinting.impl.*;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
@ -44,10 +45,12 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.util.Vector;

Datei anzeigen

@ -90,10 +90,11 @@ public class ProcessingTracesState implements LaufbauState {
Location location = current.getLocation();
if (current.getPrevious().isPresent()) {
Vector velocity = current.getPrevious().get().getVelocity();
Location previousLocation = current.getPrevious().get().getLocation();
Location movement = location.clone().subtract(previousLocation);
calculateCuboid(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98));
if (movement.getX() >= movement.getZ()) {
if (velocity.getX() >= velocity.getZ()) {
calculateCuboid(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
calculateCuboid(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
} else {

Datei anzeigen

@ -24,7 +24,6 @@ import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.core.Core;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.api.Plain;
@ -42,8 +41,9 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.RayTraceResult;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -83,6 +83,12 @@ public class SmartPlaceListener implements Plain, Listener {
}
private static final Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem");
private static final Class<?> entityPlayer = Reflection.getClass("{nms.server.level}.EntityPlayer");
private static final Class<?> craftPlayer = Reflection.getClass("{obc}.entity.CraftPlayer");
private static final Reflection.MethodInvoker getHandle = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer);
private static final Class<?> playerConnectionClazz = Reflection.getClass("{nms.server.network}.PlayerConnection");
private static final Reflection.FieldAccessor<?> playerConnection = Reflection.getField(entityPlayer, playerConnectionClazz, 0);
private static final Reflection.MethodInvoker packetExecutor = Reflection.getMethod(playerConnectionClazz, null, useItem);
private static final Set<Player> SMART_PLACING = new HashSet<>();
private static final Set<Player> WAS_EXECUTED = new HashSet<>();
@ -91,16 +97,14 @@ public class SmartPlaceListener implements Plain, Listener {
TinyProtocol.instance.addFilter(useItem, (player, packet) -> {
if(!Permission.BUILD.hasPermission(player)) return packet;
if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return packet;
RayTraceResult rayTraceResult = player.rayTraceBlocks(6);
Block block = rayTraceResult != null ? rayTraceResult.getHitBlock() : null;
BlockFace blockFace = rayTraceResult != null ? rayTraceResult.getHitBlockFace() : null;
Block block = player.getTargetBlockExact(6);
boolean shouldSneak = false;
if (block != null) {
ItemStack itemStack = player.getInventory().getItemInMainHand();
if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) {
shouldSneak = true;
}
if (CONTAINERS.contains(block.getType())) {
ItemStack itemStack = player.getInventory().getItemInMainHand();
if (itemStack.getType() == Material.TNT) {
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
shouldSneak = false;
@ -112,9 +116,6 @@ public class SmartPlaceListener implements Plain, Listener {
if (IGNORED.contains(block.getType())) {
shouldSneak = false;
}
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && itemStack.getType().isSolid()) {
shouldSneak = true;
}
}
boolean sneaking = player.isSneaking();
if (sneaking) SMART_PLACING.add(player);
@ -148,10 +149,10 @@ public class SmartPlaceListener implements Plain, Listener {
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
if (!SMART_PLACING.contains(event.getPlayer())) {
if (Core.getVersion() >= 20 && CONTAINERS.contains(event.getBlockAgainst().getType())) {
if (CONTAINERS.contains(event.getBlockAgainst().getType())) {
SoundGroup soundGroup = event.getBlockPlaced().getBlockData().getSoundGroup();
event.getPlayer().playSound(event.getBlockPlaced().getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
}

Datei anzeigen

@ -219,9 +219,6 @@ public class TNTPoint implements Externalizable {
public boolean equals(Object obj) {
if (!(obj instanceof TNTPoint)) return false;
TNTPoint record = (TNTPoint) obj;
if (record.getTntId() != tntId) return false;
if (record.getFuse() != fuse) return false;
if (record.getTicksSinceStart() != ticksSinceStart) return false;
if (record.isExplosion() != explosion) return false;
if (!record.getLocation().equals(location)) return false;
if (!record.getVelocity().equals(velocity)) return false;

Datei anzeigen

@ -29,14 +29,11 @@ import de.steamwar.entity.REntityServer;
import lombok.Cleanup;
import lombok.Getter;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.*;
import java.lang.ref.SoftReference;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.GZIPInputStream;
@ -191,19 +188,7 @@ public class Trace {
* @param playerTraceShowData The showData for modifying the rendering
*/
protected void render(List<TNTPoint> records, Player player, PlayerTraceShowData playerTraceShowData) {
REntityServer entityServer = entityServerMap.computeIfAbsent(player, k -> {
REntityServer newEntityServer = new REntityServer();
newEntityServer.addPlayer(k);
newEntityServer.setCallback((p, rEntity, entityAction) -> {
if (entityAction != REntityServer.EntityAction.INTERACT) return;
if (rEntity instanceof TraceEntity) {
((TraceEntity) rEntity).printIntoChat(p);
}
});
return newEntityServer;
});
render(records, entityServer, playerTraceShowData);
render(records, entityServerMap.get(player), playerTraceShowData);
}
/**
@ -311,28 +296,16 @@ public class Trace {
/**
* Loads the records of this trace from storage to memory
*/
@SneakyThrows
private void loadRecords() {
List<TNTPoint> records = new ArrayList<>();
long readBytes = 0;
try {
FileInputStream fileInputStream = new FileInputStream(recordsSaveFile);
@Cleanup
ObjectInputStream inputStream = new ObjectInputStream(new GZIPInputStream(fileInputStream));
long fileLenght = recordsSaveFile.length();
while (fileInputStream.getChannel().position() < fileLenght) {
records.add((TNTPoint) inputStream.readObject());
readBytes = fileInputStream.getChannel().position();
}
} catch (EOFException e) {
Logger logger = Bukkit.getLogger();
logger.log(Level.WARNING, "EOF in trace read detected in " + uuid);
logger.log(Level.WARNING, "Read " + readBytes + "/" + recordsSaveFile.length() + " Bytes");
logger.log(Level.WARNING, "Read so far: " + records);
FileInputStream fileInputStream = new FileInputStream(recordsSaveFile);
e.printStackTrace();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
@Cleanup
ObjectInputStream inputStream = new ObjectInputStream(new GZIPInputStream(fileInputStream));
while (fileInputStream.getChannel().position() < recordsSaveFile.length()) {
records.add((TNTPoint) inputStream.readObject());
}
Map<Integer, List<TNTPoint>> histories = new HashMap<>();
@ -346,7 +319,7 @@ public class Trace {
this.records = new SoftReference<>(records);
}
public synchronized List<TNTPoint> getRecords() {
public List<TNTPoint> getRecords() {
if (records.get() == null) {
loadRecords();
}

Datei anzeigen

@ -57,21 +57,17 @@ public class TraceCommand extends SWCommand {
public void stop(@Validator Player player) {
Region region = Region.getRegion(player.getLocation());
TraceRecorder.instance.stopRecording(region);
if (TraceRecorder.instance.isAutoTraceEnabledInRegion(region)) {
TraceRecorder.instance.removeAutoTraceRegion(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_STOP", player);
} else {
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
}
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
}
@Register(value = "auto", description = "TRACE_COMMAND_HELP_AUTO")
public void auto(@Validator Player player) {
Region region = Region.getRegion(player.getLocation());
TraceRecorder.instance.addAutoTraceRegion(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_START", player);
if (TraceRecorder.instance.toggleAutoTrace(region)) {
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_START", player);
} else {
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_STOP", player);
}
}
@Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW")
@ -138,7 +134,6 @@ public class TraceCommand extends SWCommand {
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", player);
}
@Register(value = "delete")
@Register(value = "clear")
public void clear(@Validator Player player) {
TraceManager.instance.clear(Region.getRegion(player.getLocation()));
@ -157,9 +152,9 @@ public class TraceCommand extends SWCommand {
BauSystem.MESSAGE.send("TRACE_MESSAGE_ISOLATE", player);
}
@Register(value = "broadcast", description = "TRACE_COMMAND_HELP_BROADCAST")
public void broadcast(@Validator Player player) {
BauSystem.MESSAGE.broadcast("TRACE_MESSAGE_BROADCAST", "TRACE_MESSAGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace follow " + player.getName()), player.getName());
@Register(value = "share", description = "TRACE_COMMAND_HELP_SHARE")
public void share(@Validator Player player) {
BauSystem.MESSAGE.broadcast("TRACE_MESSAGE_SHARE", "TRACE_MESSAGE_SHARE_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace follow " + player.getName()), player.getName());
}
@Register(value = "follow", description = "TRACE_COMMAND_HELP_FOLLOW")
@ -252,7 +247,7 @@ public class TraceCommand extends SWCommand {
@Override
public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) {
for (ViewFlag flag : ViewFlag.flags) {
if (s.equals("-" + flag.name)) {
if (s.equals("--" + flag.name)) {
return flag;
}
@ -268,7 +263,7 @@ public class TraceCommand extends SWCommand {
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return ViewFlag.flags.stream()
.flatMap(viewFlag -> Stream.concat(Stream.of("-" + viewFlag.name),
.flatMap(viewFlag -> Stream.concat(Stream.of("--" + viewFlag.name),
Arrays.stream(viewFlag.aliases).map(name -> "-" + name)))
.collect(Collectors.toList());
}

Datei anzeigen

@ -152,7 +152,7 @@ public class TraceManager implements Listener {
.keySet()
.forEach(player -> {
Set<Player> players = followerMap.getOrDefault(player, Collections.emptySet());
tracesByRegion.getOrDefault(region, new HashMap<>()).values().forEach(trace -> {
tracesByRegion.get(region).values().forEach(trace -> {
trace.hide(player);
players.forEach(trace::hide);
});

Datei anzeigen

@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.region.Region;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
@ -33,8 +32,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@Linked
public class TraceRecorder implements Listener {
@ -77,12 +74,18 @@ public class TraceRecorder implements Listener {
}, 0, 1);
}
public void addAutoTraceRegion(Region region) {
autoTraceRegions.add(region);
}
public void removeAutoTraceRegion(Region region) {
autoTraceRegions.remove(region);
/**
* Toggles auto trace for the given region
*
* @param region
*/
public boolean toggleAutoTrace(Region region) {
if (!autoTraceRegions.remove(region)) {
autoTraceRegions.add(region);
return true;
} else {
return false;
}
}
/**
@ -101,11 +104,14 @@ public class TraceRecorder implements Listener {
*
* @param region region to be recorded
*/
public void startRecording(Region region) {
if (activeTraces.containsKey(region)) return;
public int startRecording(Region region) {
if (activeTraces.containsKey(region)) {
return -1;
}
TraceRecordingWrapper wrappedTrace = new TraceRecordingWrapper(region);
activeTraces.put(region, wrappedTrace);
return TraceManager.instance.add(wrappedTrace.getTrace());
}
/**
@ -118,6 +124,7 @@ public class TraceRecorder implements Listener {
if (wrappedTrace == null) return;
wrappedTrace.finalizeRecording();
activeTraces.remove(region);
for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) {
historyMap.remove(tnt);
@ -131,19 +138,9 @@ public class TraceRecorder implements Listener {
private void record() {
for (Region region : activeTraces.keySet()) {
TraceRecordingWrapper wrappedTrace = activeTraces.get(region);
Iterator<TNTPrimed> iter = trackedTNT.getOrDefault(region, Collections.emptyList()).iterator();
while (iter.hasNext()) {
TNTPrimed tnt = iter.next();
if (tnt.getFuseTicks() == 80) continue;
for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) {
TNTPoint record = record(tnt, wrappedTrace, Collections.emptyList());
if (record == null) {
iter.remove();
tntSpawnRegion.remove(tnt);
historyMap.remove(tnt);
tntSpawnRegion.remove(tnt);
} else {
wrappedTrace.addRecord(record);
}
wrappedTrace.addRecord(record);
}
wrappedTrace.commitRecorded();
}
@ -159,26 +156,10 @@ public class TraceRecorder implements Listener {
*/
private TNTPoint record(TNTPrimed tntPrimed, TraceRecordingWrapper wrappedTrace, List<Block> destroyedBlocks) {
List<TNTPoint> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>());
// Failsave for tnt entering unloaded chunks
if (tntPrimed == null || tntPrimed.isDead() || history.size() > 0 && history.get(history.size() - 1).getFuse() == tntPrimed.getFuseTicks()) {
return null;
}
int tntID;
if (history.size() == 0) {
try {
historyMap.put(tntPrimed, history);
}
catch (NullPointerException e) {
Logger logger = Bukkit.getLogger();
//TODO remove when no longer neccecary
logger.log(Level.WARNING, "Nullpointer thrown by historyMap");
logger.log(Level.WARNING, "TNT History: " + history);
logger.log(Level.WARNING, "History Map: " + historyMap);
throw e;
}
historyMap.put(tntPrimed, history);
tntID = wrappedTrace.getNextOpenRecordIdAndIncrement();
} else {
tntID = history.get(0).getTntId();
@ -190,7 +171,7 @@ public class TraceRecorder implements Listener {
}
boolean afterFirstExplosion = wrappedTrace.isExplosionRecorded();
TNTPoint record = new TNTPoint(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentRealTick.get() - wrappedTrace.getStartTick(), history, destroyedBlocks);
TNTPoint record = new TNTPoint(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentTick.get() - wrappedTrace.getStartTick(), history, destroyedBlocks);
history.add(record);
return record;
@ -204,22 +185,6 @@ public class TraceRecorder implements Listener {
return activeTraces.containsKey(region);
}
/**
* Get the trace that is currently recorded in the given region
*
* @param region the region to get the trace for
* @return the trace recorded in region or empty if no trace is recorded in region
*/
public Optional<Trace> getActiveTraceForRegion(Region region) {
TraceRecordingWrapper traceWrapper = activeTraces.get(region);
if (traceWrapper == null) {
return Optional.empty();
} else {
return Optional.of(traceWrapper.getTrace());
}
}
public long getStartTimeOfTraceInRegion(Region region) {
TraceRecordingWrapper wrapper = activeTraces.get(region);
if (wrapper == null) return 0;
@ -260,16 +225,15 @@ public class TraceRecorder implements Listener {
*
* @param event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTNTExplode(EntityExplodeEvent event) {
if (!(event.getEntity() instanceof TNTPrimed)) return;
Region region = tntSpawnRegion.getOrDefault((TNTPrimed) event.getEntity(), null);
if (region == null) return;
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());
tntSpawnRegion.remove((TNTPrimed) event.getEntity());
activeTraces.get(region).addRecord(record((TNTPrimed) event.getEntity(), activeTraces.get(region), event.blockList()));
tntSpawnRegion.remove((TNTPrimed) event.getEntity());
historyMap.remove((TNTPrimed) event.getEntity());
}
}

Datei anzeigen

@ -53,6 +53,7 @@ public class TraceRecordingWrapper {
recordList = new ArrayList<>();
trace = new Trace(region, recordList);
TraceManager.instance.add(trace);
File recordsSaveFile = new File(TraceManager.tracesFolder, trace.getUuid() + ".records");
recordsOutputStream = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(recordsSaveFile)));
}
@ -89,6 +90,9 @@ public class TraceRecordingWrapper {
protected void finalizeRecording() {
recordsOutputStream.flush();
recordsOutputStream.close();
TraceManager.instance.add(trace);
if (trace.getRecords().isEmpty()) {
TraceManager.instance.remove(trace);
}
}
}

Datei anzeigen

@ -19,16 +19,20 @@
package de.steamwar.bausystem.features.tracer.rendering;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tracer.TNTPoint;
import de.steamwar.bausystem.features.tracer.Trace;
import de.steamwar.bausystem.features.tracer.TraceManager;
import de.steamwar.core.Core;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.techhider.BlockIds;
import lombok.Getter;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.List;
@ -37,7 +41,9 @@ import java.util.stream.Collectors;
/**
* Wrapper for the rendering of a record bundle
*/
public class TraceEntity extends RFallingBlockEntity {
public class TraceEntity extends REntity {
private static final Reflection.MethodInvoker addEntityMethod = Reflection.getMethod(REntityServer.class, "addEntity", REntity.class);
/**
* The records represented by this REntity
@ -53,11 +59,12 @@ public class TraceEntity extends RFallingBlockEntity {
private final Trace trace;
public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TNTPoint> records, Trace trace) {
super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT);
this.records = records;
this.trace = trace;
uniqueTntIdsString = records.stream().map(TNTPoint::getTntId).distinct().map(Object::toString).collect(Collectors.joining(" "));
super(server, EntityType.FALLING_BLOCK, location, BlockIds.impl.materialToId(isExplosion ? Material.RED_STAINED_GLASS : Material.TNT) >> (Core.getVersion() <= 12 ? 4 : 0));
setNoGravity(true);
this.records = records;
uniqueTntIdsString = records.stream().map(TNTPoint::getTntId).distinct().map(Object::toString).collect(Collectors.joining(" "));
this.trace = trace;
addEntityMethod.invoke(server, this);
}
/**
@ -78,4 +85,11 @@ public class TraceEntity extends RFallingBlockEntity {
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, representative.getVelocity().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + TraceManager.instance.getId(trace) + " " + uniqueTntIdsString));
}
@Override
public boolean equals(Object object) {
if (!(object instanceof TraceEntity)) return false;
TraceEntity entity = (TraceEntity) object;
return records.get(0).equals(entity.getRecords().get(0));
}
}

Datei anzeigen

@ -26,7 +26,10 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -34,9 +37,6 @@ import java.util.stream.Stream;
* A settable flag that changes how a trace is rendered
*/
public abstract class ViewFlag {
public static final Vector GRAVATY = new Vector(0.0, -0.04, 0.0);
public static final Vector DRAG_FACTOR = new Vector(0.98, 0.98, 0.98);
/**
* Static registry of static flags
*/
@ -120,29 +120,26 @@ public abstract class ViewFlag {
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {
for (TraceEntity entity : entities) {
TNTPoint representative = entity.getRecords().get(0);
Optional<TNTPoint> prev = representative.getPrevious();
if (prev.isEmpty()) continue;
TNTPoint current = entity.getRecords().get(0);
if (current.isExplosion()) continue;
TNTPoint next = current.getNext().orElse(null);
if (next == null) continue;
TNTPoint previous = prev.get();
Location delta = representative.getLocation().clone().subtract(previous.getLocation());
Vector previousVelocity = previous.isAfterFirstExplosion() ? previous.getVelocity() : delta.toVector().clone().divide(DRAG_FACTOR).subtract(GRAVATY);
Location pos = current.getLocation().clone();
pos.setY(next.getLocation().getY());
Location yLocation = previous.getLocation().clone().add(0, delta.getY(), 0);
if (yLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && yLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) {
RFallingBlockEntity y = new RFallingBlockEntity(server, yLocation, Material.WHITE_STAINED_GLASS);
if (pos.distanceSquared(current.getLocation()) >= 1.0 / 256.0) {
RFallingBlockEntity y = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS);
y.setNoGravity(true);
}
Location secoundLocation;
if (previousVelocity.getX() >= previousVelocity.getZ()) {
secoundLocation = previous.getLocation().clone().add(delta.getX(), delta.getY(), 0);
if (current.getVelocity().getX() >= current.getVelocity().getZ()) {
pos.setX(next.getLocation().getX());
} else {
secoundLocation = previous.getLocation().clone().add(0, delta.getY(), delta.getZ());
pos.setZ(next.getLocation().getZ());
}
if (secoundLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && secoundLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) {
RFallingBlockEntity second = new RFallingBlockEntity(server, secoundLocation, Material.WHITE_STAINED_GLASS);
if (pos.distanceSquared(next.getLocation()) >= 1.0 / 256.0) {
RFallingBlockEntity second = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS);
second.setNoGravity(true);
}
}

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.bausystem.features.warp;
import de.steamwar.bausystem.region.Region;
import de.steamwar.core.Core;
import de.steamwar.entity.RArmorStand;
import de.steamwar.entity.REntityServer;
import de.steamwar.linkage.Linked;
@ -108,9 +107,9 @@ public class WarpListener implements Listener {
vector.setY(0);
Vector position = p.getLocation().toVector().clone().add(vector.normalize().multiply(5));
position.setY(p.getLocation().getY() - (Core.getVersion() >= 20 ? 0 : 1));
position.setY(p.getLocation().getY() - 1);
if ((position.getX() - current.getX()) * (position.getX() - current.getX()) + (position.getZ() - current.getZ()) * (position.getZ() - current.getZ()) < 0.1) {
if (position.distanceSquared(current) < 0.1) {
name = "§a§l" + name;
selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location);
}

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.BauServer;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.BauweltMember;
@ -35,7 +34,6 @@ public class AntiBauAddMemberFix implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) {
if (BauSystem.DEV_SERVER) return;
if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) {
return;
}

Datei anzeigen

@ -36,26 +36,21 @@ public class ClipboardListener implements Listener {
@EventHandler
public void onLogin(PlayerJoinEvent e) {
if (!Permission.SUPERVISOR.hasPermission(e.getPlayer())) return;
if(!Permission.SUPERVISOR.hasPermission(e.getPlayer())) return;
SchematicNode schematic;
try {
schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, (Integer) null);
} catch (Exception ex) {
return;
}
if (schematic == null) return;
try {
new SchematicData(schematic).loadToPlayer(e.getPlayer());
SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, (Integer) null);
if (schematic != null) {
new SchematicData(schematic).loadToPlayer(e.getPlayer());
}
} catch (Exception ex) {
// ignore cause players do all kind of stuff with schematics.... like massively oversized schems
schematic.delete();
}
}
@EventHandler
public void onLogout(PlayerQuitEvent e) {
if (!Permission.SUPERVISOR.hasPermission(e.getPlayer())) return;
if(!Permission.SUPERVISOR.hasPermission(e.getPlayer())) return;
SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, (Integer) null);
boolean newSchem = false;

Datei anzeigen

@ -41,7 +41,6 @@ import org.bukkit.event.block.BlockMultiPlaceEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.*;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
@ -117,11 +116,9 @@ public class SpectatorListener implements Listener {
private static void resendChunks(Player player) {
Location location = player.getLocation().clone();
Vector velocity = player.getVelocity().clone();
player.teleport(location.clone().add(16.0 * player.getClientViewDistance() + 32, 0, 16.0 * player.getClientViewDistance() + 32));
player.teleport(location.clone().add(16.0 * player.getClientViewDistance(), 0, 16.0 * player.getClientViewDistance()));
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
player.teleport(location);
player.setVelocity(velocity);
}, 5);
}
@ -131,7 +128,6 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (BauSystem.DEV_SERVER) return;
if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) {
return;
}
@ -152,7 +148,7 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
if (!anySupervisorOnline(null) && !BauSystem.DEV_SERVER) {
if (!anySupervisorOnline(null)) {
Bukkit.getOnlinePlayers().forEach(player -> {
player.kickPlayer("");
});
@ -169,7 +165,6 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
NO_TECHHIDER.remove(event.getPlayer());
if (BauSystem.DEV_SERVER) return;
if (!anySupervisorOnline(event.getPlayer())) {
Bukkit.getOnlinePlayers().forEach(player -> {
player.kickPlayer("");

Datei anzeigen

@ -46,6 +46,7 @@ import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Datei anzeigen

@ -35,7 +35,8 @@ public enum Flag implements EnumDisplay {
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE),
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE),
ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE),
NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE),
TESTBLOCK("FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE),
CHANGED("FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE),
;
@Getter

Datei anzeigen

@ -0,0 +1,58 @@
/*
* 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.region.flags.flagvalues;
import de.steamwar.bausystem.region.flags.Flag;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ChangedMode implements Flag.Value<ChangedMode> {
NO_CHANGE("FLAG_CHANGED_NO_CHANGE", false),
HAS_CHANGE("FLAG_CHANGED_HAS_CHANGE", true);
private static ChangedMode[] values;
private final String chatValue;
private final Boolean changed;
@Override
public ChangedMode[] getValues() {
if (ChangedMode.values == null) {
ChangedMode.values = ChangedMode.values(); //NOSONAR
}
return ChangedMode.values;
}
@Override
public ChangedMode getValue() {
return this;
}
@Override
public ChangedMode getValueOf(final String name) {
try {
return ChangedMode.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}

Datei anzeigen

@ -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;
}
}
}

Datei anzeigen

@ -0,0 +1,62 @@
/*
* 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.region.flags.flagvalues;
import de.steamwar.bausystem.region.flags.Flag;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum TestblockMode implements Flag.Value<TestblockMode> {
NO_VALUE("FLAG_TESTBLOCK_NO_VALUE", false, false),
NORTH("FLAG_TESTBLOCK_NORTH", false, true),
SOUTH("FLAG_TESTBLOCK_SOUTH", false, false),
FIXED_NORTH("FLAG_TESTBLOCK_NORTH", true, true),
FIXED_SOUTH("FLAG_TESTBLOCK_SOUTH", true, false);
private static TestblockMode[] values;
private final String chatValue;
private final boolean fixed;
private final boolean north;
@Override
public TestblockMode[] getValues() {
if (TestblockMode.values == null) {
TestblockMode.values = TestblockMode.values(); //NOSONAR
}
return TestblockMode.values;
}
@Override
public TestblockMode getValue() {
return this;
}
@Override
public TestblockMode getValueOf(final String name) {
try {
return TestblockMode.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,176 @@
/*
* 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.region.Point;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Optional;
public class GlobalRegion implements Region {
public static final Region GLOBAL_REGION = new GlobalRegion();
private GlobalRegion() {
}
@Override
public RegionType getRegionType() {
return RegionType.GLOBAL;
}
@Override
public HasFlagResult hasFlag(Flag flag) {
return switch (flag) {
case TNT, FIRE, FREEZE, ITEMS -> HasFlagResult.WRITABLE;
default -> HasFlagResult.NOT_APPLICABLE;
};
}
@Override
public void setFlag(Flag flag, Flag.Value<?> value) {
}
@Override
public Flag.Value<?> getFlag(Flag flagType) {
return null;
}
@Override
public Point getMinPoint() {
return new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
}
@Override
public Point getMaxPoint() {
return new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
}
@Override
public boolean inRegion(Location location) {
return true;
}
@Override
public Optional<Point> getBuildMinPoint(boolean extension) {
return Optional.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;
}
@Override
public void forEachChunk(ChunkCoordinatesConsumer consumer) {
}
@Override
public ChunkCoordinatePredicate getChunkOutsidePredicate() {
return (chunkX, chunkZ) -> false;
}
@Override
public Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<File> getGameModeConfig() {
return Optional.empty();
}
@Override
public Optional<EditSession> copy() {
return Optional.empty();
}
@Override
public Optional<EditSession> copyBuild(boolean extension) {
return Optional.empty();
}
@Override
public Optional<EditSession> copyTestblock(boolean extension) {
return Optional.empty();
}
@Override
public void reset() {
}
@Override
public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void resetBuildWireframe(boolean extension) {
}
@Override
public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void remember(EditSession editSession) {
}
@Override
public boolean undo() {
return false;
}
@Override
public boolean redo() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,160 @@
/*
* 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.region.Point;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.sql.SchematicNode;
import lombok.RequiredArgsConstructor;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
public interface Region {
RegionSystem regionSystem = load();
private static RegionSystem load() {
try {
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.ModularRegionSystem").getConstructor().newInstance();
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
static Region get(Location location) {
return regionSystem.get(location);
}
enum HasFlagResult {
NOT_APPLICABLE,
READ_ONLY,
WRITABLE
}
@RequiredArgsConstructor
enum RegionType {
GLOBAL(false, false, false, true),
WATER(true, false, false, false),
WATER_CONNECTING(true, false, false, false),
LAND(false, true, false, false),
LAND_CONNECTING(false, true, false, false),
WALL(false, false, true, false),
OLD(false, false, false, false),
;
public final boolean water;
public final boolean land;
public final boolean wall;
public final boolean global;
}
interface ChunkCoordinatesConsumer {
void accept(int chunkX, int chunkZ);
}
interface ChunkCoordinatePredicate {
boolean test(int chunkX, int chunkZ);
}
RegionType getRegionType();
HasFlagResult hasFlag(Flag flag);
void setFlag(Flag flag, Flag.Value<?> value);
Flag.Value<?> getFlag(Flag flagType);
default <T extends Enum<T> & Flag.Value<T>> T getFlagValue(Flag flagType) {
Flag.Value<?> value = getFlag(flagType);
if (value == null) return null;
return (T) value.getValue();
}
default <T extends Enum<T> & Flag.Value<T>> T getFlagValue(Flag flagType, Class<T> type) {
return getFlagValue(flagType);
}
Point getMinPoint();
Point getMaxPoint();
boolean inRegion(Location location);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getBuildMinPoint(boolean extension);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getBuildMaxPoint(boolean extension);
boolean inBuildRegion(Location location, boolean extension);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getTestblockMinPoint(boolean extension);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getTestblockMaxPoint(boolean extension);
boolean inTestblockRegion(Location location, boolean extension);
void forEachChunk(ChunkCoordinatesConsumer consumer);
ChunkCoordinatePredicate getChunkOutsidePredicate();
Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension);
Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension);
Optional<File> getGameModeConfig();
Optional<EditSession> copy();
Optional<EditSession> copyBuild(boolean extension);
Optional<EditSession> copyTestblock(boolean extension);
void reset();
void resetBuild(@Nullable SchematicNode schematicNode, boolean extension);
void resetBuildWireframe(boolean extension);
void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension);
void remember(EditSession editSession);
boolean undo();
boolean redo();
}

Datei anzeigen

@ -0,0 +1,41 @@
/*
* 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 org.bukkit.Location;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
public interface RegionSystem {
void load();
void save();
Region get(Location location);
Optional<Region> get(String name);
Stream<Region> getRegions();
boolean isModular();
// TODO: Add creating and removing of Regions as well as moving
}

Datei anzeigen

@ -85,7 +85,7 @@ public class WorldData {
try {
worldData.toYAPION(new FileOutput(optionsFile)).close();
} catch (IOException e) {
e.printStackTrace();
// Ignored
}
}
}

Datei anzeigen

@ -1,7 +1,7 @@
name: BauSystem
authors: [ Lixfel, YoyoNow, Chaoscaot, Zeanon, D4rkr34lm ]
authors: [Lixfel, YoyoNow, Chaoscaot, Zeanon]
version: "2.0"
depend: [ WorldEdit, SpigotCore ]
depend: [WorldEdit, SpigotCore]
load: POSTWORLD
main: de.steamwar.bausystem.BauSystem
api-version: "1.13"

Datei anzeigen

@ -0,0 +1,56 @@
/*
* 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/>.
*/
plugins {
id 'base'
id 'java'
}
group 'steamwar'
version '1.0'
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 17
targetCompatibility = 17
sourceSets {
main {
java {
srcDirs = ['src/']
}
resources {
srcDirs = ['src/']
exclude '**/*.java', '**/*.kt'
}
}
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation project(":BauSystem_Main")
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
compileOnly swdep('SpigotCore')
compileOnly swdep('FastAsyncWorldEdit-1.18')
}

Datei anzeigen

@ -0,0 +1,182 @@
/*
* 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.region;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.TestblockMode;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Optional;
public class FixedRegionImpl implements Region { // TODO: Finalize this
@Override
public RegionType getRegionType() {
return RegionType.OLD;
}
@Override
public HasFlagResult hasFlag(Flag flag) {
return switch (flag) {
case TNT, FIRE, FREEZE, ITEMS, CHANGED -> HasFlagResult.WRITABLE;
case COLOR -> HasFlagResult.WRITABLE; // TODO Only for normal Regions not Spawn Region
case PROTECT -> HasFlagResult.WRITABLE; // TODO: Only for protectable Regions
case TESTBLOCK -> HasFlagResult.READ_ONLY; // TODO: Implement NOT_APPLICABLE for Special regions
};
}
@Override
public void setFlag(Flag flag, Flag.Value<?> value) {
}
@Override
public Flag.Value<?> getFlag(Flag flagType) {
if (flagType == Flag.TESTBLOCK) {
return TestblockMode.NO_VALUE; // TODO: This needs to change based on if the Region is a WarShip Region
}
return null;
}
@Override
public Point getMinPoint() {
return null;
}
@Override
public Point getMaxPoint() {
return null;
}
@Override
public boolean inRegion(Location location) {
return false;
}
@Override
public Optional<Point> getBuildMinPoint(boolean extension) {
return Optional.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;
}
@Override
public void forEachChunk(ChunkCoordinatesConsumer consumer) {
}
@Override
public ChunkCoordinatePredicate getChunkOutsidePredicate() {
return null;
}
@Override
public Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<File> getGameModeConfig() {
return Optional.empty();
}
@Override
public Optional<EditSession> copy() {
return Optional.empty();
}
@Override
public Optional<EditSession> copyBuild(boolean extension) {
return Optional.empty();
}
@Override
public Optional<EditSession> copyTestblock(boolean extension) {
return Optional.empty();
}
@Override
public void reset() {
}
@Override
public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void resetBuildWireframe(boolean extension) {
}
@Override
public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void remember(EditSession editSession) {
}
@Override
public boolean undo() {
return false;
}
@Override
public boolean redo() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,76 @@
/*
* 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.region;
import de.steamwar.bausystem.regionnew.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem;
import lombok.Getter;
import org.bukkit.Location;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
public class FixedRegionSystem implements RegionSystem {
@Getter
private static FixedRegionSystem instance;
public FixedRegionSystem() {
instance = this;
}
private static final Map<String, Region> REGION_MAP = new HashMap<>();
@Override
public void load() {
// TODO: Add Load
}
@Override
public void save() {
// TODO: Add Save
}
@Override
public Region get(Location location) {
return REGION_MAP.values().stream()
.filter(region -> region.inRegion(location))
.findFirst()
.orElse(GlobalRegion.GLOBAL_REGION);
}
@Override
public Optional<Region> get(String name) {
return Optional.ofNullable(REGION_MAP.get(name));
}
@Override
public Stream<Region> getRegions() {
return REGION_MAP.values().stream();
}
@Override
public boolean isModular() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
* 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/>.
*/
plugins {
id 'base'
id 'java'
}
group 'steamwar'
version '1.0'
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 17
targetCompatibility = 17
sourceSets {
main {
java {
srcDirs = ['src/']
}
resources {
srcDirs = ['src/']
exclude '**/*.java', '**/*.kt'
}
}
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation project(":BauSystem_Main")
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
compileOnly swdep('SpigotCore')
compileOnly swdep('FastAsyncWorldEdit-1.18')
}

Datei anzeigen

@ -0,0 +1,88 @@
/*
* 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.region;
import de.steamwar.bausystem.regionnew.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem;
import lombok.Getter;
import org.bukkit.Location;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
public class ModularRegionSystem implements RegionSystem {
@Getter
private static ModularRegionSystem instance;
public ModularRegionSystem() {
instance = this;
new TileActionBar();
}
private Map<Tile, UUID> OCCUPIED_TILES = new HashMap<>();
private Map<UUID, Region> REGIONS = new HashMap<>();
private Map<String, Region> REGIONS_BY_NAME = new HashMap<>();
@Override
public void load() {
// TODO: Add Load
}
@Override
public void save() {
// TODO: Add Save
}
public Region get(Tile tile) {
if (tile == null) {
return GlobalRegion.GLOBAL_REGION;
}
UUID uuid = OCCUPIED_TILES.get(tile);
if (uuid == null) {
return GlobalRegion.GLOBAL_REGION;
}
return REGIONS.get(uuid);
}
@Override
public Region get(Location location) {
return get(Tile.of(location));
}
@Override
public Optional<Region> get(String name) {
return Optional.ofNullable(REGIONS_BY_NAME.get(name));
}
@Override
public Stream<Region> getRegions() {
return REGIONS.values().stream();
}
@Override
public boolean isModular() {
return true;
}
}

Datei anzeigen

@ -0,0 +1,101 @@
/*
* 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.region;
import org.bukkit.Location;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class Tile {
private static final int MAX_X = 1024;
private static final int MAX_Z = 1024;
public static Tile of(Location location) {
int x = location.getBlockX() + 9;
int z = location.getBlockZ() + 9;
if (x < 0) x -= 19;
if (z < 0) z -= 19;
x /= 19;
z /= 19;
if (x < -MAX_X || x >= MAX_X || z < -MAX_Z || z >= MAX_Z) {
return null;
}
return new Tile(x, z);
}
private int tileX;
private int tileZ;
private Tile(int tileX, int tileZ) {
this.tileX = tileX;
this.tileZ = tileZ;
}
public Tile offset(int tileDx, int tileDz) {
int tileX = this.tileX + tileDx;
int tileZ = this.tileZ + tileDz;
if (tileX < -MAX_X || tileX >= MAX_X || tileZ < -MAX_Z || tileZ >= MAX_Z) {
return null;
}
return new Tile(tileX, tileZ);
}
public Set<Tile> surrounding() {
Set<Tile> tiles = new HashSet<>();
for (int dx = -1; dx <= 1; dx++) {
for (int dz = -1; dz <= 1; dz++) {
if (dx == 0 && dz == 0) continue;
tiles.add(offset(dx, dz));
}
}
tiles.remove(null);
return tiles;
}
public Set<Tile> adjacent() {
Set<Tile> tiles = new HashSet<>();
tiles.add(offset(-1, 0));
tiles.add(offset(1, 0));
tiles.add(offset(0, -1));
tiles.add(offset(0, 1));
tiles.remove(null);
return tiles;
}
@Override
public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof Tile tile)) return false;
return tileX == tile.tileX && tileZ == tile.tileZ;
}
@Override
public int hashCode() {
return Objects.hash(tileX, tileZ);
}
@Override
public String toString() {
return tileX + "/" + tileZ;
}
}

Datei anzeigen

@ -0,0 +1,45 @@
/*
* 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.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.regionnew.Region;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class TileActionBar implements Listener {
public TileActionBar() {
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Tile tile = Tile.of(event.getTo());
Region region = Region.get(event.getTo());
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§e" + tile + " §8- §e" + region.getClass().getSimpleName()));
}
}

Datei anzeigen

@ -16,7 +16,6 @@
* 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/>.
*/
plugins {
// Adding the base plugin fixes the following gradle warnings in IntelliJ:
//