mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
refactor: Use native platform adventure implementations
This commit is contained in:
12 files changed
+66
-29
No files matched your search
@@ -46,7 +46,6 @@ shadowJar {
|
||||
relocate 'dev.dejvokep.boostedyaml', 'net.william278.huskhomes.libraries.boostedyaml'
|
||||
relocate 'org.yaml.snakeyaml', 'net.william278.huskhomes.libraries.snakeyaml'
|
||||
relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson'
|
||||
relocate 'net.kyori', 'net.william278.huskhomes.libraries'
|
||||
relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats'
|
||||
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
relocate 'space.arim.morepaperlib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package net.william278.huskhomes;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.william278.annotaml.Annotaml;
|
||||
import net.william278.desertwell.util.Version;
|
||||
@@ -258,6 +260,12 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Audience getAudience(@NotNull UUID user) {
|
||||
return audiences.player(user);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<SavedUser> getSavedUsers() {
|
||||
@@ -476,7 +484,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitAudiences getAudiences() {
|
||||
public AudienceProvider getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.william278.huskhomes.user;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
@@ -31,6 +30,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -42,13 +42,11 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class BukkitUser extends OnlineUser {
|
||||
|
||||
private final BukkitHuskHomes plugin;
|
||||
private final Player player;
|
||||
|
||||
private BukkitUser(@NotNull Player player, @NotNull BukkitHuskHomes plugin) {
|
||||
super(player.getUniqueId(), player.getName());
|
||||
super(player.getUniqueId(), player.getName(), plugin);
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,12 +106,6 @@ public class BukkitUser extends OnlineUser {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Audience getAudience() {
|
||||
return plugin.getAudiences().player(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
|
||||
// Ensure the world exists
|
||||
@@ -129,11 +121,12 @@ public class BukkitUser extends OnlineUser {
|
||||
}
|
||||
|
||||
// Run on the appropriate thread scheduler for this platform
|
||||
plugin.getScheduler().entitySpecificScheduler(player).run(
|
||||
final GracefulScheduling scheduler = ((BukkitHuskHomes) plugin).getScheduler();
|
||||
scheduler.entitySpecificScheduler(player).run(
|
||||
() -> {
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
if (async || plugin.getScheduler().isUsingFolia()) {
|
||||
if (async || scheduler.isUsingFolia()) {
|
||||
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
return;
|
||||
}
|
||||
@@ -171,7 +164,7 @@ public class BukkitUser extends OnlineUser {
|
||||
* Send a Bukkit plugin message to the player.
|
||||
*/
|
||||
public void sendPluginMessage(@NotNull String channel, final byte[] message) {
|
||||
player.sendPluginMessage(plugin, channel, message);
|
||||
player.sendPluginMessage((BukkitHuskHomes) plugin, channel, message);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -11,11 +11,12 @@ dependencies {
|
||||
api 'net.william278:PagineDown:1.1'
|
||||
api 'net.william278:DesertWell:2.0.4'
|
||||
api 'dev.dejvokep:boosted-yaml:1.3.1'
|
||||
api 'net.kyori:adventure-api:4.14.0'
|
||||
api('com.zaxxer:HikariCP:5.1.0') {
|
||||
exclude module: 'slf4j-api'
|
||||
}
|
||||
|
||||
compileOnly 'net.kyori:adventure-api:4.15.0'
|
||||
compileOnly 'net.kyori:adventure-platform-api:4.3.1'
|
||||
compileOnly "redis.clients:jedis:$jedis_version"
|
||||
compileOnly "org.xerial:sqlite-jdbc:$sqlite_driver_version"
|
||||
compileOnly "com.mysql:mysql-connector-j:$mysql_driver_version"
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.william278.huskhomes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.william278.annotaml.Annotaml;
|
||||
import net.william278.desertwell.util.ThrowingConsumer;
|
||||
@@ -86,6 +87,16 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
|
||||
@NotNull
|
||||
List<OnlineUser> getOnlineUsers();
|
||||
|
||||
|
||||
/**
|
||||
* Get the adventure {@link Audience} for a given {@link UUID}.
|
||||
*
|
||||
* @param user The {@link UUID} of the user to get the {@link Audience} for.
|
||||
* @return The {@link Audience} for the given {@link UUID}.
|
||||
*/
|
||||
@NotNull
|
||||
Audience getAudience(@NotNull UUID user);
|
||||
|
||||
/**
|
||||
* Finds a local {@link OnlineUser} by their name. Auto-completes partially typed names for the closest match
|
||||
*
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
@@ -42,8 +43,11 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class OnlineUser extends User implements Teleportable, CommandUser {
|
||||
|
||||
public OnlineUser(@NotNull UUID uuid, @NotNull String username) {
|
||||
protected final HuskHomes plugin;
|
||||
|
||||
protected OnlineUser(@NotNull UUID uuid, @NotNull String username, @NotNull HuskHomes plugin) {
|
||||
super(uuid, username);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +179,9 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
||||
* @return the adventure {@link Audience} for this player
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Audience getAudience();
|
||||
public Audience getAudience() {
|
||||
return plugin.getAudience(getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the specified local {@link Location}.
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -222,6 +223,12 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Audience getAudience(@NotNull UUID user) {
|
||||
return audiences.player(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<SavedUser> getSavedUsers() {
|
||||
|
||||
@@ -42,13 +42,11 @@ import java.util.*;
|
||||
|
||||
public class FabricUser extends OnlineUser {
|
||||
|
||||
private final FabricHuskHomes plugin;
|
||||
private final ServerPlayerEntity player;
|
||||
|
||||
private FabricUser(@NotNull ServerPlayerEntity player, @NotNull FabricHuskHomes plugin) {
|
||||
super(player.getUuid(), player.getEntityName());
|
||||
super(player.getUuid(), player.getEntityName(), plugin);
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -94,14 +92,14 @@ public class FabricUser extends OnlineUser {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String node) {
|
||||
final boolean requiresOp = Boolean.TRUE.equals(plugin.getPermissions().getOrDefault(node, true));
|
||||
return Permissions.check(player, node, !requiresOp || player.hasPermissionLevel(3));
|
||||
boolean op = Boolean.TRUE.equals(((FabricHuskHomes) plugin).getPermissions().getOrDefault(node, true));
|
||||
return Permissions.check(player, node, !op || player.hasPermissionLevel(3));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Boolean> getPermissions() {
|
||||
return plugin.getPermissions().entrySet().stream()
|
||||
return ((FabricHuskHomes) plugin).getPermissions().entrySet().stream()
|
||||
.filter(entry -> Permissions.check(player, entry.getKey(), entry.getValue()))
|
||||
.collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ shadowJar {
|
||||
relocate 'dev.dejvokep.boostedyaml', 'net.william278.huskhomes.libraries.boostedyaml'
|
||||
relocate 'org.yaml.snakeyaml', 'net.william278.huskhomes.libraries.snakeyaml'
|
||||
relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson'
|
||||
relocate 'net.kyori', 'net.william278.huskhomes.libraries'
|
||||
relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats'
|
||||
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
relocate 'space.arim.morepaperlib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
|
||||
@@ -19,9 +19,13 @@
|
||||
|
||||
package net.william278.huskhomes;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.william278.huskhomes.listener.PaperEventListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PaperHuskHomes extends BukkitHuskHomes {
|
||||
|
||||
@Override
|
||||
@@ -30,4 +34,10 @@ public class PaperHuskHomes extends BukkitHuskHomes {
|
||||
return new PaperEventListener(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Audience getAudience(@NotNull UUID user) {
|
||||
final Player player = getServer().getPlayer(user);
|
||||
return player == null || !player.isOnline() ? Audience.empty() : player;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
package net.william278.huskhomes;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.william278.annotaml.Annotaml;
|
||||
import net.william278.desertwell.util.Version;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
@@ -229,6 +230,12 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Audience getAudience(@NotNull UUID user) {
|
||||
return game.server().player(user).map(player -> (Audience) player).orElse(Audience.empty());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<SavedUser> getSavedUsers() {
|
||||
|
||||
@@ -37,12 +37,10 @@ import java.util.Optional;
|
||||
public class SpongeUser extends OnlineUser {
|
||||
|
||||
private final ServerPlayer player;
|
||||
private final SpongeHuskHomes plugin;
|
||||
|
||||
private SpongeUser(@NotNull ServerPlayer player, @NotNull SpongeHuskHomes plugin) {
|
||||
super(player.uniqueId(), player.name());
|
||||
super(player.uniqueId(), player.name(), plugin);
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +118,7 @@ public class SpongeUser extends OnlineUser {
|
||||
|
||||
@Override
|
||||
public void sendPluginMessage(@NotNull String channel, byte[] message) {
|
||||
plugin.getPluginMessageChannel().sendTo(player, channelBuf -> channelBuf.writeBytes(message));
|
||||
((SpongeHuskHomes) plugin).getPluginMessageChannel().sendTo(player, buf -> buf.writeBytes(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user