private PlayerInventory getInventory(Player p) {
   String group = getWorldGroup(p.getWorld());
   if (group == null) return null;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(p);
   if (!pcm.exists()) pcm.createFile();
   Integer invSize = pcm.getInt("inventory." + group + ".size");
   final PlayerInventory i = p.getInventory();
   i.clear();
   if (pcm.get("inventory." + group + ".slot") == null) return i;
   for (int slot = 0; slot < invSize; slot++) {
     ItemStack is = pcm.getItemStack("inventory." + group + ".slot." + slot);
     if (is == null) continue;
     i.setItem(slot, is);
   }
   i.setHelmet(pcm.getItemStack("inventory." + group + ".slot.helm"));
   i.setChestplate(pcm.getItemStack("inventory." + group + ".slot.chestplate"));
   i.setLeggings(pcm.getItemStack("inventory." + group + ".slot.leggings"));
   i.setBoots(pcm.getItemStack("inventory." + group + ".slot.boots"));
   if (Config.separateXP) {
     Float xp = pcm.getFloat("inventory." + group + ".xp");
     Integer xpLevel = pcm.getInt("inventory." + group + ".xplevel");
     p.setExp(xp);
     p.setLevel(xpLevel);
   }
   return i;
 }
 private void saveEnderInventory(OfflinePlayer op, String world, Inventory i) {
   if (!Config.separateInv || !Config.separateEnder) return;
   World w = this.plugin.getServer().getWorld(world);
   String group = getWorldGroup(w);
   if (group == null) return;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(op);
   for (int slot = 0; slot < i.getSize(); slot++) {
     pcm.set("inventory." + group + ".ender.slot." + slot, i.getItem(slot));
   }
   pcm.set("inventory." + group + ".ender.size", i.getSize());
 }
 private void saveEnderInventory(Player p, Inventory i) {
   if (!Config.separateInv || !Config.separateEnder) return;
   World w = p.getWorld();
   String group = getWorldGroup(w);
   if (group == null) return;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(p);
   for (int slot = 0; slot < i.getSize(); slot++) {
     pcm.set("inventory." + group + ".ender.slot." + slot, i.getItem(slot));
   }
   pcm.set("inventory." + group + ".ender.size", i.getSize());
 }
示例#4
0
 @Override
 public boolean runCommand(
     final CommandSender cs, final Command cmd, final String label, final String[] args) {
   if (args.length < 1) {
     cs.sendMessage(cmd.getDescription());
     return false;
   }
   final OfflinePlayer t = RUtils.getOfflinePlayer(args[0]);
   if (t.isOnline() && !this.plugin.isVanished((Player) t, cs)) {
     cs.sendMessage(
         MessageColor.POSITIVE
             + "The player "
             + MessageColor.NEUTRAL
             + t.getName()
             + MessageColor.POSITIVE
             + " was last seen "
             + MessageColor.NEUTRAL
             + "now"
             + MessageColor.POSITIVE
             + ".");
     return true;
   }
   final PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(t);
   if (!pcm.exists()) {
     cs.sendMessage(MessageColor.NEGATIVE + "That player doesn't exist!");
     return true;
   }
   if (pcm.get("seen") == null) {
     cs.sendMessage(MessageColor.NEGATIVE + "I don't know when that player was last seen!");
     return true;
   }
   final long seen = pcm.getLong("seen");
   if (seen < 1L) {
     cs.sendMessage(MessageColor.NEGATIVE + "I don't know when that player was last seen!");
     return true;
   }
   final String lastseen = RUtils.formatDateDiff(seen);
   cs.sendMessage(
       MessageColor.POSITIVE
           + "The player "
           + MessageColor.NEUTRAL
           + t.getName()
           + MessageColor.POSITIVE
           + " was last seen"
           + MessageColor.NEUTRAL
           + lastseen
           + MessageColor.POSITIVE
           + " ago.");
   return true;
 }
 private Inventory getEnderInventory(Player p) {
   World w = p.getWorld();
   String group = getWorldGroup(w);
   if (group == null) return null;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(p);
   if (!pcm.exists()) pcm.createFile();
   Integer invSize = pcm.getInt("inventory." + group + ".ender.size");
   final Inventory i = Bukkit.createInventory(p, invSize);
   if (pcm.get("inventory." + group + ".ender.slot") == null) return i;
   for (int slot = 0; slot < invSize; slot++) {
     ItemStack is = pcm.getItemStack("inventory." + group + ".ender.slot." + slot);
     if (is == null) continue;
     i.setItem(slot, is);
   }
   return i;
 }
 public void saveInventory(OfflinePlayer op, String world, Inventory i) {
   if (!Config.separateInv) return;
   String group = this.getWorldGroup(this.plugin.getServer().getWorld(world));
   if (group == null) return;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(op);
   for (int slot = 0; slot < i.getSize(); slot++) {
     pcm.set("inventory." + group + ".slot." + slot, i.getItem(slot));
   }
   if (i instanceof PlayerInventory) {
     PlayerInventory pi = (PlayerInventory) i;
     pcm.set("inventory." + group + ".slot.helm", pi.getHelmet());
     pcm.set("inventory." + group + ".slot.chestplate", pi.getChestplate());
     pcm.set("inventory." + group + ".slot.leggings", pi.getLeggings());
     pcm.set("inventory." + group + ".slot.boots", pi.getBoots());
   }
   pcm.set("inventory." + group + ".size", i.getSize());
 }
 private void saveInventory(Player p, Inventory i, World w) {
   if (!Config.separateInv) return;
   String group = getWorldGroup(w);
   if (group == null) return;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(p);
   for (int slot = 0; slot < i.getSize(); slot++) {
     pcm.set("inventory." + group + ".slot." + slot, i.getItem(slot));
   }
   if (i instanceof PlayerInventory) {
     PlayerInventory pi = (PlayerInventory) i;
     pcm.set("inventory." + group + ".slot.helm", pi.getHelmet());
     pcm.set("inventory." + group + ".slot.chestplate", pi.getChestplate());
     pcm.set("inventory." + group + ".slot.leggings", pi.getLeggings());
     pcm.set("inventory." + group + ".slot.boots", pi.getBoots());
   }
   pcm.set("inventory." + group + ".size", i.getSize());
   if (Config.separateXP) {
     pcm.set("inventory." + group + ".xp", p.getExp());
     pcm.set("inventory." + group + ".xplevel", p.getLevel());
   }
 }
 public Inventory getOfflinePlayerInventory(OfflinePlayer op, String world) {
   final World w = this.plugin.getServer().getWorld(world);
   if (w == null) return null;
   final String group = getWorldGroup(w);
   if (group == null) return null;
   final PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(op);
   if (!pcm.exists()) pcm.createFile();
   final int invSize = pcm.getInt("inventory." + group + ".size");
   final Inventory i =
       this.plugin
           .getServer()
           .createInventory(
               new OfflineInventoryHolder(w, op.getUniqueId()),
               InventoryType.PLAYER.getDefaultSize());
   if (!pcm.isSet("inventory." + group + ".slot")) return i;
   for (int slot = 0; slot < invSize; slot++) {
     final ItemStack is = pcm.getItemStack("inventory." + group + ".slot." + slot);
     if (is == null) continue;
     i.setItem(slot, is);
   }
   return i;
 }