Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d955d55a7 |
No files matched your search
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.pgadual</groupId>
|
||||
<artifactId>PGADuals</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>PgaDuals</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>paperapi-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url> </repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>26.2.build.121-stable</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.pgadual;
|
||||
import me.pgadual.commands.Dual;
|
||||
import me.pgadual.games.InstanceManager;
|
||||
import me.pgadual.handlers.Dbms;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class PgaDuals extends JavaPlugin {
|
||||
|
||||
private static PgaDuals instance;
|
||||
private InstanceManager instanceManager;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
instanceManager = new InstanceManager();
|
||||
Dbms db = new Dbms();
|
||||
db.init();
|
||||
getCommand("dual").setExecutor(new Dual());
|
||||
|
||||
}
|
||||
|
||||
public InstanceManager getInstanceManager() {
|
||||
return instanceManager;
|
||||
}
|
||||
|
||||
|
||||
public static PgaDuals getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package me.pgadual.commands;
|
||||
|
||||
import me.pgadual.commands.admin.map.Create;
|
||||
import me.pgadual.games.Games;
|
||||
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;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Dual implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
||||
if (sender instanceof Player) {
|
||||
if (sender.isOp()) { // TODO: fix perms for regular dual command
|
||||
Player p = (Player) sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
p.sendMessage("Usage: /dual <player_name>. See /dual help for more commands.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("create")) {
|
||||
|
||||
if (args.length < 3) {
|
||||
p.sendMessage("Usage: /dual create <game> <map_name>");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!args[1].isEmpty() && !args[2].isEmpty()) {
|
||||
Create c = new Create();
|
||||
String game = args[1].toUpperCase();
|
||||
|
||||
if (game.equals(Games.gamesList.BOW_DUAL.toString())) {
|
||||
c.create_cmd_tasks(p, Games.gamesList.BOW_DUAL, args[2]);
|
||||
}
|
||||
|
||||
else if (game.equals(Games.gamesList.ONE_V_ONE.toString())) {
|
||||
c.create_cmd_tasks(p, Games.gamesList.ONE_V_ONE, args[2]);
|
||||
}
|
||||
|
||||
else {
|
||||
p.sendMessage("Invalid game name! Options are: " + Arrays.toString(Games.gamesList.values()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else if (args.length == 1) {
|
||||
Games g = new Games();
|
||||
g.start_game(Games.gamesList.BOW_DUAL, p, p);
|
||||
}
|
||||
|
||||
else {
|
||||
p.sendMessage("Invalid Argument!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package me.pgadual.commands.admin.map;// Create a map
|
||||
|
||||
|
||||
import me.pgadual.games.Games;
|
||||
import me.pgadual.handlers.Dbms;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Create {
|
||||
public void create_cmd_tasks(Player p, Games.gamesList game_name, String map_name) { //TODO: implement map name
|
||||
Dbms db = new Dbms();
|
||||
World world = p.getWorld();
|
||||
db.add_world(game_name, world);
|
||||
p.sendMessage("Success! Created new map with " + map_name + " at world " + p.getWorld().getName() + " (current).");
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1 @@
|
||||
// Set the world backup state
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.pgadual.games;
|
||||
import org.bukkit.World;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GameManager {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package me.pgadual.games;
|
||||
import me.pgadual.PgaDuals;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Games {
|
||||
|
||||
public enum gamesList {
|
||||
BOW_DUAL,
|
||||
ONE_V_ONE
|
||||
}
|
||||
|
||||
public void start_game(gamesList game, Player p1, Player p2) {
|
||||
|
||||
InstanceManager i = PgaDuals.getInstance().getInstanceManager();
|
||||
|
||||
if (game == gamesList.BOW_DUAL) {
|
||||
World game_world = i.create_instance(Games.gamesList.BOW_DUAL);
|
||||
if (game_world == null) {
|
||||
p1.getPlayer().sendMessage("Could not start dual as all worlds associated with the game are in use! (" + i.get_instances().get(gamesList.BOW_DUAL).size() + "/" + i.get_instances().get(gamesList.BOW_DUAL).size() + " worlds taken)");
|
||||
//p2.getPlayer().sendMessage("Could not start dual as all worlds associated with the game are in use! (" + i.get_instances().get(gamesList.BOW_DUAL).size() + "/" + i.get_instances().size() + " worlds taken)");
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: add tp to the correct defined spawn positions
|
||||
p1.getPlayer().teleport(game_world.getSpawnLocation());
|
||||
//p2.getPlayer().teleport(game_world.getSpawnLocation());
|
||||
}
|
||||
|
||||
|
||||
else if (game == gamesList.ONE_V_ONE) {
|
||||
World game_world = i.create_instance(gamesList.ONE_V_ONE);
|
||||
if (game_world == null) {
|
||||
p1.getPlayer().sendMessage("Could not start dual as all worlds associated with the game are in use! (" + i.get_instances().get(gamesList.ONE_V_ONE).size() + "/" + i.get_instances().get(gamesList.ONE_V_ONE).size() + " worlds taken)");
|
||||
//p2.getPlayer().sendMessage("Could not start dual as all worlds associated with the game are in use! (" + i.get_instances().get(gamesList.ONE_V_ONE).size() + "/" + i.get_instances().size() + " worlds taken)");
|
||||
return;
|
||||
}
|
||||
|
||||
p1.getPlayer().teleport(game_world.getSpawnLocation());
|
||||
//p2.getPlayer().teleport(game_world.getSpawnLocation());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.pgadual.games;
|
||||
|
||||
import me.pgadual.handlers.Dbms;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class InstanceManager {
|
||||
private final HashMap<Games.gamesList, List<World>> instances = new HashMap<>();
|
||||
|
||||
public HashMap<Games.gamesList, List<World>> get_instances() {
|
||||
return instances;
|
||||
}
|
||||
|
||||
public World create_instance(Games.gamesList game) {
|
||||
|
||||
Bukkit.getLogger().info(game.name());
|
||||
|
||||
Dbms db = new Dbms();
|
||||
World[] worlds = db.get_worlds(game);
|
||||
|
||||
List<World> activeInstances = instances.computeIfAbsent(game, k -> new ArrayList<>());
|
||||
List<World> availableWorlds = new ArrayList<>();
|
||||
|
||||
if (worlds == null){return null;};
|
||||
|
||||
if (activeInstances.size() >= worlds.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
for (World world : worlds) {
|
||||
if (!activeInstances.contains(world)) {
|
||||
availableWorlds.add(world);
|
||||
}
|
||||
}
|
||||
|
||||
World pickedWorld = availableWorlds.get(random.nextInt(availableWorlds.size()));
|
||||
|
||||
activeInstances.add(pickedWorld);
|
||||
|
||||
return pickedWorld;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void remove_instance(Games.gamesList game, World world) {
|
||||
List<World> activeWorlds = instances.get(game);
|
||||
|
||||
if (activeWorlds == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeWorlds.remove(world);
|
||||
|
||||
if (activeWorlds.isEmpty()) {
|
||||
instances.remove(game);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,6 @@
|
||||
package me.pgadual.games.bowDual;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class bowDual extends JavaPlugin {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.pgadual.games;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public class mains {
|
||||
static void main() {
|
||||
InstanceManager i = new InstanceManager();
|
||||
World world_to_tp = i.create_instance(Games.gamesList.BOW_DUAL);
|
||||
// Tp player and start the game
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package me.pgadual.handlers;
|
||||
|
||||
import me.pgadual.games.Games;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Dbms {
|
||||
|
||||
String url = "jdbc:sqlite:dual_games.db";
|
||||
|
||||
public void init() {
|
||||
|
||||
String games_and_worlds_table = "CREATE TABLE IF NOT EXISTS 'worlds' ('game_name' TEXT, 'world_name' TEXT UNIQUE)";
|
||||
|
||||
try {
|
||||
|
||||
|
||||
Connection conn = DriverManager.getConnection(url);
|
||||
Statement statement = conn.createStatement();
|
||||
statement.addBatch(games_and_worlds_table);
|
||||
statement.executeBatch();
|
||||
conn.close();
|
||||
|
||||
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public World[] get_worlds(Games.gamesList game) {
|
||||
|
||||
List<World> worlds = new ArrayList<>();
|
||||
String world_query = "SELECT * FROM worlds WHERE game_name = ?";
|
||||
|
||||
try {
|
||||
|
||||
Connection conn = DriverManager.getConnection(url);
|
||||
PreparedStatement ps = conn.prepareStatement(world_query);
|
||||
ps.setString(1, game.toString());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
World world = Bukkit.getWorld(rs.getString("world_name"));
|
||||
|
||||
if (world != null) {
|
||||
worlds.add(world);
|
||||
}
|
||||
}
|
||||
|
||||
return worlds.toArray(new World[0]);
|
||||
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void add_world(Games.gamesList game, World world) {
|
||||
String world_query = "INSERT OR IGNORE INTO worlds (game_name, world_name) VALUES (?, ?) ";
|
||||
|
||||
try {
|
||||
|
||||
Connection conn = DriverManager.getConnection(url);
|
||||
PreparedStatement ps = conn.prepareStatement(world_query);
|
||||
ps.setString(1, game.toString());
|
||||
ps.setString(2, world.getName());
|
||||
ps.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,9 @@
|
||||
name: PGADual
|
||||
version: '${project.version}'
|
||||
main: me.pgadual.PgaDuals
|
||||
api-version: 26.2
|
||||
commands:
|
||||
dual:
|
||||
description: dual stuff
|
||||
usage: /<command>
|
||||
permission: dual.dual
|
||||
Reference in new issue
Block a user