Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added GUI. But there some bugs.

Fixed Bug at Update.
  • Loading branch information...
commit 19d4f5131eaa192e801dbcdaf1bac91614139c3a 1 parent 38454f8
ibhh authored
162 src/Test
... ... @@ -0,0 +1,162 @@
  1 +
  2 + /**
  3 + * Called by onCommand and selllevel, sells XP.
  4 + *
  5 + * @param sender, amount, moneyactive = true if you want that player have to buy XP, false if there is an info what that would cost.
  6 + * @return true if no error occurred.
  7 + */
  8 + public int sell(CommandSender sender, int sellamount, boolean moneyactive, String von)
  9 + {
  10 + Player player = (Player) sender;
  11 + if (sellamount == 0)
  12 + {
  13 + SubstractedXP = 0;
  14 + return SubstractedXP;
  15 + }
  16 + if(player.getLevel() + player.getExp() <= 0.14)
  17 + {
  18 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + (getConfig().getString("command.error.notenoughxp." + getConfig().getString("language"))));
  19 + SubstractedXP = 0;
  20 + return SubstractedXP;
  21 + }
  22 + else
  23 + {
  24 + try
  25 + {
  26 + /** Noch nicht von Bukkit implementiert!
  27 + if(player.getTotalExperience() >= sellamount)
  28 + {
  29 + getmoney = (getConfig().getDouble("xptomoney"));
  30 + int neuXP = player.getTotalExperience() - sellamount;
  31 + player.setTotalExperience(neuXP);
  32 + addmoney156((getmoney * sellamount), player);
  33 + if(ActionxpShop.equalsIgnoreCase("sell"))
  34 + {
  35 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + (getConfig().getString("command.success." + ActionxpShop + "." + getConfig().getString("language") + ".1")) + " " + sellamount + " " + (getConfig().getString("command.success." + ActionxpShop + "." + getConfig().getString("language") + ".2")) + " " + addmoney + " " + (getConfig().getString("command.success." + ActionxpShop + "." + getConfig().getString("language") + ".3")));
  36 + }
  37 + }
  38 + else
  39 + {
  40 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + (getConfig().getString("command.error.notenoughxp." + getConfig().getString("language"))));
  41 + }
  42 + **/
  43 + if(SubstractedXP != 0)
  44 + {
  45 + SubstractedXP = 0;
  46 + }
  47 + getmoney = (getConfig().getDouble("xptomoney"));
  48 + while((SubstractedXP < sellamount) && (player.getLevel() + player.getExp() >= 0.14))
  49 + {
  50 + float endetest = 0;
  51 + float anfangtest = player.getExp();
  52 + int anfangleveltest = player.getLevel();
  53 + player.giveExp(1);
  54 + if(anfangleveltest < player.getLevel())
  55 + {
  56 + player.giveExp(-2);
  57 + }
  58 + else if(anfangleveltest == player.getLevel())
  59 + {
  60 + endetest = player.getExp();
  61 + }
  62 + float diff = endetest - anfangtest;
  63 +
  64 + if((diff*2) > player.getExp())
  65 + {
  66 + float set = (player.getExp() - (diff * 2));
  67 + player.setExp(set);
  68 + if(moneyactive == true)
  69 + {
  70 + addmoney156(getmoney, player);
  71 + }
  72 + SubstractedXP++;
  73 + }
  74 + else
  75 + {
  76 + try
  77 + {
  78 + if(player.getLevel() > 0)
  79 + {
  80 + SubstractedXP++;
  81 + int level = player.getLevel();
  82 + level = level - 1;
  83 + player.setLevel(level);
  84 + player.setExp( (float) 0.999999);
  85 + if(moneyactive == true)
  86 + {
  87 + addmoney156(getmoney, player);
  88 + }
  89 + }
  90 + else
  91 + {
  92 + break;
  93 + }
  94 + }
  95 + catch (Exception E)
  96 + {
  97 + E.printStackTrace();
  98 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + (getConfig().getString("command.error.else." + getConfig().getString("language"))));
  99 + }
  100 + }
  101 +
  102 + } //while(SubstractedXP > TOTALXP)
  103 + }
  104 + catch (NumberFormatException ex)
  105 + {
  106 + player.sendMessage("Invalid exp count: " + sellamount);
  107 + return SubstractedXP;
  108 + }
  109 + player.saveData();
  110 + double x = (getConfig().getDouble("xptomoney"))* SubstractedXP;
  111 + addmoney = Math.round(x);
  112 + if(ActionxpShop.equalsIgnoreCase("sell"))
  113 + {
  114 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + String.format((getConfig().getString("command.success." + "sell" + "." + getConfig().getString("language"))), SubstractedXP, addmoney));
  115 + }
  116 + else if (ActionxpShop.equalsIgnoreCase("info") && von.equals("selllevel") == false)
  117 + {
  118 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + String.format((getConfig().getString("info.prefix." + getConfig().getString("language"))) + " " + (getConfig().getString("command.success.sell." + getConfig().getString("language"))), SubstractedXP, addmoney));
  119 + }
  120 + }
  121 + return SubstractedXP;
  122 + }
  123 +
  124 +
  125 + /**
  126 + * Sells level from a player.
  127 + *
  128 + * @param sender, amount, moneyactive = true if you want that player have to buy XP, false if there is an info what that would cost.
  129 + * @return
  130 + */
  131 + public void selllevel(CommandSender sender, int levelamontsell, boolean moneyactive)
  132 + {
  133 + Player player = (Player) sender;
  134 + if(player.getLevel() + player.getExp() <= 0.20)
  135 + {
  136 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + (getConfig().getString("command.error.notenoughxp." + getConfig().getString("language"))));
  137 + return;
  138 + }
  139 + else
  140 + {
  141 + int levelsell = player.getLevel();
  142 + while ((player.getLevel() + player.getExp() >= 0.14) && ((levelsell - player.getLevel()) <= levelamontsell))
  143 + {
  144 + if(moneyactive == true)
  145 + {
  146 + rounds = rounds + sell(sender, 1, true, "selllevel");
  147 + }
  148 + else if(moneyactive == false)
  149 + {
  150 + rounds = rounds + sell(sender, 1, false, "selllevel");
  151 + }
  152 + }
  153 + if(ActionxpShop.equalsIgnoreCase("buylevel"))
  154 + {
  155 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + String.format((getConfig().getString("command.success." + "selllevel" + "." + getConfig().getString("language"))), rounds, ((getConfig().getDouble("xptomoney")) * rounds)));
  156 + }
  157 + else if (ActionxpShop.equalsIgnoreCase("info"))
  158 + {
  159 + player.sendMessage(ChatColor.GRAY + "[xpShop]" + ChatColor.RED + String.format((getConfig().getString("info.prefix." + getConfig().getString("language"))) + " " + (getConfig().getString("command.success.selllevel" + "." + getConfig().getString("language"))), rounds, ((getConfig().getDouble("xptomoney")) * rounds)));
  160 + }
  161 + }
  162 + }
43 src/config.yml
... ... @@ -1,17 +1,28 @@
1   -language: en
2   -autodownload: true
3   -SQL: false
4   -dbPath: localhost:3306/jail
5   -dbUser:
6   -dbPassword:
7   -permissions:
8   - error:
9   - de: Houston Wir haben ein Problem! Diesen Befehl darfst Du nicht verwenden!
10   - en: Houston we have a problem! You can't use this command!
11   - notfound:
12   - de: PermissionsEx plugin nicht gefunden!
13   - en: PermissionsEx not found!
14   -iConomy:
15   - error:
16   - de: Kein iConomy5 oder 6 oder Register gefunden!
  1 +language: en
  2 +autodownload: true
  3 +firstRun: true
  4 +debug: false
  5 +SQL: false
  6 +dbPath: localhost:3306/AuctionTrade
  7 +dbUser: nulll
  8 +dbPassword: nulll
  9 +command:
  10 + success:
  11 + create:
  12 + de: Auction erfolgreich mit Zeit %d und Item %s und Anfangspreis %f erstellt!
  13 + en: Auction successfully with time %d und Item %s und amount %f created!
  14 + error:
  15 + time0:
  16 + de: Die Dauer darf nicht 0 sein!
  17 + en: time couldnt be 0!
  18 +permissions:
  19 + error:
  20 + de: Houston Wir haben ein Problem! Diesen Befehl darfst Du nicht verwenden!
  21 + en: Houston we have a problem! You can't use this command!
  22 + notfound:
  23 + de: PermissionsEx plugin nicht gefunden!
  24 + en: PermissionsEx not found!
  25 +iConomy:
  26 + error:
  27 + de: Kein iConomy5 oder 6 oder Register gefunden!
17 28 en: No iConomy5 or 6 or Register found!
376 src/me/ibhh/AuctionTrade/AuctionTrade.java
... ... @@ -1,10 +1,8 @@
1 1 /**
2   - *
  2 + *
3 3 */
4 4 package me.ibhh.AuctionTrade;
5 5
6   -import java.sql.Date;
7   -
8 6 import org.bukkit.command.Command;
9 7 import org.bukkit.command.CommandSender;
10 8 import org.bukkit.entity.Player;
@@ -12,186 +10,220 @@
12 10
13 11 /**
14 12 * @author Simon
15   - *
  13 + *
16 14 */
17   -public class AuctionTrade extends JavaPlugin
18   -{
19   - public float Version = 0;
20   - private SQLConnectionHandler con;
21   - private PermissionsHandler Permission;
22   - private TimeHandler Time;
23   - private String action = "";
  15 +public class AuctionTrade extends JavaPlugin {
  16 +
  17 + public float Version = 0;
  18 + private SQLConnectionHandler con;
  19 + private PermissionsHandler Permission;
  20 + private TimeHandler Time;
  21 + private String action = "";
  22 + public boolean debug = false;
  23 + public static String Prefix = "ChatColor.DARK_BLUE + " + "[AuctionTrade] " + " + ChatColor.GOLD";
  24 + private String Time0msg;
  25 + private String Successcreate;
  26 + private PanelControl panel;
24 27
25   - /**
26   - * Called by Bukkit on stopping the server
27   - *
28   - * @param
29   - * @return
30   - */
31   - @Override
32   - public void onDisable() {
33   - con.CloseCon();
34   - System.out.println("[AuctionTrade] disabled!");
  28 + /**
  29 + * Called by Bukkit on stopping the server
  30 + *
  31 + * @param
  32 + * @return
  33 + */
  34 + @Override
  35 + public void onDisable() {
  36 + con.CloseCon();
  37 + System.out.println("[AuctionTrade] disabled!");
35 38
36   - }
37   -
38   - public boolean UpdateConfig() {
39   - try {
40   - getConfig().options().copyDefaults(true);
41   - saveConfig();
42   - reloadConfig();
43   - System.out.println("[AuctionTrade] Config file found!");
44   - return true;
45   - } catch (Exception e) {
46   - e.printStackTrace();
47   - return false;
48   - }
49   - }
  39 + }
50 40
51   - /**
52   - * Called by Bukkit on starting the server
53   - *
54   - * @param
55   - * @return
56   - */
57   - @Override
58   - public void onEnable()
59   - {
  41 + public boolean UpdateConfig() {
  42 + try {
  43 + getConfig().options().copyDefaults(true);
  44 + saveConfig();
  45 + reloadConfig();
  46 + System.out.println("[AuctionTrade] Config file found!");
  47 + return true;
  48 + } catch (Exception e) {
  49 + e.printStackTrace();
  50 + return false;
  51 + }
  52 + }
60 53
61   - UpdateConfig();
62   - con = new SQLConnectionHandler(this);
63   - Permission = new PermissionsHandler(this);
64   - Time = new TimeHandler();
65   - try {
66   - con.createConnection();
67   - } catch (Exception e) {
68   - e.printStackTrace();
69   - onDisable();
70   - return;
71   - }
72   - try {
73   - con.PrepareDB();
74   - } catch (Exception e) {
75   - e.printStackTrace();
76   - onDisable();
77   - return;
78   - }
79   - try {
80   - aktuelleVersion();
81   - } catch (Exception e) {
82   - e.printStackTrace();
83   - }
84   -
85   - System.out.println("[AuctionTrade] Version: " + Version
86   - + " successfully enabled!");
  54 + /**
  55 + * Called by Bukkit on starting the server
  56 + *
  57 + * @param
  58 + * @return
  59 + */
  60 + @Override
  61 + public void onEnable() {
  62 + UpdateConfig();
  63 + try {
  64 + getConfigStrings();
  65 + } catch (Exception e) {
  66 + Logger(e.getMessage(), "Error");
  67 + }
  68 + debug = getConfig().getBoolean("debug");
87 69
88   - String URL = "http://ibhh.de:80/aktuelleversionAuctionTrade.html";
89   - if ((Update.UpdateAvailable(URL, Version) == true)) {
90   - System.out.println("[AuctionTrade] New version: "
91   - + Update.getNewVersion(URL) + " found!");
92   - System.out
93   - .println("[AuctionTrade] ******************************************");
94   - System.out
95   - .println("[AuctionTrade] *********** Please update!!!! ************");
96   - System.out
97   - .println("[AuctionTrade] * http://ibhh.de/AuctionTrade.jar *");
98   - System.out
99   - .println("[AuctionTrade] ******************************************");
100   - if (getConfig().getBoolean("autodownload") == true) {
101   - try {
102   - String path = getDataFolder().toString() + "/Update/";
103   - Update.autoUpdate("http://ibhh.de/AuctionTrade.jar", path,
104   - "AuctionTrade.jar");
105   - } catch (Exception e) {
106   - System.out
107   - .println("[AuctionTrade] "
108   - + "Error on checking permissions with PermissionsEx!");
109   - e.printStackTrace();
110   - return;
111   - }
  70 + if (getConfig().getBoolean("firstRun")) {
  71 + panel = new PanelControl(this);
  72 + panel.setSize(400, 300);
  73 + panel.setLocation(200, 300);
  74 + panel.setVisible(true);
  75 + }
  76 + con = new SQLConnectionHandler(this);
  77 + Permission = new PermissionsHandler(this);
  78 + Time = new TimeHandler();
  79 + try {
  80 + con.createConnection();
  81 + } catch (Exception e) {
  82 + e.printStackTrace();
  83 + onDisable();
  84 + return;
  85 + }
  86 + try {
  87 + con.PrepareDB();
  88 + } catch (Exception e) {
  89 + e.printStackTrace();
  90 + onDisable();
  91 + return;
  92 + }
  93 + try {
  94 + aktuelleVersion();
  95 + } catch (Exception e) {
  96 + e.printStackTrace();
  97 + }
  98 + System.out.println("[AuctionTrade] Version: " + Version + " successfully enabled!");
  99 + String URL = "http://ibhh.de:80/aktuelleversionAuctionTrade.html";
  100 + if ((Update.UpdateAvailable(URL, Version) == true)) {
  101 + System.out.println("[AuctionTrade] New version: " + Update.getNewVersion(URL) + " found!");
  102 + System.out.println("[AuctionTrade] ******************************************");
  103 + System.out.println("[AuctionTrade] *********** Please update!!!! ************");
  104 + System.out.println("[AuctionTrade] * http://ibhh.de/AuctionTrade.jar *");
  105 + System.out.println("[AuctionTrade] ******************************************");
  106 + if (getConfig().getBoolean("autodownload") == true) {
  107 + try {
  108 + String path = getDataFolder().toString() + "/Update/";
  109 + Update.autoUpdate("http://ibhh.de/AuctionTrade.jar", path, "AuctionTrade.jar");
  110 + } catch (Exception e) {
  111 + System.out.println("[AuctionTrade] " + "Error on checking permissions with PermissionsEx!");
  112 + e.printStackTrace();
  113 + }
  114 + } else {
  115 + System.out.println("[AuctionTrade] Please type [AuctionTrade download] to download manual! ");
  116 + }
  117 + }
  118 + }
112 119
113   - } else {
114   - System.out
115   - .println("[AuctionTrade] Please type [AuctionTrade download] to download manual! ");
116   - }
117   - }
118   - }
  120 + public void getConfigStrings() {
  121 + Time0msg = getConfig().getString("command.error.time0." + getConfig().getString("language"));
  122 + Successcreate = getConfig().getString("command.success.create." + getConfig().getString("language"));
  123 + }
119 124
120   - /**
121   - * Gets version.
122   - *
123   - * @param
124   - * @return float: Version of the installed plugin.
125   - */
126   - public float aktuelleVersion() {
127   - try {
128   - Version = Float.parseFloat(getDescription().getVersion());
129   - } catch (Exception e) {
130   - System.out
131   - .println("[AuctionTrade]Could not parse version in float");
132   - }
133   - return Version;
134   - }
  125 + /**
  126 + * Gets version.
  127 + *
  128 + * @param
  129 + * @return float: Version of the installed plugin.
  130 + */
  131 + public float aktuelleVersion() {
  132 + try {
  133 + Version = Float.parseFloat(getDescription().getVersion());
  134 + } catch (Exception e) {
  135 + System.out.println("[AuctionTrade]Could not parse version in float");
  136 + }
  137 + return Version;
  138 + }
135 139
  140 + public static void Logger(String msg, String TYPE) {
  141 + if (TYPE.equalsIgnoreCase("Warning") || TYPE.equalsIgnoreCase("Error")) {
  142 + System.err.println("[AuctionTrade] " + TYPE + msg);
  143 + } else if (TYPE.equalsIgnoreCase("Debug")) {
  144 + System.out.println("[AuctionTrade] Debug:" + msg);
  145 + } else {
  146 + System.out.println("[AuctionTrade] " + msg);
  147 + }
  148 + }
136 149
137   - /**
138   - * Called by Bukkit on reloading the server
139   - *
140   - * @param
141   - * @return
142   - */
143   - public void onReload() {
144   - onEnable();
145   - }
  150 + public static void PlayerLogger(Player p, String msg, String TYPE) {
  151 + if (TYPE.equalsIgnoreCase("Error")) {
  152 + p.sendMessage(Prefix + "Error: " + msg);
  153 + } else {
  154 + p.sendMessage(Prefix + msg);
  155 + }
  156 + }
146 157
147   - protected static boolean isConsole(CommandSender sender) {
148   - return !(sender instanceof Player);
149   - }
  158 + /**
  159 + * Called by Bukkit on reloading the server
  160 + *
  161 + * @param
  162 + * @return
  163 + */
  164 + public void onReload() {
  165 + onEnable();
  166 + }
150 167
151   - /**
152   - * Called by Bukkit if player posts a command
153   - *
154   - * @param none
155   - * , cause of Bukkit.
156   - * @return true if no errors happened else return false to Bukkit.
157   - */
158   - @Override
159   - public boolean onCommand(CommandSender sender, Command cmd, String label,
160   - String[] args) {
161   - if (sender instanceof Player) {
162   - Player player = (Player) sender;
163   - action = args[0];
164   - if (cmd.getName().equalsIgnoreCase("AuctionTrade"))
165   - {
166   - if(Permission.checkpermissions(player, action))
167   - {
168   - if(args.length == 1)
169   - {
170   - if(args[0].equalsIgnoreCase("create"))
171   - {
172   - Date date = Time.getDate();
173   - String ItemId = args[1];
174   - con.InsertAuction(15, sender, ItemId, date, null, "");
175   - }
176   - }
177   - }
178   - }
179   - } else {
180   - if (isConsole(sender)) {
181   - if (cmd.getName().equalsIgnoreCase("AuctionTrade")) {
182   - if (args.length == 1) {
183   - if (args[0].equals("download")) {
184   - String path = getDataFolder().toString()
185   - + "/Update/";
186   - Update.autoUpdate(
187   - "http://ibhh.de/AuctionTrade.jar", path,
188   - "AuctionTrade.jar");
189   - }
190   - }
191   - }
192   - }
193   - }
194   - return false;
195   - }
  168 + protected static boolean isConsole(CommandSender sender) {
  169 + return !(sender instanceof Player);
  170 + }
196 171
  172 + /**
  173 + * Called by Bukkit if player posts a command
  174 + *
  175 + * @param none , cause of Bukkit.
  176 + * @return true if no errors happened else return false to Bukkit.
  177 + */
  178 + @Override
  179 + public boolean onCommand(CommandSender sender, Command cmd, String label,
  180 + String[] args) {
  181 + if (sender instanceof Player) {
  182 + Player player = (Player) sender;
  183 + action = args[0];
  184 + if (cmd.getName().equalsIgnoreCase("AuctionTrade")) {
  185 + if (Permission.checkpermissions(player, "AuctionTrade.create")) {
  186 + if (args.length == 1) {
  187 + if (args[0].equalsIgnoreCase("create")) {
  188 + Long TIME = Time.getTime();
  189 + String ItemId = args[1];
  190 + int Dauer = 0;
  191 + double Anfang = 0;
  192 + try {
  193 + Anfang = Double.parseDouble(args[3]);
  194 + } catch (Exception e) {
  195 + Logger(e.getMessage(), "Error");
  196 + PlayerLogger(player, e.getMessage(), "Error");
  197 + }
  198 + try {
  199 + Dauer = Integer.parseInt(args[2]);
  200 + Dauer = Dauer * 1000 * 60 * 60;
  201 + } catch (Exception e) {
  202 + Logger(e.getMessage(), "Error");
  203 + PlayerLogger(player, e.getMessage(), "Error");
  204 + }
  205 + if (Dauer != 0) {
  206 + con.InsertAuction(TIME, sender, ItemId, Anfang, Dauer, "");
  207 + PlayerLogger(player, String.format(Successcreate, TIME, ItemId, Dauer), "");
  208 + } else {
  209 + PlayerLogger(player, Time0msg, label);
  210 + }
  211 + }
  212 + }
  213 + }
  214 + }
  215 + } else {
  216 + if (isConsole(sender)) {
  217 + if (cmd.getName().equalsIgnoreCase("AuctionTrade")) {
  218 + if (args.length == 1) {
  219 + if (args[0].equals("download")) {
  220 + String path = getDataFolder().toString() + "/Update/";
  221 + Update.autoUpdate("http://ibhh.de/AuctionTrade.jar", path, "AuctionTrade.jar");
  222 + }
  223 + }
  224 + }
  225 + }
  226 + }
  227 + return false;
  228 + }
197 229 }
130 src/me/ibhh/AuctionTrade/PanelControl.java
... ... @@ -0,0 +1,130 @@
  1 +package me.ibhh.AuctionTrade;
  2 +
  3 +import java.awt.BorderLayout;
  4 +import java.awt.event.ActionEvent;
  5 +import java.awt.event.ActionListener;
  6 +import javax.swing.*;
  7 +
  8 +public class PanelControl extends JFrame {
  9 +
  10 + private JPanel hauptPanel;
  11 + private AuctionTrade auc;
  12 + private JButton Button1;
  13 + private JButton Button2;
  14 + private JButton Button3;
  15 + private JTextField text;
  16 + private JCheckBox Haken;
  17 + private BorderLayout borderLayout;
  18 +
  19 + public PanelControl(AuctionTrade au) {
  20 + super();
  21 + auc = au;
  22 + setTitle("Default options");
  23 + setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  24 + borderLayout = new BorderLayout();
  25 + hauptPanel = init();
  26 + this.getContentPane().add(hauptPanel);
  27 + }
  28 +
  29 + public JPanel hauptpanel(){
  30 + JPanel panel = new JPanel(borderLayout);
  31 + Button1 = new JButton("Abbruch");
  32 + Button1.addActionListener(new ActionListener() {
  33 +
  34 + @Override
  35 + public void actionPerformed(ActionEvent event) {
  36 + if (auc.debug) {
  37 + System.out.println("Button2 get" + event.toString());
  38 + System.out.println("Source: " + event.getSource());
  39 + }
  40 + PanelControl.this.remove(hauptPanel);
  41 + PanelControl.this.repaint();
  42 + PanelControl.this.dispose();
  43 + }
  44 + });
  45 + Button3 = new JButton("Weiter");
  46 + Button3.addActionListener(new ActionListener() {
  47 +
  48 + @Override
  49 + public void actionPerformed(ActionEvent event) {
  50 + if (auc.debug) {
  51 + System.out.println("Button2 get" + event.toString());
  52 + System.out.println("Source: " + event.getSource());
  53 + }
  54 + }
  55 + });
  56 + JPanel panelunten = new JPanel();
  57 + panelunten.add(Button1, BorderLayout.SOUTH);
  58 + panelunten.add(Button3, BorderLayout.SOUTH);
  59 + panel.add(firstPanel(), BorderLayout.CENTER);
  60 + panel.add(panelunten, BorderLayout.SOUTH);
  61 + return panel;
  62 + }
  63 +
  64 + public JPanel secondPanel() {
  65 + JPanel panel = new JPanel();
  66 + final JLabel label = new JLabel("SQLUser: ");
  67 + text = new JTextField("User");
  68 +
  69 + Button2 = new JButton("Weiter");
  70 + Button2.addActionListener(new ActionListener() {
  71 +
  72 + @Override
  73 + public void actionPerformed(ActionEvent event) {
  74 + if (auc.debug) {
  75 + System.out.println("Button1 get");
  76 + System.out.println("Source: " + event.getSource());
  77 + }
  78 + auc.getConfig().set("dbUser", text.getText());
  79 + if (auc.debug) {
  80 + System.out.println("User: " + text.getText());
  81 + System.out.println("Weiter");
  82 + }
  83 + auc.getConfig().set("firstRun", false);
  84 + }
  85 + });
  86 + panel.add(label);
  87 + panel.add(text);
  88 + panel.add(Button2);
  89 + PanelControl.this.repaint();
  90 + return panel;
  91 + }
  92 +
  93 + public JPanel firstPanel() {
  94 + JPanel panel = new JPanel();
  95 + final JLabel label = new JLabel("Use MYSQL?");
  96 + Haken = new JCheckBox();
  97 + Haken.setSelected(auc.getConfig().getBoolean("SQL"));
  98 + Haken.addActionListener(new ActionListener() {
  99 +
  100 + @Override
  101 + public void actionPerformed(ActionEvent event) {
  102 + if (auc.debug) {
  103 + System.out.println("Button2 get" + event.toString());
  104 + System.out.println("Source: " + event.getSource());
  105 + }
  106 + boolean temp = auc.getConfig().getBoolean("SQL");
  107 + auc.getConfig().set("SQL", !temp);
  108 + auc.saveConfig();
  109 + auc.reloadConfig();
  110 + if (auc.debug) {
  111 + System.out.println("temp: " + temp);
  112 + System.out.println("Selected: " + Haken.isSelected());
  113 + System.out.println("Neue Config: " + auc.getConfig().getBoolean("SQL"));
  114 + System.out.println("Weiter");
  115 + }
  116 + }
  117 + });
  118 + panel.add(label);
  119 + panel.add(Haken);
  120 + return panel;
  121 + }
  122 +
  123 + /**
  124 + * Komponenten initialisieren
  125 + */
  126 + private JPanel init() {
  127 + JPanel j = hauptpanel();
  128 + return j;
  129 + }
  130 +}
191 src/me/ibhh/AuctionTrade/PermissionsHandler.java
... ... @@ -1,119 +1,72 @@
1   -/**
2   - *
3   - */
4   -package me.ibhh.AuctionTrade;
5   -
6   -import org.bukkit.Bukkit;
7   -import org.bukkit.ChatColor;
8   -import org.bukkit.command.CommandSender;
9   -import org.bukkit.entity.Player;
10   -
11   -import ru.tehkode.permissions.PermissionManager;
12   -import ru.tehkode.permissions.bukkit.PermissionsEx;
13   -
14   -/**
15   - * @author Simon
16   - *
17   - */
18   -public class PermissionsHandler
19   -{
20   - private AuctionTrade auTrade;
21   -
22   - public PermissionsHandler(AuctionTrade AuctTrade)
23   - {
24   - auTrade = AuctTrade;
25   - }
26   -
27   - public boolean checkpermissions(CommandSender sender , String action)
28   - {
29   - if (sender instanceof Player)
30   - {
31   - Player player = (Player) sender;
32   - if (!action.isEmpty())
33   - {
34   - if (!Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx"))
35   - {
36   - try {
37   - if (player.hasPermission("xpShop." + action))
38   - {
39   - return true;
40   - } // if(permissions.has(player, "xpShop." + action))
41   - else
42   - {
43   - player.sendMessage(
44   - ChatColor.GRAY
45   - + "[xpShop] "
46   - + ChatColor.RED
47   - + (auTrade.getConfig() .getString("permissions.error."
48   - + auTrade.getConfig().getString("language")))
49   - );
50   - return false;
51   - }
52   - }
53   - catch (Exception e)
54   - {
55   - System.out.println("[xpShop] "
56   - + "Error on checking permissions with BukkitPermissions!");
57   - player.sendMessage("[xpShop] "
58   - + "Error on checking permissions with BukkitPermissions!");
59   - e.printStackTrace();
60   - return false;
61   - }
62   -
63   - }
64   - else
65   - {
66   - if (Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx"))
67   - {
68   - try
69   - {
70   - PermissionManager permissions = PermissionsEx.getPermissionManager();
71   - // Permission check
72   - if (permissions.has(player, "xpShop." + action)) {
73   - // yay!
74   - return true;
75   - }
76   - else
77   - {
78   - // houston, we have a problem :)
79   - player.sendMessage(ChatColor.GRAY
80   - + "[xpShop] "
81   - + ChatColor.RED
82   - + (auTrade.getConfig().getString("permissions.error."
83   - + auTrade.getConfig().getString("language"))));
84   - return false;
85   - }
86   - }
87   - catch (Exception e)
88   - {
89   - System.out
90   - .println("[xpShop] "
91   - + "Error on checking permissions with PermissionsEx!");
92   - player.sendMessage("[xpShop] "
93   - + "Error on checking permissions with PermissionsEx!");
94   - e.printStackTrace();
95   - return false;
96   - }
97   - }
98   - else
99   - {
100   - System.out
101   - .println("PermissionsEx plugin are not found.");
102   - return false;
103   - }
104   - }
105   - }
106   - else
107   - {
108   - return false;
109   - }
110   -
111   - }
112   - else {
113   - System.out.println("[xpShop] "
114   - + (auTrade.getConfig().getString("command.error.noplayer"
115   - + auTrade.getConfig().getString("language"))));
116   - return false;
117   - }
118   - }
119   -}
  1 +/**
  2 + *
  3 + */
  4 +package me.ibhh.AuctionTrade;
  5 +
  6 +import org.bukkit.Bukkit;
  7 +import org.bukkit.command.CommandSender;
  8 +import org.bukkit.entity.Player;
  9 +import ru.tehkode.permissions.PermissionManager;
  10 +import ru.tehkode.permissions.bukkit.PermissionsEx;
  11 +
  12 +/**
  13 + * @author Simon
  14 + *
  15 + */
  16 +public class PermissionsHandler {
  17 + private AuctionTrade auTrade;
  18 + public PermissionsHandler(AuctionTrade AuctTrade) {
  19 + auTrade = AuctTrade;
  20 + }
  21 + public boolean checkpermissions(CommandSender sender , String action){
  22 + if (sender instanceof Player) {
  23 + Player player = (Player) sender;
  24 + if (!action.isEmpty()) {
  25 + if (!Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")) {
  26 + try {
  27 + if (player.hasPermission(action)) {
  28 + return true;
  29 + } // if(permissions.has(player, "AuctionTrade." + action))
  30 + else {
  31 + player.sendMessage(AuctionTrade.Prefix + auTrade.getConfig().getString("permissions.error." + auTrade.getConfig().getString("language")));
  32 + return false;
  33 + }
  34 + } catch (Exception e) {
  35 + System.out.println("[AuctionTrade] " + "Error on checking permissions with BukkitPermissions!");
  36 + player.sendMessage("[AuctionTrade] " + "Error on checking permissions with BukkitPermissions!");
  37 + e.printStackTrace();
  38 + return false;
  39 + }
  40 + } else {
  41 + if (Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")) {
  42 + try {
  43 + PermissionManager permissions = PermissionsEx.getPermissionManager();
  44 + // Permission check
  45 + if (permissions.has(player, "AuctionTrade." + action)) {
  46 + // yay!
  47 + return true;
  48 + } else {
  49 + // houston, we have a problem :)
  50 + player.sendMessage(AuctionTrade.Prefix + auTrade.getConfig().getString("permissions.error." + auTrade.getConfig().getString("language")));
  51 + return false;
  52 + }
  53 + } catch (Exception e) {
  54 + System.out.println("[AuctionTrade] " + "Error on checking permissions with PermissionsEx!");
  55 + player.sendMessage("[AuctionTrade] " + "Error on checking permissions with PermissionsEx!");
  56 + e.printStackTrace();
  57 + return false;
  58 + }
  59 + } else {
  60 + System.out.println("PermissionsEx plugin are not found.");
  61 + return false;
  62 + }
  63 + }
  64 + } else {
  65 + return false;
  66 + }
  67 + } else {
  68 + System.out.println("[AuctionTrade] " + (auTrade.getConfig().getString("command.error.noplayer" + auTrade.getConfig().getString("language"))));
  69 + return false;
  70 + }
  71 + }
  72 +}
359 src/me/ibhh/AuctionTrade/SQLConnectionHandler.java
... ... @@ -1,155 +1,208 @@
1   -/**
2   - *
3   - */
4 1 package me.ibhh.AuctionTrade;
5 2
6   -import java.io.File;
7   -import java.sql.Connection;
8   -import java.sql.Date;
9   -import java.sql.DriverManager;
10   -import java.sql.PreparedStatement;
11   -import java.sql.SQLException;
12   -import java.sql.Statement;
13   -
14   -import org.bukkit.command.CommandSender;
15   -
16   -/**
17   - * @author Simon
18   - *
19   - */
20   -public class SQLConnectionHandler
21   -{
22   -
23   - private String dbPath;
24   - private String dbUser;
25   - private String dbPassword;
26   - private Connection cn;
27   - private boolean useMySQL;
28   - private AuctionTrade auTrade;
29   -
30   - public SQLConnectionHandler(AuctionTrade AuctTrade)
31   - {
32   - auTrade = AuctTrade;
33   - dbPath = auTrade.getConfig().getString("dbPath");
34   - dbUser = auTrade.getConfig().getString("dbUser");
35   - dbPassword = auTrade.getConfig().getString("dbPassword");
36   - cn = null;
37   - useMySQL = auTrade.getConfig().getBoolean("SQL");
38   -
39   - }
40   -
41   - public void PrepareDB()
42   - {
43   - Statement st = null;
44   - try {
45   - st = cn.createStatement();
46   - if (auTrade.getConfig().getBoolean("SQL"))
47   - {
48   - st.executeUpdate("CREATE TABLE IF NOT EXISTS AuctionTrade (Time DOUBLE, sender CHAR(20), ItemId CHAR(20), Begin DOUBLE, End DOUBLE, Winner CHAR(20), PRIMARY KEY (ID))");
49   - System.out.println("[AuctionTrade] Table created!");
50   - }
51   - else
52   - {
53   - st.executeUpdate("CREATE TABLE IF NOT EXISTS \"AuctionTrade\" (\"ID\" VARCHAR PRIMARY KEY NOT NULL , \"Time\" DOUBLE, \"sender\" VARCHAR, \"ItemId\" VARCHAR, `Begin` DOUBLE, `End` DOUBLE, Winner VARCHAR)");
54   - System.out.println("[AuctionTrade] Table created!");
55   - }
56   - cn.commit();
57   - st.close();
58   - }
59   - catch (SQLException e)
60   - {
61   - System.out.println("[AuctionTrade]: Error while creating tables! - " + e.getMessage());
62   - e.printStackTrace();
63   - }
64   - // UpdateDB();
65   - }
66   -
67   - public boolean InsertAuction(int i, CommandSender sender, String ItemId, Date date, Date date1, String Winner) {
68   -
69   - try {
70   - PreparedStatement ps = cn.prepareStatement("INSERT INTO jail_prisoners (Time, sender, ItemId, Begin, End, Winner) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
71   - ps.setInt(1, i);
72   - ps.setString(2, sender.getName());
73   - ps.setString(3, ItemId);
74   - ps.setDate(4, date);
75   - ps.setDate(5, date1);
76   - ps.setString(6, Winner);
77   - ps.executeUpdate();
78   - cn.commit();
79   - ps.close();
80   - return true;
81   - } catch (SQLException e) {
82   - System.out.println("[AuctionTrade] Error while inserting Prisoner into DB! - " + e.getMessage());
83   - e.printStackTrace();
84   - return false;
85   - }
86   - }
87   -
88   - public Connection createConnection() {
89   - try {
90   - if ((dbPath == "unknown") || (dbUser == "unknown")
91   - || (dbPassword == "unknown")) {
92   - System.out
93   - .println("[AuctionTrade] could not be enabled: Failed to connect to DB: Check config settings dbPath, dbUser and dbPassword");
94   - return null;
95   - } else if (useMySQL) {
96   - try {
97   - Class.forName("com.mysql.jdbc.Driver");
98   - cn = DriverManager.getConnection("jdbc:mysql://" + dbPath,
99   - dbUser, dbPassword);
100   - cn.setAutoCommit(false);
101   - return cn;
102   - } catch (SQLException e) {
103   - System.out
104   - .println("[AuctionTrade] could not be enabled: Exception occured while trying to connect to DB");
105   - e.printStackTrace();
106   - if (cn != null) {
107   - System.out
108   - .println("[AuctionTrade] Old Connection still activated");
109   -
110   - try {
111   - cn.close();
112   - System.out
113   - .println("[AuctionTrade] Old connection that was still activated has been successfully closed");
114   - } catch (SQLException e2) {
115   - System.out
116   - .println("[AuctionTrade] Failed to close old connection that was still activated");
117   - e2.printStackTrace();
118   - }
119   - }
120   - return null;
121   - } catch (ClassNotFoundException e) {
122   - e.printStackTrace();
123   - return null;
124   - }
125   - } else if (!useMySQL) {
126   - Class.forName("org.sqlite.JDBC");
127   - cn = DriverManager.getConnection("jdbc:sqlite:plugins"
128   - + File.separator + "AuctionTrade" + File.separator
129   - + "AuctionTrade.sqlite");
130   - cn.setAutoCommit(false);
131   - return cn;
132   - }
133   - } catch (ClassNotFoundException e) {
134   - e.printStackTrace();
135   - return null;
136   - } catch (SQLException e) {
137   - e.printStackTrace();
138   - }
139   - return null;
140   - }
141   -
142   - public boolean CloseCon()
143   - {
144   - try {
145   - cn.close();
146   - return true;
147   - } catch (SQLException e) {
148   - System.out
149   - .println("[AuctionTrade] Failed to close connection to DB!");
150   - e.printStackTrace();
151   - return false;
152   - }
153   - }
154   -
155   -}
  3 +/**
  4 + *
  5 + */
  6 +
  7 +
  8 +import java.io.File;
  9 +import java.sql.*;
  10 +import org.bukkit.command.CommandSender;
  11 +import sun.security.util.BigInt;
  12 +
  13 +/**
  14 + * @author Simon
  15 + *
  16 + */
  17 +public class SQLConnectionHandler {
  18 +
  19 + private String dbPath;
  20 + private String dbUser;
  21 + private String dbPassword;
  22 + private Connection cn;
  23 + private boolean useMySQL;
  24 + private AuctionTrade auTrade;
  25 +
  26 + public SQLConnectionHandler(AuctionTrade AuctTrade) {
  27 + auTrade = AuctTrade;
  28 + dbPath = auTrade.getConfig().getString("dbPath");
  29 + dbUser = auTrade.getConfig().getString("dbUser");
  30 + dbPassword = auTrade.getConfig().getString("dbPassword");
  31 + cn = null;
  32 + useMySQL = auTrade.getConfig().getBoolean("SQL");
  33 +
  34 + }
  35 +
  36 + public void PrepareDB() {
  37 + Statement st = null;
  38 + try {
  39 + String sql = "CREATE TABLE IF NOT EXISTS AuctionTrade (ID VARCHAR PRIMARY KEY AUTO_INCREMENT NOT NULL , Time BIGINT NOT NULL, sender VARCHAR NOT NULL, ItemId VARCHAR NOT NULL, Begin DOUBLE NOT NULL, End DOUBLE, Winner VARCHAR)";
  40 + st = cn.createStatement();
  41 + if (auTrade.getConfig().getBoolean("SQL")) {
  42 + st.executeUpdate(sql);
  43 + System.out.println("[AuctionTrade] Table created!");
  44 + } else {
  45 + st.executeUpdate("CREATE TABLE IF NOT EXISTS AuctionTrade (ID VARCHAR PRIMARY KEY NOT NULL, Time BIGINT, sender VARCHAR, ItemId VARCHAR, Begin DOUBLE, End DOUBLE, Winner VARCHAR)");
  46 + System.out.println("[AuctionTrade] Table created!");
  47 + }
  48 + cn.commit();
  49 + st.close();
  50 + } catch (SQLException e) {
  51 + System.out.println("[AuctionTrade]: Error while creating tables! - " + e.getMessage());
  52 + SQLErrorHandler(e);
  53 + }
  54 + // UpdateDB();
  55 + }