Update event bus library, fix compile errors
This commit is contained in:
parent
0161fef673
commit
ef08583850
5 changed files with 58 additions and 93 deletions
|
@ -1,26 +1,26 @@
|
|||
package dev.zontreck.ariaslib.events;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.zontreck.eventsbus.Cancellable;
|
||||
import dev.zontreck.eventsbus.Event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Cancellable
|
||||
public class CommandEvent extends Event {
|
||||
public String command;
|
||||
public List<String> arguments = Lists.newArrayList();
|
||||
public String command;
|
||||
public List<String> arguments = new ArrayList<>();
|
||||
|
||||
public CommandEvent(String commandString) {
|
||||
String[] cmds = commandString.split(" ");
|
||||
if (cmds.length > 0) {
|
||||
command = cmds[0];
|
||||
if (cmds.length == 1) return;
|
||||
for (int i = 1; i < cmds.length; i++) {
|
||||
arguments.add(cmds[i]);
|
||||
}
|
||||
public CommandEvent(String commandString) {
|
||||
String[] cmds = commandString.split(" ");
|
||||
if (cmds.length > 0) {
|
||||
command = cmds[0];
|
||||
if (cmds.length == 1) return;
|
||||
for (int i = 1; i < cmds.length; i++) {
|
||||
arguments.add(cmds[i]);
|
||||
}
|
||||
|
||||
} else throw new IllegalArgumentException("The command cannot be empty!");
|
||||
}
|
||||
} else throw new IllegalArgumentException("The command cannot be empty!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,33 +5,26 @@ import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
|||
import dev.zontreck.eventsbus.Bus;
|
||||
|
||||
import java.io.Console;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class ConsolePrompt extends Task {
|
||||
public static final Console console = System.console();
|
||||
public static final Console console = System.console();
|
||||
|
||||
public ConsolePrompt() {
|
||||
super("ConsolePrompt", true);
|
||||
}
|
||||
public ConsolePrompt() {
|
||||
super("ConsolePrompt", true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Print a prompt
|
||||
console.printf("\n" + Terminal.PREFIX + " > ");
|
||||
String commandInput = console.readLine();
|
||||
@Override
|
||||
public void run() {
|
||||
// Print a prompt
|
||||
console.printf("\n" + Terminal.PREFIX + " > ");
|
||||
String commandInput = console.readLine();
|
||||
|
||||
CommandEvent event = new CommandEvent(commandInput);
|
||||
try {
|
||||
if (!Bus.Post(event)) {
|
||||
DelayedExecutorService.getInstance().schedule(new ConsolePrompt(), 2);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
CommandEvent event = new CommandEvent(commandInput);
|
||||
if (!Bus.Post(event)) {
|
||||
DelayedExecutorService.getInstance().schedule(new ConsolePrompt(), 2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,43 +1,38 @@
|
|||
package dev.zontreck.ariaslib.terminal;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TaskBus extends Task
|
||||
{
|
||||
public static List<Task> tasks = new ArrayList<>();
|
||||
public static Task current = null;
|
||||
public class TaskBus extends Task {
|
||||
public static List<Task> tasks = new ArrayList<>();
|
||||
public static Task current = null;
|
||||
|
||||
public TaskBus()
|
||||
{
|
||||
super("TaskBus",true);
|
||||
}
|
||||
public TaskBus() {
|
||||
super("TaskBus", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try{
|
||||
public static void register() {
|
||||
DelayedExecutorService.getInstance().scheduleRepeating(new TaskBus(), 1);
|
||||
}
|
||||
|
||||
if(TaskBus.current == null)
|
||||
{
|
||||
TaskBus.current = tasks.get(0);
|
||||
tasks.remove(0);
|
||||
TaskBus.current.startTask();
|
||||
}else {
|
||||
if(TaskBus.current.isComplete())
|
||||
{
|
||||
TaskBus.current.stopTask();
|
||||
TaskBus.current=null;
|
||||
}
|
||||
}
|
||||
// Don't care about a empty stack exception. We'll just queue this task check back up
|
||||
}catch(Exception e){}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
public static void register()
|
||||
{
|
||||
DelayedExecutorService.getInstance().scheduleRepeating(new TaskBus(), 1);
|
||||
}
|
||||
if (TaskBus.current == null) {
|
||||
TaskBus.current = tasks.get(0);
|
||||
tasks.remove(0);
|
||||
TaskBus.current.startTask();
|
||||
} else {
|
||||
if (TaskBus.current.isComplete()) {
|
||||
TaskBus.current.stopTask();
|
||||
TaskBus.current = null;
|
||||
}
|
||||
}
|
||||
// Don't care about a empty stack exception. We'll just queue this task check back up
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue