Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
commandrod committed Aug 31, 2022
1 parent 6cd0468 commit 57a60a2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.bukkit.contexts.OnlinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public abstract class TargetedCommand<T extends CommandSender> extends BaseCommand {
public abstract class TargetedCommand extends BaseCommand {

public abstract void handle(T sender, OnlinePlayer args);
public abstract void handle(Player sender, OnlinePlayer args);

@Default
public void targetedCommand(T sender, @Optional OnlinePlayer target) {
if (sender == null) return;
public void targetedCommand(Player sender, @Optional OnlinePlayer target) {
if (target == null) {
if (!(sender instanceof Player player)) {
sender.sendMessage("EventTools > You must provide a player in order to execute this command.");
return;
}
handle(sender, new OnlinePlayer(player));
handle(sender, new OnlinePlayer(sender));
return;
}
handle(sender, target);
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/me/commandrod/eventtools/commands/HealCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.kyori.adventure.text.Component;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand All @@ -20,18 +19,13 @@

@CommandAlias("heal")
@CommandPermission("eventtools.heal")
public class HealCommand extends TargetedCommand<CommandSender> {
public class HealCommand extends TargetedCommand {

@Dependency
private ConfigManager configManager;

public void handle(CommandSender sender, @Optional OnlinePlayer args) {
Player player;
if (!(sender instanceof Player)) {
player = args.getPlayer();
} else {
player = (Player) sender;
}
public void handle(Player sender, @Optional OnlinePlayer args) {
Player player = args.getPlayer();

AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
player.setHealth(attribute == null ? 20 : attribute.getBaseValue());
Expand All @@ -46,7 +40,9 @@ public void handle(CommandSender sender, @Optional OnlinePlayer args) {

Component msg = configManager.getMessages().PREFIX.append(
configManager.getTranslatedMessage("heal", "You healed <yellow>%player%</yellow>!")
.replaceText(Replacement.builder().replace("%player%", player.getName()).build())
.replaceText(Replacement.builder()
.replace("%player%", player.getName())
.build())
);
if (configManager.isEmpty(msg)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@CommandAlias("eventspawn|espawn")
@CommandPermission("eventtools.spawn")
public class SpawnCommand extends TargetedCommand<Player> {
public class SpawnCommand extends TargetedCommand {

@Dependency
private ConfigManager configManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public void onChat(AsyncChatEvent event) {
"<gold>%player%</gold><gray>:</gray> <yellow>%message%</yellow>")
.replaceText(Replacement.builder()
.replace("%player%", player.getName())
.build())
.replaceText(Replacement.builder()
.replace("%message%", event.message())
.build()
)
.build())
);
if (configManager.isEmpty(msg)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Replacement replace(@RegExp String placeholder, String value) {
}

public Replacement replace(@RegExp String placeholder, ComponentLike value) {
this.replacementBuilder.match(placeholder).replacement(value);
this.replacementBuilder.match(placeholder).replacement(value.asComponent());
return this;
}

Expand Down

0 comments on commit 57a60a2

Please sign in to comment.