use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.
the class ForceFieldAdapter method onPacketReceiving.
@Override
public void onPacketReceiving(PacketEvent e) {
if (e.isCancelled()) {
return;
}
Player player = e.getPlayer();
ICombatManager combatManager = this.plugin.getCombatManager();
if (!combatManager.isInCombat(player)) {
return;
}
World world = player.getWorld();
PacketContainer packetContainer = e.getPacket();
Location location = getLocation0(world, packetContainer);
if (location == null) {
return;
}
if (isForceFieldBlock(player, location)) {
PacketType packetType = packetContainer.getType();
if (packetType == Client.BLOCK_DIG) {
StructureModifier<PlayerDigType> playerDigTypeModifier = packetContainer.getPlayerDigTypes();
PlayerDigType playerDigType = playerDigTypeModifier.readSafely(0);
GameMode gameMode = player.getGameMode();
if (playerDigType == PlayerDigType.STOP_DESTROY_BLOCK || (playerDigType == PlayerDigType.START_DESTROY_BLOCK && gameMode == GameMode.CREATIVE)) {
this.forceFieldListener.sendForceField(player, location);
}
}
if (packetType == Client.USE_ITEM) {
this.forceFieldListener.sendForceField(player, location);
}
}
}
use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.
the class ForceFieldAdapter method onPacketSending.
@Override
public void onPacketSending(PacketEvent e) {
if (e.isCancelled()) {
return;
}
Player player = e.getPlayer();
ICombatManager combatManager = this.plugin.getCombatManager();
if (!combatManager.isInCombat(player)) {
return;
}
World world = player.getWorld();
PacketContainer packetContainer = e.getPacket();
Location location = getLocation0(world, packetContainer);
if (isForceFieldBlock(player, location)) {
WrappedBlockData wrappedBlockData = getWrappedBlockData();
if (wrappedBlockData != null) {
packetContainer.getBlockData().writeSafely(0, wrappedBlockData);
}
}
}
use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.
the class ListenerForceField method isSafe.
protected boolean isSafe(Player player, Location location) {
ICombatManager combatManager = getCombatManager();
LivingEntity enemy = combatManager.getEnemy(player);
TagType tagType = getTagType(enemy);
return isSafe(player, location, tagType);
}
use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.
the class ListenerDamage method onDamage.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
Entity entity = e.getEntity();
if (!(entity instanceof Player))
return;
if (checkDamageByEntity(e))
return;
Player player = (Player) entity;
DamageCause damageCause = e.getCause();
if (isDisabled(damageCause))
return;
ICombatLogX combatLogX = getCombatLogX();
ICombatManager combatManager = combatLogX.getCombatManager();
boolean wasInCombat = combatManager.isInCombat(player);
boolean tagged = combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
if (tagged && !wasInCombat)
sendMessage(player, damageCause);
}
use of com.github.sirblobman.combatlogx.api.manager.ICombatManager in project CombatLogX by SirBlobman.
the class ListenerMythicMobs method onDamage.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent e) {
Entity damaged = e.getEntity();
Entity damager = e.getDamager();
ICombatManager combatManager = getCombatManager();
if (damaged instanceof Player && damager instanceof LivingEntity && isMythicMob(damager)) {
String mobName = getMythicMobName(damager);
if (isForceTag(mobName)) {
Player playerDamaged = (Player) damaged;
LivingEntity livingDamager = (LivingEntity) damager;
combatManager.tag(playerDamaged, livingDamager, TagType.MYTHIC_MOB, TagReason.ATTACKED);
}
}
if (damager instanceof Player && damaged instanceof LivingEntity && isMythicMob(damaged)) {
String mobName = getMythicMobName(damaged);
if (isForceTag(mobName)) {
Player playerDamager = (Player) damager;
LivingEntity livingDamaged = (LivingEntity) damaged;
combatManager.tag(playerDamager, livingDamaged, TagType.MYTHIC_MOB, TagReason.ATTACKER);
}
}
}
Aggregations