How do you make a spawn plugin with /RELOAD fix?

Discussion in 'Plugin Development' started by Reshunboy, May 8, 2014.

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

    Reshunboy

    So I was wondering how you made that ^,
    I couldn't find something on the internet soooooo,
    this is the code I already have:


    Code:
    package me.Reshunboy;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Hub extends JavaPlugin {
       
        public final Logger logger = Logger.getLogger("Minecraft");
       
       
        @Override
        public void onEnable() {
     
        }
       
        @Override
        public void onDisable() {
     
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
         
            if(commandLabel.equalsIgnoreCase("sethub") && sender instanceof Player){
     
                this.getConfig().set("Hub" + ".X", player.getLocation().getBlockX());
                this.getConfig().set("Hub" + ".Y", player.getLocation().getBlockY());
                this.getConfig().set("Hub" + ".Z", player.getLocation().getBlockZ());
                this.getConfig().set("Hub" + ".Yaw", player.getLocation().getYaw());
                this.getConfig().set("Hub" + ".Pitch", player.getLocation().getPitch());
                this.getConfig().set("Hub" + ".World", player.getLocation().getWorld());
               
                player.sendMessage(ChatColor.GREEN + "Hub set!");
                return true;
            }
           
            if(commandLabel.equalsIgnoreCase("hub") && sender instanceof Player){
                int hubX = this.getConfig().getInt("Hub" + ".X");
                int hubY = this.getConfig().getInt("Hub" + ".Y");
                int hubZ = this.getConfig().getInt("Hub" + ".Z");
                int hubYaw = this.getConfig().getInt("Hub" + ".Yaw");
                int hubPitch = this.getConfig().getInt("Hub" + ".Pitch");
                Object world = this.getConfig().get("Hub" + ".World");
             
                Location hub = new Location((World) world, hubX, hubY, hubZ, hubYaw, hubPitch);
             
                player.teleport(hub);
             
                player.sendMessage(ChatColor.GREEN + "Returning to hub!");
                return true;
            }
            return false;
    }
    }
     
  2. If there's an error, that would be useful.
    I recommend using:
    Code:
    Bukkit.getWorld(world)
    instead of
    Code:
    (World) world
    (since the name 'world' isn't a world object, it's merely a string).
     
  3. Offline

    Mayoz

    What exactly needs fixing other than what DJSkepter said... What's going wrong? Also why do you do "Hub" + ".X" instead of just "Hub.X"? It's just a pointless waste.
     
    DJSkepter likes this.
  4. Offline

    Anonymous350

    Reshunboy

    Please look into this and learn from it. It's a shorter and better way of your code.
    --
    YOU DON'T NEED TO CREATE A CONFIG FOR THIS CODE
    --

    Code:java
    1. if(p.isOp()) {
    2. if (label.equalsIgnoreCase("sethub")) {
    3. getConfig().set("hub.world", p.getLocation().getWorld().getName());
    4. getConfig().set("hub.x", p.getLocation().getX());
    5. getConfig().set("hub.y", p.getLocation().getY());
    6. getConfig().set("hub.z", p.getLocation().getZ());
    7. getConfig().get("hub.pitch", p.getLocation().getPitch());
    8. getConfig().get("hub.yaw", p.getLocation().getYaw());
    9. saveConfig();
    10. reloadConfig();
    11. p.sendMessage(this.prefix + ChatColor.GREEN + "Hub has been set!");
    12. return true;
    13.  
    14. if (label.equalsIgnoreCase("hub") {
    15. if (getConfig().getConfigurationSection("hub") == null) {
    16. p.sendMessage(this.prefix + ChatColor.GREEN + "The " + ChatColor.RED + "Hub" + ChatColor.GREEN + " has not been set!");
    17. return true;
    18.  
    19. }
    20. World w = Bukkit.getServer().getWorld(getConfig().getString("hub.world"));
    21. double x = getConfig().getDouble("hub.x");
    22. double y = getConfig().getDouble("hub.y");
    23. double z = getConfig().getDouble("hub.z");
    24. Location hub = new Location(w, x, y, z);
    25. hub.setPitch((float) getConfig().getDouble("hub.pitch"));
    26. hub.setYaw((float) getConfig().getDouble("hub.yaw"));
    27. p.teleport(hub);
    28. p.sendMessage(this.prefix + ChatColor.GREEN + "Welcome to the Hub!");
    29. return true;


    - P.S - I never fixed getting the Yaw/Pitch.
     
  5. Offline

    coasterman10

    Other than that I can see you copy too much from BcBroz, I can't really tell what's wrong since you haven't told us what isn't working. Could you explain what isn't working or what you want to do?
     
  6. Offline

    Reshunboy

    Thanks! It worked :D
     
Thread Status:
Not open for further replies.

Share This Page