-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/main/java/com/onarandombox/MultiverseSignPortals/listeners/MVSPTravelAgent.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/com/onarandombox/MultiverseSignPortals/utils/PortalLocation.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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; | ||
} | ||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/mvplugins/multiverse/signportals/MultiverseSignPortalsPluginBinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
34 changes: 17 additions & 17 deletions
34
...box/MultiverseSignPortals/enums/Axis.java → ...ns/multiverse/signportals/enums/Axis.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
22 changes: 11 additions & 11 deletions
22
...ptions/MoreThanOneSignFoundException.java → ...ptions/MoreThanOneSignFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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