I want to tp a player to my "wilderness" server, as soon as he clicks the right item in the gui.
I tried doing it via localized names, but i am still a beginenr and i dont know how to get the other server etc.
THis si the code where stuff gets executed as soon as a item is clicked. u will notice there is nothig under "wilderness", since i dont know how.
package me.lorin.interactivegui.Listeners;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import static org.bukkit.Bukkit.getServer;
public class InventoryListener implements Listener {
@EventHandlerpublic void onInvClick(InventoryClickEvent event) {
if (event.getCurrentItem() == null) return;
if(event.getView().getTitle() == "Menu") {
Player player = (Player) event.getWhoClicked();
event.setCancelled(true);
if(event.getCurrentItem().getItemMeta().hasLocalizedName()){
switch(event.getCurrentItem().getItemMeta().getLocalizedName()){
case "Survival":
player.setGameMode(GameMode.SURVIVAL);
player.closeInventory();
break;
case "Creative":
player.setGameMode(GameMode.CREATIVE);
player.closeInventory();
break;
case "Wilderness":
}
}
}
}
}
And here is how the items are set:
import me.lorin.interactivegui.Util.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryCommand implements CommandExecutor {
@Overridepublic boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if(!(sender instanceof Player)) return false;
Player player = (Player) sender;
Inventory inventory = Bukkit.createInventory(null, 45, "Menu");
inventory.setItem(13, new ItemBuilder(Material.PAPER).setDisplayname(player.getName()).setLore("Watch your stats!").build());
if(player.getGameMode() == GameMode.CREATIVE){
inventory.setItem(31, new ItemBuilder(Material.REDSTONE_LAMP).setDisplayname("Switch GameMode!").setLocalizedName("Survival").setLore("Switch to Survival!").build());
}else {
inventory.setItem(31, new ItemBuilder(Material.REDSTONE_LAMP).setDisplayname("Switch GameMode!").setLocalizedName("Creative").setLore("Switch to Creative!").build());
}
inventory.setItem(20, new ItemBuilder(Material.GRASS_BLOCK).setDisplayname("Teleport").setLore("TP TO WILDERNESS").setLocalizedName("Wilderness").build());
player.openInventory(inventory);
return false;
}
}
Thank you in advance.
I tried doing it via localized names, but i am still a beginenr and i dont know how to get the other server etc.
THis si the code where stuff gets executed as soon as a item is clicked. u will notice there is nothig under "wilderness", since i dont know how.
package me.lorin.interactivegui.Listeners;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import static org.bukkit.Bukkit.getServer;
public class InventoryListener implements Listener {
@EventHandlerpublic void onInvClick(InventoryClickEvent event) {
if (event.getCurrentItem() == null) return;
if(event.getView().getTitle() == "Menu") {
Player player = (Player) event.getWhoClicked();
event.setCancelled(true);
if(event.getCurrentItem().getItemMeta().hasLocalizedName()){
switch(event.getCurrentItem().getItemMeta().getLocalizedName()){
case "Survival":
player.setGameMode(GameMode.SURVIVAL);
player.closeInventory();
break;
case "Creative":
player.setGameMode(GameMode.CREATIVE);
player.closeInventory();
break;
case "Wilderness":
}
}
}
}
}
And here is how the items are set:
import me.lorin.interactivegui.Util.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryCommand implements CommandExecutor {
@Overridepublic boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if(!(sender instanceof Player)) return false;
Player player = (Player) sender;
Inventory inventory = Bukkit.createInventory(null, 45, "Menu");
inventory.setItem(13, new ItemBuilder(Material.PAPER).setDisplayname(player.getName()).setLore("Watch your stats!").build());
if(player.getGameMode() == GameMode.CREATIVE){
inventory.setItem(31, new ItemBuilder(Material.REDSTONE_LAMP).setDisplayname("Switch GameMode!").setLocalizedName("Survival").setLore("Switch to Survival!").build());
}else {
inventory.setItem(31, new ItemBuilder(Material.REDSTONE_LAMP).setDisplayname("Switch GameMode!").setLocalizedName("Creative").setLore("Switch to Creative!").build());
}
inventory.setItem(20, new ItemBuilder(Material.GRASS_BLOCK).setDisplayname("Teleport").setLore("TP TO WILDERNESS").setLocalizedName("Wilderness").build());
player.openInventory(inventory);
return false;
}
}
Thank you in advance.
- Version Output
- git-Paper-499 (MC: 1.19.4)
Last edited: