2020-07-13 22:01:24 +05:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-08-26 21:58:45 +05:00
|
|
|
using System.Drawing;
|
2020-07-13 22:01:24 +05:00
|
|
|
using MinecraftClient.Inventory;
|
2020-08-20 21:36:50 +05:00
|
|
|
using MinecraftClient.Mapping;
|
2020-07-13 22:01:24 +05:00
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
{
|
|
|
|
|
class Entitycmd : Command
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
public override string CmdName { get { return "entity"; } }
|
|
|
|
|
public override string CmdUsage { get { return "entity <id|entitytype> <attack|use>"; } }
|
|
|
|
|
public override string CmdDesc { get { return ""; } }
|
2020-07-13 22:01:24 +05:00
|
|
|
|
|
|
|
|
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
|
|
|
|
|
{
|
|
|
|
|
if (handler.GetEntityHandlingEnabled())
|
|
|
|
|
{
|
|
|
|
|
string[] args = getArgs(command);
|
|
|
|
|
if (args.Length >= 1)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-08-20 21:36:50 +05:00
|
|
|
int entityID = 0;
|
|
|
|
|
int.TryParse(args[0], out entityID);
|
|
|
|
|
if (entityID != 0)
|
2020-07-13 22:01:24 +05:00
|
|
|
{
|
2020-08-26 21:58:45 +05:00
|
|
|
if (handler.GetEntities().ContainsKey(entityID))
|
2020-08-20 21:36:50 +05:00
|
|
|
{
|
2020-08-26 21:58:45 +05:00
|
|
|
string action = args.Length > 1
|
|
|
|
|
? args[1].ToLower()
|
|
|
|
|
: "list";
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case "attack":
|
2022-08-15 17:31:17 -04:00
|
|
|
handler.InteractEntity(entityID, InteractType.Attack);
|
2020-10-17 19:41:31 +08:00
|
|
|
return Translations.Get("cmd.entityCmd.attacked");
|
2020-08-26 21:58:45 +05:00
|
|
|
case "use":
|
2022-08-15 17:31:17 -04:00
|
|
|
handler.InteractEntity(entityID, InteractType.Interact);
|
2020-10-17 19:41:31 +08:00
|
|
|
return Translations.Get("cmd.entityCmd.used");
|
2020-08-26 21:58:45 +05:00
|
|
|
default:
|
|
|
|
|
Entity entity = handler.GetEntities()[entityID];
|
|
|
|
|
int id = entity.ID;
|
|
|
|
|
float health = entity.Health;
|
|
|
|
|
int latency = entity.Latency;
|
|
|
|
|
Item item = entity.Item;
|
|
|
|
|
string nickname = entity.Name;
|
|
|
|
|
string customname = entity.CustomName;
|
|
|
|
|
EntityPose pose = entity.Pose;
|
|
|
|
|
EntityType type = entity.Type;
|
|
|
|
|
double distance = Math.Round(entity.Location.Distance(handler.GetCurrentLocation()), 2);
|
|
|
|
|
|
|
|
|
|
string color = "§a"; // Green
|
|
|
|
|
if (health < 10)
|
|
|
|
|
color = "§c"; // Red
|
|
|
|
|
else if (health < 15)
|
|
|
|
|
color = "§e"; // Yellow
|
|
|
|
|
|
2020-12-07 19:01:32 +01:00
|
|
|
string location = String.Format("X:{0}, Y:{1}, Z:{2}", Math.Round(entity.Location.X, 2), Math.Round(entity.Location.Y, 2), Math.Round(entity.Location.Z, 2));
|
2020-10-17 19:41:31 +08:00
|
|
|
string done = Translations.Replace("([cmd.entityCmd.entity]): {0}\n [MCC] Type: {1}", id, type);
|
2020-08-26 21:58:45 +05:00
|
|
|
if (!String.IsNullOrEmpty(nickname))
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.nickname]): {0}", nickname);
|
2020-08-26 21:58:45 +05:00
|
|
|
else if (!String.IsNullOrEmpty(customname))
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.customname]): {0}§8", customname.Replace("&", "§"));
|
2020-08-26 21:58:45 +05:00
|
|
|
if (type == EntityType.Player)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.latency]): {0}", latency);
|
2020-08-26 21:58:45 +05:00
|
|
|
else if (type == EntityType.Item || type == EntityType.ItemFrame || type == Mapping.EntityType.EyeOfEnder || type == Mapping.EntityType.Egg || type == Mapping.EntityType.EnderPearl || type == Mapping.EntityType.Potion || type == Mapping.EntityType.Fireball || type == Mapping.EntityType.FireworkRocket)
|
|
|
|
|
{
|
|
|
|
|
string displayName = item.DisplayName;
|
|
|
|
|
if (String.IsNullOrEmpty(displayName))
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.item]): {0} x{1}", item.Type, item.Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
else
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.item]): {0} x{1} - {2}§8", item.Type, item.Count, displayName);
|
2020-08-26 21:58:45 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.Equipment.Count >= 1 && entity.Equipment != null)
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.equipment]):");
|
2020-08-26 21:58:45 +05:00
|
|
|
if (entity.Equipment.ContainsKey(0) && entity.Equipment[0] != null)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.mainhand]): {0} x{1}", entity.Equipment[0].Type, entity.Equipment[0].Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
if (entity.Equipment.ContainsKey(1) && entity.Equipment[1] != null)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.offhand]): {0} x{1}", entity.Equipment[1].Type, entity.Equipment[1].Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
if (entity.Equipment.ContainsKey(5) && entity.Equipment[5] != null)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.helmet]): {0} x{1}", entity.Equipment[5].Type, entity.Equipment[5].Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
if (entity.Equipment.ContainsKey(4) && entity.Equipment[4] != null)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.chestplate]): {0} x{1}", entity.Equipment[4].Type, entity.Equipment[4].Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
if (entity.Equipment.ContainsKey(3) && entity.Equipment[3] != null)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.leggings]): {0} x{1}", entity.Equipment[3].Type, entity.Equipment[3].Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
if (entity.Equipment.ContainsKey(2) && entity.Equipment[2] != null)
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.boots]): {0} x{1}", entity.Equipment[2].Type, entity.Equipment[2].Count);
|
2020-08-26 21:58:45 +05:00
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.pose]): {0}", pose);
|
|
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.health]): {0}", color + health + "§8");
|
|
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.distance]): {0}", distance);
|
|
|
|
|
done += Translations.Replace("\n [MCC] ([cmd.entityCmd.location]): {0}", location);
|
2020-08-26 21:58:45 +05:00
|
|
|
return done;
|
|
|
|
|
}
|
2020-08-20 21:36:50 +05:00
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
else return Translations.Get("cmd.entityCmd.not_found");
|
2020-08-20 21:36:50 +05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EntityType interacttype = EntityType.Player;
|
|
|
|
|
Enum.TryParse(args[0], out interacttype);
|
2020-10-17 19:41:31 +08:00
|
|
|
string actionst = "cmd.entityCmd.attacked";
|
2020-08-20 21:36:50 +05:00
|
|
|
int actioncount = 0;
|
2020-08-26 21:58:45 +05:00
|
|
|
foreach (var entity2 in handler.GetEntities())
|
2020-08-20 21:36:50 +05:00
|
|
|
{
|
|
|
|
|
if (entity2.Value.Type == interacttype)
|
|
|
|
|
{
|
|
|
|
|
string action = args.Length > 1
|
|
|
|
|
? args[1].ToLower()
|
|
|
|
|
: "list";
|
|
|
|
|
if (action == "attack")
|
|
|
|
|
{
|
2022-08-15 17:31:17 -04:00
|
|
|
handler.InteractEntity(entity2.Key, InteractType.Attack);
|
2020-10-17 19:41:31 +08:00
|
|
|
actionst = "cmd.entityCmd.attacked";
|
2020-08-20 21:36:50 +05:00
|
|
|
actioncount++;
|
|
|
|
|
}
|
|
|
|
|
else if (action == "use")
|
|
|
|
|
{
|
2022-08-15 17:31:17 -04:00
|
|
|
handler.InteractEntity(entity2.Key, InteractType.Interact);
|
2020-10-17 19:41:31 +08:00
|
|
|
actionst = "cmd.entityCmd.used";
|
2020-08-20 21:36:50 +05:00
|
|
|
actioncount++;
|
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
else return GetCmdDescTranslated();
|
2020-08-20 21:36:50 +05:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
return actioncount + " " + Translations.Get(actionst);
|
2020-07-13 22:01:24 +05:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
catch (FormatException) { return GetCmdDescTranslated(); }
|
2020-07-13 22:01:24 +05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
Dictionary<int, Entity> entities = handler.GetEntities();
|
2020-07-13 22:01:24 +05:00
|
|
|
List<string> response = new List<string>();
|
2020-10-17 19:41:31 +08:00
|
|
|
response.Add(Translations.Get("cmd.entityCmd.entities"));
|
2020-07-13 22:01:24 +05:00
|
|
|
foreach (var entity2 in entities)
|
|
|
|
|
{
|
2020-08-26 21:58:45 +05:00
|
|
|
int id = entity2.Key;
|
|
|
|
|
float health = entity2.Value.Health;
|
|
|
|
|
int latency = entity2.Value.Latency;
|
|
|
|
|
string nickname = entity2.Value.Name;
|
|
|
|
|
string customname = entity2.Value.CustomName;
|
|
|
|
|
EntityPose pose = entity2.Value.Pose;
|
|
|
|
|
EntityType type = entity2.Value.Type;
|
2020-08-27 22:33:45 +05:00
|
|
|
Item item = entity2.Value.Item;
|
2020-12-12 22:48:21 +01:00
|
|
|
string location = String.Format("X:{0}, Y:{1}, Z:{2}", Math.Round(entity2.Value.Location.X, 2), Math.Round(entity2.Value.Location.Y, 2), Math.Round(entity2.Value.Location.Z, 2));
|
2020-08-26 21:58:45 +05:00
|
|
|
|
2020-10-17 19:41:31 +08:00
|
|
|
if (type == EntityType.Item || type == EntityType.ItemFrame || type == EntityType.EyeOfEnder || type == EntityType.Egg || type == EntityType.EnderPearl || type == EntityType.Potion || type == EntityType.Fireball || type == EntityType.FireworkRocket)
|
|
|
|
|
response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.item]): {2}, ([cmd.entityCmd.location]): {3}", id, type, item.Type, location));
|
|
|
|
|
else if (type == EntityType.Player && !String.IsNullOrEmpty(nickname))
|
|
|
|
|
response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.nickname]): §8{2}§8, ([cmd.entityCmd.latency]): {3}, ([cmd.entityCmd.health]): {4}, ([cmd.entityCmd.pose]): {5}, ([cmd.entityCmd.location]): {6}", id, type, nickname, latency, health, pose, location));
|
|
|
|
|
else if (type == EntityType.Player && !String.IsNullOrEmpty(customname))
|
|
|
|
|
response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.customname]): §8{2}§8, ([cmd.entityCmd.latency]): {3}, ([cmd.entityCmd.health]): {4}, ([cmd.entityCmd.pose]): {5}, ([cmd.entityCmd.location]): {6}", id, type, customname.Replace("&", "§"), latency, health, pose, location));
|
2020-07-13 22:01:24 +05:00
|
|
|
else
|
2020-10-17 19:41:31 +08:00
|
|
|
response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.health]): {2}, ([cmd.entityCmd.location]): {3}", id, type, health, location));
|
2020-07-13 22:01:24 +05:00
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
response.Add(GetCmdDescTranslated());
|
2020-07-13 22:01:24 +05:00
|
|
|
return String.Join("\n", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
else return Translations.Get("extra.entity_required");
|
2020-07-13 22:01:24 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|