Minor fixes

This commit is contained in:
Stephen Seo 2018-10-26 14:18:48 +09:00
parent aa229036ad
commit 39257cee55
4 changed files with 53 additions and 22 deletions

View file

@ -95,12 +95,16 @@ public class AttackEventHandler
} }
else else
{ {
editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity()).clone(); editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity());
if(editingInfo.entityInfo == null) if(editingInfo.entityInfo == null)
{ {
editingInfo.entityInfo = new EntityInfo(); editingInfo.entityInfo = new EntityInfo();
editingInfo.entityInfo.classType = event.getEntity().getClass(); editingInfo.entityInfo.classType = event.getEntity().getClass();
} }
else
{
editingInfo.entityInfo = editingInfo.entityInfo.clone();
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), (EntityPlayerMP) editingInfo.editor);
TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\""); TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\"");
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor);

View file

@ -45,21 +45,22 @@ public class BattleManager
*/ */
public boolean checkAttack(final LivingAttackEvent event) public boolean checkAttack(final LivingAttackEvent event)
{ {
Config config = TurnBasedMinecraftMod.proxy.getConfig();
// verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo // verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo
if(!((event.getEntity() instanceof EntityPlayer && !((EntityPlayer)event.getEntity()).isCreative()) || TurnBasedMinecraftMod.proxy.getConfig().getEntityInfoReference(event.getEntity().getClass().getName()) != null) if(!((event.getEntity() instanceof EntityPlayer && !((EntityPlayer)event.getEntity()).isCreative()) || (config.getEntityInfoReference(event.getEntity().getClass().getName()) != null || config.getCustomEntityInfoReference(event.getEntity().getCustomNameTag()) != null))
|| !((event.getSource().getTrueSource() instanceof EntityPlayer && !((EntityPlayer)event.getSource().getTrueSource()).isCreative()) || TurnBasedMinecraftMod.proxy.getConfig().getEntityInfoReference(event.getSource().getTrueSource().getClass().getName()) != null)) || !((event.getSource().getTrueSource() instanceof EntityPlayer && !((EntityPlayer)event.getSource().getTrueSource()).isCreative()) || (config.getEntityInfoReference(event.getSource().getTrueSource().getClass().getName()) != null || config.getCustomEntityInfoReference(event.getSource().getTrueSource().getCustomNameTag()) != null)))
{ {
return false; return false;
} }
// check if ignore battle in config // check if ignore battle in config
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(event.getEntity().getCustomNameTag()); EntityInfo entityInfo = config.getCustomEntityInfoReference(event.getEntity().getCustomNameTag());
if(entityInfo == null) if(entityInfo == null)
{ {
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity()); entityInfo = config.getMatchingEntityInfo(event.getEntity());
} }
if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle)) if(entityInfo != null && (config.isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
{ {
// attacked entity ignores battle // attacked entity ignores battle
synchronized(battleMap) synchronized(battleMap)
@ -68,16 +69,22 @@ public class BattleManager
{ {
if(b.hasCombatant(event.getSource().getTrueSource().getEntityId())) if(b.hasCombatant(event.getSource().getTrueSource().getEntityId()))
{ {
// logger.debug("Attack Canceled: attacked ignores battle but attacker in battle"); logger.debug("Attack Canceled: attacked ignores battle but attacker in battle");
return true; return true;
} }
} }
} }
// logger.debug("Attack Not Canceled: attacked ignores battle"); logger.debug("Attack Not Canceled: attacked ignores battle");
return false; return false;
} }
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getSource().getTrueSource());
if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle)) entityInfo = config.getCustomEntityInfoReference(event.getSource().getTrueSource().getCustomNameTag());
if(entityInfo == null)
{
entityInfo = config.getMatchingEntityInfo(event.getSource().getTrueSource());
}
if(entityInfo != null && (config.isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
{ {
// attacker entity ignores battle // attacker entity ignores battle
synchronized(battleMap) synchronized(battleMap)
@ -86,12 +93,12 @@ public class BattleManager
{ {
if(b.hasCombatant(event.getEntity().getEntityId())) if(b.hasCombatant(event.getEntity().getEntityId()))
{ {
// logger.debug("Attack Canceled: attacker ignores battle but attacked in battle"); logger.debug("Attack Canceled: attacker ignores battle but attacked in battle");
return true; return true;
} }
} }
} }
// logger.debug("Attack Not Canceled: attacker ignores battle"); logger.debug("Attack Not Canceled: attacker ignores battle");
return false; return false;
} }
@ -109,7 +116,7 @@ public class BattleManager
if(inBattle != null) if(inBattle != null)
{ {
// both combatants are in battle // both combatants are in battle
// logger.debug("Attack Canceled: both are in battle"); logger.debug("Attack Canceled: both are in battle");
return true; return true;
} }
else else
@ -124,7 +131,7 @@ public class BattleManager
if(inBattle != null) if(inBattle != null)
{ {
// both combatants are in battle // both combatants are in battle
// logger.debug("Attack Canceled: both are in battle"); logger.debug("Attack Canceled: both are in battle");
return true; return true;
} }
else else
@ -148,17 +155,17 @@ public class BattleManager
sideA.add(event.getEntity()); sideA.add(event.getEntity());
sideB.add(event.getSource().getTrueSource()); sideB.add(event.getSource().getTrueSource());
createBattle(sideA, sideB); createBattle(sideA, sideB);
// logger.debug("Attack Not Canceled: new battle created"); logger.debug("Attack Not Canceled: new battle created");
} }
else else
{ {
// logger.debug("Attack Not Canceled: neither are in battle or players"); logger.debug("Attack Not Canceled: neither are in battle or players");
} }
return false; return false;
} }
// at this point only one entity is in battle, so add entity to other side // at this point only one entity is in battle, so add entity to other side
if(battle.getSize() >= TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle()) if(battle.getSize() >= config.getMaxInBattle())
{ {
// battle limit reached, cannot add to battle // battle limit reached, cannot add to battle
return true; return true;
@ -172,14 +179,31 @@ public class BattleManager
battle.addCombatantToSideA(notInBattle); battle.addCombatantToSideA(notInBattle);
} }
// logger.debug("Attack Canceled: one is in battle"); logger.debug("Attack Canceled: one is in battle");
return true; return true;
} }
public void checkTargeted(LivingSetAttackTargetEvent event) public void checkTargeted(LivingSetAttackTargetEvent event)
{ {
EntityInfo attackerInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity()); EntityInfo attackerInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(event.getEntity().getCustomNameTag());
EntityInfo targetedInfo = event.getTarget() instanceof EntityPlayer ? null : TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getTarget()); if(attackerInfo == null)
{
attackerInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
}
EntityInfo targetedInfo;
if(event.getTarget() instanceof EntityPlayer)
{
targetedInfo = null;
}
else
{
targetedInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(event.getTarget().getCustomNameTag());
if(targetedInfo == null)
{
targetedInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getTarget());
}
}
if((event.getTarget() instanceof EntityPlayer && ((EntityPlayer)event.getTarget()).isCreative()) if((event.getTarget() instanceof EntityPlayer && ((EntityPlayer)event.getTarget()).isCreative())
|| attackerInfo == null || attackerInfo == null
|| attackerInfo.ignoreBattle || attackerInfo.ignoreBattle

View file

@ -287,7 +287,7 @@ public class EntityInfo
public void applyEffectToEntity(EntityLivingBase entity) public void applyEffectToEntity(EntityLivingBase entity)
{ {
applyEffectToEntity(entity, 20 * 7, 0); applyEffectToEntity(entity, 20 * 12, 0);
} }
public void applyEffectToEntity(EntityLivingBase entity, int duration, int amplifier) public void applyEffectToEntity(EntityLivingBase entity, int duration, int amplifier)

View file

@ -78,8 +78,11 @@ public class PacketEditingMessage implements IMessage
public PacketEditingMessage(Type type, EntityInfo entityInfo) public PacketEditingMessage(Type type, EntityInfo entityInfo)
{ {
this.type = type; this.type = type;
if(entityInfo != null)
{
this.entityInfo = entityInfo; this.entityInfo = entityInfo;
} }
}
@Override @Override
public void fromBytes(ByteBuf buf) public void fromBytes(ByteBuf buf)