New Coin/Gem Command

This commit is contained in:
Shaun Bennett 2014-10-27 19:59:30 -05:00
parent 01d44cd250
commit 054c26dfbc
3 changed files with 92 additions and 35 deletions

View File

@ -1,11 +1,14 @@
package mineplex.core.donation;
import java.util.UUID;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
public class CoinCommand extends CommandBase<DonationManager>
@ -20,32 +23,58 @@ public class CoinCommand extends CommandBase<DonationManager>
{
if (args.length < 2)
{
UtilPlayer.message(caller, F.main("Coin", "Missing Args"));
UtilPlayer.message(caller, F.main("Coin", "Missing Args: " + F.elem("/coin <player> <amount>")));
return;
}
//Try Online
final Player target = UtilPlayer.searchOnline(caller, args[0], true);
String targetName = args[0];
String coinsString = args[1];
Player target = UtilPlayer.searchExact(targetName);
if (target == null)
return;
{
UUID uuid = UUIDFetcher.getUUIDOf(targetName);
if (uuid != null)
{
rewardCoins(caller, null, targetName, uuid, coinsString);
}
else
{
UtilPlayer.message(caller, F.main("Coin", "Could not find player " + F.name(targetName)));
}
}
else
{
rewardCoins(caller, target, target.getName(), target.getUniqueId(), coinsString);
}
}
//Give Coins to Target
private void rewardCoins(final Player caller, final Player target, final String targetName, final UUID uuid, String coinsString)
{
try
{
final int coins = Integer.parseInt(args[1]);
Plugin.RewardCoins(new Callback<Boolean>()
{
public void run(Boolean completed)
{
UtilPlayer.message(caller, F.main("Coin", "You gave " + F.elem(coins + " Coins") + " to " + F.name(target.getName()) + "."));
UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + "."));
}
}, caller.getName(), target.getName(), target.getUniqueId(), coins);
int coins = Integer.parseInt(coinsString);
rewardCoins(caller, target, targetName, uuid, coins);
}
catch (Exception e)
{
UtilPlayer.message(caller, F.main("Coin", "Invalid Coins Amount"));
}
}
private void rewardCoins(final Player caller, final Player target, final String targetName, final UUID uuid, final int coins)
{
Plugin.RewardCoins(new Callback<Boolean>()
{
public void run(Boolean completed)
{
UtilPlayer.message(caller, F.main("Coin", "You gave " + F.elem(coins + " Coins") + " to " + F.name(targetName) + "."));
if (target != null)
{
UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + "."));
}
}
}, caller.getName(), targetName, uuid, coins);
}
}

View File

@ -1,11 +1,14 @@
package mineplex.core.donation;
import java.util.UUID;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
public class GemCommand extends CommandBase<DonationManager>
@ -20,32 +23,58 @@ public class GemCommand extends CommandBase<DonationManager>
{
if (args.length < 2)
{
UtilPlayer.message(caller, F.main("Gem", "Missing Args"));
UtilPlayer.message(caller, F.main("gem", "Missing Args: " + F.elem("/gem <player> <amount>")));
return;
}
//Try Online
final Player target = UtilPlayer.searchOnline(caller, args[0], true);
String targetName = args[0];
String gemsString = args[1];
Player target = UtilPlayer.searchExact(targetName);
if (target == null)
return;
{
UUID uuid = UUIDFetcher.getUUIDOf(targetName);
if (uuid != null)
{
rewardGems(caller, null, targetName, uuid, gemsString);
}
else
{
UtilPlayer.message(caller, F.main("Gem", "Could not find player " + F.name(targetName)));
}
}
else
{
rewardGems(caller, target, target.getName(), target.getUniqueId(), gemsString);
}
}
//Give Gems to Target
private void rewardGems(final Player caller, final Player target, final String targetName, final UUID uuid, String gemsString)
{
try
{
final int gems = Integer.parseInt(args[1]);
Plugin.RewardGems(new Callback<Boolean>()
{
public void run(Boolean completed)
{
UtilPlayer.message(caller, F.main("Gem", "You gave " + F.elem(gems + " Gems") + " to " + F.name(target.getName()) + "."));
UtilPlayer.message(target, F.main("Gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " Gems") + "."));
}
}, caller.getName(), target.getName(), target.getUniqueId(), gems);
int gems = Integer.parseInt(gemsString);
rewardGems(caller, target, targetName, uuid, gems);
}
catch (Exception e)
{
UtilPlayer.message(caller, F.main("Gem", "Invalid Gem Amount"));
UtilPlayer.message(caller, F.main("gem", "Invalid gems Amount"));
}
}
private void rewardGems(final Player caller, final Player target, final String targetName, final UUID uuid, final int gems)
{
Plugin.RewardGems(new Callback<Boolean>()
{
public void run(Boolean completed)
{
UtilPlayer.message(caller, F.main("gem", "You gave " + F.elem(gems + " gems") + " to " + F.name(targetName) + "."));
if (target != null)
{
UtilPlayer.message(target, F.main("gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " gems") + "."));
}
}
}, caller.getName(), targetName, uuid, gems);
}
}

View File

@ -4,7 +4,6 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
@ -63,7 +62,7 @@ public class GiveItemCommand extends CommandBase<InventoryManager>
}
}
public void displayUsage(Player caller)
private void displayUsage(Player caller)
{
UtilPlayer.message(caller, F.main("Item", "Usage: " + F.elem("/giveitem <playername> <item name> <amount>")));
}