Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed stacked blocks not registered correctly (#1068)
- Loading branch information
1 parent
25ac275
commit d052ba9
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/bgsoftware/superiorskyblock/serialization/impl/StackedBlockSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.bgsoftware.superiorskyblock.serialization.impl; | ||
|
||
import com.bgsoftware.superiorskyblock.serialization.ISerializer; | ||
import com.bgsoftware.superiorskyblock.utils.StringUtils; | ||
import com.bgsoftware.superiorskyblock.utils.locations.SmartLocation; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public final class StackedBlockSerializer implements ISerializer<Location, String> { | ||
|
||
private static final StackedBlockSerializer INSTANCE = new StackedBlockSerializer(); | ||
|
||
public static StackedBlockSerializer getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
private StackedBlockSerializer() { | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String serialize(@Nullable Location serializable) { | ||
return serializable == null ? "" : | ||
serializable.getWorld().getName() + ", " + | ||
serializable.getBlockX() + ", " + | ||
serializable.getBlockY() + ", " + | ||
serializable.getBlockZ(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Location deserialize(@Nullable String element) { | ||
if (StringUtils.isBlank(element)) | ||
return null; | ||
|
||
// Due to issues with commit #feacca9ec, we must parse the values as decimals | ||
|
||
String[] positionSections = element.split(", "); | ||
|
||
return positionSections.length < 4 ? null : new Location(Bukkit.getWorld(positionSections[0]), | ||
Double.parseDouble(positionSections[1]), | ||
Double.parseDouble(positionSections[2]), | ||
Double.parseDouble(positionSections[3])); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters