Added a /disguise command

This commit is contained in:
Sollace 2019-02-17 02:03:55 +02:00
parent eb0341b632
commit 851c1650be
5 changed files with 133 additions and 7 deletions

View file

@ -0,0 +1,113 @@
package com.minelittlepony.unicopia.command;
import java.util.List;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.spell.SpellDisguise;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
class CommandDisguise extends CommandBase {
@Override
public String getName() {
return "disguise";
}
@Override
public int getRequiredPermissionLevel() {
return 2;
}
@Override
public String getUsage(ICommandSender sender) {
return "commands.disguise.usage";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 2) {
throw new WrongUsageException(getUsage(sender));
}
EntityPlayerMP player = args.length > 1 ? getPlayer(server, sender, args[0]) : getCommandSenderAsPlayer(sender);
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player);
Entity entity = constructDisguiseEntity(player.world, args);
if (entity == null) {
throw new CommandException("commands.disguise.notfound", args[1]);
}
SpellDisguise effect = iplayer.getEffect(SpellDisguise.class, true);
if (effect == null) {
iplayer.setEffect(new SpellDisguise().setDisguise(entity));
} else {
effect.setDisguise(entity);
}
if (player != sender) {
notifyCommandListener(sender, this, 1, "commands.disguise.success.other", player.getName(), entity.getName());
} else {
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
player.sendMessage(new TextComponentTranslation("commands.disguise.success.self", entity.getName()));
}
notifyCommandListener(sender, this, 1, "commands.disguise.success.otherself", player.getName(), entity.getName());
}
}
protected Entity constructDisguiseEntity(World world, String[] args) throws CommandException {
NBTTagCompound nbt = getEntityNBT(args);
nbt.setString("id", args[1]);
return AnvilChunkLoader.readWorldEntityPos(nbt, world, 0, 0, 0, false);
}
protected NBTTagCompound getEntityNBT(String[] args) throws CommandException {
if (args.length > 2) {
try {
return JsonToNBT.getTagFromJson(buildString(args, 2));
} catch (NBTException e) {
throw new CommandException("commands.summon.tagError", e.getMessage());
}
}
return new NBTTagCompound();
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
}
if (args.length == 2) {
return getListOfStringsMatchingLastWord(args, EntityList.getEntityNameList());
}
return null;
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return index == 1;
}
}

View file

@ -21,28 +21,27 @@ import net.minecraft.util.text.TextFormatting;
class CommandSpecies extends CommandBase { class CommandSpecies extends CommandBase {
@Override
public String getName() { public String getName() {
return "race"; return "race";
} }
@Override
public int getRequiredPermissionLevel() { public int getRequiredPermissionLevel() {
return 0; return 0;
} }
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) { public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return sender.canUseCommand(getRequiredPermissionLevel(), "help"); return sender.canUseCommand(getRequiredPermissionLevel(), "help");
} }
private String getRacesString() { @Override
String values = "";
return values;
}
public String getUsage(ICommandSender sender) { public String getUsage(ICommandSender sender) {
return "commands.race.usage"; return "commands.race.usage";
} }
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!processCommand(server, sender, args)) { if (!processCommand(server, sender, args)) {
throw new WrongUsageException(getUsage(sender)); throw new WrongUsageException(getUsage(sender));
@ -133,7 +132,7 @@ class CommandSpecies extends CommandBase {
protected boolean list(EntityPlayer player) { protected boolean list(EntityPlayer player) {
player.sendMessage(new TextComponentTranslation("commands.race.list")); player.sendMessage(new TextComponentTranslation("commands.race.list"));
ITextComponent message = new TextComponentString(getRacesString()); ITextComponent message = new TextComponentString("");
boolean first = true; boolean first = true;
for (Race i : Race.values()) { for (Race i : Race.values()) {

View file

@ -8,6 +8,7 @@ public class Commands {
event.registerServerCommand(new CommandOverrideGameMode()); event.registerServerCommand(new CommandOverrideGameMode());
event.registerServerCommand(new CommandSpecies()); event.registerServerCommand(new CommandSpecies());
event.registerServerCommand(new CommandRacelist()); event.registerServerCommand(new CommandRacelist());
event.registerServerCommand(new CommandDisguise());
event.getServer().setAllowFlight(true); event.getServer().setAllowFlight(true);
} }

View file

@ -19,6 +19,7 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityFlying; import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
@ -26,6 +27,7 @@ import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.item.EntityFallingBlock; import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.item.EntityMinecart; import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.monster.EntityShulker; import net.minecraft.entity.monster.EntityShulker;
import net.minecraft.entity.monster.EntityVex;
import net.minecraft.entity.passive.EntityAmbientCreature; import net.minecraft.entity.passive.EntityAmbientCreature;
import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -103,6 +105,8 @@ public class SpellDisguise extends AbstractSpell implements ISuppressable, IFlyi
entityId = entityNbt.getString("id"); entityId = entityNbt.getString("id");
} }
setDirty(true);
return this; return this;
} }
@ -449,6 +453,7 @@ public class SpellDisguise extends AbstractSpell implements ISuppressable, IFlyi
return entity instanceof EntityFlying return entity instanceof EntityFlying
|| entity instanceof net.minecraft.entity.passive.EntityFlying || entity instanceof net.minecraft.entity.passive.EntityFlying
|| entity instanceof EntityDragon || entity instanceof EntityDragon
|| entity instanceof EntityVex
|| entity instanceof EntityAmbientCreature || entity instanceof EntityAmbientCreature
|| entity instanceof EntityShulkerBullet || entity instanceof EntityShulkerBullet
|| ProjectileUtil.isProjectile(entity); || ProjectileUtil.isProjectile(entity);
@ -478,11 +483,13 @@ public class SpellDisguise extends AbstractSpell implements ISuppressable, IFlyi
public static boolean skipsUpdate(Entity entity) { public static boolean skipsUpdate(Entity entity) {
return entity instanceof EntityFallingBlock return entity instanceof EntityFallingBlock
|| entity instanceof EntityHanging
|| entity instanceof EntityPlayer; || entity instanceof EntityPlayer;
} }
public static boolean isAttachedEntity(Entity entity) { public static boolean isAttachedEntity(Entity entity) {
return entity instanceof EntityShulker return entity instanceof EntityShulker
|| entity instanceof EntityHanging
|| entity instanceof EntityFallingBlock; || entity instanceof EntityFallingBlock;
} }
} }

View file

@ -192,6 +192,12 @@ commands.racelist.disallowed.failed=%1$s is not on the whitelist.
commands.racelist.disallowed.other=%1$s was removed from the whitelist by %2$s. commands.racelist.disallowed.other=%1$s was removed from the whitelist by %2$s.
commands.racelist.disallowed.failed.other=%2$s tried to remove %1$s from the whitelist but it has not been added yet. commands.racelist.disallowed.failed.other=%2$s tried to remove %1$s from the whitelist but it has not been added yet.
commands.disguise.usage=/disguise <player> <entity> [nbt]
commands.disguise.notfound=The entity id '%s' does not exist.
commands.disguise.success.other=%1$s is now disguised as %2$s
commands.disguise.success.self=Updated disguise to %s
commands.disguise.success.otherself=%1$s changed their disguise to %2$s
unicopia.race.human=Human unicopia.race.human=Human
unicopia.race.human.alt=Humans unicopia.race.human.alt=Humans
unicopia.race.earth=Earth Pony unicopia.race.earth=Earth Pony