Initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>me.oskar3123</groupId>
|
||||||
|
<artifactId>staffchat</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package me.oskar3123.staffchat;
|
||||||
|
|
||||||
|
import me.oskar3123.staffchat.command.StaffChatCommand;
|
||||||
|
import me.oskar3123.staffchat.event.ChatListener;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class Main extends JavaPlugin
|
||||||
|
{
|
||||||
|
|
||||||
|
public final String usePerm = "staffchat.use";
|
||||||
|
public final String seePerm = "staffchat.see";
|
||||||
|
public final String commandPerm = "staffchat.command";
|
||||||
|
public final String reloadPerm = "staffchat.reload";
|
||||||
|
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
saveDefaultConfig();
|
||||||
|
registerCommands();
|
||||||
|
registerEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerCommands()
|
||||||
|
{
|
||||||
|
getCommand("staffchat").setExecutor(new StaffChatCommand(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEvents()
|
||||||
|
{
|
||||||
|
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package me.oskar3123.staffchat.command;
|
||||||
|
|
||||||
|
import me.oskar3123.staffchat.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;
|
||||||
|
|
||||||
|
public class StaffChatCommand implements CommandExecutor
|
||||||
|
{
|
||||||
|
|
||||||
|
private Main plugin;
|
||||||
|
private FileConfiguration config;
|
||||||
|
|
||||||
|
public StaffChatCommand(Main plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
config = plugin.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))
|
||||||
|
{
|
||||||
|
sender.sendMessage(noPerm);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length < 1)
|
||||||
|
{
|
||||||
|
help(sender, label);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("reload"))
|
||||||
|
{
|
||||||
|
if (sender.hasPermission(plugin.reloadPerm))
|
||||||
|
{
|
||||||
|
reload(sender);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage(noPerm);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
help(sender, label);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 + "/" + 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,56 @@
|
|||||||
|
package me.oskar3123.staffchat.event;
|
||||||
|
|
||||||
|
import me.oskar3123.staffchat.Main;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
|
public class ChatListener implements Listener
|
||||||
|
{
|
||||||
|
|
||||||
|
private Main plugin;
|
||||||
|
|
||||||
|
public ChatListener(Main plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void chat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (!event.getPlayer().hasPermission(plugin.usePerm))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileConfiguration 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\\}", event.getPlayer().getName());
|
||||||
|
format = format.replaceAll("\\{MESSAGE\\}", event.getMessage().substring(character.length()).trim());
|
||||||
|
format = clr(format);
|
||||||
|
final String message = format;
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(p -> p.hasPermission(plugin.seePerm))
|
||||||
|
.forEach(p -> p.sendMessage(message));
|
||||||
|
plugin.getLogger().info(ChatColor.stripColor(message));
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String clr(String string)
|
||||||
|
{
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', string);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
settings:
|
||||||
|
character: '@'
|
||||||
|
format: '&b{NAME}: {MESSAGE}'
|
||||||
|
messages:
|
||||||
|
prefix: '&7StaffChat&8> &7'
|
||||||
|
nopermission: '&cYou don''t have permission to do that'
|
||||||
|
reloaded: 'Reloaded the config file'
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
name: StaffChat
|
||||||
|
authors: [oskar3123]
|
||||||
|
main: me.oskar3123.staffchat.Main
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
|
commands:
|
||||||
|
staffchat:
|
||||||
|
usage: /<command>
|
||||||
|
description: Used to reload the config file.
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
staffchat.*:
|
||||||
|
description: Gives you permission to everything in the plugin.
|
||||||
|
children:
|
||||||
|
staffchat.use: true
|
||||||
|
staffchat.see: true
|
||||||
|
staffchat.reload: true
|
||||||
|
staffchat.command: true
|
||||||
|
staffchat.use:
|
||||||
|
description: Gives you permission to use the staffchat.
|
||||||
|
default: op
|
||||||
|
staffchat.see:
|
||||||
|
description: Gives you permission to see the staffchat.
|
||||||
|
default: op
|
||||||
|
staffchat.reload:
|
||||||
|
description: Allows you to reload the config file.
|
||||||
|
default: op
|
||||||
|
staffchat.command:
|
||||||
|
description: Allows you to use the staffchat command.
|
||||||
|
default: true
|
||||||
Reference in New Issue
Block a user