DataItemStack - Dependencies, Better Debug, Better Order...

This commit is contained in:
Olof Larsson 2016-04-25 09:36:24 +02:00
parent 2c5fb79d9e
commit a0bcc5ae8d
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
17 changed files with 195 additions and 136 deletions

View File

@ -64,10 +64,7 @@ import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
import com.massivecraft.massivecore.integration.vault.IntegrationVault; import com.massivecraft.massivecore.integration.vault.IntegrationVault;
import com.massivecraft.massivecore.item.DataBannerPattern; import com.massivecraft.massivecore.item.DataBannerPattern;
import com.massivecraft.massivecore.item.WriterBannerPattern;
import com.massivecraft.massivecore.item.WriterFireworkEffect;
import com.massivecraft.massivecore.item.WriterItemStack; import com.massivecraft.massivecore.item.WriterItemStack;
import com.massivecraft.massivecore.item.WriterPotionEffect;
import com.massivecraft.massivecore.mixin.MixinActionbar; import com.massivecraft.massivecore.mixin.MixinActionbar;
import com.massivecraft.massivecore.mixin.MixinActual; import com.massivecraft.massivecore.mixin.MixinActual;
import com.massivecraft.massivecore.mixin.MixinCommand; import com.massivecraft.massivecore.mixin.MixinCommand;
@ -86,6 +83,7 @@ import com.massivecraft.massivecore.mixin.MixinVisibility;
import com.massivecraft.massivecore.mixin.MixinWorld; import com.massivecraft.massivecore.mixin.MixinWorld;
import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.mson.MsonEvent; import com.massivecraft.massivecore.mson.MsonEvent;
import com.massivecraft.massivecore.nms.NmsItemStack;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSAdapter; import com.massivecraft.massivecore.ps.PSAdapter;
import com.massivecraft.massivecore.store.ModificationPollerLocal; import com.massivecraft.massivecore.store.ModificationPollerLocal;
@ -168,8 +166,12 @@ public class MassiveCore extends MassivePlugin
ret.registerTypeAdapter(Mson.class, AdapterMson.get()); ret.registerTypeAdapter(Mson.class, AdapterMson.get());
ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.get()); ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.get());
// Items and Inventories // ItemStack
ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get()); ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get());
Class<?> classCraftItemStack = NmsItemStack.get().classCraftItemStack;
if (classCraftItemStack != null) ret.registerTypeAdapter(classCraftItemStack, AdapterItemStack.get());
// Inventory
ret.registerTypeAdapter(Inventory.class, AdapterInventory.get()); ret.registerTypeAdapter(Inventory.class, AdapterInventory.get());
ret.registerTypeAdapter(PlayerInventory.class, AdapterPlayerInventory.get()); ret.registerTypeAdapter(PlayerInventory.class, AdapterPlayerInventory.get());
@ -240,9 +242,6 @@ public class MassiveCore extends MassivePlugin
// Writer, // Writer,
WriterItemStack.class, WriterItemStack.class,
WriterPotionEffect.class,
WriterFireworkEffect.class,
WriterBannerPattern.class,
// Engine // Engine
EngineMassiveCoreChestGui.class, EngineMassiveCoreChestGui.class,

View File

