Fix compile errors

This commit is contained in:
Luck 2020-01-17 10:05:19 +00:00
parent a050a2604f
commit 7e8402b542
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 38 additions and 45 deletions

View File

@ -74,7 +74,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
@Override
public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, @NonNull String[] args) {
Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
List<String> arguments = processSelectors(sender, ArgumentTokenizer.EXECUTE.tokenizeInput(args));
List<String> arguments = resolveSelectors(sender, ArgumentTokenizer.EXECUTE.tokenizeInput(args));
executeCommand(wrapped, label, arguments);
return true;
}
@ -82,11 +82,11 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
@Override
public List<String> onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, @NonNull String[] args) {
Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
List<String> arguments = processSelectors(sender, ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args));
List<String> arguments = resolveSelectors(sender, ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args));
return tabCompleteCommand(wrapped, arguments);
}
private List<String> processSelectors(CommandSender sender, List<String> args) {
private List<String> resolveSelectors(CommandSender sender, List<String> args) {
if (!SELECT_ENTITIES_SUPPORTED) {
return args;
}
@ -95,8 +95,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
return args;
}
ListIterator<String> it = args.listIterator();
while (it.hasNext()) {
for (ListIterator<String> it = args.listIterator(); it.hasNext(); ) {
String arg = it.next();
if (arg.isEmpty() || arg.charAt(0) != '@') {
continue;
@ -127,6 +126,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
Player player = matchedPlayers.get(0);
it.set(player.getUniqueId().toString());
}
return args;
}
}

View File

@ -148,12 +148,12 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
}
if (isAsyncTabCompleteSupported()) {
this.commandManager = new BukkitAsyncCommandExecutor(this);
this.commandManager = new BukkitAsyncCommandExecutor(this, command);
} else {
this.commandManager = new BukkitCommandExecutor(this);
this.commandManager = new BukkitCommandExecutor(this, command);
}
this.commandManager.register(command);
this.commandManager.register();
// setup brigadier
if (isBrigadierSupported()) {

View File

@ -149,7 +149,8 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio
protected RuntimeException reportException(String file, Exception ex) throws RuntimeException {
this.plugin.getLogger().warn("Exception thrown whilst performing i/o: " + file);
ex.printStackTrace();
throw Throwables.propagate(ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
@Override

View File

@ -38,6 +38,7 @@ import me.lucko.luckperms.common.util.MoreFiles;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
import org.spongepowered.api.Server;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.entity.living.player.Player;
@ -203,6 +204,10 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
return this.game;
}
public Optional<Server> getServer() {
return this.game.isServerAvailable() ? Optional.of(this.game.getServer()) : Optional.empty();
}
public Scheduler getSpongeScheduler() {
return this.spongeScheduler;
}
@ -232,13 +237,13 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
@Override
public String getServerBrand() {
return getGame().getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName();
return this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName();
}
@Override
public String getServerVersion() {
PluginContainer api = getGame().getPlatform().getContainer(Platform.Component.API);
PluginContainer impl = getGame().getPlatform().getContainer(Platform.Component.IMPLEMENTATION);
PluginContainer api = this.game.getPlatform().getContainer(Platform.Component.API);
PluginContainer impl = this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION);
return api.getName() + ": " + api.getVersion().orElse("null") + " - " + impl.getName() + ": " + impl.getVersion().orElse("null");
}
@ -265,55 +270,45 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
@Override
public Optional<Player> getPlayer(UUID uniqueId) {
if (!getGame().isServerAvailable()) {
return Optional.empty();
}
return getGame().getServer().getPlayer(uniqueId);
return getServer().flatMap(s -> s.getPlayer(uniqueId));
}
@Override
public Optional<UUID> lookupUniqueId(String username) {
if (!getGame().isServerAvailable()) {
return Optional.empty();
}
return getGame().getServer().getGameProfileManager().get(username)
return getServer().flatMap(server -> server.getGameProfileManager().get(username)
.thenApply(p -> Optional.of(p.getUniqueId()))
.exceptionally(x -> Optional.empty())
.join();
.join()
);
}
@Override
public Optional<String> lookupUsername(UUID uniqueId) {
if (!getGame().isServerAvailable()) {
return Optional.empty();
}
return getGame().getServer().getGameProfileManager().get(uniqueId)
return getServer().flatMap(server -> server.getGameProfileManager().get(uniqueId)
.thenApply(GameProfile::getName)
.exceptionally(x -> Optional.empty())
.join();
.join()
);
}
@Override
public int getPlayerCount() {
return getGame().isServerAvailable() ? getGame().getServer().getOnlinePlayers().size() : 0;
return getServer().map(server -> server.getOnlinePlayers().size()).orElse(0);
}
@Override
public Stream<String> getPlayerList() {
return getGame().isServerAvailable() ? getGame().getServer().getOnlinePlayers().stream().map(Player::getName) : Stream.empty();
return getServer().map(server -> server.getOnlinePlayers().stream().map(Player::getName)).orElseGet(Stream::empty);
}
@Override
public Stream<UUID> getOnlinePlayers() {
return getGame().isServerAvailable() ? getGame().getServer().getOnlinePlayers().stream().map(Player::getUniqueId) : Stream.empty();
return getServer().map(server -> server.getOnlinePlayers().stream().map(Player::getUniqueId)).orElseGet(Stream::empty);
}
@Override
public boolean isPlayerOnline(UUID uniqueId) {
return getGame().isServerAvailable() ? getGame().getServer().getPlayer(uniqueId).map(Player::isOnline).orElse(false) : false;
return getServer().flatMap(server -> server.getPlayer(uniqueId).map(Player::isOnline)).orElse(false);
}
}

