Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# GemsEconomy
This is my public spigot plugin GemsEconomy.
If you are looking for the source for the expansion.
Go here: https://github.com/Xanium1/GemsEconomy-Expansion
# GemsEconomyR
Es una modificacion de GemsEconomy, actualizada a SpigotMC 1.21, asi como contar con algunos cambios en el manejo de la basae de datos.

Repositorio Original: https://github.com/Xanium1/GemsEconomy-Expansion

Spigot link: https://www.spigotmc.org/resources/gemseconomy.19655/
26 changes: 5 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<libs.dir>${project.basedir}${file.separator}libs</libs.dir>
<package.dir>${project.build.directory}</package.dir>
<package.name>${project.build.finalName}</package.name>
Expand All @@ -33,8 +33,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -76,23 +76,13 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>reserve-repo</id>
<url>https://dl.bintray.com/theneweconomy/java/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -107,12 +97,6 @@
<version>3.4.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>Reserve</artifactId>
<version>0.1.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
31 changes: 29 additions & 2 deletions src/main/java/me/xanium/gemseconomy/GemsEconomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void onEnable() {
initializeDataStore(getConfig().getString("storage"), true);

getServer().getPluginManager().registerEvents(new EconomyListener(), this);
getCommand("gemseconomy").setExecutor(new GemsEconomyCommand());
getCommand("balance").setExecutor(new BalanceCommand());
getCommand("baltop").setExecutor(new BalanceTopCommand());
getCommand("economy").setExecutor(new EconomyCommand());
Expand Down Expand Up @@ -143,6 +144,32 @@ public void onDisable() {
}
}

public void reloadLanguages() {
// TODO: Implement language reloading logic here
}

public void reloadConfiguration() {
// Reload config.yml
reloadConfig();

// Update settings
setDebug(getConfig().getBoolean("debug"));
setVault(getConfig().getBoolean("vault"));
setLogging(getConfig().getBoolean("transaction_log"));
setCheques(getConfig().getBoolean("cheque.enabled"));

// Re-initialize DataStore
if (getDataStore() != null) {
getDataStore().close();
}

// Clear old data
DataStorage.getMethods().clear();

// Re-initialize with new config
initializeDataStore(getConfig().getString("storage"), true);
}

public void initializeDataStore(String strategy, boolean load) {

DataStorage.getMethods().add(new YamlStorage(new File(getDataFolder(), "data.yml")));
Expand All @@ -156,7 +183,7 @@ public void initializeDataStore(String strategy, boolean load) {
} else {
UtilServer.consoleLog("§cNo valid storage method provided.");
UtilServer.consoleLog("§cCheck your files, then try again.");
getServer().getPluginManager().disablePlugin(this);
// getServer().getPluginManager().disablePlugin(this); // Don't disable plugin on fail
return;
}

Expand All @@ -173,7 +200,7 @@ public void initializeDataStore(String strategy, boolean load) {
UtilServer.consoleLog("§cCannot load initial data from DataStore.");
UtilServer.consoleLog("§cCheck your files, then try again.");
e.printStackTrace();
getServer().getPluginManager().disablePlugin(this);
// getServer().getPluginManager().disablePlugin(this); // Don't disable plugin on fail
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.xanium.gemseconomy.commands;

import me.xanium.gemseconomy.GemsEconomy;
import me.xanium.gemseconomy.utils.UtilString;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

public class GemsEconomyCommand implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("gemseconomy.command.reload")) {
sender.sendMessage(UtilString.colorize(GemsEconomy.getInstance().getConfig().getString("messages.no_permission")));
return true;
}

if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
GemsEconomy.getInstance().reloadConfiguration();
sender.sendMessage(UtilString.colorize("&aConfiguration and database connection reloaded!"));
return true;
}

