Search in sources :

Example 1 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class EventHandler method onPlayerInteract.

/**
     * Event when a player right clicks a block, or right clicks with an item.
     * Event gets cancelled when player has no permission. Event gets cancelled
     * when the player has no permission to place a hut, and tried it.
     *
     * @param event {@link PlayerInteractEvent.RightClickBlock}
     */
@SubscribeEvent
public void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
    final EntityPlayer player = event.getEntityPlayer();
    final World world = event.getWorld();
    //Only execute for the main hand our colony events.
    if (event.getHand() == EnumHand.MAIN_HAND && !(event.getWorld().isRemote)) {
        // and uses that return value, but I didn't want to call it twice
        if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
            final IColony colony = ColonyManager.getIColony(world, event.getPos());
            if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
                event.setCanceled(true);
            }
            return;
        } else if (event.getEntityPlayer() != null && "pmardle".equalsIgnoreCase(event.getEntityPlayer().getName()) && event.getItemStack() != null && Block.getBlockFromItem(event.getItemStack().getItem()) instanceof BlockSilverfish) {
            LanguageHandler.sendPlayerMessage(event.getEntityPlayer(), "Stop that you twat!!!");
            event.setCanceled(true);
        }
        if (player.getHeldItemMainhand() == null || player.getHeldItemMainhand().getItem() == null) {
            return;
        }
        handleEventCancellation(event, player);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) BlockSilverfish(net.minecraft.block.BlockSilverfish) World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class EventHandler method onDebugOverlay.

/**
     * Event when the debug screen is opened. Event gets called by displayed
     * text on the screen, we only need it when f3 is clicked.
     *
     * @param event {@link net.minecraftforge.client.event.RenderGameOverlayEvent.Text}
     */
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onDebugOverlay(final RenderGameOverlayEvent.Text event) {
    if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        final Minecraft mc = Minecraft.getMinecraft();
        if (mc.gameSettings.showDebugInfo) {
            final WorldClient world = mc.world;
            final EntityPlayerSP player = mc.player;
            IColony colony = ColonyManager.getIColony(world, player.getPosition());
            final double minDistance = ColonyManager.getMinimumDistanceBetweenTownHalls();
            if (colony == null) {
                colony = ColonyManager.getClosestIColony(world, player.getPosition());
                if (colony == null || Math.sqrt(colony.getDistanceSquared(player.getPosition())) > 2 * minDistance) {
                    event.getLeft().add(LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.noCloseColony"));
                    return;
                }
                event.getLeft().add(LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.nextColony", (int) Math.sqrt(colony.getDistanceSquared(player.getPosition())), minDistance));
                return;
            }
            event.getLeft().add(colony.getName() + " : " + LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.blocksFromCenter", (int) Math.sqrt(colony.getDistanceSquared(player.getPosition()))));
        }
    }
}
Also used : IColony(com.minecolonies.coremod.colony.IColony) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Minecraft(net.minecraft.client.Minecraft) WorldClient(net.minecraft.client.multiplayer.WorldClient) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class AbstractCitizensCommands method execute.

@NotNull
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    boolean firstArgumentColonyId = true;
    int colonyId = -1;
    if (args.length >= 2) {
        colonyId = getIthArgument(args, 0, -1);
        if (colonyId == -1) {
            firstArgumentColonyId = false;
        }
    }
    final Colony colony;
    if (sender instanceof EntityPlayer && colonyId == -1) {
        final IColony tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
        if (tempColony != null) {
            colonyId = tempColony.getID();
            firstArgumentColonyId = false;
        }
    }
    colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
    if (citizenId == -1 || colony.getCitizen(citizenId) == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    executeSpecializedCode(server, sender, colony, citizenId);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class ShowColonyInfoCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int colonyId;
    colonyId = getIthArgument(args, 0, -1);
    IColony tempColony = ColonyManager.getColony(colonyId);
    if (colonyId == -1 && args.length >= 1) {
        final EntityPlayer player = server.getEntityWorld().getPlayerEntityByName(args[0]);
        if (player != null) {
            tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
        }
    }
    if (sender instanceof EntityPlayer) {
        final UUID mayorID = sender.getCommandSenderEntity().getUniqueID();
        if (tempColony == null) {
            tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
        }
        if (tempColony != null) {
            colonyId = tempColony.getID();
        }
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, SHOWCOLONYINFO, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    if (tempColony == null) {
        if (colonyId == -1 && args.length != 0) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE, args[0])));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE_ID, colonyId)));
        }
        return;
    }
    final Colony colony = ColonyManager.getColony(tempColony.getID());
    if (colony == null) {
        if (colonyId == -1 && args.length != 0) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE, args[0])));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE_ID, colonyId)));
        }
        return;
    }
    final BlockPos position = colony.getCenter();
    sender.sendMessage(new TextComponentString(ID_TEXT + colony.getID() + NAME_TEXT + colony.getName()));
    final String mayor = colony.getPermissions().getOwnerName();
    sender.sendMessage(new TextComponentString(MAYOR_TEXT + mayor));
    sender.sendMessage(new TextComponentString(CITIZENS + colony.getCitizens().size() + "/" + colony.getMaxCitizens()));
    sender.sendMessage(new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
    sender.sendMessage(new TextComponentString(String.format(LAST_CONTACT_TEXT, colony.getLastContactInHours())));
}
Also used : IColony(com.minecolonies.coremod.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class EventHandler method onTownHallPlaced.

static boolean onTownHallPlaced(@NotNull final World world, @NotNull final EntityPlayer player, final BlockPos pos) {
    IColony colony = ColonyManager.getIColonyByOwner(world, player);
    if (colony != null) {
        return canOwnerPlaceTownHallHere(world, player, colony, pos);
    }
    colony = ColonyManager.getClosestIColony(world, pos);
    if (colony == null) {
        return true;
    }
    //  Town Halls must be far enough apart
    return canPlayerPlaceTownHallHere(world, player, pos, colony);
}
Also used : IColony(com.minecolonies.coremod.colony.IColony)

Aggregations

IColony (com.minecolonies.coremod.colony.IColony)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 TextComponentString (net.minecraft.util.text.TextComponentString)9 Colony (com.minecolonies.coremod.colony.Colony)8 NotNull (org.jetbrains.annotations.NotNull)3 UUID (java.util.UUID)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 ArrayList (java.util.ArrayList)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1 Minecraft (net.minecraft.client.Minecraft)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 Style (net.minecraft.util.text.Style)1 ClickEvent (net.minecraft.util.text.event.ClickEvent)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1