use of org.bukkit.event.Listener in project MagicPlugin by elBukkit.
the class Mage method onPlayerQuit.
public void onPlayerQuit(PlayerEvent event) {
Player player = getPlayer();
if (player == null || player != event.getPlayer()) {
return;
}
// Must allow listeners to remove themselves during the event!
List<Listener> active = new ArrayList<>(quitListeners);
for (Listener listener : active) {
callEvent(listener, event);
}
}
use of org.bukkit.event.Listener in project MassiveCore by MassiveCraft.
the class EventUtil method callEventAfter.
public static void callEventAfter(Event event, Listener listener, EventPriority priority) {
HandlerList handlers = event.getHandlers();
RegisteredListener[] listeners = handlers.getRegisteredListeners().clone();
boolean run = false;
for (RegisteredListener registration : listeners) {
if (run) {
fireEventRegistration(event, registration);
} else {
try {
EventPriority thisPriority = (EventPriority) fieldRegisteredListenerDotPriority.get(registration);
Listener thisListener = (Listener) fieldRegisteredListenerDotListener.get(registration);
if (thisListener == listener && thisPriority == priority)
run = true;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of org.bukkit.event.Listener in project Skills by StarTux.
the class BukkitSkillsPlugin method onEnable.
@Override
public void onEnable() {
// Files
writeDefaultFiles(false);
reloadConfig();
// Economy
if (!setupEconomy()) {
getLogger().warning("Economy setup failed. Disabling skills.");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Database
db = new SQLDatabase(this);
for (Class<?> clazz : SQLDB.getDatabaseClasses()) db.registerTable(clazz);
if (!db.createAllTables()) {
getLogger().warning("Database setup failed. Disabling skills.");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Skills
skills.configure();
for (BukkitSkill skill : skills.getSkills()) {
if (skill instanceof Listener) {
getServer().getPluginManager().registerEvents((Listener) skill, this);
} else {
getLogger().warning("Not an Event Listener: " + skill.getDisplayName());
}
}
// Double check skills
for (BukkitSkillType type : BukkitSkillType.values()) {
BukkitSkill skill = skills.getSkillMap().get(type);
if (skill == null) {
getLogger().warning("Missing skill: " + type.name());
} else {
skill.configureSkill();
skill.onEnable();
}
}
// Commands
getCommand("skillsadmin").setExecutor(adminCommand);
getCommand("skills").setExecutor(skillsCommand);
getCommand("highscore").setExecutor(highscoreCommand);
// Events
getServer().getPluginManager().registerEvents(this, this);
// Tasks
new BukkitRunnable() {
@Override
public void run() {
saveSome();
updateAllPlayers();
}
}.runTaskTimer(this, 20, 20);
//
skills.buildNameMap();
}
use of org.bukkit.event.Listener in project Essentials by EssentialsX.
the class Essentials method handleCrash.
private void handleCrash(Throwable exception) {
final PluginManager pm = getServer().getPluginManager();
LOGGER.log(Level.SEVERE, exception.toString());
exception.printStackTrace();
pm.registerEvents(new Listener() {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event) {
event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
}
}, this);
for (Player player : getOnlinePlayers()) {
player.sendMessage("Essentials failed to load, read the log file.");
}
this.setEnabled(false);
}
use of org.bukkit.event.Listener in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractPhase method enable.
@Override
public void enable() {
if (!checkDependencies()) {
game.abortGame();
return;
}
if (!checkVictoryConditionDependencies()) {
game.abortGame();
return;
}
if (victoryConditions.size() == 0) {
addVictoryCondition(getGame().createVictoryCondition(EmptyVictoryCondition.class, this));
}
// enable timer
startTime = LocalDateTime.now();
log.finer("enable phase" + getName());
phaseTickables.values().forEach(Tickable::enable);
for (Feature feature : features) {
if (game.isAborting()) {
return;
}
log.finer("enable " + feature.getName());
try {
feature.enable();
} catch (Exception ex) {
log.severe("error while starting " + feature.getName());
ex.printStackTrace();
game.abortGame();
return;
}
if (feature instanceof Listener) {
eventHandler.registerEvents((Listener) feature, getGame());
}
if (feature instanceof FeatureCommandImplementor) {
AbstractFeatureCommand cmd = injector.getInstance(((FeatureCommandImplementor) feature).getCommandClass());
// noinspection unchecked
cmd.setFeature(feature);
commandHandler.register(cmd, this);
}
startedFeatures.add(feature);
}
for (VictoryCondition victoryCondition : victoryConditions) {
if (victoryCondition instanceof Listener) {
eventHandler.registerEvents((Listener) victoryCondition, getGame());
}
}
}
Aggregations