@Override
 protected boolean set(EntityMinecartCommandBlock container, Optional<Text> value) {
   container
       .getCommandBlockLogic()
       .setLastOutput(SpongeTexts.toComponent(value.orElse(Text.of())));
   return true;
 }
Exemplo n.º 2
0
 public static List<Text> getPagesFromNBT(NBTTagCompound compound) {
   final NBTTagList list = compound.getTagList(ITEM_BOOK_PAGES, TAG_STRING);
   if (list.hasNoTags()) {
     return new ArrayList<>();
   }
   return SpongeTexts.fromLegacy(list);
 }
 @Override
 public Text getMessage() {
   if (this.spongeNewText == null) {
     this.spongeNewText = SpongeTexts.toText(this.component);
   }
   return this.spongeNewText;
 }
  @Override
  public void syncDataToSponge(Event forgeEvent) {
    super.syncDataToSponge(forgeEvent);

    ServerChatEvent event = (ServerChatEvent) forgeEvent;
    this.spongeNewText = SpongeTexts.toText(event.getComponent());
  }
  // Server events
  private static ServerChatEvent createServerChatEvent(Event event) {
    if (!(event instanceof MessageSinkEvent.Chat)) {
      throw new IllegalArgumentException("Event is not a valid MessageSinkEvent.");
    }

    MessageSinkEvent.Chat spongeEvent = (MessageSinkEvent.Chat) event;
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
      return null;
    }

    IChatComponent component =
        SpongeTexts.toComponent(spongeEvent.getOriginalMessage(), player.get().getLocale());
    if (!(component instanceof ChatComponentTranslation)) {
      component = new ChatComponentTranslation("%s", component);
    }

    // Using toPlain here is fine, since the raw message from the client
    // can't have formatting.
    ServerChatEvent forgeEvent =
        new ServerChatEvent(
            (EntityPlayerMP) player.get(),
            Texts.toPlain(spongeEvent.getOriginalMessage()),
            (ChatComponentTranslation) component);
    ((IMixinEventPlayerChat) forgeEvent).setRawMessage(spongeEvent.getRawMessage());

    return forgeEvent;
  }
 // TODO: Better integration with forge mods?
 @Override
 public void setMessage(Text text) {
   this.spongeNewText = text;
   final IChatComponent component =
       SpongeTexts.toComponent(text, ((Player) this.player).getLocale());
   if (component instanceof ChatComponentTranslation) {
     this.component = ((ChatComponentTranslation) component);
   } else {
     this.component = new ChatComponentTranslation("%s", component);
   }
 }
