Set Gamemode doesn't work?

Discussion in 'Plugin Development' started by maximumtech, May 20, 2012.

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

    maximumtech

    Okay, when I made a command, ((Player) sender).setGameMode(GameMode.CREATIVE);
    and vice versa, It doesn't set gamemode? I have the plugin.yml working, with the proper settings. My guess is that either depreciated or it doesn't work like that, the javadoc shed no insight. Help?

    Oh and, it seems the 10% won. :p
     
  2. Offline

    r0306

    maximumtech
    Try using this instead
    Code:
    Bukkit.getPlayer(sender).setGameMode(GameMode.CREATIVE);
     
  3. Offline

    Njol

    Can you please post the plugin.yml, the main class and the command executor (if it's not in your main class already)?
     
  4. Offline

    ImminentFate

    PHP:
    Player player = (Playersender;
    Gamemode gm player.getGameMode();
     
    If (
    gm = = GameMode.CREATIVE){
    player.setGameMode(GameMode.SURVIVAL);
     
    }Else If (
    gm = = GameMode.SURVIVAL){
    player.setGameMode(GameMode.CREATIVE);
    }
     
  5. Player player = (Player) Sender;
    ^^ error: Sender not reconised
    Gamemode gm = player.getGameMode();

    If (gm = GameMode.CREATIVE){
    ^^error, unknown key word: If, parsing as if
    ^^ You can't use an GameMode as an boolean
    player.setGameMode(GameMode.SURVIVAL);

    }Else If (gm = GameMode.SURVIVAL){
    ^^ Error: unknow keyword: Else
    ^^error, unknown key word: If, parsing as if
    ^^ You can't use an GameMode as an boolean
    player.setGameMode(GameMode.CREATIVE);
    }
     
  6. Offline

    CXdur

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player p = (Player) sender;
    if (p.getGameMode().equals(GameMode.CREATIVE)) {
    p.setGameMode(GameMode.SURVIVAL);
    } else if (p.getGameMode().equals(GameMode.SURVIVAL)) {
    p.setGameMode(GameMode.CREATIVE);
    return true;
    }
    return false;
    }
    return false;
    }
    }
    
     
  7. Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. Player p = (Player) sender;
    4. if (p.getGameMode().equals(GameMode.CREATIVE))
    5. {
    6. p.setGameMode(GameMode.SURVIVAL);
    7. }
    8. else if (p.getGameMode().equals(GameMode.SURVIVAL))
    9. {
    10. p.setGameMode(GameMode.CREATIVE);
    11. return true;
    12. }
    13. return false;
    14. }
    15. return false; // ????
    16. } // ????
    17. } // ????
     
  8. Offline

    ImminentFate

    make sure that you've added bukkit.jar as an external jar file. NOT craftbukkit.jar
    Other that that, i can't see why you're getting these errors.
     
  9. Offline

    r0306

    Make sure Sender is the correct case. Capitalization matters.
    Code:
    Player player = (Player) sender;
    As stated above, capitalization matters in Java! Change 'If' to 'if'.
    Also, you used one '=' You must use '==' instead.
    Code:
    if (gm == GameMode.CREATIVE){
    See above ^
    Code:
    }else if (gm == GameMode.SURVIVAL){
     
    ImminentFate likes this.
  10. Offline

    Assaru

    Hi Guys! I'm working on my plugin for personal use on my server that im gonna be using to prevent people to be able to transfer there items to the survival world, But the code doesn't work! main class(that's the only class in the plugin):
    package me.Assaru.Survivalplugin;

    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin {
    @Override
    public void onDisable() {
    System.out.println("Now enabled");

    }
    @Override
    public void onEnable() {
    System.out.println("Now disabled");
    }
    public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
    Player p = (Player) sender;
    if(commandlabel.equalsIgnoreCase("survive")) {
    String vem = p.getName();
    p.getInventory().setContents(null);
    p.getInventory().setArmorContents(null);
    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "warp hej " + vem);
    p.sendMessage("Hoj hoj");
    p.setGameMode(GameMode.SURVIVAL);
    }
    return true;
    }

    }
    plugin.yml file:
    name: Survivalplugin
    version: 0.1
    main: me.Assaru.Survivalplugin.main
    commands:
    survive:
    describtion: Let the survival adventure begin...
    usage: /survive
     
  11. Offline

    Vandrake

    1- on your enable you say its disabled and your disabled say its enabled?@.@ ????
    2 - replace warp hej with /warp hej ... watever that is :confused: << notice theres a little space in there after the hej so you can add the players name after it

    And btw Assaru ppl can just set home there and teleport to the creative world? I'm assuming you have one there?@.@
     
  12. Offline

    Assaru

    Thx Vandrake! I have a advanced permission system setup with modifyworld so it isn't possible. THANKS SO MUCH!!!
    sry for the fail(didn't notice that)
     
Thread Status:
Not open for further replies.

Share This Page