Skip to content

Commit

Permalink
nothing to see here
Browse files Browse the repository at this point in the history
  • Loading branch information
JRoy committed May 8, 2024
1 parent f65a672 commit 7795c7a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 39 deletions.
Expand Up @@ -16,13 +16,16 @@
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -127,11 +130,12 @@ public ItemStack get(String id, final boolean useResolvers) throws Exception {
final ItemStack stack = new ItemStack(material);
stack.setAmount(material.getMaxStackSize());

final PotionMetaProvider.AbstractPotionData potionData = data.getPotionData();
final ItemData.EssentialPotionData potionData = data.getPotionData();
final ItemMeta meta = stack.getItemMeta();

if (potionData != null && meta instanceof PotionMeta) {
final PotionMeta potionMeta = (PotionMeta) meta;
potionMeta.setBasePotionType(potionData.getType());
//todo figure out what to do here potionMeta.setBasePotionType(potionData);
}

Expand Down Expand Up @@ -205,7 +209,7 @@ private ItemData lookup(final ItemStack item) {

if (MaterialUtil.isPotion(type) && item.getItemMeta() instanceof PotionMeta) {
final PotionMetaProvider.AbstractPotionData potion = ess.getPotionMetaProvider().getPotionData(item);
return new ItemData(type, potion);
return new ItemData(type, new ItemData.EssentialPotionData(potion.getType(), potion.isUpgraded(), potion.isExtended();
} else if (type.toString().contains("SPAWNER")) {
final EntityType entity = ess.getSpawnerItemProvider().getEntityType(item);
return new ItemData(type, entity);
Expand All @@ -224,17 +228,16 @@ public Collection<String> listNames() {
public static class ItemData {
private Material material;
private String[] fallbacks = null;
// todo unfuck all of this
//private PotionMetaProvider.AbstractPotionData potionData = null;
private EssentialPotionData potionData = null;
private EntityType entity = null;

ItemData(final Material material) {
this.material = material;
}

ItemData(final Material material, final PotionMetaProvider.AbstractPotionData potionData) {
ItemData(final Material material, final EssentialPotionData potionData) {
this.material = material;
//this.potionData = potionData;
this.potionData = potionData;
}

ItemData(final Material material, final EntityType entity) {
Expand All @@ -244,8 +247,7 @@ public static class ItemData {

@Override
public int hashCode() {
return 31 * material.hashCode();
//return (31 * material.hashCode()) ^ potionData.hashCode();
return (31 * material.hashCode()) ^ potionData.hashCode();
}

@Override
Expand All @@ -269,26 +271,22 @@ public Material getMaterial() {
return material;
}

public PotionMetaProvider.AbstractPotionData getPotionData() {
return null;
//return this.potionData;
public EssentialPotionData getPotionData() {
return this.potionData;
}

public EntityType getEntity() {
return this.entity;
}

private boolean potionDataEquals(final ItemData o) {
return true;
/*
if (this.potionData == null && o.getPotionData() == null) {
return true;
} else if (this.potionData != null && o.getPotionData() != null) {
return this.potionData.equals(o.getPotionData());
} else {
return false;
}
*/
}

private boolean entityEquals(final ItemData o) {
Expand All @@ -300,5 +298,50 @@ private boolean entityEquals(final ItemData o) {
return false;
}
}

public static class EssentialPotionData {
private PotionType type;
private String fallbackType;
private final boolean upgraded;
private final boolean extended;

EssentialPotionData(PotionType type, boolean upgraded, boolean extended) {
this.type = type;
this.upgraded = upgraded;
this.extended = extended;
}

public PotionType getType() {
if (type == null && fallbackType != null) {
type = EnumUtil.valueOf(PotionType.class, fallbackType);
fallbackType = null; // If fallback fails, don't keep trying to look up fallbacks
}

return type;
}

public boolean isUpgraded() {
return upgraded;
}

public boolean isExtended() {
return extended;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final EssentialPotionData that = (EssentialPotionData) o;
return upgraded == that.upgraded &&
extended == that.extended &&
type == that.type;
}

@Override
public int hashCode() {
return Objects.hash(type, upgraded, extended);
}
}
}
}
Expand Up @@ -2,33 +2,9 @@

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;

import java.util.Collection;

public interface PotionMetaProvider extends Provider {
ItemStack createPotionItem(Material initial, int effectId);

AbstractPotionData getPotionData(ItemStack stack);

void updatePotionStack(ItemStack stack, AbstractPotionData data);

interface AbstractPotionData {
/**
* Should only be used for pre-flattening
*/
boolean isSplash();

/**
* Should only be used for pre-flattening
*/
Collection<PotionEffect> getEffects();

int hashCode();

PotionType getType();

void setType(final PotionType type);
}
ItemStack setBasePotionData(ItemStack stack, PotionData data);
}

0 comments on commit 7795c7a

Please sign in to comment.