mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2025-11-24 21:36:12 +00:00
110
pom.xml
110
pom.xml
@@ -1,59 +1,53 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cn.CityCraft</groupId>
|
<groupId>cn.CityCraft</groupId>
|
||||||
<artifactId>RealBackpacks</artifactId>
|
<artifactId>RealBackpacks</artifactId>
|
||||||
<version>0.1.3-SNAPSHOT</version>
|
<version>0.1.3-SNAPSHOT</version>
|
||||||
<name>RealBackpacks</name>
|
<name>RealBackpacks</name>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src</directory>
|
<directory>src</directory>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/*.java</exclude>
|
<exclude>**/*.java</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.1</version>
|
<version>3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.7</source>
|
||||||
<target>1.7</target>
|
<target>1.7</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.8.3-R0.1-SNAPSHOT</version>
|
<version>1.8.3-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.CityCraft</groupId>
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
<artifactId>BVLib</artifactId>
|
<artifactId>VaultAPI</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>1.5</version>
|
||||||
<type>jar</type>
|
<scope>system</scope>
|
||||||
</dependency>
|
<systemPath>${project.basedir}/lib/Vault.jar</systemPath>
|
||||||
<dependency>
|
</dependency>
|
||||||
<groupId>net.milkbowl.vault</groupId>
|
</dependencies>
|
||||||
<artifactId>VaultAPI</artifactId>
|
<properties>
|
||||||
<version>1.5</version>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<scope>system</scope>
|
</properties>
|
||||||
<systemPath>${project.basedir}/lib/Vault.jar</systemPath>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
</project>
|
</project>
|
||||||
@@ -16,8 +16,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import cn.citycraft.Utils.config.FileConfig;
|
import cn.citycraft.plugins.config.FileConfig;
|
||||||
import cn.citycraft.Utils.config.PlayerConfig;
|
import cn.citycraft.plugins.config.PlayerConfig;
|
||||||
import cn.citycraft.plugins.util.MysqlFunctions;
|
import cn.citycraft.plugins.util.MysqlFunctions;
|
||||||
import cn.citycraft.plugins.util.RBUtil;
|
import cn.citycraft.plugins.util.RBUtil;
|
||||||
import cn.citycraft.plugins.util.Serialization;
|
import cn.citycraft.plugins.util.Serialization;
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import cn.citycraft.Utils.config.ConfigLoader;
|
|
||||||
import cn.citycraft.Utils.config.FileConfig;
|
|
||||||
|
|
||||||
public class Config extends ConfigLoader {
|
public class Config extends ConfigLoader {
|
||||||
private static String CONFIG_NAME = "config.yml";
|
private static String CONFIG_NAME = "config.yml";
|
||||||
|
|||||||
102
src/cn/citycraft/plugins/config/ConfigLoader.java
Normal file
102
src/cn/citycraft/plugins/config/ConfigLoader.java
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
package cn.citycraft.plugins.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class ConfigLoader extends FileConfig {
|
||||||
|
protected static FileConfig config;
|
||||||
|
protected static boolean tip = true;
|
||||||
|
protected static Plugin plugin;
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, File file) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, file, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, File file, boolean res) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, file, null, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, File file, String ver) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, file, ver, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, File file, String ver, boolean res) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, file, ver, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, String filename) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, new File(p.getDataFolder(), filename), null,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, String filename, boolean res) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, new File(p.getDataFolder(), filename), null, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, String filename, String ver) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigLoader(Plugin p, String filename, String ver, boolean res) {
|
||||||
|
ConfigLoader.plugin = p;
|
||||||
|
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfig getInstance() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) {
|
||||||
|
tip = res ;
|
||||||
|
if (!file.getParentFile().exists()) {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "...");
|
||||||
|
}
|
||||||
|
if (!file.exists()) {
|
||||||
|
fileCreate(p, file, res);
|
||||||
|
} else {
|
||||||
|
if (ver != null) {
|
||||||
|
FileConfig configcheck = init(file);
|
||||||
|
String version = configcheck.getString("version");
|
||||||
|
if (version == null || !version.equals(ver)) {
|
||||||
|
p.saveResource(file.getName(), true);
|
||||||
|
p.getLogger().warning(
|
||||||
|
"配置文件: " + file.getName() + " 版本过低 正在升级...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tip)
|
||||||
|
p.getLogger().info(
|
||||||
|
"载入配置文件: " + file.getName()
|
||||||
|
+ (ver != null ? " 版本: " + ver : ""));
|
||||||
|
return init(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fileCreate(Plugin p, File file, boolean res) {
|
||||||
|
if (res) {
|
||||||
|
p.saveResource(file.getName(), false);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "...");
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
p.getLogger().info("配置文件" + file.getName() + "创建失败...");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveError(File file) {
|
||||||
|
plugin.getLogger().info("配置文件" + file.getName() + "保存错误...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
88
src/cn/citycraft/plugins/config/FileConfig.java
Normal file
88
src/cn/citycraft/plugins/config/FileConfig.java
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package cn.citycraft.plugins.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.Configuration;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConstructor;
|
||||||
|
import org.bukkit.configuration.file.YamlRepresenter;
|
||||||
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of {@link Configuration} which saves all files in Yaml.
|
||||||
|
* Note that this implementation is not synchronized.
|
||||||
|
*/
|
||||||
|
public class FileConfig extends YamlConfiguration {
|
||||||
|
|
||||||
|
protected final DumperOptions yamlOptions = new DumperOptions();
|
||||||
|
protected final Representer yamlRepresenter = new YamlRepresenter();
|
||||||
|
protected final Yaml yaml = new Yaml(new YamlConstructor(),
|
||||||
|
yamlRepresenter, yamlOptions);
|
||||||
|
|
||||||
|
public static FileConfig init(File file) {
|
||||||
|
return FileConfig.loadConfiguration(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfig loadConfiguration(File file) {
|
||||||
|
Validate.notNull(file, "File cannot be null");
|
||||||
|
FileConfig config = new FileConfig();
|
||||||
|
try {
|
||||||
|
config.load(file);
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||||
|
} catch (InvalidConfigurationException ex) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String saveToString() {
|
||||||
|
yamlOptions.setIndent(options().indent());
|
||||||
|
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
String header = buildHeader();
|
||||||
|
String dump = yaml.dump(getValues(false));
|
||||||
|
if (dump.equals(BLANK_CONFIG)) {
|
||||||
|
dump = "";
|
||||||
|
}
|
||||||
|
return header + dump;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(File file) throws FileNotFoundException, IOException,
|
||||||
|
InvalidConfigurationException {
|
||||||
|
Validate.notNull(file, "File cannot be null");
|
||||||
|
final FileInputStream stream = new FileInputStream(file);
|
||||||
|
load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(File file) throws IOException {
|
||||||
|
Validate.notNull(file, "File cannot be null");
|
||||||
|
Files.createParentDirs(file);
|
||||||
|
String data = saveToString();
|
||||||
|
Writer writer = new OutputStreamWriter(new FileOutputStream(file),
|
||||||
|
Charsets.UTF_8);
|
||||||
|
try {
|
||||||
|
writer.write(data);
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/cn/citycraft/plugins/config/PlayerConfig.java
Normal file
48
src/cn/citycraft/plugins/config/PlayerConfig.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package cn.citycraft.plugins.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class PlayerConfig extends ConfigLoader {
|
||||||
|
private static String CONFIG_FOLDER = "userdate";
|
||||||
|
private static FileConfig instance;
|
||||||
|
private static File file;
|
||||||
|
|
||||||
|
public PlayerConfig(Plugin p, String player) {
|
||||||
|
super(p, CONFIG_FOLDER + File.separator + player + ".yml", false);
|
||||||
|
file = new File(p.getDataFolder(), CONFIG_FOLDER + File.separator
|
||||||
|
+ player + ".yml");
|
||||||
|
instance = super.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfig getInstance(Plugin p, Player player) {
|
||||||
|
new PlayerConfig(p, player.getName());
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfig getInstance(Plugin p, String player) {
|
||||||
|
new PlayerConfig(p, player);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMessage(String path) {
|
||||||
|
String message = instance.getString(path).replaceAll("&", "§");
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getStringArray(String path) {
|
||||||
|
return instance.getStringList(path).toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void save() {
|
||||||
|
try {
|
||||||
|
instance.save(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
saveError(file);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,8 +14,8 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import cn.citycraft.Utils.config.PlayerConfig;
|
|
||||||
import cn.citycraft.plugins.RealBackpacks;
|
import cn.citycraft.plugins.RealBackpacks;
|
||||||
|
import cn.citycraft.plugins.config.PlayerConfig;
|
||||||
import cn.citycraft.plugins.util.MysqlFunctions;
|
import cn.citycraft.plugins.util.MysqlFunctions;
|
||||||
import cn.citycraft.plugins.util.RBUtil;
|
import cn.citycraft.plugins.util.RBUtil;
|
||||||
import cn.citycraft.plugins.util.Serialization;
|
import cn.citycraft.plugins.util.Serialization;
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import cn.citycraft.Utils.config.FileConfig;
|
|
||||||
import cn.citycraft.Utils.config.PlayerConfig;
|
|
||||||
import cn.citycraft.plugins.RealBackpacks;
|
import cn.citycraft.plugins.RealBackpacks;
|
||||||
|
import cn.citycraft.plugins.config.FileConfig;
|
||||||
|
import cn.citycraft.plugins.config.PlayerConfig;
|
||||||
import cn.citycraft.plugins.util.MysqlFunctions;
|
import cn.citycraft.plugins.util.MysqlFunctions;
|
||||||
import cn.citycraft.plugins.util.RBUtil;
|
import cn.citycraft.plugins.util.RBUtil;
|
||||||
import cn.citycraft.plugins.util.Serialization;
|
import cn.citycraft.plugins.util.Serialization;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import java.util.List;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import cn.citycraft.Utils.config.PlayerConfig;
|
|
||||||
import cn.citycraft.plugins.RealBackpacks;
|
import cn.citycraft.plugins.RealBackpacks;
|
||||||
|
import cn.citycraft.plugins.config.PlayerConfig;
|
||||||
|
|
||||||
public class RBUtil {
|
public class RBUtil {
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ import cn.citycraft.plugins.json.JSONObject;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Serialization {
|
public class Serialization {
|
||||||
|
public static String NullString = "|-空-|";
|
||||||
|
public static String SplitString = "|-分割-|";
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Map<String, Object> toMap(final JSONObject object) throws JSONException {
|
public static Map<String, Object> toMap(final JSONObject object) throws JSONException {
|
||||||
final Map<String, Object> map = new HashMap<String, Object>();
|
final Map<String, Object> map = new HashMap<String, Object>();
|
||||||
@@ -59,7 +60,7 @@ public class Serialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> stringToList(final String listString) {
|
public static List<String> stringToList(final String listString) {
|
||||||
return Arrays.asList(listString.split("<->"));
|
return Arrays.asList(listString.split(SplitString));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String listToString(final List<String> list) {
|
public static String listToString(final List<String> list) {
|
||||||
@@ -68,7 +69,7 @@ public class Serialization {
|
|||||||
if (newString == null) {
|
if (newString == null) {
|
||||||
newString = s;
|
newString = s;
|
||||||
} else {
|
} else {
|
||||||
newString = newString + "<->" + s;
|
newString = newString + SplitString + s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newString;
|
return newString;
|
||||||
@@ -82,7 +83,7 @@ public class Serialization {
|
|||||||
}
|
}
|
||||||
for (final ConfigurationSerializable cs : items) {
|
for (final ConfigurationSerializable cs : items) {
|
||||||
if (cs == null) {
|
if (cs == null) {
|
||||||
result.add("null");
|
result.add(NullString);
|
||||||
} else {
|
} else {
|
||||||
result.add(new JSONObject(serialize(cs)).toString());
|
result.add(new JSONObject(serialize(cs)).toString());
|
||||||
}
|
}
|
||||||
@@ -94,7 +95,7 @@ public class Serialization {
|
|||||||
final Inventory inv = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', name));
|
final Inventory inv = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', name));
|
||||||
final List<ItemStack> contents = new ArrayList<ItemStack>();
|
final List<ItemStack> contents = new ArrayList<ItemStack>();
|
||||||
for (final String piece : stringItems) {
|
for (final String piece : stringItems) {
|
||||||
if (piece.equalsIgnoreCase("null")) {
|
if (piece.equalsIgnoreCase(NullString)) {
|
||||||
contents.add(null);
|
contents.add(null);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user