138 Commits

Author SHA1 Message Date
0b689c90eb Add new Schematic reader 2025-01-08 12:49:17 +01:00
da4aa0aef5 Add new Schematic reader 2025-01-07 16:59:36 +01:00
Lixfel
46fed25da4 Fix renaming for class name duplications 2025-01-07 16:38:40 +01:00
Lixfel
d3fbbb9768 Merge pull request 'Mojang map reflections' (#89) from MojMapReflections into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/89
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2025-01-07 16:27:02 +01:00
ed16de900e Merge pull request 'Fix /schem changetype schem type normal' (#99) from SchematicSystem/changetypenormal into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/99
Reviewed-by: Chaoscaot <chaos@chaoscaot.de>
2025-01-06 20:12:19 +01:00
Lixfel
66f4efb27f Fix /schem changetype schem type normal 2025-01-06 19:24:15 +01:00
Lixfel
9888700273 Migrate reflections to mojang mapped by default 2025-01-06 16:44:10 +01:00
Lixfel
94a1ed3569 More robust version detection. 2025-01-06 10:25:19 +01:00
Lixfel
da148c0e9f Replace {nms} and {obc} tags 2025-01-06 10:15:48 +01:00
Lixfel
ab34d86da4 Merge branch 'main' into MojMapReflections
# Conflicts:
#	SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java
#	SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java
#	SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java
2025-01-06 10:06:28 +01:00
Lixfel
a3490b801e Fix server transfer failure after checkpoint restoration 2025-01-03 12:55:59 +01:00
Lixfel
856c79661b Merge pull request 'Move ViaVersion to Proxy' (#87) from ViaOnProxy into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/87
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2025-01-03 07:33:45 +01:00
Lixfel
9f0f11adeb Fix entity orientation 2025-01-02 17:24:37 +01:00
Lixfel
6b7825ead9 Fix version matching 2025-01-02 11:05:07 +01:00
025ec2a850 Hotfix: 1.20 Schematic Reader 2025-01-01 14:12:38 +01:00
Lixfel
d7d6c2df7b Merge pull request 'VelocityCore/PrivateTicketLog' (#61) from VelocityCore/PrivateTicketLog into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/61
Reviewed-by: Lixfel <lixfel@steamwar.de>
2025-01-01 13:00:44 +01:00
Lixfel
55c3579e5c Merge pull request 'Add custom NPC Chats for specific players' (#93) from LobbySystem/NPCChats into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/93
Reviewed-by: Lixfel <lixfel@steamwar.de>
2025-01-01 12:58:12 +01:00
Lixfel
d64e32eaa5 Cleanup code 2025-01-01 12:56:49 +01:00
Lixfel
abb8ab2204 Merge pull request 'Fix Schematics Readers' (#72) from Schematics/1.21 into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/72
Reviewed-by: Lixfel <lixfel@steamwar.de>
2025-01-01 12:42:01 +01:00
c1dbce4648 Fix EventListener.onPlayerQuit 2024-12-31 18:56:42 +01:00
7dc5686389 Fixes... 2024-12-31 11:25:00 +01:00
f52cec0448 Add custom NPC Chats for TheBreadBeard 2024-12-28 22:58:35 +01:00
add43b2f54 Merge pull request 'Remove anti pickaxe drop code' (#94) from TNTLeague/RemovePickaxeDropCode into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/94
Reviewed-by: Chaoscaot <chaos@chaoscaot.de>
2024-12-28 22:28:20 +01:00
ca0f82897e Remove anti pickaxe drop code 2024-12-28 18:26:04 +01:00
f111d55200 Add custom NPC Chats for specific players 2024-12-28 17:36:40 +01:00
7eba9231d5 Fix build issues 2024-12-28 17:15:57 +01:00
e9ac198fcb Remove deop on TNTLeague join (mit Lixfel abgesprochen) 2024-12-26 22:42:07 +01:00
3a47e348d0 Merge pull request 'Add LastOnline to WhoisCommand' (#90) from VelocityCore/LastOnlineTime into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/90
Reviewed-by: Lixfel <lixfel@steamwar.de>
2024-12-26 22:23:01 +01:00
a16e1e8cee Add LastOnline to WhoisCommand 2024-12-26 21:44:40 +01:00
Lixfel
0f73939bf0 Move and rename Reflection fields 2024-12-26 19:11:01 +01:00
Lixfel
30ac38ef53 Merge pull request 'Remove /leader command, allow for Leader promotion' (#86) from FightSystem/Leader into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/86
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2024-12-26 10:53:07 +01:00
Lixfel
22a8ca4aea Move ViaVersion to Proxy 2024-12-24 14:55:27 +01:00
Lixfel
bd87221198 Add subcommand to reload gamemodes without full softreload 2024-12-23 13:12:57 +01:00
Lixfel
fb0a653b0e Remove /leader command, allow for Leader promotion 2024-12-23 13:05:00 +01:00
9154077104 Fix TNT League Stage Names 2024-12-23 12:50:38 +01:00
4448eab877 Hotfix: Rework Pickaxe 2024-12-22 22:54:46 +01:00
180fb685bd Hotfix: SubMessage 2024-12-22 22:49:06 +01:00
df1ec88f6c Hotfix: SubMessage 2024-12-22 22:46:00 +01:00
655b6cd15f Merge pull request 'Add Some Fixes and Improvements' (#83) from TNTLeague/fixes-and-improvements into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/83
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2024-12-22 22:38:03 +01:00
867091d210 Merge remote-tracking branch 'origin/TNTLeague/fixes-and-improvements' into TNTLeague/fixes-and-improvements 2024-12-22 22:27:45 +01:00
2f34369756 Fix SubMessage class 2024-12-22 22:27:30 +01:00
89fe401b03 Cleanup DealerInventory and TNTLeagueConfig 2024-12-22 22:22:42 +01:00
aaa808f90f Add Some Fixes and Improvements 2024-12-22 21:57:54 +01:00
Lixfel
1ea6bd61f8 Fix concurrent cipher usage 2024-12-22 16:17:58 +01:00
Lixfel
026b7bcc0e Fix SpectatePort 2024-12-22 16:02:52 +01:00
Lixfel
4da2307d50 Merge pull request 'TechHider refactoring, simple Blocktagging' (#82) from blocktagger into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/82
Reviewed-by: Chaoscaot <chaos@chaoscaot.de>
2024-12-22 07:18:41 +01:00
Lixfel
7d9996529e Add orientation pattern 2024-12-21 21:19:40 +01:00
a2710628a5 Update TechHiderWrapper and add orientation pattern 2024-12-21 19:47:40 +01:00
ec5382316a Fixes 2024-12-21 19:33:23 +01:00
51fd5faa4d Merge branch 'main' into Schematics/1.21
# Conflicts:
#	VelocityCore/build.gradle.kts
2024-12-21 19:29:46 +01:00
Lixfel
acbc5c5fd3 Cryptographically secure signature 2024-12-21 18:46:33 +01:00
Lixfel
793fc31b5c TechHider refactoring, simple Blocktagging 2024-12-21 16:53:49 +01:00
1b47700c19 Fix Event 2024-12-21 16:16:54 +01:00
06b0af5a16 Hotfix API EventFight Create 2024-12-21 15:42:27 +01:00
d08ccc3a98 Fix Everything 2024-12-21 12:30:39 +01:00
336915dd96 Fix Schem Upload 2024-12-21 12:03:43 +01:00
Lixfel
8fac9cd37e Merge pull request 'Partial diagonal HullHider uncovering, performance improvement' (#79) from FIghtSystem/partialSides into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/79
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2024-12-21 11:21:45 +01:00
Lixfel
3b2ee668b2 Merge pull request 'Additional Pluginmessage classifications, Lunar refactoring' (#80) from VelocityCore/PluginMessages into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/80
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2024-12-21 11:21:21 +01:00
Lixfel
c479d21cd2 Additional Pluginmessage classifications, Lunar refactoring 2024-12-21 11:09:16 +01:00
Lixfel
10e016c850 Partial diagonal HullHider uncovering, performance improvement 2024-12-21 10:52:41 +01:00
0e43c2a615 Hotfix: SW Survival 2024-12-17 20:02:12 +01:00
9eab15bfd5 Hotfix: Groups 2024-12-15 17:18:40 +01:00
2436340765 Fixes and Balances 2024-12-13 19:13:14 +01:00
7d9b3cd098 Merge remote-tracking branch 'origin/main' 2024-12-13 13:08:34 +01:00
85c6dcdc1e Add TNTLeague Auto-Stop 2024-12-13 13:08:28 +01:00
Lixfel
997a800c85 Fix Hullhider 1.15-, improve performance. 2024-12-13 11:26:19 +01:00
Lixfel
a5ffddad66 Add AdminReplay line of sight tools. 2024-12-13 10:42:44 +01:00
61e8ba14ca Fixes 2024-12-13 10:22:01 +01:00
56c66b33b7 Fix Locations 2024-12-13 09:43:18 +01:00
b90884ee1d Fix Locations 2024-12-13 09:31:15 +01:00
e1d3e47845 Fixes and De-Spagetti Code 2024-12-12 16:09:25 +01:00
b12846d011 Merge remote-tracking branch 'origin/main' 2024-12-11 15:05:02 +01:00
7488a4d063 Remove Stats 2024-12-11 15:04:54 +01:00
Lixfel
429e2f86aa Fix Hullhider. 2024-12-11 15:03:32 +01:00
Lixfel
c308a06e6b Test if broadcasting apollo:json acceptance triggers ModList sending. 2024-12-11 14:48:32 +01:00
68c7cfed73 Hotfix: Allow ReplayMod on Devservers 2024-12-11 14:34:31 +01:00
c3c4b94e3b Fix TNTLeague Sound 2024-12-11 14:20:38 +01:00
f61c27804a Fix TNTLeague Sound 2024-12-11 14:11:39 +01:00
b36c974f86 Fix TNTLeague Sound 2024-12-11 14:08:33 +01:00
ae4d498694 Fix TNTLeague Sound 2024-12-11 14:04:06 +01:00
Lixfel
e9f6b284eb Test if broadcasting apollo:json acceptance triggers ModList sending. 2024-12-11 13:26:12 +01:00
Lixfel
454cfecc0e Merge pull request 'Better Hull Hider Algorithm' (#76) from FightSystem/HullHiderAlgo_v2 into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/76
Reviewed-by: Chaoscaot <chaos@chaoscaot.de>
2024-12-11 13:16:39 +01:00
bc217c16dd Merge pull request 'Finish TNTLeague' (#53) from TNTLeague/finish into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/53
Reviewed-by: Lixfel <lixfel@steamwar.de>
2024-12-11 10:53:39 +01:00
d3f6075686 Add to CI 2024-12-11 10:53:17 +01:00
Lixfel
a1e77e571b Fix entity hider. 2024-12-11 09:52:05 +01:00
Lixfel
b31bd58e1a Handle additional recorded plugin channels. 2024-12-10 12:58:19 +01:00
Lixfel
f81b95e39f Fix direction id. 2024-12-10 12:57:21 +01:00
Lixfel
7ce5e319b5 Reduce unnecessary branch propagation by early abort with primary direction visibility. 2024-12-10 11:08:44 +01:00
Lixfel
c50bb64516 Performance improvements 2024-12-10 01:59:16 +01:00
Lixfel
b1c0e36cee Remove diagonal diagonals, branch only in enemy direction 2024-12-10 00:44:26 +01:00
Lixfel
be653754a7 Better Hull Hider Algorithm
Cardinal visibility with diagonal branching.
2024-12-10 00:01:47 +01:00
9c055ee929 Merge pull request 'Fix Schematic Punishment Messages' (#75) from SchematicSystem/fix-punishment into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/75
Reviewed-by: Lixfel <lixfel@steamwar.de>
2024-12-09 19:06:00 +01:00
80ab0eeda0 Fix 2024-12-09 19:05:36 +01:00
257f70cc6a Merge pull request 'Limit maximum number of sent in Schematics' (#74) from SchematicSystem/no-more-than-three into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/74
Reviewed-by: Lixfel <lixfel@steamwar.de>
2024-12-09 19:02:46 +01:00
Lixfel
970780b855 Reduce PluginMessage spam 2024-12-09 16:26:48 +01:00
Lixfel
c0d9b9f89b Fix /historic hover 2024-12-09 16:20:21 +01:00
6d0fa6527e Fix Schematic Punishment Messages 2024-12-08 23:40:50 +01:00
df4cd12d2a Unused Import 2024-12-08 23:29:57 +01:00
60dc00fd92 Limit maximum number of sent in Schematics 2024-12-08 23:29:13 +01:00
06eec10660 Fixes... 2024-12-08 23:18:32 +01:00
e1010f79e9 Merge pull request 'Fix color region reset' (#73) from BauSystem/resetColor into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/73
Reviewed-by: YoyoNow <jwsteam@nidido.de>
2024-12-06 21:04:49 +01:00
e93683842b Language 2024-12-06 18:36:59 +01:00
Lixfel
cd17e625ca Remove debug output 2024-12-06 13:39:08 +01:00
Lixfel
d21e50dadd Test fix DiscordAlert 2024-12-06 13:36:13 +01:00
Lixfel
19ea605784 Debug DiscordAlert 2024-12-06 13:32:37 +01:00
Lixfel
4c12148552 Fix color region reset 2024-12-06 13:22:02 +01:00
Lixfel
da672a7506 Fix tablist after softreload 2024-12-06 13:07:21 +01:00
Lixfel
2f50c7acae Add debug output for DiscordAlert malfunction, add plugin messages 2024-12-06 12:50:09 +01:00
Lixfel
ed276bf4ce Fix for delayed interaction replys, add plugin messages 2024-12-06 11:41:29 +01:00
Lixfel
f5f8b3bd06 Test fix for delayed interaction replys 2024-12-06 11:23:54 +01:00
Lixfel
f01f869479 Fix logging of WARN level in Exception table 2024-12-05 21:48:52 +01:00
Lixfel
3ce958778a Fix NPE 2024-12-05 16:03:21 +01:00
Lixfel
c4849657df Deploy api backend 2024-12-05 13:28:46 +01:00
Lixfel
9a6dec6679 Merge pull request 'SubserverSystem-Refactoring' (#71) from SubserverSystem-Refactoring into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/71
Reviewed-by: Chaoscaot <chaos@chaoscaot.de>
2024-12-04 11:43:27 +01:00
0134ef1f61 Maybe, Fix Schematics Readers 2024-12-03 22:43:14 +01:00
19a4d0e93a Fixes 2024-12-03 17:17:29 +01:00
677eb4137a Merge branch 'main' into TNTLeague/finish 2024-12-03 17:07:56 +01:00
Lixfel
7b55e99be0 Fix arena start condition 2024-12-03 17:05:53 +01:00
Lixfel
3abba4ae35 Add /build stop command 2024-12-03 15:50:32 +01:00
Lixfel
d2650ad97f Remove Servertype enum, fix starting multiple servers at once, 2024-12-03 15:42:57 +01:00
b3cd8d843f Add private ticket log 2024-11-27 19:34:19 +01:00
3e270643e8 Add private ticket log 2024-11-27 19:18:41 +01:00
8bb2be52f2 Language Fixes 2024-11-24 22:38:01 +01:00
d30fb5f949 Merge remote-tracking branch 'origin/main' into TNTLeague/finish 2024-11-24 22:20:41 +01:00
5e74aaad2c Merge branch 'main' into TNTLeague/finish 2024-11-24 22:13:01 +01:00
ec990cb52a Remove Component Messages 2024-11-24 21:35:13 +01:00
9415a3f217 Nits 2024-11-18 18:02:15 +01:00
4bb1bc0cbd Fixes, changes and Refactors 2024-11-17 12:04:07 +01:00
78853c70f8 Fixes and Update Copyright 2024-11-15 23:42:08 +01:00
5ac327409b Merge branch 'SpigotCore/1.21' into TNTLeague/finish 2024-11-15 23:13:44 +01:00
2e9dbfe8b8 Fixes... 2024-11-15 21:35:10 +01:00
27bd7be776 Fix Translations 2024-11-14 22:55:03 +01:00
9dff1f5884 Revert "Update Message"
This reverts commit ac9197c554.
2024-11-14 22:18:34 +01:00
26f15304a2 Merge branch 'KotlinCore/message-update' into TNTLeague/finish 2024-11-14 22:16:14 +01:00
d115975403 Add ComponentMessage, for TranslatableComponents in Paper >1.20 2024-11-14 22:08:06 +01:00
ac9197c554 Update Message 2024-11-14 19:31:17 +01:00
9d87ac6747 Merge branch 'main' into TNTLeague/finish 2024-11-10 16:47:14 +01:00
4edc59ba66 Add translations 2024-08-29 22:33:54 +02:00
455 changed files with 3073 additions and 18220 deletions

View File

@@ -19,27 +19,21 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.util.NoClipCommand;
import net.minecraft.server.v1_15_R1.*; import net.minecraft.server.v1_15_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.LongSupplier;
public class NMSWrapper15 implements NMSWrapper { public class NMSWrapper15 implements NMSWrapper {
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); private static final Reflection.Field<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -63,7 +57,7 @@ public class NMSWrapper15 implements NMSWrapper {
player.updateInventory(); player.updateInventory();
} }
private static final Reflection.FieldAccessor<Integer> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0); private static final Reflection.Field<Integer> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0);
@Override @Override
public void setGameStateChangeReason(Object packet) { public void setGameStateChangeReason(Object packet) {
@@ -120,12 +114,12 @@ public class NMSWrapper15 implements NMSWrapper {
return invalid; return invalid;
} }
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Class<?> explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket");
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field<Double> a = Reflection.getField(explosionPacket, double.class, 0);
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field<Double> b = Reflection.getField(explosionPacket, double.class, 1);
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2); private final Reflection.Field<Double> c = Reflection.getField(explosionPacket, double.class, 2);
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0); private final Reflection.Field<Float> d = Reflection.getField(explosionPacket, float.class, 0);
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0); private final Reflection.Field<List> e = Reflection.getField(explosionPacket, List.class, 0);
@Override @Override
public Object resetExplosionKnockback(Object packet) { public Object resetExplosionKnockback(Object packet) {

View File

@@ -19,12 +19,9 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.EntityPlayer;
import net.minecraft.server.v1_15_R1.PacketPlayInFlying; import net.minecraft.server.v1_15_R1.PacketPlayInFlying;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntity;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -19,36 +19,26 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.util.NoClipCommand;
import net.minecraft.SystemUtils;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.server.level.PlayerInteractManager;
import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.phys.Vec3D;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.LongSupplier;
public class NMSWrapper18 implements NMSWrapper { public class NMSWrapper18 implements NMSWrapper {
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); private static final Reflection.Field<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -73,7 +63,7 @@ public class NMSWrapper18 implements NMSWrapper {
player.updateInventory(); player.updateInventory();
} }
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); private static final Reflection.Field<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
@Override @Override
public void setGameStateChangeReason(Object packet) { public void setGameStateChangeReason(Object packet) {
@@ -130,12 +120,12 @@ public class NMSWrapper18 implements NMSWrapper {
return invalid; return invalid;
} }
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Class<?> explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket");
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field<Double> a = Reflection.getField(explosionPacket, double.class, 0);
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field<Double> b = Reflection.getField(explosionPacket, double.class, 1);
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2); private final Reflection.Field<Double> c = Reflection.getField(explosionPacket, double.class, 2);
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0); private final Reflection.Field<Float> d = Reflection.getField(explosionPacket, float.class, 0);
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0); private final Reflection.Field<List> e = Reflection.getField(explosionPacket, List.class, 0);
@Override @Override
public Object resetExplosionKnockback(Object packet) { public Object resetExplosionKnockback(Object packet) {

View File

@@ -19,8 +19,7 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.network.protocol.game.PacketPlayInFlying;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.EntityPlayer;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;

View File

@@ -19,37 +19,26 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.util.NoClipCommand;
import net.minecraft.SystemUtils;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.DataWatcher;
import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.server.level.PlayerInteractManager;
import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.phys.Vec3D;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.LongSupplier;
public class NMSWrapper19 implements NMSWrapper { public class NMSWrapper19 implements NMSWrapper {
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); private static final Reflection.Field<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -73,7 +62,7 @@ public class NMSWrapper19 implements NMSWrapper {
player.updateInventory(); player.updateInventory();
} }
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); private static final Reflection.Field<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
@Override @Override
public void setGameStateChangeReason(Object packet) { public void setGameStateChangeReason(Object packet) {
@@ -130,12 +119,12 @@ public class NMSWrapper19 implements NMSWrapper {
return invalid; return invalid;
} }
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Class<?> explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket");
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field<Double> a = Reflection.getField(explosionPacket, double.class, 0);
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field<Double> b = Reflection.getField(explosionPacket, double.class, 1);
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2); private final Reflection.Field<Double> c = Reflection.getField(explosionPacket, double.class, 2);
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0); private final Reflection.Field<Float> d = Reflection.getField(explosionPacket, float.class, 0);
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0); private final Reflection.Field<List> e = Reflection.getField(explosionPacket, List.class, 0);
@Override @Override
public Object resetExplosionKnockback(Object packet) { public Object resetExplosionKnockback(Object packet) {

View File

@@ -19,17 +19,12 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.network.protocol.game.PacketPlayInFlying;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.EntityPlayer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class PlayerMovementWrapper19 implements PlayerMovementWrapper { public class PlayerMovementWrapper19 implements PlayerMovementWrapper {
@Override @Override

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.util.NoClipCommand;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -40,7 +40,7 @@ import java.util.List;
public class NMSWrapper20 implements NMSWrapper { public class NMSWrapper20 implements NMSWrapper {
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); private static final Reflection.Field<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -64,7 +64,7 @@ public class NMSWrapper20 implements NMSWrapper {
player.updateInventory(); player.updateInventory();
} }
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); private static final Reflection.Field<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
@Override @Override
public void setGameStateChangeReason(Object packet) { public void setGameStateChangeReason(Object packet) {
@@ -121,12 +121,12 @@ public class NMSWrapper20 implements NMSWrapper {
return invalid; return invalid;
} }
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Class<?> explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket");
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.Field<Double> a = Reflection.getField(explosionPacket, double.class, 0);
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1); private final Reflection.Field<Double> b = Reflection.getField(explosionPacket, double.class, 1);
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2); private final Reflection.Field<Double> c = Reflection.getField(explosionPacket, double.class, 2);
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0); private final Reflection.Field<Float> d = Reflection.getField(explosionPacket, float.class, 0);
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0); private final Reflection.Field<List> e = Reflection.getField(explosionPacket, List.class, 0);
@Override @Override
public Object resetExplosionKnockback(Object packet) { public Object resetExplosionKnockback(Object packet) {

View File

@@ -19,18 +19,12 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.network.protocol.game.PacketPlayInFlying;
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.EntityPlayer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class PlayerMovementWrapper20 implements PlayerMovementWrapper { public class PlayerMovementWrapper20 implements PlayerMovementWrapper {
@Override @Override

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.features.util.NoClipCommand; import de.steamwar.bausystem.features.util.NoClipCommand;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
@@ -45,7 +45,7 @@ import java.util.Optional;
public class NMSWrapper21 implements NMSWrapper { public class NMSWrapper21 implements NMSWrapper {
private static final Reflection.FieldAccessor<PlayerInteractManager> playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class); private static final Reflection.Field<PlayerInteractManager> playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class);
@Override @Override
public void setInternalGameMode(Player player, GameMode gameMode) { public void setInternalGameMode(Player player, GameMode gameMode) {
@@ -68,14 +68,14 @@ public class NMSWrapper21 implements NMSWrapper {
player.updateInventory(); player.updateInventory();
} }
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); private static final Reflection.Field<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
@Override @Override
public void setGameStateChangeReason(Object packet) { public void setGameStateChangeReason(Object packet) {
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d); gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
} }
private static final Reflection.FieldAccessor<PlayerAbilities> playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class); private static final Reflection.Field<PlayerAbilities> playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class);
@Override @Override
public void setPlayerBuildAbilities(Player player) { public void setPlayerBuildAbilities(Player player) {

View File

@@ -38,7 +38,6 @@ dependencies {
compileOnly(libs.spigotapi) compileOnly(libs.spigotapi)
compileOnly(libs.axiom) compileOnly(libs.axiom)
compileOnly(libs.authlib) compileOnly(libs.authlib)
compileOnly(libs.viaapi)
compileOnly(libs.fawe18) compileOnly(libs.fawe18)

View File

@@ -1014,5 +1014,3 @@ COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §
TYPEREPLACE_HELP=§8//§etypereplace §8[§7type§8] §8[§7type§8] §8- §7Replace all blocks of one type with another TYPEREPLACE_HELP=§8//§etypereplace §8[§7type§8] §8[§7type§8] §8- §7Replace all blocks of one type with another
# Schematic # Schematic
SCHEMATIC_GUI_ITEM=§eSchematics SCHEMATIC_GUI_ITEM=§eSchematics
#VersionAnnouncer
SERVER_VERSION=§7This server runs on Minecraft version §e{0}

View File

@@ -955,5 +955,3 @@ COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §
TYPEREPLACE_HELP=§8//§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Ersetzt einen Blockgruppe mit einer anderen TYPEREPLACE_HELP=§8//§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Ersetzt einen Blockgruppe mit einer anderen
# Schematics # Schematics
SCHEMATIC_GUI_ITEM=§eSchematics SCHEMATIC_GUI_ITEM=§eSchematics
#VersionAnnouncer
SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0}

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.observer; package de.steamwar.bausystem.features.observer;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Point;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@@ -170,7 +170,7 @@ public class ObserverTracer {
} }
} }
private static final Class<?> craftPoweredRail = Reflection.getClass("{obc}.block.impl.CraftPoweredRail"); private static final Class<?> craftPoweredRail = Reflection.getClass("org.bukkit.craftbukkit.block.impl.CraftPoweredRail");
private boolean checkAllowed(Block block, BlockData blockData) { private boolean checkAllowed(Block block, BlockData blockData) {
if (checkMaterial(block)) return true; if (checkMaterial(block)) return true;
if (block.getType() == Material.BELL) { if (block.getType() == Material.BELL) {

View File

@@ -20,7 +20,6 @@
package de.steamwar.bausystem.features.region; package de.steamwar.bausystem.features.region;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.config.BauServer;
import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
@@ -31,7 +30,6 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance; import de.steamwar.linkage.LinkedInstance;
import de.steamwar.sql.Punishment; import de.steamwar.sql.Punishment;
@@ -40,7 +38,6 @@ import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
@Linked @Linked
@@ -61,7 +58,7 @@ public class ResetCommand extends SWCommand {
PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL)))
.color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()); .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor());
region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL);
for (Flag value : Flag.values()) { for (Flag value : Flag.getResetFlags()) {
region.set(value, value.getDefaultValue()); region.set(value, value.getDefaultValue());
} }
RegionUtils.message(region, "REGION_RESET_RESETED"); RegionUtils.message(region, "REGION_RESET_RESETED");

View File

@@ -24,7 +24,6 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.script.ScriptRunner; 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.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
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;
@@ -32,7 +31,6 @@ import de.steamwar.core.TrickyTrialsWrapper;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@@ -72,10 +70,11 @@ public class EventListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
StorageLib.removePlayer(event.getPlayer()); if(Permission.BUILD.hasPermission(event.getPlayer())) {
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event); ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event);
} }
StorageLib.removePlayer(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
@@ -72,9 +72,9 @@ import java.util.stream.Collectors;
public class SimulatorCursor implements Listener { public class SimulatorCursor implements Listener {
private final World WORLD = Bukkit.getWorlds().get(0); private final World WORLD = Bukkit.getWorlds().get(0);
private Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); private Class<?> position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
private Class<?> look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); private Class<?> look = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot");
private Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); private Class<?> positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
private Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>()); private Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
private Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>()); private Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.smartplace; package de.steamwar.bausystem.features.smartplace;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
@@ -81,7 +81,7 @@ public class SmartPlaceListener implements Listener {
IGNORED.remove(Material.BARRIER); IGNORED.remove(Material.BARRIER);
} }
private static final Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); private static final Class<?> useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket");
private static final Set<Player> SMART_PLACING = new HashSet<>(); private static final Set<Player> SMART_PLACING = new HashSet<>();
private static final Set<Player> WAS_EXECUTED = new HashSet<>(); private static final Set<Player> WAS_EXECUTED = new HashSet<>();

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.tpslimit; package de.steamwar.bausystem.features.tpslimit;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.core.BountifulWrapper; import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.ChatWrapper; import de.steamwar.core.ChatWrapper;
@@ -45,18 +45,18 @@ class PacketCache {
private static Set<Entity> entities = new HashSet<>(); private static Set<Entity> entities = new HashSet<>();
private static BukkitTask task = null; private static BukkitTask task = null;
private static Class<?> vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D"); private static Class<?> vec3dClass = Reflection.getClass("net.minecraft.world.phys.Vec3");
private static Reflection.FieldAccessor<Object> zeroVec3d = (Reflection.FieldAccessor<Object>) Reflection.getField(vec3dClass, vec3dClass, 0); private static Reflection.Field<Object> zeroVec3d = (Reflection.Field<Object>) Reflection.getField(vec3dClass, vec3dClass, 0);
private static Object ZERO_VEC3D = zeroVec3d.get(null); private static Object ZERO_VEC3D = zeroVec3d.get(null);
private static Class<?> velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); private static Class<?> velocityPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket");
private static Reflection.ConstructorInvoker velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); private static Reflection.Constructor velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass);
private static Class<?> teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); private static Class<?> teleportPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket");
private static Class<?> entityClass = Reflection.getClass("{nms.world.entity}.Entity"); private static Class<?> entityClass = Reflection.getClass("net.minecraft.world.entity.Entity");
private static Reflection.ConstructorInvoker teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); private static Reflection.Constructor teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass);
private static Class<?> craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity"); private static Class<?> craftEntityClass = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity");
private static Reflection.MethodInvoker getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); private static Reflection.Method getHandle = Reflection.getMethod(craftEntityClass, "getHandle");
private static Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class); private static Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class);
private static Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); private static Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class);

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.tpslimit; package de.steamwar.bausystem.features.tpslimit;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import lombok.Getter; import lombok.Getter;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -28,11 +28,11 @@ import org.bukkit.World;
@UtilityClass @UtilityClass
public class TPSFreezeUtils { public class TPSFreezeUtils {
private static Reflection.FieldAccessor<Boolean> fieldAccessor; private static Reflection.Field<Boolean> fieldAccessor;
@Getter @Getter
private static final boolean canFreeze; private static final boolean canFreeze;
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null);
@Getter @Getter
private static boolean frozen = false; private static boolean frozen = false;
@@ -40,9 +40,9 @@ public class TPSFreezeUtils {
private static final World world = Bukkit.getWorlds().get(0); private static final World world = Bukkit.getWorlds().get(0);
static { static {
Reflection.FieldAccessor<Boolean> fieldAccessor; Reflection.Field<Boolean> fieldAccessor;
try { try {
fieldAccessor = Reflection.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed", boolean.class); fieldAccessor = Reflection.getField(Reflection.getClass("net.minecraft.server.level.ServerLevel"), "freezed", boolean.class);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
fieldAccessor = null; fieldAccessor = null;
} }

View File

@@ -19,15 +19,12 @@
package de.steamwar.bausystem.features.tpslimit; package de.steamwar.bausystem.features.tpslimit;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.utils.PlayerMovementWrapper; import de.steamwar.bausystem.utils.PlayerMovementWrapper;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.core.TPSWatcher;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@@ -104,8 +101,8 @@ public class TPSLimitUtils {
} }
*/ */
private static final Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); private static final Class<?> position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
private static final Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); private static final Class<?> positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
static { static {
BiFunction<Player, Object, Object> positionSetter = (player, o) -> { BiFunction<Player, Object, Object> positionSetter = (player, o) -> {
if (tpsLimiter != null) { if (tpsLimiter != null) {

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.util; package de.steamwar.bausystem.features.util;
import com.comphenix.tinyprotocol.Reflection; 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.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
@@ -49,15 +49,15 @@ import java.util.function.BiFunction;
@Linked @Linked
public class NoClipCommand extends SWCommand implements Listener { public class NoClipCommand extends SWCommand implements Listener {
public static final Class<?> gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); public static final Class<?> gameStateChange = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket");
private static final Reflection.FieldAccessor<Float> floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); private static final Reflection.Field<Float> floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0);
private static final Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); private static final Class<?> position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
private static final Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); private static final Class<?> positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
private static final Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); private static final Class<?> useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket");
private static final Class<?> blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); private static final Class<?> blockDig = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket");
private static final Class<?> windowClick = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInWindowClick"); private static final Class<?> windowClick = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundContainerClickPacket");
private static final Class<?> setSlotStack = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInSetCreativeSlot"); private static final Class<?> setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket");
@Getter @Getter
private static final List<Player> NOCLIPS = new ArrayList<>(); private static final List<Player> NOCLIPS = new ArrayList<>();

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
@@ -32,7 +32,7 @@ public class AntiCursorReCentering implements Enable {
@Override @Override
public void enable() { public void enable() {
Class<?> closeWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); Class<?> closeWindow = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundContainerClosePacket");
TinyProtocol.instance.addFilter(closeWindow, (player, object) -> { TinyProtocol.instance.addFilter(closeWindow, (player, object) -> {
if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) {
return object; return object;

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.bausystem.utils.NMSWrapper;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
@@ -29,7 +29,7 @@ import org.bukkit.GameMode;
public class NoCreativeKnockback { public class NoCreativeKnockback {
public NoCreativeKnockback() { public NoCreativeKnockback() {
TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"), (player, o) -> { TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"), (player, o) -> {
if (player.getGameMode() != GameMode.CREATIVE) return o; if (player.getGameMode() != GameMode.CREATIVE) return o;
return NMSWrapper.impl.resetExplosionKnockback(o); return NMSWrapper.impl.resetExplosionKnockback(o);
}); });

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
@@ -48,21 +48,21 @@ import org.bukkit.util.Vector;
@MinVersion(20) @MinVersion(20)
public class SignEditFrom20 implements Listener { public class SignEditFrom20 implements Listener {
private static final Class<?> blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); private static final Class<?> blockPosition = Reflection.getClass("net.minecraft.core.BlockPos");
private static final Class<?> craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); private static final Class<?> craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock");
private static final Class<?> craftWorld = Reflection.getClass("{obc}.CraftWorld"); private static final Class<?> craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld");
private static final Class<?> generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); private static final Class<?> generatorAccess = Reflection.getClass("net.minecraft.world.level.LevelAccessor");
private static final Reflection.MethodInvoker getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition);
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null);
private static final Reflection.MethodInvoker at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition);
private static final Class<?> openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); private static final Class<?> openSign = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket");
private static final Reflection.FieldAccessor<?> blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); private static final Reflection.Field<?> blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0);
private static final Reflection.FieldAccessor<?> sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); private static final Reflection.Field<?> sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0);
private static final Class<?> updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); private static final Class<?> updateSign = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket");
private static final Reflection.FieldAccessor<?> getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); private static final Reflection.Field<?> getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0);
private static final Reflection.FieldAccessor<String[]> stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); private static final Reflection.Field<String[]> stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0);
@EventHandler @EventHandler
public void editSign(PlayerInteractEvent event) { public void editSign(PlayerInteractEvent event) {

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
@@ -40,20 +40,20 @@ import org.bukkit.event.player.PlayerInteractEvent;
@MaxVersion(19) @MaxVersion(19)
public class SignEditUntil19 implements Listener { public class SignEditUntil19 implements Listener {
private static final Class<?> blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); private static final Class<?> blockPosition = Reflection.getClass("net.minecraft.core.BlockPos");
private static final Class<?> craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); private static final Class<?> craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock");
private static final Class<?> craftWorld = Reflection.getClass("{obc}.CraftWorld"); private static final Class<?> craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld");
private static final Class<?> generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); private static final Class<?> generatorAccess = Reflection.getClass("net.minecraft.world.level.LevelAccessor");
private static final Reflection.MethodInvoker getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition);
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null);
private static final Reflection.MethodInvoker at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition);
private static final Class<?> openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); private static final Class<?> openSign = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket");
private static final Reflection.FieldAccessor<?> blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); private static final Reflection.Field<?> blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0);
private static final Class<?> updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); private static final Class<?> updateSign = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket");
private static final Reflection.FieldAccessor<?> getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); private static final Reflection.Field<?> getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0);
private static final Reflection.FieldAccessor<String[]> stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); private static final Reflection.Field<String[]> stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0);
@EventHandler @EventHandler
public void editSign(PlayerInteractEvent event) { public void editSign(PlayerInteractEvent event) {

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.xray; package de.steamwar.bausystem.features.xray;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.techhider.TechHiderCommand; import de.steamwar.bausystem.features.techhider.TechHiderCommand;
@@ -108,8 +108,8 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
}); });
} }
private static final Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); private static final Class<?> position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
private static final Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); private static final Class<?> positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
{ {
BiFunction<Player, Object, Object> positionSetter = (player, o) -> { BiFunction<Player, Object, Object> positionSetter = (player, o) -> {

View File

@@ -21,41 +21,40 @@ package de.steamwar.bausystem.region.flags;
import de.steamwar.bausystem.region.flags.flagvalues.*; import de.steamwar.bausystem.region.flags.flagvalues.*;
import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.bausystem.shared.EnumDisplay;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Getter @Getter
@AllArgsConstructor
public enum Flag implements EnumDisplay { public enum Flag implements EnumDisplay {
COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW), COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW, false),
TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB), TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB, true),
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW), FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, true),
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE), FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, true),
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE), PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, true),
ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE), ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE, true),
NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE), NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE, true),
; ;
@Getter @Getter
private static final Set<Flag> flags; private static final Set<Flag> flags;
@Getter
private static final Set<Flag> resetFlags;
static { static {
flags = EnumSet.allOf(Flag.class); flags = EnumSet.allOf(Flag.class);
resetFlags = flags.stream().filter(flag -> flag.reset).collect(Collectors.toUnmodifiableSet());
} }
private final String chatValue; private final String chatValue;
private final Class<? extends Value<?>> valueType; private final Class<? extends Value<?>> valueType;
private final Flag.Value<?> defaultValue; private final Flag.Value<?> defaultValue;
private final Value<?>[] values; private final boolean reset;
<T extends Enum<T> & Value<T>> Flag(String chatValue, final Class<? extends Value<T>> valueType, final Flag.Value<T> defaultValue) {
this.chatValue = chatValue;
this.valueType = valueType;
this.defaultValue = defaultValue;
this.values = defaultValue.getValues();
}
public Value<?> getFlagValueOf(final String name) { public Value<?> getFlagValueOf(final String name) {
return this.defaultValue.getValueOf(name); return this.defaultValue.getValueOf(name);

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
@@ -81,12 +81,12 @@ public class PlaceItemUtils {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
private static final Class<?> blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); private static final Class<?> blockPosition = Reflection.getClass("net.minecraft.core.BlockPos");
private static final Reflection.ConstructorInvoker blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); private static final Reflection.Constructor blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class);
private static final Class<?> craftBlock = Reflection.getClass("{obc}.block.CraftBlockState"); private static final Class<?> craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlockState");
private static final Class<?> craftWorld = Reflection.getClass("{obc}.CraftWorld"); private static final Class<?> craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld");
private static final Reflection.FieldAccessor<?> positionAccessor = Reflection.getField(craftBlock, blockPosition, 0); private static final Reflection.Field<?> positionAccessor = Reflection.getField(craftBlock, blockPosition, 0);
private static final Reflection.FieldAccessor<?> worldAccessor = Reflection.getField(craftBlock, craftWorld, 0); private static final Reflection.Field<?> worldAccessor = Reflection.getField(craftBlock, craftWorld, 0);
/** /**
* Attempt to place an {@link ItemStack} the {@link Player} is holding against a {@link Block} inside the World. * Attempt to place an {@link ItemStack} the {@link Player} is holding against a {@link Block} inside the World.

View File

@@ -19,17 +19,16 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.core.BountifulWrapper; import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.Core;
import de.steamwar.core.VersionDependent; import de.steamwar.core.VersionDependent;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public interface PlayerMovementWrapper { public interface PlayerMovementWrapper {
Class<?> teleportPacket = REntity.teleportPacket; Class<?> teleportPacket = REntity.teleportPacket;
Reflection.FieldAccessor<Integer> teleportEntity = REntity.teleportEntity; Reflection.Field<Integer> teleportEntity = REntity.teleportEntity;
BountifulWrapper.PositionSetter teleportPosition = REntity.teleportPosition; BountifulWrapper.PositionSetter teleportPosition = REntity.teleportPosition;
PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance());

View File

@@ -1,49 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.utils;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@Linked
public class VersionAnnouncer implements Listener {
private final String versionString = Bukkit.getBukkitVersion().split("-", 2)[0];
@SuppressWarnings("unchecked")
private final ViaAPI<Player> via = Via.getAPI();
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if(via.getServerVersion().supportedVersions().contains(via.getPlayerVersion(player)))
return;
BauSystem.MESSAGE.sendPrefixless("SERVER_VERSION", player, ChatMessageType.ACTION_BAR, versionString);
}
}

View File

@@ -19,7 +19,7 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.Reflection;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@@ -100,7 +100,7 @@ public class WorldEditUtils {
.getSessionManager() .getSessionManager()
.get(BukkitAdapter.adapt(player)); .get(BukkitAdapter.adapt(player));
Reflection.ConstructorInvoker constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class); Reflection.Constructor constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class);
RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld())); RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld()));
localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector); localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector);

View File

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

View File

@@ -1,27 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
steamwar.java
}
dependencies {
testImplementation(libs.junit)
testImplementation(libs.hamcrest)
}

View File

@@ -1,27 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
steamwar.java
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

View File

@@ -1,216 +0,0 @@
/*
* 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), (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), (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) {
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) {
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(dataMethodAnnotationTriple.c, 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;
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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;
}
}

View File

@@ -1,25 +0,0 @@
/*
* 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);
}

View File

@@ -1,62 +0,0 @@
/*
* 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);
}
}
}

View File

@@ -1,93 +0,0 @@
/*
* 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.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Stream;
public class CommandFrameworkException extends RuntimeException {
private Function causeMessage;
private Throwable cause;
private Function stackTraceExtractor;
private String extraStackTraces;
private String message;
public CommandFrameworkException(InvocationTargetException invocationTargetException, String alias, String[] args) {
this(e -> {
StringBuilder st = new StringBuilder();
st.append(e.getCause().getClass().getTypeName());
if (e.getCause().getMessage() != null) {
st.append(": ").append(e.getCause().getMessage());
}
if (alias != null && !alias.isEmpty()) {
st.append("\n").append("Performed command: " + alias + " " + String.join(" ", args));
}
return st.toString();
}, invocationTargetException, e -> {
StackTraceElement[] stackTraceElements = e.getCause().getStackTrace();
return Arrays.stream(stackTraceElements).limit(stackTraceElements.length - e.getStackTrace().length);
}, null);
}
private <T extends Throwable> CommandFrameworkException(Function<T, String> causeMessage, T cause, Function<T, Stream<StackTraceElement>> stackTraceExtractor, String extraStackTraces) {
super(causeMessage.apply(cause), cause);
this.causeMessage = causeMessage;
this.cause = cause;
this.stackTraceExtractor = stackTraceExtractor;
this.extraStackTraces = extraStackTraces;
}
public synchronized String getBuildStackTrace() {
if (message != null) {
return message;
}
StringBuilder st = new StringBuilder();
st.append(causeMessage.apply(cause)).append("\n");
((Stream<StackTraceElement>) stackTraceExtractor.apply(cause)).forEach(stackTraceElement -> {
st.append("\tat ").append(stackTraceElement.toString()).append("\n");
});
if (extraStackTraces != null) {
st.append("\tat ").append(extraStackTraces).append("\n");
}
message = st.toString();
return message;
}
@Override
public void printStackTrace() {
printStackTrace(System.err);
}
@Override
public void printStackTrace(PrintStream s) {
s.print(getBuildStackTrace());
}
@Override
public void printStackTrace(PrintWriter s) {
s.print(getBuildStackTrace());
}
}

View File

@@ -1,26 +0,0 @@
/*
* 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 CommandLoader<T> {
AbstractCommand<T> get();
void add(Object command);
}

View File

@@ -1,148 +0,0 @@
/*
* 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.mapper.BooleanMapper;
import de.steamwar.command.mapper.NumberMapper;
import lombok.experimental.UtilityClass;
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.*;
import java.util.function.ToIntFunction;
@UtilityClass
public class CommandUtils {
final Map<String, AbstractTypeMapper<?, ?>> MAPPER_FUNCTIONS = new HashMap<>();
final Map<String, AbstractTypeValidator<?, ?>> VALIDATOR_FUNCTIONS = new HashMap<>();
final Map<String, AbstractTypeSupplier<?, ?>> SUPPLIER_FUNCTIONS = new HashMap<>();
static final AbstractTypeMapper<Object, String> STRING_MAPPER = new AbstractTypeMapper<>() {
@Override
public String map(Object sender, PreviousArguments previousArguments, String s) {
return s;
}
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
return Collections.singletonList(s);
}
};
static {
addMapper(boolean.class, Boolean.class, new BooleanMapper());
addMapper(int.class, Integer.class, new NumberMapper(Integer::parseInt, false));
addMapper(long.class, Long.class, new NumberMapper(Long::parseLong, false));
addMapper(float.class, Float.class, new NumberMapper(Float::parseFloat, true));
addMapper(double.class, Double.class, new NumberMapper(Double::parseDouble, true));
MAPPER_FUNCTIONS.put(String.class.getTypeName(), STRING_MAPPER);
}
private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, AbstractTypeMapper<?, ?> mapper) {
MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper);
MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper);
}
public static <K, T> void addMapper(Class<T> clazz, AbstractTypeMapper<K, T> mapper) {
addMapper(clazz.getTypeName(), mapper);
}
public static <T> void addMapper(String name, AbstractTypeMapper<T, ?> mapper) {
MAPPER_FUNCTIONS.putIfAbsent(name, mapper);
}
public static <T> void addValidator(Class<T> clazz, AbstractTypeValidator<T, ?> validator) {
addValidator(clazz.getTypeName(), validator);
}
public static <T> void addValidator(String name, AbstractTypeValidator<T, ?> validator) {
VALIDATOR_FUNCTIONS.putIfAbsent(name, validator);
}
public static <T> void addSupplier(Class<T> clazz, AbstractTypeSupplier<T, ?> supplier) {
addSupplier(clazz.getTypeName(), supplier);
}
public static <T> void addSupplier(String name, AbstractTypeSupplier<T, ?> supplier) {
SUPPLIER_FUNCTIONS.putIfAbsent(name, supplier);
}
public static List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
List<Annotation> annotationList = new ArrayList<>();
for (Annotation annotation : annotatedElement.getAnnotations()) {
try {
Method method = annotation.annotationType().getMethod("value");
Class<?> returnType = method.getReturnType();
if (!returnType.isArray()) {
annotationList.add(annotation);
continue;
}
Class<?> innerReturnType = returnType.getComponentType();
if (!(innerReturnType.isAnnotation() && innerReturnType.isAnnotationPresent(Repeatable.class))) {
annotationList.add(annotation);
continue;
}
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 {
Annotation[] innerAnnotations = (Annotation[]) method.invoke(annotation);
Collections.addAll(annotationList, innerAnnotations);
} catch (Exception e) {
annotationList.add(annotation);
}
} catch (NoSuchMethodException e) {
annotationList.add(annotation);
}
}
annotationList.removeIf(anno -> !anno.annotationType().isAnnotationPresent(Handler.Implementation.class));
return annotationList;
}
public static <T extends Handler> List<Annotation> getAnnotations(AnnotatedElement annotatedElement, Class<T> type) {
List<Annotation> annotations = getAnnotations(annotatedElement);
annotations.removeIf(annotation -> {
Handler.Implementation implementation = annotation.annotationType().getAnnotation(Handler.Implementation.class);
return implementation == null || !type.isAssignableFrom(implementation.value());
});
return annotations;
}
public static ToIntFunction<Number> createComparator(String type, Class<?> clazz, int iValue, long lValue, float fValue, double dValue) {
if (clazz == int.class || clazz == Integer.class) {
return number -> Integer.compare(number.intValue(), iValue);
} else if (clazz == long.class || clazz == Long.class) {
return number -> Long.compare(number.longValue(), lValue);
} else if (clazz == float.class || clazz == Float.class) {
return number -> Float.compare(number.floatValue(), fValue);
} else if (clazz == double.class || clazz == Double.class) {
return number -> Double.compare(number.doubleValue(), dValue);
} else {
throw new IllegalArgumentException(type + " annotation is not supported for " + clazz);
}
}
}

View File

@@ -1,186 +0,0 @@
/*
* 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;
import de.steamwar.command.annotations.Supplier;
import de.steamwar.command.graph.*;
import de.steamwar.command.handler.GreedyHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
class DataImpl implements Handler.DataCheckable, Handler.DataReadable, Handler.DataWritable {
private final AbstractCommand<?> container;
private final Object self;
private final RootNode<?> node;
private final Map<Class<?>, Function<?, ?>> executorMapper;
private final Map<String, AbstractTypeMapper<?, ?>> mapper;
private final Map<String, AbstractTypeMapper<?, ?>> globalMapper;
private final Map<String, AbstractTypeValidator<?, ?>> validator;
private final Map<String, AbstractTypeValidator<?, ?>> globalValidator;
private final Map<String, AbstractTypeSupplier<?, ?>> supplier;
private final Map<String, AbstractTypeSupplier<?, ?>> globalSupplier;
private final Map<Method, Object> cache = new HashMap<>();
DataImpl(AbstractCommand<?> container, Object self, RootNode<?> node, Map<Class<?>, Function<?, ?>> executorMapper, Map<String, AbstractTypeMapper<?, ?>> mapper, Map<String, AbstractTypeMapper<?, ?>> globalMapper, Map<String, AbstractTypeValidator<?, ?>> validator, Map<String, AbstractTypeValidator<?, ?>> globalValidator, Map<String, AbstractTypeSupplier<?, ?>> supplier, Map<String, AbstractTypeSupplier<?, ?>> globalSupplier) {
this.container = container;
this.self = self;
this.node = node;
this.executorMapper = executorMapper;
this.mapper = mapper;
this.globalMapper = globalMapper;
this.validator = validator;
this.globalValidator = globalValidator;
this.supplier = supplier;
this.globalSupplier = globalSupplier;
}
@Override
public boolean hasExecutorMapper(Class<?> clazz) {
return getExecutorMapper(clazz) != null;
}
@Override
public Function<?, ?> getExecutorMapper(Class<?> clazz) {
for (Map.Entry<Class<?>, Function<?, ?>> entry : executorMapper.entrySet()) {
if (entry.getKey().isAssignableFrom(clazz)) {
return entry.getValue();
}
}
return null;
}
@Override
public boolean hasMapper(String key) {
return mapper.containsKey(key) || globalMapper.containsKey(key);
}
@Override
public <A, B> AbstractTypeMapper<A, B> getMapper(String key) {
return (AbstractTypeMapper<A, B>) mapper.getOrDefault(key, globalMapper.get(key));
}
@Override
public <A, B> void addMapper(String key, boolean local, AbstractTypeMapper<A, B> mapper) {
if (local) {
this.mapper.put(key, mapper);
} else {
this.globalMapper.putIfAbsent(key, mapper);
}
}
@Override
public boolean hasValidator(String key) {
return validator.containsKey(key) || globalValidator.containsKey(key);
}
@Override
public <A, B> AbstractTypeValidator<A, B> getValidator(String key) {
return (AbstractTypeValidator<A, B>) validator.getOrDefault(key, globalValidator.get(key));
}
@Override
public <A, B> void addValidator(String key, boolean local, AbstractTypeValidator<A, B> validator) {
if (local) {
this.validator.put(key, validator);
} else {
this.globalValidator.putIfAbsent(key, validator);
}
}
@Override
public boolean hasSupplier(String key) {
return supplier.containsKey(key) || globalSupplier.containsKey(key);
}
@Override
public <A, B> AbstractTypeSupplier<A, B> getSupplier(String key) {
return (AbstractTypeSupplier<A, B>) supplier.getOrDefault(key, globalSupplier.get(key));
}
@Override
public <A, B> void addSupplier(String key, boolean local, AbstractTypeSupplier<A, B> supplier) {
if (local) {
this.supplier.put(key, supplier);
} else {
this.globalSupplier.putIfAbsent(key, supplier);
}
}
/**
* Invoking the same method twice will result in the exact same result.
*/
@Override
public <T> T invoke(Method method) {
return (T) cache.computeIfAbsent(method, m -> {
try {
return m.invoke(self);
} catch (IllegalAccessException | InvocationTargetException e) {
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
@Override
public void addCommand(Method method, String[] subCommand, String[] description, boolean noTabComplete) {
Node<?> temp = node;
container.descriptions.addAll(Arrays.asList(description));
if (noTabComplete) {
temp = temp.addChild(null, new NoTabCompleteNode<>());
}
for (int i = 0; i < subCommand.length; i++) {
temp = temp.addChild(null, new LiteralNode<>(subCommand[i]));
}
Parameter[] parameters = method.getParameters();
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
if (i == 0) {
temp = temp.addChild(parameter, new ExecutorTypeNode<>(parameter, i, this));
continue;
}
if (parameter.isAnnotationPresent(Supplier.class)) {
temp = temp.addChild(parameter, new SupplierNode<>(parameter, this));
continue;
}
Class<?> type = parameter.getType();
boolean isArray = parameter.isVarArgs() || type.isArray();
if (!isArray) {
temp = temp.addChild(parameter, new TypeNode<>(parameter, i, this));
continue;
}
boolean greedy = parameter.isVarArgs() || GreedyHandler.isGreedy(parameter);
if (greedy) {
temp = temp.addChild(parameter, new GreedyArrayNode<>(parameter, i, this));
} else {
temp = temp.addChild(parameter, new NonGreedyArrayNode<>(parameter, i, this));
}
}
temp.addChild(null, new ExecuteNode<>(self, method));
}
}

View File

@@ -1,121 +0,0 @@
/*
* 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;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
public interface Handler {
default Optional<Class<?>> getGenericTypeOfReturn(Method method) {
Type type;
try {
type = method.getGenericReturnType();
} catch (Exception e) {
return Optional.empty();
}
if (!(type instanceof ParameterizedType)) {
return Optional.empty();
}
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] generics = parameterizedType.getActualTypeArguments();
if (generics.length != 1 && generics.length != 2) {
return Optional.empty();
}
Type genericType = generics[generics.length - 1];
try {
return Optional.of(Class.forName(genericType.getTypeName()));
} catch (Exception e) {
return Optional.empty();
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
@interface Implementation {
Class<? extends Handler> value();
}
interface DataCheckable {
boolean hasExecutorMapper(Class<?> clazz);
boolean hasMapper(String key);
boolean hasValidator(String key);
boolean hasSupplier(String key);
}
interface DataReadable {
Function<?, ?> getExecutorMapper(Class<?> clazz);
<A, B> AbstractTypeMapper<A, B> getMapper(String key);
<A, B> AbstractTypeValidator<A, B> getValidator(String key);
<A, B> AbstractTypeSupplier<A, B> getSupplier(String key);
}
interface DataWritable {
Function<?, ?> getExecutorMapper(Class<?> clazz);
<A, B> void addMapper(String key, boolean local, AbstractTypeMapper<A, B> mapper);
<A, B> void addValidator(String key, boolean local, AbstractTypeValidator<A, B> validator);
<A, B> void addSupplier(String key, boolean local, AbstractTypeSupplier<A, B> supplier);
/**
* Invoking the same method twice will result in the exact same result.
*/
<T> T invoke(Method method);
void addCommand(Method method, String[] subCommand, String[] description, boolean noTabComplete);
}
interface HandlerMethod<T extends Annotation> extends Handler {
void check(T annotation, Method method, DataCheckable dataCheckable) throws Exception;
int getRunPriority();
void run(T annotation, Method method, DataWritable dataWritable);
}
interface HandlerParameter<T extends Annotation, A, B> extends Handler {
void check(T annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception;
default boolean needsParentTypeMapper() {
return false;
}
/**
* Null values are allowed to be returned.
*/
default AbstractTypeMapper<A, B> getTypeMapper(T annotation, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<A, B> parentTypeMapper) {
return null;
}
default int getValidatorPriority() {
return 0;
}
/**
* Null values are allowed to be returned.
*/
default AbstractTypeValidator<A, B> getValidator(T annotation, Parameter parameter, int index, DataReadable dataReadable) {
return null;
}
}
}

View File

@@ -1,30 +0,0 @@
/*
* 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;
import java.util.Arrays;
import java.util.List;
public interface OptionEnum<T extends Enum<T> & OptionEnum<T>> {
default List<String> getTabCompletes() {
return Arrays.asList("-" + ((T) this).name().toLowerCase());
}
T[] getRemoved();
}

View File

@@ -1,96 +0,0 @@
/*
* 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 lombok.NonNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
public class PreviousArguments {
public final String[] userArgs;
public final Object[] mappedArgs;
public final boolean hasMoreArguments;
private final Function<String, Object> getByNameFunction;
private boolean usedOptionalValue = false;
public PreviousArguments(String[] userArgs, Object[] mappedArgs, boolean hasMoreArguments, Function<String, Object> getByNameFunction) {
this.userArgs = userArgs;
this.mappedArgs = mappedArgs;
this.hasMoreArguments = hasMoreArguments;
this.getByNameFunction = getByNameFunction;
}
public boolean hasUsedOptionalValue() {
return usedOptionalValue;
}
public void usedOptionalValue() {
this.usedOptionalValue = true;
}
public String getUserArg(int index) {
return userArgs[userArgs.length - index - 1];
}
public <T> T getMappedArg(int index) {
return (T) mappedArgs[mappedArgs.length - index - 1];
}
public <T> Optional<T> getFirst(Class<T> clazz) {
for (Object o : mappedArgs) {
if (clazz.isInstance(o)) {
return Optional.of((T) o);
}
}
return Optional.empty();
}
public <T> List<T> getAll(Class<T> clazz) {
List<T> list = new ArrayList<>();
for (Object o : mappedArgs) {
if (clazz.isInstance(o)) {
list.add((T) o);
}
if (o == null) {
continue;
}
if (o.getClass().isArray()) {
Object[] array = (Object[]) o;
if (array.length == 0) {
continue;
}
for (Object o1 : array) {
if (clazz.isInstance(o1)) {
list.add((T) o1);
}
}
}
}
return list;
}
public <T> T getByName(@NonNull String name) {
return (T) getByNameFunction.apply(name);
}
}

View File

@@ -1,109 +0,0 @@
/*
* 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.mapper.internal.DelegatingMapper;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.experimental.UtilityClass;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@UtilityClass
public class TabCompletionCache {
private final Map<Key, TabCompletions> tabCompletionCache = new ConcurrentHashMap<>();
Set<AbstractTypeMapper<?, ?>> cached = new HashSet<>();
Set<AbstractTypeMapper<?, ?>> global = new HashSet<>();
Map<AbstractTypeMapper<?, ?>, Long> cacheDuration = new HashMap<>();
static {
Thread thread = new Thread(() -> {
while (true) {
Set<Key> toRemove = new HashSet<>();
for (Map.Entry<Key, TabCompletions> tabCompletionsEntry : tabCompletionCache.entrySet()) {
if (System.currentTimeMillis() - tabCompletionsEntry.getValue().timestamp > cacheDuration.get(tabCompletionsEntry.getKey().typeMapper)) {
toRemove.add(tabCompletionsEntry.getKey());
}
}
for (Key key : toRemove) {
tabCompletionCache.remove(key);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
thread.setName("TabCompletionCache Invalidator");
thread.setDaemon(true);
thread.start();
}
public void add(AbstractTypeMapper<?, ?> typeMapper, boolean global, long cacheDuration, TimeUnit timeUnit) {
TabCompletionCache.cached.add(typeMapper);
if (global) TabCompletionCache.global.add(typeMapper);
TabCompletionCache.cacheDuration.put(typeMapper, timeUnit.toMillis(cacheDuration));
}
public <A, B> AbstractTypeMapper<A, B> cached(AbstractTypeMapper<A, B> dataMapper, AbstractTypeMapper<A, B> toBeCached) {
if (!cached.contains(dataMapper)) return toBeCached;
boolean global = TabCompletionCache.global.contains(dataMapper);
long cacheDuration = TabCompletionCache.cacheDuration.get(dataMapper);
return new DelegatingMapper<>(toBeCached, null) {
@Override
public Collection<String> tabComplete(A sender, PreviousArguments previousArguments, String s) {
String normalizedArg = dataMapper.normalize(global ? null : sender, s);
if (normalizedArg == null) normalizedArg = "";
Key key = new Key(global ? null : sender, normalizedArg, dataMapper);
TabCompletions tabCompletions = tabCompletionCache.computeIfAbsent(key, ignore -> {
return new TabCompletions(System.currentTimeMillis(), toBeCached.tabComplete(sender, previousArguments, s));
});
if (System.currentTimeMillis() - tabCompletions.timestamp > cacheDuration) {
tabCompletions.tabCompletions = toBeCached.tabComplete(sender, previousArguments, s);
}
tabCompletions.timestamp = System.currentTimeMillis();
return tabCompletions.tabCompletions;
}
};
}
@EqualsAndHashCode
@AllArgsConstructor
private static class Key {
private Object sender;
private String arg;
private AbstractTypeMapper<?, ?> typeMapper;
}
@AllArgsConstructor
private static class TabCompletions {
private long timestamp;
private Collection<String> tabCompletions;
}
}

View File

@@ -1,37 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.AllowNullHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to allow null values passed to the command.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(AllowNullHandler.Impl.class)
public @interface AllowNull {
}

View File

@@ -1,53 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.ArrayLengthHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define a minimum and maximum length the supplied array can have.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(ArrayLengthHandler.Impl.class)
public @interface ArrayLength {
/**
* Inclusive
*/
int min() default 0;
/**
* Inclusive
*/
int max() default Integer.MAX_VALUE;
/**
* Error message if too few Elements got parsed. There are 2 arguments provided to the message.
* The first is the number of elements that got parsed as a number and the second one is how many
* should have been parsed, so the min number of elements expected.
*/
String error() default "";
}

