<commit_before>/*
 * Aeronica's mxTune MOD
 * Copyright {2016} <NAME> a.k.a. Aeronica
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.aeronica.mods.mxtune.network.server;

import net.aeronica.mods.mxtune.blocks.TileBandAmp;
import net.aeronica.mods.mxtune.network.AbstractMessage;
import net.aeronica.mods.mxtune.sound.SoundRange;
import net.aeronica.mods.mxtune.world.IModLockableContainer;
import net.aeronica.mods.mxtune.world.OwnerUUID;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LockCode;
import net.minecraftforge.fml.relauncher.Side;

public class BandAmpMessage extends AbstractMessage.AbstractServerMessage<BandAmpMessage>
{
    private boolean lockContainer;
    private BlockPos pos;
    private boolean rearRedstoneInputEnabled;
    private boolean leftRedstoneOutputEnabled;
    private boolean rightRedstoneOutputEnabled;
    private SoundRange soundRange;

    @SuppressWarnings("unused")
    public BandAmpMessage() {/* NOP */}

    public BandAmpMessage(BlockPos pos, boolean lockContainer, boolean rearRedstoneInputEnabled, boolean leftRedstoneOutputEnabled, boolean rightRedstoneOutputEnabled, SoundRange soundRange)
    {
        this.pos = pos;
        this.lockContainer = lockContainer;
        this.rearRedstoneInputEnabled = rearRedstoneInputEnabled;
        this.leftRedstoneOutputEnabled = leftRedstoneOutputEnabled;
        this.rightRedstoneOutputEnabled = rightRedstoneOutputEnabled;
        this.soundRange = soundRange;
    }

    @Override
    protected void read(PacketBuffer buffer)
    {
        pos = buffer.readBlockPos();
        lockContainer = buffer.readBoolean();
        rearRedstoneInputEnabled = buffer.readBoolean();
        leftRedstoneOutputEnabled = buffer.readBoolean();
        rightRedstoneOutputEnabled = buffer.readBoolean();
        soundRange = buffer.readEnumValue(SoundRange.class);
    }

    @Override
    protected void write(PacketBuffer buffer)
    {
        buffer.writeBlockPos(pos);
        buffer.writeBoolean(lockContainer);
        buffer.writeBoolean(rearRedstoneInputEnabled);
        buffer.writeBoolean(leftRedstoneOutputEnabled);
        buffer.writeBoolean(rightRedstoneOutputEnabled);
        buffer.writeEnumValue(soundRange);
    }

    @Override
    public void process(EntityPlayer player, Side side)
    {
        if(player.world.isBlockLoaded(pos))
        {
            TileEntity tileEntity = player.world.getTileEntity(pos);
            processLockButton(player, tileEntity);
            processRedstoneButtons(tileEntity);
        }
    }

    private void processLockButton(EntityPlayer player, TileEntity tileEntity)
    {
        if(tileEntity instanceof IModLockableContainer)
        {
            IModLockableContainer lockableContainer = (IModLockableContainer) tileEntity;
            OwnerUUID ownerUUID = new OwnerUUID(player.getPersistentID());

            if(lockableContainer.isOwner(ownerUUID))
            {
                if(lockContainer)
                {
                    LockCode lockCode = new LockCode(ownerUUID.toString());
                    lockableContainer.setLockCode(lockCode);
                }
                else
                    lockableContainer.setLockCode(LockCode.EMPTY_CODE);
            }
        }
    }

    private void processRedstoneButtons(TileEntity tileEntity)
    {
        if(tileEntity instanceof TileBandAmp)
        {
            TileBandAmp tileBandAmp = (TileBandAmp) tileEntity;
            tileBandAmp.setRearRedstoneInputEnabled(rearRedstoneInputEnabled);
            tileBandAmp.setLeftRedstoneOutputEnabled(leftRedstoneOutputEnabled);
            tileBandAmp.setRightRedstoneOutputEnabled(rightRedstoneOutputEnabled);
            tileBandAmp.setSoundRange(soundRange);
        }
    }
}<commit_msg>Simple lock code. don't need the UUID String of the owner.<commit_after>/*
 * Aeronica's mxTune MOD
 * Copyright {2016} <NAME> a.k.a. Aeronica
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.aeronica.mods.mxtune.network.server;

import net.aeronica.mods.mxtune.blocks.TileBandAmp;
import net.aeronica.mods.mxtune.network.AbstractMessage;
import net.aeronica.mods.mxtune.sound.SoundRange;
import net.aeronica.mods.mxtune.world.IModLockableContainer;
import net.aeronica.mods.mxtune.world.OwnerUUID;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LockCode;
import net.minecraftforge.fml.relauncher.Side;

public class BandAmpMessage extends AbstractMessage.AbstractServerMessage<BandAmpMessage>
{
    private boolean lockContainer;
    private BlockPos pos;
    private boolean rearRedstoneInputEnabled;
    private boolean leftRedstoneOutputEnabled;
    private boolean rightRedstoneOutputEnabled;
    private SoundRange soundRange;

    @SuppressWarnings("unused")
    public BandAmpMessage() {/* NOP */}

    public BandAmpMessage(BlockPos pos, boolean lockContainer, boolean rearRedstoneInputEnabled, boolean leftRedstoneOutputEnabled, boolean rightRedstoneOutputEnabled, SoundRange soundRange)
    {
        this.pos = pos;
        this.lockContainer = lockContainer;
        this.rearRedstoneInputEnabled = rearRedstoneInputEnabled;
        this.leftRedstoneOutputEnabled = leftRedstoneOutputEnabled;
        this.rightRedstoneOutputEnabled = rightRedstoneOutputEnabled;
        this.soundRange = soundRange;
    }

    @Override
    protected void read(PacketBuffer buffer)
    {
        pos = buffer.readBlockPos();
        lockContainer = buffer.readBoolean();
        rearRedstoneInputEnabled = buffer.readBoolean();
        leftRedstoneOutputEnabled = buffer.readBoolean();
        rightRedstoneOutputEnabled = buffer.readBoolean();
        soundRange = buffer.readEnumValue(SoundRange.class);
    }

    @Override
    protected void write(PacketBuffer buffer)
    {
        buffer.writeBlockPos(pos);
        buffer.writeBoolean(lockContainer);
        buffer.writeBoolean(rearRedstoneInputEnabled);
        buffer.writeBoolean(leftRedstoneOutputEnabled);
        buffer.writeBoolean(rightRedstoneOutputEnabled);
        buffer.writeEnumValue(soundRange);
    }

    @Override
    public void process(EntityPlayer player, Side side)
    {
        if(player.world.isBlockLoaded(pos))
        {
            TileEntity tileEntity = player.world.getTileEntity(pos);
            processLockButton(player, tileEntity);
            processRedstoneButtons(tileEntity);
        }
    }

    private void processLockButton(EntityPlayer player, TileEntity tileEntity)
    {
        if(tileEntity instanceof IModLockableContainer)
        {
            IModLockableContainer lockableContainer = (IModLockableContainer) tileEntity;
            OwnerUUID ownerUUID = new OwnerUUID(player.getPersistentID());

            if(lockableContainer.isOwner(ownerUUID))
            {
                if(lockContainer)
                {
                    LockCode lockCode = new LockCode("Locked by Owner");
                    lockableContainer.setLockCode(lockCode);
                }
                else
                    lockableContainer.setLockCode(LockCode.EMPTY_CODE);
            }
        }
    }

    private void processRedstoneButtons(TileEntity tileEntity)
    {
        if(tileEntity instanceof TileBandAmp)
        {
            TileBandAmp tileBandAmp = (TileBandAmp) tileEntity;
            tileBandAmp.setRearRedstoneInputEnabled(rearRedstoneInputEnabled);
            tileBandAmp.setLeftRedstoneOutputEnabled(leftRedstoneOutputEnabled);
            tileBandAmp.setRightRedstoneOutputEnabled(rightRedstoneOutputEnabled);
            tileBandAmp.setSoundRange(soundRange);
        }
    }
}
{'fraction_non_alphanumeric': 0.07507844016136261, 'fraction_numerical': 0.0017929179740026895, 'mean_word_length': 3.2298578199052135, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327416', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2371, 'n_words': 504}