Compare commits
No commits in common. "8b1b3c4b5ab91a34b2d5103a694e70f66c90ca6e" and "060e8a4541395bf8d9e137bd5fe5eaf976eda613" have entirely different histories.
8b1b3c4b5a
...
060e8a4541
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
id("com.github.ben-manes.versions") version "0.52.0"
|
id("com.github.ben-manes.versions") version "0.52.0"
|
||||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.alttd.easter"
|
group = "com.alttd.easter"
|
||||||
|
|
@ -30,14 +29,6 @@ tasks {
|
||||||
archiveFileName.set("${rootProject.name}.jar")
|
archiveFileName.set("${rootProject.name}.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
|
||||||
archiveFileName.set("${rootProject.name}.jar")
|
|
||||||
mergeServiceFiles()
|
|
||||||
}
|
|
||||||
build {
|
|
||||||
dependsOn("shadowJar")
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
filteringCharset = Charsets.UTF_8.name()
|
filteringCharset = Charsets.UTF_8.name()
|
||||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||||
|
|
@ -52,10 +43,6 @@ dependencies {
|
||||||
isChanging = true
|
isChanging = true
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation("com.alttd.inventory_gui:InventoryGUI:1.1.5-20260201.231743-1") {
|
|
||||||
isChanging = true
|
|
||||||
}
|
|
||||||
|
|
||||||
implementation("org.slf4j:slf4j-api:2.0.17")
|
implementation("org.slf4j:slf4j-api:2.0.17")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
compileOnly("org.projectlombok:lombok:1.18.38")
|
||||||
|
|
|
||||||
|
|
@ -3,39 +3,22 @@ package com.alttd.easter;
|
||||||
import com.alttd.easter.commands.Command;
|
import com.alttd.easter.commands.Command;
|
||||||
import com.alttd.easter.config.Config;
|
import com.alttd.easter.config.Config;
|
||||||
import com.alttd.easter.config.Messages;
|
import com.alttd.easter.config.Messages;
|
||||||
import com.alttd.easter.data.DataManager;
|
|
||||||
import com.alttd.easter.glow.GlowManager;
|
|
||||||
import com.alttd.easter.gui.TurnInGuiManager;
|
|
||||||
import com.alttd.easter.listeners.DeathListener;
|
|
||||||
import com.alttd.easter.listeners.SpawnListener;
|
|
||||||
import com.alttd.easter.npc.RabbitNpcManager;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class Easter extends JavaPlugin {
|
public final class Easter extends JavaPlugin {
|
||||||
|
|
||||||
private DataManager dataManager;
|
|
||||||
private RabbitNpcManager rabbitNpcManager;
|
|
||||||
private GlowManager glowManager;
|
|
||||||
private TurnInGuiManager turnInGuiManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
reloadConfigs();
|
|
||||||
this.dataManager = new DataManager(this);
|
|
||||||
this.glowManager = new GlowManager(this);
|
|
||||||
this.turnInGuiManager = new TurnInGuiManager(dataManager);
|
|
||||||
this.rabbitNpcManager = new RabbitNpcManager(this, turnInGuiManager);
|
|
||||||
registerCommands();
|
registerCommands();
|
||||||
registerEvents();
|
registerEvents();
|
||||||
|
reloadConfigs();
|
||||||
registerSchedulers();
|
registerSchedulers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (dataManager != null) {
|
//TODO save data
|
||||||
dataManager.save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
|
|
@ -44,21 +27,16 @@ public final class Easter extends JavaPlugin {
|
||||||
|
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
PluginManager pluginManager = getServer().getPluginManager();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
pluginManager.registerEvents(new SpawnListener(glowManager), this);
|
|
||||||
pluginManager.registerEvents(new DeathListener(), this);
|
//TODO register events
|
||||||
pluginManager.registerEvents(rabbitNpcManager, this);
|
|
||||||
pluginManager.registerEvents(turnInGuiManager, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadConfigs() {
|
public void reloadConfigs() {
|
||||||
Config.reload();
|
Config.reload();
|
||||||
Messages.reload();
|
Messages.reload();
|
||||||
if (rabbitNpcManager != null) {
|
|
||||||
rabbitNpcManager.reload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSchedulers() {
|
private void registerSchedulers() {
|
||||||
// No schedulers required currently
|
//TODO register schedulers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package com.alttd.easter.commands;
|
package com.alttd.easter.commands;
|
||||||
|
|
||||||
import com.alttd.easter.Easter;
|
import com.alttd.easter.Easter;
|
||||||
import com.alttd.easter.commands.subcommands.Reload;
|
import com.alttd.easter.commands.subcommands.*;
|
||||||
import com.alttd.easter.commands.subcommands.SetPrize;
|
|
||||||
import com.alttd.easter.config.Messages;
|
import com.alttd.easter.config.Messages;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -19,8 +18,7 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@SuppressWarnings("ClassCanBeRecord")
|
@SuppressWarnings("ClassCanBeRecord")
|
||||||
@Slf4j
|
@Slf4j @Getter
|
||||||
@Getter
|
|
||||||
public class Command implements CommandExecutor, TabExecutor {
|
public class Command implements CommandExecutor, TabExecutor {
|
||||||
private final List<SubCommand> subCommands;
|
private final List<SubCommand> subCommands;
|
||||||
|
|
||||||
|
|
@ -36,8 +34,7 @@ public class Command implements CommandExecutor, TabExecutor {
|
||||||
command.setAliases(List.of("pu"));
|
command.setAliases(List.of("pu"));
|
||||||
|
|
||||||
subCommands = List.of(
|
subCommands = List.of(
|
||||||
new Reload(easter),
|
new Reload(easter)
|
||||||
new SetPrize()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,9 +49,8 @@ public class Command implements CommandExecutor, TabExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
SubCommand subCommand = getSubCommand(args[0]);
|
SubCommand subCommand = getSubCommand(args[0]);
|
||||||
if (subCommand == null) {
|
if (subCommand == null)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
||||||
commandSender.sendRichMessage(Messages.GENERIC.NO_PERMISSION, Placeholder.parsed("permission", subCommand.getPermission()));
|
commandSender.sendRichMessage(Messages.GENERIC.NO_PERMISSION, Placeholder.parsed("permission", subCommand.getPermission()));
|
||||||
|
|
@ -81,12 +77,11 @@ public class Command implements CommandExecutor, TabExecutor {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
SubCommand subCommand = getSubCommand(args[0]);
|
SubCommand subCommand = getSubCommand(args[0]);
|
||||||
if (subCommand != null && commandSender.hasPermission(subCommand.getPermission())) {
|
if (subCommand != null && commandSender.hasPermission(subCommand.getPermission()))
|
||||||
res.addAll(subCommand.getTabComplete(commandSender, args).stream()
|
res.addAll(subCommand.getTabComplete(commandSender, args).stream()
|
||||||
.filter(str -> str.toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
|
.filter(str -> str.toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
|
||||||
.toList());
|
.toList());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,14 @@ import java.util.List;
|
||||||
|
|
||||||
public abstract class SubCommand {
|
public abstract class SubCommand {
|
||||||
|
|
||||||
public SubCommand() {
|
public SubCommand() {}
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean onCommand(CommandSender commandSender, String[] args);
|
public abstract boolean onCommand(CommandSender commandSender, String[] args);
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return "easter." + getName();
|
return "playerutils." + getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<String> getTabComplete(CommandSender commandSender, String[] args);
|
public abstract List<String> getTabComplete(CommandSender commandSender, String[] args);
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
package com.alttd.easter.commands.subcommands;
|
|
||||||
|
|
||||||
import com.alttd.easter.commands.SubCommand;
|
|
||||||
import com.alttd.easter.config.Config;
|
|
||||||
import com.alttd.easter.config.Messages;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SetPrize extends SubCommand {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
|
||||||
if (!(commandSender instanceof Player player)) {
|
|
||||||
commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
ItemStack item = player.getInventory().getItemInMainHand();
|
|
||||||
if (item.getType().isAir()) {
|
|
||||||
player.sendRichMessage(Messages.SETPRIZE.EMPTY_HAND);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Config.PRIZES.addPrize(item.clone());
|
|
||||||
player.sendRichMessage(Messages.SETPRIZE.SUCCESS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "setprize";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getHelpMessage() {
|
|
||||||
return Messages.HELP.SET_PRIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -19,8 +19,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j @SuppressWarnings({"unused", "SameParameterValue"})
|
||||||
@SuppressWarnings({"unused", "SameParameterValue"})
|
|
||||||
abstract class AbstractConfig {
|
abstract class AbstractConfig {
|
||||||
File file;
|
File file;
|
||||||
YamlConfiguration yaml;
|
YamlConfiguration yaml;
|
||||||
|
|
@ -130,7 +129,8 @@ abstract class AbstractConfig {
|
||||||
final ConfigurationSection section = yaml.getConfigurationSection(path);
|
final ConfigurationSection section = yaml.getConfigurationSection(path);
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
for (String key : section.getKeys(false)) {
|
for (String key : section.getKeys(false)) {
|
||||||
@SuppressWarnings("unchecked") final T val = (T) section.get(key);
|
@SuppressWarnings("unchecked")
|
||||||
|
final T val = (T) section.get(key);
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
builder.put(key, val);
|
builder.put(key, val);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
package com.alttd.easter.config;
|
package com.alttd.easter.config;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j public class Config extends AbstractConfig{
|
||||||
public class Config extends AbstractConfig {
|
|
||||||
|
|
||||||
static Config config;
|
static Config config;
|
||||||
|
|
||||||
|
|
@ -29,72 +26,15 @@ public class Config extends AbstractConfig {
|
||||||
config.readConfig(Config.class, null);
|
config.readConfig(Config.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EGGS {
|
public static class SETTINGS {
|
||||||
private static final String prefix = "eggs.";
|
private static final String prefix = "settings.";
|
||||||
public static double SPAWN_CHANCE = 0.02; // ~2 per night per player
|
public static boolean DEBUG = false;
|
||||||
|
public static boolean WARNINGS = true;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
SPAWN_CHANCE = config.getDouble(prefix, "spawn-chance", SPAWN_CHANCE);
|
DEBUG = config.getBoolean(prefix, "debug", DEBUG);
|
||||||
}
|
WARNINGS = config.getBoolean(prefix, "warnings", WARNINGS);
|
||||||
}
|
|
||||||
|
|
||||||
public static class RABBIT {
|
|
||||||
private static final String prefix = "rabbit.";
|
|
||||||
public static String WORLD = "world";
|
|
||||||
public static double X = 0, Y = 64, Z = 0;
|
|
||||||
public static float YAW = 0, PITCH = 0;
|
|
||||||
public static double INTERACT_RADIUS = 2.5;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static void load() {
|
|
||||||
WORLD = config.getString(prefix, "world", WORLD);
|
|
||||||
X = config.getDouble(prefix, "x", X);
|
|
||||||
Y = config.getDouble(prefix, "y", Y);
|
|
||||||
Z = config.getDouble(prefix, "z", Z);
|
|
||||||
YAW = (float) config.getDouble(prefix, "yaw", YAW);
|
|
||||||
PITCH = (float) config.getDouble(prefix, "pitch", PITCH);
|
|
||||||
INTERACT_RADIUS = config.getDouble(prefix, "interact-radius", INTERACT_RADIUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location getLocation(org.bukkit.Server server) {
|
|
||||||
World world = server.getWorld(WORLD);
|
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Location(world, X, Y, Z, YAW, PITCH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PRIZES {
|
|
||||||
private static final String prefix = "prizes.";
|
|
||||||
public static List<ItemStack> LIST = new ArrayList<>();
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static void load() {
|
|
||||||
List<?> raw = config.yaml.getList(prefix + "list");
|
|
||||||
LIST = new ArrayList<>();
|
|
||||||
if (raw != null) {
|
|
||||||
for (Object o : raw) {
|
|
||||||
if (o instanceof ItemStack item) {
|
|
||||||
LIST.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ensure path exists
|
|
||||||
config.yaml.addDefault(prefix + "list", LIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addPrize(ItemStack item) {
|
|
||||||
LIST.add(item);
|
|
||||||
config.set(prefix, "list", LIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getRandomPrize() {
|
|
||||||
if (LIST.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return LIST.get((int) (Math.random() * LIST.size())).clone();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.easter.config;
|
package com.alttd.easter.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Messages extends AbstractConfig {
|
public class Messages extends AbstractConfig {
|
||||||
static Messages config;
|
static Messages config;
|
||||||
|
|
@ -25,14 +26,12 @@ public class Messages extends AbstractConfig {
|
||||||
public static String HELP_MESSAGE_WRAPPER = "<gold>Easter help:\n<commands></gold>";
|
public static String HELP_MESSAGE_WRAPPER = "<gold>Easter help:\n<commands></gold>";
|
||||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/pu help</gold></green>";
|
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/pu help</gold></green>";
|
||||||
public static String RELOAD = "<green>Reload the configs for Easter: <gold>/pu reload</gold></green>";
|
public static String RELOAD = "<green>Reload the configs for Easter: <gold>/pu reload</gold></green>";
|
||||||
public static String SET_PRIZE = "<green>Add the item in your hand as a prize: <gold>/pu setprize</gold></green>";
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
HELP_MESSAGE_WRAPPER = config.getString(prefix, "help-wrapper", HELP_MESSAGE_WRAPPER);
|
HELP_MESSAGE_WRAPPER = config.getString(prefix, "help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||||
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
|
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
|
||||||
RELOAD = config.getString(prefix, "reload", RELOAD);
|
RELOAD = config.getString(prefix, "reload", RELOAD);
|
||||||
SET_PRIZE = config.getString(prefix, "set-prize", SET_PRIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +46,7 @@ public class Messages extends AbstractConfig {
|
||||||
private static void load() {
|
private static void load() {
|
||||||
NO_PERMISSION = config.getString(prefix, "no-permission", NO_PERMISSION);
|
NO_PERMISSION = config.getString(prefix, "no-permission", NO_PERMISSION);
|
||||||
PLAYER_ONLY = config.getString(prefix, "player-only", PLAYER_ONLY);
|
PLAYER_ONLY = config.getString(prefix, "player-only", PLAYER_ONLY);
|
||||||
PLAYER_NOT_FOUND = config.getString(prefix, "player-not-found", PLAYER_NOT_FOUND);
|
PLAYER_NOT_FOUND = config.getString(prefix, "player-only", PLAYER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,38 +60,4 @@ public class Messages extends AbstractConfig {
|
||||||
RELOADED = config.getString(prefix, "reloaded", RELOADED);
|
RELOADED = config.getString(prefix, "reloaded", RELOADED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RABBIT {
|
|
||||||
private static final String prefix = "rabbit.";
|
|
||||||
public static String LEFT_CLICK_INTRO = "<green>Hi <player>. A bunch of different mobs have stolen my easter eggs! Can you find them and kill them for me? If you bring the eggs back I will reward you!</green>";
|
|
||||||
public static String NO_EGGS = "<yellow>Please come back when you've found some eggs!</yellow>";
|
|
||||||
public static String THANK_YOU = "<green>Thank you for finding my eggs <player>! Keep looking for more!</green>";
|
|
||||||
public static String ONE_EGG = "<green>Thank you for finding my eggs <player>! I have received the <egg1> from you. Please keep looking for more!</green>";
|
|
||||||
public static String MULTI_EGGS = "<green>Thank you for finding my eggs <player>! I have received the <egg1>, <egg2>, and <egg3> from you. Please keep looking for more!</green>";
|
|
||||||
public static String REWARD = "<green>Thank you! You've turned in 4 unique eggs and earned a prize!</green>";
|
|
||||||
public static String DUPLICATE_EGGS = "<yellow>Those are duplicates I already have. Bring me new colors!</yellow>";
|
|
||||||
public static String GUI_TITLE = "<gold>Turn in Eggs</gold>";
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static void load() {
|
|
||||||
LEFT_CLICK_INTRO = config.getString(prefix, "left-click-intro", LEFT_CLICK_INTRO);
|
|
||||||
NO_EGGS = config.getString(prefix, "no-eggs", NO_EGGS);
|
|
||||||
THANK_YOU = config.getString(prefix, "thank-you", THANK_YOU);
|
|
||||||
REWARD = config.getString(prefix, "reward", REWARD);
|
|
||||||
DUPLICATE_EGGS = config.getString(prefix, "duplicate-eggs", DUPLICATE_EGGS);
|
|
||||||
GUI_TITLE = config.getString(prefix, "gui-title", GUI_TITLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SETPRIZE {
|
|
||||||
private static final String prefix = "setprize.";
|
|
||||||
public static String SUCCESS = "<green>Added the item in your hand as a possible prize.</green>";
|
|
||||||
public static String EMPTY_HAND = "<red>You must hold an item to set it as a prize.</red>";
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static void load() {
|
|
||||||
SUCCESS = config.getString(prefix, "success", SUCCESS);
|
|
||||||
EMPTY_HAND = config.getString(prefix, "empty-hand", EMPTY_HAND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
package com.alttd.easter.data;
|
|
||||||
|
|
||||||
import com.alttd.easter.egg.EggType;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DataManager {
|
|
||||||
|
|
||||||
private final File file;
|
|
||||||
private final YamlConfiguration yaml;
|
|
||||||
private final Map<UUID, Set<EggType>> playerEggs = new HashMap<>();
|
|
||||||
|
|
||||||
public DataManager(org.bukkit.plugin.Plugin plugin) {
|
|
||||||
this.file = new File(plugin.getDataFolder(), "data.yml");
|
|
||||||
this.yaml = new YamlConfiguration();
|
|
||||||
if (file.exists()) {
|
|
||||||
try {
|
|
||||||
yaml.load(file);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void load() {
|
|
||||||
for (String key : yaml.getKeys(false)) {
|
|
||||||
try {
|
|
||||||
UUID uuid = UUID.fromString(key);
|
|
||||||
List<String> list = yaml.getStringList(key);
|
|
||||||
Set<EggType> types = list.stream().map(s -> {
|
|
||||||
try {
|
|
||||||
return EggType.valueOf(s);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
||||||
playerEggs.put(uuid, types);
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
for (Map.Entry<UUID, Set<EggType>> e : playerEggs.entrySet()) {
|
|
||||||
List<String> list = e.getValue().stream().map(Enum::name).toList();
|
|
||||||
yaml.set(e.getKey().toString(), list);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
yaml.save(file);
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<EggType> getPlayerEggs(UUID uuid) {
|
|
||||||
return playerEggs.computeIfAbsent(uuid, u -> new HashSet<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int addEggs(UUID uuid, Collection<EggType> newTypes) {
|
|
||||||
Set<EggType> set = getPlayerEggs(uuid);
|
|
||||||
int before = set.size();
|
|
||||||
set.addAll(newTypes);
|
|
||||||
return set.size() - before; // number of newly added uniques
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
package com.alttd.easter.egg;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
|
|
||||||
public enum EggType {
|
|
||||||
BROWN_HUSK(Material.BROWN_GLAZED_TERRACOTTA, EntityType.HUSK, Enchantment.FIRE_PROTECTION, 2),
|
|
||||||
RED_SPIDER(Material.RED_GLAZED_TERRACOTTA, EntityType.SPIDER, Enchantment.BANE_OF_ARTHROPODS, 2),
|
|
||||||
ORANGE_BLAZE(Material.ORANGE_GLAZED_TERRACOTTA, EntityType.BLAZE, Enchantment.FIRE_ASPECT, 2),
|
|
||||||
YELLOW_PIGLIN(Material.YELLOW_GLAZED_TERRACOTTA, EntityType.PIGLIN, Enchantment.FORTUNE, 2),
|
|
||||||
LIME_CREEPER(Material.LIME_GLAZED_TERRACOTTA, EntityType.CREEPER, Enchantment.BLAST_PROTECTION, 2),
|
|
||||||
GREEN_ZOMBIE(Material.GREEN_GLAZED_TERRACOTTA, EntityType.ZOMBIE, Enchantment.FEATHER_FALLING, 2),
|
|
||||||
LIGHT_BLUE_STRAY(Material.LIGHT_BLUE_GLAZED_TERRACOTTA, EntityType.STRAY, Enchantment.FROST_WALKER, 2),
|
|
||||||
CYAN_GUARDIAN(Material.CYAN_GLAZED_TERRACOTTA, EntityType.GUARDIAN, Enchantment.THORNS, 2),
|
|
||||||
BLUE_WARDEN(Material.BLUE_GLAZED_TERRACOTTA, EntityType.WARDEN, Enchantment.SWIFT_SNEAK, 2),
|
|
||||||
PURPLE_ENDER_DRAGON(Material.PURPLE_GLAZED_TERRACOTTA, EntityType.ENDER_DRAGON, Enchantment.POWER, 2),
|
|
||||||
MAGENTA_ENDERMAN(Material.MAGENTA_GLAZED_TERRACOTTA, EntityType.ENDERMAN, Enchantment.INFINITY, 2),
|
|
||||||
PINK_HOGLIN(Material.PINK_GLAZED_TERRACOTTA, EntityType.HOGLIN, Enchantment.PIERCING, 2),
|
|
||||||
WHITE_SKELETON(Material.WHITE_GLAZED_TERRACOTTA, EntityType.SKELETON, Enchantment.MULTISHOT, 2),
|
|
||||||
LIGHT_GRAY_SILVERFISH(Material.LIGHT_GRAY_GLAZED_TERRACOTTA, EntityType.SILVERFISH, Enchantment.EFFICIENCY, 2),
|
|
||||||
GRAY_WITHER(Material.GRAY_GLAZED_TERRACOTTA, EntityType.WITHER, Enchantment.SMITE, 2),
|
|
||||||
BLACK_WITHER_SKELETON(Material.BLACK_GLAZED_TERRACOTTA, EntityType.WITHER_SKELETON, Enchantment.LOOTING, 2);
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Material material;
|
|
||||||
private final EntityType entityType;
|
|
||||||
@Getter
|
|
||||||
private final Enchantment enchantment;
|
|
||||||
@Getter
|
|
||||||
private final int enchantLevel;
|
|
||||||
|
|
||||||
EggType(Material material, EntityType entityType, Enchantment enchantment, int enchantLevel) {
|
|
||||||
this.material = material;
|
|
||||||
this.entityType = entityType;
|
|
||||||
this.enchantment = enchantment;
|
|
||||||
this.enchantLevel = enchantLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EggType fromEntityType(EntityType entityType) {
|
|
||||||
for (EggType type : values()) {
|
|
||||||
if (type.entityType == entityType) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
package com.alttd.easter.glow;
|
|
||||||
|
|
||||||
import com.alttd.easter.egg.EggType;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
|
||||||
import org.bukkit.scoreboard.Team;
|
|
||||||
|
|
||||||
public class GlowManager {
|
|
||||||
|
|
||||||
private final Scoreboard scoreboard;
|
|
||||||
|
|
||||||
public GlowManager(org.bukkit.plugin.Plugin plugin) {
|
|
||||||
this.scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyGlow(Entity entity, EggType type) {
|
|
||||||
String teamName = ("easter_" + type.name()).toLowerCase();
|
|
||||||
Team team = scoreboard.getTeam(teamName);
|
|
||||||
if (team == null) {
|
|
||||||
team = scoreboard.registerNewTeam(teamName);
|
|
||||||
team.setCanSeeFriendlyInvisibles(false);
|
|
||||||
team.setAllowFriendlyFire(true);
|
|
||||||
team.color(colorFor(type));
|
|
||||||
}
|
|
||||||
String entry = entity.getUniqueId().toString();
|
|
||||||
if (!team.hasEntry(entry)) {
|
|
||||||
team.addEntry(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private NamedTextColor colorFor(EggType type) {
|
|
||||||
return switch (type) {
|
|
||||||
case BROWN_HUSK -> NamedTextColor.DARK_RED; // closest
|
|
||||||
case RED_SPIDER -> NamedTextColor.RED;
|
|
||||||
case ORANGE_BLAZE -> NamedTextColor.GOLD;
|
|
||||||
case YELLOW_PIGLIN -> NamedTextColor.YELLOW;
|
|
||||||
case LIME_CREEPER -> NamedTextColor.GREEN;
|
|
||||||
case GREEN_ZOMBIE -> NamedTextColor.DARK_GREEN;
|
|
||||||
case LIGHT_BLUE_STRAY -> NamedTextColor.AQUA;
|
|
||||||
case CYAN_GUARDIAN -> NamedTextColor.DARK_AQUA;
|
|
||||||
case BLUE_WARDEN -> NamedTextColor.BLUE;
|
|
||||||
case PURPLE_ENDER_DRAGON -> NamedTextColor.DARK_PURPLE;
|
|
||||||
case MAGENTA_ENDERMAN -> NamedTextColor.LIGHT_PURPLE;
|
|
||||||
case PINK_HOGLIN -> NamedTextColor.LIGHT_PURPLE;
|
|
||||||
case WHITE_SKELETON -> NamedTextColor.WHITE;
|
|
||||||
case LIGHT_GRAY_SILVERFISH -> NamedTextColor.GRAY;
|
|
||||||
case GRAY_WITHER -> NamedTextColor.DARK_GRAY;
|
|
||||||
case BLACK_WITHER_SKELETON -> NamedTextColor.BLACK;
|
|
||||||
default -> NamedTextColor.WHITE;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,130 +0,0 @@
|
||||||
package com.alttd.easter.gui;
|
|
||||||
|
|
||||||
import com.alttd.easter.config.Messages;
|
|
||||||
import com.alttd.easter.data.DataManager;
|
|
||||||
import com.alttd.easter.egg.EggType;
|
|
||||||
import com.alttd.easter.util.ItemUtils;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class TurnInGuiManager implements Listener {
|
|
||||||
|
|
||||||
private final DataManager dataManager;
|
|
||||||
private final Map<UUID, Inventory> openInventories = new HashMap<>();
|
|
||||||
|
|
||||||
public TurnInGuiManager(DataManager dataManager) {
|
|
||||||
this.dataManager = dataManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String title() {
|
|
||||||
// crude strip of minimessage tags for inventory title
|
|
||||||
String mm = Messages.RABBIT.GUI_TITLE;
|
|
||||||
String plain = mm.replaceAll("<[^>]+>", "");
|
|
||||||
if (plain.isBlank()) {
|
|
||||||
plain = "Turn in Eggs";
|
|
||||||
}
|
|
||||||
return plain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void open(Player player) {
|
|
||||||
Inventory inv = Bukkit.createInventory(player, 27, title());
|
|
||||||
openInventories.put(player.getUniqueId(), inv);
|
|
||||||
player.openInventory(inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onClick(InventoryClickEvent event) {
|
|
||||||
if (!(event.getWhoClicked() instanceof Player player)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Inventory top = openInventories.get(player.getUniqueId());
|
|
||||||
if (top == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!event.getView().getTopInventory().equals(top)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If clicking in player inventory with shift-click, prevent moving non-egg items into GUI
|
|
||||||
if (event.isShiftClick() && event.getClickedInventory() != null && event.getClickedInventory().equals(player.getInventory())) {
|
|
||||||
ItemStack stack = event.getCurrentItem();
|
|
||||||
if (stack != null && !stack.getType().isAir() && !ItemUtils.isEggItem(stack)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If placing an item into the GUI (cursor over top inventory), only allow egg items
|
|
||||||
boolean inTop = event.getRawSlot() < top.getSize() && event.getRawSlot() >= 0;
|
|
||||||
if (inTop) {
|
|
||||||
ItemStack cursor = event.getCursor();
|
|
||||||
if (!cursor.getType().isAir() && !ItemUtils.isEggItem(cursor)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onClose(InventoryCloseEvent event) {
|
|
||||||
Player player = (Player) event.getPlayer();
|
|
||||||
Inventory top = openInventories.remove(player.getUniqueId());
|
|
||||||
if (top == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!event.getInventory().equals(top)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// collect egg items and clear them from the GUI so they don't drop
|
|
||||||
Set<EggType> submitted = new HashSet<>();
|
|
||||||
for (ItemStack item : top.getContents()) {
|
|
||||||
if (ItemUtils.isEggItem(item)) {
|
|
||||||
EggType type = ItemUtils.getEggType(item);
|
|
||||||
if (type != null) {
|
|
||||||
submitted.add(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
top.clear();
|
|
||||||
if (submitted.isEmpty()) {
|
|
||||||
player.sendRichMessage(Messages.RABBIT.NO_EGGS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dataManager.addEggs(player.getUniqueId(), submitted);
|
|
||||||
dataManager.save();
|
|
||||||
// Dialog formatting for submission summary
|
|
||||||
List<String> colors = submitted.stream().map(ItemUtils::colorName).toList();
|
|
||||||
if (colors.size() == 1) {
|
|
||||||
player.sendRichMessage(Messages.RABBIT.ONE_EGG,
|
|
||||||
Placeholder.parsed("player", player.getName()),
|
|
||||||
Placeholder.parsed("egg1", colors.getFirst())
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
String c1 = !colors.isEmpty() ? colors.get(0) : "";
|
|
||||||
String c2 = colors.size() > 1 ? colors.get(1) : "";
|
|
||||||
String c3 = colors.size() > 2 ? colors.get(2) : "";
|
|
||||||
player.sendRichMessage(Messages.RABBIT.MULTI_EGGS,
|
|
||||||
Placeholder.parsed("player", player.getName()),
|
|
||||||
Placeholder.parsed("egg1", c1),
|
|
||||||
Placeholder.parsed("egg2", c2),
|
|
||||||
Placeholder.parsed("egg3", c3)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
int total = dataManager.getPlayerEggs(player.getUniqueId()).size();
|
|
||||||
if (total % 4 == 0) {
|
|
||||||
var prize = com.alttd.easter.config.Config.PRIZES.getRandomPrize();
|
|
||||||
if (prize != null) {
|
|
||||||
player.getInventory().addItem(prize);
|
|
||||||
}
|
|
||||||
player.sendRichMessage(Messages.RABBIT.REWARD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
package com.alttd.easter.listeners;
|
|
||||||
|
|
||||||
import com.alttd.easter.egg.EggType;
|
|
||||||
import com.alttd.easter.util.ItemUtils;
|
|
||||||
import com.alttd.easter.util.Keys;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
public class DeathListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onDeath(EntityDeathEvent event) {
|
|
||||||
LivingEntity entity = event.getEntity();
|
|
||||||
String eggName = entity.getPersistentDataContainer().get(Keys.EGG_ENTITY, PersistentDataType.STRING);
|
|
||||||
if (eggName == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EggType type;
|
|
||||||
try {
|
|
||||||
type = EggType.valueOf(eggName);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Ensure the egg drops
|
|
||||||
event.getDrops().add(ItemUtils.createEggItem(type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
package com.alttd.easter.listeners;
|
|
||||||
|
|
||||||
import com.alttd.easter.config.Config;
|
|
||||||
import com.alttd.easter.egg.EggType;
|
|
||||||
import com.alttd.easter.glow.GlowManager;
|
|
||||||
import com.alttd.easter.util.ItemUtils;
|
|
||||||
import com.alttd.easter.util.Keys;
|
|
||||||
import org.bukkit.entity.Creature;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
@SuppressWarnings("ClassCanBeRecord")
|
|
||||||
public class SpawnListener implements Listener {
|
|
||||||
|
|
||||||
private final GlowManager glowManager;
|
|
||||||
|
|
||||||
public SpawnListener(GlowManager glowManager) {
|
|
||||||
this.glowManager = glowManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onNaturalSpawn(CreatureSpawnEvent event) {
|
|
||||||
if (event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(event.getEntity() instanceof Creature creature)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EntityType type = event.getEntityType();
|
|
||||||
EggType eggType = EggType.fromEntityType(type);
|
|
||||||
if (eggType == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
double chance = Config.EGGS.SPAWN_CHANCE;
|
|
||||||
if (ThreadLocalRandom.current().nextDouble() >= chance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack eggItem = ItemUtils.createEggItem(eggType);
|
|
||||||
EntityEquipment equipment = creature.getEquipment();
|
|
||||||
equipment.setHelmet(eggItem);
|
|
||||||
equipment.setHelmetDropChance(1.0f);
|
|
||||||
// tag entity so we know it's an egg carrier
|
|
||||||
creature.getPersistentDataContainer().set(Keys.EGG_ENTITY, PersistentDataType.STRING, eggType.name());
|
|
||||||
creature.setGlowing(true);
|
|
||||||
glowManager.applyGlow(creature, eggType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
||||||
package com.alttd.easter.npc;
|
|
||||||
|
|
||||||
import com.alttd.easter.config.Config;
|
|
||||||
import com.alttd.easter.config.Messages;
|
|
||||||
import com.alttd.easter.gui.TurnInGuiManager;
|
|
||||||
import com.alttd.easter.util.Keys;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Rabbit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
@SuppressWarnings("ClassCanBeRecord")
|
|
||||||
public class RabbitNpcManager implements Listener {
|
|
||||||
|
|
||||||
private final org.bukkit.plugin.Plugin plugin;
|
|
||||||
private final com.alttd.easter.gui.TurnInGuiManager turnInGuiManager;
|
|
||||||
|
|
||||||
public RabbitNpcManager(Plugin plugin, TurnInGuiManager turnInGuiManager) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.turnInGuiManager = turnInGuiManager;
|
|
||||||
spawnOrFindRabbit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
|
||||||
spawnOrFindRabbit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void spawnOrFindRabbit() {
|
|
||||||
// Find existing rabbit with tag, else spawn new at config location
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
|
||||||
for (Entity e : world.getEntitiesByClass(Rabbit.class)) {
|
|
||||||
if (e.getPersistentDataContainer().has(Keys.RABBIT_NPC, PersistentDataType.BYTE)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var loc = Config.RABBIT.getLocation(plugin.getServer());
|
|
||||||
if (loc == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Rabbit rabbit = (Rabbit) loc.getWorld().spawnEntity(loc, EntityType.RABBIT);
|
|
||||||
rabbit.setCustomNameVisible(true);
|
|
||||||
rabbit.customName(net.kyori.adventure.text.Component.text("Easter Bunny"));
|
|
||||||
rabbit.getPersistentDataContainer().set(Keys.RABBIT_NPC, PersistentDataType.BYTE, (byte) 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
|
||||||
if (!(event.getRightClicked() instanceof Rabbit) && !(event.getRightClicked() instanceof org.bukkit.entity.LivingEntity le && le.getPersistentDataContainer().has(Keys.RABBIT_NPC, PersistentDataType.BYTE))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
// Right click -> open GUI
|
|
||||||
openTurnIn(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLeftClick(EntityDamageByEntityEvent event) {
|
|
||||||
if (!(event.getEntity() instanceof org.bukkit.entity.LivingEntity le)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!le.getPersistentDataContainer().has(Keys.RABBIT_NPC, PersistentDataType.BYTE)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(event.getDamager() instanceof Player player)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
player.sendRichMessage(Messages.RABBIT.LEFT_CLICK_INTRO,
|
|
||||||
Placeholder.parsed("player", player.getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openTurnIn(Player player) {
|
|
||||||
// Delegate to TurnInGuiManager which controls the inventory and submission flow
|
|
||||||
turnInGuiManager.open(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
package com.alttd.easter.util;
|
|
||||||
|
|
||||||
import com.alttd.easter.egg.EggType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.inventory.ItemFlag;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class ItemUtils {
|
|
||||||
|
|
||||||
public static String colorName(EggType type) {
|
|
||||||
return switch (type) {
|
|
||||||
case BROWN_HUSK -> "Brown";
|
|
||||||
case RED_SPIDER -> "Red";
|
|
||||||
case ORANGE_BLAZE -> "Orange";
|
|
||||||
case YELLOW_PIGLIN -> "Yellow";
|
|
||||||
case LIME_CREEPER -> "Lime";
|
|
||||||
case GREEN_ZOMBIE -> "Green";
|
|
||||||
case LIGHT_BLUE_STRAY -> "Light Blue";
|
|
||||||
case CYAN_GUARDIAN -> "Cyan";
|
|
||||||
case BLUE_WARDEN -> "Blue";
|
|
||||||
case PURPLE_ENDER_DRAGON -> "Purple";
|
|
||||||
case MAGENTA_ENDERMAN -> "Magenta";
|
|
||||||
case PINK_HOGLIN -> "Pink";
|
|
||||||
case WHITE_SKELETON -> "White";
|
|
||||||
case LIGHT_GRAY_SILVERFISH -> "Light Grey";
|
|
||||||
case GRAY_WITHER -> "Grey";
|
|
||||||
case BLACK_WITHER_SKELETON -> "Black";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack createEggItem(EggType type) {
|
|
||||||
ItemStack item = new ItemStack(type.getMaterial());
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
meta.addEnchant(type.getEnchantment(), type.getEnchantLevel(), true);
|
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
|
||||||
meta.displayName(Component.text("Easter Egg - " + prettify(type.name()), NamedTextColor.GOLD));
|
|
||||||
meta.getPersistentDataContainer().set(Keys.EGG_ITEM, PersistentDataType.STRING, type.name());
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEggItem(ItemStack item) {
|
|
||||||
if (item == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return meta.getPersistentDataContainer().has(Keys.EGG_ITEM, PersistentDataType.STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EggType getEggType(ItemStack item) {
|
|
||||||
if (!isEggItem(item)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String name = item.getItemMeta().getPersistentDataContainer().get(Keys.EGG_ITEM, PersistentDataType.STRING);
|
|
||||||
try {
|
|
||||||
return name == null ? null : EggType.valueOf(name);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String prettify(String name) {
|
|
||||||
String[] parts = name.toLowerCase().split("_");
|
|
||||||
List<String> out = new ArrayList<>();
|
|
||||||
for (String p : parts) {
|
|
||||||
if (p.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
out.add(Character.toUpperCase(p.charAt(0)) + p.substring(1));
|
|
||||||
}
|
|
||||||
return String.join(" ", out);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemUtils() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package com.alttd.easter.util;
|
|
||||||
|
|
||||||
import com.alttd.easter.Easter;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
|
|
||||||
public final class Keys {
|
|
||||||
public static final NamespacedKey EGG_ITEM = new NamespacedKey(Easter.getPlugin(Easter.class), "egg-item");
|
|
||||||
public static final NamespacedKey EGG_ENTITY = new NamespacedKey(Easter.getPlugin(Easter.class), "egg-entity");
|
|
||||||
public static final NamespacedKey RABBIT_NPC = new NamespacedKey(Easter.getPlugin(Easter.class), "rabbit-npc");
|
|
||||||
|
|
||||||
private Keys() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
name: Easter
|
|
||||||
main: com.alttd.easter.Easter
|
|
||||||
version: ${version}
|
|
||||||
description: Altitude's Easter plugin
|
|
||||||
api-version: '1.21'
|
|
||||||
author: Altitude
|
|
||||||
commands:
|
|
||||||
easter:
|
|
||||||
description: Easter main command
|
|
||||||
usage: /<command>
|
|
||||||
aliases: [ easter ]
|
|
||||||
permission: playerutils.use
|
|
||||||
permissions:
|
|
||||||
easter.reload:
|
|
||||||
description: Reload the Easter plugin
|
|
||||||
default: op
|
|
||||||
easter.setprize:
|
|
||||||
description: Set the held item as a prize
|
|
||||||
default: op
|
|
||||||
Loading…
Reference in New Issue
Block a user