Skip to content

Port changes from Triton v3.10.0 to v4 #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3c20791
refactor(spigot): use ProtocolLib's MinecraftVersion for version bran…
diogotcorreia Jun 19, 2024
c9fffb1
chore: update dependencies to target minecraft 1.20.6
diogotcorreia Jun 23, 2024
fe96712
refactor(spigot): use ProtocolLib's reflection utils to get CB and NM…
diogotcorreia Jun 23, 2024
98a429c
refactor: get banner material by name
diogotcorreia Jun 23, 2024
32aa7ae
fix(spigot): checking whether player's inventory is open in MC 1.20.6
diogotcorreia Jun 23, 2024
252ab4c
refactor(spigot): use protocollib's wrappers for sign packet handling
diogotcorreia Jun 23, 2024
ab3cfde
fix(spigot): item translation in MC 1.20.6
diogotcorreia Jun 9, 2024
c04270a
refactor(spigot): use ProtocolLib's team parameters wrapper for team …
diogotcorreia Jun 9, 2024
efb9aee
fix(spigot): advancement translation in MC 1.20.6
diogotcorreia Jun 9, 2024
a45d295
fix(spigot): container carried item not being translated
diogotcorreia Jun 10, 2024
a365e05
fix(spigot): incorrect head rotation of NPCs after refresh
diogotcorreia Jun 10, 2024
d71b4ab
feat(spigot): add text display and item frame as default holograms
diogotcorreia Jun 18, 2024
0d1c087
chore: update dependencies to target minecraft 1.21
diogotcorreia Jun 18, 2024
3503830
fix(spigot): WrappedRegistrable to DataComponentType throwing on MC 1.21
diogotcorreia Jun 18, 2024
eb60132
refactor(spigot): use protocollib accessors for bossbar packets
diogotcorreia Jun 19, 2024
9c2f475
feat(spigot): support death screen translation
diogotcorreia Jun 19, 2024
7d92fa1
fix(spigot): text displays not being translated on 1.19.3 through 1.20.1
diogotcorreia Jun 23, 2024
3852b4c
fix(spigot): incompatibility with Citizens 2.0.34-b3426
diogotcorreia Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ public interface TritonConfig {
*/
boolean isAdvancements();

/**
* @return The value of "language-creation.death-screen.enabled" in the config.
* @since 3.10.0
*/
boolean isDeathScreen();

/**
* @return The value of "language-creation.terminal" in the config.
* @since 2.6.0
Expand Down Expand Up @@ -323,4 +329,10 @@ public interface TritonConfig {
*/
FeatureSyntax getAdvancementsSyntax();

/**
* @return The {@link com.rexcantor64.triton.api.config.FeatureSyntax FeatureSyntax} of "language-creation
* .death-screen" in the config.
*/
FeatureSyntax getDeathScreenSyntax();

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public class MainConfig implements TritonConfig {
private boolean advancementsRefresh;
private boolean resourcePackPrompt;
private FeatureSyntax resourcePackPromptSyntax;
private boolean deathScreen;
private FeatureSyntax deathScreenSyntax;
private boolean terminal;
private boolean terminalAnsi;
private boolean preventPlaceholdersInChat;
Expand Down Expand Up @@ -293,6 +295,10 @@ private void setupLanguageCreation(Configuration section) {
this.resourcePackPrompt = resourcePackPrompt.getBoolean("enabled", true);
this.resourcePackPromptSyntax = FeatureSyntax.fromSection(resourcePackPrompt);

Configuration deathScreen = section.getSection("death-screen");
this.deathScreen = deathScreen.getBoolean("enabled", true);
this.deathScreenSyntax = FeatureSyntax.fromSection(deathScreen);

List<String> hologramList = holograms.getStringList("types");
for (String hologram : hologramList)
try {
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions triton-bungeecord/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ dependencies {
compileOnly project(path: ":api")
compileOnly project(path: ":core")

compileOnly 'net.md-5:bungeecord-api:1.20-R0.2-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-proxy:1.20-R0.2-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-api:1.21-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-proxy:1.21-R0.1-SNAPSHOT'

compileOnly 'net.kyori:adventure-text-serializer-bungeecord:4.3.2'

Expand Down
9 changes: 6 additions & 3 deletions triton-spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ String pluginAuthor = project.property("pluginAuthor")
String pluginApiVersion = project.property("pluginApiVersion")
String pluginName = project.property("pluginName")

// Plugins that also hook into ProtocolLib and therefore have to be loaded before Triton
List conflictingPlugins = ['Citizens']

apply plugin: 'net.minecrell.plugin-yml.bukkit'
group 'com.rexcantor64.triton'

Expand All @@ -18,13 +21,13 @@ dependencies {
implementation project(path: ":spigot-legacy")
implementation project(path: ":v1_13")

compileOnly 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'

compileOnly 'net.kyori:adventure-text-serializer-gson:4.15.0'
compileOnly 'net.kyori:adventure-text-serializer-legacy:4.15.0'
compileOnly 'net.kyori:adventure-text-serializer-bungeecord:4.3.2'

compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0-SNAPSHOT'
compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.11.1'

// Libraries available on Spigot
Expand All @@ -43,7 +46,7 @@ bukkit {
apiVersion = pluginApiVersion

depend = ['ProtocolLib']
softDepend = ['PlaceholderAPI']
softDepend = ['PlaceholderAPI'] + conflictingPlugins

commands {
twin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.val;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.ChatColor;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SingleLineChart;
Expand All @@ -43,10 +42,6 @@

public class SpigotTriton extends Triton<SpigotLanguagePlayer, SpigotBridgeManager> {

@Getter
private final short mcVersion;
@Getter
private final short minorMcVersion;
private ProtocolLibListener protocolLibListener;
@Getter
private MaterialWrapperManager wrapperManager;
Expand All @@ -62,9 +57,6 @@ public class SpigotTriton extends Triton<SpigotLanguagePlayer, SpigotBridgeManag

public SpigotTriton(PluginLoader loader) {
super(new PlayerManager<>(SpigotLanguagePlayer::new), new SpigotBridgeManager());
val versionSplit = Bukkit.getServer().getClass().getPackage().getName().split("_");
mcVersion = Short.parseShort(versionSplit[1]);
minorMcVersion = Short.parseShort(versionSplit[2].substring(1));
super.loader = loader;
}

Expand Down Expand Up @@ -103,16 +95,7 @@ public void onEnable() {
Bukkit.getPluginManager().registerEvents(guiManager = new GuiManager(), getLoader());
Bukkit.getPluginManager().registerEvents(new BukkitListener(), getLoader());

// Setup ProtocolLib
if (getConfig().isAsyncProtocolLib()) {
val asyncManager = ProtocolLibrary.getProtocolManager().getAsynchronousManager();
asyncManager.registerAsyncHandler(protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC)).start();
asyncManager.registerAsyncHandler(new MotdPacketHandler()).start();
ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibListener(this, HandlerFunction.HandlerType.SYNC));
} else {
ProtocolLibrary.getProtocolManager().addPacketListener(protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC, HandlerFunction.HandlerType.SYNC));
ProtocolLibrary.getProtocolManager().addPacketListener(new MotdPacketHandler());
}
registerProtocolLibListeners();

if (getConfig().isBungeecord()) {
if (!isSpigotProxyMode() && !isPaperProxyMode()) {
Expand All @@ -137,6 +120,29 @@ public void onEnable() {
}
}

private void registerProtocolLibListeners() {
if (getConfig().isAsyncProtocolLib()) {
protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC);
} else {
protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC, HandlerFunction.HandlerType.SYNC);
}

// Use delayed task to try to be the last registered listener and therefore have the final say in packets
Bukkit.getScheduler().scheduleSyncDelayedTask(getLoader(), () -> {
if (getConfig().isAsyncProtocolLib()) {
val asyncManager = ProtocolLibrary.getProtocolManager().getAsynchronousManager();
asyncManager.registerAsyncHandler(protocolLibListener).start();
asyncManager.registerAsyncHandler(new MotdPacketHandler()).start();
ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibListener(this, HandlerFunction.HandlerType.SYNC));
} else {
ProtocolLibrary.getProtocolManager().addPacketListener(protocolLibListener);
ProtocolLibrary.getProtocolManager().addPacketListener(new MotdPacketHandler());
}
getLogger().logInfo("Registered ProtocolLib listeners");
}, 1L);

}

@SneakyThrows
private PluginCommand registerTritonCommand() {
val constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
Expand Down Expand Up @@ -187,10 +193,12 @@ private boolean isProtocolLibAvailable() {
}

try {
MinecraftVersion ignore = MinecraftVersion.v1_20_4;
// Field known to exist in build 717 (commit e726f6e)
boolean ignore = MinecraftVersion.v1_21_0.atOrAbove();
} catch (NoSuchFieldError ignore) {
// Triton requires ProtocolLib 5.2.0 or later
getLogger().logError("ProtocolLib 5.2.0 or later is required! Older versions of ProtocolLib will only partially work or not work at all, and are therefore not recommended.");
// Triton requires ProtocolLib 5.3.0 or later
getLogger().logError("ProtocolLib 5.3.0 or later is required! Older versions of ProtocolLib will only partially work or not work at all, and are therefore not recommended.");
getLogger().logError("It is likely that you need the latest dev version, which you can download at https://triton.rexcantor64.com/protocollib");
getLogger().logError("If you want to enable the plugin anyway, add `i-know-what-i-am-doing: true` to Triton's config.yml.");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rexcantor64.triton.spigot.banners;

import com.comphenix.protocol.utility.MinecraftVersion;
import com.rexcantor64.triton.Triton;
import com.rexcantor64.triton.api.language.Language;
import com.rexcantor64.triton.spigot.SpigotTriton;
Expand All @@ -15,9 +16,36 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;
import java.util.stream.Stream;

public class BannerBuilder {

private final static ItemFlag[] ITEM_FLAGS;

static {
// Enum value was renamed in MC 1.20.6
ItemFlag hideAdditionalTooltipFlag = Stream.of("HIDE_POTION_EFFECTS", "HIDE_ADDITIONAL_TOOLTIP")
.map(name -> {
try {
return ItemFlag.valueOf(name);
} catch (IllegalArgumentException e) {
return null;
}
})
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new RuntimeException("Failed to get HIDE_ADDITIONAL_TOOLTIP item flag"));

ITEM_FLAGS = new ItemFlag[] {
ItemFlag.HIDE_ENCHANTS,
ItemFlag.HIDE_ATTRIBUTES,
ItemFlag.HIDE_UNBREAKABLE,
ItemFlag.HIDE_DESTROYS,
ItemFlag.HIDE_PLACED_ON,
hideAdditionalTooltipFlag,
};
}

private final HashMap<Language, Banner> bannerCache = new HashMap<>();

public void flushCache() {
Expand All @@ -34,7 +62,7 @@ private ItemStack bannerToItemStack(Banner banner, String displayName, boolean a
ItemStack itemStack = new ItemStack(SpigotTriton.asSpigot().getWrapperManager().getBannerMaterial());
BannerMeta bannerMeta = Objects.requireNonNull((BannerMeta) itemStack.getItemMeta());
for (Banner.Layer layer : banner.getLayers()) {
val dyeColor = DyeColor.valueOf(layer.getColor().getColor());
val dyeColor = getDyeColor(layer.getColor());
val patternType = PatternType.valueOf(layer.getPattern().getType());
bannerMeta.addPattern(new Pattern(dyeColor, patternType));
}
Expand All @@ -43,10 +71,17 @@ private ItemStack bannerToItemStack(Banner banner, String displayName, boolean a
val selectedMsg = ChatColor.translateAlternateColorCodes('&', Triton.get().getMessagesConfig().getMessage("other.selected"));
bannerMeta.setLore(Collections.singletonList(selectedMsg));
}
bannerMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS,
ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_UNBREAKABLE);
bannerMeta.addItemFlags(ITEM_FLAGS);
itemStack.setItemMeta(bannerMeta);
return itemStack;
}

private static DyeColor getDyeColor(Colors color) {
if (color == Colors.GRAY && MinecraftVersion.AQUATIC_UPDATE.atOrAbove()) {
// On 1.12 and below, this color is called "SILVER"
return DyeColor.valueOf("SILVER");
}
return DyeColor.valueOf(color.getColor());
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.rexcantor64.triton.spigot.banners;

import com.rexcantor64.triton.spigot.SpigotTriton;

public enum Colors {
BLACK("BLACK", 'a'), RED("RED", 'b'), GREEN("GREEN", 'c'), BROWN("BROWN", 'd'), BLUE(
"BLUE", 'e'), PURPLE("PURPLE", 'f'), CYAN("CYAN", 'g'), GRAY(SpigotTriton.asSpigot()
.getMcVersion() <= 12 ? "SILVER" : "LIGHT_GRAY",
"BLUE", 'e'), PURPLE("PURPLE", 'f'), CYAN("CYAN", 'g'), GRAY("LIGHT_GRAY",
'h'), DARK_GRAY("GRAY", 'i'), PINK("PINK", 'j'), LIME("LIME", 'k'), YELLOW(
"YELLOW", 'l'), LIGHT_BLUE("LIGHT_BLUE", 'm'), MAGENTA("MAGENTA",
'n'), ORANGE("ORANGE", 'o'), WHITE("WHITE", 'p');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
Expand Down Expand Up @@ -50,24 +51,31 @@ private AdvancementsPacketHandler() {
SERIALIZED_ADVANCEMENT_CLASS = null;
ADVANCEMENT_DISPLAY_FIELD = null;
}
val advancementDataPlayerClass = MinecraftReflection.getMinecraftClass("server.AdvancementDataPlayer", "AdvancementDataPlayer");
val advancementDataPlayerClass = MinecraftReflection.getMinecraftClass("server.PlayerAdvancements", "server.AdvancementDataPlayer", "AdvancementDataPlayer");
ENTITY_PLAYER_ADVANCEMENT_DATA_PLAYER_FIELD = Accessors.getFieldAccessor(MinecraftReflection.getEntityPlayerClass(), advancementDataPlayerClass, true);
ADVANCEMENT_DATA_PLAYER_REFRESH_METHOD = Accessors.getMethodAccessor(advancementDataPlayerClass, "b", MinecraftReflection.getEntityPlayerClass());

val advancementDataWorldClass = MinecraftReflection.getMinecraftClass("server.AdvancementDataWorld", "AdvancementDataWorld");
CRAFT_SERVER_GET_SERVER_METHOD = Accessors.getMethodAccessor(MinecraftReflection.getCraftBukkitClass("CraftServer"), "getServer");
MINECRAFT_SERVER_GET_ADVANCEMENT_DATA_METHOD = Accessors.getMethodAccessor(Arrays.stream(MinecraftReflection.getMinecraftServerClass().getMethods())
.filter(m -> m.getReturnType() == advancementDataWorldClass).findAny()
.orElseThrow(() -> new RuntimeException("Unable to find method getAdvancementData([])")));

if (getMcVersion() < 16) {
ADVANCEMENT_DATA_PLAYER_REFRESH_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(advancementDataPlayerClass)
.getMethodByReturnTypeAndParameters("flushDirty", void.class, MinecraftReflection.getEntityPlayerClass())
);

val advancementDataWorldClass = MinecraftReflection.getMinecraftClass("server.ServerAdvancementManager", "server.AdvancementDataWorld", "AdvancementDataWorld");
CRAFT_SERVER_GET_SERVER_METHOD = Accessors.getMethodAccessor(MinecraftReflection.getCraftServer(), "getServer");
MINECRAFT_SERVER_GET_ADVANCEMENT_DATA_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getMinecraftServerClass())
.getMethodByReturnTypeAndParameters("getAdvancements", advancementDataWorldClass)
);

if (MinecraftVersion.NETHER_UPDATE.atOrAbove()) { // 1.16+
// MC 1.16+
// Loading of achievements requires an AdvancementDataWorld method
ADVANCEMENT_DATA_PLAYER_LOAD_FROM_ADVANCEMENT_DATA_WORLD_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(advancementDataPlayerClass)
.getMethodByReturnTypeAndParameters("reload", void.class, advancementDataWorldClass)
);
} else {
// MC 1.12-1.15
// Loading of achievements only needs the method to be called without any parameters
ADVANCEMENT_DATA_PLAYER_LOAD_FROM_ADVANCEMENT_DATA_WORLD_METHOD = Accessors.getMethodAccessor(advancementDataPlayerClass, "b");
} else {
// MC 1.16+
// Loading of achievements requires an AdvancementDataWorld method
ADVANCEMENT_DATA_PLAYER_LOAD_FROM_ADVANCEMENT_DATA_WORLD_METHOD = Accessors.getMethodAccessor(advancementDataPlayerClass, "a", advancementDataWorldClass);
}
}

Expand Down Expand Up @@ -181,14 +189,14 @@ public void refreshAdvancements(SpigotLanguagePlayer languagePlayer) {

Bukkit.getScheduler().runTask(getMain().getLoader(), () -> {
// These are the same methods that are called from org.bukkit.craftbukkit.<version>.util.CraftMagicNumbers#loadAdvancement
if (getMcVersion() < 16) {
// MC 1.12-1.15
ADVANCEMENT_DATA_PLAYER_LOAD_FROM_ADVANCEMENT_DATA_WORLD_METHOD.invoke(advancementDataPlayer);
} else {
if (MinecraftVersion.NETHER_UPDATE.atOrAbove()) { // 1.16+
// MC 1.16+
val minecraftServer = CRAFT_SERVER_GET_SERVER_METHOD.invoke(Bukkit.getServer());
val advancementDataWorld = MINECRAFT_SERVER_GET_ADVANCEMENT_DATA_METHOD.invoke(minecraftServer);
ADVANCEMENT_DATA_PLAYER_LOAD_FROM_ADVANCEMENT_DATA_WORLD_METHOD.invoke(advancementDataPlayer, advancementDataWorld);
} else {
// MC 1.12-1.15
ADVANCEMENT_DATA_PLAYER_LOAD_FROM_ADVANCEMENT_DATA_WORLD_METHOD.invoke(advancementDataPlayer);
}
ADVANCEMENT_DATA_PLAYER_REFRESH_METHOD.invoke(advancementDataPlayer, nmsPlayer);
});
Expand Down
Loading
Loading