Created AliLinkAPI

This commit is contained in:
alisolarflare 2016-11-30 22:58:36 -05:00
parent e605f72b4b
commit 068a353d0d
3 changed files with 71 additions and 63 deletions

View file

@ -0,0 +1,60 @@
package alisolarflare.components.alilinks;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.components.alilinks.entities.Link;
public class AliLinkAPI {
private static List<Link> linkList;
/**"Usage: /pressalilink <frequency>"*/
public static boolean sendPressEvent(CommandSender sender, String[] inputFrequencies, JavaPlugin plugin) {
if (inputFrequencies.length == 0) {
sender.sendMessage("You must specify a link frequency");
return false;
}
List<String> inputFrequencyList= Arrays.asList(inputFrequencies);
for (Link link : linkList) {
if(inputFrequencyList.contains(link.frequency)){
link.press(plugin);
}
}
sender.sendMessage("Link pressed!");
return true;
}
public static boolean createAliLink(Player player, String[] args) {
if (args == null || args.length < 1) {
player.sendMessage("You must specify a link frequency");
player.sendMessage("/pressalilink [name]");
return false;
}
String frequency = args[0];
World world = player.getWorld();
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
if (args.length > 4) {
boolean arg1isNumber = StringUtils.isNumericSpace(args[1]);
boolean arg2isNumber = StringUtils.isNumericSpace(args[2]);
boolean arg3isNumber = StringUtils.isNumericSpace(args[3]);
if (arg1isNumber && arg2isNumber && arg3isNumber) {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
}
}
Link link = new Link(frequency, world, x, y, z);
linkList.add(link);
return true;
}
}

View file

@ -13,8 +13,8 @@ import alisolarflare.components.alilinks.entities.Link;
public class AliLinkComponent extends Component {
private List<Link> linkList;
private List<Map<String,String>> linkMap;
private List<Link> linkList;
@Override
public void register(JavaPlugin plugin) {
this.linkList = MapToLinkList(plugin.getConfig().getMapList("aliLinkList"), plugin.getServer());
@ -22,7 +22,7 @@ public class AliLinkComponent extends Component {
linkMap.add(link.toMap());
}
registerCommand(plugin, new AliLink(plugin, linkList));
registerCommand(plugin, new AliLink(plugin));
}
@SuppressWarnings("unchecked")

View file

@ -1,86 +1,34 @@
package alisolarflare.components.alilinks.commands;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.commands.PlayerCommand;
import alisolarflare.components.alilinks.entities.Link;
import alisolarflare.components.alilinks.AliLinkAPI;
public class AliLink extends PlayerCommand{
private JavaPlugin plugin;
private List<Link> linkList;
public AliLink(JavaPlugin plugin, List<Link> linkList) {
public AliLink(JavaPlugin plugin) {
this.plugin = plugin;
this.linkList = linkList;
}
@Override
public boolean OnCommand(Player player, String alias, String[] args) {
if(args.length < 1)
public boolean OnCommand(Player player, String alias, String[] inputFrequencies) {
if(inputFrequencies.length < 1)
return false;
switch (args[0].toLowerCase()){
switch (inputFrequencies[0].toLowerCase()){
case "press":
return press(player, alias, args);
return AliLinkAPI.sendPressEvent(player, inputFrequencies, plugin);
case "set":
return set(player, alias, args);
AliLinkAPI.createAliLink(player, inputFrequencies);
default:
return false;
}
}
/**"Usage: /pressalilink <frequency>"*/
private boolean press(Player player, String alias, String[] inputFrequencies) {
if (inputFrequencies.length == 0) {
player.sendMessage("You must specify a link frequency");
return false;
}
List<String> inputFrequencyList= Arrays.asList(inputFrequencies);
for (Link link : linkList) {
if(inputFrequencyList.contains(link.frequency)){
link.press(plugin);
}
}
player.sendMessage("Link pressed!");
return true;
}
/**Usage: /setalilink <frequency> [x] [y] [z]*/
public boolean set(Player player, String label, String[] args) {
if (args == null || args.length < 1) {
player.sendMessage("You must specify a link frequency");
player.sendMessage("/pressalilink [name]");
return false;
}
String frequency = args[0];
World world = player.getWorld();
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
if (args.length > 4) {
boolean arg1isNumber = StringUtils.isNumericSpace(args[1]);
boolean arg2isNumber = StringUtils.isNumericSpace(args[2]);
boolean arg3isNumber = StringUtils.isNumericSpace(args[3]);
if (arg1isNumber && arg2isNumber && arg3isNumber) {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
}
}
Link link = new Link(frequency, world, x, y, z);
linkList.add(link);
return true;
}
}