Optimized TaskManager task locks and calls.
Run all player messages on the main thread.
This commit is contained in:
parent
55d028d706
commit
3b38302429
@ -56,31 +56,40 @@ 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);
|
||||||
{
|
|
||||||
_repository.addTask(task);
|
|
||||||
System.out.println("TaskManager Adding Task : " + task);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTasks();
|
if (!taskExists)
|
||||||
|
{
|
||||||
|
_repository.addTask(task);
|
||||||
|
System.out.println("TaskManager Adding Task : " + task);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
if (callback != null)
|
final boolean success = _repository.addAccountTask(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), taskId);
|
||||||
|
|
||||||
|
if (callback != null)
|
||||||
|
{
|
||||||
|
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
|
||||||
{
|
{
|
||||||
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
|
public void run()
|
||||||
{
|
{
|
||||||
public void run()
|
callback.run(success);
|
||||||
{
|
}
|
||||||
callback.run(success);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -115,19 +115,26 @@ 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)
|
||||||
{
|
{
|
||||||
if (completed)
|
_plugin.runSync(new Runnable()
|
||||||
{
|
{
|
||||||
UtilPlayer.message(_player, F.main("Treat", "You received " + F.elem(C.cYellow + amount + " Coins") + " from " + F.name(_villagerName) + "."));
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (completed)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(_player, F.main("Treat", "You received " + F.elem(C.cYellow + amount + " Coins") + " from " + F.name(_villagerName) + "."));
|
||||||
|
|
||||||
//Sound
|
//Sound
|
||||||
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -136,19 +143,26 @@ 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)
|
||||||
{
|
{
|
||||||
if (completed)
|
_plugin.runSync(new Runnable()
|
||||||
{
|
{
|
||||||
UtilPlayer.message(_player, F.main("Treat", "You received " + F.elem(C.cGreen + amount + " Gems") + " from " + F.name(_villagerName) + "."));
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (completed)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(_player, F.main("Treat", "You received " + F.elem(C.cGreen + amount + " Gems") + " from " + F.name(_villagerName) + "."));
|
||||||
|
|
||||||
//Sound
|
//Sound
|
||||||
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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