Search in sources :

Example 1 with PlotFlagAddEvent

use of com.plotsquared.core.events.PlotFlagAddEvent in project PlotSquared by IntellectualSites.

the class EventDispatcher method callFlagAdd.

public PlotFlagAddEvent callFlagAdd(PlotFlag<?, ?> flag, Plot plot) {
    PlotFlagAddEvent event = new PlotFlagAddEvent(flag, plot);
    callEvent(event);
    return event;
}
Also used : PlotFlagAddEvent(com.plotsquared.core.events.PlotFlagAddEvent)

Example 2 with PlotFlagAddEvent

use of com.plotsquared.core.events.PlotFlagAddEvent in project PlotSquared by IntellectualSites.

the class Desc method set.

@Override
public boolean set(PlotPlayer<?> player, Plot plot, String desc) {
    if (desc.isEmpty()) {
        PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plot.getFlagContainer().getFlag(DescriptionFlag.class), plot);
        if (event.getEventResult() == Result.DENY) {
            player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Description removal"));
            return false;
        }
        plot.removeFlag(event.getFlag());
        player.sendMessage(TranslatableCaption.of("desc.desc_unset"));
        return true;
    }
    PlotFlagAddEvent event = this.eventDispatcher.callFlagAdd(plot.getFlagContainer().getFlag(DescriptionFlag.class).createFlagInstance(desc), plot);
    if (event.getEventResult() == Result.DENY) {
        player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Description set"));
        return false;
    }
    boolean result = plot.setFlag(event.getFlag());
    if (!result) {
        player.sendMessage(TranslatableCaption.of("flag.flag_not_added"));
        return false;
    }
    player.sendMessage(TranslatableCaption.of("desc.desc_set"));
    return true;
}
Also used : DescriptionFlag(com.plotsquared.core.plot.flag.implementations.DescriptionFlag) PlotFlagAddEvent(com.plotsquared.core.events.PlotFlagAddEvent) PlotFlagRemoveEvent(com.plotsquared.core.events.PlotFlagRemoveEvent)

Example 3 with PlotFlagAddEvent

use of com.plotsquared.core.events.PlotFlagAddEvent in project PlotSquared by IntellectualSites.

the class Done method finish.

private void finish(Plot plot, PlotPlayer<?> player, boolean success) {
    if (!success) {
        player.sendMessage(TranslatableCaption.of("done.done_insufficient_complexity"));
        return;
    }
    long flagValue = System.currentTimeMillis() / 1000;
    PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class).createFlagInstance(Long.toString(flagValue));
    PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
    if (event.getEventResult() == Result.DENY) {
        player.sendMessage(TranslatableCaption.of("events.event_denied"));
        return;
    }
    plot.setFlag(plotFlag);
    player.sendMessage(TranslatableCaption.of("done.done_success"));
}
Also used : DoneFlag(com.plotsquared.core.plot.flag.implementations.DoneFlag) PlotFlagAddEvent(com.plotsquared.core.events.PlotFlagAddEvent)

Example 4 with PlotFlagAddEvent

use of com.plotsquared.core.events.PlotFlagAddEvent in project PlotSquared by IntellectualSites.

the class Music method onCommand.

@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
    Location location = player.getLocation();
    final Plot plot = location.getPlotAbs();
    if (plot == null) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
        return false;
    }
    if (!plot.hasOwner()) {
        player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
        return false;
    }
    if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_MUSIC_OTHER)) {
        player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_MUSIC_OTHER)));
        return true;
    }
    PlotInventory inv = new PlotInventory(this.inventoryUtil, player, 2, TranslatableCaption.of("plotjukebox.jukebox_header").getComponent(player)) {

        @Override
        public boolean onClick(int index) {
            PlotItemStack item = getItem(index);
            if (item == null) {
                return true;
            }
            if (item.getType() == ItemTypes.BEDROCK) {
                PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class).createFlagInstance(item.getType());
                PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(plotFlag, plot);
                if (event.getEventResult() == Result.DENY) {
                    getPlayer().sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Music removal"));
                    return true;
                }
                plot.removeFlag(event.getFlag());
                getPlayer().sendMessage(TranslatableCaption.of("flag.flag_removed"), Template.of("flag", "music"), Template.of("value", "music_disc"));
            } else if (item.getName().toLowerCase(Locale.ENGLISH).contains("disc")) {
                PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class).createFlagInstance(item.getType());
                PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
                if (event.getEventResult() == Result.DENY) {
                    getPlayer().sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Music addition"));
                    return true;
                }
                plot.setFlag(event.getFlag());
                getPlayer().sendMessage(TranslatableCaption.of("flag.flag_added"), Template.of("flag", "music"), Template.of("value", String.valueOf(event.getFlag().getValue())));
            } else {
                getPlayer().sendMessage(TranslatableCaption.of("flag.flag_not_added"));
            }
            return false;
        }
    };
    int index = 0;
    for (final String disc : DISCS) {
        final String name = String.format("<gold>%s</gold>", disc);
        final String[] lore = { TranslatableCaption.of("plotjukebox.click_to_play").getComponent(player) };
        ItemType type = ItemTypes.get(disc);
        if (type == null) {
            continue;
        }
        final PlotItemStack item = new PlotItemStack(type, 1, name, lore);
        if (inv.setItemChecked(index, item)) {
            index++;
        }
    }
    // Always add the cancel button
    // if (player.getMeta("music") != null) {
    String name = TranslatableCaption.of("plotjukebox.cancel_music").getComponent(player);
    String[] lore = { TranslatableCaption.of("plotjukebox.reset_music").getComponent(player) };
    inv.setItem(index, new PlotItemStack("bedrock", 1, name, lore));
    // }
    inv.openInventory();
    return true;
}
Also used : PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) Plot(com.plotsquared.core.plot.Plot) ItemType(com.sk89q.worldedit.world.item.ItemType) PlotItemStack(com.plotsquared.core.plot.PlotItemStack) PlotInventory(com.plotsquared.core.plot.PlotInventory) PlotFlagAddEvent(com.plotsquared.core.events.PlotFlagAddEvent) PlotFlagRemoveEvent(com.plotsquared.core.events.PlotFlagRemoveEvent) MusicFlag(com.plotsquared.core.plot.flag.implementations.MusicFlag) Location(com.plotsquared.core.location.Location)

Aggregations

PlotFlagAddEvent (com.plotsquared.core.events.PlotFlagAddEvent)4 PlotFlagRemoveEvent (com.plotsquared.core.events.PlotFlagRemoveEvent)2 Location (com.plotsquared.core.location.Location)1 Plot (com.plotsquared.core.plot.Plot)1 PlotInventory (com.plotsquared.core.plot.PlotInventory)1 PlotItemStack (com.plotsquared.core.plot.PlotItemStack)1 PlotFlag (com.plotsquared.core.plot.flag.PlotFlag)1 DescriptionFlag (com.plotsquared.core.plot.flag.implementations.DescriptionFlag)1 DoneFlag (com.plotsquared.core.plot.flag.implementations.DoneFlag)1 MusicFlag (com.plotsquared.core.plot.flag.implementations.MusicFlag)1 ItemType (com.sk89q.worldedit.world.item.ItemType)1