1
0
mirror of https://e.coding.net/circlecloud/RealBackpacks.git synced 2024-12-04 03:49:07 +00:00

move src path...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src"> <classpathentry kind="src" path="src/main/java"/>
<attributes> <classpathentry kind="src" path="src/main/resources"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <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" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.CityCraft</groupId> <groupId>cn.citycraft</groupId>
<artifactId>RealBackpacks</artifactId> <artifactId>RealBackpacks</artifactId>
<version>0.1.5-SNAPSHOT</version> <version>0.1.5</version>
<name>RealBackpacks</name> <name>RealBackpacks</name>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<resources> <resources>
<resource> <resource>
<directory>src</directory> <directory>src/main/resources</directory>
<excludes> <filtering>true</filtering>
<exclude>**/*.java</exclude>
</excludes>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
@ -51,4 +49,5 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<description>支持数据库的MySQL插件...</description>
</project> </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; package cn.citycraft.RealBackpacks;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import cn.citycraft.RealBackpacks.config.FileConfig; import cn.citycraft.RealBackpacks.config.FileConfig;
import cn.citycraft.RealBackpacks.config.PlayerConfig; import cn.citycraft.RealBackpacks.config.PlayerConfig;
import cn.citycraft.RealBackpacks.util.MysqlFunctions; import cn.citycraft.RealBackpacks.util.MysqlFunctions;
import cn.citycraft.RealBackpacks.util.RBUtil; import cn.citycraft.RealBackpacks.util.RBUtil;
import cn.citycraft.RealBackpacks.util.Serialization; import cn.citycraft.RealBackpacks.util.Serialization;
public class MainCommand implements CommandExecutor { public class MainCommand implements CommandExecutor {
private final RealBackpacks plugin; private final RealBackpacks plugin;
private boolean exist = false; private boolean exist = false;
private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======", private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======",
"§4* §a查看可购买列表 §7/rb list ", "§4* §a购买背包 §7/rb buy <背包名称> ", "§4* §a查看可购买列表 §7/rb list ",
"§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>", "§4* §a购买背包 §7/rb buy <背包名称> ",
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>", "§4* §a数据转移至MySQL §7/rb filetomysql" }; "§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>",
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>",
public MainCommand(final RealBackpacks plugin) { "§4* §a数据转移至MySQL §7/rb filetomysql" };
this.plugin = plugin;
} 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) { @Override
if (cmd.getName().equalsIgnoreCase("rb")) { @SuppressWarnings("deprecation")
if (args.length == 0) { public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
sender.sendMessage(helps); if (cmd.getName().equalsIgnoreCase("rb")) {
} if (args.length == 0)
if (args.length >= 1) { sender.sendMessage(helps);
final String command = args[0]; if (args.length >= 1) {
if (command.equalsIgnoreCase("reload")) { final String command = args[0];
if (plugin.isUsingPerms() && !sender.hasPermission("rb.reload")) { if (command.equalsIgnoreCase("reload")) {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!"); if (plugin.isUsingPerms() && !sender.hasPermission("rb.reload")) {
return false; sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
} return false;
final Long first = System.currentTimeMillis(); }
plugin.reloadConfig(); final Long first = System.currentTimeMillis();
plugin.setupLists(); plugin.reloadConfig();
plugin.getServer().resetRecipes(); plugin.setupLists();
plugin.setup(); plugin.getServer().resetRecipes();
sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW plugin.setup();
+ (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + "."); sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW + (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
return true; return true;
} else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) { } else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) {
if (!plugin.isUsingVault()) { if (!plugin.isUsingVault()) {
sender.sendMessage(ChatColor.RED + "当前命令无法使用,因为没有安装经济插件."); sender.sendMessage(ChatColor.RED + "当前命令无法使用,因为没有安装经济插件.");
return false; return false;
} }
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "控制台不能使用此命令."); sender.sendMessage(ChatColor.RED + "控制台不能使用此命令.");
return false; return false;
} }
if (!(args.length == 2)) { if (!(args.length == 2)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb buy <backpack>");
+ " /rb buy <backpack>"); return false;
return false; }
} String backpack = null;
String backpack = null; backpack = RBUtil.stringToBackpack(args[1]);
backpack = RBUtil.stringToBackpack(args[1]); if (backpack == null) {
if (backpack == null) { sender.sendMessage("背包不存在.");
sender.sendMessage("背包不存在."); return false;
return false; }
} if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".buy")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".buy")) { sender.sendMessage("没有购买的权限.");
sender.sendMessage("没有购买的权限."); return false;
return false; }
} if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equals("true")) {
if (plugin.backpackData.get(backpack).get(13) != null sender.sendMessage("不能被购买.");
&& !plugin.backpackData.get(backpack).get(13).equals("true")) { return false;
sender.sendMessage("不能被购买."); }
return false; final double price = Double.parseDouble(plugin.backpackData.get(backpack).get(14));
} if (RealBackpacks.econ.getBalance(sender.getName()) < price) {
final double price = Double.parseDouble(plugin.backpackData.get(backpack).get( sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包.");
14)); return false;
if (RealBackpacks.econ.getBalance(sender.getName()) < price) { }
sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包."); final Player p = (Player) sender;
return false; final Inventory inv = p.getInventory();
} final ItemStack backpackItem = plugin.backpackItems.get(backpack);
final Player p = (Player) sender; if (inv.firstEmpty() != -1) {
final Inventory inv = p.getInventory(); RealBackpacks.econ.withdrawPlayer(p.getName(), price);
final ItemStack backpackItem = plugin.backpackItems.get(backpack); if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
if (inv.firstEmpty() != -1) { if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
RealBackpacks.econ.withdrawPlayer(p.getName(), price); inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
if (plugin.backpackData.get(backpack).get(18) != null else
&& plugin.backpackData.get(backpack).get(18) inv.setItem(inv.firstEmpty(), backpackItem);
.equalsIgnoreCase("true")) { } else if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
if (RealBackpacks.globalGlow inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
&& plugin.backpackData.get(backpack).get(17) != null else
&& plugin.backpackData.get(backpack).get(17) inv.addItem(backpackItem);
.equalsIgnoreCase("true")) { p.updateInventory();
inv.setItem(inv.firstEmpty(), sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price + ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
RealBackpacks.NMS.addGlow(backpackItem)); return true;
} else { } else {
inv.setItem(inv.firstEmpty(), backpackItem); sender.sendMessage(ChatColor.RED + "你的背包是空的.");
} return false;
} else { }
if (RealBackpacks.globalGlow } else if (command.equalsIgnoreCase("list")) {
&& plugin.backpackData.get(backpack).get(17) != null if (plugin.isUsingPerms() && !sender.hasPermission("rb.list")) {
&& plugin.backpackData.get(backpack).get(17) sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
.equalsIgnoreCase("true")) { return false;
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem)); }
} else { sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|" + ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN + " 价格 ");
inv.addItem(backpackItem); sender.sendMessage(ChatColor.GOLD + "-----------------------------------");
} if (plugin.isUsingPerms())
} for (final String backpack : plugin.backpacks) {
p.updateInventory(); final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy");
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price final List<String> key = plugin.backpackData.get(backpack);
+ ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack); if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm)
return true; sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
} else { + Double.parseDouble(key.get(14)));
sender.sendMessage(ChatColor.RED + "你的背包是空的."); else if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm)
return false; sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
} else
} else if (command.equalsIgnoreCase("list")) { sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买");
if (plugin.isUsingPerms() && !sender.hasPermission("rb.list")) { }
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!"); else
return false; for (final String backpack : plugin.backpacks) {
} final List<String> key = plugin.backpackData.get(backpack);
sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|" if (plugin.backpackData.get(backpack).get(13) != null && plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true"))
+ ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
+ " 价格 "); + Double.parseDouble(key.get(14)));
sender.sendMessage(ChatColor.GOLD + "-----------------------------------"); else
if (plugin.isUsingPerms()) { sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
for (final String backpack : plugin.backpacks) { }
final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy"); } else if (command.equalsIgnoreCase("give")) {
final List<String> key = plugin.backpackData.get(backpack); if (!(args.length == 3)) {
if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY + " /rb give <玩家> <背包名称>");
&& hasPerm) { return false;
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack }
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) String backpack = null;
+ ChatColor.GOLD + " | " + ChatColor.GREEN backpack = RBUtil.stringToBackpack(args[2]);
+ Double.parseDouble(key.get(14))); if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".give")) {
} else if (plugin.backpackData.get(backpack).get(13) != null sender.sendMessage(ChatColor.RED + "没有足够的权限");
&& !plugin.backpackData.get(backpack).get(13) return false;
.equalsIgnoreCase("true") && hasPerm) { }
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack if (backpack == null) {
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) sender.sendMessage(ChatColor.RED + "背包不存在");
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买"); return false;
} else { }
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack final Player other = plugin.getServer().getPlayer(args[1]);
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) if (other == null) {
+ ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买"); sender.sendMessage(ChatColor.RED + "玩家不存在");
} return false;
} }
} else { final Inventory inv = other.getInventory();
for (final String backpack : plugin.backpacks) { final ItemStack backpackItem = plugin.backpackItems.get(backpack);
final List<String> key = plugin.backpackData.get(backpack); if (inv.firstEmpty() != -1) {
if (plugin.backpackData.get(backpack).get(13) != null if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
&& plugin.backpackData.get(backpack).get(13) if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
.equalsIgnoreCase("true")) { inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack else
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) inv.setItem(inv.firstEmpty(), backpackItem);
+ ChatColor.GOLD + " | " + ChatColor.GREEN } else if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
+ Double.parseDouble(key.get(14))); inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
} else { else
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack inv.addItem(backpackItem);
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) other.updateInventory();
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买"); sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack + ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
} return true;
} } else {
} sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
} else if (command.equalsIgnoreCase("give")) { return false;
if (!(args.length == 3)) { }
sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY } else if (command.equalsIgnoreCase("filetomysql")) {
+ " /rb give <玩家> <背包名称>"); if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql"))
return false; return false;
} plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
String backpack = null; @Override
backpack = RBUtil.stringToBackpack(args[2]); public void run() {
if (plugin.isUsingPerms() && !sender.hasPermission("rb." + backpack + ".give")) { if (!MysqlFunctions.checkIfTableExists("rb_data")) {
sender.sendMessage(ChatColor.RED + "没有足够的权限"); MysqlFunctions.createTables();
return false; exist = false;
} } else
if (backpack == null) { exist = true;
sender.sendMessage(ChatColor.RED + "背包不存在"); try {
return false; final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
} final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
final Player other = plugin.getServer().getPlayer(args[1]); int i = 0, times = 0;
if (other == null) { final int files = dir.listFiles().length;
sender.sendMessage(ChatColor.RED + "玩家不存在"); for (final File child : dir.listFiles()) {
return false; final String player = child.getName().replace(".yml", "");
} final FileConfig config = PlayerConfig.getInstance(plugin, player);
final Inventory inv = other.getInventory();
final ItemStack backpackItem = plugin.backpackItems.get(backpack); i++;
if (inv.firstEmpty() != -1) { PreparedStatement statement = null;
if (plugin.backpackData.get(backpack).get(18) != null PreparedStatement state = null;
&& plugin.backpackData.get(backpack).get(18) for (final String backpack : config.getConfigurationSection("").getKeys(false)) {
.equalsIgnoreCase("true")) { if (exist) {
if (RealBackpacks.globalGlow statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
&& plugin.backpackData.get(backpack).get(17) != null statement.setString(1, player);
&& plugin.backpackData.get(backpack).get(17) statement.setString(2, backpack);
.equalsIgnoreCase("true")) { final ResultSet res = statement.executeQuery();
inv.setItem(inv.firstEmpty(), if (res.next())
RealBackpacks.NMS.addGlow(backpackItem)); if (res.getInt(1) == 1) {
} else { state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
inv.setItem(inv.firstEmpty(), backpackItem); state.setString(1, player);
} state.setString(2, backpack);
} else { state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
if (RealBackpacks.globalGlow state.setString(4, player);
&& plugin.backpackData.get(backpack).get(17) != null state.setString(5, backpack);
&& plugin.backpackData.get(backpack).get(17) } else {
.equalsIgnoreCase("true")) { state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem)); state.setString(1, player);
} else { state.setString(2, backpack);
inv.addItem(backpackItem); state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
} }
} } else {
other.updateInventory(); state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack state.setString(1, player);
+ ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName()); state.setString(2, backpack);
return true; state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
} else { }
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了"); if (state != null) {
return false; state.executeUpdate();
} state.close();
} else if (command.equalsIgnoreCase("filetomysql")) { }
if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql")) }
return false; if (i == 50) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { i = 0;
@Override times++;
public void run() { sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50 + "/" + files + " files have been transferred.");
if (!MysqlFunctions.checkIfTableExists("rb_data")) { }
MysqlFunctions.createTables(); }
exist = false; conn.close();
} else { sender.sendMessage(ChatColor.LIGHT_PURPLE + "数据转换完成.");
exist = true; } catch (final SQLException e) {
} e.printStackTrace();
try { }
final Connection conn = DriverManager.getConnection( }
plugin.getUrl(), plugin.getUser(), plugin.getPass()); });
final File dir = new File(plugin.getDataFolder() + File.separator } else if (command.equalsIgnoreCase("view")) {
+ "userdata"); if (!(args.length == 3)) {
int i = 0,times = 0; sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb view <player> <backpack>");
final int files = dir.listFiles().length; return false;
for (final File child : dir.listFiles()) { }
final String player = child.getName().replace(".yml", ""); String backpack = null;
final FileConfig config = PlayerConfig.getInstance(plugin, backpack = RBUtil.stringToBackpack(args[2]);
player); boolean fullview = false;
boolean restrictedview = false;
i++; if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview"))
PreparedStatement statement = null; fullview = true;
PreparedStatement state = null; else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview"))
for (final String backpack : config.getConfigurationSection("") restrictedview = true;
.getKeys(false)) { if (plugin.isUsingPerms() && !fullview && !restrictedview) {
if (exist) { sender.sendMessage(ChatColor.RED + "没有足够的权限购买");
statement = conn return false;
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);"); }
statement.setString(1, player); if (backpack == null) {
statement.setString(2, backpack); sender.sendMessage(ChatColor.RED + "背包不存在");
final ResultSet res = statement.executeQuery(); return false;
if (res.next()) { }
if (res.getInt(1) == 1) { Inventory inv = null;
state = conn String name = args[1];
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;"); final Player p = (Player) sender;
state.setString(1, player); final List<String> key = plugin.backpackData.get(backpack);
state.setString(2, backpack); if (!plugin.isUsingMysql()) {
state.setString(3, Serialization boolean fileExists = false;
.listToString(config String fullName = null;
.getStringList(backpack final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
+ ".Inventory"))); for (final File f : dir.listFiles()) {
state.setString(4, player); final String fileName = f.getName();
state.setString(5, backpack); fullName = fileName.replace(".yml", "");
} else { if (fullName.equalsIgnoreCase(name)) {
state = conn name = fullName;
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);"); fileExists = true;
state.setString(1, player); break;
state.setString(2, backpack); }
state.setString(3, Serialization }
.listToString(config if (!fileExists) {
.getStringList(backpack sender.sendMessage(ChatColor.RED + "这货从来没打开过背包,所以是空的,2333.");
+ ".Inventory"))); return false;
} }
} final FileConfig config = PlayerConfig.getInstance(plugin, fullName);
} else { if (config.getStringList(backpack + ".Inventory") == null)
state = conn inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', fullName + "'s " + backpack + " data"));
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);"); else
state.setString(1, player); inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), fullName + "'s " + backpack + " data", Integer.parseInt(key.get(0)));
state.setString(2, backpack); } else {
state.setString(3, Serialization.listToString(config try {
.getStringList(backpack + ".Inventory"))); inv = MysqlFunctions.getBackpackInv(name, backpack);
} } catch (final SQLException e1) {
state.executeUpdate(); e1.printStackTrace();
state.close(); }
} if (inv == null) {
if (i == 50) { sender.sendMessage(ChatColor.RED + "这货从来没打开过背包,所以是空的,2333.");
i = 0; return false;
times++; }
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50 }
+ "/" + files + " files have been transferred."); if (plugin.playerData.containsKey(name)) {
} sender.sendMessage(ChatColor.RED + "玩家打开了背包,请等待玩家关闭.");
} return false;
conn.close(); }
sender.sendMessage(ChatColor.LIGHT_PURPLE + "数据转换完成."); if (fullview || !plugin.isUsingPerms())
} catch (final SQLException e) { plugin.adminFullView.put(sender.getName(), backpack + ":" + name);
e.printStackTrace(); else
} plugin.adminRestrictedView.add(sender.getName());
} p.openInventory(inv);
}); } else {
} else if (command.equalsIgnoreCase("view")) { sender.sendMessage(ChatColor.RED + "命令未找到.");
if (!(args.length == 3)) { sender.sendMessage(helps);
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY }
+ " /rb view <player> <backpack>"); }
return false; }
} 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; package cn.citycraft.RealBackpacks;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public interface RBInterface { public interface RBInterface {
public String inventoryToString(Inventory inventory); public String inventoryToString(Inventory inventory);
public Inventory stringToInventory(String data, String name); public Inventory stringToInventory(String data, String name);
public ItemStack addGlow(ItemStack item); public ItemStack addGlow(ItemStack item);
} }

View File

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

View File

@ -1,46 +1,46 @@
package cn.citycraft.RealBackpacks.config; package cn.citycraft.RealBackpacks.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class Config extends ConfigLoader { public class Config extends ConfigLoader {
private static String CONFIG_NAME = "config.yml"; private static String CONFIG_NAME = "config.yml";
private static FileConfig instance; private static FileConfig instance;
private static File file; private static File file;
public Config(Plugin p) { public Config(Plugin p) {
super(p, CONFIG_NAME); super(p, CONFIG_NAME);
file = new File(p.getDataFolder(), CONFIG_NAME); file = new File(p.getDataFolder(), CONFIG_NAME);
instance = super.getInstance(); instance = super.getInstance();
} }
public static void load(Plugin p) { public static void load(Plugin p) {
new Config(p); new Config(p);
} }
public static FileConfig getInstance() { public static FileConfig getInstance() {
return instance; return instance;
} }
public static String getMessage(String path) { public static String getMessage(String path) {
String message = instance.getString(path).replaceAll("&", "§"); String message = instance.getString(path).replaceAll("&", "§");
return message; return message;
} }
public static String[] getStringArray(String path) { public static String[] getStringArray(String path) {
return instance.getStringList(path).toArray(new String[0]); return instance.getStringList(path).toArray(new String[0]);
} }
public static void save(){ public static void save(){
try { try {
instance.save(file); instance.save(file);
} catch (IOException e) { } catch (IOException e) {
saveError(file); saveError(file);
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -1,102 +1,102 @@
package cn.citycraft.RealBackpacks.config; package cn.citycraft.RealBackpacks.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class ConfigLoader extends FileConfig { public class ConfigLoader extends FileConfig {
protected static FileConfig config; protected static FileConfig config;
protected static boolean tip = true; protected static boolean tip = true;
protected static Plugin plugin; protected static Plugin plugin;
public ConfigLoader(Plugin p, File file) { public ConfigLoader(Plugin p, File file) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, file, null, true); config = loadConfig(p, file, null, true);
} }
public ConfigLoader(Plugin p, File file, boolean res) { public ConfigLoader(Plugin p, File file, boolean res) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, file, null, res); config = loadConfig(p, file, null, res);
} }
public ConfigLoader(Plugin p, File file, String ver) { public ConfigLoader(Plugin p, File file, String ver) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, file, ver, true); config = loadConfig(p, file, ver, true);
} }
public ConfigLoader(Plugin p, File file, String ver, boolean res) { public ConfigLoader(Plugin p, File file, String ver, boolean res) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, file, ver, res); config = loadConfig(p, file, ver, res);
} }
public ConfigLoader(Plugin p, String filename) { public ConfigLoader(Plugin p, String filename) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), null, config = loadConfig(p, new File(p.getDataFolder(), filename), null,
true); true);
} }
public ConfigLoader(Plugin p, String filename, boolean res) { public ConfigLoader(Plugin p, String filename, boolean res) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), null, res); config = loadConfig(p, new File(p.getDataFolder(), filename), null, res);
} }
public ConfigLoader(Plugin p, String filename, String ver) { public ConfigLoader(Plugin p, String filename, String ver) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
} }
public ConfigLoader(Plugin p, String filename, String ver, boolean res) { public ConfigLoader(Plugin p, String filename, String ver, boolean res) {
ConfigLoader.plugin = p; ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
} }
public static FileConfig getInstance() { public static FileConfig getInstance() {
return config; return config;
} }
public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) { public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) {
tip = res ; tip = res ;
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "..."); p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "...");
} }
if (!file.exists()) { if (!file.exists()) {
fileCreate(p, file, res); fileCreate(p, file, res);
} else { } else {
if (ver != null) { if (ver != null) {
FileConfig configcheck = init(file); FileConfig configcheck = init(file);
String version = configcheck.getString("version"); String version = configcheck.getString("version");
if (version == null || !version.equals(ver)) { if (version == null || !version.equals(ver)) {
p.saveResource(file.getName(), true); p.saveResource(file.getName(), true);
p.getLogger().warning( p.getLogger().warning(
"配置文件: " + file.getName() + " 版本过低 正在升级..."); "配置文件: " + file.getName() + " 版本过低 正在升级...");
} }
} }
} }
if (tip) if (tip)
p.getLogger().info( p.getLogger().info(
"载入配置文件: " + file.getName() "载入配置文件: " + file.getName()
+ (ver != null ? " 版本: " + ver : "")); + (ver != null ? " 版本: " + ver : ""));
return init(file); return init(file);
} }
private void fileCreate(Plugin p, File file, boolean res) { private void fileCreate(Plugin p, File file, boolean res) {
if (res) { if (res) {
p.saveResource(file.getName(), false); p.saveResource(file.getName(), false);
} else { } else {
try { try {
p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "..."); p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "...");
file.createNewFile(); file.createNewFile();
} catch (IOException e) { } catch (IOException e) {
p.getLogger().info("配置文件" + file.getName() + "创建失败..."); p.getLogger().info("配置文件" + file.getName() + "创建失败...");
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
public static void saveError(File file) { public static void saveError(File file) {
plugin.getLogger().info("配置文件" + file.getName() + "保存错误..."); plugin.getLogger().info("配置文件" + file.getName() + "保存错误...");
} }
} }

View File

@ -1,108 +1,108 @@
package cn.citycraft.RealBackpacks.config; package cn.citycraft.RealBackpacks.config;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.util.logging.Level; import java.util.logging.Level;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration; import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.file.YamlConstructor; import org.bukkit.configuration.file.YamlConstructor;
import org.bukkit.configuration.file.YamlRepresenter; import org.bukkit.configuration.file.YamlRepresenter;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.representer.Representer; import org.yaml.snakeyaml.representer.Representer;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.io.Files; import com.google.common.io.Files;
/** /**
* An implementation of {@link Configuration} which saves all files in Yaml. Note that this * An implementation of {@link Configuration} which saves all files in Yaml. Note that this
* implementation is not synchronized. * implementation is not synchronized.
*/ */
public class FileConfig extends YamlConfiguration { public class FileConfig extends YamlConfiguration {
public static FileConfig init(File file) { public static FileConfig init(File file) {
return FileConfig.loadConfiguration(file); return FileConfig.loadConfiguration(file);
} }
public static FileConfig loadConfiguration(File file) { public static FileConfig loadConfiguration(File file) {
Validate.notNull(file, "File cannot be null"); Validate.notNull(file, "File cannot be null");
FileConfig config = new FileConfig(); FileConfig config = new FileConfig();
try { try {
config.load(file); config.load(file);
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
} catch (IOException ex) { } catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
} catch (InvalidConfigurationException ex) { } catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
} }
return config; return config;
} }
protected final DumperOptions yamlOptions = new DumperOptions(); protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter(); protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
@Override @Override
public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException { public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
Validate.notNull(file, "File cannot be null"); Validate.notNull(file, "File cannot be null");
final FileInputStream stream = new FileInputStream(file); final FileInputStream stream = new FileInputStream(file);
load(new InputStreamReader(stream, Charsets.UTF_8)); load(new InputStreamReader(stream, Charsets.UTF_8));
} }
@Override @Override
public void load(Reader reader) throws IOException, InvalidConfigurationException { public void load(Reader reader) throws IOException, InvalidConfigurationException {
BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader
: new BufferedReader(reader); : new BufferedReader(reader);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
try { try {
String line; String line;
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
builder.append(line); builder.append(line);
builder.append('\n'); builder.append('\n');
} }
} finally { } finally {
input.close(); input.close();
} }
loadFromString(builder.toString()); loadFromString(builder.toString());
} }
@Override @Override
public void save(File file) throws IOException { public void save(File file) throws IOException {
Validate.notNull(file, "File cannot be null"); Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file); Files.createParentDirs(file);
String data = saveToString(); String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
try { try {
writer.write(data); writer.write(data);
} finally { } finally {
writer.close(); writer.close();
} }
} }
@Override @Override
public String saveToString() { public String saveToString() {
yamlOptions.setIndent(options().indent()); yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
String header = buildHeader(); String header = buildHeader();
String dump = yaml.dump(getValues(false)); String dump = yaml.dump(getValues(false));
if (dump.equals(BLANK_CONFIG)) { if (dump.equals(BLANK_CONFIG)) {
dump = ""; dump = "";
} }
return header + dump; return header + dump;
} }
} }

View File

@ -1,48 +1,48 @@
package cn.citycraft.RealBackpacks.config; package cn.citycraft.RealBackpacks.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class PlayerConfig extends ConfigLoader { public class PlayerConfig extends ConfigLoader {
private static String CONFIG_FOLDER = "userdate"; private static String CONFIG_FOLDER = "userdate";
private static FileConfig instance; private static FileConfig instance;
private static File file; private static File file;
public PlayerConfig(Plugin p, String player) { public PlayerConfig(Plugin p, String player) {
super(p, CONFIG_FOLDER + File.separator + player + ".yml", false); super(p, CONFIG_FOLDER + File.separator + player + ".yml", false);
file = new File(p.getDataFolder(), CONFIG_FOLDER + File.separator file = new File(p.getDataFolder(), CONFIG_FOLDER + File.separator
+ player + ".yml"); + player + ".yml");
instance = super.getInstance(); instance = super.getInstance();
} }
public static FileConfig getInstance(Plugin p, Player player) { public static FileConfig getInstance(Plugin p, Player player) {
new PlayerConfig(p, player.getName()); new PlayerConfig(p, player.getName());
return instance; return instance;
} }
public static FileConfig getInstance(Plugin p, String player) { public static FileConfig getInstance(Plugin p, String player) {
new PlayerConfig(p, player); new PlayerConfig(p, player);
return instance; return instance;
} }
public static String getMessage(String path) { public static String getMessage(String path) {
String message = instance.getString(path).replaceAll("&", "§"); String message = instance.getString(path).replaceAll("&", "§");
return message; return message;
} }
public static String[] getStringArray(String path) { public static String[] getStringArray(String path) {
return instance.getStringList(path).toArray(new String[0]); return instance.getStringList(path).toArray(new String[0]);
} }
public static void save() { public static void save() {
try { try {
instance.save(file); instance.save(file);
} catch (IOException e) { } catch (IOException e) {
saveError(file); saveError(file);
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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