本文整理汇总了Java中org.spongepowered.api.event.Cancellable类的典型用法代码示例。如果您正苦于以下问题:Java Cancellable类的具体用法?Java Cancellable怎么用?Java Cancellable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cancellable类属于org.spongepowered.api.event包,在下文中一共展示了Cancellable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInternalEvent
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
@Listener
public void onInternalEvent(Event evt) {
InternalScriptEvent event = (InternalScriptEvent) clone();
event.internal = evt;
event.event_type = new TextTag(evt.getClass().getTypeName());
if (evt instanceof Cancellable) {
event.cancelled = ((Cancellable) evt).isCancelled();
}
else {
event.cancelled = false;
}
// TODO: Decipher cause system, allow cause tracking here
/*
Map<String, Object> causes = evt.getCause().getContext().;
event.cause = new MapTag();
for (Map.Entry<String, Object> tc : causes.entrySet()) {
event.cause.getInternal().put(tc.getKey(), new TextTag(tc.getValue().toString()));
}
*/
event.run();
if (evt instanceof Cancellable) {
((Cancellable) evt).setCancelled(event.cancelled);
}
}
示例2: callEventAsync
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
@Override
public <T extends Event> Future<T> callEventAsync(final T event, final UUID target) {
if (event instanceof Returnable || event instanceof Cancellable) {
return pool.submit(new Callable<T>() {
@Override
public T call() throws Exception {
EventPacket packet = new EventPacket(nodeClient.getConnectionInfo().getUuid(), event, target, true);
nodeClient.writePacket(packet);
final BlockingQueue<T> packetBlockingQueue = new SynchronousQueue<T>();
callbackEvents.put(packet.getEventId(), (BlockingQueue<Event>) packetBlockingQueue);
return packetBlockingQueue.take();
}
});
}
else {
return pool.submit(new Callable<T>() {
@Override
public T call() throws Exception {
nodeClient.writePacket(new EventPacket(nodeClient.getConnectionInfo().getUuid(), event, target, false));
return event;
}
});
}
}
示例3: post
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private boolean post(Event event, Collection<RegisteredListener<?>> listeners,
ThrowableConsumer<RegisteredListener, Exception> handler) {
checkNotNull(event, "event");
final CauseStack causeStack = CauseStack.currentOrEmpty();
for (RegisteredListener listener : listeners) {
// Add the calling plugin to the cause stack
causeStack.pushCause(listener.getPlugin());
try (CauseStack.Frame ignored = causeStack.pushCauseFrame()) {
if (event instanceof AbstractEvent) {
((AbstractEvent) event).currentOrder = listener.getOrder();
}
handler.accept(listener);
} catch (Throwable e) {
this.logger.error("Could not pass {} to {}", event.getClass().getSimpleName(),
listener.getPlugin(), e);
}
causeStack.popCause();
}
if (event instanceof AbstractEvent) {
((AbstractEvent) event).currentOrder = null;
}
return event instanceof Cancellable && ((Cancellable) event).isCancelled();
}
示例4: write
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
@Override
public int write(String name, ClassWriter cw, MethodVisitor mv, Method method, int locals) {
if (this.state == Tristate.UNDEFINED) {
return locals;
}
if (!Cancellable.class.isAssignableFrom(method.getParameters()[0].getType())) {
throw new IllegalStateException("Attempted to filter a non-cancellable event type by its cancellation status");
}
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Cancellable.class));
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Cancellable.class), "isCancelled", "()Z", true);
Label success = new Label();
if (this.state == Tristate.TRUE) {
mv.visitJumpInsn(IFNE, success);
} else {
mv.visitJumpInsn(IFEQ, success);
}
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitLabel(success);
return locals;
}
示例5: createFor
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
if (optService.isPresent()) {
PvPService service = optService.get();
if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
return;
}
}
attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in build worlds!"));
event.setCancelled(true);
}
};
}
示例6: createFor
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
if (pactMap.getOrDefault(attacker.getUniqueId(), new ArrayList<>()).contains(defender.getUniqueId())) {
if (hasPactScroll(attacker) && hasPactScroll(defender)) {
event.setCancelled(true);
}
} else if (pactMap.getOrDefault(defender.getUniqueId(), new ArrayList<>()).contains(attacker.getUniqueId())) {
if (hasPactScroll(attacker) && hasPactScroll(defender)) {
event.setCancelled(true);
pactMap.get(defender.getUniqueId()).remove(attacker.getUniqueId());
defender.sendMessage(Text.of(TextColors.DARK_RED, "Your pact with ", attacker.getName(), " has been broken!"));
}
}
}
};
}
示例7: createFor
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
if (optService.isPresent()) {
PvPService service = optService.get();
if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
return;
}
}
attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this area!"));
event.setCancelled(true);
}
};
}
示例8: createFor
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event, JungleRaidInstance inst) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
if (inst.getState() != JungleRaidState.IN_PROGRESS) {
attacker.sendMessage(Text.of(TextColors.RED, "You can't attack players right now!"));
event.setCancelled(true);
return;
}
if (inst.isFriendlyFire(attacker, defender)) {
attacker.sendMessage(Text.of(TextColors.RED, "Don't hit your team mates!"));
event.setCancelled(true);
return;
}
if (event instanceof DamageEntityEvent) {
inst.recordAttack(attacker, defender);
attacker.sendMessage(Text.of(TextColors.YELLOW, "You've hit ", defender.getName(), "!"));
}
}
};
}
示例9: createFor
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event, SkyWarsInstance inst) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
if (inst.getState() != SkyWarsState.IN_PROGRESS) {
attacker.sendMessage(Text.of(TextColors.RED, "You can't attack players right now!"));
event.setCancelled(true);
return;
}
if (inst.isFriendlyFire(attacker, defender)) {
attacker.sendMessage(Text.of(TextColors.RED, "Don't hit your team mates!"));
event.setCancelled(true);
return;
}
if (indirectSource instanceof Snowball && event instanceof CollideEntityEvent.Impact) {
Optional<SkyWarsPlayerData> optData = inst.getPlayerData(defender);
if (optData.isPresent()) {
SkyWarsPlayerData data = optData.get();
data.stopFlight(3000 + (1000 * Probability.getRandom(5)));
data.stopDefrost(15000);
}
} else if (!(event instanceof DamageEntityEvent)) {
return;
}
attacker.sendMessage(Text.of(TextColors.YELLOW, "You've hit ", defender.getName(), "!"));
}
};
}
示例10: checkLoginStatus
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
protected void checkLoginStatus(Cancellable event, Player player) {
if (settings.getGeneral().isBypassPermission() && player.hasPermission(PomData.ARTIFACT_ID + ".bypass")) {
return;
}
if (settings.getGeneral().isCommandOnlyProtection()) {
//check if the user is already registered
if (!plugin.getDatabase().getAccount(player).isPresent()
&& player.hasPermission(PomData.ARTIFACT_ID + ".registerRequired")) {
event.setCancelled(true);
}
} else if (!plugin.getDatabase().isLoggedIn(player)) {
event.setCancelled(true);
}
}
示例11: checkSetting
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public Tristate checkSetting(Cancellable event, Player player, List<Region> regionsAt, Supplier<Permission> perm, Function<RegionConfig.Settings, Tristate> func, Tristate defaultTo)
{
Permission permission = perm.get();
if (player != null && permission != null && player.hasPermission(permission.getId()))
{
event.setCancelled(false);
return Tristate.TRUE;
}
Tristate allow = UNDEFINED;
for (Region region : regionsAt)
{
allow = allow.and(func.apply(region.getSettings()));
if (allow != UNDEFINED)
{
if (allow == FALSE)
{
event.setCancelled(true);
return FALSE;
}
break;
}
}
if (allow == TRUE)
{
event.setCancelled(false);
}
if (allow == UNDEFINED)
{
return defaultTo;
}
return allow;
}
示例12: handleAccess
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public boolean handleAccess(Player user, Location soundLocation, Cancellable event)
{
Boolean keyBookUsed = this.checkForKeyBook(user, soundLocation);
if (this.isOwner(user)) return true;
if (keyBookUsed != null && !keyBookUsed)
{
event.setCancelled(true);
return false;
}
return keyBookUsed != null || this.checkForUnlocked(user) || user.hasPermission(
module.perms().ACCESS_OTHER.getId());
}
示例13: handleEntityInteract
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public void handleEntityInteract(Cancellable event, Player user)
{
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEUTRAL, "This entity is protected by {user}", this.getOwner());
}
if (this.getLockType() == PUBLIC) return;
if (this.handleAccess(user, null, event))
{
this.notifyUsage(user);
return;
}
if (event.isCancelled())
{
return;
}
AccessListModel access = this.getAccess(user);
if (access == null && this.getLockType() == LockType.PRIVATE)
{
event.setCancelled(true); // private & no access
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic from {user} repelled your attempts to reach this entity!", this.getOwner());
}
else
{
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic repelled your attempts to reach this entity!");
}
}
this.notifyUsage(user);
}
示例14: handleBlockBreak
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public void handleBlockBreak(Cancellable event, Player user)
{
if (this.model.getValue(TABLE_LOCKS.OWNER_ID).equals(user.getUniqueId())
|| user.hasPermission(module.perms().BREAK_OTHER.getId()))
{
this.delete(user);
return;
}
event.setCancelled(true);
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic prevents you from breaking this protection!");
}
示例15: handleBlockInteract
import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public void handleBlockInteract(Cancellable event, Player user)
{
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEUTRAL, "This block is protected by {user}", this.getOwner());
}
if (this.getLockType() == PUBLIC) return;
if (this.handleAccess(user, null, event))
{
this.notifyUsage(user);
return;
}
event.setCancelled(true);
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic prevents you from interacting with this block!");
}