-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* No longer uses the Geyser API directly, as this caused classloader problems. * Requires `floodgate` to be installed instead. * Should now work on standalone Spigot servers.
- Loading branch information
Showing
36 changed files
with
1,279 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,39 @@ | ||
# clientcontext | ||
A BungeeCord plugin that adds [LuckPerms](https://luckperms.net/) contexts for the client version and client type. | ||
# ClientContext | ||
A BungeeCord plugin that adds [LuckPerms](https://luckperms.net/) contexts for client info, allowing permissions to be added or removed depending on what kind of device the client is on. | ||
|
||
## Installation | ||
There are two ways to install ClientContext: standalone with Spigot, or in a BungeeCord network. | ||
|
||
### Standalone | ||
When you have [Geyser](https://geysermc.org/) installed as a plugin on a single Spigot or Paper server, you can add ClientContext alongside it under the `plugins` folder. | ||
|
||
For a standalone installation, you must have have [floodgate](https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/) installed as well. | ||
|
||
### Networked | ||
When using [Geyser](https://geysermc.org/) on a BungeeCord proxy (as well as [floodgate](https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/)), contexts will be resolved on the proxy and sent to each of the Spigot servers through plugin messages. This requires installing ClientContext on both the proxy and each of the Spigot servers. | ||
|
||
## Contexts | ||
### client:type | ||
This context specifies the type of Minecraft client being used. | ||
Currently, only two types are supported: `java`, and `bedrock` | ||
|
||
### client-version | ||
This context specifies the version of Minecraft client that the player is using. | ||
### client:version | ||
This context specifies the version of Minecraft client that the player is using. | ||
Two values will be assigned: an exact version (e.g. `1.2.1`), and a rough version (e.g. `1.2.x`). | ||
|
||
### client-type | ||
This context specifies the type of Minecraft client being used. | ||
Currently, only two types are supported: `java`, and `bedrock` (through [Geyser](https://geysermc.org/) for Spigot) | ||
### client:archetype | ||
A device archetype for a client. | ||
Possible values include: `computer`, `console`, `mobile`. | ||
|
||
### client:device | ||
> Bedrock clients only. | ||
The device type of a Bedrock client: | ||
See [here](https://github.com/GeyserMC/Geyser/blob/master/common/src/main/java/org/geysermc/floodgate/util/DeviceOs.java) for a list of values, e.g. `ios`, `nx`, `google`, etc. | ||
|
||
### client:controls | ||
> Bedrock clients only. | ||
The control type for a client: | ||
See [here](https://github.com/GeyserMC/Geyser/blob/master/common/src/main/java/org/geysermc/floodgate/util/InputMode.java) for a list of values, e.g | ||
`keyboard_mouse`, `touch`, `controller`, etc. |
143 changes: 0 additions & 143 deletions
143
bukkit/src/main/java/dev/ethp/clientcontext/BukkitPlugin.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
bukkit/src/main/java/dev/ethp/clientcontext/bukkit/BukkitPlatform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.ethp.clientcontext.bukkit; | ||
|
||
import dev.ethp.clientcontext.PlatformAbstraction; | ||
import dev.ethp.clientcontext.util.ClientVersion; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Implementation of platform abstraction for a Bukkit/Spigot/Paper server. | ||
*/ | ||
@SuppressWarnings("FieldCanBeLocal") | ||
public final class BukkitPlatform implements PlatformAbstraction<Player> { | ||
private final JavaPlugin plugin; | ||
private ClientVersion version; | ||
|
||
public BukkitPlatform(@NotNull JavaPlugin plugin) { | ||
this.plugin = plugin; | ||
|
||
// Parse the server version string. | ||
String[] versionParts = this.plugin.getServer().getBukkitVersion().split("[-_]")[0].split("\\."); | ||
int versionMajor = Integer.parseInt(versionParts[0]); | ||
int versionMinor = versionParts.length < 2 ? 0 : Integer.parseInt(versionParts[1]); | ||
int versionPatch = versionParts.length < 3 ? 0 : Integer.parseInt(versionParts[2]); | ||
this.version = new ClientVersion(versionMajor, versionMinor, versionPatch); | ||
} | ||
|
||
@Override | ||
public @NotNull UUID getUniqueId(@NotNull Player player) { | ||
return player.getUniqueId(); | ||
} | ||
|
||
@Override | ||
public @NotNull Optional<ClientVersion> getPlayerClientVersion(@NotNull Player player) { | ||
return Optional.of(this.version); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
bukkit/src/main/java/dev/ethp/clientcontext/bukkit/BukkitPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dev.ethp.clientcontext.bukkit; | ||
|
||
import dev.ethp.clientcontext.CommonPlugin; | ||
import dev.ethp.clientcontext.Constants; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
/** | ||
* Main class for the Bukkit plugin. | ||
*/ | ||
public class BukkitPlugin extends JavaPlugin { | ||
private BukkitPlatform platform; | ||
private CommonPlugin<Player> common; | ||
private ContextSyncReceiver sync; | ||
|
||
@Override | ||
public void onEnable() { | ||
// Initialize everything. | ||
this.platform = new BukkitPlatform(this); | ||
this.common = new CommonPlugin<>(getLogger(), this.platform); | ||
|
||
// Register contexts. | ||
if (BungeeUtil.isRunningUnderBungee()) { | ||
this.sync = new ContextSyncReceiver(this); | ||
this.common.register(this.sync); | ||
getLogger().info("Running under a BungeeCord network; contexts will be synced from proxy for accuracy."); | ||
getLogger().info("If you do not have the ClientContext plugin installed on the proxy, please install it."); | ||
} else { | ||
this.common.registerDefaults(); | ||
} | ||
|
||
// Register plugin messages. | ||
if (this.sync != null) { | ||
getServer().getPluginManager().registerEvents(this.sync, this); | ||
getServer().getMessenger().registerIncomingPluginChannel(this, Constants.CHANNEL, this.sync); | ||
getServer().getMessenger().registerOutgoingPluginChannel(this, Constants.CHANNEL); | ||
} | ||
|
||
// Sync all client info. | ||
if (this.sync != null) { | ||
this.sync.requestContext(); | ||
} | ||
} | ||
|
||
public void onDisable() { | ||
this.common.unregister(); | ||
|
||
getServer().getMessenger().unregisterIncomingPluginChannel(this); | ||
getServer().getMessenger().unregisterOutgoingPluginChannel(this); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
bukkit/src/main/java/dev/ethp/clientcontext/bukkit/BungeeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.ethp.clientcontext.bukkit; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* Utilities for working inside a BungeeCord network. | ||
*/ | ||
public class BungeeUtil { | ||
|
||
/** | ||
* Check to see if the server is running under BungeeCord. | ||
* | ||
* @return True if the spigot.yml file is configured to run under under BungeeCord. | ||
*/ | ||
public static boolean isRunningUnderBungee() { | ||
// Try finding out directly through the class that contains the config: | ||
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/CraftBukkit-Patches/0030-BungeeCord-Support.patch?until=450dcaa86efd759674bbdeae0f6a37c97977618e&untilPath=CraftBukkit-Patches%2F0030-BungeeCord-Support.patch#215 | ||
try { | ||
Class<?> config = BungeeUtil.class.getClassLoader().loadClass("org.spigotmc.SpigotConfig"); | ||
Field bungee = config.getField("bungee"); | ||
return (Boolean) bungee.get(null); | ||
} catch (ReflectiveOperationException ignored) { | ||
} | ||
|
||
// Not running a Spigot server? | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.