mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Improve hook handlers
This commit is contained in:
1 parent
02feb2592d
commit
6f1b719e44
8 files changed
+74
-7
No files matched your search
@@ -62,11 +62,11 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
||||
return user;
|
||||
}
|
||||
|
||||
public ChatChannel getChatChannel() {
|
||||
public ChatChannel getChannel() {
|
||||
return chatChannel;
|
||||
}
|
||||
|
||||
public void setChatChannel(ChatChannel chatChannel) {
|
||||
public void setChannel(ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ public class ChatFormatEvent extends Event implements Cancellable {
|
||||
return user;
|
||||
}
|
||||
|
||||
public ChatChannel getChatChannel() {
|
||||
public ChatChannel getChannel() {
|
||||
return chatChannel;
|
||||
}
|
||||
|
||||
public void setChatChannel(ChatChannel chatChannel) {
|
||||
public void setChannel(ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ItemLinkHandler implements Listener {
|
||||
public void onItemLink(ChatComponentEvent event) {
|
||||
// Handle item linking placeholders
|
||||
if (event.getUser().isOnline()) {
|
||||
for (Pattern pattern : event.getChatChannel().getItemLinkPatterns()) {
|
||||
for (Pattern pattern : event.getChannel().getItemLinkPatterns()) {
|
||||
String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
|
||||
|
||||
if (event.getOriginalMessage().contains(patternContent)) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.gmail.nossr50.api.PartyAPI;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -41,6 +42,17 @@ public final class CarbonChatMCMMO extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(ChatFormatEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
if (!isInParty(event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class FilterHandler implements Listener {
|
||||
|
||||
String filterText = moderation.getConfig().getString("filters.filter-text", "****");
|
||||
|
||||
if (channelUsesFilter(event.getChatChannel())) {
|
||||
if (channelUsesFilter(event.getChannel())) {
|
||||
for (String entry : moderation.getConfig().getStringList("filters.filtered-words")) {
|
||||
event.setMessage(event.getMessage().replaceAll(entry, filterText));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -44,6 +45,18 @@ public final class CarbonChatTowny extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(ChatFormatEvent event) {
|
||||
// TODO: event.setFailureMessage
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
if (!isInTown(event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||
String name = event.getResident().getName();
|
||||
|
||||
+43
-1
@@ -9,19 +9,25 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class CarbonChatWorldGuard extends JavaPlugin {
|
||||
|
||||
private static final String KEY = "worldguard-region";
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
carbonChat.getContextManager().register("worldguard-region", (context) -> {
|
||||
carbonChat.getContextManager().register(KEY, (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameRegion(context.getSender(), context.getTarget());
|
||||
}
|
||||
@@ -48,6 +54,42 @@ public final class CarbonChatWorldGuard extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
|
||||
if (!isInRegionOrRegions(value, event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
// TODO: placeholders (regions, etc)
|
||||
event.setFailureMessage(getConfig().getString("cancellation-message"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(ChatFormatEvent event) {
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
|
||||
if (!isInRegionOrRegions(value, event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInRegionOrRegions(Object value, ChatUser user) {
|
||||
if ((value instanceof String)) {
|
||||
return isInRegion((String) value, user);
|
||||
}
|
||||
|
||||
if (value instanceof List) {
|
||||
for (String region : ((List<String>) value)) {
|
||||
if (isInRegion(region, user)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInSameRegion(ChatUser user1, ChatUser user2) {
|
||||
if (!user1.isOnline() || !user2.isOnline()) {
|
||||
return false;
|
||||
|
||||
Whitespace-only changes.
Reference in new issue
Block a user