Skip to content

Commit 98d59e7

Browse files
authored
Merge pull request #6 from CalebGitBritannia/DEV-LEGACY
Merged changes into master
2 parents 5693409 + 2edafe0 commit 98d59e7

File tree

10 files changed

+361
-231
lines changed

10 files changed

+361
-231
lines changed

src/main/java/calebcompass/calebcompass/CalebCompassCommand.java

Lines changed: 104 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
import calebcompass.calebcompass.SavePoints.SavePoint;
44
import 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;
67
import org.bukkit.Bukkit;
78
import org.bukkit.Location;
8-
import org.bukkit.entity.Player;
99
import org.bukkit.command.Command;
10-
import org.bukkit.command.CommandSender;
1110
import 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;
1513
import org.bukkit.util.Vector;
1614

1715
import java.util.ArrayList;
18-
import java.util.prefs.PreferenceChangeEvent;
1916

2017
public 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
}
Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,17 @@
11
package calebcompass.calebcompass;
22

3-
import calebcompass.calebcompass.SavePoints.SavePoint;
4-
import org.bukkit.Bukkit;
5-
import org.bukkit.Location;
6-
import org.bukkit.util.Vector;
7-
import org.bukkit.boss.BossBar;
3+
import calebcompass.calebcompass.util.CompassConstructor;
84
import org.bukkit.entity.Player;
9-
import org.bukkit.event.Listener;
105
import org.bukkit.event.EventHandler;
6+
import org.bukkit.event.Listener;
117
import org.bukkit.event.player.PlayerMoveEvent;
128

13-
import calebcompass.calebcompass.util.*;
14-
159
public class CompassMoveEvent implements Listener {
16-
1710
@EventHandler
18-
public void onPlayerMove(PlayerMoveEvent e) {
11+
public void onMove(PlayerMoveEvent e) {
1912
Player player = e.getPlayer();
20-
Location playerLoc = player.getLocation();
21-
CompassLocation location = CompassInstance.getInstance().getCompassLocation(player);
22-
BossBar bar = CompassInstance.getInstance().getBarFromPlayer(player);
23-
24-
int yaw = Math.round((playerLoc.getYaw() + 360) / 9);
25-
if (bar == null) {
26-
bar = Bukkit.createBossBar(MessageUtil.getMessage(yaw, 365, null, null), Util.getBarColor(), Util.getBarStyle());
27-
bar.addPlayer(player);
28-
CompassInstance.getInstance().addBar(bar);
29-
}
30-
31-
bar.setVisible(CompassInstance.getInstance().isCompassVisible(player));
32-
bar.setColor(Util.getBarColor());
33-
bar.setStyle(Util.getBarStyle());
34-
35-
if (location != null && location.isTracking() && location.getTarget().getWorld().equals(player.getWorld())) {
36-
double dist = location.getOrigin().distanceSquared(location.getTarget());
37-
double newDist = playerLoc.distanceSquared(location.getTarget());
38-
if (newDist > dist) location.setOrigin(playerLoc);
39-
40-
double travel = newDist / dist;
41-
if (travel >= 1F) travel = 1F;
42-
bar.setProgress(1F - travel);
43-
44-
if (checkCoords(playerLoc, location.getTarget())) {
45-
bar.setTitle(MessageUtil.getMessage(yaw, 500, location.getActivePoints(), player.getLocation()));
46-
return;
47-
}
48-
// our target location (Point B)
49-
Vector target = location.getTarget().toVector();
50-
// set the origin's direction to be the direction vector between point A and B.
51-
playerLoc.setDirection(target.subtract(playerLoc.toVector()));
52-
float playerYaw = playerLoc.getYaw();
53-
bar.setTitle(MessageUtil.getMessage(yaw, Math.round(playerYaw / 9), location.getActivePoints(), playerLoc));
54-
return;
55-
} else if (location != null) {
56-
bar.setTitle(MessageUtil.getMessage(yaw, 600, location.getActivePoints(), playerLoc));
57-
bar.setProgress(1F);
58-
return;
59-
}
60-
61-
bar.setTitle(MessageUtil.getMessage(yaw, 500, null, null));
62-
bar.setProgress(1F);
63-
}
64-
65-
private boolean checkCoords(Location loc1, Location loc2) {
66-
return loc1.getX() == loc2.getX() && loc1.getZ() == loc2.getZ();
13+
CompassConstructor compass = new CompassConstructor(player);
14+
compass.updateCompass();
6715
}
6816

6917
}

src/main/java/calebcompass/calebcompass/SavePoints/SavePoint.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package calebcompass.calebcompass.SavePoints;
22

3-
import calebcompass.calebcompass.util.CompassInstance;
4-
import calebcompass.calebcompass.util.ConfigManager;
3+
import calebcompass.calebcompass.util.MessageUtil;
54
import org.bukkit.Location;
65

76
public class SavePoint {
87

98
private Location loc1;
109
private String symbol;
10+
private String symbolHov;
1111
private String name;
1212

13-
public SavePoint(Location loc1, String name, String symbol) {
13+
public SavePoint(Location loc1, String name, String symbol, String hov) {
1414
this.loc1 = loc1;
15-
this.symbol = "§c !!! ";
15+
this.symbol = "&c&l !!! ";
16+
this.symbolHov = "&b&l !!! ";
1617
this.name = name;
1718
if (symbol != null)this.symbol = symbol;
19+
if (hov != null) this.symbolHov = hov;
1820
}
1921

2022
public Location getLoc1() {
@@ -26,7 +28,11 @@ public void setLoc1(Location loc1) {
2628
}
2729

2830
public String getSymbol() {
29-
return symbol;
31+
return MessageUtil.colourise(symbol);
32+
}
33+
34+
public String getSymbolHov() {
35+
return MessageUtil.colourise(symbolHov);
3036
}
3137

3238
public void savePoint() {

0 commit comments

Comments
 (0)