Minecraft PC IP: play.cubecraft.net
Status
Not open for further replies.

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
People not gona use this for a alert/broadcast if you must to change the message in the config file and reload the server its not gona work
go work with agrs so players can do /bc hi and your ting say [alert] hi
I'll will rek you i start with coding now
You mean this?
Code:
    if (cmd.getName().equalsIgnoreCase("PB")) {
                int laengeArray = args.length;
                int indexArray = 0;
                String text = "";
                for (int i = 0; i < args.length; i++) {
                        text += args[i] + " ";
                }
                Bukkit.broadcastMessage(ChatColor.DARK_RED + "[Alert] " + ChatColor.RED +  text);
            }
        return true;
        }

PS: PB= Public Broadcast
PS2: The welcome message isn't usually changed, so it will stay in the config
 

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        Player player = (Player)sender;
        if (cmd.getName().equalsIgnoreCase("broadcast")) {
            if (player.hasPermission("CE.broadcast")) {
                Bukkit.broadcastMessage(ChatColor.RED + "[Alert]" + getConfig().getString("MessageToBroadcast"));
                return true;
            }

            if (cmd.getName().equalsIgnoreCase("ChatEssentials")) {
                player.sendMessage(ChatColor.DARK_BLUE + "----------------------------------------");
                player.sendMessage(ChatColor.BLUE + "ChatEssentials v1 by Hangar555");
                player.sendMessage(ChatColor.GREEN + "Commands:");
                player.sendMessage(ChatColor.DARK_GREEN + "/ChatEssentials" + ChatColor.GOLD + ":" + ChatColor.GREEN + "Displays this message");
                player.sendMessage(ChatColor.DARK_GREEN + "/Broadcast" + ChatColor.GOLD + ":" + ChatColor.GREEN + "Broadcast the message written inconfig.yml!");
                player.sendMessage(ChatColor.GREEN + "Info:");
                player.sendMessage(ChatColor.DARK_GREEN + "This plugin is able to edit player messages, to prevent curse words");
                player.sendMessage(ChatColor.DARK_GREEN + "It can also intercept heavy messages");
                player.sendMessage(ChatColor.DARK_GREEN + "You are not allowed to edit and/or copy the plugin without the developer permission");
                player.sendMessage(ChatColor.DARK_BLUE + "----------------------------------------");
            }

            return true;
        }

        if (cmd.getName().equalsIgnoreCase("PB")) {
            int laengeArray = args.length;
            int indexArray = 0;
            String text = "";
            for (int i = 0; i < args.length; i++) {
                text = text + args[i] + " ";
            }
            Bukkit.broadcastMessage(ChatColor.DARK_RED + "[Alert] " + ChatColor.RED + text);
        }
        return true;
    }
}
 

MagnificentSpam

Forum Expert
Mar 16, 2016
2,306
2,238
298
I like criticizing other peoples code, so...
@EventHandler
public void playerChatEvent(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
String message = event.getMessage();
if(message.contains("**** ***, *****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("**** *, *****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("*** ** ****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** **** *")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** *** *")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** *** ***")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** **** ***")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** **** ***")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("***** * ******* ****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

}
why not use a foreach loop there?
@EventHandler
public void playerChatEvent(AsyncPlayerChatEvent event) {
String[] blockedMessages = {
"**** ***, *****",
"**** *, *****",
"*** ** ****",
"* **** ** **** *",
"* **** ** *** *",
"* **** ** *** ***",
"* **** ** **** ***",
"***** * ******* ****"
};
for (String blockedMessage : blockedMessages) {
if(event.getMessage().contains(blockedMessage)) {
event.setCancelled(true);
event.getPlayer().sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
return;
}
}
}
This will also prevent you from getting THIS MESSAGE IS NOT ALLOWED multiple times if the message contains more than onw blocked phrase.

Also could you make it so the user can define the blocked words and the replaced words/replacements in a config file that is read in when the plugin is loaded?
And maybe a reload command if the user wants to edit the file while the server is running.
 

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
I like criticizing other peoples code, so...
@EventHandler
public void playerChatEvent(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
String message = event.getMessage();
if(message.contains("**** ***, *****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("**** *, *****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("*** ** ****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** **** *")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** *** *")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** *** ***")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** **** ***")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("* **** ** **** ***")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

if(message.contains("***** * ******* ****")) {
event.setCancelled(true);
player.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
}

}
why not use a foreach loop there?
@EventHandler
public void playerChatEvent(AsyncPlayerChatEvent event) {
String[] blockedMessages = {
"**** ***, *****",
"**** *, *****",
"*** ** ****",
"* **** ** **** *",
"* **** ** *** *",
"* **** ** *** ***",
"* **** ** **** ***",
"***** * ******* ****"
};
for (String blockedMessage : blockedMessages) {
if(event.getMessage().contains(blockedMessage)) {
event.setCancelled(true);
event.getPlayer().sendMessage("" + ChatColor.RED + ChatColor.BOLD + "THIS MESSAGE IS NOT ALLOWED");
return;
}
}
}
This will also prevent you from getting THIS MESSAGE IS NOT ALLOWED multiple times if the message contains more than onw blocked phrase.

Also could you make it so the user can define the blocked words and the replaced words/replacements in a config file that is read in when the plugin is loaded?
And maybe a reload command if the user wants to edit the file while the server is running.
The reason because it isn't added is simple: I wanted to check the reaction (and opinion) of the people on the forums, once the reaction its good, I'll make better things :P
 

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
From now, if you have any suggestion PM me. I'm working on the Final Relase (Will be also published on Spigot for free).

~If this can be locked will be awesome :D
 

ProSl3nderMan

Well-Known Member
May 16, 2016
71
4
83
24
Before it is locked, wanna ask if you covered the problem with not being able to say pass or grape or. I had that problem when I coded this.
 
Status
Not open for further replies.
Members Online

Team online

Latest profile posts

Tommy Boi wrote on xSchulzis's profile.
good job, good luck
Tommy Boi wrote on WorriedSkate940's profile.
Wow, congrats on Helper, man
good job, good luck
Tommy Boi wrote on Frontlane's profile.
good job, good luck
Eli
From musical hater to musical lover with a single trick: my girlfriend forced me to watch Hamilton 😂
UncleSpect wrote on xSchulzis's profile.
congratss!
Top Bottom