Cleanup some remaining TODOs

This commit is contained in:
Luck 2016-10-13 21:16:34 +01:00
parent cd758d7e48
commit 6109718c67
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
9 changed files with 107 additions and 42 deletions

View File

@ -220,11 +220,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return getDataFolder(); return getDataFolder();
} }
@Override
public Message getPlayerStatus(UUID uuid) {
return getServer().getPlayer(getUuidCache().getExternalUUID(uuid)) != null ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
}
@Override @Override
public int getPlayerCount() { public int getPlayerCount() {
return getServer().getOnlinePlayers().size(); return getServer().getOnlinePlayers().size();
@ -235,6 +230,16 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
} }
@Override
public Set<UUID> getOnlinePlayers() {
return getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet());
}
@Override
public boolean isOnline(UUID external) {
return getServer().getPlayer(external) != null;
}
@Override @Override
public List<Sender> getNotifyListeners() { public List<Sender> getNotifyListeners() {
return getServer().getOnlinePlayers().stream() return getServer().getOnlinePlayers().stream()

View File

@ -171,11 +171,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
return getDataFolder(); return getDataFolder();
} }
@Override
public Message getPlayerStatus(UUID uuid) {
return getProxy().getPlayer(getUuidCache().getExternalUUID(uuid)) != null ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
}
@Override @Override
public int getPlayerCount() { public int getPlayerCount() {
return getProxy().getOnlineCount(); return getProxy().getOnlineCount();
@ -186,6 +181,16 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
return getProxy().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()); return getProxy().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList());
} }
@Override
public Set<UUID> getOnlinePlayers() {
return getProxy().getPlayers().stream().map(ProxiedPlayer::getUniqueId).collect(Collectors.toSet());
}
@Override
public boolean isOnline(UUID external) {
return getProxy().getPlayer(external) != null;
}
@Override @Override
public List<Sender> getNotifyListeners() { public List<Sender> getNotifyListeners() {
return getProxy().getPlayers().stream() return getProxy().getPlayers().stream()

View File

@ -93,7 +93,10 @@ public interface LuckPermsPlugin {
* @param uuid The player's uuid * @param uuid The player's uuid
* @return a formatted status string * @return a formatted status string
*/ */
Message getPlayerStatus(UUID uuid); default Message getPlayerStatus(UUID uuid) {
UUID external = getUuidCache().getExternalUUID(uuid);
return isOnline(external) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
}
/** /**
* Gets the number of users online on the platform * Gets the number of users online on the platform
@ -107,6 +110,19 @@ public interface LuckPermsPlugin {
*/ */
List<String> getPlayerList(); List<String> getPlayerList();
/**
* Gets the UUIDs of the users online on the platform
* @return a {@link Set} of UUIDs
*/
Set<UUID> getOnlinePlayers();
/**
* Checks if a user is online
* @param external the users external uuid
* @return true if the user is online
*/
boolean isOnline(UUID external);
/** /**
* @return a {@link List} of senders online on the platform * @return a {@link List} of senders online on the platform
*/ */
@ -117,7 +133,11 @@ public interface LuckPermsPlugin {
*/ */
Sender getConsoleSender(); Sender getConsoleSender();
// TODO javadoc /**
* Gets a set of Contexts that should be pre-processed in advance
* @param op if the user being processed is op
* @return a set of contexts
*/
Set<Contexts> getPreProcessContexts(boolean op); Set<Contexts> getPreProcessContexts(boolean op);
/** /**

View File

@ -27,9 +27,11 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import me.lucko.luckperms.api.event.events.GroupAddEvent; import me.lucko.luckperms.api.event.events.GroupAddEvent;
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.api.internal.GroupLink; import me.lucko.luckperms.common.api.internal.GroupLink;
import me.lucko.luckperms.common.api.internal.PermissionHolderLink; import me.lucko.luckperms.common.api.internal.PermissionHolderLink;
import me.lucko.luckperms.common.api.internal.UserLink;
import me.lucko.luckperms.common.caching.UserData; import me.lucko.luckperms.common.caching.UserData;
import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.groups.Group;
@ -109,7 +111,6 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
userData.invalidateCache(); userData.invalidateCache();
userData = null; userData = null;
} }
// TODO
} }
/** /**
@ -124,7 +125,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
UserData ud = userData; UserData ud = userData;
ud.recalculatePermissions(); ud.recalculatePermissions();
ud.recalculateMeta(); ud.recalculateMeta();
// TODO api call? getPlugin().getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
} }
/** /**

View File

@ -30,6 +30,7 @@ import me.lucko.luckperms.common.utils.AbstractManager;
import me.lucko.luckperms.common.utils.Identifiable; import me.lucko.luckperms.common.utils.Identifiable;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
@RequiredArgsConstructor @RequiredArgsConstructor
@ -120,14 +121,23 @@ public class UserManager extends AbstractManager<UserIdentifier, User> {
* @param user The user to be cleaned up * @param user The user to be cleaned up
*/ */
public void cleanup(User user) { public void cleanup(User user) {
// TODO if (!plugin.isOnline(plugin.getUuidCache().getExternalUUID(user.getUuid()))) {
unload(user);
}
} }
/** /**
* Reloads the data of all online users * Reloads the data of all online users
*/ */
public void updateAllUsers() { public void updateAllUsers() {
// TODO plugin.doSync(() -> {
Set<UUID> players = plugin.getOnlinePlayers();
plugin.doAsync(() -> {
for (UUID uuid : players) {
plugin.getDatastore().loadUser(plugin.getUuidCache().getUUID(uuid), "null");
}
});
});
} }
@Override @Override

View File

@ -65,6 +65,7 @@ import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.scheduler.Scheduler; import org.spongepowered.api.scheduler.Scheduler;
import org.spongepowered.api.service.permission.PermissionDescription; import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
import java.io.File; import java.io.File;
@ -103,7 +104,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
private ConsecutiveExecutor consecutiveExecutor; private ConsecutiveExecutor consecutiveExecutor;
private LuckPermsService service; private LuckPermsService service;
private LocaleManager localeManager; private LocaleManager localeManager;
private ContextManager<Player> contextManager; // TODO convert this to use Subject instead of Player private ContextManager<Subject> contextManager;
private CalculatorFactory calculatorFactory; private CalculatorFactory calculatorFactory;
@Listener @Listener
@ -146,7 +147,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
contextManager = new ContextManager<>(); contextManager = new ContextManager<>();
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer())); contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
contextManager.registerCalculator(new WorldCalculator()); contextManager.registerCalculator(new WorldCalculator(this));
getLog().info("Registering PermissionService..."); getLog().info("Registering PermissionService...");
Sponge.getServiceManager().setProvider(this, PermissionService.class, (service = new LuckPermsService(this))); Sponge.getServiceManager().setProvider(this, PermissionService.class, (service = new LuckPermsService(this)));
@ -227,11 +228,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
return PlatformType.SPONGE; return PlatformType.SPONGE;
} }
@Override
public Message getPlayerStatus(UUID uuid) {
return game.getServer().getPlayer(getUuidCache().getExternalUUID(uuid)).isPresent() ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
}
@Override @Override
public int getPlayerCount() { public int getPlayerCount() {
return game.getServer().getOnlinePlayers().size(); return game.getServer().getOnlinePlayers().size();
@ -242,6 +238,16 @@ public class LPSpongePlugin implements LuckPermsPlugin {
return game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); return game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
} }
@Override
public Set<UUID> getOnlinePlayers() {
return game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet());
}
@Override
public boolean isOnline(UUID external) {
return game.getServer().getPlayer(external).isPresent();
}
@Override @Override
public List<Sender> getNotifyListeners() { public List<Sender> getNotifyListeners() {
return game.getServer().getOnlinePlayers().stream() return game.getServer().getOnlinePlayers().stream()

View File

@ -24,7 +24,6 @@ package me.lucko.luckperms.sponge.contexts;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.ContextCalculator;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.Subject;
@ -33,11 +32,11 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
public class SpongeCalculatorLink extends ContextCalculator<Player> { public class SpongeCalculatorLink extends ContextCalculator<Subject> {
private final org.spongepowered.api.service.context.ContextCalculator<Subject> calculator; private final org.spongepowered.api.service.context.ContextCalculator<Subject> calculator;
@Override @Override
public Map<String, String> giveApplicableContext(Player subject, Map<String, String> accumulator) { public Map<String, String> giveApplicableContext(Subject subject, Map<String, String> accumulator) {
Set<Context> contexts = accumulator.entrySet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(Collectors.toSet()); Set<Context> contexts = accumulator.entrySet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(Collectors.toSet());
calculator.accumulateContexts(subject, contexts); calculator.accumulateContexts(subject, contexts);
@ -46,7 +45,7 @@ public class SpongeCalculatorLink extends ContextCalculator<Player> {
} }
@Override @Override
public boolean isContextApplicable(Player subject, Map.Entry<String, String> context) { public boolean isContextApplicable(Subject subject, Map.Entry<String, String> context) {
Context c = new Context(context.getKey(), context.getValue()); Context c = new Context(context.getKey(), context.getValue());
return calculator.matches(c, subject); return calculator.matches(c, subject);
} }

View File

@ -24,23 +24,49 @@ package me.lucko.luckperms.sponge.contexts;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WorldCalculator extends ContextCalculator<Player> { public class WorldCalculator extends ContextCalculator<Subject> {
private final LPSpongePlugin plugin;
@Override @Override
public Map<String, String> giveApplicableContext(Player subject, Map<String, String> accumulator) { public Map<String, String> giveApplicableContext(Subject subject, Map<String, String> accumulator) {
accumulator.put(Context.WORLD_KEY, subject.getWorld().getName()); UUID uuid = Util.parseUuid(subject.getIdentifier());
if (uuid == null) {
return accumulator;
}
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(uuid));
if (!p.isPresent()) {
return accumulator;
}
accumulator.put(Context.WORLD_KEY, p.get().getWorld().getName());
return accumulator; return accumulator;
} }
@Override @Override
public boolean isContextApplicable(Player subject, Map.Entry<String, String> context) { public boolean isContextApplicable(Subject subject, Map.Entry<String, String> context) {
return context.getKey().equals(Context.WORLD_KEY) && subject.getWorld().getName().equals(context.getValue()); UUID uuid = Util.parseUuid(subject.getIdentifier());
if (uuid == null) {
return false;
}
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(uuid));
if (!p.isPresent()) {
return false;
}
return context.getKey().equals(Context.WORLD_KEY) && p.get().getWorld().getName().equals(context.getValue());
} }
} }

View File

@ -172,15 +172,8 @@ public class LuckPermsUserSubject implements Subject {
@Override @Override
public Set<Context> getActiveContexts() { public Set<Context> getActiveContexts() {
final UUID uuid = service.getPlugin().getUuidCache().getExternalUUID(user.getUuid()); return service.getPlugin().getContextManager().giveApplicableContext(this, new HashMap<>()).entrySet().stream()
Optional<Player> player = Sponge.getServer().getPlayer(uuid); .map(e -> new Context(e.getKey(), e.getValue()))
.collect(Collectors.toSet());
if (!player.isPresent()) {
return SubjectData.GLOBAL_CONTEXT;
}
Map<String, String> context = new HashMap<>();
service.getPlugin().getContextManager().giveApplicableContext(player.get(), context);
return context.entrySet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(Collectors.toSet());
} }
} }