Files
src
build.gradle
settings.gradle
Code
7 338
src/main/java/com/kodari/godsword/GodSwordPlugin.java
package com.kodari.godsword;
import com.cryptomorin.xseries.XMaterial;
import java.util.Objects;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
public final class GodSwordPlugin extends JavaPlugin {
private NamespacedKey swordKey;
private NamespacedKey projectileKey;
@Override
public void onEnable() {
saveDefaultConfig();
swordKey = new NamespacedKey(this, "god_stone_sword");
projectileKey = new NamespacedKey(this, "god_sword_projectile");
getServer().getPluginManager().registerEvents(new GodSwordListener(this), this);
Objects.requireNonNull(getCommand("godsword")).setExecutor(new GodSwordCommand(this));
}
public ItemStack createGodSword() {
ItemStack sword = XMaterial.matchXMaterial("STONE_SWORD")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("STONE_SWORD is unavailable"));
ItemMeta meta = sword.getItemMeta();
meta.setDisplayName("§6God Stone Sword");
meta.setUnbreakable(true);
meta.getPersistentDataContainer().set(swordKey, PersistentDataType.BYTE, (byte) 1);
sword.setItemMeta(meta);
return sword;
}
public boolean isGodSword(ItemStack item) {
return item != null
&& item.hasItemMeta()
&& item.getItemMeta().getPersistentDataContainer().has(swordKey, PersistentDataType.BYTE);
}
public boolean isGodSwordProjectile(org.bukkit.entity.Arrow arrow) {
return arrow.getPersistentDataContainer().has(projectileKey, PersistentDataType.BYTE);
}
public void markGodSwordProjectile(org.bukkit.entity.Arrow arrow) {
arrow.getPersistentDataContainer().set(projectileKey, PersistentDataType.BYTE, (byte) 1);
}
public NamespacedKey getProjectileKey() {
return projectileKey;
}
public double getDamage() {
return getConfig().getDouble("damage", 10.0);
}
public void setDamage(double damage) {
getConfig().set("damage", damage);
saveConfig();
}
}