diff --git a/Changelog.md b/Changelog.md index ac1ec89..22a239c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,15 @@ +# Version 1.7 + +Fix bug where after using "/tbm-edit", ignore_battle option is saved in +config with the wrong name. + +Add "/tbm-edit custom", which lets an OP add an entity entry for entities with +custom names (via name-tags). The entry added into the config file will use +"custom_name" instead of "name" to specify if it is a regular entity entry +or an entry for a specific custom name. + +Minor fixes and improvements. + # Version 1.6 Fix bug where player can start battle with self. diff --git a/build.gradle b/build.gradle index 80ecc87..9adf630 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'com.github.johnrengelman.shadow' -version = "1.6" +version = "1.7" group = "com.seodisparate.TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft" diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java index f5fc63a..ae02a27 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java @@ -5,6 +5,7 @@ import java.util.Iterator; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage; +import com.seodisparate.TurnBasedMinecraft.common.networking.PacketGeneralMessage; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; @@ -74,21 +75,41 @@ public class AttackEventHandler { editingInfo.isPendingEntitySelection = false; event.setCanceled(true); - editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity()); - if(editingInfo.entityInfo == null) + if(editingInfo.isEditingCustomName) { - editingInfo.entityInfo = new EntityInfo(); - editingInfo.entityInfo.classType = event.getEntity().getClass(); - TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)editingInfo.editor); - return; + if(event.getEntity().getCustomNameTag().isEmpty()) + { + TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name"); + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), (EntityPlayerMP) editingInfo.editor); + return; + } + editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomNameTag()); + if(editingInfo.entityInfo == null) + { + editingInfo.entityInfo = new EntityInfo(); + editingInfo.entityInfo.customName = event.getEntity().getCustomNameTag(); + } + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomNameTag() + "\""), (EntityPlayerMP) editingInfo.editor); + TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomNameTag() + "\""); + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor); + } + else + { + editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity()).clone(); + if(editingInfo.entityInfo == null) + { + editingInfo.entityInfo = new EntityInfo(); + editingInfo.entityInfo.classType = event.getEntity().getClass(); + } + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), (EntityPlayerMP) editingInfo.editor); + 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); return; } } } - if((event.getEntity() != null && battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId())) - || (event.getSource().getTrueSource() != null && battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId()))) + if(event.getEntity() != null && event.getSource().getTrueSource() != null && (battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()) || battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId()))) { event.setCanceled(true); return; diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java index ba66980..5527686 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java @@ -139,7 +139,12 @@ public class Battle { for(Entity e : sideA) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag()); + if(entityInfo == null) + { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + } + if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) { continue; @@ -167,7 +172,12 @@ public class Battle { for(Entity e : sideB) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag()); + if(entityInfo == null) + { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + } + if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) { continue; @@ -297,7 +307,12 @@ public class Battle public void addCombatantToSideA(Entity e) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag()); + if(entityInfo == null) + { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + } + if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) { return; @@ -353,7 +368,12 @@ public class Battle public void addCombatantToSideB(Entity e) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag()); + if(entityInfo == null) + { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); + } + if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) { return; diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java index e1ce156..9f1f5af 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java @@ -53,7 +53,12 @@ public class BattleManager } // check if ignore battle in config - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity()); + EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(event.getEntity().getCustomNameTag()); + if(entityInfo == null) + { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity()); + } + if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle)) { // attacked entity ignores battle diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommandTBMEdit.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommandTBMEdit.java index a707e2b..6092ca8 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommandTBMEdit.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommandTBMEdit.java @@ -11,7 +11,7 @@ import net.minecraft.server.MinecraftServer; public class CommandTBMEdit extends CommandBase { - public static final String usage = "/tbm-edit (Invoke without parameters to start edit)"; + public static final String usage = "/tbm-edit [custom] (Invoke without parameters or with arg \"custom\" to start edit)"; private Config config; public CommandTBMEdit(Config config) @@ -68,9 +68,16 @@ public class CommandTBMEdit extends CommandBase { if(args[0].toLowerCase().equals("finish")) { - config.editEntityEntry(editingInfo.entityInfo); - TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId()); - TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Entity info saved in config and loaded."), (EntityPlayerMP) senderEntity); + if(!config.editEntityEntry(editingInfo.entityInfo)) + { + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("An error occurred while attempting to save an entry to the config, check the logs"), (EntityPlayerMP) senderEntity); + TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId()); + } + else + { + TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId()); + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Entity info saved in config and loaded."), (EntityPlayerMP) senderEntity); + } } else if(args[0].toLowerCase().equals("cancel")) { @@ -88,11 +95,21 @@ public class CommandTBMEdit extends CommandBase } else if(editingInfo != null) { - TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP) senderEntity); + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity); } else { - TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit entity without starting editing process (use \"/tbm-edit\")."), (EntityPlayerMP)senderEntity); + if(args[0].toLowerCase().equals("custom")) + { + TurnBasedMinecraftMod.proxy.setEditingPlayer(senderEntity); + TurnBasedMinecraftMod.proxy.getEditingInfo(senderEntity.getEntityId()).isEditingCustomName = true; + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity); + TurnBasedMinecraftMod.logger.info("Begin editing custom TBM Entity for player \"" + senderEntity.getName() + "\""); + } + else + { + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit entity without starting editing process (use \"/tbm-edit\")."), (EntityPlayerMP)senderEntity); + } } } else if(args.length == 2) diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java index bb04d96..0949e0c 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java @@ -20,6 +20,7 @@ public class Config public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L; private long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT; private Map entityInfoMap; + private Map customEntityInfoMap; private Set ignoreBattleTypes; private Logger logger; private int playerSpeed = 50; @@ -47,6 +48,7 @@ public class Config public Config(Logger logger) { entityInfoMap = new HashMap(); + customEntityInfoMap = new HashMap(); ignoreBattleTypes = new HashSet(); this.logger = logger; musicBattleTypes = new HashSet(); @@ -400,18 +402,32 @@ public class Config { TomlTable entity = entityArray.getTable(i); EntityInfo eInfo = new EntityInfo(); - try + String name = null; + if(entity.contains("name") && entity.contains("custom_name")) { - eInfo.classType = Class.forName(entity.getString("name")); - } - catch (ClassNotFoundException e) - { - logger.error("Entity with class name \"" + entity.getString("name") + "\" not found, skipping..."); + logger.error("Entity cannot have both \"name\" and \"custom_name\" entries"); continue; } - catch (NullPointerException e) + else if(entity.contains("name")) { - logger.error("Entity does not have \"name\", skipping..."); + try + { + eInfo.classType = Class.forName(entity.getString("name")); + name = eInfo.classType.getName(); + } catch(ClassNotFoundException e) + { + logger.error("Entity with class name \"" + entity.getString("name") + "\" not found, skipping..."); + continue; + } + } + else if(entity.contains("custom_name")) + { + eInfo.customName = entity.getString("custom_name"); + name = eInfo.customName; + } + else + { + logger.error("Entity must have \"name\" or \"custom_name\" entry"); continue; } @@ -421,12 +437,12 @@ public class Config if(eInfo.attackPower < 0) { eInfo.attackPower = 0; - logEntityInvalidValue("attack_power", eInfo.classType.getName(), "0"); + logEntityInvalidValue("attack_power", name, "0"); } } catch (NullPointerException e) { - logEntityMissingRequiredValue("attack_power", eInfo.classType.getName()); + logEntityMissingRequiredValue("attack_power", name); continue; } @@ -436,12 +452,12 @@ public class Config if(eInfo.attackProbability < 0 || eInfo.attackProbability > 100) { eInfo.attackProbability = 35; - logEntityInvalidValue("attack_probability", eInfo.classType.getName(), "35"); + logEntityInvalidValue("attack_probability", name, "35"); } } catch (NullPointerException e) { - logEntityMissingRequiredValue("attack_probability", eInfo.classType.getName()); + logEntityMissingRequiredValue("attack_probability", name); continue; } @@ -454,13 +470,14 @@ public class Config if(eInfo.attackEffectProbability < 0 || eInfo.attackEffectProbability > 100) { eInfo.attackEffectProbability = 35; - logEntityInvalidValue("attack_effect", eInfo.classType.getName(), "35"); + logEntityInvalidValue("attack_effect", name, "35"); } } } catch (NullPointerException e) { eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; + logEntityMissingOptionalValue("attack_effect", name, "unknown"); } try @@ -469,12 +486,13 @@ public class Config if(eInfo.attackVariance < 0) { eInfo.attackVariance = 0; - logEntityInvalidValue("attack_variance", eInfo.classType.getName(), "0"); + logEntityInvalidValue("attack_variance", name, "0"); } } catch (NullPointerException e) { eInfo.attackVariance = 0; + logEntityMissingOptionalValue("attack_variance", name, "0"); } try @@ -483,7 +501,7 @@ public class Config if(eInfo.defenseDamage < 0) { eInfo.defenseDamage = 0; - logEntityInvalidValue("defense_damage", eInfo.classType.getName(), "0"); + logEntityInvalidValue("defense_damage", name, "0"); } else { @@ -491,13 +509,14 @@ public class Config if(eInfo.defenseDamageProbability < 0 || eInfo.defenseDamageProbability > 100) { eInfo.defenseDamageProbability = 35; - logEntityInvalidValue("defense_damage_probability", eInfo.classType.getName(), "35"); + logEntityInvalidValue("defense_damage_probability", name, "35"); } } } catch (NullPointerException e) { eInfo.defenseDamage = 0; + logEntityMissingOptionalValue("defense_damage", name, "0"); } try @@ -506,12 +525,12 @@ public class Config if(eInfo.evasion < 0 || eInfo.evasion > 100) { eInfo.evasion = 20; - logEntityInvalidValue("evasion", eInfo.classType.getName(), "20"); + logEntityInvalidValue("evasion", name, "20"); } } catch (NullPointerException e) { - logEntityMissingRequiredValue("evasion", eInfo.classType.getName()); + logEntityMissingRequiredValue("evasion", name); continue; } @@ -521,7 +540,8 @@ public class Config } catch (NullPointerException e) { - logEntityMissingRequiredValue("speed", eInfo.classType.getName()); + logEntityMissingRequiredValue("speed", name); + continue; } try @@ -531,12 +551,13 @@ public class Config catch (NullPointerException e) { eInfo.ignoreBattle = false; + logEntityMissingOptionalValue("ignore_battle", name, "false"); } eInfo.category = entity.getString("category"); if(eInfo.category == null) { - logEntityMissingRequiredValue("category", eInfo.classType.getName()); + logEntityMissingRequiredValue("category", name); continue; } @@ -546,7 +567,7 @@ public class Config } catch (NullPointerException e) { - logEntityMissingRequiredValue("decision_attack_probability", eInfo.classType.getName()); + logEntityMissingRequiredValue("decision_attack_probability", name); continue; } @@ -556,7 +577,7 @@ public class Config } catch (NullPointerException e) { - logEntityMissingRequiredValue("decision_defend_probability", eInfo.classType.getName()); + logEntityMissingRequiredValue("decision_defend_probability", name); continue; } @@ -566,11 +587,22 @@ public class Config } catch (NullPointerException e) { - logEntityMissingRequiredValue("decision_flee_probability", eInfo.classType.getName()); + logEntityMissingRequiredValue("decision_flee_probability", name); continue; } - entityInfoMap.put(eInfo.classType.getName(), eInfo); + if(eInfo.classType != null) + { + entityInfoMap.put(eInfo.classType.getName(), eInfo); + } + else if(!eInfo.customName.isEmpty()) + { + customEntityInfoMap.put(eInfo.customName, eInfo); + } + else + { + logger.error("Cannot add entity to internal config, no \"name\" or \"custom_name\""); + } } } return true; @@ -596,22 +628,51 @@ public class Config logger.error("Entity \"" + name + "\" does not have option \"" + option + "\", skipping..."); } + private void logEntityMissingOptionalValue(String option, String name, String defaultValue) + { + logger.info("Entity \"" + name + "\" does not have optional option \"" + option + "\", defaulting to \"" + defaultValue + "\"..."); + } + private String getRegexEntityName(String name) { String regex = "^\\s*name\\s*=\\s*"; regex += "(\"" + name + "\""; - regex += "|'" + name + "')"; + regex += "|'" + name + "'"; + regex += "|\"\"\"" + name + "\"\"\""; + regex += "|'''" + name + "''')"; + return regex; + } + + private String getRegexCustomEntityName(String name) + { + String regex = "^\\s*custom_name\\s*=\\s*"; + regex += "(\"" + name + "\""; + regex += "|'" + name + "'"; + regex += "|\"\"\"" + name + "\"\"\""; + regex += "|'''" + name + "''')"; return regex; } private boolean addEntityEntry(EntityInfo eInfo) { + if(eInfo.classType == null && eInfo.customName.isEmpty()) + { + logger.error("addEntityEntry: Got invalid eInfo, no name of any type"); + return false; + } try { File config = new File(TurnBasedMinecraftMod.CONFIG_FILE_PATH); FileWriter fw = new FileWriter(config, true); fw.write("[[server_config.entity]]\n"); - fw.write("name = \"" + eInfo.classType.getName() + "\"\n"); + if(eInfo.classType != null) + { + fw.write("name = \"" + eInfo.classType.getName() + "\"\n"); + } + else + { + fw.write("custom_name = \"" + eInfo.customName + "\"\n"); + } fw.write("attack_power = " + eInfo.attackPower + "\n"); fw.write("attack_probability = " + eInfo.attackProbability + "\n"); if(eInfo.attackVariance > 0) @@ -632,7 +693,7 @@ public class Config fw.write("speed = " + eInfo.speed + "\n"); if(eInfo.ignoreBattle) { - fw.write("ignoreBattle = true\n"); + fw.write("ignore_battle = true\n"); } fw.write("category = \"" + eInfo.category + "\"\n"); fw.write("decision_attack_probability = " + eInfo.decisionAttack + "\n"); @@ -640,11 +701,25 @@ public class Config fw.write("decision_flee_probability = " + eInfo.decisionFlee + "\n"); fw.close(); - entityInfoMap.put(eInfo.classType.getName(), eInfo); + if(eInfo.classType != null) + { + entityInfoMap.put(eInfo.classType.getName(), eInfo); + } + else + { + customEntityInfoMap.put(eInfo.customName, eInfo); + } } catch (Throwable t) { - logger.error("Failed to add entity entry (name = \"" + eInfo.classType.getName() + "\")"); + if(eInfo.classType != null) + { + logger.error("Failed to add entity entry (name = \"" + eInfo.classType.getName() + "\")"); + } + else + { + logger.error("Failed to add custom entity entry (custom_name = \"" + eInfo.customName + "\")"); + } return false; } return true; @@ -670,6 +745,7 @@ public class Config } int nameIndex = -1; + if(eInfo.classType != null) { Pattern p = Pattern.compile(getRegexEntityName(eInfo.classType.getName()), Pattern.MULTILINE); Matcher m = p.matcher(cached); @@ -678,6 +754,20 @@ public class Config nameIndex = m.start(); } } + else if(!eInfo.customName.isEmpty()) + { + Pattern p = Pattern.compile(getRegexCustomEntityName(eInfo.customName), Pattern.MULTILINE); + Matcher m = p.matcher(cached); + if(m.find()) + { + nameIndex = m.start(); + } + } + else + { + logger.error("EntityInfo does not have classType or customName, cannot edit/add"); + return false; + } int entryIndex = -1; int nextIndex = -1; if(nameIndex != -1) @@ -706,7 +796,14 @@ public class Config } else { - logger.warn("editEntityEntry: could not find entry for \"" + eInfo.classType.getName() + "\", skipping to adding it..."); + if(eInfo.classType != null) + { + logger.warn("editEntityEntry: could not find entry for \"" + eInfo.classType.getName() + "\", skipping to adding it..."); + } + else if(!eInfo.customName.isEmpty()) + { + logger.warn("editEntityEntry: could not find entry for \"" + eInfo.customName + "\", skipping to adding it..."); + } return addEntityEntry(eInfo); } @@ -781,7 +878,12 @@ public class Config */ public EntityInfo getEntityInfo(String classFullName) { - return entityInfoMap.get(classFullName).clone(); + EntityInfo eInfo = entityInfoMap.get(classFullName); + if(eInfo != null) + { + eInfo = eInfo.clone(); + } + return eInfo; } protected EntityInfo getEntityInfoReference(String classFullName) @@ -803,6 +905,26 @@ public class Config return null; } + /** + * Returns a clone of an EntityInfo (to prevent editing it). + * @param customName + * @return a clone of the stored custom EntityInfo or null if invalid String + */ + public EntityInfo getCustomEntityInfo(String customName) + { + EntityInfo eInfo = customEntityInfoMap.get(customName); + if(eInfo != null) + { + eInfo = eInfo.clone(); + } + return eInfo; + } + + protected EntityInfo getCustomEntityInfoReference(String customName) + { + return customEntityInfoMap.get(customName); + } + private int getConfigFileVersion(InputStream io) { int version = 0; diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EditingInfo.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EditingInfo.java index 02737f2..6ae4178 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EditingInfo.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EditingInfo.java @@ -7,12 +7,14 @@ public class EditingInfo public EntityPlayer editor; public EntityInfo entityInfo; public boolean isPendingEntitySelection; + public boolean isEditingCustomName; public EditingInfo() { editor = null; entityInfo = null; isPendingEntitySelection = true; + isEditingCustomName = false; } public EditingInfo(EntityPlayer player) @@ -20,5 +22,6 @@ public class EditingInfo editor = player; entityInfo = null; isPendingEntitySelection = true; + isEditingCustomName = false; } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java index 06f27c4..6b86eae 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java @@ -21,6 +21,7 @@ public class EntityInfo public int decisionAttack; public int decisionDefend; public int decisionFlee; + public String customName; public enum Effect { @@ -379,6 +380,7 @@ public class EntityInfo decisionAttack = 70; decisionDefend = 20; decisionFlee = 10; + customName = new String(); } public EntityInfo clone() @@ -399,6 +401,7 @@ public class EntityInfo newEntityInfo.decisionAttack = decisionAttack; newEntityInfo.decisionDefend = decisionDefend; newEntityInfo.decisionFlee = decisionFlee; + newEntityInfo.customName = new String(customName); return newEntityInfo; } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index 7c28a9a..0d1040c 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java @@ -21,7 +21,7 @@ public class TurnBasedMinecraftMod { public static final String MODID = "com.seodisparate.turnbasedminecraft"; public static final String NAME = "Turn Based Minecraft Mod"; - public static final String VERSION = "1.6"; + public static final String VERSION = "1.7"; public static final String CONFIG_FILENAME = "TBM_Config.toml"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME; diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketEditingMessage.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketEditingMessage.java index b2ed44a..a402b6b 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketEditingMessage.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketEditingMessage.java @@ -104,6 +104,7 @@ public class PacketEditingMessage implements IMessage entityInfo.decisionAttack = buf.readInt(); entityInfo.decisionDefend = buf.readInt(); entityInfo.decisionFlee = buf.readInt(); + entityInfo.customName = ByteBufUtils.readUTF8String(buf); } @Override @@ -132,6 +133,7 @@ public class PacketEditingMessage implements IMessage buf.writeInt(entityInfo.decisionAttack); buf.writeInt(entityInfo.decisionDefend); buf.writeInt(entityInfo.decisionFlee); + ByteBufUtils.writeUTF8String(buf, entityInfo.customName); } public static class HandlerEditingMessage implements IMessageHandler @@ -230,7 +232,7 @@ public class PacketEditingMessage implements IMessage option = new TextComponentString("E"); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion")) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Evasion"))); - value = new TextComponentString("(" + message.entityInfo.evasion + ") "); + value = new TextComponentString("(" + message.entityInfo.evasion + "%) "); value.getStyle().setColor(TextFormatting.WHITE); option.appendSibling(value); text.appendSibling(option); diff --git a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml b/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml index dd0c7ed..4ef75d5 100644 --- a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml +++ b/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml @@ -66,7 +66,8 @@ battle_turn_time_seconds = 15 # Each "server_config.entity" entry uses the following options: -# name: full class name of the entity +# name: full class name of the entity, cannot also have option "custom_name" +# custom_name: custom name-tag name, cannot also have option "name" # attack_power: how much damage an entity does on successful attack # attack_probability: percentage of attack success. (Usually calculated with enemy's evasion to determine actual percentage) # attack_variance (optional): determines how much a successful attack's damage varies.