Skip to content

Commit 164c89c

Browse files
authored
Merge pull request #98 from Multiverse/ben/mv5/core-support
Initial support for MV5 core and hk2 injection
2 parents c2be028 + 7be8f7e commit 164c89c

File tree

17 files changed

+373
-346
lines changed

17 files changed

+373
-346
lines changed

build.gradle

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ plugins {
66
}
77

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

12-
java.sourceCompatibility = JavaVersion.VERSION_11
12+
java {
13+
toolchain {
14+
languageVersion.set(JavaLanguageVersion.of(17))
15+
}
16+
}
1317

1418
repositories {
1519
mavenLocal()
@@ -24,16 +28,22 @@ repositories {
2428
name = 'onarandombox'
2529
url = uri('https://repo.onarandombox.com/content/groups/public/')
2630
}
31+
32+
maven {
33+
// todo: remove before mv5 release
34+
name = 'benwoo1110'
35+
url = uri('https://repo.c0ding.party/multiverse-beta')
36+
}
2737
}
2838

2939
dependencies {
3040
// Spigot
31-
implementation('org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT') {
41+
implementation('org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT') {
3242
exclude group: 'junit', module: 'junit'
3343
}
3444

3545
// Core
36-
implementation 'com.onarandombox.multiversecore:Multiverse-Core:4.2.2'
46+
implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT'
3747

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

58-
5968
configurations {
6069
[apiElements, runtimeElements].each {
6170
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
@@ -112,8 +121,8 @@ javadoc {
112121
project.configurations.api.canBeResolved = true
113122

114123
shadowJar {
115-
relocate 'com.dumptruckman.minecraft.util.Logging', 'com.onarandombox.MultiverseSignPortals.util.MVSPLogging'
116-
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'com.onarandombox.MultiverseSignPortals.util.DebugFileLogger'
124+
relocate 'com.dumptruckman.minecraft.util.Logging', 'org.mvplugins.multiverse.signportals.util.MVSPLogging'
125+
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.signportals.util.DebugFileLogger'
117126

118127
configurations = [project.configurations.api]
119128

@@ -122,3 +131,14 @@ shadowJar {
122131

123132
build.dependsOn shadowJar
124133
jar.enabled = false
134+
135+
tasks.register('runHabitatGenerator', JavaExec) {
136+
classpath = configurations["compileClasspath"]
137+
main = 'org.mvplugins.multiverse.external.jvnet.hk2.generator.HabitatGenerator'
138+
139+
args = [
140+
'--file', "build/libs/multiverse-signportals-$version" + ".jar",
141+
'--locator', 'Multiverse-SignPortals',
142+
]
143+
}
144+
tasks.named("build") { finalizedBy("runHabitatGenerator") }

src/main/java/com/onarandombox/MultiverseSignPortals/listeners/MVSPTravelAgent.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/com/onarandombox/MultiverseSignPortals/utils/PortalLocation.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/com/onarandombox/MultiverseSignPortals/MultiverseSignPortals.java renamed to src/main/java/org/mvplugins/multiverse/signportals/MultiverseSignPortals.java

Lines changed: 60 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,35 @@
55
* with this project.
66
*/
77

8-
package com.onarandombox.MultiverseSignPortals;
8+
package org.mvplugins.multiverse.signportals;
99

1010
import com.dumptruckman.minecraft.util.Logging;
11-
import com.onarandombox.MultiverseCore.MultiverseCore;
12-
import com.onarandombox.MultiverseCore.api.MVPlugin;
13-
import com.onarandombox.MultiverseSignPortals.listeners.MVSPBlockListener;
14-
import com.onarandombox.MultiverseSignPortals.listeners.MVSPPlayerListener;
15-
import com.onarandombox.MultiverseSignPortals.listeners.MVSPPluginListener;
16-
import com.onarandombox.MultiverseSignPortals.listeners.MVSPVersionListener;
17-
import com.onarandombox.MultiverseSignPortals.utils.PortalDetector;
18-
import org.bukkit.plugin.PluginManager;
11+
import org.mvplugins.multiverse.core.MultiverseCore;
12+
import org.mvplugins.multiverse.core.api.config.MVCoreConfig;
13+
import org.mvplugins.multiverse.core.inject.PluginServiceLocator;
14+
import org.mvplugins.multiverse.core.submodules.MVCore;
15+
import org.mvplugins.multiverse.core.submodules.MVPlugin;
16+
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
17+
import org.mvplugins.multiverse.external.vavr.control.Option;
18+
import org.mvplugins.multiverse.external.vavr.control.Try;
1919
import org.bukkit.plugin.java.JavaPlugin;
20+
import org.mvplugins.multiverse.signportals.listeners.SignPortalsListener;
2021

2122
import java.util.logging.Level;
2223

24+
@Service
2325
public class MultiverseSignPortals extends JavaPlugin implements MVPlugin {
2426

25-
protected MultiverseCore core;
26-
protected MVSPPlayerListener playerListener;
27-
protected MVSPPluginListener pluginListener;
28-
protected MVSPBlockListener blockListener;
29-
private final static int requiresProtocol = 24;
27+
private MultiverseCore core;
28+
private PluginServiceLocator serviceLocator;
3029

31-
private PortalDetector portalDetector;
30+
private final static int requiresProtocol = 50;
31+
32+
/** This fires before I get Enabled. */
33+
public void onLoad() {
34+
Logging.init(this);
35+
this.getDataFolder().mkdirs();
36+
}
3237

3338
public void onEnable() {
3439
Logging.init(this);
@@ -50,44 +55,60 @@ public void onEnable() {
5055
return;
5156
}
5257

53-
Logging.setDebugLevel(core.getMVConfig().getGlobalDebug());
58+
initializeDependencyInjection();
59+
registerEvents();
60+
Logging.setDebugLevel(serviceLocator.getActiveService(MVCoreConfig.class).getGlobalDebug());
5461

5562
this.core.incrementPluginCount();
56-
57-
// Init our listeners
58-
this.pluginListener = new MVSPPluginListener(this);
59-
this.playerListener = new MVSPPlayerListener(this);
60-
this.blockListener = new MVSPBlockListener(this);
61-
62-
// Init our events
63-
PluginManager pm = this.getServer().getPluginManager();
64-
pm.registerEvents(this.pluginListener, this);
65-
pm.registerEvents(this.playerListener, this);
66-
pm.registerEvents(this.blockListener, this);
67-
pm.registerEvents(new MVSPVersionListener(this), this);
68-
69-
this.portalDetector = new PortalDetector(this);
70-
7163
Logging.log(true, Level.INFO, " Enabled - By %s", getAuthors());
7264
}
7365

7466
public void onDisable() {
7567
// The Usual
68+
shutdownDependencyInjection();
7669
Logging.info("- Disabled");
7770
}
7871

79-
/** This fires before I get Enabled. */
80-
public void onLoad() {
81-
Logging.init(this);
82-
this.getDataFolder().mkdirs();
72+
private void initializeDependencyInjection() {
73+
serviceLocator = core.getServiceLocatorFactory()
74+
.registerPlugin(new MultiverseSignPortalsPluginBinder(this), core.getServiceLocator())
75+
.flatMap(PluginServiceLocator::enable)
76+
.getOrElseThrow(exception -> {
77+
Logging.severe("Failed to initialize dependency injection!");
78+
getServer().getPluginManager().disablePlugin(this);
79+
return new RuntimeException(exception);
80+
});
81+
}
82+
83+
private void shutdownDependencyInjection() {
84+
Option.of(serviceLocator)
85+
.peek(PluginServiceLocator::disable)
86+
.peek(ignore -> serviceLocator = null);
87+
}
88+
89+
/**
90+
* Function to Register all the Events needed.
91+
*/
92+
private void registerEvents() {
93+
var pluginManager = getServer().getPluginManager();
94+
95+
Try.run(() -> serviceLocator.getAllServices(SignPortalsListener.class).forEach(
96+
listener -> {
97+
Logging.info(listener.toString());
98+
pluginManager.registerEvents(listener, this);
99+
}))
100+
.onFailure(e -> {
101+
throw new RuntimeException("Failed to register listeners. Terminating...", e);
102+
});
83103
}
84104

85105
/**
86106
* Parse the Authors Array into a readable String with ',' and 'and'.
87107
*
88108
* @return An comma separated string of authors
89109
*/
90-
private String getAuthors() {
110+
@Override
111+
public String getAuthors() {
91112
String authors = "";
92113
for (int i = 0; i < this.getDescription().getAuthors().size(); i++) {
93114
if (i == this.getDescription().getAuthors().size() - 1) {
@@ -99,55 +120,22 @@ private String getAuthors() {
99120
return authors.substring(2);
100121
}
101122

102-
/**
103-
* {@inheritDoc}
104-
*
105-
* @deprecated This is now deprecated, nobody needs it any longer.
106-
* All logging is now done with {@link Logging}.
107-
*/
108-
@Override
109-
@Deprecated
110-
public void log(Level level, String msg) {
111-
Logging.log(level, msg);
112-
}
113-
114-
// No longer using, use getVersionInfo instead.
115123
@Override
116-
@Deprecated
117-
public String dumpVersionInfo(String buffer) {
118-
buffer += logAndAddToPasteBinBuffer(this.getVersionInfo());
119-
return buffer;
124+
public PluginServiceLocator getServiceLocator() {
125+
return serviceLocator;
120126
}
121127

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

126-
// No longer using, use getVersionInfo instead.
127-
@Deprecated
128-
private String logAndAddToPasteBinBuffer(String string) {
129-
Logging.info(string);
130-
return Logging.getPrefixedMessage(string, false);
131-
}
132-
133132
@Override
134-
public MultiverseCore getCore() {
133+
public MVCore getCore() {
135134
return this.core;
136135
}
137136

138-
@Override
139-
public void setCore(MultiverseCore core) {
140-
this.core = core;
141-
}
142-
143137
@Override
144138
public int getProtocolVersion() {
145139
return 1;
146140
}
147-
148-
public PortalDetector getPortalDetector() {
149-
return this.portalDetector;
150-
}
151-
152-
153141
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.mvplugins.multiverse.signportals;
2+
3+
import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder;
4+
import org.mvplugins.multiverse.core.submodules.MVPlugin;
5+
import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
6+
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
7+
8+
public class MultiverseSignPortalsPluginBinder extends JavaPluginBinder<MultiverseSignPortals> {
9+
10+
protected MultiverseSignPortalsPluginBinder(@NotNull MultiverseSignPortals plugin) {
11+
super(plugin);
12+
}
13+
14+
@Override
15+
protected ScopedBindingBuilder<MultiverseSignPortals> bindPluginClass(
16+
ScopedBindingBuilder<MultiverseSignPortals> bindingBuilder) {
17+
return super.bindPluginClass(bindingBuilder).to(MVPlugin.class).to(MultiverseSignPortals.class);
18+
}
19+
}

src/main/java/com/onarandombox/MultiverseSignPortals/enums/Axis.java renamed to src/main/java/org/mvplugins/multiverse/signportals/enums/Axis.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/*
2-
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
3-
* Multiverse 2 is licensed under the BSD License.
4-
* For more information please check the README.md file included
5-
* with this project.
6-
*/
7-
8-
package com.onarandombox.MultiverseSignPortals.enums;
9-
10-
/**
11-
* Multiverse 2
12-
*
13-
* @author fernferret
14-
*/
15-
public enum Axis {
16-
X, Z
17-
}
1+
/*
2+
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
3+
* Multiverse 2 is licensed under the BSD License.
4+
* For more information please check the README.md file included
5+
* with this project.
6+
*/
7+
8+
package org.mvplugins.multiverse.signportals.enums;
9+
10+
/**
11+
* Multiverse 2
12+
*
13+
* @author fernferret
14+
*/
15+
public enum Axis {
16+
X, Z
17+
}

src/main/java/com/onarandombox/MultiverseSignPortals/exceptions/MoreThanOneSignFoundException.java renamed to src/main/java/org/mvplugins/multiverse/signportals/exceptions/MoreThanOneSignFoundException.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/*
2-
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
3-
* Multiverse 2 is licensed under the BSD License.
4-
* For more information please check the README.md file included
5-
* with this project.
6-
*/
7-
8-
package com.onarandombox.MultiverseSignPortals.exceptions;
9-
10-
public class MoreThanOneSignFoundException extends Exception {
11-
}
1+
/*
2+
* Multiverse 2 Copyright (c) the Multiverse Team 2011.
3+
* Multiverse 2 is licensed under the BSD License.
4+
* For more information please check the README.md file included
5+
* with this project.
6+
*/
7+
8+
package org.mvplugins.multiverse.signportals.exceptions;
9+
10+
public class MoreThanOneSignFoundException extends Exception {
11+
}

0 commit comments

Comments
 (0)