Added GUI's
Added player settings Added commands
This commit is contained in:
parent
71c5b76d88
commit
bc74d35faa
|
|
@ -5,9 +5,6 @@ dependencyResolutionManagement {
|
|||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/") // Paper
|
||||
maven("https://jitpack.io") { // Vault
|
||||
content { includeGroup("com.github.milkbowl") }
|
||||
}
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.alttd;
|
|||
import com.alttd.commands.CommandManager;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.config.DatabaseConfig;
|
||||
import com.alttd.database.Database;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AltitudeParticles extends JavaPlugin {
|
||||
|
|
@ -22,8 +24,11 @@ public class AltitudeParticles extends JavaPlugin {
|
|||
public void onEnable() {
|
||||
Config.reload();
|
||||
DatabaseConfig.reload();
|
||||
Database.getDatabase().init();
|
||||
new CommandManager();
|
||||
|
||||
Logger.info("--------------------------------------------------");
|
||||
Logger.info("Altitude Particles started");
|
||||
Logger.info("--------------------------------------------------");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.commands;
|
||||
|
||||
import com.alttd.AltitudeParticles;
|
||||
import com.alttd.commands.subcommands.CommandGUI;
|
||||
import com.alttd.commands.subcommands.CommandHelp;
|
||||
import com.alttd.commands.subcommands.CommandReload;
|
||||
import com.alttd.config.Config;
|
||||
|
|
@ -31,20 +32,17 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
|
||||
subCommands = Arrays.asList(
|
||||
new CommandHelp(this),
|
||||
new CommandReload());
|
||||
new CommandReload(),
|
||||
new CommandGUI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<config>", subCommands.stream()
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getHelpMessage)
|
||||
.collect(Collectors.joining("\n"))), null);
|
||||
return true;
|
||||
}
|
||||
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
SubCommand subCommand;
|
||||
if (args.length == 0)
|
||||
subCommand = getSubCommand("gui");
|
||||
else
|
||||
subCommand = getSubCommand(args[0]);
|
||||
|
||||
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
||||
commandSender.sendMiniMessage(Config.NO_PERMISSION, null);
|
||||
|
|
|
|||
38
src/main/java/com/alttd/commands/subcommands/CommandGUI.java
Normal file
38
src/main/java/com/alttd/commands/subcommands/CommandGUI.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package com.alttd.commands.subcommands;
|
||||
|
||||
import com.alttd.commands.SubCommand;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.gui.windows.OpenParticleGUI;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandGUI extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
|
||||
return true;
|
||||
}
|
||||
new OpenParticleGUI(player).open(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "gui";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.GUI_HELP_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +30,6 @@ public class CommandReload extends SubCommand {
|
|||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.RELOAD_MESSAGE;
|
||||
return Config.RELOAD_HELP_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@ public final class Config extends AbstractConfig {
|
|||
|
||||
public static String HELP_MESSAGE_WRAPPER = "<gold>AltitudeParticles help:\n<commands></gold>";
|
||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/apart help</gold></green>";
|
||||
public static String RELOAD_MESSAGE = "<green>Reload configs: <gold>/apart reload</gold></green>";
|
||||
public static String RELOAD_HELP_MESSAGE = "<green>Reload configs: <gold>/apart reload</gold></green>";
|
||||
public static String GUI_HELP_MESSAGE = "<green>Open GUI: <gold>/apart</gold> or <gold>/apart gui</gold>";
|
||||
|
||||
private static void loadHelp() {
|
||||
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||
HELP_MESSAGE = config.getString("help.help", HELP_MESSAGE);
|
||||
RELOAD_MESSAGE = config.getString("help.reload", RELOAD_MESSAGE);
|
||||
RELOAD_HELP_MESSAGE = config.getString("help.reload", RELOAD_HELP_MESSAGE);
|
||||
GUI_HELP_MESSAGE = config.getString("help.gui", GUI_HELP_MESSAGE);
|
||||
}
|
||||
|
||||
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
|
||||
|
|
@ -40,6 +42,25 @@ public final class Config extends AbstractConfig {
|
|||
private static void loadMessages() {
|
||||
}
|
||||
|
||||
public static String PARTICLE_TYPE_BUTTON_NAME = "<gold><name></gold>";
|
||||
public static String PARTICLE_TYPE_GUI_NAME = "<red>AltitudeParticles</red>";
|
||||
private static void loadGUIText() {
|
||||
config.getString("gui-text.particle-type-button-name", PARTICLE_TYPE_BUTTON_NAME);
|
||||
config.getString("gui-text.particles-type-gui-name", PARTICLE_TYPE_GUI_NAME);
|
||||
}
|
||||
|
||||
public static String SEE_OTHERS_ON = "<green>Particles visible</green>";
|
||||
public static String SEE_OTHERS_ON_DESC = "<dark_aqua>Click to hide particles</dark_aqua>";
|
||||
public static String SEE_OTHERS_OFF = "<red>Particles hidden</red>";
|
||||
public static String SEE_OTHERS_OFF_DESC = "<dark_aqua>Click to show particles</dark_aqua>";
|
||||
public static String PARTICLES_ON = "<green>Particles on</green>";
|
||||
public static String PARTICLES_ON_DESC = "<dark_aqua>Click to disable particles</dark_aqua>";
|
||||
public static String PARTICLES_OFF = "<red>Particles off</red>";
|
||||
public static String PARTICLES_OFF_DESC = "<dark_aqua>Click to enable particles</dark_aqua>";
|
||||
private static void loadGUIButtons() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean DEBUG = false;
|
||||
|
||||
private static void loadSettings() {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package com.alttd.config;
|
||||
|
||||
import com.alttd.database.Database;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DatabaseConfig extends AbstractConfig {
|
||||
|
||||
static DatabaseConfig config;
|
||||
static int version;
|
||||
public DatabaseConfig() {
|
||||
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs"
|
||||
+ File.separator + "AltitudeParticles"), "database.yml");
|
||||
|
|
@ -13,7 +14,7 @@ public class DatabaseConfig extends AbstractConfig {
|
|||
|
||||
public static void reload() {
|
||||
config = new DatabaseConfig();
|
||||
config.readConfig(Config.class, null);
|
||||
config.readConfig(DatabaseConfig.class, null);
|
||||
}
|
||||
|
||||
public static String DRIVER = "mysql";
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ public class Database {
|
|||
}
|
||||
|
||||
// Tables
|
||||
createUserPointsTable();
|
||||
createActiveParticlesTable();
|
||||
createUserSettingsTable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,7 +62,7 @@ public class Database {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createUserPointsTable() {
|
||||
private static void createActiveParticlesTable() {
|
||||
try {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS active_particles(" +
|
||||
"uuid VARCHAR(36) NOT NULL, " +
|
||||
|
|
@ -78,4 +79,21 @@ public class Database {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createUserSettingsTable() {
|
||||
try {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS user_settings(" +
|
||||
"uuid VARCHAR(36) NOT NULL, " +
|
||||
"particles_active BIT(1) NOT NULL DEFAULT b'1', " +
|
||||
"seeing_particles BIT(1) NOT NULL DEFAULT b'1', " +
|
||||
"PRIMARY KEY (uuid)" +
|
||||
")";
|
||||
connection.prepareStatement(sql).executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Logger.severe("Error while trying to create user point table");
|
||||
Logger.severe("Shutting down AltitudeParticles");
|
||||
Bukkit.getPluginManager().disablePlugin(AltitudeParticles.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,28 @@
|
|||
package com.alttd.database;
|
||||
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Queries {
|
||||
public static PlayerSettings getPlayerSettings(UUID uuid) {
|
||||
String sql = "SELECT * FROM user_settings WHERE uuid = ?";
|
||||
try {
|
||||
PreparedStatement preparedStatement = Database.connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1, uuid.toString());
|
||||
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
boolean particlesActive = resultSet.getInt("particles_active") == 1;
|
||||
boolean seeingParticles = resultSet.getInt("seeing_particles") == 1;
|
||||
return new PlayerSettings(particlesActive, seeingParticles, uuid);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.alttd.frameSpawners;
|
||||
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.objects.Frame;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class FrameSpawnerLocation extends BukkitRunnable {
|
||||
|
||||
int amount;
|
||||
List<Frame> frames;
|
||||
Iterator<Frame> iterator;
|
||||
Location location;
|
||||
public FrameSpawnerLocation(int amount, List<Frame> frames, Location location) {
|
||||
this.amount = amount;
|
||||
this.frames = frames;
|
||||
this.iterator = frames.iterator();
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (iterator.hasNext())
|
||||
iterator.next().spawn(location);
|
||||
else if (amount != 0)
|
||||
iterator = frames.iterator();
|
||||
else {
|
||||
this.cancel();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Stopped repeating task due to end of frames");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.alttd.frameSpawners;
|
||||
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.objects.Frame;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||
|
||||
int amount;
|
||||
List<Frame> frames;
|
||||
Iterator<Frame> iterator;
|
||||
Player player;
|
||||
public FrameSpawnerPlayer(int amount, List<Frame> frames, Player player) {
|
||||
this.amount = amount;
|
||||
this.frames = frames;
|
||||
this.iterator = frames.iterator();
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!player.isOnline()) {
|
||||
this.cancel();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Stopped repeating task due to player offline.");
|
||||
return;
|
||||
}
|
||||
if (iterator.hasNext())
|
||||
iterator.next().spawn(player.getLocation());
|
||||
else if (amount != 0)
|
||||
iterator = frames.iterator();
|
||||
else {
|
||||
this.cancel();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Stopped repeating task due to end of frames.");
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/main/java/com/alttd/gui/DefaultGUI.java
Normal file
51
src/main/java/com/alttd/gui/DefaultGUI.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package com.alttd.gui;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Merchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DefaultGUI implements GUI {
|
||||
|
||||
protected final Inventory inventory;
|
||||
protected final HashMap<Integer, GUIAction> actions;
|
||||
|
||||
public DefaultGUI(Component name) {
|
||||
inventory = Bukkit.createInventory(null, InventoryType.CHEST, name);
|
||||
actions = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setItem(int slot, @NotNull ItemStack item, @Nullable GUIAction action) {
|
||||
inventory.setItem(slot, item);
|
||||
if (action != null)
|
||||
actions.put(slot, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Player player) {
|
||||
player.openInventory(inventory);
|
||||
GUIByUUID.put(player.getUniqueId(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GUIAction getAction(int slot) {
|
||||
return actions.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Merchant getMerchant() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
20
src/main/java/com/alttd/gui/GUI.java
Normal file
20
src/main/java/com/alttd/gui/GUI.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package com.alttd.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.Merchant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface GUI {
|
||||
HashMap<UUID, GUI> GUIByUUID = new HashMap<>();
|
||||
|
||||
void open(Player player);
|
||||
|
||||
com.alttd.gui.GUIAction getAction(int slot);
|
||||
|
||||
Inventory getInventory();
|
||||
|
||||
Merchant getMerchant();
|
||||
}
|
||||
7
src/main/java/com/alttd/gui/GUIAction.java
Normal file
7
src/main/java/com/alttd/gui/GUIAction.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package com.alttd.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface GUIAction {
|
||||
void click(Player player);
|
||||
}
|
||||
44
src/main/java/com/alttd/gui/GUIListener.java
Normal file
44
src/main/java/com/alttd/gui/GUIListener.java
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package com.alttd.gui;
|
||||
|
||||
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.event.player.PlayerQuitEvent;
|
||||
|
||||
public class GUIListener implements Listener {
|
||||
|
||||
/**
|
||||
* Handles clicking inside a gui
|
||||
* @param event gui click event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event){
|
||||
if (!(event.getWhoClicked() instanceof Player player)){
|
||||
return;
|
||||
}
|
||||
|
||||
GUI gui = GUI.GUIByUUID.get(player.getUniqueId());
|
||||
if (gui == null || gui.getInventory() == null)
|
||||
return;
|
||||
if (!gui.getInventory().equals(event.getInventory()))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
GUIAction action = gui.getAction(event.getSlot());
|
||||
|
||||
if (action != null){
|
||||
action.click(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
GUI.GUIByUUID.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event){
|
||||
GUI.GUIByUUID.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
23
src/main/java/com/alttd/gui/actions/EnterParticleMenu.java
Normal file
23
src/main/java/com/alttd/gui/actions/EnterParticleMenu.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package com.alttd.gui.actions;
|
||||
|
||||
import com.alttd.gui.GUIAction;
|
||||
import com.alttd.gui.windows.ChooseParticleGUI;
|
||||
import com.alttd.objects.APartType;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class EnterParticleMenu implements GUIAction {
|
||||
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
private final APartType aPartType;
|
||||
|
||||
public EnterParticleMenu(APartType aPartType) {
|
||||
this.aPartType = aPartType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(Player player) {
|
||||
ChooseParticleGUI chooseParticleGUI = new ChooseParticleGUI(aPartType, miniMessage.deserialize(aPartType.getName()));
|
||||
chooseParticleGUI.open(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.alttd.gui.actions;
|
||||
|
||||
import com.alttd.gui.GUIAction;
|
||||
import com.alttd.gui.windows.OpenParticleGUI;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ToggleParticlesActive implements GUIAction {
|
||||
|
||||
OpenParticleGUI openParticleGUI;
|
||||
PlayerSettings playerSettings;
|
||||
|
||||
public ToggleParticlesActive(OpenParticleGUI openParticleGUI, PlayerSettings playerSettings) {
|
||||
this.openParticleGUI = openParticleGUI;
|
||||
this.playerSettings = playerSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(Player player) {
|
||||
playerSettings.toggleParticlesActive();
|
||||
openParticleGUI.updateSettingSlots(playerSettings);
|
||||
}
|
||||
}
|
||||
23
src/main/java/com/alttd/gui/actions/ToggleSeeParticles.java
Normal file
23
src/main/java/com/alttd/gui/actions/ToggleSeeParticles.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package com.alttd.gui.actions;
|
||||
|
||||
import com.alttd.gui.GUIAction;
|
||||
import com.alttd.gui.windows.OpenParticleGUI;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ToggleSeeParticles implements GUIAction {
|
||||
|
||||
OpenParticleGUI openParticleGUI;
|
||||
PlayerSettings playerSettings;
|
||||
|
||||
public ToggleSeeParticles(OpenParticleGUI openParticleGUI, PlayerSettings playerSettings) {
|
||||
this.openParticleGUI = openParticleGUI;
|
||||
this.playerSettings = playerSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(Player player) {
|
||||
playerSettings.toggleSeeingParticles();
|
||||
openParticleGUI.updateSettingSlots(playerSettings);
|
||||
}
|
||||
}
|
||||
11
src/main/java/com/alttd/gui/windows/ChooseParticleGUI.java
Normal file
11
src/main/java/com/alttd/gui/windows/ChooseParticleGUI.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package com.alttd.gui.windows;
|
||||
|
||||
import com.alttd.gui.DefaultGUI;
|
||||
import com.alttd.objects.APartType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class ChooseParticleGUI extends DefaultGUI {
|
||||
public ChooseParticleGUI(APartType aPartType, Component name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
95
src/main/java/com/alttd/gui/windows/OpenParticleGUI.java
Normal file
95
src/main/java/com/alttd/gui/windows/OpenParticleGUI.java
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package com.alttd.gui.windows;
|
||||
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.gui.DefaultGUI;
|
||||
import com.alttd.gui.actions.EnterParticleMenu;
|
||||
import com.alttd.gui.actions.ToggleParticlesActive;
|
||||
import com.alttd.gui.actions.ToggleSeeParticles;
|
||||
import com.alttd.objects.APartType;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import com.alttd.util.Logger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class OpenParticleGUI extends DefaultGUI {
|
||||
|
||||
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
private static final Component GUIName;
|
||||
private static final ItemStack seeOthersOn, seeOthersOff, particlesOn, particlesOff;
|
||||
|
||||
public OpenParticleGUI(Player player) {
|
||||
super(GUIName);
|
||||
int i = 10;
|
||||
for (APartType particlesType : APartType.values()) {
|
||||
if (i > 25) {
|
||||
Logger.warning("Unable to add the rest of the particles to the GUI (ran out of space)");
|
||||
break;
|
||||
}
|
||||
if (i == 17)
|
||||
i = 19;
|
||||
setItem(i++, particlesType.getItemStack(), new EnterParticleMenu(particlesType));
|
||||
}
|
||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
||||
if (playerSettings == null)
|
||||
return;
|
||||
setItem(17, playerSettings.isSeeingParticles() ? seeOthersOn : seeOthersOff, new ToggleSeeParticles(this, playerSettings));
|
||||
setItem(26, playerSettings.hasActiveParticles() ? particlesOn : particlesOff, new ToggleParticlesActive(this, playerSettings));
|
||||
}
|
||||
|
||||
public void updateSettingSlots(PlayerSettings playerSettings) {
|
||||
setItem(17, playerSettings.isSeeingParticles() ? seeOthersOn : seeOthersOff, new ToggleSeeParticles(this, playerSettings));
|
||||
setItem(26, playerSettings.hasActiveParticles() ? particlesOn : particlesOff, new ToggleParticlesActive(this, playerSettings));
|
||||
}
|
||||
|
||||
static { //Init gui name
|
||||
GUIName = miniMessage.deserialize(Config.PARTICLE_TYPE_GUI_NAME);
|
||||
}
|
||||
|
||||
static { //init APart items
|
||||
Arrays.stream(APartType.values()).forEach(particlesType -> {
|
||||
ItemStack itemStack = new ItemStack(particlesType.getMaterial());
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLE_TYPE_BUTTON_NAME,
|
||||
TemplateResolver.resolving(Template.template("name", particlesType.getName()))));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
particlesType.setItemStack(itemStack);
|
||||
});
|
||||
}
|
||||
|
||||
static { //init setting buttons
|
||||
ItemMeta itemMeta;
|
||||
|
||||
seeOthersOn = new ItemStack(Material.PLAYER_HEAD);
|
||||
itemMeta = seeOthersOn.getItemMeta();
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.SEE_OTHERS_ON));
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.SEE_OTHERS_ON_DESC));
|
||||
seeOthersOn.setItemMeta(itemMeta);
|
||||
|
||||
seeOthersOff = new ItemStack(Material.SKELETON_SKULL);
|
||||
itemMeta = seeOthersOff.getItemMeta();
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.SEE_OTHERS_OFF));
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.SEE_OTHERS_OFF_DESC));
|
||||
seeOthersOff.setItemMeta(itemMeta);
|
||||
|
||||
particlesOn = new ItemStack(Material.PLAYER_HEAD);
|
||||
itemMeta = particlesOn.getItemMeta();
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_ON));
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_ON_DESC));
|
||||
particlesOn.setItemMeta(itemMeta);
|
||||
|
||||
particlesOff = new ItemStack(Material.PLAYER_HEAD);
|
||||
itemMeta = particlesOff.getItemMeta();
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_OFF));
|
||||
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_OFF_DESC));
|
||||
particlesOff.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/alttd/listeners/BlockBreakListener.java
Normal file
28
src/main/java/com/alttd/listeners/BlockBreakListener.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package com.alttd.listeners;
|
||||
|
||||
import com.alttd.objects.APartType;
|
||||
import com.alttd.objects.ParticleSet;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockBreakListener implements Listener {
|
||||
private final List<APartType> particlesToActivate;
|
||||
public BlockBreakListener(APartType... particleTypes) {
|
||||
particlesToActivate = List.of(particleTypes);
|
||||
}
|
||||
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
PlayerSettings player = PlayerSettings.getPlayer(event.getPlayer().getUniqueId());
|
||||
if (!player.hasActiveParticles())
|
||||
return;
|
||||
particlesToActivate.forEach(aPartType -> {
|
||||
ParticleSet particleSet = player.getParticles(aPartType);
|
||||
if (particleSet == null)
|
||||
return;
|
||||
particleSet.run(event.getBlock().getLocation());
|
||||
});
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/alttd/listeners/BlockPlaceListener.java
Normal file
28
src/main/java/com/alttd/listeners/BlockPlaceListener.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package com.alttd.listeners;
|
||||
|
||||
import com.alttd.objects.APartType;
|
||||
import com.alttd.objects.ParticleSet;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockPlaceListener implements Listener {
|
||||
private final List<APartType> particlesToActivate;
|
||||
public BlockPlaceListener(APartType... particleTypes) {
|
||||
particlesToActivate = List.of(particleTypes);
|
||||
}
|
||||
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
PlayerSettings player = PlayerSettings.getPlayer(event.getPlayer().getUniqueId());
|
||||
if (!player.hasActiveParticles())
|
||||
return;
|
||||
particlesToActivate.forEach(aPartType -> {
|
||||
ParticleSet particleSet = player.getParticles(aPartType);
|
||||
if (particleSet == null)
|
||||
return;
|
||||
particleSet.run(event.getBlock().getLocation());
|
||||
});
|
||||
}
|
||||
}
|
||||
27
src/main/java/com/alttd/listeners/PlayerJoinListener.java
Normal file
27
src/main/java/com/alttd/listeners/PlayerJoinListener.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package com.alttd.listeners;
|
||||
|
||||
import com.alttd.AltitudeParticles;
|
||||
import com.alttd.database.Queries;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
||||
if (playerSettings == null) Queries.getPlayerSettings(uuid);
|
||||
|
||||
//TODO activate particles sync/async???
|
||||
}
|
||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
40
src/main/java/com/alttd/objects/APartType.java
Normal file
40
src/main/java/com/alttd/objects/APartType.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public enum APartType { //TODO add description?
|
||||
HEAD("Head", Material.PLAYER_HEAD, null),
|
||||
TRAIL("Trail", Material.GOLD_INGOT, null),
|
||||
BREAK_PLACE_BLOCK("Break/place block", Material.GRASS_BLOCK, null),
|
||||
DEATH("Death", Material.SKELETON_SKULL, null),
|
||||
ATTACK_CLOSE("Attack CQC", Material.DIAMOND_SWORD, null),
|
||||
ATTACK_RANGE("Attack ranged", Material.BOW, null),
|
||||
TELEPORT_ARRIVE("Teleport", Material.DRAGON_EGG, null);
|
||||
|
||||
private final String name;
|
||||
private final Material material;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
APartType(String name, Material material, ItemStack itemStack) {
|
||||
this.name = name;
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/main/java/com/alttd/objects/Frame.java
Normal file
24
src/main/java/com/alttd/objects/Frame.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import com.destroystokyo.paper.ParticleBuilder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Frame {
|
||||
List<ParticleBuilder> particles;
|
||||
|
||||
public Frame(List<ParticleBuilder> particles) {
|
||||
this.particles = particles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns all particles in a frame (CALL ASYNC)
|
||||
*
|
||||
* @param location Location to spawn particles at
|
||||
*/
|
||||
public void spawn(Location location) {
|
||||
particles.forEach(particleBuilder -> particleBuilder.location(location).spawn());
|
||||
}
|
||||
}
|
||||
37
src/main/java/com/alttd/objects/ParticleSet.java
Normal file
37
src/main/java/com/alttd/objects/ParticleSet.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import com.alttd.AltitudeParticles;
|
||||
import com.alttd.frameSpawners.FrameSpawnerLocation;
|
||||
import com.alttd.frameSpawners.FrameSpawnerPlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParticleSet {
|
||||
|
||||
List<Frame> frames;
|
||||
int delay, repeat;
|
||||
APartType particlesType;
|
||||
boolean shouldRepeat;
|
||||
int ticksUntilNextFrame;
|
||||
|
||||
public ParticleSet(List<Frame> frames, int delay, int repeat, APartType particlesType) {
|
||||
this.frames = frames;
|
||||
this.delay = delay;
|
||||
this.repeat = repeat;
|
||||
this.particlesType = particlesType;
|
||||
this.shouldRepeat = repeat < 0;
|
||||
ticksUntilNextFrame = delay;
|
||||
}
|
||||
|
||||
public void run(Location location) {
|
||||
FrameSpawnerLocation frameSpawnerLocation = new FrameSpawnerLocation(repeat, frames, location);
|
||||
frameSpawnerLocation.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, delay);
|
||||
}
|
||||
|
||||
public void run(Player player) {
|
||||
FrameSpawnerPlayer frameSpawnerPlayer = new FrameSpawnerPlayer(repeat, frames, player);
|
||||
frameSpawnerPlayer.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, delay);
|
||||
}
|
||||
}
|
||||
66
src/main/java/com/alttd/storage/PlayerSettings.java
Normal file
66
src/main/java/com/alttd/storage/PlayerSettings.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package com.alttd.storage;
|
||||
|
||||
import com.alttd.objects.APartType;
|
||||
import com.alttd.objects.ParticleSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerSettings {
|
||||
|
||||
private static final HashMap<UUID, PlayerSettings> playerSettingsMap = new HashMap<>();
|
||||
|
||||
private boolean particlesActive, seeingParticles;
|
||||
private final UUID uuid;
|
||||
private final HashMap<APartType, ParticleSet> particles;
|
||||
|
||||
public PlayerSettings(boolean particlesActive, boolean seeingParticles, UUID uuid, HashMap<APartType, ParticleSet> particles) {
|
||||
this.particlesActive = particlesActive;
|
||||
this.seeingParticles = seeingParticles;
|
||||
this.uuid = uuid;
|
||||
this.particles = particles;
|
||||
|
||||
playerSettingsMap.put(uuid, this);
|
||||
}
|
||||
|
||||
public PlayerSettings(boolean particlesActive, boolean seeingParticles, UUID uuid) {
|
||||
this.particlesActive = particlesActive;
|
||||
this.seeingParticles = seeingParticles;
|
||||
this.uuid = uuid;
|
||||
this.particles = new HashMap<>();
|
||||
|
||||
playerSettingsMap.put(uuid, this);
|
||||
}
|
||||
|
||||
public boolean hasActiveParticles() {
|
||||
return particlesActive;
|
||||
}
|
||||
|
||||
public void toggleParticlesActive() {
|
||||
particlesActive = !particlesActive;
|
||||
}
|
||||
|
||||
public boolean isSeeingParticles() {
|
||||
return seeingParticles;
|
||||
}
|
||||
|
||||
public void toggleSeeingParticles() {
|
||||
seeingParticles = !seeingParticles;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public HashMap<APartType, ParticleSet> getParticles() {
|
||||
return particles;
|
||||
}
|
||||
|
||||
public ParticleSet getParticles(APartType aPartType) {
|
||||
return particles.get(aPartType);
|
||||
}
|
||||
|
||||
public static PlayerSettings getPlayer(UUID uuid) {
|
||||
return playerSettingsMap.get(uuid);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user