22
33import goldenshadow .displayentityeditor .DisplayEntityEditor ;
44import goldenshadow .displayentityeditor .Utilities ;
5+ import goldenshadow .displayentityeditor .conversation .InputData ;
6+ import goldenshadow .displayentityeditor .conversation .InputManager ;
7+ import goldenshadow .displayentityeditor .enums .InputType ;
58import org .bukkit .ChatColor ;
69import org .bukkit .command .CommandExecutor ;
710import org .bukkit .command .CommandSender ;
11+ import org .bukkit .entity .BlockDisplay ;
12+ import org .bukkit .entity .Display ;
813import org .bukkit .entity .Player ;
14+ import org .bukkit .entity .TextDisplay ;
915import org .bukkit .inventory .ItemStack ;
1016import org .bukkit .persistence .PersistentDataType ;
1117import org .jetbrains .annotations .NotNull ;
@@ -30,22 +36,157 @@ public class Command implements CommandExecutor {
3036 @ Override
3137 public boolean onCommand (@ NotNull CommandSender sender ,@ NotNull org .bukkit .command .Command command ,@ NotNull String label , String [] args ) {
3238 if (sender instanceof Player p ) {
33- if (savedInventories .containsKey (p .getUniqueId ())) {
34- returnInventory (p );
35- p .sendMessage (Utilities .getInfoMessageFormat ("Your inventory has been returned to you!" ));
36- savedInventories .remove (p .getUniqueId ());
39+ if (args .length == 0 ) {
40+ if (savedInventories .containsKey (p .getUniqueId ())) {
41+ returnInventory (p );
42+ p .sendMessage (Utilities .getInfoMessageFormat ("Your inventory has been returned to you!" ));
43+ savedInventories .remove (p .getUniqueId ());
44+ return true ;
45+ }
46+ saveInventory (p );
47+ ItemStack [] array = DisplayEntityEditor .inventoryFactory .getInventoryArray ();
48+ for (int i = 0 ; i < array .length ; i ++) {
49+ p .getInventory ().setItem (i , array [i ]);
50+ }
51+ if (!p .getPersistentDataContainer ().has (DisplayEntityEditor .toolPrecisionKey , PersistentDataType .DOUBLE )) {
52+ p .getPersistentDataContainer ().set (DisplayEntityEditor .toolPrecisionKey , PersistentDataType .DOUBLE , 1d );
53+ }
54+ p .sendMessage (Utilities .getInfoMessageFormat ("Given display entity tools. Left click to cycle through the tools." ));
55+ p .sendMessage (ChatColor .DARK_AQUA + "[DEE] " + ChatColor .BLUE + "Run this command again to have your inventory returned!" );
3756 return true ;
3857 }
39- saveInventory (p );
40- ItemStack [] array = DisplayEntityEditor .inventoryFactory .getInventoryArray ();
41- for (int i = 0 ; i < array .length ; i ++) {
42- p .getInventory ().setItem (i , array [i ]);
58+ if (args .length == 1 ) {
59+ if (args [0 ].equalsIgnoreCase ("reload" )) {
60+ DisplayEntityEditor .getPlugin ().reloadConfig ();
61+ DisplayEntityEditor .alternateTextInput = DisplayEntityEditor .getPlugin ().getConfig ().getBoolean ("alternate-text-input" );
62+ p .sendMessage (Utilities .getInfoMessageFormat ("Config reloaded!" ));
63+ return true ;
64+ }
4365 }
44- if (!p .getPersistentDataContainer ().has (DisplayEntityEditor .toolPrecisionKey , PersistentDataType .DOUBLE )) {
45- p .getPersistentDataContainer ().set (DisplayEntityEditor .toolPrecisionKey , PersistentDataType .DOUBLE , 1d );
66+
67+ if (args .length > 2 ) {
68+ if (DisplayEntityEditor .alternateTextInput ) {
69+ if (args [0 ].equalsIgnoreCase ("edit" )) {
70+ String input = collectArgsToString (args );
71+ Display display = Utilities .getNearestDisplayEntity (p .getLocation (), true );
72+ if (display == null ) {
73+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked display entity within 5 blocks!" ));
74+ return true ;
75+ }
76+ if (args [1 ].equalsIgnoreCase ("name" )) {
77+ InputManager .successfulTextInput (new InputData (display , InputType .NAME , null ), input , p );
78+ return true ;
79+ }
80+ if (args [1 ].equalsIgnoreCase ("background_color" )) {
81+ if (display instanceof TextDisplay ) {
82+ InputManager .successfulTextInput (new InputData (display , InputType .BACKGROUND_COLOR , null ), input , p );
83+ return true ;
84+ }
85+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked text display entity within 5 blocks!" ));
86+ return true ;
87+ }
88+ if (args [1 ].equalsIgnoreCase ("text" )) {
89+ if (display instanceof TextDisplay ) {
90+ InputManager .successfulTextInput (new InputData (display , InputType .TEXT , null ), input , p );
91+ return true ;
92+ }
93+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked text display entity within 5 blocks!" ));
94+ return true ;
95+ }
96+ if (args [1 ].equalsIgnoreCase ("text_append" )) {
97+ if (display instanceof TextDisplay ) {
98+ InputManager .successfulTextInput (new InputData (display , InputType .TEXT_APPEND , null ), input , p );
99+ return true ;
100+ }
101+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked text display entity within 5 blocks!" ));
102+ return true ;
103+ }
104+ if (args [1 ].equalsIgnoreCase ("glow_color" )) {
105+ if (!(display instanceof TextDisplay )) {
106+ InputManager .successfulTextInput (new InputData (display , InputType .GLOW_COLOR , null ), input , p );
107+ return true ;
108+ }
109+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked block/item display entity within 5 blocks!" ));
110+ return true ;
111+ }
112+ if (args [1 ].equalsIgnoreCase ("block_state" )) {
113+ if (display instanceof BlockDisplay ) {
114+ InputManager .successfulTextInput (new InputData (display , InputType .BLOCK_STATE , ((BlockDisplay ) display ).getBlock ().getMaterial ()), input , p );
115+ return true ;
116+ }
117+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked block display entity within 5 blocks!" ));
118+ return true ;
119+ }
120+ if (args [1 ].equalsIgnoreCase ("view_range" )) {
121+ if (InputManager .isFloat (input )) {
122+ InputManager .successfulFloatInput (new InputData (display , InputType .VIEW_RANGE , null ), Float .parseFloat (input ), p );
123+ return true ;
124+ }
125+ }
126+ if (args [1 ].equalsIgnoreCase ("display_height" )) {
127+ if (InputManager .isFloat (input )) {
128+ InputManager .successfulFloatInput (new InputData (display , InputType .DISPLAY_HEIGHT , null ), Float .parseFloat (input ), p );
129+ return true ;
130+ }
131+ }
132+ if (args [1 ].equalsIgnoreCase ("display_width" )) {
133+ if (InputManager .isFloat (input )) {
134+ InputManager .successfulFloatInput (new InputData (display , InputType .DISPLAY_WIDTH , null ), Float .parseFloat (input ), p );
135+ return true ;
136+ }
137+ }
138+ if (args [1 ].equalsIgnoreCase ("shadow_radius" )) {
139+ if (InputManager .isFloat (input )) {
140+ InputManager .successfulFloatInput (new InputData (display , InputType .SHADOW_RADIUS , null ), Float .parseFloat (input ), p );
141+ return true ;
142+ }
143+ }
144+ if (args [1 ].equalsIgnoreCase ("shadow_strength" )) {
145+ if (InputManager .isFloat (input )) {
146+ float f = Float .parseFloat (input );
147+ if (0 <= f && f <= 1 ) {
148+ InputManager .successfulFloatInput (new InputData (display , InputType .SHADOW_STRENGTH , null ), Float .parseFloat (input ), p );
149+ return true ;
150+ }
151+ p .sendMessage (Utilities .getErrorMessageFormat ("Value should be between 0 and 1!" ));
152+ return true ;
153+ }
154+ }
155+ if (args [1 ].equalsIgnoreCase ("text_opacity" )) {
156+ if (display instanceof TextDisplay ) {
157+ if (InputManager .isByte (input )) {
158+ InputManager .successfulByteInput (new InputData (display , InputType .TEXT_OPACITY , null ), Integer .parseInt (input ), p );
159+ return true ;
160+ }
161+ }
162+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked text display entity within 5 blocks!" ));
163+ return true ;
164+ }
165+ if (args [1 ].equalsIgnoreCase ("background_opacity" )) {
166+ if (display instanceof TextDisplay ) {
167+ if (InputManager .isByte (input )) {
168+ InputManager .successfulByteInput (new InputData (display , InputType .BACKGROUND_OPACITY , null ), Integer .parseInt (input ), p );
169+ return true ;
170+ }
171+ }
172+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked text display entity within 5 blocks!" ));
173+ return true ;
174+ }
175+ if (args [1 ].equalsIgnoreCase ("line_width" )) {
176+ if (display instanceof TextDisplay ) {
177+ if (InputManager .isInteger (input )) {
178+ InputManager .successfulIntegerInput (new InputData (display , InputType .LINE_WIDTH , null ), Integer .parseInt (input ), p );
179+ return true ;
180+ }
181+ }
182+ p .sendMessage (Utilities .getErrorMessageFormat ("There is no unlocked text display entity within 5 blocks!" ));
183+ return true ;
184+ }
185+ }
186+ }
187+ return true ;
46188 }
47- p .sendMessage (Utilities .getInfoMessageFormat ("Given display entity tools. Left click to cycle through the tools." ));
48- p .sendMessage (ChatColor .DARK_AQUA + "[DEE] " + ChatColor .BLUE + "Run this command again to have your inventory returned!" );
189+ p .sendMessage (Utilities .getErrorMessageFormat ("Invalid arguments!" ));
49190 return true ;
50191 }
51192 sender .sendMessage ("This command must be run by a player!" );
@@ -73,4 +214,14 @@ private static void returnInventory(Player player) {
73214 player .getInventory ().setItem (i , saved [i ]);
74215 }
75216 }
217+
218+ private static String collectArgsToString (String [] args ) {
219+ StringBuilder s = new StringBuilder ();
220+ for (int i = 2 ; i < args .length ; i ++) {
221+ if (i != 2 ) s .append (" " );
222+ s .append (args [i ]);
223+ }
224+ return s .toString ();
225+ }
226+
76227}
0 commit comments