Search in sources :

Example 6 with TrustedPlayer

use of omtteam.omlib.util.TrustedPlayer in project OpenModularTurrets by OpenModularTurretsTeam.

the class BlockTurretBase method clOnBlockActivated.

@Override
protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
        ItemStack heldItem = player.getHeldItemMainhand();
        TurretBase base = (TurretBase) world.getTileEntity(pos);
        if (player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem == ItemStackTools.getEmptyStack()) {
            if (base != null) {
                if (player.getUniqueID().toString().equals(base.getOwner())) {
                    base.setCamoState(state);
                    world.notifyBlockUpdate(pos, state, state, 3);
                } else {
                    addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
                }
            }
        }
        Block heldItemBlock = null;
        if (heldItem != ItemStackTools.getEmptyStack()) {
            heldItemBlock = Block.getBlockFromItem(heldItem.getItem());
        }
        if (!player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem != ItemStackTools.getEmptyStack() && heldItem.getItem() instanceof ItemBlock && heldItemBlock.isNormalCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && Block.getBlockFromItem(heldItem.getItem()).isOpaqueCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && !(Block.getBlockFromItem(heldItem.getItem()) instanceof BlockTurretBase)) {
            if (base != null) {
                if (player.getUniqueID().toString().equals(base.getOwner())) {
                    base.setCamoState(heldItemBlock.getStateFromMeta(heldItem.getItemDamage()));
                    world.notifyBlockUpdate(pos, state, state, 3);
                } else {
                    addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
                }
            }
        } else if (player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2) {
            ((UsableMetaItem) player.getHeldItemMainhand().getItem()).setDataStored(player.getHeldItemMainhand(), base.writeMemoryCardNBT());
        } else if (!player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2 && ((UsableMetaItem) player.getHeldItemMainhand().getItem()).hasDataStored(player.getHeldItemMainhand())) {
            base.readMemoryCardNBT(((UsableMetaItem) player.getHeldItemMainhand().getItem()).getDataStored(player.getHeldItemMainhand()));
        } else if (!player.isSneaking() && base != null) {
            TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
            if (trustedPlayer != null && trustedPlayer.canOpenGUI) {
                world.notifyBlockUpdate(pos, state, state, 6);
                player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
                return true;
            } else if (PlayerUtil.isPlayerOwner(player, base)) {
                world.notifyBlockUpdate(pos, state, state, 6);
                player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
            } else {
                addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
            }
        }
    }
    return true;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) UsableMetaItem(omtteam.openmodularturrets.items.UsableMetaItem) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) Block(net.minecraft.block.Block) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 7 with TrustedPlayer

use of omtteam.omlib.util.TrustedPlayer in project OpenModularTurrets by OpenModularTurretsTeam.

the class MessageTurretBase method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(x);
    buf.writeInt(y);
    buf.writeInt(z);
    buf.writeInt(tier);
    buf.writeInt(owner.length());
    buf.writeBytes(owner.getBytes());
    buf.writeInt(ownerName.length());
    buf.writeBytes(ownerName.getBytes());
    buf.writeInt(rfStorageCurrent);
    buf.writeInt(rfStorageMax);
    buf.writeInt(maxRange);
    buf.writeInt(mode.ordinal());
    buf.writeBoolean(attacksMobs);
    buf.writeBoolean(attacksNeutrals);
    buf.writeBoolean(attacksPlayers);
    buf.writeBoolean(multiTargeting);
    buf.writeInt(camoBlockRegName.length());
    buf.writeBytes(camoBlockRegName.getBytes());
    buf.writeInt(camoBlockMeta);
    buf.writeInt(trustedPlayers.size());
    if (trustedPlayers.size() > 0) {
        for (TrustedPlayer trustedPlayer : trustedPlayers) {
            buf.writeInt(trustedPlayer.getName().length());
            buf.writeBytes(trustedPlayer.getName().getBytes());
            buf.writeInt(trustedPlayer.uuid.toString().length());
            buf.writeBytes(trustedPlayer.uuid.toString().getBytes());
            buf.writeBoolean(trustedPlayer.canOpenGUI);
            buf.writeBoolean(trustedPlayer.canChangeTargeting);
            buf.writeBoolean(trustedPlayer.admin);
        }
    }
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer)

Example 8 with TrustedPlayer

use of omtteam.omlib.util.TrustedPlayer in project OpenModularTurrets by OpenModularTurretsTeam.

the class MessageTurretBase method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    this.x = buf.readInt();
    this.y = buf.readInt();
    this.z = buf.readInt();
    this.tier = buf.readInt();
    int ownerLength = buf.readInt();
    this.owner = new String(buf.readBytes(ownerLength).array());
    int ownerNameLength = buf.readInt();
    this.ownerName = new String(buf.readBytes(ownerNameLength).array());
    this.rfStorageCurrent = buf.readInt();
    this.rfStorageMax = buf.readInt();
    this.maxRange = buf.readInt();
    this.mode = EnumMachineMode.values()[buf.readInt()];
    this.attacksMobs = buf.readBoolean();
    this.attacksNeutrals = buf.readBoolean();
    this.attacksPlayers = buf.readBoolean();
    this.multiTargeting = buf.readBoolean();
    int camoBlockRegNameLength = buf.readInt();
    this.camoBlockRegName = new String(buf.readBytes(camoBlockRegNameLength).array());
    this.camoBlockMeta = buf.readInt();
    int lengthOfTPList = buf.readInt();
    if (lengthOfTPList > 0) {
        for (int i = 0; i < lengthOfTPList; i++) {
            int length = buf.readInt();
            String name = new String(buf.readBytes(length).array());
            TrustedPlayer trustedPlayer = new TrustedPlayer(name);
            length = buf.readInt();
            trustedPlayer.uuid = UUID.fromString(new String(buf.readBytes(length).array()));
            trustedPlayer.canOpenGUI = buf.readBoolean();
            trustedPlayer.canChangeTargeting = buf.readBoolean();
            trustedPlayer.admin = buf.readBoolean();
            trustedPlayers.add(trustedPlayer);
        }
    }
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer)

Aggregations

TrustedPlayer (omtteam.omlib.util.TrustedPlayer)8 TextComponentString (net.minecraft.util.text.TextComponentString)3 TurretBase (omtteam.openmodularturrets.tileentity.TurretBase)2 ArrayList (java.util.ArrayList)1 Callback (li.cil.oc.api.machine.Callback)1 Block (net.minecraft.block.Block)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 GuiButton (net.minecraft.client.gui.GuiButton)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 IHasItemBlock (omtteam.omlib.api.IHasItemBlock)1 UsableMetaItem (omtteam.openmodularturrets.items.UsableMetaItem)1 ItemBlockExpander (omtteam.openmodularturrets.items.blocks.ItemBlockExpander)1 ItemBlockTurretBase (omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase)1 Expander (omtteam.openmodularturrets.tileentity.Expander)1