+113
.gitignore
+113
.gitignore
···
1
+
# User-specific stuff
2
+
.idea/
3
+
4
+
*.iml
5
+
*.ipr
6
+
*.iws
7
+
8
+
# IntelliJ
9
+
out/
10
+
11
+
# Compiled class file
12
+
*.class
13
+
14
+
# Log file
15
+
*.log
16
+
17
+
# BlueJ files
18
+
*.ctxt
19
+
20
+
# Package Files #
21
+
*.jar
22
+
*.war
23
+
*.nar
24
+
*.ear
25
+
*.zip
26
+
*.tar.gz
27
+
*.rar
28
+
29
+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30
+
hs_err_pid*
31
+
32
+
*~
33
+
34
+
# temporary files which can be created if a process still has a handle open of a deleted file
35
+
.fuse_hidden*
36
+
37
+
# KDE directory preferences
38
+
.directory
39
+
40
+
# Linux trash folder which might appear on any partition or disk
41
+
.Trash-*
42
+
43
+
# .nfs files are created when an open file is removed but is still being accessed
44
+
.nfs*
45
+
46
+
# General
47
+
.DS_Store
48
+
.AppleDouble
49
+
.LSOverride
50
+
51
+
# Icon must end with two \r
52
+
Icon
53
+
54
+
# Thumbnails
55
+
._*
56
+
57
+
# Files that might appear in the root of a volume
58
+
.DocumentRevisions-V100
59
+
.fseventsd
60
+
.Spotlight-V100
61
+
.TemporaryItems
62
+
.Trashes
63
+
.VolumeIcon.icns
64
+
.com.apple.timemachine.donotpresent
65
+
66
+
# Directories potentially created on remote AFP share
67
+
.AppleDB
68
+
.AppleDesktop
69
+
Network Trash Folder
70
+
Temporary Items
71
+
.apdisk
72
+
73
+
# Windows thumbnail cache files
74
+
Thumbs.db
75
+
Thumbs.db:encryptable
76
+
ehthumbs.db
77
+
ehthumbs_vista.db
78
+
79
+
# Dump file
80
+
*.stackdump
81
+
82
+
# Folder config file
83
+
[Dd]esktop.ini
84
+
85
+
# Recycle Bin used on file shares
86
+
$RECYCLE.BIN/
87
+
88
+
# Windows Installer files
89
+
*.cab
90
+
*.msi
91
+
*.msix
92
+
*.msm
93
+
*.msp
94
+
95
+
# Windows shortcuts
96
+
*.lnk
97
+
98
+
target/
99
+
100
+
pom.xml.tag
101
+
pom.xml.releaseBackup
102
+
pom.xml.versionsBackup
103
+
pom.xml.next
104
+
105
+
release.properties
106
+
dependency-reduced-pom.xml
107
+
buildNumber.properties
108
+
.mvn/timing.properties
109
+
.mvn/wrapper/maven-wrapper.jar
110
+
.flattened-pom.xml
111
+
112
+
# Common working directory
113
+
run/
+8
META-INF/MANIFEST.MF
+8
META-INF/MANIFEST.MF
···
1
+
Manifest-Version: 1.0
2
+
Main-Class:
3
+
Class-Path: kotlin-stdlib-jdk8-1.6.20.jar kotlin-stdlib-1.7.10.jar okio-
4
+
jvm-3.2.0.jar okhttp-jvm-5.0.0-alpha.11.jar annotations-24.0.1.jar jack
5
+
son-databind-2.15.1.jar jackson-core-2.14.2.jar kotlin-stdlib-jdk7-1.6.
6
+
20.jar okhttp-5.0.0-alpha.11.jar kotlin-stdlib-common-1.7.10.jar jackso
7
+
n-annotations-2.15.1.jar
8
+
+4
claim.md
+4
claim.md
+89
pom.xml
+89
pom.xml
···
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+
<modelVersion>4.0.0</modelVersion>
6
+
7
+
<groupId>dev.keii</groupId>
8
+
<artifactId>KeiiChunks</artifactId>
9
+
<version>1.0-SNAPSHOT</version>
10
+
<packaging>jar</packaging>
11
+
12
+
<name>KeiiChunks</name>
13
+
14
+
<properties>
15
+
<java.version>1.8</java.version>
16
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17
+
</properties>
18
+
19
+
<build>
20
+
<plugins>
21
+
<plugin>
22
+
<groupId>org.apache.maven.plugins</groupId>
23
+
<artifactId>maven-compiler-plugin</artifactId>
24
+
<version>3.8.1</version>
25
+
<configuration>
26
+
<source>16</source>
27
+
<target>16</target>
28
+
</configuration>
29
+
</plugin>
30
+
<plugin>
31
+
<groupId>org.apache.maven.plugins</groupId>
32
+
<artifactId>maven-shade-plugin</artifactId>
33
+
<version>3.2.4</version>
34
+
<executions>
35
+
<execution>
36
+
<phase>package</phase>
37
+
<goals>
38
+
<goal>shade</goal>
39
+
</goals>
40
+
<configuration>
41
+
<createDependencyReducedPom>false</createDependencyReducedPom>
42
+
</configuration>
43
+
</execution>
44
+
</executions>
45
+
</plugin>
46
+
</plugins>
47
+
<resources>
48
+
<resource>
49
+
<directory>src/main/resources</directory>
50
+
<filtering>true</filtering>
51
+
</resource>
52
+
</resources>
53
+
</build>
54
+
55
+
<repositories>
56
+
<repository>
57
+
<id>papermc-repo</id>
58
+
<url>https://repo.papermc.io/repository/maven-public/</url>
59
+
</repository>
60
+
<repository>
61
+
<id>sonatype</id>
62
+
<url>https://oss.sonatype.org/content/groups/public/</url>
63
+
</repository>
64
+
</repositories>
65
+
66
+
<dependencies>
67
+
<dependency>
68
+
<groupId>io.papermc.paper</groupId>
69
+
<artifactId>paper-api</artifactId>
70
+
<version>1.20.1-R0.1-SNAPSHOT</version>
71
+
<scope>provided</scope>
72
+
</dependency>
73
+
<dependency>
74
+
<groupId>com.squareup.okhttp3</groupId>
75
+
<artifactId>okhttp</artifactId>
76
+
<version>4.10.0</version>
77
+
</dependency>
78
+
<dependency>
79
+
<groupId>com.fasterxml.jackson.core</groupId>
80
+
<artifactId>jackson-core</artifactId>
81
+
<version>2.14.2</version>
82
+
</dependency>
83
+
<dependency>
84
+
<groupId>com.fasterxml.jackson.core</groupId>
85
+
<artifactId>jackson-databind</artifactId>
86
+
<version>2.15.1</version>
87
+
</dependency>
88
+
</dependencies>
89
+
</project>
+66
src/main/java/dev/keii/keiichunks/Config.java
+66
src/main/java/dev/keii/keiichunks/Config.java
···
1
+
package dev.keii.keiichunks;
2
+
3
+
import net.kyori.adventure.text.Component;
4
+
import net.kyori.adventure.text.format.NamedTextColor;
5
+
import net.kyori.adventure.text.format.TextDecoration;
6
+
import org.bukkit.Bukkit;
7
+
import org.bukkit.configuration.file.FileConfiguration;
8
+
9
+
public class Config {
10
+
public boolean Claims;
11
+
public boolean Invite;
12
+
13
+
public String ApiUrl;
14
+
15
+
public String DbUrl;
16
+
public String DbName;
17
+
public String DbUser;
18
+
public String DbPassword;
19
+
20
+
21
+
public void fileConfigToConfig(FileConfiguration config)
22
+
{
23
+
DbUrl = config.getString("dbUrl");
24
+
DbName = config.getString("dbName");
25
+
DbUser = config.getString("dbUser");
26
+
DbPassword = config.getString("dbPassword");
27
+
}
28
+
29
+
public void loadConfig() {
30
+
FileConfiguration config = KeiiChunks.getInstance().getConfig();
31
+
32
+
if(config.getString("dbUrl") == null)
33
+
config.set("dbUrl", "jdbc:mysql://localhost:3306/");
34
+
if(config.getString("dbName") == null)
35
+
config.set("dbName", "");
36
+
if(config.getString("dbUser") == null)
37
+
config.set("dbUser", "");
38
+
if(config.getString("dbPassword") == null)
39
+
config.set("dbPassword", "");
40
+
41
+
config.options().copyDefaults(true);
42
+
KeiiChunks.getInstance().saveConfig();
43
+
44
+
config = KeiiChunks.getInstance().getConfig();
45
+
46
+
if(config.getString("dbName").isEmpty())
47
+
{
48
+
Bukkit.broadcast(Component.text("Database is not set in the config. Core functionality of the plugin ").color(NamedTextColor.RED)
49
+
.append(
50
+
Component.text("will not")
51
+
.decorate(TextDecoration.ITALIC)
52
+
.decorate(TextDecoration.BOLD))
53
+
.color(NamedTextColor.RED)
54
+
.append(
55
+
Component.text(" work")
56
+
.color(NamedTextColor.RED)));
57
+
}
58
+
59
+
fileConfigToConfig(config);
60
+
61
+
DatabaseConnector.DB_URL = DbUrl;
62
+
DatabaseConnector.DB_NAME = DbName;
63
+
DatabaseConnector.DB_USER = DbUser;
64
+
DatabaseConnector.DB_PASSWORD = DbPassword;
65
+
}
66
+
}
+164
src/main/java/dev/keii/keiichunks/DatabaseConnector.java
+164
src/main/java/dev/keii/keiichunks/DatabaseConnector.java
···
1
+
package dev.keii.keiichunks;
2
+
3
+
import net.kyori.adventure.text.Component;
4
+
import net.kyori.adventure.text.format.NamedTextColor;
5
+
import org.bukkit.Bukkit;
6
+
7
+
import java.sql.Connection;
8
+
import java.sql.DriverManager;
9
+
import java.sql.SQLException;
10
+
import java.sql.Statement;
11
+
12
+
public class DatabaseConnector {
13
+
public static String createDatabaseSqlSqlLite = "PRAGMA foreign_keys = ON;\n" +
14
+
"CREATE TABLE IF NOT EXISTS `claim` (\n" +
15
+
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
16
+
" `user_id` INTEGER NOT NULL,\n" +
17
+
" `chunk_x` INTEGER NOT NULL,\n" +
18
+
" `chunk_z` INTEGER NOT NULL,\n" +
19
+
" `created_at` TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
20
+
" `updated_at` TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
21
+
" `allow_explosions` INTEGER NOT NULL DEFAULT 0\n" +
22
+
");\n" +
23
+
"CREATE TABLE IF NOT EXISTS `claim_permission` (\n" +
24
+
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
25
+
" `user_id` INTEGER,\n" +
26
+
" `claim_id` INTEGER NOT NULL,\n" +
27
+
" `block_break` INTEGER NOT NULL DEFAULT 0,\n" +
28
+
" `block_place` INTEGER NOT NULL DEFAULT 0,\n" +
29
+
" `bucket_empty` INTEGER NOT NULL DEFAULT 0,\n" +
30
+
" `bucket_fill` INTEGER NOT NULL DEFAULT 0,\n" +
31
+
" `interact` INTEGER NOT NULL DEFAULT 0,\n" +
32
+
" `created_at` TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
33
+
" `updated_at` TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
34
+
" FOREIGN KEY (`user_id`) REFERENCES `user`(`id`),\n" +
35
+
" FOREIGN KEY (`claim_id`) REFERENCES `claim`(`id`)\n" +
36
+
");\n" +
37
+
"CREATE TABLE IF NOT EXISTS `user` (\n" +
38
+
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
39
+
" `uuid` TEXT NOT NULL,\n" +
40
+
" `timestamp` TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
41
+
" `claim_power` INTEGER NOT NULL DEFAULT 10\n" +
42
+
");\n" +
43
+
"COMMIT;";
44
+
45
+
public static String createDatabaseSqlMySQL =
46
+
"START TRANSACTION;\n" +
47
+
"CREATE TABLE IF NOT EXISTS `claim` (\n" +
48
+
" `id` bigint(20) UNSIGNED NOT NULL,\n" +
49
+
" `user_id` bigint(20) UNSIGNED NOT NULL,\n" +
50
+
" `chunk_x` smallint(6) NOT NULL,\n" +
51
+
" `chunk_z` smallint(6) NOT NULL,\n" +
52
+
" `created_at` timestamp NOT NULL DEFAULT current_timestamp(),\n" +
53
+
" `updated_at` timestamp NOT NULL DEFAULT current_timestamp(),\n" +
54
+
" `allow_explosions` tinyint(1) NOT NULL DEFAULT 0\n" +
55
+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n" +
56
+
"CREATE TABLE IF NOT EXISTS `claim_permission` (\n" +
57
+
" `id` bigint(20) UNSIGNED NOT NULL,\n" +
58
+
" `user_id` bigint(20) UNSIGNED DEFAULT NULL,\n" +
59
+
" `claim_id` bigint(20) UNSIGNED NOT NULL,\n" +
60
+
" `block_break` tinyint(1) NOT NULL DEFAULT 0,\n" +
61
+
" `block_place` tinyint(1) NOT NULL DEFAULT 0,\n" +
62
+
" `bucket_empty` tinyint(1) NOT NULL DEFAULT 0,\n" +
63
+
" `bucket_fill` tinyint(1) NOT NULL DEFAULT 0,\n" +
64
+
" `interact` tinyint(1) NOT NULL DEFAULT 0,\n" +
65
+
" `created_at` timestamp NOT NULL DEFAULT current_timestamp(),\n" +
66
+
" `updated_at` timestamp NOT NULL DEFAULT current_timestamp()\n" +
67
+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n" +
68
+
"CREATE TABLE IF NOT EXISTS `user` (\n" +
69
+
" `id` bigint(20) UNSIGNED NOT NULL,\n" +
70
+
" `nickname` TEXT NOT NULL,\n" +
71
+
" `uuid` varchar(36) NOT NULL,\n" +
72
+
" `timestamp` timestamp NOT NULL DEFAULT current_timestamp(),\n" +
73
+
" `claim_power` int(10) UNSIGNED NOT NULL DEFAULT 10\n" +
74
+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n" +
75
+
76
+
"ALTER TABLE `claim`\n" +
77
+
" ADD PRIMARY KEY (`id`),\n" +
78
+
" ADD KEY `claim_user_id_foreign` (`user_id`);\n" +
79
+
"ALTER TABLE `claim_permission`\n" +
80
+
" ADD PRIMARY KEY (`id`),\n" +
81
+
" ADD KEY `claim_permission_user_id_foreign` (`user_id`),\n" +
82
+
" ADD KEY `claim_permission_claim_id_foreign` (`claim_id`);\n" +
83
+
"ALTER TABLE `user`\n" +
84
+
" ADD PRIMARY KEY (`id`);\n" +
85
+
"ALTER TABLE `claim`\n" +
86
+
" MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=70;\n" +
87
+
"ALTER TABLE `claim_permission`\n" +
88
+
" MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=51;\n" +
89
+
"ALTER TABLE `user`\n" +
90
+
" MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;\n" +
91
+
"ALTER TABLE `claim`\n" +
92
+
" ADD CONSTRAINT `claim_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);\n" +
93
+
"ALTER TABLE `claim_permission`\n" +
94
+
" ADD CONSTRAINT `claim_permission_claim_id_foreign` FOREIGN KEY (`claim_id`) REFERENCES `claim` (`id`),\n" +
95
+
" ADD CONSTRAINT `claim_permission_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);\n" +
96
+
"COMMIT;";
97
+
98
+
// public static boolean InitializeDatabase()
99
+
// {
100
+
// Connection connection = getConnection();
101
+
//
102
+
// try {
103
+
// Statement statement = connection.createStatement();
104
+
//
105
+
// System.out.println("Database initialization succeeded!");
106
+
//
107
+
// statement.execute(createDatabaseSqlMySQL);
108
+
//
109
+
// return true;
110
+
// } catch (SQLException e) {
111
+
// Bukkit.getServer().sendMessage(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
112
+
// return false;
113
+
// }
114
+
// };
115
+
116
+
// public static Connection getConnection() {
117
+
// try {
118
+
// Class.forName("org.sqlite.JDBC");
119
+
//
120
+
// final String url = "jdbc:sqlite:./plugins/KeiiChunks/database.db";
121
+
//
122
+
// return DriverManager.getConnection(url);
123
+
// } catch(Exception e)
124
+
// {
125
+
// Bukkit.getServer().sendMessage(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
126
+
//
127
+
// return null;
128
+
// }
129
+
// }
130
+
131
+
static String DB_URL = null;
132
+
static String DB_NAME = null;
133
+
static String DB_USER = null;
134
+
static String DB_PASSWORD = null;
135
+
136
+
public static boolean InitializeDatabase()
137
+
{
138
+
Connection connection = getConnection();
139
+
140
+
try {
141
+
Statement statement = connection.createStatement();
142
+
143
+
Bukkit.getServer().sendMessage(Component.text("Database initialization succeeded").color(NamedTextColor.GREEN));
144
+
145
+
statement.execute(createDatabaseSqlMySQL);
146
+
147
+
return true;
148
+
} catch (SQLException e) {
149
+
Bukkit.getServer().sendMessage(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
150
+
return false;
151
+
}
152
+
};
153
+
154
+
public static Connection getConnection() {
155
+
try {
156
+
final String url = DB_URL + DB_NAME;
157
+
158
+
return DriverManager.getConnection(url, DB_USER, DB_PASSWORD);
159
+
} catch (SQLException e) {
160
+
Bukkit.getServer().sendMessage(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
161
+
return null;
162
+
}
163
+
}
164
+
}
+226
src/main/java/dev/keii/keiichunks/KeiiChunks.java
+226
src/main/java/dev/keii/keiichunks/KeiiChunks.java
···
1
+
package dev.keii.keiichunks;
2
+
3
+
import dev.keii.keiichunks.commands.CommandMap;
4
+
import dev.keii.keiichunks.events.*;
5
+
import dev.keii.keiichunks.saveload.Claim;
6
+
import dev.keii.keiichunks.saveload.ClaimPermission;
7
+
import dev.keii.keiichunks.saveload.User;
8
+
import net.kyori.adventure.text.Component;
9
+
import net.kyori.adventure.text.format.NamedTextColor;
10
+
import org.bukkit.Bukkit;
11
+
import org.bukkit.plugin.PluginManager;
12
+
import org.bukkit.plugin.java.JavaPlugin;
13
+
import org.joml.Vector2i;
14
+
15
+
import java.io.FileWriter;
16
+
import java.io.IOException;
17
+
import java.sql.Connection;
18
+
import java.sql.ResultSet;
19
+
import java.sql.SQLException;
20
+
import java.sql.Statement;
21
+
import java.util.ArrayList;
22
+
import java.util.HashMap;
23
+
import java.util.List;
24
+
import java.io.File;
25
+
import java.util.Map;
26
+
27
+
public final class KeiiChunks extends JavaPlugin {
28
+
29
+
private static KeiiChunks instance;
30
+
public static List<RuntimeError> RuntimeErrors = new ArrayList<>();
31
+
32
+
public static Map<Vector2i, Claim> claims = new HashMap<>();
33
+
public static Map<String, User> users = new HashMap<>();
34
+
public static Map<Long, ClaimPermission> claimPermissions = new HashMap<>();
35
+
36
+
public static Config config;
37
+
38
+
@Override
39
+
public void onEnable() {
40
+
instance = this;
41
+
42
+
config = new Config();
43
+
config.loadConfig();
44
+
45
+
File pluginDir = new File("./plugins/KeiiChunks");
46
+
if (!pluginDir.exists()){
47
+
if(!pluginDir.mkdirs()) {
48
+
Bukkit.getServer().sendMessage(Component.text("Creating plugin folders failed").color(NamedTextColor.RED));
49
+
}
50
+
}
51
+
File sqlFile = new File("./plugins/KeiiChunks/database.sql");
52
+
try {
53
+
if (!sqlFile.createNewFile()){
54
+
Bukkit.getServer().sendMessage(Component.text("Creating sql file failed").color(NamedTextColor.RED));
55
+
} else {
56
+
FileWriter myWriter = new FileWriter("./plugins/KeiiChunks/database.sql");
57
+
myWriter.write(DatabaseConnector.createDatabaseSqlMySQL);
58
+
myWriter.close();
59
+
Bukkit.getServer().sendMessage(Component.text("Created sql file").color(NamedTextColor.YELLOW));
60
+
}
61
+
} catch (IOException e) {
62
+
throw new RuntimeException(e);
63
+
}
64
+
DatabaseConnector.InitializeDatabase();
65
+
66
+
registerEvents();
67
+
registerCommands();
68
+
}
69
+
70
+
public void registerEvents() {
71
+
//This first line is optional, makes it faster with lots of classes
72
+
PluginManager pm = Bukkit.getServer().getPluginManager();
73
+
pm.registerEvents(new PlayerJoin(), this);
74
+
pm.registerEvents(new PlayerQuit(), this);
75
+
pm.registerEvents(new BlockBreak(), this);
76
+
pm.registerEvents(new BlockPlace(), this);
77
+
pm.registerEvents(new BucketEmpty(), this);
78
+
pm.registerEvents(new BucketFill(), this);
79
+
pm.registerEvents(new PlayerInteract(), this);
80
+
pm.registerEvents(new InventoryClick(), this);
81
+
pm.registerEvents(new PlayerMove(), this);
82
+
pm.registerEvents(new EntityExplode(), this);
83
+
pm.registerEvents(new PlayerChat(), this);
84
+
pm.registerEvents(new PlayerResourcePack(), this);
85
+
}
86
+
87
+
public void registerCommands() {
88
+
this.getCommand("map").setExecutor(new CommandMap());
89
+
}
90
+
91
+
@Override
92
+
public void onDisable() {
93
+
// Plugin shutdown logic
94
+
}
95
+
96
+
public static KeiiChunks getInstance()
97
+
{
98
+
return instance;
99
+
}
100
+
101
+
public static void SaveData()
102
+
{
103
+
Connection connection = DatabaseConnector.getConnection();
104
+
try {
105
+
connection.setAutoCommit(false);
106
+
Statement statement = connection.createStatement();
107
+
108
+
Bukkit.getServer().broadcast(Component.text("Server is saving! Expect some lag.").color(NamedTextColor.YELLOW));
109
+
110
+
statement.execute("DELETE FROM user;");
111
+
Bukkit.getServer().sendMessage(Component.text("Saving: Deleted users in database").color(NamedTextColor.YELLOW));
112
+
113
+
for(User user : users.values())
114
+
{
115
+
statement.execute(String.format("INSERT INTO user(id, uuid, timestamp, claim_power) VALUES(%d, %s, %s, %d)", user.id, user.uuid, user.timestamp, user.claimPower));
116
+
}
117
+
Bukkit.getServer().sendMessage(Component.text("Saving: Saved new users into database").color(NamedTextColor.YELLOW));
118
+
119
+
statement.execute("DELETE FROM claim;");
120
+
Bukkit.getServer().sendMessage(Component.text("Saving: Deleted claims in database").color(NamedTextColor.YELLOW));
121
+
122
+
for(Claim claim : claims.values())
123
+
{
124
+
statement.execute(String.format("INSERT INTO claim(id, user_id, chunk_x, chunk_z, created_at, updated_at, allow_explosions) VALUES(%d, %d, %d, %d, %s, %s, %d)", claim.id, claim.userId, claim.chunkX, claim.chunkZ, claim.createdAt, claim.updatedAt, claim.allowExplosions ? 1 : 0));
125
+
}
126
+
Bukkit.getServer().sendMessage(Component.text("Saving: Saved new claims into database").color(NamedTextColor.YELLOW));
127
+
128
+
statement.execute("DELETE FROM claim_permission;");
129
+
Bukkit.getServer().sendMessage(Component.text("Saving: Delete claim permissions in database").color(NamedTextColor.YELLOW));
130
+
131
+
for(ClaimPermission claimPermission : claimPermissions.values())
132
+
{
133
+
statement.execute(String.format("INSERT INTO claim_permission(id, user_id, claim_id, block_break, block_place, bucket_empty, bucket_fill, interact, created_at, updated_at) VALUES(%d, %d, %d, %d, %d, %d, %d, %d, %s, %s)", claimPermission.id, claimPermission.userId, claimPermission.claimId, claimPermission.blockBreak ? 1 : 0, claimPermission.blockPlace ? 1 : 0, claimPermission.bucketEmpty ? 1 : 0, claimPermission.bucketFill ? 1 : 0, claimPermission.interact ? 1 : 0, claimPermission.createdAt, claimPermission.updatedAt));
134
+
}
135
+
Bukkit.getServer().sendMessage(Component.text("Saving: Saved new claim permissions into database").color(NamedTextColor.YELLOW));
136
+
137
+
Bukkit.getServer().broadcast(Component.text("Save complete!").color(NamedTextColor.GREEN));
138
+
139
+
connection.commit();
140
+
statement.close();
141
+
connection.close();
142
+
return;
143
+
} catch (SQLException e) {
144
+
Bukkit.getServer().broadcast(Component.text("Save failed!").color(NamedTextColor.RED));
145
+
try {
146
+
connection.rollback();
147
+
} catch (SQLException ex) {
148
+
throw new RuntimeException(ex);
149
+
}
150
+
Bukkit.getServer().sendMessage(Component.text(e.getMessage()).color(NamedTextColor.RED));
151
+
e.printStackTrace();
152
+
}
153
+
}
154
+
155
+
public static void LoadData()
156
+
{
157
+
Connection connection = DatabaseConnector.getConnection();
158
+
try {
159
+
Bukkit.getServer().broadcast(Component.text("Server is saving! Expect some lag.").color(NamedTextColor.YELLOW));
160
+
161
+
Statement statement = connection.createStatement();
162
+
163
+
ResultSet users = statement.executeQuery("SELECT * FROM user;");
164
+
165
+
while(users.next())
166
+
{
167
+
long id = users.getLong("id");
168
+
String uuid = users.getString("uuid");
169
+
String timestamp = users.getString("timestamp");
170
+
int claimPower = users.getInt("claimPower");
171
+
172
+
KeiiChunks.users.put(uuid, new User(id, uuid, timestamp, claimPower));
173
+
}
174
+
175
+
users.close();
176
+
Bukkit.getServer().sendMessage(Component.text("Loading: Loaded users").color(NamedTextColor.YELLOW));
177
+
178
+
ResultSet claims = statement.executeQuery("SELECT * FROM claim;");
179
+
180
+
while(claims.next())
181
+
{
182
+
long id = claims.getLong("id");
183
+
long userId = claims.getLong("user_id");
184
+
long chunkX = claims.getLong("chunk_x");
185
+
long chunkZ = claims.getLong("chunk_z");
186
+
String createdAt = claims.getString("created_at");
187
+
String updatedAt = claims.getString("updated_at");
188
+
boolean allowExplosions = claims.getBoolean("allow_explosions");
189
+
190
+
KeiiChunks.claims.put(new Vector2i((int) chunkX, (int) chunkZ), new Claim(id, userId, chunkX, chunkZ, createdAt, updatedAt, allowExplosions));
191
+
}
192
+
193
+
claims.close();
194
+
Bukkit.getServer().sendMessage(Component.text("Loading: Loaded claims").color(NamedTextColor.YELLOW));
195
+
196
+
ResultSet claimPermission = statement.executeQuery("SELECT * FROM claim_permission;");
197
+
198
+
while(claimPermission.next())
199
+
{
200
+
long id = claims.getLong("id");
201
+
long userId = claims.getLong("user_id");
202
+
long claimId = claims.getLong("chunk_x");
203
+
boolean blockBreak = claims.getBoolean("block_break");
204
+
boolean blockPlace = claims.getBoolean("block_place");
205
+
boolean bucketEmpty = claims.getBoolean("bucket_empty");
206
+
boolean bucketFill = claims.getBoolean("bucket_fill");
207
+
boolean interact = claims.getBoolean("interact");
208
+
String createdAt = claims.getString("created_at");
209
+
String updatedAt = claims.getString("updated_at");
210
+
211
+
KeiiChunks.claimPermissions.put(claimId, new ClaimPermission(id, userId, claimId, blockBreak, blockPlace, bucketEmpty, bucketFill, interact, createdAt, updatedAt));
212
+
}
213
+
214
+
claimPermission.close();
215
+
Bukkit.getServer().sendMessage(Component.text("Loading: Loaded claim permissions").color(NamedTextColor.YELLOW));
216
+
217
+
Bukkit.getServer().broadcast(Component.text("Load complete!").color(NamedTextColor.GREEN));
218
+
statement.close();
219
+
connection.close();
220
+
} catch (SQLException e) {
221
+
Bukkit.getServer().broadcast(Component.text("Save failed!").color(NamedTextColor.RED));
222
+
Bukkit.getServer().broadcast(Component.text(e.getMessage()).color(NamedTextColor.RED));
223
+
e.printStackTrace();
224
+
}
225
+
}
226
+
}
+863
src/main/java/dev/keii/keiichunks/PlayerChunk.java
+863
src/main/java/dev/keii/keiichunks/PlayerChunk.java
···
1
+
package dev.keii.keiichunks;
2
+
3
+
import dev.keii.keiichunks.api.ApiChunk;
4
+
import dev.keii.keiichunks.error.Failure;
5
+
import dev.keii.keiichunks.error.Result;
6
+
import dev.keii.keiichunks.error.Success;
7
+
import net.kyori.adventure.text.Component;
8
+
import net.kyori.adventure.text.format.NamedTextColor;
9
+
import org.bukkit.Bukkit;
10
+
import org.bukkit.Chunk;
11
+
import org.bukkit.Location;
12
+
import org.bukkit.Material;
13
+
import org.bukkit.block.data.BlockData;
14
+
import org.bukkit.entity.Player;
15
+
16
+
import javax.annotation.Nullable;
17
+
import java.sql.*;
18
+
import java.util.HashMap;
19
+
import java.util.Map;
20
+
21
+
public class PlayerChunk {
22
+
static Map<Long, ApiChunk> claimCache = new HashMap<>();
23
+
24
+
public static boolean getPlayerOwnsChunk(Player player, Chunk chunk) {
25
+
try {
26
+
Connection connection = DatabaseConnector.getConnection();
27
+
Statement statement = connection.createStatement();
28
+
29
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
30
+
ResultSet userResultSet = statement.executeQuery(userQuery);
31
+
32
+
if (!userResultSet.next()) {
33
+
userResultSet.close();
34
+
statement.close();
35
+
connection.close();
36
+
return false;
37
+
}
38
+
39
+
int userId = userResultSet.getInt("id");
40
+
41
+
String query = "SELECT user_id FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + +chunk.getZ();
42
+
ResultSet resultSet = statement.executeQuery(query);
43
+
44
+
if (!resultSet.next()) {
45
+
userResultSet.close();
46
+
resultSet.close();
47
+
statement.close();
48
+
connection.close();
49
+
return false;
50
+
}
51
+
52
+
// Bukkit.broadcastMessage("DB: " + resultSet.getInt("user_id") + " Local: " + userId);
53
+
if (resultSet.getInt("user_id") != userId) {
54
+
userResultSet.close();
55
+
resultSet.close();
56
+
statement.close();
57
+
connection.close();
58
+
return false;
59
+
}
60
+
// Close resources
61
+
resultSet.close();
62
+
statement.close();
63
+
connection.close();
64
+
return true;
65
+
} catch (SQLException e) {
66
+
Bukkit.getServer().broadcast(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
67
+
}
68
+
return false;
69
+
}
70
+
71
+
public static boolean getPlayerCanModifyChunk(Player player, Chunk chunk) {
72
+
try {
73
+
Connection connection = DatabaseConnector.getConnection();
74
+
Statement statement = connection.createStatement();
75
+
76
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
77
+
ResultSet userResultSet = statement.executeQuery(userQuery);
78
+
79
+
if (!userResultSet.next()) {
80
+
userResultSet.close();
81
+
statement.close();
82
+
connection.close();
83
+
return true;
84
+
}
85
+
86
+
int userId = userResultSet.getInt("id");
87
+
88
+
String query = "SELECT user_id FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + +chunk.getZ();
89
+
ResultSet resultSet = statement.executeQuery(query);
90
+
91
+
if (!resultSet.next()) {
92
+
userResultSet.close();
93
+
resultSet.close();
94
+
statement.close();
95
+
connection.close();
96
+
return true;
97
+
}
98
+
99
+
// Bukkit.broadcastMessage("DB: " + resultSet.getInt("user_id") + " Local: " + userId);
100
+
if (resultSet.getLong("user_id") != userId) {
101
+
userResultSet.close();
102
+
resultSet.close();
103
+
statement.close();
104
+
connection.close();
105
+
return false;
106
+
}
107
+
// Close resources
108
+
userResultSet.close();
109
+
resultSet.close();
110
+
statement.close();
111
+
connection.close();
112
+
return true;
113
+
} catch (SQLException e) {
114
+
e.printStackTrace();
115
+
}
116
+
return false;
117
+
}
118
+
119
+
@Nullable
120
+
public static String getChunkOwner(Chunk chunk) {
121
+
try {
122
+
Connection connection = DatabaseConnector.getConnection();
123
+
Statement statement = connection.createStatement();
124
+
125
+
String query = "SELECT user_id, nickname FROM claim LEFT JOIN user ON user_id = user.id WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + +chunk.getZ();
126
+
ResultSet resultSet = statement.executeQuery(query);
127
+
128
+
if (!resultSet.next()) {
129
+
resultSet.close();
130
+
statement.close();
131
+
connection.close();
132
+
return null;
133
+
}
134
+
135
+
String nickname = resultSet.getString("nickname");
136
+
137
+
// Close resources
138
+
resultSet.close();
139
+
statement.close();
140
+
connection.close();
141
+
return nickname;
142
+
} catch (SQLException e) {
143
+
e.printStackTrace();
144
+
}
145
+
return null;
146
+
}
147
+
148
+
@Nullable
149
+
public static String getChunkOwnerUUID(Chunk chunk) {
150
+
try {
151
+
Connection connection = DatabaseConnector.getConnection();
152
+
Statement statement = connection.createStatement();
153
+
154
+
String query = "SELECT user_id, nickname, uuid FROM claim LEFT JOIN user ON user_id = user.id WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + +chunk.getZ();
155
+
ResultSet resultSet = statement.executeQuery(query);
156
+
157
+
if (!resultSet.next()) {
158
+
resultSet.close();
159
+
statement.close();
160
+
connection.close();
161
+
return null;
162
+
}
163
+
164
+
String uuid = resultSet.getString("uuid");
165
+
166
+
// Close resources
167
+
resultSet.close();
168
+
statement.close();
169
+
connection.close();
170
+
return uuid;
171
+
} catch (SQLException e) {
172
+
e.printStackTrace();
173
+
}
174
+
return null;
175
+
}
176
+
177
+
public static boolean claimChunk(Player player, Chunk chunk) {
178
+
if (getChunkOwner(chunk) != null) {
179
+
return false;
180
+
}
181
+
182
+
Connection connection = null;
183
+
Statement statement = null;
184
+
ResultSet userResultSet = null;
185
+
ResultSet claimPowerResultSet = null;
186
+
187
+
try {
188
+
connection = DatabaseConnector.getConnection();
189
+
statement = connection.createStatement();
190
+
191
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
192
+
userResultSet = statement.executeQuery(userQuery);
193
+
194
+
if (!userResultSet.next()) {
195
+
Bukkit.getServer().broadcastMessage("NO USER");
196
+
197
+
return false;
198
+
}
199
+
200
+
int userId = userResultSet.getInt("id");
201
+
202
+
userResultSet.close();
203
+
204
+
claimPowerResultSet = statement.executeQuery("SELECT claim_power FROM user WHERE id = " + userId);
205
+
claimPowerResultSet.next();
206
+
207
+
Integer claimPower = claimPowerResultSet.getInt("claim_power");
208
+
209
+
claimPowerResultSet.close();
210
+
211
+
claimPowerResultSet = statement.executeQuery("SELECT COUNT(id) as count FROM `claim` WHERE user_id = " + userId);
212
+
claimPowerResultSet.next();
213
+
214
+
if (claimPowerResultSet.getInt("count") >= claimPower) {
215
+
player.sendMessage(Component.text("Not enough power to claim chunk").color(NamedTextColor.RED));
216
+
return false;
217
+
}
218
+
219
+
claimPowerResultSet.close();
220
+
221
+
String query = "INSERT INTO claim(user_id, chunk_x, chunk_z) VALUES(" + userId + ", " + chunk.getX() + ", " + chunk.getZ() + ")";
222
+
statement.execute(query);
223
+
224
+
showChunkPerimeter(player, chunk);
225
+
var result = addChunkPermissionsForUser(player, null, chunk);
226
+
227
+
if (result instanceof Failure) {
228
+
player.sendMessage(result.getMessage());
229
+
}
230
+
231
+
return true;
232
+
} catch (SQLException e) {
233
+
Bukkit.getServer().broadcastMessage("DB ERROR" + e.getMessage());
234
+
e.printStackTrace();
235
+
} finally {
236
+
try {
237
+
if (claimPowerResultSet != null) {
238
+
claimPowerResultSet.close();
239
+
}
240
+
if (userResultSet != null) {
241
+
userResultSet.close();
242
+
}
243
+
if (statement != null) {
244
+
statement.close();
245
+
}
246
+
if (connection != null) {
247
+
connection.close();
248
+
}
249
+
} catch (SQLException e) {
250
+
e.printStackTrace();
251
+
}
252
+
}
253
+
254
+
return false;
255
+
}
256
+
257
+
public static boolean unClaimChunk(Player player, Chunk chunk) {
258
+
try {
259
+
Connection connection = DatabaseConnector.getConnection();
260
+
Statement statement = connection.createStatement();
261
+
262
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
263
+
ResultSet userResultSet = statement.executeQuery(userQuery);
264
+
265
+
if (!userResultSet.next()) {
266
+
userResultSet.close();
267
+
statement.close();
268
+
connection.close();
269
+
return false;
270
+
}
271
+
272
+
int userId = userResultSet.getInt("id");
273
+
274
+
userResultSet.close();
275
+
276
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
277
+
userResultSet = statement.executeQuery(claimQuery);
278
+
279
+
if (!userResultSet.next()) {
280
+
userResultSet.close();
281
+
statement.close();
282
+
connection.close();
283
+
return false;
284
+
}
285
+
286
+
Long claimId = userResultSet.getLong("id");
287
+
288
+
if (userResultSet.getInt("user_id") != userId) {
289
+
userResultSet.close();
290
+
statement.close();
291
+
connection.close();
292
+
return false;
293
+
}
294
+
295
+
statement.execute("DELETE FROM claim_permission WHERE claim_id = " + claimId);
296
+
String query = "DELETE FROM claim WHERE user_id = " + userId + " AND chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
297
+
statement.execute(query);
298
+
299
+
userResultSet.close();
300
+
statement.close();
301
+
connection.close();
302
+
return true;
303
+
} catch (SQLException e) {
304
+
player.sendMessage(Component.text(e.getMessage()).color(NamedTextColor.RED));
305
+
e.printStackTrace();
306
+
}
307
+
308
+
return false;
309
+
}
310
+
311
+
private static void showChunkPerimeter(Player player, Chunk chunk) {
312
+
int worldX = chunk.getX() * 16;
313
+
int worldZ = chunk.getZ() * 16;
314
+
315
+
HashMap<Location, BlockData> blockChanges = new HashMap<>();
316
+
317
+
for (var i = 0; i < 16; i++) {
318
+
if(i > 1 || i < 16)
319
+
{
320
+
continue;
321
+
}
322
+
323
+
int x = worldX + i;
324
+
int z = worldZ;
325
+
int y = chunk.getWorld().getHighestBlockYAt(x, z);
326
+
327
+
BlockData bd = Material.GOLD_BLOCK.createBlockData();
328
+
329
+
blockChanges.put(new Location(chunk.getWorld(), x, y, z), bd);
330
+
}
331
+
332
+
for (var i = 0; i < 15; i++) {
333
+
if(i > 1 || i < 16)
334
+
{
335
+
continue;
336
+
}
337
+
338
+
int x = worldX + i;
339
+
int z = worldZ + 15;
340
+
int y = chunk.getWorld().getHighestBlockYAt(x, z);
341
+
342
+
BlockData bd = Material.GOLD_BLOCK.createBlockData();
343
+
344
+
blockChanges.put(new Location(chunk.getWorld(), x, y, z), bd);
345
+
}
346
+
347
+
for (var i = 0; i < 15; i++) {
348
+
if(i > 1 || i < 16)
349
+
{
350
+
continue;
351
+
}
352
+
353
+
int x = worldX;
354
+
int z = worldZ + i;
355
+
int y = chunk.getWorld().getHighestBlockYAt(x, z);
356
+
357
+
BlockData bd = Material.GOLD_BLOCK.createBlockData();
358
+
359
+
blockChanges.put(new Location(chunk.getWorld(), x, y, z), bd);
360
+
}
361
+
362
+
for (var i = 0; i < 16; i++) {
363
+
if(i > 1 || i < 16)
364
+
{
365
+
continue;
366
+
}
367
+
368
+
int x = worldX + 15;
369
+
int z = worldZ + i;
370
+
int y = chunk.getWorld().getHighestBlockYAt(x, z);
371
+
372
+
BlockData bd = Material.GOLD_BLOCK.createBlockData();
373
+
374
+
blockChanges.put(new Location(chunk.getWorld(), x, y, z), bd);
375
+
}
376
+
377
+
player.sendMultiBlockChange(blockChanges);
378
+
}
379
+
380
+
public static boolean toggleExplosionPolicy(Player player, Chunk chunk) {
381
+
try {
382
+
Connection connection = DatabaseConnector.getConnection();
383
+
Statement statement = connection.createStatement();
384
+
385
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId().toString() + "\"";
386
+
ResultSet userResultSet = statement.executeQuery(userQuery);
387
+
388
+
if (!userResultSet.next()) {
389
+
userResultSet.close();
390
+
statement.close();
391
+
connection.close();
392
+
return false;
393
+
}
394
+
395
+
int userId = userResultSet.getInt("id");
396
+
397
+
userResultSet.close();
398
+
399
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
400
+
userResultSet = statement.executeQuery(claimQuery);
401
+
402
+
if (!userResultSet.next()) {
403
+
userResultSet.close();
404
+
statement.close();
405
+
connection.close();
406
+
return false;
407
+
}
408
+
409
+
long id = userResultSet.getLong("id");
410
+
long user_id = userResultSet.getLong("user_id");
411
+
int chunk_x = userResultSet.getInt("chunk_x");
412
+
int chunk_z = userResultSet.getInt("chunk_z");
413
+
Timestamp created_at = userResultSet.getTimestamp("created_at");
414
+
Timestamp updated_at = userResultSet.getTimestamp("updated_at");
415
+
416
+
if (userResultSet.getInt("user_id") != userId) {
417
+
userResultSet.close();
418
+
statement.close();
419
+
connection.close();
420
+
return false;
421
+
}
422
+
423
+
int newExp = (userResultSet.getBoolean("allow_explosions") ? 0 : 1);
424
+
425
+
String query = "UPDATE claim SET allow_explosions = " + newExp + ", updated_at = current_timestamp() WHERE user_id = " + userId + " AND chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
426
+
statement.execute(query);
427
+
428
+
ApiChunk c = claimCache.get(chunk.getChunkKey());
429
+
if (c != null) {
430
+
c.setAllowExplosions(newExp == 1);
431
+
claimCache.remove(chunk.getChunkKey());
432
+
claimCache.put(chunk.getChunkKey(), c);
433
+
} else {
434
+
claimCache.put(chunk.getChunkKey(), new ApiChunk(
435
+
id,
436
+
user_id,
437
+
chunk_x,
438
+
chunk_z,
439
+
created_at,
440
+
updated_at,
441
+
newExp == 1
442
+
));
443
+
}
444
+
445
+
userResultSet.close();
446
+
statement.close();
447
+
connection.close();
448
+
return true;
449
+
} catch (SQLException e) {
450
+
player.sendMessage(Component.text(e.getMessage()).color(NamedTextColor.RED));
451
+
e.printStackTrace();
452
+
}
453
+
454
+
return false;
455
+
}
456
+
457
+
public static boolean getExplosionPolicy(Chunk chunk) {
458
+
ApiChunk cache = claimCache.get(chunk.getChunkKey());
459
+
if (cache != null) {
460
+
return cache.isAllowExplosions();
461
+
}
462
+
463
+
try {
464
+
Connection connection = DatabaseConnector.getConnection();
465
+
Statement statement = connection.createStatement();
466
+
467
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
468
+
ResultSet resultSet = statement.executeQuery(claimQuery);
469
+
470
+
if (!resultSet.next()) {
471
+
resultSet.close();
472
+
statement.close();
473
+
connection.close();
474
+
return false;
475
+
}
476
+
477
+
boolean allow = resultSet.getBoolean("allow_explosions");
478
+
479
+
claimCache.put(chunk.getChunkKey(), new ApiChunk(
480
+
resultSet.getLong("id"),
481
+
resultSet.getLong("user_id"),
482
+
resultSet.getInt("chunk_x"),
483
+
resultSet.getInt("chunk_z"),
484
+
resultSet.getTimestamp("created_at"),
485
+
resultSet.getTimestamp("updated_at"),
486
+
resultSet.getBoolean("allow_explosions")
487
+
));
488
+
489
+
resultSet.close();
490
+
statement.close();
491
+
connection.close();
492
+
return allow;
493
+
} catch (SQLException e) {
494
+
e.printStackTrace();
495
+
}
496
+
497
+
return false;
498
+
}
499
+
500
+
public enum ChunkPermission {
501
+
BlockBreak,
502
+
BlockPlace,
503
+
BucketEmpty,
504
+
BucketFill,
505
+
Interact
506
+
}
507
+
508
+
public static String getChunkPermissionString(ChunkPermission perm)
509
+
{
510
+
switch(perm) {
511
+
case BucketEmpty -> {
512
+
return "bucket_empty";
513
+
}
514
+
case BucketFill -> {
515
+
return "bucket_fill";
516
+
}
517
+
case Interact -> {
518
+
return "interact";
519
+
}
520
+
case BlockBreak -> {
521
+
return "block_break";
522
+
}
523
+
case BlockPlace -> {
524
+
return "block_place";
525
+
}
526
+
}
527
+
return "";
528
+
}
529
+
530
+
public static boolean setClaimPermission(Player player, Chunk chunk, @Nullable String targetPlayerUUID, ChunkPermission permission, boolean value)
531
+
{
532
+
try {
533
+
Connection connection = DatabaseConnector.getConnection();
534
+
Statement statement = connection.createStatement();
535
+
536
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
537
+
ResultSet userResultSet = statement.executeQuery(userQuery);
538
+
539
+
if (!userResultSet.next()) {
540
+
userResultSet.close();
541
+
statement.close();
542
+
connection.close();
543
+
return false;
544
+
}
545
+
546
+
int userId = userResultSet.getInt("id");
547
+
548
+
userResultSet.close();
549
+
550
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
551
+
ResultSet claimResultSet = statement.executeQuery(claimQuery);
552
+
553
+
if (!claimResultSet.next()) {
554
+
claimResultSet.close();
555
+
statement.close();
556
+
connection.close();
557
+
return false;
558
+
}
559
+
560
+
if (claimResultSet.getInt("user_id") != userId) {
561
+
claimResultSet.close();
562
+
statement.close();
563
+
connection.close();
564
+
return false;
565
+
}
566
+
567
+
Long claimId = claimResultSet.getLong("id");
568
+
Long targetId = null;
569
+
if(targetPlayerUUID != null) {
570
+
String targetQuery = "SELECT * FROM user WHERE uuid = \"" + targetPlayerUUID + "\"";
571
+
ResultSet targetResultSet = statement.executeQuery(targetQuery);
572
+
573
+
if (!targetResultSet.next()) {
574
+
targetResultSet.close();
575
+
claimResultSet.close();
576
+
statement.close();
577
+
connection.close();
578
+
return false;
579
+
}
580
+
581
+
targetId = targetResultSet.getLong("id");
582
+
}
583
+
584
+
String claimPermissionQuery;
585
+
if(targetId != null) {
586
+
claimPermissionQuery = "SELECT * FROM claim_permission WHERE user_id = " + String.valueOf(targetId) + " AND claim_id = " + claimId;
587
+
} else {
588
+
claimPermissionQuery = "SELECT * FROM claim_permission WHERE user_id IS NULL AND claim_id = " + claimId;
589
+
}
590
+
ResultSet claimPermissionResultSet = statement.executeQuery(claimPermissionQuery);
591
+
592
+
if(!claimPermissionResultSet.next())
593
+
{
594
+
if(targetId != null) {
595
+
statement.execute("INSERT INTO claim_permission(claim_id, user_id) VALUES(" + claimId + ", " + String.valueOf(targetId) + ")");
596
+
} else {
597
+
statement.execute("INSERT INTO claim_permission(claim_id, user_id) VALUES(" + claimId + ", NULL)");
598
+
}
599
+
}
600
+
601
+
String permissionString = "";
602
+
switch(permission) {
603
+
case Interact -> permissionString = "interact";
604
+
case BlockBreak -> permissionString = "block_break";
605
+
case BlockPlace -> permissionString = "block_place";
606
+
case BucketFill -> permissionString = "bucket_fill";
607
+
case BucketEmpty -> permissionString = "bucket_empty";
608
+
}
609
+
610
+
String updateQuery;
611
+
if(targetId != null) {
612
+
updateQuery = "UPDATE claim_permission SET " + permissionString + " = " + (value ? 1 : 0) + " WHERE user_id = " + String.valueOf(targetId) + " AND claim_id = " + claimId;
613
+
} else {
614
+
updateQuery = "UPDATE claim_permission SET " + permissionString + " = " + (value ? 1 : 0) + " WHERE user_id IS NULL AND claim_id = " + claimId;
615
+
}
616
+
statement.execute(updateQuery);
617
+
618
+
claimPermissionResultSet.close();
619
+
claimResultSet.close();
620
+
userResultSet.close();
621
+
statement.close();
622
+
connection.close();
623
+
return true;
624
+
} catch (SQLException e) {
625
+
player.sendMessage(Component.text(e.getMessage()).color(NamedTextColor.RED));
626
+
e.printStackTrace();
627
+
}
628
+
629
+
return false;
630
+
}
631
+
632
+
@Nullable
633
+
public static Map<ChunkPermission, Boolean> getChunkPermissionsForUser(String uuid, Chunk chunk)
634
+
{
635
+
try {
636
+
Connection connection = DatabaseConnector.getConnection();
637
+
Statement statement = connection.createStatement();
638
+
639
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
640
+
ResultSet claimResultSet = statement.executeQuery(claimQuery);
641
+
642
+
if (!claimResultSet.next()) {
643
+
claimResultSet.close();
644
+
statement.close();
645
+
connection.close();
646
+
Bukkit.getConsoleSender().sendMessage("No Claim");
647
+
return null;
648
+
}
649
+
650
+
long claimId = claimResultSet.getLong("id");
651
+
claimResultSet.close();
652
+
653
+
if(uuid == null)
654
+
{
655
+
656
+
ResultSet claimPermissionResultSet = statement.executeQuery("SELECT * FROM claim_permission WHERE user_id IS NULL AND claim_id = " + claimId);
657
+
658
+
if (!claimPermissionResultSet.next()) {
659
+
Bukkit.getConsoleSender().sendMessage("No Claim Permission");
660
+
661
+
claimPermissionResultSet.close();
662
+
claimResultSet.close();
663
+
statement.close();
664
+
connection.close();
665
+
return null;
666
+
}
667
+
668
+
Boolean bb = claimPermissionResultSet.getBoolean("block_break");
669
+
Boolean bp = claimPermissionResultSet.getBoolean("block_place");
670
+
Boolean be = claimPermissionResultSet.getBoolean("bucket_empty");
671
+
Boolean bf = claimPermissionResultSet.getBoolean("bucket_fill");
672
+
Boolean in = claimPermissionResultSet.getBoolean("interact");
673
+
674
+
Map<ChunkPermission, Boolean> perm = new HashMap<>();
675
+
perm.put(ChunkPermission.BlockBreak, bb);
676
+
perm.put(ChunkPermission.BlockPlace, bp);
677
+
perm.put(ChunkPermission.BucketEmpty, be);
678
+
perm.put(ChunkPermission.BucketFill, bf);
679
+
perm.put(ChunkPermission.Interact, in);
680
+
681
+
claimPermissionResultSet.close();
682
+
claimResultSet.close();
683
+
statement.close();
684
+
connection.close();
685
+
return perm;
686
+
}
687
+
688
+
String sql = "SELECT * FROM user WHERE uuid = \"" + uuid + "\"";
689
+
ResultSet userResultSet = statement.executeQuery(sql);
690
+
691
+
if (!userResultSet.next()) {
692
+
Bukkit.getConsoleSender().sendMessage("No User" + sql);
693
+
694
+
userResultSet.close();
695
+
claimResultSet.close();
696
+
statement.close();
697
+
connection.close();
698
+
return null;
699
+
}
700
+
701
+
long userId = userResultSet.getLong("id");
702
+
userResultSet.close();
703
+
704
+
ResultSet claimPermissionResultSet = statement.executeQuery("SELECT * FROM claim_permission WHERE user_id = " + userId + " AND claim_id = " + claimId);
705
+
706
+
if (!claimPermissionResultSet.next()) {
707
+
Bukkit.getConsoleSender().sendMessage("No Claim Permission");
708
+
709
+
claimPermissionResultSet.close();
710
+
userResultSet.close();
711
+
claimResultSet.close();
712
+
statement.close();
713
+
connection.close();
714
+
return null;
715
+
}
716
+
717
+
Boolean bb = claimPermissionResultSet.getBoolean("block_break");
718
+
Boolean bp = claimPermissionResultSet.getBoolean("block_place");
719
+
Boolean be = claimPermissionResultSet.getBoolean("bucket_empty");
720
+
Boolean bf = claimPermissionResultSet.getBoolean("bucket_fill");
721
+
Boolean in = claimPermissionResultSet.getBoolean("interact");
722
+
723
+
Map<ChunkPermission, Boolean> perm = new HashMap<>();
724
+
perm.put(ChunkPermission.BlockBreak, bb);
725
+
perm.put(ChunkPermission.BlockPlace, bp);
726
+
perm.put(ChunkPermission.BucketEmpty, be);
727
+
perm.put(ChunkPermission.BucketFill, bf);
728
+
perm.put(ChunkPermission.Interact, in);
729
+
730
+
claimPermissionResultSet.close();
731
+
userResultSet.close();
732
+
claimResultSet.close();
733
+
statement.close();
734
+
connection.close();
735
+
return perm;
736
+
} catch (SQLException e) {
737
+
e.printStackTrace();
738
+
}
739
+
740
+
Bukkit.getConsoleSender().sendMessage("Found error");
741
+
742
+
return null;
743
+
}
744
+
745
+
public static Result addChunkPermissionsForUser(Player player, @Nullable String targetNickname, Chunk chunk)
746
+
{
747
+
try {
748
+
Connection connection = DatabaseConnector.getConnection();
749
+
Statement statement = connection.createStatement();
750
+
751
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
752
+
ResultSet claimResultSet = statement.executeQuery(claimQuery);
753
+
754
+
if (!claimResultSet.next()) {
755
+
claimResultSet.close();
756
+
statement.close();
757
+
connection.close();
758
+
// Bukkit.getConsoleSender().sendMessage("No Claim");
759
+
return new Failure("No claim at chunk");
760
+
}
761
+
762
+
long claimOwnerId = claimResultSet.getLong("user_id");
763
+
long claimId = claimResultSet.getLong("id");
764
+
claimResultSet.close();
765
+
766
+
String sql = "SELECT * FROM user WHERE uuid = \"" + player.getUniqueId().toString() + "\"";
767
+
ResultSet userResultSet = statement.executeQuery(sql);
768
+
769
+
if (!userResultSet.next()) {
770
+
// Bukkit.getConsoleSender().sendMessage("No User");
771
+
772
+
userResultSet.close();
773
+
claimResultSet.close();
774
+
statement.close();
775
+
connection.close();
776
+
return new Failure("No user exists with uuid");
777
+
}
778
+
779
+
long userId = userResultSet.getLong("id");
780
+
userResultSet.close();
781
+
782
+
if(claimOwnerId != userId)
783
+
{
784
+
// player.sendMessage(Component.text("No permission to update chunk").color(NamedTextColor.RED));
785
+
786
+
statement.close();
787
+
connection.close();
788
+
return new Failure("Player doesn't have permission to update chunk");
789
+
}
790
+
791
+
if(targetNickname == null)
792
+
{
793
+
Statement checkPermStatement = connection.createStatement();
794
+
ResultSet chunkPermissionRS = checkPermStatement.executeQuery("SELECT 1 FROM claim_permission WHERE user_id IS NULL AND claim_id = " + claimId);
795
+
796
+
if(chunkPermissionRS.next())
797
+
{
798
+
chunkPermissionRS.close();
799
+
checkPermStatement.close();
800
+
statement.close();
801
+
connection.close();
802
+
return new Failure("Everyone already exists on chunk");
803
+
}
804
+
805
+
chunkPermissionRS.close();
806
+
807
+
statement.execute("INSERT INTO claim_permission(user_id, claim_id) VALUES(NULL, " + claimId + ")");
808
+
809
+
statement.close();
810
+
connection.close();
811
+
return new Success("Created everyone permission");
812
+
}
813
+
814
+
String targetSql = "SELECT * FROM user WHERE UPPER(nickname) = UPPER(\"" + targetNickname + "\")";
815
+
ResultSet targetResultSet = statement.executeQuery(targetSql);
816
+
817
+
if (!targetResultSet.next()) {
818
+
// Bukkit.getConsoleSender().sendMessage("No Target");
819
+
820
+
targetResultSet.close();
821
+
statement.close();
822
+
connection.close();
823
+
return new Failure("No target with nickname");
824
+
}
825
+
826
+
long targetUserId = targetResultSet.getLong("id");
827
+
targetResultSet.close();
828
+
829
+
if(targetUserId == userId)
830
+
{
831
+
// Bukkit.getConsoleSender().sendMessage("Can't be same as user");
832
+
833
+
statement.close();
834
+
connection.close();
835
+
return new Failure("Target can't be the same as user");
836
+
}
837
+
838
+
ResultSet chunkPermissionRS = statement.executeQuery("SELECT 1 FROM claim_permission WHERE user_id = " + targetUserId + " AND claim_id = " + claimId);
839
+
840
+
if(chunkPermissionRS.next())
841
+
{
842
+
chunkPermissionRS.close();
843
+
statement.close();
844
+
connection.close();
845
+
return new Failure("Target permission already exists on chunk");
846
+
}
847
+
848
+
chunkPermissionRS.close();
849
+
850
+
statement.execute("INSERT INTO claim_permission(user_id, claim_id) VALUES(" + targetUserId + ", " + claimId + ")");
851
+
852
+
statement.close();
853
+
connection.close();
854
+
return new Success("Created permission");
855
+
} catch (SQLException e) {
856
+
e.printStackTrace();
857
+
}
858
+
859
+
// Bukkit.getConsoleSender().sendMessage("Found error");
860
+
861
+
return new Failure("Internal error");
862
+
}
863
+
}
+20
src/main/java/dev/keii/keiichunks/RuntimeError.java
+20
src/main/java/dev/keii/keiichunks/RuntimeError.java
···
1
+
package dev.keii.keiichunks;
2
+
3
+
public class RuntimeError {
4
+
private final Exception exception;
5
+
private final String executor;
6
+
7
+
public RuntimeError(Exception e, String executor)
8
+
{
9
+
this.exception = e;
10
+
this.executor = executor;
11
+
}
12
+
13
+
public String getExecutor() {
14
+
return executor;
15
+
}
16
+
17
+
public Exception getException() {
18
+
return exception;
19
+
}
20
+
}
+79
src/main/java/dev/keii/keiichunks/api/ApiChunk.java
+79
src/main/java/dev/keii/keiichunks/api/ApiChunk.java
···
1
+
package dev.keii.keiichunks.api;
2
+
3
+
import java.sql.Timestamp;
4
+
5
+
public class ApiChunk {
6
+
private long id;
7
+
private long userID;
8
+
private int chunkX;
9
+
private int chunkZ;
10
+
private Timestamp createdAt;
11
+
private Timestamp updatedAt;
12
+
private boolean allowExplosions;
13
+
14
+
public ApiChunk(long id, long userID, int chunkX, int chunkZ, Timestamp createdAt, Timestamp updatedAt, boolean allowExplosions) {
15
+
this.id = id;
16
+
this.userID = userID;
17
+
this.chunkZ = chunkZ;
18
+
this.chunkX = chunkX;
19
+
this.createdAt = createdAt;
20
+
this.updatedAt = updatedAt;
21
+
this.allowExplosions = allowExplosions;
22
+
}
23
+
24
+
public long getId() {
25
+
return id;
26
+
}
27
+
28
+
public void setId(long id) {
29
+
this.id = id;
30
+
}
31
+
32
+
public long getUserID() {
33
+
return userID;
34
+
}
35
+
36
+
public void setUserID(long userID) {
37
+
this.userID = userID;
38
+
}
39
+
40
+
public int getChunkX() {
41
+
return chunkX;
42
+
}
43
+
44
+
public void setChunkX(int chunkX) {
45
+
this.chunkX = chunkX;
46
+
}
47
+
48
+
public int getChunkZ() {
49
+
return chunkZ;
50
+
}
51
+
52
+
public void setChunkZ(int chunkZ) {
53
+
this.chunkZ = chunkZ;
54
+
}
55
+
56
+
public Timestamp getCreatedAt() {
57
+
return createdAt;
58
+
}
59
+
60
+
public void setCreatedAt(Timestamp createdAt) {
61
+
this.createdAt = createdAt;
62
+
}
63
+
64
+
public Timestamp getUpdatedAt() {
65
+
return updatedAt;
66
+
}
67
+
68
+
public void setUpdatedAt(Timestamp updatedAt) {
69
+
this.updatedAt = updatedAt;
70
+
}
71
+
72
+
public boolean isAllowExplosions() {
73
+
return allowExplosions;
74
+
}
75
+
76
+
public void setAllowExplosions(boolean allowExplosions) {
77
+
this.allowExplosions = allowExplosions;
78
+
}
79
+
}
+26
src/main/java/dev/keii/keiichunks/api/ApiStatusMessage.java
+26
src/main/java/dev/keii/keiichunks/api/ApiStatusMessage.java
···
1
+
package dev.keii.keiichunks.api;
2
+
3
+
import com.fasterxml.jackson.annotation.JsonCreator;
4
+
import com.fasterxml.jackson.annotation.JsonProperty;
5
+
6
+
public class ApiStatusMessage {
7
+
@JsonProperty("status")
8
+
private final int status;
9
+
@JsonProperty("message")
10
+
private final String message;
11
+
12
+
@JsonCreator
13
+
public ApiStatusMessage(@JsonProperty("status") int status, @JsonProperty("message") String message)
14
+
{
15
+
this.status = status;
16
+
this.message = message;
17
+
}
18
+
19
+
public String getMessage() {
20
+
return this.message;
21
+
}
22
+
23
+
public int getStatus() {
24
+
return this.status;
25
+
}
26
+
}
+19
src/main/java/dev/keii/keiichunks/commands/CommandLoad.java
+19
src/main/java/dev/keii/keiichunks/commands/CommandLoad.java
···
1
+
package dev.keii.keiichunks.commands;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.inventories.InventoryMap;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.command.Command;
8
+
import org.bukkit.command.CommandExecutor;
9
+
import org.bukkit.command.CommandSender;
10
+
import org.bukkit.entity.Player;
11
+
import org.jetbrains.annotations.NotNull;
12
+
13
+
public class CommandLoad implements CommandExecutor {
14
+
@Override
15
+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
16
+
KeiiChunks.LoadData();
17
+
return true;
18
+
}
19
+
}
+26
src/main/java/dev/keii/keiichunks/commands/CommandMap.java
+26
src/main/java/dev/keii/keiichunks/commands/CommandMap.java
···
1
+
package dev.keii.keiichunks.commands;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.inventories.InventoryMap;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.command.Command;
8
+
import org.bukkit.command.CommandExecutor;
9
+
import org.bukkit.command.CommandSender;
10
+
import org.bukkit.entity.Player;
11
+
import org.jetbrains.annotations.NotNull;
12
+
13
+
public class CommandMap implements CommandExecutor {
14
+
@Override
15
+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
16
+
if(!(sender instanceof Player player)) {
17
+
sender.sendMessage(Component.text("You must run this command as player!").color(NamedTextColor.RED));
18
+
return false;
19
+
}
20
+
21
+
InventoryMap map = new InventoryMap(player);
22
+
player.openInventory(map.getInventory());
23
+
24
+
return true;
25
+
}
26
+
}
+19
src/main/java/dev/keii/keiichunks/commands/CommandSave.java
+19
src/main/java/dev/keii/keiichunks/commands/CommandSave.java
···
1
+
package dev.keii.keiichunks.commands;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.inventories.InventoryMap;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.command.Command;
8
+
import org.bukkit.command.CommandExecutor;
9
+
import org.bukkit.command.CommandSender;
10
+
import org.bukkit.entity.Player;
11
+
import org.jetbrains.annotations.NotNull;
12
+
13
+
public class CommandSave implements CommandExecutor {
14
+
@Override
15
+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
16
+
KeiiChunks.SaveData();
17
+
return true;
18
+
}
19
+
}
+7
src/main/java/dev/keii/keiichunks/error/Failure.java
+7
src/main/java/dev/keii/keiichunks/error/Failure.java
+14
src/main/java/dev/keii/keiichunks/error/Result.java
+14
src/main/java/dev/keii/keiichunks/error/Result.java
+7
src/main/java/dev/keii/keiichunks/error/Success.java
+7
src/main/java/dev/keii/keiichunks/error/Success.java
+97
src/main/java/dev/keii/keiichunks/events/BlockBreak.java
+97
src/main/java/dev/keii/keiichunks/events/BlockBreak.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.DatabaseConnector;
4
+
import dev.keii.keiichunks.KeiiChunks;
5
+
import dev.keii.keiichunks.PlayerChunk;
6
+
import net.kyori.adventure.text.Component;
7
+
import net.kyori.adventure.text.format.NamedTextColor;
8
+
import org.bukkit.Bukkit;
9
+
import org.bukkit.Chunk;
10
+
import org.bukkit.entity.Player;
11
+
import org.bukkit.event.EventHandler;
12
+
import org.bukkit.event.Listener;
13
+
import org.bukkit.event.block.BlockBreakEvent;
14
+
15
+
import java.sql.Connection;
16
+
import java.sql.ResultSet;
17
+
import java.sql.SQLException;
18
+
import java.sql.Statement;
19
+
20
+
import static dev.keii.keiichunks.PlayerChunk.getChunkPermissionString;
21
+
22
+
public class BlockBreak implements Listener {
23
+
24
+
public static boolean getPlayerPermissionForChunk(Player player, Chunk chunk, PlayerChunk.ChunkPermission perm)
25
+
{
26
+
boolean canBreak = true;
27
+
28
+
try {
29
+
Connection connection = DatabaseConnector.getConnection();
30
+
Statement statement = connection.createStatement();
31
+
32
+
ResultSet claimResultSet = statement.executeQuery("SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ());
33
+
34
+
if(!claimResultSet.next()) // Claim doesn't exist
35
+
{
36
+
claimResultSet.close();
37
+
statement.close();
38
+
connection.close();
39
+
return true;
40
+
}
41
+
42
+
long claimId = claimResultSet.getLong("id");
43
+
long claimOwnerId = claimResultSet.getLong("user_id");
44
+
claimResultSet.close();
45
+
46
+
ResultSet claimPermissionResultSet = statement.executeQuery("SELECT * FROM claim_permission WHERE user_id IS NULL AND claim_id = " + claimId);
47
+
48
+
if(claimPermissionResultSet.next())
49
+
{
50
+
canBreak = claimPermissionResultSet.getBoolean(getChunkPermissionString(perm));
51
+
}
52
+
53
+
claimPermissionResultSet.close();
54
+
55
+
ResultSet userResultSet = statement.executeQuery( "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId().toString() + "\"");
56
+
57
+
if(userResultSet.next()) {
58
+
if(userResultSet.getLong("id") == claimOwnerId)
59
+
{
60
+
canBreak = true;
61
+
} else {
62
+
ResultSet claimPermissionUserResultSet = statement.executeQuery("SELECT * FROM claim_permission WHERE user_id = " + userResultSet.getLong("id") + " AND claim_id = " + claimId);
63
+
64
+
if (claimPermissionUserResultSet.next()) {
65
+
canBreak = claimPermissionUserResultSet.getBoolean(getChunkPermissionString(perm));
66
+
}
67
+
68
+
claimPermissionUserResultSet.close();
69
+
}
70
+
}
71
+
72
+
userResultSet.close();
73
+
74
+
statement.close();
75
+
connection.close();
76
+
} catch (SQLException e) {
77
+
Bukkit.getServer().broadcast(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
78
+
}
79
+
80
+
return canBreak;
81
+
}
82
+
83
+
@EventHandler
84
+
public void onBlockBreak(BlockBreakEvent event)
85
+
{
86
+
Player player = event.getPlayer();
87
+
Chunk chunk = event.getBlock().getChunk();
88
+
89
+
boolean canBreak = getPlayerPermissionForChunk(player, chunk, PlayerChunk.ChunkPermission.BlockBreak);
90
+
91
+
event.setCancelled(!canBreak);
92
+
if(!canBreak)
93
+
{
94
+
player.sendActionBar(Component.text("You do not have the rights to break blocks in this chunk!").color(NamedTextColor.RED));
95
+
}
96
+
}
97
+
}
+28
src/main/java/dev/keii/keiichunks/events/BlockPlace.java
+28
src/main/java/dev/keii/keiichunks/events/BlockPlace.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.Chunk;
8
+
import org.bukkit.entity.Player;
9
+
import org.bukkit.event.EventHandler;
10
+
import org.bukkit.event.Listener;
11
+
import org.bukkit.event.block.BlockPlaceEvent;
12
+
13
+
public class BlockPlace implements Listener {
14
+
@EventHandler
15
+
public void onBlockPlace(BlockPlaceEvent event)
16
+
{
17
+
Player player = event.getPlayer();
18
+
Chunk chunk = event.getBlock().getChunk();
19
+
20
+
boolean canBreak = BlockBreak.getPlayerPermissionForChunk(player, chunk, PlayerChunk.ChunkPermission.BlockPlace);
21
+
22
+
event.setCancelled(!canBreak);
23
+
if(!canBreak)
24
+
{
25
+
player.sendActionBar(Component.text("You do not have the rights to place blocks in this chunk!").color(NamedTextColor.RED));
26
+
}
27
+
}
28
+
}
+28
src/main/java/dev/keii/keiichunks/events/BucketEmpty.java
+28
src/main/java/dev/keii/keiichunks/events/BucketEmpty.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.Chunk;
8
+
import org.bukkit.entity.Player;
9
+
import org.bukkit.event.EventHandler;
10
+
import org.bukkit.event.Listener;
11
+
import org.bukkit.event.player.PlayerBucketEmptyEvent;
12
+
13
+
public class BucketEmpty implements Listener {
14
+
@EventHandler
15
+
public void onBucketEmpty(PlayerBucketEmptyEvent event)
16
+
{
17
+
Player player = event.getPlayer();
18
+
Chunk chunk = event.getBlock().getChunk();
19
+
20
+
boolean canBreak = BlockBreak.getPlayerPermissionForChunk(player, chunk, PlayerChunk.ChunkPermission.BucketEmpty);
21
+
22
+
event.setCancelled(!canBreak);
23
+
if(!canBreak)
24
+
{
25
+
player.sendActionBar(Component.text("You do not have the rights to empty buckets in this chunk!").color(NamedTextColor.RED));
26
+
}
27
+
}
28
+
}
+28
src/main/java/dev/keii/keiichunks/events/BucketFill.java
+28
src/main/java/dev/keii/keiichunks/events/BucketFill.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.Chunk;
8
+
import org.bukkit.entity.Player;
9
+
import org.bukkit.event.EventHandler;
10
+
import org.bukkit.event.Listener;
11
+
import org.bukkit.event.player.PlayerBucketFillEvent;
12
+
13
+
public class BucketFill implements Listener {
14
+
@EventHandler
15
+
public void onBucketFill(PlayerBucketFillEvent event)
16
+
{
17
+
Player player = event.getPlayer();
18
+
Chunk chunk = event.getBlock().getChunk();
19
+
20
+
boolean canBreak = BlockBreak.getPlayerPermissionForChunk(player, chunk, PlayerChunk.ChunkPermission.BucketFill);
21
+
22
+
event.setCancelled(!canBreak);
23
+
if(!canBreak)
24
+
{
25
+
player.sendActionBar(Component.text("You do not have the rights to fill buckets in this chunk!").color(NamedTextColor.RED));
26
+
}
27
+
}
28
+
}
+5
src/main/java/dev/keii/keiichunks/events/ChatListener.java
+5
src/main/java/dev/keii/keiichunks/events/ChatListener.java
+15
src/main/java/dev/keii/keiichunks/events/ChunkPermissionAddPlayer.java
+15
src/main/java/dev/keii/keiichunks/events/ChunkPermissionAddPlayer.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import org.bukkit.Chunk;
4
+
5
+
public class ChunkPermissionAddPlayer extends ChatListener {
6
+
Chunk chunk;
7
+
8
+
public ChunkPermissionAddPlayer(Chunk chunk) {
9
+
this.chunk = chunk;
10
+
}
11
+
12
+
public Chunk getChunk() {
13
+
return chunk;
14
+
}
15
+
}
+15
src/main/java/dev/keii/keiichunks/events/EntityExplode.java
+15
src/main/java/dev/keii/keiichunks/events/EntityExplode.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import org.bukkit.event.EventHandler;
6
+
import org.bukkit.event.Listener;
7
+
import org.bukkit.event.entity.EntityExplodeEvent;
8
+
9
+
public class EntityExplode implements Listener {
10
+
@EventHandler
11
+
public void onEntityExplode(EntityExplodeEvent event)
12
+
{
13
+
event.blockList().removeIf(b -> !PlayerChunk.getExplosionPolicy(b.getChunk()));
14
+
}
15
+
}
+233
src/main/java/dev/keii/keiichunks/events/InventoryClick.java
+233
src/main/java/dev/keii/keiichunks/events/InventoryClick.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.PlayerChunk;
4
+
import dev.keii.keiichunks.saveload.User;
5
+
import dev.keii.keiichunks.inventories.InventoryChunkPermission;
6
+
import dev.keii.keiichunks.inventories.InventoryMap;
7
+
import dev.keii.keiichunks.inventories.InventoryModifyChunk;
8
+
import dev.keii.keiichunks.inventories.InventoryModifyChunkPermission;
9
+
import net.kyori.adventure.text.Component;
10
+
import net.kyori.adventure.text.format.NamedTextColor;
11
+
import org.bukkit.Bukkit;
12
+
import org.bukkit.Chunk;
13
+
import org.bukkit.entity.Player;
14
+
import org.bukkit.event.EventHandler;
15
+
import org.bukkit.event.Listener;
16
+
import org.bukkit.event.inventory.InventoryClickEvent;
17
+
import org.bukkit.inventory.Inventory;
18
+
import org.joml.Vector2i;
19
+
20
+
import java.util.HashMap;
21
+
import java.util.List;
22
+
import java.util.Map;
23
+
import java.util.Objects;
24
+
25
+
public class InventoryClick implements Listener {
26
+
public static Map<String, Vector2i> modifyChunk = new HashMap<>();
27
+
public static Map<String, Integer> modifyChunkPermissionUser = new HashMap<>();
28
+
29
+
@EventHandler
30
+
public void onInventoryClick(InventoryClickEvent event)
31
+
{
32
+
Inventory inventory = event.getInventory();
33
+
34
+
if(inventory.getHolder() instanceof InventoryMap) {
35
+
event.setCancelled(true);
36
+
Player player = (Player)event.getWhoClicked();
37
+
38
+
if(event.getCurrentItem() == null)
39
+
{
40
+
return;
41
+
}
42
+
43
+
List<String> lore = Objects.requireNonNull(event.getCurrentItem()).getLore();
44
+
45
+
Integer chunkX = null;
46
+
Integer chunkZ = null;
47
+
48
+
for(String line : Objects.requireNonNull(lore))
49
+
{
50
+
if(line.startsWith("ChunkX")) {
51
+
String[] split = line.split(",");
52
+
chunkX = Integer.parseInt(split[0].substring(8));
53
+
chunkZ = Integer.parseInt(split[1].substring(9));
54
+
}
55
+
}
56
+
57
+
if(chunkX != null)
58
+
{
59
+
String owner = PlayerChunk.getChunkOwnerUUID(event.getWhoClicked().getWorld().getChunkAt(chunkX, chunkZ));
60
+
if(owner != null) {
61
+
if(owner.equals(player.getUniqueId().toString())) {
62
+
player.closeInventory();
63
+
InventoryModifyChunk mc = new InventoryModifyChunk();
64
+
InventoryClick.modifyChunk.remove(player.getUniqueId().toString());
65
+
InventoryClick.modifyChunk.put(player.getUniqueId().toString(), new Vector2i(chunkX, chunkZ));
66
+
player.openInventory(mc.getInventory());
67
+
}
68
+
return;
69
+
}
70
+
71
+
if(PlayerChunk.claimChunk(player, event.getWhoClicked().getWorld().getChunkAt(chunkX, chunkZ))) {
72
+
PlayerChunk.addChunkPermissionsForUser(player, null, event.getWhoClicked().getWorld().getChunkAt(chunkX, chunkZ));
73
+
player.sendMessage(Component.text("Claimed Chunk").color(NamedTextColor.YELLOW));
74
+
} else {
75
+
player.sendMessage(Component.text("Failed to claim chunk").color(NamedTextColor.RED));
76
+
}
77
+
78
+
player.closeInventory();
79
+
InventoryMap map = new InventoryMap(player);
80
+
player.openInventory(map.getInventory());
81
+
}
82
+
} else if(inventory.getHolder() instanceof InventoryModifyChunk) {
83
+
event.setCancelled(true);
84
+
85
+
int slot = event.getSlot();
86
+
if(slot > 17)
87
+
{
88
+
slot -= 9;
89
+
}
90
+
if(slot > 8)
91
+
{
92
+
slot -= 9;
93
+
}
94
+
95
+
Player player = (Player) event.getWhoClicked();
96
+
97
+
Chunk chunk = event.getWhoClicked().getWorld().getChunkAt(modifyChunk.get(player.getUniqueId().toString()).x, modifyChunk.get(player.getUniqueId().toString()).y);
98
+
99
+
if(slot > 5)
100
+
{
101
+
if(PlayerChunk.unClaimChunk(player, chunk)) {
102
+
player.sendMessage(Component.text("Unclaimed chunk").color(NamedTextColor.YELLOW));
103
+
player.closeInventory();
104
+
105
+
InventoryMap map = new InventoryMap(player);
106
+
player.openInventory(map.getInventory());
107
+
} else {
108
+
player.sendMessage(Component.text("Failed to unclaim chunk").color(NamedTextColor.RED));
109
+
}
110
+
} else if(slot > 2)
111
+
{
112
+
if(!PlayerChunk.toggleExplosionPolicy(player, chunk))
113
+
{
114
+
player.sendMessage(Component.text("Failed to toggle explosions for chunk").color(NamedTextColor.RED));
115
+
return;
116
+
}
117
+
118
+
if(PlayerChunk.getExplosionPolicy(chunk))
119
+
{
120
+
player.sendMessage(Component.text("Enabled explosions in chunk").color(NamedTextColor.YELLOW));
121
+
} else
122
+
{
123
+
player.sendMessage(Component.text("Disabled explosions in chunk").color(NamedTextColor.YELLOW));
124
+
}
125
+
126
+
127
+
} else {
128
+
player.closeInventory();
129
+
InventoryChunkPermission cp = new InventoryChunkPermission(chunk);
130
+
player.openInventory(cp.getInventory());
131
+
}
132
+
133
+
} else if(inventory.getHolder() instanceof InventoryChunkPermission)
134
+
{
135
+
event.setCancelled(true);
136
+
137
+
if(event.getCurrentItem() == null)
138
+
{
139
+
return;
140
+
}
141
+
142
+
Player player = (Player) event.getWhoClicked();
143
+
Chunk chunk = event.getWhoClicked().getWorld().getChunkAt(modifyChunk.get(player.getUniqueId().toString()).x, modifyChunk.get(player.getUniqueId().toString()).y);
144
+
145
+
if(event.getCurrentItem().displayName().toString().contains("Everyone")) {
146
+
// player.sendMessage("Found");
147
+
modifyChunkPermissionUser.put(player.getUniqueId().toString(), null);
148
+
149
+
player.closeInventory();
150
+
InventoryModifyChunkPermission mcp = new InventoryModifyChunkPermission(null, chunk);
151
+
player.openInventory(mcp.getInventory());
152
+
} else if (!event.getCurrentItem().displayName().toString().contains("Add User")) {
153
+
String userid = null;
154
+
for(var i : Objects.requireNonNull(event.getCurrentItem().lore()))
155
+
{
156
+
if(i.toString().contains("User")) {
157
+
userid = i.toString().split("\"")[1].split(":")[1];
158
+
}
159
+
}
160
+
if(userid == null)
161
+
{
162
+
return;
163
+
}
164
+
165
+
modifyChunkPermissionUser.put(player.getUniqueId().toString(), Integer.parseInt(userid.trim()));
166
+
167
+
player.closeInventory();
168
+
InventoryModifyChunkPermission mcp = new InventoryModifyChunkPermission(User.getUUIDFromID(Integer.parseInt(userid.trim())), chunk);
169
+
player.openInventory(mcp.getInventory());
170
+
} else {
171
+
PlayerChat.chunkListener.put(player.getUniqueId().toString(), new ChunkPermissionAddPlayer(chunk));
172
+
player.sendMessage(Component.text("Type name of player you wish to add permissions for in chat!").color(NamedTextColor.YELLOW));
173
+
player.closeInventory();
174
+
}
175
+
} else if(inventory.getHolder() instanceof InventoryModifyChunkPermission)
176
+
{
177
+
event.setCancelled(true);
178
+
179
+
Player player = (Player) event.getWhoClicked();
180
+
Chunk chunk = event.getWhoClicked().getWorld().getChunkAt(modifyChunk.get(player.getUniqueId().toString()).x, modifyChunk.get(player.getUniqueId().toString()).y);
181
+
182
+
if(event.getCurrentItem() == null)
183
+
{
184
+
return;
185
+
}
186
+
187
+
String displayName = event.getCurrentItem().displayName().toString();
188
+
189
+
if(modifyChunkPermissionUser.get(player.getUniqueId().toString()) != null) {
190
+
if (displayName.contains("Interact")) {
191
+
PlayerChunk.setClaimPermission(player, chunk, User.getUUIDFromID(modifyChunkPermissionUser.get(player.getUniqueId().toString())), PlayerChunk.ChunkPermission.Interact, displayName.contains("Enable"));
192
+
} else if (displayName.contains("Block Break")) {
193
+
PlayerChunk.setClaimPermission(player, chunk, User.getUUIDFromID(modifyChunkPermissionUser.get(player.getUniqueId().toString())), PlayerChunk.ChunkPermission.BlockBreak, displayName.contains("Enable"));
194
+
} else if (displayName.contains("Block Place")) {
195
+
PlayerChunk.setClaimPermission(player, chunk, User.getUUIDFromID(modifyChunkPermissionUser.get(player.getUniqueId().toString())), PlayerChunk.ChunkPermission.BlockPlace, displayName.contains("Enable"));
196
+
} else if (displayName.contains("Bucket Empty")) {
197
+
PlayerChunk.setClaimPermission(player, chunk, User.getUUIDFromID(modifyChunkPermissionUser.get(player.getUniqueId().toString())), PlayerChunk.ChunkPermission.BucketEmpty, displayName.contains("Enable"));
198
+
} else if (displayName.contains("Bucket Fill")) {
199
+
PlayerChunk.setClaimPermission(player, chunk, User.getUUIDFromID(modifyChunkPermissionUser.get(player.getUniqueId().toString())), PlayerChunk.ChunkPermission.BucketFill, displayName.contains("Enable"));
200
+
}
201
+
} else {
202
+
if (displayName.contains("Interact")) {
203
+
PlayerChunk.setClaimPermission(player, chunk, null, PlayerChunk.ChunkPermission.Interact, displayName.contains("Enable"));
204
+
} else if (displayName.contains("Block Break")) {
205
+
PlayerChunk.setClaimPermission(player, chunk, null, PlayerChunk.ChunkPermission.BlockBreak, displayName.contains("Enable"));
206
+
} else if (displayName.contains("Block Place")) {
207
+
PlayerChunk.setClaimPermission(player, chunk, null, PlayerChunk.ChunkPermission.BlockPlace, displayName.contains("Enable"));
208
+
} else if (displayName.contains("Bucket Empty")) {
209
+
PlayerChunk.setClaimPermission(player, chunk, null, PlayerChunk.ChunkPermission.BucketEmpty, displayName.contains("Enable"));
210
+
} else if (displayName.contains("Bucket Fill")) {
211
+
PlayerChunk.setClaimPermission(player, chunk, null, PlayerChunk.ChunkPermission.BucketFill, displayName.contains("Enable"));
212
+
}
213
+
}
214
+
215
+
if(displayName.contains("Back"))
216
+
{
217
+
player.closeInventory();
218
+
InventoryChunkPermission cp = new InventoryChunkPermission(chunk);
219
+
player.openInventory(cp.getInventory());
220
+
return;
221
+
}
222
+
223
+
player.closeInventory();
224
+
if(modifyChunkPermissionUser.get(player.getUniqueId().toString()) != null) {
225
+
InventoryModifyChunkPermission mcp = new InventoryModifyChunkPermission(User.getUUIDFromID(modifyChunkPermissionUser.get(player.getUniqueId().toString())), chunk);
226
+
player.openInventory(mcp.getInventory());
227
+
} else {
228
+
InventoryModifyChunkPermission mcp = new InventoryModifyChunkPermission(null, chunk);
229
+
player.openInventory(mcp.getInventory());
230
+
}
231
+
}
232
+
}
233
+
}
+48
src/main/java/dev/keii/keiichunks/events/PlayerChat.java
+48
src/main/java/dev/keii/keiichunks/events/PlayerChat.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import dev.keii.keiichunks.error.Success;
6
+
import dev.keii.keiichunks.inventories.InventoryChunkPermission;
7
+
import net.kyori.adventure.text.Component;
8
+
import net.kyori.adventure.text.format.NamedTextColor;
9
+
import org.bukkit.entity.Player;
10
+
import org.bukkit.event.EventHandler;
11
+
import org.bukkit.event.Listener;
12
+
import org.bukkit.event.player.PlayerChatEvent;
13
+
14
+
import java.util.HashMap;
15
+
import java.util.Map;
16
+
17
+
public class PlayerChat implements Listener {
18
+
19
+
public static Map<String, ChatListener> chunkListener = new HashMap<>();
20
+
21
+
@EventHandler
22
+
public void onPlayerChat(PlayerChatEvent event)
23
+
{
24
+
Player player = event.getPlayer();
25
+
26
+
if(chunkListener.get(player.getUniqueId().toString()) == null)
27
+
{
28
+
return;
29
+
}
30
+
31
+
if(chunkListener.get(player.getUniqueId().toString()) instanceof ChunkPermissionAddPlayer)
32
+
event.setCancelled(true);
33
+
34
+
var result = PlayerChunk.addChunkPermissionsForUser(player, event.getMessage(), ((ChunkPermissionAddPlayer)chunkListener.get(player.getUniqueId().toString())).getChunk());
35
+
36
+
if(result instanceof Success) {
37
+
player.sendMessage(Component.text("Permissions added for player").color(NamedTextColor.GREEN));
38
+
player.closeInventory();
39
+
InventoryChunkPermission cp = new InventoryChunkPermission(((ChunkPermissionAddPlayer)chunkListener.get(player.getUniqueId().toString())).getChunk());
40
+
player.openInventory(cp.getInventory());
41
+
} else {
42
+
player.sendMessage(Component.text("Failed: " + result.getMessage()).color(NamedTextColor.RED));
43
+
44
+
}
45
+
46
+
chunkListener.remove(player.getUniqueId().toString());
47
+
}
48
+
}
+36
src/main/java/dev/keii/keiichunks/events/PlayerInteract.java
+36
src/main/java/dev/keii/keiichunks/events/PlayerInteract.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.Bukkit;
8
+
import org.bukkit.Chunk;
9
+
import org.bukkit.entity.Player;
10
+
import org.bukkit.event.EventHandler;
11
+
import org.bukkit.event.Listener;
12
+
import org.bukkit.event.player.PlayerInteractEvent;
13
+
14
+
public class PlayerInteract implements Listener {
15
+
@EventHandler
16
+
public void onPlayerInteract(PlayerInteractEvent event)
17
+
{
18
+
Player player = event.getPlayer();
19
+
20
+
if(event.getClickedBlock() == null)
21
+
{
22
+
event.setCancelled(false);
23
+
return;
24
+
}
25
+
26
+
Chunk chunk = event.getClickedBlock().getChunk();
27
+
28
+
boolean canBreak = BlockBreak.getPlayerPermissionForChunk(player, chunk, PlayerChunk.ChunkPermission.Interact);
29
+
30
+
event.setCancelled(!canBreak);
31
+
if(!canBreak)
32
+
{
33
+
player.sendActionBar(Component.text("You do not have the rights to interact with this chunk!").color(NamedTextColor.RED));
34
+
}
35
+
}
36
+
}
+58
src/main/java/dev/keii/keiichunks/events/PlayerJoin.java
+58
src/main/java/dev/keii/keiichunks/events/PlayerJoin.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import com.destroystokyo.paper.profile.PlayerProfile;
4
+
import com.destroystokyo.paper.profile.ProfileProperty;
5
+
import com.fasterxml.jackson.databind.ObjectMapper;
6
+
import dev.keii.keiichunks.DatabaseConnector;
7
+
import dev.keii.keiichunks.KeiiChunks;
8
+
import dev.keii.keiichunks.RuntimeError;
9
+
import dev.keii.keiichunks.error.Result;
10
+
import net.kyori.adventure.text.Component;
11
+
import net.kyori.adventure.text.format.NamedTextColor;
12
+
import org.bukkit.Bukkit;
13
+
import org.bukkit.entity.Player;
14
+
import org.bukkit.event.EventHandler;
15
+
import org.bukkit.event.Listener;
16
+
import org.bukkit.event.player.PlayerJoinEvent;
17
+
18
+
import java.sql.Connection;
19
+
import java.sql.ResultSet;
20
+
import java.sql.SQLException;
21
+
import java.sql.Statement;
22
+
import java.util.Set;
23
+
24
+
public class PlayerJoin implements Listener {
25
+
26
+
@EventHandler
27
+
public void onPlayerJoin(PlayerJoinEvent event)
28
+
{
29
+
Player player = event.getPlayer();
30
+
31
+
String resourcePackURL = "https://github.com/shykeiichi/plugin-resourcepack/raw/main/release.zip";
32
+
player.setResourcePack(resourcePackURL);
33
+
34
+
try {
35
+
Connection connection = DatabaseConnector.getConnection();
36
+
Statement statement = connection.createStatement();
37
+
38
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
39
+
ResultSet userResultSet = statement.executeQuery(userQuery);
40
+
41
+
if (!userResultSet.next()) { // User does not exist
42
+
userResultSet.close();
43
+
String createUserQuery = "INSERT INTO user (uuid, nickname, claim_power) VALUES (\"" + player.getUniqueId() + "\", \"" + player.getName() + "\", 15)";
44
+
statement.execute(createUserQuery);
45
+
46
+
statement.close();
47
+
connection.close();
48
+
return;
49
+
}
50
+
51
+
userResultSet.close();
52
+
statement.close();
53
+
connection.close();
54
+
} catch (SQLException e) {
55
+
Bukkit.getServer().broadcast(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
56
+
}
57
+
}
58
+
}
+28
src/main/java/dev/keii/keiichunks/events/PlayerMove.java
+28
src/main/java/dev/keii/keiichunks/events/PlayerMove.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.KeiiChunks;
4
+
import dev.keii.keiichunks.PlayerChunk;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.entity.Player;
8
+
import org.bukkit.event.EventHandler;
9
+
import org.bukkit.event.Listener;
10
+
import org.bukkit.event.player.PlayerMoveEvent;
11
+
public class PlayerMove implements Listener {
12
+
@EventHandler
13
+
public void onPlayerMove(PlayerMoveEvent event)
14
+
{
15
+
Player player = event.getPlayer();
16
+
if (!event.getFrom().getChunk().equals(event.getTo().getChunk())) {
17
+
if(PlayerChunk.getPlayerOwnsChunk(player, event.getTo().getChunk()) && !PlayerChunk.getPlayerOwnsChunk(player, event.getFrom().getChunk())) {
18
+
player.sendActionBar(Component.text("You have entered your chunk").color(NamedTextColor.YELLOW));
19
+
} else if(!PlayerChunk.getPlayerOwnsChunk(player, event.getTo().getChunk()) && PlayerChunk.getPlayerOwnsChunk(player, event.getFrom().getChunk())) {
20
+
player.sendActionBar(Component.text("You have left your chunk").color(NamedTextColor.YELLOW));
21
+
} else if(PlayerChunk.getChunkOwner(event.getTo().getChunk()) != null && PlayerChunk.getChunkOwner(event.getFrom().getChunk()) == null) {
22
+
player.sendActionBar(Component.text("You have entered " + PlayerChunk.getChunkOwner(event.getTo().getChunk()) + "'s chunk").color(NamedTextColor.RED));
23
+
} else if(PlayerChunk.getChunkOwner(event.getTo().getChunk()) == null && PlayerChunk.getChunkOwner(event.getFrom().getChunk()) != null) {
24
+
player.sendActionBar(Component.text("You have entered neutral chunks").color(NamedTextColor.AQUA));
25
+
}
26
+
}
27
+
}
28
+
}
+18
src/main/java/dev/keii/keiichunks/events/PlayerQuit.java
+18
src/main/java/dev/keii/keiichunks/events/PlayerQuit.java
···
1
+
package dev.keii.keiichunks.events;
2
+
import net.kyori.adventure.text.Component;
3
+
import org.bukkit.Bukkit;
4
+
import org.bukkit.Statistic;
5
+
import org.bukkit.entity.Player;
6
+
import org.bukkit.event.EventHandler;
7
+
import org.bukkit.event.Listener;
8
+
import org.bukkit.event.player.PlayerQuitEvent;
9
+
10
+
public class PlayerQuit implements Listener {
11
+
@EventHandler
12
+
public void onPlayerQuit(PlayerQuitEvent event)
13
+
{
14
+
// Player player = event.getPlayer();
15
+
16
+
// Bukkit.broadcast(Component.text(player.getStatistic(Statistic.PLAY_ONE_MINUTE)));
17
+
}
18
+
}
+25
src/main/java/dev/keii/keiichunks/events/PlayerResourcePack.java
+25
src/main/java/dev/keii/keiichunks/events/PlayerResourcePack.java
···
1
+
package dev.keii.keiichunks.events;
2
+
3
+
import dev.keii.keiichunks.PlayerChunk;
4
+
import net.kyori.adventure.text.Component;
5
+
import net.kyori.adventure.text.format.NamedTextColor;
6
+
import org.bukkit.entity.Player;
7
+
import org.bukkit.event.EventHandler;
8
+
import org.bukkit.event.Listener;
9
+
import org.bukkit.event.player.PlayerMoveEvent;
10
+
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
11
+
12
+
public class PlayerResourcePack implements Listener {
13
+
@EventHandler
14
+
public void onPlayerUpdateServerResourcePack(PlayerResourcePackStatusEvent event)
15
+
{
16
+
Player player = event.getPlayer();
17
+
if(event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED)
18
+
{
19
+
player.kick(Component.text("You must accept the server resource pack!\n").color(NamedTextColor.RED));
20
+
} else if(event.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD)
21
+
{
22
+
player.kick(Component.text("Server resource pack download failed!\n").color(NamedTextColor.RED));
23
+
}
24
+
}
25
+
}
+131
src/main/java/dev/keii/keiichunks/inventories/InventoryChunkPermission.java
+131
src/main/java/dev/keii/keiichunks/inventories/InventoryChunkPermission.java
···
1
+
package dev.keii.keiichunks.inventories;
2
+
3
+
import dev.keii.keiichunks.DatabaseConnector;
4
+
import net.kyori.adventure.text.Component;
5
+
import net.kyori.adventure.text.format.NamedTextColor;
6
+
import org.bukkit.Bukkit;
7
+
import org.bukkit.Chunk;
8
+
import org.bukkit.Material;
9
+
import org.bukkit.inventory.Inventory;
10
+
import org.bukkit.inventory.InventoryHolder;
11
+
import org.bukkit.inventory.ItemStack;
12
+
import org.bukkit.inventory.meta.ItemMeta;
13
+
import org.jetbrains.annotations.NotNull;
14
+
15
+
import java.sql.Connection;
16
+
import java.sql.ResultSet;
17
+
import java.sql.SQLException;
18
+
import java.sql.Statement;
19
+
import java.util.ArrayList;
20
+
import java.util.List;
21
+
22
+
public class InventoryChunkPermission implements InventoryHolder {
23
+
24
+
public static Component Name = Component.text("\uF805\uEffd\uF80B\uF80A\uF809\uF808\uF80A\uF808\uF806").color(NamedTextColor.WHITE).append(Component.text("Modify Chunk Permissions").color(NamedTextColor.DARK_GRAY));
25
+
26
+
private final Chunk chunk;
27
+
28
+
public InventoryChunkPermission(Chunk chunk)
29
+
{
30
+
this.chunk = chunk;
31
+
}
32
+
33
+
34
+
private List<Component> getChunkPermissions(ResultSet claimPermissionEveryoneResultSet) throws SQLException {
35
+
List<Component> lore = new ArrayList<>();
36
+
lore.add(Component.text("Block Break: " + claimPermissionEveryoneResultSet.getBoolean("block_break")));
37
+
lore.add(Component.text("Block Place: " + claimPermissionEveryoneResultSet.getBoolean("block_place")));
38
+
lore.add(Component.text("Bucket Empty: " + claimPermissionEveryoneResultSet.getBoolean("bucket_empty")));
39
+
lore.add(Component.text("Bucket Place: " + claimPermissionEveryoneResultSet.getBoolean("bucket_fill")));
40
+
lore.add(Component.text("Interact: " + claimPermissionEveryoneResultSet.getBoolean("interact")));
41
+
return lore;
42
+
}
43
+
44
+
@Override
45
+
public @NotNull Inventory getInventory()
46
+
{
47
+
Inventory inventory = Bukkit.createInventory(this, 27, Name);
48
+
49
+
try {
50
+
Connection connection = DatabaseConnector.getConnection();
51
+
Statement statement = connection.createStatement();
52
+
53
+
String claimQuery = "SELECT * FROM claim WHERE chunk_x = " + chunk.getX() + " AND chunk_z = " + chunk.getZ();
54
+
ResultSet claimResultSet = statement.executeQuery(claimQuery);
55
+
56
+
if (!claimResultSet.next()) {
57
+
claimResultSet.close();
58
+
statement.close();
59
+
connection.close();
60
+
throw new Exception("No claim exists for chunk " + chunk.getX() + " " + chunk.getZ());
61
+
}
62
+
63
+
long claimId = claimResultSet.getLong("id");
64
+
65
+
String claimPermissionQuery = "SELECT * FROM claim_permission WHERE user_id IS NULL AND claim_id = " + claimId;
66
+
ResultSet claimPermissionEveryoneResultSet = statement.executeQuery(claimPermissionQuery);
67
+
68
+
if(claimPermissionEveryoneResultSet.next())
69
+
{
70
+
ItemStack item = new ItemStack(Material.STICK);
71
+
ItemMeta meta = item.getItemMeta();
72
+
meta.displayName(Component.text("Everyone").color(NamedTextColor.AQUA));
73
+
meta.lore(getChunkPermissions(claimPermissionEveryoneResultSet));
74
+
meta.setCustomModelData(1001);
75
+
item.setItemMeta(meta);
76
+
inventory.addItem(item);
77
+
}
78
+
79
+
claimPermissionEveryoneResultSet.close();
80
+
81
+
claimPermissionQuery = "SELECT * FROM claim_permission WHERE user_id IS NOT NULL AND claim_id = " + claimId;
82
+
ResultSet claimPermissionResultSet = statement.executeQuery(claimPermissionQuery);
83
+
84
+
while(claimPermissionResultSet.next())
85
+
{
86
+
Statement userStatement = connection.createStatement();
87
+
ItemStack item = new ItemStack(Material.STICK);
88
+
ItemMeta meta = item.getItemMeta();
89
+
90
+
String userQuery = "SELECT * FROM user WHERE id = " + claimPermissionResultSet.getInt("user_id");
91
+
ResultSet userResultSet = userStatement.executeQuery(userQuery);
92
+
93
+
String username;
94
+
if(userResultSet.next())
95
+
{
96
+
username = userResultSet.getString("nickname");
97
+
} else {
98
+
username = "Invalid User";
99
+
}
100
+
101
+
meta.displayName(Component.text(username).color(NamedTextColor.YELLOW));
102
+
List<Component> lore = getChunkPermissions(claimPermissionResultSet);
103
+
lore.add(Component.text("User: " + claimPermissionResultSet.getInt("user_id")));
104
+
meta.setCustomModelData(1001);
105
+
meta.lore(lore);
106
+
item.setItemMeta(meta);
107
+
inventory.addItem(item);
108
+
userResultSet.close();
109
+
}
110
+
111
+
ItemStack item = new ItemStack(Material.STICK);
112
+
ItemMeta meta = item.getItemMeta();
113
+
meta.setCustomModelData(1002);
114
+
meta.displayName(Component.text("Add User").color(NamedTextColor.YELLOW));
115
+
item.setItemMeta(meta);
116
+
inventory.setItem(18, item);
117
+
118
+
claimPermissionResultSet.close();
119
+
claimResultSet.close();
120
+
statement.close();
121
+
connection.close();
122
+
return inventory;
123
+
} catch (SQLException e) {
124
+
e.printStackTrace();
125
+
} catch (Exception e) {
126
+
Bukkit.getConsoleSender().sendMessage(Component.text(e.getMessage()));
127
+
}
128
+
129
+
return inventory;
130
+
}
131
+
}
+468
src/main/java/dev/keii/keiichunks/inventories/InventoryMap.java
+468
src/main/java/dev/keii/keiichunks/inventories/InventoryMap.java
···
1
+
package dev.keii.keiichunks.inventories;
2
+
3
+
import dev.keii.keiichunks.DatabaseConnector;
4
+
import dev.keii.keiichunks.KeiiChunks;
5
+
import dev.keii.keiichunks.PlayerChunk;
6
+
import net.kyori.adventure.text.Component;
7
+
import net.kyori.adventure.text.format.NamedTextColor;
8
+
import org.bukkit.*;
9
+
import org.bukkit.block.Biome;
10
+
import org.bukkit.block.Block;
11
+
import org.bukkit.entity.Player;
12
+
import org.bukkit.inventory.Inventory;
13
+
import org.bukkit.inventory.InventoryHolder;
14
+
import org.bukkit.inventory.ItemStack;
15
+
import org.bukkit.inventory.meta.ItemMeta;
16
+
import org.jetbrains.annotations.NotNull;
17
+
import org.joml.Vector2i;
18
+
19
+
import java.sql.Connection;
20
+
import java.sql.ResultSet;
21
+
import java.sql.SQLException;
22
+
import java.sql.Statement;
23
+
import java.util.ArrayList;
24
+
import java.util.Arrays;
25
+
import java.util.HashMap;
26
+
import java.util.List;
27
+
28
+
public class InventoryMap implements InventoryHolder {
29
+
public HashMap<String, Integer> MapLookup = new HashMap<>();
30
+
31
+
Player player;
32
+
33
+
public InventoryMap(Player player)
34
+
{
35
+
MapLookup.put("wgswo", 1000);
36
+
MapLookup.put("wggge", 1001);
37
+
MapLookup.put("gssgo", 1002);
38
+
MapLookup.put("sgswn", 1003);
39
+
MapLookup.put("swgso", 1004);
40
+
MapLookup.put("gwggo", 1005);
41
+
MapLookup.put("wgsge", 1006);
42
+
MapLookup.put("gwsge", 1007);
43
+
MapLookup.put("wswge", 1008);
44
+
MapLookup.put("gssse", 1009);
45
+
MapLookup.put("sswsn", 1010);
46
+
MapLookup.put("ggswo", 1011);
47
+
MapLookup.put("sssge", 1012);
48
+
MapLookup.put("gggwe", 1013);
49
+
MapLookup.put("wwgwn", 1014);
50
+
MapLookup.put("wwsgo", 1015);
51
+
MapLookup.put("wwgso", 1016);
52
+
MapLookup.put("swsgo", 1017);
53
+
MapLookup.put("sggwn", 1018);
54
+
MapLookup.put("wgwso", 1019);
55
+
MapLookup.put("swswe", 1020);
56
+
MapLookup.put("gsgwn", 1021);
57
+
MapLookup.put("wggwn", 1022);
58
+
MapLookup.put("sgwwo", 1023);
59
+
MapLookup.put("sgwso", 1024);
60
+
MapLookup.put("sgssn", 1025);
61
+
MapLookup.put("gwwwe", 1026);
62
+
MapLookup.put("gsgsn", 1027);
63
+
MapLookup.put("wgwwn", 1028);
64
+
MapLookup.put("wwssn", 1029);
65
+
MapLookup.put("swgwo", 1030);
66
+
MapLookup.put("sgsge", 1031);
67
+
MapLookup.put("swswn", 1032);
68
+
MapLookup.put("wssge", 1033);
69
+
MapLookup.put("gwwge", 1034);
70
+
MapLookup.put("gwssn", 1035);
71
+
MapLookup.put("wggse", 1036);
72
+
MapLookup.put("sssse", 1037);
73
+
MapLookup.put("ssgge", 1038);
74
+
MapLookup.put("sgsgn", 1039);
75
+
MapLookup.put("ggwge", 1040);
76
+
MapLookup.put("wwswn", 1041);
77
+
MapLookup.put("wgwsn", 1042);
78
+
MapLookup.put("wwsse", 1043);
79
+
MapLookup.put("sgwgo", 1044);
80
+
MapLookup.put("gwsgo", 1045);
81
+
MapLookup.put("ggggo", 1046);
82
+
MapLookup.put("ggswn", 1047);
83
+
MapLookup.put("wwsgn", 1048);
84
+
MapLookup.put("gggse", 1049);
85
+
MapLookup.put("sswwn", 1050);
86
+
MapLookup.put("wssso", 1051);
87
+
MapLookup.put("swsge", 1052);
88
+
MapLookup.put("gwsso", 1053);
89
+
MapLookup.put("swwse", 1054);
90
+
MapLookup.put("gwswe", 1055);
91
+
MapLookup.put("gsggn", 1056);
92
+
MapLookup.put("gsgse", 1057);
93
+
MapLookup.put("gwsgn", 1058);
94
+
MapLookup.put("wswso", 1059);
95
+
MapLookup.put("ggsgn", 1060);
96
+
MapLookup.put("sswgo", 1061);
97
+
MapLookup.put("wsgwo", 1062);
98
+
MapLookup.put("wwwgn", 1063);
99
+
MapLookup.put("sgsgo", 1064);
100
+
MapLookup.put("wssgn", 1065);
101
+
MapLookup.put("wsgsn", 1066);
102
+
MapLookup.put("swwge", 1067);
103
+
MapLookup.put("swsse", 1068);
104
+
MapLookup.put("wgsse", 1069);
105
+
MapLookup.put("wggso", 1070);
106
+
MapLookup.put("gssgn", 1071);
107
+
MapLookup.put("ssggo", 1072);
108
+
MapLookup.put("wwgwo", 1073);
109
+
MapLookup.put("gwgsn", 1074);
110
+
MapLookup.put("ggwso", 1075);
111
+
MapLookup.put("ssgwe", 1076);
112
+
MapLookup.put("swsgn", 1077);
113
+
MapLookup.put("wgswe", 1078);
114
+
MapLookup.put("swwwe", 1079);
115
+
MapLookup.put("wwswo", 1080);
116
+
MapLookup.put("sswwe", 1081);
117
+
MapLookup.put("ssggn", 1082);
118
+
MapLookup.put("ggwsn", 1083);
119
+
MapLookup.put("wwwwn", 1084);
120
+
MapLookup.put("wgwwo", 1085);
121
+
MapLookup.put("sswge", 1086);
122
+
MapLookup.put("ggwwe", 1087);
123
+
MapLookup.put("ssswe", 1088);
124
+
MapLookup.put("wsggn", 1089);
125
+
MapLookup.put("gswwn", 1090);
126
+
MapLookup.put("gsgge", 1091);
127
+
MapLookup.put("wwwse", 1092);
128
+
MapLookup.put("gwwsn", 1093);
129
+
MapLookup.put("ggssn", 1094);
130
+
MapLookup.put("wswwo", 1095);
131
+
MapLookup.put("wgwgn", 1096);
132
+
MapLookup.put("gwwse", 1097);
133
+
MapLookup.put("wssgo", 1098);
134
+
MapLookup.put("sggse", 1099);
135
+
MapLookup.put("wgsgn", 1100);
136
+
MapLookup.put("gwwgo", 1101);
137
+
MapLookup.put("swwso", 1102);
138
+
MapLookup.put("sggwo", 1103);
139
+
MapLookup.put("wsgwe", 1104);
140
+
MapLookup.put("gwwgn", 1105);
141
+
MapLookup.put("gwsse", 1106);
142
+
MapLookup.put("gsswn", 1107);
143
+
MapLookup.put("gsgwo", 1108);
144
+
MapLookup.put("sggwe", 1109);
145
+
MapLookup.put("wswsn", 1110);
146
+
MapLookup.put("swsso", 1111);
147
+
MapLookup.put("wsswn", 1112);
148
+
MapLookup.put("wwgse", 1113);
149
+
MapLookup.put("swswo", 1114);
150
+
MapLookup.put("wswwn", 1115);
151
+
MapLookup.put("wwggo", 1116);
152
+
MapLookup.put("gsswo", 1117);
153
+
MapLookup.put("wsswo", 1118);
154
+
MapLookup.put("ggwgo", 1119);
155
+
MapLookup.put("swwsn", 1120);
156
+
MapLookup.put("sgggn", 1121);
157
+
MapLookup.put("gwwwo", 1122);
158
+
MapLookup.put("sggso", 1123);
159
+
MapLookup.put("wsggo", 1124);
160
+
MapLookup.put("wgwgo", 1125);
161
+
MapLookup.put("wssse", 1126);
162
+
MapLookup.put("ggggn", 1127);
163
+
MapLookup.put("swgsn", 1128);
164
+
MapLookup.put("sgwwn", 1129);
165
+
MapLookup.put("gwwwn", 1130);
166
+
MapLookup.put("gswse", 1131);
167
+
MapLookup.put("gswgo", 1132);
168
+
MapLookup.put("gwwso", 1133);
169
+
MapLookup.put("ssgwo", 1134);
170
+
MapLookup.put("swggn", 1135);
171
+
MapLookup.put("wwwsn", 1136);
172
+
MapLookup.put("sgswo", 1137);
173
+
MapLookup.put("wggwe", 1138);
174
+
MapLookup.put("gwgge", 1139);
175
+
MapLookup.put("sswso", 1140);
176
+
MapLookup.put("ggswe", 1141);
177
+
MapLookup.put("wwgwe", 1142);
178
+
MapLookup.put("gsssn", 1143);
179
+
MapLookup.put("sgswe", 1144);
180
+
MapLookup.put("sssgo", 1145);
181
+
MapLookup.put("sggsn", 1146);
182
+
MapLookup.put("gwgse", 1147);
183
+
MapLookup.put("swgwe", 1148);
184
+
MapLookup.put("wwgsn", 1149);
185
+
MapLookup.put("wggwo", 1150);
186
+
MapLookup.put("wwwge", 1151);
187
+
MapLookup.put("ssswn", 1152);
188
+
MapLookup.put("ssswo", 1153);
189
+
MapLookup.put("wgsgo", 1154);
190
+
MapLookup.put("gggsn", 1155);
191
+
MapLookup.put("gggwn", 1156);
192
+
MapLookup.put("wwggn", 1157);
193
+
MapLookup.put("ggwwo", 1158);
194
+
MapLookup.put("gwggn", 1159);
195
+
MapLookup.put("wgsso", 1160);
196
+
MapLookup.put("wswwe", 1161);
197
+
MapLookup.put("wsgge", 1162);
198
+
MapLookup.put("wswgn", 1163);
199
+
MapLookup.put("gswwo", 1164);
200
+
MapLookup.put("gsggo", 1165);
201
+
MapLookup.put("wgwge", 1166);
202
+
MapLookup.put("swggo", 1167);
203
+
MapLookup.put("gwswn", 1168);
204
+
MapLookup.put("sgwsn", 1169);
205
+
MapLookup.put("gsgwe", 1170);
206
+
MapLookup.put("wwsge", 1171);
207
+
MapLookup.put("gswso", 1172);
208
+
MapLookup.put("wswse", 1173);
209
+
MapLookup.put("sgwgn", 1174);
210
+
MapLookup.put("ggsge", 1175);
211
+
MapLookup.put("gsgso", 1176);
212
+
MapLookup.put("wwsso", 1177);
213
+
MapLookup.put("sgsso", 1178);
214
+
MapLookup.put("gwgso", 1179);
215
+
MapLookup.put("wsgse", 1180);
216
+
MapLookup.put("swgse", 1181);
217
+
MapLookup.put("gswgn", 1182);
218
+
MapLookup.put("ggwwn", 1183);
219
+
MapLookup.put("swwwn", 1184);
220
+
MapLookup.put("swgwn", 1185);
221
+
MapLookup.put("wwswe", 1186);
222
+
MapLookup.put("sgwse", 1187);
223
+
MapLookup.put("sswwo", 1188);
224
+
MapLookup.put("wwwgo", 1189);
225
+
MapLookup.put("sgsse", 1190);
226
+
MapLookup.put("wgwwe", 1191);
227
+
MapLookup.put("gswwe", 1192);
228
+
MapLookup.put("gswge", 1193);
229
+
MapLookup.put("ggsso", 1194);
230
+
MapLookup.put("wswgo", 1195);
231
+
MapLookup.put("gggge", 1196);
232
+
MapLookup.put("sssso", 1197);
233
+
MapLookup.put("wgswn", 1198);
234
+
MapLookup.put("wgggo", 1199);
235
+
MapLookup.put("ssssn", 1200);
236
+
MapLookup.put("ssgso", 1201);
237
+
MapLookup.put("wsgwn", 1202);
238
+
MapLookup.put("wwwwe", 1203);
239
+
MapLookup.put("ggwse", 1204);
240
+
MapLookup.put("sggge", 1205);
241
+
MapLookup.put("ssgse", 1206);
242
+
MapLookup.put("swwwo", 1207);
243
+
MapLookup.put("wwgge", 1208);
244
+
MapLookup.put("wggsn", 1209);
245
+
MapLookup.put("wgssn", 1210);
246
+
MapLookup.put("wsgso", 1211);
247
+
MapLookup.put("sswse", 1212);
248
+
MapLookup.put("gggwo", 1213);
249
+
MapLookup.put("sgggo", 1214);
250
+
MapLookup.put("ggwgn", 1215);
251
+
MapLookup.put("gswsn", 1216);
252
+
MapLookup.put("wsssn", 1217);
253
+
MapLookup.put("gggso", 1218);
254
+
MapLookup.put("wgwse", 1219);
255
+
MapLookup.put("gssso", 1220);
256
+
MapLookup.put("swgge", 1221);
257
+
MapLookup.put("ggsse", 1222);
258
+
MapLookup.put("swssn", 1223);
259
+
MapLookup.put("wwwso", 1224);
260
+
MapLookup.put("sgwge", 1225);
261
+
MapLookup.put("gwgwn", 1226);
262
+
MapLookup.put("ggsgo", 1227);
263
+
MapLookup.put("ssgsn", 1228);
264
+
MapLookup.put("wwwwo", 1229);
265
+
MapLookup.put("gwgwo", 1230);
266
+
MapLookup.put("sgwwe", 1231);
267
+
MapLookup.put("gwgwe", 1232);
268
+
MapLookup.put("gwswo", 1233);
269
+
MapLookup.put("gssge", 1234);
270
+
MapLookup.put("wgggn", 1235);
271
+
MapLookup.put("swwgn", 1236);
272
+
MapLookup.put("ssgwn", 1237);
273
+
MapLookup.put("sssgn", 1238);
274
+
MapLookup.put("swwgo", 1239);
275
+
MapLookup.put("gsswe", 1240);
276
+
MapLookup.put("wsswe", 1241);
277
+
MapLookup.put("sswgn", 1242);
278
+
279
+
this.player = player;
280
+
}
281
+
282
+
public static final String Name = "\uF809\uEff3\uF80B\uF80B\uF80A\uF809\uF806";
283
+
284
+
public char getLetterOfBiome(Block block)
285
+
{
286
+
Material highestBlockType = block.getWorld().getBlockAt(block.getX(), block.getWorld().getHighestBlockYAt(block.getLocation()), block.getZ()).getType();
287
+
if(highestBlockType == Material.WATER || highestBlockType == Material.ICE || highestBlockType == Material.PACKED_ICE) {
288
+
return 'w';
289
+
} else if(highestBlockType == Material.SAND) {
290
+
return 's';
291
+
}
292
+
293
+
Biome biome = block.getBiome();
294
+
295
+
Biome[] waterBiomes = new Biome[] {Biome.RIVER, Biome.FROZEN_RIVER, Biome.WARM_OCEAN, Biome.LUKEWARM_OCEAN, Biome.DEEP_LUKEWARM_OCEAN, Biome.OCEAN, Biome.DEEP_OCEAN, Biome.COLD_OCEAN, Biome.DEEP_COLD_OCEAN, Biome.FROZEN_OCEAN, Biome.DEEP_FROZEN_OCEAN};
296
+
Biome[] sandBiomes = new Biome[] {Biome.BADLANDS, Biome.DESERT, Biome.ERODED_BADLANDS, Biome.BEACH, Biome.SNOWY_BEACH};
297
+
298
+
if(Arrays.stream(waterBiomes).toList().contains(biome))
299
+
{
300
+
return 'w';
301
+
}
302
+
303
+
if(Arrays.stream(sandBiomes).toList().contains(biome))
304
+
{
305
+
return 's';
306
+
}
307
+
308
+
return 'g';
309
+
}
310
+
311
+
public String getImageRepresentationOfChunk(Chunk chunk)
312
+
{
313
+
// Image pixels representation order
314
+
// 1 2
315
+
// 3 4
316
+
317
+
String representation = "";
318
+
319
+
representation += getLetterOfBiome(chunk.getBlock(12, 62, 12));
320
+
representation += getLetterOfBiome(chunk.getBlock(3, 62, 12));
321
+
representation += getLetterOfBiome(chunk.getBlock(12, 62, 3));
322
+
representation += getLetterOfBiome(chunk.getBlock(3, 62, 3));
323
+
324
+
if(PlayerChunk.getPlayerOwnsChunk(player, chunk))
325
+
{
326
+
representation += "o";
327
+
} else if(PlayerChunk.getChunkOwner(chunk) == null)
328
+
{
329
+
representation += "n";
330
+
} else {
331
+
representation += "e";
332
+
}
333
+
334
+
return representation;
335
+
}
336
+
337
+
public String getDirectionMarker() {
338
+
double rotation = (player.getLocation().getYaw() - 90.0F) % 360.0F;
339
+
if (rotation < 0.0D) {
340
+
rotation += 360.0D;
341
+
}
342
+
if ((0.0D <= rotation) && (rotation < 22.5D)) {
343
+
return "\ueff6";
344
+
}
345
+
if ((22.5D <= rotation) && (rotation < 67.5D)) {
346
+
return "\ueff7";
347
+
}
348
+
if ((67.5D <= rotation) && (rotation < 112.5D)) {
349
+
return "\ueff8";
350
+
}
351
+
if ((112.5D <= rotation) && (rotation < 157.5D)) {
352
+
return "\ueff9";
353
+
}
354
+
if ((157.5D <= rotation) && (rotation < 202.5D)) {
355
+
return "\ueffa";
356
+
}
357
+
if ((202.5D <= rotation) && (rotation < 247.5D)) {
358
+
return "\ueffb";
359
+
}
360
+
if ((247.5D <= rotation) && (rotation < 292.5D)) {
361
+
return "\ueff4";
362
+
}
363
+
if ((292.5D <= rotation) && (rotation < 337.5D)) {
364
+
return "\ueff5";
365
+
}
366
+
if ((337.5D <= rotation) && (rotation < 360.0D)) {
367
+
return "\ueff6";
368
+
}
369
+
return null;
370
+
}
371
+
372
+
private Vector2i getClaimPower() {
373
+
try {
374
+
Connection connection = DatabaseConnector.getConnection();
375
+
Statement statement = connection.createStatement();
376
+
377
+
String userQuery = "SELECT id FROM user WHERE uuid = \"" + player.getUniqueId() + "\"";
378
+
ResultSet userResultSet = statement.executeQuery(userQuery);
379
+
380
+
if(!userResultSet.next()) {
381
+
userResultSet.close();
382
+
statement.close();
383
+
connection.close();
384
+
return new Vector2i(0, 0);
385
+
}
386
+
387
+
int userId = userResultSet.getInt("id");
388
+
389
+
ResultSet claimPowerResultSet = statement.executeQuery("SELECT claim_power FROM user WHERE id = " + userId);
390
+
391
+
claimPowerResultSet.next();
392
+
393
+
int claimPower = claimPowerResultSet.getInt("claim_power");
394
+
395
+
claimPowerResultSet.close();
396
+
397
+
claimPowerResultSet = statement.executeQuery("SELECT COUNT(id) as count FROM `claim` WHERE user_id = " + userId);
398
+
claimPowerResultSet.next();
399
+
400
+
return new Vector2i(claimPowerResultSet.getInt("count"), claimPower);
401
+
} catch (SQLException e) {
402
+
Bukkit.getServer().broadcast(Component.text("Fatal Database Error: " + e.getMessage()).color(NamedTextColor.RED));
403
+
}
404
+
405
+
return new Vector2i(0, 0);
406
+
}
407
+
408
+
@Override
409
+
@NotNull
410
+
public Inventory getInventory() {
411
+
// eff4
412
+
// effb
413
+
414
+
Vector2i claimPower = getClaimPower();
415
+
416
+
Inventory mapInventory = Bukkit.createInventory(this, 54, Component.text(Name + getDirectionMarker()).color(NamedTextColor.WHITE).append(Component.text(" Power " + claimPower.x + "/" + claimPower.y).color(NamedTextColor.BLACK)));
417
+
418
+
for(int i = 0; i < 54; i++)
419
+
{
420
+
int x = i % 9 - 4;
421
+
int y = i / 9 - 3;
422
+
423
+
int playerChunkX = player.getChunk().getX();
424
+
int playerChunkY = player.getChunk().getZ();
425
+
426
+
int chunkX = playerChunkX - x;
427
+
int chunkY = playerChunkY - y;
428
+
429
+
int chunkWorldX = chunkX * 16;
430
+
int chunkWorldY = chunkY * 16;
431
+
432
+
Chunk chunk = player.getWorld().getChunkAt(new Location(player.getWorld(), chunkWorldX, 0, chunkWorldY));
433
+
434
+
String stringRepresentation = getImageRepresentationOfChunk(chunk);
435
+
int representation = MapLookup.get(stringRepresentation);
436
+
437
+
ItemStack mapItem = new ItemStack(Material.MAP);
438
+
ItemMeta mapItemMeta = mapItem.getItemMeta();
439
+
mapItemMeta.setCustomModelData(representation);
440
+
441
+
List<Component> lore = new ArrayList<>();
442
+
443
+
lore.add(Component.text("Biome: ").append(Component.translatable(chunk.getBlock(0, 0, 0).getBiome().translationKey())));
444
+
lore.add(Component.text("ChunkX: " + chunkX + ", ChunkZ: " + chunkY));
445
+
lore.add(Component.text("WorldX: " + chunkWorldX + ", WorldZ: " + chunkWorldY));
446
+
447
+
switch (stringRepresentation.charAt(stringRepresentation.length() - 1)) {
448
+
case 'n' -> mapItemMeta.displayName(Component.text("Click to claim!").color(NamedTextColor.YELLOW));
449
+
case 'o' -> {
450
+
mapItemMeta.displayName(Component.text("You own this chunk").color(NamedTextColor.AQUA));
451
+
lore.add(0, Component.text("Click to modify").color(NamedTextColor.YELLOW));
452
+
}
453
+
case 'e' -> mapItemMeta.displayName(Component.text(PlayerChunk.getChunkOwner(chunk) + "'s chunk").color(NamedTextColor.RED));
454
+
}
455
+
456
+
if(i == 31)
457
+
{
458
+
lore.add(0, Component.text("You are here!").color(NamedTextColor.RED));
459
+
}
460
+
461
+
mapItemMeta.lore(lore);
462
+
mapItem.setItemMeta(mapItemMeta);
463
+
mapInventory.setItem(i, mapItem);
464
+
}
465
+
466
+
return mapInventory;
467
+
}
468
+
}
+58
src/main/java/dev/keii/keiichunks/inventories/InventoryModifyChunk.java
+58
src/main/java/dev/keii/keiichunks/inventories/InventoryModifyChunk.java
···
1
+
package dev.keii.keiichunks.inventories;
2
+
3
+
import net.kyori.adventure.text.Component;
4
+
import net.kyori.adventure.text.format.NamedTextColor;
5
+
import org.bukkit.Bukkit;
6
+
import org.bukkit.Material;
7
+
import org.bukkit.inventory.Inventory;
8
+
import org.bukkit.inventory.InventoryHolder;
9
+
import org.bukkit.inventory.ItemStack;
10
+
import org.bukkit.inventory.meta.ItemMeta;
11
+
import org.jetbrains.annotations.NotNull;
12
+
13
+
public class InventoryModifyChunk implements InventoryHolder {
14
+
15
+
public static final Component Name = Component.text("\uF805\uEffc\uF80A\uF806\uF80C\uF822").color(NamedTextColor.WHITE);
16
+
17
+
private ItemStack createGuiItem(String name)
18
+
{
19
+
ItemStack item = new ItemStack(Material.STICK);
20
+
ItemMeta meta = item.getItemMeta();
21
+
meta.setCustomModelData(1000);
22
+
meta.displayName(Component.text(name));
23
+
item.setItemMeta(meta);
24
+
return item;
25
+
}
26
+
27
+
@Override
28
+
@NotNull
29
+
public Inventory getInventory()
30
+
{
31
+
Inventory inventory = Bukkit.createInventory(this, 27, Name);
32
+
33
+
for(int i = 0; i < 27; i++)
34
+
{
35
+
int slot = i;
36
+
if(slot > 17)
37
+
{
38
+
slot -= 9;
39
+
}
40
+
if(slot > 8)
41
+
{
42
+
slot -= 9;
43
+
}
44
+
45
+
if(slot > 5)
46
+
{
47
+
inventory.setItem(i, createGuiItem("Unclaim"));
48
+
} else if(slot > 2)
49
+
{
50
+
inventory.setItem(i, createGuiItem("Toggle TNT"));
51
+
} else {
52
+
inventory.setItem(i, createGuiItem("Modify Permissions"));
53
+
}
54
+
}
55
+
56
+
return inventory;
57
+
}
58
+
}
+75
src/main/java/dev/keii/keiichunks/inventories/InventoryModifyChunkPermission.java
+75
src/main/java/dev/keii/keiichunks/inventories/InventoryModifyChunkPermission.java
···
1
+
package dev.keii.keiichunks.inventories;
2
+
3
+
import dev.keii.keiichunks.PlayerChunk;
4
+
import dev.keii.keiichunks.saveload.User;
5
+
import net.kyori.adventure.text.Component;
6
+
import net.kyori.adventure.text.format.NamedTextColor;
7
+
import org.bukkit.Bukkit;
8
+
import org.bukkit.Chunk;
9
+
import org.bukkit.Material;
10
+
import org.bukkit.inventory.Inventory;
11
+
import org.bukkit.inventory.InventoryHolder;
12
+
import org.bukkit.inventory.ItemStack;
13
+
import org.bukkit.inventory.meta.ItemMeta;
14
+
import org.jetbrains.annotations.NotNull;
15
+
16
+
import javax.annotation.Nullable;
17
+
import java.util.Map;
18
+
19
+
public class InventoryModifyChunkPermission implements InventoryHolder {
20
+
21
+
public static Component Name = Component.text("\uF805\uEffd\uF80B\uF80A\uF809\uF808\uF80A\uF808\uF806").color(NamedTextColor.WHITE);
22
+
23
+
@Nullable String uuid;
24
+
Chunk chunk;
25
+
26
+
public InventoryModifyChunkPermission(@Nullable String uuid, Chunk chunk)
27
+
{
28
+
this.chunk = chunk;
29
+
this.uuid = uuid;
30
+
}
31
+
32
+
33
+
@Override
34
+
public @NotNull Inventory getInventory()
35
+
{
36
+
Inventory inventory = Bukkit.createInventory(this, 27, Name.append(Component.text((uuid != null ? User.getNicknameFromUUID(uuid) : "Everyone") + "'s permissions").color(NamedTextColor.DARK_GRAY)));
37
+
38
+
if(uuid != null) {
39
+
Bukkit.getConsoleSender().sendMessage(Component.text(uuid));
40
+
}
41
+
Map<PlayerChunk.ChunkPermission, Boolean> perm = PlayerChunk.getChunkPermissionsForUser(uuid, chunk);
42
+
43
+
if(perm != null) {
44
+
for (var permission : perm.entrySet()) {
45
+
String permissionString = "";
46
+
// Bukkit.getServer().broadcastMessage(permission.getKey().toString());
47
+
switch (permission.getKey()) {
48
+
case Interact -> permissionString = "Interact";
49
+
case BlockBreak -> permissionString = "Block Break";
50
+
case BlockPlace -> permissionString = "Block Place";
51
+
case BucketFill -> permissionString = "Bucket Fill";
52
+
case BucketEmpty -> permissionString = "Bucket Empty";
53
+
}
54
+
55
+
ItemStack item = new ItemStack(Material.STICK);
56
+
ItemMeta meta = item.getItemMeta();
57
+
meta.setCustomModelData(permission.getValue() ? 1003 : 1004);
58
+
meta.displayName(Component.text((permission.getValue() ? "Disable " : "Enable ") + permissionString).color(NamedTextColor.YELLOW));
59
+
item.setItemMeta(meta);
60
+
inventory.addItem(item);
61
+
}
62
+
}
63
+
64
+
// 18 26
65
+
66
+
ItemStack item = new ItemStack(Material.STICK);
67
+
ItemMeta meta = item.getItemMeta();
68
+
meta.setCustomModelData(1005);
69
+
meta.displayName(Component.text("Back").color(NamedTextColor.YELLOW));
70
+
item.setItemMeta(meta);
71
+
inventory.setItem(18, item);
72
+
73
+
return inventory;
74
+
}
75
+
}
+22
src/main/java/dev/keii/keiichunks/saveload/Claim.java
+22
src/main/java/dev/keii/keiichunks/saveload/Claim.java
···
1
+
package dev.keii.keiichunks.saveload;
2
+
3
+
public class Claim {
4
+
public long id;
5
+
public long userId;
6
+
public long chunkX;
7
+
public long chunkZ;
8
+
public String createdAt;
9
+
public String updatedAt;
10
+
public boolean allowExplosions;
11
+
12
+
public Claim(long id, long userId, long chunkX, long chunkZ, String createdAt, String updatedAt, boolean allowExplosions)
13
+
{
14
+
this.id = id;
15
+
this.userId = userId;
16
+
this.chunkX = chunkX;
17
+
this.chunkZ = chunkZ;
18
+
this.createdAt = createdAt;
19
+
this.updatedAt = updatedAt;
20
+
this.allowExplosions = allowExplosions;
21
+
}
22
+
}
+27
src/main/java/dev/keii/keiichunks/saveload/ClaimPermission.java
+27
src/main/java/dev/keii/keiichunks/saveload/ClaimPermission.java
···
1
+
package dev.keii.keiichunks.saveload;
2
+
3
+
public class ClaimPermission {
4
+
public long id;
5
+
public long userId;
6
+
public long claimId;
7
+
public boolean blockBreak;
8
+
public boolean blockPlace;
9
+
public boolean bucketEmpty;
10
+
public boolean bucketFill;
11
+
public boolean interact;
12
+
public String createdAt;
13
+
public String updatedAt;
14
+
15
+
public ClaimPermission(long id, long userId, long claimId, boolean blockBreak, boolean blockPlace, boolean bucketEmpty, boolean bucketFill, boolean interact, String createdAt, String updatedAt)
16
+
{
17
+
this.id = id;
18
+
this.userId = userId;
19
+
this.claimId = claimId;
20
+
this.blockBreak = blockBreak;
21
+
this.bucketEmpty = bucketEmpty;
22
+
this.bucketFill = bucketFill;
23
+
this.interact = interact;
24
+
this.createdAt = createdAt;
25
+
this.updatedAt = updatedAt;
26
+
}
27
+
}
+114
src/main/java/dev/keii/keiichunks/saveload/User.java
+114
src/main/java/dev/keii/keiichunks/saveload/User.java
···
1
+
package dev.keii.keiichunks.saveload;
2
+
3
+
import dev.keii.keiichunks.DatabaseConnector;
4
+
5
+
import javax.annotation.Nullable;
6
+
import java.sql.Connection;
7
+
import java.sql.ResultSet;
8
+
import java.sql.SQLException;
9
+
import java.sql.Statement;
10
+
11
+
public class User {
12
+
public long id;
13
+
public String uuid;
14
+
public String timestamp;
15
+
public int claimPower;
16
+
17
+
public User(long id, String uuid, String timestamp, int claimPower)
18
+
{
19
+
this.id = id;
20
+
this.uuid = uuid;
21
+
this.timestamp = timestamp;
22
+
this.claimPower = claimPower;
23
+
}
24
+
25
+
@Nullable
26
+
public static String getUUIDFromID(int id)
27
+
{
28
+
try {
29
+
Connection connection = DatabaseConnector.getConnection();
30
+
Statement statement = connection.createStatement();
31
+
32
+
String sql = "SELECT * FROM user WHERE id = " + id;
33
+
ResultSet userResultSet = statement.executeQuery(sql);
34
+
35
+
if (!userResultSet.next()) {
36
+
userResultSet.close();
37
+
statement.close();
38
+
connection.close();
39
+
return null;
40
+
}
41
+
42
+
String uuid = userResultSet.getString("uuid");
43
+
44
+
userResultSet.close();
45
+
statement.close();
46
+
connection.close();
47
+
return uuid;
48
+
} catch (SQLException e) {
49
+
e.printStackTrace();
50
+
}
51
+
52
+
return null;
53
+
}
54
+
55
+
@Nullable
56
+
public static String getNicknameFromId(int id)
57
+
{
58
+
try {
59
+
Connection connection = DatabaseConnector.getConnection();
60
+
Statement statement = connection.createStatement();
61
+
62
+
String sql = "SELECT * FROM user WHERE id = " + id;
63
+
ResultSet userResultSet = statement.executeQuery(sql);
64
+
65
+
if (!userResultSet.next()) {
66
+
userResultSet.close();
67
+
statement.close();
68
+
connection.close();
69
+
return null;
70
+
}
71
+
72
+
String nickname = userResultSet.getString("nickname");
73
+
74
+
userResultSet.close();
75
+
statement.close();
76
+
connection.close();
77
+
return nickname;
78
+
} catch (SQLException e) {
79
+
e.printStackTrace();
80
+
}
81
+
82
+
return null;
83
+
}
84
+
85
+
@Nullable
86
+
public static String getNicknameFromUUID(String uuid)
87
+
{
88
+
try {
89
+
Connection connection = DatabaseConnector.getConnection();
90
+
Statement statement = connection.createStatement();
91
+
92
+
String sql = "SELECT * FROM user WHERE uuid = \"" + uuid + "\"";
93
+
ResultSet userResultSet = statement.executeQuery(sql);
94
+
95
+
if (!userResultSet.next()) {
96
+
userResultSet.close();
97
+
statement.close();
98
+
connection.close();
99
+
return null;
100
+
}
101
+
102
+
String nickname = userResultSet.getString("nickname");
103
+
104
+
userResultSet.close();
105
+
statement.close();
106
+
connection.close();
107
+
return nickname;
108
+
} catch (SQLException e) {
109
+
e.printStackTrace();
110
+
}
111
+
112
+
return null;
113
+
}
114
+
}
+18
src/main/resources/plugin.yml
+18
src/main/resources/plugin.yml
···
1
+
name: KeiiChunks
2
+
version: '${project.version}'
3
+
main: dev.keii.keiichunks.KeiiChunks
4
+
api-version: '1.20'
5
+
6
+
commands:
7
+
map:
8
+
description: Opens the map
9
+
usage: /map
10
+
permission: keii.map
11
+
# save:
12
+
# description: Saves claim data
13
+
# usage: /save
14
+
# permission: keii.save
15
+
# load:
16
+
# description: Saves load data
17
+
# usage: /load
18
+
# permission: keii.load