From a9bdfab5aa4ae5e1ce456ab2437548b66e722d3f Mon Sep 17 00:00:00 2001 From: TheE Date: Wed, 30 May 2012 00:16:51 +0200 Subject: [PATCH] Added ability to check if player's hand is empty (turned on in config by default). --- config.yml | 4 +- src/net/spoothie/comfort/Comfort.java | 47 ++++++++++++--------- src/net/spoothie/comfort/EventListener.java | 4 ++ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/config.yml b/config.yml index a6cb78e..6359fb2 100644 --- a/config.yml +++ b/config.yml @@ -7,6 +7,7 @@ # 53: 0.5 # 44:2: 0.3 # ------ +# empty: If set to true, your hand have to be empty when you rightclick to sit down on a seat. # sneaking: If set to true, you have to sneak and rightclick to sit down on a seat. # distance: The maximum distance between the seat (the center of the block) and the player to be able to sit down (to prevent glitching through walls, etc.). # ------ @@ -15,5 +16,6 @@ blocks: '53:1': 0.5 '53:2': 0.5 '53:3': 0.5 -sneaking: true +empty: true +sneaking: false distance: 2 \ No newline at end of file diff --git a/src/net/spoothie/comfort/Comfort.java b/src/net/spoothie/comfort/Comfort.java index 5076ad5..fdc8511 100644 --- a/src/net/spoothie/comfort/Comfort.java +++ b/src/net/spoothie/comfort/Comfort.java @@ -27,7 +27,7 @@ public class Comfort extends JavaPlugin { public HashMap comfortPlayers = new HashMap(); public HashMap comfortBlocks = new HashMap(); - public boolean sneaking, useSpout; + public boolean empty, sneaking, useSpout; public double distance; private File pluginFolder; @@ -37,9 +37,9 @@ public class Comfort extends JavaPlugin { public void onEnable() { pluginFolder = getDataFolder(); configFile = new File(pluginFolder, "config.yml"); - createConfig(); - saveConfig(); - loadConfig(); + createConfig(); + saveConfig(); + loadConfig(); EventListener eventListener = new EventListener(this); getServer().getPluginManager().registerEvents(eventListener, this); @@ -76,6 +76,7 @@ private void createConfig() { } private void loadConfig() { + empty = getConfig().getBoolean("empty"); sneaking = getConfig().getBoolean("sneaking"); distance = getConfig().getDouble("distance"); @@ -87,23 +88,27 @@ private void loadConfig() { } } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (command.getName().equalsIgnoreCase("comfort")) { - if(sender instanceof Player && !((Player)sender).hasPermission("comfort.reload")) - return true; - - if(args.length > 0 && args[0].equalsIgnoreCase("reload")) { - reloadConfig(); - loadConfig(); - sender.sendMessage(ChatColor.YELLOW + "Comfort configuration file reloaded."); - } - else - sender.sendMessage(ChatColor.YELLOW + "Use '/comfort reload' to reload the configuration file."); - } - - return true; - } - + @Override + public boolean onCommand(CommandSender sender, Command command, + String label, String[] args) { + if (command.getName().equalsIgnoreCase("comfort")) { + if (sender instanceof Player + && !((Player) sender).hasPermission("comfort.reload")) + return true; + + if (args.length > 0 && args[0].equalsIgnoreCase("reload")) { + reloadConfig(); + loadConfig(); + sender.sendMessage(ChatColor.YELLOW + + "Comfort configuration file reloaded."); + } else + sender.sendMessage(ChatColor.YELLOW + + "Use '/comfort reload' to reload the configuration file."); + } + + return true; + } + public void sitDown(Player player, Block block) { player.setAllowFlight(true); player.setFlying(true); diff --git a/src/net/spoothie/comfort/EventListener.java b/src/net/spoothie/comfort/EventListener.java index defd7a1..0556fb8 100644 --- a/src/net/spoothie/comfort/EventListener.java +++ b/src/net/spoothie/comfort/EventListener.java @@ -56,6 +56,10 @@ public void onPlayerInteract(PlayerInteractEvent event) { if(plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0.5, 0.5)) > plugin.distance) return; + // Check if player's hand is empty + if(plugin.empty == true && player.getItemInHand().getType() != Material.AIR) + return; + // Check if player is sneaking. if(plugin.sneaking == false || (plugin.sneaking == true && player.isSneaking())) { plugin.sitDown(player, block);