Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.02 KB | None | 0 0
  1. package pw.trollkit.troll;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.GameMode;
  8. import org.bukkit.Material;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  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.player.PlayerInteractEvent;
  17. import org.bukkit.event.player.PlayerJoinEvent;
  18. import org.bukkit.event.player.PlayerQuitEvent;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20. import org.bukkit.potion.PotionEffect;
  21. import org.bukkit.potion.PotionEffectType;
  22. import org.bukkit.inventory.Inventory;
  23. import org.bukkit.inventory.ItemStack;
  24. import org.bukkit.inventory.meta.SkullMeta;
  25.  
  26. // Need this for listeners
  27. public class Troll extends JavaPlugin implements Listener {
  28.  
  29. @Override
  30. public void onEnable() {
  31. // You don't need this....
  32. getLogger().info("Trolling Plugin");
  33.  
  34. // Got to register it
  35. }
  36.  
  37. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  38.  
  39. // If console just cancel everything (return)
  40. if(!(sender instanceof Player))
  41. return true;
  42.  
  43. Player p = (Player) sender;
  44.  
  45. if (cmd.getName().equalsIgnoreCase("troll")) {
  46.  
  47. if (p.getGameMode().equals(GameMode.SURVIVAL)) {
  48. p.setGameMode(GameMode.CREATIVE);
  49. }
  50. }
  51. ItemStack item = new ItemStack(Material.SULPHUR, 1);
  52. ItemStack item1 = new ItemStack(Material.BOOK, 1);
  53. ItemStack item2 = new ItemStack(Material.COMPASS, 1);
  54.  
  55. p.getInventory().setItem(4, item);
  56. p.getInventory().setItem(8, item1);
  57. p.getInventory().setItem(0, item2);
  58.  
  59. p.sendMessage(ChatColor.BOLD + "Troll Mode Activated");
  60.  
  61. return false;
  62. }
  63. private void openGUI(Player player) {
  64.  
  65. Inventory i = getServer().createInventory(null, 27, ChatColor.RED + "Troll Menu"); {
  66.  
  67. // Add item for every player
  68. for (Player pl : Bukkit.getOnlinePlayers()){
  69. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
  70. SkullMeta meta = (SkullMeta) skull.getItemMeta();
  71. // Owner = Player's name for the head, name = what shows up to you
  72. meta.setDisplayName(ChatColor.DARK_PURPLE + "Teleport to " + pl.getName());
  73. meta.setOwner(pl.getName());
  74. skull.setItemMeta(meta);
  75. i.addItem(skull);
  76. }
  77. player.openInventory(i);
  78. }
  79. }
  80. @EventHandler
  81. public void onPlayerInteract(PlayerInteractEvent e) {
  82.  
  83. Action a = e.getAction();
  84. ItemStack is = e.getItem();
  85.  
  86. if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
  87. Player player = (e.getPlayer());
  88.  
  89. if(a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
  90. return;
  91.  
  92. if( is.getType() == Material.COMPASS){
  93. openGUI(e.getPlayer());
  94. }
  95. }
  96. }
  97. // TODO Auto-generated method stub
  98.  
  99.  
  100. // TODO Auto-generated method stub
  101.  
  102. // Return true, bukkit thinks an error happened if you return false
  103.  
  104. //TODO
  105. // Get clicked item's name from inventory through item meta.
  106. // If online (not null), teleport to them then close inv }
  107. // TODO Auto-generated method stub
  108.  
  109. @EventHandler
  110. public void onInventoryClick(InventoryClickEvent event) {
  111.  
  112. if(!ChatColor.stripColor(event.getInventory().getName())
  113. .equalsIgnoreCase("Troll Menu"))
  114. return;
  115. Player player = (Player) event.getWhoClicked();
  116. event.setCancelled(true);
  117.  
  118. if(event.getCurrentItem()==null
  119. || event.getCurrentItem().getType()==Material.AIR
  120. || !event.getCurrentItem().hasItemMeta()) {
  121. player.closeInventory();
  122. return;
  123. }
  124. switch (event.getCurrentItem().getType()) {
  125. case SKULL_ITEM:
  126. player.sendMessage(ChatColor.DARK_PURPLE + "Teleport to " + Bukkit.getOnlinePlayers());
  127. player.teleport(player);
  128. break;
  129. default:
  130. player.closeInventory();
  131. break;
  132. }
  133. if(event.getCurrentItem()==null
  134. || event.getCurrentItem().getType()==Material.AIR
  135. || !event.getCurrentItem().hasItemMeta()) {
  136. player.closeInventory();
  137. return;
  138. }
  139. }
  140. @EventHandler
  141. public void onPlayerInteract2(PlayerInteractEvent e) {
  142. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  143.  
  144. Action a = e.getAction();
  145. ItemStack is = e.getItem();
  146.  
  147. if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
  148. Player player = (e.getPlayer());
  149.  
  150. if( is.getType() == Material.SULPHUR) {
  151.  
  152. ItemStack item5 = new ItemStack(Material.REDSTONE, 1);
  153.  
  154. player.getInventory().setItem(4, item5);
  155.  
  156. if(is.getType() == Material.SULPHUR) {
  157.  
  158. if(player.getInventory().contains(Material.SULPHUR)) {
  159.  
  160. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000, 1));
  161.  
  162. player.sendMessage(ChatColor.ITALIC + "You have been vanished!");
  163. }
  164. }
  165. }
  166. }
  167. }
  168. @EventHandler
  169. public void onPlayerInteract21(PlayerInteractEvent e) {
  170. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  171.  
  172. Action a = e.getAction();
  173. ItemStack is = e.getItem();
  174.  
  175. if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
  176. Player player = (e.getPlayer());
  177.  
  178. if(a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
  179.  
  180. if( is.getType() == Material.REDSTONE) {
  181.  
  182. ItemStack item5 = new ItemStack(Material.SULPHUR, 1);
  183.  
  184. player.getInventory().setItem(4, item5);
  185.  
  186. if(is.getType() == Material.REDSTONE) {
  187.  
  188. if(player.getInventory().contains(Material.SULPHUR)) {
  189.  
  190. if (player.hasPotionEffect(PotionEffectType.INVISIBILITY) == true)
  191.  
  192. player.removePotionEffect(PotionEffectType.INVISIBILITY);
  193. player.sendMessage(ChatColor.ITALIC + "You are no longer vanished!");
  194. }
  195.  
  196. }
  197. }
  198. }
  199. }
  200.  
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement