From da05087876e7304cf7892e52fa0eba2331eac869 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Sun, 9 May 2021 22:47:10 +0200 Subject: [PATCH] Implemented Block-Location de/serialisation --- .../LinkedBeaconTeleporters/Function.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Function.java 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 +"'"); + } + } +}