forked from SteamWar/SteamWar
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ae094abe4 | ||
|
|
3d6c50938c | ||
|
|
e9d814bc95 | ||
|
|
ef61cf455d | ||
|
|
b6bad4e78e | ||
|
|
18659385d2 | ||
|
|
f6fc65a370 | ||
|
|
fbc14d0503 | ||
|
|
9fe38bcf61 | ||
|
|
fd22c1cccc | ||
|
|
b627b3b4a6 | ||
|
|
f9faa9b296 |
@@ -1,46 +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.bausystem.utils;
|
|
||||||
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class PlayerMovementWrapper21 implements PlayerMovementWrapper {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Player player, Object object) {
|
|
||||||
ServerboundMovePlayerPacket packetPlayInFlying = ((ServerboundMovePlayerPacket) object);
|
|
||||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
if (packetPlayInFlying.hasPos) {
|
|
||||||
serverPlayer.setPosRaw(packetPlayInFlying.x, packetPlayInFlying.y, packetPlayInFlying.z);
|
|
||||||
}
|
|
||||||
if (packetPlayInFlying.hasRot) {
|
|
||||||
serverPlayer.setXRot(packetPlayInFlying.xRot);
|
|
||||||
serverPlayer.setYRot(packetPlayInFlying.yRot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convertToOut(Player player, Object object) {
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1030,7 +1030,6 @@ SCHEMATIC_GUI_ITEM=§eSchematics
|
|||||||
# TNTListener
|
# TNTListener
|
||||||
TLS_MESSAGE_79=§7TLS§8> §7Tick §e{0} §8- §7TNT §e{1}
|
TLS_MESSAGE_79=§7TLS§8> §7Tick §e{0} §8- §7TNT §e{1}
|
||||||
TLS_MESSAGE_80=§7TLS§8> §7Tick §e{0} §8- §7TNT §e{1} §8(§e{2} §7with Fuse 80§8)
|
TLS_MESSAGE_80=§7TLS§8> §7Tick §e{0} §8- §7TNT §e{1} §8(§e{2} §7with Fuse 80§8)
|
||||||
TLS_START_HELP=§8/§etls start §8- §7Start the TNT Listener
|
TLS_START_HELP=§8/§etls start §8: §7Start the TNT Listener
|
||||||
TLS_STOP_HELP=§8/§etls stop §8- §7Stop the TNT Listener
|
TLS_STOP_HELP=§8/§etls stop §8: §7Stop the TNT Listener
|
||||||
TLS_SCOREBOARD_ELEMENT=§eTLS§8: §aon
|
TLS_SCOREBOARD_ELEMENT=§eTLS§8: §aon
|
||||||
TLS_TOGGLE_HELP=§8/§etls§8: §7Toggle the TNT Listener
|
|
||||||
@@ -961,7 +961,6 @@ TYPEREPLACE_HELP=§8//§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Erset
|
|||||||
# Schematics
|
# Schematics
|
||||||
SCHEMATIC_GUI_ITEM=§eSchematics
|
SCHEMATIC_GUI_ITEM=§eSchematics
|
||||||
TLS_MESSAGE_80=§7TLS§8> §7Tick §e{0} §8- §7TNT §e{1} §8(§e{2} §7mit Fuse 80§8)
|
TLS_MESSAGE_80=§7TLS§8> §7Tick §e{0} §8- §7TNT §e{1} §8(§e{2} §7mit Fuse 80§8)
|
||||||
TLS_START_HELP=§8/§etls start §8- §7Starte den TNT Listener
|
TLS_START_HELP=§8/§etls start §8: §7Starte den TNT Listener
|
||||||
TLS_STOP_HELP=§8/§etls stop §8- §7Stope den TNT Listener
|
TLS_STOP_HELP=§8/§etls stop §8: §7Stope den TNT Listener
|
||||||
TLS_SCOREBOARD_ELEMENT=§eTLS§8: §aan
|
TLS_SCOREBOARD_ELEMENT=§eTLS§8: §aan
|
||||||
TLS_TOGGLE_HELP=§8/§etls §8: §7Toggle den TNT Listener
|
|
||||||
@@ -27,6 +27,8 @@ import de.steamwar.sql.SteamwarUser;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -37,12 +39,13 @@ public enum Permission {
|
|||||||
return bauweltMember.isSupervisor();
|
return bauweltMember.isSupervisor();
|
||||||
}),
|
}),
|
||||||
BUILD(bauweltMember -> {
|
BUILD(bauweltMember -> {
|
||||||
|
if (isTempOnlySpectator(bauweltMember)) return false;
|
||||||
return bauweltMember.isBuild() || SUPERVISOR.permissionPredicate.test(bauweltMember);
|
return bauweltMember.isBuild() || SUPERVISOR.permissionPredicate.test(bauweltMember);
|
||||||
}),
|
}),
|
||||||
/**
|
/**
|
||||||
* Only used for {@link BauMemberUpdate}
|
* Only used for {@link BauMemberUpdate}
|
||||||
*/
|
*/
|
||||||
SPECTATOR(bauweltMember -> {
|
REAL_SPECTATOR(bauweltMember -> {
|
||||||
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
||||||
}),
|
}),
|
||||||
/**
|
/**
|
||||||
@@ -52,6 +55,28 @@ public enum Permission {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
private static final Set<Integer> TEMP_ONLY_SPECTATOR = new HashSet<>();
|
||||||
|
|
||||||
|
private static boolean isTempOnlySpectator(BauweltMember bauweltMember) {
|
||||||
|
return TEMP_ONLY_SPECTATOR.contains(bauweltMember.getMemberID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTempOnlySpectator(Player player) {
|
||||||
|
return TEMP_ONLY_SPECTATOR.contains(SteamwarUser.get(player.getUniqueId()).getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void forceOnlySpectator(Player player) {
|
||||||
|
TEMP_ONLY_SPECTATOR.add(SteamwarUser.get(player.getUniqueId()).getId());
|
||||||
|
BauMemberUpdate.baumemberUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only used by {@link BauMemberUpdate}
|
||||||
|
*/
|
||||||
|
public static void removeForceOnlySpectator(Player player) {
|
||||||
|
TEMP_ONLY_SPECTATOR.remove(SteamwarUser.get(player.getUniqueId()).getId());
|
||||||
|
}
|
||||||
|
|
||||||
private final Predicate<BauweltMember> permissionPredicate;
|
private final Predicate<BauweltMember> permissionPredicate;
|
||||||
|
|
||||||
public boolean hasPermission(BauweltMember bauweltMember) {
|
public boolean hasPermission(BauweltMember bauweltMember) {
|
||||||
@@ -61,10 +86,10 @@ public enum Permission {
|
|||||||
|
|
||||||
public boolean hasPermission(Player member) {
|
public boolean hasPermission(Player member) {
|
||||||
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
||||||
return this != SPECTATOR;
|
return this != REAL_SPECTATOR;
|
||||||
}
|
}
|
||||||
BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
||||||
if (bauweltMember == null) return this == SPECTATOR;
|
if (bauweltMember == null) return this == REAL_SPECTATOR;
|
||||||
return permissionPredicate.test(bauweltMember);
|
return permissionPredicate.test(bauweltMember);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-2
@@ -32,7 +32,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.type.Chest;
|
import org.bukkit.block.data.type.Chest;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
@@ -121,7 +120,6 @@ public class AutostartListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
|
||||||
if (regionStartTime.isEmpty()) {
|
if (regionStartTime.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.bausystem.features.bau;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.command.PreviousArguments;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class ForceSpectatorCommand extends SWCommand {
|
||||||
|
|
||||||
|
public ForceSpectatorCommand() {
|
||||||
|
super("forcespectator");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void forceSpectator(@Validator("supervisor") Player player, @Mapper("builder") Player other) {
|
||||||
|
Permission.forceOnlySpectator(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mapper("builder")
|
||||||
|
public TypeMapper<Player> spectatorMapper() {
|
||||||
|
return new TypeMapper<>() {
|
||||||
|
@Override
|
||||||
|
public Player map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
Player player = Bukkit.getPlayer(s);
|
||||||
|
if (player == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (Permission.BUILD.hasPermission(player) && !Permission.SUPERVISOR.hasPermission(player)) {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||||
|
return Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(Permission.BUILD::hasPermission)
|
||||||
|
.filter(player -> !Permission.SUPERVISOR.hasPermission(player))
|
||||||
|
.map(Player::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
-39
@@ -21,10 +21,9 @@ package de.steamwar.bausystem.features.countingwand;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -32,32 +31,13 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Countingwand {
|
public class Countingwand {
|
||||||
|
|
||||||
@Data
|
|
||||||
public class CountingWandComponent implements SWPlayer.Component {
|
|
||||||
private Point pos1;
|
|
||||||
private Point pos2;
|
|
||||||
|
|
||||||
public boolean setPosition(boolean pos1, Point point) {
|
|
||||||
if (this.pos1 == null || this.pos2 == null) {
|
|
||||||
this.pos1 = point;
|
|
||||||
this.pos2 = point;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Point current = pos1 ? this.pos1 : this.pos2;
|
|
||||||
if (current.equals(point)) return false;
|
|
||||||
if (pos1) {
|
|
||||||
this.pos1 = point;
|
|
||||||
} else {
|
|
||||||
this.pos2 = point;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getWandItem(Player player) {
|
public static ItemStack getWandItem(Player player) {
|
||||||
ItemStack itemStack = new SWItem(Material.STICK, BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE1", player), BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE2", player)), false, null).getItemStack();
|
ItemStack itemStack = new SWItem(Material.STICK, BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE1", player), BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE2", player)), false, null).getItemStack();
|
||||||
ItemUtils.setItem(itemStack, "countingwand");
|
ItemUtils.setItem(itemStack, "countingwand");
|
||||||
@@ -67,20 +47,61 @@ public class Countingwand {
|
|||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCountingwand(ItemStack itemStack) {
|
private final Map<String, Pair<Point, Point>> selections = new HashMap<>();
|
||||||
return ItemUtils.isItem(itemStack, "countingwand");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkSelection(final Point point, final boolean pos1, final Player p) {
|
public boolean isCountingwand(ItemStack itemStack) {
|
||||||
SWPlayer player = SWPlayer.of(p);
|
return ItemUtils.isItem(itemStack, "countingwand");
|
||||||
CountingWandComponent countingWandComponent = player.getComponentOrDefault(CountingWandComponent.class, CountingWandComponent::new);
|
}
|
||||||
if (countingWandComponent.setPosition(pos1, point)) {
|
|
||||||
Point point1 = countingWandComponent.pos1;
|
public void checkSelection(final Point point, final boolean pos1, final Player p) {
|
||||||
Point point2 = countingWandComponent.pos2;
|
Pair<Point, Point> selection = selections.get(p.getUniqueId().toString());
|
||||||
int amount = (Math.abs(point1.getX() - point2.getX()) + 1) * (Math.abs(point1.getY() - point2.getY()) + 1) * (Math.abs(point1.getZ() - point2.getZ()) + 1);
|
final boolean newPos;
|
||||||
String dimension = player.using(BauSystem.MESSAGE).parse("COUNTINGWAND_MESSAGE_VOLUME", amount);
|
if (selection != null) {
|
||||||
String volume = player.parse("COUNTINGWAND_MESSAGE_DIMENSION", Math.abs(point1.getX() - point2.getX()) + 1, Math.abs(point1.getY() - point2.getY()) + 1, Math.abs(point1.getZ() - point2.getZ()) + 1);
|
if (pos1) {
|
||||||
player.sendMessage(pos1 ? "COUNTINGWAND_MESSAGE_RCLICK" : "COUNTINGWAND_MESSAGE_LCLICK", point.getX(), point.getY(), point.getZ(), dimension, volume);
|
newPos = !point.equals(selection.setKey(point));
|
||||||
}
|
} else {
|
||||||
}
|
newPos = !point.equals(selection.setValue(point));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (pos1) {
|
||||||
|
selection = new Pair<>(point, null);
|
||||||
|
} else {
|
||||||
|
selection = new Pair<>(null, point);
|
||||||
|
}
|
||||||
|
selections.put(p.getUniqueId().toString(), selection);
|
||||||
|
newPos = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPos) {
|
||||||
|
String dimension = getDimensions(p, selection.getKey(), selection.getValue());
|
||||||
|
String volume = getVolume(p, selection.getKey(), selection.getValue());
|
||||||
|
if (pos1) {
|
||||||
|
BauSystem.MESSAGE.send("COUNTINGWAND_MESSAGE_RCLICK", p, point.getX(), point.getY(), point.getZ(), dimension, volume);
|
||||||
|
} else {
|
||||||
|
BauSystem.MESSAGE.send("COUNTINGWAND_MESSAGE_LCLICK", p, point.getX(), point.getY(), point.getZ(), dimension, volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayer(Player p) {
|
||||||
|
selections.remove(p.getUniqueId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVolume(Player player, final Point point1, final Point point2) {
|
||||||
|
if (point1 == null || point2 == null) {
|
||||||
|
return BauSystem.MESSAGE.parse("COUNTINGWAND_MESSAGE_VOLUME", player, 0);
|
||||||
|
}
|
||||||
|
return BauSystem.MESSAGE.parse("COUNTINGWAND_MESSAGE_VOLUME", player, getAmount(point1, point2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDimensions(Player player, final Point point1, final Point point2) {
|
||||||
|
if (point1 == null || point2 == null) {
|
||||||
|
return BauSystem.MESSAGE.parse("COUNTINGWAND_MESSAGE_DIMENSION", player, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return BauSystem.MESSAGE.parse("COUNTINGWAND_MESSAGE_DIMENSION", player, Math.abs(point1.getX() - point2.getX()) + 1, Math.abs(point1.getY() - point2.getY()) + 1, Math.abs(point1.getZ() - point2.getZ()) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount(final Point point1, final Point point2) {
|
||||||
|
return (Math.abs(point1.getX() - point2.getX()) + 1) * (Math.abs(point1.getY() - point2.getY()) + 1) * (Math.abs(point1.getZ() - point2.getZ()) + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
@@ -27,6 +27,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.util.RayTraceResult;
|
import org.bukkit.util.RayTraceResult;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -66,4 +67,9 @@ public class CountingwandListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Countingwand.checkSelection(Point.fromLocation(Objects.requireNonNull(event.getClickedBlock()).getLocation()), false, event.getPlayer());
|
Countingwand.checkSelection(Point.fromLocation(Objects.requireNonNull(event.getClickedBlock()).getLocation()), false, event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLeave(PlayerQuitEvent event) {
|
||||||
|
Countingwand.removePlayer(event.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+14
-29
@@ -25,11 +25,8 @@ import de.steamwar.bausystem.configplayer.Config;
|
|||||||
import de.steamwar.bausystem.features.autostart.AutostartListener;
|
import de.steamwar.bausystem.features.autostart.AutostartListener;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -48,28 +45,7 @@ import java.util.*;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Detonator {
|
public class Detonator {
|
||||||
|
|
||||||
public class DetonatorComponent implements SWPlayer.Component {
|
private static final Map<Player, REntityServer> ENTITIES_MAP = new HashMap<>();
|
||||||
private final REntityServer entities = new REntityServer();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private boolean hasUpdated = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMount(SWPlayer player) {
|
|
||||||
entities.addPlayer(player.getPlayer());
|
|
||||||
entities.setCallback((player1, entity, action) -> {
|
|
||||||
Vector vector = new Vector(entity.getX(), entity.getY(), entity.getZ());
|
|
||||||
DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnmount(SWPlayer player) {
|
|
||||||
entities.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Vector HALF = new Vector(0.5, 0, 0.5);
|
private static final Vector HALF = new Vector(0.5, 0, 0.5);
|
||||||
|
|
||||||
public static boolean isDetonator(ItemStack itemStack) {
|
public static boolean isDetonator(ItemStack itemStack) {
|
||||||
@@ -77,19 +53,28 @@ public class Detonator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showDetonator(Player p, List<Location> locs) {
|
public static void showDetonator(Player p, List<Location> locs) {
|
||||||
DetonatorComponent detonatorComponent = SWPlayer.of(p).getComponentOrDefault(DetonatorComponent.class, DetonatorComponent::new);
|
if (ENTITIES_MAP.containsKey(p)) return;
|
||||||
|
REntityServer entities = new REntityServer();
|
||||||
|
entities.setCallback((player, rEntity, entityAction) -> {
|
||||||
|
Vector vector = new Vector(rEntity.getX(), rEntity.getY(), rEntity.getZ());
|
||||||
|
DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player);
|
||||||
|
DetonatorListener.HAS_UPDATED.add(player);
|
||||||
|
});
|
||||||
|
entities.addPlayer(p);
|
||||||
|
ENTITIES_MAP.put(p, entities);
|
||||||
|
|
||||||
locs.forEach(location -> {
|
locs.forEach(location -> {
|
||||||
RFallingBlockEntity entity = new RFallingBlockEntity(detonatorComponent.entities, location.clone().add(HALF), Material.RED_STAINED_GLASS);
|
RFallingBlockEntity entity = new RFallingBlockEntity(entities, location.clone().add(HALF), Material.RED_STAINED_GLASS);
|
||||||
entity.setNoGravity(true);
|
entity.setNoGravity(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void hideDetonator(Player p) {
|
public static void hideDetonator(Player p) {
|
||||||
SWPlayer.of(p).removeComponent(DetonatorComponent.class);
|
ENTITIES_MAP.remove(p).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasActiveDetonatorShow(Player p) {
|
public static boolean hasActiveDetonatorShow(Player p) {
|
||||||
return SWPlayer.of(p).hasComponent(DetonatorComponent.class);
|
return ENTITIES_MAP.containsKey(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void activateDetonator(DetonatorStorage detonator) {
|
public static void activateDetonator(DetonatorStorage detonator) {
|
||||||
|
|||||||
+32
-24
@@ -24,7 +24,6 @@ import de.steamwar.bausystem.Permission;
|
|||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -37,11 +36,15 @@ import org.bukkit.event.player.PlayerItemHeldEvent;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class DetonatorListener implements Listener {
|
public class DetonatorListener implements Listener {
|
||||||
|
|
||||||
|
static final Set<Player> HAS_UPDATED = new HashSet<>();
|
||||||
|
|
||||||
static void addLocationToDetonator(Location location, Player p) {
|
static void addLocationToDetonator(Location location, Player p) {
|
||||||
SWPlayer.of(p).getComponent(Detonator.DetonatorComponent.class).ifPresent(detonatorComponent -> detonatorComponent.setHasUpdated(true));
|
|
||||||
Detoblock detoblock = Detonator.getBlock(location.getBlock());
|
Detoblock detoblock = Detonator.getBlock(location.getBlock());
|
||||||
if (detoblock == Detoblock.INVALID) {
|
if (detoblock == Detoblock.INVALID) {
|
||||||
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_INVALID_BLOCK", p));
|
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_INVALID_BLOCK", p));
|
||||||
@@ -63,59 +66,64 @@ public class DetonatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
if (Detonator.isDetonator(p.getInventory().getItemInMainHand())) {
|
if (Detonator.isDetonator(p.getInventory().getItemInMainHand())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
addLocationToDetonator(event.getBlock().getLocation(), p);
|
addLocationToDetonator(event.getBlock().getLocation(), p);
|
||||||
|
HAS_UPDATED.add(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
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 (!Detonator.isDetonator(event.getItem())) return;
|
if (!Detonator.isDetonator(event.getItem())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
DetonatorStorage detonator = new ItemStorage(event.getPlayer());
|
DetonatorStorage detonator = new ItemStorage(event.getPlayer());
|
||||||
Detonator.activateDetonator(detonator);
|
Detonator.activateDetonator(detonator);
|
||||||
SWPlayer.of(event.getPlayer()).getComponent(Detonator.DetonatorComponent.class).ifPresent(detonatorComponent -> detonatorComponent.setHasUpdated(true));
|
HAS_UPDATED.add(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer()) || !Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer()) ||!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||||
if (Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
if (Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
||||||
Detonator.hideDetonator(event.getPlayer());
|
Detonator.hideDetonator(event.getPlayer());
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
|
if (!Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
||||||
|
Detonator.showDetonator(event.getPlayer(), new ItemStorage(event.getPlayer()).getLocations());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
|
||||||
Detonator.showDetonator(event.getPlayer(), new ItemStorage(event.getPlayer()).getLocations());
|
if (HAS_UPDATED.contains(event.getPlayer())) {
|
||||||
return;
|
HAS_UPDATED.remove(event.getPlayer());
|
||||||
|
if (Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
||||||
|
Detonator.hideDetonator(event.getPlayer());
|
||||||
|
Detonator.showDetonator(event.getPlayer(), new ItemStorage(event.getPlayer()).getLocations());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Detonator.DetonatorComponent component = SWPlayer.of(event.getPlayer())
|
|
||||||
.getComponentAndFilter(Detonator.DetonatorComponent.class, Detonator.DetonatorComponent::isHasUpdated)
|
|
||||||
.orElse(null);
|
|
||||||
if (component == null) return;
|
|
||||||
component.setHasUpdated(false);
|
|
||||||
Detonator.hideDetonator(event.getPlayer());
|
|
||||||
Detonator.showDetonator(event.getPlayer(), new ItemStorage(event.getPlayer()).getLocations());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) return;
|
if (Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||||
SWPlayer.of(event.getPlayer()).getComponent(Detonator.DetonatorComponent.class).ifPresent(detonatorComponent -> detonatorComponent.setHasUpdated(true));
|
HAS_UPDATED.add(event.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!(Detonator.isDetonator(event.getMainHandItem()) || Detonator.isDetonator(event.getOffHandItem()))) return;
|
if (Detonator.isDetonator(event.getMainHandItem()) || Detonator.isDetonator(event.getOffHandItem())) {
|
||||||
SWPlayer.of(event.getPlayer()).getComponent(Detonator.DetonatorComponent.class).ifPresent(detonatorComponent -> detonatorComponent.setHasUpdated(true));
|
HAS_UPDATED.add(event.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
|||||||
import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT;
|
import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT;
|
||||||
import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait;
|
import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait;
|
||||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
@@ -41,17 +40,21 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class Loader implements Listener, SWPlayer.Component {
|
public class Loader implements Listener {
|
||||||
|
|
||||||
|
private static final Map<Player, Loader> LOADER_MAP = new HashMap<>();
|
||||||
|
|
||||||
public static Loader getLoader(Player player) {
|
public static Loader getLoader(Player player) {
|
||||||
return SWPlayer.of(player).getComponent(Loader.class).orElse(null);
|
return LOADER_MAP.get(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void newLoader(Player player) {
|
public static void newLoader(Player player) {
|
||||||
SWPlayer.of(player).setComponent(new Loader(player));
|
LOADER_MAP.put(player, new Loader(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Player p;
|
private final Player p;
|
||||||
@@ -142,7 +145,7 @@ public class Loader implements Listener, SWPlayer.Component {
|
|||||||
recorder = null;
|
recorder = null;
|
||||||
}
|
}
|
||||||
elements.clear();
|
elements.clear();
|
||||||
SWPlayer.of(p).removeComponent(Loader.class);
|
LOADER_MAP.remove(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setTicksBetweenShots(int delay) {
|
public boolean setTicksBetweenShots(int delay) {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.bukkit.boss.BarColor;
|
|||||||
import org.bukkit.boss.BarStyle;
|
import org.bukkit.boss.BarStyle;
|
||||||
import org.bukkit.boss.BossBar;
|
import org.bukkit.boss.BossBar;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
@@ -157,7 +156,6 @@ public class Loadtimer implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onTntExplode(EntityExplodeEvent event) {
|
public void onTntExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
|
||||||
if (region.getBuildArea().inRegion(event.getLocation(), true) && stage == Stage.IGNITION) {
|
if (region.getBuildArea().inRegion(event.getLocation(), true) && stage == Stage.IGNITION) {
|
||||||
stage = Stage.END;
|
stage = Stage.END;
|
||||||
explode = TPSUtils.currentRealTick.get();
|
explode = TPSUtils.currentRealTick.get();
|
||||||
|
|||||||
+1
-2
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.observer;
|
|||||||
|
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.Reflection;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
@@ -35,7 +34,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ObserverTracer implements SWPlayer.Component {
|
public class ObserverTracer {
|
||||||
|
|
||||||
private static final Set<BlockFace> ALLOWED = EnumSet.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
|
private static final Set<BlockFace> ALLOWED = EnumSet.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.observer;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@@ -42,23 +41,23 @@ public class ObserverTracerCommand extends SWCommand {
|
|||||||
@Register(value = "disable", description = "OBSERVER_HELP_DISABLE")
|
@Register(value = "disable", description = "OBSERVER_HELP_DISABLE")
|
||||||
public void disable(Player p) {
|
public void disable(Player p) {
|
||||||
ObserverTracerListener.enabled.remove(p);
|
ObserverTracerListener.enabled.remove(p);
|
||||||
SWPlayer.of(p).removeComponent(ObserverTracer.class);
|
ObserverTracerListener.observerTracerMap.remove(p);
|
||||||
BauSystem.MESSAGE.send("OBSERVER_DISABLE", p);
|
BauSystem.MESSAGE.send("OBSERVER_DISABLE", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "delete", description = "OBSERVER_HELP_DELETE")
|
@Register(value = "delete", description = "OBSERVER_HELP_DELETE")
|
||||||
public void delete(@Validator Player p) {
|
public void delete(@Validator Player p) {
|
||||||
SWPlayer.of(p).removeComponent(ObserverTracer.class);
|
ObserverTracerListener.observerTracerMap.remove(p);
|
||||||
BauSystem.MESSAGE.send("OBSERVER_DELETE", p);
|
BauSystem.MESSAGE.send("OBSERVER_DELETE", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "retrace", description = "OBSERVER_HELP_RETRACE")
|
@Register(value = "retrace", description = "OBSERVER_HELP_RETRACE")
|
||||||
public void retrace(@Validator Player p) {
|
public void retrace(@Validator Player p) {
|
||||||
if (SWPlayer.of(p).hasComponent(ObserverTracer.class)) {
|
if (ObserverTracerListener.observerTracerMap.containsKey(p)) {
|
||||||
BauSystem.MESSAGE.send("OBSERVER_RETRACE_NO_TRACE", p);
|
BauSystem.MESSAGE.send("OBSERVER_RETRACE_NO_TRACE", p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SWPlayer.of(p).getComponent(ObserverTracer.class).ifPresent(ObserverTracer::trace);
|
ObserverTracerListener.observerTracerMap.get(p).trace();
|
||||||
BauSystem.MESSAGE.send("OBSERVER_RETRACE_DONE", p);
|
BauSystem.MESSAGE.send("OBSERVER_RETRACE_DONE", p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-12
@@ -22,7 +22,6 @@ package de.steamwar.bausystem.features.observer;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@@ -35,19 +34,23 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class ObserverTracerListener implements Listener {
|
public class ObserverTracerListener implements Listener {
|
||||||
|
|
||||||
static Set<Player> enabled = new HashSet<>();
|
static Set<Player> enabled = new HashSet<>();
|
||||||
|
static Map<Player, ObserverTracer> observerTracerMap = new HashMap<>();
|
||||||
|
|
||||||
public ObserverTracerListener() {
|
public ObserverTracerListener() {
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
SWPlayer.allWithSingleComponent(ObserverTracer.class).forEach(pair -> {
|
observerTracerMap.forEach((player, observerTracer) -> {
|
||||||
if (pair.getKey().getGameMode() != GameMode.SPECTATOR) return;
|
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
pair.getValue().show();
|
observerTracer.show();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, 15L, 15L);
|
}, 15L, 15L);
|
||||||
}
|
}
|
||||||
@@ -55,16 +58,20 @@ public class ObserverTracerListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
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 (!enabled.contains(event.getPlayer())) return;
|
if (!enabled.contains(event.getPlayer())) {
|
||||||
if (event.getClickedBlock() == null) return;
|
return;
|
||||||
ObserverTracer observerTracer = SWPlayer.of(event.getPlayer()).getComponent(ObserverTracer.class).orElse(null);
|
}
|
||||||
if (observerTracer != null) {
|
if (event.getClickedBlock() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (observerTracerMap.containsKey(event.getPlayer())) {
|
||||||
|
ObserverTracer observerTracer = observerTracerMap.get(event.getPlayer());
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
if (!observerTracer.trace()) {
|
if (!observerTracer.trace()) {
|
||||||
createNew(event);
|
createNew(event);
|
||||||
}
|
}
|
||||||
SWPlayer.allWithSingleComponent(ObserverTracer.class).forEach(pair -> {
|
observerTracerMap.forEach((player, o) -> {
|
||||||
pair.getValue().trace();
|
o.trace();
|
||||||
});
|
});
|
||||||
}, 1L);
|
}, 1L);
|
||||||
} else {
|
} else {
|
||||||
@@ -79,13 +86,13 @@ public class ObserverTracerListener implements Listener {
|
|||||||
if (event.getClickedBlock().getType() == Material.OBSERVER) {
|
if (event.getClickedBlock().getType() == Material.OBSERVER) {
|
||||||
ObserverTracer observerTracer = new ObserverTracer(event.getPlayer(), event.getClickedBlock());
|
ObserverTracer observerTracer = new ObserverTracer(event.getPlayer(), event.getClickedBlock());
|
||||||
observerTracer.trace();
|
observerTracer.trace();
|
||||||
SWPlayer.of(event.getPlayer()).setComponent(observerTracer);
|
observerTracerMap.put(event.getPlayer(), observerTracer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||||
event.getNewBuilder().forEach(player -> SWPlayer.of(player).removeComponent(ObserverTracer.class));
|
event.getNewSpectator().forEach(observerTracerMap::remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -96,5 +103,6 @@ public class ObserverTracerListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
enabled.remove(event.getPlayer());
|
enabled.remove(event.getPlayer());
|
||||||
|
observerTracerMap.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-12
@@ -26,10 +26,8 @@ import de.steamwar.bausystem.region.flags.Flag;
|
|||||||
import de.steamwar.bausystem.region.flags.TNTMode;
|
import de.steamwar.bausystem.region.flags.TNTMode;
|
||||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -41,14 +39,11 @@ import java.util.List;
|
|||||||
@Linked
|
@Linked
|
||||||
public class TNTListener implements Listener, ScoreboardElement {
|
public class TNTListener implements Listener, ScoreboardElement {
|
||||||
|
|
||||||
private void explode(List<Block> blockList, boolean destroy) {
|
private void explode(List<Block> blockList) {
|
||||||
blockList.removeIf(block -> {
|
blockList.removeIf(block -> {
|
||||||
Region region = Region.getRegion(block.getLocation());
|
Region region = Region.getRegion(block.getLocation());
|
||||||
TNTMode value = region.getFlags().get(Flag.TNT).getWithDefault();
|
TNTMode value = region.getFlags().get(Flag.TNT).getWithDefault();
|
||||||
if (value == TNTMode.ALLOW) {
|
if (value == TNTMode.ALLOW) {
|
||||||
if (destroy && block.getType() != Material.TNT) {
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
} else if (value == TNTMode.ONLY_TB) {
|
} else if (value == TNTMode.ONLY_TB) {
|
||||||
if (region.getBuildArea().inRegion(block.getLocation(), true)) {
|
if (region.getBuildArea().inRegion(block.getLocation(), true)) {
|
||||||
@@ -62,16 +57,12 @@ public class TNTListener implements Listener, ScoreboardElement {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockExplode(BlockExplodeEvent event) {
|
public void onBlockExplode(BlockExplodeEvent event) {
|
||||||
explode(event.blockList(), false);
|
explode(event.blockList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onExplode(EntityExplodeEvent event) {
|
public void onExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) {
|
explode(event.blockList());
|
||||||
event.blockList().clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
explode(event.blockList(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+23
-12
@@ -72,14 +72,6 @@ public class TestblockCommand extends SWCommand {
|
|||||||
resetRegion(p, node, isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL, isIgnoreAir, isOnlyColor, replaceTNT, replaceWater);
|
resetRegion(p, node, isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL, isIgnoreAir, isOnlyColor, replaceTNT, replaceWater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value="default")
|
|
||||||
public void setTestblockDefault(Player p) {
|
|
||||||
Region region = regionCheck(p);
|
|
||||||
if (region == null) return;
|
|
||||||
region.getRegionData().setTestblockSchematic(null);
|
|
||||||
resetRegion(p, null, RegionExtensionType.EXTENSION, false, false, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetRegion(Player p, SchematicNode node, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean removeTNT, boolean removeWater) {
|
private void resetRegion(Player p, SchematicNode node, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean removeTNT, boolean removeWater) {
|
||||||
Region region = regionCheck(p);
|
Region region = regionCheck(p);
|
||||||
if (region == null) return;
|
if (region == null) return;
|
||||||
@@ -100,10 +92,29 @@ public class TestblockCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node == null) {
|
// Beta Tester enabled
|
||||||
node = region.getRegionData().getTestblockSchematic();
|
switch (BauServer.getInstance().getOwnerID()) {
|
||||||
} else {
|
case 245:
|
||||||
region.getRegionData().setTestblockSchematic(node);
|
case 403:
|
||||||
|
case 1898:
|
||||||
|
case 3320:
|
||||||
|
case 4603:
|
||||||
|
case 5262:
|
||||||
|
case 5399:
|
||||||
|
case 6032:
|
||||||
|
case 7862:
|
||||||
|
case 11077:
|
||||||
|
case 11888:
|
||||||
|
case 12258:
|
||||||
|
case 16009:
|
||||||
|
if (node == null) {
|
||||||
|
node = region.getRegionData().getTestblockSchematic();
|
||||||
|
} else {
|
||||||
|
region.getRegionData().setTestblockSchematic(node);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
PasteBuilder.ClipboardProvider clipboardProvider;
|
PasteBuilder.ClipboardProvider clipboardProvider;
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ public class ScriptListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
playerSet.remove(event.getPlayer());
|
ScriptRunner.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|||||||
+13
-39
@@ -23,11 +23,8 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.features.script.lua.CommandRegister;
|
import de.steamwar.bausystem.features.script.lua.CommandRegister;
|
||||||
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
||||||
import de.steamwar.bausystem.features.script.lua.SteamWarPlatform;
|
import de.steamwar.bausystem.features.script.lua.SteamWarPlatform;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.sql.Script;
|
import de.steamwar.sql.Script;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
@@ -47,25 +44,12 @@ public class ScriptRunner {
|
|||||||
// Key -> bau-script-<BUCH NAME>
|
// Key -> bau-script-<BUCH NAME>
|
||||||
// Value -> <LUA Script>
|
// Value -> <LUA Script>
|
||||||
|
|
||||||
public class ScriptData implements SWPlayer.Component {
|
private static final Map<Player, Map<SteamWarGlobalLuaPlugin.EventType, List<LuaFunction>>> EVENT_MAP = new HashMap<>();
|
||||||
private Map<SteamWarGlobalLuaPlugin.EventType, List<LuaFunction>> events = new EnumMap<>(SteamWarGlobalLuaPlugin.EventType.class);
|
private static final Map<Player, Map<Hotkey, List<LuaFunction>>> HOTKEY_MAP = new HashMap<>();
|
||||||
private Map<Hotkey, List<LuaFunction>> hotkeys = new HashMap<>();
|
private static final Map<Player, Map<String, CommandRegister>> COMMAND_MAP = new HashMap<>();
|
||||||
private Map<String, CommandRegister> commands = new HashMap<>();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private Set<String> calledCommands = new HashSet<>();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private Long lastF = Long.MAX_VALUE;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private boolean ignore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getCommandsOfPlayer(Player player) {
|
public Set<String> getCommandsOfPlayer(Player player) {
|
||||||
return SWPlayer.of(player).getComponentOrDefault(ScriptData.class, ScriptData::new).commands.keySet();
|
return COMMAND_MAP.getOrDefault(player, new HashMap<>()).keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runScript(String script, Player player) {
|
public static void runScript(String script, Player player) {
|
||||||
@@ -80,12 +64,10 @@ public class ScriptRunner {
|
|||||||
|
|
||||||
public static void createGlobalScript(List<String> scripts, Player player) {
|
public static void createGlobalScript(List<String> scripts, Player player) {
|
||||||
remove(player);
|
remove(player);
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
|
||||||
ScriptData scriptData = swPlayer.getComponentOrDefault(ScriptData.class, ScriptData::new);
|
|
||||||
Globals globals = SteamWarPlatform.createGlobalGlobals(player,
|
Globals globals = SteamWarPlatform.createGlobalGlobals(player,
|
||||||
(s, luaFunction) -> scriptData.events.computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction),
|
(s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new EnumMap<>(SteamWarGlobalLuaPlugin.EventType.class)).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction),
|
||||||
(s, luaFunction) -> scriptData.hotkeys.computeIfAbsent(Hotkey.fromString(s), s1 -> new ArrayList<>()).add(luaFunction),
|
(s, luaFunction) -> HOTKEY_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(Hotkey.fromString(s), s1 -> new ArrayList<>()).add(luaFunction),
|
||||||
commandRegister -> scriptData.commands.put(commandRegister.getName(), commandRegister));
|
commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister));
|
||||||
|
|
||||||
for (String script : scripts) {
|
for (String script : scripts) {
|
||||||
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> globals.load(script).call());
|
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> globals.load(script).call());
|
||||||
@@ -93,14 +75,13 @@ public class ScriptRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void remove(Player player) {
|
public static void remove(Player player) {
|
||||||
SWPlayer.of(player).removeComponent(ScriptData.class);
|
EVENT_MAP.remove(player);
|
||||||
|
COMMAND_MAP.remove(player);
|
||||||
|
HOTKEY_MAP.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue, Event wrappedEvent) {
|
public static void callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue, Event wrappedEvent) {
|
||||||
List<LuaFunction> luaFunctions = SWPlayer.of(player).getComponent(ScriptData.class)
|
List<LuaFunction> luaFunctions = EVENT_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(event, Collections.emptyList());
|
||||||
.map(scriptData -> scriptData.events)
|
|
||||||
.orElse(Collections.emptyMap())
|
|
||||||
.getOrDefault(event, Collections.emptyList());
|
|
||||||
if (luaFunctions.isEmpty()) {
|
if (luaFunctions.isEmpty()) {
|
||||||
if(event == SteamWarGlobalLuaPlugin.EventType.DoubleSwap) {
|
if(event == SteamWarGlobalLuaPlugin.EventType.DoubleSwap) {
|
||||||
player.performCommand("gui");
|
player.performCommand("gui");
|
||||||
@@ -143,10 +124,7 @@ public class ScriptRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean callCommand(Player player, String command, String[] argsArray) {
|
public static boolean callCommand(Player player, String command, String[] argsArray) {
|
||||||
CommandRegister commandRegister = SWPlayer.of(player).getComponent(ScriptData.class)
|
CommandRegister commandRegister = COMMAND_MAP.getOrDefault(player, Collections.emptyMap()).get(command);
|
||||||
.map(scriptData -> scriptData.commands)
|
|
||||||
.orElse(Collections.emptyMap())
|
|
||||||
.get(command);
|
|
||||||
if (commandRegister == null) {
|
if (commandRegister == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -210,11 +188,7 @@ public class ScriptRunner {
|
|||||||
|
|
||||||
public static void callHotkey(int mods, int key, Player player, boolean pressed) {
|
public static void callHotkey(int mods, int key, Player player, boolean pressed) {
|
||||||
Hotkey hotkey = Hotkey.fromChar(key, mods);
|
Hotkey hotkey = Hotkey.fromChar(key, mods);
|
||||||
List<LuaFunction> hotkeys = SWPlayer.of(player).getComponent(ScriptData.class)
|
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))));
|
||||||
.map(scriptData -> scriptData.hotkeys)
|
|
||||||
.orElse(Collections.emptyMap())
|
|
||||||
.getOrDefault(hotkey, Collections.emptyList());
|
|
||||||
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> hotkeys.forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void catchScript(String errorMsg, Player player, Runnable run) {
|
public static void catchScript(String errorMsg, Player player, Runnable run) {
|
||||||
|
|||||||
+25
-5
@@ -21,24 +21,44 @@ package de.steamwar.bausystem.features.script.event;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class CommandListener implements Listener {
|
public class CommandListener implements Listener {
|
||||||
|
|
||||||
|
private Map<Player, Set<String>> calledCommands = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
String[] split = event.getMessage().split(" ");
|
String[] split = event.getMessage().split(" ");
|
||||||
ScriptRunner.ScriptData scriptData = SWPlayer.of(event.getPlayer()).getComponentOrDefault(ScriptRunner.ScriptData.class, ScriptRunner.ScriptData::new);
|
if (calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).contains(split[0])) {
|
||||||
if (scriptData.getCalledCommands().contains(split[0])) return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
scriptData.getCalledCommands().add(split[0]);
|
calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).add(split[0]);
|
||||||
event.setCancelled(ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), split));
|
event.setCancelled(ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), split));
|
||||||
scriptData.getCalledCommands().remove(split[0]);
|
calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).remove(split[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
calledCommands.put(event.getPlayer(), new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
calledCommands.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-23
@@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.script.ScriptRunner;
|
|||||||
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
||||||
import de.steamwar.bausystem.features.script.lua.libs.StorageLib;
|
import de.steamwar.bausystem.features.script.lua.libs.StorageLib;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.core.TrickyTrialsWrapper;
|
import de.steamwar.core.TrickyTrialsWrapper;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -44,27 +43,32 @@ import org.bukkit.event.player.*;
|
|||||||
import org.luaj.vm2.LuaTable;
|
import org.luaj.vm2.LuaTable;
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class EventListener implements Listener {
|
public class EventListener implements Listener {
|
||||||
|
|
||||||
|
private static final Map<Player, Long> LAST_FS = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
long millis = System.currentTimeMillis();
|
long millis = System.currentTimeMillis();
|
||||||
SWPlayer.allWithSingleComponent(ScriptRunner.ScriptData.class)
|
LAST_FS.entrySet().removeIf(entry -> millis - entry.getValue() > 200);
|
||||||
.filter(pair -> millis - pair.getValue().getLastF() > 200)
|
|
||||||
.forEach(pair -> pair.getValue().setLastF(Long.MAX_VALUE));
|
|
||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL, event);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
if (Permission.BUILD.hasPermission(event.getPlayer())) {
|
if(Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event);
|
||||||
}
|
}
|
||||||
StorageLib.removePlayer(event.getPlayer());
|
StorageLib.removePlayer(event.getPlayer());
|
||||||
@@ -72,20 +76,19 @@ public class EventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
ScriptRunner.ScriptData scriptData = SWPlayer.of(event.getPlayer()).getComponentOrDefault(ScriptRunner.ScriptData.class, ScriptRunner.ScriptData::new);
|
if (LAST_FS.containsKey(event.getPlayer())) {
|
||||||
if (scriptData.getLastF() != Long.MAX_VALUE) {
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL, event);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL, event);
|
||||||
}, 1);
|
}, 1);
|
||||||
} else {
|
} else {
|
||||||
scriptData.setLastF(System.currentTimeMillis());
|
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("x", event.getBlock().getX());
|
table.set("x", event.getBlock().getX());
|
||||||
table.set("y", event.getBlock().getY());
|
table.set("y", event.getBlock().getY());
|
||||||
@@ -96,7 +99,7 @@ public class EventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("x", event.getBlock().getX());
|
table.set("x", event.getBlock().getX());
|
||||||
table.set("y", event.getBlock().getY());
|
table.set("y", event.getBlock().getY());
|
||||||
@@ -105,12 +108,12 @@ public class EventListener implements Listener {
|
|||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table, event);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Set<Player> ignore = new HashSet<>();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
ScriptRunner.ScriptData scriptData = SWPlayer.of(event.getPlayer()).getComponentOrDefault(ScriptRunner.ScriptData.class, ScriptRunner.ScriptData::new);
|
if (ignore.remove(event.getPlayer())) {
|
||||||
if (scriptData.isIgnore()) {
|
|
||||||
scriptData.setIgnore(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
@@ -121,7 +124,7 @@ public class EventListener implements Listener {
|
|||||||
table.set("hand", event.getHand().name());
|
table.set("hand", event.getHand().name());
|
||||||
}
|
}
|
||||||
table.set("block", event.getItem() == null ? Material.AIR.name() : event.getItem().getType().name());
|
table.set("block", event.getItem() == null ? Material.AIR.name() : event.getItem().getType().name());
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
table.set("hasBlock", LuaValue.valueOf(true));
|
table.set("hasBlock", LuaValue.valueOf(true));
|
||||||
table.set("blockX", event.getClickedBlock().getX());
|
table.set("blockX", event.getClickedBlock().getX());
|
||||||
table.set("blockY", event.getClickedBlock().getY());
|
table.set("blockY", event.getClickedBlock().getY());
|
||||||
@@ -147,7 +150,7 @@ public class EventListener implements Listener {
|
|||||||
Region tntRegion = Region.getRegion(event.getLocation());
|
Region tntRegion = Region.getRegion(event.getLocation());
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!Permission.BUILD.hasPermission(player)) continue;
|
if(!Permission.BUILD.hasPermission(player)) continue;
|
||||||
if (tntRegion.getArea().inRegion(player.getLocation(), false)) {
|
if (tntRegion.getArea().inRegion(player.getLocation(), false)) {
|
||||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL, event);
|
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL, event);
|
||||||
}
|
}
|
||||||
@@ -169,7 +172,7 @@ public class EventListener implements Listener {
|
|||||||
boolean inBuild = event.blockList().stream().anyMatch(block -> tntRegion.getBuildArea().inRegion(block.getLocation(), true));
|
boolean inBuild = event.blockList().stream().anyMatch(block -> tntRegion.getBuildArea().inRegion(block.getLocation(), true));
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!Permission.BUILD.hasPermission(player)) continue;
|
if(!Permission.BUILD.hasPermission(player)) continue;
|
||||||
if (tntRegion.getArea().inRegion(player.getLocation(), false)) {
|
if (tntRegion.getArea().inRegion(player.getLocation(), false)) {
|
||||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table, event);
|
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table, event);
|
||||||
if (inBuild) {
|
if (inBuild) {
|
||||||
@@ -181,9 +184,8 @@ public class EventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
ScriptRunner.ScriptData scriptData = SWPlayer.of(event.getPlayer()).getComponentOrDefault(ScriptRunner.ScriptData.class, ScriptRunner.ScriptData::new);
|
ignore.add(event.getPlayer());
|
||||||
scriptData.setIgnore(true);
|
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("type", event.getItemDrop().getItemStack().getType().name());
|
table.set("type", event.getItemDrop().getItemStack().getType().name());
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table, event);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table, event);
|
||||||
@@ -192,7 +194,7 @@ public class EventListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!Permission.BUILD.hasPermission(player)) continue;
|
if(!Permission.BUILD.hasPermission(player)) continue;
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("type", event.getEntityType().name());
|
table.set("type", event.getEntityType().name());
|
||||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table, event);
|
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table, event);
|
||||||
|
|||||||
+1
-2
@@ -48,7 +48,6 @@ import java.util.logging.Level;
|
|||||||
public class SteamWarLuaPlugin extends TwoArgFunction {
|
public class SteamWarLuaPlugin extends TwoArgFunction {
|
||||||
|
|
||||||
private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null;
|
private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null;
|
||||||
private static final Set<String> ignoreCommandFromWorldEdit = Set.of("select", "schem", "/schem", "schematic", "/schematic");
|
|
||||||
|
|
||||||
protected static final Map<Class<?>, List<LuaLib>> LUA_LIBS = new HashMap<>();
|
protected static final Map<Class<?>, List<LuaLib>> LUA_LIBS = new HashMap<>();
|
||||||
|
|
||||||
@@ -117,7 +116,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
|
|||||||
command = preprocessEvent.getMessage().substring(1);
|
command = preprocessEvent.getMessage().substring(1);
|
||||||
Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command);
|
Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command);
|
||||||
String[] commandSplit = command.split(" ");
|
String[] commandSplit = command.split(" ");
|
||||||
if (!ignoreCommandFromWorldEdit.contains(commandSplit[0]) && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) {
|
if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) {
|
||||||
EditSession editSession = WorldEditUtils.getEditSession(player);
|
EditSession editSession = WorldEditUtils.getEditSession(player);
|
||||||
Actor actor = BukkitAdapter.adapt(player);
|
Actor actor = BukkitAdapter.adapt(player);
|
||||||
WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession));
|
WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession));
|
||||||
|
|||||||
-2
@@ -26,7 +26,6 @@ import de.steamwar.bausystem.utils.PasteBuilder;
|
|||||||
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -52,7 +51,6 @@ public class StabGenerator extends StabStep implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
|
||||||
if (Region.getRegion(event.getEntity().getLocation()) == data.region) {
|
if (Region.getRegion(event.getEntity().getLocation()) == data.region) {
|
||||||
event.blockList().forEach(block -> {
|
event.blockList().forEach(block -> {
|
||||||
if (!data.region.getTestblockArea().inRegion(block.getLocation(), true))
|
if (!data.region.getTestblockArea().inRegion(block.getLocation(), true))
|
||||||
|
|||||||
+44
-34
@@ -20,14 +20,17 @@
|
|||||||
package de.steamwar.bausystem.features.slaves.laufbau;
|
package de.steamwar.bausystem.features.slaves.laufbau;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.sql.UserConfig;
|
import de.steamwar.sql.UserConfig;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import yapion.hierarchy.output.StreamOutput;
|
import yapion.hierarchy.output.StreamOutput;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
@@ -36,45 +39,44 @@ import yapion.parser.options.StreamOptions;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
@UtilityClass
|
@Linked
|
||||||
public class LaufbauUtils {
|
public class LaufbauUtils implements Listener {
|
||||||
|
|
||||||
public static class LaufbauComponent implements SWPlayer.Component {
|
private static Map<Player, YAPIONObject> yapionObjectMap = new HashMap<>();
|
||||||
|
|
||||||
private YAPIONObject yapionObject = new YAPIONObject();
|
@EventHandler
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
@SneakyThrows
|
String config = UserConfig.getConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau");
|
||||||
public void onMount(SWPlayer player) {
|
if (config == null) {
|
||||||
String config = UserConfig.getConfig(player.getPlayer().getUniqueId(), "bausystem-laufbau");
|
return;
|
||||||
if (config == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
byte[] bytes = Base64.getDecoder().decode(config);
|
|
||||||
@Cleanup GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
|
|
||||||
yapionObject = new YAPIONParser(gzipInputStream, new StreamOptions().stopOnStreamEnd(true)).parse().result();
|
|
||||||
}
|
}
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(config);
|
||||||
|
@Cleanup GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
|
||||||
|
YAPIONObject yapionObject = new YAPIONParser(gzipInputStream, new StreamOptions().stopOnStreamEnd(true)).parse().result();
|
||||||
|
yapionObjectMap.put(event.getPlayer(), yapionObject);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@EventHandler
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void onUnmount(SWPlayer player) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
if (yapionObject.isEmpty()) {
|
YAPIONObject yapionObject = yapionObjectMap.get(event.getPlayer());
|
||||||
UserConfig.removePlayerConfig(player.getPlayer().getUniqueId(), "bausystem-laufbau");
|
if (yapionObject == null) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
@Cleanup ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
||||||
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
|
|
||||||
yapionObject.toYAPION(new StreamOutput(gzipOutputStream)).close();
|
|
||||||
UserConfig.updatePlayerConfig(player.getPlayer().getUniqueId(), "bausystem-laufbau", Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()));
|
|
||||||
}
|
}
|
||||||
|
if (yapionObject.isEmpty()) {
|
||||||
|
UserConfig.removePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@Cleanup ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
|
||||||
|
yapionObject.toYAPION(new StreamOutput(gzipOutputStream)).close();
|
||||||
|
UserConfig.updatePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau", Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) {
|
public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) {
|
||||||
@@ -123,7 +125,11 @@ public class LaufbauUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String identifier = identifier(bb);
|
String identifier = identifier(bb);
|
||||||
return SWPlayer.of(p).getComponentOrDefault(LaufbauComponent.class, LaufbauComponent::new).yapionObject.containsKey(identifier);
|
YAPIONObject yapionObject = yapionObjectMap.get(p);
|
||||||
|
if (yapionObject == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return yapionObject.containsKey(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -132,7 +138,11 @@ public class LaufbauUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String identifier = identifier(bb);
|
String identifier = identifier(bb);
|
||||||
YAPIONObject yapionObject = SWPlayer.of(p).getComponentOrDefault(LaufbauComponent.class, LaufbauComponent::new).yapionObject;
|
YAPIONObject yapionObject = yapionObjectMap.get(p);
|
||||||
|
if (yapionObject == null) {
|
||||||
|
yapionObject = new YAPIONObject();
|
||||||
|
yapionObjectMap.put(p, yapionObject);
|
||||||
|
}
|
||||||
if (yapionObject.containsKey(identifier)) {
|
if (yapionObject.containsKey(identifier)) {
|
||||||
yapionObject.remove(identifier);
|
yapionObject.remove(identifier);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-2
@@ -107,7 +107,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
|
|||||||
@Override
|
@Override
|
||||||
public Player map(CommandSender commandSender, String[] previousArguments, String s) {
|
public Player map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
Player player = Bukkit.getPlayer(s);
|
Player player = Bukkit.getPlayer(s);
|
||||||
if (player != null && Permission.SPECTATOR.hasPermission(player)) {
|
if (player != null && Permission.REAL_SPECTATOR.hasPermission(player)) {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -116,7 +116,7 @@ public class TechHiderCommand extends SWCommand implements Listener, ScoreboardE
|
|||||||
@Override
|
@Override
|
||||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||||
return Bukkit.getOnlinePlayers().stream()
|
return Bukkit.getOnlinePlayers().stream()
|
||||||
.filter(Permission.SPECTATOR::hasPermission)
|
.filter(Permission.REAL_SPECTATOR::hasPermission)
|
||||||
.map(Player::getName)
|
.map(Player::getName)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -22,7 +22,6 @@ package de.steamwar.bausystem.features.testblock.blockcounter;
|
|||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
@@ -35,7 +34,6 @@ public class BlockCounterListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
|
||||||
Region region = Region.getRegion(event.getLocation());
|
Region region = Region.getRegion(event.getLocation());
|
||||||
if (region.getType().isGlobal()) {
|
if (region.getType().isGlobal()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-10
@@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.tls;
|
package de.steamwar.bausystem.features.tntlistener;
|
||||||
|
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
@@ -43,13 +43,4 @@ public class TLSCommand extends SWCommand {
|
|||||||
public void stop(@Validator Player player) {
|
public void stop(@Validator Player player) {
|
||||||
listener.stopListening(player);
|
listener.stopListening(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(description = "TLS_TOGGLE_HELP")
|
|
||||||
public void toggle(@Validator Player player) {
|
|
||||||
if (listener.isActiveFor(player)) {
|
|
||||||
listener.stopListening(player);
|
|
||||||
} else {
|
|
||||||
listener.startListening(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.tls;
|
package de.steamwar.bausystem.features.tntlistener;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.tls;
|
package de.steamwar.bausystem.features.tntlistener;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
+7
-7
@@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.util;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -40,11 +39,10 @@ public class GamemodeCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void genericCommand(final Player p) {
|
public void genericCommand(final Player p) {
|
||||||
SWPlayer swPlayer = SWPlayer.of(p);
|
if (NoClipCommand.getNOCLIPS().contains(p)) {
|
||||||
if (swPlayer.hasComponent(NoClipCommand.NoClipData.class)) {
|
p.performCommand("noclip");
|
||||||
swPlayer.removeComponent(NoClipCommand.NoClipData.class);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
if (p.getGameMode() == GameMode.CREATIVE) {
|
if (p.getGameMode() == GameMode.CREATIVE) {
|
||||||
p.setGameMode(GameMode.SPECTATOR);
|
p.setGameMode(GameMode.SPECTATOR);
|
||||||
} else {
|
} else {
|
||||||
@@ -54,7 +52,9 @@ public class GamemodeCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void gamemodeCommand(final Player p, final GameMode gameMode) {
|
public void gamemodeCommand(final Player p, final GameMode gameMode) {
|
||||||
SWPlayer.of(p).removeComponent(NoClipCommand.NoClipData.class);
|
if (NoClipCommand.getNOCLIPS().contains(p)) {
|
||||||
|
p.performCommand("noclip");
|
||||||
|
}
|
||||||
p.setGameMode(gameMode);
|
p.setGameMode(gameMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+48
-37
@@ -26,7 +26,6 @@ import de.steamwar.bausystem.shared.EnumDisplay;
|
|||||||
import de.steamwar.command.PreviousArguments;
|
import de.steamwar.command.PreviousArguments;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.data.CMDs;
|
import de.steamwar.data.CMDs;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
@@ -57,9 +56,11 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
WorldEditListener.addCommandExclusion("material");
|
WorldEditListener.addCommandExclusion("material");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<Player, Search> searchMap = new HashMap<>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class SearchParameter implements SWPlayer.Component {
|
static class Search {
|
||||||
SearchType transparent = SearchType.IGNORE;
|
SearchType transparent = SearchType.IGNORE;
|
||||||
SearchType solid = SearchType.IGNORE;
|
SearchType solid = SearchType.IGNORE;
|
||||||
SearchType gravity = SearchType.IGNORE;
|
SearchType gravity = SearchType.IGNORE;
|
||||||
@@ -103,10 +104,10 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void materialGUI(Player p) {
|
public void materialGUI(Player p) {
|
||||||
materialGUI(p, SWPlayer.of(p).getComponentOrDefault(SearchParameter.class, SearchParameter::new));
|
materialGUI(p, searchMap.get(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, BiConsumer<SearchParameter, SearchType>> elements = new HashMap<>();
|
private static final Map<String, BiConsumer<Search, SearchType>> elements = new HashMap<>();
|
||||||
static {
|
static {
|
||||||
elements.put("-transparent", (search, searchType) -> search.transparent = searchType);
|
elements.put("-transparent", (search, searchType) -> search.transparent = searchType);
|
||||||
elements.put("-solid", (search, searchType) -> search.solid = searchType);
|
elements.put("-solid", (search, searchType) -> search.solid = searchType);
|
||||||
@@ -121,15 +122,15 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void search(Player p, @Mapper("search") String... searches) {
|
public void search(Player p, @Mapper("search") String... searches) {
|
||||||
SearchParameter searchParameter = SWPlayer.of(p).getComponentOrDefault(SearchParameter.class, SearchParameter::new);
|
Search search = new Search();
|
||||||
for (String s : searches) {
|
for (String s : searches) {
|
||||||
boolean has = false;
|
boolean has = false;
|
||||||
for (Map.Entry<String, BiConsumer<SearchParameter, SearchType>> element: elements.entrySet()) {
|
for (Map.Entry<String, BiConsumer<Search, SearchType>> element: elements.entrySet()) {
|
||||||
if (s.startsWith(element.getKey() + ":")) {
|
if (s.startsWith(element.getKey() + ":")) {
|
||||||
element.getValue().accept(searchParameter, SearchType.valueOf(s.substring(element.getKey().length() + 1).toUpperCase()));
|
element.getValue().accept(search, SearchType.valueOf(s.substring(element.getKey().length() + 1).toUpperCase()));
|
||||||
has = true;
|
has = true;
|
||||||
} else if (s.startsWith(element.getKey().substring(0, 2) + ":")) {
|
} else if (s.startsWith(element.getKey().substring(0, 2) + ":")) {
|
||||||
element.getValue().accept(searchParameter, SearchType.valueOf(s.substring(element.getKey().substring(0, 2).length() + 1).toUpperCase()));
|
element.getValue().accept(search, SearchType.valueOf(s.substring(element.getKey().substring(0, 2).length() + 1).toUpperCase()));
|
||||||
has = true;
|
has = true;
|
||||||
}
|
}
|
||||||
if (has) break;
|
if (has) break;
|
||||||
@@ -140,15 +141,15 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
case "-blastresistance:":
|
case "-blastresistance:":
|
||||||
s = s.substring(s.indexOf(':') + 1).replace('_', ' ');
|
s = s.substring(s.indexOf(':') + 1).replace('_', ' ');
|
||||||
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
|
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
|
||||||
searchParameter.blastResistance = s;
|
search.blastResistance = s;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
searchParameter.name = s;
|
search.name = s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
materialGUI(p, searchParameter);
|
materialGUI(p, search);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapper(value = "search", local = true)
|
@Mapper(value = "search", local = true)
|
||||||
@@ -181,7 +182,7 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void materialGUI(Player p, SearchParameter search) {
|
public void materialGUI(Player p, Search search) {
|
||||||
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
||||||
MaterialLazyInit.materialData.forEach(data -> {
|
MaterialLazyInit.materialData.forEach(data -> {
|
||||||
if (data.is(search)) {
|
if (data.is(search)) {
|
||||||
@@ -201,59 +202,59 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
private void searchGUI(Player p) {
|
private void searchGUI(Player p) {
|
||||||
SWInventory swInventory = new SWInventory(p, 54, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p));
|
SWInventory swInventory = new SWInventory(p, 54, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p));
|
||||||
SearchParameter searchParameter = SWPlayer.of(p).getComponentOrDefault(SearchParameter.class, SearchParameter::new);
|
Search search = searchMap.get(p);
|
||||||
swInventory.setItem(0, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> {
|
swInventory.setItem(0, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> {
|
||||||
materialGUI(p);
|
materialGUI(p);
|
||||||
}).setCustomModelData(CMDs.BACK));
|
}).setCustomModelData(CMDs.BACK));
|
||||||
swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, searchParameter.name), clickType -> {
|
swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> {
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), searchParameter.name);
|
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name);
|
||||||
swAnvilInv.setCallback(s -> {
|
swAnvilInv.setCallback(s -> {
|
||||||
searchParameter.name = s;
|
search.name = s;
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
});
|
});
|
||||||
swAnvilInv.open();
|
swAnvilInv.open();
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(19, new SWItem(Material.GLASS, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.transparent.getChatValue(), p)), clickType -> {
|
swInventory.setItem(19, new SWItem(Material.GLASS, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.transparent.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.transparent = searchParameter.transparent.next();
|
search.transparent = search.transparent.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(20, new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.solid.getChatValue(), p)), clickType -> {
|
swInventory.setItem(20, new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.solid.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.solid = searchParameter.solid.next();
|
search.solid = search.solid.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(21, new SWItem(Material.BLACK_CONCRETE_POWDER, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_GRAVITY", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.gravity.getChatValue(), p)), clickType -> {
|
swInventory.setItem(21, new SWItem(Material.BLACK_CONCRETE_POWDER, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_GRAVITY", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.gravity.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.gravity = searchParameter.gravity.next();
|
search.gravity = search.gravity.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.occluding.getChatValue(), p)), clickType -> {
|
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.occluding.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.occluding = searchParameter.occluding.next();
|
search.occluding = search.occluding.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.interacteable.getChatValue(), p)), clickType -> {
|
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.interacteable.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.interacteable = searchParameter.interacteable.next();
|
search.interacteable = search.interacteable.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(24, new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_FLAMMABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.flammable.getChatValue(), p)), clickType -> {
|
swInventory.setItem(24, new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_FLAMMABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.flammable.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.flammable = searchParameter.flammable.next();
|
search.flammable = search.flammable.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.burnable.getChatValue(), p)), clickType -> {
|
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.burnable.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.burnable = searchParameter.burnable.next();
|
search.burnable = search.burnable.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.waterloggable.getChatValue(), p)), clickType -> {
|
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.waterloggable.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.waterloggable = searchParameter.waterloggable.next();
|
search.waterloggable = search.waterloggable.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(29, new SWItem(Material.PISTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_UNMOVEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.unmoveable.getChatValue(), p)), clickType -> {
|
swInventory.setItem(29, new SWItem(Material.PISTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_UNMOVEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.unmoveable.getChatValue(), p)), clickType -> {
|
||||||
searchParameter.unmoveable = searchParameter.unmoveable.next();
|
search.unmoveable = search.unmoveable.next();
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
}));
|
}));
|
||||||
swInventory.setItem(34, new SWItem(Material.NETHER_BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, searchParameter.blastResistance), clickType -> {
|
swInventory.setItem(34, new SWItem(Material.NETHER_BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistance), clickType -> {
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), searchParameter.blastResistance);
|
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistance);
|
||||||
swAnvilInv.setCallback(s -> {
|
swAnvilInv.setCallback(s -> {
|
||||||
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
|
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
|
||||||
searchParameter.blastResistance = s;
|
search.blastResistance = s;
|
||||||
}
|
}
|
||||||
searchGUI(p);
|
searchGUI(p);
|
||||||
});
|
});
|
||||||
@@ -261,4 +262,14 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
}));
|
}));
|
||||||
swInventory.open();
|
swInventory.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
searchMap.put(event.getPlayer(), new Search());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
searchMap.remove(event.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -133,7 +133,7 @@ public class MaterialLazyInit {
|
|||||||
}), originalMaterial);
|
}), originalMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean is(MaterialCommand.SearchParameter search) {
|
public boolean is(MaterialCommand.Search search) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
result &= search.transparent.test(transparent);
|
result &= search.transparent.test(transparent);
|
||||||
result &= search.solid.test(solid);
|
result &= search.solid.test(solid);
|
||||||
|
|||||||
+31
-29
@@ -19,17 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.util;
|
package de.steamwar.bausystem.features.util;
|
||||||
|
|
||||||
|
import de.steamwar.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
import de.steamwar.bausystem.utils.NMSWrapper;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.ProtocolWrapper;
|
import de.steamwar.core.ProtocolWrapper;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -40,6 +40,10 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
@@ -55,34 +59,29 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
private static final Class<?> windowClick = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundContainerClickPacket");
|
private static final Class<?> windowClick = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundContainerClickPacket");
|
||||||
private static final Class<?> setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket");
|
private static final Class<?> setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket");
|
||||||
|
|
||||||
public static class NoClipData implements SWPlayer.Component {
|
@Getter
|
||||||
private long lastTick = -1;
|
private static final List<Player> NOCLIPS = new ArrayList<>();
|
||||||
|
private static final Map<Player, Long> LAST_TICKS = new HashMap<>();
|
||||||
@Override
|
|
||||||
public void onUnmount(SWPlayer player) {
|
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoClipCommand() {
|
public NoClipCommand() {
|
||||||
super("noclip", "nc");
|
super("noclip", "nc");
|
||||||
|
|
||||||
BiFunction<Player, Object, Object> first = (player, o) -> {
|
BiFunction<Player, Object, Object> first = (player, o) -> {
|
||||||
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
if (NOCLIPS.contains(player)) {
|
||||||
if (noClipData == null) return o;
|
if (LAST_TICKS.getOrDefault(player, -1L).equals(TPSUtils.currentTick.get())) return o;
|
||||||
if (noClipData.lastTick == TPSUtils.currentTick.get()) return o;
|
NMSWrapper.impl.setInternalGameMode(player, GameMode.SPECTATOR);
|
||||||
NMSWrapper.impl.setInternalGameMode(player, GameMode.SPECTATOR);
|
LAST_TICKS.put(player, TPSUtils.currentTick.get());
|
||||||
noClipData.lastTick = TPSUtils.currentTick.get();
|
}
|
||||||
return o;
|
return o;
|
||||||
};
|
};
|
||||||
TinyProtocol.instance.addFilter(position, first);
|
TinyProtocol.instance.addFilter(position, first);
|
||||||
TinyProtocol.instance.addFilter(positionLook, first);
|
TinyProtocol.instance.addFilter(positionLook, first);
|
||||||
|
|
||||||
BiFunction<Player, Object, Object> second = (player, o) -> {
|
BiFunction<Player, Object, Object> second = (player, o) -> {
|
||||||
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
if (NOCLIPS.contains(player)) {
|
||||||
if (noClipData == null) return o;
|
NMSWrapper.impl.setInternalGameMode(player, GameMode.CREATIVE);
|
||||||
NMSWrapper.impl.setInternalGameMode(player, GameMode.CREATIVE);
|
LAST_TICKS.put(player, TPSUtils.currentTick.get());
|
||||||
noClipData.lastTick = TPSUtils.currentTick.get();
|
}
|
||||||
return o;
|
return o;
|
||||||
};
|
};
|
||||||
TinyProtocol.instance.addFilter(useItem, second);
|
TinyProtocol.instance.addFilter(useItem, second);
|
||||||
@@ -90,7 +89,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
TinyProtocol.instance.addFilter(windowClick, second);
|
TinyProtocol.instance.addFilter(windowClick, second);
|
||||||
|
|
||||||
BiFunction<Player, Object, Object> third = (player, o) -> {
|
BiFunction<Player, Object, Object> third = (player, o) -> {
|
||||||
if (SWPlayer.of(player).hasComponent(NoClipData.class)) {
|
if (NOCLIPS.contains(player)) {
|
||||||
NMSWrapper.impl.setSlotToItemStack(player, o);
|
NMSWrapper.impl.setSlotToItemStack(player, o);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
@@ -100,9 +99,9 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
@Register(help = true)
|
@Register(help = true)
|
||||||
public void genericCommand(@Validator Player player) {
|
public void genericCommand(@Validator Player player) {
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
if (NOCLIPS.contains(player)) {
|
||||||
if (swPlayer.hasComponent(NoClipData.class)) {
|
NOCLIPS.remove(player);
|
||||||
swPlayer.removeComponent(NoClipData.class);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
} else {
|
} else {
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
NMSWrapper.impl.setPlayerBuildAbilities(player);
|
NMSWrapper.impl.setPlayerBuildAbilities(player);
|
||||||
@@ -111,7 +110,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
NMSWrapper.impl.setGameStateChangeReason(gameStateChangeObject);
|
NMSWrapper.impl.setGameStateChangeReason(gameStateChangeObject);
|
||||||
floatFieldAccessor.set(gameStateChangeObject, 1F);
|
floatFieldAccessor.set(gameStateChangeObject, 1F);
|
||||||
|
|
||||||
swPlayer.setComponent(new NoClipData());
|
NOCLIPS.add(player);
|
||||||
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
||||||
TinyProtocol.instance.sendPacket(player, gameStateChangeObject);
|
TinyProtocol.instance.sendPacket(player, gameStateChangeObject);
|
||||||
pseudoGameMode(player, GameMode.SPECTATOR);
|
pseudoGameMode(player, GameMode.SPECTATOR);
|
||||||
@@ -121,27 +120,30 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||||
event.getNewSpectator().forEach(player -> {
|
event.getNewSpectator().forEach(player -> {
|
||||||
SWPlayer.of(player).removeComponent(NoClipData.class);
|
if (NOCLIPS.contains(player)) {
|
||||||
|
NOCLIPS.remove(player);
|
||||||
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (NOCLIPS.contains(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onBlock(BlockCanBuildEvent event) {
|
public void onBlock(BlockCanBuildEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (NOCLIPS.contains(event.getPlayer())) {
|
||||||
event.setBuildable(true);
|
event.setBuildable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (NOCLIPS.contains(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().setFlying(true);
|
event.getPlayer().setFlying(true);
|
||||||
}
|
}
|
||||||
@@ -152,7 +154,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
|
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (NOCLIPS.contains(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
event.getPlayer().setSpectatorTarget(null);
|
event.getPlayer().setSpectatorTarget(null);
|
||||||
|
|||||||
+8
-5
@@ -24,7 +24,6 @@ import de.steamwar.bausystem.Permission;
|
|||||||
import de.steamwar.bausystem.linkage.BauGuiItem;
|
import de.steamwar.bausystem.linkage.BauGuiItem;
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
@@ -36,11 +35,15 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class SelectBauGuiItem extends BauGuiItem {
|
public class SelectBauGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
|
private static final Map<Player, LastSelect> LAST_SELECT_MAP = new HashMap<>();
|
||||||
|
|
||||||
public SelectBauGuiItem() {
|
public SelectBauGuiItem() {
|
||||||
super(13);
|
super(13);
|
||||||
}
|
}
|
||||||
@@ -55,13 +58,13 @@ public class SelectBauGuiItem extends BauGuiItem {
|
|||||||
|
|
||||||
private static void selectFinish(Player p, RegionType type, RegionExtensionType extensionType) {
|
private static void selectFinish(Player p, RegionType type, RegionExtensionType extensionType) {
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
SWPlayer.of(p).setComponent(new LastSelect(type, extensionType));
|
LAST_SELECT_MAP.put(p, new LastSelect(type, extensionType));
|
||||||
p.performCommand("select " + type.name() + " " + extensionType.toString());
|
p.performCommand("select " + type.name() + " " + extensionType.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(Player player) {
|
public ItemStack getItem(Player player) {
|
||||||
LastSelect last = SWPlayer.of(player).getComponentOrDefault(LastSelect.class, () -> new LastSelect(RegionType.BUILD, RegionExtensionType.NORMAL));
|
LastSelect last = LAST_SELECT_MAP.getOrDefault(player, new LastSelect(RegionType.BUILD, RegionExtensionType.NORMAL));
|
||||||
return new SWItem(Material.SCAFFOLDING, BauSystem.MESSAGE.parse("SELECT_ITEM_SELECT", player), Arrays.asList(BauSystem.MESSAGE.parse("SELECT_ITEM_AUSWAHL", player, BauSystem.MESSAGE.parse(last.type.getChatValue(), player), last.extensionType.name()), BauSystem.MESSAGE.parse("SELECT_ITEM_RIGHT_CLICK", player)), false, clickType -> {
|
return new SWItem(Material.SCAFFOLDING, BauSystem.MESSAGE.parse("SELECT_ITEM_SELECT", player), Arrays.asList(BauSystem.MESSAGE.parse("SELECT_ITEM_AUSWAHL", player, BauSystem.MESSAGE.parse(last.type.getChatValue(), player), last.extensionType.name()), BauSystem.MESSAGE.parse("SELECT_ITEM_RIGHT_CLICK", player)), false, clickType -> {
|
||||||
}).getItemStack();
|
}).getItemStack();
|
||||||
}
|
}
|
||||||
@@ -77,7 +80,7 @@ public class SelectBauGuiItem extends BauGuiItem {
|
|||||||
inv.open();
|
inv.open();
|
||||||
} else {
|
} else {
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
LastSelect last = SWPlayer.of(p).getComponentOrDefault(LastSelect.class, () -> new LastSelect(RegionType.BUILD, RegionExtensionType.NORMAL));
|
LastSelect last = LAST_SELECT_MAP.getOrDefault(p, new LastSelect(RegionType.BUILD, RegionExtensionType.NORMAL));
|
||||||
p.performCommand("select " + last.getType().name() + " " + last.getExtensionType().toString());
|
p.performCommand("select " + last.getType().name() + " " + last.getExtensionType().toString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -89,7 +92,7 @@ public class SelectBauGuiItem extends BauGuiItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class LastSelect implements SWPlayer.Component {
|
private static class LastSelect {
|
||||||
@Getter
|
@Getter
|
||||||
private final RegionType type;
|
private final RegionType type;
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
+42
-32
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.warp;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.entity.RArmorStand;
|
import de.steamwar.entity.RArmorStand;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
@@ -31,10 +30,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@@ -46,21 +42,8 @@ import java.util.Map;
|
|||||||
@Linked
|
@Linked
|
||||||
public class WarpListener implements Listener {
|
public class WarpListener implements Listener {
|
||||||
|
|
||||||
public static class WarpComponent implements SWPlayer.Component {
|
private Map<Player, REntityServer> warpEntityServer = new HashMap<>();
|
||||||
private REntityServer server;
|
private Map<Player, List<Location>> selected = new HashMap<>();
|
||||||
private List<Location> selected = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMount(SWPlayer player) {
|
|
||||||
server = new REntityServer();
|
|
||||||
server.addPlayer(player.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnmount(SWPlayer player) {
|
|
||||||
server.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
||||||
@@ -82,11 +65,20 @@ public class WarpListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reshow(Player p, Material material, boolean sneaking) {
|
private void reshow(Player p, Material material, boolean sneaking) {
|
||||||
SWPlayer swPlayer = SWPlayer.of(p);
|
REntityServer entityServer = warpEntityServer.get(p);
|
||||||
swPlayer.removeComponent(WarpComponent.class);
|
if (entityServer != null) {
|
||||||
if (material != Material.COMPASS) return;
|
entityServer.close();
|
||||||
|
}
|
||||||
|
if (material != Material.COMPASS) {
|
||||||
|
warpEntityServer.remove(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
selected.remove(p);
|
||||||
|
entityServer = new REntityServer();
|
||||||
|
entityServer.addPlayer(p);
|
||||||
|
warpEntityServer.put(p, entityServer);
|
||||||
|
|
||||||
WarpComponent warpComponent = swPlayer.getComponentOrDefault(WarpComponent.class, WarpComponent::new);
|
|
||||||
Vector current = p.getLocation().clone().add(p.getLocation().getDirection().multiply(5)).toVector();
|
Vector current = p.getLocation().clone().add(p.getLocation().getDirection().multiply(5)).toVector();
|
||||||
|
|
||||||
Map<String, Location> locations = new HashMap<>();
|
Map<String, Location> locations = new HashMap<>();
|
||||||
@@ -107,9 +99,12 @@ public class WarpListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
REntityServer finalEntityServer = entityServer;
|
||||||
locations.forEach((name, location) -> {
|
locations.forEach((name, location) -> {
|
||||||
Vector vector = location.toVector().subtract(p.getLocation().toVector());
|
Vector vector = location.toVector().subtract(p.getLocation().toVector());
|
||||||
if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) return;
|
if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
vector.setY(0);
|
vector.setY(0);
|
||||||
|
|
||||||
Vector position = p.getLocation().toVector().clone().add(vector.normalize().multiply(5));
|
Vector position = p.getLocation().toVector().clone().add(vector.normalize().multiply(5));
|
||||||
@@ -117,9 +112,9 @@ public class WarpListener implements Listener {
|
|||||||
|
|
||||||
if ((position.getX() - current.getX()) * (position.getX() - current.getX()) + (position.getZ() - current.getZ()) * (position.getZ() - current.getZ()) < 0.1) {
|
if ((position.getX() - current.getX()) * (position.getX() - current.getX()) + (position.getZ() - current.getZ()) * (position.getZ() - current.getZ()) < 0.1) {
|
||||||
name = "§a§l" + name;
|
name = "§a§l" + name;
|
||||||
warpComponent.selected.add(location);
|
selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location);
|
||||||
}
|
}
|
||||||
RArmorStand armorStand = new RArmorStand(warpComponent.server, position.toLocation(p.getWorld()), RArmorStand.Size.MARKER);
|
RArmorStand armorStand = new RArmorStand(finalEntityServer, position.toLocation(p.getWorld()), RArmorStand.Size.MARKER);
|
||||||
armorStand.setDisplayName(name);
|
armorStand.setDisplayName(name);
|
||||||
armorStand.setNoGravity(true);
|
armorStand.setNoGravity(true);
|
||||||
armorStand.setInvisible(true);
|
armorStand.setInvisible(true);
|
||||||
@@ -128,13 +123,28 @@ public class WarpListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.COMPASS) return;
|
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.COMPASS) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_AIR) return;
|
return;
|
||||||
WarpComponent warpComponent = SWPlayer.of(event.getPlayer()).getComponent(WarpComponent.class).orElse(null);
|
}
|
||||||
if (warpComponent == null || warpComponent.selected.size() != 1) return;
|
if (event.getAction() != Action.RIGHT_CLICK_AIR) {
|
||||||
Location location = warpComponent.selected.get(0);
|
return;
|
||||||
|
}
|
||||||
|
List<Location> locations = selected.getOrDefault(event.getPlayer(), new ArrayList<>());
|
||||||
|
if (locations.size() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Location location = locations.get(0);
|
||||||
event.getPlayer().teleport(location);
|
event.getPlayer().teleport(location);
|
||||||
event.getPlayer().playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
|
event.getPlayer().playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
warpEntityServer.computeIfPresent(event.getPlayer(), (player, rEntityServer) -> {
|
||||||
|
rEntityServer.close();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
selected.remove(event.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -59,14 +59,18 @@ public class BauMemberUpdate extends PacketHandler implements Listener {
|
|||||||
Set<Player> newSpectator = new HashSet<>();
|
Set<Player> newSpectator = new HashSet<>();
|
||||||
Set<Player> newBuilder = new HashSet<>();
|
Set<Player> newBuilder = new HashSet<>();
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
if (Permission.SPECTATOR.hasPermission(player)) {
|
if (Permission.REAL_SPECTATOR.hasPermission(player)) {
|
||||||
if (!SPECTATORS.contains(player)) {
|
if (!SPECTATORS.contains(player)) {
|
||||||
SPECTATORS.add(player);
|
SPECTATORS.add(player);
|
||||||
|
Permission.removeForceOnlySpectator(player);
|
||||||
newSpectator.add(player);
|
newSpectator.add(player);
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false));
|
||||||
showSpectatorNotice(player);
|
showSpectatorNotice(player);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (Permission.SUPERVISOR.hasPermission(player)) {
|
||||||
|
Permission.removeForceOnlySpectator(player);
|
||||||
|
}
|
||||||
if (SPECTATORS.contains(player)) {
|
if (SPECTATORS.contains(player)) {
|
||||||
SPECTATORS.remove(player);
|
SPECTATORS.remove(player);
|
||||||
newBuilder.add(player);
|
newBuilder.add(player);
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.bausystem.features.world;
|
||||||
|
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class OtherTNTListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onExplosion(EntityExplodeEvent e) {
|
||||||
|
e.blockList().removeIf(block -> {
|
||||||
|
if(block.getType() == Material.TNT) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-18
@@ -49,7 +49,6 @@ import java.util.Set;
|
|||||||
@Linked
|
@Linked
|
||||||
public class SpectatorListener implements Listener {
|
public class SpectatorListener implements Listener {
|
||||||
|
|
||||||
private static final TechHider techHider;
|
|
||||||
private static final Set<Player> NO_TECHHIDER = new HashSet<>();
|
private static final Set<Player> NO_TECHHIDER = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -101,20 +100,10 @@ public class SpectatorListener implements Listener {
|
|||||||
materials.add(Material.WATER);
|
materials.add(Material.WATER);
|
||||||
materials.remove(Material.BARRIER);
|
materials.remove(Material.BARRIER);
|
||||||
materials.remove(Material.STONE);
|
materials.remove(Material.STONE);
|
||||||
techHider = new TechHider((TechHider.LocationEvaluator) (player, i, i1) -> {
|
TechHider techHider = new TechHider((TechHider.LocationEvaluator) (player, i, i1) -> {
|
||||||
return Permission.BUILD.hasPermission(player) || NO_TECHHIDER.contains(player);
|
return Permission.BUILD.hasPermission(player) || Permission.isTempOnlySpectator(player) || NO_TECHHIDER.contains(player);
|
||||||
}, Material.END_STONE, materials, new HashSet<>());
|
}, Material.END_STONE, materials, new HashSet<>());
|
||||||
}
|
techHider.enable();
|
||||||
|
|
||||||
private static void enableOrDisableTechhider() {
|
|
||||||
boolean enable = Bukkit.getOnlinePlayers()
|
|
||||||
.stream()
|
|
||||||
.anyMatch(player -> !(Permission.BUILD.hasPermission(player) || NO_TECHHIDER.contains(player)));
|
|
||||||
if (enable) {
|
|
||||||
techHider.enable();
|
|
||||||
} else {
|
|
||||||
techHider.disable();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toggleNoTechHider(Player player) {
|
public static void toggleNoTechHider(Player player) {
|
||||||
@@ -124,7 +113,6 @@ public class SpectatorListener implements Listener {
|
|||||||
NO_TECHHIDER.add(player);
|
NO_TECHHIDER.add(player);
|
||||||
}
|
}
|
||||||
resendChunks(player);
|
resendChunks(player);
|
||||||
enableOrDisableTechhider();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resendChunks(Player player) {
|
private static void resendChunks(Player player) {
|
||||||
@@ -143,7 +131,6 @@ public class SpectatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
enableOrDisableTechhider();
|
|
||||||
if (BauSystem.DEV_SERVER) return;
|
if (BauSystem.DEV_SERVER) return;
|
||||||
if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) {
|
if (event.getPlayer().getUniqueId().equals(BauServer.getInstance().getOwner())) {
|
||||||
return;
|
return;
|
||||||
@@ -165,7 +152,6 @@ public class SpectatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||||
enableOrDisableTechhider();
|
|
||||||
if (!anySupervisorOnline(null) && !BauSystem.DEV_SERVER) {
|
if (!anySupervisorOnline(null) && !BauSystem.DEV_SERVER) {
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
player.kickPlayer("");
|
player.kickPlayer("");
|
||||||
@@ -175,6 +161,7 @@ public class SpectatorListener implements Listener {
|
|||||||
|
|
||||||
event.getChanged().forEach(player -> {
|
event.getChanged().forEach(player -> {
|
||||||
NO_TECHHIDER.remove(player);
|
NO_TECHHIDER.remove(player);
|
||||||
|
if (Permission.isTempOnlySpectator(player)) return;
|
||||||
resendChunks(player);
|
resendChunks(player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -182,7 +169,6 @@ public class SpectatorListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
NO_TECHHIDER.remove(event.getPlayer());
|
NO_TECHHIDER.remove(event.getPlayer());
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), SpectatorListener::enableOrDisableTechhider, 1);
|
|
||||||
if (BauSystem.DEV_SERVER) return;
|
if (BauSystem.DEV_SERVER) return;
|
||||||
if (!anySupervisorOnline(event.getPlayer())) {
|
if (!anySupervisorOnline(event.getPlayer())) {
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
|||||||
+15
-10
@@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
import de.steamwar.core.SWPlayer;
|
|
||||||
import de.steamwar.core.WorldEditRenderer;
|
import de.steamwar.core.WorldEditRenderer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.linkage.MinVersion;
|
import de.steamwar.linkage.MinVersion;
|
||||||
@@ -36,10 +35,13 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@@ -69,23 +71,32 @@ public class SelectAdjacent implements Listener {
|
|||||||
new Vector(0, -1, -1),
|
new Vector(0, -1, -1),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Map<Player, Selector> selectors = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!event.hasItem()) return;
|
if (!event.hasItem()) return;
|
||||||
if (event.getItem().getType() != Material.WOODEN_AXE) return;
|
if (event.getItem().getType() != Material.WOODEN_AXE) return;
|
||||||
|
Selector selector = selectors.get(event.getPlayer());
|
||||||
|
if (selector != null) selector.cancel();
|
||||||
if (!event.getPlayer().isSneaking()) return;
|
if (!event.getPlayer().isSneaking()) return;
|
||||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
|
||||||
Material material = event.getPlayer().getInventory().getItemInOffHand().getType();
|
Material material = event.getPlayer().getInventory().getItemInOffHand().getType();
|
||||||
Selector selector;
|
|
||||||
if (material.isAir()) {
|
if (material.isAir()) {
|
||||||
selector = new Selector(event.getClickedBlock(), event.getPlayer(), __ -> true);
|
selector = new Selector(event.getClickedBlock(), event.getPlayer(), __ -> true);
|
||||||
} else {
|
} else {
|
||||||
selector = new Selector(event.getClickedBlock(), event.getPlayer(), type -> type == material);
|
selector = new Selector(event.getClickedBlock(), event.getPlayer(), type -> type == material);
|
||||||
}
|
}
|
||||||
SWPlayer.of(event.getPlayer()).setComponent(selector);
|
selectors.put(event.getPlayer(), selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Selector implements SWPlayer.Component {
|
@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 static final int MAX_BLOCKS = 500_000;
|
||||||
|
|
||||||
@@ -143,7 +154,6 @@ public class SelectAdjacent implements Listener {
|
|||||||
if (toCalc.isEmpty() || seen.size() > MAX_BLOCKS) {
|
if (toCalc.isEmpty() || seen.size() > MAX_BLOCKS) {
|
||||||
bukkitTask.cancel();
|
bukkitTask.cancel();
|
||||||
player.sendTitle("§aDone", "§e" + volume + " §7Blocks", 0, 20, 5);
|
player.sendTitle("§aDone", "§e" + volume + " §7Blocks", 0, 20, 5);
|
||||||
SWPlayer.of(player).removeComponent(Selector.class);
|
|
||||||
}
|
}
|
||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
@@ -180,10 +190,5 @@ public class SelectAdjacent implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnmount(SWPlayer player) {
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
|
|||||||
if (hidden.containsKey(region) && hidden.get(region).contains(player)) {
|
if (hidden.containsKey(region) && hidden.get(region).contains(player)) {
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
PlayerMovementWrapper.impl.setPosition(player, o);
|
PlayerMovementWrapper.impl.setPosition(player, o);
|
||||||
}, 0);
|
}, 1L);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
steamwar.java
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation(libs.junit)
|
||||||
|
testImplementation(libs.hamcrest)
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
steamwar.java
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":CommandFramework:CommandFrameworkBase", "default"))
|
||||||
|
annotationProcessor(project(":CommandFramework:CommandFrameworkBase", "default"))
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
de.steamwar.command.annotationprocessor.impl.CachedAnnotationProcessor
|
||||||
|
de.steamwar.command.annotationprocessor.impl.MapperAnnotationProcessor
|
||||||
|
de.steamwar.command.annotationprocessor.impl.RegisterAnnotationProcessor
|
||||||
|
de.steamwar.command.annotationprocessor.impl.SupplierAnnotationProcessor
|
||||||
|
de.steamwar.command.annotationprocessor.impl.ValidatorAnnotationProcessor
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.command;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
public class HandlerForAnnotationMirror<A extends Annotation> implements Handler.AnnotationWrapper<A> {
|
||||||
|
|
||||||
|
private A annotation;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private AnnotationMirror annotationMirror;
|
||||||
|
|
||||||
|
public HandlerForAnnotationMirror(A annotation, AnnotationMirror annotationMirror) {
|
||||||
|
this.annotation = annotation;
|
||||||
|
this.annotationMirror = annotationMirror;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public A getAnnotation() {
|
||||||
|
return annotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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.command;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
import javax.lang.model.element.VariableElement;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
import javax.lang.model.util.Types;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HandlerForExecutableElement implements Handler.MethodWrapper {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final ExecutableElement method;
|
||||||
|
private final Types types;
|
||||||
|
private final Elements elements;
|
||||||
|
|
||||||
|
public HandlerForExecutableElement(ExecutableElement method, Types types, Elements elements) {
|
||||||
|
this.method = method;
|
||||||
|
this.types = types;
|
||||||
|
this.elements = elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return method.getSimpleName().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getParameterCount() {
|
||||||
|
return method.getParameters().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Handler.TypeWrapper getReturnType() {
|
||||||
|
return new HandlerForTypeMirror(method.getReturnType(), types, elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Handler.ParameterWrapper[] getParameters() {
|
||||||
|
Handler.ParameterWrapper[] parameters = new Handler.ParameterWrapper[method.getParameters().size()];
|
||||||
|
List<? extends VariableElement> variableElements = method.getParameters();
|
||||||
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
|
VariableElement variableElement = variableElements.get(i);
|
||||||
|
parameters[i] = new HandlerForVariableElement(variableElement, types, elements, i == parameters.length - 1 && method.isVarArgs());
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
}
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* 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.command;
|
||||||
|
|
||||||
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.element.ElementKind;
|
||||||
|
import javax.lang.model.type.ArrayType;
|
||||||
|
import javax.lang.model.type.DeclaredType;
|
||||||
|
import javax.lang.model.type.TypeKind;
|
||||||
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
|
public class HandlerForTypeMirror implements Handler.TypeWrapper {
|
||||||
|
|
||||||
|
private final TypeMirror type;
|
||||||
|
private final Types types;
|
||||||
|
private final Elements elements;
|
||||||
|
|
||||||
|
public HandlerForTypeMirror(TypeMirror type, Types types, Elements elements) {
|
||||||
|
this.type = type;
|
||||||
|
this.types = types;
|
||||||
|
this.elements = elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAssignableTo(Class<?> clazz) {
|
||||||
|
return types.isAssignable(types.erasure(type), types.erasure(elements.getTypeElement(clazz.getTypeName()).asType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAssignableTo(Handler.TypeWrapper type) {
|
||||||
|
if (type instanceof ForClass) {
|
||||||
|
return isAssignableTo(((ForClass) type).getClazz());
|
||||||
|
} else if (type instanceof HandlerForTypeMirror) {
|
||||||
|
return types.isAssignable(types.erasure(this.type), types.erasure(((HandlerForTypeMirror) type).type));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitive() {
|
||||||
|
return type.getKind().isPrimitive();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isArray() {
|
||||||
|
return type instanceof ArrayType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnum() {
|
||||||
|
if (type.getKind() != TypeKind.DECLARED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclaredType declaredType = (DeclaredType) type;
|
||||||
|
Element element = declaredType.asElement();
|
||||||
|
|
||||||
|
return element.getKind() == ElementKind.ENUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean is(Class<?> clazz) {
|
||||||
|
if (type.getKind() == TypeKind.VOID && clazz == Void.TYPE) {
|
||||||
|
return true;
|
||||||
|
} else if (type.getKind().isPrimitive() && clazz.isPrimitive()) {
|
||||||
|
return type.toString().equals(clazz.getTypeName());
|
||||||
|
} else if (!type.getKind().isPrimitive() && !clazz.isPrimitive()) {
|
||||||
|
return types.isSameType(types.erasure(type), types.erasure(elements.getTypeElement(clazz.getTypeName()).asType()));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean is(Handler.TypeWrapper type) {
|
||||||
|
if (type instanceof ForClass) {
|
||||||
|
return is(((ForClass) type).getClazz());
|
||||||
|
} else if (type instanceof HandlerForTypeMirror) {
|
||||||
|
return types.isSameType(types.erasure(this.type), types.erasure(((HandlerForTypeMirror) type).type));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Handler.TypeWrapper getComponentType() {
|
||||||
|
if (type instanceof ArrayType) {
|
||||||
|
return new HandlerForTypeMirror(((ArrayType) type).getComponentType(), types, elements);
|
||||||
|
} else {
|
||||||
|
return new HandlerForTypeMirror(null, types, elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return type.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeName() {
|
||||||
|
return type.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+151
@@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* 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.command;
|
||||||
|
|
||||||
|
import de.steamwar.command.utils.Pair;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
|
import javax.lang.model.element.VariableElement;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
import javax.lang.model.util.Types;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.annotation.Repeatable;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class HandlerForVariableElement implements Handler.ParameterWrapper {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final VariableElement parameter;
|
||||||
|
private final Types types;
|
||||||
|
private final Elements elements;
|
||||||
|
private final boolean varArgs;
|
||||||
|
|
||||||
|
public HandlerForVariableElement(VariableElement variableElement, Types types, Elements elements, boolean varArgs) {
|
||||||
|
this.parameter = variableElement;
|
||||||
|
this.types = types;
|
||||||
|
this.elements = elements;
|
||||||
|
this.varArgs = varArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Handler.TypeWrapper getType() {
|
||||||
|
return new HandlerForTypeMirror(parameter.asType(), types, elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVarArgs() {
|
||||||
|
return varArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
|
||||||
|
return parameter.getAnnotation(annotation) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <A extends Annotation> Handler.AnnotationWrapper<A> getAnnotation(Class<A> annotation) {
|
||||||
|
A ann = parameter.getAnnotation(annotation);
|
||||||
|
AnnotationMirror annMirror = parameter.getAnnotationMirrors()
|
||||||
|
.stream()
|
||||||
|
.filter(am -> new HandlerForTypeMirror(am.getAnnotationType(), types, elements).is(annotation))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
return new HandlerForAnnotationMirror<>(ann, annMirror);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return parameter.getSimpleName().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Handler.AnnotationWrapper<?>> getAnnotations() {
|
||||||
|
return parameter.getAnnotationMirrors()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(Function.identity(), annotationMirror -> {
|
||||||
|
Class<?> clazz = getClass(annotationMirror.getAnnotationType().toString());
|
||||||
|
if (clazz == null) return null;
|
||||||
|
return parameter.getAnnotation((Class<? extends Annotation>) clazz);
|
||||||
|
}))
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(entry -> entry.getValue() != null)
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, entry -> {
|
||||||
|
Annotation annotation = entry.getValue();
|
||||||
|
try {
|
||||||
|
Method method = annotation.annotationType().getMethod("value");
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
if (!returnType.isArray()) {
|
||||||
|
return List.of(annotation);
|
||||||
|
}
|
||||||
|
Class<?> innerReturnType = returnType.getComponentType();
|
||||||
|
if (!(innerReturnType.isAnnotation() && innerReturnType.isAnnotationPresent(Repeatable.class))) {
|
||||||
|
return List.of(annotation);
|
||||||
|
}
|
||||||
|
Repeatable repeatable = innerReturnType.getAnnotation(Repeatable.class);
|
||||||
|
Class<? extends Annotation> containerType = repeatable.value();
|
||||||
|
if (containerType == returnType) {
|
||||||
|
throw new UnsupportedOperationException("Repeatable annotation must have a container annotation");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Arrays.asList((Annotation[]) method.invoke(annotation));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return List.of(annotation);
|
||||||
|
}
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
return List.of(annotation);
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.flatMap(entry -> {
|
||||||
|
return entry.getValue()
|
||||||
|
.stream()
|
||||||
|
.map(annotation -> new Pair<AnnotationMirror, Annotation>(entry.getKey(), annotation));
|
||||||
|
})
|
||||||
|
.filter(pair -> pair.b.annotationType().isAnnotationPresent(Handler.Implementation.class))
|
||||||
|
.map(pair -> new HandlerForAnnotationMirror<>(pair.b, pair.a))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class<?> getClass(String name) {
|
||||||
|
try {
|
||||||
|
return Class.forName(name);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
if (!name.contains(".")) return null;
|
||||||
|
Class<?> outerClass = getClass(name.substring(0, name.lastIndexOf('.')));
|
||||||
|
if (outerClass == null) return null;
|
||||||
|
name = name.substring(name.lastIndexOf('.') + 1);
|
||||||
|
for (Class<?> declaredClass : outerClass.getDeclaredClasses()) {
|
||||||
|
if (declaredClass.getSimpleName().equals(name)) {
|
||||||
|
return declaredClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+156
@@ -0,0 +1,156 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.annotationprocessor;
|
||||||
|
|
||||||
|
import de.steamwar.command.Handler;
|
||||||
|
import de.steamwar.command.HandlerForAnnotationMirror;
|
||||||
|
import de.steamwar.command.HandlerForExecutableElement;
|
||||||
|
import de.steamwar.command.HandlerForVariableElement;
|
||||||
|
|
||||||
|
import javax.annotation.processing.AbstractProcessor;
|
||||||
|
import javax.annotation.processing.Messager;
|
||||||
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
|
import javax.lang.model.SourceVersion;
|
||||||
|
import javax.lang.model.element.*;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
import javax.lang.model.util.Types;
|
||||||
|
import javax.tools.Diagnostic;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public abstract class AbstractAnnotationProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
|
private Messager messager;
|
||||||
|
private Types types;
|
||||||
|
private Elements elements;
|
||||||
|
|
||||||
|
public abstract Class<? extends Annotation> getAnnotationClass();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||||
|
super.init(processingEnv);
|
||||||
|
this.messager = processingEnv.getMessager();
|
||||||
|
this.types = processingEnv.getTypeUtils();
|
||||||
|
this.elements = processingEnv.getElementUtils();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getSupportedAnnotationTypes() {
|
||||||
|
return Collections.singleton(this.getAnnotationClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SourceVersion getSupportedSourceVersion() {
|
||||||
|
return SourceVersion.latestSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
|
List<ExecutableElement> elements = roundEnv.getElementsAnnotatedWith(getAnnotationClass())
|
||||||
|
.stream()
|
||||||
|
.filter(element -> element.getKind() == ElementKind.METHOD)
|
||||||
|
.map(ExecutableElement.class::cast)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (elements.isEmpty()) return false;
|
||||||
|
elements.forEach(element -> {
|
||||||
|
checkMethodAnnotation(element, element.getAnnotation(getAnnotationClass()));
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Handler getHandler(Annotation annotation, Element element) {
|
||||||
|
Handler.Implementation implementation = annotation.annotationType().getAnnotation(Handler.Implementation.class);
|
||||||
|
if (implementation == null) return null;
|
||||||
|
try {
|
||||||
|
return implementation.value().getConstructor().newInstance();
|
||||||
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||||
|
InvocationTargetException e) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR, "Handler " + implementation.value().getName() + " cannot be used to check the argument validity", element);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkMethodAnnotation(ExecutableElement method, Annotation annotation) {
|
||||||
|
Handler handler = getHandler(annotation, method);
|
||||||
|
if (handler == null) return;
|
||||||
|
if (!(handler instanceof Handler.HandlerMethod)) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR, "Handler " + handler.getClass().getName() + " is not a HandlerMethod", method);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Handler.HandlerMethod handlerMethod = (Handler.HandlerMethod) handler;
|
||||||
|
try {
|
||||||
|
handlerMethod.check(new HandlerForAnnotationMirror(annotation, null), new HandlerForExecutableElement(method, types, elements), DataCheckableImpl.INSTANCE);
|
||||||
|
} catch (Handler.HandlerException e) {
|
||||||
|
Handler.CodePlace codePlace = e.getCodePlace();
|
||||||
|
AnnotationMirror[] annotationMirrors = new AnnotationMirror[0];
|
||||||
|
if (codePlace.getAnnotations().length > 0) {
|
||||||
|
annotationMirrors = Arrays.stream(codePlace.getAnnotations())
|
||||||
|
.map(annotationWrapper -> (HandlerForAnnotationMirror) annotationWrapper)
|
||||||
|
.map(HandlerForAnnotationMirror::getAnnotationMirror)
|
||||||
|
.toArray(AnnotationMirror[]::new);
|
||||||
|
}
|
||||||
|
Element element = null;
|
||||||
|
if (codePlace.getMethod() != null) {
|
||||||
|
element = ((HandlerForExecutableElement) codePlace.getMethod()).getMethod();
|
||||||
|
} else if (codePlace.getParameter() != null) {
|
||||||
|
element = ((HandlerForVariableElement) codePlace.getParameter()).getParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (annotationMirrors.length > 0) {
|
||||||
|
for (int i = 0; i < annotationMirrors.length; i++) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage(), element, annotationMirrors[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage(), element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class DataCheckableImpl implements Handler.DataCheckable {
|
||||||
|
|
||||||
|
private static final DataCheckableImpl INSTANCE = new DataCheckableImpl();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasExecutorMapper(Class<?> clazz) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMapper(String key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasValidator(String key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasSupplier(String key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.annotationprocessor.impl;
|
||||||
|
|
||||||
|
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||||
|
import de.steamwar.command.annotations.Cached;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
public class CachedAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationClass() {
|
||||||
|
return Cached.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.annotationprocessor.impl;
|
||||||
|
|
||||||
|
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||||
|
import de.steamwar.command.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
public class MapperAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationClass() {
|
||||||
|
return Mapper.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.annotationprocessor.impl;
|
||||||
|
|
||||||
|
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||||
|
import de.steamwar.command.annotations.Register;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
public class RegisterAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationClass() {
|
||||||
|
return Register.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.annotationprocessor.impl;
|
||||||
|
|
||||||
|
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||||
|
import de.steamwar.command.annotations.Supplier;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
public class SupplierAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationClass() {
|
||||||
|
return Supplier.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.annotationprocessor.impl;
|
||||||
|
|
||||||
|
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||||
|
import de.steamwar.command.annotations.Validator;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
public class ValidatorAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationClass() {
|
||||||
|
return Validator.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
steamwar.java
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
/*
|
||||||
|
* 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.command;
|
||||||
|
|
||||||
|
import de.steamwar.command.graph.NodeData;
|
||||||
|
import de.steamwar.command.graph.RootNode;
|
||||||
|
import de.steamwar.command.utils.Pair;
|
||||||
|
import de.steamwar.command.utils.Triple;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public abstract class AbstractCommand<T> {
|
||||||
|
|
||||||
|
private static final Map<Class<? extends AbstractCommand<?>>, Map<Class<?>, Function<?, ?>>> EXECUTOR_MAPPER = new HashMap<>();
|
||||||
|
|
||||||
|
public static <E, T> void addExecutorMapper(Class<? extends AbstractCommand<E>> wrapper, Class<T> executorType, Function<E, T> mapper) {
|
||||||
|
EXECUTOR_MAPPER.computeIfAbsent(wrapper, __ -> new HashMap<>())
|
||||||
|
.putIfAbsent(executorType, mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String command;
|
||||||
|
protected final String permission;
|
||||||
|
private final Consumer<CommandLoader<T>> initializer;
|
||||||
|
protected final String[] aliases;
|
||||||
|
protected final List<String> descriptions = new ArrayList<>();
|
||||||
|
|
||||||
|
private boolean initialized = false;
|
||||||
|
protected final RootNode<T> rootNode = new RootNode<>();
|
||||||
|
|
||||||
|
private final Map<String, AbstractTypeMapper<T, ?>> localTypeMapper = new HashMap<>();
|
||||||
|
private final Map<String, AbstractTypeValidator<T, ?>> localValidators = new HashMap<>();
|
||||||
|
private final Map<String, AbstractTypeSupplier<T, ?>> localSupplier = new HashMap<>();
|
||||||
|
|
||||||
|
protected AbstractCommand(String command, Consumer<CommandLoader<T>> initializer, String... aliases) {
|
||||||
|
this(command, null, initializer, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AbstractCommand(String command, String permission, Consumer<CommandLoader<T>> initializer, String... aliases) {
|
||||||
|
this.command = command;
|
||||||
|
this.permission = permission;
|
||||||
|
this.initializer = initializer;
|
||||||
|
this.aliases = aliases;
|
||||||
|
initCommand();
|
||||||
|
unregister();
|
||||||
|
register();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected synchronized void initCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void unregister();
|
||||||
|
|
||||||
|
public abstract void register();
|
||||||
|
|
||||||
|
protected void commandSystemError(T sender, CommandFrameworkException e) {
|
||||||
|
Logger.getGlobal().log(Level.WARNING, "An unexpected error occurred", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendMessage(T sender, String message, Object[] args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void execute(T sender, String alias, String[] args) {
|
||||||
|
initialize();
|
||||||
|
List<Runnable> errors = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
boolean executed = rootNode.execute(sender, new NodeData(alias, fixArgs(args, true), (s, args1) -> {
|
||||||
|
errors.add(() -> sendMessage(sender, s, args1));
|
||||||
|
}));
|
||||||
|
if (executed) return;
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
errors.forEach(Runnable::run);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
descriptions.forEach(s -> sendMessage(sender, s, new Object[0]));
|
||||||
|
} catch (CommandFrameworkException e) {
|
||||||
|
commandSystemError(sender, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final List<String> tabComplete(T sender, String alias, String[] args) throws IllegalArgumentException {
|
||||||
|
initialize();
|
||||||
|
List<Collection<String>> tabCompletes = new ArrayList<>();
|
||||||
|
rootNode.tabComplete(sender, new NodeData(alias, fixArgs(args, false), (s, args1) -> {}), tabCompletes);
|
||||||
|
return tabCompletes.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] fixArgs(String[] args, boolean allowEmpty) {
|
||||||
|
int removedCount = 0;
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
String arg = args[i];
|
||||||
|
if (arg.isEmpty() && i != args.length - 1) {
|
||||||
|
removedCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
args[i] = args[i - removedCount];
|
||||||
|
}
|
||||||
|
if (removedCount != 0) {
|
||||||
|
args = Arrays.copyOf(args, args.length - removedCount);
|
||||||
|
}
|
||||||
|
if (args.length == 0 && !allowEmpty) {
|
||||||
|
return new String[]{""};
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void initialize() {
|
||||||
|
if (initialized) return;
|
||||||
|
|
||||||
|
List<Object> commandObjects = new ArrayList<>();
|
||||||
|
initializer.accept(new CommandLoader<>() {
|
||||||
|
@Override
|
||||||
|
public AbstractCommand<T> get() {
|
||||||
|
return AbstractCommand.this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Object command) {
|
||||||
|
commandObjects.add(command);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
List<Pair<DataImpl, Method>> methods = new ArrayList<>();
|
||||||
|
for (Object commandObject : commandObjects) {
|
||||||
|
DataImpl dataImpl = new DataImpl(this, commandObject, rootNode, EXECUTOR_MAPPER.getOrDefault(this.getClass(), Collections.emptyMap()), (Map) localTypeMapper, CommandUtils.MAPPER_FUNCTIONS, (Map) localValidators, CommandUtils.VALIDATOR_FUNCTIONS, (Map) localSupplier, CommandUtils.SUPPLIER_FUNCTIONS);
|
||||||
|
methods(commandObject).stream()
|
||||||
|
.filter(method -> Arrays.stream(method.getAnnotations()).anyMatch(anno -> anno.annotationType().isAnnotationPresent(Handler.Implementation.class)))
|
||||||
|
.forEach(method -> methods.add(new Pair<>(dataImpl, method)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Map<Triple<DataImpl, Method, Annotation>, List<Handler.HandlerMethod<Annotation>>>> handlerMap = new HashMap<>();
|
||||||
|
for (Pair<DataImpl, Method> commandMethod : methods) {
|
||||||
|
List<Annotation> annotations = CommandUtils.getAnnotations(commandMethod.b);
|
||||||
|
for (Annotation annotation : annotations) {
|
||||||
|
Handler.Implementation handler = annotation.annotationType().getAnnotation(Handler.Implementation.class);
|
||||||
|
Handler handlerObject;
|
||||||
|
try {
|
||||||
|
handlerObject = handler.value().getConstructor().newInstance();
|
||||||
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||||
|
InvocationTargetException e) {
|
||||||
|
throw new UnsupportedOperationException("Handler " + handler.value().getName() + " cannot be used to check the argument validity", e);
|
||||||
|
}
|
||||||
|
if (!(handlerObject instanceof Handler.HandlerMethod)) {
|
||||||
|
throw new UnsupportedOperationException("Handler " + handlerObject.getClass().getName() + " is not a HandlerMethod");
|
||||||
|
}
|
||||||
|
handlerMap.computeIfAbsent(((Handler.HandlerMethod<?>) handlerObject).getRunPriority(), k -> new LinkedHashMap<>())
|
||||||
|
.computeIfAbsent(new Triple<>(commandMethod.a, commandMethod.b, annotation), k -> new ArrayList<>())
|
||||||
|
.add((Handler.HandlerMethod<Annotation>) handlerObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> runPriorities = new ArrayList<>(handlerMap.keySet());
|
||||||
|
runPriorities.sort(Comparator.naturalOrder());
|
||||||
|
for (int runPriority : runPriorities) {
|
||||||
|
handlerMap.get(runPriority).forEach((dataMethodAnnotationTriple, handlerMethods) -> {
|
||||||
|
handlerMethods.forEach(annotationHandlerMethod -> {
|
||||||
|
try {
|
||||||
|
annotationHandlerMethod.check(new Handler.AnnotationWrapper.ForAnnotation<>(dataMethodAnnotationTriple.c), new Handler.MethodWrapper.ForMethod(dataMethodAnnotationTriple.b), dataMethodAnnotationTriple.a);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedOperationException("Method check failed for " + dataMethodAnnotationTriple.b.getName(), e);
|
||||||
|
}
|
||||||
|
annotationHandlerMethod.run(dataMethodAnnotationTriple.c, dataMethodAnnotationTriple.b, dataMethodAnnotationTriple.a);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
rootNode.sort();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement this when Message System is ready
|
||||||
|
/*
|
||||||
|
public void addDefaultHelpMessage(String message) {
|
||||||
|
defaultHelpMessages.add(message);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private List<Method> methods(Object commandObject) {
|
||||||
|
List<Method> methods = new ArrayList<>();
|
||||||
|
Class<?> current = commandObject.getClass();
|
||||||
|
while (current != null) {
|
||||||
|
methods.addAll(Arrays.asList(current.getDeclaredMethods()));
|
||||||
|
current = current.getSuperclass();
|
||||||
|
}
|
||||||
|
return methods;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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.command;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface AbstractTypeMapper<K, T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CommandSender can be null!
|
||||||
|
*/
|
||||||
|
T map(K sender, PreviousArguments previousArguments, String s);
|
||||||
|
|
||||||
|
Collection<String> tabComplete(K sender, PreviousArguments previousArguments, String s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the next element should be appended to the current tab complete.
|
||||||
|
*/
|
||||||
|
default boolean appendNextElementTabCompletions() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize the cache key by sender and user provided argument. <br>
|
||||||
|
* Note: The CommandSender can be null if the cache is defined as a global cache!<br>
|
||||||
|
* Returning null and the empty string are equivalent.
|
||||||
|
*/
|
||||||
|
default String normalize(K sender, String s) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 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.command;
|
||||||
|
|
||||||
|
public interface AbstractTypeSupplier<K, T> {
|
||||||
|
|
||||||
|
T get(K sender, PreviousArguments previousArguments);
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 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.command;
|
||||||
|
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface AbstractTypeValidator<K, T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the given value.
|
||||||
|
*
|
||||||
|
* @param sender The sender of the command.
|
||||||
|
* @param value The value to validate or null if mapping returned null.
|
||||||
|
* @param messageSender The message sender to send messages to the player. Never send messages directly to the player.
|
||||||
|
* @return The result of the validation.
|
||||||
|
*/
|
||||||
|
boolean validate(K sender, T value, MessageSender messageSender);
|
||||||
|
|
||||||
|
default AbstractTypeValidator<K, T> and(AbstractTypeValidator<K, T> other) {
|
||||||
|
return (sender, value, messageSender) -> validate(sender, value, messageSender) && other.validate(sender, value, messageSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
default AbstractTypeValidator<K, T> or(AbstractTypeValidator<K, T> other) {
|
||||||
|
return (sender, value, messageSender) -> validate(sender, value, messageSender) || other.validate(sender, value, messageSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
default AbstractTypeValidator<K, T> not() {
|
||||||
|
return (sender, value, messageSender) -> !validate(sender, value, messageSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
interface MessageSender {
|
||||||
|
void send(String s, Object... args);
|
||||||
|
|
||||||
|
default boolean send(boolean condition, String s, Object... args) {
|
||||||
|
if (condition) send(s, args);
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean send(BooleanSupplier condition, String s, Object... args) {
|
||||||
|
return send(condition.getAsBoolean(), s, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user