38
38
39
39
import java .util .HashSet ;
40
40
import java .util .Locale ;
41
+ import java .util .Objects ;
41
42
42
43
public class EventListener implements Listener {
43
44
44
45
private static final double MAX_RAYTRACE_DISTANCE = 60D ;
45
46
46
- /*
47
- Returns whether to cancel an action based on the location data and flags
48
- */
47
+ // Returns whether to cancel an action based on the location data and flags
49
48
public static boolean cancelPlayerAction (Player player , Location location , ActionType actionType , boolean sendMessage ) {
50
49
ClaimCache claimCache = HuskTowns .getClaimCache ();
51
50
PlayerCache playerCache = HuskTowns .getPlayerCache ();
@@ -59,7 +58,7 @@ public static boolean cancelPlayerAction(Player player, Location location, Actio
59
58
return true ;
60
59
}
61
60
62
- ClaimedChunk chunk = claimCache .getChunkAt (location .getChunk ().getX (), location .getChunk ().getZ (), location .getWorld ().getName ());
61
+ ClaimedChunk chunk = claimCache .getChunkAt (location .getChunk ().getX (), location .getChunk ().getZ (), Objects . requireNonNull ( location .getWorld () ).getName ());
63
62
if (chunk != null ) {
64
63
switch (AccessManager .getPlayerAccess (player , actionType , chunk , true )) {
65
64
case CANNOT_PERFORM_ACTION_ADMIN_CLAIM :
@@ -156,9 +155,9 @@ private static boolean areChunksInSameTown(Location location1, Location location
156
155
}
157
156
158
157
ClaimedChunk chunk1 = claimCache .getChunkAt (location1 .getChunk ().getX (),
159
- location1 .getChunk ().getZ (), location1 .getWorld ().getName ());
158
+ location1 .getChunk ().getZ (), Objects . requireNonNull ( location1 .getWorld () ).getName ());
160
159
ClaimedChunk chunk2 = claimCache .getChunkAt (location2 .getChunk ().getX (),
161
- location2 .getChunk ().getZ (), location2 .getWorld ().getName ());
160
+ location2 .getChunk ().getZ (), Objects . requireNonNull ( location2 .getWorld () ).getName ());
162
161
163
162
String chunk1Town = "Wilderness" ;
164
163
String chunk2Town = "Wilderness" ;
@@ -191,9 +190,14 @@ public void onPlayerJoin(PlayerJoinEvent e) {
191
190
@ EventHandler
192
191
public void onPlayerMove (PlayerMoveEvent e ) {
193
192
Player player = e .getPlayer ();
193
+ final Location toLocation = e .getTo ();
194
+ final Location fromLocation = e .getFrom ();
195
+ if (toLocation == null ) {
196
+ return ;
197
+ }
194
198
195
199
// Check when a player changes chunk
196
- if (!e . getFrom (). getChunk ().equals (e . getTo () .getChunk ())) {
200
+ if (!fromLocation . getChunk ().equals (toLocation .getChunk ())) {
197
201
final ClaimCache claimCache = HuskTowns .getClaimCache ();
198
202
final TownDataCache messageCache = HuskTowns .getTownDataCache ();
199
203
if (!claimCache .hasLoaded ()) {
@@ -203,26 +207,23 @@ public void onPlayerMove(PlayerMoveEvent e) {
203
207
return ;
204
208
}
205
209
206
- Location toLocation = e .getTo ();
207
- Location fromLocation = e .getFrom ();
208
-
209
210
ClaimedChunk toClaimedChunk = claimCache .getChunkAt (toLocation .getChunk ().getX (),
210
- toLocation .getChunk ().getZ (), toLocation .getWorld ().getName ());
211
+ toLocation .getChunk ().getZ (), Objects . requireNonNull ( toLocation .getWorld () ).getName ());
211
212
ClaimedChunk fromClaimedChunk = claimCache .getChunkAt (fromLocation .getChunk ().getX (),
212
- fromLocation .getChunk ().getZ (), fromLocation .getWorld ().getName ());
213
+ fromLocation .getChunk ().getZ (), Objects . requireNonNull ( fromLocation .getWorld () ).getName ());
213
214
214
215
// When a player travels through the wilderness
215
216
if (toClaimedChunk == null && fromClaimedChunk == null ) {
216
217
if (AutoClaimUtil .isAutoClaiming (player )) {
217
- AutoClaimUtil .autoClaim (player , e . getTo () );
218
+ AutoClaimUtil .autoClaim (player , toLocation );
218
219
}
219
220
return ;
220
221
}
221
222
222
223
// When a goes from a town to wilderness
223
224
if (toClaimedChunk == null ) {
224
225
if (AutoClaimUtil .isAutoClaiming (player )) {
225
- AutoClaimUtil .autoClaim (player , e . getTo () );
226
+ AutoClaimUtil .autoClaim (player , toLocation );
226
227
} else {
227
228
MessageManager .sendActionBar (player , "wilderness" );
228
229
try {
@@ -323,6 +324,7 @@ public void onHangingBreak(HangingBreakByEntityEvent e) {
323
324
damagingEntityChunk = dispenser .getBlock ().getLocation ().getChunk ();
324
325
} else {
325
326
LivingEntity damagingProjectileShooter = (LivingEntity ) damagingProjectile .getShooter ();
327
+ assert damagingProjectileShooter != null ;
326
328
if (!Flag .isActionAllowed (damagedEntity .getLocation (), ActionType .MOB_GRIEF_WORLD )) {
327
329
e .setCancelled (true );
328
330
return ;
@@ -556,6 +558,7 @@ public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
556
558
damagingEntityChunk = dispenser .getBlock ().getLocation ().getChunk ();
557
559
} else {
558
560
LivingEntity damagingProjectileShooter = (LivingEntity ) damagingProjectile .getShooter ();
561
+ assert damagingProjectileShooter != null ;
559
562
if (damagedEntity instanceof Monster || damagedEntity instanceof Player ) {
560
563
return ;
561
564
}
0 commit comments