From 896487cfce968c693355c16ad30cd304dcbb6cca Mon Sep 17 00:00:00 2001 From: cnaude Date: Sun, 3 Feb 2013 17:19:49 -0700 Subject: [PATCH] Some code cleanup (removed old NMS code) Add item frames to work the same way signs do. --- src/config.yml | 5 +++ src/net/spoothie/chairs/ChairWatcher.java | 4 +- src/net/spoothie/chairs/Chairs.java | 19 ++++++++- src/net/spoothie/chairs/ChairsCommand.java | 1 - src/net/spoothie/chairs/EventListener.java | 48 ++++++++++++++++++---- src/plugin.yml | 2 +- 6 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/config.yml b/src/config.yml index 66cc49f..5449b78 100644 --- a/src/config.yml +++ b/src/config.yml @@ -23,6 +23,11 @@ allowed-blocks: - BRICK_STAIRS - SMOOTH_STAIRS - NETHER_BRICK_STAIRS +valid-signs: + - SIGN + - WALL_SIGN + - SIGN_POST + - ITEM_FRAME auto-rotate: true sneaking: true max-chair-width: 3 diff --git a/src/net/spoothie/chairs/ChairWatcher.java b/src/net/spoothie/chairs/ChairWatcher.java index 061a382..70df9aa 100644 --- a/src/net/spoothie/chairs/ChairWatcher.java +++ b/src/net/spoothie/chairs/ChairWatcher.java @@ -5,8 +5,8 @@ package net.spoothie.chairs; import java.util.ArrayList; -import net.minecraft.server.v1_4_6.DataWatcher; -import net.minecraft.server.v1_4_6.WatchableObject; +import net.minecraft.server.v1_4_R1.DataWatcher; +import net.minecraft.server.v1_4_R1.WatchableObject; /** diff --git a/src/net/spoothie/chairs/Chairs.java b/src/net/spoothie/chairs/Chairs.java index 36a49fd..a747b0d 100644 --- a/src/net/spoothie/chairs/Chairs.java +++ b/src/net/spoothie/chairs/Chairs.java @@ -6,12 +6,12 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.v1_4_6.Packet40EntityMetadata; +import net.minecraft.server.v1_4_R1.Packet40EntityMetadata; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -21,6 +21,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class Chairs extends JavaPlugin { private static Chairs instance = null; 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; @@ -34,6 +35,7 @@ public class Chairs extends JavaPlugin { static final Logger log = Logger.getLogger("Minecraft"); public PluginManager pm; public static ChairsIgnoreList ignoreList; + @Override public void onEnable() { @@ -102,6 +104,19 @@ public class Chairs extends JavaPlugin { } } + 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)); + } + } + catch (Exception e) { + logInfo("ERROR: " + e.getMessage()); + } + } + ArrayList perms = new ArrayList(); perms.add("chairs.sit"); perms.add("chairs.reload"); diff --git a/src/net/spoothie/chairs/ChairsCommand.java b/src/net/spoothie/chairs/ChairsCommand.java index 2f43f3d..a556081 100644 --- a/src/net/spoothie/chairs/ChairsCommand.java +++ b/src/net/spoothie/chairs/ChairsCommand.java @@ -4,7 +4,6 @@ */ package net.spoothie.chairs; -import java.io.Console; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/src/net/spoothie/chairs/EventListener.java b/src/net/spoothie/chairs/EventListener.java index 9af50de..db3a84a 100644 --- a/src/net/spoothie/chairs/EventListener.java +++ b/src/net/spoothie/chairs/EventListener.java @@ -7,8 +7,11 @@ 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; +import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; @@ -141,11 +144,11 @@ public class EventListener implements Listener { // Check if block beneath chair is solid. if (block.getRelative(BlockFace.DOWN).isLiquid()) { return; - } + } if (block.getRelative(BlockFace.DOWN).isEmpty()) { return; - } - if (!net.minecraft.server.v1_4_6.Block.byId[block.getTypeId()].material.isSolid()) { + } + if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) { return; } @@ -182,11 +185,11 @@ public class EventListener implements Listener { boolean sign2 = false; if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { - sign1 = checkSign(block, BlockFace.EAST); - sign2 = checkSign(block, BlockFace.WEST); + sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player); + sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player); } else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { - sign1 = checkSign(block, BlockFace.NORTH); - sign2 = checkSign(block, BlockFace.SOUTH); + sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player); + sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player); } if (!(sign1 == true && sign2 == true)) { @@ -285,9 +288,9 @@ public class EventListener implements Listener { private boolean checkSign(Block block, BlockFace face) { // Go through the blocks next to the clicked block and check if are signs on the end. for (int i = 1; true; i++) { - Block relative = block.getRelative(face, i); + Block relative = block.getRelative(face, i); if (!plugin.allowedBlocks.contains(relative.getType()) || (block.getState().getData() instanceof Stairs && ((Stairs) relative.getState().getData()).getDescendingDirection() != ((Stairs) block.getState().getData()).getDescendingDirection())) { - if (relative.getType() == Material.SIGN || relative.getType() == Material.WALL_SIGN || relative.getType() == Material.SIGN_POST) { + if (plugin.validSigns.contains(relative.getType())) { return true; } else { return false; @@ -295,4 +298,31 @@ public class EventListener implements Listener { } } } + + private boolean checkFrame(Block block, BlockFace face, Player player) { + // Go through the blocks next to the clicked block and check if are signs on the end. + + for (int i = 1; true; i++) { + Block relative = block.getRelative(face, i); + int x = relative.getLocation().getBlockX(); + int y = relative.getLocation().getBlockY(); + int z = relative.getLocation().getBlockZ(); + if (!plugin.allowedBlocks.contains(relative.getType()) || (block.getState().getData() instanceof Stairs && ((Stairs) relative.getState().getData()).getDescendingDirection() != ((Stairs) block.getState().getData()).getDescendingDirection())) { + if (relative.getType().equals(Material.AIR)) { + for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) { + if (e instanceof ItemFrame && plugin.validSigns.contains(Material.ITEM_FRAME)) { + int x2 = e.getLocation().getBlockX(); + int y2 = e.getLocation().getBlockY(); + int z2 = e.getLocation().getBlockZ(); + if (x == x2 && y == y2 && z == z2) { + return true; + } + } + } + } else { + return false; + } + } + } + } } \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index 4c756ed..29c80db 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 1.15.0 +version: 1.16.0 description: Let players sit on blocks. authors: - spoothie