Guest User

Untitled

a guest
Sep 3rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 KB | None | 0 0
  1. package com.gmail.haloinverse.DynamicMarket;
  2.  
  3.  
  4. import com.nijikokun.bukkit.Permissions.Permissions;
  5. import com.nijiko.coelho.iConomy.iConomy;
  6. //import com.haloinverse.AnyConomy.AnyConomy;
  7. import java.io.File;
  8. import java.util.Timer;
  9. import java.util.logging.Logger;
  10. //import org.bukkit.Server;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.event.Event;
  14. import org.bukkit.event.server.PluginEvent;
  15. import org.bukkit.event.server.ServerListener;
  16. import org.bukkit.plugin.Plugin;
  17. import org.bukkit.plugin.PluginDescriptionFile;
  18. //import org.bukkit.plugin.PluginLoader;
  19. import org.bukkit.plugin.PluginManager;
  20. import org.bukkit.plugin.java.JavaPlugin;
  21.  
  22. public class DynamicMarket extends JavaPlugin
  23. {
  24. public final Logger log = Logger.getLogger("Minecraft");
  25.  
  26. public String name; // = "SimpleMarket";
  27. public String codename = "arensirb";
  28. public String version; // = "0.4a";
  29.  
  30. public iListen playerListener = new iListen(this);
  31. //public DMServerListener serverListener = new DMServerListener(this);
  32. public static Permissions Permissions;
  33. public static iProperty Settings;
  34. public static String directory; // = "DynamicMarket" + File.separator;
  35. public String shop_tag = "{BKT}[{}Shop{BKT}]{} ";
  36. protected String currency;// = "Coin";
  37. protected int max_per_purchase = 64;
  38. protected int max_per_sale = 64;
  39. public String defaultShopAccount = "";
  40. public boolean defaultShopAccountFree = true;
  41.  
  42. protected String database_type = "sqlite";
  43. protected static String sqlite = "jdbc:sqlite:" + directory + "shop.db";
  44. protected static String mysql = "jdbc:mysql://localhost:3306/minecraft";
  45. protected static String mysql_user = "root";
  46. protected static String mysql_pass = "pass";
  47. protected static String mysql_dbEngine = "MyISAM";
  48. protected static Timer timer = null;
  49. protected static String csvFileName;
  50. protected static String csvFilePath;
  51. protected iConomy iC = null;
  52. //protected AnyConomy anyConomy = null;
  53. protected boolean econLoaded = false;
  54. protected EconType econType = EconType.NONE;
  55. protected Items items;
  56. protected String itemsPath = "";
  57. protected DatabaseMarket db = null;
  58. protected boolean wrapperMode = false;
  59. protected boolean wrapperPermissions = false;
  60. protected boolean simplePermissions = false;
  61. protected PermissionInterface permissionWrapper = null;
  62. protected TransactionLogger transLog = null;
  63. protected String transLogFile = "transactions.log";
  64. protected boolean transLogAutoFlush = true;
  65. private MyServerListener myServerListener = new MyServerListener(this);
  66. //public static YamlPropFile yamlPropTest;
  67.  
  68. private class MyServerListener extends ServerListener {
  69.  
  70. private DynamicMarket plugin;
  71. public MyServerListener(DynamicMarket thisPlugin)
  72. {
  73. this.plugin = thisPlugin;
  74. }
  75.  
  76. @Override
  77. public void onPluginEnabled(PluginEvent event)
  78. {
  79. // This is called for plugins enabled AFTER this one.
  80. String thisPluginName = event.getPlugin().getDescription().getName();
  81. if(thisPluginName.equals("iConomy"))
  82. {
  83. plugin.connectEconomy(event.getPlugin());
  84. }
  85. }
  86. }
  87.  
  88. public void onDisable() {
  89. log.info(Messaging.bracketize(name) + " version " + Messaging.bracketize(version) + " (" + codename + ") disabled");
  90. }
  91.  
  92. @Override
  93. public void onEnable() {
  94. PluginDescriptionFile desc = getDescription();
  95. getDataFolder().mkdir();
  96.  
  97. name = desc.getName();
  98. version = desc.getVersion();
  99.  
  100. directory = getDataFolder() + File.separator;
  101. sqlite = "jdbc:sqlite:" + directory + "shop.db";
  102.  
  103. setup();
  104. System.out.println("Setup() OK!");
  105. //setupItems(); //CHANGED: Initialisation moved to Items constructor.
  106. setupEconomy();
  107. System.out.println("SetupEconomy OK!");
  108. setupPermissions();
  109. registerEvents();
  110. log.info(Messaging.bracketize(name) + " version " + Messaging.bracketize(version) + " (" + codename + ") enabled");
  111. }
  112.  
  113. private void registerEvents()
  114. {
  115. PluginManager thisPluginManager = getServer().getPluginManager();
  116. thisPluginManager.registerEvent(Event.Type.PLUGIN_ENABLE, this.myServerListener, Event.Priority.Monitor, this);
  117. }
  118.  
  119. @Override
  120. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
  121. {
  122. if (!wrapperMode)
  123. {
  124. boolean thisReturn;
  125. thisReturn = this.playerListener.parseCommand(sender, cmd.getName(), args, "", defaultShopAccount, defaultShopAccountFree);
  126. return thisReturn;
  127. }
  128. else
  129. return true;
  130. }
  131.  
  132. public boolean wrapperCommand(CommandSender sender, String cmd, String[] args, String shopLabel, String accountName, boolean freeAccount)
  133. {
  134. return this.playerListener.parseCommand(sender, cmd, args, (shopLabel == null ? "" : shopLabel), accountName, freeAccount);
  135. }
  136.  
  137. public boolean wrapperCommand(CommandSender sender, String cmd, String[] args, String shopLabel)
  138. {
  139. return wrapperCommand(sender, cmd, args, (shopLabel == null ? "" : shopLabel), defaultShopAccount, defaultShopAccountFree);
  140. }
  141.  
  142. public boolean wrapperCommand(CommandSender sender, String cmd, String[] args)
  143. {
  144. return wrapperCommand(sender, cmd, args, "");
  145. }
  146.  
  147.  
  148. public void setup()
  149. {
  150. Settings = new iProperty(getDataFolder() + File.separator + name + ".settings");
  151.  
  152. //ItemsFile = new iProperty("items.db");
  153. itemsPath = Settings.getString("items-db-path", getDataFolder() + File.separator);
  154. items = new Items(itemsPath + "items.db", this);
  155.  
  156. shop_tag = Settings.getString("shop-tag", shop_tag);
  157. max_per_purchase = Settings.getInt("max-items-per-purchase", 64);
  158. max_per_sale = Settings.getInt("max-items-per-sale", 64);
  159.  
  160. this.database_type = Settings.getString("database-type", "sqlite");
  161.  
  162. mysql = Settings.getString("mysql-db", mysql);
  163. mysql_user = Settings.getString("mysql-user", mysql_user);
  164. mysql_pass = Settings.getString("mysql-pass", mysql_pass);
  165. mysql_dbEngine = Settings.getString("mysql-dbengine", mysql_dbEngine);
  166.  
  167. if (this.database_type.equalsIgnoreCase("mysql"))
  168. db = new DatabaseMarket(DatabaseMarket.Type.MYSQL, "Market", items, mysql_dbEngine, this);
  169. else
  170. db = new DatabaseMarket(DatabaseMarket.Type.SQLITE, "Market", items, "", this);
  171.  
  172. csvFileName = Settings.getString("csv-file", "shopDB.csv");
  173. csvFilePath = Settings.getString("csv-file-path", getDataFolder() + File.separator);
  174. wrapperMode = Settings.getBoolean("wrapper-mode", false);
  175. simplePermissions = Settings.getBoolean("simple-permissions", false);
  176. wrapperPermissions = Settings.getBoolean("wrapper-permissions", false);
  177.  
  178. Messaging.colNormal = "&" + Settings.getString("text-colour-normal", "e");
  179. Messaging.colCmd = "&" + Settings.getString("text-colour-command", "f");
  180. Messaging.colBracket = "&" + Settings.getString("text-colour-bracket", "d");
  181. Messaging.colParam = "&" + Settings.getString("text-colour-param", "b");
  182. Messaging.colError = "&" + Settings.getString("text-colour-error", "c");
  183.  
  184. defaultShopAccount = Settings.getString("default-shop-account", "");
  185. defaultShopAccountFree = Settings.getBoolean("default-shop-account-free", defaultShopAccountFree);
  186.  
  187. transLogFile = Settings.getString("transaction-log-file", transLogFile);
  188. transLogAutoFlush = Settings.getBoolean("transaction-log-autoflush", transLogAutoFlush);
  189. if ((transLogFile != null) && (!transLogFile.isEmpty()))
  190. transLog = new TransactionLogger(this, getDataFolder() + File.separator + transLogFile, transLogAutoFlush);
  191. else
  192. transLog = new TransactionLogger(this, null, false);
  193.  
  194. String econTypeString = Settings.getString("economy-plugin", "iconomy4");
  195. if (econTypeString.equalsIgnoreCase("iconomy3"))
  196. econType = EconType.ICONOMY3;
  197. else if (econTypeString.equalsIgnoreCase("iconomy4"))
  198. econType = EconType.ICONOMY4;
  199. else if (econTypeString.equalsIgnoreCase("anyconomy"))
  200. econType = EconType.ANYCONOMY;
  201. else
  202. {
  203. log.severe(Messaging.bracketize(name) + " Invalid economy setting for 'economy-plugin='.");
  204. econType = EconType.NONE;
  205. }
  206.  
  207. //yamlPropTest = new YamlPropFile(getDataFolder() + File.separator + "SimpleMarket.yml");
  208. //yamlPropTest.load();
  209. }
  210.  
  211. public void setupPermissions()
  212. {
  213. if (simplePermissions)
  214. {
  215. Permissions = null;
  216. log.info(Messaging.bracketize(name) + " Simple permission system active.");
  217. }
  218. else if (wrapperPermissions)
  219. log.info(Messaging.bracketize(name) + " Permissions will be delegated to wrapper plugin.");
  220. else
  221. {
  222. Plugin test = getServer().getPluginManager().getPlugin("Permissions");
  223.  
  224. if (Permissions == null)
  225. if (test != null) {
  226. Permissions = (Permissions)test;
  227. log.info(Messaging.bracketize(name) + " Standard Permission plugin enabled.");
  228. } else {
  229. log.info(Messaging.bracketize(name) + " Permission system not enabled. Disabling plugin.");
  230. getServer().getPluginManager().disablePlugin(this);
  231. }
  232. }
  233. }
  234.  
  235. public void setupEconomy()
  236. {
  237. // Called with iConomy 2.1(Cookies wrapper).
  238. // This catches plugins enabled BEFORE this plugin.
  239. Plugin test = getServer().getPluginManager().getPlugin("iConomy");
  240. if (test != null) {
  241. connectEconomy(test);
  242. }
  243.  
  244. test = getServer().getPluginManager().getPlugin("AnyConomy");
  245. if (test != null) {
  246. connectEconomy(test);
  247. }
  248.  
  249. }
  250.  
  251. public void connectEconomy(Plugin thisPlugin)
  252. {
  253.  
  254. System.out.println("Econ is: " + econType);
  255. if(econType == EconType.ICONOMY3 || econType == EconType.ICONOMY4)
  256. {
  257. System.out.println("It got in! YEY ;D");
  258. if(thisPlugin instanceof iConomy)
  259. System.out.println("Yes, it is an instance of iConomy");
  260. connectToiConomy((iConomy)thisPlugin);
  261. }
  262.  
  263.  
  264. }
  265.  
  266. public void connectToiConomy(iConomy thisPlugin)
  267. {
  268. iC = thisPlugin;
  269. try {
  270. currency = iConomy.getBank().getCurrency();
  271. } catch (Exception e) {
  272. System.out.println("EXCEPTION!! " + e);
  273. e.printStackTrace();
  274. }
  275. System.out.println("Got this far yeah!");
  276. econLoaded = true;
  277. log.info(Messaging.bracketize(name) + " iConomy connected.");
  278. }
  279.  
  280. public static enum EconType
  281. {
  282. NONE, ICONOMY2, ICONOMY3, ICONOMY4, ANYCONOMY;
  283. }
  284. }
Add Comment
Please, Sign In to add comment