Search in sources :

Example 6 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class ClientEditPacket method execute.

@Override
public void execute(EntityPlayer player) {
    UserListOpsEntry opsEntry = player == null ? null : player.getServer().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
    if (!MinestuckConfig.giveItems) {
        if (username == -1)
            ServerEditHandler.onPlayerExit(player);
        else if (!MinestuckConfig.privateComputers || IdentifierHandler.encode(player).getId() == this.username || opsEntry != null && opsEntry.getPermissionLevel() >= 2)
            ServerEditHandler.newServerEditor((EntityPlayerMP) player, IdentifierHandler.getById(username), IdentifierHandler.getById(target));
        return;
    }
    EntityPlayerMP playerMP = IdentifierHandler.getById(target).getPlayer();
    if (playerMP != null && (!MinestuckConfig.privateComputers || IdentifierHandler.getById(username).appliesTo(player)) || opsEntry != null && opsEntry.getPermissionLevel() >= 2) {
        SburbConnection c = SkaianetHandler.getClientConnection(IdentifierHandler.getById(target));
        if (c == null || c.getServerIdentifier().getId() != username || !(c.isMain() || SkaianetHandler.giveItems(IdentifierHandler.getById(target))))
            return;
        for (int i = 0; i < 5; i++) if (i == 4) {
            if (c.enteredGame())
                continue;
            ItemStack card = AlchemyRecipeHandler.createCard(SburbHandler.getEntryItem(c.getClientIdentifier()), true);
            if (!playerMP.inventory.hasItemStack(card))
                c.givenItems()[i] = playerMP.inventory.addItemStackToInventory(card) || c.givenItems()[i];
        } else {
            ItemStack machine = new ItemStack(MinestuckBlocks.sburbMachine, 1, i);
            if (i == 1 && !c.enteredGame())
                continue;
            if (!playerMP.inventory.hasItemStack(machine))
                c.givenItems()[i] = playerMP.inventory.addItemStackToInventory(machine) || c.givenItems()[i];
        }
        player.getServer().getPlayerList().syncPlayerInventory(playerMP);
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) UserListOpsEntry(net.minecraft.server.management.UserListOpsEntry) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 7 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class MinestuckPlayerTracker method updateGristCache.

/**
 * Uses an "encoded" username as parameter.
 */
public static void updateGristCache(PlayerIdentifier player) {
    GristSet gristSet = MinestuckPlayerData.getGristSet(player);
    // The player
    EntityPlayerMP playerMP = player.getPlayer();
    if (playerMP != null) {
        MinestuckPacket packet = MinestuckPacket.makePacket(Type.GRISTCACHE, gristSet, false);
        MinestuckChannelHandler.sendToPlayer(packet, playerMP);
    }
    // The editing player, if there is any.
    SburbConnection c = SkaianetHandler.getClientConnection(player);
    if (c != null && ServerEditHandler.getData(c) != null) {
        EntityPlayerMP editor = ServerEditHandler.getData(c).getEditor();
        MinestuckPacket packet = MinestuckPacket.makePacket(Type.GRISTCACHE, gristSet, true);
        MinestuckChannelHandler.sendToPlayer(packet, editor);
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 8 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class GristHelper method notifyServer.

private static void notifyServer(PlayerIdentifier player, String type, Integer difference, String action) {
    SburbConnection sc = SkaianetHandler.getClientConnection(player);
    if (sc == null)
        return;
    EditData ed = ServerEditHandler.getData(sc);
    if (ed == null)
        return;
    notify(IdentifierHandler.encode(ed.getEditor()), type, difference, action);
}
Also used : EditData(com.mraof.minestuck.editmode.EditData) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 9 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class SburbClient method getStringList.

@Override
public ArrayList<UnlocalizedString> getStringList(TileEntityComputer te) {
    ArrayList<UnlocalizedString> list = new ArrayList<UnlocalizedString>();
    NBTTagCompound nbt = te.getData(getId());
    SburbConnection c = SkaiaClient.getClientConnection(te.ownerId);
    if (// If it is connected to someone.
    nbt.getBoolean("connectedToServer") && c != null) {
        String displayPlayer = c.getServerDisplayName();
        list.add(new UnlocalizedString("computer.messageConnect", displayPlayer));
        list.add(new UnlocalizedString("computer.buttonClose"));
    } else if (nbt.getBoolean("isResuming")) {
        list.add(new UnlocalizedString("computer.messageResumeClient"));
        list.add(new UnlocalizedString("computer.buttonClose"));
    } else if (// If the player doesn't have an other active client
    !SkaiaClient.isActive(te.ownerId, true)) {
        list.add(new UnlocalizedString("computer.messageSelect"));
        if (// If it has a resumable connection
        SkaiaClient.getAssociatedPartner(te.ownerId, true) != -1)
            list.add(new UnlocalizedString("computer.buttonResume"));
        for (Map.Entry<Integer, String> entry : SkaiaClient.getAvailableServers(te.ownerId).entrySet()) list.add(new UnlocalizedString("computer.buttonConnect", entry.getValue(), entry.getKey()));
    } else
        list.add(new UnlocalizedString("computer.messageClientActive"));
    if (SkaiaClient.canSelect(te.ownerId))
        list.add(new UnlocalizedString("computer.selectColor"));
    return list;
}
Also used : ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Map(java.util.Map) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 10 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class SburbServer method getStringList.

@Override
public ArrayList<UnlocalizedString> getStringList(TileEntityComputer te) {
    int clientId = te.getData(1).hasKey("connectedClient") ? te.getData(1).getInteger("connectedClient") : -1;
    SburbConnection connection = clientId != -1 ? SkaiaClient.getClientConnection(clientId) : null;
    if (connection != null && connection.getServerId() != te.ownerId)
        connection = null;
    ArrayList<UnlocalizedString> list = new ArrayList<UnlocalizedString>();
    String displayPlayer = connection == null ? "UNDEFINED" : connection.getClientDisplayName();
    if (connection != null) {
        list.add(new UnlocalizedString("computer.messageConnect", displayPlayer));
        list.add(new UnlocalizedString("computer.buttonClose"));
        list.add(new UnlocalizedString(MinestuckConfig.clientGiveItems ? "computer.buttonGive" : "computer.buttonEdit"));
    } else if (te.getData(getId()).getBoolean("isOpen")) {
        list.add(new UnlocalizedString("computer.messageResumeServer"));
        list.add(new UnlocalizedString("computer.buttonClose"));
    } else if (SkaiaClient.isActive(te.ownerId, false))
        list.add(new UnlocalizedString("computer.messageServerActive"));
    else {
        list.add(new UnlocalizedString("computer.messageOffline"));
        list.add(new UnlocalizedString("computer.buttonOpen"));
        if (SkaiaClient.getAssociatedPartner(te.ownerId, false) != -1)
            list.add(new UnlocalizedString("computer.buttonResume"));
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Aggregations

SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 MinestuckPacket (com.mraof.minestuck.network.MinestuckPacket)3 ArrayList (java.util.ArrayList)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 ItemStack (net.minecraft.item.ItemStack)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EditData (com.mraof.minestuck.editmode.EditData)1 EntityDecoy (com.mraof.minestuck.entity.EntityDecoy)1 ItemCruxiteArtifact (com.mraof.minestuck.item.ItemCruxiteArtifact)1 Location (com.mraof.minestuck.util.Location)1 Title (com.mraof.minestuck.util.Title)1 WorldProviderLands (com.mraof.minestuck.world.WorldProviderLands)1 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)1 Map (java.util.Map)1 Random (java.util.Random)1