mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Add ChannelSwitchEvent (#413)
This commit is contained in:
1 parent
8ef507f51c
commit
2ed8ef2298
11 files changed
+126
-1
No files matched your search
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* CarbonChat
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Josua Parks (Vicarious)
|
||||||
|
* Contributors
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package net.draycia.carbon.api.event.events;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player switches channels.
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public interface ChannelSwitchEvent extends CarbonEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player switching channels.
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
CarbonPlayer player();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The channel the player is switching to.
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
ChatChannel channel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the player's new channel.
|
||||||
|
*
|
||||||
|
* @param chatChannel the new channel
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
void channel(final ChatChannel chatChannel);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -48,6 +48,7 @@ import net.draycia.carbon.api.channels.ChannelRegistry;
|
|||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
|
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
|
||||||
|
import net.draycia.carbon.api.event.events.ChannelSwitchEvent;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.common.DataDirectory;
|
import net.draycia.carbon.common.DataDirectory;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
@@ -56,6 +57,7 @@ import net.draycia.carbon.common.config.ConfigManager;
|
|||||||
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||||
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
|
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
|
||||||
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
|
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
|
||||||
|
import net.draycia.carbon.common.event.events.ChannelSwitchEventImpl;
|
||||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
||||||
@@ -399,7 +401,10 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
|||||||
// TODO: trigger platform events related to chat
|
// TODO: trigger platform events related to chat
|
||||||
this.sendMessageInChannel(player, chatChannel, message);
|
this.sendMessageInChannel(player, chatChannel, message);
|
||||||
} else {
|
} else {
|
||||||
player.selectedChannel(chatChannel);
|
final ChannelSwitchEvent switchEvent = new ChannelSwitchEventImpl(player, chatChannel);
|
||||||
|
this.eventHandler.emit(switchEvent);
|
||||||
|
|
||||||
|
player.selectedChannel(switchEvent.channel());
|
||||||
this.carbonMessages.changedChannels(player, channelKey.value());
|
this.carbonMessages.changedChannels(player, channelKey.value());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -111,4 +111,5 @@ public class PartyChatChannel extends ConfigChatChannel {
|
|||||||
party == null ? Component.text("null") : party.name()
|
party == null ? Component.text("null") : party.name()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -97,4 +97,5 @@ public final class IntegrationConfigContainer {
|
|||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* CarbonChat
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Josua Parks (Vicarious)
|
||||||
|
* Contributors
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package net.draycia.carbon.common.event.events;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
|
import net.draycia.carbon.api.event.events.ChannelSwitchEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public class ChannelSwitchEventImpl implements ChannelSwitchEvent {
|
||||||
|
|
||||||
|
private final CarbonPlayer player;
|
||||||
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
|
public ChannelSwitchEventImpl(final CarbonPlayer player, final ChatChannel chatChannel) {
|
||||||
|
this.player = player;
|
||||||
|
this.chatChannel = chatChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CarbonPlayer player() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatChannel channel() {
|
||||||
|
return this.chatChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channel(final ChatChannel chatChannel) {
|
||||||
|
this.chatChannel = chatChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
@@ -117,4 +117,5 @@ public final class MiniPlaceholdersExpansion {
|
|||||||
}
|
}
|
||||||
return this.channels.defaultKey().asString();
|
return this.channels.defaultKey().asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -82,4 +82,5 @@ public final class TagPermissions {
|
|||||||
public static Component parseTags(final String basePermission, final String message, final Predicate<String> permission) {
|
public static Component parseTags(final String basePermission, final String message, final Predicate<String> permission) {
|
||||||
return parseTags(basePermission, message, permission, TagResolver.builder());
|
return parseTags(basePermission, message, permission, TagResolver.builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -335,4 +335,5 @@ public abstract class CachingUserManager implements UserManagerInternal<CarbonPl
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -502,4 +502,5 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
public void party(final @Nullable Party party) {
|
public void party(final @Nullable Party party) {
|
||||||
this.party.set(party == null ? null : party.id());
|
this.party.set(party == null ? null : party.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -133,4 +133,5 @@ public final class PartyInvites {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -200,4 +200,5 @@ public class JSONUserManager extends CachingUserManager {
|
|||||||
Exceptions.rethrow(ex);
|
Exceptions.rethrow(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user