Distort Sign Text

This commit is contained in:
Sn0wStorm 2013-11-17 20:02:32 +01:00
parent 4e279fae2e
commit 71963232f3
3 changed files with 38 additions and 0 deletions

View File

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

View File

@ -9,6 +9,7 @@ import java.lang.Character;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.block.SignChangeEvent;
import com.dre.brewery.BPlayer;
@ -19,6 +20,7 @@ public class Words {
public static ArrayList<Words> words = new ArrayList<Words>();
public static List<String> commands;
public static FileConfiguration config;
public static Boolean doSigns;
public static Boolean log;
private static Map<String, Long> waitPlayers = new HashMap<String, Long>();
@ -106,6 +108,30 @@ public class Words {
}
}
// Distort players words when he uses a command
public static void signWrite(SignChangeEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());
if (bPlayer != null) {
if (loadWords()) {
int index = 0;
for (String message : event.getLines()) {
if (message.length() > 1) {
for (Words word : words) {
if (word.alcohol <= bPlayer.getDrunkeness()) {
message = word.distort(message);
}
}
if (message.length() > 15) {
message = message.substring(0, 14);
}
event.setLine(index, message);
}
index++;
}
}
}
}
// Distort players words when he talks
public static void playerChat(AsyncPlayerChatEvent event) {
BPlayer bPlayer = BPlayer.get(event.getPlayer().getName());

View File

@ -10,6 +10,8 @@ import org.bukkit.block.Block;
import com.dre.brewery.BCauldron;
import com.dre.brewery.Barrel;
import com.dre.brewery.BPlayer;
import com.dre.brewery.Words;
import com.dre.brewery.P;
public class BlockListener implements Listener {
@ -25,6 +27,15 @@ public class BlockListener implements Listener {
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onSignChangeLow(SignChangeEvent event) {
if (Words.doSigns) {
if (BPlayer.players.containsKey(event.getPlayer().getName())) {
Words.signWrite(event);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();