Java Code Examples for org.bukkit.Bukkit#getPlayerExact()

The following examples show how to use org.bukkit.Bukkit#getPlayerExact() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NametagHandler.java    From NametagEdit with GNU General Public License v3.0 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example 2
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: UUIDMigration.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: ServerTutorial.java    From ServerTutorial with MIT License 5 votes vote down vote up
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);
}
 
Example 5
Source File: NametagHandler.java    From NametagEdit with GNU General Public License v3.0 5 votes vote down vote up
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);
            }
        }
    });
}
 
Example 6
Source File: BukkitServerBridge.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 7
Source File: ChannelPlayerUUID.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * プレイヤー名から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;
}
 
Example 8
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 9
Source File: TabListImpl.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 10
Source File: CommandOpenMenu.java    From TrMenu with MIT License 5 votes vote down vote up
@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");
            }
        }
    }
}
 
Example 11
Source File: ChannelMemberPlayer.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * プレイヤー名から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;
}
 
Example 12
Source File: ScoreComponent.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 : "";
}
 
Example 13
Source File: ItemMenu.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public void run()
{
	Player p = Bukkit
			.getPlayerExact(playerName);
	if (p != null)
	{
		parent.open(p);
	}
}
 
Example 14
Source File: Commands.java    From PlayerSQL with GNU General Public License v2.0 4 votes vote down vote up
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());
     });
 }
 
Example 15
Source File: EntityPet.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
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));
    }
}
 
Example 16
Source File: ItemMenu.java    From AmpMenus with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void run() {
    Player p = Bukkit.getPlayerExact(playerName);
    if (p != null) {
        parent.open(p);
    }
}
 
Example 17
Source File: EntityPet.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
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));
    }
}
 
Example 18
Source File: Users.java    From ProjectAres with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 19
Source File: ChannelPlayerName.java    From LunaChat with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * BukkitのPlayerを取得する
 * @return Player
 * @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPlayer()
 */
@Override
public Player getPlayer() {
    return Bukkit.getPlayerExact(name);
}
 
Example 20
Source File: TrUtils.java    From TrMenu with MIT License 2 votes vote down vote up
/**
 * 判断一个玩家是否在线
 *
 * @param player 玩家名称
 * @return 是否在线
 */
public boolean isPlayerOnline(String player) {
    return Bukkit.getPlayerExact(player) != null && Bukkit.getPlayerExact(player).isOnline();
}