Guest User

Untitled

a guest
Sep 7th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. package net.minecraft.command;
  2.  
  3. import com.google.gson.JsonParseException;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import javax.annotation.Nullable;
  7. import net.minecraft.entity.player.EntityPlayerMP;
  8. import net.minecraft.network.play.server.SPacketTitle;
  9. import net.minecraft.server.MinecraftServer;
  10. import net.minecraft.util.math.BlockPos;
  11. import net.minecraft.util.text.ITextComponent;
  12. import net.minecraft.util.text.TextComponentUtils;
  13. import org.apache.logging.log4j.LogManager;
  14. import org.apache.logging.log4j.Logger;
  15.  
  16. public class CommandTitle extends CommandBase
  17. {
  18. private static final Logger LOGGER = LogManager.getLogger();
  19.  
  20. /**
  21. * Gets the name of the command
  22. */
  23. public String getCommandName()
  24. {
  25. return "title";
  26. }
  27.  
  28. /**
  29. * Return the required permission level for this command.
  30. */
  31. public int getRequiredPermissionLevel()
  32. {
  33. return 2;
  34. }
  35.  
  36. /**
  37. * Gets the usage string for the command.
  38. */
  39. public String getCommandUsage(ICommandSender sender)
  40. {
  41. return "commands.title.usage";
  42. }
  43.  
  44. /**
  45. * Callback for when the command is executed
  46. */
  47. public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
  48. {
  49. if (args.length < 2)
  50. {
  51. throw new WrongUsageException("commands.title.usage", new Object[0]);
  52. }
  53. else
  54. {
  55. if (args.length < 3)
  56. {
  57. if ("title".equals(args[1]) || "subtitle".equals(args[1]) || "actionbar".equals(args[1]))
  58. {
  59. throw new WrongUsageException("commands.title.usage.title", new Object[0]);
  60. }
  61.  
  62. if ("times".equals(args[1]))
  63. {
  64. throw new WrongUsageException("commands.title.usage.times", new Object[0]);
  65. }
  66. }
  67.  
  68. EntityPlayerMP entityplayermp = getPlayer(server, sender, args[0]);
  69. SPacketTitle.Type spackettitle$type = SPacketTitle.Type.byName(args[1]);
  70.  
  71. if (spackettitle$type != SPacketTitle.Type.CLEAR && spackettitle$type != SPacketTitle.Type.RESET)
  72. {
  73. if (spackettitle$type == SPacketTitle.Type.TIMES)
  74. {
  75. if (args.length != 5)
  76. {
  77. throw new WrongUsageException("commands.title.usage", new Object[0]);
  78. }
  79. else
  80. {
  81. int i = parseInt(args[2]);
  82. int j = parseInt(args[3]);
  83. int k = parseInt(args[4]);
  84. SPacketTitle spackettitle2 = new SPacketTitle(i, j, k);
  85. entityplayermp.connection.sendPacket(spackettitle2);
  86. notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
  87. }
  88. }
  89. else if (args.length < 3)
  90. {
  91. throw new WrongUsageException("commands.title.usage", new Object[0]);
  92. }
  93. else
  94. {
  95. String s = buildString(args, 2);
  96. ITextComponent itextcomponent;
  97.  
  98. try
  99. {
  100. itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
  101. }
  102. catch (JsonParseException jsonparseexception)
  103. {
  104. throw toSyntaxException(jsonparseexception);
  105. }
  106.  
  107. SPacketTitle spackettitle1 = new SPacketTitle(spackettitle$type, TextComponentUtils.processComponent(sender, itextcomponent, entityplayermp));
  108. entityplayermp.connection.sendPacket(spackettitle1);
  109. notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
  110. }
  111. }
  112. else if (args.length != 2)
  113. {
  114. throw new WrongUsageException("commands.title.usage", new Object[0]);
  115. }
  116. else
  117. {
  118. SPacketTitle spackettitle = new SPacketTitle(spackettitle$type, (ITextComponent)null);
  119. entityplayermp.connection.sendPacket(spackettitle);
  120. notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
  121. }
  122. }
  123. }
  124.  
  125. public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos)
  126. {
  127. if (args.length == 1)
  128. {
  129. return getListOfStringsMatchingLastWord(args, server.getAllUsernames());
  130. }
  131. else
  132. {
  133. return args.length == 2 ? getListOfStringsMatchingLastWord(args, SPacketTitle.Type.getNames()) : Collections.emptyList();
  134. }
  135. }
  136.  
  137. /**
  138. * Return whether the specified command parameter index is a username parameter.
  139. */
  140. public boolean isUsernameIndex(String[] args, int index)
  141. {
  142. return index == 0;
  143. }
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment