refactor: enhance nametag action handling and improve lore management
This commit is contained in:
1 parent
167ed811b6
commit
3513477265
2 files changed
+28
-14
No files matched your search
-1
@@ -13,7 +13,6 @@ public class NametagAnvilListener extends ApplianceListener<SilenceNametag> {
|
||||
ItemStack resultItem = event.getResult();
|
||||
if(resultItem == null) return;
|
||||
|
||||
|
||||
AnvilView anvilView = event.getView();
|
||||
ItemStack inputItem = anvilView.getItem(0);
|
||||
if(inputItem == null || inputItem.getType() != Material.NAME_TAG) return;
|
||||
|
||||
+28
-13
@@ -27,14 +27,30 @@ public class SilenceNametag extends Appliance {
|
||||
new NamespacedKey(pluginName, "nametag-action");
|
||||
|
||||
ItemStack setNametagAction(ItemStack item, NametagActions action) {
|
||||
Objects.requireNonNull(item, "item must not be null");
|
||||
item.editPersistentDataContainer(pdc -> {
|
||||
pdc.set(
|
||||
nametagActionKey,
|
||||
PersistentDataType.INTEGER,
|
||||
action.ordinal()
|
||||
);
|
||||
Objects.requireNonNull(item, "Item must not be null.");
|
||||
setPersistentDataOfNametag(item, action);
|
||||
removeLoreOfNametag(item);
|
||||
setLoreOfNametag(item, action);
|
||||
return item;
|
||||
}
|
||||
|
||||
void setPersistentDataOfNametag(ItemStack item, NametagActions action){
|
||||
item.editPersistentDataContainer(pdc -> pdc.set(
|
||||
nametagActionKey,
|
||||
PersistentDataType.INTEGER,
|
||||
action.ordinal()
|
||||
));
|
||||
}
|
||||
|
||||
void removeLoreOfNametag(ItemStack item){
|
||||
item.editMeta(meta -> {
|
||||
List<Component> lore = meta.hasLore() ? new ArrayList<>(meta.lore()) : new ArrayList<>();
|
||||
lore.removeIf(line -> line.toString().contains("Dieser Name Tag"));
|
||||
meta.lore(lore);
|
||||
});
|
||||
}
|
||||
|
||||
void setLoreOfNametag(ItemStack item, NametagActions action){
|
||||
item.editMeta(meta -> {
|
||||
List<Component> lore = meta.hasLore() ? new ArrayList<>(meta.lore()) : new ArrayList<>();
|
||||
if(action == NametagActions.SILENCE) {
|
||||
@@ -45,23 +61,22 @@ public class SilenceNametag extends Appliance {
|
||||
meta.customName(null);
|
||||
meta.lore(lore);
|
||||
});
|
||||
return item;
|
||||
}
|
||||
|
||||
@Nullable NametagActions getNametagAction(ItemStack item) {
|
||||
Objects.requireNonNull(item, "item must not be null");
|
||||
Objects.requireNonNull(item, "Item must not be null.");
|
||||
return item.getPersistentDataContainer().get(nametagActionKey, PersistentDataType.INTEGER) == null
|
||||
? null
|
||||
: NametagActions.values()[item.getPersistentDataContainer().get(nametagActionKey, PersistentDataType.INTEGER)];
|
||||
}
|
||||
|
||||
public ItemStack createSilenceNametag(ItemStack oldResultItem, String renameText){
|
||||
public ItemStack createSilenceNametag(ItemStack ResultItem, String renameText){
|
||||
if(renameText.equals(muteString)) {
|
||||
return this.setNametagAction(oldResultItem, NametagActions.SILENCE);
|
||||
return this.setNametagAction(ResultItem, NametagActions.SILENCE);
|
||||
} else if(renameText.equals(unmuteString)) {
|
||||
return this.setNametagAction(oldResultItem, NametagActions.UNSILENCE);
|
||||
return this.setNametagAction(ResultItem, NametagActions.UNSILENCE);
|
||||
}
|
||||
return oldResultItem;
|
||||
return ResultItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user