WIP
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<groupId>me.oskar3123</groupId>
|
<groupId>me.oskar3123</groupId>
|
||||||
<artifactId>staffchat</artifactId>
|
<artifactId>staffchat</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|||||||
@@ -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.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -27,7 +28,7 @@ public class BungeeMain extends Plugin
|
|||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
if (!reloadConfig())
|
if (!reloadConfig())
|
||||||
{
|
{
|
||||||
getLogger().severe("Could not load config file, disabling plugin.");
|
getLogger().severe("Could not load config file, using defaults.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
registerCommands();
|
registerCommands();
|
||||||
@@ -53,6 +54,7 @@ public class BungeeMain extends Plugin
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
|
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(getResourceAsStream("config.yml"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,7 @@ public class BungeeMain extends Plugin
|
|||||||
{
|
{
|
||||||
if (!getDataFolder().exists())
|
if (!getDataFolder().exists())
|
||||||
{
|
{
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
getDataFolder().mkdir();
|
getDataFolder().mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package me.oskar3123.staffchat.bungee.command;
|
|||||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
import me.oskar3123.staffchat.bungee.BungeeMain;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
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.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
@@ -10,33 +11,32 @@ import net.md_5.bungee.config.Configuration;
|
|||||||
public class BungeeStaffChatCommand extends Command
|
public class BungeeStaffChatCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
private BungeeMain plugin;
|
private BungeeMain main;
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
private static final String LABEL = "staffchat";
|
|
||||||
|
|
||||||
public BungeeStaffChatCommand(BungeeMain plugin)
|
public BungeeStaffChatCommand(BungeeMain main)
|
||||||
{
|
{
|
||||||
super(LABEL);
|
super("staffchat");
|
||||||
this.plugin = plugin;
|
this.main = main;
|
||||||
config = plugin.getConfig();
|
config = main.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
String noPerm = clr(config.getString("messages.prefix") + config.getString("messages.nopermission"));
|
BaseComponent[] noPerm = txt(config.getString("messages.prefix") + config.getString("messages.nopermission"));
|
||||||
if (!sender.hasPermission(plugin.commandPerm))
|
if (!sender.hasPermission(main.commandPerm))
|
||||||
{
|
{
|
||||||
sender.sendMessage(noPerm);
|
sender.sendMessage(noPerm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
help(sender, LABEL);
|
help(sender, getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("reload"))
|
if (args[0].equalsIgnoreCase("reload"))
|
||||||
{
|
{
|
||||||
if (sender.hasPermission(plugin.reloadPerm))
|
if (sender.hasPermission(main.reloadPerm))
|
||||||
{
|
{
|
||||||
reload(sender);
|
reload(sender);
|
||||||
}
|
}
|
||||||
@@ -46,30 +46,29 @@ public class BungeeStaffChatCommand extends Command
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
help(sender, LABEL);
|
help(sender, getName());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void help(CommandSender sender, String label)
|
private void help(CommandSender sender, String label)
|
||||||
{
|
{
|
||||||
String prefix = clr(config.getString("messages.prefix"));
|
String prefix = config.getString("messages.prefix");
|
||||||
sender.sendMessage(prefix + "Version " + plugin.getDescription().getVersion() + ", made by oskar3123");
|
sender.sendMessage(txt(prefix + "Version " + main.getDescription().getVersion() + ", made by oskar3123"));
|
||||||
if (sender.hasPermission(plugin.reloadPerm))
|
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)
|
private void reload(CommandSender sender)
|
||||||
{
|
{
|
||||||
plugin.reloadConfig();
|
main.reloadConfig();
|
||||||
config = plugin.getConfig();
|
config = main.getConfig();
|
||||||
sender.sendMessage(clr(config.getString("messages.prefix") + config.getString("messages.reloaded")));
|
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;
|
package me.oskar3123.staffchat.bungee.event;
|
||||||
|
|
||||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
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.event.ChatEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
public class BungeeChatListener implements Listener
|
public class BungeeChatListener implements Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
BungeeMain plugin;
|
private BungeeMain plugin;
|
||||||
|
private Configuration config;
|
||||||
|
|
||||||
public BungeeChatListener(BungeeMain plugin)
|
public BungeeChatListener(BungeeMain plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
config = plugin.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void chat(ChatEvent event)
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: StaffChat
|
name: StaffChat
|
||||||
authors: [oskar3123]
|
authors: [oskar3123]
|
||||||
main: me.oskar3123.staffchat.bungee.BungeeMain
|
main: me.oskar3123.staffchat.bungee.BungeeMain
|
||||||
version: 1.0.0
|
version: 1.1.0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: StaffChat
|
name: StaffChat
|
||||||
authors: [oskar3123]
|
authors: [oskar3123]
|
||||||
main: me.oskar3123.staffchat.spigot.Main
|
main: me.oskar3123.staffchat.spigot.Main
|
||||||
version: 1.0.0
|
version: 1.1.0
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
staffchat:
|
staffchat:
|
||||||
|
|||||||
Reference in New Issue
Block a user