2011-05-15 19:33:03 +02:00
|
|
|
package com.Acrobot.ChestShop;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Commands.ItemInfo;
|
|
|
|
import com.Acrobot.ChestShop.Commands.Version;
|
2011-06-09 22:54:01 +02:00
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
2011-09-06 19:01:57 +02:00
|
|
|
import com.Acrobot.ChestShop.Config.ConfigObject;
|
2011-06-11 17:36:55 +02:00
|
|
|
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;
|
2012-03-17 15:00:25 +01:00
|
|
|
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
|
|
|
import com.Acrobot.ChestShop.Utils.uNumber;
|
2011-05-29 13:25:25 +02:00
|
|
|
import com.avaje.ebean.EbeanServer;
|
2011-07-23 21:00:47 +02:00
|
|
|
import com.lennardf1989.bukkitex.Database;
|
2012-03-17 15:00:25 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.Server;
|
2012-03-01 22:03:59 +01:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2011-05-15 18:16:25 +02:00
|
|
|
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 java.io.File;
|
2011-07-24 16:56:18 +02:00
|
|
|
import java.util.ArrayList;
|
2011-05-29 13:25:25 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
/**
|
|
|
|
* Main file of the plugin
|
2011-05-29 13:25:25 +02:00
|
|
|
*
|
2011-05-15 18:16:25 +02:00
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2011-05-15 19:33:03 +02:00
|
|
|
public class ChestShop extends JavaPlugin {
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-09-06 19:01:57 +02:00
|
|
|
public static File folder = new File("plugins/ChestShop");
|
2011-09-01 18:59:15 +02:00
|
|
|
public static final String chatPrefix = "[ChestShop] ";
|
2011-07-23 21:00:47 +02:00
|
|
|
private static EbeanServer DB;
|
2011-06-11 17:36:55 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
private static PluginDescriptionFile description;
|
2011-05-15 18:16:25 +02:00
|
|
|
private static Server server;
|
|
|
|
|
2011-09-06 19:01:57 +02:00
|
|
|
public static PluginManager pm;
|
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
public void onEnable() {
|
2011-09-06 19:01:57 +02:00
|
|
|
pm = getServer().getPluginManager();
|
|
|
|
folder = getDataFolder();
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
//Set up our config file!
|
2011-09-06 19:01:57 +02:00
|
|
|
Config.setup(new ConfigObject());
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
//Register our events
|
2011-09-06 19:01:57 +02:00
|
|
|
registerEvents();
|
2011-08-13 12:08:34 +02:00
|
|
|
|
2011-08-26 23:12:32 +02:00
|
|
|
description = this.getDescription(); //Description of the plugin
|
|
|
|
server = getServer(); //Setting out server variable
|
|
|
|
|
2011-09-06 19:01:57 +02:00
|
|
|
pluginEnable.initializePlugins();
|
2011-07-05 19:08:55 +02:00
|
|
|
|
2012-03-06 19:41:14 +01:00
|
|
|
warnAboutSpawnProtection();
|
2012-03-17 15:00:25 +01:00
|
|
|
warnAboutOldBukkit();
|
2012-03-06 19:41:14 +01:00
|
|
|
|
2011-09-06 19:01:57 +02:00
|
|
|
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) setupDB();
|
|
|
|
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) scheduleTask(new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
|
|
|
|
if (Config.getBoolean(Property.LOG_TO_FILE)) scheduleTask(new FileWriterQueue(), 201L, 201L);
|
2011-12-16 17:20:09 +01:00
|
|
|
playerInteract.interval = Config.getInteger(Property.SHOP_INTERACTION_INTERVAL);
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
//Register our commands!
|
|
|
|
getCommand("iteminfo").setExecutor(new ItemInfo());
|
|
|
|
getCommand("csVersion").setExecutor(new Version());
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2012-01-25 16:32:34 +01:00
|
|
|
//Start the statistics pinger
|
|
|
|
startStatistics();
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable() {
|
2012-03-01 22:03:59 +01:00
|
|
|
getServer().getScheduler().cancelTasks(this);
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2012-01-25 16:32:34 +01:00
|
|
|
////////////////// REGISTER EVENTS, SCHEDULER & STATS ///////////////////////////
|
2011-09-06 19:01:57 +02:00
|
|
|
private void registerEvents() {
|
2012-02-16 19:09:37 +01:00
|
|
|
PluginManager pm = getServer().getPluginManager();
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2012-02-16 19:09:37 +01:00
|
|
|
pm.registerEvents(new blockBreak(), this);
|
|
|
|
pm.registerEvents(new blockPlace(), this);
|
|
|
|
pm.registerEvents(new signChange(), this);
|
|
|
|
pm.registerEvents(new playerInteract(), this);
|
|
|
|
pm.registerEvents(new entityExplode(), this);
|
2011-09-06 19:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void scheduleTask(Runnable runnable, long startTime, long repetetionTime) {
|
|
|
|
server.getScheduler().scheduleAsyncRepeatingTask(this, runnable, startTime, repetetionTime);
|
|
|
|
}
|
|
|
|
|
2012-03-17 15:00:25 +01:00
|
|
|
private void startStatistics() {
|
|
|
|
try {
|
2012-04-16 16:34:00 +02:00
|
|
|
new Metrics(this).start();
|
2012-03-17 15:00:25 +01:00
|
|
|
} catch (Exception ex) {
|
2012-03-06 19:41:14 +01:00
|
|
|
System.err.println(chatPrefix + "There was an error while submitting statistics.");
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 15:00:25 +01:00
|
|
|
///////////////////// WARN ///////////////////////////
|
2012-03-06 19:41:14 +01:00
|
|
|
private static void warnAboutSpawnProtection() {
|
|
|
|
if (getBukkitConfig().getInt("settings.spawn-radius") > 0)
|
|
|
|
System.err.println(ChestShop.chatPrefix + "WARNING! Your spawn-radius in bukkit.yml isn't set to 0! " +
|
|
|
|
"You won't be able to sell to shops built near spawn!");
|
|
|
|
}
|
|
|
|
|
2012-03-17 15:00:25 +01:00
|
|
|
private static void warnAboutOldBukkit() {
|
|
|
|
String split[] = Bukkit.getBukkitVersion().split("-R");
|
|
|
|
if (split[0].equals("1.1") && split.length > 1 && uNumber.isInteger(split[1]) && (Integer.parseInt(split[1])) < 7) {
|
|
|
|
System.err.println(ChestShop.chatPrefix + "Your CraftBukkit version is outdated! Use at least 1.1-R7 or 1.2.3-R0!");
|
|
|
|
ShopManagement.useOldChest = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
///////////////////// DATABASE STUFF ////////////////////////////////
|
2012-03-01 22:03:59 +01:00
|
|
|
private static YamlConfiguration getBukkitConfig() {
|
|
|
|
return YamlConfiguration.loadConfiguration(new File("bukkit.yml"));
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-07-24 16:56:18 +02:00
|
|
|
private static Database database;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
private void setupDB() {
|
|
|
|
database = new Database(this) {
|
|
|
|
protected java.util.List<Class<?>> getDatabaseClasses() {
|
2011-07-24 16:56:18 +02:00
|
|
|
List<Class<?>> list = new ArrayList<Class<?>>();
|
2011-07-23 21:00:47 +02:00
|
|
|
list.add(Transaction.class);
|
|
|
|
return list;
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
2011-07-23 21:00:47 +02:00
|
|
|
};
|
|
|
|
|
2012-03-01 22:03:59 +01:00
|
|
|
YamlConfiguration config = getBukkitConfig();
|
2011-07-23 21:00:47 +02:00
|
|
|
|
|
|
|
database.initializeDatabase(
|
|
|
|
config.getString("database.driver"),
|
|
|
|
config.getString("database.url"),
|
|
|
|
config.getString("database.username"),
|
|
|
|
config.getString("database.password"),
|
2011-09-22 15:56:06 +02:00
|
|
|
config.getString("database.isolation")
|
2011-07-23 21:00:47 +02:00
|
|
|
);
|
2011-07-24 16:56:18 +02:00
|
|
|
|
|
|
|
DB = database.getDatabase();
|
2011-09-06 19:01:57 +02:00
|
|
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
@Override
|
2011-07-23 21:00:47 +02:00
|
|
|
public EbeanServer getDatabase() {
|
|
|
|
return database.getDatabase();
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static Server getBukkitServer() {
|
|
|
|
return server;
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static String getVersion() {
|
2011-07-23 21:00:47 +02:00
|
|
|
return description.getVersion();
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPluginName() {
|
2011-07-23 21:00:47 +02:00
|
|
|
return description.getName();
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
|
|
|
|
2011-06-09 22:54:01 +02:00
|
|
|
public static EbeanServer getDB() {
|
2011-07-23 21:00:47 +02:00
|
|
|
return DB;
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2011-09-06 19:01:57 +02:00
|
|
|
|
2012-03-01 22:03:59 +01:00
|
|
|
public static List getDependencies() {
|
|
|
|
return (List) description.getSoftDepend();
|
2011-09-06 19:01:57 +02:00
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|