From 046bebe54c3d35d115a8ac0edfda9de6eba7a730 Mon Sep 17 00:00:00 2001 From: Super_ Date: Wed, 5 Feb 2020 17:07:16 -0500 Subject: [PATCH] shop updates --- .../command/Command_manageshop.java | 65 ++++++++++++++++++- .../totalfreedommod/command/Command_shop.java | 8 ++- .../totalfreedommod/fun/ItemFun.java | 4 +- .../totalfreedommod/shop/ShopData.java | 14 ++++ 4 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java index bc119e15..9549e075 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java @@ -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 = "/ >", aliases = "ms") +@CommandParameters(description = "Manage the shop", usage = "/ | items: >", 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; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java index c0e87e56..5b1b55e7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java @@ -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(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 3c3cd2b4..35d08602 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -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); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java index ad13b341..3820a33a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java @@ -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 it = items.iterator(); + while (it.hasNext()) + { + String i = it.next(); + if (i.startsWith(item.ordinal() + "")) + { + it.remove(); + } + } + } + @Override public boolean isValid() {