Search in sources :

Example 1 with TrustedPlayer

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

the class BlockExpander method clOnBlockActivated.

@Override
protected boolean clOnBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (hand.equals(EnumHand.OFF_HAND))
        return true;
    Expander expander = (Expander) worldIn.getTileEntity(pos);
    if (expander == null) {
        return true;
    }
    TurretBase base = expander.getBase();
    if (base == null) {
        worldIn.destroyBlock(pos, true);
        return true;
    }
    TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(playerIn, base);
    if (trustedPlayer != null) {
        if (base.getTrustedPlayer(playerIn.getUniqueID()).canOpenGUI && state.getValue(META) < 5) {
            playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
            return true;
        }
    }
    if (PlayerUtil.isPlayerOwner(playerIn, base)) {
        if (playerIn.isSneaking() && playerIn.getHeldItemMainhand() == null) {
            worldIn.destroyBlock(pos, true);
        } else if (state.getValue(META) < 5) {
            playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
        } else {
            return true;
        }
    } else {
        addChatMessage(playerIn, new TextComponentString(safeLocalize("status.ownership")));
    }
    return true;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) ItemBlockExpander(omtteam.openmodularturrets.items.blocks.ItemBlockExpander) Expander(omtteam.openmodularturrets.tileentity.Expander) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with TrustedPlayer

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

the class TurretBaseAbstractGui method drawGuiContainerForegroundLayer.

@SuppressWarnings("unchecked")
@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2) {
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
    fontRenderer.drawString(base.getTier() > 1 ? safeLocalize(OMTNames.Localizations.GUI.ADDONS) : "", 71, 6, 0);
    fontRenderer.drawString(base.getTier() > 1 ? safeLocalize(OMTNames.Localizations.GUI.UPGRADES) : "", 71, 39, 0);
    fontRenderer.drawString(safeLocalize(OMTNames.Localizations.GUI.AMMO), 8, 6, 0);
    fontRenderer.drawString(safeLocalize(OMTNames.Localizations.GUI.INVENTORY), 8, ySize - 97 + 4, 0);
    fontRenderer.drawStringWithShadow("" + base.getCurrentMaxRange(), String.valueOf(base.getCurrentMaxRange()).length() == 1 ? 127 : 124, 39, base.getCurrentMaxRange() == getBaseUpperBoundRange() ? 16724530 : 40000);
    fontRenderer.drawString(safeLocalize(OMTNames.Localizations.GUI.RANGE), 116, 6, 0);
    ArrayList targetInfo = new ArrayList();
    targetInfo.add("§6" + safeLocalize(OMLibNames.Localizations.GUI.OWNER) + ": §f" + base.getOwnerName());
    boolean isCurrentlyOn = base.isActive();
    targetInfo.add("§6" + safeLocalize(OMLibNames.Localizations.GUI.ACTIVE) + ": " + (getColoredBooleanLocalizationYesNo(isCurrentlyOn)));
    targetInfo.add("");
    if (base.getTrustedPlayers().size() != 0) {
        targetInfo.add("§5" + safeLocalize(OMTNames.Localizations.GUI.TRUSTED_PLAYERS) + ":");
        for (TrustedPlayer trusted_player : base.getTrustedPlayers()) {
            targetInfo.add("§b" + trusted_player.name);
        }
    } else {
        targetInfo.add("§5" + safeLocalize(OMTNames.Localizations.GUI.TRUSTED_PLAYERS) + ": " + getColoredBooleanLocalizationYesNo(false));
    }
    targetInfo.add("");
    targetInfo.add("§7" + safeLocalize(OMTNames.Localizations.GUI.ATTACK_MOBS) + ": " + getColoredBooleanLocalizationYesNo(base.isAttacksMobs()));
    targetInfo.add("§7" + safeLocalize(OMTNames.Localizations.GUI.ATTACK_NEUTRALS) + ": " + getColoredBooleanLocalizationYesNo(base.isAttacksNeutrals()));
    targetInfo.add("§7" + safeLocalize(OMTNames.Localizations.GUI.ATTACK_PLAYERS) + ": " + getColoredBooleanLocalizationYesNo(base.isAttacksPlayers()));
    this.drawHoveringText(targetInfo, -128, 17, fontRenderer);
    drawTooltips();
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) ArrayList(java.util.ArrayList) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 3 with TrustedPlayer

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

the class TurretBase method addTrustedPlayer.

@Optional.Method(modid = omtteam.omlib.compatability.ModCompatibility.OCModID)
@Callback(doc = "function(name:String, [canOpenGUI:boolean , canChangeTargeting:boolean , " + "admin:boolean]):string; adds Trusted player to Trustlist.")
public Object[] addTrustedPlayer(Context context, Arguments args) {
    if (!computerAccessible) {
        return new Object[] { "Computer access deactivated!" };
    }
    if (!this.addTrustedPlayer(args.checkString(0))) {
        return new Object[] { "Name not valid!" };
    }
    TrustedPlayer trustedPlayer = this.getTrustedPlayer(args.checkString(0));
    trustedPlayer.canOpenGUI = args.optBoolean(1, false);
    trustedPlayer.canChangeTargeting = args.optBoolean(1, false);
    trustedPlayer.admin = args.optBoolean(1, false);
    trustedPlayer.uuid = getPlayerUUID(args.checkString(0));
    return null;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) Callback(li.cil.oc.api.machine.Callback)

Example 4 with TrustedPlayer

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

the class ConfigureGui method actionPerformed.

@SuppressWarnings("deprecation")
@Override
protected void actionPerformed(GuiButton guibutton) {
    TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
    if (guibutton.id == 1) {
        //change Attack Mobs
        if (PlayerUtil.isPlayerOwner(player, base)) {
            sendChangeToServerMobs(!base.isAttacksMobs());
            guibutton.displayString = safeLocalize(OMTNames.Localizations.GUI.ATTACK_MOBS) + ": " + (getColoredBooleanLocalizationYesNo(!base.isAttacksMobs()));
        } else if (trustedPlayer != null && trustedPlayer.canChangeTargeting) {
            sendChangeToServerMobs(!base.isAttacksMobs());
            guibutton.displayString = safeLocalize(OMTNames.Localizations.GUI.ATTACK_MOBS) + ": " + (getColoredBooleanLocalizationYesNo(!base.isAttacksMobs()));
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
    if (guibutton.id == 2) {
        //change Attack Neutrals
        if (PlayerUtil.isPlayerOwner(player, base)) {
            sendChangeToServerNeutrals(!base.isAttacksNeutrals());
            guibutton.displayString = safeLocalize(OMTNames.Localizations.GUI.ATTACK_NEUTRALS) + ": " + (getColoredBooleanLocalizationYesNo(!base.isAttacksNeutrals()));
        } else if (trustedPlayer != null && trustedPlayer.canChangeTargeting) {
            sendChangeToServerNeutrals(!base.isAttacksNeutrals());
            guibutton.displayString = safeLocalize(OMTNames.Localizations.GUI.ATTACK_NEUTRALS) + ": " + (getColoredBooleanLocalizationYesNo(!base.isAttacksNeutrals()));
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
    if (guibutton.id == 3) {
        // change Attack Players
        if (PlayerUtil.isPlayerOwner(player, base)) {
            sendChangeToServerPlayers(!base.isAttacksPlayers());
            guibutton.displayString = safeLocalize(OMTNames.Localizations.GUI.ATTACK_PLAYERS) + ": " + (getColoredBooleanLocalizationYesNo(!base.isAttacksPlayers()));
        } else if (trustedPlayer != null && trustedPlayer.canChangeTargeting) {
            sendChangeToServerPlayers(!base.isAttacksPlayers());
            guibutton.displayString = safeLocalize(OMTNames.Localizations.GUI.ATTACK_PLAYERS) + ": " + (getColoredBooleanLocalizationYesNo(!base.isAttacksPlayers()));
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
    if (guibutton.id == 4) {
        //add trusted player
        if (PlayerUtil.isPlayerOwner(player, base)) {
            if (!textFieldAddTrustedPlayer.getText().equals("") || !textFieldAddTrustedPlayer.getText().isEmpty()) {
                sendChangeToServerAddTrusted();
                textFieldAddTrustedPlayer.setText("");
                waitForServerTrustedPlayers = 20;
            }
        } else if (trustedPlayer != null && trustedPlayer.admin) {
            if (!textFieldAddTrustedPlayer.getText().equals("") || !textFieldAddTrustedPlayer.getText().isEmpty()) {
                sendChangeToServerAddTrusted();
                textFieldAddTrustedPlayer.setText("");
                waitForServerTrustedPlayers = 20;
            }
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
    if (guibutton.id == 5) {
        if (this.base.getTrustedPlayers().size() <= base.trustedPlayerIndex) {
            return;
        }
        if (base.getTrustedPlayers().size() > 0) {
            if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null && player.getUniqueID().toString().equals(base.getOwner())) {
                sendChangeToServerRemoveTrusted();
                base.removeTrustedPlayer(base.getTrustedPlayers().get(base.trustedPlayerIndex).getName());
                textFieldAddTrustedPlayer.setText("");
                this.base.trustedPlayerIndex = 0;
                player.openGui(OpenModularTurrets.instance, 6, player.getEntityWorld(), base.getPos().getX(), base.getPos().getY(), base.getPos().getZ());
            } else if (base.getTrustedPlayer(player.getUniqueID()).admin) {
                if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null && this.base.getTrustedPlayers().size() > 0) {
                    sendChangeToServerRemoveTrusted();
                    base.removeTrustedPlayer(base.getTrustedPlayers().get(base.trustedPlayerIndex).getName());
                    textFieldAddTrustedPlayer.setText("");
                    this.base.trustedPlayerIndex = 0;
                    if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex).uuid.equals(player.getUniqueID()) && !player.getUniqueID().toString().equals(base.getOwner())) {
                        mc.displayGuiScreen(null);
                        return;
                    }
                    player.openGui(OpenModularTurrets.instance, 6, player.getEntityWorld(), base.getPos().getX(), base.getPos().getY(), base.getPos().getZ());
                }
            } else {
                addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
            }
        }
    }
    if (guibutton.id == 6) {
        //decrease index of trusted player list
        if ((this.base.trustedPlayerIndex - 1 >= 0)) {
            this.base.trustedPlayerIndex--;
            player.openGui(OpenModularTurrets.instance, 6, player.getEntityWorld(), base.getPos().getX(), base.getPos().getY(), base.getPos().getZ());
        }
    }
    if (guibutton.id == 7) {
        //increase index of trusted player list
        if (!((this.base.trustedPlayerIndex + 1) > (base.getTrustedPlayers().size() - 1))) {
            this.base.trustedPlayerIndex++;
            player.openGui(OpenModularTurrets.instance, 6, player.getEntityWorld(), base.getPos().getX(), base.getPos().getY(), base.getPos().getZ());
        }
    }
    if (this.base.getTrustedPlayers().size() <= base.trustedPlayerIndex) {
        return;
    }
    if (guibutton.id == 8) {
        //change trusted player permission for GUI opening
        if (PlayerUtil.isPlayerOwner(player, base) && this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null) {
            sendChangeToServerModifyPermissions(this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(), "gui", !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI);
            guibutton.displayString = !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI ? "§2Y" : "§cN";
        } else if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null && trustedPlayer != null && trustedPlayer.admin) {
            sendChangeToServerModifyPermissions(this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(), "gui", !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI);
            guibutton.displayString = !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI ? "§2Y" : "§cN";
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
    if (guibutton.id == 9) {
        if (this.base.getTrustedPlayers().size() <= base.trustedPlayerIndex) {
            return;
        }
        if (PlayerUtil.isPlayerOwner(player, base) && this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null) {
            sendChangeToServerModifyPermissions(this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(), "targeting", !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting);
            guibutton.displayString = !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting ? "§2Y" : "§cN";
        } else if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null && trustedPlayer != null && trustedPlayer.admin) {
            sendChangeToServerModifyPermissions(this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(), "targeting", !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting);
            guibutton.displayString = !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting ? "§2Y" : "§cN";
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
    if (guibutton.id == 10) {
        if (this.base.getTrustedPlayers().size() <= base.trustedPlayerIndex) {
            return;
        }
        if (PlayerUtil.isPlayerOwner(player, base) && this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null) {
            sendChangeToServerModifyPermissions(this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(), "isAdmin", !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin);
            guibutton.displayString = !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin ? "§2Y" : "§cN";
        } else if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null && trustedPlayer != null && trustedPlayer.admin) {
            sendChangeToServerModifyPermissions(this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(), "isAdmin", !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin);
            guibutton.displayString = !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin ? "§2Y" : "§cN";
        } else {
            addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
        }
    }
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with TrustedPlayer

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

the class TurretBaseAbstractGui method initGui.

@Override
@SuppressWarnings("unchecked")
public void initGui() {
    super.initGui();
    int x = (width - xSize) / 2;
    int y = (height - ySize) / 2;
    TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
    this.buttonList.add(new GuiButton(1, x + 120, y + 15, 20, 20, "+"));
    this.buttonList.add(new GuiButton(2, x + 120, y + 50, 20, 20, "-"));
    if (PlayerUtil.isPlayerOwner(player, base)) {
        this.buttonList.add(new GuiButton(3, x + 180, y, 80, 20, "Drop Turrets"));
        this.buttonList.add(new GuiButton(4, x + 180, y + 25, 80, 20, "Drop Base"));
        this.buttonList.add(new GuiButton(5, x + 180, y + 50, 80, 20, "Configure"));
        this.buttonList.add(new GuiButton(6, x + 180, y + 75, 80, 20, base.isMultiTargeting() ? safeLocalize(OMTNames.Localizations.GUI.TARGET) + ": " + safeLocalize(OMTNames.Localizations.GUI.MULTI) : safeLocalize(OMTNames.Localizations.GUI.TARGET) + ": " + safeLocalize(OMTNames.Localizations.GUI.SINGLE)));
    } else if (trustedPlayer != null) {
        if (trustedPlayer.admin) {
            this.buttonList.add(new GuiButton(3, x + 180, y, 80, 20, "Drop Turrets"));
            this.buttonList.add(new GuiButton(4, x + 180, y + 25, 80, 20, "Drop Base"));
        }
        if (trustedPlayer.canChangeTargeting || trustedPlayer.admin) {
            this.buttonList.add(new GuiButton(5, x + 180, y + 50, 80, 20, "Configure"));
            this.buttonList.add(new GuiButton(6, x + 180, y + 75, 80, 20, base.isMultiTargeting() ? safeLocalize(OMTNames.Localizations.GUI.TARGET) + ": " + safeLocalize(OMTNames.Localizations.GUI.MULTI) : safeLocalize(OMTNames.Localizations.GUI.TARGET) + ": " + safeLocalize(OMTNames.Localizations.GUI.SINGLE)));
        }
    }
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) GuiButton(net.minecraft.client.gui.GuiButton)

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