Skip to content

Commit

Permalink
Add /estools test and update version
Browse files Browse the repository at this point in the history
  • Loading branch information
CoPokBl committed May 2, 2024
1 parent 69e9c34 commit 922a18f
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 3 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ A general purpose Essentials like plugin with everything you need but not messin
EsTools is a plugin designed to be like EssentialsX in that it provides heaps of
helpful commands, but unlike essentials it doesn't mess up or override vanilla features (e.g. the give command).
This plugin doesn't override existing Minecraft commands and therefore is less likely to mess stuff up.
EsTools is also completely `/reload` safe.

Commands:
[View Them In Our Wiki](https://github.com/CoPokBl/EsTools/wiki/commands)

## Installing
Download the latest .jar from our [releases page](https://github.com/CoPokBl/EsTools/releases/). Place
the file in the plugins folder of your server and start it.
For optional Vault support install [Vault from SpigotMC](https://www.spigotmc.org/resources/vault.34315/).

## Support
The plugin is designed to work on every public spigot build. Any issues found on legacy versions
should be reported. Due to the size of the task, we can't test every new feature on every version.
Expand All @@ -34,4 +40,12 @@ Language features from Java 8 are used in the plugin.
## Contributing
We are open to contributions. If you want to contribute to the project, please fork the repository and make a pull request.

**DO NOT CONTRIBUTE CODE WITH JAVA 9+ FEATURES**
**DO NOT CONTRIBUTE CODE WITH JAVA 9+ FEATURES**

## Testing
We have a builtin testing system for commands. It isn't fully autonomous and will still require you to
verify that the commands were successful, although it will report any exceptions that occur in commands.

Start the test with `/estools test`. Read the chat output as it goes through and runs every command,
sometimes it may `/msg` you and ask you to do something. In general don't switch item slots
and only move for the commands `/fly`, `/flyspeed` and `/walkspeed`.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.serble.EsTools</groupId>
<artifactId>EsTools</artifactId>
<version>4.0</version>
<version>4.1.0</version>
<packaging>jar</packaging>

<name>EsTools</name>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/serble/estools/Commands/EsTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;

import net.serble.estools.Tester;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -57,6 +58,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

send(sender, "&cWarning, this will reset all configuration files, use /estools reset confirm to reset");
} else if (args[0].equalsIgnoreCase("test")) {
if (!(sender instanceof Player)) {
send(sender, "&cYou must be a player to use this command.");
return false;
}
Tester tester = new Tester((Player) sender);
tester.startTests();
} else if (args[0].equalsIgnoreCase("throw")) {
throw new RuntimeException("Test exception");
} else {
send(sender, "&aEsTools v" + Main.plugin.getDescription().getVersion());
}
Expand All @@ -72,6 +82,7 @@ public List<String> tabComplete(CommandSender sender, String[] args, String lArg
tab.add("reload");
tab.add("version");
tab.add("reset");
tab.add("test");
}

return tab;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/serble/estools/Commands/SafeTp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.bukkit.event.player.PlayerTeleportEvent;

public class SafeTp extends EsToolsCommand implements Listener {
private static boolean enabled = true;
public static boolean enabled = true;

@Override
public void onEnable() {
Expand Down
166 changes: 166 additions & 0 deletions src/main/java/net/serble/estools/Tester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package net.serble.estools;

import net.serble.estools.Commands.SafeTp;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.io.PrintWriter;
import java.io.StringWriter;

public class Tester {
private final Player player;
private int currentCommand = 0;

@SuppressWarnings("unchecked") // It doesn't allow specifying type
private static final Tuple<String, Double>[] routine = new Tuple[] {
new Tuple<>("gmsp", 1),
new Tuple<>("gmc", 1),
new Tuple<>("gma", 1),
new Tuple<>("gms", 1),
new Tuple<>("i apple", 1),
new Tuple<>("h dirt", 1),
new Tuple<>("fly", 3),
new Tuple<>("flyspeed 10", 2),
new Tuple<>("flyspeed 2", 0.1),
new Tuple<>("fly", 0.1),
new Tuple<>("walkspeed 10", 2),
new Tuple<>("walkspeed 2", 0.1),
new Tuple<>("pa", 0.1),
new Tuple<>("ph", 0.1),
new Tuple<>("pp", 0.1),
new Tuple<>("psh", 0.1),
new Tuple<>("ps", 3),
new Tuple<>("tphere {randomplayer}", 1),
new Tuple<>("tpall", 1),
new Tuple<>("warps add test", 0.5),
new Tuple<>("safetp", 1),
new Tuple<>("tp ~50 ~5000 ~50", 2),
new Tuple<>("warp test", 2),
new Tuple<>("warps remove test", 0.1),
new Tuple<>("tp ~50 ~5000 ~50", 1),
new Tuple<>("back", 1),
new Tuple<>("cchest", 5),
new Tuple<>("ci", 1),
new Tuple<>("h sign", 0.1),
new Tuple<>("msg {player} Place and look at the sign (leave it empty)", 3),
new Tuple<>("editsign 1 Hello World!", 1),
new Tuple<>("editsign glow", 1),
new Tuple<>("editsign unglow", 1),
new Tuple<>("editsign 2 Does it work?", 1),
new Tuple<>("eff speed 1 60 {player}", 2),
new Tuple<>("h iron_sword", 0.1),
new Tuple<>("ench knockback 10", 2),
new Tuple<>("estools", 1),
new Tuple<>("sethunger 1", 1),
new Tuple<>("feed", 1),
new Tuple<>("setsaturation 20", 1),
new Tuple<>("msg {player} Mine a block with the sword and hold it", 3),
new Tuple<>("fix", 1),
new Tuple<>("getinfo {player}", 3),
new Tuple<>("god", 0.1),
new Tuple<>("tp ~ ~10 ~", 4),
new Tuple<>("god", 0.1),
new Tuple<>("sethealth 1", 1),
new Tuple<>("heal", 1),
new Tuple<>("hideflags", 2),
new Tuple<>("h dirt", 0.1),
new Tuple<>("infinite", 5),
new Tuple<>("invsee {randomplayer}", 3),
new Tuple<>("h dirt", 0.1),
new Tuple<>("lore add Silly dirt", 2),
new Tuple<>("lore remove 1", 2),
new Tuple<>("music", 3),
new Tuple<>("night", 1),
new Tuple<>("day", 1),
new Tuple<>("potion speed", 2),
new Tuple<>("rename &6This dirt is special", 2),
new Tuple<>("setmaxhealth 10", 1),
new Tuple<>("setstack 127", 1),
new Tuple<>("h iron_sword", 0.1),
new Tuple<>("setunbreakable", 3),
new Tuple<>("smite {player}", 1),
new Tuple<>("heal", 0.1),
new Tuple<>("sudo {randomplayer} say I have been sudoed", 1),
new Tuple<>("h dirt", 0.1),
new Tuple<>("setpersistentdata estools:hello string wassup", 1),
new Tuple<>("getpersistentdata estools:hello string", 1),
new Tuple<>("removepersistentdata estools:hello", 1),
new Tuple<>("suicide", 0.1)
};

public Tester(Player p) {
player = p;
}

public void startTests() {
EsToolsCommand.send(player, "&aStarting tests...");

// Init some stuff
SafeTp.enabled = false;

execNextCommand();
}

private void execNextCommand() {
if (routine.length == currentCommand) {
EsToolsCommand.send(player, "&aTests complete!");
return;
}

Tuple<String, Double> cCmd = routine[currentCommand];
currentCommand++;

String cmd = cCmd.a();
if (cmd.contains("{randomplayer}")) {
// Find a random player that isn't player
Player randomPlayer = null;
for (Player p : Bukkit.getOnlinePlayers()) {
if (p != player) {
randomPlayer = p;
break;
}
}

if (randomPlayer == null) {
randomPlayer = player;
}

cmd = cmd.replace("{randomplayer}", randomPlayer.getName());
}
cmd = cmd.replace("{player}", player.getName());

try {
exec(cmd);
} catch (Exception e) {
EsToolsCommand.send(player, "&cFailed to execute the following command: " + cmd);

// Print the full stacktrace not just the message
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTrace = sw.toString();

EsToolsCommand.send(player, "&c" + stackTrace);
Bukkit.getLogger().severe(stackTrace);
return;
}

Double secVal;
Object val = cCmd.b();
//noinspection ConstantValue, it's not constant
if (val instanceof Integer) { // Stupid java being dumb
secVal = ((Integer) val).doubleValue();
} else {
secVal = cCmd.b();
}
@SuppressWarnings("WrapperTypeMayBePrimitive") Double timeInTicks = (secVal * 20.0); // The type cannot be primitive
Bukkit.getScheduler().runTaskLater(Main.plugin, this::execNextCommand, timeInTicks.longValue());
EsToolsCommand.send(player, "&bWaiting " + cCmd.b() + " seconds");
}

private void exec(String cmd) {
EsToolsCommand.send(player, "&aExecuting: " + cmd);
Bukkit.dispatchCommand(player, cmd);
}

}

0 comments on commit 922a18f

Please sign in to comment.