1010import net .swofty .commons .StringUtility ;
1111import net .swofty .commons .protocol .objects .punishment .PunishPlayerProtocolObject ;
1212import net .swofty .commons .punishment .PunishmentReason ;
13+ import net .swofty .commons .punishment .PunishmentRedis ;
14+ import net .swofty .commons .punishment .PunishmentTag ;
1315import net .swofty .commons .punishment .PunishmentType ;
1416import net .swofty .commons .punishment .template .BanType ;
1517import net .swofty .proxyapi .ProxyPlayer ;
1618import net .swofty .proxyapi .ProxyService ;
1719import net .swofty .type .generic .command .CommandParameters ;
1820import net .swofty .type .generic .command .HypixelCommand ;
1921import net .swofty .type .generic .user .categories .Rank ;
22+ import org .jetbrains .annotations .Nullable ;
2023
2124import java .io .IOException ;
25+ import java .util .ArrayList ;
26+ import java .util .List ;
27+ import java .util .Optional ;
2228import java .util .UUID ;
2329import java .util .concurrent .CompletableFuture ;
2430import java .util .concurrent .TimeUnit ;
31+ import java .util .concurrent .atomic .AtomicBoolean ;
2532
2633@ CommandParameters (
2734 aliases = "ban tempban banip tempbanip" ,
@@ -41,6 +48,11 @@ public void registerUsage(MinestomCommand command) {
4148 suggestion .addEntry (new SuggestionEntry (type .name (), Component .text ("§c" + type .getReason () + " §7| Wipe: " + type .isWipe ())));
4249 }
4350 });
51+ Argument <String []> extraArg = ArgumentType .StringArray ("extra" ).setSuggestionCallback ((sender , context , suggestion ) -> {
52+ for (PunishmentTag tag : PunishmentTag .values ()) {
53+ suggestion .addEntry (new SuggestionEntry ("-" + tag .getShortCode (), Component .text ("§e" + tag .getShortCode () + " §7| " + (tag .getDescription () != null ? tag .getDescription () : "No description" ))));
54+ }
55+ }); // can be -O -U etc.
4456
4557 command .addSyntax ((sender , context ) -> {
4658 String playerName = context .get (playerArg );
@@ -68,7 +80,7 @@ public void registerUsage(MinestomCommand command) {
6880 long expiryTime = System .currentTimeMillis () + actualTime ;
6981
7082 CompletableFuture .runAsync (() -> {
71- banPlayer (sender , targetUuid , type , senderUuid , actualTime , expiryTime , playerName );
83+ banPlayer (sender , targetUuid , type , senderUuid , actualTime , expiryTime , playerName , null );
7284 });
7385 }, playerArg , durationArg , reasonArg );
7486
@@ -85,23 +97,78 @@ public void registerUsage(MinestomCommand command) {
8597 sender instanceof Player player ? player .getUuid () : UUID .fromString ("00000000-0000-0000-0000-000000000000" ),
8698 0 ,
8799 -1 ,
88- playerName );
100+ playerName , null );
89101 } catch (IOException e ) {
90102 sender .sendMessage ("§cCould not find player: " + playerName );
91103 return ;
92104 }
93105 });
94106 }, playerArg , reasonArg );
107+
108+ command .addSyntax ((sender , context ) -> {
109+ String playerName = context .get (playerArg );
110+ BanType reason = BanType .valueOf (context .get (reasonArg ));
111+ List <PunishmentTag > tags = parseTags (List .of (context .get (extraArg )));
112+
113+ CompletableFuture .runAsync (() -> {
114+ try {
115+ banPlayer (sender ,
116+ MojangUtils .getUUID (playerName ),
117+ reason ,
118+ sender instanceof Player player ? player .getUuid () : UUID .fromString ("00000000-0000-0000-0000-000000000000" ),
119+ 0 ,
120+ -1 ,
121+ playerName , tags );
122+ } catch (IOException e ) {
123+ sender .sendMessage ("§cCould not find player: " + playerName );
124+ }
125+ });
126+ }, playerArg , reasonArg , extraArg );
127+ }
128+
129+ private List <PunishmentTag > parseTags (List <String > rawTags ) {
130+ List <PunishmentTag > tags = new ArrayList <>();
131+
132+ for (String rawTag : rawTags ) {
133+ if (rawTag .startsWith ("-" )) {
134+ String tagCode = rawTag .substring (1 ).toUpperCase ();
135+ for (PunishmentTag tag : PunishmentTag .values ()) {
136+ if (tag .getShortCode ().equalsIgnoreCase (tagCode )) {
137+ tags .add (tag );
138+ break ;
139+ }
140+ }
141+ }
142+ }
143+
144+ return tags ;
95145 }
96146
97- private void banPlayer (CommandSender sender , UUID targetUuid , BanType type , UUID senderUuid , long actualTime , long expiryTime , String playerName ) {
147+ private void banPlayer (CommandSender sender , UUID targetUuid , BanType type , UUID senderUuid , long actualTime , long expiryTime , String playerName , @ Nullable List <PunishmentTag > tags ) {
148+ if (tags != null && !tags .contains (PunishmentTag .OVERWRITE )) {
149+ Optional <PunishmentRedis .ActivePunishment > activePunishment = PunishmentRedis .getActive (targetUuid );
150+ AtomicBoolean alreadyBanned = new AtomicBoolean (false );
151+ activePunishment .ifPresent (punishment -> {
152+ PunishmentType t = PunishmentType .valueOf (punishment .type ());
153+ if (t == PunishmentType .BAN ) {
154+ sender .sendMessage ("§cThis player is already banned. If you want to replace this ban use the tag -O, Punishment ID: §7" + punishment .banId ());
155+ alreadyBanned .set (true );
156+ }
157+ });
158+ if (alreadyBanned .get ()) {
159+ return ;
160+ }
161+ }
162+
98163 ProxyService punishmentService = new ProxyService (ServiceType .PUNISHMENT );
99164 PunishmentReason reason = new PunishmentReason (type );
165+ ArrayList <PunishmentTag > tagList = (tags != null ) ? new ArrayList <>(tags ) : new ArrayList <>();
100166 PunishPlayerProtocolObject .PunishPlayerMessage message = new PunishPlayerProtocolObject .PunishPlayerMessage (
101167 targetUuid ,
102168 PunishmentType .BAN .name (),
103169 reason ,
104170 senderUuid ,
171+ tagList ,
105172 actualTime > 0 ? expiryTime : -1
106173 );
107174
0 commit comments