22
33import calebcompass .calebcompass .SavePoints .SavePoint ;
44import calebcompass .calebcompass .SavePoints .SavePointConfig ;
5- import com .sun .corba .se .impl .io .TypeMismatchException ;
5+ import calebcompass .calebcompass .util .CompassInstance ;
6+ import calebcompass .calebcompass .util .CompassLocation ;
67import org .bukkit .Bukkit ;
78import org .bukkit .Location ;
8- import org .bukkit .entity .Player ;
99import org .bukkit .command .Command ;
10- import org .bukkit .command .CommandSender ;
1110import org .bukkit .command .CommandExecutor ;
12-
13- import calebcompass .calebcompass .util .CompassInstance ;
14- import calebcompass .calebcompass .util .CompassLocation ;
11+ import org .bukkit .command .CommandSender ;
12+ import org .bukkit .entity .Player ;
1513import org .bukkit .util .Vector ;
1614
1715import java .util .ArrayList ;
18- import java .util .prefs .PreferenceChangeEvent ;
1916
2017public class CalebCompassCommand implements CommandExecutor {
2118
@@ -24,17 +21,35 @@ public class CalebCompassCommand implements CommandExecutor {
2421 @ Override
2522 public boolean onCommand (CommandSender sender , Command command , String label , String [] args ) {
2623 // help
27- if (args .length >= 1 && args [0 ].equalsIgnoreCase ("help" )) {
28- sender .sendMessage (PREFIX + "List of commands :" );
29- sender .sendMessage ("§4/calebcompass track x y z§r Create a new waypoint to follow " );
30- sender .sendMessage ("§4/calebcompass clear§r Clear your current waypoint " );
31- sender .sendMessage ("§4/calebcompass hide§r Hide the compass" );
32- sender .sendMessage ("§4/calebcompass show§r Show the compass" );
24+ if (( args .length == 1 || ( args . length >= 1 && args [ 1 ]. equals ( "1" ))) && args [0 ].equalsIgnoreCase ("help" )) {
25+ sender .sendMessage (PREFIX + "Commands, page 1/2 :" );
26+ sender .sendMessage ("§4/calebcompass track O:(player) x y z§r Track a set of coordinates on the compass " );
27+ sender .sendMessage ("§4/calebcompass clear O:(player) §r Clear current track " );
28+ sender .sendMessage ("§4/calebcompass hide O:(player) §r Hide the compass" );
29+ sender .sendMessage ("§4/calebcompass show O:§(player) §r Show the compass" );
3330 sender .sendMessage ("§4/calebcompass save (name)§r Save a new waypoint for the compass" );
34- sender .sendMessage ("§4/calebcompass toggle (waypoint) (true/false)§r Toggle viewing a waypoint " );
31+ sender .sendMessage ("§4Any arguments marked with O: are optional " );
3532 return true ;
3633 }
3734
35+ if (args .length >=1 && args [0 ].equalsIgnoreCase ("help" )) {
36+ try {
37+ switch (Integer .parseInt (args [1 ])) {
38+ case (2 ):
39+ sender .sendMessage (PREFIX + "Commands, page 2/2" );
40+ sender .sendMessage ("§4/calebcompass remove (waypoint)§r Remove a waypoint" );
41+ sender .sendMessage ("§4/calebcompass toggle O:(player) (waypoint) (enable/disable)§r Toggle viewing a waypoint" );
42+ sender .sendMessage ("§4/calebcompass focus§r Focus your quest marker on a specific waypoint" );
43+ sender .sendMessage ("§4/calebcompass waypoints (page)§r List all active waypoints enabled for you" );
44+ sender .sendMessage ("§4Any arguments marked with O: are optional" );
45+ return true ;
46+ }
47+ } catch (Exception e ) {
48+ }
49+ sender .sendMessage (PREFIX + "Page not found, try /calebcompass help" );
50+ return true ;
51+ }
52+
3853 // track
3954 if (args .length == 4 && args [0 ].equalsIgnoreCase ("track" )) {
4055 if (!(sender instanceof Player )) {
@@ -48,6 +63,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4863 return true ;
4964 }
5065
66+
5167 try {
5268 CompassLocation location = CompassInstance .getInstance ().getCompassLocation (player );
5369 if (location == null ) CompassInstance .getInstance ().addCompassLocation (player , player .getLocation (), new Location (player .getWorld (), Integer .parseInt (args [1 ]), Integer .parseInt (args [3 ]), Integer .parseInt (args [3 ])));
@@ -134,6 +150,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
134150 }
135151
136152 CalebCompass .getConfigManager ().setup ();
153+ SavePointConfig .getInstance ().load ();
137154 CompassInstance .getInstance ().load ();
138155 sender .sendMessage (PREFIX + "Config has been loaded into the game" );
139156 return true ;
@@ -203,25 +220,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
203220 return true ;
204221 }
205222
206- // hide
207- if (args .length >= 2 && args [0 ].equalsIgnoreCase ("hide" )) {
208- if (sender instanceof Player && !CompassInstance .hasPerm ((Player ) sender , "view.hide.other" )) {
209- sender .sendMessage (PREFIX + "You do not have permission for this command!" );
210- return true ;
211- }
212-
213- Player player = Bukkit .getPlayer (args [1 ]);
214- if (player == null ) {
215- sender .sendMessage (PREFIX + "Player not found!" );
216- return true ;
217- }
218-
219- CompassInstance .getInstance ().setPlayerVisible (player , false );
220- sender .sendMessage (PREFIX + "Hid compass for player " + args [1 ]);
221- CompassInstance .getInstance ().saveData ();
222- return true ;
223- }
224-
225223 // save point
226224 if (args .length >= 2 && args [0 ].equalsIgnoreCase ("save" ) && sender instanceof Player ) {
227225 if (!CompassInstance .hasPerm ((Player ) sender , "point.save" )) {
@@ -233,7 +231,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
233231 sender .sendMessage (PREFIX + "A point with this name already exists" );
234232 return true ;
235233 }
236- SavePoint newSave = new SavePoint (((Player ) sender ).getLocation (), args [1 ], " §c !!! " );
234+ SavePoint newSave = new SavePoint (((Player ) sender ).getLocation (), args [1 ], "&c&l !!! " , "&b&l !!! " );
237235 newSave .savePoint ();
238236 sender .sendMessage (PREFIX + "Saved point" );
239237 SavePointConfig .getInstance ().saveData ();
@@ -254,6 +252,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
254252 SavePointConfig .getInstance ().removeSave (SavePointConfig .getInstance ().getPointFromName (args [1 ]));
255253 sender .sendMessage (PREFIX + "Removed point" );
256254 SavePointConfig .getInstance ().saveData ();
255+ CompassInstance .getInstance ().load ();
257256 return true ;
258257 }
259258
@@ -284,7 +283,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
284283 SavePointConfig .getInstance ().togglePlayerPoint (player .getUniqueId (), args [1 ], toggleTo );
285284 if (toggleTo ) CompassInstance .getInstance ().addSavePoint (player .getUniqueId (), SavePointConfig .getInstance ().getPointFromName (args [2 ]));
286285 if (!toggleTo ) CompassInstance .getInstance ().removeSavePoint (player .getUniqueId (), SavePointConfig .getInstance ().getPointFromName (args [2 ]));
287- sender .sendMessage (PREFIX + "Toggled point " + args [1 ]);
286+ String status = "on" ;
287+ if (!toggleTo ) status = "off" ;
288+ sender .sendMessage (PREFIX + "Toggled point " + args [1 ] + " " + status );
288289 CompassInstance .getInstance ().saveData ();
289290 SavePointConfig .getInstance ().saveData ();
290291 CompassInstance .getInstance ().load ();
@@ -331,43 +332,62 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
331332
332333 // focus point
333334 if (args .length == 1 && args [0 ].equalsIgnoreCase ("focus" ) && sender instanceof Player ) {
335+
334336 SavePointConfig .getInstance ().load ();
335337 if (!CompassInstance .hasPerm ((Player ) sender , "point.focus" )) {
336338 sender .sendMessage (PREFIX + "You do not have permission for this command!" );
337339 return true ;
338340 }
339-
340341 Player player = (Player ) sender ;
341- Location playerLoc = player .getLocation ();
342- int yaw = Math .round ((playerLoc .getYaw () + 360 ) / 9 );
343342
344- if (yaw >= 40 ) yaw -=40 ;
343+ SavePoint point = getSavePointAtLoc (player );
344+ if (point == null ) {
345+ player .sendMessage (PREFIX + "No point found, please look at a waypoint!" );
346+ return true ;
347+ }
345348
349+ CompassInstance .getInstance ().getCompassLocation (player ).setTarget (point .getLoc1 ());
350+ CompassInstance .getInstance ().getCompassLocation (player ).setOrigin (player .getLocation ());
351+ CompassInstance .getInstance ().getCompassLocation (player ).setTracking (true );
352+ sender .sendMessage (PREFIX + "Changed focus" );
353+ CompassInstance .getInstance ().saveData ();
354+ return true ;
355+ }
346356
347- if (CompassInstance .getInstance ().getCompassLocation (player ) == null ) {
348- sender .sendMessage (PREFIX + "No point found" );
357+ //list waypoints
358+ if (args .length >=1 && args [0 ].equalsIgnoreCase ("waypoints" ) && sender instanceof Player ) {
359+ if (!CompassInstance .hasPerm ((Player ) sender , "point.list" )) {
360+ sender .sendMessage (PREFIX + "You do not have permission for this command!" );
349361 return true ;
350362 }
351-
352- ArrayList <SavePoint > extraPoints = CompassInstance .getInstance ().getCompassLocation (player ).getActivePoints ();
353- for (SavePoint cur : extraPoints ) {
354- if (!cur .getLoc1 ().getWorld ().equals (player .getLocation ().getWorld ())) continue ;
355- // our target location (Point B)
356- Vector target = cur .getLoc1 ().toVector ();
357- // set the origin's direction to be the direction vector between point A and B.
358- playerLoc .setDirection (target .subtract (playerLoc .toVector ()));
359- float playerYaw = playerLoc .getYaw ();
360- int goDir2 = Math .round (playerYaw / 9 );
361- if (goDir2 == yaw ) {
362- CompassInstance .getInstance ().getCompassLocation (player ).setTarget (cur .getLoc1 ());
363- CompassInstance .getInstance ().getCompassLocation (player ).setOrigin (playerLoc );
364- CompassInstance .getInstance ().getCompassLocation (player ).setTracking (true );
365- sender .sendMessage (PREFIX + "Changed focus" );
366- CompassInstance .getInstance ().saveData ();
367- return true ;
363+ if (args .length == 1 || args [1 ].equals ("1" )) {
364+ sender .sendMessage (PREFIX + "Current active points page 1:" );
365+ CompassLocation loc = CompassInstance .getInstance ().getCompassLocation ((Player ) sender );
366+ if (loc == null || loc .getActivePoints () == null ) return true ;
367+ for (int i = 0 ; i < 5 ; i ++) {
368+ try {
369+ SavePoint currentPoint = loc .getActivePoints ().get (i );
370+ if (currentPoint != null ) sender .sendMessage ("§e" + currentPoint .getName () + " §eX:" + currentPoint .getLoc1 ().getBlockX () + " §eY:" + currentPoint .getLoc1 ().getBlockY () + " §eZ:" + currentPoint .getLoc1 ().getBlockZ () + " §eSymbol: " + currentPoint .getSymbol ());
371+ } catch (Exception e ) { }
368372 }
373+ return true ;
369374 }
370- sender .sendMessage (PREFIX + "No point found to focus" );
375+ try {
376+ int page = Integer .parseInt (args [1 ]);
377+ if (page >=2 ) {
378+ sender .sendMessage (PREFIX + "Current active points page " + page +":" );
379+ CompassLocation loc = CompassInstance .getInstance ().getCompassLocation ((Player ) sender );
380+ if (loc == null || loc .getActivePoints () == null ) return true ;
381+ for (int i = (page * 5 ) - 5 ; i < (page * 5 ); i ++) {
382+ try {
383+ SavePoint currentPoint = loc .getActivePoints ().get (i );
384+ if (currentPoint != null ) sender .sendMessage ("§e" + currentPoint .getName () + " §eX:" + currentPoint .getLoc1 ().getBlockX () + " §eY:" + currentPoint .getLoc1 ().getBlockY () + " §eZ:" + currentPoint .getLoc1 ().getBlockZ () + " §eSymbol: " + currentPoint .getSymbol ());
385+ } catch (Exception e ) { }
386+ }
387+ return true ;
388+ }
389+ } catch (Exception e ) { }
390+ sender .sendMessage (PREFIX + "Please enter a valid page number!" );
371391 return true ;
372392 }
373393
@@ -377,4 +397,29 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
377397 return true ;
378398 }
379399
400+ public SavePoint getSavePointAtLoc (Player player ) {
401+ Location playerLoc = player .getLocation ();
402+ int yaw = Math .round ((playerLoc .getYaw () + 360 ) / 9 );
403+
404+ if (yaw >= 40 ) yaw -=40 ;
405+
406+
407+ if (CompassInstance .getInstance ().getCompassLocation (player ) == null ) {
408+ return null ;
409+ }
410+
411+ ArrayList <SavePoint > extraPoints = CompassInstance .getInstance ().getCompassLocation (player ).getActivePoints ();
412+ for (SavePoint cur : extraPoints ) {
413+ if (!cur .getLoc1 ().getWorld ().equals (player .getLocation ().getWorld ())) continue ;
414+ Vector target = cur .getLoc1 ().toVector ();
415+ playerLoc .setDirection (target .subtract (playerLoc .toVector ()));
416+ float playerYaw = playerLoc .getYaw ();
417+ int goDir2 = Math .round (playerYaw / 9 );
418+ if (goDir2 == yaw ) {
419+ return cur ;
420+ }
421+ }
422+ return null ;
423+ }
424+
380425}
0 commit comments