You are not logged in.

  • Login
Bitte besucht unser neues Forum unter https://forum.nitrado.net | Please visit our new Forum at https://forum.nitrado.net

jphserver

User / Kunde

  • "jphserver" started this thread

Posts: 3

  • Send private message

1

Monday, January 28th 2019, 5:54pm

MySQL CoinPlugin Fehler

Hallo, ich habe ein Problem mit meinem CoinsPlugin. Wenn ich einem Spieler Coins gebe geht es aber wenn ich ihm dann zb etwas abziehe dann kommt ein Error!
(Nachdem ich ihm Coins gebe kann ich den Wert nicht verändern)

Commands:

package cc.sys.cmd;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cc.sys.main.Main;
import cc.sys.util.CoinManager;

public class CoinCommands implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) {
if(cmd.getName().equalsIgnoreCase("coins")) {
if(args.length == 3) {
if(sender.hasPermission("system.coins.all")) {
if(args[0].equalsIgnoreCase("add")) {
Player target = Bukkit.getPlayer(args[1]);
if(target.isOnline()) {
if(!args[2].isEmpty()) {
int coinamount = Integer.valueOf(args[2]);
CoinManager.addCoins(target.getUniqueId().toString(), coinamount);
sender.sendMessage(Main.prefix + "§aDu hast §b" + target.getName() + "§c " + coinamount + "§a Coins hinzugefügt!");
} else {
sender.sendMessage(Main.prefix + "§c/coins <add|remove> <Spieler> <Anzahl>");
}
} else {
sender.sendMessage(Main.prefix + "§cDer Spieler §b" + args[1] + "§c konnte nicht gefunden werden!");
}
} else {
if(args[0].equalsIgnoreCase("remove")) {
Player target = Bukkit.getPlayer(args[1]);
if(target.isOnline()) {
if(!args[2].isEmpty()) {
int coinamount = Integer.valueOf(args[2]);
CoinManager.removeCoins(target.getUniqueId().toString(), coinamount);
sender.sendMessage(Main.prefix + "§aDu hast §b" + target.getName() + "§c " + coinamount + "§a Coins abgezogen!");
} else {
sender.sendMessage(Main.prefix + "§c/coins <add|remove> <Spieler> <Anzahl>");
}
} else {
sender.sendMessage(Main.prefix + "§cDer Spieler §b" + args[1] + "§c konnte nicht gefunden werden!");
}
}
}
} else {
sender.sendMessage(Main.prefix + Main.noperms);
}
}
}
return true;
}

}

CoinManager:


package cc.sys.util;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cc.sys.mysql.MySQL;

public class CoinManager {

public static int getCoins(String uuid) {
try {
PreparedStatement st = MySQL.con.prepareStatement("SELECT * FROM PlayerCoins WHERE UUID = ?");
st.setString(1, uuid);
ResultSet rs = st.executeQuery();
while(rs.next()) {
return rs.getInt("coins");
}
} catch(SQLException e) {
e.printStackTrace();
}
return -1;
}

public static void setCoins(String uuid, int coins) {
if(getCoins(uuid) == -1) {
try {
PreparedStatement st = MySQL.con.prepareStatement("INSERT INTO PlayerCoins (UUID,coins) VALUES (?,?)");
st.setString(1, uuid);
st.setInt(2, coins);
st.executeUpdate();
} catch(SQLException e) {
e.printStackTrace();
}
} else {
try {
PreparedStatement st = MySQL.con.prepareStatement("UPDATE PlayerCoins SET coins = ? WHERE UUID = ?");
st.setString(1, uuid);
st.setInt(2, coins);
st.executeUpdate();
} catch(SQLException e) {
e.printStackTrace();
}
}
}

public static void addCoins(String uuid, int coins) {
setCoins(uuid, coins + getCoins(uuid));
}

public static void removeCoins(String uuid, int coins) {
int current = getCoins(uuid);
setCoins(uuid, current - coins);
}

}

Error:


[17:32:03 WARN]: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '4df451d5-af89-3985-b0c5-70c991d6728b'
[17:32:03 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3591)
[17:32:03 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
[17:32:03 WARN]: at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
[17:32:03 WARN]: at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
[17:32:03 WARN]: at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
[17:32:03 WARN]: at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
[17:32:03 WARN]: at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2407)
[17:32:03 WARN]: at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2325)
[17:32:03 WARN]: at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2310)
[17:32:03 WARN]: at cc.sys.util.CoinManager.setCoins(CoinManager.java:40)
[17:32:03 WARN]: at cc.sys.util.CoinManager.addCoins(CoinManager.java:48 )
[17:32:03 WARN]: at cc.sys.cmd.CoinCommands.onCommand(CoinCommands.java:24)
[17:32:03 WARN]: at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
[17:32:03 WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
[17:32:03 WARN]: at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
[17:32:03 WARN]: at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[17:32:03 WARN]: at java.util.concurrent.FutureTask.run(Unknown Source)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
[17:32:03 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
[17:32:03 WARN]: at java.lang.Thread.run(Unknown Source)

thunfischbaum

User / Kunde

  • "thunfischbaum" is male

Posts: 254

Location: %JAVA_HOME%

Occupation: Fachinformatiker für Systemintegration

Thanks: 5

  • Send private message

2

Friday, February 1st 2019, 10:29pm

Eine bitte.
Nutze :

Source code

1

				

Danke.

Schönes Wochenende,
thunfisch

Bitte besucht unser neues Forum unter https://forum.nitrado.net| Please visit our new Forum at https://forum.nitrado.net

Similar threads