Skip to content

Commit f408607

Browse files
committed
First Commit - not tested
0 parents  commit f408607

15 files changed

+627
-0
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BetterRanks.iml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>PAPER</platformType>
8+
<platformType>ADVENTURE</platformType>
9+
</autoDetectTypes>
10+
</configuration>
11+
</facet>
12+
</component>
13+
</module>

buildNumber.properties

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#maven.buildNumber.plugin properties file
2+
#Sat Sep 30 02:09:26 CEST 2023
3+
buildNumber=1

pom.xml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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>betterbox.mine.game</groupId>
8+
<artifactId>BetterRanks</artifactId>
9+
<version>1.3-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>BetterRanks</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>${java.version}</source>
27+
<target>${java.version}</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.18.2-R0.1-SNAPSHOT</version>
71+
<scope>provided</scope>
72+
</dependency>
73+
</dependencies>
74+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package betterbox.mine.game.betterranks;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.configuration.file.FileConfiguration;
5+
import org.bukkit.configuration.file.YamlConfiguration;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.util.UUID;
11+
12+
public final class BetterRanks extends JavaPlugin {
13+
14+
// Fields are made package-private or public to be accessible from the command handler
15+
File usersFile;
16+
PluginLogger pluginLogger;
17+
FileConfiguration usersConfig;
18+
DataManager dataManager;
19+
20+
@Override
21+
public void onEnable() {
22+
pluginLogger = new PluginLogger(this);
23+
dataManager = new DataManager(this, pluginLogger);
24+
25+
// Set the command executor to the new command handler class
26+
this.getCommand("br").setExecutor(new BetterRanksCommandHandler(this));
27+
pluginLogger.info("Plugin has been enabled!");
28+
29+
// Load the users.yml file relative to the plugins directory
30+
usersFile = new File(getDataFolder().getParentFile(), "GroupManager/worlds/world/users.yml");
31+
if (!usersFile.exists()) {
32+
try {
33+
usersFile.getParentFile().mkdirs();
34+
usersFile.createNewFile();
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
pluginLogger.severe("Could not create users.yml: " + e.getMessage());
38+
}
39+
}
40+
usersConfig = YamlConfiguration.loadConfiguration(usersFile);
41+
42+
// Load data from DataManager
43+
dataManager.reloadData();
44+
45+
// Schedule a repeating task for rank expiry check
46+
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::checkRankExpiry, 0L, 72000L);
47+
}
48+
49+
private void checkRankExpiry() {
50+
boolean updated = false;
51+
52+
for (String uuidStr : dataManager.getAllPlayerUUIDs()) {
53+
long expiryTime = dataManager.getExpiryTime(UUID.fromString(uuidStr));
54+
55+
if (expiryTime != -1 && System.currentTimeMillis() > expiryTime) {
56+
removePlayerRank(UUID.fromString(uuidStr));
57+
updated = true;
58+
}
59+
}
60+
61+
if (updated) {
62+
try {
63+
usersConfig.save(usersFile);
64+
} catch (IOException e) {
65+
pluginLogger.severe("BetterRanks: checkRankExpiry: "+e);
66+
}
67+
}
68+
}
69+
70+
void removePlayerRank(UUID playerUUID) {
71+
usersConfig.set("users." + playerUUID.toString() + ".group", "Player");
72+
dataManager.removePlayerData(playerUUID);
73+
pluginLogger.info("BetterRanks: removePlayerRank: Player " + playerUUID + " removed");
74+
try {
75+
usersConfig.save(usersFile);
76+
pluginLogger.info("Rank set successfully!");
77+
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manload");
78+
79+
} catch (IOException e) {
80+
pluginLogger.severe("BetterRanks: removePlayerRank: "+e);
81+
}
82+
}
83+
84+
void addPlayerRank(String playerName, String rank, int time, char timeUnit) {
85+
try {
86+
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + playerName + " " + rank);
87+
88+
// Get UUID from playerName
89+
UUID playerUUID = Bukkit.getPlayer(playerName).getUniqueId();
90+
91+
long expiryTime = System.currentTimeMillis();
92+
switch (timeUnit) {
93+
case 's':
94+
expiryTime += time * 1000L;
95+
break;
96+
case 'm':
97+
expiryTime += time * 60000L;
98+
break;
99+
case 'd':
100+
expiryTime += time * 86400000L;
101+
break;
102+
default:
103+
throw new IllegalArgumentException("Invalid time unit: " + timeUnit);
104+
}
105+
106+
// Set expiry time using UUID
107+
dataManager.setExpiryTime(playerUUID, expiryTime);
108+
pluginLogger.info("Rank added successfully for " + playerName);
109+
} catch (Exception e) {
110+
pluginLogger.severe("BetterRanks: addPlayerRank: " + e);
111+
}
112+
}
113+
114+
115+
@Override
116+
public void onDisable() {
117+
// Save the users file
118+
try {
119+
usersConfig.save(usersFile);
120+
} catch (IOException e) {
121+
e.printStackTrace();
122+
}
123+
124+
// Save data to DataManager
125+
dataManager.saveData();
126+
}
127+
}

0 commit comments

Comments
 (0)