22
33import org .bukkit .Bukkit ;
44import org .bukkit .ChatColor ;
5+ import org .bukkit .entity .Player ;
56import org .bukkit .event .EventHandler ;
67import org .bukkit .event .Listener ;
78import org .bukkit .event .player .PlayerCommandPreprocessEvent ;
@@ -27,25 +28,60 @@ public void onCommandRun(PlayerCommandPreprocessEvent event) {
2728 // Has player as argument
2829 if (Bukkit .getPlayer (command .split (" " )[1 ]) != null ) {
2930 // Valid player (and online)
30- String acceptText = getConfig ().getString ("message.accept" );
31- String denyText = getConfig ().getString ("message.deny" );
32- boolean useDisplayName = getConfig ().getBoolean ("message.use-display-name" );
33- String [] firstLine = getConfig ().getString ("message.line-1" ).split (" " );
34- JSONMessage message ;
35- for (int i = 0 ; i < firstLine .length ; i ++) {
36- if (i == 0 ) {
37- message = JSONMessage .create ();
38- if (firstLine [i ].contains ("&" )) {
39- int index = firstLine [i ].indexOf ("&" );
40- ChatColor colour = ChatColor .getByChar (firstLine [i ].substring (index , index + 1 ));
41- // Add text to JSONMessage instance
42- }
43- }
44- }
31+ sendMessages (Bukkit .getPlayer (command .split (" " )[1 ]));
4532 }
4633 }
4734 }
4835 }
4936 }
37+
38+ private JSONMessage getFirstLine (Player player ) {
39+ boolean useDisplayName = getConfig ().getBoolean ("message.use-display-name" );
40+ JSONMessage message = JSONMessage .create ();
41+ if (getConfig ().getString ("message.line-1" ) != "" ) {
42+ String [] words = getConfig ().getString ("message.line-1" ).split (" " );
43+ for (int i = 0 ; i < words .length ; i ++) {
44+ String word = trans (words [i ].replace ("%player%" , useDisplayName ? player .getDisplayName () : player .getName ()));
45+ if (word .equalsIgnoreCase ("%accept%" )) {
46+ message .then (word ).runCommand ("tpaccept" );
47+ } else if (word .equalsIgnoreCase ("%deny%" )) {
48+ message .then (word ).runCommand ("tpdeny" );
49+ } else {
50+ message .then (word );
51+ }
52+ message .then (" " );
53+ }
54+ }
55+ return message ;
56+ }
57+
58+ private JSONMessage getSecondLine (Player player ) {
59+ boolean useDisplayName = getConfig ().getBoolean ("message.use-display-name" );
60+ JSONMessage message = JSONMessage .create ();
61+ if (getConfig ().getString ("message.line-2" ) != "" ) {
62+ String [] words = getConfig ().getString ("message.line-2" ).split (" " );
63+ for (int i = 0 ; i < words .length ; i ++) {
64+ String word = trans (words [i ].replace ("%player%" , useDisplayName ? player .getDisplayName () : player .getName ()));
65+ if (word .equalsIgnoreCase ("%accept%" )) {
66+ message .then (word ).runCommand ("tpaccept" );
67+ } else if (word .equalsIgnoreCase ("%deny%" )) {
68+ message .then (word ).runCommand ("tpdeny" );
69+ } else {
70+ message .then (word );
71+ }
72+ message .then (" " );
73+ }
74+ }
75+ return message ;
76+ }
77+
78+ private void sendMessages (Player player ) {
79+ getFirstLine (player ).send (player );
80+ getSecondLine (player ).send (player );
81+ }
82+
83+ private String trans (String string ) {
84+ return ChatColor .translateAlternateColorCodes ('&' , string );
85+ }
5086
5187}
0 commit comments