classes and world gen, thinking of going with mw-core instead of doing own thing optimzed import also
This commit is contained in:
unurled 2022-02-25 19:57:15 +01:00
parent 60181f9fed
commit e6ea2a59cb
19 changed files with 271 additions and 24 deletions

View file

@ -42,6 +42,7 @@ repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
mavenCentral()
}
dependencies {
@ -52,9 +53,9 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
//mongo stuff
implementation 'org.mongodb:mongodb-driver-sync:4.4.0'
implementation 'org.mongodb:bson:4.4.0'
implementation 'org.mongodb:mongodb-driver-core:4.4.0'
implementation 'org.mongodb:mongodb-driver-sync:4.5.0'
implementation 'org.mongodb:bson:4.5.0'
implementation 'org.mongodb:mongodb-driver-core:4.5.0'
implementation 'de.tr7zw:item-nbt-api-plugin:2.9.0'
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
@ -62,14 +63,14 @@ dependencies {
compileOnly 'net.luckperms:api:5.3'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'net.essentialsx:EssentialsX:2.19.2'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.0.0-SNAPSHOT'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.0.0-SNAPSHOT'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.0.1'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.0.1'
compileOnly fileTree(dir: 'libs', include: '*.jar')
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.18.1-R0.1-SNAPSHOT")
}
group = 'gq.unurled'
version = '0.4.5'
version = '0.4.6'
description = 'Raxen'
java.sourceCompatibility = JavaVersion.VERSION_17

View file

@ -10,7 +10,6 @@ import gq.unurled.raxen.utils.Reload;
import gq.unurled.raxen.utils.Vault;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -21,7 +20,7 @@ public final class Raxen extends JavaPlugin {
private static final String prefix = ChatColor.AQUA + "Rx" + ChatColor.LIGHT_PURPLE + "> ";
@Getter
private static String version = "0.4.5";
private static String version = "0.4.6";
private final PluginManager pm = getServer().getPluginManager();
private static Raxen plugin;
@ -29,6 +28,7 @@ public final class Raxen extends JavaPlugin {
private static Logger logger;
private static Config config;
private static WorldManager worldManager;
@Getter
private static StorageManager storageManager;
@ -62,6 +62,7 @@ public final class Raxen extends JavaPlugin {
//Config and storage sruff
config = new Config(this);
worldManager = new WorldManager(this);
storageManager = new StorageManager(this);
//Managers

View file

@ -2,7 +2,6 @@ package gq.unurled.raxen.components.entity;
import gq.unurled.raxen.Raxen;
import org.bukkit.NamespacedKey;
import org.checkerframework.checker.units.qual.N;
public class EntityNamespacedKey {

View file

@ -14,7 +14,6 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static gq.unurled.raxen.utils.Items.*;

View file

@ -16,7 +16,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import static gq.unurled.raxen.utils.Items.setItemsToInventory;
import static gq.unurled.raxen.utils.Utils.debug;

View file

@ -1,4 +1,27 @@
package gq.unurled.raxen.components.player.classes;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import static gq.unurled.raxen.utils.Utils.color;
public class Class {
@Getter
String name;
@Getter
String colorName;
@Getter
String ID;
@Getter
ItemStack placeHolder;
public Class(String name, String colorName, String ID, String itemPlaceHolder) {
this.name = name;
this.ID = ID;
this.placeHolder = new ItemStack(Material.getMaterial(itemPlaceHolder));
this.placeHolder.getItemMeta().displayName(Component.text(color(colorName)));
}
}

View file

@ -0,0 +1,80 @@
package gq.unurled.raxen.components.player.classes;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.manager.PlayerManager;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import static gq.unurled.raxen.utils.Utils.debug;
import static gq.unurled.raxen.utils.Utils.error;
public class Classes {
private final Raxen main;
@Getter
private HashMap<String, Class> classes = new HashMap<>();
public Classes(Raxen main) {
this.main = main;
}
public void register() {
File folder = new File(main.getDataFolder() + "/Class/");
File[] listFile = folder.listFiles();
PlayerManager pm = main.getPlayerManager();
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isFile()) {
FileConfiguration customClass = new YamlConfiguration();
try {
customClass.load(listFile[i]);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
resultClass cla = registerClass(customClass);
pm.addClasses(cla.getClas(), cla.getId());
} else if (listFile[i].isDirectory()) {
for (int a = 0; a < listFile[i].listFiles().length; a++) {
if(listFile[i].listFiles()[a].isFile()) {
FileConfiguration customClass = new YamlConfiguration();
try {
customClass.load(listFile[i].listFiles()[a]);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
resultClass cla = registerClass(customClass);
pm.addClasses(cla.getClas(), cla.getId());
} else if (listFile[i].listFiles()[a].isDirectory()) {
error("Can't use more than 2 folder to get Class.yml");
}
}
}
}
}
public class resultClass {
@Getter
@Setter
public Class clas;
@Getter
@Setter
public String id;
public resultClass(Class clas, String id) {
this.clas = clas;
this.id = id;
}
}
public resultClass registerClass(FileConfiguration file) {
String id = file.getString("id");
debug(id);
return new resultClass(new Class(file.getString("name"), file.getString("color-name"), id, file.getString("item_placeholder")), id);
}
}

View file

@ -3,9 +3,9 @@ package gq.unurled.raxen.config;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.player.attributes.Attributes;
import gq.unurled.raxen.components.player.Inventories;
import gq.unurled.raxen.components.player.Storage;
import gq.unurled.raxen.components.player.attributes.Attributes;
import gq.unurled.raxen.components.player.storages.EnderChest;
import gq.unurled.raxen.manager.PlayerManager;
import gq.unurled.raxen.manager.StorageManager;

View file

@ -1,8 +1,8 @@
package gq.unurled.raxen.listener.entity;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.entity.EntityUtils;
import gq.unurled.raxen.components.entity.EntityNamespacedKey;
import gq.unurled.raxen.components.entity.EntityUtils;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View file

@ -6,7 +6,6 @@ import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@ -30,7 +29,7 @@ public class EntityManager {
}
public void registerEntityFromConfig(FileConfiguration file) {
debug(main, (String) file.get("id"));
debug(file.getString("id"));
World world = Bukkit.getWorld(file.getString("world"));
String name = file.getString("name");
}

View file

@ -100,7 +100,7 @@ public class ItemManager {
}
registerItem(customItem);
} else if (listFile[i].listFiles()[a].isDirectory()) {
error("Cann't use more than 2 folder to get Items.yml");
error("Can't use more than 2 folder to get Items.yml");
}
}
@ -109,7 +109,7 @@ public class ItemManager {
}
private void registerItem(FileConfiguration file) {
debug(main, (String) file.get("id"));
debug(file.getString("id"));
ItemStack it = new ItemStack(Material.getMaterial((String) file.get("id")));
ItemMeta itm = it.getItemMeta();
itm.displayName(Component.text(color((String) file.get("name"))));

View file

@ -1,8 +1,9 @@
package gq.unurled.raxen.manager;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.player.attributes.Attribute;
import gq.unurled.raxen.components.player.RaxenPlayer;
import gq.unurled.raxen.components.player.attributes.Attribute;
import gq.unurled.raxen.components.player.classes.Class;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -15,6 +16,7 @@ public class PlayerManager {
private Raxen main;
private HashMap<UUID, BukkitTask> actionBar = new HashMap<>();
private HashMap<String, Class> classes = new HashMap<>();
public PlayerManager(Raxen main) {
this.main = main;
@ -49,4 +51,25 @@ public class PlayerManager {
public void unRegisterRaxenPlayer(Player player) {
}
public void registerClasses() {
}
/**
* getClasses
* @return the classes HashMap
*/
public HashMap<String, Class> getClasses() {
return classes;
}
/**
* add @param to hashmap of classes
* @param clas a class instance
* @param id the id of the class
*/
public void addClasses(Class clas, String id) {
classes.put(id, clas);
}
}

View file

@ -97,4 +97,49 @@ public class StorageManager {
return customConfig;
}
public static FileConfiguration createYml(File file) {
FileConfiguration customConfig;
if (!file.exists()) {
file.getParentFile().mkdirs();
try {
file.createNewFile();
}
catch (IOException e) {
error("Error in Storage Manager saving new File.");
e.printStackTrace();
}
}
customConfig = new YamlConfiguration();
try {
customConfig.load(file);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
return customConfig;
}
public static FileConfiguration createYml(String path) {
File customFile;
FileConfiguration customConfig;
customFile = new File(path);
if (!customFile.exists()) {
customFile.getParentFile().mkdirs();
try {
customFile.createNewFile();
}
catch (IOException e) {
error("Error in Storage Manager saving new File.");
e.printStackTrace();
}
}
customConfig = new YamlConfiguration();
try {
customConfig.load(customFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
return customConfig;
}
}

View file

@ -0,0 +1,75 @@
package gq.unurled.raxen.manager;
import gq.unurled.raxen.Raxen;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public class WorldManager {
private Raxen main;
private static StorageManager sto;
@Getter
private HashMap<String, World> worlds = new HashMap<>();
public WorldManager(Raxen main) {
this.main = main;
this.sto = main.getStorageManager();
if(!(new File(main.getDataFolder() + "/Worlds/").exists())) {
new File(main.getDataFolder() + "/Worlds/").mkdirs();
}
}
public void save() {
String path = main.getDataFolder() + "/Worlds/";
File folder = new File(path);
List<World> worlds = Bukkit.getWorlds();
for (World world : worlds) {
File file = new File(path + world.getName() + ".yml");
FileConfiguration fileConf = sto.createYml(file);
fileConf.set("name", world.getName());
fileConf.set("uuid", world.getUID().toString());
try {
fileConf.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void saveWorld(String name) {
World world = Bukkit.getWorld(name);
UUID uuid = world.getUID();
String key = world.getKey().getKey();
File file = new File(main.getDataFolder() + "/Worlds/" + name + ".yml");
}
public void load() {
String path = main.getDataFolder() + "/Worlds/";
File folder = new File(path);
File[] listFile = folder.listFiles();
for (File file : listFile) {
loadWorld(file);
}
}
public World loadWorld(File file) {
FileConfiguration fileConf = sto.createYml(file);
World world = Bukkit.createWorld(new WorldCreator(fileConf.getString("name")));
worlds.put(world.getName(), world);
return world;
}
public World getWorld(String name) {
return Bukkit.getWorld(name);
}
}

View file

@ -1,14 +1,11 @@
package gq.unurled.raxen.utils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import de.tr7zw.nbtapi.NBTItem;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.items.Attributes;
import gq.unurled.raxen.components.items.NBT;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.*;

View file

@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.logging.Logger;
public class Utils {

View file

@ -1,7 +1,5 @@
package gq.unurled.raxen.utils;
import com.fastasyncworldedit.core.FaweAPI;
public class WorldEdit {
}

View file

@ -0,0 +1,5 @@
id: "SWORDSMANN"
name: "Swordsmann"
color-name: "&cSwordsmann"
item_placeholder: "DIAMOND_SWORD"
max_level: 10

View file

@ -0,0 +1,2 @@
name: "HALLO"
uuid: "uuid"