forked from SteamWar/SteamWar
Compare commits
62
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1a75402ac | ||
|
|
459a465e34 | ||
|
|
7de562bf84 | ||
|
|
c9bfa9896b | ||
|
|
6209b86149 | ||
|
|
6f1403df9c | ||
|
|
0113788da2 | ||
|
|
8a7f65e000 | ||
|
|
8401f67b24 | ||
|
|
362468e756 | ||
|
|
ece12df0bc | ||
|
|
f35c07ab5b | ||
|
|
549f7e555c | ||
|
|
859238d7fa | ||
|
|
a79b00f78f | ||
|
|
105eda32e6 | ||
|
|
b4487b8079 | ||
|
|
ea3aad3bd2 | ||
|
|
d307f890e2 | ||
|
|
97c1da1b2a | ||
|
|
8a53aecfac | ||
|
|
5236afba17 | ||
|
|
d3c8b6e1c6 | ||
|
|
00ea792eee | ||
|
|
38e845b0e4 | ||
|
|
c60a8caed8 | ||
|
|
2e390286b2 | ||
|
|
6476125a3f | ||
|
|
311437d451 | ||
|
|
5a52771ec1 | ||
|
|
72b70a62e1 | ||
|
|
8575dcac33 | ||
|
|
cb744f6aa0 | ||
|
|
227f63c9ff | ||
|
|
397b10c319 | ||
|
|
32569f19d9 | ||
|
|
f19e4158e7 | ||
|
|
6c46b5b2a2 | ||
|
|
58516448d9 | ||
|
|
683236bb59 | ||
|
|
8dc101639d | ||
|
|
792620804a | ||
|
|
4aa7c99a6e | ||
|
|
cce18124f2 | ||
|
|
18ad0ad90c | ||
|
|
a58de898bb | ||
|
|
507b7c2569 | ||
|
|
a18098b8f4 | ||
|
|
97773f292d | ||
|
|
5fdfc03587 | ||
|
|
493e66cc98 | ||
|
|
2be3a136ae | ||
|
|
c62a566447 | ||
|
|
0684765a76 | ||
|
|
c40f29c3c1 | ||
|
|
72dc4eee9e | ||
|
|
c7a949322e | ||
|
|
9d5b7893f1 | ||
|
|
ae898e14c2 | ||
|
|
726f73cc45 | ||
|
|
64e627514d | ||
|
|
3a247de43d
|
@@ -32,6 +32,7 @@ import de.steamwar.bausystem.features.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.features.tracer.TraceRecorder;
|
||||
import de.steamwar.bausystem.features.world.BauScoreboard;
|
||||
import de.steamwar.bausystem.linkage.BauGuiItem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionSystem;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.bausystem.utils.TickManager;
|
||||
@@ -40,8 +41,9 @@ import de.steamwar.command.AbstractValidator;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.core.CRIUSleepEvent;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.core.WorldIdentifier;
|
||||
import de.steamwar.core.worldedit.SteamEdit;
|
||||
import de.steamwar.core.worldedit.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.linkage.AbstractLinker;
|
||||
import de.steamwar.linkage.SpigotLinker;
|
||||
import de.steamwar.message.Message;
|
||||
@@ -49,6 +51,7 @@ import de.steamwar.providers.BauServerInfo;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -129,7 +132,19 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
TraceManager.instance.init();
|
||||
TraceRecorder.instance.init();
|
||||
|
||||
new WorldEditRendererCUIEditor();
|
||||
SteamEdit.init();
|
||||
SteamEdit.ADJACENT_FILTERS = location -> {
|
||||
Region region = Region.getRegion(location);
|
||||
Region.Area area;
|
||||
if (region.getBuildArea().inRegion(location, true)) {
|
||||
area = region.getBuildArea();
|
||||
} else if (region.getTestblockArea().inRegion(location, true)) {
|
||||
area = region.getTestblockArea();
|
||||
} else {
|
||||
return SteamEdit.AdjacentFilter.ALWAYS;
|
||||
}
|
||||
return (x, y, z) -> area.inRegion(new Location(null, x, y, z), true);
|
||||
};
|
||||
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.SEND_COMMAND_FEEDBACK, false);
|
||||
|
||||
|
||||
+1
-1
@@ -290,7 +290,7 @@ public class KillcheckerVisualizer {
|
||||
}
|
||||
rEntities.get(point).die();
|
||||
}
|
||||
RBlockDisplay entity = new RBlockDisplay(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5));
|
||||
RBlockDisplay entity = new RBlockDisplay(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0, 0, 0));
|
||||
entity.setBlock(MATERIALS[Math.min(count - 1, MATERIALS.length) - 1].createBlockData());
|
||||
rEntities.put(point, entity);
|
||||
if (outlinePoints.contains(point)) outlinePointsCache.add(point);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class ObserverTracerListener implements Listener {
|
||||
public ObserverTracerListener() {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
SWPlayer.allWithSingleComponent(ObserverTracer.class).forEach(pair -> {
|
||||
if (pair.getPlayer().getGameMode() != GameMode.SPECTATOR) return;
|
||||
if (pair.getSwPlayer().getPlayer().getGameMode() != GameMode.SPECTATOR) return;
|
||||
pair.getComponent().show();
|
||||
});
|
||||
}, 15L, 15L);
|
||||
|
||||
+66
-74
@@ -19,12 +19,10 @@
|
||||
|
||||
package de.steamwar.bausystem.features.smartplace;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -34,104 +32,98 @@ import org.bukkit.block.data.*;
|
||||
import org.bukkit.block.data.type.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
public class SmartPlaceListener implements Listener {
|
||||
|
||||
private static final Set<Material> CONTAINERS = new HashSet<>();
|
||||
private static final Set<Material> IGNORED = new HashSet<>();
|
||||
private static final Set<Material> IGNORED = Set.of(Material.TNT, Material.REDSTONE_ORE, Material.BEEHIVE, Material.SEA_PICKLE);
|
||||
|
||||
static {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
Block block = world.getBlockAt(0, 0, 0);
|
||||
block.setType(Material.AIR);
|
||||
BlockState state = block.getState();
|
||||
for (Material material : Material.values()) {
|
||||
if (material.isLegacy()) continue;
|
||||
if (!material.isInteractable() && !material.isBlock()) continue;
|
||||
BlockData blockData = material.createBlockData();
|
||||
block.setBlockData(blockData);
|
||||
if (block.getState() instanceof TileState) {
|
||||
CONTAINERS.add(material);
|
||||
} else if (blockData instanceof Stairs) {
|
||||
CONTAINERS.add(material);
|
||||
}
|
||||
state.update(true, false);
|
||||
}
|
||||
CONTAINERS.add(Material.GRINDSTONE);
|
||||
CONTAINERS.remove(Material.COMPARATOR);
|
||||
state.update(true, false);
|
||||
private static final Set<UUID> FAKED_SNEAK = new HashSet<>();
|
||||
|
||||
IGNORED.add(Material.TNT);
|
||||
IGNORED.add(Material.REDSTONE_ORE);
|
||||
IGNORED.add(Material.BEEHIVE);
|
||||
IGNORED.add(Material.SEA_PICKLE);
|
||||
IGNORED.remove(Material.STONE);
|
||||
IGNORED.remove(Material.BARRIER);
|
||||
private static boolean isContainer(Block block) {
|
||||
if (block.getType() == Material.COMPARATOR) return false;
|
||||
if (block.getType() == Material.GRINDSTONE) return true;
|
||||
return block.getState() instanceof TileState || block.getBlockData() instanceof Stairs;
|
||||
}
|
||||
|
||||
private static final Set<Player> SMART_PLACING = new HashSet<>();
|
||||
private static final Set<Player> WAS_EXECUTED = new HashSet<>();
|
||||
private static boolean isReallySneaking(Player player) {
|
||||
return player.isSneaking() && !FAKED_SNEAK.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
public SmartPlaceListener() {
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (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;
|
||||
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())) {
|
||||
if (itemStack.getType() == Material.TNT) {
|
||||
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
|
||||
shouldSneak = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
shouldSneak = false;
|
||||
}
|
||||
if (IGNORED.contains(block.getType())) {
|
||||
shouldSneak = false;
|
||||
}
|
||||
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && itemStack.getType().isSolid()) {
|
||||
shouldSneak = true;
|
||||
private static boolean shouldSmartPlace(Block block, BlockFace blockFace, Material heldType) {
|
||||
boolean smartPlace = false;
|
||||
if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) {
|
||||
smartPlace = true;
|
||||
}
|
||||
if (isContainer(block)) {
|
||||
if (heldType == Material.TNT) {
|
||||
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
|
||||
smartPlace = false;
|
||||
}
|
||||
}
|
||||
boolean sneaking = player.isSneaking();
|
||||
if (sneaking) SMART_PLACING.add(player);
|
||||
player.setSneaking(shouldSneak || sneaking);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
SMART_PLACING.remove(player);
|
||||
player.setSneaking(sneaking);
|
||||
}, 0);
|
||||
return packet;
|
||||
} else {
|
||||
smartPlace = false;
|
||||
}
|
||||
if (IGNORED.contains(block.getType())) {
|
||||
smartPlace = false;
|
||||
}
|
||||
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && heldType.isSolid()) {
|
||||
smartPlace = true;
|
||||
}
|
||||
return smartPlace;
|
||||
}
|
||||
|
||||
private static boolean smartPlaceEnabled(Player player) {
|
||||
return Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onSmartPlace(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) return;
|
||||
if (!Permission.BUILD.hasPermission(player)) return;
|
||||
if (!smartPlaceEnabled(player)) return;
|
||||
if (player.isSneaking()) return;
|
||||
|
||||
ItemStack itemStack = event.getItem();
|
||||
if (itemStack == null || itemStack.getType().isAir()) return;
|
||||
if (!shouldSmartPlace(event.getClickedBlock(), event.getBlockFace(), itemStack.getType())) return;
|
||||
|
||||
player.setSneaking(true);
|
||||
FAKED_SNEAK.add(player.getUniqueId());
|
||||
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
||||
if (FAKED_SNEAK.remove(player.getUniqueId())) {
|
||||
player.setSneaking(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
FAKED_SNEAK.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
||||
WAS_EXECUTED.add(event.getPlayer());
|
||||
if (!smartPlaceEnabled(event.getPlayer())) return;
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
|
||||
if (!event.getPlayer().isSneaking()) return;
|
||||
if (!isReallySneaking(event.getPlayer())) return;
|
||||
if (event.getClickedBlock().getType() != Material.REPEATER) return;
|
||||
if ((event.getItem() == null || event.getItem().getType() == Material.REPEATER)) {
|
||||
Repeater repeater = (Repeater) event.getClickedBlock().getBlockData();
|
||||
@@ -146,9 +138,9 @@ public class SmartPlaceListener implements Listener {
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
||||
if (!SMART_PLACING.contains(event.getPlayer())) {
|
||||
if (CONTAINERS.contains(event.getBlockAgainst().getType())) {
|
||||
if (!smartPlaceEnabled(event.getPlayer())) return;
|
||||
if (!isReallySneaking(event.getPlayer())) {
|
||||
if (isContainer(event.getBlockAgainst())) {
|
||||
SoundGroup soundGroup = event.getBlockPlaced().getBlockData().getSoundGroup();
|
||||
event.getPlayer().playSound(event.getBlockPlaced().getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
||||
}
|
||||
|
||||
@@ -165,6 +165,7 @@ public class TPSSystem implements Listener {
|
||||
}
|
||||
|
||||
@Register(value = "default", description = "TPSLIMIT_DEFAULT_HELP")
|
||||
@Register(value = "rate")
|
||||
public void reset(@Validator Player player) {
|
||||
TickManager.impl.setTickRate(20.0F);
|
||||
sendTickRateChange();
|
||||
@@ -187,15 +188,18 @@ public class TPSSystem implements Listener {
|
||||
}
|
||||
|
||||
@Register(value = {"rate", "0"}, description = "TICK_FREEZE_HELP")
|
||||
@Register(value = "freeze", description = "TICK_FREEZE_HELP_2")
|
||||
public void freeze(@Validator Player player) {
|
||||
public void rate(@Validator Player player) {
|
||||
TickManager.impl.setFreeze(true);
|
||||
sendTickRateChange();
|
||||
}
|
||||
|
||||
@Register(value = "unfreeze", description = "TICK_UNFREEZE_HELP")
|
||||
public void unfreeze(@Validator Player player) {
|
||||
TickManager.impl.setTickRate(20.0F);
|
||||
@Register(value = "freeze", description = "TICK_FREEZE_HELP_2")
|
||||
public void freezeToggle(@Validator Player player) {
|
||||
if (TickManager.impl.isFrozen()) {
|
||||
TickManager.impl.setTickRate(20.0F);
|
||||
} else {
|
||||
TickManager.impl.setFreeze(true);
|
||||
}
|
||||
sendTickRateChange();
|
||||
}
|
||||
}
|
||||
|
||||
+31
-89
@@ -22,122 +22,71 @@ package de.steamwar.bausystem.features.util;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.world.entity.player.Abilities;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import org.bukkit.Bukkit;
|
||||
import io.papermc.paper.event.player.PlayerFailMoveEvent;
|
||||
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Linked
|
||||
public class NoClipCommand extends SWCommand implements Listener {
|
||||
|
||||
public static class NoClipData implements SWPlayer.Component {
|
||||
private long lastTick = -1;
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
public void onUnmount(SWPlayer swPlayer) {
|
||||
Player player = swPlayer.getPlayer();
|
||||
showClientGameMode(player, GameMode.CREATIVE, GameMode.CREATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
public NoClipCommand() {
|
||||
super("noclip", "nc");
|
||||
|
||||
BiFunction<Player, ServerboundMovePlayerPacket, Object> first = (player, o) -> {
|
||||
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
||||
if (noClipData == null) return o;
|
||||
if (noClipData.lastTick == TPSUtils.currentTick.get()) return o;
|
||||
setInternalGameMode(player, GameMode.SPECTATOR);
|
||||
noClipData.lastTick = TPSUtils.currentTick.get();
|
||||
return o;
|
||||
};
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, first);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, first);
|
||||
|
||||
BiFunction<Player, Object, Object> second = (player, o) -> {
|
||||
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
||||
if (noClipData == null) return o;
|
||||
setInternalGameMode(player, GameMode.CREATIVE);
|
||||
noClipData.lastTick = TPSUtils.currentTick.get();
|
||||
return o;
|
||||
};
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, second);
|
||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, second);
|
||||
TinyProtocol.instance.addFilter(ServerboundContainerClickPacket.class, second);
|
||||
|
||||
BiFunction<Player, ServerboundSetCreativeModeSlotPacket, Object> third = (player, o) -> {
|
||||
if (SWPlayer.of(player).hasComponent(NoClipData.class)) {
|
||||
int index = o.slotNum();
|
||||
if (index >= 36 && index <= 44) {
|
||||
index -= 36;
|
||||
} else if (index > 44) {
|
||||
index -= 5;
|
||||
} else if (index <= 8) {
|
||||
index = index - 8 + 36;
|
||||
}
|
||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(o.itemStack()));
|
||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
||||
player.updateInventory();
|
||||
}
|
||||
return o;
|
||||
};
|
||||
TinyProtocol.instance.addFilter(ServerboundSetCreativeModeSlotPacket.class, third);
|
||||
}
|
||||
|
||||
private void setInternalGameMode(Player player, GameMode gameMode) {
|
||||
((CraftPlayer) player).getHandle().gameMode.gameModeForPlayer = GameType.byId(gameMode.getValue());
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
@Register
|
||||
public void genericCommand(@Validator Player player) {
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
if (swPlayer.hasComponent(NoClipData.class)) {
|
||||
swPlayer.removeComponent(NoClipData.class);
|
||||
} else {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
Abilities abilities = (((CraftPlayer) player).getHandle()).getAbilities();
|
||||
abilities.mayBuild = true;
|
||||
abilities.mayfly = true;
|
||||
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
swPlayer.setComponent(new NoClipData());
|
||||
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
||||
TinyProtocol.instance.sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, 1F));
|
||||
pseudoGameMode(player, GameMode.SPECTATOR);
|
||||
showClientGameMode(player, GameMode.CREATIVE, GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(player -> {
|
||||
SWPlayer.of(player).removeComponent(NoClipData.class);
|
||||
});
|
||||
public void onPlayerFailMove(PlayerFailMoveEvent event) {
|
||||
if (event.getFailReason() != PlayerFailMoveEvent.FailReason.CLIPPED_INTO_BLOCK) return;
|
||||
if (!SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) return;
|
||||
event.setAllowed(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(player -> SWPlayer.of(player).removeComponent(NoClipData.class));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onBlock(BlockCanBuildEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||
@@ -145,7 +94,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||
event.setCancelled(true);
|
||||
@@ -153,20 +102,13 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
|
||||
return;
|
||||
}
|
||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
event.getPlayer().setSpectatorTarget(null);
|
||||
}, 1L);
|
||||
}
|
||||
/**
|
||||
* @param player player
|
||||
* @param localMode GameMode for breaking and placing
|
||||
* @param listedMode GameMode for noPhysics
|
||||
*/
|
||||
private static void showClientGameMode(Player player, GameMode localMode, GameMode listedMode) {
|
||||
TinyProtocol.instance.sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, localMode.getValue()));
|
||||
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), listedMode));
|
||||
}
|
||||
|
||||
private static void pseudoGameMode(Player player, GameMode gameMode) {
|
||||
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), gameMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.world;
|
||||
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
@Linked
|
||||
public class AntiPlayerCollision implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Scoreboard board = event.getPlayer().getScoreboard();
|
||||
Team team = board.getTeam("players");
|
||||
if (team == null) team = board.registerNewTeam("players");
|
||||
team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
team.addPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
plugins {
|
||||
steamwar.kotlin
|
||||
kotlin("plugin.lombok")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
@@ -40,4 +41,8 @@ dependencies {
|
||||
compileOnlyApi(libs.exposedDao)
|
||||
compileOnlyApi(libs.exposedJdbc)
|
||||
compileOnlyApi(libs.exposedTime)
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -688,13 +688,6 @@ public final class GameModeConfig<M, W> {
|
||||
*/
|
||||
public final int MaxBlocks;
|
||||
|
||||
/**
|
||||
* Maximal amount of items per dispenser
|
||||
*
|
||||
* @implSpec {@code 128} by default
|
||||
*/
|
||||
public final int MaxDispenserItems;
|
||||
|
||||
/**
|
||||
* Maximal blast resistance for the blocks
|
||||
*
|
||||
@@ -710,10 +703,12 @@ public final class GameModeConfig<M, W> {
|
||||
public final double MaxDesignBlastResistance;
|
||||
|
||||
/**
|
||||
* List of limited material (combinations)<br/>
|
||||
* List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format)
|
||||
* List of limited block materials
|
||||
*
|
||||
* @implSpec {@link SQLWrapper#getInventoryMaterials)} are all disallowed by default to have any content but are unlimited in number.
|
||||
* @implSpec Any Block that has more Blast Resistance than {@link #MaxBlastResistance} will be defaulted to 0.
|
||||
*/
|
||||
public final Map<Set<M>, Integer> Limited;
|
||||
public final List<BlockRule<M>> Limited;
|
||||
|
||||
private SchematicConfig(YMLWrapper<M, ?> loader) {
|
||||
loaded = loader.canLoad();
|
||||
@@ -731,32 +726,140 @@ public final class GameModeConfig<M, W> {
|
||||
IgnorePublicOnly = loader.getBoolean("IgnorePublicOnly", false);
|
||||
UnlimitedPrepare = loader.getBoolean("UnlimitedPrepare", false);
|
||||
MaxBlocks = loader.getInt("MaxBlocks", 0);
|
||||
MaxDispenserItems = loader.getInt("MaxDispenserItems", 128);
|
||||
MaxBlastResistance = loader.getDouble("MaxBlastResistance", Double.MAX_VALUE);
|
||||
MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", MaxBlastResistance);
|
||||
|
||||
Map<Set<M>, Integer> Limited = new HashMap<>();
|
||||
for (Map<?, ?> entry : loader.getMapList("Limited")) {
|
||||
int amount = (Integer) entry.get("Amount");
|
||||
Set<String> materials = new HashSet<>((List<String>) entry.get("Materials"));
|
||||
if (amount == 0) {
|
||||
materials.forEach(material -> {
|
||||
Limited.put(Collections.singleton(loader.materialMapper.apply(material.toUpperCase())), 0);
|
||||
});
|
||||
} else {
|
||||
Limited.put(Collections.unmodifiableSet(materials.stream().map(String::toUpperCase).map(loader.materialMapper).collect(Collectors.toSet())), amount);
|
||||
}
|
||||
List<BlockRule<M>> limited = new ArrayList<>();
|
||||
Set<M> blocks = new HashSet<>();
|
||||
for (YMLWrapper<M, ?> limitedLoader : loader.withAsList("Limited")) {
|
||||
BlockRule<M> blockRule = new BlockRule<>(limitedLoader);
|
||||
blocks.addAll(blockRule.Materials);
|
||||
limited.add(blockRule);
|
||||
}
|
||||
SQLWrapper.impl.getMaterialWithGreaterBlastResistance(MaxBlastResistance).forEach(material -> {
|
||||
if (Limited.entrySet().stream().anyMatch(entry -> entry.getKey().contains(material))) return;
|
||||
Limited.put(Collections.singleton((M) material), 0);
|
||||
});
|
||||
this.Limited = Collections.unmodifiableMap(Limited);
|
||||
for (M material : (List<M>) SQLWrapper.impl.getMaterialWithGreaterBlastResistance(MaxBlastResistance)) {
|
||||
if (material == null || !blocks.add(material)) continue;
|
||||
limited.add(new BlockRule<>(material, 0));
|
||||
}
|
||||
for (M material : (Set<M>) SQLWrapper.impl.getInventoryMaterials()) {
|
||||
if (material == null || !blocks.add(material)) continue;
|
||||
limited.add(new BlockRule<>(material, Integer.MAX_VALUE));
|
||||
}
|
||||
this.Limited = Collections.unmodifiableList(limited);
|
||||
|
||||
this.ReplacementsWithoutBlockUpdates = loader.getMap("ReplacementsWithoutBlockUpdates", loader.materialMapper, loader.materialMapper);
|
||||
this.ReplacementsWithBlockUpdates = loader.getMap("ReplacementsWithBlockUpdates", loader.materialMapper, loader.materialMapper);
|
||||
}
|
||||
|
||||
public int getMaxCount(M material) {
|
||||
return Limited.stream()
|
||||
.filter(rule -> rule.Materials.contains(material))
|
||||
.mapToInt(rule -> rule.Amount)
|
||||
.max()
|
||||
.orElse(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public boolean isInventory(M material) {
|
||||
return Limited.stream()
|
||||
.filter(rule -> rule.Materials.contains(material))
|
||||
.anyMatch(rule -> rule.Content.loaded);
|
||||
}
|
||||
|
||||
public Integer getItemAmount(M material, M item) {
|
||||
return Limited.stream()
|
||||
.filter(rule -> rule.Materials.contains(material))
|
||||
.filter(rule -> rule.Content.Items.contains(item))
|
||||
.mapToInt(rule -> rule.Content.Amount)
|
||||
.max()
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class BlockRule<M> {
|
||||
|
||||
/**
|
||||
* The block materials this rule applies to
|
||||
*/
|
||||
public final Set<M> Materials;
|
||||
|
||||
/**
|
||||
* Maximal amount of Blocks allowed in the schematic
|
||||
*
|
||||
* @implSpec {@code 0} by default
|
||||
*/
|
||||
public final int Amount;
|
||||
|
||||
/**
|
||||
* The item content filter for Blocks
|
||||
*
|
||||
* @implSpec no Items with {@code Amount 0} (denies any item) by default
|
||||
*/
|
||||
public final Content<M> Content;
|
||||
|
||||
/**
|
||||
* Resolves one {@code Materials} entry to the concrete materials it denotes: {@code storage}
|
||||
* for {@link SQLWrapper#getStorageMaterials()}, {@code inventory} for
|
||||
* {@link SQLWrapper#getInventoryMaterials()}, or the material itself otherwise.
|
||||
*/
|
||||
private Set<M> expandInventoryGroup(YMLWrapper<M, ?> loader, String name) {
|
||||
switch (name.toUpperCase()) {
|
||||
case "STORAGE":
|
||||
return (Set<M>) SQLWrapper.impl.getStorageMaterials();
|
||||
case "INVENTORY":
|
||||
return (Set<M>) SQLWrapper.impl.getInventoryMaterials();
|
||||
default:
|
||||
M material = loader.materialMapper.apply(name.toUpperCase());
|
||||
return material != null ? Collections.singleton(material) : Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
private BlockRule(YMLWrapper<M, ?> loader) {
|
||||
Set<M> blocks = loader.getStringList("Materials")
|
||||
.stream()
|
||||
.flatMap(value -> expandInventoryGroup(loader, value).stream())
|
||||
.collect(Collectors.toSet());
|
||||
Materials = Collections.unmodifiableSet(blocks);
|
||||
Amount = loader.getInt("Amount", 0);
|
||||
Content = new Content<>(loader.with("Content"));
|
||||
}
|
||||
|
||||
private BlockRule(M block, int amount) {
|
||||
Materials = Collections.singleton(block);
|
||||
Amount = amount;
|
||||
Content = new Content<>();
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class Content<M> {
|
||||
|
||||
public final boolean loaded;
|
||||
|
||||
/**
|
||||
* Items allowed by this rule
|
||||
*/
|
||||
public final Set<M> Items;
|
||||
|
||||
/**
|
||||
* Maximal amount of an allowed item per single block instance
|
||||
*
|
||||
* @implSpec {@code 0} by default
|
||||
*/
|
||||
public final int Amount;
|
||||
|
||||
private Content(YMLWrapper<M, ?> loader) {
|
||||
loaded = loader.canLoad();
|
||||
List<M> items = loader.getMaterialList("Items");
|
||||
Items = Collections.unmodifiableSet(new HashSet<>(items));
|
||||
Amount = loader.getInt("Amount", 0);
|
||||
}
|
||||
|
||||
private Content() {
|
||||
loaded = false;
|
||||
Items = new HashSet<>();
|
||||
Amount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class SizeConfig {
|
||||
|
||||
|
||||
@@ -183,14 +183,6 @@ class Punishment(id: EntityID<Int>) : IntEntity(id) {
|
||||
"UNNOFIGHTSERVER",
|
||||
UserPerm.MODERATION
|
||||
),
|
||||
NoTeamServer(
|
||||
"NOTEAMSERVER_TEAM",
|
||||
"NOTEAMSERVER_PERMA",
|
||||
"NOTEAMSERVER_UNTIL",
|
||||
"UNNOTEAMSERVER_ERROR",
|
||||
"UNNOTEAMSERVER",
|
||||
UserPerm.MODERATION
|
||||
),
|
||||
Note("NOTE_TEAM", null, null, null, null, UserPerm.PUNISHMENTS, true);
|
||||
|
||||
fun isMulti() =
|
||||
|
||||
@@ -24,6 +24,7 @@ import de.steamwar.ImplementationProvider;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface SQLWrapper<M> {
|
||||
SQLWrapper<?> impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl");
|
||||
@@ -36,5 +37,21 @@ public interface SQLWrapper<M> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage-type inventory materials (chests, barrels, shulker boxes of any color) - the
|
||||
* {@code storage} group usable in {@code GameModeConfig}'s {@code Limited}.
|
||||
*/
|
||||
default Set<M> getStorageMaterials() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every inventory material - the {@code all} group usable in {@code GameModeConfig}'s
|
||||
* {@code Limited}. Expected to be a superset of {@link #getStorageMaterials()}.
|
||||
*/
|
||||
default Set<M> getInventoryMaterials() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
void additionalExceptionMetadata(StringBuilder builder);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,25 @@ final class YMLWrapper<M, W> {
|
||||
return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, winconditionMapper);
|
||||
}
|
||||
|
||||
public List<YMLWrapper<M, W>> withAsList(String path) {
|
||||
if (document.containsKey(path)) {
|
||||
Object value = document.get(path);
|
||||
if (value instanceof List) {
|
||||
List<?> list = (List<?>) value;
|
||||
List<Map> maps = list.stream()
|
||||
.filter(Map.class::isInstance)
|
||||
.map(Map.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
if (maps.size() == list.size()) {
|
||||
return (List) maps.stream()
|
||||
.map(map -> new YMLWrapper(true, map, materialMapper, winconditionMapper))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public <T> T get(String path, T defaultValue, Function<Object, T> mapper) {
|
||||
Object value = this.document.get(path);
|
||||
if (value == null) return defaultValue;
|
||||
|
||||
@@ -107,15 +107,23 @@ Schematic:
|
||||
UnlimitedPrepare: false # defaults to false if missing
|
||||
# Maximal amount of blocks allowed in the schematic
|
||||
MaxBlocks: 0 # defaults to 0 (ignored) if missing
|
||||
# Maximal amount of items per dispenser
|
||||
MaxDispenserItems: 128 # defaults to 128 if missing
|
||||
# Maximal blast resistance for the design blocks
|
||||
MaxDesignBlastResistance: 100000000 # defaults to Double.MAX_VALUE if missing
|
||||
# List of limited material (combinations)
|
||||
# List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format)
|
||||
# List of limited block materials
|
||||
# InventoryMaterials are all disallowed by default to have any content but are unlimited in number
|
||||
# Any Block that has more Blast Resistance than MaxBlastResistance will be defaulted to 0.
|
||||
Limited:
|
||||
- Materials: [ ]
|
||||
Amount: 0
|
||||
- Blocks: [ DISPENSER ]
|
||||
MaxCount: 64
|
||||
- Blocks: [ DISPENSER ]
|
||||
MaxCount: 16
|
||||
Content:
|
||||
Items: [ ARROW, FIRE_CHARGE ]
|
||||
Amount: 128
|
||||
- Blocks: [ storage ]
|
||||
Content:
|
||||
Items: [ TNT ]
|
||||
Amount: 1728
|
||||
|
||||
# The name of the game mode presented to the players
|
||||
GameName: WarGear # defaults to WarGear if missing
|
||||
|
||||
@@ -39,6 +39,7 @@ public enum ArenaMode {
|
||||
public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK));
|
||||
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
|
||||
public static final Set<ArenaMode> Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST));
|
||||
public static final Set<ArenaMode> TestOrReferee = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, EVENT));
|
||||
|
||||
public static final Set<ArenaMode> AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY)));
|
||||
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));
|
||||
|
||||
@@ -21,8 +21,8 @@ package de.steamwar.fightsystem;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.fightsystem.commands.TechareaCommand;
|
||||
import de.steamwar.core.worldedit.SteamEdit;
|
||||
import de.steamwar.core.worldedit.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.ClickAnalyzer;
|
||||
@@ -108,7 +108,7 @@ public class FightSystem extends JavaPlugin {
|
||||
}
|
||||
});
|
||||
new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f));
|
||||
new OneShotStateDependent(ArenaMode.Test, FightState.All, WorldEditRendererCUIEditor::new);
|
||||
new OneShotStateDependent(ArenaMode.Test, FightState.All, SteamEdit::init);
|
||||
Config.world.setGameRule(GameRule.REDUCED_DEBUG_INFO, ArenaMode.AntiTest.contains(Config.mode));
|
||||
|
||||
hullHider = new HullHider();
|
||||
@@ -127,8 +127,6 @@ public class FightSystem extends JavaPlugin {
|
||||
if (checkSchematicNode.isPrepared()) {
|
||||
Fight.getRedTeam().setSchem(checkSchematicNode, NodeData.getRevisions(checkSchematicNode) - 1);
|
||||
}
|
||||
|
||||
new TechareaCommand();
|
||||
} else if (Config.mode == ArenaMode.PREPARE) {
|
||||
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
|
||||
}
|
||||
|
||||
@@ -24,35 +24,25 @@ import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Kit;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class AkCommand implements CommandExecutor {
|
||||
public class AkCommand extends FightSWCommand {
|
||||
|
||||
public AkCommand() {
|
||||
new StateDependentCommand(ArenaMode.Test, FightState.All, "ak", this);
|
||||
super(ArenaMode.Test, FightState.All, "ak");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (!player.isOp()) return false;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return player.isOp() && user.hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin();
|
||||
}
|
||||
|
||||
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Kit.createKit(args[0], player);
|
||||
return false;
|
||||
@Register
|
||||
public void run(@Validator Player player, String name) {
|
||||
Kit.createKit(name, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.fightsystem.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class FightSWCommand extends SWCommand implements Listener {
|
||||
|
||||
private final String command;
|
||||
private final String[] aliases;
|
||||
|
||||
protected FightSWCommand(Set<ArenaMode> mode, Set<FightState> states, String command) {
|
||||
super(command);
|
||||
this.command = command;
|
||||
this.aliases = new String[0];
|
||||
stateDependant(mode, states);
|
||||
}
|
||||
|
||||
protected FightSWCommand(Set<ArenaMode> mode, Set<FightState> states, String command, String... aliases) {
|
||||
super(command, aliases);
|
||||
this.command = command;
|
||||
this.aliases = aliases;
|
||||
stateDependant(mode, states);
|
||||
}
|
||||
|
||||
private void stateDependant(Set<ArenaMode> mode, Set<FightState> states) {
|
||||
FightSWCommand.this.unregister();
|
||||
new StateDependent(mode, states) {
|
||||
@Override
|
||||
public void enable() {
|
||||
System.out.println("--- Enable: " + command);
|
||||
FightSWCommand.this.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
System.out.println("--- Disable: " + command);
|
||||
FightSWCommand.this.unregister();
|
||||
}
|
||||
}.register();
|
||||
}
|
||||
|
||||
public static void postFightStateChange() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.updateCommands();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public final void onPlayerCommandSend(PlayerCommandSendEvent event) {
|
||||
if (hasPerm(event.getPlayer(), SteamwarUser.get(event.getPlayer().getUniqueId()))) return;
|
||||
event.getCommands().remove(command);
|
||||
for (String alias : aliases) {
|
||||
event.getCommands().remove(alias);
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public final TypeValidator<Player> permissionCheck() {
|
||||
return (sender, value, messageSender) -> hasPerm(value, SteamwarUser.get(value.getUniqueId()));
|
||||
}
|
||||
}
|
||||
+10
-74
@@ -19,92 +19,28 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Linked
|
||||
public class GamemodeCommand extends BukkitCommand {
|
||||
|
||||
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
|
||||
"spectator");
|
||||
public class GamemodeCommand extends FightSWCommand {
|
||||
|
||||
public GamemodeCommand() {
|
||||
super("gamemode");
|
||||
List<String> aliases = new ArrayList<>();
|
||||
aliases.add("gm");
|
||||
this.setAliases(aliases);
|
||||
|
||||
Map<String, Command> knownCommands = ((CraftServer) Bukkit.getServer()).getCommandMap().getKnownCommands();
|
||||
knownCommands.remove("gamemode");
|
||||
Commands.injectCommand(this);
|
||||
super(ArenaMode.TestOrReferee, FightState.All, "gamemode", "gm");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
} else if (args.length == 0) {
|
||||
FightSystem.getMessage().sendPrefixless("GAMEMODE_HELP", sender);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
if (!(Config.test() || Config.isReferee(p))) {
|
||||
FightSystem.getMessage().sendPrefixless("GAMEMODE_NOT_ALLOWED", p, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameMode mode = createMode(args[0]);
|
||||
|
||||
if (mode == null) {
|
||||
FightSystem.getMessage().sendPrefixless("GAMEMODE_UNKNOWN", p, ChatMessageType.ACTION_BAR, args[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
p.setGameMode(mode);
|
||||
return true;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Config.test() || Config.isReferee(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private GameMode createMode(String modeArg) {
|
||||
try {
|
||||
return GameMode.getByValue(Integer.parseInt(modeArg));
|
||||
} catch (NumberFormatException ignored) {
|
||||
if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c"))) {
|
||||
return GameMode.CREATIVE;
|
||||
} else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a"))) {
|
||||
return GameMode.ADVENTURE;
|
||||
} else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp"))) {
|
||||
return GameMode.SPECTATOR;
|
||||
} else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s"))) {
|
||||
return GameMode.SURVIVAL;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@Register(description = "GAMEMODE_HELP")
|
||||
public void execute(@Validator Player player, GameMode gameMode) {
|
||||
player.setGameMode(gameMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, new ArrayList<>(GAMEMODE_NAMES.size()));
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,34 +20,31 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.Check;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class InfoCommand implements CommandExecutor {
|
||||
public class InfoCommand extends FightSWCommand {
|
||||
|
||||
public InfoCommand() {
|
||||
new StateDependentCommand(ArenaMode.All, FightState.All, "fightinfo", this);
|
||||
super(ArenaMode.All, FightState.All, "fightinfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK)) return false;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Check.checkPermission(user, Config.GameModeConfig);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void run(@Validator Player player) {
|
||||
for (FightTeam team : Fight.teams()) {
|
||||
if (!team.isLeaderless()) {
|
||||
FightSystem.getMessage().send("INFO_LEADER", player, team.getColoredName(), team.getLeader().getEntity().getName());
|
||||
@@ -58,6 +55,5 @@ public class InfoCommand implements CommandExecutor {
|
||||
FightSystem.getMessage().send("INFO_SCHEMATIC", player, team.getColoredName(), schematic.getName(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getRank());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,32 +21,23 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class KitCommand implements CommandExecutor {
|
||||
public class KitCommand extends FightSWCommand {
|
||||
|
||||
public KitCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "kit", this);
|
||||
super(ArenaMode.AntiReplay, FightState.Setup, "kit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
GUI.kitSelection(player, "");
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
GUI.kitSelection(player, "");
|
||||
} else {
|
||||
Commands.kit(player, args[0]);
|
||||
}
|
||||
return false;
|
||||
@Register
|
||||
public void execute(Player player, String query) { // TODO: TabCompletion of Kit Names!
|
||||
GUI.kitSelection(player, query);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-14
@@ -21,28 +21,18 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class LeaveCommand implements CommandExecutor {
|
||||
public class LeaveCommand extends FightSWCommand {
|
||||
|
||||
public LeaveCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "leave", this);
|
||||
super(ArenaMode.AntiReplay, FightState.Setup, "leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
Commands.leaveTeam(player);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-20
@@ -20,52 +20,42 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.Check;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class LockschemCommand implements CommandExecutor {
|
||||
public class LockschemCommand extends FightSWCommand {
|
||||
|
||||
public LockschemCommand() {
|
||||
new StateDependentCommand(ArenaMode.All, FightState.Schem, "lockschem", this);
|
||||
super(ArenaMode.All, FightState.Schem, "lockschem");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Check.checkPermission(user, Config.GameModeConfig);
|
||||
}
|
||||
|
||||
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK)) return false;
|
||||
|
||||
if (args.length != 1) {
|
||||
FightSystem.getMessage().sendPrefixless("LOCKSCHEM_HELP", player);
|
||||
return false;
|
||||
}
|
||||
|
||||
String teamName = args[0];
|
||||
@Register(description = "LOCKSCHEM_HELP")
|
||||
public void execute(@Validator Player player, String teamName) {
|
||||
FightTeam fightTeam = Fight.getTeamByName(teamName);
|
||||
|
||||
if (fightTeam == null) {
|
||||
FightSystem.getMessage().sendPrefixless("UNKNOWN_TEAM", player, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
SchematicNode.getSchematicNode(fightTeam.getSchematic()).setSchemtype(SchematicType.Normal);
|
||||
FightSystem.getMessage().sendPrefixless("LOCKSCHEM_LOCKED", player, ChatMessageType.ACTION_BAR);
|
||||
fightTeam.broadcastSystem("LOCKSCHEM_LOCKED_BY", player.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-14
@@ -21,28 +21,18 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class ReadyCommand implements CommandExecutor {
|
||||
public class ReadyCommand extends FightSWCommand {
|
||||
|
||||
public ReadyCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready", this);
|
||||
super(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
Commands.toggleReady(player);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-21
@@ -20,35 +20,19 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class RemoveCommand implements CommandExecutor {
|
||||
public class RemoveCommand extends FightSWCommand {
|
||||
|
||||
public RemoveCommand() {
|
||||
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this);
|
||||
super(ArenaMode.VariableTeams, FightState.Setup, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (args.length != 1) {
|
||||
FightSystem.getMessage().sendPrefixless("REMOVE_HELP", player);
|
||||
return false;
|
||||
}
|
||||
|
||||
Commands.kick(player, args[0]);
|
||||
return false;
|
||||
@Register(description = "REMOVE_HELP")
|
||||
public void execute(Player player, Player teamMember) {
|
||||
Commands.kick(player, teamMember.getName());
|
||||
}
|
||||
}
|
||||
|
||||
+6
-15
@@ -26,37 +26,28 @@ import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.fight.JoinRequest;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@Linked
|
||||
public class RequestsCommand implements CommandExecutor {
|
||||
public class RequestsCommand extends FightSWCommand {
|
||||
|
||||
public RequestsCommand() {
|
||||
new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", this);
|
||||
new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "requests", this);
|
||||
super(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", "requests");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
FightPlayer fp = Fight.getFightPlayer(player);
|
||||
if (fp == null || !(fp.isLeader() || fp.isLiving())) {
|
||||
GUI.joinRequest(player);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Commands.checkGetLeader(player) == null) return false;
|
||||
|
||||
if (Commands.checkGetLeader(player) == null) return;
|
||||
GUI.chooseJoinRequests(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void onJoinRequest(Player player, JoinRequest request, BiConsumer<JoinRequest, FightTeam> handleJoinRequest) {
|
||||
|
||||
@@ -24,32 +24,22 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.record.PacketProcessor;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class SkipCommand implements CommandExecutor {
|
||||
public class SkipCommand extends FightSWCommand {
|
||||
|
||||
public SkipCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip", this);
|
||||
super(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
if (PacketProcessor.isReplaying() && player.getUniqueId().equals(Fight.getBlueTeam().getDesignatedLeader())) {
|
||||
PacketProcessor.currentReplay().skipToSubtitle();
|
||||
} else {
|
||||
Commands.toggleSkip(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-14
@@ -21,27 +21,18 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class StateCommand implements CommandExecutor {
|
||||
public class StateCommand extends FightSWCommand {
|
||||
|
||||
public StateCommand() {
|
||||
new StateDependentCommand(ArenaMode.Test, FightState.All, "state", this);
|
||||
super(ArenaMode.Test, FightState.All, "state");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GUI.state((Player) sender);
|
||||
return false;
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
GUI.state(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,26 +22,18 @@ package de.steamwar.fightsystem.commands;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class TBCommand implements CommandExecutor {
|
||||
public class TBCommand extends FightSWCommand {
|
||||
|
||||
public TBCommand() {
|
||||
new StateDependentCommand(ArenaMode.Check, FightState.All, "resettb", this);
|
||||
super(ArenaMode.Check, FightState.All, "resettb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
Fight.getRedTeam().pasteSchem();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-19
@@ -20,34 +20,20 @@ package de.steamwar.fightsystem.commands;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class TPSWarpCommand implements CommandExecutor {
|
||||
public class TPSWarpCommand extends FightSWCommand {
|
||||
|
||||
public TPSWarpCommand() {
|
||||
new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", this);
|
||||
new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpslimit", this);
|
||||
super(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", "tpslimit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
float tps;
|
||||
try {
|
||||
tps = Float.parseFloat(args[0]);
|
||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||
FightSystem.getMessage().send("TPSWARP_HELP", sender);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Register(description = "TPSWARP_HELP")
|
||||
public void execute(Player player, float tps) {
|
||||
MinecraftServer.getServer().tickRateManager().setTickRate(tps);
|
||||
|
||||
FightSystem.getMessage().broadcastActionbar("TPSWARP_SET", tps);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-21
@@ -19,42 +19,39 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.entity.CWireframe;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TechareaCommand extends SWCommand {
|
||||
private final Map<UUID, REntityServer> servers = new HashMap<>();
|
||||
@Linked
|
||||
public class TechareaCommand extends FightSWCommand {
|
||||
private REntityServer entityServer = new REntityServer();
|
||||
|
||||
public TechareaCommand() {
|
||||
super("techarea");
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> servers.forEach((uuid, rEntityServer) -> rEntityServer.tick()), 2, 2);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
if (servers.containsKey(player.getUniqueId())) {
|
||||
servers.get(player.getUniqueId()).close();
|
||||
} else {
|
||||
super(ArenaMode.Check, FightState.All, "techarea");
|
||||
new OneShotStateDependent(ArenaMode.Check, FightState.All, () -> {
|
||||
if (!entityServer.getEntities().isEmpty()) return;
|
||||
REntityServer server = new REntityServer();
|
||||
CWireframe wireframe = new CWireframe(server);
|
||||
|
||||
wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world));
|
||||
wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world).subtract(1, 1, 1));
|
||||
wireframe.setBlock(Material.RED_CONCRETE.createBlockData());
|
||||
});
|
||||
}
|
||||
|
||||
server.addPlayer(player);
|
||||
servers.put(player.getUniqueId(), server);
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
if (entityServer.getPlayers().contains(player)) {
|
||||
entityServer.removePlayer(player);
|
||||
} else {
|
||||
entityServer.addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-10
@@ -25,27 +25,24 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SWException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Linked
|
||||
public class TechhiderbugCommand implements CommandExecutor {
|
||||
public class TechhiderbugCommand extends FightSWCommand {
|
||||
|
||||
public TechhiderbugCommand() {
|
||||
new StateDependentCommand(ArenaMode.All, FightState.All, "techhiderbug", this);
|
||||
super(ArenaMode.All, FightState.All, "techhiderbug");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
@Register
|
||||
public void execute(Player player, String... args) {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
@@ -76,7 +73,6 @@ public class TechhiderbugCommand implements CommandExecutor {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Error while generating bug report", e);
|
||||
}
|
||||
|
||||
SWException.log("Techhider-Bug reported by " + sender.getName() + ": " + Arrays.toString(args), writer.toString());
|
||||
return false;
|
||||
SWException.log("Techhider-Bug reported by " + player.getName() + ": " + Arrays.toString(args), writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,28 +23,20 @@ import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class WGCommand implements CommandExecutor {
|
||||
public class WGCommand extends FightSWCommand {
|
||||
|
||||
public WGCommand() {
|
||||
new StateDependentCommand(ArenaMode.Check, FightState.All, "resetwg", this);
|
||||
super(ArenaMode.Check, FightState.All, "resetwg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
FightWorld.resetWorld();
|
||||
Fight.getBlueTeam().pasteSchem();
|
||||
Fight.getRedTeam().pasteSchem();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,49 +25,34 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class WinCommand implements CommandExecutor {
|
||||
public class WinCommand extends FightSWCommand {
|
||||
|
||||
public WinCommand() {
|
||||
new StateDependentCommand(ArenaMode.Event, FightState.Ingame, "win", this);
|
||||
super(ArenaMode.Event, FightState.Ingame, "win");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Config.isReferee(player);
|
||||
}
|
||||
|
||||
if (!Config.isReferee(p)) {
|
||||
FightSystem.getMessage().sendPrefixless("NOT_FIGHTLEADER", p, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
FightSystem.getMessage().sendPrefixless("WIN_HELP", p);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("tie")) {
|
||||
@Register
|
||||
public void execute(@Validator Player player, String teamName) {
|
||||
if (teamName.equalsIgnoreCase("tie")) {
|
||||
FightSystem.setSpectateState(null, "Referee", "WIN_FIGHTLEADER");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
for (FightTeam team : Fight.teams()) {
|
||||
if (args[0].equalsIgnoreCase(team.getName())) {
|
||||
if (teamName.equalsIgnoreCase(team.getName())) {
|
||||
FightSystem.setSpectateState(team, "Referee", "WIN_FIGHTLEADER");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.GameModeConfig;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
@@ -44,14 +45,28 @@ public class Check implements Listener {
|
||||
new StateDependentListener(ArenaMode.Check, FightState.All, this);
|
||||
}
|
||||
|
||||
private boolean checkPermission(SteamwarUser user, SchematicNode schematic) {
|
||||
GameModeConfig<Object, String> gameModeConfig = GameModeConfig.getAll().stream()
|
||||
.filter(gmc -> gmc.Schematic.Type != null && gmc.Schematic.Type.checkType() != null && schematic.getSchemtype().name().equals(gmc.Schematic.Type.checkType().name()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults();
|
||||
return checkPermission(user, gameModeConfig);
|
||||
}
|
||||
|
||||
public static boolean checkPermission(SteamwarUser user, GameModeConfig gameModeConfig) {
|
||||
if (user.hasPerm(UserPerm.ADMINISTRATION)) return true;
|
||||
if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true;
|
||||
return gameModeConfig.Checkers.contains(user.getId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
if (user.hasPerm(UserPerm.CHECK)) return;
|
||||
|
||||
SchematicNode schem = SchematicNode.getSchematicNode(Config.CheckSchemID);
|
||||
if (checkPermission(user, schem)) return;
|
||||
if (user.getId() == schem.getOwner()) return;
|
||||
|
||||
FightSystem.getMessage().send("CHECK_JOIN_DENIED", player);
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.fightsystem.record;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.core.WorldEditWrapper;
|
||||
import de.steamwar.core.worldedit.WorldEditWrapper;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RPlayer;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.states;
|
||||
|
||||
import de.steamwar.fightsystem.commands.FightSWCommand;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
@@ -62,6 +63,7 @@ public enum FightState {
|
||||
}
|
||||
|
||||
public static void setFightState(FightState state) {
|
||||
if (fightState.equals(state)) return;
|
||||
fightState = state;
|
||||
|
||||
for (Map.Entry<IStateDependent, Boolean> feature : stateDependentFeatures.entrySet()) {
|
||||
@@ -77,6 +79,7 @@ public enum FightState {
|
||||
feature.setValue(false);
|
||||
}
|
||||
}
|
||||
FightSWCommand.postFightStateChange();
|
||||
}
|
||||
|
||||
public static boolean setup() {
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* 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 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.fightsystem.states;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class StateDependentCommand extends StateDependent {
|
||||
|
||||
private static final CommandExecutor unavailable = (sender, cmd, s, strings) -> {
|
||||
FightSystem.getMessage().sendPrefixless("COMMAND_CURRENTLY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
};
|
||||
|
||||
private final PluginCommand command;
|
||||
private final CommandExecutor executor;
|
||||
|
||||
public StateDependentCommand(Set<ArenaMode> mode, Set<FightState> states, String name, CommandExecutor executor) {
|
||||
super(mode, states);
|
||||
this.executor = executor;
|
||||
this.command = FightSystem.getPlugin().getCommand(name);
|
||||
assert command != null;
|
||||
disable();
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
command.setExecutor(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
command.setExecutor(unavailable);
|
||||
}
|
||||
}
|
||||
@@ -10,22 +10,4 @@ depend:
|
||||
- WorldEdit
|
||||
api-version: "1.13"
|
||||
|
||||
commands:
|
||||
ak:
|
||||
request:
|
||||
requests:
|
||||
fightinfo:
|
||||
leave:
|
||||
ready:
|
||||
kit:
|
||||
remove:
|
||||
lockschem:
|
||||
state:
|
||||
skip:
|
||||
win:
|
||||
resetwg:
|
||||
resettb:
|
||||
tpslimit:
|
||||
tpswarp:
|
||||
techhiderbug:
|
||||
unrank:
|
||||
commands:
|
||||
@@ -53,3 +53,15 @@ tasks.register<FightServer>("WarGear21") {
|
||||
config = "WarGear21.yml"
|
||||
jar = "/jars/paper-1.21.6.jar"
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("WarShip21") {
|
||||
group = "run"
|
||||
description = "Run a WarShip 1.21 Fight Server"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":FightSystem:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
template = "WarShip21"
|
||||
worldName = "arenas/Artic"
|
||||
config = "WarShip21.yml"
|
||||
jar = "/jars/paper-1.21.6.jar"
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ dependencies {
|
||||
compileOnly(libs.paperapi)
|
||||
compileOnly(project(":SpigotCore"))
|
||||
|
||||
implementation(libs.coroutinesCore)
|
||||
implementation(libs.exposedCore)
|
||||
implementation(libs.exposedDao)
|
||||
implementation(libs.exposedJdbc)
|
||||
@@ -47,4 +48,4 @@ val compileKotlin: KotlinCompile by tasks
|
||||
|
||||
compileKotlin.compilerOptions {
|
||||
freeCompilerArgs.set(listOf("-XXLanguage:+ContextParameters"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
abstract class Observable<T> {
|
||||
internal val listeners = mutableSetOf<ObserverListener>()
|
||||
|
||||
open fun removeListener(render: ObserverListener) {
|
||||
listeners.remove(render)
|
||||
}
|
||||
|
||||
internal fun notifyListeners() {
|
||||
listeners.forEach { it.update() }
|
||||
}
|
||||
|
||||
context(render: ObserverListener)
|
||||
fun listen(): Observable<T> {
|
||||
listeners.add(render)
|
||||
render.observers.add(this)
|
||||
return this
|
||||
}
|
||||
|
||||
fun listen(callback: (T) -> Unit): () -> Unit {
|
||||
val listener = object: ObserverListener() {
|
||||
override fun update() = callback(get())
|
||||
}
|
||||
listeners.add(listener)
|
||||
callback(get())
|
||||
return { removeListener(listener) }
|
||||
}
|
||||
|
||||
abstract fun get(): T
|
||||
|
||||
fun <R> map(mapper: (T) -> R): Observable<R> = Delegate(mapper, this)
|
||||
|
||||
class Delegate<T, R>(val mapper: (T) -> R, val parent: Observable<T>): Observable<R>(), ReadOnlyProperty<Any?, R> {
|
||||
var value: R? = null
|
||||
var unsubParent = parent.listen {
|
||||
val old = value
|
||||
value = mapper(it)
|
||||
if (old != value) {
|
||||
notifyListeners()
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeListener(render: ObserverListener) {
|
||||
super.removeListener(render)
|
||||
if (listeners.isEmpty()) {
|
||||
unsubParent()
|
||||
}
|
||||
}
|
||||
|
||||
override fun get(): R = value!!
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): R = value!!
|
||||
}
|
||||
}
|
||||
|
||||
class Observer<T>(private var value: T): ReadWriteProperty<Any?, T>, Observable<T>() {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
this.value = value
|
||||
notifyListeners()
|
||||
}
|
||||
|
||||
fun set(value: T) {
|
||||
this.value = value
|
||||
notifyListeners()
|
||||
}
|
||||
|
||||
override fun get() = value
|
||||
|
||||
fun update(update: (T) -> T) {
|
||||
this.value = update(value)
|
||||
notifyListeners()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalForInheritanceCoroutinesApi
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.FlowCollector
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
private val uiStateScope = CoroutineScope(SupervisorJob() + Dispatchers.Unconfined)
|
||||
|
||||
context(render: StateFlowListener)
|
||||
fun <T> StateFlow<T>.listen(): StateFlow<T> {
|
||||
render.track(this) {
|
||||
drop(1).onEach { render.update() }.launchIn(uiStateScope)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
context(render: StateFlowListener)
|
||||
fun <T> MutableStateFlow<T>.listen(): MutableStateFlow<T> {
|
||||
render.track(this) {
|
||||
drop(1).onEach { render.update() }.launchIn(uiStateScope)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun <T> StateFlow<T>.listen(callback: (T) -> Unit): () -> Unit {
|
||||
callback(value)
|
||||
val job = drop(1).onEach { callback(it) }.launchIn(uiStateScope)
|
||||
return { job.cancel() }
|
||||
}
|
||||
|
||||
operator fun <T> StateFlow<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
|
||||
|
||||
operator fun <T> MutableStateFlow<T>.setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
fun <T, R> StateFlow<T>.map(mapper: (T) -> R): StateFlow<R> = MappedStateFlow(this, mapper)
|
||||
|
||||
@OptIn(ExperimentalForInheritanceCoroutinesApi::class)
|
||||
private class MappedStateFlow<T, R>(
|
||||
private val parent: StateFlow<T>,
|
||||
private val mapper: (T) -> R,
|
||||
): StateFlow<R> {
|
||||
override val replayCache: List<R>
|
||||
get() = listOf(value)
|
||||
|
||||
override val value: R
|
||||
get() = mapper(parent.value)
|
||||
|
||||
override suspend fun collect(collector: FlowCollector<R>): Nothing {
|
||||
var initialized = false
|
||||
var previous: Any? = null
|
||||
|
||||
parent.collect {
|
||||
val mapped = mapper(it)
|
||||
if (!initialized || previous != mapped) {
|
||||
initialized = true
|
||||
previous = mapped
|
||||
collector.emit(mapped)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-5
@@ -19,13 +19,23 @@
|
||||
|
||||
package de.steamwar.kotlin.ui
|
||||
|
||||
abstract class ObserverListener {
|
||||
val observers = mutableSetOf<Observable<*>>()
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
abstract class StateFlowListener {
|
||||
private val jobs = mutableMapOf<Any, Job>()
|
||||
|
||||
internal fun track(key: Any, createJob: () -> Job) {
|
||||
if (key in jobs) return
|
||||
|
||||
val job = createJob()
|
||||
jobs[key] = job
|
||||
job.invokeOnCompletion { jobs.remove(key) }
|
||||
}
|
||||
|
||||
abstract fun update()
|
||||
|
||||
open fun destroy() {
|
||||
observers.forEach { it.removeListener(this) }
|
||||
observers.clear()
|
||||
jobs.values.toList().forEach { it.cancel() }
|
||||
jobs.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import de.steamwar.kotlin.ui.components.item
|
||||
import de.steamwar.kotlin.util.count
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
val Counter = MutableStateFlow(0)
|
||||
|
||||
class TestInv(player: Player): UIInventory(player) {
|
||||
override fun view() {
|
||||
inventory(3, "") {
|
||||
item {
|
||||
val amount by Counter.map { it + 1 }.listen()
|
||||
item = ItemStack.of(Material.STONE)
|
||||
.count(amount)
|
||||
x = 0
|
||||
y = 0
|
||||
onClick {
|
||||
Counter.value += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import de.steamwar.kotlin.ui.context.WindowContext
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
|
||||
abstract class UIInventory(val player: Player): ObserverListener() {
|
||||
abstract class UIInventory(val player: Player): StateFlowListener() {
|
||||
var window: UIWindow? = null
|
||||
|
||||
abstract fun view()
|
||||
@@ -52,4 +52,4 @@ abstract class UIInventory(val player: Player): ObserverListener() {
|
||||
protected fun inventory(type: InventoryType, title: String, init: WindowContext.() -> Unit) {
|
||||
window = UIWindow(type, title, player, init)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.kotlin.ui.components
|
||||
|
||||
import de.steamwar.kotlin.ui.ObserverListener
|
||||
import de.steamwar.kotlin.ui.StateFlowListener
|
||||
import de.steamwar.kotlin.ui.RenderMarker
|
||||
import de.steamwar.kotlin.ui.RenderObject
|
||||
import de.steamwar.kotlin.ui.context.GroupContext
|
||||
@@ -29,7 +29,7 @@ import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@RenderMarker
|
||||
class ItemContext(val parent: RenderParent, val renderFunc: ItemContext.() -> Unit): RenderObject, ObserverListener() {
|
||||
class ItemContext(val parent: RenderParent, val renderFunc: ItemContext.() -> Unit): RenderObject, StateFlowListener() {
|
||||
override fun update() {
|
||||
val oldX = x
|
||||
val oldY = y
|
||||
@@ -40,6 +40,7 @@ class ItemContext(val parent: RenderParent, val renderFunc: ItemContext.() -> Un
|
||||
}
|
||||
|
||||
override fun destroy() {
|
||||
super.destroy()
|
||||
parent.resetSlot(x, y)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
|
||||
package de.steamwar.kotlin.ui.context
|
||||
|
||||
import de.steamwar.kotlin.ui.ObserverListener
|
||||
import de.steamwar.kotlin.ui.StateFlowListener
|
||||
import de.steamwar.kotlin.ui.RenderMarker
|
||||
import de.steamwar.kotlin.ui.RenderObject
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@RenderMarker
|
||||
open class GroupContext(val parent: RenderParent?, val init: GroupContext.() -> Unit): ObserverListener(), RenderObject, RenderParent {
|
||||
open class GroupContext(val parent: RenderParent?, val init: GroupContext.() -> Unit): StateFlowListener(), RenderObject, RenderParent {
|
||||
val children = mutableListOf<RenderObject>()
|
||||
val updatedSlots = mutableSetOf<Pair<Int, Int>>()
|
||||
|
||||
@@ -62,4 +62,4 @@ open class GroupContext(val parent: RenderParent?, val init: GroupContext.() ->
|
||||
init(this)
|
||||
(oldUpdatedSlots - updatedSlots).forEach { resetSlot(it.first, it.second) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +80,12 @@ public class CustomMap implements Listener {
|
||||
|
||||
if (mapFileOrDirectory.isDirectory()) {
|
||||
AtomicReference<Month> lastMonth = new AtomicReference<>(LocalDateTime.now().getMonth());
|
||||
AtomicReference<Long> lastModified = new AtomicReference<>(Long.MAX_VALUE);
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
long modified = mapFileOrDirectory.lastModified();
|
||||
Month current = LocalDateTime.now().getMonth();
|
||||
if (!current.equals(lastMonth.get()) || update) {
|
||||
if (modified > lastModified.get() || !current.equals(lastMonth.get()) || update) {
|
||||
lastModified.set(modified);
|
||||
lastMonth.set(current);
|
||||
update = false;
|
||||
this.mapFile = new File(mapFileOrDirectory, current.getValue() + ".png");
|
||||
|
||||
@@ -69,6 +69,7 @@ public class CustomItem extends SpecialItem {
|
||||
}
|
||||
for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
|
||||
if (!itemFile.canRead() || !itemFile.isFile()) continue;
|
||||
if (!itemFile.getName().endsWith(".json")) continue;
|
||||
try {
|
||||
JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
|
||||
new CustomItem(new ScriptedItem(jsonObject));
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.scripts.ScriptedItem;
|
||||
import de.steamwar.misslewars.scripts.utils.EntityUtils;
|
||||
import de.steamwar.misslewars.scripts.utils.EntityUtils.ScriptShortcut;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Projectile;
|
||||
|
||||
public class LaunchScript implements RunnableScript {
|
||||
|
||||
@@ -75,6 +75,11 @@ public class EntityUtils {
|
||||
});
|
||||
case "arrow":
|
||||
return new ScriptShortcut<>(Arrow.class, (jsonObject, entity, runnableScriptEvent) -> setProjectileOptions(entity, jsonObject));
|
||||
case "windcharge":
|
||||
return new ScriptShortcut<>(WindCharge.class, (jsonObject, entity, runnableScriptEvent) -> {
|
||||
setFireballOptions(entity, jsonObject);
|
||||
entity.setDirection(runnableScriptEvent.getLocation().getDirection());
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ AUTO_CHECKER_RESULT_DEFUNCT_NBT = §7Defunct NBT: §7[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_DESIGN_BLOCK = §7{0} in Design: [{1}, {2}, {3}]
|
||||
AUTO_CHECKER_RESULT_ENTITY = §7Entity: §7[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_RECORD = §7Record: §c[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS = §7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7items, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_INVENTORY_ITEMS = §7{6}: §c[{0}, {1}, {2}]§7, §c{3}x {5}§7, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT = §7Forbidden Item NBT: [{0}, {1}, {2}] -> §c{3}
|
||||
AUTO_CHECKER_RESULT_TELEPORT_HERE = §7Teleport to block
|
||||
AUTO_CHECKER_RESULT_AFTER_DEADLINE = §cThe deadline has expired: {0}
|
||||
|
||||
@@ -248,7 +248,7 @@ AUTO_CHECKER_RESULT_FORBIDDEN_ITEM = §7Verbotener gegenstand: [{0}, {1}, {2}] -
|
||||
AUTO_CHECKER_RESULT_DEFUNCT_NBT = §7Keine NBT-Daten: §c[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_DESIGN_BLOCK = §7{0} im Design: [{1}, {2}, {3}]
|
||||
AUTO_CHECKER_RESULT_RECORD = §7Schallplatte: §c[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS = §7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7gegenstände, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_INVENTORY_ITEMS = §7{6}: §c[{0}, {1}, {2}]§7, §c{3}x {5}§7, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT = §7Verbotene NBT-Daten: [{0}, {1}, {2}] -> §c{3}
|
||||
AUTO_CHECKER_RESULT_TELEPORT_HERE = §7Zum block teleportieren
|
||||
AUTO_CHECKER_RESULT_AFTER_DEADLINE = §cDer einsendeschluss ist bereits vorbei: {0}
|
||||
|
||||
@@ -75,9 +75,9 @@ public class AutoChecker {
|
||||
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
|
||||
if (AutoCheckerItems.impl.getInventoryMaterials().contains(material)) {
|
||||
if (type.Schematic.isInventory(material)) {
|
||||
checkInventory(result, block, material, pos, type);
|
||||
if (result.getDispenserItems().getOrDefault(pos, 0) > 0) {
|
||||
if (!result.getInventoryItemCounts().getOrDefault(pos, Collections.emptyMap()).isEmpty()) {
|
||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||
}
|
||||
} else {
|
||||
@@ -93,19 +93,6 @@ public class AutoChecker {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final Map<Material, Set<Material>> itemsInInv = new EnumMap<>(Material.class);
|
||||
|
||||
static {
|
||||
itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER));
|
||||
itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST, Material.BARREL, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX,
|
||||
Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX,
|
||||
Material.LIGHT_GRAY_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
|
||||
Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX));
|
||||
itemsInInv.put(Material.FIRE_CHARGE, EnumSet.of(Material.DISPENSER));
|
||||
itemsInInv.put(Material.ARROW, EnumSet.of(Material.DISPENSER));
|
||||
AutoCheckerItems.impl.getAllowedMaterialsInInventory().forEach(material -> itemsInInv.put(material, AutoCheckerItems.impl.getInventoryMaterials()));
|
||||
}
|
||||
|
||||
private void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos, GameModeConfig<Material, String> type) {
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
if (nbt == null) {
|
||||
@@ -122,7 +109,7 @@ public class AutoChecker {
|
||||
List<CompoundTag> items = nbt.getList("Items", CompoundTag.class);
|
||||
if (items.isEmpty()) return; // Leeres Inventar
|
||||
|
||||
int counter = 0;
|
||||
Map<Material, Integer> itemCounts = new EnumMap<>(Material.class);
|
||||
int windChargeCount = 0;
|
||||
for (CompoundTag item : items) {
|
||||
if (!item.containsKey("id")) {
|
||||
@@ -136,16 +123,19 @@ public class AutoChecker {
|
||||
|
||||
if (type.Schematic.Type.getName().equals("wargearseason26") && material == Material.DISPENSER && itemType == Material.WIND_CHARGE) {
|
||||
windChargeCount += item.getInt("count");
|
||||
} else if (!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) {
|
||||
} else if (type.Schematic.getItemAmount(material, itemType) == 0) {
|
||||
result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
||||
} else if (material == Material.DISPENSER && (itemType == Material.ARROW || itemType == Material.FIRE_CHARGE)) {
|
||||
counter += item.getInt("count");
|
||||
} else {
|
||||
itemCounts.merge(itemType, item.getInt("count"), Integer::sum);
|
||||
}
|
||||
if (item.containsKey("tag")) {
|
||||
result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
||||
}
|
||||
}
|
||||
result.getDispenserItems().put(pos, counter);
|
||||
if (!itemCounts.isEmpty()) {
|
||||
result.getInventoryItemCounts().put(pos, itemCounts);
|
||||
result.getInventoryBlockType().put(pos, material);
|
||||
}
|
||||
result.getWindChargeCount().put(pos, windChargeCount);
|
||||
}
|
||||
|
||||
@@ -156,7 +146,8 @@ public class AutoChecker {
|
||||
private final List<BlockPos> defunctNbt = new ArrayList<>();
|
||||
private final List<BlockPos> records = new ArrayList<>();
|
||||
private final Map<Material, List<BlockPos>> designBlocks = new EnumMap<>(Material.class);
|
||||
private final Map<BlockPos, Integer> dispenserItems = new HashMap<>();
|
||||
private final Map<BlockPos, Map<Material, Integer>> inventoryItemCounts = new HashMap<>();
|
||||
private final Map<BlockPos, Material> inventoryBlockType = new HashMap<>();
|
||||
private final Map<BlockPos, Integer> windChargeCount = new HashMap<>();
|
||||
private final Map<BlockPos, Set<Material>> forbiddenItems = new HashMap<>();
|
||||
private final Map<BlockPos, Set<Material>> forbiddenNbt = new HashMap<>();
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* 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 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.schematicsystem.autocheck;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AutoCheckerItems {
|
||||
|
||||
public static final AutoCheckerItems impl = new AutoCheckerItems();
|
||||
|
||||
private static final Set<Material> INVENTORY = EnumSet.of(Material.BARREL, Material.BLAST_FURNACE, Material.BREWING_STAND, Material.CAMPFIRE,
|
||||
Material.CHEST, Material.DISPENSER, Material.DROPPER, Material.FURNACE, Material.HOPPER, Material.JUKEBOX, Material.SHULKER_BOX,
|
||||
Material.WHITE_SHULKER_BOX, Material.ORANGE_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX,
|
||||
Material.LIME_SHULKER_BOX, Material.PINK_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX, Material.CYAN_SHULKER_BOX,
|
||||
Material.PURPLE_SHULKER_BOX, Material.BLUE_SHULKER_BOX, Material.BROWN_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.RED_SHULKER_BOX,
|
||||
Material.BLACK_SHULKER_BOX, Material.SMOKER, Material.TRAPPED_CHEST);
|
||||
|
||||
private static final Set<Material> FLOWERS = EnumSet.of(Material.CORNFLOWER, Material.POPPY, Material.FERN, Material.DANDELION, Material.BLUE_ORCHID,
|
||||
Material.ALLIUM, Material.AZURE_BLUET, Material.RED_TULIP, Material.ORANGE_TULIP, Material.WHITE_TULIP, Material.PINK_TULIP, Material.OXEYE_DAISY,
|
||||
Material.LILY_OF_THE_VALLEY, Material.WITHER_ROSE, Material.SUNFLOWER, Material.DIAMOND_HORSE_ARMOR, Material.IRON_HORSE_ARMOR,
|
||||
Material.GOLDEN_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR, Material.HONEY_BOTTLE, Material.LILAC, Material.ROSE_BUSH, Material.PEONY,
|
||||
Material.TALL_GRASS, Material.LARGE_FERN);
|
||||
|
||||
public Set<Material> getInventoryMaterials() {
|
||||
return INVENTORY;
|
||||
}
|
||||
|
||||
public Set<Material> getAllowedMaterialsInInventory() {
|
||||
return FLOWERS;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class AutoCheckerResult {
|
||||
isSizeOk() &&
|
||||
isBlockCountOk() &&
|
||||
isLimitedBlocksOK() &&
|
||||
isDispenserItemsOK() &&
|
||||
isInventoryItemsOK() &&
|
||||
isWindchargeCountOK() &&
|
||||
!type.isAfterDeadline() &&
|
||||
entities.isEmpty() &&
|
||||
@@ -71,8 +71,14 @@ public class AutoCheckerResult {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDispenserItemsOK() {
|
||||
return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.Schematic.MaxDispenserItems);
|
||||
public boolean isInventoryItemsOK() {
|
||||
return blockScanResult.getInventoryItemCounts().entrySet().stream().allMatch(posEntry -> {
|
||||
Material inventory = blockScanResult.getInventoryBlockType().get(posEntry.getKey());
|
||||
return posEntry.getValue().entrySet().stream().allMatch(itemEntry -> {
|
||||
int cap = type.Schematic.getItemAmount(inventory, itemEntry.getKey());
|
||||
return itemEntry.getValue() <= cap;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasWarnings() {
|
||||
@@ -100,13 +106,8 @@ public class AutoCheckerResult {
|
||||
}
|
||||
|
||||
public boolean isLimitedBlocksOK() {
|
||||
try {
|
||||
return type.Schematic.Limited.entrySet().stream()
|
||||
.map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(blockScanResult.getBlockCounts()::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false))
|
||||
.reduce(Boolean::logicalAnd).orElse(true);
|
||||
} catch (NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
return blockScanResult.getBlockCounts().entrySet().stream()
|
||||
.allMatch(entry -> entry.getValue() <= type.Schematic.getMaxCount(entry.getKey()));
|
||||
}
|
||||
|
||||
public boolean isDesignBlastResistanceOK() {
|
||||
@@ -130,14 +131,13 @@ public class AutoCheckerResult {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockScanResult.getBlockCounts().values().stream().reduce(Integer::sum).orElse(0), type.Schematic.MaxBlocks);
|
||||
}
|
||||
if (!isLimitedBlocksOK()) {
|
||||
type.Schematic.Limited.forEach((materials, integer) -> {
|
||||
for (Material mat : materials) {
|
||||
if (mat != null && blockScanResult.getBlockCounts().getOrDefault(mat, 0) > integer) {
|
||||
if (integer == 0) {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_BLOCK", p, mat.name());
|
||||
} else {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_BLOCK", p, mat.name(), blockScanResult.getBlockCounts().getOrDefault(mat, 0), integer);
|
||||
}
|
||||
blockScanResult.getBlockCounts().forEach((mat, count) -> {
|
||||
int maxCount = type.Schematic.getMaxCount(mat);
|
||||
if (count > maxCount) {
|
||||
if (maxCount == 0) {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_BLOCK", p, mat.name());
|
||||
} else {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_BLOCK", p, mat.name(), count, maxCount);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -155,13 +155,20 @@ public class AutoCheckerResult {
|
||||
});
|
||||
}
|
||||
|
||||
blockScanResult.getDispenserItems().entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.Schematic.MaxDispenserItems).forEach(blockVector3IntegerEntry -> {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3IntegerEntry.getKey()),
|
||||
blockVector3IntegerEntry.getKey().getBlockX(),
|
||||
blockVector3IntegerEntry.getKey().getBlockY(),
|
||||
blockVector3IntegerEntry.getKey().getBlockZ(),
|
||||
blockVector3IntegerEntry.getValue(),
|
||||
type.Schematic.MaxDispenserItems);
|
||||
blockScanResult.getInventoryItemCounts().forEach((pos, itemCounts) -> {
|
||||
Material inventory = blockScanResult.getInventoryBlockType().get(pos);
|
||||
itemCounts.forEach((itemType, count) -> {
|
||||
int cap = type.Schematic.getItemAmount(inventory, itemType);
|
||||
if (count <= cap) return;
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_INVENTORY_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(pos),
|
||||
pos.getBlockX(),
|
||||
pos.getBlockY(),
|
||||
pos.getBlockZ(),
|
||||
count,
|
||||
cap,
|
||||
itemType.name(),
|
||||
inventory.name());
|
||||
});
|
||||
});
|
||||
|
||||
blockScanResult.getRecords().forEach(blockVector3 -> {
|
||||
|
||||
+14
-10
@@ -197,27 +197,31 @@ public class SchematicCommand extends SWCommand {
|
||||
clipboard.setBlock(vector, block.toBaseBlock(builder.build()));
|
||||
}
|
||||
|
||||
if (type.Schematic.MaxDispenserItems > 0) {
|
||||
for (Map.Entry<BlockPos, Integer> entry : result.getBlockScanResult().getDispenserItems().entrySet()) {
|
||||
if (entry.getValue() <= type.Schematic.MaxDispenserItems) {
|
||||
for (Map.Entry<BlockPos, Map<Material, Integer>> posEntry : result.getBlockScanResult().getInventoryItemCounts().entrySet()) {
|
||||
BlockPos pos = posEntry.getKey();
|
||||
Material inventory = result.getBlockScanResult().getInventoryBlockType().get(pos);
|
||||
|
||||
for (Map.Entry<Material, Integer> itemEntry : posEntry.getValue().entrySet()) {
|
||||
Material itemType = itemEntry.getKey();
|
||||
Integer cap = type.Schematic.getItemAmount(inventory, itemType);
|
||||
if (itemEntry.getValue() <= cap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos pos = entry.getKey();
|
||||
BlockVector3 vector = BlockVector3.at(pos.getX(), pos.getY(), pos.getZ());
|
||||
BaseBlock block = clipboard.getFullBlock(vector);
|
||||
CompoundTag tag = block.getNbtData();
|
||||
CompoundTagBuilder builder = tag.createBuilder();
|
||||
List<CompoundTag> items = new ArrayList<>(tag.getList("Items", CompoundTag.class));
|
||||
Collections.reverse(items); // To let the first item be in the Dispenser
|
||||
Collections.reverse(items); // To let the first item be in the inventory
|
||||
List<CompoundTag> list = new ArrayList<>();
|
||||
int diff = entry.getValue() - type.Schematic.MaxDispenserItems;
|
||||
int diff = itemEntry.getValue() - cap;
|
||||
for (CompoundTag item : items) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (diff == 0) {
|
||||
if (diff == 0 || Material.matchMaterial(item.getString("id")) != itemType) {
|
||||
list.add(item);
|
||||
continue;
|
||||
}
|
||||
@@ -238,9 +242,9 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
|
||||
if (!result.isLimitedBlocksOK()) {
|
||||
Set<Material> toReplace = type.Schematic.Limited.entrySet().stream()
|
||||
.filter(setIntegerEntry -> setIntegerEntry.getValue() == 0)
|
||||
.flatMap(setIntegerEntry -> setIntegerEntry.getKey().stream())
|
||||
Set<Material> toReplace = type.Schematic.Limited.stream()
|
||||
.filter(rule -> rule.Amount == 0)
|
||||
.flatMap(rule -> rule.Materials.stream())
|
||||
.collect(Collectors.toSet());
|
||||
BlockState replaceType = Objects.requireNonNull(toReplace.contains(Material.END_STONE) ? BlockTypes.IRON_BLOCK : BlockTypes.END_STONE).getDefaultState();
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
|
||||
@@ -108,19 +108,33 @@ UNNOSCHEMSUBMITTING = §e{0} §7may now submit §e§lschematics§7 again§8.
|
||||
|
||||
WORLDEDIT_CUI_TITLE = WorldEdit CUI
|
||||
WORLDEDIT_CUI_TITLE_SUBMENU = WorldEdit CUI - {0}
|
||||
WORLDEDIT_CUI_SELECTION = Own Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD = Own Clipboard
|
||||
WORLDEDIT_CUI_SELECTION_OTHER = Other Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD_OTHER = Other Clipboard
|
||||
WORLDEDIT_CUI_SELECTION = Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD = Clipboard
|
||||
WORLDEDIT_CUI_CURSOR = Cursor
|
||||
|
||||
WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0}
|
||||
WORLDEDIT_CUI_MATERIAL_CLICK = §7Click to edit
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_NAME = §eWidth {0}
|
||||
WORLDEDIT_CUI_WIDTH_NAME_DIST = §eRange {0}
|
||||
WORLDEDIT_CUI_WIDTH_LORE = §8> §7{0}
|
||||
WORLDEDIT_CUI_WIDTH_LORE_SELECTED = §8> §e{0}
|
||||
WORLDEDIT_CUI_WIDTH_CLICK = §7Click to change
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_HUGE = 1/ 8 Block
|
||||
WORLDEDIT_CUI_WIDTH_LARGE = 1/16 Block
|
||||
WORLDEDIT_CUI_WIDTH_MEDIUM = 1/32 Block
|
||||
WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block
|
||||
WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_HUGE_DIST = 40 Blocks
|
||||
WORLDEDIT_CUI_WIDTH_LARGE_DIST = 30 Blocks
|
||||
WORLDEDIT_CUI_WIDTH_MEDIUM_DIST = 20 Blocks
|
||||
WORLDEDIT_CUI_WIDTH_SLIM_DIST = 10 Blocks
|
||||
|
||||
WORLDEDIT_CUI_TOOL_SOON = §7Tool cooming soon!
|
||||
WORLDEDIT_CUI_TOOL_COPY = §eCopy Tool
|
||||
WORLDEDIT_CUI_TOOL_COPY_LORE = §eClick§8:§7 copy selection
|
||||
WORLDEDIT_CUI_TOOL_PASTE = §ePaste Tool
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_1 = §eClick§8:§7 paste clipboard
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_2 = §eShift §8+§e Click§8:§7 paste clipboard and select
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_3 = §eDrop§8:§7 paste clipboard at copy origin
|
||||
@@ -101,13 +101,20 @@ NOSCHEMSUBMITTING_UNTIL = §7Du bist §ebis zum {0} §7vom §e§lEinsenden von S
|
||||
UNNOSCHEMSUBMITTING_ERROR = §cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen.
|
||||
UNNOSCHEMSUBMITTING = §e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8.
|
||||
|
||||
WORLDEDIT_CUI_SELECTION = Eigene Auswahl
|
||||
WORLDEDIT_CUI_CLIPBOARD = Eigene Kopie
|
||||
WORLDEDIT_CUI_SELECTION_OTHER = Auswahl Anderer
|
||||
WORLDEDIT_CUI_CLIPBOARD_OTHER = Kopie Anderer
|
||||
WORLDEDIT_CUI_SELECTION = Auswahl
|
||||
WORLDEDIT_CUI_CLIPBOARD = Kopie
|
||||
|
||||
WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0}
|
||||
WORLDEDIT_CUI_MATERIAL_CLICK = §7Klicke zum Editieren
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_NAME = §eDicke - {0}
|
||||
WORLDEDIT_CUI_WIDTH_CLICK = §7Klicke zum ändern
|
||||
WORLDEDIT_CUI_WIDTH_NAME = §eKlicke - {0}
|
||||
WORLDEDIT_CUI_WIDTH_NAME_DIST = Reichweite§e {0}
|
||||
WORLDEDIT_CUI_WIDTH_CLICK = §7Klicke zum ändern
|
||||
|
||||
WORLDEDIT_CUI_TOOL_SOON = §7Werkzeug kommt in kürze!
|
||||
WORLDEDIT_CUI_TOOL_COPY = §eCopy Werkzeug
|
||||
WORLDEDIT_CUI_TOOL_COPY_LORE = §eKlick§8:§7 Auswahl zu kopieren
|
||||
WORLDEDIT_CUI_TOOL_PASTE = §ePaste Werkzeug
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_1 = §eKlick§8:§7 Clipboard einzufügen
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_2 = §eUmschalt §8+§e Klick§8:§7 Clipboard einzufügen und auszuwählen
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_3 = §eDrop§8:§7 Clipboard am Kopierpunkt einzufügen
|
||||
@@ -21,8 +21,8 @@ package de.steamwar.core;
|
||||
|
||||
import de.steamwar.message.Message;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Delegate;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -99,11 +99,11 @@ public class SWPlayer {
|
||||
|
||||
@Data
|
||||
public static final class SWPlayerWithComponent<T extends Component> {
|
||||
private final SWPlayer player;
|
||||
private final SWPlayer swPlayer;
|
||||
private final T component;
|
||||
}
|
||||
|
||||
@Delegate
|
||||
@Getter
|
||||
private final Player player;
|
||||
private final Map<Class<? extends Component>, Component> components = new HashMap<>();
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* 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 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.core.events;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SWException;
|
||||
import de.steamwar.techhider.ProtocolUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Linked
|
||||
public class AntiNocom implements Listener {
|
||||
|
||||
private final Map<Player, Integer> flags = new ConcurrentHashMap<>();
|
||||
|
||||
public AntiNocom() {
|
||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::onDig);
|
||||
registerUseItem();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
flags.remove(e.getPlayer());
|
||||
}
|
||||
|
||||
private void registerUseItem() {
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (player, packet) -> {
|
||||
BlockPos pos = packet.getHitResult().getBlockPos();
|
||||
return isValid(player, "UseItem", pos.getX(), pos.getZ()) ? packet : null;
|
||||
});
|
||||
}
|
||||
|
||||
private ServerboundPlayerActionPacket onDig(Player player, ServerboundPlayerActionPacket packet) {
|
||||
BlockPos pos = packet.getPos();
|
||||
return isValid(player, "Dig", pos.getX(), pos.getZ()) ? packet : null;
|
||||
}
|
||||
|
||||
private boolean isValid(Player player, String type, int x, int z) {
|
||||
if ((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int amount = flags.compute(player, (p, a) -> a == null ? 1 : a + 1);
|
||||
if (amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam
|
||||
if (amount == 8) {
|
||||
// Schedule player kick only once
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
||||
}
|
||||
|
||||
SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.core.worldedit;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class SteamEdit {
|
||||
|
||||
private static final AtomicBoolean INITIALIZED = new AtomicBoolean();
|
||||
|
||||
public static void init() {
|
||||
INITIALIZED.set(true);
|
||||
new Command();
|
||||
new SteamEditWand();
|
||||
new WorldEditRendererCUIEditor();
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return INITIALIZED.get();
|
||||
}
|
||||
|
||||
public static Function<Location, AdjacentFilter> ADJACENT_FILTERS = location -> AdjacentFilter.ALWAYS;
|
||||
|
||||
public interface AdjacentFilter {
|
||||
AdjacentFilter ALWAYS = (x, y, z) -> true;
|
||||
|
||||
boolean contains(int x, int y, int z);
|
||||
}
|
||||
|
||||
private static final class Command extends SWCommand {
|
||||
|
||||
public Command() {
|
||||
super("steamwand", "steamedit", "steameditwand", "swwand", "sweditwand", "swedit");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void get(Player player) {
|
||||
if (player.getInventory().contains(SteamEditWand.ITEM)) {
|
||||
player.getInventory().remove(SteamEditWand.ITEM);
|
||||
}
|
||||
ItemStack handItem = player.getInventory().getItemInMainHand();
|
||||
player.getInventory().setItemInMainHand(SteamEditWand.ITEM);
|
||||
if (!handItem.isEmpty()) {
|
||||
player.getInventory().addItem(handItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.core.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SteamEditSelectAdjacent {
|
||||
|
||||
private static final BlockFace[] FACES = {
|
||||
BlockFace.NORTH,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.WEST,
|
||||
BlockFace.UP,
|
||||
BlockFace.DOWN,
|
||||
};
|
||||
|
||||
private Location min;
|
||||
private Location max;
|
||||
|
||||
private SteamEdit.AdjacentFilter filter;
|
||||
|
||||
private LinkedHashSet<Location> frontier = new LinkedHashSet<>();
|
||||
|
||||
public SteamEditSelectAdjacent(Location origin) {
|
||||
// TODO: Fix the flood fill algorithm!
|
||||
min = origin.clone();
|
||||
max = origin.clone();
|
||||
frontier.add(origin);
|
||||
filter = SteamEdit.ADJACENT_FILTERS.apply(origin);
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
for (int i = 0; i < 500_000 && !frontier.isEmpty(); i++) {
|
||||
if (System.currentTimeMillis() - time > 1000) break;
|
||||
expandNext();
|
||||
}
|
||||
|
||||
Core.getInstance().getLogger().finer(System.currentTimeMillis() - time + "ms " + frontier.size() + " " + min + " to " + max);
|
||||
}
|
||||
|
||||
public BlockVector3 pos1() {
|
||||
return BlockVector3.at(min.getBlockX(), min.getBlockY(), min.getBlockZ());
|
||||
}
|
||||
|
||||
public BlockVector3 pos2() {
|
||||
return BlockVector3.at(max.getBlockX(), max.getBlockY(), max.getBlockZ());
|
||||
}
|
||||
|
||||
private boolean inside(Location loc, int offset) {
|
||||
return loc.getBlockX() >= min.getBlockX() + offset && loc.getBlockX() <= max.getBlockX() - offset &&
|
||||
loc.getBlockY() >= min.getBlockY() + offset && loc.getBlockY() <= max.getBlockY() - offset &&
|
||||
loc.getBlockZ() >= min.getBlockZ() + offset && loc.getBlockZ() <= max.getBlockZ() - offset;
|
||||
}
|
||||
|
||||
public void expandNext() {
|
||||
Location location = frontier.removeFirst();
|
||||
expand(location);
|
||||
}
|
||||
|
||||
private void expand(Location loc) {
|
||||
for (BlockFace face : FACES) {
|
||||
Vector direction = face.getDirection();
|
||||
Location location = loc.clone().add(direction);
|
||||
if (!filter.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) continue;
|
||||
if (inside(location, 0)) continue;
|
||||
List<Location> layer = Stream.concat(selectFrontier(direction.getBlockX() == 0 ? null : loc.getBlockX(), direction.getBlockY() == 0 ? null : loc.getBlockY(), direction.getBlockZ() == 0 ? null : loc.getBlockZ())
|
||||
.map(Location::clone)
|
||||
.map(l -> l.add(direction)), Stream.of(location))
|
||||
.filter(l -> !l.getBlock().isEmpty())
|
||||
.filter(l -> !l.getBlock().isLiquid())
|
||||
.toList();
|
||||
if (layer.isEmpty()) continue;
|
||||
|
||||
if (direction.getBlockX() < 0 || direction.getBlockY() < 0 || direction.getBlockZ() < 0) {
|
||||
min.add(direction);
|
||||
} else {
|
||||
max.add(direction);
|
||||
}
|
||||
layer.stream().filter(l -> !inside(l, 1))
|
||||
.filter(l -> filter.contains(l.getBlockX(), l.getBlockY(), l.getBlockZ()))
|
||||
.forEach(frontier::add);
|
||||
}
|
||||
}
|
||||
|
||||
private Stream<Location> selectFrontier(Integer x, Integer y, Integer z) {
|
||||
Stream<Location> stream = frontier.stream();
|
||||
if (x != null) stream = stream.filter(loc -> loc.getBlockX() == x);
|
||||
if (y != null) stream = stream.filter(loc -> loc.getBlockY() == y);
|
||||
if (z != null) stream = stream.filter(loc -> loc.getBlockZ() == z);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.core.worldedit;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.entity.CWireframe;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SteamEditWand implements Listener {
|
||||
|
||||
public static final Material MATERIAL = Material.GOLDEN_AXE;
|
||||
public static final String NAME = "§eSteam§8Edit §7Wand";
|
||||
public static final String[] LORE = {
|
||||
"§eL-Click§8: §7Set Pos1",
|
||||
"§eR-Click§8: §7Set Pos2",
|
||||
"§eShift §8+ §eR-Click§8: §7Set Pos2 or Expand Selection",
|
||||
"§eM-Click§8: §7Select connected",
|
||||
"§eSwap-Hands§8: §7Open CUI"
|
||||
};
|
||||
public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack();
|
||||
|
||||
private boolean noWand(Player player) {
|
||||
return player.getInventory().getItemInMainHand().getType() != SteamEditWand.MATERIAL;
|
||||
}
|
||||
|
||||
private final WorldEditPlugin we;
|
||||
|
||||
SteamEditWand() {
|
||||
we = WorldEditWrapper.getWorldEditPlugin();
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
|
||||
TinyProtocol.instance.addFilter(ServerboundSwingPacket.class, this::leftClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundInteractPacket.class, (player, packet) -> {
|
||||
if (packet.isAttack()) {
|
||||
return leftClick(player, packet);
|
||||
} else {
|
||||
return rightClick(player, packet);
|
||||
}
|
||||
});
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemPacket.class, this::rightClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::rightClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundPickItemFromBlockPacket.class, this::middleClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::swapHands);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::movePlayerPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::movePlayerPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::movePlayerPacket);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (noWand(player)) SWPlayer.of(player).removeComponent(SWEditCursor.class);
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (noWand(event.getPlayer())) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public static class SWEditCursor implements SWPlayer.Component {
|
||||
private Player player;
|
||||
private REntityServer entityServer = new REntityServer();
|
||||
private CWireframe wireframe;
|
||||
|
||||
@Override
|
||||
public void onMount(SWPlayer player) {
|
||||
this.player = player.getPlayer();
|
||||
entityServer.addPlayer(player.getPlayer());
|
||||
wireframe = new CWireframe(entityServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
entityServer.close();
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
wireframe.setPos1And2(location, location);
|
||||
wireframe.setBlock(WorldEditRendererCUIEditor.Type.CURSOR.getMaterial(player).createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
private Packet<?> leftClick(Player player, Packet<?> packet) {
|
||||
if (noWand(player)) return packet;
|
||||
if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet;
|
||||
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||
if (result == null) return packet;
|
||||
Block block = result.getHitBlock();
|
||||
if (block == null) return packet;
|
||||
BlockVector3 pos1 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||
setPos1(player, pos1);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setPos1(Player player, BlockVector3 pos1) {
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return;
|
||||
selectPos1(session.getRegionSelector(world), player, session, pos1);
|
||||
}
|
||||
|
||||
private Packet<?> rightClick(Player player, Packet<?> packet) {
|
||||
if (noWand(player)) return packet;
|
||||
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||
if (result == null) return packet;
|
||||
Block block = result.getHitBlock();
|
||||
if (block == null) return packet;
|
||||
BlockVector3 pos2 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||
if (!player.isSneaking()) {
|
||||
setPos2(player, pos2);
|
||||
} else {
|
||||
setPos2OrExpand(player, pos2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setPos2(Player player, BlockVector3 pos2) {
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return;
|
||||
selectPos2(session.getRegionSelector(world), player, session, pos2);
|
||||
}
|
||||
|
||||
private void setPos2OrExpand(Player player, BlockVector3 expand) {
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return;
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
|
||||
// Only primary set for now
|
||||
if (!regionSelector.isDefined()) {
|
||||
selectPos2(session.getRegionSelector(world), player, session, expand);
|
||||
return;
|
||||
}
|
||||
|
||||
List<BlockVector3> vertices = regionSelector.getVertices();
|
||||
// Probably not a cuboid selection!
|
||||
if (vertices.size() > 2) {
|
||||
selectPos2(session.getRegionSelector(world), player, session, expand);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockVector3 pos1 = vertices.get(0);
|
||||
BlockVector3 pos2 = vertices.get(1);
|
||||
|
||||
BlockVector3 min = pos1.getMinimum(pos2);
|
||||
BlockVector3 max = pos1.getMaximum(pos2);
|
||||
if (expand.containedWithin(pos1, pos2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Closer x = Closer.UNKNOWN;
|
||||
Closer y = Closer.UNKNOWN;
|
||||
Closer z = Closer.UNKNOWN;
|
||||
|
||||
boolean insideX = min.x() < expand.x() && max.x() > expand.x();
|
||||
boolean insideY = min.y() < expand.y() && max.y() > expand.y();
|
||||
boolean insideZ = min.z() < expand.z() && max.z() > expand.z();
|
||||
|
||||
if (insideX) {
|
||||
// No Change needed
|
||||
} else if (Math.abs(pos1.x() - expand.x()) > Math.abs(pos2.x() - expand.x())) {
|
||||
x = Closer.POS2;
|
||||
} else if (Math.abs(pos1.x() - expand.x()) < Math.abs(pos2.x() - expand.x())) {
|
||||
x = Closer.POS1;
|
||||
}
|
||||
|
||||
if (insideY) {
|
||||
// No Change needed
|
||||
} else if (Math.abs(pos1.y() - expand.y()) > Math.abs(pos2.y() - expand.y())) {
|
||||
y = Closer.POS2;
|
||||
} else if (Math.abs(pos1.y() - expand.y()) < Math.abs(pos2.y() - expand.y())) {
|
||||
y = Closer.POS1;
|
||||
}
|
||||
|
||||
if (insideZ) {
|
||||
// No Change needed
|
||||
} else if (Math.abs(pos1.z() - expand.z()) > Math.abs(pos2.z() - expand.z())) {
|
||||
z = Closer.POS2;
|
||||
} else if (Math.abs(pos1.z() - expand.z()) < Math.abs(pos2.z() - expand.z())) {
|
||||
z = Closer.POS1;
|
||||
}
|
||||
|
||||
Closer x1 = Closer.UNKNOWN;
|
||||
Closer y1 = Closer.UNKNOWN;
|
||||
Closer z1 = Closer.UNKNOWN;
|
||||
|
||||
if (!insideX && pos1.x() != expand.x() && pos2.x() != expand.x() && x == Closer.UNKNOWN) {
|
||||
x1 = y.and(z).or(Closer.POS1);
|
||||
}
|
||||
if (!insideY && pos1.y() != expand.y() && pos2.y() != expand.y() && y == Closer.UNKNOWN) {
|
||||
y1 = x.and(z).or(Closer.POS1);
|
||||
}
|
||||
if (!insideZ && pos1.z() != expand.z() && pos2.z() != expand.z() && z == Closer.UNKNOWN) {
|
||||
z1 = x.and(y).or(Closer.POS1);
|
||||
}
|
||||
|
||||
if (x1 != Closer.UNKNOWN) x = x1;
|
||||
if (y1 != Closer.UNKNOWN) y = y1;
|
||||
if (z1 != Closer.UNKNOWN) z = z1;
|
||||
|
||||
boolean p1updated = false;
|
||||
boolean p2updated = false;
|
||||
|
||||
if (x == Closer.POS1) {
|
||||
pos1 = pos1.withX(expand.x());
|
||||
p1updated = true;
|
||||
} else if (x == Closer.POS2) {
|
||||
pos2 = pos2.withX(expand.x());
|
||||
p2updated = true;
|
||||
}
|
||||
|
||||
if (y == Closer.POS1) {
|
||||
pos1 = pos1.withY(expand.y());
|
||||
p1updated = true;
|
||||
} else if (y == Closer.POS2) {
|
||||
pos2 = pos2.withY(expand.y());
|
||||
p2updated = true;
|
||||
}
|
||||
|
||||
if (z == Closer.POS1) {
|
||||
pos1 = pos1.withZ(expand.z());
|
||||
p1updated = true;
|
||||
} else if (z == Closer.POS2) {
|
||||
pos2 = pos2.withZ(expand.z());
|
||||
p2updated = true;
|
||||
}
|
||||
|
||||
if (p1updated) selectPos1(session.getRegionSelector(world), player, session, pos1);
|
||||
if (p2updated) selectPos2(session.getRegionSelector(world), player, session, pos2);
|
||||
}
|
||||
|
||||
private enum Closer {
|
||||
POS1,
|
||||
POS2,
|
||||
UNKNOWN,
|
||||
;
|
||||
|
||||
public Closer and(Closer closer) {
|
||||
if (this == closer) {
|
||||
return this;
|
||||
} else if (this == UNKNOWN) {
|
||||
return closer;
|
||||
} else if (closer == UNKNOWN) {
|
||||
return this;
|
||||
} else {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public Closer or(Closer closer) {
|
||||
if (this == UNKNOWN) return closer;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private ServerboundPickItemFromBlockPacket middleClick(Player player, ServerboundPickItemFromBlockPacket packet) {
|
||||
if (noWand(player)) return packet;
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return packet;
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
BlockPos pos = packet.pos();
|
||||
SteamEditSelectAdjacent selector = new SteamEditSelectAdjacent(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
|
||||
selectPos1(regionSelector, player, session, selector.pos1());
|
||||
selectPos2(regionSelector, player, session, selector.pos2());
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class Pos1Message implements SWPlayer.Component {
|
||||
private BukkitTask task;
|
||||
|
||||
public Pos1Message(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos1) {
|
||||
task = Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
regionSelector.explainPrimarySelection(BukkitAdapter.adapt(player), session, pos1);
|
||||
SWPlayer.of(player).removeComponent(Pos1Message.class);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPos1(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos1) {
|
||||
try {
|
||||
if (!pos1.equals(regionSelector.getPrimaryPosition())) {
|
||||
SWPlayer.of(player).setComponent(new Pos1Message(regionSelector, player, session, pos1));
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
SWPlayer.of(player).setComponent(new Pos1Message(regionSelector, player, session, pos1));
|
||||
}
|
||||
regionSelector.selectPrimary(pos1, PermissiveSelectorLimits.getInstance());
|
||||
WorldEditRenderer.renderPlayer(player);
|
||||
}
|
||||
|
||||
private static class Pos2Message implements SWPlayer.Component {
|
||||
private BukkitTask task;
|
||||
|
||||
public Pos2Message(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos2) {
|
||||
task = Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
regionSelector.explainSecondarySelection(BukkitAdapter.adapt(player), session, pos2);
|
||||
SWPlayer.of(player).removeComponent(Pos1Message.class);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPos2(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos2) {
|
||||
try {
|
||||
if (regionSelector.getVertices().size() == 2 && !pos2.equals(regionSelector.getVertices().get(1))) {
|
||||
SWPlayer.of(player).setComponent(new Pos2Message(regionSelector, player, session, pos2));
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
SWPlayer.of(player).setComponent(new Pos2Message(regionSelector, player, session, pos2));
|
||||
}
|
||||
regionSelector.selectSecondary(pos2, PermissiveSelectorLimits.getInstance());
|
||||
WorldEditRenderer.renderPlayer(player);
|
||||
}
|
||||
|
||||
private ServerboundPlayerActionPacket swapHands(Player player, ServerboundPlayerActionPacket packet) {
|
||||
if (noWand(player)) return packet;
|
||||
if (packet.getAction() != ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND) return packet;
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||
WorldEditRendererCUIEditor.open(player, true);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServerboundMovePlayerPacket movePlayerPacket(Player player, ServerboundMovePlayerPacket packet) {
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
|
||||
if (noWand(player)) {
|
||||
swPlayer.removeComponent(SWEditCursor.class);
|
||||
return packet;
|
||||
}
|
||||
|
||||
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||
Block block = result == null ? null : result.getHitBlock();
|
||||
if (result == null || block == null) {
|
||||
swPlayer.removeComponent(SWEditCursor.class);
|
||||
return packet;
|
||||
}
|
||||
|
||||
if (!swPlayer.hasComponent(SWEditCursor.class)) {
|
||||
swPlayer.setComponent(new SWEditCursor());
|
||||
}
|
||||
|
||||
swPlayer.getComponent(SWEditCursor.class).ifPresent(cursor -> {
|
||||
cursor.setLocation(block.getLocation());
|
||||
});
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2026 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
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
@@ -28,6 +28,7 @@ import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.PluginCheck;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -39,13 +40,15 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Linked
|
||||
@PluginCheck("FastAsyncWorldEdit")
|
||||
public class WorldEditRenderer implements Listener {
|
||||
|
||||
private static WorldEditRenderer INSTANCE;
|
||||
|
||||
private static final Material WAND = Material.WOODEN_AXE;
|
||||
private static final Set<Material> WANDS = Set.of(Material.WOODEN_AXE, SteamEditWand.MATERIAL);
|
||||
|
||||
private final WorldEditPlugin we;
|
||||
|
||||
@@ -102,7 +105,7 @@ public class WorldEditRenderer implements Listener {
|
||||
|
||||
private void drawCuboid(Vector min, Vector max, boolean scheduled, boolean clipboard, Player owner) {
|
||||
//noinspection deprecation
|
||||
if (owner.getItemInHand().getType() != WAND) {
|
||||
if (!WANDS.contains(owner.getItemInHand().getType())) {
|
||||
WorldEditRendererWrapper.impl.hide(owner, true, true);
|
||||
WorldEditRendererWrapper.impl.hide(owner, false, true);
|
||||
} else {
|
||||
@@ -114,7 +117,8 @@ public class WorldEditRenderer implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.getPlayer().getItemInHand().getType() == WAND) {
|
||||
//noinspection deprecation
|
||||
if (WANDS.contains(event.getPlayer().getItemInHand().getType())) {
|
||||
WorldEditRendererWrapper.impl.tick(event.getPlayer());
|
||||
}
|
||||
renderClipboard(event.getPlayer(), we.getSession(event.getPlayer()), false);
|
||||
+78
-15
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2026 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
|
||||
@@ -17,9 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.CRIUSleepEvent;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
@@ -30,6 +32,7 @@ import org.bukkit.block.data.type.Light;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -59,6 +62,7 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
public enum Type {
|
||||
SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.MEDIUM),
|
||||
CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.SLIM),
|
||||
CURSOR("cui_cursor_material", "cui_cursor_range", Material.RED_CONCRETE, Width.SLIM),
|
||||
;
|
||||
|
||||
private final Map<Player, Material> materialCache = new HashMap<>();
|
||||
@@ -104,19 +108,27 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum Width {
|
||||
HUGE(15, "WORLDEDIT_CUI_WIDTH_HUGE", 2 / 16f),
|
||||
LARGE(8, "WORLDEDIT_CUI_WIDTH_LARGE", 1 / 16f),
|
||||
MEDIUM(4, "WORLDEDIT_CUI_WIDTH_MEDIUM", 1 / 32f),
|
||||
SLIM(0, "WORLDEDIT_CUI_WIDTH_SLIM", 1 / 64f);
|
||||
HUGE(15, "WORLDEDIT_CUI_WIDTH_HUGE", 1 / 8f, 40),
|
||||
LARGE(8, "WORLDEDIT_CUI_WIDTH_LARGE", 1 / 16f, 30),
|
||||
MEDIUM(4, "WORLDEDIT_CUI_WIDTH_MEDIUM", 1 / 32f, 20),
|
||||
SLIM(0, "WORLDEDIT_CUI_WIDTH_SLIM", 1 / 64f, 10);
|
||||
|
||||
public final int lightLevel;
|
||||
public final String name;
|
||||
public final float value;
|
||||
public final float width;
|
||||
public final int blocks;
|
||||
}
|
||||
|
||||
private static Command command = null;
|
||||
|
||||
public WorldEditRendererCUIEditor() {
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
new Command();
|
||||
command = new Command();
|
||||
}
|
||||
|
||||
public static void open(Player player, boolean steamEditWand) {
|
||||
if (command == null) return;
|
||||
command.cuiEditor(player, steamEditWand);
|
||||
}
|
||||
|
||||
private static class Command extends SWCommand {
|
||||
@@ -127,18 +139,44 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
|
||||
@Register
|
||||
public void cuiEditor(Player player) {
|
||||
cuiEditor(player, false);
|
||||
}
|
||||
|
||||
public void cuiEditor(Player player, boolean steamEditWand) {
|
||||
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player));
|
||||
setElement(inv, player, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
if (SteamEdit.isInitialized() && steamEditWand) {
|
||||
setElement(inv, player, true, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, true, 2, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
setCursor(inv, player, 3, "WORLDEDIT_CUI_CURSOR");
|
||||
inv.setItem(5, new SWItem(Material.PAPER, "WORLDEDIT_CUI_TOOL_COPY").setLore("WORLDEDIT_CUI_TOOL_COPY_LORE").translate(player, Core.MESSAGE).getItemStack(), click -> {
|
||||
player.performCommand("/copy");
|
||||
});
|
||||
inv.setItem(6, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
inv.setItem(7, new SWItem(Material.GRASS_BLOCK, "WORLDEDIT_CUI_TOOL_PASTE").setLore("WORLDEDIT_CUI_TOOL_PASTE_LORE_1", "WORLDEDIT_CUI_TOOL_PASTE_LORE_2", "WORLDEDIT_CUI_TOOL_PASTE_LORE_3").translate(player, Core.MESSAGE).getItemStack(), click -> {
|
||||
if (click == ClickType.DROP) {
|
||||
player.performCommand("/paste -o");
|
||||
} else if (click == ClickType.SHIFT_LEFT || click == ClickType.SHIFT_RIGHT) {
|
||||
player.performCommand("/paste -s");
|
||||
} else if (click == ClickType.LEFT || click == ClickType.RIGHT) {
|
||||
player.performCommand("/paste");
|
||||
}
|
||||
});
|
||||
inv.setItem(14, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
inv.setItem(15, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
inv.setItem(16, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
} else {
|
||||
setElement(inv, player, false, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, false, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
}
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private void setElement(SWInventory inv, Player player, int index, String uiName, Type type) {
|
||||
private void setElement(SWInventory inv, Player player, boolean steamEditWand, int index, String uiName, Type type) {
|
||||
Material material = type.getMaterial(player);
|
||||
Width width = type.getWidth(player);
|
||||
|
||||
inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> {
|
||||
cuiMaterial(player, uiName, type, material);
|
||||
cuiMaterial(player, steamEditWand, uiName, type, material);
|
||||
}));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
@@ -153,7 +191,7 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
}
|
||||
SWItem lightItem = new SWItem(Material.LIGHT, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> {
|
||||
type.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]);
|
||||
setElement(inv, player, index, uiName, type);
|
||||
setElement(inv, player, steamEditWand, index, uiName, type);
|
||||
});
|
||||
ItemMeta itemMeta = lightItem.getItemMeta();
|
||||
Light light = (Light) Material.LIGHT.createBlockData();
|
||||
@@ -163,16 +201,41 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
inv.setItem(index + 9, lightItem);
|
||||
}
|
||||
|
||||
private void setCursor(SWInventory inv, Player player, int index, String uiName) {
|
||||
Material material = Type.CURSOR.getMaterial(player);
|
||||
Width width = Type.CURSOR.getWidth(player);
|
||||
|
||||
inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> {
|
||||
cuiMaterial(player, true, uiName, Type.CURSOR, material);
|
||||
}));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_CLICK", player));
|
||||
lore.add("");
|
||||
for (Width value : Width.values()) {
|
||||
if (value == width) {
|
||||
lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE_SELECTED", player, Core.MESSAGE.parse(value.name + "_DIST", player)));
|
||||
} else {
|
||||
lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE", player, Core.MESSAGE.parse(value.name + "_DIST", player)));
|
||||
}
|
||||
}
|
||||
SWItem stickItem = new SWItem(Material.STICK, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME_DIST", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> {
|
||||
Type.CURSOR.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]);
|
||||
setCursor(inv, player, index, uiName);
|
||||
}).setCustomModelData(1);
|
||||
inv.setItem(index + 9, stickItem);
|
||||
}
|
||||
|
||||
private final Material[] materials = {Material.WHITE_CONCRETE, Material.LIGHT_GRAY_CONCRETE, Material.GRAY_CONCRETE, Material.BLACK_CONCRETE, Material.BROWN_CONCRETE, Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE, Material.LIME_CONCRETE, Material.GREEN_CONCRETE, Material.CYAN_CONCRETE, Material.LIGHT_BLUE_CONCRETE, Material.BLUE_CONCRETE, Material.PURPLE_CONCRETE, Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE, null, Material.BARRIER};
|
||||
|
||||
private void cuiMaterial(Player player, String subMenu, Type type, Material currentSelection) {
|
||||
private void cuiMaterial(Player player, boolean steamEditWand, String subMenu, Type type, Material currentSelection) {
|
||||
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE_SUBMENU", player, Core.MESSAGE.parse(subMenu, player)));
|
||||
for (int i = 0; i < materials.length; i++) {
|
||||
Material material = materials[i];
|
||||
if (material == null) continue;
|
||||
inv.setItem(i, new SWItem(material, "", Collections.emptyList(), material == currentSelection, click -> {
|
||||
type.setMaterial(player, material);
|
||||
cuiEditor(player);
|
||||
cuiEditor(player, steamEditWand);
|
||||
}));
|
||||
}
|
||||
inv.open();
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
+4
-3
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2026 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
|
||||
@@ -17,8 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import de.steamwar.core.PlayerVersion;
|
||||
import de.steamwar.entity.CWireframe;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import org.bukkit.Material;
|
||||
@@ -82,7 +83,7 @@ public class WorldEditRendererWrapper {
|
||||
});
|
||||
|
||||
WorldEditRendererCUIEditor.Type type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD : WorldEditRendererCUIEditor.Type.SELECTION;
|
||||
float width = type.getWidth(player).value;
|
||||
float width = type.getWidth(player).width;
|
||||
Material material = type.getMaterial(player);
|
||||
if (material == Material.BARRIER) {
|
||||
hide(player, clipboard, true);
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2026 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
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV2;
|
||||
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV3;
|
||||
@@ -34,6 +34,7 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.NodeData;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -1,20 +1,14 @@
|
||||
package de.steamwar.cursor;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@Linked
|
||||
public class CursorListener implements Listener {
|
||||
@@ -26,10 +20,6 @@ public class CursorListener implements Listener {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::updateCursorFromPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::updateCursorFromPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::updateCursorFromPacket);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
SWPlayer.allWithSingleComponent(Cursor.class)
|
||||
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
||||
@@ -37,15 +27,6 @@ public class CursorListener implements Listener {
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
public Packet<?> updateCursorFromPacket(Player player, Packet<?> packet) {
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
||||
|
||||
activeCursor.ifPresent(Cursor::renderDeduplicated);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
||||
|
||||
@@ -22,10 +22,12 @@ package de.steamwar.inventory;
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.message.Message;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -225,4 +227,14 @@ public class SWItem {
|
||||
itemStack.setAmount(count);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWItem translate(Player player, Message message) {
|
||||
setName(message.parse(itemMeta.getDisplayName(), player));
|
||||
if (itemMeta.hasLore()) {
|
||||
setLore(itemMeta.getLore().stream()
|
||||
.map(s -> message.parse(s, player))
|
||||
.toList());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SQLWrapperImpl implements SQLWrapper<Material> {
|
||||
@@ -52,6 +55,45 @@ public class SQLWrapperImpl implements SQLWrapper<Material> {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage-type inventory materials (chests, barrels, shulker boxes of any color).
|
||||
*/
|
||||
private static final Set<Material> STORAGE_MATERIALS = Collections.unmodifiableSet(EnumSet.of(
|
||||
Material.CHEST, Material.TRAPPED_CHEST, Material.BARREL, Material.SHULKER_BOX,
|
||||
Material.WHITE_SHULKER_BOX, Material.ORANGE_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX,
|
||||
Material.YELLOW_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.PINK_SHULKER_BOX, Material.GRAY_SHULKER_BOX,
|
||||
Material.LIGHT_GRAY_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.BLUE_SHULKER_BOX,
|
||||
Material.BROWN_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.BLACK_SHULKER_BOX
|
||||
));
|
||||
|
||||
/**
|
||||
* Every inventory material - {@link #STORAGE_MATERIALS} plus the "functional" containers that
|
||||
* are not storage (dispenser, dropper, hopper, the furnace family, brewing stand, campfire,
|
||||
* jukebox). Built on top of {@link #STORAGE_MATERIALS} so anything added there is automatically
|
||||
* included here.
|
||||
*/
|
||||
private static final Set<Material> INVENTORY_MATERIALS;
|
||||
|
||||
static {
|
||||
Set<Material> materials = EnumSet.copyOf(STORAGE_MATERIALS);
|
||||
materials.addAll(EnumSet.of(
|
||||
Material.DISPENSER, Material.DROPPER, Material.HOPPER,
|
||||
Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER,
|
||||
Material.BREWING_STAND, Material.CAMPFIRE, Material.JUKEBOX
|
||||
));
|
||||
INVENTORY_MATERIALS = Collections.unmodifiableSet(materials);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> getStorageMaterials() {
|
||||
return STORAGE_MATERIALS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> getInventoryMaterials() {
|
||||
return INVENTORY_MATERIALS;
|
||||
}
|
||||
|
||||
private static final String SERVER_VERSION = Bukkit.getServer().getVersion();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.core.WorldEditWrapper;
|
||||
import de.steamwar.core.worldedit.WorldEditWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
package de.steamwar.teamserver;
|
||||
|
||||
import de.steamwar.core.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.core.worldedit.SteamEdit;
|
||||
import de.steamwar.core.worldedit.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.linkage.AbstractLinker;
|
||||
import de.steamwar.linkage.SpigotLinker;
|
||||
import de.steamwar.message.Message;
|
||||
@@ -51,7 +52,7 @@ public final class Builder extends JavaPlugin {
|
||||
}
|
||||
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||
new WorldEditRendererCUIEditor();
|
||||
SteamEdit.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -138,14 +138,16 @@ public class Subserver {
|
||||
writer.println(command);
|
||||
}
|
||||
|
||||
private ProcessHandle serverProcess() {
|
||||
if (checkpoint) {
|
||||
return process.children().findAny().orElseGet(process::toHandle);
|
||||
}
|
||||
return process.toHandle();
|
||||
}
|
||||
|
||||
public void sleep() {
|
||||
try {
|
||||
long pid = process.pid();
|
||||
if (checkpoint) {
|
||||
pid = process.children().findAny().map(ProcessHandle::pid).orElse(pid);
|
||||
}
|
||||
|
||||
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(pid)});
|
||||
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(serverProcess().pid())});
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Failed to send SIGUSR1 to subserver.", e);
|
||||
}
|
||||
@@ -162,7 +164,7 @@ public class Subserver {
|
||||
|
||||
public void stop() {
|
||||
try {
|
||||
process.destroy();
|
||||
serverProcess().destroy();
|
||||
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
||||
forceStop();
|
||||
} else if (thread.isAlive()) {
|
||||
@@ -177,6 +179,7 @@ public class Subserver {
|
||||
public void forceStop() {
|
||||
try {
|
||||
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
|
||||
serverProcess().destroyForcibly();
|
||||
process.destroyForcibly();
|
||||
|
||||
if (thread.isAlive()) thread.join();
|
||||
|
||||
@@ -202,12 +202,6 @@ NOFIGHTSERVER_UNTIL = §7You are excluded from §e§lfighting§7 §euntil {0}§8
|
||||
UNNOFIGHTSERVER_ERROR = §cThe player is not excluded from fighting.
|
||||
UNNOFIGHTSERVER = §e{0} §7may now join §e§lfights§7 again§8.
|
||||
|
||||
NOTEAMSERVER_TEAM = §e{0} §7was excluded from §e{1} {2} §7from §e§lteam servers§8: §f{3}
|
||||
NOTEAMSERVER_PERMA = §7You are §epermanently§7 excluded from §e§lteam servers§8: §e{0}
|
||||
NOTEAMSERVER_UNTIL = §7You are excluded from §e§lteam servers§7 §euntil {0}§8: §e{1}
|
||||
UNNOTEAMSERVER_ERROR = §cThe player is not excluded from team servers.
|
||||
UNNOTEAMSERVER = §e{0} §7may now set §e§lteam servers§7 again§8.
|
||||
|
||||
NOTE_TEAM = §e{0} §7received a §e§lnote§7 from §e{1} {2}: §f{3}
|
||||
|
||||
#BugCommand
|
||||
@@ -271,7 +265,8 @@ CHALLENGE_ACCEPT_HOVER = §aAccept challenge
|
||||
#EventCommand
|
||||
EVENT_TIME_FORMAT = HH:mm
|
||||
EVENT_DATE_FORMAT = dd.MM.
|
||||
EVENT_USAGE = §8/§7event §8[§eTeam§8] - §7To teleport to a fight
|
||||
EVENT_TEAM_USAGE = §8/§7event team §8[§eTeam§8] - §7To teleport to a fight
|
||||
EVENT_SHOW_FIGHTS_USAGE = §8/§7event showfights §8[§eEvent§8] - §7To show the fights of that Event
|
||||
EVENT_NO_TEAM = §cThis team does not exist
|
||||
EVENT_NO_FIGHT_TEAM = §cThis team has no current fight
|
||||
EVENT_NO_CURRENT = §cThere is no event taking place currently
|
||||
@@ -282,9 +277,13 @@ EVENT_COMING_SCHEM_DEADLINE = §7 Submission deadline§8: §7{0}
|
||||
EVENT_COMING_TEAMS = §7 With§8: {0}
|
||||
EVENT_COMING_TEAM = §{0}{1}
|
||||
EVENT_CURRENT_EVENT = §e§l{0}
|
||||
EVENT_CURRENT_FIGHT = §7{0} §{1}{2}§8 vs §{3}{4}
|
||||
EVENT_CURRENT_FIGHT_1 = §7{0} §{1}{2}
|
||||
EVENT_CURRENT_FIGHT_VS = '§8 vs '
|
||||
EVENT_CURRENT_FIGHT_2 = §{0}{1}
|
||||
EVENT_CURRENT_FIGHT_WIN = §8: §7Victory §{0}{1}
|
||||
EVENT_CURRENT_FIGHT_DRAW = §8: §7Draw
|
||||
EVENT_TEAM_TABLE = §{0}{1}{2} §8 with §e{3} §7points
|
||||
EVENT_SHOW_TABLE_USAGE = §8/§7event showtable §8[§eEvent§8] - §7To show the table of that Event
|
||||
|
||||
#EventRescheduleCommand
|
||||
EVENTRESCHEDULE_USAGE = §8/§7eventreschedule §8[§eTeam1§8] [§eTeam2§8]
|
||||
@@ -751,3 +750,9 @@ DC_SCHEMUPLOAD_IGNORED = Skipping `{0}`, not a schematic file.
|
||||
DC_SCHEMUPLOAD_INVCHAR = `{0}` has invalid characters in its name.
|
||||
DC_SCHEMUPLOAD_SUCCESS = `{0}` was uploaded successfully.
|
||||
DC_SCHEMUPLOAD_ERROR = An error has occured during the upload of `{0}`. For more information ask a Developer.
|
||||
|
||||
UTIL_LIST_BACK_ARROW = §8««
|
||||
UTIL_LIST_BACK_ARROW_HOVER = §ePrevious page
|
||||
UTIL_LIST_PAGE = §e Page §7({0}/{1})
|
||||
UTIL_LIST_NEXT = §8 »»
|
||||
UTIL_LIST_NEXT_HOVER = §eNext page
|
||||
@@ -184,12 +184,6 @@ NOFIGHTSERVER_UNTIL = §7Du bist §ebis zum {0} §7vom §e§lKämpfen§7 ausgesc
|
||||
UNNOFIGHTSERVER_ERROR = §cDer Spieler ist nicht vom Kämpfen ausgeschlossen.
|
||||
UNNOFIGHTSERVER = §e{0} §7darf nun wieder §e§lKämpfen§7 beitreten§8.
|
||||
|
||||
NOTEAMSERVER_TEAM = §e{0} §7wurde von §e{1} {2} §7vom §e§lTeamserver§7 setzen ausgeschlossen§8: §f{3}
|
||||
NOTEAMSERVER_PERMA = §7Du bist §epermanent §7vom §e§lTeamserver§7 setzen ausgeschlossen§8: §e{0}
|
||||
NOTEAMSERVER_UNTIL = §7Du bist §ebis zum {0} §7vom §e§lTeamserver§7 setzen ausgeschlossen§8: §e{1}
|
||||
UNNOTEAMSERVER_ERROR = §cDer Spieler ist nicht vom Teamserver setzten ausgeschlossen.
|
||||
UNNOTEAMSERVER = §e{0} §7darf nun wieder §e§lTeamserver§7 setzen§8.
|
||||
|
||||
NOTE_TEAM = §e{0} §7erhielt von §e{1} {2} §7die §e§lNotiz§7§8: §f{3}
|
||||
|
||||
#BugCommand
|
||||
@@ -253,7 +247,8 @@ CHALLENGE_ACCEPT_HOVER = §aHerausforderung annehmen
|
||||
#EventCommand
|
||||
EVENT_TIME_FORMAT = HH:mm
|
||||
EVENT_DATE_FORMAT = dd.MM.
|
||||
EVENT_USAGE = §8/§7event §8[§eTeam§8] - §7Um dich zum Kampf zu teleportieren
|
||||
EVENT_TEAM_USAGE=§8/§7event team §8[§eTeam§8] - §7Um dich zum Kampf zu teleportieren
|
||||
EVENT_SHOW_FIGHTS_USAGE = §8/§7event showfights §8[§eEvent§8] - §7Um die fights des Events zu zeigen
|
||||
EVENT_NO_TEAM = §cDieses Team gibt es nicht
|
||||
EVENT_NO_FIGHT_TEAM = §cDas Team kämpft derzeit nicht
|
||||
EVENT_NO_CURRENT = §cDerzeit findet kein Event statt
|
||||
@@ -264,9 +259,10 @@ EVENT_COMING_SCHEM_DEADLINE = §7 Einsendeschluss§8: §7{0}
|
||||
EVENT_COMING_TEAMS = §7 Mit§8: {0}
|
||||
EVENT_COMING_TEAM = §{0}{1}
|
||||
EVENT_CURRENT_EVENT = §e§l{0}
|
||||
EVENT_CURRENT_FIGHT = §7{0} §{1}{2}§8 vs §{3}{4}
|
||||
EVENT_CURRENT_FIGHT_WIN = §8: §7Sieg §{0}{1}
|
||||
EVENT_CURRENT_FIGHT_DRAW = §8: §7Unentschieden
|
||||
EVENT_TEAM_TABLE = §{0}{1}{2} §8 mit §e{3} §7Punkten
|
||||
EVENT_SHOW_TABLE_USAGE = §8/§7event showtable §8[§eEvent§8] - §7Um die Tabelle des Events zu zeigen.
|
||||
|
||||
#EventRescheduleCommand
|
||||
EVENTRESCHEDULE_USAGE = §8/§7eventreschedule §8[§eTeam1§8] [§eTeam2§8]
|
||||
|
||||
@@ -86,7 +86,7 @@ public class EventStarter {
|
||||
}
|
||||
}).start();
|
||||
|
||||
command = "/event " + blue.getTeamKuerzel();
|
||||
command = "/event team " + blue.getTeamKuerzel();
|
||||
} else {
|
||||
command = "/" + spectatePorts.get(next.getSpectatePort());
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ServerStarter {
|
||||
public static final String WORLDS_BASE_PATH = WORLDS_FOLDER + "/userworlds";
|
||||
public static final String BUILDER_BASE_PATH = WORLDS_FOLDER + "/builder";
|
||||
|
||||
private static final String WORLDS_STORAGE_BASE_PATH = "/mnt/storage/worlds/userworlds";
|
||||
public static final String WORLDS_STORAGE_BASE_PATH = "/mnt/storage/worlds/userworlds";
|
||||
|
||||
private File directory = null;
|
||||
private String worldDir = null;
|
||||
|
||||
@@ -149,7 +149,6 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
new PunishmentCommand("noschemsubmitting", Punishment.PunishmentType.NoSchemSubmitting);
|
||||
new PunishmentCommand("nodev", Punishment.PunishmentType.NoDevServer);
|
||||
new PunishmentCommand("nofight", Punishment.PunishmentType.NoFightServer);
|
||||
new PunishmentCommand("noteamserver", Punishment.PunishmentType.NoTeamServer);
|
||||
new PunishmentCommand("note", Punishment.PunishmentType.Note);
|
||||
|
||||
linker = new AbstractLinker<>(this) {
|
||||
|
||||
@@ -44,6 +44,7 @@ import de.steamwar.velocitycore.inventory.SWItem;
|
||||
import de.steamwar.velocitycore.network.NetworkSender;
|
||||
import de.steamwar.velocitycore.util.BauLock;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -187,11 +188,35 @@ public class BauCommand extends SWCommand {
|
||||
bauserver.getRegisteredServer().getPlayersConnected().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket()));
|
||||
}
|
||||
|
||||
try {
|
||||
deletePlayerData(owner, user);
|
||||
} catch (Exception e) {
|
||||
// Ignore this silently since it does not matter in any way if the data is not deleted properly.
|
||||
}
|
||||
|
||||
member.system("BAU_DELMEMBER_DELETED_TARGET", owner);
|
||||
owner.system("BAU_DELMEMBER_DELETED");
|
||||
});
|
||||
}
|
||||
|
||||
private void deletePlayerData(Chatter owner, SteamwarUser user) {
|
||||
String worldName = String.valueOf(owner.user().getId());
|
||||
String targetDat = user.getUUID().toString().toLowerCase() + ".dat";
|
||||
String targetDatOld = user.getUUID().toString().toLowerCase() + ".dat_old";
|
||||
for (ServerVersion version : ServerVersion.values()) {
|
||||
File playerData = new File(new File(version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH), worldName), "playerdata");
|
||||
if (playerData.exists()) {
|
||||
new File(playerData, targetDat).delete();
|
||||
new File(playerData, targetDatOld).delete();
|
||||
}
|
||||
File playerDataStorage = new File(new File(version.getWorldFolder(ServerStarter.WORLDS_STORAGE_BASE_PATH), worldName), "playerdata");
|
||||
if (playerDataStorage.exists()) {
|
||||
new File(playerDataStorage, targetDat).delete();
|
||||
new File(playerDataStorage, targetDatOld).delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Mapper(value = "addedUsers", local = true)
|
||||
public TypeMapper<SteamwarUser> addedUsers() {
|
||||
return new TypeMapper<SteamwarUser>() {
|
||||
|
||||
@@ -85,7 +85,6 @@ public class CheckCommand extends SWCommand {
|
||||
if (user.perms().contains(UserPerm.CHECK)) return true;
|
||||
return GameModeConfig.getAll()
|
||||
.stream()
|
||||
.filter(GameModeConfig::isActive)
|
||||
.anyMatch(gameMode -> gameMode.Checkers.contains(user.getId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import de.steamwar.persistent.Subserver;
|
||||
import de.steamwar.sql.*;
|
||||
import de.steamwar.velocitycore.EventStarter;
|
||||
import de.steamwar.velocitycore.SubserverSystem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
@@ -82,35 +84,84 @@ public class EventCommand extends SWCommand {
|
||||
|
||||
@Register
|
||||
public void eventOverview(@Validator(value = "noEvent", invert = true) Chatter sender) {
|
||||
sender.system("EVENT_USAGE");
|
||||
sender.system("EVENT_TEAM_USAGE");
|
||||
|
||||
Event currentEvent = Event.get();
|
||||
sender.system("EVENT_CURRENT_EVENT", currentEvent.getEventName());
|
||||
eventShowFightsPage(sender, currentEvent, 1);
|
||||
}
|
||||
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_TIME_FORMAT"));
|
||||
for (EventFight fight : EventFight.getEvent(currentEvent.getEventID())) {
|
||||
Team blue = Team.byId(fight.getTeamBlue());
|
||||
Team red = Team.byId(fight.getTeamRed());
|
||||
StringBuilder fline = new StringBuilder(sender.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel()));
|
||||
// @Register(value = "showtable", description = "EVENT_SHOW_TABLE_USAGE")
|
||||
public void eventtable(Chatter sender, Event event) {
|
||||
if (!Instant.now().isBefore(event.getEnd().toInstant())) return;
|
||||
|
||||
if (fight.hasFinished()) {
|
||||
switch (fight.getErgebnis()) {
|
||||
Map<Integer, Integer> Teampoints = new HashMap<>();
|
||||
|
||||
EventFight.getEvent(event.getEventID()).forEach(eventFight -> {
|
||||
if (eventFight.hasFinished() && eventFight.getGroup().isPresent()) {
|
||||
switch (eventFight.getErgebnis()) {
|
||||
case 1:
|
||||
fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel()));
|
||||
//win blue
|
||||
Teampoints.put(eventFight.getTeamBlue(), Teampoints.getOrDefault(eventFight.getTeamBlue(), 0) + eventFight.getGroup().get().getPointsPerWin());
|
||||
Teampoints.put(eventFight.getTeamRed(), Teampoints.getOrDefault(eventFight.getTeamRed(),0) + eventFight.getGroup().get().getPointsPerLoss());
|
||||
break;
|
||||
case 2:
|
||||
fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel()));
|
||||
//win red
|
||||
Teampoints.put(eventFight.getTeamBlue(), Teampoints.getOrDefault(eventFight.getTeamBlue(),0) + eventFight.getGroup().get().getPointsPerLoss());
|
||||
Teampoints.put(eventFight.getTeamRed(), Teampoints.getOrDefault(eventFight.getTeamRed(),0) + eventFight.getGroup().get().getPointsPerWin());
|
||||
break;
|
||||
default:
|
||||
fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW"));
|
||||
//draw
|
||||
Teampoints.put(eventFight.getTeamBlue(), Teampoints.getOrDefault(eventFight.getTeamBlue(),0) + eventFight.getGroup().get().getPointsPerDraw());
|
||||
Teampoints.put(eventFight.getTeamRed(), Teampoints.getOrDefault(eventFight.getTeamRed(),0) + eventFight.getGroup().get().getPointsPerDraw());
|
||||
}
|
||||
}
|
||||
});
|
||||
Map<Integer, Integer> Teampointssortet = Teampoints.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByValue())
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
Map.Entry::getValue,
|
||||
(a , b) -> a,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
|
||||
sender.prefixless("PLAIN_STRING", fline.toString());
|
||||
for (Map.Entry<Integer, Integer> entry : Teampointssortet.entrySet()) {
|
||||
Component finalmessage = sender.parse("EVENT_TEAM_TABLE",Team.byId(entry.getKey()).getTeamColor(), Team.byId(entry.getKey()).getTeamKuerzel(), Team.byId(entry.getKey()).getTeamName(), entry.getValue());
|
||||
finalmessage = finalmessage.clickEvent(ClickEvent.runCommand("/team info " + Team.byId(entry.getKey()).getTeamName()));
|
||||
sender.sendMessage(finalmessage);
|
||||
}
|
||||
}
|
||||
|
||||
@Register
|
||||
@Register(value = "showfights", description = "EVENT_SHOW_FIGHTS_USAGE")
|
||||
public void eventShowFightsPage(Chatter sender, Event event, @AllowNull @OptionalValue("1") int page) {
|
||||
if (!Instant.now().isBefore(event.getEnd().toInstant())) return;
|
||||
int pagecount = sendEventPage(sender, event, page);
|
||||
|
||||
Integer nextpage = page + 1;
|
||||
Integer prevpage = page - 1;
|
||||
|
||||
Component finalmessage;
|
||||
|
||||
Component pagenumber = sender.parse("UTIL_LIST_PAGE", page, pagecount);
|
||||
|
||||
if (pagecount != 0 && page != 1) {
|
||||
finalmessage = sender.parse("UTIL_LIST_BACK_ARROW");
|
||||
finalmessage = finalmessage.clickEvent(ClickEvent.runCommand("/event showfights " + event.getEventName() + " " + prevpage));
|
||||
finalmessage = finalmessage.append(pagenumber);
|
||||
} else {
|
||||
finalmessage = pagenumber;
|
||||
}
|
||||
|
||||
if (pagecount != 0 && pagecount > page) {
|
||||
Component nextbutton = sender.parse("UTIL_LIST_NEXT");
|
||||
nextbutton = nextbutton.clickEvent(ClickEvent.runCommand("/event showfights " + event.getEventName() + " " + nextpage));
|
||||
finalmessage = finalmessage.append(nextbutton);
|
||||
}
|
||||
sender.sendMessage(finalmessage);
|
||||
}
|
||||
|
||||
@Register(value = "team", description = "EVENT_TEAM_USAGE")
|
||||
public void eventWithTeam(@Validator(value = "noEvent", invert = true) PlayerChatter sender, @ErrorMessage("EVENT_NO_TEAM") Team team) {
|
||||
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
|
||||
if (eventArena == null || !Subserver.getServerList().contains(eventArena)) {
|
||||
@@ -122,6 +173,69 @@ public class EventCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private int sendEventPage(Chatter sender, Event event, int page) {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_DATE_FORMAT"));
|
||||
Map<String, List<EventFight>> dates = EventFight.getEvent(event.getEventID()).stream().collect(Collectors.groupingBy(p -> p.getStartTime().toLocalDateTime().format(dateTimeFormatter)));
|
||||
if (dates.size() >= page) {
|
||||
sender.system("EVENT_CURRENT_EVENT", event.getEventName());
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_TIME_FORMAT"));
|
||||
for (EventFight eventFight : dates.get(dates.keySet().toArray()[page - 1])) {
|
||||
Team blue = Team.byId(eventFight.getTeamBlue());
|
||||
Team red = Team.byId(eventFight.getTeamRed());
|
||||
Component finalfightline = sender.parse("EVENT_CURRENT_FIGHT_1", eventFight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel());
|
||||
finalfightline = finalfightline.clickEvent(ClickEvent.runCommand("/team info " + blue.getTeamName()));
|
||||
Component vs = sender.parse("EVENT_CURRENT_FIGHT_VS");
|
||||
finalfightline = finalfightline.append(vs);
|
||||
Component redteam = sender.parse("EVENT_CURRENT_FIGHT_2", red.getTeamColor(), red.getTeamKuerzel());
|
||||
redteam = redteam.clickEvent(ClickEvent.runCommand("/team info " + red.getTeamName()));
|
||||
finalfightline = finalfightline.append(redteam);
|
||||
|
||||
if (eventFight.hasFinished()) {
|
||||
Component ergebnis;
|
||||
switch (eventFight.getErgebnis()) {
|
||||
case 1:
|
||||
ergebnis = sender.parse("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel());
|
||||
break;
|
||||
case 2:
|
||||
ergebnis = sender.parse("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel());
|
||||
break;
|
||||
default:
|
||||
ergebnis = sender.parse("EVENT_CURRENT_FIGHT_DRAW");
|
||||
}
|
||||
finalfightline = finalfightline.append(ergebnis);
|
||||
}
|
||||
sender.sendMessage(finalfightline);
|
||||
}
|
||||
}
|
||||
return dates.size();
|
||||
}
|
||||
|
||||
protected static TypeMapper<Event> eventTypeMapper() {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public Event map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
return Event.get(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
Set<String> events = new HashSet<>();
|
||||
List<Event> allevents = Event.getAll();
|
||||
for (Event event : allevents) {
|
||||
if (!Instant.now().isAfter(event.getEnd().toInstant())) {
|
||||
events.add(event.getEventName());
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassMapper(value = Event.class, local = true)
|
||||
public TypeMapper<Event> eventMapper() {
|
||||
return eventTypeMapper();
|
||||
}
|
||||
|
||||
protected static TypeMapper<Team> eventTeam(Function<EventFight, List<Integer>> teamMapper) {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
|
||||
@@ -287,6 +287,10 @@ public class TeamCommand extends SWCommand {
|
||||
|
||||
@Register(value = "info", description = "TEAM_INFO_USAGE")
|
||||
public void info(Chatter sender, @ErrorMessage("UNKNOWN_TEAM") Team team) {
|
||||
if (team.getMembers().isEmpty()) {
|
||||
sender.system("UNKNOWN_TEAM");
|
||||
return;
|
||||
}
|
||||
List<SteamwarUser> users = team.getMembers().stream().map(SteamwarUser::byId).toList();
|
||||
|
||||
sender.system("TEAM_INFO_TEAM", team.getTeamName(), team.getTeamColor(), team.getTeamKuerzel());
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.util.ServerLink;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
@@ -45,9 +46,7 @@ import de.steamwar.velocitycore.mods.ModUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Linked
|
||||
@@ -79,9 +78,27 @@ public class ConnectionListener extends BasicListener {
|
||||
});
|
||||
}
|
||||
|
||||
private static final List<ServerLink> SERVER_LINKS = getServerLinks();
|
||||
|
||||
private static List<ServerLink> getServerLinks() {
|
||||
List<ServerLink> serverLinks = new ArrayList<>();
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.BUG_REPORT, "https://git.steamwar.de/SteamWar/SteamWar/issues/new"));
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.COMMUNITY_GUIDELINES, "https://steamwar.de/verhaltensrichtlinien/"));
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.SUPPORT, "https://discord.com/channels/690530484920385586/870028487455571999"));
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.COMMUNITY, "https://steamwar.de/discord"));
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.WEBSITE, "https://steamwar.de/"));
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.NEWS, "https://discord.com/channels/690530484920385586/690535200865910794"));
|
||||
serverLinks.add(ServerLink.serverLink(ServerLink.Type.ANNOUNCEMENTS, "https://discord.com/channels/690530484920385586/690535200865910794"));
|
||||
return serverLinks;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21)) {
|
||||
player.setServerLinks(SERVER_LINKS);
|
||||
}
|
||||
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
Chatter chatter = Chatter.of(player);
|
||||
CheckCommand.sendReminder(chatter);
|
||||
|
||||
@@ -39,22 +39,28 @@ public class TexturePackSystem extends BasicListener {
|
||||
|
||||
private static final File PACKS_DIR = new File("/var/www/packs");
|
||||
private static final String BASE_ULR = "https://packs.steamwar.de/";
|
||||
private TreeMap<Integer, Integer> protocolVersionToPackVersion = new TreeMap<>();
|
||||
private TreeMap<Integer, String> protocolVersionToPackVersion = new TreeMap<>();
|
||||
|
||||
public TexturePackSystem() {
|
||||
// https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats
|
||||
// https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers
|
||||
protocolVersionToPackVersion.put(759, 9);
|
||||
protocolVersionToPackVersion.put(761, 12);
|
||||
protocolVersionToPackVersion.put(762, 13);
|
||||
protocolVersionToPackVersion.put(763, 15);
|
||||
protocolVersionToPackVersion.put(764, 18);
|
||||
protocolVersionToPackVersion.put(765, 22);
|
||||
protocolVersionToPackVersion.put(766, 32);
|
||||
protocolVersionToPackVersion.put(767, 34);
|
||||
protocolVersionToPackVersion.put(768, 42);
|
||||
protocolVersionToPackVersion.put(769, 46);
|
||||
protocolVersionToPackVersion.put(770, 55);
|
||||
protocolVersionToPackVersion.put(759, "9");
|
||||
protocolVersionToPackVersion.put(761, "12");
|
||||
protocolVersionToPackVersion.put(762, "13");
|
||||
protocolVersionToPackVersion.put(763, "15");
|
||||
protocolVersionToPackVersion.put(764, "18");
|
||||
protocolVersionToPackVersion.put(765, "22");
|
||||
protocolVersionToPackVersion.put(766, "32");
|
||||
protocolVersionToPackVersion.put(767, "34");
|
||||
protocolVersionToPackVersion.put(768, "42");
|
||||
protocolVersionToPackVersion.put(769, "46");
|
||||
protocolVersionToPackVersion.put(770, "55");
|
||||
protocolVersionToPackVersion.put(771, "63");
|
||||
protocolVersionToPackVersion.put(772, "64");
|
||||
protocolVersionToPackVersion.put(773, "69.0");
|
||||
protocolVersionToPackVersion.put(774, "75.0");
|
||||
protocolVersionToPackVersion.put(775, "84.0");
|
||||
protocolVersionToPackVersion.put(776, "88.0");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -63,20 +69,19 @@ public class TexturePackSystem extends BasicListener {
|
||||
return;
|
||||
}
|
||||
VelocityCore.schedule(() -> {
|
||||
TreeMap<Integer, File> fileTreeMap = new TreeMap<>();
|
||||
TreeMap<String, File> fileTreeMap = new TreeMap<>();
|
||||
for (File fileEntry : PACKS_DIR.listFiles()) {
|
||||
try {
|
||||
int packVersion = Integer.parseInt(fileEntry.getName().split("_")[0]);
|
||||
fileTreeMap.put(packVersion, fileEntry);
|
||||
fileTreeMap.put(fileEntry.getName().split("_")[0], fileEntry);
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
int playerVersion = event.getPlayer().getProtocolVersion().getProtocol();
|
||||
Map.Entry<Integer, Integer> packVersionEntry = protocolVersionToPackVersion.floorEntry(playerVersion);
|
||||
Map.Entry<Integer, String> packVersionEntry = protocolVersionToPackVersion.floorEntry(playerVersion);
|
||||
if (packVersionEntry == null) return;
|
||||
Map.Entry<Integer, File> selectedPackEntry = fileTreeMap.floorEntry(packVersionEntry.getValue());
|
||||
Map.Entry<String, File> selectedPackEntry = fileTreeMap.floorEntry(packVersionEntry.getValue());
|
||||
if (selectedPackEntry == null) return;
|
||||
File selectedPack = selectedPackEntry.getValue();
|
||||
|
||||
|
||||
@@ -21,6 +21,12 @@ import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import java.net.URI
|
||||
import java.util.*
|
||||
|
||||
pluginManagement {
|
||||
plugins {
|
||||
kotlin("plugin.lombok") version "2.3.20"
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "SteamWar"
|
||||
|
||||
private val isInCi by lazy { Os.isFamily(Os.FAMILY_UNIX) && ProcessBuilder("hostname").start().inputStream.bufferedReader().readText().startsWith("steamwar.de") }
|
||||
@@ -128,6 +134,7 @@ dependencyResolutionManagement {
|
||||
library("msgpack", "org.msgpack:msgpack-core:0.9.8")
|
||||
|
||||
library("logback", "ch.qos.logback:logback-classic:1.5.6")
|
||||
library("coroutinesCore", "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
|
||||
|
||||
val ktorVersion = "2.3.12"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user