diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 0f2d175..b1c6461 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,9 +5,14 @@
-
+
+
+
+
+
+
+
-
@@ -153,10 +158,10 @@
-
+
-
+
@@ -166,51 +171,51 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
diff --git a/pom.xml b/pom.xml
index 94a32af..3c23f5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
net.seanomik
tamablefoxes
- 1.5.2-SNAPSHOT
+ 1.5.4-SNAPSHOT
jar
Tamablefoxes
diff --git a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java
index c8a5a47..61c7fef 100644
--- a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java
+++ b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java
@@ -26,6 +26,7 @@ public class EntityTamableFox extends EntityFox {
private EntityLiving owner;
private UUID ownerUUID;
private FoxPathfinderGoalSit goalSit;
+ private String customName = "";
public EntityTamableFox(EntityTypes extends EntityFox> entitytypes, World world) {
super(entitytypes, world);
@@ -178,7 +179,9 @@ public class EntityTamableFox extends EntityFox {
this.tamed = tamed;
// Remove goals that are not needed when named, or defeats the purpose of taming
- untamedGoals.forEach(goal -> goalSelector.a(goal));
+ try {
+ untamedGoals.forEach(goal -> goalSelector.a(goal));
+ } catch (Exception e) {}
}
public EntityLiving getOwner() {
@@ -210,14 +213,24 @@ public class EntityTamableFox extends EntityFox {
}
}
+ // This is needed for the updateFoxVisual runnable to set the foxes name.
+ void setCustomName(String customName) {
+ this.customName = customName;
+ updateFoxVisual();
+ }
+
public void updateFoxVisual() {
new BukkitRunnable() {
@Override
public void run() {
goalSit.setSitting(sitting);
- if (tamed && owner != null && !hasCustomName() && Config.doesShowOwnerFoxName()) {
- getBukkitEntity().setCustomName(LanguageConfig.getOwnerInFoxNameFormat().replaceAll("%player%", owner.getName()));
+ if (tamed && owner != null && !customName.isEmpty()) {
+ if (Config.doesShowOwnerFoxName()) {
+ getBukkitEntity().setCustomName(LanguageConfig.getFoxNameFormat().replaceAll("%OWNER%", owner.getName()).replaceAll("%FOX_NAME%", customName));
+ } else {
+ getBukkitEntity().setCustomName(LanguageConfig.getFoxNameFormat().replaceAll("%FOX_NAME%", customName));
+ }
}
}
}.runTask(TamableFoxes.getPlugin());
diff --git a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java
index 9fd64ca..8300baa 100644
--- a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java
+++ b/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java
@@ -37,7 +37,10 @@ import java.util.stream.Collectors;
// @TODO:
/* @CHANGELOG (1.5.2):
- * Removed debug messages
+ * Code cleanup
+ * Updated old path finding goals
+ * Added a section in language.yml to customize how a foxes owner's name is displayed.
+ * Added a choice in the config.yml to disable the Anvil naming GUI so all foxes would have to be named by name tags.
*/
public final class TamableFoxes extends JavaPlugin implements Listener {
private static TamableFoxes plugin;
@@ -62,11 +65,13 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
Field field = EntityTypes.FOX.getClass().getDeclaredField("ba");
field.setAccessible(true);
- // Remove the final modifier from the "ba" variable
- Field fieldMutable = field.getClass().getDeclaredField("modifiers");
- fieldMutable.setAccessible(true);
- fieldMutable.set(field, fieldMutable.getInt(field) & ~Modifier.FINAL);
- fieldMutable.setAccessible(false);
+ // If the field is final, then make it non final
+ if ((field.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
+ Field fieldMutable = field.getClass().getDeclaredField("modifiers");
+ fieldMutable.setAccessible(true);
+ fieldMutable.set(field, fieldMutable.getInt(field) & ~Modifier.FINAL);
+ fieldMutable.setAccessible(false);
+ }
field.set(EntityTypes.FOX, (EntityTypes.b) (type, world) -> new EntityTamableFox(type, world));
@@ -74,7 +79,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
} catch (Exception e) {
- e.printStackTrace();
+ //e.printStackTrace();
getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
}
@@ -108,7 +113,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
}
@EventHandler
- public void onChunkLoad(ChunkLoadEvent event) {
+ public void onChunkLoad(ChunkLoadEvent event) { // Wait for all the entities to load.
Bukkit.getScheduler().runTaskLaterAsynchronously(this, ()-> {
spawnedFoxes.addAll(Utils.loadFoxesInChunk(event.getChunk()));
}, 5L);
@@ -149,7 +154,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) entity).getHandle();
// Check if its tamed but ignore it if the player is holding sweet berries for breeding or nametag for renaming
- if (tamableFox.isTamed() && tamableFox.getOwner() != null && itemHand.getType() != Material.SWEET_BERRIES && itemHand.getType() != Material.NAME_TAG) {
+ if (tamableFox.isTamed() && tamableFox.getOwner() != null && itemHand.getType() != Material.SWEET_BERRIES) {
if (tamableFox.getOwner().getUniqueID() == player.getUniqueId()) {
event.setCancelled(true);
if (player.isSneaking()) {
@@ -160,6 +165,13 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
if (itemHand.getAmount() == 1) player.getInventory().removeItem(itemHand);
else itemHand.setAmount(itemHand.getAmount() - 1);
}
+ } else if (itemHand.getType() == Material.NAME_TAG) {
+ if (itemHand.getAmount() == 1) player.getInventory().removeItem(itemHand);
+ else itemHand.setAmount(itemHand.getAmount() - 1);
+
+ tamableFox.setCustomName(handMeta.getDisplayName());
+
+ event.setCancelled(true);
} else {
tamableFox.toggleSitting();
}
@@ -179,7 +191,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
new AnvilGUI.Builder()
.onComplete((plr, text) -> { // Called when the inventory output slot is clicked
if (!text.equals("")) {
- tamableFox.getBukkitEntity().setCustomName(text);
+ tamableFox.setCustomName(text);
tamableFox.setCustomNameVisible(true);
plr.sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(text));
tamableFox.saveNbt();
@@ -187,7 +199,6 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
return AnvilGUI.Response.close();
})
- //.preventClose() // Prevents the inventory from being closed
.text("Fox name") // Sets the text the GUI should start with
.plugin(this) // Set the plugin instance
.open(player); // Opens the GUI for the player provided
diff --git a/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java b/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java
index f99ef4d..296325f 100644
--- a/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java
+++ b/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java
@@ -107,8 +107,8 @@ public class LanguageConfig extends YamlConfiguration {
return getConfig().getString("taming-chosen-name-perfect").replaceAll("%NAME%", chosen);
}
- public static String getOwnerInFoxNameFormat() {
- return getConfig().getString("owner-in-fox-name-format");
+ public static String getFoxNameFormat() {
+ return getConfig().getString("fox-name-format");
}
public static String getNoPermMessage() {
@@ -131,10 +131,6 @@ public class LanguageConfig extends YamlConfiguration {
public static String getReloadMessage() {
return getConfig().getString("reloaded-message");
}
-
- public static String getCreatedSQLDatabase() {
- return getConfig().getString("created-sql-foxes-database");
- }
}
\ No newline at end of file
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 4c538b5..5ced56a 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,7 +1,7 @@
# Config for Tamable Foxes
show-owner-in-fox-name: true
enable-taming-permission: true
-ask-for-name-after-taming: false
+ask-for-name-after-taming: true
tamed-behavior:
attack-wild-animals: true
\ No newline at end of file
diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml
index 4d4c114..af13e7c 100644
--- a/src/main/resources/language.yml
+++ b/src/main/resources/language.yml
@@ -7,7 +7,7 @@ saving-foxes-message: "Saving foxes."
taming-tamed-message: "You just tamed a wild fox!"
taming-asking-for-name-message: "What do you want to call it?"
taming-chosen-name-perfect: "%NAME% is perfect!"
-owner-in-fox-name-format: "%player%'s Fox"
+fox-name-format: "%FOX_NAME% (%OWNER%'s Fox)"
no-permission: "You do not have the permission for this command."
only-run-by-player: "Command can only be run from player state!"
diff --git a/target/classes/config.yml b/target/classes/config.yml
index 0741882..5ced56a 100644
--- a/target/classes/config.yml
+++ b/target/classes/config.yml
@@ -1,7 +1,7 @@
# Config for Tamable Foxes
show-owner-in-fox-name: true
-show-nametags: true
enable-taming-permission: true
+ask-for-name-after-taming: true
tamed-behavior:
attack-wild-animals: true
\ No newline at end of file
diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml
index a1035dc..e266104 100644
--- a/target/classes/plugin.yml
+++ b/target/classes/plugin.yml
@@ -1,5 +1,5 @@
name: Tamablefoxes
-version: 1.5.2-SNAPSHOT
+version: 1.5.4-SNAPSHOT
main: net.seanomik.tamablefoxes.TamableFoxes
api-version: 1.15
load: POSTWORLD
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
index 8f4c0a8..5caa166 100644
--- a/target/maven-archiver/pom.properties
+++ b/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Mon Jan 27 07:55:13 CST 2020
-version=1.5.2-SNAPSHOT
+#Sat Feb 01 12:07:47 CST 2020
+version=1.5.4-SNAPSHOT
groupId=net.seanomik
artifactId=tamablefoxes
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
index b641638..93cca77 100644
--- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -1,10 +1,10 @@
net\seanomik\tamablefoxes\EntityTamableFox.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.class
+net\seanomik\tamablefoxes\EntityTamableFox$1.class
net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.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