generated from Turnip-Labs/bta-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
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
fb75368
commit 4b1ae56
Showing
13 changed files
with
262 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<img align="right" height="128" width="128" alt="" loading="lazy" decoding="async" src="./src/main/resources/icon.png"/> | ||
|
||
# Playground | ||
# Proximity Chat | ||
|
||
This is the beginning of awesome mods! | ||
Select your chat channel and keep the chat within a circle. | ||
|
||
> **Important** | ||
> Required [Babric](https://github.com/Turnip-Labs/babric-instance-repo/releases) to run the mod. | ||
> - This is a **server-side mod**. You must install it on the server. | ||
> - Required [Babric](https://github.com/Turnip-Labs/babric-instance-repo/releases) to run the mod. | ||
|
||
## Features | ||
|
||
- Feature #1 | ||
- Feature #2 | ||
- Feature #3 | ||
- Chat can be sent to a set radius of the player using proximity channel. | ||
- Select your channel with `/channel global` or `/channel prox`. Your later message will be sent into the selected channel. | ||
- If you're in the global chat, you can quickly send a proximity message by adding `# ` (a hash and 1 space) in front of your message. Eg: `# Is anyone around me?`. | ||
- Set your proximity radius with `/radius <radius>`. Eg: `/radius 50`. |
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 was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
src/main/java/rootenginear/proximitychat/ProximityChat.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,24 @@ | ||
package rootenginear.proximitychat; | ||
|
||
import net.fabricmc.api.DedicatedServerModInitializer; | ||
import net.minecraft.core.net.PropertyManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
|
||
public class ProximityChat implements DedicatedServerModInitializer { | ||
public static final String MOD_ID = "proximitychat"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
|
||
public static int RADIUS; | ||
|
||
@Override | ||
public void onInitializeServer() { | ||
PropertyManager propertyManagerObj = new PropertyManager(new File("server.properties")); | ||
|
||
RADIUS = propertyManagerObj.getIntProperty("default-proximity-radius", 50); | ||
|
||
LOGGER.info("Proximity Chat initialized."); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/rootenginear/proximitychat/command/ChannelCommand.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,54 @@ | ||
package rootenginear.proximitychat.command; | ||
|
||
import net.minecraft.core.net.command.CommandError; | ||
import net.minecraft.core.net.command.CommandHandler; | ||
import net.minecraft.core.net.command.CommandSender; | ||
import net.minecraft.core.net.command.ServerCommand; | ||
import net.minecraft.server.MinecraftServer; | ||
import rootenginear.proximitychat.struct.PlayerChannelConfig; | ||
|
||
import static rootenginear.proximitychat.store.PlayerChannelData.getPlayerChannelData; | ||
import static rootenginear.proximitychat.store.PlayerChannelData.setPlayerChannelData; | ||
|
||
public class ChannelCommand extends ServerCommand { | ||
public ChannelCommand(MinecraftServer server) { | ||
super(server, "channel", "ch"); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { | ||
if (!sender.isPlayer()) { | ||
throw new CommandError("Must be used by a player!"); | ||
} | ||
if (args.length > 1) { | ||
return false; | ||
} | ||
String name = sender.getName(); | ||
if (args.length == 0) { | ||
PlayerChannelConfig cfg = getPlayerChannelData(name); | ||
sender.sendMessage(name + "'s current channel is: " + (cfg.isGlobal ? "Global" : "Proximity")); | ||
return true; | ||
} | ||
switch (args[0]) { | ||
case "global": | ||
case "proximity": | ||
case "prox": | ||
setPlayerChannelData(name, args[0]); | ||
sender.sendMessage("Changed " + name + "'s channel to: " + (args[0].equals("global") ? "Global" : "Proximity")); | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean opRequired(String[] args) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { | ||
sender.sendMessage("/channel"); | ||
sender.sendMessage("/channel <global|prox>"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/rootenginear/proximitychat/mixin/CommandsMixin.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,24 @@ | ||
package rootenginear.proximitychat.mixin; | ||
|
||
import net.minecraft.core.net.command.Command; | ||
import net.minecraft.core.net.command.Commands; | ||
import net.minecraft.server.MinecraftServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import rootenginear.proximitychat.command.ChannelCommand; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(value = {Commands.class}, remap = false) | ||
public class CommandsMixin { | ||
@Shadow | ||
public static List<Command> commands; | ||
|
||
@Inject(method = "initServerCommands", at = @At("TAIL")) | ||
private static void addChannelCmd(MinecraftServer server, CallbackInfo ci) { | ||
commands.add(new ChannelCommand(server)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/rootenginear/proximitychat/mixin/NetServerHandlerMixin.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,56 @@ | ||
package rootenginear.proximitychat.mixin; | ||
|
||
import net.minecraft.core.net.packet.Packet3Chat; | ||
import net.minecraft.server.entity.player.EntityPlayerMP; | ||
import net.minecraft.server.net.ServerConfigurationManager; | ||
import net.minecraft.server.net.handler.NetServerHandler; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import rootenginear.proximitychat.struct.PlayerChannelConfig; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static rootenginear.proximitychat.store.PlayerChannelData.getPlayerChannelData; | ||
|
||
@Mixin(value = {NetServerHandler.class}, remap = false) | ||
public class NetServerHandlerMixin { | ||
@Shadow | ||
private EntityPlayerMP playerEntity; | ||
|
||
@Redirect( | ||
method = "handleChat(Lnet/minecraft/core/net/packet/Packet3Chat;)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/server/net/ServerConfigurationManager;sendEncryptedChatToAllPlayers(Ljava/lang/String;)V" | ||
) | ||
) | ||
private void proximityChat(ServerConfigurationManager instance, String s) { | ||
Pattern playerChatPattern = Pattern.compile("<(.+?)> §0(.+)"); | ||
Matcher result = playerChatPattern.matcher(s); | ||
|
||
if (!result.matches()) { | ||
instance.sendEncryptedChatToAllPlayers(s); | ||
return; | ||
} | ||
|
||
String playerName = result.group(1); | ||
String msg = result.group(2); | ||
|
||
PlayerChannelConfig playerData = getPlayerChannelData(playerName); | ||
if (playerData.isGlobal || msg.startsWith("# ")) { | ||
instance.sendEncryptedChatToAllPlayers(s.replaceFirst("# ", "")); | ||
return; | ||
} | ||
instance.sendPacketToPlayersAroundPoint( | ||
this.playerEntity.x, | ||
this.playerEntity.y, | ||
this.playerEntity.z, | ||
playerData.radius, | ||
this.playerEntity.dimension, | ||
new Packet3Chat("<✉ " + playerName + "> §0" + msg.replaceFirst("# ", "")) | ||
); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/rootenginear/proximitychat/mixin/ServerConfigurationManagerMixin.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,36 @@ | ||
package rootenginear.proximitychat.mixin; | ||
|
||
import net.minecraft.core.entity.player.EntityPlayer; | ||
import net.minecraft.core.net.packet.Packet; | ||
import net.minecraft.core.net.packet.Packet3Chat; | ||
import net.minecraft.core.util.helper.AES; | ||
import net.minecraft.server.entity.player.EntityPlayerMP; | ||
import net.minecraft.server.net.ServerConfigurationManager; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(value = {ServerConfigurationManager.class}, remap = false) | ||
public class ServerConfigurationManagerMixin { | ||
@Shadow | ||
public List<EntityPlayerMP> playerEntities; | ||
|
||
@Inject(method = "func_28171_a", at = @At("HEAD"), cancellable = true) | ||
public void sendEncryptedChatToPlayersAroundPoint(EntityPlayer entityplayer, double d, double d1, double d2, double d3, int i, Packet packet, CallbackInfo ci) { | ||
if (packet instanceof Packet3Chat) { | ||
for (EntityPlayerMP playerEntity : this.playerEntities) { | ||
double d6; | ||
double d5; | ||
double d4; | ||
if (playerEntity == entityplayer || playerEntity.dimension != i || !((d4 = d - playerEntity.x) * d4 + (d5 = d1 - playerEntity.y) * d5 + (d6 = d2 - playerEntity.z) * d6 < d3 * d3)) | ||
continue; | ||
playerEntity.playerNetServerHandler.sendPacket(new Packet3Chat(((Packet3Chat) packet).message, AES.keyChain.get(playerEntity.username))); | ||
} | ||
ci.cancel(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/rootenginear/proximitychat/store/PlayerChannelData.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 rootenginear.proximitychat.store; | ||
|
||
import rootenginear.proximitychat.ProximityChat; | ||
import rootenginear.proximitychat.struct.PlayerChannelConfig; | ||
|
||
import java.util.HashMap; | ||
|
||
public class PlayerChannelData { | ||
public static HashMap<String, PlayerChannelConfig> playerProxData = new HashMap<>(); | ||
|
||
public static PlayerChannelConfig getPlayerChannelData(String playerName) { | ||
if (playerProxData.containsKey(playerName)) return playerProxData.get(playerName); | ||
|
||
PlayerChannelConfig t = new PlayerChannelConfig(true, ProximityChat.RADIUS); | ||
playerProxData.put(playerName, t); | ||
return t; | ||
} | ||
|
||
public static void setPlayerChannelData(String playerName, String mode) { | ||
if (!mode.equals("global") && !mode.equals("proximity") && !mode.equals("prox")) return; | ||
|
||
if (!playerProxData.containsKey(playerName)) { | ||
playerProxData.put(playerName, new PlayerChannelConfig(mode.equals("global"), ProximityChat.RADIUS)); | ||
return; | ||
} | ||
|
||
PlayerChannelConfig t = playerProxData.get(playerName); | ||
t.isGlobal = mode.equals("global"); | ||
playerProxData.replace(playerName, t); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/rootenginear/proximitychat/struct/PlayerChannelConfig.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,11 @@ | ||
package rootenginear.proximitychat.struct; | ||
|
||
public class PlayerChannelConfig { | ||
public boolean isGlobal; | ||
public int radius; | ||
|
||
public PlayerChannelConfig(boolean isGlobal, int radius) { | ||
this.isGlobal = isGlobal; | ||
this.radius = radius; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "rootenginear.proximitychat.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"server": [ | ||
"CommandsMixin", | ||
"NetServerHandlerMixin", | ||
"ServerConfigurationManagerMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |