Created
September 25, 2013 02:05
-
-
Save aadnk/6694284 to your computer and use it in GitHub Desktop.
Using the new ItemRenamer API to hide lore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.comphenix.example; | |
import org.bukkit.Material; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.shininet.bukkit.itemrenamer.api.RenamerAPI; | |
import org.shininet.bukkit.itemrenamer.api.RenamerListener; | |
import org.shininet.bukkit.itemrenamer.api.RenamerPriority; | |
import org.shininet.bukkit.itemrenamer.api.RenamerSnapshot; | |
import com.google.common.collect.Lists; | |
public class ItemRenamerHideLore extends JavaPlugin { | |
@Override | |
public void onEnable() { | |
RenamerAPI.getAPI().addListener(this, RenamerPriority.POST_NORMAL, new RenamerListener() { | |
@Override | |
public void onItemsRenaming(Player player, RenamerSnapshot snapshot) { | |
for (ItemStack stack : snapshot) { | |
if (stack != null && stack.hasItemMeta()) { | |
ItemMeta meta = stack.getItemMeta(); | |
// Our marker - hide the lore | |
if (meta.hasLore() && meta.getLore().get(0).startsWith("[ExampleMod]")) { | |
meta.setLore(null); | |
stack.setItemMeta(meta); | |
} | |
} | |
} | |
} | |
}); | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
if (sender instanceof Player) { | |
Player player = (Player) sender; | |
ItemStack stack = new ItemStack(Material.GOLD_AXE); | |
ItemMeta meta = stack.getItemMeta(); | |
meta.setLore(Lists.newArrayList("[ExampleMod]Your custom data. Human readable?")); | |
stack.setItemMeta(meta); | |
// Testing | |
player.getInventory().addItem(stack); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment