Implemented Block-Location de/serialisation
This commit is contained in:
		
							parent
							
								
									2f621d7a9b
								
							
						
					
					
						commit
						da05087876
					
				@ -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 +"'");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user