Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ tasks {
downloadPlugins.modrinth("WorldGuard", Versions.WORLDGUARD)
downloadPlugins.modrinth("LuckPerms", "v${Versions.LUCKPERMS}-bukkit")
}

runPaper.folia.registerTask() {
Comment thread
CitralFlo marked this conversation as resolved.
Outdated
minecraftVersion("1.21.11")

downloadPlugins.modrinth("PacketEvents", "${Versions.PACKETEVENTS}+spigot")
}
}

tasks.shadowJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void onEnable() {
@Override
public void onDisable() {
EternalCombatProvider.deinitialize();
FoliaChecker.clearCache();
Comment thread
CitralFlo marked this conversation as resolved.
Outdated

if (this.liteCommands != null) {
this.liteCommands.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@
import com.eternalcode.commons.bukkit.scheduler.BukkitSchedulerImpl;
import com.eternalcode.commons.bukkit.scheduler.MinecraftScheduler;
import com.eternalcode.commons.folia.scheduler.FoliaSchedulerImpl;
import java.util.logging.Logger;
import org.bukkit.plugin.Plugin;

public final class CombatSchedulerAdapter {

private static final String FOLIA_CLASS = "io.papermc.paper.threadedregions.RegionizedServer";

private CombatSchedulerAdapter() {
throw new UnsupportedOperationException("This is an utility class and cannot be instantiated");
}

public static MinecraftScheduler getAdaptiveScheduler(Plugin plugin) {
Logger logger = plugin.getLogger();

try {
Class.forName(FOLIA_CLASS);
logger.info("» Detected Folia environment. Using FoliaScheduler.");
if (FoliaChecker.isFolia(plugin)) {
return new FoliaSchedulerImpl(plugin);
}
catch (ClassNotFoundException exception) {
logger.info("» Detected Bukkit/Paper environment. Using BukkitScheduler.");
return new BukkitSchedulerImpl(plugin);
}

Comment thread
CitralFlo marked this conversation as resolved.
return new BukkitSchedulerImpl(plugin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.eternalcode.combat;

import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;

public final class FoliaChecker {

private static final String FOLIA_CLASS = "io.papermc.paper.threadedregions.RegionizedServer";
private static Boolean cachedResult = null;
Comment thread
CitralFlo marked this conversation as resolved.
Outdated

private FoliaChecker() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static boolean isFolia() {
return detectFoliaEnvironment(null);
}

public static boolean isFolia(Plugin plugin) {
return detectFoliaEnvironment(plugin);
}

private static synchronized boolean detectFoliaEnvironment(@Nullable Plugin plugin) {
Comment thread
CitralFlo marked this conversation as resolved.
Outdated
Comment thread
CitralFlo marked this conversation as resolved.
Outdated
if (cachedResult != null) {
return cachedResult;
}

try {
Class.forName(FOLIA_CLASS);
cachedResult = true;
if (plugin != null) {
plugin.getLogger().info("» Detected Folia environment.");
}
}
catch (ClassNotFoundException exception) {
cachedResult = false;
if (plugin != null) {
plugin.getLogger().info("» Detected Bukkit/Paper environment.");
}
}
return cachedResult;
}

public static void clearCache() {
cachedResult = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public class PluginConfig extends OkaeriConfig {
@Comment("# \\____/ \\__\\___|_| |_| |_|\\__,_|_|\\____/\\___/|_| |_| |_|_.__/ \\__,_|\\__| ")
@Comment(" ")

@Comment({
" ",
"# This option does NOT affect other server versions.",
"# Options: true - users cannot tag them self when using ender pearls, arrows or other self inflicted damage",
"# false - players get tagged from all above damage sources used on themself"
})
public boolean stopFoliaFromSelfTagging = true;

@Comment({
" ",
"# Settings for the plugin.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.combat.fight.controller;

import com.eternalcode.combat.FoliaChecker;
import com.eternalcode.combat.WhitelistBlacklistMode;
import com.eternalcode.combat.config.implementation.PluginConfig;
import com.eternalcode.combat.fight.FightManager;
Expand Down Expand Up @@ -55,6 +56,17 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}

UUID attackedUniqueId = attackedPlayerByPerson.getUniqueId();
UUID attackerUniqueId = attacker.getUniqueId();
Comment thread
CitralFlo marked this conversation as resolved.
Outdated

if (
attackedUniqueId.equals(attackerUniqueId)
&& FoliaChecker.isFolia()
&& this.config.stopFoliaFromSelfTagging
) {
return;
}

Comment thread
CitralFlo marked this conversation as resolved.
Outdated
if (this.config.combat.disableFlying) {
if (attackedPlayerByPerson.isFlying()) {
attackedPlayerByPerson.setFlying(false);
Expand All @@ -68,8 +80,6 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}

Duration combatTime = this.config.settings.combatTimerDuration;
UUID attackedUniqueId = attackedPlayerByPerson.getUniqueId();
UUID attackerUniqueId = attacker.getUniqueId();

this.fightManager.tag(attackedUniqueId, combatTime, CauseOfTag.PLAYER, attackerUniqueId);
this.fightManager.tag(attackerUniqueId, combatTime, CauseOfTag.PLAYER, attackedUniqueId);
Expand Down