From 2b56329a97521117c6c97c6e408f509ce79ff1f1 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 01:32:15 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=20gradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 0eeddb5..089e004 100644 --- a/build.gradle +++ b/build.gradle @@ -64,22 +64,32 @@ subprojects { } } -task runApp(type: JavaExec) { +/** + * Запуск сервера. + * Для указания рабочей папки, указываем JVM параметр + * -DworkDir=path\to\workdir + * Если используется отдельная папка для имплементации логгера, то указываем + * -DlogImplDir=path\to\logimpldir + * Если необходимо передать дополнительные JVM параметры серверу, то указываем их с двойной "D", например: + * -DDspringConfig=spring.xml + * -DDlog4j.configurationFile=log4j2.xml + */ +task runServer(type: JavaExec) { main = 'mc.core.Main' - workingDir = (project.hasProperty("workDir") ? project.workDir : '.') + workingDir = System.getProperty("workDir", ".") subprojects.findAll().each{ prj -> classpath += prj.sourceSets.main.runtimeClasspath } - /* Uncomment, if your Log Implements are folder '{workDir}/log-impl' */ - //classpath += files(fileTree(dir: new File(workingDir, "log-impl"))) - /* Uncomment, if you used VM args */ - //jvmArgs = [ - // "-DspringConfig=spring.xml", - // "-Dlog4j.configurationFile=log4j2.xml" - //] + if (System.getProperty("logImplDir") != null) { + classpath += files(fileTree(dir: new File(System.getProperty("logImplDir")))) + } + + System.getProperties().stringPropertyNames().stream() + .filter{propName -> propName.startsWith("D")} + .forEach{propName -> jvmArgs += "-D" + propName.substring(1) + "=" + System.getProperty(propName)} ignoreExitValue = true } From b1877b1e969f86ba3127399f6d7b26803da35d2f Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 12:43:12 +0300 Subject: [PATCH 2/8] ignore *.log files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fa048d1..311183a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ gradlew.* ## PROJECT ## libs/ +*.log From b2efb3f8caf4678c92be93cdad01381b2de627fd Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 12:45:51 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=D1=81=D1=8F=20=D0=BE=D1=82=20=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=83=D0=B6=D0=BD=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/mc/core/nbt/Taggable.java | 11 ----- .../mc/core/world/block/AbstractBlock.java | 21 --------- .../main/java/mc/core/world/block/Block.java | 4 +- .../mc/core/network/proto_1_12_2/Crypter.java | 43 ------------------- 4 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 core/src/main/java/mc/core/nbt/Taggable.java delete mode 100644 proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/Crypter.java diff --git a/core/src/main/java/mc/core/nbt/Taggable.java b/core/src/main/java/mc/core/nbt/Taggable.java deleted file mode 100644 index 0e3a46c..0000000 --- a/core/src/main/java/mc/core/nbt/Taggable.java +++ /dev/null @@ -1,11 +0,0 @@ -package mc.core.nbt; - -import com.flowpowered.nbt.Tag; - -import java.util.stream.Stream; - -public interface Taggable { - Tag getTag(String name); - void setTag(Tag tag); - Stream> tagStream(); -} diff --git a/core/src/main/java/mc/core/world/block/AbstractBlock.java b/core/src/main/java/mc/core/world/block/AbstractBlock.java index b00b8af..6bf8445 100644 --- a/core/src/main/java/mc/core/world/block/AbstractBlock.java +++ b/core/src/main/java/mc/core/world/block/AbstractBlock.java @@ -1,13 +1,8 @@ package mc.core.world.block; -import com.flowpowered.nbt.Tag; import lombok.Getter; import lombok.Setter; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - public abstract class AbstractBlock implements Block { @Getter @Setter @@ -16,7 +11,6 @@ public abstract class AbstractBlock implements Block { private int light = 0; @Getter private final BlockType blockType; - private final Map> nbtTagsMap = new HashMap<>(); protected AbstractBlock(BlockType type) { this.blockType = type; @@ -28,19 +22,4 @@ public abstract class AbstractBlock implements Block { else if (light < 0) this.light = 0; else this.light = light; } - - @Override - public Tag getTag(String name) { - return nbtTagsMap.get(name); - } - - @Override - public void setTag(Tag tag) { - nbtTagsMap.put(tag.getName(), tag); - } - - @Override - public Stream> tagStream() { - return nbtTagsMap.values().stream(); - } } diff --git a/core/src/main/java/mc/core/world/block/Block.java b/core/src/main/java/mc/core/world/block/Block.java index b54a7d0..a23d3df 100644 --- a/core/src/main/java/mc/core/world/block/Block.java +++ b/core/src/main/java/mc/core/world/block/Block.java @@ -1,8 +1,6 @@ package mc.core.world.block; -import mc.core.nbt.Taggable; - -public interface Block extends Taggable{ +public interface Block { int getLight(); void setLight(int light); BlockType getBlockType(); diff --git a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/Crypter.java b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/Crypter.java deleted file mode 100644 index 7259f93..0000000 --- a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/Crypter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * DmitriyMX - * 2018-06-11 - */ -package mc.core.network.proto_1_12_2; - -import lombok.extern.slf4j.Slf4j; - -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.util.Random; - -@Slf4j -public class Crypter { - private static final Crypter instance = new Crypter(); - private KeyPair keyPair; - private byte[] verifyToken; - - public static KeyPair getKeyPair() { - if (instance.keyPair == null) { - try { - KeyPairGenerator keypairgenerator = KeyPairGenerator.getInstance("RSA"); - keypairgenerator.initialize(1024); - instance.keyPair = keypairgenerator.generateKeyPair(); - } catch (NoSuchAlgorithmException e) { - log.error("WTF?! Algorithm \"RSA\" not defined?!", e); - } - } - - return instance.keyPair; - } - - public static byte[] getVerifyToken() { - if (instance.verifyToken == null) { - instance.verifyToken = new byte[4]; - Random rand = new Random(); - rand.nextBytes(instance.verifyToken); - } - - return instance.verifyToken; - } -} From bc8c05dacc4e617ad4dabdefe1798b09129c934f Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 12:44:05 +0300 Subject: [PATCH 4/8] =?UTF-8?q?gradle:=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B0=20SonarQube?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/build.gradle b/build.gradle index 089e004..cd525cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,27 @@ +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath (group: 'org.sonarsource.scanner.gradle', name: 'sonarqube-gradle-plugin', version: '2.6.2') + } +} + +/** + * Проверка кода в SonarQube. + * Для запуска локальной проверки кода, используются следующий command line: + * gradle sonarqube \ + * -Dsonar.host.url=http://127.0.0.1:9000 + * -Dsonar.login= + * где + * - - сгенерированный токен учетки "сонара" + */ +plugins { + id "org.sonarqube" version "2.6.2" +} + allprojects { apply plugin: 'java' From 46413c4a0d93ca35b80c3e4f6545c3f26c33ded6 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 12:54:10 +0300 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20EntityLocation#clone()=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=BB=20null=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B5=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/mc/core/EntityLocation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/mc/core/EntityLocation.java b/core/src/main/java/mc/core/EntityLocation.java index 0b4e237..8e8fbdb 100644 --- a/core/src/main/java/mc/core/EntityLocation.java +++ b/core/src/main/java/mc/core/EntityLocation.java @@ -3,6 +3,7 @@ package mc.core; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.springframework.lang.Nullable; @NoArgsConstructor @AllArgsConstructor @@ -49,7 +50,7 @@ public class EntityLocation implements Cloneable { return (EntityLocation) super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); - return null; + return ZERO(); } } } From 217a329b5e81f2a7fdfad657b9b8ad016fc2d0f1 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 13:11:51 +0300 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20BlockLocation#clone()=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=BB=20null=20=D0=B2=20?= =?UTF-8?q?=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/mc/core/world/block/BlockLocation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/mc/core/world/block/BlockLocation.java b/core/src/main/java/mc/core/world/block/BlockLocation.java index 9ac33f0..ff6fd5f 100644 --- a/core/src/main/java/mc/core/world/block/BlockLocation.java +++ b/core/src/main/java/mc/core/world/block/BlockLocation.java @@ -26,7 +26,7 @@ public class BlockLocation implements Cloneable { return (BlockLocation) super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); - return null; + return ZERO(); } } } From 5897183561dc7005749626cc345821f76d07c62d Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 13:28:58 +0300 Subject: [PATCH 7/8] fix: remove unboxing --- core/src/main/java/mc/core/EntityLocation.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/mc/core/EntityLocation.java b/core/src/main/java/mc/core/EntityLocation.java index 8e8fbdb..735c50b 100644 --- a/core/src/main/java/mc/core/EntityLocation.java +++ b/core/src/main/java/mc/core/EntityLocation.java @@ -33,15 +33,15 @@ public class EntityLocation implements Cloneable { } public int getBlockX() { - return Double.valueOf(Math.floor(x)).intValue(); + return (int) Math.floor(x); } public int getBlockY() { - return Double.valueOf(Math.floor(y)).intValue(); + return (int) Math.floor(y); } public int getBlockZ() { - return Double.valueOf(Math.floor(z)).intValue(); + return (int) Math.floor(z); } @Override From fa5ef8c97c27fdec82e9707e8d9b0dd472fb144d Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 19 Nov 2018 13:37:22 +0300 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20SpawnPositionPacket=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../proto_1_12_2/packets/SpawnPositionPacket.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/SpawnPositionPacket.java b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/SpawnPositionPacket.java index 5264c7d..2b3eb6e 100644 --- a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/SpawnPositionPacket.java +++ b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/SpawnPositionPacket.java @@ -1,7 +1,3 @@ -/* - * DmitriyMX - * 2018-06-11 - */ package mc.core.network.proto_1_12_2.packets; import lombok.AllArgsConstructor; @@ -19,15 +15,10 @@ import mc.core.network.SCPacket; public class SpawnPositionPacket implements SCPacket { private EntityLocation location; - private int floor_double(double value) { - int i = (int)value; - return value < (double)i ? i - 1 : i; - } - private long location2long(EntityLocation entityLocation) { - return ((floor_double(entityLocation.getX()) & 0x3FFFFFF) << 38) - | ((floor_double(entityLocation.getY()) & 0xFFF) << 26) - | (floor_double(entityLocation.getZ()) & 0x3FFFFFF); + return (((long) entityLocation.getBlockX() & 0x3FFFFFF) << 38) + | (((long) entityLocation.getBlockY() & 0x0000FFF) << 26) + | ((long) entityLocation.getBlockZ() & 0x3FFFFFF); } @Override