Java Code Examples for org.bukkit.command.CommandSender#getName()

The following examples show how to use org.bukkit.command.CommandSender#getName() . 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: ExcPlayer.java    From FunnyGuilds with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
    MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
    PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
    
    if (args.length == 0 && !(sender instanceof Player)) {
        sender.sendMessage(messages.playerOnly);
        return;
    }
    
    String name = args.length == 0 ? sender.getName() : args[0];

    User user = UserUtils.get(name, config.playerLookupIgnorecase);

    if (user == null) {
        sender.sendMessage(messages.generalNotPlayedBefore);
        return;
    }

    sendInfoMessage(messages.playerInfoList, user, sender);
}
 
Example 2
Source File: LastLoginCommand.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    // Get the player
    String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);

    PlayerAuth auth = dataSource.getAuth(playerName);
    if (auth == null) {
        commonService.send(sender, MessageKey.UNKNOWN_USER);
        return;
    }

    // Get the last login date
    final Long lastLogin = auth.getLastLogin();
    final String lastLoginDate = lastLogin == null ? "never" : new Date(lastLogin).toString();

    // Show the player status
    sender.sendMessage("[AuthMe] " + playerName + " last login: " + lastLoginDate);
    if (lastLogin != null) {
        sender.sendMessage("[AuthMe] The player " + playerName + " last logged in "
            + createLastLoginIntervalMessage(lastLogin) + " ago");
    }
    sender.sendMessage("[AuthMe] Last player's IP: " + auth.getLastIp());
}
 
Example 3
Source File: MarriageManager.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
public void priestFinishDivorce(@NotNull Marriage marriage, @NotNull CommandSender divorceBy)
{
	DivorceEvent divorceEvent = new DivorceEvent(marriage, divorceBy);
	Bukkit.getPluginManager().callEvent(divorceEvent);
	if(!divorceEvent.isCancelled())
	{
		marriage.divorce();
		MarriagePlayer player1 = marriage.getPartner1(), player2 = marriage.getPartner2();
		String priestName, priestDPName, player1DisplayName = player1.getDisplayName(), player2DisplayName = player2.getDisplayName();
		if(divorceBy instanceof Player)
		{
			priestName = divorceBy.getName();
			priestDPName = ((Player) divorceBy).getDisplayName();
		}
		else
		{
			priestName = CONSOLE_NAME;
			priestDPName = CONSOLE_DISPLAY_NAME;
		}
		if(announceMarriage)
		{
			messageBroadcastDivorce.broadcast(priestName, priestDPName, player1.getName(), player1DisplayName, player2.getName(), player2DisplayName);
		}
		messageDivorced.send(divorceBy, player1.getName(), player1DisplayName, player2.getName(), player2DisplayName);
		if(player1.isOnline()) player1.send(messageDivorcedPlayer, priestName, priestDPName, player2.getName(), player2DisplayName);
		if(player2.isOnline()) player2.send(messageDivorcedPlayer, priestName, priestDPName, player1.getName(), player1DisplayName);
		plugin.getServer().getPluginManager().callEvent(new DivorcedEvent(marriage.getPartner1(), marriage.getPartner2(), divorceBy));
	}
}
 
Example 4
Source File: ChannelMemberPlayer.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * CommandSenderから、ChannelPlayerを作成して返す
 * @param sender
 * @return ChannelPlayer
 */
public static ChannelMemberPlayer getChannelPlayer(CommandSender sender) {
    if ( sender instanceof Player ) {
        return new ChannelMemberPlayer(((Player)sender).getUniqueId());
    }
    return new ChannelMemberPlayer(sender.getName());
}
 
Example 5
Source File: ChannelPlayerUUID.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * CommandSenderから、ChannelPlayerを作成して返す
 * @param sender
 * @return ChannelPlayer
 */
public static ChannelPlayer getChannelPlayer(CommandSender sender) {
    if ( sender instanceof Player ) {
        return new ChannelPlayerUUID(((Player)sender).getUniqueId());
    }
    return new ChannelPlayerName(sender.getName());
}
 
