Fixed a bug that would cause foxes to not be tamed after a server reboot

Also tested on PaperMC and 1.15.2 (works)
This commit is contained in:
SeanOMik 2020-01-26 17:57:21 -06:00
parent ba5a373201
commit 6053e66e2d
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
21 changed files with 226 additions and 156 deletions

View File

@ -8,9 +8,11 @@
<outputRelativeToContentRoot value="true" />
<module name="TamableFoxesCustomEntity" />
<module name="tamableFoxes" />
<module name="TamableFoxes" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="TamableFoxes" target="1.8" />
<module name="tamableFoxes" target="1.8" />
<module name="TamableFoxesCustomEntity" target="1.8" />
</bytecodeTargetLevel>

View File

@ -2,18 +2,25 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="dcab9632-7b1a-44d7-9283-be9b37640afc" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/language.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<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/Config.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/io/Config.java" 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/TamableFoxes.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/command/CommandSpawnTamableFox.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/command/CommandSpawnTamableFox.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/sqlite/SQLiteSetterGetter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/sqlite/SQLiteSetterGetter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/plugin.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/plugin.yml" 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$/src/main/java/net/seanomik/tamablefoxes/command/CommandSpawnTamableFox.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/command/CommandSpawnTamableFox.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalFollowOwner.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalFollowOwner.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalHurtByTarget.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalHurtByTarget.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalMeleeAttack.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalMeleeAttack.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalPanic.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalPanic.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/pathfinding/FoxPathfinderGoalSit.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalSit.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/sqlite/SQLiteHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/sqlite/SQLiteHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/sqlite/SQLiteSetterGetter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/sqlite/SQLiteSetterGetter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/language.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/language.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/plugin.yml" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/plugin.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/maven-archiver/pom.properties" beforeDir="false" afterPath="$PROJECT_DIR$/target/maven-archiver/pom.properties" 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>
@ -49,7 +56,7 @@
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/io" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../DexunGUI" />
<property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.0" />
@ -64,12 +71,32 @@
</key>
</component>
<component name="RunManager" selected="JAR Application.Spigot-1.15.1">
<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_" />
<option name="ALTERNATIVE_JRE_PATH" />
<method v="2" />
</configuration>
<configuration name="Paper-1.15.2" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/../../_TEST_SERVER_PAPER_1.15.2_/paper-77.jar" />
<option name="PROGRAM_PARAMETERS" value="nogui" />
<option name="WORKING_DIRECTORY" value="D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.15.2_" />
<option name="ALTERNATIVE_JRE_PATH" />
<method v="2" />
</configuration>
<configuration name="Spigot-1.15.1" type="JarApplication">
<option name="JAR_PATH" value="$USER_HOME$/_TEST_SERVER_1.15.1_/spigot-1.15.1.jar" />
<option name="JAR_PATH" value="$PROJECT_DIR$/../../_TEST_SERVER_1.15.1_/spigot-1.15.1.jar" />
<option name="WORKING_DIRECTORY" value="D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.1_" />
<option name="ALTERNATIVE_JRE_PATH" />
<method v="2" />
</configuration>
<configuration name="Spigot-1.15.2" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/../../_TEST_SERVER_1.15.2_/spigot-1.15.2.jar" />
<option name="PROGRAM_PARAMETERS" value="nogui" />
<option name="WORKING_DIRECTORY" value="D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.2_" />
<option name="ALTERNATIVE_JRE_PATH" />
<method v="2" />
</configuration>
<configuration default="true" type="JarApplication">
<option name="JAR_PATH" value="$USER_HOME$/_TEST_SERVER_2_/spigot-1.15.1.jar" />
<option name="WORKING_DIRECTORY" value="D:\Code\java\spigotPlugins\_TEST_SERVER_2_" />
@ -104,6 +131,9 @@
</configuration>
<list>
<item itemvalue="JAR Application.Spigot-1.15.1" />
<item itemvalue="JAR Application.Spigot-1.15.2" />
<item itemvalue="JAR Application.Paper-1.15.1" />
<item itemvalue="JAR Application.Paper-1.15.2" />
<item itemvalue="Maven.TamableFoxesCustomEntity build" />
</list>
</component>
@ -133,61 +163,65 @@
<servers />
</component>
<component name="WindowStateProjectService">
<state x="414" y="174" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1580016134312">
<state x="414" y="174" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1580081956712">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="414" y="174" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580016134312" />
<state x="414" y="174" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580081956712" />
<state x="414" y="174" key="#com.intellij.execution.impl.EditConfigurationsDialog/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1579710781130" />
<state x="765" y="230" key="#com.intellij.ide.util.MemberChooser" timestamp="1579737522244">
<state x="765" y="230" key="#com.intellij.ide.util.MemberChooser" timestamp="1580081253579">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="765" y="230" key="#com.intellij.ide.util.MemberChooser/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1579737522244" />
<state x="765" y="230" key="#com.intellij.ide.util.MemberChooser/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580081253579" />
<state x="765" y="230" key="#com.intellij.ide.util.MemberChooser/1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1579708181770" />
<state x="740" y="274" key="FileChooserDialogImpl" timestamp="1579710595269">
<state x="740" y="274" key="FileChooserDialogImpl" timestamp="1580081289890">
<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="1579471488647" />
<state width="1877" height="234" key="GridCell.Tab.0.bottom" timestamp="1580022271776">
<state x="740" y="274" key="FileChooserDialogImpl/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580081289890" />
<state x="794" y="418" key="Github.CreateGistDialog" timestamp="1580081718270">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.0.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.0.center" timestamp="1580022271776">
<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="237" key="GridCell.Tab.0.bottom" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.0.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.0.left" timestamp="1580022271776">
<state width="1877" height="237" key="GridCell.Tab.0.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.0.center" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.0.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.0.right" timestamp="1580022271776">
<state width="1877" height="237" key="GridCell.Tab.0.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.0.left" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.0.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.1.bottom" timestamp="1580022271776">
<state width="1877" height="237" key="GridCell.Tab.0.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.0.right" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.1.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.1.center" timestamp="1580022271776">
<state width="1877" height="237" key="GridCell.Tab.0.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.1.bottom" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.1.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.1.left" timestamp="1580022271776">
<state width="1877" height="237" key="GridCell.Tab.1.bottom/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.1.center" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.1.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="234" key="GridCell.Tab.1.right" timestamp="1580022271776">
<state width="1877" height="237" key="GridCell.Tab.1.center/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.1.left" timestamp="1580082727030">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="234" key="GridCell.Tab.1.right/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580022271776" />
<state width="1877" height="237" key="GridCell.Tab.1.left/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580082727030" />
<state width="1877" height="237" key="GridCell.Tab.1.right" timestamp="1580082727030">
<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="1580082727030" />
<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="1579647313147">
<state x="656" y="343" key="com.intellij.ide.util.TipDialog" timestamp="1580063431581">
<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="1579647313147" />
<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="-781" y="188" width="1359" height="1028" key="dock-window-1" timestamp="1580017524734">
<screen x="-1920" y="0" width="1920" height="1040" />
</state>
@ -204,5 +238,9 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="342" y="189" key="new project wizard/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1579657428699" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1580063483764">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1580063483764" />
</component>
</project>

View File

@ -6,7 +6,7 @@
<groupId>net.seanomik</groupId>
<artifactId>tamablefoxes</artifactId>
<version>1.5-SNAPSHOT</version>
<version>1.5.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Tamablefoxes</name>
@ -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>E:\_TEST_SERVER_1.15.1_\plugins\${project.artifactId}-MC-1.15.1-${project.version}.jar</outputFile>-->
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.15.1_\plugins\TamableFoxes-MC-v1.15.2-v${project.version}.jar</outputFile>-->
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
@ -74,7 +74,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -3,7 +3,7 @@ package net.seanomik.tamablefoxes;
import com.mojang.datafixers.Dynamic;
import net.minecraft.server.v1_15_R1.*;
import net.seanomik.tamablefoxes.io.Config;
import net.seanomik.tamablefoxes.pathfinding.*;
import net.seanomik.tamablefoxes.versions.version_1_15.pathfinding.*;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.entity.Item;

View File

@ -1,11 +1,11 @@
package net.seanomik.tamablefoxes;
import net.minecraft.server.v1_15_R1.*;
import net.seanomik.tamablefoxes.command.CommandSpawnTamableFox;
import net.seanomik.tamablefoxes.versions.version_1_15.command.CommandSpawnTamableFox;
import net.seanomik.tamablefoxes.io.Config;
import net.seanomik.tamablefoxes.io.LanguageConfig;
import net.seanomik.tamablefoxes.sqlite.SQLiteHandler;
import net.seanomik.tamablefoxes.sqlite.SQLiteSetterGetter;
import net.seanomik.tamablefoxes.versions.version_1_15.sqlite.SQLiteSetterGetter;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.*;
import org.bukkit.Material;
@ -23,38 +23,44 @@ import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
// @TODO: Add language.yml
// Foxes will be loaded in as sitting, even if they weren't when the server was shutdown (sometimes)
// @TODO:
/* @CHANGELOG (1.5.1):
* Now loads on Linux
* Fixed a bug that would cause foxes to not be tamed after a server reboot
* Updated to 1.15.2
*/
public final class TamableFoxes extends JavaPlugin implements Listener {
private static TamableFoxes plugin;
public List<EntityTamableFox> spawnedFoxes = new ArrayList<>();
public SQLiteSetterGetter sqLiteSetterGetter = new SQLiteSetterGetter();
public SQLiteHandler sqLiteHandler;
public SQLiteHandler sqLiteHandler = new SQLiteHandler();
private boolean versionSupported = true;
@Override
public void onLoad() {
sqLiteHandler = new SQLiteHandler(getDataFolder());
plugin = this;
LanguageConfig.getConfig().saveDefault();
String version = Bukkit.getServer().getClass().getPackage().getName();
if (!version.equals("org.bukkit.craftbukkit.v1_15_R1")) {
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getUnsupportedMCVersionRegister());
versionSupported = false;
@ -98,8 +104,6 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
this.saveDefaultConfig();
getConfig().options().copyDefaults(true);
saveConfig();
spawnedFoxes = sqLiteSetterGetter.loadFoxes();
}
@Override
@ -113,6 +117,13 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
sqLiteSetterGetter.saveFoxes(spawnedFoxes);
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
Bukkit.getScheduler().runTaskLaterAsynchronously(this, ()-> {
spawnedFoxes.addAll(sqLiteSetterGetter.loadFoxes(event.getChunk()));
}, 5L);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
@ -140,6 +151,8 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
if (event.getHand() != EquipmentSlot.HAND) return;
player.sendMessage(entity.getUniqueId().toString());
ItemStack itemHand = player.getInventory().getItemInMainHand();
ItemMeta handMeta = itemHand.getItemMeta();
@ -258,7 +271,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
}
// Remove the fox from database
sqLiteSetterGetter.removeFox(tamableFox);
//sqLiteSetterGetter.removeFox(tamableFox);
}
public EntityTamableFox spawnTamableFox(Location loc, EntityFox.Type type) {

View File

@ -1,11 +1,16 @@
package net.seanomik.tamablefoxes;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.List;
import java.util.UUID;
public class Utils {
@ -83,4 +88,26 @@ public class Utils {
return null;
}
}
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;
}
}

