Java Code Examples for org.bukkit.Bukkit.getPlayer()

The following are Jave code examples for showing how to use getPlayer() of the org.bukkit.Bukkit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AsgardAscension   File: TribeManager.java   View Source Code Vote up 6 votes
public static List<String> getTribeListDescription() {
	List<String> desc = new ArrayList<>();
	ChatColor color;
	int online;
	for(Tribe tribe : getTribes()) {
		online = 0;
		if("vanir".equals(tribe.getType()))
			color = ChatColor.RED;
		else color = ChatColor.YELLOW;
		for(String str : tribe.getMembers()) {
			if(Bukkit.getPlayer(str) != null)
				online++;
		}
		desc.add(color + tribe.getName() + ChatColor.GRAY + " " + online + "/" + tribe.getMembers().size() + " online, $" + tribe.getBalance());
	}
	return desc;
}
 
Example 2
Project: OpenUHC   File: BlindnessModule.java   View Source Code Vote up 5 votes
@EventHandler
public void onScatter(GameScatterEvent event) {
  for (UUID uuid : OpenUHC.getCurrentGame().getPlayers()) {
    Player player = Bukkit.getPlayer(uuid);
    if (player != null) {
      for (PotionEffect effect : EFFECTS) {
        player.addPotionEffect(effect);
      }
    }
  }
}
 
Example 3
Project: ZorahPractice   File: TeamMatch.java   View Source Code Vote up 5 votes
private List<Player> getTeam1Players() {
    List<Player> players = new ArrayList<>();

    for (UUID uuid : this.team1.keySet()) {
        Player p = Bukkit.getPlayer(uuid);

        if (p == null || !p.isOnline()) {
            continue;
        }

        players.add(p);
    }

    return players;
}
 
Example 4
Project: Kineticraft   File: CommandCheck.java   View Source Code Vote up 5 votes
@Override
protected void onCommand(CommandSender sender, String[] args) {
    Player p = (Player) sender;
    boolean hasReturn = MetadataManager.hasMetadata(p, "checkGm");

    if (args.length > 0) {
        if (!Utils.isVisible(sender, args[0]))
            return;

        if (!hasReturn) {
            MetadataManager.setMetadata(p, "checkGm", p.getGameMode());
            MetadataManager.setMetadata(p, "checkLocation", p.getLocation());
        }
        Player target = Bukkit.getPlayer(args[0]);
        p.setGameMode(GameMode.SPECTATOR);
        p.teleport(target);
        Bukkit.getScheduler().runTask(Core.getInstance(), () -> p.setSpectatorTarget(target));
        return;
    }

    if (!hasReturn) {
        sender.sendMessage(ChatColor.RED + "No previous state to return to.");
        return;
    }

    p.teleport((Location) MetadataManager.removeMetadata(p, "checkLocation"));
    p.setGameMode(MetadataManager.getEnum(p, "checkGm", GameMode.class));
}
 
Example 5
Project: ZorahPractice   File: FfaMatch.java   View Source Code Vote up 5 votes
@Override
public void sendMessage(String message) {
    for (Player p : getPlayers()) {
        p.sendMessage(message);
    }

    for (UUID uuid : this.spectators) {
        if (Bukkit.getPlayer(uuid) != null) {
            Bukkit.getPlayer(uuid).sendMessage(message);
        }
        else {
            this.spectators.remove(uuid);
        }
    }
}
 
Example 6
Project: FactionsXL   File: UninviteCommand.java   View Source Code Vote up 5 votes
@Override
public void onExecute(String[] args, CommandSender sender) {
    i = 1;
    Faction faction = getSenderFactionOrFromArg(sender, args, 1, true);
    if (faction == null) {
        return;
    }

    if (!(sender instanceof Player) || !faction.isPrivileged((Player) sender)) {
        ParsingUtil.sendMessage(sender, FMessage.ERROR_NO_PERMISSION.getMessage());
        return;
    }

    Player player = Bukkit.getPlayer(args[i]);
    if (!player.isOnline()) {
        ParsingUtil.sendMessage(sender, FMessage.ERROR_PLAYER_NOT_ONLINE.getMessage(), args[i]);
        return;
    }

    if (faction.getMembers().contains(player)) {
        ParsingUtil.sendMessage(sender, FMessage.CMD_INVITE_FAIL.getMessage(), args[i]);
        return;
    }

    faction.getInvitedPlayers().remove(player);
    faction.sendMessage(FMessage.CMD_UNINVITE_SUCCESS.getMessage(), sender, player);
}
 
Example 7
Project: SamaGamesCore   File: ResourcePacksManagerImpl.java   View Source Code Vote up 5 votes
@Override
public void kickAllUndownloaded()
{
    for (UUID id : currentlyDownloading)
    {
        Player player = Bukkit.getPlayer(id);
        if (player != null)
            player.kickPlayer(rejectMessage);
    }

    currentlyDownloading.clear();
}
 
Example 8
Project: HCFCore   File: StuckTimer.java   View Source Code Vote up 5 votes
public void onExpire(UUID userUUID)
{
    Player player = Bukkit.getPlayer(userUUID);
    if (player == null) {
        return;
    }
    Location nearest = LandMap.getNearestSafePosition(player, player.getLocation(), 24);

    if (player.teleport(nearest, PlayerTeleportEvent.TeleportCause.PLUGIN)) {
        player.sendMessage(ChatColor.YELLOW + getDisplayName() + ChatColor.YELLOW + " timer has teleported you to the nearest safe area.");
    }
}
 
Example 9
Project: Kineticraft   File: CommandMessage.java   View Source Code Vote up 5 votes
@Override
protected void onCommand(CommandSender sender, String[] args) {
    String message = ChatColor.DARK_GRAY + ": " + ChatColor.WHITE
            + Chat.applyAllFilters(sender, String.join(" ", skipArgs(args, 1)));
    CommandSender receiver = args[0].equalsIgnoreCase("CONSOLE")
            ? Bukkit.getConsoleSender() : Bukkit.getPlayer(args[0]);

    if (!Utils.isVisible(sender, receiver))
        return;

    if (receiver instanceof Player && AFK.isAFK((Player) receiver))
        sender.sendMessage(ChatColor.GRAY + "This player is AFK, and may not receive your message.");

    // Send display to sender
    String rName = Utils.getSenderName(receiver);
    sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.BOLD + "TO " + rName + message);
    if (sender instanceof Player)
        MetadataManager.setMetadata((Player) sender, "lastWhisper", receiver.getName());

    // Send display to receiver.
    if (receiver instanceof Player) {
        Player p = (Player) receiver;
        if (KCPlayer.getWrapper(p).isIgnoring(sender))
            return;

        p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, .75F);
        MetadataManager.setMetadata(p, "lastWhisper", sender.getName());
    }

    receiver.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.BOLD + "FROM " + Utils.getSenderName(sender) + message);
}
 
Example 10
Project: Kineticraft   File: CommandZen.java   View Source Code Vote up 5 votes
@Override
protected void onCommand(CommandSender sender, String[] args) {
    if (!Utils.isVisible(sender, args[0]))
        return;

    Player p = Bukkit.getPlayer(args[0]);
    KCPlayer.getWrapper(p).setZenMode(new Date().getTime() + TimeUnit.DAYS.toMillis(1));
    p.sendMessage(ChatColor.YELLOW.toString() + ChatColor.BOLD
            + Utils.randElement("Experience Tranquility", "Pass into the Iris") + ".");
}
 
Example 11
Project: HCFCore   File: StuckTimer.java   View Source Code Vote up 5 votes
public void onExpire(UUID userUUID)
{
    Player player = Bukkit.getPlayer(userUUID);
    if (player == null) {
        return;
    }
    Location nearest = LandMap.getNearestSafePosition(player, player.getLocation(), 24);

    if (player.teleport(nearest, PlayerTeleportEvent.TeleportCause.PLUGIN)) {
        player.sendMessage(ChatColor.YELLOW + getDisplayName() + ChatColor.YELLOW + " timer has teleported you to the nearest safe area.");
    }
}
 
Example 12
Project: Slimefun4-Chinese-Version   File: JetBootsTask.java   View Source Code Vote up 5 votes
public void run()
{
    if(Bukkit.getPlayer(uuid) == null)
        Bukkit.getScheduler().cancelTask(id);
    else
    if(Bukkit.getPlayer(uuid).isDead())
        Bukkit.getScheduler().cancelTask(id);
    else
    if(!Bukkit.getPlayer(uuid).isSneaking())
    {
        Bukkit.getScheduler().cancelTask(id);
    } else
    {
        Player p = Bukkit.getPlayer(uuid);
        float cost = 0.075F;
        float charge = ItemEnergy.getStoredEnergy(p.getInventory().getBoots());
        double accuracy = Double.valueOf((new DecimalFormat("##.##")).format(speed - 0.69999999999999996D).replace(",", ".")).doubleValue();
        if(charge >= cost)
        {
            p.getInventory().setBoots(ItemEnergy.chargeItem(p.getInventory().getBoots(), -cost));
            me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerInventory.update(p);
            p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 0.25F, 1.0F);
            p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1);
            p.setFallDistance(0.0F);
            double gravity = 0.040000000000000001D;
            double offset = SlimefunStartup.chance(100, 50) ? accuracy : -accuracy;
            Vector vector = new Vector(p.getEyeLocation().getDirection().getX() * speed + offset, gravity, p.getEyeLocation().getDirection().getZ() * speed - offset);
            p.setVelocity(vector);
        } else
        {
            Bukkit.getScheduler().cancelTask(id);
        }
    }
}
 
