Skip to content

Initial support for MV5 core and hk2 injection #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ plugins {
}

version = System.getenv('GITHUB_VERSION') ?: 'local'
group = 'com.onarandombox.multiversesignportals'
group = 'org.mvplugins.multiverse.signportals'
description = 'Multiverse-SignPortals'

java.sourceCompatibility = JavaVersion.VERSION_11
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

repositories {
mavenLocal()
Expand All @@ -24,16 +28,22 @@ repositories {
name = 'onarandombox'
url = uri('https://repo.onarandombox.com/content/groups/public/')
}

maven {
// todo: remove before mv5 release
name = 'benwoo1110'
url = uri('https://repo.c0ding.party/multiverse-beta')
}
}

dependencies {
// Spigot
implementation('org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT') {
implementation('org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT') {
exclude group: 'junit', module: 'junit'
}

// Core
implementation 'com.onarandombox.multiversecore:Multiverse-Core:4.2.2'
implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT'

// Utils
api('com.dumptruckman.minecraft:Logging:1.1.1') {
Expand All @@ -55,7 +65,6 @@ tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}


configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
Expand Down Expand Up @@ -112,8 +121,8 @@ javadoc {
project.configurations.api.canBeResolved = true

shadowJar {
relocate 'com.dumptruckman.minecraft.util.Logging', 'com.onarandombox.MultiverseSignPortals.util.MVSPLogging'
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'com.onarandombox.MultiverseSignPortals.util.DebugFileLogger'
relocate 'com.dumptruckman.minecraft.util.Logging', 'org.mvplugins.multiverse.signportals.util.MVSPLogging'
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.signportals.util.DebugFileLogger'

configurations = [project.configurations.api]

Expand All @@ -122,3 +131,14 @@ shadowJar {

build.dependsOn shadowJar
jar.enabled = false

tasks.register('runHabitatGenerator', JavaExec) {
classpath = configurations["compileClasspath"]
main = 'org.mvplugins.multiverse.external.jvnet.hk2.generator.HabitatGenerator'

args = [
'--file', "build/libs/multiverse-signportals-$version" + ".jar",
'--locator', 'Multiverse-SignPortals',
]
}
tasks.named("build") { finalizedBy("runHabitatGenerator") }
Comment on lines +134 to +144
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main part that make it work

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@
* with this project.
*/

package com.onarandombox.MultiverseSignPortals;
package org.mvplugins.multiverse.signportals;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVPlugin;
import com.onarandombox.MultiverseSignPortals.listeners.MVSPBlockListener;
import com.onarandombox.MultiverseSignPortals.listeners.MVSPPlayerListener;
import com.onarandombox.MultiverseSignPortals.listeners.MVSPPluginListener;
import com.onarandombox.MultiverseSignPortals.listeners.MVSPVersionListener;
import com.onarandombox.MultiverseSignPortals.utils.PortalDetector;
import org.bukkit.plugin.PluginManager;
import org.mvplugins.multiverse.core.MultiverseCore;
import org.mvplugins.multiverse.core.api.config.MVCoreConfig;
import org.mvplugins.multiverse.core.inject.PluginServiceLocator;
import org.mvplugins.multiverse.core.submodules.MVCore;
import org.mvplugins.multiverse.core.submodules.MVPlugin;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.external.vavr.control.Option;
import org.mvplugins.multiverse.external.vavr.control.Try;
import org.bukkit.plugin.java.JavaPlugin;
import org.mvplugins.multiverse.signportals.listeners.SignPortalsListener;

import java.util.logging.Level;

@Service
public class MultiverseSignPortals extends JavaPlugin implements MVPlugin {

protected MultiverseCore core;
protected MVSPPlayerListener playerListener;
protected MVSPPluginListener pluginListener;
protected MVSPBlockListener blockListener;
private final static int requiresProtocol = 24;
private MultiverseCore core;
private PluginServiceLocator serviceLocator;

private PortalDetector portalDetector;
private final static int requiresProtocol = 50;

/** This fires before I get Enabled. */
public void onLoad() {
Logging.init(this);
this.getDataFolder().mkdirs();
}

public void onEnable() {
Logging.init(this);
Expand All @@ -50,44 +55,60 @@ public void onEnable() {
return;
}

Logging.setDebugLevel(core.getMVConfig().getGlobalDebug());
initializeDependencyInjection();
registerEvents();
Logging.setDebugLevel(serviceLocator.getActiveService(MVCoreConfig.class).getGlobalDebug());

this.core.incrementPluginCount();

// Init our listeners
this.pluginListener = new MVSPPluginListener(this);
this.playerListener = new MVSPPlayerListener(this);
this.blockListener = new MVSPBlockListener(this);

// Init our events
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(this.pluginListener, this);
pm.registerEvents(this.playerListener, this);
pm.registerEvents(this.blockListener, this);
pm.registerEvents(new MVSPVersionListener(this), this);

this.portalDetector = new PortalDetector(this);

Logging.log(true, Level.INFO, " Enabled - By %s", getAuthors());
}

public void onDisable() {
// The Usual
shutdownDependencyInjection();
Logging.info("- Disabled");
}

/** This fires before I get Enabled. */
public void onLoad() {
Logging.init(this);
this.getDataFolder().mkdirs();
private void initializeDependencyInjection() {
serviceLocator = core.getServiceLocatorFactory()
.registerPlugin(new MultiverseSignPortalsPluginBinder(this), core.getServiceLocator())
.flatMap(PluginServiceLocator::enable)
.getOrElseThrow(exception -> {
Logging.severe("Failed to initialize dependency injection!");
getServer().getPluginManager().disablePlugin(this);
return new RuntimeException(exception);
});
}

private void shutdownDependencyInjection() {
Option.of(serviceLocator)
.peek(PluginServiceLocator::disable)
.peek(ignore -> serviceLocator = null);
}

/**
* Function to Register all the Events needed.
*/
private void registerEvents() {
var pluginManager = getServer().getPluginManager();

Try.run(() -> serviceLocator.getAllServices(SignPortalsListener.class).forEach(
listener -> {
Logging.info(listener.toString());
pluginManager.registerEvents(listener, this);
}))
.onFailure(e -> {
throw new RuntimeException("Failed to register listeners. Terminating...", e);
});
}
Comment on lines +72 to 103
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here is the same way of initializing service locator as core


/**
* Parse the Authors Array into a readable String with ',' and 'and'.
*
* @return An comma separated string of authors
*/
private String getAuthors() {
@Override
public String getAuthors() {
String authors = "";
for (int i = 0; i < this.getDescription().getAuthors().size(); i++) {
if (i == this.getDescription().getAuthors().size() - 1) {
Expand All @@ -99,55 +120,22 @@ private String getAuthors() {
return authors.substring(2);
}

/**
* {@inheritDoc}
*
* @deprecated This is now deprecated, nobody needs it any longer.
* All logging is now done with {@link Logging}.
*/
@Override
@Deprecated
public void log(Level level, String msg) {
Logging.log(level, msg);
}

// No longer using, use getVersionInfo instead.
@Override
@Deprecated
public String dumpVersionInfo(String buffer) {
buffer += logAndAddToPasteBinBuffer(this.getVersionInfo());
return buffer;
public PluginServiceLocator getServiceLocator() {
return serviceLocator;
}

public String getVersionInfo() {
return "[Multiverse-SignPortals] Multiverse-SignPortals Version: " + this.getDescription().getVersion() + '\n';
}

// No longer using, use getVersionInfo instead.
@Deprecated
private String logAndAddToPasteBinBuffer(String string) {
Logging.info(string);
return Logging.getPrefixedMessage(string, false);
}

@Override
public MultiverseCore getCore() {
public MVCore getCore() {
return this.core;
}

@Override
public void setCore(MultiverseCore core) {
this.core = core;
}

@Override
public int getProtocolVersion() {
return 1;
}

public PortalDetector getPortalDetector() {
return this.portalDetector;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.mvplugins.multiverse.signportals;

import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder;
import org.mvplugins.multiverse.core.submodules.MVPlugin;
import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;

public class MultiverseSignPortalsPluginBinder extends JavaPluginBinder<MultiverseSignPortals> {

protected MultiverseSignPortalsPluginBinder(@NotNull MultiverseSignPortals plugin) {
super(plugin);
}

@Override
protected ScopedBindingBuilder<MultiverseSignPortals> bindPluginClass(
ScopedBindingBuilder<MultiverseSignPortals> bindingBuilder) {
return super.bindPluginClass(bindingBuilder).to(MVPlugin.class).to(MultiverseSignPortals.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
* Multiverse 2 is licensed under the BSD License.
* For more information please check the README.md file included
* with this project.
*/

package com.onarandombox.MultiverseSignPortals.enums;

/**
* Multiverse 2
*
* @author fernferret
*/
public enum Axis {
X, Z
}
/*
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
* Multiverse 2 is licensed under the BSD License.
* For more information please check the README.md file included
* with this project.
*/
package org.mvplugins.multiverse.signportals.enums;
/**
* Multiverse 2
*
* @author fernferret
*/
public enum Axis {
X, Z
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
* Multiverse 2 is licensed under the BSD License.
* For more information please check the README.md file included
* with this project.
*/

package com.onarandombox.MultiverseSignPortals.exceptions;

public class MoreThanOneSignFoundException extends Exception {
}
/*
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
* Multiverse 2 is licensed under the BSD License.
* For more information please check the README.md file included
* with this project.
*/
package org.mvplugins.multiverse.signportals.exceptions;
public class MoreThanOneSignFoundException extends Exception {
}
Loading
Loading