Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hm.petmaster</groupId>
<artifactId>PetMaster</artifactId>
<version>1.12.5</version>
<version>1.12.6</version>
<url>https://github.com/PyvesB/PetMaster</url>
<name>PetMaster</name>
<description>Manage pets and display useful information via holograms, action bar or chat messages!</description>
Expand All @@ -30,16 +30,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.5.3</version>
<configuration>
<relocations>
<relocation>
Expand Down Expand Up @@ -86,46 +86,53 @@
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- Adventure Minimessage API -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.11.0</version>
<version>4.17.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.11.0</version>
<version>4.17.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.1.1</version>
<version>4.3.2</version>
</dependency>

<!-- Adventure Minimessage API end-->

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.20.6-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.0</version>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.8.8</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.hm.mcshared</groupId>
<artifactId>MCShared</artifactId>
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/com/hm/petmaster/PetMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@

/**
* Manage pets and display useful information via holograms, action bar or chat messages!
*
*
* PetMaster is under GNU General Public License version 3. Please visit the plugin's GitHub for more information :
* https://github.com/PyvesB/PetMaster
*
* Official plugin's server: hellominecraft.fr
*
*
* Bukkit project page: dev.bukkit.org/bukkit-plugins/pet-master
*
*
* Spigot project page: spigotmc.org/resources/pet-master.15904
*
*
* @since December 2015.
* @version 1.12.5
* @author DarkPyves
Expand Down Expand Up @@ -96,10 +96,12 @@ public void onEnable() {
this.adventure = BukkitAudiences.create(this);
this.messageSender = new MessageSender(this);

getLogger().info("Server version..." + Bukkit.getServer().getBukkitVersion());
getLogger().info("Registered subVersion..." + Bukkit.getServer().getBukkitVersion().replace(".", ",").split(",")[1].split("-")[0]);
getLogger().info("Registering listeners...");

serverVersion = Integer.parseInt(
Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].split("_")[1]);
Bukkit.getServer().getBukkitVersion().replace(".", ",").split(",")[1].split("-")[0]);

playerInteractListener = new PlayerInteractListener(this);
playerLeashListener = new PlayerLeashListener(this);
Expand All @@ -118,7 +120,7 @@ public void onEnable() {
}

extractParametersFromConfig(true);

PetAbilityFile.petAbilitySetup();
PetAbilityFile.getPetAbilities().options().copyDefaults(true);
PetAbilityFile.petAbilitySave();
Expand Down Expand Up @@ -175,7 +177,7 @@ public void extractParametersFromConfig(boolean attemptUpdate) {
if (config.getBoolean("checkForUpdate", true)) {
if (updateChecker == null) {
updateChecker = new UpdateChecker(this, "https://raw.githubusercontent.com/PyvesB/PetMaster/master/pom.xml",
"petmaster.admin", chatHeader, "spigotmc.org/resources/pet-master.15904");
"petmaster.admin", chatHeader, "spigotmc.org/resources/pet-master.15904");
getServer().getPluginManager().registerEvents(updateChecker, this);
updateChecker.launchUpdateCheckerTask();
}
Expand All @@ -201,7 +203,7 @@ public void extractParametersFromConfig(boolean attemptUpdate) {

/**
* Loads and backs up file fileName.
*
*
* @param fileName
* @return the loaded CommentedYamlConfiguration
*/
Expand All @@ -212,7 +214,7 @@ private CommentedYamlConfiguration loadAndBackupYamlConfiguration(String fileNam
} catch (IOException | InvalidConfigurationException e) {
getLogger().severe("Error while loading " + fileName + " file, disabling plugin.");
getLogger().log(Level.SEVERE,
"Verify your syntax by visiting yaml-online-parser.appspot.com and using the following logs: ", e);
"Verify your syntax by visiting yaml-online-parser.appspot.com and using the following logs: ", e);
getServer().getPluginManager().disablePlugin(this);
}

Expand All @@ -233,23 +235,23 @@ private void updateOldConfiguration() {

updateSetting(config, "languageFileName", "lang.yml", "Name of the language file.");
updateSetting(config, "checkForUpdate", true,
"Check for update on plugin launch and notify when an OP joins the game.");
"Check for update on plugin launch and notify when an OP joins the game.");
updateSetting(config, "changeOwnerPrice", 0, "Price of the /petm setowner command (requires Vault).");
updateSetting(config, "displayDog", true, "Take dogs into account.");
updateSetting(config, "displayCat", true, "Take cats into account.");
updateSetting(config, "displayHorse", true, "Take horses into account.");
updateSetting(config, "displayLlama", true, "Take llamas into account.");
updateSetting(config, "displayParrot", true, "Take parrots into account.");
updateSetting(config, "actionBarMessage", false,
"Enable or disable action bar messages when right-clicking on a pet.");
"Enable or disable action bar messages when right-clicking on a pet.");
updateSetting(config, "displayToOwner", false,
"Enable or disable showing ownership information for a player's own pets.");
"Enable or disable showing ownership information for a player's own pets.");
updateSetting(config, "freePetPrice", 0, "Price of the /petm free command (requires Vault).");
updateSetting(config, "showHealth", true,
"Show health next to owner in chat and action bar messages (not holograms).");
"Show health next to owner in chat and action bar messages (not holograms).");
updateSetting(config, "disablePlayerDamage", false, "Protect pets to avoid being hurt by other player.");
updateSetting(config, "enableAngryMobPlayerDamage", true,
"Allows players to defend themselves against angry tamed mobs (e.g. dogs) even if disablePlayerDamage is true.");
"Allows players to defend themselves against angry tamed mobs (e.g. dogs) even if disablePlayerDamage is true.");
updateSetting(config, "disableLeash", false, "Prevent others from using leash on pet.");
updateSetting(config, "disableRiding", false, "Prevent others from mounting pet (horse/donkey).");

