diff --git a/src/main/java/ru/skyfire/zeta/dailyrewards/serializers/RewardDeserializer.java b/src/main/java/ru/skyfire/zeta/dailyrewards/serializers/RewardDeserializer.java index 1cf8866..0b56a60 100644 --- a/src/main/java/ru/skyfire/zeta/dailyrewards/serializers/RewardDeserializer.java +++ b/src/main/java/ru/skyfire/zeta/dailyrewards/serializers/RewardDeserializer.java @@ -9,6 +9,7 @@ import ru.skyfire.zeta.dailyrewards.reward.ItemReward; import ru.skyfire.zeta.dailyrewards.reward.MoneyReward; import ru.skyfire.zeta.dailyrewards.reward.Reward; +import ru.skyfire.zeta.dailyrewards.util.ItemUtil; import java.math.BigDecimal; import java.util.*; @@ -80,6 +81,10 @@ public RewardDeserializer(ConfigurationNode node) { lore.add(q, Text.of(days.getNode(a, "icon", "lore").getChildrenMap().get(String.valueOf(q+1)).getString().replace("&","ยง"))); q++; } + for (Object b : days.getNode(a, "icon", "nbt").getChildrenMap().keySet()){ + stack=ItemUtil.setCustomData(stack, String.valueOf(b), String.valueOf(days.getNode(a, "icon", "nbt", b).getString())); + } + stack.offer(Keys.ITEM_LORE, lore); } bufIconMap.put(a, stack != null ? stack.copy() : parseItem("minecraft:dirt")); diff --git a/src/main/java/ru/skyfire/zeta/dailyrewards/util/ItemUtil.java b/src/main/java/ru/skyfire/zeta/dailyrewards/util/ItemUtil.java index 10ed458..37d73d2 100644 --- a/src/main/java/ru/skyfire/zeta/dailyrewards/util/ItemUtil.java +++ b/src/main/java/ru/skyfire/zeta/dailyrewards/util/ItemUtil.java @@ -11,6 +11,8 @@ import org.spongepowered.api.item.inventory.entity.PlayerInventory; import org.spongepowered.api.item.inventory.query.QueryOperationTypes; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -196,4 +198,23 @@ public static ItemStack parseItem(String text) { public static boolean isItemStacksSimilar(ItemStack stack1, ItemStack stack2){ return stack1.getType().equals(stack2.getType()); } + + public static String getCustomData(ItemStack itemStack, String key){ + if(itemStack==null){ + return "0"; + } + DataContainer container = itemStack.toContainer(); + String value = container.get(DataQuery.of('.', "UnsafeData."+key)).orElse(0).toString(); + return value; + } + + public static ItemStack setCustomData(ItemStack itemStack, String inKey, Object value) { + Map extraMap = new HashMap<>(); + extraMap.put(inKey, value); + DataContainer container = itemStack.toContainer(); + for(String key : extraMap.keySet()) { + container.set(DataQuery.of('.', "UnsafeData."+key), extraMap.get(key)); + } + return ItemStack.builder().fromContainer(container).build(); + } } diff --git a/src/main/resources/assets/dailyrewards/DailyRewards.conf b/src/main/resources/assets/dailyrewards/DailyRewards.conf index d074ea1..73d93ab 100644 --- a/src/main/resources/assets/dailyrewards/DailyRewards.conf +++ b/src/main/resources/assets/dailyrewards/DailyRewards.conf @@ -1,60 +1,62 @@ -{ - debug=false //some debug stuffs, don't touch without need - hardMode=false //push player back to the first day if he missed one day or not - show-rewards-on-join=true //shows rewards to player when he joins or not +debug=false //some debug stuffs, don't touch without need +hardMode=false //push player back to the first day if he missed one day or not +show-rewards-on-join=true //shows rewards to player when he joins or not - daycap=7 //after this day player will be pushed back to the first day anyway - end of his row - guiShowDelay=0 +daycap=7 //after this day player will be pushed back to the first day anyway - end of his row +guiShowDelay=0 - messages-amount: 3 // amount of messages which player will recieve if he didn't take his reward. (0 to turn off) - time-interval: 600 //time interval in seconds between messages. (0 to turn off) +messages-amount: 3 // amount of messages which player will recieve if he didn't take his reward. (0 to turn off) +time-interval: 600 //time interval in seconds between messages. (0 to turn off) - button: "minecraft:end_crystal" +button: "minecraft:end_crystal" - days{ - 1: { //day number - if you will create 1,2 and 4 days, player shall not take reward for 3 day, but he will on 4 day - reward-message: "&5Wow! Your reaward is diamonds and coal! Yummy!" //Shows on reward take - icon: { // your icon settings for this day - player will see it in GUI - item: "minecraft:diamond" // materialname for item - fill free to use metadata - name: "Day 1" - lore: { - 1: "That's your first day Reward!" - 2: "Second string!" - 3: "Third string!" - } +days{ + 1: { //day number - if you will create 1,2 and 4 days, player shall not take reward for 3 day, but he will on 4 day + reward-message: "&5Wow! Your reaward is diamonds and coal! Yummy!" //Shows on reward take + icon: { // your icon settings for this day - player will see it in GUI + item: "minecraft:diamond" // materialname for item - fill free to use metadata + name: "Day 1" + lore: { + 1: "That's your first day Reward!" + 2: "Second string!" + 3: "Third string!" + } + nbt: { //nbt data for items. For heads, for example + key1: "value1" + key2: "value2" } - rewards: [ //rewards, which player will take in this day - {reward: "ITEM minecraft:diamond 4"}, //ITEM - just give items to player - {reward: "ITEM minecraft:coal 16"} //if you need more rewards, feel free to add more like here - ] } - 2: { - icon: { - item: "minecraft:diamond" - name: "Day 2" - lore: { - 1: "That's your first day Reward!" - 2: "Second string!" - 3: "Third string!" - } + rewards: [ //rewards, which player will take in this day + {reward: "ITEM minecraft:diamond 4"}, //ITEM - just give items to player + {reward: "ITEM minecraft:coal 16"} //if you need more rewards, feel free to add more like here + ] + } + 2: { + icon: { + item: "minecraft:diamond" + name: "Day 2" + lore: { + 1: "That's your first day Reward!" + 2: "Second string!" + 3: "Third string!" } - rewards: [ - {reward: "MONEY 1000"}, //give money to player - ] } - 3: { - icon: { - item: "minecraft:diamond" - name: "Day 3" - lore: { - 1: "That's your first day Reward!" - 2: "Second string!" - 3: "Third string!" - } + rewards: [ + {reward: "MONEY 1000"}, //give money to player + ] + } + 3: { + icon: { + item: "minecraft:diamond" + name: "Day 3" + lore: { + 1: "That's your first day Reward!" + 2: "Second string!" + 3: "Third string!" } - rewards: [ - {reward: "CMD give diamond 1"} //command, which will execute from console when player take this reward - ] //use placeholder - it's player's name who takes the reward } + rewards: [ + {reward: "CMD give diamond 1"} //command, which will execute from console when player take this reward + ] //use placeholder - it's player's name who takes the reward } } \ No newline at end of file