Files
src
build.gradle
settings.gradle
Code
8 1,149
src/main/java/com/kodari/eventitems/EventItemsPlugin.java
package com.kodari.eventitems;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.stream.Collectors;
public final class EventItemsPlugin extends JavaPlugin {
private NamespacedKey ghostKey;
private GhostListener ghostListener;
private WorldEditReplacement worldEditReplacement;
@Override
public void onEnable() {
saveDefaultConfig();
ghostKey = new NamespacedKey(this, "ghost_item");
ghostListener = new GhostListener(this);
getServer().getPluginManager().registerEvents(ghostListener, this);
EventItemsCommand command = new EventItemsCommand(this);
if (getCommand("eventitems") != null) {
getCommand("eventitems").setExecutor(command);
}
WorldEditReplacement worldEditReplacement = new WorldEditReplacement(this);
this.worldEditReplacement = worldEditReplacement;
getServer().getPluginManager().registerEvents(worldEditReplacement, this);
getLogger().info("Własny zamiennik WorldEdit załadowany.");
}
@Override
public void onDisable() {
if (ghostListener != null) {
ghostListener.restoreAll();
}
if (worldEditReplacement != null) {
worldEditReplacement.clearAll();
}
}
public NamespacedKey getGhostKey() {
return ghostKey;
}
public boolean isGhostEnabled() {
return getConfig().getBoolean("ghost.enabled", true);
}
public void restoreGhostEffects() {
if (ghostListener != null) {
ghostListener.restoreAll();
}
}
public void forceDisableGhost(Player player) {
if (ghostListener != null) {
ghostListener.forceDisable(player);
}
}
public int getGhostDurationTicks() {
return Math.max(1, getConfig().getInt("ghost.duration-seconds", 3) * 20);
}
public int getGhostDurationSeconds() {
return Math.max(1, getConfig().getInt("ghost.duration-seconds", 3));
}
public ItemStack createGhostItem() {
String materialName = getConfig().getString("ghost.material", "GHAST_TEAR");
ItemStack item = XMaterial.matchXMaterial(materialName)
.map(XMaterial::parseItem)
.orElse(null);
if (item == null) {
item = XMaterial.matchXMaterial("GHAST_TEAR")
.map(XMaterial::parseItem)
.orElse(null);
}
if (item == null) {
return null;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item;
}
String name = getConfig().getString("ghost.name", "&b&lDuch");
List<String> lore = getConfig().getStringList("ghost.lore")
.stream()
.map(this::color)
.collect(Collectors.toList());
meta.setDisplayName(color(name));
meta.setLore(lore);
meta.getPersistentDataContainer().set(
ghostKey,
org.bukkit.persistence.PersistentDataType.BYTE,
(byte) 1
);
item.setItemMeta(meta);
return item;
}
public boolean isGhostItem(ItemStack item) {
if (item == null || !item.hasItemMeta()) {
return false;
}
ItemMeta meta = item.getItemMeta();
return meta != null
&& meta.getPersistentDataContainer().has(
ghostKey,
org.bukkit.persistence.PersistentDataType.BYTE
);
}
public String message(String path) {
return color(getConfig().getString(path, ""));
}
public String color(String text) {
return ChatColor.translateAlternateColorCodes('&', text);
}
}