mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 12:32:29 +00:00
- Added interface to game, client and server - Added transformations - Made ingredient conditions more practical to use, no longer requires imports - Started implementation of event handling - Moved commands and logic to the common API code - Added common interface to MineTweaker recipes - Added string methods - Moved the logger from static value to static getter - Fixed crashes on dedicated servers - Fixed bracket resolution for <id:meta> values in 1.6.4 - Fixed scripts not being sent to multiplayer clients in 1.6.4
76 lines
2.0 KiB
Java
76 lines
2.0 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package minetweaker.expand;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import minetweaker.MineTweakerImplementationAPI;
|
|
import minetweaker.api.chat.IChatMessage;
|
|
import minetweaker.api.data.DataString;
|
|
import minetweaker.api.data.IData;
|
|
import stanhebben.zenscript.annotations.Optional;
|
|
import stanhebben.zenscript.annotations.ZenCaster;
|
|
import stanhebben.zenscript.annotations.ZenExpansion;
|
|
import stanhebben.zenscript.annotations.ZenMethod;
|
|
|
|
/**
|
|
*
|
|
* @author Stanneke
|
|
*/
|
|
@ZenExpansion("string")
|
|
public class ExpandString {
|
|
@ZenCaster
|
|
public static IData asData(String value) {
|
|
return new DataString(value);
|
|
}
|
|
|
|
@ZenCaster
|
|
public static IChatMessage asChatMessage(String value) {
|
|
return MineTweakerImplementationAPI.platform.getMessage(value);
|
|
}
|
|
|
|
@ZenMethod
|
|
public static List<String> split(String value, String separator, @Optional int maximum) {
|
|
List<String> result = new ArrayList<String>();
|
|
int minIndex = 0;
|
|
int numSplits = 0;
|
|
|
|
while (minIndex + separator.length() <= value.length()) {
|
|
int index = value.indexOf(separator, minIndex);
|
|
if (index < 0) break;
|
|
result.add(value.substring(minIndex, index));
|
|
minIndex = index + separator.length();
|
|
|
|
numSplits++;
|
|
if (maximum > 0 && numSplits >= maximum) break;
|
|
}
|
|
|
|
result.add(value.substring(minIndex));
|
|
return result;
|
|
}
|
|
|
|
@ZenMethod
|
|
public static int indexOf(String value, String needle) {
|
|
return value.indexOf(needle);
|
|
}
|
|
|
|
@ZenMethod
|
|
public static int indexOf(String value, String needle, int fromIndex) {
|
|
return value.indexOf(needle, fromIndex);
|
|
}
|
|
|
|
@ZenMethod
|
|
public static int lastIndexOf(String value, String needle) {
|
|
return value.lastIndexOf(needle);
|
|
}
|
|
|
|
@ZenMethod
|
|
public static int lastIndexOf(String value, String needle, int fromIndex) {
|
|
return value.lastIndexOf(value, fromIndex);
|
|
}
|
|
}
|