From 2566addf8d8039dc9fa2e73790fa0825c112da63 Mon Sep 17 00:00:00 2001 From: cnaude Date: Thu, 27 Jun 2013 21:24:28 -0700 Subject: [PATCH] Fix issues with wooden steps. Add option to select blocks by data value. --- src/com/cnaude/chairs/ChairBlock.java | 10 ++++++++-- src/com/cnaude/chairs/Chairs.java | 18 +++++++++++------ src/com/cnaude/chairs/EventListener.java | 25 +++++++++++++++++++++--- src/plugin.yml | 2 +- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/com/cnaude/chairs/ChairBlock.java b/src/com/cnaude/chairs/ChairBlock.java index 4febecf..4f6fca2 100644 --- a/src/com/cnaude/chairs/ChairBlock.java +++ b/src/com/cnaude/chairs/ChairBlock.java @@ -13,10 +13,12 @@ import org.bukkit.Material; public class ChairBlock { private Material mat; private double sitHeight; + private byte data; - public ChairBlock(Material m, double d) { + public ChairBlock(Material m, double s, String d) { mat = m; - sitHeight = d; + sitHeight = s; + data = Byte.parseByte(d); } public Material getMat() { @@ -26,4 +28,8 @@ public class ChairBlock { public double getSitHeight() { return sitHeight; } + + public byte getDamage() { + return data; + } } diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index e02524a..aaa8e69 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -26,7 +26,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class Chairs extends JavaPlugin { private static Chairs instance = null; public static ChairEffects chairEffects; - public List allowedBlocks = new ArrayList(); + public List allowedBlocks = new ArrayList(); public List validSigns = new ArrayList(); public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms; public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms, ignoreIfBlockInHand; @@ -152,10 +152,16 @@ public class Chairs extends JavaPlugin { for (String s : getConfig().getStringList("allowed-blocks")) { String type; double sh = sittingHeight; + String d = "0"; if (s.contains(":")) { - String tmp[] = s.split(":",2); - type = tmp[0]; - sh = Double.parseDouble(tmp[1]); + String tmp[] = s.split(":",3); + type = tmp[0]; + if (!tmp[1].isEmpty()) { + sh = Double.parseDouble(tmp[1]); + } + if (tmp.length == 3) { + d = tmp[2]; + } } else { type = s; } @@ -167,8 +173,8 @@ public class Chairs extends JavaPlugin { mat = Material.matchMaterial(type); } if (mat != null) { - logInfo("Allowed block: " + mat.toString() + " => " + sh); - allowedBlocks.add(new ChairBlock(mat,sh)); + logInfo("Allowed block: " + mat.toString() + " => " + sh + " => " + d); + allowedBlocks.add(new ChairBlock(mat,sh,d)); } else { logError("Invalid block: " + type); } diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index 931e715..88950f7 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -21,6 +21,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.material.Stairs; import org.bukkit.material.Step; +import org.bukkit.material.WoodenStep; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -122,8 +123,9 @@ public class EventListener implements Listener { Block block = event.getClickedBlock(); Stairs stairs = null; Step step = null; + WoodenStep wStep = null; double sh = plugin.sittingHeight; - boolean blockOkay = false; + boolean blockOkay = false; Player player = event.getPlayer(); if (ignoreList.isIgnored(player.getName())) { @@ -149,21 +151,33 @@ public class EventListener implements Listener { } for (ChairBlock cb : plugin.allowedBlocks) { - if (cb.getMat().equals(block.getType())) { + //plugin.logInfo("Comparing: (" + cb.getMat().name() + " ? " + block.getType().name() + ") (" + // + cb.getDamage() + " ? " + block.getData() + ")"); + if (cb.getMat().equals(block.getType()) + && cb.getDamage() == block.getData()) { blockOkay = true; - sh = cb.getSitHeight(); + sh = cb.getSitHeight(); + continue; } } if (blockOkay + || (player.hasPermission("chairs.sit." + block.getTypeId() + ":" + block.getData()) && plugin.perItemPerms) + || (player.hasPermission("chairs.sit." + block.getType().toString() + ":" + block.getData()) && plugin.perItemPerms) || (player.hasPermission("chairs.sit." + block.getTypeId()) && plugin.perItemPerms) || (player.hasPermission("chairs.sit." + block.getType().toString()) && plugin.perItemPerms)) { if (block.getState().getData() instanceof Stairs) { stairs = (Stairs) block.getState().getData(); + //plugin.logInfo("STAIR"); } else if (block.getState().getData() instanceof Step) { step = (Step) block.getState().getData(); + //plugin.logInfo("STEP"); + } else if (block.getState().getData() instanceof WoodenStep) { + wStep = (WoodenStep) block.getState().getData(); + //plugin.logInfo("WOODEN_STEP"); } else { sh += plugin.sittingHeightAdj; + //plugin.logInfo("OTHER"); } int chairwidth = 1; @@ -205,6 +219,11 @@ public class EventListener implements Listener { return; } } + if (wStep != null) { + if (wStep.isInverted() && plugin.invertedStepCheck) { + return; + } + } // Check for signs. if (plugin.signCheck == true && stairs != null) { diff --git a/src/plugin.yml b/src/plugin.yml index 2195a76..0b55000 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 2.1.2 +version: 2.1.3 description: Let players sit on blocks. website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/ authors: