Search in sources :

Example 1 with MassiveSet

use of com.massivecraft.massivecore.collections.MassiveSet in project MassiveCore by MassiveCraft.

the class IdUtil method getLocalPlayerDatas.

// -------------------------------------------- //
// ONLINEPLAYER DATAS
// -------------------------------------------- //
// This data source is simply based on the players currently online
public static Set<IdData> getLocalPlayerDatas() {
    Set<IdData> ret = new MassiveSet<>();
    long millis = System.currentTimeMillis();
    for (Player player : MUtil.getOnlinePlayers()) {
        String id = getId(player);
        if (id == null)
            throw new NullPointerException("id");
        String name = getName(player);
        if (name == null)
            throw new NullPointerException("name");
        IdData data = new IdData(id, name, millis);
        ret.add(data);
    }
    return ret;
}
Also used : Player(org.bukkit.entity.Player) MassiveSet(com.massivecraft.massivecore.collections.MassiveSet)

Example 2 with MassiveSet

use of com.massivecraft.massivecore.collections.MassiveSet in project MassiveCore by MassiveCraft.

the class TypeNameAbstract method read.

// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String read(String arg, CommandSender sender) throws MassiveException {
    if (arg == null)
        throw new NullPointerException("arg");
    // Allow changing capitalization of the current name if lenient.
    String current = this.getCurrentName(sender);
    if (current != null && current.equalsIgnoreCase(arg) && this.isLenient())
        return arg;
    if (this.isNameTaken(arg))
        throw new MassiveException().addMsg("<b>The name \"<h>%s<b>\" is already in use.", arg);
    Integer lengthMin = this.getLengthMin();
    if (lengthMin != null && arg.length() < lengthMin) {
        throw new MassiveException().addMsg("<b>The name must be at least <h>%d<b> characters.", lengthMin);
    }
    Integer lengthMax = this.getLengthMax();
    if (lengthMax != null && arg.length() > lengthMax) {
        throw new MassiveException().addMsg("<b>The name must be at most <h>%d<b> characters.", lengthMax);
    }
    Set<Character> disallowed = new MassiveSet<>();
    for (char character : arg.toCharArray()) {
        if (!this.isCharacterAllowed(character))
            disallowed.add(character);
    }
    // We found some disallowed characters
    if (!disallowed.isEmpty()) {
        String characterViolations = Txt.implode(disallowed, "");
        String pluralityResolution = disallowed.size() == 1 ? " is" : "s are";
        throw new MassiveException().addMsg("<b>The following character%s not allowed: <h>%s<b>.", pluralityResolution, characterViolations);
    }
    return arg;
}
Also used : MassiveException(com.massivecraft.massivecore.MassiveException) MassiveSet(com.massivecraft.massivecore.collections.MassiveSet)

Example 3 with MassiveSet

use of com.massivecraft.massivecore.collections.MassiveSet in project MassiveCore by MassiveCraft.

the class TypeSenderIdAbstract method getTabList.

@Override
public Collection<String> getTabList(CommandSender sender, String arg) {
    // Step 1: Calculate presence.
    SenderPresence presence = this.presence;
    if (presence == SenderPresence.ANY)
        presence = SenderPresence.ONLINE;
    // Special step: We don't tab complete offline players.
    if (presence == SenderPresence.OFFLINE)
        return Collections.emptySet();
    // Step 2: Calculate type.
    SenderType type = this.type;
    // Step 3: Get Ids
    Set<String> ids = IdUtil.getIds(presence, type);
    // Step 4: Create Ret with visible names
    boolean addIds = (arg.length() >= TAB_LIST_UUID_THRESHOLD);
    int size = ids.size();
    if (addIds)
        size *= 2;
    Set<String> ret = new MassiveSet<>(size);
    for (String id : ids) {
        if (!MixinVisibility.get().isVisible(id, sender))
            continue;
        if (addIds)
            ret.add(id);
        String name = IdUtil.getName(id);
        if (name == null)
            continue;
        ret.add(name);
    }
    // Step 5: Return the ret.
    return ret;
}
Also used : SenderType(com.massivecraft.massivecore.SenderType) SenderPresence(com.massivecraft.massivecore.SenderPresence) MassiveSet(com.massivecraft.massivecore.collections.MassiveSet)

Example 4 with MassiveSet

use of com.massivecraft.massivecore.collections.MassiveSet in project MassiveCore by MassiveCraft.

the class BoardUtil method updateBoards.

public static void updateBoards() {
    // Create
    Set<Scoreboard> boards = new MassiveSet<>();
    // Fill > Simple
    boards.add(getBoardMain());
    boards.add(getBoardOur());
    // Fill > Players
    for (Player player : getPlayers().values()) {
        Scoreboard board = getBoard(player);
        boards.add(board);
    }
    // Set
    boards = Collections.unmodifiableSet(boards);
    BoardUtil.boards = boards;
}
Also used : Player(org.bukkit.entity.Player) Scoreboard(org.bukkit.scoreboard.Scoreboard) MassiveSet(com.massivecraft.massivecore.collections.MassiveSet)

Example 5 with MassiveSet

use of com.massivecraft.massivecore.collections.MassiveSet in project MassiveCore by MassiveCraft.

the class MUtil method getNearbyPlayers.

public static Set<Player> getNearbyPlayers(Location location, double radius) {
    // Create
    Set<Player> ret = new MassiveSet<>();
    // Fill
    final World world = location.getWorld();
    final double radiusSquared = radius * radius;
    for (Player player : MUtil.getOnlinePlayers()) {
        Location playerLocation = player.getLocation();
        World playerWorld = playerLocation.getWorld();
        if (!world.equals(playerWorld))
            continue;
        double distanceSquared = location.distanceSquared(playerLocation);
        if (distanceSquared > radiusSquared)
            continue;
        ret.add(player);
    }
    // Return
    return ret;
}
Also used : Player(org.bukkit.entity.Player) ExtractorPlayer(com.massivecraft.massivecore.util.extractor.ExtractorPlayer) ExtractorWorld(com.massivecraft.massivecore.util.extractor.ExtractorWorld) World(org.bukkit.World) MassiveSet(com.massivecraft.massivecore.collections.MassiveSet) Location(org.bukkit.Location)

Aggregations

MassiveSet (com.massivecraft.massivecore.collections.MassiveSet)5 Player (org.bukkit.entity.Player)3 MassiveException (com.massivecraft.massivecore.MassiveException)1 SenderPresence (com.massivecraft.massivecore.SenderPresence)1 SenderType (com.massivecraft.massivecore.SenderType)1 ExtractorPlayer (com.massivecraft.massivecore.util.extractor.ExtractorPlayer)1 ExtractorWorld (com.massivecraft.massivecore.util.extractor.ExtractorWorld)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Scoreboard (org.bukkit.scoreboard.Scoreboard)1