move src path...

Signed-off-by: 502647092 <jtb1@163.com>
master
502647092 2015-09-02 09:39:12 +08:00
parent 360553e25f
commit 81689c97eb
26 changed files with 3467 additions and 3589 deletions

View File

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>

11
pom.xml
View File

@ -1,19 +1,17 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.CityCraft</groupId>
<groupId>cn.citycraft</groupId>
<artifactId>RealBackpacks</artifactId>
<version>0.1.5-SNAPSHOT</version>
<version>0.1.5</version>
<name>RealBackpacks</name>
<build>
<finalName>${project.name}</finalName>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
@ -51,4 +49,5 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>支持数据库的MySQL插件...</description>
</project>

View File

@ -1,177 +0,0 @@
package cn.citycraft.RealBackpacks.util;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
public class MysqlFunctions {
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
public static void addBackpackData(final String playerName,
final String backpack, final List<String> invString)
throws SQLException {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()
+ "?"
+ "user="
+ plugin.getUser()
+ "&password="
+ plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager
.getConnection(url);
PreparedStatement statement = conn
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, playerName);
statement.setString(2, backpack);
final ResultSet res = statement.executeQuery();
PreparedStatement state = null;
if (res.next()) {
if (res.getInt(1) == 1) {
state = conn
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
state.setString(4, playerName);
state.setString(5, backpack);
} else {
state = conn
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
}
}
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static boolean checkIfTableExists(final String table) {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
state.close();
conn.close();
if (tables.next())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
return false;
}
public static void createTables() {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
public static void delete(final String playerName, final String backpack) {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()
+ "?"
+ "user="
+ plugin.getUser()
+ "&password="
+ plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager
.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static Inventory getBackpackInv(final String playerName,
final String backpack) throws SQLException {
Inventory returnInv = null;
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
state.setString(1, playerName);
state.setString(2, backpack);
final ResultSet res = state.executeQuery();
if (res.next()) {
final String invString = res.getString(1);
if (invString != null) {
returnInv = Serialization.toInventory(Serialization
.stringToList(invString), ChatColor
.translateAlternateColorCodes('&',
plugin.backpackData.get(backpack).get(3)),
Integer.parseInt(plugin.backpackData.get(backpack)
.get(0)));
} else {
returnInv = null;
}
}
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
return returnInv;
}
public static void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}

View File

@ -1,404 +1,325 @@
package cn.citycraft.RealBackpacks;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.config.FileConfig;
import cn.citycraft.RealBackpacks.config.PlayerConfig;
import cn.citycraft.RealBackpacks.util.MysqlFunctions;
import cn.citycraft.RealBackpacks.util.RBUtil;
import cn.citycraft.RealBackpacks.util.Serialization;
public class MainCommand implements CommandExecutor {
private final RealBackpacks plugin;
private boolean exist = false;
private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======",
"§4* §a查看可购买列表 §7/rb list ", "§4* §a购买背包 §7/rb buy <背包名称> ",
"§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>",
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>", "§4* §a数据转移至MySQL §7/rb filetomysql" };
public MainCommand(final RealBackpacks plugin) {
this.plugin = plugin;
}
@Override
@SuppressWarnings("deprecation")
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (cmd.getName().equalsIgnoreCase("rb")) {
if (args.length == 0) {
sender.sendMessage(helps);
}
if (args.length >= 1) {
final String command = args[0];
if (command.equalsIgnoreCase("reload")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.reload")) {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
return false;
}
final Long first = System.currentTimeMillis();
plugin.reloadConfig();
plugin.setupLists();
plugin.getServer().resetRecipes();
plugin.setup();
sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW
+ (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
return true;
} else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) {
if (!plugin.isUsingVault()) {
sender.sendMessage(ChatColor.RED + "当前命令无法使用,因为没有安装经济插件.");
return false;
}
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "控制台不能使用此命令.");
return false;
}
if (!(args.length == 2)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY
+ " /rb buy <backpack>");
return false;
}
String backpack = null;
backpack = RBUtil.stringToBackpack(args[1]);
if (backpack == null) {
sender.sendMessage("背包不存在.");
return false;
}
if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".buy")) {
sender.sendMessage("没有购买的权限.");
return false;
}
if (plugin.backpackData.get(backpack).get(13) != null
&& !plugin.backpackData.get(backpack).get(13).equals("true")) {
sender.sendMessage("不能被购买.");
return false;
}
final double price = Double.parseDouble(plugin.backpackData.get(backpack).get(
14));
if (RealBackpacks.econ.getBalance(sender.getName()) < price) {
sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包.");
return false;
}
final Player p = (Player) sender;
final Inventory inv = p.getInventory();
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
if (inv.firstEmpty() != -1) {
RealBackpacks.econ.withdrawPlayer(p.getName(), price);
if (plugin.backpackData.get(backpack).get(18) != null
&& plugin.backpackData.get(backpack).get(18)
.equalsIgnoreCase("true")) {
if (RealBackpacks.globalGlow
&& plugin.backpackData.get(backpack).get(17) != null
&& plugin.backpackData.get(backpack).get(17)
.equalsIgnoreCase("true")) {
inv.setItem(inv.firstEmpty(),
RealBackpacks.NMS.addGlow(backpackItem));
} else {
inv.setItem(inv.firstEmpty(), backpackItem);
}
} else {
if (RealBackpacks.globalGlow
&& plugin.backpackData.get(backpack).get(17) != null
&& plugin.backpackData.get(backpack).get(17)
.equalsIgnoreCase("true")) {
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
} else {
inv.addItem(backpackItem);
}
}
p.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price
+ ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
return true;
} else {
sender.sendMessage(ChatColor.RED + "你的背包是空的.");
return false;
}
} else if (command.equalsIgnoreCase("list")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.list")) {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
return false;
}
sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|"
+ ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN
+ " 价格 ");
sender.sendMessage(ChatColor.GOLD + "-----------------------------------");
if (plugin.isUsingPerms()) {
for (final String backpack : plugin.backpacks) {
final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy");
final List<String> key = plugin.backpackData.get(backpack);
if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true")
&& hasPerm) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.GREEN
+ Double.parseDouble(key.get(14)));
} else if (plugin.backpackData.get(backpack).get(13) != null
&& !plugin.backpackData.get(backpack).get(13)
.equalsIgnoreCase("true") && hasPerm) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
} else {
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买");
}
}
} else {
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (plugin.backpackData.get(backpack).get(13) != null
&& plugin.backpackData.get(backpack).get(13)
.equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.GREEN
+ Double.parseDouble(key.get(14)));
} else {
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
}
}
}
} else if (command.equalsIgnoreCase("give")) {
if (!(args.length == 3)) {
sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY
+ " /rb give <玩家> <背包名称>");
return false;
}
String backpack = null;
backpack = RBUtil.stringToBackpack(args[2]);
if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".give")) {
sender.sendMessage(ChatColor.RED + "没有足够的权限");
return false;
}
if (backpack == null) {
sender.sendMessage(ChatColor.RED + "背包不存在");
return false;
}
final Player other = plugin.getServer().getPlayer(args[1]);
if (other == null) {
sender.sendMessage(ChatColor.RED + "玩家不存在");
return false;
}
final Inventory inv = other.getInventory();
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
if (inv.firstEmpty() != -1) {
if (plugin.backpackData.get(backpack).get(18) != null
&& plugin.backpackData.get(backpack).get(18)
.equalsIgnoreCase("true")) {
if (RealBackpacks.globalGlow
&& plugin.backpackData.get(backpack).get(17) != null
&& plugin.backpackData.get(backpack).get(17)
.equalsIgnoreCase("true")) {
inv.setItem(inv.firstEmpty(),
RealBackpacks.NMS.addGlow(backpackItem));
} else {
inv.setItem(inv.firstEmpty(), backpackItem);
}
} else {
if (RealBackpacks.globalGlow
&& plugin.backpackData.get(backpack).get(17) != null
&& plugin.backpackData.get(backpack).get(17)
.equalsIgnoreCase("true")) {
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
} else {
inv.addItem(backpackItem);
}
}
other.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack
+ ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
return true;
} else {
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
return false;
}
} else if (command.equalsIgnoreCase("filetomysql")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql"))
return false;
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (!MysqlFunctions.checkIfTableExists("rb_data")) {
MysqlFunctions.createTables();
exist = false;
} else {
exist = true;
}
try {
final Connection conn = DriverManager.getConnection(
plugin.getUrl(), plugin.getUser(), plugin.getPass());
final File dir = new File(plugin.getDataFolder() + File.separator
+ "userdata");
int i = 0,times = 0;
final int files = dir.listFiles().length;
for (final File child : dir.listFiles()) {
final String player = child.getName().replace(".yml", "");
final FileConfig config = PlayerConfig.getInstance(plugin,
player);
i++;
PreparedStatement statement = null;
PreparedStatement state = null;
for (final String backpack : config.getConfigurationSection("")
.getKeys(false)) {
if (exist) {
statement = conn
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, player);
statement.setString(2, backpack);
final ResultSet res = statement.executeQuery();
if (res.next()) {
if (res.getInt(1) == 1) {
state = conn
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, player);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(config
.getStringList(backpack
+ ".Inventory")));
state.setString(4, player);
state.setString(5, backpack);
} else {
state = conn
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, player);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(config
.getStringList(backpack
+ ".Inventory")));
}
}
} else {
state = conn
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, player);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(config
.getStringList(backpack + ".Inventory")));
}
state.executeUpdate();
state.close();
}
if (i == 50) {
i = 0;
times++;
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50
+ "/" + files + " files have been transferred.");
}
}
conn.close();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "数据转换完成.");
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
} else if (command.equalsIgnoreCase("view")) {
if (!(args.length == 3)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY
+ " /rb view <player> <backpack>");
return false;
}
String backpack = null;
backpack = RBUtil.stringToBackpack(args[2]);
boolean fullview = false;
boolean restrictedview = false;
if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview")) {
fullview = true;
} else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview")) {
restrictedview = true;
}
if (plugin.isUsingPerms() && !fullview && !restrictedview) {
sender.sendMessage(ChatColor.RED + "没有足够的权限购买");
return false;
}
if (backpack == null) {
sender.sendMessage(ChatColor.RED + "背包不存在");
return false;
}
Inventory inv = null;
String name = args[1];
final Player p = (Player) sender;
final List<String> key = plugin.backpackData.get(backpack);
if (!plugin.isUsingMysql()) {
boolean fileExists = false;
String fullName = null;
final File dir = new File(plugin.getDataFolder() + File.separator
+ "userdata");
for (final File f : dir.listFiles()) {
final String fileName = f.getName();
fullName = fileName.replace(".yml", "");
if (fullName.equalsIgnoreCase(name)) {
name = fullName;
fileExists = true;
break;
}
}
if (!fileExists) {
sender.sendMessage(ChatColor.RED + "这货从来没打开过背包,所以是空的,2333.");
return false;
}
final FileConfig config = PlayerConfig.getInstance(plugin, fullName);
if (config.getStringList(backpack + ".Inventory") == null) {
inv = plugin.getServer().createInventory(
p,
Integer.parseInt(key.get(0)),
ChatColor.translateAlternateColorCodes('&', fullName + "'s "
+ backpack + " data"));
} else {
inv = Serialization.toInventory(
config.getStringList(backpack + ".Inventory"), fullName + "'s "
+ backpack + " data", Integer.parseInt(key.get(0)));
}
} else {
try {
inv = MysqlFunctions.getBackpackInv(name, backpack);
} catch (final SQLException e1) {
e1.printStackTrace();
}
if (inv == null) {
sender.sendMessage(ChatColor.RED + "这货从来没打开过背包,所以是空的,2333.");
return false;
}
}
if (plugin.playerData.containsKey(name)) {
sender.sendMessage(ChatColor.RED + "玩家打开了背包,请等待玩家关闭.");
return false;
}
if (fullview || !plugin.isUsingPerms()) {
plugin.adminFullView.put(sender.getName(), backpack + ":" + name);
} else {
plugin.adminRestrictedView.add(sender.getName());
}
p.openInventory(inv);
} else {
sender.sendMessage(ChatColor.RED + "命令未找到.");
sender.sendMessage(helps);
}
}
}
return false;
}
}
package cn.citycraft.RealBackpacks;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.config.FileConfig;
import cn.citycraft.RealBackpacks.config.PlayerConfig;
import cn.citycraft.RealBackpacks.util.MysqlFunctions;
import cn.citycraft.RealBackpacks.util.RBUtil;
import cn.citycraft.RealBackpacks.util.Serialization;
public class MainCommand implements CommandExecutor {
private final RealBackpacks plugin;
private boolean exist = false;
private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======",
"§4* §a查看可购买列表 §7/rb list ",
"§4* §a购买背包 §7/rb buy <背包名称> ",
"§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>",
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>",
"§4* §a数据转移至MySQL §7/rb filetomysql" };
public MainCommand(final RealBackpacks plugin) {
this.plugin = plugin;
}
@Override
@SuppressWarnings("deprecation")
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (cmd.getName().equalsIgnoreCase("rb")) {
if (args.length == 0)
sender.sendMessage(helps);
if (args.length >= 1) {
final String command = args[0];
if (command.equalsIgnoreCase("reload")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.reload")) {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
return false;
}
final Long first = System.currentTimeMillis();
plugin.reloadConfig();
plugin.setupLists();
plugin.getServer().resetRecipes();
plugin.setup();
sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW + (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
return true;
} else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) {
if (!plugin.isUsingVault()) {
sender.sendMessage(ChatColor.RED + "当前命令无法使用,因为没有安装经济插件.");
return false;
}
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "控制台不能使用此命令.");
return false;
}
if (!(args.length == 2)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb buy <backpack>");
return false;
}
String backpack = null;
backpack = RBUtil.stringToBackpack(args[1]);
if (backpack == null) {
sender.sendMessage("背包不存在.");
return false;
}
if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".buy")) {
sender.sendMessage("没有购买的权限.");
return false;
}
if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equals("true")) {
sender.sendMessage("不能被购买.");
return false;
}
final double price = Double.parseDouble(plugin.backpackData.get(backpack).get(14));
if (RealBackpacks.econ.getBalance(sender.getName()) < price) {
sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包.");
return false;
}
final Player p = (Player) sender;
final Inventory inv = p.getInventory();
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
if (inv.firstEmpty() != -1) {
RealBackpacks.econ.withdrawPlayer(p.getName(), price);
if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
else
inv.setItem(inv.firstEmpty(), backpackItem);
} else if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
else
inv.addItem(backpackItem);
p.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price + ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
return true;
} else {
sender.sendMessage(ChatColor.RED + "你的背包是空的.");
return false;
}
} else if (command.equalsIgnoreCase("list")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.list")) {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
return false;
}
sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|" + ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN + " 价格 ");
sender.sendMessage(ChatColor.GOLD + "-----------------------------------");
if (plugin.isUsingPerms())
for (final String backpack : plugin.backpacks) {
final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy");
final List<String> key = plugin.backpackData.get(backpack);
if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm)
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
+ Double.parseDouble(key.get(14)));
else if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm)
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
else
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买");
}
else
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (plugin.backpackData.get(backpack).get(13) != null && plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true"))
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
+ Double.parseDouble(key.get(14)));
else
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
}
} else if (command.equalsIgnoreCase("give")) {
if (!(args.length == 3)) {
sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY + " /rb give <玩家> <背包名称>");
return false;
}
String backpack = null;
backpack = RBUtil.stringToBackpack(args[2]);
if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".give")) {
sender.sendMessage(ChatColor.RED + "没有足够的权限");
return false;
}
if (backpack == null) {
sender.sendMessage(ChatColor.RED + "背包不存在");
return false;
}
final Player other = plugin.getServer().getPlayer(args[1]);
if (other == null) {
sender.sendMessage(ChatColor.RED + "玩家不存在");
return false;
}
final Inventory inv = other.getInventory();
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
if (inv.firstEmpty() != -1) {
if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
else
inv.setItem(inv.firstEmpty(), backpackItem);
} else if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
else
inv.addItem(backpackItem);
other.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack + ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
return true;
} else {
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
return false;
}
} else if (command.equalsIgnoreCase("filetomysql")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql"))
return false;
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (!MysqlFunctions.checkIfTableExists("rb_data")) {
MysqlFunctions.createTables();
exist = false;
} else
exist = true;
try {
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
int i = 0, times = 0;
final int files = dir.listFiles().length;
for (final File child : dir.listFiles()) {
final String player = child.getName().replace(".yml", "");
final FileConfig config = PlayerConfig.getInstance(plugin, player);
i++;
PreparedStatement statement = null;
PreparedStatement state = null;
for (final String backpack : config.getConfigurationSection("").getKeys(false)) {
if (exist) {
statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, player);
statement.setString(2, backpack);
final ResultSet res = statement.executeQuery();
if (res.next())
if (res.getInt(1) == 1) {
state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, player);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
state.setString(4, player);
state.setString(5, backpack);
} else {
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, player);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
}
} else {
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, player);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
}
if (state != null) {
state.executeUpdate();
state.close();
}
}
if (i == 50) {
i = 0;
times++;
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50 + "/" + files + " files have been transferred.");
}
}
conn.close();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "数据转换完成.");
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
} else if (command.equalsIgnoreCase("view")) {
if (!(args.length == 3)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb view <player> <backpack>");
return false;
}
String backpack = null;
backpack = RBUtil.stringToBackpack(args[2]);
boolean fullview = false;
boolean restrictedview = false;
if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview"))
fullview = true;
else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview"))
restrictedview = true;
if (plugin.isUsingPerms() && !fullview && !restrictedview) {
sender.sendMessage(ChatColor.RED + "没有足够的权限购买");
return false;
}
if (backpack == null) {
sender.sendMessage(ChatColor.RED + "背包不存在");
return false;
}
Inventory inv = null;
String name = args[1];
final Player p = (Player) sender;
final List<String> key = plugin.backpackData.get(backpack);
if (!plugin.isUsingMysql()) {
boolean fileExists = false;
String fullName = null;
final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
for (final File f : dir.listFiles()) {
final String fileName = f.getName();
fullName = fileName.replace(".yml", "");
if (fullName.equalsIgnoreCase(name)) {
name = fullName;
fileExists = true;
break;
}
}
if (!fileExists) {
sender.sendMessage(ChatColor.RED + "这货从来没打开过背包,所以是空的,2333.");
return false;
}
final FileConfig config = PlayerConfig.getInstance(plugin, fullName);
if (config.getStringList(backpack + ".Inventory") == null)
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', fullName + "'s " + backpack + " data"));
else
inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), fullName + "'s " + backpack + " data", Integer.parseInt(key.get(0)));
} else {
try {
inv = MysqlFunctions.getBackpackInv(name, backpack);
} catch (final SQLException e1) {
e1.printStackTrace();
}
if (inv == null) {
sender.sendMessage(ChatColor.RED + "这货从来没打开过背包,所以是空的,2333.");
return false;
}
}
if (plugin.playerData.containsKey(name)) {
sender.sendMessage(ChatColor.RED + "玩家打开了背包,请等待玩家关闭.");
return false;
}
if (fullview || !plugin.isUsingPerms())
plugin.adminFullView.put(sender.getName(), backpack + ":" + name);
else
plugin.adminRestrictedView.add(sender.getName());
p.openInventory(inv);
} else {
sender.sendMessage(ChatColor.RED + "命令未找到.");
sender.sendMessage(helps);
}
}
}
return false;
}
}

View File

@ -1,14 +1,14 @@
package cn.citycraft.RealBackpacks;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public interface RBInterface {
public String inventoryToString(Inventory inventory);
public Inventory stringToInventory(String data, String name);
public ItemStack addGlow(ItemStack item);
}
package cn.citycraft.RealBackpacks;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public interface RBInterface {
public String inventoryToString(Inventory inventory);
public Inventory stringToInventory(String data, String name);
public ItemStack addGlow(ItemStack item);
}

View File

@ -1,68 +1,68 @@
package cn.citycraft.RealBackpacks;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class WalkSpeedRunnable implements Runnable {
private RealBackpacks plugin;
public WalkSpeedRunnable(RealBackpacks plugin) {
this.plugin = plugin;
}
@Override
public void run() {
for (Player p : plugin.getServer().getOnlinePlayers()) {
final String name = p.getName();
if (plugin.slowedPlayers.contains(name)) {
return;
}
final Inventory inv = p.getInventory();
final List<String> backpackList = new ArrayList<String>();
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (key.get(8) != null && key.get(8).equalsIgnoreCase("true") && inv != null && inv.contains(plugin.backpackItems.get(backpack))) {
backpackList.add(backpack);
}
}
final int listsize = backpackList.size();
if (listsize > 0) {
float walkSpeedMultiplier = 0.0F;
if (listsize > 1) {
if (plugin.isAveraging()) {
float average = 0;
for (final String backpack : backpackList) {
average += Float.parseFloat(plugin.backpackData.get(backpack).get(9));
}
walkSpeedMultiplier = average / listsize;
} else {
if (plugin.isAdding()) {
float sum = 0;
for (final String backpack : backpackList) {
sum += 0.2F - Float.parseFloat(plugin.backpackData.get(backpack).get(9));
}
walkSpeedMultiplier = 0.2F - sum;
} else {
final List<Float> floatList = new ArrayList<Float>();
for (final String backpack : backpackList) {
floatList.add(Float.parseFloat(plugin.backpackData.get(backpack).get(9)));
}
walkSpeedMultiplier = Collections.max(floatList);
}
}
} else {
if (listsize == 1) {
walkSpeedMultiplier = Float.parseFloat(plugin.backpackData.get(backpackList.get(0)).get(9));
}
}
plugin.slowedPlayers.add(name);
p.setWalkSpeed(walkSpeedMultiplier);
}
}
}
}
package cn.citycraft.RealBackpacks;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class WalkSpeedRunnable implements Runnable {
private RealBackpacks plugin;
public WalkSpeedRunnable(RealBackpacks plugin) {
this.plugin = plugin;
}
@Override
public void run() {
for (Player p : plugin.getServer().getOnlinePlayers()) {
final String name = p.getName();
if (plugin.slowedPlayers.contains(name)) {
return;
}
final Inventory inv = p.getInventory();
final List<String> backpackList = new ArrayList<String>();
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (key.get(8) != null && key.get(8).equalsIgnoreCase("true") && inv != null && inv.contains(plugin.backpackItems.get(backpack))) {
backpackList.add(backpack);
}
}
final int listsize = backpackList.size();
if (listsize > 0) {
float walkSpeedMultiplier = 0.0F;
if (listsize > 1) {
if (plugin.isAveraging()) {
float average = 0;
for (final String backpack : backpackList) {
average += Float.parseFloat(plugin.backpackData.get(backpack).get(9));
}
walkSpeedMultiplier = average / listsize;
} else {
if (plugin.isAdding()) {
float sum = 0;
for (final String backpack : backpackList) {
sum += 0.2F - Float.parseFloat(plugin.backpackData.get(backpack).get(9));
}
walkSpeedMultiplier = 0.2F - sum;
} else {
final List<Float> floatList = new ArrayList<Float>();
for (final String backpack : backpackList) {
floatList.add(Float.parseFloat(plugin.backpackData.get(backpack).get(9)));
}
walkSpeedMultiplier = Collections.max(floatList);
}
}
} else {
if (listsize == 1) {
walkSpeedMultiplier = Float.parseFloat(plugin.backpackData.get(backpackList.get(0)).get(9));
}
}
plugin.slowedPlayers.add(name);
p.setWalkSpeed(walkSpeedMultiplier);
}
}
}
}

View File

@ -1,46 +1,46 @@
package cn.citycraft.RealBackpacks.config;
import java.io.File;
import java.io.IOException;
import org.bukkit.plugin.Plugin;
public class Config extends ConfigLoader {
private static String CONFIG_NAME = "config.yml";
private static FileConfig instance;
private static File file;
public Config(Plugin p) {
super(p, CONFIG_NAME);
file = new File(p.getDataFolder(), CONFIG_NAME);
instance = super.getInstance();
}
public static void load(Plugin p) {
new Config(p);
}
public static FileConfig getInstance() {
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();
}
}
}
package cn.citycraft.RealBackpacks.config;
import java.io.File;
import java.io.IOException;
import org.bukkit.plugin.Plugin;
public class Config extends ConfigLoader {
private static String CONFIG_NAME = "config.yml";
private static FileConfig instance;
private static File file;
public Config(Plugin p) {
super(p, CONFIG_NAME);
file = new File(p.getDataFolder(), CONFIG_NAME);
instance = super.getInstance();
}
public static void load(Plugin p) {
new Config(p);
}
public static FileConfig getInstance() {
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();
}
}
}

View File

@ -1,102 +1,102 @@
package cn.citycraft.RealBackpacks.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() + "保存错误...");
}
}
package cn.citycraft.RealBackpacks.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() + "保存错误...");
}
}

View File

@ -1,108 +1,108 @@
package cn.citycraft.RealBackpacks.config;
import java.io.BufferedReader;
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.Reader;
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 {
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;
}
protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
@Override
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));
}
@Override
public void load(Reader reader) throws IOException, InvalidConfigurationException {
BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader
: new BufferedReader(reader);
StringBuilder builder = new StringBuilder();
try {
String line;
while ((line = input.readLine()) != null) {
builder.append(line);
builder.append('\n');
}
} finally {
input.close();
}
loadFromString(builder.toString());
}
@Override
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();
}
}
@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;
}
}
package cn.citycraft.RealBackpacks.config;
import java.io.BufferedReader;
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.Reader;
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 {
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;
}
protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
@Override
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));
}
@Override
public void load(Reader reader) throws IOException, InvalidConfigurationException {
BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader
: new BufferedReader(reader);
StringBuilder builder = new StringBuilder();
try {
String line;
while ((line = input.readLine()) != null) {
builder.append(line);
builder.append('\n');
}
} finally {
input.close();
}
loadFromString(builder.toString());
}
@Override
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();
}
}
@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;
}
}

View File

@ -1,48 +1,48 @@
package cn.citycraft.RealBackpacks.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();
}
}
}
package cn.citycraft.RealBackpacks.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();
}
}
}

View File

@ -1,419 +1,419 @@
package cn.citycraft.RealBackpacks.json;
/*
* Copyright (c) 2002 JSON.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* The Software shall be used for Good, not Evil.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
public class JSONArray {
private final ArrayList<Object> myArrayList;
public JSONArray() {
this.myArrayList = new ArrayList<Object>();
}
public JSONArray(Collection<?> collection) {
this.myArrayList = new ArrayList<Object>();
if (collection != null) {
Iterator<?> iter = collection.iterator();
while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next()));
}
}
}
public JSONArray(JSONTokener x) throws JSONException {
this();
if (x.nextClean() != '[')
throw x.syntaxError("A JSONArray text must start with '['");
if (x.nextClean() != ']') {
x.back();
for (;;) {
if (x.nextClean() == ',') {
x.back();
this.myArrayList.add(JSONObject.NULL);
} else {
x.back();
this.myArrayList.add(x.nextValue());
}
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == ']')
return;
x.back();
break;
case ']':
return;
default:
throw x.syntaxError("Expected a ',' or ']'");
}
}
}
}
public JSONArray(Object array) throws JSONException {
this();
if (array.getClass().isArray()) {
int length = Array.getLength(array);
for (int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i)));
}
} else
throw new JSONException(
"JSONArray initial value should be a string or collection or array.");
}
public JSONArray(String source) throws JSONException {
this(new JSONTokener(source));
}
public Object get(int index) throws JSONException {
Object object = this.opt(index);
if (object == null)
throw new JSONException("JSONArray[" + index + "] not found.");
return object;
}
public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
if (object.equals(Boolean.FALSE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("false")))
return false;
else if (object.equals(Boolean.TRUE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("true")))
return true;
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
}
public double getDouble(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
public int getInt(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).intValue()
: Integer.parseInt((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
public JSONArray getJSONArray(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONArray)
return (JSONArray) object;
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
}
public JSONObject getJSONObject(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONObject)
return (JSONObject) object;
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
}
public long getLong(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
public String getString(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof String)
return (String) object;
throw new JSONException("JSONArray[" + index + "] not a string.");
}
public boolean isNull(int index) {
return JSONObject.NULL.equals(this.opt(index));
}
public String join(String separator) throws JSONException {
int len = this.length();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(separator);
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
}
return sb.toString();
}
public int length() {
return this.myArrayList.size();
}
public Object opt(int index) {
return (index < 0 || index >= this.length()) ? null : this.myArrayList
.get(index);
}
public boolean optBoolean(int index) {
return this.optBoolean(index, false);
}
public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
}
public double optDouble(int index) {
return this.optDouble(index, Double.NaN);
}
public double optDouble(int index, double defaultValue) {
try {
return this.getDouble(index);
} catch (Exception e) {
return defaultValue;
}
}
public int optInt(int index) {
return this.optInt(index, 0);
}
public int optInt(int index, int defaultValue) {
try {
return this.getInt(index);
} catch (Exception e) {
return defaultValue;
}
}
public JSONArray optJSONArray(int index) {
Object o = this.opt(index);
return o instanceof JSONArray ? (JSONArray) o : null;
}
public JSONObject optJSONObject(int index) {
Object o = this.opt(index);
return o instanceof JSONObject ? (JSONObject) o : null;
}
public long optLong(int index) {
return this.optLong(index, 0);
}
public long optLong(int index, long defaultValue) {
try {
return this.getLong(index);
} catch (Exception e) {
return defaultValue;
}
}
public String optString(int index) {
return this.optString(index, "");
}
public String optString(int index, String defaultValue) {
Object object = this.opt(index);
return JSONObject.NULL.equals(object) ? defaultValue : object
.toString();
}
public JSONArray put(boolean value) {
this.put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
public JSONArray put(Collection<?> value) {
this.put(new JSONArray(value));
return this;
}
public JSONArray put(double value) throws JSONException {
Double d = new Double(value);
JSONObject.testValidity(d);
this.put(d);
return this;
}
public JSONArray put(int value) {
this.put(new Integer(value));
return this;
}
public JSONArray put(int index, boolean value) throws JSONException {
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
public JSONArray put(int index, Collection<?> value) throws JSONException {
this.put(index, new JSONArray(value));
return this;
}
public JSONArray put(int index, double value) throws JSONException {
this.put(index, new Double(value));
return this;
}
public JSONArray put(int index, int value) throws JSONException {
this.put(index, new Integer(value));
return this;
}
public JSONArray put(int index, long value) throws JSONException {
this.put(index, new Long(value));
return this;
}
public JSONArray put(int index, Map<?, ?> value) throws JSONException {
this.put(index, new JSONObject(value));
return this;
}
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0)
throw new JSONException("JSONArray[" + index + "] not found.");
if (index < this.length()) {
this.myArrayList.set(index, value);
} else {
while (index != this.length()) {
this.put(JSONObject.NULL);
}
this.put(value);
}
return this;
}
public JSONArray put(long value) {
this.put(new Long(value));
return this;
}
public JSONArray put(Map<?, ?> value) {
this.put(new JSONObject());
return this;
}
public JSONArray put(Object value) {
this.myArrayList.add(value);
return this;
}
public Object remove(int index) {
Object o = this.opt(index);
this.myArrayList.remove(index);
return o;
}
public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || this.length() == 0)
return null;
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
}
return jo;
}
@Override
public String toString() {
try {
return this.toString(0);
} catch (Exception e) {
return null;
}
}
public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
return this.write(sw, indentFactor, 0).toString();
}
}
public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
}
Writer write(Writer writer, int indentFactor, int indent)
throws JSONException {
try {
boolean commanate = false;
int length = this.length();
writer.write('[');
if (length == 1) {
JSONObject.writeValue(writer, this.myArrayList.get(0),
indentFactor, indent);
} else if (length != 0) {
final int newindent = indent + indentFactor;
for (int i = 0; i < length; i += 1) {
if (commanate) {
writer.write(',');
}
if (indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, newindent);
JSONObject.writeValue(writer, this.myArrayList.get(i),
indentFactor, newindent);
commanate = true;
}
if (indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, indent);
}
writer.write(']');
return writer;
} catch (IOException e) {
throw new JSONException(e);
}
}
package cn.citycraft.RealBackpacks.json;
/*
* Copyright (c) 2002 JSON.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* The Software shall be used for Good, not Evil.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
public class JSONArray {
private final ArrayList<Object> myArrayList;
public JSONArray() {
this.myArrayList = new ArrayList<Object>();
}
public JSONArray(Collection<?> collection) {
this.myArrayList = new ArrayList<Object>();
if (collection != null) {
Iterator<?> iter = collection.iterator();
while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next()));
}
}
}
public JSONArray(JSONTokener x) throws JSONException {
this();
if (x.nextClean() != '[')
throw x.syntaxError("A JSONArray text must start with '['");
if (x.nextClean() != ']') {
x.back();
for (;;) {
if (x.nextClean() == ',') {
x.back();
this.myArrayList.add(JSONObject.NULL);
} else {
x.back();
this.myArrayList.add(x.nextValue());
}
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == ']')
return;
x.back();
break;
case ']':
return;
default:
throw x.syntaxError("Expected a ',' or ']'");
}
}
}
}
public JSONArray(Object array) throws JSONException {
this();
if (array.getClass().isArray()) {
int length = Array.getLength(array);
for (int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i)));
}
} else
throw new JSONException(
"JSONArray initial value should be a string or collection or array.");
}
public JSONArray(String source) throws JSONException {
this(new JSONTokener(source));
}
public Object get(int index) throws JSONException {
Object object = this.opt(index);
if (object == null)
throw new JSONException("JSONArray[" + index + "] not found.");
return object;
}
public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
if (object.equals(Boolean.FALSE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("false")))
return false;
else if (object.equals(Boolean.TRUE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("true")))
return true;
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
}
public double getDouble(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
public int getInt(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).intValue()
: Integer.parseInt((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
public JSONArray getJSONArray(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONArray)
return (JSONArray) object;
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
}
public JSONObject getJSONObject(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONObject)
return (JSONObject) object;
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
}
public long getLong(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
}
public String getString(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof String)
return (String) object;
throw new JSONException("JSONArray[" + index + "] not a string.");
}
public boolean isNull(int index) {
return JSONObject.NULL.equals(this.opt(index));
}
public String join(String separator) throws JSONException {
int len = this.length();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(separator);
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
}
return sb.toString();
}
public int length() {
return this.myArrayList.size();
}
public Object opt(int index) {
return (index < 0 || index >= this.length()) ? null : this.myArrayList
.get(index);
}
public boolean optBoolean(int index) {
return this.optBoolean(index, false);
}
public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
}
public double optDouble(int index) {
return this.optDouble(index, Double.NaN);
}
public double optDouble(int index, double defaultValue) {
try {
return this.getDouble(index);
} catch (Exception e) {
return defaultValue;
}
}
public int optInt(int index) {
return this.optInt(index, 0);
}
public int optInt(int index, int defaultValue) {
try {
return this.getInt(index);
} catch (Exception e) {
return defaultValue;
}
}
public JSONArray optJSONArray(int index) {
Object o = this.opt(index);
return o instanceof JSONArray ? (JSONArray) o : null;
}
public JSONObject optJSONObject(int index) {
Object o = this.opt(index);
return o instanceof JSONObject ? (JSONObject) o : null;
}
public long optLong(int index) {
return this.optLong(index, 0);
}
public long optLong(int index, long defaultValue) {
try {
return this.getLong(index);
} catch (Exception e) {
return defaultValue;
}
}
public String optString(int index) {
return this.optString(index, "");
}
public String optString(int index, String defaultValue) {
Object object = this.opt(index);
return JSONObject.NULL.equals(object) ? defaultValue : object
.toString();
}
public JSONArray put(boolean value) {
this.put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
public JSONArray put(Collection<?> value) {
this.put(new JSONArray(value));
return this;
}
public JSONArray put(double value) throws JSONException {
Double d = new Double(value);
JSONObject.testValidity(d);
this.put(d);
return this;
}
public JSONArray put(int value) {
this.put(new Integer(value));
return this;
}
public JSONArray put(int index, boolean value) throws JSONException {
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
public JSONArray put(int index, Collection<?> value) throws JSONException {
this.put(index, new JSONArray(value));
return this;
}
public JSONArray put(int index, double value) throws JSONException {
this.put(index, new Double(value));
return this;
}
public JSONArray put(int index, int value) throws JSONException {
this.put(index, new Integer(value));
return this;
}
public JSONArray put(int index, long value) throws JSONException {
this.put(index, new Long(value));
return this;
}
public JSONArray put(int index, Map<?, ?> value) throws JSONException {
this.put(index, new JSONObject(value));
return this;
}
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0)
throw new JSONException("JSONArray[" + index + "] not found.");
if (index < this.length()) {
this.myArrayList.set(index, value);
} else {
while (index != this.length()) {
this.put(JSONObject.NULL);
}
this.put(value);
}
return this;
}
public JSONArray put(long value) {
this.put(new Long(value));
return this;
}
public JSONArray put(Map<?, ?> value) {
this.put(new JSONObject());
return this;
}
public JSONArray put(Object value) {
this.myArrayList.add(value);
return this;
}
public Object remove(int index) {
Object o = this.opt(index);
this.myArrayList.remove(index);
return o;
}
public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || this.length() == 0)
return null;
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
}
return jo;
}
@Override
public String toString() {
try {
return this.toString(0);
} catch (Exception e) {
return null;
}
}
public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
return this.write(sw, indentFactor, 0).toString();
}
}
public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
}
Writer write(Writer writer, int indentFactor, int indent)
throws JSONException {
try {
boolean commanate = false;
int length = this.length();
writer.write('[');
if (length == 1) {
JSONObject.writeValue(writer, this.myArrayList.get(0),
indentFactor, indent);
} else if (length != 0) {
final int newindent = indent + indentFactor;
for (int i = 0; i < length; i += 1) {
if (commanate) {
writer.write(',');
}
if (indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, newindent);
JSONObject.writeValue(writer, this.myArrayList.get(i),
indentFactor, newindent);
commanate = true;
}
if (indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, indent);
}
writer.write(']');
return writer;
} catch (IOException e) {
throw new JSONException(e);
}
}
}

View File

@ -1,21 +1,21 @@
package cn.citycraft.RealBackpacks.json;
public class JSONException extends Exception {
private static final long serialVersionUID = 0;
private Throwable cause;
public JSONException(final String message) {
super(message);
}
public JSONException(final Throwable cause) {
super(cause.getMessage());
this.cause = cause;
}
@Override
public Throwable getCause() {
return this.cause;
}
}
package cn.citycraft.RealBackpacks.json;
public class JSONException extends Exception {
private static final long serialVersionUID = 0;
private Throwable cause;
public JSONException(final String message) {
super(message);
}
public JSONException(final Throwable cause) {
super(cause.getMessage());
this.cause = cause;
}
@Override
public Throwable getCause() {
return this.cause;
}
}

View File

@ -1,6 +1,6 @@
package cn.citycraft.RealBackpacks.json;
public interface JSONString {
public String toJSONString();
package cn.citycraft.RealBackpacks.json;
public interface JSONString {
public String toJSONString();
}

View File

@ -1,315 +1,315 @@
package cn.citycraft.RealBackpacks.json;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
/*
* Copyright (c) 2002 JSON.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* The Software shall be used for Good, not Evil.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class JSONTokener {
private long character;
private boolean eof;
private long index;
private long line;
private char previous;
private final Reader reader;
private boolean usePrevious;
public JSONTokener(final Reader reader) {
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
this.eof = false;
this.usePrevious = false;
this.previous = 0;
this.index = 0;
this.character = 1;
this.line = 1;
}
public JSONTokener(final InputStream inputStream) throws JSONException {
this(new InputStreamReader(inputStream));
}
public JSONTokener(final String s) {
this(new StringReader(s));
}
public void back() throws JSONException {
if (this.usePrevious || this.index <= 0) {
throw new JSONException("Stepping back two steps is not supported");
}
this.index -= 1;
this.character -= 1;
this.usePrevious = true;
this.eof = false;
}
public static int dehexchar(final char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
if (c >= 'A' && c <= 'F') {
return c - ('A' - 10);
}
if (c >= 'a' && c <= 'f') {
return c - ('a' - 10);
}
return -1;
}
public boolean end() {
return this.eof && !this.usePrevious;
}
public boolean more() throws JSONException {
this.next();
if (this.end()) {
return false;
}
this.back();
return true;
}
public char next() throws JSONException {
int c;
if (this.usePrevious) {
this.usePrevious = false;
c = this.previous;
} else {
try {
c = this.reader.read();
} catch (final IOException exception) {
throw new JSONException(exception);
}
if (c <= 0) { // End of stream
this.eof = true;
c = 0;
}
}
this.index += 1;
if (this.previous == '\r') {
this.line += 1;
this.character = c == '\n' ? 0 : 1;
} else if (c == '\n') {
this.line += 1;
this.character = 0;
} else {
this.character += 1;
}
this.previous = (char) c;
return this.previous;
}
public char next(final char c) throws JSONException {
final char n = this.next();
if (n != c) {
throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
}
return n;
}
public String next(final int n) throws JSONException {
if (n == 0) {
return "";
}
final char[] chars = new char[n];
int pos = 0;
while (pos < n) {
chars[pos] = this.next();
if (this.end()) {
throw this.syntaxError("Substring bounds error");
}
pos += 1;
}
return new String(chars);
}
public char nextClean() throws JSONException {
for (;;) {
final char c = this.next();
if (c == 0 || c > ' ') {
return c;
}
}
}
public String nextString(final char quote) throws JSONException {
char c;
final StringBuffer sb = new StringBuffer();
for (;;) {
c = this.next();
switch (c) {
case 0:
case '\n':
case '\r':
throw this.syntaxError("Unterminated string");
case '\\':
c = this.next();
switch (c) {
case 'b':
sb.append('\b');
break;
case 't':
sb.append('\t');
break;
case 'n':
sb.append('\n');
break;
case 'f':
sb.append('\f');
break;
case 'r':
sb.append('\r');
break;
case 'u':
sb.append((char) Integer.parseInt(this.next(4), 16));
break;
case '"':
case '\'':
case '\\':
case '/':
sb.append(c);
break;
default:
throw this.syntaxError("Illegal escape.");
}
break;
default:
if (c == quote) {
return sb.toString();
}
sb.append(c);
}
}
}
public String nextTo(final char delimiter) throws JSONException {
final StringBuffer sb = new StringBuffer();
for (;;) {
final char c = this.next();
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
if (c != 0) {
this.back();
}
return sb.toString().trim();
}
sb.append(c);
}
}
public String nextTo(final String delimiters) throws JSONException {
char c;
final StringBuffer sb = new StringBuffer();
for (;;) {
c = this.next();
if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') {
if (c != 0) {
this.back();
}
return sb.toString().trim();
}
sb.append(c);
}
}
public Object nextValue() throws JSONException {
char c = this.nextClean();
String string;
switch (c) {
case '"':
case '\'':
return this.nextString(c);
case '{':
this.back();
return new JSONObject(this);
case '[':
this.back();
return new JSONArray(this);
}
/*
* Handle unquoted text. This could be the values true, false, or
* null, or it can be a number. An implementation (such as this one)
* is allowed to also accept non-standard forms.
*
* Accumulate characters until we reach the end of the text or a
* formatting character.
*/
final StringBuffer sb = new StringBuffer();
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c);
c = this.next();
}
this.back();
string = sb.toString().trim();
if ("".equals(string)) {
throw this.syntaxError("Missing value");
}
return JSONObject.stringToValue(string);
}
public char skipTo(final char to) throws JSONException {
char c;
try {
final long startIndex = this.index;
final long startCharacter = this.character;
final long startLine = this.line;
this.reader.mark(1000000);
do {
c = this.next();
if (c == 0) {
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.line = startLine;
return c;
}
} while (c != to);
} catch (final IOException exc) {
throw new JSONException(exc);
}
this.back();
return c;
}
public JSONException syntaxError(final String message) {
return new JSONException(message + this.toString());
}
@Override
public String toString() {
return " at " + this.index + " [character " + this.character + " line " + this.line + "]";
}
}
package cn.citycraft.RealBackpacks.json;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
/*
* Copyright (c) 2002 JSON.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* The Software shall be used for Good, not Evil.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class JSONTokener {
private long character;
private boolean eof;
private long index;
private long line;
private char previous;
private final Reader reader;
private boolean usePrevious;
public JSONTokener(final Reader reader) {
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
this.eof = false;
this.usePrevious = false;
this.previous = 0;
this.index = 0;
this.character = 1;
this.line = 1;
}
public JSONTokener(final InputStream inputStream) throws JSONException {
this(new InputStreamReader(inputStream));
}
public JSONTokener(final String s) {
this(new StringReader(s));
}
public void back() throws JSONException {
if (this.usePrevious || this.index <= 0) {
throw new JSONException("Stepping back two steps is not supported");
}
this.index -= 1;
this.character -= 1;
this.usePrevious = true;
this.eof = false;
}
public static int dehexchar(final char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
if (c >= 'A' && c <= 'F') {
return c - ('A' - 10);
}
if (c >= 'a' && c <= 'f') {
return c - ('a' - 10);
}
return -1;
}
public boolean end() {
return this.eof && !this.usePrevious;
}
public boolean more() throws JSONException {
this.next();
if (this.end()) {
return false;
}
this.back();
return true;
}
public char next() throws JSONException {
int c;
if (this.usePrevious) {
this.usePrevious = false;
c = this.previous;
} else {
try {
c = this.reader.read();
} catch (final IOException exception) {
throw new JSONException(exception);
}
if (c <= 0) { // End of stream
this.eof = true;
c = 0;
}
}
this.index += 1;
if (this.previous == '\r') {
this.line += 1;
this.character = c == '\n' ? 0 : 1;
} else if (c == '\n') {
this.line += 1;
this.character = 0;
} else {
this.character += 1;
}
this.previous = (char) c;
return this.previous;
}
public char next(final char c) throws JSONException {
final char n = this.next();
if (n != c) {
throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
}
return n;
}
public String next(final int n) throws JSONException {
if (n == 0) {
return "";
}
final char[] chars = new char[n];
int pos = 0;
while (pos < n) {
chars[pos] = this.next();
if (this.end()) {
throw this.syntaxError("Substring bounds error");
}
pos += 1;
}
return new String(chars);
}
public char nextClean() throws JSONException {
for (;;) {
final char c = this.next();
if (c == 0 || c > ' ') {
return c;
}
}
}
public String nextString(final char quote) throws JSONException {
char c;
final StringBuffer sb = new StringBuffer();
for (;;) {
c = this.next();
switch (c) {
case 0:
case '\n':
case '\r':
throw this.syntaxError("Unterminated string");
case '\\':
c = this.next();
switch (c) {
case 'b':
sb.append('\b');
break;
case 't':
sb.append('\t');
break;
case 'n':
sb.append('\n');
break;
case 'f':
sb.append('\f');
break;
case 'r':
sb.append('\r');
break;
case 'u':
sb.append((char) Integer.parseInt(this.next(4), 16));
break;
case '"':
case '\'':
case '\\':
case '/':
sb.append(c);
break;
default:
throw this.syntaxError("Illegal escape.");
}
break;
default:
if (c == quote) {
return sb.toString();
}
sb.append(c);
}
}
}
public String nextTo(final char delimiter) throws JSONException {
final StringBuffer sb = new StringBuffer();
for (;;) {
final char c = this.next();
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
if (c != 0) {
this.back();
}
return sb.toString().trim();
}
sb.append(c);
}
}
public String nextTo(final String delimiters) throws JSONException {
char c;
final StringBuffer sb = new StringBuffer();
for (;;) {
c = this.next();
if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') {
if (c != 0) {
this.back();
}
return sb.toString().trim();
}
sb.append(c);
}
}
public Object nextValue() throws JSONException {
char c = this.nextClean();
String string;
switch (c) {
case '"':
case '\'':
return this.nextString(c);
case '{':
this.back();
return new JSONObject(this);
case '[':
this.back();
return new JSONArray(this);
}
/*
* Handle unquoted text. This could be the values true, false, or
* null, or it can be a number. An implementation (such as this one)
* is allowed to also accept non-standard forms.
*
* Accumulate characters until we reach the end of the text or a
* formatting character.
*/
final StringBuffer sb = new StringBuffer();
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c);
c = this.next();
}
this.back();
string = sb.toString().trim();
if ("".equals(string)) {
throw this.syntaxError("Missing value");
}
return JSONObject.stringToValue(string);
}
public char skipTo(final char to) throws JSONException {
char c;
try {
final long startIndex = this.index;
final long startCharacter = this.character;
final long startLine = this.line;
this.reader.mark(1000000);
do {
c = this.next();
if (c == 0) {
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.line = startLine;
return c;
}
} while (c != to);
} catch (final IOException exc) {
throw new JSONException(exc);
}
this.back();
return c;
}
public JSONException syntaxError(final String message) {
return new JSONException(message + this.toString());
}
@Override
public String toString() {
return " at " + this.index + " [character " + this.character + " line " + this.line + "]";
}
}

