Skip to content

Commit

Permalink
Spigot: programmatically add Geyser permissions and fix reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed May 6, 2022
1 parent 05e98c3 commit f38c1fb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import me.lucko.commodore.CommodoreProvider;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
import org.geysermc.geyser.command.CommandManager;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
Expand All @@ -61,10 +64,16 @@
import java.net.SocketAddress;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;

public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
/**
* Determines if the plugin has been ran once before, including before /geyser reload.
*/
private static boolean INITIALIZED = false;

private GeyserSpigotCommandManager geyserCommandManager;
private GeyserSpigotConfiguration geyserConfig;
private GeyserSpigotInjector geyserInjector;
Expand Down Expand Up @@ -232,14 +241,32 @@ public void onEnable() {
}
geyserLogger.debug("Using default world manager: " + this.geyserWorldManager.getClass());
}
GeyserSpigotBlockPlaceListener blockPlaceListener = new GeyserSpigotBlockPlaceListener(geyser, this.geyserWorldManager);
Bukkit.getServer().getPluginManager().registerEvents(blockPlaceListener, this);

Bukkit.getServer().getPluginManager().registerEvents(new GeyserPistonListener(geyser, this.geyserWorldManager), this);

PluginCommand pluginCommand = this.getCommand("geyser");
pluginCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser));

if (!INITIALIZED) {
// Register permissions so they appear in, for example, LuckPerms' UI
// Re-registering permissions throws an error
for (Map.Entry<String, GeyserCommand> entry : geyserCommandManager.getCommands().entrySet()) {
GeyserCommand command = entry.getValue();
if (command.getAliases().contains(entry.getKey())) {
// Don't register aliases
continue;
}

Bukkit.getPluginManager().addPermission(new Permission(command.getPermission(),
GeyserLocale.getLocaleStringLog(command.getDescription()),
command.isSuggestedOpOnly() ? PermissionDefault.OP : PermissionDefault.TRUE));
}

// Events cannot be unregistered - re-registering results in duplicate firings
GeyserSpigotBlockPlaceListener blockPlaceListener = new GeyserSpigotBlockPlaceListener(geyser, this.geyserWorldManager);
Bukkit.getServer().getPluginManager().registerEvents(blockPlaceListener, this);

Bukkit.getServer().getPluginManager().registerEvents(new GeyserPistonListener(geyser, this.geyserWorldManager), this);
}

boolean brigadierSupported = CommodoreProvider.isSupported();
geyserLogger.debug("Brigadier supported? " + brigadierSupported);
if (brigadierSupported) {
Expand All @@ -248,6 +275,8 @@ public void onEnable() {

// Check to ensure the current setup can support the protocol version Geyser uses
GeyserSpigotVersionChecker.checkForSupportedProtocol(geyserLogger, isViaVersion);

INITIALIZED = true;
}

@Override
Expand Down
31 changes: 0 additions & 31 deletions bootstrap/spigot/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,3 @@ commands:
geyser:
description: The main command for Geyser.
usage: /geyser <subcommand>
permissions:
geyser.command.help:
description: Shows help for all registered commands.
default: true
geyser.command.offhand:
description: Puts an items in your offhand.
default: true
geyser.command.advancements:
description: Shows the advancements of the player on the server.
default: true
geyser.command.tooltips:
description: Toggles showing advanced tooltips on your items.
default: true
geyser.command.statistics:
description: Shows the statistics of the player on the server.
default: true
geyser.command.settings:
description: Modify user settings
default: true
geyser.command.list:
description: List all players connected through Geyser.
default: op
geyser.command.dump:
description: Dumps Geyser debug information for bug reports.
default: op
geyser.command.reload:
description: Reloads the Geyser configurations. Kicks all players when used!
default: false
geyser.command.version:
description: Shows the current Geyser version and checks for updates.
default: op
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@ public boolean hasSubCommands() {
public boolean isBedrockOnly() {
return false;
}

/**
* Used for permission defaults on server implementations.
*
* @return if this command is designated to be used only by server operators.
*/
public boolean isSuggestedOpOnly() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,9 @@ public void execute(GeyserSession session, CommandSender sender, String[] args)
public List<String> getSubCommands() {
return Arrays.asList("offline", "full", "logs");
}

@Override
public boolean isSuggestedOpOnly() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public void execute(GeyserSession session, CommandSender sender, String[] args)

sender.sendMessage(message);
}

@Override
public boolean isSuggestedOpOnly() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public void execute(GeyserSession session, CommandSender sender, String[] args)
geyser.getSessionManager().disconnectAll("geyser.commands.reload.kick");
geyser.reload();
}

@Override
public boolean isSuggestedOpOnly() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public void execute(GeyserSession session, CommandSender sender, String[] args)

geyser.getBootstrap().onDisable();
}

@Override
public boolean isSuggestedOpOnly() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ public void execute(GeyserSession session, CommandSender sender, String[] args)
}
}
}

@Override
public boolean isSuggestedOpOnly() {
return true;
}
}

0 comments on commit f38c1fb

Please sign in to comment.