1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Register permissions on Spigot. Profile ID can be null. Fixed submodule

This commit is contained in:
Tim203
2022-02-06 02:10:17 +01:00
parent 141643f381
commit 039b398dad
13 changed files with 63 additions and 33 deletions

4
.gitmodules vendored
View File

@@ -0,0 +1,4 @@
[submodule "core/src/main/resources/languages"]
path = core/src/main/resources/languages
url = https://github.com/GeyserMC/languages
branch = l10n_floodgate

View File

@@ -51,7 +51,7 @@ public class PropertyKey {
this.removable = removable;
}
public Result isAddAllowed(Object obj) { //todo use for add and remove
public Result isAddAllowed(Object obj) {
if (obj instanceof PropertyKey) {
PropertyKey propertyKey = (PropertyKey) obj;

View File

@@ -100,7 +100,7 @@ public class FloodgatePlatform {
InstanceHolder.set(api, link, this.injector, packetHandlers, handshakeHandlers, KEY);
// todo provide build number and branch for Geyser dump
// todo this was the place where we provided the build number and branch for Geyser dump
guice.getInstance(NewsChecker.class).start();
}

View File

@@ -48,7 +48,7 @@ import org.geysermc.floodgate.player.UserAudience;
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
import org.geysermc.floodgate.player.UserAudienceArgument;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.Permissions;
import org.geysermc.floodgate.command.util.Permission;
@NoArgsConstructor
public final class LinkAccountCommand implements FloodgateCommand {
@@ -60,7 +60,7 @@ public final class LinkAccountCommand implements FloodgateCommand {
return commandManager.commandBuilder("linkaccount",
ArgumentDescription.of("Link your Java account with your Bedrock account"))
.senderType(PlayerAudience.class)
.permission(Permissions.COMMAND_LINK.get())
.permission(Permission.COMMAND_LINK.get())
.argument(UserAudienceArgument.of("player", true))
.argument(StringArgument.optional("code"))
.handler(this::execute)

View File

@@ -43,7 +43,7 @@ import org.geysermc.floodgate.platform.command.TranslatableMessage;
import org.geysermc.floodgate.player.UserAudience;
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.Permissions;
import org.geysermc.floodgate.command.util.Permission;
@NoArgsConstructor
public final class UnlinkAccountCommand implements FloodgateCommand {
@@ -54,7 +54,7 @@ public final class UnlinkAccountCommand implements FloodgateCommand {
return commandManager.commandBuilder("unlinkaccount",
ArgumentDescription.of("Unlink your Java account from your Bedrock account"))
.senderType(PlayerAudience.class)
.permission(Permissions.COMMAND_UNLINK.get())
.permission(Permission.COMMAND_UNLINK.get())
.handler(this::execute)
.build();
}

View File

@@ -48,7 +48,7 @@ import org.geysermc.floodgate.player.UserAudienceArgument;
import org.geysermc.floodgate.player.UserAudienceArgument.PlayerType;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.HttpUtils;
import org.geysermc.floodgate.util.Permissions;
import org.geysermc.floodgate.command.util.Permission;
public class WhitelistCommand implements FloodgateCommand {
@Inject private FloodgateConfig config;
@@ -58,7 +58,7 @@ public class WhitelistCommand implements FloodgateCommand {
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
Command.Builder<UserAudience> builder = commandManager.commandBuilder("fwhitelist",
ArgumentDescription.of("Easy way to whitelist Bedrock players"))
.permission(Permissions.COMMAND_WHITELIST.get());
.permission(Permission.COMMAND_WHITELIST.get());
commandManager.command(builder
.literal("add", "a")

View File

@@ -35,9 +35,9 @@ import cloud.commandframework.context.CommandContext;
import java.util.Locale;
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import org.geysermc.floodgate.command.util.Permission;
import org.geysermc.floodgate.platform.command.FloodgateCommand;
import org.geysermc.floodgate.player.UserAudience;
import org.geysermc.floodgate.util.Permissions;
public final class MainCommand implements FloodgateCommand {
@Override
@@ -46,12 +46,13 @@ public final class MainCommand implements FloodgateCommand {
"floodgate",
ArgumentDescription.of("A set of Floodgate related actions in one command"))
.senderType(UserAudience.class)
.permission(Permissions.COMMAND_MAIN.get())
.permission(Permission.COMMAND_MAIN.get())
.handler(this::execute);
for (SubCommand subCommand : SubCommand.VALUES) {
commandManager.command(builder
.literal(subCommand.name().toLowerCase(Locale.ROOT), subCommand.description)
.permission(subCommand.permission.get())
.handler(subCommand.executor::accept)
);
}
@@ -65,11 +66,13 @@ public final class MainCommand implements FloodgateCommand {
StringBuilder helpMessage = new StringBuilder("Available subcommands are:\n");
for (SubCommand subCommand : SubCommand.VALUES) {
if (context.getSender().hasPermission(subCommand.permission.get())) {
helpMessage.append('\n').append(COLOR_CHAR).append('b')
.append(subCommand.name().toLowerCase(Locale.ROOT))
.append(COLOR_CHAR).append("f - ").append(COLOR_CHAR).append('7')
.append(subCommand.description);
}
}
context.getSender().sendMessage(helpMessage.toString());
}
@@ -77,11 +80,12 @@ public final class MainCommand implements FloodgateCommand {
@RequiredArgsConstructor
enum SubCommand {
FIREWALL("Check if your outgoing firewall allows Floodgate to work properly",
FirewallCheckSubcommand::executeFirewall);
Permission.COMMAND_MAIN_FIREWALL, FirewallCheckSubcommand::executeFirewall);
static final SubCommand[] VALUES = values();
final String description;
final Permission permission;
final Consumer<CommandContext<UserAudience>> executor;
}
}

View File

@@ -72,7 +72,7 @@ public final class ConfigUpdater {
"config now and we'll also generate a new Floodgate key for you, but if " +
"you're running a network or if you're running a Spigot server with " +
"Geyser Standalone please update as you'll no longer be able to connect.");
renames.put("enabled", "enable"); //todo make dump system and add a boolean 'found-legacy-key' or something like that
renames.put("enabled", "enable");
renames.put("allowed", "allow-linking");
// relocate the old key so that they can restore it if it was a new key

View File

@@ -43,7 +43,7 @@ import org.geysermc.floodgate.platform.command.CommandUtil;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.HttpUtils;
import org.geysermc.floodgate.util.HttpUtils.HttpResponse;
import org.geysermc.floodgate.util.Permissions;
import org.geysermc.floodgate.command.util.Permission;
public class NewsChecker {
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
@@ -72,8 +72,6 @@ public class NewsChecker {
}
private void checkNews() {
// todo also check news for the downloaded database types
HttpResponse<JsonArray> response =
HttpUtils.getSilent(
Constants.NEWS_OVERVIEW_URL + Constants.NEWS_PROJECT_NAME,
@@ -121,14 +119,14 @@ public class NewsChecker {
return;
}
if (commandUtil.hasPermission(player, Permissions.NEWS_RECEIVE.get())) {
if (commandUtil.hasPermission(player, Permission.NEWS_RECEIVE.get())) {
String message = Constants.COLOR_CHAR + "a " + news.getMessage();
commandUtil.sendMessage(player, message);
}
break;
case BROADCAST_TO_OPERATORS:
Collection<Object> onlinePlayers = commandUtil.getOnlinePlayersWithPermission(
Permissions.NEWS_RECEIVE.get()
Permission.NEWS_RECEIVE.get()
);
for (Object onlinePlayer : onlinePlayers) {
@@ -182,7 +180,8 @@ public class NewsChecker {
schedule(delayMs > 0 ? delayMs : 0);
break;
case CONFIG_SPECIFIC:
//todo
//todo this can replace the downloaded database types update check.
// check if ConfigUtils has a way to check this easily
break;
}
activeNewsItems.put(item.getId(), item);

View File

@@ -63,19 +63,16 @@ public final class SpigotPlugin extends JavaPlugin {
@Override
public void onEnable() {
boolean usePaperListener = ReflectionUtils.getClassSilently(
"com.destroystokyo.paper.event.profile.PreFillProfileEvent") != null;
platform.enable(
new SpigotCommandModule(this),
new SpigotAddonModule(),
new PluginMessageModule()
new PluginMessageModule(),
(usePaperListener ? new PaperListenerModule() : new SpigotListenerModule())
);
if (ReflectionUtils.getClassSilently(
"com.destroystokyo.paper.event.profile.PreFillProfileEvent") != null) {
platform.enable(new PaperListenerModule());
} else {
platform.enable(new SpigotListenerModule());
}
//todo add proper support for disabling things on shutdown and enabling this on enable
injector.getInstance(HandshakeHandlers.class)
.addHandshakeHandler(injector.getInstance(SpigotHandshakeHandler.class));

View File

@@ -41,7 +41,9 @@ public final class PaperProfileListener implements Listener {
@EventHandler
public void onFill(PreFillProfileEvent event) {
UUID id = event.getPlayerProfile().getId();
if (!this.api.isFloodgatePlayer(id) ||
// back when this event got added the PlayerProfile class didn't have the
// hasProperty / hasTextures methods
if (id == null || !this.api.isFloodgatePlayer(id) ||
event.getPlayerProfile().getProperties().stream().anyMatch(
prop -> "textures".equals(prop.getName()))) {
return;

View File

@@ -32,8 +32,12 @@ import com.google.inject.Provides;
import com.google.inject.Singleton;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import org.geysermc.floodgate.SpigotPlugin;
import org.geysermc.floodgate.command.util.Permission;
import org.geysermc.floodgate.platform.command.CommandUtil;
import org.geysermc.floodgate.player.FloodgateCommandPreprocessor;
import org.geysermc.floodgate.player.UserAudience;
@@ -42,6 +46,12 @@ import org.geysermc.floodgate.player.UserAudience;
public final class SpigotCommandModule extends CommandModule {
private final SpigotPlugin plugin;
@Override
protected void configure() {
super.configure();
registerPermissions();
}
@Provides
@Singleton
@SneakyThrows
@@ -55,4 +65,20 @@ public final class SpigotCommandModule extends CommandModule {
commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
return commandManager;
}
private void registerPermissions() {
PluginManager manager = Bukkit.getPluginManager();
for (Permission permission : Permission.values()) {
if (manager.getPermission(permission.get()) != null) {
continue;
}
PermissionDefault defaultValue =
PermissionDefault.getByName(permission.defaultValue().name());
manager.addPermission(new org.bukkit.permissions.Permission(
permission.get(), defaultValue
));
}
}
}

View File

@@ -43,8 +43,6 @@ public class SpigotPluginMessageRegistration implements PluginMessageRegistratio
(channel1, player, message) ->
channel.handleServerCall(message, player.getUniqueId(), player.getName()));
//todo actually do something with the result, lol
messenger.registerOutgoingPluginChannel(plugin, channel.getIdentifier());
}
}