From 73dd820949548b6b28d89c140be53f5315fed371 Mon Sep 17 00:00:00 2001 From: cnaude Date: Wed, 19 Dec 2012 07:40:24 -0700 Subject: [PATCH] Update CB 1.4.5-R1.0 Added chairs.sit.[item] perm node Added ability to use item numbers instead of item names. --- src/config.yml | 5 +- src/net/spoothie/chairs/ChairWatcher.java | 5 +- src/net/spoothie/chairs/Chairs.java | 19 ++++-- src/net/spoothie/chairs/EventListener.java | 69 +++++++++++++--------- src/plugin.yml | 2 +- 5 files changed, 62 insertions(+), 38 deletions(-) diff --git a/src/config.yml b/src/config.yml index f11783f..a08c279 100644 --- a/src/config.yml +++ b/src/config.yml @@ -2,7 +2,7 @@ # ------ # 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. Currently, only stairs-blocks are working. +# allowed-blocks: Set the blocks you want to be able to sit down on. Use descriptive name or item ID. # 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). @@ -31,4 +31,5 @@ sitting-height: 0.7 permissions: true notify-player: true upside-down-check: true -seat-occupied-check: true \ No newline at end of file +seat-occupied-check: true +upper-step-check: true \ No newline at end of file diff --git a/src/net/spoothie/chairs/ChairWatcher.java b/src/net/spoothie/chairs/ChairWatcher.java index 7e9ae47..8258010 100644 --- a/src/net/spoothie/chairs/ChairWatcher.java +++ b/src/net/spoothie/chairs/ChairWatcher.java @@ -5,8 +5,9 @@ package net.spoothie.chairs; import java.util.ArrayList; -import net.minecraft.server.DataWatcher; -import net.minecraft.server.WatchableObject; +import net.minecraft.server.v1_4_5.DataWatcher; +import net.minecraft.server.v1_4_5.WatchableObject; + /** * diff --git a/src/net/spoothie/chairs/Chairs.java b/src/net/spoothie/chairs/Chairs.java index f0cd32e..fb082ed 100644 --- a/src/net/spoothie/chairs/Chairs.java +++ b/src/net/spoothie/chairs/Chairs.java @@ -6,21 +6,21 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.Packet40EntityMetadata; +import net.minecraft.server.v1_4_5.Packet40EntityMetadata; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class Chairs extends JavaPlugin { public List allowedBlocks = new ArrayList(); - public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, invertedStairCheck, seatOccupiedCheck; + public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, invertedStairCheck, seatOccupiedCheck, invertedStepCheck; public double sittingHeight, distance; public int maxChairWidth; private File pluginFolder; @@ -33,6 +33,7 @@ public class Chairs extends JavaPlugin { @Override public void onEnable() { + pluginFolder = getDataFolder(); configFile = new File(pluginFolder, "config.yml"); createConfig(); @@ -65,7 +66,7 @@ public class Chairs extends JavaPlugin { } } - private void loadConfig() { + private void loadConfig() { autoRotate = getConfig().getBoolean("auto-rotate"); sneaking = getConfig().getBoolean("sneaking"); signCheck = getConfig().getBoolean("sign-check"); @@ -76,10 +77,15 @@ public class Chairs extends JavaPlugin { notifyplayer = getConfig().getBoolean("notify-player"); invertedStairCheck = getConfig().getBoolean("upside-down-check"); seatOccupiedCheck = getConfig().getBoolean("seat-occupied-check"); + invertedStepCheck = getConfig().getBoolean("upper-step-check"); for (String type : getConfig().getStringList("allowed-blocks")) { try { - allowedBlocks.add(Material.getMaterial(type)); + if (type.matches("\\d+")) { + allowedBlocks.add(Material.getMaterial(Integer.parseInt(type))); + } else { + allowedBlocks.add(Material.getMaterial(type)); + } } catch (Exception e) { logInfo("ERROR: " + e.getMessage()); @@ -126,7 +132,7 @@ public class Chairs extends JavaPlugin { // Send stand packet to all online players public void sendStand(Player p) { if (sit.containsKey(p.getName())) { - if (notifyplayer) { + if (notifyplayer) { p.sendMessage(ChatColor.GRAY + "You are no longer sitting."); } sit.remove(p.getName()); @@ -144,4 +150,5 @@ public class Chairs extends JavaPlugin { public void logError(String _message) { log.log(Level.SEVERE, String.format("%s %s", LOG_HEADER, _message)); } + } diff --git a/src/net/spoothie/chairs/EventListener.java b/src/net/spoothie/chairs/EventListener.java index 4608497..7009088 100644 --- a/src/net/spoothie/chairs/EventListener.java +++ b/src/net/spoothie/chairs/EventListener.java @@ -1,5 +1,6 @@ package net.spoothie.chairs; +import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; import org.bukkit.Bukkit; @@ -19,6 +20,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.material.Stairs; +import org.bukkit.material.Step; public class EventListener implements Listener { @@ -36,7 +38,7 @@ public class EventListener implements Listener { Location from = player.getLocation(); Location to = plugin.sit.get(pname); if (from.getWorld() == to.getWorld()) { - if (from.distance(to) > 1) { + if (from.distance(to) > 1.5) { plugin.sendStand(player); } else { plugin.sendSit(player); @@ -75,12 +77,17 @@ public class EventListener implements Listener { public void onBlockDestroy(BlockBreakEvent event) { Block block = event.getBlock(); if (!plugin.sit.isEmpty()) { + ArrayList standList = new ArrayList(); for (String s : plugin.sit.keySet()) { if (plugin.sit.get(s).equals(block.getLocation())) { - Player player = Bukkit.getPlayer(s); - plugin.sendStand(player); + standList.add(s); } } + for (String s : standList) { + Player player = Bukkit.getPlayer(s); + plugin.sendStand(player); + } + standList.clear(); } } @@ -89,36 +96,40 @@ public class EventListener implements Listener { if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block block = event.getClickedBlock(); 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; } - if (plugin.allowedBlocks.contains(block.getType())) { - Player player = event.getPlayer(); + Player player = event.getPlayer(); + // Permissions Check + if (plugin.permissions) { + if (!player.hasPermission("chairs.sit")) { + return; + } + } + if (plugin.allowedBlocks.contains(block.getType()) + || player.hasPermission("chairs.sit." + block.getTypeId()) + || player.hasPermission("chairs.sit." + block.getType().toString()) ) { + int chairwidth = 1; // Check if block beneath chair is solid. - if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR) { + if (block.getRelative(BlockFace.DOWN).isLiquid()) { return; } - if (block.getRelative(BlockFace.DOWN).getType() == Material.WATER) { + if (block.getRelative(BlockFace.DOWN).isEmpty()) { return; } - if (block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { + if (!net.minecraft.server.v1_4_5.Block.byId[block.getTypeId()].material.isSolid()) { return; - } - if (!net.minecraft.server.Block.byId[block.getTypeId()].material.isSolid()) { - return; - } - - // Permissions Check - if (plugin.permissions) { - if (!player.hasPermission("chairs.sit")) { - return; - } - } - + } + // Check if player is sitting. - if (plugin.sit.containsKey(event.getPlayer().getName())) { plugin.sit.remove(player.getName()); event.setCancelled(true); @@ -139,6 +150,11 @@ public class EventListener implements Listener { return; } } + if (step != null) { + if (step.isInverted() && plugin.invertedStepCheck) { + return; + } + } // Check for signs. if (plugin.signCheck == true && stairs != null) { @@ -193,7 +209,7 @@ public class EventListener implements Listener { // Rotate the player's view to the descending side of the block. if (plugin.autoRotate && stairs != null) { Location plocation = block.getLocation().clone(); - plocation.add(0.5D, (plugin.sittingHeight - 0.5), 0.5D); + plocation.add(0.5D, (sh - 0.5D), 0.5D); switch (stairs.getDescendingDirection()) { case NORTH: plocation.setYaw(90); @@ -207,11 +223,11 @@ public class EventListener implements Listener { case WEST: plocation.setYaw(0); } - player.teleport(plocation); - } else { - player.teleport(block.getLocation().add(0.5D, 0.0D, 0.5D)); + Location plocation = block.getLocation().clone(); + plocation.setYaw(player.getLocation().getYaw()); + player.teleport(plocation.add(0.5D, (sh - 0.5D), 0.5D)); } player.setSneaking(true); if (plugin.notifyplayer) { @@ -222,8 +238,7 @@ public class EventListener implements Listener { Timer timer = new Timer(); long delay = 1 * 2000; - timer.schedule(new sendSitTask(), delay); - //plugin.sendSit(player); + timer.schedule(new sendSitTask(), delay); } } } diff --git a/src/plugin.yml b/src/plugin.yml index deca77c..714944a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 1.10.1 +version: 1.13.0 description: Let players sit on blocks. authors: - spoothie