add @Overraide flags...

Signed-off-by: j502647092 <jtb1@163.com>
master
j502647092 2015-08-01 23:31:38 +08:00
parent 0cbb61647f
commit 5b32f28d08
2 changed files with 58 additions and 57 deletions

View File

@ -24,18 +24,18 @@ public class LuckLottery extends JavaPlugin {
public static Chat chat = null; public static Chat chat = null;
public static LuckLottery plugin; public static LuckLottery plugin;
public void onLoad() { @Override
plugin = this; public void onDisable() {
Config.load(this, "1.1"); this.getLogger().info("保存彩票数据中...");
OfflineDate.load(this); LotteryUtils.saveLottery();
PlayerDate.load(this); this.getLogger().info("保存玩家数据中...");
ChatUtils.setPluginname(Config.getMessage("pluginname")); PlayerDate.save();
LotteryUtils.setNumbersame(Config.getInstance().getBoolean("numbersame"));
} }
@Override
public void onEnable() { public void onEnable() {
PluginManager pm = this.getServer().getPluginManager(); PluginManager pm = this.getServer().getPluginManager();
if (!pm.getPlugin("Vault").isEnabled()){ if (!pm.getPlugin("Vault").isEnabled()) {
this.getLogger().warning("未找到前置插件Vault 关闭插件..."); this.getLogger().warning("未找到前置插件Vault 关闭插件...");
this.getServer().getPluginManager().disablePlugin(this); this.getServer().getPluginManager().disablePlugin(this);
return; return;
@ -49,33 +49,25 @@ public class LuckLottery extends JavaPlugin {
return; return;
} }
this.getServer().getScheduler() this.getServer().getScheduler()
.runTaskTimer(plugin, new LotteryReward(true), 10, 10 * 60 * 20); .runTaskTimer(plugin, new LotteryReward(true), 10, 10 * 60 * 20);
this.getLogger().info("彩票系统已开启..."); this.getLogger().info("彩票系统已开启...");
pm.registerEvents(new PlayerListen(), this); pm.registerEvents(new PlayerListen(), this);
getCommand("ll").setExecutor(new LuckLotteryCommand(this)); getCommand("ll").setExecutor(new LuckLotteryCommand(this));
} }
public void onDisable() { @Override
this.getLogger().info("保存彩票数据中..."); public void onLoad() {
LotteryUtils.saveLottery(); plugin = this;
this.getLogger().info("保存玩家数据中..."); Config.load(this, "1.1");
PlayerDate.save(); OfflineDate.load(this);
} PlayerDate.load(this);
ChatUtils.setPluginname(Config.getMessage("pluginname"));
public boolean setupPermissions() { LotteryUtils.setNumbersame(Config.getInstance().getBoolean("numbersame"));
RegisteredServiceProvider<Permission> permissionProvider = getServer()
.getServicesManager().getRegistration(
net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
} }
public boolean setupChat() { public boolean setupChat() {
RegisteredServiceProvider<Chat> chatProvider = getServer() RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager()
.getServicesManager().getRegistration( .getRegistration(net.milkbowl.vault.chat.Chat.class);
net.milkbowl.vault.chat.Chat.class);
if (chatProvider != null) { if (chatProvider != null) {
chat = chatProvider.getProvider(); chat = chatProvider.getProvider();
} }
@ -84,13 +76,21 @@ public class LuckLottery extends JavaPlugin {
} }
public boolean setupEconomy() { public boolean setupEconomy() {
RegisteredServiceProvider<Economy> economyProvider = getServer() RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager()
.getServicesManager().getRegistration( .getRegistration(net.milkbowl.vault.economy.Economy.class);
net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) { if (economyProvider != null) {
economy = economyProvider.getProvider(); economy = economyProvider.getProvider();
} }
return (economy != null); return (economy != null);
} }
public boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
.getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
} }

View File

@ -25,16 +25,11 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files; import com.google.common.io.Files;
/** /**
* An implementation of {@link Configuration} which saves all files in Yaml. * An implementation of {@link Configuration} which saves all files in Yaml. Note that this
* Note that this implementation is not synchronized. * implementation is not synchronized.
*/ */
public class FileConfig extends YamlConfiguration { public class FileConfig extends YamlConfiguration {
protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(),
yamlRepresenter, yamlOptions);
public static FileConfig init(File file) { public static FileConfig init(File file) {
return FileConfig.loadConfiguration(file); return FileConfig.loadConfiguration(file);
} }
@ -53,6 +48,32 @@ public class FileConfig extends YamlConfiguration {
return config; return config;
} }
protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
@Override
public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
Validate.notNull(file, "File cannot be null");
final FileInputStream stream = new FileInputStream(file);
load(new InputStreamReader(stream, Charsets.UTF_8));
}
@Override
public void save(File file) throws IOException {
Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file);
String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
try {
writer.write(data);
} finally {
writer.close();
}
}
@Override @Override
public String saveToString() { public String saveToString() {
yamlOptions.setIndent(options().indent()); yamlOptions.setIndent(options().indent());
@ -65,24 +86,4 @@ public class FileConfig extends YamlConfiguration {
} }
return header + dump; return header + dump;
} }
public void load(File file) throws FileNotFoundException, IOException,
InvalidConfigurationException {
Validate.notNull(file, "File cannot be null");
final FileInputStream stream = new FileInputStream(file);
load(new InputStreamReader(stream, Charsets.UTF_8));
}
public void save(File file) throws IOException {
Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file);
String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file),
Charsets.UTF_8);
try {
writer.write(data);
} finally {
writer.close();
}
}
} }