use of com.sk89q.worldguard.util.profile.Profile in project WorldGuard by EngineHub.
the class DefaultDomain method toPlayersComponent.
private Component toPlayersComponent(ProfileCache cache) {
List<String> uuids = Lists.newArrayList();
Map<String, UUID> profileMap = Maps.newHashMap();
for (String name : playerDomain.getPlayers()) {
profileMap.put(name, null);
}
if (cache != null) {
ImmutableMap<UUID, Profile> results = cache.getAllPresent(playerDomain.getUniqueIds());
for (UUID uuid : playerDomain.getUniqueIds()) {
Profile profile = results.get(uuid);
if (profile != null) {
profileMap.put(profile.getName(), uuid);
} else {
uuids.add(uuid.toString());
}
}
} else {
for (UUID uuid : playerDomain.getUniqueIds()) {
uuids.add(uuid.toString());
}
}
final TextComponent.Builder builder = TextComponent.builder("");
final Iterator<TextComponent> profiles = profileMap.keySet().stream().sorted().map(name -> {
final UUID uuid = profileMap.get(name);
final TextComponent component = TextComponent.of(name, TextColor.YELLOW).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, uuid == null ? TextComponent.of("Name only", TextColor.GRAY) : TextComponent.of("Last known name of uuid: ", TextColor.GRAY).append(TextComponent.of(uuid.toString(), TextColor.WHITE))));
if (uuid == null) {
return component;
}
return component.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, uuid.toString()));
}).iterator();
while (profiles.hasNext()) {
builder.append(profiles.next());
if (profiles.hasNext() || !uuids.isEmpty()) {
builder.append(TextComponent.of(", "));
}
}
if (!uuids.isEmpty()) {
builder.append(TextComponent.of(uuids.size() + " unknown uuid" + (uuids.size() == 1 ? "" : "s"), TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(String.join("\n", uuids)).append(TextComponent.newline().append(TextComponent.of("Click to select"))))).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, String.join(",", uuids))));
}
return builder.build();
}
use of com.sk89q.worldguard.util.profile.Profile in project WorldGuard by EngineHub.
the class DomainInputResolver method call.
@Override
public DefaultDomain call() throws UnresolvedNamesException {
DefaultDomain domain = new DefaultDomain();
List<String> namesToQuery = new ArrayList<>();
for (String s : input) {
Matcher m = GROUP_PATTERN.matcher(s);
if (m.matches()) {
domain.addGroup(m.group(1));
} else {
UUID uuid = parseUUID(s);
if (uuid != null) {
// Try to add any UUIDs given
domain.addPlayer(UUID.fromString(UUIDs.addDashes(s.replaceAll("^uuid:", ""))));
} else {
switch(locatorPolicy) {
case NAME_ONLY:
domain.addPlayer(s);
break;
case UUID_ONLY:
namesToQuery.add(s.toLowerCase());
break;
case UUID_AND_NAME:
domain.addPlayer(s);
namesToQuery.add(s.toLowerCase());
}
}
}
}
if (!namesToQuery.isEmpty()) {
try {
for (Profile profile : profileService.findAllByName(namesToQuery)) {
namesToQuery.remove(profile.getName().toLowerCase());
domain.addPlayer(profile.getUniqueId());
}
} catch (IOException e) {
throw new UnresolvedNamesException("The UUID lookup service failed so the names entered could not be turned into UUIDs");
} catch (InterruptedException e) {
throw new UnresolvedNamesException("UUID lookup was interrupted");
}
}
if (!namesToQuery.isEmpty()) {
throw new UnresolvedNamesException("Unable to resolve the names " + Joiner.on(", ").join(namesToQuery));
}
return domain;
}
use of com.sk89q.worldguard.util.profile.Profile in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerJoin.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(world);
if (cfg.activityHaltToggle) {
player.sendMessage(ChatColor.YELLOW + "Intensive server activity has been HALTED.");
int removed = 0;
for (Entity entity : world.getEntities()) {
if (Entities.isIntensiveEntity(BukkitAdapter.adapt(entity))) {
entity.remove();
removed++;
}
}
if (removed > 10) {
log.info("Halt-Act: " + removed + " entities (>10) auto-removed from " + player.getWorld());
}
}
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW + "Fire spread is currently globally disabled for this world.");
}
Events.fire(new ProcessPlayerEvent(player));
WorldGuard.getInstance().getExecutorService().submit(() -> WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
}
use of com.sk89q.worldguard.util.profile.Profile in project WorldGuard by EngineHub.
the class UUIDMigration method migrate.
private boolean migrate(Collection<ProtectedRegion> regions) throws MigrationException {
// Name scan pass
Set<String> names = getNames(regions);
if (!names.isEmpty()) {
// This task logs the progress of conversion (% converted...)
// periodically
TimerTask task = new ResolvedNamesTimerTask();
try {
timer.schedule(task, LOG_DELAY, LOG_DELAY);
log.log(Level.INFO, "Resolving " + names.size() + " name(s) into UUIDs... this may take a while.");
// Don't lookup names that we already looked up for previous
// worlds -- note: all names are lowercase in these collections
Set<String> lookupNames = new HashSet<>(names);
lookupNames.removeAll(resolvedNames.keySet());
// Ask Mojang for names
profileService.findAllByName(lookupNames, new Predicate<Profile>() {
@Override
public boolean apply(Profile profile) {
resolvedNames.put(profile.getName().toLowerCase(), profile.getUniqueId());
return true;
}
});
} catch (IOException e) {
throw new MigrationException("The name -> UUID service failed", e);
} catch (InterruptedException e) {
throw new MigrationException("The migration was interrupted");
} finally {
// Stop showing the % converted messages
task.cancel();
}
// Name -> UUID in all regions
log.log(Level.INFO, "UUIDs resolved... now migrating all regions to UUIDs where possible...");
convert(regions);
return true;
} else {
return false;
}
}
use of com.sk89q.worldguard.util.profile.Profile in project WorldGuard by EngineHub.
the class DefaultDomain method toPlayersString.
public String toPlayersString(@Nullable ProfileCache cache) {
StringBuilder str = new StringBuilder();
List<String> output = new ArrayList<>();
for (String name : playerDomain.getPlayers()) {
output.add("name:" + name);
}
if (cache != null) {
ImmutableMap<UUID, Profile> results = cache.getAllPresent(playerDomain.getUniqueIds());
for (UUID uuid : playerDomain.getUniqueIds()) {
Profile profile = results.get(uuid);
if (profile != null) {
output.add(profile.getName() + "*");
} else {
output.add("uuid:" + uuid);
}
}
} else {
for (UUID uuid : playerDomain.getUniqueIds()) {
output.add("uuid:" + uuid);
}
}
output.sort(String.CASE_INSENSITIVE_ORDER);
for (Iterator<String> it = output.iterator(); it.hasNext(); ) {
str.append(it.next());
if (it.hasNext()) {
str.append(", ");
}
}
return str.toString();
}
Aggregations