Advertisement
eekelmo

Working Code

May 22nd, 2016
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.Eekelmo.GUITP;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.block.Action;
  11. import org.bukkit.event.inventory.InventoryClickEvent;
  12. import org.bukkit.event.player.PlayerInteractEvent;
  13. import org.bukkit.inventory.Inventory;
  14. import org.bukkit.inventory.ItemStack;
  15. import org.bukkit.inventory.meta.ItemMeta;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17.  
  18. public class gui extends JavaPlugin implements Listener {
  19. // Enable
  20. @Override
  21. public void onEnable() {
  22. getServer().getPluginManager().registerEvents(this, this);
  23. getLogger().info("-------- GUI TP by Eekelmo enabled -------");
  24. }
  25.  
  26. // Disable
  27. @Override
  28. public void onDisable() {
  29. getLogger().info("-------- GUI TP by Eekelmo disabled -------");
  30. }
  31.  
  32. // Teleport thing
  33. private void teleportInWorld(Player player, int x, int y, int z) {
  34. player.teleport(new Location(player.getWorld(), x, y, z));
  35.  
  36. }
  37.  
  38. private void openGUI(Player player) {
  39. Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GREEN + "World Selector");
  40. // Main world
  41. ItemStack mainworld = new ItemStack(Material.NETHER_STAR);
  42. ItemMeta mainworldMeta = mainworld.getItemMeta();
  43. // Mining
  44. ItemStack miningworld = new ItemStack(Material.DIAMOND_PICKAXE);
  45. ItemMeta miningworldMeta = miningworld.getItemMeta();
  46. // Setting text
  47. mainworldMeta.setDisplayName(ChatColor.DARK_RED + "Main");
  48. mainworld.setItemMeta(mainworldMeta);
  49. // Setting text
  50. miningworldMeta.setDisplayName(ChatColor.GREEN + "Mining");
  51. miningworld.setItemMeta(miningworldMeta);
  52. // Setting placement
  53. inv.setItem(3, mainworld);
  54. inv.setItem(5, miningworld);
  55. // Opening
  56. player.openInventory(inv);
  57. }
  58.  
  59. @EventHandler
  60. public void onInventoryClick(InventoryClickEvent event) {
  61. if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("World Selector"))
  62. return;
  63. Player player = (Player) event.getWhoClicked();
  64. event.setCancelled(true);
  65.  
  66. if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR
  67. || !event.getCurrentItem().hasItemMeta()) {
  68. player.closeInventory();
  69. return;
  70. }
  71.  
  72. switch (event.getCurrentItem().getType()) {
  73. case NETHER_STAR:
  74. teleportInWorld(player, -1034, 76, -849);
  75. player.closeInventory();
  76. event.setCancelled(true);
  77. player.sendMessage(String.format("&sTeleported to the &sMain World&s!", ChatColor.GOLD, ChatColor.DARK_RED, ChatColor.GOLD));
  78. break;
  79. case DIAMOND_PICKAXE:
  80. teleportInWorld(player, -945, 69, -873);
  81. player.closeInventory();
  82. event.setCancelled(true);
  83. player.sendMessage(String.format("&sTeleported to the &sMining World&s!", ChatColor.GOLD, ChatColor.GREEN, ChatColor.GOLD));
  84. break;
  85. default:
  86. player.closeInventory();
  87. break;
  88. }
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. @EventHandler
  98. public void onPlayerInteract(PlayerInteractEvent event) {
  99. Action a = event.getAction();
  100. ItemStack is = event.getItem();
  101. if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
  102. return;
  103. if(is.getType() == Material.COMPASS)
  104. getLogger().info("Compass used successfully");
  105. openGUI(event.getPlayer());
  106. }
  107.  
  108. }
Advertisement
RAW Paste Data Copied
Advertisement