-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
5 changed files
with
198 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
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
82 changes: 82 additions & 0 deletions
82
server/src/main/java/org/allaymc/server/command/defaults/TitleCommand.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,82 @@ | ||
package org.allaymc.server.command.defaults; | ||
|
||
import org.allaymc.api.command.SimpleCommand; | ||
import org.allaymc.api.command.tree.CommandTree; | ||
import org.allaymc.api.entity.component.player.EntityPlayerBaseComponent; | ||
import org.allaymc.api.entity.interfaces.EntityPlayer; | ||
import org.allaymc.api.i18n.TrKeys; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author daoge_cmd | ||
*/ | ||
public class TitleCommand extends SimpleCommand { | ||
public TitleCommand() { | ||
super("title", TrKeys.M_COMMANDS_TITLE_DESCRIPTION); | ||
} | ||
|
||
@Override | ||
public void prepareCommandTree(CommandTree tree) { | ||
tree.getRoot() | ||
.key("set") | ||
.playerTarget("players") | ||
.enumClass("type", TitleType.class) | ||
.str("text") | ||
.exec(context -> { | ||
Collection<EntityPlayer> players = context.getResult(1); | ||
TitleType type = context.getResult(2); | ||
String text = context.getResult(3); | ||
players.forEach(p -> sendTitle(p, text, type)); | ||
context.addOutput(TrKeys.M_COMMANDS_TITLE_SUCCESS); | ||
return context.success(); | ||
}) | ||
.root() | ||
.key("clear") | ||
.playerTarget("players") | ||
.exec(context -> { | ||
Collection<EntityPlayer> players = context.getResult(1); | ||
players.forEach(EntityPlayerBaseComponent::clearTitle); | ||
context.addOutput(TrKeys.M_COMMANDS_TITLE_SUCCESS); | ||
return context.success(); | ||
}) | ||
.root() | ||
.key("times") | ||
.playerTarget("players") | ||
.intNum("fadeInTime") | ||
.intNum("duration") | ||
.intNum("fadeOutTime") | ||
.exec(context -> { | ||
Collection<EntityPlayer> players = context.getResult(1); | ||
int fadeInTime = context.getResult(2); | ||
int duration = context.getResult(3); | ||
int fadeOutTime = context.getResult(4); | ||
players.forEach(p -> p.setTitleSettings(fadeInTime, duration, fadeOutTime)); | ||
context.addOutput(TrKeys.M_COMMANDS_TITLE_SUCCESS); | ||
return context.success(); | ||
}) | ||
.root() | ||
.key("reset") | ||
.playerTarget("players") | ||
.exec(context -> { | ||
Collection<EntityPlayer> players = context.getResult(1); | ||
players.forEach(EntityPlayerBaseComponent::resetTitleSettings); | ||
context.addOutput(TrKeys.M_COMMANDS_TITLE_SUCCESS); | ||
return context.success(); | ||
}); | ||
} | ||
|
||
protected void sendTitle(EntityPlayer player, String text, TitleType type) { | ||
switch (type) { | ||
case TITLE -> player.sendTitle(text); | ||
case SUBTITLE -> player.sendSubtitle(text); | ||
case ACTIONBAR -> player.sendActionBar(text); | ||
} | ||
} | ||
|
||
protected enum TitleType { | ||
TITLE, | ||
SUBTITLE, | ||
ACTIONBAR | ||
} | ||
} |
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