Přidání funkcí pro PDC a jejich lepší okomentování

pull/7/head
jakub 1 year ago
parent e0025bbde3
commit f71cb4c032
  1. 2
      src/main/java/xyz/soukup/mineconomiaCoreV2/core/MsgRetriever.java
  2. 15
      src/main/java/xyz/soukup/mineconomiaCoreV2/core/PDC.java

@ -1,11 +1,13 @@
package xyz.soukup.mineconomiaCoreV2.core; package xyz.soukup.mineconomiaCoreV2.core;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory;
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config;
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.plugin; import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.plugin;
public class MsgRetriever { public class MsgRetriever {
public static YamlConfiguration lang = null; public static YamlConfiguration lang = null;
public static void loadLang(){ public static void loadLang(){
String langPath = "lang/" + config.getString("lang"); String langPath = "lang/" + config.getString("lang");

@ -7,41 +7,56 @@ 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;
//funkce pro lehčí manipulaci s minecraft PDC (trvalé uchovávání dat v entitách, itemech a blocích)
public class PDC { public class PDC {
//Zapíše hodnotu do hráče
public static void WritePlayerPDC(Player player, String key, PersistentDataType type, Object value){ public static void WritePlayerPDC(Player player, String key, PersistentDataType type, Object value){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = player.getPersistentDataContainer(); PersistentDataContainer pdc = player.getPersistentDataContainer();
pdc.set(nKey, type, value); pdc.set(nKey, type, value);
} }
//Vezme hodnotu z hráče
public static Object GetPlayerPDC(Player player, String key, PersistentDataType type){ public static Object GetPlayerPDC(Player player, String key, PersistentDataType type){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = player.getPersistentDataContainer(); PersistentDataContainer pdc = player.getPersistentDataContainer();
return pdc.get(nKey, type); return pdc.get(nKey, type);
} }
//Odstraní hodnotu z hráče
public static void DeletePlayerPDC(Player player, String key){ public static void DeletePlayerPDC(Player player, String key){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = player.getPersistentDataContainer(); PersistentDataContainer pdc = player.getPersistentDataContainer();
pdc.remove(nKey); pdc.remove(nKey);
} }
//Zapíše hodnotu do itemu
public static void WriteItemMetaPDC(ItemMeta itemMeta, String key, PersistentDataType type, Object value){ public static void WriteItemMetaPDC(ItemMeta itemMeta, String key, PersistentDataType type, Object value){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = itemMeta.getPersistentDataContainer(); PersistentDataContainer pdc = itemMeta.getPersistentDataContainer();
pdc.set(nKey, type, value); pdc.set(nKey, type, value);
} }
//Odstraní hodnotu z itemu
public static Object GetItemMetaPDC(ItemMeta itemMeta, String key, PersistentDataType type){ public static Object GetItemMetaPDC(ItemMeta itemMeta, String key, PersistentDataType type){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = itemMeta.getPersistentDataContainer(); PersistentDataContainer pdc = itemMeta.getPersistentDataContainer();
return pdc.get(nKey, type); return pdc.get(nKey, type);
} }
//Zapíše hodnotu do statusu bloku
public static void WriteTileStatePDC(TileState tileState, String key, PersistentDataType type, Object value){ public static void WriteTileStatePDC(TileState tileState, String key, PersistentDataType type, Object value){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = tileState.getPersistentDataContainer(); PersistentDataContainer pdc = tileState.getPersistentDataContainer();
pdc.set(nKey, type, value); pdc.set(nKey, type, value);
} }
//Vezme hodnotu ze statusu bloku
public static Object GetTileStatePDC(TileState tileState, String key, PersistentDataType type){ public static Object GetTileStatePDC(TileState tileState, String key, PersistentDataType type){
NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key); NamespacedKey nKey = new NamespacedKey(sharedValues.plugin, key);
PersistentDataContainer pdc = tileState.getPersistentDataContainer(); PersistentDataContainer pdc = tileState.getPersistentDataContainer();

Loading…
Cancel
Save