This commit is contained in:
tyuXX 2025-06-04 21:07:55 +03:00
parent 0311b5af22
commit 79098e3e24
41 changed files with 318 additions and 42 deletions

View file

@ -0,0 +1,18 @@
package org.gsdistance.grimmsServer.Commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.gsdistance.grimmsServer.Config.ConfigLoader;
import org.gsdistance.grimmsServer.GrimmsServer;
import java.util.logging.Level;
public class ReloadConfig implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
ConfigLoader.loadConfigFromFile();
GrimmsServer.logger.log(Level.INFO, "Config reloaded.");
return true;
}
}

View file

@ -0,0 +1,20 @@
package org.gsdistance.grimmsServer.Config;
import java.util.List;
public class ActiveConfig {
public static boolean module_Jobs = true;
public static boolean module_Factions = true;
public static boolean module_Market = true;
public static boolean module_Leaderboard = true;
public static String[] disabledCommands = new String[] {};
public static void updateConfig(boolean module_Jobs, boolean module_Factions,
boolean module_Market, boolean module_Leaderboard, List<String> disabledCommands) {
ActiveConfig.module_Jobs = module_Jobs;
ActiveConfig.module_Factions = module_Factions;
ActiveConfig.module_Market = module_Market;
ActiveConfig.module_Leaderboard = module_Leaderboard;
ActiveConfig.disabledCommands = disabledCommands.toArray(new String[0]);
}
}

View file

@ -0,0 +1,52 @@
package org.gsdistance.grimmsServer.Config;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.gsdistance.grimmsServer.GrimmsServer;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
public class ConfigLoader {
private static FileConfiguration config;
private static File configFile;
public static void initialize(JavaPlugin plugin) {
configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
plugin.saveDefaultConfig();
}
config = YamlConfiguration.loadConfiguration(configFile);
}
public static void loadConfigFromFile() {
if (config == null) return;
boolean module_Jobs = config.getBoolean("module_Jobs", true);
boolean module_Factions = config.getBoolean("module_Factions", true);
boolean module_Market = config.getBoolean("module_Market", true);
boolean module_Leaderboard = config.getBoolean("module_Leaderboard", true);
List<String> disabledCommands = config.getStringList("disabledCommands");
ActiveConfig.updateConfig(module_Jobs, module_Factions, module_Market, module_Leaderboard, disabledCommands);
}
public static void saveConfigFromActive() {
if (config == null) return;
config.set("module_Jobs", ActiveConfig.module_Jobs);
config.set("module_Factions", ActiveConfig.module_Factions);
config.set("module_Market", ActiveConfig.module_Market);
config.set("module_Leaderboard", ActiveConfig.module_Leaderboard);
config.set("disabledCommands", List.of(ActiveConfig.disabledCommands));
try {
config.save(configFile);
} catch (IOException e) {
GrimmsServer.logger.log(Level.WARNING, "Failed to save config file: " + e.getMessage());
}
}
}

View file

@ -0,0 +1,17 @@
package org.gsdistance.grimmsServer.Constructable;
import org.bukkit.Chunk;
import java.util.UUID;
public class WorldChunk {
public int x;
public int y;
public UUID factionUUID;
public WorldChunk(Chunk chunk, UUID factionUUID) {
this.x = chunk.getX();
this.y = chunk.getZ();
this.factionUUID = factionUUID;
}
}

View file

@ -1,28 +0,0 @@
package org.gsdistance.grimmsServer.Data;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.gsdistance.grimmsServer.GrimmsServer;
import java.io.File;
import java.util.logging.Logger;
public class Config {
public final JavaPlugin plugin;
public final Logger logger;
public final FileConfiguration config;
public Config(JavaPlugin plugin) {
this.plugin = plugin;
this.logger = plugin.getLogger();
this.config = plugin.getConfig();
}
public void saveConfig() {
try {
config.save(plugin.getDataFolder().getPath() + File.pathSeparatorChar + "config.yml");
} catch (Exception e) {
logger.warning("Failed to save config file");
logger.warning(e.getMessage());
}
}
}

View file

