Added a command and a new API function "getVersion()"

This commit is contained in:
fillefilip8 2016-03-03 14:57:04 +01:00
parent ef118a3a64
commit 5930a83765
4 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,48 @@
package us.myles.ViaVersion;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.myles.ViaVersion.api.ViaVersion;
import java.util.ArrayList;
import java.util.List;
/**
* Created by fillefilip8 on 2016-03-03.
*/
public class ViaVersionCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("viaversion.admin")) {
if (args.length == 0) {
sender.sendMessage(color("&aViaVersion &c" + ViaVersion.getInstance().getVersion() + "&b by &6_MylesC"));
sender.sendMessage(color("&6Commands:"));
sender.sendMessage(color("&2/viaversion list &7- &6Shows lists of all 1.9 clients and 1.8 clients."));
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
List<String> portedPlayers = new ArrayList<String>();
List<String> normalPlayers = new ArrayList<String>();
for (Player p : Bukkit.getOnlinePlayers()) {
if (ViaVersion.getInstance().isPorted(p)) {
portedPlayers.add(p.getName());
} else {
normalPlayers.add(p.getName());
}
}
sender.sendMessage(color("&8[&61.9&8]: &b" + portedPlayers.toString()));
sender.sendMessage(color("&8[&61.8&8]: &b" + normalPlayers.toString()));
}
}
}
return false;
}
public String color(String string){
return string.replace("&", "§");
}
}

View File

@ -52,6 +52,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
setPorted(e.getPlayer().getUniqueId(), false); setPorted(e.getPlayer().getUniqueId(), false);
} }
}, this); }, this);
getCommand("viaversion").setExecutor(new ViaVersionCommand());
} }
public void injectPacketHandler() throws Exception { public void injectPacketHandler() throws Exception {
@ -78,6 +79,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
return portedPlayers.contains(player.getUniqueId()); return portedPlayers.contains(player.getUniqueId());
} }
@Override
public String getVersion() {
return getDescription().getVersion();
}
public void setPorted(UUID id, boolean value) { public void setPorted(UUID id, boolean value) {
if (value) { if (value) {
portedPlayers.add(id); portedPlayers.add(id);

View File

@ -9,4 +9,5 @@ public interface ViaVersionAPI {
* @return * @return
*/ */
boolean isPorted(Player player); boolean isPorted(Player player);
String getVersion();
} }

View File

@ -4,3 +4,5 @@ author: _MylesC
version: ${version} version: ${version}
load: startup load: startup
loadbefore: [ProtocolLib, ProxyPipe] loadbefore: [ProtocolLib, ProxyPipe]
commands:
viaversion: