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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations