Files
src
build.gradle
settings.gradle
Code
10 1,187
src/main/java/com/atlas/smp/AtlasPlugin.java
package com.atlas.smp;
import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Random;
public final class AtlasPlugin extends JavaPlugin implements Listener {
private final Random random = new Random();
private NamespacedKey itemKey;
private GodManager godManager;
private AbilityManager abilityManager;
private GodMenu godMenu;
@Override
public void onEnable() {
itemKey = new NamespacedKey(this, "atlas_item");
godManager = new GodManager(this);
abilityManager = new AbilityManager(this);
godMenu = new GodMenu(this);
getServer().getPluginManager().registerEvents(this, this);
getServer().getPluginManager().registerEvents(abilityManager, this);
getServer().getPluginManager().registerEvents(godMenu, this);
AtlasItems.registerRecipes(this);
getCommand("atlas").setExecutor(new AtlasCommand(this));
getCommand("ability").setExecutor(new AtlasCommand(this));
getCommand("cooldown").setExecutor(new AtlasCommand(this));
}
public NamespacedKey getItemKey() {
return itemKey;
}
public GodManager getGodManager() {
return godManager;
}
public AbilityManager getAbilityManager() {
return abilityManager;
}
public GodMenu getGodMenu() {
return godMenu;
}
public Random getRandom() {
return random;
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (godManager.hasGod(player.getUniqueId())) return;
AtlasGod chosen = AtlasGod.rollable().get(random.nextInt(AtlasGod.rollable().size()));
for (int step = 0; step < 15; step++) {
int rollStep = step;
Bukkit.getScheduler().runTaskLater(this, () -> {
if (!player.isOnline()) return;
AtlasGod display = AtlasGod.rollable().get(rollStep % AtlasGod.rollable().size());
player.sendTitle("§6" + display.displayName(), "§eThe gods are choosing you...", 0, 5, 0);
XSound.matchXSound("BLOCK_NOTE_BLOCK_CHIME").ifPresent(sound -> sound.play(player));
XParticle.of("FIREWORK").ifPresent(particle -> player.getWorld().spawnParticle(particle.get(), player.getLocation().add(0, 1, 0), 8, .5, .5, .5, .03));
}, step * 4L);
}
Bukkit.getScheduler().runTaskLater(this, () -> {
if (!player.isOnline()) return;
godManager.setGod(player.getUniqueId(), chosen);
player.sendTitle("§6§l" + chosen.displayName(), "§fYour divine abilities have awakened", 5, 60, 15);
XSound.matchXSound("ENTITY_PLAYER_LEVELUP").ifPresent(sound -> sound.play(player));
XParticle.of("TOTEM_OF_UNDYING").ifPresent(particle -> player.getWorld().spawnParticle(particle.get(), player.getLocation().add(0, 1, 0), 35, .8, 1, .8, .12));
}, 60L);
}
@EventHandler
public void onSwap(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
if (!player.isSneaking()) return;
event.setCancelled(true);
abilityManager.activate(player, 1);
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND) return;
ItemStack item = event.getItem();
String itemId = AtlasItems.id(this, item);
if (itemId != null && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true);
useCustomItem(event.getPlayer(), item, itemId);
return;
}
if (event.getPlayer().isSneaking() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
abilityManager.activate(event.getPlayer(), 2);
}
}
private void useCustomItem(Player player, ItemStack item, String id) {
switch (id) {
case "reroller" -> {
godManager.setGod(player.getUniqueId(), AtlasGod.rollable().get(random.nextInt(AtlasGod.rollable().size())));
consumeOne(player, item);
player.sendMessage("§aThe gods have chosen §6" + godManager.getGod(player).displayName() + "§a. Your blessings remain unchanged.");
XParticle.of("TOTEM_OF_UNDYING").ifPresent(particle -> player.getWorld().spawnParticle(particle.get(), player.getLocation().add(0, 1, 0), 20, .5, .8, .5, .1));
}
case "god_picker" -> godMenu.openPicker(player);
case "blessing" -> {
if (godManager.getBlessings(player.getUniqueId()) >= 5) {
player.sendMessage("§cYou already have the maximum of 5 blessings.");
} else {
godManager.setBlessings(player.getUniqueId(), godManager.getBlessings(player.getUniqueId()) + 1);
consumeOne(player, item);
player.sendMessage("§dBlessing added. Total: §f" + godManager.getBlessings(player.getUniqueId()));
}
}
default -> player.sendMessage("§cThat Atlas item is not recognized.");
}
}
private void consumeOne(Player player, ItemStack item) {
if (player.getGameMode().name().equals("CREATIVE")) return;
if (item.getAmount() <= 1) player.getInventory().setItemInMainHand(null);
else item.setAmount(item.getAmount() - 1);
}
@EventHandler
public void onDeath(EntityDeathEvent event) {
if (!(event.getEntity() instanceof Player)) return;
ItemStack blessing = AtlasItems.create(this, "blessing", "NETHER_STAR", "Blessing", "§7A divine token used to upgrade your god.");
if (blessing != null) event.getDrops().add(blessing);
}
@EventHandler
public void onPotionEffect(EntityPotionEffectEvent event) {
if (!(event.getEntity() instanceof Player player) || event.getNewEffect() == null) return;
AtlasGod god = godManager.getGod(player);
if (god != AtlasGod.YMIR && god != AtlasGod.RHIONE) return;
String type = event.getNewEffect().getType().getName();
boolean negative = type.equalsIgnoreCase("SLOW") || type.equalsIgnoreCase("SLOWNESS")
|| type.equalsIgnoreCase("BLINDNESS") || type.equalsIgnoreCase("POISON")
|| type.equalsIgnoreCase("WITHER") || type.equalsIgnoreCase("WEAKNESS")
|| type.equalsIgnoreCase("HUNGER") || type.equalsIgnoreCase("CONFUSION")
|| type.equalsIgnoreCase("NAUSEA") || type.equalsIgnoreCase("MINING_FATIGUE")
|| type.equalsIgnoreCase("LEVITATION") || type.equalsIgnoreCase("DARKNESS")
|| type.equalsIgnoreCase("BAD_OMEN") || type.equalsIgnoreCase("UNLUCK")
|| type.equalsIgnoreCase("TRIAL_OMEN") || type.equalsIgnoreCase("RAID_OMEN")
|| type.equalsIgnoreCase("GLOWING");
if (negative && (god == AtlasGod.YMIR || type.equalsIgnoreCase("SLOW") || type.equalsIgnoreCase("SLOWNESS"))) {
event.setCancelled(true);
}
}
@EventHandler
public void onCraft(CraftItemEvent event) {
if (!(event.getWhoClicked() instanceof Player player) || event.getCurrentItem() == null) return;
String type = event.getCurrentItem().getType().name();
if (godManager.getGod(player) != AtlasGod.PLUTUS || !type.endsWith("_PICKAXE") || event.getCurrentItem().getItemMeta() == null) return;
XEnchantment.matchXEnchantment("FORTUNE").ifPresent(enchantment -> {
ItemStack result = event.getCurrentItem().clone();
result.addUnsafeEnchantment(enchantment.getEnchant(), 3);
event.setCurrentItem(result);
});
}
@EventHandler
public void onTameableInteract(PlayerInteractEntityEvent event) {
if (godManager.getGod(event.getPlayer()) != AtlasGod.YMIR) return;
if (!(event.getRightClicked() instanceof Tameable tameable) || tameable.isTamed()) return;
tameable.setOwner(event.getPlayer());
event.getPlayer().sendMessage("§bThe creature answers Ymir's call.");
XParticle.of("SNOWFLAKE").ifPresent(particle -> event.getRightClicked().getWorld().spawnParticle(particle.get(), event.getRightClicked().getLocation().add(0, 1, 0), 15, .5, .5, .5, .02));
}
}