use of de.Keyle.MyPet.api.util.inventory.material.MaterialHolder in project MyPet by xXKeyleXx.
the class CommandOptionCreate method createInfo.
public static void createInfo(MyPetType petType, String[] args, TagCompound compound) {
for (String arg : args) {
if (arg.equalsIgnoreCase("baby")) {
compound.getCompoundData().put("Baby", new TagByte(true));
} else if (arg.equalsIgnoreCase("fire")) {
compound.getCompoundData().put("Fire", new TagByte(true));
} else if (arg.equalsIgnoreCase("powered")) {
compound.getCompoundData().put("Powered", new TagByte(true));
} else if (arg.equalsIgnoreCase("screaming")) {
compound.getCompoundData().put("Screaming", new TagByte(true));
} else if (arg.equalsIgnoreCase("saddle")) {
compound.getCompoundData().put("Saddle", new TagByte(true));
} else if (arg.equalsIgnoreCase("sheared")) {
compound.getCompoundData().put("Sheared", new TagByte(true));
} else if (arg.equalsIgnoreCase("wither")) {
compound.getCompoundData().put("Type", new TagInt(1));
} else if (arg.equalsIgnoreCase("stray")) {
compound.getCompoundData().put("Type", new TagInt(2));
} else if (arg.equalsIgnoreCase("husk")) {
compound.getCompoundData().put("Type", new TagInt(6));
} else if (arg.equalsIgnoreCase("tamed")) {
compound.getCompoundData().put("Tamed", new TagByte(true));
} else if (arg.equalsIgnoreCase("angry")) {
compound.getCompoundData().put("Angry", new TagByte(true));
} else if (arg.equalsIgnoreCase("villager")) {
compound.getCompoundData().put("Villager", new TagByte(true));
} else if (arg.equalsIgnoreCase("chest")) {
compound.getCompoundData().put("Chest", new TagByte(true));
} else if (arg.equalsIgnoreCase("elder")) {
compound.getCompoundData().put("Elder", new TagByte(true));
} else if (arg.equalsIgnoreCase("donkey")) {
compound.getCompoundData().put("Type", new TagByte((byte) 1));
} else if (arg.equalsIgnoreCase("mule")) {
compound.getCompoundData().put("Type", new TagByte((byte) 2));
} else if (arg.equalsIgnoreCase("zombie")) {
compound.getCompoundData().put("Type", new TagByte((byte) 3));
} else if (arg.equalsIgnoreCase("skeleton")) {
compound.getCompoundData().put("Type", new TagByte((byte) 4));
} else if (arg.equalsIgnoreCase("glowing")) {
compound.getCompoundData().put("Glowing", new TagByte(true));
} else if (arg.equalsIgnoreCase("rainbow")) {
compound.getCompoundData().put("Rainbow", new TagByte(true));
} else if (arg.equalsIgnoreCase("has-stung")) {
compound.getCompoundData().put("HasStung", new TagByte(true));
} else if (arg.equalsIgnoreCase("has-nectar")) {
compound.getCompoundData().put("HasNectar", new TagByte(true));
} else if (arg.startsWith("size:")) {
String size = arg.replace("size:", "");
if (Util.isInt(size)) {
compound.getCompoundData().put("Size", new TagInt(Integer.parseInt(size)));
}
} else if (arg.startsWith("horse:")) {
String horseTypeString = arg.replace("horse:", "");
if (Util.isByte(horseTypeString)) {
int horseType = Integer.parseInt(horseTypeString);
horseType = Math.min(Math.max(0, horseType), 4);
compound.getCompoundData().put("Type", new TagByte((byte) horseType));
}
} else if (arg.startsWith("variant:")) {
String variantString = arg.replace("variant:", "");
if (Util.isInt(variantString)) {
int variant = Integer.parseInt(variantString);
if (petType == MyPetType.Horse) {
variant = Math.min(Math.max(0, variant), 1030);
compound.getCompoundData().put("Variant", new TagInt(variant));
} else if (petType == MyPetType.Rabbit) {
if (variant != 99 && (variant > 5 || variant < 0)) {
variant = 0;
}
compound.getCompoundData().put("Variant", new TagByte(variant));
} else if (petType == MyPetType.Llama || petType == MyPetType.TraderLlama) {
if (variant > 3 || variant < 0) {
variant = 0;
}
compound.getCompoundData().put("Variant", new TagInt(variant));
} else if (petType == MyPetType.Parrot) {
compound.getCompoundData().put("Variant", new TagInt(variant));
} else if (petType == MyPetType.Axolotl) {
compound.getCompoundData().put("Variant", new TagInt(variant));
} else if (petType == MyPetType.TropicalFish) {
compound.getCompoundData().put("Variant", new TagInt(variant));
}
}
} else if (arg.startsWith("cat:")) {
String catTypeString = arg.replace("cat:", "");
if (Util.isInt(catTypeString)) {
int catType = Integer.parseInt(catTypeString);
catType = Math.min(Math.max(0, catType), 3);
compound.getCompoundData().put("CatType", new TagInt(catType));
}
} else if (arg.startsWith("profession:")) {
String professionString = arg.replace("profession:", "");
if (Util.isInt(professionString)) {
int profession = Integer.parseInt(professionString);
profession = Math.min(Math.max(0, profession), MyPetApi.getCompatUtil().isCompatible("1.14") ? 15 : 5);
if (petType == MyPetType.Villager) {
compound.getCompoundData().put("Profession", new TagInt(profession));
if (!compound.getCompoundData().containsKey("VillagerLevel")) {
compound.getCompoundData().put("VillagerLevel", new TagInt(1));
}
} else if (petType == MyPetType.Zombie || petType == MyPetType.ZombieVillager) {
compound.getCompoundData().put("Villager", new TagByte(true));
compound.getCompoundData().put("Profession", new TagInt(profession));
if (!compound.getCompoundData().containsKey("TradingLevel")) {
compound.getCompoundData().put("TradingLevel", new TagInt(1));
}
}
}
} else if (arg.startsWith("color:")) {
String colorString = arg.replace("color:", "");
if (Util.isByte(colorString)) {
byte color = Byte.parseByte(colorString);
color = color > 15 ? 15 : color < 0 ? 0 : color;
compound.getCompoundData().put("Color", new TagByte(color));
}
} else if (arg.startsWith("collar:")) {
String colorString = arg.replace("collar:", "");
if (Util.isByte(colorString)) {
byte color = Byte.parseByte(colorString);
color = color > 15 ? 15 : color < 0 ? 0 : color;
compound.getCompoundData().put("CollarColor", new TagByte(color));
}
} else if (arg.startsWith("block:")) {
String block = arg.replace("block:", "");
ItemDatabase itemDatabase = MyPetApi.getServiceManager().getService(ItemDatabase.class).get();
MaterialHolder materialHolder = itemDatabase.getByID(block.toLowerCase());
if (materialHolder != null) {
compound.getCompoundData().put("BlockName", new TagString(materialHolder.getId()));
}
} else if (arg.startsWith("puff:")) {
switch(arg) {
case "puff:none":
compound.getCompoundData().put("PuffState", new TagInt(0));
break;
case "puff:semi":
compound.getCompoundData().put("PuffState", new TagInt(1));
break;
case "puff:fully":
compound.getCompoundData().put("PuffState", new TagInt(2));
break;
}
} else if (arg.startsWith("main-gene:") || arg.startsWith("hidden-gene:")) {
String gene;
String key;
if (arg.startsWith("main-gene:")) {
key = "MainGene";
gene = arg.substring(10);
} else {
key = "HiddenGene";
gene = arg.substring(12);
}
switch(gene.toLowerCase()) {
case "normal":
compound.getCompoundData().put(key, new TagInt(0));
break;
case "lazy":
compound.getCompoundData().put(key, new TagInt(1));
break;
case "worried":
compound.getCompoundData().put(key, new TagInt(2));
break;
case "playful":
compound.getCompoundData().put(key, new TagInt(3));
break;
case "brown":
compound.getCompoundData().put(key, new TagInt(4));
break;
case "weak":
compound.getCompoundData().put(key, new TagInt(5));
break;
case "aggressive":
compound.getCompoundData().put(key, new TagInt(6));
break;
}
} else if (arg.startsWith("type:")) {
switch(petType) {
case Fox:
switch(arg) {
case "type:white":
compound.getCompoundData().put("FoxType", new TagInt(1));
break;
case "type:red":
default:
compound.getCompoundData().put("FoxType", new TagInt(0));
break;
}
break;
case Mooshroom:
switch(arg) {
case "type:brown":
compound.getCompoundData().put("CowType", new TagInt(1));
break;
case "type:red":
default:
compound.getCompoundData().put("CowType", new TagInt(0));
break;
}
break;
case Cat:
String catTypeString = arg.replace("type:", "");
if (Util.isInt(catTypeString)) {
int catType = Integer.parseInt(catTypeString);
catType = Util.clamp(catType, 0, 10);
compound.getCompoundData().put("CatType", new TagInt(catType));
}
break;
case Villager:
case ZombieVillager:
String villagerTypeString = arg.replace("type:", "");
if (Util.isInt(villagerTypeString)) {
int villagerType = Integer.parseInt(villagerTypeString);
villagerType = Util.clamp(villagerType, 0, 6);
compound.getCompoundData().put("VillagerType", new TagInt(villagerType));
}
break;
}
}
}
}
use of de.Keyle.MyPet.api.util.inventory.material.MaterialHolder in project MyPet by xXKeyleXx.
the class MyEnderman method readExtendedInfo.
@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("BlockName")) {
ItemDatabase itemDatabase = MyPetApi.getServiceManager().getService(ItemDatabase.class).get();
String id = info.getAs("BlockName", TagString.class).getStringData();
MaterialHolder materialHolder = itemDatabase.getByID(id);
if (materialHolder != null) {
Material material = materialHolder.getMaterial();
if (material != null) {
if (MyPetApi.getCompatUtil().isCompatible("1.13")) {
setBlock(new ItemStack(material, 1));
} else {
short data = materialHolder.getLegacyId().getData();
setBlock(new ItemStack(material, 1, data));
}
setBlock(new ItemStack(material, 1));
}
}
} else if (info.containsKey("BlockID")) {
int id;
byte data = 0;
if (info.containsKeyAs("BlockID", TagShort.class)) {
id = info.getAs("BlockID", TagShort.class).getShortData();
} else {
id = info.getAs("BlockID", TagInt.class).getIntData();
}
if (info.containsKeyAs("BlockData", TagShort.class)) {
data = (byte) info.getAs("BlockData", TagShort.class).getShortData();
} else if (info.containsKeyAs("BlockData", TagInt.class)) {
data = (byte) info.getAs("BlockData", TagInt.class).getIntData();
}
ItemDatabase itemDatabase = MyPetApi.getServiceManager().getService(ItemDatabase.class).get();
MaterialHolder materialHolder = itemDatabase.getByLegacyId(id, data);
if (materialHolder != null) {
Material material = materialHolder.getMaterial();
if (MyPetApi.getCompatUtil().isCompatible("1.13")) {
setBlock(new ItemStack(material, 1));
} else {
setBlock(new ItemStack(material, 1, data));
}
}
} else if (info.containsKey("Block")) {
TagCompound itemStackCompund = info.getAs("Block", TagCompound.class);
try {
ItemStack block = MyPetApi.getPlatformHelper().compundToItemStack(itemStackCompund);
setBlock(block);
} catch (Exception e) {
MyPetApi.getLogger().warning("Could not load Block item from pet data!");
}
}
}
use of de.Keyle.MyPet.api.util.inventory.material.MaterialHolder in project MyPet by xXKeyleXx.
the class CommandChooseSkilltree 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 (WorldGroup.getGroupByWorld(player.getWorld()).isDisabled()) {
player.sendMessage(Translation.getString("Message.No.AllowedHere", player));
return true;
}
if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
final MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
final MyPetPlayer myPetOwner = myPet.getOwner();
if (Configuration.Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) {
myPet.autoAssignSkilltree();
sender.sendMessage(Translation.getString("Message.Command.ChooseSkilltree.AutomaticSkilltreeAssignment", myPet.getOwner()));
} else {
if (args.length >= 1) {
if (Configuration.Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) {
myPet.autoAssignSkilltree();
sender.sendMessage(Translation.getString("Message.Command.ChooseSkilltree.AutomaticSkilltreeAssignment", myPet.getOwner()));
} else if (myPet.getSkilltree() != null && Configuration.Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.OnlyOnce", myPet.getOwner()), myPet.getPetName()));
} else {
String skilltreeName = "";
for (String arg : args) {
skilltreeName += arg + " ";
}
skilltreeName = skilltreeName.substring(0, skilltreeName.length() - 1);
if (MyPetApi.getSkilltreeManager().hasSkilltree(skilltreeName)) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skilltreeName);
if (skilltree.getMobTypes().contains(myPet.getPetType()) && skilltree.checkRequirements(myPet)) {
int requiredLevel = skilltree.getRequiredLevel();
if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Message", player), myPet.getPetName(), requiredLevel));
} else if (myPet.setSkilltree(skilltree, MyPetSelectSkilltreeEvent.Source.PlayerCommand)) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", player), Colorizer.setColors(skilltree.getDisplayName())));
if (!myPet.getOwner().isMyPetAdmin() || Configuration.Skilltree.SWITCH_FEE_ADMIN) {
double switchPenalty = Configuration.Skilltree.SWITCH_FEE_FIXED;
switchPenalty += myPet.getExperience().getExp() * Configuration.Skilltree.SWITCH_FEE_PERCENT / 100.;
if (requiredLevel > 1) {
double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
switchPenalty = myPet.getExp() - switchPenalty < minExp ? myPet.getExp() - minExp : switchPenalty;
}
if (Configuration.LevelSystem.Experience.ALLOW_LEVEL_DOWNGRADE) {
myPet.getExperience().removeExp(switchPenalty);
} else {
myPet.getExperience().removeCurrentExp(switchPenalty);
}
}
} else {
sender.sendMessage(Translation.getString("Message.Skilltree.NotSwitched", player));
}
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", player), skilltreeName));
}
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", player), skilltreeName));
}
}
} else {
List<Skilltree> availableSkilltrees = new ArrayList<>();
for (Skilltree skilltree : MyPetApi.getSkilltreeManager().getOrderedSkilltrees()) {
if (skilltree.getMobTypes().contains(myPet.getPetType()) && skilltree.checkRequirements(myPet)) {
availableSkilltrees.add(skilltree);
}
}
if (availableSkilltrees.size() == 0) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.NoneAvailable", player), myPet.getPetName()));
return true;
}
final Map<Integer, Skilltree> skilltreeSlotMap = new HashMap<>();
IconMenu menu = new IconMenu(Util.cutString(Util.formatText(Translation.getString("Message.Skilltree.Available", myPetOwner), myPet.getPetName()), 32), event -> {
if (myPet != myPetOwner.getMyPet()) {
event.setWillClose(true);
event.setWillDestroy(true);
return;
}
if (myPet.getSkilltree() != null && Configuration.Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.OnlyOnce", myPet.getOwner()), myPet.getPetName()));
} else if (skilltreeSlotMap.containsKey(event.getPosition())) {
Skilltree selecedSkilltree = skilltreeSlotMap.get(event.getPosition());
if (selecedSkilltree != null) {
int requiredLevel = selecedSkilltree.getRequiredLevel();
if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Message", myPetOwner), myPet.getPetName(), requiredLevel));
} else if (myPet.setSkilltree(selecedSkilltree, MyPetSelectSkilltreeEvent.Source.PlayerCommand)) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", myPetOwner), Colorizer.setColors(selecedSkilltree.getDisplayName())));
if (!myPet.getOwner().isMyPetAdmin() || Configuration.Skilltree.SWITCH_FEE_ADMIN) {
double switchPenalty = Configuration.Skilltree.SWITCH_FEE_FIXED;
switchPenalty += myPet.getExperience().getExp() * Configuration.Skilltree.SWITCH_FEE_PERCENT / 100.;
if (requiredLevel > 1) {
double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
switchPenalty = myPet.getExp() - switchPenalty < minExp ? myPet.getExp() - minExp : switchPenalty;
}
if (Configuration.LevelSystem.Experience.ALLOW_LEVEL_DOWNGRADE) {
myPet.getExperience().removeExp(switchPenalty);
} else {
myPet.getExperience().removeCurrentExp(switchPenalty);
}
}
} else {
myPet.getOwner().sendMessage(Translation.getString("Message.Skilltree.NotSwitched", myPetOwner));
}
}
}
event.setWillClose(true);
event.setWillDestroy(true);
}, MyPetApi.getPlugin());
ItemDatabase itemDatabase = MyPetApi.getServiceManager().getService(ItemDatabase.class).get();
for (int i = 0; i < availableSkilltrees.size(); i++) {
Skilltree addedSkilltree = availableSkilltrees.get(i);
SkilltreeIcon icon = addedSkilltree.getIcon();
MaterialHolder material = itemDatabase.getByID(icon.getMaterial());
if (material == null) {
material = itemDatabase.getByID("oak_sapling");
}
IconMenuItem option = new IconMenuItem().setMaterial(material.getMaterial()).setGlowing(icon.isGlowing()).setTitle(ChatColor.RESET + "❱❱❱ " + ChatColor.DARK_GREEN + Colorizer.setColors(addedSkilltree.getDisplayName()) + ChatColor.RESET + " ❰❰❰");
if (material.isLegacy()) {
option.setData(material.getLegacyId().getData());
}
boolean selectable = false;
int requiredLevel = addedSkilltree.getRequiredLevel();
if (requiredLevel > 1) {
selectable = myPet.getExperience().getLevel() >= addedSkilltree.getRequiredLevel();
}
List<String> description = new ArrayList<>();
if (requiredLevel > 1) {
String reqLevelMessage = ChatColor.RESET + "▶▶▶ ";
if (selectable) {
reqLevelMessage += ChatColor.GREEN;
} else {
reqLevelMessage += ChatColor.DARK_RED;
}
reqLevelMessage += Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Item", myPetOwner), requiredLevel) + ChatColor.RESET + " ◀◀◀";
description.add(reqLevelMessage);
}
for (String line : addedSkilltree.getDescription()) {
description.add(ChatColor.RESET + Colorizer.setColors(line));
}
option.addLore(description);
menu.setOption(i, option);
skilltreeSlotMap.put(i, addedSkilltree);
}
menu.open(player);
}
}
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", player));
}
return true;
}
use of de.Keyle.MyPet.api.util.inventory.material.MaterialHolder in project MyPet by xXKeyleXx.
the class CommandShop method onCommand.
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!MyPetApi.getHookHelper().isEconomyEnabled()) {
sender.sendMessage(Translation.getString("Message.No.Economy", sender));
return true;
}
Player player = null;
if (sender instanceof ConsoleCommandSender && args.length < 2) {
sender.sendMessage("You can't use this command from server console!");
return true;
}
if (sender instanceof Player) {
if (WorldGroup.getGroupByWorld(((Player) sender).getWorld()).isDisabled()) {
sender.sendMessage(Translation.getString("Message.No.AllowedHere", sender));
return true;
}
}
if (args.length > 1) {
if (!(sender instanceof Player) || Permissions.has((Player) sender, "MyPet.admin")) {
player = Bukkit.getPlayer(args[1]);
if (player == null || !player.isOnline()) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.No.PlayerOnline", sender));
return true;
}
}
}
if (player == null) {
if (!(sender instanceof Player)) {
sender.sendMessage("You can't use this command from server console!");
return true;
}
player = (Player) sender;
}
final Optional<ShopManager> shopManager = MyPetApi.getServiceManager().getService(ShopManager.class);
if (shopManager.isPresent()) {
if (args.length > 0) {
String shop = args[0];
if (Permissions.has(player, "MyPet.shop.access." + shop) || Permissions.has(player, "MyPet.admin")) {
shopManager.get().open(shop, player);
} else {
player.sendMessage(Translation.getString("Message.No.Allowed", player));
}
} else {
String shop = shopManager.get().getDefaultShopName();
if (shop != null) {
if (Permissions.has(player, "MyPet.shop.access." + shop) || Permissions.has(player, "MyPet.admin")) {
shopManager.get().open(player);
return true;
}
} else {
final List<String> availableShops = getAvailablePetShops(player);
if (availableShops != null && availableShops.size() > 0) {
final Player finalPlayer = player;
Map<Integer, String> shops = new HashMap<>();
IconMenu menu = new IconMenu(Translation.getString("Message.Shop.Available", player), event -> {
String shopname = shops.get(event.getPosition());
if (shopname != null) {
final String finalShopname = shopname;
new BukkitRunnable() {
@Override
public void run() {
shopManager.get().open(finalShopname, finalPlayer);
}
}.runTaskLater(MyPetApi.getPlugin(), 5L);
event.setWillClose(true);
event.setWillDestroy(true);
}
}, MyPetApi.getPlugin());
ItemDatabase itemDatabase = MyPetApi.getServiceManager().getService(ItemDatabase.class).get();
for (String shopname : availableShops) {
PetShop s = shopManager.get().getShop(shopname);
IconMenuItem icon = new IconMenuItem();
icon.setTitle(RESET + Colorizer.setColors(s.getDisplayName()));
SkilltreeIcon si = s.getIcon();
MaterialHolder material = itemDatabase.getByID(si.getMaterial());
if (material == null) {
material = itemDatabase.getByID("chest");
}
icon.setMaterial(material.getMaterial()).setGlowing(si.isGlowing());
if (material.isLegacy()) {
icon.setData(material.getLegacyId().getData());
}
if (Util.isBetween(0, 53, s.getPosition())) {
menu.setOption(s.getPosition(), icon);
shops.put(s.getPosition(), s.getName());
} else {
shops.put(menu.addOption(icon), s.getName());
}
}
menu.open(player);
return true;
}
}
player.sendMessage(Translation.getString("Message.No.Allowed", player));
}
}
return true;
}
Aggregations