本文整理汇总了Java中org.spongepowered.api.event.Event类的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Event类属于org.spongepowered.api.event包,在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInternalEvent
import org.spongepowered.api.event.Event; //导入依赖的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: getEventClass
import org.spongepowered.api.event.Event; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T extends Event> Class<T> getEventClass(EventListener<? super T> listener) {
Class<? extends EventListener> listenerClass = listener.getClass();
// We can't just do this:
// Method handleMethod = listenerClass.getMethod(EVENT_LISTENER_HANDLE_METHOD_NAME, Event.class);
// so we do this:
Method[] methods = listenerClass.getMethods();
List<Method> handleMethods = Arrays.asList(methods).stream()
.filter(m -> !m.getDeclaringClass().equals(EventListener.class))
.filter(m -> m.getName().equals(EVENT_LISTENER_HANDLE_METHOD_NAME))
.collect(Collectors.toList());
if (handleMethods.size() == 2) {
if (handleMethods.get(0).getParameterTypes()[0].equals(Event.class)) {
return (Class<T>) handleMethods.get(1).getParameterTypes()[0];
} else {
return (Class<T>) handleMethods.get(0).getParameterTypes()[0];
}
} if (handleMethods.size() == 1) {
return (Class<T>) handleMethods.get(0).getParameterTypes()[0];
} else if (handleMethods.size() > 2) {
throw new IllegalStateException("Finding best matching Event not yet implemented: " + handleMethods);
} else {
throw new IllegalArgumentException("Failed to obtain 'handle' Method from listener: " + listener);
}
}
示例3: processEvent
import org.spongepowered.api.event.Event; //导入依赖的package包/类
public void processEvent(Event event, Player player, String key, int increment) {
final UUID uuid = player.getUniqueId();
BadgeUpEvent newEvent = new BadgeUpEvent(key, uuid, new Modifier(ModifierOperation.INC, increment));
for (Method m : event.getClass().getMethods()) {
final String methodName = m.getName();
if (methodName.startsWith("get")) {
m.setAccessible(true);
// To catch weird stuff such as getting entity snapshots from
// DropItemEvent after Order.PRE, which can't be done
try {
Object result = m.invoke(event, (Object[]) null);
// Substring to index 3 to remove "get"
newEvent.addDataEntry(methodName.substring(3), result);
} catch (Exception e) {
continue;
}
}
}
send(newEvent);
}
示例4: callEventAsync
import org.spongepowered.api.event.Event; //导入依赖的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;
}
});
}
}
示例5: postPacket
import org.spongepowered.api.event.Event; //导入依赖的package包/类
public void postPacket(EventPacket packet) {
if (packet.getSender().equals(nodeClient.getConnectionInfo().getUuid())) {
try {
callbackEvents.get(packet.getEventId()).put(packet.getEvent().get());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else {
Event event = packet.getEvent().get();
logger.debug(event.toString());
eventManager.post(event);
if (packet.isReturnable())
nodeClient.writePacket(packet);
}
}
示例6: post
import org.spongepowered.api.event.Event; //导入依赖的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();
}
示例7: write
import org.spongepowered.api.event.Event; //导入依赖的package包/类
@Override
public Tuple<Integer, Integer> write(ClassWriter cw, MethodVisitor mv, Method method, Parameter param, int local) {
// Get the cause
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Event.class), "getCause",
"()" + Type.getDescriptor(Cause.class), true);
Class<?> targetType = param.getType();
insertCauseCall(mv, param, targetType);
int paramLocal = local++;
mv.visitVarInsn(ASTORE, paramLocal);
insertTransform(mv, param, targetType, paramLocal);
return new Tuple<>(local, paramLocal);
}
示例8: generateDynamicListener
import org.spongepowered.api.event.Event; //导入依赖的package包/类
public Object generateDynamicListener(Map<StaticClass, Set<Consumer<? extends Event>>> map) {
Object o = null;
try {
byte[] b = generateDynamicListenerbc(map);
o = loadClass("cz.neumimto.rpg.listeners.DynamicListener", b);
Class<?> listener = Class.forName("cz.neumimto.rpg.listeners.DynamicListener");
o = listener.newInstance();
for (Field field : listener.getDeclaredFields()) {
if (Set.class.isAssignableFrom(field.getType())) {
Set s = (Set) field.get(o);
ParameterizedType paramtype = (ParameterizedType) field.getGenericType();
ParameterizedType type = (ParameterizedType) paramtype.getActualTypeArguments()[0];
Class<? extends Event> event = (Class<? extends Event>) type.getActualTypeArguments()[0];
map.entrySet().stream()
.filter(m -> m.getKey().getRepresentedClass() == event)
.forEach(a -> s.addAll(a.getValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
示例9: getHandlerList
import org.spongepowered.api.event.Event; //导入依赖的package包/类
private static HandlerList getHandlerList(Class<?> pore) {
Class<?> superClass = pore;
do {
superClass = superClass.getSuperclass();
if (!Modifier.isAbstract(superClass.getModifiers())
&& superClass.getName().startsWith("org.bukkit.event")) {
break;
}
} while (superClass != null);
if (superClass == null) {
throw new IllegalStateException("Not a Bukkit handle event " + pore);
}
Class<? extends org.bukkit.event.Event> handle = superClass.asSubclass(org.bukkit.event.Event.class);
return SimplePluginManager.getEventListeners(handle);
}
示例10: create
import org.spongepowered.api.event.Event; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static <P extends org.bukkit.event.Event & PoreEvent<S>, S extends Event> EventConstructor<P, S> create(
Class<P> pore, Predicate<S> matcher) {
for (Constructor<?> c : pore.getConstructors()) {
int len = c.getParameterCount();
if (len == 0 || len > 2) {
continue;
}
Parameter[] parameters = c.getParameters();
Class<S> sponge = (Class<S>) parameters[0].getType();
if (!Event.class.isAssignableFrom(sponge)) {
continue;
}
if (len == 1) {
return new Simple<>(pore, sponge, matcher);
} else if (parameters[1].getAnnotation(blue.lapis.pore.event.Source.class) != null) {
return new Source<>(pore, sponge, matcher, parameters[1].getType());
}
}
throw new IllegalArgumentException("No supported constructor found in " + pore);
}
示例11: fail
import org.spongepowered.api.event.Event; //导入依赖的package包/类
boolean fail(Player player, Event event, Action action, Cause cause) {
this.cancelled = action.fail(player, event);
User user = User.get(player);
SequenceFailEvent failEvent = new SequenceFailEvent(user, this, event, cause);
Sponge.getEventManager().post(failEvent);
return false;
}
示例12: fail
import org.spongepowered.api.event.Event; //导入依赖的package包/类
public boolean fail(Player player, Event event) {
// true if should cancel
return this.failureListeners.stream()
.filter(callback -> callback.test(player, event))
.findFirst()
.isPresent();
}
示例13: printEvent
import org.spongepowered.api.event.Event; //导入依赖的package包/类
public static void printEvent(Event event) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream out = new PrintStream(os);
out.println();
out.println(event.getClass().getSimpleName());
printEventByType(out, event);
out.println(" Caused by");
for (Entry<String, Object> e : event.getCause().getNamedCauses().entrySet()) {
out.println(" " + e.getKey() + ": " + prettyCauseObj(e.getValue()));
}
out.println();
System.out.println(new String(os.toByteArray(), Charsets.UTF_8));
}
示例14: printEventByType
import org.spongepowered.api.event.Event; //导入依赖的package包/类
private static void printEventByType(PrintStream out, Event event) {
if (event instanceof ChangeBlockEvent) {
printChangeBlock(out, (ChangeBlockEvent) event);
} else if (event instanceof InteractBlockEvent) {
printInteractBlock(out, (InteractBlockEvent) event);
} else if (event instanceof NotifyNeighborBlockEvent) {
printNotifyEvent(out, (NotifyNeighborBlockEvent) event);
} else if (event instanceof InteractInventoryEvent) {
printInteractInventory(out, (InteractInventoryEvent) event);
} else {
out.println(event.toString());
}
}
示例15: damageEntity
import org.spongepowered.api.event.Event; //导入依赖的package包/类
@Listener(order = Order.POST)
public void damageEntity(Event event, @Root EntityDamageSource cause)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (!(cause.getSource() instanceof Player)) {
return;
}
processEvent(event, (Player) cause.getSource());
}