From 068a353d0d3f23c4f3e4fe6a15832842537a14c3 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 30 Nov 2016 22:58:36 -0500 Subject: [PATCH] Created AliLinkAPI --- .../components/alilinks/AliLinkAPI.java | 60 ++++++++++++++++ .../components/alilinks/AliLinkComponent.java | 4 +- .../components/alilinks/commands/AliLink.java | 70 +++---------------- 3 files changed, 71 insertions(+), 63 deletions(-) create mode 100644 src/alisolarflare/components/alilinks/AliLinkAPI.java diff --git a/src/alisolarflare/components/alilinks/AliLinkAPI.java b/src/alisolarflare/components/alilinks/AliLinkAPI.java new file mode 100644 index 0000000..d957919 --- /dev/null +++ b/src/alisolarflare/components/alilinks/AliLinkAPI.java @@ -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 linkList; + /**"Usage: /pressalilink "*/ + 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 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; + } +} diff --git a/src/alisolarflare/components/alilinks/AliLinkComponent.java b/src/alisolarflare/components/alilinks/AliLinkComponent.java index 78095d6..8b2e98f 100644 --- a/src/alisolarflare/components/alilinks/AliLinkComponent.java +++ b/src/alisolarflare/components/alilinks/AliLinkComponent.java @@ -13,8 +13,8 @@ import alisolarflare.components.alilinks.entities.Link; public class AliLinkComponent extends Component { - private List linkList; private List> linkMap; + private List 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") diff --git a/src/alisolarflare/components/alilinks/commands/AliLink.java b/src/alisolarflare/components/alilinks/commands/AliLink.java index 362a8ab..2bd3f83 100644 --- a/src/alisolarflare/components/alilinks/commands/AliLink.java +++ b/src/alisolarflare/components/alilinks/commands/AliLink.java @@ -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 linkList; - public AliLink(JavaPlugin plugin, List 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 "*/ - private boolean press(Player player, String alias, String[] inputFrequencies) { - if (inputFrequencies.length == 0) { - player.sendMessage("You must specify a link frequency"); - return false; - } - - List inputFrequencyList= Arrays.asList(inputFrequencies); - for (Link link : linkList) { - if(inputFrequencyList.contains(link.frequency)){ - link.press(plugin); - } - } - - player.sendMessage("Link pressed!"); - - return true; - } + - /**Usage: /setalilink [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; - } + }