Solved Help with Temp-Banning.

Discussion in 'Plugin Development' started by Mindlessmink, Sep 7, 2016.

Thread Status:
Not open for further replies.
  1. Hey, So I'm making an Anti-Hacks system, Then I realised that I didn't want to perm ban for some hack modules, So... I had a go at making something that would temp ban users.

    However, I literally have NO clue what I am doing lol, And so. This is what I got so far.

    I was told system.current time Millis returned the number of milliseconds since computers started counting, So. This is what I came up with

    (This is for Anti-Knockback by the way)

    After we did some checks and confirmed they are not lagging, And they're cheating:
    Code:
                  plugin.getConfig().set("players." + p.getName() + ".bantime", System.currentTimeMillis());
                   plugin.saveConfig();
                   long bantime = 3600000;
                   long timeleft = System.currentTimeMillis() - bantime;
                   p.kickPlayer(ChatColor.translateAlternateColorCodes('&', "&4[&6MAH&4] &7You have been temp banned by the CatCraft AntiCheat.\n&cReason: &7Anti-Knockback / Knockback modifier.\n\n&4Time: " + TimeUnit.MILLISECONDS.toMinutes(timeleft) + " minutes." + " \n\n&c&nInfo&r\n \n&cDeveloper: &7MindlessMink\n &cOwner: &7catman2014_ \n \n&7If you were unfairly punished,\n &7Please contact a server developer."));
                   for (Player pl : Bukkit.getOnlinePlayers()) {
                     if (pl.hasPermission("mah.notify")) {
                       pl.sendMessage(ChatColor.translateAlternateColorCodes('&',
                           "&3&k,&4[&6MAH&4]&3&k, &e" + p.getName() + " &6was punished for AntiKnockback hacking."));
                       new FancyMessage("(Hover for more info!)").color(ChatColor.GRAY)
                           .tooltip(ChatColor.translateAlternateColorCodes('&', "&3&k,&4[&6MAH&4]&3&k, &eAntiKnockBack hack info:\n\n&6AntiKnockback is a hack that allows the user to take no knockback,\n&6Or modify their current knockback. This Player was not lagging,\n&6And was tested multiple ways to ensure he was not false banned.\nzn&cThank you :)"))
                           .send(pl);
                     }
    
    Yes, I am using Fanciful API for JSon messages. I recommend it, Very good Library


    OnPlayerLogin to check if they're banned:

    Code:
      @EventHandler
       public void on(PlayerLoginEvent e){
         Player p = e.getPlayer();
           if (plugin.getConfig().getLong("players." + p.getName() + ".bantime") < System.currentTimeMillis() + 3600000){
             p.kickPlayer(ChatColor.translateAlternateColorCodes('&', "&4[&6MAH&4] &7You have been temp banned by the CatCraft AntiCheat.\n&cReason: &7Anti-Knockback / Knockback modifier.\n\n&4Time: 1 hour" +  " \n\n&c&nInfo&r\n \n&cDeveloper: &7MindlessMink\n &cOwner: &7catman2014_ \n \n&7If you were unfairly punished,\n &7Please contact a server developer."));
           } else {
             return;
           }
         }
    
    yes, I know there's probably a bunch of errors on this. Lol. Please tell me if I'm using System.currentTimeMillis wrong, And yes, I do not need help with detecting Anti-Knockback. I'm pretty sure that's working fine since I tested it a few times and turned out fine.

    Thanks for all help you leave below.

    Cheers again,

    ~ Mink.
     
  2. Offline

    Zombie_Striker

    @Mindlessmink
    There already is a method for tempbans. Use BanList#addBan()
    Code:
    Bukkit.getBanList(BanList.Type.NAME).addBan(Name, Reason, Date, null);
     
  3. @Zombie_Striker, Does it allow you to edit the original Bukkit ban-message? Or is the reason just come up in ugly white?

    Also, What would I fill in the "Date" section.
     
  4. Offline

    Zombie_Striker

    @Mindlessmink
    Yes, you can edit the reason. Replace "Reason" with the string you want to send.

    Replace Date with a date object, such as
     
  5. @Zombie_Striker Tried, But I can still log in, Lmao

    Code:
            if (p.getLocation().distanceSquared(hitloc) <= 0.01D) {
               if (antiKb.containsKey(p)) {
                 if (((Integer) antiKb.get(p)).intValue() >= 3) {
                   System.out.println(antiKb.get(p));
                   antiKb.remove(p);
                   p.kickPlayer(ChatColor.translateAlternateColorCodes('&', "&4[&6MAH&4] &7You have been temp banned by the CatCraft AntiCheat.\n&cReason: &7Anti-Knockback / Knockback modifier.\n\n&4Time: &e60&6" + " minutes." + " \n\n&c&nInfo&r\n \n&cDeveloper: &7MindlessMink\n &cOwner: &7catman2014_ \n \n&7If you were unfairly punished,\n &7Please contact a server developer."));
                   Bukkit.getBanList(BanList.Type.NAME).addBan(p.getName(), ChatColor.translateAlternateColorCodes('&', "&4[&6MAH&4] &7You have been temp banned by the CatCraft AntiCheat.\n&cReason: &7Anti-Knockback / Knockback modifier.\n\n&4Time: &e60&6" + " minutes." + " \n\n&c&nInfo&r\n \n&cDeveloper: &7MindlessMink\n &cOwner: &7catman2014_ \n \n&7If you were unfairly punished,\n &7Please contact a server developer."), new Date(2016 ,9 ,7), null);
                   for (Player pl : Bukkit.getOnlinePlayers()) {
                     if (pl.hasPermission("mah.notify")) {
                       pl.sendMessage(ChatColor.translateAlternateColorCodes('&',
                           "&3&k,&4[&6MAH&4]&3&k, &e" + p.getName() + " &6was punished for AntiKnockback hacking."));
                       new FancyMessage("(Hover for more info!)").color(ChatColor.GRAY)
                           .tooltip(ChatColor.translateAlternateColorCodes('&', "&3&k,&4[&6MAH&4]&3&k, &eAntiKnockBack hack info:\n\n&6AntiKnockback is a hack that allows the user to take no knockback,\n&6Or modify their current knockback. This Player was not lagging,\n&6And was tested multiple ways to ensure he was not false banned.\nzn&cThank you :)"))
                           .send(pl);
                     }
                   }
    
    Yes, I just copied the one you sent me. Lol.
     
  6. Offline

    Zombie_Striker

    @Mindlessmink
    That is because you provided todays date. That means the ban will be lifted today. Change the "7" to an "8"
     
    Last edited: Sep 7, 2016
  7. @Zombie_Striker, But that's the thing. I want to ban them for 1 hour not one day. However, I was wondering if you could provide just one hour ahead of the current time of banning the user.

    Using this method would mean I'd have to change the code every day, which would not be convenient.

    Also, sorry for late reply. Was busy with homework
     
  8. Offline

    Zombie_Striker

    @Mindlessmink
    If you look at the parameters for the Date object, you can use the following for banning for just one hour.
    Code:
    Date date = new Date();
    date.setHour(date.getHour()+1);
    //then ban for that date.
     
    Mindlessmink likes this.
  9. Offline

    BeastyBoo

    Use UUID's instead of the players name. At least thats useful incase they change their names in my experience.
     
  10. @BeastyBoo yeah, I've UUID // IP Banned for more extreme measures. But for Anti-Knockback, This is a rather minimal offence. So I don't want to go with too many extreme measures.

    @Zombie_Striker thanks a lot, dude. Helped me out so much, Will try method right now.

    EDIT: Okay, Problemo solved, However. I do not want this ugly ban message layout.
    Is there any possible way to remove it?

    The white bit up the top,
    "You are banned from this server!"
    "Reason: Then my ban message."

    Example: https://gyazo.com/7c39636bba9c35e21cedc3a225978411

    BUMP
     
    Last edited: Sep 8, 2016
  11. BUMP

    Edit: not sure if I'm allowed to double post, I think I am 'cause the last one was yesterday :p

    I can't be bothered having that Tim's dumb bot messaging me .-.
     
  12. Offline

    Zombie_Striker

    @Mindlessmink
    No, the default message will always be used. If you want, try adding more new lines above and below the message. Hopefully, you are able to move the default message above the player's screen.
     
  13. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page