@EventHandler
 public void onDamage(EntityDamageByEntityEvent event) {
   if (!(event.getEntity() instanceof Player && event.getDamager() instanceof Player))
     return; // We only want to check this if players hit each other
   final Player attacker = (Player) event.getDamager();
   if (attacker.getInventory().getHeldItemSlot() != 8) return;
   final Player victim = (Player) event.getEntity();
   if (AbilityManager.getInstance().getCurrentSpell(attacker) instanceof AbilityHealing) {
     event.setCancelled(true);
     victim.setHealth(victim.getMaxHealth());
     ParticleEffect.HEART.display(
         Vector.getRandom(), 1, victim.getEyeLocation().add(0, 0, .25), Bukkit.getOnlinePlayers());
   }
   if (!(AbilityManager.getInstance().getCurrentSpell(attacker) instanceof AbilityHeartripping))
     return; // Make sure the person punching has heartripping active
   if (!AbilityManager.getInstance().getCurrentSpell(attacker).canUse(attacker)) return;
   if (victim.hasPermission("heart.block")) {
     ChatManager.messageBad(attacker, "That player is too powerful!");
     ChatManager.messageGood(
         victim, attacker.getName() + " attempted to rip out your heart but was too weak!");
     return;
   }
   if (!spellSelection.containsKey(attacker) || !spellSelection.get(attacker).equals(victim)) {
     ChatManager.messageGood(
         attacker, "You ripped " + victim.getName() + "'s heart out of their body!");
     ChatManager.messageBad(
         victim, attacker.getName() + " has ripped your heart out of your body!");
     spellSelection.put(attacker, victim);
   }
   attacker.getInventory().setItemInMainHand(getValidBook(attacker));
 }
예제 #2
0
 public static void startGame() {
   for (int i = 1; i <= 8; i++) {
     if (i > inqueue.size()) {
       break;
     }
     Player p = Bukkit.getPlayer(inqueue.get(i - 1));
     p.setAllowFlight(false);
     p.setFlying(false);
     if (p.getGameMode() != GameMode.SURVIVAL) {
       p.setGameMode(GameMode.SURVIVAL);
     }
     Location loc = Game.getLocation("Spawn" + i).add(0.5, 1, 0.5);
     p.teleport(loc);
     p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10, 2));
     invs.put(p.getName(), p.getInventory().getContents());
     armors.put(p.getName(), p.getInventory().getArmorContents());
     p.getInventory().clear();
     p.getInventory().setBoots(null);
     p.getInventory().setLeggings(null);
     p.getInventory().setChestplate(null);
     p.getInventory().setHelmet(null);
     p.updateInventory();
     p.setWalkSpeed(0.2f);
     ParticleEffect.FIREWORKS_SPARK.display(0.5f, 1f, 0.5f, 0.05f, 20, loc, 100);
     ingame.add(p.getName());
   }
   inqueue.removeAll(ingame);
   sendToAll(Game.tag + "§eGame starting.");
   for (int i = 1; i <= inqueue.size(); i++) {
     int util = i - 1;
     Player p = Bukkit.getPlayer(inqueue.get(util));
     p.sendMessage(
         Game.tag + "§eA game has started, you have been moved to §b" + i + "§e in queue.");
   }
 }
예제 #3
0
  private void doGive(boolean isGift) {
    if (amount == 0) { // give one stack
      amount = Items.maxStackSize(item.getId());
    }

    int slot = who.getInventory().firstEmpty();

    if (slot < 0) {
      who.getWorld().dropItem(who.getLocation(), item.getStack(amount));
    } else {
      who.getInventory().addItem(item.getStack(amount));
    }

    if (isGift) {
      Messaging.send(
          who,
          "&2Enjoy the gift! &f"
              + (amount < 0 ? "infinite" : amount)
              + "&2 of &f"
              + Items.name(item)
              + "&2!");
    } else {
      Messaging.send(
          who,
          "&2Enjoy! Giving &f"
              + (amount < 0 ? "infinite" : amount)
              + "&2 of &f"
              + Items.name(item)
              + "&2.");
    }
  }
예제 #4
0
 @Override
 public boolean use(Player player) {
   boolean containsBow = false;
   for (ItemStack item : player.getInventory().getContents()) {
     if (item.getType() == Material.BOW) {
       containsBow = true;
       break;
     }
   }
   if (containsBow) {
     if (player.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1)) {
       player.launchProjectile(Arrow.class);
       player
           .getInventory()
           .removeItem(
               new ItemStack(Material.ARROW), new ItemStack(Material.FERMENTED_SPIDER_EYE));
       return true;
     } else {
       player.sendMessage(ChatColor.RED + "You require an arrow.");
     }
   } else {
     player.sendMessage(ChatColor.RED + "You require a bow.");
   }
   return false;
 }
예제 #5
0
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onPlayerJoin(PlayerJoinEvent event) {
    if (this.getConfig().getBoolean("clearInventoryOnJoin")) {
      Player p = event.getPlayer();
      p.getInventory().clear();

      if (this.getConfig().getBoolean("backToHubItem")) {
        ItemStack bth = new ItemStack(Material.NETHER_STAR, 1);
        ItemMeta bthMeta = bth.getItemMeta();
        bthMeta.setDisplayName(
            ChatColor.LIGHT_PURPLE + "Back " + ChatColor.GREEN + "To " + ChatColor.BLUE + "Hub");
        bth.setItemMeta(bthMeta);

        p.getInventory().setItem(8, bth);
      }
      if (this.getConfig().getBoolean("quickWarpItem")) {
        ItemStack qw = new ItemStack(Material.COMPASS, 1);
        ItemMeta qwMeta = qw.getItemMeta();
        qwMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Quick Warp");
        qw.setItemMeta(qwMeta);

        p.getInventory().setItem(7, qw);
      }
      p.updateInventory();
    }
  }
예제 #6
0
  public void rebuild() {
    for (String locale : Locale.getLocales()) {
      if (!localeMeta.containsKey(locale)) localeMeta.put(locale, getLocaleMeta("en_GB"));
    }
    for (String locale : Locale.getLocales()) {
      List<String> lines = getTooltipLines(locale);
      ItemMeta meta = getLocaleMeta(locale);
      meta.setDisplayName(lines.get(0));
      lines.remove(0);
      meta.setLore(lines);
      setLocaleMeta(locale, meta);
      // item.setItemMeta(meta);
    }

    for (Player player : Bukkit.getOnlinePlayers()) {
      Iterator<ItemStack> it = player.getInventory().iterator();
      String locale = Locale.getPlayerLocale(player);
      while (it.hasNext()) {
        ItemStack item = it.next();
        if (ItemManager.toRPGItem(item) != null) updateItem(item, locale, false);
      }
      for (ItemStack item : player.getInventory().getArmorContents()) {
        if (ItemManager.toRPGItem(item) != null) updateItem(item, locale, false);
      }
    }
    resetRecipe(true);
  }
예제 #7
0
    @Override
    public void upgrade(Arena arena, Player p) {
      if (item == null) return;

      ItemStack[] items = p.getInventory().getContents();
      int firstEmpty = -1;

      // Find a matching ID and upgrade it
      for (int i = 0; i < 9; i++) {
        // Save the first null index
        if (items[i] == null) {
          if (firstEmpty < 0) firstEmpty = i;
          continue;
        }
        // If we find an ID, upgrade and quit
        if (items[i].getTypeId() == item.getTypeId()) {
          items[i] = item;
          p.getInventory().setContents(items);
          return;
        }
      }

      // If nothing was found, just give them a new weapon
      if (firstEmpty > 0) {
        items[firstEmpty] = item;
        p.getInventory().setContents(items);
      } else {
        p.getInventory().addItem(item);
      }
    }
예제 #8
0
 /**
  * @param currency true - gold
  * @param currency false - silver
  */
 public void giveBanknote(Player player, int amount, boolean currency) {
   String name = ChatColor.GREEN + "Bank Note";
   ItemStack note = new ItemStack(Material.PAPER, 1);
   ArrayList<String> lore = new ArrayList<String>();
   if (currency) {
     lore.add(
         String.valueOf(
             ChatColor.WHITE + "" + amount + " " + ChatColor.BOLD + "" + ChatColor.GOLD + "Gold"));
     lore.add(ChatColor.GRAY + "Exchange at any bank for " + ChatColor.GOLD + "GOLD");
   } else {
     lore.add(
         String.valueOf(
             ChatColor.WHITE
                 + ""
                 + amount
                 + " "
                 + ChatColor.BOLD
                 + ""
                 + ChatColor.WHITE
                 + "Silver"));
     lore.add(ChatColor.GRAY + "Exchange at any bank for " + ChatColor.WHITE + "SILVER");
   }
   setItemText(note, name, lore);
   player.getInventory().setItem(player.getInventory().firstEmpty(), note);
   lore.clear();
 }
예제 #9
0
  public void startModification(Region r, String region, String input, Player p) {
    if (!p.getInventory().contains(new ItemStack(ConfigurationData.defaultSelectionTool, 1))) {
      ItemStack is = new ItemStack(ConfigurationData.defaultSelectionTool, 1);

      p.getInventory().addItem(is);

      if (p.getItemInHand() == new ItemStack(Material.AIR, 0)) {
        p.setItemInHand(is);
      }
    }
    if (r == null) {
      p.sendMessage(
          ChatColor.RED
              + "[Regios] The region "
              + ChatColor.BLUE
              + region
              + ChatColor.RED
              + " doesn't exist!");
      return;
    } else {
      if (!super.canModifyMain(r, p)) {
        p.sendMessage(ChatColor.RED + "[Regios] You are not permitted to modify this region!");
        return;
      }
      p.sendMessage(
          ChatColor.GREEN + "[Regios] Modifying points for region " + ChatColor.BLUE + region);
    }
    CreationCommands.modRegion.put(p, r);
    CreationCommands.modding.put(p, true);
    CreationCommands.setting.put(p, false);
  }
예제 #10
0
  /**
   * Figure out how much of a given item is in the player's inventory
   *
   * @param player The player entity in question.
   * @param id The Data Value of the item in question.
   * @return The amount of the item in the player's inventory as an integer.
   */
  public int getAmountInInventory(Player player, ItemStack it) {
    int inInventory = 0;
    int x = 0;
    ItemStack slot;
    // we do it this way incase a user has an expanded inventory via another plugin
    for (@SuppressWarnings("unused") ItemStack stack : player.getInventory().getContents()) {

      slot = player.getInventory().getItem(x);

      if (slot != null) {
        Byte slotData = Byte.valueOf("0");
        Byte itData = Byte.valueOf("0");

        try {
          slotData = slot.getData().getData();
        } catch (NullPointerException e) {

        }
        try {
          itData = it.getData().getData();
        } catch (NullPointerException e) {

        }

        if ((slot.getTypeId() == it.getTypeId()) && (slotData.compareTo(itData) == 0)) {
          inInventory += slot.getAmount();
        }
      } /*else {
            return 0;
        }*/
      x++;
    }
    return inInventory;
  }
 @EventHandler
 private void entityDamageByEntityEvent(EntityDamageByEntityEvent event) {
   if (event.isCancelled()
       || !(event.getDamager() instanceof Player)
       || !(event.getEntity() instanceof Player)
       || !(RandomPackage.getEnabledEnchantsConfig()
           .getString("Unique.Curse")
           .equalsIgnoreCase("true"))) {
     return;
   } else {
     Player damager = (Player) event.getDamager();
     Player victim = (Player) event.getEntity();
     if (victim.getInventory().getChestplate() == null
         || !(victim.getInventory().getChestplate().hasItemMeta())
         || !(victim.getInventory().getChestplate().getItemMeta().hasLore())) {
       return;
     } else {
       Bukkit.getScheduler()
           .scheduleSyncDelayedTask(
               RandomPackage.getPlugin(),
               new Runnable() {
                 public void run() {
                   if (event.isCancelled()) {
                     return;
                   } else {
                     Random random = new Random();
                     int chance = 8;
                     int duration = 60;
                     for (int i = 1; i <= 3; i++) {
                       chance = chance + 2;
                       duration = duration + 40;
                       if (victim
                               .getInventory()
                               .getChestplate()
                               .getItemMeta()
                               .getLore()
                               .contains(
                                   ChatColor.translateAlternateColorCodes(
                                       '&',
                                       RandomPackage.getPlugin()
                                           .getConfig()
                                           .getString(
                                               "Enchantments.Unique.Curse.Curse"
                                                   + i
                                                   + ".ItemLore")))
                           && random.nextInt(100) <= chance) {
                         damager.addPotionEffect(
                             new PotionEffect(PotionEffectType.SLOW, duration, 4));
                         return;
                       }
                     }
                     return;
                   }
                 }
               },
               1);
       return;
     }
   }
 }
예제 #12
0
  public static void restoreInventory(Player player) {
    player.getInventory().clear();
    player.teleport((Location) locations.get(player.getName()));
    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }
    player.getInventory().setContents((ItemStack[]) inventoryContents.get(player.getName()));
    player.getInventory().setArmorContents((ItemStack[]) armourContents.get(player.getName()));
    player.setExp(((Float) xp.get(player.getName())).floatValue());
    player.setLevel(((Integer) xpLevel.get(player.getName())).intValue());
    player.setGameMode((GameMode) gameModes.get(player.getName()));
    player.addPotionEffects((Collection<PotionEffect>) potions.get(player.getName()));
    player.setFoodLevel(((Integer) foodLevel.get(player.getName())).intValue());
    player.setHealth(((Double) Health.get(player.getName())).doubleValue());
    player.setAllowFlight(((Boolean) flight.get(player.getName())).booleanValue());

    flight.remove(player.getName());
    Health.remove(player.getName());
    foodLevel.remove(player.getName());
    potions.remove(player.getName());
    xpLevel.remove(player.getName());
    xp.remove(player.getName());
    locations.remove(player.getName());
    armourContents.remove(player.getName());
    inventoryContents.remove(player.getName());
    gameModes.remove(player.getName());
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent event) {
    Player p = event.getPlayer();
    if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
      if (p.getItemInHand().getType() == Material.EYE_OF_ENDER) {

        for (Player other : Bukkit.getServer().getOnlinePlayers()) {
          other.hidePlayer(p);
          p.hidePlayer(other);

          Inventory inventory = p.getInventory();
          inventory.setItem(8, new ItemStack(Material.ENDER_PEARL, 1));
        }

      } else if (p.getItemInHand().getType() == Material.ENDER_PEARL) {
        for (Player other : Bukkit.getServer().getOnlinePlayers()) {
          other.showPlayer(p);
          p.showPlayer(other);
          Inventory inventory = p.getInventory();
          inventory.setItem(8, new ItemStack(Material.EYE_OF_ENDER, 1));
        }
      } else if (p.getItemInHand().getType() == Material.GOLD_AXE) {
        p.launchProjectile(EnderPearl.class);
      }
    } else {

    }
  }
예제 #14
0
  /**
   * Set the armor from the given slot as the given item.
   *
   * @param slot Slot of the armor (must be between 0 and 4)
   * @param item Item to set the armor as
   */
  @SuppressWarnings("deprecation")
  public void set(int slot, ItemStack item) {
    if (npc.getBukkitEntity() instanceof Enderman) {
      if (slot != 0) throw new UnsupportedOperationException("Slot can only be 0 for enderman");

      ((Enderman) npc.getBukkitEntity()).setCarriedMaterial(item.getData());
    } else if (npc.getBukkitEntity() instanceof Player) {
      Player player = (Player) npc.getBukkitEntity();
      switch (slot) {
        case 0:
          player.setItemInHand(item);
          break;
        case 1:
          player.getInventory().setHelmet(item);
          break;
        case 2:
          player.getInventory().setChestplate(item);
          break;
        case 3:
          player.getInventory().setLeggings(item);
          break;
        case 4:
          player.getInventory().setBoots(item);
          break;
        default:
          throw new IllegalArgumentException("Slot must be between 0 and 4");
      }
      player.updateInventory();
    }
    equipment[slot] = item;
  }
예제 #15
0
	@SuppressWarnings("deprecation")
	public void restoreState() {
		if (state == null) {
			return;
		}
		
		bukkitPlayer.getInventory().setContents(state.getContents());
		bukkitPlayer.getInventory().setHelmet(state.getHelmet());
		bukkitPlayer.getInventory().setChestplate(state.getChestplate());
		bukkitPlayer.getInventory().setLeggings(state.getLeggings());
		bukkitPlayer.getInventory().setBoots(state.getBoots());
		
		bukkitPlayer.setExhaustion(state.getExhaustion());
		bukkitPlayer.setSaturation(state.getSaturation());
		
		bukkitPlayer.setFoodLevel(state.getFoodLevel());
		bukkitPlayer.setHealth(state.getHealth());
		
		bukkitPlayer.addPotionEffects(state.getPotioneffects());
		
		bukkitPlayer.setLevel(state.getLevel());
		bukkitPlayer.setExp(state.getExp());
		bukkitPlayer.setAllowFlight(state.isFly());
		
		sendMessage(I18N._("stateRestored"));
		bukkitPlayer.updateInventory();
		state = null;
	}
예제 #16
0
  public void applyInventory(final BattlePlayer p) {
    Player pl = (Player) p;
    Inventory i = pl.getInventory();

    ItemStack HEALTH_POTION = new ItemStack(Material.POTION, 1, (short) 16373);
    ItemStack COOKED_FISH = new ItemStack(Material.COOKED_FISH, 2);
    ItemStack BOW = new ItemStack(Material.BOW, 1);
    ItemStack ARROWS = new ItemStack(Material.ARROW, 48);
    ItemStack LEATHER_HELMET = new ItemStack(Material.LEATHER_HELMET, 1);
    ItemStack IRON_CHESTPLATE = new ItemStack(Material.IRON_CHESTPLATE, 1);
    ItemStack CHAINMAIL_PANTS = new ItemStack(Material.CHAINMAIL_LEGGINGS, 1);
    ItemStack GOLD_BOOTS = new ItemStack(Material.GOLD_BOOTS, 1);
    ItemStack IRON_SWORD = new ItemStack(Material.IRON_SWORD, 1);

    ArmourUtils.colourArmourAccordingToTeam(p, new ItemStack[] {LEATHER_HELMET});

    pl.getInventory().setBoots(GOLD_BOOTS);
    pl.getInventory().setLeggings(CHAINMAIL_PANTS);
    pl.getInventory().setChestplate(IRON_CHESTPLATE);
    pl.getInventory().setHelmet(LEATHER_HELMET);

    i.setItem(0, IRON_SWORD);
    i.setItem(1, BOW);
    i.setItem(3, COOKED_FISH);
    i.setItem(4, HEALTH_POTION);
    i.setItem(28, ARROWS);

    if (p.getTeamType() == Team.TDM_BLUE) p.setItem(5, Material.ENDER_PEARL, 2);
  }
예제 #17
0
  private Inventory getFuelInventory(Player player) {

    if (isValidFuelJacket(player.getInventory().getChestplate())) {

      FileConfiguration fuelConfig = getFuelConfig(player);
      Material jacket = player.getInventory().getChestplate().getType();

      int jacketSize = getFuelJacketSize(jacket);
      String jacketType = getFuelJacketConfigString(jacket);

      if (fuelConfig.get(jacketType) != null) {

        Inventory fuelInventory;
        ArrayList<ItemStack> itemStack = new ArrayList<>();

        itemStack.addAll(
            fuelConfig
                .getList(jacketType)
                .stream()
                .map(fuelCurrentItem -> (ItemStack) fuelCurrentItem)
                .collect(Collectors.toList()));

        fuelInventory =
            Bukkit.createInventory(
                player,
                jacketSize,
                "" + ChatColor.DARK_RED + ChatColor.BOLD + "Rocket Boot Fuel Jacket");
        fuelInventory.setContents(itemStack.toArray(new ItemStack[itemStack.size()]));

        return fuelInventory;
      }
    }

    return null;
  }
예제 #18
0
  private void getItem(Player sender, User user, Shop shop, ItemStack item) {
    if (sender == null || user == null || shop == null) return;

    if (item == null || item.getType() == Material.AIR) {
      sender.sendMessage(lang.getColoredMessage(user.getLanguage(), "invaliditem"));
      return;
    }

    EdgeItemStack guiItem = new EdgeItemStack(item);

    if (!shop.getGuiItems().containsKey(guiItem)) {
      sender.sendMessage(lang.getColoredMessage(user.getLanguage(), "shop_getitem_notused"));
      return;
    }

    if (sender.getInventory().firstEmpty() == -1) {
      sender.sendMessage(lang.getColoredMessage(user.getLanguage(), "shop_getitem_nospace"));
      return;
    }

    shop.removeItem(new EdgeItemStack(item));
    sender.getInventory().addItem(item);

    sender.sendMessage(
        lang.getColoredMessage(user.getLanguage(), "shop_getitem_success")
            .replace("[0]", item.getType().name())
            .replace("[1]", shop.getCuboid().getName()));
  }
예제 #19
0
  public static CustomEntityPlayer newInstance(org.bukkit.entity.Player playerDuplicate) {
    WorldServer worldServer = ((CraftWorld) playerDuplicate.getWorld()).getHandle();
    CustomEntityPlayer player =
        new CustomEntityPlayer(
            worldServer.getMinecraftServer(),
            worldServer,
            ((CraftPlayer) playerDuplicate).getHandle().getProfile(),
            new PlayerInteractManager(worldServer));

    Location loc = playerDuplicate.getLocation();
    player.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());

    ((Player) player.getBukkitEntity()).setItemInHand(playerDuplicate.getItemInHand());
    ((Player) player.getBukkitEntity()).setCustomName(playerDuplicate.getName());
    ((Player) player.getBukkitEntity())
        .getEquipment()
        .setArmorContents(playerDuplicate.getInventory().getArmorContents());
    player.setInventory(
        new ArrayList<ItemStack>(Arrays.asList(playerDuplicate.getInventory().getContents())));
    player.getBukkitEntity().setGameMode(GameMode.SURVIVAL);
    player.getBukkitEntity().setCanPickupItems(false);

    ((Player) player.getBukkitEntity()).setHealthScale(playerDuplicate.getHealthScale());
    ((Player) player.getBukkitEntity()).setMaxHealth(playerDuplicate.getMaxHealth());
    ((Player) player.getBukkitEntity()).setHealth(playerDuplicate.getHealth());
    ((Player) player.getBukkitEntity()).setRemoveWhenFarAway(false);

    worldServer.addEntity(player, SpawnReason.CUSTOM);

    return player;
  }
 @EventHandler
 public void onBreak(BlockBreakEvent bbe) {
   if (!(bbe.isCancelled())) {
     Block block = bbe.getBlock();
     if (bbe.getPlayer() != null) {
       Player breaker = bbe.getPlayer();
       UUID uuid = breaker.getUniqueId();
       if (block.getState().getType().equals(Material.REDSTONE_ORE)
           || block.getType().equals(Material.REDSTONE_ORE)) {
         boolean notSilkTouch = true;
         if (breaker.getInventory().getItemInHand() != null) {
           ItemStack handItem = breaker.getInventory().getItemInHand();
           if (handItem.containsEnchantment(Enchantment.SILK_TOUCH)) {
             notSilkTouch = false;
           }
         }
         boolean lowLevel = true;
         int level = LevelManager.getLevel(breaker);
         if (level > 30) {
           lowLevel = false;
         }
         if (notSilkTouch && lowLevel) {
           int broke = LevelingXP_Breaking.get(uuid);
           broke += 1;
           if (broke >= (10 * LevelManager.getLevel(breaker))) {
             XPmanager.giveXP(breaker, 80);
           } else {
             LevelingXP_Breaking.set(uuid, broke);
           }
         }
       }
     }
   }
 }
예제 #21
0
 public static void resetPlayer(Player player) {
   player.setHealth(player.getMaxHealth());
   player.setFoodLevel(20);
   player.setSaturation(20);
   player.getInventory().clear();
   player
       .getInventory()
       .setArmorContents(
           new ItemStack[] {
             new ItemStack(Material.AIR),
             new ItemStack(Material.AIR),
             new ItemStack(Material.AIR),
             new ItemStack(Material.AIR)
           });
   for (PotionEffect effect : player.getActivePotionEffects()) {
     try {
       player.removePotionEffect(effect.getType());
     } catch (NullPointerException ignored) {
     }
   }
   player.setTotalExperience(0);
   player.setExp(0);
   player.setPotionParticles(true);
   player.setWalkSpeed(0.2F);
   player.setFlySpeed(0.2F);
 }
예제 #22
0
  public void doMake(Player player) throws IOException {
    int num = 1;
    ItemStack item = null;
    BookMeta bm = null;

    FileInputStream fstream =
        new FileInputStream(getDataFolder() + "/" + "Great Expectations-Charles Dickens.txt");
    BufferedInputStream buff = new BufferedInputStream(fstream);
    byte buffer[] = new byte[200];
    int page = 0;
    while (buff.read(buffer) != -1) {
      page++;
      if (page > 300 || bm == null) {
        if (page > 300 && bm != null) {
          page = 0;
          num++;
          item.setItemMeta(bm);
          player.getInventory().addItem(item);
        }

        item = new ItemStack(Material.WRITTEN_BOOK);
        bm = (BookMeta) item.getItemMeta();
        bm.setTitle("Great Expectations Vol. " + num);
        bm.setAuthor("Charles Dickens");
      }
      bm.addPage(new String(buffer));
    }

    item.setItemMeta(bm);
    player.getInventory().addItem(item);
  }
예제 #23
0
  @Override
  public boolean finalizeTransaction(TransactionInfo info) {
    String stock = info.getStock().name().toLowerCase();
    Player player = info.getPlayerParticipant();
    int amount = info.getAmount();

    boolean result = false;
    int endAmount = amount * this.amount;
    ItemStack clone = is.clone();
    clone.setAmount(endAmount);

    if (stock == "sell") {
      ItemStack[] contents = player.getInventory().getContents();
      for (int i = 0; i < contents.length && endAmount > 0; ++i) {
        ItemStack nItem = contents[i];
        if (nItem != null && nItem.isSimilar(clone)) {
          int diff = endAmount - nItem.getAmount();
          if (diff < 0) nItem.setAmount(-diff);
          else player.getInventory().setItem(i, null);
          endAmount = diff;
        }
      }
      result = true;
    } else if (stock == "buy") {
      player.getInventory().addItem(clone);
      result = true;
    }
    return result;
  }
예제 #24
0
 public static void addInventory(Player player) {
   HPlayer.get(player.getName()).storeInventory("splegg", player.getInventory().getContents());
   HPlayer.get(player.getName())
       .storeInventory("splegg_armour", player.getInventory().getArmorContents());
   player.getInventory().clear();
   player.getInventory().setItem(0, new ItemStack(Material.IRON_SPADE));
 }
예제 #25
0
 @EventHandler
 public void onInteract(PlayerInteractEvent pie) {
   if (pie.getAction().equals(Action.RIGHT_CLICK_BLOCK)
       || pie.getAction().equals(Action.RIGHT_CLICK_AIR)) {
     Player player = pie.getPlayer();
     World world = player.getWorld();
     if (player.getInventory().getItemInHand() != null) {
       ItemStack item = player.getInventory().getItemInHand();
       if (item.getType().equals(Material.DOUBLE_PLANT)) {
         pie.setCancelled(true);
         Item bomb = world.dropItem(player.getEyeLocation(), new ItemStack(Material.GOLD_BLOCK));
         bomb.setPickupDelay(Integer.MAX_VALUE);
         bomb.setVelocity(player.getLocation().getDirection().multiply(0.5));
         double radius = 1.5;
         for (double i = 0; i <= 20D; i += 0.1) {
           Item coin = world.dropItem(bomb.getLocation(), new ItemStack(Material.DOUBLE_PLANT));
           double x = Math.sin(radius * i);
           double z = Math.cos(radius * i);
           Bukkit.getScheduler()
               .scheduleSyncDelayedTask(
                   Factions.instance,
                   new Runnable() {
                     public void run() {}
                   },
                   1);
         }
       }
     }
   }
 }
  @EventHandler(priority = EventPriority.NORMAL)
  public void applyInventory(InventoryEvent event) {

    String par = event.getMessage();
    Player p = event.getPlayer();
    Inventory i = p.getInventory();
    if (par.equalsIgnoreCase(name)) {
      clearInv(p);

      ItemStack HEALTH_POTION = new ItemStack(Material.POTION, 1, (short) 16373);
      ItemStack STEAK = new ItemStack(Material.COOKED_BEEF, 1);
      ItemStack BOW = new ItemStack(Material.BOW, 1);
      ItemStack FISHING_ROD = new ItemStack(Material.FISHING_ROD, 1);
      ItemStack ARROWS = new ItemStack(Material.ARROW, 64);
      ItemStack IRON_HELMET = new ItemStack(Material.IRON_HELMET, 1);
      ItemStack IRON_CHESTPLATE = new ItemStack(Material.IRON_CHESTPLATE, 1);
      ItemStack IRON_PANTS = new ItemStack(Material.IRON_LEGGINGS, 1);
      ItemStack IRON_BOOTS = new ItemStack(Material.IRON_BOOTS, 1);
      ItemStack IRON_SWORD = new ItemStack(Material.IRON_SWORD, 1);

      p.getInventory().setBoots(IRON_BOOTS);
      p.getInventory().setLeggings(IRON_PANTS);
      p.getInventory().setChestplate(IRON_CHESTPLATE);
      p.getInventory().setHelmet(IRON_HELMET);

      i.setItem(0, IRON_SWORD);
      i.setItem(1, FISHING_ROD);
      i.setItem(2, BOW);
      i.setItem(3, STEAK);
      i.setItem(4, HEALTH_POTION);
      i.setItem(5, ARROWS);
    }
  }
예제 #27
0
  public void createDuel(Player p1, Player p2, String mode) {
    Duel duel = new Duel(this.plugin, p1.getName(), p2.getName(), mode);

    this.invites.removeAll(p1.getName());
    this.invites.removeAll(p2.getName());

    p1.getInventory().clear();
    p2.getInventory().clear();

    p1.updateInventory();
    p2.updateInventory();

    p1.setHealth(20.0D);
    p2.setHealth(20.0D);

    this.duels.add(duel);
    duel.setTaskID(Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, duel, 0L, 10L));
    for (String s : ovo) {
      Player p = Bukkit.getPlayerExact(s);
      if ((!p.getName().equals(p1.getName())) && (!p.getName().equals(p2.getName()))) {
        p1.hidePlayer(p);
        p2.hidePlayer(p);
      }
    }
  }
예제 #28
0
  public void pay(Player p, double amt) {
    if (this.usingItemsForPayment()) {
      int amtNeeded = (int) Math.ceil(amt);

      for (int i = 0; i < p.getInventory().getSize(); i++) {
        ItemStack it = p.getInventory().getItem(i);

        // The item is either air or we doesn't match out needs
        if (it == null || it.getType() != this.item) continue;

        // If the itemstack has more than or equal to the amount
        // that we need, remove it and subject from the amt needed
        if (amtNeeded >= it.getAmount()) {
          amtNeeded -= it.getAmount();
          p.getInventory().clear(i);
        } else {
          // Otherwise, subject from the itemstack just the amount we need
          it.setAmount(it.getAmount() - amtNeeded);
          p.getInventory().setItem(i, it);
          amtNeeded = 0;
        }

        if (amtNeeded == 0) break;
      }
    } else {
      this.economy.withdrawPlayer(p, amt);
    }
  }
예제 #29
0
  @Override
  public boolean effect(Event event, Player player) {
    int slot = player.getInventory().getHeldItemSlot();

    ItemStack potion = player.getInventory().getItem(slot + 1);
    Location loc = player.getLocation();
    if (potion != null && potion.getType().toString().contains("POTION")) {
      ThrownPotion tp = player.launchProjectile(ThrownPotion.class);
      EffectManager.playSound(loc, "ENTITY_GENERIC_EXPLODE", 0.5f, 2f);

      try {
        tp.setItem(potion);
      } catch (IllegalArgumentException ex) {
        ItemStack pt = potion.clone();
        if (potion.getType().equals(Material.POTION)
            || potion.getType().equals(Material.LINGERING_POTION))
          pt.setType(Material.SPLASH_POTION);
        tp.setItem(pt);
      }

      tp.setBounce(false);
      tp.setVelocity(loc.getDirection().multiply(ProjectileSpeedMultiplier));
      if (!player.getGameMode().equals(GameMode.CREATIVE)) {
        potion.setAmount(potion.getAmount() - 1);
        player.getInventory().setItem(slot + 1, potion);
        player.updateInventory();
      }
      return true;
    } else {
      player.sendMessage(
          ChatColor.RED + "You need a Potion in the slot to the right of the Potion Launcher!");
      player.getWorld().playEffect(loc, Effect.CLICK1, 5);
    }
    return false;
  }
예제 #30
0
 @Override
 public void addParticipant(Player p) {
   Initialise.pushStatistics(p);
   participants.add(p);
   previousLocation.put(p, SoloPool.locs.get(p));
   invent.put(p, p.getInventory().getContents());
   inventArmour.put(p, p.getInventory().getArmorContents());
 }