Handle custom WorldGuard flags not existing

Don't query and try to use flags if they haven't been registered
This commit is contained in:
Eric 2019-07-24 14:45:45 +02:00
parent e82c28e5e8
commit fed894a9b0

View File

@ -70,6 +70,11 @@ public class WorldGuardListener implements Listener {
// }
private boolean handleForLocation(Player player, Location loc, Cancellable e, IWrappedFlag<WrappedState> flag) {
if (flag == null) {
// Flag may have not been registered successfully, so ignore them.
return false;
}
WrappedState state = wgWrapper.queryFlag(player, loc, flag).orElse(WrappedState.DENY);
if (state == WrappedState.DENY) {
e.setCancelled(true);
@ -82,8 +87,8 @@ public class WorldGuardListener implements Listener {
private IWrappedFlag<WrappedState> getStateFlag(String flagName) {
Optional<IWrappedFlag<WrappedState>> flagOptional = wgWrapper.getFlag(flagName, WrappedState.class);
if (!flagOptional.isPresent()) {
plugin.getLogger().severe("Failed to get WorldGuard flag '" + flagName + "'.");
plugin.debug("WorldGuard flag '" + flagName + "' is not present!");
plugin.getLogger().severe("Failed to get WorldGuard state flag '" + flagName + "'.");
plugin.debug("WorldGuard state flag '" + flagName + "' is not present!");
return null;
}
return flagOptional.get();