Skip to content

Commit

Permalink
add dispatchevent boutique - 1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
YanisBft committed May 26, 2023
1 parent e71bfe4 commit 906672b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Dispatches a custom event with a given name and player.
Permission: `pacutilities.dispatchevent`

Usage:
- `/dispatchevent <type> <player> <name>`
- `/dispatchevent donjon <player> <name>`
- `/dispatchevent boutique <player> <gradeName> <months>`

### /pacutilities
Reloads the plugin.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pacutilities_group = fr.peaceandcube
pacutilities_name = pacutilities
pacutilities_version = 1.3.1
pacutilities_version = 1.3.2

paper_version = 1.19.4-R0.1-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.peaceandcube.pacutilities.command;

import fr.peaceandcube.pacutilities.event.PlayerBuyGradeEvent;
import fr.peaceandcube.pacutilities.event.PlayerFinishDonjonEvent;
import fr.peaceandcube.pacutilities.util.PlayerMessages;
import fr.peaceandcube.pacutilities.util.SuggestionProviders;
Expand All @@ -19,7 +20,7 @@

public class DispatchEventCommand implements CommandExecutor, TabExecutor {
private static final String PERM_DISPATCHEVENT = "pacutilities.dispatchevent";
private static final List<String> TYPES = List.of("donjon");
private static final List<String> TYPES = List.of("boutique", "donjon");
private static final TextComponent TYPE_INVALID = Component.text("Le type est invalide", TextColor.color(0xFF5555));

@Override
Expand All @@ -28,7 +29,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (args.length >= 3) {
String type = args[0];
Player player = Bukkit.getPlayer(args[1]);
String name = String.join(" ", List.of(args).subList(2, args.length));

if (!TYPES.contains(type)) {
sender.sendMessage(TYPE_INVALID);
Expand All @@ -41,7 +41,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

if (type.equals("donjon")) {
String name = String.join(" ", List.of(args).subList(2, args.length));
Bukkit.getServer().getPluginManager().callEvent(new PlayerFinishDonjonEvent(player, name));
} else if (type.equals("boutique")) {
String gradeName = args[2];
int months = Integer.parseInt(args[3]);
Bukkit.getServer().getPluginManager().callEvent(new PlayerBuyGradeEvent(player, gradeName, months));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fr.peaceandcube.pacutilities.event;

import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;

public class PlayerBuyGradeEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();

private final String gradeName;
private final int months;

public PlayerBuyGradeEvent(Player player, String gradeName, int months) {
super(player);
this.gradeName = gradeName;
this.months = months;
}

public String getGradeName() {
return gradeName;
}

public int getMonths() {
return months;
}

@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}

@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ commands:
description: Allows you to dispatch an event
permission: pacutilities.dispatchevent
permission-message: §cYou do not have the permission to use this command.
usage: "§eUsage: §r/dispatchevent <type> <player> <name>"
usage: "§eUsage: §r/dispatchevent <type> <player> <name> [...]"
pacutilities:
description: Reload the plugin
permission: pacutilities.pacutilities
Expand Down

0 comments on commit 906672b

Please sign in to comment.