Cleaned up AliLink Code
This commit is contained in:
parent
21bb3a03f9
commit
7886c052e0
4 changed files with 47 additions and 41 deletions
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import alisolarflare.components.Component;
|
||||
|
@ -17,7 +18,7 @@ public class AliLinkComponent extends Component {
|
|||
private List<Map<String,String>> linkData;
|
||||
@Override
|
||||
public void register(JavaPlugin plugin) {
|
||||
this.linkList = MapToLinkList(plugin.getConfig().getMapList("aliLinkList"));
|
||||
this.linkList = MapToLinkList(plugin.getConfig().getMapList("aliLinkList"), plugin.getServer());
|
||||
for (Link link: linkList){
|
||||
linkData.add(link.toMap());
|
||||
}
|
||||
|
@ -27,10 +28,10 @@ public class AliLinkComponent extends Component {
|
|||
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Link> MapToLinkList(List<Map<?, ?>> mapList) {
|
||||
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));
|
||||
linkList.add(new Link((Map<String,String>) MapWithLinkData, server));
|
||||
}
|
||||
return linkList;
|
||||
}
|
||||
|
|
|
@ -18,14 +18,15 @@ public class PressAliLink extends PlayerCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
public boolean OnCommand(CommandSender sender, String label, String[] inputFrequencies) {
|
||||
if (inputFrequencies.length < 1) {
|
||||
sender.sendMessage("You must specify a link frequency");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Link link : linkList) {
|
||||
for (String inputlink : args) {
|
||||
if (inputlink.equals(link.frequency)) {
|
||||
for (String frequency : inputFrequencies) {
|
||||
if (frequency.equals(link.frequency)) {
|
||||
link.press(plugin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,18 +35,18 @@ public class SetAliLink extends PlayerCommand {
|
|||
|
||||
String frequency = args[0];
|
||||
World world = player.getWorld();
|
||||
Double x = player.getLocation().getX();
|
||||
Double y = player.getLocation().getY();
|
||||
Double z = player.getLocation().getZ();
|
||||
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 = Double.parseDouble(args[1]);
|
||||
y = Double.parseDouble(args[2]);
|
||||
z = Double.parseDouble(args[3]);
|
||||
x = Integer.parseInt(args[1]);
|
||||
y = Integer.parseInt(args[2]);
|
||||
z = Integer.parseInt(args[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Map;
|
|||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -12,52 +13,55 @@ import alisolarflare.components.alilinks.tasks.UnpressTask;
|
|||
|
||||
public class Link{
|
||||
public String frequency;
|
||||
public String world;
|
||||
public String x;
|
||||
public String y;
|
||||
public String z;
|
||||
public World world;
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
public Link(Map<String,String> linkFromMap){
|
||||
this.frequency = linkFromMap.get("frequency");
|
||||
this.world = linkFromMap.get("world");
|
||||
this.x = linkFromMap.get("x");
|
||||
this.y = linkFromMap.get("y");
|
||||
this.z = linkFromMap.get("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;
|
||||
}
|
||||
|
||||
public Link(String frequency, Location location){
|
||||
public Link(String frequency, Location location, Server server){
|
||||
this.frequency = frequency;
|
||||
this.world = location.getWorld().getName();
|
||||
this.x = "" + location.getBlockX();
|
||||
this.y = "" + location.getBlockY();
|
||||
this.z = "" + location.getBlockZ();
|
||||
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);
|
||||
}
|
||||
public Link (String frequency, World world, Double x, Double y, Double z){
|
||||
this.frequency = frequency;
|
||||
this.world = world.getName();
|
||||
this.x = "" + x;
|
||||
this.y = "" + y;
|
||||
this.z = "" + z;
|
||||
|
||||
public Link(Map<String,String> linkFromMap, Server server){
|
||||
this.frequency = linkFromMap.get("frequency");
|
||||
this.world = server.getWorld(linkFromMap.get("world"));
|
||||
this.x = Integer.parseInt(linkFromMap.get("x"));
|
||||
this.y = Integer.parseInt(linkFromMap.get("y"));
|
||||
this.z = Integer.parseInt(linkFromMap.get("z"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the Ali-Link
|
||||
* @param plugin
|
||||
*/
|
||||
public void press(JavaPlugin plugin) {
|
||||
Location location = new Location(plugin.getServer().getWorld(world), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z));
|
||||
Location location = new Location(this.world, this.x, this.y, this.z);
|
||||
location.getBlock().setType(Material.REDSTONE_BLOCK);
|
||||
UnpressTask unPressTask = new UnpressTask(location);
|
||||
unPressTask.runTaskTimer(plugin, 2, 1);
|
||||
new UnpressTask(location).runTaskTimer(plugin, 2, 1);
|
||||
}
|
||||
|
||||
public Map<String,String> toMap(){
|
||||
Map<String, String> linkAsMap = new HashMap<String,String>();
|
||||
|
||||
linkAsMap.put("frequency", frequency);
|
||||
linkAsMap.put("world", world);
|
||||
linkAsMap.put("x", x);
|
||||
linkAsMap.put("y", y);
|
||||
linkAsMap.put("z", z);
|
||||
linkAsMap.put("world", world.getName());
|
||||
linkAsMap.put("x", Integer.toString(this.x));
|
||||
linkAsMap.put("y", Integer.toString(this.y));
|
||||
linkAsMap.put("z", Integer.toString(this.z));
|
||||
|
||||
return linkAsMap;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue