本文整理汇总了Java中org.bukkit.event.Cancellable类的典型用法代码示例。如果您正苦于以下问题:Java Cancellable类的具体用法?Java Cancellable怎么用?Java Cancellable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cancellable类属于org.bukkit.event包,在下文中一共展示了Cancellable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processQuery
import org.bukkit.event.Cancellable; //导入依赖的package包/类
/**
* Query the rule's filter with the given objects.
* If the query is denied, cancel the event and set the deny message.
* If the query is allowed, un-cancel the event.
* If the query abstains, do nothing.
* @return false if the query abstained, otherwise true
*/
protected static boolean processQuery(Event event, EventRule rule, IQuery query) {
if(rule.filter() == null) {
return false;
}
switch(rule.filter().query(query)) {
case ALLOW:
if(event instanceof Cancellable) {
((Cancellable) event).setCancelled(false);
}
return true;
case DENY:
if(event instanceof GeneralizingEvent) {
((GeneralizingEvent) event).setCancelled(true, rule.message());
} else if(event instanceof Cancellable) {
((Cancellable) event).setCancelled(true);
}
return true;
default:
return false;
}
}
示例2: forbidIfInProtectedTerritory
import org.bukkit.event.Cancellable; //导入依赖的package包/类
private void forbidIfInProtectedTerritory(Player breaker, Block destroyed, Cancellable event, boolean destroy) {
if (breaker == null) {
return;
}
if (FPermission.hasPermission(breaker, FPermission.BUILD)) {
return;
}
Region region = board.getByChunk(destroyed.getChunk());
if (region == null || region.isNeutral()) {
if (wildernessProtected) {
event.setCancelled(true);
ParsingUtil.sendMessage(breaker, (destroy ? FMessage.PROTECTION_CANNOT_DESTROY_WILDERNESS : FMessage.PROTECTION_CANNOT_BUILD_WILDERNESS).getMessage());
}
return;
}
Faction bFaction = factions.getByMember(breaker);
Faction owner = region.getOwner();
Relation rel = owner.getRelation(bFaction);
if (!rel.canBuild()) {
event.setCancelled(true);
ParsingUtil.sendMessage(breaker, (destroy ? FMessage.PROTECTION_CANNOT_DESTROY_FACTION : FMessage.PROTECTION_CANNOT_BUILD_FACTION).getMessage(), region.getOwner());
}
}
示例3: fire
import org.bukkit.event.Cancellable; //导入依赖的package包/类
/**
* Fire this event.
*/
public void fire() {
if (getVanilla() == null || getVanilla().getType() == Material.AIR || getWrapper() instanceof GenericItem)
return;
if (getEvent() instanceof Cancellable) // Cancel events by default.
((Cancellable) getEvent()).setCancelled(true);
try {
for (Method m : ReflectionUtil.getMethods(getWrapper().getClass(), getClass())) {
ItemListener l = m.getAnnotation(ItemListener.class);
if (l != null && (l.value() == null || Arrays.asList(l.value().getUsages()).contains(getUsage())))
m.invoke(getWrapper(), this);
}
handle();
} catch (Exception e) {
e.printStackTrace();
Core.warn("Error using " + player.getName() + "'s " + getWrapper().getClass().getSimpleName() + "!");
getPlayer().sendMessage(ChatColor.RED + "There was an error while using this item.");
}
}
示例4: handle
import org.bukkit.event.Cancellable; //导入依赖的package包/类
public void handle(String msg, CommandSender sender, Cancellable event) {
if (Config.get().hiddenMode && !sender.hasPermission("camerastudio.use") && !sender.isOp()) return;
if (msg.startsWith("/cam") || msg.startsWith("/camerastudio")) {
event.setCancelled(true);
List<String> args = Lists.newArrayList(msg.split(" "));
if (args.size() > 1) {
args.remove(0);
}
Traveller traveller = null;
if (sender instanceof ConsoleCommandSender) {
traveller = new BukkitTraveller(null);
} else {
Player player = (Player) sender;
traveller = Travellers.impl().get(player.getUniqueId());
}
CmdCam.get().preExec(traveller, args);
}
}
示例5: handleCommand
import org.bukkit.event.Cancellable; //导入依赖的package包/类
private void handleCommand(CommandSender sender, String s, Cancellable event) {
if (s.isEmpty()) {
return;
}
if (this.plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
return;
}
if (s.charAt(0) == '/') {
s = s.substring(1);
}
if (s.startsWith("minecraft:")) {
s = s.substring("minecraft:".length());
}
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
event.setCancelled(true);
sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
}
}
示例6: init
import org.bukkit.event.Cancellable; //导入依赖的package包/类
@SuppressWarnings("null")
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
if (isDelayed == Kleenean.TRUE) {
Skript.error("Can't cancel an event anymore after is has already passed", ErrorQuality.SEMANTIC_ERROR);
return false;
}
cancel = matchedPattern == 0;
final Class<? extends Event>[] es = ScriptLoader.getCurrentEvents();
if (es == null)
return false;
for (final Class<? extends Event> e : es) {
if (Cancellable.class.isAssignableFrom(e) || BlockCanBuildEvent.class.isAssignableFrom(e))
return true; // TODO warning if some event(s) cannot be cancelled even though some can (needs a way to be suppressed)
}
if (ScriptLoader.isCurrentEvent(PlayerLoginEvent.class))
Skript.error("A connect event cannot be cancelled, but the player may be kicked ('kick player by reason of \"...\"')", ErrorQuality.SEMANTIC_ERROR);
else
Skript.error(Utils.A(ScriptLoader.getCurrentEventName()) + " event cannot be cancelled", ErrorQuality.SEMANTIC_ERROR);
return false;
}
示例7: post
import org.bukkit.event.Cancellable; //导入依赖的package包/类
private boolean post(Event cause, Block block, BlockState oldState,
BlockState newState, Player bukkit, boolean cancel) {
ArcadePlayer player = null;
if (bukkit != null) {
player = this.plugin.getPlayer(bukkit);
}
BlockTransformEvent event = new BlockTransformEvent(
this.plugin, block, cause, newState, oldState, player);
this.plugin.getEventBus().publish(event);
boolean canceled = cancel && event.isCanceled() &&
cause instanceof Cancellable;
if (canceled) {
((Cancellable) cause).setCancelled(true);
}
return event.isCanceled();
}
示例8: updatePearlHolder
import org.bukkit.event.Cancellable; //导入依赖的package包/类
/**
* Updates the pearl holder
* @param pearl The pearl to update
* @param holder The pearl holder
* @param event The event
*/
private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) {
if (holder instanceof Chest) {
updatePearl(pearl, (Chest)holder);
} else if (holder instanceof DoubleChest) {
updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide());
} else if (holder instanceof Furnace) {
updatePearl(pearl, (Furnace) holder);
} else if (holder instanceof Dispenser) {
updatePearl(pearl, (Dispenser) holder);
} else if (holder instanceof Dropper) {
updatePearl(pearl, (Dropper) holder);
} else if (holder instanceof Hopper) {
updatePearl(pearl, (Hopper) holder);
} else if (holder instanceof BrewingStand) {
updatePearl(pearl, (BrewingStand) holder);
} else if (holder instanceof Player) {
updatePearl(pearl, (Player) holder);
}else {
event.setCancelled(true);
}
}
示例9: check
import org.bukkit.event.Cancellable; //导入依赖的package包/类
public boolean check(Event e) {
if (!(e instanceof Cancellable)) {
return false;
}
if (((Cancellable) e).isCancelled()) {
if (boo == true) {
return true;
} else {
return false;
}
} else {
if (boo == false) {
return true;
} else {
return false;
}
}
}
示例10: canEdit
import org.bukkit.event.Cancellable; //导入依赖的package包/类
boolean canEdit(Player player, ArmorStand as){
ignoreNextInteract = true;
ArrayList<Event> events = new ArrayList<Event>();
events.add(new PlayerInteractEntityEvent(player, as, EquipmentSlot.HAND));
events.add(new PlayerInteractAtEntityEvent(player, as, as.getLocation().toVector(), EquipmentSlot.HAND));
//events.add(new PlayerArmorStandManipulateEvent(player, as, player.getEquipment().getItemInMainHand(), as.getItemInHand(), EquipmentSlot.HAND));
for(Event event : events){
if(!(event instanceof Cancellable)) continue;
try{
plugin.getServer().getPluginManager().callEvent(event);
} catch(IllegalStateException ise){
ise.printStackTrace();
ignoreNextInteract = false;
return false; //Something went wrong, don't allow edit just in case
}
if(((Cancellable)event).isCancelled()){
ignoreNextInteract = false;
return false;
}
}
ignoreNextInteract = false;
return true;
}
示例11: checkLimits
import org.bukkit.event.Cancellable; //导入依赖的package包/类
private void checkLimits(Cancellable event, EntityType entityType, Location location) {
if (entityType == null) {
return; // Only happens on "other-plugins", i.e. EchoPet
}
String islandName = WorldGuardHandler.getIslandNameAt(location);
if (islandName == null) {
event.setCancelled(true); // Only allow spawning on active islands...
return;
}
if (entityType.getEntityClass().isAssignableFrom(Ghast.class) && location.getWorld().getEnvironment() != World.Environment.NETHER) {
// Disallow ghasts for now...
event.setCancelled(true);
return;
}
us.talabrek.ultimateskyblock.api.IslandInfo islandInfo = plugin.getIslandInfo(islandName);
if (islandInfo == null) {
// Disallow spawns on inactive islands
event.setCancelled(true);
return;
}
if (!plugin.getLimitLogic().canSpawn(entityType, islandInfo)) {
event.setCancelled(true);
}
}
示例12: runCommand
import org.bukkit.event.Cancellable; //导入依赖的package包/类
public static void runCommand(CommandSender sender, String command) {
if (CraftoAPI.instance() != null && CraftoAPI.instance().getServiceManager().getService(CommandService.class).isAvailable()) {
CommandService cmdService = CommandService.instance().get();
if (cmdService.processCompletely(sender, command)) {
return;
}
}
if (CraftoPlugin.instance() != null && CraftoPlugin.instance().getCommands() != null) {
CraftoCommands commands = CraftoPlugin.instance().getCommands();
Cancellable cancellable = new SimpleCancellable();
commands.handleCommandEvent(sender, command, cancellable);
if (!cancellable.isCancelled()) { // Command wasnt handled by craftocommands, so it has to be a bukkit command
Bukkit.getServer().dispatchCommand(sender, command);
}
}
else { Bukkit.getServer().dispatchCommand(sender, command); }
}
示例13: cancelBowSpleefEntityEvent
import org.bukkit.event.Cancellable; //导入依赖的package包/类
private void cancelBowSpleefEntityEvent(Entity entity, Cancellable cancellable) {
boolean isBowspleefEntity = false;
List<MetadataValue> metadatas = entity.getMetadata(BOWSPLEEF_METADATA_KEY);
for (MetadataValue value : metadatas) {
if (value.getOwningPlugin() != getHeavySpleef().getPlugin()) {
continue;
}
isBowspleefEntity = value.asBoolean();
}
if (isBowspleefEntity) {
entity.remove();
cancellable.setCancelled(true);
}
}
示例14: masterBroken
import org.bukkit.event.Cancellable; //导入依赖的package包/类
public MessageWithStatus masterBroken(Cancellable event, Sign sign, Player player) {
BankSet bank = bankManager.getBank(sign.getBlock().getLocation());
if (bank == null) return null;
if (!bank.getOwner().equals(player.getName())) {
if (can_override_break.check(player)) {
return new BasicMessage("break override allowed", Status.INFO);
} else {
event.setCancelled(true);
return new BasicMessage(Status.WARNING, "Cannot destroy a MondoChest which does not belong to you");
}
}
// If we're here, actually delete the bank
int num_slaves = bank.numChests();
bankManager.removeBank(sign.getWorld().getName(), bank);
playerManager.getState(player).setLastClickedMaster(null);
return new BasicMessage(Status.SUCCESS,
"removed bank and %d slave%s",
num_slaves,
pluralize(num_slaves)
);
}
示例15: slaveBroken
import org.bukkit.event.Cancellable; //导入依赖的package包/类
public MessageWithStatus slaveBroken(Cancellable event, Sign sign, Player player) {
Map<ChestManager, BankSet> slaves = bankManager.getWorldSlaves(sign.getWorld().getName());
int removed = 0;
for (Chest chest: slaveFinder().nearbyChests(sign)) {
ChestManager info = new ChestManager(chest, false);
if (slaves.containsKey(info)) {
BankSet bs = slaves.get(info);
if (bs.getAccess(player).canRemoveChests() || can_override_break.check(player)) {
if (bs.removeChest(chest)) {
bankManager.markChanged(bs);
}
removed++;
} else {
event.setCancelled(true);
return new BasicMessage(Status.WARNING, "No access to remove this slave sign");
}
}
}
return new BasicMessage(Status.SUCCESS, "Removed %d chests", removed);
}