TDev_Tobi

InvisibleFrame.java

Apr 13th, 2021
470
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package tk.orzo.spigot.test;
  2.  
  3. import org.bukkit.Material;
  4. import org.bukkit.NamespacedKey;
  5. import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
  6. import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
  7. import org.bukkit.entity.EntityType;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.hanging.HangingBreakByEntityEvent;
  11. import org.bukkit.inventory.ItemStack;
  12. import org.bukkit.inventory.ShapedRecipe;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14.  
  15. import net.minecraft.server.v1_16_R3.NBTTagByte;
  16. import net.minecraft.server.v1_16_R3.NBTTagCompound;
  17.  
  18. public class InvisibleFrame implements Listener {
  19.    
  20.     private JavaPlugin plugin;
  21.    
  22.     public InvisibleFrame(JavaPlugin plugin) {
  23.         this.plugin = plugin;
  24.     }
  25.    
  26.     @EventHandler
  27.     public void onFrameBreak(HangingBreakByEntityEvent e) {
  28.         if (e.getEntity().getType() == EntityType.ITEM_FRAME) {
  29.             net.minecraft.server.v1_16_R3.Entity nmsEntity = ((CraftEntity) e.getEntity()).getHandle();
  30.             NBTTagCompound compound = new NBTTagCompound();
  31.             nmsEntity.d(compound);
  32.            
  33.             if (compound.getBoolean("Invisible")) {
  34.                 e.setCancelled(true);
  35.                 e.getEntity().getLocation().getWorld().dropItem(e.getEntity().getLocation(), getItemStack());
  36.                 e.getEntity().remove();
  37.             }
  38.         }
  39.     }
  40.    
  41.     public ShapedRecipe getRecipe() {
  42.         NamespacedKey key = new NamespacedKey(plugin, "InvisibleItemframe");
  43.         ShapedRecipe r = new ShapedRecipe(key , getItemStack());
  44.         r.shape("   ", " I ", "   ");
  45.         r.setIngredient( 'I', Material.ITEM_FRAME);
  46.         return r;
  47.     }
  48.    
  49.     public ItemStack getItemStack() {      
  50.         ItemStack item = new ItemStack(Material.ITEM_FRAME);
  51.         net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
  52.         NBTTagCompound compound = new NBTTagCompound();
  53.  
  54.  
  55.         NBTTagCompound entityTag = new NBTTagCompound();
  56.         entityTag.set("Invisible", NBTTagByte.a(true));
  57.         compound.set("EntityTag", entityTag);
  58.  
  59.  
  60.         nmsItem.setTag(compound);
  61.  
  62.  
  63.         return CraftItemStack.asBukkitCopy(nmsItem);
  64.     }
  65.  
  66. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×