attempted to start adding quests
This commit is contained in:
parent
b07eebcfc8
commit
1ecf4508e8
|
|
@ -1,5 +1,11 @@
|
||||||
package com.alttd.altitudequests;
|
package com.alttd.altitudequests;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.config.Config;
|
||||||
|
import com.alttd.altitudequests.config.DatabaseConfig;
|
||||||
|
import com.alttd.altitudequests.config.LocalConfig;
|
||||||
|
import com.alttd.altitudequests.config.MessagesConfig;
|
||||||
|
import com.alttd.altitudequests.events.TalkToQuest;
|
||||||
|
import com.alttd.altitudequests.util.Logger;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class AQuests extends JavaPlugin {
|
public final class AQuests extends JavaPlugin {
|
||||||
|
|
@ -17,12 +23,24 @@ public final class AQuests extends JavaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
Config.reload();
|
||||||
|
DatabaseConfig.reload();
|
||||||
|
MessagesConfig.reload();
|
||||||
|
LocalConfig.reload();
|
||||||
|
|
||||||
|
registerEvents();
|
||||||
|
|
||||||
|
Logger.info("--------------------------------------------------");
|
||||||
|
Logger.info("AQuest started");
|
||||||
|
Logger.info("--------------------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
// Plugin shutdown logic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerEvents() {
|
||||||
|
getServer().getPluginManager().registerEvents(new TalkToQuest(), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.altitudequests.commands;
|
package com.alttd.altitudequests.commands;
|
||||||
|
|
||||||
import com.alttd.altitudequests.AQuests;
|
import com.alttd.altitudequests.AQuests;
|
||||||
|
import com.alttd.altitudequests.commands.subcommands.CommandCreateScruff;
|
||||||
import com.alttd.altitudequests.commands.subcommands.CommandHelp;
|
import com.alttd.altitudequests.commands.subcommands.CommandHelp;
|
||||||
import com.alttd.altitudequests.commands.subcommands.CommandReload;
|
import com.alttd.altitudequests.commands.subcommands.CommandReload;
|
||||||
import com.alttd.altitudequests.config.Config;
|
import com.alttd.altitudequests.config.Config;
|
||||||
|
|
@ -31,7 +32,8 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
||||||
|
|
||||||
subCommands = Arrays.asList(
|
subCommands = Arrays.asList(
|
||||||
new CommandHelp(this),
|
new CommandHelp(this),
|
||||||
new CommandReload());
|
new CommandReload(),
|
||||||
|
new CommandCreateScruff());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
package com.alttd.altitudequests.commands.subcommands;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.commands.SubCommand;
|
||||||
|
import com.alttd.altitudequests.config.Config;
|
||||||
|
import com.alttd.altitudequests.config.LocalConfig;
|
||||||
|
import com.alttd.altitudequests.config.MessagesConfig;
|
||||||
|
import com.alttd.altitudequests.util.Utilities;
|
||||||
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.*;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CommandCreateScruff extends SubCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
|
if (args.length != 8) {
|
||||||
|
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = Bukkit.getServer().getWorld(args[7]);
|
||||||
|
if (world == null) {
|
||||||
|
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Location location = new Location(world, Double.parseDouble(args[2]),Double.parseDouble(args[3]), Double.parseDouble(args[4]),
|
||||||
|
Float.parseFloat(args[5]), Float.parseFloat(args[6]));
|
||||||
|
Wolf wolf = (Wolf) world.spawnEntity(location, EntityType.WOLF, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||||
|
wolf.setPersistent(true);
|
||||||
|
wolf.setInvulnerable(true);
|
||||||
|
wolf.setGravity(false);
|
||||||
|
wolf.setSilent(true);
|
||||||
|
wolf.setAI(false);
|
||||||
|
wolf.setCollarColor(DyeColor.MAGENTA);
|
||||||
|
wolf.setCustomNameVisible(true);
|
||||||
|
wolf.customName(getMiniMessage().deserialize("Scruff"));
|
||||||
|
|
||||||
|
UUID uuid = wolf.getUniqueId();
|
||||||
|
|
||||||
|
LocalConfig.setActiveNPC(uuid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "createscruff";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||||
|
List<String> res = new ArrayList<>();
|
||||||
|
switch (args.length) {
|
||||||
|
case 2 -> {
|
||||||
|
if (commandSender instanceof Player player) {
|
||||||
|
res.add(String.valueOf(Utilities.round(player.getLocation().getX(), 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 3 -> {
|
||||||
|
if (commandSender instanceof Player player) {
|
||||||
|
res.add(String.valueOf(Utilities.round(player.getLocation().getY(), 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 4 -> {
|
||||||
|
if (commandSender instanceof Player player) {
|
||||||
|
res.add(String.valueOf(Utilities.round(player.getLocation().getZ(), 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 5 -> {
|
||||||
|
if (commandSender instanceof Player player) {
|
||||||
|
res.add(String.valueOf(Utilities.round(player.getLocation().getYaw(), 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 6 -> {
|
||||||
|
if (commandSender instanceof Player player) {
|
||||||
|
res.add(String.valueOf(Utilities.round(player.getLocation().getPitch(), 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 7 -> {
|
||||||
|
if (commandSender instanceof Player player) {
|
||||||
|
res.add(player.getLocation().getWorld().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return MessagesConfig.CREATE_SCRUFF_MESSAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ package com.alttd.altitudequests.commands.subcommands;
|
||||||
|
|
||||||
import com.alttd.altitudequests.commands.CommandManager;
|
import com.alttd.altitudequests.commands.CommandManager;
|
||||||
import com.alttd.altitudequests.commands.SubCommand;
|
import com.alttd.altitudequests.commands.SubCommand;
|
||||||
import com.alttd.altitudequests.config.Config;
|
import com.alttd.altitudequests.config.MessagesConfig;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -20,7 +20,7 @@ public class CommandHelp extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
|
commandSender.sendMiniMessage(MessagesConfig.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
|
||||||
.getSubCommands().stream()
|
.getSubCommands().stream()
|
||||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||||
.map(SubCommand::getHelpMessage)
|
.map(SubCommand::getHelpMessage)
|
||||||
|
|
@ -40,6 +40,6 @@ public class CommandHelp extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return Config.HELP_MESSAGE;
|
return MessagesConfig.HELP_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package com.alttd.altitudequests.commands.subcommands;
|
||||||
|
|
||||||
import com.alttd.altitudequests.commands.SubCommand;
|
import com.alttd.altitudequests.commands.SubCommand;
|
||||||
import com.alttd.altitudequests.config.Config;
|
import com.alttd.altitudequests.config.Config;
|
||||||
|
import com.alttd.altitudequests.config.DatabaseConfig;
|
||||||
|
import com.alttd.altitudequests.config.LocalConfig;
|
||||||
|
import com.alttd.altitudequests.config.MessagesConfig;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -12,6 +15,9 @@ public class CommandReload extends SubCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
Config.reload();
|
Config.reload();
|
||||||
|
DatabaseConfig.reload();
|
||||||
|
MessagesConfig.reload();
|
||||||
|
LocalConfig.reload();
|
||||||
commandSender.sendMiniMessage("<green>Reloaded AltitudeQuests config.</green>", null);
|
commandSender.sendMiniMessage("<green>Reloaded AltitudeQuests config.</green>", null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +34,6 @@ public class CommandReload extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return Config.RELOAD_HELP_MESSAGE;
|
return MessagesConfig.RELOAD_HELP_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,11 @@ abstract class AbstractConfig {
|
||||||
return yaml.getList(path, yaml.getList(path));
|
return yaml.getList(path, yaml.getList(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> getStringList(String path, List<String> def) {
|
||||||
|
yaml.addDefault(path, def);
|
||||||
|
return yaml.getStringList(path);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Map<String, T> getMap(final @NonNull String path, final @Nullable Map<String, T> def) {
|
<T> Map<String, T> getMap(final @NonNull String path, final @Nullable Map<String, T> def) {
|
||||||
final ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
|
final ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.altitudequests.config;
|
package com.alttd.altitudequests.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class Config extends AbstractConfig {
|
public final class Config extends AbstractConfig {
|
||||||
|
|
||||||
|
|
@ -9,7 +10,6 @@ public final class Config extends AbstractConfig {
|
||||||
public Config() {
|
public Config() {
|
||||||
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "AltitudeQuests"), "config.yml");
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "AltitudeQuests"), "config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
config = new Config();
|
config = new Config();
|
||||||
|
|
||||||
|
|
@ -19,33 +19,29 @@ public final class Config extends AbstractConfig {
|
||||||
config.readConfig(Config.class, null);
|
config.readConfig(Config.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String HELP_MESSAGE_WRAPPER = "<gold>AltitudeQuests help:\n<commands></gold>";
|
|
||||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/aquest help</gold></green>";
|
|
||||||
public static String RELOAD_HELP_MESSAGE = "<green>Reload configs: <gold>/aquest reload</gold></green>";
|
|
||||||
|
|
||||||
private static void loadHelp() {
|
|
||||||
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
|
||||||
HELP_MESSAGE = config.getString("help.help", HELP_MESSAGE);
|
|
||||||
RELOAD_HELP_MESSAGE = config.getString("help.reload", RELOAD_HELP_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
|
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
|
||||||
public static String NO_CONSOLE = "<red>You cannot use this command from console.</red>";
|
public static String NO_CONSOLE = "<red>You cannot use this command from console.</red>";
|
||||||
|
|
||||||
private static void loadGeneric() {
|
private static void loadGeneric() {
|
||||||
NO_PERMISSION = config.getString("generic.no-permission", NO_PERMISSION);
|
NO_PERMISSION = config.getString("generic.no-permission", NO_PERMISSION);
|
||||||
NO_CONSOLE = config.getString("generic.no-console", NO_CONSOLE);
|
NO_CONSOLE = config.getString("generic.no-console", NO_CONSOLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadMessages() {
|
public static String QUEST_BOOK_AUTHOR = "<magenta>Scruff</magenta>";
|
||||||
|
public static String QUEST_BOOK_TITLE = "<green>Quest Title</green>";
|
||||||
|
public static List<String> QUEST_PAGES = List.of("Example");
|
||||||
|
private static void loadBook() {
|
||||||
|
QUEST_BOOK_AUTHOR = config.getString("book.author", QUEST_BOOK_AUTHOR);
|
||||||
|
QUEST_BOOK_TITLE = config.getString("book.title", QUEST_BOOK_TITLE);
|
||||||
|
QUEST_PAGES = config.getStringList("book.pages", QUEST_PAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadGUIText() {
|
private static void loadGUIText() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String NPC_NAME = "<light_purple>Scruff</light_purple>";
|
||||||
public static boolean DEBUG = false;
|
public static boolean DEBUG = false;
|
||||||
|
|
||||||
private static void loadSettings() {
|
private static void loadSettings() {
|
||||||
|
NPC_NAME = config.getString("settings.npd-name", NPC_NAME);
|
||||||
DEBUG = config.getBoolean("settings.debug", DEBUG);
|
DEBUG = config.getBoolean("settings.debug", DEBUG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.altitudequests.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class DatabaseConfig extends AbstractConfig {
|
||||||
|
|
||||||
|
static DatabaseConfig config;
|
||||||
|
public DatabaseConfig() {
|
||||||
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs"
|
||||||
|
+ File.separator + "AltitudeQuests"), "database.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
config = new DatabaseConfig();
|
||||||
|
config.readConfig(DatabaseConfig.class, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String DRIVER = "mysql";
|
||||||
|
public static String IP = "localhost";
|
||||||
|
public static String PORT = "3306";
|
||||||
|
public static String DATABASE_NAME = "AltitudeQuests";
|
||||||
|
public static String USERNAME = "root";
|
||||||
|
public static String PASSWORD = "root";
|
||||||
|
|
||||||
|
private static void loadDatabase() {
|
||||||
|
DRIVER = config.getString("database.driver", DRIVER);
|
||||||
|
IP = config.getString("database.ip", IP);
|
||||||
|
PORT = config.getString("database.port", PORT);
|
||||||
|
DATABASE_NAME = config.getString("database.name", DATABASE_NAME);
|
||||||
|
USERNAME = config.getString("database.username", USERNAME);
|
||||||
|
PASSWORD = config.getString("database.password", PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.alttd.altitudequests.config;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class LocalConfig extends AbstractConfig{
|
||||||
|
|
||||||
|
static LocalConfig config;
|
||||||
|
|
||||||
|
public LocalConfig() {
|
||||||
|
super("LocalConfig");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
config = new LocalConfig();
|
||||||
|
config.readConfig(LocalConfig.class, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID activeNPC = null;
|
||||||
|
|
||||||
|
private static void loadActiveNPC() {
|
||||||
|
activeNPC = UUID.fromString(config.getString("active-npc", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeActiveNPC() {
|
||||||
|
config.set("active-npc", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setActiveNPC(UUID uuid) {
|
||||||
|
config.set("active-npc", uuid.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.alttd.altitudequests.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MessagesConfig extends AbstractConfig{
|
||||||
|
|
||||||
|
static MessagesConfig config;
|
||||||
|
|
||||||
|
public MessagesConfig() {
|
||||||
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs"
|
||||||
|
+ File.separator + "AltitudeQuests"), "messages.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
config = new MessagesConfig();
|
||||||
|
config.readConfig(MessagesConfig.class, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String HELP_MESSAGE_WRAPPER = "<gold>AltitudeQuests help:\n<commands></gold>";
|
||||||
|
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/aquest help</gold></green>";
|
||||||
|
public static String RELOAD_HELP_MESSAGE = "<green>Reload configs: <gold>/aquest reload</gold></green>";
|
||||||
|
public static String CREATE_SCRUFF_MESSAGE = "<green>Create Scruff: <gold>/aquest createscruff <x> <y> <z> <yaw> <pitch> <world></gold></green>";
|
||||||
|
|
||||||
|
private static void loadHelp() {
|
||||||
|
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||||
|
HELP_MESSAGE = config.getString("help.help", HELP_MESSAGE);
|
||||||
|
RELOAD_HELP_MESSAGE = config.getString("help.reload", RELOAD_HELP_MESSAGE);
|
||||||
|
CREATE_SCRUFF_MESSAGE = config.getString("help.help-wrapper", CREATE_SCRUFF_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void loadCommandMessages() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
package com.alttd.altitudequests.database;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.AQuests;
|
||||||
|
import com.alttd.altitudequests.config.DatabaseConfig;
|
||||||
|
import com.alttd.altitudequests.util.Logger;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
|
||||||
|
private static Database instance = null;
|
||||||
|
public static Connection connection = null;
|
||||||
|
|
||||||
|
private Database() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Database getDatabase(){
|
||||||
|
if (instance == null)
|
||||||
|
instance = new Database();
|
||||||
|
return (instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
try {
|
||||||
|
openConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tables
|
||||||
|
createUserPointsTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the connection if it's not already open.
|
||||||
|
* @throws SQLException If it can't create the connection.
|
||||||
|
*/
|
||||||
|
private void openConnection() throws SQLException {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
connection = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://" + DatabaseConfig.IP + ":" + DatabaseConfig.PORT + "/" + DatabaseConfig.DATABASE_NAME +
|
||||||
|
"?autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true",
|
||||||
|
DatabaseConfig.USERNAME, DatabaseConfig.PASSWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createUserPointsTable() {
|
||||||
|
try {
|
||||||
|
String sql = "CREATE TABLE IF NOT EXISTS quest_progress(" +
|
||||||
|
"uuid VARCHAR(36) NOT NULL, " +
|
||||||
|
"quest VARCHAR(36) NOT NULL, " +
|
||||||
|
"prepare_progress INT NOT NULL, " +
|
||||||
|
"turn_in_progress INT NOT NULL, " +
|
||||||
|
"PRIMARY KEY (UUID, quest)" +
|
||||||
|
")";
|
||||||
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Logger.severe("Error while trying to create user point table");
|
||||||
|
Logger.severe("Shutting down AltitudeQuests");
|
||||||
|
Bukkit.getPluginManager().disablePlugin(AQuests.getInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/main/java/com/alttd/altitudequests/database/Queries.java
Normal file
35
src/main/java/com/alttd/altitudequests/database/Queries.java
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.alttd.altitudequests.database;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.objects.GoalType;
|
||||||
|
import com.alttd.altitudequests.util.Logger;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Queries {
|
||||||
|
|
||||||
|
public static int setUserProgress(UUID uuid, GoalType goalType, int progress) {
|
||||||
|
String sql = "INSERT VALUES (?, ?, ?) INTO user_seen " +
|
||||||
|
"WHERE uuid = ? AND goal_type = ? " +
|
||||||
|
"ON DUPLICATE KEY UPDATE progress = ?";
|
||||||
|
long time;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedStatement = Database.connection.prepareStatement(sql);
|
||||||
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
preparedStatement.setString(2, goalType.name());
|
||||||
|
preparedStatement.setInt(3, progress);
|
||||||
|
preparedStatement.setString(4, uuid.toString());
|
||||||
|
preparedStatement.setString(5, goalType.name());
|
||||||
|
preparedStatement.setInt(6, progress);
|
||||||
|
|
||||||
|
preparedStatement.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Logger.warning("Unable to set progress for %.", uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.alttd.altitudequests.events;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.objects.Quest;
|
||||||
|
import com.alttd.altitudequests.objects.quests.MineQuest;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MineBlocks implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
Quest quest = Quest.getDailyQuest(uuid);
|
||||||
|
if (quest == null || quest.isDone())
|
||||||
|
return;
|
||||||
|
if (quest instanceof MineQuest mineQuest)
|
||||||
|
mineQuest.mine(event.getBlock(), player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.altitudequests.events;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.config.Config;
|
||||||
|
import com.alttd.altitudequests.config.LocalConfig;
|
||||||
|
import net.kyori.adventure.inventory.Book;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class TalkToQuest implements Listener {
|
||||||
|
|
||||||
|
private static final Book book;
|
||||||
|
static {
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
book = Book.builder()
|
||||||
|
.author(miniMessage.deserialize(Config.QUEST_BOOK_AUTHOR))
|
||||||
|
.title(miniMessage.deserialize(Config.QUEST_BOOK_TITLE))
|
||||||
|
.pages(Config.QUEST_PAGES.stream()
|
||||||
|
.map(miniMessage::deserialize)
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||||
|
if (LocalConfig.activeNPC == null || !LocalConfig.activeNPC.equals(event.getRightClicked().getUniqueId()))
|
||||||
|
return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.getPlayer().openBook(book);
|
||||||
|
//TODO make it so there can be one book config per quest
|
||||||
|
//TODO make it so everything can be done with commands and just don't let them tab complete and do them through the book instead
|
||||||
|
//TODO in config allow a multitude of events to be prepared and randomly select from them at certain times of day?
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/main/java/com/alttd/altitudequests/gui/BookGUI.java
Normal file
5
src/main/java/com/alttd/altitudequests/gui/BookGUI.java
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.alttd.altitudequests.gui;
|
||||||
|
|
||||||
|
public class BookGUI {
|
||||||
|
|
||||||
|
}
|
||||||
20
src/main/java/com/alttd/altitudequests/gui/GUI.java
Normal file
20
src/main/java/com/alttd/altitudequests/gui/GUI.java
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.alttd.altitudequests.gui;
|
||||||
|
|
||||||
|
import net.kyori.adventure.inventory.Book;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface GUI {
|
||||||
|
HashMap<UUID, GUI> GUIByUUID = new HashMap<>();
|
||||||
|
|
||||||
|
void open(Player player);
|
||||||
|
|
||||||
|
GUIAction getGuiAction(int slot);
|
||||||
|
|
||||||
|
Inventory getInventory();
|
||||||
|
|
||||||
|
Book getBook();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.alttd.altitudequests.gui;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface GUIAction {
|
||||||
|
void click(Player player);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.alttd.altitudequests.objects;
|
||||||
|
|
||||||
|
public enum GoalType {
|
||||||
|
TALK,
|
||||||
|
MONEY,
|
||||||
|
MINE,
|
||||||
|
WALK
|
||||||
|
}
|
||||||
38
src/main/java/com/alttd/altitudequests/objects/Quest.java
Normal file
38
src/main/java/com/alttd/altitudequests/objects/Quest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.altitudequests.objects;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class Quest {
|
||||||
|
|
||||||
|
private static Quest dailyQuest = null;
|
||||||
|
private static final HashMap<UUID, Quest> dailyQuests = new HashMap<>();
|
||||||
|
private static Quest weeklyQuest = null;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private GoalType goalType;
|
||||||
|
//TODO add all data every quest needs
|
||||||
|
|
||||||
|
|
||||||
|
public Quest(String name, GoalType goalType) {
|
||||||
|
this.name = name;
|
||||||
|
this.goalType = goalType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Quest getDailyQuest(UUID uuid) {
|
||||||
|
if (!dailyQuests.containsKey(uuid))
|
||||||
|
dailyQuests.put(uuid, dailyQuest.initQuest());
|
||||||
|
return dailyQuests.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setActiveDailyQuest(Quest newQuest) {
|
||||||
|
Quest.dailyQuest = newQuest;
|
||||||
|
}
|
||||||
|
public static void setActiveWeeklyQuest(Quest newQuest) {
|
||||||
|
Quest.weeklyQuest = newQuest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isDone();
|
||||||
|
|
||||||
|
public abstract Quest initQuest();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.alttd.altitudequests.objects.quests;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.objects.GoalType;
|
||||||
|
import com.alttd.altitudequests.objects.Quest;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class MineQuest extends Quest {
|
||||||
|
|
||||||
|
public MineQuest(String name, GoalType goalType) {
|
||||||
|
super(name, goalType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDone() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Quest initQuest() {
|
||||||
|
return new MineQuest("Mine", GoalType.MINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mine(Block block, Player player) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.alttd.altitudequests.util;
|
||||||
|
|
||||||
|
public class Utilities {
|
||||||
|
public static double round(double num, int precision) {
|
||||||
|
double scale = Math.pow(10, precision);
|
||||||
|
return ((int) (num * scale)) / scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user