Skip to content
Merged
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
/build/
/run/
/devbox.lock
/.idea/
/lib/
/.idea/
28 changes: 7 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ext {
minecraftVersion = project.findProperty('minecraftVersion') ?: '1.20.4'
javaVersion = JavaVersion.toVersion(project.findProperty('javaVersion') ?: '21')
pluginVersion = project.findProperty('pluginVersion') ?: '1.0.0'
donationApiVersion = project.findProperty('donationApiVersion') ?: '1.0.2'
}

repositories {
Expand All @@ -28,7 +27,7 @@ repositories {
}
maven {
// FoliaLib
url = 'https://nexuslite.gcnt.net/repos/other/'
url = 'https://repo.tcoded.com/releases/'
content {
includeGroup 'com.tcoded'
}
Expand All @@ -50,7 +49,7 @@ dependencies {

// Folia API
// https://jd.papermc.io/folia/1.20/
//compileOnly group: 'dev.folia', name: 'folia-api', version: "${project.minecraft_version}-R0.1-SNAPSHOT"
compileOnly group: 'dev.folia', name: 'folia-api', version: "${project.minecraftVersion}-R0.1-SNAPSHOT"

// https://www.jetbrains.com/help/idea/annotating-source-code.html
compileOnly group: 'org.jetbrains', name: 'annotations', version: "26.0.1"
Expand All @@ -59,10 +58,10 @@ dependencies {
shadow group: 'com.jcabi', name: 'jcabi-aspects', version: '0.25.1'

// https://github.com/TechnicallyCoded/FoliaLib
shadow group: 'com.tcoded', name: 'FoliaLib', version: "0.4.2"
shadow group: 'com.tcoded', name: 'FoliaLib', version: "0.5.1"

// DonationAPI (from GitHub releases, downloaded at build time)
compileOnly files("$rootDir/lib/DonationAPI-${donationApiVersion}.jar")
// DonationAPI (vendored jar)
compileOnly files("$rootDir/lib/DonationAPI-1.0.3.jar")
}

java {
Expand Down Expand Up @@ -116,18 +115,5 @@ tasks {
}
}

tasks.register('downloadDonationApi') {
doLast {
def libDir = file("$rootDir/lib")
if (!libDir.exists()) libDir.mkdirs()
def jar = file("$rootDir/lib/DonationAPI-${donationApiVersion}.jar")
if (!jar.exists()) {
println "Downloading DonationAPI-${donationApiVersion}.jar..."
def url = "https://github.com/zeroBzeroT/DonationAPI/releases/download/${donationApiVersion}/DonationAPI-${donationApiVersion}.jar"
ant.get(src: url, dest: jar, verbose: true)
}
}
}

//tasks.named('compileJava').configure { dependsOn(downloadDonationApi) }
//tasks.named('compileTestJava').configure { dependsOn(downloadDonationApi) }
// DonationAPI jar vendored under lib/. Bump the version below and replace the file
// when updating. See https://github.com/zeroBzeroT/DonationAPI for upstream.
7 changes: 2 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Plugin version
pluginVersion=1.0.3
pluginVersion=1.0.4

# Java version
javaVersion=21

# Minecraft version
minecraftVersion=1.20.4

# DonationAPI version
donationApiVersion=1.0.2
minecraftVersion=1.20.4
Binary file added lib/DonationAPI-1.0.3.jar
Binary file not shown.
12 changes: 7 additions & 5 deletions src/main/java/org/crayne/ptjdnc/NameColorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ private void registerCommands() {
}

private void registerPlayerOpEventTimerTask() {
// probably not the best solution for a player op event, but atleast it works? spigot or paper, please add an op event :sob:
// poll op status and dispatch per-player work to the players region thread for the actual profile update
foliaLib.getScheduler().runTimerAsync(() -> {
final Map<UUID, Boolean> difference = getUuidBooleanMap();

difference.forEach((uuid, wasOp) -> {
final Player player = Bukkit.getPlayer(uuid);
if (player == null) return;

final PlayerOpStatusChangeEvent opStatusChangeEvent = new PlayerOpStatusChangeEvent(player, wasOp, player.isOp(), true);
Bukkit.getPluginManager().callEvent(opStatusChangeEvent);
// folia: forceUpdate / callEvent must run on the player's region
foliaLib.getScheduler().runAtEntity(player, task -> {
if (!player.isOnline()) return;
final PlayerOpStatusChangeEvent opStatusChangeEvent = new PlayerOpStatusChangeEvent(player, wasOp, player.isOp(), true);
Bukkit.getPluginManager().callEvent(opStatusChangeEvent);
});
});
}, 20L, 20L);
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/crayne/ptjdnc/command/ItemColorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.crayne.ptjdnc.NameColorPlugin;
import org.crayne.ptjdnc.api.NameStyle;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -40,7 +43,7 @@ public boolean onCommand(@NotNull final CommandSender commandSender, @NotNull fi
}
final PlainTextComponentSerializer plainText = PlainTextComponentSerializer.plainText();
final ItemMeta meta = mainhandItem.getItemMeta();
final Component defaultDisplayComponent = Component.translatable(mainhandItem.translationKey());
final Component defaultDisplayComponent = defaultDisplayFor(mainhandItem, meta);
final Component displayName = Optional.ofNullable(meta.displayName()).orElse(defaultDisplayComponent);
final String defaultDisplayName = plainText.serialize(defaultDisplayComponent);

Expand All @@ -66,4 +69,17 @@ public boolean onCommand(@NotNull final CommandSender commandSender, @NotNull fi
p.sendMessage(deserialize("ic_success", s -> s));
return true;
}

private static Component defaultDisplayFor(@NotNull final ItemStack item, @NotNull final ItemMeta meta) {
if (meta instanceof SkullMeta skull) {
final OfflinePlayer owner = skull.getOwningPlayer();
if (owner != null && owner.getName() != null) {
return Component.text(owner.getName() + "'s Head");
}
}
if (meta instanceof BookMeta book && book.getTitle() != null) {
return Component.text(book.getTitle());
}
return Component.translatable(item.translationKey());
}
}