sender.sendMessage(UtilString.colorize("&cUsage: /gemseconomy reload"));
return true;
}
}
18 changes: 17 additions & 1 deletion src/main/java/me/xanium/gemseconomy/data/MySQLStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,31 @@ public class MySQLStorage extends DataStorage {

public MySQLStorage(String host, int port, String database, String username, String password) {
super("MySQL", true);

// Sanitize host if it contains port
if (host.contains(":")) {
String[] split = host.split(":");
host = split[0];
try {
int parsedPort = Integer.parseInt(split[1]);
if (parsedPort > 0 && parsedPort < 65536) {
port = parsedPort;
}
} catch (NumberFormatException ignored) {}
}

hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?allowPublicKeyRetrieval=true&useSSL=false");
hikariConfig.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?allowPublicKeyRetrieval=true&useSSL=false&autoReconnect=true&verifyServerCertificate=false");
hikariConfig.setPassword(password);
hikariConfig.setUsername(username);
hikariConfig.setMaxLifetime(1500000);
hikariConfig.setConnectionTimeout(30000);
hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
hikariConfig.addDataSourceProperty("userServerPrepStmts", "true");
// Disable initialization fail fast to prevent plugin disable on startup connection failure
hikariConfig.setInitializationFailTimeout(-1);
}

private String getTablePrefix() {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/me/xanium/gemseconomy/nbt/NBTReflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ private static Class getCraftItemstack() {
@SuppressWarnings("rawtypes")
private static Object getNewNBTTag() {
try {
Class c = Class.forName("net.minecraft.server." + GemsEconomy.getInstance().getNmsVersion().getVersionString() + ".NBTTagCompound");
String version = GemsEconomy.getInstance().getNmsVersion().getVersionString();
Class c;
if (version.startsWith("v1_17") || version.startsWith("v1_18") || version.startsWith("v1_19") || version.startsWith("v1_20") || version.startsWith("v1_21")) {
c = Class.forName("net.minecraft.nbt.NBTTagCompound");
} else {
c = Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
}
return c.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/me/xanium/gemseconomy/nbt/NMSVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ public class NMSVersion {

public static final String V1_16_R3 = "v1_16_R3";

public static final String V1_17_R1 = "v1_17_R1";

public static final String V1_18_R1 = "v1_18_R1";

public static final String V1_18_R2 = "v1_18_R2";

public static final String V1_19_R1 = "v1_19_R1";

public static final String V1_19_R2 = "v1_19_R2";

public static final String V1_19_R3 = "v1_19_R3";

public static final String V1_20_R1 = "v1_20_R1";

public static final String V1_20_R2 = "v1_20_R2";

public static final String V1_20_R3 = "v1_20_R3";

public static final String V1_20_R4 = "v1_20_R4";

public static final String V1_21_R1 = "v1_21_R1";

private Map<Integer, String> versionMap;

private int versionID;
Expand Down Expand Up @@ -90,6 +112,17 @@ private void loadVersions() {
registerVersion(V1_16_R1);
registerVersion(V1_16_R2);
registerVersion(V1_16_R3);
registerVersion(V1_17_R1);
registerVersion(V1_18_R1);
registerVersion(V1_18_R2);
registerVersion(V1_19_R1);
registerVersion(V1_19_R2);
registerVersion(V1_19_R3);
registerVersion(V1_20_R1);
registerVersion(V1_20_R2);
registerVersion(V1_20_R3);
registerVersion(V1_20_R4);
registerVersion(V1_21_R1);
}

private void registerVersion(String string) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ author: Xanium
description: A multi-currency economy plugin for spigot servers!
website: https://www.spigotmc.org/resources/gemseconomy.19655/
load: STARTUP
api-version: 1.16
api-version: 1.21
loadbefore:
- ItemFrameShops
softdepend: [Vault]
commands:
gemseconomy:
description: Main command for GemsEconomy
usage: /gemseconomy reload
aliases: [ge, gems]
balance:
description: Shows your balances
usage: /balance (account)
Expand Down