Solved e.setCancelled(true) does not work

Discussion in 'Plugin Development' started by JookerPlays, Dec 24, 2017.

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

    JookerPlays

    Hello, my name is Fabio and i developed a plugin but, this code doesn't works. Help me please

    Main:
    Code:
    Bukkit.getPluginManager().registerEvents(new PunicoesList(), this);
    Code of PlayerChatEvent
    Code:
    public void onChatMute(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            try {
                PreparedStatement search = (PreparedStatement)SqlConnector.con.prepareStatement("SELECT * FROM `jogadores` WHERE `Nick`='"+ p.getName() + "' OR `UUID`='" + p.getUniqueId().toString()+"'");
                ResultSet rs = search.executeQuery();
                if(rs.next()) {
                    if(rs.getString("mute").equals("true")) {
                        String motivo = rs.getString("mutemo");
                        int tempo = rs.getInt("mutetemp");
                        if(tempo == 0) {
                            p.sendMessage("§cVoce esta mutado permanentemente por: " + motivo);
                            e.setCancelled(true);
                        }else {
                            long milisec = rs.getLong("mutesec");
                            long amilisec = System.currentTimeMillis();
                            long temppmili = tempo * 60000;
                            long tempomutado = amilisec - milisec;
                            if(tempomutado >=temppmili) {
                                p.sendMessage("not muted2");
                                mutados.remove(p.getName());
                            }else {
                                mutados.add(p.getName());
                                tempomutado = tempomutado / 60000;
                                long temporest = tempo - tempomutado;
                                p.sendMessage("§cVoce esta mutado por mais " + temporest + " minutos por: " + motivo);
                            }
                        }
                    }else {
                        e.setCancelled(false);
                        p.sendMessage("not muted");
                    }
                }
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
    Print: https://prnt.sc/hrpxmx
     
  2. Offline

    timtower Administrator Administrator Moderator

    @JookerPlays Never call e.setCancelled(false); please, other plugins might be using it.
     
  3. Offline

    JookerPlays

    Ok, but, tell me please, what another plugin?
     
  4. Offline

    timtower Administrator Administrator Moderator

    Other plugins might be cancelling the chat as well, with that line you undo that change.

    And it looks like you only cancel it in 1 occasion, when tempo==0, not when tempo!=0
     
  5. Offline

    JookerPlays

    Ok but if tempo is 0 the mute is permanent. So legend chat? EssentialsChat?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @JookerPlays But shouldn't the message be stopped when it isn't as well?
    And you don't understand.
    Using setCancelled(false) will override plugins that already cancelled the event, you shouldn't be doing that.
     
  7. Offline

    Unknown123

Thread Status:
Not open for further replies.

Share This Page