From cfc95f48955d03affc07d72590e5d4f860a29508 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 19 Sep 2014 09:30:08 +0200 Subject: [PATCH] Support more sender object types in the canPlayerBuildAt method. Makes it possible to check offline player rights too. --- .../listeners/FactionsListenerMain.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java index 5666749d..fe128567 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -706,13 +706,15 @@ public class FactionsListenerMain implements Listener // -------------------------------------------- // // FLAG: BUILD // -------------------------------------------- // - - public static boolean canPlayerBuildAt(Player player, PS ps, boolean verboose) + + public static boolean canPlayerBuildAt(Object senderObject, PS ps, boolean verboose) { - String name = player.getName(); + MPlayer mplayer = MPlayer.get(senderObject); + if (mplayer == null) return false; + + String name = mplayer.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; - MPlayer mplayer = MPlayer.get(player); if (mplayer.isUsingAdminMode()) return true; if (!FPerm.BUILD.has(mplayer, ps, false) && FPerm.PAINBUILD.has(mplayer, ps, false)) @@ -721,7 +723,11 @@ public class FactionsListenerMain implements Listener { Faction hostFaction = BoardColl.get().getFactionAt(ps); mplayer.msg("It is painful to build in the territory of %s.", hostFaction.describeTo(mplayer)); - player.damage(MConf.get().actionDeniedPainAmount); + Player player = mplayer.getPlayer(); + if (player != null) + { + player.damage(MConf.get().actionDeniedPainAmount); + } } return true; } @@ -746,7 +752,7 @@ public class FactionsListenerMain implements Listener Entity breaker = entityEvent.getRemover(); if (! (breaker instanceof Player)) return; - if ( ! canPlayerBuildAt((Player)breaker, PS.valueOf(event.getEntity()), true)) + if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity()), true)) { event.setCancelled(true); }