Пример #1
0
 public static void setRenderDistance(World world, int distance) {
   try {
     ReflectionHelper.field("e")
         .in(ReflectionHelper.field("manager").in(((CraftWorld) world).getHandle()).get())
         .set(distance);
   } catch (Exception ignored) {
     ignored.printStackTrace();
   }
 }
Пример #2
0
 /**
  * Controls minecraft's thunderstorm flag in world data.
  *
  * @param world Bukkit world object
  * @param flag whether to set it to thundering or not
  */
 public static void setThunderNoEvent(World world, boolean flag) {
   try {
     WorldData data = ((CraftWorld) world).getHandle().worldData;
     ReflectionHelper.field("isThundering").in(data).set(flag);
     ReflectionHelper.field("thunderTicks").in(data).set(flag ? Integer.MAX_VALUE : 0);
   } catch (Exception ex) {
     world.setStorm(true); // Can still set the storm
   }
 }
  @Override
  public void init(GenericTask task, Map<String, String> properties) {
    Field[] fields = ReflectionHelper.getDeclaredFields(this.getClass(), null);
    for (Field field : fields) {
      if (!field.isAnnotationPresent(VersionProviderParam.class)) {
        continue;
      }

      VersionProviderParam param = field.getAnnotation(VersionProviderParam.class);
      if (!properties.containsKey(param.value())) {
        continue;
      }

      // make private and protected fields also accessible
      field.setAccessible(true);

      try {
        field.set(this, properties.get(param.value()));
      } catch (IllegalAccessException e) {
        throw new BuildException(
            "Failed to set build version provider param '" + param.value() + "'", e);
      }
    }
  }