Files
resource-pack
src
build.gradle
README.md
settings.gradle
Code
51 1,480
src/main/java/com/festivalcore/FestivalCore.java
package com.festivalcore;
import com.cryptomorin.xseries.particles.XParticle;
import com.festivalcore.command.FestivalCommand;
import com.festivalcore.config.ConfigManager;
import com.festivalcore.festival.FestivalType;
import com.festivalcore.flags.FlagManager;
import com.festivalcore.fireworks.FireworksManager;
import com.festivalcore.god.GodModeManager;
import com.festivalcore.gui.FestivalMenuListener;
import com.festivalcore.items.FestivalItemService;
import com.festivalcore.listener.FestivalListener;
import com.festivalcore.manager.FestivalManager;
import com.festivalcore.placeholder.FestivalPlaceholder;
import com.festivalcore.rewards.RewardManager;
import com.festivalcore.storage.Storage;
import com.festivalcore.storage.YamlStorage;
import com.festivalcore.util.Text;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class FestivalCore extends JavaPlugin {
private ConfigManager configs;
private Storage storage;
private FestivalManager festivals;
private FireworksManager fireworks;
private FestivalItemService items;
private RewardManager rewards;
private GodModeManager godMode;
private FlagManager flags;
private FestivalMenuListener menu;
private NamespacedKey flagKey;
@Override
public void onEnable() {
configs = new ConfigManager(this);
configs.load();
storage = new YamlStorage(this);
festivals = new FestivalManager(this);
fireworks = new FireworksManager(this);
items = new FestivalItemService(this);
rewards = new RewardManager(this, storage);
godMode = new GodModeManager();
flags = new FlagManager(this, items);
menu = new FestivalMenuListener(this);
flagKey = new NamespacedKey(this, "festival_flag");
FestivalCommand command = new FestivalCommand(this);
getCommand("festival").setExecutor(command);
getCommand("festival").setTabCompleter(command);
Bukkit.getPluginManager().registerEvents(new FestivalListener(this), this);
Bukkit.getPluginManager().registerEvents(menu, this);
festivals.startAutomaticChecks();
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) new FestivalPlaceholder(this).register();
getLogger().info("FestivalCore enabled. Decorative effects are limited by the configured caps.");
}
@Override
public void onDisable() {
if (festivals != null) festivals.stopAll();
if (fireworks != null) fireworks.cleanup();
if (storage != null) storage.save();
}
public void reloadFestival() {
configs.reload();
reloadConfig();
}
public Location getEventLocation(String name) {
String serialized = getConfig().getString("settings.locations." + name, "");
if (serialized == null || serialized.isBlank()) return null;
String[] parts = serialized.split(",");
if (parts.length < 4) return null;
World world = Bukkit.getWorld(parts[0]);
if (world == null) return null;
try {
float yaw = parts.length > 4 ? Float.parseFloat(parts[4]) : 0;
float pitch = parts.length > 5 ? Float.parseFloat(parts[5]) : 0;
return new Location(world, Double.parseDouble(parts[1]), Double.parseDouble(parts[2]), Double.parseDouble(parts[3]), yaw, pitch);
} catch (NumberFormatException exception) {
getLogger().warning("Invalid saved location for " + name);
return null;
}
}
public void giveItem(Player player, String id) {
org.bukkit.inventory.ItemStack item = items.create(id);
if (item == null) { Text.message(player, configs.prefix(), "&cCould not create item: " + id); return; }
if (player.getInventory().addItem(item).isEmpty()) Text.message(player, configs.prefix(), configs.message("item-received").replace("%item%", id));
else player.getWorld().dropItemNaturally(player.getLocation(), item);
}
public void recordParticipation(Player player, FestivalType type) {
storage.recordParticipation(player.getUniqueId(), type.key());
Text.message(player, configs.prefix(), configs.message("participation").replace("%event%", type.displayName()));
}
public boolean claimAvailableReward(Player player) {
boolean claimed = false;
for (FestivalType type : FestivalType.values()) if (festivals.isActive(type)) claimed |= rewards.participation(player, type);
if (!claimed) Text.message(player, configs.prefix(), configs.message("reward-unavailable"));
return claimed;
}
public void toggleGod(org.bukkit.command.CommandSender sender, Player target) {
boolean enabled = godMode.toggle(target.getUniqueId());
Text.message(target, configs.prefix(), configs.message(enabled ? "god-enabled" : "god-disabled"));
if (!sender.equals(target)) Text.message(sender, configs.prefix(), "&eGod Mode for " + target.getName() + ": " + (enabled ? "enabled" : "disabled"));
}
public void playFirecracker(Location location) {
XParticle.of("FIREWORK").ifPresent(particle -> location.getWorld().spawnParticle(particle.get(), location, Math.min(12, getConfig().getInt("settings.max-particles", 24)), .25, .25, .25, .01));
XParticle.of("CRIT").ifPresent(particle -> location.getWorld().spawnParticle(particle.get(), location, Math.min(8, getConfig().getInt("settings.max-particles", 24)), .35, .35, .35, .05));
}
public void decorateGhat(Location location) {
XParticle.of("HAPPY_VILLAGER").ifPresent(particle -> location.getWorld().spawnParticle(particle.get(), location.clone().add(0, 1, 0), Math.min(24, getConfig().getInt("settings.max-particles", 24)), 1.5, .5, 1.5, .01));
}
public void announceChhath(String moment) {
String message = configs.get("chhath.yml").getString("announcements." + moment, "&eChhath Puja " + moment + " celebration is beginning.");
Bukkit.broadcastMessage(Text.color(configs.prefix() + message));
for (Player player : Bukkit.getOnlinePlayers()) {
Location ghat = getEventLocation("chhath");
if (ghat != null && player.getWorld().equals(ghat.getWorld())) recordParticipation(player, FestivalType.CHHATH);
}
Location location = getEventLocation("chhath");
if (location != null) decorateGhat(location);
if (configs.get("chhath.yml").getBoolean("chhath.fireworks", true)) fireworks.start("chhath_show");
}
public ConfigManager configs() { return configs; }
public FestivalManager festivals() { return festivals; }
public FireworksManager fireworks() { return fireworks; }
public FestivalItemService items() { return items; }
public RewardManager rewards() { return rewards; }
public GodModeManager godMode() { return godMode; }
public FlagManager flags() { return flags; }
public FestivalMenuListener menu() { return menu; }
public NamespacedKey flagKey() { return flagKey; }
}