From 7a9c5843fc493d80618d80552678e10ca700eaf9 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 31 Jul 2017 19:11:00 +0100 Subject: [PATCH] Get skin data from Google Sheets --- .../mineplex/core/gadget/GadgetManager.java | 3 + .../gamemodifiers/moba/HeroSkinGadget.java | 63 +++++++++++++++++++ .../moba/HeroSkinGadgetData.java | 41 ++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadget.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadgetData.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index 1ce9cc446..8a57cb77a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -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) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadget.java new file mode 100644 index 000000000..4e65370af --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadget.java @@ -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> getSkins() + { + Map> skinData = new HashMap<>(); + Map>> sheet = SHEET_MANAGER.getSheetData("MOBA_SKINS"); + + sheet.forEach((sheetName, rows) -> + { + List 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()); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadgetData.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadgetData.java new file mode 100644 index 000000000..c22f04b2c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/HeroSkinGadgetData.java @@ -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; + } +}