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
@ -174,8 +174,7 @@ public class RealBackpacks extends JavaPlugin {
|
||||
getLogger().info("真实背包已加载 By: 喵♂呜.");
|
||||
}
|
||||
}
|
||||
versionChecker = new VersionChecker(this);
|
||||
versionChecker.VersionCheck(null);
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,8 +194,7 @@ public class RealBackpacks extends JavaPlugin {
|
||||
public void setup() {
|
||||
user = getConfig().getString("Data.MySQL.username");
|
||||
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().getInt("Data.MySQL.port") + "/"
|
||||
+ getConfig().getString("Data.MySQL.database");
|
||||
|
||||
if (!getConfig().isSet("Config.MultipleBackpacksInInventory.average")) {
|
||||
@ -240,8 +238,7 @@ public class RealBackpacks extends JavaPlugin {
|
||||
|
||||
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")) {
|
||||
@ -287,14 +284,11 @@ 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,
|
||||
(byte) Integer.parseInt(itemsplit[1]));
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -307,8 +301,7 @@ public class RealBackpacks extends JavaPlugin {
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null)
|
||||
return false;
|
||||
final RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager()
|
||||
.getRegistration(Economy.class);
|
||||
final RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null)
|
||||
return false;
|
||||
econ = rsp.getProvider();
|
||||
@ -320,23 +313,20 @@ public class RealBackpacks extends JavaPlugin {
|
||||
backpackRecipe.clear();
|
||||
backpackData.clear();
|
||||
backpackLore.clear();
|
||||
for (final String backpack : getConfig().getConfigurationSection("Backpacks")
|
||||
.getKeys(false)) {
|
||||
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"));
|
||||
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"));
|
||||
backpackLore.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".BackpackItem.lore"));
|
||||
} else {
|
||||
backpackLore.put(backpack, null);
|
||||
}
|
||||
@ -344,26 +334,11 @@ public class RealBackpacks extends JavaPlugin {
|
||||
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(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"));
|
||||
@ -371,10 +346,8 @@ public class RealBackpacks extends JavaPlugin {
|
||||
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"));
|
||||
backpackBlacklist.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".ItemBlacklist"));
|
||||
backpackWhitelist.put(backpack, getConfig().getStringList("Backpacks." + backpack + ".ItemWhitelist"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -61,8 +60,7 @@ public class PlayerListener implements Listener {
|
||||
if (config.getStringList(backpack + ".Inventory") == null) {
|
||||
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) {
|
||||
@ -122,8 +120,7 @@ public class PlayerListener implements Listener {
|
||||
for (final String backpack : plugin.backpacks) {
|
||||
final List<String> key = plugin.backpackData.get(backpack);
|
||||
if (item.getItemMeta().hasDisplayName()
|
||||
&& item.getItemMeta().getDisplayName()
|
||||
.equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
|
||||
&& item.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
|
||||
if (plugin.isUsingPerms() && !p.hasPermission("rb." + backpack + ".use")) {
|
||||
p.sendMessage(ChatColor.RED + "你没有打开此背包的权限...");
|
||||
continue;
|
||||
@ -165,20 +162,16 @@ public class PlayerListener implements Listener {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (inv == null) {
|
||||
inv = plugin.getServer().createInventory(p,
|
||||
Integer.parseInt(key.get(0)),
|
||||
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)),
|
||||
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||
}
|
||||
} else {
|
||||
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
||||
if (!config.isSet(backpack + ".Inventory")) {
|
||||
inv = plugin.getServer().createInventory(p,
|
||||
Integer.parseInt(key.get(0)),
|
||||
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)),
|
||||
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||
} else {
|
||||
inv = Serialization.toInventory(
|
||||
config.getStringList(backpack + ".Inventory"), key.get(3),
|
||||
Integer.parseInt(key.get(0)));
|
||||
inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), key.get(3), Integer.parseInt(key.get(0)));
|
||||
}
|
||||
}
|
||||
if (p.getOpenInventory().getTopInventory() != null) {
|
||||
@ -192,14 +185,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
if (player.hasPermission("rb.reload")) {
|
||||
RealBackpacks.versionChecker.VersionCheck(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPickup(final PlayerPickupItemEvent e) {
|
||||
final ItemStack item = e.getItem().getItemStack();
|
||||
@ -258,8 +243,7 @@ public class PlayerListener implements Listener {
|
||||
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)) {
|
||||
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();
|
||||
|
@ -10,31 +10,83 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
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 com.google.common.base.Charsets;
|
||||
|
||||
public class VersionChecker {
|
||||
/**
|
||||
* 自动更新类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月14日下午4:01:15
|
||||
*/
|
||||
public class VersionChecker implements Listener {
|
||||
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) {
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
String website = plugin.getDescription().getWebsite();
|
||||
String readURL = website
|
||||
+ (website.substring(website.length() - 1).equals("/") ? "" : "/")
|
||||
+ "/lastSuccessfulBuild/artifact/src/plugin.yml";
|
||||
String readURL = getCheckUrl(plugin.getName(), branch);
|
||||
FileConfiguration config;
|
||||
String currentVersion = plugin.getDescription().getVersion();
|
||||
try {
|
||||
URL url = new URL(readURL);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),
|
||||
Charsets.UTF_8));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8));
|
||||
config = YamlConfiguration.loadConfiguration(br);
|
||||
String newVersion = config.getString("version");
|
||||
br.close();
|
||||
@ -42,14 +94,12 @@ public class VersionChecker {
|
||||
String[] msg = new String[] {
|
||||
ChatColor.GREEN + plugin.getName() + " 插件最新版本 v" + newVersion,
|
||||
ChatColor.RED + "服务器运行版本: v" + currentVersion,
|
||||
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE
|
||||
+ plugin.getDescription().getWebsite() };
|
||||
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + plugin.getDescription().getWebsite()
|
||||
};
|
||||
if (player != null) {
|
||||
player.sendMessage(msg);
|
||||
} else {
|
||||
for (String s : msg) {
|
||||
plugin.getLogger().info(s);
|
||||
}
|
||||
plugin.getServer().getConsoleSender().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user