use of de.Keyle.MyPet.gui.selectionmenu.MyPetSelectionGui in project MyPet by xXKeyleXx.
the class CommandSwitch method onCommand.
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("You can't use this command from server console!");
return true;
}
Player player = (Player) sender;
if (!Permissions.hasLegacy(player, "MyPet.command.switch")) {
player.sendMessage(Translation.getString("Message.No.Allowed", player));
return true;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
final MyPetPlayer owner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
MyPetApi.getRepository().getMyPets(owner, new RepositoryCallback<List<StoredMyPet>>() {
@Override
public void callback(List<StoredMyPet> pets) {
if (pets.size() - (owner.hasMyPet() ? 1 : 0) == 0) {
owner.sendMessage(Translation.getString("Message.Command.Switch.NoStoredPets", owner));
return;
}
if (owner.isOnline()) {
String worldGroup = WorldGroup.getGroupByWorld(owner.getPlayer().getWorld().getName()).getName();
int inactivePetCount = getInactivePetCount(pets, worldGroup);
int maxPetCount = getMaxPetCount(owner.getPlayer());
String title;
if (owner.hasMyPet()) {
inactivePetCount--;
title = Translation.getString("Message.Npc.SwitchTitle", owner);
} else {
title = Translation.getString("Message.SelectMyPet", owner);
}
String stats = "(" + inactivePetCount + "/" + maxPetCount + ")";
final MyPetSelectionGui gui = new MyPetSelectionGui(owner, title + " " + stats);
gui.open(pets, new RepositoryCallback<StoredMyPet>() {
@Override
public void callback(StoredMyPet storedMyPet) {
Optional<MyPet> activePet = MyPetApi.getMyPetManager().activateMyPet(storedMyPet);
if (activePet.isPresent() && owner.isOnline()) {
Player player = owner.getPlayer();
activePet.get().getOwner().sendMessage(Util.formatText(Translation.getString("Message.Npc.ChosenPet", owner), activePet.get().getPetName()));
WorldGroup wg = WorldGroup.getGroupByWorld(player.getWorld().getName());
owner.setMyPetForWorldGroup(wg, activePet.get().getUUID());
switch(activePet.get().createEntity()) {
case Canceled:
owner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", owner), activePet.get().getPetName()));
break;
case NoSpace:
owner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", owner), activePet.get().getPetName()));
break;
case NotAllowed:
owner.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", owner), activePet.get().getPetName()));
break;
case Dead:
owner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", owner), activePet.get().getPetName(), activePet.get().getRespawnTime()));
break;
case Spectator:
sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Spectator", owner), activePet.get().getPetName()));
break;
}
}
}
});
}
}
});
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", player));
}
return true;
}
Aggregations