mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2024-12-04 03:49:07 +00:00
Update VersionChecker...
This commit is contained in:
parent
962eed36e2
commit
360553e25f
@ -1,381 +1,354 @@
|
|||||||
package cn.citycraft.RealBackpacks;
|
package cn.citycraft.RealBackpacks;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cn.citycraft.RealBackpacks.config.Config;
|
import cn.citycraft.RealBackpacks.config.Config;
|
||||||
import cn.citycraft.RealBackpacks.listeners.CraftListener;
|
import cn.citycraft.RealBackpacks.listeners.CraftListener;
|
||||||
import cn.citycraft.RealBackpacks.listeners.EntityListener;
|
import cn.citycraft.RealBackpacks.listeners.EntityListener;
|
||||||
import cn.citycraft.RealBackpacks.listeners.InventoryListener;
|
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;
|
import cn.citycraft.RealBackpacks.util.VersionChecker;
|
||||||
|
|
||||||
public class RealBackpacks extends JavaPlugin {
|
public class RealBackpacks extends JavaPlugin {
|
||||||
|
|
||||||
public static RBInterface NMS;
|
public static RBInterface NMS;
|
||||||
|
|
||||||
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 average = false;
|
||||||
private static boolean add = false;
|
private static boolean add = false;
|
||||||
public static VersionChecker versionChecker;
|
public static VersionChecker versionChecker;
|
||||||
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 String user = null;
|
private String user = null;
|
||||||
private String password = null;
|
private String password = null;
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
public List<String> backpacks = new ArrayList<String>();
|
public List<String> backpacks = new ArrayList<String>();
|
||||||
public HashMap<String, List<String>> backpackData = new HashMap<String, List<String>>();
|
public HashMap<String, List<String>> backpackData = new HashMap<String, List<String>>();
|
||||||
public HashMap<String, List<String>> backpackLore = new HashMap<String, List<String>>();
|
public HashMap<String, List<String>> backpackLore = new HashMap<String, List<String>>();
|
||||||
public HashMap<String, List<String>> backpackRecipe = new HashMap<String, List<String>>();
|
public HashMap<String, List<String>> backpackRecipe = new HashMap<String, List<String>>();
|
||||||
public HashMap<String, ItemStack> backpackItems = new HashMap<String, ItemStack>();
|
public HashMap<String, ItemStack> backpackItems = new HashMap<String, ItemStack>();
|
||||||
public HashMap<String, ItemStack> backpackOverrides = new HashMap<String, ItemStack>();
|
public HashMap<String, ItemStack> backpackOverrides = new HashMap<String, ItemStack>();
|
||||||
public HashMap<String, List<String>> backpackBlacklist = new HashMap<String, List<String>>();
|
public HashMap<String, List<String>> backpackBlacklist = new HashMap<String, List<String>>();
|
||||||
|
|
||||||
public HashMap<String, List<String>> backpackWhitelist = new HashMap<String, List<String>>();
|
public HashMap<String, List<String>> backpackWhitelist = new HashMap<String, List<String>>();
|
||||||
public HashMap<String, String> playerData = new HashMap<String, String>();
|
public HashMap<String, String> playerData = new HashMap<String, String>();
|
||||||
public HashMap<String, String> adminFullView = new HashMap<String, String>();
|
public HashMap<String, String> adminFullView = new HashMap<String, String>();
|
||||||
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>();
|
||||||
|
|
||||||
// List key
|
// List key
|
||||||
// 0 = Size
|
// 0 = Size
|
||||||
// 1 = UseRecipe
|
// 1 = UseRecipe
|
||||||
// 2 = id
|
// 2 = id
|
||||||
// 3 = name
|
// 3 = name
|
||||||
// 4 =destroyContents
|
// 4 =destroyContents
|
||||||
// 5 = dropContents
|
// 5 = dropContents
|
||||||
// 6 = dropBackpack
|
// 6 = dropBackpack
|
||||||
// 7 = keepBackpack
|
// 7 = keepBackpack
|
||||||
// 8 = walkSpeedEnabled
|
// 8 = walkSpeedEnabled
|
||||||
// 9 = walkSpeedMultiplier
|
// 9 = walkSpeedMultiplier
|
||||||
// 10 = increasedHungerEnabled
|
// 10 = increasedHungerEnabled
|
||||||
// 11 = hungerBarsToDeplete
|
// 11 = hungerBarsToDeplete
|
||||||
// 12 = hungerBarsToSubtractWhenEating
|
// 12 = hungerBarsToSubtractWhenEating
|
||||||
// 13 = Purchasable
|
// 13 = Purchasable
|
||||||
// 14 = Price
|
// 14 = Price
|
||||||
// 15 = OpenWith
|
// 15 = OpenWith
|
||||||
// 16 = UseWhitelist
|
// 16 = UseWhitelist
|
||||||
// 17 = addGlow
|
// 17 = addGlow
|
||||||
// 18 = Unstackable
|
// 18 = Unstackable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
if (Config.getInstance() == null) {
|
if (Config.getInstance() == null) {
|
||||||
Config.load(this);
|
Config.load(this);
|
||||||
}
|
}
|
||||||
return Config.getInstance();
|
return Config.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getConfigLore(final ItemStack item, final String backpack) {
|
private ItemStack getConfigLore(final ItemStack item, final String backpack) {
|
||||||
final List<String> key = backpackData.get(backpack);
|
final List<String> key = backpackData.get(backpack);
|
||||||
final ItemMeta meta = item.getItemMeta();
|
final ItemMeta meta = item.getItemMeta();
|
||||||
final ArrayList<String> lore = new ArrayList<String>();
|
final ArrayList<String> lore = new ArrayList<String>();
|
||||||
lore.clear();
|
lore.clear();
|
||||||
if (backpackLore.get(backpack) != null) {
|
if (backpackLore.get(backpack) != null) {
|
||||||
for (final String s : backpackLore.get(backpack)) {
|
for (final String s : backpackLore.get(backpack)) {
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||||
}
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPass() {
|
public String getPass() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUser() {
|
public String getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdding() {
|
public boolean isAdding() {
|
||||||
return add;
|
return add;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAveraging() {
|
public boolean isAveraging() {
|
||||||
return average;
|
return average;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUsingMysql() {
|
public boolean isUsingMysql() {
|
||||||
return usingMysql;
|
return usingMysql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUsingPerms() {
|
public boolean isUsingPerms() {
|
||||||
return usingPermissions;
|
return usingPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUsingVault() {
|
public boolean isUsingVault() {
|
||||||
return vault;
|
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." + version;
|
String classname = getClass().getPackage().getName() + ".versions." + version;
|
||||||
try {
|
try {
|
||||||
final Class<?> clazz = Class.forName(classname);
|
final Class<?> clazz = Class.forName(classname);
|
||||||
final Constructor<?> cons = clazz.getDeclaredConstructor(getClass());
|
final Constructor<?> cons = clazz.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;
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
globalGlow = false;
|
globalGlow = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
MysqlFunctions.setMysqlFunc(this);
|
MysqlFunctions.setMysqlFunc(this);
|
||||||
RBUtil.setRBUtil(this);
|
RBUtil.setRBUtil(this);
|
||||||
if (!setupEconomy()) {
|
if (!setupEconomy()) {
|
||||||
getLogger().warning("Vault 未找到, 部分功能无法使用...");
|
getLogger().warning("Vault 未找到, 部分功能无法使用...");
|
||||||
vault = false;
|
vault = false;
|
||||||
} else {
|
} else {
|
||||||
getLogger().info("Vault 已找到, 启用经济系统...");
|
getLogger().info("Vault 已找到, 启用经济系统...");
|
||||||
}
|
}
|
||||||
setupLists();
|
setupLists();
|
||||||
setup();
|
setup();
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new CraftListener(this), this);
|
getServer().getPluginManager().registerEvents(new CraftListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new InventoryListener(this), this);
|
getServer().getPluginManager().registerEvents(new InventoryListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new EntityListener(this), this);
|
getServer().getPluginManager().registerEvents(new EntityListener(this), this);
|
||||||
getServer().getScheduler().runTaskTimer(this, new WalkSpeedRunnable(this), 20, 20);
|
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);
|
new VersionChecker(this);
|
||||||
versionChecker.VersionCheck(null);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void reloadConfig() {
|
||||||
public void reloadConfig() {
|
Config.load(this);
|
||||||
Config.load(this);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void saveConfig() {
|
||||||
public void saveConfig() {
|
if (Config.getInstance() == null) {
|
||||||
if (Config.getInstance() == null) {
|
Config.load(this);
|
||||||
Config.load(this);
|
}
|
||||||
}
|
Config.save();
|
||||||
Config.save();
|
}
|
||||||
}
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@SuppressWarnings("deprecation")
|
public void setup() {
|
||||||
public void setup() {
|
user = getConfig().getString("Data.MySQL.username");
|
||||||
user = getConfig().getString("Data.MySQL.username");
|
password = getConfig().getString("Data.MySQL.password");
|
||||||
password = getConfig().getString("Data.MySQL.password");
|
url = "jdbc:mysql://" + getConfig().getString("Data.MySQL.ip") + ":" + getConfig().getInt("Data.MySQL.port") + "/"
|
||||||
url = "jdbc:mysql://" + getConfig().getString("Data.MySQL.ip") + ":"
|
+ getConfig().getString("Data.MySQL.database");
|
||||||
+ getConfig().getInt("Data.MySQL.port") + "/"
|
|
||||||
+ getConfig().getString("Data.MySQL.database");
|
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.average")) {
|
||||||
|
average = false;
|
||||||
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.average")) {
|
} else {
|
||||||
average = false;
|
average = getConfig().getBoolean("Config.MultipleBackpacksInInventory.average");
|
||||||
} else {
|
}
|
||||||
average = getConfig().getBoolean("Config.MultipleBackpacksInInventory.average");
|
|
||||||
}
|
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.add")) {
|
||||||
|
add = false;
|
||||||
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.add")) {
|
} else {
|
||||||
add = false;
|
add = getConfig().getBoolean("Config.MultipleBackpacksInInventory.add");
|
||||||
} else {
|
}
|
||||||
add = getConfig().getBoolean("Config.MultipleBackpacksInInventory.add");
|
|
||||||
}
|
if (!getConfig().isSet("Data.FileSystem")) {
|
||||||
|
usingMysql = false;
|
||||||
if (!getConfig().isSet("Data.FileSystem")) {
|
} else if (getConfig().getString("Data.FileSystem").equalsIgnoreCase("mysql")
|
||||||
usingMysql = false;
|
|| getConfig().getString("Data.FileSystem").equalsIgnoreCase("sql")) {
|
||||||
} else if (getConfig().getString("Data.FileSystem").equalsIgnoreCase("mysql")
|
usingMysql = true;
|
||||||
|| getConfig().getString("Data.FileSystem").equalsIgnoreCase("sql")) {
|
if (!MysqlFunctions.checkIfTableExists("rb_data")) {
|
||||||
usingMysql = true;
|
MysqlFunctions.createTables();
|
||||||
if (!MysqlFunctions.checkIfTableExists("rb_data")) {
|
}
|
||||||
MysqlFunctions.createTables();
|
} else {
|
||||||
}
|
usingMysql = false;
|
||||||
} else {
|
}
|
||||||
usingMysql = false;
|
|
||||||
}
|
if (!getConfig().isSet("Config.usePermissions")) {
|
||||||
|
usingPermissions = true;
|
||||||
if (!getConfig().isSet("Config.usePermissions")) {
|
} else {
|
||||||
usingPermissions = true;
|
usingPermissions = getConfig().getBoolean("Config.usePermissions");
|
||||||
} else {
|
}
|
||||||
usingPermissions = getConfig().getBoolean("Config.usePermissions");
|
|
||||||
}
|
for (final String backpack : backpacks) {
|
||||||
|
|
||||||
for (final String backpack : backpacks) {
|
final String override = getConfig().getString("Backpacks." + backpack + ".Override");
|
||||||
|
if (override != null) {
|
||||||
final String override = getConfig().getString("Backpacks." + backpack + ".Override");
|
backpackOverrides.put(backpack, RBUtil.getItemstackFromString(override));
|
||||||
if (override != null) {
|
} else {
|
||||||
backpackOverrides.put(backpack, RBUtil.getItemstackFromString(override));
|
backpackOverrides.put(backpack, null);
|
||||||
} else {
|
}
|
||||||
backpackOverrides.put(backpack, null);
|
|
||||||
}
|
final List<String> key = backpackData.get(backpack);
|
||||||
|
final String backpackItem = key.get(2);
|
||||||
final List<String> key = backpackData.get(backpack);
|
backpackItems.put(backpack, getConfigLore(RBUtil.getItemstackFromString(backpackItem), backpack));
|
||||||
final String backpackItem = key.get(2);
|
|
||||||
backpackItems.put(backpack,
|
ShapedRecipe recipe = null;
|
||||||
getConfigLore(RBUtil.getItemstackFromString(backpackItem), backpack));
|
if (key.get(1).equalsIgnoreCase("true")) {
|
||||||
|
recipe = new ShapedRecipe(backpackItems.get(backpack));
|
||||||
ShapedRecipe recipe = null;
|
recipe.shape("abc", "def", "ghi");
|
||||||
if (key.get(1).equalsIgnoreCase("true")) {
|
int i = 0;
|
||||||
recipe = new ShapedRecipe(backpackItems.get(backpack));
|
for (final String s : backpackRecipe.get(backpack)) {
|
||||||
recipe.shape("abc", "def", "ghi");
|
final String[] itemIds = s.split(",");
|
||||||
int i = 0;
|
char shapechar = 0;
|
||||||
for (final String s : backpackRecipe.get(backpack)) {
|
for (final String itemid : itemIds) {
|
||||||
final String[] itemIds = s.split(",");
|
i++;
|
||||||
char shapechar = 0;
|
switch (i) {
|
||||||
for (final String itemid : itemIds) {
|
case 1:
|
||||||
i++;
|
shapechar = 'a';
|
||||||
switch (i) {
|
break;
|
||||||
case 1:
|
case 2:
|
||||||
shapechar = 'a';
|
shapechar = 'b';
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 3:
|
||||||
shapechar = 'b';
|
shapechar = 'c';
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 4:
|
||||||
shapechar = 'c';
|
shapechar = 'd';
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
shapechar = 'd';
|
shapechar = 'e';
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 6:
|
||||||
shapechar = 'e';
|
shapechar = 'f';
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 7:
|
||||||
shapechar = 'f';
|
shapechar = 'g';
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 8:
|
||||||
shapechar = 'g';
|
shapechar = 'h';
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 9:
|
||||||
shapechar = 'h';
|
shapechar = 'i';
|
||||||
break;
|
break;
|
||||||
case 9:
|
}
|
||||||
shapechar = 'i';
|
final String[] itemsplit = itemid.split(":");
|
||||||
break;
|
if (itemsplit[0].equals("0")) {
|
||||||
}
|
continue;
|
||||||
final String[] itemsplit = itemid.split(":");
|
}
|
||||||
if (itemsplit[0].equals("0")) {
|
if (itemsplit.length > 1) {
|
||||||
continue;
|
final Material baseblock = Material.getMaterial(Integer.parseInt(itemsplit[0]));
|
||||||
}
|
final MaterialData ingredient = new MaterialData(baseblock, (byte) Integer.parseInt(itemsplit[1]));
|
||||||
if (itemsplit.length > 1) {
|
recipe.setIngredient(shapechar, ingredient);
|
||||||
final Material baseblock = Material.getMaterial(Integer
|
} else {
|
||||||
.parseInt(itemsplit[0]));
|
final Material baseblock = Material.getMaterial(Integer.parseInt(itemsplit[0]));
|
||||||
final MaterialData ingredient = new MaterialData(baseblock,
|
recipe.setIngredient(shapechar, baseblock);
|
||||||
(byte) Integer.parseInt(itemsplit[1]));
|
}
|
||||||
recipe.setIngredient(shapechar, ingredient);
|
}
|
||||||
} else {
|
}
|
||||||
final Material baseblock = Material.getMaterial(Integer
|
getServer().addRecipe(recipe);
|
||||||
.parseInt(itemsplit[0]));
|
}
|
||||||
recipe.setIngredient(shapechar, baseblock);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
private boolean setupEconomy() {
|
||||||
getServer().addRecipe(recipe);
|
if (getServer().getPluginManager().getPlugin("Vault") == null)
|
||||||
}
|
return false;
|
||||||
}
|
final RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
}
|
if (rsp == null)
|
||||||
|
return false;
|
||||||
private boolean setupEconomy() {
|
econ = rsp.getProvider();
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null)
|
return econ != null;
|
||||||
return false;
|
}
|
||||||
final RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager()
|
|
||||||
.getRegistration(Economy.class);
|
public void setupLists() {
|
||||||
if (rsp == null)
|
backpacks.clear();
|
||||||
return false;
|
backpackRecipe.clear();
|
||||||
econ = rsp.getProvider();
|
backpackData.clear();
|
||||||
return econ != null;
|
backpackLore.clear();
|
||||||
}
|
for (final String backpack : getConfig().getConfigurationSection("Backpacks").getKeys(false)) {
|
||||||
|
final List<String> list = new ArrayList<String>();
|
||||||
public void setupLists() {
|
backpacks.add(backpack);
|
||||||
backpacks.clear();
|
list.add(0, getConfig().getString("Backpacks." + backpack + ".Size"));
|
||||||
backpackRecipe.clear();
|
list.add(1, getConfig().getString("Backpacks." + backpack + ".UseRecipe"));
|
||||||
backpackData.clear();
|
if (getConfig().getStringList("Backpacks." + backpack + ".Recipe") != null) {
|
||||||
backpackLore.clear();
|
backpackRecipe.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".Recipe"));
|
||||||
for (final String backpack : getConfig().getConfigurationSection("Backpacks")
|
} else {
|
||||||
.getKeys(false)) {
|
backpackRecipe.put(backpack, null);
|
||||||
final List<String> list = new ArrayList<String>();
|
}
|
||||||
backpacks.add(backpack);
|
list.add(2, getConfig().getString("Backpacks." + backpack + ".BackpackItem.id"));
|
||||||
list.add(0, getConfig().getString("Backpacks." + backpack + ".Size"));
|
list.add(3, getConfig().getString("Backpacks." + backpack + ".BackpackItem.name"));
|
||||||
list.add(1, getConfig().getString("Backpacks." + backpack + ".UseRecipe"));
|
if (getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore") != null) {
|
||||||
if (getConfig().getStringList("Backpacks." + backpack + ".Recipe") != null) {
|
backpackLore.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore"));
|
||||||
backpackRecipe.put(backpack,
|
} else {
|
||||||
getConfig().getStringList("Backpacks." + backpack + ".Recipe"));
|
backpackLore.put(backpack, null);
|
||||||
} else {
|
}
|
||||||
backpackRecipe.put(backpack, null);
|
list.add(4, getConfig().getString("Backpacks." + backpack + ".onDeath.destroyContents"));
|
||||||
}
|
list.add(5, getConfig().getString("Backpacks." + backpack + ".onDeath.dropContents"));
|
||||||
list.add(2, getConfig().getString("Backpacks." + backpack + ".BackpackItem.id"));
|
list.add(6, getConfig().getString("Backpacks." + backpack + ".onDeath.dropBackpack"));
|
||||||
list.add(3, getConfig().getString("Backpacks." + backpack + ".BackpackItem.name"));
|
list.add(7, getConfig().getString("Backpacks." + backpack + ".onDeath.keepBackpack"));
|
||||||
if (getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore") != null) {
|
list.add(8, getConfig().getString("Backpacks." + backpack + ".WalkSpeedFeature.enabled"));
|
||||||
backpackLore.put(backpack,
|
list.add(9, getConfig().getString("Backpacks." + backpack + ".WalkSpeedFeature.walkingSpeed"));
|
||||||
getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore"));
|
list.add(10, getConfig().getString("Backpacks." + backpack + ".IncreasedHungerFeature.enabled"));
|
||||||
} else {
|
list.add(11, getConfig().getString("Backpacks." + backpack + ".IncreasedHungerFeature.extraHungerBarsToDeplete"));
|
||||||
backpackLore.put(backpack, null);
|
list.add(12, getConfig().getString("Backpacks." + backpack + ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating"));
|
||||||
}
|
list.add(13, getConfig().getString("Backpacks." + backpack + ".Purchasable"));
|
||||||
list.add(4, getConfig().getString("Backpacks." + backpack + ".onDeath.destroyContents"));
|
list.add(14, getConfig().getString("Backpacks." + backpack + ".Price"));
|
||||||
list.add(5, getConfig().getString("Backpacks." + backpack + ".onDeath.dropContents"));
|
list.add(15, getConfig().getString("Backpacks." + backpack + ".OpenWith"));
|
||||||
list.add(6, getConfig().getString("Backpacks." + backpack + ".onDeath.dropBackpack"));
|
list.add(16, getConfig().getString("Backpacks." + backpack + ".UseWhitelist"));
|
||||||
list.add(7, getConfig().getString("Backpacks." + backpack + ".onDeath.keepBackpack"));
|
list.add(17, getConfig().getString("Backpacks." + backpack + ".addGlow"));
|
||||||
list.add(8, getConfig()
|
list.add(18, getConfig().getString("Backpacks." + backpack + ".Unstackable"));
|
||||||
.getString("Backpacks." + backpack + ".WalkSpeedFeature.enabled"));
|
backpackData.put(backpack, list);
|
||||||
list.add(
|
backpackBlacklist.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".ItemBlacklist"));
|
||||||
9,
|
backpackWhitelist.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".ItemWhitelist"));
|
||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,271 +1,255 @@
|
|||||||
package cn.citycraft.RealBackpacks.listeners;
|
package cn.citycraft.RealBackpacks.listeners;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
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.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
import cn.citycraft.RealBackpacks.RealBackpacks;
|
||||||
import cn.citycraft.RealBackpacks.RealBackpacks;
|
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 PlayerListener implements Listener {
|
||||||
public class PlayerListener implements Listener {
|
|
||||||
|
private final RealBackpacks plugin;
|
||||||
private final RealBackpacks plugin;
|
|
||||||
|
private final HashMap<String, String> deadPlayers = new HashMap<String, String>();
|
||||||
private final HashMap<String, String> deadPlayers = new HashMap<String, String>();
|
|
||||||
|
public PlayerListener(final RealBackpacks plugin) {
|
||||||
public PlayerListener(final RealBackpacks plugin) {
|
this.plugin = plugin;
|
||||||
this.plugin = plugin;
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
public void onDeath(final PlayerDeathEvent e) {
|
||||||
public void onDeath(final PlayerDeathEvent e) {
|
final Player p = e.getEntity();
|
||||||
final Player p = e.getEntity();
|
final String name = p.getName();
|
||||||
final String name = p.getName();
|
for (final String backpack : plugin.backpacks) {
|
||||||
for (final String backpack : plugin.backpacks) {
|
if (!p.getInventory().contains(plugin.backpackItems.get(backpack))) {
|
||||||
if (!p.getInventory().contains(plugin.backpackItems.get(backpack))) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
p.setWalkSpeed(0.2F);
|
||||||
p.setWalkSpeed(0.2F);
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
if (key.get(5) != null && key.get(5).equalsIgnoreCase("true")) {
|
||||||
if (key.get(5) != null && key.get(5).equalsIgnoreCase("true")) {
|
// Drop contents
|
||||||
// Drop contents
|
Inventory binv = null;
|
||||||
Inventory binv = null;
|
if (plugin.isUsingMysql()) {
|
||||||
if (plugin.isUsingMysql()) {
|
try {
|
||||||
try {
|
binv = MysqlFunctions.getBackpackInv(name, backpack);
|
||||||
binv = MysqlFunctions.getBackpackInv(name, backpack);
|
} catch (final SQLException e1) {
|
||||||
} catch (final SQLException e1) {
|
e1.printStackTrace();
|
||||||
e1.printStackTrace();
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
||||||
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
if (config.getStringList(backpack + ".Inventory") == null) {
|
||||||
if (config.getStringList(backpack + ".Inventory") == null) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
binv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), key.get(3), Integer.parseInt(key.get(0)));
|
||||||
binv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"),
|
}
|
||||||
key.get(3), Integer.parseInt(key.get(0)));
|
if (plugin.playerData.containsKey(name)) {
|
||||||
}
|
if (p.getItemOnCursor() != null) {
|
||||||
if (plugin.playerData.containsKey(name)) {
|
p.setItemOnCursor(null);
|
||||||
if (p.getItemOnCursor() != null) {
|
}
|
||||||
p.setItemOnCursor(null);
|
}
|
||||||
}
|
if (binv != null) {
|
||||||
}
|
for (final ItemStack item : binv.getContents()) {
|
||||||
if (binv != null) {
|
if (item != null) {
|
||||||
for (final ItemStack item : binv.getContents()) {
|
p.getWorld().dropItemNaturally(p.getLocation(), item);
|
||||||
if (item != null) {
|
}
|
||||||
p.getWorld().dropItemNaturally(p.getLocation(), item);
|
}
|
||||||
}
|
}
|
||||||
}
|
RBUtil.destroyContents(name, backpack);
|
||||||
}
|
}
|
||||||
RBUtil.destroyContents(name, backpack);
|
if (key.get(4) != null && key.get(4).equalsIgnoreCase("true")) {
|
||||||
}
|
// Destroy contents
|
||||||
if (key.get(4) != null && key.get(4).equalsIgnoreCase("true")) {
|
RBUtil.destroyContents(name, backpack);
|
||||||
// Destroy contents
|
p.sendMessage(ChatColor.RED + "因为死亡背包物品已销毁...");
|
||||||
RBUtil.destroyContents(name, backpack);
|
}
|
||||||
p.sendMessage(ChatColor.RED + "因为死亡背包物品已销毁...");
|
if (key.get(6) != null && key.get(6).equalsIgnoreCase("false")) {
|
||||||
}
|
// Drop backpack
|
||||||
if (key.get(6) != null && key.get(6).equalsIgnoreCase("false")) {
|
e.getDrops().remove(plugin.backpackItems.get(backpack));
|
||||||
// Drop backpack
|
}
|
||||||
e.getDrops().remove(plugin.backpackItems.get(backpack));
|
if (key.get(7) != null && key.get(7).equalsIgnoreCase("true")) {
|
||||||
}
|
deadPlayers.put(name, backpack);
|
||||||
if (key.get(7) != null && key.get(7).equalsIgnoreCase("true")) {
|
}
|
||||||
deadPlayers.put(name, backpack);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onDrop(final PlayerDropItemEvent e) {
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
final Player p = e.getPlayer();
|
||||||
public void onDrop(final PlayerDropItemEvent e) {
|
final String name = p.getName();
|
||||||
final Player p = e.getPlayer();
|
final ItemStack item = e.getItemDrop().getItemStack();
|
||||||
final String name = p.getName();
|
if (plugin.slowedPlayers.contains(name)) {
|
||||||
final ItemStack item = e.getItemDrop().getItemStack();
|
for (final String backpack : plugin.backpacks) {
|
||||||
if (plugin.slowedPlayers.contains(name)) {
|
if (plugin.backpackItems.get(backpack).equals(item)) {
|
||||||
for (final String backpack : plugin.backpacks) {
|
plugin.slowedPlayers.remove(name);
|
||||||
if (plugin.backpackItems.get(backpack).equals(item)) {
|
p.setWalkSpeed(0.2F);
|
||||||
plugin.slowedPlayers.remove(name);
|
break;
|
||||||
p.setWalkSpeed(0.2F);
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onInteract(final PlayerInteractEvent e) {
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
if (e.getAction().equals(Action.PHYSICAL))
|
||||||
public void onInteract(final PlayerInteractEvent e) {
|
return;
|
||||||
if (e.getAction().equals(Action.PHYSICAL))
|
|
||||||
return;
|
final Action act = e.getAction();
|
||||||
|
final Player p = e.getPlayer();
|
||||||
final Action act = e.getAction();
|
final ItemStack item = p.getItemInHand();
|
||||||
final Player p = e.getPlayer();
|
final String name = p.getName();
|
||||||
final ItemStack item = p.getItemInHand();
|
if (item.hasItemMeta()) {
|
||||||
final String name = p.getName();
|
for (final String backpack : plugin.backpacks) {
|
||||||
if (item.hasItemMeta()) {
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
for (final String backpack : plugin.backpacks) {
|
if (item.getItemMeta().hasDisplayName()
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
&& item.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
|
||||||
if (item.getItemMeta().hasDisplayName()
|
if (plugin.isUsingPerms() && !p.hasPermission("rb." + backpack + ".use")) {
|
||||||
&& item.getItemMeta().getDisplayName()
|
p.sendMessage(ChatColor.RED + "你没有打开此背包的权限...");
|
||||||
.equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
|
continue;
|
||||||
if (plugin.isUsingPerms() && !p.hasPermission("rb." + backpack + ".use")) {
|
}
|
||||||
p.sendMessage(ChatColor.RED + "你没有打开此背包的权限...");
|
final String openWith = key.get(15);
|
||||||
continue;
|
if (openWith != null) {
|
||||||
}
|
if (openWith.equalsIgnoreCase("left_click")) {
|
||||||
final String openWith = key.get(15);
|
if (act.equals(Action.RIGHT_CLICK_AIR)) {
|
||||||
if (openWith != null) {
|
continue;
|
||||||
if (openWith.equalsIgnoreCase("left_click")) {
|
}
|
||||||
if (act.equals(Action.RIGHT_CLICK_AIR)) {
|
if (act.equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (act.equals(Action.RIGHT_CLICK_BLOCK)) {
|
} else if (openWith.equalsIgnoreCase("right_click")) {
|
||||||
continue;
|
if (act.equals(Action.LEFT_CLICK_AIR)) {
|
||||||
}
|
continue;
|
||||||
} else if (openWith.equalsIgnoreCase("right_click")) {
|
}
|
||||||
if (act.equals(Action.LEFT_CLICK_AIR)) {
|
if (act.equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (act.equals(Action.LEFT_CLICK_BLOCK)) {
|
}
|
||||||
continue;
|
} else {
|
||||||
}
|
if (act.equals(Action.LEFT_CLICK_AIR)) {
|
||||||
}
|
continue;
|
||||||
} else {
|
}
|
||||||
if (act.equals(Action.LEFT_CLICK_AIR)) {
|
if (act.equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (act.equals(Action.LEFT_CLICK_BLOCK)) {
|
}
|
||||||
continue;
|
if (act.equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
}
|
e.setCancelled(true);
|
||||||
}
|
p.updateInventory();
|
||||||
if (act.equals(Action.RIGHT_CLICK_BLOCK)) {
|
}
|
||||||
e.setCancelled(true);
|
Inventory inv = null;
|
||||||
p.updateInventory();
|
if (plugin.isUsingMysql()) {
|
||||||
}
|
try {
|
||||||
Inventory inv = null;
|
inv = MysqlFunctions.getBackpackInv(name, backpack);
|
||||||
if (plugin.isUsingMysql()) {
|
} catch (final SQLException e1) {
|
||||||
try {
|
e1.printStackTrace();
|
||||||
inv = MysqlFunctions.getBackpackInv(name, backpack);
|
}
|
||||||
} catch (final SQLException e1) {
|
if (inv == null) {
|
||||||
e1.printStackTrace();
|
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)),
|
||||||
}
|
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||||
if (inv == null) {
|
}
|
||||||
inv = plugin.getServer().createInventory(p,
|
} else {
|
||||||
Integer.parseInt(key.get(0)),
|
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
||||||
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
if (!config.isSet(backpack + ".Inventory")) {
|
||||||
}
|
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)),
|
||||||
} else {
|
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||||
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
} else {
|
||||||
if (!config.isSet(backpack + ".Inventory")) {
|
inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), key.get(3), Integer.parseInt(key.get(0)));
|
||||||
inv = plugin.getServer().createInventory(p,
|
}
|
||||||
Integer.parseInt(key.get(0)),
|
}
|
||||||
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
if (p.getOpenInventory().getTopInventory() != null) {
|
||||||
} else {
|
p.closeInventory();
|
||||||
inv = Serialization.toInventory(
|
}
|
||||||
config.getStringList(backpack + ".Inventory"), key.get(3),
|
plugin.playerData.put(name, backpack);
|
||||||
Integer.parseInt(key.get(0)));
|
p.openInventory(inv);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if (p.getOpenInventory().getTopInventory() != null) {
|
}
|
||||||
p.closeInventory();
|
}
|
||||||
}
|
}
|
||||||
plugin.playerData.put(name, backpack);
|
|
||||||
p.openInventory(inv);
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
break;
|
public void onPickup(final PlayerPickupItemEvent e) {
|
||||||
}
|
final ItemStack item = e.getItem().getItemStack();
|
||||||
}
|
final Player p = e.getPlayer();
|
||||||
}
|
final String name = p.getName();
|
||||||
}
|
for (final String backpack : plugin.backpacks) {
|
||||||
|
if (!item.isSimilar(plugin.backpackItems.get(backpack))) {
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
continue;
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
}
|
||||||
Player player = e.getPlayer();
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
if (player.hasPermission("rb.reload")) {
|
if (!plugin.slowedPlayers.contains(name)) {
|
||||||
RealBackpacks.versionChecker.VersionCheck(player);
|
plugin.slowedPlayers.add(name);
|
||||||
}
|
}
|
||||||
}
|
p.setWalkSpeed(Float.parseFloat(key.get(9)));
|
||||||
|
if (key.get(18) != null && key.get(18).equalsIgnoreCase("true")) {
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
final Inventory inv = p.getInventory();
|
||||||
public void onPickup(final PlayerPickupItemEvent e) {
|
final Location loc = e.getItem().getLocation();
|
||||||
final ItemStack item = e.getItem().getItemStack();
|
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
|
||||||
final Player p = e.getPlayer();
|
int emptySlots = 0, itemAmount = item.getAmount();
|
||||||
final String name = p.getName();
|
for (final ItemStack invItem : inv.getContents()) {
|
||||||
for (final String backpack : plugin.backpacks) {
|
if (invItem == null) {
|
||||||
if (!item.isSimilar(plugin.backpackItems.get(backpack))) {
|
emptySlots++;
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
if (emptySlots == 0) {
|
||||||
if (!plugin.slowedPlayers.contains(name)) {
|
e.setCancelled(true);
|
||||||
plugin.slowedPlayers.add(name);
|
} else {
|
||||||
}
|
e.getItem().remove();
|
||||||
p.setWalkSpeed(Float.parseFloat(key.get(9)));
|
e.setCancelled(true);
|
||||||
if (key.get(18) != null && key.get(18).equalsIgnoreCase("true")) {
|
if (itemAmount > emptySlots) {
|
||||||
final Inventory inv = p.getInventory();
|
final ItemStack dropItem = backpackItem;
|
||||||
final Location loc = e.getItem().getLocation();
|
dropItem.setAmount(itemAmount - emptySlots);
|
||||||
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
|
p.getWorld().dropItem(loc, dropItem);
|
||||||
int emptySlots = 0,itemAmount = item.getAmount();
|
itemAmount = emptySlots;
|
||||||
for (final ItemStack invItem : inv.getContents()) {
|
}
|
||||||
if (invItem == null) {
|
if (itemAmount == 1) {
|
||||||
emptySlots++;
|
backpackItem.setAmount(1);
|
||||||
}
|
inv.setItem(inv.firstEmpty(), backpackItem);
|
||||||
}
|
} else if (itemAmount > 1) {
|
||||||
if (emptySlots == 0) {
|
int x = itemAmount;
|
||||||
e.setCancelled(true);
|
backpackItem.setAmount(1);
|
||||||
} else {
|
while (x > 0) {
|
||||||
e.getItem().remove();
|
x--;
|
||||||
e.setCancelled(true);
|
inv.setItem(inv.firstEmpty(), backpackItem);
|
||||||
if (itemAmount > emptySlots) {
|
}
|
||||||
final ItemStack dropItem = backpackItem;
|
}
|
||||||
dropItem.setAmount(itemAmount - emptySlots);
|
}
|
||||||
p.getWorld().dropItem(loc, dropItem);
|
}
|
||||||
itemAmount = emptySlots;
|
break;
|
||||||
}
|
}
|
||||||
if (itemAmount == 1) {
|
}
|
||||||
backpackItem.setAmount(1);
|
|
||||||
inv.setItem(inv.firstEmpty(), backpackItem);
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
} else if (itemAmount > 1) {
|
public void onRespawn(final PlayerRespawnEvent e) {
|
||||||
int x = itemAmount;
|
final Player p = e.getPlayer();
|
||||||
backpackItem.setAmount(1);
|
final String name = p.getName();
|
||||||
while (x > 0) {
|
for (final String backpack : plugin.backpacks) {
|
||||||
x--;
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
inv.setItem(inv.firstEmpty(), backpackItem);
|
if (key.get(7) != null && key.get(7).equalsIgnoreCase("true") && deadPlayers.get(name) != null && deadPlayers.get(name).equals(backpack)) {
|
||||||
}
|
// Keep backpack
|
||||||
}
|
p.getInventory().addItem(plugin.backpackItems.get(backpack));
|
||||||
}
|
p.updateInventory();
|
||||||
}
|
deadPlayers.remove(name);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
}
|
||||||
public void onRespawn(final PlayerRespawnEvent e) {
|
|
||||||
final Player p = e.getPlayer();
|
|
||||||
final String name = p.getName();
|
|
||||||
for (final String backpack : plugin.backpacks) {
|
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
|
||||||
if (key.get(7) != null && key.get(7).equalsIgnoreCase("true")
|
|
||||||
&& deadPlayers.get(name) != null && deadPlayers.get(name).equals(backpack)) {
|
|
||||||
// Keep backpack
|
|
||||||
p.getInventory().addItem(plugin.backpackItems.get(backpack));
|
|
||||||
p.updateInventory();
|
|
||||||
deadPlayers.remove(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -10,46 +10,96 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
public class VersionChecker {
|
/**
|
||||||
|
* 自动更新类
|
||||||
|
*
|
||||||
|
* @author 蒋天蓓
|
||||||
|
* 2015年8月14日下午4:01:15
|
||||||
|
*/
|
||||||
|
public class VersionChecker implements Listener {
|
||||||
Plugin plugin;
|
Plugin plugin;
|
||||||
|
public String checkurl = "https://coding.net/u/502647092/p/%s/git/raw/%s/src/plugin.yml";
|
||||||
|
public String branch = "master";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param plugin
|
||||||
|
* - 插件
|
||||||
|
*/
|
||||||
public VersionChecker(Plugin plugin) {
|
public VersionChecker(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
this.versioncheck(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void VersionCheck(final Player player) {
|
/**
|
||||||
|
* @param plugin
|
||||||
|
* - 插件
|
||||||
|
* @param branch
|
||||||
|
* - 分支名称
|
||||||
|
*/
|
||||||
|
public VersionChecker(Plugin plugin, String branch) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
this.branch = branch;
|
||||||
|
this.versioncheck(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取插件更新链接
|
||||||
|
*
|
||||||
|
* @param pluginName
|
||||||
|
* - 插件名称
|
||||||
|
* @param branch
|
||||||
|
* - 插件分支
|
||||||
|
* @return 更新链接
|
||||||
|
*/
|
||||||
|
public String getCheckUrl(String pluginName, String branch) {
|
||||||
|
return String.format(checkurl, pluginName, branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
|
if (e.getPlayer().isOp()) {
|
||||||
|
this.versioncheck(e.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始更新
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* - 获取更新的玩家(null则默认为控制台)
|
||||||
|
*/
|
||||||
|
public void versioncheck(final Player player) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String website = plugin.getDescription().getWebsite();
|
String readURL = getCheckUrl(plugin.getName(), branch);
|
||||||
String readURL = website
|
|
||||||
+ (website.substring(website.length() - 1).equals("/") ? "" : "/")
|
|
||||||
+ "/lastSuccessfulBuild/artifact/src/plugin.yml";
|
|
||||||
FileConfiguration config;
|
FileConfiguration config;
|
||||||
String currentVersion = plugin.getDescription().getVersion();
|
String currentVersion = plugin.getDescription().getVersion();
|
||||||
try {
|
try {
|
||||||
URL url = new URL(readURL);
|
URL url = new URL(readURL);
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),
|
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8));
|
||||||
Charsets.UTF_8));
|
|
||||||
config = YamlConfiguration.loadConfiguration(br);
|
config = YamlConfiguration.loadConfiguration(br);
|
||||||
String newVersion = config.getString("version");
|
String newVersion = config.getString("version");
|
||||||
br.close();
|
br.close();
|
||||||
if (!newVersion.equals(currentVersion)) {
|
if (!newVersion.equals(currentVersion)) {
|
||||||
String[] msg = new String[] {
|
String[] msg = new String[] {
|
||||||
ChatColor.GREEN + plugin.getName() + "插件最新版本 v" + newVersion,
|
ChatColor.GREEN + plugin.getName() + " 插件最新版本 v" + newVersion,
|
||||||
ChatColor.RED + "服务器运行版本: v" + currentVersion,
|
ChatColor.RED + "服务器运行版本: v" + currentVersion,
|
||||||
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE
|
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + plugin.getDescription().getWebsite()
|
||||||
+ plugin.getDescription().getWebsite() };
|
};
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.sendMessage(msg);
|
player.sendMessage(msg);
|
||||||
} else {
|
} else {
|
||||||
for (String s : msg) {
|
plugin.getServer().getConsoleSender().sendMessage(msg);
|
||||||
plugin.getLogger().info(s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user