@ -71,43 +71,55 @@ public class EngineMassiveCoreSponsor extends Engine
} }
// -------------------------------------------- // // -------------------------------------------- //
// INFORM // ENABLED
// -------------------------------------------- // // -------------------------------------------- //
public void inform(final CommandSender sender) public boolean isEnabled(final CommandSender sender)
{ {
// Fail Safe // If there is a sender ...
if (sender == null) return; if (sender == null) return false;
// If enabled by mconf ... // ... and enabled by mconf ...
if ( ! MassiveCoreMConf.get().sponsorEnabled) return; if ( ! MassiveCoreMConf.get().sponsorEnabled) return false;
// ... and enabled by info base ... // ... and enabled by info base ...
if ( ! MassiveCoreMSponsorInfo.get().enabled) return; if ( ! MassiveCoreMSponsorInfo.get().enabled) return false;
// ... and enabled by info time ... // ... and enabled by info time ...
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long to = MassiveCoreMSponsorInfo.get().enabledToMillis; long to = MassiveCoreMSponsorInfo.get().enabledToMillis;
long left = to - now; long left = to - now;
if (left <= 0) return; if (left <= 0) return false;
// ... and enabled by sender type ... // ... and enabled by sender type ...
boolean isConsole = IdUtil.isConsole(sender); boolean enabledByType = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleEnabled : MassiveCoreMSponsorInfo.get().ingameEnabled);
boolean enabledByType = (isConsole ? MassiveCoreMSponsorInfo.get().consoleEnabled : MassiveCoreMSponsorInfo.get().ingameEnabled); if ( ! enabledByType) return false;
if ( ! enabledByType) return;
// ... and enabled by sender operator ... // ... and enabled by sender operator ...
if ( ! sender.isOp()) return; if ( ! sender.isOp()) return false;
// ... and enabled by in indicator files ... // ... and enabled by in indicator files ...
for (String indicatorFileName : MassiveCoreMSponsorInfo.get().indicatorFileNames) for (String indicatorFileName : MassiveCoreMSponsorInfo.get().indicatorFileNames)
{ {
File indicatorFile = new File(indicatorFileName); File indicatorFile = new File(indicatorFileName);
if (indicatorFile.exists()) return; if (indicatorFile.exists()) return false;
} }
// ... then schedule inner inform. // ... then it's actually enabled.
int delayTicks = (isConsole ? MassiveCoreMSponsorInfo.get().consoleDelayTicks : MassiveCoreMSponsorInfo.get().ingameDelayTicks); return true;
}
// -------------------------------------------- //
// INFORM
// -------------------------------------------- //
public void inform(final CommandSender sender)
{
// Enabled
if ( ! this.isEnabled(sender)) return;
// Schedule
int delayTicks = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleDelayTicks : MassiveCoreMSponsorInfo.get().ingameDelayTicks);
Bukkit.getScheduler().runTaskLater(this.getPlugin(), new Runnable() Bukkit.getScheduler().runTaskLater(this.getPlugin(), new Runnable()
{ {
@Override @Override
@ -120,11 +132,11 @@ public class EngineMassiveCoreSponsor extends Engine
public void informInner(CommandSender sender) public void informInner(CommandSender sender)
{ {
// Console? // Enabled
boolean isConsole = IdUtil.isConsole(sender); if ( ! this.isEnabled(sender)) return;
// Messages // Messages
List<String> msgs = (isConsole ? MassiveCoreMSponsorInfo.get().consoleMsgs : MassiveCoreMSponsorInfo.get().ingameMsgs); List<String> msgs = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleMsgs : MassiveCoreMSponsorInfo.get().ingameMsgs);
String senderVisual = MixinDisplayName.get().getDisplayName(sender, sender); String senderVisual = MixinDisplayName.get().getDisplayName(sender, sender);
for (String msg : msgs) for (String msg : msgs)
{ {

View File

@ -1,11 +1,13 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import java.util.Arrays;
import java.util.List; import java.util.List;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.MassiveCoreMConf; import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean; import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.ReflectionUtil; import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -14,53 +16,132 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
// -------------------------------------------- // // -------------------------------------------- //
// WRITERS // WRITERS
// -------------------------------------------- // // -------------------------------------------- //
// A writer may contain subwriters. // Writer have dependencies and child writers.
// A dependency is another writer that must be successfully activated for this writer to function.
// For that reason the dependencies are activated just after the provoke logic.
// Examples would be WriterPotionEffect and WriterFireworkEffect.
// They are implicitly required for some ItemStack field writers.
private List<Class<?>> dependencyClasses = new MassiveList<>();
public List<Class<?>> getDependencyClasses() { return this.dependencyClasses; }
public void addDependencyClasses(Class<?>... dependencyClasses) { this.getDependencyClasses().addAll(Arrays.asList(dependencyClasses)); }
// This is the writer classes scheduled to be used at setup.
// We do not yet know if they are compatible with this Minecraft version.
// All, some or none of them may fail.
private List<Class<?>> writerClasses = new MassiveList<>();
public List<Class<?>> getWriterClasses() { return this.writerClasses; }
public void addWriterClasses(Class<?>... writerClasses) { this.getWriterClasses().addAll(Arrays.asList(writerClasses)); }
// These are the actually functional child writers.
// This list should only contain writers that passed the provoke routine.
private List<WriterAbstract<CA, CB, ?, ?, ?, ?>> writers = new MassiveList<>(); private List<WriterAbstract<CA, CB, ?, ?, ?, ?>> writers = new MassiveList<>();
public List<WriterAbstract<CA, CB, ?, ?, ?, ?>> getWriters() { return this.writers; }
public List<WriterAbstract<CA, CB, ?, ?, ?, ?>> getWriters() // Here is the logic to perform the dependency and child writer setup.
public void setupDependencies()
{ {
return this.writers; for (Class<?> dependencyClass : this.getDependencyClasses())
{
this.setupWriter(dependencyClass, false);
}
} }
public void clearWriters() public void setupWriters()
{ {
this.writers.clear(); for (Class<?> writerClass : this.getWriterClasses())
{
this.setupWriter(writerClass, true);
}
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void addWriter(Class<?> clazz) public void setupWriter(Class<?> writerClass, boolean add)
{ {
boolean success = false;
try try
{ {
Class<WriterAbstract<CA, CB, ?, ?, ?, ?>> clazzInner = (Class<WriterAbstract<CA, CB, ?, ?, ?, ?>>) clazz; Class<WriterAbstract<?, ?, ?, ?, ?, ?>> writerClassInner = (Class<WriterAbstract<?, ?, ?, ?, ?, ?>>) writerClass;
WriterAbstract<CA, CB, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(clazzInner); WriterAbstract<?, ?, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(writerClassInner);
writer.setActive(this.getActivePlugin());
this.getWriters().add(writer); if ( ! writer.isActive()) writer.setActive(this.getActivePlugin());
success = true;
if (add) this.getWriters().add((WriterAbstract<CA, CB, ?, ?, ?, ?>)writer);
} }
catch (Throwable t) catch (Throwable t)
{ {
if (MassiveCoreMConf.get().debugWriters) this.reportSuccess(false, writerClass.getSimpleName(), t);
{
t.printStackTrace();
}
}
if (MassiveCoreMConf.get().debugWriters)
{
String message = Txt.parse("<h>%s %s", clazz.getSimpleName(), TypeBoolean.getOn().getVisual(success));
this.getActivePlugin().log(message);
} }
} }
public void addWriters(Class<?>... clazzs) public void reportSuccess(boolean success)
{ {
for (Class<?> clazz : clazzs) this.reportSuccess(success, this.getClass().getSimpleName());
}
public void reportSuccess(boolean success, String name)
{
this.reportSuccess(success, name, null);
}
public void reportSuccess(boolean success, String name, Throwable t)
{
if ( ! MassiveCoreMConf.get().debugWriters) return;
// Create
List<String> messages = new MassiveList<>();
// Fill
String message;
// Main
message = Txt.parse("<h>%s %s", name, TypeBoolean.getOn().getVisual(success));
messages.add(message);
// Throwable
if (t != null)
{ {
this.addWriter(clazz); message = Txt.parse("<b>### %s <i>%s", t.getClass().getSimpleName(), t.getMessage());
messages.add(message);
for (String s : MUtil.getStackTraceStrings(Arrays.asList(t.getStackTrace()), true))
{
message = Txt.parse("<b>--> %s", s);
messages.add(message);
}
} }
// Send
for (String s : messages)
{
this.getActivePlugin().log(s);
}
}
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
// The setActive method starts out with the provoke.
// This means it can fail immediately with a runtime exception.
// If this happens it will not have been activated in any way.
@Override
public void setActive(boolean active)
{
if (active)
{
// Provoke
this.provoke();
// Setup Dependencies
this.setupDependencies();
// Report This Success
this.reportSuccess(true);
// Setup Writers
this.setupWriters();
}
super.setActive(active);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -121,17 +202,6 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
return cb; return cb;
} }
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActive(boolean active)
{
this.provoke();
super.setActive(active);
}
// -------------------------------------------- // // -------------------------------------------- //
// PROVOKE // PROVOKE
// -------------------------------------------- // // -------------------------------------------- //
@ -167,7 +237,7 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
public void write(OA oa, OB ob, boolean a2b) public void write(OA oa, OB ob, boolean a2b)
{ {
if (!this.isActive()) throw new IllegalStateException("not active " + this.getClass().getName()); if ( ! this.isActive()) throw new IllegalStateException("not active " + this.getClass().getName());
if (oa == null) throw new NullPointerException("oa"); if (oa == null) throw new NullPointerException("oa");
if (ob == null) throw new NullPointerException("ob"); if (ob == null) throw new NullPointerException("ob");

View File

@ -1,9 +1,20 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material;
import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.BlockStateMeta;
public abstract class WriterAbstractItemStackMetaState<OB, CB, FA, FB> extends WriterAbstractItemStackMeta<OB, CB, FA, FB> public abstract class WriterAbstractItemStackMetaState<OB, CB, FA, FB> extends WriterAbstractItemStackMeta<OB, CB, FA, FB>
{ {
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public WriterAbstractItemStackMetaState()
{
// For the initial provoke to pass we must set a Material with a BlockStateMeta.
this.setMaterial(Material.SHIELD);
}
// -------------------------------------------- // // -------------------------------------------- //
// CREATE // CREATE
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -8,22 +8,12 @@ public class WriterBannerPattern extends WriterAbstractBannerPattern<Object, Obj
private static final WriterBannerPattern i = new WriterBannerPattern(); private static final WriterBannerPattern i = new WriterBannerPattern();
public static WriterBannerPattern get() { return i; } public static WriterBannerPattern get() { return i; }
public WriterBannerPattern()
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active)
{ {
if ( ! active) return; this.addWriterClasses(
this.clearWriters();
this.addWriters(
WriterBannerPatternId.class, WriterBannerPatternId.class,
WriterBannerPatternColor.class WriterBannerPatternColor.class
); );
} }
} }

View File

@ -8,25 +8,15 @@ public class WriterFireworkEffect extends WriterAbstractFireworkEffect<Object, O
private static final WriterFireworkEffect i = new WriterFireworkEffect(); private static final WriterFireworkEffect i = new WriterFireworkEffect();
public static WriterFireworkEffect get() { return i; } public static WriterFireworkEffect get() { return i; }
public WriterFireworkEffect()
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active)
{ {
if ( ! active) return; this.addWriterClasses(
this.clearWriters();
this.addWriters(
WriterFireworkEffectFlicker.class, WriterFireworkEffectFlicker.class,
WriterFireworkEffectTrail.class, WriterFireworkEffectTrail.class,
WriterFireworkEffectColors.class, WriterFireworkEffectColors.class,
WriterFireworkEffectFadeColors.class, WriterFireworkEffectFadeColors.class,
WriterFireworkEffectType.class WriterFireworkEffectType.class
); );
} }
} }

View File

@ -8,18 +8,9 @@ public class WriterItemStack extends WriterAbstractItemStackField<Object, Object
private static final WriterItemStack i = new WriterItemStack(); private static final WriterItemStack i = new WriterItemStack();
public static WriterItemStack get() { return i; } public static WriterItemStack get() { return i; }
public WriterItemStack()
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active)
{ {
if ( ! active) return; this.addWriterClasses(
this.clearWriters();
this.addWriters(
// BASIC // BASIC
WriterItemStackId.class, WriterItemStackId.class,
WriterItemStackCount.class, WriterItemStackCount.class,
@ -30,5 +21,4 @@ public class WriterItemStack extends WriterAbstractItemStackField<Object, Object
); );
} }
} }

View File

@ -8,18 +8,9 @@ public class WriterItemStackMeta extends WriterAbstractItemStackMetaMorph<Object
private static final WriterItemStackMeta i = new WriterItemStackMeta(); private static final WriterItemStackMeta i = new WriterItemStackMeta();
public static WriterItemStackMeta get() { return i; } public static WriterItemStackMeta get() { return i; }
public WriterItemStackMeta()
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active)
{ {
if ( ! active) return; this.addWriterClasses(
this.clearWriters();
this.addWriters(
// UNSPECIFIC // UNSPECIFIC
WriterItemStackMetaName.class, WriterItemStackMetaName.class,
WriterItemStackMetaLore.class, WriterItemStackMetaLore.class,

View File

@ -18,6 +18,9 @@ public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMe
this.setMaterial(Material.BANNER); this.setMaterial(Material.BANNER);
this.setConverterTo(ConverterToBannerPatterns.get()); this.setConverterTo(ConverterToBannerPatterns.get());
this.setConverterFrom(ConverterFromBannerPatterns.get()); this.setConverterFrom(ConverterFromBannerPatterns.get());
this.addDependencyClasses(
WriterBannerPattern.class
);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -16,6 +16,9 @@ public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMe
this.setMaterial(Material.FIREWORK_CHARGE); this.setMaterial(Material.FIREWORK_CHARGE);
this.setConverterTo(ConverterToFireworkEffect.get()); this.setConverterTo(ConverterToFireworkEffect.get());
this.setConverterFrom(ConverterFromFireworkEffect.get()); this.setConverterFrom(ConverterFromFireworkEffect.get());
this.addDependencyClasses(
WriterFireworkEffect.class
);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -18,6 +18,9 @@ public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackM
this.setMaterial(Material.FIREWORK); this.setMaterial(Material.FIREWORK);
this.setConverterTo(ConverterToFireworkEffects.get()); this.setConverterTo(ConverterToFireworkEffects.get());
this.setConverterFrom(ConverterFromFireworkEffects.get()); this.setConverterFrom(ConverterFromFireworkEffects.get());
this.addDependencyClasses(
WriterFireworkEffect.class
);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -18,6 +18,9 @@ public class WriterItemStackMetaPotionEffects extends WriterAbstractItemStackMet
this.setMaterial(Material.POTION); this.setMaterial(Material.POTION);
this.setConverterTo(ConverterToPotionEffects.get()); this.setConverterTo(ConverterToPotionEffects.get());
this.setConverterFrom(ConverterFromPotionEffects.get()); this.setConverterFrom(ConverterFromPotionEffects.get());
this.addDependencyClasses(
WriterPotionEffect.class
);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -8,18 +8,9 @@ public class WriterItemStackMetaState extends WriterAbstractItemStackMetaStateMo
private static final WriterItemStackMetaState i = new WriterItemStackMetaState(); private static final WriterItemStackMetaState i = new WriterItemStackMetaState();
public static WriterItemStackMetaState get() { return i; } public static WriterItemStackMetaState get() { return i; }
public WriterItemStackMetaState()
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active)
{ {
if ( ! active) return; this.addWriterClasses(
this.clearWriters();
this.addWriters(
// SHIELD // SHIELD
WriterItemStackMetaStateShieldBase.class, WriterItemStackMetaStateShieldBase.class,
WriterItemStackMetaStateShieldPatterns.class WriterItemStackMetaStateShieldPatterns.class

View File

@ -18,6 +18,9 @@ public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemSt
this.setMaterial(Material.SHIELD); this.setMaterial(Material.SHIELD);
this.setConverterTo(ConverterToBannerPatterns.get()); this.setConverterTo(ConverterToBannerPatterns.get());
this.setConverterFrom(ConverterFromBannerPatterns.get()); this.setConverterFrom(ConverterFromBannerPatterns.get());
this.addDependencyClasses(
WriterBannerPattern.class
);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -8,18 +8,9 @@ public class WriterPotionEffect extends WriterAbstractPotionEffect<Object, Objec
private static final WriterPotionEffect i = new WriterPotionEffect(); private static final WriterPotionEffect i = new WriterPotionEffect();
public static WriterPotionEffect get() { return i; } public static WriterPotionEffect get() { return i; }
public WriterPotionEffect()
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active)
{ {
if ( ! active) return; this.addWriterClasses(
this.clearWriters();
this.addWriters(
WriterPotionEffectId.class, WriterPotionEffectId.class,
WriterPotionEffectDuraction.class, WriterPotionEffectDuraction.class,
WriterPotionEffectAmplifier.class, WriterPotionEffectAmplifier.class,
@ -27,7 +18,6 @@ public class WriterPotionEffect extends WriterAbstractPotionEffect<Object, Objec
WriterPotionEffectParticles.class, WriterPotionEffectParticles.class,
WriterPotionEffectColor.class WriterPotionEffectColor.class
); );
} }
} }

View File

@ -61,7 +61,7 @@ public class NmsItemStack extends NmsAbstract
// Fill // Fill
if (this.isAvailable()) if (this.isAvailable())
{ {
ret = ReflectionUtil.invokeConstructor(this.constructorCraftItemStack, (Object[])null); ret = ReflectionUtil.invokeConstructor(this.constructorCraftItemStack, (Object)null);
} }
else else
{ {

View File

@ -117,6 +117,11 @@ public class ReflectionUtil
} }
} }
public static <T> T invokeMethod(Method method, Object target, Object argument)
{
return invokeMethod(method, target, new Object[]{argument});
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T invokeMethod(Method method, Object target) public static <T> T invokeMethod(Method method, Object target)
{ {
@ -160,6 +165,11 @@ public class ReflectionUtil
} }
} }
public static <T> T invokeConstructor(Constructor<?> constructor, Object argument)
{
return invokeConstructor(constructor, new Object[]{argument});
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T invokeConstructor(Constructor<?> constructor) public static <T> T invokeConstructor(Constructor<?> constructor)
{ {