use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class CommandOptionSkilltree method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender commandSender, String[] strings) {
if (strings.length == 2) {
return null;
}
if (strings.length == 3) {
Player player = Bukkit.getServer().getPlayer(strings[1]);
if (player == null || !player.isOnline()) {
return CommandAdmin.EMPTY_LIST;
}
if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(myPet.getPetType());
List<String> skilltreeList = new ArrayList<>();
for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
skilltreeList.add(skillTree.getName());
}
return skilltreeList;
}
}
return CommandAdmin.EMPTY_LIST;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class MyPetPlugin method onEnable.
public void onEnable() {
this.isReady = false;
Updater updater = new Updater("MyPet");
updater.update();
if (compatUtil.getInternalVersion() == null || !MyPetVersion.isValidBukkitPacket(compatUtil.getInternalVersion())) {
getLogger().warning(ChatColor.RED + "This version of MyPet is not compatible with \"" + compatUtil.getInternalVersion() + "\". Is MyPet up to date?");
updater.waitForDownload();
setEnabled(false);
return;
}
serviceManager.activate(Load.State.OnEnable);
pluginHookManager.enableHooks();
serviceManager.activate(Load.State.AfterHooks);
entityRegistry.registerEntityTypes();
if (getLogger() instanceof MyPetLogger) {
((MyPetLogger) getLogger()).updateDebugLoggerLogLevel();
}
compatManager.enable();
getLogger().info("Compat mode for " + compatUtil.getInternalVersion() + " loaded.");
// register event listener
PlayerListener playerListener = new PlayerListener();
getServer().getPluginManager().registerEvents(playerListener, this);
VehicleListener vehicleListener = new VehicleListener();
getServer().getPluginManager().registerEvents(vehicleListener, this);
EntityListener entityListener = new EntityListener();
getServer().getPluginManager().registerEvents(entityListener, this);
LevelUpListener levelupListener = new LevelUpListener();
getServer().getPluginManager().registerEvents(levelupListener, this);
WorldListener worldListener = new WorldListener();
getServer().getPluginManager().registerEvents(worldListener, this);
// register commands
getCommand("petname").setExecutor(new CommandName());
getCommand("petcall").setExecutor(new CommandCall());
getCommand("petsendaway").setExecutor(new CommandSendAway());
getCommand("petstop").setExecutor(new CommandStop());
getCommand("petrelease").setExecutor(new CommandRelease());
getCommand("mypet").setExecutor(new CommandHelp());
getCommand("petinventory").setExecutor(new CommandInventory());
getCommand("petpickup").setExecutor(new CommandPickup());
getCommand("petbehavior").setExecutor(new CommandBehavior());
getCommand("petinfo").setExecutor(new CommandInfo());
getCommand("mypetadmin").setExecutor(new CommandAdmin());
getCommand("petskill").setExecutor(new CommandSkill());
getCommand("petskilltree").setExecutor(new CommandShowSkillTree());
getCommand("petchooseskilltree").setExecutor(new CommandChooseSkilltree());
getCommand("petbeacon").setExecutor(new CommandBeacon());
getCommand("petrespawn").setExecutor(new CommandRespawn());
getCommand("pettype").setExecutor(new CommandPetType());
getCommand("petsettings").setExecutor(new CommandSettings());
getCommand("petswitch").setExecutor(new CommandSwitch());
getCommand("petstore").setExecutor(new CommandStore());
getCommand("petlist").setExecutor(new CommandList());
// register skills
registerSkillsInfo();
registerSkills();
// create folders
File skilltreeFolder = new File(getDataFolder().getPath(), "skilltrees");
getDataFolder().mkdirs();
boolean createDefaultSkilltree = skilltreeFolder.mkdirs();
new File(getDataFolder(), "locale").mkdirs();
new File(getDataFolder(), "logs").mkdirs();
if (createDefaultSkilltree) {
platformHelper.copyResource(this, "skilltrees/default.st", new File(skilltreeFolder, "default.st"));
getLogger().info("Default skilltree file created (default.st).");
}
// load skilltrees
List<String> petTypes = new LinkedList<>();
petTypes.add("default");
for (MyPetType type : MyPetType.all()) {
petTypes.add(type.name());
}
SkillTreeMobType.clearMobTypes();
SkillTreeLoaderNBT.getSkilltreeLoader().loadSkillTrees(getDataFolder().getPath() + File.separator + "skilltrees", petTypes);
Set<String> skilltreeNames = new LinkedHashSet<>();
for (MyPetType mobType : MyPetType.values()) {
SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(mobType);
SkillTreeLoader.addDefault(skillTreeMobType);
SkillTreeLoader.manageInheritance(skillTreeMobType);
skilltreeNames.addAll(skillTreeMobType.getSkillTreeNames());
}
// register skilltree permissions
for (String skilltreeName : skilltreeNames) {
try {
Bukkit.getPluginManager().addPermission(new Permission("MyPet.skilltree." + skilltreeName));
} catch (Exception ignored) {
}
}
for (int i = 0; i <= Configuration.Misc.MAX_STORED_PET_COUNT; i++) {
try {
Bukkit.getPluginManager().addPermission(new Permission("MyPet.petstorage.limit." + i));
} catch (Exception ignored) {
}
}
File translationReadme = new File(getDataFolder(), "locale" + File.separator + "readme.txt");
if (!translationReadme.exists()) {
platformHelper.copyResource(this, "locale-readme.txt", translationReadme);
}
Translation.init();
for (Team team : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) {
if (team.getName().startsWith("MyPet-")) {
team.unregister();
}
}
// init repository
repo = new SqLiteRepository();
try {
repo.init();
} catch (RepositoryInitException ignored) {
setEnabled(false);
return;
}
File nbtFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "My.Pets");
if (nbtFile.exists()) {
Converter.convert();
}
if (repo instanceof Scheduler) {
Timer.addTask((Scheduler) repo);
}
// load worldgroups
loadGroups(new File(getDataFolder().getPath(), "worldgroups.yml"));
Timer.startTimer();
// init Metrics
Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SingleLineChart("active_pets", () -> myPetManager.countActiveMyPets()));
metrics.addCustomChart(new Metrics.SimplePie("build", MyPetVersion::getBuild));
metrics.addCustomChart(new Metrics.SimplePie("update_mode", () -> {
String mode = "Disabled";
if (Configuration.Update.CHECK) {
mode = "Check";
if (Configuration.Update.DOWNLOAD) {
mode += " & Download";
}
}
return mode;
}));
updater.waitForDownload();
getLogger().info("version " + MyPetVersion.getVersion() + "-b" + MyPetVersion.getBuild() + ChatColor.GREEN + " ENABLED");
this.isReady = true;
serviceManager.activate(Load.State.OnReady);
// load pets for online players
new BukkitRunnable() {
@Override
public void run() {
for (final Player player : getServer().getOnlinePlayers()) {
repo.getMyPetPlayer(player, new RepositoryCallback<MyPetPlayer>() {
@Override
public void callback(final MyPetPlayer p) {
if (p != null) {
final MyPetPlayerImpl onlinePlayer = (MyPetPlayerImpl) p;
onlinePlayer.setLastKnownName(player.getName());
if (!player.getUniqueId().equals(onlinePlayer.getOfflineUUID())) {
if (onlinePlayer.getMojangUUID() == null) {
onlinePlayer.setMojangUUID(player.getUniqueId());
}
onlinePlayer.setOnlineMode(true);
}
playerManager.setOnline(onlinePlayer);
final WorldGroup joinGroup = WorldGroup.getGroupByWorld(player.getWorld().getName());
if (onlinePlayer.hasMyPet()) {
MyPet myPet = onlinePlayer.getMyPet();
if (!myPet.getWorldGroup().equals(joinGroup.getName())) {
myPetManager.deactivateMyPet(onlinePlayer, true);
}
}
if (joinGroup != null && !onlinePlayer.hasMyPet() && onlinePlayer.hasMyPetInWorldGroup(joinGroup.getName())) {
final UUID petUUID = onlinePlayer.getMyPetForWorldGroup(joinGroup.getName());
MyPetApi.getRepository().getMyPet(petUUID, new RepositoryCallback<StoredMyPet>() {
@Override
public void callback(StoredMyPet storedMyPet) {
myPetManager.activateMyPet(storedMyPet);
if (onlinePlayer.hasMyPet()) {
final MyPet myPet = onlinePlayer.getMyPet();
final MyPetPlayer myPetPlayer = myPet.getOwner();
if (myPet.wantsToRespawn()) {
if (myPetPlayer.hasMyPet()) {
MyPet runMyPet = myPetPlayer.getMyPet();
switch(runMyPet.createEntity()) {
case Canceled:
runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", myPet.getOwner()), runMyPet.getPetName()));
break;
case NoSpace:
runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", myPet.getOwner()), runMyPet.getPetName()));
break;
case NotAllowed:
runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPet.getOwner()), myPet.getPetName()));
break;
case Dead:
runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", myPet.getOwner()), myPet.getPetName(), myPet.getRespawnTime()));
break;
case Flying:
runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", myPet.getOwner()), myPet.getPetName()));
break;
case Success:
runMyPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", myPet.getOwner()), runMyPet.getPetName()));
break;
}
}
}
}
}
});
}
onlinePlayer.checkForDonation();
}
}
});
}
}
}.runTaskLater(this, 0);
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class CommandChooseSkilltree method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String s, String[] strings) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
if (Configuration.Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) {
return CommandAdmin.EMPTY_LIST;
} else if (myPet.getSkilltree() != null && Configuration.Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) {
return CommandAdmin.EMPTY_LIST;
} else if (SkillTreeMobType.hasMobType(myPet.getPetType())) {
SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(myPet.getPetType());
List<String> skilltreeList = new ArrayList<>();
for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
if (Permissions.hasLegacy(player, "MyPet.skilltree.", skillTree.getPermission())) {
skilltreeList.add(skillTree.getName());
}
}
return skilltreeList;
}
}
}
return CommandAdmin.EMPTY_LIST;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class CommandShowSkillTree method onCommand.
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
SkillTreeMobType mobType;
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("default")) {
mobType = SkillTreeMobType.DEFAULT;
} else {
MyPetType type = MyPetType.byName(args[0]);
if (type != null) {
mobType = SkillTreeMobType.byPetType(type);
} else {
MyPetApi.getLogger().info("There is " + ChatColor.RED + "no" + ChatColor.RESET + " mobtype with the name: " + ChatColor.AQUA + args[0]);
return true;
}
}
if (args.length >= 2) {
if (mobType.hasSkillTree(args[1])) {
SkillTree skillTree = mobType.getSkillTree(args[1]);
MyPetApi.getLogger().info("----- MyPet Skilltree: " + ChatColor.AQUA + skillTree.getName() + ChatColor.RESET + " - Inherits: " + (skillTree.getInheritance() != null ? ChatColor.AQUA + skillTree.getInheritance() + ChatColor.RESET : ChatColor.DARK_GRAY + "none" + ChatColor.RESET) + " -----");
for (SkillTreeLevel lvl : skillTree.getLevelList()) {
MyPetApi.getLogger().info(ChatColor.YELLOW + " " + lvl.getLevel() + ChatColor.RESET + ": (" + (lvl.hasLevelupMessage() ? Colorizer.setColors(lvl.getLevelupMessage()) + ChatColor.RESET : "-") + ")");
for (SkillInfo skill : lvl.getSkills()) {
if (skill.isAddedByInheritance()) {
MyPetApi.getLogger().info(" " + ChatColor.DARK_GRAY + skill.getName());
} else {
MyPetApi.getLogger().info(" " + skill.getName());
}
}
}
MyPetApi.getLogger().info("----- MyPet Skilltree " + ChatColor.AQUA + skillTree.getName() + ChatColor.RESET + " end -----");
} else {
MyPetApi.getLogger().info("There is " + ChatColor.RED + "no" + ChatColor.RESET + " skilltree with the name: " + ChatColor.AQUA + args[1]);
}
} else {
MyPetApi.getLogger().info("----- MyPet Skilltrees for: " + ChatColor.GREEN + args[0]);
for (String skillTreeName : mobType.getSkillTreeNames()) {
MyPetApi.getLogger().info(" " + skillTreeName);
}
}
} else {
return false;
}
} else {
sender.sendMessage("Can only be used in server console");
}
return true;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class SkillTreeLoader method addDefault.
public static void addDefault(SkillTreeMobType skillTreeMobType) {
SkillTreeMobType defaultSkillTreeMobType = SkillTreeMobType.DEFAULT;
for (String skillTreeName : defaultSkillTreeMobType.getSkillTreeNames()) {
if (!skillTreeMobType.hasSkillTree(skillTreeName) && defaultSkillTreeMobType.hasSkillTree(skillTreeName)) {
SkillTree newSkillTree = defaultSkillTreeMobType.getSkillTree(skillTreeName).clone();
for (SkillTreeLevel level : newSkillTree.getLevelList()) {
for (SkillInfo skill : level.getSkills()) {
skill.setIsInherited(true);
}
}
skillTreeMobType.addSkillTree(newSkillTree);
}
}
}
Aggregations