Ban is becoming null

Discussion in 'Plugin Development' started by TheMCBukkitTut, Aug 3, 2014.

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

    TheMCBukkitTut

    How do i make it so that when i do /ban jacobsscoot test and when the player trys to rejoin it will say the reason: test. but its not doing it for me

    Code:

    Code:java
    1. package me.harryplaysmc.apm;
    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.EventPriority;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerLoginEvent;
    12. import org.bukkit.event.player.PlayerLoginEvent.Result;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener{
    16.  
    17. @Override
    18. public void onEnable() {
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @SuppressWarnings("deprecation")
    23. public boolean onCommand(CommandSender sender, Command command,
    24. String label, String[] args) {
    25. if (label.equalsIgnoreCase("kick")){
    26. if(args.length == 0){
    27. sender.sendMessage(ChatColor.RED + "Please specify a player");
    28. return true;
    29. }
    30. Player target = Bukkit.getServer().getPlayer(args[0]);
    31. if(target == null){
    32. sender.sendMessage(ChatColor.RED + "Could not find player " + ChatColor.GRAY + args[0] + ChatColor.RED + "!");
    33. return true;
    34. }
    35.  
    36. String msg = "";
    37. for (int i = 1; i < args.length; i++){
    38. msg += args[i] + " ";
    39. }
    40.  
    41. if(msg.isEmpty()){
    42. target.kickPlayer(ChatColor.RED + "You have been kick by " + ChatColor.GRAY + sender.getName());
    43. Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.KICK));
    44. }
    45.  
    46. target.kickPlayer(ChatColor.RED + "You have been kick by " + ChatColor.GRAY + sender.getName() + ChatColor.RED + " for " + ChatColor.YELLOW + msg);
    47. Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.KICK));
    48. }
    49.  
    50. if (label.equalsIgnoreCase("ban")){
    51. if(args.length == 0){
    52. sender.sendMessage(ChatColor.RED + "Please specify a player");
    53. return true;
    54. }
    55. Player target = Bukkit.getServer().getPlayer(args[0]);
    56. if(target == null){
    57. sender.sendMessage(ChatColor.RED + "Could not find player " + ChatColor.GRAY + args[0] + ChatColor.RED + "!");
    58. return true;
    59. }
    60.  
    61. String msg = "";
    62. for (int i = 1; i < args.length; i++){
    63. msg += args[i] + " ";
    64. }
    65.  
    66. if(msg.isEmpty()){
    67. target.kickPlayer(ChatColor.RED + "You have been banned by " + ChatColor.GRAY + sender.getName() + ChatColor.AQUA + " Purchause a unban at: store.apparelprison.net");
    68. target.setBanned(true);
    69. Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.BAN));
    70. }
    71.  
    72. target.kickPlayer(ChatColor.RED + "You have been banned by " + ChatColor.GRAY + sender.getName() + ChatColor.RED + " for " + ChatColor.YELLOW + msg + ChatColor.AQUA + " Purchause a unban at: store.apparelprison.net");
    73. target.setBanned(true);
    74. Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.BAN));
    75. }
    76. return false;
    77. }
    78.  
    79. @EventHandler (priority = EventPriority.HIGHEST)
    80. public void onPlayerBanned(PlayerLoginEvent event) {
    81. Player player = event.getPlayer();
    82. String bm = ChatColor.YELLOW + getConfig().getString("Players." + player.getName() + ".Reason");
    83. if (event.getResult() == Result.KICK_BANNED) {
    84. if(bm != null){
    85. event.setKickMessage(ChatColor.RED + "Banned: " + bm);
    86. }
    87. }
    88. }
    89. }
    90. [/i][/i]
     
  2. If you don't do player.setBanned(true); but add their uuid to a list, and when they try to join and are in the list, you kick them again.
     
  3. Offline

    TheMCBukkitTut

    can you help me with code?
     
  4. Offline

    PandazNWafflez

    On a side note, you spelt 'purchase' wrong.
     
  5. I'll try, but I'm on my phone.
    <syntax=java>
    package me.harryplaysmc.apm;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{

    ArrayList<String> banned = new ArrayList<String>();

    @Override
    public void onEnable() {
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }

    @SuppressWarnings("deprecation")
    public boolean onCommand(CommandSender sender, Command command,
    String label, String[] args) {
    if (label.equalsIgnoreCase("kick")){
    if(args.length == 0){
    sender.sendMessage(ChatColor.RED + "Please specify a player");
    return true;
    }
    Player target = Bukkit.getServer().getPlayer(args[0]);
    if(target == null){
    sender.sendMessage(ChatColor.RED + "Could not find player " + ChatColor.GRAY + args[0] + ChatColor.RED + "!");
    return true;
    }

    String msg = "";
    for (int i = 1; i < args.length; i++){
    msg += args + " ";
    }

    if(msg.isEmpty()){
    target.kickPlayer(ChatColor.RED + "You have been kick by " + ChatColor.GRAY + sender.getName());
    Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.KICK));
    }

    target.kickPlayer(ChatColor.RED + "You have been kick by " + ChatColor.GRAY + sender.getName() + ChatColor.RED + " for " + ChatColor.YELLOW + msg);
    Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.KICK));
    }

    if (label.equalsIgnoreCase("ban")){
    if(args.length == 0){
    sender.sendMessage(ChatColor.RED + "Please specify a player");
    return true;
    }
    Player target = Bukkit.getServer().getPlayer(args[0]);
    if(target == null){
    sender.sendMessage(ChatColor.RED + "Could not find player " + ChatColor.GRAY + args[0] + ChatColor.RED + "!");
    return true;
    }

    String msg = "";
    for (int i = 1; i < args.length; i++){
    msg += args + " ";
    }

    if(msg.isEmpty()){
    target.kickPlayer(ChatColor.RED + "You have been banned by " + ChatColor.GRAY + sender.getName() + ChatColor.AQUA + " Purchause a unban at: store.apparelprison.net");
    banned.add(target.getUniqueId().toString());
    Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.BAN));
    }

    target.kickPlayer(ChatColor.RED + "You have been banned by " + ChatColor.GRAY + sender.getName() + ChatColor.RED + " for " + ChatColor.YELLOW + msg + ChatColor.AQUA + " Purchause a unban at: store.apparelprison.net");
    banned.add(target.getUniqueId().toString());
    Bukkit.getServer().getPluginManager().callEvent(new APMEvent(target, Type.BAN));
    }
    return false;
    }

    @EventHandler (priority = EventPriority.HIGHEST)
    public void onPlayerBanned(PlayerLoginEvent event) {
    Player player = event.getPlayer();
    String bm = ChatColor.YELLOW + getConfig().getString("Players." + player.getName() + ".Reason");
    if (banned.contains(event.getPlayer().getUniqueId().toString()) {
    if(bm != null){
    event.setKickMessage(ChatColor.RED + "Banned: " + bm);
    }
    }
    }
    }

    </syntax>

    If I made a typo, you kan easily fix it. And did you also add the reason in the config, did you saved the config? The only you have to do with the list is save them.
     
  6. Offline

    TheMCBukkitTut

    I added replaced my code with yours and i get this:
    http://gyazo.com/5bce90b3564d88cc7e19324c619a6aa1

    plus when i try to join back Im not banned I can login
     
  7. When you get the reason in the onCommand, it misses the [ i ] after the args. And did you add the reason into the config because I didn't saw that in the code.
    And you could just use Bram0101 instead of reply
    Bukkit forums changes [ i ] (but without spaces) to italic. So it messes up code
     
  8. Offline

    TheMCBukkitTut

    I didn't know i had to add the reason I wanted the reason to be added by its self and okay how do i fix the args?
     
  9. Offline

    mythbusterma

    TheMCBukkitTut

    May I suggest learning java before attempting to use Bukkit.
     
  10. String msg = "";
    for (int i = 1; i < args.length; i++){
    msg += args[ i ] + " ";
    }
     
  11. Offline

    TheMCBukkitTut

    Im sorry would you like to link me to a java tutorial (a mac version not windows bc eclipse and software on windows like terminal are different on window)

    Thanks ill add that now plus what can i do for the config to add it automatically?
     
  12. Bukkit changes [ i ] (but without spaces) to italic. That confuses people. I see another of people saying at other people that they need to learn java, even if they know java but are just a bit confused, or just don't see it right away.

    You can check out thenewboston for programming tutorials. And java for Windows and Mac are the same. Also this link should help you with the config
    http://wiki.bukkit.org/Configuration_API_Reference

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  13. Offline

    TheMCBukkitTut

    Okay thanks and i sometimes get confused between the terminals on windows and mac
     
  14. Offline

    mythbusterma

    TheMCBukkitTut

    Except we're not learning about Eclipse here, we're learning about JAVA, and one of the primary boosting points of Java is that is almost completely platform-independent. You don't need an operating system specific tutorial on how to write Java. Also, for the most part, all IDEs are the same, with only minor differences. Follow the Java tutorials published by Oracle, they are excellent.
     
  15. Well I like (and I think most people) that someone explaining it. I think that I heart that you remember it better it you hear or see it instead of reading it. And those letters can get annoying.
     
  16. Offline

    mythbusterma

    Bram0101

    And you remember best by writing it down, which is what you should be doing.
     
  17. And how do you know how I remember it the best. It could be by something else. It rarely helped me.
     
  18. Offline

    PandazNWafflez

    Bram0101 While that's true, most people remember best by writing it down and practising.
     
Thread Status:
Not open for further replies.

Share This Page