Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f415b9aba | ||
|
|
aebd7f7bc8 | ||
|
|
410658259d | ||
|
|
1dbc9b29a3 | ||
|
|
b1c92310cb | ||
|
|
15ee6ee79e | ||
|
|
dd2d71d754 | ||
|
|
3221450cde | ||
|
|
f615dc867a | ||
|
|
673bae4d50 | ||
|
|
6ad9407cb4 |
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.silenceNametag;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.view.AnvilView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NametagAnvilListener extends ApplianceListener<SilenceNametag> {
|
||||||
|
@EventHandler
|
||||||
|
public void onAnvilRename(PrepareAnvilEvent event){
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
if(!SilenceNametag.muteString.equals(anvilView.getRenameText())
|
||||||
|
&& !SilenceNametag.unmuteString.equals(anvilView.getRenameText())) return;
|
||||||
|
|
||||||
|
event.setResult(this.getAppliance().createSilenceNametag(resultItem, anvilView.getRenameText()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.silenceNametag;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class SilenceNametag extends Appliance {
|
||||||
|
public static final String pluginName = "silence-nametag";
|
||||||
|
public static final String muteString = "@verstummen";
|
||||||
|
public static final String unmuteString = "@entstummen";
|
||||||
|
|
||||||
|
public enum NametagActions {
|
||||||
|
SILENCE,
|
||||||
|
UNSILENCE
|
||||||
|
}
|
||||||
|
|
||||||
|
NamespacedKey nametagActionKey =
|
||||||
|
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()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
item.editMeta(meta -> {
|
||||||
|
List<Component> lore = meta.hasLore() ? new ArrayList<>(meta.lore()) : new ArrayList<>();
|
||||||
|
if(action == NametagActions.SILENCE) {
|
||||||
|
lore.add(Component.text("Dieses Namensschild verstummt Mobs."));
|
||||||
|
} else if (action == NametagActions.UNSILENCE){
|
||||||
|
lore.add(Component.text("Dieses Namensschild entstummt Mobs."));
|
||||||
|
}
|
||||||
|
meta.customName(null);
|
||||||
|
meta.lore(lore);
|
||||||
|
});
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
NametagActions getNametagAction(ItemStack item) {
|
||||||
|
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){
|
||||||
|
if(renameText.equals(muteString)) {
|
||||||
|
return this.setNametagAction(oldResultItem, NametagActions.SILENCE);
|
||||||
|
} else if(renameText.equals(unmuteString)) {
|
||||||
|
return this.setNametagAction(oldResultItem, NametagActions.UNSILENCE);
|
||||||
|
}
|
||||||
|
return oldResultItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(new NametagAnvilListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user