Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.busterroni.HelloWorld;
- //imports
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.craftbukkit.libs.jline.internal.Log;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public final class Main extends JavaPlugin implements Listener{
- //hashmaps for saving whether the player is in a private chat or not
- private HashMap<String, String> chatMap=new HashMap<String, String>();
- public void onEnable(){
- //check for sent chat messaes
- getServer().getPluginManager().registerEvents(this, this);
- }
- public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
- Player player = (Player) sender;
- if(!(sender instanceof Player)){
- sender.sendMessage(ChatColor.RED + "The console cannot change its chat!");
- }
- else{
- //if the player enters the command 'ac' and has the staffchat.admin permission:
- if(cmd.getName().equalsIgnoreCase("ac") && player.hasPermission("staffchat.admin")){
- if(!chatMap.containsKey(player.getName())){
- chatMap.put(player.getDisplayName(), "default");
- }
- //if the player typed in /ac and does not have admin chat enabled
- if(!chatMap.get(player.getName()).equals("admin")){
- player.sendMessage(ChatColor.RED + "Admin Chat enabled!");
- //enable admin chat
- chatMap.put(player.getDisplayName(), "admin");
- }
- //if the player typed in /ac and does have admin chat enabled
- else{
- player.sendMessage(ChatColor.RED + "Admin Chat disabled!");
- //disable admin chat
- chatMap.put(player.getName(), "default");
- }
- }
- else if(cmd.getName().equalsIgnoreCase("ac") && !player.hasPermission("staffchat.admin")){
- player.sendMessage(ChatColor.RED + "You do not have permission to use the admin chat!");
- }
- //if the player enters the command 'mc' and has the staffchat.mod permission:
- if(cmd.getName().equalsIgnoreCase("mc") && player.hasPermission("staffchat.mod")){
- if(!chatMap.containsKey(player.getName())){
- chatMap.put(player.getDisplayName(), "default");
- }
- //if the player typed in /mc and does not have mod chat enabled
- if(chatMap.containsKey(player.getName()) && !chatMap.get(player.getName()).equals("mod")){
- player.sendMessage(ChatColor.DARK_PURPLE + "Mod Chat enabled!");
- //enable mod chat
- chatMap.put(player.getDisplayName(), "mod");
- }
- //if the player typed in /mc and does have mod chat enabled
- else{
- player.sendMessage(ChatColor.DARK_PURPLE + "Mod Chat disabled!");
- //disable mod chat
- chatMap.put(player.getDisplayName(), "default");
- }
- }
- else if(cmd.getName().equalsIgnoreCase("mc") && !player.hasPermission("staffchat.mod")){
- player.sendMessage(ChatColor.RED + "You do not have permission to use the mod chat!");
- }
- }
- return false;
- }
- @EventHandler
- public void onPlayerChat(AsyncPlayerChatEvent e){
- Date currentDate=new Date();
- SimpleDateFormat dateFormat=new SimpleDateFormat("HH:mm:ss");
- Player player = e.getPlayer();
- if((chatMap.get(player.getName()).equals("admin") && !player.hasPermission("staffchat.admin")) ||
- (chatMap.get(player.getName()).equals("mod") && !player.hasPermission("staffchat.mod"))){
- chatMap.remove(player.getName());
- }
- //log the sent message
- Log.info(dateFormat.format(currentDate) +" <" + player.getDisplayName() + "> " + e.getMessage());
- //if a player sent a message using private admin chat:
- if(chatMap.get(player.getName()).equals("admin")){
- e.setCancelled(true);
- //run through all the online players
- for(Player p:Bukkit.getOnlinePlayers()){
- //if the player checked has the staffchat.admin permission:
- if(p.hasPermission("staffchat.admin")){
- //send them the private admin message
- p.sendMessage(ChatColor.RED + "[AC]" + ChatColor.WHITE + " <" + player.getDisplayName() + "> " + ChatColor.AQUA + e.getMessage());
- }
- }
- }
- //if a player sent a message using private mod chat:
- else if(chatMap.get(player.getDisplayName()).equals("mod")){
- e.setCancelled(true);
- //run through all the online players
- for(Player p:Bukkit.getOnlinePlayers()){
- //if the player checked has the staffchat.mod permission:
- if(p.hasPermission("staffchat.mod")){
- //send them the private mod message
- p.sendMessage(ChatColor.DARK_PURPLE + "[MC]" + ChatColor.WHITE + " <" + player.getDisplayName() + "> " + ChatColor.LIGHT_PURPLE + e.getMessage());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement