Skip to content

Paper only #238

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ repositories {
}

dependencies {
api(libs.adventure.bukkit)
api(libs.adventure.minimessage)
api(libs.adventure.configurate)

compileOnly(libs.spigot)
compileOnly(libs.paper)
}

tasks {
withType<ShadowJar> {
listOf(
"net.kyori",
"io.leangen",
).forEach { relocate(it, "at.helpch.chatchat.libs.$it") }

Expand Down
13 changes: 5 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[versions]
# Minecraft
spigot = "1.21.4-R0.1-SNAPSHOT"
paper = "1.21.7-R0.1-SNAPSHOT"

# Adventure
minimessage = "4.16.0"
adventure-platform = "4.3.4"
#adventure
adventure = "4.23.0"

# Other
configurate = "4.1.2"
Expand All @@ -19,12 +18,10 @@ griefprevention = "16.18.1"

[libraries]
# Minecraft
spigot = { module = "org.spigotmc:spigot-api", version.ref = "spigot" }
paper = { module = "io.papermc.paper:paper-api", version.ref = "paper" }

# Adventure
adventure-bukkit = { module = "net.kyori:adventure-platform-bukkit", version.ref = "adventure-platform" }
adventure-configurate = { module = "net.kyori:adventure-serializer-configurate4", version.ref = "adventure-platform" }
adventure-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "minimessage" }
adventure-configurate = { module = "net.kyori:adventure-serializer-configurate4", version.ref = "adventure" }

# Other
configurate = { module = "org.spongepowered:configurate-yaml", version.ref = "configurate" }
Expand Down
9 changes: 6 additions & 3 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import dev.triumphteam.helper.implementation
import dev.triumphteam.helper.papi
import dev.triumphteam.helper.triumphSnapshots
import xyz.jpenilla.resourcefactory.bukkit.Permission
Expand Down Expand Up @@ -33,13 +34,16 @@ dependencies {
implementation(projects.chatChatApi)

implementation(libs.triumph.cmds)
implementation(libs.adventure.configurate)
implementation(libs.configurate)
implementation(libs.bstats)

compileOnly(libs.spigot)
compileOnly(libs.paper)
compileOnly(libs.papi)
compileOnly(libs.towny)
compileOnly(libs.essentials)
compileOnly(libs.essentials) {
exclude("org.spigotmc")
}
compileOnly(libs.discordsrv)
compileOnly(libs.supervanish)
compileOnly(libs.griefprevention)
Expand Down Expand Up @@ -215,7 +219,6 @@ sourceSets.main {
tasks {
withType<ShadowJar> {
listOf(
"net.kyori",
"dev.triumphteam",
"org.spongepowered",
"io.leangen",
Expand Down
9 changes: 0 additions & 9 deletions plugin/src/main/java/at/helpch/chatchat/ChatChatPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey;
import dev.triumphteam.cmd.core.message.MessageKey;
import dev.triumphteam.cmd.core.suggestion.SuggestionKey;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimpleBarChart;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -78,8 +77,6 @@ public final class ChatChatPlugin extends JavaPlugin {
private @NotNull
final ChatChatAPIImpl api = new ChatChatAPIImpl(this);


private static BukkitAudiences audiences;
private BukkitCommandManager<User> commandManager;
private BukkitTask dataSaveTask;

Expand All @@ -92,7 +89,6 @@ public void onLoad() {

@Override
public void onEnable() {
audiences = BukkitAudiences.create(this);

commandManager = BukkitCommandManager.create(this,
usersHolder::getUser,
Expand Down Expand Up @@ -149,7 +145,6 @@ public void onDisable() {
hookManager().muteHooks().forEach(Hook::disable);
getServer().getServicesManager().unregisterAll(this);

audiences.close();
if (!dataSaveTask.isCancelled()) dataSaveTask.cancel();

for (final Player player : Bukkit.getOnlinePlayers()) {
Expand Down Expand Up @@ -179,10 +174,6 @@ public static long cacheDuration() {
return channelTypeRegistryImpl;
}

public static @NotNull BukkitAudiences audiences() {
return audiences;
}

public @NotNull BukkitCommandManager<User> commandManager() {
return commandManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public boolean canSee(@NotNull final User target) {

@Override
public @NotNull Audience audience() {
return ChatChatPlugin.audiences().player(uuid);
return player().map(player -> (Audience) player).orElse(Audience.empty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import at.helpch.chatchat.format.ChatFormat;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void chatState(final boolean enabled) {

@Override
public @NotNull Audience audience() {
return ChatChatPlugin.audiences().console();
return Bukkit.getConsoleSender();
}

@Override
Expand Down
86 changes: 10 additions & 76 deletions plugin/src/main/java/at/helpch/chatchat/util/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,31 @@
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public final class ItemUtils {

private static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacySection();
private static Method translationKeyMethod;
private static final Map<Predicate<Material>, Function<Material, String>> translations = new LinkedHashMap<>();

static {
if (VersionHelper.IS_PAPER) {
try {
//noinspection JavaReflectionMemberAccess
ItemUtils.translationKeyMethod = Material.class.getMethod("translationKey"); // paper method
} catch (NoSuchMethodException ignored) {
}
}

translations.put(
__ -> VersionHelper.IS_PAPER && translationKeyMethod != null,
material -> {
try {
return (String) translationKeyMethod.invoke(material);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
return "null." + material.getKey().getKey();
}
}
);
translations.put(
material -> VersionHelper.HAS_SMITHING_TEMPLATE && material.name().endsWith("SMITHING_TEMPLATE"),
__ -> "item.minecraft.smithing_template"
);
translations.put(
Material::isItem,
material -> "item.minecraft." + material.getKey().getKey()
);
translations.put(
Material::isBlock,
material -> "block.minecraft." + material.getKey().getKey()
);
}

private ItemUtils() {
throw new AssertionError("Util classes are not to be instantiated!");
}

private static @NotNull Component getTranslation(@NotNull final Material material) {
for (final var entry : translations.entrySet()) {
if (entry.getKey().test(material)) {
return Component.translatable(entry.getValue().apply(material));
}
}

return Component.translatable("null." + material.getKey().getKey());
}

public static @NotNull TagResolver.@NotNull Single createItemPlaceholder(
@NotNull final String itemFormat,
@NotNull final String itemFormatInfo,
@NotNull final ItemStack item
) {
final var materialName = getTranslation(item.getType());
final var materialName = Component.translatable(item.getType().translationKey());
final var itemPlaceholder = Placeholder.component("item", materialName);
final var amountPlaceholder = Placeholder.component("amount", Component.text(item.getAmount()));

Expand Down Expand Up @@ -118,7 +65,7 @@ private ItemUtils() {
enchants = meta.getEnchants().entrySet()
.stream()
.map(entry -> formattedEnchantment(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
.toList();
}

var lore = Collections.<Component>emptyList();
Expand Down Expand Up @@ -172,27 +119,14 @@ private ItemUtils() {
return enchantmentName.append(Component.text(" I"));
}

@NotNull final String roman;
switch (level) {
case 1:
roman = "I";
break;
case 2:
roman = "II";
break;
case 3:
roman = "III";
break;
case 4:
roman = "IV";
break;
case 5:
roman = "V";
break;
default:
roman = level.toString();
break;
}
@NotNull final String roman = switch (level) {
case 1 -> "I";
case 2 -> "II";
case 3 -> "III";
case 4 -> "IV";
case 5 -> "V";
default -> level.toString();
};

return enchantmentName.append(Component.space()).append(Component.text(roman));
}
Expand Down
27 changes: 0 additions & 27 deletions plugin/src/main/java/at/helpch/chatchat/util/VersionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,8 @@ public final class VersionHelper {

public static final int CURRENT_VERSION = getCurrentVersion();

public static final boolean IS_PAPER = checkPaper();

public static final int V1_13_2 = 1132;
public static final int V1_14_4 = 1144;
public static final int V1_15_2 = 1152;
public static final int V1_16_5 = 1165;
public static final int V1_17_1 = 1171;
public static final int V1_18_2 = 1182;
public static final int V1_19_0 = 1190;

public static final int V1_20_0 = 1200;

public static boolean HAS_SMITHING_TEMPLATE = CURRENT_VERSION >= V1_20_0;

/**
* Check if the server has access to the Paper API
* Taken from <a href="https://github.com/PaperMC/PaperLib">PaperLib</a>
*
* @return True if on Paper server (or forks), false anything else
*/
private static boolean checkPaper() {
try {
Class.forName("com.destroystokyo.paper.PaperConfig");
return true;
} catch (ClassNotFoundException ignored) {
return false;
}
}

/**
* Gets the current server version
*
Expand Down
Loading