use of com.bergerkiller.bukkit.common.internal.map.CommonMapController in project BKCommonLib by bergerhealer.
the class CommonPlugin method enable.
@Override
public void enable() {
// Validate version
if (Common.IS_COMPATIBLE) {
log(Level.INFO, "BKCommonLib is running on " + Common.SERVER.getServerDetails());
} else {
String verText = Common.TEMPLATE_RESOLVER.getDebugSupportedVersionsString();
log(Level.SEVERE, "This version of BKCommonLib is not compatible with: " + Common.SERVER.getServerDetails());
log(Level.SEVERE, "It could be that BKCommonLib has to be updated, as the current version is built for MC " + verText);
log(Level.SEVERE, "Please look for a new updated BKCommonLib version that is compatible:");
log(Level.SEVERE, "https://www.spigotmc.org/resources/bkcommonlib.39590/");
log(Level.SEVERE, "Unstable development builds for MC " + Common.MC_VERSION + " may be found on our continuous integration server:");
log(Level.SEVERE, "https://ci.mg-dev.eu/job/BKCommonLib/");
this.onCriticalStartupFailure("BKCommonLib is not compatible with " + Common.SERVER.getServerDetails());
return;
}
// Set the packet handler to use before enabling further - it could fail!
if (!this.updatePacketHandler()) {
this.onCriticalStartupFailure("Critical failure updating the packet handler");
return;
}
// Allow this to fail if there's big problems, as this is an optional requirement
try {
CommonBootstrap.preloadCriticalComponents();
} catch (Throwable t) {
Logging.LOGGER_REFLECTION.log(Level.SEVERE, "Failed to initialize some critical components", t);
}
// Load configuration
FileConfiguration config = new FileConfiguration(this);
config.load();
config.setHeader("This is the main configuration file of BKCommonLib");
config.addHeader("Normally you should not have to make changes to this file");
config.addHeader("Unused components of the library can be disabled to improve performance");
config.addHeader("By default all components and features are enabled");
config.setHeader("enableMapDisplays", "\nWhether the Map Display engine is enabled, running in the background to refresh and render maps");
config.addHeader("enableMapDisplays", "When enabled, the map item tracking may impose a slight overhead");
config.addHeader("enableMapDisplays", "If no plugin is using map displays, then this can be safely disabled to improve performance");
this.isMapDisplaysEnabled = config.get("enableMapDisplays", true);
// If java.awt is not available, the map display API won't work. Just disable it, and log an error.
if (this.isMapDisplaysEnabled && CommonBootstrap.isHeadlessJDK()) {
this.isMapDisplaysEnabled = false;
Logging.LOGGER_MAPDISPLAY.log(Level.SEVERE, "The Map Displays feature has been turned off because the server is incompatible");
Logging.LOGGER_MAPDISPLAY.log(Level.SEVERE, "Reason: The Java AWT runtime library is not available");
Logging.LOGGER_MAPDISPLAY.log(Level.SEVERE, "This is usually because a headless JVM is used for the server");
Logging.LOGGER_MAPDISPLAY.log(Level.SEVERE, "Please install and configure a non-headless JVM to have Map Displays work");
}
config.setHeader("enableItemFrameDisplays", "\nWhether all item frames on the server are tracked to see if they display a map display.");
config.addHeader("enableItemFrameDisplays", "This allows for map displays to be displayed on item frames and interacted with.");
config.addHeader("enableItemFrameDisplays", "If 'enableItemFrameTiling' is also true, then this allows for multi-item frame displays.");
config.addHeader("enableItemFrameDisplays", "Tracking the existence of all item frames on the server can pose an overhead, as");
config.addHeader("enableItemFrameDisplays", "shown under the 'MapDisplayFramedMapUpdater' task. Turning this off can help performance.");
config.addHeader("enableItemFrameDisplays", "If 'enableMapDisplays' is true then player-held maps will continue working fine.");
this.isFrameDisplaysEnabled = config.get("enableItemFrameDisplays", true);
config.setHeader("enableItemFrameTiling", "\nWhether multiple item frames next to each other can merge to show one large display");
config.addHeader("enableItemFrameTiling", "This allows Map Displays to be displayed on multiple item frames at a larger resolution");
config.addHeader("enableItemFrameTiling", "The tiling detection logic poses some overhead on the server, and if unused, can be disabled");
this.isFrameTilingSupported = config.get("enableItemFrameTiling", true);
config.setHeader("teleportPlayersToSeat", "\nWhether to teleport players to their supposed seat while they hold the sneak button");
config.addHeader("teleportPlayersToSeat", "This is used on Minecraft 1.16 and later to make sure players stay near their seat,");
config.addHeader("teleportPlayersToSeat", "when exiting the seat was cancelled.");
this.teleportPlayersToSeat = config.get("teleportPlayersToSeat", true);
config.setHeader("forceSynchronousSaving", "\nWhether to force saving to be done synchronously, rather than asynchronously");
config.addHeader("forceSynchronousSaving", "If the Asynchronous File I/O in the JVM has a glitch in it, it might cause very large");
config.addHeader("forceSynchronousSaving", "corrupt (.yml) files to be generated. On server restart this can cause a loss of data.");
config.addHeader("forceSynchronousSaving", "Synchronous saving (such as YAML) may hurt server performance for large files,");
config.addHeader("forceSynchronousSaving", "but will prevent these issues from happening.");
this.forceSynchronousSaving = config.get("forceSynchronousSaving", false);
config.setHeader("debugTimings", "\nWhether to instrument additional Timings for some of the core BKCommonLib components");
config.addHeader("debugTimings", "These timings might be useful to identify performance problems, or their causes");
config.addHeader("debugTimings", "They may cause a slight performance hit, so leave this option disabled unless you need them");
final boolean debugTimings = config.get("debugTimings", false);
config.save();
// Welcome message
final List<String> welcomeMessages = Arrays.asList("This library is written with stability in mind.", "No Bukkit moderators were harmed while compiling this piece of art.", "Have a problem Bukkit can't fix? Write a library!", "Bringing home the bacon since 2011!", "Completely virus-free and scanned by various Bukkit-dev-staff watching eyes.", "Hosts all the features that are impossible to include in a single Class", "CraftBukkit: redone, reworked, translated and interfaced.", "Having an error? *gasp* Don't forget to file a ticket on github!", "Package versioning is what brought BKCommonLib and CraftBukkit closer together!", "For all the haters out there: BKCommonLib at least tries!", "Want fries with that? We have hidden fries in the FoodUtil class.", "Not enough wrappers. Needs more wrappers. Moooreee...", "Reflection can open the way to everyone's heart, including CraftBukkit.", "Our love is not permitted by the overlords. We must flee...", "Now a plugin, a new server implementation tomorrow???", "Providing support for supporting the unsupportable.", "Every feature break in Bukkit makes my feature list longer.", "I...I forgot an exclamation mark...*rages internally*", "I am still winning the game. Are you?", "We did what our big brother couldn't", "If you need syntax help visit javadocs.a.b.v1_2_3.net", "v1_1_R1 1+1+1 = 3, Half life 3 confirmed?", "BKCommonLib > Minecraft.a.b().q.f * Achievement.OBFUSCATED.value", "BKCommonLib isn't a plugin, its a language based on english.", "Updating is like reinventing the wheel for BKCommonLib.", "Say thanks to our wonderful devs: Friwi, KamikazePlatypus and mg_1999", "Welcome to the modern era, welcome to callback hell", "Soon generating lambda expressions from thin air!", "We have a Discord!", "Years of Minecraft history carefully catalogued", "50% generated, 50% crafted by an artificial intelligence", "Supplier supplying suppliers for your lazy needs!", "Please wait while we get our code ready...", "60% of the time, it works all the time.", "I don't make mistakes. I just find ways not to code this plugin.", "Less complicated than the American election.");
setEnableMessage(welcomeMessages.get(new Random().nextInt(welcomeMessages.size())));
setDisableMessage(null);
// Enable all components in order
this.components.enable(this.serverLogRecorder);
this.components.enableForVersions("Dimension to Holder conversion", "1.18.2", null, MC1_18_2_Conversion::initComponent);
this.components.enableCreate(OfflineWorld::initializeComponent);
this.components.enableForVersions("Dimension resource key tracker", "1.16", "1.16.1", DimensionResourceKeyConversion.Tracker::new);
// Timings, if enabled, otherwise no-op
if (debugTimings) {
CommonTimings.QUEUE_PACKET = Timings.create(this, "PacketHandler::queuePacket");
CommonTimings.SEND_PACKET = Timings.create(this, "PacketHandler::sendPacket");
}
// Setup next tick executor
CommonNextTickExecutor.INSTANCE.setExecutorTask(new CommonNextTickExecutor.ExecutorTask(this));
// Initialize LookupEntityClassMap and hook it into the server
try {
LookupEntityClassMap.hook();
} catch (Throwable t) {
t.printStackTrace();
}
// Do not do this if map displays are disabled.
if (this.isMapDisplaysEnabled) {
MapColorPalette.getColor(0, 0, 0);
}
// Initialize NBT early
NBTBaseHandle.T.forceInitialization();
// Initialize entity add/remove tracking handler
// Note: onWorldEnabled() is called for all the worlds later on
EntityAddRemoveHandler.INSTANCE.onEnabled(this);
// Initialize vehicle mount manager
vehicleMountManager = new CommonVehicleMountManager(this);
vehicleMountManager.enable();
// Initialize chunk loader pool
chunkLoaderPool = new CommonChunkLoaderPool();
// Initialize forced chunk manager
forcedChunkManager = new CommonForcedChunkManager(this);
forcedChunkManager.enable();
// Initialize permissions
permissionHandler = new PermissionHandler();
// Initialize event factory
eventFactory = new CommonEventFactory();
// Initialize portal handling logic
PortalHandler.INSTANCE.enable(this);
// Initialize entity map (needs to be here because of CommonPlugin instance needed)
playerMetadata = new EntityMap<Player, CommonPlayerMeta>();
// Register events and tasks, initialize
register(listener = new CommonListener());
// NO LONGER USED!!!
// register(new CommonPacketMonitor(), CommonPacketMonitor.TYPES);
mapController = new CommonMapController();
if (this.isMapDisplaysEnabled) {
mapController.onEnable(this, startedTasks);
}
startedTasks.add(new MoveEventHandler(this).start(1, 1));
startedTasks.add(new EntityRemovalHandler(this).start(1, 1));
startedTasks.add(new CreaturePreSpawnEventHandlerDetectorTask(this).start(0, 20));
startedTasks.add(new ObjectCacheCleanupTask(this).start(10, 20 * 60 * 30));
// For those servers, we handle them using our own system
if (!EntityPlayerHandle.T.getRemoveQueue.isAvailable()) {
startedTasks.add(new EntityRemoveQueueSyncTask(this).start(1, 1));
}
// Operations to execute the next tick (when the server has started)
CommonUtil.nextTick(() -> {
// Set server started state
isServerStarted = true;
});
// Register listeners and hooks
for (World world : WorldUtil.getWorlds()) {
notifyWorldAdded(world);
}
// BKCommonLib Metrics
if (hasMetrics()) {
// Soft dependencies
getMetrics().addGraph(new SoftDependenciesGraph());
// Depending
getMetrics().addGraph(new MyDependingPluginsGraph());
}
// Server-specific enabling occurs
Common.SERVER.enable(this);
// Parse BKCommonLib version to int
int version = this.getVersionNumber();
if (version != Common.VERSION) {
log(Level.SEVERE, "Common.VERSION needs to be updated to contain '" + version + "'!");
}
}
Aggregations