General AliLink Refactoring
This commit is contained in:
parent
068a353d0d
commit
7d73a18d17
5 changed files with 37 additions and 42 deletions
|
@ -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<Link> MapToLinkList(List<Map<?, ?>> mapList, Server server) {
|
||||
List<Link> linkList = new ArrayList<Link>();
|
||||
for (Map<?, ?> MapWithLinkData : mapList){
|
||||
linkList.add(new Link((Map<String,String>) MapWithLinkData, server));
|
||||
}
|
||||
return linkList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Map<String,String>> linkMap;
|
||||
private List<Link> 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<Link> MapToLinkList(List<Map<?, ?>> mapList, Server server) {
|
||||
List<Link> linkList = new ArrayList<Link>();
|
||||
for (Map<?, ?> MapWithLinkData : mapList){
|
||||
linkList.add(new Link((Map<String,String>) MapWithLinkData, server));
|
||||
}
|
||||
return linkList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<String,String> 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<String,String> toMap(){
|
||||
|
|
|
@ -17,5 +17,4 @@ public class UnpressTask extends BukkitRunnable {
|
|||
location.getBlock().setData((byte) 14);
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue