mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2024-12-04 03:49:07 +00:00
add VersionCheck while admin join the game...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
60e804875a
commit
ca128c5035
@ -35,13 +35,14 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
|
|
||||||
private static boolean average = false;
|
private static boolean average = false;
|
||||||
private static boolean add = false;
|
private static boolean add = false;
|
||||||
|
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>>();
|
||||||
@ -49,14 +50,13 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
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>();
|
|
||||||
|
|
||||||
private VersionChecker versionChecker;
|
public List<String> slowedPlayers = new ArrayList<String>();
|
||||||
|
|
||||||
// List key
|
// List key
|
||||||
// 0 = Size
|
// 0 = Size
|
||||||
@ -358,12 +358,12 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
11,
|
11,
|
||||||
getConfig().getString(
|
getConfig().getString(
|
||||||
"Backpacks." + backpack
|
"Backpacks." + backpack
|
||||||
+ ".IncreasedHungerFeature.extraHungerBarsToDeplete"));
|
+ ".IncreasedHungerFeature.extraHungerBarsToDeplete"));
|
||||||
list.add(
|
list.add(
|
||||||
12,
|
12,
|
||||||
getConfig().getString(
|
getConfig().getString(
|
||||||
"Backpacks." + backpack
|
"Backpacks." + backpack
|
||||||
+ ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating"));
|
+ ".IncreasedHungerFeature.hungerBarsToSubtractWhenEating"));
|
||||||
list.add(13, getConfig().getString("Backpacks." + backpack + ".Purchasable"));
|
list.add(13, getConfig().getString("Backpacks." + backpack + ".Purchasable"));
|
||||||
list.add(14, getConfig().getString("Backpacks." + backpack + ".Price"));
|
list.add(14, getConfig().getString("Backpacks." + backpack + ".Price"));
|
||||||
list.add(15, getConfig().getString("Backpacks." + backpack + ".OpenWith"));
|
list.add(15, getConfig().getString("Backpacks." + backpack + ".OpenWith"));
|
||||||
|
@ -14,6 +14,7 @@ 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;
|
||||||
@ -36,11 +37,82 @@ public class PlayerListener implements Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onDeath(final PlayerDeathEvent e) {
|
||||||
|
final Player p = e.getEntity();
|
||||||
|
final String name = p.getName();
|
||||||
|
for (final String backpack : plugin.backpacks) {
|
||||||
|
if (!p.getInventory().contains(plugin.backpackItems.get(backpack))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
p.setWalkSpeed(0.2F);
|
||||||
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
|
if (key.get(5) != null && key.get(5).equalsIgnoreCase("true")) {
|
||||||
|
// Drop contents
|
||||||
|
Inventory binv = null;
|
||||||
|
if (plugin.isUsingMysql()) {
|
||||||
|
try {
|
||||||
|
binv = MysqlFunctions.getBackpackInv(name, backpack);
|
||||||
|
} catch (final SQLException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
||||||
|
if (config.getStringList(backpack + ".Inventory") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
binv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"),
|
||||||
|
key.get(3), Integer.parseInt(key.get(0)));
|
||||||
|
}
|
||||||
|
if (plugin.playerData.containsKey(name)) {
|
||||||
|
if (p.getItemOnCursor() != null) {
|
||||||
|
p.setItemOnCursor(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (binv != null) {
|
||||||
|
for (final ItemStack item : binv.getContents()) {
|
||||||
|
if (item != null) {
|
||||||
|
p.getWorld().dropItemNaturally(p.getLocation(), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RBUtil.destroyContents(name, backpack);
|
||||||
|
}
|
||||||
|
if (key.get(4) != null && key.get(4).equalsIgnoreCase("true")) {
|
||||||
|
// Destroy contents
|
||||||
|
RBUtil.destroyContents(name, backpack);
|
||||||
|
p.sendMessage(ChatColor.RED + "因为死亡背包物品已销毁...");
|
||||||
|
}
|
||||||
|
if (key.get(6) != null && key.get(6).equalsIgnoreCase("false")) {
|
||||||
|
// Drop backpack
|
||||||
|
e.getDrops().remove(plugin.backpackItems.get(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) {
|
||||||
|
final Player p = e.getPlayer();
|
||||||
|
final String name = p.getName();
|
||||||
|
final ItemStack item = e.getItemDrop().getItemStack();
|
||||||
|
if (plugin.slowedPlayers.contains(name)) {
|
||||||
|
for (final String backpack : plugin.backpacks) {
|
||||||
|
if (plugin.backpackItems.get(backpack).equals(item)) {
|
||||||
|
plugin.slowedPlayers.remove(name);
|
||||||
|
p.setWalkSpeed(0.2F);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onInteract(final PlayerInteractEvent e) {
|
public void onInteract(final PlayerInteractEvent e) {
|
||||||
if (e.getAction().equals(Action.PHYSICAL)) {
|
if (e.getAction().equals(Action.PHYSICAL))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
final Action act = e.getAction();
|
final Action act = e.getAction();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
@ -49,7 +121,9 @@ public class PlayerListener implements Listener {
|
|||||||
if (item.hasItemMeta()) {
|
if (item.hasItemMeta()) {
|
||||||
for (final String backpack : plugin.backpacks) {
|
for (final String backpack : plugin.backpacks) {
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
if (item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
|
if (item.getItemMeta().hasDisplayName()
|
||||||
|
&& item.getItemMeta().getDisplayName()
|
||||||
|
.equals(ChatColor.translateAlternateColorCodes('&', key.get(3)))) {
|
||||||
if (plugin.isUsingPerms() && !p.hasPermission("rb." + backpack + ".use")) {
|
if (plugin.isUsingPerms() && !p.hasPermission("rb." + backpack + ".use")) {
|
||||||
p.sendMessage(ChatColor.RED + "你没有打开此背包的权限...");
|
p.sendMessage(ChatColor.RED + "你没有打开此背包的权限...");
|
||||||
continue;
|
continue;
|
||||||
@ -91,14 +165,20 @@ public class PlayerListener implements Listener {
|
|||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
if (inv == null) {
|
if (inv == null) {
|
||||||
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
inv = plugin.getServer().createInventory(p,
|
||||||
|
Integer.parseInt(key.get(0)),
|
||||||
|
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
||||||
if (!config.isSet(backpack + ".Inventory")) {
|
if (!config.isSet(backpack + ".Inventory")) {
|
||||||
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
inv = plugin.getServer().createInventory(p,
|
||||||
|
Integer.parseInt(key.get(0)),
|
||||||
|
ChatColor.translateAlternateColorCodes('&', key.get(3)));
|
||||||
} else {
|
} 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) {
|
if (p.getOpenInventory().getTopInventory() != null) {
|
||||||
@ -112,19 +192,11 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onDrop(final PlayerDropItemEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
final Player p = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
final String name = p.getName();
|
if (player.hasPermission("rb.reload")) {
|
||||||
final ItemStack item = e.getItemDrop().getItemStack();
|
RealBackpacks.versionChecker.VersionCheck(player);
|
||||||
if (plugin.slowedPlayers.contains(name)) {
|
|
||||||
for (final String backpack : plugin.backpacks) {
|
|
||||||
if (plugin.backpackItems.get(backpack).equals(item)) {
|
|
||||||
plugin.slowedPlayers.remove(name);
|
|
||||||
p.setWalkSpeed(0.2F);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +218,7 @@ public class PlayerListener implements Listener {
|
|||||||
final Inventory inv = p.getInventory();
|
final Inventory inv = p.getInventory();
|
||||||
final Location loc = e.getItem().getLocation();
|
final Location loc = e.getItem().getLocation();
|
||||||
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
|
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
|
||||||
int emptySlots = 0, itemAmount = item.getAmount();
|
int emptySlots = 0,itemAmount = item.getAmount();
|
||||||
for (final ItemStack invItem : inv.getContents()) {
|
for (final ItemStack invItem : inv.getContents()) {
|
||||||
if (invItem == null) {
|
if (invItem == null) {
|
||||||
emptySlots++;
|
emptySlots++;
|
||||||
@ -180,69 +252,15 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
|
||||||
public void onDeath(final PlayerDeathEvent e) {
|
|
||||||
final Player p = e.getEntity();
|
|
||||||
final String name = p.getName();
|
|
||||||
for (final String backpack : plugin.backpacks) {
|
|
||||||
if (!p.getInventory().contains(plugin.backpackItems.get(backpack))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
p.setWalkSpeed(0.2F);
|
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
|
||||||
if (key.get(5) != null && key.get(5).equalsIgnoreCase("true")) {
|
|
||||||
//Drop contents
|
|
||||||
Inventory binv = null;
|
|
||||||
if (plugin.isUsingMysql()) {
|
|
||||||
try {
|
|
||||||
binv = MysqlFunctions.getBackpackInv(name, backpack);
|
|
||||||
} catch (final SQLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FileConfig config = PlayerConfig.getInstance(plugin, name);
|
|
||||||
if (config.getStringList(backpack + ".Inventory") == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
binv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), key.get(3), Integer.parseInt(key.get(0)));
|
|
||||||
}
|
|
||||||
if (plugin.playerData.containsKey(name)) {
|
|
||||||
if (p.getItemOnCursor() != null) {
|
|
||||||
p.setItemOnCursor(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (binv != null) {
|
|
||||||
for (final ItemStack item : binv.getContents()) {
|
|
||||||
if (item != null) {
|
|
||||||
p.getWorld().dropItemNaturally(p.getLocation(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RBUtil.destroyContents(name, backpack);
|
|
||||||
}
|
|
||||||
if (key.get(4) != null && key.get(4).equalsIgnoreCase("true")) {
|
|
||||||
//Destroy contents
|
|
||||||
RBUtil.destroyContents(name, backpack);
|
|
||||||
p.sendMessage(ChatColor.RED + "因为死亡背包物品已销毁...");
|
|
||||||
}
|
|
||||||
if (key.get(6) != null && key.get(6).equalsIgnoreCase("false")) {
|
|
||||||
//Drop backpack
|
|
||||||
e.getDrops().remove(plugin.backpackItems.get(backpack));
|
|
||||||
}
|
|
||||||
if (key.get(7) != null && key.get(7).equalsIgnoreCase("true")) {
|
|
||||||
deadPlayers.put(name, backpack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onRespawn(final PlayerRespawnEvent e) {
|
public void onRespawn(final PlayerRespawnEvent e) {
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final String name = p.getName();
|
final String name = p.getName();
|
||||||
for (final String backpack : plugin.backpacks) {
|
for (final String backpack : plugin.backpacks) {
|
||||||
final List<String> key = plugin.backpackData.get(backpack);
|
final List<String> key = plugin.backpackData.get(backpack);
|
||||||
if (key.get(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")
|
||||||
//Keep backpack
|
&& deadPlayers.get(name) != null && deadPlayers.get(name).equals(backpack)) {
|
||||||
|
// Keep backpack
|
||||||
p.getInventory().addItem(plugin.backpackItems.get(backpack));
|
p.getInventory().addItem(plugin.backpackItems.get(backpack));
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
deadPlayers.remove(name);
|
deadPlayers.remove(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user