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

The following are Jave code examples for showing how to use getPlayerExact() 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: MelonNametag   File: Commands.java   View Source Code Vote up 6 votes
private int Cheak(String[] args) {
	if (args[0] == null) {
		return 0;
	} else if (Bukkit.getPlayerExact(args[0]) == null) {
		return 3;
	} else if (args[1] == null) {
		return 0;
	} else if (CheckPS(args[1]) == false) {
		return 4;
	} else if (args[2] == null) {
		return 0;
	} else if (args[3] == null) {
		return 0;
	} else if (CheakColor(args[3]) == false) {
		return 1;
	} else if (CheakFormat(args[4]) == false) {
		return 2;
	} else
		return 233;
}
 
Example 2
Project: mczone   File: TeamChatCmd.java   View Source Code Vote up 6 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        Chat.player(sender, "&cThis command is only available for players!");
        return true;
    }
    Player p = (Player) sender;
    if (args.length == 0) {
    	Chat.player(sender, "&cUse command like this: /team [message]");
    	return true;
    }
    StringBuilder sb = new StringBuilder();
    for (String arg : args) {
    	sb.append(arg);
    	sb.append(" ");
    }
    Team team = Team.getTeam(p);
    for (String s : team.getMembers()) {
    	Player t = Bukkit.getPlayerExact(s);
    	Chat.player(t, "&2/team &7" + team.getColor() + p.getName() + "&f: " + sb.toString());
    	return true;
    }
    
    return true;
}
 
Example 3
Project: DynamicAC   File: UserManager.java   View Source Code Vote up 6 votes
public void incrementUser(User user, String reason) {
    if(user == null) {
        System.err.println("User reported null!");
        return;
    }
    Player player = Bukkit.getPlayerExact(user.getName());
    if(player != null && user.getLevel() < MagicNumbers.MAX_WARN) {
        player.sendMessage(DynamicAC.prefix + "You've been warned for hacking!");
        if(reason.isEmpty()) {
            for (Player p : DynamicAC.instance.onlinestaff) {
                p.sendMessage(DynamicAC.prefix + player.getName() + " failed a check!");
            }
        }
        int warns = user.increment();
        user.serialize();
        DynamicAC.punishmentLog(user.getName() + " incremented to " + user.getLevel() + " at " + LocalDateTime.now()
                + ".");
        if (warns >= MagicNumbers.MAX_WARN && !player.isOnline()) {
            users.remove(user);
            user = null; // so it can be garbage collected
        }
    }
}
 
Example 4
Project: ProjectAres   File: CommandUtils.java   View Source Code Vote up 5 votes
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 5
Project: MinecraftMarket-Plugin   File: PurchasesTask.java   View Source Code Vote up 5 votes
private void runCommand(Command command) {
    Player player = Bukkit.getPlayerExact(command.getPlayer().getName());
    if (command.isRequiredOnline() && (player == null || !player.isOnline())) {
        return;
    }

    if (command.getRequiredSlots() > 0 && (player != null && player.isOnline())) {
        if (getEmptySlots(player.getInventory()) < command.getRequiredSlots()) {
            return;
        }
    }

    if (MCMarket.getApi().setExecuted(command.getId())) {
        plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, () -> {
            plugin.getServer().getScheduler().runTask(plugin, () -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command.getCommand()));
            if (command.isRepeat()) {
                long period = command.getRepeatPeriod() > 0 ? 20 * 60 * 60 * command.getRepeatPeriod() : 1;
                new BukkitRunnable() {
                    int executed = 0;

                    @Override
                    public void run() {
                        plugin.getServer().getScheduler().runTask(plugin, () -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command.getCommand()));
                        executed++;

                        if (executed >= command.getRepeatCycles()) {
                            cancel();
                        }
                    }
                }.runTaskTimerAsynchronously(plugin, period, period);
            }
        }, command.getDelay() > 0 ? 20 * command.getDelay() : 1);
    }
}
 
Example 6
Project: mczone   File: Walls.java   View Source Code Vote up 5 votes
public static void updateSpectators() {
	for (String list : getSpectators()) {
		Player t = Bukkit.getPlayerExact(list);
		if (t == null || !t.isOnline())
			continue;
		
		t.setAllowFlight(true);
		
		for (Player p : Bukkit.getOnlinePlayers()) {
			if (getSpectators().contains(p.getName()))
				continue;
			p.hidePlayer(t);
		}
	}
}
 
Example 7
Project: EchoPet   File: Pet.java   View Source Code Vote up 5 votes
@Override
public Player getOwner(){
	if(this.ownerIdentification == null){ return null; }
	if(this.ownerIdentification instanceof UUID){
		return Bukkit.getPlayer((UUID) ownerIdentification);
	}else{
		return Bukkit.getPlayerExact((String) this.ownerIdentification);
	}
}
 
Example 8
Project: mczone   File: BanCmd.java   View Source Code Vote up 5 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (Rank.getRank(sender.getName()).getType().getLevel() < RankType.MOD.getLevel()) {
		Chat.player(sender, "&cYou don't have permission to do this.");
		return true;
	}
    if (args.length < 2) {
    	Chat.player(sender, "&cUsage: /ban [username] [reason]");
    	return true;
    }
    
    String username = null;
    String reason = Chat.stripColor(StringUtils.join(args, " ", 1, args.length));
    
    Player p = Bukkit.getPlayerExact(args[0]);
    if (p != null)
    	username = p.getName();
    else {
    	String check = Hive.getInstance().getUsername(args[0]);
    	if (check != null)
    		username = check;
    }
    if (username == null) {
    	Chat.player(sender, "&cNo player found by the name of, " + args[0]);
    	return true;
    }
    String prefix = "INSERT INTO infractions (username,staff,type,reason) VALUES ";
    String content = "('" + username + "','" + sender.getName() + "','ban','" + reason + "')";
    Hive.getInstance().getDatabase().update(prefix + content);
    
    Chat.player(sender, "&4[Ban] &b" + username + " &7&ofor &c" + reason);
    
    Ban i = new Ban(username, reason, Hive.getInstance().getServerTime());
  	if (p != null && p.isOnline())
  		p.kickPlayer(i.getKickMessage());
  	
    return true;
}
 
