Search in sources :

Example 1 with WorldXYZ

use of com.github.sirblobman.api.object.WorldXYZ in project CombatLogX by SirBlobman.

the class ListenerLootProtection method onItemSpawn.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent e) {
    if (this.pendingProtectionMap.isEmpty()) {
        return;
    }
    WorldXYZ location = WorldXYZ.from(e.getLocation());
    if (!this.pendingProtectionMap.containsKey(location)) {
        return;
    }
    Item itemEntity = e.getEntity();
    UUID itemEntityId = itemEntity.getUniqueId();
    ConcurrentLinkedQueue<ProtectedItem> protectedItemQueue = this.pendingProtectionMap.get(location);
    for (ProtectedItem protectedItem : protectedItemQueue) {
        ItemStack protectedItemStack = protectedItem.getItemStack();
        ItemStack itemEntityStack = itemEntity.getItemStack();
        if (protectedItemStack.equals(itemEntityStack)) {
            protectedItem.setItemUUID(itemEntityId);
            this.protectedItemMap.put(itemEntityId, protectedItem);
            protectedItemQueue.remove(protectedItem);
            if (protectedItemQueue.isEmpty()) {
                this.pendingProtectionMap.remove(location);
            }
            return;
        }
    }
}
Also used : Item(org.bukkit.entity.Item) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with WorldXYZ

use of com.github.sirblobman.api.object.WorldXYZ in project CombatLogX by SirBlobman.

the class ForceFieldAdapter method isForceFieldBlock.

private boolean isForceFieldBlock(Player player, Location location) {
    UUID uuid = player.getUniqueId();
    if (this.forceFieldListener.fakeBlockMap.containsKey(uuid)) {
        boolean isSafe = this.forceFieldListener.isSafe(player, location);
        boolean isSafeSurround = this.forceFieldListener.isSafeSurround(player, location);
        boolean canPlace = this.forceFieldListener.canPlace(WorldXYZ.from(location));
        if (isSafe && isSafeSurround && canPlace) {
            WorldXYZ worldXYZ = WorldXYZ.from(location);
            return this.forceFieldListener.fakeBlockMap.get(uuid).contains(worldXYZ);
        }
    }
    return false;
}
Also used : WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) UUID(java.util.UUID)

Example 3 with WorldXYZ

use of com.github.sirblobman.api.object.WorldXYZ in project CombatLogX by SirBlobman.

the class ListenerForceField method safeForceField.

private void safeForceField(Player player, LivingEntity enemy) {
    Set<WorldXYZ> oldArea = new HashSet<>();
    Set<WorldXYZ> newArea = getForceFieldArea(player, enemy);
    Set<WorldXYZ> fullArea = new HashSet<>(newArea);
    UUID uuid = player.getUniqueId();
    if (this.fakeBlockMap.containsKey(uuid)) {
        oldArea = this.fakeBlockMap.get(uuid);
        newArea.removeAll(oldArea);
        oldArea.removeAll(fullArea);
    }
    this.fakeBlockMap.put(uuid, fullArea);
    for (WorldXYZ worldXYZ : newArea) {
        Location location = worldXYZ.asLocation();
        if (location != null)
            sendForceField(player, location);
    }
    for (WorldXYZ worldXYZ : oldArea) {
        Location location = worldXYZ.asLocation();
        if (location != null)
            resetBlock(player, location);
    }
}
Also used : WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) UUID(java.util.UUID) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Example 4 with WorldXYZ

use of com.github.sirblobman.api.object.WorldXYZ in project CombatLogX by SirBlobman.

