ChestShop-3/com/Acrobot/ChestShop/ChestShop.java

142 lines
4.7 KiB
Java
Raw Normal View History

2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.Commands.ItemInfo;
import com.Acrobot.ChestShop.Commands.Options;
import com.Acrobot.ChestShop.Commands.Version;
2011-06-09 22:54:01 +02:00
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
2011-06-09 22:54:01 +02:00
import com.Acrobot.ChestShop.DB.Generator;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction;
2011-05-15 19:33:03 +02:00
import com.Acrobot.ChestShop.Listeners.*;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.Logging.FileWriterQueue;
import com.Acrobot.ChestShop.Logging.Logging;
import com.avaje.ebean.EbeanServer;
import org.bukkit.Server;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
2011-05-29 13:25:25 +02:00
import javax.persistence.PersistenceException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Main file of the plugin
2011-05-29 13:25:25 +02:00
*
* @author Acrobot
*/
2011-05-15 19:33:03 +02:00
public class ChestShop extends JavaPlugin {
private final pluginEnable pluginEnable = new pluginEnable();
private final blockBreak blockBreak = new blockBreak();
private final blockPlace blockPlace = new blockPlace();
private final signChange signChange = new signChange();
private final pluginDisable pluginDisable = new pluginDisable();
private final playerInteract playerInteract = new playerInteract();
2011-06-09 22:54:01 +02:00
public static File folder;
public static EbeanServer db;
2011-05-29 13:25:25 +02:00
private static PluginDescriptionFile desc;
private static Server server;
public void onEnable() {
PluginManager pm = getServer().getPluginManager();
2011-05-29 13:25:25 +02:00
//Register our events
pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, blockPlace, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.SIGN_CHANGE, signChange, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerInteract, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginEnable, Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, pluginDisable, Event.Priority.Monitor, this);
desc = this.getDescription();
server = getServer();
2011-05-29 13:25:25 +02:00
//Set up our config file!
Config.setUp();
2011-05-29 13:25:25 +02:00
2011-06-09 22:54:01 +02:00
//Yep, set up our folder!
folder = getDataFolder();
2011-05-29 13:25:25 +02:00
//Now set up our database for storing transactions!
setupDBfile();
if (Config.getBoolean(Property.USE_DATABASE)) {
2011-05-29 13:25:25 +02:00
setupDB();
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);
2011-06-09 22:54:01 +02:00
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) {
2011-06-09 22:54:01 +02:00
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, 300L);
}
db = getDatabase();
2011-05-29 13:25:25 +02:00
}
//Now set up our logging to file!
if (Config.getBoolean(Property.LOG_TO_FILE)) {
2011-05-29 13:25:25 +02:00
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new FileWriterQueue(), 201L, 201L);
}
2011-06-09 22:54:01 +02:00
2011-05-29 13:25:25 +02:00
//Register our commands!
getCommand("iteminfo").setExecutor(new ItemInfo());
getCommand("chestOptions").setExecutor(new Options());
getCommand("csVersion").setExecutor(new Version());
System.out.println('[' + desc.getName() + "] version " + desc.getVersion() + " initialized!");
}
public void onDisable() {
System.out.println('[' + desc.getName() + "] version " + desc.getVersion() + " shutting down!");
}
2011-05-29 13:25:25 +02:00
///////////////////// DATABASE STUFF ////////////////////////////////
private void setupDB() {
try {
getDatabase().find(Transaction.class).findRowCount();
} catch (PersistenceException pe) {
Logging.log("Installing database for " + getPluginName());
installDDL();
}
}
2011-05-29 13:25:25 +02:00
private static void setupDBfile() {
File file = new File("ebean.properties");
2011-06-09 22:54:01 +02:00
if (!file.exists()) {
try {
2011-05-29 13:25:25 +02:00
file.createNewFile();
2011-06-09 22:54:01 +02:00
} catch (Exception e) {
2011-05-29 13:25:25 +02:00
Logging.log("Failed to create ebean.properties file!");
}
}
2011-05-29 13:25:25 +02:00
}
2011-05-29 13:25:25 +02:00
@Override
public List<Class<?>> getDatabaseClasses() {
List<Class<?>> list = new ArrayList<Class<?>>();
list.add(Transaction.class);
return list;
}
///////////////////////////////////////////////////////////////////////////////
2011-05-29 13:25:25 +02:00
public static Server getBukkitServer() {
return server;
}
2011-05-29 13:25:25 +02:00
public static String getVersion() {
return desc.getVersion();
}
public static String getPluginName() {
return desc.getName();
}
2011-06-09 22:54:01 +02:00
public static EbeanServer getDB() {
return db;
}
}