Files
543
EchantedMC - Copy
Code
28 3,440
543/src/main/java/com/catalyst/smp/CatalystSMP.java
package com.catalyst.smp;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class CatalystSMP extends JavaPlugin {
private CatalystItems items;
private CatalystPoints points;
private CatalystBosses bosses;
private CatalystManager catalysts;
private CombatEffects effects;
private TrustManager trusts;
private CatalystAuditLog auditLog;
private CatalystListener listener;
@Override
public void onEnable() {
saveDefaultConfig();
this.items = new CatalystItems(this);
this.items.registerRecipes();
this.auditLog = new CatalystAuditLog(this);
this.points = new CatalystPoints(this, auditLog);
this.effects = new CombatEffects();
this.trusts = new TrustManager(this, auditLog);
this.catalysts = new CatalystManager(this, items, effects, auditLog);
this.bosses = new CatalystBosses(this, items, effects, auditLog);
this.listener = new CatalystListener(this, items, points, bosses, catalysts, effects, trusts, auditLog);
Bukkit.getPluginManager().registerEvents(listener, this);
BossCommand bossCommand = new BossCommand(bosses, auditLog);
getCommand("boss").setExecutor(bossCommand);
getCommand("boss").setTabCompleter(bossCommand);
CatalystCommand catalystCommand = new CatalystCommand(items, points, catalysts, auditLog);
getCommand("catalyst").setExecutor(catalystCommand);
getCommand("catalyst").setTabCompleter(catalystCommand);
TrustCommand trustCommand = new TrustCommand(trusts, auditLog);
getCommand("trust").setExecutor(trustCommand);
getCommand("trust").setTabCompleter(trustCommand);
listener.startPassiveTask();
auditLog.log("PLUGIN enabled");
}
@Override
public void onDisable() {
if (auditLog != null) {
auditLog.log("PLUGIN disabled");
}
if (points != null) {
points.save();
}
if (catalysts != null) {
catalysts.save();
}
if (bosses != null) {
bosses.shutdown();
}
}
public void sendResourcePack(Player player) {
if (!getConfig().getBoolean("resource-pack.enabled", false)) {
return;
}
String url = getConfig().getString("resource-pack.url", "").trim();
if (url.isEmpty()) {
return;
}
String sha1 = getConfig().getString("resource-pack.sha1", "").trim();
byte[] hash = sha1.isEmpty() ? null : decodeSha1(sha1);
String prompt = getConfig().getString("resource-pack.prompt", "Download the CatalystSMP resource pack?");
boolean required = getConfig().getBoolean("resource-pack.required", false);
player.setResourcePack(url, hash, prompt, required);
}
private byte[] decodeSha1(String value) {
if (!value.matches("(?i)[0-9a-f]{40}")) {
getLogger().warning("resource-pack.sha1 must be exactly 40 hexadecimal characters; ignoring it.");
return null;
}
byte[] hash = new byte[20];
for (int i = 0; i < hash.length; i++) {
hash[i] = (byte) Integer.parseInt(value.substring(i * 2, i * 2 + 2), 16);
}
return hash;
}
}