Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.camdenorrb.bukkit.plugins;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.DyeColor;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.material.Dye;
- import org.bukkit.material.Wool;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Chat extends JavaPlugin implements Listener, CommandExecutor {
- Wool wool = new Wool(DyeColor.PINK);
- ItemStack pink = wool.toItemStack();
- private final Map<UUID, ChatColor> playerColors = new HashMap<>();
- private final ArrayList<String> words = new ArrayList<>(Arrays.asList("cunt", "twat", "faggot", "asshole", "fuck", "shit", "pussy", "dick", "bitch", "anal", "penis", "nigger", "nigga", "vagina"));
- private final ArrayList<String> WhiteList = new ArrayList<>(Arrays.asList("bass", "derp"));
- private static Plugin plugin;
- private static Listener plugin2;
- private static boolean bool;
- FileConfiguration config = getConfig();
- public Inventory inv;
- Dye on = new Dye();
- Dye off = new Dye();
- ItemStack Lapis = new ItemStack(Material.LAPIS_BLOCK);
- ItemStack redstone = new ItemStack(Material.REDSTONE_BLOCK);
- ItemStack emerald = new ItemStack(Material.EMERALD_BLOCK);
- ItemStack gold = new ItemStack(Material.GOLD_BLOCK);
- ItemMeta Pink = pink.getItemMeta();
- ItemMeta diamondMETA = Lapis.getItemMeta();
- ItemMeta redstoneMETA = redstone.getItemMeta();
- ItemMeta emeraldMETA = emerald.getItemMeta();
- ItemMeta goldMETA = gold.getItemMeta();
- List<String> toggled = new ArrayList<>();
- public void openGUI(Player p) {
- inv = Bukkit.createInventory(null, 9, ChatColor.RED + "Colors!"); //format: null, size of inventory (must be divisible by 9), "GUI name"
- diamondMETA.setDisplayName(ChatColor.BLUE + "BLUE!");
- redstoneMETA.setDisplayName(ChatColor.RED + "Red");
- emeraldMETA.setDisplayName(ChatColor.GREEN + "Green");
- goldMETA.setDisplayName(ChatColor.YELLOW + "Yellow");
- Pink.setDisplayName(ChatColor.LIGHT_PURPLE + "Pink");
- Lapis.setItemMeta(diamondMETA);
- redstone.setItemMeta(redstoneMETA);
- emerald.setItemMeta(emeraldMETA);
- gold.setItemMeta(goldMETA);
- pink.setItemMeta(Pink);
- inv.setItem(0, new ItemStack(Lapis));
- inv.setItem(1, new ItemStack(redstone));
- inv.setItem(2, new ItemStack(emerald));
- inv.setItem(3, new ItemStack(gold));
- inv.setItem(4, new ItemStack(pink));
- p.openInventory(inv);
- }
- @Override
- public void onEnable() {
- plugin = this;
- plugin2 = this;
- getServer().getPluginManager().registerEvents(plugin2, plugin);
- intializeConfig();
- for (Player p : Bukkit.getOnlinePlayers()) {
- playerJoin(p.getUniqueId());
- }
- }
- @Override
- public void onDisable() {
- plugin = null;
- plugin2 = null;
- // TODO: Place any custom disable code here.
- }
- private void intializeConfig() {
- config.addDefault("BlockMessageOn?", true);
- config.addDefault("words", words);
- config.addDefault("whitelist", WhiteList);
- config.addDefault("Showmessage", "&cThe use of foul language is prohibitedd.");
- config.addDefault("message", "&4Please do not use foul language.");
- config.options().copyDefaults(true);
- saveConfig();
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (cmd.getLabel().equalsIgnoreCase("color") && args.length == 1) {
- if (sender instanceof ConsoleCommandSender) {
- sender.sendMessage("This command can only be run by a player.");
- return false;
- } else {
- Player player = (Player) sender;
- if (args[0].equalsIgnoreCase("toggle")) {
- if (sender instanceof ConsoleCommandSender) {
- sender.sendMessage("This command can only be run by a player.");
- return false;
- } else {
- if (toggled.contains(player.getName())) {
- sender.sendMessage(ChatColor.GREEN + "Turn On Color With /color");
- toggled.add(player.getName());
- return true;
- } else {
- playerColors.put(player.getUniqueId(), ChatColor.RESET);
- sender.sendMessage(ChatColor.GREEN + "You DeActivated Your Chat Color!@!");
- toggled.remove(player.getName());
- return true;
- }
- }
- } else if (args[0].equalsIgnoreCase("reload")) {
- if(player.hasPermission("color.reload")){
- return true;
- }else{
- player.sendMessage(ChatColor.GREEN+"You Do Not Have Permissions Required To "+ChatColor.RED+"Reload");
- return true;
- }
- }
- }
- } else if (cmd.getLabel().equalsIgnoreCase("color") && args.length == 0) {
- if (sender instanceof ConsoleCommandSender) {
- sender.sendMessage("This command can only be run by a player.");
- return false;
- } else {
- Player player = (Player) sender;
- openGUI(player);
- return true;
- }
- }
- return false;
- }
- @EventHandler
- public void playerChat(AsyncPlayerChatEvent e) {
- String message = getConfig().getString("message").replaceAll("(&([a-f0-9]))", "\u00A7$2").replaceAll("($([a-f0-9]))", "\u00A7$2").replaceAll("(%([a-f0-9]))", "\u00A7$2");
- String Showmessage = getConfig().getString("Showmessage").replaceAll("(&([a-f0-9]))", "\u00A7$2").replaceAll("($([a-f0-9]))", "\u00A7$2").replaceAll("(%([a-f0-9]))", "\u00A7$2");
- if (config.getStringList("whitelist").contains(e.getMessage().toLowerCase())) {
- bool = false;
- }else{
- bool = true;
- if (bool == true) {
- for (String word : getConfig().getStringList("words")) {
- String sent = e.getMessage().toLowerCase().replaceAll("\\.", "").replaceAll("&", "");
- if (sent.contains(word)) {
- bool = true;
- if (config.getBoolean("BlockMessageOn?") == true && bool == true) {
- e.setMessage(Showmessage.replaceAll("'", "").replaceAll("’", "").replaceAll("‘", ""));
- e.getPlayer().sendMessage(message.replaceAll("'", "").replaceAll("’", "").replaceAll("‘", ""));
- } else {
- bool = false;
- }
- }
- }
- }
- }
- ChatColor test = playerColors.get(e.getPlayer().getUniqueId());
- e.setMessage(test + e.getMessage());
- }
- @EventHandler
- public void onJoinEvent(PlayerJoinEvent e) {
- if (playerColors.get(e.getPlayer().getUniqueId()) != null) {
- } else {
- playerJoin(e.getPlayer().getUniqueId());
- }
- }
- public void playerJoin(UUID u) {
- playerColors.put(u, ChatColor.RESET);
- }
- @EventHandler //MAKE SURE YOU HAVE THIS
- public void InventoryClick(InventoryClickEvent e) {
- Player p = (Player) e.getWhoClicked();
- if (e.getInventory().getTitle().contains(ChatColor.RED + "Colors!")) {
- e.setCancelled(true); //Cancel the event so they can't take items out of the GUI
- if (e.getCurrentItem() == null) {
- } else {
- if (e.getCurrentItem().getType() == Material.LAPIS_BLOCK) {
- //gets called when the current item's type (The item the player clicked) is a diamond
- playerColors.put(p.getUniqueId(), ChatColor.BLUE);
- p.closeInventory(); //call if you want to close the inventory when they click it
- } else if (e.getCurrentItem().getType() == Material.REDSTONE_BLOCK) {
- //gets called when the current item's type (The item the player clicked) is a diamond
- playerColors.put(p.getUniqueId(), ChatColor.RED);
- p.closeInventory(); //call if you want to close the inventory when they click it
- intializeConfig();
- } else if (e.getCurrentItem().getType() == Material.EMERALD_BLOCK) {
- //gets called when the current item's type (The item the player clicked) is a diamond
- playerColors.put(p.getUniqueId(), ChatColor.GREEN);
- p.closeInventory(); //call if you want to close the inventory when they click it
- intializeConfig();
- } else if (e.getCurrentItem().getType() == Material.GOLD_BLOCK) {
- //gets called when the current item's type (The item the player clicked) is a diamond
- playerColors.put(p.getUniqueId(), ChatColor.YELLOW);
- p.closeInventory(); //call if you want to close the inventory when they click it
- } else if (e.getCurrentItem().getItemMeta().equals(Pink)) {
- //gets called when the current item's type (The item the player clicked) is a diamond
- playerColors.put(p.getUniqueId(), ChatColor.LIGHT_PURPLE);
- p.closeInventory(); //call if you want to close the inventory when they click it
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement