Skip to content

Commit 1f6c294

Browse files
committed
Updated WrappersAdapter to support newer versions
1 parent ec955d9 commit 1f6c294

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

wrappers/bukkit/legacy/src/test/java/it/fulminazzo/yagl/LegacyWrappersAdapterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void testPotionEffectToWPotionEffect() {
8383
@Test
8484
void testPotionConversion() {
8585
Potion expected = new Potion(PotionType.JUMP.name(), 1, true, false);
86-
org.bukkit.potion.Potion potion = WrappersAdapter.wPotionToPotion(expected);
86+
org.bukkit.potion.Potion potion = WrappersAdapter.wPotionToPotion(expected).getInternalPotion();
8787
assertEquals(expected, WrappersAdapter.potionToWPotion(potion));
8888
}
8989

wrappers/bukkit/src/main/java/it/fulminazzo/yagl/WrappersAdapter.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,22 +570,39 @@ private static <T> void playInternalSound(final @NotNull Player player, final @N
570570

571571
/**
572572
* Converts the given wrapper {@link Potion} to a Bukkit potion.
573+
* Because of Bukkit recent changes (1.20.6+), <code>org.bukkit.potion.Potion</code> does not exist anymore.
574+
* For retro-compatibility reasons, this class will return a {@link PotionWrapper} instead,
575+
* from which the actual <code>org.bukkit.potion.Potion</code> object can be retrieved.
573576
*
574577
* @param potion the potion
575-
* @return the potion
578+
* @return the wrapped potion
576579
*/
577-
public static @NotNull org.bukkit.potion.Potion wPotionToPotion(final @NotNull Potion potion) {
578-
return new org.bukkit.potion.Potion(EnumUtils.valueOf(PotionType.class, potion.getName()),
580+
public static @NotNull PotionWrapper wPotionToPotion(final @NotNull Potion potion) {
581+
return new PotionWrapper(EnumUtils.valueOf(PotionType.class, potion.getName()),
579582
potion.getLevel(), potion.isSplash(), potion.isExtended());
580583
}
581584

582585
/**
583586
* Converts the given Bukkit potion to a wrapper {@link Potion}.
587+
* Because of Bukkit recent changes (1.20.6+), <code>org.bukkit.potion.Potion</code> does not exist anymore.
588+
* For retro-compatibility reasons, this class allows a generic parameter to be passed,
589+
* but it will require an object of type org.bukkit.potion.Potion.
584590
*
585-
* @param potion the potion
591+
* @param <P> the type of the potion (org.bukkit.potion.Potion).
592+
* @param potion the bukkit potion
593+
* @return the potion
594+
*/
595+
public static <P> @NotNull Potion potionToWPotion(final @NotNull P potion) {
596+
return potionToWPotion(new PotionWrapper(potion));
597+
}
598+
599+
/**
600+
* Converts the given potion wrapper to a wrapper {@link Potion}.
601+
*
602+
* @param potion the potion wrapper
586603
* @return the potion
587604
*/
588-
public static @NotNull Potion potionToWPotion(final @NotNull org.bukkit.potion.Potion potion) {
605+
public static @NotNull Potion potionToWPotion(final @NotNull PotionWrapper potion) {
589606
return new Potion(potion.getType().name(), potion.getLevel(), potion.isSplash(), potion.hasExtendedDuration());
590607
}
591608

0 commit comments

Comments
 (0)