Getting an offline user


#1

So I am trying to make a ban panel where you will be able to ban anyone offline/online Players but I don’t know how to do it anyone has some examples?

This is what I have right now

package org.devoflua.hello.commands;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.devoflua.hello.Main;
import org.devoflua.hello.utils.IconMenu;
import org.bukkit.ChatColor;
import org.bukkit.Material;

public class tempban implements CommandExecutor {

	private Main plugin;
	
	public tempban(Main plugin) {
		this.plugin = plugin;
		plugin.getCommand("tempban").setExecutor(this);
	}

	@SuppressWarnings("deprecation")
	@Override
    public boolean onCommand(CommandSender Sender, Command cmd, String commandLabel, String[] arg) {

		if (!(Sender instanceof Player)) {
			Sender.sendMessage("Only senders can use this command");
			return true;
		}
		
		Player p = (Player) Sender;
		
		if (p.hasPermission("tempban.use")) {
			
			if (arg.length == 0) {
				p.sendMessage(ChatColor.DARK_RED + "You cannot ban yourself");
				return true;
			}
			
			System.out.print("1");
			
			Player target = Bukkit.getPlayerExact(arg[0]);
			
			if (target == null) {
				System.out.print("2");
				target = (Player) Bukkit.getOfflinePlayer(arg[0]);
			}
			
			if (target == null) {
				p.sendMessage("Your target " + arg[0] + " does not exists");
			} else {
				System.out.print("3");
				if (p.getUniqueId() != target.getUniqueId()) {
		            IconMenu menu = new IconMenu("Menu", 27, new IconMenu.OptionClickEventHandler() {
		                @Override
		                public void onOptionClick(IconMenu.OptionClickEvent event) {
		                    event.getPlayer().sendMessage("You have chosen " + event.getName());
		                    event.setWillClose(true);
		                }
		            }, plugin);
		            menu.setOption(3, new ItemStack(Material.APPLE, 1), "Food", "The food is delicious");
		            menu.setOption(4, new ItemStack(Material.IRON_SWORD, 1), "Weapon", "Weapons are for awesome people");
		            menu.setOption(5, new ItemStack(Material.EMERALD, 1), "Money", "Money brings happiness");
		            menu.open(p);
		            return true;
				} else {
					p.sendMessage(ChatColor.DARK_RED + "You cannot ban yourself");
				}
			}
			
		} else {
			p.sendMessage("You do not have permission to send this message");
		}


        return false;
    }
}

#2

Errrr. Just so you know that is Bukkit code. This is Sponge, a completely different api.

You will probably find better help at https://bukkit.org/forums/

If you are wanting to develop for sponge and just didnt know that it didnt use the Bukkit API then great, here is a good starting point. https://docs.spongepowered.org/stable/en/plugin/index.html


#3

I cannot post bukkit stuff?


#4

Please note how it states it’s for sponge plugin development.


#5

Its like posting how to fix a macbook on the windows forums. The help you will get isn’t going to be as great as if you just posted on the apple forums.