1616import me .general_breddok .blockdisplaycreator .permission .DefaultPermissions ;
1717import me .general_breddok .blockdisplaycreator .placeholder .universal .PlayerSkinBase64Placeholder ;
1818import me .general_breddok .blockdisplaycreator .util .ChatUtil ;
19+ import me .general_breddok .blockdisplaycreator .util .CommandUtil ;
1920import me .general_breddok .blockdisplaycreator .util .ItemUtil ;
2021import me .general_breddok .blockdisplaycreator .world .WorldSelection ;
2122import org .bukkit .Bukkit ;
3435import java .util .List ;
3536
3637
37- /**
38- * @deprecated
39- */
40- @ Deprecated (since = "MC1.19.4" )
38+
4139public class BlockDisplayCreatorSpigotCommand implements TabExecutor {
4240
43- private final BlockDisplayCreator instance ;
41+ private final BlockDisplayCreator plugin ;
4442 private final CustomBlockService service ;
4543
46- public BlockDisplayCreatorSpigotCommand (BlockDisplayCreator instance , CustomBlockService service ) {
47- this .instance = instance ;
44+ public BlockDisplayCreatorSpigotCommand (BlockDisplayCreator plugin , CustomBlockService service ) {
45+ this .plugin = plugin ;
4846 this .service = service ;
4947 }
5048
@@ -138,7 +136,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
138136 ChatUtil .sendMessage (sender , StringMessagesValue .COMMAND_CUSTOM_BLOCK_GIVE_NO_PLAYER );
139137 return true ;
140138 } else {
139+ CommandUtil .applyPlaceholdersForItem (customBlockItem , player );
140+ CommandUtil .applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , player );
141+
141142 ItemUtil .distributeItem (player , customBlockItem );
143+
142144 ChatUtil .sendMessage (player ,
143145 StringMessagesValue .COMMAND_CUSTOM_BLOCK_GIVE_PLAYER_RECEIVE
144146 .replace ("%customblock_name%" , arg3 )
@@ -149,8 +151,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
149151 switch (arg4 ) {
150152 case "@a" -> {
151153 for (Player recipient : Bukkit .getOnlinePlayers ()) {
152- applyPlaceholdersForItem (customBlockItem , recipient );
153- applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , recipient );
154+ CommandUtil .applyPlaceholdersForItem (customBlockItem , recipient );
155+ CommandUtil .applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , recipient );
156+
154157 ItemUtil .distributeItem (recipient , customBlockItem );
155158 }
156159 ChatUtil .sendMessage (sender , "&bYou have given the &l%s&ox%s&r&b block to all players" , arg3 , amount );
@@ -162,9 +165,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
162165 return true ;
163166 }
164167
165- applyPlaceholdersForItem (customBlockItem , player );
166- applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , player );
168+ CommandUtil .applyPlaceholdersForItem (customBlockItem , player );
169+ CommandUtil .applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , player );
170+
167171 ItemUtil .distributeItem (player , customBlockItem );
172+
168173 ChatUtil .sendMessage (sender , "&bYou have received the &l%s&ox%s&r&b block" , arg3 , amount );
169174 return true ;
170175 }
@@ -176,9 +181,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
176181 return true ;
177182 }
178183
179- applyPlaceholdersForItem (customBlockItem , randomPlayer );
180- applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , randomPlayer );
184+ CommandUtil .applyPlaceholdersForItem (customBlockItem , randomPlayer );
185+ CommandUtil .applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , randomPlayer );
186+
181187 ItemUtil .distributeItem (randomPlayer , customBlockItem );
188+
182189 ChatUtil .sendMessage (sender , "&bYou have given the &l%s&ox%s&r&b block to random player %s" , arg3 , amount , randomPlayer .getName ());
183190 return true ;
184191 }
@@ -189,10 +196,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
189196 }
190197
191198 Player nearestPlayer = TargetSelectorType .getNearestPlayer (player .getLocation (), player );
192- applyPlaceholdersForItem (customBlockItem , nearestPlayer );
193- applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , nearestPlayer );
199+
200+ CommandUtil .applyPlaceholdersForItem (customBlockItem , nearestPlayer );
201+ CommandUtil .applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , nearestPlayer );
194202
195203 ItemUtil .distributeItem (nearestPlayer , customBlockItem );
204+
196205 ChatUtil .sendMessage (sender , "&bYou have given the &l%s&ox%s&r&b block to nearest player %s" , arg3 , amount , nearestPlayer .getName ());
197206 return true ;
198207 }
@@ -204,9 +213,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
204213 return true ;
205214 }
206215
207- applyPlaceholdersForItem (customBlockItem , recipient );
208- applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , recipient );
216+ CommandUtil .applyPlaceholdersForItem (customBlockItem , recipient );
217+ CommandUtil .applyPlaceholdersForCommand (abstractCustomBlock , customBlockItem , recipient );
218+
209219 ItemUtil .distributeItem (recipient , customBlockItem );
220+
210221 ChatUtil .sendMessage (sender , "&bYou have given the &l%s&ox%s&r&b block to player %s" , arg3 , amount , recipient .getName ());
211222 return true ;
212223 }
@@ -490,10 +501,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
490501 }
491502
492503 if (arg2 == null ) {
493- instance .reloadConfig ();
504+ plugin .reloadConfig ();
494505 ChatUtil .sendMessage (sender , "&aConfig has been reloaded!" );
495506 } else {
496- this .instance .getCustomBlockService ().getStorage ().reload (arg2 );
507+ this .plugin .getCustomBlockService ().getStorage ().reload (arg2 );
497508 ChatUtil .sendMessage (sender , "&a%s block has been reloaded!" , arg2 );
498509 }
499510 }
@@ -742,62 +753,5 @@ private void eraseCbData(BoundingBox boundingBox, Player sender) {
742753 ChatUtil .sendMessage (sender , "&6Killed %d collision entities" , collisions .size ());
743754 ChatUtil .sendMessage (sender , "&6Cleared %d custom blocks" , blocksCount [0 ]);
744755 }
745-
746- public void applyPlaceholdersForItem (ItemStack item , Player player ) {
747- ItemMeta itemMeta = item .getItemMeta ();
748- Plugin placeholderApi = BlockDisplayCreator .getInstance ().getDependentPluginsManager ().getPlaceholderApi ();
749-
750- if (placeholderApi == null ) {
751- return ;
752- }
753-
754- itemMeta .setDisplayName (ChatUtil .setPlaceholders (player , itemMeta .getDisplayName (), placeholderApi ));
755- List <String > itemMetaLore = itemMeta .getLore ();
756- if (itemMetaLore != null ) {
757- List <String > lore = new ArrayList <>();
758- itemMetaLore .forEach (line -> lore .add (ChatUtil .setPlaceholders (player , line , placeholderApi )));
759- itemMeta .setLore (lore );
760- }
761-
762-
763- item .setItemMeta (itemMeta );
764- }
765-
766- public void applyPlaceholdersForCommand (AbstractCustomBlock abstractCustomBlock , ItemStack item , Player player ) {
767- Plugin placeholderApi = BlockDisplayCreator .getInstance ().getDependentPluginsManager ().getPlaceholderApi ();
768- if (placeholderApi == null ) {
769- return ;
770- }
771-
772- GroupSummoner <Display > displaySummoner = abstractCustomBlock .getDisplaySummoner ();
773-
774- if (displaySummoner instanceof AutomaticCommandDisplaySummoner displayCommandSummoner ) {
775- if (!displayCommandSummoner .isUsePlaceholder ()) {
776- return ;
777- }
778-
779-
780- CommandLine [] parsed = displayCommandSummoner .getCommands ()
781- .stream ()
782- .map (commandLine ->
783- {
784- String lineString = commandLine .toString ();
785- String base64Formatted = new PlayerSkinBase64Placeholder (player ).apply (lineString );
786-
787- return (CommandLine ) new MCCommandLine (ChatUtil .setPlaceholders (
788- player ,
789- base64Formatted ,
790- placeholderApi ));
791- }
792- ).toArray (CommandLine []::new );
793-
794- ItemMeta itemMeta = item .getItemMeta ();
795- PersistentData <CommandLine []> commandListPD = new PersistentData <>(itemMeta , TypeTokens .COMMAND_ARRAY );
796-
797- commandListPD .set (CustomBlockKey .DISPLAY_SPAWN_COMMAND , parsed );
798-
799- item .setItemMeta (itemMeta );
800- }
801- }
802756}
803757
0 commit comments