Solved /hub plugin for BungeeCord won't work help

Discussion in 'BungeeCord Plugin Help' started by MaxTheSavageBear, Jun 14, 2019 at 8:16 PM.

  1. I think the topic sais it all, my code is here:
    Code (Java):

    package de.stephen.HubCommand.main;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.messaging.PluginMessageListener;


    public class Main extends JavaPlugin implements Listener{
     
       public void onEnable() {
              this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
               this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord",(PluginMessageListener) this);
               getCommand("hub").setExecutor(new command());
           Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
       }
       public class command extends Main implements CommandExecutor{
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {    
           if(sender instanceof Player) {
               Player p = (Player) sender;
           
                 ByteArrayOutputStream b = new ByteArrayOutputStream();
                 DataOutputStream out = new DataOutputStream(b);
                 try {
                   out.writeUTF("Connect");
                   out.writeUTF("lobby");
                 } catch (IOException e) {
                   e.printStackTrace();
                 }
                 p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
               }

               return true;
         
           }
       }
    }
    ------------------------------------------------------------------------------------------------------------------------------------------------
    log:
    Code (Text):

    [16:30:53] [Server thread/INFO]: Starting minecraft server version 1.12
    [16:30:53] [Server thread/WARN]: To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
    [16:30:53] [Server thread/INFO]: Loading properties
    [16:30:53] [Server thread/INFO]: Default game type: SURVIVAL
    [16:30:54] [Server thread/INFO]: This server is running CraftBukkit version git-Spigot-596221b-9a1fc1e (MC: 1.12) (Implementing API version 1.12-R0.1-SNAPSHOT)
    [16:30:54] [Server thread/INFO]: Debug logging is disabled
    [16:30:54] [Server thread/INFO]: Server Ping Player Sample Count: 12
    [16:30:54] [Server thread/INFO]: Using 4 threads for Netty based IO
    [16:30:54] [Server thread/INFO]: Generating keypair
    [16:30:54] [Server thread/INFO]: Starting Minecraft server on *:25566
    [16:30:54] [Server thread/INFO]: Using default channel type
    [16:30:54] [Server thread/INFO]: Set PluginClassLoader as parallel capable
    [16:30:54] [Server thread/INFO]: [HubCommand] Loading HubCommand vAlpha 0.1
    [16:30:54] [Server thread/INFO]: [PersonalMassage] Loading PersonalMassage v0.1
    [16:30:54] [Server thread/WARN]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
    [16:30:54] [Server thread/WARN]: The server will make no attempt to authenticate usernames. Beware.
    [16:30:54] [Server thread/WARN]: Whilst this makes it possible to use BungeeCord, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.
    [16:30:54] [Server thread/WARN]: Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.
    [16:30:54] [Server thread/WARN]: To change this, set "online-mode" to "true" in the server.properties file.
    [16:30:54] [Server thread/INFO]: **** Beginning UUID conversion, this may take A LONG time ****
    [16:30:54] [Server thread/INFO]: Preparing level "hub"
    [16:30:54] [Server thread/INFO]: -------- World Settings For [hub] --------
    [16:30:54] [Server thread/INFO]: Item Despawn Rate: 6000
    [16:30:54] [Server thread/INFO]: Item Merge Radius: 2.5
    [16:30:54] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [16:30:54] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [16:30:54] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [16:30:54] [Server thread/INFO]: Experience Merge Radius: 3.0
    [16:30:54] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [16:30:54] [Server thread/INFO]: View Distance: 10
    [16:30:54] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Cane Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Melon Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: NetherWart Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Vine Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Cocoa Growth Modifier: 100%
    [16:30:54] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [16:30:54] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [16:30:54] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 1 Hopper Amount: 1
    [16:30:54] [Server thread/INFO]: Random Lighting Updates: false
    [16:30:54] [Server thread/INFO]: Structure Info Saving: true
    [16:30:54] [Server thread/INFO]: Max TNT Explosions: 100
    [16:30:54] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [16:30:54] [Server thread/INFO]: Mob Spawn Range: 4
    [16:30:54] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617 Monument: 10387313 Slime: 987234911
    [16:30:55] [Server thread/INFO]: -------- World Settings For [hub_nether] --------
    [16:30:55] [Server thread/INFO]: Item Despawn Rate: 6000
    [16:30:55] [Server thread/INFO]: Item Merge Radius: 2.5
    [16:30:55] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [16:30:55] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [16:30:55] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [16:30:55] [Server thread/INFO]: Experience Merge Radius: 3.0
    [16:30:55] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [16:30:55] [Server thread/INFO]: View Distance: 10
    [16:30:55] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Cane Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Melon Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: NetherWart Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Vine Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Cocoa Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [16:30:55] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [16:30:55] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 1 Hopper Amount: 1
    [16:30:55] [Server thread/INFO]: Random Lighting Updates: false
    [16:30:55] [Server thread/INFO]: Structure Info Saving: true
    [16:30:55] [Server thread/INFO]: Max TNT Explosions: 100
    [16:30:55] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [16:30:55] [Server thread/INFO]: Mob Spawn Range: 4
    [16:30:55] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617 Monument: 10387313 Slime: 987234911
    [16:30:55] [Server thread/INFO]: -------- World Settings For [hub_the_end] --------
    [16:30:55] [Server thread/INFO]: Item Despawn Rate: 6000
    [16:30:55] [Server thread/INFO]: Item Merge Radius: 2.5
    [16:30:55] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [16:30:55] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [16:30:55] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [16:30:55] [Server thread/INFO]: Experience Merge Radius: 3.0
    [16:30:55] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [16:30:55] [Server thread/INFO]: View Distance: 10
    [16:30:55] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Cane Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Melon Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: NetherWart Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Vine Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Cocoa Growth Modifier: 100%
    [16:30:55] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [16:30:55] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [16:30:55] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 1 Hopper Amount: 1
    [16:30:55] [Server thread/INFO]: Random Lighting Updates: false
    [16:30:55] [Server thread/INFO]: Structure Info Saving: true
    [16:30:55] [Server thread/INFO]: Max TNT Explosions: 100
    [16:30:55] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [16:30:55] [Server thread/INFO]: Mob Spawn Range: 4
    [16:30:55] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617 Monument: 10387313 Slime: 987234911
    [16:30:55] [Server thread/INFO]: Preparing start region for level 0 (Seed: -7460576736882053312)
    [16:30:55] [Server thread/INFO]: Preparing start region for level 1 (Seed: 825876375340051097)
    [16:30:56] [Server thread/INFO]: Preparing start region for level 2 (Seed: 825876375340051097)
    [16:30:57] [Server thread/INFO]: [HubCommand] Enabling HubCommand vAlpha 0.1
    [16:30:57] [Server thread/ERROR]: Error occurred while enabling HubCommand vAlpha 0.1 (Is it up to date?)
    java.lang.ClassCastException: de.stephen.HubCommand.main.Main cannot be cast to org.bukkit.plugin.messaging.PluginMessageListener
       at de.stephen.HubCommand.main.Main.onEnable(Main.java:20) ~[?:?]
       at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:374) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:323) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    [16:30:57] [Server thread/INFO]: [PersonalMassage] Enabling PersonalMassage v0.1
    [16:30:57] [Server thread/INFO]: Hallo, willkommen zurück auf deinem SPIGOT 1.12 Server!
    [16:30:57] [Server thread/WARN]: Could not register alias hub because it contains commands that do not exist: server lobby
    [16:30:57] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [16:30:57] [Server thread/INFO]: Done (2,386s)! For help, type "help" or "?"
    [16:31:05] [Server thread/INFO]: Stopping the server
    [16:31:05] [Server thread/INFO]: Stopping server
    [16:31:05] [Server thread/INFO]: [PersonalMassage] Disabling PersonalMassage v0.1
    [16:31:05] [Server thread/INFO]: Auf wiedersehen, bis zum nächsten mal
    [16:31:05] [Server thread/INFO]: [HubCommand] Disabling HubCommand vAlpha 0.1
    [16:31:05] [Server thread/INFO]: Saving players
    [16:31:05] [Server thread/INFO]: Saving worlds
    [16:31:05] [Server thread/INFO]: Saving chunks for level 'hub'/overworld
    [16:31:06] [Server thread/INFO]: Saving chunks for level 'hub_nether'/the_nether
    [16:31:06] [Server thread/INFO]: Saving chunks for level 'hub_the_end'/the_end
     
     
    #1 MaxTheSavageBear, Jun 14, 2019 at 8:16 PM
    Last edited: Jun 14, 2019 at 9:42 PM
  2. Looks like you meant to implement PluginMessageListener (org.bukkit.plugin.messaging) rather than Listener (org.bukkit.event)
     
  3. Sorry, I'm new in coding, but when i do that
    Code (Java):
    package de.stephen.HubCommand.main;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.messaging.PluginMessageListener;


    public class Main extends JavaPlugin implements PluginMessageListener{
     
        public void onEnable() {
               this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
                this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord",(PluginMessageListener) this);
                getCommand("hub").setExecutor(new command());
            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        }
        public class command extends Main implements CommandExecutor{
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {      
            if(sender instanceof Player) {
                Player p = (Player) sender;
             
                  ByteArrayOutputStream b = new ByteArrayOutputStream();
                  DataOutputStream out = new DataOutputStream(b);
                  try {
                    out.writeUTF("Connect");
                    out.writeUTF("lobby");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
                }

                return true;
           
            }
        }
        [USER=32110]@Override[/USER]
        public void onPluginMessageReceived(String arg0, Player arg1, byte[] arg2) {
            // TODO Auto-generated method stub
         
        }
    }
    I get the error
    Code (Text):

    [22:12:17] [Server thread/ERROR]: Error occurred while enabling HubCommand vAlpha 0.1 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at de.stephen.HubCommand.main.Main.<init>(Main.java:15) ~[?:?]
        at de.stephen.HubCommand.main.Main$command.<init>(Main.java:23) ~[?:?]
        at de.stephen.HubCommand.main.Main.onEnable(Main.java:20) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:374) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:323) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at de.stephen.HubCommand.main.Main.<init>(Main.java:15) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_201]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_201]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_201]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:326) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:298) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        ... 2 more
     
    #3 MaxTheSavageBear, Jun 14, 2019 at 9:15 PM
    Last edited: Jun 14, 2019 at 9:41 PM
  4. I'm not sure why you're extending main here, but what's happening is you now have two classes that Spigot identifies as plugins in the same .jar file which causes Spigot to be confused. Don't extend main here.

    Edit: in the future use code tags please.
     
    #4 AlanZ, Jun 14, 2019 at 9:22 PM
    Last edited: Jun 14, 2019 at 9:30 PM
  5. I was extending Main because I have tried pretty much everything, when I not extend Main on the
    class command, I get the error
    Code (Text):
    <[22:30:03] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'hub' in plugin HubCommand vAlpha 0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1385) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1220) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_201]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_201]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.ClassCastException: de.stephen.HubCommand.main.Main$command cannot be cast to org.bukkit.plugin.Plugin
        at de.stephen.HubCommand.main.Main$command.onCommand(Main.java:37) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        ... 15 more
    I found something on internet, that you have to get the lines
    Code (Java):
    <
               this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
                this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord",(PluginMessageListener) this);
    into the class where you use
    Code (Java):
    <p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
    but to do this I have to extend the class "command" with JavaPlugin, wich also has to be in Main, so when I extend "command" with JavaPlugin I get an Error with something like "Plugin already initialized".......
     
  6. Which one is line 37?
    You have to reference main, not this in this line:
    Code (Java):
    p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
     
  7. BTW, when I just remove the
    Code (Java):
    extends Main
    it does this: code.png

    so I have to transform it into
    Code (Java):
    p.sendPluginMessage((Plugin) this, "BungeeCord", b.toByteArray());
    and the it just sais
    Code (Text):
    command cannot be cast to org.bukkit.plugin.Plugin
    ...
     
  8. Yeah you shouldn't use this there, you should use a reference to main there.
     
  9. How do you mean? like put the line up to Main? but then i woud have to put
    Code (Java):

        if(sender instanceof Player) {
                Player p = (Player) sender;
     
    into Main as well?
     
  10. Directly under
    Code (Java):
    public class command implements CommandExecutor{
    put
    Code (Java):

    Main main;
    command(Main main) {
    this.main = main;
    }
    Then replace
    Code (Java):
    p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
    with
    Code (Java):
    p.sendPluginMessage(main, "BungeeCord", b.toByteArray());
    Edit: It's also recommended that you use camel case (MyCoolClass) rather than lowercase or anything else. So your class "command" would become "Command"
     
    #10 AlanZ, Jun 14, 2019 at 10:03 PM
    Last edited: Jun 14, 2019 at 10:31 PM
  11. ok, thank you for your patience, but now there arre more problems, this is driving me crazy... so when I do exactly what you said my code looks like that
    Code (Java):

    package de.stephen.HubCommand.main;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import org.bukkit.Bukkit;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.messaging.PluginMessageListener;


    public class Main extends JavaPlugin implements PluginMessageListener{
       
        public void onEnable() {
               this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
                this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord",(PluginMessageListener) this);
                getCommand("hub").setExecutor(new Command(null));
            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        }
        public class Command implements CommandExecutor{
            Main main;
            Command(Main main) {
            this.main = main;
            }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {      
            if(sender instanceof Player) {
                Player p = (Player) sender;
                  ByteArrayOutputStream b = new ByteArrayOutputStream();
                  DataOutputStream out = new DataOutputStream(b);
                  try {
                    out.writeUTF("Connect");
                    out.writeUTF("lobby");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  p.sendPluginMessage(main, "BungeeCord", b.toByteArray());
                }

                return true;
             
            }
        }
    }
     
    but now it sais :
    code2.png

    for booth classes, when I add the unimplemented methods, it just creates the empty methods:
    Code (Java):

    package de.stephen.HubCommand.main;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import org.bukkit.Bukkit;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.messaging.PluginMessageListener;


    public class Main extends JavaPlugin implements PluginMessageListener{
       
        public void onEnable() {
               this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
                this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord",(PluginMessageListener) this);
                getCommand("hub").setExecutor(new Command(null));
            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        }
        public class Command implements CommandExecutor{
            Main main;
            Command(Main main) {
            this.main = main;
            }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {      
            if(sender instanceof Player) {
                Player p = (Player) sender;
                  ByteArrayOutputStream b = new ByteArrayOutputStream();
                  DataOutputStream out = new DataOutputStream(b);
                  try {
                    out.writeUTF("Connect");
                    out.writeUTF("lobby");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  p.sendPluginMessage(main, "BungeeCord", b.toByteArray());
                }

                return true;
             
            }
        @Override
        public boolean onCommand(CommandSender arg0, org.bukkit.command.Command arg1, String arg2, String[] arg3) {
            // TODO Auto-generated method stub
            return false;
        }
        }
        @Override
        public void onPluginMessageReceived(String arg0, Player arg1, byte[] arg2) {
            // TODO Auto-generated method stub
           
        }
    }
     
    I don't realy know what to type in these methods and when I export it, there are no errors in the server console but I can type in the command without any problems, it just don't reacts to it.

    (sorry if my english is bad i'm from germany)
     
  12. Move all of your code from your onCommand method to the one it made for you. Now that your class is named Command it clashes with the org.bukkit Command class. I forgot about that happening. The auto-generated one references the class Command directly so to not cause that problem.
     
  13. 1st I still got the problem with the unimplemented stuff and 2nd problem is that putting all the code into the class makes no sense in my oppinion because the class can be named enything and also now (marked as a 2) the programm doesnt even know what I mean by sender because "sender" was in the method "onCommand".. So yeah of cause I am new and thats why im in this forum, so I'm realy happy if you could explain that. :)
    code3.png
     
  14. I meant use the add unimplemented methods, then put that code into the newly generated onCommand method. Blank methods aren't necessarily a bad thing.
     
  15. ooh now I know what you mean..
    Code (Java):

    package de.stephen.HubCommand.main;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import org.bukkit.Bukkit;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.messaging.PluginMessageListener;


    public class Main extends JavaPlugin implements PluginMessageListener{
       
        public void onEnable() {
               this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
                this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord",(PluginMessageListener) this);
                getCommand("hub").setExecutor(new Command(null));
            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        }
        public class Command implements CommandExecutor{
            Main main;
            Command(Main main) {
            this.main = main;
            }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {      
                return true;
             
            }
        @Override
        public boolean onCommand(CommandSender sender, org.bukkit.command.Command arg1, String arg2, String[] arg3) {
            if(sender instanceof Player) {
                Player p = (Player) sender;
                  ByteArrayOutputStream b = new ByteArrayOutputStream();
                  DataOutputStream out = new DataOutputStream(b);
                  try {
                    out.writeUTF("Connect");
                    out.writeUTF("lobby");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  p.sendPluginMessage(main, "BungeeCord", b.toByteArray());
                }

            return false;
        }
        }
        @Override
        public void onPluginMessageReceived(String arg0, Player arg1, byte[] arg2) {
            // TODO Auto-generated method stub
           
        }
    }
     
    BUT when i do this i get:
    Code (Text):

    org.bukkit.command.CommandException: Unhandled exception executing command 'hub' in plugin HubCommand vAlpha 0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1385) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1220) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_201]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_201]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.IllegalArgumentException: Plugin source cannot be null
        at org.bukkit.plugin.messaging.StandardMessenger.validatePluginMessage(StandardMessenger.java:473) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer.sendPluginMessage(CraftPlayer.java:1078) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at de.stephen.HubCommand.main.Main$Command.onCommand(Main.java:55) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        ... 15 more
     
    I think I would have to change something in
    Code (Java):

                getCommand("hub").setExecutor(new Command(null));
     
    but I tried a few things and everything just gives me errors so if I type
    Code (Java):

                getCommand("hub").setExecutor(new Command(Command));
     
    or
    Code (Java):

                getCommand("hub").setExecutor(new Command(Main));
     
    or something else it just sais "... can not be resolved as a variable" so do I have to assign my Command class to a variable? if yes how do i do that and if no what else could I do?
     
  16. You do "new Command(this)". Sorry, forgot that part.
     
    • Like Like x 1
  17. OH MAN thank you so much, finaly got it to work, I want to add more commands into the Main package but as different class names so for example the class Command was the /hub command, will it work if I just do the same thing with for example "Command2" as i did with Command so like creating these 2 classes and putting
    Code (Java):

            Main main;
            Command2(Main main) {
            this.main = main;
     
    right after the class begins?
     
  18. BUt yeah that's another topic i`'m just gonna try so THANK YOU VERY MUCH (y)
     
  19. Yep, pretty much. You'll probably want to split the classes into different files though, like Main.java, HubCommand.java, SurvivalCommand.java, etc.
     
  20. No problem, don't forget to mark this thread as solved! :)
     

Share This Page