Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
7c54df0
add dimension to getPlayer
thisryan Dec 21, 2025
f11a134
add positional arguments to ArgumentParser
thisryan Dec 21, 2025
e88ef33
update getPlayer with new positional arguments
thisryan Dec 21, 2025
68d10bf
improve the retrival of results
thisryan Dec 21, 2025
5d821da
refactor command to StringCommand
thisryan Dec 21, 2025
5b64c31
refactor Add Inventory to new ArgumentParser
thisryan Dec 21, 2025
a9102cc
refactor batching to new ArgumentParser
thisryan Dec 21, 2025
ac6a09c
refactor ChatCommand to new Argument Parser
thisryan Dec 21, 2025
1cbd3d4
refactor DeleteBossBar to new ArgumentParser
thisryan Dec 21, 2025
39f59af
refactor EditBossBar to new ArgumentParser
thisryan Dec 21, 2025
4ac99c0
refactor EditEntty to new ArgumentParser
thisryan Dec 21, 2025
0d37bd6
refactor GetBlock to new ArgumentParser
thisryan Dec 21, 2025
85ab2df
refactor GetEntity to new ArgumentParser
thisryan Dec 21, 2025
a03db39
refactor GetInventory to new ArgumentParser
thisryan Dec 21, 2025
c489b1a
refactor GetPlayer to new ArgumentPArser
thisryan Dec 21, 2025
fe05844
refactor PollChat to new ArgumentParser
thisryan Dec 21, 2025
3520e83
refactor PostChat to new ArgumentParser
thisryan Dec 21, 2025
e77894c
refactor SetBlock to new ArgumentPArser
thisryan Dec 21, 2025
6cf4126
refactor SetPlayerPos to new ArgumentParser
thisryan Dec 21, 2025
523d7d6
refactor setPlayerStat to new ArgumentParser
thisryan Dec 21, 2025
c6da52e
refactor SetPlayerVelocity to new ArgumentParse
thisryan Dec 21, 2025
3d21677
refactor ShowTitle to new ArgumentParser
thisryan Dec 21, 2025
5ea268f
refactor SpawnBossBar to new ArgumentParser
thisryan Dec 21, 2025
fc5ea43
refactor SpawnEntitiy to new ArgumentParser
thisryan Dec 21, 2025
4435751
add batching warning
thisryan Dec 21, 2025
8d5b057
cleanup
thisryan Dec 21, 2025
8f03ee6
add dimension to getPlayer
thisryan Dec 21, 2025
ac711be
remove name conversion
thisryan Dec 21, 2025
03aa5af
update getPlayer command in Readme
thisryan Dec 21, 2025
743a466
update return of getPlayer
thisryan Dec 21, 2025
d5e7a1e
add dimensions to Readme
thisryan Dec 21, 2025
bc27bac
Merge branch 'feature_dimensions' of github.com:stjume/minecraft-pyth…
thisryan Dec 21, 2025
49eb099
add dimension to SetPlayerPos
thisryan Dec 21, 2025
b818306
fix setPlayerPos
thisryan Dec 21, 2025
e233ded
add dimension to setBlock
thisryan Dec 21, 2025
515f9c2
update readme
thisryan Dec 21, 2025
2cd98ea
add dimension to GetBlock
thisryan Dec 21, 2025
04ef0c2
add dimensions to spawnEntity
thisryan Dec 21, 2025
700bcfb
cleanup
thisryan Dec 21, 2025
c3a7a72
Merge pull request #6 from stjume/argument_rework
thisryan Dec 21, 2025
3b9d8eb
add dimension to SetPlayerPos
thisryan Dec 21, 2025
1af5a58
fix setPlayerPos
thisryan Dec 21, 2025
227d9d3
add dimension to setBlock
thisryan Dec 21, 2025
6dcee7d
update readme
thisryan Dec 21, 2025
c17b17b
add dimension to GetBlock
thisryan Dec 21, 2025
f0834eb
add dimensions to spawnEntity
thisryan Dec 21, 2025
83b9172
cleanup
thisryan Dec 21, 2025
77d0c84
Merge branch 'feature_dimensions' of github.com:stjume/minecraft-pyth…
thisryan Dec 21, 2025
0829834
add timestamp and index to message return on pollChat
thisryan Dec 21, 2025
ab980b9
fix bug in postChat
thisryan Dec 21, 2025
c1f43b2
add dimension to getEntity
thisryan Dec 21, 2025
2141c66
add dimension to editEntity
thisryan Dec 21, 2025
f5d27f3
fix small bug
thisryan Dec 21, 2025
8f4bea9
Merge pull request #10 from stjume/feature_message_improvement
thisryan Dec 21, 2025
3639927
how to create server
nonchris Dec 21, 2025
53a2e18
Fix parsing bug
thisryan Dec 21, 2025
a03535a
Merge branch 'main' of github.com:stjume/minecraft-python-backend
thisryan Dec 21, 2025
9c5f65a
fix bug
thisryan Dec 21, 2025
7705331
Merge pull request #11 from stjume/readme
thisryan Dec 21, 2025
69264bb
add dimension to getPlayer
thisryan Dec 21, 2025
2d87b30
remove name conversion
thisryan Dec 21, 2025
6504b36
update getPlayer command in Readme
thisryan Dec 21, 2025
f764fe8
update return of getPlayer
thisryan Dec 21, 2025
02217bb
add dimensions to Readme
thisryan Dec 21, 2025
1feec94
add dimension to SetPlayerPos
thisryan Dec 21, 2025
280cc45
fix setPlayerPos
thisryan Dec 21, 2025
c39a8e1
add dimension to setBlock
thisryan Dec 21, 2025
1717eae
update readme
thisryan Dec 21, 2025
21c0aab
add dimension to GetBlock
thisryan Dec 21, 2025
d45f457
add dimensions to spawnEntity
thisryan Dec 21, 2025
1c0cd0c
cleanup
thisryan Dec 21, 2025
1f9fd92
add dimension to getEntity
thisryan Dec 21, 2025
6c405b5
add dimension to editEntity
thisryan Dec 21, 2025
248c282
fix small bug
thisryan Dec 21, 2025
d5eee7f
Merge branch 'feature_dimensions' of github.com:stjume/minecraft-pyth…
thisryan Dec 21, 2025
fc7f1d8
fix bug
thisryan Dec 21, 2025
9717b9d
fix bug
thisryan Dec 21, 2025
3c15d1e
set ip to something more sensible
thisryan Dec 21, 2025
27eb08d
fix bug
thisryan Dec 21, 2025
f2abbbc
bug fix
thisryan Dec 21, 2025
9d98728
buggus fixus
thisryan Dec 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 49 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A simple minecraft plugin for sending commands to a server.

`The plugin was developed with spigot version 1.21.5`.
`The plugin was developed with spigot version 1.21.5` [download](https://getbukkit.org/download/spigot).

## Building

Expand All @@ -12,6 +12,22 @@ This project can be build using maven, just run the mvn command in the directory
mvn
```

### Creating the Server
Follow the [instructions](https://www.spigotmc.org/wiki/spigot-installation/#windows).
Basically.:
- Create an arbitrary folder
- Create a new file (`.txt` is the simplest)
- Put these three lines below in it (make sure to replace the version in the .jar's filename if needed.
- Rename the file to `start.bat` (accept window's warning, we want the file to be executable).
- Put the downloaded server-jar in the folder, next to the bat
- Create a new folder inside your current folder, name it `plugins`
- Put the plugin-jar, you built or downloaded in it

```@echo off
java -Xms#G -Xmx#G -XX:+UseG1GC -jar spigot-1.21.5.jar nogui
pause
```

## Usage

- This is a plugin intended to be used with a spigot server, just put the jar into the plugin folder.
Expand All @@ -28,10 +44,17 @@ mvn
- Throughout the commands there are references to indices of online players, it is important to note that currently the index is completly based on the order the players joined in and will change if the players disconnect and rejoin. Currently there is no way to identify the players unqiuely based on a id.
- You can of course still differantiate the players based on their names

#### Dimensions

- Currently the following dimensions are available
- `world`: the normal overworld
- `world_nether`: The Nether
- ` world_the_end`: The End

### Player

- `getPlayer <index:int>` gets information about a player. [Details](#command-getplayer)
- `setPlayerPos <playerindex:int> <x:int> <y:int> <z:int> ?rotation:int?` Set the player position [Details](#command-setplayerpos)
- `setPlayerPos <playerindex:int> <x:int> <y:int> <z:int> <dimension> ?rotation:int?` Set the player position [Details](#command-setplayerpos)
- `setPlayerStat <type:string> <playerIndex:int> <value:double>` Set a player stat [Details](#command-setplayerstat)
- `showTitle <playerIndex:int> <title:String> <subtitle:String> <fadeIn:int> <stay:int> <fadeOut:int>` Show a Title to players [Details](#command-showtitle)

Expand All @@ -42,8 +65,8 @@ mvn

## Block

- `setBlock <x:int> <y:int> <z:int> <blockid:String>` Set a block at a location [Deailts](#command-setblock)
- `getBlock <x:int> <y:int> <z:int>` gets information about a block [Details](#command-getblock)
- `setBlock <x:int> <y:int> <z:int> <dimension:String> <blockid:String>` Set a block at a location [Deailts](#command-setblock)
- `getBlock <x:int> <y:int> <z:int> <dimension:String>` gets information about a block [Details](#command-getblock)

## Chat

Expand All @@ -53,8 +76,8 @@ mvn

### Entity

- `spawnEntity <x:int> <y:int> <z:int> <entityid:String>` [Details](#command-spawnentity)
- `editEntity <target:String> ?name:String? ?position:x;y;z? ?ai:boolean?` [Details](#command-editentity)
- `spawnEntity <x:int> <y:int> <z:int> <dimension:String> <entityid:String>` [Details](#command-spawnentity)
- `editEntity <target:String> ?name:String? ?position:x;y;z;dimension? ?ai:boolean?` [Details](#command-editentity)
- `getEntity <target:String>` [Details](#command-getentity)

### Boss Bar
Expand Down Expand Up @@ -108,10 +131,10 @@ Flags are arguments that toggle an effect, the send command just needs to contai

#### Returns

- `<index:int> <name:String> <x:int> <y:int> <z:int> <rotation:int> <looking_at_block:String> <sneak:boolean> <max_health:double> <health:double> <food_level:double> <saturation: double> <xp_level:int> <xp_progress:double>`
- `<index:int> <name:String> <x:int> <y:int> <z:int> <dimension:String> <rotation:int> <looking_at_block:String> <sneak:boolean> <max_health:double> <health:double> <food_level:double> <saturation: double> <xp_level:int> <xp_progress:double>`
- `<index>` the index of the player
- `<name>` the name of the player
- `<x>, <y>, <z>` The tile position of the player
- `<x>, <y>, <z>` `<dimension>` The tile position of the player (see [dimensions](#dimensions))
- `<rotation>` The minecraft rotation of the player.
- `<looking_at_block>` The block type the player is looking at
- `<sneak>` depending of wether or not the player is sneaking `true` or `false`
Expand All @@ -131,7 +154,7 @@ Flags are arguments that toggle an effect, the send command just needs to contai

```bash
getPlayer 0
0 ThisRyan 39 83 72 17 STONE false
0 Player1 39 83 72 17 STONE false
```

### Command: setPlayerStat
Expand Down Expand Up @@ -233,21 +256,22 @@ getInv 0

### Command: setPlayerPos

- `setPlayerPos <playerindex:int> <x:int> <y:int> <z:int> ?rotation:int?`
- `setPlayerPos <playerindex:int> <x:int> <y:int> <z:int> <dimension:String> ?rotation:int?`

#### Args

- `playerIndex` the index of the online player
- `<x>, <y>, <z>` the new position of the player
- `<x:>, <y>, <z> <dimension>` the new position of the player (see [dimensions](#dimensions))
- `?rotation?` optionaly the direction the player should be looking in

### Command: setBlock

- `setBlock <x:int> <y:int> <z:int> <blockid:String>` Set a block at a location
- `setBlock <x:int> <y:int> <z:int> <dimension:String> <blockid:String>` Set a block at a location

#### Args

- `<x> <y> <z>` position of the block
- `<dimension>` see [dimensions](#dimensions)
- `<blockid>` the block id as a string i.e. "stone"

#### Example
Expand All @@ -259,11 +283,12 @@ setBlock 10 10 10 stone

### Command: getBlock

- `getBlock <x:int> <y:int> <z:int>` gets information about a block
- `getBlock <x:int> <y:int> <z:int> <dimension:String>` gets information about a block

#### Args

- `<x> <y> <z>:int int int` position of the block
- `<dimension>` see [dimensions](#dimensions)

#### Example

Expand Down Expand Up @@ -308,22 +333,23 @@ chatCommand say Hello from plugin!

#### Return

- A list of block of `<playername>:<message>` seperated by `𝇉`
- A list of blocks of `<playername>:|<year>|<month>|<day>|<hour>|<minute>|<second> :<playerIndex>:<message>` seperated by `𝇉`

#### Example

```bash
pollChat
Player1:Hallo𝇉Player1:A second message𝇉Player2:Last message
Player1:2025|12|21|17|49|27:0:This is a message:2025|12|21|17|49|29:1:Message 2
```

### Command: spawnEntity

- `spawnEntity <x:int> <y:int> <z:int> <entityid:String>` Spawns an entity
- `spawnEntity <x:int> <y:int> <z:int> <dimension:String> <entityid:String>` Spawns an entity

#### Args

- `<x> <y> <z>` position
- `<dimension>` see [dimensions](#dimensions)
- `<entityid>` a string with entity id full list can be cound here: [Entities](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html)

#### Returns
Expand All @@ -339,13 +365,13 @@ ff568527-7c0c-4536-aed2-ef77429d61b8

### Command: editEntity

- `editEntity <target:String> ?name:String? ?position:x;y;z? ?ai:boolean?` Edits a existing entity which was previously spawned by the `spawnEntity` command
- `editEntity <target:String> ?name:String? ?position:x;y;z;dimension? ?ai:boolean?` Edits a existing entity which was previously spawned by the `spawnEntity` command

#### Args

- `target` is the uuid returned by `spawnEntity`
- `name` if is set the entites custom name is changed
- `position`if is set the entities position will be set to the given x,y,z coordinates
- `position`if is set the entities position will be set to the given x,y,z coordinates as well as the [dimension](#dimensions) ,
- `ai` sets the ai of the entity, if its turned off the entity will not move.

#### Example
Expand All @@ -365,7 +391,9 @@ editEntity ff568527-7c0c-4536-aed2-ef77429d61b8 name:Zomb position:10;10;200 ai:

#### Returns

- `<target:String> <name:string> <x:int> <y:int> <z:int> <health:double>`
- `<target:String> <name:string> <x:int> <y:int> <z:int> <dimension:String> <health:double>`

- `<dimensions>` see [dimensions](#dimensions)

#### Example

Expand Down Expand Up @@ -426,6 +454,8 @@ deleteBossBar myuniquename

### Command: batch

!!This command is currently not supported!!

- `batch ;|;<command:String>;|;<command:String>` Runs all commands in a batch, the `;|;` acts as the seperator. Please make sure there are no spaces around the seperator except before the first one.

#### Args
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/sk/skMinecraft/CommandFactory.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.sk.skMinecraft;

import org.sk.skMinecraft.SkMinecraft.StringCommand;
import org.sk.skMinecraft.commands.*;

import java.util.HashMap;
import java.util.function.Function;

public class CommandFactory {

private final HashMap<String, Function<String, Command>> commands;
private final HashMap<String, Function<StringCommand, Command>> commands;

public CommandFactory() {
this.commands = new HashMap<>();
Expand All @@ -29,7 +30,7 @@ public CommandFactory() {
this.commands.put("addInv", AddInventory::new);
this.commands.put("getInv", GetInventory::new);

this.commands.put("batch", Batching::new);
// this.commands.put("batch", Batching::new);

this.commands.put("spawnBossBar", SpawnBossBar::new);
this.commands.put("editBossBar", EditBossBar::new);
Expand All @@ -39,14 +40,12 @@ public CommandFactory() {

this.commands.put("setPlayerPos", SetPlayerPos::new);

this.commands.put("validate", Validator::new);
// this.commands.put("validate", Validator::new);

this.commands.put("showTitle", ShowTitle::new);
}

public Command build(String command) {
int firstSpace = command.indexOf(SkMinecraft.seperator);
String commandName = firstSpace == -1 ? command : command.substring(0, firstSpace);
return this.commands.get(commandName).apply(command);
public Command build(StringCommand command) {
return this.commands.get(command.name()).apply(command);
}
}
31 changes: 27 additions & 4 deletions src/main/java/org/sk/skMinecraft/SkMinecraft.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.sk.skMinecraft;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
Expand All @@ -13,13 +15,16 @@
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.LocalDateTime;
import java.util.Arrays;

public final class SkMinecraft extends JavaPlugin implements Listener {

private Thread tcpListenerThread;
private ServerSocket serverSocket;

public static String seperator = "𝇉";
public record StringCommand(String name, String[] arguments) {};

public static String joinWithSeperator(Object... args) {
String result = "";
Expand All @@ -40,6 +45,23 @@ public static String joinWithSeperator(Object... args) {
return result;
}

public static StringCommand splitCommand(String command) {
String[] parts = command.split(SkMinecraft.seperator);
return new StringCommand(parts[0], Arrays.copyOfRange(parts, 1, parts.length));
}

public static int playerIndexFromName(String name) {
Player[] players = Bukkit.getOnlinePlayers().toArray(new Player[0]);

for(int i = 0;i < players.length;i++){
if(players[i].getName().equals(name)) {
return i;
}
}

return -1;
}

@Override
public void onEnable() {
CentralResourceHandler.init();
Expand All @@ -55,8 +77,8 @@ public void onDisable() {
private void startTcpListener() {
tcpListenerThread = new Thread(() -> {
try {
serverSocket = new ServerSocket(12345); // Use your desired port
getLogger().info("TCP server started on port 12345");
serverSocket = new ServerSocket(25595);
getLogger().info("TCP server started on port 25595");

while (!serverSocket.isClosed()) {
Socket client = serverSocket.accept();
Expand All @@ -76,7 +98,7 @@ private void startTcpListener() {

@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
ChatMessage message = new ChatMessage(event.getPlayer(), event.getMessage());
ChatMessage message = new ChatMessage(event.getPlayer(), event.getMessage(), LocalDateTime.now());
CentralResourceHandler.addChatMessage(message);
}

Expand Down Expand Up @@ -108,7 +130,8 @@ private void handleClient(Socket client) {

getLogger().info("Received: " + command);

Command commandObject = commandFactory.build(command);
StringCommand stringCommand = splitCommand(command);
Command commandObject = commandFactory.build(stringCommand);

if(commandObject == null) continue;

Expand Down
53 changes: 21 additions & 32 deletions src/main/java/org/sk/skMinecraft/commands/AddInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.sk.skMinecraft.SkMinecraft;
import org.sk.skMinecraft.SkMinecraft.StringCommand;
import org.sk.skMinecraft.commands.ArgumentParser.ParseResult;

import java.util.Arrays;
import java.util.HashMap;

public class AddInventory extends Command{

Expand All @@ -21,47 +20,37 @@ public class AddInventory extends Command{
private int slot;
private boolean unbreakable;

public AddInventory(String command) {
String[] parts = command.split(SkMinecraft.seperator);
public AddInventory(StringCommand command) {
ArgumentParser parser = new ArgumentParser();

if(parts.length < 4) {
this.valid = false;
return;
}
parser.addPositionalArguments(
ArgumentParser.IntParser,
ArgumentParser.StringParser,
ArgumentParser.IntParser
);

try {
this.playerIndex = Integer.parseInt(parts[1]);
this.amount = Integer.parseInt(parts[3]);
} catch(NumberFormatException e){
this.valid = false;
return;
}
parser.addOptionalArgument("name", ArgumentParser.StringParser, "");
parser.addOptionalArgument("slot", Integer::parseInt, -1);

if(playerIndex < 0 || playerIndex >= Bukkit.getOnlinePlayers().toArray(new Player[0]).length) {
this.valid = false;
return;
}
parser.addFlag("unbreakable");

String blockId = parts[2].toUpperCase();
this.material = Material.matchMaterial(blockId);
ParseResult result = parser.parse(command.arguments());

if(this.material == null) {
if(!this.isValid()) {
this.valid = false;
return;
}

ArgumentParser parser = new ArgumentParser();

parser.addArgument("name", ArgumentParser.StringParser, "");
parser.addArgument("slot", Integer::parseInt, -1);
this.playerIndex = result.getPositional(0);

parser.addFlag("unbreakable");
String blockId = result.getPositional(1);
this.material = Material.matchMaterial(blockId.toUpperCase());

HashMap<String,ArgumentParser.ArgumentResult> result = parser.parse(Arrays.copyOfRange(parts,4, parts.length));
this.amount = result.getPositional(2);

this.name = result.get("name").asString();
this.slot = result.get("slot").asInt();
this.unbreakable = result.get("unbreakable").asBool();
this.name = result.getOptional("name");
this.slot = result.getOptional("slot");
this.unbreakable = result.getOptional("unbreakable");
}

@Override
Expand Down
Loading