L2JMobius

Events + Voicecommand?

thxforlove · 1 · 1981

Offline thxforlove

  • Vassal
  • *
    • Posts: 7
Code: [Select]
private static final HashMap<Integer, Future<?>> AUTO_POTION_TASKS = new HashMap<>();
private static final int POTION_TASK_DELAY = 1000; // 1 second

private static final String[] VOICED_COMMANDS =
{
"apon",
"apoff"
};

@Override
public boolean useVoicedCommand(String command, PlayerInstance activeChar, String target)
{
if (!Config.AUTO_POTIONS_ENABLED || (activeChar == null))
{
return false;
}
if (activeChar.getLevel() < Config.AUTO_POTION_MIN_LVL)
{
activeChar.sendMessage("You need to be at least " + Config.AUTO_POTION_MIN_LVL + " to use auto potions.");
return false;
}

final int playerOID = activeChar.getObjectId();
if (command.equals("apon"))
{
if (AUTO_POTION_TASKS.containsKey(playerOID))
{
AUTO_POTION_TASKS.get(playerOID).cancel(true);
AUTO_POTION_TASKS.remove(playerOID);
}
AUTO_POTION_TASKS.put(activeChar.getObjectId(), ThreadPool.scheduleAtFixedRate(new AutoPotionTask(activeChar), POTION_TASK_DELAY, POTION_TASK_DELAY));
activeChar.sendMessage("Auto potions is enabled.");
return true;
}
else if (command.equals("apoff"))
{
if (AUTO_POTION_TASKS.containsKey(playerOID))
{
AUTO_POTION_TASKS.get(playerOID).cancel(true);
AUTO_POTION_TASKS.remove(playerOID);
}
activeChar.sendMessage("Auto potions is disabled.");
}
return false;
}

@RegisterEvent(EventType.ON_PLAYER_LOGOUT)
@RegisterType(ListenerRegisterType.GLOBAL)
public void OnPlayerLogout(OnPlayerLogout event)
{
final int playerOID = event.getPlayer().getObjectId();
if (AUTO_POTION_TASKS.containsKey(playerOID))
{
AUTO_POTION_TASKS.get(playerOID).cancel(true);
AUTO_POTION_TASKS.remove(playerOID);
}
}

@Override
public String[] getVoicedCommandList()
{
return VOICED_COMMANDS;
}

Code: [Select]
@RegisterEvent(EventType.ON_PLAYER_LOGOUT)
@RegisterType(ListenerRegisterType.GLOBAL)

Hello, can i ask ? why my events dont work ? on voicecommand?
On QUest work perfect but on voice i cant understand