Use new BlockData API for Leaderboards.
This commit fixes a bug on Minecraft 1.14 servers where leaderboards would cause a NullPointerException due to the MaterialData API being broken. Instead, we now use the new BlockData API, and everything is back to normal. Fixes #536
This commit is contained in:
@@ -12,6 +12,7 @@ These changes will (most likely) be included in the next version.
|
|||||||
|
|
||||||
## [Unreleased]
|
## [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`.
|
- 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.
|
- 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.
|
- Food levels no longer deplete for players in the lobby and spectator area.
|
||||||
- Wither skeletons now correctly spawn with stone swords.
|
- Wither skeletons now correctly spawn with stone swords.
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import com.garbagemule.MobArena.MobArena;
|
|||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Directional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -134,7 +137,11 @@ public class Leaderboard
|
|||||||
Sign current = this.topLeftSign;
|
Sign current = this.topLeftSign;
|
||||||
|
|
||||||
// Calculate matrix dimensions.
|
// 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.rows = getSignCount(current, BlockFace.DOWN);
|
||||||
this.cols = getSignCount(current, direction);
|
this.cols = getSignCount(current, direction);
|
||||||
|
|
||||||
@@ -224,8 +231,19 @@ public class Leaderboard
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
BlockState state = s.getBlock().getState();
|
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++;
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -240,13 +258,16 @@ public class Leaderboard
|
|||||||
|
|
||||||
private BlockFace getRightDirection(Sign s)
|
private BlockFace getRightDirection(Sign s)
|
||||||
{
|
{
|
||||||
byte data = s.getRawData();
|
BlockData data = s.getBlockData();
|
||||||
|
if (data instanceof Directional) {
|
||||||
if (data == 2) return BlockFace.WEST;//BlockFace.NORTH;
|
BlockFace direction = ((Directional) data).getFacing();
|
||||||
if (data == 3) return BlockFace.EAST;//BlockFace.SOUTH;
|
switch (direction) {
|
||||||
if (data == 4) return BlockFace.SOUTH;//BlockFace.WEST;
|
case NORTH: return BlockFace.WEST;
|
||||||
if (data == 5) return BlockFace.NORTH;//BlockFace.EAST;
|
case SOUTH: return BlockFace.EAST;
|
||||||
|
case WEST: return BlockFace.SOUTH;
|
||||||
|
case EAST: return BlockFace.NORTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user