Advertisement
calebbfmv

My code/still in progress

Jul 28th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1.  
  2. package me.calebbfmv.ChestLock;
  3.  
  4.  
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.permissions.Permission;
  8. import org.bukkit.plugin.PluginDescriptionFile;
  9. import org.bukkit.plugin.PluginManager;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11.  
  12. public class ChestLock extends JavaPlugin {
  13.  
  14. public PlayerListener playerListener = new PlayerListener();
  15. public Logger log = Logger.getLogger("Minecraft");
  16. public Permission openPermission = new Permission("chestlock.open");
  17. public Permission allowPermission = new Permission ("chestlock.allow");
  18.  
  19.  
  20. public void onDisbale() {
  21. PluginDescriptionFile pdffile = this.getDescription();
  22. log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now disabled.");
  23.  
  24. }
  25.  
  26. @Override
  27. public void onEnable() {
  28. PluginDescriptionFile pdffile = this.getDescription();
  29. log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now enabled.");
  30. PluginManager pm = getServer().getPluginManager();
  31. pm.addPermission(openPermission);
  32. pm.addPermission(allowPermission);
  33. pm.registerEvents(this.playerListener, this);
  34. }
  35.  
  36. }
  37. PlayerListener Class:
  38. package me.calebbfmv.ChestLock;
  39.  
  40.  
  41. import java.util.logging.Logger;
  42.  
  43. import org.bukkit.ChatColor;
  44. import org.bukkit.Location;
  45. import org.bukkit.block.Block;
  46. import org.bukkit.entity.Player;
  47. import org.bukkit.event.EventHandler;
  48. import org.bukkit.event.Listener;
  49. import org.bukkit.event.block.Action;
  50. import org.bukkit.event.player.PlayerInteractEvent;
  51.  
  52. public class PlayerListener implements Listener {
  53.  
  54.  
  55. public ChestLock plugin;
  56. public Logger log = Logger.getLogger("Minecraft");
  57.  
  58. @EventHandler
  59. public void onPlayerInteract(PlayerInteractEvent event) {
  60. if(event.getAction()==Action.RIGHT_CLICK_BLOCK ||event.getAction()==Action.LEFT_CLICK_BLOCK) {
  61. Player p = event.getPlayer();
  62. Block block = event.getClickedBlock();
  63.  
  64. Location blockAboveLocation = block.getLocation().add(0, 1, 0);
  65. Block blockAbove = blockAboveLocation.getBlock();
  66.  
  67. if(block.getTypeId() == 54|| blockAbove.getTypeId() == 54) {{
  68. if(!p.hasPermission("chestlock.open")) {
  69. p.sendMessage(ChatColor.BLUE + "You are not allowed to open this.");
  70. event.setCancelled(true);
  71. if(p.hasPermission("chestlock.allow")) {
  72. p.sendMessage(ChatColor.GOLD + "You have granted <player> to open your chests");
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement