Skip to content

Commit

Permalink
Fixed NoSuchMethodError when shooting or dropping arrows (fixes #535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed May 2, 2024
1 parent a4c37da commit 053f7d5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 16 deletions.
21 changes: 21 additions & 0 deletions src/main/java/net/coreprotect/bukkit/BukkitAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
Expand All @@ -22,6 +23,10 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;

import net.coreprotect.config.ConfigHandler;
import net.coreprotect.utility.Util;
Expand Down Expand Up @@ -263,4 +268,20 @@ public boolean isSignFront(SignChangeEvent event) {
return true;
}

@Override
public ItemStack getArrowMeta(Arrow arrow, ItemStack itemStack) {
PotionData data = arrow.getBasePotionData();
if (data.getType() != PotionType.UNCRAFTABLE) {
itemStack = new ItemStack(Material.TIPPED_ARROW);
PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
meta.setBasePotionData(data);
for (PotionEffect effect : arrow.getCustomEffects()) {
meta.addCustomEffect(effect, false);
}
itemStack.setItemMeta(meta);
}

return itemStack;
}

}
3 changes: 3 additions & 0 deletions src/main/java/net/coreprotect/bukkit/BukkitInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
Expand Down Expand Up @@ -84,4 +85,6 @@ public interface BukkitInterface {

public boolean isSignFront(SignChangeEvent event);

public ItemStack getArrowMeta(Arrow arrow, ItemStack itemStack);

}
22 changes: 22 additions & 0 deletions src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import org.bukkit.block.ChiseledBookshelf;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.entity.Arrow;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;

import net.coreprotect.model.BlockGroup;

Expand Down Expand Up @@ -254,4 +258,22 @@ public boolean isSignFront(SignChangeEvent event) {
return event.getSide().equals(Side.FRONT);
}

@Override
public ItemStack getArrowMeta(Arrow arrow, ItemStack itemStack) {
PotionType potionType = arrow.getBasePotionType();
Color color = arrow.getColor();
if (potionType != null || color != null) {
itemStack = new ItemStack(Material.TIPPED_ARROW);
PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
meta.setBasePotionType(potionType);
meta.setColor(color);
for (PotionEffect effect : arrow.getCustomEffects()) {
meta.addCustomEffect(effect, false);
}
itemStack.setItemMeta(meta);
}

return itemStack;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.coreprotect.listener.player.PlayerInteractListener;
import net.coreprotect.listener.player.PlayerItemBreakListener;
import net.coreprotect.listener.player.PlayerJoinListener;
import net.coreprotect.listener.player.PlayerPickupArrowListener;
import net.coreprotect.listener.player.PlayerQuitListener;
import net.coreprotect.listener.player.PlayerTakeLecternBookListener;
import net.coreprotect.listener.player.ProjectileLaunchListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.coreprotect.listener;
package net.coreprotect.listener.player;

import org.bukkit.Material;
import org.bukkit.entity.AbstractArrow;
Expand All @@ -8,11 +8,8 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;

import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.consumer.Queue;
import net.coreprotect.listener.entity.EntityPickupItemListener;

Expand All @@ -31,16 +28,7 @@ public static ItemStack getArrowType(AbstractArrow arrow) {

if (arrow instanceof Arrow) {
Arrow arrowEntity = (Arrow) arrow;
PotionData data = arrowEntity.getBasePotionData();
if (data.getType() != PotionType.UNCRAFTABLE) {
itemStack = new ItemStack(Material.TIPPED_ARROW);
PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
meta.setBasePotionData(data);
for (PotionEffect effect : arrowEntity.getCustomEffects()) {
meta.addCustomEffect(effect, false);
}
itemStack.setItemMeta(meta);
}
itemStack = BukkitAdapter.ADAPTER.getArrowMeta(arrowEntity, itemStack);
}

return itemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Queue;
import net.coreprotect.database.logger.ItemLogger;
import net.coreprotect.listener.PlayerPickupArrowListener;
import net.coreprotect.utility.Util;

public final class ProjectileLaunchListener extends Queue implements Listener {
Expand Down

0 comments on commit 053f7d5

Please sign in to comment.