Skip to content

Commit c5ac72a

Browse files
authored
Add files via upload
Simplified the project based on how it worked in the past. remapped (jar) and updated bukkit methods. This fork is free of console spam on modern versions of Bukkit, Spigot and Paper!
1 parent 27e536c commit c5ac72a

File tree

9 files changed

+806
-0
lines changed

9 files changed

+806
-0
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1.0.0:
2+
Initial release on Spigot (2021)

META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Created-By: 8u292-b10 (AdoptOpenJDK)

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
**PLEASE NOTE: This fork is still a work in progress, though the errors present in minecraft versions above 1.13 and above have now been fixed.**
2+
3+
UltraCommand allows a server administrator to define custom commands that can send the executing player messages, run commands as the player or as the console, and more!
4+
5+
# Usage
6+
7+
Add a command named `<name>`:
8+
9+
/uc add <name>
10+
11+
Add an element with content `<value>` to the command `<name>`:
12+
13+
/uc add <element> <name> <value
14+
15+
where `<element>` is one of:
16+
17+
* `text` - Text that will be sent to the player. Colour codes using '&' can be used.
18+
* `chat` - Chat messages that will be force-sent by the player. Colour codes using `&` can be used.
19+
* `pcmd` - Commands that will be run as the player. The leading slash is optional.
20+
* `ccmd` - Commands that will be run as the console. The leading slash is optional.
21+
22+
If the command named `<name>` does not exist when this command is run, it is automatically created. This makes it optional to create it with `/uc add <name>` beforehand.
23+
24+
The element value can contain substitutions (placeholders for data that is specific to a certain time and context a command is run in). A list of substitions is available further down the page.
25+
26+
# Examples
27+
28+
Define `/ranks` to display a list of server ranks to the player:
29+
30+
[/uc add ranks]
31+
/uc add text ranks &eOur server's ranks:
32+
/uc add text ranks &e- &aBuilder
33+
/uc add text ranks &e- &aForeman
34+
/uc add text ranks &e- &aArchitect
35+
/uc add text ranks &e- &aPlanner
36+
/uc add text ranks &e- &cAdmin
37+
/uc add text ranks &e- &bCEO
38+
39+
Define `/welcome <player>` to show a welcome message to a new player in a chat message:
40+
41+
[/uc add welcome]
42+
/uc add chat welcome Welcome to the server, $1!
43+
44+
The `$1` substitution is used to refer to the actual content of `<player>` part of the command above.
45+
46+
Define `/nightvision` to give the player the Night Vision effect for an hour.
47+
48+
[/uc add nightvision]
49+
/uc add ccmd nightvision /effect $p 16 3600 10
50+
51+
The `$p` substitution is used to refer to the player's username.
52+
53+
# Substitutions
54+
55+
* `$p` - The username of the player running the custom command.
56+
* `$d` - The display name of the player running the custom command.
57+
* `$a` - All arguments given to the custom command, separated with spaces (e.g. for passing to another command).
58+
* `$1`, `$2`, `$3` etc. - The arguments given to the custom command.
59+
* `$2+`, `$3+` etc. - Like `$a`, but beginning with the second, third etc. argument.
60+
61+
# Commands
62+
63+
`/ultracommand` can be used as an alias to `/uc`.
64+
65+
* `/uc add <name>` - Add a command named `<name>`.
66+
* `/uc add text <name> <text>` - Add text `<text>` to command `<name>`.
67+
* `/uc add chat <name> <chat>` - Add chat message `<chat>` to command `<name>`.
68+
* `/uc add pcmd <name> <command>` - Add player command `<text>` to command `<name>`.
69+
* `/uc add ccmd <name> <command>` - Add console command `<text>` to command `<name>`.
70+
* `/uc list [name]` - List all commands, or the elements of command `<name>`.
71+
* `/uc reload` - Reload the configuration from disk.
72+
* `/uc remove <name>` - Remove command `<name>`.
73+
* `/uc remove text <name>` - Remove all text from command `<name>`.
74+
* `/uc remove chat <name>` - Remove all chat messages from command `<name>`.
75+
* `/uc remove pcmd <name>` - Remove all player commands from command `<name>`.
76+
* `/uc remove ccmd <name>` - Remove all console commands from command `<name>`.
77+
* `/uc save` - Save configuration modified in-game to disk (this is done once per minute automatically).
78+
79+
# Permissions
80+
81+
* `ultracommand.configure` - Gives access to use `/uc` and `/ultracommand`.
82+
* `ultracommand.commands.*` - Gives access to use all custom commands defined with this plugin.
83+
* `ultracommand.commands.<name>` - Gives access to use the command named `<name>` defined with this plugin.
84+
85+
# Development Builds
86+
87+
Development builds can be found in the release section of this page.
88+
89+
**Use these at your own risk. They are not guaranteed to have been fully tested.**
90+
91+
[build-server]: #

plugin.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: UltraCommand
2+
version: 1.0.0
3+
authors: [rmellis, Kier Davis]
4+
main: com.kierdavis.ultracommand.UltraCommand
5+
6+
commands:
7+
uc:
8+
description: UltraCommand alias
9+
ultracommand:
10+
description: UltraCommand main command
11+
12+
permissions:
13+
ultracommand.configure:
14+
description: Gives access to the /uc and /ultracommand commands.
15+
default: op
16+
17+
ultracommand.commands.*:
18+
description: Gives access to all custom commands defined with this plugin.
19+
default: op
20+
21+
ultracommand.commands.<name>:
22+
description: Gives access to the custom command named <name>.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package com.kierdavis.ultracommand;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.regex.Matcher;
6+
import java.util.regex.Pattern;
7+
import org.bukkit.ChatColor;
8+
import org.bukkit.Server;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.command.ConsoleCommandSender;
11+
import org.bukkit.entity.Player;
12+
13+
public class CustomCommand {
14+
private static Pattern ARG_PATTERN = Pattern.compile("\\$(\\d+)");
15+
16+
private List<String> text = null;
17+
18+
private List<String> chat = null;
19+
20+
private List<String> playerCommands = null;
21+
22+
private List<String> consoleCommands = null;
23+
24+
public void setText(List<String> paramList) {
25+
this.text = paramList;
26+
}
27+
28+
public void setChat(List<String> paramList) {
29+
this.chat = paramList;
30+
}
31+
32+
public void setPlayerCommands(List<String> paramList) {
33+
this.playerCommands = paramList;
34+
}
35+
36+
public void setConsoleCommands(List<String> paramList) {
37+
this.consoleCommands = paramList;
38+
}
39+
40+
public void addText(String paramString) {
41+
if (this.text == null)
42+
this.text = new ArrayList<>();
43+
this.text.add(paramString);
44+
}
45+
46+
public void addChat(String paramString) {
47+
if (this.chat == null)
48+
this.chat = new ArrayList<>();
49+
this.chat.add(paramString);
50+
}
51+
52+
public void addPlayerCommand(String paramString) {
53+
if (this.playerCommands == null)
54+
this.playerCommands = new ArrayList<>();
55+
this.playerCommands.add(paramString);
56+
}
57+
58+
public void addConsoleCommand(String paramString) {
59+
if (this.consoleCommands == null)
60+
this.consoleCommands = new ArrayList<>();
61+
this.consoleCommands.add(paramString);
62+
}
63+
64+
public void execute(Player paramPlayer, String[] paramArrayOfString) {
65+
if (!checkArgs(paramPlayer, this.text, paramArrayOfString.length))
66+
return;
67+
if (!checkArgs(paramPlayer, this.chat, paramArrayOfString.length))
68+
return;
69+
if (!checkArgs(paramPlayer, this.playerCommands, paramArrayOfString.length))
70+
return;
71+
if (!checkArgs(paramPlayer, this.consoleCommands, paramArrayOfString.length))
72+
return;
73+
execText(paramPlayer, paramArrayOfString);
74+
execChat(paramPlayer, paramArrayOfString);
75+
execPlayerCommands(paramPlayer, paramArrayOfString);
76+
execConsoleCommands(paramPlayer, paramArrayOfString);
77+
}
78+
79+
private void execText(Player paramPlayer, String[] paramArrayOfString) {
80+
if (this.text == null)
81+
return;
82+
for (byte b = 0; b < this.text.size(); b++) {
83+
String str = this.text.get(b);
84+
str = doSubs(str, paramPlayer, paramArrayOfString);
85+
str = ChatColor.translateAlternateColorCodes('&', str);
86+
paramPlayer.sendMessage(str);
87+
}
88+
}
89+
90+
private void execChat(Player paramPlayer, String[] paramArrayOfString) {
91+
if (this.chat == null)
92+
return;
93+
for (byte b = 0; b < this.chat.size(); b++) {
94+
String str = this.chat.get(b);
95+
str = doSubs(str, paramPlayer, paramArrayOfString);
96+
str = ChatColor.translateAlternateColorCodes('&', str);
97+
paramPlayer.chat(str);
98+
}
99+
}
100+
101+
private void execPlayerCommands(Player paramPlayer, String[] paramArrayOfString) {
102+
if (this.playerCommands == null)
103+
return;
104+
Server server = paramPlayer.getServer();
105+
for (byte b = 0; b < this.playerCommands.size(); b++) {
106+
String str = this.playerCommands.get(b);
107+
str = doSubs(str, paramPlayer, paramArrayOfString);
108+
if (str.startsWith("/"))
109+
str = str.substring(1);
110+
server.dispatchCommand((CommandSender)paramPlayer, str);
111+
}
112+
}
113+
114+
private void execConsoleCommands(Player paramPlayer, String[] paramArrayOfString) {
115+
if (this.consoleCommands == null)
116+
return;
117+
Server server = paramPlayer.getServer();
118+
ConsoleCommandSender consoleCommandSender = server.getConsoleSender();
119+
for (byte b = 0; b < this.consoleCommands.size(); b++) {
120+
String str = this.consoleCommands.get(b);
121+
str = doSubs(str, paramPlayer, paramArrayOfString);
122+
if (str.startsWith("/"))
123+
str = str.substring(1);
124+
server.dispatchCommand((CommandSender)consoleCommandSender, str);
125+
}
126+
}
127+
128+
private static String doSubs(String paramString, Player paramPlayer, String[] paramArrayOfString) {
129+
StringBuilder stringBuilder = new StringBuilder();
130+
for (byte b = 0; b < paramArrayOfString.length; b++) {
131+
paramString = paramString.replaceAll("\\$" + Integer.toString(b + 1), Matcher.quoteReplacement(paramArrayOfString[b]));
132+
if (b > 0)
133+
stringBuilder.append(" ");
134+
stringBuilder.append(paramArrayOfString[b]);
135+
}
136+
paramString = paramString.replaceAll("\\$p", Matcher.quoteReplacement(paramPlayer.getName()));
137+
paramString = paramString.replaceAll("\\$d", Matcher.quoteReplacement(paramPlayer.getDisplayName()));
138+
paramString = paramString.replaceAll("\\$a", Matcher.quoteReplacement(stringBuilder.toString()));
139+
return paramString;
140+
}
141+
142+
private boolean checkArgs(Player paramPlayer, List<String> paramList, int paramInt) {
143+
return true;
144+
}
145+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.kierdavis.ultracommand;
2+
3+
import org.bukkit.event.EventHandler;
4+
import org.bukkit.event.Listener;
5+
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
6+
7+
public class PlayerListener implements Listener {
8+
private UltraCommand plugin;
9+
10+
public PlayerListener(UltraCommand paramUltraCommand) {
11+
this.plugin = paramUltraCommand;
12+
}
13+
14+
@EventHandler
15+
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent paramPlayerCommandPreprocessEvent) {
16+
if (paramPlayerCommandPreprocessEvent.isCancelled())
17+
return;
18+
String[] arrayOfString = paramPlayerCommandPreprocessEvent.getMessage().split(" ");
19+
if (arrayOfString[0].startsWith("/"))
20+
arrayOfString[0] = arrayOfString[0].substring(1);
21+
if (arrayOfString[0].length() == 0)
22+
return;
23+
boolean bool = this.plugin.doCommand(paramPlayerCommandPreprocessEvent.getPlayer(), arrayOfString);
24+
paramPlayerCommandPreprocessEvent.setCancelled(bool);
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.kierdavis.ultracommand;
2+
3+
import org.bukkit.scheduler.BukkitRunnable;
4+
5+
public class SaveCommandsTask extends BukkitRunnable {
6+
private UltraCommand plugin;
7+
8+
public SaveCommandsTask(UltraCommand paramUltraCommand) {
9+
this.plugin = paramUltraCommand;
10+
}
11+
12+
public void run() {
13+
if (this.plugin.isDirty())
14+
this.plugin.saveCustomCommands();
15+
}
16+
}

0 commit comments

Comments
 (0)