WIP
This commit is contained in:
@@ -7,6 +7,7 @@ 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;
|
||||
@@ -27,7 +28,7 @@ public class BungeeMain extends Plugin
|
||||
saveDefaultConfig();
|
||||
if (!reloadConfig())
|
||||
{
|
||||
getLogger().severe("Could not load config file, disabling plugin.");
|
||||
getLogger().severe("Could not load config file, using defaults.");
|
||||
return;
|
||||
}
|
||||
registerCommands();
|
||||
@@ -53,6 +54,7 @@ public class BungeeMain extends Plugin
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(getResourceAsStream("config.yml"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -66,6 +68,7 @@ public class BungeeMain extends Plugin
|
||||
{
|
||||
if (!getDataFolder().exists())
|
||||
{
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.oskar3123.staffchat.bungee.command;
|
||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
@@ -10,33 +11,32 @@ import net.md_5.bungee.config.Configuration;
|
||||
public class BungeeStaffChatCommand extends Command
|
||||
{
|
||||
|
||||
private BungeeMain plugin;
|
||||
private BungeeMain main;
|
||||
private Configuration config;
|
||||
private static final String LABEL = "staffchat";
|
||||
|
||||
public BungeeStaffChatCommand(BungeeMain plugin)
|
||||
public BungeeStaffChatCommand(BungeeMain main)
|
||||
{
|
||||
super(LABEL);
|
||||
this.plugin = plugin;
|
||||
config = plugin.getConfig();
|
||||
super("staffchat");
|
||||
this.main = main;
|
||||
config = main.getConfig();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String[] args)
|
||||
{
|
||||
String noPerm = clr(config.getString("messages.prefix") + config.getString("messages.nopermission"));
|
||||
if (!sender.hasPermission(plugin.commandPerm))
|
||||
BaseComponent[] noPerm = txt(config.getString("messages.prefix") + config.getString("messages.nopermission"));
|
||||
if (!sender.hasPermission(main.commandPerm))
|
||||
{
|
||||
sender.sendMessage(noPerm);
|
||||
return;
|
||||
}
|
||||
if (args.length < 1)
|
||||
{
|
||||
help(sender, LABEL);
|
||||
help(sender, getName());
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
if (sender.hasPermission(plugin.reloadPerm))
|
||||
if (sender.hasPermission(main.reloadPerm))
|
||||
{
|
||||
reload(sender);
|
||||
}
|
||||
@@ -46,30 +46,29 @@ public class BungeeStaffChatCommand extends Command
|
||||
}
|
||||
return;
|
||||
}
|
||||
help(sender, LABEL);
|
||||
return;
|
||||
help(sender, getName());
|
||||
}
|
||||
|
||||
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))
|
||||
String prefix = config.getString("messages.prefix");
|
||||
sender.sendMessage(txt(prefix + "Version " + main.getDescription().getVersion() + ", made by oskar3123"));
|
||||
if (sender.hasPermission(main.reloadPerm))
|
||||
{
|
||||
sender.sendMessage(TextComponent.fromLegacyText(prefix + "/" + label + " reload - Reloads the config file"));
|
||||
sender.sendMessage(txt(prefix + "/" + label + " reload - Reloads the config file"));
|
||||
}
|
||||
}
|
||||
|
||||
private void reload(CommandSender sender)
|
||||
{
|
||||
plugin.reloadConfig();
|
||||
config = plugin.getConfig();
|
||||
sender.sendMessage(clr(config.getString("messages.prefix") + config.getString("messages.reloaded")));
|
||||
main.reloadConfig();
|
||||
config = main.getConfig();
|
||||
sender.sendMessage(txt(config.getString("messages.prefix") + config.getString("messages.reloaded")));
|
||||
}
|
||||
|
||||
private String clr(String string)
|
||||
private BaseComponent[] txt(String text)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,69 @@
|
||||
package me.oskar3123.staffchat.bungee.event;
|
||||
|
||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class BungeeChatListener implements Listener
|
||||
{
|
||||
|
||||
BungeeMain plugin;
|
||||
private BungeeMain plugin;
|
||||
private Configuration config;
|
||||
|
||||
public BungeeChatListener(BungeeMain plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
config = plugin.getConfig();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void chat(ChatEvent event)
|
||||
{
|
||||
if (!(event.getSender() instanceof ProxiedPlayer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if (!player.hasPermission(plugin.usePerm))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Configuration config = plugin.getConfig();
|
||||
String character = config.getString("settings.character");
|
||||
if (!event.getMessage().startsWith(character))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String format = config.getString("settings.format");
|
||||
format = format.replaceAll("\\{NAME\\}", player.getName());
|
||||
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))
|
||||
.forEach(p -> p.sendMessage(message));
|
||||
plugin.getLogger().info(ChatColor.stripColor(clr(format)));
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private String clr(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
||||
private BaseComponent[] txt(String text)
|
||||
{
|
||||
return TextComponent.fromLegacyText(clr(text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user