示例#1
0
  public boolean setPlayerInventorySlot(
      String playerName, int slot, int blockID, int damage, int quantity) {
    try {
      if (blockID == 0) {
        return clearPlayerInventorySlot(playerName, slot);
      }

      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it =
          new ItemStack(blockID, quantity, Short.valueOf(String.valueOf(damage)).shortValue());

      if (slot == 103) inv.setHelmet(it);
      else if (slot == 102) inv.setChestplate(it);
      else if (slot == 101) inv.setLeggings(it);
      else if (slot == 100) inv.setBoots(it);
      else inv.setItem(slot, it);

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
示例#2
0
  public boolean setPlayerInventorySlotWithDataAndDamage(
      String playerName, int slot, int blockID, final int data, int damage, int quantity) {
    try {
      if (blockID == 0) {
        return clearPlayerInventorySlot(playerName, slot);
      }

      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();

      ItemStack it = (new MaterialData(blockID, (byte) data)).toItemStack(quantity);
      it.setDurability((short) data);

      if (slot == 103) inv.setHelmet(it);
      else if (slot == 102) inv.setChestplate(it);
      else if (slot == 101) inv.setLeggings(it);
      else if (slot == 100) inv.setBoots(it);
      else inv.setItem(slot, it);

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
  @Override
  public void armorCheck(Player player) {
    if (!player.hasPermission("supernatural.player.ignorearmor")) {
      PlayerInventory inv = player.getInventory();
      ItemStack helmet = inv.getHelmet();
      ItemStack chest = inv.getChestplate();
      ItemStack leggings = inv.getLeggings();
      ItemStack boots = inv.getBoots();

      if (helmet != null) {
        if (!SNConfigHandler.priestArmor.contains(helmet.getType())) {
          inv.setHelmet(null);
          dropItem(player, helmet);
        }
      }
      if (chest != null) {
        if (!SNConfigHandler.priestArmor.contains(chest.getType())) {
          inv.setChestplate(null);
          dropItem(player, chest);
        }
      }
      if (leggings != null) {
        if (!SNConfigHandler.priestArmor.contains(leggings.getType())) {
          inv.setLeggings(null);
          dropItem(player, leggings);
        }
      }
      if (boots != null) {
        if (!SNConfigHandler.priestArmor.contains(boots.getType())) {
          inv.setBoots(null);
          dropItem(player, boots);
        }
      }
    }
  }
  @SuppressWarnings("deprecation")
  public void PlayerSpawn() {
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 8000, 2));

    PlayerInventory i = player.getInventory();
    i.clear();

    i.setHelmet(Colorizer.setColor(new ItemStack(Material.LEATHER_HELMET), 250, 250, 250));
    i.setChestplate(Colorizer.setColor(new ItemStack(Material.LEATHER_CHESTPLATE), 250, 250, 250));

    ItemStack legs = Colorizer.setColor(new ItemStack(Material.LEATHER_LEGGINGS), 250, 250, 250);
    legs.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    i.setLeggings(legs);

    ItemStack boot = Colorizer.setColor(new ItemStack(Material.LEATHER_BOOTS), 250, 250, 250);
    boot.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10);
    i.setBoots(boot);

    ItemStack i1 = new ItemStack(Material.BOW);
    i1.addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, 3);
    i1.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
    i.addItem(i1);

    i.addItem(new ItemStack(Material.ARROW, 1));

    player.updateInventory();
  }
 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;
 }
示例#6
0
  /**
   * Clones the first passed PlayerInventory object to the second one.
   *
   * @param source
   * @param target
   */
  private void clonePlayerInventory(PlayerInventory source, PlayerInventory target) {
    ItemStack[] contents = new ItemStack[source.getContents().length];
    System.arraycopy(source.getContents(), 0, contents, 0, contents.length);
    target.setContents(contents);

    target.setHelmet(cloneItemStack(source.getHelmet()));
    target.setChestplate(cloneItemStack(source.getChestplate()));
    target.setLeggings(cloneItemStack(source.getLeggings()));
    target.setBoots(cloneItemStack(source.getBoots()));
  }
