mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 08:59:01 +00:00
Distort Certain Commands
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
public static void playerChat(AsyncPlayerChatEvent event) {
|
||||
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());
|
||||
if (bPlayer != null) {
|
||||
if (words.isEmpty()) {
|
||||
// load when first drunk player talks
|
||||
load();
|
||||
}
|
||||
if (!words.isEmpty()) {
|
||||
if (loadWords()) {
|
||||
String message = event.getMessage();
|
||||
if (log) {
|
||||
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.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;
|
||||
@@ -165,6 +166,14 @@ public class PlayerListener implements Listener {
|
||||
Words.playerChat(event);
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user