123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package me.km.api;
- import java.util.ArrayList;
- import me.km.KajetansMod;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.text.ITextComponent;
- import net.minecraft.util.text.TextComponentUtils;
- import net.minecraft.util.text.TextFormatting;
- import net.minecraft.util.text.TextComponentString;
- import net.minecraft.world.World;
- public class MessageSender
- {
- private final ArrayList<ITextComponent> prefixes;
- private final ArrayList<TextFormatting> colors;
-
- public MessageSender()
- {
- prefixes = new ArrayList<>();
- colors = new ArrayList<>();
- }
-
- public void registerPrefix(String name, TextFormatting color)
- {
- TextComponentString text = new TextComponentString(name);
- text.getStyle().setColor(color);
- prefixes.add(new TextComponentString("[").appendSibling(text).appendText("] "));
- colors.add(color);
- }
- public void send(ICommandSender cs, String msg, int id)
- {
- if(cs == null)
- {
- return;
- }
- cs.sendMessage(prefixes.get(id).createCopy().appendText(msg));
- }
-
- public void send(ICommandSender cs, String msg)
- {
- send(cs, msg, 0);
- }
-
- public void sendToPlayers(World w, BlockPos l, double radius, String msg)
- {
- ITextComponent s = prefixes.get(0).createCopy().appendText(msg);
- Utils.getNearbyEntities(w, l, radius, EntityPlayer.class).forEach(p -> ((EntityPlayer) p).sendMessage(s));
- }
-
- public void sendBroadcast(String msg)
- {
- KajetansMod.server.getPlayerList().sendMessage(prefixes.get(0).createCopy().appendText(msg));
- }
-
- public void sendListElement(ICommandSender cs, String msg, int id)
- {
- if(cs == null)
- {
- return;
- }
- TextComponentString text = new TextComponentString("");
- TextComponentString text2 = new TextComponentString(" - ");
- text2.getStyle().setColor(colors.get(id));
- text.appendSibling(text2);
- cs.sendMessage(text.appendText(msg));
- }
-
- public void sendListElement(ICommandSender cs, String msg)
- {
- sendListElement(cs, msg, 0);
- }
-
- public void sendHelpListElement(ICommandSender cs, String msg, String msg2, int id)
- {
- if(cs == null)
- {
- return;
- }
- TextComponentString text = new TextComponentString("");
- TextComponentString text2 = new TextComponentString(" - " + msg + " ");
- text2.getStyle().setColor(colors.get(id));
- text.appendSibling(text2);
- cs.sendMessage(text.appendText(msg2));
- }
-
- public void sendHelpListElement(ICommandSender cs, String msg, String msg2)
- {
- sendHelpListElement(cs, msg, msg2, 0);
- }
-
- public void sendWarning(ICommandSender cs, String msg, int id)
- {
- if(cs == null)
- {
- return;
- }
- TextComponentString text = new TextComponentString(msg);
- text.getStyle().setColor(TextFormatting.RED);
- cs.sendMessage(prefixes.get(id).createCopy().appendSibling(text));
- }
-
- public void sendWarning(ICommandSender cs, String msg)
- {
- if(cs == null)
- {
- return;
- }
- sendWarning(cs, msg, 0);
- }
-
- public void sendToConsole(String msg, int id)
- {
- send(KajetansMod.server, msg, id);
- }
-
- public void sendToConsole(String msg)
- {
- sendToConsole(msg, 0);
- }
-
- public void sendWarningToConsole(String msg, int id)
- {
- sendWarning(KajetansMod.server, msg, id);
- }
-
- public void sendWarningToConsole(String msg)
- {
- sendWarningToConsole(msg, 0);
- }
- }
|