Using maven and fixed encoding

Also using IDEA.
Also fixes based on code analysis.
This commit is contained in:
Norbi Peti 2018-02-18 01:47:50 +01:00
parent 6127ef829a
commit 448d8a8ce0
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 117 additions and 86 deletions

View file

@ -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
View file

@ -1 +1,3 @@
/bin/ /bin/
/.idea/
*.iml

37
pom.xml Normal file
View file

@ -0,0 +1,37 @@
<?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>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<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>
</dependencies>
</project>

View file

@ -1,67 +1,67 @@
package io.github.norbipeti.onecommandhelper; package io.github.norbipeti.onecommandhelper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.CommandBlock; import org.bukkit.block.CommandBlock;
import org.bukkit.command.BlockCommandSender; import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class Commands implements CommandExecutor public class Commands implements CommandExecutor
{ {
private final String[] replacecmds = { "achievement", "ban", "ban-ip", private final String[] replacecmds = { "achievement", "ban", "ban-ip",
"banlist", "blockdata", "clear", "clone", "debug", "banlist", "blockdata", "clear", "clone", "debug",
"defaultgamemode", "deop", "difficulty", "effect", "enchant", "defaultgamemode", "deop", "difficulty", "effect", "enchant",
"entitydata", "execute", "fill", "gamemode", "gamerule", "give", "entitydata", "execute", "fill", "gamemode", "gamerule", "give",
"help", "kick", "kill", "list", "me", "op", "pardon", "particle", "help", "kick", "kill", "list", "me", "op", "pardon", "particle",
"playsound", "publish", "replaceitem", "save", "save-all", "playsound", "publish", "replaceitem", "save", "save-all",
"save-off", "save-on", "say", "scoreboard", "seed", "setblock", "save-off", "save-on", "say", "scoreboard", "seed", "setblock",
"setidletimeout", "setworldspawn", "spawnpoint", "spreadplayers", "setidletimeout", "setworldspawn", "spawnpoint", "spreadplayers",
"stats", "stop", "stopsound", "summon", "teleport", "tell", "stats", "stop", "stopsound", "summon", "teleport", "tell",
"tellraw", "testfor", "testforblock", "testforblocks", "time", "tellraw", "testfor", "testforblock", "testforblocks", "time",
"title", "toggledownfall", "tp", "trigger", "weather", "whitelist", "title", "toggledownfall", "tp", "trigger", "weather", "whitelist",
"worldborder", "xp", "commands", "banip", "broadcast", "home", "worldborder", "xp", "commands", "banip", "broadcast", "home",
"setspawn", "unban" }; "setspawn", "unban" };
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String alias, public boolean onCommand(CommandSender sender, Command cmd, String alias,
String[] args) String[] args)
{ {
StringBuilder acmdb = new StringBuilder("minecraft:execute " StringBuilder acmdb = new StringBuilder("minecraft:execute "
+ sender.getName() + " ~ ~ ~ "); + sender.getName() + " ~ ~ ~ ");
if (sender != Bukkit.getConsoleSender() if (sender != Bukkit.getConsoleSender()
&& !(sender instanceof BlockCommandSender)) && !(sender instanceof BlockCommandSender))
{ {
Block block = ((Player) sender).getLocation().subtract(0, 1, 0) Block block = ((Player) sender).getLocation().subtract(0, 1, 0)
.getBlock(); .getBlock();
if (block.getType() != Material.COMMAND) if (block.getType() != Material.COMMAND)
{ {
sender.sendMessage("§cError! Block underneath must be command block! Found " sender.sendMessage("§cError! Block underneath must be command block! Found "
+ block.getType()); + block.getType());
return true; return true;
} }
CommandBlock cmdblock = (CommandBlock) block.getState(); CommandBlock cmdblock = (CommandBlock) block.getState();
acmdb.append(cmdblock.getCommand()); acmdb.append(cmdblock.getCommand());
} else } else
{ {
if (args.length == 0) if (args.length == 0)
{ {
sender.sendMessage("§cUsage: /" + alias + " <onecommand>"); sender.sendMessage("§cUsage: /" + alias + " <onecommand>");
return true; //Why use the builtin usage shoing thing return true; //Why use the builtin usage shoing thing
} }
} }
String acmd = acmdb.toString(); String acmd = acmdb.toString();
StringBuilder replace = new StringBuilder("(" + replacecmds[0]); StringBuilder replace = new StringBuilder("(" + replacecmds[0]);
for (int i = 1; i < replacecmds.length; i++) for (int i = 1; i < replacecmds.length; i++)
replace.append("|" + replacecmds[i]); replace.append("|").append(replacecmds[i]);
replace.append(")"); replace.append(")");
acmd = acmd.replaceAll("([^t]|^)( |:| \\/|:\\/)" + replace + " ", acmd = acmd.replaceAll("([^t]|^)( |:| /|:/)" + replace + " ",
"$1$2minecraft:$3 ").replaceAll("\" (\\/*)minecraft:", "$1$2minecraft:$3 ").replaceAll("\" (/*)minecraft:",
"\"$1minecraft:"); //Tellraw "\"$1minecraft:"); //Tellraw
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), acmd); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), acmd);
return true; return true;
} }
} }

View file

@ -1,12 +1,11 @@
package io.github.norbipeti.onecommandhelper; package io.github.norbipeti.onecommandhelper;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class PluginMain extends JavaPlugin public class PluginMain extends JavaPlugin
{ {
@Override @Override
public void onEnable() { public void onEnable() {
//getServer().getPluginManager().registerEvents(new CommandListener(), this); getCommand("occ").setExecutor(new Commands());
getCommand("occ").setExecutor(new Commands()); }
} }
}