use of com.voxelgameslib.voxelgameslib.internal.timings.Timing in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoxelGamesLib method onEnable.
@Override
public void onEnable() {
try {
// logging first, only changes prefixes anyways
loggingHandler = new LoggingHandler();
loggingHandler.setErrorHandler(errorHandler);
loggingHandler.enable();
// enable by enabling external stuff. they don't require any VGL stuff
// timings
timingManager = TimingManager.of(this);
// commands
commandManager = new BukkitCommandManager(this);
commandManager.setDefaultExceptionHandler((scope, registeredCommand, sender, args, t) -> {
errorHandler.handle(sender, args, t);
return false;
});
// living on the edge!
commandManager.enableUnstableAPI("help");
// task chain
taskChainFactory = BukkitTaskChainFactory.create(this);
taskChainFactory.setDefaultErrorHandler((e, t) -> {
log.severe("Task " + t.hashCode() + " generated an exception:");
e.printStackTrace();
});
// chat menu api
ChatMenuAPI.init(this);
// menu builder (excuse the hack, but we want to shade you)
MenuBuilderPlugin menuBuilderPluginFake = new ObjenesisStd().getInstantiatorOf(MenuBuilderPlugin.class).newInstance();
menuBuilderPluginFake.inventoryListener = new InventoryListener(menuBuilderPluginFake);
MenuBuilderPlugin.instance = menuBuilderPluginFake;
Bukkit.getPluginManager().registerEvents(menuBuilderPluginFake.inventoryListener, this);
// guice
VoxelGamesLibModule module = new VoxelGamesLibModule(this, loggingHandler, timingManager, commandManager, getVersion(), getDataFolder(), ModuleHandler.getOfferedModules(), errorHandler);
injector = module.createInjector();
injector.injectMembers(this);
// startup handler
startupHandler.registerService("onEnable");
Bukkit.getPluginManager().registerEvents(injector.getInstance(StartupListener.class), this);
// then enable all VGL stuff
try (final Timing timing = new Timing("EnableAllHandlers")) {
eventHandler.enable();
configHandler.enable();
persistenceHandler.enable();
langHandler.enable();
tickHandler.enable();
chatHandler.enable();
userHandler.enable();
roleHandler.enable();
mapHandler.enable();
worldHandler.enable();
teamHandler.enable();
eloHandler.enable();
matchmakingHandler.enable();
signHandler.enable();
metricHandler.enable();
pointHandler.enable();
kitHandler.enable();
commandHandler.enable();
textureHandler.enable();
statsHandler.enable();
gameHandler.enable();
}
registerListeners();
} catch (Exception ex) {
errorHandler.handle(ex, Severity.ERROR, true);
startupHandler.interrupt();
return;
}
// register commands
registerCommandContexts();
registerCommandReplacements();
registerCommands();
registerCommandCompletions();
moduleHandler.enable();
gameHandler.startDefaultGame();
getServer().getPluginManager().callEvent(new VoxelGamesLibEnableEvent());
testStuff.test();
startupHandler.unregisterService("onEnable");
enabledCleanly = true;
}
use of com.voxelgameslib.voxelgameslib.internal.timings.Timing in project VoxelGamesLibv2 by VoxelGamesLib.
the class MetricHandler method enable.
@Override
public void enable() {
try (Timing timing = new Timing("MetricsEnable")) {
metrics = new Metrics(voxelGamesLib);
// TODO add custom charts, like user/gamemode, installed gamesmodes, user/lang, installed langs etc
// gamemodes multiline TODO enable this on the bstats page once its implemented....
metrics.addCustomChart(new Metrics.MultiLineChart("gamemodes", () -> {
Map<String, Integer> valueMap = new HashMap<>();
gameHandler.getGameModes().forEach((gm) -> valueMap.put(gm.getName(), 1));
return valueMap;
}));
} catch (Throwable ex) {
log.warning("Metrics failed to enabled. This is not a critical problem. You can ignore it.");
}
}
use of com.voxelgameslib.voxelgameslib.internal.timings.Timing in project VoxelGamesLibv2 by VoxelGamesLib.
the class ModuleHandler method findModules.
private void findModules() {
try (final Timing timing = new Timing("RegisterModules")) {
isAcceptingOffers = false;
for (Class<? extends Module> clazz : offeredModules.keySet()) {
ModuleInfo info = clazz.getAnnotation(ModuleInfo.class);
if (info == null) {
log.warning("Class " + clazz.getSimpleName() + " has no module info!");
continue;
}
log.info("Loading module " + info.name() + " v" + info.version() + " by " + Arrays.toString(info.authors()));
if (Module.class.isAssignableFrom(clazz)) {
// noinspection SuspiciousMethodCalls
Module module = offeredModules.get(clazz);
injector.injectMembers(module);
this.modules.add(module);
} else {
log.warning("Class " + clazz.getSimpleName() + " has the ModuleInfo annotation but does not implement Module!");
}
}
offeredModules.clear();
log.info("Loaded " + this.modules.size() + " modules!");
}
}
use of com.voxelgameslib.voxelgameslib.internal.timings.Timing in project VoxelGamesLibv2 by VoxelGamesLib.
the class StatsHandler method enable.
@Override
public void enable() {
registerTrackable(StatType.JOIN_COUNT);
Bukkit.getScheduler().runTaskTimer(vgl, () -> statTypes.stream().filter(Stat::shouldTick).forEach(Stat::tickOneMinute), 20 * 60, 20 * 60);
try (final Timing timing = new Timing("RegisterStatTypes")) {
// noinspection unchecked
scanner.getSubclasses(Stat.class.getName()).loadClasses().forEach(clazz -> registerStatType((Class<? extends Stat>) clazz));
}
log.info("Registered " + statTypes.size() + " StatsTypes");
Bukkit.getScheduler().runTaskTimer(vgl, () -> userHandler.getUsers().forEach(user -> {
if (user.getUserData().getStats().values().stream().anyMatch(StatInstance::isDirty)) {
log.finer("Persisting stats for " + user.getRawDisplayName());
persistenceHandler.getProvider().saveUser(user.getUserData());
}
}), 60 * 20, 60 * 20);
}
use of com.voxelgameslib.voxelgameslib.internal.timings.Timing in project VoxelGamesLibv2 by VoxelGamesLib.
the class HibernatePersistenceProvider method enable.
@Override
public void enable() {
boolean shouldCreateTable = config.persistence.initialTableCreation;
if (shouldCreateTable) {
config.persistence.initialTableCreation = false;
configHandler.saveGlobalConfig();
}
startupHandler.registerService("Hibernate");
Thread thread = new Thread(() -> {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySetting("hibernate.connection.username", config.persistence.user).applySetting("hibernate.connection.password", config.persistence.pass).applySetting("hibernate.connection.driver_class", config.persistence.driver).applySetting("hibernate.connection.url", config.persistence.url + "?useSSL=false").applySetting("hibernate.dialect", config.persistence.dialect).applySetting("hibernate.hbm2ddl.auto", shouldCreateTable ? "create" : "update").applySetting("hibernate.show_sql", config.persistence.showSQL + "").applySetting("hibernate.enable_lazy_load_no_trans", true).applySetting("hibernate.connection.autocommit", true).applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "").build();
MetadataSources sources = new MetadataSources(registry);
try (final Timing timing = new Timing("Init converters")) {
scanner.getClassesImplementing(VGLConverter.class.getName()).loadClasses().forEach((annotatedClass) -> {
try {
((VGLConverter<?, ?>) annotatedClass.newInstance()).init();
} catch (InstantiationException | IllegalAccessException e) {
log.warning("Error while initializing converter " + annotatedClass.getSimpleName());
e.printStackTrace();
}
});
}
try (final Timing timing = new Timing("RegisterDBEntities")) {
scanner.getClassesWithAnnotation(Entity.class.getName()).loadClasses().forEach((annotatedClass) -> {
if (!annotatedClass.getName().contains("ebean"))
sources.addAnnotatedClass(annotatedClass);
});
}
try {
Metadata metadata = sources.buildMetadata();
sessionFactory = metadata.buildSessionFactory();
log.info("Build HibernationSessionFactory with " + sources.getAnnotatedClasses().size() + " entities.");
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(registry);
e.printStackTrace();
}
cBuilder = sessionFactory.getCriteriaBuilder();
startupHandler.unregisterService("Hibernate");
});
thread.setName("Hibernate Startup");
thread.start();
}
Aggregations