mirror of
https://github.com/5vl/DoubleJump.git
synced 2025-05-24 06:06:59 +00:00
added double jump and mysql support for the most part
This commit is contained in:
parent
db288cd997
commit
2262ca36a6
24
pom.xml
24
pom.xml
@ -36,30 +36,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
|
||||||
<artifactId>kotlin-maven-plugin</artifactId>
|
|
||||||
<version>${kotlin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>compile</id>
|
|
||||||
<phase>process-sources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>compile</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>test-compile</id>
|
|
||||||
<phase>test-compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test-compile</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<jvmTarget>1.8</jvmTarget>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
17
src/main/java/me/fivevl/doublejump/Database.java
Normal file
17
src/main/java/me/fivevl/doublejump/Database.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package me.fivevl.doublejump;
|
||||||
|
|
||||||
|
import javax.sql.rowset.CachedRowSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public interface Database {
|
||||||
|
void connect() throws SQLException;
|
||||||
|
void disconnect() throws SQLException;
|
||||||
|
boolean isConnected() throws SQLException;
|
||||||
|
void setUsername(String username);
|
||||||
|
void setPassword(String password);
|
||||||
|
void setHost(String host);
|
||||||
|
void setDatabase(String database);
|
||||||
|
void setPort(String port);
|
||||||
|
CachedRowSet query(String query) throws SQLException;
|
||||||
|
void execute(String query) throws SQLException;
|
||||||
|
}
|
@ -1,15 +1,72 @@
|
|||||||
package me.fivevl.doublejump;
|
package me.fivevl.doublejump;
|
||||||
|
|
||||||
|
import me.fivevl.doublejump.events.OnFly;
|
||||||
|
import me.fivevl.doublejump.events.OnJump;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
|
public static List<Player> doDoubleJump = new ArrayList<>();
|
||||||
|
private static Main instance;
|
||||||
|
public static Main getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
private static MySQL sql;
|
||||||
|
public static MySQL getMySQL() {
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
sql = new MySQL();
|
||||||
|
try {
|
||||||
|
setupDatabase();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Bukkit.getPluginManager().registerEvents(new OnFly(), this);
|
||||||
|
Bukkit.getPluginManager().registerEvents(new OnJump(), this);
|
||||||
getLogger().info("DoubleJump enabled!");
|
getLogger().info("DoubleJump enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
try {
|
||||||
|
sql.disconnect();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
getLogger().info("DoubleJump disabled!");
|
getLogger().info("DoubleJump disabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupDatabase() throws SQLException {
|
||||||
|
ConfigurationSection config = getConfig().getConfigurationSection("database");
|
||||||
|
if (config == null) {
|
||||||
|
getLogger().severe("Database configuration not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String[] credentials = {config.getString("host"), config.getString("port"), config.getString("database"), config.getString("username"), config.getString("password")};
|
||||||
|
for (String s : credentials) {
|
||||||
|
if (s == null) {
|
||||||
|
getLogger().severe("Correct database configuration not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (credentials[0].equalsIgnoreCase("12.34.56.78")) {
|
||||||
|
getLogger().severe("Please set the database credentials in the config.yml!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sql.setUsername(credentials[3]);
|
||||||
|
sql.setPassword(credentials[4]);
|
||||||
|
sql.setHost(credentials[0]);
|
||||||
|
sql.setPort(credentials[1]);
|
||||||
|
sql.setDatabase(credentials[2]);
|
||||||
|
sql.connect();
|
||||||
|
sql.execute("CREATE TABLE IF NOT EXISTS `settings` (`uuid` VARCHAR(36) NOT NULL, `strength` DOUBLE NOT NULL DEFAULT '1', PRIMARY KEY (`uuid`))");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
66
src/main/java/me/fivevl/doublejump/MySQL.java
Normal file
66
src/main/java/me/fivevl/doublejump/MySQL.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package me.fivevl.doublejump;
|
||||||
|
|
||||||
|
import javax.sql.rowset.CachedRowSet;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class MySQL implements Database {
|
||||||
|
private Connection connection;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private String database;
|
||||||
|
private String host;
|
||||||
|
private String port;
|
||||||
|
@Override
|
||||||
|
public void connect() throws SQLException {
|
||||||
|
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect() throws SQLException {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConnected() throws SQLException {
|
||||||
|
return !connection.isClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDatabase(String database) {
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPort(String port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CachedRowSet query(String query) throws SQLException{
|
||||||
|
CachedRowSet cachedRowSet = new com.sun.rowset.CachedRowSetImpl();
|
||||||
|
cachedRowSet.populate(connection.prepareStatement(query).executeQuery());
|
||||||
|
return cachedRowSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String query) throws SQLException {
|
||||||
|
connection.prepareStatement(query).execute();
|
||||||
|
}
|
||||||
|
}
|
21
src/main/java/me/fivevl/doublejump/events/OnFly.java
Normal file
21
src/main/java/me/fivevl/doublejump/events/OnFly.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package me.fivevl.doublejump.events;
|
||||||
|
|
||||||
|
import me.fivevl.doublejump.Main;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class OnFly implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onFly(PlayerToggleFlightEvent e) {
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
if (p.hasPermission("doublejump.use") && Main.doDoubleJump.contains(p) && (p.getGameMode() == GameMode.ADVENTURE || p.getGameMode() == GameMode.SURVIVAL)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
p.setAllowFlight(false);
|
||||||
|
p.setVelocity(p.getLocation().getDirection().multiply(2.0D));
|
||||||
|
p.setFallDistance(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
src/main/java/me/fivevl/doublejump/events/OnJump.java
Normal file
24
src/main/java/me/fivevl/doublejump/events/OnJump.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package me.fivevl.doublejump.events;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class OnJump implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onJump(PlayerJumpEvent e) {
|
||||||
|
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(), () -> {
|
||||||
|
p.setAllowFlight(false);
|
||||||
|
Main.doDoubleJump.remove(p);
|
||||||
|
}, 20L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
src/main/resources/config.yml
Normal file
6
src/main/resources/config.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
database: # Database configuration, please change it to a valid one.
|
||||||
|
host: "12.34.56.78"
|
||||||
|
port: 3306
|
||||||
|
username: "admin"
|
||||||
|
password: "password"
|
||||||
|
database: "database"
|
@ -4,3 +4,6 @@ main: me.fivevl.doublejump.Main
|
|||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
authors: [ 5vl ]
|
authors: [ 5vl ]
|
||||||
description: A trial project for DevRoom.
|
description: A trial project for DevRoom.
|
||||||
|
commands:
|
||||||
|
jump:
|
||||||
|
description: Opens the main GUI
|
Loading…
x
Reference in New Issue
Block a user