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
4b1ae56
commit 36ae7a6
Showing
9 changed files
with
147 additions
and
55 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
64 changes: 64 additions & 0 deletions
64
src/main/java/rootenginear/proximitychat/command/RadiusCommand.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,64 @@ | ||
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.ProximityChat; | ||
import rootenginear.proximitychat.struct.PlayerChannelConfig; | ||
|
||
import static rootenginear.proximitychat.store.PlayerChannelData.getPlayerChannelData; | ||
import static rootenginear.proximitychat.store.PlayerChannelData.setPlayerRadius; | ||
|
||
public class RadiusCommand extends ServerCommand { | ||
public RadiusCommand(MinecraftServer server) { | ||
super(server, "radius", "rad"); | ||
} | ||
|
||
@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 colorfulName = sender.getName() + "§r"; | ||
String rawName = sender.getName().replaceFirst("§.", ""); | ||
|
||
if (args.length == 0) { | ||
PlayerChannelConfig cfg = getPlayerChannelData(rawName); | ||
sender.sendMessage(colorfulName + "'s proximity chat radius is: " + cfg.radius); | ||
return true; | ||
} | ||
|
||
int newRadius; | ||
try { | ||
newRadius = Integer.parseInt(args[0]); | ||
} catch (Exception e) { | ||
throw new CommandError("Not a number: \"" + args[0] + "\""); | ||
} | ||
|
||
if (newRadius > ProximityChat.MAX_RADIUS) { | ||
sender.sendMessage("Your radius (" + newRadius + ") exceeds the limit (" + ProximityChat.MAX_RADIUS + ")."); | ||
newRadius = ProximityChat.MAX_RADIUS; | ||
} | ||
|
||
setPlayerRadius(rawName, newRadius); | ||
sender.sendMessage("Changed " + colorfulName + "'s proximity chat radius to: " + newRadius); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean opRequired(String[] args) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { | ||
sender.sendMessage("/radius"); | ||
sender.sendMessage("/radius <number>"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "playground", | ||
"version": "${version}", | ||
"name": "Playground", | ||
"description": "This is the beginning of awesome mods!", | ||
"authors": [ | ||
"rootEnginear" | ||
], | ||
"schemaVersion": 1, | ||
"id": "proximitychat", | ||
"version": "${version}", | ||
"name": "Proximity Chat", | ||
"description": "Communicate with other players within a certain radius.", | ||
"authors": [ | ||
"rootEnginear" | ||
], | ||
"icon": "icon.png", | ||
"contact": { | ||
"homepage": "https://github.com/rootEnginear/bta-rootenginear-mods", | ||
"sources": "https://github.com/rootEnginear/bta-rootenginear-mods", | ||
"issues": "https://github.com/rootEnginear/bta-rootenginear-mods/issues" | ||
}, | ||
"license": "CC0-1.0", | ||
"environment": "*", | ||
"entrypoints": { | ||
"server": [ | ||
"contact": { | ||
"homepage": "https://github.com/rootEnginear/bta-rootenginear-mods/tree/proximity-chat", | ||
"sources": "https://github.com/rootEnginear/bta-rootenginear-mods/tree/proximity-chat", | ||
"issues": "https://github.com/rootEnginear/bta-rootenginear-mods/issues" | ||
}, | ||
"license": "CC0-1.0", | ||
"environment": "*", | ||
"entrypoints": { | ||
"server": [ | ||
"rootenginear.proximitychat.ProximityChat" | ||
] | ||
}, | ||
"mixins": [ | ||
"proximitychat.mixins.json" | ||
], | ||
"depends": { | ||
"fabricloader": ">=0.13.3" | ||
} | ||
] | ||
}, | ||
"mixins": [ | ||
"proximitychat.mixins.json" | ||
], | ||
"depends": { | ||
"fabricloader": ">=0.13.3" | ||
} | ||
} |