Is there an action like player.switchWorlds

Discussion in 'Plugin Development' started by xpaintall, Oct 8, 2020.

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

    xpaintall

    Hi, i just started coding plugins a few days ago. I understood all of the basics, like events and how to make a custom command. So here it goes: my friend, an owner of a server asked me to make him a /hub command (teleports you to the lobby after you execute it). Now, i thought it was easy but it doesn't seem that i can find an action like player.switchWorlds("name" location) coz my friend uses multiverse. Now i am thinking, i could just use the multiverse api but i cannot anywhere on the internet and ifi actually found something, none of the links don't work. Please help idk what to do now.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @xpaintall You just teleport them to the different world.
     
  3. Offline

    KarimAKL

    @xpaintall There's no need to have a Player#switchWorld(World, Location) method, as Location already includes a world, so you can just do Player#teleport(Location).
     
  4. Offline

    xpaintall

    @KarimAKL yes i know, but when i try to do that it says "cannot resolve symbol 'worldname' "
     
  5. Offline

    KarimAKL

  6. Offline

    xpaintall

    @KarimAKL let me write:
    Code:
    package com.xpaintall.Hub.command;
    
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class HubCommand implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if (!(sender instanceof Player)) {
                return true;
            }
            Player p = (Player) sender;
    
            if (cmd.getName().equalsIgnoreCase("hub")) {
                World survivallobby = null;
                Location location = new Location(survivallobby, 57, 5, 9);
                    p.teleport(location);
                    p.sendMessage("§7[§aBattleFighters§7] §7Teleporting to hub");
                return true;
            }
            return true;
        }
    }
    
    What's wrong and why is it not loading in the console (the plugin)
     
    Last edited: Oct 9, 2020
  7. Offline

    KarimAKL

    The world is null. You have to get it using Bukkit#getWorld("worldName").
     
  8. Offline

    spuddy

    Another approach is to have a command such as /sethub which sets your Hub location to the point and world the player is standing when they execute the command, you can do that simply by saving the player's location player.getLocation().clone() to a class field or global. The advantage to that is it also records the orientation of the player as well, so when people arrive at the hub, they're looking in a particular direction. Be wary of config though, if your plugin is loaded before your world manager it will throw an exception if the Hub world is not initialized when it tries to get the Location object out of the config. If that's the case you could set the Hub world to be the main world, set a "softdepend: [Multiverse-Core] " (or whatever world manager you're using) in the plugin.yml or defer your plugin initialization using the ServerLoadEvent.
     
  9. Offline

    xpaintall

    @spuddy that is interesting, but i know i can save the pitch and the horizontal head rotation with the teleport method, because i don't use any world manager plugin even tho i should. Can u recommend some coz i cannot seem to find the multiverse api anywhere on the internet. I am making this plugin for only my friend, so i won't make any config so that is making it easier. Also, why is it not loading in the console and in the plugins list? (The plugin)
     
    Last edited: Oct 9, 2020
  10. Offline

    Xp10d3

    Did you register you commands class in your main?
     
  11. Offline

    xpaintall

    yeah, @Xp10d3
    Code:
    package com.xpaintall.Hub;
    
    import org.bukkit.command.CommandExecutor;
    import com.xpaintall.Hub.events.Events;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import sun.applet.Main;
    
    public class MainHub extends JavaPlugin {
    
    
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(new Events(), this);
            getCommand("hub").setExecutor(new MainHub());
            getServer().getConsoleSender().sendMessage("§bMctall: Plugin loading!");
        }
    
    
        @Override
        public void onDisable() {
            getServer().getConsoleSender().sendMessage("§bMctall: Plugin closed!");
        }
    
    
    
    }
    
    but i get this error in the console:
    Code:
    [19:25:27 ERROR]: Error occurred while enabling Hub v1.0.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at com.xpaintall.Hub.MainHub.<init>(MainHub.java:9) ~[?:?]
            at com.xpaintall.Hub.MainHub.onEnable(MainHub.java:15) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [server.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_261]
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at com.xpaintall.Hub.MainHub.<init>(MainHub.java:9) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_261]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_261]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_261]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_261]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_261]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) ~[server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:739) ~[server.jar:git-Spigot-db6de12-18fbb24]
            ... 10 more
    what does that mean?
     
    Last edited by a moderator: Oct 20, 2020
  12. Offline

    timtower Administrator Administrator Moderator

    @xpaintall Don't call "new MainHub()", use "this" instead
     
  13. Offline

    xpaintall

    Thank you, finally got it working and i added some extra stuff.

    Ty a lot!
     
  14. Offline

    Strahan

    You shouldn't be embedding the color character; you should use the ChatColor enum. For a String with only one or two instances of colors, I typically insert it directly like ChatColor.RED or whatever. If it has a lot of formatting, ChatColor has a translateAlternateColorCodes method to allow for swapping a custom character for the color char (like &).
     
Thread Status:
Not open for further replies.

Share This Page