From 1a3c2172840874791489096144c09c9a9b5cae72 Mon Sep 17 00:00:00 2001 From: cnaude Date: Sun, 24 Feb 2013 11:24:22 -0700 Subject: [PATCH] Added per item sitting height Added sitting-height-adj option (non-stairs non-steps) --- src/config.yml | 4 ++- src/net/spoothie/chairs/ChairBlock.java | 29 ++++++++++++++++ src/net/spoothie/chairs/Chairs.java | 40 +++++++++++++++------- src/net/spoothie/chairs/EventListener.java | 28 ++++++++++----- src/plugin.yml | 2 +- 5 files changed, 80 insertions(+), 23 deletions(-) create mode 100644 src/net/spoothie/chairs/ChairBlock.java diff --git a/src/config.yml b/src/config.yml index 5449b78..fed1e23 100644 --- a/src/config.yml +++ b/src/config.yml @@ -2,13 +2,14 @@ # ------ # A list of all compatible block and item names: http://bit.ly/AmJgMb. # ------ -# allowed-blocks: Set the blocks you want to be able to sit down on. Use descriptive name or item ID. +# allowed-blocks: Set the blocks you want to be able to sit down on. Use descriptive name or item ID. Use name:number to set sitting height. # auto-rotate: If set to true, you are automatically rotated to the descending face of the stairs-block when sitting down. # sneaking: If set to true, you have to sneak to sit down on a chair. # max-chair-width: Define how many blocks a chair can be long (set to number <= 0 for unlimited width). # sign-check: If set to true, you will only be able to sit down when there are signs on both of the ends of the chair. # distance: The maximum distance between the chair (the center of the block) and the player to be able to sit down (to prevent glitching through walls, etc.). # sitting-height: Set how high you are sitting 'in' the stairs block (default is 0.7). +# sitting-height-adj: Non-stairs and non-steps are adjusted automatically by this amount. # upsidedown-check: If true then prevent players from sitting on upside down stairs. # seat-occupied-check: Check if seat is already occupied. # per-item-perms: Enable chairs.sit.[item] permission node. Set to false if you're sitting on every block. @@ -34,6 +35,7 @@ max-chair-width: 3 sign-check: false distance: 2 sitting-height: 0.7 +sitting-height-adj: 1.0 permissions: true notify-player: true upside-down-check: true diff --git a/src/net/spoothie/chairs/ChairBlock.java b/src/net/spoothie/chairs/ChairBlock.java new file mode 100644 index 0000000..fdf38c9 --- /dev/null +++ b/src/net/spoothie/chairs/ChairBlock.java @@ -0,0 +1,29 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package net.spoothie.chairs; + +import org.bukkit.Material; + +/** + * + * @author cnaude + */ +public class ChairBlock { + private Material mat; + private double sitHeight; + + public ChairBlock(Material m, double d) { + mat = m; + sitHeight = d; + } + + public Material getMat() { + return mat; + } + + public double getSitHeight() { + return sitHeight; + } +} diff --git a/src/net/spoothie/chairs/Chairs.java b/src/net/spoothie/chairs/Chairs.java index a747b0d..5532327 100644 --- a/src/net/spoothie/chairs/Chairs.java +++ b/src/net/spoothie/chairs/Chairs.java @@ -20,11 +20,11 @@ import org.bukkit.plugin.java.JavaPlugin; public class Chairs extends JavaPlugin { private static Chairs instance = null; - 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; - public double sittingHeight, distance; + public double sittingHeight, sittingHeightAdj, distance; public int maxChairWidth; private File pluginFolder; private File configFile; @@ -34,8 +34,7 @@ public class Chairs extends JavaPlugin { public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]"; static final Logger log = Logger.getLogger("Minecraft"); public PluginManager pm; - public static ChairsIgnoreList ignoreList; - + public static ChairsIgnoreList ignoreList; @Override public void onEnable() { @@ -81,6 +80,7 @@ public class Chairs extends JavaPlugin { sneaking = getConfig().getBoolean("sneaking"); signCheck = getConfig().getBoolean("sign-check"); sittingHeight = getConfig().getDouble("sitting-height"); + sittingHeightAdj = getConfig().getDouble("sitting-height-adj"); distance = getConfig().getDouble("distance"); maxChairWidth = getConfig().getInt("max-chair-width"); permissions = getConfig().getBoolean("permissions"); @@ -91,29 +91,45 @@ public class Chairs extends JavaPlugin { perItemPerms = getConfig().getBoolean("per-item-perms"); opsOverridePerms = getConfig().getBoolean("ops-override-perms"); - for (String type : getConfig().getStringList("allowed-blocks")) { - try { + for (String s : getConfig().getStringList("allowed-blocks")) { + String type; + double sh = sittingHeight; + if (s.contains(":")) { + String tmp[] = s.split(":",2); + type = tmp[0]; + sh = Double.parseDouble(tmp[1]); + } else { + type = s; + } + try { + Material mat; if (type.matches("\\d+")) { - allowedBlocks.add(Material.getMaterial(Integer.parseInt(type))); + mat = Material.getMaterial(Integer.parseInt(type)); } else { - allowedBlocks.add(Material.getMaterial(type)); + mat = Material.matchMaterial(type); + } + if (mat != null) { + logInfo("Allowed block: " + mat.toString() + " => " + sh); + allowedBlocks.add(new ChairBlock(mat,sh)); + } else { + logError("Invalid block: " + type); } } catch (Exception e) { - logInfo("ERROR: " + e.getMessage()); + logError(e.getMessage()); } } - for (String type : getConfig().getStringList("valid-signs")) { + for (String type : getConfig().getStringList("valid-signs")) { try { if (type.matches("\\d+")) { validSigns.add(Material.getMaterial(Integer.parseInt(type))); } else { - validSigns.add(Material.getMaterial(type)); + validSigns.add(Material.matchMaterial(type)); } } catch (Exception e) { - logInfo("ERROR: " + e.getMessage()); + logError(e.getMessage()); } } diff --git a/src/net/spoothie/chairs/EventListener.java b/src/net/spoothie/chairs/EventListener.java index db3a84a..4ea20b2 100644 --- a/src/net/spoothie/chairs/EventListener.java +++ b/src/net/spoothie/chairs/EventListener.java @@ -7,7 +7,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; @@ -55,6 +54,7 @@ public class EventListener implements Listener { } } } + class sendSitTask extends TimerTask { @@ -106,13 +106,8 @@ public class EventListener implements Listener { Stairs stairs = null; Step step = null; double sh = plugin.sittingHeight; - if (block.getState().getData() instanceof Stairs) { - stairs = (Stairs) block.getState().getData(); - } else if (block.getState().getData() instanceof Step) { - step = (Step) block.getState().getData(); - } else { - sh += 1.0; - } + boolean blockOkay = false; + Player player = event.getPlayer(); if (ignoreList.isIgnored(player.getName())) { return; @@ -135,9 +130,24 @@ public class EventListener implements Listener { PermissionDefault.FALSE)); } } - if (plugin.allowedBlocks.contains(block.getType()) + + for (ChairBlock cb : plugin.allowedBlocks) { + if (cb.getMat().equals(block.getType())) { + blockOkay = true; + sh = cb.getSitHeight(); + } + } + if (blockOkay || (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(); + } else if (block.getState().getData() instanceof Step) { + step = (Step) block.getState().getData(); + } else { + sh += plugin.sittingHeightAdj; + } int chairwidth = 1; diff --git a/src/plugin.yml b/src/plugin.yml index 29c80db..999280c 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 1.16.0 +version: 1.17.0 description: Let players sit on blocks. authors: - spoothie