-
Notifications
You must be signed in to change notification settings - Fork 15
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
9 changed files
with
158 additions
and
7 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
71 changes: 71 additions & 0 deletions
71
Allay-Server/src/main/java/org/allaymc/server/command/defaults/TimeCommand.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,71 @@ | ||
package org.allaymc.server.command.defaults; | ||
|
||
import org.allaymc.api.command.SimpleCommand; | ||
import org.allaymc.api.command.tree.CommandTree; | ||
import org.allaymc.api.i18n.TrKeys; | ||
import org.allaymc.api.world.WorldData; | ||
|
||
/** | ||
* Allay Project 2024/3/23 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class TimeCommand extends SimpleCommand { | ||
public TimeCommand() { | ||
super("time", TrKeys.M_COMMANDS_TIME_DESCRIPTION); | ||
} | ||
|
||
@Override | ||
public void prepareCommandTree(CommandTree tree) { | ||
tree.getRoot() | ||
.key("set") | ||
.enums("time", "day", "night", "midnight", "noon", "sunrise", "sunset") | ||
.exec(context -> { | ||
var world = context.getSender().getCmdExecuteLocation().dimension().getWorld(); | ||
long time = 0L; | ||
switch ((String) context.getSecondResult()) { | ||
case "day" -> { | ||
time = WorldData.TIME_DAY; | ||
} | ||
case "night" -> { | ||
time = WorldData.TIME_NIGHT; | ||
} | ||
case "midnight" -> { | ||
time = WorldData.TIME_MIDNIGHT; | ||
} | ||
case "noon" -> { | ||
time = WorldData.TIME_NOON; | ||
} | ||
case "sunrise" -> { | ||
time = WorldData.TIME_SUNRISE; | ||
} | ||
case "sunset" -> { | ||
time = WorldData.TIME_SUNSET; | ||
} | ||
} | ||
world.setTime(time); | ||
context.addOutput(TrKeys.M_COMMANDS_TIME_SET, time); | ||
return context.success(); | ||
}) | ||
.up() | ||
.longNum("amount") | ||
.exec(context -> { | ||
var world = context.getSender().getCmdExecuteLocation().dimension().getWorld(); | ||
long time = context.getSecondResult(); | ||
world.setTime(time); | ||
context.addOutput(TrKeys.M_COMMANDS_TIME_SET, time); | ||
return context.success(); | ||
}) | ||
.root() | ||
.key("add") | ||
.longNum("amount") | ||
.exec(context -> { | ||
var world = context.getSender().getCmdExecuteLocation().dimension().getWorld(); | ||
long amount = context.getSecondResult(); | ||
world.addTime(amount); | ||
context.addOutput(TrKeys.M_COMMANDS_TIME_ADDED, amount); | ||
return context.success(); | ||
}); | ||
|
||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
Allay-Server/src/main/java/org/allaymc/server/command/tree/node/LongNode.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,39 @@ | ||
package org.allaymc.server.command.tree.node; | ||
|
||
import org.allaymc.api.command.tree.BaseNode; | ||
import org.allaymc.api.command.tree.CommandContext; | ||
import org.allaymc.api.command.tree.CommandNode; | ||
import org.cloudburstmc.protocol.bedrock.data.command.CommandParam; | ||
import org.cloudburstmc.protocol.bedrock.data.command.CommandParamData; | ||
|
||
/** | ||
* Allay Project 2024/3/23 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class LongNode extends BaseNode { | ||
public LongNode(String name, CommandNode parent, long defaultValue) { | ||
super(name, parent, defaultValue); | ||
} | ||
|
||
@Override | ||
public boolean match(CommandContext context) { | ||
var arg = context.queryArg(); | ||
var number = 0L; | ||
try { | ||
number = Long.parseLong(arg); | ||
} catch (NumberFormatException e) { | ||
return false; | ||
} | ||
context.putResult(number); | ||
context.popArg(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public CommandParamData toNetworkData() { | ||
var data = super.toNetworkData(); | ||
data.setType(CommandParam.INT); | ||
return data; | ||
} | ||
} |
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