When I type `/test` it calls my method to ban a player with testing values, but in console when trying to ban, it says: Code (Text): [10:45:50 INFO]: Could not ban player c4ef7b5f-1502-44c5-bb51-39542176d1f5 ºcºlReason: Code (Java): package com.xenderaura.moderation; //import java.util.UUID; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.xenderaura.moderation.cmnds.Mod; public class Moderation extends JavaPlugin implements Listener{ public void onEnable(){ PluginDescriptionFile pdfFile = getDescription(); Logger logger = Logger.getLogger("Minecraft"); getCommand("mod").setExecutor(new Mod()); PluginManager pm = getServer().getPluginManager(); pm.registerEvents(this, this); logger.info(pdfFile.getName() + " has been enabled!"); } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(label.equalsIgnoreCase("test")){ System.out.println("test 4"); Player p = (Player) sender; this.createPunishment(p, p, Type.BAN, "Test Ban"); } return false; } public void onDisable(){ PluginDescriptionFile pdfFile = getDescription(); Logger logger = Logger.getLogger("Minecraft"); logger.info(pdfFile.getName() + " has been disabled!"); } public void createPunishment(Player staff, Player target, Type t, String reason){ //UUID u = target.getUniqueId(); if(t==Type.BAN){ System.out.println("test 1"); this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "ban " + target.getName() + "\n§cReason: §f" + reason + "\n§cStaff: §f" + staff.getName() + "\n§cExpires: §fNEVER\n§cAppeal: §fForums"); }else{ System.out.println("test 2"); } } public void createPunishment(Player staff, Player target, Type t, String reason, int time){ } }
Yeah, use the API. Otherwise you're relying on what implements /ban and how its handled. In this case however you error is you have no space between .getName() and the "\n<message>", so its trying to do: /ban player\ninsertbanmessagehere
Yeah don't use that method (I think it's deprecated). Use BanList: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/BanList.html https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Server.html#getBanList(org.bukkit.BanList.Type)
So, Code (Java): public void createPunishment(Player staff, Player target, Type t, String reason){ //UUID u = target.getUniqueId(); String a = target.getName(); String b = "\n§cReason: §f" + reason + "\n§cStaff: §f" + staff.getName() + "\n§cExpires: §fNEVER\n§cAppeal: §fForums"; String c = staff.getName(); if(t==Type.BAN){ System.out.println("test 1"); BanList.addBan(a, b, null, c) } ?
you'd have to call Server::getBanList(BanList.Type) first (with the right BanList.Type), to get the right BanList. Moreover: Don't use the Minecraft Logger, use your plugin's Logger (JavaPlugin:: getLogger()) Don't compare command labels, but compare command names (Command::getName(), which automatically supports aliases) Don't blindly cast to Player, CommandSender can be f.e. ConsoleCommandSender (which will result in a ClassCastException) It's advised to annotate overridden method with @Override, so the compiler warns you for user errors (like typos in method names)
Code (Java): BanList banList = BanList.getBanList(BanList.BAN); String a = target. String b = "\n§cReason: §f" + reason + "\n§cStaff: §f" + staff.getName() + "\n§cExpires: §fNEVER\n§cAppeal: §fForums"; String c = staff.getName(); if(t==Type.BAN){ System.out.println("test 1"); banList.addBan(a, b, null, c); } ? I don't know what valid types there are for the BanList type.