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;
}
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;
}
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"));
}
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;
}
Aggregations