Plugin won't work?

Discussion in 'Plugin Development' started by BeastCraft3, Nov 17, 2014.

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

    BeastCraft3

    Hello, I've tried to make a pvp enable plugin, but for some reason the main command won't work. I don't get any errors in the consol and the plugin looks like it should work when I type /plugins

    This is my code:
    Code:java
    1. package com.DrBeast.PrisonPurge;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class PrisonPurge extends JavaPlugin{
    13.  
    14. ArrayList<Player> cooldown = new ArrayList<Player>();
    15.  
    16. public void onEnalbe(){
    17. System.out.println("Plugin Enabled!");
    18. }
    19.  
    20. public void onDisable(){
    21. System.out.println("Plugin Disabled!");
    22. }
    23. public int i = 60;
    24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    25. if(!(sender instanceof Player)) {
    26. sender.sendMessage("§conly players can use this command");
    27. return true;
    28. }
    29.  
    30. Player p = (Player) sender;
    31. final Player p2 = (Player) sender;
    32. if(p.getName().equalsIgnoreCase("purge")){
    33. if(p.hasPermission("Purge.start")) {
    34. if(args.length == 0) {
    35. p.sendMessage("§4§m§l|------( §r§6Purge Help §4§m§l)------| ");
    36. p.sendMessage("§8/purge start");
    37. p.sendMessage("§7this command will enable pvp everywhere for 15 minutes.");
    38. p.sendMessage("§4§m§l|------( §r§6Purge Help §4§m§l)------| ");
    39. }else if(args.length < 1) {
    40. if(args[0].equalsIgnoreCase("start")){
    41. if(cooldown.contains(p2)){
    42. p2.sendMessage("§cThis purge is already running!");
    43. } else {
    44.  
    45. cooldown.add(p2);
    46. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    47. public void run() {
    48. if(i == 60){
    49. Bukkit.broadcastMessage(ChatColor.RED + "The Purge will begin in " + i + " seconds");
    50. i--;
    51. }
    52. cooldown.remove(p2);
    53. }
    54. }, 18000);
    55.  
    56. }
    57. }
    58. }
    59. }
    60. }
    61. return false;
    62. }
    63.  
    64.  
    65.  
    66. }
    67.  
     
  2. Offline

    Th3Br1x

    BeastCraft3
    Actually, your task will start - after 18000 milliseconds. Because thats the starting delay of the task.
    Have you tried to wait that period of time?
     
  3. Offline

    Unica

    Code:java
    1. public void onEnalbe(){
    2. System.out.println("Plugin Enabled!");
    3. }


    onEnable*
    You made a typo ;)
     
  4. Offline

    BeastCraft3

    Unica Th3Br1x
    lol I fixed it Unica :p it still doesn't work though and Th3Br1x its suppost to start after the void run, at least all the tutorials I could find on google did that. and again the /purge doesn't work either. if they write /purge it's suppot to display the Help menu
     
  5. Offline

    Th3Br1x

    BeastCraft3
    Lol, check your code carefully :D
    You're checking, if the players name is "purge".

    Fixed? :)
     
  6. Offline

    aaomidi

    You should always @Override onEnable. It'll also tell you if you had a typo then.
     
  7. Offline

    Th3Br1x

    aaomidi
    Actually not. Why should it display a typo? (Except for eclipse's spelling module).
    But that's not the problem anymore :)
     
  8. Offline

    teej107

    Th3Br1x because you override those methods to begin with if you use them. You can't override a method that doesn't exist in the super class.
     
    Th3Br1x likes this.
  9. Offline

    Th3Br1x

    Well, i didn't even knew that, thank you :)
    You always learn new stuff as a programmer...
     
  10. Offline

    BeastCraft3

    Th3Br1x teej107 Th3Br1x aaomidi
    Would this work? as you can see am having problems mixing up arrays and hashmap. Please tell me what to do ;(
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. if(!(sender instanceof Player)) {
    3. sender.sendMessage("§conly players can use this command");
    4. return true;
    5. }
    6.  
    7. Player p = (Player) sender;
    8. final Player p2 = (Player) sender;
    9. if(p.getName().equalsIgnoreCase("purge")){
    10. if(p.hasPermission("Purge.start")) {
    11. if(args.length == 0) {
    12. p.sendMessage("§4§m§l|------( §r§6Purge Help §4§m§l)------| ");
    13. p.sendMessage("§8/purge start");
    14. p.sendMessage("§7this command will enable pvp everywhere for 15 minutes.");
    15. p.sendMessage("§4§m§l|------( §r§6Purge Help §4§m§l)------| ");
    16. }else if(args.length < 1) {
    17. if(args[0].equalsIgnoreCase("start")){
    18. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    19. public void run() {
    20. for(Player pl : Bukkit.getOnlinePlayers()){
    21. if(pl != null) {
    22. }
    23. int time = purge.get(pl.getName());
    24. time--;
    25. if (time == 1200) {
    26. Bukkit.broadcastMessage("§cThe Purge will begin in 1 minute!");
    27. } else if(time == 600){
    28. Bukkit.broadcastMessage("§cThe Purge will begin in 30 seconds!");
    29. } else if(time == 200){
    30. Bukkit.broadcastMessage("§cThe Purge will begin in 10 seconds!");
    31. } else if(time == 60){
    32. Bukkit.broadcastMessage("§cThe Purge will begin in 3 seconds!");
    33. } else if(time == 40){
    34. Bukkit.broadcastMessage("§cThe Purge will begin in 2 seconds!");
    35. } else if(time == 20){
    36. Bukkit.broadcastMessage("§cThe Purge will begin in 1 second!");
    37. } else if(time < 1){
    38. Bukkit.broadcastMessage("§cThe Purge has now begin, pvp is allowed EVERYWHERE for 15 minutes. Goodluck");
    39. purge.remove(pl.getName());
    40. }
    41.  
    42. }
    43. }
    44. }, 18000);
    45.  
    46. }
    47. }
    48. }
    49. }
    50.  
    51. }
    52. return false;
     
  11. Offline

    Creeoer

    BeastCraft3
    If player isn't null, do nothing. line 22
     
  12. Offline

    timbragg12

    Code:java
    1. 32. if(p.getName().equalsIgnoreCase("purge")){

    Should it not be:
    Code:java
    1. if(cmd.getname().equalsIgnoreCase("purge")){

    ?
     
  13. Offline

    mythbusterma

    timbragg12

    I don't know what you're talking about, my IGN is always "purge."

    Kidding aside, this is a prime example of one character variable names are usually a bad thing, it's much harder to see mistakes like this at a glance, rather than player.getName().... which would be a very obvious mistake.
     
  14. Offline

    FabeGabeMC

    BeastCraft3
    Why are you doing a for loop then broadcasting the message? That will spam everybody's chat. Also, store the player's UUID instead of the actual Player Object.
     
  15. Offline

    timbragg12

    mythbusterma I agree, although I will continue to use "p" anyway. :)
     
  16. Offline

    Unica

    FabeGabeMC

    I think you can save the object, as long as you remove it on disconnecting / reloading.
     
  17. Offline

    FabeGabeMC

    Unica
    I know but it might cause memory leaks.
     
  18. Offline

    teej107

    might. only if you forget to remove the player.
     
  19. Offline

    BeastCraft3

  20. Offline

    JordyPwner

  21. Offline

    BeastCraft3

  22. Offline

    JordyPwner

    U got saros or skype?
     
  23. Offline

    BeastCraft3

  24. Offline

    Th3Br1x

  25. Offline

    BeastCraft3

    Th3Br1x
    Code:java
    1. int time = purge.get(pl.getName());

    purge is my hashmap:
    Code:java
    1. private HashMap<UUID, Integer> purge = new HashMap<>();


    and cooldown is my arraylist:
    Code:java
    1. ArrayList<Player> cooldown = new ArrayList<Player>();


    Which one of them should I use?
     
  26. Offline

    Th3Br1x

    BeastCraft3
    It depends on your usage. If you just want to have a list, to check which players have still a running cooldown, use the ArrayList. If you also want to store the remaining cooldown, use the hashmap. :)
     
  27. Offline

    BeastCraft3

    Th3Br1x
    I don't want to store them. ahh this plugin is getting soo advanced... I just wanted to create a simple plugin when you use /purge start it will be a cooldown on 1 minute then pvp over the entire world will be enabled with Bukkit.getConsoleSender().dispatchCommand("Region flag __global__ -w plotworld pvp allow"); for 15 minutes then disable it with the same command
     
Thread Status:
Not open for further replies.

Share This Page