Changes to lock command

This commit is contained in:
LCastr0 2016-08-25 20:12:00 -03:00
parent 84c6720d1c
commit 25d64c6dee
4 changed files with 114 additions and 35 deletions

View File

@ -1,13 +1,17 @@
package mineplex.core.gadget.commands;
import java.util.UUID;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.inventory.ClientItem;
import mineplex.core.inventory.data.Item;
import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.inventory.ClientInventory;
import mineplex.core.mount.Mount;
import mineplex.core.pet.Pet;
import org.bukkit.entity.Player;
public class LockCosmeticsCommand extends CommandBase<GadgetManager>
@ -21,31 +25,105 @@ public class LockCosmeticsCommand extends CommandBase<GadgetManager>
_plugin = plugin;
}
@Override
public void Execute(Player caller, String[] args)
{
lockCosmetics(caller);
}
private void lockCosmetics(Player player) {
UtilPlayer.message(player, "This command is being re-created!");
}
private void lockCosmetic(String itemName, Player player)
@Override
public void Execute(Player caller, String[] args)
{
// First try, with Donation Manager
_plugin.getDonationManager().Get(player).RemoveUnknownSalesPackagesOwned(itemName);
// Second try, with Inventory Manager
Item item = _plugin.getInventoryManager().getItem(itemName);
if (item != null)
// Adds all cosmetic types
if (args.length == 0)
{
_plugin.getInventoryManager().Get(player).removeItem(new ClientItem(item, 1));
removeCosmetics(null, caller);
}
// Adds specific type
else
{
String type = args[0];
if (type.equalsIgnoreCase("all"))
{
removeCosmetics(null, caller);
}
else if (type.equalsIgnoreCase("pet"))
{
removePets(caller);
}
else if (type.equalsIgnoreCase("mount"))
{
removeMounts(caller);
}
else
{
GadgetType gadgetType = GadgetType.valueOf(type);
if (gadgetType == null)
{
UtilPlayer.message(caller, F.main("Cosmetics", "Invalid cosmetic type!"));
}
else
{
removeCosmetics(gadgetType, caller);
}
}
}
}
private void lockCosmetic(String itemName, UUID uuid)
private void removeCosmetics(GadgetType gadgetType, Player caller)
{
// TODO
if (gadgetType == null)
{
for (GadgetType type : GadgetType.values())
{
removeCosmetics(type, caller);
}
removeMounts(caller);
removePets(caller);
return;
}
ClientInventory clientInventory = _plugin.getInventoryManager().Get(caller);
int removed = 0;
int amount = -1;
for (Gadget gadget : _plugin.getGadgets(gadgetType))
{
if (gadgetType == GadgetType.ITEM)
continue;
if (gadget.ownsGadget(caller))
{
clientInventory.removeItem(clientInventory.getClientItem(gadget.getName()));
removed++;
}
}
UtilPlayer.message(caller, F.main("Cosmetics", "Removed all the " + gadgetType.name().toLowerCase()
.replace("_", " ") + "! (Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("item", removed) + ")"));
}
private void removeMounts(Player caller)
{
int removed = 0;
ClientInventory clientInventory = _plugin.getInventoryManager().Get(caller);
for (Mount<?> mount : _plugin.getMountManager().getMounts())
{
if (mount.hasMount(caller))
{
clientInventory.removeItem(clientInventory.getClientItem(mount.getName()));
removed++;
}
}
UtilPlayer.message(caller, F.main("Cosmetics", "Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("mount", removed) + "!"));
}
private void removePets(Player caller)
{
int removed = 0;
for (Pet pet : _plugin.getPetManager().getFactory().GetPets())
{
if (_plugin.getPetManager().Get(caller).getPets().containsKey(pet.getPetType()))
{
_plugin.getPetManager().Get(caller).getPets().remove(pet.getPetType());
removed++;
}
}
UtilPlayer.message(caller, F.main("Cosmetics", "Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("pet", removed) + "!"));
}
}

View File

@ -14,6 +14,7 @@ import mineplex.core.gadget.event.GadgetSelectLocationEvent;
import mineplex.core.gadget.gadgets.particle.unrelated.MetalManEffect;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.recharge.Recharge;
import mineplex.core.utils.UtilGameProfile;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -37,11 +38,12 @@ public class MorphMetalMan extends MorphGadget
{
applyArmor(player, message);
DisguisePlayer disguisePlayer = new DisguisePlayer(player);
disguisePlayer.setProfile(new GameProfile(UUID.randomUUID(), C.cYellow + "Metal " + C.cRed + "Man"));
SkinData metalMan = SkinData.METAL_MAN;
disguisePlayer.setSkinData(metalMan);
disguisePlayer.setSendSkinDataToSelf(true);
GameProfile gameProfile = UtilGameProfile.getGameProfile(player);
gameProfile.getProperties().clear();
gameProfile.getProperties().put("textures", SkinData.METAL_MAN.getProperty());
DisguisePlayer disguisePlayer = new DisguisePlayer(player, gameProfile);
disguisePlayer.showInTabList(true, 0);
Manager.getDisguiseManager().disguise(disguisePlayer);
}

View File

@ -24,6 +24,10 @@ public class ClientInventory
if (Items.get(item.Item.Name).Count == 0)
Items.remove(item.Item.Name);
}
public ClientItem getClientItem(String name) {
return Items.containsKey(name) ? Items.get(name) : null;
}
public int getItemCount(String name)
{

View File

@ -3,10 +3,7 @@ import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import java.util.*;
import mineplex.core.Managers;
import mineplex.core.MiniClientPlugin;
@ -106,8 +103,6 @@ import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
public class HubManager extends MiniClientPlugin<HubClient>
{
// Snowman!
@ -198,7 +193,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
_mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager);
_inventoryManager = inventoryManager;
new BenefitManager(plugin, clientManager, _inventoryManager);
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager, packetHandler, hologramManager, incognito);
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, Managers.get(ProjectileManager.class), achievementManager, packetHandler, hologramManager, incognito);
FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager);
YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager);