Search in sources :

Example 1 with AliasCore

use of com.laytonsmith.core.AliasCore in project CommandHelper by EngineHub.

the class StaticTest method InstallFakeServerFrontend.

/**
 * This installs a fake server frontend. You must have already included
 *
 * @PrepareForTest(Static.class) in the calling test code, which will allow the proper static methods to be mocked.
 */
public static void InstallFakeServerFrontend() {
    if (frontendInstalled) {
        return;
    }
    ClassDiscovery.getDefaultInstance().addDiscoveryLocation(ClassDiscovery.GetClassContainer(Static.class));
    ClassDiscovery.getDefaultInstance().addDiscoveryLocation(ClassDiscovery.GetClassContainer(StaticTest.class));
    ExtensionManager.Initialize(ClassDiscovery.getDefaultInstance());
    Implementation.setServerType(Implementation.Type.TEST);
    AliasCore fakeCore = mock(AliasCore.class);
    fakeCore.autoIncludes = new ArrayList<File>();
    SetPrivate(CommandHelperPlugin.class, "ac", fakeCore, AliasCore.class);
    frontendInstalled = true;
    try {
        Prefs.init(new File("preferences.ini"));
    } catch (IOException ex) {
        Logger.getLogger(StaticTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    CHLog.initialize(new File("."));
}
Also used : AliasCore(com.laytonsmith.core.AliasCore) IOException(java.io.IOException) Static(com.laytonsmith.core.Static) File(java.io.File)

Example 2 with AliasCore

use of com.laytonsmith.core.AliasCore in project CommandHelper by EngineHub.

the class CommandHelperPlugin method onEnable.

/**
 * Called on plugin enable.
 */
@Override
public void onEnable() {
    if (loadingThread.isAlive()) {
        StreamUtils.GetSystemOut().println("[CommandHelper] Waiting for extension loading to complete...");
        try {
            loadingThread.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(CommandHelperPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    myServer = StaticLayer.GetServer();
    BukkitMCEntityType.build();
    BukkitMCBiomeType.build();
    BukkitMCSound.build();
    // Metrics
    try {
        Metrics m = new Metrics(this);
        Metrics.Graph graph = m.createGraph("Player count");
        graph.addPlotter(new Metrics.Plotter("Player count") {

            @Override
            public int getValue() {
                return Static.getServer().getOnlinePlayers().size();
            }
        });
        m.addGraph(graph);
        m.start();
    } catch (IOException e) {
    // Failed to submit the stats :-(
    }
    try {
        // This may seem redundant, but on a /reload, we want to refresh these
        // properties.
        Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile());
    } catch (IOException ex) {
        Logger.getLogger(CommandHelperPlugin.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (Prefs.UseSudoFallback()) {
        Logger.getLogger(CommandHelperPlugin.class.getName()).log(Level.WARNING, "In your preferences, use-sudo-fallback is turned on. Consider turning this off if you can.");
    }
    CHLog.initialize(CommandHelperFileLocations.getDefault().getConfigDirectory());
    version = new SimpleVersion(getDescription().getVersion());
    String script_name = Prefs.ScriptName();
    String main_file = Prefs.MainFile();
    boolean showSplashScreen = Prefs.ShowSplashScreen();
    if (showSplashScreen) {
        StreamUtils.GetSystemOut().println(TermColors.reset());
        // StreamUtils.GetSystemOut().flush();
        StreamUtils.GetSystemOut().println("\n\n" + Static.Logo());
    }
    ac = new AliasCore(new File(CommandHelperFileLocations.getDefault().getConfigDirectory(), script_name), CommandHelperFileLocations.getDefault().getLocalPackagesDirectory(), CommandHelperFileLocations.getDefault().getPreferencesFile(), new File(CommandHelperFileLocations.getDefault().getConfigDirectory(), main_file), this);
    ac.reload(null, null, true);
    // Clear out our hostname cache
    hostnameLookupCache = new ConcurrentHashMap<>();
    // Create a new thread pool, with a custom ThreadFactory,
    // so we can more clearly name our threads.
    hostnameLookupThreadPool = Executors.newFixedThreadPool(3, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "CommandHelperHostnameLookup-" + (++hostnameThreadPoolID));
        }
    });
    for (Player p : getServer().getOnlinePlayers()) {
        // Repopulate our cache for currently online players.
        // New players that join later will get a lookup done
        // on them at that time.
        Static.HostnameCache(p.getName(), p.getAddress());
    }
    BukkitDirtyRegisteredListener.PlayDirty();
    registerEvents(playerListener);
    // interpreter events
    registerEvents(interpreterListener);
    registerEvents(serverListener);
    // Script events
    StaticLayer.Startup(this);
    playerListener.loadGlobalAliases();
    interpreterListener.reload();
    Static.getLogger().log(Level.INFO, "[CommandHelper] CommandHelper {0} enabled", getDescription().getVersion());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) Player(org.bukkit.entity.Player) BukkitMCPlayer(com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer) MCPlayer(com.laytonsmith.abstraction.MCPlayer) AliasCore(com.laytonsmith.core.AliasCore) IOException(java.io.IOException) Metrics(org.mcstats.Metrics) SimpleVersion(com.laytonsmith.PureUtilities.SimpleVersion) File(java.io.File)

Aggregations

AliasCore (com.laytonsmith.core.AliasCore)2 File (java.io.File)2 IOException (java.io.IOException)2 SimpleVersion (com.laytonsmith.PureUtilities.SimpleVersion)1 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 BukkitMCPlayer (com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer)1 Static (com.laytonsmith.core.Static)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Player (org.bukkit.entity.Player)1 Metrics (org.mcstats.Metrics)1