Search in sources :

Example 1 with PermissionEvent

use of com.minecolonies.api.colony.permissions.PermissionEvent in project minecolonies by ldtteam.

the class ColonyPermissionEventHandler method cancelEvent.

/**
 * Cancel an event and record the denial details in the colony's town hall.
 *
 * @param event  the event to cancel
 * @param entity the player whose action was denied
 * @param colony the colony where the event took place
 * @param action the action which was denied
 * @param pos    the location of the action which was denied
 */
private void cancelEvent(final Event event, @Nullable final Entity entity, final Colony colony, final Action action, final BlockPos pos) {
    event.setResult(Event.Result.DENY);
    if (event.isCancelable()) {
        event.setCanceled(true);
        if (entity == null) {
            if (colony.hasTownHall()) {
                colony.getBuildingManager().getTownHall().addPermissionEvent(new PermissionEvent(null, "-", action, pos));
            }
            return;
        }
        if (colony.hasTownHall()) {
            colony.getBuildingManager().getTownHall().addPermissionEvent(new PermissionEvent(entity.getUUID(), entity.getName().getString(), action, pos));
        }
        if (entity instanceof FakePlayer) {
            return;
        }
        final long worldTime = entity.level.getGameTime();
        if (!lastPlayerNotificationTick.containsKey(entity.getUUID()) || lastPlayerNotificationTick.get(entity.getUUID()) + (Constants.TICKS_SECOND * MineColonies.getConfig().getServer().secondsBetweenPermissionMessages.get()) < worldTime) {
            LanguageHandler.sendPlayerMessage((PlayerEntity) entity, "com.minecolonies.coremod.permission.no");
            lastPlayerNotificationTick.put(entity.getUUID(), worldTime);
        }
    }
}
Also used : PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 2 with PermissionEvent

use of com.minecolonies.api.colony.permissions.PermissionEvent in project minecolonies by Minecolonies.

the class ColonyPermissionEventHandler method cancelEvent.

/**
 * Cancel an event and record the denial details in the colony's town hall.
 *
 * @param event  the event to cancel
 * @param entity the player whose action was denied
 * @param colony the colony where the event took place
 * @param action the action which was denied
 * @param pos    the location of the action which was denied
 */
private void cancelEvent(final Event event, @Nullable final Entity entity, final Colony colony, final Action action, final BlockPos pos) {
    event.setResult(Event.Result.DENY);
    if (event.isCancelable()) {
        event.setCanceled(true);
        if (entity == null) {
            if (colony.hasTownHall()) {
                colony.getBuildingManager().getTownHall().addPermissionEvent(new PermissionEvent(null, "-", action, pos));
            }
            return;
        }
        if (colony.hasTownHall()) {
            colony.getBuildingManager().getTownHall().addPermissionEvent(new PermissionEvent(entity.getUUID(), entity.getName().getString(), action, pos));
        }
        if (entity instanceof FakePlayer) {
            return;
        }
        final long worldTime = entity.level.getGameTime();
        if (!lastPlayerNotificationTick.containsKey(entity.getUUID()) || lastPlayerNotificationTick.get(entity.getUUID()) + (Constants.TICKS_SECOND * MineColonies.getConfig().getServer().secondsBetweenPermissionMessages.get()) < worldTime) {
            MessageUtils.format(PERMISSION_DENIED).sendTo((PlayerEntity) entity);
            lastPlayerNotificationTick.put(entity.getUUID(), worldTime);
        }
    }
}
Also used : PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 3 with PermissionEvent

use of com.minecolonies.api.colony.permissions.PermissionEvent in project minecolonies by Minecolonies.

the class WindowInfoPage method addPlayerToColonyClicked.

/**
 * Action performed when remove player button is clicked.
 *
 * @param button Button that holds the user clicked on.
 */
private void addPlayerToColonyClicked(@NotNull final Button button) {
    final int row = eventList.getListElementIndexByPane(button);
    if (row >= 0 && row < building.getPermissionEvents().size()) {
        final PermissionEvent user = building.getPermissionEvents().get(row);
        Network.getNetwork().sendToServer(new PermissionsMessage.AddPlayerOrFakePlayer(building.getColony(), user.getName(), user.getId()));
    }
}
Also used : PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) PermissionsMessage(com.minecolonies.coremod.network.messages.PermissionsMessage)

Example 4 with PermissionEvent

use of com.minecolonies.api.colony.permissions.PermissionEvent in project minecolonies by Minecolonies.

the class WindowInfoPage method fillEventsList.

private void fillEventsList() {
    eventList = findPaneOfTypeByID(EVENTS_LIST, ScrollingList.class);
    eventList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return permissionEvents ? building.getPermissionEvents().size() : building.getColonyEvents().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final Text nameLabel = rowPane.findPaneOfTypeByID(NAME_LABEL, Text.class);
            final Text actionLabel = rowPane.findPaneOfTypeByID(ACTION_LABEL, Text.class);
            if (permissionEvents) {
                final List<PermissionEvent> permissionEvents = building.getPermissionEvents();
                Collections.reverse(permissionEvents);
                final PermissionEvent event = permissionEvents.get(index);
                nameLabel.setText(event.getName() + (event.getId() == null ? " <fake>" : ""));
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getPosition().getX() + " " + event.getPosition().getY() + " " + event.getPosition().getZ());
                if (event.getId() == null) {
                    rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
                }
                actionLabel.setText(new TranslationTextComponent(KEY_TO_PERMISSIONS + event.getAction().toString().toLowerCase(Locale.US)));
            } else {
                final List<IColonyEventDescription> colonyEvents = building.getColonyEvents();
                Collections.reverse(colonyEvents);
                final IColonyEventDescription event = colonyEvents.get(index);
                if (event instanceof CitizenDiedEvent) {
                    actionLabel.setText(((CitizenDiedEvent) event).getDeathCause());
                } else {
                    actionLabel.setText(event.getName());
                }
                if (event instanceof ICitizenEventDescription) {
                    nameLabel.setText(((ICitizenEventDescription) event).getCitizenName());
                } else if (event instanceof IBuildingEventDescription) {
                    IBuildingEventDescription buildEvent = (IBuildingEventDescription) event;
                    nameLabel.setText(MessageUtils.format(buildEvent.getBuildingName()).append(" " + buildEvent.getLevel()).create());
                }
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getEventPos().getX() + " " + event.getEventPos().getY() + " " + event.getEventPos().getZ());
                rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
            }
        }
    });
}
Also used : IBuildingEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription) Text(com.ldtteam.blockout.controls.Text) Pane(com.ldtteam.blockout.Pane) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent) ICitizenEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 5 with PermissionEvent

use of com.minecolonies.api.colony.permissions.PermissionEvent in project minecolonies by Minecolonies.

the class BuildingTownHall method serializeToView.

@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
    super.serializeToView(buf);
    buf.writeBoolean(MineColonies.getConfig().getServer().canPlayerUseAllyTHTeleport.get());
    buf.writeInt(permissionEvents.size());
    for (final PermissionEvent event : permissionEvents) {
        event.serialize(buf);
    }
    List<IColonyEventDescription> colonyEvents = colony.getEventDescriptionManager().getEventDescriptions();
    buf.writeInt(colonyEvents.size());
    for (final IColonyEventDescription event : colonyEvents) {
        buf.writeUtf(event.getEventTypeId().getPath());
        event.serialize(buf);
    }
}
Also used : IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent)

Aggregations

PermissionEvent (com.minecolonies.api.colony.permissions.PermissionEvent)6 IColonyEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription)3 FakePlayer (net.minecraftforge.common.util.FakePlayer)2 Pane (com.ldtteam.blockout.Pane)1 Text (com.ldtteam.blockout.controls.Text)1 ScrollingList (com.ldtteam.blockout.views.ScrollingList)1 IBuildingEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription)1 ICitizenEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription)1 CitizenDiedEvent (com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent)1 PermissionsMessage (com.minecolonies.coremod.network.messages.PermissionsMessage)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1