View File

@@ -1,52 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.CachedHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;
/**
* This annotation is used to register a or {@link Mapper}
* on registration as being cached. Only TabCompletions are cached for the duration
* denoted by {@link #timeUnit()} and {@link #cacheDuration()} using
* {@link TimeUnit#toMillis(long)}. If {@link #global()} is {@code true}, the
* cache will not be created per player but for everyone. This is useful for
* commands that are not player specific.
* <br><br>
* To calculate the cache key for a {@link AbstractTypeMapper} the
* {@link AbstractTypeMapper#normalize(Object, String)} method is called.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Handler.Implementation(CachedHandler.Impl.class)
public @interface Cached {
long cacheDuration() default 5;
TimeUnit timeUnit() default TimeUnit.SECONDS;
boolean global() default false;
}

View File

@@ -1,56 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.ClassMapperHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation for registering a method as a class mapper.
* The annotated method will be executed while {@link #initialize()}
* is evaluated. The result of this method will be cached under the
* name {@link ClassMapper#value()} converted to a {@link String} using
* {@link Class#getTypeName()}. {@link AbstractTypeMapper} will be used
* as the default mapper if the type this mapper is registered for is
* found as a parameter of any command method annotated with {@link Register}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Handler.Implementation(ClassMapperHandler.Impl.class)
@Deprecated
@DeprecationInfo("Use @Mapper instead")
public @interface ClassMapper {
/**
* The type this mapper is registered for.
*/
Class<?> value();
/**
* If {@code true}, the mapper will only be used in the current command class.
*/
boolean local() default true;
}

View File

@@ -1,53 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.ClassValidatorHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation for registering a method as a class validator.
* The annotated method will be executed while {@link #initialize()}
* is evaluated. The result of this method will be cached under the
* name {@link ClassValidator#value()} converted to a {@link String} using
* {@link Class#getTypeName()}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Handler.Implementation(ClassValidatorHandler.Impl.class)
@Deprecated
@DeprecationInfo("Use @Validator instead")
public @interface ClassValidator {
/**
* The type this validator is registered for.
*/
Class<?> value();
/**
* If {@code true}, the validator will only be used in the current command class.
*/
boolean local() default true;
}

View File

@@ -1,28 +0,0 @@
/*
* 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.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface DeprecationInfo {
String value();
}

View File

@@ -1,38 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.EndsWithHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(EndsWithHandler.Impl.class)
public @interface EndsWith {
String value();
String error() default "";
}

View File

@@ -1,48 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.ErrorMessageHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define an error message for a parameter.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(ErrorMessageHandler.Impl.class)
public @interface ErrorMessage {
/**
* Error message to be displayed when the parameter is invalid.
*/
String value();
/**
* This is the short form for 'allowEmptyArrays'.
*/
@Deprecated
@DeprecationInfo("Use @ArrayLength instead of this flag")
boolean allowEAs() default true;
}

View File

@@ -1,46 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.GreedyHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation can have a huge performance impact. Both positive and negative.
* You can design your command to be more flexible and allow performance improvements if used correctly.
* <br><br>
* The more restrictive the underlying array type is, the more performance can be gained.
* <br><br>
* Using this annotation on the varargs parameter of a command will not have any effect, since they are already treated as greedy arrays.
* <br><br>
* The {@link #backTrackingDepth()} can be used to limit the amount of backtracking that is done. This can be used to improve performance.
* For varargs parameters, this value is defaulted to 0, since they are at the end of the parameter list.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(GreedyHandler.Impl.class)
public @interface Greedy {
int backTrackingDepth() default Integer.MAX_VALUE;
}

View File

@@ -1,46 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.LengthHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define a minimum and maximum length the supplied string can have.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(LengthHandler.Impl.class)
public @interface Length {
/**
* Inclusive
*/
int min() default 0;
/**
* Inclusive
*/
int max() default Integer.MAX_VALUE;
}

View File

@@ -1,58 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.MapperHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation for registering a method as a mapper. The annotated method will
* be executed while {@link #initialize()} is evaluated. The result of this
* method will be cached under either {@link Mapper#value()} or {@link Mapper#value()}.
* If {@link Mapper#type()} is used any parameter using that type will be using
* this {@link AbstractTypeMapper} implicitly. While using this annotation on
* a method it can be possible to not supply any type. On a parameter you can
* only use this annotation using the {@link Mapper#value()} value.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Handler.Implementation(MapperHandler.Impl.class)
public @interface Mapper {
/**
* The name this mapper is registered for.
*/
String value() default "";
/**
* The type this mapper is registered for.
*/
Class<?> type() default void.class;
/**
* If {@code true}, the mapper will only be used in the current command class.
*/
boolean local() default true;
}

View File

@@ -1,70 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.MaxHandler;
import de.steamwar.command.handler.MaxReferenceHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define a maximum number value for a parameter.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(MaxHandler.Impl.class)
public @interface Max {
int intValue() default Integer.MAX_VALUE;
long longValue() default Long.MAX_VALUE;
float floatValue() default Float.MAX_VALUE;
double doubleValue() default Double.MAX_VALUE;
boolean inclusive() default true;
/**
* Error message to be displayed when the argument supplied is bigger than this allows.
* Two arguments are supplied to the error message. The first is the number that got parsed
* and the second is the max this annotation allows.
*/
String error() default "";
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(MaxReferenceHandler.Impl.class)
@interface Reference {
String value();
boolean inclusive() default true;
/**
* Error message to be displayed when the argument supplied is smaller than this allows.
* Two arguments are supplied to the error message. The first is the number that got parsed
* and the second is the min this annotation allows.
*/
String error() default "";
}
}

View File

@@ -1,70 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.MinHandler;
import de.steamwar.command.handler.MinReferenceHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define a minimum number value for a parameter.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(MinHandler.Impl.class)
public @interface Min {
int intValue() default Integer.MIN_VALUE;
long longValue() default Long.MIN_VALUE;
float floatValue() default Float.MIN_VALUE;
double doubleValue() default Double.MIN_VALUE;
boolean inclusive() default true;
/**
* Error message to be displayed when the argument supplied is smaller than this allows.
* Two arguments are supplied to the error message. The first is the number that got parsed
* and the second is the min this annotation allows.
*/
String error() default "";
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(MinReferenceHandler.Impl.class)
@interface Reference {
String value();
boolean inclusive() default true;
/**
* Error message to be displayed when the argument supplied is smaller than this allows.
* Two arguments are supplied to the error message. The first is the number that got parsed
* and the second is the min this annotation allows.
*/
String error() default "";
}
}

View File

@@ -1,31 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface Name {
String value();
}

View File

@@ -1,46 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.OptionalValueHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define a default value for a parameter.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(OptionalValueHandler.Impl.class)
public @interface OptionalValue {
/**
* Will pe parsed against the TypeMapper specified by the parameter or annotation.
*/
String value();
/**
* The method name stands for 'onlyUseIfNoneIsGiven'.
*/
boolean onlyUINIG() default false;
}

View File

@@ -1,38 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.RegexHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(RegexHandler.Impl.class)
public @interface Regex {
String value();
String error() default "";
}

View File

@@ -1,57 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.RegisterHandler;
import java.lang.annotation.*;
/**
* Annotation for registering a method as a command.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Repeatable(Register.Registers.class)
@Handler.Implementation(RegisterHandler.Impl.class)
public @interface Register {
/**
* Identifier of subcommand.
*/
String[] value() default {};
/**
* Description of subcommand.
*/
String[] description() default {};
/**
* If {@code true}, the command will not be tab completed.
*/
boolean noTabComplete() default false;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Handler.Implementation(RegisterHandler.Impl.class)
@interface Registers {
Register[] value();
}
}

View File

@@ -1,38 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.StartsWithHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(StartsWithHandler.Impl.class)
public @interface StartsWith {
String value();
String error() default "";
}

View File

@@ -1,58 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.StaticValueHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define static values for a parameter like an enum just without the enum.
* You can use this annotation on a parameter of type {@link String} or {@link int}, {@link long} and
* {@link boolean}. While using an int, the value will represent the index into the value array. While
* using a boolean, the {@link #falseValues()} defines which indices are considered {@code false} or
* {@code true}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(StaticValueHandler.Impl.class)
@Deprecated
@DeprecationInfo("Use @Values instead")
public @interface StaticValue {
String[] value();
/**
* This is the short form for 'allowImplicitSwitchExpressions'
* and can be set to true if you want to allow int as well as boolean as annotated parameter types.
* The value array needs to be at least 2 long for this flag to be considered.
* While using an int, the value will represent the index into the value array.
* While using a boolean, the {@link #falseValues()} defines which indices are
* considered {@code false} or {@code true}.
*/
@Deprecated
@DeprecationInfo("Dont need to set this to true")
boolean allowISE() default false;
int[] falseValues() default {0};
}

View File

@@ -1,48 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.SupplierHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Handler.Implementation(SupplierHandler.Impl.class)
public @interface Supplier {
/**
* The name this supplier is registered for.
*/
String value() default "";
/**
* The type this supplier is registered for.
*/
Class<?> type() default void.class;
/**
* If {@code true}, the supplier will only be used in the current command class.
*/
boolean local() default true;
}

View File

@@ -1,40 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.TabFilterHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation defines per Parameter how the TabCompletions should be filtered and displayed by the client.
* There are 3 modes further described by {@link TabFilterType}. If this annotation is not present the default
* {@link TabFilterType#STARTS_WITH} is used.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(TabFilterHandler.Impl.class)
public @interface TabFilter {
TabFilterType value();
}

View File

@@ -1,41 +0,0 @@
/*
* 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.annotations;
public enum TabFilterType {
/**
* This value defines that, the starts with tab-completion filter is used.<br>
* see: {@link de.steamwar.command.mapper.internal.StartsWithFilter} for more.
*/
STARTS_WITH,
/**
* This value defines that, the contains tab-completions filter is used.
* see: {@link de.steamwar.command.mapper.internal.ContainsFilter} for more.
*/
CONTAINS,
/**
* This value disables any tab-completion filters and just returns anything you
* specified inside the TypeMapper.
*/
NONE
}

View File

@@ -1,37 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.UniqueHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define an array with unique values.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(UniqueHandler.Impl.class)
public @interface Unique {
}

View File

@@ -1,68 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.ValidatorHandler;
import java.lang.annotation.*;
/**
* Annotation for registering a method as a validator.
* The annotated method will be executed while {@link #initialize()}
* is evaluated. The result of this method will be cached under the
* name {@link ClassValidator#value()} converted to a {@link String} using
* {@link Class#getTypeName()}.
* This annotation can also be used on parameters to apply a validator to them.
* You can leave the {@link #value()} empty here to use the type of the parameter.
* For registering you should never leave {@link #value()} empty.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Handler.Implementation(ValidatorHandler.Impl.class)
@Repeatable(Validator.Validators.class)
public @interface Validator {
/**
* The name this validator is registered for.
*/
String value() default "";
/**
* The type this validator is registered for.
*/
Class<?> type() default void.class;
/**
* If {@code true}, the validator will only be used in the current command class.
*/
boolean local() default true;
/**
* If {@code true}, the validator will be inverted for parameter usage.
*/
boolean invert() default false;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(ValidatorHandler.Impl.class)
@interface Validators {
Validator[] value();
}
}

View File

@@ -1,52 +0,0 @@
/*
* 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.annotations;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.ValuesHandler;
import de.steamwar.command.handler.ValuesReferenceHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to define static values for a parameter like an enum just without the enum.
* You can use this annotation on a parameter of type {@link String} or {@link int}, {@link long} and
* {@link boolean}. While using an int, the value will represent the index into the value array. While
* using a boolean, the {@link #falseValues()} defines which indices are considered {@code false} or
* {@code true}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(ValuesHandler.Impl.class)
public @interface Values {
String[] value();
int[] falseValues() default {0};
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@Handler.Implementation(ValuesReferenceHandler.Impl.class)
@interface Reference {
String value();
}
}

View File

@@ -1,110 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.Handler;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.handler.ArrayLengthHandler;
import de.steamwar.command.handler.UniqueHandler;
import de.steamwar.command.utils.Triple;
import java.lang.reflect.Array;
import java.lang.reflect.Parameter;
import java.util.*;
public abstract class AbstractArrayNode<E> extends AbstractTypeNode<E> {
protected final boolean unique;
protected final int minArrayLength;
protected final int maxArrayLength;
protected final String error;
protected AbstractArrayNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter, index, dataReadable);
this.unique = UniqueHandler.isPresent(parameter);
this.minArrayLength = ArrayLengthHandler.getMin(parameter);
this.maxArrayLength = ArrayLengthHandler.getMax(parameter);
this.error = ArrayLengthHandler.getError(parameter);
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
Object array = Array.newInstance(type, Math.min(nodeData.unparsedArgumentsSize(), maxArrayLength));
int i = 0;
while (!nodeData.hasOneLeft()) {
if (i >= minArrayLength) {
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
}
nodeData.add(name, arrayCopy(array, i));
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
nodeData.remove();
if (!argument.b) {
for (; i > 0; i--) nodeData.unconsume();
return;
}
nodeData.consume();
Array.set(array, i, argument.a);
i++;
}
nodeData.add(name, arrayCopy(array, i));
if (i < maxArrayLength) {
PreviousArguments previousArguments = nodeData.toPreviousArguments();
if (unique) {
Map<Object, List<String>> mapped = new HashMap<>();
for (String s : typeMapper.tabComplete(executor, previousArguments, nodeData.current())) {
mapped.computeIfAbsent(typeMapper.map(executor, previousArguments, s), object -> new ArrayList<>())
.add(s);
}
for (int j = 0; j < i; j++) {
mapped.remove(Array.get(array, j));
}
mapped.forEach((object, strings) -> {
completions.add(strings);
});
} else {
completions.add(typeMapper.tabComplete(executor, previousArguments, nodeData.current()));
}
}
if (i >= minArrayLength) {
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
}
nodeData.remove();
for (; i > 0; i--) nodeData.unconsume();
}
protected Object arrayCopy(Object array, int newLength) {
Object newArray = Array.newInstance(type, newLength);
System.arraycopy(array, 0, newArray, 0, Math.min(Array.getLength(array), newLength));
return newArray;
}
@Override
public int nodeCost() {
return minArrayLength * 2 + super.nodeCost();
}
}

View File

@@ -1,145 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.*;
import de.steamwar.command.annotations.TabFilterType;
import de.steamwar.command.handler.TabFilterHandler;
import de.steamwar.command.mapper.EnumMapper;
import de.steamwar.command.mapper.OptionEnumMapper;
import de.steamwar.command.mapper.internal.ContainsFilter;
import de.steamwar.command.mapper.internal.StartsWithFilter;
import de.steamwar.command.utils.Pair;
import de.steamwar.command.utils.Triple;
import java.lang.annotation.Annotation;
import java.lang.reflect.Parameter;
import java.util.List;
public abstract class AbstractTypeNode<E> extends AbstractValidationNode<E> {
protected Class<?> type;
protected AbstractTypeMapper<E, Object> typeMapper;
protected AbstractTypeNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter, index, dataReadable);
type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
initializeTypeMapper(handlerParameters, parameter, index, dataReadable);
}
private AbstractTypeMapper<E, Object> getTypeMapper(Handler.DataReadable dataReadable) {
AbstractTypeMapper<E, Object> typeMapper = dataReadable.getMapper(type.getTypeName());
if (typeMapper == null && type.isEnum()) {
if (OptionEnum.class.isAssignableFrom(type)) {
typeMapper = (AbstractTypeMapper) new OptionEnumMapper((Class) type);
} else {
typeMapper = (AbstractTypeMapper) new EnumMapper((Class) type);
}
}
return typeMapper;
}
private void initializeTypeMapper(List<Pair<Annotation, Handler.HandlerParameter>> pairs, Parameter parameter, int index, Handler.DataReadable dataReadable) {
AbstractTypeMapper<E, Object> typeMapper = getTypeMapper(dataReadable);
boolean isStillDefault = true;
for (Pair<Annotation, Handler.HandlerParameter> pair : pairs) {
if (pair.b.needsParentTypeMapper()) {
continue;
}
if (!isStillDefault) {
throw new UnsupportedOperationException("Only one HandlerParameter can be used without a parent TypeMapper");
}
AbstractTypeMapper<E, Object> temp = pair.b.getTypeMapper(pair.a, parameter, index, dataReadable, null);
if (temp != null) {
typeMapper = temp;
isStillDefault = false;
}
}
AbstractTypeMapper<E, Object> current = typeMapper;
for (Pair<Annotation, Handler.HandlerParameter> pair : pairs) {
if (!pair.b.needsParentTypeMapper()) {
continue;
}
AbstractTypeMapper<E, Object> temp = pair.b.getTypeMapper(pair.a, parameter, index, dataReadable, typeMapper);
if (temp != null) {
typeMapper = temp;
}
}
current = TabCompletionCache.cached(current, typeMapper);
TabFilterType tabFilterType = TabFilterHandler.getTabFilterType(parameter);
switch (tabFilterType) {
case NONE:
this.typeMapper = current;
break;
case STARTS_WITH:
this.typeMapper = new StartsWithFilter<>(current);
break;
case CONTAINS:
this.typeMapper = new ContainsFilter<>(current);
break;
}
}
protected Triple<Object, Boolean, Boolean> argument(E executor, NodeData nodeData) {
Object value;
boolean usedOptional;
try {
PreviousArguments previousArguments = nodeData.toPreviousArguments();
value = typeMapper.map(executor, previousArguments, nodeData.current());
usedOptional = previousArguments.hasUsedOptionalValue();
} catch (Exception e) {
return new Triple<>(null, false, false);
}
if (validate(executor, value, nodeData)) {
return new Triple<>(value, true, usedOptional);
} else {
return new Triple<>(null, false, false);
}
}
protected boolean validate(E executor, Object value, NodeData nodeData) {
for (AbstractTypeValidator<E, Object> validator : validators) {
try {
if (!validator.validate(executor, value, nodeData)) {
return false;
}
} catch (ClassCastException e) {
// Ignore
} catch (Throwable e) {
return false;
}
}
return true;
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
if (!(children instanceof AbstractTypeNode)) {
return false;
}
return super.equals(parameter, children);
}
}

View File

@@ -1,109 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.AbstractTypeValidator;
import de.steamwar.command.CommandUtils;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.AllowNullHandler;
import de.steamwar.command.utils.Pair;
import java.lang.annotation.Annotation;
import java.lang.reflect.Parameter;
import java.util.*;
public abstract class AbstractValidationNode<E> extends Node<E> {
private static final AbstractTypeValidator<?, ?> NON_NULL_VALIDATOR = (AbstractTypeValidator<Object, Object>) (sender, value, messageSender) -> value != null;
protected final List<Annotation> annotations;
protected final List<Pair<Annotation, Handler.HandlerParameter>> handlerParameters;
protected final List<AbstractTypeValidator<E, Object>> validators = new ArrayList<>();
protected AbstractValidationNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter);
annotations = CommandUtils.getAnnotations(parameter, Handler.HandlerParameter.class);
List<Pair<Annotation, Handler.HandlerParameter>> pairs = new ArrayList<>();
for (Annotation annotation : annotations) {
Handler.Implementation implementation = annotation.annotationType().getAnnotation(Handler.Implementation.class);
try {
pairs.add(new Pair<>(annotation, (Handler.HandlerParameter) implementation.value().getConstructor().newInstance()));
} catch (Exception e) {
throw new SecurityException(e);
}
}
handlerParameters = pairs;
initializeValidators(handlerParameters, parameter, index, dataReadable);
}
private void initializeValidators(List<Pair<Annotation, Handler.HandlerParameter>> pairs, Parameter parameter, int index, Handler.DataReadable dataReadable) {
pairs.sort(Comparator.comparingInt(p -> p.b.getValidatorPriority()));
for (Pair<Annotation, Handler.HandlerParameter> pair : pairs) {
AbstractTypeValidator<E, Object> validator = pair.b.getValidator(pair.a, parameter, index, dataReadable);
if (validator != null) {
validators.add(validator);
}
}
if (!AllowNullHandler.isPresent(parameter)) {
validators.add((AbstractTypeValidator<E, Object>) NON_NULL_VALIDATOR);
}
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
if (this.parameter.getType() != parameter.getType()) {
return false;
}
Annotation[] annotations = this.parameter.getAnnotations();
Annotation[] currentAnnotations = parameter.getAnnotations();
if (annotations.length == 0 && currentAnnotations.length == 0) {
return true;
}
if (annotations.length != currentAnnotations.length) {
return false;
}
Map<Class<?>, Annotation> annotationMap = new HashMap<>();
boolean duplicate = false;
for (Annotation annotation : annotations) {
if (annotationMap.put(annotation.annotationType(), annotation) != null) {
duplicate = true;
break;
}
}
if (duplicate) {
return false;
}
for (Annotation annotation : currentAnnotations) {
Annotation other = annotationMap.get(annotation.annotationType());
if (!annotation.equals(other)) {
continue;
}
annotationMap.remove(annotation.annotationType());
}
return annotationMap.isEmpty();
}
}

View File

@@ -1,89 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.CommandFrameworkException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class ExecuteNode<E> extends Node<E> {
private final Object self;
private final Method method;
public ExecuteNode(Object self, Method method) {
super(null);
this.self = self;
this.method = method;
}
@Override
public boolean execute(E executor, NodeData nodeData) {
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) {
return true;
}
}
if (nodeData.hasMore()) {
return false;
}
try {
method.invoke(self, nodeData.mapped());
return true;
} catch (InvocationTargetException e) {
throw new CommandFrameworkException(e, nodeData.alias(), nodeData.args());
} catch (IllegalAccessException | RuntimeException e) {
return false;
}
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
if (children instanceof ExecuteNode) {
String parameters = Arrays.stream(method.getParameters()).map(par -> {
String annotations = Arrays.stream(par.getAnnotations())
.map(annotation -> "@" + annotation.getClass().getSimpleName())
.collect(Collectors.joining(" "));
if (par.isVarArgs()) {
return annotations + (annotations.isEmpty() ? "" : " ") + par.getType().componentType().getSimpleName() + "...";
} else {
return annotations + (annotations.isEmpty() ? "" : " ") + par.getType().getSimpleName();
}
}).collect(Collectors.joining(", "));
throw new UnsupportedOperationException("Command with parameters " + parameters + " is already defined in " + self.getClass().getName());
}
return children instanceof ExecuteNode;
}
}

View File

@@ -1,95 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.AbstractTypeValidator;
import de.steamwar.command.Handler;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
public class ExecutorTypeNode<E> extends AbstractValidationNode<E> {
protected final Function<E, ?> executorMapper;
public ExecutorTypeNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter, index, dataReadable);
this.executorMapper = (Function<E, ?>) dataReadable.getExecutorMapper(parameter.getType());
}
@Override
public boolean execute(E executor, NodeData nodeData) {
Object mappedExecutor = executorMapper.apply(executor);
if (mappedExecutor == null) return false;
for (AbstractTypeValidator<E, Object> validator : validators) {
try {
if (!validator.validate(executor, executor, nodeData)) {
return false;
}
} catch (ClassCastException e) {
// Ignore
} catch (Throwable e) {
return false;
}
}
nodeData.add(name, mappedExecutor);
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
nodeData.remove();
return false;
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
Object mappedExecutor = executorMapper.apply(executor);
if (mappedExecutor == null) return;
for (AbstractTypeValidator<E, Object> validator : validators) {
try {
if (!validator.validate(executor, executor, nodeData)) {
return;
}
} catch (ClassCastException e) {
// Ignore
} catch (Throwable e) {
return;
}
}
nodeData.add(name, mappedExecutor);
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
nodeData.remove();
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
if (!(children instanceof ExecutorTypeNode)) {
return false;
}
ExecutorTypeNode other = (ExecutorTypeNode) children;
if (executorMapper != other.executorMapper) {
return false;
}
return super.equals(parameter, children);
}
}

View File

@@ -1,98 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.Handler;
import de.steamwar.command.handler.GreedyHandler;
import de.steamwar.command.utils.Triple;
import java.lang.reflect.Array;
import java.lang.reflect.Parameter;
import java.util.HashSet;
import java.util.Set;
public class GreedyArrayNode<E> extends AbstractArrayNode<E> {
protected final int backTrackingDepth;
public GreedyArrayNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter, index, dataReadable);
this.backTrackingDepth = GreedyHandler.getBackTrackingDepth(parameter);
}
@Override
public boolean execute(E executor, NodeData nodeData) {
int min = Math.min(nodeData.unparsedArgumentsSize(), minArrayLength);
int max = Math.min(nodeData.unparsedArgumentsSize(), maxArrayLength);
if (max < minArrayLength) {
nodeData.send(error, 0, minArrayLength);
return false;
}
Object array = Array.newInstance(type, max);
Set<Object> seen = new HashSet<>();
int i = 0;
for (; i < max; i++) {
nodeData.add(name, arrayCopy(array, i));
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
nodeData.remove();
if (!argument.b || (unique && !seen.add(argument.a))) {
if (i < minArrayLength) {
nodeData.send(error, i, minArrayLength);
for (; i > 0; i--) nodeData.unconsume();
return false;
}
break;
}
Array.set(array, i, argument.a);
nodeData.consume();
}
int backTrackingDepth = i - this.backTrackingDepth;
for (; i >= min; i--) {
Object copiedArray = arrayCopy(array, i);
nodeData.add(name, copiedArray);
if (validate(executor, copiedArray, nodeData)) {
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) {
return true;
}
}
}
nodeData.remove();
if (i <= backTrackingDepth) {
break;
}
if (i > 0) {
nodeData.unconsume();
}
}
if (i < minArrayLength) nodeData.send(error, i, minArrayLength);
for (; i > 0; i--) nodeData.unconsume();
return false;
}
@Override
public int nodeCost() {
return -1;
}
}

View File

@@ -1,75 +0,0 @@
/*
* 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.graph;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
public class LiteralNode<E> extends Node<E> {
protected final String literal;
public LiteralNode(String literal) {
super(null);
this.literal = literal;
}
@Override
public boolean execute(E executor, NodeData nodeData) {
if (!nodeData.hasMore()) return false;
if (nodeData.current().equalsIgnoreCase(literal)) {
nodeData.consume();
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) {
return true;
}
}
nodeData.unconsume();
}
return false;
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
if (nodeData.hasOneLeft()) {
if (literal.startsWith(nodeData.current())) {
completions.add(List.of(literal));
}
return;
}
if (nodeData.current().equalsIgnoreCase(literal)) {
nodeData.consume();
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
nodeData.unconsume();
}
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
if (!(children instanceof LiteralNode)) {
return false;
}
return literal.equalsIgnoreCase(((LiteralNode) children).literal);
}
}

View File

@@ -1,49 +0,0 @@
/*
* 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.graph;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
public class NoTabCompleteNode<E> extends Node<E> {
public NoTabCompleteNode() {
super(null);
}
@Override
public boolean execute(E executor, NodeData nodeData) {
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
return false;
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
// Do nothing
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
return children instanceof NoTabCompleteNode;
}
}

View File

@@ -1,83 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.annotations.Name;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class Node<E> {
protected final Parameter parameter;
protected final String name;
protected final List<Node<E>> children = new ArrayList<>();
protected Node(Parameter parameter) {
this.parameter = parameter;
if (parameter == null) {
this.name = null;
return;
}
Name name = parameter.getAnnotation(Name.class);
if (name == null) {
this.name = parameter.getName();
} else {
this.name = name.value();
}
}
public abstract boolean execute(E executor, NodeData nodeData);
public abstract void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions);
public final Node<E> addChild(Parameter parameter, Node<E> child) {
for (Node<E> currentChild : children) {
if (currentChild.equals(parameter, child)) {
return currentChild;
}
}
children.add(child);
return child;
}
public abstract boolean equals(Parameter parameter, Node<E> children);
public int nodeCost() {
return 2;
}
public final int sort() {
AtomicInteger max = new AtomicInteger(0);
if (children.size() == 1) {
return children.get(0).sort() + nodeCost();
}
children.sort(Comparator.comparingInt(value -> {
int sort = value.sort();
if (sort > max.get()) max.set(sort);
return -sort;
}));
return max.get() + nodeCost();
}
}

View File

@@ -1,120 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.AbstractTypeValidator;
import de.steamwar.command.PreviousArguments;
import lombok.NonNull;
import java.util.Arrays;
import java.util.LinkedList;
public class NodeData implements AbstractTypeValidator.MessageSender {
private final String alias;
private final LinkedList<String> parsedArguments = new LinkedList<>();
private final LinkedList<String> unparsedArguments;
private final LinkedList<Object> mapped = new LinkedList<>();
private final LinkedList<String> names = new LinkedList<>();
private final AbstractTypeValidator.MessageSender messageSender;
public NodeData(String alias, String[] args, AbstractTypeValidator.MessageSender messageSender) {
this.alias = alias;
this.unparsedArguments = new LinkedList<>(Arrays.asList(args));
this.messageSender = messageSender;
}
public String[] args() {
return parsedArguments.toArray(String[]::new);
}
public String alias() {
return alias;
}
public String current() {
if (unparsedArguments.isEmpty()) return null;
return unparsedArguments.getFirst();
}
public boolean hasMore() {
return !unparsedArguments.isEmpty();
}
public boolean hasOneLeft() {
return unparsedArguments.size() == 1;
}
void consume() {
parsedArguments.addLast(unparsedArguments.removeFirst());
}
void unconsume() {
unparsedArguments.addFirst(parsedArguments.removeLast());
}
void add(String name, Object mapped) {
this.names.addLast(name);
this.mapped.addLast(mapped);
}
void remove() {
this.names.removeLast();
this.mapped.removeLast();
}
public Object getByName(@NonNull String name) {
for (int i = mapped.size() - 1; i >= 0; i--) {
if (name.equals(names.get(i))) {
return mapped.get(i);
}
}
return null;
}
public Object[] mapped() {
return mapped.toArray();
}
public int unparsedArgumentsSize() {
return unparsedArguments.size();
}
@Override
public void send(String s, Object... args) {
if (s == null || s.isEmpty()) return;
messageSender.send(s, args);
}
PreviousArguments toPreviousArguments() {
return new PreviousArguments(args(), mapped(), hasMore(), this::getByName);
}
@Override
public String toString() {
return "NodeData{" +
"alias='" + alias + '\'' +
", parsedArguments=" + parsedArguments + " (" + parsedArguments.size() + ")" +
", unparsedArguments=" + unparsedArguments + " (" + unparsedArguments.size() + ")" +
", mapped=" + mapped + " (" + mapped.size() + ")" +
", names=" + names + " (" + names.size() + ")" +
'}';
}
}

View File

@@ -1,83 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.Handler;
import de.steamwar.command.utils.Triple;
import java.lang.reflect.Array;
import java.lang.reflect.Parameter;
import java.util.HashSet;
import java.util.Set;
public class NonGreedyArrayNode<E> extends AbstractArrayNode<E> {
public NonGreedyArrayNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter, index, dataReadable);
}
@Override
public boolean execute(E executor, NodeData nodeData) {
int min = Math.max(nodeData.unparsedArgumentsSize(), minArrayLength);
int max = Math.min(nodeData.unparsedArgumentsSize(), maxArrayLength);
if (max < minArrayLength) {
nodeData.send(error, 0, minArrayLength);
return false;
}
Object array = Array.newInstance(type, max);
Set<Object> seen = new HashSet<>();
int i = 0;
do {
Object copiedArray = arrayCopy(array, i);
nodeData.add(name, copiedArray);
if (i >= min && validate(executor, copiedArray, nodeData)) {
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
}
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
nodeData.remove();
if (!argument.b || (unique && !seen.add(argument.a))) {
if (i < minArrayLength) nodeData.send(error, i, minArrayLength);
for (; i > 0; i--) nodeData.unconsume();
return false;
}
nodeData.consume();
Array.set(array, i, argument.a);
i++;
} while (i < max);
if (i >= min) {
Object copiedArray = arrayCopy(array, i);
nodeData.add(name, copiedArray);
if (validate(executor, copiedArray, nodeData)) {
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
}
nodeData.remove();
}
if (i < minArrayLength) nodeData.send(error, i, minArrayLength);
for (; i > 0; i--) nodeData.unconsume();
return false;
}
}

View File

@@ -1,51 +0,0 @@
/*
* 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.graph;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
public class RootNode<E> extends Node<E> {
public RootNode() {
super(null);
}
@Override
public boolean execute(E executor, NodeData nodeData) {
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
return false;
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
return children instanceof RootNode;
}
}

View File

@@ -1,100 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.AbstractTypeSupplier;
import de.steamwar.command.Handler;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.annotations.Supplier;
import de.steamwar.command.handler.AllowNullHandler;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
public class SupplierNode<E> extends Node<E> {
protected final AbstractTypeSupplier<E, Object> typeSupplier;
protected final boolean allowNull;
public SupplierNode(Parameter parameter, Handler.DataReadable dataReadable) {
super(parameter);
Supplier annotation = parameter.getAnnotation(Supplier.class);
String s = annotation.value() != null && !annotation.value().isEmpty() ? annotation.value() : parameter.getType().getTypeName();
typeSupplier = dataReadable.getSupplier(s);
allowNull = AllowNullHandler.isPresent(parameter);
}
@Override
public boolean execute(E executor, NodeData nodeData) {
PreviousArguments previousArguments = nodeData.toPreviousArguments();
Object value;
try {
value = typeSupplier.get(executor, previousArguments);
} catch (Exception e) {
return false;
}
if (!allowNull && value == null) {
return false;
}
nodeData.add(name, value);
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
nodeData.remove();
return false;
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
PreviousArguments previousArguments = nodeData.toPreviousArguments();
Object value;
try {
value = typeSupplier.get(executor, previousArguments);
} catch (Exception e) {
return;
}
if (!allowNull && value == null) {
return;
}
nodeData.add(name, value);
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
nodeData.remove();
}
@Override
public boolean equals(Parameter parameter, Node<E> children) {
if (children instanceof SupplierNode) {
SupplierNode<?> supplierNode = (SupplierNode<?>) children;
return allowNull == supplierNode.allowNull && typeSupplier == supplierNode.typeSupplier;
}
return false;
}
}

View File

@@ -1,84 +0,0 @@
/*
* 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.graph;
import de.steamwar.command.Handler;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.utils.Triple;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
public class TypeNode<E> extends AbstractTypeNode<E> {
public TypeNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
super(parameter, index, dataReadable);
}
@Override
public boolean execute(E executor, NodeData nodeData) {
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
if (!argument.b) return false;
nodeData.add(name, argument.a);
if (!argument.c) nodeData.consume();
for (Node<E> child : children) {
if (child.execute(executor, nodeData)) return true;
}
nodeData.remove();
if (!argument.c) nodeData.unconsume();
return false;
}
@Override
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
if (nodeData.hasOneLeft()) {
PreviousArguments previousArguments = nodeData.toPreviousArguments();
Collection<String> tabCompletions = typeMapper.tabComplete(executor, previousArguments, nodeData.current());
completions.add(tabCompletions);
if (typeMapper.appendNextElementTabCompletions()) {
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
}
return;
}
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
if (!argument.b) return;
nodeData.add(name, argument.a);
if (!argument.c) nodeData.consume();
for (Node<E> child : children) {
child.tabComplete(executor, nodeData, completions);
}
nodeData.remove();
if (!argument.c) nodeData.unconsume();
}
@Override
public int nodeCost() {
return type == String.class ? 1 : 2;
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.AllowNull;
import java.lang.reflect.Parameter;
/**
* This special Handler is just for validating the AllowNull annotation.
*/
public final class AllowNullHandler {
public static boolean isPresent(Parameter parameter) {
return parameter.isAnnotationPresent(AllowNull.class);
}
public static final class Impl implements Handler.HandlerParameter<AllowNull, Object, Object> {
@Override
public void check(AllowNull annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("AllowNull annotation cannot be used on the first parameter");
}
if (parameter.getType().isPrimitive()) {
throw new UnsupportedOperationException("AllowNull annotation cannot be used on primitive types");
}
}
}
}

View File

@@ -1,62 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.ArrayLength;
import java.lang.reflect.Parameter;
public final class ArrayLengthHandler {
public static int getMin(Parameter parameter) {
ArrayLength arrayLength = parameter.getAnnotation(ArrayLength.class);
if (arrayLength == null) return 0;
return arrayLength.min();
}
public static int getMax(Parameter parameter) {
ArrayLength arrayLength = parameter.getAnnotation(ArrayLength.class);
if (arrayLength == null) return Integer.MAX_VALUE;
return arrayLength.max();
}
public static String getError(Parameter parameter) {
ArrayLength arrayLength = parameter.getAnnotation(ArrayLength.class);
if (arrayLength == null) return "";
return arrayLength.error();
}
public static final class Impl implements Handler.HandlerParameter<ArrayLength, Object, Object> {
@Override
public void check(ArrayLength arrayLength, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("ArrayLength annotation cannot be used on first parameter");
}
if (!parameter.getType().isArray()) {
throw new UnsupportedOperationException("Parameter " + index + " of " + parameter.getDeclaringExecutable().getName() + " is not an array");
}
if (arrayLength.min() > arrayLength.max()) {
throw new UnsupportedOperationException("Min ArrayLength cannot be smaller than Max ArrayLength");
}
}
}
}

View File

@@ -1,54 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.TabCompletionCache;
import de.steamwar.command.annotations.Cached;
import java.lang.reflect.Method;
public final class CachedHandler {
public static final class Impl implements Handler.HandlerMethod<Cached> {
@Override
public void check(Cached annotation, Method method, DataCheckable dataCheckable) throws Exception {
if (method.getParameterCount() != 0) {
throw new UnsupportedOperationException("Cached method must have no parameters");
}
if (!AbstractTypeMapper.class.isAssignableFrom(method.getReturnType())) {
throw new UnsupportedOperationException("Cached method must return AbstractTypeMapper");
}
}
@Override
public int getRunPriority() {
return Integer.MIN_VALUE;
}
@Override
public void run(Cached annotation, Method method, DataWritable dataWritable) {
AbstractTypeMapper abstractTypeMapper = dataWritable.invoke(method);
TabCompletionCache.add(abstractTypeMapper, annotation.global(), annotation.cacheDuration(), annotation.timeUnit());
}
}
}

View File

@@ -1,54 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.ClassMapper;
import java.lang.reflect.Method;
@Deprecated
public final class ClassMapperHandler {
public static final class Impl implements Handler.HandlerMethod<ClassMapper> {
@Override
public void check(ClassMapper annotation, Method method, DataCheckable dataCheckable) throws Exception {
if (method.getParameterCount() != 0) {
throw new UnsupportedOperationException("ClassMapper method must have no parameters");
}
if (!AbstractTypeMapper.class.isAssignableFrom(method.getReturnType())) {
throw new UnsupportedOperationException("ClassMapper method must return AbstractTypeMapper");
}
}
@Override
public int getRunPriority() {
return Integer.MIN_VALUE;
}
@Override
public void run(ClassMapper annotation, Method method, DataWritable dataWritable) {
AbstractTypeMapper abstractTypeMapper = dataWritable.invoke(method);
dataWritable.addMapper(annotation.value().getName(), annotation.local(), abstractTypeMapper);
}
}
}

View File

@@ -1,54 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeValidator;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.ClassValidator;
import java.lang.reflect.Method;
@Deprecated
public final class ClassValidatorHandler {
public static final class Impl implements Handler.HandlerMethod<ClassValidator> {
@Override
public void check(ClassValidator annotation, Method method, DataCheckable dataCheckable) throws Exception {
if (method.getParameterCount() != 0) {
throw new UnsupportedOperationException("ClassValidator method must have no parameters");
}
if (!AbstractTypeValidator.class.isAssignableFrom(method.getReturnType())) {
throw new UnsupportedOperationException("ClassValidator method must return AbstractValidator");
}
}
@Override
public int getRunPriority() {
return Integer.MIN_VALUE;
}
@Override
public void run(ClassValidator annotation, Method method, DataWritable dataWritable) {
AbstractTypeValidator<Object, Object> abstractTypeValidator = dataWritable.invoke(method);
dataWritable.addValidator(annotation.value().getName(), annotation.local(), abstractTypeValidator);
}
}
}

View File

@@ -1,84 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.AbstractTypeValidator;
import de.steamwar.command.Handler;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.annotations.EndsWith;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.stream.Collectors;
public final class EndsWithHandler {
public static final class Impl implements Handler.HandlerParameter<EndsWith, Object, String> {
@Override
public void check(EndsWith annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("EndsWith annotation cannot be used on first parameter");
}
if (parameter.getType() != String.class) {
throw new UnsupportedOperationException("EndsWith annotation cannot be used on String parameter");
}
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, String> getTypeMapper(EndsWith annotation, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, String> parentTypeMapper) {
String endsWith = annotation.value();
return new DelegatingMapper<>(parentTypeMapper, annotation) {
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
return super.tabComplete(sender, previousArguments, s).stream().map(s1 -> {
if (s1.startsWith(endsWith)) return s1;
return s1 + endsWith;
}).collect(Collectors.toList());
}
};
}
@Override
public int getValidatorPriority() {
return 0;
}
@Override
public AbstractTypeValidator<Object, String> getValidator(EndsWith annotation, Parameter parameter, int index, DataReadable dataReadable) {
String endsWith = annotation.value();
String error = annotation.error();
return (sender, value, messageSender) -> {
if (value == null) return true;
if (value.endsWith(endsWith)) return true;
messageSender.send(error);
return false;
};
}
}
}

View File

@@ -1,60 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeValidator;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.ErrorMessage;
import java.lang.reflect.Array;
import java.lang.reflect.Parameter;
public final class ErrorMessageHandler {
public static final class Impl implements Handler.HandlerParameter<ErrorMessage, Object, Object> {
@Override
public void check(ErrorMessage errorMessage, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("ErrorMessage annotation cannot be used on first parameter");
}
if (!errorMessage.allowEAs() && !(parameter.isVarArgs() || parameter.getType().isArray())) {
throw new UnsupportedOperationException("ErrorMessage allowESs cannot be used on non array or varargs parameter");
}
}
@Override
public int getValidatorPriority() {
return Integer.MAX_VALUE;
}
@Override
public AbstractTypeValidator<Object, Object> getValidator(ErrorMessage errorMessage, Parameter parameter, int index, DataReadable dataReadable) {
return (sender, value, messageSender) -> {
if (value == null) messageSender.send(errorMessage.value());
if (!errorMessage.allowEAs() && value != null && value.getClass().isArray() && Array.getLength(value) == 0) {
messageSender.send(errorMessage.value());
return false;
}
return value != null;
};
}
}
}

View File

@@ -1,53 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.Greedy;
import java.lang.reflect.Parameter;
/**
* This special Handler is just for validating the Greedy annotation.
*/
public final class GreedyHandler {
public static boolean isGreedy(Parameter parameter) {
return parameter.isAnnotationPresent(Greedy.class);
}
public static int getBackTrackingDepth(Parameter parameter) {
Greedy greedy = parameter.getAnnotation(Greedy.class);
if (greedy == null || parameter.isVarArgs()) {
return 0;
}
return greedy.backTrackingDepth();
}
public static final class Impl implements Handler.HandlerParameter<Greedy, Object, Object> {
@Override
public void check(Greedy annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (!parameter.getType().isArray() || parameter.isVarArgs()) {
throw new UnsupportedOperationException("Greedy annotation cannot be used on non array parameters");
}
}
}
}

View File

@@ -1,76 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.annotations.Length;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public final class LengthHandler {
public static final class Impl implements Handler.HandlerParameter<Length, Object, Object> {
@Override
public void check(Length annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("Length annotation cannot be used on first parameter");
}
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, Object> getTypeMapper(Length length, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Object> parentTypeMapper) {
int min = length.min();
int max = length.max();
return new DelegatingMapper<>(parentTypeMapper, length) {
@Override
public Object map(Object sender, PreviousArguments previousArguments, String s) {
if (s.length() < min || s.length() > max) return null;
return delegate.map(sender, previousArguments, s);
}
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
List<String> tabCompletes = delegate.tabComplete(sender, previousArguments, s)
.stream()
.filter(str -> str.length() >= min)
.map(str -> str.substring(0, Math.min(str.length(), max)))
.collect(Collectors.toList());
if (s.length() < min) {
tabCompletes.add(0, s);
}
return tabCompletes;
}
};
}
}
}

View File

@@ -1,96 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.annotations.Mapper;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Optional;
public final class MapperHandler {
public static final class Impl implements Handler.HandlerMethod<Mapper>, Handler.HandlerParameter<Mapper, Object, Object> {
@Override
public void check(Mapper annotation, Method method, DataCheckable dataCheckable) throws Exception {
if (method.getParameterCount() != 0) {
throw new UnsupportedOperationException("Mapper method must have no parameters");
}
if (!AbstractTypeMapper.class.isAssignableFrom(method.getReturnType())) {
throw new UnsupportedOperationException("Mapper method must return AbstractTypeMapper");
}
if (annotation.value() != null && !annotation.value().isEmpty()) {
return;
}
Optional<Class<?>> genericType = getGenericTypeOfReturn(method);
if (annotation.type() == void.class) {
if (genericType.isEmpty()) {
throw new UnsupportedOperationException("Please supply a class type to the Mapper");
}
} else {
if (genericType.isPresent() && !annotation.type().isAssignableFrom(genericType.get())) {
throw new UnsupportedOperationException("Supplied type does not conform to actual type");
}
}
}
@Override
public int getRunPriority() {
return Integer.MIN_VALUE;
}
@Override
public void run(Mapper annotation, Method method, DataWritable dataWritable) {
AbstractTypeMapper abstractTypeMapper = dataWritable.invoke(method);
if (annotation.value() != null && !annotation.value().isEmpty()) {
dataWritable.addMapper(annotation.value(), annotation.local(), abstractTypeMapper);
} else {
Class<?> type = annotation.type();
if (type == void.class) type = getGenericTypeOfReturn(method).get();
dataWritable.addMapper(type.getName(), annotation.local(), abstractTypeMapper);
}
}
@Override
public void check(Mapper annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("Mapper annotation cannot be used on first parameter");
}
if (!dataCheckable.hasMapper(annotation.value())) {
throw new UnsupportedOperationException("Mapper '" + annotation.value() + "' not found");
}
}
@Override
public AbstractTypeMapper<Object, Object> getTypeMapper(Mapper annotation, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Object> parentTypeMapper) {
String s = annotation.value();
AbstractTypeMapper<Object, Object> abstractTypeMapper = dataReadable.getMapper(s);
if (abstractTypeMapper == null) {
throw new IllegalArgumentException("No mapper found for " + s);
}
return abstractTypeMapper;
}
}
}