示例#7
0
  public static void setAllContents(Inventory from, Inventory to) {
    to.setContents(from.getContents());
    if (from instanceof PlayerInventory) {
      PlayerInventory pfrom = (PlayerInventory) from;
      if (to instanceof PlayerInventory) {
        PlayerInventory pto = (PlayerInventory) to;

        pto.setHelmet(pfrom.getHelmet());
        pto.setChestplate(pfrom.getChestplate());
        pto.setLeggings(pfrom.getLeggings());
        pto.setBoots(pfrom.getBoots());
      }
    }
  }
示例#8
0
 public static void clearupperson(Player p) {
   p.setAllowFlight(false);
   p.setLevel(0);
   p.setExp(0);
   p.setFoodLevel(20);
   p.setSaturation(10);
   p.setHealth(20D);
   PlayerInventory pi = p.getInventory();
   pi.clear();
   pi.setHeldItemSlot(0);
   ItemStack Air = new ItemStack(Material.AIR);
   pi.setHelmet(Air);
   pi.setChestplate(Air);
   pi.setLeggings(Air);
   pi.setBoots(Air);
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
 }
示例#9
0
 @EventHandler
 public void onPlayerRespawnEvent(PlayerRespawnEvent event) {
   if (event.getPlayer().getName().equals("Esaych")) {
     PlayerInventory eInv = event.getPlayer().getInventory();
     if (eInv.getHelmet() != null) return;
     if (eInv.getChestplate() != null) return;
     if (eInv.getLeggings() != null) return;
     if (eInv.getBoots() != null) return;
     eInv.setHelmet(new ItemStack(Material.LEATHER_HELMET));
     eInv.setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
     eInv.setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
     eInv.setBoots(new ItemStack(Material.LEATHER_BOOTS));
     PlayerInventory inv = event.getPlayer().getInventory();
     colorize(inv.getHelmet(), 47, 0, 111);
     colorize(inv.getChestplate(), 47, 0, 111);
     colorize(inv.getLeggings(), 47, 0, 111);
     colorize(inv.getBoots(), 47, 0, 111);
   }
 }
示例#10
0
  public boolean setPlayerInventorySlotWithDataDamageAndEnchantments(
      String playerName,
      int slot,
      int blockID,
      final int data,
      int damage,
      int quantity,
      Object[] enchantments) {
    try {
      if (blockID == 0) {
        return clearPlayerInventorySlot(playerName, slot);
      }

      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it = (new MaterialData(blockID, (byte) data)).toItemStack(quantity);
      it.setDurability((short) data);

      for (int i = 0; i < enchantments.length; i++) {
        JSONObject o = (JSONObject) enchantments[i];
        it.addEnchantment(
            Enchantment.getById(Integer.valueOf(o.get("enchantment").toString())),
            Integer.valueOf(o.get("level").toString()));
      }

      if (slot == 103) inv.setHelmet(it);
      else if (slot == 102) inv.setChestplate(it);
      else if (slot == 101) inv.setLeggings(it);
      else if (slot == 100) inv.setBoots(it);
      else inv.setItem(slot, it);

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
示例#11
0
  private void equipPlayer(Player player, TeamInfo team) {
    PlayerInventory inv = player.getInventory();
    Color color = team.getDyeColor().getFireworkColor();

    // give them team-dyed armor, and a sword
    ItemStack armor = new ItemStack(Material.LEATHER_CHESTPLATE);

    LeatherArmorMeta meta = ((LeatherArmorMeta) armor.getItemMeta());
    meta.setColor(color);

    armor.setItemMeta(meta);
    inv.setChestplate(armor);

    armor = new ItemStack(Material.LEATHER_CHESTPLATE);
    armor.setItemMeta(meta);
    inv.setLeggings(armor);

    armor = new ItemStack(Material.LEATHER_BOOTS);
    armor.setItemMeta(meta);
    inv.setBoots(armor);

    inv.addItem(new ItemStack(Material.IRON_SWORD));
  }
示例#12
0
 public static void setChestplate(Inventory inventory, ItemStack chestplate) {
   PlayerInventory playerInventory = asPlayerInventory(inventory);
   if (playerInventory == null) return;
   playerInventory.setChestplate(chestplate);
 }
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    if (e.getClickedBlock().getState() instanceof Sign) {
      Sign s = (Sign) e.getClickedBlock().getState();

      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "knight"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "class")) {
          e.getPlayer().sendMessage(ChatColor.RED + "You have chosen the Knight Class");
          ItemStack stonesword = new ItemStack(Material.STONE_SWORD, 1);

          ItemStack ironhelmet = new ItemStack(Material.IRON_HELMET, 1);
          ItemStack ironchest = new ItemStack(Material.IRON_CHESTPLATE, 1);
          ItemStack ironlegs = new ItemStack(Material.IRON_LEGGINGS, 1);
          ItemStack ironboots = new ItemStack(Material.IRON_BOOTS, 1);

          ItemStack strength = new ItemStack(373, 1, (short) 8233);
          ItemStack harming = new ItemStack(373, 1, (short) 16396);
          PlayerInventory pi = player.getInventory();
          pi.clear();
          pi.addItem(stonesword);
          pi.addItem(strength);
          pi.addItem(harming);
          pi.addItem(harming);

          pi.setHelmet(ironhelmet);
          pi.setChestplate(ironchest);
          pi.setLeggings(ironlegs);
          pi.setBoots(ironboots);
          player.updateInventory();
          World world = player.getWorld();
          Location loc = new Location(world, 500, 60, -813);
          player.teleport(loc);
        }

      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "archer"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "class")) {

          e.getPlayer().sendMessage(ChatColor.RED + "You have chosen the Archer Class");
          ItemStack wood = new ItemStack(Material.WOOD_SWORD, 1);
          ItemStack chainhelmet = new ItemStack(Material.CHAINMAIL_HELMET, 1);
          ItemStack chainchest = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
          ItemStack chainlegs = new ItemStack(Material.CHAINMAIL_LEGGINGS, 1);
          ItemStack chainboots = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
          ItemStack bow = new ItemStack(Material.BOW, 1);
          bow.addEnchantment(Enchantment.DURABILITY, 1);
          ItemStack arrow = new ItemStack(Material.ARROW, 64);

          PlayerInventory pi = player.getInventory();
          pi.clear();
          pi.addItem(wood);
          pi.addItem(bow);
          pi.addItem(arrow);
          pi.addItem(arrow);

          pi.setHelmet(chainhelmet);
          pi.setChestplate(chainchest);
          pi.setLeggings(chainlegs);
          pi.setBoots(chainboots);
          player.updateInventory();
          World world = player.getWorld();
          Location loc = new Location(world, 500, 60, -813);
          player.teleport(loc);
        }

      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Wizard"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "class")) {

          e.getPlayer().sendMessage(ChatColor.RED + "You have chosen the Wizard Class");

          ItemStack leatherhelmet = new ItemStack(Material.LEATHER_HELMET, 1);
          ItemStack leatherchest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
          ItemStack leatherlegs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
          ItemStack leatherboots = new ItemStack(Material.LEATHER_BOOTS, 1);
          ItemStack swiftness = new ItemStack(373, 1, (short) 8194);
          ItemStack harming = new ItemStack(373, 4, (short) 16420);
          ItemStack stick = new ItemStack(Material.STICK, 1);
          stick.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 1);
          stick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1);
          PlayerInventory pi = player.getInventory();
          pi.clear();
          pi.addItem(stick);
          pi.addItem(swiftness);
          pi.addItem(harming);
          pi.setHelmet(leatherhelmet);
          pi.setChestplate(leatherchest);
          pi.setLeggings(leatherlegs);
          pi.setBoots(leatherboots);
          player.updateInventory();
          World world = player.getWorld();
          Location loc = new Location(world, 500, 60, -813);
          player.teleport(loc);
        }
      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "farmer"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "class")) {
          e.getPlayer().sendMessage(ChatColor.RED + "You have chosen the Farmer Class");
          ItemStack stonesword = new ItemStack(Material.STONE_SWORD, 1);

          ItemStack ironhelmet = new ItemStack(Material.IRON_HELMET, 1);
          ItemStack ironchest = new ItemStack(Material.IRON_CHESTPLATE, 1);
          ItemStack ironlegs = new ItemStack(Material.IRON_LEGGINGS, 1);
          ItemStack ironboots = new ItemStack(Material.IRON_BOOTS, 1);

          ItemStack strength = new ItemStack(373, 1, (short) 8233);
          ItemStack harming = new ItemStack(373, 1, (short) 16396);
          PlayerInventory pi = player.getInventory();
          pi.clear();
          pi.addItem(stonesword);
          pi.addItem(strength);
          pi.addItem(harming);
          pi.addItem(harming);

          pi.setHelmet(ironhelmet);
          pi.setChestplate(ironchest);
          pi.setLeggings(ironlegs);
          pi.setBoots(ironboots);
          player.updateInventory();
          World world = player.getWorld();
          Location loc = new Location(world, 657, 63, -831, 195, 175);
          player.teleport(loc);
        }

      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "bowman"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "class")) {

          e.getPlayer().sendMessage(ChatColor.RED + "You have chosen the Bowman Class");
          ItemStack wood = new ItemStack(Material.WOOD_SWORD, 1);
          ItemStack chainhelmet = new ItemStack(Material.CHAINMAIL_HELMET, 1);
          ItemStack chainchest = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
          ItemStack chainlegs = new ItemStack(Material.CHAINMAIL_LEGGINGS, 1);
          ItemStack chainboots = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
          ItemStack bow = new ItemStack(Material.BOW, 1);
          bow.addEnchantment(Enchantment.DURABILITY, 1);
          ItemStack arrow = new ItemStack(Material.ARROW, 64);

          PlayerInventory pi = player.getInventory();
          pi.clear();
          pi.addItem(wood);
          pi.addItem(bow);
          pi.addItem(arrow);
          pi.addItem(arrow);

          pi.setHelmet(chainhelmet);
          pi.setChestplate(chainchest);
          pi.setLeggings(chainlegs);
          pi.setBoots(chainboots);
          player.updateInventory();
          World world = player.getWorld();
          Location loc = new Location(world, 657, 63, -831, 195, 175);
          player.teleport(loc);
        }

      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "alchemist"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "class")) {

          e.getPlayer().sendMessage(ChatColor.RED + "You have chosen the Alchemist Class");

          ItemStack leatherhelmet = new ItemStack(Material.LEATHER_HELMET, 1);
          ItemStack leatherchest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
          ItemStack leatherlegs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
          ItemStack leatherboots = new ItemStack(Material.LEATHER_BOOTS, 1);
          ItemStack swiftness = new ItemStack(373, 1, (short) 8194);
          ItemStack harming = new ItemStack(373, 4, (short) 16420);
          ItemStack stick = new ItemStack(Material.STICK, 1);
          stick.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 1);
          stick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1);
          PlayerInventory pi = player.getInventory();
          pi.clear();
          pi.addItem(stick);
          pi.addItem(swiftness);
          pi.addItem(harming);
          pi.setHelmet(leatherhelmet);
          pi.setChestplate(leatherchest);
          pi.setLeggings(leatherlegs);
          pi.setBoots(leatherboots);
          player.updateInventory();
          World world = player.getWorld();
          Location loc = new Location(world, 657, 63, -831, 195, 175);
          player.teleport(loc);
        }

      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "choose side:"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.RED + "village")) {
          World world = player.getWorld();
          Location loc = player.getLocation();
          world.setSpawnLocation(659, 54, -832);
          player.sendMessage(ChatColor.DARK_PURPLE + "You choose the side: Village");
        }
      if (s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "choose side:"))
        if (s.getLine(2).equalsIgnoreCase(ChatColor.RED + "castle")) {
          World world = player.getWorld();
          Location loc = player.getLocation();
          world.setSpawnLocation(484, 75, -813);
          player.sendMessage(ChatColor.DARK_PURPLE + "You choose the side: Castle");
        }
    }
  }