Automatic activation of engines, colls, commands and others

This commit is contained in:
Magnus Ulf Jørgensen 2017-03-10 16:23:26 +01:00
parent d3fc83386d
commit fe81648eb7
46 changed files with 632 additions and 459 deletions

View File

@ -2,7 +2,7 @@ package com.massivecraft.massivecore;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCore;
import com.massivecraft.massivecore.cmd.CmdMassiveCore;
import com.massivecraft.massivecore.command.requirement.Requirement;
import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;

View File

@ -35,7 +35,7 @@ public abstract class Engine implements Active, Listener, Runnable
if (this.hasPlugin()) return;
this.plugin = plugin;
}
// -------------------------------------------- //
// TASK
// -------------------------------------------- //

View File

@ -28,70 +28,18 @@ import com.massivecraft.massivecore.collections.MassiveTreeMap;
import com.massivecraft.massivecore.collections.MassiveTreeMapDef;
import com.massivecraft.massivecore.collections.MassiveTreeSet;
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCore;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreBuffer;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreClick;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreCmdurl;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreStore;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreUsys;
import com.massivecraft.massivecore.command.type.RegistryType;
import com.massivecraft.massivecore.engine.EngineMassiveCoreChestGui;
import com.massivecraft.massivecore.engine.EngineMassiveCoreCollTick;
import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandRegistration;
import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandSet;
import com.massivecraft.massivecore.engine.EngineMassiveCoreDatabase;
import com.massivecraft.massivecore.engine.EngineMassiveCoreDestination;
import com.massivecraft.massivecore.engine.EngineMassiveCoreGank;
import com.massivecraft.massivecore.engine.EngineMassiveCoreLorePriority;
import com.massivecraft.massivecore.engine.EngineMassiveCoreMain;
import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerLeave;
import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerState;
import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerUpdate;
import com.massivecraft.massivecore.engine.EngineMassiveCoreScheduledTeleport;
import com.massivecraft.massivecore.engine.EngineMassiveCoreSponsor;
import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause;
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud;
import com.massivecraft.massivecore.integration.vault.IntegrationVault;
import com.massivecraft.massivecore.item.DataBannerPattern;
import com.massivecraft.massivecore.item.WriterItemStack;
import com.massivecraft.massivecore.mixin.MixinActionbar;
import com.massivecraft.massivecore.mixin.MixinActual;
import com.massivecraft.massivecore.mixin.MixinCommand;
import com.massivecraft.massivecore.mixin.MixinDisplayName;
import com.massivecraft.massivecore.mixin.MixinEvent;
import com.massivecraft.massivecore.mixin.MixinGamemode;
import com.massivecraft.massivecore.mixin.MixinInventory;
import com.massivecraft.massivecore.mixin.MixinKick;
import com.massivecraft.massivecore.mixin.MixinLog;
import com.massivecraft.massivecore.mixin.MixinMassiveCraftPremium;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.mixin.MixinModification;
import com.massivecraft.massivecore.mixin.MixinPlayed;
import com.massivecraft.massivecore.mixin.MixinSenderPs;
import com.massivecraft.massivecore.mixin.MixinTeleport;
import com.massivecraft.massivecore.mixin.MixinTitle;
import com.massivecraft.massivecore.mixin.MixinVisibility;
import com.massivecraft.massivecore.mixin.MixinWorld;
import com.massivecraft.massivecore.mson.Mson;
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;
import com.massivecraft.massivecore.nms.NmsItemStackTooltip;
import com.massivecraft.massivecore.nms.NmsPermissions;
import com.massivecraft.massivecore.nms.NmsPlayerInventoryCreate;
import com.massivecraft.massivecore.nms.NmsSkullMeta;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSAdapter;
import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.ModificationPollerLocal;
import com.massivecraft.massivecore.store.ModificationPollerRemote;
import com.massivecraft.massivecore.test.TestTypeEnchantment;
import com.massivecraft.massivecore.util.BoardUtil;
import com.massivecraft.massivecore.util.ContainerUtil;
import com.massivecraft.massivecore.util.EventUtil;
@ -123,6 +71,7 @@ import org.bukkit.inventory.PlayerInventory;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
@ -197,7 +146,7 @@ public class MassiveCore extends MassivePlugin
ret.registerTypeAdapter(PS.class, PSAdapter.get());
ret.registerTypeAdapter(Sound.class, AdapterSound.get());
ret.registerTypeAdapter(UUID.class, AdapterUUID.get());
// Mson
ret.registerTypeAdapter(Mson.class, AdapterMson.get());
ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.get());
@ -277,87 +226,19 @@ public class MassiveCore extends MassivePlugin
RegistryType.registerAll();
// Activate
this.activateAuto();
// These must be activated after nms
this.activate(
// Coll
MultiverseColl.class,
AspectColl.class,
MassiveCoreMConfColl.class,
MassiveCoreMSponsorInfoColl.class,
// Nms
NmsBasics.class,
NmsBoard.class,
NmsChat.class,
NmsEntityDamageEvent.class,
NmsEntityGet.class,
NmsItemStackCreate.class,
NmsItemStackTooltip.class,
NmsPermissions.class,
NmsPlayerInventoryCreate.class,
NmsSkullMeta.class,
// Writer,
WriterItemStack.class,
// Engine
EngineMassiveCoreChestGui.class,
EngineMassiveCoreCollTick.class,
EngineMassiveCoreCommandRegistration.class,
EngineMassiveCoreCommandSet.class,
EngineMassiveCoreDatabase.class,
EngineMassiveCoreDestination.class,
EngineMassiveCoreGank.class,
EngineMassiveCoreLorePriority.class,
EngineMassiveCoreMain.class,
EngineMassiveCorePlayerLeave.class,
EngineMassiveCorePlayerState.class,
EngineMassiveCorePlayerUpdate.class,
EngineMassiveCoreScheduledTeleport.class,
EngineMassiveCoreTeleportMixinCause.class,
EngineMassiveCoreVariable.class,
EngineMassiveCoreWorldNameSet.class,
EngineMassiveCoreSponsor.class,
// Util
PlayerUtil.class,
BoardUtil.class,
// Integration
IntegrationVault.class,
IntegrationLiabilityAreaEffectCloud.class,
// Command
CmdMassiveCore.class,
CmdMassiveCoreUsys.class,
CmdMassiveCoreStore.class,
CmdMassiveCoreBuffer.class,
CmdMassiveCoreCmdurl.class,
CmdMassiveCoreClick.class,
// Mixin
MixinEvent.class, // NOTE: Should be first
MixinActionbar.class,
MixinActual.class,
MixinCommand.class,
MixinDisplayName.class,
MixinGamemode.class,
MixinInventory.class,
MixinKick.class,
MixinLog.class,
MixinMassiveCraftPremium.class,
MixinMessage.class,
MixinModification.class,
MixinPlayed.class,
MixinSenderPs.class,
MixinTeleport.class,
MixinTitle.class,
MixinVisibility.class,
MixinWorld.class,
// Test
TestTypeEnchantment.class
BoardUtil.class
);
// Start the examine threads
// Start AFTER initializing the MConf, because they rely on the MConf.
ModificationPollerLocal.get().start();
@ -367,6 +248,25 @@ public class MassiveCore extends MassivePlugin
MassiveCoreTaskDeleteFiles.get().run();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, MassiveCoreTaskDeleteFiles.get());
}
@Override
public List<Class<?>> getClassesActiveColls()
{
List<Class<?>> ret = this.getClassesActive(null, Coll.class);
return ret;
}
@Override
public List<Class<?>> getClassesActiveMixins()
{
List<Class<?>> ret = super.getClassesActiveMixins();
ret.remove(MixinEvent.class);
ret.add(0, MixinEvent.class);
return ret;
}
// -------------------------------------------- //
// DISABLE

View File

@ -143,6 +143,7 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
// -------------------------------------------- //
public boolean debugWriters = false;
public boolean debugActives = false;
public boolean testsEnabled = false;
// -------------------------------------------- //

View File

@ -25,4 +25,4 @@ public class MassiveCoreTaskDeleteFiles implements Runnable
}
}
}
}

View File

@ -2,7 +2,13 @@ package com.massivecraft.massivecore;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateAnd;
import com.massivecraft.massivecore.predicate.PredicateIsClassSingleton;
import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
import com.massivecraft.massivecore.test.Test;
import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.xlib.gson.Gson;
@ -14,6 +20,8 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -198,24 +206,59 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
this.log(Txt.parse("<b>Now I suicide!"));
Bukkit.getPluginManager().disablePlugin(this);
}
public void activate(Object... objects)
{
for (Object object : objects)
{
Active active = asActive(object);
if (active == null) continue;
active.setActive(this);
}
this.activateOne(objects);
}
// We must get one active at a time because initialisation of some
// can only happen after others have been initialised.
public void activateOne(Object object)
{
boolean debug = MassiveCoreMConf.get() != null && MassiveCoreMConf.get().debugActives;
// Try collection
if (object instanceof Iterable)
{
Iterable<?> elements = (Iterable) object;
for (Object element : elements)
{
this.activateOne(element);
}
return;
}
// Try array
if (object instanceof Object[])
{
Object[] array = (Object[]) object;
activateOne(Arrays.asList(array));
return;
}
Active active = asActive(object);
if (active == null) return;
if (active.isActive())
{
if (debug) log(Txt.parse("<h>%s <b>is already active.", active.getClass().getSimpleName()));
}
active.setActive(this);
if (debug) log(Txt.parse("<i>Activating <h>%s<i>.", active.getClass().getSimpleName()));
}
private static Active asActive(Object object)
{
// Active already
if (object instanceof Active)
{
return (Active)object;
return (Active) object;
}
// Try string as class name
if (object instanceof String)
{
String string = (String)object;
@ -229,19 +272,21 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
return null;
}
}
// Try class
if (object instanceof Class<?>)
{
Class<?> clazz = (Class<?>)object;
if ( ! Active.class.isAssignableFrom(clazz)) throw new IllegalArgumentException("Not Active Class: " + (clazz == null ? "NULL" : clazz));
Object instance = ReflectionUtil.getSingletonInstance(clazz);
if ( ! (instance instanceof Active)) throw new IllegalArgumentException("Not Active Instance: " + (instance == null ? "NULL" : instance) + " for object: " + (object == null ? "NULL" : object));
Active active = (Active)instance;
return active;
}
// No success
throw new IllegalArgumentException("Neither Active nor Class: " + object);
}
@ -266,10 +311,135 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
active.setActive(false);
}
}
// -------------------------------------------- //
// ACTIVATE AUTO
// -------------------------------------------- //
public void activateAuto()
{
// And activate them
this.activate(getClassesActive());
}
public List<Class<?>> getClassesActive()
{
List<Class<?>> ret = new MassiveList<>();
// Fill with all kinds of Actives
ret.addAll(this.getClassesActiveMigrators());
ret.addAll(this.getClassesActiveColls());
ret.addAll(this.getClassesActiveNms());
ret.addAll(this.getClassesActiveCommands());
ret.addAll(this.getClassesActiveEngines());
ret.addAll(this.getClassesActiveIntegrations());
ret.addAll(this.getClassesActiveTasks());
ret.addAll(this.getClassesActiveMixins());
ret.addAll(this.getClassesActiveTests());
return ret;
}
public List<Class<?>> getClassesActiveColls()
{
return getClassesActive("entity", Coll.class);
}
public List<Class<?>> getClassesActiveNms()
{
return getClassesActive("nms", Mixin.class, new Predicate<Class<?>>()
{
@Override
public boolean apply(Class<?> clazz)
{
try
{
ReflectionUtil.getField(clazz, "d");
return true;
}
catch (Exception ex)
{
return false;
}
}
}
);
}
public List<Class<?>> getClassesActiveCommands()
{
return getClassesActive("cmd", MassiveCommand.class);
}
public List<Class<?>> getClassesActiveEngines()
{
return getClassesActive(Engine.class);
}
public List<Class<?>> getClassesActiveIntegrations()
{
return getClassesActive(Integration.class);
}
public List<Class<?>> getClassesActiveTasks()
{
return getClassesActive("task", ModuloRepeatTask.class);
}
public List<Class<?>> getClassesActiveMixins()
{
return getClassesActive(Mixin.class);
}
public List<Class<?>> getClassesActiveTests()
{
return getClassesActive(Test.class);
}
public List<Class<?>> getClassesActiveMigrators()
{
return getClassesActive("entity.migrator", MigratorRoot.class);
}
public List<Class<?>> getClassesActive(Class<? extends Active> superClass, Predicate<Class<?>>... predicates)
{
return getClassesActive(superClass.getSimpleName().toLowerCase(), superClass);
}
@SuppressWarnings("unchecked")
public List<Class<?>> getClassesActive(String packageName, final Class<?> superClass, Predicate<Class<?>>... predicates)
{
if (!Active.class.isAssignableFrom(superClass)) throw new IllegalArgumentException(superClass.getName() + " is not insatnce of Active.");
packageName = packageName == null ? "" : "." + packageName;
packageName = this.getClass().getPackage().getName() + packageName;
Predicate predicateCombined = PredicateAnd.get(predicates);
Predicate<Class<?>> predicateNotAbstract = new Predicate<Class<?>>()
{
@Override
public boolean apply(Class<?> type)
{
return !Modifier.isAbstract(type.getModifiers());
}
};
Predicate<Class<?>> predicateSubclass = new Predicate<Class<?>>()
{
@Override
public boolean apply(Class<?> type)
{
return superClass.isAssignableFrom(type);
}
};
Predicate<Class<?>> predicateSingleton = PredicateIsClassSingleton.get();
return ReflectionUtil.getPackageClasses(packageName, this.getClassLoader(), true, predicateCombined, predicateNotAbstract, predicateSubclass, predicateSingleton);
}
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //
private String logPrefixColored = null;
private String logPrefixPlain = null;
public void log(Object... msg)

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveCoreMConf;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCoreMConf;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeString;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeString;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,127 +1,128 @@
package com.massivecraft.massivecore.command.massivecore;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.util.WebUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public class CmdMassiveCoreCmdurl extends MassiveCoreCommand
{
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static CmdMassiveCoreCmdurl i = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesCmdurl; } };
public static CmdMassiveCoreCmdurl get() { return i; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdMassiveCoreCmdurl()
{
// Parameters
this.addParameter(TypeString.get(), "url").setDesc("the url to load");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
String urlString = this.readArg();
final URL url;
try
{
url = new URL(urlString);
}
catch (MalformedURLException e)
{
msg("<b>Malformed URL: %s", e.getMessage());
return;
}
// Apply
final Player commander = me;
msg("<i>Loading <aqua>%s <i>...", urlString);
async(new Runnable()
{
@Override
public void run()
{
try
{
final List<String> lines = WebUtil.getLines(url);
sync(new Runnable()
{
@Override
public void run()
{
MixinMessage.get().msgOne(commander, "<i>... <h>%d <i>lines loaded. Now executing ...", lines.size());
for (int i = 0; i <= lines.size() - 1; i++)
{
String line = lines.get(i);
line = line.trim();
if (line.length() == 0 || line.startsWith("#"))
{
MixinMessage.get().msgOne(commander, "<b>#%d: <i>%s", i, line);
// Ignore the line
}
else
{
MixinMessage.get().msgOne(commander, "<g>#%d: <i>%s", i, line);
// Run the line
commander.chat(line);
}
}
}
});
return;
}
catch (final Exception e)
{
sync(new Runnable()
{
@Override
public void run()
{
MixinMessage.get().msgOne(commander, "<b>%s: %s", e.getClass().getSimpleName(), e.getMessage());
}
});
return;
}
}
});
}
// -------------------------------------------- //
// ASYNC/SYNC SHORTHANDS
// -------------------------------------------- //
public static void sync(Runnable runnable)
{
Bukkit.getScheduler().runTask(MassiveCore.get(), runnable);
}
public static void async(Runnable runnable)
{
Bukkit.getScheduler().runTaskAsynchronously(MassiveCore.get(), runnable);
}
}
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.util.WebUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public class CmdMassiveCoreCmdurl extends MassiveCoreCommand
{
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static CmdMassiveCoreCmdurl i = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesCmdurl; } };
public static CmdMassiveCoreCmdurl get() { return i; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdMassiveCoreCmdurl()
{
// Parameters
this.addParameter(TypeString.get(), "url").setDesc("the url to load");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
String urlString = this.readArg();
final URL url;
try
{
url = new URL(urlString);
}
catch (MalformedURLException e)
{
msg("<b>Malformed URL: %s", e.getMessage());
return;
}
// Apply
final Player commander = me;
msg("<i>Loading <aqua>%s <i>...", urlString);
async(new Runnable()
{
@Override
public void run()
{
try
{
final List<String> lines = WebUtil.getLines(url);
sync(new Runnable()
{
@Override
public void run()
{
MixinMessage.get().msgOne(commander, "<i>... <h>%d <i>lines loaded. Now executing ...", lines.size());
for (int i = 0; i <= lines.size() - 1; i++)
{
String line = lines.get(i);
line = line.trim();
if (line.length() == 0 || line.startsWith("#"))
{
MixinMessage.get().msgOne(commander, "<b>#%d: <i>%s", i, line);
// Ignore the line
}
else
{
MixinMessage.get().msgOne(commander, "<g>#%d: <i>%s", i, line);
// Run the line
commander.chat(line);
}
}
}
});
return;
}
catch (final Exception e)
{
sync(new Runnable()
{
@Override
public void run()
{
MixinMessage.get().msgOne(commander, "<b>%s: %s", e.getClass().getSimpleName(), e.getMessage());
}
});
return;
}
}
});
}
// -------------------------------------------- //
// ASYNC/SYNC SHORTHANDS
// -------------------------------------------- //
public static void sync(Runnable runnable)
{
Bukkit.getScheduler().runTask(MassiveCore.get(), runnable);
}
public static void async(Runnable runnable)
{
Bukkit.getScheduler().runTaskAsynchronously(MassiveCore.get(), runnable);
}
}

View File

@ -1,43 +1,43 @@
package com.massivecraft.massivecore.command.massivecore;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.SoundEffect;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect;
import com.massivecraft.massivecore.command.type.container.TypeList;
import java.util.List;
public class CmdMassiveCoreHearsound extends MassiveCoreCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdMassiveCoreHearsound()
{
// Aliases
this.addAliases("hearsounds");
// Parameters
this.addParameter(TypeList.get(TypeSoundEffect.get()), "sound(s)", true).setDesc("the sounds to hear");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
List<SoundEffect> soundEffects = this.readArg();
// Apply
SoundEffect.runAll(soundEffects, me);
}
}
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.SoundEffect;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect;
import com.massivecraft.massivecore.command.type.container.TypeList;
import java.util.List;
public class CmdMassiveCoreHearsound extends MassiveCoreCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdMassiveCoreHearsound()
{
// Aliases
this.addAliases("hearsounds");
// Parameters
this.addParameter(TypeList.get(TypeSoundEffect.get()), "sound(s)", true).setDesc("the sounds to hear");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
List<SoundEffect> soundEffects = this.readArg();
// Apply
SoundEffect.runAll(soundEffects, me);
}
}

View File

@ -1,17 +1,17 @@
package com.massivecraft.massivecore.command.massivecore;
import com.massivecraft.massivecore.ConfServer;
public class CmdMassiveCoreId extends MassiveCoreCommand
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
this.msg("<i>The id of this server is \"<h>%s<i>\".", ConfServer.serverid);
}
}
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.ConfServer;
public class CmdMassiveCoreId extends MassiveCoreCommand
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
this.msg("<i>The id of this server is \"<h>%s<i>\".", ConfServer.serverid);
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.MassiveCorePerm;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCoreMConf;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.ConfServer;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.store.TypeColl;

View File

@ -1,94 +1,94 @@
package com.massivecraft.massivecore.command.massivecore;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.Visibility;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.command.type.TypeItemStack;
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.InventoryUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class CmdMassiveCoreTest extends MassiveCoreCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdMassiveCoreTest()
{
// Parameters
this.addParameter(false, TypeBooleanYes.get(), "set", "no");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
// VisibilityMode
this.setVisibility(Visibility.SECRET);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
boolean set = this.readArg();
if (set)
{
InventoryUtil.setHelmet(me, new ItemStack(Material.DIAMOND_HELMET));
InventoryUtil.setChestplate(me, new ItemStack(Material.DIAMOND_CHESTPLATE));
InventoryUtil.setLeggings(me, new ItemStack(Material.DIAMOND_LEGGINGS));
InventoryUtil.setBoots(me, new ItemStack(Material.DIAMOND_BOOTS));
InventoryUtil.setWeapon(me, new ItemStack(Material.DIAMOND_SWORD));
InventoryUtil.setShield(me, new ItemStack(Material.DIRT));
}
inform("helmet", InventoryUtil.getHelmet(me));
inform("chestplate", InventoryUtil.getChestplate(me));
inform("leggings", InventoryUtil.getLeggings(me));
inform("boots", InventoryUtil.getBoots(me));
inform("weapon", InventoryUtil.getWeapon(me));
inform("shield", InventoryUtil.getShield(me));
inform("all", InventoryUtil.getContentsAll(me.getInventory()));
inform("storage", InventoryUtil.getContentsStorage(me.getInventory()));
inform("armor", InventoryUtil.getContentsArmor(me.getInventory()));
inform("extra", InventoryUtil.getContentsExtra(me.getInventory()));
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public Mson visualize(ItemStack item)
{
return TypeItemStack.get().getVisualMson(item, sender);
}
public Mson visualize(ItemStack... items)
{
List<Mson> msons = new MassiveList<>(Mson.mson(String.valueOf(items.length)).color(ChatColor.AQUA));
for (ItemStack item : items)
{
msons.add(visualize(item));
}
return Mson.implode(msons, Mson.SPACE);
}
public void inform(String key, ItemStack... items)
{
message(mson(key, ": ", visualize(items)));
}
}
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.Visibility;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.command.type.TypeItemStack;
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.InventoryUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class CmdMassiveCoreTest extends MassiveCoreCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdMassiveCoreTest()
{
// Parameters
this.addParameter(false, TypeBooleanYes.get(), "set", "no");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
// VisibilityMode
this.setVisibility(Visibility.SECRET);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
boolean set = this.readArg();
if (set)
{
InventoryUtil.setHelmet(me, new ItemStack(Material.DIAMOND_HELMET));
InventoryUtil.setChestplate(me, new ItemStack(Material.DIAMOND_CHESTPLATE));
InventoryUtil.setLeggings(me, new ItemStack(Material.DIAMOND_LEGGINGS));
InventoryUtil.setBoots(me, new ItemStack(Material.DIAMOND_BOOTS));
InventoryUtil.setWeapon(me, new ItemStack(Material.DIAMOND_SWORD));
InventoryUtil.setShield(me, new ItemStack(Material.DIRT));
}
inform("helmet", InventoryUtil.getHelmet(me));
inform("chestplate", InventoryUtil.getChestplate(me));
inform("leggings", InventoryUtil.getLeggings(me));
inform("boots", InventoryUtil.getBoots(me));
inform("weapon", InventoryUtil.getWeapon(me));
inform("shield", InventoryUtil.getShield(me));
inform("all", InventoryUtil.getContentsAll(me.getInventory()));
inform("storage", InventoryUtil.getContentsStorage(me.getInventory()));
inform("armor", InventoryUtil.getContentsArmor(me.getInventory()));
inform("extra", InventoryUtil.getContentsExtra(me.getInventory()));
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public Mson visualize(ItemStack item)
{
return TypeItemStack.get().getVisualMson(item, sender);
}
public Mson visualize(ItemStack... items)
{
List<Mson> msons = new MassiveList<>(Mson.mson(String.valueOf(items.length)).color(ChatColor.AQUA));
for (ItemStack item : items)
{
msons.add(visualize(item));
}
return Mson.implode(msons, Mson.SPACE);
}
public void inform(String key, ItemStack... items)
{
message(mson(key, ": ", visualize(items)));
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCoreMConf;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
public class CmdMassiveCoreUsysAspect extends MassiveCoreCommand
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.Aspect;
import com.massivecraft.massivecore.AspectColl;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.Aspect;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.Aspect;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
public class CmdMassiveCoreUsysMultiverse extends MassiveCoreCommand
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Multiverse;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.MultiverseColl;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.Aspect;
import com.massivecraft.massivecore.MassiveCore;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
public class CmdMassiveCoreUsysUniverse extends MassiveCoreCommand
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveException;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Multiverse;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Multiverse;

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.command.massivecore;
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.MassiveCorePerm;
import com.massivecraft.massivecore.command.MassiveCommand;

View File

@ -40,6 +40,8 @@ public class CommandEditSingleton<O> extends CommandEditProperties<O, O>
@SuppressWarnings("unchecked")
private static <O> Type<O> getType(O object)
{
if (object == null) throw new NullPointerException("object");
// Get the return value
Type<O> ret = TypeSingleton.get(object);

View File

@ -93,7 +93,8 @@ public class Mixin extends Engine
}
catch (Throwable t)
{
throw ReflectionUtil.asRuntimeException(t);
t.printStackTrace();
//throw ReflectionUtil.asRuntimeException(t);
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.predicate;
import com.massivecraft.massivecore.util.ReflectionUtil;
public class PredicateIsClassSingleton implements Predicate<Class<?>>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PredicateIsClassSingleton i = new PredicateIsClassSingleton();
public static PredicateIsClassSingleton get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean apply(Class clazz)
{
return ReflectionUtil.isSingleton(clazz);
}
}

View File

@ -978,4 +978,3 @@ public final class PS implements Serializable, Comparable<PS>
}
}

View File

@ -9,6 +9,7 @@ import com.massivecraft.massivecore.util.Txt;
import java.util.List;
public abstract class Test extends Engine
{
// -------------------------------------------- //

View File

@ -1,8 +1,14 @@
package com.massivecraft.massivecore.util;
import com.google.common.reflect.ClassPath;
import com.google.common.reflect.ClassPath.ClassInfo;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateAnd;
import org.bukkit.Bukkit;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@ -12,6 +18,7 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class ReflectionUtil
@ -243,6 +250,19 @@ public class ReflectionUtil
}
return fallback;
}
public static boolean isSingleton(Class<?> clazz)
{
try
{
Method get = getMethod(clazz, "get");
return true;
}
catch (Exception ex)
{
return false;
}
}
// -------------------------------------------- //
// ANNOTATION
@ -422,7 +442,61 @@ public class ReflectionUtil
}
});
}
// -------------------------------------------- //
// GET PACKAGE CLASSES
// -------------------------------------------- //
@SuppressWarnings("unchecked")
public static List<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader, boolean recursive, Predicate<Class<?>>... predicates)
{
// Create ret
List<Class<?>> ret = new MassiveList<>();
try
{
// Get info
ClassPath classPath = ClassPath.from(classLoader);
Predicate<Class<?>> predicateCombined = PredicateAnd.get(predicates);
Collection<ClassInfo> classes = recursive ? classPath.getTopLevelClassesRecursive(packageName) : classPath.getTopLevelClasses(packageName);
for (ClassInfo classInfo : classes)
{
// Get name of class
String className = classInfo.getName();
// Avoid versions created at runtime
// Apparently it found a "EngineMassiveCoreCollTick 3" which we don't want
if (className.contains(" ")) continue;
// Try and load it
Class<?> clazz;
try
{
clazz = classInfo.load();
}
catch (NoClassDefFoundError ex)
{
// This thing couldn't be loaded. Probably has to do with integrations.
// Just skip it
continue;
}
// And it must not be ignored
if (!predicateCombined.apply(clazz)) continue;
ret.add(clazz);
}
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
return ret;
}
// -------------------------------------------- //
// AS RUNTIME EXCEPTION
// -------------------------------------------- //

View File

@ -2,7 +2,7 @@ package com.massivecraft.massivecore.util;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCore;
import com.massivecraft.massivecore.cmd.CmdMassiveCore;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.mson.MsonEvent;
import com.massivecraft.massivecore.predicate.Predicate;