Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Ghoul.HealingStone;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockPlaceEvent;
- public class LocationSerializer implements Listener {
- Hs plugin;
- public LocationSerializer(final Hs plugin) {
- this.plugin = plugin;
- Bukkit.getPluginManager().registerEvents(this, plugin);
- }
- public String prefix = (ChatColor.GOLD + "[" + ChatColor.GREEN + "Hs" + ChatColor.GOLD + "]");
- @EventHandler
- public void onPlace(BlockPlaceEvent event) {
- Player player = event.getPlayer();
- Block block = event.getBlockPlaced();
- if (block.getType().equals(Material.getMaterial(plugin.getConfig().getString("Healingstone.BlockType")))) {
- plugin.getConfig().set("HealingBlocks", LocationSerializer.getSerializedLocation(block.getLocation()));
- player.sendMessage(prefix + " " + ChatColor.GOLD + "You Just Placed A Healing Block");
- }
- }
- String serializeLocation(Location loc) {
- return loc.getWorld().getName() + "," + loc.getBlockX() + "," + "," + loc.getBlockY() + "," + loc.getBlockZ();
- }
- public static Location getDeserializedLocation(String s) {// Converts String -> Location
- String[] parts = s.split(";"); // If you changed the semicolon you must change it here too
- double x = Double.parseDouble(parts[0]);
- double y = Double.parseDouble(parts[1]);
- double z = Double.parseDouble(parts[2]);
- UUID u = UUID.fromString(parts[3]);
- World w = Bukkit.getServer().getWorld(u);
- return new Location(w, x, y, z); // can return null if the world no longer exists
- }
- public static Object getSerializedLocation(Location location) {
- // TODO Auto-generated method stub
- return location;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement