コード例 #1
0
 /**
  * Handles players deaths. Checks if the the player was killed player. If the player was killed by
  * the player set the killers name to red.
  *
  * @param event The player death event
  */
 @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
 public void onPlayerDeath(PlayerDeathEvent event) {
   Player killer;
   String nickCommand;
   if (!(event.getEntity().getKiller() == null)) {
     killer = event.getEntity().getKiller();
     // Sets a player to a PEX group with a red name for 4 hours
     nickCommand = ("pex user " + killer.getName() + " group add PlayerKiller * 14400");
     killer.setCustomNameVisible(true);
     plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), nickCommand);
     // Essentials bug workaround, a players name does not change color until /list is called once
     plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "list");
   }
 }
コード例 #2
0
 /**
  * Handles all item pickup events by players. If the item that was picked up is the gem used for
  * money, credit the player $1 and remove the gem.
  *
  * @param event The item pickup event
  */
 @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
 public void onItemPickup(PlayerPickupItemEvent event) {
   Player player = event.getPlayer();
   String giveMoneyCommand = "money give " + player.getName() + " 1";
   if (event.getItem().getItemStack().getItemMeta().equals(moneyGem.getItemMeta())) {
     for (int i = 0; i < event.getItem().getItemStack().getAmount(); i++) {
       plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), giveMoneyCommand);
     }
     if (event.getItem().getItemStack().getAmount() == 1) {
       player.sendMessage(ChatColor.DARK_GREEN + "You have found a rare gem!");
     } else if (event.getItem().getItemStack().getAmount() > 1) {
       player.sendMessage(
           ChatColor.DARK_GREEN
               + "You have found "
               + event.getItem().getItemStack().getAmount()
               + " rare gems!");
     }
     event.getItem().remove();
     event.setCancelled(true);
   }
 }