diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Function.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Function.java new file mode 100644 index 0000000..fb98e74 --- /dev/null +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Function.java @@ -0,0 +1,30 @@ +package eu.ruekov.ruakij.LinkedBeaconTeleporters; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +import java.util.InvalidPropertiesFormatException; +import java.util.List; +import java.util.Map; +import java.util.Random; + +public class Function { + public static String serialiseBlockLocation(Location loc){ + return loc.getWorld().getName()+";"+loc.getBlockX()+";"+loc.getBlockY()+";"+loc.getBlockZ(); + } + public static Location deserializeBlockLocation(String serialisedLoc) throws InvalidPropertiesFormatException { + try{ + String[] locData = serialisedLoc.split(";"); + + World world = Bukkit.getWorld(locData[0]); + int x = Integer.parseInt(locData[1]); + int y = Integer.parseInt(locData[2]); + int z = Integer.parseInt(locData[3]); + + return new Location(world, x, y, z); + }catch(Exception ex){ + throw new InvalidPropertiesFormatException("Could not deserialize BlockLocation '"+ serialisedLoc +"'"); + } + } +}