Fix NPE when checking player options on NPC.

This commit is contained in:
bloodshot 2020-02-01 12:31:43 -05:00
parent 84fdbd2de0
commit 99d0085d96
2 changed files with 60 additions and 0 deletions

View File

@ -338,6 +338,11 @@ public boolean onEntityMove(Event event, Location fromLocation, Location toLocat
private void runPlayerCommands(GDClaim claim, GDPermissionUser user, boolean enter) { private void runPlayerCommands(GDClaim claim, GDPermissionUser user, boolean enter) {
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
List<String> rawCommandList = new ArrayList<>(); List<String> rawCommandList = new ArrayList<>();
Set<Context> contexts = new HashSet<>(); Set<Context> contexts = new HashSet<>();
if (player.getUniqueId().equals(claim.getOwnerUniqueId())) { if (player.getUniqueId().equals(claim.getOwnerUniqueId())) {
@ -406,6 +411,11 @@ private String replacePlaceHolders(GDClaim claim, Player player, String command)
private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) { private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode gameMode = player.getGameMode(); final GameMode gameMode = player.getGameMode();
if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR) { if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR) {
@ -432,6 +442,11 @@ private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim
private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) { private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode gameMode = player.getGameMode(); final GameMode gameMode = player.getGameMode();
if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR || !player.isInvulnerable()) { if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR || !player.isInvulnerable()) {
@ -456,6 +471,11 @@ private void checkPlayerGameMode(GDPermissionUser user, GDClaim fromClaim, GDCla
} }
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode currentGameMode = player.getGameMode(); final GameMode currentGameMode = player.getGameMode();
final GameModeType gameModeType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(GameModeType.class), playerData.getSubject(), Options.PLAYER_GAMEMODE, toClaim); final GameModeType gameModeType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(GameModeType.class), playerData.getSubject(), Options.PLAYER_GAMEMODE, toClaim);
@ -478,6 +498,11 @@ private void checkPlayerWalkSpeed(GDPermissionUser user, GDClaim fromClaim, GDCl
} }
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final float currentWalkSpeed = player.getWalkSpeed(); final float currentWalkSpeed = player.getWalkSpeed();
final double walkSpeed = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_WALK_SPEED, toClaim); final double walkSpeed = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_WALK_SPEED, toClaim);
@ -499,6 +524,11 @@ public void checkPlayerWeather(GDPermissionUser user, GDClaim fromClaim, GDClaim
} }
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final WeatherType weatherType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(WeatherType.class), playerData.getSubject(), Options.PLAYER_WEATHER, toClaim); final WeatherType weatherType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(WeatherType.class), playerData.getSubject(), Options.PLAYER_WEATHER, toClaim);
if (weatherType != null && weatherType != WeatherTypes.UNDEFINED) { if (weatherType != null && weatherType != WeatherTypes.UNDEFINED) {

View File

@ -383,6 +383,11 @@ public boolean onEntityMove(MoveEntityEvent event, Location<World> fromLocation,
private void runPlayerCommands(GDClaim claim, GDPermissionUser user, boolean enter) { private void runPlayerCommands(GDClaim claim, GDPermissionUser user, boolean enter) {
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely NPC
return;
}
List<String> rawCommandList = new ArrayList<>(); List<String> rawCommandList = new ArrayList<>();
Set<Context> contexts = new HashSet<>(); Set<Context> contexts = new HashSet<>();
if (player.getUniqueId().equals(claim.getOwnerUniqueId())) { if (player.getUniqueId().equals(claim.getOwnerUniqueId())) {
@ -451,6 +456,11 @@ private String replacePlaceHolders(GDClaim claim, Player player, String command)
private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) { private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode gameMode = player.get(Keys.GAME_MODE).orElse(null); final GameMode gameMode = player.get(Keys.GAME_MODE).orElse(null);
if (gameMode == null || gameMode == GameModes.CREATIVE || gameMode == GameModes.SPECTATOR) { if (gameMode == null || gameMode == GameModes.CREATIVE || gameMode == GameModes.SPECTATOR) {
@ -478,6 +488,11 @@ private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim
private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) { private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode gameMode = player.get(Keys.GAME_MODE).get(); final GameMode gameMode = player.get(Keys.GAME_MODE).get();
if (gameMode == GameModes.CREATIVE || gameMode == GameModes.SPECTATOR || !player.get(Keys.INVULNERABLE).get()) { if (gameMode == GameModes.CREATIVE || gameMode == GameModes.SPECTATOR || !player.get(Keys.INVULNERABLE).get()) {
@ -502,6 +517,11 @@ private void checkPlayerGameMode(GDPermissionUser user, GDClaim fromClaim, GDCla
} }
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode currentGameMode = player.get(Keys.GAME_MODE).get(); final GameMode currentGameMode = player.get(Keys.GAME_MODE).get();
final GameModeType gameModeType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(GameModeType.class), playerData.getSubject(), Options.PLAYER_GAMEMODE, toClaim); final GameModeType gameModeType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(GameModeType.class), playerData.getSubject(), Options.PLAYER_GAMEMODE, toClaim);
@ -524,6 +544,11 @@ private void checkPlayerWalkSpeed(GDPermissionUser user, GDClaim fromClaim, GDCl
} }
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final double currentWalkSpeed = player.get(Keys.WALKING_SPEED).get(); final double currentWalkSpeed = player.get(Keys.WALKING_SPEED).get();
final double walkSpeed = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_WALK_SPEED, toClaim); final double walkSpeed = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_WALK_SPEED, toClaim);
@ -544,6 +569,11 @@ public void checkPlayerWeather(GDPermissionUser user, GDClaim fromClaim, GDClaim
} }
final Player player = user.getOnlinePlayer(); final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely NPC
return;
}
final GDPlayerData playerData = user.getInternalPlayerData(); final GDPlayerData playerData = user.getInternalPlayerData();
final WeatherType weatherType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(WeatherType.class), playerData.getSubject(), Options.PLAYER_WEATHER, toClaim); final WeatherType weatherType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(WeatherType.class), playerData.getSubject(), Options.PLAYER_WEATHER, toClaim);
if (weatherType != null) { if (weatherType != null) {