mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2517
This commit is contained in:
parent
1141a01fd0
commit
8536965962
@ -51,6 +51,7 @@
|
||||
* Fixed #2499
|
||||
* Fixed #2527
|
||||
* Fixed #2519
|
||||
* Fixed #2517
|
||||
|
||||
## Release Candidate 17 (17 Oct 2020)
|
||||
|
||||
|
@ -1,22 +1,29 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataHolder;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* The {@link BlockDataService} is similar to the {@link CustomItemDataService},
|
||||
@ -27,7 +34,7 @@ import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public class BlockDataService implements PersistentDataService, Keyed {
|
||||
public class BlockDataService implements Keyed {
|
||||
|
||||
private final NamespacedKey namespacedKey;
|
||||
|
||||
@ -62,14 +69,27 @@ public class BlockDataService implements PersistentDataService, Keyed {
|
||||
Validate.notNull(b, "The block cannot be null!");
|
||||
Validate.notNull(value, "The value cannot be null!");
|
||||
|
||||
BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
|
||||
// Due to a bug on older versions, Persistent Data is nullable for non-snapshots
|
||||
boolean useSnapshot = SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_16);
|
||||
|
||||
BlockStateSnapshotResult result = PaperLib.getBlockState(b, useSnapshot);
|
||||
BlockState state = result.getState();
|
||||
|
||||
if (state instanceof TileState) {
|
||||
setString((TileState) state, namespacedKey, value);
|
||||
try {
|
||||
PersistentDataContainer container = ((TileState) state).getPersistentDataContainer();
|
||||
container.set(namespacedKey, PersistentDataType.STRING, value);
|
||||
|
||||
if (result.isSnapshot()) {
|
||||
state.update();
|
||||
if (result.isSnapshot()) {
|
||||
state.update();
|
||||
}
|
||||
} catch (Exception x) {
|
||||
Slimefun.getLogger().log(Level.SEVERE, "Please check if your Server Software is up to date!");
|
||||
|
||||
String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName();
|
||||
Slimefun.getLogger().log(Level.SEVERE, () -> serverSoftware + " | " + Bukkit.getVersion() + " | " + Bukkit.getBukkitVersion());
|
||||
|
||||
Slimefun.getLogger().log(Level.SEVERE, "An Exception was thrown while trying to set Persistent Data for a Block", x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,7 +107,8 @@ public class BlockDataService implements PersistentDataService, Keyed {
|
||||
BlockState state = PaperLib.getBlockState(b, false).getState();
|
||||
|
||||
if (state instanceof TileState) {
|
||||
return getString((TileState) state, namespacedKey);
|
||||
PersistentDataContainer container = ((TileState) state).getPersistentDataContainer();
|
||||
return Optional.ofNullable(container.get(namespacedKey, PersistentDataType.STRING));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
@ -26,7 +28,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
* @see SlimefunItemStack
|
||||
*
|
||||
*/
|
||||
public class CustomItemDataService implements PersistentDataService, Keyed {
|
||||
public class CustomItemDataService implements Keyed {
|
||||
|
||||
private final NamespacedKey namespacedKey;
|
||||
|
||||
@ -71,16 +73,17 @@ public class CustomItemDataService implements PersistentDataService, Keyed {
|
||||
* This method stores the given id on the provided {@link ItemMeta} via
|
||||
* persistent data.
|
||||
*
|
||||
* @param im
|
||||
* @param meta
|
||||
* The {@link ItemMeta} to store data on
|
||||
* @param id
|
||||
* The id to store on the {@link ItemMeta}
|
||||
*/
|
||||
public void setItemData(@Nonnull ItemMeta im, @Nonnull String id) {
|
||||
Validate.notNull(im, "The ItemMeta cannot be null!");
|
||||
public void setItemData(@Nonnull ItemMeta meta, @Nonnull String id) {
|
||||
Validate.notNull(meta, "The ItemMeta cannot be null!");
|
||||
Validate.notNull(id, "Cannot store null on an ItemMeta!");
|
||||
|
||||
setString(im, namespacedKey, id);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(namespacedKey, PersistentDataType.STRING, id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +118,8 @@ public class CustomItemDataService implements PersistentDataService, Keyed {
|
||||
public Optional<String> getItemData(@Nonnull ItemMeta meta) {
|
||||
Validate.notNull(meta, "Cannot read data from null!");
|
||||
|
||||
return getString(meta, namespacedKey);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
return Optional.ofNullable(container.get(namespacedKey, PersistentDataType.STRING));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -21,6 +20,8 @@ import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.localization.Language;
|
||||
@ -37,7 +38,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
* @see Language
|
||||
*
|
||||
*/
|
||||
public class LocalizationService extends SlimefunLocalization implements PersistentDataService {
|
||||
public class LocalizationService extends SlimefunLocalization {
|
||||
|
||||
private static final String LANGUAGE_PATH = "language";
|
||||
|
||||
@ -151,10 +152,12 @@ public class LocalizationService extends SlimefunLocalization implements Persist
|
||||
@Override
|
||||
public Language getLanguage(@Nonnull Player p) {
|
||||
Validate.notNull("Player cannot be null!");
|
||||
Optional<String> language = getString(p, languageKey);
|
||||
|
||||
if (language.isPresent()) {
|
||||
Language lang = languages.get(language.get());
|
||||
PersistentDataContainer container = p.getPersistentDataContainer();
|
||||
String language = container.get(languageKey, PersistentDataType.STRING);
|
||||
|
||||
if (language != null) {
|
||||
Language lang = languages.get(language);
|
||||
|
||||
if (lang != null) {
|
||||
return lang;
|
||||
|
@ -1,35 +0,0 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataHolder;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
|
||||
/**
|
||||
* This interface is used to defer calls to Persistent Data and make sure they are only called
|
||||
* if the {@link MinecraftVersion} supports it.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @deprecated This is redundant, we can use {@link PersistentDataAPI} instead.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
interface PersistentDataService {
|
||||
|
||||
default void setString(Object obj, NamespacedKey key, String value) {
|
||||
PersistentDataContainer container = ((PersistentDataHolder) obj).getPersistentDataContainer();
|
||||
container.set(key, PersistentDataType.STRING, value);
|
||||
}
|
||||
|
||||
default Optional<String> getString(Object obj, NamespacedKey key) {
|
||||
PersistentDataContainer container = ((PersistentDataHolder) obj).getPersistentDataContainer();
|
||||
return Optional.ofNullable(container.get(key, PersistentDataType.STRING));
|
||||
}
|
||||
|
||||
}
|
@ -101,9 +101,6 @@ public class ThirdPartyPluginService {
|
||||
// mcMMO Integration
|
||||
if (isPluginInstalled("mcMMO")) {
|
||||
try {
|
||||
// This makes sure that the FakeEvent interface is present.
|
||||
// Class.forName("com.gmail.nossr50.events.fake.FakeEvent");
|
||||
|
||||
new McMMOIntegration(plugin);
|
||||
isMcMMOInstalled = true;
|
||||
} catch (Exception | LinkageError x) {
|
||||
@ -170,7 +167,7 @@ public class ThirdPartyPluginService {
|
||||
* @return Whether this is a fake event
|
||||
*/
|
||||
public boolean isEventFaked(@Nonnull Event event) {
|
||||
// TODO: Change this to FakeEvent once the new mcMMO build was released
|
||||
// This can be changed to "FakeEvent" in a later version
|
||||
return isMcMMOInstalled && event instanceof FakeBlockBreakEvent;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user