Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package me.Ghoul.HealingStone;
  2.  
  3. import java.util.UUID;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.World;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.block.BlockPlaceEvent;
  15.  
  16. public class LocationSerializer implements Listener {
  17.  
  18. Hs plugin;
  19.  
  20. public LocationSerializer(final Hs plugin) {
  21.  
  22. this.plugin = plugin;
  23. Bukkit.getPluginManager().registerEvents(this, plugin);
  24.  
  25. }
  26.  
  27. public String prefix = (ChatColor.GOLD + "[" + ChatColor.GREEN + "Hs" + ChatColor.GOLD + "]");
  28.  
  29. @EventHandler
  30. public void onPlace(BlockPlaceEvent event) {
  31.  
  32. Player player = event.getPlayer();
  33. Block block = event.getBlockPlaced();
  34.  
  35. if (block.getType().equals(Material.getMaterial(plugin.getConfig().getString("Healingstone.BlockType")))) {
  36. plugin.getConfig().set("HealingBlocks", LocationSerializer.getSerializedLocation(block.getLocation()));
  37. player.sendMessage(prefix + " " + ChatColor.GOLD + "You Just Placed A Healing Block");
  38.  
  39. }
  40. }
  41.  
  42. String serializeLocation(Location loc) {
  43. return loc.getWorld().getName() + "," + loc.getBlockX() + "," + "," + loc.getBlockY() + "," + loc.getBlockZ();
  44. }
  45.  
  46. public static Location getDeserializedLocation(String s) {// Converts String -> Location
  47. String[] parts = s.split(";"); // If you changed the semicolon you must change it here too
  48. double x = Double.parseDouble(parts[0]);
  49. double y = Double.parseDouble(parts[1]);
  50. double z = Double.parseDouble(parts[2]);
  51. UUID u = UUID.fromString(parts[3]);
  52. World w = Bukkit.getServer().getWorld(u);
  53. return new Location(w, x, y, z); // can return null if the world no longer exists
  54. }
  55.  
  56. public static Object getSerializedLocation(Location location) {
  57. // TODO Auto-generated method stub
  58. return location;
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement