Search in sources :

Example 1 with ItemBannerRallyGuards

use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by ldtteam.

the class AbstractBuildingGuards method getRallyLocation.

@Override
@Nullable
public ILocation getRallyLocation() {
    if (rallyLocation == null) {
        return null;
    }
    boolean outOfRange = false;
    final IColony colonyAtPosition = IColonyManager.getInstance().getColonyByPosFromDim(rallyLocation.getDimension(), rallyLocation.getInDimensionLocation());
    if (colonyAtPosition == null || colonyAtPosition.getID() != colony.getID()) {
        outOfRange = true;
    }
    if (rallyLocation instanceof EntityLocation) {
        final PlayerEntity player = ((EntityLocation) rallyLocation).getPlayerEntity();
        if (player == null) {
            setRallyLocation(null);
            return null;
        }
        if (outOfRange) {
            LanguageHandler.sendPlayerMessage(player, "item.minecolonies.banner_rally_guards.outofrange");
            setRallyLocation(null);
            return null;
        }
        final int size = player.inventory.getContainerSize();
        for (int i = 0; i < size; i++) {
            final ItemStack stack = player.inventory.getItem(i);
            if (stack.getItem() instanceof ItemBannerRallyGuards) {
                if (((ItemBannerRallyGuards) (stack.getItem())).isActiveForGuardTower(stack, this)) {
                    return rallyLocation;
                }
            }
        }
        // if the user moves the banner around in the inventory.
        return null;
    }
    return rallyLocation;
}
Also used : EntityLocation(com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation) IColony(com.minecolonies.api.colony.IColony) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ItemBannerRallyGuards(com.minecolonies.coremod.items.ItemBannerRallyGuards) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ItemBannerRallyGuards

use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by ldtteam.

the class EventHandler method onPlayerEnterWorld.

/**
 * Event called when a player enters the world.
 *
 * @param event player enter world event
 */
@SubscribeEvent
public static void onPlayerEnterWorld(final PlayerEvent.PlayerLoggedInEvent event) {
    if (event.getPlayer() instanceof ServerPlayerEntity) {
        final ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
        for (final IColony colony : IColonyManager.getInstance().getAllColonies()) {
            if (colony.getPermissions().hasPermission(player, Action.CAN_KEEP_COLONY_ACTIVE_WHILE_AWAY) || colony.getPermissions().hasPermission(player, Action.RECEIVE_MESSAGES_FAR_AWAY)) {
                colony.getPackageManager().addImportantColonyPlayer(player);
            }
        }
        // Add visiting/subscriber to colony we're logging into
        final Chunk chunk = (Chunk) player.level.getChunk(new BlockPos(player.position()));
        final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
        if (cap != null && cap.getOwningColony() != 0) {
            IColony colony = IColonyManager.getInstance().getColonyByDimension(cap.getOwningColony(), player.level.dimension());
            if (colony != null) {
                colony.addVisitingPlayer(player);
                colony.getPackageManager().addCloseSubscriber(player);
            }
        }
        final int size = player.inventory.getContainerSize();
        for (int i = 0; i < size; i++) {
            final ItemStack stack = player.inventory.getItem(i);
            if (stack.getItem() instanceof ItemBannerRallyGuards) {
                ItemBannerRallyGuards.broadcastPlayerToRally(stack, player.getLevel(), player);
            }
        }
        IGlobalResearchTree.getInstance().sendGlobalResearchTreePackets((ServerPlayerEntity) event.getPlayer());
        CustomRecipeManager.getInstance().sendCustomRecipeManagerPackets((ServerPlayerEntity) event.getPlayer());
    }
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) ItemStack(net.minecraft.item.ItemStack) EntryPoint(com.minecolonies.coremod.commands.EntryPoint) ItemBannerRallyGuards(com.minecolonies.coremod.items.ItemBannerRallyGuards) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with ItemBannerRallyGuards

use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by Minecolonies.

the class AbstractBuildingGuards method getRallyLocation.

@Override
@Nullable
public ILocation getRallyLocation() {
    if (rallyLocation == null) {
        return null;
    }
    boolean outOfRange = false;
    final IColony colonyAtPosition = IColonyManager.getInstance().getColonyByPosFromDim(rallyLocation.getDimension(), rallyLocation.getInDimensionLocation());
    if (colonyAtPosition == null || colonyAtPosition.getID() != colony.getID()) {
        outOfRange = true;
    }
    if (rallyLocation instanceof EntityLocation) {
        final PlayerEntity player = ((EntityLocation) rallyLocation).getPlayerEntity();
        if (player == null) {
            setRallyLocation(null);
            return null;
        }
        if (outOfRange) {
            MessageUtils.format(WARNING_RALLYING_POINT_OUT_OF_RANGE).sendTo(player);
            setRallyLocation(null);
            return null;
        }
        final int size = player.inventory.getContainerSize();
        for (int i = 0; i < size; i++) {
            final ItemStack stack = player.inventory.getItem(i);
            if (stack.getItem() instanceof ItemBannerRallyGuards) {
                if (((ItemBannerRallyGuards) (stack.getItem())).isActiveForGuardTower(stack, this)) {
                    return rallyLocation;
                }
            }
        }
        // if the user moves the banner around in the inventory.
        return null;
    }
    return rallyLocation;
}
Also used : EntityLocation(com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation) IColony(com.minecolonies.api.colony.IColony) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ItemBannerRallyGuards(com.minecolonies.coremod.items.ItemBannerRallyGuards) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ItemBannerRallyGuards

use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by Minecolonies.

the class EventHandler method onPlayerEnterWorld.

/**
 * Event called when a player enters the world.
 *
 * @param event player enter world event
 */
@SubscribeEvent
public static void onPlayerEnterWorld(final PlayerEvent.PlayerLoggedInEvent event) {
    if (event.getPlayer() instanceof ServerPlayerEntity) {
        final ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
        for (final IColony colony : IColonyManager.getInstance().getAllColonies()) {
            if (colony.getPermissions().hasPermission(player, Action.CAN_KEEP_COLONY_ACTIVE_WHILE_AWAY) || colony.getPermissions().hasPermission(player, Action.RECEIVE_MESSAGES_FAR_AWAY)) {
                colony.getPackageManager().addImportantColonyPlayer(player);
            }
        }
        // Add visiting/subscriber to colony we're logging into
        final Chunk chunk = (Chunk) player.level.getChunk(new BlockPos(player.position()));
        final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
        if (cap != null && cap.getOwningColony() != 0) {
            IColony colony = IColonyManager.getInstance().getColonyByDimension(cap.getOwningColony(), player.level.dimension());
            if (colony != null) {
                colony.addVisitingPlayer(player);
                colony.getPackageManager().addCloseSubscriber(player);
            }
        }
        final int size = player.inventory.getContainerSize();
        for (int i = 0; i < size; i++) {
            final ItemStack stack = player.inventory.getItem(i);
            if (stack.getItem() instanceof ItemBannerRallyGuards) {
                ItemBannerRallyGuards.broadcastPlayerToRally(stack, player.getLevel(), player);
            }
        }
        IGlobalResearchTree.getInstance().sendGlobalResearchTreePackets((ServerPlayerEntity) event.getPlayer());
        CustomRecipeManager.getInstance().sendCustomRecipeManagerPackets((ServerPlayerEntity) event.getPlayer());
    }
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) ItemStack(net.minecraft.item.ItemStack) EntryPoint(com.minecolonies.coremod.commands.EntryPoint) ItemBannerRallyGuards(com.minecolonies.coremod.items.ItemBannerRallyGuards) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ItemBannerRallyGuards (com.minecolonies.coremod.items.ItemBannerRallyGuards)4 ItemStack (net.minecraft.item.ItemStack)4 IColony (com.minecolonies.api.colony.IColony)2 EntityLocation (com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation)2 EntryPoint (com.minecolonies.coremod.commands.EntryPoint)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 Chunk (net.minecraft.world.chunk.Chunk)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 Nullable (org.jetbrains.annotations.Nullable)2