Expand Down Expand Up @@ -337,7 +339,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,

/**
* Updates the configuration file to include a new setting with its default value and its comments.
*
*
* @param file
* @param name
* @param value
Expand All @@ -349,7 +351,7 @@ private void updateSetting(CommentedYamlConfiguration file, String name, Object
updatePerformed = true;
}
}

public int getServerVersion() {
return serverVersion;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/hm/petmaster/command/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

/**
* Class in charge of displaying the plugin's extra information (/petm info).
*
*
* @author Pyves
*
*
*/
public class InfoCommand {

Expand All @@ -25,7 +25,7 @@ public InfoCommand(PetMaster plugin) {

/**
* Displays information about the plugin.
*
*
* @param sender
*/
public void getInfo(CommandSender sender) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/hm/petmaster/command/SetOwnerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

/**
* Class in charge of handling player requests to change ownership of a pet (/petm setowner).
*
*
* @author Pyves
*
*
*/
public class SetOwnerCommand {

Expand Down
44 changes: 27 additions & 17 deletions src/main/java/com/hm/petmaster/listener/PlayerInteractListener.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.hm.petmaster.listener;

import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.hm.mcshared.event.PlayerChangeAnimalOwnershipEvent;
import com.hm.petmaster.PetMaster;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.milkbowl.vault.economy.Economy;
Expand All @@ -20,12 +20,12 @@
import org.bukkit.scheduler.BukkitRunnable;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Class used to display holograms, change the owner of a pet or free a pet.
*
*
* @author Pyves
*
*/
Expand Down Expand Up @@ -85,13 +85,13 @@ public void extractParameters() {
showHealth = plugin.getPluginConfig().getBoolean("showHealth", true);
disableRiding = plugin.getPluginConfig().getBoolean("disableRiding", false);

boolean holographicDisplaysAvailable = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
boolean decentHologramsAvailable = Bukkit.getPluginManager().isPluginEnabled("DecentHolograms");
// Checking whether user configured plugin to display hologram but HolographicsDisplays not available.
if (hologramMessage && !holographicDisplaysAvailable) {
if (hologramMessage && !decentHologramsAvailable) {
hologramMessage = false;
actionBarMessage = true;
plugin.getLogger().warning(
"HolographicDisplays was not found; disabling usage of holograms and enabling action bar messages.");
"DecentHolograms was not found; disabling usage of holograms and enabling action bar messages.");
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {

/**
* Determines whether the current PlayerInteractEntityEvent should be handled.
*
*
* @param event
* @return true if the event should be handled, false otherwise
*/
Expand All @@ -147,7 +147,7 @@ private boolean shouldHandleEvent(PlayerInteractEntityEvent event) {

/**
* Change the owner of a pet.
*
*
* @param player
* @param oldOwner
* @param newOwner
Expand All @@ -161,7 +161,7 @@ private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, T
+ plugin.getPluginLang().getString("owner-changed", "This pet was given to a new owner!"));
newOwner.sendMessage(plugin.getChatHeader()
+ plugin.getPluginLang().getString("new-owner", "Player PLAYER gave you ownership of a pet!")
.replace("PLAYER", player.getName()));
.replace("PLAYER", oldOwner.getName()));

// Create new event to allow other plugins to be aware of the ownership change.
PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent = new PlayerChangeAnimalOwnershipEvent(
Expand All @@ -172,7 +172,7 @@ private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, T

/**
* Frees a pet; it will no longer be tamed.
*
*
* @param player
* @param oldOwner
* @param tameable
Expand Down Expand Up @@ -207,7 +207,7 @@ private void freePet(Player player, AnimalTamer oldOwner, Tameable tameable) {

/**
* Displays a hologram, and automatically delete it after a given delay.
*
*
* @param player
* @param owner
* @param tameable
Expand Down Expand Up @@ -248,19 +248,29 @@ private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameabl
Location hologramLocation = new Location(eventLocation.getWorld(), eventLocation.getX(),
eventLocation.getY() + offset, eventLocation.getZ());

final Hologram hologram = HologramsAPI.createHologram(plugin, hologramLocation);
hologram.appendTextLine(plugin.getMessageSender().parseMessageToString(

String hologramname = player.getUniqueId() + "_pm";

List<String> lines = Collections.singletonList(plugin.getMessageSender().parseMessageToString(
"petmaster-hologram",
Placeholder.component("owner", Component.text(owner.getName() != null ? owner.getName() : "null"))
));

if (DHAPI.getHologram(hologramname) == null) {
Hologram hologram = DHAPI.createHologram(hologramname, hologramLocation, lines);
} else {
return;
}


// Runnable to delete hologram.

new BukkitRunnable() {

@Override
public void run() {

hologram.delete();
DHAPI.removeHologram(hologramname);
}
}.runTaskLater(plugin, hologramDuration);
}
Expand All @@ -274,7 +284,7 @@ public void run() {
Placeholder.component("current-health", Component.text(String.format("%.1f", animal.getHealth()))),
Placeholder.component("max-health", Component.text(
plugin.getServerVersion() < 9 ? String.format("%.1f", animal.getMaxHealth())
: String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())))
: String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())))
);
}

Expand Down Expand Up @@ -303,7 +313,7 @@ public void run() {

/**
* Charges a player if he has enough money and displays relevant messages.
*
*
* @param player
* @param price
* @return true if money should be withdrawn from the player, false otherwise
Expand Down
Loading