Skip to content

Commit

Permalink
Merge pull request #559 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to master --release
  • Loading branch information
Shynixn authored Dec 2, 2023
2 parents b90ee40 + 4a7d4ee commit 068ed09
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 108 deletions.
47 changes: 3 additions & 44 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.github.shynixn"
version = "9.0.1"
version = "9.0.2"

repositories {
mavenCentral()
Expand Down Expand Up @@ -40,8 +40,8 @@ dependencies {
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.4.3")

// Custom dependencies
implementation("com.github.shynixn.mcutils:common:1.0.39")
implementation("com.github.shynixn.mcutils:packet:1.0.56")
implementation("com.github.shynixn.mcutils:common:1.0.40")
implementation("com.github.shynixn.mcutils:packet:1.0.60")
implementation("com.github.shynixn.mcutils:database:1.0.14")
implementation("com.github.shynixn.mcutils:pathfinder:1.0.19")

Expand Down Expand Up @@ -91,48 +91,9 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
*/
tasks.register("pluginJars") {
dependsOn("pluginJarLatest")
dependsOn("pluginJarLegacy")
dependsOn("pluginJarPremium")
}

/**
* Create legacy plugin jar file.
*/
tasks.register("relocateLegacyPluginJar", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class.java) {
dependsOn("shadowJar")
from(zipTree(File("./build/libs/" + (tasks.getByName("shadowJar") as Jar).archiveName)))
archiveName = "${baseName}-${version}-legacy-relocate.${extension}"
relocate("com.github.shynixn.mcutils", "com.github.shynixn.petblocks.lib.com.github.shynixn.mcutils")
relocate("kotlin", "com.github.shynixn.petblocks.lib.kotlin")
relocate("org.intellij", "com.github.shynixn.petblocks.lib.org.intelli")
relocate("javax", "com.github.shynixn.petblocks.lib.javax")
relocate("kotlinx", "com.github.shynixn.petblocks.lib.kotlinx")
relocate("com.google", "com.github.shynixn.petblocks.lib.com.google")
relocate("com.fasterxml", "com.github.shynixn.petblocks.lib.com.fasterxml")
relocate("com.github.shynixn.mccoroutine", "com.github.shynixn.petblocks.lib.com.github.shynixn.mccoroutine")
exclude("plugin.yml")
rename("plugin-legacy.yml", "plugin.yml")
}

/**
* Create legacy plugin jar file.
*/
tasks.register("pluginJarLegacy", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class.java) {
dependsOn("relocateLegacyPluginJar")
from(zipTree(File("./build/libs/" + (tasks.getByName("relocateLegacyPluginJar") as Jar).archiveName)))
archiveName = "${baseName}-${version}-legacy.${extension}"
// destinationDir = File("C:\\temp\\plugins")
exclude("com/github/shynixn/mcutils/**")
exclude("org/**")
exclude("kotlin/**")
exclude("kotlinx/**")
exclude("javax/**")
exclude("com/google/**")
exclude("com/github/shynixn/mccoroutine/**")
exclude("com/fasterxml/**")
exclude("plugin-legacy.yml")
}

/**
* Create legacy plugin jar file.
*/
Expand Down Expand Up @@ -168,7 +129,6 @@ tasks.register("pluginJarLatest", com.github.jengelman.gradle.plugins.shadow.tas
exclude("javax/**")
exclude("com/google/**")
exclude("com/fasterxml/**")
exclude("plugin-legacy.yml")
}

/**
Expand All @@ -188,7 +148,6 @@ tasks.register("pluginJarPremium", com.github.jengelman.gradle.plugins.shadow.ta
exclude("javax/**")
exclude("com/google/**")
exclude("com/fasterxml/**")
exclude("plugin-legacy.yml")
}

tasks.register("languageFile") {
Expand Down
45 changes: 45 additions & 0 deletions docs/wiki/docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Api

PetBlocks offers a Developer Api, however it is not published to Maven Central or any other distribution system yet.
You need to directly reference the PetBlocks.jar file.

## Usage

Add a dependency in your plugin.yml

```yaml
softdepend: [ PetBlocks]
```
Take a look at the following example:
```java
public class YourPlugin extends JavaPlugin {
@Override
public void onEnable() {
// Always gets the same instance of the PetService.
PetService petService = Bukkit.getServicesManager().load(PetService.class);

Player player = Bukkit.getPlayer("YourPlayerName");
Plugin plugin = this;

// GetPetsFromPlayerAsync may retrieve the pet from the Database or the InMemory cache.
petService.getPetsFromPlayerAsync(player).thenAccept(pets -> {
// Main Thread
if (pets.size() > 0) {
// Do not keep the pet instance in your plugin (e.g. in fields). Always retrieve it with getPetsFromPlayerAsync.
// If you need to keep the pet instance in high performance scenarios, check if the pet has already been disposed before using it with pet.isDisposed().
Pet pet = pets.get(0);

// All pet methods are safe to be called regardless if the pet is currently spawned or not.
pet.call();
// Changes are automatically applied to the pet if it is spawned and automatically persisted.
pet.setDisplayName("Hello World");
pet.setLoop("idle");
}
}).exceptionally(error -> {
plugin.getLogger().log(Level.SEVERE, "Failed to load pets.", error);
return null;
});
}
}
```
31 changes: 28 additions & 3 deletions docs/wiki/docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ events:
createText();
```
### Debugging Actions
When you start creating actions, it is very helpful to know, which action is currently being executed and how
variables are evaluated. Every action can be logged to your server console by setting the optional ``debug: true`` property of an action.
```yaml
events:
rightClick:
actions: # You can add/remove actions as you want here.
- name: "Delay Action" # Required arbitrary name.
type: "DELAY" # Required action type.
ticks: 60 # Required for type DELAY. 60 Ticks delay.
debug: true # Optional flag to log this action to the console.
```
### Restricting Actions
#### Permission
Expand All @@ -146,9 +161,19 @@ events:
#### Conditions
Actions can optionally have conditions, which support 2 types: ``STRING_EQUALS`` and ``JAVASCRIPT``.
Prefer using ``STRING_EQUALS`` over ``JAVASCRIPT``. ``STRING_EQUALS`` checks if the 2 values in ``left`` and ``right``
are the same. ``JAVASCRIPT`` evaluates a boolean expression.
Actions can optionally have conditions, which support the following types:
* ``STRING_EQUALS``
* ``STRING_NOT_EQUALS``
* ``STRING_EQUALS_IGNORE_CASE``
* ``STRING_NOT_EQUALS_IGNORE_CASE``
* ``NUMBER_GREATER_THAN``
* ``NUMBER_GREATER_THAN_OR_EQUAL``
* ``NUMBER_LESS_THAN``
* ``NUMBER_LESS_THAN_OR_EQUAL``
* ``JAVASCRIPT``
Try to avoid using ``JAVASCRIPT`` because it requires more computation time. It should only be used if you want to create complex boolean expressions.
```yaml
events:
Expand Down
1 change: 1 addition & 0 deletions docs/wiki/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nav:
- Templates: template.md
- GUI: gui.md
- PlaceHolders: placeholders.md
- Developer Api: api.md
- 'FAQ': faq.md
theme:
name: material
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ object PetBlocksLanguage {
/** [&9PetBlocks&f] Pet is looking at a location. **/
var petLookAtMessage : String = "[&9PetBlocks&f] Pet is looking at a location."

/** [&9PetBlocks&f] &cCannot parse template file. See console log for details. **/
var errorLoadingTemplatesMessage : String = "[&9PetBlocks&f] &cCannot parse template file. See console log for details."

/** [&9PetBlocks&f] PetBlocks has been reloaded. **/
var reloadMessage : String = "[&9PetBlocks&f] PetBlocks has been reloaded."

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.shynixn.petblocks.contract

import com.github.shynixn.mcutils.common.CancellationToken
import com.github.shynixn.petblocks.entity.PetActionDefinition
import org.bukkit.entity.Player

Expand All @@ -8,5 +9,5 @@ interface PetActionExecutionService {
* Executes an pet action.
* @param eventPlayer Related to the event. May not be the owner.
*/
suspend fun executeAction(eventPlayer : Player, pet: Pet, petActionDefinition: PetActionDefinition)
suspend fun executeAction(eventPlayer : Player, pet: Pet, petActionDefinition: PetActionDefinition, cancellationToken: CancellationToken)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ package com.github.shynixn.petblocks.enumeration
enum class PetActionConditionType {
NONE,
STRING_EQUALS,
STRING_NOT_EQUALS,
STRING_EQUALS_IGNORE_CASE,
STRING_NOT_EQUALS_IGNORE_CASE,
NUMBER_GREATER_THAN,
NUMBER_GREATER_THAN_OR_EQUAL,
NUMBER_LESS_THAN,
NUMBER_LESS_THAN_OR_EQUAL,
JAVASCRIPT,
}
16 changes: 13 additions & 3 deletions src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.shynixn.mccoroutine.bukkit.CoroutineTimings
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import com.github.shynixn.mccoroutine.bukkit.ticks
import com.github.shynixn.mcutils.common.CancellationToken
import com.github.shynixn.mcutils.common.Vector3d
import com.github.shynixn.mcutils.common.physic.PhysicObject
import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcher
Expand Down Expand Up @@ -52,6 +53,7 @@ class PetEntityImpl(
private var positionUpdateCounter = 0
private var velocity = Vector3d(0.0, 0.0, 0.0)
private var lastClickTimeStamp = 0L
private var cancellationToken = CancellationToken()

// Mover
private var lastRandomTimeStamp = 0L
Expand All @@ -78,7 +80,8 @@ class PetEntityImpl(
break
}

petActionExecutionService.executeAction(pet.player, pet, loop)
cancellationToken = CancellationToken()
petActionExecutionService.executeAction(pet.player, pet, loop, cancellationToken)
delay(1.ticks)
} catch (e: Exception) {
plugin.logger.log(Level.SEVERE, "Cannot execute pet loop '${pet.loop}'.", e)
Expand Down Expand Up @@ -123,6 +126,13 @@ class PetEntityImpl(
this.physicsComponent.teleport(vector3d)
}

/**
* Cancels the execution of the currently executed loop.
*/
fun cancelLoop() {
cancellationToken.isCancelled = true
}

/**
* RightClicks the pet.
*/
Expand All @@ -138,7 +148,7 @@ class PetEntityImpl(
val rightClickEvent = pet.template.events["rightClick"]
if (rightClickEvent != null) {
plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) {
petActionExecutionService.executeAction(player, pet, rightClickEvent)
petActionExecutionService.executeAction(player, pet, rightClickEvent, CancellationToken())
}
}
}
Expand All @@ -158,7 +168,7 @@ class PetEntityImpl(
val leftClickEvent = pet.template.events["leftClick"]
if (leftClickEvent != null) {
plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) {
petActionExecutionService.executeAction(player, pet, leftClickEvent)
petActionExecutionService.executeAction(player, pet, leftClickEvent, CancellationToken())
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class PetImpl(
}
set(value) {
petMeta.loop = value
petEntity?.cancelLoop()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,21 @@ class PetBlocksCommandExecutor @Inject constructor(
plugin.reloadTranslation(language, PetBlocksLanguage::class.java, "en_us")
plugin.logger.log(Level.INFO, "Loaded language file $language.properties.")
templateRepository.clearCache()
val templates = templateRepository.getAll()
for (pet in petService.getCache().values.flatten()) {
val matchingTemplate = templates.firstOrNull { e -> e.name.equals(pet.template.name, true) }

if (matchingTemplate != null) {
pet.template = matchingTemplate
try {
val templates = templateRepository.getAll()
for (pet in petService.getCache().values.flatten()) {
val matchingTemplate = templates.firstOrNull { e -> e.name.equals(pet.template.name, true) }

if (matchingTemplate != null) {
pet.template = matchingTemplate
}
}
sender.sendPluginMessage(PetBlocksLanguage.reloadMessage)
} catch (e: Exception) {
plugin.logger.log(Level.SEVERE, "Failed to load file", e)
sender.sendPluginMessage(PetBlocksLanguage.errorLoadingTemplatesMessage)
}

sender.sendPluginMessage(PetBlocksLanguage.reloadMessage)
return true
}

Expand Down
Loading

0 comments on commit 068ed09

Please sign in to comment.