use of de.Keyle.MyPet.repository.types.SqLiteRepository in project MyPet by xXKeyleXx.
the class PlayerListener method on.
@EventHandler
public void on(final PlayerJoinEvent event) {
long delay = MyPetApi.getRepository() instanceof SqLiteRepository ? 1L : Configuration.Repository.EXTERNAL_LOAD_DELAY;
new BukkitRunnable() {
@Override
public void run() {
MyPetApi.getRepository().getMyPetPlayer(event.getPlayer(), new RepositoryCallback<MyPetPlayer>() {
@Override
public void callback(final MyPetPlayer p) {
final MyPetPlayerImpl joinedPlayer = (MyPetPlayerImpl) p;
joinedPlayer.setLastKnownName(event.getPlayer().getName());
if (!event.getPlayer().getUniqueId().equals(joinedPlayer.getOfflineUUID())) {
if (joinedPlayer.getMojangUUID() == null) {
joinedPlayer.setMojangUUID(event.getPlayer().getUniqueId());
}
joinedPlayer.setOnlineMode(true);
}
MyPetApi.getPlayerManager().setOnline(joinedPlayer);
final WorldGroup joinGroup = WorldGroup.getGroupByWorld(event.getPlayer().getWorld().getName());
if (joinedPlayer.hasMyPet()) {
MyPet myPet = joinedPlayer.getMyPet();
if (!myPet.getWorldGroup().equals(joinGroup.getName())) {
MyPetApi.getMyPetManager().deactivateMyPet(joinedPlayer, true);
}
}
if (!joinedPlayer.hasMyPet() && joinedPlayer.hasMyPetInWorldGroup(joinGroup.getName())) {
final UUID petUUID = joinedPlayer.getMyPetForWorldGroup(joinGroup.getName());
MyPetApi.getRepository().getMyPet(petUUID, new RepositoryCallback<StoredMyPet>() {
@Override
public void callback(StoredMyPet storedMyPet) {
MyPetApi.getMyPetManager().activateMyPet(storedMyPet);
if (joinedPlayer.hasMyPet()) {
final MyPet myPet = joinedPlayer.getMyPet();
if (myPet.wantsToRespawn()) {
switch(myPet.createEntity()) {
case Canceled:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", joinedPlayer), myPet.getPetName()));
break;
case NotAllowed:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", joinedPlayer), myPet.getPetName()));
break;
case Dead:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", joinedPlayer), myPet.getPetName(), myPet.getRespawnTime()));
break;
case Flying:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", joinedPlayer), myPet.getPetName()));
break;
case NoSpace:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", joinedPlayer), myPet.getPetName()));
break;
}
}
}
}
});
}
joinedPlayer.checkForDonation();
Bukkit.getServer().getPluginManager().callEvent(new MyPetPlayerJoinEvent(joinedPlayer));
}
});
}
}.runTaskLater(MyPetApi.getPlugin(), delay);
if (event.getPlayer().isOp() && Updater.isUpdateAvailable()) {
event.getPlayer().sendMessage(Util.formatText(Translation.getString("Message.Update.Available", event.getPlayer())) + " " + Updater.getLatest());
event.getPlayer().sendMessage(ChatColor.DARK_GREEN + " https://mypet-plugin.de/download");
}
}
use of de.Keyle.MyPet.repository.types.SqLiteRepository in project MyPet by xXKeyleXx.
the class Converter method convert.
public static boolean convert() {
MyPetApi.getLogger().info("Converting from NBT to " + Configuration.Repository.REPOSITORY_TYPE + "...");
NbtRepository fromRepo = new NbtRepository();
fromRepo.init();
SqLiteRepository toRepo = (SqLiteRepository) MyPetApi.getRepository();
List<MyPetPlayer> playerList = fromRepo.getAllMyPetPlayers();
toRepo.addMyPetPlayers(playerList);
List<StoredMyPet> pets = fromRepo.getAllMyPets();
toRepo.addMyPets(pets);
toRepo.save();
fromRepo.disable();
File nbtFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "My.Pets");
File nbtFileOld = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "My.Pets.old");
nbtFile.renameTo(nbtFileOld);
MyPetApi.getPlugin().getConfig().set("MyPet.Repository.NBT", null);
MyPetApi.getPlugin().saveConfig();
MyPetApi.getLogger().info("Conversion from NBT to " + Configuration.Repository.REPOSITORY_TYPE + " complete!");
return true;
}
use of de.Keyle.MyPet.repository.types.SqLiteRepository 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);
}
Aggregations