Files
src
build.gradle
Code
40 2,679
src/main/java/com/shrinesmp/ShrineSMP.java
package com.shrinesmp;
import com.shrinesmp.commands.*;
import com.shrinesmp.inventory.gui.GUIListener;
import com.shrinesmp.inventory.gui.GUIManager;
import com.shrinesmp.listeners.ShrineListener;
import com.shrinesmp.shrines.ShrineAbility;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class ShrineSMP extends JavaPlugin {
// Static NamespacedKeys
public static NamespacedKey SHRINE_MACE_KEY;
public static NamespacedKey SECOND_ABILITY_KEY;
public static NamespacedKey REROLL_KEY;
public static NamespacedKey END_ITEM_KEY;
public static NamespacedKey ENDER_CONSUMABLE_KEY;
public static NamespacedKey SHRINE_PROJECTILE_KEY;
public static NamespacedKey SHRINE_SHOOTER_KEY;
public static NamespacedKey SHRINE_PROJECTILE_TYPE_KEY;
public static NamespacedKey SHRINE_BOOK_KEY;
@Getter private static ShrineSMP instance;
@Getter private PlayerDataManager playerDataManager;
@Getter private ShrineManager shrineManager;
@Getter private GUIManager guiManager;
@Getter @Setter private boolean pvpDisabled = false;
// Ender shrine: set of players whose next attack ignores 25% armor
@Getter private final Set<UUID> enderArmorPiercing = new HashSet<>();
// Ender passive: players currently glowing due to Ender shrine
private final Set<UUID> enderGlowedPlayers = new HashSet<>();
@Override
public void onEnable() {
instance = this;
// Init NamespacedKeys
SHRINE_MACE_KEY = new NamespacedKey(this, "shrine_mace");
SECOND_ABILITY_KEY = new NamespacedKey(this, "second_ability");
REROLL_KEY = new NamespacedKey(this, "reroll");
END_ITEM_KEY = new NamespacedKey(this, "end_item");
ENDER_CONSUMABLE_KEY = new NamespacedKey(this, "ender_consumable");
SHRINE_PROJECTILE_KEY = new NamespacedKey(this, "shrine_projectile_damage");
SHRINE_SHOOTER_KEY = new NamespacedKey(this, "shrine_shooter");
SHRINE_PROJECTILE_TYPE_KEY = new NamespacedKey(this, "shrine_projectile_type");
SHRINE_BOOK_KEY = new NamespacedKey(this, "shrine_book");
playerDataManager = new PlayerDataManager();
shrineManager = new ShrineManager(this);
guiManager = new GUIManager();
// Register listeners
getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);
getServer().getPluginManager().registerEvents(new ShrineListener(this), this);
// Register commands
getCommand("ab1").setExecutor(new Ab1Command(this));
getCommand("ab2").setExecutor(new Ab2Command(this));
getCommand("shrinegive").setExecutor(new ShrineGiveCommand(this));
getCommand("info").setExecutor(new InfoCommand(this));
getCommand("trust").setExecutor(new TrustCommand(this));
getCommand("reroll").setExecutor(new RerollCommand(this));
getCommand("setshrine").setExecutor(new SetShrineCommand(this));
getCommand("start").setExecutor(new StartCommand(this));
getCommand("withdraw").setExecutor(new WithdrawCommand(this));
getCommand("ei").setExecutor(new EICommand(this));
// Passive tick task (every 2 seconds)
new BukkitRunnable() {
@Override
public void run() {
for (Player player : getServer().getOnlinePlayers()) {
PlayerData data = playerDataManager.getData(player.getUniqueId());
if (data == null || data.getShrine() == null || data.isShrineDisabled()) continue;
ShrineAbility ability = shrineManager.getAbility(data.getShrine());
if (ability != null) {
ability.onPassiveTick(player, data);
}
}
// Ender shrine passive: apply glow to players near Ender shrine holders
Set<UUID> shouldGlow = new HashSet<>();
for (Player player : getServer().getOnlinePlayers()) {
PlayerData data = playerDataManager.getData(player.getUniqueId());
if (data == null || data.getShrine() != ShrineType.ENDER || data.isShrineDisabled()) continue;
for (Player nearby : player.getWorld().getPlayers()) {
if (nearby.getLocation().distance(player.getLocation()) <= 25) {
shouldGlow.add(nearby.getUniqueId());
}
}
}
// Update glowing state
for (Player player : getServer().getOnlinePlayers()) {
boolean shouldBeGlowing = shouldGlow.contains(player.getUniqueId());
boolean wasGlowing = enderGlowedPlayers.contains(player.getUniqueId());
if (shouldBeGlowing && !wasGlowing) {
player.setGlowing(true);
enderGlowedPlayers.add(player.getUniqueId());
} else if (!shouldBeGlowing && wasGlowing) {
player.setGlowing(false);
enderGlowedPlayers.remove(player.getUniqueId());
}
}
}
}.runTaskTimer(this, 40L, 40L);
getLogger().info("ShrineSMP enabled with " + ShrineType.values().length + " shrines.");
}
@Override
public void onDisable() {
// Clean up Ender glow
for (UUID uuid : enderGlowedPlayers) {
Player p = getServer().getPlayer(uuid);
if (p != null) p.setGlowing(false);
}
getLogger().info("ShrineSMP disabled.");
}
}