Update gradle standard to 8.14.2
This commit is contained in:
1 parent
bf8e5737fa
commit
133318635f
31 files changed
+1346
-1326
No files matched your search
+24
-26
@@ -1,8 +1,9 @@
|
||||
plugins {
|
||||
id("java") // Tell gradle this is a java project.
|
||||
id("java-library") // Import helper for source-based libraries.
|
||||
id("com.diffplug.spotless") version "7.0.4" // Import auto-formatter.
|
||||
id("com.gradleup.shadow") version "8.3.6" // Import shadow API.
|
||||
java // Tell gradle this is a java project.
|
||||
eclipse // Import eclipse plugin for IDE integration.
|
||||
kotlin("jvm") version "2.1.21" // Import kotlin jvm plugin for kotlin/java integration.
|
||||
}
|
||||
|
||||
java {
|
||||
@@ -11,20 +12,17 @@ java {
|
||||
}
|
||||
|
||||
group = "com.hm.petmaster" // Declare bundle identifier.
|
||||
|
||||
version = "1.0" // Declare plugin version (will be in .jar).
|
||||
|
||||
val apiVersion = "1.19" // Declare minecraft server target version.
|
||||
|
||||
tasks.named<ProcessResources>("processResources") {
|
||||
val props = mapOf(
|
||||
"version" to version,
|
||||
"apiVersion" to apiVersion
|
||||
)
|
||||
val props = mapOf("version" to version, "apiVersion" to apiVersion)
|
||||
|
||||
inputs.properties(props) // Indicates to rerun if version changes.
|
||||
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
filesMatching("plugin.yml") { expand(props) }
|
||||
from("LICENSE") { // Bundle license into .jars.
|
||||
into("/")
|
||||
}
|
||||
@@ -33,15 +31,9 @@ tasks.named<ProcessResources>("processResources") {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url = uri("https://jitpack.io")
|
||||
}
|
||||
maven {
|
||||
url = uri("https://repo.purpurmc.org/snapshots")
|
||||
}
|
||||
maven {
|
||||
url = uri("https://repo.codemc.io/repository/maven-public/")
|
||||
}
|
||||
maven { url = uri("https://jitpack.io") }
|
||||
maven { url = uri("https://repo.purpurmc.org/snapshots") }
|
||||
maven { url = uri("https://repo.codemc.io/repository/maven-public/") }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -52,7 +44,7 @@ dependencies {
|
||||
implementation("net.kyori:adventure-text-minimessage:4.17.0") // Adventure Minimessage API.
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.3.2") // Adventure Minimessage API.
|
||||
compileOnly(project(":libs:MCShared-OG")) // Import source-based TrueOG Network MCShared-OG API.
|
||||
compileOnly(project(":libs:Utilities-OG")) // Import source-based TrueOG Network Utilities-OG API.
|
||||
compileOnlyApi(project(":libs:Utilities-OG")) // Import source-based TrueOG Network Utilities-OG API.
|
||||
}
|
||||
|
||||
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
|
||||
@@ -67,12 +59,11 @@ tasks.shadowJar {
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(tasks.spotlessApply)
|
||||
dependsOn(tasks.shadowJar)
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
archiveClassifier.set("part")
|
||||
}
|
||||
tasks.jar { archiveClassifier.set("part") }
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.compilerArgs.add("-parameters")
|
||||
@@ -81,13 +72,20 @@ tasks.withType<JavaCompile>().configureEach {
|
||||
options.isFork = true
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
vendor = JvmVendorSpec.GRAAL_VM
|
||||
}
|
||||
}
|
||||
|
||||
spotless {
|
||||
java {
|
||||
removeUnusedImports()
|
||||
palantirJavaFormat()
|
||||
}
|
||||
kotlinGradle {
|
||||
ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) }
|
||||
target("build.gradle.kts", "settings.gradle.kts")
|
||||
}
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -112,7 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -203,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
@@ -211,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+4
-2
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -68,11 +70,11 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
+1
-1
Submodule libs/MCShared-OG updated: d7d9d6008f...e6be6980c4.
+1
-1
Submodule libs/Utilities-OG updated: 6151b2de7f...e68d3fec7a.
+3
-3
@@ -1,14 +1,14 @@
|
||||
rootProject.name = "PetMaster-OG"
|
||||
|
||||
// Run the bootstrap at configuration time.
|
||||
val process = ProcessBuilder("sh", "bootstrap.sh")
|
||||
.directory(rootDir)
|
||||
.start()
|
||||
val process = ProcessBuilder("sh", "bootstrap.sh").directory(rootDir).start()
|
||||
|
||||
val exitValue = process.waitFor()
|
||||
|
||||
if (exitValue != 0) {
|
||||
throw GradleException("bootstrap.sh failed with exit code $exitValue")
|
||||
}
|
||||
|
||||
include("libs:MCShared-OG")
|
||||
|
||||
include("libs:Utilities-OG")
|
||||
@@ -1,19 +1,5 @@
|
||||
package com.hm.petmaster;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.hm.mcshared.file.CommentedYamlConfiguration;
|
||||
import com.hm.petmaster.command.EnableDisableCommand;
|
||||
import com.hm.petmaster.command.FreeCommand;
|
||||
@@ -33,10 +19,21 @@ import com.hm.petmaster.listener.PlayerLeashListener;
|
||||
import com.hm.petmaster.listener.PlayerQuitListener;
|
||||
import com.hm.petmaster.listener.PlayerTameListener;
|
||||
import com.hm.petmaster.utils.MessageSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Manage pets and display useful information via holograms, action bar or chat messages!
|
||||
@@ -56,253 +53,268 @@ import net.kyori.adventure.text.TextComponent;
|
||||
*/
|
||||
public class PetMaster extends JavaPlugin {
|
||||
|
||||
// Plugin options and various parameters.
|
||||
private TextComponent chatHeader;
|
||||
private int serverVersion;
|
||||
// Plugin options and various parameters.
|
||||
private TextComponent chatHeader;
|
||||
private int serverVersion;
|
||||
|
||||
// Fields related to file handling.
|
||||
private CommentedYamlConfiguration config;
|
||||
private CommentedYamlConfiguration lang;
|
||||
// Fields related to file handling.
|
||||
private CommentedYamlConfiguration config;
|
||||
private CommentedYamlConfiguration lang;
|
||||
|
||||
// Plugin listeners.
|
||||
private PlayerInteractListener playerInteractListener;
|
||||
private PlayerLeashListener playerLeashListener;
|
||||
private PlayerQuitListener playerQuitListener;
|
||||
private PlayerAttackListener playerAttackListener;
|
||||
private PlayerTameListener playerTameListener;
|
||||
private PlayerBreedListener playerBreedListener;
|
||||
// Plugin listeners.
|
||||
private PlayerInteractListener playerInteractListener;
|
||||
private PlayerLeashListener playerLeashListener;
|
||||
private PlayerQuitListener playerQuitListener;
|
||||
private PlayerAttackListener playerAttackListener;
|
||||
private PlayerTameListener playerTameListener;
|
||||
private PlayerBreedListener playerBreedListener;
|
||||
|
||||
// Additional classes related to plugin commands.
|
||||
private HelpCommand helpCommand;
|
||||
private InfoCommand infoCommand;
|
||||
private SetOwnerCommand setOwnerCommand;
|
||||
private FreeCommand freeCommand;
|
||||
private EnableDisableCommand enableDisableCommand;
|
||||
private ReloadCommand reloadCommand;
|
||||
private SetColorCommand setColorCommand;
|
||||
private ShareCommand shareCommand;
|
||||
private PetInvincibleCommand petInvincibleCommand;
|
||||
private PetSkillCommand petSkillCommand;
|
||||
// Additional classes related to plugin commands.
|
||||
private HelpCommand helpCommand;
|
||||
private InfoCommand infoCommand;
|
||||
private SetOwnerCommand setOwnerCommand;
|
||||
private FreeCommand freeCommand;
|
||||
private EnableDisableCommand enableDisableCommand;
|
||||
private ReloadCommand reloadCommand;
|
||||
private SetColorCommand setColorCommand;
|
||||
private ShareCommand shareCommand;
|
||||
private PetInvincibleCommand petInvincibleCommand;
|
||||
private PetSkillCommand petSkillCommand;
|
||||
|
||||
// Messaging System.
|
||||
private BukkitAudiences adventure;
|
||||
private MessageSender messageSender;
|
||||
// Messaging System.
|
||||
private BukkitAudiences adventure;
|
||||
private MessageSender messageSender;
|
||||
|
||||
public @NotNull BukkitAudiences adventure() {
|
||||
if(this.adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
public @NotNull BukkitAudiences adventure() {
|
||||
if (this.adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when server is launched or reloaded.
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Start enabling plugin.
|
||||
long startTime = System.currentTimeMillis();
|
||||
/**
|
||||
* Called when server is launched or reloaded.
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Start enabling plugin.
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// Initializing the Messaging System
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
this.messageSender = new MessageSender(this);
|
||||
// Initializing the Messaging System
|
||||
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...");
|
||||
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().getBukkitVersion().replace(".", ",").split(",")[1].split("-")[0]);
|
||||
serverVersion = Integer.parseInt(Bukkit.getServer()
|
||||
.getBukkitVersion()
|
||||
.replace(".", ",")
|
||||
.split(",")[1]
|
||||
.split("-")[0]);
|
||||
|
||||
playerInteractListener = new PlayerInteractListener(this);
|
||||
playerLeashListener = new PlayerLeashListener(this);
|
||||
playerQuitListener = new PlayerQuitListener(this);
|
||||
playerTameListener = new PlayerTameListener(this);
|
||||
playerBreedListener = new PlayerBreedListener(this);
|
||||
playerInteractListener = new PlayerInteractListener(this);
|
||||
playerLeashListener = new PlayerLeashListener(this);
|
||||
playerQuitListener = new PlayerQuitListener(this);
|
||||
playerTameListener = new PlayerTameListener(this);
|
||||
playerBreedListener = new PlayerBreedListener(this);
|
||||
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
// Register listeners.
|
||||
pm.registerEvents(playerInteractListener, this);
|
||||
pm.registerEvents(playerLeashListener, this);
|
||||
pm.registerEvents(playerQuitListener, this);
|
||||
pm.registerEvents(playerTameListener, this);
|
||||
if (getServerVersion() >= 10) {
|
||||
pm.registerEvents(playerBreedListener, this);
|
||||
}
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
// Register listeners.
|
||||
pm.registerEvents(playerInteractListener, this);
|
||||
pm.registerEvents(playerLeashListener, this);
|
||||
pm.registerEvents(playerQuitListener, this);
|
||||
pm.registerEvents(playerTameListener, this);
|
||||
if (getServerVersion() >= 10) {
|
||||
pm.registerEvents(playerBreedListener, this);
|
||||
}
|
||||
|
||||
extractParametersFromConfig(true);
|
||||
extractParametersFromConfig(true);
|
||||
|
||||
PetAbilityFile.petAbilitySetup();
|
||||
PetAbilityFile.getPetAbilities().options().copyDefaults(true);
|
||||
PetAbilityFile.petAbilitySave();
|
||||
PetAbilityFile.petAbilitySetup();
|
||||
PetAbilityFile.getPetAbilities().options().copyDefaults(true);
|
||||
PetAbilityFile.petAbilitySave();
|
||||
|
||||
chatHeader = Component.text("<gray>[<gold>\u25b2<gray>]");
|
||||
chatHeader = Component.text("<gray>[<gold>\u25b2<gray>]");
|
||||
|
||||
File playerColorConfig = new File(getDataFolder() + File.separator + "playersettings.yml");
|
||||
File playerColorConfig = new File(getDataFolder() + File.separator + "playersettings.yml");
|
||||
|
||||
helpCommand = new HelpCommand(this);
|
||||
infoCommand = new InfoCommand(this);
|
||||
setOwnerCommand = new SetOwnerCommand(this);
|
||||
freeCommand = new FreeCommand(this);
|
||||
enableDisableCommand = new EnableDisableCommand(this);
|
||||
reloadCommand = new ReloadCommand(this);
|
||||
setColorCommand = new SetColorCommand(this, playerColorConfig);
|
||||
shareCommand = new ShareCommand(this);
|
||||
petInvincibleCommand = new PetInvincibleCommand(this);
|
||||
petSkillCommand = new PetSkillCommand(this);
|
||||
helpCommand = new HelpCommand(this);
|
||||
infoCommand = new InfoCommand(this);
|
||||
setOwnerCommand = new SetOwnerCommand(this);
|
||||
freeCommand = new FreeCommand(this);
|
||||
enableDisableCommand = new EnableDisableCommand(this);
|
||||
reloadCommand = new ReloadCommand(this);
|
||||
setColorCommand = new SetColorCommand(this, playerColorConfig);
|
||||
shareCommand = new ShareCommand(this);
|
||||
petInvincibleCommand = new PetInvincibleCommand(this);
|
||||
petSkillCommand = new PetSkillCommand(this);
|
||||
|
||||
// Warn if an outdated entry is contained in the language file
|
||||
if (lang.contains("petmaster-command-info-hover")){
|
||||
getLogger().log(Level.WARNING, "Your language file contains outdated entrys! It is highly reccomended to delete it and let it regenerate so that all messages appear correctly.");
|
||||
}
|
||||
// Warn if an outdated entry is contained in the language file
|
||||
if (lang.contains("petmaster-command-info-hover")) {
|
||||
getLogger()
|
||||
.log(
|
||||
Level.WARNING,
|
||||
"Your language file contains outdated entrys! It is highly reccomended to delete it and let it regenerate so that all messages appear correctly.");
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled(this)) {
|
||||
getLogger().info("Plugin enabled and ready to run! Took " + (System.currentTimeMillis() - startTime) + "ms.");
|
||||
}
|
||||
}
|
||||
if (getServer().getPluginManager().isPluginEnabled(this)) {
|
||||
getLogger()
|
||||
.info("Plugin enabled and ready to run! Took " + (System.currentTimeMillis() - startTime) + "ms.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts plugin parameters from the configuration file.
|
||||
*
|
||||
* @param attemptUpdate
|
||||
*/
|
||||
public void extractParametersFromConfig(boolean attemptUpdate) {
|
||||
getLogger().info("Backing up and loading configuration files...");
|
||||
/**
|
||||
* Extracts plugin parameters from the configuration file.
|
||||
*
|
||||
* @param attemptUpdate
|
||||
*/
|
||||
public void extractParametersFromConfig(boolean attemptUpdate) {
|
||||
getLogger().info("Backing up and loading configuration files...");
|
||||
|
||||
config = loadAndBackupYamlConfiguration("config.yml");
|
||||
lang = loadAndBackupYamlConfiguration(config.getString("languageFileName", "lang.yml"));
|
||||
config = loadAndBackupYamlConfiguration("config.yml");
|
||||
lang = loadAndBackupYamlConfiguration(config.getString("languageFileName", "lang.yml"));
|
||||
|
||||
if (!getServer().getPluginManager().isPluginEnabled(this)) {
|
||||
return;
|
||||
}
|
||||
if (!getServer().getPluginManager().isPluginEnabled(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerInteractListener.extractParameters();
|
||||
playerLeashListener.extractParameters();
|
||||
playerInteractListener.extractParameters();
|
||||
playerLeashListener.extractParameters();
|
||||
|
||||
if (config.getBoolean("disablePlayerDamage", false)) {
|
||||
if (playerAttackListener == null) {
|
||||
playerAttackListener = new PlayerAttackListener(this);
|
||||
getServer().getPluginManager().registerEvents(playerAttackListener, this);
|
||||
playerAttackListener.extractParameters();
|
||||
}
|
||||
if (config.getBoolean("disablePlayerDamage", false)) {
|
||||
if (playerAttackListener == null) {
|
||||
playerAttackListener = new PlayerAttackListener(this);
|
||||
getServer().getPluginManager().registerEvents(playerAttackListener, this);
|
||||
playerAttackListener.extractParameters();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (playerAttackListener != null) {
|
||||
HandlerList.unregisterAll(playerAttackListener);
|
||||
playerAttackListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (playerAttackListener != null) {
|
||||
HandlerList.unregisterAll(playerAttackListener);
|
||||
playerAttackListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and backs up file fileName.
|
||||
*
|
||||
* @param fileName
|
||||
* @return the loaded CommentedYamlConfiguration
|
||||
*/
|
||||
private CommentedYamlConfiguration loadAndBackupYamlConfiguration(String fileName) {
|
||||
CommentedYamlConfiguration yamlConfiguration = new CommentedYamlConfiguration(fileName, this);
|
||||
try {
|
||||
yamlConfiguration.loadConfiguration();
|
||||
} 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);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
/**
|
||||
* Loads and backs up file fileName.
|
||||
*
|
||||
* @param fileName
|
||||
* @return the loaded CommentedYamlConfiguration
|
||||
*/
|
||||
private CommentedYamlConfiguration loadAndBackupYamlConfiguration(String fileName) {
|
||||
CommentedYamlConfiguration yamlConfiguration = new CommentedYamlConfiguration(fileName, this);
|
||||
try {
|
||||
yamlConfiguration.loadConfiguration();
|
||||
} 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);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
try {
|
||||
yamlConfiguration.backupConfiguration();
|
||||
} catch (IOException e) {
|
||||
getLogger().log(Level.SEVERE, "Error while backing up configuration file: ", e);
|
||||
}
|
||||
return yamlConfiguration;
|
||||
}
|
||||
try {
|
||||
yamlConfiguration.backupConfiguration();
|
||||
} catch (IOException e) {
|
||||
getLogger().log(Level.SEVERE, "Error while backing up configuration file: ", e);
|
||||
}
|
||||
return yamlConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when server is stopped or reloaded.
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Closing Adventure API
|
||||
if(this.adventure != null) {
|
||||
this.adventure.close();
|
||||
this.adventure = null;
|
||||
}
|
||||
getLogger().info("PetMaster has been disabled.");
|
||||
}
|
||||
/**
|
||||
* Called when server is stopped or reloaded.
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Closing Adventure API
|
||||
if (this.adventure != null) {
|
||||
this.adventure.close();
|
||||
this.adventure = null;
|
||||
}
|
||||
getLogger().info("PetMaster has been disabled.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player or the console enters a command.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!"petm".equalsIgnoreCase(cmd.getName())) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Called when a player or the console enters a command.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!"petm".equalsIgnoreCase(cmd.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 0 || args.length == 1 && "help".equalsIgnoreCase(args[0])) {
|
||||
helpCommand.getHelp(sender);
|
||||
} else if ("info".equalsIgnoreCase(args[0])) {
|
||||
infoCommand.getInfo(sender);
|
||||
} else if ("reload".equalsIgnoreCase(args[0])) {
|
||||
reloadCommand.reload(sender);
|
||||
} else if ("disable".equalsIgnoreCase(args[0])) {
|
||||
enableDisableCommand.setState(sender, true);
|
||||
} else if ("enable".equalsIgnoreCase(args[0])) {
|
||||
enableDisableCommand.setState(sender, false);
|
||||
} else if ("setowner".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
setOwnerCommand.setOwner(((Player) sender), args);
|
||||
} else if ("free".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
freeCommand.freePet(((Player) sender), args);
|
||||
} else if ("setcolor".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
setColorCommand.setColor(((Player) sender), args);
|
||||
} else if("sharepet".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
shareCommand.sharePetCommand((Player) sender);
|
||||
} else if("godpet".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
petInvincibleCommand.godPetCommand((Player)sender);
|
||||
} else if ("petskill".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
petSkillCommand.petSkillCommand((Player)sender);
|
||||
} else {
|
||||
getMessageSender().sendMessage(sender, "misused-command");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0 || args.length == 1 && "help".equalsIgnoreCase(args[0])) {
|
||||
helpCommand.getHelp(sender);
|
||||
} else if ("info".equalsIgnoreCase(args[0])) {
|
||||
infoCommand.getInfo(sender);
|
||||
} else if ("reload".equalsIgnoreCase(args[0])) {
|
||||
reloadCommand.reload(sender);
|
||||
} else if ("disable".equalsIgnoreCase(args[0])) {
|
||||
enableDisableCommand.setState(sender, true);
|
||||
} else if ("enable".equalsIgnoreCase(args[0])) {
|
||||
enableDisableCommand.setState(sender, false);
|
||||
} else if ("setowner".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
setOwnerCommand.setOwner(((Player) sender), args);
|
||||
} else if ("free".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
freeCommand.freePet(((Player) sender), args);
|
||||
} else if ("setcolor".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
setColorCommand.setColor(((Player) sender), args);
|
||||
} else if ("sharepet".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
shareCommand.sharePetCommand((Player) sender);
|
||||
} else if ("godpet".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
petInvincibleCommand.godPetCommand((Player) sender);
|
||||
} else if ("petskill".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
petSkillCommand.petSkillCommand((Player) sender);
|
||||
} else {
|
||||
getMessageSender().sendMessage(sender, "misused-command");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
public int getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
public TextComponent getChatHeader() {
|
||||
return chatHeader;
|
||||
}
|
||||
public TextComponent getChatHeader() {
|
||||
return chatHeader;
|
||||
}
|
||||
|
||||
public CommentedYamlConfiguration getPluginConfig() {
|
||||
return config;
|
||||
}
|
||||
public CommentedYamlConfiguration getPluginConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public CommentedYamlConfiguration getPluginLang() {
|
||||
return lang;
|
||||
}
|
||||
public CommentedYamlConfiguration getPluginLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public SetOwnerCommand getSetOwnerCommand() {
|
||||
return setOwnerCommand;
|
||||
}
|
||||
public SetOwnerCommand getSetOwnerCommand() {
|
||||
return setOwnerCommand;
|
||||
}
|
||||
|
||||
public FreeCommand getFreeCommand() {
|
||||
return freeCommand;
|
||||
}
|
||||
public FreeCommand getFreeCommand() {
|
||||
return freeCommand;
|
||||
}
|
||||
|
||||
public EnableDisableCommand getEnableDisableCommand() {
|
||||
return enableDisableCommand;
|
||||
}
|
||||
public EnableDisableCommand getEnableDisableCommand() {
|
||||
return enableDisableCommand;
|
||||
}
|
||||
|
||||
public SetColorCommand getSetColorCommand() {
|
||||
return setColorCommand;
|
||||
}
|
||||
|
||||
public MessageSender getMessageSender(){
|
||||
return messageSender;
|
||||
}
|
||||
public SetColorCommand getSetColorCommand() {
|
||||
return setColorCommand;
|
||||
}
|
||||
|
||||
public MessageSender getMessageSender() {
|
||||
return messageSender;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,27 @@
|
||||
package com.hm.petmaster.abilities;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
public class PetAbilities {
|
||||
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
|
||||
// General Variables.
|
||||
Tameable pet;
|
||||
boolean isPetOwned;
|
||||
Player player;
|
||||
// General Variables.
|
||||
Tameable pet;
|
||||
boolean isPetOwned;
|
||||
Player player;
|
||||
|
||||
// Health Bonus Variables.
|
||||
int healthBonusAmount = plugin.getConfig().getInt("Health-Bonus-Amount");
|
||||
boolean isHealthBonusEnabled = plugin.getConfig().getBoolean("Health-Bonus-Enabled");
|
||||
// Health Bonus Variables.
|
||||
int healthBonusAmount = plugin.getConfig().getInt("Health-Bonus-Amount");
|
||||
boolean isHealthBonusEnabled = plugin.getConfig().getBoolean("Health-Bonus-Enabled");
|
||||
|
||||
public PetAbilities(PetMaster petmaster) {
|
||||
this.plugin = petmaster;
|
||||
}
|
||||
|
||||
public PetAbilities(PetMaster petmaster) {
|
||||
this.plugin = petmaster;
|
||||
}
|
||||
|
||||
public void petHealthBonus() {
|
||||
if(isHealthBonusEnabled == true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void petHealthBonus() {
|
||||
if (isHealthBonusEnabled == true) {}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Class in charge of enabling or disabling the plugin on the fly (/petm enable or /petm disable).
|
||||
@@ -12,29 +11,28 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class EnableDisableCommand {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private boolean disabled;
|
||||
private final PetMaster plugin;
|
||||
private boolean disabled;
|
||||
|
||||
public EnableDisableCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
disabled = false;
|
||||
}
|
||||
public EnableDisableCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
disabled = false;
|
||||
}
|
||||
|
||||
public void setState(CommandSender sender, boolean disabled) {
|
||||
if (sender.hasPermission("petmaster.admin")) {
|
||||
this.disabled = disabled;
|
||||
if (disabled) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-disabled");
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-enabled");
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(sender, "no-permissions");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
public void setState(CommandSender sender, boolean disabled) {
|
||||
if (sender.hasPermission("petmaster.admin")) {
|
||||
this.disabled = disabled;
|
||||
if (disabled) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-disabled");
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-enabled");
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(sender, "no-permissions");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
/**
|
||||
* Class in charge of handling player requests to free a pet (/petm free).
|
||||
*
|
||||
@@ -16,34 +14,33 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class FreeCommand {
|
||||
|
||||
private final PetMaster plugin;
|
||||
// Contains names of owners wanting to free their pets.
|
||||
private final Set<UUID> freePetSet;
|
||||
private final PetMaster plugin;
|
||||
// Contains names of owners wanting to free their pets.
|
||||
private final Set<UUID> freePetSet;
|
||||
|
||||
public FreeCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
freePetSet = new HashSet<>();
|
||||
}
|
||||
public FreeCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
freePetSet = new HashSet<>();
|
||||
}
|
||||
|
||||
public void freePet(Player player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (!player.hasPermission("petmaster.free")) {
|
||||
plugin.getMessageSender().sendMessage(player, "no-permissions");
|
||||
} else if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
plugin.getMessageSender().sendMessage(player, "currently-disabled");
|
||||
} else {
|
||||
freePetSet.add(player.getUniqueId());
|
||||
plugin.getMessageSender().sendMessage(player, "right-click");
|
||||
// Cancel previous pending operation.
|
||||
plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(player, "misused-command");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean collectPendingFreeRequest(Player player) {
|
||||
return freePetSet.remove(player.getUniqueId());
|
||||
}
|
||||
public void freePet(Player player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (!player.hasPermission("petmaster.free")) {
|
||||
plugin.getMessageSender().sendMessage(player, "no-permissions");
|
||||
} else if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
plugin.getMessageSender().sendMessage(player, "currently-disabled");
|
||||
} else {
|
||||
freePetSet.add(player.getUniqueId());
|
||||
plugin.getMessageSender().sendMessage(player, "right-click");
|
||||
// Cancel previous pending operation.
|
||||
plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(player, "misused-command");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean collectPendingFreeRequest(Player player) {
|
||||
return freePetSet.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Class in charge of displaying the plugin's help (/petm help).
|
||||
@@ -12,44 +11,42 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class HelpCommand {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
public HelpCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public HelpCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void getHelp(CommandSender sender) {
|
||||
// Header.
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-help-header");
|
||||
public void getHelp(CommandSender sender) {
|
||||
// Header.
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-help-header");
|
||||
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-info");
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-info");
|
||||
|
||||
if (sender.hasPermission("petmaster.free")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-free");
|
||||
}
|
||||
|
||||
if (sender.hasPermission("petmaster.free")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-free");
|
||||
}
|
||||
if (sender.hasPermission("petmaster.admin")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-reload");
|
||||
|
||||
if (sender.hasPermission("petmaster.admin")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-reload");
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-enable");
|
||||
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-enable");
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-disable");
|
||||
}
|
||||
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-disable");
|
||||
}
|
||||
if (sender.hasPermission("petmaster.setowner")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-setowner");
|
||||
}
|
||||
|
||||
if (sender.hasPermission("petmaster.setowner")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-setowner");
|
||||
}
|
||||
if (sender.hasPermission("petmaster.setcolor")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-setcolor");
|
||||
}
|
||||
|
||||
if (sender.hasPermission("petmaster.setcolor")) {
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-command-setcolor");
|
||||
}
|
||||
|
||||
// Empty line.
|
||||
sender.sendMessage("");
|
||||
|
||||
// Tip message.
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-tip");
|
||||
}
|
||||
// Empty line.
|
||||
sender.sendMessage("");
|
||||
|
||||
// Tip message.
|
||||
plugin.getMessageSender().sendMessage(sender, "petmaster-tip");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Class in charge of displaying the plugin's extra information (/petm info).
|
||||
@@ -19,40 +16,51 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
*/
|
||||
public class InfoCommand {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
public InfoCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays information about the plugin.
|
||||
*
|
||||
* @param sender
|
||||
*/
|
||||
public void getInfo(CommandSender sender) {
|
||||
List<TagResolver> templates = new ArrayList<>();
|
||||
templates.add(Placeholder.component("name", Component.text(plugin.getPluginMeta().getName())));
|
||||
templates.add(Placeholder.component("version", Component.text(plugin.getPluginMeta().getVersion())));
|
||||
templates.add(Placeholder.component("website", Component.text(
|
||||
plugin.getPluginMeta().getWebsite() != null ? plugin.getPluginMeta().getWebsite() : ""
|
||||
)));
|
||||
templates.add(Placeholder.component("author", Component.text(plugin.getPluginMeta().getAuthors().get(0))));
|
||||
templates.add(Placeholder.component("description-details", Component.text(
|
||||
plugin.getPluginLang().getString(
|
||||
"version-command-description-details",
|
||||
"Manage pets and display useful information via holograms, action bar or chat messages!"
|
||||
)
|
||||
)));
|
||||
templates.add(Placeholder.component("state", Component.text(
|
||||
plugin.getEnableDisableCommand().isDisabled() ? "NO" : "YES")
|
||||
));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-name", templates.toArray(new TagResolver[]{}));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-version", templates.toArray(new TagResolver[]{}));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-website", templates.toArray(new TagResolver[]{}));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-author", templates.toArray(new TagResolver[]{}));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-description", templates.toArray(new TagResolver[]{}));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-enabled", templates.toArray(new TagResolver[]{}));
|
||||
}
|
||||
public InfoCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays information about the plugin.
|
||||
*
|
||||
* @param sender
|
||||
*/
|
||||
public void getInfo(CommandSender sender) {
|
||||
List<TagResolver> templates = new ArrayList<>();
|
||||
templates.add(Placeholder.component(
|
||||
"name", Component.text(plugin.getPluginMeta().getName())));
|
||||
templates.add(Placeholder.component(
|
||||
"version", Component.text(plugin.getPluginMeta().getVersion())));
|
||||
templates.add(Placeholder.component(
|
||||
"website",
|
||||
Component.text(
|
||||
plugin.getPluginMeta().getWebsite() != null
|
||||
? plugin.getPluginMeta().getWebsite()
|
||||
: "")));
|
||||
templates.add(Placeholder.component(
|
||||
"author", Component.text(plugin.getPluginMeta().getAuthors().get(0))));
|
||||
templates.add(
|
||||
Placeholder.component(
|
||||
"description-details",
|
||||
Component.text(
|
||||
plugin.getPluginLang()
|
||||
.getString(
|
||||
"version-command-description-details",
|
||||
"Manage pets and display useful information via holograms, action bar or chat messages!"))));
|
||||
templates.add(Placeholder.component(
|
||||
"state", Component.text(plugin.getEnableDisableCommand().isDisabled() ? "NO" : "YES")));
|
||||
plugin.getMessageSender().sendMessage(sender, "version-command-name", templates.toArray(new TagResolver[] {}));
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(sender, "version-command-version", templates.toArray(new TagResolver[] {}));
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(sender, "version-command-website", templates.toArray(new TagResolver[] {}));
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(sender, "version-command-author", templates.toArray(new TagResolver[] {}));
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(sender, "version-command-description", templates.toArray(new TagResolver[] {}));
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(sender, "version-command-enabled", templates.toArray(new TagResolver[] {}));
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,31 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
public class PetInvincibleCommand {
|
||||
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
|
||||
public PetInvincibleCommand(PetMaster petMaster) {
|
||||
public PetInvincibleCommand(PetMaster petMaster) {
|
||||
|
||||
this.plugin = petMaster;
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
|
||||
}
|
||||
public void godPetCommand(CommandSender sender) {
|
||||
|
||||
public void godPetCommand(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,79 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
public class PetSkillCommand {
|
||||
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
|
||||
public PetSkillCommand(PetMaster petMaster) {
|
||||
public PetSkillCommand(PetMaster petMaster) {
|
||||
|
||||
this.plugin = petMaster;
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
|
||||
}
|
||||
public void petSkillCommand(CommandSender sender) {
|
||||
|
||||
public void petSkillCommand(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
Player player = (Player) sender;
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
if (player.hasPermission("petmaster.admin") || player.isOp()) {
|
||||
|
||||
if(player.hasPermission("petmaster.admin") || player.isOp()) {
|
||||
UtilitiesOG.trueogMessage(player, "Pet Boosts Info");
|
||||
UtilitiesOG.trueogMessage(player, "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Pet Boost(Enabled): " + "&2"
|
||||
+ plugin.getConfig().getBoolean("Pet-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Health Boost(Enabled): " + "&2"
|
||||
+ plugin.getConfig().getBoolean("Health-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Damage Boost(Enabled): " + "&2"
|
||||
+ plugin.getConfig().getBoolean("Damage-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Speed Boost(Enabled): " + "&2"
|
||||
+ plugin.getConfig().getBoolean("Speed-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Defense Boost(Enabled): " + "&2"
|
||||
+ plugin.getConfig().getBoolean("Defense-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
}
|
||||
|
||||
UtilitiesOG.trueogMessage(player, "Pet Boosts Info");
|
||||
UtilitiesOG.trueogMessage(player, "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" Pet Boost(Enabled): " + "&2" +plugin.getConfig().getBoolean("Pet-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" Health Boost(Enabled): " + "&2" + plugin.getConfig().getBoolean("Health-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" Damage Boost(Enabled): " + "&2" + plugin.getConfig().getBoolean("Damage-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" Speed Boost(Enabled): " + "&2" + plugin.getConfig().getBoolean("Speed-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" Defense Boost(Enabled): " + "&2" + plugin.getConfig().getBoolean("Defense-Boost-Enabled"));
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
|
||||
}
|
||||
|
||||
// Stats of boosts current pet is giving them.
|
||||
UtilitiesOG.trueogMessage(player, "Pet Boosts");
|
||||
UtilitiesOG.trueogMessage(player, "#---------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader()+ "&d" +" Health Boost: "+ "&2" + plugin.getConfig().getDouble("Health-Boost-Amount")+ "&d"+ " %");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader()+ "&d" +" Damage Boost: "+ "&2" + plugin.getConfig().getDouble("Damage-Boost-Amount")+ "&d"+ " %");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader()+ "&d" +" Speed Boost: "+ "&2" + plugin.getConfig().getDouble("Speed-Boost-Amount")+ "&d"+ " %");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader()+ "&d" +" Defense Boost: "+ "&2" + plugin.getConfig().getDouble("Defense-Boost-Amount")+ "&d"+ " %");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
// Stats of boosts current pet is giving them.
|
||||
UtilitiesOG.trueogMessage(player, "Pet Boosts");
|
||||
UtilitiesOG.trueogMessage(player, "#---------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Health Boost: " + "&2"
|
||||
+ plugin.getConfig().getDouble("Health-Boost-Amount") + "&d" + " %");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Damage Boost: " + "&2"
|
||||
+ plugin.getConfig().getDouble("Damage-Boost-Amount") + "&d" + " %");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Speed Boost: " + "&2"
|
||||
+ plugin.getConfig().getDouble("Speed-Boost-Amount") + "&d" + " %");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player,
|
||||
plugin.getChatHeader() + "&d" + " Defense Boost: " + "&2"
|
||||
+ plugin.getConfig().getDouble("Defense-Boost-Amount") + "&d" + " %");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
/**
|
||||
* Class in charge of reloading the plugin's configuration files (/petm reload).
|
||||
*
|
||||
@@ -13,32 +12,31 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class ReloadCommand {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
public ReloadCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void reload(CommandSender sender) {
|
||||
if (sender.hasPermission("petmaster.admin")) {
|
||||
plugin.reloadConfig();
|
||||
plugin.extractParametersFromConfig(false);
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled(plugin)) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
plugin.getMessageSender().sendMessage(player, "configuration-successfully-reloaded");
|
||||
}
|
||||
plugin.getLogger().info("Configuration successfully reloaded.");
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
plugin.getMessageSender().sendMessage(player, "configuration-reload-failed");
|
||||
}
|
||||
plugin.getLogger().severe("Errors while reloading configuration. Please view logs for more details.");
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(sender, "no-permissions");
|
||||
}
|
||||
}
|
||||
public ReloadCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void reload(CommandSender sender) {
|
||||
if (sender.hasPermission("petmaster.admin")) {
|
||||
plugin.reloadConfig();
|
||||
plugin.extractParametersFromConfig(false);
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled(plugin)) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
plugin.getMessageSender().sendMessage(player, "configuration-successfully-reloaded");
|
||||
}
|
||||
plugin.getLogger().info("Configuration successfully reloaded.");
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
plugin.getMessageSender().sendMessage(player, "configuration-reload-failed");
|
||||
}
|
||||
plugin.getLogger().severe("Errors while reloading configuration. Please view logs for more details.");
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(sender, "no-permissions");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,95 +1,96 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
/**
|
||||
* Class in charge of handling player requests to change default color of a pets
|
||||
* collar. (/petm setcolor).
|
||||
*/
|
||||
public class SetColorCommand {
|
||||
|
||||
private static final String COLOR_CONFIG_NAME = "color";
|
||||
private static final String COLOR_CONFIG_NAME = "color";
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final File playerColorConfig;
|
||||
private final PetMaster plugin;
|
||||
private final File playerColorConfig;
|
||||
|
||||
public SetColorCommand(PetMaster plugin, File playerColorConfig) {
|
||||
this.plugin = plugin;
|
||||
this.playerColorConfig = playerColorConfig;
|
||||
}
|
||||
public SetColorCommand(PetMaster plugin, File playerColorConfig) {
|
||||
this.plugin = plugin;
|
||||
this.playerColorConfig = playerColorConfig;
|
||||
}
|
||||
|
||||
public void setColor(Player player, String[] args) {
|
||||
if (args.length != 2) {
|
||||
plugin.getMessageSender().sendMessage(player, "misused-command");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DyeColor color = DyeColor.valueOf(args[1].toUpperCase());
|
||||
if (!player.hasPermission("petmaster.setcolor")) {
|
||||
plugin.getMessageSender().sendMessage(player, "no-permissions");
|
||||
} else if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
plugin.getMessageSender().sendMessage(player, "currently-disabled");
|
||||
} else {
|
||||
try {
|
||||
if (!playerColorConfig.exists()) {
|
||||
playerColorConfig.createNewFile();
|
||||
}
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(playerColorConfig);
|
||||
ConfigurationSection playerConfig = config.getConfigurationSection(player.getUniqueId().toString());
|
||||
if (playerConfig == null) {
|
||||
playerConfig = config.createSection(player.getUniqueId().toString());
|
||||
}
|
||||
playerConfig.set(COLOR_CONFIG_NAME, color.toString());
|
||||
config.save(playerColorConfig);
|
||||
public void setColor(Player player, String[] args) {
|
||||
if (args.length != 2) {
|
||||
plugin.getMessageSender().sendMessage(player, "misused-command");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DyeColor color = DyeColor.valueOf(args[1].toUpperCase());
|
||||
if (!player.hasPermission("petmaster.setcolor")) {
|
||||
plugin.getMessageSender().sendMessage(player, "no-permissions");
|
||||
} else if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
plugin.getMessageSender().sendMessage(player, "currently-disabled");
|
||||
} else {
|
||||
try {
|
||||
if (!playerColorConfig.exists()) {
|
||||
playerColorConfig.createNewFile();
|
||||
}
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(playerColorConfig);
|
||||
ConfigurationSection playerConfig =
|
||||
config.getConfigurationSection(player.getUniqueId().toString());
|
||||
if (playerConfig == null) {
|
||||
playerConfig = config.createSection(player.getUniqueId().toString());
|
||||
}
|
||||
playerConfig.set(COLOR_CONFIG_NAME, color.toString());
|
||||
config.save(playerColorConfig);
|
||||
|
||||
plugin.getMessageSender().sendMessage(player, "color-successfully-set");
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Error while loading " + playerColorConfig.getName());
|
||||
plugin.getLogger().log(Level.SEVERE, "Verify your syntax by visiting yaml-online-parser.appspot.com and using the following logs: ", e);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
StringBuilder colors = new StringBuilder();
|
||||
int length = DyeColor.values().length;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
DyeColor color = DyeColor.values()[i];
|
||||
colors.append(color.name().toLowerCase());
|
||||
if (i < length - 1) {
|
||||
colors.append(' ');
|
||||
}
|
||||
}
|
||||
plugin.getMessageSender().sendMessage(
|
||||
player,
|
||||
"available-colors",
|
||||
Placeholder.component("colors", Component.text(colors.toString()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public DyeColor getColor(UUID player) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(playerColorConfig);
|
||||
ConfigurationSection playerConfig = config.getConfigurationSection(player.toString());
|
||||
if (playerConfig != null) {
|
||||
String color = playerConfig.getString(COLOR_CONFIG_NAME);
|
||||
if (color != null) {
|
||||
return DyeColor.valueOf(color);
|
||||
}
|
||||
}
|
||||
return DyeColor.RED;
|
||||
}
|
||||
plugin.getMessageSender().sendMessage(player, "color-successfully-set");
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Error while loading " + playerColorConfig.getName());
|
||||
plugin.getLogger()
|
||||
.log(
|
||||
Level.SEVERE,
|
||||
"Verify your syntax by visiting yaml-online-parser.appspot.com and using the following logs: ",
|
||||
e);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
StringBuilder colors = new StringBuilder();
|
||||
int length = DyeColor.values().length;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
DyeColor color = DyeColor.values()[i];
|
||||
colors.append(color.name().toLowerCase());
|
||||
if (i < length - 1) {
|
||||
colors.append(' ');
|
||||
}
|
||||
}
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(
|
||||
player,
|
||||
"available-colors",
|
||||
Placeholder.component("colors", Component.text(colors.toString())));
|
||||
}
|
||||
}
|
||||
|
||||
public DyeColor getColor(UUID player) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(playerColorConfig);
|
||||
ConfigurationSection playerConfig = config.getConfigurationSection(player.toString());
|
||||
if (playerConfig != null) {
|
||||
String color = playerConfig.getString(COLOR_CONFIG_NAME);
|
||||
if (color != null) {
|
||||
return DyeColor.valueOf(color);
|
||||
}
|
||||
}
|
||||
return DyeColor.RED;
|
||||
}
|
||||
}
|
||||
@@ -1,140 +1,135 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import com.hm.petmaster.files.PetAbilityFile;
|
||||
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SetConfigCommand {
|
||||
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
|
||||
public SetConfigCommand(PetMaster plugin) {
|
||||
public SetConfigCommand(PetMaster plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
}
|
||||
public void setConfigCommand(Player player, String[] args) {
|
||||
|
||||
public void setConfigCommand(Player player, String[] args) {
|
||||
if (player.hasPermission("petmaster.admin")) {
|
||||
|
||||
if(player.hasPermission("petmaster.admin")) {
|
||||
if (args[0].equalsIgnoreCase("set")) {
|
||||
|
||||
if(args[0].equalsIgnoreCase("set")) {
|
||||
if (args[1].equalsIgnoreCase("config")) {
|
||||
|
||||
if(args[1].equalsIgnoreCase("config")) {
|
||||
if (args[2].equalsIgnoreCase("set")) {
|
||||
|
||||
if(args[2].equalsIgnoreCase("set")) {
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("pet-abilities")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
if (args[2].equalsIgnoreCase("enabled")) {
|
||||
|
||||
}
|
||||
if (args[3].equalsIgnoreCase("true")) {
|
||||
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("pet-abilities")) {
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
|
||||
if(args[2].equalsIgnoreCase("enabled")) {
|
||||
PetAbilityFile.getPetAbilities().set("Is-Pet-Abilities-Enabled", true);
|
||||
}
|
||||
|
||||
if(args[3].equalsIgnoreCase("true")) {
|
||||
if (args[3].equalsIgnoreCase("false")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have disabled Pet Abilities!");
|
||||
|
||||
PetAbilityFile.getPetAbilities().set("Is-Pet-Abilities-Enabled", true);
|
||||
PetAbilityFile.getPetAbilities().set("Is-Pet-Abilities-Enabled", false);
|
||||
}
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("set")) {
|
||||
|
||||
}
|
||||
if (args[3].equalsIgnoreCase("health")) {
|
||||
|
||||
if(args[3].equalsIgnoreCase("false")) {
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
}
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have disabled Pet Abilities!");
|
||||
if (args[3].equalsIgnoreCase("damage")) {
|
||||
|
||||
PetAbilityFile.getPetAbilities().set("Is-Pet-Abilities-Enabled", false);
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
}
|
||||
|
||||
}
|
||||
if (args[3].equalsIgnoreCase("speed")) {
|
||||
|
||||
}
|
||||
if(args[2].equalsIgnoreCase("set")) {
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
}
|
||||
|
||||
if(args[3].equalsIgnoreCase("health")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
|
||||
}
|
||||
|
||||
if(args[3].equalsIgnoreCase("damage")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
|
||||
}
|
||||
|
||||
if(args[3].equalsIgnoreCase("speed")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
|
||||
}
|
||||
|
||||
if(args[3].equalsIgnoreCase("protection")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (args[3].equalsIgnoreCase("protection")) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(
|
||||
player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
UtilitiesOG.trueogMessage(player, "You have enabled Pet Abilities!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
/**
|
||||
* Class in charge of handling player requests to change ownership of a pet (/petm setowner).
|
||||
*
|
||||
@@ -17,45 +15,45 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class SetOwnerCommand {
|
||||
|
||||
private final PetMaster plugin;
|
||||
// Contains pairs with name of previous owner and new owner.
|
||||
private final Map<UUID, Player> changeOwnershipMap;
|
||||
private final PetMaster plugin;
|
||||
// Contains pairs with name of previous owner and new owner.
|
||||
private final Map<UUID, Player> changeOwnershipMap;
|
||||
|
||||
public SetOwnerCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
changeOwnershipMap = new HashMap<>();
|
||||
}
|
||||
public SetOwnerCommand(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
changeOwnershipMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setOwner(Player player, String[] args) {
|
||||
if (args.length == 2) {
|
||||
Player newOwner = null;
|
||||
for (Player currentPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (currentPlayer.getName().equalsIgnoreCase(args[1])) {
|
||||
newOwner = currentPlayer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newOwner == null) {
|
||||
plugin.getMessageSender().sendMessage(player, "player-offline");
|
||||
} else if (! player.hasPermission("petmaster.setowner")) {
|
||||
plugin.getMessageSender().sendMessage(player, "no-permissions");
|
||||
} else if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
plugin.getMessageSender().sendMessage(player, "currently-disabled");
|
||||
} else if (! player.hasPermission("petmaster.admin") && newOwner.getUniqueId().equals(player.getUniqueId())) {
|
||||
plugin.getMessageSender().sendMessage(player, "cannot-change-to-yourself");
|
||||
} else {
|
||||
changeOwnershipMap.put(player.getUniqueId(), newOwner);
|
||||
plugin.getMessageSender().sendMessage(player, "right-click");
|
||||
// Cancel previous pending operation.
|
||||
plugin.getFreeCommand().collectPendingFreeRequest(player);
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(player, "misused-command");
|
||||
}
|
||||
}
|
||||
|
||||
public Player collectPendingSetOwnershipRequest(Player player) {
|
||||
return changeOwnershipMap.remove(player.getUniqueId());
|
||||
}
|
||||
public void setOwner(Player player, String[] args) {
|
||||
if (args.length == 2) {
|
||||
Player newOwner = null;
|
||||
for (Player currentPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (currentPlayer.getName().equalsIgnoreCase(args[1])) {
|
||||
newOwner = currentPlayer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newOwner == null) {
|
||||
plugin.getMessageSender().sendMessage(player, "player-offline");
|
||||
} else if (!player.hasPermission("petmaster.setowner")) {
|
||||
plugin.getMessageSender().sendMessage(player, "no-permissions");
|
||||
} else if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
plugin.getMessageSender().sendMessage(player, "currently-disabled");
|
||||
} else if (!player.hasPermission("petmaster.admin")
|
||||
&& newOwner.getUniqueId().equals(player.getUniqueId())) {
|
||||
plugin.getMessageSender().sendMessage(player, "cannot-change-to-yourself");
|
||||
} else {
|
||||
changeOwnershipMap.put(player.getUniqueId(), newOwner);
|
||||
plugin.getMessageSender().sendMessage(player, "right-click");
|
||||
// Cancel previous pending operation.
|
||||
plugin.getFreeCommand().collectPendingFreeRequest(player);
|
||||
}
|
||||
} else {
|
||||
plugin.getMessageSender().sendMessage(player, "misused-command");
|
||||
}
|
||||
}
|
||||
|
||||
public Player collectPendingSetOwnershipRequest(Player player) {
|
||||
return changeOwnershipMap.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,31 @@
|
||||
package com.hm.petmaster.command;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
public class ShareCommand {
|
||||
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
PetMaster plugin = PetMaster.getPlugin(PetMaster.class);
|
||||
|
||||
public ShareCommand(PetMaster petMaster) {
|
||||
public ShareCommand(PetMaster petMaster) {
|
||||
|
||||
this.plugin = petMaster;
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
|
||||
}
|
||||
public void sharePetCommand(CommandSender sender) {
|
||||
|
||||
public void sharePetCommand(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" +"#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" +" This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
UtilitiesOG.trueogMessage(player, " ");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "# PetMaster Dev Note #");
|
||||
UtilitiesOG.trueogMessage(player, "&d" + "#-------------------------#");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " This is a test feature!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " It will be available soon!");
|
||||
UtilitiesOG.trueogMessage(player, plugin.getChatHeader() + "&d" + " Enjoy!");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2,99 +2,96 @@ package com.hm.petmaster.files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class PetAbilityFile {
|
||||
|
||||
private static File petAbilityFile;
|
||||
private static FileConfiguration petAbility;
|
||||
private static File petAbilityFile;
|
||||
private static FileConfiguration petAbility;
|
||||
|
||||
private static int wolfHealth = 0;
|
||||
private static int wolfDamage = 0;
|
||||
private static int wolfSpeed = 0;
|
||||
private static int wolfProtection = 0;
|
||||
private static int wolfHealth = 0;
|
||||
private static int wolfDamage = 0;
|
||||
private static int wolfSpeed = 0;
|
||||
private static int wolfProtection = 0;
|
||||
|
||||
private static int catHealth = 0;
|
||||
private static int catDamage = 0;
|
||||
private static int catSpeed = 0;
|
||||
private static int catProtection = 0;
|
||||
private static int catHealth = 0;
|
||||
private static int catDamage = 0;
|
||||
private static int catSpeed = 0;
|
||||
private static int catProtection = 0;
|
||||
|
||||
private static int donkeyHealth = 0;
|
||||
private static int donkeyDamage = 0;
|
||||
private static int donkeySpeed = 0;
|
||||
private static int donkeyProtection = 0;
|
||||
private static int donkeyHealth = 0;
|
||||
private static int donkeyDamage = 0;
|
||||
private static int donkeySpeed = 0;
|
||||
private static int donkeyProtection = 0;
|
||||
|
||||
private static int llamaHealth = 0;
|
||||
private static int llamaDamage = 0;
|
||||
private static int llamaSpeed = 0;
|
||||
private static int llamaProtection = 0;
|
||||
private static int llamaHealth = 0;
|
||||
private static int llamaDamage = 0;
|
||||
private static int llamaSpeed = 0;
|
||||
private static int llamaProtection = 0;
|
||||
|
||||
private static int parrotHealth = 0;
|
||||
private static int parrotDamage = 0;
|
||||
private static int parrotSpeed = 0;
|
||||
private static int parrotProtection = 0;
|
||||
private static int parrotHealth = 0;
|
||||
private static int parrotDamage = 0;
|
||||
private static int parrotSpeed = 0;
|
||||
private static int parrotProtection = 0;
|
||||
|
||||
public static void petAbilitySetup() {
|
||||
petAbilityFile = new File(Bukkit.getServer().getPluginManager().getPlugin("PetMaster").getDataFolder(),"petability.yml" );
|
||||
public static void petAbilitySetup() {
|
||||
petAbilityFile = new File(
|
||||
Bukkit.getServer().getPluginManager().getPlugin("PetMaster").getDataFolder(), "petability.yml");
|
||||
|
||||
if(!petAbilityFile.exists()) {
|
||||
try {
|
||||
petAbilityFile.createNewFile();
|
||||
}catch(IOException e) {
|
||||
if (!petAbilityFile.exists()) {
|
||||
try {
|
||||
petAbilityFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
petAbility = YamlConfiguration.loadConfiguration(petAbilityFile);
|
||||
}
|
||||
}
|
||||
petAbility = YamlConfiguration.loadConfiguration(petAbilityFile);
|
||||
}
|
||||
|
||||
}
|
||||
public static FileConfiguration getPetAbilities() {
|
||||
return petAbility;
|
||||
}
|
||||
|
||||
public static FileConfiguration getPetAbilities() {
|
||||
return petAbility;
|
||||
}
|
||||
public static void petAbilitySave() {
|
||||
try {
|
||||
petAbility.save(petAbilityFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void petAbilitySave() {
|
||||
try {
|
||||
petAbility.save(petAbilityFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
public static void petAbilityReload() {
|
||||
petAbility = YamlConfiguration.loadConfiguration(petAbilityFile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static void petAbilityAddDefaults() {
|
||||
petAbility.set("Is-Pet-Abilities-Enabled", true);
|
||||
|
||||
public static void petAbilityReload() {
|
||||
petAbility = YamlConfiguration.loadConfiguration(petAbilityFile);
|
||||
}
|
||||
petAbility.set("Wolf-Health", wolfHealth);
|
||||
petAbility.set("Wolf-Damage", wolfDamage);
|
||||
petAbility.set("Wolf-Speed", wolfSpeed);
|
||||
petAbility.set("Wolf-Protection", wolfProtection);
|
||||
|
||||
public static void petAbilityAddDefaults() {
|
||||
petAbility.set("Is-Pet-Abilities-Enabled", true);
|
||||
petAbility.set("Cat-Health", catHealth);
|
||||
petAbility.set("Cat-Damage", catDamage);
|
||||
petAbility.set("Cat-Speed", catSpeed);
|
||||
petAbility.set("Cat-Protection", catProtection);
|
||||
|
||||
petAbility.set("Wolf-Health", wolfHealth);
|
||||
petAbility.set("Wolf-Damage", wolfDamage);
|
||||
petAbility.set("Wolf-Speed", wolfSpeed);
|
||||
petAbility.set("Wolf-Protection", wolfProtection);
|
||||
petAbility.set("Donkey-Health", donkeyHealth);
|
||||
petAbility.set("Donkey-Damage", donkeyDamage);
|
||||
petAbility.set("Donkey-Speed", donkeySpeed);
|
||||
petAbility.set("Donkey-Protection", donkeyProtection);
|
||||
|
||||
petAbility.set("Cat-Health", catHealth);
|
||||
petAbility.set("Cat-Damage", catDamage);
|
||||
petAbility.set("Cat-Speed", catSpeed);
|
||||
petAbility.set("Cat-Protection", catProtection);
|
||||
|
||||
petAbility.set("Donkey-Health", donkeyHealth);
|
||||
petAbility.set("Donkey-Damage", donkeyDamage);
|
||||
petAbility.set("Donkey-Speed", donkeySpeed);
|
||||
petAbility.set("Donkey-Protection", donkeyProtection);
|
||||
|
||||
petAbility.set("Llama-Health", llamaHealth);
|
||||
petAbility.set("Llama-Damage", llamaDamage);
|
||||
petAbility.set("Llama-Speed", llamaSpeed);
|
||||
petAbility.set("Llama-Protection", llamaProtection);
|
||||
|
||||
petAbility.set("Parrot-Health", parrotHealth);
|
||||
petAbility.set("Parrot-Damage", parrotDamage);
|
||||
petAbility.set("Parrot-Speed", parrotSpeed);
|
||||
petAbility.set("Parrot-Protection", parrotProtection);
|
||||
}
|
||||
petAbility.set("Llama-Health", llamaHealth);
|
||||
petAbility.set("Llama-Damage", llamaDamage);
|
||||
petAbility.set("Llama-Speed", llamaSpeed);
|
||||
petAbility.set("Llama-Protection", llamaProtection);
|
||||
|
||||
petAbility.set("Parrot-Health", parrotHealth);
|
||||
petAbility.set("Parrot-Damage", parrotDamage);
|
||||
petAbility.set("Parrot-Speed", parrotSpeed);
|
||||
petAbility.set("Parrot-Protection", parrotProtection);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,31 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
public class PetDeathListener implements Listener {
|
||||
PetMaster plugin;
|
||||
|
||||
public class PetDeathListener implements Listener{
|
||||
PetMaster plugin;
|
||||
/*Tameable tameable;
|
||||
public PetDeathListener(PetMaster petMaster) {
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
|
||||
/*Tameable tameable;
|
||||
public PetDeathListener(PetMaster petMaster) {
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
boolean isTamed = tameable.isTamed();
|
||||
boolean isDead = tameable.isDead();
|
||||
|
||||
boolean isTamed = tameable.isTamed();
|
||||
boolean isDead = tameable.isDead();
|
||||
public void onPetDeath (EntityDeathEvent event) {
|
||||
if(event.getEntity() instanceof org.bukkit.entity.Tameable && isTamed == true && isDead == true) {
|
||||
tameable.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
isDead = true;
|
||||
isTamed = true;
|
||||
}
|
||||
else if(tameable == null) {
|
||||
return;
|
||||
|
||||
public void onPetDeath (EntityDeathEvent event) {
|
||||
if(event.getEntity() instanceof org.bukkit.entity.Tameable && isTamed == true && isDead == true) {
|
||||
tameable.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
isDead = true;
|
||||
isTamed = true;
|
||||
}
|
||||
else if(tameable == null) {
|
||||
return;
|
||||
|
||||
}else {
|
||||
isDead = false;
|
||||
isTamed =false;
|
||||
}
|
||||
}*/
|
||||
}else {
|
||||
isDead = false;
|
||||
isTamed =false;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -9,8 +10,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
/**
|
||||
* Class used to prevent player damage to pets who have an owner.
|
||||
*
|
||||
@@ -19,55 +18,56 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class PlayerAttackListener implements Listener {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
private boolean enableAngryMobPlayerDamage;
|
||||
private boolean enableAngryMobPlayerDamage;
|
||||
|
||||
public PlayerAttackListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public PlayerAttackListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void extractParameters() {
|
||||
enableAngryMobPlayerDamage = plugin.getPluginConfig().getBoolean("enableAngryMobPlayerDamage", true);
|
||||
}
|
||||
public void extractParameters() {
|
||||
enableAngryMobPlayerDamage = plugin.getPluginConfig().getBoolean("enableAngryMobPlayerDamage", true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerDamagePet(EntityDamageByEntityEvent event) {
|
||||
if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
return;
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerDamagePet(EntityDamageByEntityEvent event) {
|
||||
if (plugin.getEnableDisableCommand().isDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity damager = event.getDamager();
|
||||
Entity damaged = event.getEntity();
|
||||
if (! isDamagerProjectileOrPlayer(damager) || ! isDamagedOwned(damaged)) {
|
||||
return;
|
||||
}
|
||||
if (damager instanceof Projectile) {
|
||||
damager = (Entity) ((Projectile) damager).getShooter();
|
||||
}
|
||||
if (isDamagerPlayerDifferentFromDamagedOwner(damager, damaged)) {
|
||||
event.setCancelled(! enableAngryMobPlayerDamage || ! isDamagedTargettingDamager(damager, damaged));
|
||||
}
|
||||
}
|
||||
Entity damager = event.getDamager();
|
||||
Entity damaged = event.getEntity();
|
||||
if (!isDamagerProjectileOrPlayer(damager) || !isDamagedOwned(damaged)) {
|
||||
return;
|
||||
}
|
||||
if (damager instanceof Projectile) {
|
||||
damager = (Entity) ((Projectile) damager).getShooter();
|
||||
}
|
||||
if (isDamagerPlayerDifferentFromDamagedOwner(damager, damaged)) {
|
||||
event.setCancelled(!enableAngryMobPlayerDamage || !isDamagedTargettingDamager(damager, damaged));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDamagerProjectileOrPlayer(Entity damager) {
|
||||
return damager instanceof Projectile || damager instanceof Player;
|
||||
}
|
||||
private boolean isDamagerProjectileOrPlayer(Entity damager) {
|
||||
return damager instanceof Projectile || damager instanceof Player;
|
||||
}
|
||||
|
||||
private boolean isDamagedOwned(Entity damaged) {
|
||||
return damaged instanceof Tameable && ((Tameable) damaged).getOwner() != null;
|
||||
}
|
||||
private boolean isDamagedOwned(Entity damaged) {
|
||||
return damaged instanceof Tameable && ((Tameable) damaged).getOwner() != null;
|
||||
}
|
||||
|
||||
private boolean isDamagerPlayerDifferentFromDamagedOwner(Entity damager, Entity damaged) {
|
||||
return damager instanceof Player && ! ((Tameable) damaged).getOwner().getUniqueId().equals(damager.getUniqueId());
|
||||
}
|
||||
|
||||
private boolean isDamagedTargettingDamager(Entity damager, Entity damaged) {
|
||||
if (damaged instanceof Creature) {
|
||||
Creature creature = (Creature) damaged;
|
||||
return creature.getTarget() != null && creature.getTarget().getUniqueId().equals(damager.getUniqueId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean isDamagerPlayerDifferentFromDamagedOwner(Entity damager, Entity damaged) {
|
||||
return damager instanceof Player
|
||||
&& !((Tameable) damaged).getOwner().getUniqueId().equals(damager.getUniqueId());
|
||||
}
|
||||
|
||||
private boolean isDamagedTargettingDamager(Entity damager, Entity damaged) {
|
||||
if (damaged instanceof Creature) {
|
||||
Creature creature = (Creature) damaged;
|
||||
return creature.getTarget() != null
|
||||
&& creature.getTarget().getUniqueId().equals(damager.getUniqueId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -9,27 +10,25 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityBreedEvent;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
public class PlayerBreedListener implements Listener {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
public PlayerBreedListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBreedNewPet(EntityBreedEvent event) {
|
||||
if (plugin.getServerVersion() >= 14 && event.getEntity().getType().equals(EntityType.CAT)) {
|
||||
Cat cat = ((Cat) event.getEntity());
|
||||
DyeColor color = plugin.getSetColorCommand().getColor(cat.getOwner().getUniqueId());
|
||||
cat.setCollarColor(color);
|
||||
} else if (event.getEntity().getType().equals(EntityType.WOLF)) {
|
||||
Wolf wolf = ((Wolf) event.getEntity());
|
||||
DyeColor color = plugin.getSetColorCommand().getColor(wolf.getOwner().getUniqueId());
|
||||
wolf.setCollarColor(color);
|
||||
}
|
||||
}
|
||||
public PlayerBreedListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBreedNewPet(EntityBreedEvent event) {
|
||||
if (plugin.getServerVersion() >= 14 && event.getEntity().getType().equals(EntityType.CAT)) {
|
||||
Cat cat = ((Cat) event.getEntity());
|
||||
DyeColor color = plugin.getSetColorCommand().getColor(cat.getOwner().getUniqueId());
|
||||
cat.setCollarColor(color);
|
||||
} else if (event.getEntity().getType().equals(EntityType.WOLF)) {
|
||||
Wolf wolf = ((Wolf) event.getEntity());
|
||||
DyeColor color =
|
||||
plugin.getSetColorCommand().getColor(wolf.getOwner().getUniqueId());
|
||||
wolf.setCollarColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.mcshared.event.PlayerChangeAnimalOwnershipEvent;
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import eu.decentsoftware.holograms.api.DHAPI;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@@ -26,14 +31,6 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.hm.mcshared.event.PlayerChangeAnimalOwnershipEvent;
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import eu.decentsoftware.holograms.api.DHAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
/**
|
||||
* Class used to display holograms, change the owner of a pet or free a pet.
|
||||
*
|
||||
@@ -42,311 +39,327 @@ import net.milkbowl.vault.economy.Economy;
|
||||
*/
|
||||
public class PlayerInteractListener implements Listener {
|
||||
|
||||
// Vertical offsets of the holograms for each mob type.
|
||||
private static final double DOG_OFFSET = 1.5;
|
||||
private static final double CAT_OFFSET = 1.42;
|
||||
private static final double HORSE_OFFSET = 2.32;
|
||||
private static final double LLAMA_OFFSET = 2.42;
|
||||
private static final double PARROT_OFFSET = 1.15;
|
||||
// Vertical offsets of the holograms for each mob type.
|
||||
private static final double DOG_OFFSET = 1.5;
|
||||
private static final double CAT_OFFSET = 1.42;
|
||||
private static final double HORSE_OFFSET = 2.32;
|
||||
private static final double LLAMA_OFFSET = 2.42;
|
||||
private static final double PARROT_OFFSET = 1.15;
|
||||
|
||||
private final PetMaster plugin;
|
||||
private Economy economy;
|
||||
private final PetMaster plugin;
|
||||
private Economy economy;
|
||||
|
||||
// Configuration parameters.
|
||||
private boolean chatMessage;
|
||||
private boolean hologramMessage;
|
||||
private boolean actionBarMessage;
|
||||
private boolean displayDog;
|
||||
private boolean displayCat;
|
||||
private boolean displayHorse;
|
||||
private boolean displayLlama;
|
||||
private boolean displayParrot;
|
||||
private boolean displayToOwner;
|
||||
private int hologramDuration;
|
||||
private int changeOwnerPrice;
|
||||
private int freePetPrice;
|
||||
private boolean showHealth;
|
||||
private boolean disableRiding;
|
||||
// Configuration parameters.
|
||||
private boolean chatMessage;
|
||||
private boolean hologramMessage;
|
||||
private boolean actionBarMessage;
|
||||
private boolean displayDog;
|
||||
private boolean displayCat;
|
||||
private boolean displayHorse;
|
||||
private boolean displayLlama;
|
||||
private boolean displayParrot;
|
||||
private boolean displayToOwner;
|
||||
private int hologramDuration;
|
||||
private int changeOwnerPrice;
|
||||
private int freePetPrice;
|
||||
private boolean showHealth;
|
||||
private boolean disableRiding;
|
||||
|
||||
public PlayerInteractListener(PetMaster petMaster) {
|
||||
this.plugin = petMaster;
|
||||
// Try to retrieve an Economy instance from Vault.
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager()
|
||||
.getRegistration(Economy.class);
|
||||
if (rsp != null) {
|
||||
economy = rsp.getProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
public PlayerInteractListener(PetMaster petMaster) {
|
||||
this.plugin = petMaster;
|
||||
// Try to retrieve an Economy instance from Vault.
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp != null) {
|
||||
economy = rsp.getProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void extractParameters() {
|
||||
displayDog = plugin.getPluginConfig().getBoolean("displayDog", true);
|
||||
displayCat = plugin.getPluginConfig().getBoolean("displayCat", true);
|
||||
displayHorse = plugin.getPluginConfig().getBoolean("displayHorse", true);
|
||||
displayLlama = plugin.getPluginConfig().getBoolean("displayLlama", true);
|
||||
displayParrot = plugin.getPluginConfig().getBoolean("displayParrot", true);
|
||||
displayToOwner = plugin.getPluginConfig().getBoolean("displayToOwner", false);
|
||||
hologramDuration = plugin.getPluginConfig().getInt("hologramDuration", 50);
|
||||
changeOwnerPrice = plugin.getPluginConfig().getInt("changeOwnerPrice", 0);
|
||||
freePetPrice = plugin.getPluginConfig().getInt("freePetPrice", 0);
|
||||
chatMessage = plugin.getPluginConfig().getBoolean("chatMessage", true);
|
||||
hologramMessage = plugin.getPluginConfig().getBoolean("hologramMessage", false);
|
||||
actionBarMessage = plugin.getPluginConfig().getBoolean("actionBarMessage", true);
|
||||
showHealth = plugin.getPluginConfig().getBoolean("showHealth", true);
|
||||
disableRiding = plugin.getPluginConfig().getBoolean("disableRiding", false);
|
||||
public void extractParameters() {
|
||||
displayDog = plugin.getPluginConfig().getBoolean("displayDog", true);
|
||||
displayCat = plugin.getPluginConfig().getBoolean("displayCat", true);
|
||||
displayHorse = plugin.getPluginConfig().getBoolean("displayHorse", true);
|
||||
displayLlama = plugin.getPluginConfig().getBoolean("displayLlama", true);
|
||||
displayParrot = plugin.getPluginConfig().getBoolean("displayParrot", true);
|
||||
displayToOwner = plugin.getPluginConfig().getBoolean("displayToOwner", false);
|
||||
hologramDuration = plugin.getPluginConfig().getInt("hologramDuration", 50);
|
||||
changeOwnerPrice = plugin.getPluginConfig().getInt("changeOwnerPrice", 0);
|
||||
freePetPrice = plugin.getPluginConfig().getInt("freePetPrice", 0);
|
||||
chatMessage = plugin.getPluginConfig().getBoolean("chatMessage", true);
|
||||
hologramMessage = plugin.getPluginConfig().getBoolean("hologramMessage", false);
|
||||
actionBarMessage = plugin.getPluginConfig().getBoolean("actionBarMessage", true);
|
||||
showHealth = plugin.getPluginConfig().getBoolean("showHealth", true);
|
||||
disableRiding = plugin.getPluginConfig().getBoolean("disableRiding", false);
|
||||
|
||||
boolean decentHologramsAvailable = Bukkit.getPluginManager().isPluginEnabled("DecentHolograms");
|
||||
// Checking whether user configured plugin to display hologram but HolographicsDisplays not available.
|
||||
if (hologramMessage && !decentHologramsAvailable) {
|
||||
hologramMessage = false;
|
||||
actionBarMessage = true;
|
||||
plugin.getLogger().warning(
|
||||
"DecentHolograms was not found; disabling usage of holograms and enabling action bar messages.");
|
||||
}
|
||||
}
|
||||
boolean decentHologramsAvailable = Bukkit.getPluginManager().isPluginEnabled("DecentHolograms");
|
||||
// Checking whether user configured plugin to display hologram but HolographicsDisplays not available.
|
||||
if (hologramMessage && !decentHologramsAvailable) {
|
||||
hologramMessage = false;
|
||||
actionBarMessage = true;
|
||||
plugin.getLogger()
|
||||
.warning(
|
||||
"DecentHolograms was not found; disabling usage of holograms and enabling action bar messages.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
|
||||
if (shouldHandleEvent(event)) {
|
||||
Tameable tameable = (Tameable) event.getRightClicked();
|
||||
AnimalTamer currentOwner = tameable.getOwner();
|
||||
if (currentOwner == null || currentOwner.getName() == null) {
|
||||
return;
|
||||
}
|
||||
// Has the player clicked on one of his own pets?
|
||||
Player player = event.getPlayer();
|
||||
boolean isOwner = player.getUniqueId().equals(currentOwner.getUniqueId());
|
||||
// Retrieve new owner from the map and delete corresponding entry.
|
||||
Player newOwner = plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
|
||||
// Has the player requested to free one of his pets?
|
||||
boolean freePet = plugin.getFreeCommand().collectPendingFreeRequest(player);
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
|
||||
if (shouldHandleEvent(event)) {
|
||||
Tameable tameable = (Tameable) event.getRightClicked();
|
||||
AnimalTamer currentOwner = tameable.getOwner();
|
||||
if (currentOwner == null || currentOwner.getName() == null) {
|
||||
return;
|
||||
}
|
||||
// Has the player clicked on one of his own pets?
|
||||
Player player = event.getPlayer();
|
||||
boolean isOwner = player.getUniqueId().equals(currentOwner.getUniqueId());
|
||||
// Retrieve new owner from the map and delete corresponding entry.
|
||||
Player newOwner = plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
|
||||
// Has the player requested to free one of his pets?
|
||||
boolean freePet = plugin.getFreeCommand().collectPendingFreeRequest(player);
|
||||
|
||||
if (disableRiding && ! isOwner && !player.hasPermission("petmaster.admin") && tameable instanceof Vehicle) {
|
||||
plugin.getMessageSender().sendMessage(player, "not-owner");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (disableRiding && !isOwner && !player.hasPermission("petmaster.admin") && tameable instanceof Vehicle) {
|
||||
plugin.getMessageSender().sendMessage(player, "not-owner");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cannot change ownership or free pet if not owner and no bypass permission.
|
||||
if ((newOwner != null || freePet) && ! isOwner && !player.hasPermission("petmaster.admin")) {
|
||||
plugin.getMessageSender().sendMessage(player, "not-owner");
|
||||
return;
|
||||
}
|
||||
// Cannot change ownership or free pet if not owner and no bypass permission.
|
||||
if ((newOwner != null || freePet) && !isOwner && !player.hasPermission("petmaster.admin")) {
|
||||
plugin.getMessageSender().sendMessage(player, "not-owner");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newOwner != null) {
|
||||
changeOwner(player, currentOwner, newOwner, tameable);
|
||||
} else if (freePet) {
|
||||
freePet(player, currentOwner, tameable);
|
||||
} else if ((displayToOwner || ! isOwner) && player.hasPermission("petmaster.showowner.*")) {
|
||||
displayHologramAndMessage(player, currentOwner, tameable);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newOwner != null) {
|
||||
changeOwner(player, currentOwner, newOwner, tameable);
|
||||
} else if (freePet) {
|
||||
freePet(player, currentOwner, tameable);
|
||||
} else if ((displayToOwner || !isOwner) && player.hasPermission("petmaster.showowner.*")) {
|
||||
displayHologramAndMessage(player, currentOwner, tameable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current PlayerInteractEntityEvent should be handled.
|
||||
*
|
||||
* @param event
|
||||
* @return true if the event should be handled, false otherwise
|
||||
*/
|
||||
private boolean shouldHandleEvent(PlayerInteractEntityEvent event) {
|
||||
return !plugin.getEnableDisableCommand().isDisabled() && event.getRightClicked() instanceof Tameable
|
||||
// On Minecraft 1.9+, the event is fired once per hand (HAND and OFF_HAND).
|
||||
&& (plugin.getServerVersion() < 9 || event.getHand() == EquipmentSlot.HAND);
|
||||
}
|
||||
/**
|
||||
* Determines whether the current PlayerInteractEntityEvent should be handled.
|
||||
*
|
||||
* @param event
|
||||
* @return true if the event should be handled, false otherwise
|
||||
*/
|
||||
private boolean shouldHandleEvent(PlayerInteractEntityEvent event) {
|
||||
return !plugin.getEnableDisableCommand().isDisabled()
|
||||
&& event.getRightClicked() instanceof Tameable
|
||||
// On Minecraft 1.9+, the event is fired once per hand (HAND and OFF_HAND).
|
||||
&& (plugin.getServerVersion() < 9 || event.getHand() == EquipmentSlot.HAND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the owner of a pet.
|
||||
*
|
||||
* @param player
|
||||
* @param oldOwner
|
||||
* @param newOwner
|
||||
* @param tameable
|
||||
*/
|
||||
private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, Tameable tameable) {
|
||||
if (chargePrice(player, changeOwnerPrice)) {
|
||||
// Change owner.
|
||||
tameable.setOwner(newOwner);
|
||||
player.sendMessage(plugin.getChatHeader()
|
||||
+ 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", oldOwner.getName()));
|
||||
/**
|
||||
* Change the owner of a pet.
|
||||
*
|
||||
* @param player
|
||||
* @param oldOwner
|
||||
* @param newOwner
|
||||
* @param tameable
|
||||
*/
|
||||
private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, Tameable tameable) {
|
||||
if (chargePrice(player, changeOwnerPrice)) {
|
||||
// Change owner.
|
||||
tameable.setOwner(newOwner);
|
||||
player.sendMessage(plugin.getChatHeader()
|
||||
+ 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", oldOwner.getName()));
|
||||
|
||||
// Create new event to allow other plugins to be aware of the ownership change.
|
||||
PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent = new PlayerChangeAnimalOwnershipEvent(
|
||||
oldOwner, newOwner, tameable);
|
||||
Bukkit.getServer().getPluginManager().callEvent(playerChangeAnimalOwnershipEvent);
|
||||
}
|
||||
}
|
||||
// Create new event to allow other plugins to be aware of the ownership change.
|
||||
PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent =
|
||||
new PlayerChangeAnimalOwnershipEvent(oldOwner, newOwner, tameable);
|
||||
Bukkit.getServer().getPluginManager().callEvent(playerChangeAnimalOwnershipEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees a pet; it will no longer be tamed.
|
||||
*
|
||||
* @param player
|
||||
* @param oldOwner
|
||||
* @param tameable
|
||||
*/
|
||||
private void freePet(Player player, AnimalTamer oldOwner, Tameable tameable) {
|
||||
if (chargePrice(player, freePetPrice)) {
|
||||
// Free pet.
|
||||
tameable.setTamed(false);
|
||||
// Make freed pet stand up.
|
||||
if (plugin.getServerVersion() >= 12 && tameable instanceof Sittable) {
|
||||
((Sittable) tameable).setSitting(false);
|
||||
} else if (tameable instanceof Wolf) {
|
||||
((Wolf) tameable).setSitting(false);
|
||||
} else if (tameable instanceof Ocelot) {
|
||||
// Since Minecraft 1.14, ocelots are no longer Sittable, use reflection for old game versions.
|
||||
try {
|
||||
Method setSitting = Ocelot.class.getMethod("setSitting", boolean.class);
|
||||
setSitting.invoke(tameable, false);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.getLogger().warning("Failed to make freed ocelot stand up.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Frees a pet; it will no longer be tamed.
|
||||
*
|
||||
* @param player
|
||||
* @param oldOwner
|
||||
* @param tameable
|
||||
*/
|
||||
private void freePet(Player player, AnimalTamer oldOwner, Tameable tameable) {
|
||||
if (chargePrice(player, freePetPrice)) {
|
||||
// Free pet.
|
||||
tameable.setTamed(false);
|
||||
// Make freed pet stand up.
|
||||
if (plugin.getServerVersion() >= 12 && tameable instanceof Sittable) {
|
||||
((Sittable) tameable).setSitting(false);
|
||||
} else if (tameable instanceof Wolf) {
|
||||
((Wolf) tameable).setSitting(false);
|
||||
} else if (tameable instanceof Ocelot) {
|
||||
// Since Minecraft 1.14, ocelots are no longer Sittable, use reflection for old game versions.
|
||||
try {
|
||||
Method setSitting = Ocelot.class.getMethod("setSitting", boolean.class);
|
||||
setSitting.invoke(tameable, false);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.getLogger().warning("Failed to make freed ocelot stand up.");
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getMessageSender().sendMessage(player, "pet-freed");
|
||||
plugin.getMessageSender().sendMessage(player, "pet-freed");
|
||||
|
||||
// Create new event to allow other plugins to be aware of the freeing.
|
||||
PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent = new PlayerChangeAnimalOwnershipEvent(
|
||||
oldOwner, null, tameable);
|
||||
Bukkit.getServer().getPluginManager().callEvent(playerChangeAnimalOwnershipEvent);
|
||||
}
|
||||
}
|
||||
// Create new event to allow other plugins to be aware of the freeing.
|
||||
PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent =
|
||||
new PlayerChangeAnimalOwnershipEvent(oldOwner, null, tameable);
|
||||
Bukkit.getServer().getPluginManager().callEvent(playerChangeAnimalOwnershipEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a hologram, and automatically delete it after a given delay.
|
||||
*
|
||||
* @param player
|
||||
* @param owner
|
||||
* @param tameable
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameable tameable) {
|
||||
if (hologramMessage) {
|
||||
int version = plugin.getServerVersion();
|
||||
double offset = HORSE_OFFSET;
|
||||
if (tameable instanceof Ocelot || version >= 14 && tameable instanceof Cat) {
|
||||
if (! displayCat || !player.hasPermission("petmaster.showowner.cat")) {
|
||||
return;
|
||||
}
|
||||
offset = CAT_OFFSET;
|
||||
} else if (tameable instanceof Wolf) {
|
||||
if (! displayDog || !player.hasPermission("petmaster.showowner.dog")) {
|
||||
return;
|
||||
}
|
||||
offset = DOG_OFFSET;
|
||||
} else if (version >= 11 && tameable instanceof Llama) {
|
||||
if (! displayLlama || !player.hasPermission("petmaster.showowner.llama")) {
|
||||
return;
|
||||
}
|
||||
offset = LLAMA_OFFSET;
|
||||
} else if (version >= 12 && tameable instanceof Parrot) {
|
||||
if (! displayParrot || !player.hasPermission("petmaster.showowner.parrot")) {
|
||||
return;
|
||||
}
|
||||
offset = PARROT_OFFSET;
|
||||
} else if (tameable instanceof Vehicle) {
|
||||
if (! displayHorse || !player.hasPermission("petmaster.showowner.horse")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Displays a hologram, and automatically delete it after a given delay.
|
||||
*
|
||||
* @param player
|
||||
* @param owner
|
||||
* @param tameable
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameable tameable) {
|
||||
if (hologramMessage) {
|
||||
int version = plugin.getServerVersion();
|
||||
double offset = HORSE_OFFSET;
|
||||
if (tameable instanceof Ocelot || version >= 14 && tameable instanceof Cat) {
|
||||
if (!displayCat || !player.hasPermission("petmaster.showowner.cat")) {
|
||||
return;
|
||||
}
|
||||
offset = CAT_OFFSET;
|
||||
} else if (tameable instanceof Wolf) {
|
||||
if (!displayDog || !player.hasPermission("petmaster.showowner.dog")) {
|
||||
return;
|
||||
}
|
||||
offset = DOG_OFFSET;
|
||||
} else if (version >= 11 && tameable instanceof Llama) {
|
||||
if (!displayLlama || !player.hasPermission("petmaster.showowner.llama")) {
|
||||
return;
|
||||
}
|
||||
offset = LLAMA_OFFSET;
|
||||
} else if (version >= 12 && tameable instanceof Parrot) {
|
||||
if (!displayParrot || !player.hasPermission("petmaster.showowner.parrot")) {
|
||||
return;
|
||||
}
|
||||
offset = PARROT_OFFSET;
|
||||
} else if (tameable instanceof Vehicle) {
|
||||
if (!displayHorse || !player.hasPermission("petmaster.showowner.horse")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Location eventLocation = ((Animals) tameable).getLocation();
|
||||
// Create location with offset.
|
||||
Location hologramLocation = new Location(eventLocation.getWorld(), eventLocation.getX(),
|
||||
eventLocation.getY() + offset, eventLocation.getZ());
|
||||
Location eventLocation = ((Animals) tameable).getLocation();
|
||||
// Create location with offset.
|
||||
Location hologramLocation = new Location(
|
||||
eventLocation.getWorld(),
|
||||
eventLocation.getX(),
|
||||
eventLocation.getY() + offset,
|
||||
eventLocation.getZ());
|
||||
|
||||
String hologramname = player.getUniqueId() + "_pm";
|
||||
|
||||
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"))));
|
||||
|
||||
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) {
|
||||
DHAPI.createHologram(hologramname, hologramLocation, lines);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DHAPI.getHologram(hologramname) == null) {
|
||||
DHAPI.createHologram(hologramname, hologramLocation, lines);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// Runnable to delete hologram.
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
// Runnable to delete hologram.
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
new BukkitRunnable() {
|
||||
DHAPI.removeHologram(hologramname);
|
||||
}
|
||||
}.runTaskLater(plugin, hologramDuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Component healthInfo = null;
|
||||
if (showHealth) {
|
||||
Animals animal = (Animals) tameable;
|
||||
healthInfo = plugin.getMessageSender()
|
||||
.parseMessage(
|
||||
plugin.getPluginLang().getString("petmaster-health"),
|
||||
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()))));
|
||||
}
|
||||
|
||||
DHAPI.removeHologram(hologramname);
|
||||
}
|
||||
}.runTaskLater(plugin, hologramDuration);
|
||||
}
|
||||
if (chatMessage) {
|
||||
Component parsedComponent = plugin.getMessageSender()
|
||||
.parseMessage(
|
||||
plugin.getPluginLang().getString("petmaster-chat"),
|
||||
Placeholder.component(
|
||||
"owner", Component.text(owner.getName() != null ? owner.getName() : "null")));
|
||||
if (healthInfo != null) {
|
||||
parsedComponent = parsedComponent.append(healthInfo);
|
||||
}
|
||||
plugin.getMessageSender().sendComponent(player, parsedComponent);
|
||||
}
|
||||
|
||||
Component healthInfo = null;
|
||||
if (showHealth) {
|
||||
Animals animal = (Animals) tameable;
|
||||
healthInfo = plugin.getMessageSender().parseMessage(
|
||||
plugin.getPluginLang().getString("petmaster-health"),
|
||||
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()))));
|
||||
}
|
||||
|
||||
if (chatMessage) {
|
||||
Component parsedComponent = plugin.getMessageSender().parseMessage(
|
||||
plugin.getPluginLang().getString("petmaster-chat"),
|
||||
Placeholder.component("owner", Component.text(owner.getName() != null ? owner.getName() : "null")));
|
||||
if (healthInfo != null){
|
||||
parsedComponent = parsedComponent.append(healthInfo);
|
||||
}
|
||||
plugin.getMessageSender().sendComponent(player, parsedComponent);
|
||||
}
|
||||
|
||||
if (actionBarMessage) {
|
||||
Component parsedComponent = plugin.getMessageSender().parseMessage(
|
||||
plugin.getPluginLang().getString("petmaster-action-bar"),
|
||||
Placeholder.component("owner", Component.text(owner.getName() != null ? owner.getName() : "null")));
|
||||
if (healthInfo != null){
|
||||
parsedComponent = parsedComponent.append(healthInfo);
|
||||
}
|
||||
plugin.getMessageSender().sendComponentToActionBar(player, parsedComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private boolean chargePrice(Player player, int price) {
|
||||
// Charge player for changing ownership.
|
||||
if (price > 0 && !player.hasPermission("petmaster.admin") && economy != null) {
|
||||
// If server has set different currency names depending on amount, adapt message accordingly.
|
||||
String priceWithCurrency = price + " "
|
||||
+ (price > 1 ? economy.currencyNamePlural() : economy.currencyNameSingular());
|
||||
if (economy.getBalance(player) < price) {
|
||||
plugin.getMessageSender().sendMessage(
|
||||
player,
|
||||
"not-enough-money",
|
||||
Placeholder.component("amount", Component.text(priceWithCurrency))
|
||||
);
|
||||
return false;
|
||||
}
|
||||
economy.withdrawPlayer(player, price);
|
||||
plugin.getMessageSender().sendMessage(
|
||||
player,
|
||||
"change-owner-price",
|
||||
Placeholder.component("amount", Component.text(priceWithCurrency))
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (actionBarMessage) {
|
||||
Component parsedComponent = plugin.getMessageSender()
|
||||
.parseMessage(
|
||||
plugin.getPluginLang().getString("petmaster-action-bar"),
|
||||
Placeholder.component(
|
||||
"owner", Component.text(owner.getName() != null ? owner.getName() : "null")));
|
||||
if (healthInfo != null) {
|
||||
parsedComponent = parsedComponent.append(healthInfo);
|
||||
}
|
||||
plugin.getMessageSender().sendComponentToActionBar(player, parsedComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private boolean chargePrice(Player player, int price) {
|
||||
// Charge player for changing ownership.
|
||||
if (price > 0 && !player.hasPermission("petmaster.admin") && economy != null) {
|
||||
// If server has set different currency names depending on amount, adapt message accordingly.
|
||||
String priceWithCurrency =
|
||||
price + " " + (price > 1 ? economy.currencyNamePlural() : economy.currencyNameSingular());
|
||||
if (economy.getBalance(player) < price) {
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(
|
||||
player,
|
||||
"not-enough-money",
|
||||
Placeholder.component("amount", Component.text(priceWithCurrency)));
|
||||
return false;
|
||||
}
|
||||
economy.withdrawPlayer(player, price);
|
||||
plugin.getMessageSender()
|
||||
.sendMessage(
|
||||
player,
|
||||
"change-owner-price",
|
||||
Placeholder.component("amount", Component.text(priceWithCurrency)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -9,39 +10,35 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerLeashEntityEvent;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
public class PlayerLeashListener implements Listener {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
// Configuration parameters.
|
||||
private boolean disableLeash;
|
||||
// Configuration parameters.
|
||||
private boolean disableLeash;
|
||||
|
||||
public PlayerLeashListener(PetMaster petMaster) {
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
public PlayerLeashListener(PetMaster petMaster) {
|
||||
this.plugin = petMaster;
|
||||
}
|
||||
|
||||
public void extractParameters() {
|
||||
disableLeash = plugin.getPluginConfig().getBoolean("disableLeash", false);
|
||||
}
|
||||
public void extractParameters() {
|
||||
disableLeash = plugin.getPluginConfig().getBoolean("disableLeash", false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerLeashEntityEvent(PlayerLeashEntityEvent event) {
|
||||
if (plugin.getEnableDisableCommand().isDisabled() || ! disableLeash)
|
||||
return;
|
||||
Entity entity = event.getEntity();
|
||||
if (! (entity instanceof Tameable))
|
||||
return;
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerLeashEntityEvent(PlayerLeashEntityEvent event) {
|
||||
if (plugin.getEnableDisableCommand().isDisabled() || !disableLeash) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Tameable)) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Tameable tameable = (Tameable) entity;
|
||||
AnimalTamer currentOwner = tameable.getOwner();
|
||||
if (currentOwner == null || currentOwner.getUniqueId().equals(player.getUniqueId()) || player.hasPermission("petmaster.admin"))
|
||||
return;
|
||||
|
||||
plugin.getMessageSender().sendMessage(player, "not-owner");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Tameable tameable = (Tameable) entity;
|
||||
AnimalTamer currentOwner = tameable.getOwner();
|
||||
if (currentOwner == null
|
||||
|| currentOwner.getUniqueId().equals(player.getUniqueId())
|
||||
|| player.hasPermission("petmaster.admin")) return;
|
||||
|
||||
plugin.getMessageSender().sendMessage(player, "not-owner");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
/**
|
||||
* Class used to empty the change ownership map when a player quits the server, to avoid memory leaks.
|
||||
*
|
||||
@@ -15,17 +14,16 @@ import com.hm.petmaster.PetMaster;
|
||||
*/
|
||||
public class PlayerQuitListener implements Listener {
|
||||
|
||||
private PetMaster plugin;
|
||||
private PetMaster plugin;
|
||||
|
||||
public PlayerQuitListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
// Delete pending requests.
|
||||
plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(event.getPlayer());
|
||||
plugin.getFreeCommand().collectPendingFreeRequest(event.getPlayer());
|
||||
}
|
||||
public PlayerQuitListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
// Delete pending requests.
|
||||
plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(event.getPlayer());
|
||||
plugin.getFreeCommand().collectPendingFreeRequest(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hm.petmaster.listener;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -9,25 +10,24 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTameEvent;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
public class PlayerTameListener implements Listener {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final PetMaster plugin;
|
||||
|
||||
public PlayerTameListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerTamePet(EntityTameEvent event) {
|
||||
if (plugin.getServerVersion() >= 14 && event.getEntity().getType().equals(EntityType.CAT)) {
|
||||
DyeColor color = plugin.getSetColorCommand().getColor(event.getOwner().getUniqueId());
|
||||
((Cat) event.getEntity()).setCollarColor(color);
|
||||
} else if (event.getEntity().getType().equals(EntityType.WOLF)) {
|
||||
DyeColor color = plugin.getSetColorCommand().getColor(event.getOwner().getUniqueId());
|
||||
((Wolf) event.getEntity()).setCollarColor(color);
|
||||
}
|
||||
}
|
||||
public PlayerTameListener(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerTamePet(EntityTameEvent event) {
|
||||
if (plugin.getServerVersion() >= 14 && event.getEntity().getType().equals(EntityType.CAT)) {
|
||||
DyeColor color =
|
||||
plugin.getSetColorCommand().getColor(event.getOwner().getUniqueId());
|
||||
((Cat) event.getEntity()).setCollarColor(color);
|
||||
} else if (event.getEntity().getType().equals(EntityType.WOLF)) {
|
||||
DyeColor color =
|
||||
plugin.getSetColorCommand().getColor(event.getOwner().getUniqueId());
|
||||
((Wolf) event.getEntity()).setCollarColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +1,83 @@
|
||||
package com.hm.petmaster.utils;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.hm.petmaster.PetMaster;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MessageSender {
|
||||
|
||||
private final PetMaster plugin;
|
||||
private final MiniMessage miniMessage;
|
||||
private final PetMaster plugin;
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public MessageSender(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
miniMessage = MiniMessage.miniMessage();
|
||||
}
|
||||
public MessageSender(PetMaster plugin) {
|
||||
this.plugin = plugin;
|
||||
miniMessage = MiniMessage.miniMessage();
|
||||
}
|
||||
|
||||
public String parseMessageToString(String key, TagResolver... tagResolvers) {
|
||||
return LegacyComponentSerializer.builder()
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build()
|
||||
.serialize(parseMessage(plugin.getPluginLang().getString(key), tagResolvers));
|
||||
}
|
||||
|
||||
public String parseMessageToString(String key, TagResolver... tagResolvers) {
|
||||
return LegacyComponentSerializer.builder().useUnusualXRepeatedCharacterHexFormat().build().serialize(
|
||||
parseMessage(plugin.getPluginLang().getString(key), tagResolvers));
|
||||
}
|
||||
public Component parseMessage(String message, TagResolver... tagResolvers) {
|
||||
List<TagResolver> allTagResolvers =
|
||||
new ArrayList<>(Arrays.stream(tagResolvers).toList());
|
||||
allTagResolvers.add(Placeholder.parsed(
|
||||
"prefix", plugin.getPluginLang().getString("petmaster-prefix", "<gray>[<gold>♞<gray>] ")));
|
||||
return miniMessage.deserialize(message, allTagResolvers.toArray(new TagResolver[] {}));
|
||||
}
|
||||
|
||||
public Component parseMessage(String message, TagResolver... tagResolvers) {
|
||||
List<TagResolver> allTagResolvers = new ArrayList<>(Arrays.stream(tagResolvers).toList());
|
||||
allTagResolvers.add(Placeholder.parsed(
|
||||
"prefix",
|
||||
plugin.getPluginLang().getString("petmaster-prefix", "<gray>[<gold>♞<gray>] ")));
|
||||
return miniMessage.deserialize(message, allTagResolvers.toArray(new TagResolver[]{}));
|
||||
}
|
||||
public void sendComponent(Player player, Component component) {
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
public void sendComponent(Player player, Component component){
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
public void sendComponentToActionBar(Player player, Component component) {
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
audience.sendActionBar(component);
|
||||
}
|
||||
|
||||
public void sendComponentToActionBar(Player player, Component component){
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
audience.sendActionBar(component);
|
||||
}
|
||||
public void sendMessage(Audience audience, String key, TagResolver... tagResolvers) {
|
||||
audience.sendMessage(parseMessage(plugin.getPluginLang().getString(key), tagResolvers));
|
||||
}
|
||||
|
||||
public void sendMessage(Audience audience, String key, TagResolver... tagResolvers) {
|
||||
audience.sendMessage(parseMessage(plugin.getPluginLang().getString(key), tagResolvers));
|
||||
}
|
||||
public void sendMessage(Player player, String key, TagResolver... tagResolvers) {
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
sendMessage(audience, key, tagResolvers);
|
||||
}
|
||||
|
||||
public void sendMessage(Player player, String key, TagResolver... tagResolvers) {
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
sendMessage(audience, key, tagResolvers);
|
||||
}
|
||||
public void sendMessage(CommandSender sender, String key, TagResolver... tagResolvers) {
|
||||
Audience audience = plugin.adventure().sender(sender);
|
||||
sendMessage(audience, key, tagResolvers);
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender sender, String key, TagResolver... tagResolvers) {
|
||||
Audience audience = plugin.adventure().sender(sender);
|
||||
sendMessage(audience, key, tagResolvers);
|
||||
}
|
||||
public void sendActionBar(Audience audience, String key, TagResolver... tagResolvers) {
|
||||
audience.sendActionBar(parseMessage(plugin.getPluginLang().getString(key), tagResolvers));
|
||||
}
|
||||
|
||||
public void sendActionBar(Audience audience, String key, TagResolver... tagResolvers) {
|
||||
audience.sendActionBar(parseMessage(plugin.getPluginLang().getString(key), tagResolvers));
|
||||
}
|
||||
public void sendActionBar(Player player, String key, TagResolver... tagResolvers) {
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
sendActionBar(audience, key, tagResolvers);
|
||||
}
|
||||
|
||||
public void sendActionBar(Player player, String key, TagResolver... tagResolvers) {
|
||||
Audience audience = plugin.adventure().player(player);
|
||||
sendActionBar(audience, key, tagResolvers);
|
||||
}
|
||||
|
||||
public void sendNewLine(CommandSender sender, boolean sendPrefix){
|
||||
Audience audience = plugin.adventure().sender(sender);
|
||||
|
||||
if (sendPrefix){
|
||||
sendMessage(audience, "petmaster-prefix");
|
||||
} else {
|
||||
audience.sendMessage(Component.newline());
|
||||
}
|
||||
}
|
||||
public void sendNewLine(CommandSender sender, boolean sendPrefix) {
|
||||
Audience audience = plugin.adventure().sender(sender);
|
||||
|
||||
if (sendPrefix) {
|
||||
sendMessage(audience, "petmaster-prefix");
|
||||
} else {
|
||||
audience.sendMessage(Component.newline());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,32 +4,41 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
public class TabCompleterPetm implements TabCompleter{
|
||||
public class TabCompleterPetm implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> list = Arrays.asList("help", "info" ,"reload", "disable", "enable", " setowner", "free", "setcolor", "sharepet", "godpet", "petskill");
|
||||
String input = args[0].toLowerCase();
|
||||
|
||||
List<String> completions = null;
|
||||
for (String s : list) {
|
||||
if (s.startsWith(input)) {
|
||||
if (completions == null) {
|
||||
completions = new ArrayList<>();
|
||||
}
|
||||
completions.add(s);
|
||||
}
|
||||
}
|
||||
if (completions != null) {
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> list = Arrays.asList(
|
||||
"help",
|
||||
"info",
|
||||
"reload",
|
||||
"disable",
|
||||
"enable",
|
||||
" setowner",
|
||||
"free",
|
||||
"setcolor",
|
||||
"sharepet",
|
||||
"godpet",
|
||||
"petskill");
|
||||
String input = args[0].toLowerCase();
|
||||
|
||||
List<String> completions = null;
|
||||
for (String s : list) {
|
||||
if (s.startsWith(input)) {
|
||||
if (completions == null) {
|
||||
completions = new ArrayList<>();
|
||||
}
|
||||
completions.add(s);
|
||||
}
|
||||
}
|
||||
if (completions != null) {
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user