diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..13695fd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive", + "java.dependency.packagePresentation": "hierarchical", + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/Links.txt b/Links.txt index b5beb3f..141a7a8 100644 --- a/Links.txt +++ b/Links.txt @@ -5,4 +5,5 @@ https://riptutorial.com/bukkit/example/25262/hiding-a-player-from-other-players https://www.spigotmc.org/threads/hide-player.66254/ https://www.spigotmc.org/threads/launch-player-in-specific-direction.408591/ https://bukkit.org/threads/player-pressure-plate-event.161460/ -https://www.spigotmc.org/threads/playerinteractevent-pressure-plate.403327/ \ No newline at end of file +https://www.spigotmc.org/threads/playerinteractevent-pressure-plate.403327/ +https://github.com/xerial/sqlite-jdbc \ No newline at end of file diff --git a/README.md b/README.md index 1414f18..4059e09 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,6 @@ -# SteevsLobbyPlugin -I am making this Plugin, to finaly solve a Problem i have with currently avaiable Plugins. -I am aiming on creating a Plugin that once its done implements all the Features current Lobby Systems have and even charge Money for. +# Lobbysystem -# Maintenance -Due to the Fact, that i am developing this Plugin in my free time i wont keep the support for it forever.. -I also wont create anything like an Update Schedule Updates release when their done. - -# Current Stand -I am working on getting the plugin stable neither proper permission handling nor actualerror handling have been done. -You may look at this plugin like an ALPHA at least most of the plugin is still work in progress and will be done - -# Roadmap -As of now i am not sure enough, to make an entire roadmap.. -The only things i can say as of now, are i am working on features and some stabillity things +currently implemented: +- bouncing plates +- inventory ui +- config defined warps diff --git a/config.yml b/config.yml index 1c006a4..5c2a87a 100644 --- a/config.yml +++ b/config.yml @@ -1,6 +1,22 @@ forceSpawn: true defaultSpawn: example +database: + type: "yml" + url: jdbc:mysql://localhost:3306/lobby + user: root + password: root jumpPlates: ground: EMERALD_BLOCK plate: STONE_PRESSURE_PLATE - multiplier: 4 \ No newline at end of file + multiplier: 4 +permission: + allperms: lobby.* + admin: + all: lobby.admin.* + help: lobby.admin.help + setloc: lobby.admin.location.set + remloc: lobby.admin.location.remove + setjump: lobby.admin.jumps.set + remjump: lobby.admin.jumps.remove + user: + jump: lobby.user.jumpplates.use \ No newline at end of file diff --git a/mysql-connector.jar b/mysql-connector.jar new file mode 100644 index 0000000..0170c3e Binary files /dev/null and b/mysql-connector.jar differ diff --git a/plugin.yml b/plugin.yml index b432f85..762f824 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: Lobby -main: de.slpnetwork.lobby.Lobby +main: de.vortexhq.lobby.Lobby version: 0.1 api-version: 1.18 commands: diff --git a/pom.xml b/pom.xml index 7a6c752..c2ba446 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,11 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - de.slpnetwork.lobby - slpnetlobby + de.vortexhq.lobby + vortexlobby 1.0 @@ -22,13 +22,30 @@ - org.spigotmc spigot-api - 1.18.2-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT provided - + + org.xerial + sqlite-jdbc + 3.42.0.0 + + + + + ${project.basedir}/src/main/java + + + ${project.basedir}/src/main/resources + + plugin.yml + mysql-connector.jar + + + + \ No newline at end of file diff --git a/src/main/java/de/vortexhq/lobby/Commands/slpl.java b/src/main/java/de/vortexhq/lobby/Commands/slpl.java new file mode 100644 index 0000000..a477d00 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Commands/slpl.java @@ -0,0 +1,47 @@ +package de.vortexhq.lobby.Commands; + +import de.vortexhq.lobby.Commands.subcommands.admin; +import de.vortexhq.lobby.Manager.LobbyManager; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Locale; + +// TODO: Implement Permission handling + +public class slpl implements CommandExecutor { + private LobbyManager lobbyManager; + private admin cmdAdmin; + + public slpl(LobbyManager lobbyManager) { + this.lobbyManager = lobbyManager; + cmdAdmin = new admin(this.lobbyManager); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player player = sender.getServer().getPlayer(sender.getName()); + + System.out.println("Debug -> Command Output"); + System.out.println(args[0]); + System.out.println(args[1]); + System.out.println(args[2]); + + if(args.length >= 0) { + switch (args[0].toLowerCase()) { + case "admin": + switch (args[1].toLowerCase()) { + case "help" -> cmdAdmin.sendHelp(player); + case "setloc" -> cmdAdmin.setLoc(player.getLocation(), args[2].toLowerCase()); + case "remloc" -> cmdAdmin.remLoc(args[2]); + case "setjump" -> cmdAdmin.setJumpPlate(player, args); + case "remjump" -> cmdAdmin.remJumpPlate(args[2].toLowerCase()); + } + break; + } + } + return false; + } +} diff --git a/src/main/java/de/vortexhq/lobby/Commands/subcommands/admin.java b/src/main/java/de/vortexhq/lobby/Commands/subcommands/admin.java new file mode 100644 index 0000000..d2f0618 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Commands/subcommands/admin.java @@ -0,0 +1,142 @@ +package de.vortexhq.lobby.Commands.subcommands; + +import de.vortexhq.lobby.Manager.LobbyManager; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.io.IOException; +import java.util.Locale; + +// TODO: Implement Permission Handling + +public class admin { + private LobbyManager lobbyManager; + + public admin(LobbyManager lobbyManager) { + this.lobbyManager = lobbyManager; + } + + /** + * sends administration help to player + * @param player player reference + */ + public static void sendHelp(Player player) { + // Send help message (when done) + } + + /** + * sets a Jumplate and adds it to config 1: Name, 2: Sound, 3: Vertical Speed, 4: Horizontal Speed, 5: x-grid plates, 6: y-grid plates + * @param args command arguments passed by executor + */ + public void setJumpPlate(Player player, String[] args) { + try { + if(args[1] != null) { + String sound = "ENTITY_GENERIC_EXPLODE"; + int vertical = 1; + int horizontal = 8; + int grid_x = 1; + int grid_y = 1; + + try { + if (args[3] != null) { sound = args[3]; } + if (args[4] != null) { vertical = Integer.parseInt(args[4]); } + if (args[5] != null) { horizontal = Integer.parseInt(args[5]); } + if (args[6] != null) { grid_x = Integer.parseInt(args[6]); } + if (args[7] != null) { grid_y = Integer.parseInt(args[7]); } + } catch (Exception ex){ + + } + + // Check for arguments and place plates + if(grid_x > 1 && grid_y > 1) { + for(int x = Math.round((grid_x/2)*(-1)); x < Math.round((grid_x/2)); x++) { + for (int y = Math.round((grid_y/2)*(-1)); y < Math.round((grid_y/2)); y++) { + Location loc = new Location( + player.getWorld(), + player.getLocation().getBlockX() + x, + player.getLocation().getBlockY(), + player.getLocation().getBlockZ() + y + ); + platePlacement(loc, args[1], horizontal, vertical); + } + } + } else { + platePlacement(player.getLocation(), args[1], horizontal, vertical); + } + + // save data to files + this.lobbyManager.getLobby().jumpDataConfig.save(this.lobbyManager.getLobby().jumpData); + } + } catch (IOException exception) { + // Just dont do anything + } + } + + /** + * removes a specific plate + * @param name the plates name + */ + public void remJumpPlate(String name){ + try { + // TODO: Get the Plates Position + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name, null); + this.lobbyManager.getLobby().jumpDataConfig.save(this.lobbyManager.getLobby().jumpData); + } catch (IOException exception) { + + } + } + + /** + * handles command input and stores its give location + * @param loc inworld location + * @param name locations reference name + */ + public void setLoc(Location loc, String name){ + System.out.println("DEBUG -> SetLoc Input: " + name + ", " + loc); + try { + // set location in locations.yml + this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".name", name); + this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".world", loc.getWorld().getName()); + this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".X", loc.getBlockX()); + this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".Y", loc.getBlockY()); + this.lobbyManager.getLobby().teleportDataConfig.save(this.lobbyManager.getLobby().teleportData); + } catch (IOException ex) { + // this is bads + } + } + + /** + * removes a given location if it exists + * @param name removing location name + */ + public void remLoc(String name){ + // set location in locations.yml + // set location in locations.yml + this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name, null); + try { + this.lobbyManager.getLobby().teleportDataConfig.save(this.lobbyManager.getLobby().teleportData); + } catch (IOException ex) { + // this is bads + } + } + + // Prevents messy code + private void platePlacement(Location loc, String name, int horizontalVel, int verticalVel){ + // Set Location + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.world", loc.getWorld().getName()); + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.X", loc.getBlockX()); + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.Y", loc.getBlockY()); + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.Z", loc.getBlockZ()); + + // Set Modifier + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".multiplier.vertical", verticalVel); + this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".multiplier.horizontal", horizontalVel); + + Block plate = loc.getWorld().getBlockAt(loc); + plate.setType(Material.getMaterial(this.lobbyManager.getLobby().config.getString("jumpPlates.plate"))); + } +} diff --git a/src/main/java/de/vortexhq/lobby/Events/PlayerInteract.java b/src/main/java/de/vortexhq/lobby/Events/PlayerInteract.java new file mode 100644 index 0000000..9e4abed --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Events/PlayerInteract.java @@ -0,0 +1,61 @@ +package de.vortexhq.lobby.Events; + +import de.vortexhq.lobby.Lobby; +import de.vortexhq.lobby.Manager.LobbyManager; +import de.vortexhq.lobby.Utils.Log; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.util.Vector; + +public class PlayerInteract implements Listener { + private LobbyManager lobbyManager; + + public PlayerInteract(LobbyManager lobbyManager) { + this.lobbyManager = lobbyManager; + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event){ + if(event.getAction().equals(Action.PHYSICAL)) { + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + if(event.getClickedBlock().getType() == Material.getMaterial(this.lobbyManager.getLobby().config.getString("jumpPlates.plate"))) { + + // TODO: Test Jumpplate Code + for(String key: this.lobbyManager.getLobby().jumpDataConfig.getConfigurationSection("plates").getKeys(false)) { + // Construct Launcher + this.lobbyManager.getLobby().Logger.Debug("plate-key:" + key); + this.lobbyManager.getLobby().Logger.Debug("loc world: " + this.lobbyManager.getLobby().jumpDataConfig.getString("plates." + key + ".location.world")); + this.lobbyManager.getLobby().Logger.Debug("loc x: " + this.lobbyManager.getLobby().jumpDataConfig.getDouble("plates." + key + ".location.X")); + this.lobbyManager.getLobby().Logger.Debug("loc y: " + this.lobbyManager.getLobby().jumpDataConfig.getDouble("plates." + key + ".location.Y")); + this.lobbyManager.getLobby().Logger.Debug("loc z: " + this.lobbyManager.getLobby().jumpDataConfig.getDouble("plates." + key + ".location.Z")); + this.lobbyManager.getLobby().Logger.Debug(String.valueOf("loc world: " + block.getLocation().getWorld().getName() == this.lobbyManager.getLobby().jumpDataConfig.getString("plates." + key + ".location.world"))); + this.lobbyManager.getLobby().Logger.Debug("loc x: " + ((int)block.getLocation().getBlockX() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.X"))); + this.lobbyManager.getLobby().Logger.Debug("loc y: " + ((int)block.getLocation().getBlockY() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Y"))); + this.lobbyManager.getLobby().Logger.Debug("loc z: " + ((int)block.getLocation().getBlockZ() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Z"))); + + if((int)block.getLocation().getBlockX() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.X") && + (int)block.getLocation().getBlockY() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Y") && + (int)block.getLocation().getBlockZ() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Z")) { + + // Launch Player in looking direction + System.out.println("DEBUG -> Launching Player"); + player.setVelocity(new Vector( + player.getLocation().getDirection().multiply(this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".multiplier.horizontal")).getX(), + this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".multiplier.vertical"), + player.getLocation().getDirection().multiply(this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".multiplier.horizontal")).getZ())); + + // Player Sound + player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 5.0f, 1.0f); + } + } + } + } + } +} diff --git a/src/main/java/de/vortexhq/lobby/Lobby.java b/src/main/java/de/vortexhq/lobby/Lobby.java new file mode 100644 index 0000000..1ea644a --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Lobby.java @@ -0,0 +1,143 @@ +package de.vortexhq.lobby; + +import de.vortexhq.lobby.Commands.slpl; +import de.vortexhq.lobby.Events.PlayerInteract; +import de.vortexhq.lobby.Manager.InventoryManager; +import de.vortexhq.lobby.Manager.LobbyManager; +import de.vortexhq.lobby.Utils.Log; +import de.vortexhq.lobby.Utils.Datahandler; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import java.io.File; +import java.io.InputStreamReader; + +public class Lobby extends JavaPlugin implements Listener, PluginMessageListener { + public LobbyManager lobbyManager; + public FileConfiguration config; + public File itemData; + public FileConfiguration itemDataConfig; + public File menuData; + public FileConfiguration menuDataConfig; + public File teleportData; + public FileConfiguration teleportDataConfig; + public File jumpData; + public FileConfiguration jumpDataConfig; + public Log Logger; + public Datahandler database; + + @Override + public void onEnable(){ + super.onEnable(); + this.Logger.Info("Initializing Configs"); + try { + // setup plugin wide Handler + this.saveDefaultConfig(); + config = this.getConfig(); + Logger = new Log(this); + if (this.config.getString("database.type") != "yml") { + try { + this.Logger.Info("Initializing Database Manager"); + } catch (Exception ex) { + this.Logger.Error("could not initialize database connection manager threw exception: " + ex.getLocalizedMessage()); + } + } + + database = new Datahandler(this, this.config.getString("database.type"), this.config.getString("database.url"),this.config.getString("database.username"),this.config.getString("database.password")); + + // handle plugin files + itemData = new File(this.getDataFolder(), "items.yml"); + menuData = new File(this.getDataFolder(), "menus.yml"); + teleportData = new File(this.getDataFolder(), "locations.yml"); + jumpData = new File(this.getDataFolder(), "jumps.yml"); + + if(!itemData.exists() || !menuData.exists() || !teleportData.exists()) { + this.Logger.Info("Loading config files"); + itemData = new File(this.getDataFolder(), "items.yml"); + menuData = new File(this.getDataFolder(), "menus.yml"); + teleportData = new File(this.getDataFolder(), "locations.yml"); + jumpData = new File(this.getDataFolder(), "jumps.yml"); + + itemDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("items.yml"))); + menuDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("menus.yml"))); + teleportDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("locations.yml"))); + jumpDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("jumps.yml"))); + + itemDataConfig.save(itemData); + menuDataConfig.save(menuData); + teleportDataConfig.save(teleportData); + jumpDataConfig.save(jumpData); + } + + itemDataConfig = YamlConfiguration.loadConfiguration(itemData); + menuDataConfig = YamlConfiguration.loadConfiguration(menuData); + teleportDataConfig = YamlConfiguration.loadConfiguration(teleportData); + jumpDataConfig = YamlConfiguration.loadConfiguration(jumpData); + }catch (Exception ex) { + this.Logger.Warn("initialization failed with exception: " + ex.getLocalizedMessage()); + } + + this.Logger.Info("Initializing Lobbymanager Instance"); + this.lobbyManager = new LobbyManager(this); + + this.Logger.Info("Regsiter command"); + this.getCommand("slpl").setExecutor(new slpl(this.lobbyManager)); + + this.Logger.Info("Register Plugin events"); + this.getServer().getPluginManager().registerEvents(this, this); + this.getServer().getPluginManager().registerEvents(new PlayerInteract(this.lobbyManager), this); + this.getServer().getPluginManager().registerEvents(new InventoryManager(this.lobbyManager), this); + + this.Logger.Info("Register Plugin Message channel"); + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this); + } + + @Override + public void onDisable(){ + super.onDisable(); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + e.getPlayer().getInventory().clear(); + + // Fetch and set configured items + for (String key: this.itemDataConfig.getConfigurationSection("items").getKeys(false)) { + this.Logger.Debug("Material: " + key); + ItemStack is = new ItemStack(Material.getMaterial(this.itemDataConfig.getString("items." + key + ".material"))); + ItemMeta im = is.getItemMeta(); + im.setDisplayName(this.itemDataConfig.getString("items." + key + ".display")); + im.addItemFlags(); + is.setItemMeta(im); + e.getPlayer().getInventory().setItem(this.itemDataConfig.getInt("items." + key + ".slot"), is); + } + } + + @EventHandler + public void onPlayerUse(PlayerInteractEvent e) { + // Error: somewhere on the way of triggering + // The menu does not get opened + try { + Player p = e.getPlayer(); + this.lobbyManager.getInventoryManager().openInventory(p, this.itemDataConfig.getString("items." + e.getMaterial() + ".menu")); + } catch (Exception ex) { + // possibly nullpointer nothing else can happen here + } + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] bytes) { + if (!channel.equals("BungeeCord")) { return; } + } +} diff --git a/src/main/java/de/vortexhq/lobby/Manager/InventoryManager.java b/src/main/java/de/vortexhq/lobby/Manager/InventoryManager.java new file mode 100644 index 0000000..9993356 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Manager/InventoryManager.java @@ -0,0 +1,115 @@ +package de.vortexhq.lobby.Manager; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.HumanEntity; +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.InventoryDragEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Arrays; +import java.util.HashMap; + +//TODO: Implement Permission Handling + +public class InventoryManager implements Listener { + private final LobbyManager lobbyManager; + private HashMap inventories; + + public InventoryManager(LobbyManager lobbyManager){ + this.lobbyManager = lobbyManager; + this.lobbyManager.getLobby().getServer().getLogger().info("Initializing Lobby"); + this.lobbyManager.setInventoryManager(this); + this.inventories = new HashMap(); + + for(String key: this.lobbyManager.getLobby().menuDataConfig.getConfigurationSection("menus").getKeys(false)) { + this.inventories.put( + this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".identifier"), Bukkit.createInventory(null, + this.lobbyManager.getLobby().menuDataConfig.getInt("menus." + key + ".slots"), + this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".title") + ) + ); + System.out.println(this.inventories.size() + " inventories stored"); // debugging inventories not beeing generated + initializeItems(key); + } + } + + void initializeItems(String key){ + Inventory inv = inventories.get(this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".identifier")); + + // Nullpointer debugging + System.out.println(key + "0"); + if(this.lobbyManager.getLobby().menuDataConfig.get("menus." + key) == null) System.out.println("Error: no items have been set, Menu will not be created"); // fixes nullpointer + if(this.lobbyManager.getLobby().menuDataConfig.get("menus." + key) == null) return; // fixes nullpointer + + for(String keyItem : this.lobbyManager.getLobby().menuDataConfig.getConfigurationSection("menus." + key + ".items").getKeys(false)) { + System.out.println("debug-> " + keyItem); + System.out.println(this.lobbyManager.getLobby().menuDataConfig.getString("menus."+key+".items."+keyItem+".material") + "1"); + + inv.setItem(this.lobbyManager.getLobby().menuDataConfig.getInt("menus." + key + ".items." + keyItem + ".slot"), + createGuiItem(Material.getMaterial(this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".items." + keyItem + ".material")), + this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".items." + keyItem + ".title"), + this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".items." + keyItem + ".description") + ) + ); + } + } + + protected ItemStack createGuiItem(final Material material, final String name, final String... lore) { + final ItemStack item = new ItemStack(material, 1); + final ItemMeta meta = item.getItemMeta(); + + // Set the name of the item + meta.setDisplayName(name); + + // Set the lore of the item + meta.setLore(Arrays.asList(lore)); + + item.setItemMeta(meta); + + return item; + } + + // You can open the inventory with this + public void openInventory(final HumanEntity ent, String Inventory) { + System.out.println(Inventory); + System.out.println(inventories.containsKey(Inventory)); + if(inventories.containsKey(Inventory)) { + ent.openInventory(inventories.get(Inventory)); + } + } + + // Check for clicks on items + @EventHandler + public void onInventoryClick(final InventoryClickEvent e) { + if(!inventories.containsValue(e.getInventory())) return; + + e.setCancelled(true); + + final ItemStack clickedItem = e.getCurrentItem(); + this.lobbyManager.getLobby().getServer().getLogger().info(clickedItem.toString()); + + // verify current item is not null + if (clickedItem == null || clickedItem.getType().isAir()) return; + + final Player p = (Player) e.getWhoClicked(); + this.lobbyManager.getCommandInterpreter().execute(p.getPlayer(), + this.lobbyManager.getLobby().menuDataConfig.getString("menus." + e.getView().getTitle().toLowerCase() + ".items."+ clickedItem.getType() + ".action.type"), + this.lobbyManager.getLobby().menuDataConfig.getString("menus." + e.getView().getTitle().toLowerCase() + ".items."+ clickedItem.getType() + ".action.argument")); + // Using slots click is a best option for your inventory click's + p.sendMessage("You clicked at slot " + e.getRawSlot()); + } + + // Cancel dragging in our inventory + @EventHandler + public void onInventoryClick(final InventoryDragEvent e) { + if (inventories.containsValue(e.getInventory())) { + e.setCancelled(true); + } + } +} diff --git a/src/main/java/de/vortexhq/lobby/Manager/LobbyManager.java b/src/main/java/de/vortexhq/lobby/Manager/LobbyManager.java new file mode 100644 index 0000000..487b54e --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Manager/LobbyManager.java @@ -0,0 +1,37 @@ +package de.vortexhq.lobby.Manager; + +import de.vortexhq.lobby.Lobby; +import de.vortexhq.lobby.Utils.CommandInterpreter; + +public class LobbyManager { + private Lobby lobby; + private InventoryManager inventoryManager; + private CommandInterpreter commandInterpreter; + private PlayerManager playerManager; + + public LobbyManager(Lobby lobby) { + this.lobby = lobby; + this.commandInterpreter = new CommandInterpreter(this); + this.playerManager = new PlayerManager(this); + } + + public Lobby getLobby() { + return lobby; + } + + public InventoryManager getInventoryManager() { + return inventoryManager; + } + + public CommandInterpreter getCommandInterpreter() { + return commandInterpreter; + } + + public PlayerManager getPlayerManager() { + return playerManager; + } + + public void setInventoryManager(InventoryManager inventoryManager) { + this.inventoryManager = inventoryManager; + } +} diff --git a/src/main/java/de/vortexhq/lobby/Manager/PlayerManager.java b/src/main/java/de/vortexhq/lobby/Manager/PlayerManager.java new file mode 100644 index 0000000..b23e1d7 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Manager/PlayerManager.java @@ -0,0 +1,37 @@ +package de.vortexhq.lobby.Manager; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class PlayerManager { + private LobbyManager lobbyManager; + + public PlayerManager(LobbyManager lobbyManager) { + this.lobbyManager = lobbyManager; + } + + /** + * teleports a player to a location + * @param player the wanted player + * @param loc the wanted location + */ + public void teleportPlayer(Player player, Location loc) { + player.teleport(loc); + } + + /** + * Moves a player from a server to another + * @param dest the destination + * @param target the player to send + */ + public void moveFromServer(String dest, Player target) { + ByteArrayDataOutput aOut = ByteStreams.newDataOutput(); + aOut.writeUTF("Connect"); + aOut.writeUTF(dest); + target.sendPluginMessage(this.lobbyManager.getLobby(), "BungeeCord", aOut.toByteArray()); + } +} diff --git a/src/main/java/de/vortexhq/lobby/Manager/ScoreboradManager.java b/src/main/java/de/vortexhq/lobby/Manager/ScoreboradManager.java new file mode 100644 index 0000000..14b4037 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Manager/ScoreboradManager.java @@ -0,0 +1,4 @@ +package de.vortexhq.lobby.Manager; + +public class ScoreboradManager { +} diff --git a/src/main/java/de/vortexhq/lobby/Manager/SettingsManager.java b/src/main/java/de/vortexhq/lobby/Manager/SettingsManager.java new file mode 100644 index 0000000..ce56ae7 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Manager/SettingsManager.java @@ -0,0 +1,7 @@ +package de.vortexhq.lobby.Manager; + +// TODO: Figure out how Settings can be Implemented + +public class SettingsManager { + +} diff --git a/src/main/java/de/vortexhq/lobby/Utils/ArrayHelper.java b/src/main/java/de/vortexhq/lobby/Utils/ArrayHelper.java new file mode 100644 index 0000000..9a48158 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Utils/ArrayHelper.java @@ -0,0 +1,62 @@ +package de.vortexhq.lobby.Utils; + +import java.util.Arrays; + +import com.google.gson.JsonObject; + +public class ArrayHelper { + public static int[] push(int[] arr, int item) { + int[] tmp = Arrays.copyOf(arr, arr.length + 1); + tmp[tmp.length - 1] = item; + return tmp; + } + + public static String[] push(String[] arr, String item) { + String[] tmp = Arrays.copyOf(arr, arr.length + 1); + tmp[tmp.length - 1] = item; + return tmp; + } + + public static double[] push(double[] arr, double item) { + double[] tmp = Arrays.copyOf(arr, arr.length + 1); + tmp[tmp.length - 1] = item; + return tmp; + } + + public static boolean[] push(boolean[] arr, boolean item) { + boolean[] tmp = Arrays.copyOf(arr, arr.length + 1); + tmp[tmp.length - 1] = item; + return tmp; + } + + public static JsonObject[] push(JsonObject[] arr, JsonObject item) { + JsonObject[] tmp = Arrays.copyOf(arr, arr.length + 1); + tmp[tmp.length - 1] = item; + return tmp; + } + + public static int[] pop(int[] arr) { + int[] tmp = Arrays.copyOf(arr, arr.length - 1); + return tmp; + } + + public static String[] pop(String[] arr) { + String[] tmp = Arrays.copyOf(arr, arr.length - 1); + return tmp; + } + + public static double[] pop(double[] arr) { + double[] tmp = Arrays.copyOf(arr, arr.length - 1); + return tmp; + } + + public static boolean[] pop(boolean[] arr) { + boolean[] tmp = Arrays.copyOf(arr, arr.length - 1); + return tmp; + } + + public static JsonObject[] pop(JsonObject[] arr) { + JsonObject[] tmp = Arrays.copyOf(arr, arr.length - 1); + return tmp; + } +} \ No newline at end of file diff --git a/src/main/java/de/vortexhq/lobby/Utils/CommandInterpreter.java b/src/main/java/de/vortexhq/lobby/Utils/CommandInterpreter.java new file mode 100644 index 0000000..90aeb66 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Utils/CommandInterpreter.java @@ -0,0 +1,47 @@ +package de.vortexhq.lobby.Utils; + +import de.vortexhq.lobby.Manager.LobbyManager; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.Objects; + +public class CommandInterpreter { + private LobbyManager lobbyManager; + public CommandInterpreter(LobbyManager lobbyManager) { + this.lobbyManager = lobbyManager; + } + + /** + * Executes configured action + * @param executor User who performed the Action + * @param action the action to perform + * @param args aditional arguments + */ + public void execute(Player executor, String action, String args){ + switch (action.toLowerCase()) { + default: + this.lobbyManager.getLobby().getServer().getLogger().warning("The Action: '" + action + "' is not defined"); + break; + case "menu": + this.lobbyManager.getInventoryManager().openInventory(executor, args); + break; + case "teleport": + this.lobbyManager.getLobby().teleportDataConfig.getLocation("locations." + args); + Location destination = new Location(Bukkit.getServer().getWorld(this.lobbyManager.getLobby().teleportDataConfig.getString("locations." + args + ".world")), + this.lobbyManager.getLobby().teleportDataConfig.getDouble("locations." + args + ".X"), + this.lobbyManager.getLobby().teleportDataConfig.getDouble("locations." + args + ".Y"), + this.lobbyManager.getLobby().teleportDataConfig.getDouble("locations." + args + ".Z")); + this.lobbyManager.getPlayerManager().teleportPlayer(executor, destination); + break; + case "connect": + this.lobbyManager.getPlayerManager().moveFromServer(args, Objects.requireNonNull(executor.getPlayer())); + break; + case "execute": + // Not yet implemented + // Might be droped during development phase + break; + } + } +} diff --git a/src/main/java/de/vortexhq/lobby/Utils/Data/MySQL.java b/src/main/java/de/vortexhq/lobby/Utils/Data/MySQL.java new file mode 100644 index 0000000..b1c0b5f --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Utils/Data/MySQL.java @@ -0,0 +1,294 @@ +package de.vortexhq.lobby.Utils.Data; + +import com.google.gson.JsonObject; +import de.vortexhq.lobby.Utils.ArrayHelper; +import de.vortexhq.lobby.interfaces.IDataHandler; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +import javax.annotation.Nullable; + +public class MySQL implements IDataHandler { + + private Connection con; + + /**te + * handles all mysql database operations + * @param url the target url for the database + * @param username the username for the database + * @param password the password for the database + * @param database the name of the datbase (not yet required) + * @throws Exception if anything failes during connection attempt an exception throws + */ + public MySQL(String url, String username, String password, String database) throws Exception{ + try { + connect(url, username, password); + } catch(Exception ex) { + throw new Exception("could not connect to database due to error: " + ex.getLocalizedMessage()); + } + } + + /** + * connects to the Database + * @param url target url to the database + * @param username username for the database + * @param password password for the database + */ + private Connection connect(String url, String username, String password){ + try { + con = DriverManager.getConnection(url, username, password); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + /** + * creates a table in the set database + * @param name the tables name + * @param fieldMap a map given with fieldnames and datatypes + * @throws SQLException + */ + @Override + public void createTable(String name, Map fieldMap) { + String fields = ""; + + fields += "("; + for (Map.Entry entry : fieldMap.entrySet()) { + System.out.println(entry.getKey() + ":" + entry.getValue()); + fields += entry.getKey() + " " + entry.getValue(); + } + fields += ")"; + + try { + this.con.createStatement().executeQuery("CREATE TABLE IF NOT EXISTS " + name + " " + fields); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * execute a given statement on a mysql database + * this only returns a single given fields value for return of rows use getResults + * @param stmt the statement used to query the database + * @param target used to specify which field is required + * @return if found values from the database of type int + */ + @Override + public int getInt(String stmt, String target) { + try { + int returning = 0; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getInt(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return 0; + } + + /** + * execute a given statement on a mysql database + * this only returns a single given fields value for return of rows use getResults + * @param stmt the statement used to query the database + * @param target used to specify which field is required + * @return if found values from the database of type int + */ + @Override + public int[] getInts(String stmt, String target) { + try { + int[] returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + ArrayHelper.push(returning, res.getInt(target)); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + /** + * execute a given statement on a mysql database + * @param stmt the statement used to query the database + * @param a2 not used + * @return if found values from the database of type int + */ + @Override + public double getDouble(String stmt, @Nullable String target) { + try { + double returning = 0; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getDouble(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public double[] getDoubles(String stmt, String target) { + try { + double[] returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + ArrayHelper.push(returning, res.getDouble(target)); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + /** + * execute a given statement on a mysql database + * @param stmt the statement used to query the database + * @param target states what field is wanted + * @return if found values from the database of type string + */ + @Override + public String getString(String stmt, String target) { + try { + String returning = ""; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getString(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return ""; + } + + /** + * execute a given statement on a mysql database + * @param stmt the statement used to query the database + * @param target not used + * @return if found values from the database of type string as array + */ + @Override + public String[] getStrings(String stmt, String target) { + try { + String[] returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + ArrayHelper.push(returning, res.getString(target)); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + /** + * execute a given statement on a mysql database + * @param stmt the statement used to query the database + * @param target not used + * @return if found values from the database of type boolean + */ + @Override + public boolean getBool(String stmt, String target) { + try { + boolean returning = false; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getBoolean(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } + + /** + * execute a given statement on a mysql database + * @param stmt the statement used to query the database + * @param target not used + * @return if found values from the database of type boolean as array + */ + @Override + public boolean[] getBools(String stmt, String target) { + boolean[] result = {}; + + try { + ResultSet rs = this.con.createStatement().executeQuery(stmt); + while (rs.next()) { + result = ArrayHelper.push(result,rs.getBoolean(target)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return result; + } + + /** + * execute a given statement on a mysql database + * @param stmt the statement used to query the database + * @return if found values from the database of type int + */ + @Override + public boolean writeData(String stmt) { + return false; + } + + + /** + * executes a query and returns the unproccessed resultset + * @param a1 the query given as a string + * @return a resultset to continue proccessing with + */ + @Override + public ResultSet getResults(String a1) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getResults'"); + } + + + @Override + public JsonObject getResultAsJSON(String a1) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getResultAsJSON'"); + } + + + @Override + public JsonObject[] getResultsAsJSON(String a1) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getResultsAsJSON'"); + } + + + @Override + public Map getResultsAsMap(String a1) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getResultsAsMap'"); + } +} diff --git a/src/main/java/de/vortexhq/lobby/Utils/Data/SQLite.java b/src/main/java/de/vortexhq/lobby/Utils/Data/SQLite.java new file mode 100644 index 0000000..6ea25e2 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Utils/Data/SQLite.java @@ -0,0 +1,248 @@ +package de.vortexhq.lobby.Utils.Data; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +import com.google.gson.JsonObject; +import de.vortexhq.lobby.Lobby; +import de.vortexhq.lobby.Utils.ArrayHelper; +import de.vortexhq.lobby.interfaces.IDataHandler; +import netscape.javascript.JSObject; + +import javax.annotation.Nullable; + +public class SQLite implements IDataHandler { + + private Connection con; + private Lobby plugin; + + public SQLite(Lobby plugin, String path) throws Exception { + + this.plugin = plugin; + + // setup connection + try { + this.con = connect(path); + } catch(Exception ex) { + throw new Exception("SQLite initailzatio failed due to exception" + ex.getLocalizedMessage(), ex.getCause()); + } + } + + private Connection connect(String path) throws Exception{ + try { + return DriverManager.getConnection("jdbc:sqlite:" + path); + } catch (Exception ex) { + throw new Exception("SQLite connection failed due to exception" + ex.getLocalizedMessage(), ex.getCause()); + } + } + + /** + * creates a table in the set database + * @param name the tables name + * @throws SQLException + */ + @Override + public void createTable(String name, Map fieldMap) { + String fields = ""; + + fields += "("; + for (Map.Entry entry : fieldMap.entrySet()) { + System.out.println(entry.getKey() + ":" + entry.getValue()); + fields += entry.getKey() + " " + entry.getValue(); + } + fields += ")"; + + try { + this.con.createStatement().executeQuery("CREATE TABLE IF NOT EXISTS " + name + " " + fields); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * executes a given query and returns a result of type int + * @param query the query to execute + * @param a2 secondary argument used to define the required field + * @return the found result of type int + */ + @Override + public int getInt(String stmt, String target) { + try { + int returning = 0; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getInt(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public int[] getInts(String stmt, String target) { + try { + int[] returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + ArrayHelper.push(returning, res.getInt(target)); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public double getDouble(String stmt, @Nullable String target) { + try { + double returning = 0; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getDouble(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public double[] getDoubles(String stmt, String target) { + try { + double[] returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + ArrayHelper.push(returning, res.getDouble(target)); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public String getString(String stmt, String target) { + try { + String returning = ""; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getString(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return ""; + } + + @Override + public String[] getStrings(String stmt, String target) { + try { + String[] returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + ArrayHelper.push(returning, res.getString(target)); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public boolean getBool(String stmt, String target) { + try { + boolean returning = {}; + ResultSet res = this.con.createStatement().executeQuery(stmt); + + while (res.next()) { + returning = res.getBoolean(target); + } + + return returning; + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } + + @Override + public boolean[] getBools(String stmt, String target) { + boolean[] result = {}; + + try { + ResultSet rs = this.con.createStatement().executeQuery(stmt); + while (rs.next()) { + result = ArrayHelper.push(result,rs.getBoolean(target)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return result; + } + + @Override + public JsonObject getResultAsJSON(String a1) { + JsonObject result = new JsonObject(); + + try { + ResultSet rs = this.con.createStatement().executeQuery(query); + while (rs.next()) { + // result = ArrayHelper.push(result,rs.getBoolean(target)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return result; + } + + @Override + public JsonObject[] getResultsAsJSON(String a1) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getResultsAsJSON'"); + } + + /** + * executes a query and returns the unproccessed resultset + * @param a1 the query given as a string + * @return a resultset to continue proccessing with + */ + @Override + public ResultSet getResults(String a1) { + throw new UnsupportedOperationException("Unimplemented method 'getRestuls'"); + } + + @Override + public boolean writeData(String query, Byte[] a2, Byte[] a3) { + throw new UnsupportedOperationException("Unimplemented method 'writeData'"); + } + + @Override + public Map getResultsAsMap(String a1) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getResultsAsMap'"); + } +} \ No newline at end of file diff --git a/src/main/java/de/vortexhq/lobby/Utils/Datahandler.java b/src/main/java/de/vortexhq/lobby/Utils/Datahandler.java new file mode 100644 index 0000000..0ea4a95 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Utils/Datahandler.java @@ -0,0 +1,63 @@ +package de.vortexhq.lobby.Utils; + +import java.util.Map; + +import de.vortexhq.lobby.Lobby; +import de.vortexhq.lobby.Utils.Data.MySQL; +import de.vortexhq.lobby.Utils.Data.SQLite; +import de.vortexhq.lobby.interfaces.IDataHandler; + +public class Datahandler { + private Lobby plugin; + private IDataHandler handler; + private String type; + + /** + * handles all data operations + * @param plugin a plugin reference + * @param type the type of datahandling + * @param url if mysql selected database url + * @param username if mysql selected database username + * @param password if mysql selected databaes password + */ + public Datahandler(Lobby plugin, String type, String url, String username, String password) { + plugin.Logger.Info("Initialize Database handler"); + this.plugin = plugin; + this.type = type; + + switch (type) { + case "mysql": + try { + this.plugin.getLogger().info("initializing mysql"); + this.handler = new MySQL(url, username, password, ""); + } catch (Exception e) { + this.plugin.getLogger().info("an error occured during mysql intialization exception thrown: " + e.getLocalizedMessage()); + e.printStackTrace(); + return; + } + break; + case "sqlite": + this.plugin.Logger.Info("Initialize SQLite Datasource"); + try { + this.handler = new SQLite(this.plugin, url); + } catch (Exception e) { + e.printStackTrace(); + return; + } + break; + } + } + + public void createTable(String tablename, Map fieldmap){ + try { + this.handler.createTable(tablename, fieldmap); + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + + public IDataHandler getDatahandler(){ + return handler; + } +} diff --git a/src/main/java/de/vortexhq/lobby/Utils/Log.java b/src/main/java/de/vortexhq/lobby/Utils/Log.java new file mode 100644 index 0000000..2b3be32 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/Utils/Log.java @@ -0,0 +1,50 @@ +package de.vortexhq.lobby.Utils; + +import de.vortexhq.lobby.Lobby; +import org.bukkit.ChatColor; + +public class Log { + private Lobby plugin; + private String prefix = ChatColor.GRAY + "[ " + ChatColor.BLUE + "LOBBY" + ChatColor.GRAY + "] "; + + public Log(Lobby plugin){ + Info("Initialized Logger"); + this.plugin = plugin; + } + + /** + * Send a formatted info log over the plugins logger + * @param MSG the message to log + */ + public void Info(String MSG) { + this.plugin.getLogger().info(prefix + ChatColor.BLUE + "INFO >> " + ChatColor.WHITE + MSG); + } + + /** + * Send a formatted warning log over the plugins logger + * @param MSG the message to log + */ + public void Warn(String MSG) { + this.plugin.getLogger().warning(prefix + ChatColor.GOLD + "WARNING >> " + MSG); + } + + /** + * Send a formatted error log over the plugins logger + * @param MSG the message to log + */ + public void Error(String MSG) { + this.plugin.getLogger().warning(prefix + ChatColor.RED + "ERROR >> " + MSG ); + } + + + /** + * handles reading the debugging property from config and sends a formatted debug log over the plugins logger + * @param MSG the message to log + */ + public void Debug(String MSG) { + // if debug mode isn't active escape out of this function + // if this doesn't work with performance cut debug logging all together + if (!this.plugin.config.getBoolean("debug")) return; + this.plugin.getLogger().info(prefix + ChatColor.GOLD + "DEBUG >> " + MSG); + } +} diff --git a/src/main/java/de/vortexhq/lobby/interfaces/IDataHandler.java b/src/main/java/de/vortexhq/lobby/interfaces/IDataHandler.java new file mode 100644 index 0000000..76275b0 --- /dev/null +++ b/src/main/java/de/vortexhq/lobby/interfaces/IDataHandler.java @@ -0,0 +1,84 @@ +package de.vortexhq.lobby.interfaces; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.util.Map; + +import com.google.gson.JsonObject; +import netscape.javascript.JSObject; + +public interface IDataHandler { + /** + * get integers values from a datasource + * @param a1 first argument usually used as target value + * @param a2 second argument usually used as value or extra file + * @return value of type int + */ + public int getInt(String a1, String a2); + public int[] getInts(String a1, String a2); + + /** + * get floats values from a datasource + * @param a1 first argument usually used as target value + * @param a2 second argument usually used as value or extra file + * @return value of type float + */ + public double getDouble(String a1, String a2); + public double[] getDoubles(String a1, String a2); + + /** + * get strings values from a datasource + * @param a1 first argument usually used as target value + * @param a2 second argument usually used as value or extra file + * @return value of type String + */ + public String getString(String a1, String a2); + public String[] getStrings(String a1, String a2); + + /** + * get boolean values from a datasource + * @param a1 first argument usually used as target value + * @param a2 second argument usually used as value or extra file + * @return value of type int + */ + public boolean getBool(String a1, String a2); + public boolean[] getBools(String a1, String a2); + + /** + * executes a query and returns the unproccessed resultset + * @param a1 the query given as a string + * @return a resultset to continue proccessing with + */ + public ResultSet getResults(String a1); + + /** + * executes given query and returns result as json object + * @param a1 the query to execute + * @return the result as JSONObject + */ + public JsonObject getResultAsJSON(String a1); + public JsonObject[] getResultsAsJSON(String a1); + + /** + * executes a query and returns untyped results as map + * @param a1 the query given as a string + * @return a resultset to continue proccessing with + */ + public Map getResultsAsMap(String a1); + + /** + * write values to a set datasource + * @param a1 first argument usually used as location or statement + * @param a2 second argument usually used as value or config location + * @param a3 third argument usually used as value or extra file + * @return if the write operation was successful + */ + public boolean writeData(String a1, Byte[] a3); + + /** + * creates table if the datasource supports it + * @param name the table name + * @param fieldMap a map[string]string of the files and their types for that given table + */ + public void createTable(String name, Map fieldMap); +} diff --git a/src/main/resources/menus.yml b/src/main/resources/menus.yml index ad432ac..778020a 100644 --- a/src/main/resources/menus.yml +++ b/src/main/resources/menus.yml @@ -3,7 +3,7 @@ menus: title: "Navigator" identifier: "navigator" slots: 54 - permission: slpnet.lobby.navigator + permission: lobby.menu.navigator items: TRIDENT: title: "TridentWar" @@ -33,7 +33,7 @@ menus: title: "Profile" identifier: "profile" slots: 54 - permission: slpnet.lobby.profile + permission: lobby.menu.profile items: TRIDENT: title: "TridentWar"