Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhh committed May 4, 2013
1 parent a027b31 commit 0950121
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 56 deletions.
Binary file modified bin/me/ibhh/xpShop/xpShop.class
Binary file not shown.
Expand Up @@ -7,7 +7,7 @@ public class PlayerNotOnlineException extends Exception {
private static final long serialVersionUID = 1L;

public PlayerNotOnlineException(xpShop plugin, String player) {
super(player + plugin.config.playernotonline);
super(player + " " + plugin.config.playernotonline);
}

}
Expand Up @@ -7,7 +7,7 @@ public class PlayerWasNeverOnlineException extends Exception {
private static final long serialVersionUID = 1L;

public PlayerWasNeverOnlineException(xpShop plugin, String player) {
super(player + plugin.config.playerwasntonline);
super(player + " " + plugin.config.playerwasntonline);
}

}
50 changes: 23 additions & 27 deletions src/me/ibhh/xpShop/Tools/Tools.java
Expand Up @@ -100,48 +100,44 @@ public static Player getmyOfflinePlayer(xpShop plugin, String[] args, int index)

public static Player getmyOfflinePlayer(xpShop plugin, String playername) throws PlayerNotOnlineException, PlayerWasNeverOnlineException {
plugin.Logger("Empfaenger: " + playername, "Debug");
Player player = plugin.getServer().getPlayerExact(playername);
try {
if (player == null) {
return plugin.getServer().getPlayer(playername);
Player player = plugin.getServer().getPlayer(playername);
if (player != null) {
if (player.isOnline()) {
plugin.Logger("Player is online!", "Debug");
return player;
} else {
throw new PlayerNotOnlineException(plugin, playername);
}
boolean wasonline = false;
for (OfflinePlayer p : Bukkit.getServer().getOfflinePlayers()) {
OfflinePlayer offp = p;
if (offp.getName().toLowerCase().equals(playername.toLowerCase())) {
plugin.Logger("Player has same name: " + offp.getName(), "Debug");
if (offp != null) {
if (offp.hasPlayedBefore()) {
wasonline = true;
plugin.Logger("Player has Played before: " + offp.getName(), "Debug");
}
break;
}
boolean wasonline = false;
for (OfflinePlayer p : Bukkit.getServer().getOfflinePlayers()) {
if (p.getName().toLowerCase().equals(playername.toLowerCase())) {
if (p != null) {
if (p.hasPlayedBefore()) {
wasonline = true;
plugin.Logger("Player has Played before: " + p.getName(), "Debug");
}
break;
}
}
if (!wasonline) {
throw new PlayerWasNeverOnlineException(plugin, playername);
} else {
throw new PlayerNotOnlineException(plugin, playername);
}
} catch (Exception e) {
e.printStackTrace();
plugin.Logger("Uncatched Exeption!", "Error");
plugin.report.report(3312, "Uncatched Exeption on getting offlineplayer", e.getMessage(), "BookShop", e);
}
return player;
if (!wasonline) {
throw new PlayerWasNeverOnlineException(plugin, playername);
} else {
throw new PlayerNotOnlineException(plugin, playername);
}
}

public static boolean addDB(final xpShop plugin, final String player, final String sender, final int amount) throws InvalidXPAmountException {
if (amount > 0) {
final XPSend send = new XPSend(player, sender, amount, String.format(plugin.config.commandsuccessrecievedxp, amount, sender), 0);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {

@Override
public void run() {
plugin.getSendDatabase().InsertSend(send);
}
} );
});
} else {
throw new InvalidXPAmountException(amount);
}
Expand Down
20 changes: 10 additions & 10 deletions src/me/ibhh/xpShop/send/sql/SendDatabase.java
Expand Up @@ -65,7 +65,7 @@ public void PrepareDB() {
st.executeUpdate(sql);
plugin.Logger("Table created!", "Debug");
} else {
st.executeUpdate("CREATE TABLE IF NOT EXISTS xpShopSend (ID INT PRIMARY KEY AUTOINCREMENT, Name VARCHAR, Sender VARCHAR, Message VARCHAR, XP INT, Status INT);");
st.executeUpdate("CREATE TABLE IF NOT EXISTS xpShopSend (ID INTEGER PRIMARY KEY AUTOINCREMENT, Name VARCHAR, Sender VARCHAR, Message VARCHAR, XP INT, Status INT);");
plugin.Logger("Table created!", "Debug");
}
cn.commit();
Expand All @@ -89,10 +89,10 @@ public boolean InsertSend(String player, String sender, int sendedXP, String mes
time = System.nanoTime();
try {
PreparedStatement ps = cn.prepareStatement("INSERT INTO xpShopSend (Name, Sender, Message, XP, Status) VALUES (?,?,?,?,?)");
ps.setString(1, player);
ps.setString(2, sender);
ps.setInt(3, sendedXP);
ps.setString(4, message);
ps.setString(1, player.toLowerCase());
ps.setString(2, sender.toLowerCase());
ps.setString(3, message);
ps.setInt(4, sendedXP);
ps.setInt(5, status);
ps.execute();
cn.commit();
Expand All @@ -107,12 +107,12 @@ public boolean InsertSend(String player, String sender, int sendedXP, String mes
return true;
}

public boolean setStatus(String player, int id, int status) {
public boolean setStatus(final String player,final int id, final int status) {
long time = 0;
plugin.Logger("Updating XP in DB!", "Debug");
time = System.nanoTime();
try {
PreparedStatement ps = cn.prepareStatement("UPDATE xpShopSend SET Status='" + status + "' WHERE Name='" + player + "' AND ID=" + id + ";");
PreparedStatement ps = cn.prepareStatement("UPDATE xpShopSend SET Status='" + status + "' WHERE Name='" + player.toLowerCase() + "' AND ID=" + id + ";");
ps.executeUpdate();
cn.commit();
ps.close();
Expand Down Expand Up @@ -196,7 +196,7 @@ public boolean CloseCon() {
}
}

public ArrayList<XPSend> getOpenTransactions(String name) throws SQLException {
public ArrayList<XPSend> getOpenTransactions(final String name) throws SQLException {
long time = 0;
plugin.Logger("getting Transactions!", "Debug");
time = System.nanoTime();
Expand All @@ -208,12 +208,12 @@ public ArrayList<XPSend> getOpenTransactions(String name) throws SQLException {
} catch (SQLException e) {
SQLErrorHandler(e);
}
sql = "SELECT * from xpShopSend WHERE Name='" + name + "' AND Status=0;";
sql = "SELECT * from xpShopSend WHERE Name='" + name.toLowerCase() + "' AND Status=0;";
result = st.executeQuery(sql);
ArrayList<XPSend> xpSends = new ArrayList<XPSend>();
try {
while (result.next() == true) {
XPSend temp = new XPSend(result.getString("Name"), result.getString("Sender"), result.getInt("XP"), result.getString("Message"), result.getInt("Status"));
XPSend temp = new XPSend(result.getString("Name").toLowerCase(), result.getString("Sender").toLowerCase(), result.getInt("XP"), result.getString("Message"), result.getInt("Status"));
temp.setId(result.getInt("ID"));
xpSends.add(temp);
}
Expand Down
17 changes: 0 additions & 17 deletions src/me/ibhh/xpShop/xpShop.java
Expand Up @@ -92,10 +92,6 @@ public class xpShop extends JavaPlugin {
public String[] commands = { "help", "bottle", "bottleconfirm", "bottlecancel", "buy", "sell", "buylevel", "selllevel", "info", "send", "infoxpown", "infoxpother", "infolevelown", "infolevelother", "toolinfo", "repair", "grand", "showdebug", "debugfile", "internet", "version", "update", "reload", "deletedebug", "log", "toggle", "deletetable", "language", "resetplayer", "setXP", "tpto", "tpme", "yestp", "notp", "accept", "deny", "repaircancel", "repairconfirm" };
public TeleportManager TP;

public boolean isBukkitVersionCompatible() {
return Tools.packagesExists("net.minecraft.server.v1_4_5.MinecraftServer") || Tools.packagesExists("net.minecraft.server.v1_4_6.MinecraftServer") || Tools.packagesExists("net.minecraft.server.v1_4_R1.MinecraftServer") || Tools.packagesExists("net.minecraft.server.v1_5_R1.MinecraftServer") || Tools.packagesExists("net.minecraft.server.v1_5_R2.MinecraftServer") || Tools.packagesExists("net.minecraft.server.MinecraftServer");
}

public ReportToHost getReportHandler() {
if (report == null) {
report = new ReportToHost(this);
Expand Down Expand Up @@ -166,19 +162,6 @@ public void onEnable() {
Logger("Version: " + Version + " failed to enable!", "Error");
onDisable();
}
if (isBukkitVersionCompatible()) {
Logger("This plugin is compatible to this bukkit-version", "Debug");
} else {
Logger("Your plugin-version is NOT compatible!", "Error");
Logger("*****************************", "Warning");
Logger("Because of some Bukkitchanges", "Warning");
Logger("you have to update the plugin", "Warning");
Logger("manually.", "Warning");
Logger("*****************************", "Warning");
Logger("Your Bukkit version: " + getServer().getBukkitVersion(), "Warning");
setEnabled(false);
return;
}
report = new ReportToHost(this);
if (ex1 != null) {
report.report(332, "Config loading failed", ex1.getMessage(), "xpShop", ex1);
Expand Down
1 change: 1 addition & 0 deletions src/me/ibhh/xpShop/xpShopListener.java
Expand Up @@ -53,6 +53,7 @@ public void run() {
for(XPSend send : xpSends) {
plugin.PlayerLogger(player, send.getMessage(), "");
plugin.UpdateXP(player, send.getSendedXP(), "sendxp");
player.saveData();
plugin.getSendDatabase().setStatus(player.getName(), send.getId(), 1);
}
} catch (SQLException e) {
Expand Down

0 comments on commit 0950121

Please sign in to comment.