mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 19:55:48 +00:00
Fix remaining issues
This commit is contained in:
parent
5e39920e59
commit
a6a29509c7
@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical.talisman
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.cscorelib2.data.PersistentJsonDataType;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
@ -11,6 +13,7 @@ import org.bukkit.NamespacedKey;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -42,22 +45,23 @@ public class ResurrectedTalisman extends Talisman {
|
|||||||
return e -> {
|
return e -> {
|
||||||
Location currentLoc = e.getPlayer().getLocation();
|
Location currentLoc = e.getPlayer().getLocation();
|
||||||
JsonObject json = createJsonFromLocation(currentLoc);
|
JsonObject json = createJsonFromLocation(currentLoc);
|
||||||
|
ItemMeta itemMeta = e.getItem().getItemMeta();
|
||||||
|
|
||||||
PersistentDataContainer pdc = e.getItem().getItemMeta().getPersistentDataContainer();
|
itemMeta.getPersistentDataContainer().set(locationKey, PersistentJsonDataType.JSON_OBJECT, json);
|
||||||
pdc.set(locationKey, PersistentDataType.STRING, json.toString());
|
|
||||||
|
e.getItem().setItemMeta(itemMeta);
|
||||||
|
|
||||||
SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.talisman.resurrected-location", true);
|
SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.talisman.resurrected-location", true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Location getSavedLocation(ItemStack item) {
|
public Location getSavedLocation(@Nonnull ItemStack item) {
|
||||||
PersistentDataContainer pdc = item.getItemMeta().getPersistentDataContainer();
|
PersistentDataContainer pdc = item.getItemMeta().getPersistentDataContainer();
|
||||||
String data = pdc.get(locationKey, PersistentDataType.STRING);
|
JsonObject json = pdc.get(locationKey, PersistentJsonDataType.JSON_OBJECT);
|
||||||
/* Data here is always null, it doesnt get saved properly */
|
|
||||||
|
|
||||||
if (data != null) {
|
if (json != null) {
|
||||||
return parseLocationFromJson(data);
|
return parseLocationFromJsonObject(json);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
@ -77,9 +81,7 @@ public class ResurrectedTalisman extends Talisman {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Location parseLocationFromJson(@Nonnull String rawData) {
|
private Location parseLocationFromJsonObject(@Nonnull JsonObject json) {
|
||||||
JsonObject json = new JsonParser().parse(rawData).getAsJsonObject();
|
|
||||||
|
|
||||||
UUID uuid = UUID.fromString(json.get("world").getAsString());
|
UUID uuid = UUID.fromString(json.get("world").getAsString());
|
||||||
World world = Bukkit.getWorld(uuid);
|
World world = Bukkit.getWorld(uuid);
|
||||||
|
|
||||||
|
@ -325,12 +325,17 @@ public class TalismanListener implements Listener {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private Location getSafeRespawnLocation(@Nonnull Player player) {
|
private Location getSafeRespawnLocation(@Nonnull Player player) {
|
||||||
ItemStack item = Talisman.checkForAndGet(SlimefunItems.TALISMAN_RESURRECTED, player);
|
ItemStack item = Talisman.checkForAndGet(SlimefunItems.TALISMAN_RESURRECTED, player);
|
||||||
|
SlimefunItem sfItem = ResurrectedTalisman.getByItem(item);
|
||||||
|
|
||||||
if (item != null) {
|
if (sfItem instanceof ResurrectedTalisman) {
|
||||||
Location savedLoc = ResurrectedTalisman.getSavedLocation(item);
|
ResurrectedTalisman talisman = (ResurrectedTalisman) sfItem;
|
||||||
|
|
||||||
if (savedLoc != null) {
|
if (item != null) {
|
||||||
return savedLoc;
|
Location savedLoc = talisman.getSavedLocation(item);
|
||||||
|
|
||||||
|
if (savedLoc != null) {
|
||||||
|
return savedLoc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user