Skip to content
Closed
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
8 changes: 7 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repositories {
maven("https://repo.codemc.org/repository/maven-public")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://jitpack.io")
maven("https://repo.tcoded.com/releases")
}

dependencies {
Expand All @@ -31,6 +32,8 @@ dependencies {
implementation(libs.commons.lang3)
implementation(libs.nbt.api)
implementation(libs.holoeasy)
implementation(libs.folialib)
implementation(libs.bstats)
}

tasks {
Expand Down Expand Up @@ -60,6 +63,8 @@ tasks {
relocate("org.holoeasy", "fr.aerwyn81.libs.holoEasy")
relocate("org.json", "fr.aerwyn81.libs.json")
relocate("org.slf4j", "fr.aerwyn81.libs.slf4j")
relocate("com.tcoded.folialib", "fr.aerwyn81.libs.foliaLib")
relocate("org.bstats", "fr.aerwyn81.libs.bstats")

if (project.hasProperty("cd"))
archiveFileName.set("HeadBlocks.jar")
Expand All @@ -68,7 +73,7 @@ tasks {

destinationDirectory.set(file(System.getenv("outputDir") ?: "$rootDir/build/"))

minimize()
//minimize()
}
}

Expand All @@ -81,6 +86,7 @@ bukkit {
softDepend = listOf("PlaceholderAPI", "HeadDatabase", "packetevents")
version = project.version.toString()
website = "https://just2craft.fr"
foliaSupported = true

commands {
register("headblocks") {
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gson = "2.11.0"
commons-lang3 = "3.12.0"
nbt-api = "2.15.3"
holoeasy = "master-SNAPSHOT"
folialib = "0.5.1"
bstats = "3.1.0"

# Build Plugins
shadow = "8.3.5"
Expand All @@ -32,6 +34,8 @@ gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang3" }
nbt-api = { module = "de.tr7zw:item-nbt-api", version.ref = "nbt-api" }
holoeasy = { module = "com.github.AerWyn81.holoeasy:holoeasy-core", version.ref = "holoeasy" }
folialib = { module = "com.tcoded:FoliaLib", version.ref = "folialib" }
bstats = { module = "org.bstats:bstats-bukkit", version.ref = "bstats" }

[plugins]
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/fr/aerwyn81/headblocks/HeadBlocks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.aerwyn81.headblocks;

import com.tcoded.folialib.FoliaLib;
import com.tcoded.folialib.impl.PlatformScheduler;
import com.tcoded.folialib.util.FoliaLibOptions;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import fr.aerwyn81.headblocks.commands.HBCommandExecutor;
Expand All @@ -14,7 +17,9 @@
import fr.aerwyn81.headblocks.utils.bukkit.VersionUtils;
import fr.aerwyn81.headblocks.utils.config.ConfigUpdater;
import fr.aerwyn81.headblocks.utils.internal.LogUtil;
import fr.aerwyn81.headblocks.utils.internal.Metrics;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bstats.charts.SingleLineChart;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.holoeasy.HoloEasy;
Expand All @@ -27,6 +32,7 @@
public final class HeadBlocks extends JavaPlugin {

private static HeadBlocks instance;
private static FoliaLib foliaLib;
public static boolean isPlaceholderApiActive;
public static boolean isReloadInProgress;
public static boolean isHeadDatabaseActive;
Expand Down Expand Up @@ -71,7 +77,9 @@ public void onLoad() {
@Override
public void onEnable() {
instance = this;

FoliaLibOptions options = new FoliaLibOptions();
options.disableNotifications();
foliaLib = new FoliaLib(this, options);
initializeExternals();

LogUtil.info("HeadBlocks initializing...");
Expand Down Expand Up @@ -122,30 +130,30 @@ public void onEnable() {

if (ConfigService.isMetricsEnabled()) {
var m = new Metrics(this, 15495);
m.addCustomChart(new Metrics.SimplePie("database_type", StorageService::selectedStorageType));
m.addCustomChart(new Metrics.SingleLineChart("heads", () -> HeadService.getChargedHeadLocations().size()));
m.addCustomChart(new Metrics.SimplePie("lang", LanguageService::getLanguage));
m.addCustomChart(new Metrics.SimplePie("feat_order", () -> {
m.addCustomChart(new SimplePie("database_type", StorageService::selectedStorageType));
m.addCustomChart(new SingleLineChart("heads", () -> HeadService.getChargedHeadLocations().size()));
m.addCustomChart(new SimplePie("lang", LanguageService::getLanguage));
m.addCustomChart(new SimplePie("feat_order", () -> {
var anyOrder = HeadService.getChargedHeadLocations().stream().anyMatch(h -> h.getOrderIndex() != -1);
return anyOrder ? "True" : "False";
}));
m.addCustomChart(new Metrics.SimplePie("feat_hit", () -> {
m.addCustomChart(new SimplePie("feat_hit", () -> {
var anyHit = HeadService.getChargedHeadLocations().stream().anyMatch(h -> h.getHitCount() != -1);
return anyHit ? "True" : "False";
}));
m.addCustomChart(new Metrics.SimplePie("feat_hint_sound", () -> {
m.addCustomChart(new SimplePie("feat_hint_sound", () -> {
var anyHit = HeadService.getChargedHeadLocations().stream().anyMatch(HeadLocation::isHintSoundEnabled);
return anyHit ? "True" : "False";
}));
m.addCustomChart(new Metrics.SimplePie("feat_hint_actionBarMessage", () -> {
m.addCustomChart(new SimplePie("feat_hint_actionBarMessage", () -> {
var anyHit = HeadService.getChargedHeadLocations().stream().anyMatch(HeadLocation::isHintActionBarEnabled);
return anyHit ? "True" : "False";
}));
m.addCustomChart(new Metrics.SimplePie("feat_hint_rewards", () -> {
m.addCustomChart(new SimplePie("feat_hint_rewards", () -> {
var anyHit = HeadService.getChargedHeadLocations().stream().anyMatch(h -> !h.getRewards().isEmpty());
return anyHit ? "True" : "False";
}));
m.addCustomChart(new Metrics.SimplePie("feat_hide_heads", () -> ConfigService.hideFoundHeads() ? "True" : "False"));
m.addCustomChart(new SimplePie("feat_hide_heads", () -> ConfigService.hideFoundHeads() ? "True" : "False"));
}

LogUtil.info("HeadBlocks successfully loaded!");
Expand All @@ -170,7 +178,7 @@ public void onDisable() {
HeadService.clearHeadMoves();
GuiService.clearCache();

Bukkit.getScheduler().cancelTasks(this);
foliaLib.getScheduler().cancelAllTasks();

packetEventsHook.unload();

Expand Down Expand Up @@ -198,13 +206,17 @@ public void startInternalTaskTimer() {
return;
}

globalTask.runTaskTimer(this, 0, ConfigService.getDelayGlobalTask());
globalTask.runAsyncRepeating(0, ConfigService.getDelayGlobalTask());
}

public static HeadBlocks getInstance() {
return instance;
}

public static PlatformScheduler getScheduler() {
return foliaLib.getScheduler();
}

public HeadDatabaseHook getHeadDatabaseHook() {
return headDatabaseHook;
}
Expand Down
54 changes: 28 additions & 26 deletions src/main/java/fr/aerwyn81/headblocks/commands/list/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -371,25 +372,25 @@ private void handleResyncLocations(CommandSender sender) {
.replaceAll("%count%", String.valueOf(headLocations.size())));

// Run on main thread since we're modifying blocks
Bukkit.getScheduler().runTask(HeadBlocks.getInstance(), () -> {
int restored = 0;
int textureApplied = 0;
int skipped = 0;
int failed = 0;

for (var headLocation : headLocations) {
var location = headLocation.getLocation();
AtomicInteger restored = new AtomicInteger();
AtomicInteger textureApplied = new AtomicInteger();
AtomicInteger skipped = new AtomicInteger();
AtomicInteger failed = new AtomicInteger();

for (var headLocation : headLocations) {
var location = headLocation.getLocation();
HeadBlocks.getScheduler().runAtLocation(location, (task) -> {
if (location == null || location.getWorld() == null) {
failed++;
continue;
failed.getAndIncrement();
return;
}

try {
var texture = StorageService.getHeadTexture(headLocation.getUuid());
if (texture == null || texture.isEmpty()) {
LogUtil.warning("Resync locations: No texture found for head {0}", headLocation.getUuid());
failed++;
continue;
failed.getAndIncrement();
return;
}

var block = location.getBlock();
Expand All @@ -398,36 +399,37 @@ private void handleResyncLocations(CommandSender sender) {
// Block is already a head, check if texture matches
var currentTexture = HeadUtils.getHeadTexture(block);
if (texture.equals(currentTexture)) {
skipped++;
continue;
skipped.getAndIncrement();
return;
}

if (HeadUtils.applyTextureToBlock(block, texture)) {
textureApplied++;
textureApplied.getAndIncrement();
} else {
failed++;
failed.getAndIncrement();
}
} else {
// Block is not a head, create it
block.setType(Material.PLAYER_HEAD);
if (HeadUtils.applyTextureToBlock(block, texture)) {
restored++;
restored.getAndIncrement();
} else {
failed++;
failed.getAndIncrement();
}
}
} catch (InternalException e) {
LogUtil.error("Resync locations: Error processing head {0}: {1}", headLocation.getUuid(), e.getMessage());
failed++;
failed.getAndIncrement();
}
}

sender.sendMessage(LanguageService.getMessage("Messages.ResyncLocationsSuccess")
.replaceAll("%restored%", String.valueOf(restored))
.replaceAll("%textureApplied%", String.valueOf(textureApplied))
.replaceAll("%skipped%", String.valueOf(skipped))
.replaceAll("%failed%", String.valueOf(failed)));
});
sender.sendMessage(LanguageService.getMessage("Messages.ResyncLocationsSuccess")
.replaceAll("%restored%", String.valueOf(restored.get()))
.replaceAll("%textureApplied%", String.valueOf(textureApplied.get()))
.replaceAll("%skipped%", String.valueOf(skipped.get()))
.replaceAll("%failed%", String.valueOf(failed.get())));
});
}

}

public static List<UUID> pickRandomUUIDs(List<UUID> uuidList, int numberOfElements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean perform(CommandSender sender, String[] args) {

sender.sendMessage(MessageUtils.colorize(LanguageService.getMessage("Messages.ExportInProgress")));

Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAsync((task) -> {
try {
ExportSQLHelper.generateFile(typeDatabase, fileName);
Thread.sleep(10000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void execute(Player player, HeadLocation headLocation) {
var value = parsedValue;
switch (type) {
case MESSAGE -> player.sendMessage(parsedValue);
case COMMAND -> Bukkit.getScheduler().runTaskLater(plugin, () ->
case COMMAND -> HeadBlocks.getScheduler().runLater(() ->
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), value), 1L);
case BROADCAST -> plugin.getServer().broadcastMessage(parsedValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void hide(Player player) {

@Override
public void delete() {
Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAsync((task) -> {
var pool = getPool();
if (pool != null) {
hologram.hide(getPool());
Expand All @@ -42,7 +42,7 @@ public void delete() {
public IHologram create(String name, Location location, List<String> lines) {
hologram = new Hologram(HeadBlocks.getInstance().getHoloEasyLib(), location);

Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAsync((task) -> {
ConfigService.getHologramsAdvancedLines().forEach(l -> hologram.getLines().add(
new DisplayTextLine(hologram, player ->
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public boolean isVisible(Player player) {
}

public void refresh(Player player) {
Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAsync((task) -> {
for (Line<?> line : hologram.getLines()) {
line.update(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void handleChunkData(PacketSendEvent event, Player player) {
}

// Schedule a task to send block changes after the chunk is loaded on the client side
Bukkit.getScheduler().runTaskLater(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAtEntityLater(player, () -> {
for (var headUuid : headsInChunk) {
var headLocation = HeadService.getHeadByUUID(headUuid);
if (headLocation != null && player.getWorld().equals(headLocation.getLocation().getWorld())) {
Expand Down Expand Up @@ -143,7 +143,7 @@ public void onPlayerJoin(Player player) {
}
playerChunkHeadsCache.put(player.getUniqueId(), chunkHeadsMap);

Bukkit.getScheduler().runTaskLater(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAtEntityLater(player, (task) -> {
for (var headUuid : foundHeads) {
var headLocation = HeadService.getHeadByUUID(headUuid);
if (headLocation != null && player.getWorld().equals(headLocation.getLocation().getWorld())) {
Expand Down Expand Up @@ -211,7 +211,7 @@ public void removeFoundHead(Player player, UUID headUuid) {
}

if (player.getWorld().equals(loc.getWorld())) {
Bukkit.getScheduler().runTaskLater(HeadBlocks.getInstance(), () -> {
HeadBlocks.getScheduler().runAtLocationLater(loc, () -> {
player.sendBlockChange(loc, loc.getBlock().getBlockData());
var world = loc.getWorld();
if (world != null) {
Expand All @@ -234,20 +234,20 @@ public void showAllPreviousHeads(Player player) {
playerChunkHeadsCache.remove(player.getUniqueId());

if (previouslyHiddenHeads != null && !previouslyHiddenHeads.isEmpty()) {
Bukkit.getScheduler().runTaskLater(HeadBlocks.getInstance(), () -> {
for (var headUuid : previouslyHiddenHeads) {
var headLocation = HeadService.getHeadByUUID(headUuid);
if (headLocation != null && player.getWorld().equals(headLocation.getLocation().getWorld())) {
var location = headLocation.getLocation();
for (var headUuid : previouslyHiddenHeads) {
var headLocation = HeadService.getHeadByUUID(headUuid);
if (headLocation != null && player.getWorld().equals(headLocation.getLocation().getWorld())) {
var location = headLocation.getLocation();
HeadBlocks.getScheduler().runAtLocationLater(location, () -> {
player.sendBlockChange(location, location.getBlock().getBlockData());
var world = location.getWorld();
if (world != null) {
var blockState = location.getBlock().getState();
blockState.update(true, false);
}
}
}, 1L);
}
}, 1L);
}
}
}

Expand Down
Loading