Optimized TaskManager task locks and calls.
Run all player messages on the main thread.
This commit is contained in:
parent
55d028d706
commit
3b38302429
@ -56,20 +56,30 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
boolean taskExists = false;
|
||||||
|
|
||||||
synchronized (_taskLock)
|
synchronized (_taskLock)
|
||||||
{
|
{
|
||||||
if (!_tasks.containsKey(task))
|
taskExists = _tasks.containsKey(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!taskExists)
|
||||||
{
|
{
|
||||||
_repository.addTask(task);
|
_repository.addTask(task);
|
||||||
System.out.println("TaskManager Adding Task : " + task);
|
System.out.println("TaskManager Adding Task : " + task);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTasks();
|
updateTasks();
|
||||||
|
}
|
||||||
|
|
||||||
|
int taskId = -1;
|
||||||
|
|
||||||
|
|
||||||
synchronized (_taskLock)
|
synchronized (_taskLock)
|
||||||
{
|
{
|
||||||
final boolean success = _repository.addAccountTask(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), _tasks.get(task));
|
taskId = _tasks.get(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean success = _repository.addAccountTask(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), taskId);
|
||||||
|
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
{
|
{
|
||||||
@ -82,7 +92,6 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,12 @@ public class TrickDialogue
|
|||||||
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
|
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
|
||||||
_plugin.getDonationManager().RewardCoins(new Callback<Boolean>()
|
_plugin.getDonationManager().RewardCoins(new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
public void run(Boolean completed)
|
public void run(final Boolean completed)
|
||||||
|
{
|
||||||
|
_plugin.runSync(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (completed)
|
if (completed)
|
||||||
{
|
{
|
||||||
@ -129,6 +134,8 @@ public class TrickDialogue
|
|||||||
UtilPlayer.message(_player, F.main("Treat", "There was an error giving " + F.elem(C.cYellow + amount + " Coins") + " to you. Please visit that villager again.") + ".");
|
UtilPlayer.message(_player, F.main("Treat", "There was an error giving " + F.elem(C.cYellow + amount + " Coins") + " to you. Please visit that villager again.") + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}, "Treat " + _villagerName, _player.getName(), _plugin.getClientManager().getAccountId(_player), amount);
|
}, "Treat " + _villagerName, _player.getName(), _plugin.getClientManager().getAccountId(_player), amount);
|
||||||
}
|
}
|
||||||
else //Gems
|
else //Gems
|
||||||
@ -136,7 +143,12 @@ public class TrickDialogue
|
|||||||
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
|
final int amount = Math.max(new Random().nextInt(100) + 100, (int) Math.floor(new Random().nextDouble() * 600));
|
||||||
_plugin.getDonationManager().RewardGems(new Callback<Boolean>()
|
_plugin.getDonationManager().RewardGems(new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
public void run(Boolean completed)
|
public void run(final Boolean completed)
|
||||||
|
{
|
||||||
|
_plugin.runSync(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (completed)
|
if (completed)
|
||||||
{
|
{
|
||||||
@ -150,6 +162,8 @@ public class TrickDialogue
|
|||||||
UtilPlayer.message(_player, F.main("Treat", "There was an error giving " + F.elem(C.cGreen + amount + " Gems") + " to you. Please visit that villager again.") + ".");
|
UtilPlayer.message(_player, F.main("Treat", "There was an error giving " + F.elem(C.cGreen + amount + " Gems") + " to you. Please visit that villager again.") + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}, "Treat " + _villagerName, _player.getName(), _player.getUniqueId(), amount);
|
}, "Treat " + _villagerName, _player.getName(), _player.getUniqueId(), amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user