-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
212 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/it/rattly/duels/commands/CommandManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package it.rattly.duels.commands; | ||
|
||
import it.rattly.duels.Duels; | ||
import it.rattly.duels.Toggleable; | ||
import it.rattly.duels.commands.impl.DuelAcceptCommand; | ||
import it.rattly.duels.commands.impl.DuelCommand; | ||
import it.rattly.duels.commands.impl.DuelDenyCommand; | ||
|
||
public record CommandManager(Duels duels) implements Toggleable { | ||
@Override | ||
public void enable() { | ||
duels.getLogger().info("Registering commands..."); | ||
|
||
int commands = registerCommands( | ||
new DuelCommand(duels), | ||
new DuelAcceptCommand(duels), | ||
new DuelDenyCommand(duels) | ||
); | ||
|
||
duels.getLogger().info(() -> commands + " listeners registered!"); | ||
} | ||
|
||
private int registerCommands(AbstractCommand... commands) { | ||
return commands.length; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/it/rattly/duels/commands/impl/DuelAcceptCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package it.rattly.duels.commands.impl; | ||
|
||
import it.rattly.duels.Duels; | ||
import it.rattly.duels.commands.AbstractCommand; | ||
import it.rattly.duels.player.DuelsPlayer; | ||
import it.rattly.duels.utils.Palette; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
import static net.kyori.adventure.text.Component.text; | ||
|
||
public class DuelAcceptCommand extends AbstractCommand { | ||
public DuelAcceptCommand(Duels duels) { | ||
super(duels, "duelaccept"); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (!(sender instanceof Player player)) { | ||
sender.sendMessage( | ||
text().append( | ||
text("You can't use this command from console.") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
if (args.length < 1) { | ||
sender.sendMessage( | ||
text().append( | ||
text("Usage: /duelaccept <name>") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
Player target = Bukkit.getPlayer(args[0]); | ||
if (target == null) { | ||
sender.sendMessage( | ||
text().append( | ||
text("The person you mentioned is offline or non-existant.") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
DuelsPlayer duelsPlayer = duels.getPlayerManager().getPlayer(player); | ||
if (duelsPlayer.isInvitedBy(target.getUniqueId())) { | ||
duelsPlayer.acceptInvite(duelsPlayer.getInviteBy(target.getUniqueId()).get()); | ||
} else { | ||
sender.sendMessage( | ||
text().append( | ||
text("You aren't invited by that player.") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { | ||
return null; //TODO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/it/rattly/duels/commands/impl/DuelDenyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package it.rattly.duels.commands.impl; | ||
|
||
import it.rattly.duels.Duels; | ||
import it.rattly.duels.commands.AbstractCommand; | ||
import it.rattly.duels.player.DuelsPlayer; | ||
import it.rattly.duels.utils.Palette; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
import static net.kyori.adventure.text.Component.text; | ||
|
||
public class DuelDenyCommand extends AbstractCommand { | ||
public DuelDenyCommand(Duels duels) { | ||
super(duels, "dueldeny"); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (!(sender instanceof Player player)) { | ||
sender.sendMessage( | ||
text().append( | ||
text("You can't use this command from console.") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
if (args.length < 1) { | ||
sender.sendMessage( | ||
text().append( | ||
text("Usage: /duelaccept <name>") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
Player target = Bukkit.getPlayer(args[0]); | ||
if (target == null) { | ||
sender.sendMessage( | ||
text().append( | ||
text("The person you mentioned is offline or non-existant.") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
DuelsPlayer duelsPlayer = duels.getPlayerManager().getPlayer(player); | ||
if (duelsPlayer.isInvitedBy(target.getUniqueId())) { | ||
duelsPlayer.denyInvite(duelsPlayer.getInviteBy(target.getUniqueId()).get()); | ||
} else { | ||
sender.sendMessage( | ||
text().append( | ||
text("You aren't invited by that player.") | ||
).color(Palette.ERROR) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { | ||
return null; //TODO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters