Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #156 from DragonetMC/vehicles
Browse files Browse the repository at this point in the history
Vehicles
  • Loading branch information
DefinitlyEvil authored Dec 24, 2017
2 parents 3aa7ee9 + fdeaf62 commit d343ed5
Show file tree
Hide file tree
Showing 152 changed files with 5,499 additions and 5,477 deletions.
39 changes: 18 additions & 21 deletions src/main/java/org/dragonet/proxy/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,29 @@
import org.dragonet.proxy.DragonProxy;

public abstract class Command {
// vars
private final String name;
protected String description = "";
private CommandRegister commandMap = null;

// constructor
public Command(String name) {
this(name, "");
}
private final String name;
protected String description = "";
private CommandRegister commandMap = null;

public Command(String name, String description) {
this.name = name;
this.description = description;
}
// constructor
public Command(String name) {
this(name, "");
}

// public
public String getName() {
return name;
}
public Command(String name, String description) {
this.name = name;
this.description = description;
}

public String getDescription() {
return description;
}
public String getName() {
return name;
}

public abstract void execute(DragonProxy proxy, String[] args);
public String getDescription() {
return description;
}

// private
public abstract void execute(DragonProxy proxy, String[] args);

}
87 changes: 41 additions & 46 deletions src/main/java/org/dragonet/proxy/commands/CommandRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,51 @@
import org.dragonet.proxy.commands.defaults.*;

public final class CommandRegister {
// vars
private final Map<String, Command> commandMap = Collections.synchronizedMap(new HashMap<String, Command>());
private final DragonProxy proxy;

// constructor
public CommandRegister(DragonProxy proxy) {
this.proxy = proxy;
registerDefaults();
}
private final Map<String, Command> commandMap = Collections.synchronizedMap(new HashMap<String, Command>());
private final DragonProxy proxy;

// public
public void registerDefaults() {
registerCommand("stop", new StopCommand("stop"));
registerCommand("help", new HelpCommand("help"));
registerCommand("kill", new KillCommand("kill")); // Bad things could happen
registerCommand("test", new TestCommand("test")); // FOR TESTING
}
public CommandRegister(DragonProxy proxy) {
this.proxy = proxy;
registerDefaults();
}

public void registerCommand(String command, Command console) {
commandMap.put(command, console);
}
public void registerDefaults() {
registerCommand("stop", new StopCommand("stop"));
registerCommand("help", new HelpCommand("help"));
registerCommand("kill", new KillCommand("kill")); // Bad things could happen
registerCommand("test", new TestCommand("test")); // FOR TESTING
}

public Map<String, Command> getCommands() {
return commandMap;
}
public void registerCommand(String command, Command console) {
commandMap.put(command, console);
}

public void callCommand(String cmd) {
String trimedCmd = cmd.trim();
String label = null;
String[] args = null;
if (!cmd.trim().contains(" ")) {
label = trimedCmd.toLowerCase();
args = new String[0];
} else {
label = trimedCmd.substring(0, trimedCmd.indexOf(" ")).toLowerCase();
String argLine = trimedCmd.substring(trimedCmd.indexOf(" ") + 1);
args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
}
if (label == null) {
proxy.getLogger().warning(proxy.getLang().get(Lang.COMMAND_NOT_FOUND));
return;
}
Command command = commandMap.get(label);
if (command == null) {
proxy.getLogger().warning(proxy.getLang().get(Lang.COMMAND_NOT_FOUND));
return;
}
command.execute(proxy, args);
}

// private
public Map<String, Command> getCommands() {
return commandMap;
}

public void callCommand(String cmd) {
String trimedCmd = cmd.trim();
String label = null;
String[] args = null;
if (!cmd.trim().contains(" ")) {
label = trimedCmd.toLowerCase();
args = new String[0];
} else {
label = trimedCmd.substring(0, trimedCmd.indexOf(" ")).toLowerCase();
String argLine = trimedCmd.substring(trimedCmd.indexOf(" ") + 1);
args = argLine.contains(" ") ? argLine.split(" ") : new String[]{argLine};
}
if (label == null) {
proxy.getLogger().warning(proxy.getLang().get(Lang.COMMAND_NOT_FOUND));
return;
}
Command command = commandMap.get(label);
if (command == null) {
proxy.getLogger().warning(proxy.getLang().get(Lang.COMMAND_NOT_FOUND));
return;
}
command.execute(proxy, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
import org.dragonet.proxy.DragonProxy;

public interface IConsoleCommand {
void execute(DragonProxy proxy, String[] args);

void execute(DragonProxy proxy, String[] args);
}
34 changes: 14 additions & 20 deletions src/main/java/org/dragonet/proxy/commands/defaults/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,22 @@
import java.util.TreeMap;

public class HelpCommand extends Command {
// vars

// constructor
public HelpCommand(String name) {
super(name, "Displays commands for DragonProxy");
}
public HelpCommand(String name) {
super(name, "Displays commands for DragonProxy");
}

// public
public void execute(DragonProxy proxy, String[] args) {
proxy.getLogger().info(MCColor.GREEN + "----[ All commands for DragonProxy ]----");
public void execute(DragonProxy proxy, String[] args) {
proxy.getLogger().info(MCColor.GREEN + "----[ All commands for DragonProxy ]----");

Map<String, Command> commands = new TreeMap<>();
for (Command cmd : proxy.getCommandRegister().getCommands().values()) {
commands.put(cmd.getName(), cmd);
}

for (Command command1 : commands.values()) {
proxy.getLogger()
.info(MCColor.DARK_GREEN + command1.getName() + ": " + MCColor.WHITE + command1.getDescription());
}
}

// private
Map<String, Command> commands = new TreeMap<>();
for (Command cmd : proxy.getCommandRegister().getCommands().values()) {
commands.put(cmd.getName(), cmd);
}

for (Command command1 : commands.values()) {
proxy.getLogger()
.info(MCColor.DARK_GREEN + command1.getName() + ": " + MCColor.WHITE + command1.getDescription());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@

// Only use if you have to. Clients will eventually timeout.
public class KillCommand extends Command {
// vars

// constructor
public KillCommand(String name) {
super(name, "Forcefully kill the proxy");
}

// public
public void execute(DragonProxy proxy, String[] args) {
proxy.getLogger().info("Forcefully killing proxy...");
System.exit(0);
}

// private
public KillCommand(String name) {
super(name, "Forcefully kill the proxy");
}

public void execute(DragonProxy proxy, String[] args) {
proxy.getLogger().info("Forcefully killing proxy...");
System.exit(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@
import org.dragonet.proxy.commands.Command;

public class StopCommand extends Command {
// vars

// constructor
public StopCommand(String name) {
super(name, "Stop the proxy");
}

// public
public void execute(DragonProxy proxy, String[] args) {
proxy.shutdown();
}

// private
public StopCommand(String name) {
super(name, "Stop the proxy");
}

public void execute(DragonProxy proxy, String[] args) {
proxy.shutdown();
}
}
Loading

0 comments on commit d343ed5

Please sign in to comment.