mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
shop updates
This commit is contained in:
parent
ea6d541270
commit
046bebe54c
@ -3,14 +3,16 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopData;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage the shop", usage = "/<command> <coins: <add | set | remove> <amount> <player | all>>", aliases = "ms")
|
||||
@CommandParameters(description = "Manage the shop", usage = "/<command> <coins: <add | set | remove> <amount> <player | all> | items: <give | remove> <player> <item>>", aliases = "ms")
|
||||
public class Command_manageshop extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
@ -21,9 +23,9 @@ public class Command_manageshop extends FreedomCommand
|
||||
msg("The shop is currently disabled!", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
if (!FUtil.isExecutive(sender.getName()))
|
||||
if (!FUtil.isExecutive(sender.getName()) && !FUtil.isDeveloper(sender.getName()))
|
||||
{
|
||||
msg("Only executives can use this command!", ChatColor.RED);
|
||||
msg("Only executives and developers can use this command!", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
|
||||
@ -158,6 +160,63 @@ public class Command_manageshop extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("items"))
|
||||
{
|
||||
switch (args[1])
|
||||
{
|
||||
case "give":
|
||||
{
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
ShopItem item = ShopItem.findItem(args[3]);
|
||||
if (item == null)
|
||||
{
|
||||
msg("Invalid item: " + item);
|
||||
return true;
|
||||
}
|
||||
ShopData sd = plugin.sh.getData(player);
|
||||
if (sd.hasItem(item))
|
||||
{
|
||||
msg("That player already has a(n) " + item.getName() + "!");
|
||||
return true;
|
||||
}
|
||||
String key = sd.giveItem(item);
|
||||
plugin.sh.save(sd);
|
||||
FUtil.give(player, item, ChatColor.DARK_GRAY + key);
|
||||
msg(prefix + ChatColor.GREEN + "Gave " + ChatColor.RED + player.getName() + ChatColor.GREEN + " a(n) " + item.getColoredName());
|
||||
return true;
|
||||
}
|
||||
case "remove":
|
||||
{
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
ShopItem item = ShopItem.findItem(args[3]);
|
||||
if (item == null)
|
||||
{
|
||||
msg("Invalid item: " + item);
|
||||
return true;
|
||||
}
|
||||
ShopData sd = plugin.sh.getData(player);
|
||||
if (!sd.hasItem(item))
|
||||
{
|
||||
msg("That player doesn't have a(n) " + item.getName() + "!");
|
||||
return true;
|
||||
}
|
||||
sd.takeItem(item);
|
||||
plugin.sh.save(sd);
|
||||
msg(prefix + ChatColor.GREEN + "Took " + ChatColor.RED + player.getName() + ChatColor.GREEN + "'s " + item.getColoredName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -76,6 +76,10 @@ public class Command_shop extends FreedomCommand
|
||||
msg(prefix + ChatColor.GREEN + "Available items:");
|
||||
for (ShopItem item : ShopItem.values())
|
||||
{
|
||||
if (!item.isPurchaseable())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
msg(prefix + ChatColor.AQUA + item.getName() + ChatColor.GREEN + " - " + ChatColor.RED + item.getCost());
|
||||
}
|
||||
return true;
|
||||
@ -133,14 +137,14 @@ public class Command_shop extends FreedomCommand
|
||||
case "get":
|
||||
{
|
||||
ShopItem item = ShopItem.findItem(args[1]);
|
||||
if (item == null || !item.isPurchaseable())
|
||||
if (item == null)
|
||||
{
|
||||
msg("Invalid item: " + item);
|
||||
return true;
|
||||
}
|
||||
if (!sd.hasItem(item))
|
||||
{
|
||||
msg(prefix + ChatColor.GREEN + "You don't have that item! To buy iy, use " + ChatColor.RED + "/shop buy " + item.name() + ChatColor.GREEN + "!");
|
||||
msg(prefix + ChatColor.GREEN + "You don't have that item! To buy it, use " + ChatColor.RED + "/shop buy " + item.name() + ChatColor.GREEN + "!");
|
||||
return true;
|
||||
}
|
||||
Inventory inv = playerSender.getInventory();
|
||||
|
@ -366,13 +366,13 @@ public class ItemFun extends FreedomService
|
||||
}
|
||||
String key = psd.giveItem(ShopItem.SUPERIOR_SWORD);
|
||||
FUtil.bcastMsg("THOR'S STAR HAS GRANTED " + rplayer.getName().toUpperCase() + " A " + ChatColor.GOLD + "SUPERIOR SWORD" + ChatColor.RED + "!!!!", ChatColor.RED);
|
||||
FUtil.give(player, ShopItem.SUPERIOR_SWORD, "&7RMB - Shoot fireball", ChatColor.DARK_GRAY + key);
|
||||
FUtil.give(rplayer, ShopItem.SUPERIOR_SWORD, "&7RMB - Shoot fireball", ChatColor.DARK_GRAY + key);
|
||||
}
|
||||
else
|
||||
{
|
||||
String key = psd.giveItem(ShopItem.ELECTRICAL_DIAMOND_SWORD);
|
||||
FUtil.bcastMsg("Thor's Star has granted " + rplayer.getName() + " an " + ChatColor.YELLOW + "Electrical Diamond Sword" + ChatColor.RED + "!", ChatColor.RED);
|
||||
FUtil.give(player, ShopItem.ELECTRICAL_DIAMOND_SWORD, "&7RMB - Strike lightning", ChatColor.DARK_GRAY + key);
|
||||
FUtil.give(rplayer, ShopItem.ELECTRICAL_DIAMOND_SWORD, "&7RMB - Strike lightning", ChatColor.DARK_GRAY + key);
|
||||
}
|
||||
plugin.sh.save(psd);
|
||||
cooldown(player, "nether_star", 600);
|
||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.shop;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -222,6 +223,19 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
return true;
|
||||
}
|
||||
|
||||
public void takeItem(ShopItem item)
|
||||
{
|
||||
Iterator<String> it = items.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
String i = it.next();
|
||||
if (i.startsWith(item.ordinal() + ""))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user