From 33e9b3409f25a7cae5e834024e3df4e2cf7e03dc Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 16:21:08 +0200 Subject: [PATCH 01/17] Add SelectAdjacent for BauSystem and Builder --- .../features/worldedit/SelectAdjacent.java | 157 ++++++++++++++++++ .../de/steamwar/core/WorldEditRenderer.java | 7 + .../src/de/steamwar/teamserver/Builder.java | 6 + .../teamserver/listener/SelectAdjacent.java | 153 +++++++++++++++++ 4 files changed, 323 insertions(+) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java create mode 100644 Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java new file mode 100644 index 00000000..869af4c9 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java @@ -0,0 +1,157 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.worldedit; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.utils.FlatteningWrapper; +import de.steamwar.core.WorldEditRenderer; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Linked +@MinVersion(20) +public class SelectAdjacent implements Listener { + + private BlockFace[] FACES = { + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN + }; + + private Map selectors = new HashMap<>(); + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!event.hasItem()) return; + if (event.getItem().getType() != Material.WOODEN_AXE) return; + if (!event.getPlayer().isSneaking()) return; + if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; + Selector selector = selectors.get(event.getPlayer()); + if (selector != null) selector.cancel(); + selector = new Selector(event.getClickedBlock(), event.getPlayer()); + selectors.put(event.getPlayer(), selector); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Selector selector = selectors.remove(event.getPlayer()); + if (selector != null) selector.cancel(); + } + + private class Selector { + + private static final int MAX_BLOCKS = 1_000_000; + + private int minX; + private int minY; + private int minZ; + private int maxX; + private int maxY; + private int maxZ; + + private BukkitTask bukkitTask; + private Set seen = new HashSet<>(); + private Set toCalc = new HashSet<>(); + + public Selector(Block block, Player player) { + toCalc.add(block.getLocation()); + minX = block.getX(); + minY = block.getY(); + minZ = block.getZ(); + maxX = block.getX(); + maxY = block.getY(); + maxZ = block.getZ(); + + bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + run(); + + long volume = (long)(maxX - minX + 1) * (long)(maxY - minY + 1) * (long)(maxZ - minZ + 1); + player.sendTitle("", "§e" + volume + " §7Blocks", 0, 5, 0); + + Point minPoint = new Point(minX, minY, minZ); + Point maxPoint = new Point(maxX, maxY, maxZ); + + FlatteningWrapper.impl.setSelection(player, minPoint, maxPoint); + WorldEditRenderer.renderPlayer(player); + + boolean finished = toCalc.stream().allMatch(location -> { + return location.getBlockX() >= minX && location.getBlockY() >= minY && location.getBlockZ() >= minZ && + location.getBlockX() <= maxX && location.getBlockY() <= maxY && location.getBlockZ() <= maxZ; + }); + + if (finished || seen.size() > MAX_BLOCKS) { + bukkitTask.cancel(); + player.sendTitle("§aDone", "§e" + volume + " §7Blocks", 0, 20, 5); + } + }, 1, 1); + } + + private void cancel() { + bukkitTask.cancel(); + } + + private void run() { + Set current = toCalc; + toCalc = new HashSet<>(); + + for (Location location : current) { + Block block = location.getBlock(); + if (block.isEmpty() || block.isLiquid()) continue; + seen.add(location); + + minX = Math.min(minX, location.getBlockX()); + maxX = Math.max(maxX, location.getBlockX()); + minY = Math.min(minY, location.getBlockY()); + maxY = Math.max(maxY, location.getBlockY()); + minZ = Math.min(minZ, location.getBlockZ()); + maxZ = Math.max(maxZ, location.getBlockZ()); + + for (BlockFace face : FACES) { + Block next = block.getRelative(face); + if (next.isEmpty() || next.isLiquid()) continue; + Location loc = next.getLocation(); + if (seen.contains(loc)) continue; + toCalc.add(loc); + } + } + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 225053a2..79c54986 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -39,11 +39,14 @@ import org.bukkit.util.Vector; public class WorldEditRenderer implements Listener { + private static WorldEditRenderer INSTANCE; + private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE"); private final WorldEditPlugin we; public WorldEditRenderer() { + INSTANCE = this; we = WorldEditWrapper.getWorldEditPlugin(); Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); @@ -54,6 +57,10 @@ public class WorldEditRenderer implements Listener { }, 20, 20); } + public static void renderPlayer(Player player) { + WorldEditRenderer.INSTANCE.renderPlayer(player, false); + } + private void renderPlayer(Player player, boolean scheduled) { LocalSession session = we.getSession(player); renderClipboard(player, session, scheduled); diff --git a/Teamserver/src/de/steamwar/teamserver/Builder.java b/Teamserver/src/de/steamwar/teamserver/Builder.java index 55aeed2d..94dadf8a 100644 --- a/Teamserver/src/de/steamwar/teamserver/Builder.java +++ b/Teamserver/src/de/steamwar/teamserver/Builder.java @@ -19,12 +19,14 @@ package de.steamwar.teamserver; +import de.steamwar.core.Core; import de.steamwar.core.WorldEditRendererCUIEditor; import de.steamwar.message.Message; import de.steamwar.teamserver.command.*; import de.steamwar.teamserver.listener.AxiomHandshakeListener; import de.steamwar.teamserver.listener.FreezeListener; import de.steamwar.teamserver.listener.PlayerChange; +import de.steamwar.teamserver.listener.SelectAdjacent; import org.bukkit.Bukkit; import org.bukkit.GameRule; import org.bukkit.plugin.java.JavaPlugin; @@ -60,6 +62,10 @@ public final class Builder extends JavaPlugin { Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); new WorldEditRendererCUIEditor(); + + if (Core.getVersion() >= 20) { + Bukkit.getPluginManager().registerEvents(new SelectAdjacent(), this); + } } @Override diff --git a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java new file mode 100644 index 00000000..06fb8907 --- /dev/null +++ b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java @@ -0,0 +1,153 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.teamserver.listener; + +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; +import com.sk89q.worldedit.world.World; +import de.steamwar.core.WorldEditRenderer; +import de.steamwar.teamserver.Builder; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scheduler.BukkitTask; + +import java.util.*; + +public class SelectAdjacent implements Listener { + + private BlockFace[] FACES = { + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN + }; + + private Map selectors = new HashMap<>(); + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!event.hasItem()) return; + if (event.getItem().getType() != Material.WOODEN_AXE) return; + if (!event.getPlayer().isSneaking()) return; + if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; + Selector selector = selectors.get(event.getPlayer()); + if (selector != null) selector.cancel(); + selector = new Selector(event.getClickedBlock(), event.getPlayer()); + selectors.put(event.getPlayer(), selector); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Selector selector = selectors.remove(event.getPlayer()); + if (selector != null) selector.cancel(); + } + + private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); + private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); + + private class Selector { + + private static final int MAX_BLOCKS = 1_000_000; + + private int minX; + private int minY; + private int minZ; + private int maxX; + private int maxY; + private int maxZ; + + private BukkitTask bukkitTask; + private Set seen = new HashSet<>(); + private Set toCalc = new HashSet<>(); + + public Selector(Block block, Player player) { + toCalc.add(block.getLocation()); + minX = block.getX(); + minY = block.getY(); + minZ = block.getZ(); + maxX = block.getX(); + maxY = block.getY(); + maxZ = block.getZ(); + + bukkitTask = Bukkit.getScheduler().runTaskTimer(Builder.getInstance(), () -> { + run(); + + long volume = (long)(maxX - minX + 1) * (long)(maxY - minY + 1) * (long)(maxZ - minZ + 1); + player.sendTitle("", "§e" + volume + " §7Blocks", 0, 5, 0); + + WORLDEDIT_PLUGIN.getSession(player).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, BlockVector3.at(minX, minY, minZ), BlockVector3.at(maxX, maxY, maxZ))); + WorldEditRenderer.renderPlayer(player); + + boolean finished = toCalc.stream().allMatch(location -> { + return location.getBlockX() >= minX && location.getBlockY() >= minY && location.getBlockZ() >= minZ && + location.getBlockX() <= maxX && location.getBlockY() <= maxY && location.getBlockZ() <= maxZ; + }); + + if (finished || seen.size() > MAX_BLOCKS) { + bukkitTask.cancel(); + player.sendTitle("§aDone", "§e" + volume + " §7Blocks", 0, 20, 5); + } + }, 1, 1); + } + + private void cancel() { + bukkitTask.cancel(); + } + + private void run() { + Set current = toCalc; + toCalc = new HashSet<>(); + + for (Location location : current) { + Block block = location.getBlock(); + if (block.isEmpty() || block.isLiquid()) continue; + seen.add(location); + + minX = Math.min(minX, location.getBlockX()); + maxX = Math.max(maxX, location.getBlockX()); + minY = Math.min(minY, location.getBlockY()); + maxY = Math.max(maxY, location.getBlockY()); + minZ = Math.min(minZ, location.getBlockZ()); + maxZ = Math.max(maxZ, location.getBlockZ()); + + for (BlockFace face : FACES) { + Block next = block.getRelative(face); + if (next.isEmpty() || next.isLiquid()) continue; + Location loc = next.getLocation(); + if (seen.contains(loc)) continue; + toCalc.add(loc); + } + } + } + } +} From 8076f31a19330eb54eb390e2230d4091a33fbdd7 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 16:25:05 +0200 Subject: [PATCH 02/17] Fix SelectAdjacent but make it a touch slower --- .../bausystem/features/worldedit/SelectAdjacent.java | 10 +++++----- .../steamwar/teamserver/listener/SelectAdjacent.java | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java index 869af4c9..c51238ee 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java @@ -112,12 +112,12 @@ public class SelectAdjacent implements Listener { FlatteningWrapper.impl.setSelection(player, minPoint, maxPoint); WorldEditRenderer.renderPlayer(player); - boolean finished = toCalc.stream().allMatch(location -> { - return location.getBlockX() >= minX && location.getBlockY() >= minY && location.getBlockZ() >= minZ && - location.getBlockX() <= maxX && location.getBlockY() <= maxY && location.getBlockZ() <= maxZ; - }); + // boolean finished = toCalc.stream().allMatch(location -> { + // return location.getBlockX() >= minX && location.getBlockY() >= minY && location.getBlockZ() >= minZ && + // location.getBlockX() <= maxX && location.getBlockY() <= maxY && location.getBlockZ() <= maxZ; + // }); - if (finished || seen.size() > MAX_BLOCKS) { + if (toCalc.isEmpty() || seen.size() > MAX_BLOCKS) { bukkitTask.cancel(); player.sendTitle("§aDone", "§e" + volume + " §7Blocks", 0, 20, 5); } diff --git a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java index 06fb8907..02f67136 100644 --- a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java +++ b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java @@ -108,12 +108,12 @@ public class SelectAdjacent implements Listener { WORLDEDIT_PLUGIN.getSession(player).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, BlockVector3.at(minX, minY, minZ), BlockVector3.at(maxX, maxY, maxZ))); WorldEditRenderer.renderPlayer(player); - boolean finished = toCalc.stream().allMatch(location -> { - return location.getBlockX() >= minX && location.getBlockY() >= minY && location.getBlockZ() >= minZ && - location.getBlockX() <= maxX && location.getBlockY() <= maxY && location.getBlockZ() <= maxZ; - }); + // boolean finished = toCalc.stream().allMatch(location -> { + // return location.getBlockX() >= minX && location.getBlockY() >= minY && location.getBlockZ() >= minZ && + // location.getBlockX() <= maxX && location.getBlockY() <= maxY && location.getBlockZ() <= maxZ; + // }); - if (finished || seen.size() > MAX_BLOCKS) { + if (toCalc.isEmpty() || seen.size() > MAX_BLOCKS) { bukkitTask.cancel(); player.sendTitle("§aDone", "§e" + volume + " §7Blocks", 0, 20, 5); } From 3f88ea1e57fcc361f378596fa7cf15f95bd7cc9d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 16:30:02 +0200 Subject: [PATCH 03/17] Fix SelectAdjacent but make it a touch slower --- .../features/worldedit/SelectAdjacent.java | 33 +++++++++++++------ .../teamserver/listener/SelectAdjacent.java | 32 +++++++++++++----- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java index c51238ee..76ffc749 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java @@ -29,7 +29,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -37,6 +36,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; import java.util.HashMap; import java.util.HashSet; @@ -47,13 +47,26 @@ import java.util.Set; @MinVersion(20) public class SelectAdjacent implements Listener { - private BlockFace[] FACES = { - BlockFace.NORTH, - BlockFace.EAST, - BlockFace.SOUTH, - BlockFace.WEST, - BlockFace.UP, - BlockFace.DOWN + private Vector[] FACES = { + new Vector(1, 0, 0), + new Vector(-1, 0, 0), + new Vector(0, 1, 0), + new Vector(0, -1, 0), + new Vector(0, 0, 1), + new Vector(0, 0, -1), + + new Vector(1, 1, 0), + new Vector(1, -1, 0), + new Vector(1, 0, 1), + new Vector(1, 0, -1), + new Vector(-1, 1, 0), + new Vector(-1, -1, 0), + new Vector(-1, 0, 1), + new Vector(-1, 0, -1), + new Vector(0, 1, 1), + new Vector(0, 1, -1), + new Vector(0, -1, 1), + new Vector(0, -1, -1), }; private Map selectors = new HashMap<>(); @@ -144,8 +157,8 @@ public class SelectAdjacent implements Listener { minZ = Math.min(minZ, location.getBlockZ()); maxZ = Math.max(maxZ, location.getBlockZ()); - for (BlockFace face : FACES) { - Block next = block.getRelative(face); + for (Vector face : FACES) { + Block next = block.getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ()); if (next.isEmpty() || next.isLiquid()) continue; Location loc = next.getLocation(); if (seen.contains(loc)) continue; diff --git a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java index 02f67136..003703dd 100644 --- a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java +++ b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java @@ -38,18 +38,32 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; import java.util.*; public class SelectAdjacent implements Listener { - private BlockFace[] FACES = { - BlockFace.NORTH, - BlockFace.EAST, - BlockFace.SOUTH, - BlockFace.WEST, - BlockFace.UP, - BlockFace.DOWN + private Vector[] FACES = { + new Vector(1, 0, 0), + new Vector(-1, 0, 0), + new Vector(0, 1, 0), + new Vector(0, -1, 0), + new Vector(0, 0, 1), + new Vector(0, 0, -1), + + new Vector(1, 1, 0), + new Vector(1, -1, 0), + new Vector(1, 0, 1), + new Vector(1, 0, -1), + new Vector(-1, 1, 0), + new Vector(-1, -1, 0), + new Vector(-1, 0, 1), + new Vector(-1, 0, -1), + new Vector(0, 1, 1), + new Vector(0, 1, -1), + new Vector(0, -1, 1), + new Vector(0, -1, -1), }; private Map selectors = new HashMap<>(); @@ -140,8 +154,8 @@ public class SelectAdjacent implements Listener { minZ = Math.min(minZ, location.getBlockZ()); maxZ = Math.max(maxZ, location.getBlockZ()); - for (BlockFace face : FACES) { - Block next = block.getRelative(face); + for (Vector face : FACES) { + Block next = block.getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ()); if (next.isEmpty() || next.isLiquid()) continue; Location loc = next.getLocation(); if (seen.contains(loc)) continue; From b7963f2fe6c010554851cf6e34c5a40077679801 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 18:00:38 +0200 Subject: [PATCH 04/17] Fix PistonCalculator --- .../de/steamwar/bausystem/features/util/PistonCalculator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index ddc98cd5..4479ff63 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -55,7 +55,8 @@ public class PistonCalculator implements Listener { public void onPlayerInteract(PlayerInteractEvent event) { if (!Permission.BUILD.hasPermission(event.getPlayer())) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if (event.hasItem() && event.getItem().getType() != Material.SLIME_BALL) return; + if (event.hasItem() && event.getItem().getType() == Material.SLIME_BALL) { + } else if (event.hasItem()) return; if (event.getClickedBlock() == null) return; Block clickedBlock = event.getClickedBlock(); Material blockType = clickedBlock.getType(); From 9279d9cd8e707c35492bc40b01cb86eddd845d7f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 18:37:02 +0200 Subject: [PATCH 05/17] Improve SelectAdjacent --- .../features/worldedit/SelectAdjacent.java | 14 ++++++++++++-- .../teamserver/listener/SelectAdjacent.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java index 76ffc749..9afcd59e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java @@ -42,6 +42,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.function.Predicate; @Linked @MinVersion(20) @@ -79,7 +80,12 @@ public class SelectAdjacent implements Listener { if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; Selector selector = selectors.get(event.getPlayer()); if (selector != null) selector.cancel(); - selector = new Selector(event.getClickedBlock(), event.getPlayer()); + Material material = event.getPlayer().getInventory().getItemInOffHand().getType(); + if (material.isAir()) { + selector = new Selector(event.getClickedBlock(), event.getPlayer(), __ -> true); + } else { + selector = new Selector(event.getClickedBlock(), event.getPlayer(), type -> type == material); + } selectors.put(event.getPlayer(), selector); } @@ -101,10 +107,12 @@ public class SelectAdjacent implements Listener { private int maxZ; private BukkitTask bukkitTask; + private Predicate predicate; private Set seen = new HashSet<>(); private Set toCalc = new HashSet<>(); - public Selector(Block block, Player player) { + public Selector(Block block, Player player, Predicate predicate) { + this.predicate = predicate; toCalc.add(block.getLocation()); minX = block.getX(); minY = block.getY(); @@ -148,6 +156,7 @@ public class SelectAdjacent implements Listener { for (Location location : current) { Block block = location.getBlock(); if (block.isEmpty() || block.isLiquid()) continue; + if (!predicate.test(block.getType())) continue; seen.add(location); minX = Math.min(minX, location.getBlockX()); @@ -160,6 +169,7 @@ public class SelectAdjacent implements Listener { for (Vector face : FACES) { Block next = block.getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ()); if (next.isEmpty() || next.isLiquid()) continue; + if (!predicate.test(next.getType())) continue; Location loc = next.getLocation(); if (seen.contains(loc)) continue; toCalc.add(loc); diff --git a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java index 003703dd..2fbebbf3 100644 --- a/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java +++ b/Teamserver/src/de/steamwar/teamserver/listener/SelectAdjacent.java @@ -41,6 +41,7 @@ import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Vector; import java.util.*; +import java.util.function.Predicate; public class SelectAdjacent implements Listener { @@ -76,7 +77,12 @@ public class SelectAdjacent implements Listener { if (event.getAction() != Action.LEFT_CLICK_BLOCK) return; Selector selector = selectors.get(event.getPlayer()); if (selector != null) selector.cancel(); - selector = new Selector(event.getClickedBlock(), event.getPlayer()); + Material material = event.getPlayer().getInventory().getItemInOffHand().getType(); + if (material.isAir()) { + selector = new Selector(event.getClickedBlock(), event.getPlayer(), __ -> true); + } else { + selector = new Selector(event.getClickedBlock(), event.getPlayer(), type -> type == material); + } selectors.put(event.getPlayer(), selector); } @@ -101,10 +107,12 @@ public class SelectAdjacent implements Listener { private int maxZ; private BukkitTask bukkitTask; + private Predicate predicate; private Set seen = new HashSet<>(); private Set toCalc = new HashSet<>(); - public Selector(Block block, Player player) { + public Selector(Block block, Player player, Predicate predicate) { + this.predicate = predicate; toCalc.add(block.getLocation()); minX = block.getX(); minY = block.getY(); @@ -145,6 +153,7 @@ public class SelectAdjacent implements Listener { for (Location location : current) { Block block = location.getBlock(); if (block.isEmpty() || block.isLiquid()) continue; + if (!predicate.test(block.getType())) continue; seen.add(location); minX = Math.min(minX, location.getBlockX()); @@ -157,6 +166,7 @@ public class SelectAdjacent implements Listener { for (Vector face : FACES) { Block next = block.getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ()); if (next.isEmpty() || next.isLiquid()) continue; + if (!predicate.test(next.getType())) continue; Location loc = next.getLocation(); if (seen.contains(loc)) continue; toCalc.add(loc); From 6623e9d808fb29c4d84ba4fefa410bd6fefef271 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 10:43:37 +0200 Subject: [PATCH 06/17] Add VacationCommand --- .../velocitycore/discord/DiscordBot.java | 10 +- .../velocitycore/discord/VacationCommand.java | 189 ++++++++++++++++++ 2 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 28cd0c22..53714c52 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -54,8 +54,8 @@ import net.dv8tion.jda.api.utils.MemberCachePolicy; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.awt.*; -import java.util.List; import java.util.*; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -193,14 +193,20 @@ public class DiscordBot { VelocityCore.schedule(CouncilChannel::updateAll).repeat(1, TimeUnit.HOURS).schedule(); + VacationCommand vacationCommand = new VacationCommand(); jda.addEventListener( new DiscordTicketHandler(), new DiscordTeamEvent(), new ChannelListener(), - new DiscordSchemUpload() + new DiscordSchemUpload(), + vacationCommand ); commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); + + jda.getGuildById(1241489896909180998L) + .upsertCommand(vacationCommand.COMMAND) + .queue(); } private final OptionData commandArgument = new OptionData(OptionType.STRING, ARGUMENT_NAME, "Command arguments", false); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java new file mode 100644 index 00000000..ace8dcf6 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java @@ -0,0 +1,189 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.velocitycore.discord; + +import it.unimi.dsi.fastutil.Pair; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.ScheduledEvent; +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.interactions.InteractionHook; +import net.dv8tion.jda.api.interactions.commands.Command; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; +import net.dv8tion.jda.internal.interactions.CommandDataImpl; +import org.jetbrains.annotations.NotNull; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class VacationCommand extends ListenerAdapter { + + private final Guild guild = Objects.requireNonNull(DiscordBot.getInstance().getJda().getGuildById(1241489896909180998L)); + + public final CommandDataImpl COMMAND = new CommandDataImpl("vacation", "Verwalte deinen Urlaub"); + + public VacationCommand() { + COMMAND.addSubcommands(new SubcommandData("create", "Erstelle deinen Urlaub") + .addOptions(new OptionData(OptionType.STRING, "from", "Datum (TT.MM.JJJJ)", true), + new OptionData(OptionType.STRING, "to", "Datum (TT.MM.JJJJ)", true))); + COMMAND.addSubcommands(new SubcommandData("delete", "Lösche deinen Urlaub") + .addOptions(new OptionData(OptionType.INTEGER, "vacation", "Dein Urlaub", true, true))); + } + + @Override + public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { + if (!event.getName().equals("vacation")) return; + switch (event.getSubcommandName()) { + case "create": + createVacation(event); + break; + case "delete": + deleteVacation(event); + break; + default: + break; + } + } + + public static final DateTimeFormatter PARSER = DateTimeFormatter.ofPattern("dd.MM.uuuu"); + + private void createVacation(SlashCommandInteractionEvent event) { + InteractionHook interactionHook = event.deferReply(true).complete(); + String from = event.getOption("from").getAsString(); + String to = event.getOption("to").getAsString(); + + LocalDateTime fromDate; + try { + fromDate = LocalDate.parse(from, PARSER).atStartOfDay(); + } catch (DateTimeParseException e) { + interactionHook.editOriginal("Das Datumsformat ist falsch! Bitte verwenden Sie TT.MM.JJJJ für den ersten Tag deines Urlaubs").queue(); + return; + } + if (fromDate == null) { + interactionHook.editOriginal("Das Datumsformat ist falsch! Bitte verwenden Sie TT.MM.JJJJ für den ersten Tag deines Urlaubs").queue(); + return; + } + if (!fromDate.isAfter(LocalDateTime.now())) { + interactionHook.editOriginal("Bitte gib ein Datum in der Zukunft an!").queue(); + return; + } + + LocalDateTime toDate; + try { + toDate = LocalDate.parse(to, PARSER).atTime(23, 59, 59); + } catch (DateTimeParseException e) { + interactionHook.editOriginal("Das Datumsformat ist falsch! Bitte verwenden Sie TT.MM.JJJJ für den letzten Tag deines Urlaubs").queue(); + return; + } + if (toDate == null) { + interactionHook.editOriginal("Das Datumsformat ist falsch! Bitte verwenden Sie TT.MM.JJJJ für den letzten Tag deines Urlaubs").queue(); + return; + } + if (!toDate.isAfter(LocalDateTime.now())) { + interactionHook.editOriginal("Bitte gib ein Datum in der Zukunft an!").queue(); + return; + } + if (!toDate.isAfter(fromDate)) { + interactionHook.editOriginal("Bitte gib ein Datum nach dem ersten Urlaubstag an!").queue(); + return; + } + + guild.createScheduledEvent( + "Urlaub " + event.getMember().getEffectiveName(), + event.getMember().getId(), + OffsetDateTime.of(fromDate, ZoneId.of("Europe/Berlin").getRules().getOffset(fromDate)), + OffsetDateTime.of(toDate, ZoneId.of("Europe/Berlin").getRules().getOffset(toDate)) + ).onSuccess(scheduledEvent -> { + interactionHook.editOriginal("Urlaub erstellt!").queue(); + }) + .onErrorMap(throwable -> { + interactionHook.editOriginal("Urlaub konnte nicht erstellt werden!").queue(); + return null; + }) + .queue(); + } + + private void deleteVacation(SlashCommandInteractionEvent event) { + InteractionHook interactionHook = event.deferReply(true).complete(); + long eventId = event.getOption("vacation").getAsLong(); + ScheduledEvent scheduledEvent = guild.getScheduledEventById(eventId); + if (scheduledEvent == null) { + interactionHook.editOriginal("Konnte den Urlaub nicht finden!").queue(); + return; + } + scheduledEvent.delete() + .onSuccess(unused -> { + interactionHook.editOriginal("Urlaub gelöscht!").queue(); + }) + .onErrorMap(throwable -> { + interactionHook.editOriginal("Urlaub konnte nicht gelöscht werden!").queue(); + return null; + }) + .queue(); + } + + @Override + public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInteractionEvent event) { + if (!event.getName().equals("vacation")) return; + switch (event.getFocusedOption().getName()) { + case "vacation": + listVacations(event); + break; + default: + break; + } + } + + private void listVacations(CommandAutoCompleteInteractionEvent event) { + String vacation = event.getOption("vacation").getAsString(); + List choices = guild.getScheduledEvents() + .stream() + .filter(scheduledEvent -> scheduledEvent.getLocation().equals(event.getMember().getId())) + .map(scheduledEvent -> { + StringBuilder st = new StringBuilder(); + st.append(String.format("%02d", scheduledEvent.getStartTime().getDayOfMonth())).append("."); + st.append(String.format("%02d", scheduledEvent.getStartTime().getMonth())).append("."); + st.append(scheduledEvent.getStartTime().getYear()); + st.append(" - "); + st.append(String.format("%02d", scheduledEvent.getEndTime().getDayOfMonth())).append("."); + st.append(String.format("%02d", scheduledEvent.getEndTime().getDayOfMonth())).append("."); + st.append(scheduledEvent.getEndTime().getYear()); + return Pair.of(scheduledEvent, st.toString()); + }) + .filter(pair -> pair.right().startsWith(vacation)) + .limit(25) + .map(pair -> { + return new Command.Choice(pair.right(), pair.left().getLocation()); + }) + .collect(Collectors.toList()); + event.replyChoices(choices) + .queue(); + } +} From d14022e69ef06648ffb4433719f019b3a93936c9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 10:46:54 +0200 Subject: [PATCH 07/17] Fix ChannelListener --- .../steamwar/velocitycore/discord/listeners/ChannelListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java index bebf194c..bfecf313 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java @@ -70,6 +70,7 @@ public class ChannelListener extends ListenerAdapter { @Override public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { + if (event.getGuild().getIdLong() == 1241489896909180998L) return; InteractionReply.reply(event, sender -> { if(sender.user().getDiscordId() == null) return; From 9e629d09a80c90a5d36ea630f8a6597e353cd122 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 10:48:17 +0200 Subject: [PATCH 08/17] Fix VacationCommand --- .../src/de/steamwar/velocitycore/discord/VacationCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java index ace8dcf6..2c43356c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java @@ -169,11 +169,11 @@ public class VacationCommand extends ListenerAdapter { .map(scheduledEvent -> { StringBuilder st = new StringBuilder(); st.append(String.format("%02d", scheduledEvent.getStartTime().getDayOfMonth())).append("."); - st.append(String.format("%02d", scheduledEvent.getStartTime().getMonth())).append("."); + st.append(String.format("%02d", scheduledEvent.getStartTime().getMonthValue())).append("."); st.append(scheduledEvent.getStartTime().getYear()); st.append(" - "); st.append(String.format("%02d", scheduledEvent.getEndTime().getDayOfMonth())).append("."); - st.append(String.format("%02d", scheduledEvent.getEndTime().getDayOfMonth())).append("."); + st.append(String.format("%02d", scheduledEvent.getEndTime().getMonthValue())).append("."); st.append(scheduledEvent.getEndTime().getYear()); return Pair.of(scheduledEvent, st.toString()); }) From d9681877509654f9730d8e0a3e92a138eb10eda4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 10:49:28 +0200 Subject: [PATCH 09/17] Fix VacationCommand --- .../src/de/steamwar/velocitycore/discord/VacationCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java index 2c43356c..f4121468 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java @@ -180,7 +180,7 @@ public class VacationCommand extends ListenerAdapter { .filter(pair -> pair.right().startsWith(vacation)) .limit(25) .map(pair -> { - return new Command.Choice(pair.right(), pair.left().getLocation()); + return new Command.Choice(pair.right(), Long.parseLong(pair.left().getLocation())); }) .collect(Collectors.toList()); event.replyChoices(choices) From 01f55c43093f6641d387fafc6a189c99057470ed Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 10:51:17 +0200 Subject: [PATCH 10/17] Fix VacationCommand --- .../de/steamwar/velocitycore/discord/VacationCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java index f4121468..5be79f9e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/VacationCommand.java @@ -54,7 +54,7 @@ public class VacationCommand extends ListenerAdapter { .addOptions(new OptionData(OptionType.STRING, "from", "Datum (TT.MM.JJJJ)", true), new OptionData(OptionType.STRING, "to", "Datum (TT.MM.JJJJ)", true))); COMMAND.addSubcommands(new SubcommandData("delete", "Lösche deinen Urlaub") - .addOptions(new OptionData(OptionType.INTEGER, "vacation", "Dein Urlaub", true, true))); + .addOptions(new OptionData(OptionType.STRING, "vacation", "Dein Urlaub", true, true))); } @Override @@ -132,7 +132,7 @@ public class VacationCommand extends ListenerAdapter { private void deleteVacation(SlashCommandInteractionEvent event) { InteractionHook interactionHook = event.deferReply(true).complete(); - long eventId = event.getOption("vacation").getAsLong(); + String eventId = event.getOption("vacation").getAsString(); ScheduledEvent scheduledEvent = guild.getScheduledEventById(eventId); if (scheduledEvent == null) { interactionHook.editOriginal("Konnte den Urlaub nicht finden!").queue(); @@ -180,7 +180,7 @@ public class VacationCommand extends ListenerAdapter { .filter(pair -> pair.right().startsWith(vacation)) .limit(25) .map(pair -> { - return new Command.Choice(pair.right(), Long.parseLong(pair.left().getLocation())); + return new Command.Choice(pair.right(), pair.left().getId()); }) .collect(Collectors.toList()); event.replyChoices(choices) From 3a13fc7bb92e080a4cd6c388596c3b18d1d1ee9e Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 17:51:19 +0200 Subject: [PATCH 11/17] Reduce MAX_BLOCKS of SelectAdjacent --- .../steamwar/bausystem/features/worldedit/SelectAdjacent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java index 9afcd59e..c92b5aa2 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SelectAdjacent.java @@ -97,7 +97,7 @@ public class SelectAdjacent implements Listener { private class Selector { - private static final int MAX_BLOCKS = 1_000_000; + private static final int MAX_BLOCKS = 100_000; private int minX; private int minY; From 2166096ba55af0bc8c4773e48c680b1e980c076e Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 1 Aug 2025 21:17:58 +0200 Subject: [PATCH 12/17] Fix PistonCalculator --- .../steamwar/bausystem/features/util/PistonCalculator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index 4479ff63..6bf9b0c9 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -55,8 +55,9 @@ public class PistonCalculator implements Listener { public void onPlayerInteract(PlayerInteractEvent event) { if (!Permission.BUILD.hasPermission(event.getPlayer())) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if (event.hasItem() && event.getItem().getType() == Material.SLIME_BALL) { - } else if (event.hasItem()) return; + if (event.getItem() == null) {} + else if (event.getItem() != null && event.getItem().getType() == Material.SLIME_BALL) {} + else return; if (event.getClickedBlock() == null) return; Block clickedBlock = event.getClickedBlock(); Material blockType = clickedBlock.getType(); From 70d0f179ccd0851700e510d2ce9f57a8db64a70d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 2 Aug 2025 11:34:41 +0200 Subject: [PATCH 13/17] Fix stuff in DiscordBot --- .../velocitycore/discord/DiscordBot.java | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 53714c52..68d5d316 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -41,7 +41,6 @@ import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; -import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; @@ -49,13 +48,14 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.requests.GatewayIntent; -import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; import net.dv8tion.jda.api.utils.MemberCachePolicy; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.awt.*; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -67,9 +67,10 @@ public class DiscordBot { @Getter private static final Map commands = new HashMap<>(); + private final OptionData commandArgument = new OptionData(OptionType.STRING, ARGUMENT_NAME, "Command arguments", false); public static void withBot(Consumer consumer) { - if(instance != null) + if (instance != null) consumer.accept(instance); } @@ -141,7 +142,7 @@ public class DiscordBot { ActionRow.of(Button.link("https://steamwar.de", "Website"), Button.link("https://steamwar.de/youtube", "YouTube")), ActionRow.of(Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen")) ), event -> { - if(event.getComponentId().equals("auth")) + if (event.getComponentId().equals("auth")) event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + AuthManager.createDiscordAuthToken(event.getUser()) + "`` auf dem Minecraft Server ein").setEphemeral(true).queue(); }); List actionRows = new ArrayList<>(); @@ -202,42 +203,24 @@ public class DiscordBot { vacationCommand ); - commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); + jda.updateCommands() + .addCommands(commands.keySet() + .stream() + .filter(command -> command.matches("^[\\w-]+$")) + .map(command -> Commands.slash(command, command).addOptions(commandArgument)) + .toArray(CommandData[]::new)) + .queue(); + jda.getGuildById(690530484920385586L).updateCommands().queue(); jda.getGuildById(1241489896909180998L) .upsertCommand(vacationCommand.COMMAND) .queue(); } - private final OptionData commandArgument = new OptionData(OptionType.STRING, ARGUMENT_NAME, "Command arguments", false); - private void commandSetup(List existing, CommandListUpdateAction updateCommands) { - Set correctCommands = new HashSet<>(); - for(Command command : existing) { - if(!commands.containsKey(command.getName())) { - command.delete().complete(); - continue; - } - - List options = command.getOptions(); - if(options.size() != 1 || options.get(0).getType() != OptionType.STRING) - command.editCommand().clearOptions().addOptions(commandArgument).complete(); - - correctCommands.add(command.getName()); - } - - updateCommands - .addCommands(commands - .keySet().stream() - .filter(command -> !correctCommands.contains(command)) - .filter(command -> command.matches("^[\\w-]+$")) - .map(command -> Commands.slash(command, command).addOptions(commandArgument)) - .toArray(CommandData[]::new)) - .queue(); - } - private boolean activityToggle = false; + private void activity() { - if(activityToggle) { + if (activityToggle) { Event event = Event.get(); jda.getPresence().setActivity(event != null ? Activity.competing("dem Event " + event.getEventName()) : Activity.playing("auf SteamWar.de")); } else { From 018b9a971f62ea37b1755ec55087134bcf022460 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 2 Aug 2025 11:36:08 +0200 Subject: [PATCH 14/17] Fix stuff in DiscordBot --- .../src/de/steamwar/velocitycore/discord/DiscordBot.java | 1 - 1 file changed, 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 68d5d316..e2930bb6 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -210,7 +210,6 @@ public class DiscordBot { .map(command -> Commands.slash(command, command).addOptions(commandArgument)) .toArray(CommandData[]::new)) .queue(); - jda.getGuildById(690530484920385586L).updateCommands().queue(); jda.getGuildById(1241489896909180998L) .upsertCommand(vacationCommand.COMMAND) From 2e91a5a582b4e07f38dedc970e4ba90158cef3b1 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 2 Aug 2025 11:42:39 +0200 Subject: [PATCH 15/17] Trigger rebuild --- .../src/de/steamwar/velocitycore/discord/DiscordBot.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index e2930bb6..ae9decbd 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -131,6 +131,7 @@ public class DiscordBot { reply.system("DC_ROLE_ADDED", role.getAsMention()); } })); + new StaticMessageChannel(config.channel("rules"), () -> new MessageCreateBuilder() .setEmbeds(new EmbedBuilder() .setDescription(String.join("\n", config.getRules())) @@ -145,6 +146,7 @@ public class DiscordBot { if (event.getComponentId().equals("auth")) event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + AuthManager.createDiscordAuthToken(event.getUser()) + "`` auf dem Minecraft Server ein").setEphemeral(true).queue(); }); + List actionRows = new ArrayList<>(); List