View File

@ -1,59 +1,59 @@
package cn.citycraft.RealBackpacks.listeners;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.RealBackpacks;
public class CraftListener implements Listener {
private final RealBackpacks plugin;
public CraftListener(final RealBackpacks plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPrepareCraft(final PrepareItemCraftEvent e) {
final ItemStack result = e.getInventory().getResult();
final HumanEntity human = e.getView().getPlayer();
if (!(human instanceof Player) || result == null) {
return;
}
for (final String backpack : plugin.backpacks) {
if (plugin.backpackOverrides.get(backpack) != null && result.isSimilar(plugin.backpackOverrides.get(backpack))) {
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
e.getInventory().setResult(RealBackpacks.NMS.addGlow(plugin.backpackItems.get(backpack)));
} else {
e.getInventory().setResult(plugin.backpackItems.get(backpack));
}
break;
}
}
if (result.hasItemMeta() && result.getItemMeta().hasDisplayName()) {
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (!result.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
continue;
}
if (!human.hasPermission("rb." + backpack + ".craft") && plugin.isUsingPerms()) {
e.getInventory().setResult(null);
((Player) human).sendMessage(ChatColor.RED + "你没有合成此背包的权限...");
break;
}
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
e.getInventory().setResult(RealBackpacks.NMS.addGlow(plugin.backpackItems.get(backpack)));
}
}
}
}
}
package cn.citycraft.RealBackpacks.listeners;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.RealBackpacks;
public class CraftListener implements Listener {
private final RealBackpacks plugin;
public CraftListener(final RealBackpacks plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPrepareCraft(final PrepareItemCraftEvent e) {
final ItemStack result = e.getInventory().getResult();
final HumanEntity human = e.getView().getPlayer();
if (!(human instanceof Player) || result == null) {
return;
}
for (final String backpack : plugin.backpacks) {
if (plugin.backpackOverrides.get(backpack) != null && result.isSimilar(plugin.backpackOverrides.get(backpack))) {
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
e.getInventory().setResult(RealBackpacks.NMS.addGlow(plugin.backpackItems.get(backpack)));
} else {
e.getInventory().setResult(plugin.backpackItems.get(backpack));
}
break;
}
}
if (result.hasItemMeta() && result.getItemMeta().hasDisplayName()) {
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (!result.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
continue;
}
if (!human.hasPermission("rb." + backpack + ".craft") && plugin.isUsingPerms()) {
e.getInventory().setResult(null);
((Player) human).sendMessage(ChatColor.RED + "你没有合成此背包的权限...");
break;
}
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
e.getInventory().setResult(RealBackpacks.NMS.addGlow(plugin.backpackItems.get(backpack)));
}
}
}
}
}

View File

@ -1,65 +1,65 @@
package cn.citycraft.RealBackpacks.listeners;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
import cn.citycraft.RealBackpacks.util.RBUtil;
public class EntityListener implements Listener {
private final RealBackpacks plugin;
private int setlevel = 0;
public EntityListener(final RealBackpacks plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onFoodChange(final FoodLevelChangeEvent e) {
if (e.getEntity() instanceof Player) {
final int foodlevel = e.getFoodLevel();
final Player p = (Player) e.getEntity();
final int pLevel = p.getFoodLevel();
final Inventory inv = p.getInventory();
final List<String> backpackList = new ArrayList<String>();
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (!key.get(10).equals("true")) {
continue;
}
if (!inv.contains(plugin.backpackItems.get(backpack))) {
continue;
}
backpackList.add(backpack);
}
final int listsize = backpackList.size();
if (listsize > 0) {
if (pLevel > foodlevel) {
//Starving
setlevel = RBUtil.getFoodLevel(foodlevel, pLevel, listsize, 11, backpackList);
if (setlevel < 0) {
setlevel = 0;
}
} else {
//Ate food
setlevel = RBUtil.getFoodLevel(foodlevel, pLevel, listsize, 12, backpackList);
if (setlevel < pLevel) {
setlevel = pLevel;
}
}
e.setCancelled(true);
p.setFoodLevel(setlevel);
}
}
}
}
package cn.citycraft.RealBackpacks.listeners;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
import cn.citycraft.RealBackpacks.util.RBUtil;
public class EntityListener implements Listener {
private final RealBackpacks plugin;
private int setlevel = 0;
public EntityListener(final RealBackpacks plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onFoodChange(final FoodLevelChangeEvent e) {
if (e.getEntity() instanceof Player) {
final int foodlevel = e.getFoodLevel();
final Player p = (Player) e.getEntity();
final int pLevel = p.getFoodLevel();
final Inventory inv = p.getInventory();
final List<String> backpackList = new ArrayList<String>();
for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack);
if (!key.get(10).equals("true")) {
continue;
}
if (!inv.contains(plugin.backpackItems.get(backpack))) {
continue;
}
backpackList.add(backpack);
}
final int listsize = backpackList.size();
if (listsize > 0) {
if (pLevel > foodlevel) {
//Starving
setlevel = RBUtil.getFoodLevel(foodlevel, pLevel, listsize, 11, backpackList);
if (setlevel < 0) {
setlevel = 0;
}
} else {
//Ate food
setlevel = RBUtil.getFoodLevel(foodlevel, pLevel, listsize, 12, backpackList);
if (setlevel < pLevel) {
setlevel = pLevel;
}
}
e.setCancelled(true);
p.setFoodLevel(setlevel);
}
}
}
}

View File

@ -1,228 +1,228 @@
package cn.citycraft.RealBackpacks.listeners;
import java.sql.SQLException;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import cn.citycraft.RealBackpacks.RealBackpacks;
import cn.citycraft.RealBackpacks.config.PlayerConfig;
import cn.citycraft.RealBackpacks.util.MysqlFunctions;
import cn.citycraft.RealBackpacks.util.RBUtil;
import cn.citycraft.RealBackpacks.util.Serialization;
public class InventoryListener implements Listener {
private final RealBackpacks plugin;
public InventoryListener(final RealBackpacks plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation")
public boolean isSimilar(ItemStack origin, ItemStack compare) {
if (compare == null)
return false;
if (compare == origin)
return true;
return compare.getTypeId() == origin.getTypeId()
&& compare.getDurability() == origin.getDurability()
&& compare.hasItemMeta() == origin.hasItemMeta()
&& (compare.hasItemMeta() ? isSimilarMeta(compare.getItemMeta(),
origin.getItemMeta()) : true);
}
public boolean isSimilarMeta(ItemMeta origin, ItemMeta compare) {
if (origin.hasDisplayName() != compare.hasDisplayName())
return false;
if (origin.hasEnchants() != compare.hasEnchants())
return false;
if (origin.hasLore() != compare.hasLore())
return false;
if (origin.hasDisplayName() && compare.hasDisplayName()) {
if (!origin.getDisplayName().equals(compare.getDisplayName()))
return false;
}
if (origin.hasEnchants() && compare.hasEnchants()) {
if (!origin.getEnchants().equals(compare.getEnchants()))
return false;
}
if (origin.hasLore() && compare.hasLore()) {
if (!(compare.getLore().containsAll(origin.getLore())))
return false;
}
return true;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent e) {
if (e.getWhoClicked() instanceof Player) {
final Player p = (Player) e.getWhoClicked();
final String name = p.getName();
if (plugin.adminRestrictedView.contains(name)) {
e.setCancelled(true);
return;
}
final Inventory otherInv = e.getView().getTopInventory();
final ItemStack curItem = e.getCurrentItem();
boolean otherInvPresent = false;
if (otherInv != null) {
otherInvPresent = true;
}
if (curItem != null && curItem.hasItemMeta() && curItem.getItemMeta().hasDisplayName()) {
for (final String backpack : plugin.backpacks) {
if (curItem.isSimilar(plugin.backpackItems.get(backpack))) {
plugin.slowedPlayers.remove(name);
p.setWalkSpeed(0.2F);
break;
}
}
}
if (!e.isCancelled() && curItem != null && otherInvPresent) {
if (plugin.playerData.containsKey(name)) {
final String backpack = plugin.playerData.get(name);
final List<String> key = plugin.backpackData.get(backpack);
final ItemStack cursor = e.getCursor();
boolean go = true;
if (key.get(16) != null && key.get(16).equalsIgnoreCase("true")) {
for (final String whitelist : plugin.backpackWhitelist.get(backpack)) {
if (whitelist == null) {
continue;
}
String potentialBackpack = RBUtil.stringToBackpack(whitelist);
if (potentialBackpack != null
&& plugin.backpackItems.containsKey(potentialBackpack)) {
if (curItem.isSimilar(plugin.backpackItems.get(potentialBackpack))
|| cursor.isSimilar(plugin.backpackItems
.get(potentialBackpack))) {
go = false;
break;
}
} else {
if (RBUtil.itemsAreEqual(curItem, whitelist)
|| RBUtil.itemsAreEqual(cursor, whitelist)) {
go = false;
break;
}
}
}
if (go) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
return;
}
}
for (final String blacklist : plugin.backpackBlacklist.get(backpack)) {
if (blacklist == null) {
continue;
}
String potentialBackpack = RBUtil.stringToBackpack(blacklist);
if (potentialBackpack != null
&& plugin.backpackItems.containsKey(potentialBackpack)) {
if (isSimilar(curItem, plugin.backpackItems.get(potentialBackpack))) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
return;
}
} else {
if (RBUtil.itemsAreEqual(curItem, blacklist)) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
return;
}
}
}
}
}
/*
* Dupes for (String backpack : plugin.backpackItems.keySet()) { if
* (p.getInventory().contains(plugin.backpackItems.get(backpack))) {
* plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
*
* @Override public void run() { Location loc = p.getLocation(); World world =
* p.getWorld(); for (ItemStack item : p.getInventory().getContents()) { if (item !=
* null && item.hasItemMeta() && item.getAmount() > 1) { for (String backpack :
* plugin.backpacks) { String unstackable = plugin.backpackData.get(backpack).get(18);
* if (unstackable == null || unstackable.equalsIgnoreCase("false")) { continue; } if
* (item.isSimilar(plugin.backpackItems.get(backpack))) { while (item.getAmount() > 1) {
* item.setAmount(item.getAmount() - 1); if (p.getInventory().firstEmpty() != -1) {
* p.getInventory().setItem(p.getInventory().firstEmpty(), item); p.updateInventory(); }
* else { world.dropItemNaturally(loc, plugin.backpackItems.get(backpack)); } } } } } }
* } }, 2L); break; } }
*/
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(final InventoryCloseEvent e) {
final String name = e.getPlayer().getName();
final Inventory inv = e.getView().getTopInventory();
final List<String> invString = Serialization.toString(inv);
final String backpack = plugin.playerData.get(name);
plugin.playerData.remove(name);
final String adminBackpack = plugin.adminFullView.get(name);
plugin.adminFullView.remove(name);
if (backpack != null) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (plugin.isUsingMysql()) {
try {
MysqlFunctions.addBackpackData(name, backpack, invString);
} catch (final SQLException e) {
e.printStackTrace();
}
} else {
PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory",
invString);
PlayerConfig.save();
}
}
});
} else if (adminBackpack != null) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
final String[] split = adminBackpack.split(":");
if (plugin.isUsingMysql()) {
try {
MysqlFunctions.addBackpackData(split[0], split[1], invString);
} catch (final SQLException e) {
e.printStackTrace();
}
} else {
PlayerConfig.getInstance(plugin, split[1]).set(split[0] + ".Inventory",
invString);
PlayerConfig.save();
}
}
});
} else if (plugin.adminRestrictedView.contains(name)) {
plugin.adminRestrictedView.remove(name);
}
}
}
package cn.citycraft.RealBackpacks.listeners;
import java.sql.SQLException;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import cn.citycraft.RealBackpacks.RealBackpacks;
import cn.citycraft.RealBackpacks.config.PlayerConfig;
import cn.citycraft.RealBackpacks.util.MysqlFunctions;
import cn.citycraft.RealBackpacks.util.RBUtil;
import cn.citycraft.RealBackpacks.util.Serialization;
public class InventoryListener implements Listener {
private final RealBackpacks plugin;
public InventoryListener(final RealBackpacks plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation")
public boolean isSimilar(ItemStack origin, ItemStack compare) {
if (compare == null)
return false;
if (compare == origin)
return true;
return compare.getTypeId() == origin.getTypeId()
&& compare.getDurability() == origin.getDurability()
&& compare.hasItemMeta() == origin.hasItemMeta()
&& (compare.hasItemMeta() ? isSimilarMeta(compare.getItemMeta(),
origin.getItemMeta()) : true);
}
public boolean isSimilarMeta(ItemMeta origin, ItemMeta compare) {
if (origin.hasDisplayName() != compare.hasDisplayName())
return false;
if (origin.hasEnchants() != compare.hasEnchants())
return false;
if (origin.hasLore() != compare.hasLore())
return false;
if (origin.hasDisplayName() && compare.hasDisplayName()) {
if (!origin.getDisplayName().equals(compare.getDisplayName()))
return false;
}
if (origin.hasEnchants() && compare.hasEnchants()) {
if (!origin.getEnchants().equals(compare.getEnchants()))
return false;
}
if (origin.hasLore() && compare.hasLore()) {
if (!(compare.getLore().containsAll(origin.getLore())))
return false;
}
return true;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent e) {
if (e.getWhoClicked() instanceof Player) {
final Player p = (Player) e.getWhoClicked();
final String name = p.getName();
if (plugin.adminRestrictedView.contains(name)) {
e.setCancelled(true);
return;
}
final Inventory otherInv = e.getView().getTopInventory();
final ItemStack curItem = e.getCurrentItem();
boolean otherInvPresent = false;
if (otherInv != null) {
otherInvPresent = true;
}
if (curItem != null && curItem.hasItemMeta() && curItem.getItemMeta().hasDisplayName()) {
for (final String backpack : plugin.backpacks) {
if (curItem.isSimilar(plugin.backpackItems.get(backpack))) {
plugin.slowedPlayers.remove(name);
p.setWalkSpeed(0.2F);
break;
}
}
}
if (!e.isCancelled() && curItem != null && otherInvPresent) {
if (plugin.playerData.containsKey(name)) {
final String backpack = plugin.playerData.get(name);
final List<String> key = plugin.backpackData.get(backpack);
final ItemStack cursor = e.getCursor();
boolean go = true;
if (key.get(16) != null && key.get(16).equalsIgnoreCase("true")) {
for (final String whitelist : plugin.backpackWhitelist.get(backpack)) {
if (whitelist == null) {
continue;
}
String potentialBackpack = RBUtil.stringToBackpack(whitelist);
if (potentialBackpack != null
&& plugin.backpackItems.containsKey(potentialBackpack)) {
if (curItem.isSimilar(plugin.backpackItems.get(potentialBackpack))
|| cursor.isSimilar(plugin.backpackItems
.get(potentialBackpack))) {
go = false;
break;
}
} else {
if (RBUtil.itemsAreEqual(curItem, whitelist)
|| RBUtil.itemsAreEqual(cursor, whitelist)) {
go = false;
break;
}
}
}
if (go) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
return;
}
}
for (final String blacklist : plugin.backpackBlacklist.get(backpack)) {
if (blacklist == null) {
continue;
}
String potentialBackpack = RBUtil.stringToBackpack(blacklist);
if (potentialBackpack != null
&& plugin.backpackItems.containsKey(potentialBackpack)) {
if (isSimilar(curItem, plugin.backpackItems.get(potentialBackpack))) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
return;
}
} else {
if (RBUtil.itemsAreEqual(curItem, blacklist)) {
e.setCancelled(true);
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
return;
}
}
}
}
}
/*
* Dupes for (String backpack : plugin.backpackItems.keySet()) { if
* (p.getInventory().contains(plugin.backpackItems.get(backpack))) {
* plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
*
* @Override public void run() { Location loc = p.getLocation(); World world =
* p.getWorld(); for (ItemStack item : p.getInventory().getContents()) { if (item !=
* null && item.hasItemMeta() && item.getAmount() > 1) { for (String backpack :
* plugin.backpacks) { String unstackable = plugin.backpackData.get(backpack).get(18);
* if (unstackable == null || unstackable.equalsIgnoreCase("false")) { continue; } if
* (item.isSimilar(plugin.backpackItems.get(backpack))) { while (item.getAmount() > 1) {
* item.setAmount(item.getAmount() - 1); if (p.getInventory().firstEmpty() != -1) {
* p.getInventory().setItem(p.getInventory().firstEmpty(), item); p.updateInventory(); }
* else { world.dropItemNaturally(loc, plugin.backpackItems.get(backpack)); } } } } } }
* } }, 2L); break; } }
*/
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(final InventoryCloseEvent e) {
final String name = e.getPlayer().getName();
final Inventory inv = e.getView().getTopInventory();
final List<String> invString = Serialization.toString(inv);
final String backpack = plugin.playerData.get(name);
plugin.playerData.remove(name);
final String adminBackpack = plugin.adminFullView.get(name);
plugin.adminFullView.remove(name);
if (backpack != null) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (plugin.isUsingMysql()) {
try {
MysqlFunctions.addBackpackData(name, backpack, invString);
} catch (final SQLException e) {
e.printStackTrace();
}
} else {
PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory",
invString);
PlayerConfig.save();
}
}
});
} else if (adminBackpack != null) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
final String[] split = adminBackpack.split(":");
if (plugin.isUsingMysql()) {
try {
MysqlFunctions.addBackpackData(split[0], split[1], invString);
} catch (final SQLException e) {
e.printStackTrace();
}
} else {
PlayerConfig.getInstance(plugin, split[1]).set(split[0] + ".Inventory",
invString);
PlayerConfig.save();
}
}
});
} else if (plugin.adminRestrictedView.contains(name)) {
plugin.adminRestrictedView.remove(name);
}
}
}

