use of org.bukkit.entity.EntityType in project Denizen-For-Bukkit by DenizenScript.
the class BiomeNMSImpl method getSpawnableEntities.
private List<EntityType> getSpawnableEntities(MobCategory creatureType) {
MobSpawnSettings mobs = biomeBase.getMobSettings();
WeightedRandomList<MobSpawnSettings.SpawnerData> typeSettingList = mobs.getMobs(creatureType);
List<EntityType> entityTypes = new ArrayList<>();
if (typeSettingList == null) {
return entityTypes;
}
for (MobSpawnSettings.SpawnerData meta : typeSettingList.unwrap()) {
try {
String n = net.minecraft.world.entity.EntityType.getKey(meta.type).getPath();
EntityType et = EntityType.fromName(n);
if (et == null) {
et = EntityType.valueOf(n.toUpperCase(Locale.ENGLISH));
}
entityTypes.add(et);
} catch (Throwable e) {
// Ignore the error. Likely from invalid entity type name output.
}
}
return entityTypes;
}
use of org.bukkit.entity.EntityType in project Essentials by drtshock.
the class EssentialsBlockListener method onBlockPlace.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event) {
// Do not rely on getItemInHand();
// http://leaky.bukkit.org/issues/663
final ItemStack is = LocationUtil.convertBlockToItem(event.getBlockPlaced());
if (is == null) {
return;
}
if (is.getType() == Material.MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == Material.MOB_SPAWNER) {
final BlockState blockState = event.getBlockPlaced().getState();
if (blockState instanceof CreatureSpawner) {
final CreatureSpawner spawner = (CreatureSpawner) blockState;
final EntityType type = ess.getSpawnerProvider().getEntityType(event.getItemInHand());
if (type != null && Mob.fromBukkitType(type) != null) {
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
spawner.setSpawnedType(type);
spawner.update();
}
}
}
}
final User user = ess.getUser(event.getPlayer());
if (user.hasUnlimited(is) && user.getBase().getGameMode() == GameMode.SURVIVAL) {
class UnlimitedItemSpawnTask implements Runnable {
@Override
public void run() {
user.getBase().getInventory().addItem(is);
user.getBase().updateInventory();
}
}
ess.scheduleSyncDelayedTask(new UnlimitedItemSpawnTask());
}
}
use of org.bukkit.entity.EntityType in project MyPet by xXKeyleXx.
the class ConfigurationLoader method upgradeConfig.
public static void upgradeConfig() {
FileConfiguration config = MyPetApi.getPlugin().getConfig();
if (config.contains("MyPet.Skilltree.SwitchPenalty.Fixed")) {
Skilltree.SWITCH_FEE_FIXED = config.getDouble("MyPet.Skilltree.SwitchPenalty.Fixed", 0.0);
Skilltree.SWITCH_FEE_PERCENT = config.getInt("MyPet.Skilltree.SwitchPenalty.Percent", 5);
Skilltree.SWITCH_FEE_ADMIN = config.getBoolean("MyPet.Skilltree.SwitchPenalty.Admin", false);
config.getConfigurationSection("MyPet.Skilltree").set("SwitchPenalty", null);
}
if (config.contains("MyPet.Name.OverHead")) {
Name.Tag.SHOW = config.getBoolean("MyPet.Name.OverHead.Visible", Name.Tag.SHOW);
Name.Tag.PREFIX = config.getString("MyPet.Name.OverHead.Prefix", Name.Tag.PREFIX);
Name.Tag.SUFFIX = config.getString("MyPet.Name.OverHead.Suffix", Name.Tag.SUFFIX);
config.getConfigurationSection("MyPet.Name").set("OverHead", null);
}
if (config.contains("MyPet.Update-Check")) {
Update.CHECK = config.getBoolean("MyPet.Update-Check", Update.CHECK);
config.getConfigurationSection("MyPet").set("Update-Check", null);
}
if (config.contains("MyPet.Activate-Resourcepack-By-Default")) {
config.getConfigurationSection("MyPet").set("Activate-Resourcepack-By-Default", null);
}
if (config.contains("MyPet.HungerSystem.HungerPointsPerFeed")) {
HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED = config.getDouble("MyPet.HungerSystem.HungerPointsPerFeed", HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED);
config.getConfigurationSection("MyPet.HungerSystem").set("HungerPointsPerFeed", null);
}
if (config.contains("MyPet.Backup")) {
config.getConfigurationSection("MyPet").set("Backup", null);
}
if (config.contains("MyPet.Skill.Inventory.Creative")) {
Skilltree.Skill.Backpack.OPEN_IN_CREATIVE = config.getBoolean("MyPet.Skill.Inventory.Creative", true);
Skilltree.Skill.Backpack.DROP_WHEN_OWNER_DIES = config.getBoolean("MyPet.Skill.Inventory.DropWhenOwnerDies", false);
config.getConfigurationSection("MyPet.Skill").set("Inventory", null);
}
if (config.contains("MyPet.Exp.Active")) {
for (EntityType entityType : EntityType.values()) {
if (MonsterExperience.mobExp.containsKey(entityType.name())) {
double max = config.getDouble("MyPet.Exp.Active." + entityType.name() + ".Max", 0.);
double min = config.getDouble("MyPet.Exp.Active." + entityType.name() + ".Min", 0.);
if (min == max) {
MonsterExperience.getMonsterExperience(entityType).setExp(max);
} else {
MonsterExperience.getMonsterExperience(entityType).setMin(min);
MonsterExperience.getMonsterExperience(entityType).setMax(max);
}
}
}
config.getConfigurationSection("MyPet.Exp").set("Active", null);
}
if (config.contains("MyPet.Hooks.PvPManager.Enabled")) {
config.getConfigurationSection("MyPet.Hooks").set("PvPManager", null);
}
if (config.contains("MyPet.Skill.Ride.FlyZones")) {
config.getConfigurationSection("MyPet.Skill.Ride").set("FlyZones", null);
}
if (config.contains("MyPet.Hooks")) {
MyPetApi.getLogger().warning("The config for all MyPet hooks moved to hooks-config.yml. All settings have been reset!");
config.getConfigurationSection("MyPet").set("Hooks", null);
}
if (config.contains("MyPet.Update.Token")) {
config.getConfigurationSection("MyPet.Update").set("Token", null);
}
if (config.contains("MyPet.FollowStartDistance")) {
Entity.MYPET_FOLLOW_START_DISTANCE = config.getDouble("MyPet.FollowStartDistance", 7.0D);
config.getConfigurationSection("MyPet").set("FollowStartDistance", null);
}
if (config.contains("MyPet.Entity.Skip-Movement-AI-Ticks")) {
config.getConfigurationSection("MyPet.Entity").set("Skip-Movement-AI-Ticks", null);
}
MyPetApi.getPlugin().saveConfig();
File petConfigFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "pet-config.yml");
FileConfiguration petConfig = new YamlConfiguration();
if (petConfigFile.exists()) {
try {
petConfig.load(petConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
if (petConfig != null && config.contains("MyPet.RemovePetsAfterRelease")) {
boolean removePetsAfterRelease = config.getBoolean("MyPet.RemovePetsAfterRelease", false);
boolean releasePetsOnDeath = config.getBoolean("MyPet.ReleasePetsOnDeath", false);
config.getConfigurationSection("MyPet").set("RemovePetsAfterRelease", null);
config.getConfigurationSection("MyPet").set("ReleasePetsOnDeath", null);
MyPetApi.getPlugin().saveConfig();
for (MyPetType petType : MyPetType.values()) {
if (!petType.checkMinecraftVersion()) {
continue;
}
DefaultInfo pi = petType.getMyPetClass().getAnnotation(DefaultInfo.class);
if (pi == null) {
continue;
}
petConfig.set("MyPet.Pets." + petType.name() + ".ReleaseOnDeath", releasePetsOnDeath);
petConfig.set("MyPet.Pets." + petType.name() + ".RemoveAfterRelease", removePetsAfterRelease);
}
}
for (MyPetType petType : MyPetType.values()) {
if (petConfig.contains("MyPet.Pets." + petType.name() + ".LeashFlags")) {
String[] flagString = petConfig.getString("MyPet.Pets." + petType.name() + ".LeashFlags").split(",");
Set<String> flags = new HashSet<>(Arrays.asList(flagString));
flags.remove("None");
petConfig.set("MyPet.Pets." + petType.name() + ".LeashRequirements", flags.toArray(new String[0]));
petConfig.getConfigurationSection("MyPet.Pets." + petType).set("LeashFlags", null);
}
}
if (petConfig.contains("MyPet.Pets.IronGolem.CanThrowUp")) {
MyPet.IronGolem.CAN_TOSS_UP = petConfig.getBoolean("MyPet.Pets.IronGolem.CanThrowUp");
petConfig.getConfigurationSection("MyPet.Pets.IronGolem").set("CanThrowUp", null);
}
try {
petConfig.save(petConfigFile);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bukkit.entity.EntityType in project MyPet by xXKeyleXx.
the class ConfigurationLoader method setDefault.
public static void setDefault() {
FileConfiguration config = MyPetApi.getPlugin().getConfig();
config.options().header("" + "#################################################################\n" + " This is the main configuration of MyPet #\n" + " You can find more info on the wiki: #\n" + " https://wiki.mypet-plugin.de/setup/configurations/config.yml #\n" + "#################################################################\n");
config.options().copyHeader(true);
config.addDefault("MyPet.Update.Check", Update.CHECK);
config.addDefault("MyPet.Update.Download", Update.DOWNLOAD);
config.addDefault("MyPet.Update.ReplaceOld", Update.REPLACE_OLD);
config.addDefault("MyPet.Update.In-Background", Update.ASYNC);
config.addDefault("MyPet.Update.OP-Notification", Update.SHOW_OP);
config.addDefault("MyPet.Leash.Consume", Misc.CONSUME_LEASH_ITEM);
config.addDefault("MyPet.Leash.AllowRanged", Misc.ALLOW_RANGED_LEASHING);
config.addDefault("MyPet.OwnerCanAttackPet", Misc.OWNER_CAN_ATTACK_PET);
config.addDefault("MyPet.DisablePetVersusPlayer", Misc.DISABLE_PET_VS_PLAYER);
config.addDefault("MyPet.RetainEquipmentOnTame", Misc.RETAIN_EQUIPMENT_ON_TAME);
config.addDefault("MyPet.Make-Pet-Invisible-When-Owner-Is-Invisible", Misc.INVISIBLE_LIKE_OWNER);
config.addDefault("MyPet.Log.Level", Log.LEVEL);
config.addDefault("MyPet.Log.Report-Errors", true);
config.addDefault("MyPet.Log.Unique-ID", SentryErrorReporter.getServerUUID().toString());
config.addDefault("MyPet.Max-Stored-Pet-Count", Misc.MAX_STORED_PET_COUNT);
config.addDefault("MyPet.Throw-PlayerMoveEvent-While-Riding", Misc.THROW_PLAYER_MOVE_EVENT_WHILE_RIDING);
config.addDefault("MyPet.Disable-All-Actionbar-Messages", Misc.DISABLE_ALL_ACTIONBAR_MESSAGES);
config.addDefault("MyPet.OverwriteLanguages", Misc.OVERWRITE_LANGUAGE);
config.addDefault("MyPet.Right-Click-Command", Misc.RIGHT_CLICK_COMMAND);
config.addDefault("MyPet.Recall-Pet-After-Despawn", Misc.RECALL_PET_AFTER_DESPAWN);
config.addDefault("MyPet.Entity.Skip-Target-AI-Ticks", Entity.SKIP_TARGET_AI_TICKS);
config.addDefault("MyPet.Entity.FollowStartDistance", Entity.MYPET_FOLLOW_START_DISTANCE);
config.addDefault("MyPet.Repository.Type", Repository.REPOSITORY_TYPE);
config.addDefault("MyPet.Repository.ConvertFrom", Repository.CONVERT_FROM);
config.addDefault("MyPet.Repository.LoadDelay", Repository.EXTERNAL_LOAD_DELAY);
config.addDefault("MyPet.Repository.MySQL.Database", Repository.MySQL.DATABASE);
config.addDefault("MyPet.Repository.MySQL.TablePrefix", Repository.MySQL.PREFIX);
config.addDefault("MyPet.Repository.MySQL.Host", Repository.MySQL.HOST);
config.addDefault("MyPet.Repository.MySQL.Password", Repository.MySQL.PASSWORD);
config.addDefault("MyPet.Repository.MySQL.User", Repository.MySQL.USER);
config.addDefault("MyPet.Repository.MySQL.Port", Repository.MySQL.PORT);
config.addDefault("MyPet.Repository.MySQL.MaxConnections", Repository.MySQL.POOL_SIZE);
config.addDefault("MyPet.Repository.MySQL.CharacterEncoding", Repository.MySQL.CHARACTER_ENCODING);
config.addDefault("MyPet.Repository.MongoDB.Database", Repository.MongoDB.DATABASE);
config.addDefault("MyPet.Repository.MongoDB.CollectionPrefix", Repository.MongoDB.PREFIX);
config.addDefault("MyPet.Repository.MongoDB.Host", Repository.MongoDB.HOST);
config.addDefault("MyPet.Repository.MongoDB.Password", Repository.MongoDB.PASSWORD);
config.addDefault("MyPet.Repository.MongoDB.User", Repository.MongoDB.USER);
config.addDefault("MyPet.Repository.MongoDB.Port", Repository.MongoDB.PORT);
config.addDefault("MyPet.Respawn.Time.Disabled", Respawn.DISABLE_AUTO_RESPAWN);
config.addDefault("MyPet.Respawn.Time.Default.Factor", Respawn.TIME_FACTOR);
config.addDefault("MyPet.Respawn.Time.Player.Factor", Respawn.TIME_PLAYER_FACTOR);
config.addDefault("MyPet.Respawn.Time.Default.Fixed", Respawn.TIME_FIXED);
config.addDefault("MyPet.Respawn.Time.Player.Fixed", Respawn.TIME_PLAYER_FIXED);
config.addDefault("MyPet.Respawn.EconomyCost.Fixed", Respawn.COSTS_FIXED);
config.addDefault("MyPet.Respawn.EconomyCost.Factor", Respawn.COSTS_FACTOR);
config.addDefault("MyPet.Permissions.Enabled", Permissions.ENABLED);
config.addDefault("MyPet.Permissions.Extended", Permissions.EXTENDED);
config.addDefault("MyPet.Permissions.Legacy", Permissions.LEGACY);
config.addDefault("MyPet.LevelSystem.CalculationMode", LevelSystem.CALCULATION_MODE);
config.addDefault("MyPet.HungerSystem.Active", HungerSystem.USE_HUNGER_SYSTEM);
config.addDefault("MyPet.HungerSystem.Time", HungerSystem.HUNGER_SYSTEM_TIME);
config.addDefault("MyPet.HungerSystem.SaturationPerFeed", HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED);
config.addDefault("MyPet.HungerSystem.Affect-Ride-Speed", HungerSystem.AFFECT_RIDE_SPEED);
config.addDefault("MyPet.HungerSystem.Affect-Beacon-Range", HungerSystem.AFFECT_BEACON_RANGE);
config.addDefault("MyPet.Skilltree.AutomaticAssignment", Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT);
config.addDefault("MyPet.Skilltree.RandomAssignment", Skilltree.RANDOM_SKILLTREE_ASSIGNMENT);
config.addDefault("MyPet.Skilltree.ChooseOnce", Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE);
config.addDefault("MyPet.Skilltree.PreventLevellingWithout", Skilltree.PREVENT_LEVELLING_WITHOUT_SKILLTREE);
config.addDefault("MyPet.Skilltree.SwitchFee.Fixed", Skilltree.SWITCH_FEE_FIXED);
config.addDefault("MyPet.Skilltree.SwitchFee.Percent", Skilltree.SWITCH_FEE_PERCENT);
config.addDefault("MyPet.Skilltree.SwitchFee.Admin", Skilltree.SWITCH_FEE_ADMIN);
config.addDefault("MyPet.Name.Filter", Lists.newArrayList("whore", "fuck"));
config.addDefault("MyPet.Name.MaxLength", Name.MAX_LENGTH);
config.addDefault("MyPet.Name.Tag.Show", Name.Tag.SHOW);
config.addDefault("MyPet.Name.Tag.Prefix", Name.Tag.PREFIX);
config.addDefault("MyPet.Name.Tag.Suffix", Name.Tag.SUFFIX);
config.addDefault("MyPet.Exp.DamageWeightedExperienceDistribution", LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION);
config.addDefault("MyPet.Exp.Passive.Always-Grant-Passive-XP", LevelSystem.Experience.ALWAYS_GRANT_PASSIVE_XP);
config.addDefault("MyPet.Exp.Passive.PercentPerMonster", LevelSystem.Experience.PASSIVE_PERCENT_PER_MONSTER);
config.addDefault("MyPet.Exp.Loss.Percent", LevelSystem.Experience.LOSS_PERCENT);
config.addDefault("MyPet.Exp.Loss.Fixed", LevelSystem.Experience.LOSS_FIXED);
config.addDefault("MyPet.Exp.Loss.Drop", LevelSystem.Experience.DROP_LOST_EXP);
config.addDefault("MyPet.Exp.Loss.Allow-Level-Drowngrade", LevelSystem.Experience.ALLOW_LEVEL_DOWNGRADE);
config.addDefault("MyPet.Exp.Gain.PreventFromSpawnReason", new ArrayList<>());
config.addDefault("MyPet.Exp.LevelCap", LevelSystem.Experience.LEVEL_CAP);
config.addDefault("MyPet.Exp.Disabled-Worlds", new String[0]);
config.addDefault("MyPet.Exp.Modifier.Global", LevelSystem.Experience.Modifier.GLOBAL);
config.addDefault("MyPet.Exp.Modifier.Use-Permissions", LevelSystem.Experience.Modifier.PERMISSION);
config.addDefault("MyPet.Skill.Control.Item", "lead");
config.addDefault("MyPet.Skill.Backpack.Creative", Skilltree.Skill.Backpack.OPEN_IN_CREATIVE);
config.addDefault("MyPet.Skill.Backpack.DropWhenOwnerDies", Skilltree.Skill.Backpack.DROP_WHEN_OWNER_DIES);
config.addDefault("MyPet.Skill.Beacon.HungerDecreaseTime", Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME);
config.addDefault("MyPet.Skill.Beacon.Disable-Head-Textures", Skilltree.Skill.Beacon.DISABLE_HEAD_TEXTURE);
config.addDefault("MyPet.Skill.Beacon.Party-Support", Skilltree.Skill.Beacon.PARTY_SUPPORT);
config.addDefault("MyPet.Skill.Ride.Item", "lead");
config.addDefault("MyPet.Skill.Ride.HungerPerMeter", Skilltree.Skill.Ride.HUNGER_PER_METER);
config.addDefault("MyPet.Skill.Ride.Prevent-Teleportation-While-Riding", Skilltree.Skill.Ride.PREVENT_TELEPORTATION);
config.addDefault("MyPet.Info.Wiki-URL", Misc.WIKI_URL);
config.options().copyDefaults(true);
MyPetApi.getPlugin().saveConfig();
File expConfigFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "exp-config.yml");
config = new YamlConfiguration();
config.options().header("" + "#####################################################################\n" + " This is the exp configuration of MyPet #\n" + " You can find more info on the wiki: #\n" + " https://wiki.mypet-plugin.de/setup/configurations/exp-config.yml #\n" + "#####################################################################\n");
config.options().copyHeader(true);
if (expConfigFile.exists()) {
try {
config.load(expConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
} else {
config.addDefault("Custom." + ChatColor.RED + "Big Boss.Max", 300.0);
config.addDefault("Custom." + ChatColor.RED + "Big Boss.Min", 150.0);
}
for (EntityType entityType : EntityType.values()) {
if (MonsterExperience.mobExp.containsKey(entityType.name())) {
config.addDefault("Default." + entityType.name() + ".Min", MonsterExperience.getMonsterExperience(entityType).getMin());
config.addDefault("Default." + entityType.name() + ".Max", MonsterExperience.getMonsterExperience(entityType).getMax());
}
}
config.options().copyDefaults(true);
try {
config.save(expConfigFile);
} catch (IOException e) {
e.printStackTrace();
}
File petConfigFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "pet-config.yml");
config = new YamlConfiguration();
if (petConfigFile.exists()) {
try {
config.load(petConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
config.options().header("" + "#####################################################################\n" + " This is the pet configuration of MyPet #\n" + " You can find more info on the wiki: #\n" + " https://wiki.mypet-plugin.de/setup/configurations/pet-config.yml #\n" + "#####################################################################\n");
config.options().copyHeader(true);
for (MyPetType petType : MyPetType.values()) {
if (!petType.checkMinecraftVersion()) {
continue;
}
DefaultInfo pi = petType.getMyPetClass().getAnnotation(DefaultInfo.class);
if (pi == null) {
continue;
}
config.addDefault("MyPet.Pets." + petType.name() + ".HP", pi.hp());
config.addDefault("MyPet.Pets." + petType.name() + ".Speed", pi.walkSpeed());
config.addDefault("MyPet.Pets." + petType.name() + ".Food", linkFood(pi.food()));
config.addDefault("MyPet.Pets." + petType.name() + ".LeashRequirements", pi.leashFlags());
config.addDefault("MyPet.Pets." + petType.name() + ".CustomRespawnTimeFactor", 0);
config.addDefault("MyPet.Pets." + petType.name() + ".CustomRespawnTimeFixed", 0);
config.addDefault("MyPet.Pets." + petType.name() + ".LeashItem", "lead");
config.addDefault("MyPet.Pets." + petType.name() + ".ReleaseOnDeath", false);
config.addDefault("MyPet.Pets." + petType.name() + ".RemoveAfterRelease", false);
}
config.addDefault("MyPet.Pets.Bat.CanGlide", MyPet.Bat.CAN_GLIDE);
config.addDefault("MyPet.Pets.Bee.CanGlide", MyPet.Bee.CAN_GLIDE);
config.addDefault("MyPet.Pets.Blaze.CanGlide", MyPet.Blaze.CAN_GLIDE);
config.addDefault("MyPet.Pets.Ghast.CanGlide", MyPet.Ghast.CAN_GLIDE);
config.addDefault("MyPet.Pets.Chicken.CanGlide", MyPet.Chicken.CAN_GLIDE);
config.addDefault("MyPet.Pets.EnderDragon.CanGlide", MyPet.EnderDragon.CAN_GLIDE);
config.addDefault("MyPet.Pets.Chicken.CanLayEggs", MyPet.Chicken.CAN_LAY_EGGS);
config.addDefault("MyPet.Pets.Cow.CanGiveMilk", MyPet.Cow.CAN_GIVE_MILK);
if (MyPetType.Donkey.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Donkey.GrowUpItem", "experience_bottle");
}
if (MyPetType.Hoglin.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Hoglin.GrowUpItem", "experience_bottle");
}
config.addDefault("MyPet.Pets.IronGolem.CanTossUp", MyPet.IronGolem.CAN_TOSS_UP);
config.addDefault("MyPet.Pets.Snowman.FixSnowTrack", MyPet.Snowman.FIX_SNOW_TRACK);
config.addDefault("MyPet.Pets.Chicken.GrowUpItem", "experience_bottle");
config.addDefault("MyPet.Pets.Cow.GrowUpItem", "experience_bottle");
config.addDefault("MyPet.Pets.Horse.GrowUpItem", "bread");
if (MyPetType.Llama.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Llama.GrowUpItem", "experience_bottle");
}
config.addDefault("MyPet.Pets.Mooshroom.GrowUpItem", "experience_bottle");
config.addDefault("MyPet.Pets.Mooshroom.CanGiveStew", MyPet.Mooshroom.CAN_GIVE_SOUP);
if (MyPetType.Mule.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Mule.GrowUpItem", "experience_bottle");
}
config.addDefault("MyPet.Pets.Ocelot.GrowUpItem", "experience_bottle");
if (MyPetType.Parrot.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Parrot.CanGlide", MyPet.Parrot.CAN_GLIDE);
}
if (MyPetType.Phantom.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Phantom.CanGlide", MyPet.Phantom.CAN_GLIDE);
}
config.addDefault("MyPet.Pets.Pig.GrowUpItem", "experience_bottle");
if (MyPetType.Piglin.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Piglin.GrowUpItem", "experience_bottle");
}
if (MyPetType.PiglinBrute.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.PiglinBrute.GrowUpItem", "experience_bottle");
}
config.addDefault("MyPet.Pets.PigZombie.GrowUpItem", "experience_bottle");
if (MyPetType.Rabbit.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Rabbit.GrowUpItem", "experience_bottle");
}
config.addDefault("MyPet.Pets.Sheep.CanBeSheared", MyPet.Sheep.CAN_BE_SHEARED);
config.addDefault("MyPet.Pets.Sheep.CanRegrowWool", MyPet.Sheep.CAN_REGROW_WOOL);
config.addDefault("MyPet.Pets.Sheep.GrowUpItem", "experience_bottle");
if (MyPetType.SkeletonHorse.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.SkeletonHorse.GrowUpItem", "experience_bottle");
}
if (MyPetType.Strider.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Strider.GrowUpItem", "experience_bottle");
}
if (MyPetType.Vex.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Vex.CanGlide", MyPet.Vex.CAN_GLIDE);
}
config.addDefault("MyPet.Pets.Villager.GrowUpItem", "experience_bottle");
config.addDefault("MyPet.Pets.Wolf.GrowUpItem", "experience_bottle");
config.addDefault("MyPet.Pets.Wither.CanGlide", MyPet.Wither.CAN_GLIDE);
if (MyPetType.Zoglin.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.Zoglin.GrowUpItem", "experience_bottle");
}
config.addDefault("MyPet.Pets.Zombie.GrowUpItem", "experience_bottle");
if (MyPetType.ZombieHorse.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.ZombieHorse.GrowUpItem", "experience_bottle");
}
if (MyPetType.ZombifiedPiglin.checkMinecraftVersion()) {
config.addDefault("MyPet.Pets.ZombifiedPiglin.GrowUpItem", "experience_bottle");
}
config.options().copyDefaults(true);
try {
config.save(petConfigFile);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bukkit.entity.EntityType in project InfernalMobs by NyaaCat.
the class CommandHandler method onCommand.
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (!sender.hasPermission("infernal_mobs.commands")) {
sender.sendMessage("You don't have permission to use this command!");
return true;
}
Arguments arg = Arguments.parse(args);
if (arg == null)
return false;
String subcommand = arg.next();
if (subcommand == null)
subcommand = "help";
try {
if ("help".equalsIgnoreCase(subcommand)) {
printHelp(sender);
} else if ("reload".equalsIgnoreCase(subcommand)) {
plugin.reloadConfig();
ConfigReader.reload();
plugin.reloadLoot();
InfernalMobs.instance.reloadMainLoopTask();
EnumAbilities.reloadAbility();
sender.sendMessage("§eConfig reloaded!");
} else if ("mobList".equalsIgnoreCase(subcommand)) {
sender.sendMessage("Mob List:");
for (EntityType t : EntityType.values()) {
sender.sendMessage(t.name());
}
} else if ("error".equalsIgnoreCase(subcommand)) {
plugin.errorList.add(asPlayer(sender));
sender.sendMessage("Click on a mob to send an error report about it.");
} else if ("info".equalsIgnoreCase(subcommand)) {
sender.sendMessage("Mounts: " + plugin.mobManager.mounteeMobs.size());
sender.sendMessage("Infernals: " + plugin.mobManager.mobMap.size());
} else if ("worldInfo".equalsIgnoreCase(subcommand)) {
final World world = asPlayer(sender).getWorld();
String enabled = ConfigReader.isEnabledWorld(world) ? "is" : "is not";
sender.sendMessage("The world you are currently in, " + world + " " + enabled + " enabled.");
sender.sendMessage("All the world that are enabled are: ");
for (World w : Bukkit.getWorlds()) {
if (ConfigReader.isEnabledWorld(w)) {
sender.sendMessage("- " + w.getName());
}
}
} else if ("abilities".equalsIgnoreCase(subcommand)) {
printAbilities(sender);
} else if ("addloot".equalsIgnoreCase(subcommand)) {
if (arg.top() == null) {
sender.sendMessage("usage: /im addloot <name>");
return true;
}
ItemStack item = asPlayer(sender).getInventory().getItemInMainHand();
if (item == null || item.getType() == Material.AIR) {
sender.sendMessage("Add fail. Please check if you are holding the item");
return true;
}
String name = arg.nextString();
LootItem li = new LootItem();
li.item = item.clone();
if (plugin.lootManager.cfg.lootItems.containsKey(name)) {
sender.sendMessage("Fail. Duplicated name");
return true;
}
plugin.lootManager.cfg.lootItems.put(name, li);
plugin.lootManager.save();
sender.sendMessage("Item Added.");
} else if ("checkchance".equalsIgnoreCase(subcommand)) {
if ("level".equalsIgnoreCase(arg.nextString())) {
int level = arg.nextInt();
Map<String, Double> m = plugin.lootManager.cfg.dropMap.get(level);
Double sum = m.values().stream().mapToDouble(Double::doubleValue).sum();
sender.sendMessage(String.format("Listing drop chance for level %d", level));
m.entrySet().stream().sorted((a, b) -> a.getValue().compareTo(b.getValue())).forEach(e -> sender.sendMessage(String.format(" %3.03f%% %s", e.getValue() / sum * 100D, getLootDisplayName(e.getKey()))));
} else {
String itemName = arg.nextString();
Map2D<Integer, String, Double> map = new Map2D<>();
for (Map.Entry<Integer, Map<String, Double>> e : plugin.lootManager.cfg.dropMap.entrySet()) {
map.setRow(e.getKey(), normalize(e.getValue()));
}
sender.sendMessage(String.format("Listing drop chance for item \"%s\"", itemName));
Map<Integer, Double> m = map.getColumn(itemName);
if (m.size() == 0) {
sender.sendMessage("Item never dropped");
} else {
normalize(m).entrySet().stream().sorted((a, b) -> a.getKey().compareTo(b.getKey())).forEach(e -> sender.sendMessage(String.format(" SpawnConfig%2d: %.03f%%", e.getKey(), e.getValue() * 100D)));
}
}
} else if ("setdrop".equalsIgnoreCase(subcommand)) {
int level = arg.nextInt();
String name = arg.nextString();
double w = arg.nextDouble();
plugin.lootManager.cfg.setDropChance(level, name, w);
plugin.lootManager.save();
sender.sendMessage("Chance set.");
} else if ("killall".equalsIgnoreCase(subcommand)) {
String worldName = arg.nextString();
World w = plugin.getServer().getWorld(worldName);
if (w == null) {
sender.sendMessage("World not found!");
return true;
}
for (Entity e : w.getEntities()) {
if (plugin.mobManager.mobMap.containsKey(e.getUniqueId())) {
plugin.mobManager.mobMap.remove(e.getUniqueId());
e.remove();
}
}
sender.sendMessage("Killed all loaded infernal mobs in that world!");
} else if ("kill".equalsIgnoreCase(subcommand)) {
int radius = arg.nextInt();
for (Entity e : asPlayer(sender).getNearbyEntities(radius, radius, radius)) {
if (plugin.mobManager.mobMap.containsKey(e.getUniqueId())) {
plugin.mobManager.mobMap.remove(e.getUniqueId());
e.remove();
}
}
sender.sendMessage("Killed all infernal mobs near you!");
} else if ("getloot".equalsIgnoreCase(subcommand)) {
if (arg.top() == null) {
Player player = asPlayer(sender);
final int powers = Helper.rand(ConfigReader.getMinimalLevel(), ConfigReader.getMaximumLevel());
final ItemStack gottenLoot = plugin.lootManager.getRandomLoot(player, powers);
if (gottenLoot != null && gottenLoot.getType() != Material.AIR) {
if (!InventoryUtils.addItem(player, gottenLoot)) {
Location location = player.getLocation();
player.getWorld().dropItem(location, gottenLoot);
}
if (sender.isOp()) {
sender.sendMessage("§eGave you some random loot!");
}
}
} else {
String name = arg.nextString();
ItemStack i = plugin.lootManager.getLootByName(asPlayer(sender), name);
if (i != null && i.getType() != Material.AIR) {
Player player = asPlayer(sender);
if (!InventoryUtils.addItem(player, i)) {
Location location = player.getLocation();
player.getWorld().dropItem(location, i);
}
if (sender.isOp()) {
sender.sendMessage("§eGave you the loot: " + name);
}
}
}
} else if ("spawn".equalsIgnoreCase(subcommand)) {
EntityType type = arg.nextEnum(EntityType.class);
Location farSpawnLoc = asPlayer(sender).getTargetBlock((Set<Material>) null, 200).getLocation();
farSpawnLoc.setY(farSpawnLoc.getY() + 1.0);
List<EnumAbilities> abilities = new ArrayList<>();
if (arg.top() == null) {
// random ability
abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), MobManager.getInfernalLevelForLocation(farSpawnLoc));
} else {
// ability list
while (arg.top() != null) abilities.add(arg.nextEnum(EnumAbilities.class));
}
if (abilities.size() <= 0) {
sender.sendMessage("No ability selected");
} else {
if (plugin.mobManager.spawnMob(type, farSpawnLoc, abilities, InfernalSpawnReason.COMMAND) != null) {
sender.sendMessage("Mob spawned");
} else {
sender.sendMessage("Cannot spawn mob");
}
}
} else if ("sm".equalsIgnoreCase(subcommand)) {
String mobName = arg.nextString();
if ("list".equalsIgnoreCase(mobName)) {
Map<String, CustomMobConfig.CustomMob> customMobs = ConfigReader.getCustomMobConfig().getCustomMobs();
Set<String> names = customMobs.keySet();
if (names.isEmpty()) {
if (sender.isOp()) {
sender.sendMessage("no custom mobs found");
}
} else {
if (sender.isOp()) {
String message = "&aHere " + (names.size() == 1 ? "is " : "are ") + names.size() + " mob" + (names.size() == 1 ? "" : "s");
message = ChatColor.translateAlternateColorCodes('&', message);
sender.sendMessage(message);
names.forEach(s -> {
sender.sendMessage(s);
});
}
}
return true;
}
Location farSpawnLoc = asPlayer(sender).getTargetBlock((Set<Material>) null, 200).getLocation();
CustomMobConfig mbConf = ConfigReader.getCustomMobConfig();
CustomMobConfig.CustomMob cm = mbConf.getByName(mobName);
List<EnumAbilities> abilities = new ArrayList<>();
mbConf.setAbilities(abilities, cm);
Mob mob = mbConf.spawnCustomMob(plugin.mobManager, farSpawnLoc, abilities, cm);
String top = arg.top();
if (top != null) {
cm.spawnLevel = Integer.parseInt(top);
} else {
cm.spawnLevel = cm.smSpawnLevel == -1 ? ConfigReader.getLevelConfig().getLevel(farSpawnLoc.distance(farSpawnLoc.getWorld().getSpawnLocation())) : cm.smSpawnLevel;
}
mbConf.addCustomAttr(mob, cm);
LivingEntity entity = (LivingEntity) InfernalMobs.instance.getServer().getEntity(mob.entityId);
InfernalMobSpawnEvent event = new InfernalMobSpawnEvent(entity, mob, null, InfernalSpawnReason.COMMAND);
MobManager.setInfernalMobName(event);
String spawned = "&aspawned &e" + cm.name + " &alevel &e" + cm.spawnLevel;
spawned = ChatColor.translateAlternateColorCodes('&', spawned);
sender.sendMessage(spawned);
} else if ("csm".equalsIgnoreCase(subcommand)) {
String mobName = arg.nextString();
if ("list".equalsIgnoreCase(mobName)) {
Map<String, CustomMobConfig.CustomMob> customMobs = ConfigReader.getCustomMobConfig().getCustomMobs();
Set<String> names = customMobs.keySet();
if (names.isEmpty()) {
if (sender.isOp()) {
sender.sendMessage("no custom mobs found");
}
} else {
if (sender.isOp()) {
String message = "&aHere " + (names.size() == 1 ? "is " : "are ") + names.size() + " mob" + (names.size() == 1 ? "" : "s");
message = ChatColor.translateAlternateColorCodes('&', message);
sender.sendMessage(message);
names.forEach(s -> {
sender.sendMessage(s);
});
}
}
return true;
}
String worldName = arg.nextString();
World w = plugin.getServer().getWorld(worldName);
if (w == null) {
sender.sendMessage("World not found!");
return true;
}
double x = arg.nextDouble();
double y = arg.nextDouble();
double z = arg.nextDouble();
Location loc = new Location(w, x, y, z);
CustomMobConfig mbConf = ConfigReader.getCustomMobConfig();
CustomMobConfig.CustomMob cm = mbConf.getByName(mobName);
List<EnumAbilities> abilities = new ArrayList<>();
mbConf.setAbilities(abilities, cm);
Mob mob = mbConf.spawnCustomMob(plugin.mobManager, loc, abilities, cm);
String top = arg.top();
if (top != null) {
cm.spawnLevel = Integer.parseInt(top);
} else {
cm.spawnLevel = cm.smSpawnLevel == -1 ? ConfigReader.getLevelConfig().getLevel(loc.distance(loc.getWorld().getSpawnLocation())) : cm.smSpawnLevel;
}
mbConf.addCustomAttr(mob, cm);
LivingEntity entity = (LivingEntity) InfernalMobs.instance.getServer().getEntity(mob.entityId);
InfernalMobSpawnEvent event = new InfernalMobSpawnEvent(entity, mob, null, InfernalSpawnReason.COMMAND);
MobManager.setInfernalMobName(event);
String spawned = "&aspawned &e" + cm.name + " &alevel &e" + cm.spawnLevel;
spawned = ChatColor.translateAlternateColorCodes('&', spawned);
sender.sendMessage(spawned);
} else if ("cspawn".equalsIgnoreCase(subcommand)) {
EntityType type = arg.nextEnum(EntityType.class);
String worldName = arg.nextString();
World w = plugin.getServer().getWorld(worldName);
if (w == null) {
sender.sendMessage("World not found!");
return true;
}
double x = arg.nextDouble();
double y = arg.nextDouble();
double z = arg.nextDouble();
Location loc = new Location(w, x, y, z);
List<EnumAbilities> abilities = new ArrayList<>();
if (arg.top() == null) {
// random ability
abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), MobManager.getInfernalLevelForLocation(loc));
} else {
// ability list
while (arg.top() != null) abilities.add(arg.nextEnum(EnumAbilities.class));
}
if (abilities.size() <= 0) {
sender.sendMessage("No ability selected");
} else {
if (plugin.mobManager.spawnMob(type, loc, abilities, InfernalSpawnReason.COMMAND) != null) {
sender.sendMessage("Mob spawned");
} else {
sender.sendMessage("Cannot spawn mob");
}
}
} else if ("pspawn".equalsIgnoreCase(subcommand)) {
EntityType type = arg.nextEnum(EntityType.class);
String playerName = arg.nextString();
Player p = Bukkit.getPlayer(playerName);
if (p == null) {
sender.sendMessage("Player not found: " + playerName);
return true;
}
Location loc = p.getLocation();
List<EnumAbilities> abilities = new ArrayList<>();
if (arg.top() == null) {
// random ability
abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), MobManager.getInfernalLevelForLocation(loc));
} else {
// ability list
while (arg.top() != null) abilities.add(arg.nextEnum(EnumAbilities.class));
}
if (abilities.size() <= 0) {
sender.sendMessage("No ability selected");
} else {
if (plugin.mobManager.spawnMob(type, loc, abilities, InfernalSpawnReason.COMMAND) != null) {
sender.sendMessage("Mob spawned");
} else {
sender.sendMessage("Cannot spawn mob");
}
}
}
} catch (NotPlayerException ex) {
sender.sendMessage("This command can only be run by a player!");
return true;
} catch (RuntimeException ex) {
sender.sendMessage("Command fail: " + ex.getMessage());
ex.printStackTrace();
return true;
}
return true;
// TODO set infernal spawner
// if (args[0].equals("setInfernal") && args.length == 2) {
// if (player.getTargetBlock((Set<Material>) null, 25).getType().equals((Object) Material.MOB_SPAWNER)) {
// final int delay = Integer.parseInt(args[1]);
// Location loc = player.getTargetBlock((Set<Material>) null, 25).getLocation();
// plugin.persist.validInfernalSpawners.put(loc, delay);
// sender.sendMessage("Spawner set to infernal with a " + delay + " second delay!");
// } else {
// sender.sendMessage("You must be looking a spawner to make it infernal!");
// }
// }
}
Aggregations