Search in sources :

Example 36 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class CommandSpaceStationChangeOwner method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    String oldOwner = null;
    String newOwner = "ERROR";
    int stationID = -1;
    EntityPlayerMP playerAdmin = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
    if (args.length > 1) {
        newOwner = args[1];
        try {
            stationID = Integer.parseInt(args[0]);
        } catch (final Exception var6) {
            throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getUsage(sender)), new Object[0]);
        }
        if (stationID < 2) {
            throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getUsage(sender)), new Object[0]);
        }
        try {
            SpaceStationWorldData stationData = SpaceStationWorldData.getMPSpaceStationData(null, stationID, null);
            if (stationData == null) {
                throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getUsage(sender)), new Object[0]);
            }
            oldOwner = stationData.getOwner();
            stationData.getAllowedPlayers().remove(oldOwner);
            if (stationData.getSpaceStationName().equals("Station: " + oldOwner)) {
                stationData.setSpaceStationName("Station: " + newOwner);
            }
            stationData.getAllowedPlayers().add(newOwner);
            stationData.setOwner(newOwner);
            final EntityPlayerMP oldPlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(oldOwner, true);
            final EntityPlayerMP newPlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(newOwner, true);
            if (oldPlayer != null) {
                GCPlayerStats stats = GCPlayerStats.get(oldPlayer);
                SpaceStationWorldData.updateSSOwnership(oldPlayer, oldOwner, stats, stationID, stationData);
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(oldPlayer.world), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), oldPlayer);
            }
            if (newPlayer != null) {
                GCPlayerStats stats = GCPlayerStats.get(newPlayer);
                SpaceStationWorldData.updateSSOwnership(newPlayer, newOwner.replace(".", ""), stats, stationID, stationData);
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(oldPlayer.world), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), newPlayer);
            }
        } catch (final Exception var6) {
            throw new CommandException(var6.getMessage(), new Object[0]);
        }
    } else {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
    }
    if (playerAdmin != null) {
        playerAdmin.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner)));
    } else // Console
    {
        System.out.println(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner));
    }
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 37 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class CommandSpaceStationRemoveOwner method getPlayers.

protected String[] getPlayers(MinecraftServer server, ICommandSender sender) {
    EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), false);
    if (playerBase != null) {
        GCPlayerStats stats = GCPlayerStats.get(playerBase);
        if (!stats.getSpaceStationDimensionData().isEmpty()) {
            String[] allNames = server.getOnlinePlayerNames();
            // data.getAllowedPlayers may include some in lowercase
            // Convert to correct case at least for those players who are online
            HashSet<String> allowedNames = Sets.newHashSet();
            for (Map.Entry<Integer, Integer> e : stats.getSpaceStationDimensionData().entrySet()) {
                final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.world, e.getValue(), playerBase);
                allowedNames.addAll(data.getAllowedPlayers());
            }
            Iterator<String> itName = allowedNames.iterator();
            ArrayList<String> replaceNames = new ArrayList<String>();
            while (itName.hasNext()) {
                String name = itName.next();
                for (String allEntry : allNames) {
                    if (name.equalsIgnoreCase(allEntry)) {
                        itName.remove();
                        replaceNames.add(allEntry);
                    }
                }
            }
            // This does the conversion to correct case
            allowedNames.addAll(replaceNames);
            String[] rvsize = new String[allowedNames.size()];
            return allowedNames.toArray(rvsize);
        }
    }
    String[] returnvalue = { "" };
    return returnvalue;
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 38 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class CommandSpaceStationRemoveOwner method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    String var3 = null;
    EntityPlayerMP playerBase = null;
    if (args.length > 0) {
        var3 = args[0];
        try {
            playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), false);
            if (playerBase != null) {
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                if (stats.getSpaceStationDimensionData().isEmpty()) {
                    throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
                } else {
                    for (Map.Entry<Integer, Integer> e : stats.getSpaceStationDimensionData().entrySet()) {
                        final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.world, e.getValue(), playerBase);
                        String str = null;
                        for (String name : data.getAllowedPlayers()) {
                            if (name.equalsIgnoreCase(var3)) {
                                str = name;
                                break;
                            }
                        }
                        if (str != null) {
                            data.getAllowedPlayers().remove(str);
                            data.markDirty();
                        } else {
                            throw new CommandException(GCCoreUtil.translateWithFormat("commands.ssuninvite.no_player", "\"" + var3 + "\""), new Object[0]);
                        }
                    }
                }
            }
        } catch (final Exception var6) {
            throw new CommandException(var6.getMessage(), new Object[0]);
        }
    } else {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
    }
    if (playerBase != null) {
        playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.removesuccess", var3)));
    }
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 39 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class CommandGCAstroMiner method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length > 2) {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
    }
    if (args.length < 1) {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
    }
    int type = 0;
    int newvalue = 0;
    if (args[0].equalsIgnoreCase("show")) {
        type = 1;
    } else if (args[0].equalsIgnoreCase("reset")) {
        type = 2;
    } else if (args[0].length() > 3 && args[0].substring(0, 3).equalsIgnoreCase("set")) {
        String number = args[0].substring(3);
        try {
            newvalue = Integer.parseInt(number);
            if (newvalue > 0) {
                type = 3;
            }
        } catch (NumberFormatException ex) {
        }
    }
    // Proceed if syntax of show|reset|set<number> was correct
    if (type > 0) {
        EntityPlayerMP playerBase = null;
        try {
            if (args.length == 2) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
            } else {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
            }
            if (playerBase != null) {
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                switch(type) {
                    case 1:
                        sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + stats.getAstroMinerCount())));
                        break;
                    case 2:
                        stats.setAstroMinerCount(0);
                        sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + 0)));
                        break;
                    case 3:
                        stats.setAstroMinerCount(newvalue);
                        sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + newvalue)));
                        break;
                }
            } else {
                throw new Exception("Could not find player with name: " + args[1]);
            }
        } catch (final Exception e) {
            throw new CommandException(e.getMessage(), new Object[0]);
        }
        return;
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 40 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class OxygenUtil method hasValidOxygenSetup.

public static boolean hasValidOxygenSetup(EntityPlayerMP player) {
    boolean missingComponent = false;
    GCPlayerStats stats = GCPlayerStats.get(player);
    if (!OxygenUtil.isItemValidForPlayerTankInv(0, stats.getExtendedInventory().getStackInSlot(0))) {
        boolean handled = false;
        for (final ItemStack armorStack : player.inventory.armorInventory) {
            if (!armorStack.isEmpty() && armorStack.getItem() instanceof IBreathableArmor) {
                final IBreathableArmor breathableArmor = (IBreathableArmor) armorStack.getItem();
                if (breathableArmor.handleGearType(EnumGearType.HELMET)) {
                    if (breathableArmor.canBreathe(armorStack, player, EnumGearType.HELMET)) {
                        handled = true;
                    }
                }
            }
        }
        if (!handled) {
            missingComponent = true;
        }
    }
    if (!OxygenUtil.isItemValidForPlayerTankInv(1, stats.getExtendedInventory().getStackInSlot(1))) {
        boolean handled = false;
        for (final ItemStack armorStack : player.inventory.armorInventory) {
            if (!armorStack.isEmpty() && armorStack.getItem() instanceof IBreathableArmor) {
                final IBreathableArmor breathableArmor = (IBreathableArmor) armorStack.getItem();
                if (breathableArmor.handleGearType(EnumGearType.GEAR)) {
                    if (breathableArmor.canBreathe(armorStack, player, EnumGearType.GEAR)) {
                        handled = true;
                    }
                }
            }
        }
        if (!handled) {
            missingComponent = true;
        }
    }
    if (!OxygenUtil.isItemValidForPlayerTankInv(2, stats.getExtendedInventory().getStackInSlot(2)) && !OxygenUtil.isItemValidForPlayerTankInv(3, stats.getExtendedInventory().getStackInSlot(3))) {
        boolean handled = false;
        for (final ItemStack armorStack : player.inventory.armorInventory) {
            if (!armorStack.isEmpty() && armorStack.getItem() instanceof IBreathableArmor) {
                final IBreathableArmor breathableArmor = (IBreathableArmor) armorStack.getItem();
                if (breathableArmor.handleGearType(EnumGearType.TANK1)) {
                    if (breathableArmor.canBreathe(armorStack, player, EnumGearType.TANK1)) {
                        handled = true;
                    }
                }
                if (breathableArmor.handleGearType(EnumGearType.TANK2)) {
                    if (breathableArmor.canBreathe(armorStack, player, EnumGearType.TANK2)) {
                        handled = true;
                    }
                }
            }
        }
        if (!handled) {
            missingComponent = true;
        }
    }
    return !missingComponent;
}
Also used : IBreathableArmor(micdoodle8.mods.galacticraft.api.item.IBreathableArmor) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) ItemStack(net.minecraft.item.ItemStack)

Aggregations

GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)88 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)55 ItemStack (net.minecraft.item.ItemStack)43 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)19 CommandException (net.minecraft.command.CommandException)16 WrongUsageException (net.minecraft.command.WrongUsageException)16 TextComponentString (net.minecraft.util.text.TextComponentString)16 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)14 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)12 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)12 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)12 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)10 TileEntity (net.minecraft.tileentity.TileEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 WorldServer (net.minecraft.world.WorldServer)10 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)8 Entity (net.minecraft.entity.Entity)7 PotionEffect (net.minecraft.potion.PotionEffect)7 ChatComponentText (net.minecraft.util.ChatComponentText)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6