File tree Expand file tree Collapse file tree 5 files changed +45
-3
lines changed
java/de/olivermakesco/bta_utils Expand file tree Collapse file tree 5 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,5 @@ public void onInitialize() {
11
11
DiscordClient .init ();
12
12
DiscordChatRelay .sendMessageAsBot ("**Server Started**" );
13
13
}).start ();
14
- Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
15
- DiscordChatRelay .sendMessageAsBot ("**Server Stopped**" );
16
- }));
17
14
}
18
15
}
Original file line number Diff line number Diff line change
1
+ package de .olivermakesco .bta_utils .mixin .server ;
2
+
3
+ import de .olivermakesco .bta_utils .server .DiscordChatRelay ;
4
+ import net .minecraft .core .entity .Entity ;
5
+ import net .minecraft .server .entity .player .EntityPlayerMP ;
6
+ import org .spongepowered .asm .mixin .Mixin ;
7
+ import org .spongepowered .asm .mixin .Shadow ;
8
+ import org .spongepowered .asm .mixin .injection .At ;
9
+ import org .spongepowered .asm .mixin .injection .Inject ;
10
+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
11
+
12
+ @ Mixin (value = EntityPlayerMP .class , remap = false )
13
+ public abstract class Mixin_EntityPlayerMP {
14
+ @ Shadow protected abstract String deathMessage (Entity entity );
15
+
16
+ @ Inject (
17
+ method = "onDeath" ,
18
+ at = @ At ("RETURN" )
19
+ )
20
+ void sendDeathMessage (Entity entity , CallbackInfo ci ) {
21
+ String message = deathMessage (entity ).replaceAll ("§." , "" );
22
+ DiscordChatRelay .sendMessageAsBot ("**" + message + "**" );
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ package de .olivermakesco .bta_utils .mixin .server ;
2
+
3
+ import de .olivermakesco .bta_utils .server .DiscordChatRelay ;
4
+ import net .minecraft .server .MinecraftServer ;
5
+ import org .spongepowered .asm .mixin .Mixin ;
6
+ import org .spongepowered .asm .mixin .injection .At ;
7
+ import org .spongepowered .asm .mixin .injection .Inject ;
8
+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
9
+
10
+ @ Mixin (value = MinecraftServer .class , remap = false )
11
+ public class Mixin_MinecraftServer {
12
+ @ Inject (
13
+ method = "initiateShutdown" ,
14
+ at = @ At ("RETURN" )
15
+ )
16
+ void sendStopMessage (CallbackInfo ci ) {
17
+ DiscordChatRelay .sendMessageAsBot ("**Server stopped.**" );
18
+ }
19
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ public class DiscordChatRelay {
11
11
public static void sendToMinecraft (String author , String message ) {
12
12
MinecraftServer server = MinecraftServer .getInstance ();
13
13
message = "[" + TextFormatting .PURPLE + "DISCORD" + TextFormatting .RESET + "] <" + author + "> " + message ;
14
+ System .out .println (message );
14
15
String [] lines = message .split ("\n " );
15
16
for (String chatMessage : lines ) {
16
17
server .configManager .sendEncryptedChatToAllPlayers (
Original file line number Diff line number Diff line change 5
5
"compatibilityLevel" : " JAVA_8" ,
6
6
"mixins" : [
7
7
" core.Mixin_BlockFarmland" ,
8
+ " server.Mixin_EntityPlayerMP" ,
8
9
" server.Mixin_NetLoginHandler" ,
9
10
" server.Mixin_NetServerHandler"
10
11
],
You can’t perform that action at this time.
0 commit comments