Add a check to see if the name is null.

Without this check I would get a null pointer when you attempt to tame a fox.
This commit is contained in:
SeanOMik 2020-01-27 18:41:18 -06:00
parent 9e64f9c6f9
commit a6408840b2
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
6 changed files with 67 additions and 88 deletions

View File

@ -4,6 +4,10 @@
<list default="true" id="dcab9632-7b1a-44d7-9283-be9b37640afc" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/Utils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/Utils.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst" beforeDir="false" afterPath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" beforeDir="false" afterPath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -51,7 +55,7 @@
<recent name="E:\TamableFoxesCustomEntity\src\main\resources" />
</key>
</component>
<component name="RunManager" selected="JAR Application.Spigot-1.15.1">
<component name="RunManager" selected="JAR Application.Spigot-1.15.2">
<configuration name="Paper-1.15.1" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/../../_TEST_SERVER_PAPER_1.15.1_/paper-62.jar" />
<option name="WORKING_DIRECTORY" value="D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.15.1_" />
@ -162,51 +166,51 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="794" y="418" width="356" height="203" key="Github.CreateGistDialog/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580081718270" />
<state width="1877" height="199" key="GridCell.Tab.0.bottom" timestamp="1580134668965">
<state width="1877" height="221" key="GridCell.Tab.0.bottom" timestamp="1580171814347">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.0.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="221" key="GridCell.Tab.0.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814347" />
<state width="1877" height="199" key="GridCell.Tab.0.bottom/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1580134668965" />
<state width="1877" height="199" key="GridCell.Tab.0.center" timestamp="1580134668964">
<state width="1877" height="221" key="GridCell.Tab.0.center" timestamp="1580171814347">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.0.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="221" key="GridCell.Tab.0.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814347" />
<state width="1877" height="199" key="GridCell.Tab.0.center/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1580134668964" />
<state width="1877" height="199" key="GridCell.Tab.0.left" timestamp="1580134668964">
<state width="1877" height="221" key="GridCell.Tab.0.left" timestamp="1580171814347">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.0.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="221" key="GridCell.Tab.0.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814347" />
<state width="1877" height="199" key="GridCell.Tab.0.left/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1580134668964" />
<state width="1877" height="199" key="GridCell.Tab.0.right" timestamp="1580134668964">
<state width="1877" height="221" key="GridCell.Tab.0.right" timestamp="1580171814347">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.0.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="221" key="GridCell.Tab.0.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814347" />
<state width="1877" height="199" key="GridCell.Tab.0.right/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1580134668964" />
<state width="1877" height="237" key="GridCell.Tab.1.bottom" timestamp="1580083439451">
<state width="1877" height="221" key="GridCell.Tab.1.bottom" timestamp="1580171814249">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.1.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="237" key="GridCell.Tab.1.center" timestamp="1580083439451">
<state width="1877" height="221" key="GridCell.Tab.1.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814249" />
<state width="1877" height="221" key="GridCell.Tab.1.center" timestamp="1580171814249">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.1.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="237" key="GridCell.Tab.1.left" timestamp="1580083439451">
<state width="1877" height="221" key="GridCell.Tab.1.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814249" />
<state width="1877" height="221" key="GridCell.Tab.1.left" timestamp="1580171814249">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.1.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="237" key="GridCell.Tab.1.right" timestamp="1580083439451">
<state width="1877" height="221" key="GridCell.Tab.1.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814249" />
<state width="1877" height="221" key="GridCell.Tab.1.right" timestamp="1580171814249">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="237" key="GridCell.Tab.1.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580083439451" />
<state width="1877" height="221" key="GridCell.Tab.1.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171814249" />
<state x="490" y="174" key="Maven.ArtifactSearchDialog" timestamp="1579373377880">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="498" height="446" key="SwitcherDM/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1579469022098" />
<state width="498" height="446" key="SwitcherDM/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1579705820492" />
<state x="656" y="343" key="com.intellij.ide.util.TipDialog" timestamp="1580132930429">
<state x="656" y="343" key="com.intellij.ide.util.TipDialog" timestamp="1580171129088">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="656" y="343" key="com.intellij.ide.util.TipDialog/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580063431581" />
<state x="656" y="343" key="com.intellij.ide.util.TipDialog/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580171129088" />
<state x="656" y="343" key="com.intellij.ide.util.TipDialog/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1580132930429" />
<state x="-781" y="188" width="1359" height="1028" key="dock-window-1" timestamp="1580017524734">
<screen x="-1920" y="0" width="1920" height="1040" />

12
pom.xml
View File

@ -40,7 +40,7 @@
</goals>
<configuration>
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.1_\plugins\TamableFoxes-MC-v1.15.1-v${project.version}.jar</outputFile>-->
<outputFile>C:\code\java\_TEST_SERVER_1.15.2_\plugins\TamableFoxes-MC-v1.15.X-v${project.version}.jar</outputFile>
<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.2_\plugins\TamableFoxes-MC-v1.15.X-v${project.version}.jar</outputFile>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
@ -71,19 +71,19 @@
</repositories>
<dependencies>
<!--<dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>-->
<dependency>
</dependency>
<!--<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<scope>system</scope>
<version>1.15.2</version>
<systemPath>${project.basedir}/../spigot-1.15.2.jar</systemPath>
</dependency>
</dependency>-->
<dependency>
<groupId>com.github.WesJD.AnvilGUI</groupId>
<artifactId>anvilgui</artifactId>

View File

@ -266,6 +266,29 @@ public class EntityTamableFox extends EntityFox {
}
}
public void save() {
NamespacedKey rootKey = new NamespacedKey(TamableFoxes.getPlugin(), "tamableFoxes");
CraftPersistentDataContainer persistentDataContainer = getBukkitEntity().getPersistentDataContainer();
PersistentDataContainer tamableFoxesData;
if (persistentDataContainer.has(rootKey, PersistentDataType.TAG_CONTAINER)) {
tamableFoxesData = persistentDataContainer.get(rootKey, PersistentDataType.TAG_CONTAINER);
} else {
tamableFoxesData = persistentDataContainer.getAdapterContext().newPersistentDataContainer();
}
NamespacedKey ownerKey = new NamespacedKey(TamableFoxes.getPlugin(), "owner");
NamespacedKey chosenNameKey = new NamespacedKey(TamableFoxes.getPlugin(), "chosenName");
NamespacedKey sittingKey = new NamespacedKey(TamableFoxes.getPlugin(), "sitting");
NamespacedKey sleepingKey = new NamespacedKey(TamableFoxes.getPlugin(), "sleeping");
tamableFoxesData.set(ownerKey, PersistentDataType.STRING, getOwner() == null ? "none" : getOwner().getUniqueID().toString());
if (getChosenName() != null && !getChosenName().isEmpty()) {
tamableFoxesData.set(chosenNameKey, PersistentDataType.STRING, getChosenName());
}
tamableFoxesData.set(sittingKey, PersistentDataType.BYTE, (byte) (isSitting() ? 1 : 0));
tamableFoxesData.set(sleepingKey, PersistentDataType.BYTE, (byte) (isSleeping() ? 1 : 0));
persistentDataContainer.set(rootKey, PersistentDataType.TAG_CONTAINER, tamableFoxesData);
}
// Used for all the nasty stuff below.
private static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
@ -468,26 +491,4 @@ public class EntityTamableFox extends EntityFox {
return groupdataentity;
}
public void save() {
NamespacedKey rootKey = new NamespacedKey(TamableFoxes.getPlugin(), "tamableFoxes");
CraftPersistentDataContainer persistentDataContainer = getBukkitEntity().getPersistentDataContainer();
PersistentDataContainer tamableFoxesData;
if (persistentDataContainer.has(rootKey, PersistentDataType.TAG_CONTAINER)) {
tamableFoxesData = persistentDataContainer.get(rootKey, PersistentDataType.TAG_CONTAINER);
} else {
tamableFoxesData = persistentDataContainer.getAdapterContext().newPersistentDataContainer();
}
NamespacedKey ownerKey = new NamespacedKey(TamableFoxes.getPlugin(), "owner");
NamespacedKey chosenNameKey = new NamespacedKey(TamableFoxes.getPlugin(), "chosenName");
NamespacedKey sittingKey = new NamespacedKey(TamableFoxes.getPlugin(), "sitting");
NamespacedKey sleepingKey = new NamespacedKey(TamableFoxes.getPlugin(), "sleeping");
tamableFoxesData.set(ownerKey, PersistentDataType.STRING, getOwner() == null ? "none" : getOwner().getUniqueID().toString());
tamableFoxesData.set(chosenNameKey, PersistentDataType.STRING, getChosenName());
tamableFoxesData.set(sittingKey, PersistentDataType.BYTE, (byte) (isSitting() ? 1 : 0));
tamableFoxesData.set(sleepingKey, PersistentDataType.BYTE, (byte) (isSleeping() ? 1 : 0));
persistentDataContainer.set(rootKey, PersistentDataType.TAG_CONTAINER, tamableFoxesData);
}
}

View File

@ -92,28 +92,6 @@ public class Utils {
}
}
public static Entity getEntity(UUID uuid) {
for (World world : Bukkit.getServer().getWorlds()) {
for (Entity entity : world.getEntities()) {
if (entity.getUniqueId().equals(uuid)) {
return entity;
}
}
}
return null;
}
public static Entity getEntity(Chunk chunk, UUID uuid) {
for (Entity entity : chunk.getEntities()) {
if (entity.getUniqueId().equals(uuid)) {
return entity;
}
}
return null;
}
public static List<EntityTamableFox> loadFoxesInChunk(Chunk chunk) {
return Arrays.stream(chunk.getEntities()).filter(Utils::isTamableFox)
.map(entity -> (EntityTamableFox) ((CraftEntity) entity).getHandle())

View File

@ -1,16 +1,14 @@
net\seanomik\tamablefoxes\EntityTamableFox.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtTarget.class
net\seanomik\tamablefoxes\io\LanguageConfig.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.class
net\seanomik\tamablefoxes\sqlite\SQLiteHandler.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalFollowOwner.class
net\seanomik\tamablefoxes\TamableFoxes.class
net\seanomik\tamablefoxes\EntityTamableFox$UpdateFoxRunnable.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalSit.class
net\seanomik\tamablefoxes\versions\version_1_15\command\CommandSpawnTamableFox.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.class
net\seanomik\tamablefoxes\versions\version_1_15\sqlite\SQLiteSetterGetter.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtTarget.class
net\seanomik\tamablefoxes\io\LanguageConfig.class
net\seanomik\tamablefoxes\Utils.class
net\seanomik\tamablefoxes\io\Config.class

View File

@ -1,15 +1,13 @@
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\sqlite\SQLiteHandler.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\Utils.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\EntityTamableFox.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\sqlite\SQLiteSetterGetter.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalSit.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\command\CommandSpawnTamableFox.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtTarget.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalFollowOwner.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\TamableFoxes.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\LanguageConfig.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.java
C:\code\java\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\Config.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\command\CommandSpawnTamableFox.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalSit.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\Utils.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalFollowOwner.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\TamableFoxes.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\Config.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtTarget.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\EntityTamableFox.java
D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\LanguageConfig.java