mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-29 12:45:14 +01:00
Distort Certain Commands
This commit is contained in:
parent
f4f0bc9511
commit
4e279fae2e
32
config.yml
32
config.yml
@ -1,7 +1,7 @@
|
|||||||
# config for Brewery.jar
|
# config for Brewery.jar
|
||||||
|
|
||||||
|
|
||||||
# Settings
|
# -- Settings --
|
||||||
# Defaults are written in []
|
# Defaults are written in []
|
||||||
# Deleting of single settings disables them
|
# Deleting of single settings disables them
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ enablePuke: true
|
|||||||
# Item that is dropped multiple times uncollectable when puking [SOUL_SAND]
|
# Item that is dropped multiple times uncollectable when puking [SOUL_SAND]
|
||||||
pukeItem: 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:
|
drainItems:
|
||||||
- BREAD/4
|
- BREAD/4
|
||||||
- MILK_BUCKET/2
|
- MILK_BUCKET/2
|
||||||
@ -48,17 +48,14 @@ hangoverDays: 7
|
|||||||
colorInBarrels: true
|
colorInBarrels: true
|
||||||
colorInBrewer: false
|
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 interval in minutes [3]
|
||||||
autosave: 3
|
autosave: 3
|
||||||
|
|
||||||
# Config Version
|
# 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)
|
# name: Different names for bad/normal/good (Formatting codes possible: such as &6)
|
||||||
# ingredients: List of material/amount
|
# 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.
|
# 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.
|
# Will be processed from first to last and a written sentece is altered in that order.
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ public class P extends JavaPlugin {
|
|||||||
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
|
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
|
||||||
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
|
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
|
||||||
Words.log = config.getBoolean("logRealChat", false);
|
Words.log = config.getBoolean("logRealChat", false);
|
||||||
|
Words.commands = config.getStringList("distortCommands");
|
||||||
|
|
||||||
// loading recipes
|
// loading recipes
|
||||||
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.lang.Character;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
import com.dre.brewery.BPlayer;
|
import com.dre.brewery.BPlayer;
|
||||||
|
|
||||||
@ -13,8 +17,10 @@ public class Words {
|
|||||||
// represends Words and letters, that are replaced in drunk players messages
|
// represends Words and letters, that are replaced in drunk players messages
|
||||||
|
|
||||||
public static ArrayList<Words> words = new ArrayList<Words>();
|
public static ArrayList<Words> words = new ArrayList<Words>();
|
||||||
|
public static List<String> commands;
|
||||||
public static FileConfiguration config;
|
public static FileConfiguration config;
|
||||||
public static Boolean log;
|
public static Boolean log;
|
||||||
|
private static Map<String, Long> waitPlayers = new HashMap<String, Long>();
|
||||||
|
|
||||||
private String from;
|
private String from;
|
||||||
private String to;
|
private String to;
|
||||||
@ -59,15 +65,52 @@ 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) {
|
||||||
|
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
|
// Distort players words when he talks
|
||||||
public static void playerChat(AsyncPlayerChatEvent event) {
|
public static void playerChat(AsyncPlayerChatEvent event) {
|
||||||
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());
|
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());
|
||||||
if (bPlayer != null) {
|
if (bPlayer != null) {
|
||||||
if (words.isEmpty()) {
|
if (loadWords()) {
|
||||||
// load when first drunk player talks
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
if (!words.isEmpty()) {
|
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
if (log) {
|
if (log) {
|
||||||
P.p.log(P.p.languageReader.get("Player_TriedToSay", event.getPlayer().getName(), message));
|
P.p.log(P.p.languageReader.get("Player_TriedToSay", event.getPlayer().getName(), message));
|
||||||
|
@ -6,6 +6,7 @@ import org.bukkit.event.player.PlayerItemConsumeEvent;
|
|||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
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
|
// player joins while passed out
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user