From 7d73a18d175c104f1b1105af3f510b5f951c7ab9 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 30 Nov 2016 23:42:04 -0500 Subject: [PATCH] General AliLink Refactoring --- .../components/alilinks/AliLinkAPI.java | 11 +++++ .../components/alilinks/AliLinkComponent.java | 23 ---------- .../components/alilinks/commands/AliLink.java | 2 +- .../components/alilinks/entities/Link.java | 42 +++++++++++-------- .../alilinks/tasks/UnpressTask.java | 1 - 5 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/alisolarflare/components/alilinks/AliLinkAPI.java b/src/alisolarflare/components/alilinks/AliLinkAPI.java index d957919..d5a990a 100644 --- a/src/alisolarflare/components/alilinks/AliLinkAPI.java +++ b/src/alisolarflare/components/alilinks/AliLinkAPI.java @@ -1,9 +1,12 @@ package alisolarflare.components.alilinks; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -57,4 +60,12 @@ public class AliLinkAPI { linkList.add(link); return true; } + @SuppressWarnings("unchecked") + private List MapToLinkList(List> mapList, Server server) { + List linkList = new ArrayList(); + for (Map MapWithLinkData : mapList){ + linkList.add(new Link((Map) MapWithLinkData, server)); + } + return linkList; + } } diff --git a/src/alisolarflare/components/alilinks/AliLinkComponent.java b/src/alisolarflare/components/alilinks/AliLinkComponent.java index 8b2e98f..5a14d08 100644 --- a/src/alisolarflare/components/alilinks/AliLinkComponent.java +++ b/src/alisolarflare/components/alilinks/AliLinkComponent.java @@ -1,36 +1,13 @@ package alisolarflare.components.alilinks; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.bukkit.Server; import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.architecture.Component; import alisolarflare.components.alilinks.commands.AliLink; -import alisolarflare.components.alilinks.entities.Link; public class AliLinkComponent extends Component { - - private List> linkMap; - private List linkList; @Override public void register(JavaPlugin plugin) { - this.linkList = MapToLinkList(plugin.getConfig().getMapList("aliLinkList"), plugin.getServer()); - for (Link link: linkList){ - linkMap.add(link.toMap()); - } - registerCommand(plugin, new AliLink(plugin)); - - } - @SuppressWarnings("unchecked") - private List MapToLinkList(List> mapList, Server server) { - List linkList = new ArrayList(); - for (Map MapWithLinkData : mapList){ - linkList.add(new Link((Map) MapWithLinkData, server)); - } - return linkList; } } diff --git a/src/alisolarflare/components/alilinks/commands/AliLink.java b/src/alisolarflare/components/alilinks/commands/AliLink.java index 2bd3f83..20884db 100644 --- a/src/alisolarflare/components/alilinks/commands/AliLink.java +++ b/src/alisolarflare/components/alilinks/commands/AliLink.java @@ -21,7 +21,7 @@ public class AliLink extends PlayerCommand{ case "press": return AliLinkAPI.sendPressEvent(player, inputFrequencies, plugin); case "set": - AliLinkAPI.createAliLink(player, inputFrequencies); + return AliLinkAPI.createAliLink(player, inputFrequencies); default: return false; } diff --git a/src/alisolarflare/components/alilinks/entities/Link.java b/src/alisolarflare/components/alilinks/entities/Link.java index a2ea8f1..7fe08cf 100644 --- a/src/alisolarflare/components/alilinks/entities/Link.java +++ b/src/alisolarflare/components/alilinks/entities/Link.java @@ -19,23 +19,15 @@ public class Link{ public int y; public int z; - public Link (String frequency, World world, int x, int y, int z){ - this.frequency = frequency; - this.world = world; - this.x = x; - this.y = y; - this.z = z; + /**Constructor for copying links*/ + public Link(Link link){ + this.frequency = link.frequency; + this.world = link.world; + this.x = link.x; + this.y = link.y; + this.z = link.z; } - - public Link(String frequency, Location location, Server server){ - this.frequency = frequency; - this.world = server.getWorld(location.getWorld().getName()); - this.x = location.getBlockX(); - this.y = location.getBlockY(); - this.z = location.getBlockZ(); - //plugin.plugin.getConfig().set("frequency", 10); - } - + /**Constructor for deserialization*/ public Link(Map linkFromMap, Server server){ this.frequency = linkFromMap.get("frequency"); this.world = server.getWorld(linkFromMap.get("world")); @@ -43,6 +35,22 @@ public class Link{ this.y = Integer.parseInt(linkFromMap.get("y")); this.z = Integer.parseInt(linkFromMap.get("z")); } + /**Constructor for Location inputs*/ + public Link(String frequency, Location location){ + this.frequency = frequency; + this.world = location.getWorld(); + this.x = location.getBlockX(); + this.y = location.getBlockY(); + this.z = location.getBlockZ(); + } + /**Pure Constructor*/ + public Link(String frequency, World world, int x, int y, int z){ + this.frequency = frequency; + this.world = world; + this.x = x; + this.y = y; + this.z = z; + } /** * Activates the Ali-Link @@ -51,7 +59,7 @@ public class Link{ public void press(JavaPlugin plugin) { Location location = new Location(this.world, this.x, this.y, this.z); location.getBlock().setType(Material.REDSTONE_BLOCK); - new UnpressTask(location).runTaskTimer(plugin, 2, 1); + new UnpressTask(location).runTaskLater(plugin, 2); } public Map toMap(){ diff --git a/src/alisolarflare/components/alilinks/tasks/UnpressTask.java b/src/alisolarflare/components/alilinks/tasks/UnpressTask.java index 8820778..38a06b0 100644 --- a/src/alisolarflare/components/alilinks/tasks/UnpressTask.java +++ b/src/alisolarflare/components/alilinks/tasks/UnpressTask.java @@ -17,5 +17,4 @@ public class UnpressTask extends BukkitRunnable { location.getBlock().setData((byte) 14); this.cancel(); } - }