Fixed callbacks for gem/coin rewards.

This commit is contained in:
Jonathan Williams 2015-06-26 01:13:28 -05:00
parent 526b0dadb6
commit 86e2514e37
8 changed files with 84 additions and 34 deletions

View File

@ -139,10 +139,10 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
donor.AddGems(amount); donor.AddGems(amount);
} }
} }
}
if (callback != null) if (callback != null)
callback.run(true); callback.run(success);
}
} }
}, caller, name, uuid.toString(), amount); }, caller, name, uuid.toString(), amount);
} }
@ -221,10 +221,10 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
donor.addCoins(amount); donor.addCoins(amount);
} }
} }
}
if (callback != null) if (callback != null)
callback.run(true); callback.run(success);
}
} }
}, caller, name, accountId, amount); }, caller, name, accountId, amount);
} }

View File

@ -74,6 +74,8 @@ public class CoinCommand extends CommandBase<DonationManager>
Plugin.RewardCoins(new Callback<Boolean>() Plugin.RewardCoins(new Callback<Boolean>()
{ {
public void run(Boolean completed) public void run(Boolean completed)
{
if (completed)
{ {
UtilPlayer.message(caller, F.main("Coin", "You gave " + F.elem(coins + " Coins") + " to " + F.name(targetName) + ".")); UtilPlayer.message(caller, F.main("Coin", "You gave " + F.elem(coins + " Coins") + " to " + F.name(targetName) + "."));
@ -82,6 +84,11 @@ public class CoinCommand extends CommandBase<DonationManager>
UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + ".")); UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + "."));
} }
} }
else
{
UtilPlayer.message(caller, F.main("Coin", "There was an error giving " + F.elem(coins + "Coins") + " to " + F.name(targetName) + "."));
}
}
}, caller.getName(), targetName, accountId, coins); }, caller.getName(), targetName, accountId, coins);
} }
} }

View File

@ -68,6 +68,8 @@ public class GemCommand extends CommandBase<DonationManager>
Plugin.RewardGems(new Callback<Boolean>() Plugin.RewardGems(new Callback<Boolean>()
{ {
public void run(Boolean completed) public void run(Boolean completed)
{
if (completed)
{ {
UtilPlayer.message(caller, F.main("gem", "You gave " + F.elem(gems + " gems") + " to " + F.name(targetName) + ".")); UtilPlayer.message(caller, F.main("gem", "You gave " + F.elem(gems + " gems") + " to " + F.name(targetName) + "."));
@ -76,6 +78,11 @@ public class GemCommand extends CommandBase<DonationManager>
UtilPlayer.message(target, F.main("gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " gems") + ".")); UtilPlayer.message(target, F.main("gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " gems") + "."));
} }
} }
else
{
UtilPlayer.message(caller, F.main("gem", "There was an error giving " + F.elem(gems + " gems") + " to " + F.name(targetName) + "."));
}
}
}, caller.getName(), targetName, uuid, gems); }, caller.getName(), targetName, uuid, gems);
} }
} }

View File

@ -144,4 +144,12 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
{ {
return "SELECT taskId FROM accountTasks WHERE accountId = '" + accountId + "';"; return "SELECT taskId FROM accountTasks WHERE accountId = '" + accountId + "';";
} }
public Integer getTaskId(String taskName)
{
synchronized (_taskLock)
{
return _tasks.get(taskName);
}
}
} }

View File

@ -397,12 +397,20 @@ public class ParkourManager extends MiniPlugin
_donationManager.RewardGems(new Callback<Boolean>() _donationManager.RewardGems(new Callback<Boolean>()
{ {
public void run(Boolean completed) public void run(Boolean completed)
{
if (completed)
{ {
UtilPlayer.message(player, F.main("Parkour", "You received " + F.elem(C.cGreen + fData.Gems + " Gems") + ".")); UtilPlayer.message(player, F.main("Parkour", "You received " + F.elem(C.cGreen + fData.Gems + " Gems") + "."));
//Sound //Sound
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f); player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
} }
else
{
_taskManager.Get(player).TasksCompleted.remove(_taskManager.getTaskId(fData.Name));
UtilPlayer.message(player, F.main("Parkour", "There as an error giving " + F.elem(C.cGreen + fData.Gems + " gems to you. Please click the NPC again.") + "."));
}
}
}, "Parkour " + fData.Name, player.getName(), player.getUniqueId(), fData.Gems); }, "Parkour " + fData.Name, player.getName(), player.getUniqueId(), fData.Gems);
//Sound //Sound

View File

@ -150,9 +150,6 @@ public class PollManager extends MiniDbClientPlugin<PlayerPollData>
// First update answer locally so we know it was answered // First update answer locally so we know it was answered
Get(player).addAnswer(poll.getId(), answer); Get(player).addAnswer(poll.getId(), answer);
UtilPlayer.message(player, F.main("Poll", "Thanks for your response!"));
player.playSound(player.getEyeLocation(), Sound.LEVEL_UP, 1F, 0);
// Here we add the answer into the database, and once that is successful we give the coin reward // Here we add the answer into the database, and once that is successful we give the coin reward
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable() _plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{ {
@ -166,6 +163,8 @@ public class PollManager extends MiniDbClientPlugin<PlayerPollData>
{ {
@Override @Override
public void run(Boolean completed) public void run(Boolean completed)
{
if (completed)
{ {
// Need to get out of Async code // Need to get out of Async code
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable() _plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
@ -173,10 +172,13 @@ public class PollManager extends MiniDbClientPlugin<PlayerPollData>
@Override @Override
public void run() public void run()
{ {
UtilPlayer.message(player, F.main("Poll", "Thanks for your response!"));
player.playSound(player.getEyeLocation(), Sound.LEVEL_UP, 1F, 0);
UtilPlayer.message(player, F.main("Gem", "You received " + F.elem(poll.getCoinReward() + "") + " Gems!")); UtilPlayer.message(player, F.main("Gem", "You received " + F.elem(poll.getCoinReward() + "") + " Gems!"));
} }
}); });
} }
}
}, "Poll", name, uuid, poll.getCoinReward()); }, "Poll", name, uuid, poll.getCoinReward());
} }
} }

View File

@ -136,12 +136,15 @@ public class TutorialManager extends MiniPlugin
_donationManager.RewardGems(new Callback<Boolean>() _donationManager.RewardGems(new Callback<Boolean>()
{ {
public void run(Boolean completed) public void run(Boolean completed)
{
if (completed)
{ {
UtilPlayer.message(player, F.main("Tutorial", "You received " + F.elem(C.cGreen + tut.GetGems() + " Gems") + ".")); UtilPlayer.message(player, F.main("Tutorial", "You received " + F.elem(C.cGreen + tut.GetGems() + " Gems") + "."));
//Sound //Sound
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f); player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
} }
}
}, "Tutorial " + tut.GetTutName(), player.getName(), player.getUniqueId(), tut.GetGems()); }, "Tutorial " + tut.GetTutName(), player.getName(), player.getUniqueId(), tut.GetGems());
} }
}, player, tut.GetTask()); }, player, tut.GetTask());

View File

@ -7,8 +7,10 @@ import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
import mineplex.staffServer.salespackage.SalesPackageManager; import mineplex.staffServer.salespackage.SalesPackageManager;
public class CoinCommand extends CommandBase<SalesPackageManager> public class CoinCommand extends CommandBase<SalesPackageManager>
@ -35,9 +37,22 @@ public class CoinCommand extends CommandBase<SalesPackageManager>
if (client != null) if (client != null)
{ {
Plugin.getDonationManager().RewardCoins(null, caller.getName(), playerName, client.getAccountId(), amount); Plugin.getDonationManager().RewardCoins(new Callback<Boolean>()
{
public void run(Boolean completed)
{
if (completed)
{
caller.sendMessage(F.main(Plugin.getName(), "Added " + amount + " coins to " + playerName + "'s account!")); caller.sendMessage(F.main(Plugin.getName(), "Added " + amount + " coins to " + playerName + "'s account!"));
} }
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "There was an error giving " + F.elem(amount + "Coins") + " to " + F.name(playerName) + "."));
}
}
}, caller.getName(), playerName, client.getAccountId(), amount);
}
else else
caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + playerName + "'s account!")); caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + playerName + "'s account!"));
} }