Example 13
Project: ZorahPractice   File: TeamMatch.java   View Source Code Vote up 5 votes
public void sendMessage(FancyMessage fancyMessage) {
    for (Player p : getPlayers()) {
        fancyMessage.send(p);
    }

    for (UUID uuid : this.spectators) {
        if (Bukkit.getPlayer(uuid) != null) {
            fancyMessage.send(Bukkit.getPlayer(uuid));
        } else {
            this.spectators.remove(uuid);
        }
    }
}
 
Example 14
Project: UltraCore   File: Tpa.java   View Source Code Vote up 4 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        final Player playerSender = (Player) sender;
        if (args.length == 1) {
            if (label.equals("tpa")) {
                final Player playerRequested = Bukkit.getPlayer(args[0]);
                if (playerRequested != null) {
                    tpaPlayers.put(playerRequested, playerSender);
                    playerSender.sendMessage("Teleport request send to " + playerRequested.getName());
                    playerRequested.sendMessage(ChatColor.GREEN + playerSender.getName() + ChatColor.YELLOW + " has sent you a teleportation request.");
                    
                    TextComponent message1 = new TextComponent(ChatColor.YELLOW + "Click to accept the request -" + ChatColor.GREEN + ChatColor.BOLD + " [ACCEPT]");
                    message1.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpaccept"));
                    message1.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.AQUA + "Click to accept the request").create()));
                    playerRequested.spigot().sendMessage(message1);
                    
                    TextComponent message2 = new TextComponent(ChatColor.YELLOW + "Click to deny the request -" + ChatColor.RED + ChatColor.BOLD + " [DENY]");
                    message2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpdeny"));
                    message2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.AQUA + "Click to deny the request").create()));
                    playerRequested.spigot().sendMessage(message2);
                } else {
                    playerSender.sendMessage(playerRequested.getName() + " is offline");
                }
            }
        } else if (args.length == 0) {
            final Player playerToTeleport = tpaPlayers.get(playerSender);
            if (playerToTeleport != null) {
                if (label.equals("tpaccept")) {
                    playerToTeleport.sendMessage(playerSender.getName() + " has accepted your teleport request");
                    playerSender.sendMessage("Teleporting " + playerToTeleport.getName() + " to you");
                    playerToTeleport.teleport(playerSender);
                } else {
                    playerToTeleport.sendMessage(playerSender + " has denied your teleport request");
                    playerSender.sendMessage(playerToTeleport.getName() + " teleport request denied");
                }
                tpaPlayers.remove(playerSender);
            } else {
                playerSender.sendMessage("You don't have any teleport request");
            }
        }
    }
    return true;
}
 
Example 15
Project: Crescent   File: CommandCrescent.java   View Source Code Vote up 4 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

	if (cmd.getName().equalsIgnoreCase("crescent")) {

		if (!sender.hasPermission("crescent.commands")) {
			sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
			return true;
		}

		if (args.length == 0) {
			String[] message = { ChatColor.BLUE + "Crescent",
					ChatColor.WHITE + "/crescent learn - Enable learning mode.", ChatColor.WHITE
							+ "/crescent doescheat [player] [yes/no/undefined] - Mark a player as a cheater or as a legitimate user so we can use their information to add to the database. If you want to reset it, use the undefined option." };
			sender.sendMessage(message);
			return true;
		}

		final String subCommand = args[0];

		if (subCommand.equalsIgnoreCase("learn")) {

			final boolean current = Crescent.getInstance().getConfig().getBoolean("learnMode");

			Crescent.getInstance().getConfig().set("learnMode", !current);

			final ChatColor colour = current ? ChatColor.RED : ChatColor.GREEN;

			sender.sendMessage(colour + "You have " + ((current) ? "disabled" : "enabled") + " learning mode.");
			return true;
		} else if (subCommand.equalsIgnoreCase("doescheat")) {

			if (args.length < 3) {
				sender.sendMessage(ChatColor.RED + "You must include the player and whether they cheat or not.");
				return true;
			}

			final String player = args[1];

			final Player target = Bukkit.getPlayer(player);

			if (target == null) {
				sender.sendMessage(ChatColor.RED + "That player is not online.");
				return true;
			}

			final String doesCheat = args[2];
			final KnownCheating cheating;

			switch (doesCheat.toLowerCase()) {
			case "yes":
				cheating = KnownCheating.YES;
				break;
			case "no":
				cheating = KnownCheating.NO;
				break;
			case "undefined":
				cheating = KnownCheating.UNDEFINED;
				break;
			default:
				sender.sendMessage(ChatColor.RED + "That is not a valid option.");
				return true;
			}

			Profile.getProfile(target.getUniqueId()).setKnownCheating(cheating);

			sender.sendMessage(ChatColor.GREEN + "You have let the system know that " + target.getName()
					+ "'s cheating status is: " + cheating.toString() + ".");

			return true;
		}

		return true;
	}

	return true;
}
 
Example 16
Project: bskyblock   File: Players.java   View Source Code Vote up 4 votes
public Player getPlayer() {
    return Bukkit.getPlayer(UUID.fromString(uniqueId));
}
 
Example 17
Project: Locked   File: RCommand.java   View Source Code Vote up 4 votes
@Override
public boolean execute(CommandSender sender, String[] args) throws CommandException {
    if (!(sender instanceof Player)) {
        return false;
    }
    Player player = (Player) sender;
    if (!(args.length >= 1)) {
        return false;
    }
    if (!MSGCommand.recentMessages.containsKey(player.getUniqueId())) {
        player.sendMessage(ChatColor.RED + "You have not spoken to anyone recently!");
        return true;
    }
    boolean x = false;
    for (Player p : Bukkit.getOnlinePlayers()) {
        if (p.getName().equals(Bukkit.getPlayer(MSGCommand.recentMessages.get(player.getUniqueId())).getName())) {
            x = true;
            break;
        }
    }
    if (!x) {
        player.sendMessage(ChatColor.RED + Bukkit.getPlayer(MSGCommand.recentMessages.get(player.getUniqueId())).getName() + " is not online!");
        return true;
    }
    Player target = Bukkit.getPlayer(MSGCommand.recentMessages.get(player.getUniqueId()));
    MSGCommand.recentMessages.put(player.getUniqueId(), target.getUniqueId());
    MSGCommand.recentMessages.put(target.getUniqueId(), player.getUniqueId());
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < args.length; i++) {
        sb.append(args[i]);
        sb.append(" ");
    }
    String message = sb.toString();
    try {
        player.sendMessage(ChatColor.translateAlternateColorCodes('&', ChatColor.AQUA + "To " + (!RankManager.getRankPrefix(target).equals(" ") ? RankManager.getRankPrefix(target) : "") + RankManager.getRankNameColor(target) + " " + target.getName() + ChatColor.GRAY + ": " + ChatColor.WHITE + message));
        target.sendMessage(ChatColor.translateAlternateColorCodes('&', ChatColor.AQUA + "From " + (!RankManager.getRankPrefix(player).equals(" ") ? RankManager.getRankPrefix(player) : "") + RankManager.getRankNameColor(player) + " " + player.getName() + ChatColor.GRAY + ": " + ChatColor.WHITE + message));
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return true;
}
 
Example 18
Project: MystiCraft   File: PlayerCaster.java   View Source Code Vote up 4 votes
@Override
public Player getPlayer() {
	return Bukkit.getPlayer(this.uuid);
}
 
Example 19
Project: OnlineChecker-Spigot-SQL-Support   File: SQLManager.java   View Source Code Vote up 4 votes
public void addPreloadPlayer(UUID uuid) {
	Player p = Bukkit.getPlayer(uuid);
	if (p != null && p.isOnline()) {
		loadList.add(uuid.toString());
	}
}
 
Example 20
Project: SamaGamesAPI   File: GamePlayer.java   View Source Code Vote up 2 votes
/**
 * Returns the Bukkit's {@link Player} object representing the underlying player,
 * if he is online; {@code null} else.
 *
 * @return The {@link Player} object.
 */
public Player getPlayerIfOnline()
{
    return Bukkit.getPlayer(this.uuid);
}