Possibility of making plugins world-specific?

Discussion in 'Plugin Development' started by ccrama, Jul 10, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ccrama

    Hello Bukkit,
    I am in the process of planning/starting a "core" for server networks, and I am trying to set up a system almost like bungee, but instead of running across many servers, make each world in the one server's files into its own mini server by localizing chat and other functions. I want to be able to hook into my main api which will run on /plugins/ccore.jar (global plugin) in each world by adding a plugins section to each world (/world/plugins/game.jar). Is it possible to localize events in such a way as to make specific plugins only work on specific worlds and thus appearing as if the world is its own server? The grand idea is to have my economy plugin, core plugin, and api functions rest on the default plugin location, and my core would go to each world's files and look for a plugins folder, and if that exists begin the game on that world.

    I honestly don't know if this will even work, but any suggestions/help would be appreciated.

    Cheers,
    ccrama


    EDIT:
    Visual of server setup:
    [​IMG]
     
  2. ccrama
    Code the plugins to function only in one of the worlds? Basically cancel everything if the world does not equal to the world you want it to work in.
     
  3. Offline

    mythbusterma

    ccrama

    Bukkit doesn't logically separate itself into separate worlds, it merely loads everything as one large server, any plugins that you want to be world specific must support the feature themselves, or be custom written plugins that do so. Besides modifying the source of existing plugins, there really isn't another way to do this.

    You can use your own plugin loader to modify the loading of plugins in Bukkit via PluginManager#registerInterface(Class<? extends PluginLoader>) and then by reimplementing the different features. You will also have to make events world specific.
     
  4. Offline

    mazentheamazin

    mythbusterma ccrama
    There is... I am not going to look into it that much but here's something you might want to look at.
     
  5. Offline

    mythbusterma

    I stand corrected, see me above post on how to do this.

    Examining their source code would be most helpful in this case.
     
  6. Offline

    Necrodoom

    This is a hacky method and will not work well and is far less recommended than having the plugin have per-world handling.
     
    mythbusterma likes this.
  7. Offline

    ccrama

    mythbusterma mazentheamazin mythbusterma Necrodoom

    Thanks for that link mazentheamazin. I'll see how he did that.

    Otherwise, I do understand this is a bit "hacky", but I want to make it as easy to use as possible and short from creating plugins with worlds coded in, this would be the way to do it. Thanks for you guys' help!

    @mythbusterma @mazentheamazin @mythbusterma @Necrodoom

    What I'm thinking of doing is loading each of the jars when my core plugin is enabled, and act as a leazion between the methods in the loaded jar and the events that occur. The code of the plugin jar would all be annotation based and hook into events that way (something like @coreEventHandler(EntityDamageEvent) ), and when that event occurs on that world, my plugin goes into that jar and executes that method attached to the annotation.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Offline

    unrealdesign

    ccrama If you are coding everything yourself, this is the best way. You want to implement your ccore plugin into all of your sub plugins. Have an API for easy access to your ccore plugin.

    In your ccore plugin, have a custom config file (example: plugin_worlds.yml). This will store all of the information the API will read from and send to the plugins that use it. The structure will be like so:
    Code:
    <plugin name>
        worlds: <world1>,<world2>,<world3>
    <plugin name2>
        worlds: <world2>
    In your ccore plugin, have a method that will takes the argument "plugin name" and returns a World[]. This method will read the plugin_worlds.yml file and find the plugin name tree, and then return the worlds. If it can't find a configuration path then it returns all worlds.

    In your other plugins, have it import the ccore plugin. Before you execute any commands or do any listener checks. Make sure the player, or command, or anything is in the correct world. If not, then just return.
     
    ccrama likes this.
  9. Offline

    mythbusterma

    See the following JavaDocs:
    http://jd.bukkit.org/rb/apidocs/org...nager.html#registerInterface(java.lang.Class)

    http://jd.bukkit.org/rb/apidocs/org...kit.event.Listener, org.bukkit.plugin.Plugin)

    These demonstrate how to reimplement the PluginLoader, and then how to change the way they listen for events, so you can change it to be World specific. Do keep in mind which ones are universal and which ones aren't, and I sincerely hope you are quite skilled in Java as this is not an easy undertaking.
     
    ccrama likes this.
  10. Offline

    ccrama

    unrealdesign mythbusterma

    Thank you for the ideas. I am not new to java at all, and I do understand this is quite a large undertaking, but it will be a good challenge. I will look into both methods!

    @unrealdesign

    In your method, you are saying relay every event/method through my ccore plugin and with that check worlds, if the event isn't specific to a world make it global or return, and if the player is in a world and the plugin matches, my ccore plugin would relay the information back to my per world plugin? Like say it was a player move event. Ccore would intercept player move event, get player, find his world, and if the world is listed with a plugin, say UHC, it would go into the method on the plugin with the event data and execute like so? I believe that would work but want to see if that's what you were envisioning. Thanks for the help!
     
    mythbusterma likes this.
Thread Status:
Not open for further replies.

Share This Page