Skip to content

Commit

Permalink
Added support for 1.20.5 and 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
RenanMsV committed Sep 21, 2024
1 parent 34e4793 commit 0164475
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
23 changes: 9 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xmooncorp</groupId>
<artifactId>Magic8Ball</artifactId>
<version>1.0.0</version>
<version>UNOFFICIAL</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<java.version>16</java.version>
<paper-spigot.version>1.20.6</paper-spigot.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spigot.version>1.20.4</spigot.version>
<paper.version>1.20.4</paper.version>
</properties>

<issueManagement>
Expand Down Expand Up @@ -48,7 +48,7 @@
</repositories>

<build>
<finalName>${project.name} v${project.version}</finalName>
<finalName>${project.name} ${project.version}</finalName>
<defaultGoal>clean package</defaultGoal>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>

Expand All @@ -59,6 +59,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<excludes>
<exclude>**/package-info.java</exclude>
</excludes>
Expand Down Expand Up @@ -89,17 +91,10 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>${paper.version}-R0.1-SNAPSHOT</version>
<version>${paper-spigot.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!--dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency-->

<dependency>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/xmooncorp/magic8ball/Magic8Ball.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public void onEnable() {

@Override
public void onDisable() {
// Logic for disabling the plugin...
instance = null;
log(localization().getString("console.addon-disabled"));
instance = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.xmooncorp.magic8ball.Magic8Ball;
import com.xmooncorp.magic8ball.core.ConfigBasedLocalization;
import com.xmooncorp.magic8ball.utils.LocationUtils;
import com.xmooncorp.magic8ball.utils.compatibility.VersionedParticle;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -58,17 +59,17 @@ public void sendRandom8BallMessage(@Nonnull Player player, @Nullable Block block
case "affirmative" -> {
color = "§a";
sound = Sound.ENTITY_VILLAGER_YES;
particle = Particle.TOTEM;
particle = VersionedParticle.TOTEM_OF_UNDYING;
}
case "noncommittal" -> {
color = "§7";
sound = Sound.ENTITY_VILLAGER_TRADE;
particle = Particle.CRIT;
particle = VersionedParticle.CRIT;
}
case "negative" -> {
color = "§c";
sound = Sound.ENTITY_VILLAGER_NO;
particle = Particle.CRIT_MAGIC;
particle = VersionedParticle.ENCHANTED_HIT;
}
}
sendActionBarMessage(player, color + randomMessage[1]);
Expand Down Expand Up @@ -113,6 +114,7 @@ private void playSoundAtLocation(@Nonnull World world, @Nonnull Location locatio
world.playSound(location, sound, 1, 0.65f);
}

@SuppressWarnings("unused")
@EventHandler()
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.LEFT_CLICK_AIR) return;
Expand Down
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;
}
}
}

0 comments on commit 0164475

Please sign in to comment.