Get skin data from Google Sheets

This commit is contained in:
Sam 2017-07-31 19:11:00 +01:00
parent 3f47ae6e2e
commit 7a9c5843fc
3 changed files with 107 additions and 0 deletions

View File

@ -100,6 +100,8 @@ import mineplex.core.gadget.gadgets.gamemodifiers.GameCosmeticManager;
import mineplex.core.gadget.gadgets.gamemodifiers.GameCosmeticType;
import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.GameModifierMineStrikeSkin;
import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.MineStrikeSkin;
import mineplex.core.gadget.gadgets.gamemodifiers.moba.HeroSkinGadget;
import mineplex.core.gadget.gadgets.gamemodifiers.moba.HeroSkinGadgetData;
import mineplex.core.gadget.gadgets.hat.HatItem;
import mineplex.core.gadget.gadgets.hat.HatType;
import mineplex.core.gadget.gadgets.item.ItemBatGun;
@ -733,6 +735,7 @@ public class GadgetManager extends MiniPlugin
@Override
public void addGadgets()
{
HeroSkinGadget.getSkins().values().forEach(heroSkins -> heroSkins.forEach(skinData -> addGameGadget(new HeroSkinGadget(getManager(), this, skinData))));
}
};
new GameCosmeticCategory(this, "Taunts", new ItemStack(Material.LAVA_BUCKET), false)

View File

@ -0,0 +1,63 @@
package mineplex.core.gadget.gadgets.gamemodifiers.moba;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.Material;
import mineplex.core.Managers;
import mineplex.core.common.skin.SkinData;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.gamemodifiers.GameCosmeticCategory;
import mineplex.core.gadget.types.GameModifierGadget;
import mineplex.core.google.GoogleSheetsManager;
import mineplex.core.reward.RewardRarity;
public class HeroSkinGadget extends GameModifierGadget
{
private static final GoogleSheetsManager SHEET_MANAGER = Managers.require(GoogleSheetsManager.class);
public static Map<String, List<HeroSkinGadgetData>> getSkins()
{
Map<String, List<HeroSkinGadgetData>> skinData = new HashMap<>();
Map<String, List<List<String>>> sheet = SHEET_MANAGER.getSheetData("MOBA_SKINS");
sheet.forEach((sheetName, rows) ->
{
List<HeroSkinGadgetData> heroSkins = new ArrayList<>();
AtomicInteger rowIndex = new AtomicInteger();
rows.forEach(columns ->
{
// Don't check the first row
if (rowIndex.incrementAndGet() == 1 || columns.size() < 5)
{
return;
}
HeroSkinGadgetData heroSkin = new HeroSkinGadgetData(columns.get(0), columns.get(1), RewardRarity.valueOf(columns.get(2).toUpperCase()), new SkinData(columns.get(3), columns.get(4)));
heroSkins.add(heroSkin);
});
skinData.put(sheetName, heroSkins);
});
return skinData;
}
public HeroSkinGadget(GadgetManager manager, GameCosmeticCategory category, HeroSkinGadgetData skinData)
{
this(manager, category, skinData, -2);
}
public HeroSkinGadget(GadgetManager manager, GameCosmeticCategory category, HeroSkinGadgetData skinData, int cost)
{
super(manager, category, skinData.getName(), new String[]{skinData.getDescription()}, cost, Material.GLASS, (byte) 0);
setDisplayItem(skinData.getSkinData().getSkull());
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.gadget.gadgets.gamemodifiers.moba;
import mineplex.core.common.skin.SkinData;
import mineplex.core.reward.RewardRarity;
public class HeroSkinGadgetData
{
private final String _name;
private final String _description;
private final RewardRarity _rarity;
private final SkinData _skinData;
public HeroSkinGadgetData(String name, String description, RewardRarity rarity, SkinData skinData)
{
_name = name;
_description = description;
_rarity = rarity;
_skinData = skinData;
}
public String getName()
{
return _name;
}
public String getDescription()
{
return _description;
}
public RewardRarity getRarity()
{
return _rarity;
}
public SkinData getSkinData()
{
return _skinData;
}
}