1
我在1.10中創建了插頭插件。它主要是必需品,但是我添加了一個指南針庫存GUI,並且在您第一次登錄時收到它。出於某種奇怪的原因,我實施這個後,您無法獲取庫存中的物品,它們會立即消失。對於GUI類低於插頭插件 - 無法建立1.10
package me.Roofah.Essentials;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
public class Essentials extends JavaPlugin implements Listener{
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
this.getCommand("teleport").setExecutor(new Teleport(this));;
this.getCommand("vanish").setExecutor(new Vanish(this));;
this.getCommand("unvanish").setExecutor(new Vanish(this));;
Bukkit.getServer().getLogger().info("Teleport Plugin Enabled!");
}
public Player getPlayer(String name) {
for(Player p : Bukkit.getOnlinePlayers()) {
if(p.getName().equalsIgnoreCase(name))
return p;
}
return null;
}
public void onDisable() {
Bukkit.getServer().getLogger().info("Teleport Plugin Disabled!");
}
private void teleportInWord(Player player, int x, int y, int z) {
player.teleport(new Location(player.getWorld(), x, y, z));
}
private void openGUI(Player player) {
Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Warp Selector || By Roofah");
ItemStack Spawn = new ItemStack(Material.DIAMOND_AXE);
ItemMeta SpawnMeta = Spawn.getItemMeta();
ItemStack Build = new ItemStack(Material.DIAMOND_PICKAXE);
ItemMeta BuildMeta = Build.getItemMeta();
SpawnMeta.setDisplayName(ChatColor.DARK_RED + "Spawn");
Spawn.setItemMeta(SpawnMeta);
BuildMeta.setDisplayName(ChatColor.GREEN + "Build");
Build.setItemMeta(BuildMeta);
// 35
inv.setItem(3, Spawn);
inv.setItem(5, Build);
player.openInventory(inv);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Warp Selector")) {
return;
}
Player player = (Player) event.getWhoClicked();
event.setCancelled(true);
if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR
|| !event.getCurrentItem().hasItemMeta()) {
player.closeInventory();
return;
}
switch(event.getCurrentItem().getType()){
case DIAMOND_AXE:
teleportInWord(player, 967, 90, 484);
player.closeInventory();
player.sendMessage(String.format("%sTeleported to %sSpawn%s!", ChatColor.GOLD, ChatColor.DARK_RED, ChatColor.GOLD));
break;
case DIAMOND_PICKAXE:
teleportInWord(player, 906, 96, 428);
player.closeInventory();
player.sendMessage(String.format("%sTeleported to %sBUILD%s!", ChatColor.GOLD, ChatColor.GREEN, ChatColor.GOLD));
break;
default:
player.closeInventory();
break;
}
}
@EventHandler
public void onPlayerKoin(PlayerJoinEvent event) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS));
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Action a = event.getAction();
ItemStack is = event.getItem();
if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR) {
return;
}
if (is.getType() == Material.COMPASS) {
openGUI(event.getPlayer());
}
}
}
還有其他2類,但我仍然可以獲取塊,而不在GUI中添加。
你說它不適用於1.10。它在1.9上運行嗎?是否有另外一個插件可以否認你添加了一個Item到庫存中? – Nightfighter001
'if(ChatColor.stripColor(event.getInventory()。getName())。equalsIgnoreCase(「Warp Selector」)){'似乎與你想要的相反(它只是在屏幕爲_not_時做你的邏輯)扭曲選擇器「)。也許你想'if(!ChatColor.stripColor(event.getInventory()。getName())。equalsIgnoreCase(「Warp Selector」)){'? – Pokechu22