-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pablete1234 <[email protected]>
- Loading branch information
1 parent
b6d8732
commit 855a695
Showing
11 changed files
with
82 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package tc.oc.pgm.kits.tag; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.DyeColor; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.bukkit.inventory.meta.LeatherArmorMeta; | ||
import tc.oc.pgm.api.player.MatchPlayer; | ||
import tc.oc.pgm.util.bukkit.BukkitUtils; | ||
import tc.oc.pgm.util.inventory.tag.ItemTag; | ||
|
||
public class ItemModifier { | ||
|
||
public static final ItemTag<Boolean> TEAM_COLOR = ItemTag.newBoolean("team-color"); | ||
|
||
public static final ImmutableSet<Material> COLOR_AFFECTED = | ||
ImmutableSet.of( | ||
Material.WOOL, | ||
Material.CARPET, | ||
Material.STAINED_CLAY, | ||
Material.STAINED_GLASS, | ||
Material.STAINED_GLASS_PANE); | ||
|
||
// Apply per-player customizations of items. | ||
// This may be expanded on the future but currently only handles coloring armor & blocks. | ||
// The method is explicitly mutate-only, if you don't want side effects pass a clone. | ||
public static void apply(ItemStack item, MatchPlayer player) { | ||
if (!TEAM_COLOR.has(item)) return; | ||
TEAM_COLOR.clear(item); | ||
|
||
ItemMeta meta = item.getItemMeta(); | ||
|
||
if (meta instanceof LeatherArmorMeta) { | ||
LeatherArmorMeta leather = (LeatherArmorMeta) meta; | ||
leather.setColor(player.getParty().getFullColor()); | ||
item.setItemMeta(meta); | ||
} else if (COLOR_AFFECTED.contains(item.getType())) { | ||
item.setDurability(getWoolColor(player.getParty().getColor())); | ||
} | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
private static byte getWoolColor(ChatColor color) { | ||
return BukkitUtils.chatColorToDyeColor(color).getWoolData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters