Plugin not working

Discussion in 'Plugin Development' started by Zangoran, Jun 1, 2014.

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

    Zangoran

    Here is what it is supposed to do: It is supposed to kick a player when /smp on is on but what it is doing right now is just kicking all the online players. It is supposed to kick them when they join too but it is not why is it not?

    CODE:
    Code:java
    1. package me.zangoran.kobaltorange.smp;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class SMP extends JavaPlugin implements Listener {
    14.  
    15. public static boolean state = false;
    16. private int smp1;
    17.  
    18. public void onEnable1() {
    19. getLogger().info("onEnable has been enabled!");
    20. getServer().getPluginManager().registerEvents(this, this);
    21. }
    22.  
    23. @
    24. Override
    25. public void onDisable() {}
    26.  
    27. int smp = 0;
    28. public void onEnable() {
    29. getServer().getPluginManager().registerEvents(this, this);
    30. }
    31. @EventHandler
    32. public void onPlayerJoin(PlayerJoinEvent event){
    33. if(smp == 1){
    34. Player player = event.getPlayer();
    35. player.kickPlayer("Server is under maintencance!");
    36. }
    37. else {
    38.  
    39. }
    40. }
    41.  
    42.  
    43. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    44. if (cmd.getName().equalsIgnoreCase("smp") && sender instanceof Player) {
    45. Player player = (Player) sender;
    46. if (!player.hasPermission("smp.toggle")) {
    47. player.sendMessage(ChatColor.RED + "You are not allowed to perform this command.");
    48. return true;
    49. } else if (args.length > 0) {
    50. if (args[0].equalsIgnoreCase("on")) {
    51. smp1 = 1;
    52. for (Player p: Bukkit.getServer().getOnlinePlayers()) {
    53. if (!p.hasPermission("smp.bypass")) {
    54. p.kickPlayer("Server is under maintenance!");
    55. return true;
    56. } else {
    57. Bukkit.getLogger().info(ChatColor.RED + "[" + ChatColor.GOLD + "SMP" + ChatColor.RED + "]" + ChatColor.BLUE + " SMP has been turned" + ChatColor.DARK_GREEN + " ON");
    58. p.sendMessage(ChatColor.RED + "[" + ChatColor.GOLD + "SMP" + ChatColor.RED + "]" + ChatColor.BLUE + " SMP has been turned" + ChatColor.DARK_GREEN + " ON");
    59. }
    60. }
    61. } else if (args[0].equalsIgnoreCase("off")) {
    62. smp1 = 0;
    63. for (Player p: Bukkit.getServer().getOnlinePlayers()) {
    64. p.sendMessage(ChatColor.RED + "[" + ChatColor.GOLD + "SMP" + ChatColor.RED + "]" + ChatColor.BLUE + " SMP has been turned" + ChatColor.RED + " OFF");
    65. }
    66. return true;
    67.  
    68. } else if (args[0].equalsIgnoreCase("status")) {
    69. for (Player p: Bukkit.getServer().getOnlinePlayers()) {
    70. p.sendMessage(ChatColor.RED + "[" + ChatColor.GOLD + "SMP" + ChatColor.RED + "]" + " " + ChatColor.RED + ChatColor.BOLD + smp1 + ChatColor.GOLD + " 0 = OFF, 1 = ON");
    71. }
    72. return true;
    73. } else if (args[0].equalsIgnoreCase("reload")) {
    74. if (player.hasPermission("smp.reload")) {
    75. this.reloadConfig();
    76. player.sendMessage(ChatColor.RED + "[" + ChatColor.GOLD + "SMP" + ChatColor.RED + "]" + ChatColor.DARK_RED + " SMP reloaded!");
    77. Bukkit.getLogger().info(ChatColor.RED + "[" + ChatColor.GOLD + "SMP" + ChatColor.RED + "]" + ChatColor.DARK_RED + " SMP reloaded!");
    78. return true;
    79. }
    80. }
    81. } else {
    82. return false;
    83. }
    84. } else {
    85. return true;
    86. }
    87.  
    88. return true;
    89. }
    90.  
    91. }
     
  2. Offline

    WhatAaCow

    Zangoran Please STOP asking the same question ever and ever again! This is like your 10. thread with the SAME thing.

    SEARCH for a JAVA tutorial AND do the turorial. This is not a Java basic help forum at all.
     
    es359, Konkz and 1Rogue like this.
  3. Offline

    JaguarJo

    A progressive history of your work on this plugin in case anyone needs references:
    http://forums.bukkit.org/threads/plugin-yml-help.273695/
    http://forums.bukkit.org/threads/plugin-yml-crashing-my-server.273984/
    http://forums.bukkit.org/threads/onplayerjoin-help.274028/
    http://forums.bukkit.org/threads/dev-help-please.274043/
    http://forums.bukkit.org/threads/kick-message-help.274078/
    http://forums.bukkit.org/threads/help-with-my-plugin.274284/
    http://forums.bukkit.org/threads/having-problems-again.274534/

    Locking the old posts and directing people to come to this one. After this, let's please try to keep everything in one place. There's no need to keep opening up new threads for working on the same project. Keep it here.
     
    Konkz and WhatAaCow like this.
  4. Offline

    FlareLine

    Code:java
    1. private int smp1;
    2.  
    3. public void onEnable1() {
    4. getLogger().info("onEnable has been enabled!");
    5. getServer().getPluginManager().registerEvents(this, this);
    6. }
    7.  
    8. @
    9. Override
    10. public void onDisable() {}
    11.  
    12. int smp = 0;

    Note the variables at the start and end of this syntax block and fix your error.

    You should really do some tutorials as this is EXTREMELY easy to fix, even for a Beginning Developer.
     
    Konkz likes this.
  5. Offline

    Zangoran

    Do you know why it is not kicking a player when they join? I have searched and searched and it is not working. Please help.
     
  6. Offline

    Kassestral

    FlareLine likes this.
  7. Offline

    FlareLine

    JaguarJo Suggestion to add a limit to how many threads people can open in a certain timeframe
     
  8. Offline

    es359

    You really need to start reading the bukkit docs. There is a method for this... And in several of your other posts I have even shown it to you...
     
  9. Offline

    FlareLine

    es359 he doesn't even need to read the docs to solve this problem. He needs to learn Java before asking the Bukkit community about simple syntax and reference errors. I'm pretty sure there's a post stating the community is not here to teach anyone Java...

    I quote mbaxter - 'You can't start with a "how 2 bukkit" tutorial. Step further back and read some instruction on java itself.'
     
    es359 likes this.
  10. Zangoran When a player logs in, start a delayed task to kick them instead of trying to kick them in the event.
    Isn't this EXACTLY what whitelisting does?
     
  11. Offline

    FlareLine

    Im_Zeus What he is saying is to kick them after a delay rather than kicking straight away - I'm pretty sure that's not what OP wants.
     
Thread Status:
Not open for further replies.

Share This Page