@ -5,7 +5,7 @@ import org.bukkit.enchantments.Enchantment;
import java.util.Map;
public class EnchantBaseValues {
public static final Map<Enchantment, Double> enchantBaseValues = Map.ofEntries(
public static Map<Enchantment, Double> enchantBaseValues = Map.ofEntries(
Map.entry(Enchantment.SHARPNESS, 3000.0),
Map.entry(Enchantment.EFFICIENCY, 3500.0),
Map.entry(Enchantment.KNOCKBACK, 2000.0),

View file

@ -5,7 +5,7 @@ import org.bukkit.Material;
import java.util.Map;
public class MarketBaseValues {
public static final Map<Material, Double> marketBaseValues = Map.ofEntries(
public static Map<Material, Double> marketBaseValues = Map.ofEntries(
Map.entry(Material.DRAGON_EGG, 250000.0),
Map.entry(Material.DIAMOND, 100.0),
Map.entry(Material.GOLD_INGOT, 50.0),

View file

@ -0,0 +1,12 @@
package org.gsdistance.grimmsServer.Data;
import java.util.Map;
public class ModuleRequirements {
public static final Map<String, String> CommandRequirements;
static {
CommandRequirements = Map.ofEntries(
Map.entry("","job")
);
}
}

View file

@ -33,6 +33,9 @@ public class PlayerTitleManager {
}
public static void checkForMoney(Player player) {
if(!PlayerStats.getPlayerStats(player).hasExactStat("money")){
return;
}
double money = (double) PlayerStats.getPlayerStats(player).getStat("money");
PlayerTitles playerTitles = PlayerTitles.getPlayerTitles(player);
if (money > 100000.0) {

View file

@ -27,7 +27,7 @@ public class PluginDataStorage {
}
public void saveData(Object object, Type objectType, String fileName, String addedPath) {
File writeFolder = new File(plugin.getDataFolder().getPath() + addedPath);
File writeFolder = new File(plugin.getDataFolder().getPath() + File.separatorChar + addedPath);
File writeFile = new File(writeFolder.getPath() + File.separatorChar + fileName);
if (!writeFolder.exists()) {
writeFolder.mkdir();

View file

@ -0,0 +1,15 @@
package org.gsdistance.grimmsServer.Events;
import org.gsdistance.grimmsServer.Constructable.WorldChunk;
import org.gsdistance.grimmsServer.Data.PluginDataStorage;
import org.gsdistance.grimmsServer.GrimmsServer;
public class ChunkLoadEvent {
public static void Event(org.bukkit.event.world.ChunkLoadEvent event) {
PluginDataStorage pluginDataStorage = new PluginDataStorage(GrimmsServer.instance);
if (event.isNewChunk()){
pluginDataStorage.saveData(new WorldChunk(event.getChunk(),null), WorldChunk.class, event.getChunk().getWorld().getName() + "_" + event.getChunk().getX() + "_" + event.getChunk().getZ() + ".json",
"chunks");
}
}
}

View file

@ -0,0 +1,16 @@
package org.gsdistance.grimmsServer.Events;
import org.gsdistance.grimmsServer.Manage.CommandRegistry;
import org.gsdistance.grimmsServer.GrimmsServer;
import java.util.logging.Level;
public class PlayerCommandPreprocessEvent {
public static void Event(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
String command = event.getMessage().split(" ")[0].substring(1); // Extract the command
if (!CommandRegistry.CanExecute(command)) {
event.setCancelled(true);
GrimmsServer.logger.log(Level.INFO, "Command interrupted: '" + event.getMessage() + "' by player: " + event.getPlayer().getName() + ". Command is disabled in the config.");
}
}
}

View file

@ -1,6 +1,6 @@
package org.gsdistance.grimmsServer.Events;
import org.gsdistance.grimmsServer.Commands.CommandRegistry;
import org.gsdistance.grimmsServer.Manage.CommandRegistry;
import org.gsdistance.grimmsServer.GrimmsServer;
import java.util.logging.Level;

View file

@ -1,9 +1,14 @@
package org.gsdistance.grimmsServer;
import org.bukkit.plugin.java.JavaPlugin;
import org.gsdistance.grimmsServer.Events.EventTrigger;
import org.gsdistance.grimmsServer.Config.ConfigLoader;
import org.gsdistance.grimmsServer.Manage.EventTrigger;
import org.gsdistance.grimmsServer.Events.ServerStartupEvent;
import java.io.*;
import java.util.Arrays;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
public final class GrimmsServer extends JavaPlugin {
@ -15,6 +20,9 @@ public final class GrimmsServer extends JavaPlugin {
// Plugin startup logic
instance = this;
logger = this.getLogger();
ConfigLoader.initialize(this);
ConfigLoader.loadConfigFromFile();
copyResourceFiles();
getServer().getPluginManager().registerEvents(new EventTrigger(), this);
ServerStartupEvent.Event();
}
@ -23,4 +31,86 @@ public final class GrimmsServer extends JavaPlugin {
public void onDisable() {
// Plugin shutdown logic
}
public void copyResourceFiles(){
// Check if version.embed exists
File versionEmbedFile = new File("" + getDataFolder() + File.separatorChar + "embed" + File.separatorChar + "version.embed");
if (versionEmbedFile.exists()){
boolean Do = false;
// Updated code
try (InputStream jarStream = getClass().getResourceAsStream("/embed/version.embed");
InputStream fileStream = new FileInputStream(versionEmbedFile)) {
if (jarStream != null) {
byte[] jarBytes = jarStream.readAllBytes();
byte[] fileBytes = fileStream.readAllBytes();
if (!Arrays.equals(jarBytes, fileBytes)) {
// Files are different, delete the embed folder
Do = true;
}
}
} catch (IOException e) {
logger.log(Level.WARNING, "Error comparing version.embed files", e);
}
if(Do){
File embedFolder = new File(getDataFolder(), "embed");
deleteDirectoryRecursively(embedFolder);
saveResourceIfNotExists("embed", true); // Copy the embed folder from the jar
logger.log(Level.INFO, "Updated embed folder from jar.");
}
}
else {
// If it does not exist, copy the embed folder from the jar
saveResourceIfNotExists("embed", true);
}
}
private void deleteDirectoryRecursively(File directory) {
if (directory.isDirectory()) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
deleteDirectoryRecursively(file);
}
}
}
directory.delete();
}
private void saveResourceIfNotExists(String resourcePath, boolean isDirectory) {
File targetFile = new File(getDataFolder(), resourcePath);
if (!targetFile.exists()) {
if (isDirectory) {
targetFile.mkdirs();
try {
String jarPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
try (JarFile jarFile = new JarFile(jarPath)) {
jarFile.stream()
.filter(entry -> entry.getName().startsWith(resourcePath) && !entry.isDirectory())
.forEach(entry -> {
String relativePath = entry.getName().substring(resourcePath.length() + 1);
saveResourceIfNotExists(resourcePath + "/" + relativePath, false);
});
}
} catch (IOException e) {
logger.warning("Failed to copy directory: " + resourcePath);
e.printStackTrace();
}
} else {
try (InputStream in = getClass().getClassLoader().getResourceAsStream(resourcePath);
OutputStream out = new FileOutputStream(targetFile)) {
if (in == null) {
logger.warning("Resource not found: " + resourcePath);
return;
}
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
} catch (IOException e) {
logger.log(Level.WARNING, "Failed to copy file: " + resourcePath, e);
}
}
}
}
}

View file

@ -1,5 +1,7 @@
package org.gsdistance.grimmsServer.Commands;
package org.gsdistance.grimmsServer.Manage;
import org.gsdistance.grimmsServer.Commands.*;
import org.gsdistance.grimmsServer.Config.ActiveConfig;
import org.gsdistance.grimmsServer.GrimmsServer;
public class CommandRegistry {
@ -31,5 +33,15 @@ public class CommandRegistry {
GrimmsServer.instance.getCommand("acceptRequest").setExecutor(new AcceptRequest());
GrimmsServer.instance.getCommand("buyTp").setExecutor(new BuyTp());
GrimmsServer.instance.getCommand("removeTitle").setExecutor(new RemoveTitle());
GrimmsServer.instance.getCommand("reloadGrimmsConfig").setExecutor(new ReloadConfig());
}
public static boolean CanExecute(String command) {
for (String disabledCommand : ActiveConfig.disabledCommands) {
if (disabledCommand.equalsIgnoreCase(command)) {
return false;
}
}
return true;
}
}

View file

@ -1,4 +1,4 @@
package org.gsdistance.grimmsServer.Events;
package org.gsdistance.grimmsServer.Manage;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -8,6 +8,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.gsdistance.grimmsServer.Events.PlayerChatEvent;
import org.gsdistance.grimmsServer.Events.PlayerCommandPreprocessEvent;
public class EventTrigger implements Listener {
@EventHandler
@ -39,4 +41,12 @@ public class EventTrigger implements Listener {
public void onChatUse(AsyncPlayerChatEvent event) {
PlayerChatEvent.Event(event);
}
@EventHandler
public void onCommandUse(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
PlayerCommandPreprocessEvent.Event(event);
}
@EventHandler
public void onChunkLoad(org.bukkit.event.world.ChunkLoadEvent event) {
org.gsdistance.grimmsServer.Events.ChunkLoadEvent.Event(event);
}
}

View file

@ -96,10 +96,6 @@ public class PlayerStats {
return dataContainer.getOrDefault(new NamespacedKey(plugin, stat), type, 0);
}
public boolean hasStat(String stat) {
return dataContainer.has(new NamespacedKey(plugin, stat));
}
public boolean hasExactStat(String stat) {
return dataContainer.has(new NamespacedKey(plugin, stat), Stats.get(stat));
}

View file

@ -0,0 +1,6 @@
testValue: false
module_Jobs: true
module_Factions: true
module_Market: true
module_Leaderboard: true
disabledCommands: []

View file

@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 61,
"description": "Grimm's Server Built-In Data Pack"
}
}

View file

@ -0,0 +1 @@
Monke

View file

@ -0,0 +1 @@
0

View file

@ -1,7 +1,12 @@
name: GrimmsServer
author: Grimm&tyuXX
description: A spigot plugin made by Grimm and tyuXX, it adds player leveling, a market, money, and more.
website: www.gsdistance.org
prefix: Grimm
main: org.gsdistance.grimmsServer.GrimmsServer
version: ${version}
api-version: 1.16
api-version: 1.20
load: STARTUP
commands:
logSelfStats:
description: Displays the player's own stats including death count, money, and total kills.
@ -110,6 +115,10 @@ commands:
description: Faction commands
usage: /faction <command> <args>
permission: grimmsserver.faction
reloadGrimmsConfig:
description: Reloads the GrimmsServer configuration.
usage: /reloadGrimmsConfig
permission: grimmsserver.reloadConfig
permissions:
grimmsserver.logSelfStats:
description: Allows a player to log their own stats
@ -194,4 +203,7 @@ permissions:
default: true
grimmsserver.factionAdmin:
description: Allows a player to use faction admin commands
default: op
grimmsserver.reloadConfig:
description: Allows a player to reload the GrimmsServer configuration
default: op