Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit bcca2a4

Browse files
committed
[v2.0.9-jv8]
1 parent 6c071ff commit bcca2a4

File tree

9 files changed

+96
-40
lines changed

9 files changed

+96
-40
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.github.yuttyann</groupId>
44
<artifactId>ScriptBlockPlus</artifactId>
5-
<version>2.0.8</version>
5+
<version>2.0.9</version>
66

77
<name>ScriptBlockPlus</name>
88
<url>https://github.com/yuttyann/ScriptBlockPlus</url>

src/main/java/com/github/yuttyann/scriptblockplus/file/json/BaseJson.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import com.github.yuttyann.scriptblockplus.file.json.builder.BlockCoordsDeserializer;
2424
import com.github.yuttyann.scriptblockplus.file.json.builder.BlockCoordsSerializer;
2525
import com.github.yuttyann.scriptblockplus.file.json.builder.FieldExclusion;
26+
import com.github.yuttyann.scriptblockplus.file.json.builder.ScriptKeyDeserializer;
27+
import com.github.yuttyann.scriptblockplus.file.json.builder.ScriptKeySerializer;
28+
import com.github.yuttyann.scriptblockplus.script.ScriptKey;
2629
import com.github.yuttyann.scriptblockplus.utils.collection.IntMap;
2730
import com.github.yuttyann.scriptblockplus.utils.collection.IntHashMap;
2831
import com.github.yuttyann.scriptblockplus.utils.unmodifiable.UnmodifiableBlockCoords;
@@ -116,6 +119,8 @@ public enum Status {
116119
b.serializeNulls();
117120
b.setPrettyPrinting();
118121
b.setExclusionStrategies(new FieldExclusion());
122+
b.registerTypeAdapter(ScriptKey.class, new ScriptKeySerializer());
123+
b.registerTypeAdapter(ScriptKey.class, new ScriptKeyDeserializer());
119124
b.registerTypeAdapter(BlockCoords.class, new BlockCoordsSerializer());
120125
b.registerTypeAdapter(BlockCoords.class, new BlockCoordsDeserializer());
121126
b.registerTypeAdapter(UnmodifiableBlockCoords.class, new BlockCoordsSerializer());
@@ -355,7 +360,7 @@ public final Status getStatus() {
355360
* @return {@link boolean} - 削除を行う場合は{@code true}
356361
*/
357362
protected boolean isTemporary() {
358-
return true;
363+
return false;
359364
}
360365

361366
/**
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* ScriptBlockPlus - Allow you to add script to any blocks.
3+
* Copyright (C) 2021 yuttyann44581
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by the Free Software Foundation,
7+
* either version 3 of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
* See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program.
14+
* If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
package com.github.yuttyann.scriptblockplus.file.json.builder;
17+
18+
import java.lang.reflect.Type;
19+
20+
import com.github.yuttyann.scriptblockplus.script.ScriptKey;
21+
import com.google.gson.JsonDeserializationContext;
22+
import com.google.gson.JsonDeserializer;
23+
import com.google.gson.JsonElement;
24+
import com.google.gson.JsonObject;
25+
import com.google.gson.JsonParseException;
26+
27+
import org.jetbrains.annotations.NotNull;
28+
29+
/**
30+
* ScriptBlockPlus ScriptKeyDeserializer クラス
31+
* @author yuttyann44581
32+
*/
33+
public class ScriptKeyDeserializer implements JsonDeserializer<ScriptKey> {
34+
35+
@Override
36+
@NotNull
37+
public ScriptKey deserialize(@NotNull JsonElement json, @NotNull Type typeOfT, @NotNull JsonDeserializationContext context) throws JsonParseException {
38+
if (json.isJsonObject()) {
39+
JsonObject jsonObject = json.getAsJsonObject();
40+
if (!jsonObject.has("name")) {
41+
return ScriptKey.INTERACT;
42+
}
43+
return ScriptKey.valueOf(jsonObject.get("name").getAsString());
44+
} else {
45+
return ScriptKey.valueOf(json.getAsString());
46+
}
47+
}
48+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* ScriptBlockPlus - Allow you to add script to any blocks.
3+
* Copyright (C) 2021 yuttyann44581
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by the Free Software Foundation,
7+
* either version 3 of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
* See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program.
14+
* If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
package com.github.yuttyann.scriptblockplus.file.json.builder;
17+
18+
import java.lang.reflect.Type;
19+
20+
import com.github.yuttyann.scriptblockplus.script.ScriptKey;
21+
import com.google.gson.JsonElement;
22+
import com.google.gson.JsonSerializationContext;
23+
import com.google.gson.JsonSerializer;
24+
25+
import org.jetbrains.annotations.NotNull;
26+
27+
/**
28+
* ScriptBlockPlus ScriptKeySerializer クラス
29+
* @author yuttyann44581
30+
*/
31+
public class ScriptKeySerializer implements JsonSerializer<ScriptKey> {
32+
33+
@Override
34+
@NotNull
35+
public JsonElement serialize(@NotNull ScriptKey scriptKey, @NotNull Type typeOfSrc, @NotNull JsonSerializationContext context) {
36+
return context.serialize(scriptKey.toString());
37+
}
38+
}

src/main/java/com/github/yuttyann/scriptblockplus/file/json/derived/BlockScriptJson.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ protected BlockScriptJson(@NotNull ScriptKey scriptKey) {
4444
super(scriptKey.getName());
4545
}
4646

47-
@Override
48-
protected boolean isTemporary() {
49-
return false;
50-
}
51-
5247
@Override
5348
protected boolean isCacheFileExists() {
5449
return false;
@@ -62,7 +57,7 @@ public ScriptKey getScriptKey() {
6257
@Override
6358
@NotNull
6459
protected BlockScript newInstance() {
65-
return new BlockScript(getScriptKey());
60+
return new BlockScript();
6661
}
6762

6863
@NotNull

src/main/java/com/github/yuttyann/scriptblockplus/file/json/derived/PlayerCountJson.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ protected PlayerCountJson(@NotNull UUID uuid) {
4747
super(uuid.toString());
4848
}
4949

50-
@Override
51-
protected boolean isTemporary() {
52-
return false;
53-
}
54-
5550
@Override
5651
@NotNull
5752
protected PlayerCount newInstance(@NotNull ScriptKey scriptKey, @NotNull BlockCoords location) {

src/main/java/com/github/yuttyann/scriptblockplus/file/json/derived/PlayerTempJson.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ protected PlayerTempJson(@NotNull UUID uuid) {
4747
super(uuid.toString());
4848
}
4949

50-
@Override
51-
protected boolean isTemporary() {
52-
return false;
53-
}
54-
5550
@Override
5651
@NotNull
5752
protected PlayerTemp newInstance() {

src/main/java/com/github/yuttyann/scriptblockplus/file/json/element/BlockScript.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,20 @@
1717

1818
import com.github.yuttyann.scriptblockplus.BlockCoords;
1919
import com.github.yuttyann.scriptblockplus.file.json.BaseElement;
20-
import com.github.yuttyann.scriptblockplus.file.json.annotation.Alternate;
21-
import com.github.yuttyann.scriptblockplus.script.ScriptKey;
2220
import com.google.gson.annotations.SerializedName;
2321
import org.jetbrains.annotations.NotNull;
2422

2523
import java.util.HashMap;
24+
import java.util.Map;
2625

2726
/**
2827
* ScriptBlockPlus BlockScript クラス
2928
* @author yuttyann44581
3029
*/
3130
public class BlockScript extends BaseElement {
3231

33-
@Alternate("scripttype")
34-
@SerializedName(value = "scriptkey", alternate = { "scripttype" })
35-
private final ScriptKey scriptKey;
36-
3732
@SerializedName("scripts")
38-
private final HashMap<BlockCoords, ScriptParam> scripts = new HashMap<>();
39-
40-
public BlockScript(@NotNull ScriptKey scriptKey) {
41-
this.scriptKey = scriptKey;
42-
}
43-
44-
@NotNull
45-
public ScriptKey getScriptKey() {
46-
return scriptKey;
47-
}
33+
private final Map<BlockCoords, ScriptParam> scripts = new HashMap<>();
4834

4935
public boolean has(@NotNull BlockCoords blockCoords) {
5036
ScriptParam scriptParam = scripts.get(blockCoords);

src/main/java/com/github/yuttyann/scriptblockplus/script/ScriptKey.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package com.github.yuttyann.scriptblockplus.script;
1717

18-
import com.github.yuttyann.scriptblockplus.file.json.annotation.Exclude;
1918
import com.github.yuttyann.scriptblockplus.utils.StreamUtils;
20-
import com.google.gson.annotations.SerializedName;
2119

2220
import org.jetbrains.annotations.NotNull;
2321
import org.jetbrains.annotations.Nullable;
@@ -42,13 +40,9 @@ public final class ScriptKey implements Comparable<ScriptKey>, Serializable {
4240
public static final ScriptKey WALK = new ScriptKey("walk");
4341
public static final ScriptKey HIT = new ScriptKey("hit");
4442

45-
@Exclude
4643
private final String lowerName;
47-
48-
@SerializedName("name")
4944
private final String upperName;
5045

51-
@SerializedName("ordinal")
5246
private final int ordinal;
5347

5448
/**

0 commit comments

Comments
 (0)