Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Usage of CustomModleData can be toggled
Browse files Browse the repository at this point in the history
Resorts to disabled for versions below 1.14
  • Loading branch information
Sentropic committed Oct 11, 2020
1 parent e198cf8 commit 316ad8d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/sucy/skill/api/player/PlayerCombos.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private void checkExpired() {
public String getCurrentComboString() {
if (clickIndex == 0) { return ""; } else if (clickIndex == clicks.length) {
final int id = SkillAPI.getComboManager().convertCombo(clicks);
checkExpired();
if (skills.containsKey(id)) {
return SkillAPI.getSkill(skills.get(id)).getName();
} else { return ""; }
Expand Down
31 changes: 23 additions & 8 deletions src/main/java/com/sucy/skill/api/util/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@

import com.rit.sucy.config.parse.DataSection;
import com.rit.sucy.text.TextFormatter;
import com.sucy.skill.SkillAPI;
import com.sucy.skill.data.Settings;
import org.apache.commons.lang.ObjectUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;

Expand All @@ -57,11 +60,17 @@ private static ItemStack parse(final String mat, final short dur, final int data

final ItemStack item = new ItemStack(material);
final ItemMeta meta = item.getItemMeta();
if (data!=0) {
meta.setCustomModelData(data);
}
item.setDurability(dur);

if (meta instanceof Damageable) {
((Damageable) meta).setDamage(dur);
}
if (SkillAPI.getSettings().useCustomModelData()) {
if (data!=0) {
meta.setCustomModelData(data);
}
} else {
item.setData(new MaterialData(material, (byte) data));
}
if (lore != null && !lore.isEmpty()) {
final List<String> colored = TextFormatter.colorStringList(lore);
meta.setDisplayName(colored.remove(0));
Expand All @@ -82,11 +91,17 @@ private static ItemStack parse(final String mat, final short dur, final int data
*/
public static void serializeIcon(ItemStack item, DataSection config) {
config.set(MAT, item.getType().name());
config.set(DURABILITY, item.getDurability());
ItemMeta meta = item.getItemMeta();
config.set(DATA, meta.hasCustomModelData() ? meta.getCustomModelData() : 0);

if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
ItemMeta meta = item.getItemMeta();
if (SkillAPI.getSettings().useCustomModelData()) {
config.set(DATA, meta.hasCustomModelData() ? meta.getCustomModelData() : 0);
} else {
config.set(DATA, item.getData().getData());
}
if (meta instanceof Damageable) {
config.set(DURABILITY, ((Damageable) meta).getDamage());
}
if (meta.hasDisplayName()) {
List<String> lore = item.getItemMeta().getLore();
if (lore == null) { lore = new ArrayList<>(); }
lore.add(0, item.getItemMeta().getDisplayName());
Expand Down
48 changes: 34 additions & 14 deletions src/main/java/com/sucy/skill/data/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,13 @@
import com.sucy.skill.log.Logger;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* <p>The management class for SkillAPI's config.yml settings.</p>
Expand Down Expand Up @@ -1464,6 +1456,7 @@ private void loadExpSettings() {
private ItemStack unassigned;
private boolean[] defaultBarLayout = new boolean[9];
private boolean[] lockedSlots = new boolean[9];
private boolean customModelData;

/**
* Checks whether or not the skill bar is enabled
Expand Down Expand Up @@ -1510,20 +1503,47 @@ public boolean[] getLockedSlots() {
return lockedSlots;
}

/**
* Checks whether or not CustomModelData is enabled
*
* @return true if enabled, false otherwise
*/
public boolean useCustomModelData() {
return customModelData;
}

private void loadSkillBarSettings() {
DataSection bar = config.getSection("Skill Bar");
skillBarEnabled = bar.getBoolean("enabled", false) && !castEnabled;
skillBarCooldowns = bar.getBoolean("show-cooldown", true);
customModelData = bar.getBoolean("use-custommodeldata", false);
if (customModelData) {
try {
ItemMeta.class.getMethod("hasCustomModelData",null);
} catch (NoSuchMethodException e) {
customModelData = false;
Logger.log("CustomModelData not supported below 1.14+. Using item durability/data instead.");
}
}

DataSection icon = bar.getSection("empty-icon");
Material mat = Material.matchMaterial(icon.getString("material", "PUMPKIN_SEEDS"));
if (mat == null) { mat = Material.PUMPKIN_SEEDS; }
unassigned = new ItemStack(mat);

ItemMeta meta = unassigned.getItemMeta();
int customModelData = icon.getInt("data", 0);
if (customModelData!=0) {
meta.setCustomModelData(icon.getInt("data", 0));

if (meta instanceof org.bukkit.inventory.meta.Damageable) {
((Damageable) meta).setDamage((short) icon.getInt("durability", 0));
}

final int data = icon.getInt("data", 0);
if (customModelData) {
if (data!=0) {
meta.setCustomModelData(data);
}
} else {
unassigned.setData(new MaterialData(mat, (byte) data));
}

if (icon.isList("text")) {
Expand Down

0 comments on commit 316ad8d

Please sign in to comment.