예제 #1
0
  public boolean func_174882_b(final EntityPlayer p_174882_1_) {
    ICommandSender var2 =
        new ICommandSender() {

          public String getName() {
            return p_174882_1_.getName();
          }

          public IChatComponent getDisplayName() {
            return p_174882_1_.getDisplayName();
          }

          public void addChatMessage(IChatComponent message) {}

          public boolean canCommandSenderUseCommand(int permissionLevel, String command) {
            return true;
          }

          public BlockPos getPosition() {
            return TileEntitySign.this.pos;
          }

          public Vec3 getPositionVector() {
            return new Vec3(
                (double) TileEntitySign.this.pos.getX() + 0.5D,
                (double) TileEntitySign.this.pos.getY() + 0.5D,
                (double) TileEntitySign.this.pos.getZ() + 0.5D);
          }

          public World getEntityWorld() {
            return p_174882_1_.getEntityWorld();
          }

          public Entity getCommandSenderEntity() {
            return p_174882_1_;
          }

          public boolean sendCommandFeedback() {
            return false;
          }

          public void func_174794_a(CommandResultStats.Type p_174794_1_, int p_174794_2_) {
            TileEntitySign.this.field_174883_i.func_179672_a(this, p_174794_1_, p_174794_2_);
          }
        };

    for (int var3 = 0; var3 < this.signText.length; ++var3) {
      ChatStyle var4 = this.signText[var3] == null ? null : this.signText[var3].getChatStyle();

      if (var4 != null && var4.getChatClickEvent() != null) {
        ClickEvent var5 = var4.getChatClickEvent();

        if (var5.getAction() == ClickEvent.Action.RUN_COMMAND) {
          MinecraftServer.getServer().getCommandManager().executeCommand(var2, var5.getValue());
        }
      }
    }

    return true;
  }
  @Override
  public void processCommand(ICommandSender sender, String[] params) {
    if (canCommandSenderUseCommand(sender)) {
      ChatStyle style = new ChatStyle();
      EntityPlayer player = (EntityPlayer) getCommandSenderAsPlayer(sender);
      ItemStack stack = player.getCurrentEquippedItem();
      if (stack != null) {
        for (String val : params[0].split(":")) {
          int value = Integer.parseInt(val);
          if (value < 16) {
            style.setColor(EnumChatFormatting.values()[value]);
          } else {
            switch (EnumChatFormatting.values()[value]) {
              case OBFUSCATED:
                style.setObfuscated(true);
                break;
              case BOLD:
                style.setBold(true);
                break;
              case STRIKETHROUGH:
                style.setStrikethrough(true);
                break;
              case UNDERLINE:
                style.setUnderlined(true);
                break;
              case ITALIC:
                style.setItalic(true);
                break;
              default:
                break;
            }
          }
        }
        StringBuilder name = new StringBuilder();
        for (String str : params[1].split(":")) {
          name.append(str + " ");
        }
        if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());
        NBTTagList list = new NBTTagList();
        StringBuilder desc = new StringBuilder();
        for (int i = 1; i < params.length; i++) {
          desc.append(params[i].replace(':', ' '));
        }

        NBTTagString strTag = new NBTTagString(style.getFormattingCode() + desc.toString());
        list.appendTag(strTag);
        stack.stackTagCompound.getCompoundTag("display").setTag("Lore", list);

        sender.addChatMessage(
            new ChatComponentTranslation("commands.lore.success", stack.getDisplayName()));
      }
    }
  }
예제 #3
0
 void fixSerialization() {
   List<HoverEvent> list = Lists.newArrayList();
   @SuppressWarnings("unchecked")
   Iterable<IChatComponent> chat = message;
   for (IChatComponent message : chat) {
     ChatStyle style = message.getChatStyle();
     HoverEvent hover = style.getChatHoverEvent();
     if (list.contains(hover)) continue;
     list.add(hover);
     if (hover != null && hover.getAction() == Action.SHOW_ENTITY) {
       // serialization is bugged
       try {
         String[] names = {"b", "field_150703_b", "value"};
         ReflectionHelper.setFieldValue(HoverEvent.class, hover, null, names);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }
예제 #4
0
  public boolean executeCommand(final EntityPlayer playerIn) {
    ICommandSender icommandsender =
        new ICommandSender() {
          public String getName() {
            return playerIn.getName();
          }

          public IChatComponent getDisplayName() {
            return playerIn.getDisplayName();
          }

          public void addChatMessage(IChatComponent component) {}

          public boolean canCommandSenderUseCommand(int permLevel, String commandName) {
            return permLevel <= 2;
          }

          public BlockPos getPosition() {
            return TileEntitySign.this.pos;
          }

          public Vec3 getPositionVector() {
            return new Vec3(
                (double) TileEntitySign.this.pos.getX() + 0.5D,
                (double) TileEntitySign.this.pos.getY() + 0.5D,
                (double) TileEntitySign.this.pos.getZ() + 0.5D);
          }

          public World getEntityWorld() {
            return playerIn.getEntityWorld();
          }

          public Entity getCommandSenderEntity() {
            return playerIn;
          }

          public boolean sendCommandFeedback() {
            return false;
          }

          public void setCommandStat(CommandResultStats.Type type, int amount) {
            TileEntitySign.this.stats.func_179672_a(this, type, amount);
          }
        };

    for (int i = 0; i < this.signText.length; ++i) {
      ChatStyle chatstyle = this.signText[i] == null ? null : this.signText[i].getChatStyle();

      if (chatstyle != null && chatstyle.getChatClickEvent() != null) {
        ClickEvent clickevent = chatstyle.getChatClickEvent();

        if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) {
          MinecraftServer.getServer()
              .getCommandManager()
              .executeCommand(icommandsender, clickevent.getValue());
        }
      }
    }

    return true;
  }
예제 #5
0
 static {
   description.setColor(GRAY);
   version.setColor(AQUA);
 }