Skip to content

Commit

Permalink
Added more commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim committed Jun 9, 2024
1 parent f8a637a commit 1d6fe43
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.liebki</groupId>
<artifactId>simplepushevents</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.3</version>
<name>simplepushevents</name>


Expand Down
33 changes: 30 additions & 3 deletions src/main/java/de/liebki/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class Start extends JavaPlugin {
public void onEnable() {
config = new Config("plugins/simplepushevents", "options.yml", this);
if (!config.check("configexists")) {
String serverUuid = (UUID.randomUUID() + Bukkit.getServer().getIp()).trim();
System.out.println(serverUuid);

String uuid = CreateShortUuid();

config.set("donottouch.configexists", true);
config.set("donottouch.pushchannel", serverUuid);
config.set("donottouch.pushchannel", uuid);

config.set("messages.general.title", "Minecraft Server:");

Expand All @@ -34,6 +34,26 @@ public void onEnable() {
config.set("messages.player.command.op.status", true);
config.set("messages.player.command.op.content", "The player %PLAYER% executed /op for %TARGET% !");

config.set("messages.player.command.deop.status", true);
config.set("messages.player.command.deop.content", "The player %PLAYER% executed /deop for %TARGET% !");

config.set("messages.player.command.ban.status", true);
config.set("messages.player.command.ban.content", "The player %PLAYER% executed /ban for %TARGET% !");

config.set("messages.player.command.banip.status", true);
config.set("messages.player.command.banip.content", "The player %PLAYER% executed /ban-ip for %TARGET% !");

config.set("messages.player.command.pardon.status", true);
config.set("messages.player.command.pardon.content", "The player %PLAYER% executed /pardon for %TARGET% !");

config.set("messages.player.command.pardonip.status", true);
config.set("messages.player.command.pardonip.content",
"The player %PLAYER% executed /pardon-ip for %TARGET% !");

config.set("messages.player.command.whitelist.status", true);
config.set("messages.player.command.whitelist.content",
"The player %PLAYER% used a whitelist command: %CONTENT%");

config.set("messages.player.join.status", true);
config.set("messages.player.join.content", "The player %PLAYER% joined!");

Expand All @@ -57,6 +77,13 @@ public void onEnable() {

}

String CreateShortUuid() {
String base = (UUID.randomUUID() + Bukkit.getServer().getIp()).trim();
base = base.replace("-", "").substring(6, base.length() / 2);

return base;
}

@Override
public void onDisable() {
Bukkit.getConsoleSender().sendMessage("§4SimplePushEvents powering off");
Expand Down
60 changes: 50 additions & 10 deletions src/main/java/de/liebki/events/EventManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package de.liebki.events;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
Expand All @@ -19,19 +23,55 @@ public EventManager(Start plugin, PushManager pushManager) {
this.pushManager = pushManager;
}

@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
boolean IsActive = (boolean) plugin.config.get("messages.player.command.op.status");
private static final Map<String, String> commandMap = new HashMap<>();

if (IsActive && e.getPlayer().isOp() && e.getMessage().startsWith("/op")) {
String configMessage = (String) plugin.config.get("messages.player.command.op.content");
configMessage = configMessage.replace("%PLAYER%", e.getPlayer().getName()).replace("%TARGET%",
e.getMessage().replace("/op ", ""));

pushManager.SendMessage(configMessage);
static {
commandMap.put("/op", "messages.player.command.op");
commandMap.put("/deop", "messages.player.command.deop");
commandMap.put("/ban", "messages.player.command.ban");
commandMap.put("/ban-ip", "messages.player.command.banip");
commandMap.put("/pardon", "messages.player.command.pardon");
commandMap.put("/pardon-ip", "messages.player.command.pardonip");
commandMap.put("/whitelist", "messages.player.command.whitelist");
}

@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
String commandText = e.getMessage();
Player player = e.getPlayer();

if (player.isOp()) {
String playerName = player.getName();
String messageToPushSend = "";

for (Map.Entry<String, String> entry : commandMap.entrySet()) {
if (commandText.startsWith(entry.getKey())) {
boolean isActive = (boolean) plugin.config.get(entry.getValue() + ".status");

if (isActive) {
if (entry.getKey().equals("/whitelist")) {
messageToPushSend = (String) plugin.config.get(entry.getValue() + ".content");
messageToPushSend = messageToPushSend.replace("%CONTENT%", commandText).replace("%PLAYER%",
playerName);
} else {
String[] parts = commandText.split(" ");
if (parts.length > 1) {
String targetPlayer = parts[1];
messageToPushSend = (String) plugin.config.get(entry.getValue() + ".content");

messageToPushSend = messageToPushSend.replace("%PLAYER%", playerName)
.replace("%TARGET%", targetPlayer);
}
}
}
break;
}
}

if (!messageToPushSend.isEmpty()) {
pushManager.SendMessage(messageToPushSend);
}
}

}

@EventHandler
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: SimplePushEvents
main: de.liebki.Start
version: 0.0.1
version: 0.0.3
api-version: "1.16"
commands:

0 comments on commit 1d6fe43

Please sign in to comment.