my /hub plugin has a problem

Discussion in 'Plugin Development' started by evanog, Nov 3, 2015.

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

    evanog

    Ok so i made a /hub plugin. It also has /sethub. When i install, i go ingame and do /sethub and i can do /hub to go there. Problem is after every restart, i cant do /hub anymore and have to do /sethub again. Can anyone help? my code can be found here: http://pastebin.com/nujAnc28
     
  2. Offline

    Zombie_Striker

    getConfig().options().copyDefaults(true);

    This is your problem I think. Just check if the config is blank (or does not have a path that it should) before applying this. If is not blank (has something in it), then don;t use it.
     
  3. Offline

    evanog

    When my config generates, it generates with X,Y,and Z values. I just don't understand why after every restart I have to set the hub again because maybe those values from before the restart get deleted? Also I have tried removing the code above and I still got the same problem. I'm just really confused.
     
  4. Offline

    CrystalxNeth

    EDIT: Do what the other person said, I was wrong^
     
    Last edited: Nov 3, 2015
  5. Offline

    Zombie_Striker

    THIS IS YOUR PROBLEM. THIS IS WHY YOU HAVE TO RESET IT.
     
  6. Offline

    evanog

    I removed the code and the same thing happens. The config file isn't generated until I set hub in game and I looked in the config right after a restart and it was empty. There had to be a simple fix :(
     
  7. Offline

    RoboticPlayer

    Replace
    getConfig().options().copyDefaults(true);
    saveConfig();
    with
    saveDefaultConfig();
     
  8. Offline

    evanog

    Still resets the location after restart :( . After restart when i do /hub it says an internal error has occured until i set the hub.
     
  9. Offline

    mythbusterma

    @evanog

    Probably a NullPointerException. Just a guess. Look in your console.
     
  10. Offline

    evanog

    ok how can i fix if that is the probably and i think you are right
     
  11. Offline

    mythbusterma

    @evanog

    Something is null, make it not null.
     
  12. Offline

    evanog

    UPDATE:: I looked in the console and recieve a huge error u can see it here: http://pastebin.com/CN8SAu5Y
     
  13. Offline

    mythbusterma

    @evanog

    Well you didn't include the useful part of that error...
     
  14. Offline

    evanog

    Whenever i type /hub in chat and look it in console it says NullPointerException in console
     
  15. Offline

    Zombie_Striker

    @evanog
    Here's a hint: Nullcheck. That should be all I have to say in order for you to understand what you need to do.
     
  16. Offline

    evanog

    if (myVar != null) { << that after my code right?
     
  17. Offline

    Zombie_Striker

    @evanog
    Not after, before the code. You don't want to use anything that is null.
     
  18. Offline

    Scimiguy

    Try it

    Surprisingly, you'll learn a lot more from trying things out than asking here every step
     
    CrystalxNeth likes this.
  19. Offline

    evanog

    Thanks guys i'll expermiment!

    Ok so I completely recoded the plugin and now i have a different problem. /sethub command works, but when i do /hub, nothing happens. I feel like I may have forgotten something. I've tried everything I know to do and for some reason /hub command dosent work. pastebin: http://pastebin.com/EwpZRXum

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 4, 2015
  20. Offline

    Scimiguy

    @evanog
    Because you have an extra curly brace here:
    ("sethub")){{if(p.hasPermission("H

    Line 38
     
  21. Offline

    CrystalxNeth

    Your code could use a nice CTRL+SHIFT+F in eclipse too
     
  22. Offline

    RoboticPlayer

    A) onEnable and onDisable can be overridden
    B) No need for enabling/disabling messages, Bukkit already does this
    C) Because of B, no need for an onDisable method at all in this case
    D) You can merge all of your PlayerJoinEvents into one, you don't need a separate event for everything you do
    E) onCommand can be overridden
    F) Check before casting sender to player
    G) In your sethub command, you say something about arguments if they don't have the proper permission, yet your code says nothing about arguments
    H) You never save the hub location to your config with your sethub command
    I) I would recommend you teleport the player to the coordinates in the config instead of the world's spawn location
    J) Returning false says that the occurrence was not handled, and will return the usage from the plugin.yml
     
  23. Offline

    evanog

    Ok so recoded my plugin again and everything works fine. Except 1 thing. I am trying to give them potion effects in the hub, and then make them loose the effects when the go to another world. Im not sure how to do this. I also want them to spawn on join which explains the join event. Can someone help me with this? my code is at: http://pastebin.com/fr51yx0N
     
  24. Offline

    Scimiguy

    @evanog
    Listen to the PlayerChangedWorldEvent, using Event#getTo() to check the world they're going to

    If it's not the hub world, then loop through the player's potion effects and remove them, ala

    Code:
                  for (PotionEffect effect : p.getActivePotionEffects()) {
                      p.removePotionEffect(effect.getType());
                    }
     
  25. Offline

    evanog

    Ill try and let you know thanks!

    Ok so would this code work? Im really confused.

    Code:
        @EventHandler
        public void onplayerchange(PlayerChangedWorldEvent event) {
            Player p = event.getPlayer();
            if (event.getPlayer().getLocation().getWorld().getName().endsWith("world");
                for (PotionEffect effect : p.getActivePotionEffects()) {
                    p.removePotionEffect(effect.getType());
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 6, 2015
  26. Offline

    Scimiguy

    Give it a go, see if it works

    A large part of programming is solving problems.
    We can't solve them all for you ;)
     
Thread Status:
Not open for further replies.

Share This Page