Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "team-color" attribute to Armor Kits #856

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion core/src/main/java/tc/oc/pgm/kits/ArmorKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import tc.oc.pgm.api.player.MatchPlayer;

public class ArmorKit extends AbstractKit {
public static class ArmorItem {
public final ItemStack stack;
public final boolean locked;
public final boolean teamColor;

public ArmorItem(ItemStack stack, boolean locked) {
public ArmorItem(ItemStack stack, boolean locked, boolean teamColor) {
this.stack = stack;
this.locked = locked;
this.teamColor = teamColor;
}
}

Expand All @@ -39,6 +42,12 @@ public void applyPostEvent(MatchPlayer player, boolean force, List<ItemStack> di
if (force || wearing[slot] == null || wearing[slot].getType() == Material.AIR) {
wearing[slot] = entry.getValue().stack.clone();

if (entry.getValue().teamColor) {
LeatherArmorMeta meta = (LeatherArmorMeta) wearing[slot].getItemMeta();
meta.setColor(player.getParty().getFullColor());
wearing[slot].setItemMeta(meta);
}

KitMatchModule kitMatchModule = player.getMatch().getModule(KitMatchModule.class);
if (kitMatchModule != null) {
kitMatchModule.lockArmorSlot(player, entry.getKey(), entry.getValue().locked);
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/tc/oc/pgm/kits/KitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ private ArmorKit.ArmorItem parseArmorItem(Element el) throws InvalidXMLException
}
ItemStack stack = parseItem(el, true);
boolean locked = XMLUtils.parseBoolean(el.getAttribute("locked"), false);
return new ArmorKit.ArmorItem(stack, locked);

boolean teamColor =
stack.getItemMeta() instanceof LeatherArmorMeta
&& XMLUtils.parseBoolean(el.getAttribute("team-color"), false);
return new ArmorKit.ArmorItem(stack, locked, teamColor);
}

public ArmorKit parseArmorKit(Element el) throws InvalidXMLException {
Expand Down