diff --git a/changelog.md b/changelog.md index 5f2e11f..b888674 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ These changes will (most likely) be included in the next version. ## [Unreleased] - Tridents and crossbows are now considered weapons with regards to the `unbreakable-weapons` flag. All class items that have durability now have their unbreakable flag set to true unless the `unbreakable-weapons` and/or `unbreakable-armor` flags are set to `false`. +- Leaderboards now work again on servers running Minecraft 1.14+. - MobArena no longer crashes when players try to join with items that lower their max health below the default of 20. Players with lower max health will notice missing health in the lobby, but it will quickly regenerate to full. - Food levels no longer deplete for players in the lobby and spectator area. - Wither skeletons now correctly spawn with stone swords. diff --git a/src/main/java/com/garbagemule/MobArena/leaderboards/Leaderboard.java b/src/main/java/com/garbagemule/MobArena/leaderboards/Leaderboard.java index d951798..db11331 100644 --- a/src/main/java/com/garbagemule/MobArena/leaderboards/Leaderboard.java +++ b/src/main/java/com/garbagemule/MobArena/leaderboards/Leaderboard.java @@ -6,9 +6,12 @@ import com.garbagemule.MobArena.MobArena; import com.garbagemule.MobArena.framework.Arena; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; import java.util.ArrayList; import java.util.Collections; @@ -134,7 +137,11 @@ public class Leaderboard Sign current = this.topLeftSign; // Calculate matrix dimensions. - this.direction = getRightDirection(current); + BlockFace direction = getRightDirection(current); + if (direction == null) { + return false; + } + this.direction = direction; this.rows = getSignCount(current, BlockFace.DOWN); this.cols = getSignCount(current, direction); @@ -145,7 +152,7 @@ public class Leaderboard // Get the left-most sign in the current row. Sign first = getAdjacentSign(current, BlockFace.DOWN); - + for (int i = 1; i < rows; i++) { // Back to the first sign of the row. @@ -222,11 +229,22 @@ public class Leaderboard private int getSignCount(Sign s, BlockFace direction) { int i = 1; - + BlockState state = s.getBlock().getState(); - while ((state = state.getBlock().getRelative(direction).getState()) instanceof Sign) + while (state != null) { + Block current = state.getBlock(); + if (current == null) break; + + Block relative = current.getRelative(direction); + if (relative == null) break; + + state = relative.getState(); + if (!(state instanceof Sign)) { + break; + } i++; - + } + return i; } @@ -240,13 +258,16 @@ public class Leaderboard private BlockFace getRightDirection(Sign s) { - byte data = s.getRawData(); - - if (data == 2) return BlockFace.WEST;//BlockFace.NORTH; - if (data == 3) return BlockFace.EAST;//BlockFace.SOUTH; - if (data == 4) return BlockFace.SOUTH;//BlockFace.WEST; - if (data == 5) return BlockFace.NORTH;//BlockFace.EAST; - + BlockData data = s.getBlockData(); + if (data instanceof Directional) { + BlockFace direction = ((Directional) data).getFacing(); + switch (direction) { + case NORTH: return BlockFace.WEST; + case SOUTH: return BlockFace.EAST; + case WEST: return BlockFace.SOUTH; + case EAST: return BlockFace.NORTH; + } + } return null; }