the class ListenerLootProtection method onDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent e) {
    LivingEntity entity = e.getEntity();
    ICombatLogX combatLogX = getCombatLogX();
    IDeathListener deathListener = combatLogX.getDeathListener();
    YamlConfiguration configuration = getExpansionConfigurationManager().get("config.yml");
    if (entity instanceof Player) {
        Player player = (Player) entity;
        if (configuration.getBoolean("only-protect-after-log", false) && !deathListener.contains(player)) {
            return;
        }
    }
    UUID entityId = entity.getUniqueId();
    UUID enemyId = this.enemyMap.get(entityId);
    if (!checkVoidKill(e) && entity instanceof Player) {
        Player player = (Player) entity;
        PlayerDataManager playerDataManager = getPlayerDataManager();
        YamlConfiguration playerData = playerDataManager.get(player);
        String enemyIdString = playerData.getString("loot-protection-enemy");
        if (enemyIdString != null) {
            playerData.set("loot-protection-enemy", null);
            playerDataManager.save(player);
            enemyId = UUID.fromString(enemyIdString);
        }
    }
    if (enemyId == null) {
        return;
    }
    Entity enemy = Bukkit.getEntity(enemyId);
    if (enemy == null) {
        return;
    }
    enemyId = enemy.getUniqueId();
    WorldXYZ entityLocation = WorldXYZ.from(entity);
    ConcurrentLinkedQueue<ProtectedItem> protectedItemQueue = new ConcurrentLinkedQueue<>();
    List<ItemStack> dropList = e.getDrops();
    for (ItemStack drop : dropList) {
        ProtectedItem protectedItem = new ProtectedItem(entityLocation, drop);
        protectedItem.setOwnerUUID(enemyId);
        protectedItemQueue.add(protectedItem);
    }
    this.pendingProtectionMap.put(entityLocation, protectedItemQueue);
    String entityName = (entity.getCustomName() == null ? entity.getName() : entity.getCustomName());
    long timeLeftMillis = this.protectedItemMap.getExpiration();
    long timeLeftSeconds = TimeUnit.MILLISECONDS.toSeconds(timeLeftMillis);
    String timeLeft = Long.toString(timeLeftSeconds);
    Replacer replacer = message -> message.replace("{time}", timeLeft).replace("{enemy}", entityName);
    sendMessageWithPrefix(enemy, "expansion.loot-protection.enemy-died", replacer, true);
}
Also used : PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) Item(org.bukkit.entity.Item) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) ExpansionListener(com.github.sirblobman.combatlogx.api.expansion.ExpansionListener) ItemSpawnEvent(org.bukkit.event.entity.ItemSpawnEvent) Player(org.bukkit.entity.Player) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) EventHandler(org.bukkit.event.EventHandler) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) Location(org.bukkit.Location) Replacer(com.github.sirblobman.api.language.Replacer) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Bukkit(org.bukkit.Bukkit) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PlayerPunishEvent(com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent) Entity(org.bukkit.entity.Entity) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) ExpiringMap(net.jodah.expiringmap.ExpiringMap) Set(java.util.Set) UUID(java.util.UUID) LivingEntity(org.bukkit.entity.LivingEntity) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ItemStack(org.bukkit.inventory.ItemStack) TimeUnit(java.util.concurrent.TimeUnit) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) Replacer(com.github.sirblobman.api.language.Replacer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) LivingEntity(org.bukkit.entity.LivingEntity) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) UUID(java.util.UUID) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 5 with WorldXYZ

use of com.github.sirblobman.api.object.WorldXYZ in project CombatLogX by SirBlobman.

the class ListenerForceField method getForceFieldArea.

private Set<WorldXYZ> getForceFieldArea(Player player, LivingEntity enemy) {
    World world = player.getWorld();
    WorldXYZ playerXYZ = WorldXYZ.from(player);
    TagType tagType = getTagType(enemy);
    int radius = getForceFieldRadius();
    Set<WorldXYZ> area = new HashSet<>();
    int playerX = playerXYZ.getX(), playerY = playerXYZ.getY(), playerZ = playerXYZ.getZ();
    int minX = (playerX - radius), maxX = (playerX + radius);
    int minZ = (playerZ - radius), maxZ = (playerZ + radius);
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            WorldXYZ worldXYZ = WorldXYZ.from(world, x, playerY, z);
            Location location = worldXYZ.asLocation();
            if (location == null) {
                continue;
            }
            if (!isSafe(player, location, tagType)) {
                continue;
            }
            if (!isSafeSurround(player, location, tagType)) {
                continue;
            }
            for (int y = -radius; y < radius; y++) {
                WorldXYZ worldXYZ2 = WorldXYZ.from(world, x, playerY + y, z);
                if (!canPlace(worldXYZ2)) {
                    continue;
                }
                area.add(worldXYZ2);
            }
        }
    }
    return area;
}
Also used : TagType(com.github.sirblobman.combatlogx.api.object.TagType) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) World(org.bukkit.World) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Aggregations

WorldXYZ (com.github.sirblobman.api.object.WorldXYZ)6 UUID (java.util.UUID)5 Location (org.bukkit.Location)4 HashSet (java.util.HashSet)3 ProtectedItem (combatlogx.expansion.loot.protection.object.ProtectedItem)2 World (org.bukkit.World)2 Item (org.bukkit.entity.Item)2 EventHandler (org.bukkit.event.EventHandler)2 ItemStack (org.bukkit.inventory.ItemStack)2 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)1 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)1 Replacer (com.github.sirblobman.api.language.Replacer)1 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)1 PlayerPunishEvent (com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent)1 PlayerUntagEvent (com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent)1 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)1 ExpansionListener (com.github.sirblobman.combatlogx.api.expansion.ExpansionListener)1 IDeathListener (com.github.sirblobman.combatlogx.api.listener.IDeathListener)1 TagType (com.github.sirblobman.combatlogx.api.object.TagType)1 UntagReason (com.github.sirblobman.combatlogx.api.object.UntagReason)1