Skip to content

Commit

Permalink
Added nbt support
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyFire55 committed Dec 8, 2018
1 parent 72acb5a commit fb47ffe
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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"));
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/ru/skyfire/zeta/dailyrewards/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, Object> 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();
}
}
98 changes: 50 additions & 48 deletions src/main/resources/assets/dailyrewards/DailyRewards.conf
Original file line number Diff line number Diff line change
@@ -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 <materialname:meta> <amount> - 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 <materialname:meta> <amount> - 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 <player> diamond 1"} //command, which will execute from console when player take this reward
] //use <player> placeholder - it's player's name who takes the reward
}
rewards: [
{reward: "CMD give <player> diamond 1"} //command, which will execute from console when player take this reward
] //use <player> placeholder - it's player's name who takes the reward
}
}

0 comments on commit fb47ffe

Please sign in to comment.