Fixed the MassiveCore error but there's more

#106
This commit is contained in:
Norbi Peti 2019-10-27 23:27:54 +01:00
parent 73fc4aedcc
commit 98ee2ce771
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 49 additions and 4 deletions

View file

@ -9,6 +9,9 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Delegate;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
@ -21,6 +24,8 @@ import org.mockito.MockSettings;
import org.mockito.Mockito;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.UUID;
@ -175,6 +180,48 @@ public abstract class DiscordConnectedPlayer extends DiscordSenderBase implement
@Setter
private String displayName;
@Override
public AttributeInstance getAttribute(Attribute attribute) {
return new AttributeInstance() {
@Override
public Attribute getAttribute() {
return attribute;
}
@Override
public double getBaseValue() {
return getDefaultValue();
}
@Override
public void setBaseValue(double value) {
}
@Override
public Collection<AttributeModifier> getModifiers() {
return Collections.emptyList();
}
@Override
public void addModifier(AttributeModifier modifier) {
}
@Override
public void removeModifier(AttributeModifier modifier) {
}
@Override
public double getValue() {
return getDefaultValue();
}
@Override
public double getDefaultValue() {
return 20; //Works for max health, should be okay for the rest
}
};
}
public static DiscordConnectedPlayer create(User user, MessageChannel channel, UUID uuid, String mcname,
MinecraftChatModule module) {
return Mockito.mock(DiscordConnectedPlayer.class,

View file

@ -4,7 +4,7 @@ import buttondevteam.discordplugin.DiscordConnectedPlayer;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.bukkit.entity.Damageable;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
/**
@ -34,9 +34,7 @@ public class AppTest extends TestCase {
public void testApp() {
Player dcp = DiscordConnectedPlayer.createTest();
double h = dcp.getMaxHealth();
double h = dcp.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue(); ; ;
System.out.println(h);
Damageable d = (Damageable) dcp;
System.out.println(d.getMaxHealth());
}
}