示例#1
0
 // This is called client side.
 public List<ClientScreenModule> getClientScreenModules() {
   if (clientScreenModules == null) {
     needsServerData = false;
     clientScreenModules = new ArrayList<ClientScreenModule>();
     for (int i = 0; i < inventoryHelper.getCount(); i++) {
       ItemStack itemStack = inventoryHelper.getStackInSlot(i);
       if (itemStack != null && itemStack.getItem() instanceof ModuleProvider) {
         ModuleProvider moduleProvider = (ModuleProvider) itemStack.getItem();
         ClientScreenModule clientScreenModule;
         try {
           clientScreenModule = moduleProvider.getClientScreenModule().newInstance();
         } catch (InstantiationException e) {
           e.printStackTrace();
           continue;
         } catch (IllegalAccessException e) {
           e.printStackTrace();
           continue;
         }
         clientScreenModule.setupFromNBT(
             itemStack.getTagCompound(), worldObj.provider.dimensionId, xCoord, yCoord, zCoord);
         clientScreenModules.add(clientScreenModule);
         if (clientScreenModule.needsServerData()) {
           needsServerData = true;
         }
       } else {
         clientScreenModules.add(
             null); // To keep the indexing correct so that the modules correspond with there slot
                    // number.
       }
     }
   }
   return clientScreenModules;
 }
  /**
   * Creates the brain and launches if it is an agent. The brain class is given as a String. The
   * name argument is used to instantiate the name of the corresponding agent. If the gui flag is
   * true, a bean is created and associated to this agent.
   */
  public void makeBrain(String className, String name, boolean gui, String behaviorFileName) {
    try {
      Class c;
      // c = Class.forName(className);
      c = madkit.kernel.Utils.loadClass(className);
      myBrain = (Brain) c.newInstance();
      myBrain.setBody(this);
      if (myBrain instanceof AbstractAgent) {
        String n = name;
        if (n == null) {
          n = getLabel();
        }
        if (n == null) {
          n = getID();
        }
        if (behaviorFileName != null) setBehaviorFileName(behaviorFileName);
        getStructure().getAgent().doLaunchAgent((AbstractAgent) myBrain, n, gui);
      }

    } catch (ClassNotFoundException ev) {
      System.err.println("Class not found :" + className + " " + ev);
      ev.printStackTrace();
    } catch (InstantiationException e) {
      System.err.println("Can't instanciate ! " + className + " " + e);
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      System.err.println("illegal access! " + className + " " + e);
      e.printStackTrace();
    }
  }
示例#3
0
  /**
   * Method to store the value under the specified key
   *
   * @param key Key to store the value under
   * @param value Object to store
   * @param listType Type of List implementation to use to store multivalues in
   * @param index Index into the list of values to place the new value
   * @return Previous object stored under this key
   */
  public Object put(Object key, Object value, Class listType, int index) {

    // Get the list of values for the key
    List values = (List) super.get(key);

    // If none found, create a new list
    if (values == null) {

      // Create the new instance type of List
      try {
        values = (List) listType.newInstance();
      } catch (IllegalAccessException eae) {
        eae.printStackTrace();
      } catch (InstantiationException inste) {
        inste.printStackTrace();
      }
    }

    // If the value doesn't already exist
    if (!values.contains(value)) {

      // If index is -1, then append to end
      if (index > -1) {
        values.add(index, value);
      } else {
        values.add(value);
      }
    }

    return super.put(key, values);
  }
  public Distribution<T> parse(String distrAsString) {
    DiscreteDistribution<T> dist = new DiscreteDistribution<T>();

    StringTokenizer tok = new StringTokenizer(distrAsString, ",");

    while (tok.hasMoreElements()) {
      String pair = tok.nextToken().trim();
      StringTokenizer sub = new StringTokenizer(pair, "/");

      try {
        T value = (T) domainType.getConstructor(String.class).newInstance(sub.nextToken().trim());
        Degree deg = (Degree) getDegreeStringConstructor().newInstance(sub.nextToken().trim());

        dist.put(value, deg);
      } catch (NoSuchMethodException nsme) {
        nsme.printStackTrace();
      } catch (IllegalAccessException iae) {
        iae.printStackTrace();
      } catch (InstantiationException ie) {
        ie.printStackTrace();
      } catch (InvocationTargetException ite) {
        ite.printStackTrace();
      }
    }
    return dist;
  }
示例#5
0
  /**
   * forward an execute request to a helper instance associated with the rule
   *
   * @param recipient the recipient of the method from which execution of this rule was triggered or
   *     null if it was a static method
   * @param args the arguments of the method from which execution of this rule was triggered
   */
  private void execute(Object recipient, Object[] args) throws ExecuteException {
    // type check and createHelperAdapter the rule now if it has not already been done

    if (ensureTypeCheckedCompiled()) {

      // create a helper and get it to execute the rule
      // eventually we will create a subclass of helper for each rule and createHelperAdapter
      // an implementation of execute from the rule source. for now we create a generic
      // helper and call the generic execute method which interprets the rule
      HelperAdapter helper;
      try {
        Constructor constructor = helperImplementationClass.getConstructor(Rule.class);
        helper = (HelperAdapter) constructor.newInstance(this);
        // helper = (RuleHelper)helperClass.newInstance();
        // helper.setRule(this);
        helper.execute(recipient, args);
      } catch (NoSuchMethodException e) {
        // should not happen!!!
        System.out.println(
            "cannot find constructor "
                + helperImplementationClass.getCanonicalName()
                + "(Rule) for helper class");
        e.printStackTrace(System.out);
        return;
      } catch (InvocationTargetException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      } catch (InstantiationException e) {
        // should not happen
        System.out.println(
            "cannot create instance of " + helperImplementationClass.getCanonicalName());
        e.printStackTrace(System.out);
        return;
      } catch (IllegalAccessException e) {
        // should not happen
        System.out.println("cannot access " + helperImplementationClass.getCanonicalName());
        e.printStackTrace(System.out);
        return;
      } catch (ClassCastException e) {
        // should not happen
        System.out.println("cast exception " + helperImplementationClass.getCanonicalName());
        e.printStackTrace(System.out);
        return;
      } catch (EarlyReturnException e) {
        throw e;
      } catch (ThrowException e) {
        throw e;
      } catch (ExecuteException e) {
        System.out.println(getName() + " : " + e);
        throw e;
      } catch (Throwable throwable) {
        System.out.println(getName() + " : " + throwable);
        throw new ExecuteException(getName() + "  : caught " + throwable, throwable);
      }
    }
  }
示例#6
0
 @SuppressWarnings("unchecked")
 public AbstractNetSystem() {
   super();
   try {
     this.marking = (M) Marking.class.newInstance();
     this.marking.setPetriNet(this);
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
 }
 private Variation createInstance(String className) {
   try {
     return (Variation) Class.forName(className).newInstance();
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   return null;
 }
 public E getE() {
   if (e == null) {
     // 这是使用泛型没有办法之举:ERROR InstantiatingNullHandler Could not create
     // and/or set value back on to object
     // at
     // com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:169)
     try {
       e = this.getEntityClass().newInstance();
     } catch (InstantiationException e) {
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     }
   }
   return e;
 }
示例#9
0
  @SuppressWarnings("unchecked")
  private <T> T clone(final T o, final Map<Object, Object> clones) throws IllegalAccessException {
    if (o == null) return null;
    if (ignoredInstances.containsKey(o)) return o;

    final Class<T> clz = (Class<T>) o.getClass();
    if (clz.isEnum()) return o;
    // skip cloning ignored classes
    if (ignored.contains(clz)) return o;
    final Object clonedPreviously = clones != null ? clones.get(o) : null;
    if (clonedPreviously != null) return (T) clonedPreviously;

    if (clz.isArray()) {
      final int length = Array.getLength(o);
      final T newInstance = (T) Array.newInstance(clz.getComponentType(), length);
      clones.put(o, newInstance);
      for (int i = 0; i < length; i++) {
        final Object v = Array.get(o, i);
        final Object clone = clones != null ? clone(v, clones) : v;
        Array.set(newInstance, i, clone);
      }
      return newInstance;
    }

    T newInstance = null;
    try {
      newInstance = newInstance(clz);
    } catch (InstantiationException e) {
      e.printStackTrace();
    }
    if (clones != null) {
      clones.put(o, newInstance);
    }
    final List<Field> fields = allFields(clz);
    for (final Field field : fields) {
      if (!Modifier.isStatic(field.getModifiers())) {
        field.setAccessible(true);
        final Object fieldObject = field.get(o);
        final Object fieldObjectClone = clones != null ? clone(fieldObject, clones) : fieldObject;
        field.set(newInstance, fieldObjectClone);
      }
    }
    return newInstance;
  }
示例#10
0
 public List<Object> readExcel(Workbook wb, Class clz, int readLine, int tailLine) {
   Sheet sheet = wb.getSheetAt(0); // 取第一张表
   List<Object> objs = null;
   try {
     Row row = sheet.getRow(readLine); // 开始行,主题栏
     objs = new ArrayList<Object>();
     Map<Integer, String> maps = getHeaderMap(row, clz); // 设定对应的字段顺序与方法名
     if (maps == null || maps.size() <= 0)
       throw new RuntimeException("要读取的Excel的格式不正确,检查是否设定了合适的行"); // 与order顺序不符
     for (int i = readLine + 1; i <= sheet.getLastRowNum() - tailLine; i++) { // 取数据
       row = sheet.getRow(i);
       Object obj = clz.newInstance(); //   调用无参结构
       for (Cell c : row) {
         int ci = c.getColumnIndex();
         String mn = maps.get(ci).substring(3); // 消除get
         mn = mn.substring(0, 1).toLowerCase() + mn.substring(1);
         Map<String, Object> params = new HashMap<String, Object>();
         if (!"enterDate".equals(mn)) c.setCellType(Cell.CELL_TYPE_STRING); // 设置单元格格式
         else c.setCellType(Cell.CELL_TYPE_NUMERIC);
         if (this.getCellValue(c).trim().equals("是")) {
           BeanUtils.copyProperty(obj, mn, 1);
         } else if (this.getCellValue(c).trim().equals("否")) {
           BeanUtils.copyProperty(obj, mn, 0);
         } else BeanUtils.copyProperty(obj, mn, this.getCellValue(c));
       }
       objs.add(obj);
     }
   } catch (InstantiationException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (InvocationTargetException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (NumberFormatException e) {
     e.printStackTrace();
     logger.error(e);
   }
   return objs;
 }
 // convenience method for invoking a constructor;
 // used as a central point for exception handling for Java reflection
 // constructor calls
 private <T> T invokeConstructor(
     Class<T> clazz, Class<?>[] argumentClasses, Object[] argumentObjects) {
   try {
     Constructor<T> constructor = clazz.getConstructor(argumentClasses);
     return constructor.newInstance(argumentObjects);
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
   }
   return null;
 }
示例#12
0
 protected synchronized Message receiveMessage() throws IOException {
   if (messageBuffer.size() > 0) {
     Message m = (Message) messageBuffer.get(0);
     messageBuffer.remove(0);
     return m;
   }
   try {
     InetSocketAddress remoteAddress = (InetSocketAddress) channel.receive(receiveBuffer);
     if (remoteAddress != null) {
       int len = receiveBuffer.position();
       receiveBuffer.rewind();
       receiveBuffer.get(buf, 0, len);
       try {
         IP address = IP.fromInetAddress(remoteAddress.getAddress());
         int port = remoteAddress.getPort();
         extractor.appendData(buf, 0, len, new SocketDescriptor(address, port));
         receiveBuffer.clear();
         extractor.updateAvailableMessages();
         return extractor.nextMessage();
       } catch (EOFException exc) {
         exc.printStackTrace();
         System.err.println(buf.length + ", " + len);
       } catch (InvocationTargetException exc) {
         exc.printStackTrace();
       } catch (IllegalAccessException exc) {
         exc.printStackTrace();
       } catch (InstantiationException exc) {
         exc.printStackTrace();
       } catch (IllegalArgumentException e) {
         e.printStackTrace();
       } catch (InvalidCompressionMethodException e) {
         e.printStackTrace();
       }
     }
   } catch (ClosedChannelException exc) {
     if (isKeepAlive()) {
       throw exc;
     }
   }
   return null;
 }
示例#13
0
  // This is called server side.
  public List<ScreenModule> getScreenModules() {
    if (screenModules == null) {
      totalRfPerTick = 0;
      screenModules = new ArrayList<ScreenModule>();
      for (int i = 0; i < inventoryHelper.getCount(); i++) {
        ItemStack itemStack = inventoryHelper.getStackInSlot(i);
        if (itemStack != null && itemStack.getItem() instanceof ModuleProvider) {
          ModuleProvider moduleProvider = (ModuleProvider) itemStack.getItem();
          ScreenModule screenModule;
          try {
            screenModule = moduleProvider.getServerScreenModule().newInstance();
          } catch (InstantiationException e) {
            e.printStackTrace();
            continue;
          } catch (IllegalAccessException e) {
            e.printStackTrace();
            continue;
          }
          screenModule.setupFromNBT(
              itemStack.getTagCompound(), worldObj.provider.dimensionId, xCoord, yCoord, zCoord);
          screenModules.add(screenModule);
          totalRfPerTick += screenModule.getRfPerTick();

          if (screenModule instanceof ComputerScreenModule) {
            ComputerScreenModule computerScreenModule = (ComputerScreenModule) screenModule;
            String tag = computerScreenModule.getTag();
            if (!computerModules.containsKey(tag)) {
              computerModules.put(tag, new ArrayList<ComputerScreenModule>());
            }
            computerModules.get(tag).add(computerScreenModule);
          }
        } else {
          screenModules.add(
              null); // To keep the indexing correct so that the modules correspond with there slot
                     // number.
        }
      }
    }
    return screenModules;
  }
示例#14
0
 static Mod newModInstance(Class<? extends Mod> modClass) {
   Mod mod = null;
   try {
     mod =
         modClass
             .getConstructor(MinecraftVersion.class)
             .newInstance(MCPatcher.minecraft.getVersion());
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     try {
       mod = modClass.newInstance();
     } catch (Exception e1) {
       e1.printStackTrace();
     }
   }
   return mod;
 }
示例#15
0
  public ReverseFlashCard() {
    // basic init
    setTitle("WayMemo -Reverse Flash Card Mode");
    this.setSize(800, 600);
    paneCenter = new JPanel(new GridLayout(7, 1));

    add(ln, "North");
    add(paneCenter, "Center");
    add(b2, "West");
    add(bReset, "South");
    add(b1, "East");
    paneCenter.add(l1);
    paneCenter.add(l2);
    paneCenter.add(l3);
    paneCenter.add(l4);
    paneCenter.add(l5);
    paneCenter.add(b3);
    paneCenter.add(pMark);
    pMark.add(bMark);
    pMark.add(bUnMark);
    pMark.add(lt);

    // text area init

    Utility.initTextAreaView(l1);
    Utility.initTextAreaView(l2);
    Utility.initTextAreaView(l3);
    Utility.initTextAreaView(l4);
    Utility.initTextAreaView(l5);

    // action

    //
    Action actionNext =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num++;
            wordDisplay();
          }
        };
    b1.getInputMap().put(KeyStroke.getKeyStroke("C"), "pressed");
    b1.getActionMap().put("released", actionNext);
    //
    Action actionBack =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num--;
            wordDisplay();
          }
        };
    b2.getInputMap().put(KeyStroke.getKeyStroke("Z"), "pressed");
    b2.getActionMap().put("released", actionBack);
    //
    Action actionShow =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            l1.setText(dtr[num]);
            l3.setText(d2[num]);
            l4.setText(d3[num]);
            l5.setText(d4[num]);
          }
        };
    b3.getInputMap().put(KeyStroke.getKeyStroke("X"), "pressed");
    b3.getActionMap().put("released", actionShow);
    //
    //
    Action actionMark =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            d1[num] = "[MARKED*]" + d1[num];
            l2.setText(d1[num]);
          }
        };
    bMark.getInputMap().put(KeyStroke.getKeyStroke("S"), "pressed");
    bMark.getActionMap().put("released", actionMark);
    //
    //
    //
    Action actionUnmark =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            d1[num] = od1[num];
            l2.setText(d1[num]);
          }
        };
    bUnMark.getInputMap().put(KeyStroke.getKeyStroke("F2"), "pressed");
    bUnMark.getActionMap().put("released", actionUnmark);
    //
    //
    Action actionReset =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num = 0;
            wordDisplay();
          }
        };
    bReset.getInputMap().put(KeyStroke.getKeyStroke("r"), "pressed");
    bReset.getActionMap().put("released", actionReset);
    //
    //
    b1.setMnemonic(KeyEvent.VK_C);
    b2.setMnemonic(KeyEvent.VK_Z);
    b3.setMnemonic(KeyEvent.VK_X);
    bMark.setMnemonic(KeyEvent.VK_S);
    bUnMark.setMnemonic(KeyEvent.VK_D);
    bReset.setMnemonic(KeyEvent.VK_R);

    b1.addActionListener(actionNext);
    b2.addActionListener(actionBack);
    b3.addActionListener(actionShow);
    bReset.addActionListener(actionReset);
    bMark.addActionListener(actionMark);
    bUnMark.addActionListener(actionUnmark);
    //
    //
    try {
      this.fileScan(new OpenFileDTR().getPathDTR());
    } catch (IOException e) {
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#16
0
  /**
   * Load a license.
   *
   * @param path The license file path.
   * @return The license info.
   */
  public static LicenseInfo loadLicense(Log log, String path) {
    String keyString = null;
    try {
      keyString =
          ((AkteraKeyProvider) Class.forName("de.iritgo.aktera.license.AkteraKey").newInstance())
              .getKey();
    } catch (InstantiationException x1) {
      x1.printStackTrace();
    } catch (IllegalAccessException x1) {
      x1.printStackTrace();
    } catch (ClassNotFoundException x1) {
      x1.printStackTrace();
    }

    Properties props = new Properties();

    try {
      BufferedReader in = new BufferedReader(new FileReader(path));
      StringBuffer sb = new StringBuffer();
      String line = null;

      while ((line = in.readLine()) != null) {
        if ("# SHA1 Signature".equals(line)) {
          break;
        } else {
          sb.append(line + "\n");
        }
      }

      StringBuffer sbSig = new StringBuffer();

      while ((line = in.readLine()) != null) {
        sbSig.append(line + "\n");
      }

      X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.decodeBase64(keyString.getBytes()));
      KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
      PublicKey key = keyFactory.generatePublic(spec);

      Signature sig = Signature.getInstance("SHA1withDSA", "SUN");

      sig.initVerify(key);
      sig.update(sb.toString().getBytes(), 0, sb.toString().getBytes().length);

      boolean valid = sig.verify(Base64.decodeBase64(sbSig.toString().getBytes()));

      if (!valid) {
        return null;
      }

      try {
        props.load(new StringReader(sb.toString()));
      } catch (Exception x) {
        System.out.println("LicenseTools.loadLicense: " + x.getMessage());
        x.printStackTrace();
        return null;
      }
    } catch (Exception x) {
      System.out.println("LicenseTools.loadLicense: " + x.getMessage());
      x.printStackTrace();
      return null;
    }

    return new LicenseInfo(log, props);
  }
示例#17
0
  public RPGItem(ConfigurationSection s) {

    name = s.getString("name");
    id = s.getInt("id");
    setDisplay(s.getString("display"), false);
    setType(
        s.getString("type", Plugin.plugin.getConfig().getString("defaults.sword", "Sword")), false);
    setHand(
        s.getString("hand", Plugin.plugin.getConfig().getString("defaults.hand", "One handed")),
        false);
    setLore(s.getString("lore"), false);
    description = (List<String>) s.getList("description", new ArrayList<String>());
    for (int i = 0; i < description.size(); i++) {
      description.set(i, ChatColor.translateAlternateColorCodes('&', description.get(i)));
    }
    quality = Quality.valueOf(s.getString("quality"));
    damageMin = s.getInt("damageMin");
    damageMax = s.getInt("damageMax");
    armour = s.getInt("armour", 0);
    item = new ItemStack(Material.valueOf(s.getString("item")));
    ItemMeta meta = item.getItemMeta();
    if (meta instanceof LeatherArmorMeta) {
      ((LeatherArmorMeta) meta).setColor(Color.fromRGB(s.getInt("item_colour", 0)));
    } else {
      item.setDurability((short) s.getInt("item_data", 0));
    }
    for (String locale : Locale.getLocales()) {
      localeMeta.put(locale, meta.clone());
    }
    ignoreWorldGuard = s.getBoolean("ignoreWorldGuard", false);

    // Powers
    ConfigurationSection powerList = s.getConfigurationSection("powers");
    if (powerList != null) {
      for (String sectionKey : powerList.getKeys(false)) {
        ConfigurationSection section = powerList.getConfigurationSection(sectionKey);
        try {
          if (!Power.powers.containsKey(section.getString("powerName"))) {
            // Invalid power
            continue;
          }
          Power pow = Power.powers.get(section.getString("powerName")).newInstance();
          pow.init(section);
          pow.item = this;
          addPower(pow, false);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    }
    encodedID = getMCEncodedID(id);

    // Recipes
    hasRecipe = s.getBoolean("hasRecipe", false);
    if (hasRecipe) {
      recipe = (List<ItemStack>) s.getList("recipe");
    }

    ConfigurationSection drops = s.getConfigurationSection("dropChances");
    if (drops != null) {
      for (String key : drops.getKeys(false)) {
        double chance = drops.getDouble(key, 0.0);
        chance = Math.min(chance, 100.0);
        if (chance > 0) {
          dropChances.put(key, chance);
          if (!Events.drops.containsKey(key)) {
            Events.drops.put(key, new HashSet<Integer>());
          }
          Set<Integer> set = Events.drops.get(key);
          set.add(getID());
        } else {
          dropChances.remove(key);
          if (Events.drops.containsKey(key)) {
            Set<Integer> set = Events.drops.get(key);
            set.remove(getID());
          }
        }
        dropChances.put(key, chance);
      }
    }
    if (item.getType().getMaxDurability() != 0) {
      hasBar = true;
    }
    maxDurability = s.getInt("maxDurability", item.getType().getMaxDurability());
    forceBar = s.getBoolean("forceBar", false);

    if (maxDurability == 0) {
      maxDurability = -1;
    }

    rebuild();
  }