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;
}
}
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations