Impl /tbm-edit , some fixes

This commit is contained in:
Stephen Seo 2019-11-27 16:55:48 +09:00
parent 9ccc692d2c
commit 4ddd0312e4
2 changed files with 322 additions and 435 deletions

View file

@ -1,433 +0,0 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketEditingMessage;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
public class CommandTBMEdit extends CommandBase
{
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)
{
this.config = config;
}
@Override
public String getName()
{
return "tbm-edit";
}
@Override
public String getUsage(ICommandSender sender)
{
return usage;
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
EntityPlayer senderEntity = null;
EditingInfo editingInfo = null;
try
{
senderEntity = (EntityPlayer) sender.getCommandSenderEntity();
} catch (ClassCastException e)
{
// if sender is not EntityPlayer, ignore
return;
}
editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(senderEntity.getEntityId());
if(args.length == 0)
{
if(editingInfo != null && !editingInfo.isPendingEntitySelection)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
else if(editingInfo != null)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP) senderEntity);
}
else
{
TurnBasedMinecraftMod.proxy.setEditingPlayer(senderEntity);
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP) senderEntity);
TurnBasedMinecraftMod.logger.info("Begin editing TBM Entity for player \"" + senderEntity.getName() + "\"");
}
}
else if(args.length == 1)
{
if(editingInfo != null && !editingInfo.isPendingEntitySelection)
{
if(args[0].toLowerCase().equals("finish"))
{
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"))
{
TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cancelled editing entity."), (EntityPlayerMP)senderEntity);
}
else if(args[0].toLowerCase().equals("edit"))
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
else
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit <arg>\"."), (EntityPlayerMP)senderEntity);
}
}
else if(editingInfo != null)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity);
}
else
{
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)
{
if(editingInfo != null && !editingInfo.isPendingEntitySelection)
{
if(args[0].toLowerCase().equals("edit"))
{
switch(args[1])
{
case "ignoreBattle":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE), (EntityPlayerMP) senderEntity);
break;
case "attackPower":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER), (EntityPlayerMP) senderEntity);
break;
case "attackProbability":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY), (EntityPlayerMP) senderEntity);
break;
case "attackVariance":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE), (EntityPlayerMP) senderEntity);
break;
case "attackEffect":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT), (EntityPlayerMP) senderEntity);
break;
case "attackEffectProbability":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY), (EntityPlayerMP) senderEntity);
break;
case "defenseDamage":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE), (EntityPlayerMP) senderEntity);
break;
case "defenseDamageProbability":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY), (EntityPlayerMP) senderEntity);
break;
case "evasion":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION), (EntityPlayerMP) senderEntity);
break;
case "speed":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED), (EntityPlayerMP) senderEntity);
break;
case "category":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY), (EntityPlayerMP) senderEntity);
break;
case "decisionAttack":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK), (EntityPlayerMP) senderEntity);
break;
case "decisionDefend":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND), (EntityPlayerMP) senderEntity);
break;
case "decisionFlee":
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE), (EntityPlayerMP) senderEntity);
break;
default:
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit <arg>\""), (EntityPlayerMP) senderEntity);
break;
}
}
else
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid arguments for \"/tbm-edit <arg> <arg>\"."), (EntityPlayerMP)senderEntity);
}
}
else if(editingInfo != null)
{
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);
}
}
else if(args.length == 3)
{
if(editingInfo != null && !editingInfo.isPendingEntitySelection)
{
if(args[0].toLowerCase().equals("edit"))
{
switch(args[1])
{
case "ignoreBattle":
if(args[2].toLowerCase().equals("true"))
{
editingInfo.entityInfo.ignoreBattle = true;
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
else if(args[2].toLowerCase().equals("false"))
{
editingInfo.entityInfo.ignoreBattle = false;
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
else
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit ignoreBattle <boolean>\""), (EntityPlayerMP)senderEntity);
}
break;
case "attackPower":
try
{
editingInfo.entityInfo.attackPower = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.attackPower < 0)
{
editingInfo.entityInfo.attackPower = 0;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit attackPower <integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "attackProbability":
try
{
editingInfo.entityInfo.attackProbability = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.attackProbability < 0)
{
editingInfo.entityInfo.attackProbability = 0;
}
else if(editingInfo.entityInfo.attackProbability > 100)
{
editingInfo.entityInfo.attackProbability = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit attackProbability <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "attackVariance":
try
{
editingInfo.entityInfo.attackVariance = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.attackVariance < 0)
{
editingInfo.entityInfo.attackVariance = 0;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit attackVariance <integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "attackEffect":
editingInfo.entityInfo.attackEffect = EntityInfo.Effect.fromString(args[2]);
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
break;
case "attackEffectProbability":
try
{
editingInfo.entityInfo.attackEffectProbability = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.attackEffectProbability < 0)
{
editingInfo.entityInfo.attackEffectProbability = 0;
}
else if(editingInfo.entityInfo.attackEffectProbability > 100)
{
editingInfo.entityInfo.attackEffectProbability = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit attackEffectProbability <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "defenseDamage":
try
{
editingInfo.entityInfo.defenseDamage = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.defenseDamage < 0)
{
editingInfo.entityInfo.defenseDamage = 0;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit defenseDamage <integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "defenseDamageProbability":
try
{
editingInfo.entityInfo.defenseDamageProbability = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.defenseDamageProbability < 0)
{
editingInfo.entityInfo.defenseDamageProbability = 0;
}
else if(editingInfo.entityInfo.defenseDamageProbability > 100)
{
editingInfo.entityInfo.defenseDamageProbability = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit defenseDamageProbability <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "evasion":
try
{
editingInfo.entityInfo.evasion = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.evasion < 0)
{
editingInfo.entityInfo.evasion = 0;
}
else if(editingInfo.entityInfo.evasion > 100)
{
editingInfo.entityInfo.evasion = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit evasion <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "speed":
try
{
editingInfo.entityInfo.speed = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.speed < 0)
{
editingInfo.entityInfo.speed = 0;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit speed <integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "category":
editingInfo.entityInfo.category = args[2];
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
break;
case "decisionAttack":
try
{
editingInfo.entityInfo.decisionAttack = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.decisionAttack < 0)
{
editingInfo.entityInfo.decisionAttack = 0;
}
else if(editingInfo.entityInfo.decisionAttack > 100)
{
editingInfo.entityInfo.decisionAttack = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit decisionAttack <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "decisionDefend":
try
{
editingInfo.entityInfo.decisionDefend = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.decisionDefend < 0)
{
editingInfo.entityInfo.decisionDefend = 0;
}
else if(editingInfo.entityInfo.decisionDefend > 100)
{
editingInfo.entityInfo.decisionDefend = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit decisionDefend <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
case "decisionFlee":
try
{
editingInfo.entityInfo.decisionFlee = Integer.parseInt(args[2]);
if(editingInfo.entityInfo.decisionFlee < 0)
{
editingInfo.entityInfo.decisionFlee = 0;
}
else if(editingInfo.entityInfo.decisionFlee > 100)
{
editingInfo.entityInfo.decisionFlee = 100;
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)senderEntity);
}
catch (NumberFormatException e)
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid argument for \"/tbm-edit edit decisionFlee <percentage-integer>\""), (EntityPlayerMP)senderEntity);
}
break;
default:
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid second argument for \"/tbm-edit edit <arg> <arg>\""), (EntityPlayerMP)senderEntity);
break;
}
}
else
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid arguments for \"/tbm-edit <arg> <arg> <arg>\"."), (EntityPlayerMP)senderEntity);
}
}
else if(editingInfo != null)
{
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);
}
}
else
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Invalid arguments for \"/tbm-edit\"."), (EntityPlayerMP)senderEntity);
}
}
}

View file

@ -2,6 +2,11 @@ package com.burnedkirby.TurnBasedMinecraft.common;
import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy; import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy;
import com.burnedkirby.TurnBasedMinecraft.common.networking.*; import com.burnedkirby.TurnBasedMinecraft.common.networking.*;
import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.command.Commands; import net.minecraft.command.Commands;
import net.minecraft.command.arguments.EntityArgument; import net.minecraft.command.arguments.EntityArgument;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
@ -164,7 +169,7 @@ public class TurnBasedMinecraftMod
.requires(c -> !proxy.getConfig().getIfOnlyOPsCanDisableTurnBasedForSelf() || c.hasPermissionLevel(2)) .requires(c -> !proxy.getConfig().getIfOnlyOPsCanDisableTurnBasedForSelf() || c.hasPermissionLevel(2))
.executes(c -> { .executes(c -> {
proxy.getConfig().removeBattleIgnoringPlayer(c.getSource().asPlayer().getEntityId()); proxy.getConfig().removeBattleIgnoringPlayer(c.getSource().asPlayer().getEntityId());
c.getSource().sendFeedback(new StringTextComponent("Enabled turn-based-combat for current player"), true)); c.getSource().sendFeedback(new StringTextComponent("Enabled turn-based-combat for current player"), true);
return 1; return 1;
})); }));
// tbm-enable-all // tbm-enable-all
@ -204,7 +209,322 @@ public class TurnBasedMinecraftMod
return 1; return 1;
}))); })));
// tbm-edit // tbm-edit
event.registerServerCommand(new CommandTBMEdit(proxy.getConfig())); event.getServer().getCommandManager().getDispatcher().register(
Commands.literal("tbm-edit")
.requires(c -> c.hasPermissionLevel(2))
.executes(c -> {
ServerPlayerEntity player = c.getSource().asPlayer();
EditingInfo editingInfo = proxy.getEditingInfo(player.getEntityId());
if(editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} else if(editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
} else {
proxy.setEditingPlayer(c.getSource().asPlayer());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
logger.info("Begin editing TBM Entity for player \"" + player.getDisplayName().getUnformattedComponentText() + "\"");
}
return 1;
})
.then(Commands.argument("action", StringArgumentType.word())
.executes(c -> {
String action = StringArgumentType.getString(c, "action").toLowerCase();
ServerPlayerEntity player = c.getSource().asPlayer();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId());
if(editingInfo != null && !editingInfo.isPendingEntitySelection) {
if (action.equals("finish")) {
if (!proxy.getConfig().editEntityEntry(editingInfo.entityInfo)) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("An error occurred while attempting to save an entry to the config"));
proxy.removeEditingInfo(player.getEntityId());
} else {
proxy.removeEditingInfo(player.getEntityId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Entity info saved in config and loaded."));
}
} else if (action.equals("cancel")) {
proxy.removeEditingInfo(player.getEntityId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Cancelled editing entry."));
} else if (action.equals("edit")) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} else {
Message exceptionMessage = new LiteralMessage("Invalid action for tbm-edit");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
} else if(editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
} else {
if(action.equals("custom")) {
proxy.setEditingPlayer(player);
proxy.getEditingInfo(player.getEntityId()).isEditingCustomName = true;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
logger.info("Begin editing custom TBM Entity for player \"" + player.getDisplayName().getUnformattedComponentText() + "\'");
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
}
return 1;
})
.then(Commands.argument("category", StringArgumentType.word())
.executes(c -> {
String action = StringArgumentType.getString(c, "action").toLowerCase();
String category = StringArgumentType.getString(c, "category");
ServerPlayerEntity player = c.getSource().asPlayer();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId());
if(editingInfo != null && !editingInfo.isPendingEntitySelection) {
if (action.equals("edit")) {
switch (category) {
case "ignoreBattle":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE));
break;
case "attackPower":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER));
break;
case "attackProbability":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY));
break;
case "attackVariance":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE));
break;
case "attackEffect":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT));
break;
case "attackEffectProbability":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY));
break;
case "defenseDamage":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE));
break;
case "defenseDamageProbability":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY));
break;
case "evasion":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION));
break;
case "speed":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED));
break;
case "category":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY));
break;
case "decisionAttack":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK));
break;
case "decisionDefend":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND));
break;
case "decisionFlee":
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE));
break;
default:
Message exceptionMessage = new LiteralMessage("Invalid argument for \"/tbm-edit edit <category>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
} else {
Message exceptionMessage = new LiteralMessage("Invalid argument");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
} else if(editingInfo != null){
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
return 1;
})
.then(Commands.argument("value", StringArgumentType.greedyString()))
.executes(c -> {
String action = StringArgumentType.getString(c, "action").toLowerCase();
String category = StringArgumentType.getString(c, "category");
String value = StringArgumentType.getString(c, "value").toLowerCase();
ServerPlayerEntity player = c.getSource().asPlayer();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId());
if(editingInfo != null && !editingInfo.isPendingEntitySelection) {
if (action.equals("edit")) {
switch (category) {
case "ignoreBattle":
if (value.equals("true")) {
editingInfo.entityInfo.ignoreBattle = true;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} else if (value.equals("false")) {
editingInfo.entityInfo.ignoreBattle = false;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} else {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit ignoreBattle <boolean>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "attackPower":
try {
editingInfo.entityInfo.attackPower = Integer.parseInt(value);
if (editingInfo.entityInfo.attackPower < 0) {
editingInfo.entityInfo.attackPower = 0;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackPower <integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "attackProbability":
try {
editingInfo.entityInfo.attackProbability = Integer.parseInt(value);
if (editingInfo.entityInfo.attackProbability < 0) {
editingInfo.entityInfo.attackProbability = 0;
} else if (editingInfo.entityInfo.attackProbability > 100) {
editingInfo.entityInfo.attackProbability = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackProbability <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "attackVariance":
try {
editingInfo.entityInfo.attackVariance = Integer.parseInt(value);
if (editingInfo.entityInfo.attackVariance < 0) {
editingInfo.entityInfo.attackVariance = 0;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackVariance <integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "attackEffect":
editingInfo.entityInfo.attackEffect = EntityInfo.Effect.fromString(value);
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
break;
case "attackEffectProbability":
try {
editingInfo.entityInfo.attackEffectProbability = Integer.parseInt(value);
if (editingInfo.entityInfo.attackEffectProbability < 0) {
editingInfo.entityInfo.attackEffectProbability = 0;
} else if (editingInfo.entityInfo.attackEffectProbability > 100) {
editingInfo.entityInfo.attackEffectProbability = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackEffectProbability <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "defenseDamage":
try {
editingInfo.entityInfo.defenseDamage = Integer.parseInt(value);
if (editingInfo.entityInfo.defenseDamage < 0) {
editingInfo.entityInfo.defenseDamage = 0;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit defenseDamage <integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "defenseDamageProbability":
try {
editingInfo.entityInfo.defenseDamageProbability = Integer.parseInt(value);
if (editingInfo.entityInfo.defenseDamageProbability < 0) {
editingInfo.entityInfo.defenseDamageProbability = 0;
} else if (editingInfo.entityInfo.defenseDamageProbability > 100) {
editingInfo.entityInfo.defenseDamageProbability = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit defenseDamageProbability <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "evasion":
try {
editingInfo.entityInfo.evasion = Integer.parseInt(value);
if (editingInfo.entityInfo.evasion < 0) {
editingInfo.entityInfo.evasion = 0;
} else if (editingInfo.entityInfo.evasion > 100) {
editingInfo.entityInfo.evasion = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit evasion <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "speed":
try {
editingInfo.entityInfo.speed = Integer.parseInt(value);
if (editingInfo.entityInfo.speed < 0) {
editingInfo.entityInfo.speed = 0;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit speed <integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "category":
editingInfo.entityInfo.category = value;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
break;
case "decisionAttack":
try {
editingInfo.entityInfo.decisionAttack = Integer.parseInt(value);
if (editingInfo.entityInfo.decisionAttack < 0) {
editingInfo.entityInfo.decisionAttack = 0;
} else if (editingInfo.entityInfo.decisionAttack > 100) {
editingInfo.entityInfo.decisionAttack = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit decisionAttack <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "decisionDefend":
try {
editingInfo.entityInfo.decisionDefend = Integer.parseInt(value);
if (editingInfo.entityInfo.decisionDefend < 0) {
editingInfo.entityInfo.decisionDefend = 0;
} else if (editingInfo.entityInfo.decisionDefend > 100) {
editingInfo.entityInfo.decisionDefend = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit decisionDefend <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
case "decisionFlee":
try {
editingInfo.entityInfo.decisionFlee = Integer.parseInt(value);
if (editingInfo.entityInfo.decisionFlee < 0) {
editingInfo.entityInfo.decisionFlee = 0;
} else if (editingInfo.entityInfo.decisionFlee > 100) {
editingInfo.entityInfo.decisionFlee = 100;
}
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
} catch (NumberFormatException e) {
Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit decisionFlee <percentage-integer>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
break;
default:
Message exceptionMessage = new LiteralMessage("Invalid category for \"/tbm-edit edit <category> <value>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
} else {
Message exceptionMessage = new LiteralMessage("Invalid args for \"/tbm-edit <args...>\"");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
} else if(editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
return 1;
})
))
);
} }
@SubscribeEvent @SubscribeEvent