-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: better hunger & save hunger
* feat: difficulty command
- Loading branch information
Showing
12 changed files
with
140 additions
and
23 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
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
28 changes: 28 additions & 0 deletions
28
Allay-Server/src/main/java/org/allaymc/server/command/defaults/DifficultyCommand.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,28 @@ | ||
package org.allaymc.server.command.defaults; | ||
|
||
import org.allaymc.api.command.SenderType; | ||
import org.allaymc.api.command.SimpleCommand; | ||
import org.allaymc.api.command.tree.CommandTree; | ||
import org.allaymc.api.i18n.TrKeys; | ||
import org.allaymc.api.world.Difficulty; | ||
|
||
/** | ||
* Allay Project 13/07/2024 | ||
* | ||
* @author IWareQ | ||
*/ | ||
public class DifficultyCommand extends SimpleCommand { | ||
public DifficultyCommand() { | ||
super("difficulty", TrKeys.M_COMMANDS_DIFFICULTY_DESCRIPTION); | ||
} | ||
|
||
@Override | ||
public void prepareCommandTree(CommandTree tree) { | ||
tree.getRoot().difficultyNode("difficulty").exec((context, player) -> { | ||
Difficulty difficulty = context.getResult(0); | ||
player.getWorld().setDifficulty(difficulty); | ||
context.addOutput(TrKeys.M_COMMANDS_DIFFICULTY_SUCCESS, difficulty); | ||
return context.success(); | ||
}, SenderType.PLAYER); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
Allay-Server/src/main/java/org/allaymc/server/command/tree/node/DifficultyNode.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,31 @@ | ||
package org.allaymc.server.command.tree.node; | ||
|
||
import org.allaymc.api.command.tree.CommandNode; | ||
import org.allaymc.api.world.Difficulty; | ||
|
||
/** | ||
* Allay Project 13/07/2024 | ||
* | ||
* @author IWareQ | ||
*/ | ||
public class DifficultyNode extends EnumNode { | ||
private static final String[] VALUES = new String[]{ | ||
"peaceful", "p", "0", | ||
"easy", "e", "1", | ||
"normal", "n", "2", | ||
"hard", "h", "3" | ||
}; | ||
|
||
public DifficultyNode(String name, CommandNode parent, Difficulty defaultValue) { | ||
super(name, parent, defaultValue, VALUES); | ||
} | ||
|
||
@Override | ||
protected Difficulty argToResult(String arg) { | ||
try { | ||
return Difficulty.from(Integer.parseInt(arg)); | ||
} catch (NumberFormatException ignored) { | ||
return Difficulty.from(arg); | ||
} | ||
} | ||
} |
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