So pretty much I am making an anti-swear plugin. Simple right? XD I have the listener set up and everything, but I am wondering how I can get a list of data (swear words lol) imported into my plugin. Otherwise, I will have to do a long, tedious, "if" statement that has stringContains "F***" || stringContains "S***" etc, etc, etc. Thanks guys
Code:java for(String word : this.getConfig().getStringList("swearwords")){ if(msg.contains(word)){ //There is a swear word }}
Thanks a bunch. I want to have it temp-ban after repeated attempts. How would I implement this (3 warnings, then tempban) Thanks! Also, how do you get the text all formatted for java on the forums like you did??
So, one more thing. I was messing around with the bit of code you gave me, and it said "The method getConfig() is undefined for the type SwearListener" Here is my code: Code:java package me.CaptainXD.iTitanium; import org.bukkit.ChatColor;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerChatEvent; @SuppressWarnings("deprecation")public class SwearListener implements Listener {@EventHandlerpublic void onSwear(PlayerChatEvent event) { Player player = event.getPlayer(); for(String word : this.getConfig().getStringList("SwearWords")){if(event.getMessage().toLowerCase().contains(word)) {event.setCancelled(true);event.getPlayer().kickPlayer("Swearing is " + ChatColor.DARK_RED + "NOT" + ChatColor.GRAY + " allowed");//There is a swear word}}}} Does the fact that the config is empty trigger this? Or is it something else? Thanks
Sorry to jump in on a random topic, but i think i see whats wrong with it. I believe you need to add a constructor to your listener class, so you can get methods such as getConfig(), getServer(), etc..., out of your main class. Here's the code: Code:java public nameOfMainClass plugin; public void nameOfYourListener(nameOfMainClass i) {i = plugin;} Then just use plugin.getConfig(), plugin.getServer(), or for any other methods you need. Hope this helps!
CaptainXD Learn some very basic Java before jumping into a plugin. I recommend using the Bukkit Wiki.
We developed our Swear.jar for Drewpercraft about two years ago. It lets you manage the swear words and implements a smart filter to keep the potty mouths from using punctuation, spacing, etc to avoid exact matches, while also allowing you to whitelist words like assassin. Source.Jar can be downloaded from http://www.drewpercraft.com/index.php?board=11.0 Hitechwizard