Guest User

Untitled

a guest
Aug 25th, 2019
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.dani17val.lutorcrafts;
  2.  
  3. import java.util.Iterator;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Material;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.HumanEntity;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.block.Action;
  15. import org.bukkit.event.inventory.InventoryClickEvent;
  16. import org.bukkit.event.inventory.InventoryCloseEvent;
  17. import org.bukkit.event.inventory.InventoryDragEvent;
  18. import org.bukkit.event.inventory.InventoryType;
  19. import org.bukkit.event.player.PlayerInteractEvent;
  20. import org.bukkit.inventory.CraftingInventory;
  21. import org.bukkit.inventory.Inventory;
  22. import org.bukkit.inventory.ItemStack;
  23. import org.bukkit.plugin.java.JavaPlugin;
  24.  
  25. public final class Lutorcrafts extends JavaPlugin implements Listener {
  26.  
  27. private static final String nombreInv = ChatColor.BLUE + "Mesa de trabajo";
  28.  
  29. @Override
  30. public void onEnable() {
  31. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  32. }
  33.  
  34. @Override
  35. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  36. Player j = (Player) sender;
  37. if(!j.hasPermission("lutorlandia.lutorcrafts")){
  38. j.sendMessage(ChatColor.RED+"No tienes permisos.");
  39. return true;
  40. }
  41. if (label.equalsIgnoreCase("lutorcrafts") || label.equalsIgnoreCase("lutorcraft")) {
  42. Inventory mesa = Bukkit.createInventory(null, InventoryType.WORKBENCH, nombreInv);
  43. j.openInventory(mesa);
  44. j.sendMessage("Abriendo mesa por comando...");
  45. return true;
  46. }
  47. return true;
  48. }
  49.  
  50. @EventHandler
  51. public void clickDerecho(PlayerInteractEvent e) {
  52. Player j = e.getPlayer();
  53. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
  54. if (e.getClickedBlock().getType() == Material.CRAFTING_TABLE && !e.getPlayer().isSneaking()) {
  55. Inventory mesa = Bukkit.createInventory(null, InventoryType.WORKBENCH, nombreInv);
  56. j.openInventory(mesa);
  57. j.sendMessage("Abriendo mesa...");
  58. e.setCancelled(true);
  59. }
  60. }
  61. }
  62.  
  63. @EventHandler
  64. public void alDrag(InventoryDragEvent e) {
  65. if (e.getInventory().getName().equalsIgnoreCase(nombreInv)) {
  66. if (e.getInventorySlots().contains(25)) {
  67. e.setCancelled(true);
  68. }
  69. }
  70. }
  71.  
  72. @EventHandler
  73. public void alClickarEnGui(InventoryClickEvent e) {
  74. Inventory inv = e.getInventory();
  75. HumanEntity p = e.getWhoClicked();
  76. if (inv instanceof CraftingInventory) {
  77. p.sendMessage("Es crafting");
  78. CraftingInventory ci = (CraftingInventory) inv;
  79. if (ci.getName().equals(nombreInv)) {
  80. p.sendMessage("Es la nuestra");
  81. /*
  82. int slot = e.getSlot();
  83. ItemStack item = e.getCurrentItem();
  84. if (item != null && item.getType() == Material.GRAY_STAINED_GLASS_PANE
  85. && item.getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
  86. e.setCancelled(true);
  87. } else if (slot == 10 || slot == 11 || slot == 12 || slot == 19 || slot == 20 || slot == 21
  88. || slot == 28 || slot == 29 || slot == 30) {
  89. } else if ((slot == 25) || (e.getAction().equals(InventoryAction.PLACE_ONE)
  90. || (e.getAction().equals(InventoryAction.PLACE_SOME))
  91. || e.getAction().equals(InventoryAction.PLACE_ALL))) {
  92. e.setCancelled(true);
  93. }
  94. */
  95. getServer().broadcastMessage("xD");
  96. }
  97. }
  98. }
  99.  
  100. @EventHandler
  101. public void alSalirDeGui(InventoryCloseEvent e) {
  102. Inventory inv = e.getInventory();
  103. HumanEntity p = e.getPlayer();
  104. p.sendMessage("xD");
  105. if (inv instanceof CraftingInventory) {
  106. p.sendMessage("Es crafting");
  107. CraftingInventory ci = (CraftingInventory) inv;
  108. if (ci.getName().equals(nombreInv)) {
  109. p.sendMessage("Es la nuestra");
  110. Iterator<ItemStack> ite = ci.iterator();
  111. p.sendMessage("matriz: ");
  112. for(int i=0; i<ci.getContents().length; i++) {
  113. p.sendMessage(" "+i+": "+ci.getContents()[i].getType());
  114. }
  115. while(ite.hasNext()) {
  116. ItemStack item = ite.next();
  117. if (item != null) {
  118. p.sendMessage("xD item "+item.getType());
  119. p.getWorld().dropItem(p.getLocation(), item);
  120. }else
  121. p.sendMessage("xD item null");
  122. }
  123. }
  124. }
  125. }
  126. }
RAW Paste Data