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

fix VersionChecker...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-06-12 20:10:48 +08:00
parent c81f9978ab
commit 60e804875a

View File

@ -24,6 +24,7 @@ import cn.citycraft.RealBackpacks.listeners.InventoryListener;
import cn.citycraft.RealBackpacks.listeners.PlayerListener;
import cn.citycraft.RealBackpacks.util.MysqlFunctions;
import cn.citycraft.RealBackpacks.util.RBUtil;
import cn.citycraft.RealBackpacks.util.VersionChecker;
public class RealBackpacks extends JavaPlugin {
@ -32,11 +33,11 @@ public class RealBackpacks extends JavaPlugin {
public static Economy econ = null;
public static boolean globalGlow = true;
private static boolean average = false;
private static boolean add = false;
private boolean usingMysql = false;
private boolean vault = true;
private boolean usingPermissions = true;
private static boolean average = false;
private static boolean add = false;
private String user = null;
private String password = null;
private String url;
@ -55,6 +56,8 @@ public class RealBackpacks extends JavaPlugin {
public List<String> adminRestrictedView = new ArrayList<String>();
public List<String> slowedPlayers = new ArrayList<String>();
private VersionChecker versionChecker;
// List key
// 0 = Size
// 1 = UseRecipe
@ -76,16 +79,70 @@ public class RealBackpacks extends JavaPlugin {
// 17 = addGlow
// 18 = Unstackable
@Override
public FileConfiguration getConfig() {
if (Config.getInstance() == null) {
Config.load(this);
}
return Config.getInstance();
}
private ItemStack getConfigLore(final ItemStack item, final String backpack) {
final List<String> key = backpackData.get(backpack);
final ItemMeta meta = item.getItemMeta();
final ArrayList<String> lore = new ArrayList<String>();
lore.clear();
if (backpackLore.get(backpack) != null) {
for (final String s : backpackLore.get(backpack)) {
lore.add(ChatColor.translateAlternateColorCodes('&', s));
}
meta.setLore(lore);
}
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', key.get(3)));
item.setItemMeta(meta);
return item;
}
public String getPass() {
return password;
}
public String getUrl() {
return url;
}
public String getUser() {
return user;
}
public boolean isAdding() {
return add;
}
public boolean isAveraging() {
return average;
}
public boolean isUsingMysql() {
return usingMysql;
}
public boolean isUsingPerms() {
return usingPermissions;
}
public boolean isUsingVault() {
return vault;
}
@Override
public void onEnable() {
final String p = getServer().getClass().getPackage().getName();
final String version = p.substring(p.lastIndexOf('.') + 1);
String classname = getClass().getPackage().getName() + ".versions."
+ version;
String classname = getClass().getPackage().getName() + ".versions." + version;
try {
final Class<?> clazz = Class.forName(classname);
final Constructor<?> cons = clazz
.getDeclaredConstructor(getClass());
final Constructor<?> cons = clazz.getDeclaredConstructor(getClass());
final Object obj = cons.newInstance(this);
if (obj instanceof RBInterface) {
NMS = (RBInterface) obj;
@ -106,30 +163,24 @@ public class RealBackpacks extends JavaPlugin {
setupLists();
setup();
if (isEnabled()) {
getServer().getPluginManager().registerEvents(
new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(
new CraftListener(this), this);
getServer().getPluginManager().registerEvents(
new InventoryListener(this), this);
getServer().getPluginManager().registerEvents(
new EntityListener(this), this);
getServer().getScheduler().runTaskTimer(this,
new WalkSpeedRunnable(this), 20, 20);
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new CraftListener(this), this);
getServer().getPluginManager().registerEvents(new InventoryListener(this), this);
getServer().getPluginManager().registerEvents(new EntityListener(this), this);
getServer().getScheduler().runTaskTimer(this, new WalkSpeedRunnable(this), 20, 20);
getCommand("rb").setExecutor(new MainCommand(this));
getLogger().info("真实背包已加载 By: 喵♂呜.");
}
}
versionChecker = new VersionChecker(this);
versionChecker.VersionCheck(null);
}
@Override
public FileConfiguration getConfig() {
if (Config.getInstance() == null) {
Config.load(this);
}
return Config.getInstance();
public void reloadConfig() {
Config.load(this);
}
@Override
@ -140,142 +191,6 @@ public class RealBackpacks extends JavaPlugin {
Config.save();
}
@Override
public void reloadConfig() {
Config.load(this);
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
final RegisteredServiceProvider<Economy> rsp = getServer()
.getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
public void setupLists() {
backpacks.clear();
backpackRecipe.clear();
backpackData.clear();
backpackLore.clear();
for (final String backpack : getConfig().getConfigurationSection(
"Backpacks").getKeys(false)) {
final List<String> list = new ArrayList<String>();
backpacks.add(backpack);
list.add(0, getConfig()
.getString("Backpacks." + backpack + ".Size"));
list.add(
1,
getConfig().getString(
"Backpacks." + backpack + ".UseRecipe"));
if (getConfig().getStringList("Backpacks." + backpack + ".Recipe") != null) {
backpackRecipe.put(
backpack,
getConfig().getStringList(
"Backpacks." + backpack + ".Recipe"));
} else {
backpackRecipe.put(backpack, null);
}
list.add(
2,
getConfig().getString(
"Backpacks." + backpack + ".BackpackItem.id"));
list.add(
3,
getConfig().getString(
"Backpacks." + backpack + ".BackpackItem.name"));
if (getConfig().getStringList(
"Backpacks." + backpack + ".BackpackItem.lore") != null) {
backpackLore
.put(backpack,
getConfig().getStringList(
"Backpacks." + backpack
+ ".BackpackItem.lore"));
} else {
backpackLore.put(backpack, null);
}
list.add(
4,
getConfig().getString(
"Backpacks." + backpack
+ ".onDeath.destroyContents"));
list.add(
5,
getConfig().getString(
"Backpacks." + backpack + ".onDeath.dropContents"));
list.add(
6,
getConfig().getString(
"Backpacks." + backpack + ".onDeath.dropBackpack"));
list.add(
7,
getConfig().getString(
"Backpacks." + backpack + ".onDeath.keepBackpack"));
list.add(
8,
getConfig().getString(
"Backpacks." + backpack
+ ".WalkSpeedFeature.enabled"));
list.add(
9,
getConfig().getString(
"Backpacks." + backpack
+ ".WalkSpeedFeature.walkingSpeed"));
list.add(
10,
getConfig().getString(
"Backpacks." + backpack
+ ".IncreasedHungerFeature.enabled"));
list.add(
11,
getConfig()
.getString(
"Backpacks."
+ backpack
+ ".IncreasedHungerFeature.extraHungerBarsToDeplete"));
list.add(
12,
getConfig()
.getString(
"Backpacks."
+ backpack
+ ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating"));
list.add(
13,
getConfig().getString(
"Backpacks." + backpack + ".Purchasable"));
list.add(14,
getConfig().getString("Backpacks." + backpack + ".Price"));
list.add(15,
getConfig()
.getString("Backpacks." + backpack + ".OpenWith"));
list.add(
16,
getConfig().getString(
"Backpacks." + backpack + ".UseWhitelist"));
list.add(17,
getConfig().getString("Backpacks." + backpack + ".addGlow"));
list.add(
18,
getConfig().getString(
"Backpacks." + backpack + ".Unstackable"));
backpackData.put(backpack, list);
backpackBlacklist.put(
backpack,
getConfig().getStringList(
"Backpacks." + backpack + ".ItemBlacklist"));
backpackWhitelist.put(
backpack,
getConfig().getStringList(
"Backpacks." + backpack + ".ItemWhitelist"));
}
}
@SuppressWarnings("deprecation")
public void setup() {
user = getConfig().getString("Data.MySQL.username");
@ -287,23 +202,19 @@ public class RealBackpacks extends JavaPlugin {
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.average")) {
average = false;
} else {
average = getConfig().getBoolean(
"Config.MultipleBackpacksInInventory.average");
average = getConfig().getBoolean("Config.MultipleBackpacksInInventory.average");
}
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.add")) {
add = false;
} else {
add = getConfig().getBoolean(
"Config.MultipleBackpacksInInventory.add");
add = getConfig().getBoolean("Config.MultipleBackpacksInInventory.add");
}
if (!getConfig().isSet("Data.FileSystem")) {
usingMysql = false;
} else if (getConfig().getString("Data.FileSystem").equalsIgnoreCase(
"mysql")
|| getConfig().getString("Data.FileSystem").equalsIgnoreCase(
"sql")) {
} else if (getConfig().getString("Data.FileSystem").equalsIgnoreCase("mysql")
|| getConfig().getString("Data.FileSystem").equalsIgnoreCase("sql")) {
usingMysql = true;
if (!MysqlFunctions.checkIfTableExists("rb_data")) {
MysqlFunctions.createTables();
@ -320,21 +231,17 @@ public class RealBackpacks extends JavaPlugin {
for (final String backpack : backpacks) {
final String override = getConfig().getString(
"Backpacks." + backpack + ".Override");
final String override = getConfig().getString("Backpacks." + backpack + ".Override");
if (override != null) {
backpackOverrides.put(backpack,
RBUtil.getItemstackFromString(override));
backpackOverrides.put(backpack, RBUtil.getItemstackFromString(override));
} else {
backpackOverrides.put(backpack, null);
}
final List<String> key = backpackData.get(backpack);
final String backpackItem = key.get(2);
backpackItems.put(
backpack,
getConfigLore(RBUtil.getItemstackFromString(backpackItem),
backpack));
backpackItems.put(backpack,
getConfigLore(RBUtil.getItemstackFromString(backpackItem), backpack));
ShapedRecipe recipe = null;
if (key.get(1).equalsIgnoreCase("true")) {
@ -380,15 +287,14 @@ public class RealBackpacks extends JavaPlugin {
continue;
}
if (itemsplit.length > 1) {
final Material baseblock = Material
.getMaterial(Integer.parseInt(itemsplit[0]));
final MaterialData ingredient = new MaterialData(
baseblock,
final Material baseblock = Material.getMaterial(Integer
.parseInt(itemsplit[0]));
final MaterialData ingredient = new MaterialData(baseblock,
(byte) Integer.parseInt(itemsplit[1]));
recipe.setIngredient(shapechar, ingredient);
} else {
final Material baseblock = Material
.getMaterial(Integer.parseInt(itemsplit[0]));
final Material baseblock = Material.getMaterial(Integer
.parseInt(itemsplit[0]));
recipe.setIngredient(shapechar, baseblock);
}
}
@ -398,53 +304,78 @@ public class RealBackpacks extends JavaPlugin {
}
}
private ItemStack getConfigLore(final ItemStack item, final String backpack) {
final List<String> key = backpackData.get(backpack);
final ItemMeta meta = item.getItemMeta();
final ArrayList<String> lore = new ArrayList<String>();
lore.clear();
if (backpackLore.get(backpack) != null) {
for (final String s : backpackLore.get(backpack)) {
lore.add(ChatColor.translateAlternateColorCodes('&', s));
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null)
return false;
final RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager()
.getRegistration(Economy.class);
if (rsp == null)
return false;
econ = rsp.getProvider();
return econ != null;
}
public void setupLists() {
backpacks.clear();
backpackRecipe.clear();
backpackData.clear();
backpackLore.clear();
for (final String backpack : getConfig().getConfigurationSection("Backpacks")
.getKeys(false)) {
final List<String> list = new ArrayList<String>();
backpacks.add(backpack);
list.add(0, getConfig().getString("Backpacks." + backpack + ".Size"));
list.add(1, getConfig().getString("Backpacks." + backpack + ".UseRecipe"));
if (getConfig().getStringList("Backpacks." + backpack + ".Recipe") != null) {
backpackRecipe.put(backpack,
getConfig().getStringList("Backpacks." + backpack + ".Recipe"));
} else {
backpackRecipe.put(backpack, null);
}
meta.setLore(lore);
list.add(2, getConfig().getString("Backpacks." + backpack + ".BackpackItem.id"));
list.add(3, getConfig().getString("Backpacks." + backpack + ".BackpackItem.name"));
if (getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore") != null) {
backpackLore.put(backpack,
getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore"));
} else {
backpackLore.put(backpack, null);
}
list.add(4, getConfig().getString("Backpacks." + backpack + ".onDeath.destroyContents"));
list.add(5, getConfig().getString("Backpacks." + backpack + ".onDeath.dropContents"));
list.add(6, getConfig().getString("Backpacks." + backpack + ".onDeath.dropBackpack"));
list.add(7, getConfig().getString("Backpacks." + backpack + ".onDeath.keepBackpack"));
list.add(8, getConfig()
.getString("Backpacks." + backpack + ".WalkSpeedFeature.enabled"));
list.add(
9,
getConfig().getString(
"Backpacks." + backpack + ".WalkSpeedFeature.walkingSpeed"));
list.add(
10,
getConfig().getString(
"Backpacks." + backpack + ".IncreasedHungerFeature.enabled"));
list.add(
11,
getConfig().getString(
"Backpacks." + backpack
+ ".IncreasedHungerFeature.extraHungerBarsToDeplete"));
list.add(
12,
getConfig().getString(
"Backpacks." + backpack
+ ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating"));
list.add(13, getConfig().getString("Backpacks." + backpack + ".Purchasable"));
list.add(14, getConfig().getString("Backpacks." + backpack + ".Price"));
list.add(15, getConfig().getString("Backpacks." + backpack + ".OpenWith"));
list.add(16, getConfig().getString("Backpacks." + backpack + ".UseWhitelist"));
list.add(17, getConfig().getString("Backpacks." + backpack + ".addGlow"));
list.add(18, getConfig().getString("Backpacks." + backpack + ".Unstackable"));
backpackData.put(backpack, list);
backpackBlacklist.put(backpack,
getConfig().getStringList("Backpacks." + backpack + ".ItemBlacklist"));
backpackWhitelist.put(backpack,
getConfig().getStringList("Backpacks." + backpack + ".ItemWhitelist"));
}
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&',
key.get(3)));
item.setItemMeta(meta);
return item;
}
public boolean isAveraging() {
return average;
}
public boolean isAdding() {
return add;
}
public boolean isUsingMysql() {
return usingMysql;
}
public boolean isUsingVault() {
return vault;
}
public boolean isUsingPerms() {
return usingPermissions;
}
public String getUser() {
return user;
}
public String getPass() {
return password;
}
public String getUrl() {
return url;
}
}