-
-
Notifications
You must be signed in to change notification settings - Fork 9
GH-334 Folia pearl fix #334
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe consider renaming this to a more meaningful name, like |
||
|
|
||
| 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) { | ||
| 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 |
|---|---|---|
| @@ -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; | ||
|
|
@@ -55,6 +56,17 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | |
| return; | ||
| } | ||
|
|
||
| UUID attackedUniqueId = attackedPlayerByPerson.getUniqueId(); | ||
| UUID attackerUniqueId = attacker.getUniqueId(); | ||
|
|
||
| if ( | ||
| attackedUniqueId.equals(attackerUniqueId) | ||
| && FoliaChecker.isFolia() | ||
| && this.config.stopFoliaFromSelfTagging | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
|
Comment on lines
+59
to
+69
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can even make this anti-self-tagging thing an option even in a normal Paper environment, right? |
||
| if (this.config.combat.disableFlying) { | ||
| if (attackedPlayerByPerson.isFlying()) { | ||
| attackedPlayerByPerson.setFlying(false); | ||
|
|
@@ -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); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.