Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
c975ca7cd5 | |||
e7109d40a8 | |||
ef4011d73d | |||
f13cb2777a | |||
a009dd3730 | |||
448d8a8ce0 | |||
6127ef829a | |||
cdae90bde3 | |||
2ab7c27fd4 | |||
584515199d | |||
dfc11f4cea |
12 changed files with 244 additions and 97 deletions
.classpath.gitignoreREADME.mdREADME_hu.mdplugin.ymlpom.xml
src
io/github/norbipeti/onecommandhelper
main
test/java
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
|
||||||
<classpathentry kind="lib" path="D:/Z - Norbi cucca/0 Projektek/TheButtonMCAutoFlairProto/Spigot server (build)/spigot-1.9.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
/bin/
|
/bin/
|
||||||
|
/.idea/
|
||||||
|
*.iml
|
||||||
|
|
18
README.md
18
README.md
|
@ -1,12 +1,26 @@
|
||||||
English / [Magyar](https://github.com/NorbiPeti/OneCommandHelper/blob/master/README_hu.md)
|
English / [Magyar](https://github.com/NorbiPeti/OneCommandHelper/blob/master/README_hu.md)
|
||||||
|
|
||||||
# OneCommandHelper
|
# OneCommandHelper
|
||||||
A plugin that allows one command creations to work on Spigot/Bukkit.
|
A plugin that allows one (or multiple) command creations to work on Spigot/Bukkit.
|
||||||
|
This is needed because the plugins installed on the server may have a command which replaces a vanilla command, and the plugin's version may not work the same way.
|
||||||
|
|
||||||
|
Let's take /kill as an example.
|
||||||
|
Essentials has a /kill command, so if you use that plugin, it takes over, so every time you run /kill, it runs that one.
|
||||||
|
However, that command doesn't know about selectors, so something like `/kill @a[r=1]` wouldn't work with it.
|
||||||
|
|
||||||
|
But, there is a syntax in Bukkit, `/plugin:command`, which allows running a specific plugin's command - or Minecraft's.
|
||||||
|
So simply running `/minecraft:kill` deals with the issue.
|
||||||
|
|
||||||
|
But this isn't typically done in one command creations, it'd greatly limit the command length anyways.
|
||||||
|
So, this plugin does it.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Put the downloaded ([see Releases at top or click here](https://github.com/NorbiPeti/OneCommandHelper/releases)) JAR file into the server's plugin directory. No configuration needed.
|
Put the downloaded ([see Releases at top or click here](https://github.com/NorbiPeti/OneCommandHelper/releases)) JAR file into the server's plugin directory. No configuration needed.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Paste the command into a command block, but *do not power it*. Instead, stand on it, and run /occ in the chat.
|
Paste the command into a command block, but *do not power it*. Instead, look at it, and run /occ in the chat.
|
||||||
|
|
||||||
|
In case of multiple commands, look at the one the command's creator said to activate.
|
||||||
|
|
||||||
## Video
|
## Video
|
||||||
|
[](http://www.youtube.com/watch?v=rfPeuj0NWVg)
|
||||||
|
|
18
README_hu.md
18
README_hu.md
|
@ -1,12 +1,26 @@
|
||||||
[English](https://github.com/NorbiPeti/OneCommandHelper/blob/master/README.md) / Magyar
|
[English](https://github.com/NorbiPeti/OneCommandHelper/blob/master/README.md) / Magyar
|
||||||
|
|
||||||
# OneCommandHelper
|
# OneCommandHelper
|
||||||
Egy plugin, ami működőképessé teszi az egy parancsos alkotásokat Spigot/Bukkit szervereken.
|
Egy plugin, ami működőképessé teszi az egy (vagy több) parancsos alkotásokat Spigot/Bukkit szervereken.
|
||||||
|
Erre azért van szükség, mert a szerverekre telepített pluginoknak lehet olyan parancsuk, ami lecserél egy beépített parancsot.
|
||||||
|
|
||||||
|
Vegyük például a /kill parancsot.
|
||||||
|
Az Essentialsnak van /kill parancsa, ezért ha használod azt a plugint, minden alkalommal, amikor lefuttatod a /kill prancsot, azt futtatja le.
|
||||||
|
Ugyanakkor az a parancs nem ismeri a szelektorokat, ezért pl. a `/kill @a[r=1]` parancs nem működne vele.
|
||||||
|
|
||||||
|
De van egy szintaxis a Bukkitban, `/plugin:parancs`, ami lehetővé teszi egy bizonyos plugin - vagy a Minecraft - parancsának a futtatását.
|
||||||
|
Így egyszerűen a `/minecraft:kill` futtatása megoldja a problémát.
|
||||||
|
|
||||||
|
De ezt általában nem teszik meg az egy parancsos alkotásookban, nagy mértékben korlátozná a parancs hosszúságát egyébként is.
|
||||||
|
Úgyhogy ez a plugin megcsinálja.
|
||||||
|
|
||||||
## Telepítés
|
## Telepítés
|
||||||
Rakd a letöltött ([lásd Releases felül vagy kattints ide](https://github.com/NorbiPeti/OneCommandHelper/releases)) JAR fájlt a szerver plugins mappába. Konfiguráció nem szükséges.
|
Rakd a letöltött ([lásd Releases felül vagy kattints ide](https://github.com/NorbiPeti/OneCommandHelper/releases)) JAR fájlt a szerver plugins mappába. Konfiguráció nem szükséges.
|
||||||
|
|
||||||
## Használat
|
## Használat
|
||||||
Illeszd be a parancsot egy parancsblokkba, de *ne aktiváld*, helyette állj a parancsblokkra és írd be a /occ parancsot.
|
Illeszd be a parancsot egy parancsblokkba, de *ne aktiváld*, helyette nézz rá a parancsblokkra és írd be a /occ parancsot.
|
||||||
|
|
||||||
|
Több parancs esetében arra nézz, amelyiket aktiválni kell a parancs készítője szerint.
|
||||||
|
|
||||||
## Videó
|
## Videó
|
||||||
|
[](http://www.youtube.com/watch?v=rfPeuj0NWVg)
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
name: OneCommandHelper
|
|
||||||
main: io.github.norbipeti.onecommandhelper.PluginMain
|
|
||||||
version: 1.0
|
|
||||||
commands:
|
|
||||||
occ:
|
|
43
pom.xml
Normal file
43
pom.xml
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.github.NorbiPeti</groupId>
|
||||||
|
<artifactId>OneCommandHelper</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-all</artifactId>
|
||||||
|
<version>2.0.2-beta</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -1,69 +0,0 @@
|
||||||
package io.github.norbipeti.onecommandhelper;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.CommandBlock;
|
|
||||||
import org.bukkit.command.BlockCommandSender;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor
|
|
||||||
{
|
|
||||||
private final String[] replacecmds = { "achievement", "ban", "ban-ip",
|
|
||||||
"banlist", "blockdata", "clear", "clone", "debug",
|
|
||||||
"defaultgamemode", "deop", "difficulty", "effect", "enchant",
|
|
||||||
"entitydata", "execute", "fill", "gamemode", "gamerule", "give",
|
|
||||||
"help", "kick", "kill", "list", "me", "op", "pardon", "particle",
|
|
||||||
"playsound", "publish", "replaceitem", "save", "save-all",
|
|
||||||
"save-off", "save-on", "say", "scoreboard", "seed", "setblock",
|
|
||||||
"setidletimeout", "setworldspawn", "spawnpoint", "spreadplayers",
|
|
||||||
"stats", "stop", "stopsound", "summon", "teleport", "tell",
|
|
||||||
"tellraw", "testfor", "testforblock", "testforblocks", "time",
|
|
||||||
"title", "toggledownfall", "tp", "trigger", "weather", "whitelist",
|
|
||||||
"worldborder", "xp", "commands", "banip", "broadcast", "home",
|
|
||||||
"setspawn", "unban" };
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String alias,
|
|
||||||
String[] args)
|
|
||||||
{
|
|
||||||
StringBuilder acmdb = new StringBuilder("minecraft:execute "
|
|
||||||
+ sender.getName() + " ~ ~ ~");
|
|
||||||
if (sender != Bukkit.getConsoleSender()
|
|
||||||
&& !(sender instanceof BlockCommandSender))
|
|
||||||
{
|
|
||||||
Block block = ((Player) sender).getLocation().subtract(0, 1, 0)
|
|
||||||
.getBlock();
|
|
||||||
if (block.getType() != Material.COMMAND)
|
|
||||||
{
|
|
||||||
sender.sendMessage("§cError! Block underneath must be command block! Found "
|
|
||||||
+ block.getType());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
CommandBlock cmdblock = (CommandBlock) block.getState();
|
|
||||||
acmdb.append(" ").append(cmdblock.getCommand());
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (args.length == 0)
|
|
||||||
{
|
|
||||||
sender.sendMessage("§cUsage: /" + alias + " <onecommand>");
|
|
||||||
return true; //Why use the builtin usage shoing thing
|
|
||||||
}
|
|
||||||
for (String arg : args)
|
|
||||||
acmdb.append(" ").append(arg);
|
|
||||||
}
|
|
||||||
String acmd = acmdb.toString();
|
|
||||||
StringBuilder replace = new StringBuilder("(" + replacecmds[0]);
|
|
||||||
for (int i = 1; i < replacecmds.length; i++)
|
|
||||||
replace.append("|" + replacecmds[i]);
|
|
||||||
replace.append(")");
|
|
||||||
acmd = acmd.replaceAll("Command:\\/" + replace, "/minecraft:$1")
|
|
||||||
.replaceAll("Command\\:" + replace, "Command:minecraft:$1")
|
|
||||||
.replaceAll(" " + replace + " ", " minecraft:$1 ");
|
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), acmd);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package io.github.norbipeti.onecommandhelper;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
//getServer().getPluginManager().registerEvents(new CommandListener(), this);
|
|
||||||
getCommand("occ").setExecutor(new Commands());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package io.github.norbipeti.onecommandhelper;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.CommandBlock;
|
||||||
|
import org.bukkit.command.BlockCommandSender;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
|
import org.bukkit.help.IndexHelpTopic;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
private final String[] fallbackreplacecmds = {"achievement", "ban", "ban-ip",
|
||||||
|
"banlist", "blockdata", "clear", "clone", "debug",
|
||||||
|
"defaultgamemode", "deop", "difficulty", "effect", "enchant",
|
||||||
|
"entitydata", "execute", "fill", "gamemode", "gamerule", "give",
|
||||||
|
"help", "kick", "kill", "list", "me", "op", "pardon", "particle",
|
||||||
|
"playsound", "publish", "replaceitem", "save", "save-all",
|
||||||
|
"save-off", "save-on", "say", "scoreboard", "seed", "setblock",
|
||||||
|
"setidletimeout", "setworldspawn", "spawnpoint", "spreadplayers",
|
||||||
|
"stats", "stop", "stopsound", "summon", "teleport", "tell",
|
||||||
|
"tellraw", "testfor", "testforblock", "testforblocks", "time",
|
||||||
|
"title", "toggledownfall", "tp", "trigger", "weather", "whitelist",
|
||||||
|
"worldborder", "xp", "commands", "banip", "broadcast", "home",
|
||||||
|
"setspawn", "unban"};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String alias,
|
||||||
|
String[] args) {
|
||||||
|
if (!sender.isOp()) {
|
||||||
|
sender.sendMessage("§cYou need to be an OP to use this command.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
StringBuilder acmdb = new StringBuilder("minecraft:execute ");
|
||||||
|
acmdb.append(sender.getName()).append(" ");
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Block block = ((Player) sender).getTargetBlock(null, 10);
|
||||||
|
if (block == null) {
|
||||||
|
sender.sendMessage("§cYou need to look at the command block you want to activate. Make sure you're within 10 blocks of it.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (block.getType() != Material.COMMAND) {
|
||||||
|
sender.sendMessage("§cError! You need to look at a command block. Found "
|
||||||
|
+ block.getType());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CommandBlock cmdblock = (CommandBlock) block.getState();
|
||||||
|
acmdb.append(block.getX()).append(".5 ").append(block.getY()).append(".5 ").append(block.getZ()).append(".5 ");
|
||||||
|
acmdb.append(cmdblock.getCommand());
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("§cYou need to be a player and look at the command block where you have the command you need to run.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String acmd = acmdb.toString();
|
||||||
|
IndexHelpTopic iht = (IndexHelpTopic) Bukkit.getHelpMap().getHelpTopic("Minecraft");
|
||||||
|
String[] replacecmds;
|
||||||
|
try { //Get Minecraft (vanilla) commands
|
||||||
|
Field f = iht.getClass().getDeclaredField("allTopics");
|
||||||
|
f.setAccessible(true);
|
||||||
|
replacecmds = ((Collection<HelpTopic>) f.get(iht)).stream().filter(ht -> ht.getName().startsWith("/minecraft:")).map(ht -> ht.getName().substring("/minecraft:".length())).toArray(String[]::new);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
PluginMain.getPlugin(PluginMain.class).getLogger().info("Using fallback command array");
|
||||||
|
replacecmds = fallbackreplacecmds;
|
||||||
|
}
|
||||||
|
StringBuilder replace = new StringBuilder("(").append(replacecmds[0]);
|
||||||
|
for (int i = 1; i < replacecmds.length; i++)
|
||||||
|
replace.append("|").append(replacecmds[i]);
|
||||||
|
replace.append(")");
|
||||||
|
acmd = acmd.replaceAll("([^t]|^)( |:| /|:/)" + replace + " ",
|
||||||
|
"$1$2minecraft:$3 ").replaceAll("\" (/*)minecraft:",
|
||||||
|
"\"$1minecraft:"); //Tellraw
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), acmd);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package io.github.norbipeti.onecommandhelper;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin {
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
getCommand("occ").setExecutor(new Commands());
|
||||||
|
}
|
||||||
|
}
|
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
name: OneCommandHelper
|
||||||
|
main: io.github.norbipeti.onecommandhelper.PluginMain
|
||||||
|
version: 2.0
|
||||||
|
commands:
|
||||||
|
occ:
|
||||||
|
description: Runs one (or more) command creations you look at.
|
67
src/test/java/CommandTestTest.java
Normal file
67
src/test/java/CommandTestTest.java
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import io.github.norbipeti.onecommandhelper.Commands;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.CommandBlock;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class CommandTestTest { //Nope. See below.
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
/*Bukkit.setServer(Mockito.mock(Server.class, new Answer() {
|
||||||
|
@Override
|
||||||
|
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
|
if (is(invocationOnMock, String.class))
|
||||||
|
return "test";
|
||||||
|
if (is(invocationOnMock, Logger.class))
|
||||||
|
return Logger.getLogger("Test");
|
||||||
|
if (invocationOnMock.getMethod().getName().equals("sendMessage")) {
|
||||||
|
System.out.println(Arrays.toString(invocationOnMock.getArguments()));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!Modifier.isAbstract(invocationOnMock.getMethod().getModifiers()))
|
||||||
|
return invocationOnMock.callRealMethod();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Commands cmds = new Commands();
|
||||||
|
cmds.onCommand(Mockito.mock(Player.class, new Answer() {
|
||||||
|
@Override
|
||||||
|
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
|
if (is(invocationOnMock, boolean.class))
|
||||||
|
return true;
|
||||||
|
if (is(invocationOnMock, Block.class))
|
||||||
|
return Mockito.mock(Block.class, new Answer() {
|
||||||
|
@Override
|
||||||
|
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
|
if (is(invocationOnMock, Material.class))
|
||||||
|
return Material.COMMAND;
|
||||||
|
if (is(invocationOnMock, BlockState.class))
|
||||||
|
return Mockito.mock(CommandBlock.class);
|
||||||
|
return null; //Nope. The help topics would need to be added too.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
System.out.println(invocationOnMock.getMethod().getName());
|
||||||
|
System.out.println(Arrays.toString(invocationOnMock.getArguments()));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}), null, "occ", new String[]{});*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> boolean is(InvocationOnMock invocationOnMock, Class<T> cl) {
|
||||||
|
return invocationOnMock.getMethod().getReturnType().isAssignableFrom(cl);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue