Skip to content
Browse files

Added: blacklist of words

Changed: Much config stuff with try/catch
  • Loading branch information...
1 parent bcfe831 commit 769a390c6f836c9815cf00d3e07480477c56b2a7 @timbru31 committed
View
1 src/bannedWords.txt
@@ -0,0 +1 @@
+God
View
22 src/de/xghostkillerx/colorme/Actions.java
@@ -1,5 +1,7 @@
package de.xghostkillerx.colorme;
+import java.io.IOException;
+
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -127,7 +129,11 @@ static boolean set(String name, String value, String world, String pluginPart) {
}
// Write to the config and save and update the names
ColorMe.players.set(name + "." + pluginPart + "." + world, value);
- ColorMe.savePlayers();
+ try {
+ ColorMe.players.save(ColorMe.playersFile);
+ } catch (IOException e) {
+ ColorMe.log.warning("ColorMe failed to save the player.yml! Please report this! IOException");
+ }
checkNames(name, world);
return true;
}
@@ -153,7 +159,11 @@ static boolean remove(String name, String world, String pluginPart) {
// If the player has got a color
if (has(name, world, pluginPart)) {
ColorMe.players.set(name + "." + pluginPart + "." + world, "");
- ColorMe.savePlayers();
+ try {
+ ColorMe.players.save(ColorMe.playersFile);
+ } catch (IOException e) {
+ ColorMe.log.warning("ColorMe failed to save the players.yml! Please report this! IOException");
+ }
checkNames(name, world);
return true;
}
@@ -163,7 +173,11 @@ static boolean remove(String name, String world, String pluginPart) {
// Removes a color/prefix/suffix if exists, otherwise returns false
static boolean removeGlobal(String pluginPart) {
ColorMe.config.set("global_default." + pluginPart, "");
- ColorMe.saveConfigs();
+ try {
+ ColorMe.config.save(ColorMe.configFile);
+ } catch (IOException e) {
+ ColorMe.log.warning("ColorMe failed to save the config.yml! Please report this! IOException");
+ }
return false;
}
@@ -254,7 +268,7 @@ static void restoreName(String name) {
}
player.setPlayerListName(newName);
}
- if (ColorMe.spoutEnabled == true && playerTitle == true) {
+ if (ColorMe.spoutEnabled && playerTitle) {
SpoutPlayer spoutPlayer = (SpoutPlayer) player;
spoutPlayer.resetTitle();
}
View
184 src/de/xghostkillerx/colorme/ColorMe.java
@@ -14,6 +14,7 @@
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@@ -47,13 +48,14 @@
private final ColorMeBlockListener blockListener = new ColorMeBlockListener(this);
public Economy economy = null;
public static FileConfiguration config, players, localization, colors;
- public static File configFile, playersFile, localizationFile, colorsFile;
- public static boolean spoutEnabled, Prefixer, Suffixer, globalSuffix, globalPrefix, globalColor, chatBrackets, chatColors, signColors, newColorOnJoin, displayAlwaysGlobalPrefix, displayAlwaysGlobalSuffix;
+ public static File configFile, playersFile, localizationFile, colorsFile, bannedWordsFile;
+ public static boolean spoutEnabled, Prefixer, Suffixer, globalSuffix, globalPrefix, globalColor, chatBrackets, chatColors, signColors, newColorOnJoin, displayAlwaysGlobalPrefix, displayAlwaysGlobalSuffix, blacklist;
public static int prefixLength, suffixLength;
private ColorMeCommands colorExecutor;
private PrefixCommands prefixExecutor;
private SuffixCommands suffixExecutor;
public List<String> values = new ArrayList<String>();
+ public static List<String> bannedWords = new ArrayList<String>();
// Shutdown
public void onDisable() {
@@ -76,13 +78,7 @@ public void onEnable() {
copy(getResource("players.yml"), playersFile);
}
// Try to load
- try {
- players = YamlConfiguration.loadConfiguration(playersFile);
- }
- // Log if failed
- catch (Exception e) {
- log.warning("ColorMe failed to load the players.yml! Please report this!");
- }
+ players = YamlConfiguration.loadConfiguration(playersFile);
// Custom colors config
colorsFile = new File(getDataFolder(), "colors.yml");
@@ -92,13 +88,7 @@ public void onEnable() {
copy(getResource("colors.yml"), colorsFile);
}
// Try to load
- try {
- colors = YamlConfiguration.loadConfiguration(colorsFile);
- }
- // Log if failed
- catch (Exception e) {
- log.warning("ColorMe failed to load the colors.yml! Please report this!");
- }
+ colors = YamlConfiguration.loadConfiguration(colorsFile);
// Config
configFile = new File(getDataFolder(), "config.yml");
@@ -116,13 +106,22 @@ public void onEnable() {
copy(getResource("localization.yml"), localizationFile);
}
// Try to load
- try {
- localization = YamlConfiguration.loadConfiguration(localizationFile);
- loadLocalization();
- }
- // If it failed, tell it
- catch (Exception e) {
- log.warning("ColorMe failed to load the localization!");
+ localization = YamlConfiguration.loadConfiguration(localizationFile);
+ loadLocalization();
+
+ if (config.getBoolean("useWordBlacklist")) {
+ // BannedWords file
+ bannedWordsFile = new File(getDataFolder(), "bannedWords.txt");
+ if(!bannedWordsFile.exists()){
+ bannedWordsFile.getParentFile().mkdirs();
+ copy(getResource("bannedWords.txt"), bannedWordsFile);
+ }
+ // Try to load
+ try {
+ loadBannedWords();
+ } catch (IOException e) {
+ log.warning("ColorMe failed to load the bannedWords.txt! Please report this! IOException");
+ }
}
// Force to update the config (remove empty lines)
@@ -130,8 +129,8 @@ public void onEnable() {
try {
updateConfig(playersFile);
}
- catch (Exception e) {
- log.warning("ColorMe failed to update the config! Please report this!");
+ catch (IOException e) {
+ log.warning("ColorMe failed to update the config! Please report this! IOExcpetion");
}
finally {
config.set("updateConfig", false);
@@ -160,7 +159,8 @@ public void onEnable() {
// If Vault is enabled, load the economy
log.info(pdfFile.getName() + " loaded Vault successfully");
setupEconomy();
- } else {
+ }
+ else {
// Else tell the admin about the missing of Vault
log.warning("Vault was NOT found! Running without economy!");
}
@@ -178,6 +178,9 @@ public void onEnable() {
spoutEnabled = false;
}
+ // What is enabled?
+ checkParts();
+
// Stats
checkStatsStuff();
try {
@@ -200,11 +203,28 @@ public int getValue() {
metrics.start();
}
catch (IOException e) {}
+ }
- checkParts();
+
+ // If no config is found, copy the default one(s)!
+ private void copy(InputStream in, File file) {
+ try {
+ OutputStream out = new FileOutputStream(file);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ in.close();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
}
- public void updateConfig(File config) throws Exception {
+ // Remove empty lines
+ public void updateConfig(File config) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(config));
File tempFile = new File(getDataFolder(), "temp.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
@@ -228,16 +248,18 @@ public void updateConfig(File config) throws Exception {
}
}
- private void checkStatsStuff() {
- if (Prefixer) values.add("Prefixer");
- if (Suffixer) values.add("Suffixer");
- if (config.getBoolean("ColorMe.displayName")) values.add("ColorMe - displayName");
- if (config.getBoolean("ColorMe.tabList")) values.add("ColorMe - tabList");
- if (config.getBoolean("ColorMe.playerTitle")) values.add("ColorMe - playerTitle");
- if (chatColors) values.add("ColorMe - chatColors");
- if (signColors) values.add("ColorMe - signColors");
+ // Load the banned words
+ private void loadBannedWords() throws IOException{
+ BufferedReader reader = new BufferedReader(new FileReader(bannedWordsFile));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ if (line.isEmpty()) continue;
+ bannedWords.add(line);
+ }
+ reader.close();
}
+
// Loads the config at the start
public void loadConfig() {
config.options().header("For help please refer to http://bit.ly/colormebukkit or http://bit.ly/bukkitdevcolorme");
@@ -271,6 +293,7 @@ public void loadConfig() {
config.addDefault("newColorOnJoin" , false);
config.addDefault("displayAlways.globalSuffix", false);
config.addDefault("displayAlways.globalPefix", false);
+ config.addDefault("useWordBlacklist", true);
config.options().copyDefaults(true);
saveConfig();
}
@@ -362,30 +385,38 @@ public void loadLocalization() {
localization.addDefault("help_prefix_9", "/suffixer global <suffix> - Sets the global suffix");
localization.addDefault("custom_colors_enabled", "&4Custom colors are enabled, too! Please ask your admin for them!");
localization.addDefault("too_long", "&4Sorry, this message is too long!");
+ localization.addDefault("bad_words", "&4Sorry,but '%s' is on the blacklist!");
localization.options().copyDefaults(true);
- saveLocalization();
+ try {
+ localization.save(localizationFile);
+ } catch (IOException e) {
+ log.warning("ColorMe failed to save the localization! Please report this! IOException");
+ }
}
// Reloads the config via command /colorme reload, /prefixer reload or /suffixer reload
public static void loadConfigsAgain() {
try {
config.load(configFile);
- saveConfigs();
+ config.save(configFile);
players.load(playersFile);
- savePlayers();
+ players.save(playersFile);
localization.load(localizationFile);
- saveLocalization();
+ localization.save(localizationFile);
colors.load(colorsFile);
- saveColors();
+ colors.save(colorsFile);
checkParts();
}
- catch (Exception e) {
- log.warning("ColorMe failed to load the configs! Please report this!");
+ catch (IOException e) {
+ log.warning("ColorMe failed to load the configs! Please report this! IOException");
+ }
+ catch (InvalidConfigurationException e) {
+ log.warning("ColorMe failed to load the configs! Please report this! InvalidConfigurationException");
}
}
+ // Maybe something changed on the fly
private static void checkParts() {
- // Maybe something changed on the fly
Suffixer = config.getBoolean("Suffixer");
Prefixer = config.getBoolean("Prefixer");
chatBrackets = config.getBoolean("chatBrackets");
@@ -399,62 +430,18 @@ private static void checkParts() {
newColorOnJoin = config.getBoolean("newColorOnJoin");
displayAlwaysGlobalPrefix = config.getBoolean("displayAlways.globalPefix");
displayAlwaysGlobalSuffix = config.getBoolean("displayAlways.globalSuffix");
+ blacklist = config.getBoolean("useWordBlacklist");
}
- // Try to save the players.yml
- public static void savePlayers() {
- try {
- players.save(playersFile);
- } catch (Exception e) {
- log.warning("ColorMe failed to save the players.yml! Please report this!");
- }
- }
-
- // Saves the localization
- public static void saveLocalization() {
- try {
- localization.save(localizationFile);
- }
- catch (IOException e) {
- log.warning("ColorMe failed to save the localization! Please report this!");
- }
- }
-
- // Saves the config
- public static void saveConfigs() {
- try {
- config.save(configFile);
- }
- catch (IOException e) {
- log.warning("ColorMe failed to save the config! Please report this!");
- }
- }
-
- // Saves the colors file
- public static void saveColors() {
- try {
- colors.save(colorsFile);
- }
- catch (IOException e) {
- log.warning("ColorMe failed to save the colors! Please report this!");
- }
- }
-
- // If no config is found, copy the default one(s)!
- private void copy(InputStream in, File file) {
- try {
- OutputStream out = new FileOutputStream(file);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- out.close();
- in.close();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
+ // Used for Metrics
+ private void checkStatsStuff() {
+ if (Prefixer) values.add("Prefixer");
+ if (Suffixer) values.add("Suffixer");
+ if (config.getBoolean("ColorMe.displayName")) values.add("ColorMe - displayName");
+ if (config.getBoolean("ColorMe.tabList")) values.add("ColorMe - tabList");
+ if (config.getBoolean("ColorMe.playerTitle")) values.add("ColorMe - playerTitle");
+ if (chatColors) values.add("ColorMe - chatColors");
+ if (signColors) values.add("ColorMe - signColors");
}
// Initialized to work with Vault
@@ -475,6 +462,7 @@ public static void message(CommandSender sender, Player player, String message,
.replaceAll("%color", value)
.replaceAll("%prefix", value)
.replaceAll("%suffix", value)
+ .replaceAll("%s", value)
.replaceAll("%player", target)
.replaceAll("%version", "3.5");
if (cost != null) {
View
4 src/de/xghostkillerx/colorme/ColorMeCommands.java
@@ -74,6 +74,7 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
+ // Else set the global color
ColorMe.config.set("global_default.color", globalColor);
ColorMe.globalColor = true;
plugin.saveConfig();
@@ -222,8 +223,8 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
ColorMe.message(sender, null, message, null, world, target, null);
return true;
}
- color = Actions.get(target, world, pluginPart).toLowerCase();
// Gets color
+ color = Actions.get(target, world, pluginPart).toLowerCase();
if (target.equalsIgnoreCase(senderName)) {
message = ColorMe.localization.getString("get_color_self");
ColorMe.message(sender, null, message, color, world, null, null);
@@ -253,6 +254,7 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
return true;
}
}
+ // Is a world explicit named? Also lower case
color = args[1].toLowerCase();
senderName = sender.getName().toLowerCase();
if (args.length > 2) {
View
23 src/de/xghostkillerx/colorme/ColorMePlayerListener.java
@@ -1,5 +1,7 @@
package de.xghostkillerx.colorme;
+import java.io.IOException;
+
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -61,7 +63,6 @@ public void onPlayerChat(PlayerChatEvent event) {
// Get world prefix if available
if (Actions.has(name, world, "prefix")) {
prefix = Actions.get(name, world, "prefix");
- //mhm.put(name, prefix);
}
// Get default prefix
else if (Actions.has(name, "default", "prefix")) {
@@ -75,6 +76,7 @@ else if (ColorMe.globalPrefix) {
if (prefix != null) {
event.setFormat(prefix + ChatColor.WHITE + " " + event.getFormat());
}
+ // Display global one, too?
if (ColorMe.globalPrefix && ColorMe.displayAlwaysGlobalPrefix) {
globalPrefix = Actions.getGlobal("prefix");
event.setFormat(globalPrefix + ChatColor.WHITE + " " + event.getFormat());
@@ -93,7 +95,6 @@ else if (Actions.has(name, "default", "suffix")) {
else if (ColorMe.globalSuffix) {
suffix = Actions.getGlobal("suffix");
}
- // If suffix is not null
// Search the bracket
if (event.getFormat().contains(">")) {
int i = event.getFormat().lastIndexOf(">") + 1;
@@ -140,17 +141,29 @@ private void CheckRoutine(Player player, String name, String world) {
ColorMe.players.set(name + ".colors." + world, "");
ColorMe.players.set(name + ".prefix." + world, "");
ColorMe.players.set(name + ".suffix." + world, "");
- ColorMe.savePlayers();
+ try {
+ ColorMe.players.save(ColorMe.playersFile);
+ } catch (IOException e) {
+ ColorMe.log.warning("ColorMe failed to save the players.yml! Please report this! IOException");
+ }
}
for (int i = 0; i <= 2; i++) {
String actualPart = pluginPart[i];
if (!ColorMe.players.contains(name + "." + actualPart + "." + world)) {
ColorMe.players.set(name + "." + actualPart + "." + world, "");
- ColorMe.savePlayers();
+ try {
+ ColorMe.players.save(ColorMe.playersFile);
+ } catch (IOException e) {
+ ColorMe.log.warning("ColorMe failed to save the players.yml! Please report this! IOException");
+ }
}
if (!ColorMe.players.contains(name + "." + actualPart + "." + "default")) {
ColorMe.players.set(name + "." + actualPart + "." + "default", "");
- ColorMe.savePlayers();
+ try {
+ ColorMe.players.save(ColorMe.playersFile);
+ } catch (IOException e) {
+ ColorMe.log.warning("ColorMe failed to save the players.yml! Please report this! IOException");
+ }
}
}
Actions.checkNames(name, world);
View
35 src/de/xghostkillerx/colorme/PrefixCommands.java
@@ -8,7 +8,7 @@
import org.bukkit.entity.Player;
public class PrefixCommands implements CommandExecutor {
-
+
ColorMe plugin;
public PrefixCommands(ColorMe instance) {
plugin = instance;
@@ -50,6 +50,17 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
+ // If sender hasn't got the noFilter permission look if there are bad words in!
+ if (ColorMe.blacklist && !sender.hasPermission("prefixer.nofilter")) {
+ for (String s : ColorMe.bannedWords) {
+ if (globalPrefix.contains(s)) {
+ // Message, bad words in etc.
+ message = ColorMe.localization.getString("bad_words");
+ ColorMe.message(sender, null, message, s, null, null, null);
+ return true;
+ }
+ }
+ }
// Check if the message is too long
if (ChatColor.stripColor(Actions.replaceThings(globalPrefix)).length() > ColorMe.prefixLength) {
message = ColorMe.localization.getString("too_long");
@@ -255,6 +266,17 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
// Self prefixing
if (sender.hasPermission("prefixer.self") && Actions.self(sender, target)) {
+ // If sender hasn't got the noFilter permission look if there are bad words in!
+ if (ColorMe.blacklist && !sender.hasPermission("prefixer.nofilter")) {
+ for (String s : ColorMe.bannedWords) {
+ if (prefix.contains(s)) {
+ // Message, bad words in etc.
+ message = ColorMe.localization.getString("bad_words");
+ ColorMe.message(sender, null, message, s, null, null, null);
+ return true;
+ }
+ }
+ }
// Check if the message is too long
if (ChatColor.stripColor(Actions.replaceThings(prefix)).length() > ColorMe.prefixLength) {
message = ColorMe.localization.getString("too_long");
@@ -300,6 +322,17 @@ else if (plugin.economy != null) {
}
// Prefixing other
else if (sender.hasPermission("prefixer.other") && !Actions.self(sender, target)) {
+ // If sender hasn't got the noFilter permission look if there are bad words in!
+ if (ColorMe.blacklist && !sender.hasPermission("prefixer.nofilter")) {
+ for (String s : ColorMe.bannedWords) {
+ if (prefix.contains(s)) {
+ // Message, bad words in etc.
+ message = ColorMe.localization.getString("bad_words");
+ ColorMe.message(sender, null, message, s, null, null, null);
+ return true;
+ }
+ }
+ }
// Check if the message is too long
if (ChatColor.stripColor(Actions.replaceThings(prefix)).length() > ColorMe.prefixLength) {
message = ColorMe.localization.getString("too_long");
View
33 src/de/xghostkillerx/colorme/SuffixCommands.java
@@ -50,6 +50,17 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
+ // If sender hasn't got the noFilter permission look if there are bad words in!
+ if (ColorMe.blacklist && !sender.hasPermission("suffixer.nofilter")) {
+ for (String s : ColorMe.bannedWords) {
+ if (globalSuffix.contains(s)) {
+ // Message, bad words in etc.
+ message = ColorMe.localization.getString("bad_words");
+ ColorMe.message(sender, null, message, s, null, null, null);
+ return true;
+ }
+ }
+ }
// Check if the message is too long
if (ChatColor.stripColor(Actions.replaceThings(globalSuffix)).length() > ColorMe.suffixLength) {
message = ColorMe.localization.getString("too_long");
@@ -255,6 +266,17 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
// Self suffixing
if (sender.hasPermission("suffixer.self") && Actions.self(sender, target)) {
+ // If sender hasn't got the noFilter permission look if there are bad words in!
+ if (ColorMe.blacklist && !sender.hasPermission("suffixer.nofilter")) {
+ for (String s : ColorMe.bannedWords) {
+ if (suffix.contains(s)) {
+ // Message, bad words in etc.
+ message = ColorMe.localization.getString("bad_words");
+ ColorMe.message(sender, null, message, s, null, null, null);
+ return true;
+ }
+ }
+ }
// Check if the message is too long
if (ChatColor.stripColor(Actions.replaceThings(suffix)).length() > ColorMe.suffixLength) {
message = ColorMe.localization.getString("too_long");
@@ -300,6 +322,17 @@ else if (plugin.economy != null) {
}
// Suffixing other
else if (sender.hasPermission("suffixer.other") && !Actions.self(sender, target)) {
+ // If sender hasn't got the noFilter permission look if there are bad words in!
+ if (ColorMe.blacklist && !sender.hasPermission("suffixer.nofilter")) {
+ for (String s : ColorMe.bannedWords) {
+ if (suffix.contains(s)) {
+ // Message, bad words in etc.
+ message = ColorMe.localization.getString("bad_words");
+ ColorMe.message(sender, null, message, s, null, null, null);
+ return true;
+ }
+ }
+ }
// Check if the message is too long
if (ChatColor.stripColor(Actions.replaceThings(suffix)).length() > ColorMe.suffixLength) {
message = ColorMe.localization.getString("too_long");
View
12 src/plugin.yml
@@ -1,6 +1,6 @@
name: ColorMe
main: de.xghostkillerx.colorme.ColorMe
-version: 3.5 dev3
+version: 3.5 dev4
author: xGhOsTkiLLeRx
authors: [Valrix]
website: http://bit.ly/bukkitdevcolorme
@@ -13,9 +13,11 @@ commands:
description: Gives the player name a color
prefix:
usage: /prefix help - to see the help
+ aliases: [prefixme, prefixer]
description: Gives the player name a prefix
suffix:
usage: /suffix help - to see the help
+ aliases: [suffixme, suffixer]
description: Gives the player name a suffix
permissions:
colorme.list:
@@ -165,6 +167,9 @@ permissions:
prefixer.free:
default: op
description: No costs for prefixing
+ prefixer.nofilter:
+ default: op
+ description: No filter for prefixing
prefixer.*:
children:
prefixer.list: true
@@ -174,6 +179,7 @@ permissions:
prefixer.get: true
prefixer.global: true
prefixer.free: true
+ prefixer.nofilter: true
description: Allows all commands for Prefixer
suffixer.list:
default: true
@@ -196,6 +202,9 @@ permissions:
suffixer.free:
default: op
description: No costs for suffixing
+ suffixer.nofilter:
+ default: op
+ description: No filter for suffixing
suffixer.*:
children:
suffixer.list: true
@@ -205,5 +214,6 @@ permissions:
suffixer.get: true
suffixer.global: true
suffixer.free: true
+ suffixer.nofilter: true
description: Allows all commands for Suffixer
softdepend: [Vault, Spout]

0 comments on commit 769a390

Please sign in to comment.
Something went wrong with that request. Please try again.