Search in sources :

Example 1 with CommandLimbo

use of me.semx11.autotip.command.impl.CommandLimbo in project Hyperium by HyperiumClient.

the class Autotip method setup.

private void setup() {
    try {
        fileUtil = new FileUtil(this);
        gson = new GsonBuilder().registerTypeAdapter(Config.class, new ConfigCreator(this)).registerTypeAdapter(StatsDaily.class, new StatsDailyCreator(this)).setExclusionStrategies(new AnnotationExclusionStrategy()).setPrettyPrinting().create();
        config = new Config(this);
        reloadGlobalSettings();
        reloadLocale();
        sessionManager = new SessionManager(this);
        statsManager = new StatsManager(this);
        migrationManager = new MigrationManager(this);
        fileUtil.createDirectories();
        config.load();
        taskManager.getExecutor().execute(() -> migrationManager.migrateLegacyFiles());
        registerEvents(new EventClientConnection(this), new EventChatReceived(this));
        registerCommands(new CommandAutotip(this), new CommandLimbo(this));
        Runtime.getRuntime().addShutdownHook(new Thread(sessionManager::logout));
        initialized = true;
    } catch (IOException e) {
        messageUtil.send("Autotip is disabled because it couldn't create the required files.");
        ErrorReport.reportException(e);
    } catch (IllegalStateException e) {
        messageUtil.send("Autotip is disabled because it couldn't connect to the API.");
        ErrorReport.reportException(e);
    }
}
Also used : ConfigCreator(me.semx11.autotip.gson.creator.ConfigCreator) CommandAutotip(me.semx11.autotip.command.impl.CommandAutotip) GsonBuilder(com.google.gson.GsonBuilder) EventClientConnection(me.semx11.autotip.event.impl.EventClientConnection) Config(me.semx11.autotip.config.Config) SessionManager(me.semx11.autotip.core.SessionManager) CommandLimbo(me.semx11.autotip.command.impl.CommandLimbo) StatsDailyCreator(me.semx11.autotip.gson.creator.StatsDailyCreator) IOException(java.io.IOException) MigrationManager(me.semx11.autotip.core.MigrationManager) AnnotationExclusionStrategy(me.semx11.autotip.gson.exclusion.AnnotationExclusionStrategy) StatsManager(me.semx11.autotip.core.StatsManager) EventChatReceived(me.semx11.autotip.event.impl.EventChatReceived) FileUtil(me.semx11.autotip.util.FileUtil)

Example 2 with CommandLimbo

use of me.semx11.autotip.command.impl.CommandLimbo in project Hyperium by HyperiumClient.

the class EventChatReceived method onChat.

@InvokeEvent
public void onChat(ServerChatEvent event) {
    Config config = autotip.getConfig();
    if (!autotip.getSessionManager().isOnHypixel()) {
        return;
    }
    String msg = UniversalUtil.getUnformattedText(event);
    CommandLimbo limboCommand = autotip.getCommand(CommandLimbo.class);
    if (limboCommand.hasExecuted()) {
        if (msg.startsWith("A kick occurred in your connection")) {
            event.setCancelled(true);
        } else if (msg.startsWith("Illegal characters in chat")) {
            event.setCancelled(true);
            limboCommand.setExecuted(false);
        }
    }
    if (!config.isEnabled())
        return;
    GlobalSettings settings = autotip.getGlobalSettings();
    MessageOption option = config.getMessageOption();
    for (Message message : settings.getMessages()) {
        MessageMatcher matcher = message.getMatcherFor(msg);
        if (matcher.matches()) {
            event.setCancelled(message.shouldHide(option));
            return;
        }
    }
    String hover = UniversalUtil.getHoverText(event);
    settings.getStatsMessages().forEach(message -> {
        StatsMessageMatcher matcher = message.getMatcherFor(msg);
        if (!matcher.matches())
            return;
        StatsDaily stats = getStats();
        matcher.applyStats(stats);
        message.applyHoverStats(hover, stats);
        event.setCancelled(message.shouldHide(option));
    });
}
Also used : StatsMessageMatcher(me.semx11.autotip.message.StatsMessageMatcher) MessageMatcher(me.semx11.autotip.message.MessageMatcher) StatsMessageMatcher(me.semx11.autotip.message.StatsMessageMatcher) Message(me.semx11.autotip.message.Message) Config(me.semx11.autotip.config.Config) CommandLimbo(me.semx11.autotip.command.impl.CommandLimbo) MessageOption(me.semx11.autotip.chat.MessageOption) GlobalSettings(me.semx11.autotip.config.GlobalSettings) StatsDaily(me.semx11.autotip.stats.StatsDaily) InvokeEvent(cc.hyperium.event.InvokeEvent)

Aggregations

CommandLimbo (me.semx11.autotip.command.impl.CommandLimbo)2 Config (me.semx11.autotip.config.Config)2 InvokeEvent (cc.hyperium.event.InvokeEvent)1 GsonBuilder (com.google.gson.GsonBuilder)1 IOException (java.io.IOException)1 MessageOption (me.semx11.autotip.chat.MessageOption)1 CommandAutotip (me.semx11.autotip.command.impl.CommandAutotip)1 GlobalSettings (me.semx11.autotip.config.GlobalSettings)1 MigrationManager (me.semx11.autotip.core.MigrationManager)1 SessionManager (me.semx11.autotip.core.SessionManager)1 StatsManager (me.semx11.autotip.core.StatsManager)1 EventChatReceived (me.semx11.autotip.event.impl.EventChatReceived)1 EventClientConnection (me.semx11.autotip.event.impl.EventClientConnection)1 ConfigCreator (me.semx11.autotip.gson.creator.ConfigCreator)1 StatsDailyCreator (me.semx11.autotip.gson.creator.StatsDailyCreator)1 AnnotationExclusionStrategy (me.semx11.autotip.gson.exclusion.AnnotationExclusionStrategy)1 Message (me.semx11.autotip.message.Message)1 MessageMatcher (me.semx11.autotip.message.MessageMatcher)1 StatsMessageMatcher (me.semx11.autotip.message.StatsMessageMatcher)1 StatsDaily (me.semx11.autotip.stats.StatsDaily)1