Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
Signed-off-by: William <[email protected]>
  • Loading branch information
WiIIiam278 committed Oct 9, 2021
1 parent aa4a0d7 commit 1e5790c
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@

import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;

public class EventListener implements Listener {

private static final double MAX_RAYTRACE_DISTANCE = 60D;

/*
Returns whether to cancel an action based on the location data and flags
*/
// Returns whether to cancel an action based on the location data and flags
public static boolean cancelPlayerAction(Player player, Location location, ActionType actionType, boolean sendMessage) {
ClaimCache claimCache = HuskTowns.getClaimCache();
PlayerCache playerCache = HuskTowns.getPlayerCache();
Expand All @@ -59,7 +58,7 @@ public static boolean cancelPlayerAction(Player player, Location location, Actio
return true;
}

ClaimedChunk chunk = claimCache.getChunkAt(location.getChunk().getX(), location.getChunk().getZ(), location.getWorld().getName());
ClaimedChunk chunk = claimCache.getChunkAt(location.getChunk().getX(), location.getChunk().getZ(), Objects.requireNonNull(location.getWorld()).getName());
if (chunk != null) {
switch (AccessManager.getPlayerAccess(player, actionType, chunk, true)) {
case CANNOT_PERFORM_ACTION_ADMIN_CLAIM:
Expand Down Expand Up @@ -156,9 +155,9 @@ private static boolean areChunksInSameTown(Location location1, Location location
}

ClaimedChunk chunk1 = claimCache.getChunkAt(location1.getChunk().getX(),
location1.getChunk().getZ(), location1.getWorld().getName());
location1.getChunk().getZ(), Objects.requireNonNull(location1.getWorld()).getName());
ClaimedChunk chunk2 = claimCache.getChunkAt(location2.getChunk().getX(),
location2.getChunk().getZ(), location2.getWorld().getName());
location2.getChunk().getZ(), Objects.requireNonNull(location2.getWorld()).getName());

String chunk1Town = "Wilderness";
String chunk2Town = "Wilderness";
Expand Down Expand Up @@ -191,9 +190,14 @@ public void onPlayerJoin(PlayerJoinEvent e) {
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
final Location toLocation = e.getTo();
final Location fromLocation = e.getFrom();
if (toLocation == null) {
return;
}

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

Location toLocation = e.getTo();
Location fromLocation = e.getFrom();

ClaimedChunk toClaimedChunk = claimCache.getChunkAt(toLocation.getChunk().getX(),
toLocation.getChunk().getZ(), toLocation.getWorld().getName());
toLocation.getChunk().getZ(), Objects.requireNonNull(toLocation.getWorld()).getName());
ClaimedChunk fromClaimedChunk = claimCache.getChunkAt(fromLocation.getChunk().getX(),
fromLocation.getChunk().getZ(), fromLocation.getWorld().getName());
fromLocation.getChunk().getZ(), Objects.requireNonNull(fromLocation.getWorld()).getName());

// When a player travels through the wilderness
if (toClaimedChunk == null && fromClaimedChunk == null) {
if (AutoClaimUtil.isAutoClaiming(player)) {
AutoClaimUtil.autoClaim(player, e.getTo());
AutoClaimUtil.autoClaim(player, toLocation);
}
return;
}

// When a goes from a town to wilderness
if (toClaimedChunk == null) {
if (AutoClaimUtil.isAutoClaiming(player)) {
AutoClaimUtil.autoClaim(player, e.getTo());
AutoClaimUtil.autoClaim(player, toLocation);
} else {
MessageManager.sendActionBar(player, "wilderness");
try {
Expand Down Expand Up @@ -323,6 +324,7 @@ public void onHangingBreak(HangingBreakByEntityEvent e) {
damagingEntityChunk = dispenser.getBlock().getLocation().getChunk();
} else {
LivingEntity damagingProjectileShooter = (LivingEntity) damagingProjectile.getShooter();
assert damagingProjectileShooter != null;
if (!Flag.isActionAllowed(damagedEntity.getLocation(), ActionType.MOB_GRIEF_WORLD)) {
e.setCancelled(true);
return;
Expand Down Expand Up @@ -556,6 +558,7 @@ public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
damagingEntityChunk = dispenser.getBlock().getLocation().getChunk();
} else {
LivingEntity damagingProjectileShooter = (LivingEntity) damagingProjectile.getShooter();
assert damagingProjectileShooter != null;
if (damagedEntity instanceof Monster || damagedEntity instanceof Player) {
return;
}
Expand Down

0 comments on commit 1e5790c

Please sign in to comment.