generated from Slimefun/Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/xmooncorp/magic8ball/utils/compatibility/VersionedParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.xmooncorp.magic8ball.utils.compatibility; | ||
|
||
import io.github.thebusybiscuit.slimefun4.libraries.paperlib.PaperLib; | ||
import org.bukkit.Particle; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.lang.reflect.Field; | ||
|
||
public class VersionedParticle { | ||
|
||
public static final Particle PORTAL; | ||
public static final Particle ENCHANTED_HIT; | ||
public static final Particle TOTEM_OF_UNDYING; | ||
public static final Particle CRIT; | ||
|
||
static { | ||
|
||
int version = PaperLib.getMinecraftVersion(); | ||
int patchVersion = PaperLib.getMinecraftPatchVersion(); | ||
boolean IS_MINECRAFT_1_20_5_OR_6 = (version == 20 && (patchVersion == 5 || patchVersion == 6)); | ||
|
||
// PORTAL was not renamed in 1.20.5 | ||
PORTAL = Particle.PORTAL; | ||
|
||
// CRIT was not renamed in 1.20.5 | ||
CRIT = Particle.CRIT; | ||
|
||
// CRIT_MAGIC is renamed to ENCHANTED_HIT in 1.20.5 | ||
ENCHANTED_HIT = IS_MINECRAFT_1_20_5_OR_6 | ||
? getKey("ENCHANTED_HIT") | ||
: getKey("CRIT_MAGIC"); | ||
|
||
// TOTEM is renamed to TOTEM_OF_UNDYING in 1.20.5 | ||
TOTEM_OF_UNDYING = IS_MINECRAFT_1_20_5_OR_6 | ||
? getKey("TOTEM_OF_UNDYING") | ||
: getKey("TOTEM"); | ||
} | ||
|
||
@Nullable | ||
private static Particle getKey(@Nonnull String key) { | ||
try { | ||
Field field = Particle.class.getDeclaredField(key); | ||
return (Particle) field.get(null); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
} |