Help me with a listner

Discussion in 'Plugin Development' started by Danielh90, Dec 25, 2014.

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

    Danielh90

    k i have a listener called CommandopBlockListeners and what it does is when someone does /op it cancel the command out but i would like to get notifaction one some does it so i can monitor them and if they are trying to hack here is my code i think i got it basic :) done just need to add like someone name so
    Danielh90 someone is using /op <Playername> somthing like that
    Code:
    package com.danielh90.listeners;
    
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    
    
    
    public class CommandopBlockListeners implements Listener{
    
       
       
       
         @EventHandler
            public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
                    if (e.getPlayer().isOp()) {
                            return;
                    }
                  
                if (e.getMessage().startsWith("/op"))
                    {
                    e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&4you don't have permissions"));
                    e.setCancelled(true);
                           
                    }
            }
            
        }
    
     
  2. Offline

    mythbusterma

    @Danielh90

    Just send a message to anyone with a permission?
     
  3. Offline

    Danielh90

    can you give me the code because i can't make how to do it maybe
    (I AM NOOB LOL)
     
  4. Offline

    teej107

    goodbye every singe command that starts with /op. Well not really. "/oP"
     
  5. Offline

    Danielh90

    ???
     
  6. Offline

    teej107

    @Danielh90 Your code will cancel any command that starts with /op like /open for example. You aren't checking for uppercase lettering, anybody can bypass with "/oP".
     
  7. Offline

    caderape

    if (e.getmessage.tolowercase().startwith("/op "){
    e.setcancelled(true);
    for (Player p : bukkit.getonlineplayers){
    if (p.isop() {
    p.sendmessage("blabla is trying to op himself");

    the is really basic java. You should geta look to some tutos
     
  8. Offline

    teej107

  9. Offline

    stoneminer02

    Here is what caderape said(notice the spaces):
    Code:
    if(e.getMessage().toLowercase().startsWith("/op "))
        e.setCancelled(true);
    for(Player player : Bukkit.getOnlinePlayers())
      if(p.isOp())
        player.sendMessage(e.getPlayer() + " tried to do /op");
    But this still tho, can get bypassed with no spaces xD
     
  10. Offline

    teej107

    @stoneminer02 You are still making the same mistake. Nobody here said the complete correct solution yet. I've seen so many of these problems on here lately and they are doing it wrongly that it makes me want to create a resource thread about it. @Danielh90 Here is how to do it correctly:
    1. Get the message and make all the characters have a shared, common case. eg: toLowerCase() or toUpperCase() OR ignore this step and use equalsIgnoreCase() in step 3.
    2. Split the message by single whitespaces using split() like so: theString.split(" ")
    3. Now its the time to do the correct checking of the command so to check if "/op" was ran, it would be the 0 index in the array returned by the split() method.
     
Thread Status:
Not open for further replies.

Share This Page