-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.faulty.wpreplace; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Log4j2 | ||
@NoArgsConstructor(access = AccessLevel.NONE) | ||
public class EnvUtils { | ||
|
||
static String getEnvOrDefault(String variableName, String defaultValue) { | ||
String value = System.getProperty(variableName); | ||
return (value != null && !value.isEmpty()) ? value : defaultValue; | ||
} | ||
|
||
static int getEnvIntOrDefault(String variableName, int defaultValue) { | ||
String unitCountString = System.getProperty(variableName); | ||
try { | ||
return (unitCountString != null && !unitCountString.isEmpty()) ? Integer.parseInt(unitCountString) : defaultValue; | ||
} catch (NumberFormatException e) { | ||
log.warn("Error parsing {}. Using default value {}.", variableName, defaultValue); | ||
return defaultValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.faulty.wpreplace; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.io.IOUtils; | ||
import org.luaj.vm2.Globals; | ||
import org.luaj.vm2.LuaValue; | ||
import org.luaj.vm2.lib.jse.JsePlatform; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.zip.ZipInputStream; | ||
|
||
@NoArgsConstructor(access = AccessLevel.NONE) | ||
public class LuaReader { | ||
|
||
static LuaValue loadMissionFromEntry(ZipInputStream zipInputStream) throws IOException { | ||
String luaScript = IOUtils.toString(zipInputStream, Charset.defaultCharset()); | ||
luaScript += "\nreturn mission"; | ||
return loadMission(luaScript); | ||
} | ||
|
||
private static LuaValue loadMission(String luaScript) { | ||
Globals globals = JsePlatform.standardGlobals(); | ||
LuaValue chunk = globals.load(new ByteArrayInputStream(luaScript.getBytes()), "mission", "bt", globals); | ||
return chunk.checkfunction().call(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters