Skip to content

Commit

Permalink
v0.0.8 - Already tamed wolves can become a Dog by interacting with th…
Browse files Browse the repository at this point in the history
…em, dogs can be freed, options for only showing the nametag when hovering as well as option to disable the cross-world teleporting.
  • Loading branch information
Fido2603 committed Aug 26, 2019
1 parent 4db2999 commit 15960b6
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 39 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ Tamed wolves but at least 10x better
* Automatically make newly bred Wolves into a Dog.
* Config option for killing players for XP.
* Configurables all the way from the sound to the messages displayed (excluding error messages for now...)
* Add a way to return your Dog to the wild, without having to kill it (less violence <3).
* The ability to add currently existing Tamed Wolves to the MyDog system, and register them as new Dogs.

**Resources:**
* Resource page on [Spigot](https://www.spigotmc.org/resources/mydog.70260/).
* Project page on [Bukkit](https://dev.bukkit.org/projects/mydog).

**TODO Feature-list:**
* Add inventory to Dogs, so they can wear armor and take less damage.
* Try to hide the nametag, and only show on hover, if possible.
* Config with customizable experience values for entities.
* Add currently existing Tamed Wolves to the MyDog system, and register them as new Dogs.
* Add a way to return your Dog to the wild, without having to kill it (less violence <3).

**Permissions:**
```YAML
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>dk.fido2603</groupId>
<artifactId>mydog</artifactId>
<version>0.0.7</version>
<version>0.0.8</version>
<name>MyDog</name>
<description>Tamed wolves but at least 10x better!</description>
<url>https://github.com/DoggyCraftDK/MyDog</url>
Expand Down
56 changes: 54 additions & 2 deletions src/dk/fido2603/mydog/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ else if ((args.length == 2) && (player != null))

return true;
}
if (((args[0].equalsIgnoreCase("free")) || (args[0].equalsIgnoreCase("setfree"))) && (player != null))
{
if ((!player.isOp()) && (!MyDog.getPermissionsManager().hasPermission(player, "mydog.free")))
{
return false;
}

commandDogFree(sender, args[1]);

return true;
}
if (((args[0].equalsIgnoreCase("stats")) || (args[0].equalsIgnoreCase("info"))) && (player != null))
{
if ((!player.isOp()) && (!MyDog.getPermissionsManager().hasPermission(player, "mydog.stats")))
Expand Down Expand Up @@ -211,6 +222,10 @@ private boolean commandList(CommandSender sender)
{
sender.sendMessage(ChatColor.AQUA + "/mydog putdown <id>" + ChatColor.WHITE + " - Get rid of a Dog you own");
}
if ((sender.isOp()) || (MyDog.getPermissionsManager().hasPermission(player, "mydog.free")))
{
sender.sendMessage(ChatColor.AQUA + "/mydog free <id>" + ChatColor.WHITE + " - Set one of your Dogs free!");
}
if ((sender.isOp()) || (MyDog.getPermissionsManager().hasPermission(player, "mydog.comehere")))
{
sender.sendMessage(ChatColor.AQUA + "/mydog comehere <id>" + ChatColor.WHITE + " - Forces your Dog to teleport to your location");
Expand Down Expand Up @@ -270,7 +285,7 @@ private boolean commandDogRename(CommandSender sender, String[] args)
return false;
}

sender.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "[" + plugin.getChatPrefix() + "] " + ChatColor.RESET + ChatColor.AQUA + "From now on, I will call you " + dog.getDogName() + ChatColor.RESET + ChatColor.AQUA + "!");
sender.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "[" + plugin.getChatPrefix() + "] " + ChatColor.RESET + ChatColor.AQUA + "From now on, I will call you " + dog.getDogColor() + dog.getDogName() + ChatColor.RESET + ChatColor.AQUA + "!");

return true;
}
Expand Down Expand Up @@ -298,6 +313,35 @@ private boolean commandDogPutdown(CommandSender sender, String dogIdentifier)
return true;
}

private boolean commandDogFree(CommandSender sender, String dogIdentifier)
{
Dog dog = MyDog.getDogManager().getDog(dogIdentifier, ((Player) sender).getUniqueId());
if (dog == null)
{
sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + plugin.getChatPrefix() + "] " + ChatColor.RESET + ChatColor.RED + "Could not find a Dog with that ID! Check /mydog dogs");
return false;
}

sender.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "[" + plugin.getChatPrefix() + "] " + ChatColor.RESET + ChatColor.AQUA + "It was great having you here, " + dog.getDogColor() + dog.getDogName() + ChatColor.RESET + ChatColor.AQUA + "...");

Wolf wolf = (Wolf) plugin.getServer().getEntity(dog.getDogId());

if (wolf != null)
{
wolf.setCustomName("");
wolf.setCustomNameVisible(false);
if (wolf.isSitting())
{
wolf.setSitting(false);
}
wolf.setTamed(false);
}

MyDog.getDogManager().removeDog(dog.getDogId());

return true;
}

private boolean commandDogStats(CommandSender sender, String dogIdentifier)
{
Dog dog = MyDog.getDogManager().getDog(dogIdentifier, ((Player) sender).getUniqueId());
Expand Down Expand Up @@ -574,14 +618,22 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String alia
{
arg1.add("info");
}
if (player == null || (player.isOp() || MyDog.getPermissionsManager().hasPermission(player, "mydog.free")))
{
arg1.add("free");
}
if (player == null || (player.isOp() || MyDog.getPermissionsManager().hasPermission(player, "mydog.rename")))
{
arg1.add("rename");
}
Iterable<String> FIRST_ARGUMENTS = arg1;
StringUtil.copyPartialMatches(args[0], FIRST_ARGUMENTS, result);
}
else if (args.length == 2)
{
List<String> arg2 = new ArrayList<String>();

if (player != null && (args[0].equalsIgnoreCase("putdown") || args[0].equalsIgnoreCase("comehere") || args[0].equalsIgnoreCase("rename") || args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("kill") || args[0].equalsIgnoreCase("stats")))
if (player != null && (args[0].equalsIgnoreCase("putdown") || args[0].equalsIgnoreCase("comehere") || args[0].equalsIgnoreCase("free") || args[0].equalsIgnoreCase("setfree") || args[0].equalsIgnoreCase("rename") || args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("kill") || args[0].equalsIgnoreCase("stats")))
{
List<Dog> dogs = MyDog.getDogManager().getDogs(player.getUniqueId());
for (Dog dog : dogs)
Expand Down
96 changes: 92 additions & 4 deletions src/dk/fido2603/mydog/DogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DogManager
private FileConfiguration dogsConfig = null;
private File dogsConfigFile = null;
private Random random = new Random();
private long lastSaveTime = 0L;
private long lastSaveTime = 0L;

DogManager(MyDog plugin)
{
Expand Down Expand Up @@ -104,6 +104,67 @@ public Dog(Wolf dog, Player dogOwner, Integer dogUID)
saveTimed();
}

// For new, already-tamed dogs with old data
public Dog(Wolf dog, Player dogOwner, String customName, DyeColor collarColorImport, Integer dogUID)
{
// The UUID of the Dog
this.dogId = dog.getUniqueId();

// The UUID of the Dog's owner (Player)
this.dogOwnerId = dogOwner.getUniqueId();
dogsConfig.set(dogId.toString() + ".Owner", dogOwnerId.toString());

// Generate an ID for the Dog
this.dogIdentifier = dogUID;
dogsConfig.set(dogId.toString() + ".ID", dogIdentifier);

// Generate a new name for the Dog
if (customName == null || customName.isEmpty())
{
this.dogName = newDogName();
}
else
{
this.dogName = customName;
}
dogsConfig.set(dogId.toString() + ".Name", dogName);

// Generate a random Collar Color and set the Dog's Color
if (collarColorImport == null)
{
if (plugin.randomCollarColor)
{
dog.setCollarColor(ColorUtils.randomDyeColor());
}
}

this.collarColor = dog.getCollarColor();
this.nameColor = ColorUtils.getChatColorFromDyeColor(collarColor);
dogsConfig.set(dogId.toString() + ".NameChatColor", nameColor.name());

// Save the Dog's last seen location
this.location = dog.getLocation();
dogsConfig.set(dogId.toString() + ".LastSeen.World", location.getWorld().getName());
dogsConfig.set(dogId.toString() + ".LastSeen.X", location.getX());
dogsConfig.set(dogId.toString() + ".LastSeen.Y", location.getY());
dogsConfig.set(dogId.toString() + ".LastSeen.Z", location.getZ());

// Give the Dog a level
if (plugin.useLevels)
{
this.level = 1;
dogsConfig.set(dogId.toString() + ".Level.Level", level);
this.experience = 0;
dogsConfig.set(dogId.toString() + ".Level.Experience", experience);
}

// Set the current time as the Dog's birthday
this.birthday = new Date();
dogsConfig.set(dogId.toString() + ".Birthday", formatter.format(birthday));

saveTimed();
}

// For old, already created, dogs
public Dog(Wolf dog)
{
Expand Down Expand Up @@ -221,7 +282,14 @@ public boolean setDogColor(DyeColor color)

plugin.logDebug("Setting customName to: " + nameColor + dogName);
dog.setCustomName(nameColor + dogName);
dog.setCustomNameVisible(true);
if (plugin.onlyShowNametagOnHover)
{
dog.setCustomNameVisible(false);
}
else
{
dog.setCustomNameVisible(true);
}
}
saveTimed();
return true;
Expand Down Expand Up @@ -253,7 +321,14 @@ public boolean setDogName(String name)

plugin.logDebug("Setting customName to: " + nameColor + dogName);
dog.setCustomName(nameColor + dogName);
dog.setCustomNameVisible(true);
if (plugin.onlyShowNametagOnHover)
{
dog.setCustomNameVisible(false);
}
else
{
dog.setCustomNameVisible(true);
}
}
saveTimed();
return true;
Expand Down Expand Up @@ -400,7 +475,14 @@ public boolean setDogCustomName()
{
plugin.logDebug("Setting customName to: " + nameColor + dogName);
dog.setCustomName(nameColor + dogName);
dog.setCustomNameVisible(true);
if (plugin.onlyShowNametagOnHover)
{
dog.setCustomNameVisible(false);
}
else
{
dog.setCustomNameVisible(true);
}
plugin.logDebug("Returning true!");
return true;
}
Expand Down Expand Up @@ -520,6 +602,7 @@ public void load()

public void save()
{
this.lastSaveTime = System.currentTimeMillis();
if ((this.dogsConfig == null) || (this.dogsConfigFile == null))
{
return;
Expand Down Expand Up @@ -588,6 +671,11 @@ public Dog newDog(Wolf dog, Player dogOwner) {
return new Dog(dog, dogOwner, dogID);
}

public Dog newDog(Wolf dog, Player dogOwner, String customName, DyeColor collarColor) {
Integer dogID = generateNewId(dogOwner.getUniqueId());
return new Dog(dog, dogOwner, customName, collarColor, dogID);
}

public Dog getDog(UUID dogId)
{
if (dogsConfig.contains(dogId.toString()))
Expand Down
8 changes: 7 additions & 1 deletion src/dk/fido2603/mydog/MyDog.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class MyDog extends JavaPlugin
public static Server server = null;
public boolean debug = false;
public boolean instantSave = false;
public boolean teleportOnWorldChange = true;
public boolean onlyShowNametagOnHover = false;

public boolean allowPlayerKillExp = true;
public boolean allowNametagRename = true;
Expand Down Expand Up @@ -205,6 +207,8 @@ public void loadSettings()
this.instantSave = config.getBoolean("Settings.InstantSaveConfig", false);
this.randomCollarColor = config.getBoolean("DogSettings.RandomCollarColor", true);
this.useLevels = config.getBoolean("DogSettings.UseLevels", true);
this.teleportOnWorldChange = config.getBoolean("DogSettings.TeleportOnWorldChange", true);
this.onlyShowNametagOnHover = config.getBoolean("DogSettings.OnlyShowNametagOnHover", false);
this.allowPlayerKillExp = config.getBoolean("DogSettings.AllowPlayerKillExp", true);
this.allowNametagRename = config.getBoolean("DogSettings.AllowNametagRename", true);
if (config.contains("DogSettings.DogNames"))
Expand Down Expand Up @@ -266,6 +270,8 @@ public void saveSettings()
config.set("Settings.InstantSaveConfig", Boolean.valueOf(this.instantSave));
config.set("DogSettings.RandomCollarColor", this.randomCollarColor);
config.set("DogSettings.UseLevels", this.useLevels);
config.set("DogSettings.TeleportOnWorldChange", this.teleportOnWorldChange);
config.set("DogSettings.OnlyShowNametagOnHover", this.onlyShowNametagOnHover);
config.set("DogSettings.AllowPlayerKillExp", this.allowPlayerKillExp);
config.set("DogSettings.AllowNametagRename", this.allowNametagRename);
config.set("DogSettings.DogNames", this.dogNames);
Expand All @@ -282,7 +288,7 @@ public void saveSettings()
// Messages and sounds
config.set("PlayerInteraction.LevelUpSound", this.levelUpSound);
config.set("PlayerInteraction.LevelUpString", this.levelUpString);
config.set("PlayerInteraction.LevelUpString", this.cannotTeleportWolfString);
config.set("PlayerInteraction.CannotTeleportWolfString", this.cannotTeleportWolfString);
config.set("PlayerInteraction.NewDogString", this.newDogString);
config.set("PlayerInteraction.DeadDogString", this.deadDogString);
config.set("PlayerInteraction.DeadDogLevelString", this.deadDogLevelString);
Expand Down
Loading

0 comments on commit 15960b6

Please sign in to comment.