Merge branch 'master' into schematic-node
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Commit
32a9e2f619
@ -51,8 +51,9 @@ public abstract class SWCommand {
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
createMapping();
|
createMapping();
|
||||||
}
|
}
|
||||||
if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false;
|
if (!commandList.stream().anyMatch(s -> s.invoke(sender, args))) {
|
||||||
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
|
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,13 +88,13 @@ public abstract class SWCommand {
|
|||||||
add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> {
|
add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> {
|
||||||
if (!anno.help()) return;
|
if (!anno.help()) return;
|
||||||
if (parameters.length != 2) {
|
if (parameters.length != 2) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking parameters or has too many");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking parameters or has too many");
|
||||||
}
|
}
|
||||||
if (!parameters[parameters.length - 1].isVarArgs()) {
|
if (!parameters[parameters.length - 1].isVarArgs()) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument");
|
||||||
}
|
}
|
||||||
if (parameters[parameters.length - 1].getType().getComponentType() != String.class) {
|
if (parameters[parameters.length - 1].getType().getComponentType() != String.class) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>()));
|
commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>()));
|
||||||
@ -114,7 +115,7 @@ public abstract class SWCommand {
|
|||||||
}
|
}
|
||||||
String name = mapper != null ? mapper.value() : clazz.getTypeName();
|
String name = mapper != null ? mapper.value() : clazz.getTypeName();
|
||||||
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name) && !localTypeMapper.containsKey(name)) {
|
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name) && !localTypeMapper.containsKey(name)) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,15 +142,15 @@ public abstract class SWCommand {
|
|||||||
|
|
||||||
Parameter[] parameters = method.getParameters();
|
Parameter[] parameters = method.getParameters();
|
||||||
if (!parameterTester.test(parameters.length)) {
|
if (!parameterTester.test(parameters.length)) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking parameters or has too many");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking parameters or has too many");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (firstParameter && !CommandSender.class.isAssignableFrom(parameters[0].getType())) {
|
if (firstParameter && !CommandSender.class.isAssignableFrom(parameters[0].getType())) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (returnType != null && method.getReturnType() != returnType) {
|
if (returnType != null && method.getReturnType() != returnType) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arrays.stream(anno).forEach(t -> consumer.accept(t, parameters));
|
Arrays.stream(anno).forEach(t -> consumer.accept(t, parameters));
|
||||||
|
@ -28,7 +28,7 @@ public class Elo {
|
|||||||
public static int getElo(int userId, String gameMode){
|
public static int getElo(int userId, String gameMode){
|
||||||
return get.select(rs -> {
|
return get.select(rs -> {
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
return rs.getInt("id");
|
return rs.getInt("Elo");
|
||||||
return 1000;
|
return 1000;
|
||||||
}, userId, gameMode);
|
}, userId, gameMode);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
|
import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@ -33,27 +34,27 @@ public class SQL {
|
|||||||
private SQL(){}
|
private SQL(){}
|
||||||
|
|
||||||
private static Connection con;
|
private static Connection con;
|
||||||
private static String url;
|
private static final String URL;
|
||||||
private static String user;
|
private static final String USER;
|
||||||
private static String password;
|
private static final String PASSWORD;
|
||||||
|
|
||||||
static{
|
static {
|
||||||
File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
|
||||||
if(!file.exists())
|
if(!file.exists())
|
||||||
throw new SecurityException("SQL-ConfigFile not found!");
|
throw new SecurityException("SQL-ConfigFile not found!");
|
||||||
|
|
||||||
url = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
|
URL = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
|
||||||
user = config.getString("USER");
|
USER = config.getString("USER");
|
||||||
password = config.getString("PASSWORD");
|
PASSWORD = config.getString("PASSWORD");
|
||||||
|
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void connect() {
|
private static void connect() {
|
||||||
try {
|
try {
|
||||||
con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password);
|
con = DriverManager.getConnection(URL + "?useServerPrepStmts=true", USER, PASSWORD);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SecurityException("Could not start SQL connection", e);
|
throw new SecurityException("Could not start SQL connection", e);
|
||||||
}
|
}
|
||||||
@ -95,7 +96,8 @@ public class SQL {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static void update(String qry, Object... objects) {
|
static void update(String qry, Object... objects) {
|
||||||
try {
|
try {
|
||||||
prepare(qry, objects).executeUpdate();
|
prepare(qry, objects).executeUpdate();
|
||||||
@ -105,7 +107,8 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ResultSet select(String qry, Object... objects){
|
@Deprecated
|
||||||
|
static ResultSet select(String qry, Object... objects) {
|
||||||
try {
|
try {
|
||||||
return prepare(qry, objects).executeQuery();
|
return prepare(qry, objects).executeQuery();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -114,7 +117,8 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Blob blob(){
|
@Deprecated
|
||||||
|
static Blob blob() {
|
||||||
try {
|
try {
|
||||||
return con.createBlob();
|
return con.createBlob();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -123,7 +127,8 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PreparedStatement prepare(String qry, Object... objects) throws SQLException{
|
@Deprecated
|
||||||
|
private static PreparedStatement prepare(String qry, Object... objects) throws SQLException {
|
||||||
PreparedStatement st = con.prepareStatement(qry);
|
PreparedStatement st = con.prepareStatement(qry);
|
||||||
for(int i = 0; i < objects.length; i++){
|
for(int i = 0; i < objects.length; i++){
|
||||||
st.setObject(i+1, objects[i]);
|
st.setObject(i+1, objects[i]);
|
||||||
@ -166,10 +171,15 @@ public class SQL {
|
|||||||
|
|
||||||
private synchronized <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
private synchronized <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
||||||
try {
|
try {
|
||||||
setObjects(objects);
|
try {
|
||||||
return runnable.run();
|
setObjects(objects);
|
||||||
|
return runnable.run();
|
||||||
|
} catch (CommunicationsException e) {
|
||||||
|
reset();
|
||||||
|
setObjects(objects);
|
||||||
|
return runnable.run();
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
reset();
|
|
||||||
throw new SecurityException("Could not execute SQL statement", e);
|
throw new SecurityException("Could not execute SQL statement", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren