Solved <SOLVED> GameMode & WorldSettings Per World Please Help

Discussion in 'Spigot Plugin Development' started by Th3_DoC, Feb 6, 2020.

  1. I've scowered the internet and am about ready to start ripping multiverse code apart! There must be a fairly simple way to output and access the world properties at the very least? Or I would think anyways. I'm mainly attempting to set default gamemode per world in my plugin (without multiverse). Though in the coming future as I progress through my custom plugins I will need access to all world properties I am still learning bukkit and advanced java along the way and don't want to complicate things to much, I am a quick learner and good with logic so a quick explanation with any advanced java would be swell!. Any help is much appreciated thanks for taking the time to atleast read my issue :)
     
  2. Found it!
    You will have to get a handle to the NMS world thou
    Code (Java):
    net.minecraft.server.v1_14_R1.World world = ...;
    final WorldData data = world.getWorldData();
    final NBTTagCompound generatorOptions = data.getGeneratorOptions();
     
    Edit: You can easily set the difficulty using
    Code (Java):
    data.setGameType(EnumGameType);
    But couldn't you just set the gamemode in the server.properties?
     
  3. First off thanks for pointing me in the right direction...again :) I've not had time to-do any tinkering yet but i have a few questions for now and i'm sure i will sort it from there...I hope haha

    Doesn't server.properties only handle the main server world's ex. World, world_nether, and world_the_end? I'm after per world settings.
    Also if server.properties handles multiple world's does it handle setting these via plugin commands?

    I've not found any info on the web relating to these classes, how frustrating, but i found Bukkits GitHub in the process, nice juicy info there :) that said....

    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/World.java
    Code (Text):
    net.minecraft.server.v1_14_R1.World world = ...; //IT SEEMS THIS SHOULD ACCEPT A WORLD I ASSUME WE CAN
    ITERATE THROUGH OUR WORLD LIST getWorldData() & SAVE ALL WORLD SETTINGS TO .YML FOR EASY EDITING...
    BUT I AM THINKING IF WE ARE SETTING THESE IN GAME WHATS THE POINT IN THE .YML ? OR DO I NEED IT, THOUGHTS?
    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/WorldData.java
    Code (Text):
    final WorldData data = world.getWorldData();//FAIRLY EXPLANATORY GIVE IT OUR WORLD AND RECEIVE WORLD SETTINGS
    AND ACCESS TO SETTERS/GETTERS
    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/NBTTagCompound.java
    Code (Text):
    final NBTTagCompound generatorOptions = data.getGeneratorOptions();//THIS ONE HAS ME WONDERING THOUGH AS YOU
    DON'T CALL IT PER-SAY BUT AFTER A HEAVY LOOK AT THESE 3 PAGES I THINK YOU INTEND FOR ME TO PASS IT TO THE
    WorldData CLASS OR THIS WOULD BE USED IN CONJUNCTION WITH A GENERATOR CLASS PRIOR TO CREATING...OR FOR
    STORING THE OPTIONS FOR REFERENCE
    Curiously do you know if WorldData Class holds player inventory info in the playerData Variable?
     
    #3 Th3_DoC, Feb 7, 2020
    Last edited: Feb 7, 2020
  4. md_5

    Administrator Developer

    This is not even remotely the right direction.... analogs of both those methods are very clearly available in the World/WorldCreator API
    This is completely off track, look at the World and WorldCreator classes in the Javadoc https://hub.spigotmc.org/javadocs/spigot/
     
    • Useful Useful x 1

  5. I've now gone over the javadocs yet again and can find no reference in :
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/WorldCreator.html ||
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html
    about setting the GAMEMODE via either of these classes?

    However i did stumble accross the GameMode enum in the package org.bukkit:
    Code (Text):

    //with this i can set a variable as such
    final GameMode CREATIVE = GameMode.CREATIVE;
    //also i can set the game mode this way, i'm sure this sets the servers default though and i want PER WORLD SETTINGS.
    Bukkit.setDefaultGameMode();
    //or i can do it by player....
    player.setGameMode(GameMode.CREATIVE);
     
    I see options via the per player with checks for which world there in etc.....but this seems redundant to me, constantly checking player location via TeleportEvent/PortalEvent and i suppose this is how players will be sent there...is this how it should/needs to be done? or are there other options.....or am I way out to lunch lol. I feel as though we would be required to have a worlds.yml as multiverse does to save these "Per World" Settings...probably even need to save some playerData per world to achieve full functionality/seperate inventories etc.

    Thanks for the input @md_5 .
     
    #5 Th3_DoC, Feb 7, 2020
    Last edited: Feb 7, 2020
  6. md_5

    Administrator Developer

    The per world gamemode would have to be set on the PlayerWorldChangedEvent, the server does not switch players when they move across worlds by itself.
     
  7. *FacePalm* I wish i had seen that in the javadocs >.< thanks for the help !
     
  8. Wait where can I get a Handle to the WorldData and especially the generator-settings from in the API?
     
  9. md_5

    Administrator Developer

  10. md_5

    Administrator Developer

    http://xyproblem.info/

    You can't change it once generated, so why do you need access to it?
     
  11. Not for any specific problem. You said, however, that analogs to both of my methods exist. While I missed to see that for the game-mode (mostly because I have misunderstood the question), I was wondering what the analog for the first method was. Could be interesting, if one would want to know what kind of structures can spawn in the world (since canGenerateStructures seem to be pretty generic)
     
  12. md_5

    Administrator Developer

    generatorSettings is unfortunately rather opaque unless you parse it yourself, and there is practically zero documentation even on the MC Wiki about what it looks like in recent versions
     
    • Like Like x 1