Search in sources :

Example 26 with PlayerIdentifier

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

the class CommandGristSend method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (!(sender instanceof EntityPlayerMP))
        throw new PlayerNotFoundException("commands.playerOnly.redirectGrist");
    EntityPlayerMP player = (EntityPlayerMP) sender;
    if (args.length < 3 || args.length % 2 == 0)
        throw new WrongUsageException(this.getUsage(sender));
    String receiver = args[0];
    EntityPlayerMP receivingPlayer = server.getPlayerList().getPlayerByUsername(receiver);
    if (receivingPlayer != null) {
        if (!isPermittedFor(player, receivingPlayer))
            throw new CommandException("commands.gristSend.notPermitted", receivingPlayer.getName());
        GristSet set = new GristSet();
        GristAmount[] parsedAmounts = CommandGrist.parseGrist(args, 1);
        for (GristAmount amount : parsedAmounts) set.addGrist(amount);
        GristSet playerGrist = MinestuckPlayerData.getGristSet(player);
        GristSet receiverGrist = MinestuckPlayerData.getGristSet(receivingPlayer);
        StringBuilder costStr = new StringBuilder();
        boolean first = true;
        for (GristType type : GristType.values()) {
            int i = Math.max(0, Math.min(playerGrist.getGrist(type), set.getGrist(type)));
            if (i > 0) {
                playerGrist.addGrist(type, -i);
                receiverGrist.addGrist(type, i);
                if (!first)
                    costStr.append(", ");
                costStr.append(i + " " + type.getDisplayName());
                first = false;
            }
        }
        PlayerIdentifier senderIdentifier;
        PlayerIdentifier receiverIdentifier;
        senderIdentifier = IdentifierHandler.encode(player);
        receiverIdentifier = IdentifierHandler.encode(receivingPlayer);
        MinestuckPlayerTracker.updateGristCache(senderIdentifier);
        MinestuckPlayerTracker.updateGristCache(receiverIdentifier);
        notifyCommandListener(sender, this, "commands.gristSend.success", receiver, costStr.toString());
    } else
        throw new PlayerNotFoundException("Couldn't find player \"%s\".", receiver);
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 27 with PlayerIdentifier

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

the class CommandGristSend method isPermittedFor.

private static boolean isPermittedFor(EntityPlayerMP player, EntityPlayerMP player2) {
    PlayerIdentifier name1 = IdentifierHandler.encode(player), name2 = IdentifierHandler.encode(player2);
    SburbConnection c1 = SkaianetHandler.getMainConnection(name1, true);
    SburbConnection c2 = SkaianetHandler.getMainConnection(name2, true);
    if (c1 == null || c2 == null || !c1.enteredGame() || !c2.enteredGame())
        return false;
    else
        return SessionHandler.getPlayerSession(name1) == SessionHandler.getPlayerSession(name2);
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

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