mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user