Added config option to disable Chat distortion

Closes: #125
This commit is contained in:
Sn0wStorm 2016-06-28 16:04:45 +02:00
parent 2d714d25e2
commit 82223aafe1
7 changed files with 159 additions and 48 deletions

View File

@ -65,7 +65,7 @@ updateCheck: true
autosave: 3
# Config Version
version: '1.4'
version: '1.5'
# -- Rezepte für Getränke --
@ -268,6 +268,12 @@ useLogBlock: true
# -- Chat Veränderungs Einstellungen --
# Ob geschriebener Chat bei großer Trunkenheit abgefälscht werden soll,
# so dass es etwas betrunken aussieht was geschrieben wird.
# Wie stark der Chat verändert wird hängt davon ab wie betrunken der Spieler ist
# Unten kann noch eingestellt werden wie und was verändert wird
enableChatDistortion: true
# Text nach den angegebenen Kommandos wird bei Trunkenheit ebenfalls Verändert (Liste) [- /gl]
distortCommands:
- /gl
@ -293,6 +299,7 @@ distortCommands:
distortSignText: false
# Im Chat geschriebener Text, der zwischen diesen Buchstaben steht, wird nicht verändert ("," als Trennung verwenden) (Liste) [- '[,]']
# Also zum Beispiel im Chat: Hallo ich bin betrunken *Ich teste Brewery*
distortBypass:
- '*,*'
- '[,]'

View File

@ -62,7 +62,7 @@ updateCheck: true
autosave: 3
# Config Version
version: '1.4'
version: '1.5'
# -- Recipes for Potions --
@ -266,6 +266,12 @@ useLogBlock: true
# -- Chat Distortion Settings --
# If written Chat is distorted when the Player is Drunk,
# so that it looks like drunk writing
# How much the chat is distorted depends on how drunk the Player is
# Below are settings for what and how changes in chat occur
enableChatDistortion: true
# Log to the Serverlog what the player actually wrote, before his words were altered [false]
logRealChat: false
@ -294,6 +300,7 @@ distortCommands:
distortSignText: false
# Enclose a Chat text with these Letters to bypass Chat Distortion (Use "," as Separator) (list) [- '[,]']
# Chat Example: Hello i am drunk *I am testing Brewery*
distortBypass:
- '*,*'
- '[,]'

View File

@ -62,7 +62,7 @@ updateCheck: true
autosave: 3
# Version de configuration
version: '1.4'
version: '1.5'
# -- Recette pour les boissons --
@ -271,6 +271,12 @@ useLogBlock: true
# -- Paramètres de la distorsion du Chat --
# If written Chat is distorted when the Player is Drunk,
# so that it looks like drunk writing
# How much the chat is distorted depends on how drunk the Player is
# Below are settings for what and how changes in chat occur
enableChatDistortion: true
# Ecrire dans les "logs" du serveur ce que le joueur devrait dire, à la place de la distorsion. [false]
logRealChat: false
@ -299,6 +305,7 @@ distortCommands:
distortSignText: false
# Entourer les textes avec ces caractères pour ignorer la distorsion (Utilisez "," comme un séparateur) (list) [- '[,]']
# Chat Example: Hello i am drunk *I am testing Brewery*
distortBypass:
- '*,*'
- '[,]'

View File

@ -62,7 +62,7 @@ updateCheck: true
autosave: 3
# Versione del config
version: '1.4'
version: '1.5'
# -- Ricette per pozioni --
@ -266,6 +266,12 @@ useLogBlock: true
# -- Imostazioni di distorsione della chat --
# If written Chat is distorted when the Player is Drunk,
# so that it looks like drunk writing
# How much the chat is distorted depends on how drunk the Player is
# Below are settings for what and how changes in chat occur
enableChatDistortion: true
# Salva nel log del server quello che il giocatore ha realmente scritto, prima che le sue parole venissero alterate [false]
logRealChat: false
@ -294,6 +300,7 @@ distortCommands:
distortSignText: false
# Definisci dei caratteri fra cui inserire le parole per evitare la distorsione della chat (usa "," come separatore) (list) [- '[,]']
# Chat Example: Hello i am drunk *I am testing Brewery*
distortBypass:
- '*,*'
- '[,]'

View File

@ -35,7 +35,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class P extends JavaPlugin {
public static P p;
public static final String configVersion = "1.4";
public static final String configVersion = "1.5";
public static boolean debug;
public static boolean useUUID;
public static boolean use1_9;
@ -144,6 +144,7 @@ public class P extends JavaPlugin {
Wakeup.wakeups.clear();
Words.words.clear();
Words.ignoreText.clear();
Words.commands = null;
this.log(this.getDescription().getName() + " disabled!");
}
@ -164,6 +165,8 @@ public class P extends JavaPlugin {
BIngredients.recipes.clear();
BIngredients.cookedNames.clear();
Words.words.clear();
Words.ignoreText.clear();
Words.commands = null;
BPlayer.drainItems.clear();
if (useLB) {
try {
@ -289,12 +292,6 @@ public class P extends JavaPlugin {
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
PlayerListener.openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
Words.log = config.getBoolean("logRealChat", false);
Words.commands = config.getStringList("distortCommands");
Words.doSigns = config.getBoolean("distortSignText", false);
for (String bypass : config.getStringList("distortBypass")) {
Words.ignoreText.add(bypass.split(","));
}
// loading recipes
ConfigurationSection configSection = config.getConfigurationSection("recipes");
@ -360,8 +357,18 @@ public class P extends JavaPlugin {
}
}
// telling Words the path, it will load it when needed
Words.config = config;
// Loading Words
if (config.getBoolean("enableChatDistortion", false)) {
for (Map<?, ?> map : config.getMapList("words")) {
new Words(map);
}
for (String bypass : config.getStringList("distortBypass")) {
Words.ignoreText.add(bypass.split(","));
}
Words.commands = config.getStringList("distortCommands");
}
Words.log = config.getBoolean("logRealChat", false);
Words.doSigns = config.getBoolean("distortSignText", false);
return true;
}

View File

@ -1,15 +1,13 @@
package com.dre.brewery;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.lang.Character;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.block.SignChangeEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Words {
@ -18,7 +16,6 @@ public class Words {
public static ArrayList<Words> words = new ArrayList<>();
public static List<String> commands;
public static List<String[]> ignoreText = new ArrayList<>();
public static FileConfiguration config;
public static Boolean doSigns;
public static Boolean log;
private static Map<String, Long> waitPlayers = new HashMap<>();
@ -66,19 +63,11 @@ public class Words {
}
}
private static boolean loadWords() {
if (words.isEmpty()) {
// load when first drunk player talks
load();
}
return !words.isEmpty();
}
// Distort players words when he uses a command
public static void playerCommand(PlayerCommandPreprocessEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer());
if (bPlayer != null) {
if (!commands.isEmpty() && loadWords()) {
if (commands != null && !commands.isEmpty() && !words.isEmpty()) {
String name = event.getPlayer().getName();
if (!waitPlayers.containsKey(name) || waitPlayers.get(name) + 500 < System.currentTimeMillis()) {
String chat = event.getMessage();
@ -108,7 +97,7 @@ public class Words {
public static void signWrite(SignChangeEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer());
if (bPlayer != null) {
if (loadWords()) {
if (!words.isEmpty()) {
int index = 0;
for (String message : event.getLines()) {
if (message.length() > 1) {
@ -129,7 +118,7 @@ public class Words {
public static void playerChat(AsyncPlayerChatEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer());
if (bPlayer != null) {
if (loadWords()) {
if (!words.isEmpty()) {
String message = event.getMessage();
if (log) {
P.p.log(P.p.languageReader.get("Player_TriedToSay", event.getPlayer().getName(), message));
@ -282,13 +271,4 @@ public class Words {
return isBefore;
}
// load from config file
public static void load() {
if (config != null) {
for (Map<?, ?> map : config.getMapList("words")) {
new Words(map);
}
}
}
}

View File

@ -89,9 +89,10 @@ public class ConfigUpdater {
lang = "de";
}
}
boolean de = lang.equals("de");
if (fromVersion.equals("0.5") || fromVersion.equals("1.0")) {
if (lang.equals("de")) {
if (de) {
update05de();
} else {
update10en();
@ -99,7 +100,7 @@ public class ConfigUpdater {
fromVersion = "1.1";
}
if (fromVersion.equals("1.1") || fromVersion.equals("1.1.1")) {
if (lang.equals("de")) {
if (de) {
update11de();
} else {
update11en();
@ -108,7 +109,7 @@ public class ConfigUpdater {
}
if (fromVersion.equals("1.2")) {
if (lang.equals("de")) {
if (de) {
update12de();
} else {
update12en();
@ -117,7 +118,7 @@ public class ConfigUpdater {
}
if (fromVersion.equals("1.3")) {
if (lang.equals("de")) {
if (de) {
update13de();
} else {
update13en();
@ -126,7 +127,7 @@ public class ConfigUpdater {
}
if (fromVersion.equals("1.3.1")) {
if (lang.equals("de")) {
if (de) {
update131de();
} else {
update131en();
@ -134,7 +135,16 @@ public class ConfigUpdater {
fromVersion = "1.4";
}
if (!fromVersion.equals("1.4")) {
if (fromVersion.equals("1.4")) {
if (de) {
update14de();
} else {
update14en();
}
fromVersion = "1.5";
}
if (!fromVersion.equals("1.5")) {
P.p.log(P.p.languageReader.get("Error_ConfigUpdate", fromVersion));
return;
}
@ -899,5 +909,91 @@ public class ConfigUpdater {
}
// Update de from 1.4 to 1.5
private void update14de() {
updateVersion("1.5");
String[] lines = new String[] {"",
"# Ob geschriebener Chat bei großer Trunkenheit abgefälscht werden soll,",
"# so dass es etwas betrunken aussieht was geschrieben wird.",
"# Wie stark der Chat verändert wird hängt davon ab wie betrunken der Spieler ist",
"# Unten kann noch eingestellt werden wie und was verändert wird",
"enableChatDistortion: true"};
int index = indexOfStart("# -- Chat") + 2;
if (index == 1) {
index = indexOfStart("distortCommands:") - 1;
if (index == -2) {
index = indexOfStart("distortSignText:") - 1;
if (index == -2) {
index = indexOfStart("# words:");
if (index == -1) {
index = indexOfStart("words:");
}
}
}
}
if (index == -1) {
appendLines(lines);
} else {
addLines(index - 1, lines);
}
lines = new String[] {"# Also zum Beispiel im Chat: Hallo ich bin betrunken *Ich teste Brewery*"};
index = indexOfStart("# Im Chat geschriebener Text, der zwischen");
if (index != -1) {
addLines(index + 1, lines);
} else {
index = indexOfStart("distortBypass:");
if (index != -1) {
addLines(index, lines);
}
}
}
// Update de from 1.4 to 1.5
private void update14en() {
updateVersion("1.5");
String[] lines = new String[] {"",
"# If written Chat is distorted when the Player is Drunk,",
"# so that it looks like drunk writing",
"# How much the chat is distorted depends on how drunk the Player is",
"# Below are settings for what and how changes in chat occur",
"enableChatDistortion: true"};
int index = indexOfStart("# -- Chat") + 2;
if (index == 1) {
index = indexOfStart("distortCommands:") - 1;
if (index == -2) {
index = indexOfStart("distortSignText:") - 1;
if (index == -2) {
index = indexOfStart("# words:");
if (index == -1) {
index = indexOfStart("words:");
}
}
}
}
if (index == -1) {
appendLines(lines);
} else {
addLines(index - 1, lines);
}
lines = new String[] {"# Chat Example: Hello i am drunk *I am testing Brewery*"};
index = indexOfStart("# Enclose a Chat text with these Letters");
if (index != -1) {
addLines(index + 1, lines);
} else {
index = indexOfStart("distortBypass:");
if (index != -1) {
addLines(index, lines);
}
}
}
}