1
1
package de .liebki .events ;
2
2
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
6
+ import org .bukkit .entity .Player ;
3
7
import org .bukkit .event .EventHandler ;
4
8
import org .bukkit .event .Listener ;
5
9
import org .bukkit .event .player .PlayerCommandPreprocessEvent ;
@@ -19,19 +23,55 @@ public EventManager(Start plugin, PushManager pushManager) {
19
23
this .pushManager = pushManager ;
20
24
}
21
25
22
- @ EventHandler
23
- public void onPlayerCommand (PlayerCommandPreprocessEvent e ) {
24
- boolean IsActive = (boolean ) plugin .config .get ("messages.player.command.op.status" );
26
+ private static final Map <String , String > commandMap = new HashMap <>();
25
27
26
- if (IsActive && e .getPlayer ().isOp () && e .getMessage ().startsWith ("/op" )) {
27
- String configMessage = (String ) plugin .config .get ("messages.player.command.op.content" );
28
- configMessage = configMessage .replace ("%PLAYER%" , e .getPlayer ().getName ()).replace ("%TARGET%" ,
29
- e .getMessage ().replace ("/op " , "" ));
30
-
31
- pushManager .SendMessage (configMessage );
28
+ static {
29
+ commandMap .put ("/op" , "messages.player.command.op" );
30
+ commandMap .put ("/deop" , "messages.player.command.deop" );
31
+ commandMap .put ("/ban" , "messages.player.command.ban" );
32
+ commandMap .put ("/ban-ip" , "messages.player.command.banip" );
33
+ commandMap .put ("/pardon" , "messages.player.command.pardon" );
34
+ commandMap .put ("/pardon-ip" , "messages.player.command.pardonip" );
35
+ commandMap .put ("/whitelist" , "messages.player.command.whitelist" );
36
+ }
32
37
38
+ @ EventHandler
39
+ public void onPlayerCommand (PlayerCommandPreprocessEvent e ) {
40
+ String commandText = e .getMessage ();
41
+ Player player = e .getPlayer ();
42
+
43
+ if (player .isOp ()) {
44
+ String playerName = player .getName ();
45
+ String messageToPushSend = "" ;
46
+
47
+ for (Map .Entry <String , String > entry : commandMap .entrySet ()) {
48
+ if (commandText .startsWith (entry .getKey ())) {
49
+ boolean isActive = (boolean ) plugin .config .get (entry .getValue () + ".status" );
50
+
51
+ if (isActive ) {
52
+ if (entry .getKey ().equals ("/whitelist" )) {
53
+ messageToPushSend = (String ) plugin .config .get (entry .getValue () + ".content" );
54
+ messageToPushSend = messageToPushSend .replace ("%CONTENT%" , commandText ).replace ("%PLAYER%" ,
55
+ playerName );
56
+ } else {
57
+ String [] parts = commandText .split (" " );
58
+ if (parts .length > 1 ) {
59
+ String targetPlayer = parts [1 ];
60
+ messageToPushSend = (String ) plugin .config .get (entry .getValue () + ".content" );
61
+
62
+ messageToPushSend = messageToPushSend .replace ("%PLAYER%" , playerName )
63
+ .replace ("%TARGET%" , targetPlayer );
64
+ }
65
+ }
66
+ }
67
+ break ;
68
+ }
69
+ }
70
+
71
+ if (!messageToPushSend .isEmpty ()) {
72
+ pushManager .SendMessage (messageToPushSend );
73
+ }
33
74
}
34
-
35
75
}
36
76
37
77
@ EventHandler
0 commit comments