Java Code Examples for ch.njol.skript.classes.Changer#ChangeMode

The following examples show how to use ch.njol.skript.classes.Changer#ChangeMode . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExprCustomModelData.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	long data = delta == null ? 0 : ((Number) delta[0]).intValue();
	if (data > 99999999 || data < 0) data = 0;
	for (ItemType item : getExpr().getArray(e)) {
		long oldData = 0;
		ItemMeta meta = item.getItemMeta();
		if (meta.hasCustomModelData())
			oldData = meta.getCustomModelData();
		switch (mode) {
			case ADD:
				data = oldData + data;
				break;
			case REMOVE:
				data = oldData - data;
				break;
			case DELETE:
			case RESET:
			case REMOVE_ALL:
				data = 0;
		}
		meta.setCustomModelData((int) data);
		item.setItemMeta(meta);
	}
}
 
Example 2
Source File: ExprBookAuthor.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	ItemStack itemStack = getExpr().getSingle(e).getRandom();
	if (itemStack == null || !book.isOfType(itemStack))
		return;
	BookMeta bookMeta = (BookMeta) itemStack.getItemMeta();
	switch (mode){
		case SET:
			bookMeta.setAuthor(delta == null ? "" : (String) delta[0]);
			break;
		case RESET:
		case DELETE:
			bookMeta.setAuthor("");
			break;
			//$CASES-OMITTED$
		default:
			assert false;
	}
	itemStack.setItemMeta(bookMeta);
}
 
Example 3
Source File: ExprTimePlayed.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	if (delta == null) {
		return;
	}
	long ticks = ((Timespan) delta[0]).getTicks_i();
	for (Player player : getExpr().getArray(e)) {
		long playerTicks = player.getStatistic(TIME_PLAYED);
		switch (mode) {
			case ADD:
				ticks = playerTicks + ticks;
				break;
			case REMOVE:
				ticks = playerTicks - ticks;
				break;
		}
		player.setStatistic(TIME_PLAYED, (int) ticks);
	}
}
 
Example 4
Source File: ExprBookTitle.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	ItemStack itemStack = getExpr().getSingle(e).getRandom();
	if (itemStack == null || !book.isOfType(itemStack))
		return;
	BookMeta bookMeta = (BookMeta) itemStack.getItemMeta();
	switch (mode){
		case SET:
			bookMeta.setTitle(delta == null ? "" : (String) delta[0]);
			break;
		case RESET:
		case DELETE:
			bookMeta.setTitle("");
			break;
			//$CASES-OMITTED$
		default:
			assert false;
	}
	itemStack.setItemMeta(bookMeta);
}
 
Example 5
Source File: ExprChatFormat.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	if (delta == null){
		return;
	}
	String format = null;
	if (mode == Changer.ChangeMode.SET){
		String newFormat = (String) delta[0];
		if (newFormat == null){
			return;
		}
		format = convertToNormal(newFormat);
	}else if (mode == Changer.ChangeMode.RESET){
		format = "<%s> %s";
	}
	if (format == null){
		return;
	}
	((AsyncPlayerChatEvent) e).setFormat(format);
}
 
Example 6
Source File: ExprMetadata.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET)
		return CollectionUtils.array(Object.class);
	return null;
}
 
Example 7
Source File: ExprAI.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) {
	if (delta == null || delta[0] == null) {
		return;
	}
	boolean value = (Boolean) delta[0];
	for (LivingEntity entity : getExpr().getArray(event)) {
		entity.setAI(value);
	}
}
 
Example 8
Source File: ExprBookAuthor.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.DELETE)
		return CollectionUtils.array(String.class);
	return null;
}
 
Example 9
Source File: ExprPlayerlistHeaderFooter.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	switch (mode) {
		case SET:
		case DELETE:
		case RESET:
			return CollectionUtils.array(String.class);
	}
	return null;
}
 
Example 10
Source File: ExprFlightMode.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) {
	boolean state = mode != Changer.ChangeMode.RESET && delta != null && (boolean) delta[0];
	for (Player player : getExpr().getArray(event)) {
		player.setAllowFlight(state);
	}
}
 
Example 11
Source File: ExprHotbarSlot.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	assert delta != null;
	Slot slot = (Slot) delta[0];
	if (!(slot instanceof InventorySlot))
		return; // Only inventory slots can be hotbar slots
	
	int index = ((InventorySlot) slot).getIndex();
	if (index > 8) // Only slots in hotbar can be current hotbar slot
		return;
	
	for (Player p : getExpr().getArray(e)) {
		p.getInventory().setHeldItemSlot(index);
	}
}
 
Example 12
Source File: ExprHotbarSlot.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.SET)
		return new Class[] {Slot.class};
	return null;
}
 
Example 13
Source File: SExprFileOwner.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final Changer.ChangeMode mode) {
  if (mode == Changer.ChangeMode.SET) {
    return CollectionUtils.array(String.class);
  }
  return null;
}
 
Example 14
Source File: ExprSpectatorTarget.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.SET
			|| mode == Changer.ChangeMode.RESET
			|| mode == Changer.ChangeMode.DELETE) {
		return CollectionUtils.array(Entity.class);
	}
	return null;
}
 
Example 15
Source File: ExprYamlComments.java    From skript-yaml with MIT License 5 votes vote down vote up
@Override
public Class<?>[] acceptChange(final Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.SET) {
		return CollectionUtils.array(Object[].class);	
	}
	return null;
}
 
Example 16
Source File: ExprBookTitle.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.DELETE){
		return new Class<?>[]{String.class};
	}
	return null;
}
 
Example 17
Source File: SExprYaml.java    From skUtilities with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
  File pth = new File(skUtilities.getDefaultPath(path.getSingle(e)));
  String ypth = ypath.getSingle(e);
  FileConfiguration con = YamlConfiguration.loadConfiguration(pth);
  try {
    if (mode == Changer.ChangeMode.DELETE) {
      con.set(ypth, null);
    } else {
      Object v = (delta[0] == null ? "" : delta[0]);
      switch (ty) {
        case 0: {
          if (mode == Changer.ChangeMode.SET) {
            con.set(ypth, delta[0]);
          }
          break;
        }
        case 1:
        case 2:
          if (mode == Changer.ChangeMode.ADD) {
            con.createSection(ypth);
          } else if (mode == Changer.ChangeMode.REMOVE) {
            con.set(ypth + "." + v, null);
          }
          break;
        case 3: {
          if (mode == Changer.ChangeMode.ADD) {
            List obj = con.getList(ypth);
            if (obj == null) {
              obj = new ArrayList<>();
              obj.add(delta[0]);
              con.set(ypth, obj);
            } else {
              obj.add(delta[0]);
            }
          } else if (mode == Changer.ChangeMode.REMOVE) {
            con.getList(ypth).remove(delta[0]);
          }
        }
      }
    }
  } finally {
    try {
      con.save(pth);
    } catch (IOException x) {
      skUtilities.prSysE("Failed to save: '" + pth + "'", getClass().getSimpleName(), x);
    }
  }
}
 
Example 18
Source File: ExprExhaustion.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	return CollectionUtils.array(Number.class);
}
 
Example 19
Source File: ExprRemainingAir.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	return (mode != ChangeMode.REMOVE_ALL) ? CollectionUtils.array(Timespan.class) : null;
}
 
Example 20
Source File: ExprAllLoadedYaml.java    From skript-yaml with MIT License 2 votes vote down vote up
@Override
public void change(Event event, Object[] delta, Changer.ChangeMode mode) {

}