version 1.2.0
added /staffchat toggle added placeholderapi support (spigot version only) small fixes for bungeecord version
This commit is contained in:
parent
9e8278d439
commit
c57fb7223a
17
pom.xml
17
pom.xml
|
@ -7,7 +7,7 @@
|
|||
|
||||
<groupId>me.oskar3123</groupId>
|
||||
<artifactId>staffchat</artifactId>
|
||||
<version>1.1.5-SNAPSHOT</version>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -22,27 +22,38 @@
|
|||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.13-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.9.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -19,6 +19,7 @@ public class BungeeMain extends Plugin
|
|||
public final String seePerm = "staffchat.see";
|
||||
public final String commandPerm = "staffchat.command";
|
||||
public final String reloadPerm = "staffchat.reload";
|
||||
public final BungeeChatListener chatListener = new BungeeChatListener(this);
|
||||
private Configuration config;
|
||||
|
||||
public void onEnable()
|
||||
|
@ -40,7 +41,7 @@ public class BungeeMain extends Plugin
|
|||
|
||||
private void registerEvents()
|
||||
{
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeChatListener(this));
|
||||
getProxy().getPluginManager().registerListener(this, chatListener);
|
||||
}
|
||||
|
||||
public boolean reloadConfig()
|
||||
|
@ -48,15 +49,42 @@ public class BungeeMain extends Plugin
|
|||
try
|
||||
{
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
||||
loadDefaultValues();
|
||||
return true;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(getResourceAsStream("config.yml"));
|
||||
loadDefaultValues();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDefaultValues()
|
||||
{
|
||||
String[] keys = new String[] {
|
||||
"settings.character",
|
||||
"settings.format",
|
||||
"messages.prefix",
|
||||
"messages.nopermission",
|
||||
"messages.playeronly",
|
||||
"messages.reloaded",
|
||||
"messages.toggled",
|
||||
"messages.onstring",
|
||||
"messages.offstring",
|
||||
};
|
||||
Configuration def = ConfigurationProvider.getProvider(YamlConfiguration.class).load(getResourceAsStream("config.yml"));
|
||||
for (String key : keys)
|
||||
{
|
||||
String v = config.getString(key);
|
||||
if (v == null || v.isEmpty())
|
||||
{
|
||||
config.set(key, def.getString(key));
|
||||
}
|
||||
}
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public Configuration getConfig()
|
||||
{
|
||||
return config;
|
||||
|
@ -85,4 +113,17 @@ public class BungeeMain extends Plugin
|
|||
}
|
||||
}
|
||||
|
||||
public void saveConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(getDataFolder(), "config.yml"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
getLogger().severe("Failed to save config");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ 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.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
|
@ -46,13 +47,35 @@ public class BungeeStaffChatCommand extends Command
|
|||
}
|
||||
return;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("toggle"))
|
||||
{
|
||||
if (sender.hasPermission(plugin.usePerm))
|
||||
{
|
||||
toggle(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(noPerm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
help(sender, getName());
|
||||
}
|
||||
|
||||
private void playerOnly(CommandSender sender)
|
||||
{
|
||||
sender.sendMessage(txt(config.getString("messages.prefix") + config.getString("messages.playeronly")));
|
||||
}
|
||||
|
||||
private void help(CommandSender sender, String label)
|
||||
{
|
||||
String prefix = config.getString("messages.prefix");
|
||||
sender.sendMessage(txt(prefix + "Version " + plugin.getDescription().getVersion() + ", made by oskar3123"));
|
||||
if (sender.hasPermission(plugin.usePerm))
|
||||
{
|
||||
sender.sendMessage(txt(prefix + "Message prefix: " + config.getString("settings.character")));
|
||||
sender.sendMessage(txt(prefix + "/" + label + " toggle - Toggles auto staffchat"));
|
||||
}
|
||||
if (sender.hasPermission(plugin.reloadPerm))
|
||||
{
|
||||
sender.sendMessage(txt(prefix + "/" + label + " reload - Reloads the config file"));
|
||||
|
@ -66,6 +89,18 @@ public class BungeeStaffChatCommand extends Command
|
|||
sender.sendMessage(txt(config.getString("messages.prefix") + config.getString("messages.reloaded")));
|
||||
}
|
||||
|
||||
private void toggle(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof ProxiedPlayer))
|
||||
{
|
||||
playerOnly(sender);
|
||||
return;
|
||||
}
|
||||
boolean toggled = plugin.chatListener.togglePlayer(((ProxiedPlayer) sender).getUniqueId());
|
||||
String state = toggled ? config.getString("messages.onstring") : config.getString("messages.offstring");
|
||||
sender.sendMessage(txt(config.getString("messages.prefix") + String.format(config.getString("messages.toggled"), state)));
|
||||
}
|
||||
|
||||
private String clr(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
|
|
|
@ -12,10 +12,15 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeChatListener implements Listener
|
||||
{
|
||||
|
||||
private BungeeMain plugin;
|
||||
private Set<UUID> toggledPlayers = new HashSet<>();
|
||||
|
||||
public BungeeChatListener(BungeeMain plugin)
|
||||
{
|
||||
|
@ -25,6 +30,10 @@ public class BungeeChatListener implements Listener
|
|||
@EventHandler
|
||||
public void chat(ChatEvent event)
|
||||
{
|
||||
if (event.getMessage().startsWith("/"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!(event.getSender() instanceof ProxiedPlayer))
|
||||
{
|
||||
return;
|
||||
|
@ -38,13 +47,14 @@ public class BungeeChatListener implements Listener
|
|||
|
||||
Configuration config = plugin.getConfig();
|
||||
String character = config.getString("settings.character");
|
||||
if (!event.getMessage().startsWith(character))
|
||||
boolean isToggled = toggledPlayers.contains(player.getUniqueId());
|
||||
if (!event.getMessage().startsWith(character) && !isToggled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String format = config.getString("settings.format");
|
||||
String message = event.getMessage().substring(character.length()).trim();
|
||||
String message = event.getMessage().substring(isToggled ? 0 : character.length()).trim();
|
||||
|
||||
BungeeStaffChatEvent chatEvent = new BungeeStaffChatEvent(player, format, message);
|
||||
plugin.getProxy().getPluginManager().callEvent(chatEvent);
|
||||
|
@ -76,4 +86,15 @@ public class BungeeChatListener implements Listener
|
|||
return TextComponent.fromLegacyText(clr(text));
|
||||
}
|
||||
|
||||
public boolean togglePlayer(UUID player)
|
||||
{
|
||||
if (toggledPlayers.contains(player))
|
||||
{
|
||||
toggledPlayers.remove(player);
|
||||
return false;
|
||||
}
|
||||
toggledPlayers.add(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package me.oskar3123.staffchat.spigot;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.oskar3123.staffchat.spigot.command.StaffChatCommand;
|
||||
import me.oskar3123.staffchat.spigot.listener.ChatListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin
|
||||
|
@ -12,6 +14,7 @@ public class Main extends JavaPlugin
|
|||
public final String seePerm = "staffchat.see";
|
||||
public final String commandPerm = "staffchat.command";
|
||||
public final String reloadPerm = "staffchat.reload";
|
||||
public final ChatListener chatListener = new ChatListener(this);
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
|
@ -21,6 +24,14 @@ public class Main extends JavaPlugin
|
|||
registerEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDefaultConfig()
|
||||
{
|
||||
super.saveDefaultConfig();
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void registerCommands()
|
||||
{
|
||||
getCommand("staffchat").setExecutor(new StaffChatCommand(this));
|
||||
|
@ -28,7 +39,21 @@ public class Main extends JavaPlugin
|
|||
|
||||
private void registerEvents()
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(this.chatListener, this);
|
||||
}
|
||||
|
||||
private boolean isPlaceholderApiEnabled()
|
||||
{
|
||||
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
}
|
||||
|
||||
public String replacePlaceholders(Player player, String string)
|
||||
{
|
||||
if (!isPlaceholderApiEnabled())
|
||||
{
|
||||
return string;
|
||||
}
|
||||
return PlaceholderAPI.setPlaceholders(player, string);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ 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
|
||||
{
|
||||
|
@ -45,14 +46,36 @@ public class StaffChatCommand implements CommandExecutor
|
|||
}
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("toggle"))
|
||||
{
|
||||
if (sender.hasPermission(plugin.usePerm))
|
||||
{
|
||||
toggle(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(noPerm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
help(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void playerOnly(CommandSender sender)
|
||||
{
|
||||
sender.sendMessage(clr(config.getString("messages.prefix") + config.getString("messages.playeronly")));
|
||||
}
|
||||
|
||||
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.usePerm))
|
||||
{
|
||||
sender.sendMessage(prefix + "Message prefix: " + config.getString("settings.character"));
|
||||
sender.sendMessage(prefix + "/" + label + " toggle - Toggles auto staffchat");
|
||||
}
|
||||
if (sender.hasPermission(plugin.reloadPerm))
|
||||
{
|
||||
sender.sendMessage(prefix + "/" + label + " reload - Reloads the config file");
|
||||
|
@ -66,6 +89,18 @@ public class StaffChatCommand implements CommandExecutor
|
|||
sender.sendMessage(clr(config.getString("messages.prefix") + config.getString("messages.reloaded")));
|
||||
}
|
||||
|
||||
private void toggle(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
playerOnly(sender);
|
||||
return;
|
||||
}
|
||||
boolean toggled = plugin.chatListener.togglePlayer(((Player) sender).getUniqueId());
|
||||
String state = toggled ? config.getString("messages.onstring") : config.getString("messages.offstring");
|
||||
sender.sendMessage(clr(config.getString("messages.prefix") + String.format(config.getString("messages.toggled"), state)));
|
||||
}
|
||||
|
||||
private String clr(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
|
|
|
@ -10,10 +10,15 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatListener implements Listener
|
||||
{
|
||||
|
||||
private Main plugin;
|
||||
private Set<UUID> toggledPlayers = new HashSet<>();
|
||||
|
||||
public ChatListener(Main plugin)
|
||||
{
|
||||
|
@ -30,13 +35,18 @@ public class ChatListener implements Listener
|
|||
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
String character = config.getString("settings.character");
|
||||
if (!event.getMessage().startsWith(character))
|
||||
boolean isToggled = toggledPlayers.contains(event.getPlayer().getUniqueId());
|
||||
if (!event.getMessage().startsWith(character) && !isToggled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String format = config.getString("settings.format");
|
||||
String message = event.getMessage().substring(character.length()).trim();
|
||||
String message = event.getMessage().substring(isToggled ? 0 : character.length()).trim();
|
||||
if (config.getBoolean("settings.replaceplaceholdersinmessage"))
|
||||
{
|
||||
message = plugin.replacePlaceholders(event.getPlayer(), message);
|
||||
}
|
||||
|
||||
StaffChatEvent chatEvent = new StaffChatEvent(event.getPlayer(), format, message);
|
||||
Bukkit.getServer().getPluginManager().callEvent(chatEvent);
|
||||
|
@ -47,8 +57,10 @@ public class ChatListener implements Listener
|
|||
format = chatEvent.getFormat();
|
||||
|
||||
format = format.replaceAll("\\{NAME\\}", StringUtils.sanitize(event.getPlayer().getName()));
|
||||
format = format.replaceAll("\\{MESSAGE\\}", StringUtils.sanitize(message));
|
||||
format = ChatColor.translateAlternateColorCodes('&', format);
|
||||
format = plugin.replacePlaceholders(event.getPlayer(), format);
|
||||
format = format.replaceAll("\\{MESSAGE\\}", StringUtils.sanitize(message));
|
||||
|
||||
final String finalMessage = format;
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
|
@ -59,4 +71,15 @@ public class ChatListener implements Listener
|
|||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public boolean togglePlayer(UUID player)
|
||||
{
|
||||
if (toggledPlayers.contains(player))
|
||||
{
|
||||
toggledPlayers.remove(player);
|
||||
return false;
|
||||
}
|
||||
toggledPlayers.add(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
name: StaffChat
|
||||
authors: [oskar3123]
|
||||
main: me.oskar3123.staffchat.bungee.BungeeMain
|
||||
version: 1.1.5
|
||||
version: 1.2.0
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
settings:
|
||||
character: '@'
|
||||
format: '&b{NAME}: {MESSAGE}'
|
||||
replaceplaceholdersinmessage: true
|
||||
messages:
|
||||
prefix: '&7StaffChat&8> &7'
|
||||
nopermission: '&cYou don''t have permission to do that'
|
||||
reloaded: 'Reloaded the config file'
|
||||
playeronly: '&cPlayer only command'
|
||||
reloaded: 'Reloaded the config file'
|
||||
toggled: 'You toggled auto staffchat %s'
|
||||
onstring: 'on'
|
||||
offstring: 'off'
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
name: StaffChat
|
||||
authors: [oskar3123]
|
||||
main: me.oskar3123.staffchat.spigot.Main
|
||||
version: 1.1.5
|
||||
|
||||
api-version: 1.13
|
||||
version: 1.2.0
|
||||
softdepend: [PlaceholderAPI]
|
||||
commands:
|
||||
staffchat:
|
||||
usage: /<command>
|
||||
description: Used to reload the config file.
|
||||
|
||||
permissions:
|
||||
staffchat.*:
|
||||
description: Gives you permission to everything in the plugin.
|
||||
|
|
Loading…
Reference in New Issue