diff --git a/src/main/java/me/fivevl/doublejump/JumpCommand.java b/src/main/java/me/fivevl/doublejump/JumpCommand.java new file mode 100644 index 0000000..53ce201 --- /dev/null +++ b/src/main/java/me/fivevl/doublejump/JumpCommand.java @@ -0,0 +1,26 @@ +package me.fivevl.doublejump; + +import me.fivevl.doublejump.guis.JumpGui; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class JumpCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use this command!"); + return true; + } + Player p = (Player) sender; + if (!p.hasPermission("doublejump.gui")) { + p.sendMessage("You don't have permission to use this command!"); + return true; + } + p.openInventory(JumpGui.getGui(p)); + Main.inGui.add(p); + return true; + } +} diff --git a/src/main/java/me/fivevl/doublejump/Main.java b/src/main/java/me/fivevl/doublejump/Main.java index 26632b4..54619b3 100644 --- a/src/main/java/me/fivevl/doublejump/Main.java +++ b/src/main/java/me/fivevl/doublejump/Main.java @@ -9,9 +9,11 @@ import org.bukkit.plugin.java.JavaPlugin; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class Main extends JavaPlugin { public static List doDoubleJump = new ArrayList<>(); + public static List inGui = new ArrayList<>(); private static Main instance; public static Main getInstance() { return instance; @@ -23,6 +25,7 @@ public class Main extends JavaPlugin { @Override public void onEnable() { instance = this; + saveDefaultConfig(); sql = new MySQL(); try { setupDatabase(); @@ -31,6 +34,7 @@ public class Main extends JavaPlugin { } Bukkit.getPluginManager().registerEvents(new OnFly(), this); Bukkit.getPluginManager().registerEvents(new OnJump(), this); + Objects.requireNonNull(getCommand("jump")).setExecutor(new JumpCommand()); getLogger().info("DoubleJump enabled!"); } diff --git a/src/main/java/me/fivevl/doublejump/MySQL.java b/src/main/java/me/fivevl/doublejump/MySQL.java index ed84797..a0fa481 100644 --- a/src/main/java/me/fivevl/doublejump/MySQL.java +++ b/src/main/java/me/fivevl/doublejump/MySQL.java @@ -19,7 +19,9 @@ public class MySQL implements Database { @Override public void disconnect() throws SQLException { - connection.close(); + if (isConnected()) { + connection.close(); + } } @Override diff --git a/src/main/java/me/fivevl/doublejump/guis/JumpGui.java b/src/main/java/me/fivevl/doublejump/guis/JumpGui.java new file mode 100644 index 0000000..986d098 --- /dev/null +++ b/src/main/java/me/fivevl/doublejump/guis/JumpGui.java @@ -0,0 +1,14 @@ +package me.fivevl.doublejump.guis; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +public class JumpGui { + @SuppressWarnings("deprecation") + public static Inventory getGui(Player p) { + Inventory inv = Bukkit.createInventory(null, 27, "Jump Strength"); + + return inv; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 473e7bd..810cc43 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,6 @@ database: # Database configuration, please change it to a valid one. host: "12.34.56.78" - port: 3306 + port: "3306" username: "admin" password: "password" database: "database" \ No newline at end of file