Search in sources :

Example 1 with KitPlayer

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);
}
Also used : KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with KitPlayer

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);
}
Also used : KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 3 with KitPlayer

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());
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) Player(org.bukkit.entity.Player) LastHitInformation(de.hglabor.plugins.kitapi.pvp.LastHitInformation) KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 4 with KitPlayer

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);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) Player(org.bukkit.entity.Player) KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 5 with 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);
}
Also used : KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

KitPlayer (de.hglabor.plugins.kitapi.player.KitPlayer)132 Player (org.bukkit.entity.Player)105 KitEvent (de.hglabor.plugins.kitapi.kit.events.KitEvent)67 EventHandler (org.bukkit.event.EventHandler)49 ItemStack (org.bukkit.inventory.ItemStack)19 Block (org.bukkit.block.Block)18 LivingEntity (org.bukkit.entity.LivingEntity)18 PotionEffect (org.bukkit.potion.PotionEffect)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)14 Entity (org.bukkit.entity.Entity)11 KitEventHandler (de.hglabor.plugins.kitapi.kit.events.KitEventHandler)9 Location (org.bukkit.Location)8 Material (org.bukkit.Material)8 ArrayList (java.util.ArrayList)6 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 Vector (org.bukkit.util.Vector)5 AbstractKit (de.hglabor.plugins.kitapi.kit.AbstractKit)4 Random (java.util.Random)4 ArmorStand (org.bukkit.entity.ArmorStand)4