下面列出了org.bukkit.Bukkit#getPlayerExact ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void clear(final CommandSender sender, final String player) {
Player target = Bukkit.getPlayerExact(player);
if (target != null) {
handleClear(target.getUniqueId(), player);
return;
}
UUIDFetcher.lookupUUID(player, plugin, new UUIDFetcher.UUIDLookup() {
@Override
public void response(UUID uuid) {
if (uuid == null) {
NametagMessages.UUID_LOOKUP_FAILED.send(sender);
} else {
handleClear(uuid, player);
}
}
});
}
public void run()
{
Player p = Bukkit
.getPlayerExact(playerName);
if (p != null)
{
parent.open(p);
}
}
@Override
public String getValue(String locale) {
String value = forcedvalue;
if (value == null) {
Player player = Bukkit.getPlayerExact(playername);
if (player != null) {
Scoreboard board = player.getScoreboard();
Objective objective = board.getObjective(objectivename);
if (objective != null) {
value = String.valueOf(objective.getScore(playername).getScore());
}
}
}
return value != null ? value : "";
}
/**
* プレイヤー名からUUIDを取得してChannelMemberPlayerを作成して返す
* @param name プレイヤー名
* @return ChannelMemberPlayer
*/
public static ChannelMemberPlayer getChannelMemberPlayerFromName(String name) {
Player player = Bukkit.getPlayerExact(name);
if ( player != null ) {
return new ChannelMemberPlayer(player.getUniqueId());
}
@SuppressWarnings("deprecation")
OfflinePlayer offline = Bukkit.getOfflinePlayer(name);
if ( offline != null && offline.getUniqueId() != null ) {
return new ChannelMemberPlayer(offline.getUniqueId());
}
return null;
}
@Override
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 1) {
TLocale.sendTo(sender, "COMMANDS.HELP-PAGE", TrMenu.getPlugin().getDescription().getVersion(), label.toUpperCase().charAt(0) + label.substring(1));
return;
}
Menu menu = TrMenuAPI.getMenu(args[0]);
if (menu == null) {
TLocale.sendTo(sender, "MENU.NOT-EXIST");
return;
}
if (args.length == 1) {
if (sender instanceof Player) {
menu.open((Player) sender, true);
} else {
TLocale.sendTo(sender, "COMMANDS.NOT-PLAYER");
}
}
if (args.length >= 2) {
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null || !player.isOnline()) {
TLocale.sendTo(sender, "COMMANDS.NO-PLAYER");
} else {
menu.open(player, true);
if (!(args.length >= 3 && "silent".equalsIgnoreCase(args[2]))) {
TLocale.sendTo(sender, "COMMANDS.OPENED-FOR");
}
}
}
}
public TabListImpl(NovaPlayer nPlayer) {
super(nPlayer);
try {
//Texture
Object targetProfile;
if(Bukkit.getOnlineMode()) {
Collection<String> headSkinStringCollection = new ArrayList<>();
if(Config.TABLIST_TEXTURE.isList()) {
headSkinStringCollection.addAll(Config.TABLIST_TEXTURE.getStringList());
}
else {
headSkinStringCollection.add(Config.TABLIST_TEXTURE.getString());
}
for(String headSkinString : headSkinStringCollection) {
Player online = Bukkit.getPlayerExact(headSkinString);
if(online != null) {
targetProfile = entityPlayerGetProfileMethod.invoke(Reflections.getHandle(online));
}
else {
targetProfile = craftOfflinePlayerGetProfileMethod.invoke(Bukkit.getOfflinePlayer(headSkinString));
}
if(Iterables.getFirst(propertyMapGetMethod.invoke(gameProfileGetPropertiesMethod.invoke(targetProfile), "textures"), null) == null) {
Object server = minecraftServerGetMinecraftServerMethod.invoke(null);
Object service = minecraftServerMinecraftSessionServiceField.get(server);
targetProfile = minecraftSessionServiceFillProfilePropertiesMethod.invoke(service, targetProfile, true);
skinProfiles.add(targetProfile);
}
}
}
}
catch(IllegalAccessException | InvocationTargetException e) {
LoggerUtils.exception(e);
}
}
public static String getDisplayName(@Nullable PlayerId target, CommandSender viewer) {
if(target == null) {
return CONSOLE_DISPLAY_NAME;
} else {
Player targetPlayer = Bukkit.getPlayerExact(target.username(), viewer);
if(targetPlayer == null) {
return ChatColor.DARK_AQUA + target.username();
} else {
return targetPlayer.getDisplayName(viewer);
}
}
}
public static String getDisplayName(@Nullable String username, CommandSender viewer) {
if(username == null || username.trim().length() == 0 || username.trim().equalsIgnoreCase("CONSOLE")) {
return CONSOLE_DISPLAY_NAME;
} else {
Player targetPlayer = Bukkit.getPlayerExact(username, viewer);
if(targetPlayer == null) {
return ChatColor.DARK_AQUA + username;
} else {
return targetPlayer.getDisplayName(viewer);
}
}
}
/**
* プレイヤー名からUUIDを取得してChannelPlayerUUIDを作成して返す
* @param name プレイヤー名
* @return ChannelPlayerUUID
*/
public static ChannelPlayerUUID getChannelPlayerUUIDFromName(String name) {
Player player = Bukkit.getPlayerExact(name);
if ( player != null ) {
return new ChannelPlayerUUID(player.getUniqueId());
}
OfflinePlayer offline = Bukkit.getOfflinePlayer(name);
if ( offline != null && offline.getUniqueId() != null ) {
return new ChannelPlayerUUID(offline.getUniqueId());
}
return null;
}
/**
* Gets the player with the given name.
*
* @param playerName Player name
* @return returns a an instance of IPlayer if found, otherwise null
*/
@Override
public IPlayer getPlayer(String playerName) {
Player player = Bukkit.getPlayerExact(playerName);
if (player == null) {
return null;
} else {
return PlotMe_CorePlugin.getInstance().wrapPlayer(player);
}
}
void save(final CommandSender sender, String targetName, NametagEvent.ChangeType changeType, String value) {
Player player = Bukkit.getPlayerExact(targetName);
PlayerData data = getPlayerData(player);
if (data == null) {
data = new PlayerData(targetName, null, "", "", -1);
if (player != null) {
storePlayerData(player.getUniqueId(), data);
}
}
if (changeType == NametagEvent.ChangeType.PREFIX) {
data.setPrefix(value);
} else {
data.setSuffix(value);
}
if (player != null) {
applyTagToPlayer(player, false);
data.setUuid(player.getUniqueId());
abstractConfig.save(data);
return;
}
final PlayerData finalData = data;
UUIDFetcher.lookupUUID(targetName, plugin, new UUIDFetcher.UUIDLookup() {
@Override
public void response(UUID uuid) {
if (uuid == null) {
NametagMessages.UUID_LOOKUP_FAILED.send(sender);
} else {
storePlayerData(uuid, finalData);
finalData.setUuid(uuid);
abstractConfig.save(finalData);
}
}
});
}
public void incrementCurrentView(String name) {
TutorialView fromTutorialView = TutorialManager.getManager().getTutorialView(name);
Caching.getCaching().currentTutorialView().put(name, TutorialManager.getManager().getCurrentView(name) + 1);
TutorialView toTutorialView = TutorialManager.getManager().getTutorialView(name);
ViewSwitchEvent event = new ViewSwitchEvent(Bukkit.getPlayerExact(name), fromTutorialView, toTutorialView,
TutorialManager.getManager().getCurrentTutorial(name));
Bukkit.getServer().getPluginManager().callEvent(event);
}
/**
* Returns the player represented by the given identification (retrieved by using this class)
* <p/>
* This method makes use of both player names and UUIDs to find the required online player
*
* @param identification identification to search with
* @return player represented by the given identification, or null if the player is not online
*/
public static Player getPlayerOf(Object identification) {
if (supportsUuid()) {
if (identification instanceof UUID) {
return Bukkit.getPlayer((UUID) identification);
} else if (identification instanceof String) {
return Bukkit.getPlayer(convertUUID((String) identification));
}
} else if (identification instanceof String) {
return Bukkit.getPlayerExact((String) identification);
}
return null;
}
private void openInventory(CommandSender sender, Iterator<String> iterator) {
Player player = (Player) sender;
String name = iterator.next();
Player found = Bukkit.getPlayerExact(name);
if (found != null) {
player.openInventory(found.getInventory());
return;
}
CompletableFuture.runAsync(() -> {
List<PlayerData> list = UserManager.INSTANCE.fetchName(name);
if (list.isEmpty()) {
player.sendMessage("player not found");
return;
}
PlayerData data;
if (list.size() == 1) {
data = list.get(0);
} else if (iterator.hasNext()) {
int index = Integer.parseInt(iterator.next());
data = list.get(index);
} else {
player.sendMessage("You should special player data id");
for (int i = 0; i < list.size(); i++) {
player.sendMessage(String.format("id=%s, guid=%s", i, list.get(i).getUuid()));
}
return;
}
if (data.isLocked()) {
player.sendMessage("player current online");
return;
}
ItemStack[] stacks = UserManager.INSTANCE.toStack(data.getInventory());
CustomInventory inventory = CustomInventory.onCreate(res -> {
Inventory inv = Bukkit.createInventory(res, InventoryType.PLAYER);
inv.setContents(stacks);
return inv;
}).onClose(res -> {
data.setInventory(UserManager.INSTANCE.toString(res.getContents()));
CompletableFuture.runAsync(() -> UserManager.INSTANCE.saveUser(data, data.isLocked()));
});
CompletableFuture.runAsync(() -> player.openInventory(inventory.getInventory()), PluginMain.getPlugin());
});
}
public void onLive() {
if (this.pet == null) {
this.remove(false);
return;
}
if (this.getPlayerOwner() == null || !this.getPlayerOwner().isOnline() || Bukkit.getPlayerExact(this.getPlayerOwner().getName()) == null) {
EchoPet.getManager().removePet(this.getPet(), true);
return;
}
if (pet.isOwnerRiding() && this.passenger == null && !pet.isOwnerInMountingProcess()) {
pet.ownerRidePet(false);
}
if (((CraftPlayer) this.getPlayerOwner()).getHandle().isInvisible() != this.isInvisible() && !this.shouldVanish) {
this.setInvisible(!this.isInvisible());
}
if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSneaking() != this.isSneaking()) {
this.setSneaking(!this.isSneaking());
}
if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSprinting() != this.isSprinting()) {
this.setSprinting(!this.isSprinting());
}
if (this.getPet().isHat()) {
this.lastYaw = this.yaw = (this.getPet().getPetType() == PetType.ENDERDRAGON ? this.getPlayerOwner().getLocation().getYaw() - 180 : this.getPlayerOwner().getLocation().getYaw());
}
if (this.getPlayerOwner().isFlying() && EchoPet.getOptions().canFly(this.getPet().getPetType())) {
Location petLoc = this.getLocation();
Location ownerLoc = this.getPlayerOwner().getLocation();
Vector v = ownerLoc.toVector().subtract(petLoc.toVector());
double x = v.getX();
double y = v.getY();
double z = v.getZ();
Vector vo = this.getPlayerOwner().getLocation().getDirection();
if (vo.getX() > 0) {
x -= 1.5;
} else if (vo.getX() < 0) {
x += 1.5;
}
if (vo.getZ() > 0) {
z -= 1.5;
} else if (vo.getZ() < 0) {
z += 1.5;
}
this.setVelocity(new Vector(x, y, z).normalize().multiply(0.3F));
}
}
public void run() {
Player p = Bukkit.getPlayerExact(playerName);
if (p != null) {
parent.open(p);
}
}
public void onLive() {
if (this.pet == null) {
this.remove(false);
return;
}
if (this.getPlayerOwner() == null || !this.getPlayerOwner().isOnline() || Bukkit.getPlayerExact(this.getPlayerOwner().getName()) == null) {
EchoPet.getManager().removePet(this.getPet(), true);
return;
}
if (pet.isOwnerRiding() && this.passenger == null && !pet.isOwnerInMountingProcess()) {
pet.ownerRidePet(false);
}
if (((CraftPlayer) this.getPlayerOwner()).getHandle().isInvisible() != this.isInvisible() && !this.shouldVanish) {
this.setInvisible(!this.isInvisible());
}
if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSneaking() != this.isSneaking()) {
this.setSneaking(!this.isSneaking());
}
if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSprinting() != this.isSprinting()) {
this.setSprinting(!this.isSprinting());
}
if (this.getPet().isHat()) {
this.lastYaw = this.yaw = (this.getPet().getPetType() == PetType.ENDERDRAGON ? this.getPlayerOwner().getLocation().getYaw() - 180 : this.getPlayerOwner().getLocation().getYaw());
}
if (this.getPlayerOwner().isFlying() && EchoPet.getOptions().canFly(this.getPet().getPetType())) {
Location petLoc = this.getLocation();
Location ownerLoc = this.getPlayerOwner().getLocation();
Vector v = ownerLoc.toVector().subtract(petLoc.toVector());
double x = v.getX();
double y = v.getY();
double z = v.getZ();
Vector vo = this.getPlayerOwner().getLocation().getDirection();
if (vo.getX() > 0) {
x -= 1.5;
} else if (vo.getX() < 0) {
x += 1.5;
}
if (vo.getZ() > 0) {
z -= 1.5;
} else if (vo.getZ() < 0) {
z += 1.5;
}
this.setVelocity(new Vector(x, y, z).normalize().multiply(0.3F));
}
}
/**
* 判断一个玩家是否在线
*
* @param player 玩家名称
* @return 是否在线
*/
public boolean isPlayerOnline(String player) {
return Bukkit.getPlayerExact(player) != null && Bukkit.getPlayerExact(player).isOnline();
}
/**
* This method is for legacy support ONLY.
*
* Use {@link OnlinePlayers#find(UserId)} instead.
*/
@Deprecated
public static @Nullable Player player(PlayerId playerId) {
return Bukkit.getPlayerExact(playerId.username());
}
/**
* BukkitのPlayerを取得する
* @return Player
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPlayer()
*/
@Override
public Player getPlayer() {
return Bukkit.getPlayerExact(name);
}