forked from SteamWar/SteamWar
Merge branch 'main' into 1.21.6/fightsystem
This commit is contained in:
+7
-1
@@ -55,7 +55,13 @@ public class PistonCalculator implements Listener {
|
|||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
if (event.hasItem() && event.getItem().getType() != Material.SLIME_BALL) return;
|
if (event.getItem() == null) {}
|
||||||
|
else if (event.getItem() != null && event.getItem().getType() == Material.SLIME_BALL) {}
|
||||||
|
else if (!event.getItem().getType().isBlock()) {
|
||||||
|
DEBOUNCE.put(event.getPlayer(), System.currentTimeMillis());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else return;
|
||||||
if (event.getClickedBlock() == null) return;
|
if (event.getClickedBlock() == null) return;
|
||||||
Block clickedBlock = event.getClickedBlock();
|
Block clickedBlock = event.getClickedBlock();
|
||||||
Material blockType = clickedBlock.getType();
|
Material blockType = clickedBlock.getType();
|
||||||
|
|||||||
+180
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.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.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 org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
@MinVersion(20)
|
||||||
|
public class SelectAdjacent implements Listener {
|
||||||
|
|
||||||
|
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<Player, Selector> 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();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 = 500_000;
|
||||||
|
|
||||||
|
private int minX;
|
||||||
|
private int minY;
|
||||||
|
private int minZ;
|
||||||
|
private int maxX;
|
||||||
|
private int maxY;
|
||||||
|
private int maxZ;
|
||||||
|
|
||||||
|
private BukkitTask bukkitTask;
|
||||||
|
private Predicate<Material> predicate;
|
||||||
|
private Set<Location> seen = new HashSet<>();
|
||||||
|
private Set<Location> toCalc = new HashSet<>();
|
||||||
|
|
||||||
|
public Selector(Block block, Player player, Predicate<Material> predicate) {
|
||||||
|
this.predicate = predicate;
|
||||||
|
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 (toCalc.isEmpty() || 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<Location> current = toCalc;
|
||||||
|
toCalc = new HashSet<>();
|
||||||
|
|
||||||
|
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());
|
||||||
|
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 (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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,11 +39,14 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
public class WorldEditRenderer implements Listener {
|
public class WorldEditRenderer implements Listener {
|
||||||
|
|
||||||
|
private static WorldEditRenderer INSTANCE;
|
||||||
|
|
||||||
private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE");
|
private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE");
|
||||||
|
|
||||||
private final WorldEditPlugin we;
|
private final WorldEditPlugin we;
|
||||||
|
|
||||||
public WorldEditRenderer() {
|
public WorldEditRenderer() {
|
||||||
|
INSTANCE = this;
|
||||||
we = WorldEditWrapper.getWorldEditPlugin();
|
we = WorldEditWrapper.getWorldEditPlugin();
|
||||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||||
|
|
||||||
@@ -54,6 +57,10 @@ public class WorldEditRenderer implements Listener {
|
|||||||
}, 20, 20);
|
}, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void renderPlayer(Player player) {
|
||||||
|
WorldEditRenderer.INSTANCE.renderPlayer(player, false);
|
||||||
|
}
|
||||||
|
|
||||||
private void renderPlayer(Player player, boolean scheduled) {
|
private void renderPlayer(Player player, boolean scheduled) {
|
||||||
LocalSession session = we.getSession(player);
|
LocalSession session = we.getSession(player);
|
||||||
renderClipboard(player, session, scheduled);
|
renderClipboard(player, session, scheduled);
|
||||||
|
|||||||
@@ -19,12 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.teamserver;
|
package de.steamwar.teamserver;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.WorldEditRendererCUIEditor;
|
import de.steamwar.core.WorldEditRendererCUIEditor;
|
||||||
import de.steamwar.message.Message;
|
import de.steamwar.message.Message;
|
||||||
import de.steamwar.teamserver.command.*;
|
import de.steamwar.teamserver.command.*;
|
||||||
import de.steamwar.teamserver.listener.AxiomHandshakeListener;
|
import de.steamwar.teamserver.listener.AxiomHandshakeListener;
|
||||||
import de.steamwar.teamserver.listener.FreezeListener;
|
import de.steamwar.teamserver.listener.FreezeListener;
|
||||||
import de.steamwar.teamserver.listener.PlayerChange;
|
import de.steamwar.teamserver.listener.PlayerChange;
|
||||||
|
import de.steamwar.teamserver.listener.SelectAdjacent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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);
|
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||||
new WorldEditRendererCUIEditor();
|
new WorldEditRendererCUIEditor();
|
||||||
|
|
||||||
|
if (Core.getVersion() >= 20) {
|
||||||
|
Bukkit.getPluginManager().registerEvents(new SelectAdjacent(), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.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 org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class SelectAdjacent implements Listener {
|
||||||
|
|
||||||
|
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<Player, Selector> 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();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 Predicate<Material> predicate;
|
||||||
|
private Set<Location> seen = new HashSet<>();
|
||||||
|
private Set<Location> toCalc = new HashSet<>();
|
||||||
|
|
||||||
|
public Selector(Block block, Player player, Predicate<Material> predicate) {
|
||||||
|
this.predicate = predicate;
|
||||||
|
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 (toCalc.isEmpty() || 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<Location> current = toCalc;
|
||||||
|
toCalc = new HashSet<>();
|
||||||
|
|
||||||
|
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());
|
||||||
|
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 (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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,7 +41,6 @@ import net.dv8tion.jda.api.entities.Role;
|
|||||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
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.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
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.ActionRow;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
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.MemberCachePolicy;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -67,9 +67,10 @@ public class DiscordBot {
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static final Map<String, SWCommand> commands = new HashMap<>();
|
private static final Map<String, SWCommand> commands = new HashMap<>();
|
||||||
|
private final OptionData commandArgument = new OptionData(OptionType.STRING, ARGUMENT_NAME, "Command arguments", false);
|
||||||
|
|
||||||
public static void withBot(Consumer<DiscordBot> consumer) {
|
public static void withBot(Consumer<DiscordBot> consumer) {
|
||||||
if(instance != null)
|
if (instance != null)
|
||||||
consumer.accept(instance);
|
consumer.accept(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +131,7 @@ public class DiscordBot {
|
|||||||
reply.system("DC_ROLE_ADDED", role.getAsMention());
|
reply.system("DC_ROLE_ADDED", role.getAsMention());
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
new StaticMessageChannel(config.channel("rules"), () -> new MessageCreateBuilder()
|
new StaticMessageChannel(config.channel("rules"), () -> new MessageCreateBuilder()
|
||||||
.setEmbeds(new EmbedBuilder()
|
.setEmbeds(new EmbedBuilder()
|
||||||
.setDescription(String.join("\n", config.getRules()))
|
.setDescription(String.join("\n", config.getRules()))
|
||||||
@@ -141,9 +143,10 @@ public class DiscordBot {
|
|||||||
ActionRow.of(Button.link("https://steamwar.de", "Website"), Button.link("https://steamwar.de/youtube", "YouTube")),
|
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"))
|
ActionRow.of(Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen"))
|
||||||
), event -> {
|
), 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();
|
event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + AuthManager.createDiscordAuthToken(event.getUser()) + "`` auf dem Minecraft Server ein").setEphemeral(true).queue();
|
||||||
});
|
});
|
||||||
|
|
||||||
List<ActionRow> actionRows = new ArrayList<>();
|
List<ActionRow> actionRows = new ArrayList<>();
|
||||||
List<Button> list = new ArrayList<>();
|
List<Button> list = new ArrayList<>();
|
||||||
for (DiscordTicketType type : DiscordTicketType.values()) {
|
for (DiscordTicketType type : DiscordTicketType.values()) {
|
||||||
@@ -163,6 +166,7 @@ public class DiscordBot {
|
|||||||
.setColor(Color.RED)
|
.setColor(Color.RED)
|
||||||
.build())
|
.build())
|
||||||
.setComponents(actionRows), DiscordTicketHandler::openTicket);
|
.setComponents(actionRows), DiscordTicketHandler::openTicket);
|
||||||
|
|
||||||
eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get);
|
eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get);
|
||||||
checklistChannel = new ChecklistChannel(config.channel("checklist"));
|
checklistChannel = new ChecklistChannel(config.channel("checklist"));
|
||||||
config.getCouncilThread().forEach((roleId, threadId) -> new CouncilChannel(DiscordBot.getGuild().getRoleById(roleId), DiscordBot.getGuild().getThreadChannelById(threadId)));
|
config.getCouncilThread().forEach((roleId, threadId) -> new CouncilChannel(DiscordBot.getGuild().getRoleById(roleId), DiscordBot.getGuild().getThreadChannelById(threadId)));
|
||||||
@@ -193,45 +197,32 @@ public class DiscordBot {
|
|||||||
|
|
||||||
VelocityCore.schedule(CouncilChannel::updateAll).repeat(1, TimeUnit.HOURS).schedule();
|
VelocityCore.schedule(CouncilChannel::updateAll).repeat(1, TimeUnit.HOURS).schedule();
|
||||||
|
|
||||||
|
VacationCommand vacationCommand = new VacationCommand();
|
||||||
jda.addEventListener(
|
jda.addEventListener(
|
||||||
new DiscordTicketHandler(),
|
new DiscordTicketHandler(),
|
||||||
new DiscordTeamEvent(),
|
new DiscordTeamEvent(),
|
||||||
new ChannelListener(),
|
new ChannelListener(),
|
||||||
new DiscordSchemUpload()
|
new DiscordSchemUpload(),
|
||||||
|
vacationCommand
|
||||||
);
|
);
|
||||||
|
|
||||||
commandSetup(jda.retrieveCommands().complete(), jda.updateCommands());
|
jda.updateCommands()
|
||||||
}
|
.addCommands(commands.keySet()
|
||||||
|
.stream()
|
||||||
private final OptionData commandArgument = new OptionData(OptionType.STRING, ARGUMENT_NAME, "Command arguments", false);
|
|
||||||
private void commandSetup(List<Command> existing, CommandListUpdateAction updateCommands) {
|
|
||||||
Set<String> correctCommands = new HashSet<>();
|
|
||||||
for(Command command : existing) {
|
|
||||||
if(!commands.containsKey(command.getName())) {
|
|
||||||
command.delete().complete();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Command.Option> 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-]+$"))
|
.filter(command -> command.matches("^[\\w-]+$"))
|
||||||
.map(command -> Commands.slash(command, command).addOptions(commandArgument))
|
.map(command -> Commands.slash(command, command).addOptions(commandArgument))
|
||||||
.toArray(CommandData[]::new))
|
.toArray(CommandData[]::new))
|
||||||
.queue();
|
.queue();
|
||||||
|
|
||||||
|
jda.getGuildById(1241489896909180998L)
|
||||||
|
.upsertCommand(vacationCommand.COMMAND)
|
||||||
|
.queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean activityToggle = false;
|
private boolean activityToggle = false;
|
||||||
|
|
||||||
private void activity() {
|
private void activity() {
|
||||||
if(activityToggle) {
|
if (activityToggle) {
|
||||||
Event event = Event.get();
|
Event event = Event.get();
|
||||||
jda.getPresence().setActivity(event != null ? Activity.competing("dem Event " + event.getEventName()) : Activity.playing("auf SteamWar.de"));
|
jda.getPresence().setActivity(event != null ? Activity.competing("dem Event " + event.getEventName()) : Activity.playing("auf SteamWar.de"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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.STRING, "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();
|
||||||
|
String eventId = event.getOption("vacation").getAsString();
|
||||||
|
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<Command.Choice> 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().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().getMonthValue())).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().getId());
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
event.replyChoices(choices)
|
||||||
|
.queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,6 +70,7 @@ public class ChannelListener extends ListenerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
||||||
|
if (event.getGuild().getIdLong() == 1241489896909180998L) return;
|
||||||
InteractionReply.reply(event, sender -> {
|
InteractionReply.reply(event, sender -> {
|
||||||
if(sender.user().getDiscordId() == null)
|
if(sender.user().getDiscordId() == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user