Created
January 4, 2017 22:04
-
-
Save finreinhard/8dcaf516b029f042bfb3d8c07be09e67 to your computer and use it in GitHub Desktop.
ActionBar
This file contains hidden or 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
package li.angu.youtube.tutorial.actionbar; | |
import net.minecraft.server.v1_8_R3.IChatBaseComponent; | |
import net.minecraft.server.v1_8_R3.PacketPlayOutChat; | |
import org.bukkit.ChatColor; | |
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; | |
import org.bukkit.entity.Player; | |
/** | |
* Created by finreinhard on 04.01.17. | |
*/ | |
public class ActionBarMessage { | |
private String message; | |
public ActionBarMessage(String message) { | |
this.message = message; | |
} | |
public String getMessage() { | |
return message; | |
} | |
public void setMessage(String message) { | |
this.message = message; | |
} | |
public void send(Player player) { | |
/* | |
BYTE | |
0 = Chat Message | |
1 = System Message | |
2 = Action Bar | |
*/ | |
PacketPlayOutChat packet = | |
new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a("{'text': '" + ChatColor | |
.translateAlternateColorCodes('&', getMessage()) + "'}"), (byte) 2); | |
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); | |
} | |
} |
This file contains hidden or 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
package li.angu.youtube.tutorial.command; | |
import li.angu.youtube.tutorial.actionbar.ActionBarMessage; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import java.util.Arrays; | |
/** | |
* Created by finreinhard on 04.01.17. | |
*/ | |
public class TestCommand implements CommandExecutor { | |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments) { | |
if (!(sender instanceof Player)) { | |
sender.sendMessage("Du hast keine Actionbar!"); | |
return false; | |
} | |
String testMessage = "&8Das ist eine &6Test Nachricht&8!"; | |
// /test &6Das ist auch eine &3Test Nachricht | |
// Das ist auch eine Test Nachricht | |
if (arguments.length != 0) { | |
// JAVA 8 | |
StringBuilder stringBuilder = new StringBuilder(); | |
Arrays.stream(arguments).forEach(argument -> stringBuilder.append(argument).append(" ")); | |
testMessage = stringBuilder.toString(); | |
// JAVA 7 & 6 | |
/* | |
testMessage = ""; | |
for (String argument : arguments) { | |
testMessage += argument + " "; | |
} | |
*/ | |
} | |
new ActionBarMessage(testMessage).send((Player) sender); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment