嗨,我正在为我和一些朋友制造一个小型的minecraft服务器,我有一段时间没有使用Java了,即时通讯使用spigot 1.14.1 btw。 遗憾的是,即使我运行了第一个命令并知道我的UUID在HashMap中,我的containsKey()也会返回false。 如果有人可以解释的话,那将是很好的,如果可能的话,除了解释之外,还可以修改我的代码版本:) 非常感谢您。
我尝试使自己的包含布尔值无法正常工作
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.melorn.com.pineapplegang.mc.chatutility.Prefix;
import me.melorn.com.pineapplegang.mc.programutility.HashMapUtility;
public class TempYannick implements CommandExecutor{
private static Location joejoespawn;
private HashMap<UUID, Location> OLDLOCATIONS = new HashMap<UUID, Location>();
public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
if(sender instanceof Player) {
Player player = (Player) sender;
if(cmd.getName().equalsIgnoreCase("joejoe")) {
this.OLDLOCATIONS.put(player.getUniqueId(), player.getLocation());
player.sendMessage(Prefix.getPineappleCore() + Prefix.getChatPrefix() + Prefix.getChatColor() + " You have ben teleported to " + Prefix.getPlayerNameColor() + "JoeJoe's" + Prefix.getChatColor() + " Creative Universe");
}else if(cmd.getName().equalsIgnoreCase("joejoeback")) {
if(this.OLDLOCATIONS.containsKey(player.getUniqueId())) {
this.OLDLOCATIONS.remove(player.getUniqueId());
player.sendMessage(Prefix.getPineappleCore() + Prefix.getChatPrefix() + Prefix.getChatColor() + " You teleported back to your old location away from " + Prefix.getPlayerNameColor() + "JoeJoe's " + Prefix.getChatColor() + " Creative Universe");
}else {
player.sendMessage(Prefix.getPineappleCore() + Prefix.getChatPrefix() + Prefix.getChatColor() + " You cant teleport back from " + Prefix.getPlayerNameColor() + "JoeJoe's" + Prefix.getChatColor() + " Creative Universe if you have not ben there!");
}
}
}
return false;
}
}
我希望containsKey()将返回true,以便将“您传送回您的旧位置”消息发送给播放器。