jump gui command

This commit is contained in:
5vl 2022-04-08 14:30:51 +02:00
parent 2262ca36a6
commit 82b08ff1d5
No known key found for this signature in database
GPG Key ID: DA8938F22548E4D5
5 changed files with 48 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -9,9 +9,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
public static List<Player> doDoubleJump = new ArrayList<>(); public static List<Player> doDoubleJump = new ArrayList<>();
public static List<Player> inGui = new ArrayList<>();
private static Main instance; private static Main instance;
public static Main getInstance() { public static Main getInstance() {
return instance; return instance;
@ -23,6 +25,7 @@ public class Main extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
instance = this; instance = this;
saveDefaultConfig();
sql = new MySQL(); sql = new MySQL();
try { try {
setupDatabase(); setupDatabase();
@ -31,6 +34,7 @@ public class Main extends JavaPlugin {
} }
Bukkit.getPluginManager().registerEvents(new OnFly(), this); Bukkit.getPluginManager().registerEvents(new OnFly(), this);
Bukkit.getPluginManager().registerEvents(new OnJump(), this); Bukkit.getPluginManager().registerEvents(new OnJump(), this);
Objects.requireNonNull(getCommand("jump")).setExecutor(new JumpCommand());
getLogger().info("DoubleJump enabled!"); getLogger().info("DoubleJump enabled!");
} }

View File

@ -19,8 +19,10 @@ public class MySQL implements Database {
@Override @Override
public void disconnect() throws SQLException { public void disconnect() throws SQLException {
if (isConnected()) {
connection.close(); connection.close();
} }
}
@Override @Override
public boolean isConnected() throws SQLException { public boolean isConnected() throws SQLException {

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
database: # Database configuration, please change it to a valid one. database: # Database configuration, please change it to a valid one.
host: "12.34.56.78" host: "12.34.56.78"
port: 3306 port: "3306"
username: "admin" username: "admin"
password: "password" password: "password"
database: "database" database: "database"