[New Coder]

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

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


    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;

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    Player player = (Player) sender;
    } else {
    player.sendMessage("[Hostel-Network] You Do Not Have Permission (HoselNetwork.Creative)");

    return false;


    Thanks in Advance.
  2. Offline


    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


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


    Example: [NOT TESTED]
    1. package com.ste.Help;
    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;
    11. public class Help extends JavaPlugin {
    13. public void onEnable() {
    14. Bukkit.getServer().getLogger().info("Help Enabled!");
    15. }
    17. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    19. Player p = (Player) sender;
    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. }
    32. }

    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);
Thread Status:
Not open for further replies.

Share This Page