Итак, я пытался закодировать меню puni sh GUI для запретов, отключений звука и т. Д. c. Я попытался включить игрока в событие onClick, чтобы я мог забанить игрока оттуда, поскольку GUI решает, что это судьба. Я перепробовал все, что знаю, и я не понимаю, почему это дает мне ноль. Вот мой код: Commands.class:
package dev.glacial.punish;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import net.minecraft.server.v1_12_R1.CommandExecute;
public class Commands extends CommandExecute implements CommandExecutor,Listener {
public BanList banlist = Bukkit.getBanList(BanList.Type.NAME);
public String cmd1 = "bantest";
public GUIMenu m = new GUIMenu();
public Events e = new Events();
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if(cmd.getName().contains(cmd1)) {
for(Player online : Bukkit.getOnlinePlayers()) {
System.out.println("Searching Online");
if(online.getName().equals(args[0])) {
m.newInventory(player);
m.setArg(args);
e.setPlayer(online);
System.out.println("Found Online");
return true;
}else {
for(OfflinePlayer offp : Bukkit.getOfflinePlayers()) {
System.out.println("Searching Offline");
if(offp.getName().equals(args[0])) {
m.newInventory(player);
m.setArg(args);
e.setOffp(offp);
System.out.println("Found Offline");
return true;
}else {
player.sendMessage(ChatColor.RED + "Error:" + ChatColor.DARK_RED + "The player you tried to find never joined the server!");
System.out.println("Player never joined, Invalid Player.");
return true;
}
}
}
}
}
Events.class:
package dev.glacial.punish;
import java.sql.Date;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class Events implements Listener {
public GUIMenu m = new GUIMenu();
public BanList banlist = Bukkit.getBanList(BanList.Type.NAME);
public Player p;
public OfflinePlayer offp;
public void setPlayer(Player player) {
Player p2 = player;
p = p2;
System.out.println("Set player:" + p2.getName());
System.out.println("Set player:" + p.getName());
}
public Player getPlayer() {
Player p2 = p;
if(p2 == null) {
System.out.println("Player Invalid");
}
return p;
}
public OfflinePlayer getOffp() {
return offp;
}
public void setOffp(OfflinePlayer player) {
offp = player;
}
@EventHandler
public void onLogin(PlayerLoginEvent event) {
if (event.getResult() == Result.KICK_BANNED) {
event.setKickMessage("banned");
System.out.println(" 1");
}
}
@EventHandler
public void onClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ClickType click = event.getClick();
Inventory einv = event.getInventory();
String[] args = m.getArgs();
Player target = p;;
OfflinePlayer oftarget = offp;
ItemStack i = event.getCurrentItem();
ItemMeta imeta = i.getItemMeta();
i.setItemMeta(imeta);
if(i == null || !i.hasItemMeta()) {
System.out.println("Invalid Menu Item");
return;
}
if(einv == null) {
return;
}
if(einv.getName().equals(ChatColor.AQUA + "GlacialMC Punish GUI")) {
System.out.println(imeta.toString());
System.out.println(i.toString());
event.setCancelled(true);
System.out.println(target.getName());
System.out.println(oftarget.getName());
if(i.getItemMeta().getDisplayName().equals(ChatColor.RED + "Ban Hammer")) {
if(!(target == null)) {
Date date = new Date(System.currentTimeMillis() + 60*60*1000);
banlist.addBan(target.getName(), ChatColor.RED + "Ban", date, player.getName());
target.kickPlayer(ChatColor.RED + "Ban");
System.out.println("Banned Online");
}else {
return;
}
if(!(oftarget == null)) {
Date date = new Date(System.currentTimeMillis() + 60*60*1000);
banlist.addBan(oftarget.getName(), ChatColor.RED + "Ban", date, player.getName());
System.out.println("Banned Offline");
}else {
System.out.println("Failed to ban");
return;
}
System.out.println("Clicked Menu Item");
}
System.out.println("Clicked in the Inventory");
}
}
}
GUIMenu.class:
package dev.glacial.punish;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class GUIMenu implements Listener {
public String[] args;
public Player p;
public OfflinePlayer offp;
public void newInventory(Player player) {
Inventory inv = Bukkit.getServer().createInventory(null, 27, ChatColor.AQUA + "GlacialMC Punish GUI");
ItemStack item = new ItemStack(Material.APPLE,1);
ItemMeta imeta = item.getItemMeta();
imeta.setDisplayName(ChatColor.RED + "Ban Hammer");
item.setItemMeta(imeta);
inv.setItem(15,item);
player.openInventory(inv);
System.out.println("Opened Inventory");
}
public ItemStack getItem1() {
ItemStack item = new ItemStack(Material.APPLE,1);
ItemMeta imeta = item.getItemMeta();
imeta.setDisplayName(ChatColor.RED + "Ban Hammer");
item.setItemMeta(imeta);
return item;
}
public void setArg(String[] newargs) {
this.args = newargs;
}
public String[] getArgs() {
return this.args;
}
}
Хотелось бы помочь, спасибо!