use of de.Keyle.MyPet.api.event.MyPetRemoveEvent in project MyPet by xXKeyleXx.
the class CommandRelease method onCommand.
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player petOwner = (Player) sender;
if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
if (!Permissions.hasLegacy(petOwner, "MyPet.command.release")) {
return true;
}
if (myPet.getStatus() == PetState.Despawned) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Call.First", petOwner), myPet.getPetName()));
return true;
} else if (myPet.getStatus() == PetState.Dead) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", petOwner), myPet.getPetName(), myPet.getRespawnTime()));
return true;
}
String name = "";
if (args.length > 0) {
for (String arg : args) {
if (!name.equals("")) {
name += " ";
}
name += arg;
}
}
if (ChatColor.stripColor(myPet.getPetName()).trim().equalsIgnoreCase(name.trim())) {
MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.Release);
Bukkit.getServer().getPluginManager().callEvent(removeEvent);
if (myPet.getSkills().isSkillActive(Inventory.class)) {
myPet.getSkills().getSkill(Inventory.class).get().getInventory().dropContentAt(myPet.getLocation().get());
}
if (myPet instanceof MyPetEquipment) {
((MyPetEquipment) myPet).dropEquipment();
}
if (!Configuration.Misc.REMOVE_PETS_AFTER_RELEASE) {
LivingEntity normalEntity = (LivingEntity) myPet.getLocation().get().getWorld().spawnEntity(myPet.getLocation().get(), EntityType.valueOf(myPet.getPetType().getBukkitName()));
Optional<EntityConverterService> converter = MyPetApi.getServiceManager().getService(EntityConverterService.class);
if (converter.isPresent()) {
converter.get().convertEntity(myPet, normalEntity);
}
}
myPet.removePet();
myPet.getOwner().setMyPetForWorldGroup(WorldGroup.getGroupByWorld(petOwner.getWorld().getName()), null);
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Release.Success", petOwner), myPet.getPetName()));
MyPetApi.getMyPetManager().deactivateMyPet(myPet.getOwner(), false);
MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
return true;
} else {
FancyMessage message = new FancyMessage(Translation.getString("Message.Command.Release.Confirm", petOwner) + " ");
List<String> lore = new ArrayList<>();
lore.add(RESET + Translation.getString("Name.Hunger", petOwner) + ": " + GOLD + Math.round(myPet.getSaturation()));
if (myPet.getRespawnTime() > 0) {
lore.add(RESET + Translation.getString("Name.Respawntime", petOwner) + ": " + GOLD + myPet.getRespawnTime() + "sec");
} else {
lore.add(RESET + Translation.getString("Name.HP", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getHealth()));
}
lore.add(RESET + Translation.getString("Name.Exp", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getExp()));
lore.add(RESET + Translation.getString("Name.Type", petOwner) + ": " + GOLD + Translation.getString("Name." + myPet.getPetType().name(), petOwner));
lore.add(RESET + Translation.getString("Name.Skilltree", petOwner) + ": " + GOLD + (myPet.getSkilltree() != null ? myPet.getSkilltree().getDisplayName() : "-"));
message.then(myPet.getPetName()).color(ChatColor.AQUA).command("/petrelease " + ChatColor.stripColor(myPet.getPetName())).itemTooltip(new ItemTooltip().setMaterial(Material.MONSTER_EGG).addLore(lore).setTitle(myPet.getPetName()));
MyPetApi.getPlatformHelper().sendMessageRaw((Player) sender, message.toJSONString());
return true;
}
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", petOwner));
}
return true;
}
sender.sendMessage("You can't use this command from server console!");
return false;
}
use of de.Keyle.MyPet.api.event.MyPetRemoveEvent in project MyPet by xXKeyleXx.
the class CommandOptionRemove method onCommandOption.
@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
String lang = MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender);
if (args.length >= 1) {
Player player = Bukkit.getPlayer(args[0]);
if (player == null || !player.isOnline()) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.No.PlayerOnline", lang));
return true;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
MyPetPlayer petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
if (petOwner.hasMyPet()) {
MyPet myPet = petOwner.getMyPet();
MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.AdminCommand);
Bukkit.getServer().getPluginManager().callEvent(removeEvent);
myPet.getOwner().setMyPetForWorldGroup(WorldGroup.getGroupByWorld(player.getWorld().getName()), null);
MyPetApi.getMyPetManager().deactivateMyPet(myPet.getOwner(), false);
MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] You removed the MyPet of: " + ChatColor.YELLOW + petOwner.getName());
}
}
}
return true;
}
Aggregations