summaryrefslogtreecommitdiff
path: root/src/main/java/com/redstoner/misc/ModuleInfo.java
blob: e96e81375e6639a09c59904938d8e418850aaf5a (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.redstoner.misc;

import java.io.InputStream;
import java.io.InputStreamReader;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import com.redstoner.coremods.moduleLoader.ModuleLoader;
import com.redstoner.exceptions.MissingVersionException;
import com.redstoner.modules.Module;

public class ModuleInfo {

	private String simpleName;
	private String displayName;
	private String category;
	private String description;
	private String version;
	
	private String warning;
	
	public ModuleInfo(InputStream descriptor, Module module) {
		try {
			InputStreamReader reader = new InputStreamReader(descriptor);
			FileConfiguration config = YamlConfiguration.loadConfiguration(reader);
		
			displayName = config.getString("displayName");
			category = config.getString("category");
			description = config.getString("description");
		}
		catch (Exception e) {
			warning = "Descriptor file could not be loaded, using the class's name.";
		}
		
		simpleName = module.getClass().getSimpleName();
		
		if (displayName == null)
			displayName = simpleName;
		
		if (category == null)
			category = "Other";
		
		try {
			version = VersionHelper.getVersion(module.getClass());
		} catch (MissingVersionException e) {}
	}

	public String getSimpleName() {
		return simpleName;
	}
	
	public String getDisplayName() {
		return displayName;
	}

	public String getCategory() {
		return category;
	}

	public String getDescription() {
		return description;
	}

	public String getWarning() {
		return warning;
	}
	
	public String getVersion() {
		return version;
	}
	
	public String getModuleInfoHover() {
		return "&8&o" + getSimpleName() + "\n"
			 + "&r&e" + (getVersion() == null? "&cVersion Missing" : getVersion())
             + "&r&9" + (ModuleLoader.hasCategories()? "\n" + getCategory() : "")
             + "&r&7" + (getDescription() == null? "" : "\n\n" + getDescription());
	}
	
	
}