Add methods to check if a player owns a game cosmetic
This commit is contained in:
parent
67291804bf
commit
16daa3f7d8
@ -674,7 +674,7 @@ public class GadgetManager extends MiniPlugin
|
||||
@Override
|
||||
public void addCategories()
|
||||
{
|
||||
new GameCosmeticCategory(this, "Pistol", new ItemStack(Material.NETHER_STALK))
|
||||
new GameCosmeticCategory(this, "Pistol", new ItemStack(Material.NETHER_STALK), true)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
@ -685,7 +685,7 @@ public class GadgetManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this, "Shotgun", new ItemBuilder(Material.INK_SACK, (byte) 14).build())
|
||||
new GameCosmeticCategory(this, "Shotgun", new ItemBuilder(Material.INK_SACK, (byte) 14).build(), true)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
@ -696,7 +696,7 @@ public class GadgetManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this, "SMG", new ItemBuilder(Material.INK_SACK, (byte) 4).build())
|
||||
new GameCosmeticCategory(this, "SMG", new ItemBuilder(Material.INK_SACK, (byte) 4).build(), true)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
@ -707,7 +707,7 @@ public class GadgetManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this, "Rifle", new ItemBuilder(Material.INK_SACK, (byte) 7).build())
|
||||
new GameCosmeticCategory(this, "Rifle", new ItemBuilder(Material.INK_SACK, (byte) 7).build(), true)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
@ -718,7 +718,7 @@ public class GadgetManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this, "Knife", new ItemStack(Material.DIAMOND_SWORD))
|
||||
new GameCosmeticCategory(this, "Knife", new ItemStack(Material.DIAMOND_SWORD), true)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
@ -737,28 +737,28 @@ public class GadgetManager extends MiniPlugin
|
||||
@Override
|
||||
public void addCategories()
|
||||
{
|
||||
new GameCosmeticCategory(this,"Hero Skins", SkinData.HATTORI.getSkull())
|
||||
new GameCosmeticCategory(this,"Hero Skins", SkinData.HATTORI.getSkull(), true)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
{
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this,"Taunts", new ItemStack(Material.LAVA_BUCKET))
|
||||
new GameCosmeticCategory(this,"Taunts", new ItemStack(Material.LAVA_BUCKET), false)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
{
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this,"Base Decorations", new ItemStack(Material.WOOD_DOOR))
|
||||
new GameCosmeticCategory(this,"Base Decorations", new ItemStack(Material.WOOD_DOOR), false)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
{
|
||||
}
|
||||
};
|
||||
new GameCosmeticCategory(this,"Shop Morph", SkinData.HATTORI.getSkull())
|
||||
new GameCosmeticCategory(this,"Shop Morph", SkinData.HATTORI.getSkull(), false)
|
||||
{
|
||||
@Override
|
||||
public void addGadgets()
|
||||
|
@ -16,14 +16,16 @@ public abstract class GameCosmeticCategory
|
||||
private final String _categoryName;
|
||||
private final List<GameModifierGadget> _gadgets;
|
||||
private final ItemStack _itemStack;
|
||||
private final boolean _allowMultiple;
|
||||
|
||||
public GameCosmeticCategory(GameCosmeticType type, String categoryName, ItemStack itemStack)
|
||||
public GameCosmeticCategory(GameCosmeticType type, String categoryName, ItemStack itemStack, boolean allowMultiple)
|
||||
{
|
||||
_type = type;
|
||||
_manager = type.getManager();
|
||||
_categoryName = categoryName;
|
||||
_gadgets = new ArrayList<>();
|
||||
_itemStack = itemStack;
|
||||
_allowMultiple = allowMultiple;
|
||||
|
||||
addGadgets();
|
||||
|
||||
@ -52,4 +54,9 @@ public abstract class GameCosmeticCategory
|
||||
{
|
||||
return _itemStack;
|
||||
}
|
||||
|
||||
public boolean isAllowingMultiple()
|
||||
{
|
||||
return _allowMultiple;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
package mineplex.core.gadget.gadgets.gamemodifiers;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.gadget.types.GameModifierGadget;
|
||||
import mineplex.core.game.GameDisplay;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class GameCosmeticManager extends MiniPlugin
|
||||
@ -20,11 +26,93 @@ public class GameCosmeticManager extends MiniPlugin
|
||||
_cosmetics = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addCosmeticTypes(GameCosmeticType type, List<GameCosmeticCategory> cosmetics)
|
||||
public void addCosmeticType(GameCosmeticType type, List<GameCosmeticCategory> cosmetics)
|
||||
{
|
||||
_cosmetics.put(type, cosmetics);
|
||||
}
|
||||
|
||||
public GameModifierGadget getOwnedCosmetic(Player player, GameDisplay gameType, String categoryName)
|
||||
{
|
||||
GameCosmeticCategory category = getCategoryFrom(gameType, categoryName);
|
||||
|
||||
if (category == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (category.isAllowingMultiple())
|
||||
{
|
||||
throw new IllegalArgumentException("The category " + categoryName + " allows for multiple gadgets to be enabled at a time. Please use getOwnedCosmetics");
|
||||
}
|
||||
|
||||
List<GameModifierGadget> gadgets = category.getGadgets();
|
||||
|
||||
if (gadgets == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (GameModifierGadget gadget : gadgets)
|
||||
{
|
||||
if (gadget.ownsGadget(player))
|
||||
{
|
||||
return gadget;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<GameModifierGadget> getOwnedCosmetics(Player player, GameDisplay gameType, String categoryName)
|
||||
{
|
||||
GameCosmeticCategory category = getCategoryFrom(gameType, categoryName);
|
||||
|
||||
if (category == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (!category.isAllowingMultiple())
|
||||
{
|
||||
throw new IllegalArgumentException("The category " + categoryName + " does not allow multiple gadgets enabled at one time. Please use getOwnedCosmetic");
|
||||
}
|
||||
|
||||
List<GameModifierGadget> gadgets = category.getGadgets();
|
||||
|
||||
if (gadgets == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<GameModifierGadget> gadgetsCloned = new ArrayList<>(gadgets);
|
||||
gadgetsCloned.removeIf(gadget -> !gadget.ownsGadget(player));
|
||||
|
||||
return gadgetsCloned;
|
||||
}
|
||||
|
||||
private GameCosmeticCategory getCategoryFrom(GameDisplay gameType, String categoryName)
|
||||
{
|
||||
for (Entry<GameCosmeticType, List<GameCosmeticCategory>> entry : _cosmetics.entrySet())
|
||||
{
|
||||
GameCosmeticType type = entry.getKey();
|
||||
|
||||
if (type.getGame() != gameType)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (GameCosmeticCategory category : entry.getValue())
|
||||
{
|
||||
if (!category.getCategoryName().equals(categoryName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<GameCosmeticType, List<GameCosmeticCategory>> getTypes()
|
||||
{
|
||||
return _cosmetics;
|
||||
|
@ -23,7 +23,7 @@ public abstract class GameCosmeticType
|
||||
|
||||
addCategories();
|
||||
|
||||
manager.getGameCosmeticManager().addCosmeticTypes(this, _categories);
|
||||
manager.getGameCosmeticManager().addCosmeticType(this, _categories);
|
||||
}
|
||||
|
||||
public abstract void addCategories();
|
||||
|
@ -1,16 +1,17 @@
|
||||
package mineplex.core.gadget.types;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* An abstract wrapper for Gadgets of the type GameModifiers
|
||||
*/
|
||||
public abstract class GameModifierGadget extends Gadget
|
||||
public class GameModifierGadget extends Gadget
|
||||
{
|
||||
|
||||
protected final GameModifierType _type;
|
||||
|
Loading…
Reference in New Issue
Block a user