use of org.bukkit.event.Event in project Conquer by xXAndrew28Xx.
the class LFEventForwarder method onFactionsChange.
@EventHandler
public void onFactionsChange(EventFactionsChange event) {
Event forwardEvent;
if (event.getFactionNew().isWilderness()) {
forwardEvent = new ConquerFactionLeaveEvent(LFFaction.get(plugin, event.getFactionOld()), LFPlayer.get(plugin, event.getFPlayer()));
} else {
forwardEvent = new ConquerFactionJoinEvent(LFFaction.get(plugin, event.getFactionNew()), LFPlayer.get(plugin, event.getFPlayer()));
}
callEvent(forwardEvent);
if (((Cancellable) forwardEvent).isCancelled()) {
event.setCancelled(true);
}
}
use of org.bukkit.event.Event in project Conquer by xXAndrew28Xx.
the class CondWarpPassValid method check.
@Override
public boolean check(Event e) {
String password = this.password.getSingle(e);
ConquerFaction faction = this.faction.getSingle(e);
return password != null && faction != null && names.check(e, warp -> faction.isWarpPassword(warp, password), isNegated());
}
use of org.bukkit.event.Event in project AuthMeReloaded by AuthMe.
the class PasswordSecurityTest method setUpMocks.
@BeforeInjecting
public void setUpMocks() {
caughtClassInEvent = null;
// When the password encryption event is emitted, replace the encryption method with our mock.
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
if (arguments[0] instanceof PasswordEncryptionEvent) {
PasswordEncryptionEvent event = (PasswordEncryptionEvent) arguments[0];
caughtClassInEvent = event.getMethod() == null ? null : event.getMethod().getClass();
event.setMethod(method);
}
return null;
}
}).when(pluginManager).callEvent(any(Event.class));
given(settings.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
given(settings.getProperty(SecuritySettings.LEGACY_HASHES)).willReturn(Collections.emptySet());
given(settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND)).willReturn(8);
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme.security.crypts").create();
injector.register(Settings.class, settings);
given(hashAlgorithmFactory.newInstance(any(Class.class))).willAnswer(invocation -> {
Object o = injector.createIfHasDependencies(invocation.getArgument(0));
if (o == null) {
throw new IllegalArgumentException("Cannot create object of class '" + invocation.getArgument(0) + "': missing class that needs to be provided?");
}
return o;
});
}
use of org.bukkit.event.Event in project Glowstone by GlowstoneMC.
the class GlowFishingHookTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
eventsFired.removeAll(PlayerFishEvent.class);
when(world.getBlockAt(any(Location.class))).thenReturn(block);
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
when(block.getType()).thenReturn(Material.WATER);
fishingRewardManager = new FishingRewardManager();
when(server.getFishingRewardManager()).thenReturn(fishingRewardManager);
when(player.getLocation()).thenReturn(location);
when(eventFactory.callEvent(any(Event.class))).thenAnswer(invocation -> {
Event e = invocation.getArgument(0);
eventsFired.put(e.getClass(), e);
return e;
});
when(eventFactory.onEntityDamage(any(EntityDamageEvent.class))).thenAnswer(returnsFirstArg());
}
use of org.bukkit.event.Event in project Bukkit by Bukkit.
the class JavaPluginLoader method createRegisteredListeners.
public Map<Class<? extends Event>, Set<RegisteredListener>> createRegisteredListeners(Listener listener, final Plugin plugin) {
Validate.notNull(plugin, "Plugin can not be null");
Validate.notNull(listener, "Listener can not be null");
boolean useTimings = server.getPluginManager().useTimings();
Map<Class<? extends Event>, Set<RegisteredListener>> ret = new HashMap<Class<? extends Event>, Set<RegisteredListener>>();
Set<Method> methods;
try {
Method[] publicMethods = listener.getClass().getMethods();
methods = new HashSet<Method>(publicMethods.length, Float.MAX_VALUE);
for (Method method : publicMethods) {
methods.add(method);
}
for (Method method : listener.getClass().getDeclaredMethods()) {
methods.add(method);
}
} catch (NoClassDefFoundError e) {
plugin.getLogger().severe("Plugin " + plugin.getDescription().getFullName() + " has failed to register events for " + listener.getClass() + " because " + e.getMessage() + " does not exist.");
return ret;
}
for (final Method method : methods) {
final EventHandler eh = method.getAnnotation(EventHandler.class);
if (eh == null)
continue;
final Class<?> checkClass;
if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(checkClass = method.getParameterTypes()[0])) {
plugin.getLogger().severe(plugin.getDescription().getFullName() + " attempted to register an invalid EventHandler method signature \"" + method.toGenericString() + "\" in " + listener.getClass());
continue;
}
final Class<? extends Event> eventClass = checkClass.asSubclass(Event.class);
method.setAccessible(true);
Set<RegisteredListener> eventSet = ret.get(eventClass);
if (eventSet == null) {
eventSet = new HashSet<RegisteredListener>();
ret.put(eventClass, eventSet);
}
for (Class<?> clazz = eventClass; Event.class.isAssignableFrom(clazz); clazz = clazz.getSuperclass()) {
// This loop checks for extending deprecated events
if (clazz.getAnnotation(Deprecated.class) != null) {
Warning warning = clazz.getAnnotation(Warning.class);
WarningState warningState = server.getWarningState();
if (!warningState.printFor(warning)) {
break;
}
plugin.getLogger().log(Level.WARNING, String.format("\"%s\" has registered a listener for %s on method \"%s\", but the event is Deprecated." + " \"%s\"; please notify the authors %s.", plugin.getDescription().getFullName(), clazz.getName(), method.toGenericString(), (warning != null && warning.reason().length() != 0) ? warning.reason() : "Server performance will be affected", Arrays.toString(plugin.getDescription().getAuthors().toArray())), warningState == WarningState.ON ? new AuthorNagException(null) : null);
break;
}
}
EventExecutor executor = new EventExecutor() {
public void execute(Listener listener, Event event) throws EventException {
try {
if (!eventClass.isAssignableFrom(event.getClass())) {
return;
}
method.invoke(listener, event);
} catch (InvocationTargetException ex) {
throw new EventException(ex.getCause());
} catch (Throwable t) {
throw new EventException(t);
}
}
};
if (useTimings) {
eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
} else {
eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
}
}
return ret;
}
Aggregations