[New Coder]

Discussion in 'Plugin Development' started by HostelCraft, Feb 25, 2014.

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

    HostelCraft

    Hey i am working on my server (new) called Hostel-Network and i am working on the Core plugin and i am stuck on the part with the changing the gamemode in the command executor class here is the GameModeCreative class:

    package HostelGamer.HostelNetworkCore;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class GameModeCreatetive implements CommandExecutor
    {
    private Main plugin;

    public void GameModeCreative(Main plugin)
    {
    this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    {
    Player player = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("Creative")){
    if(player.hasPermission("HostelNetwork.Creative")){
    player.getGameMode().CREATIVE.
    } else {
    player.sendMessage("[Hostel-Network] You Do Not Have Permission (HoselNetwork.Creative)");
    }
    }

    return false;

    }
    }




    Thanks in Advance.
     
  2. Offline

    NathanWolf

    Try player.setGameMode(GameMode.CREATIVE)

    Oh, and inside the "if" that is checking for your command, return true so Bukkit knows you handled that command.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
    thomasb454 and Garris0n like this.
  3. Offline

    HostelCraft

    Ahhh okay thanks mate i was stuck for like 30 minutes looking on diferent websites on this.
     
  4. Offline

    badboystee

    Example: [NOT TESTED]
    Code:java
    1. package com.ste.Help;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.GameMode;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Help extends JavaPlugin {
    12.  
    13. public void onEnable() {
    14. Bukkit.getServer().getLogger().info("Help Enabled!");
    15. }
    16.  
    17. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    18.  
    19. Player p = (Player) sender;
    20.  
    21. if(cmd.getName().equalsIgnoreCase("Creative")) {
    22. if(p.hasPermission("HostelNetwork.Creative")) {
    23. p.setGameMode(GameMode.CREATIVE);
    24. } else {
    25. p.sendMessage(ChatColor.RED + "You Don't Have Permission BOY!");
    26. }
    27. }
    28. return true;
    29. }
    30.  
    31.  
    32. }
    33.  


    EDIT: I added a ChatColor in and changed Player player to Player p = (Player) sender; :)
    EDIT#2: I changed it all up a bit. So it's different but does what yours does
    EDIT#3: Added return true; so Bukkit knows that you have done the command :)
    EDIT#4: Easy way I think compared to yours but we all have our difference in coding :p
     
  5. Try using setGameMode.(GameMode.CREATIVE);
    :D
     
Thread Status:
Not open for further replies.

Share This Page