mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Fix spigot support, use common adventure API, move message dispatch to common
This commit is contained in:
1 parent
1d98e22c9c
commit
f1929a0fa6
8 files changed
+60
-48
No files matched your search
+2
-1
@@ -12,7 +12,8 @@ version "$ext.plugin_version-${versionMetadata()}"
|
||||
|
||||
ext {
|
||||
set 'version', version.toString()
|
||||
set 'adventure_version', adventure_version.toString()
|
||||
set 'adventure_api_version', adventure_api_version.toString()
|
||||
set 'adventure_bukkit_platform_version', adventure_bukkit_platform_version.toString()
|
||||
set 'jedis_version', jedis_version.toString()
|
||||
set 'sqlite_driver_version', sqlite_driver_version.toString()
|
||||
set 'mysql_driver_version', mysql_driver_version.toString()
|
||||
|
||||
+3
-2
@@ -8,7 +8,8 @@ dependencies {
|
||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
|
||||
compileOnly 'net.kyori:adventure-platform-bukkit:' + adventure_version
|
||||
compileOnly 'net.kyori:adventure-api:' + adventure_api_version
|
||||
compileOnly 'net.kyori:adventure-platform-bukkit:' + adventure_bukkit_platform_version
|
||||
compileOnly 'redis.clients:jedis:' + jedis_version
|
||||
compileOnly 'commons-io:commons-io:2.11.0'
|
||||
compileOnly 'com.google.guava:guava:31.1-jre'
|
||||
@@ -19,7 +20,7 @@ dependencies {
|
||||
|
||||
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
|
||||
testImplementation 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
|
||||
testImplementation 'net.kyori:adventure-platform-bukkit:' + adventure_version
|
||||
testImplementation 'net.kyori:adventure-platform-bukkit:' + adventure_bukkit_platform_version
|
||||
testImplementation 'redis.clients:jedis:' + jedis_version
|
||||
testImplementation 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
|
||||
testImplementation 'mysql:mysql-connector-java:' + mysql_driver_version
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package net.william278.huskhomes.player;
|
||||
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import de.themoep.minedown.adventure.MineDownParser;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.HuskHomesException;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
@@ -32,12 +27,10 @@ import java.util.stream.Collectors;
|
||||
public class BukkitPlayer extends OnlineUser {
|
||||
|
||||
private final Player player;
|
||||
private final Audience audience;
|
||||
|
||||
private BukkitPlayer(@NotNull Player player) {
|
||||
super(player.getUniqueId(), player.getName());
|
||||
this.player = player;
|
||||
this.audience = BukkitHuskHomes.getInstance().getAudiences().player(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,36 +90,8 @@ public class BukkitPlayer extends OnlineUser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(@NotNull MineDown mineDown, boolean subTitle) {
|
||||
final Component text = mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent();
|
||||
audience.showTitle(Title.title(subTitle ? Component.empty() : text,
|
||||
subTitle ? text : Component.empty()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionBar(@NotNull MineDown mineDown) {
|
||||
audience.sendActionBar(mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NotNull MineDown mineDown) {
|
||||
audience.sendMessage(mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMinecraftMessage(@NotNull String translationKey) {
|
||||
player.spigot().sendMessage(new TranslatableComponent(translationKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(@NotNull String soundEffect) {
|
||||
player.playSound(player.getLocation(), soundEffect, 1, 1);
|
||||
protected @NotNull Audience getAudience() {
|
||||
return BukkitHuskHomes.getInstance().getAudiences().player(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,8 @@ softdepend:
|
||||
- BlueMap
|
||||
- Plan
|
||||
libraries:
|
||||
- 'net.kyori:adventure-platform-bukkit:${adventure_version}'
|
||||
- 'net.kyori:adventure-platform-bukkit:${adventure_bukkit_platform_version}'
|
||||
- 'net.kyori:adventure-api:${adventure_api_version}'
|
||||
- 'redis.clients:jedis:${jedis_version}'
|
||||
- 'mysql:mysql-connector-java:${mysql_driver_version}'
|
||||
- 'org.xerial:sqlite-jdbc:${sqlite_driver_version}'
|
||||
|
||||
@@ -11,6 +11,7 @@ dependencies {
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||
compileOnly 'com.google.guava:guava:31.1-jre'
|
||||
compileOnly 'net.kyori:adventure-api:' + adventure_api_version
|
||||
compileOnly 'redis.clients:jedis:' + jedis_version
|
||||
compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
|
||||
compileOnly 'mysql:mysql-connector-java:' + mysql_driver_version
|
||||
|
||||
@@ -100,7 +100,7 @@ public class EventListener {
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(plugin.getPluginServer()))
|
||||
.ifPresent(position -> onlineUser.teleport(position, plugin.getSettings().asynchronousTeleports));
|
||||
onlineUser.sendMinecraftMessage("block.minecraft.spawn.not_valid");
|
||||
onlineUser.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||
} else {
|
||||
onlineUser.teleport(bedPosition.get(), plugin.getSettings().asynchronousTeleports);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
package net.william278.huskhomes.player;
|
||||
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import de.themoep.minedown.adventure.MineDownParser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.InvalidKeyException;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.TitlePart;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.TeleportResult;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@@ -63,14 +71,22 @@ public abstract class OnlineUser extends User {
|
||||
* @param mineDown the parsed {@link MineDown} to send
|
||||
* @param subTitle whether to send the title as a subtitle ({@code true} for a subtitle, {@code false} for a title)
|
||||
*/
|
||||
public abstract void sendTitle(@NotNull MineDown mineDown, boolean subTitle);
|
||||
public final void sendTitle(@NotNull MineDown mineDown, boolean subTitle) {
|
||||
getAudience().sendTitlePart(subTitle ? TitlePart.SUBTITLE : TitlePart.TITLE, mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a MineDown-formatted action bar message to this player
|
||||
*
|
||||
* @param mineDown the parsed {@link MineDown} to send
|
||||
*/
|
||||
public abstract void sendActionBar(@NotNull MineDown mineDown);
|
||||
public final void sendActionBar(@NotNull MineDown mineDown) {
|
||||
getAudience().sendActionBar(mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,21 +94,47 @@ public abstract class OnlineUser extends User {
|
||||
*
|
||||
* @param mineDown the parsed {@link MineDown} to send
|
||||
*/
|
||||
public abstract void sendMessage(@NotNull MineDown mineDown);
|
||||
public final void sendMessage(@NotNull MineDown mineDown) {
|
||||
getAudience().sendMessage(mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a Minecraft translatable keyed-message to this player
|
||||
*
|
||||
* @param translationKey the translation key of the message to send
|
||||
* @implNote This method is intended for use with Minecraft's built-in translation keys. If the key is invalid,
|
||||
* it will be substituted with {@code minecraft:block.minecraft.spawn.not_valid}
|
||||
*/
|
||||
public abstract void sendMinecraftMessage(@NotNull String translationKey);
|
||||
public final void sendTranslatableMessage(@Subst(Key.MINECRAFT_NAMESPACE + "block.minecraft.spawn.not_valid")
|
||||
@NotNull String translationKey) {
|
||||
getAudience().sendMessage(Component.translatable(translationKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the specified sound to this player
|
||||
*
|
||||
* @param soundEffect the sound effect to play. If the sound name is invalid, the sound will not play
|
||||
* @implNote If the key is invalid, it will be substituted with {@code minecraft:block.note_block.banjo}
|
||||
*/
|
||||
public abstract void playSound(@NotNull String soundEffect);
|
||||
public final void playSound(@Subst(Key.MINECRAFT_NAMESPACE + "block.note_block.banjo")
|
||||
@NotNull String soundEffect) throws IllegalArgumentException {
|
||||
try {
|
||||
getAudience().playSound(Sound.sound(Key.key(soundEffect), Sound.Source.PLAYER,
|
||||
1.0f, 1.0f), Sound.Emitter.self());
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new IllegalArgumentException("Invalid sound effect name: " + soundEffect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the adventure {@link Audience} for this player
|
||||
*
|
||||
* @return the adventure {@link Audience} for this player
|
||||
*/
|
||||
@NotNull
|
||||
protected abstract Audience getAudience();
|
||||
|
||||
/**
|
||||
* Teleport a player to the specified {@link Location}
|
||||
|
||||
+2
-1
@@ -10,4 +10,5 @@ jedis_version=4.2.3
|
||||
sqlite_driver_version=3.39.2.0
|
||||
mysql_driver_version=8.0.30
|
||||
commons_text_version=1.9
|
||||
adventure_version = 4.1.2
|
||||
adventure_api_version=4.11.0
|
||||
adventure_bukkit_platform_version=4.1.2
|
||||
Reference in new issue
Block a user