Skip to content
Permalink
Browse files

fix some nms module code dup

  • Loading branch information...
mcmonkey4eva committed Feb 19, 2019
1 parent 4e9a9d2 commit 92e7bd936f86968495d30a05433bd09a79268433
@@ -11,8 +11,7 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.List;
import java.util.Map;
import java.util.*;

public interface ItemHelper {

@@ -32,7 +31,32 @@

ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag);

Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack);
default Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers);

@@ -105,34 +105,6 @@ public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
return CraftItemStack.asBukkitCopy(nmsItemStack);
}

@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
@@ -105,34 +105,6 @@ public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
return CraftItemStack.asBukkitCopy(nmsItemStack);
}

@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
@@ -105,34 +105,6 @@ public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
return CraftItemStack.asBukkitCopy(nmsItemStack);
}

@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
@@ -106,34 +106,6 @@ public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
return CraftItemStack.asBukkitCopy(nmsItemStack);
}

@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
@@ -105,34 +105,6 @@ public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
return CraftItemStack.asBukkitCopy(nmsItemStack);
}

@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
@@ -105,34 +105,6 @@ public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
return CraftItemStack.asBukkitCopy(nmsItemStack);
}

@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}

@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));

0 comments on commit 92e7bd9

Please sign in to comment.
You can’t perform that action at this time.