View File

@ -256,19 +256,17 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
@Override
public Stream<Sender> getOnlineSenders() {
if (!this.bootstrap.getGame().isServerAvailable()) {
return Stream.empty();
}
return Stream.concat(
Stream.of(getConsoleSender()),
this.bootstrap.getGame().getServer().getOnlinePlayers().stream().map(s -> this.senderFactory.wrap(s))
this.bootstrap.getServer().map(server -> server.getOnlinePlayers().stream().map(s -> this.senderFactory.wrap(s))).orElseGet(Stream::empty)
);
}
@Override
public Sender getConsoleSender() {
if (!this.bootstrap.getGame().isServerAvailable()) {
if (this.bootstrap.getGame().isServerAvailable()) {
return this.senderFactory.wrap(this.bootstrap.getGame().getServer().getConsole());
} else {
return new DummySender(this, Sender.CONSOLE_UUID, Sender.CONSOLE_NAME) {
@Override
protected void consumeMessage(String s) {
@ -276,7 +274,6 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
}
};
}
return this.senderFactory.wrap(this.bootstrap.getGame().getServer().getConsole());
}
@Override

View File

@ -57,7 +57,7 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall
@Override
public @NonNull CommandResult process(@NonNull CommandSource source, @NonNull String args) {
Sender wrapped = this.plugin.getSenderFactory().wrap(source);
List<String> arguments = processSelectors(source, ArgumentTokenizer.EXECUTE.tokenizeInput(args));
List<String> arguments = resolveSelectors(source, ArgumentTokenizer.EXECUTE.tokenizeInput(args));
executeCommand(wrapped, "lp", arguments);
return CommandResult.success();
}
@ -65,7 +65,7 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall
@Override
public @NonNull List<String> getSuggestions(@NonNull CommandSource source, @NonNull String args, @Nullable Location<World> location) {
Sender wrapped = this.plugin.getSenderFactory().wrap(source);
List<String> arguments = processSelectors(source, ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args));
List<String> arguments = resolveSelectors(source, ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args));
return tabCompleteCommand(wrapped, arguments);
}
@ -89,13 +89,12 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall
return Text.of("/luckperms");
}
private List<String> processSelectors(CommandSource source, List<String> args) {
private List<String> resolveSelectors(CommandSource source, List<String> args) {
if (!this.plugin.getConfiguration().get(ConfigKeys.RESOLVE_COMMAND_SELECTORS)) {
return args;
}
ListIterator<String> it = args.listIterator();
while (it.hasNext()) {
for (ListIterator<String> it = args.listIterator(); it.hasNext(); ) {
String arg = it.next();
if (arg.isEmpty() || arg.charAt(0) != '@') {
continue;
@ -126,6 +125,7 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall
Player player = matchedPlayers.get(0);
it.set(player.getUniqueId().toString());
}
return args;
}