|
1 | 1 | package cn.clexus.targetTracker.managers; |
2 | 2 | import cn.clexus.targetTracker.TargetTracker; |
| 3 | +import cn.clexus.targetTracker.events.TrackStartEvent; |
| 4 | +import cn.clexus.targetTracker.events.TrackStopEvent; |
3 | 5 | import cn.clexus.targetTracker.utils.I18n; |
4 | 6 | import cn.clexus.targetTracker.utils.ParseUtil; |
5 | 7 | import com.github.retrooper.packetevents.protocol.world.Location; |
@@ -51,36 +53,42 @@ public int getTargetEntityId(Point point, Player player) { |
51 | 53 | return -1; |
52 | 54 | } |
53 | 55 | public boolean startTrack(Point point, Player player) { |
54 | | - if(activeTracks.containsKey(player.getUniqueId()+":"+point.getId())) { |
55 | | - return false; |
56 | | - } |
57 | | - Location playerLocation = new Location(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch()); |
58 | | - Location targetLocation = new Location( |
59 | | - point.getTarget().getLocation().getX(), |
60 | | - point.getTarget().getLocation().getY(), |
61 | | - point.getTarget().getLocation().getZ(), |
62 | | - 0, |
63 | | - 0 |
64 | | - ); |
65 | | - double initialDistance = point.getMark().getDistance(); |
66 | | - |
67 | | - int markEntityId = Bukkit.getUnsafe().nextEntityId(); |
68 | | - int targetEntityId = Bukkit.getUnsafe().nextEntityId(); |
69 | | - |
70 | | - sendSpawnPacket(player, markEntityId, playerLocation, point.getMark().getScale()); |
71 | | - sendSpawnPacket(player, targetEntityId, targetLocation, point.getTarget().getScale()); |
72 | | - |
73 | | - int distance = (int) player.getLocation().distance(point.getTarget().getLocation()); |
74 | | - sendTextChangePacket(player, markEntityId, point.getMark().getDisplay(), distance); |
75 | | - sendTextChangePacket(player, targetEntityId, point.getTarget().getDisplay(), distance); |
76 | | - |
77 | | - TrackTask task = new TrackTask(player, point, markEntityId, targetEntityId, point.getTarget().getLocation(), initialDistance); |
78 | | - task.runTaskTimer(TargetTracker.getInstance(), 0L, 1L); |
79 | | - activeTracks.put(player.getUniqueId()+":"+point.getId(), task); |
80 | | - return true; |
| 56 | + TrackStartEvent event = new TrackStartEvent(player, point); |
| 57 | + Bukkit.getPluginManager().callEvent(event); |
| 58 | + if(event.isCancelled()) { |
| 59 | + return false; |
| 60 | + } |
| 61 | + if(activeTracks.containsKey(player.getUniqueId()+":"+point.getId())) { |
| 62 | + return false; |
| 63 | + } |
| 64 | + Location playerLocation = new Location(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch()); |
| 65 | + Location targetLocation = new Location( |
| 66 | + point.getTarget().getLocation().getX(), |
| 67 | + point.getTarget().getLocation().getY(), |
| 68 | + point.getTarget().getLocation().getZ(), |
| 69 | + 0, |
| 70 | + 0 |
| 71 | + ); |
| 72 | + double initialDistance = point.getMark().getDistance(); |
| 73 | + int markEntityId = Bukkit.getUnsafe().nextEntityId(); |
| 74 | + int targetEntityId = Bukkit.getUnsafe().nextEntityId(); |
| 75 | + sendSpawnPacket(player, markEntityId, playerLocation, point.getMark().getScale()); |
| 76 | + sendSpawnPacket(player, targetEntityId, targetLocation, point.getTarget().getScale()); |
| 77 | + int distance = (int) player.getLocation().distance(point.getTarget().getLocation()); |
| 78 | + sendTextChangePacket(player, markEntityId, point.getMark().getDisplay(), distance); |
| 79 | + sendTextChangePacket(player, targetEntityId, point.getTarget().getDisplay(), distance); |
| 80 | + TrackTask task = new TrackTask(player, point, markEntityId, targetEntityId, point.getTarget().getLocation(), initialDistance); |
| 81 | + task.runTaskTimer(TargetTracker.getInstance(), 0L, 1L); |
| 82 | + activeTracks.put(player.getUniqueId()+":"+point.getId(), task); |
| 83 | + return true; |
81 | 84 | } |
82 | 85 |
|
83 | 86 | public boolean stopTrack(Player player, Point point, boolean trigger) { |
| 87 | + TrackStopEvent event = new TrackStopEvent(player, point, trigger); |
| 88 | + Bukkit.getPluginManager().callEvent(event); |
| 89 | + if(event.isCancelled()) { |
| 90 | + return false; |
| 91 | + } |
84 | 92 | TrackTask task = activeTracks.remove(player.getUniqueId()+":"+point.getId()); |
85 | 93 | if (task != null) { |
86 | 94 | task.cancel(); |
|
0 commit comments