Ejemplo n.º 1
0
 @EventHandler
 public void onEat(FoodLevelChangeEvent event) {
   if (event.getEntity() instanceof Player) {
     if (GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return;
     Player p = (Player) event.getEntity();
     if (GameManager.INSTANCE.getSession(p) == null) return;
     int old = p.getFoodLevel();
     int newLevel = event.getFoodLevel();
     if (newLevel - old > 0) {
       p.setHealth(Math.min(p.getHealth() + 1, p.getMaxHealth()));
     }
   }
 }
Ejemplo n.º 2
0
 @EventHandler
 public void onHealthRegenerate(EntityRegainHealthEvent event) {
   EntityType entityType = event.getEntityType();
   if (entityType.equals(EntityType.PLAYER)) {
     if (GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return;
     if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.SATIATED)) {
       event.setCancelled(true);
     }
   }
 }
Ejemplo n.º 3
0
 @EventHandler
 public void onInteract(PlayerInteractEvent event) {
   if (GameManager.INSTANCE.getSession(event.getPlayer()) == null) return;
   ItemStack item = event.getItem();
   if (item == null
       || (!event.getAction().equals(Action.RIGHT_CLICK_AIR)
           && !event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) return;
   if (item.getType().equals(Material.PAPER) && event.getPlayer().getHealth() != 20) {
     GeneralUtils.subtractItemInHand(event.getPlayer());
     GeneralUtils.addHealthByPaper(event.getPlayer());
   }
   if (event.hasBlock() && !Material.WORKBENCH.equals(event.getClickedBlock().getType()))
     event.setCancelled(true);
 }
Ejemplo n.º 4
0
 @EventHandler
 public void onDamage(EntityDamageByEntityEvent event) {
   if (event.getEntity() instanceof Player == false
       || GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return;
   if (event.getDamager() instanceof Zombie) {
     event.setDamage(
         (int) (Configs.Config.ZOMBIE_DAMAGE_MULTIPLIER.getGlobalDouble() * event.getDamage()));
   } else if (event.getDamager() instanceof Player) {
     Player p = (Player) event.getDamager();
     if (p.getItemInHand().getType().equals(Material.PAPER)) {
       event.setCancelled(true);
       bandage.put(p.getName(), ((Player) event.getEntity()).getName());
       GeneralUtils.subtractItemInHand(p);
     }
   }
 }
Ejemplo n.º 5
0
 @EventHandler
 public void onEntityInteract(PlayerInteractEntityEvent event) {
   if (event.getRightClicked() instanceof Player == false
       || GameManager.INSTANCE.getSession((Player) event.getRightClicked()) == null) return;
   ItemStack item = event.getPlayer().getItemInHand();
   if (item == null) return;
   Player clicked = (Player) event.getRightClicked();
   if (item.getType().equals(Material.SHEARS)) {
     if (bandage.containsKey(event.getPlayer().getName())
         && bandage
             .get(event.getPlayer().getName())
             .equals(((Player) event.getRightClicked()).getName())) {
       GeneralUtils.addHealthByPaper(clicked);
     } else {
       event.getPlayer().sendMessage("Health: " + clicked.getHealth());
     }
   }
 }
Ejemplo n.º 6
0
 @EventHandler
 public void onBlockPlace(BlockPlaceEvent event) {
   if (GameManager.INSTANCE.getSession(event.getPlayer()) != null) {
     event.setCancelled(true);
   }
 }