mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
[CI skip] Removed deprecated classes
This commit is contained in:
parent
2b01c37e64
commit
0f7318a749
@ -2,6 +2,7 @@
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
**Table of contents**
|
||||
|
||||
- [Release Candidate 15 (TBD)](#release-candidate-15-tbd)
|
||||
- [Release Candidate 14 (12 Jul 2020)](#release-candidate-14-12-jul-2020)
|
||||
- [Release Candidate 13 (16 Jun 2020)](#release-candidate-13-16-jun-2020)
|
||||
- [Release Candidate 12 (27 May 2020)](#release-candidate-12-27-may-2020)
|
||||
@ -19,6 +20,8 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
## Release Candidate 15 (TBD)
|
||||
|
||||
## Release Candidate 14 (12 Jul 2020)
|
||||
|
||||
#### Additions
|
||||
|
@ -1,31 +0,0 @@
|
||||
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.energy.ItemEnergy;
|
||||
|
||||
/**
|
||||
* This class is deprecated.
|
||||
*
|
||||
* @deprecated Please implement the {@link Rechargeable} interface from now on.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class ChargableItem extends SlimefunItem implements Rechargeable {
|
||||
|
||||
public ChargableItem(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxItemCharge(ItemStack item) {
|
||||
return ItemEnergy.getMaxEnergy(item);
|
||||
}
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package me.mrCookieSlime.Slimefun.api.energy;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
/**
|
||||
* @deprecated Please implement {@link Rechargeable} on your {@link SlimefunItem} instead.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ItemEnergy {
|
||||
|
||||
// We should find a replacement for this class
|
||||
// Perhaps we could also use PersistentData here too?
|
||||
private ItemEnergy() {}
|
||||
|
||||
// "&c&o&8\u21E8 &e\u26A1 &70 / 50 J"
|
||||
|
||||
public static float getStoredEnergy(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR || item.getAmount() < 1) return 0F;
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
||||
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) {
|
||||
return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[0].replace(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7"), ""));
|
||||
}
|
||||
}
|
||||
|
||||
return 0F;
|
||||
}
|
||||
|
||||
public static float getMaxEnergy(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR || item.getAmount() < 1) return 0F;
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
||||
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) {
|
||||
return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[1].replace(" J", ""));
|
||||
}
|
||||
}
|
||||
|
||||
return 0F;
|
||||
}
|
||||
|
||||
public static float addStoredEnergy(ItemStack item, float energy) {
|
||||
if (item == null || item.getType() == Material.AIR || item.getAmount() < 1) return 0F;
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0;
|
||||
|
||||
float rest = 0F;
|
||||
float capacity = getMaxEnergy(item);
|
||||
|
||||
if ((int) capacity == 0) {
|
||||
return rest;
|
||||
}
|
||||
|
||||
float stored = getStoredEnergy(item);
|
||||
|
||||
if (stored + energy > capacity) {
|
||||
rest = (stored + energy) - capacity;
|
||||
stored = capacity;
|
||||
}
|
||||
else if (stored + energy < 0) {
|
||||
stored = 0F;
|
||||
}
|
||||
else {
|
||||
stored = stored + energy;
|
||||
}
|
||||
|
||||
List<String> lore = item.getItemMeta().getLore();
|
||||
|
||||
int index = -1;
|
||||
for (int i = 0; i < lore.size(); i++) {
|
||||
String line = lore.get(i);
|
||||
|
||||
if (line.startsWith(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal decimal = BigDecimal.valueOf(stored).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
lore.set(index, ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7") + decimal.floatValue() + " / " + capacity + " J");
|
||||
|
||||
ItemMeta im = item.getItemMeta();
|
||||
im.setLore(lore);
|
||||
item.setItemMeta(im);
|
||||
return rest;
|
||||
}
|
||||
|
||||
public static ItemStack chargeItem(ItemStack item, float energy) {
|
||||
addStoredEnergy(item, energy);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void chargeInventory(Player p, float energy) {
|
||||
p.getInventory().setItemInMainHand(chargeItem(p.getInventory().getItemInMainHand(), energy));
|
||||
p.getInventory().setItemInOffHand(chargeItem(p.getInventory().getItemInOffHand(), energy));
|
||||
p.getInventory().setHelmet(chargeItem(p.getInventory().getHelmet(), energy));
|
||||
p.getInventory().setChestplate(chargeItem(p.getInventory().getChestplate(), energy));
|
||||
p.getInventory().setLeggings(chargeItem(p.getInventory().getLeggings(), energy));
|
||||
p.getInventory().setBoots(chargeItem(p.getInventory().getBoots(), energy));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user