public class AutoCp extends Functions implements IVoicedCommandHandler{
private static final String[] _voicedCommands =
{
"autocp"
};
private static boolean _active;
private static Player _player;
private Future<?> _autoCpTask;
@Override
public boolean useVoicedCommand(String command, Player activeChar, String args)
{
final ItemInstance item = activeChar.getInventory().getItemByItemId(5592);
_player = activeChar;
if (command.equalsIgnoreCase("autocp"))
{
if (!_active)
{
if (item == null)
{
activeChar.sendMessage("");
return false;
}
_active = true;
activeChar.sendMessage("AutoCp enabled.");
// Start use Potion.
if (_autoCpTask == null)
{
_autoCpTask = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoCpTask(), item.useItem());
}
}
else
{
_active = false;
activeChar.sendMessage("AutoCp disabled.");
// Stop use Potion.
if (_autoCpTask != null)
{
_autoCpTask.cancel(false);
_autoCpTask = null;
}
}
}
return true;
}
protected void doAutoCp()
{
try
{
final IItemHandler handler = ItemHandler.getInstance().getHandler(_player.getInventory().getItemByItemId(5592).getEtcItem());
if ((_player.getCurrentCp() >= _player.getMaxCp()) || _player.isInvul() || _player.isInvisible() || _player.isInOlympiadMode() || _player.isDead())
{
return;
}
if (handler == null)
{
_player.sendMessage("You no have Greater CP Potion.");
_player.sendMessage("AutoCp disabled.");
return;
}
handler.useItem(_player, _player.getInventory().getItemByItemId(5592), false);
}
catch (Exception e)
{
_active = false;
// Stop use Potion.
if (_autoCpTask != null)
{
_autoCpTask.cancel(false);
_autoCpTask = null;
}
}
}
class AutoCpTask implements Runnable
{
@Override
public void run()
{
try
{
doAutoCp();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "", e);
}
}
}
@Override
public String[] getVoicedCommandList()
{
return _voicedCommands;
}
}
private static final String[] _voicedCommands =
{
"autocp"
};
private static boolean _active;
private static Player _player;
private Future<?> _autoCpTask;
@Override
public boolean useVoicedCommand(String command, Player activeChar, String args)
{
final ItemInstance item = activeChar.getInventory().getItemByItemId(5592);
_player = activeChar;
if (command.equalsIgnoreCase("autocp"))
{
if (!_active)
{
if (item == null)
{
activeChar.sendMessage("");
return false;
}
_active = true;
activeChar.sendMessage("AutoCp enabled.");
// Start use Potion.
if (_autoCpTask == null)
{
_autoCpTask = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoCpTask(), item.useItem());
}
}
else
{
_active = false;
activeChar.sendMessage("AutoCp disabled.");
// Stop use Potion.
if (_autoCpTask != null)
{
_autoCpTask.cancel(false);
_autoCpTask = null;
}
}
}
return true;
}
protected void doAutoCp()
{
try
{
final IItemHandler handler = ItemHandler.getInstance().getHandler(_player.getInventory().getItemByItemId(5592).getEtcItem());
if ((_player.getCurrentCp() >= _player.getMaxCp()) || _player.isInvul() || _player.isInvisible() || _player.isInOlympiadMode() || _player.isDead())
{
return;
}
if (handler == null)
{
_player.sendMessage("You no have Greater CP Potion.");
_player.sendMessage("AutoCp disabled.");
return;
}
handler.useItem(_player, _player.getInventory().getItemByItemId(5592), false);
}
catch (Exception e)
{
_active = false;
// Stop use Potion.
if (_autoCpTask != null)
{
_autoCpTask.cancel(false);
_autoCpTask = null;
}
}
}
class AutoCpTask implements Runnable
{
@Override
public void run()
{
try
{
doAutoCp();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "", e);
}
}
}
@Override
public String[] getVoicedCommandList()
{
return _voicedCommands;
}
}
Отметил красным где ошибка вот хендлер
public interface IItemHandler {
public static final IItemHandler NULL = new IItemHandler() {
@Override
public boolean useItem(Playable playable, ItemInstance item, boolean ctrl) {
return false;
}
@Override
public void dropItem(Player player, ItemInstance item, long count, Location loc) {
if (item.isEquipped()) {
player.getInventory().unEquipItem(item);
player.sendUserInfo(true);
}
item = player.getInventory().removeItemByObjectId(item.getObjectId(), count);
if (item == null) {
player.sendActionFailed();
return;
}
Log.LogItem(player, Log.Drop, item);
item.dropToTheGround(player, loc);
player.disableDrop(1000);
player.sendChanges();
}
@Override
public boolean pickupItem(Playable playable, ItemInstance item) {
return true;
}
@Override
public int[] getItemIds() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
};
public boolean useItem(Playable playable, ItemInstance item, boolean ctrl);
public void dropItem(Player player, ItemInstance item, long count, Location loc);
public boolean pickupItem(Playable playable, ItemInstance item);
public int[] getItemIds();
}
public static final IItemHandler NULL = new IItemHandler() {
@Override
public boolean useItem(Playable playable, ItemInstance item, boolean ctrl) {
return false;
}
@Override
public void dropItem(Player player, ItemInstance item, long count, Location loc) {
if (item.isEquipped()) {
player.getInventory().unEquipItem(item);
player.sendUserInfo(true);
}
item = player.getInventory().removeItemByObjectId(item.getObjectId(), count);
if (item == null) {
player.sendActionFailed();
return;
}
Log.LogItem(player, Log.Drop, item);
item.dropToTheGround(player, loc);
player.disableDrop(1000);
player.sendChanges();
}
@Override
public boolean pickupItem(Playable playable, ItemInstance item) {
return true;
}
@Override
public int[] getItemIds() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
};
public boolean useItem(Playable playable, ItemInstance item, boolean ctrl);
public void dropItem(Player player, ItemInstance item, long count, Location loc);
public boolean pickupItem(Playable playable, ItemInstance item);
public int[] getItemIds();
}