Skip to content

Commit 30fc79e

Browse files
committed
New test commit
Signed-off-by: Staartvin <[email protected]>
1 parent 561400e commit 30fc79e

File tree

1 file changed

+165
-164
lines changed

1 file changed

+165
-164
lines changed
Lines changed: 165 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,165 @@
1-
package me.staartvin.plugins.pluginlibrary;
2-
3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.List;
6-
7-
import me.staartvin.plugins.pluginlibrary.hooks.LibraryHook;
8-
import me.staartvin.plugins.pluginlibrary.hooks.customstats.CustomStatsManager;
9-
import net.md_5.bungee.api.ChatColor;
10-
11-
import org.bukkit.plugin.java.JavaPlugin;
12-
13-
/**
14-
* Main class of PluginLibrary
15-
* <p>
16-
* Date created: 14:06:30 12 aug. 2015
17-
*
18-
* @author Staartvin
19-
*
20-
*/
21-
public class PluginLibrary extends JavaPlugin {
22-
23-
private final List<Library> loadedLibraries = new ArrayList<Library>();
24-
private CustomStatsManager customStatsManager;
25-
26-
@Override
27-
public void onEnable() {
28-
29-
loadedLibraries.clear();
30-
31-
//this is a test
32-
logMessage(ChatColor.GOLD + "***== Loading libraries ==***");
33-
logMessage(ChatColor.GOLD + "***== Loaded " + ChatColor.WHITE
34-
+ loadLibraries() + ChatColor.GOLD + " libraries! ==***");
35-
36-
if (this.isLibraryLoaded(Library.STATS)) {
37-
// Register custom stats so that Stats has special mobs and food eaten requirement.
38-
setCustomStatsManager(new CustomStatsManager(this));
39-
this.getCustomStatsManager().registerCustomStats();
40-
}
41-
42-
logMessage(ChatColor.GOLD + "Loaded libraries: "
43-
+ getLoadedLibrariesAsString());
44-
45-
logMessage(ChatColor.GREEN
46-
+ "*** Ready for plugins to send/retrieve data. ***");
47-
48-
logMessage(this.getDescription().getFullName() + " is now enabled!");
49-
}
50-
51-
@Override
52-
public void onDisable() {
53-
54-
loadedLibraries.clear();
55-
56-
logMessage(this.getDescription().getFullName() + " is now disabled!");
57-
}
58-
59-
/**
60-
* Load all libraries, this will be done automatically by the plugin.
61-
*
62-
* @return how many libraries were loaded.
63-
*/
64-
public int loadLibraries() {
65-
int count = 0;
66-
67-
for (Library l : Library.values()) {
68-
if (l.getHook().isAvailable()) {
69-
70-
// One more library loaded.
71-
if (l.getHook().hook()) {
72-
loadedLibraries.add(l);
73-
count++;
74-
}
75-
76-
}
77-
}
78-
79-
return count;
80-
}
81-
82-
public void logMessage(String message) {
83-
// This makes sure it can support colours.
84-
this.getServer().getConsoleSender()
85-
.sendMessage(ChatColor.GRAY + "[PluginLibrary] " + message);
86-
}
87-
88-
/**
89-
* Get a list of all loaded libraries. <br>
90-
* This list is unmodifiable and when you try to alter it, it will give an
91-
* {@link UnsupportedOperationException}.
92-
*
93-
* @return a list of loaded libraries.
94-
*/
95-
public List<Library> getLoadedLibraries() {
96-
return Collections.unmodifiableList(loadedLibraries);
97-
}
98-
99-
/**
100-
* Gets the library for a specific plugin. <br>
101-
* Will throw a {@link IllegalArgumentException} when there is no library
102-
* with the given name.
103-
*
104-
* @param pluginName Name of the plugin. Case-insensitive!
105-
* @return {@link me.staartvin.plugins.pluginlibrary.LibraryHook} class or
106-
* an error.
107-
*/
108-
public static LibraryHook getLibrary(String pluginName) {
109-
return Library.getEnum(pluginName).getHook();
110-
}
111-
112-
/**
113-
* @see #getLibrary(String)
114-
* <br>
115-
* Returns the same as {@link #getLibrary(String)}.
116-
* @param lib Library enum to get the library hook for.
117-
* @return {@link me.staartvin.plugins.pluginlibrary.LibraryHook} class or
118-
* an error.
119-
*/
120-
public static LibraryHook getLibrary(Library lib) {
121-
return lib.getHook();
122-
}
123-
124-
/**
125-
* Checks to see whether the library is loaded and thus ready for use.
126-
*
127-
* @param lib Library to check.
128-
* @return true if the library is loaded; false otherwise.
129-
*/
130-
public boolean isLibraryLoaded(Library lib) {
131-
return loadedLibraries.contains(lib);
132-
}
133-
134-
public CustomStatsManager getCustomStatsManager() {
135-
return customStatsManager;
136-
}
137-
138-
public void setCustomStatsManager(CustomStatsManager customStatsManager) {
139-
this.customStatsManager = customStatsManager;
140-
}
141-
142-
private String getLoadedLibrariesAsString() {
143-
StringBuilder builder = new StringBuilder("");
144-
145-
for (int i = 0, l = loadedLibraries.size(); i < l; i++) {
146-
if (i == 0) {
147-
builder.append(ChatColor.DARK_AQUA
148-
+ loadedLibraries.get(i).getPluginName() + ChatColor.RESET);
149-
} else if (i == (l - 1)) {
150-
builder.append(ChatColor.GRAY
151-
+ " and "
152-
+ (ChatColor.DARK_AQUA
153-
+ loadedLibraries.get(i).getPluginName() + ChatColor.RESET));
154-
} else {
155-
builder.append(ChatColor.GRAY
156-
+ ", "
157-
+ (ChatColor.DARK_AQUA
158-
+ loadedLibraries.get(i).getPluginName() + ChatColor.RESET));
159-
}
160-
}
161-
162-
return builder.toString();
163-
}
164-
}
1+
package me.staartvin.plugins.pluginlibrary;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
import me.staartvin.plugins.pluginlibrary.hooks.LibraryHook;
8+
import me.staartvin.plugins.pluginlibrary.hooks.customstats.CustomStatsManager;
9+
import net.md_5.bungee.api.ChatColor;
10+
11+
import org.bukkit.plugin.java.JavaPlugin;
12+
13+
/**
14+
* Main class of PluginLibrary
15+
* <p>
16+
* Date created: 14:06:30 12 aug. 2015
17+
*
18+
* @author Staartvin
19+
*
20+
*/
21+
public class PluginLibrary extends JavaPlugin {
22+
23+
private final List<Library> loadedLibraries = new ArrayList<Library>();
24+
private CustomStatsManager customStatsManager;
25+
26+
@Override
27+
public void onEnable() {
28+
29+
loadedLibraries.clear();
30+
31+
//this is a test
32+
// I'm just one below yours
33+
logMessage(ChatColor.GOLD + "***== Loading libraries ==***");
34+
logMessage(ChatColor.GOLD + "***== Loaded " + ChatColor.WHITE
35+
+ loadLibraries() + ChatColor.GOLD + " libraries! ==***");
36+
37+
if (this.isLibraryLoaded(Library.STATS)) {
38+
// Register custom stats so that Stats has special mobs and food eaten requirement.
39+
setCustomStatsManager(new CustomStatsManager(this));
40+
this.getCustomStatsManager().registerCustomStats();
41+
}
42+
43+
logMessage(ChatColor.GOLD + "Loaded libraries: "
44+
+ getLoadedLibrariesAsString());
45+
46+
logMessage(ChatColor.GREEN
47+
+ "*** Ready for plugins to send/retrieve data. ***");
48+
49+
logMessage(this.getDescription().getFullName() + " is now enabled!");
50+
}
51+
52+
@Override
53+
public void onDisable() {
54+
55+
loadedLibraries.clear();
56+
57+
logMessage(this.getDescription().getFullName() + " is now disabled!");
58+
}
59+
60+
/**
61+
* Load all libraries, this will be done automatically by the plugin.
62+
*
63+
* @return how many libraries were loaded.
64+
*/
65+
public int loadLibraries() {
66+
int count = 0;
67+
68+
for (Library l : Library.values()) {
69+
if (l.getHook().isAvailable()) {
70+
71+
// One more library loaded.
72+
if (l.getHook().hook()) {
73+
loadedLibraries.add(l);
74+
count++;
75+
}
76+
77+
}
78+
}
79+
80+
return count;
81+
}
82+
83+
public void logMessage(String message) {
84+
// This makes sure it can support colours.
85+
this.getServer().getConsoleSender()
86+
.sendMessage(ChatColor.GRAY + "[PluginLibrary] " + message);
87+
}
88+
89+
/**
90+
* Get a list of all loaded libraries. <br>
91+
* This list is unmodifiable and when you try to alter it, it will give an
92+
* {@link UnsupportedOperationException}.
93+
*
94+
* @return a list of loaded libraries.
95+
*/
96+
public List<Library> getLoadedLibraries() {
97+
return Collections.unmodifiableList(loadedLibraries);
98+
}
99+
100+
/**
101+
* Gets the library for a specific plugin. <br>
102+
* Will throw a {@link IllegalArgumentException} when there is no library
103+
* with the given name.
104+
*
105+
* @param pluginName Name of the plugin. Case-insensitive!
106+
* @return {@link me.staartvin.plugins.pluginlibrary.LibraryHook} class or
107+
* an error.
108+
*/
109+
public static LibraryHook getLibrary(String pluginName) {
110+
return Library.getEnum(pluginName).getHook();
111+
}
112+
113+
/**
114+
* @see #getLibrary(String)
115+
* <br>
116+
* Returns the same as {@link #getLibrary(String)}.
117+
* @param lib Library enum to get the library hook for.
118+
* @return {@link me.staartvin.plugins.pluginlibrary.LibraryHook} class or
119+
* an error.
120+
*/
121+
public static LibraryHook getLibrary(Library lib) {
122+
return lib.getHook();
123+
}
124+
125+
/**
126+
* Checks to see whether the library is loaded and thus ready for use.
127+
*
128+
* @param lib Library to check.
129+
* @return true if the library is loaded; false otherwise.
130+
*/
131+
public boolean isLibraryLoaded(Library lib) {
132+
return loadedLibraries.contains(lib);
133+
}
134+
135+
public CustomStatsManager getCustomStatsManager() {
136+
return customStatsManager;
137+
}
138+
139+
public void setCustomStatsManager(CustomStatsManager customStatsManager) {
140+
this.customStatsManager = customStatsManager;
141+
}
142+
143+
private String getLoadedLibrariesAsString() {
144+
StringBuilder builder = new StringBuilder("");
145+
146+
for (int i = 0, l = loadedLibraries.size(); i < l; i++) {
147+
if (i == 0) {
148+
builder.append(ChatColor.DARK_AQUA
149+
+ loadedLibraries.get(i).getPluginName() + ChatColor.RESET);
150+
} else if (i == (l - 1)) {
151+
builder.append(ChatColor.GRAY
152+
+ " and "
153+
+ (ChatColor.DARK_AQUA
154+
+ loadedLibraries.get(i).getPluginName() + ChatColor.RESET));
155+
} else {
156+
builder.append(ChatColor.GRAY
157+
+ ", "
158+
+ (ChatColor.DARK_AQUA
159+
+ loadedLibraries.get(i).getPluginName() + ChatColor.RESET));
160+
}
161+
}
162+
163+
return builder.toString();
164+
}
165+
}

0 commit comments

Comments
 (0)