Java Code Examples for cn.nukkit.Player#getName()

The following examples show how to use cn.nukkit.Player#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: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void actOnQuitEvent(PlayerQuitEvent event) {
    long time = System.currentTimeMillis();
    Player player = event.getPlayer();
    String playerName = player.getName();
    UUID playerUUID = player.getUniqueId();
    if (playerUUID == null) return; // Can be null when player is not signed in to xbox live

    UUID serverUUID = serverInfo.getServerUUID();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    NukkitAFKListener.AFK_TRACKER.loggedOut(playerUUID, time);

    nicknameCache.removeDisplayName(playerUUID);

    dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, player::isBanned));

    sessionCache.endSession(playerUUID, time)
            .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));

    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
 
Example 2
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void beforePlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_LEAVE));
}
 
Example 3
Source File: SeeMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args){
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.seemoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 1){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	
	String player = args[0];
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	
	double money = this.plugin.myMoney(player);
	if(money < 0){
		sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
		return true;
	}
	sender.sendMessage(this.plugin.getMessage("seemoney-seemoney", new String[]{player, Double.toString(money)}, sender));
	return true;
}
 
Example 4
Source File: SeeMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args){
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.seemoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 1){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	
	String player = args[0];
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	
	double money = this.plugin.myMoney(player);
	if(money < 0){
		sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
		return true;
	}
	sender.sendMessage(this.plugin.getMessage("seemoney-seemoney", new String[]{player, Double.toString(money)}, sender));
	return true;
}
 
Example 5
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void actOnJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    UUID playerUUID = player.getUniqueId();
    UUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    NukkitAFKListener.AFK_TRACKER.performedAction(playerUUID, time);

    String world = player.getLevel().getName();
    String gm = GMTimes.magicNumberToGMName(player.getGamemode());

    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));

    String address = player.getAddress();

    String playerName = player.getName();
    String displayName = player.getDisplayName();

    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(
                new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
        );
    }

    long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate, playerName, serverUUID));
    Session session = new Session(playerUUID, serverUUID, time, world, gm);
    session.putRawData(SessionKeys.NAME, playerName);
    session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());
    sessionCache.cacheSession(playerUUID, session)
            .ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));

    database.executeTransaction(new NicknameStoreTransaction(
            playerUUID, new Nickname(displayName, time, serverUUID),
            (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)
    ));

    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
 
Example 6
Source File: TakeMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.takemoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		if(amount < 0){
			sender.sendMessage(this.plugin.getMessage("takemoney-invalid-number", sender));
			return true;
		}
		
		int result = this.plugin.reduceMoney(player, amount);
		switch(result){
		case EconomyAPI.RET_INVALID:
			sender.sendMessage(this.plugin.getMessage("takemoney-player-lack-of-money", new String[]{player, Double.toString(amount), Double.toString(this.plugin.myMoney(player))}, sender));
			return true;
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_CANCELLED:
			sender.sendMessage(this.plugin.getMessage("takemoney-failed", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			sender.sendMessage(this.plugin.getMessage("takemoney-took-money", new String[]{player, Double.toString(amount)}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("takemoney-money-taken", new String[]{Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender));
	}
	return true;
}
 
Example 7
Source File: PayCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args){
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.pay")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(!(sender instanceof Player)){
		sender.sendMessage(TextFormat.RED + "Please use this command in-game.");
		return true;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		
		int result = this.plugin.reduceMoney((Player) sender, amount);
		switch(result){
		case EconomyAPI.RET_INVALID:
		case EconomyAPI.RET_CANCELLED:
			sender.sendMessage(this.plugin.getMessage("pay-failed", sender));
			return true;
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			this.plugin.addMoney(player, amount, true);
			
			sender.sendMessage(this.plugin.getMessage("pay-success", new String[]{Double.toString(amount), player}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("money-paid", new String[]{sender.getName(), Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender));
	}
	return true;
}
 
Example 8
Source File: GiveMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.givemoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		if(amount < 0){
			sender.sendMessage(this.plugin.getMessage("givemoney-invalid-number", sender));
			return true;
		}
		
		int result = this.plugin.addMoney(player, amount);
		switch(result){
		case EconomyAPI.RET_INVALID:
			sender.sendMessage(this.plugin.getMessage("reached-max", new String[]{Double.toString(amount)}, sender));
			return true;
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			sender.sendMessage(this.plugin.getMessage("givemoney-gave-money", new String[]{Double.toString(amount), player}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("givemoney-money-given", new String[]{Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("givemoney-must-be-number", sender));
	}
	return true;
}
 
Example 9
Source File: SetMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.setmoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		if(amount < 0){
			sender.sendMessage(this.plugin.getMessage("setmoney-invalid-number", sender));
			return true;
		}
		
		int result = this.plugin.setMoney(player, amount);
		switch(result){
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_CANCELLED:
			sender.sendMessage(this.plugin.getMessage("setmoney-failed", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_INVALID:
			sender.sendMessage(this.plugin.getMessage("reached-max", new String[]{Double.toString(amount)}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			sender.sendMessage(this.plugin.getMessage("setmoney-setmoney", new String[]{player, Double.toString(amount)}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("setmoney-set", new String[]{Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("setmoney-invalid-number", sender));
	}
	return true;
}
 
Example 10
Source File: TakeMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.takemoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		if(amount < 0){
			sender.sendMessage(this.plugin.getMessage("takemoney-invalid-number", sender));
			return true;
		}
		
		int result = this.plugin.reduceMoney(player, amount);
		switch(result){
		case EconomyAPI.RET_INVALID:
			sender.sendMessage(this.plugin.getMessage("takemoney-player-lack-of-money", new String[]{player, Double.toString(amount), Double.toString(this.plugin.myMoney(player))}, sender));
			return true;
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_CANCELLED:
			sender.sendMessage(this.plugin.getMessage("takemoney-failed", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			sender.sendMessage(this.plugin.getMessage("takemoney-took-money", new String[]{player, Double.toString(amount)}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("takemoney-money-taken", new String[]{Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender));
	}
	return true;
}
 
Example 11
Source File: PayCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args){
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.pay")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(!(sender instanceof Player)){
		sender.sendMessage(TextFormat.RED + "Please use this command in-game.");
		return true;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		
		int result = this.plugin.reduceMoney((Player) sender, amount);
		switch(result){
		case EconomyAPI.RET_INVALID:
		case EconomyAPI.RET_CANCELLED:
			sender.sendMessage(this.plugin.getMessage("pay-failed", sender));
			return true;
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			this.plugin.addMoney(player, amount, true);
			
			sender.sendMessage(this.plugin.getMessage("pay-success", new String[]{Double.toString(amount), player}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("money-paid", new String[]{sender.getName(), Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender));
	}
	return true;
}
 
Example 12
Source File: GiveMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.givemoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		if(amount < 0){
			sender.sendMessage(this.plugin.getMessage("givemoney-invalid-number", sender));
			return true;
		}
		
		int result = this.plugin.addMoney(player, amount);
		switch(result){
		case EconomyAPI.RET_INVALID:
			sender.sendMessage(this.plugin.getMessage("reached-max", new String[]{Double.toString(amount)}, sender));
			return true;
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			sender.sendMessage(this.plugin.getMessage("givemoney-gave-money", new String[]{Double.toString(amount), player}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("givemoney-money-given", new String[]{Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("givemoney-must-be-number", sender));
	}
	return true;
}
 
Example 13
Source File: SetMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.setmoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 2){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String player = args[0];
	
	Player p = this.plugin.getServer().getPlayer(player);
	if(p != null){
		player = p.getName();
	}
	try{
		double amount = Double.parseDouble(args[1]);
		if(amount < 0){
			sender.sendMessage(this.plugin.getMessage("setmoney-invalid-number", sender));
			return true;
		}
		
		int result = this.plugin.setMoney(player, amount);
		switch(result){
		case EconomyAPI.RET_NO_ACCOUNT:
			sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_CANCELLED:
			sender.sendMessage(this.plugin.getMessage("setmoney-failed", new String[]{player}, sender));
			return true;
		case EconomyAPI.RET_INVALID:
			sender.sendMessage(this.plugin.getMessage("reached-max", new String[]{Double.toString(amount)}, sender));
			return true;
		case EconomyAPI.RET_SUCCESS:
			sender.sendMessage(this.plugin.getMessage("setmoney-setmoney", new String[]{player, Double.toString(amount)}, sender));
			if(p instanceof Player){
				p.sendMessage(this.plugin.getMessage("setmoney-set", new String[]{Double.toString(amount)}, sender));
			}
			return true;
		}
	}catch(NumberFormatException e){
		sender.sendMessage(this.plugin.getMessage("setmoney-invalid-number", sender));
	}
	return true;
}