View File

@ -1,24 +1,20 @@
package net.seanomik.tamablefoxes.sqlite;
import net.seanomik.tamablefoxes.TamableFoxes;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class SQLiteHandler {
private Connection connection;
private File dataFolder;
public SQLiteHandler(File dataFolder) {
this.dataFolder = dataFolder;
}
public void connect() {
try {
String url = "jdbc:sqlite:/" + dataFolder.getAbsolutePath() + "/foxes.db";
String url = "jdbc:sqlite:" + TamableFoxes.getPlugin().getDataFolder() + "/foxes.db";
connection = DriverManager.getConnection(url);
//Bukkit.getConsoleSender().sendMessage(TamableFoxes.getPrefix() + "Connection to SQLite has been established.");
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.command;
package net.seanomik.tamablefoxes.versions.version_1_15.command;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.seanomik.tamablefoxes.TamableFoxes;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.minecraft.server.v1_15_R1.*;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.minecraft.server.v1_15_R1.*;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.minecraft.server.v1_15_R1.EntityLiving;
import net.minecraft.server.v1_15_R1.PathfinderGoalMeleeAttack;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.minecraft.server.v1_15_R1.EntityLiving;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.minecraft.server.v1_15_R1.EntityLiving;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.minecraft.server.v1_15_R1.EntityFox;
import net.minecraft.server.v1_15_R1.PathfinderGoalPanic;

View File

@ -1,4 +1,4 @@
package net.seanomik.tamablefoxes.pathfinding;
package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.minecraft.server.v1_15_R1.EntityLiving;

View File

@ -1,12 +1,17 @@
package net.seanomik.tamablefoxes.sqlite;
package net.seanomik.tamablefoxes.versions.version_1_15.sqlite;
import net.minecraft.server.v1_15_R1.EntityLiving;
import net.seanomik.tamablefoxes.EntityTamableFox;
import net.seanomik.tamablefoxes.TamableFoxes;
import net.seanomik.tamablefoxes.Utils;
import net.seanomik.tamablefoxes.io.LanguageConfig;
import net.seanomik.tamablefoxes.sqlite.SQLiteHandler;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
@ -14,6 +19,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
// @TODO: Use try-with-resource instead of try-catch-finally
public class SQLiteSetterGetter {
public static TamableFoxes plugin;
public static SQLiteHandler sqLiteHandler;
@ -39,17 +46,13 @@ public class SQLiteSetterGetter {
PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(foxesTable);
statement.executeUpdate();
plugin.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + LanguageConfig.getCreatedSQLDatabase());
plugin.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getCreatedSQLDatabase());
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (sqLiteHandler.getConnection() != null) {
try {
sqLiteHandler.getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteHandler.closeConnection();
}
}
}
@ -91,11 +94,7 @@ public class SQLiteSetterGetter {
e.printStackTrace();
} finally {
if (sqLiteHandler.getConnection() != null) {
try {
sqLiteHandler.getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteHandler.closeConnection();
}
}
}
@ -108,30 +107,38 @@ public class SQLiteSetterGetter {
}
}
public List<EntityTamableFox> loadFoxes() {
public List<EntityTamableFox> loadFoxes(Chunk chunk) {
plugin = TamableFoxes.getPlugin(TamableFoxes.class);
List<UUID> toRemoveLater = new ArrayList<>();
// If there are no foxes then don't even start
List<EntityTamableFox> foxesInChunk = new ArrayList<>();
for (Entity entity : chunk.getEntities()) {
if (Utils.isTamableFox(entity)) {
foxesInChunk.add((EntityTamableFox) ((CraftEntity) entity).getHandle());
}
}
if (foxesInChunk.size() == 0) {
return new ArrayList<>();
}
try {
sqLiteHandler.connect();
PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement("SELECT * FROM foxes");
ResultSet results = statement.executeQuery();
List<EntityTamableFox> spawnedFoxes = new ArrayList<>();
while (results.next()) { // Loop through each row
UUID entityUUID = UUID.fromString(results.getString("ENTITY_UUID"));
for (EntityTamableFox tamableFox : foxesInChunk) {
PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement("SELECT * FROM foxes WHERE ENTITY_UUID=?");
statement.setString(1, tamableFox.getUniqueID().toString());
ResultSet results = statement.executeQuery();
if (results.next()) {
String ownerUUIDString = results.getString("OWNER_UUID");
String name = results.getString("NAME");
boolean sitting = results.getInt("SITTING") == 1;
boolean sleeping = results.getInt("SLEEPING") == 1;
// If the entity is null, it doesn't exist anymore so remove it from database
if (plugin.getServer().getEntity(entityUUID) == null) {
toRemoveLater.add(entityUUID);
continue;
}
boolean tamed = false;
EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) plugin.getServer().getEntity(entityUUID)).getHandle();
if (!ownerUUIDString.equals("none")) {
tamed = true;
@ -146,33 +153,26 @@ public class SQLiteSetterGetter {
tamableFox.setChosenName(name);
}
// Fox may spawn standing if the server was closed while it was sitting.
if (sitting) {
if (tamed) {
if (sitting && tamed) {
tamableFox.setHardSitting(true);
}
} else if (sleeping) {
tamableFox.setSleeping(true);
} else { // Avoid the foxes getting stuck sitting down.
tamableFox.setSitting(false);
tamableFox.setSleeping(false);
}
spawnedFoxes.add(tamableFox);
}
}
return spawnedFoxes;
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (sqLiteHandler.getConnection() != null) {
try {
sqLiteHandler.getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
}
// Remove those to remove later UUIDs
for (UUID uuid : toRemoveLater) {
removeFox(uuid);
sqLiteHandler.closeConnection();
}
}
return null;
@ -189,11 +189,7 @@ public class SQLiteSetterGetter {
e.printStackTrace();
} finally {
if (sqLiteHandler.getConnection() != null) {
try {
sqLiteHandler.getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteHandler.closeConnection();
}
}
}

View File

@ -1,5 +1,5 @@
unsupported-mc-version-not-registering: "ERROR: This plugin version only supports 1.15.1! Not registering entity!"
unsupported-mc-version-disabling: "This plugin version only supports 1.15.1! Disabling plugin!"
unsupported-mc-version-not-registering: "ERROR: This plugin version only supports Spigot 1.15.1, currently not Paper! Not registering entity!"
unsupported-mc-version-disabling: "This plugin version only supports Spigot 1.15.1, currently not Paper! Disabling plugin!"
success-replaced-entity: "Replaced tamable fox entity!"
error-to-replaced-entity: "Failed to replace tamable fox entity!"

View File

@ -1,10 +1,8 @@
name: Tamablefoxes
version: 1.5-SNAPSHOT
version: 1.5.1-SNAPSHOT
main: net.seanomik.tamablefoxes.TamableFoxes
api-version: 1.15
#load: STARTUP
load: POSTWORLD
#load: STARTUP
description: Adds tamable foxes to Minecraft!
commands:

View File

@ -1,5 +1,5 @@
#Generated by Maven
#Wed Jan 22 08:36:01 CST 2020
version=1.5-SNAPSHOT
#Sun Jan 26 14:51:19 CST 2020
version=1.5.1-SNAPSHOT
groupId=net.seanomik
artifactId=tamablefoxes

View File

@ -1,16 +1,16 @@
net\seanomik\tamablefoxes\EntityTamableFox.class
net\seanomik\tamablefoxes\command\CommandSpawnTamableFox.class
net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalSit.class
net\seanomik\tamablefoxes\sqlite\SQLiteSetterGetter.class
net\seanomik\tamablefoxes\io\LanguageConfig.class
net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalPanic.class
net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalOwnerHurtTarget.class
net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalMeleeAttack.class
net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.class
net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalFollowOwner.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.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\pathfinding\FoxPathfinderGoalHurtByTarget.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\pathfinding\FoxPathfinderGoalOwnerHurtTarget.class
net\seanomik\tamablefoxes\io\LanguageConfig.class
net\seanomik\tamablefoxes\versions\version_1_15\sqlite\SQLiteSetterGetter.class
net\seanomik\tamablefoxes\Utils.class
net\seanomik\tamablefoxes\io\Config.class

View File

@ -1,15 +1,15 @@
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalHurtByTarget.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\command\CommandSpawnTamableFox.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\TamableFoxes.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\Config.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\Utils.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalSit.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\EntityTamableFox.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalOwnerHurtTarget.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\sqlite\SQLiteHandler.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\sqlite\SQLiteSetterGetter.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalFollowOwner.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalMeleeAttack.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\pathfinding\FoxPathfinderGoalPanic.java
D:\Code\java\spigotPlugins\myPlugins\GitTamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\LanguageConfig.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\sqlite\SQLiteHandler.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\sqlite\SQLiteSetterGetter.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