use of de.hglabor.plugins.kitapi.player.KitPlayer in project kit-api by HGLabor.
the class InventoryDetection method onInventoryClickEvent.
/*
* Could be triggered after choosing a kit in a gui
* So it could be set to true even if the selection
* menu closes the gui
* Priority always triggers the listener first
*/
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClickEvent(InventoryClickEvent event) {
KitPlayer kitPlayer = KitApi.getInstance().getPlayer((Player) event.getWhoClicked());
Logger.debug(String.format("%s opened inventory", event.getWhoClicked().getName()));
if (!kitPlayer.isInInventory())
kitPlayer.setInInventory(true);
}
use of de.hglabor.plugins.kitapi.player.KitPlayer in project kit-api by HGLabor.
the class InventoryDetection method onInventoryCloseEvent.
@EventHandler
public void onInventoryCloseEvent(InventoryCloseEvent event) {
KitPlayer kitPlayer = KitApi.getInstance().getPlayer((Player) event.getPlayer());
Logger.debug(String.format("%s closed inventory", event.getPlayer().getName()));
kitPlayer.setInInventory(false);
}
use of de.hglabor.plugins.kitapi.player.KitPlayer in project kit-api by HGLabor.
the class LastHitDetection method onPlayerHitOtherPlayer.
@EventHandler
public void onPlayerHitOtherPlayer(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
KitPlayer attacker = KitApi.getInstance().getPlayer((Player) event.getDamager());
KitPlayer enemy = KitApi.getInstance().getPlayer((Player) event.getEntity());
if (attacker.isValid() && enemy.isValid()) {
LastHitInformation lastHitInformation = attacker.getLastHitInformation();
long NOW = System.currentTimeMillis();
lastHitInformation.setPlayerTimeStamp(NOW);
lastHitInformation.setLastPlayer((Player) event.getEntity());
lastHitInformation.setEntityTimeStamp(NOW);
lastHitInformation.setLastEntity((LivingEntity) event.getEntity());
LastHitInformation lastHitInformationEnemy = enemy.getLastHitInformation();
lastHitInformationEnemy.setLastDamager((Player) event.getDamager());
lastHitInformationEnemy.setLastDamagerTimestamp(NOW);
}
} else if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) {
KitPlayer attacker = KitApi.getInstance().getPlayer((Player) event.getDamager());
if (attacker.isValid()) {
LastHitInformation lastHitInformation = attacker.getLastHitInformation();
lastHitInformation.setEntityTimeStamp(System.currentTimeMillis());
lastHitInformation.setLastEntity((LivingEntity) event.getEntity());
}
}
}
use of de.hglabor.plugins.kitapi.player.KitPlayer in project kit-api by HGLabor.
the class Tracker method onUseTracker.
@EventHandler
public void onUseTracker(PlayerInteractEvent event) {
Player player = event.getPlayer();
Entity target = searchForCompassTarget(player);
KitPlayer kitPlayer = playerList.getKitPlayer(player);
if (event.getMaterial() == Material.COMPASS) {
if (target == null) {
player.sendMessage(t("hglabor.tracker.noTarget", ChatUtils.locale(player)));
} else {
player.setCompassTarget(target.getLocation());
sendTrackingMessage(player, target, kitPlayer);
}
}
}
use of de.hglabor.plugins.kitapi.player.KitPlayer in project kit-api by HGLabor.
the class KitItemSupplierImpl method addKitItemsToInventory.
private void addKitItemsToInventory(KitPlayer kitPlayer, AbstractKit kit, List<ItemStack> extraItems) {
Player player = Bukkit.getPlayer(kitPlayer.getUUID());
if (player == null) {
return;
}
List<ItemStack> kitItems = new ArrayList<>(kit.getKitItems());
kitItems.addAll(extraItems);
// EDGECASE FÜR REVIVE
if (kit.isUsingOffHand()) {
player.getInventory().setItemInOffHand(kit.getMainKitItem());
return;
}
new BukkitRunnable() {
@Override
public void run() {
if (!kitPlayer.isValid() || !player.isValid() || !kitPlayer.hasKit(kit)) {
cancel();
return;
}
while (player.getInventory().firstEmpty() != -1) {
if (kitItems.size() > 0) {
if (!player.getInventory().contains(kitItems.get(0))) {
player.getInventory().addItem(kitItems.get(0));
}
kitItems.remove(0);
} else {
break;
}
}
if (kitItems.isEmpty()) {
cancel();
}
}
}.runTaskTimer(KitApi.getInstance().getPlugin(), 0, 20);
}
Aggregations