WIP
This commit is contained in:
@@ -14,6 +14,10 @@
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@@ -27,6 +31,11 @@
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.11-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class BungeeMain extends Plugin
|
||||
{
|
||||
|
||||
public final String usePerm = "staffchat.use";
|
||||
public final String seePerm = "staffchat.see";
|
||||
public final String commandPerm = "staffchat.command";
|
||||
public final String reloadPerm = "staffchat.reload";
|
||||
private Configuration config;
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
saveDefaultConfig();
|
||||
if (!reloadConfig())
|
||||
{
|
||||
getLogger().severe("Could not load config file, disabling plugin.");
|
||||
return;
|
||||
}
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
private void registerCommands()
|
||||
{
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeStaffChatCommand(this));
|
||||
}
|
||||
|
||||
private void registerEvents()
|
||||
{
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeChatListener(this));
|
||||
}
|
||||
|
||||
public boolean reloadConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
||||
return true;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration getConfig()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
private void saveDefaultConfig()
|
||||
{
|
||||
if (!getDataFolder().exists())
|
||||
{
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
try (InputStream in = getResourceAsStream("config.yml"))
|
||||
{
|
||||
Files.copy(in, file.toPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
public class BungeeStaffChatCommand extends Command
|
||||
{
|
||||
|
||||
private BungeeMain plugin;
|
||||
private Configuration config;
|
||||
private static final String LABEL = "staffchat";
|
||||
|
||||
public BungeeStaffChatCommand(BungeeMain plugin)
|
||||
{
|
||||
super(LABEL);
|
||||
this.plugin = plugin;
|
||||
config = plugin.getConfig();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String[] args)
|
||||
{
|
||||
String noPerm = clr(config.getString("messages.prefix") + config.getString("messages.nopermission"));
|
||||
if (!sender.hasPermission(plugin.commandPerm))
|
||||
{
|
||||
sender.sendMessage(noPerm);
|
||||
return;
|
||||
}
|
||||
if (args.length < 1)
|
||||
{
|
||||
help(sender, LABEL);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
if (sender.hasPermission(plugin.reloadPerm))
|
||||
{
|
||||
reload(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(noPerm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
help(sender, LABEL);
|
||||
return;
|
||||
}
|
||||
|
||||
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(TextComponent.fromLegacyText(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")));
|
||||
}
|
||||
|
||||
private String clr(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.oskar3123.staffchat.bungee.event;
|
||||
|
||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class BungeeChatListener implements Listener
|
||||
{
|
||||
|
||||
BungeeMain plugin;
|
||||
|
||||
public BungeeChatListener(BungeeMain plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void chat(ChatEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package me.oskar3123.staffchat;
|
||||
package me.oskar3123.staffchat.spigot;
|
||||
|
||||
import me.oskar3123.staffchat.command.StaffChatCommand;
|
||||
import me.oskar3123.staffchat.event.ChatListener;
|
||||
import me.oskar3123.staffchat.spigot.command.StaffChatCommand;
|
||||
import me.oskar3123.staffchat.spigot.event.ChatListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
+3
-2
@@ -1,11 +1,12 @@
|
||||
package me.oskar3123.staffchat.command;
|
||||
package me.oskar3123.staffchat.spigot.command;
|
||||
|
||||
import me.oskar3123.staffchat.Main;
|
||||
import me.oskar3123.staffchat.spigot.Main;
|
||||
import org.bukkit.ChatColor;
|
||||
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
|
||||
{
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package me.oskar3123.staffchat.event;
|
||||
package me.oskar3123.staffchat.spigot.event;
|
||||
|
||||
import me.oskar3123.staffchat.Main;
|
||||
import me.oskar3123.staffchat.spigot.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -0,0 +1,4 @@
|
||||
name: StaffChat
|
||||
authors: [oskar3123]
|
||||
main: me.oskar3123.staffchat.bungee.BungeeMain
|
||||
version: 1.0.0
|
||||
@@ -1,6 +1,6 @@
|
||||
name: StaffChat
|
||||
authors: [oskar3123]
|
||||
main: me.oskar3123.staffchat.Main
|
||||
main: me.oskar3123.staffchat.spigot.Main
|
||||
version: 1.0.0
|
||||
|
||||
commands:
|
||||
@@ -27,4 +27,4 @@ permissions:
|
||||
default: op
|
||||
staffchat.command:
|
||||
description: Allows you to use the staffchat command.
|
||||
default: true
|
||||
default: true
|
||||
|
||||
Reference in New Issue
Block a user