(SOLVED) Plugin On/Off Command

Discussion in 'Plugin Development' started by Rex285, May 17, 2014.

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

    Rex285

    I created a plugin and I'm curious on how to make a command that would disable the plugin. IE: (/thisplugin on) (/thisplugin off) Thanks!
     
  2. Offline

    RawCode

    post code
     
  3. Offline

    Rex285

    RawCode

    PlayerListener
    Code:java
    1. package me.sphiinx;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.PlayerDeathEvent;
    7.  
    8. public class PlayerListener implements Listener {
    9.  
    10. public PlayerListener(DeathCoords plugin) {
    11. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    12.  
    13. }
    14.  
    15. @EventHandler
    16. public void onPlayerDeath(PlayerDeathEvent event) {
    17.  
    18. int x = (int) event.getEntity().getLocation().getX();
    19. int y = (int) event.getEntity().getLocation().getY();
    20. int z = (int) event.getEntity().getLocation().getZ();
    21. event.setDeathMessage(ChatColor.GREEN + "Death Coordinates: " + ChatColor.RED + "X: " + x + " Y: " + y + " Z: " + z);
    22. }
    23.  
    24. }
    25.  
     
  4. Offline

    RawCode

    i see zero attempts to implement commands you want.

    if you want someone to write plugin for you - visit plugin request section.
     
  5. Offline

    Rex285

    RawCode
    I'm asking how to... I never said I knew anywhere to start. I have no Idea on how to do it, that's why I'm asking here because i'd like to learn....


    Here is my DeathCoords.java if you need that too....
    Code:java
    1. package me.sphiinx;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class DeathCoords extends JavaPlugin {
    6.  
    7. @Override
    8. public void onEnable() {
    9. getLogger().info("This was created by Sphiinx of VaultCraft Visit Vaultdarkrp.com for info or contact me @ [email][email protected][/email]");
    10. new PlayerListener(this);
    11. }
    12.  
    13. @Override
    14. public void onDisable() {
    15.  
    16. }
    17.  
    18. }
    19.  
     
  6. Offline

    coasterman10

    Create a boolean value that represents whether it is enabled or not. Then, check this value to determine whether to run your event code. You can for example create a public boolean in your main class:
    Code:java
    1. public boolean enabled = true;

    And then, in your event:
    Code:java
    1. if (plugin.enabled) {
    2. // Plugin is enabled
    3. }
     
  7. Offline

    Rex285

    coasterman10
    How would this add a command ingame that would enable/disable the plugin? Thanks for the help!
     
  8. Offline

    Gater12

    Rex285
    You would have to make that. Make a command and check the arguments. Set the Boolean value relative to the argument.
     
  9. Offline

    tryy3

  10. Offline

    Rex285

    tryy3
    Thanks! I like how the other people think I know how to do what they're saying. When they help someone they need to make it easier for someone to understand than what they understand in their own terms.
     
  11. Offline

    Gater12

    Rex285
    Usually, I expect developers posting here to know at least some basic knowledge of Java and the Bukkit API. Other developers helping have their own expectations, also.
    You should state specifically what you want to do, what you don't know (Anything even remotely relative to your problem), what you know, and what you have. That way, IMO, is the best way I can help you!
     
  12. Offline

    Rex285


    I have one more question. I know how to make permissions for a specific command but is it possible to make permissions for a plugin in general? For example the plugin I have made has no command but how would I make it so the plugin will only work on the player if the player has the permission?
     
  13. Offline

    Gater12

    Rex285
    Check if the player has permission before executing the functions!

    Code:java
    1. if(player.hasPermission("insert.le.permission.node")){
    2. /* Player has permission so run code for them */
    3. }
     
  14. Offline

    Rex285

    Gater12

    Where would I put that line of code? xD Thanks for the help by the way. Lastly in my Plugin.yml when the player types the /help command and it displays the description it is cut off. How do i make it so it displays the whole description? (<-- Essentials Fixes this) Thanks!

    Plugin.yml
    Code:
    name: DeathCoords
    main: me.sphiinx.DeathCoords
    version: 1.0
    commands:
      help deathcoords:
          description: This plugin will display the players death coordinates.
          usage: Type /help deathcoords
          permission: <plugin name>.allow
          permission-message: You don't have <permission>
     
  15. Offline

    Wingzzz

    Rex285
    If your questions/problems have been resolved please mark your thread as "solved" by editing it and setting the prefix to "Solved" this helps developers to know the issue(s) has/have been resolved without having to delve into the thread itself.

    Also, I'd just like to mention that please don't let people discourage you from asking what they consider "stupid" questions (not saying you are). This is the "Plugin Development" section and not the "Experienced Plugin Development" section. There are no bounds to questions no matter how simple or complicated. Developers who respond with snarky comments are an eye sore to the community IMO because they're not being welcoming and encouraging (not to mention unhelpful sometimes) to the OP.

    You've been (as far as I can see) straight to the point and communicating with good grammar. It makes it easy for a developer to respond to those kind of threads, thanks!

    Although I do have a few tips about posting questions here (and for any other people viewing this thread):
    1. Try to stay away from purely Java related questions. Googling around should be sufficient to finding more than a couple dozen articles/threads/posts etc relating to the topic you're looking for. There are websites out there that will more than likely already have asked the question you have or relate to it such as stackoverflow.
    2. Be sure to put all questions in the OP (if you have them all at the time of posting).
    3. Request details/sources if you need them as not all developers respond in as much detail as others do.
    4. Update your main post via "Edit <#>: ..." so that people can track the progress of the thread easily.
    Just a few suggestions for posting questions. Also, I'm glad your problem seems to be solved :)
     
    NathanWolf likes this.
  16. Offline

    Sneling

    If you disable the plugin by a command, when disabled you cannot enable him by a command... Maybe by passing through an another plugin? And i'm not sure.
    And yes, please put 'solved'
     
  17. Offline

    Wingzzz

    I believe he was looking for a toggle for his functionality and not to actually disable the plugin. Although, you can disable/enable plugins freely via the PluginManager.

    To disable a plugin, simply call PluginManager#disablePlugin(Plugin plugin) like so:
    Code:java
    1. Bukkit.getPluginManager().disablePlugin(plugin);


    To enable a plugin, simply call PluginManager#enablePlugin(Plugin plugin) like so:
    Code:java
    1. Bukkit.getPluginManager().enablePlugin(plugin);


    These methods differ from actually loading/unloading the plugin so they should be able to be called freely without issues (unless of course a plugin depending on it doesn't properly do checks to ensure it is enabled then that dependency wouldn't function properly- but I doubt the OP's plugin has any plugins depending on it).
     
  18. Offline

    Sneling

    Wingzzz ok.. Maybe i didn't understand what he really wanted.
     
  19. Offline

    Rex285

    Wingzzz
    I'm sorry, I'm a little new to this. Where would I add this into my code at? You can look at my code above. I have some ideas where to put it, but i'm not totally sure.
     
  20. Offline

    Wingzzz

    Well posts above already described an alternative. You can create boolean such as "enabled" or "on" and then toggle it via a command (for how to create a command visit the tutorial here: http://wiki.bukkit.org/Plugin_Tutorial#Commands) and then reference the boolean to see if code should be executed (ie: check to see if(enabled == true) when you're say listening for an event).

    Now that's one way, or you could do what I mentioned with actually just disabling the plugin. The problem with this approach is that you can't re-enable it via a command since your plugin will be disabled (unless you execute /reload but this can have negative side-effects on your server). Although if you want to disable your plugin you can create a command and in that command call PluginManager#disablePlugin(Plugin plugin).

    I would recommend the boolean approach as it is more robust. You can easily accomplish this by doing something such as:
    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2.  
    3. private static MyPlugin instance;
    4. private boolean on;
    5.  
    6. @Override
    7. public void onEnable() {
    8. instance = this;
    9. on = true;
    10. Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
    11. }
    12.  
    13. public boolean isOn() {
    14. return on;
    15. }
    16.  
    17. public void setOn(boolean on) {
    18. this.on = on;
    19. }
    20.  
    21. public static MyPlugin getInstance() {
    22. return instance;
    23. }
    24.  
    25. }

    I used "isOn()" because "isEnabled()" is used by Plugin and we don't want to check if the plugin is actually enabled, but rather whether or not it is toggled or "on". Feel free to change this to meet your needs or to better suit what you think it should be named. We also set "on" to 'true' onEnable() because by default it is 'false'.

    Then say in my Listener that I've registered in another class I only want it to work if I've set my plugin to "on":
    Code:java
    1. public class PlayerListener implements Listener {
    2.  
    3. @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
    4. public void onPlayerJoin(PlayerJoinEvent event) {
    5. if(MyPlugin.getInstance().isOn()) {
    6. event.getPlayer().sendMessage(ChatColor.GREEN + "MyPlugin is on (aside from being enabled)!");
    7. }
    8. }
    9.  
    10. }


    Interested in learning more about Listeners? View Bukkit's documentation here.

    So to go over what we did here, was we made a boolean in the Plugin that we can reference via an instance of the MyPlugin class by calling MyPlugin.getInstance().isOn() and MyPlugin.getInstance().setOn(boolean on) or by any instance of the class (assume "plugin" is an instance of MyPlugin) like: plugin.isOn() and plugin.setOn(boolean on).

    Then we made a dummy test by creating and registering a Listener that listens for when players join. If they join and the plugin is set to "on" (separate functionality to that of Plugin#isEnabled()) then it will display a debug message stating it is on. This means if the plugin is set to "off" it will not do anything. You can mimic this functionality in commands, other event handlers, or any method you have. Simply do a quick check to make sure the plugin is "on" so that you know you're good to go to execute the code, otherwise if not and the plugin is "off" you can either do nothing or log some information, inform the person attempting to do the command or anything you want!

    Note, instead I could've referenced the "on" variable by passing an instance of MyPlugin to PlayerListener through its constructor as "plugin" and then called 'plugin.isOn();' although in my example I used a static method called "getInstance();" that returned MyPlugin due to the fact that a Plugin is already a singleton.

    Also, note that this example excludes imports- you will need to import all references that aren't in the same package, we aren't magicians... (Unless you are and you can, then please TEACH ME!)

    If you're still fuzzy on what I've explained above please let me know! I can go over it in simpler terms or step by step with you if need be. Hopefully my explanation didn't stray from the point and(or) didn't become complicated in the way I referenced things.
     
  21. Offline

    Rex285

    Wingzzz
    I am still a little Fuzzy on what you explained. Do you have a Skype where you could explain it in simpler terms? Also thank you for helping me.
     
  22. Offline

    Wingzzz

    No problem :) Unfortunately I won't have time to help in real time so we'll have to make due on the bukkit forums. Either through forum posts or inboxing.

    At what part aren't you understanding? We can start there.
     
  23. Offline

    Rex285

    Wingzzz
    Thats fine, the part I'm not understanding is do I have to make the command "/deathcoords on" and "/deathcoords off" and then link them to the Public Void onenables, etc.. Like that? How would I setup this. I am baffled atm. Sorry I am fairly new to this.
     
  24. Offline

    Wingzzz

    Ah I see, your problem lies in creating commands. Alright, well first things first Bukkit has documentation on how to create a command via the Bukkit API here: http://wiki.bukkit.org/Plugin_Tutorial#Commands.

    So I highly recommend reading through that and testing, and then reading some more, and then testing some more. So that you can grasp a it well, but since I'm here I'll reference this tutorial and walk you through a very basic command.

    So- for this example I'll be using a Plugin implementation (ie: your main class that extends JavaPlugin). This way I don't need to touch on CommandExecutor's and we can get straight to making the command.

    Step #1:
    We need to set up our plugin, so let's go ahead and get our Plugin class going:
    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2.  
    3. @Override
    4. public void onEnable() {
    5. // do something
    6. }
    7.  
    8. }


    Step #2:
    Now that we've got our plugin set up, we need to start creating a command. To do this we need to use the CommandExecutor#onCommand(CommandSender sender, Command command, String label, String[] args) method.

    This method is only available to classes implementing CommandExecutor but lucky for us, Plugin extends CommandExecutor (interfaces extend other interfaces, whilst classes implement interfaces- just a quick tip- if you don't follow, don't worry it's not necessary to the example). This means that if you extend JavaPlugin then your class inherits the method CommandExecutor#onCommand(...);

    In other words, this means we're good to go to create commands inside our Plugin class.

    So, let's go ahead and override the onCommand(...) method like so:
    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2.  
    3. @Override
    4. public void onEnable() {
    5. // do something
    6. }
    7.  
    8. @Override
    9. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    10. // do something
    11. }
    12.  
    13. }


    Step #3:
    We've now got our basic plugin set up, we've got our command handling method set up- we're going good. Now, what we need to do is create a command. Although before we do this- let me describe the parameters of the onCommand(...) method.
    • ( CommandSender) sender - This is the "sender" who sent the command. CommandSender is the interface for those who can send commands. Two interfaces that extend this are Player (meaning the command was sent from a player) and ConsoleCommandSender (meaning the command was sent from the console)
    • (Command) command - This is the command that was sent. The object contains methods such as the command name, its permission, usage, and other methods. Do not confuse this with the material Command, they're different.
    • (String) label - This is the command's label which is essentially the alias of the command that was used. I recommend staying away from using this- instead favour "command.getName()".
    • (String[]) args - These are the arguments that were typed after the command. Example: "/mycommand arg0 arg1 arg2 arg3". Remember Java starts indexing at 0 so the first arg is args[0]. Learn more about arrays here.
    Okay, with that out of the way let's go ahead and quickly create a command and then we'll go over it again:
    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2.  
    3. @Override
    4. public void onEnable() {
    5. // do something
    6. }
    7.  
    8. @Override
    9. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    10. if(command.getName().equalsIgnoreCase("deathcoords")) {
    11. // Check to see if the sender is a player
    12. if(sender instanceof Player) {
    13. // Cast the sender to a player
    14. Player player = (Player) sender;
    15. // Check to see if the player has the proper permissions or is OP, otherwise don't execute the command.
    16. if(!player.hasPermission("deathcoords.toggle") && !player.isOp()) {
    17. // inform them they don't have permission if you want to
    18. return true;
    19. }
    20. }
    21.  
    22. // Check to make sure they input at least 1 argument after typing /deathcoords
    23. if(args.length > 0) {
    24. // Check to make sure a sender input 1 argument. ie: /deathcoords one-argument
    25. if(args.length == 1) {
    26. // Check to see regardless of case if the argument was "on"
    27. if(args[0].equalsIgnoreCase("on")) {
    28. // Check to see if the plugin isn't "on", if so then set on. Otherwise it is already on and do nothing.
    29. if(!MyPlugin.getInstance().isOn()) {
    30. MyPlugin.getInstance().setOn(true);
    31. // inform the sender they turned on the plugin's functionality
    32. }
    33. // Check to see regardless of case if the argument was "off"
    34. } else if(args[0].equalsIgnoreCase("off")) {
    35. // Check to see if the plugin is "on", if so then set off. Otherwise it is already off and do nothing.
    36. if(MyPlugin.getInstance().isOn()) {
    37. MyPlugin.getInstance().setOn(false);
    38. // inform the sender they turned off the plugin's functionality
    39. }
    40.  
    41. // If the argument was not "on" or "off"
    42. } else {
    43. // inform the sender they input an invalid arguments, inform them the only valid args are "on" and "off"
    44. }
    45.  
    46. // Else if the args.length isn't 1, check if they input more than 1 argument.
    47. } else if(args.length > 1) {
    48. // inform the sender they input too many arguments
    49. }
    50.  
    51. // Else if args.length isn't greater than 0, this means they only typed /deathcoords
    52. } else {
    53. // inform the sender they need to input args, either on or off
    54. }
    55. }
    56.  
    57. return true;
    58. }
    59.  
    60. }


    Step #4:
    Alright, we've got a basic command going. Hopefully the comments in the code are sufficient enough to explain what's going on but just remember in arrays indexing starts at 0. If we have 1 element, meaning 1 "thing" in the array, in this case args is an array of strings, so if we have 1 String in the array, it's index will be 0. If we have 2 elements (meaning the array's length is 2), the indexes will be 0(first element) and 1(second element). So:

    If args.length == 0:
    /deathcoords

    If args.length == 1:
    /deathcoords args[0]

    If args.length == 2:
    /deathcoords args[0] args[1]

    If args.length == 3:
    /deathcoords args[0] args[1] args[2]

    Arguments are separated by spaces in commands.

    So now that we've created a command, we need to actually say "who" handles it. In order to do so, we must register it. To do this we go into our onEnable() insert the following:
    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2.  
    3. @Override
    4. public void onEnable() {
    5. this.getCommand("deathcoords").setExecutor(this);
    6. }
    7.  
    8. @Override
    9. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    10. if(command.getName().equalsIgnoreCase("deathcoords")) {
    11. // Check to see if the sender is a player
    12. if(sender instanceof Player) {
    13. // Cast the sender to a player
    14. Player player = (Player) sender;
    15. // Check to see if the player has the proper permissions or is OP, otherwise don't execute the command.
    16. if(!player.hasPermission("deathcoords.toggle") && !player.isOp()) {
    17. // inform them they don't have permission if you want to
    18. return true;
    19. }
    20. }
    21.  
    22. // Check to make sure they input at least 1 argument after typing /deathcoords
    23. if(args.length > 0) {
    24. // Check to make sure a sender input 1 argument. ie: /deathcoords one-argument
    25. if(args.length == 1) {
    26. // Check to see regardless of case if the argument was "on"
    27. if(args[0].equalsIgnoreCase("on")) {
    28. // Check to see if the plugin isn't "on", if so then set on. Otherwise it is already on and do nothing.
    29. if(!MyPlugin.getInstance().isOn()) {
    30. MyPlugin.getInstance().setOn(true);
    31. // inform the sender they turned on the plugin's functionality
    32. }
    33. // Check to see regardless of case if the argument was "off"
    34. } else if(args[0].equalsIgnoreCase("off")) {
    35. // Check to see if the plugin is "on", if so then set off. Otherwise it is already off and do nothing.
    36. if(MyPlugin.getInstance().isOn()) {
    37. MyPlugin.getInstance().setOn(false);
    38. // inform the sender they turned off the plugin's functionality
    39. }
    40.  
    41. // If the argument was not "on" or "off"
    42. } else {
    43. // inform the sender they input an invalid arguments, inform them the only valid args are "on" and "off"
    44. }
    45.  
    46. // Else if the args.length isn't 1, check if they input more than 1 argument.
    47. } else if(args.length > 1) {
    48. // inform the sender they input too many arguments
    49. }
    50.  
    51. // Else if args.length isn't greater than 0, this means they only typed /deathcoords
    52. } else {
    53. // inform the sender they need to input args, either on or off
    54. }
    55. }
    56.  
    57. return true;
    58. }
    59.  
    60. }


    Alright, now what we did was say "this" meaning "this class that the word this is being typed in" .getCommand("deathcoords") so we want to get the command "deathcoords", .setExecutor(this) we want to set the command's executor (the class that handles its execution- ie: what it does) to be "this" meaning "this class that the word this is being typed in" ie: MyPlugin.

    Step #5:
    We're almost done! Woo! All that's left to do is set up our plugin.yml. Okay let's create it and input a bit of information shall we?
    Code:
    main: <your-package>.MyPlugin
    name: MyPlugin
    author: <your-name>
    version: <plugin-version ie: 1.0.0>
    
    Awesome! Now we've got a plugin that will run. But, wait... Uh-oh! This won't run our command. We're missing something crucial in our plugin.yml. How about we fix that?

    In a plugin.yml you must define your commands. So let's revisit our plugin.yml and add in our command:
    Code:
    main: <your-package>.MyPlugin
    name: MyPlugin
    author: <your-name>
    version: <plugin-version ie: 1.0.0>
    commands:
        deathcoords:
    
    This will work although you can also add some optional command attributes such as a description, usage, permission, permission-message (although these will only show when onCommand(...) returns false although in my example I always return true so that we can handle the command messaging ourself. This allows us to have more custom messages when people do things.)

    You can find a full list of command attributes as well as other plugin.yml attributes here: http://wiki.bukkit.org/Plugin_YAML

    Step #6:
    Test your plugin! You should be able to toggle your plugin on and off freely.

    Notes:
    • I exclude imports in the examples above. Please ensure you use the proper imports.
    • This is the basic way to do commands with the Bukkit API, there are other ways with community created libs/apis. You can use annotations/command objects. Separate commands into CommandExecutors in other classes. Feel free to explore these!
    • Forgive any issues with the code above, it was all written in this forum post and not tested.
     
    NathanWolf likes this.
  25. Offline

    Rex285

    Wingzzz
    Thank you so much! You are a person who can actually explain something to someone and help them! I appreciate it so much. I now understand things a lot more! I have one question though.

    Here is the whole set of code. In the part where it checks to see if the plugin is on, and if it is it does nothing for some reason I am getting an error for the ".getInstance()" saying that "The method .getInstance() is undefined for the type DeathCoords. Thanks again for your help!
    Code:java
    1. package me.sphiinx;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class DeathCoords extends JavaPlugin {
    10.  
    11. @Override
    12. public void onEnable() {
    13. getLogger().info("This was created by Sphiinx of VaultCraft Visit Vaultdarkrp.com for info or contact me @ [email][email protected][/email]");
    14. new PlayerListener(this);
    15. this.getCommand("deathcoords").setExecutor(this);
    16. // Do Something
    17. }
    18.  
    19. @Override
    20. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    21. if(command.getName().equalsIgnoreCase("deathcoords")) {
    22. // Check to see if the sender is a player
    23. if(sender instanceof Player) {
    24. // Cast the sender to a player
    25. Player player = (Player) sender;
    26. // Check to see if the player has the proper permissions or is OP, otherwise don't execute the command.
    27. if(!player.hasPermission("deathcoords.toggle") && !player.isOp()) {
    28. // inform them they don't have permission if you want to
    29. return true;
    30. }
    31. }
    32.  
    33. // Check to make sure they input at least 1 argument after typing /deathcoords
    34. if(args.length > 0) {
    35. // Check to make sure a sender input 1 argument. ie: /deathcoords one-argument
    36. if(args.length == 1) {
    37. // Check to see regardless of case if the argument was "on"
    38. if(args[0].equalsIgnoreCase("on")) {
    39. // Check to see if the plugin isn't "on", if so then set on. Otherwise it is already on and do nothing.
    40. if(!DeathCoords.getInstance().isOn()) {
    41. DeathCoords.getInstance().setOn(true);
    42. // inform the sender they turned on the plugin's functionality
    43. }
    44. // Check to see regardless of case if the argument was "off"
    45. } else if(args[0].equalsIgnoreCase("off")) {
    46. // Check to see if the plugin is "on", if so then set off. Otherwise it is already off and do nothing.
    47. if(DeathCoords.getInstance().isOn()) {
    48. DeathCoords.getInstance().setOn(false);
    49. // inform the sender they turned off the plugin's functionality
    50. }
    51.  
    52. // If the argument was not "on" or "off"
    53. } else {
    54. // inform the sender they input an invalid arguments, inform them the only valid args are "on" and "off"
    55. }
    56.  
    57. // Else if the args.length isn't 1, check if they input more than 1 argument.
    58. } else if(args.length > 1) {
    59. // inform the sender they input too many arguments
    60. }
    61.  
    62. // Else if args.length isn't greater than 0, this means they only typed /deathcoords
    63. } else {
    64. // inform the sender they need to input args, either on or off
    65. }
    66. }
    67.  
    68. return true;
    69. }
    70.  
    71. }
     
  26. Offline

    Wingzzz

    If you look at your code, it does not have the method in it. So you need to insert the field and methods used in the toggling.

    What you're missing are the following:
    Code:java
    1. private static DeathCoords instance;
    2. private boolean on;
    3.  
    4. public boolean isOn() {
    5. return on;
    6. }
    7.  
    8. public void setOn(boolean on) {
    9. this.on = on;
    10. }
    11.  
    12. public static DeathCoords getInstance() {
    13. return instance;
    14. }


    The above is in addition to the other code in you DeathCoords.java. In order to make the above code that you should now have in the DeathCoords.java work, you must ensure onEnable(), you insert the following:
    Code:java
    1. instance = this;
    2. this.on = true;


    The above will go inside of your exising onEnable() method so that we can access the singleton (which is your plugin class DeathCoords) statically via the method DeathCoords#getInstance() which we can then do things such as:
    Code:java
    1. // Check the DeathCoords "on" state.
    2. DeathCoords.getInstance().isOn();
    3. // Change the DeathCoords "on" state.
    4. DeathCoords.getInstance().setOn(false);
     
  27. Offline

    Rex285

    Wingzzz
    Thank you so much for your help. Lastly, is my Plugin.yml correct? Thank you!

    Code:
    name: DeathCoords
    main: me.sphiinx.DeathCoords
    version: 1.0
    author: Sphiinx
    website: http://www.vaultdarkrp.com
    commands:
      deathcoords:
          description: This plugin will display the players death coordinates.
          permission: deathcoords.toggle
          default: op
     
  28. Offline

    Konkz


    If it works it must be right?
    I'm not sure if the website works as it has a colon, I think it has to be www.vaultdarkrp.com
     
  29. Offline

    Rex285

    Konkz
    Thanks! I am testing the plugin atm, and adding messages.

    Wingzzz
    Konkz
    Why am I getting this warning all of the sudden and my plugin stopped working? It was just working...
    Code:
    Description    Resource    Path    Location    Type
    Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment.    Tutorial 2        Build path    JRE System Library Problem
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  30. Offline

    Wingzzz

    Should still be able to work, although if you do have issues you can enclose String scalars in single or double quotations.

    Rex285
    The issue is that the workspace doesn't define any JREs that are compatible with the specified execution environment . IE: I specify Java SE 1.6 and yet define either none or the JRE for the workspace to be greater or lesser than the specified execution environment. Go to your project's build path, and ensure its execution environment is defined. If you use the default workspace jre then ensure that it is valid.
     
Thread Status:
Not open for further replies.

Share This Page