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