diff --git a/pom.xml b/pom.xml
index 594c831..c609886 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
cn.citycraft
Residence
- 2.8.0.4
+ 2.8.0.5
Residence
重制版本的领地插件 - 喵♂呜
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 6695758..292b0da 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
@@ -27,27 +27,50 @@ public class ResidenceBugFix implements Listener {
plugin.getLogger().info("防刷生物补丁已加载...");
}
+ public boolean checkPerm(final ClaimedResidence res, final Player p) {
+ final FlagPermissions perms = res.getPermissions();
+ final String world = p.getWorld().getName();
+ return perms.playerHas(p.getName(), world, "place", perms.playerHas(p.getName(), world, "build", false));
+ }
+
+ public Block getPlaceBlock(final PlayerInteractEvent e) {
+ final Player p = e.getPlayer();
+ final ItemStack it = p.getItemInHand();
+ if (it == null || it.getType() == Material.AIR) {
+ return null;
+ }
+ final Block b = e.getClickedBlock();
+ final BlockFace bf = e.getBlockFace();
+ if (bf == null) {
+ return null;
+ }
+ return b.getRelative(bf, 1);
+ }
+
+ public Block getPlaceBlockDown(final PlayerInteractEvent e) {
+ final Block b = this.getPlaceBlock(e);
+ return b.getRelative(BlockFace.DOWN);
+ }
+
@EventHandler
public void onBlockPlace(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();
- if (it == null || it.getType() == Material.AIR) {
+ final Block b = this.getPlaceBlockDown(e);
+ if (b == null) {
return;
}
- final Block b = e.getClickedBlock();
+ final Player p = e.getPlayer();
+ final ItemStack it = p.getItemInHand();
final ClaimedResidence res = plugin.getResidenceManager().getByLoc(b.getLocation());
if (res == null) {
return;
}
if ((it.getType() == Material.PUMPKIN && (b.getType() == Material.SNOW_BLOCK || b.getType() == Material.IRON_BLOCK))
|| (it.getType() == Material.SKULL_ITEM && b.getType() == Material.SOUL_SAND)) {
- final FlagPermissions perms = res.getPermissions();
- final String world = p.getWorld().getName();
- if (!perms.playerHas(p.getName(), world, "place", perms.playerHas(p.getName(), world, "build", false))) {
+ if (checkPerm(res, p)) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission") + ChatColor.DARK_RED + " 当前区域不允许放置!");
}
@@ -69,7 +92,7 @@ public class ResidenceBugFix implements Listener {
}
final Block b = e.getClickedBlock();
final BlockFace bf = e.getBlockFace();
- if (bf == null) {
+ if (bf == null || bf != BlockFace.UP) {
return;
}
final Block b1 = b.getRelative(bf, 1);
@@ -78,10 +101,8 @@ public class ResidenceBugFix implements Listener {
if (res == null) {
return;
}
- 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", perms.playerHas(p.getName(), world, "build", false))) {
+ if (checkPerm(res, p)) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission") + ChatColor.DARK_RED + " 当前区域不允许此操作!");
}