Skip to content
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
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 {
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 @@ -8,23 +8,19 @@

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);
if (FoliaChecker.isFolia()) {
logger.info("» Detected Folia environment. Using FoliaScheduler.");
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.
logger.info("» Detected Bukkit/Paper environment. Using BukkitScheduler.");
return new BukkitSchedulerImpl(plugin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.eternalcode.combat;

public final class FoliaChecker {

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

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

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

private static boolean detectFoliaEnvironment() {
try {
Class.forName(FOLIA_CLASS);
return true;
}
catch (ClassNotFoundException exception) {
return false;
}
}

}
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,16 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}

UUID targetId = attackedPlayerByPerson.getUniqueId();
UUID attackerId = attacker.getUniqueId();

if (
targetId.equals(attackerId)
&& FoliaChecker.isFolia()
) {
return;
}

if (this.config.combat.disableFlying) {
if (attackedPlayerByPerson.isFlying()) {
attackedPlayerByPerson.setFlying(false);
Expand All @@ -68,11 +79,9 @@ 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);
this.fightManager.tag(targetId, combatTime, CauseOfTag.PLAYER, attackerId);
this.fightManager.tag(attackerId, combatTime, CauseOfTag.PLAYER, targetId);
}


Expand Down