3.0.0-SNAPSHOT-U10
Completed the ItemStack handling system
This commit is contained in:
parent
22c3fc4765
commit
950851584a
|
@ -13,7 +13,6 @@
|
|||
<module name="FactionsOne" />
|
||||
<module name="FactionsUUID" />
|
||||
<module name="LegacyFactions" />
|
||||
<module name="PluginAPI" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: junit:junit:4.12">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -6,6 +6,11 @@
|
|||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="ignoredFiles">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$/api-modules/PluginAPI/pom.xml" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
<module fileurl="file://$PROJECT_DIR$/api-modules/FactionsOne/FactionsOne.iml" filepath="$PROJECT_DIR$/api-modules/FactionsOne/FactionsOne.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/api-modules/FactionsUUID/FactionsUUID.iml" filepath="$PROJECT_DIR$/api-modules/FactionsUUID/FactionsUUID.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/api-modules/LegacyFactions/LegacyFactions.iml" filepath="$PROJECT_DIR$/api-modules/LegacyFactions/LegacyFactions.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/api-modules/PluginAPI/PluginAPI.iml" filepath="$PROJECT_DIR$/api-modules/PluginAPI/PluginAPI.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/custombosses.iml" filepath="$PROJECT_DIR$/custombosses.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.12.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>CustomBosses</artifactId>
|
||||
<groupId>net.aminecraftdev.custombosses</groupId>
|
||||
<version>3.0.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>PluginAPI</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,41 +0,0 @@
|
|||
package net.aminecraftdev.custombosses.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 03-Jun-18
|
||||
*/
|
||||
public class StringTest {
|
||||
|
||||
@Test
|
||||
public void testReplaceList() {
|
||||
List<String> list = new ArrayList<>(Arrays.asList("abcd {0}", "efg {1}", "hij {2}"));
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{0}", "123");
|
||||
replaceMap.put("{1}", "456");
|
||||
replaceMap.put("{2}", "789");
|
||||
|
||||
System.out.println(list);
|
||||
list.replaceAll(s -> replaceString(s, replaceMap));
|
||||
System.out.println(list);
|
||||
}
|
||||
|
||||
private String replaceString(String input, Map<String, String> replaceMap) {
|
||||
if(replaceMap == null) return input;
|
||||
|
||||
for(String replaceKey : replaceMap.keySet()) {
|
||||
if(input.contains(replaceKey)) {
|
||||
input = input.replace(replaceKey, replaceMap.get(replaceKey));
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="PluginAPI" />
|
||||
<orderEntry type="module" module-name="FactionHelper" />
|
||||
<orderEntry type="module" module-name="FactionsM" />
|
||||
<orderEntry type="module" module-name="FactionsOne" />
|
||||
|
|
|
@ -14,12 +14,6 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>PluginAPI</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>FactionHelper</artifactId>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.aminecraftdev.custombosses;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.managers.ItemStackManager;
|
||||
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
|
@ -7,12 +10,20 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
* @version 1.0.0
|
||||
* @since 06-Sep-17
|
||||
*/
|
||||
public class CustomBosses extends JavaPlugin {
|
||||
public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
|
||||
@Getter private ItemStackManager itemStackManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.itemStackManager = new ItemStackManager(this);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
this.itemStackManager.reload();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package net.aminecraftdev.custombosses.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.aminecraftdev.custombosses.utils.ILoadable;
|
||||
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||
import net.aminecraftdev.custombosses.utils.ISavable;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.ItemStackConverter;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.ItemStackFileHandler;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 03-Jun-18
|
||||
*/
|
||||
public class ItemStackManager implements ILoadable, ISavable, IReloadable {
|
||||
|
||||
@Getter private final ItemStackConverter itemStackConverter = new ItemStackConverter();
|
||||
|
||||
private Map<String, ItemStackHolder> itemStackHolders = new HashMap<>();
|
||||
private ItemStackFileHandler itemStackFileHandler;
|
||||
|
||||
public ItemStackManager(JavaPlugin javaPlugin) {
|
||||
File file = new File(javaPlugin.getDataFolder(), "items.json");
|
||||
|
||||
this.itemStackFileHandler = new ItemStackFileHandler(javaPlugin, file, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.itemStackHolders = this.itemStackFileHandler.loadFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
this.itemStackFileHandler.saveFile(this.itemStackHolders);
|
||||
}
|
||||
|
||||
public ItemStackHolder getItemStackHolder(String name) {
|
||||
return this.itemStackHolders.getOrDefault(name, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package net.aminecraftdev.custombosses.utils.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
|
@ -9,8 +7,8 @@ import java.io.File;
|
|||
*/
|
||||
public interface IFileHandler<ReturnObject> {
|
||||
|
||||
ReturnObject loadFile(File file);
|
||||
ReturnObject loadFile();
|
||||
|
||||
void saveFile(File file, ReturnObject returnObject);
|
||||
void saveFile(ReturnObject returnObject);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.aminecraftdev.custombosses.utils.itemstack;
|
||||
|
||||
import net.aminecraftdev.custombosses.utils.IConverter;
|
||||
import net.aminecraftdev.custombosses.utils.IReplaceableConverter;
|
||||
import net.aminecraftdev.custombosses.utils.StringUtils;
|
||||
import net.aminecraftdev.custombosses.utils.factory.NbtFactory;
|
||||
|
|
|
@ -4,8 +4,10 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import net.aminecraftdev.custombosses.utils.file.FileUtils;
|
||||
import net.aminecraftdev.custombosses.utils.file.IFileHandler;
|
||||
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
@ -27,10 +29,32 @@ public class ItemStackFileHandler implements IFileHandler<Map<String, ItemStackH
|
|||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
private final JavaPlugin javaPlugin;
|
||||
private final boolean saveResource;
|
||||
private final File file;
|
||||
|
||||
public ItemStackFileHandler(JavaPlugin javaPlugin, File file, boolean saveResource) {
|
||||
this.saveResource = saveResource;
|
||||
this.javaPlugin = javaPlugin;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ItemStackHolder> loadFile(File file) {
|
||||
public Map<String, ItemStackHolder> loadFile() {
|
||||
Map<String, ItemStackHolder> itemStackHolderMap = new HashMap<>();
|
||||
|
||||
if(!this.file.exists()) {
|
||||
if(this.saveResource) {
|
||||
String path = this.file.getName();
|
||||
|
||||
if(this.javaPlugin.getResource(path) != null) {
|
||||
this.javaPlugin.saveResource(path, false);
|
||||
}
|
||||
} else {
|
||||
FileUtils.get().createFile(this.file);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
FileReader fileReader = new FileReader(file);
|
||||
JsonObject jsonObject = GSON.fromJson(fileReader, JsonObject.class);
|
||||
|
@ -53,7 +77,7 @@ public class ItemStackFileHandler implements IFileHandler<Map<String, ItemStackH
|
|||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(File file, Map<String, ItemStackHolder> map) {
|
||||
public void saveFile(Map<String, ItemStackHolder> map) {
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(file);
|
||||
Type type = new TypeToken<Map<String, ItemStackHolder>>(){}.getType();
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -13,14 +13,13 @@
|
|||
<module>api-modules/FactionsM</module>
|
||||
<module>api-modules/FactionsOne</module>
|
||||
<module>api-modules/FactionsUUID</module>
|
||||
<module>api-modules/PluginAPI</module>
|
||||
<module>api-modules/LegacyFactions</module>
|
||||
<module>plugin-modules/Core</module>
|
||||
<module>plugin-modules/FactionHelper</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>3.0.0-SNAPSHOT-U9</plugin.version>
|
||||
<plugin.version>3.0.0-SNAPSHOT-U10</plugin.version>
|
||||
<plugin.name>CustomBosses</plugin.name>
|
||||
<plugin.main>net.aminecraftdev.custombosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
|
Loading…
Reference in New Issue