This commit is contained in:
2017-03-15 01:19:35 +01:00
parent 24d4a5cf69
commit f37e413201
5 changed files with 31 additions and 31 deletions
@@ -2,12 +2,10 @@ package me.oskar3123.staffchat.bungee;
import me.oskar3123.staffchat.bungee.command.BungeeStaffChatCommand;
import me.oskar3123.staffchat.bungee.event.BungeeChatListener;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.IOException;
@@ -66,9 +66,14 @@ public class BungeeStaffChatCommand extends Command
sender.sendMessage(txt(config.getString("messages.prefix") + config.getString("messages.reloaded")));
}
private String clr(String string)
{
return ChatColor.translateAlternateColorCodes('&', string);
}
private BaseComponent[] txt(String text)
{
return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', text));
return TextComponent.fromLegacyText(clr(text));
}
}
@@ -13,13 +13,11 @@ import net.md_5.bungee.event.EventHandler;
public class BungeeChatListener implements Listener
{
private BungeeMain plugin;
private Configuration config;
private BungeeMain main;
public BungeeChatListener(BungeeMain plugin)
public BungeeChatListener(BungeeMain main)
{
this.plugin = plugin;
config = plugin.getConfig();
this.main = main;
}
@EventHandler
@@ -31,12 +29,12 @@ public class BungeeChatListener implements Listener
}
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
if (!player.hasPermission(plugin.usePerm))
if (!player.hasPermission(main.usePerm))
{
return;
}
Configuration config = plugin.getConfig();
Configuration config = main.getConfig();
String character = config.getString("settings.character");
if (!event.getMessage().startsWith(character))
{
@@ -48,10 +46,10 @@ public class BungeeChatListener implements Listener
format = format.replaceAll("\\{MESSAGE\\}", event.getMessage().substring(character.length()).trim());
final BaseComponent[] message = txt(format);
plugin.getProxy().getPlayers().stream()
.filter(p -> p.hasPermission(plugin.seePerm))
main.getProxy().getPlayers().stream()
.filter(p -> p.hasPermission(main.seePerm))
.forEach(p -> p.sendMessage(message));
plugin.getLogger().info(ChatColor.stripColor(clr(format)));
main.getLogger().info(ChatColor.stripColor(clr(format)));
event.setCancelled(true);
}
@@ -6,25 +6,24 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class StaffChatCommand implements CommandExecutor
{
private Main plugin;
private Main main;
private FileConfiguration config;
public StaffChatCommand(Main plugin)
public StaffChatCommand(Main main)
{
this.plugin = plugin;
config = plugin.getConfig();
this.main = main;
config = main.getConfig();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
String noPerm = clr(config.getString("messages.prefix") + config.getString("messages.nopermission"));
if (!sender.hasPermission(plugin.commandPerm))
if (!sender.hasPermission(main.commandPerm))
{
sender.sendMessage(noPerm);
return true;
@@ -36,7 +35,7 @@ public class StaffChatCommand implements CommandExecutor
}
if (args[0].equalsIgnoreCase("reload"))
{
if (sender.hasPermission(plugin.reloadPerm))
if (sender.hasPermission(main.reloadPerm))
{
reload(sender);
}
@@ -53,8 +52,8 @@ public class StaffChatCommand implements CommandExecutor
private void help(CommandSender sender, String label)
{
String prefix = clr(config.getString("messages.prefix"));
sender.sendMessage(prefix + "Version " + plugin.getDescription().getVersion() + ", made by oskar3123");
if (sender.hasPermission(plugin.reloadPerm))
sender.sendMessage(prefix + "Version " + main.getDescription().getVersion() + ", made by oskar3123");
if (sender.hasPermission(main.reloadPerm))
{
sender.sendMessage(prefix + "/" + label + " reload - Reloads the config file");
}
@@ -62,8 +61,8 @@ public class StaffChatCommand implements CommandExecutor
private void reload(CommandSender sender)
{
plugin.reloadConfig();
config = plugin.getConfig();
main.reloadConfig();
config = main.getConfig();
sender.sendMessage(clr(config.getString("messages.prefix") + config.getString("messages.reloaded")));
}
@@ -12,22 +12,22 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener
{
private Main plugin;
private Main main;
public ChatListener(Main plugin)
public ChatListener(Main main)
{
this.plugin = plugin;
this.main = main;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void chat(AsyncPlayerChatEvent event)
{
if (!event.getPlayer().hasPermission(plugin.usePerm))
if (!event.getPlayer().hasPermission(main.usePerm))
{
return;
}
FileConfiguration config = plugin.getConfig();
FileConfiguration config = main.getConfig();
String character = config.getString("settings.character");
if (!event.getMessage().startsWith(character))
{
@@ -41,9 +41,9 @@ public class ChatListener implements Listener
final String message = format;
Bukkit.getOnlinePlayers().stream()
.filter(p -> p.hasPermission(plugin.seePerm))
.filter(p -> p.hasPermission(main.seePerm))
.forEach(p -> p.sendMessage(message));
plugin.getLogger().info(ChatColor.stripColor(message));
main.getLogger().info(ChatColor.stripColor(message));
event.setCancelled(true);
}