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;
}
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();
}
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;
}
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")));
}
}
}
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)));
}
}
}
Aggregations