mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-01-22 07:21:34 +01:00
Add user_mask option for commands.
This commit is contained in:
parent
d4095fc9f0
commit
a0db45b042
@ -326,7 +326,7 @@
|
||||
<dependency>
|
||||
<groupId>com.cnaude.griefprevention</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>11.9</version>
|
||||
<version>12.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
2
pom.xml
2
pom.xml
@ -329,7 +329,7 @@
|
||||
<dependency>
|
||||
<groupId>com.cnaude.griefprevention</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>11.9</version>
|
||||
<version>12.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing only -->
|
||||
|
@ -49,6 +49,9 @@ public class GamePlayerChatListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||
String message = event.getMessage();
|
||||
if(plugin.isPluginEnabled("GriefPrevention")) {
|
||||
return;
|
||||
}
|
||||
plugin.logDebug("ChatFormat [" + event.isCancelled() + "]: " + event.getFormat());
|
||||
if (message.startsWith(PurpleIRC.TOWNYTAG)) {
|
||||
event.setMessage(message.replace(PurpleIRC.TOWNYTAG, ""));
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2014 cnaude
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.cnaude.purpleirc.GameListeners;
|
||||
|
||||
import com.cnaude.purpleirc.PurpleBot;
|
||||
import com.cnaude.purpleirc.PurpleIRC;
|
||||
import me.ryanhamshire.GriefPrevention.ChatMode;
|
||||
import me.ryanhamshire.GriefPrevention.events.ChatEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author cnaude
|
||||
*/
|
||||
public class GriefPreventionListener implements Listener {
|
||||
|
||||
private final PurpleIRC plugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public GriefPreventionListener(PurpleIRC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChatEvent(ChatEvent event) {
|
||||
ChatMode chatMode = event.getChatMode();
|
||||
Player player = event.getPlayer();
|
||||
String message = event.getMessage();
|
||||
plugin.logDebug("GP (" + chatMode
|
||||
+ "): " + player.getName()
|
||||
+ ": " + message);
|
||||
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
||||
if (chatMode.equals(ChatMode.NORMAL)) {
|
||||
ircBot.gameChat(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -105,6 +105,7 @@ public class IRCMessageHandler {
|
||||
String gcUsage = (String) ircBot.commandMap.get(channelName).get(command).get("game_command_usage");
|
||||
List<String> extraCommands = ircBot.extraCommandMap.get(channelName).get(command);
|
||||
List<String> gameCommands = new ArrayList<>();
|
||||
List<String> userMasks = ircBot.commandUsermasksMap.get(channelName).get(command);
|
||||
gameCommands.add(gc);
|
||||
gameCommands.addAll(extraCommands);
|
||||
String modes = (String) ircBot.commandMap.get(channelName).get(command).get("modes");
|
||||
@ -119,7 +120,9 @@ public class IRCMessageHandler {
|
||||
|
||||
plugin.logDebug("Target: " + target);
|
||||
|
||||
if (isValidMode(modes, user, channel) && checkPerm(perm, user.getNick())) {
|
||||
if (isValidMode(modes, user, channel)
|
||||
&& checkPerm(perm, user.getNick())
|
||||
&& checkHostMask(ircBot, user, userMasks)) {
|
||||
gc_loop:
|
||||
for (String gameCommand : gameCommands) {
|
||||
switch (gameCommand) {
|
||||
@ -178,7 +181,7 @@ public class IRCMessageHandler {
|
||||
if (plugin.adminPrivateChatHook != null) {
|
||||
String newMessage = ircBot.filterMessage(
|
||||
plugin.tokenizer.ircChatToGameTokenizer(ircBot, user, channel, plugin.getMsgTemplate(
|
||||
ircBot.botNick, channelName, TemplateName.IRC_A_CHAT), commandArgs), channelName);
|
||||
ircBot.botNick, channelName, TemplateName.IRC_A_CHAT), commandArgs), channelName);
|
||||
plugin.adminPrivateChatHook.sendMessage(newMessage, user.getNick());
|
||||
String acResponse = plugin.tokenizer.msgChatResponseTokenizer(target, commandArgs, plugin.getMsgTemplate(TemplateName.IRC_A_RESPONSE));
|
||||
if (!acResponse.isEmpty()) {
|
||||
@ -214,7 +217,7 @@ public class IRCMessageHandler {
|
||||
if (commandArgsArray.length >= startPos) {
|
||||
gameCommand = gameCommand.replace("%ARG" + startPos + "+%",
|
||||
Joiner.on(" ").join(Arrays.copyOfRange(commandArgsArray, startPos - 1, commandArgsArray.length)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameCommand.matches(".*%ARG\\d+%.*")
|
||||
@ -225,15 +228,15 @@ public class IRCMessageHandler {
|
||||
ChatColor.translateAlternateColorCodes('&', gcUsage)));
|
||||
break gc_loop;
|
||||
} else {
|
||||
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
|
||||
try {
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
new IRCConsoleCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
gameCommand.trim()));
|
||||
} catch (Exception ex) {
|
||||
plugin.logError(ex.getMessage());
|
||||
}
|
||||
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
|
||||
try {
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
new IRCConsoleCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
gameCommand.trim()));
|
||||
} catch (Exception ex) {
|
||||
plugin.logError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -281,6 +284,7 @@ public class IRCMessageHandler {
|
||||
}
|
||||
|
||||
private boolean isValidMode(String modes, User user, Channel channel) {
|
||||
plugin.logDebug("[isValidMode]: " + modes);
|
||||
boolean modeOkay = false;
|
||||
if (modes.equals("*")) {
|
||||
return true;
|
||||
@ -344,4 +348,23 @@ public class IRCMessageHandler {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkHostMask(PurpleBot ircBot, User user, List<String> userMasks) {
|
||||
if (userMasks.isEmpty()) {
|
||||
plugin.logDebug("checkHostMask [empty]: " + true);
|
||||
return true;
|
||||
}
|
||||
for (String userMask : userMasks) {
|
||||
plugin.logDebug("checkHostMask [testing]: " + userMask);
|
||||
if (userMask.equals("*")
|
||||
|| userMask.isEmpty()
|
||||
|| ircBot.checkUserMask(user, userMask)) {
|
||||
plugin.logDebug("checkHostMask [match]: ");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
plugin.logDebug("checkHostMask [no match]: " + false);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ public final class PurpleBot {
|
||||
public String defaultCustomPrefix;
|
||||
public CaseInsensitiveMap<CaseInsensitiveMap<CaseInsensitiveMap<String>>> commandMap;
|
||||
public CaseInsensitiveMap<CaseInsensitiveMap<List<String>>> extraCommandMap;
|
||||
public CaseInsensitiveMap<CaseInsensitiveMap<List<String>>> commandUsermasksMap;
|
||||
public CaseInsensitiveMap<Long> joinNoticeCooldownMap;
|
||||
public ArrayList<CommandSender> whoisSenders;
|
||||
public List<String> channelCmdNotifyRecipients;
|
||||
@ -203,6 +204,7 @@ public final class PurpleBot {
|
||||
this.channelCmdNotifyIgnore = new ArrayList<>();
|
||||
this.commandMap = new CaseInsensitiveMap<>();
|
||||
this.extraCommandMap = new CaseInsensitiveMap<>();
|
||||
this.commandUsermasksMap = new CaseInsensitiveMap<>();
|
||||
this.joinNoticeCooldownMap = new CaseInsensitiveMap<>();
|
||||
this.enabledMessages = new CaseInsensitiveMap<>();
|
||||
this.firstOccurrenceReplacements = new CaseInsensitiveMap<>();
|
||||
@ -717,6 +719,7 @@ public final class PurpleBot {
|
||||
worldList.clear();
|
||||
commandMap.clear();
|
||||
extraCommandMap.clear();
|
||||
commandUsermasksMap.clear();
|
||||
|
||||
channelCmdNotifyEnabled = config.getBoolean("command-notify.enabled", false);
|
||||
plugin.logDebug(" CommandNotifyEnabled => " + channelCmdNotifyEnabled);
|
||||
@ -980,34 +983,45 @@ public final class PurpleBot {
|
||||
// build command map
|
||||
CaseInsensitiveMap<CaseInsensitiveMap<String>> map = new CaseInsensitiveMap<>();
|
||||
CaseInsensitiveMap<List<String>> extraMap = new CaseInsensitiveMap<>();
|
||||
CaseInsensitiveMap<List<String>> userMaskMap = new CaseInsensitiveMap<>();
|
||||
try {
|
||||
for (String command : config.getConfigurationSection("channels." + enChannelName + ".commands").getKeys(false)) {
|
||||
plugin.logDebug(" Command => " + command);
|
||||
CaseInsensitiveMap<String> optionPair = new CaseInsensitiveMap<>();
|
||||
List<String> extraCommands = new ArrayList<>();
|
||||
List<String> userMasks = new ArrayList<>();
|
||||
String commandKey = "channels." + enChannelName + ".commands." + command + ".";
|
||||
|
||||
optionPair.put("modes", config.getString(commandKey + "modes", "*"));
|
||||
optionPair.put("private", config.getString(commandKey + "private", "false"));
|
||||
optionPair.put("ctcp", config.getString(commandKey + "ctcp", "false"));
|
||||
optionPair.put("game_command", config.getString(commandKey + "game_command", ""));
|
||||
optionPair.put("game_command_usage", config.getString(commandKey + "game_command_usage", ""));
|
||||
optionPair.put("sender", config.getString(commandKey + "sender", "CONSOLE"));
|
||||
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
|
||||
plugin.logDebug("extra_commands: " + extraCommands.toString());
|
||||
optionPair.put("sender", config.getString(commandKey + "sender", "CONSOLE"));
|
||||
optionPair.put("private_listen", config.getString(commandKey + "private_listen", "true"));
|
||||
optionPair.put("channel_listen", config.getString(commandKey + "channel_listen", "true"));
|
||||
optionPair.put("perm", config.getString(commandKey + "perm", ""));
|
||||
for (String s : optionPair.keySet()) {
|
||||
config.set(commandKey + s, optionPair.get(s));
|
||||
}
|
||||
|
||||
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
|
||||
plugin.logDebug("extra_commands: " + extraCommands.toString());
|
||||
userMasks.addAll(config.getStringList(commandKey + "user_masks"));
|
||||
plugin.logDebug("user_masks: " + userMasks.toString());
|
||||
|
||||
map.put(command, optionPair);
|
||||
extraMap.put(command, extraCommands);
|
||||
userMaskMap.put(command, userMasks);
|
||||
config.set(commandKey + "extra_commands", extraCommands);
|
||||
config.set(commandKey + "user_masks", userMasks);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.logError("No commands found for channel " + enChannelName);
|
||||
}
|
||||
commandMap.put(channelName, map);
|
||||
extraCommandMap.put(channelName, extraMap);
|
||||
commandUsermasksMap.put(channelName, userMaskMap);
|
||||
if (map.isEmpty()) {
|
||||
plugin.logInfo("No commands specified!");
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import com.cnaude.purpleirc.GameListeners.GamePlayerKickListener;
|
||||
import com.cnaude.purpleirc.GameListeners.GamePlayerPlayerAchievementAwardedListener;
|
||||
import com.cnaude.purpleirc.GameListeners.GamePlayerQuitListener;
|
||||
import com.cnaude.purpleirc.GameListeners.GameServerCommandListener;
|
||||
import com.cnaude.purpleirc.GameListeners.GriefPreventionListener;
|
||||
import com.cnaude.purpleirc.GameListeners.HeroChatListener;
|
||||
import com.cnaude.purpleirc.GameListeners.McMMOChatListener;
|
||||
import com.cnaude.purpleirc.GameListeners.OreBroadcastListener;
|
||||
@ -1438,10 +1439,11 @@ public class PurpleIRC extends JavaPlugin {
|
||||
heroChatEmoteFormat = heroConfig.getString("format.emote", "");
|
||||
} else {
|
||||
hookList.add(hookFormat(PL_HEROCHAT, false));
|
||||
}
|
||||
}
|
||||
if (isPluginEnabled(PL_GRIEFPREVENTION)) {
|
||||
hookList.add(hookFormat(PL_GRIEFPREVENTION, true));
|
||||
griefPreventionHook = new GriefPreventionHook(this);
|
||||
griefPreventionHook = new GriefPreventionHook(this);
|
||||
getServer().getPluginManager().registerEvents(new GriefPreventionListener(this), this);
|
||||
} else {
|
||||
hookList.add(hookFormat(PL_GRIEFPREVENTION, false));
|
||||
}
|
||||
@ -1643,15 +1645,15 @@ public class PurpleIRC extends JavaPlugin {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMuted(Player player) {
|
||||
if (griefPreventionHook != null) {
|
||||
if (griefPreventionHook.isMuted(player)) {
|
||||
logDebug("GP: Player " + player.getDisplayName() + " is muted.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,13 @@ public class BotsAndChannels {
|
||||
public ArrayList<String> bot = new ArrayList<>();
|
||||
public ArrayList<String> channel = new ArrayList<>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
* @param sender
|
||||
* @param botName
|
||||
* @param channelName
|
||||
*/
|
||||
public BotsAndChannels(PurpleIRC plugin, CommandSender sender, String botName, String channelName) {
|
||||
if (plugin.ircBots.containsKey(botName)) {
|
||||
bot.add(botName);
|
||||
@ -42,6 +49,11 @@ public class BotsAndChannels {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
* @param sender
|
||||
*/
|
||||
public BotsAndChannels(PurpleIRC plugin, CommandSender sender) {
|
||||
for (String botName : plugin.ircBots.keySet()) {
|
||||
bot.add(botName);
|
||||
|
Loading…
Reference in New Issue
Block a user