diff --git a/README.md b/README.md index b5de452..fa1f732 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ mvn - `getPlayer ` gets information about a player. [Details](#command-getplayer) - `setPlayerPos ?rotation:int?` Set the player position [Details](#command-setplayerpos) - `setPlayerStat ` Set a player stat [Details](#command-setplayerstat) +- `showTitle ` Show a Title to players [Details](#command-showtitle) #### Inventory @@ -171,6 +172,26 @@ setPlayerVelocity UP 0 1 ``` +### Command: showTitle + +- `showTitle ` + +#### Args + +- `playerIndex` Index of a player, if the index is smaller then 0 the title is shown to all players +- `title` The title to show +- `subtitle` The subtitle to show +- `fadeIn` The time it takes for the title to fade in, in ticks +- `stay` The time it takes for the title to stay, in ticks +- `fadeOut` The time it takes for the title to fade out, in ticks + +#### Example + +```bash +showTitle𝇉Das ist ein Title𝇉Mit einem subtitle𝇉200𝇉200𝇉200 + +``` + ### Command: addInv - `addInv ?name:String? ?slot:int? !unbreakable!` diff --git a/src/main/java/org/sk/skMinecraft/CommandFactory.java b/src/main/java/org/sk/skMinecraft/CommandFactory.java index fccee3b..090a8e0 100644 --- a/src/main/java/org/sk/skMinecraft/CommandFactory.java +++ b/src/main/java/org/sk/skMinecraft/CommandFactory.java @@ -40,6 +40,8 @@ public CommandFactory() { this.commands.put("setPlayerPos", SetPlayerPos::new); this.commands.put("validate", Validator::new); + + this.commands.put("showTitle", ShowTitle::new); } public Command build(String command) { diff --git a/src/main/java/org/sk/skMinecraft/commands/ShowTitle.java b/src/main/java/org/sk/skMinecraft/commands/ShowTitle.java new file mode 100644 index 0000000..2822b72 --- /dev/null +++ b/src/main/java/org/sk/skMinecraft/commands/ShowTitle.java @@ -0,0 +1,59 @@ +package org.sk.skMinecraft.commands; + +import java.util.Arrays; +import java.util.HashMap; + +import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.entity.Player; +import org.sk.skMinecraft.SkMinecraft; + +public class ShowTitle extends Command { + + private int player; + private String title; + private String subtitle; + private int fadeIn; + private int stay; + private int fadeOut; + + public ShowTitle(String command) { + String[] parts = command.split(SkMinecraft.seperator); + + if(parts.length != 7) { + this.valid = false; + return; + } + + this.title = parts[2]; + this.subtitle = parts[3]; + + try { + this.player = Integer.parseInt(parts[1]); + this.fadeIn = Integer.parseInt(parts[4]); + this.stay = Integer.parseInt(parts[5]); + this.fadeOut = Integer.parseInt(parts[6]); + } catch(NumberFormatException e) { + this.valid = false; + } + } + + @Override + public void apply() { + Player[] players = Bukkit.getOnlinePlayers().toArray(new Player[0]); + + if(this.player < 0) { + for(int i = 0;i < players.length;i++) { + players[i].sendTitle(this.title, this.subtitle, this.fadeIn, this.stay, this.fadeOut); + } + } else { + if(this.player > players.length) return; + + players[this.player].sendTitle(this.title, this.subtitle, this.fadeIn, this.stay, this.fadeOut); + } + + } + + +}