mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-23 10:35:22 +01:00
Added the ability to hide item nametags if the stack size is one.
Added the ability to hide the stack size if the stack size is one. Items will now show a colorless version of their custom display name (If available) in their nametag. The name format for items has been default changed to "&f{TYPE} [&6{AMT}x]". The square brackets are used to remove and show the amount when needed.
This commit is contained in:
parent
1df6491c7d
commit
827ddfea92
@ -4,6 +4,7 @@ import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -72,7 +73,7 @@ public class ItemListeners implements Listener {
|
||||
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(),
|
||||
instance.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_ITEM_PICKUP
|
||||
: Sound.valueOf("ITEM_PICKUP"), .2f, (float)(1 + Math.random()));
|
||||
: Sound.valueOf("ITEM_PICKUP"), .2f, (float) (1 + Math.random()));
|
||||
|
||||
updateInventory(event.getItem(), event.getPlayer().getInventory());
|
||||
}
|
||||
@ -101,7 +102,7 @@ public class ItemListeners implements Listener {
|
||||
private void updateAmount(Item item, int newAmount) {
|
||||
Material material = item.getItemStack().getType();
|
||||
String name = Methods.convertToInvisibleString("IS") +
|
||||
Methods.compileItemName(material, newAmount);
|
||||
compileItemName(item.getItemStack(), newAmount);
|
||||
|
||||
if (newAmount > 32) {
|
||||
item.setMetadata("US_AMT", new FixedMetadataValue(instance, newAmount));
|
||||
@ -113,6 +114,7 @@ public class ItemListeners implements Listener {
|
||||
|
||||
if (instance.getItemFile().getConfig().getBoolean("Items." + material + ".Has Hologram")
|
||||
&& Setting.ITEM_HOLOGRAMS.getBoolean()) {
|
||||
if (newAmount == 1 && !Setting.ITEM_HOLOGRAM_SINGLE.getBoolean()) return;
|
||||
item.setCustomName(name);
|
||||
item.setCustomNameVisible(true);
|
||||
}
|
||||
@ -125,4 +127,26 @@ public class ItemListeners implements Listener {
|
||||
return item.getItemStack().getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
private String compileItemName(ItemStack item, int amount) {
|
||||
String nameFormat = Setting.NAME_FORMAT_ITEM.getString();
|
||||
String displayName = Methods.formatText(UltimateStacker.getInstance().getItemFile().getConfig()
|
||||
.getString("Items." + item.getType().name() + ".Display Name"));
|
||||
|
||||
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName())
|
||||
displayName = ChatColor.stripColor(item.getItemMeta().getDisplayName());
|
||||
|
||||
nameFormat = nameFormat.replace("{TYPE}", displayName);
|
||||
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
|
||||
|
||||
if (amount == 1 && !Setting.SHOW_STACK_SIZE_SINGLE.getBoolean()) {
|
||||
nameFormat = nameFormat.replaceAll("\\[.*?]", "");
|
||||
} else {
|
||||
nameFormat = nameFormat.replace("[", "").replace("]", "");
|
||||
}
|
||||
|
||||
String info = Methods.convertToInvisibleString(Methods.insertSemicolon(String.valueOf(amount)) + ":");
|
||||
|
||||
return info + Methods.formatText(nameFormat).trim();
|
||||
}
|
||||
}
|
||||
|
@ -450,18 +450,6 @@ public class Methods {
|
||||
return info + Methods.formatText(nameFormat).trim();
|
||||
}
|
||||
|
||||
public static String compileItemName(Material type, int amount) {
|
||||
String nameFormat = Setting.NAME_FORMAT_ITEM.getString();
|
||||
String displayName = Methods.formatText(UltimateStacker.getInstance().getItemFile().getConfig().getString("Items." + type.name() + ".Display Name"));
|
||||
|
||||
nameFormat = nameFormat.replace("{TYPE}", displayName);
|
||||
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
|
||||
|
||||
String info = Methods.convertToInvisibleString(insertSemicolon(String.valueOf(amount)) + ":");
|
||||
|
||||
return info + Methods.formatText(nameFormat).trim();
|
||||
}
|
||||
|
||||
public static String compileEntityName(Entity entity, int amount) {
|
||||
String nameFormat = Setting.NAME_FORMAT_ENTITY.getString();
|
||||
String displayName = Methods.formatText(UltimateStacker.getInstance().getMobFile().getConfig().getString("Mobs." + entity.getType().name() + ".Display Name"));
|
||||
|
@ -106,13 +106,22 @@ public enum Setting {
|
||||
ITEM_HOLOGRAMS("Items.Holograms Enabled", true,
|
||||
"Should holograms be displayed above stacked items?"),
|
||||
|
||||
ITEM_HOLOGRAM_SINGLE("Items.Show Hologram For Single", true,
|
||||
"Should holograms be displayed above items when there is only a single",
|
||||
"item in the stack?"),
|
||||
|
||||
MAX_STACK_ITEMS("Items.Max Stack Size", 512,
|
||||
"The max stack size for items.",
|
||||
"Currently this can only be set to a max of 120."),
|
||||
|
||||
NAME_FORMAT_ITEM("Items.Name Format", "&f{TYPE} &6{AMT}x",
|
||||
NAME_FORMAT_ITEM("Items.Name Format", "&f{TYPE} [&6{AMT}x]",
|
||||
"The text displayed above a dropped item."),
|
||||
|
||||
SHOW_STACK_SIZE_SINGLE("Items.Show Stack Size For Single,", false,
|
||||
"When enabled stack sizes for a stack with a single item will",
|
||||
"not display the stack size. The stack size will be added",
|
||||
"for stacks containing two or more items."),
|
||||
|
||||
SPAWNERS_ENABLED("Spawners.Enabled", true,
|
||||
"Should spawners be stacked?"),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user