View File

@ -0,0 +1,138 @@
package cn.citycraft.RealBackpacks.util;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
public class MysqlFunctions {
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
public static void addBackpackData(final String playerName, final String backpack, final List<String> invString) throws SQLException {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, playerName);
statement.setString(2, backpack);
final ResultSet res = statement.executeQuery();
PreparedStatement state = null;
if (res.next())
if (res.getInt(1) == 1) {
state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(invString));
state.setString(4, playerName);
state.setString(5, backpack);
} else {
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(invString));
}
if (state != null) {
state.executeUpdate();
state.close();
}
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static boolean checkIfTableExists(final String table) {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
state.close();
conn.close();
if (tables.next())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
return false;
}
public static void createTables() {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
public static void delete(final String playerName, final String backpack) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static Inventory getBackpackInv(final String playerName, final String backpack) throws SQLException {
Inventory returnInv = null;
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
state.setString(1, playerName);
state.setString(2, backpack);
final ResultSet res = state.executeQuery();
if (res.next()) {
final String invString = res.getString(1);
if (invString != null)
returnInv = Serialization.toInventory(Serialization.stringToList(invString), ChatColor.translateAlternateColorCodes('&', plugin.backpackData.get(backpack).get(3)),
Integer.parseInt(plugin.backpackData.get(backpack).get(0)));
}
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
return returnInv;
}
public static void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}

View File

@ -1,135 +1,135 @@
package cn.citycraft.RealBackpacks.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.RealBackpacks;
import cn.citycraft.RealBackpacks.config.PlayerConfig;
public class RBUtil {
private static RealBackpacks plugin;
public static void destroyContents(final String name, final String backpack) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (plugin.isUsingMysql()) {
MysqlFunctions.delete(name, backpack);
} else {
PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory", null);
PlayerConfig.save();
}
}
});
}
public static int getFoodLevel(final int foodlevel, final int pLevel, final int listsize, final int key, final List<String> backpackList) {
int i = 0;
if (plugin.isAveraging()) {
int average = 0;
for (final String backpack : backpackList) {
average += Integer.parseInt(plugin.backpackData.get(backpack).get(key));
}
i = foodlevel - (average / listsize);
} else if (plugin.isAdding()) {
int sum = 0;
for (final String backpack : backpackList) {
sum += Integer.parseInt(plugin.backpackData.get(backpack).get(key));
}
i = foodlevel - sum;
} else {
final List<Integer> list = new ArrayList<Integer>();
for (final String backpack : backpackList) {
list.add(Integer.parseInt(plugin.backpackData.get(backpack).get(key)));
}
i = foodlevel - Collections.max(list);
}
return i;
}
@SuppressWarnings("deprecation")
public static ItemStack getItemstackFromString(final String s) {
ItemStack item = null;
final String[] split = s.split(":");
if (split.length == 1) {
item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])), 1);
} else {
if (split[1].equalsIgnoreCase("enchant") || split[1].equalsIgnoreCase("lore")
|| split[1].equalsIgnoreCase("all")) {
item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])));
} else {
item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])), 1,
(byte) Integer.parseInt(split[1]));
}
}
return item;
}
public static boolean hasLore(final ItemStack item) {
if (item.getItemMeta() != null) {
if (item.getItemMeta().hasDisplayName() || item.getItemMeta().hasLore())
return true;
}
return false;
}
public static boolean isEnchanted(final String s) {
final String[] split = s.split(":");
int i = 0;
if (split.length != 1) {
for (i = 1; i < split.length; i++) {
if (split[i].equalsIgnoreCase("enchant") || split[i].equalsIgnoreCase("all"))
return true;
}
}
return false;
}
public static boolean isLored(final String s) {
final String[] split = s.split(":");
int i = 0;
if (split.length != 1) {
for (i = 1; i < split.length; i++) {
if (split[i].equalsIgnoreCase("lore") || split[i].equalsIgnoreCase("all"))
return true;
}
}
return false;
}
public static boolean itemsAreEqual(final ItemStack item, final String s) {
final boolean lore = hasLore(item);
final boolean enchant = item.getEnchantments().size() >= 1;
final boolean isLored = isLored(s);
final boolean isEnchanted = isEnchanted(s);
if (!isLored && !isEnchanted && item.isSimilar(getItemstackFromString(s)))
return true;
else if (item.getType() == getItemstackFromString(s).getType()) {
if (enchant && !lore)
return isEnchanted && !isLored;
else if (enchant && lore)
return isEnchanted && isLored;
else if (!enchant && lore)
return isLored && !isEnchanted;
}
return false;
}
public static void setRBUtil(final RealBackpacks plugin) {
RBUtil.plugin = plugin;
}
public static String stringToBackpack(String s) {
for (final String b : plugin.backpacks) {
if (b.equalsIgnoreCase(s))
return b;
}
return null;
}
}
package cn.citycraft.RealBackpacks.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.RealBackpacks;
import cn.citycraft.RealBackpacks.config.PlayerConfig;
public class RBUtil {
private static RealBackpacks plugin;
public static void destroyContents(final String name, final String backpack) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (plugin.isUsingMysql()) {
MysqlFunctions.delete(name, backpack);
} else {
PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory", null);
PlayerConfig.save();
}
}
});
}
public static int getFoodLevel(final int foodlevel, final int pLevel, final int listsize, final int key, final List<String> backpackList) {
int i = 0;
if (plugin.isAveraging()) {
int average = 0;
for (final String backpack : backpackList) {
average += Integer.parseInt(plugin.backpackData.get(backpack).get(key));
}
i = foodlevel - (average / listsize);
} else if (plugin.isAdding()) {
int sum = 0;
for (final String backpack : backpackList) {
sum += Integer.parseInt(plugin.backpackData.get(backpack).get(key));
}
i = foodlevel - sum;
} else {
final List<Integer> list = new ArrayList<Integer>();
for (final String backpack : backpackList) {
list.add(Integer.parseInt(plugin.backpackData.get(backpack).get(key)));
}
i = foodlevel - Collections.max(list);
}
return i;
}
@SuppressWarnings("deprecation")
public static ItemStack getItemstackFromString(final String s) {
ItemStack item = null;
final String[] split = s.split(":");
if (split.length == 1) {
item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])), 1);
} else {
if (split[1].equalsIgnoreCase("enchant") || split[1].equalsIgnoreCase("lore")
|| split[1].equalsIgnoreCase("all")) {
item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])));
} else {
item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])), 1,
(byte) Integer.parseInt(split[1]));
}
}
return item;
}
public static boolean hasLore(final ItemStack item) {
if (item.getItemMeta() != null) {
if (item.getItemMeta().hasDisplayName() || item.getItemMeta().hasLore())
return true;
}
return false;
}
public static boolean isEnchanted(final String s) {
final String[] split = s.split(":");
int i = 0;
if (split.length != 1) {
for (i = 1; i < split.length; i++) {
if (split[i].equalsIgnoreCase("enchant") || split[i].equalsIgnoreCase("all"))
return true;
}
}
return false;
}
public static boolean isLored(final String s) {
final String[] split = s.split(":");
int i = 0;
if (split.length != 1) {
for (i = 1; i < split.length; i++) {
if (split[i].equalsIgnoreCase("lore") || split[i].equalsIgnoreCase("all"))
return true;
}
}
return false;
}
public static boolean itemsAreEqual(final ItemStack item, final String s) {
final boolean lore = hasLore(item);
final boolean enchant = item.getEnchantments().size() >= 1;
final boolean isLored = isLored(s);
final boolean isEnchanted = isEnchanted(s);
if (!isLored && !isEnchanted && item.isSimilar(getItemstackFromString(s)))
return true;
else if (item.getType() == getItemstackFromString(s).getType()) {
if (enchant && !lore)
return isEnchanted && !isLored;
else if (enchant && lore)
return isEnchanted && isLored;
else if (!enchant && lore)
return isLored && !isEnchanted;
}
return false;
}
public static void setRBUtil(final RealBackpacks plugin) {
RBUtil.plugin = plugin;
}
public static String stringToBackpack(String s) {
for (final String b : plugin.backpacks) {
if (b.equalsIgnoreCase(s))
return b;
}
return null;
}
}

View File

@ -1,163 +1,163 @@
package cn.citycraft.RealBackpacks.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.json.JSONArray;
import cn.citycraft.RealBackpacks.json.JSONException;
import cn.citycraft.RealBackpacks.json.JSONObject;
/**
* Fancy JSON serialization mostly by evilmidget38.
*
* @author evilmidget38, gomeow
*
*/
public class Serialization {
public static String NullString = "|--空--|";
public static String SplitString = "<-分割->";
@SuppressWarnings("unchecked")
public static Map<String, Object> toMap(final JSONObject object)
throws JSONException {
final Map<String, Object> map = new HashMap<String, Object>();
final Iterator<String> keys = object.keys();
while (keys.hasNext()) {
final String key = keys.next();
map.put(key, fromJson(object.get(key)));
}
return map;
}
private static Object fromJson(final Object json) throws JSONException {
if (json == JSONObject.NULL) {
return null;
} else if (json instanceof JSONObject) {
return toMap((JSONObject) json);
} else if (json instanceof JSONArray) {
return toList((JSONArray) json);
} else {
return json;
}
}
public static List<Object> toList(final JSONArray array)
throws JSONException {
final List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); i++) {
list.add(fromJson(array.get(i)));
}
return list;
}
public static List<String> stringToList(final String listString) {
return Arrays.asList(listString.split(SplitString));
}
public static String listToString(final List<String> list) {
String newString = null;
for (final String s : list) {
if (newString == null) {
newString = s;
} else {
newString += SplitString + s;
}
}
return newString;
}
public static List<String> toString(final Inventory inv) {
final List<String> result = new ArrayList<String>();
final List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>();
for (final ItemStack is : inv.getContents()) {
items.add(is);
}
for (final ConfigurationSerializable cs : items) {
if (cs == null) {
result.add(NullString);
} else {
result.add(new JSONObject(serialize(cs)).toString());
}
}
return result;
}
public static Inventory toInventory(final List<String> stringItems,
final String name, final int size) {
final Inventory inv = Bukkit.createInventory(null, size,
ChatColor.translateAlternateColorCodes('&', name));
final List<ItemStack> contents = new ArrayList<ItemStack>();
for (final String piece : stringItems) {
if (piece.equalsIgnoreCase(NullString)) {
contents.add(null);
} else {
try {
final ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(
piece)));
contents.add(item);
} catch (final JSONException e) {
e.printStackTrace();
}
}
}
final ItemStack[] items = new ItemStack[contents.size()];
for (int x = 0; x < contents.size(); x++) {
items[x] = contents.get(x);
}
inv.setContents(items);
return inv;
}
public static Map<String, Object> serialize(
final ConfigurationSerializable cs) {
final Map<String, Object> serialized = recreateMap(cs.serialize());
for (final Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry
.getValue()));
}
}
serialized.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
ConfigurationSerialization.getAlias(cs.getClass()));
return serialized;
}
public static Map<String, Object> recreateMap(
final Map<String, Object> original) {
final Map<String, Object> map = new HashMap<String, Object>();
for (final Entry<String, Object> entry : original.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static ConfigurationSerializable deserialize(
final Map<String, Object> map) {
for (final Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof Map
&& ((Map) entry.getValue())
.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map) entry.getValue()));
}
if (entry.getValue() instanceof Double) {
Double db = (Double) entry.getValue();
int value = db.intValue();
entry.setValue(value);
}
}
return ConfigurationSerialization.deserializeObject(map);
}
}
package cn.citycraft.RealBackpacks.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.json.JSONArray;
import cn.citycraft.RealBackpacks.json.JSONException;
import cn.citycraft.RealBackpacks.json.JSONObject;
/**
* Fancy JSON serialization mostly by evilmidget38.
*
* @author evilmidget38, gomeow
*
*/
public class Serialization {
public static String NullString = "|--空--|";
public static String SplitString = "<-分割->";
@SuppressWarnings("unchecked")
public static Map<String, Object> toMap(final JSONObject object)
throws JSONException {
final Map<String, Object> map = new HashMap<String, Object>();
final Iterator<String> keys = object.keys();
while (keys.hasNext()) {
final String key = keys.next();
map.put(key, fromJson(object.get(key)));
}
return map;
}
private static Object fromJson(final Object json) throws JSONException {
if (json == JSONObject.NULL) {
return null;
} else if (json instanceof JSONObject) {
return toMap((JSONObject) json);
} else if (json instanceof JSONArray) {
return toList((JSONArray) json);
} else {
return json;
}
}
public static List<Object> toList(final JSONArray array)
throws JSONException {
final List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); i++) {
list.add(fromJson(array.get(i)));
}
return list;
}
public static List<String> stringToList(final String listString) {
return Arrays.asList(listString.split(SplitString));
}
public static String listToString(final List<String> list) {
String newString = null;
for (final String s : list) {
if (newString == null) {
newString = s;
} else {
newString += SplitString + s;
}
}
return newString;
}
public static List<String> toString(final Inventory inv) {
final List<String> result = new ArrayList<String>();
final List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>();
for (final ItemStack is : inv.getContents()) {
items.add(is);
}
for (final ConfigurationSerializable cs : items) {
if (cs == null) {
result.add(NullString);
} else {
result.add(new JSONObject(serialize(cs)).toString());
}
}
return result;
}
public static Inventory toInventory(final List<String> stringItems,
final String name, final int size) {
final Inventory inv = Bukkit.createInventory(null, size,
ChatColor.translateAlternateColorCodes('&', name));
final List<ItemStack> contents = new ArrayList<ItemStack>();
for (final String piece : stringItems) {
if (piece.equalsIgnoreCase(NullString)) {
contents.add(null);
} else {
try {
final ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(
piece)));
contents.add(item);
} catch (final JSONException e) {
e.printStackTrace();
}
}
}
final ItemStack[] items = new ItemStack[contents.size()];
for (int x = 0; x < contents.size(); x++) {
items[x] = contents.get(x);
}
inv.setContents(items);
return inv;
}
public static Map<String, Object> serialize(
final ConfigurationSerializable cs) {
final Map<String, Object> serialized = recreateMap(cs.serialize());
for (final Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry
.getValue()));
}
}
serialized.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
ConfigurationSerialization.getAlias(cs.getClass()));
return serialized;
}
public static Map<String, Object> recreateMap(
final Map<String, Object> original) {
final Map<String, Object> map = new HashMap<String, Object>();
for (final Entry<String, Object> entry : original.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static ConfigurationSerializable deserialize(
final Map<String, Object> map) {
for (final Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof Map
&& ((Map) entry.getValue())
.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map) entry.getValue()));
}
if (entry.getValue() instanceof Double) {
Double db = (Double) entry.getValue();
int value = db.intValue();
entry.setValue(value);
}
}
return ConfigurationSerialization.deserializeObject(map);
}
}

View File

@ -1,253 +1,253 @@
Data:
#数据保存方式 [flatfile|MySQL]
FileSystem: flatfile
#MySQL数据库配置 只有当FileSystem配置为MySQL时有效
MySQL:
database: minecraft
username: root
password:
ip: localhost
port: 3306
Config:
#是否使用权限系统
usePermissions: true
#多背包配置模式 average平均模式 add添加模式
MultipleBackpacksInInventory:
average: false
add: true
#背包自定义配置
Backpacks:
#背包名称
Bp-18:
#背包大小
Size: 18
addGlow: true
#如何打开背包 [right_click|left_click]
OpenWith: right_click
#能否购买
Purchasable: true
#背包价格
Price: 2000
#是否启用合成
UseRecipe: true
#覆盖
Override: '0'
#合成表
Recipe:
- 334,334,334
- 334,54,334
- 334,334,334
#背包详情
BackpackItem:
#背包ID
id: 334
#背包名称
name: "&a背包-18"
#背包Lore
lore:
- "&5一个随身携带的背包."
- "&b有&d18&b个格子的物品可存放."
- "&3移动速度下降5%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
#是否开启白名单(开启后只有白名单的物品可以放入)
UseWhitelist: false
#白名单列表
ItemWhitelist: []
#黑名单列表(请填写所有背包的名称,防止背包放到背包内!)
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
#死亡后处理
onDeath:
#掉落背包物品
dropContents: false
#摧毁背包物品
destroyContents: false
#掉落背包(当服务器开启物品掉落保护时)
dropBackpack: false
#保留背包(当服务器关闭物品掉落保护时)
keepBackpack: false
#修改行走速度
WalkSpeedFeature:
#是否启用
enabled: true
#行走速度控制(0.2为正常速度)
walkingSpeed: 0.19
#饥饿系统控制
IncreasedHungerFeature:
#是否开启
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-27:
Size: 27
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 3000
UseRecipe: true
Override: '0'
Recipe:
- 334,334,334
- 334,146,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-27"
lore:
- "&5一个随身携带的背包."
- "&b有&d27&b个格子的物品可存放."
- "&3移动速度下降10%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.18
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-36:
Size: 36
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 3000
UseRecipe: true
Override: '0'
Recipe:
- 334,334,334
- 334,154,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-36"
lore:
- "&5一个随身携带的背包."
- "&b有&d36&b个格子的物品可存放."
- "&3移动速度下降15%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.17
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-45:
Size: 45
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 4000
UseRecipe: false
Override: '0'
Recipe:
- 334,334,334
- 334,154,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-45"
lore:
- "&5一个随身携带的背包."
- "&b有&d45&b个格子的物品可存放."
- "&3移动速度下降20%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.16
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-54:
Size: 54
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 5000
UseRecipe: false
Override: '0'
Recipe:
- 334,334,334
- 334,154,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-54"
lore:
- "&5一个随身携带的背包."
- "&b有&d54&b个格子的物品可存放."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.2
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Data:
#数据保存方式 [flatfile|MySQL]
FileSystem: flatfile
#MySQL数据库配置 只有当FileSystem配置为MySQL时有效
MySQL:
database: minecraft
username: root
password:
ip: localhost
port: 3306
Config:
#是否使用权限系统
usePermissions: true
#多背包配置模式 average平均模式 add添加模式
MultipleBackpacksInInventory:
average: false
add: true
#背包自定义配置
Backpacks:
#背包名称
Bp-18:
#背包大小
Size: 18
addGlow: true
#如何打开背包 [right_click|left_click]
OpenWith: right_click
#能否购买
Purchasable: true
#背包价格
Price: 2000
#是否启用合成
UseRecipe: true
#覆盖
Override: '0'
#合成表
Recipe:
- 334,334,334
- 334,54,334
- 334,334,334
#背包详情
BackpackItem:
#背包ID
id: 334
#背包名称
name: "&a背包-18"
#背包Lore
lore:
- "&5一个随身携带的背包."
- "&b有&d18&b个格子的物品可存放."
- "&3移动速度下降5%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
#是否开启白名单(开启后只有白名单的物品可以放入)
UseWhitelist: false
#白名单列表
ItemWhitelist: []
#黑名单列表(请填写所有背包的名称,防止背包放到背包内!)
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
#死亡后处理
onDeath:
#掉落背包物品
dropContents: false
#摧毁背包物品
destroyContents: false
#掉落背包(当服务器开启物品掉落保护时)
dropBackpack: false
#保留背包(当服务器关闭物品掉落保护时)
keepBackpack: false
#修改行走速度
WalkSpeedFeature:
#是否启用
enabled: true
#行走速度控制(0.2为正常速度)
walkingSpeed: 0.19
#饥饿系统控制
IncreasedHungerFeature:
#是否开启
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-27:
Size: 27
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 3000
UseRecipe: true
Override: '0'
Recipe:
- 334,334,334
- 334,146,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-27"
lore:
- "&5一个随身携带的背包."
- "&b有&d27&b个格子的物品可存放."
- "&3移动速度下降10%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.18
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-36:
Size: 36
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 3000
UseRecipe: true
Override: '0'
Recipe:
- 334,334,334
- 334,154,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-36"
lore:
- "&5一个随身携带的背包."
- "&b有&d36&b个格子的物品可存放."
- "&3移动速度下降15%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.17
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-45:
Size: 45
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 4000
UseRecipe: false
Override: '0'
Recipe:
- 334,334,334
- 334,154,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-45"
lore:
- "&5一个随身携带的背包."
- "&b有&d45&b个格子的物品可存放."
- "&3移动速度下降20%."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.16
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0
Bp-54:
Size: 54
addGlow: true
OpenWith: right_click
Purchasable: true
Price: 5000
UseRecipe: false
Override: '0'
Recipe:
- 334,334,334
- 334,154,334
- 334,334,334
BackpackItem:
id: 334
name: "&a背包-54"
lore:
- "&5一个随身携带的背包."
- "&b有&d54&b个格子的物品可存放."
- "&6背包掉落或丢失再次购买即可物品不丢失."
- "&c每种背包仅需购买一次多个不叠加."
UseWhitelist: false
ItemWhitelist: []
ItemBlacklist:
- Bp-18
- Bp-27
- Bp-36
- Bp-45
- Bp-54
- 276:all
onDeath:
dropContents: false
destroyContents: false
dropBackpack: false
keepBackpack: false
WalkSpeedFeature:
enabled: true
walkingSpeed: 0.2
IncreasedHungerFeature:
enabled: true
extraHungerBarsToDeplete: 1
hungerBarsToSubtractWhenEating: 0

View File

@ -1,23 +1,24 @@
name: RealBackpacks
main: cn.citycraft.RealBackpacks.RealBackpacks
version: 0.1.5
website: http://ci.citycraft.cn:8800/jenkins/job/RealBackpacks/
author: Slayr288,喵♂呜
softdepend: [Vault]
commands:
rb:
description: 背包插件主命令.
aliases: [realbackpacks, realb, rbs]
permissions:
rb.reload:
description: 重新载入插件!
default: op
rb.list:
description: 列出可购买背包!
default: op
rb.filetomysql:
description: 转换数据到MySql!
default: op
rb.fullview:
description: 完整查看别的玩家背包!
name: ${project.artifactId}
description: ${project.description}
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/
version: ${project.version}
authors: [喵♂呜]
softdepend: [Vault]
commands:
rb:
description: 背包插件主命令.
aliases: [realbackpacks, realb, rbs]
permissions:
rb.reload:
description: 重新载入插件!
default: op
rb.list:
description: 列出可购买背包!
default: op
rb.filetomysql:
description: 转换数据到MySql!
default: op
rb.fullview:
description: 完整查看别的玩家背包!
default: op