Search in sources :

Example 1 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class CommandGrist method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 1 || (!args[0].equalsIgnoreCase("get") && args.length < 2))
        throw new WrongUsageException(this.getUsage(sender));
    String command = args[0];
    PlayerIdentifier identifier;
    int offset = 1;
    if (!(command.equalsIgnoreCase("set") || command.equalsIgnoreCase("add") || command.equalsIgnoreCase("get"))) {
        command = args[1];
        identifier = IdentifierHandler.getForCommand(server, sender, args[0]);
        offset = 2;
    } else {
        EntityPlayerMP player = getCommandSenderAsPlayer(sender);
        identifier = IdentifierHandler.encode(player);
    }
    if ((args.length - offset) % 2 != 0)
        throw new WrongUsageException(this.getUsage(sender));
    String displayName = identifier.getUsername();
    if (command.equalsIgnoreCase("set")) {
        // Using a GristAmount array instead of a GristSet gives support for setting grist to 0
        GristAmount[] grist = parseGrist(args, offset);
        for (GristAmount amount : grist) GristHelper.setGrist(identifier, amount.getType(), amount.getAmount());
        MinestuckPlayerTracker.updateGristCache(identifier);
        notifyCommandListener(sender, this, "commands.grist.setSuccess", displayName);
    } else if (command.equalsIgnoreCase("add")) {
        GristSet grist = new GristSet(parseGrist(args, offset));
        GristHelper.increase(identifier, grist);
        MinestuckPlayerTracker.updateGristCache(identifier);
        notifyCommandListener(sender, this, "commands.grist.addSuccess", displayName);
    } else if (command.equalsIgnoreCase("get")) {
        StringBuilder grist = new StringBuilder();
        for (GristAmount amount : MinestuckPlayerData.getGristSet(identifier).getArray()) if (amount.getAmount() != 0)
            // TODO properly translate display name for client side
            grist.append("\n").append(amount.getAmount()).append(" ").append(amount.getType().getDisplayName());
        sender.sendMessage(new TextComponentTranslation("commands.grist.get", displayName, grist.toString()));
    } else
        throw new WrongUsageException("commands.invalidSubCommand", command);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Example 2 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class CommandSburbServer method execute.

@Override
public void execute(MinecraftServer mcServer, ICommandSender sender, String[] args) throws CommandException {
    if (args.length != 2)
        throw new WrongUsageException("commands.sburbServer.usage");
    PlayerIdentifier client = IdentifierHandler.getForCommand(mcServer, sender, args[0]);
    PlayerIdentifier server = IdentifierHandler.getForCommand(mcServer, sender, args[1]);
    SessionHandler.connectByCommand(sender, this, client, server);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Example 3 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class CommandSetRung method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 2)
        throw new WrongUsageException(this.getUsage(sender));
    PlayerIdentifier target = IdentifierHandler.getForCommand(server, sender, args[0]);
    int rung = parseInt(args[1], 0, Echeladder.RUNG_COUNT - 1);
    double progress = 0;
    if (args.length >= 3)
        progress = parseDouble(args[2], 0, 1);
    Echeladder echeladder = MinestuckPlayerData.getData(target).echeladder;
    echeladder.setByCommand(rung, progress);
    notifyCommandListener(sender, this, "commands.setRung.success", target.getUsername(), rung, progress * 100);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) Echeladder(com.mraof.minestuck.util.Echeladder)

Example 4 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class MessageType method createMessage.

private static ITextComponent createMessage(EntityConsort consort, EntityPlayer player, String unlocalizedMessage, String[] args, boolean consortPrefix) {
    String s = EntityList.getEntityString(consort);
    if (s == null) {
        s = "generic";
    }
    Object[] obj = new Object[args.length];
    SburbConnection c = SburbHandler.getConnectionForDimension(consort.homeDimension);
    Title title = c == null ? null : MinestuckPlayerData.getData(c.getClientIdentifier()).title;
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("playerNameLand")) {
            if (c != null)
                obj[i] = c.getClientIdentifier().getUsername();
            else
                obj[i] = "Player name";
        } else if (args[i].equals("playerName")) {
            obj[i] = player.getName();
        } else if (args[i].equals("landName")) {
            World world = consort.getServer().getWorld(consort.homeDimension);
            if (world != null && consort.world.provider instanceof WorldProviderLands) {
                ChunkProviderLands chunkProvider = (ChunkProviderLands) world.provider.createChunkGenerator();
                ITextComponent aspect1 = new TextComponentTranslation("land." + chunkProvider.aspect1.getNames()[chunkProvider.nameIndex1]);
                ITextComponent aspect2 = new TextComponentTranslation("land." + chunkProvider.aspect2.getNames()[chunkProvider.nameIndex2]);
                if (chunkProvider.nameOrder)
                    obj[i] = new TextComponentTranslation("land.format", aspect1, aspect2);
                else
                    obj[i] = new TextComponentTranslation("land.format", aspect2, aspect1);
            } else
                obj[i] = "Land name";
        } else if (args[i].equals("playerTitleLand")) {
            if (title != null)
                obj[i] = title.asTextComponent();
            else
                obj[i] = "Player title";
        } else if (args[i].equals("playerClassLand")) {
            if (title != null)
                obj[i] = title.getHeroClass().asTextComponent();
            else
                obj[i] = "Player class";
        } else if (args[i].equals("playerAspectLand")) {
            if (title != null)
                obj[i] = title.getHeroAspect().asTextComponent();
            else
                obj[i] = "Player aspect";
        } else if (args[i].equals("consortSound")) {
            obj[i] = new TextComponentTranslation("consort.sound." + s);
        } else if (args[i].equals("consortType")) {
            obj[i] = new TextComponentTranslation("entity." + s + ".name");
        } else if (args[i].equals("consortTypes")) {
            obj[i] = new TextComponentTranslation("entity." + s + ".plural.name");
        } else if (args[i].equals("playerTitle")) {
            PlayerIdentifier identifier = IdentifierHandler.encode(player);
            if (MinestuckPlayerData.getTitle(identifier) != null)
                obj[i] = MinestuckPlayerData.getTitle(identifier).asTextComponent();
            else
                obj[i] = player.getName();
        } else if (args[i].equals("denizen")) {
            if (title != null)
                obj[i] = new TextComponentTranslation("denizen." + MinestuckPlayerData.getData(c.getClientIdentifier()).title.getHeroAspect().toString() + ".name");
            else
                obj[i] = "Denizen";
        } else if (args[i].startsWith("nbtItem:")) {
            NBTTagCompound nbt = consort.getMessageTagForPlayer(player);
            ItemStack stack = new ItemStack(nbt.getCompoundTag(args[i].substring(8)));
            if (!stack.isEmpty())
                obj[i] = new TextComponentTranslation(stack.getUnlocalizedName() + ".name");
            else
                obj[i] = "Item";
        }
    }
    TextComponentTranslation message = new TextComponentTranslation("consort." + unlocalizedMessage, obj);
    if (consortPrefix) {
        message.getStyle().setColor(consort.getConsortType().getColor());
        TextComponentTranslation entity = new TextComponentTranslation("entity." + s + ".name");
        return new TextComponentTranslation("chat.type.text", entity, message);
    } else
        return message;
}
Also used : ChunkProviderLands(com.mraof.minestuck.world.lands.gen.ChunkProviderLands) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Title(com.mraof.minestuck.util.Title) World(net.minecraft.world.World) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) WorldProviderLands(com.mraof.minestuck.world.WorldProviderLands) ItemStack(net.minecraft.item.ItemStack) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 5 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SburbHandler method predefineTitle.

public static void predefineTitle(MinecraftServer server, ICommandSender sender, ICommand command, String playerName, String sessionName, Title title) throws CommandException {
    PlayerIdentifier identifier = predefineCheck(server, sender, playerName, sessionName);
    Title playerTitle = MinestuckPlayerData.getTitle(identifier);
    if (playerTitle != null)
        throw new CommandException("You can't change your title after having entered the medium.");
    Session session = sessionsByName.get(sessionName);
    for (SburbConnection c : session.connections) if (c.isMain && c.enteredGame && title.equals(MinestuckPlayerData.getTitle(c.getClientIdentifier())))
        throw new CommandException("This title is already used by %s.", c.getClientIdentifier().getUsername());
    for (Map.Entry<PlayerIdentifier, PredefineData> entry : session.predefinedPlayers.entrySet()) if (entry.getValue().title != null && title.equals(entry.getValue().title))
        throw new CommandException("This title is already assigned to %s.", entry.getKey().getUsername());
    PredefineData data = session.predefinedPlayers.get(identifier);
    data.title = title;
    TitleLandAspect landAspect = LandAspectRegistry.getSingleLandAspect(title.getHeroAspect());
    if (landAspect != null)
        // This part could be made more robust for when landTerrain is already defined
        data.landTitle = landAspect;
    CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.titleSuccess", playerName, title.asTextComponent());
}
Also used : TitleLandAspect(com.mraof.minestuck.world.lands.title.TitleLandAspect) CommandException(net.minecraft.command.CommandException) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Aggregations

PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)27 TextComponentString (net.minecraft.util.text.TextComponentString)7 CommandException (net.minecraft.command.CommandException)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 MinestuckPacket (com.mraof.minestuck.network.MinestuckPacket)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 Style (net.minecraft.util.text.Style)3 SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)2 TileEntityComputer (com.mraof.minestuck.tileentity.TileEntityComputer)2 Title (com.mraof.minestuck.util.Title)2 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 UserListOpsEntry (net.minecraft.server.management.UserListOpsEntry)2 Vec3d (net.minecraft.util.math.Vec3d)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 Modus (com.mraof.minestuck.inventory.captchalouge.Modus)1 Echeladder (com.mraof.minestuck.util.Echeladder)1 WorldProviderLands (com.mraof.minestuck.world.WorldProviderLands)1 LandAspectRegistry (com.mraof.minestuck.world.lands.LandAspectRegistry)1