generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7735dba
commit efec548
Showing
16 changed files
with
241 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/cn/focot/codelab/minecodecraft/event/EventMsg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cn.focot.codelab.minecodecraft.event; | ||
|
||
import cn.focot.codelab.minecodecraft.MineCodeCraftMod; | ||
import com.google.gson.Gson; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.StringJoiner; | ||
|
||
public abstract class EventMsg { | ||
public static final Gson gson = new Gson(); | ||
public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); // RFC3339 | ||
|
||
protected String msgSubject; | ||
public String time = dateFormat.format(new Date()); | ||
public byte[] toBytes() { | ||
return EventMsg.gson.toJson(this).getBytes(StandardCharsets.UTF_8); | ||
} | ||
public void publish() { | ||
if (MineCodeCraftMod.hasNatsConnection()) { | ||
MineCodeCraftMod.getNatsConnection().publish( | ||
new StringJoiner(MineCodeCraftMod.getConfig().getConfigBean().nats.prefix, ".", this.msgSubject).toString(), | ||
this.toBytes()); | ||
} | ||
}; | ||
|
||
protected EventMsg(String msgSubject) { | ||
this.msgSubject = msgSubject; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/cn/focot/codelab/minecodecraft/event/PlayerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.focot.codelab.minecodecraft.event; | ||
|
||
import cn.focot.codelab.minecodecraft.helpers.PlayerData; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
public class PlayerAction extends EventMsg { | ||
public String action; // join, disconnect | ||
public String name; | ||
public String uuid; | ||
public String ip; | ||
public int onlineTime; | ||
public int blockBreak; | ||
|
||
protected PlayerAction(String msgSubject) { | ||
super(msgSubject); | ||
} | ||
|
||
public static PlayerAction of(ServerPlayerEntity player, PlayerData data, String action) { | ||
PlayerAction e = new PlayerAction("playerAction"); | ||
e.action = action; | ||
e.name = player.getName().getString(); | ||
e.uuid = player.getUuidAsString(); | ||
e.ip = player.getIp(); | ||
e.onlineTime = data.getOnlineTime(); | ||
e.blockBreak = data.getBlockBreak(); | ||
return e; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/cn/focot/codelab/minecodecraft/event/ServerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.focot.codelab.minecodecraft.event; | ||
|
||
public class ServerAction extends EventMsg{ | ||
public String action; // lunch, stop | ||
|
||
protected ServerAction(String msgSubject) { | ||
super(msgSubject); | ||
} | ||
|
||
public static ServerAction of(String action) { | ||
ServerAction e = new ServerAction("serverAction"); | ||
e.action = action; | ||
return e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.