Skip to content

Commit

Permalink
Merge pull request #29 from jaron780/master
Browse files Browse the repository at this point in the history
Command Tab Autocomplete
  • Loading branch information
jrbudda authored Dec 14, 2016
2 parents 119c0c1 + 739e7a8 commit 0909f01
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/org/vivecraft/VSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;
import org.spigotmc.SpigotConfig;
import org.vivecraft.command.ConstructTabCompleter;
import org.vivecraft.command.ViveCommand;
import org.vivecraft.entities.CustomGoalSwell;
import org.vivecraft.entities.CustomPathFinderGoalPlayerWhoLookedAtTarget;
Expand Down Expand Up @@ -69,8 +70,12 @@ public void onEnable() {
saveConfig();
// end Config part

this.getCommand("vive").setExecutor(new ViveCommand(this));
this.getCommand("vse").setExecutor(new ViveCommand(this));
getCommand("vive").setExecutor(new ViveCommand(this));
getCommand("vse").setExecutor(new ViveCommand(this));
getCommand("vive").setTabCompleter(new ConstructTabCompleter());
getCommand("vse").setTabCompleter(new ConstructTabCompleter());


getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, new VivecraftNetworkListener(this));
getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);

Expand Down
27 changes: 27 additions & 0 deletions src/org/vivecraft/command/ConstructTabCompleter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.vivecraft.command;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

public class ConstructTabCompleter implements TabCompleter {

@Override
public List<String> onTabComplete(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
List<String> list = new ArrayList<String>();
if(arg0 instanceof Player){
if(arg3.length >= 1){
for(Cmd cmd: ViveCommand.getCommands()){
if(cmd.getCommand().startsWith(arg3[0]))
list.add(cmd.getCommand());
}
return list;
}
}
return null;
}
}
21 changes: 20 additions & 1 deletion src/org/vivecraft/command/ViveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ViveCommand implements CommandExecutor {

private VSE plugin;
private ArrayList<Cmd> commands = new ArrayList<Cmd>();
private static ArrayList<Cmd> commands = new ArrayList<Cmd>();

public ViveCommand(VSE vse) {
plugin = vse;
Expand All @@ -23,6 +23,11 @@ public ViveCommand(VSE vse) {
commands.add(new Cmd("sendplayerdata", "set to false to disable sending player to data to clients. Default: true"));
commands.add(new Cmd("creeperradius", "type false to disable or type a number to change the radius. Default: 1.75"));
commands.add(new Cmd("bow", "Sets the multiplier for bow damage of vive users. Default: 2"));
commands.add(new Cmd("checkforupdate", "Checked for an update every time an OP joins the server"));
}

public static ArrayList<Cmd> getCommands(){
return commands;
}

@Override
Expand Down Expand Up @@ -116,6 +121,20 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sendMessage("Version: " + version, player);
} else
//
if(command.equals("checkforupdate")){
if(args.length >= 2){
if(args[1].toLowerCase().equals("true")){
plugin.getConfig().set("checkforupdate.enabled", true);
sendMessage("Update checker has been enabled.", player);
}else if (args[1].toLowerCase().equals("false")) {
plugin.getConfig().set("checkforupdate.enabled", false);
sendMessage("Update checker has been disabled.", player);
}
}else{
sendMessage("Check for update: " + plugin.getConfig().get("checkforupdate.enabled"),player);
}
}else
//
if (command.equals("help")) {
for (Cmd cm : commands) {
sendMessage(cm.getCommand() + " - " + cm.getDescription(), player);
Expand Down
10 changes: 7 additions & 3 deletions src/org/vivecraft/listeners/VivecraftNetworkListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public void onPluginMessageReceived(String channel, Player sender, byte[] payloa
BufferedReader br = new BufferedReader(is);
VSE.vivePlayers.put(sender.getUniqueId(), new VivePlayer(sender));

sender.sendPluginMessage(vse, vse.CHANNEL, StringToPayload(PacketDiscriminators.VERSION, vse.getDescription().getFullName()));

VivePlayer vivepl = VSE.vivePlayers.get(sender.getUniqueId());
try {
String version = br.readLine();
Expand All @@ -87,15 +89,17 @@ public void onPluginMessageReceived(String channel, Player sender, byte[] payloa

if(vse.getConfig().getBoolean("welcomemsg.enabled"))
ViveCommand.sendMessage(vse.getConfig().getString("welcomemsg.welcomeVR"),sender);

if(vse.getConfig().getBoolean("SendPlayerData.enabled") == true)
sender.sendPluginMessage(vse, vse.CHANNEL, new byte[]{(byte) PacketDiscriminators.REQUESTDATA.ordinal()});
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

sender.sendPluginMessage(vse, vse.CHANNEL, StringToPayload(PacketDiscriminators.VERSION, vse.getDescription().getFullName()));
if(vse.getConfig().getBoolean("SendPlayerData.enabled") == true)
sender.sendPluginMessage(vse, vse.CHANNEL, new byte[]{(byte) PacketDiscriminators.REQUESTDATA.ordinal()});


break;
case WORLDSCALE:
break;
Expand Down
3 changes: 2 additions & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#this file is used to check for updates
1.11-r3: VSE has a new update download at https://github.com/jrbudda/Vivecraft_Spigot_Extensions/releases
1.11-r4: VSE is up to date!
1.11-r4: VSE is up to date!
1.11-r5: VSE is up to date!

0 comments on commit 0909f01

Please sign in to comment.