mirror of
https://github.com/sigmasternchen/minecraft-matrix-bridge
synced 2025-03-15 07:58:56 +00:00
feat: Add matrix.admin
to allow admin commands via matrix
This commit is contained in:
parent
254c09cb4f
commit
ada29abea7
3 changed files with 31 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
matrix.id=@username:domain.com
|
matrix.id=@username:domain.com
|
||||||
matrix.password=
|
matrix.password=
|
||||||
# matrix.room=!roomID:domain.com
|
# matrix.room=!roomID:domain.com
|
||||||
|
matrix.admin=
|
||||||
minecraft.server.name=Server
|
minecraft.server.name=Server
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class BridgePropertyReader {
|
||||||
private final String MATRIX_USERID_KEY = "matrix.id";
|
private final String MATRIX_USERID_KEY = "matrix.id";
|
||||||
private final String MATRIX_PASSWORD_KEY = "matrix.password";
|
private final String MATRIX_PASSWORD_KEY = "matrix.password";
|
||||||
private final String MATRIX_ROOMID_KEY = "matrix.room";
|
private final String MATRIX_ROOMID_KEY = "matrix.room";
|
||||||
|
private final String MATRIX_ADMINID_KEY = "matrix.admin";
|
||||||
|
|
||||||
private final String MINECRAFT_SERVER_NAME_KEY = "minecraft.server.name";
|
private final String MINECRAFT_SERVER_NAME_KEY = "minecraft.server.name";
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ public class BridgePropertyReader {
|
||||||
private void generateEmptyFile(File file) {
|
private void generateEmptyFile(File file) {
|
||||||
properties.setProperty(MATRIX_USERID_KEY, "");
|
properties.setProperty(MATRIX_USERID_KEY, "");
|
||||||
properties.setProperty(MATRIX_PASSWORD_KEY, "");
|
properties.setProperty(MATRIX_PASSWORD_KEY, "");
|
||||||
|
properties.setProperty(MATRIX_ADMINID_KEY, "");
|
||||||
properties.setProperty(MINECRAFT_SERVER_NAME_KEY, "Server");
|
properties.setProperty(MINECRAFT_SERVER_NAME_KEY, "Server");
|
||||||
try {
|
try {
|
||||||
properties.store(new FileOutputStream(file), "Matrix Bridge Properties");
|
properties.store(new FileOutputStream(file), "Matrix Bridge Properties");
|
||||||
|
@ -45,28 +47,27 @@ public class BridgePropertyReader {
|
||||||
|
|
||||||
public String getDomain() {
|
public String getDomain() {
|
||||||
String tmp = properties.getProperty(MATRIX_USERID_KEY);
|
String tmp = properties.getProperty(MATRIX_USERID_KEY);
|
||||||
|
|
||||||
return tmp.substring(tmp.indexOf(":") + 1);
|
return tmp.substring(tmp.indexOf(":") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
String tmp = properties.getProperty(MATRIX_USERID_KEY);
|
String tmp = properties.getProperty(MATRIX_USERID_KEY);
|
||||||
|
|
||||||
return tmp.substring(1, tmp.indexOf(":"));
|
return tmp.substring(1, tmp.indexOf(":"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMinecraftServerName() {
|
public String getMinecraftServerName() {
|
||||||
String tmp = properties.getProperty(MINECRAFT_SERVER_NAME_KEY);
|
return properties.getProperty(MINECRAFT_SERVER_NAME_KEY);
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
String tmp = properties.getProperty(MATRIX_PASSWORD_KEY);
|
return properties.getProperty(MATRIX_PASSWORD_KEY);
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoom() {
|
public String getRoom() {
|
||||||
String tmp = properties.getProperty(MATRIX_ROOMID_KEY);
|
return properties.getProperty(MATRIX_ROOMID_KEY);
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAdmin() {
|
||||||
|
return properties.getProperty(MATRIX_ADMINID_KEY);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,15 @@ import io.kamax.matrix.client.regular.SyncOptions;
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
import io.kamax.matrix.event._MatrixEvent;
|
||||||
import io.kamax.matrix.hs._MatrixRoom;
|
import io.kamax.matrix.hs._MatrixRoom;
|
||||||
import io.kamax.matrix.json.event.MatrixJsonRoomMessageEvent;
|
import io.kamax.matrix.json.event.MatrixJsonRoomMessageEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class BridgeService extends Thread implements Endpoint {
|
public class BridgeService extends Thread implements Endpoint {
|
||||||
Endpoint receiver;
|
MatrixPlugin receiver;
|
||||||
|
|
||||||
_MatrixClient client;
|
_MatrixClient client;
|
||||||
|
|
||||||
private BridgePropertyReader properties;
|
private BridgePropertyReader properties;
|
||||||
|
@ -35,7 +36,7 @@ public class BridgeService extends Thread implements Endpoint {
|
||||||
this.receiver.send("", players.toString());
|
this.receiver.send("", players.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BridgeService(Endpoint receiver, BridgePropertyReader properties) {
|
public BridgeService(MatrixPlugin receiver, BridgePropertyReader properties) {
|
||||||
|
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
|
|
||||||
|
@ -83,6 +84,23 @@ public class BridgeService extends Thread implements Endpoint {
|
||||||
if (msg.getBody() != null) {
|
if (msg.getBody() != null) {
|
||||||
if (msg.getBody().startsWith("!")) {
|
if (msg.getBody().startsWith("!")) {
|
||||||
this.parseCommand(msg.getBody());
|
this.parseCommand(msg.getBody());
|
||||||
|
} else if (syncToken != null
|
||||||
|
&& msg.getBody().startsWith("$")
|
||||||
|
&& msg.getSender().getId().equals(properties.getAdmin())) {
|
||||||
|
try {
|
||||||
|
Bukkit.getScheduler().runTask(this.receiver,
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Bukkit.getServer().dispatchCommand(
|
||||||
|
Bukkit.getServer().getConsoleSender(),
|
||||||
|
msg.getBody().substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.receiver.send(msg.getSender().getId(), msg.getBody());
|
this.receiver.send(msg.getSender().getId(), msg.getBody());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue