Distort Certain Commands

This commit is contained in:
Sn0wStorm 2013-11-17 15:26:28 +01:00
parent f4f0bc9511
commit 4e279fae2e
4 changed files with 83 additions and 12 deletions

View File

@ -1,7 +1,7 @@
# config for Brewery.jar
# Settings
# -- Settings --
# Defaults are written in []
# Deleting of single settings disables them
@ -36,7 +36,7 @@ enablePuke: true
# Item that is dropped multiple times uncollectable when puking [SOUL_SAND]
pukeItem: SOUL_SAND
# Consumable Item/strength. Decreases the alcohol level by <strength> when consumed.
# Consumable Item/strength. Decreases the alcohol level by <strength> when consumed. (list)
drainItems:
- BREAD/4
- MILK_BUCKET/2
@ -48,17 +48,14 @@ hangoverDays: 7
colorInBarrels: true
colorInBrewer: false
# Log to the Serverlog what the player actually wrote, before his words were altered [false]
logRealChat: false
# Autosave interval in minutes [3]
autosave: 3
# Config Version
version: '1.0'
version: '1.1'
# Recipes for Potions
# -- Recipes for Potions --
# name: Different names for bad/normal/good (Formatting codes possible: such as &6)
# ingredients: List of material/amount
@ -194,6 +191,27 @@ cooked:
# -- Chat Distortion Settings --
# Log to the Serverlog what the player actually wrote, before his words were altered [false]
logRealChat: false
# Text after specified commands will be distorted when drunk (list) [- /gl]
distortCommands:
- /gl
- /global
- /fl
- /s
- /letter
# Distort the Text written on a Sign while drunk [false]
distortSignText: false
# Enclose a text with these Letters to bypass Chat Distortion (Use "," as Seperator) (list) [- '[,]']
distortBypass:
- '*,*'
- '[,]'
# words: Words and letters that will be altered when chatting while being drunk.
# Will be processed from first to last and a written sentece is altered in that order.

View File

@ -184,6 +184,7 @@ public class P extends JavaPlugin {
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
Words.log = config.getBoolean("logRealChat", false);
Words.commands = config.getStringList("distortCommands");
// loading recipes
ConfigurationSection configSection = config.getConfigurationSection("recipes");

View File

@ -1,10 +1,14 @@
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.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import com.dre.brewery.BPlayer;
@ -13,8 +17,10 @@ public class Words {
// represends Words and letters, that are replaced in drunk players messages
public static ArrayList<Words> words = new ArrayList<Words>();
public static List<String> commands;
public static FileConfiguration config;
public static Boolean log;
private static Map<String, Long> waitPlayers = new HashMap<String, Long>();
private String from;
private String to;
@ -59,15 +65,52 @@ public class Words {
}
}
// Distort players words when he talks
public static void playerChat(AsyncPlayerChatEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());
if (bPlayer != null) {
private static boolean loadWords() {
if (words.isEmpty()) {
// load when first drunk player talks
load();
}
if (!words.isEmpty()) {
return !words.isEmpty();
}
// Distort players words when he uses a command
public static void playerCommand(PlayerCommandPreprocessEvent event) {
String name = event.getPlayer().getName();
BPlayer bPlayer = BPlayer.get(name);
if (bPlayer != null) {
if (!commands.isEmpty() && loadWords()) {
if (!waitPlayers.containsKey(name) || waitPlayers.get(name) + 500 < System.currentTimeMillis()) {
String chat = event.getMessage();
for (String command : commands) {
if (command.length() + 1 < chat.length()) {
if (Character.isSpaceChar(chat.charAt(command.length()))) {
if (chat.toLowerCase().startsWith(command.toLowerCase())) {
if (log) {
P.p.log(P.p.languageReader.get("Player_TriedToSay", name, chat));
}
String message = chat.substring(command.length() + 1);
for (Words word : words) {
if (word.alcohol <= bPlayer.getDrunkeness()) {
message = word.distort(message);
}
}
event.setMessage(chat.substring(0, command.length() + 1) + message);
waitPlayers.put(name, System.currentTimeMillis());
return;
}
}
}
}
}
}
}
}
// Distort players words when he talks
public static void playerChat(AsyncPlayerChatEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());
if (bPlayer != null) {
if (loadWords()) {
String message = event.getMessage();
if (log) {
P.p.log(P.p.languageReader.get("Player_TriedToSay", event.getPlayer().getName(), message));

View File

@ -6,6 +6,7 @@ import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.EventHandler;
@ -166,6 +167,14 @@ public class PlayerListener implements Listener {
}
}
// player commands while drunk, distort chat commands
@EventHandler(priority = EventPriority.LOWEST)
public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
if (BPlayer.players.containsKey(event.getPlayer().getName())) {
Words.playerCommand(event);
}
}
// player joins while passed out
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(PlayerLoginEvent event) {