From 92086e4f3af63b158008c8280a2da93d68aa7aea Mon Sep 17 00:00:00 2001 From: j502647092 Date: Thu, 8 Oct 2015 00:16:34 +0800 Subject: [PATCH] fix some bug... Signed-off-by: j502647092 --- .../listeners/bugfix/ResidenceBugFix.java | 67 +++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bekvon/bukkit/residence/listeners/bugfix/ResidenceBugFix.java b/src/main/java/com/bekvon/bukkit/residence/listeners/bugfix/ResidenceBugFix.java index ce7a400..7c705c8 100644 --- a/src/main/java/com/bekvon/bukkit/residence/listeners/bugfix/ResidenceBugFix.java +++ b/src/main/java/com/bekvon/bukkit/residence/listeners/bugfix/ResidenceBugFix.java @@ -7,7 +7,11 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; @@ -23,6 +27,7 @@ public class ResidenceBugFix implements Listener { plugin.getLogger().info("防刷甘蔗补丁已加载..."); plugin.getLogger().info("防刷单元补丁已加载..."); plugin.getLogger().info("防刷铁轨补丁已加载..."); + // plugin.getLogger().info("防刷生物补丁已加载..."); } @EventHandler @@ -35,6 +40,9 @@ public class ResidenceBugFix implements Listener { @EventHandler public void onPlace(final PlayerInteractEvent e) { + if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.PHYSICAL) { + return; + } try { final Player p = e.getPlayer(); final ItemStack it = p.getItemInHand(); @@ -48,19 +56,70 @@ public class ResidenceBugFix implements Listener { } final Block b1 = b.getRelative(bf, 1); final Block b2 = b.getRelative(bf, 2); - final ClaimedResidence res = plugin.getResidenceManager().getByLoc(b2.getLocation()); + final ClaimedResidence res = plugin.getResidenceManager().getByLoc(b1.getLocation()); if (res == null) { return; } - final FlagPermissions perms = plugin.getPermsByLocForPlayer(b.getLocation(), p); + final FlagPermissions perms = res.getPermissions(); final String world = p.getWorld().getName(); if (b1.getType() != Material.AIR && b2.getType() == Material.AIR) { - if (!perms.playerHas(p.getName(), world, "place", false)) { + if (!perms.playerHas(p.getName(), world, "place", perms.playerHas(p.getName(), world, "build", false))) { e.setCancelled(true); - p.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission") + ChatColor.DARK_RED + " 别费劲了 领地BUG早修了"); + p.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission") + ChatColor.DARK_RED + " 当前区域不允许此操作!"); } } } catch (final Exception e2) { } } + + @EventHandler + public void onSpawn(final CreatureSpawnEvent e) { + // final SpawnReason sr = e.getSpawnReason(); + // if (sr == SpawnReason.NATURAL) { + // return; + // } + // plugin.getLogger().info("=======CreatureSpawnEvent======="); + // plugin.getLogger().info(e.getEntity().getType().toString()); + // plugin.getLogger().info(e.getEntityType().toString()); + // plugin.getLogger().info(e.getSpawnReason().toString()); + // plugin.getLogger().info("=======CreatureSpawnEvent======="); + // final Location loc = e.getLocation(); + // if (sr == SpawnReason.BUILD_IRONGOLEM || sr == SpawnReason.BUILD_SNOWMAN || sr == SpawnReason.BUILD_WITHER) { + // final FlagPermissions perm = plugin.getPermsByLocForPlayer(loc, p); + // if (!perm.has("place", false)) { + // e.setCancelled(true); + // p.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission") + ChatColor.DARK_RED + " 当前区域无法建造生物!"); + // } + // } + } + + @EventHandler + public void onSpawn(final EntitySpawnEvent e) { + // plugin.getLogger().info("=======EntitySpawnEvent======="); + // plugin.getLogger().info(e.getEntity().getType().toString()); + // plugin.getLogger().info(e.getEntityType().toString()); + // plugin.getLogger().info(e.getLocation().toString()); + // plugin.getLogger().info("=======EntitySpawnEvent======="); + // if (e.getEntity() instanceof Player) { + // final Player p = (Player) e.getEntity(); + // final EntityType et = e.getEntityType(); + // final Location loc = e.getLocation(); + // if (et == EntityType.WITHER || et == EntityType.SNOWMAN || et == EntityType.IRON_GOLEM) { + // final FlagPermissions perm = plugin.getPermsByLocForPlayer(loc, p); + // if (!perm.has("place", false)) { + // e.setCancelled(true); + // p.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission") + ChatColor.DARK_RED + " 当前区域无法建造生物!"); + // } + // } + // } + } + + @EventHandler + public void onSpawn(final SpawnerSpawnEvent e) { + // plugin.getLogger().info("=======SpawnerSpawnEvent======="); + // plugin.getLogger().info(e.getEntityType().toString()); + // plugin.getLogger().info(e.getLocation().toString()); + // plugin.getLogger().info(e.getSpawner().getSpawnedType().toString()); + // plugin.getLogger().info("=======SpawnerSpawnEvent======="); + } }