Search in sources :

Example 1 with UserListOpsEntry

use of net.minecraft.server.management.UserListOpsEntry in project SpongeCommon by SpongePowered.

the class UserSubject method getOpLevel.

int getOpLevel() {
    Preconditions.checkState(Sponge.isServerAvailable(), "Server is not available!");
    // Query op level from server ops list based on player's game profile
    UserListOpsEntry entry = SpongePermissionService.getOps().getEntry(this.player);
    if (entry == null) {
        // Take care of singleplayer commands -- unless an op level is specified, this player follows global rules
        return SpongeImpl.getServer().getPlayerList().canSendCommands(this.player) ? SpongeImpl.getServer().getOpPermissionLevel() : 0;
    } else {
        return entry.getPermissionLevel();
    }
}
Also used : UserListOpsEntry(net.minecraft.server.management.UserListOpsEntry)

Example 2 with UserListOpsEntry

use of net.minecraft.server.management.UserListOpsEntry in project Minestuck by mraof.

the class SkaianetHandler method checkData.

private static void checkData() {
    Iterator<PlayerIdentifier> iter0 = infoToSend.keySet().iterator();
    while (iter0.hasNext()) if (iter0.next().getPlayer() == null) {
        // Debug.print("[SKAIANET] Player disconnected, removing data.");
        iter0.remove();
    }
    @SuppressWarnings("unchecked") Iterator<ComputerData>[] iter1 = new Iterator[] { serversOpen.values().iterator(), resumingClients.values().iterator(), resumingServers.values().iterator() };
    for (Iterator<ComputerData> i : iter1) while (i.hasNext()) {
        ComputerData data = i.next();
        if (getComputer(data) == null || data.dimension == -1 || !getComputer(data).owner.equals(data.owner) || !(i == iter1[1] && getComputer(data).getData(0).getBoolean("isResuming") || i != iter1[1] && getComputer(data).getData(1).getBoolean("isOpen"))) {
            Debug.warn("[SKAIANET] Invalid computer in waiting list!");
            i.remove();
        }
    }
    Iterator<SburbConnection> iter2 = connections.iterator();
    while (iter2.hasNext()) {
        SburbConnection c = iter2.next();
        if (c.getClientIdentifier() == null || c.getServerIdentifier() == null) {
            Debug.warn("Found a broken connection with the client \"" + c.getClientIdentifier() + "\" and server \"" + c.getServerIdentifier() + ". If this message continues to show up, something isn't working as it should.");
            iter2.remove();
            continue;
        }
        if (c.isActive) {
            TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
            if (cc == null || sc == null || c.client.dimension == -1 || c.server.dimension == -1 || !c.getClientIdentifier().equals(cc.owner) || !c.getServerIdentifier().equals(sc.owner) || !cc.getData(0).getBoolean("connectedToServer")) {
                Debug.warnf("[SKAIANET] Invalid computer in connection between %s and %s.", c.getClientIdentifier(), c.getServerIdentifier());
                if (!c.isMain)
                    iter2.remove();
                else
                    c.isActive = false;
                SessionHandler.onConnectionClosed(c, true);
                ServerEditHandler.onDisconnect(c);
                if (cc != null) {
                    cc.getData(0).setBoolean("connectedToServer", false);
                    cc.latestmessage.put(0, "computer.messageClosed");
                    cc.markBlockForUpdate();
                } else if (sc != null) {
                    sc.latestmessage.put(1, "computer.messageClosed");
                    sc.markBlockForUpdate();
                }
            }
            if (// If the center location isn't defined
            cc != null && c.enteredGame && c.inventory == null && c.centerX == 0 && c.centerZ == 0) {
                c.centerX = cc.getPos().getX();
                c.centerZ = cc.getPos().getZ();
                c.inventory = new NBTTagList();
            }
            if (cc != null && c.enteredGame && !MinestuckDimensionHandler.isLandDimension(c.clientHomeLand))
                c.clientHomeLand = c.client.dimension;
        }
        if (c.enteredGame && !MinestuckDimensionHandler.isLandDimension(c.clientHomeLand)) {
            EntityPlayerMP player = c.getClientIdentifier().getPlayer();
            if (player != null) {
                c.clientHomeLand = player.dimension;
                if (!MinestuckDimensionHandler.isLandDimension(c.clientHomeLand)) {
                    iter2.remove();
                    SessionHandler.onConnectionClosed(c, false);
                    if (c.isActive) {
                        TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
                        cc.getData(0).setBoolean("connectedToServer", false);
                        cc.latestmessage.put(0, "computer.messageClosed");
                        cc.markBlockForUpdate();
                        sc.getData(1).setString("connectedClient", "");
                        sc.latestmessage.put(1, "computer.messageClosed");
                        sc.markBlockForUpdate();
                    }
                }
            }
        }
    }
    if (MinestuckConfig.privateComputers) {
        for (Entry<PlayerIdentifier, PlayerIdentifier[]> entry : infoToSend.entrySet()) {
            EntityPlayerMP player = entry.getKey().getPlayer();
            UserListOpsEntry opsEntry = player == null ? null : player.getServer().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
            if (opsEntry != null && opsEntry.getPermissionLevel() >= 2)
                continue;
            for (int i = 0; i < entry.getValue().length; i++) if (entry.getValue()[i] != null && !entry.getValue()[i].equals(entry.getKey()))
                entry.getValue()[i] = null;
        }
    }
}
Also used : TileEntityComputer(com.mraof.minestuck.tileentity.TileEntityComputer) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) NBTTagList(net.minecraft.nbt.NBTTagList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UserListOpsEntry(net.minecraft.server.management.UserListOpsEntry)

Example 3 with UserListOpsEntry

use of net.minecraft.server.management.UserListOpsEntry 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 4 with UserListOpsEntry

use of net.minecraft.server.management.UserListOpsEntry in project Minestuck by mraof.

the class SkaianetHandler method requestInfo.

public static void requestInfo(EntityPlayer player, PlayerIdentifier p1) {
    checkData();
    PlayerIdentifier p0 = IdentifierHandler.encode(player);
    PlayerIdentifier[] s = infoToSend.get(p0);
    if (s == null) {
        Debug.error("[SKAIANET] Something went wrong with player \"" + player.getName() + "\"'s skaianet data!");
        return;
    }
    UserListOpsEntry opsEntry = player.getServer().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
    if (MinestuckConfig.privateComputers && !p0.equals(p1) && !(opsEntry != null && opsEntry.getPermissionLevel() >= 2)) {
        player.sendMessage(new TextComponentString("[Minestuck] ").setStyle(new Style().setColor(TextFormatting.RED)).appendSibling(new TextComponentTranslation("message.privateComputerMessage")));
        return;
    }
    int i = 0;
    for (; i < s.length; i++) {
        if (s[i] == null)
            break;
        if (s[i].equals(p1)) {
            Debug.warnf("[Skaianet] Player %s already got the requested data.", player.getName());
            // Update anyway, to fix whatever went wrong
            updatePlayer(p0);
            return;
        }
    }
    if (// If the array is full, increase size with 5.
    i == s.length) {
        PlayerIdentifier[] newS = new PlayerIdentifier[s.length + 5];
        System.arraycopy(s, 0, newS, 0, s.length);
        s = newS;
        infoToSend.put(p0, s);
    }
    s[i] = p1;
    updatePlayer(p0);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) UserListOpsEntry(net.minecraft.server.management.UserListOpsEntry) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

UserListOpsEntry (net.minecraft.server.management.UserListOpsEntry)4 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)1 TileEntityComputer (com.mraof.minestuck.tileentity.TileEntityComputer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 Style (net.minecraft.util.text.Style)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1