Skip to content

Commit

Permalink
Fixed: pSpigot hook and Carbon potion listeners
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed Jun 20, 2024
1 parent ae78c1c commit 6d8c88a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class CarbonSpigotListener implements IListener, Listener {
public void onExpire(PotionEffectExpireEvent event) {
RefinePotionExpireEvent custom = new RefinePotionExpireEvent(event.getEntity(), event.getEffect());
Bukkit.getPluginManager().callEvent(custom);

if (custom.isCancelled()) {
event.setCancelled(true);
}
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xyz.refinedev.api.spigot.equipment.EquipmentListener;
import xyz.refinedev.api.spigot.hider.EntityHider;
import xyz.refinedev.api.spigot.knockback.IKnockbackType;
import xyz.refinedev.api.spigot.util.VersionUtil;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -67,7 +68,12 @@ public void init() {
* @param teamFight {@link Boolean} should we register a listener for custom events
*/
public void init(boolean teamFight) {
this.type = SpigotType.get(); // We call the static method that checks for the supported spigot and returns the correct type
if (VersionUtil.MINOR_VERSION > 8) {
this.type = SpigotType.Default;
} else {
this.type = SpigotType.get(); // We call the static method that checks for the supported spigot and returns the correct type
}

this.knockback = type.getKnockbackType();

if (!teamFight || this.type == SpigotType.Default) return; // Don't do HCF events if not required
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package xyz.refinedev.api.spigot.util;

import org.bukkit.Bukkit;

public class VersionUtil {
public static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
public static final int MINOR_VERSION;

public VersionUtil() {
}

public static boolean canHex() {
return MINOR_VERSION >= 16;
}

static {
MINOR_VERSION = Integer.parseInt(VERSION.split("_")[1]);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package xyz.refinedev.api.spigot.knockback.impl.pspigot;

import me.scalebound.pspigot.KnockbackProfile;
import me.scalebound.pspigot.knockback.CraftKnockbackProfile;
import net.minecraft.server.v1_8_R3.EntityLiving;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.spigotmc.SpigotConfig;
import xyz.refinedev.api.spigot.knockback.IKnockbackType;

/**
Expand All @@ -22,17 +17,13 @@

public class pSpigotKnockback implements IKnockbackType {

private pSpigotKnockbackFix fix;

@Override
public void setKnockback(Player player, String knockback) {
KnockbackProfile craftKnockbackProfile = SpigotConfig.getKbProfileByName(knockback);
if (craftKnockbackProfile == null) {
craftKnockbackProfile = SpigotConfig.globalKbProfile;
}

CraftPlayer craftPlayer = (CraftPlayer) player;
EntityLiving living = craftPlayer.getHandle();
if (player.isOnline()) {
living.setKbProfile(craftKnockbackProfile);
if (fix == null) {
fix = new pSpigotKnockbackFix();
}
fix.setKnockback(player, knockback);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package xyz.refinedev.api.spigot.knockback.impl.pspigot;

import me.scalebound.pspigot.KnockbackProfile;
import net.minecraft.server.v1_8_R3.EntityLiving;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.spigotmc.SpigotConfig;

/**
* <p>
* This Project is property of Refine Development.<br>
* Copyright © 2024, All Rights Reserved.<br>
* Redistribution of this Project is not allowed.<br>
* </p>
*
* @author Drizzy
* @version SpigotAPI
* @since 3/6/2024
*/
public class pSpigotKnockbackFix {

public void setKnockback(Player player, String knockback) {
KnockbackProfile craftKnockbackProfile = SpigotConfig.getKbProfileByName(knockback);
if (craftKnockbackProfile == null) {
craftKnockbackProfile = SpigotConfig.globalKbProfile;
}

CraftPlayer craftPlayer = (CraftPlayer) player;
EntityLiving living = craftPlayer.getHandle();
if (player.isOnline()) {
living.setKbProfile(craftKnockbackProfile);
}
}

}

0 comments on commit 6d8c88a

Please sign in to comment.