Completely rewrote AliLink code
This commit is contained in:
parent
0df59ba8d4
commit
e089d8ff12
4 changed files with 85 additions and 122 deletions
|
@ -1,6 +1,8 @@
|
||||||
package alisolarflare.components.alilinks;
|
package alisolarflare.components.alilinks;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -10,24 +12,26 @@ import alisolarflare.components.alilinks.commands.SetAliLink;
|
||||||
import alisolarflare.components.alilinks.entities.Link;
|
import alisolarflare.components.alilinks.entities.Link;
|
||||||
|
|
||||||
public class AliLinkComponent extends Component {
|
public class AliLinkComponent extends Component {
|
||||||
private SetAliLink setAliLink;
|
|
||||||
|
|
||||||
|
private List<Link> linkList;
|
||||||
|
private List<Map<String,String>> linkData;
|
||||||
@Override
|
@Override
|
||||||
public void register(JavaPlugin plugin) {
|
public void register(JavaPlugin plugin) {
|
||||||
setAliLink = new SetAliLink(plugin);
|
this.linkList = MapToLinkList(plugin.getConfig().getMapList("aliLinkList"));
|
||||||
|
for (Link link: linkList){
|
||||||
|
linkData.add(link.toMap());
|
||||||
|
}
|
||||||
|
|
||||||
registerCommand(plugin, new PressAliLink(plugin, setAliLink));
|
registerCommand(plugin, new PressAliLink(plugin, linkList));
|
||||||
registerCommand(plugin, setAliLink);
|
registerCommand(plugin, new SetAliLink(plugin.getConfig(), linkList, linkData));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveLinkList(JavaPlugin plugin) {
|
|
||||||
plugin.getConfig().set("aliLinkList", setAliLink.linkList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<Link> loadLinkList(JavaPlugin plugin) {
|
private List<Link> MapToLinkList(List<Map<?, ?>> mapList) {
|
||||||
return (List<Link>) plugin.getConfig().getList("aliLinkList");
|
List<Link> linkList = new ArrayList<Link>();
|
||||||
|
for (Map<?, ?> MapWithLinkData : mapList){
|
||||||
|
linkList.add(new Link((Map<String,String>) MapWithLinkData));
|
||||||
|
}
|
||||||
|
return linkList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package alisolarflare.components.alilinks.commands;
|
package alisolarflare.components.alilinks.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -8,23 +10,23 @@ import alisolarflare.components.alilinks.entities.Link;
|
||||||
|
|
||||||
public class PressAliLink extends PlayerCommand {
|
public class PressAliLink extends PlayerCommand {
|
||||||
private JavaPlugin plugin;
|
private JavaPlugin plugin;
|
||||||
private SetAliLink setAliLink;
|
private List<Link> linkList;
|
||||||
|
|
||||||
public PressAliLink(JavaPlugin plugin, SetAliLink setAliLink) {
|
public PressAliLink(JavaPlugin plugin, List<Link> linkList) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.setAliLink = setAliLink;
|
this.linkList = linkList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
||||||
|
|
||||||
sender.getServer().broadcastMessage(setAliLink.linkList.toString() + "over.");
|
sender.getServer().broadcastMessage(linkList.toString() + "over.");
|
||||||
|
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
sender.sendMessage("You must specify a link frequency");
|
sender.sendMessage("You must specify a link frequency");
|
||||||
sender.sendMessage("/pressalilink [frequency]");
|
sender.sendMessage("/pressalilink [frequency]");
|
||||||
}
|
}
|
||||||
for (Link link : setAliLink.linkList) {
|
for (Link link : linkList) {
|
||||||
for (String inputlink : args) {
|
for (String inputlink : args) {
|
||||||
if (inputlink.equals(link.frequency)) {
|
if (inputlink.equals(link.frequency)) {
|
||||||
link.press(plugin);
|
link.press(plugin);
|
||||||
|
@ -33,9 +35,4 @@ public class PressAliLink extends PlayerCommand {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,122 +2,62 @@ package alisolarflare.components.alilinks.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import alisolarflare.components.PlayerCommand;
|
import alisolarflare.components.PlayerCommand;
|
||||||
import alisolarflare.components.alilinks.AliLinkComponent;
|
|
||||||
import alisolarflare.components.alilinks.entities.Link;
|
import alisolarflare.components.alilinks.entities.Link;
|
||||||
|
|
||||||
/**
|
|
||||||
* This class manages the command /SetAliLink <frequency> [x] [y] [z]. This command creates an Ali-Link, a location in a world that when called on by {@link PressAliLink}, creates a temporary redstone
|
|
||||||
* block, enabling wireless redstone
|
|
||||||
*
|
|
||||||
* @see PressAliLink
|
|
||||||
* @author Alisolarflare
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SetAliLink extends PlayerCommand {
|
public class SetAliLink extends PlayerCommand {
|
||||||
public List<Link> linkList = new ArrayList<Link>();
|
public List<Link> linkList;
|
||||||
AliLinkComponent subplugin;
|
public List<Map<String, String>> linkData;
|
||||||
private JavaPlugin plugin;
|
private FileConfiguration config;
|
||||||
|
|
||||||
/**
|
public SetAliLink(FileConfiguration config, List<Link> linkList, List<Map<String, String>> linkData) {
|
||||||
* Constructs the SetAliLink class
|
this.linkList = linkList;
|
||||||
*
|
this.linkData = linkData;
|
||||||
* @param plugin
|
this.config = config;
|
||||||
* The plugin that contains the configuration file of SetAliLink
|
|
||||||
*/
|
|
||||||
public SetAliLink(JavaPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This command creates an Ali-Link which, when activated by the command /PressAliLink, creates a temporary redstone block if and only if /PressAliLink [frequency] matches the frequency saved when
|
|
||||||
* /SetAliLink [frequency] is called.
|
|
||||||
*
|
|
||||||
* @see Class#PressAliLink
|
|
||||||
* @param sender
|
|
||||||
* Player who sent the command
|
|
||||||
* @param command
|
|
||||||
* Command Object created
|
|
||||||
* @param label
|
|
||||||
* Name of the command
|
|
||||||
* @param args
|
|
||||||
* Arguments: [frequency] [x-coordinate] [y-coordinate] [z-coordinate], where the coordinates point to the intended location of the Ali-Link
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
||||||
sender.sendMessage("you pressed shit");
|
Player player = (Player) sender;
|
||||||
|
player.sendMessage("you pressed");
|
||||||
if (args == null || args.length < 1) {
|
if (args == null || args.length < 1) {
|
||||||
sender.sendMessage("You must specify a link frequency");
|
sender.sendMessage("You must specify a link frequency");
|
||||||
sender.sendMessage("/pressalilink [name]");
|
sender.sendMessage("/pressalilink [name]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
|
||||||
if (args.length < 4) {
|
|
||||||
player.sendMessage("short");
|
|
||||||
linkList.add(new Link(args[0], player.getLocation()));
|
|
||||||
save(player);
|
|
||||||
player.sendMessage("end");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (StringUtils.isNumericSpace(args[1]) && StringUtils.isNumericSpace(args[2])
|
|
||||||
&& StringUtils.isNumericSpace(args[3])) {
|
|
||||||
player.sendMessage("CUUUSTOM");
|
|
||||||
linkList.add(new Link(args[0], new Location(player.getWorld(), Double.parseDouble(args[1]),
|
|
||||||
Double.parseDouble(args[2]), Double.parseDouble(args[3]))));
|
|
||||||
save(player);
|
|
||||||
player.sendMessage("FINISHED");
|
|
||||||
} else {
|
|
||||||
player.sendMessage("UNCUSTOOM");
|
|
||||||
linkList.add(new Link(args[0], player.getLocation()));
|
|
||||||
save(player);
|
|
||||||
player.sendMessage("UNFINISHED");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
String frequency = args[0];
|
||||||
* Tries to save the entire SetAliLink class into memory, which includes all of the current Ali-links saved and in use.
|
World world = player.getWorld();
|
||||||
*
|
Double x = player.getLocation().getX();
|
||||||
* @param player
|
Double y = player.getLocation().getY();
|
||||||
*/
|
Double z = player.getLocation().getZ();
|
||||||
private void save(Player player) {
|
|
||||||
player.sendMessage("SAAAVING");
|
|
||||||
player.sendMessage("SAVE FAILED: TELL ALI TO FIX THE SAVE AND UN-COMMENT THE PARAGRAPH SHE COMMENTED");
|
|
||||||
player.sendMessage("Link will only last until next server restart");
|
|
||||||
return;
|
|
||||||
/*
|
|
||||||
* subplugin.plugin.getConfig().set("aliLinkList", subplugin.linkList); try { player.sendMessage("SAVIN"); subplugin.plugin.saveConfig(); player.sendMessage("GOOD SAVE"); } catch (Exception e)
|
|
||||||
* { player.sendMessage("YOU FUCKED STUFF UP"); // TODO Auto-generated catch block e.printStackTrace(); }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (args.length > 4) {
|
||||||
* Attempts to load the previous saved state of AliLinks, from the plugin configuration file
|
boolean arg1isNumber = StringUtils.isNumericSpace(args[1]);
|
||||||
*/
|
boolean arg2isNumber = StringUtils.isNumericSpace(args[2]);
|
||||||
@SuppressWarnings("unchecked")
|
boolean arg3isNumber = StringUtils.isNumericSpace(args[3]);
|
||||||
private void load() {
|
if (arg1isNumber && arg2isNumber && arg3isNumber) {
|
||||||
try {
|
x = Double.parseDouble(args[1]);
|
||||||
linkList = (List<Link>) plugin.getConfig().getList("aliLinkList");
|
y = Double.parseDouble(args[2]);
|
||||||
if (linkList == null || linkList.isEmpty()) {
|
z = Double.parseDouble(args[3]);
|
||||||
linkList = new ArrayList<Link>();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
Link link = new Link(frequency, world, x, y, z);
|
||||||
|
linkList.add(link);
|
||||||
|
linkData.add(link.toMap());
|
||||||
|
saveLinkList();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
private void saveLinkList(){
|
||||||
@Override
|
config.set("aliLinkList", linkData);
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,29 @@
|
||||||
package alisolarflare.components.alilinks.entities;
|
package alisolarflare.components.alilinks.entities;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import alisolarflare.components.alilinks.tasks.UnpressTask;
|
import alisolarflare.components.alilinks.tasks.UnpressTask;
|
||||||
|
|
||||||
public class Link implements Serializable{
|
public class Link{
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
public String frequency;
|
public String frequency;
|
||||||
public String world;
|
public String world;
|
||||||
public String x;
|
public String x;
|
||||||
public String y;
|
public String y;
|
||||||
public String z;
|
public String 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, Location location){
|
public Link(String frequency, Location location){
|
||||||
this.frequency = frequency;
|
this.frequency = frequency;
|
||||||
|
@ -28,6 +33,13 @@ public class Link implements Serializable{
|
||||||
this.z = "" + location.getBlockZ();
|
this.z = "" + location.getBlockZ();
|
||||||
//plugin.plugin.getConfig().set("frequency", 10);
|
//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;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Activates the Ali-Link
|
* Activates the Ali-Link
|
||||||
* @param plugin
|
* @param plugin
|
||||||
|
@ -38,4 +50,14 @@ public class Link implements Serializable{
|
||||||
UnpressTask unPressTask = new UnpressTask(location);
|
UnpressTask unPressTask = new UnpressTask(location);
|
||||||
unPressTask.runTaskTimer(plugin, 2, 1);
|
unPressTask.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);
|
||||||
|
return linkAsMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue