TypeDamageModifier

This commit is contained in:
Olof Larsson 2016-05-25 14:43:16 +02:00
parent 13d7fb5040
commit 47717ff70b
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
5 changed files with 189 additions and 0 deletions

View File

@ -87,6 +87,7 @@ import com.massivecraft.massivecore.mson.MsonEvent;
import com.massivecraft.massivecore.nms.NmsBasics;
import com.massivecraft.massivecore.nms.NmsBoard;
import com.massivecraft.massivecore.nms.NmsChat;
import com.massivecraft.massivecore.nms.NmsEntityDamageEvent;
import com.massivecraft.massivecore.nms.NmsEntityGet;
import com.massivecraft.massivecore.nms.NmsItemStackCreate;
import com.massivecraft.massivecore.nms.NmsItemStackCreate17R4P;
@ -262,6 +263,7 @@ public class MassiveCore extends MassivePlugin
NmsBasics.class,
NmsBoard.class,
NmsChat.class,
NmsEntityDamageEvent.class,
NmsEntityGet.class,
NmsItemStackCreate.class,
NmsItemStackTooltip.class,

View File

@ -25,6 +25,7 @@ import com.massivecraft.massivecore.command.type.container.TypeMap;
import com.massivecraft.massivecore.command.type.container.TypeSet;
import com.massivecraft.massivecore.command.type.enumeration.TypeBiome;
import com.massivecraft.massivecore.command.type.enumeration.TypeChatColor;
import com.massivecraft.massivecore.command.type.enumeration.TypeDamageModifier;
import com.massivecraft.massivecore.command.type.enumeration.TypeDifficulty;
import com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor;
import com.massivecraft.massivecore.command.type.enumeration.TypeEntityType;
@ -221,6 +222,7 @@ public class RegistryType
try
{
register(TypeRabbitType.get());
register(TypeDamageModifier.get());
}
catch (Throwable t)
{

View File

@ -0,0 +1,18 @@
package com.massivecraft.massivecore.command.type.enumeration;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
public class TypeDamageModifier extends TypeEnum<DamageModifier>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeDamageModifier i = new TypeDamageModifier();
public static TypeDamageModifier get() { return i; }
public TypeDamageModifier()
{
super(DamageModifier.class);
}
}

View File

@ -0,0 +1,70 @@
package com.massivecraft.massivecore.nms;
import java.util.Map;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import com.google.common.base.Function;
import com.massivecraft.massivecore.mixin.Mixin;
public class NmsEntityDamageEvent extends Mixin
{
// -------------------------------------------- //
// DEFAULT
// -------------------------------------------- //
private static NmsEntityDamageEvent d = new NmsEntityDamageEvent().setAlternatives(
NmsEntityDamageEvent17R4P.class
);
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static NmsEntityDamageEvent i = d;
public static NmsEntityDamageEvent get() { return i; }
// -------------------------------------------- //
// ACCESS > ORIGINALS
// -------------------------------------------- //
public Map<DamageModifier, Double> getOriginals(EntityDamageEvent event)
{
throw this.notImplemented();
}
public void setOriginals(EntityDamageEvent event, Map<DamageModifier, Double> originals)
{
throw this.notImplemented();
}
// -------------------------------------------- //
// ACCESS > MODIFIERS
// -------------------------------------------- //
public Map<DamageModifier, Double> getModifiers(EntityDamageEvent event)
{
throw this.notImplemented();
}
public void setModifiers(EntityDamageEvent event, Map<DamageModifier, Double> modifiers)
{
throw this.notImplemented();
}
// -------------------------------------------- //
// ACCESS > FUNCTIONS
// -------------------------------------------- //
public Map<DamageModifier, Function<Double, Double>> getFunctions(EntityDamageEvent event)
{
throw this.notImplemented();
}
public void setModifierFunctions(EntityDamageEvent event, Map<DamageModifier, Function<Double, Double>> functions)
{
throw this.notImplemented();
}
}

View File

@ -0,0 +1,97 @@
package com.massivecraft.massivecore.nms;
import java.lang.reflect.Field;
import java.util.Map;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import com.google.common.base.Function;
import com.massivecraft.massivecore.util.ReflectionUtil;
public class NmsEntityDamageEvent17R4P extends NmsEntityDamageEvent
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static NmsEntityDamageEvent17R4P i = new NmsEntityDamageEvent17R4P();
public static NmsEntityDamageEvent17R4P get() { return i; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// org.bukkit.event.entity.EntityDamageEvent
private Class<?> classEntityDamageEvent;
// org.bukkit.event.entity.EntityDamageEvent#originals
private Field fieldEntityDamageEventOriginals;
// org.bukkit.event.entity.EntityDamageEvent#modifiers
private Field fieldEntityDamageEventModifiers;
// org.bukkit.event.entity.EntityDamageEvent#modifierFunctions
private Field fieldEntityDamageEventFunctions;
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
@Override
public void setup() throws Throwable
{
this.classEntityDamageEvent = EntityDamageEvent.class;
this.fieldEntityDamageEventOriginals = ReflectionUtil.getField(this.classEntityDamageEvent, "originals");
this.fieldEntityDamageEventModifiers = ReflectionUtil.getField(this.classEntityDamageEvent, "modifiers");
this.fieldEntityDamageEventFunctions = ReflectionUtil.getField(this.classEntityDamageEvent, "modifierFunctions");
}
// -------------------------------------------- //
// ACCESS > ORIGINALS
// -------------------------------------------- //
@Override
public Map<DamageModifier, Double> getOriginals(EntityDamageEvent event)
{
return ReflectionUtil.getField(this.fieldEntityDamageEventOriginals, event);
}
@Override
public void setOriginals(EntityDamageEvent event, Map<DamageModifier, Double> originals)
{
ReflectionUtil.setField(this.fieldEntityDamageEventOriginals, event, originals);
}
// -------------------------------------------- //
// ACCESS > MODIFIERS
// -------------------------------------------- //
@Override
public Map<DamageModifier, Double> getModifiers(EntityDamageEvent event)
{
return ReflectionUtil.getField(this.fieldEntityDamageEventModifiers, event);
}
@Override
public void setModifiers(EntityDamageEvent event, Map<DamageModifier, Double> modifiers)
{
ReflectionUtil.setField(this.fieldEntityDamageEventModifiers, event, modifiers);
}
// -------------------------------------------- //
// ACCESS > FUNCTIONS
// -------------------------------------------- //
@Override
public Map<DamageModifier, Function<Double, Double>> getFunctions(EntityDamageEvent event)
{
return ReflectionUtil.getField(this.fieldEntityDamageEventFunctions, event);
}
@Override
public void setModifierFunctions(EntityDamageEvent event, Map<DamageModifier, Function<Double, Double>> functions)
{
ReflectionUtil.setField(this.fieldEntityDamageEventFunctions, event, functions);
}
}