View File

@@ -1,172 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.*;
import de.steamwar.command.annotations.Max;
import de.steamwar.command.annotations.Min;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.ToIntFunction;
public final class MaxHandler {
public static final class Impl implements Handler.HandlerParameter<Max, Object, Number> {
@Override
public void check(Max max, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("Max annotation cannot be used on first parameter");
}
Class<?> type = parameter.getType();
if (parameter.isVarArgs()) type = type.getComponentType();
if (type != int.class && type != Integer.class && type != long.class && type != Long.class && type != float.class && type != Float.class && type != double.class && type != Double.class) {
throw new UnsupportedOperationException("Parameter " + index + " of " + parameter.getDeclaringExecutable() + " is not a number.");
}
if (!parameter.isAnnotationPresent(Min.class)) {
return;
}
Min min = parameter.getAnnotation(Min.class);
Number minValue;
if (type.equals(int.class) || type.equals(Integer.class)) {
minValue = min.intValue();
} else if (type.equals(long.class) || type.equals(Long.class)) {
minValue = min.longValue();
} else if (type.equals(float.class) || type.equals(Float.class)) {
minValue = min.floatValue();
} else if (type.equals(double.class) || type.equals(Double.class)) {
minValue = min.doubleValue();
} else {
throw new SecurityException();
}
ToIntFunction<Number> maxComparator = CommandUtils.createComparator("Max", type, max.intValue(), max.longValue(), max.floatValue(), max.doubleValue());
if (!(min.inclusive() && max.inclusive()) && maxComparator.applyAsInt(minValue) == 0) {
throw new UnsupportedOperationException("Min and Max cannot be equal if not both are inclusive");
} else if (maxComparator.applyAsInt(minValue) > 0) {
throw new UnsupportedOperationException("Max must be bigger then Min");
}
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, Number> getTypeMapper(Max max, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Number> parentTypeMapper) {
Class<?> type = parameter.getType();
if (parameter.isVarArgs()) type = type.getComponentType();
int compareValue = max.inclusive() ? 0 : -1;
ToIntFunction<Number> comparator = CommandUtils.createComparator("Max", type, max.intValue(), max.longValue(), max.floatValue(), max.doubleValue());
boolean onlyNegative = comparator.applyAsInt(0) >= 0;
Min min = parameter.getAnnotation(Min.class);
Number minValue;
Number maxValue;
if (type.equals(int.class) || type.equals(Integer.class)) {
minValue = min != null ? min.intValue() : null;
maxValue = max.intValue();
} else if (type.equals(long.class) || type.equals(Long.class)) {
minValue = min != null ? min.longValue() : null;
maxValue = max.longValue();
} else if (type.equals(float.class) || type.equals(Float.class)) {
minValue = min != null ? min.floatValue() : null;
maxValue = max.floatValue();
} else if (type.equals(double.class) || type.equals(Double.class)) {
minValue = min != null ? min.doubleValue() : null;
maxValue = max.doubleValue();
} else {
throw new SecurityException();
}
return new DelegatingMapper<>(parentTypeMapper, max) {
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
Collection<String> tabCompletions = new ArrayList<>(super.tabComplete(sender, previousArguments, s));
tabCompletions.removeIf(tabCompletion -> {
if (onlyNegative && !tabCompletion.startsWith("-")) return true;
Number value = super.map(sender, previousArguments, tabCompletion);
if (value == null) {
return false;
}
return comparator.applyAsInt(value) > compareValue;
});
if (tabCompletions.isEmpty()) {
if (minValue != null && min.inclusive()) {
tabCompletions.add(minValue.toString());
}
if (max.inclusive()) {
tabCompletions.add(maxValue.toString());
}
}
return tabCompletions;
}
};
}
@Override
public int getValidatorPriority() {
return 2;
}
@Override
public AbstractTypeValidator<Object, Number> getValidator(Max max, Parameter parameter, int index, DataReadable dataReadable) {
Class<?> type = parameter.getType();
if (parameter.isVarArgs()) type = type.getComponentType();
Number maxValue;
if (type.equals(int.class) || type.equals(Integer.class)) {
maxValue = max.intValue();
} else if (type.equals(long.class) || type.equals(Long.class)) {
maxValue = max.longValue();
} else if (type.equals(float.class) || type.equals(Float.class)) {
maxValue = max.floatValue();
} else if (type.equals(double.class) || type.equals(Double.class)) {
maxValue = max.doubleValue();
} else {
throw new SecurityException();
}
int compareValue = max.inclusive() ? 0 : -1;
ToIntFunction<Number> comparator = CommandUtils.createComparator("Max", type, max.intValue(), max.longValue(), max.floatValue(), max.doubleValue());
return (sender, value, messageSender) -> {
if (value == null) return true;
if (comparator.applyAsInt(value) <= compareValue) {
return true;
} else {
String error = max.error();
if (error != null && !error.isEmpty()) messageSender.send(error, value, maxValue);
return false;
}
};
}
}
}

View File

@@ -1,143 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command.handler;
import de.steamwar.command.*;
import de.steamwar.command.annotations.Max;
import de.steamwar.command.annotations.Name;
import de.steamwar.command.graph.NodeData;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.function.ToIntFunction;
public final class MaxReferenceHandler {
public static final class Impl implements Handler.HandlerParameter<Max.Reference, Object, Number> {
@Override
public void check(Max.Reference annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("Max.Reference annotation cannot be used on first parameter");
}
Class<?> type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
if (type != int.class && type != Integer.class && type != long.class && type != Long.class && type != float.class && type != Float.class && type != double.class && type != Double.class) {
throw new UnsupportedOperationException("Parameter " + index + " of " + parameter.getDeclaringExecutable() + " is not a number.");
}
Parameter[] parameters = parameter.getDeclaringExecutable().getParameters();
for (int i = index - 1; i >= 1; i--) {
Parameter toCheck = parameters[i];
Name name = toCheck.getAnnotation(Name.class);
String parameterName;
if (name == null) {
parameterName = toCheck.getName();
} else {
parameterName = name.value();
}
if (!parameterName.equals(annotation.value())) {
continue;
}
Class<?> parameterType = toCheck.getType();
if (!type.isAssignableFrom(parameterType)) {
throw new UnsupportedOperationException("Parameter type being referenced cannot be assigned here!");
} else {
return;
}
}
throw new UnsupportedOperationException("Parameter with name '" + annotation.value() + "' does not exist.");
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, Number> getTypeMapper(Max.Reference maxReference, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Number> parentTypeMapper) {
Class<?> type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
Class<?> finalType = type;
String name = maxReference.value();
int compareValue = maxReference.inclusive() ? 0 : -1;
return new DelegatingMapper<>(parentTypeMapper, maxReference) {
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
Number number = previousArguments.getByName(name);
if (number == null) return Collections.emptyList();
ToIntFunction<Number> comparator = CommandUtils.createComparator("Max.Reference", finalType, number.intValue(), number.longValue(), number.floatValue(), number.doubleValue());
boolean onlyNegative = comparator.applyAsInt(0) >= 0;
Collection<String> tabCompletions = new ArrayList<>(super.tabComplete(sender, previousArguments, s));
tabCompletions.removeIf(tabCompletion -> {
if (onlyNegative && !tabCompletion.startsWith("-")) return true;
Number value = super.map(sender, previousArguments, tabCompletion);
if (value == null) {
return false;
}
return comparator.applyAsInt(value) > compareValue;
});
if (tabCompletions.isEmpty() && maxReference.inclusive()) {
tabCompletions.add(number + "");
}
return tabCompletions;
}
};
}
@Override
public int getValidatorPriority() {
return 2;
}
@Override
public AbstractTypeValidator<Object, Number> getValidator(Max.Reference maxReference, Parameter parameter, int index, DataReadable dataReadable) {
Class<?> type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
Class<?> finalType = type;
String name = maxReference.value();
int compareValue = maxReference.inclusive() ? 0 : -1;
return (sender, value, messageSender) -> {
Number number = (Number)((NodeData) messageSender).getByName(name);
if (number == null) return false;
ToIntFunction<Number> comparator = CommandUtils.createComparator("Max.Reference", finalType, number.intValue(), number.longValue(), number.floatValue(), number.doubleValue());
if (value == null) return true;
if (comparator.applyAsInt(value) <= compareValue) {
return true;
} else {
String error = maxReference.error();
if (error != null && !error.isEmpty()) messageSender.send(error, value, number);
return false;
}
};
}
}
}

View File

@@ -1,147 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.*;
import de.steamwar.command.annotations.Max;
import de.steamwar.command.annotations.Min;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.ToIntFunction;
public final class MinHandler {
public static final class Impl implements Handler.HandlerParameter<Min, Object, Number> {
@Override
public void check(Min min, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("Min annotation cannot be used on first parameter");
}
Class<?> type = parameter.getType();
if (parameter.isVarArgs()) type = type.getComponentType();
if (type == int.class || type == Integer.class) return;
if (type == long.class || type == Long.class) return;
if (type == float.class || type == Float.class) return;
if (type == double.class || type == Double.class) return;
throw new UnsupportedOperationException("Parameter " + index + " of " + parameter.getDeclaringExecutable() + " is not a number.");
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, Number> getTypeMapper(Min min, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Number> parentTypeMapper) {
Class<?> type = parameter.getType();
if (parameter.isVarArgs()) type = type.getComponentType();
int compareValue = min.inclusive() ? 0 : 1;
ToIntFunction<Number> comparator = CommandUtils.createComparator("Min", type, min.intValue(), min.longValue(), min.floatValue(), min.doubleValue());
boolean onlyPositive = comparator.applyAsInt(0) < 0;
Max max = parameter.getAnnotation(Max.class);
Number minValue;
Number maxValue;
if (type.equals(int.class) || type.equals(Integer.class)) {
minValue = min.intValue();
maxValue = max != null ? max.intValue() : null;
} else if (type.equals(long.class) || type.equals(Long.class)) {
minValue = min.longValue();
maxValue = max != null ? max.longValue() : null;
} else if (type.equals(float.class) || type.equals(Float.class)) {
minValue = min.floatValue();
maxValue = max != null ? max.floatValue() : null;
} else if (type.equals(double.class) || type.equals(Double.class)) {
minValue = min.doubleValue();
maxValue = max != null ? max.doubleValue() : null;
} else {
throw new SecurityException();
}
return new DelegatingMapper<>(parentTypeMapper, min) {
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
Collection<String> tabCompletions = new ArrayList<>(super.tabComplete(sender, previousArguments, s));
tabCompletions.removeIf(tabCompletion -> {
if (onlyPositive && tabCompletion.startsWith("-")) return true;
Number value = super.map(sender, previousArguments, tabCompletion);
if (value == null) {
return false;
}
return comparator.applyAsInt(value) < compareValue;
});
if (tabCompletions.isEmpty()) {
if (min.inclusive()) {
tabCompletions.add(minValue.toString());
}
if (maxValue != null && max.inclusive()) {
tabCompletions.add(maxValue.toString());
}
}
return tabCompletions;
}
};
}
@Override
public int getValidatorPriority() {
return 2;
}
@Override
public AbstractTypeValidator<Object, Number> getValidator(Min min, Parameter parameter, int index, DataReadable dataReadable) {
Class<?> type = parameter.getType();
if (parameter.isVarArgs()) type = type.getComponentType();
Number minValue;
if (type.equals(int.class) || type.equals(Integer.class)) {
minValue = min.intValue();
} else if (type.equals(long.class) || type.equals(Long.class)) {
minValue = min.longValue();
} else if (type.equals(float.class) || type.equals(Float.class)) {
minValue = min.floatValue();
} else if (type.equals(double.class) || type.equals(Double.class)) {
minValue = min.doubleValue();
} else {
throw new SecurityException();
}
int compareValue = min.inclusive() ? 0 : 1;
ToIntFunction<Number> comparator = CommandUtils.createComparator("Min", type, min.intValue(), min.longValue(), min.floatValue(), min.doubleValue());
return (sender, value, messageSender) -> {
if (value == null) return true;
if (comparator.applyAsInt(value) >= compareValue) {
return true;
} else {
String error = min.error();
if (error != null && !error.isEmpty()) messageSender.send(error, value, minValue);
return false;
}
};
}
}
}

View File

@@ -1,143 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command.handler;
import de.steamwar.command.*;
import de.steamwar.command.annotations.Min;
import de.steamwar.command.annotations.Name;
import de.steamwar.command.graph.NodeData;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.function.ToIntFunction;
public final class MinReferenceHandler {
public static final class Impl implements Handler.HandlerParameter<Min.Reference, Object, Number> {
@Override
public void check(Min.Reference annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("Min.Reference annotation cannot be used on first parameter");
}
Class<?> type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
if (type != int.class && type != Integer.class && type != long.class && type != Long.class && type != float.class && type != Float.class && type != double.class && type != Double.class) {
throw new UnsupportedOperationException("Parameter " + index + " of " + parameter.getDeclaringExecutable() + " is not a number.");
}
Parameter[] parameters = parameter.getDeclaringExecutable().getParameters();
for (int i = index - 1; i >= 1; i--) {
Parameter toCheck = parameters[i];
Name name = toCheck.getAnnotation(Name.class);
String parameterName;
if (name == null) {
parameterName = toCheck.getName();
} else {
parameterName = name.value();
}
if (!parameterName.equals(annotation.value())) {
continue;
}
Class<?> parameterType = toCheck.getType();
if (!type.isAssignableFrom(parameterType)) {
throw new UnsupportedOperationException("Parameter type being referenced cannot be assigned here!");
} else {
return;
}
}
throw new UnsupportedOperationException("Parameter with name '" + annotation.value() + "' does not exist.");
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, Number> getTypeMapper(Min.Reference minReference, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Number> parentTypeMapper) {
Class<?> type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
Class<?> finalType = type;
String name = minReference.value();
int compareValue = minReference.inclusive() ? 0 : 1;
return new DelegatingMapper<>(parentTypeMapper, minReference) {
@Override
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
Number number = previousArguments.getByName(name);
if (number == null) return Collections.emptyList();
ToIntFunction<Number> comparator = CommandUtils.createComparator("Min.Reference", finalType, number.intValue(), number.longValue(), number.floatValue(), number.doubleValue());
boolean onlyPositive = comparator.applyAsInt(0) < 0;
Collection<String> tabCompletions = new ArrayList<>(super.tabComplete(sender, previousArguments, s));
tabCompletions.removeIf(tabCompletion -> {
if (onlyPositive && tabCompletion.startsWith("-")) return true;
Number value = super.map(sender, previousArguments, tabCompletion);
if (value == null) {
return false;
}
return comparator.applyAsInt(value) < compareValue;
});
if (tabCompletions.isEmpty() && minReference.inclusive()) {
tabCompletions.add(number + "");
}
return tabCompletions;
}
};
}
@Override
public int getValidatorPriority() {
return 2;
}
@Override
public AbstractTypeValidator<Object, Number> getValidator(Min.Reference minReference, Parameter parameter, int index, DataReadable dataReadable) {
Class<?> type = parameter.getType();
if (type.isArray()) type = type.getComponentType();
Class<?> finalType = type;
String name = minReference.value();
int compareValue = minReference.inclusive() ? 0 : 1;
return (sender, value, messageSender) -> {
Number number = (Number)((NodeData) messageSender).getByName(name);
if (number == null) return false;
ToIntFunction<Number> comparator = CommandUtils.createComparator("Min.Reference", finalType, number.intValue(), number.longValue(), number.floatValue(), number.doubleValue());
if (value == null) return true;
if (comparator.applyAsInt(value) >= compareValue) {
return true;
} else {
String error = minReference.error();
if (error != null && !error.isEmpty()) messageSender.send(error, value, number);
return false;
}
};
}
}
}

View File

@@ -1,80 +0,0 @@
/*
* 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.handler;
import de.steamwar.command.AbstractTypeMapper;
import de.steamwar.command.Handler;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.annotations.OptionalValue;
import de.steamwar.command.mapper.internal.DelegatingMapper;
import java.lang.reflect.Parameter;
/**
* This special Handler is just for validating the OptionalValue annotation.
*/
public final class OptionalValueHandler {
public static final class Impl implements Handler.HandlerParameter<OptionalValue, Object, Object> {
@Override
public void check(OptionalValue annotation, Parameter parameter, int index, DataCheckable dataCheckable) throws Exception {
if (index == 0) {
throw new UnsupportedOperationException("OptionalValue annotation cannot be used on the first parameter");
}
if (parameter.isVarArgs() || parameter.getType().isArray()) {
throw new UnsupportedOperationException("OptionalValue annotation cannot be used on varargs or array parameters");
}
}
@Override
public boolean needsParentTypeMapper() {
return true;
}
@Override
public AbstractTypeMapper<Object, Object> getTypeMapper(OptionalValue annotation, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<Object, Object> parentTypeMapper) {
String defaultValue = annotation.value();
boolean onlyUseIfNoneIsGiven = annotation.onlyUINIG();
return new DelegatingMapper<>(parentTypeMapper, annotation) {
@Override
public Object map(Object sender, PreviousArguments previousArguments, String s) {
if (s != null) {
Object value = delegate.map(sender, previousArguments, s);
if (value != null) {
return value;
}
}
if (previousArguments.hasMoreArguments && onlyUseIfNoneIsGiven) {
return null;
}
previousArguments.usedOptionalValue();
return delegate.map(sender, previousArguments, defaultValue);
}
@Override
public boolean appendNextElementTabCompletions() {
return !onlyUseIfNoneIsGiven;
}
};
}
}
}

Some files were not shown because too many files have changed in this diff Show More