generated from Rosewood-Development/RoseTemplate
-
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
13 changed files
with
152 additions
and
22 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
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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/xyz/oribuin/fishing/command/FishCommand.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,36 @@ | ||
package xyz.oribuin.fishing.command; | ||
|
||
import dev.rosewood.rosegarden.RosePlugin; | ||
import dev.rosewood.rosegarden.command.HelpCommand; | ||
import dev.rosewood.rosegarden.command.ReloadCommand; | ||
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition; | ||
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; | ||
import dev.rosewood.rosegarden.command.framework.CommandInfo; | ||
import xyz.oribuin.fishing.command.impl.ApplyCommand; | ||
|
||
public class FishCommand extends BaseRoseCommand { | ||
|
||
public FishCommand(RosePlugin rosePlugin) { | ||
super(rosePlugin); | ||
} | ||
|
||
@Override | ||
protected CommandInfo createCommandInfo() { | ||
return CommandInfo.builder("fish") | ||
.aliases("fishing") | ||
.arguments(this.createArguments()) | ||
.playerOnly(true) | ||
.build(); | ||
} | ||
|
||
private ArgumentsDefinition createArguments() { | ||
return ArgumentsDefinition.builder() | ||
.requiredSub( | ||
new HelpCommand(this.rosePlugin, this), | ||
new ReloadCommand(this.rosePlugin), | ||
new ApplyCommand(this.rosePlugin) | ||
); | ||
} | ||
|
||
} | ||
|
33 changes: 33 additions & 0 deletions
33
src/main/java/xyz/oribuin/fishing/command/argument/AugmentArgument.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,33 @@ | ||
package xyz.oribuin.fishing.command.argument; | ||
|
||
import dev.rosewood.rosegarden.command.framework.Argument; | ||
import dev.rosewood.rosegarden.command.framework.ArgumentHandler; | ||
import dev.rosewood.rosegarden.command.framework.CommandContext; | ||
import dev.rosewood.rosegarden.command.framework.InputIterator; | ||
import dev.rosewood.rosegarden.utils.StringPlaceholders; | ||
import xyz.oribuin.fishing.augment.Augment; | ||
import xyz.oribuin.fishing.augment.AugmentRegistry; | ||
|
||
import java.util.List; | ||
|
||
public class AugmentArgument extends ArgumentHandler<Augment> { | ||
|
||
public AugmentArgument() { | ||
super(Augment.class); | ||
} | ||
|
||
@Override | ||
public Augment handle(CommandContext context, Argument argument, InputIterator inputIterator) throws HandledArgumentException { | ||
String input = inputIterator.next(); | ||
Augment augment = AugmentRegistry.all().get(input); | ||
if (augment != null) return augment; | ||
|
||
throw new HandledArgumentException("argument-handler-augments", StringPlaceholders.of("augment", input)); | ||
} | ||
|
||
@Override | ||
public List<String> suggest(CommandContext context, Argument argument, String[] args) { | ||
return AugmentRegistry.all().keySet().stream().toList(); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/xyz/oribuin/fishing/command/impl/ApplyCommand.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,61 @@ | ||
package xyz.oribuin.fishing.command.impl; | ||
|
||
import dev.rosewood.rosegarden.RosePlugin; | ||
import dev.rosewood.rosegarden.command.argument.ArgumentHandlers; | ||
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition; | ||
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; | ||
import dev.rosewood.rosegarden.command.framework.CommandContext; | ||
import dev.rosewood.rosegarden.command.framework.CommandInfo; | ||
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
import xyz.oribuin.fishing.augment.Augment; | ||
import xyz.oribuin.fishing.augment.AugmentRegistry; | ||
import xyz.oribuin.fishing.command.argument.AugmentArgument; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ApplyCommand extends BaseRoseCommand { | ||
|
||
public ApplyCommand(RosePlugin rosePlugin) { | ||
super(rosePlugin); | ||
} | ||
|
||
@RoseExecutable | ||
public void execute(CommandContext context, Augment augment, Integer level) { | ||
if (!(context.getSender() instanceof Player player)) return; | ||
|
||
ItemStack item = player.getInventory().getItemInMainHand(); | ||
if (item.getType() != Material.FISHING_ROD) { | ||
player.sendMessage("You must be holding a fishing rod to apply an augment."); | ||
return; | ||
} | ||
|
||
// Get the augment from the argument | ||
Map<Augment, Integer> augments = new HashMap<>(AugmentRegistry.from(item)); | ||
augments.put(augment, level); | ||
|
||
// Apply the augment to the fishing rod | ||
AugmentRegistry.save(item, augments); | ||
|
||
player.sendMessage("Successfully applied the augment to the fishing rod."); | ||
augments.forEach((a, l) -> player.sendMessage("Augment: " + a.name() + " Level: " + l)); | ||
} | ||
|
||
@Override | ||
protected CommandInfo createCommandInfo() { | ||
return CommandInfo.builder("apply") | ||
.arguments(this.createArguments()) | ||
.playerOnly(true) | ||
.build(); | ||
} | ||
|
||
private ArgumentsDefinition createArguments() { | ||
return ArgumentsDefinition.builder() | ||
.required("augment", new AugmentArgument()) | ||
.required("level", ArgumentHandlers.INTEGER) | ||
.build(); | ||
} | ||
} |
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
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
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