From f5430b9101fd5298e612ba88c2907f246a64c080 Mon Sep 17 00:00:00 2001 From: cnaude Date: Sun, 23 Dec 2012 00:24:06 -0700 Subject: [PATCH] Update for 1.4.6-R1.0. --- src/config.yml | 4 +++- src/net/spoothie/chairs/ChairWatcher.java | 4 ++-- src/net/spoothie/chairs/Chairs.java | 17 +++++++++++----- src/net/spoothie/chairs/EventListener.java | 23 ++++++++++++++++++---- src/plugin.yml | 8 ++++++-- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/config.yml b/src/config.yml index a08c279..4acaed1 100644 --- a/src/config.yml +++ b/src/config.yml @@ -11,6 +11,7 @@ # sitting-height: Set how high you are sitting 'in' the stairs block (default is 0.7). # 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. # ------ allowed-blocks: - WOOD_STAIRS @@ -32,4 +33,5 @@ permissions: true notify-player: true upside-down-check: true seat-occupied-check: true -upper-step-check: true \ No newline at end of file +upper-step-check: true +per-item-perms: true \ No newline at end of file diff --git a/src/net/spoothie/chairs/ChairWatcher.java b/src/net/spoothie/chairs/ChairWatcher.java index 8258010..061a382 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_5.DataWatcher; -import net.minecraft.server.v1_4_5.WatchableObject; +import net.minecraft.server.v1_4_6.DataWatcher; +import net.minecraft.server.v1_4_6.WatchableObject; /** diff --git a/src/net/spoothie/chairs/Chairs.java b/src/net/spoothie/chairs/Chairs.java index fb082ed..22a550a 100644 --- a/src/net/spoothie/chairs/Chairs.java +++ b/src/net/spoothie/chairs/Chairs.java @@ -6,21 +6,23 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.v1_4_5.Packet40EntityMetadata; +import net.minecraft.server.v1_4_6.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.v1_4_5.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; 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, invertedStepCheck; + public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer; + public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms; public double sittingHeight, distance; public int maxChairWidth; private File pluginFolder; @@ -30,6 +32,7 @@ public class Chairs extends JavaPlugin { public static final String PLUGIN_NAME = "Chairs"; public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]"; static final Logger log = Logger.getLogger("Minecraft"); + public PluginManager pm; @Override public void onEnable() { @@ -42,6 +45,7 @@ public class Chairs extends JavaPlugin { loadConfig(); EventListener eventListener = new EventListener(this); getServer().getPluginManager().registerEvents(eventListener, this); + pm = this.getServer().getPluginManager(); } @Override @@ -78,6 +82,7 @@ public class Chairs extends JavaPlugin { invertedStairCheck = getConfig().getBoolean("upside-down-check"); seatOccupiedCheck = getConfig().getBoolean("seat-occupied-check"); invertedStepCheck = getConfig().getBoolean("upper-step-check"); + perItemPerms = getConfig().getBoolean("per-item-perms"); for (String type : getConfig().getStringList("allowed-blocks")) { try { @@ -116,7 +121,8 @@ public class Chairs extends JavaPlugin { public void sendSit(Player p) { Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false); for (Player play : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet); + ((CraftPlayer) play).getHandle().playerConnection.sendPacket(packet); + //((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet); } } @@ -139,7 +145,8 @@ public class Chairs extends JavaPlugin { } Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 0), false); for (Player play : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet); + ((CraftPlayer) play).getHandle().playerConnection.sendPacket(packet); + //((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet); } } diff --git a/src/net/spoothie/chairs/EventListener.java b/src/net/spoothie/chairs/EventListener.java index 7009088..1b6e2e5 100644 --- a/src/net/spoothie/chairs/EventListener.java +++ b/src/net/spoothie/chairs/EventListener.java @@ -21,6 +21,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.material.Stairs; import org.bukkit.material.Step; +import org.bukkit.permissions.PermissionDefault; public class EventListener implements Listener { @@ -94,7 +95,7 @@ public class EventListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { - Block block = event.getClickedBlock(); + Block block = event.getClickedBlock(); Stairs stairs = null; Step step = null; double sh = plugin.sittingHeight; @@ -112,9 +113,23 @@ public class EventListener implements Listener { return; } } + if (plugin.perItemPerms) { + if (plugin.pm.getPermission("chairs.sit." + block.getTypeId()) == null) { + plugin.pm.addPermission(new org.bukkit.permissions.Permission( + "chairs.sit." + block.getTypeId(), + "Allow players to sit on a '" + block.getType().name() + "'", + PermissionDefault.FALSE)); + } + if (plugin.pm.getPermission("chairs.sit." + block.getType().toString()) == null) { + plugin.pm.addPermission(new org.bukkit.permissions.Permission( + "chairs.sit." + block.getType().toString(), + "Allow players to sit on a '" + block.getType().name() + "'", + PermissionDefault.FALSE)); + } + } if (plugin.allowedBlocks.contains(block.getType()) - || player.hasPermission("chairs.sit." + block.getTypeId()) - || player.hasPermission("chairs.sit." + block.getType().toString()) ) { + || (player.hasPermission("chairs.sit." + block.getTypeId()) && plugin.perItemPerms) + || (player.hasPermission("chairs.sit." + block.getType().toString())&& plugin.perItemPerms) ) { int chairwidth = 1; @@ -125,7 +140,7 @@ public class EventListener implements Listener { if (block.getRelative(BlockFace.DOWN).isEmpty()) { return; } - if (!net.minecraft.server.v1_4_5.Block.byId[block.getTypeId()].material.isSolid()) { + if (!net.minecraft.server.v1_4_6.Block.byId[block.getTypeId()].material.isSolid()) { return; } diff --git a/src/plugin.yml b/src/plugin.yml index 714944a..9a5bf69 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 1.13.0 +version: 1.13.2 description: Let players sit on blocks. authors: - spoothie @@ -8,4 +8,8 @@ main: net.spoothie.chairs.Chairs commands: chairs: description: Reloads the Chairs configuration file. - usage: /chairs reload \ No newline at end of file + usage: /chairs reload +permissions: + chairs.sit: + description: Allows players to sit on blocks. + default: false \ No newline at end of file