Exemplo n.º 7
0
 public static void setPagesToNBT(ItemStack stack, List<Text> pages) {
   final NBTTagList list = SpongeTexts.asLegacy(pages);
   final NBTTagCompound compound = getOrCreateCompound(stack);
   compound.setTag(ITEM_BOOK_PAGES, list);
   if (!compound.hasKey(ITEM_BOOK_TITLE)) {
     compound.setString(ITEM_BOOK_TITLE, INVALID_TITLE);
   }
   if (!compound.hasKey(ITEM_BOOK_AUTHOR)) {
     compound.setString(ITEM_BOOK_AUTHOR, INVALID_TITLE);
   }
   compound.setBoolean(ITEM_BOOK_RESOLVED, true);
 }
  /**
   * @Author Zidane
   *
   * <p>Invoke before {@code System.arraycopy(packetIn.getLines(), 0, tileentitysign.signText, 0,
   * 4);} (line 1156 in source) to call SignChangeEvent.
   *
   * @param packetIn Injected packet param
   * @param ci Info to provide mixin on how to handle the callback
   * @param worldserver Injected world param
   * @param blockpos Injected blockpos param
   * @param tileentity Injected tilentity param
   * @param tileentitysign Injected tileentitysign param
   */
  @Inject(
      method = "processUpdateSign",
      at =
          @At(
              value = "INVOKE",
              target =
                  "Lnet/minecraft/network/play/client/C12PacketUpdateSign;getLines()[Lnet/minecraft/util/IChatComponent;"),
      cancellable = true,
      locals = LocalCapture.CAPTURE_FAILSOFT)
  public void callSignChangeEvent(
      C12PacketUpdateSign packetIn,
      CallbackInfo ci,
      WorldServer worldserver,
      BlockPos blockpos,
      TileEntity tileentity,
      TileEntitySign tileentitysign) {
    ci.cancel();
    final Optional<SignData> existingSignData = ((Sign) tileentitysign).getData();
    if (!existingSignData.isPresent()) {
      // TODO Unsure if this is the best to do here...
      throw new RuntimeException("Critical error! Sign data not present on sign!");
    }
    final SignData changedSignData = existingSignData.get().copy();

    for (int i = 0; i < packetIn.getLines().length; i++) {
      changedSignData.setLine(i, SpongeTexts.toText(packetIn.getLines()[i]));
    }
    // I pass changedSignData in here twice to emulate the fact that even-though the current sign
    // data doesn't have the lines from the packet
    // applied, this is what it "is" right now. If the data shown in the world is desired, it can be
    // fetched from Sign.getData
    final SignChangeEvent event =
        SpongeEventFactory.createSignChange(
            Sponge.getGame(),
            new Cause(null, this.playerEntity, null),
            (Sign) tileentitysign,
            changedSignData,
            changedSignData);
    if (!Sponge.getGame().getEventManager().post(event)) {
      ((Sign) tileentitysign).offer(event.getNewData());
    } else {
      // If cancelled, I set the data back that was fetched from the sign. This means that if its a
      // new sign, the sign will be empty else
      // it will be the text of the sign that was showing in the world
      ((Sign) tileentitysign).offer(existingSignData.get());
    }
    tileentitysign.markDirty();
    worldserver.markBlockForUpdate(blockpos);
  }
 /**
  * @author Simon816
  *     <p>Fire the PlayerQuitEvent before playerLoggedOut is called in order for event handlers to
  *     change the quit message captured from {@link #onSendChatMsgCall}.
  */
 @Inject(
     method = "onDisconnect",
     at =
         @At(
             value = "INVOKE",
             target =
                 "Lnet/minecraft/server/management/ServerConfigurationManager;playerLoggedOut(Lnet/minecraft/entity/player/EntityPlayerMP;)V"))
 public void onDisconnectPlayer(IChatComponent reason, CallbackInfo ci) {
   PlayerQuitEvent event =
       SpongeImplEventFactory.createPlayerQuit(
           Sponge.getGame(),
           (Player) this.playerEntity,
           SpongeTexts.toText(this.tmpQuitMessage),
           ((Player) this.playerEntity).getMessageSink());
   this.tmpQuitMessage = null;
   Sponge.getGame().getEventManager().post(event);
   event.getSink().sendMessage(event.getNewMessage());
 }
 @Override
 protected Optional<Optional<Text>> getVal(EntityMinecartCommandBlock container) {
   Text text = SpongeTexts.toText(container.getCommandBlockLogic().getLastOutput());
   return Optional.of(Optional.of(text)); // #OptionalWrapping o.o
 }
Exemplo n.º 11
0
 public static void setLoreToNBT(ItemStack stack, List<Text> lore) {
   final NBTTagList list = SpongeTexts.asLegacy(lore);
   stack.getSubCompound(ITEM_DISPLAY, true).setTag(ITEM_LORE, list);
 }
Exemplo n.º 12
0
 public static List<Text> getLoreFromNBT(NBTTagCompound subCompound) {
   final NBTTagList list = subCompound.getTagList(ITEM_LORE, TAG_STRING);
   return SpongeTexts.fromLegacy(list);
 }
 @Inject(method = "<init>", at = @At("RETURN"))
 public void onConstructed(
     EntityPlayerMP player, String message, ChatComponentTranslation component, CallbackInfo ci) {
   this.spongeText = SpongeTexts.toText(component);
   this.sink = this.originalSink = ((Player) player).getMessageSink();
 }