2019-11-25 06:29:25 +00:00
package com.burnedkirby.TurnBasedMinecraft.common ;
2018-08-28 06:13:14 +00:00
2019-11-25 06:29:25 +00:00
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage ;
2022-05-17 05:47:42 +00:00
import net.minecraft.resources.ResourceKey ;
import net.minecraft.server.level.ServerPlayer ;
import net.minecraft.world.entity.Entity ;
import net.minecraft.world.entity.monster.Creeper ;
import net.minecraft.world.entity.player.Player ;
import net.minecraft.world.level.Level ;
import net.minecraftforge.common.MinecraftForge ;
2018-08-28 06:13:14 +00:00
import net.minecraftforge.event.entity.living.LivingAttackEvent ;
2023-03-31 05:22:58 +00:00
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent ;
2022-05-17 05:47:42 +00:00
import net.minecraftforge.network.PacketDistributor ;
import org.apache.logging.log4j.Logger ;
import java.util.* ;
2018-08-28 06:13:14 +00:00
public class BattleManager
{
private int IDCounter = 0 ;
protected Map < Integer , Battle > battleMap ;
2018-09-12 05:43:59 +00:00
private Logger logger ;
2018-10-17 09:28:47 +00:00
private Map < Integer , Combatant > recentlyLeftBattle ;
2019-10-25 07:42:54 +00:00
private BattleUpdater battleUpdater ;
2019-11-29 04:47:39 +00:00
private Map < EntityIDDimPair , Integer > entityToBattleMap ;
2022-08-24 05:03:45 +00:00
private EntityIDDimPair tempIDPair ;
2022-05-17 05:47:42 +00:00
2018-09-12 05:43:59 +00:00
public BattleManager ( Logger logger )
2018-08-28 06:13:14 +00:00
{
2018-09-12 05:43:59 +00:00
this . logger = logger ;
2018-10-18 04:34:57 +00:00
battleMap = new HashMap < Integer , Battle > ( ) ;
2018-10-17 09:28:47 +00:00
recentlyLeftBattle = new HashMap < Integer , Combatant > ( ) ;
2019-10-25 07:42:54 +00:00
battleUpdater = new BattleUpdater ( this ) ;
2019-11-29 04:47:39 +00:00
entityToBattleMap = new HashMap < EntityIDDimPair , Integer > ( ) ;
2019-10-25 07:42:54 +00:00
MinecraftForge . EVENT_BUS . register ( battleUpdater ) ;
2022-08-24 05:03:45 +00:00
tempIDPair = new EntityIDDimPair ( ) ;
2018-08-28 06:13:14 +00:00
}
/ * *
* Either creates a new Battle , adds a combatant to an existing Battle , or does
* nothing , depending on if a player is involved and / or an entity is currently
* in battle .
*
* @param event
* @return True if event should be canceled
* /
public boolean checkAttack ( final LivingAttackEvent event )
{
2018-10-26 05:18:48 +00:00
Config config = TurnBasedMinecraftMod . proxy . getConfig ( ) ;
2019-10-25 07:42:54 +00:00
String receiverClassName = event . getEntity ( ) . getClass ( ) . getName ( ) ;
String receiverCustomName ;
2019-11-28 07:32:34 +00:00
2019-10-25 07:42:54 +00:00
try {
2021-05-21 05:44:31 +00:00
receiverCustomName = event . getEntity ( ) . getCustomName ( ) . getString ( ) ;
2019-10-25 07:42:54 +00:00
} catch ( NullPointerException e ) {
receiverCustomName = null ;
}
String attackerClassName ;
try {
2021-05-21 05:44:31 +00:00
attackerClassName = event . getSource ( ) . getEntity ( ) . getClass ( ) . getName ( ) ;
2019-10-25 07:42:54 +00:00
} catch ( NullPointerException e ) {
attackerClassName = null ;
}
String attackerCustomName ;
try {
2021-05-21 05:44:31 +00:00
attackerCustomName = event . getSource ( ) . getEntity ( ) . getCustomName ( ) . getString ( ) ;
2019-10-25 07:42:54 +00:00
} catch ( NullPointerException e ) {
attackerCustomName = null ;
}
2022-08-24 03:16:36 +00:00
// Verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo.
// Also check if "player_only_battles" is enabled and both entities are players.
2022-05-17 05:47:42 +00:00
if ( ! ( ( event . getEntity ( ) instanceof Player & & ! ( ( Player ) event . getEntity ( ) ) . isCreative ( ) )
2019-11-28 07:32:34 +00:00
| | ( config . getEntityInfoReference ( receiverClassName ) ! = null | | config . getCustomEntityInfoReference ( receiverCustomName ) ! = null ) )
2022-05-17 05:47:42 +00:00
| | ! ( ( event . getSource ( ) . getEntity ( ) instanceof Player & & ! ( ( Player ) event . getSource ( ) . getEntity ( ) ) . isCreative ( ) )
2022-08-24 03:16:36 +00:00
| | ( config . getEntityInfoReference ( attackerClassName ) ! = null | | config . getCustomEntityInfoReference ( attackerCustomName ) ! = null ) )
| | ( TurnBasedMinecraftMod . proxy . getConfig ( ) . isPlayerOnlyBattlesEnabled ( ) & &
( ! ( event . getEntity ( ) instanceof Player ) | | ! ( event . getSource ( ) . getEntity ( ) instanceof Player ) ) ) )
2018-09-04 06:21:49 +00:00
{
2019-11-29 04:47:39 +00:00
// logger.debug("BattleManager: Failed first check, attacker is \"" + attackerClassName + "\", defender is \"" + receiverClassName + "\"");
2018-09-04 06:21:49 +00:00
return false ;
}
2018-09-12 05:43:59 +00:00
// check if ignore battle in config
2019-10-25 07:42:54 +00:00
EntityInfo entityInfo = config . getCustomEntityInfoReference ( receiverCustomName ) ;
2018-10-26 04:35:20 +00:00
if ( entityInfo = = null )
{
2018-10-26 05:18:48 +00:00
entityInfo = config . getMatchingEntityInfo ( event . getEntity ( ) ) ;
2018-10-26 04:35:20 +00:00
}
2018-10-26 05:18:48 +00:00
if ( entityInfo ! = null & & ( config . isIgnoreBattleType ( entityInfo . category ) | | entityInfo . ignoreBattle ) )
2018-09-12 05:43:59 +00:00
{
// attacked entity ignores battle
2021-05-21 05:44:31 +00:00
Battle battle = battleMap . get ( entityToBattleMap . get ( new EntityIDDimPair ( event . getSource ( ) . getEntity ( ) ) ) ) ;
if ( battle ! = null & & battle . hasCombatant ( event . getSource ( ) . getEntity ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
logger . debug ( " Attack Canceled: attacked ignores battle but attacker in battle " ) ;
return true ;
} else {
logger . debug ( " Attack Not Canceled: attacked ignores battle " ) ;
return false ;
2018-09-12 05:43:59 +00:00
}
}
2018-10-26 05:18:48 +00:00
2019-10-25 07:42:54 +00:00
entityInfo = config . getCustomEntityInfoReference ( attackerCustomName ) ;
2018-10-26 05:18:48 +00:00
if ( entityInfo = = null )
{
2021-05-21 05:44:31 +00:00
entityInfo = config . getMatchingEntityInfo ( event . getSource ( ) . getEntity ( ) ) ;
2018-10-26 05:18:48 +00:00
}
if ( entityInfo ! = null & & ( config . isIgnoreBattleType ( entityInfo . category ) | | entityInfo . ignoreBattle ) )
2018-09-12 05:43:59 +00:00
{
// attacker entity ignores battle
2019-11-29 04:47:39 +00:00
Battle battle = battleMap . get ( entityToBattleMap . get ( new EntityIDDimPair ( event . getEntity ( ) ) ) ) ;
2021-05-21 05:44:31 +00:00
if ( battle ! = null & & battle . hasCombatant ( event . getEntity ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
logger . debug ( " Attack Canceled: attacker ignores battle but attacked in battle " ) ;
return true ;
} else {
logger . debug ( " Attack Not Canceled: attacker ignores battle " ) ;
return false ;
2018-09-12 05:43:59 +00:00
}
}
2018-08-28 06:13:14 +00:00
// check if one is in battle
2021-05-21 05:44:31 +00:00
Battle attackerBattle = battleMap . get ( entityToBattleMap . get ( new EntityIDDimPair ( event . getSource ( ) . getEntity ( ) ) ) ) ;
if ( attackerBattle ! = null & & ! attackerBattle . hasCombatant ( event . getSource ( ) . getEntity ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
attackerBattle = null ;
2018-08-28 06:13:14 +00:00
}
2019-11-29 04:47:39 +00:00
Battle defenderBattle = battleMap . get ( entityToBattleMap . get ( new EntityIDDimPair ( event . getEntity ( ) ) ) ) ;
2021-05-21 05:44:31 +00:00
if ( defenderBattle ! = null & & ! defenderBattle . hasCombatant ( event . getEntity ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
defenderBattle = null ;
}
if ( attackerBattle ! = null & & defenderBattle ! = null ) {
// both in battle, attack canceled
return true ;
} else if ( attackerBattle = = null & & defenderBattle = = null ) {
2018-08-28 06:13:14 +00:00
// neither entity is in battle
2022-05-17 05:47:42 +00:00
if ( event . getEntity ( ) instanceof Player | | event . getSource ( ) . getEntity ( ) instanceof Player )
2018-08-28 06:13:14 +00:00
{
// at least one of the entities is a player, create Battle
Collection < Entity > sideA = new ArrayList < Entity > ( 1 ) ;
Collection < Entity > sideB = new ArrayList < Entity > ( 1 ) ;
sideA . add ( event . getEntity ( ) ) ;
2021-05-21 05:44:31 +00:00
sideB . add ( event . getSource ( ) . getEntity ( ) ) ;
createBattle ( sideA , sideB , event . getEntity ( ) . level . dimension ( ) ) ;
2018-10-26 05:18:48 +00:00
logger . debug ( " Attack Not Canceled: new battle created " ) ;
2018-09-12 05:43:59 +00:00
}
else
{
2018-10-26 05:18:48 +00:00
logger . debug ( " Attack Not Canceled: neither are in battle or players " ) ;
2018-08-28 06:13:14 +00:00
}
return false ;
2019-11-29 04:47:39 +00:00
} else {
// at this point only one entity is in battle, so add entity to other side
if ( attackerBattle ! = null ) {
if ( attackerBattle . getSize ( ) > = config . getMaxInBattle ( ) ) {
// battle limit reached, cannot add to battle
return true ;
2021-05-21 05:44:31 +00:00
} else if ( attackerBattle . hasCombatantInSideA ( event . getSource ( ) . getEntity ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
attackerBattle . addCombatantToSideB ( event . getEntity ( ) ) ;
} else {
attackerBattle . addCombatantToSideA ( event . getEntity ( ) ) ;
}
entityToBattleMap . put ( new EntityIDDimPair ( event . getEntity ( ) ) , attackerBattle . getId ( ) ) ;
} else {
if ( defenderBattle . getSize ( ) > = config . getMaxInBattle ( ) ) {
// battle limit reached, cannot add to battle
return true ;
2021-05-21 05:44:31 +00:00
} else if ( defenderBattle . hasCombatantInSideA ( event . getEntity ( ) . getId ( ) ) ) {
defenderBattle . addCombatantToSideB ( event . getSource ( ) . getEntity ( ) ) ;
2019-11-29 04:47:39 +00:00
} else {
2021-05-21 05:44:31 +00:00
defenderBattle . addCombatantToSideA ( event . getSource ( ) . getEntity ( ) ) ;
2019-11-29 04:47:39 +00:00
}
2021-05-21 05:44:31 +00:00
entityToBattleMap . put ( new EntityIDDimPair ( event . getSource ( ) . getEntity ( ) ) , defenderBattle . getId ( ) ) ;
2019-11-29 04:47:39 +00:00
}
2018-08-28 06:13:14 +00:00
}
2018-09-06 08:08:36 +00:00
2018-10-26 05:18:48 +00:00
logger . debug ( " Attack Canceled: one is in battle " ) ;
2018-08-28 06:13:14 +00:00
return true ;
}
2023-03-31 05:22:58 +00:00
public void checkTargeted ( LivingChangeTargetEvent event )
2018-10-17 08:15:23 +00:00
{
2022-08-24 03:16:36 +00:00
// Check if "player_only_battles" is enabled and if both entities are players.
if ( TurnBasedMinecraftMod . proxy . getConfig ( ) . isPlayerOnlyBattlesEnabled ( ) & &
2023-03-31 05:22:58 +00:00
( ! ( event . getEntity ( ) instanceof Player ) | | ! ( event . getNewTarget ( ) instanceof Player ) ) ) {
2022-08-24 03:16:36 +00:00
return ;
}
2019-10-25 07:42:54 +00:00
String targetedCustomName ;
try {
2023-03-31 05:22:58 +00:00
targetedCustomName = event . getNewTarget ( ) . getCustomName ( ) . getString ( ) ;
2019-10-25 07:42:54 +00:00
} catch ( NullPointerException e ) {
targetedCustomName = null ;
}
String attackerCustomName ;
try {
2021-05-21 05:44:31 +00:00
attackerCustomName = event . getEntity ( ) . getCustomName ( ) . getString ( ) ;
2019-10-25 07:42:54 +00:00
} catch ( NullPointerException e ) {
attackerCustomName = null ;
}
EntityInfo attackerInfo = TurnBasedMinecraftMod . proxy . getConfig ( ) . getCustomEntityInfoReference ( attackerCustomName ) ;
2018-10-26 05:18:48 +00:00
if ( attackerInfo = = null )
{
attackerInfo = TurnBasedMinecraftMod . proxy . getConfig ( ) . getMatchingEntityInfo ( event . getEntity ( ) ) ;
}
EntityInfo targetedInfo ;
2023-03-31 05:22:58 +00:00
if ( event . getNewTarget ( ) instanceof Player )
2018-10-26 05:18:48 +00:00
{
targetedInfo = null ;
}
else
{
2019-10-25 07:42:54 +00:00
targetedInfo = TurnBasedMinecraftMod . proxy . getConfig ( ) . getCustomEntityInfoReference ( targetedCustomName ) ;
2018-10-26 05:18:48 +00:00
if ( targetedInfo = = null )
{
2023-03-31 05:22:58 +00:00
targetedInfo = TurnBasedMinecraftMod . proxy . getConfig ( ) . getMatchingEntityInfo ( event . getNewTarget ( ) ) ;
2018-10-26 05:18:48 +00:00
}
}
2023-03-31 05:22:58 +00:00
if ( ( event . getNewTarget ( ) instanceof Player & & ( ( Player ) event . getNewTarget ( ) ) . isCreative ( ) )
2018-10-17 08:15:23 +00:00
| | attackerInfo = = null
| | attackerInfo . ignoreBattle
| | TurnBasedMinecraftMod . proxy . getConfig ( ) . isIgnoreBattleType ( attackerInfo . category )
| | ( targetedInfo ! = null
& & ( targetedInfo . ignoreBattle
| | TurnBasedMinecraftMod . proxy . getConfig ( ) . isIgnoreBattleType ( targetedInfo . category ) ) ) )
{
return ;
}
2019-11-29 04:47:39 +00:00
// check if one is in battle
Battle attackerBattle = battleMap . get ( entityToBattleMap . get ( new EntityIDDimPair ( event . getEntity ( ) ) ) ) ;
2021-05-21 05:44:31 +00:00
if ( attackerBattle ! = null & & ! attackerBattle . hasCombatant ( event . getEntity ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
attackerBattle = null ;
2018-10-17 08:15:23 +00:00
}
2023-03-31 05:22:58 +00:00
Battle defenderBattle = battleMap . get ( entityToBattleMap . get ( new EntityIDDimPair ( event . getNewTarget ( ) ) ) ) ;
if ( defenderBattle ! = null & & ! defenderBattle . hasCombatant ( event . getNewTarget ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
defenderBattle = null ;
}
if ( attackerBattle ! = null & & defenderBattle ! = null ) {
return ;
} else if ( attackerBattle = = null & & defenderBattle = = null ) {
2018-10-17 08:15:23 +00:00
// neither in battle
2023-03-31 05:22:58 +00:00
if ( event . getEntity ( ) instanceof Player | | event . getNewTarget ( ) instanceof Player )
2018-10-17 08:15:23 +00:00
{
// at least one is a player, create battle
Collection < Entity > sideA = new ArrayList < Entity > ( 1 ) ;
Collection < Entity > sideB = new ArrayList < Entity > ( 1 ) ;
sideA . add ( event . getEntity ( ) ) ;
2023-03-31 05:22:58 +00:00
sideB . add ( event . getNewTarget ( ) ) ;
2021-05-21 05:44:31 +00:00
createBattle ( sideA , sideB , event . getEntity ( ) . level . dimension ( ) ) ;
2019-11-29 04:47:39 +00:00
logger . debug ( " neither in battle, at least one is player, creating new battle " ) ;
2018-10-17 08:15:23 +00:00
}
2019-11-29 04:47:39 +00:00
} else {
2018-10-17 08:15:23 +00:00
// add entity to battle
2019-11-29 04:47:39 +00:00
if ( attackerBattle ! = null ) {
if ( attackerBattle . getSize ( ) > = TurnBasedMinecraftMod . proxy . getConfig ( ) . getMaxInBattle ( ) ) {
// battle max reached, cannot add to battle
return ;
2021-05-21 05:44:31 +00:00
} else if ( attackerBattle . hasCombatantInSideA ( event . getEntity ( ) . getId ( ) ) ) {
2023-03-31 05:22:58 +00:00
attackerBattle . addCombatantToSideB ( event . getNewTarget ( ) ) ;
2019-11-29 04:47:39 +00:00
} else {
2023-03-31 05:22:58 +00:00
attackerBattle . addCombatantToSideA ( event . getNewTarget ( ) ) ;
2019-11-29 04:47:39 +00:00
}
2023-03-31 05:22:58 +00:00
entityToBattleMap . put ( new EntityIDDimPair ( event . getNewTarget ( ) ) , attackerBattle . getId ( ) ) ;
2019-11-29 04:47:39 +00:00
} else {
if ( defenderBattle . getSize ( ) > = TurnBasedMinecraftMod . proxy . getConfig ( ) . getMaxInBattle ( ) ) {
// battle max reached, cannot add to battle
return ;
2023-03-31 05:22:58 +00:00
} else if ( defenderBattle . hasCombatantInSideA ( event . getNewTarget ( ) . getId ( ) ) ) {
2019-11-29 04:47:39 +00:00
defenderBattle . addCombatantToSideB ( event . getEntity ( ) ) ;
} else {
defenderBattle . addCombatantToSideA ( event . getEntity ( ) ) ;
}
entityToBattleMap . put ( new EntityIDDimPair ( event . getEntity ( ) ) , defenderBattle . getId ( ) ) ;
2018-10-17 08:15:23 +00:00
}
}
}
2022-05-17 05:47:42 +00:00
private Battle createBattle ( Collection < Entity > sideA , Collection < Entity > sideB , ResourceKey < Level > dimension )
2018-08-28 06:13:14 +00:00
{
2018-10-18 04:34:57 +00:00
Battle newBattle = null ;
2019-11-29 04:59:41 +00:00
while ( battleMap . containsKey ( IDCounter ) )
2018-08-28 06:13:14 +00:00
{
2019-11-29 04:59:41 +00:00
+ + IDCounter ;
2018-08-28 06:13:14 +00:00
}
2019-11-29 04:59:41 +00:00
newBattle = new Battle ( this , IDCounter , sideA , sideB , true , dimension ) ;
battleMap . put ( IDCounter , newBattle ) ;
2019-11-29 04:47:39 +00:00
for ( Entity e : sideA ) {
entityToBattleMap . put ( new EntityIDDimPair ( e ) , newBattle . getId ( ) ) ;
}
for ( Entity e : sideB ) {
entityToBattleMap . put ( new EntityIDDimPair ( e ) , newBattle . getId ( ) ) ;
}
2018-08-30 07:15:20 +00:00
newBattle . notifyPlayersBattleInfo ( ) ;
2018-08-28 06:13:14 +00:00
return newBattle ;
}
2018-08-29 06:09:44 +00:00
public Battle getBattleByID ( int id )
{
2019-11-29 04:59:41 +00:00
return battleMap . get ( id ) ;
2018-08-29 06:09:44 +00:00
}
2018-09-20 06:15:34 +00:00
public void cleanup ( )
{
2019-10-25 07:42:54 +00:00
battleUpdater . setRunning ( false ) ;
MinecraftForge . EVENT_BUS . unregister ( battleUpdater ) ;
2019-11-29 04:59:41 +00:00
battleMap . clear ( ) ;
2019-10-25 07:42:54 +00:00
battleUpdater = null ;
2018-09-20 06:15:34 +00:00
}
2018-10-17 09:28:47 +00:00
protected void addRecentlyLeftBattle ( Combatant c )
{
c . time = System . nanoTime ( ) ;
Config config = TurnBasedMinecraftMod . proxy . getConfig ( ) ;
2022-05-17 05:47:42 +00:00
if ( c . entity instanceof ServerPlayer ) {
TurnBasedMinecraftMod . getHandler ( ) . send ( PacketDistributor . PLAYER . with ( ( ) - > ( ServerPlayer ) c . entity ) , new PacketGeneralMessage ( " You just left battle! " + config . getLeaveBattleCooldownSeconds ( ) + " seconds until you can attack/be-attacked again! " ) ) ;
2018-10-17 09:28:47 +00:00
}
2021-05-21 05:44:31 +00:00
recentlyLeftBattle . put ( c . entity . getId ( ) , c ) ;
2019-11-29 04:47:39 +00:00
entityToBattleMap . remove ( new EntityIDDimPair ( c . entity ) ) ;
2018-10-17 09:28:47 +00:00
}
protected void updateRecentlyLeftBattle ( )
{
long current = System . nanoTime ( ) ;
2019-11-29 04:59:41 +00:00
for ( Iterator < Map . Entry < Integer , Combatant > > iter = recentlyLeftBattle . entrySet ( ) . iterator ( ) ; iter . hasNext ( ) ; )
2018-10-17 09:28:47 +00:00
{
2019-11-29 04:59:41 +00:00
Map . Entry < Integer , Combatant > entry = iter . next ( ) ;
2022-05-17 05:47:42 +00:00
if ( entry . getValue ( ) . entity instanceof Creeper & & TurnBasedMinecraftMod . proxy . getConfig ( ) . getCreeperStopExplodeOnLeaveBattle ( ) ) {
( ( Creeper ) entry . getValue ( ) . entity ) . setSwellDir ( - 10 ) ;
2020-11-18 08:24:18 +00:00
}
2019-11-29 04:59:41 +00:00
if ( current - entry . getValue ( ) . time > TurnBasedMinecraftMod . proxy . getConfig ( ) . getLeaveBattleCooldownNanos ( ) )
2018-10-17 09:28:47 +00:00
{
2019-11-29 04:59:41 +00:00
iter . remove ( ) ;
2022-05-17 05:47:42 +00:00
if ( entry . getValue ( ) . entity instanceof ServerPlayer )
2018-10-17 09:28:47 +00:00
{
2022-05-17 05:47:42 +00:00
TurnBasedMinecraftMod . getHandler ( ) . send ( PacketDistributor . PLAYER . with ( ( ) - > ( ServerPlayer ) entry . getValue ( ) . entity ) , new PacketGeneralMessage ( " Timer ended, you can now attack/be-attacked again. " ) ) ;
2018-10-17 09:28:47 +00:00
}
}
}
}
public boolean isRecentlyLeftBattle ( int entityID )
{
2019-11-29 04:59:41 +00:00
return recentlyLeftBattle . containsKey ( entityID ) ;
2018-10-17 09:28:47 +00:00
}
2019-11-29 04:47:39 +00:00
public boolean forceLeaveBattle ( EntityIDDimPair entityInfo ) {
boolean result = false ;
Integer battleID = entityToBattleMap . get ( entityInfo ) ;
if ( battleID ! = null ) {
Battle battle = battleMap . get ( battleID ) ;
if ( battle ! = null & & battle . hasCombatant ( entityInfo . id ) ) {
battle . forceRemoveCombatant ( entityInfo ) ;
result = true ;
}
entityToBattleMap . remove ( entityInfo ) ;
}
return result ;
}
2022-08-23 04:28:49 +00:00
2022-08-23 06:01:14 +00:00
public boolean isInBattle ( Entity entity ) {
2022-08-24 05:03:45 +00:00
synchronized ( tempIDPair ) {
tempIDPair . id = entity . getId ( ) ;
tempIDPair . dim = entity . level . dimension ( ) ;
return entityToBattleMap . keySet ( ) . contains ( tempIDPair ) ;
}
2022-08-23 04:28:49 +00:00
}
2018-08-29 06:09:44 +00:00
}