mirror of
https://github.com/5vl/DoubleJump.git
synced 2025-05-24 02:27:01 +00:00
i think im done now?
This commit is contained in:
parent
82b08ff1d5
commit
266921adb4
@ -6,21 +6,26 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.sql.SQLException;
|
||||
|
||||
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!");
|
||||
sender.sendMessage(Main.color("&cOnly 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!");
|
||||
p.sendMessage(Main.color("You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
p.openInventory(JumpGui.getGui(p));
|
||||
Main.inGui.add(p);
|
||||
try {
|
||||
p.openInventory(JumpGui.getGui(p));
|
||||
Main.inGui.add(p);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,22 @@
|
||||
package me.fivevl.doublejump;
|
||||
|
||||
import me.fivevl.doublejump.events.OnFly;
|
||||
import me.fivevl.doublejump.events.OnInventoryClick;
|
||||
import me.fivevl.doublejump.events.OnJoin;
|
||||
import me.fivevl.doublejump.events.OnJump;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
public static List<Player> doDoubleJump = new ArrayList<>();
|
||||
public static HashMap<Player, Integer> doDoubleJump = new HashMap<>();
|
||||
public static List<Player> inGui = new ArrayList<>();
|
||||
private static Main instance;
|
||||
public static Main getInstance() {
|
||||
@ -34,6 +38,8 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(new OnFly(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new OnJump(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new OnJoin(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new OnInventoryClick(), this);
|
||||
Objects.requireNonNull(getCommand("jump")).setExecutor(new JumpCommand());
|
||||
getLogger().info("DoubleJump enabled!");
|
||||
}
|
||||
@ -73,4 +79,8 @@ public class Main extends JavaPlugin {
|
||||
sql.connect();
|
||||
sql.execute("CREATE TABLE IF NOT EXISTS `settings` (`uuid` VARCHAR(36) NOT NULL, `strength` DOUBLE NOT NULL DEFAULT '1', PRIMARY KEY (`uuid`))");
|
||||
}
|
||||
|
||||
public static String color(String s) {
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.fivevl.doublejump;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import javax.sql.rowset.RowSetProvider;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
@ -56,7 +57,7 @@ public class MySQL implements Database {
|
||||
|
||||
@Override
|
||||
public CachedRowSet query(String query) throws SQLException{
|
||||
CachedRowSet cachedRowSet = new com.sun.rowset.CachedRowSetImpl();
|
||||
CachedRowSet cachedRowSet = RowSetProvider.newFactory().createCachedRowSet();
|
||||
cachedRowSet.populate(connection.prepareStatement(query).executeQuery());
|
||||
return cachedRowSet;
|
||||
}
|
||||
|
@ -1,20 +1,28 @@
|
||||
package me.fivevl.doublejump.events;
|
||||
|
||||
import me.fivevl.doublejump.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class OnFly implements Listener {
|
||||
@EventHandler
|
||||
public void onFly(PlayerToggleFlightEvent e) {
|
||||
public void onFly(PlayerToggleFlightEvent e) throws SQLException {
|
||||
Player p = e.getPlayer();
|
||||
if (p.hasPermission("doublejump.use") && Main.doDoubleJump.contains(p) && (p.getGameMode() == GameMode.ADVENTURE || p.getGameMode() == GameMode.SURVIVAL)) {
|
||||
if (p.hasPermission("doublejump.use") && Main.doDoubleJump.containsKey(p) && (p.getGameMode() == GameMode.ADVENTURE || p.getGameMode() == GameMode.SURVIVAL)) {
|
||||
e.setCancelled(true);
|
||||
p.setAllowFlight(false);
|
||||
p.setVelocity(p.getLocation().getDirection().multiply(2.0D));
|
||||
Bukkit.getScheduler().cancelTask(Main.doDoubleJump.get(p));
|
||||
Main.doDoubleJump.remove(p);
|
||||
CachedRowSet rs = Main.getMySQL().query("SELECT * FROM `settings` WHERE `uuid` = '" + p.getUniqueId() + "'");
|
||||
rs.next();
|
||||
p.setVelocity(p.getLocation().getDirection().multiply(rs.getDouble("strength")));
|
||||
p.setFallDistance(0);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package me.fivevl.doublejump.events;
|
||||
|
||||
import me.fivevl.doublejump.Main;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collections;
|
||||
|
||||
public class OnInventoryClick implements Listener {
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent e) throws SQLException {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (!Main.inGui.contains(p)) return;
|
||||
e.setCancelled(true);
|
||||
CachedRowSet rs = Main.getMySQL().query("SELECT * FROM `settings` WHERE `uuid` = '" + p.getUniqueId() + "'");
|
||||
rs.next();
|
||||
double strength = rs.getDouble("strength");
|
||||
double newStrength = strength;
|
||||
if (e.getRawSlot() == 12) newStrength = strength - 0.2;
|
||||
if (e.getRawSlot() == 14) newStrength = strength + 0.2;
|
||||
if (newStrength < 1) newStrength = 1;
|
||||
if (newStrength > 5) newStrength = 5;
|
||||
if (strength == newStrength) return;
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
df.setRoundingMode(RoundingMode.CEILING);
|
||||
newStrength = Double.parseDouble(df.format(newStrength).replace(",", "."));
|
||||
Inventory inv = e.getClickedInventory();
|
||||
ItemStack item = inv.getItem(13);
|
||||
ItemMeta currentStrengthMeta = item.getItemMeta();
|
||||
currentStrengthMeta.setLore(Collections.singletonList(Main.color("&e" + newStrength)));
|
||||
item.setItemMeta(currentStrengthMeta);
|
||||
inv.setItem(13, item);
|
||||
Main.getMySQL().execute("UPDATE `settings` SET `strength` = '" + newStrength + "' WHERE `uuid` = '" + p.getUniqueId() + "'");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent e) {
|
||||
Main.inGui.remove((Player) e.getPlayer());
|
||||
}
|
||||
}
|
20
src/main/java/me/fivevl/doublejump/events/OnJoin.java
Normal file
20
src/main/java/me/fivevl/doublejump/events/OnJoin.java
Normal file
@ -0,0 +1,20 @@
|
||||
package me.fivevl.doublejump.events;
|
||||
|
||||
import me.fivevl.doublejump.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class OnJoin implements Listener {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) throws SQLException {
|
||||
Player p = e.getPlayer();
|
||||
CachedRowSet rs = Main.getMySQL().query("SELECT * FROM `settings` WHERE `uuid` = '" + p.getUniqueId() + "'");
|
||||
if (!rs.next()) {
|
||||
Main.getMySQL().execute("INSERT INTO `settings` (`uuid`, `strength`) VALUES ('" + p.getUniqueId() + "', default)");
|
||||
}
|
||||
}
|
||||
}
|
@ -14,11 +14,11 @@ public class OnJump implements Listener {
|
||||
Player p = e.getPlayer();
|
||||
if (p.hasPermission("doublejump.use") && (p.getGameMode() == GameMode.ADVENTURE || p.getGameMode() == GameMode.SURVIVAL)) {
|
||||
p.setAllowFlight(true);
|
||||
Main.doDoubleJump.add(p);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
|
||||
int id = Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
|
||||
p.setAllowFlight(false);
|
||||
Main.doDoubleJump.remove(p);
|
||||
}, 20L);
|
||||
Main.doDoubleJump.put(p, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,51 @@
|
||||
package me.fivevl.doublejump.guis;
|
||||
|
||||
import me.fivevl.doublejump.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
public class JumpGui {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Inventory getGui(Player p) {
|
||||
Inventory inv = Bukkit.createInventory(null, 27, "Jump Strength");
|
||||
public static Inventory getGui(Player p) throws SQLException {
|
||||
Inventory inv = Bukkit.createInventory(null, 27, Main.color("&8Jump Strength Menu"));
|
||||
ItemStack glass = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1);
|
||||
ItemMeta glassMeta = glass.getItemMeta();
|
||||
glassMeta.setDisplayName(" ");
|
||||
glass.setItemMeta(glassMeta);
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
inv.setItem(i, glass);
|
||||
}
|
||||
|
||||
ItemStack decreaseStrength = new ItemStack(Material.ARROW, 1);
|
||||
ItemMeta decreaseStrengthMeta = decreaseStrength.getItemMeta();
|
||||
decreaseStrengthMeta.setDisplayName(Main.color("&9Decrease Strength"));
|
||||
decreaseStrength.setItemMeta(decreaseStrengthMeta);
|
||||
inv.setItem(12, decreaseStrength);
|
||||
|
||||
ItemStack increaseStrength = new ItemStack(Material.ARROW, 1);
|
||||
ItemMeta increaseStrengthMeta = increaseStrength.getItemMeta();
|
||||
increaseStrengthMeta.setDisplayName(Main.color("&9Increase Strength"));
|
||||
increaseStrength.setItemMeta(increaseStrengthMeta);
|
||||
inv.setItem(14, increaseStrength);
|
||||
|
||||
|
||||
CachedRowSet rs = Main.getMySQL().query("SELECT * FROM `settings` WHERE `uuid` = '" + p.getUniqueId() + "'");
|
||||
if (rs.next()) {
|
||||
ItemStack currentStrength = new ItemStack(Material.FEATHER, 1);
|
||||
ItemMeta currentStrengthMeta = currentStrength.getItemMeta();
|
||||
currentStrengthMeta.setDisplayName(Main.color("&2Current Jump Strength"));
|
||||
currentStrengthMeta.setLore(Collections.singletonList(Main.color("&e" + rs.getDouble("strength"))));
|
||||
currentStrength.setItemMeta(currentStrengthMeta);
|
||||
inv.setItem(13, currentStrength);
|
||||
}
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user