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:
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -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
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class PropertyKey {
|
|||||||
this.removable = removable;
|
this.removable = removable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result isAddAllowed(Object obj) { //todo use for add and remove
|
public Result isAddAllowed(Object obj) {
|
||||||
if (obj instanceof PropertyKey) {
|
if (obj instanceof PropertyKey) {
|
||||||
PropertyKey propertyKey = (PropertyKey) obj;
|
PropertyKey propertyKey = (PropertyKey) obj;
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class FloodgatePlatform {
|
|||||||
|
|
||||||
InstanceHolder.set(api, link, this.injector, packetHandlers, handshakeHandlers, KEY);
|
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();
|
guice.getInstance(NewsChecker.class).start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import org.geysermc.floodgate.player.UserAudience;
|
|||||||
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
|
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
|
||||||
import org.geysermc.floodgate.player.UserAudienceArgument;
|
import org.geysermc.floodgate.player.UserAudienceArgument;
|
||||||
import org.geysermc.floodgate.util.Constants;
|
import org.geysermc.floodgate.util.Constants;
|
||||||
import org.geysermc.floodgate.util.Permissions;
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public final class LinkAccountCommand implements FloodgateCommand {
|
public final class LinkAccountCommand implements FloodgateCommand {
|
||||||
@@ -60,7 +60,7 @@ public final class LinkAccountCommand implements FloodgateCommand {
|
|||||||
return commandManager.commandBuilder("linkaccount",
|
return commandManager.commandBuilder("linkaccount",
|
||||||
ArgumentDescription.of("Link your Java account with your Bedrock account"))
|
ArgumentDescription.of("Link your Java account with your Bedrock account"))
|
||||||
.senderType(PlayerAudience.class)
|
.senderType(PlayerAudience.class)
|
||||||
.permission(Permissions.COMMAND_LINK.get())
|
.permission(Permission.COMMAND_LINK.get())
|
||||||
.argument(UserAudienceArgument.of("player", true))
|
.argument(UserAudienceArgument.of("player", true))
|
||||||
.argument(StringArgument.optional("code"))
|
.argument(StringArgument.optional("code"))
|
||||||
.handler(this::execute)
|
.handler(this::execute)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import org.geysermc.floodgate.platform.command.TranslatableMessage;
|
|||||||
import org.geysermc.floodgate.player.UserAudience;
|
import org.geysermc.floodgate.player.UserAudience;
|
||||||
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
|
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
|
||||||
import org.geysermc.floodgate.util.Constants;
|
import org.geysermc.floodgate.util.Constants;
|
||||||
import org.geysermc.floodgate.util.Permissions;
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public final class UnlinkAccountCommand implements FloodgateCommand {
|
public final class UnlinkAccountCommand implements FloodgateCommand {
|
||||||
@@ -54,7 +54,7 @@ public final class UnlinkAccountCommand implements FloodgateCommand {
|
|||||||
return commandManager.commandBuilder("unlinkaccount",
|
return commandManager.commandBuilder("unlinkaccount",
|
||||||
ArgumentDescription.of("Unlink your Java account from your Bedrock account"))
|
ArgumentDescription.of("Unlink your Java account from your Bedrock account"))
|
||||||
.senderType(PlayerAudience.class)
|
.senderType(PlayerAudience.class)
|
||||||
.permission(Permissions.COMMAND_UNLINK.get())
|
.permission(Permission.COMMAND_UNLINK.get())
|
||||||
.handler(this::execute)
|
.handler(this::execute)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import org.geysermc.floodgate.player.UserAudienceArgument;
|
|||||||
import org.geysermc.floodgate.player.UserAudienceArgument.PlayerType;
|
import org.geysermc.floodgate.player.UserAudienceArgument.PlayerType;
|
||||||
import org.geysermc.floodgate.util.Constants;
|
import org.geysermc.floodgate.util.Constants;
|
||||||
import org.geysermc.floodgate.util.HttpUtils;
|
import org.geysermc.floodgate.util.HttpUtils;
|
||||||
import org.geysermc.floodgate.util.Permissions;
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
|
|
||||||
public class WhitelistCommand implements FloodgateCommand {
|
public class WhitelistCommand implements FloodgateCommand {
|
||||||
@Inject private FloodgateConfig config;
|
@Inject private FloodgateConfig config;
|
||||||
@@ -58,7 +58,7 @@ public class WhitelistCommand implements FloodgateCommand {
|
|||||||
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
||||||
Command.Builder<UserAudience> builder = commandManager.commandBuilder("fwhitelist",
|
Command.Builder<UserAudience> builder = commandManager.commandBuilder("fwhitelist",
|
||||||
ArgumentDescription.of("Easy way to whitelist Bedrock players"))
|
ArgumentDescription.of("Easy way to whitelist Bedrock players"))
|
||||||
.permission(Permissions.COMMAND_WHITELIST.get());
|
.permission(Permission.COMMAND_WHITELIST.get());
|
||||||
|
|
||||||
commandManager.command(builder
|
commandManager.command(builder
|
||||||
.literal("add", "a")
|
.literal("add", "a")
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ import cloud.commandframework.context.CommandContext;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
||||||
import org.geysermc.floodgate.player.UserAudience;
|
import org.geysermc.floodgate.player.UserAudience;
|
||||||
import org.geysermc.floodgate.util.Permissions;
|
|
||||||
|
|
||||||
public final class MainCommand implements FloodgateCommand {
|
public final class MainCommand implements FloodgateCommand {
|
||||||
@Override
|
@Override
|
||||||
@@ -46,12 +46,13 @@ public final class MainCommand implements FloodgateCommand {
|
|||||||
"floodgate",
|
"floodgate",
|
||||||
ArgumentDescription.of("A set of Floodgate related actions in one command"))
|
ArgumentDescription.of("A set of Floodgate related actions in one command"))
|
||||||
.senderType(UserAudience.class)
|
.senderType(UserAudience.class)
|
||||||
.permission(Permissions.COMMAND_MAIN.get())
|
.permission(Permission.COMMAND_MAIN.get())
|
||||||
.handler(this::execute);
|
.handler(this::execute);
|
||||||
|
|
||||||
for (SubCommand subCommand : SubCommand.VALUES) {
|
for (SubCommand subCommand : SubCommand.VALUES) {
|
||||||
commandManager.command(builder
|
commandManager.command(builder
|
||||||
.literal(subCommand.name().toLowerCase(Locale.ROOT), subCommand.description)
|
.literal(subCommand.name().toLowerCase(Locale.ROOT), subCommand.description)
|
||||||
|
.permission(subCommand.permission.get())
|
||||||
.handler(subCommand.executor::accept)
|
.handler(subCommand.executor::accept)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -65,10 +66,12 @@ public final class MainCommand implements FloodgateCommand {
|
|||||||
StringBuilder helpMessage = new StringBuilder("Available subcommands are:\n");
|
StringBuilder helpMessage = new StringBuilder("Available subcommands are:\n");
|
||||||
|
|
||||||
for (SubCommand subCommand : SubCommand.VALUES) {
|
for (SubCommand subCommand : SubCommand.VALUES) {
|
||||||
helpMessage.append('\n').append(COLOR_CHAR).append('b')
|
if (context.getSender().hasPermission(subCommand.permission.get())) {
|
||||||
.append(subCommand.name().toLowerCase(Locale.ROOT))
|
helpMessage.append('\n').append(COLOR_CHAR).append('b')
|
||||||
.append(COLOR_CHAR).append("f - ").append(COLOR_CHAR).append('7')
|
.append(subCommand.name().toLowerCase(Locale.ROOT))
|
||||||
.append(subCommand.description);
|
.append(COLOR_CHAR).append("f - ").append(COLOR_CHAR).append('7')
|
||||||
|
.append(subCommand.description);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.getSender().sendMessage(helpMessage.toString());
|
context.getSender().sendMessage(helpMessage.toString());
|
||||||
@@ -77,11 +80,12 @@ public final class MainCommand implements FloodgateCommand {
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
enum SubCommand {
|
enum SubCommand {
|
||||||
FIREWALL("Check if your outgoing firewall allows Floodgate to work properly",
|
FIREWALL("Check if your outgoing firewall allows Floodgate to work properly",
|
||||||
FirewallCheckSubcommand::executeFirewall);
|
Permission.COMMAND_MAIN_FIREWALL, FirewallCheckSubcommand::executeFirewall);
|
||||||
|
|
||||||
static final SubCommand[] VALUES = values();
|
static final SubCommand[] VALUES = values();
|
||||||
|
|
||||||
final String description;
|
final String description;
|
||||||
|
final Permission permission;
|
||||||
final Consumer<CommandContext<UserAudience>> executor;
|
final Consumer<CommandContext<UserAudience>> executor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public final class ConfigUpdater {
|
|||||||
"config now and we'll also generate a new Floodgate key for you, but if " +
|
"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 " +
|
"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.");
|
"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");
|
renames.put("allowed", "allow-linking");
|
||||||
|
|
||||||
// relocate the old key so that they can restore it if it was a new key
|
// relocate the old key so that they can restore it if it was a new key
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import org.geysermc.floodgate.platform.command.CommandUtil;
|
|||||||
import org.geysermc.floodgate.util.Constants;
|
import org.geysermc.floodgate.util.Constants;
|
||||||
import org.geysermc.floodgate.util.HttpUtils;
|
import org.geysermc.floodgate.util.HttpUtils;
|
||||||
import org.geysermc.floodgate.util.HttpUtils.HttpResponse;
|
import org.geysermc.floodgate.util.HttpUtils.HttpResponse;
|
||||||
import org.geysermc.floodgate.util.Permissions;
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
|
|
||||||
public class NewsChecker {
|
public class NewsChecker {
|
||||||
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
|
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
|
||||||
@@ -72,8 +72,6 @@ public class NewsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkNews() {
|
private void checkNews() {
|
||||||
// todo also check news for the downloaded database types
|
|
||||||
|
|
||||||
HttpResponse<JsonArray> response =
|
HttpResponse<JsonArray> response =
|
||||||
HttpUtils.getSilent(
|
HttpUtils.getSilent(
|
||||||
Constants.NEWS_OVERVIEW_URL + Constants.NEWS_PROJECT_NAME,
|
Constants.NEWS_OVERVIEW_URL + Constants.NEWS_PROJECT_NAME,
|
||||||
@@ -121,14 +119,14 @@ public class NewsChecker {
|
|||||||
return;
|
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();
|
String message = Constants.COLOR_CHAR + "a " + news.getMessage();
|
||||||
commandUtil.sendMessage(player, message);
|
commandUtil.sendMessage(player, message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BROADCAST_TO_OPERATORS:
|
case BROADCAST_TO_OPERATORS:
|
||||||
Collection<Object> onlinePlayers = commandUtil.getOnlinePlayersWithPermission(
|
Collection<Object> onlinePlayers = commandUtil.getOnlinePlayersWithPermission(
|
||||||
Permissions.NEWS_RECEIVE.get()
|
Permission.NEWS_RECEIVE.get()
|
||||||
);
|
);
|
||||||
|
|
||||||
for (Object onlinePlayer : onlinePlayers) {
|
for (Object onlinePlayer : onlinePlayers) {
|
||||||
@@ -182,7 +180,8 @@ public class NewsChecker {
|
|||||||
schedule(delayMs > 0 ? delayMs : 0);
|
schedule(delayMs > 0 ? delayMs : 0);
|
||||||
break;
|
break;
|
||||||
case CONFIG_SPECIFIC:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
activeNewsItems.put(item.getId(), item);
|
activeNewsItems.put(item.getId(), item);
|
||||||
|
|||||||
@@ -63,19 +63,16 @@ public final class SpigotPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
boolean usePaperListener = ReflectionUtils.getClassSilently(
|
||||||
|
"com.destroystokyo.paper.event.profile.PreFillProfileEvent") != null;
|
||||||
|
|
||||||
platform.enable(
|
platform.enable(
|
||||||
new SpigotCommandModule(this),
|
new SpigotCommandModule(this),
|
||||||
new SpigotAddonModule(),
|
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
|
//todo add proper support for disabling things on shutdown and enabling this on enable
|
||||||
injector.getInstance(HandshakeHandlers.class)
|
injector.getInstance(HandshakeHandlers.class)
|
||||||
.addHandshakeHandler(injector.getInstance(SpigotHandshakeHandler.class));
|
.addHandshakeHandler(injector.getInstance(SpigotHandshakeHandler.class));
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ public final class PaperProfileListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFill(PreFillProfileEvent event) {
|
public void onFill(PreFillProfileEvent event) {
|
||||||
UUID id = event.getPlayerProfile().getId();
|
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(
|
event.getPlayerProfile().getProperties().stream().anyMatch(
|
||||||
prop -> "textures".equals(prop.getName()))) {
|
prop -> "textures".equals(prop.getName()))) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -32,8 +32,12 @@ import com.google.inject.Provides;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.geysermc.floodgate.SpigotPlugin;
|
import org.geysermc.floodgate.SpigotPlugin;
|
||||||
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
import org.geysermc.floodgate.platform.command.CommandUtil;
|
import org.geysermc.floodgate.platform.command.CommandUtil;
|
||||||
import org.geysermc.floodgate.player.FloodgateCommandPreprocessor;
|
import org.geysermc.floodgate.player.FloodgateCommandPreprocessor;
|
||||||
import org.geysermc.floodgate.player.UserAudience;
|
import org.geysermc.floodgate.player.UserAudience;
|
||||||
@@ -42,6 +46,12 @@ import org.geysermc.floodgate.player.UserAudience;
|
|||||||
public final class SpigotCommandModule extends CommandModule {
|
public final class SpigotCommandModule extends CommandModule {
|
||||||
private final SpigotPlugin plugin;
|
private final SpigotPlugin plugin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
super.configure();
|
||||||
|
registerPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -55,4 +65,20 @@ public final class SpigotCommandModule extends CommandModule {
|
|||||||
commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
|
commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
|
||||||
return commandManager;
|
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
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ public class SpigotPluginMessageRegistration implements PluginMessageRegistratio
|
|||||||
(channel1, player, message) ->
|
(channel1, player, message) ->
|
||||||
channel.handleServerCall(message, player.getUniqueId(), player.getName()));
|
channel.handleServerCall(message, player.getUniqueId(), player.getName()));
|
||||||
|
|
||||||
//todo actually do something with the result, lol
|
|
||||||
|
|
||||||
messenger.registerOutgoingPluginChannel(plugin, channel.getIdentifier());
|
messenger.registerOutgoingPluginChannel(plugin, channel.getIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user