Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying things #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.ArrayList;
import java.util.UUID;

import net.md_5.bungee.api.ChatMessageType;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.Vector;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacy;
import static net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText;

//Manages PlayerEditors and Player Events related to editing armorstands
Expand Down Expand Up @@ -115,35 +117,35 @@ void onArmorStandInteract(PlayerInteractAtEntityEvent event) {
//Attempt rename
if (player.getInventory().getItemInMainHand().getType() == Material.NAME_TAG && player.hasPermission("asedit.rename")) {
ItemStack nameTag = player.getInventory().getItemInMainHand();
final String name;
Component displayName;
if (nameTag.getItemMeta() != null && nameTag.getItemMeta().hasDisplayName()) {
String name = plainText().serialize(nameTag.getItemMeta().displayName());
if (name != null && player.hasPermission("asedit.rename.color")) {
displayName = legacy('&').deserialize(name);
} else {
displayName = Component.text(name);
}
name = nameTag.getItemMeta().getDisplayName().replace('&', ChatColor.COLOR_CHAR);
} else {
name = null;
displayName = null;
}

if (name == null) {
as.setCustomName(null);
if (displayName == null) {
as.customName(null);
as.setCustomNameVisible(false);
event.setCancelled(true);
} else if (!name.equals("")) { // nametag is not blank
} else {
event.setCancelled(true);

if ((player.getGameMode() != GameMode.CREATIVE)) {
if (nameTag.getAmount() > 1) {
nameTag.setAmount(nameTag.getAmount() - 1);
} else {
nameTag = new ItemStack(Material.AIR);
}
player.getInventory().setItemInMainHand(nameTag);
nameTag.subtract(1);
}

//minecraft will set the name after this event even if the event is cancelled.
//change it 1 tick later to apply formatting without it being overwritten
Bukkit.getScheduler().runTaskLater(plugin, () -> {
as.setCustomName(name);
as.setCustomNameVisible(true);
}, 1);
final Component finalDisplayName = displayName;
Bukkit.getScheduler().runTask(plugin, () -> {
as.customName(finalDisplayName);
as.setCustomNameVisible(true);
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import static net.kyori.adventure.text.format.TextColor.color;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -213,7 +214,7 @@ private ItemStack createIcon(ItemStack icon, String path, String command) {
private ItemStack createIcon(ItemStack icon, String path, String command, String option) {
ItemMeta meta = icon.getItemMeta();
meta.getPersistentDataContainer().set(ArmorStandEditorPlugin.instance().getIconKey(), PersistentDataType.STRING, "ase " + command);
meta.displayName(text(getIconName(path, option)));
meta.displayName(text(getIconName(path, option)).color(TextColor.color(0xFFFFFF)));
ArrayList < Component > loreList = new ArrayList < > ();
loreList.add(text(getIconDescription(path, option)));
meta.lore(loreList);
Expand Down
Loading