Added Channel.filteranderrormsg()

TBMCPlugins/ButtonChat#61
This commit is contained in:
Norbi Peti 2017-08-05 00:21:57 +02:00
parent 1ddfd1e3cc
commit 1a975e0d8e
4 changed files with 28 additions and 13 deletions

View file

@ -2,7 +2,6 @@ package buttondevteam.core;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -10,7 +9,6 @@ import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.Channel.RecipientTestResult;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.player.TBMCPlayerBase;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
@ -36,14 +34,12 @@ public class MainPlugin extends JavaPlugin {
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class); TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class);
TBMCChatAPI.RegisterChatChannel(Channel.GlobalChat = new Channel("§fg§f", Color.White, "g", null)); TBMCChatAPI.RegisterChatChannel(Channel.GlobalChat = new Channel("§fg§f", Color.White, "g", null));
TBMCChatAPI.RegisterChatChannel(Channel.AdminChat = new Channel("§cADMIN§f", Color.Red, "a", TBMCChatAPI.RegisterChatChannel(
s -> s.isOp() // Channel.AdminChat = new Channel("§cADMIN§f", Color.Red, "a", Channel.filteranderrormsg(null)));
? new RecipientTestResult(0) TBMCChatAPI.RegisterChatChannel(
: new RecipientTestResult("You need to be an admin to use this channel."))); Channel.ModChat = new Channel("§9MOD§f", Color.Blue, "mod", Channel.filteranderrormsg("mod")));
TBMCChatAPI.RegisterChatChannel(Channel.ModChat = new Channel("§9MOD§f", Color.Blue, "mod", TBMCChatAPI
s -> s.isOp() || (s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, "mod")) .RegisterChatChannel(new Channel("§6DEV§", Color.Gold, "dev", Channel.filteranderrormsg("developer")));
? new RecipientTestResult(0) //
: new RecipientTestResult("You need to be a mod to use this channel.")));
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ") Test: " + Test + "."); logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ") Test: " + Test + ".");
} }

View file

@ -127,7 +127,7 @@ public class TBMCCoreAPI {
} }
/** /**
* Registers Bukkit events, handling the exceptions occuring in those events * Registers Bukkit events, handling the exceptions occurring in those events
* *
* @param listener * @param listener
* The class that handles the events * The class that handles the events

View file

@ -6,6 +6,9 @@ import java.util.function.Function;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.core.MainPlugin;
public class Channel { public class Channel {
public final String DisplayName; public final String DisplayName;
@ -43,6 +46,22 @@ public class Channel {
return channels; return channels;
} }
/**
* Convenience method for the function parameter of {@link #Channel(String, Color, String, Function)}. It checks if the sender is OP or optionally has the specified group. The error message is
* generated automatically.
*
* @param permgroup
* The group that can access the channel or <b>null</b> to only allow OPs.
* @return
*/
public static Function<CommandSender, RecipientTestResult> filteranderrormsg(String permgroup) {
return s -> s.isOp() || (permgroup != null
? s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, permgroup) : false)
? new RecipientTestResult(0) //
: new RecipientTestResult("You need to be a(n) " + (permgroup != null ? permgroup : "OP")
+ " to use this channel.");
}
public static Channel GlobalChat; public static Channel GlobalChat;
public static Channel AdminChat; public static Channel AdminChat;
public static Channel ModChat; public static Channel ModChat;

View file

@ -5,8 +5,8 @@ public enum Color implements TellrawSerializableEnum {
0, 170, 170), DarkRed("dark_red", 170, 0, 0), DarkPurple("dark_purple", 0, 170, 0), Gold("gold", 255, 170, 0, 170, 170), DarkRed("dark_red", 170, 0, 0), DarkPurple("dark_purple", 0, 170, 0), Gold("gold", 255, 170,
0), Gray("gray", 170, 170, 170), DarkGray("dark_gray", 85, 85, 85), Blue("blue", 85, 85, 0), Gray("gray", 170, 170, 170), DarkGray("dark_gray", 85, 85, 85), Blue("blue", 85, 85,
255), Green("green", 85, 255, 85), Aqua("aqua", 85, 255, 255), Red("red", 255, 85, 255), Green("green", 85, 255, 85), Aqua("aqua", 85, 255, 255), Red("red", 255, 85,
85), LightPurple("light_purple", 255, 85, 255), Yellow("yellow", 255, 255, 85), LightPurple("light_purple", 255, 85,
85), White("white", 255, 255, 255), RPC("rpc", 0, 0, 0); 255), Yellow("yellow", 255, 255, 85), White("white", 255, 255, 255);
private final String name; private final String name;
private final int red; private final int red;