Esempio n. 1
0
 @EventHandler
 public void onBlockPlace(BlockPlaceEvent event) {
   String playerID = PlayerConverter.getID(event.getPlayer());
   // if the player has this objective, the event isn't canceled,
   // the block is correct and conditions are met
   if (containsPlayer(playerID)
       && !event.isCancelled()
       && event.getBlock().getType().equals(material)
       && (data < 0 || event.getBlock().getData() == data)
       && checkConditions(playerID)) {
     // add the block to the total amount
     BlockData playerData = (BlockData) dataMap.get(playerID);
     playerData.add();
     // complete the objective
     if (playerData.getAmount() == neededAmount) {
       completeObjective(playerID);
     } else if (notify) {
       // or maybe display a notification
       if (playerData.getAmount() > neededAmount) {
         Config.sendMessage(
             playerID,
             "blocks_to_break",
             new String[] {String.valueOf(playerData.getAmount() - neededAmount)});
       } else {
         Config.sendMessage(
             playerID,
             "blocks_to_place",
             new String[] {String.valueOf(neededAmount - playerData.getAmount())});
       }
     }
   }
 }
 @EventHandler
 public void onTaming(EntityTameEvent event) {
   if (event.getOwner() instanceof Player) {
     String playerID = PlayerConverter.getID((Player) event.getOwner());
     if (!dataMap.containsKey(playerID)) {
       return;
     }
     LivingEntity entity = event.getEntity();
     TameData playerData = (TameData) dataMap.get(playerID);
     switch (type) {
       case WOLF:
         if (entity.getType().equals(EntityType.WOLF) && checkConditions(playerID)) {
           playerData.subtract();
         }
         break;
       case OCELOT:
         if (entity.getType().equals(EntityType.OCELOT) && checkConditions(playerID)) {
           playerData.subtract();
         }
         break;
       case HORSE:
         if (entity.getType().equals(EntityType.HORSE) && checkConditions(playerID)) {
           playerData.subtract();
         }
         break;
       default:
         break;
     }
     if (playerData.isZero()) {
       completeObjective(playerID);
     }
   }
 }
 @Override
 public String getValue(String playerID) {
   Player player = PlayerConverter.getPlayer(playerID);
   int playersAmount = 0;
   for (ItemStack item : player.getInventory().getContents()) {
     if (item == null) {
       continue;
     }
     if (!questItem.equalsI(item)) {
       continue;
     }
     playersAmount += item.getAmount();
   }
   List<ItemStack> backpackItems = BetonQuest.getInstance().getDBHandler(playerID).getBackpack();
   for (ItemStack item : backpackItems) {
     if (item == null) {
       continue;
     }
     if (!questItem.equalsI(item)) {
       continue;
     }
     playersAmount += item.getAmount();
   }
   switch (type) {
     case AMOUNT:
       return Integer.toString(playersAmount);
     case LEFT:
       return Integer.toString(amount - playersAmount);
     default:
       return "";
   }
 }
 @EventHandler
 public void onLevelUp(PlayerLevelChangeEvent event) {
   String playerID = PlayerConverter.getID(event.getPlayer());
   if (!containsPlayer(playerID)) {
     return;
   }
   if (event.getNewLevel() >= level && checkConditions(playerID)) {
     completeObjective(playerID);
   }
 }
Esempio n. 5
0
 @Override
 public void run(String playerID) {
   Player player = PlayerConverter.getPlayer(playerID);
   for (Item theItem : questItems) {
     QuestItem questItem = theItem.getItem();
     int amount = theItem.getAmount();
     if (notify) {
       player.sendMessage(
           Config.getMessage("items_given")
               .replaceAll(
                   "%name%",
                   (questItem.getName() != null)
                       ? questItem.getName()
                       : questItem.getMaterial().toString())
               .replaceAll("%amount%", String.valueOf(amount))
               .replaceAll("&", "§"));
     }
     while (amount > 0) {
       int stackSize;
       if (amount > 64) {
         stackSize = 64;
       } else {
         stackSize = amount;
       }
       ItemStack item = questItem.generateItem(stackSize);
       HashMap<Integer, ItemStack> left = player.getInventory().addItem(item);
       for (Integer leftNumber : left.keySet()) {
         ItemStack itemStack = left.get(leftNumber);
         if (Utils.isQuestItem(itemStack)) {
           BetonQuest.getInstance().getDBHandler(playerID).addItem(itemStack, stackSize);
         } else {
           player.getWorld().dropItem(player.getLocation(), itemStack);
         }
       }
       amount = amount - stackSize;
     }
   }
 }
 public void run(String playerID) {
   PlayerConverter.getPlayer(playerID).teleport(loc);
 }