mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-21 02:31:37 +01:00
Working minecraft to discord chat
This commit is contained in:
parent
91e2ed87e4
commit
325d029d76
@ -28,7 +28,7 @@ import com.discordsrv.common.feature.messageforwarding.game.MinecraftToDiscordCh
|
||||
import com.discordsrv.fabric.config.main.FabricConfig;
|
||||
import com.discordsrv.fabric.console.FabricConsole;
|
||||
import com.discordsrv.fabric.game.handler.FabricCommandHandler;
|
||||
import com.discordsrv.fabric.listener.FabricChatListener;
|
||||
import com.discordsrv.fabric.module.FabricChatModule;
|
||||
import com.discordsrv.fabric.player.FabricPlayerProvider;
|
||||
import com.discordsrv.fabric.plugin.FabricModManager;
|
||||
import com.discordsrv.common.AbstractDiscordSRV;
|
||||
@ -69,15 +69,17 @@ public class FabricDiscordSRV extends AbstractDiscordSRV<DiscordSRVFabricBootstr
|
||||
this.messagesConfigManager = new MessagesConfigManager<>(this, MessagesConfig::new);
|
||||
|
||||
load();
|
||||
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
new FabricChatListener(this);
|
||||
@Override
|
||||
protected void enable() throws Throwable {
|
||||
super.enable();
|
||||
|
||||
// Chat
|
||||
registerModule(MinecraftToDiscordChatModule::new);
|
||||
}
|
||||
registerModule(FabricChatModule::new);
|
||||
|
||||
}
|
||||
|
||||
//TODO: Implement this method. Maybe with KnotClassloader?
|
||||
@Override
|
||||
@ -149,9 +151,4 @@ public class FabricDiscordSRV extends AbstractDiscordSRV<DiscordSRVFabricBootstr
|
||||
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
|
||||
return messagesConfigManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() throws Throwable {
|
||||
super.enable();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.discordsrv.fabric.module;
|
||||
|
||||
import com.discordsrv.common.core.module.type.AbstractModule;
|
||||
import com.discordsrv.fabric.FabricDiscordSRV;
|
||||
|
||||
public abstract class AbstractFabricModule extends AbstractModule<FabricDiscordSRV> {
|
||||
protected boolean enabled = false;
|
||||
|
||||
public AbstractFabricModule(FabricDiscordSRV discordSRV) {
|
||||
super(discordSRV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
enabled = true;
|
||||
this.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public void register() {}
|
||||
}
|
@ -16,37 +16,38 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.discordsrv.fabric.listener;
|
||||
package com.discordsrv.fabric.module;
|
||||
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import com.discordsrv.api.events.message.receive.game.GameChatMessageReceiveEvent;
|
||||
import com.discordsrv.common.feature.channel.global.GlobalChannel;
|
||||
import com.discordsrv.common.util.ComponentUtil;
|
||||
import com.discordsrv.fabric.FabricDiscordSRV;
|
||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.network.message.MessageType;
|
||||
import net.minecraft.network.message.SignedMessage;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public class FabricChatListener {
|
||||
public class FabricChatModule extends AbstractFabricModule {
|
||||
private final FabricDiscordSRV discordSRV;
|
||||
|
||||
public FabricChatListener(FabricDiscordSRV discordSRV) {
|
||||
public FabricChatModule(FabricDiscordSRV discordSRV) {
|
||||
super(discordSRV);
|
||||
this.discordSRV = discordSRV;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
ServerMessageEvents.CHAT_MESSAGE.register(this::onChatMessage);
|
||||
}
|
||||
|
||||
private void onChatMessage(SignedMessage signedMessage, ServerPlayerEntity serverPlayerEntity, MessageType.Parameters parameters) {
|
||||
// Component component = discordSRV.componentFactory().parse(signedMessage.getSignedContent());
|
||||
//
|
||||
// discordSRV.eventBus().publish(new GameChatMessageReceiveEvent(
|
||||
// null,
|
||||
// discordSRV.playerProvider().player(serverPlayerEntity),
|
||||
// MinecraftComponent.fromAdventure((com.discordsrv.unrelocate.net.kyori.adventure.text.Component) component),
|
||||
// new GlobalChannel(discordSRV),
|
||||
// false
|
||||
// ));
|
||||
}
|
||||
if (!enabled) return;
|
||||
|
||||
discordSRV.eventBus().publish(new GameChatMessageReceiveEvent(
|
||||
null,
|
||||
discordSRV.playerProvider().player(serverPlayerEntity),
|
||||
ComponentUtil.fromPlain(signedMessage.getSignedContent()),
|
||||
new GlobalChannel(discordSRV),
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user