Example 9
Project: EchoPet   File: UUIDMigration.java   View Source Code Vote up 5 votes
/**
 * 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 10
Project: DynamicAC   File: User.java   View Source Code Vote up 5 votes
protected void reset() {
    Player player = Bukkit.getPlayerExact(playerName);
    if(player != null && player.isOnline()) {
        player.sendMessage(DynamicAC.prefix + "Your warn level was cleared!");
    }
    this.level = 0;
    serialize();
}
 
Example 11
Project: mczone   File: PetInstance.java   View Source Code Vote up 5 votes
public void update() {
	if (entity != null) {
		//((CraftEntity) entity).getHandle().setEquipment(4, new net.minecraft.server.v1_5_R2.ItemStack(Item.DIAMOND_HELMET));
		//Chat.server(((CraftEntity) entity).getHandle().getEquipment().toString());
		Player owner = Bukkit.getPlayerExact(this.owner);
		if (owner == null)
			return;
        entity.setCustomName(nameColor + name);
        entity.setCustomNameVisible(true);
        if (entity instanceof Tameable) {
        	tamed = true;
        	((Tameable) entity).setTamed(true);
        	((Tameable) entity).setOwner(owner);
        }
        if (entity instanceof Ageable && age != null) {
        	if (getAge() == Age.BABY)
        		((Ageable) entity).setBaby();
        	((Ageable) entity).setAgeLock(true);
        }
        if (entity instanceof Zombie && age != null) {
        	if (getAge() == Age.BABY)
        		((Zombie) entity).setBaby(true);
        }
        if (entity instanceof Sheep && color != null) {
        	((Sheep) entity).setColor(getColor());
        }
	}
}
 
Example 12
Project: DynamicAC   File: CommandDispatcher.java   View Source Code Vote up 5 votes
private static void report(String playername, Player reporter, String reason, String... message) {
    Player player = Bukkit.getPlayerExact(playername);
    if (player == null) {
        reporter.sendMessage(ChatColor.RED + "That player cannot be found!");
        return;
    }
    for (Player p : DynamicAC.instance.onlinestaff) {
        p.sendMessage(DynamicAC.prefix + ChatColor.AQUA + reporter.getName() + " reported " + player.getName() +
                " for " + reason + " with this message: " + ChatColor.GOLD + (message[0] != null ? message[0] : "") + (message[1] != null ? message[1] : "") + (message[2] != null ? message[2] : "") + (message[3] != null ? message[3] : "") + (message[4] != null ? message[4] : "") + (message[5] != null ? message[5] : "") + (message[6] != null ? message[6] : "") + (message[7] != null ? message[7] : "") + (message[8] != null ? message[8] : "") + (message[9] != null ? message[9] : "") + (message[10] != null ? message[10] : ""));
    }
}
 
Example 13
Project: ZentrelaRPG   File: SongPlayer.java   View Source Code Vote up 4 votes
protected void createThread() {
    playerThread = new Thread(new Runnable() {
        @Override
        public void run() {
            while (!destroyed) {
                long startTime = System.currentTimeMillis();
                synchronized (SongPlayer.this) {
                    if (playing) {
                        calculateFade();
                        tick++;
                        if (tick > song.getLength()) {
                            playing = false;
                            tick = -1;
                            SongEndEvent event = new SongEndEvent(SongPlayer.this);
                            Bukkit.getPluginManager().callEvent(event);
                            if (autoDestroy) {
                                destroy();
                                return;
                            }
                        }
                        for (String s : playerList) {
                            @SuppressWarnings("deprecation")
                            Player p = Bukkit.getPlayerExact(s);
                            if (p == null) {
                                // offline...
                                continue;
                            }
                            playTick(p, tick);
                        }
                    }
                }
                long duration = System.currentTimeMillis() - startTime;
                float delayMillis = song.getDelay() * 50;
                if (duration < delayMillis) {
                    try {
                        Thread.sleep((long) (delayMillis - duration));
                    } catch (InterruptedException e) {
                        // do nothing
                    }
                }
            }
        }
    });
    playerThread.setPriority(Thread.MAX_PRIORITY);
    playerThread.start();
}
 
Example 14
Project: ChatModerator   File: PatternUtils.java   View Source Code Vote up 4 votes
public static boolean doesPlayerExist(String name) {
    return Bukkit.getPlayerExact(name) != null;
}
 
Example 15
Project: Hub   File: SongPlayer.java   View Source Code Vote up 4 votes
protected void createThread() {
    playerThread = new Thread(new Runnable() {
        @Override
        public void run() {
            while (!destroyed) {
                long startTime = System.currentTimeMillis();
                synchronized (SongPlayer.this) {
                    if (playing) {
                        calculateFade();
                        tick++;
                        if (tick > song.getLength()) {
                            playing = false;
                            tick = -1;
                            SongEndEvent event = new SongEndEvent(SongPlayer.this);
                            Bukkit.getPluginManager().callEvent(event);
                            if (autoDestroy) {
                                destroy();
                                return;
                            }
                        }
                        for (String s : playerList) {
                            Player p = Bukkit.getPlayerExact(s);
                            if (p == null) {
                                // offline...
                                continue;
                            }
                            playTick(p, tick);
                        }
                    }
                }
                long duration = System.currentTimeMillis() - startTime;
                float delayMillis = song.getDelay() * 50;
                if (duration < delayMillis) {
                    try {
                        Thread.sleep((long) (delayMillis - duration));
                    } catch (InterruptedException e) {
                        // do nothing
                    }
                }
            }
        }
    });
    playerThread.setPriority(Thread.MAX_PRIORITY);
    playerThread.start();
}
 
Example 16
Project: mczone   File: HatCmd.java   View Source Code Vote up 4 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (Rank.getRank(sender.getName()).getType().getLevel() < RankType.ELITE.getLevel()) {
		Chat.player(sender, "&cYou don't have permission to do this.");
		return true;
	}
    if (args.length != 1) {
    	Chat.player(sender, "&cUsage: /hat [item id or name]");
    	return true;
    }
    
    boolean isInt = true;
    Material m = null;
    try {
    	m = Material.getMaterial(Integer.parseInt(args[0]));
    }
    catch(Exception e) {
    	isInt = false;
    	m = Material.getMaterial(args[0].toUpperCase());
    }
    
    if (m == null) {
    	if (!isInt) {
    		for (Material c : Material.values())
    			if (c.name().toLowerCase().startsWith(args[0].toLowerCase()))
    				m = c;
    	}
    }
    
    if (m == null) {
     	Chat.player(sender, "&cUnknown item: " + args[0]);
     	return true;
    }
    
    Player p = Bukkit.getPlayerExact(sender.getName());
    p.getInventory().setHelmet(new ItemStack(m));
    Chat.player(sender, "&6Set helmet to &c" + m.name().replace("_", " ").toLowerCase());
    
    
	return true;
}
 
Example 17
Project: mczone   File: PlayerScheduler.java   View Source Code Vote up 4 votes
@Override
public void run() {
	Iterator<Entry<String, Date>> i = Events.getJoinTimes().entrySet().iterator();
	while (i.hasNext()) {
		Entry<String, Date> e = i.next();
		Date now = new Date();
		Date last = e.getValue();
		final Player p = Bukkit.getPlayerExact(e.getKey());
		if (p == null || !p.isOnline()) {
			i.remove();
			continue;
		}
		
		Gamer g = Gamer.get(p.getName());
		if (g.getRank().getLevel() > 0)
			continue;
		
		int delay = 300; // Seconds
		boolean kick = false;
		if (now.getTime() - last.getTime() > delay * 1000) {
			kick = true;
		}
		else if (now.getTime() - last.getTime() > 30 * 1000) {
			if (!Events.getMovement().contains(p.getName()))
				kick = true;
		}
		
		if (kick) {
			Chat.player(p, "&4[Lobby] &cYou have been kicked for being AFK in the MC Zone lobby.");
			new BukkitRunnable() {
				@Override
				public void run() {
					p.kickPlayer(Chat.colors("&4[Lobby] &cYou have been kicked for being AFK in the MC Zone lobby."));
				}
				
			}.runTask(Lobby.getInstance());
			i.remove();
		}
		
	}
}
 
Example 18
Project: mczone   File: TempbanCmd.java   View Source Code Vote up 4 votes
@Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  	if (Rank.getRank(sender.getName()).getType().getLevel() < RankType.MOD.getLevel()) {
  		Chat.player(sender, "&cYou don't have permission to do this.");
  		return true;
  	}
      if (args.length < 3) {
      	Chat.player(sender, "&cUsage: /tempban [username] [time] [reason]");
      	return true;
      }
      
      String username = null;
      String reason = Chat.stripColor(StringUtils.join(args, " ", 2, args.length));
      
      Player p = Bukkit.getPlayerExact(args[0]);
      if (p != null)
      	username = p.getName();
      else {
      	String check = Hive.getInstance().getUsername(args[0]);
      	if (check != null)
      		username = check;
      }
      if (username == null) {
      	Chat.player(sender, "&cNo player found by the name of, " + args[0]);
      	return true;
      }
      
      int duration = parseTime(args[1]);
      if (duration == 0) {
          Chat.player(sender, "&cInvalid duration! (ex. 10m, 6h, 1d, 1w)");
          return true;
      }
      String prefix = "INSERT INTO infractions (username,staff,type,end,reason) VALUES ";
      String content = "('" + username + "','" + sender.getName() + "','tempban',DATE_ADD(now(), INTERVAL " + duration + " SECOND),'" + reason + "')";
      Hive.getInstance().getDatabase().update(prefix + content);
      Chat.player(sender, "&4[Tempban] &b" + username + " &7&ofor &c" + reason + " &7(" + getDuration(args[1]) + ")");
      
      Date expires = null;
      ResultSet r = Hive.getInstance().getDatabase().query("SELECT DATE_ADD(now(), INTERVAL " + duration + " SECOND)");
      try {
	while (r.next())
		expires = r.getTimestamp("DATE_ADD(now(), INTERVAL " + duration + " SECOND)");
} catch (SQLException e) {
	e.printStackTrace();
}
      	
      Tempban i = new Tempban(username, reason, Hive.getInstance().getServerTime(), expires);
    	if (p != null && p.isOnline())
    		p.kickPlayer(i.getKickMessage());
    	
  	return true;
  }
 
Example 19
Project: DynamicAC   File: CommandDispatcher.java   View Source Code Vote up 4 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage("You must be a player!");
        return false;
    }
    Player player = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("dac")) {
        if(args.length == 0) {
            player.sendMessage(ChatColor.RED + "[DAC]:" + ChatColor.GREEN + "Available Commands: ");
            player.sendMessage("dac Report <Player> <Reason> [Message]");
            if (player.hasPermission("dynamicac.staff")) {
                player.sendMessage("dac Check <Player> - checks a Player for all hacks.");
                player.sendMessage("dac Report <Player> <Reason> [Message]");
                player.sendMessage("dac notifications - Turns on/off hackn notifications");
            }
            return true;
        }
        if ((args[0].equalsIgnoreCase("notifications") || args[0].equalsIgnoreCase("staff")) && player.hasPermission("dynamicac" + ".staff")) {
            if (DynamicAC.instance.onlinestaff.contains(player)) {
                DynamicAC.instance.onlinestaff.remove(player);
                player.sendMessage(ChatColor.GREEN + "You turned off notifications.");
            } else {
                DynamicAC.instance.onlinestaff.add(player);
                player.sendMessage(ChatColor.GREEN + "You turned on notifications.");
            }
        }
        if(args[0].equalsIgnoreCase("report") && args.length > 3) {
            Player reported = Bukkit.getPlayerExact(args[1]);
            String reason = args[2];
            ArrayList<String> message = new ArrayList<>();
            for (String string : args) {
                if(!string.equals(args[1]) && !string.equals(reason)) {
                    message.add(string);
                }
            }
            report(reported.getName(),player,reason,message.toArray(new String[message.size()]));
        }
        if(args[0].equalsIgnoreCase("check") && player.hasPermission("dynamicac.staff") && args.length == 2) {
            DynamicAC.FullCheck(Bukkit.getPlayerExact(args[1]));
        }
        if(args[0].equalsIgnoreCase("warn") && player.hasPermission("dynamicac.staff") && args.length == 2) {
            Player pla = Bukkit.getPlayerExact(args[1]);
            DACManager.getUserManager().incrementUser(DACManager.getUserManager().getUser(pla.getName()),"Staff");
        }
        if(args[0].equalsIgnoreCase("debug") && player.hasPermission("dynamicac.debug")) {
            if(DynamicAC.instance.devs.contains(player)) {
                DynamicAC.instance.devs.remove(player);
                player.sendMessage("You turned on debug messages.");
            } else {
                DynamicAC.instance.devs.add(player);
                player.sendMessage(ChatColor.GREEN + "You turned off debug messages.");
            }
        }
        if(args[0].equalsIgnoreCase("clear") && player.hasPermission("dynamicac.staff") && args.length == 2) {
            User user = DACManager.getUserManager().getUser(args[1]);
            if(user == null) {
                player.sendMessage(DynamicAC.prefix + "Player not found!");
                return true;
            }
            DACManager.getUserManager().resetUser(user);
        }
    }
    return true;
}
 
Example 20
Project: ProjectAres   File: Users.java   View Source Code Vote up 2 votes
/**
 * 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());
}