summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/com/earth2me/essentials/update/EssentialsUpdate.java
blob: d4ee6c0fc45aa76407a13786cccc49b386ab0ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.earth2me.essentials.update;

import com.earth2me.essentials.update.UpdateCheck.CheckResult;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;


public class EssentialsUpdate extends JavaPlugin
{
	private transient EssentialsHelp essentialsHelp;
	private transient UpdateProcess updateProcess;

	@Override
	public void onEnable()
	{
		if (!getDataFolder().exists() && !getDataFolder().mkdirs() ) {
			Bukkit.getLogger().severe("Could not create data folder:"+getDataFolder().getPath());
		}
		essentialsHelp = new EssentialsHelp(this);
		essentialsHelp.registerEvents();

		final UpdateCheck updateCheck = new UpdateCheck(this);
		updateProcess = new UpdateProcess(this, updateCheck);
		updateProcess.registerEvents();

		Bukkit.getLogger().info("EssentialsUpdate " + getDescription().getVersion() + " loaded.");

		if (updateCheck.isEssentialsInstalled())
		{
			updateCheck.checkForUpdates();
			final Version myVersion = new Version(getDescription().getVersion());
			if (updateCheck.getResult() == CheckResult.NEW_ESS && myVersion.equals(updateCheck.getNewVersion()))
			{
				Bukkit.getLogger().info("Versions of EssentialsUpdate and Essentials do not match. Starting automatic update.");
				updateProcess.doAutomaticUpdate();
			}
			updateCheck.scheduleUpdateTask();
		}
		else
		{
			Bukkit.getLogger().info("Essentials is ready for installation. Join the game and follow the instructions.");
		}
	}

	@Override
	public void onDisable()
	{
		essentialsHelp.onDisable();
	}

	@Override
	public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args)
	{
		if (command.getName().equalsIgnoreCase("essentialsupdate"))
		{
			updateProcess.onCommand(sender);
		}
		if (command.getName().equalsIgnoreCase("essentialshelp"))
		{
			essentialsHelp.onCommand(sender);
		}
		return true;
	}
}