Example 6
Source File: ForceLoginCommand.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    // Get the player query
    String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);

    Player player = bukkitService.getPlayerExact(playerName);
    if (player == null || !player.isOnline()) {
        sender.sendMessage("Player needs to be online!");
    } else if (!permissionsManager.hasPermission(player, CAN_LOGIN_BE_FORCED)) {
        sender.sendMessage("You cannot force login the player " + playerName + "!");
    } else {
        management.forceLogin(player);
        sender.sendMessage("Force login for " + playerName + " performed!");
    }
}
 
Example 7
Source File: GetEmailCommand.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);

    DataSourceValue<String> email = dataSource.getEmail(playerName);
    if (email.rowExists()) {
        sender.sendMessage("[AuthMe] " + playerName + "'s email: " + email.getValue());
    } else {
        commonService.send(sender, MessageKey.UNKNOWN_USER);
    }
}
 
Example 8
Source File: PermissionGroups.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandSender sender, List<String> arguments) {
    sender.sendMessage(ChatColor.BLUE + "AuthMe permission groups");
    String name = arguments.isEmpty() ? sender.getName() : arguments.get(0);
    Player player = Bukkit.getPlayer(name);
    if (player == null) {
        sender.sendMessage("Player " + name + " could not be found");
    } else {
        sender.sendMessage("Player " + name + " has permission groups: "
            + String.join(", ", permissionsManager.getGroups(player)));
        sender.sendMessage("Primary group is: " + permissionsManager.getGroups(player));
    }
}
 
Example 9
Source File: Messages.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieve the message from the text file.
 *
 * @param key The message key to retrieve
 * @param sender The entity to send the message to
 * @return The message from the file
 */
private String retrieveMessage(MessageKey key, CommandSender sender) {
    String message = messagesFileHandler.getMessage(key.getKey());
    String displayName = sender.getName();
    if (sender instanceof Player) {
        displayName = ((Player) sender).getDisplayName();
    }
    
    return ChatColor.translateAlternateColorCodes('&', message)
            .replace(NEWLINE_TAG, "\n")
            .replace(USERNAME_TAG, sender.getName())
            .replace(DISPLAYNAME_TAG, displayName);
}
 
Example 10
Source File: MarriageManager.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
public void marryPriestFinish(MarriagePlayer player1, MarriagePlayer player2, CommandSender priest, String surname)
{
	surname = cleanupSurname(surname);
	MarryEvent event = new MarryEvent(player1, player2, priest, surname);
	plugin.getServer().getPluginManager().callEvent(event);
	if(!event.isCancelled())
	{
		String priestName, priestDPName;
		MarriageData marriage;
		if(priest instanceof Player)
		{
			priestName = priest.getName();
			priestDPName = ((Player) priest).getDisplayName();
			marriage = new MarriageData(player1, player2, plugin.getPlayerData((Player) priest), new Date(), surname);
			if(confirm && autoDialog)
			{
				((Player) priest).chat(dialogMarried);
			}
		}
		else
		{
			priestName = CONSOLE_NAME;
			priestDPName = CONSOLE_DISPLAY_NAME;
			marriage = new MarriageData(player1, player2, null, surname);
		}

		plugin.getDatabase().cachedMarry(marriage);
		messageMarried.send(priest, player1.getName(), player1.getDisplayName(), player2.getName(), player2.getDisplayName());
		player1.sendMessage(messageHasMarried, priestName, priestDPName, player2.getName(), player2.getDisplayName());
		player2.sendMessage(messageHasMarried, priestName, priestDPName, player1.getName(), player1.getDisplayName());
		if(announceMarriage)
		{
			messageBroadcastMarriage.broadcast(priestName, priestDPName, player1.getName(), player1.getDisplayName(), player2.getName(), player2.getDisplayName());
		}
		plugin.getServer().getPluginManager().callEvent(new MarriedEvent(marriage));
	}
}
 
Example 11
Source File: RegCommand.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label,
		String[] args) {
	
	String playerName;
	String code;
	if (sender instanceof Player) {
		if (args.length != 1) {
			sender.sendMessage(ChatColor.RED+"Enter a valid registration code.");
			return false;
		}
		playerName = sender.getName();
		code = args[0];
	} else {
		if (args.length != 2) {
			sender.sendMessage(ChatColor.RED+"Enter a valid player name and registration code.");
			return false;
		}
		playerName = args[0];
		code = args[1];
	}
	
	try {
		if (SQL.sendVerification(code, playerName)) {
			sender.sendMessage(ChatColor.GREEN+"Verification success. You can now earn platinum and use perks.");
			return true;
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} 
	
	sender.sendMessage(ChatColor.RED+"Verification Failure. Please try again.");
	return false;
}
 
Example 12
Source File: BukkitSenderFactory.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
protected String getName(CommandSender sender) {
    if (sender instanceof Player) {
        return sender.getName();
    }
    return Sender.CONSOLE_NAME;
}
 
Example 13
Source File: StaffChatCmd.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String alias, String[] args)
{
	if(!permission.has(sender, options.permissionStaffChat))
	{
		message.send(sender, messages.noPermission, messages.prefixStaffChat);
		return true;
	}
	
	if(args.length > 0)
	{
		String name = sender instanceof Player ? sender.getName() : "Console";
		
		chatHandler.sendStaffChatMessage(name, JavaUtils.compileWords(args, 0));
	}else if(sender instanceof Player)
	{
		User user = userManager.get(((Player) sender).getUniqueId());
		
		if(user.isChatting())
		{
			message.send(sender, messages.staffChatStatus.replace("%status%", "disabled"), messages.prefixStaffChat);
			user.setChatting(false);
		}else
		{
			message.send(sender, messages.staffChatStatus.replace("%status%", "enabled"), messages.prefixStaffChat);
			user.setChatting(true);
		}
	}else message.send(sender, messages.onlyPlayers, messages.prefixStaffChat);
	
	return true;
}
 
Example 14
Source File: ChatCmd.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
private void handleChatArgument(CommandSender sender, String argument, String option, boolean shouldCheckPermission)
{
	String name = sender instanceof Player ? sender.getName() : "Console";
	
	switch(argument.toLowerCase())
	{
		case "clear":
			if(permission.has(sender, options.permissionChatClear) || !shouldCheckPermission)
			{
				chatHandler.clearChat(name);
			}else message.send(sender, messages.noPermission, messages.prefixGeneral);
			break;
		case "toggle":
			if(permission.has(sender, options.permissionChatToggle) || !shouldCheckPermission)
			{
				chatHandler.setChatEnabled(name, option.isEmpty() ? !chatHandler.isChatEnabled() : Boolean.valueOf(option));
			}else message.send(sender, messages.noPermission, messages.prefixGeneral);
			break;
		case "slow":
			if(permission.has(sender, options.permissionChatSlow) || !shouldCheckPermission)
			{
				if(JavaUtils.isInteger(option))
				{
					chatHandler.setChatSlow(name, Integer.parseInt(option));
				}else message.send(sender, messages.invalidArguments.replace("%usage%", getName() + " &7" + getUsage()), messages.prefixGeneral);
			}else message.send(sender, messages.noPermission, messages.prefixGeneral);
			break;
		default:
			message.send(sender, messages.invalidArguments.replace("%usage%", getName() + " &7" + getUsage()), messages.prefixGeneral);
			break;
	}
}
 
Example 15
Source File: CommandStats.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Command(name = "stats", usage = "/spleef stats [player|top [page]]",
		descref = Messages.Help.Description.STATS)
public void onStatsCommand(CommandContext context, HeavySpleef heavySpleef) throws CommandException {
	CommandSender sender = context.getSender();
	if (sender instanceof Player) {
		sender = heavySpleef.getSpleefPlayer(sender);
	}
	
	AsyncReadWriteHandler databaseHandler = heavySpleef.getDatabaseHandler();
	
	Statistic.StatisticPrinter printer;
	
	if (context.argsLength() > 0) {
		String arg = context.getString(0);
		
		if (arg.equalsIgnoreCase("top")) {
			CommandValidate.isTrue(sender.hasPermission(Permissions.PERMISSION_STATS_TOP), i18n.getString(Messages.Command.NO_PERMISSION));
			int page = 1;
			
			if (context.argsLength() > 1) {
				//Try to parse a page number
				try {
					page = Integer.parseInt(context.getString(1));
				} catch (NumberFormatException nfe) {
					//Just use the default value
				}	
			}
			
			printer = new Statistic.TopStatisticPrinter(sender, page, databaseHandler, heavySpleef.getLogger());
		} else {
			CommandValidate.isTrue(sender.hasPermission(Permissions.PERMISSION_STATS_OTHER), i18n.getString(Messages.Command.NO_PERMISSION));
			printer = new Statistic.FullStatisticPrinter(databaseHandler, sender, arg, heavySpleef.getLogger());
		}
	} else {
		if (!(sender instanceof SpleefPlayer)) {
			sender.sendMessage(i18n.getString(Messages.Command.PLAYER_ONLY));
			return;
		}
		
		CommandValidate.isTrue(sender.hasPermission(Permissions.PERMISSION_STATS), i18n.getString(Messages.Command.NO_PERMISSION));
		printer = new Statistic.FullStatisticPrinter(databaseHandler, sender, sender.getName(), heavySpleef.getLogger());
	}
	
	printer.print();
}
 
Example 16
Source File: LimitsV2.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onCommand(LWCCommandEvent event) {
    if (!enabled || event.isCancelled()) {
        return;
    }

    if (!event.hasFlag("limits")) {
        return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();
    event.setCancelled(true);

    String playerName;

    if (args.length == 0) {
        if (args.length == 0 && !(sender instanceof Player)) {
            sender.sendMessage(Colors.Dark_Red + "You are not a player!");
            return;
        }

        playerName = sender.getName();
    } else {
        if (lwc.isAdmin(sender)) {
            playerName = args[0];
        } else {
            lwc.sendLocale(sender, "protection.accessdenied");
            return;
        }
    }

    @SuppressWarnings("deprecation")
    Player player = lwc.getPlugin().getServer().getPlayer(playerName);

    if (player == null) {
        sender.sendMessage(Colors.Dark_Red + "That player is not online!");
        return;
    }

    // send their limits to them
    sendLimits(sender, player, getPlayerLimits(player));
}
 
Example 17
Source File: SetBiome.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
public SetBiome(final ASkyBlock plugin, final Island island, final Biome biomeType, CommandSender sender) {
    final World world = island.getCenter().getWorld();
    final UUID playerUUID = (sender != null && sender instanceof Player) ? ((Player)sender).getUniqueId() : null;
    final String playerName = (sender != null && sender instanceof Player) ? sender.getName() : "";
    if (sender != null) {
        plugin.getLogger().info("Starting biome change for " + playerName + " (" + biomeType.name() + ")");
    }
    // Update the settings so they can be checked later
    island.setBiome(biomeType);
    xDone = island.getMinX();
    zDone = island.getMinZ();
    new BukkitRunnable() {                
        @Override
        public void run() {
            if (inProgress) {
                return;
            }
            inProgress = true;
            int count = 0;
            //plugin.getLogger().info("DEBUG: Restart xDone = " + xDone + " zDone = " + zDone);
            //plugin.getLogger().info("DEBUG: max x = " + (island.getMinX() + island.getIslandDistance()));
            while (xDone < (island.getMinX() + island.getIslandDistance())) {                    
                while(zDone < (island.getMinZ() + island.getIslandDistance())) {
                    world.setBiome(xDone, zDone, biomeType);
                    //plugin.getLogger().info("DEBUG: xDone = " + xDone + " zDone = " + zDone);
                    if (count++ > SPEED) {
                        //plugin.getLogger().info("DEBUG: set " + SPEED + " blocks");
                        inProgress = false;
                        return;
                    }
                    zDone++;
                }
                zDone = island.getMinZ();
                xDone++;
            }
            //plugin.getLogger().info("DEBUG: END xDone = " + xDone + " zDone = " + zDone);
            this.cancel(); 
            plugin.getLogger().info("Finished biome change for " + playerName + " (" + biomeType.name() + ")");
            if (playerUUID != null) {
                Player p = plugin.getServer().getPlayer(playerUUID);
                if (p != null && p.isOnline()) {
                    Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(playerUUID).biomeSet.replace("[biome]", Util.prettifyText(biomeType.name())));
                    Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(playerUUID).needRelog);
                }
            } else {
                plugin.getMessages().setMessage(playerUUID, ChatColor.GREEN + plugin.myLocale(playerUUID).biomeSet.replace("[biome]", biomeType.name()));
            }
        }
    }.runTaskTimer(plugin, 0L, 20L); // Work every second 

}