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; package mineplex.core.gadget.commands;
import java.util.UUID;
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.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.inventory.ClientItem; import mineplex.core.gadget.types.Gadget;
import mineplex.core.inventory.data.Item; 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; import org.bukkit.entity.Player;
public class LockCosmeticsCommand extends CommandBase<GadgetManager> public class LockCosmeticsCommand extends CommandBase<GadgetManager>
@ -24,28 +28,102 @@ public class LockCosmeticsCommand extends CommandBase<GadgetManager>
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
lockCosmetics(caller); // Adds all cosmetic types
} if (args.length == 0)
private void lockCosmetics(Player player) {
UtilPlayer.message(player, "This command is being re-created!");
}
private void lockCosmetic(String itemName, Player player)
{ {
// First try, with Donation Manager removeCosmetics(null, caller);
_plugin.getDonationManager().Get(player).RemoveUnknownSalesPackagesOwned(itemName); }
// Second try, with Inventory Manager // Adds specific type
Item item = _plugin.getInventoryManager().getItem(itemName); else
if (item != null)
{ {
_plugin.getInventoryManager().Get(player).removeItem(new ClientItem(item, 1)); 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.gadgets.particle.unrelated.MetalManEffect;
import mineplex.core.gadget.types.MorphGadget; import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.utils.UtilGameProfile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -37,11 +38,12 @@ public class MorphMetalMan extends MorphGadget
{ {
applyArmor(player, message); applyArmor(player, message);
DisguisePlayer disguisePlayer = new DisguisePlayer(player); GameProfile gameProfile = UtilGameProfile.getGameProfile(player);
disguisePlayer.setProfile(new GameProfile(UUID.randomUUID(), C.cYellow + "Metal " + C.cRed + "Man")); gameProfile.getProperties().clear();
SkinData metalMan = SkinData.METAL_MAN; gameProfile.getProperties().put("textures", SkinData.METAL_MAN.getProperty());
disguisePlayer.setSkinData(metalMan);
disguisePlayer.setSendSkinDataToSelf(true); DisguisePlayer disguisePlayer = new DisguisePlayer(player, gameProfile);
disguisePlayer.showInTabList(true, 0);
Manager.getDisguiseManager().disguise(disguisePlayer); Manager.getDisguiseManager().disguise(disguisePlayer);
} }

View File

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

View File

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