-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/roiex/plugins/cmdhelper/CommandConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.roiex.plugins.cmdhelper; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
@FunctionalInterface | ||
public interface CommandConsumer { | ||
boolean runAction(CommandSender sender, Command command, String label, String[] args); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/roiex/plugins/cmdhelper/CommandRouter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.roiex.plugins.cmdhelper; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class CommandRouter implements CommandExecutor { | ||
|
||
private Map<String, CommandConsumer> routes = new HashMap<>(); | ||
|
||
public void addRoute(String pattern, CommandConsumer consumer){ | ||
routes.put(pattern, consumer); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
boolean executed = false; | ||
boolean success = true; | ||
for(Map.Entry<String, CommandConsumer> entry : routes.entrySet()){ | ||
if(StructureParser.matches(entry.getKey(), args, sender)){ | ||
executed = true; | ||
success &= entry.getValue().runAction(sender, command, label, args); | ||
} | ||
} | ||
return success && executed; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters