mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-10-31 07:51:05 +01:00
Fail silently when the Sponge Server is not available - closes #367
This commit is contained in:
parent
fce5b8430d
commit
1bb1f5ebb3
@ -32,26 +32,19 @@ import lombok.Setter;
|
|||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
|
||||||
import me.lucko.luckperms.common.commands.CommandManager;
|
import me.lucko.luckperms.common.commands.CommandManager;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.utils.DateUtil;
|
import me.lucko.luckperms.common.utils.DateUtil;
|
||||||
|
import me.lucko.luckperms.common.utils.FakeSender;
|
||||||
import net.kyori.text.Component;
|
|
||||||
import net.kyori.text.serializer.ComponentSerializer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -89,7 +82,7 @@ public class Importer implements Runnable {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
this.cmdResult = new HashMap<>();
|
this.cmdResult = new HashMap<>();
|
||||||
this.fake = new FakeSender();
|
this.fake = new FakeSender(commandManager.getPlugin(), this::logMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -182,59 +175,6 @@ public class Importer implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FakeSender implements Sender {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LuckPermsPlugin getPlatform() {
|
|
||||||
return commandManager.getPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return Constants.IMPORT_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getUuid() {
|
|
||||||
return Constants.IMPORT_UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String s) {
|
|
||||||
logMessage(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(Component message) {
|
|
||||||
logMessage(ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tristate getPermissionValue(String permission) {
|
|
||||||
return Tristate.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Permission permission) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConsole() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isImport() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private static class Result {
|
private static class Result {
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.utils;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FakeSender implements Sender {
|
||||||
|
private final LuckPermsPlugin plugin;
|
||||||
|
private final Consumer<String> messageConsumer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LuckPermsPlugin getPlatform() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return Constants.IMPORT_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUuid() {
|
||||||
|
return Constants.IMPORT_UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(String s) {
|
||||||
|
messageConsumer.accept(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(Component message) {
|
||||||
|
messageConsumer.accept(ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tristate getPermissionValue(String permission) {
|
||||||
|
return Tristate.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String permission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(Permission permission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConsole() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isImport() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -64,6 +64,7 @@ import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
|||||||
import me.lucko.luckperms.common.tasks.UpdateTask;
|
import me.lucko.luckperms.common.tasks.UpdateTask;
|
||||||
import me.lucko.luckperms.common.treeview.PermissionVault;
|
import me.lucko.luckperms.common.treeview.PermissionVault;
|
||||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||||
|
import me.lucko.luckperms.common.utils.FakeSender;
|
||||||
import me.lucko.luckperms.common.utils.FileWatcher;
|
import me.lucko.luckperms.common.utils.FileWatcher;
|
||||||
import me.lucko.luckperms.common.utils.SenderLogger;
|
import me.lucko.luckperms.common.utils.SenderLogger;
|
||||||
import me.lucko.luckperms.common.verbose.VerboseHandler;
|
import me.lucko.luckperms.common.verbose.VerboseHandler;
|
||||||
@ -107,7 +108,9 @@ import java.io.File;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.AbstractCollection;
|
import java.util.AbstractCollection;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -392,11 +395,19 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer(User user) {
|
public Player getPlayer(User user) {
|
||||||
|
if (!game.isServerAvailable()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return game.getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid())).orElse(null);
|
return game.getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid())).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UUID> lookupUuid(String username) {
|
public Optional<UUID> lookupUuid(String username) {
|
||||||
|
if (!game.isServerAvailable()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
CompletableFuture<GameProfile> fut = game.getServer().getGameProfileManager().get(username);
|
CompletableFuture<GameProfile> fut = game.getServer().getGameProfileManager().get(username);
|
||||||
try {
|
try {
|
||||||
return Optional.of(fut.get().getUniqueId());
|
return Optional.of(fut.get().getUniqueId());
|
||||||
@ -448,26 +459,30 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerCount() {
|
public int getPlayerCount() {
|
||||||
return game.getServer().getOnlinePlayers().size();
|
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getPlayerList() {
|
public List<String> getPlayerList() {
|
||||||
return game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()) : new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> getOnlinePlayers() {
|
public Set<UUID> getOnlinePlayers() {
|
||||||
return game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet());
|
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet()) : new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayerOnline(UUID external) {
|
public boolean isPlayerOnline(UUID external) {
|
||||||
return game.getServer().getPlayer(external).map(Player::isOnline).orElse(false);
|
return game.isServerAvailable() ? game.getServer().getPlayer(external).map(Player::isOnline).orElse(false) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Sender> getOnlineSenders() {
|
public List<Sender> getOnlineSenders() {
|
||||||
|
if (!game.isServerAvailable()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
return game.getServer().getOnlinePlayers().stream()
|
return game.getServer().getOnlinePlayers().stream()
|
||||||
.map(s -> getSenderFactory().wrap(s))
|
.map(s -> getSenderFactory().wrap(s))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -475,6 +490,9 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sender getConsoleSender() {
|
public Sender getConsoleSender() {
|
||||||
|
if (!game.isServerAvailable()) {
|
||||||
|
return new FakeSender(this, s -> logger.info(s));
|
||||||
|
}
|
||||||
return getSenderFactory().wrap(game.getServer().getConsole());
|
return getSenderFactory().wrap(game.getServer().getConsole());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,9 +159,9 @@ public class SpongeListener {
|
|||||||
if (p.isPresent()) {
|
if (p.isPresent()) {
|
||||||
MutableContextSet context = MutableContextSet.fromSet(plugin.getContextManager().getApplicableContext(p.get()));
|
MutableContextSet context = MutableContextSet.fromSet(plugin.getContextManager().getApplicableContext(p.get()));
|
||||||
|
|
||||||
List<String> worlds = plugin.getGame().getServer().getWorlds().stream()
|
List<String> worlds = plugin.getGame().isServerAvailable() ? plugin.getGame().getServer().getWorlds().stream()
|
||||||
.map(World::getName)
|
.map(World::getName)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()) : Collections.emptyList();
|
||||||
|
|
||||||
plugin.doAsync(() -> {
|
plugin.doAsync(() -> {
|
||||||
UserData data = user.getUserData();
|
UserData data = user.getUserData();
|
||||||
|
@ -67,6 +67,10 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
|||||||
@Override
|
@Override
|
||||||
protected void sendMessage(String channel, String message) {
|
protected void sendMessage(String channel, String message) {
|
||||||
plugin.getSpongeScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(task -> {
|
plugin.getSpongeScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(task -> {
|
||||||
|
if (!plugin.getGame().isServerAvailable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Collection<Player> players = plugin.getGame().getServer().getOnlinePlayers();
|
Collection<Player> players = plugin.getGame().getServer().getOnlinePlayers();
|
||||||
Player p = Iterables.getFirst(players, null);
|
Player p = Iterables.getFirst(players, null);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user