2828import org .bukkit .command .CommandSender ;
2929import org .bukkit .command .TabExecutor ;
3030import org .bukkit .entity .Player ;
31+ import org .bukkit .Nameable ;
3132import org .bukkit .inventory .InventoryHolder ;
3233import org .bukkit .plugin .Plugin ;
3334import org .jetbrains .annotations .NotNull ;
@@ -54,8 +55,7 @@ public boolean onCommand(
5455 @ NotNull CommandSender sender ,
5556 @ NotNull Command command ,
5657 @ NotNull String label ,
57- @ NotNull String [] args
58- ) {
58+ @ NotNull String [] args ) {
5959 if (!(sender instanceof Player senderPlayer )) {
6060 lang .sendMessage (sender , "messages.error.consoleUnsupported" );
6161 return true ;
@@ -72,8 +72,7 @@ public boolean onCommand(
7272 lang .sendMessage (
7373 sender ,
7474 "messages.error.invalidMaterial" ,
75- new Replacement ("%target%" , args [0 ])
76- );
75+ new Replacement ("%target%" , args [0 ]));
7776 return false ;
7877 }
7978
@@ -95,6 +94,7 @@ public boolean onCommand(
9594 World world = senderPlayer .getWorld ();
9695 Chunk centerChunk = senderPlayer .getLocation ().getChunk ();
9796 StringBuilder locations = new StringBuilder ();
97+ locations .append ("\n " );
9898
9999 for (int dX = -radius ; dX <= radius ; ++dX ) {
100100 for (int dZ = -radius ; dZ <= radius ; ++dZ ) {
@@ -109,31 +109,32 @@ public boolean onCommand(
109109 if (!SearchHelper .findMatch (holder .getInventory (), itemStack -> itemStack .getType () == material )) {
110110 continue ;
111111 }
112- locations .append (holder .getInventory ().getType ().name ().toLowerCase (Locale .ENGLISH )).append (" (" )
113- .append (tileEntity .getX ()).append (',' ).append (tileEntity .getY ()).append (',' )
114- .append (tileEntity .getZ ()).append ("), " );
112+ locations .append (holder .getInventory ().getType ().name ().toLowerCase (Locale .ENGLISH )).append (": " );
113+ if (holder instanceof Nameable named ) {
114+ String customName = named .getCustomName ();
115+ if (customName != null ) {
116+ locations .append (customName .toLowerCase (Locale .ENGLISH ).strip ()).append (" - " );
117+ }
118+ }
119+ locations .append (" (" ).append (tileEntity .getX ()).append (',' ).append (tileEntity .getY ()).append (',' )
120+ .append (tileEntity .getZ ()).append (")\n " );
115121 }
116122 }
117123 }
118124
119- // Matches found, delete trailing comma and space
120- if (!locations .isEmpty ()) {
121- locations .delete (locations .length () - 2 , locations .length ());
122- } else {
125+ if (locations .length () < 2 ) {
123126 lang .sendMessage (
124127 sender ,
125128 "messages.info.container.noMatches" ,
126- new Replacement ("%target%" , material .name ())
127- );
129+ new Replacement ("%target%" , material .name ()));
128130 return true ;
129131 }
130132
131133 lang .sendMessage (
132134 sender ,
133135 "messages.info.container.matches" ,
134136 new Replacement ("%target%" , material .name ()),
135- new Replacement ("%detail%" , locations .toString ())
136- );
137+ new Replacement ("%detail%" , locations .toString ()));
137138 return true ;
138139 }
139140
@@ -142,8 +143,7 @@ public List<String> onTabComplete(
142143 @ NotNull CommandSender sender ,
143144 @ NotNull Command command ,
144145 @ NotNull String label ,
145- String [] args
146- ) {
146+ String [] args ) {
147147 if (args .length < 1 || args .length > 2 || !command .testPermissionSilent (sender )) {
148148 return Collections .emptyList ();
149149 }
0 commit comments