From 8421e2799f315bf9292c98a15212f1e54d0e0ae9 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 5 Aug 2016 05:24:28 -0400 Subject: [PATCH] Shoved AliLinks into AliPresents --- plugin.yml | 6 +++- src/alisolarflare/MainPlugin.java | 8 +++++ src/alisolarflare/links/AliLinkSubPlugin.java | 20 +++++++++++ src/alisolarflare/links/Link.java | 20 +++++++++++ src/alisolarflare/links/PressAliLink.java | 28 +++++++++++++++ src/alisolarflare/links/SetAliLink.java | 34 +++++++++++++++++++ src/alisolarflare/links/UnpressTask.java | 20 +++++++++++ .../{ => shulker}/AliShulker.java | 2 +- 8 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 src/alisolarflare/links/AliLinkSubPlugin.java create mode 100644 src/alisolarflare/links/Link.java create mode 100644 src/alisolarflare/links/PressAliLink.java create mode 100644 src/alisolarflare/links/SetAliLink.java create mode 100644 src/alisolarflare/links/UnpressTask.java rename src/alisolarflare/{ => shulker}/AliShulker.java (97%) diff --git a/plugin.yml b/plugin.yml index 868d3a2..d48f733 100644 --- a/plugin.yml +++ b/plugin.yml @@ -4,4 +4,8 @@ version: 1.0.0 commands: alishulker: - description: Spawns a shulker at player location. /Alishulker \ No newline at end of file + description: Spawns a shulker at player location. /Alishulker + pressalilink: + description: Presses an Ali Link. /pressalilink |frequency| + setalilink: + description: Creates an Ali Link. /setalilink |frequency| \ No newline at end of file diff --git a/src/alisolarflare/MainPlugin.java b/src/alisolarflare/MainPlugin.java index bd92fca..e6b0f8a 100644 --- a/src/alisolarflare/MainPlugin.java +++ b/src/alisolarflare/MainPlugin.java @@ -2,10 +2,18 @@ package alisolarflare; import org.bukkit.plugin.java.JavaPlugin; +import alisolarflare.links.AliLinkSubPlugin; +import alisolarflare.shulker.AliShulker; + public class MainPlugin extends JavaPlugin{ public void onEnable(){ + registerSubPlugins(); registerCommands(); } + public void registerSubPlugins(){ + AliLinkSubPlugin alilinksubplugin = new AliLinkSubPlugin(this); + alilinksubplugin.register(); + } public void registerCommands(){ getCommand("alishulker").setExecutor(new AliShulker()); } diff --git a/src/alisolarflare/links/AliLinkSubPlugin.java b/src/alisolarflare/links/AliLinkSubPlugin.java new file mode 100644 index 0000000..cf38cf9 --- /dev/null +++ b/src/alisolarflare/links/AliLinkSubPlugin.java @@ -0,0 +1,20 @@ +package alisolarflare.links; + +import java.util.ArrayList; +import java.util.List; + +import alisolarflare.MainPlugin; + +public class AliLinkSubPlugin{ + public List linkList = new ArrayList(); + public MainPlugin plugin; + public AliLinkSubPlugin(MainPlugin plugin){ + this.plugin = plugin; + } + public void register(){ + plugin.getCommand("pressalilink").setExecutor(new PressAliLink(this)); + plugin.getCommand("setalilink").setExecutor(new SetAliLink(this)); + + } + +} diff --git a/src/alisolarflare/links/Link.java b/src/alisolarflare/links/Link.java new file mode 100644 index 0000000..16ae533 --- /dev/null +++ b/src/alisolarflare/links/Link.java @@ -0,0 +1,20 @@ +package alisolarflare.links; + +import org.bukkit.Location; +import org.bukkit.Material; + +public class Link { + static AliLinkSubPlugin plugin; + String frequency; + Location location; + + public Link(AliLinkSubPlugin plugin, String frequency, Location location){ + this.frequency = frequency; + this.location = location; + } + public void press() { + location.getBlock().setType(Material.REDSTONE_BLOCK); + UnpressTask unPressTask = new UnpressTask(location); + unPressTask.runTaskTimer(plugin.plugin, 2, 1); + } +} diff --git a/src/alisolarflare/links/PressAliLink.java b/src/alisolarflare/links/PressAliLink.java new file mode 100644 index 0000000..40261dd --- /dev/null +++ b/src/alisolarflare/links/PressAliLink.java @@ -0,0 +1,28 @@ +package alisolarflare.links; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class PressAliLink implements CommandExecutor{ + private AliLinkSubPlugin subplugin; + public PressAliLink(AliLinkSubPlugin subplugin){ + this.subplugin = subplugin; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args == null){ + sender.sendMessage("You must specify a link frequency"); + sender.sendMessage("/pressalilink [frequency]"); + } + for (Link link: subplugin.linkList){ + for (String inputlink: args){ + if(inputlink.equals(link.frequency)){ + link.press(); + } + } + } + return false; + } + +} diff --git a/src/alisolarflare/links/SetAliLink.java b/src/alisolarflare/links/SetAliLink.java new file mode 100644 index 0000000..cb59fb0 --- /dev/null +++ b/src/alisolarflare/links/SetAliLink.java @@ -0,0 +1,34 @@ +package alisolarflare.links; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SetAliLink implements CommandExecutor{ + AliLinkSubPlugin subplugin; + public SetAliLink(AliLinkSubPlugin plugin){ + this.subplugin = plugin; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args == null){ + sender.sendMessage("You must specify a link frequency"); + sender.sendMessage("/pressalilink [name]"); + } + if (!(sender instanceof Player)){ + sender.sendMessage("You must be a player to use this command!"); + } + Player player = (Player) sender; + if (args[1] == null || args[2] == null || args[3] == null){ + subplugin.linkList.add(new Link(subplugin, args[0], player.getLocation())); + } + if (StringUtils.isNumericSpace(args[1]) && StringUtils.isNumericSpace(args[2]) && StringUtils.isNumericSpace(args[3])){ + subplugin.linkList.add(new Link(subplugin, args[0],new Location(player.getWorld(), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3])))); + } + return false; + } + +} diff --git a/src/alisolarflare/links/UnpressTask.java b/src/alisolarflare/links/UnpressTask.java new file mode 100644 index 0000000..4794ef6 --- /dev/null +++ b/src/alisolarflare/links/UnpressTask.java @@ -0,0 +1,20 @@ +package alisolarflare.links; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.scheduler.BukkitRunnable; + +public class UnpressTask extends BukkitRunnable { + private Location location; + public UnpressTask(Location location){ + this.location = location; + } + + @SuppressWarnings("deprecation") + @Override + public void run() { + location.getBlock().setType(Material.STAINED_CLAY); + location.getBlock().setData((byte) 14); + } + +} diff --git a/src/alisolarflare/AliShulker.java b/src/alisolarflare/shulker/AliShulker.java similarity index 97% rename from src/alisolarflare/AliShulker.java rename to src/alisolarflare/shulker/AliShulker.java index 91efc03..5e8ee83 100644 --- a/src/alisolarflare/AliShulker.java +++ b/src/alisolarflare/shulker/AliShulker.java @@ -1,4 +1,4 @@ -package alisolarflare; +package alisolarflare.shulker; import org.bukkit.Location; import org.bukkit.command.Command;