Skip to content

Commit

Permalink
[+] Added DiceRollEvent for other plugins to hook into.
Browse files Browse the repository at this point in the history
  • Loading branch information
Loapu committed Nov 11, 2021
1 parent 049cf6d commit 59d82b6
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
git config user.name github-actions
git config user.email [email protected]
git fetch origin gh-pages --depth=1
mike deploy --push --update-aliases 2.2 latest
mike deploy --push --update-aliases 2.3 latest
mike set-default --push latest
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A small Pen-and-Paper-like dice rolling plugin for Minecraft.

## Dependencies
- [Paper](https://papermc.io/downloads#Paper-1.17) (or any of its forks) for Minecraft 1.17 or newer
- [CommandAPI](https://commandapi.jorel.dev/) version [6.3.0](https://github.com/JorelAli/CommandAPI/releases/tag/6.3.0) or newer
- [CommandAPI](https://commandapi.jorel.dev/) version [6.3.1](https://github.com/JorelAli/CommandAPI/releases/tag/6.3.1) or newer

## Installation

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
implementation("org.jetbrains:annotations:19.0.0")
annotationProcessor("dev.jorel.CommandAPI:commandapi-annotations:" + project.property("versionCommandApi") as String)
implementation("net.kyori:adventure-text-minimessage:" + project.property("versionMiniMessage") as String)
implementation(name, "VentureChat-3.0.4")
implementation(name, "VentureChat-3.2.2")
}
sourceSets {
main {
Expand Down
8 changes: 8 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
hide:
- navigation
---
# Developer API

### DiceRollEvent
As of version `2.3.0` VestriaDice fires a custom `DiceRollEvent` every time a dice is rolled by a player. This event is cancellable and allows you to get the player rolling the dice, the result and the modifier. As of now these values are not modifiable but you can use them if you wish.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ hide:

## Defaults

Below you will find the default configuration file `v3` for VestriaDice version `2.2.x`.
Below you will find the default configuration file `v3` for VestriaDice version `2.3.x`.

``` yaml
--8<-- "src/main/resources/config.yml"
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ hide:
* [Configuration](configuration)
* [Commands and Permissions](commands-and-permissions)
* [Frequently Asked Questions](faq)
* [Developer API](api)

Consider becoming a [Sponsor](https://github.com/sponsors/Loapu) if you :heart: VestriaDice!
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ hide:

## Dependencies

VestriaDice is built against the [Paper 1.17 API](https://papermc.io/downloads#Paper-1.17). Therefore you *cannot* use VestriaDice with Bukkit or Spigot. Any of the actively maintained Paper forks (Tuinity, Purpur, etc.) should work. If you encounter any problems make sure to open an Issue right here on GitHub.
VestriaDice is built against the [Paper 1.17 API](https://papermc.io/downloads#Paper-1.17). Therefore, you *cannot* use VestriaDice with Bukkit or Spigot. Any of the actively maintained Paper forks (Tuinity, Purpur, etc.) should work. If you encounter any problems make sure to open an Issue right here on GitHub.

After making sure that you use the right server software, download the [CommandAPI](https://commandapi.jorel.dev/) Plugin in its latest version and drag & drop it inside your plugins folder.

## Installation

All dependencies set? Alright, now drag & drop VestriaDice inside your plugins folder and restart your server. Please remember, neither a reload of the server nor the plugin will work, you have to restart the whole server.
All dependencies set? Alright, now drag & drop VestriaDice inside your plugins folder and restart your server. Please remember, neither reloading the server nor the plugin will work, you have to restart the whole server.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pluginGroup=dev.loapu
pluginName=VestriaDice
pluginPrefix=VD
pluginVersion=2.2.0
pluginVersion=2.3.0
pluginBuildNumber=177
pluginApiVersion=1.17
pluginAuthor=Loapu
pluginDescription=A Pen-and-Paper-like dice rolling system inside Minecraft.
pluginHomepage=https://docs.loapu.dev/VestriaDice/
projectEncoding=UTF-8
versionPaper=1.17-R0.1-SNAPSHOT
versionCommandApi=6.3.0
versionCommandApi=6.3.1
versionMiniMessage=4.1.0-SNAPSHOT
versionJava=16
Binary file removed libs/VentureChat-3.0.4.jar
Binary file not shown.
Binary file added libs/VentureChat-3.2.2.jar
Binary file not shown.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ nav:
- Configuration: configuration.md
- Commands and Permissions: commands-and-permissions.md
- Frequently Asked Questions: faq.md
- Developer API: api.md
- Open Issue: https://github.com/Loapu/VestriaDice/issues
- Become a Sponsor: https://github.com/sponsors/Loapu
15 changes: 11 additions & 4 deletions src/main/java/dev/loapu/vestriadice/commands/RollCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.jorel.commandapi.annotations.arguments.AIntegerArgument;
import dev.jorel.commandapi.annotations.arguments.AStringArgument;
import dev.loapu.vestriadice.VestriaDice;
import dev.loapu.vestriadice.events.DiceRollEvent;
import dev.loapu.vestriadice.utils.LangManager;
import dev.loapu.vestriadice.utils.Message;
import dev.loapu.vestriadice.utils.Setting;
Expand Down Expand Up @@ -69,7 +70,7 @@ private static void rollDice(Player sender, String input, int checkValue)
String diceString = input.toLowerCase();
String diceStringWithoutModifier = diceString.split("\\+")[0].split("-")[0];
String[] diceArray;
int modifier = 0;
short modifier = 0;
if (diceStringWithoutModifier.contains(".")) diceArray = diceStringWithoutModifier.split("\\."); // Split all different dice into one array
else diceArray = new String[] { diceStringWithoutModifier };
if (diceString.contains("+")) modifier += Integer.parseInt(diceString.split("\\+")[1]);
Expand Down Expand Up @@ -125,9 +126,15 @@ private static void rollDice(Player sender, String input, int checkValue)
diceRolls.add(stringBuilder.toString());
}
diceString = String.join("<gray>, ", diceRolls);
String modifierString = ((modifier > 0) ? "<color:#00ff00>+" : "<color:#ff0000>") + modifier + "</color>";
String resultString = result + modifier + "";
String deserializedDisplayname = MiniMessage.builder().build().serialize(sender.displayName());

DiceRollEvent event = new DiceRollEvent(sender, result, modifier);
Bukkit.getPluginManager().callEvent(event);

if (event.isCancelled()) return;

String modifierString = ((event.getModifier() > 0) ? "<color:#00ff00>+" : "<color:#ff0000>") + event.getModifier() + "</color>";
String resultString = event.getResult() + event.getModifier() + "";
String deserializedDisplayname = MiniMessage.builder().build().serialize(event.getPlayer().displayName());

sendComponent(lm.getComponent(Message.COMMAND_ROLL_RESULT, sender, Map.of(
"player", deserializedDisplayname,
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/dev/loapu/vestriadice/events/DiceRollEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dev.loapu.vestriadice.events;

import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

public class DiceRollEvent extends Event implements Cancellable
{
private static final HandlerList HANDLERS = new HandlerList();

private final Player player;
private final int result;
private final short modifier;
private boolean isCancelled;

public DiceRollEvent(Player player, int result, short modifier)
{
this.player = player;
this.result = result;
this.modifier = modifier;
}

@Override
public HandlerList getHandlers()
{
return HANDLERS;
}

public static HandlerList getHandlerList()
{
return HANDLERS;
}

@Override
public boolean isCancelled()
{
return this.isCancelled;
}

@Override
public void setCancelled(boolean isCancelled) {
this.isCancelled = isCancelled;
}

public Player getPlayer()
{
return player;
}

public int getResult()
{
return result;
}

public short getModifier()
{
return modifier;
}


}

0 comments on commit 59d82b6

Please sign in to comment.