Skip to content

Commit 1e5790c

Browse files
committed
Fix warnings
Signed-off-by: William <will27528@gmail.com>
1 parent aa4a0d7 commit 1e5790c

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

bukkit/src/main/java/me/william278/husktowns/listener/EventListener.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@
3838

3939
import java.util.HashSet;
4040
import java.util.Locale;
41+
import java.util.Objects;
4142

4243
public class EventListener implements Listener {
4344

4445
private static final double MAX_RAYTRACE_DISTANCE = 60D;
4546

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
4948
public static boolean cancelPlayerAction(Player player, Location location, ActionType actionType, boolean sendMessage) {
5049
ClaimCache claimCache = HuskTowns.getClaimCache();
5150
PlayerCache playerCache = HuskTowns.getPlayerCache();
@@ -59,7 +58,7 @@ public static boolean cancelPlayerAction(Player player, Location location, Actio
5958
return true;
6059
}
6160

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());
6362
if (chunk != null) {
6463
switch (AccessManager.getPlayerAccess(player, actionType, chunk, true)) {
6564
case CANNOT_PERFORM_ACTION_ADMIN_CLAIM:
@@ -156,9 +155,9 @@ private static boolean areChunksInSameTown(Location location1, Location location
156155
}
157156

158157
ClaimedChunk chunk1 = claimCache.getChunkAt(location1.getChunk().getX(),
159-
location1.getChunk().getZ(), location1.getWorld().getName());
158+
location1.getChunk().getZ(), Objects.requireNonNull(location1.getWorld()).getName());
160159
ClaimedChunk chunk2 = claimCache.getChunkAt(location2.getChunk().getX(),
161-
location2.getChunk().getZ(), location2.getWorld().getName());
160+
location2.getChunk().getZ(), Objects.requireNonNull(location2.getWorld()).getName());
162161

163162
String chunk1Town = "Wilderness";
164163
String chunk2Town = "Wilderness";
@@ -191,9 +190,14 @@ public void onPlayerJoin(PlayerJoinEvent e) {
191190
@EventHandler
192191
public void onPlayerMove(PlayerMoveEvent e) {
193192
Player player = e.getPlayer();
193+
final Location toLocation = e.getTo();
194+
final Location fromLocation = e.getFrom();
195+
if (toLocation == null) {
196+
return;
197+
}
194198

195199
// Check when a player changes chunk
196-
if (!e.getFrom().getChunk().equals(e.getTo().getChunk())) {
200+
if (!fromLocation.getChunk().equals(toLocation.getChunk())) {
197201
final ClaimCache claimCache = HuskTowns.getClaimCache();
198202
final TownDataCache messageCache = HuskTowns.getTownDataCache();
199203
if (!claimCache.hasLoaded()) {
@@ -203,26 +207,23 @@ public void onPlayerMove(PlayerMoveEvent e) {
203207
return;
204208
}
205209

206-
Location toLocation = e.getTo();
207-
Location fromLocation = e.getFrom();
208-
209210
ClaimedChunk toClaimedChunk = claimCache.getChunkAt(toLocation.getChunk().getX(),
210-
toLocation.getChunk().getZ(), toLocation.getWorld().getName());
211+
toLocation.getChunk().getZ(), Objects.requireNonNull(toLocation.getWorld()).getName());
211212
ClaimedChunk fromClaimedChunk = claimCache.getChunkAt(fromLocation.getChunk().getX(),
212-
fromLocation.getChunk().getZ(), fromLocation.getWorld().getName());
213+
fromLocation.getChunk().getZ(), Objects.requireNonNull(fromLocation.getWorld()).getName());
213214

214215
// When a player travels through the wilderness
215216
if (toClaimedChunk == null && fromClaimedChunk == null) {
216217
if (AutoClaimUtil.isAutoClaiming(player)) {
217-
AutoClaimUtil.autoClaim(player, e.getTo());
218+
AutoClaimUtil.autoClaim(player, toLocation);
218219
}
219220
return;
220221
}
221222

222223
// When a goes from a town to wilderness
223224
if (toClaimedChunk == null) {
224225
if (AutoClaimUtil.isAutoClaiming(player)) {
225-
AutoClaimUtil.autoClaim(player, e.getTo());
226+
AutoClaimUtil.autoClaim(player, toLocation);
226227
} else {
227228
MessageManager.sendActionBar(player, "wilderness");
228229
try {
@@ -323,6 +324,7 @@ public void onHangingBreak(HangingBreakByEntityEvent e) {
323324
damagingEntityChunk = dispenser.getBlock().getLocation().getChunk();
324325
} else {
325326
LivingEntity damagingProjectileShooter = (LivingEntity) damagingProjectile.getShooter();
327+
assert damagingProjectileShooter != null;
326328
if (!Flag.isActionAllowed(damagedEntity.getLocation(), ActionType.MOB_GRIEF_WORLD)) {
327329
e.setCancelled(true);
328330
return;
@@ -556,6 +558,7 @@ public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
556558
damagingEntityChunk = dispenser.getBlock().getLocation().getChunk();
557559
} else {
558560
LivingEntity damagingProjectileShooter = (LivingEntity) damagingProjectile.getShooter();
561+
assert damagingProjectileShooter != null;
559562
if (damagedEntity instanceof Monster || damagedEntity instanceof Player) {
560563
return;
561564
}

0 commit comments

Comments
 (0)