id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
23,000 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/marshalling/impl/ProcessInstanceResolverStrategy.java | ProcessInstanceResolverStrategy.connectProcessInstanceToRuntimeAndProcess | private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance,
Object streamContext) {
ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance;
InternalKnowledgeRuntime kruntime = processInstanceImpl.getKnowledgeRuntime();
// Attach the kruntime if not present
if ( kruntime == null ) {
kruntime = retrieveKnowledgeRuntime( streamContext );
processInstanceImpl.setKnowledgeRuntime( kruntime );
}
// Attach the process if not present
if ( processInstance.getProcess() == null ) {
String processId = processInstance.getProcessId();
if (processId != null) {
Process process = kruntime.getKieBase().getProcess( processId );
if (process != null) {
processInstanceImpl.setProcess( process );
}
}
}
} | java | private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance,
Object streamContext) {
ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance;
InternalKnowledgeRuntime kruntime = processInstanceImpl.getKnowledgeRuntime();
// Attach the kruntime if not present
if ( kruntime == null ) {
kruntime = retrieveKnowledgeRuntime( streamContext );
processInstanceImpl.setKnowledgeRuntime( kruntime );
}
// Attach the process if not present
if ( processInstance.getProcess() == null ) {
String processId = processInstance.getProcessId();
if (processId != null) {
Process process = kruntime.getKieBase().getProcess( processId );
if (process != null) {
processInstanceImpl.setProcess( process );
}
}
}
} | [
"private",
"void",
"connectProcessInstanceToRuntimeAndProcess",
"(",
"ProcessInstance",
"processInstance",
",",
"Object",
"streamContext",
")",
"{",
"ProcessInstanceImpl",
"processInstanceImpl",
"=",
"(",
"ProcessInstanceImpl",
")",
"processInstance",
";",
"InternalKnowledgeRuntime",
"kruntime",
"=",
"processInstanceImpl",
".",
"getKnowledgeRuntime",
"(",
")",
";",
"// Attach the kruntime if not present",
"if",
"(",
"kruntime",
"==",
"null",
")",
"{",
"kruntime",
"=",
"retrieveKnowledgeRuntime",
"(",
"streamContext",
")",
";",
"processInstanceImpl",
".",
"setKnowledgeRuntime",
"(",
"kruntime",
")",
";",
"}",
"// Attach the process if not present",
"if",
"(",
"processInstance",
".",
"getProcess",
"(",
")",
"==",
"null",
")",
"{",
"String",
"processId",
"=",
"processInstance",
".",
"getProcessId",
"(",
")",
";",
"if",
"(",
"processId",
"!=",
"null",
")",
"{",
"Process",
"process",
"=",
"kruntime",
".",
"getKieBase",
"(",
")",
".",
"getProcess",
"(",
"processId",
")",
";",
"if",
"(",
"process",
"!=",
"null",
")",
"{",
"processInstanceImpl",
".",
"setProcess",
"(",
"process",
")",
";",
"}",
"}",
"}",
"}"
] | Fill the process instance .kruntime and .process fields with the appropriate values.
@param processInstance
@param streamContext | [
"Fill",
"the",
"process",
"instance",
".",
"kruntime",
"and",
".",
"process",
"fields",
"with",
"the",
"appropriate",
"values",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/marshalling/impl/ProcessInstanceResolverStrategy.java#L117-L137 |
23,001 | kiegroup/jbpm | jbpm-audit/src/main/java/org/jbpm/process/audit/JPAWorkingMemoryDbLogger.java | JPAWorkingMemoryDbLogger.getEntityManager | private EntityManager getEntityManager(KieRuntimeEvent event) {
Environment env = event.getKieRuntime().getEnvironment();
/**
* It's important to set the sharedEM flag with _every_ operation
* otherwise, there are situations where:
* 1. it can be set to "true"
* 2. something can happen
* 3. the "true" value can no longer apply
* (I've seen this in debugging logs.. )
*/
sharedEM = false;
if( emf != null ) {
return emf.createEntityManager();
} else if (env != null) {
EntityManagerFactory emf = (EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
// first check active transaction if it contains entity manager
EntityManager em = getEntityManagerFromTransaction(env);
if (em != null && em.isOpen() && em.getEntityManagerFactory().equals(emf)) {
sharedEM = true;
return em;
}
// next check the environment itself
em = (EntityManager) env.get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);
if (em != null) {
sharedEM = true;
return em;
}
// lastly use entity manager factory
if (emf != null) {
return emf.createEntityManager();
}
}
throw new RuntimeException("Could not find or create a new EntityManager!");
} | java | private EntityManager getEntityManager(KieRuntimeEvent event) {
Environment env = event.getKieRuntime().getEnvironment();
/**
* It's important to set the sharedEM flag with _every_ operation
* otherwise, there are situations where:
* 1. it can be set to "true"
* 2. something can happen
* 3. the "true" value can no longer apply
* (I've seen this in debugging logs.. )
*/
sharedEM = false;
if( emf != null ) {
return emf.createEntityManager();
} else if (env != null) {
EntityManagerFactory emf = (EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
// first check active transaction if it contains entity manager
EntityManager em = getEntityManagerFromTransaction(env);
if (em != null && em.isOpen() && em.getEntityManagerFactory().equals(emf)) {
sharedEM = true;
return em;
}
// next check the environment itself
em = (EntityManager) env.get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);
if (em != null) {
sharedEM = true;
return em;
}
// lastly use entity manager factory
if (emf != null) {
return emf.createEntityManager();
}
}
throw new RuntimeException("Could not find or create a new EntityManager!");
} | [
"private",
"EntityManager",
"getEntityManager",
"(",
"KieRuntimeEvent",
"event",
")",
"{",
"Environment",
"env",
"=",
"event",
".",
"getKieRuntime",
"(",
")",
".",
"getEnvironment",
"(",
")",
";",
"/**\n * It's important to set the sharedEM flag with _every_ operation\n * otherwise, there are situations where:\n * 1. it can be set to \"true\"\n * 2. something can happen\n * 3. the \"true\" value can no longer apply \n * (I've seen this in debugging logs.. )\n */",
"sharedEM",
"=",
"false",
";",
"if",
"(",
"emf",
"!=",
"null",
")",
"{",
"return",
"emf",
".",
"createEntityManager",
"(",
")",
";",
"}",
"else",
"if",
"(",
"env",
"!=",
"null",
")",
"{",
"EntityManagerFactory",
"emf",
"=",
"(",
"EntityManagerFactory",
")",
"env",
".",
"get",
"(",
"EnvironmentName",
".",
"ENTITY_MANAGER_FACTORY",
")",
";",
"// first check active transaction if it contains entity manager",
"EntityManager",
"em",
"=",
"getEntityManagerFromTransaction",
"(",
"env",
")",
";",
"if",
"(",
"em",
"!=",
"null",
"&&",
"em",
".",
"isOpen",
"(",
")",
"&&",
"em",
".",
"getEntityManagerFactory",
"(",
")",
".",
"equals",
"(",
"emf",
")",
")",
"{",
"sharedEM",
"=",
"true",
";",
"return",
"em",
";",
"}",
"// next check the environment itself",
"em",
"=",
"(",
"EntityManager",
")",
"env",
".",
"get",
"(",
"EnvironmentName",
".",
"CMD_SCOPED_ENTITY_MANAGER",
")",
";",
"if",
"(",
"em",
"!=",
"null",
")",
"{",
"sharedEM",
"=",
"true",
";",
"return",
"em",
";",
"}",
"// lastly use entity manager factory",
"if",
"(",
"emf",
"!=",
"null",
")",
"{",
"return",
"emf",
".",
"createEntityManager",
"(",
")",
";",
"}",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not find or create a new EntityManager!\"",
")",
";",
"}"
] | This method creates a entity manager. | [
"This",
"method",
"creates",
"a",
"entity",
"manager",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-audit/src/main/java/org/jbpm/process/audit/JPAWorkingMemoryDbLogger.java#L254-L291 |
23,002 | kiegroup/jbpm | jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/SingletonRuntimeManager.java | SingletonRuntimeManager.getPersistedSessionId | protected Long getPersistedSessionId(String location, String identifier) {
File sessionIdStore = new File(location + File.separator + identifier+ "-jbpmSessionId.ser");
if (sessionIdStore.exists()) {
Long knownSessionId = null;
FileInputStream fis = null;
ObjectInputStream in = null;
try {
fis = new FileInputStream(sessionIdStore);
in = new ObjectInputStream(fis);
Object tmp = in.readObject();
if (tmp instanceof Integer) {
tmp = new Long((Integer) tmp);
}
knownSessionId = (Long) tmp;
return knownSessionId.longValue();
} catch (Exception e) {
return 0L;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
} else {
return 0L;
}
} | java | protected Long getPersistedSessionId(String location, String identifier) {
File sessionIdStore = new File(location + File.separator + identifier+ "-jbpmSessionId.ser");
if (sessionIdStore.exists()) {
Long knownSessionId = null;
FileInputStream fis = null;
ObjectInputStream in = null;
try {
fis = new FileInputStream(sessionIdStore);
in = new ObjectInputStream(fis);
Object tmp = in.readObject();
if (tmp instanceof Integer) {
tmp = new Long((Integer) tmp);
}
knownSessionId = (Long) tmp;
return knownSessionId.longValue();
} catch (Exception e) {
return 0L;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
} else {
return 0L;
}
} | [
"protected",
"Long",
"getPersistedSessionId",
"(",
"String",
"location",
",",
"String",
"identifier",
")",
"{",
"File",
"sessionIdStore",
"=",
"new",
"File",
"(",
"location",
"+",
"File",
".",
"separator",
"+",
"identifier",
"+",
"\"-jbpmSessionId.ser\"",
")",
";",
"if",
"(",
"sessionIdStore",
".",
"exists",
"(",
")",
")",
"{",
"Long",
"knownSessionId",
"=",
"null",
";",
"FileInputStream",
"fis",
"=",
"null",
";",
"ObjectInputStream",
"in",
"=",
"null",
";",
"try",
"{",
"fis",
"=",
"new",
"FileInputStream",
"(",
"sessionIdStore",
")",
";",
"in",
"=",
"new",
"ObjectInputStream",
"(",
"fis",
")",
";",
"Object",
"tmp",
"=",
"in",
".",
"readObject",
"(",
")",
";",
"if",
"(",
"tmp",
"instanceof",
"Integer",
")",
"{",
"tmp",
"=",
"new",
"Long",
"(",
"(",
"Integer",
")",
"tmp",
")",
";",
"}",
"knownSessionId",
"=",
"(",
"Long",
")",
"tmp",
";",
"return",
"knownSessionId",
".",
"longValue",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"return",
"0L",
";",
"}",
"finally",
"{",
"if",
"(",
"in",
"!=",
"null",
")",
"{",
"try",
"{",
"in",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"fis",
"!=",
"null",
")",
"{",
"try",
"{",
"fis",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"}",
"}",
"}",
"else",
"{",
"return",
"0L",
";",
"}",
"}"
] | Retrieves session id from serialized file named jbpmSessionId.ser from given location.
@param location directory where jbpmSessionId.ser file should be
@param identifier of the manager owning this ksessionId
@return sessionId if file was found otherwise 0 | [
"Retrieves",
"session",
"id",
"from",
"serialized",
"file",
"named",
"jbpmSessionId",
".",
"ser",
"from",
"given",
"location",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/SingletonRuntimeManager.java#L246-L285 |
23,003 | kiegroup/jbpm | jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/SingletonRuntimeManager.java | SingletonRuntimeManager.persistSessionId | protected void persistSessionId(String location, String identifier, Long ksessionId) {
if (location == null) {
return;
}
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(location + File.separator + identifier + "-jbpmSessionId.ser");
out = new ObjectOutputStream(fos);
out.writeObject(Long.valueOf(ksessionId));
out.close();
} catch (IOException ex) {
// logger.warn("Error when persisting known session id", ex);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
} | java | protected void persistSessionId(String location, String identifier, Long ksessionId) {
if (location == null) {
return;
}
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(location + File.separator + identifier + "-jbpmSessionId.ser");
out = new ObjectOutputStream(fos);
out.writeObject(Long.valueOf(ksessionId));
out.close();
} catch (IOException ex) {
// logger.warn("Error when persisting known session id", ex);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
} | [
"protected",
"void",
"persistSessionId",
"(",
"String",
"location",
",",
"String",
"identifier",
",",
"Long",
"ksessionId",
")",
"{",
"if",
"(",
"location",
"==",
"null",
")",
"{",
"return",
";",
"}",
"FileOutputStream",
"fos",
"=",
"null",
";",
"ObjectOutputStream",
"out",
"=",
"null",
";",
"try",
"{",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"location",
"+",
"File",
".",
"separator",
"+",
"identifier",
"+",
"\"-jbpmSessionId.ser\"",
")",
";",
"out",
"=",
"new",
"ObjectOutputStream",
"(",
"fos",
")",
";",
"out",
".",
"writeObject",
"(",
"Long",
".",
"valueOf",
"(",
"ksessionId",
")",
")",
";",
"out",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"// logger.warn(\"Error when persisting known session id\", ex);",
"}",
"finally",
"{",
"if",
"(",
"fos",
"!=",
"null",
")",
"{",
"try",
"{",
"fos",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"out",
"!=",
"null",
")",
"{",
"try",
"{",
"out",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"}",
"}",
"}"
] | Stores gives ksessionId in a serialized file in given location under jbpmSessionId.ser file name
@param location directory where serialized file should be stored
@param identifier of the manager owning this ksessionId
@param ksessionId value of ksessionId to be stored | [
"Stores",
"gives",
"ksessionId",
"in",
"a",
"serialized",
"file",
"in",
"given",
"location",
"under",
"jbpmSessionId",
".",
"ser",
"file",
"name"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/SingletonRuntimeManager.java#L293-L320 |
23,004 | kiegroup/jbpm | jbpm-document/src/main/java/org/jbpm/document/service/impl/DocumentStorageServiceImpl.java | DocumentStorageServiceImpl.generateUniquePath | protected String generateUniquePath() {
File parent;
String destinationPath;
do {
destinationPath = UUID.randomUUID().toString();
parent = getFileByPath(destinationPath);
} while (parent.exists());
return destinationPath;
} | java | protected String generateUniquePath() {
File parent;
String destinationPath;
do {
destinationPath = UUID.randomUUID().toString();
parent = getFileByPath(destinationPath);
} while (parent.exists());
return destinationPath;
} | [
"protected",
"String",
"generateUniquePath",
"(",
")",
"{",
"File",
"parent",
";",
"String",
"destinationPath",
";",
"do",
"{",
"destinationPath",
"=",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
";",
"parent",
"=",
"getFileByPath",
"(",
"destinationPath",
")",
";",
"}",
"while",
"(",
"parent",
".",
"exists",
"(",
")",
")",
";",
"return",
"destinationPath",
";",
"}"
] | Generates a random path to store the file to avoid overwritting files with the same name
@return A String containging the path where the document is going to be stored. | [
"Generates",
"a",
"random",
"path",
"to",
"store",
"the",
"file",
"to",
"avoid",
"overwritting",
"files",
"with",
"the",
"same",
"name"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-document/src/main/java/org/jbpm/document/service/impl/DocumentStorageServiceImpl.java#L178-L188 |
23,005 | kiegroup/jbpm | jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java | StartEventHandler.readDataOutput | protected void readDataOutput(org.w3c.dom.Node xmlNode, StartNode startNode) {
String id = ((Element) xmlNode).getAttribute("id");
String outputName = ((Element) xmlNode).getAttribute("name");
dataOutputs.put(id, outputName);
} | java | protected void readDataOutput(org.w3c.dom.Node xmlNode, StartNode startNode) {
String id = ((Element) xmlNode).getAttribute("id");
String outputName = ((Element) xmlNode).getAttribute("name");
dataOutputs.put(id, outputName);
} | [
"protected",
"void",
"readDataOutput",
"(",
"org",
".",
"w3c",
".",
"dom",
".",
"Node",
"xmlNode",
",",
"StartNode",
"startNode",
")",
"{",
"String",
"id",
"=",
"(",
"(",
"Element",
")",
"xmlNode",
")",
".",
"getAttribute",
"(",
"\"id\"",
")",
";",
"String",
"outputName",
"=",
"(",
"(",
"Element",
")",
"xmlNode",
")",
".",
"getAttribute",
"(",
"\"name\"",
")",
";",
"dataOutputs",
".",
"put",
"(",
"id",
",",
"outputName",
")",
";",
"}"
] | The results of this method are only used to check syntax | [
"The",
"results",
"of",
"this",
"method",
"are",
"only",
"used",
"to",
"check",
"syntax"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java#L242-L246 |
23,006 | kiegroup/jbpm | jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/ClassCacheManager.java | ClassCacheManager.findCommand | public Command findCommand(String name, ClassLoader cl) {
synchronized (commandCache) {
if (!commandCache.containsKey(name)) {
try {
Command commandInstance = (Command) Class.forName(name, true, cl).newInstance();
commandCache.put(name, commandInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
} else {
Command cmd = commandCache.get(name);
if (!cmd.getClass().getClassLoader().equals(cl)) {
commandCache.remove(name);
try {
Command commandInstance = (Command) Class.forName(name, true, cl).newInstance();
commandCache.put(name, commandInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
}
}
}
return commandCache.get(name);
} | java | public Command findCommand(String name, ClassLoader cl) {
synchronized (commandCache) {
if (!commandCache.containsKey(name)) {
try {
Command commandInstance = (Command) Class.forName(name, true, cl).newInstance();
commandCache.put(name, commandInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
} else {
Command cmd = commandCache.get(name);
if (!cmd.getClass().getClassLoader().equals(cl)) {
commandCache.remove(name);
try {
Command commandInstance = (Command) Class.forName(name, true, cl).newInstance();
commandCache.put(name, commandInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
}
}
}
return commandCache.get(name);
} | [
"public",
"Command",
"findCommand",
"(",
"String",
"name",
",",
"ClassLoader",
"cl",
")",
"{",
"synchronized",
"(",
"commandCache",
")",
"{",
"if",
"(",
"!",
"commandCache",
".",
"containsKey",
"(",
"name",
")",
")",
"{",
"try",
"{",
"Command",
"commandInstance",
"=",
"(",
"Command",
")",
"Class",
".",
"forName",
"(",
"name",
",",
"true",
",",
"cl",
")",
".",
"newInstance",
"(",
")",
";",
"commandCache",
".",
"put",
"(",
"name",
",",
"commandInstance",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown Command implementation with name '\"",
"+",
"name",
"+",
"\"'\"",
")",
";",
"}",
"}",
"else",
"{",
"Command",
"cmd",
"=",
"commandCache",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"!",
"cmd",
".",
"getClass",
"(",
")",
".",
"getClassLoader",
"(",
")",
".",
"equals",
"(",
"cl",
")",
")",
"{",
"commandCache",
".",
"remove",
"(",
"name",
")",
";",
"try",
"{",
"Command",
"commandInstance",
"=",
"(",
"Command",
")",
"Class",
".",
"forName",
"(",
"name",
",",
"true",
",",
"cl",
")",
".",
"newInstance",
"(",
")",
";",
"commandCache",
".",
"put",
"(",
"name",
",",
"commandInstance",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown Command implementation with name '\"",
"+",
"name",
"+",
"\"'\"",
")",
";",
"}",
"}",
"}",
"}",
"return",
"commandCache",
".",
"get",
"(",
"name",
")",
";",
"}"
] | Finds command by FQCN and if not found loads the class and store the instance in
the cache.
@param name - fully qualified class name of the command
@return initialized class instance | [
"Finds",
"command",
"by",
"FQCN",
"and",
"if",
"not",
"found",
"loads",
"the",
"class",
"and",
"store",
"the",
"instance",
"in",
"the",
"cache",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/ClassCacheManager.java#L51-L79 |
23,007 | kiegroup/jbpm | jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/ClassCacheManager.java | ClassCacheManager.findCommandCallback | public CommandCallback findCommandCallback(String name, ClassLoader cl) {
synchronized (callbackCache) {
if (!callbackCache.containsKey(name)) {
try {
CommandCallback commandCallbackInstance = (CommandCallback) Class.forName(name, true, cl).newInstance();
return commandCallbackInstance;
// callbackCache.put(name, commandCallbackInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
} else {
CommandCallback cmdCallback = callbackCache.get(name);
if (!cmdCallback.getClass().getClassLoader().equals(cl)) {
callbackCache.remove(name);
try {
CommandCallback commandCallbackInstance = (CommandCallback) Class.forName(name, true, cl).newInstance();
callbackCache.put(name, commandCallbackInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
}
}
}
return callbackCache.get(name);
} | java | public CommandCallback findCommandCallback(String name, ClassLoader cl) {
synchronized (callbackCache) {
if (!callbackCache.containsKey(name)) {
try {
CommandCallback commandCallbackInstance = (CommandCallback) Class.forName(name, true, cl).newInstance();
return commandCallbackInstance;
// callbackCache.put(name, commandCallbackInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
} else {
CommandCallback cmdCallback = callbackCache.get(name);
if (!cmdCallback.getClass().getClassLoader().equals(cl)) {
callbackCache.remove(name);
try {
CommandCallback commandCallbackInstance = (CommandCallback) Class.forName(name, true, cl).newInstance();
callbackCache.put(name, commandCallbackInstance);
} catch (Exception ex) {
throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
}
}
}
}
return callbackCache.get(name);
} | [
"public",
"CommandCallback",
"findCommandCallback",
"(",
"String",
"name",
",",
"ClassLoader",
"cl",
")",
"{",
"synchronized",
"(",
"callbackCache",
")",
"{",
"if",
"(",
"!",
"callbackCache",
".",
"containsKey",
"(",
"name",
")",
")",
"{",
"try",
"{",
"CommandCallback",
"commandCallbackInstance",
"=",
"(",
"CommandCallback",
")",
"Class",
".",
"forName",
"(",
"name",
",",
"true",
",",
"cl",
")",
".",
"newInstance",
"(",
")",
";",
"return",
"commandCallbackInstance",
";",
"// callbackCache.put(name, commandCallbackInstance);",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown Command implementation with name '\"",
"+",
"name",
"+",
"\"'\"",
")",
";",
"}",
"}",
"else",
"{",
"CommandCallback",
"cmdCallback",
"=",
"callbackCache",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"!",
"cmdCallback",
".",
"getClass",
"(",
")",
".",
"getClassLoader",
"(",
")",
".",
"equals",
"(",
"cl",
")",
")",
"{",
"callbackCache",
".",
"remove",
"(",
"name",
")",
";",
"try",
"{",
"CommandCallback",
"commandCallbackInstance",
"=",
"(",
"CommandCallback",
")",
"Class",
".",
"forName",
"(",
"name",
",",
"true",
",",
"cl",
")",
".",
"newInstance",
"(",
")",
";",
"callbackCache",
".",
"put",
"(",
"name",
",",
"commandCallbackInstance",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown Command implementation with name '\"",
"+",
"name",
"+",
"\"'\"",
")",
";",
"}",
"}",
"}",
"}",
"return",
"callbackCache",
".",
"get",
"(",
"name",
")",
";",
"}"
] | Finds command callback by FQCN and if not found loads the class and store the instance in
the cache.
@param name - fully qualified class name of the command callback
@return initialized class instance | [
"Finds",
"command",
"callback",
"by",
"FQCN",
"and",
"if",
"not",
"found",
"loads",
"the",
"class",
"and",
"store",
"the",
"instance",
"in",
"the",
"cache",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/ClassCacheManager.java#L87-L114 |
23,008 | kiegroup/jbpm | jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/ClassCacheManager.java | ClassCacheManager.buildCommandCallback | public List<CommandCallback> buildCommandCallback(CommandContext ctx, ClassLoader cl) {
List<CommandCallback> callbackList = new ArrayList<CommandCallback>();
if (ctx != null && ctx.getData("callbacks") != null) {
logger.debug("Callback: {}", ctx.getData("callbacks"));
String[] callbacksArray = ((String) ctx.getData("callbacks")).split(",");
List<String> callbacks = (List<String>) Arrays.asList(callbacksArray);
for (String callbackName : callbacks) {
CommandCallback handler = findCommandCallback(callbackName.trim(), cl);
callbackList.add(handler);
}
}
return callbackList;
} | java | public List<CommandCallback> buildCommandCallback(CommandContext ctx, ClassLoader cl) {
List<CommandCallback> callbackList = new ArrayList<CommandCallback>();
if (ctx != null && ctx.getData("callbacks") != null) {
logger.debug("Callback: {}", ctx.getData("callbacks"));
String[] callbacksArray = ((String) ctx.getData("callbacks")).split(",");
List<String> callbacks = (List<String>) Arrays.asList(callbacksArray);
for (String callbackName : callbacks) {
CommandCallback handler = findCommandCallback(callbackName.trim(), cl);
callbackList.add(handler);
}
}
return callbackList;
} | [
"public",
"List",
"<",
"CommandCallback",
">",
"buildCommandCallback",
"(",
"CommandContext",
"ctx",
",",
"ClassLoader",
"cl",
")",
"{",
"List",
"<",
"CommandCallback",
">",
"callbackList",
"=",
"new",
"ArrayList",
"<",
"CommandCallback",
">",
"(",
")",
";",
"if",
"(",
"ctx",
"!=",
"null",
"&&",
"ctx",
".",
"getData",
"(",
"\"callbacks\"",
")",
"!=",
"null",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Callback: {}\"",
",",
"ctx",
".",
"getData",
"(",
"\"callbacks\"",
")",
")",
";",
"String",
"[",
"]",
"callbacksArray",
"=",
"(",
"(",
"String",
")",
"ctx",
".",
"getData",
"(",
"\"callbacks\"",
")",
")",
".",
"split",
"(",
"\",\"",
")",
";",
"List",
"<",
"String",
">",
"callbacks",
"=",
"(",
"List",
"<",
"String",
">",
")",
"Arrays",
".",
"asList",
"(",
"callbacksArray",
")",
";",
"for",
"(",
"String",
"callbackName",
":",
"callbacks",
")",
"{",
"CommandCallback",
"handler",
"=",
"findCommandCallback",
"(",
"callbackName",
".",
"trim",
"(",
")",
",",
"cl",
")",
";",
"callbackList",
".",
"add",
"(",
"handler",
")",
";",
"}",
"}",
"return",
"callbackList",
";",
"}"
] | Builds completely initialized list of callbacks for given context.
@param ctx contextual data given by execution service
@return | [
"Builds",
"completely",
"initialized",
"list",
"of",
"callbacks",
"for",
"given",
"context",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/impl/ClassCacheManager.java#L121-L133 |
23,009 | kiegroup/jbpm | jbpm-query-jpa/src/main/java/org/jbpm/query/jpa/data/QueryWhere.java | QueryWhere.clear | public void clear() {
this.union = true;
this.type = QueryCriteriaType.NORMAL;
this.ancestry.clear();
if( this.criteria != null ) {
this.criteria.clear();
}
this.currentCriteria = this.criteria;
this.maxResults = null;
this.offset = null;
this.orderByListId = null;
this.ascOrDesc = null;
this.joinPredicates = null;
} | java | public void clear() {
this.union = true;
this.type = QueryCriteriaType.NORMAL;
this.ancestry.clear();
if( this.criteria != null ) {
this.criteria.clear();
}
this.currentCriteria = this.criteria;
this.maxResults = null;
this.offset = null;
this.orderByListId = null;
this.ascOrDesc = null;
this.joinPredicates = null;
} | [
"public",
"void",
"clear",
"(",
")",
"{",
"this",
".",
"union",
"=",
"true",
";",
"this",
".",
"type",
"=",
"QueryCriteriaType",
".",
"NORMAL",
";",
"this",
".",
"ancestry",
".",
"clear",
"(",
")",
";",
"if",
"(",
"this",
".",
"criteria",
"!=",
"null",
")",
"{",
"this",
".",
"criteria",
".",
"clear",
"(",
")",
";",
"}",
"this",
".",
"currentCriteria",
"=",
"this",
".",
"criteria",
";",
"this",
".",
"maxResults",
"=",
"null",
";",
"this",
".",
"offset",
"=",
"null",
";",
"this",
".",
"orderByListId",
"=",
"null",
";",
"this",
".",
"ascOrDesc",
"=",
"null",
";",
"this",
".",
"joinPredicates",
"=",
"null",
";",
"}"
] | clear & clone | [
"clear",
"&",
"clone"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-query-jpa/src/main/java/org/jbpm/query/jpa/data/QueryWhere.java#L312-L327 |
23,010 | kiegroup/jbpm | jbpm-audit/src/main/java/org/jbpm/process/audit/query/AbstractAuditDeleteBuilderImpl.java | AbstractAuditDeleteBuilderImpl.date | @SuppressWarnings("unchecked")
public T date( Date... date ) {
if (checkIfNull(date)) {
return (T) this;
}
date = ensureDateNotTimestamp(date);
addObjectParameter(DATE_LIST, "date", date);
return (T) this;
} | java | @SuppressWarnings("unchecked")
public T date( Date... date ) {
if (checkIfNull(date)) {
return (T) this;
}
date = ensureDateNotTimestamp(date);
addObjectParameter(DATE_LIST, "date", date);
return (T) this;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"T",
"date",
"(",
"Date",
"...",
"date",
")",
"{",
"if",
"(",
"checkIfNull",
"(",
"date",
")",
")",
"{",
"return",
"(",
"T",
")",
"this",
";",
"}",
"date",
"=",
"ensureDateNotTimestamp",
"(",
"date",
")",
";",
"addObjectParameter",
"(",
"DATE_LIST",
",",
"\"date\"",
",",
"date",
")",
";",
"return",
"(",
"T",
")",
"this",
";",
"}"
] | query builder methods | [
"query",
"builder",
"methods"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-audit/src/main/java/org/jbpm/process/audit/query/AbstractAuditDeleteBuilderImpl.java#L74-L82 |
23,011 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/services/task/assignment/AssignmentServiceProvider.java | AssignmentServiceProvider.override | static AssignmentService override(AssignmentStrategy strategy) {
Holder.INSTANCE.setAssignmentService(new AssignmentServiceImpl(strategy));
return get();
} | java | static AssignmentService override(AssignmentStrategy strategy) {
Holder.INSTANCE.setAssignmentService(new AssignmentServiceImpl(strategy));
return get();
} | [
"static",
"AssignmentService",
"override",
"(",
"AssignmentStrategy",
"strategy",
")",
"{",
"Holder",
".",
"INSTANCE",
".",
"setAssignmentService",
"(",
"new",
"AssignmentServiceImpl",
"(",
"strategy",
")",
")",
";",
"return",
"get",
"(",
")",
";",
"}"
] | for test purpose | [
"for",
"test",
"purpose"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/services/task/assignment/AssignmentServiceProvider.java#L48-L52 |
23,012 | kiegroup/jbpm | jbpm-case-mgmt/jbpm-case-mgmt-impl/src/main/java/org/jbpm/casemgmt/impl/marshalling/CaseMarshallerFactory.java | CaseMarshallerFactory.withJpa | public CaseMarshallerFactory withJpa(String puName) {
marshallers.add(new JPAPlaceholderResolverStrategy(puName, classLoader));
this.toString.append(".withJpa(\"" + puName + "\")");
return this;
} | java | public CaseMarshallerFactory withJpa(String puName) {
marshallers.add(new JPAPlaceholderResolverStrategy(puName, classLoader));
this.toString.append(".withJpa(\"" + puName + "\")");
return this;
} | [
"public",
"CaseMarshallerFactory",
"withJpa",
"(",
"String",
"puName",
")",
"{",
"marshallers",
".",
"add",
"(",
"new",
"JPAPlaceholderResolverStrategy",
"(",
"puName",
",",
"classLoader",
")",
")",
";",
"this",
".",
"toString",
".",
"append",
"(",
"\".withJpa(\\\"\"",
"+",
"puName",
"+",
"\"\\\")\"",
")",
";",
"return",
"this",
";",
"}"
] | Add JPA marshalling strategy to be used by CaseFileMarshaller
@param puName persistence unit name to be used
@return this factory instance | [
"Add",
"JPA",
"marshalling",
"strategy",
"to",
"be",
"used",
"by",
"CaseFileMarshaller"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-case-mgmt/jbpm-case-mgmt-impl/src/main/java/org/jbpm/casemgmt/impl/marshalling/CaseMarshallerFactory.java#L64-L68 |
23,013 | kiegroup/jbpm | jbpm-case-mgmt/jbpm-case-mgmt-impl/src/main/java/org/jbpm/casemgmt/impl/marshalling/CaseMarshallerFactory.java | CaseMarshallerFactory.with | public CaseMarshallerFactory with(ObjectMarshallingStrategy custom) {
marshallers.add(custom);
this.toString.append(".with(new " + custom.getClass().getName() + "())");
return this;
} | java | public CaseMarshallerFactory with(ObjectMarshallingStrategy custom) {
marshallers.add(custom);
this.toString.append(".with(new " + custom.getClass().getName() + "())");
return this;
} | [
"public",
"CaseMarshallerFactory",
"with",
"(",
"ObjectMarshallingStrategy",
"custom",
")",
"{",
"marshallers",
".",
"add",
"(",
"custom",
")",
";",
"this",
".",
"toString",
".",
"append",
"(",
"\".with(new \"",
"+",
"custom",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
"+",
"\"())\"",
")",
";",
"return",
"this",
";",
"}"
] | Adds given custom marshalling strategy to be used by CaseFileMarshaller
@param custom any marshalling strategy fully configured
@return this factory instance | [
"Adds",
"given",
"custom",
"marshalling",
"strategy",
"to",
"be",
"used",
"by",
"CaseFileMarshaller"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-case-mgmt/jbpm-case-mgmt-impl/src/main/java/org/jbpm/casemgmt/impl/marshalling/CaseMarshallerFactory.java#L75-L79 |
23,014 | kiegroup/jbpm | jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/commands/error/AutoAckErrorCommand.java | AutoAckErrorCommand.getScheduleTime | @Override
public Date getScheduleTime() {
if (nextScheduleTimeAdd < 0) {
return null;
}
long current = System.currentTimeMillis();
Date nextSchedule = new Date(current + nextScheduleTimeAdd);
logger.debug("Next schedule for job {} is set to {}", this.getClass().getSimpleName(), nextSchedule);
return nextSchedule;
} | java | @Override
public Date getScheduleTime() {
if (nextScheduleTimeAdd < 0) {
return null;
}
long current = System.currentTimeMillis();
Date nextSchedule = new Date(current + nextScheduleTimeAdd);
logger.debug("Next schedule for job {} is set to {}", this.getClass().getSimpleName(), nextSchedule);
return nextSchedule;
} | [
"@",
"Override",
"public",
"Date",
"getScheduleTime",
"(",
")",
"{",
"if",
"(",
"nextScheduleTimeAdd",
"<",
"0",
")",
"{",
"return",
"null",
";",
"}",
"long",
"current",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"Date",
"nextSchedule",
"=",
"new",
"Date",
"(",
"current",
"+",
"nextScheduleTimeAdd",
")",
";",
"logger",
".",
"debug",
"(",
"\"Next schedule for job {} is set to {}\"",
",",
"this",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
",",
"nextSchedule",
")",
";",
"return",
"nextSchedule",
";",
"}"
] | one day in milliseconds | [
"one",
"day",
"in",
"milliseconds"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-executor/src/main/java/org/jbpm/executor/commands/error/AutoAckErrorCommand.java#L45-L57 |
23,015 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/services/task/utils/LdapSearcher.java | LdapSearcher.search | public LdapSearcher search(String context, String filterExpr, Object... filterArgs) {
searchResults.clear();
LdapContext ldapContext = null;
NamingEnumeration<SearchResult> ldapResult = null;
try {
ldapContext = buildLdapContext();
ldapResult = ldapContext.search(context, filterExpr, filterArgs, createSearchControls());
while (ldapResult.hasMore()) {
searchResults.add(ldapResult.next());
}
} catch (NamingException ex) {
throw new RuntimeException("LDAP search has failed", ex);
} finally {
if (ldapResult != null) {
try {
ldapResult.close();
} catch (NamingException ex) {
log.error("Failed to close LDAP results enumeration", ex);
}
}
if (ldapContext != null) {
try {
ldapContext.close();
} catch (NamingException ex) {
log.error("Failed to close LDAP context", ex);
}
}
}
return this;
} | java | public LdapSearcher search(String context, String filterExpr, Object... filterArgs) {
searchResults.clear();
LdapContext ldapContext = null;
NamingEnumeration<SearchResult> ldapResult = null;
try {
ldapContext = buildLdapContext();
ldapResult = ldapContext.search(context, filterExpr, filterArgs, createSearchControls());
while (ldapResult.hasMore()) {
searchResults.add(ldapResult.next());
}
} catch (NamingException ex) {
throw new RuntimeException("LDAP search has failed", ex);
} finally {
if (ldapResult != null) {
try {
ldapResult.close();
} catch (NamingException ex) {
log.error("Failed to close LDAP results enumeration", ex);
}
}
if (ldapContext != null) {
try {
ldapContext.close();
} catch (NamingException ex) {
log.error("Failed to close LDAP context", ex);
}
}
}
return this;
} | [
"public",
"LdapSearcher",
"search",
"(",
"String",
"context",
",",
"String",
"filterExpr",
",",
"Object",
"...",
"filterArgs",
")",
"{",
"searchResults",
".",
"clear",
"(",
")",
";",
"LdapContext",
"ldapContext",
"=",
"null",
";",
"NamingEnumeration",
"<",
"SearchResult",
">",
"ldapResult",
"=",
"null",
";",
"try",
"{",
"ldapContext",
"=",
"buildLdapContext",
"(",
")",
";",
"ldapResult",
"=",
"ldapContext",
".",
"search",
"(",
"context",
",",
"filterExpr",
",",
"filterArgs",
",",
"createSearchControls",
"(",
")",
")",
";",
"while",
"(",
"ldapResult",
".",
"hasMore",
"(",
")",
")",
"{",
"searchResults",
".",
"add",
"(",
"ldapResult",
".",
"next",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"NamingException",
"ex",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"LDAP search has failed\"",
",",
"ex",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"ldapResult",
"!=",
"null",
")",
"{",
"try",
"{",
"ldapResult",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"NamingException",
"ex",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to close LDAP results enumeration\"",
",",
"ex",
")",
";",
"}",
"}",
"if",
"(",
"ldapContext",
"!=",
"null",
")",
"{",
"try",
"{",
"ldapContext",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"NamingException",
"ex",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to close LDAP context\"",
",",
"ex",
")",
";",
"}",
"}",
"}",
"return",
"this",
";",
"}"
] | Search LDAP and stores the results in searchResults field.
@param context the name of the context where the search starts (the depth depends on ldap.search.scope)
@param filterExpr the filter expression to use for the search. The expression may contain variables of the form
"<code>{i}</code>" where <code>i</code> is a non-negative integer. May not be null.
@param filterArgs the array of arguments to substitute for the variables in <code>filterExpr</code>. The value of
<code>filterArgs[i]</code> will replace each occurrence of "<code>{i}</code>". If null, an equivalent of an empty
array is used.
@return this | [
"Search",
"LDAP",
"and",
"stores",
"the",
"results",
"in",
"searchResults",
"field",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-core/src/main/java/org/jbpm/services/task/utils/LdapSearcher.java#L69-L100 |
23,016 | kiegroup/jbpm | jbpm-query-jpa/src/main/java/org/jbpm/query/jpa/data/QueryCriteria.java | QueryCriteria.getParameters | public List<Object> getParameters() {
List<Object> parameters = new ArrayList<Object>(getValues());
if( this.dateValues != null && ! this.dateValues.isEmpty() ) {
parameters.addAll(this.dateValues);
}
if( parameters.isEmpty() ) {
return parameters;
}
return parameters;
} | java | public List<Object> getParameters() {
List<Object> parameters = new ArrayList<Object>(getValues());
if( this.dateValues != null && ! this.dateValues.isEmpty() ) {
parameters.addAll(this.dateValues);
}
if( parameters.isEmpty() ) {
return parameters;
}
return parameters;
} | [
"public",
"List",
"<",
"Object",
">",
"getParameters",
"(",
")",
"{",
"List",
"<",
"Object",
">",
"parameters",
"=",
"new",
"ArrayList",
"<",
"Object",
">",
"(",
"getValues",
"(",
")",
")",
";",
"if",
"(",
"this",
".",
"dateValues",
"!=",
"null",
"&&",
"!",
"this",
".",
"dateValues",
".",
"isEmpty",
"(",
")",
")",
"{",
"parameters",
".",
"addAll",
"(",
"this",
".",
"dateValues",
")",
";",
"}",
"if",
"(",
"parameters",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"parameters",
";",
"}",
"return",
"parameters",
";",
"}"
] | This method returns a list that should only be read
@return | [
"This",
"method",
"returns",
"a",
"list",
"that",
"should",
"only",
"be",
"read"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-query-jpa/src/main/java/org/jbpm/query/jpa/data/QueryCriteria.java#L219-L228 |
23,017 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/process/core/event/NonAcceptingEventTypeFilter.java | NonAcceptingEventTypeFilter.acceptsEvent | @Override
public boolean acceptsEvent(String type, Object event, Function<String, String> resolver) {
return false;
} | java | @Override
public boolean acceptsEvent(String type, Object event, Function<String, String> resolver) {
return false;
} | [
"@",
"Override",
"public",
"boolean",
"acceptsEvent",
"(",
"String",
"type",
",",
"Object",
"event",
",",
"Function",
"<",
"String",
",",
"String",
">",
"resolver",
")",
"{",
"return",
"false",
";",
"}"
] | Nodes that use this event filter should never be triggered by this event | [
"Nodes",
"that",
"use",
"this",
"event",
"filter",
"should",
"never",
"be",
"triggered",
"by",
"this",
"event"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/process/core/event/NonAcceptingEventTypeFilter.java#L37-L40 |
23,018 | kiegroup/jbpm | jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/service/ServiceRegistry.java | ServiceRegistry.service | public Object service(String name) {
Object service = this.services.get(name);
if (service == null) {
throw new IllegalArgumentException("Service '" + name + "' not found");
}
return service;
} | java | public Object service(String name) {
Object service = this.services.get(name);
if (service == null) {
throw new IllegalArgumentException("Service '" + name + "' not found");
}
return service;
} | [
"public",
"Object",
"service",
"(",
"String",
"name",
")",
"{",
"Object",
"service",
"=",
"this",
".",
"services",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"service",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Service '\"",
"+",
"name",
"+",
"\"' not found\"",
")",
";",
"}",
"return",
"service",
";",
"}"
] | Retrieves service registered under given name
@param name name of the service
@return instance of the service registered with given name
@throws IllegalArgumentException thrown in case service with given name is not registered | [
"Retrieves",
"service",
"registered",
"under",
"given",
"name"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/service/ServiceRegistry.java#L93-L99 |
23,019 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-audit/src/main/java/org/jbpm/services/task/audit/TaskAuditLoggerFactory.java | TaskAuditLoggerFactory.newJMSInstance | public static AsyncTaskLifeCycleEventProducer newJMSInstance(boolean transacted, ConnectionFactory connFactory, Queue queue) {
AsyncTaskLifeCycleEventProducer logger = new AsyncTaskLifeCycleEventProducer();
logger.setTransacted(transacted);
logger.setConnectionFactory(connFactory);
logger.setQueue(queue);
return logger;
} | java | public static AsyncTaskLifeCycleEventProducer newJMSInstance(boolean transacted, ConnectionFactory connFactory, Queue queue) {
AsyncTaskLifeCycleEventProducer logger = new AsyncTaskLifeCycleEventProducer();
logger.setTransacted(transacted);
logger.setConnectionFactory(connFactory);
logger.setQueue(queue);
return logger;
} | [
"public",
"static",
"AsyncTaskLifeCycleEventProducer",
"newJMSInstance",
"(",
"boolean",
"transacted",
",",
"ConnectionFactory",
"connFactory",
",",
"Queue",
"queue",
")",
"{",
"AsyncTaskLifeCycleEventProducer",
"logger",
"=",
"new",
"AsyncTaskLifeCycleEventProducer",
"(",
")",
";",
"logger",
".",
"setTransacted",
"(",
"transacted",
")",
";",
"logger",
".",
"setConnectionFactory",
"(",
"connFactory",
")",
";",
"logger",
".",
"setQueue",
"(",
"queue",
")",
";",
"return",
"logger",
";",
"}"
] | Creates new instance of JMS task audit logger based on given connection factory and queue.
@param transacted determines if JMS session is transacted or not
@param connFactory connection factory instance
@param queue JMS queue instance
@return new instance of JMS task audit logger | [
"Creates",
"new",
"instance",
"of",
"JMS",
"task",
"audit",
"logger",
"based",
"on",
"given",
"connection",
"factory",
"and",
"queue",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-audit/src/main/java/org/jbpm/services/task/audit/TaskAuditLoggerFactory.java#L109-L116 |
23,020 | kiegroup/jbpm | jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/SimpleRuntimeEnvironment.java | SimpleRuntimeEnvironment.addAsset | public void addAsset(Resource resource, ResourceType type) {
/**
* The code below (CSV/XLS) was added because of timelines related to switchyard/fuse.
*
* However, it is an ugly hack: As soon as is possible, the code below should be removed or refactored.
* - an "addAsset(Resource, ResourceType, ResourceConfiguration)" method should be added to this implementation
* - or the kbuilder code should be refactored so that there are two ResourceTypes: CSV and XLS
*
* (refactoring the kbuilder code is probably a better idea.)
*/
boolean replaced = false;
if (resource.getSourcePath() != null ) {
String path = resource.getSourcePath();
String typeStr = null;
if( path.toLowerCase().endsWith(".csv") ) {
typeStr = DecisionTableInputType.CSV.toString();
} else if( path.toLowerCase().endsWith(".xls") ) {
typeStr = DecisionTableInputType.XLS.toString();
}
if( typeStr != null ) {
String worksheetName = null;
boolean replaceConfig = true;
ResourceConfiguration config = resource.getConfiguration();
if( config != null && config instanceof DecisionTableConfiguration ) {
DecisionTableInputType realType = DecisionTableInputType.valueOf(typeStr);
if( ((DecisionTableConfiguration) config).getInputType().equals(realType) ) {
replaceConfig = false;
} else {
worksheetName = ((DecisionTableConfiguration) config).getWorksheetName();
}
}
if( replaceConfig ) {
Properties prop = new Properties();
prop.setProperty(ResourceTypeImpl.KIE_RESOURCE_CONF_CLASS, DecisionTableConfigurationImpl.class.getName());
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_TYPE, typeStr);
if( worksheetName != null ) {
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_WORKSHEET, worksheetName);
}
ResourceConfiguration conf = ResourceTypeImpl.fromProperties(prop);
this.kbuilder.add(resource, type, conf);
replaced = true;
}
}
}
if( ! replaced ) {
this.kbuilder.add(resource, type);
}
if (this.kbuilder.hasErrors()) {
StringBuffer errorMessage = new StringBuffer();
for( KnowledgeBuilderError error : kbuilder.getErrors()) {
errorMessage.append(error.getMessage() + ",");
}
this.kbuilder.undo();
throw new IllegalArgumentException("Cannot add asset: " + errorMessage.toString());
}
} | java | public void addAsset(Resource resource, ResourceType type) {
/**
* The code below (CSV/XLS) was added because of timelines related to switchyard/fuse.
*
* However, it is an ugly hack: As soon as is possible, the code below should be removed or refactored.
* - an "addAsset(Resource, ResourceType, ResourceConfiguration)" method should be added to this implementation
* - or the kbuilder code should be refactored so that there are two ResourceTypes: CSV and XLS
*
* (refactoring the kbuilder code is probably a better idea.)
*/
boolean replaced = false;
if (resource.getSourcePath() != null ) {
String path = resource.getSourcePath();
String typeStr = null;
if( path.toLowerCase().endsWith(".csv") ) {
typeStr = DecisionTableInputType.CSV.toString();
} else if( path.toLowerCase().endsWith(".xls") ) {
typeStr = DecisionTableInputType.XLS.toString();
}
if( typeStr != null ) {
String worksheetName = null;
boolean replaceConfig = true;
ResourceConfiguration config = resource.getConfiguration();
if( config != null && config instanceof DecisionTableConfiguration ) {
DecisionTableInputType realType = DecisionTableInputType.valueOf(typeStr);
if( ((DecisionTableConfiguration) config).getInputType().equals(realType) ) {
replaceConfig = false;
} else {
worksheetName = ((DecisionTableConfiguration) config).getWorksheetName();
}
}
if( replaceConfig ) {
Properties prop = new Properties();
prop.setProperty(ResourceTypeImpl.KIE_RESOURCE_CONF_CLASS, DecisionTableConfigurationImpl.class.getName());
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_TYPE, typeStr);
if( worksheetName != null ) {
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_WORKSHEET, worksheetName);
}
ResourceConfiguration conf = ResourceTypeImpl.fromProperties(prop);
this.kbuilder.add(resource, type, conf);
replaced = true;
}
}
}
if( ! replaced ) {
this.kbuilder.add(resource, type);
}
if (this.kbuilder.hasErrors()) {
StringBuffer errorMessage = new StringBuffer();
for( KnowledgeBuilderError error : kbuilder.getErrors()) {
errorMessage.append(error.getMessage() + ",");
}
this.kbuilder.undo();
throw new IllegalArgumentException("Cannot add asset: " + errorMessage.toString());
}
} | [
"public",
"void",
"addAsset",
"(",
"Resource",
"resource",
",",
"ResourceType",
"type",
")",
"{",
"/**\n * The code below (CSV/XLS) was added because of timelines related to switchyard/fuse.\n * \n * However, it is an ugly hack: As soon as is possible, the code below should be removed or refactored. \n * - an \"addAsset(Resource, ResourceType, ResourceConfiguration)\" method should be added to this implementation\n * - or the kbuilder code should be refactored so that there are two ResourceTypes: CSV and XLS\n * \n * (refactoring the kbuilder code is probably a better idea.)\n */",
"boolean",
"replaced",
"=",
"false",
";",
"if",
"(",
"resource",
".",
"getSourcePath",
"(",
")",
"!=",
"null",
")",
"{",
"String",
"path",
"=",
"resource",
".",
"getSourcePath",
"(",
")",
";",
"String",
"typeStr",
"=",
"null",
";",
"if",
"(",
"path",
".",
"toLowerCase",
"(",
")",
".",
"endsWith",
"(",
"\".csv\"",
")",
")",
"{",
"typeStr",
"=",
"DecisionTableInputType",
".",
"CSV",
".",
"toString",
"(",
")",
";",
"}",
"else",
"if",
"(",
"path",
".",
"toLowerCase",
"(",
")",
".",
"endsWith",
"(",
"\".xls\"",
")",
")",
"{",
"typeStr",
"=",
"DecisionTableInputType",
".",
"XLS",
".",
"toString",
"(",
")",
";",
"}",
"if",
"(",
"typeStr",
"!=",
"null",
")",
"{",
"String",
"worksheetName",
"=",
"null",
";",
"boolean",
"replaceConfig",
"=",
"true",
";",
"ResourceConfiguration",
"config",
"=",
"resource",
".",
"getConfiguration",
"(",
")",
";",
"if",
"(",
"config",
"!=",
"null",
"&&",
"config",
"instanceof",
"DecisionTableConfiguration",
")",
"{",
"DecisionTableInputType",
"realType",
"=",
"DecisionTableInputType",
".",
"valueOf",
"(",
"typeStr",
")",
";",
"if",
"(",
"(",
"(",
"DecisionTableConfiguration",
")",
"config",
")",
".",
"getInputType",
"(",
")",
".",
"equals",
"(",
"realType",
")",
")",
"{",
"replaceConfig",
"=",
"false",
";",
"}",
"else",
"{",
"worksheetName",
"=",
"(",
"(",
"DecisionTableConfiguration",
")",
"config",
")",
".",
"getWorksheetName",
"(",
")",
";",
"}",
"}",
"if",
"(",
"replaceConfig",
")",
"{",
"Properties",
"prop",
"=",
"new",
"Properties",
"(",
")",
";",
"prop",
".",
"setProperty",
"(",
"ResourceTypeImpl",
".",
"KIE_RESOURCE_CONF_CLASS",
",",
"DecisionTableConfigurationImpl",
".",
"class",
".",
"getName",
"(",
")",
")",
";",
"prop",
".",
"setProperty",
"(",
"DecisionTableConfigurationImpl",
".",
"DROOLS_DT_TYPE",
",",
"typeStr",
")",
";",
"if",
"(",
"worksheetName",
"!=",
"null",
")",
"{",
"prop",
".",
"setProperty",
"(",
"DecisionTableConfigurationImpl",
".",
"DROOLS_DT_WORKSHEET",
",",
"worksheetName",
")",
";",
"}",
"ResourceConfiguration",
"conf",
"=",
"ResourceTypeImpl",
".",
"fromProperties",
"(",
"prop",
")",
";",
"this",
".",
"kbuilder",
".",
"add",
"(",
"resource",
",",
"type",
",",
"conf",
")",
";",
"replaced",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"replaced",
")",
"{",
"this",
".",
"kbuilder",
".",
"add",
"(",
"resource",
",",
"type",
")",
";",
"}",
"if",
"(",
"this",
".",
"kbuilder",
".",
"hasErrors",
"(",
")",
")",
"{",
"StringBuffer",
"errorMessage",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"for",
"(",
"KnowledgeBuilderError",
"error",
":",
"kbuilder",
".",
"getErrors",
"(",
")",
")",
"{",
"errorMessage",
".",
"append",
"(",
"error",
".",
"getMessage",
"(",
")",
"+",
"\",\"",
")",
";",
"}",
"this",
".",
"kbuilder",
".",
"undo",
"(",
")",
";",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot add asset: \"",
"+",
"errorMessage",
".",
"toString",
"(",
")",
")",
";",
"}",
"}"
] | Adds given asset to knowledge builder to produce KieBase
@param resource asset to be added
@param type type of the asset | [
"Adds",
"given",
"asset",
"to",
"knowledge",
"builder",
"to",
"produce",
"KieBase"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/SimpleRuntimeEnvironment.java#L115-L175 |
23,021 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java | TaskDataImpl.addComment | public void addComment(Comment comment) {
if (comments == null || comments.size() == 0) {
comments = new ArrayList<Comment>();
}
comments.add((CommentImpl) comment);
} | java | public void addComment(Comment comment) {
if (comments == null || comments.size() == 0) {
comments = new ArrayList<Comment>();
}
comments.add((CommentImpl) comment);
} | [
"public",
"void",
"addComment",
"(",
"Comment",
"comment",
")",
"{",
"if",
"(",
"comments",
"==",
"null",
"||",
"comments",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"comments",
"=",
"new",
"ArrayList",
"<",
"Comment",
">",
"(",
")",
";",
"}",
"comments",
".",
"add",
"(",
"(",
"CommentImpl",
")",
"comment",
")",
";",
"}"
] | Adds the specified comment to our list of comments.
@param comment comment to add | [
"Adds",
"the",
"specified",
"comment",
"to",
"our",
"list",
"of",
"comments",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java#L653-L659 |
23,022 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java | TaskDataImpl.removeComment | public Comment removeComment(final long commentId) {
Comment removedComment = null;
if (comments != null) {
for (int index = comments.size() - 1; index >= 0; --index) {
Comment currentComment = comments.get(index);
if (currentComment.getId() == commentId) {
removedComment = comments.remove(index);
break;
}
}
}
return removedComment;
} | java | public Comment removeComment(final long commentId) {
Comment removedComment = null;
if (comments != null) {
for (int index = comments.size() - 1; index >= 0; --index) {
Comment currentComment = comments.get(index);
if (currentComment.getId() == commentId) {
removedComment = comments.remove(index);
break;
}
}
}
return removedComment;
} | [
"public",
"Comment",
"removeComment",
"(",
"final",
"long",
"commentId",
")",
"{",
"Comment",
"removedComment",
"=",
"null",
";",
"if",
"(",
"comments",
"!=",
"null",
")",
"{",
"for",
"(",
"int",
"index",
"=",
"comments",
".",
"size",
"(",
")",
"-",
"1",
";",
"index",
">=",
"0",
";",
"--",
"index",
")",
"{",
"Comment",
"currentComment",
"=",
"comments",
".",
"get",
"(",
"index",
")",
";",
"if",
"(",
"currentComment",
".",
"getId",
"(",
")",
"==",
"commentId",
")",
"{",
"removedComment",
"=",
"comments",
".",
"remove",
"(",
"index",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"removedComment",
";",
"}"
] | Removes the Comment specified by the commentId.
@param commentId id of Comment to remove
@return removed Comment or null if one was not found with the id | [
"Removes",
"the",
"Comment",
"specified",
"by",
"the",
"commentId",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java#L667-L682 |
23,023 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java | TaskDataImpl.addAttachment | public void addAttachment(Attachment attachment) {
if (attachments == null || attachments == Collections.<Attachment>emptyList()) {
attachments = new ArrayList<Attachment>();
}
attachments.add((AttachmentImpl) attachment);
} | java | public void addAttachment(Attachment attachment) {
if (attachments == null || attachments == Collections.<Attachment>emptyList()) {
attachments = new ArrayList<Attachment>();
}
attachments.add((AttachmentImpl) attachment);
} | [
"public",
"void",
"addAttachment",
"(",
"Attachment",
"attachment",
")",
"{",
"if",
"(",
"attachments",
"==",
"null",
"||",
"attachments",
"==",
"Collections",
".",
"<",
"Attachment",
">",
"emptyList",
"(",
")",
")",
"{",
"attachments",
"=",
"new",
"ArrayList",
"<",
"Attachment",
">",
"(",
")",
";",
"}",
"attachments",
".",
"add",
"(",
"(",
"AttachmentImpl",
")",
"attachment",
")",
";",
"}"
] | Adds the specified attachment to our list of Attachments.
@param attachment attachment to add | [
"Adds",
"the",
"specified",
"attachment",
"to",
"our",
"list",
"of",
"Attachments",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java#L697-L703 |
23,024 | kiegroup/jbpm | jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java | TaskDataImpl.removeAttachment | public Attachment removeAttachment(final long attachmentId) {
Attachment removedAttachment = null;
if (attachments != null) {
for (int index = attachments.size() - 1; index >= 0; --index) {
Attachment currentAttachment = attachments.get(index);
if (currentAttachment.getId() == attachmentId) {
removedAttachment = attachments.remove(index);
break;
}
}
}
return removedAttachment;
} | java | public Attachment removeAttachment(final long attachmentId) {
Attachment removedAttachment = null;
if (attachments != null) {
for (int index = attachments.size() - 1; index >= 0; --index) {
Attachment currentAttachment = attachments.get(index);
if (currentAttachment.getId() == attachmentId) {
removedAttachment = attachments.remove(index);
break;
}
}
}
return removedAttachment;
} | [
"public",
"Attachment",
"removeAttachment",
"(",
"final",
"long",
"attachmentId",
")",
"{",
"Attachment",
"removedAttachment",
"=",
"null",
";",
"if",
"(",
"attachments",
"!=",
"null",
")",
"{",
"for",
"(",
"int",
"index",
"=",
"attachments",
".",
"size",
"(",
")",
"-",
"1",
";",
"index",
">=",
"0",
";",
"--",
"index",
")",
"{",
"Attachment",
"currentAttachment",
"=",
"attachments",
".",
"get",
"(",
"index",
")",
";",
"if",
"(",
"currentAttachment",
".",
"getId",
"(",
")",
"==",
"attachmentId",
")",
"{",
"removedAttachment",
"=",
"attachments",
".",
"remove",
"(",
"index",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"removedAttachment",
";",
"}"
] | Removes the Attachment specified by the attachmentId.
@param attachmentId id of attachment to remove
@return removed Attachment or null if one was not found with the id | [
"Removes",
"the",
"Attachment",
"specified",
"by",
"the",
"attachmentId",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-human-task/jbpm-human-task-jpa/src/main/java/org/jbpm/services/task/impl/model/TaskDataImpl.java#L711-L726 |
23,025 | kiegroup/jbpm | jbpm-services/jbpm-services-ejb/jbpm-services-ejb-impl/src/main/java/org/jbpm/services/ejb/impl/DeploymentServiceEJBImpl.java | DeploymentServiceEJBImpl.setBpmn2Service | @EJB(beanInterface=DefinitionServiceEJBLocal.class)
@Override
public void setBpmn2Service(DefinitionService bpmn2Service) {
super.setBpmn2Service(bpmn2Service);
super.addListener((DeploymentEventListener) bpmn2Service);
} | java | @EJB(beanInterface=DefinitionServiceEJBLocal.class)
@Override
public void setBpmn2Service(DefinitionService bpmn2Service) {
super.setBpmn2Service(bpmn2Service);
super.addListener((DeploymentEventListener) bpmn2Service);
} | [
"@",
"EJB",
"(",
"beanInterface",
"=",
"DefinitionServiceEJBLocal",
".",
"class",
")",
"@",
"Override",
"public",
"void",
"setBpmn2Service",
"(",
"DefinitionService",
"bpmn2Service",
")",
"{",
"super",
".",
"setBpmn2Service",
"(",
"bpmn2Service",
")",
";",
"super",
".",
"addListener",
"(",
"(",
"DeploymentEventListener",
")",
"bpmn2Service",
")",
";",
"}"
] | inject ejb beans | [
"inject",
"ejb",
"beans"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-impl/src/main/java/org/jbpm/services/ejb/impl/DeploymentServiceEJBImpl.java#L105-L111 |
23,026 | kiegroup/jbpm | jbpm-case-mgmt/jbpm-case-mgmt-api/src/main/java/org/jbpm/casemgmt/api/admin/CaseMigrationReport.java | CaseMigrationReport.complete | public void complete() {
this.endDate = new Date();
if (reports.stream().allMatch(report -> report.isSuccessful() == true)) {
this.successful = true;
}
} | java | public void complete() {
this.endDate = new Date();
if (reports.stream().allMatch(report -> report.isSuccessful() == true)) {
this.successful = true;
}
} | [
"public",
"void",
"complete",
"(",
")",
"{",
"this",
".",
"endDate",
"=",
"new",
"Date",
"(",
")",
";",
"if",
"(",
"reports",
".",
"stream",
"(",
")",
".",
"allMatch",
"(",
"report",
"->",
"report",
".",
"isSuccessful",
"(",
")",
"==",
"true",
")",
")",
"{",
"this",
".",
"successful",
"=",
"true",
";",
"}",
"}"
] | Completes the migration and calculates the status. | [
"Completes",
"the",
"migration",
"and",
"calculates",
"the",
"status",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-case-mgmt/jbpm-case-mgmt-api/src/main/java/org/jbpm/casemgmt/api/admin/CaseMigrationReport.java#L79-L85 |
23,027 | kiegroup/jbpm | jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/query/QueryMapperRegistry.java | QueryMapperRegistry.mapperFor | public QueryResultMapper<?> mapperFor(String name, Map<String, String> columnMapping) {
if (!knownMappers.containsKey(name)) {
throw new IllegalArgumentException("No mapper found with name " + name);
}
if (columnMapping == null) {
return knownMappers.get(name);
} else {
return knownMappers.get(name).forColumnMapping(columnMapping);
}
} | java | public QueryResultMapper<?> mapperFor(String name, Map<String, String> columnMapping) {
if (!knownMappers.containsKey(name)) {
throw new IllegalArgumentException("No mapper found with name " + name);
}
if (columnMapping == null) {
return knownMappers.get(name);
} else {
return knownMappers.get(name).forColumnMapping(columnMapping);
}
} | [
"public",
"QueryResultMapper",
"<",
"?",
">",
"mapperFor",
"(",
"String",
"name",
",",
"Map",
"<",
"String",
",",
"String",
">",
"columnMapping",
")",
"{",
"if",
"(",
"!",
"knownMappers",
".",
"containsKey",
"(",
"name",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No mapper found with name \"",
"+",
"name",
")",
";",
"}",
"if",
"(",
"columnMapping",
"==",
"null",
")",
"{",
"return",
"knownMappers",
".",
"get",
"(",
"name",
")",
";",
"}",
"else",
"{",
"return",
"knownMappers",
".",
"get",
"(",
"name",
")",
".",
"forColumnMapping",
"(",
"columnMapping",
")",
";",
"}",
"}"
] | Returns mapper for given name if found
@param name unique name that mapper is bound to
@param columnMapping provides column mapping (name to type) that can be
shipped to mapper for improved transformation - can be null (accepted types: string, long, integer, date, double)
@return instance of the <code>QueryResultMapper</code> if found
@throws IllegalArgumentException in case there is no mapper found with given name | [
"Returns",
"mapper",
"for",
"given",
"name",
"if",
"found"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/query/QueryMapperRegistry.java#L64-L73 |
23,028 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/process/core/timer/TimerServiceRegistry.java | TimerServiceRegistry.registerTimerService | public void registerTimerService(String id, TimerService timerService) {
if (timerService instanceof GlobalTimerService) {
((GlobalTimerService) timerService).setTimerServiceId(id);
}
this.registeredServices.put(id, timerService);
} | java | public void registerTimerService(String id, TimerService timerService) {
if (timerService instanceof GlobalTimerService) {
((GlobalTimerService) timerService).setTimerServiceId(id);
}
this.registeredServices.put(id, timerService);
} | [
"public",
"void",
"registerTimerService",
"(",
"String",
"id",
",",
"TimerService",
"timerService",
")",
"{",
"if",
"(",
"timerService",
"instanceof",
"GlobalTimerService",
")",
"{",
"(",
"(",
"GlobalTimerService",
")",
"timerService",
")",
".",
"setTimerServiceId",
"(",
"id",
")",
";",
"}",
"this",
".",
"registeredServices",
".",
"put",
"(",
"id",
",",
"timerService",
")",
";",
"}"
] | Registers timerServie under given id. In case timer service is already registered
with this id it will be overridden.
@param id key used to get hold of the timer service instance
@param timerService fully initialized TimerService instance | [
"Registers",
"timerServie",
"under",
"given",
"id",
".",
"In",
"case",
"timer",
"service",
"is",
"already",
"registered",
"with",
"this",
"id",
"it",
"will",
"be",
"overridden",
"."
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/process/core/timer/TimerServiceRegistry.java#L48-L53 |
23,029 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/process/core/timer/TimerServiceRegistry.java | TimerServiceRegistry.get | public TimerService get(String id) {
if (id == null) {
return null;
}
return this.registeredServices.get(id);
} | java | public TimerService get(String id) {
if (id == null) {
return null;
}
return this.registeredServices.get(id);
} | [
"public",
"TimerService",
"get",
"(",
"String",
"id",
")",
"{",
"if",
"(",
"id",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"this",
".",
"registeredServices",
".",
"get",
"(",
"id",
")",
";",
"}"
] | Returns TimerService instance registered under given key
@param id timer service identifier
@return returns timer service instance or null of there was none registered with given id | [
"Returns",
"TimerService",
"instance",
"registered",
"under",
"given",
"key"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/process/core/timer/TimerServiceRegistry.java#L60-L65 |
23,030 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/BiomeGeneratorImplementation.java | BiomeGeneratorImplementation.onBiomeGenInit | @SubscribeEvent(priority = EventPriority.LOWEST)
public void onBiomeGenInit(WorldTypeEvent.InitBiomeGens event) {
// Negative one is flag value for normal world gen
if (bparams.getBiome() == -1)
return;
GenLayer[] replacement = new GenLayer[2];
replacement[0] = new GenLayerConstant(bparams.getBiome());
replacement[1] = replacement[0];
event.setNewBiomeGens(replacement);
} | java | @SubscribeEvent(priority = EventPriority.LOWEST)
public void onBiomeGenInit(WorldTypeEvent.InitBiomeGens event) {
// Negative one is flag value for normal world gen
if (bparams.getBiome() == -1)
return;
GenLayer[] replacement = new GenLayer[2];
replacement[0] = new GenLayerConstant(bparams.getBiome());
replacement[1] = replacement[0];
event.setNewBiomeGens(replacement);
} | [
"@",
"SubscribeEvent",
"(",
"priority",
"=",
"EventPriority",
".",
"LOWEST",
")",
"public",
"void",
"onBiomeGenInit",
"(",
"WorldTypeEvent",
".",
"InitBiomeGens",
"event",
")",
"{",
"// Negative one is flag value for normal world gen",
"if",
"(",
"bparams",
".",
"getBiome",
"(",
")",
"==",
"-",
"1",
")",
"return",
";",
"GenLayer",
"[",
"]",
"replacement",
"=",
"new",
"GenLayer",
"[",
"2",
"]",
";",
"replacement",
"[",
"0",
"]",
"=",
"new",
"GenLayerConstant",
"(",
"bparams",
".",
"getBiome",
"(",
")",
")",
";",
"replacement",
"[",
"1",
"]",
"=",
"replacement",
"[",
"0",
"]",
";",
"event",
".",
"setNewBiomeGens",
"(",
"replacement",
")",
";",
"}"
] | Make sure that the biome is one type with an event on biome gen | [
"Make",
"sure",
"that",
"the",
"biome",
"is",
"one",
"type",
"with",
"an",
"event",
"on",
"biome",
"gen"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/BiomeGeneratorImplementation.java#L84-L93 |
23,031 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java | CraftingHelper.itemStackIngredientsMatch | private static boolean itemStackIngredientsMatch(ItemStack A, ItemStack B)
{
if (A == null && B == null)
return true;
if (A == null || B == null)
return false;
if (A.getMetadata() == OreDictionary.WILDCARD_VALUE || B.getMetadata() == OreDictionary.WILDCARD_VALUE)
return A.getItem() == B.getItem();
return ItemStack.areItemsEqual(A, B);
} | java | private static boolean itemStackIngredientsMatch(ItemStack A, ItemStack B)
{
if (A == null && B == null)
return true;
if (A == null || B == null)
return false;
if (A.getMetadata() == OreDictionary.WILDCARD_VALUE || B.getMetadata() == OreDictionary.WILDCARD_VALUE)
return A.getItem() == B.getItem();
return ItemStack.areItemsEqual(A, B);
} | [
"private",
"static",
"boolean",
"itemStackIngredientsMatch",
"(",
"ItemStack",
"A",
",",
"ItemStack",
"B",
")",
"{",
"if",
"(",
"A",
"==",
"null",
"&&",
"B",
"==",
"null",
")",
"return",
"true",
";",
"if",
"(",
"A",
"==",
"null",
"||",
"B",
"==",
"null",
")",
"return",
"false",
";",
"if",
"(",
"A",
".",
"getMetadata",
"(",
")",
"==",
"OreDictionary",
".",
"WILDCARD_VALUE",
"||",
"B",
".",
"getMetadata",
"(",
")",
"==",
"OreDictionary",
".",
"WILDCARD_VALUE",
")",
"return",
"A",
".",
"getItem",
"(",
")",
"==",
"B",
".",
"getItem",
"(",
")",
";",
"return",
"ItemStack",
".",
"areItemsEqual",
"(",
"A",
",",
"B",
")",
";",
"}"
] | Compare two ItemStacks and see if their items match - take wildcards into account, don't take stacksize into account.
@param A ItemStack A
@param B ItemStack B
@return true if the stacks contain matching items. | [
"Compare",
"two",
"ItemStacks",
"and",
"see",
"if",
"their",
"items",
"match",
"-",
"take",
"wildcards",
"into",
"account",
"don",
"t",
"take",
"stacksize",
"into",
"account",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java#L210-L219 |
23,032 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java | CraftingHelper.totalBurnTimeInInventory | public static int totalBurnTimeInInventory(EntityPlayerMP player)
{
Integer fromCache = fuelCaches.get(player);
int total = (fromCache != null) ? fromCache : 0;
for (int i = 0; i < player.inventory.mainInventory.size(); i++)
{
ItemStack is = player.inventory.mainInventory.get(i);
total += TileEntityFurnace.getItemBurnTime(is);
}
return total;
} | java | public static int totalBurnTimeInInventory(EntityPlayerMP player)
{
Integer fromCache = fuelCaches.get(player);
int total = (fromCache != null) ? fromCache : 0;
for (int i = 0; i < player.inventory.mainInventory.size(); i++)
{
ItemStack is = player.inventory.mainInventory.get(i);
total += TileEntityFurnace.getItemBurnTime(is);
}
return total;
} | [
"public",
"static",
"int",
"totalBurnTimeInInventory",
"(",
"EntityPlayerMP",
"player",
")",
"{",
"Integer",
"fromCache",
"=",
"fuelCaches",
".",
"get",
"(",
"player",
")",
";",
"int",
"total",
"=",
"(",
"fromCache",
"!=",
"null",
")",
"?",
"fromCache",
":",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"player",
".",
"inventory",
".",
"mainInventory",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"ItemStack",
"is",
"=",
"player",
".",
"inventory",
".",
"mainInventory",
".",
"get",
"(",
"i",
")",
";",
"total",
"+=",
"TileEntityFurnace",
".",
"getItemBurnTime",
"(",
"is",
")",
";",
"}",
"return",
"total",
";",
"}"
] | Go through player's inventory and see how much fuel they have.
@param player
@return the amount of fuel available in ticks | [
"Go",
"through",
"player",
"s",
"inventory",
"and",
"see",
"how",
"much",
"fuel",
"they",
"have",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java#L225-L235 |
23,033 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java | CraftingHelper.getRecipesForRequestedOutput | public static List<IRecipe> getRecipesForRequestedOutput(String output)
{
List<IRecipe> matchingRecipes = new ArrayList<IRecipe>();
ItemStack target = MinecraftTypeHelper.getItemStackFromParameterString(output);
List<?> recipes = CraftingManager.getInstance().getRecipeList();
for (Object obj : recipes)
{
if (obj == null)
continue;
if (obj instanceof IRecipe)
{
ItemStack is = ((IRecipe)obj).getRecipeOutput();
if (is == null)
continue;
if (ItemStack.areItemsEqual(is, target))
{
matchingRecipes.add((IRecipe)obj);
}
}
}
return matchingRecipes;
} | java | public static List<IRecipe> getRecipesForRequestedOutput(String output)
{
List<IRecipe> matchingRecipes = new ArrayList<IRecipe>();
ItemStack target = MinecraftTypeHelper.getItemStackFromParameterString(output);
List<?> recipes = CraftingManager.getInstance().getRecipeList();
for (Object obj : recipes)
{
if (obj == null)
continue;
if (obj instanceof IRecipe)
{
ItemStack is = ((IRecipe)obj).getRecipeOutput();
if (is == null)
continue;
if (ItemStack.areItemsEqual(is, target))
{
matchingRecipes.add((IRecipe)obj);
}
}
}
return matchingRecipes;
} | [
"public",
"static",
"List",
"<",
"IRecipe",
">",
"getRecipesForRequestedOutput",
"(",
"String",
"output",
")",
"{",
"List",
"<",
"IRecipe",
">",
"matchingRecipes",
"=",
"new",
"ArrayList",
"<",
"IRecipe",
">",
"(",
")",
";",
"ItemStack",
"target",
"=",
"MinecraftTypeHelper",
".",
"getItemStackFromParameterString",
"(",
"output",
")",
";",
"List",
"<",
"?",
">",
"recipes",
"=",
"CraftingManager",
".",
"getInstance",
"(",
")",
".",
"getRecipeList",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"recipes",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
")",
"continue",
";",
"if",
"(",
"obj",
"instanceof",
"IRecipe",
")",
"{",
"ItemStack",
"is",
"=",
"(",
"(",
"IRecipe",
")",
"obj",
")",
".",
"getRecipeOutput",
"(",
")",
";",
"if",
"(",
"is",
"==",
"null",
")",
"continue",
";",
"if",
"(",
"ItemStack",
".",
"areItemsEqual",
"(",
"is",
",",
"target",
")",
")",
"{",
"matchingRecipes",
".",
"add",
"(",
"(",
"IRecipe",
")",
"obj",
")",
";",
"}",
"}",
"}",
"return",
"matchingRecipes",
";",
"}"
] | Attempt to find all recipes that result in an item of the requested output.
@param output the desired item, eg from Types.xsd - "diamond_pickaxe" etc - or as a Minecraft name - eg "tile.woolCarpet.blue"
@return a list of IRecipe objects that result in this item. | [
"Attempt",
"to",
"find",
"all",
"recipes",
"that",
"result",
"in",
"an",
"item",
"of",
"the",
"requested",
"output",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java#L329-L350 |
23,034 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java | CraftingHelper.getSmeltingRecipeForRequestedOutput | public static ItemStack getSmeltingRecipeForRequestedOutput(String output)
{
ItemStack target = MinecraftTypeHelper.getItemStackFromParameterString(output);
Iterator<?> furnaceIt = FurnaceRecipes.instance().getSmeltingList().keySet().iterator();
while (furnaceIt.hasNext())
{
ItemStack isInput = (ItemStack)furnaceIt.next();
ItemStack isOutput = (ItemStack)FurnaceRecipes.instance().getSmeltingList().get(isInput);
if (itemStackIngredientsMatch(target, isOutput))
return isInput;
}
return null;
} | java | public static ItemStack getSmeltingRecipeForRequestedOutput(String output)
{
ItemStack target = MinecraftTypeHelper.getItemStackFromParameterString(output);
Iterator<?> furnaceIt = FurnaceRecipes.instance().getSmeltingList().keySet().iterator();
while (furnaceIt.hasNext())
{
ItemStack isInput = (ItemStack)furnaceIt.next();
ItemStack isOutput = (ItemStack)FurnaceRecipes.instance().getSmeltingList().get(isInput);
if (itemStackIngredientsMatch(target, isOutput))
return isInput;
}
return null;
} | [
"public",
"static",
"ItemStack",
"getSmeltingRecipeForRequestedOutput",
"(",
"String",
"output",
")",
"{",
"ItemStack",
"target",
"=",
"MinecraftTypeHelper",
".",
"getItemStackFromParameterString",
"(",
"output",
")",
";",
"Iterator",
"<",
"?",
">",
"furnaceIt",
"=",
"FurnaceRecipes",
".",
"instance",
"(",
")",
".",
"getSmeltingList",
"(",
")",
".",
"keySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"furnaceIt",
".",
"hasNext",
"(",
")",
")",
"{",
"ItemStack",
"isInput",
"=",
"(",
"ItemStack",
")",
"furnaceIt",
".",
"next",
"(",
")",
";",
"ItemStack",
"isOutput",
"=",
"(",
"ItemStack",
")",
"FurnaceRecipes",
".",
"instance",
"(",
")",
".",
"getSmeltingList",
"(",
")",
".",
"get",
"(",
"isInput",
")",
";",
"if",
"(",
"itemStackIngredientsMatch",
"(",
"target",
",",
"isOutput",
")",
")",
"return",
"isInput",
";",
"}",
"return",
"null",
";",
"}"
] | Attempt to find a smelting recipe that results in the requested output.
@param output
@return an ItemStack representing the required input. | [
"Attempt",
"to",
"find",
"a",
"smelting",
"recipe",
"that",
"results",
"in",
"the",
"requested",
"output",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java#L356-L368 |
23,035 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java | CraftingHelper.dumpRecipes | public static void dumpRecipes(String filename) throws IOException
{
FileOutputStream fos = new FileOutputStream(filename);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter writer = new BufferedWriter(osw);
List<?> recipes = CraftingManager.getInstance().getRecipeList();
for (Object obj : recipes)
{
if (obj == null)
continue;
if (obj instanceof IRecipe)
{
ItemStack is = ((IRecipe)obj).getRecipeOutput();
if (is == null)
continue;
String s = is.getCount() + "x" + is.getUnlocalizedName() + " = ";
List<ItemStack> ingredients = getIngredients((IRecipe)obj);
if (ingredients == null)
continue;
boolean first = true;
for (ItemStack isIngredient : ingredients)
{
if (!first)
s += ", ";
s += isIngredient.getCount() + "x" + isIngredient.getUnlocalizedName();
s += "(" + isIngredient.getDisplayName() + ")";
first = false;
}
s += "\n";
writer.write(s);
}
}
Iterator<?> furnaceIt = FurnaceRecipes.instance().getSmeltingList().keySet().iterator();
while (furnaceIt.hasNext())
{
ItemStack isInput = (ItemStack)furnaceIt.next();
ItemStack isOutput = (ItemStack)FurnaceRecipes.instance().getSmeltingList().get(isInput);
String s = isOutput.getCount() + "x" + isOutput.getUnlocalizedName() + " = FUEL + " + isInput.getCount() + "x" + isInput.getUnlocalizedName() + "\n";
writer.write(s);
}
writer.close();
} | java | public static void dumpRecipes(String filename) throws IOException
{
FileOutputStream fos = new FileOutputStream(filename);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter writer = new BufferedWriter(osw);
List<?> recipes = CraftingManager.getInstance().getRecipeList();
for (Object obj : recipes)
{
if (obj == null)
continue;
if (obj instanceof IRecipe)
{
ItemStack is = ((IRecipe)obj).getRecipeOutput();
if (is == null)
continue;
String s = is.getCount() + "x" + is.getUnlocalizedName() + " = ";
List<ItemStack> ingredients = getIngredients((IRecipe)obj);
if (ingredients == null)
continue;
boolean first = true;
for (ItemStack isIngredient : ingredients)
{
if (!first)
s += ", ";
s += isIngredient.getCount() + "x" + isIngredient.getUnlocalizedName();
s += "(" + isIngredient.getDisplayName() + ")";
first = false;
}
s += "\n";
writer.write(s);
}
}
Iterator<?> furnaceIt = FurnaceRecipes.instance().getSmeltingList().keySet().iterator();
while (furnaceIt.hasNext())
{
ItemStack isInput = (ItemStack)furnaceIt.next();
ItemStack isOutput = (ItemStack)FurnaceRecipes.instance().getSmeltingList().get(isInput);
String s = isOutput.getCount() + "x" + isOutput.getUnlocalizedName() + " = FUEL + " + isInput.getCount() + "x" + isInput.getUnlocalizedName() + "\n";
writer.write(s);
}
writer.close();
} | [
"public",
"static",
"void",
"dumpRecipes",
"(",
"String",
"filename",
")",
"throws",
"IOException",
"{",
"FileOutputStream",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"filename",
")",
";",
"OutputStreamWriter",
"osw",
"=",
"new",
"OutputStreamWriter",
"(",
"fos",
",",
"\"utf-8\"",
")",
";",
"BufferedWriter",
"writer",
"=",
"new",
"BufferedWriter",
"(",
"osw",
")",
";",
"List",
"<",
"?",
">",
"recipes",
"=",
"CraftingManager",
".",
"getInstance",
"(",
")",
".",
"getRecipeList",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"recipes",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
")",
"continue",
";",
"if",
"(",
"obj",
"instanceof",
"IRecipe",
")",
"{",
"ItemStack",
"is",
"=",
"(",
"(",
"IRecipe",
")",
"obj",
")",
".",
"getRecipeOutput",
"(",
")",
";",
"if",
"(",
"is",
"==",
"null",
")",
"continue",
";",
"String",
"s",
"=",
"is",
".",
"getCount",
"(",
")",
"+",
"\"x\"",
"+",
"is",
".",
"getUnlocalizedName",
"(",
")",
"+",
"\" = \"",
";",
"List",
"<",
"ItemStack",
">",
"ingredients",
"=",
"getIngredients",
"(",
"(",
"IRecipe",
")",
"obj",
")",
";",
"if",
"(",
"ingredients",
"==",
"null",
")",
"continue",
";",
"boolean",
"first",
"=",
"true",
";",
"for",
"(",
"ItemStack",
"isIngredient",
":",
"ingredients",
")",
"{",
"if",
"(",
"!",
"first",
")",
"s",
"+=",
"\", \"",
";",
"s",
"+=",
"isIngredient",
".",
"getCount",
"(",
")",
"+",
"\"x\"",
"+",
"isIngredient",
".",
"getUnlocalizedName",
"(",
")",
";",
"s",
"+=",
"\"(\"",
"+",
"isIngredient",
".",
"getDisplayName",
"(",
")",
"+",
"\")\"",
";",
"first",
"=",
"false",
";",
"}",
"s",
"+=",
"\"\\n\"",
";",
"writer",
".",
"write",
"(",
"s",
")",
";",
"}",
"}",
"Iterator",
"<",
"?",
">",
"furnaceIt",
"=",
"FurnaceRecipes",
".",
"instance",
"(",
")",
".",
"getSmeltingList",
"(",
")",
".",
"keySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"furnaceIt",
".",
"hasNext",
"(",
")",
")",
"{",
"ItemStack",
"isInput",
"=",
"(",
"ItemStack",
")",
"furnaceIt",
".",
"next",
"(",
")",
";",
"ItemStack",
"isOutput",
"=",
"(",
"ItemStack",
")",
"FurnaceRecipes",
".",
"instance",
"(",
")",
".",
"getSmeltingList",
"(",
")",
".",
"get",
"(",
"isInput",
")",
";",
"String",
"s",
"=",
"isOutput",
".",
"getCount",
"(",
")",
"+",
"\"x\"",
"+",
"isOutput",
".",
"getUnlocalizedName",
"(",
")",
"+",
"\" = FUEL + \"",
"+",
"isInput",
".",
"getCount",
"(",
")",
"+",
"\"x\"",
"+",
"isInput",
".",
"getUnlocalizedName",
"(",
")",
"+",
"\"\\n\"",
";",
"writer",
".",
"write",
"(",
"s",
")",
";",
"}",
"writer",
".",
"close",
"(",
")",
";",
"}"
] | Little utility method for dumping out a list of all the recipes we understand.
@param filename location to save the dumped list.
@throws IOException | [
"Little",
"utility",
"method",
"for",
"dumping",
"out",
"a",
"list",
"of",
"all",
"the",
"recipes",
"we",
"understand",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/CraftingHelper.java#L527-L568 |
23,036 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Server/ServerStateMachine.java | ServerStateMachine.onCheckSpawn | @SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
// Decide whether or not to allow spawning.
// We shouldn't allow spawning unless it has been specifically turned on - whether
// a mission is running or not. (Otherwise spawning may happen in between missions.)
boolean allowSpawning = false;
if (currentMissionInit() != null && currentMissionInit().getMission() != null)
{
// There is a mission running - does it allow spawning?
ServerSection ss = currentMissionInit().getMission().getServerSection();
ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
if (sic != null)
allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
{
// Spawning is allowed, but restricted to our list.
// Is this mob on our list?
String mobName = EntityList.getEntityString(cs.getEntity());
allowSpawning = false;
for (EntityTypes mob : sic.getAllowedMobs())
{
if (mob.value().equals(mobName))
{
allowSpawning = true;
break;
}
}
}
}
if (allowSpawning)
cs.setResult(Result.DEFAULT);
else
cs.setResult(Result.DENY);
} | java | @SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
// Decide whether or not to allow spawning.
// We shouldn't allow spawning unless it has been specifically turned on - whether
// a mission is running or not. (Otherwise spawning may happen in between missions.)
boolean allowSpawning = false;
if (currentMissionInit() != null && currentMissionInit().getMission() != null)
{
// There is a mission running - does it allow spawning?
ServerSection ss = currentMissionInit().getMission().getServerSection();
ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
if (sic != null)
allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
{
// Spawning is allowed, but restricted to our list.
// Is this mob on our list?
String mobName = EntityList.getEntityString(cs.getEntity());
allowSpawning = false;
for (EntityTypes mob : sic.getAllowedMobs())
{
if (mob.value().equals(mobName))
{
allowSpawning = true;
break;
}
}
}
}
if (allowSpawning)
cs.setResult(Result.DEFAULT);
else
cs.setResult(Result.DENY);
} | [
"@",
"SubscribeEvent",
"public",
"void",
"onCheckSpawn",
"(",
"CheckSpawn",
"cs",
")",
"{",
"// Decide whether or not to allow spawning.",
"// We shouldn't allow spawning unless it has been specifically turned on - whether",
"// a mission is running or not. (Otherwise spawning may happen in between missions.)",
"boolean",
"allowSpawning",
"=",
"false",
";",
"if",
"(",
"currentMissionInit",
"(",
")",
"!=",
"null",
"&&",
"currentMissionInit",
"(",
")",
".",
"getMission",
"(",
")",
"!=",
"null",
")",
"{",
"// There is a mission running - does it allow spawning?",
"ServerSection",
"ss",
"=",
"currentMissionInit",
"(",
")",
".",
"getMission",
"(",
")",
".",
"getServerSection",
"(",
")",
";",
"ServerInitialConditions",
"sic",
"=",
"(",
"ss",
"!=",
"null",
")",
"?",
"ss",
".",
"getServerInitialConditions",
"(",
")",
":",
"null",
";",
"if",
"(",
"sic",
"!=",
"null",
")",
"allowSpawning",
"=",
"(",
"sic",
".",
"isAllowSpawning",
"(",
")",
"==",
"Boolean",
".",
"TRUE",
")",
";",
"if",
"(",
"allowSpawning",
"&&",
"sic",
".",
"getAllowedMobs",
"(",
")",
"!=",
"null",
"&&",
"!",
"sic",
".",
"getAllowedMobs",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"// Spawning is allowed, but restricted to our list.",
"// Is this mob on our list?",
"String",
"mobName",
"=",
"EntityList",
".",
"getEntityString",
"(",
"cs",
".",
"getEntity",
"(",
")",
")",
";",
"allowSpawning",
"=",
"false",
";",
"for",
"(",
"EntityTypes",
"mob",
":",
"sic",
".",
"getAllowedMobs",
"(",
")",
")",
"{",
"if",
"(",
"mob",
".",
"value",
"(",
")",
".",
"equals",
"(",
"mobName",
")",
")",
"{",
"allowSpawning",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"allowSpawning",
")",
"cs",
".",
"setResult",
"(",
"Result",
".",
"DEFAULT",
")",
";",
"else",
"cs",
".",
"setResult",
"(",
"Result",
".",
"DENY",
")",
";",
"}"
] | Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world. | [
"Called",
"by",
"Forge",
"-",
"return",
"ALLOW",
"DENY",
"or",
"DEFAULT",
"to",
"control",
"spawning",
"in",
"our",
"world",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Server/ServerStateMachine.java#L256-L291 |
23,037 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/JSONWorldDataHelper.java | JSONWorldDataHelper.buildAchievementStats | public static void buildAchievementStats(JsonObject json, EntityPlayerMP player)
{
StatisticsManagerServer sfw = player.getStatFile();
json.addProperty("DistanceTravelled",
sfw.readStat((StatBase)StatList.WALK_ONE_CM)
+ sfw.readStat((StatBase)StatList.SWIM_ONE_CM)
+ sfw.readStat((StatBase)StatList.DIVE_ONE_CM)
+ sfw.readStat((StatBase)StatList.FALL_ONE_CM)
); // TODO: there are many other ways of moving!
json.addProperty("TimeAlive", sfw.readStat((StatBase)StatList.TIME_SINCE_DEATH));
json.addProperty("MobsKilled", sfw.readStat((StatBase)StatList.MOB_KILLS));
json.addProperty("PlayersKilled", sfw.readStat((StatBase)StatList.PLAYER_KILLS));
json.addProperty("DamageTaken", sfw.readStat((StatBase)StatList.DAMAGE_TAKEN));
json.addProperty("DamageDealt", sfw.readStat((StatBase)StatList.DAMAGE_DEALT));
/* Other potential reinforcement signals that may be worth researching:
json.addProperty("BlocksDestroyed", sfw.readStat((StatBase)StatList.objectBreakStats) - but objectBreakStats is an array of 32000 StatBase objects - indexed by block type.);
json.addProperty("Blocked", ev.player.isMovementBlocked()) - but isMovementBlocker() is a protected method (can get round this with reflection)
*/
} | java | public static void buildAchievementStats(JsonObject json, EntityPlayerMP player)
{
StatisticsManagerServer sfw = player.getStatFile();
json.addProperty("DistanceTravelled",
sfw.readStat((StatBase)StatList.WALK_ONE_CM)
+ sfw.readStat((StatBase)StatList.SWIM_ONE_CM)
+ sfw.readStat((StatBase)StatList.DIVE_ONE_CM)
+ sfw.readStat((StatBase)StatList.FALL_ONE_CM)
); // TODO: there are many other ways of moving!
json.addProperty("TimeAlive", sfw.readStat((StatBase)StatList.TIME_SINCE_DEATH));
json.addProperty("MobsKilled", sfw.readStat((StatBase)StatList.MOB_KILLS));
json.addProperty("PlayersKilled", sfw.readStat((StatBase)StatList.PLAYER_KILLS));
json.addProperty("DamageTaken", sfw.readStat((StatBase)StatList.DAMAGE_TAKEN));
json.addProperty("DamageDealt", sfw.readStat((StatBase)StatList.DAMAGE_DEALT));
/* Other potential reinforcement signals that may be worth researching:
json.addProperty("BlocksDestroyed", sfw.readStat((StatBase)StatList.objectBreakStats) - but objectBreakStats is an array of 32000 StatBase objects - indexed by block type.);
json.addProperty("Blocked", ev.player.isMovementBlocked()) - but isMovementBlocker() is a protected method (can get round this with reflection)
*/
} | [
"public",
"static",
"void",
"buildAchievementStats",
"(",
"JsonObject",
"json",
",",
"EntityPlayerMP",
"player",
")",
"{",
"StatisticsManagerServer",
"sfw",
"=",
"player",
".",
"getStatFile",
"(",
")",
";",
"json",
".",
"addProperty",
"(",
"\"DistanceTravelled\"",
",",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"WALK_ONE_CM",
")",
"+",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"SWIM_ONE_CM",
")",
"+",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"DIVE_ONE_CM",
")",
"+",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"FALL_ONE_CM",
")",
")",
";",
"// TODO: there are many other ways of moving!",
"json",
".",
"addProperty",
"(",
"\"TimeAlive\"",
",",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"TIME_SINCE_DEATH",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"MobsKilled\"",
",",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"MOB_KILLS",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"PlayersKilled\"",
",",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"PLAYER_KILLS",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"DamageTaken\"",
",",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"DAMAGE_TAKEN",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"DamageDealt\"",
",",
"sfw",
".",
"readStat",
"(",
"(",
"StatBase",
")",
"StatList",
".",
"DAMAGE_DEALT",
")",
")",
";",
"/* Other potential reinforcement signals that may be worth researching:\n json.addProperty(\"BlocksDestroyed\", sfw.readStat((StatBase)StatList.objectBreakStats) - but objectBreakStats is an array of 32000 StatBase objects - indexed by block type.);\n json.addProperty(\"Blocked\", ev.player.isMovementBlocked()) - but isMovementBlocker() is a protected method (can get round this with reflection)\n */",
"}"
] | Builds the basic achievement world data to be used as observation signals by the listener.
@param json a JSON object into which the achievement stats will be added. | [
"Builds",
"the",
"basic",
"achievement",
"world",
"data",
"to",
"be",
"used",
"as",
"observation",
"signals",
"by",
"the",
"listener",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/JSONWorldDataHelper.java#L100-L119 |
23,038 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/JSONWorldDataHelper.java | JSONWorldDataHelper.buildLifeStats | public static void buildLifeStats(JsonObject json, EntityPlayerMP player)
{
json.addProperty("Life", player.getHealth());
json.addProperty("Score", player.getScore()); // Might always be the same as XP?
json.addProperty("Food", player.getFoodStats().getFoodLevel());
json.addProperty("XP", player.experienceTotal);
json.addProperty("IsAlive", !player.isDead);
json.addProperty("Air", player.getAir());
json.addProperty("Name", player.getName());
} | java | public static void buildLifeStats(JsonObject json, EntityPlayerMP player)
{
json.addProperty("Life", player.getHealth());
json.addProperty("Score", player.getScore()); // Might always be the same as XP?
json.addProperty("Food", player.getFoodStats().getFoodLevel());
json.addProperty("XP", player.experienceTotal);
json.addProperty("IsAlive", !player.isDead);
json.addProperty("Air", player.getAir());
json.addProperty("Name", player.getName());
} | [
"public",
"static",
"void",
"buildLifeStats",
"(",
"JsonObject",
"json",
",",
"EntityPlayerMP",
"player",
")",
"{",
"json",
".",
"addProperty",
"(",
"\"Life\"",
",",
"player",
".",
"getHealth",
"(",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"Score\"",
",",
"player",
".",
"getScore",
"(",
")",
")",
";",
"// Might always be the same as XP?",
"json",
".",
"addProperty",
"(",
"\"Food\"",
",",
"player",
".",
"getFoodStats",
"(",
")",
".",
"getFoodLevel",
"(",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"XP\"",
",",
"player",
".",
"experienceTotal",
")",
";",
"json",
".",
"addProperty",
"(",
"\"IsAlive\"",
",",
"!",
"player",
".",
"isDead",
")",
";",
"json",
".",
"addProperty",
"(",
"\"Air\"",
",",
"player",
".",
"getAir",
"(",
")",
")",
";",
"json",
".",
"addProperty",
"(",
"\"Name\"",
",",
"player",
".",
"getName",
"(",
")",
")",
";",
"}"
] | Builds the basic life world data to be used as observation signals by the listener.
@param json a JSON object into which the life stats will be added. | [
"Builds",
"the",
"basic",
"life",
"world",
"data",
"to",
"be",
"used",
"as",
"observation",
"signals",
"by",
"the",
"listener",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/JSONWorldDataHelper.java#L124-L133 |
23,039 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/JSONWorldDataHelper.java | JSONWorldDataHelper.buildPositionStats | public static void buildPositionStats(JsonObject json, EntityPlayerMP player)
{
json.addProperty("XPos", player.posX);
json.addProperty("YPos", player.posY);
json.addProperty("ZPos", player.posZ);
json.addProperty("Pitch", player.rotationPitch);
json.addProperty("Yaw", player.rotationYaw);
} | java | public static void buildPositionStats(JsonObject json, EntityPlayerMP player)
{
json.addProperty("XPos", player.posX);
json.addProperty("YPos", player.posY);
json.addProperty("ZPos", player.posZ);
json.addProperty("Pitch", player.rotationPitch);
json.addProperty("Yaw", player.rotationYaw);
} | [
"public",
"static",
"void",
"buildPositionStats",
"(",
"JsonObject",
"json",
",",
"EntityPlayerMP",
"player",
")",
"{",
"json",
".",
"addProperty",
"(",
"\"XPos\"",
",",
"player",
".",
"posX",
")",
";",
"json",
".",
"addProperty",
"(",
"\"YPos\"",
",",
"player",
".",
"posY",
")",
";",
"json",
".",
"addProperty",
"(",
"\"ZPos\"",
",",
"player",
".",
"posZ",
")",
";",
"json",
".",
"addProperty",
"(",
"\"Pitch\"",
",",
"player",
".",
"rotationPitch",
")",
";",
"json",
".",
"addProperty",
"(",
"\"Yaw\"",
",",
"player",
".",
"rotationYaw",
")",
";",
"}"
] | Builds the player position data to be used as observation signals by the listener.
@param json a JSON object into which the positional information will be added. | [
"Builds",
"the",
"player",
"position",
"data",
"to",
"be",
"used",
"as",
"observation",
"signals",
"by",
"the",
"listener",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/JSONWorldDataHelper.java#L138-L145 |
23,040 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MapFileHelper.java | MapFileHelper.copyMapFiles | static public File copyMapFiles(File mapFile, boolean isTemporary)
{
System.out.println("Current directory: "+System.getProperty("user.dir"));
// Look for the basemap file.
// If it exists, copy it into the Minecraft saves folder,
// and attempt to load it.
File savesDir = FMLClientHandler.instance().getSavesDir();
File dst = null;
if (mapFile != null && mapFile.exists())
{
dst = new File(savesDir, getNewSaveFileLocation(isTemporary));
try
{
FileUtils.copyDirectory(mapFile, dst);
}
catch (IOException e)
{
System.out.println("Failed to load file: " + mapFile.getPath());
return null;
}
}
return dst;
} | java | static public File copyMapFiles(File mapFile, boolean isTemporary)
{
System.out.println("Current directory: "+System.getProperty("user.dir"));
// Look for the basemap file.
// If it exists, copy it into the Minecraft saves folder,
// and attempt to load it.
File savesDir = FMLClientHandler.instance().getSavesDir();
File dst = null;
if (mapFile != null && mapFile.exists())
{
dst = new File(savesDir, getNewSaveFileLocation(isTemporary));
try
{
FileUtils.copyDirectory(mapFile, dst);
}
catch (IOException e)
{
System.out.println("Failed to load file: " + mapFile.getPath());
return null;
}
}
return dst;
} | [
"static",
"public",
"File",
"copyMapFiles",
"(",
"File",
"mapFile",
",",
"boolean",
"isTemporary",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Current directory: \"",
"+",
"System",
".",
"getProperty",
"(",
"\"user.dir\"",
")",
")",
";",
"// Look for the basemap file.",
"// If it exists, copy it into the Minecraft saves folder,",
"// and attempt to load it.",
"File",
"savesDir",
"=",
"FMLClientHandler",
".",
"instance",
"(",
")",
".",
"getSavesDir",
"(",
")",
";",
"File",
"dst",
"=",
"null",
";",
"if",
"(",
"mapFile",
"!=",
"null",
"&&",
"mapFile",
".",
"exists",
"(",
")",
")",
"{",
"dst",
"=",
"new",
"File",
"(",
"savesDir",
",",
"getNewSaveFileLocation",
"(",
"isTemporary",
")",
")",
";",
"try",
"{",
"FileUtils",
".",
"copyDirectory",
"(",
"mapFile",
",",
"dst",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Failed to load file: \"",
"+",
"mapFile",
".",
"getPath",
"(",
")",
")",
";",
"return",
"null",
";",
"}",
"}",
"return",
"dst",
";",
"}"
] | Attempt to copy the specified file into the Minecraft saves folder.
@param mapFile full path to the map file required
@param overwriteOldFiles if false, will rename copy to avoid overwriting any other saved games
@return if successful, a File object representing the new copy, which can be fed to Minecraft to load - otherwise null. | [
"Attempt",
"to",
"copy",
"the",
"specified",
"file",
"into",
"the",
"Minecraft",
"saves",
"folder",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MapFileHelper.java#L48-L72 |
23,041 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MapFileHelper.java | MapFileHelper.createAndLaunchWorld | public static boolean createAndLaunchWorld(WorldSettings worldsettings, boolean isTemporary)
{
String s = getNewSaveFileLocation(isTemporary);
Minecraft.getMinecraft().launchIntegratedServer(s, s, worldsettings);
cleanupTemporaryWorlds(s);
return true;
} | java | public static boolean createAndLaunchWorld(WorldSettings worldsettings, boolean isTemporary)
{
String s = getNewSaveFileLocation(isTemporary);
Minecraft.getMinecraft().launchIntegratedServer(s, s, worldsettings);
cleanupTemporaryWorlds(s);
return true;
} | [
"public",
"static",
"boolean",
"createAndLaunchWorld",
"(",
"WorldSettings",
"worldsettings",
",",
"boolean",
"isTemporary",
")",
"{",
"String",
"s",
"=",
"getNewSaveFileLocation",
"(",
"isTemporary",
")",
";",
"Minecraft",
".",
"getMinecraft",
"(",
")",
".",
"launchIntegratedServer",
"(",
"s",
",",
"s",
",",
"worldsettings",
")",
";",
"cleanupTemporaryWorlds",
"(",
"s",
")",
";",
"return",
"true",
";",
"}"
] | Creates and launches a unique world according to the settings.
@param worldsettings the world's settings
@param isTemporary if true, the world will be deleted whenever newer worlds are created
@return | [
"Creates",
"and",
"launches",
"a",
"unique",
"world",
"according",
"to",
"the",
"settings",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MapFileHelper.java#L106-L112 |
23,042 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MapFileHelper.java | MapFileHelper.cleanupTemporaryWorlds | public static void cleanupTemporaryWorlds(String currentWorld){
List<WorldSummary> saveList;
ISaveFormat isaveformat = Minecraft.getMinecraft().getSaveLoader();
isaveformat.flushCache();
try{
saveList = isaveformat.getSaveList();
} catch (AnvilConverterException e){
e.printStackTrace();
return;
}
String searchString = tempMark + AddressHelper.getMissionControlPort() + "_";
for (WorldSummary s: saveList){
String folderName = s.getFileName();
if (folderName.startsWith(searchString) && !folderName.equals(currentWorld)){
isaveformat.deleteWorldDirectory(folderName);
}
}
} | java | public static void cleanupTemporaryWorlds(String currentWorld){
List<WorldSummary> saveList;
ISaveFormat isaveformat = Minecraft.getMinecraft().getSaveLoader();
isaveformat.flushCache();
try{
saveList = isaveformat.getSaveList();
} catch (AnvilConverterException e){
e.printStackTrace();
return;
}
String searchString = tempMark + AddressHelper.getMissionControlPort() + "_";
for (WorldSummary s: saveList){
String folderName = s.getFileName();
if (folderName.startsWith(searchString) && !folderName.equals(currentWorld)){
isaveformat.deleteWorldDirectory(folderName);
}
}
} | [
"public",
"static",
"void",
"cleanupTemporaryWorlds",
"(",
"String",
"currentWorld",
")",
"{",
"List",
"<",
"WorldSummary",
">",
"saveList",
";",
"ISaveFormat",
"isaveformat",
"=",
"Minecraft",
".",
"getMinecraft",
"(",
")",
".",
"getSaveLoader",
"(",
")",
";",
"isaveformat",
".",
"flushCache",
"(",
")",
";",
"try",
"{",
"saveList",
"=",
"isaveformat",
".",
"getSaveList",
"(",
")",
";",
"}",
"catch",
"(",
"AnvilConverterException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"return",
";",
"}",
"String",
"searchString",
"=",
"tempMark",
"+",
"AddressHelper",
".",
"getMissionControlPort",
"(",
")",
"+",
"\"_\"",
";",
"for",
"(",
"WorldSummary",
"s",
":",
"saveList",
")",
"{",
"String",
"folderName",
"=",
"s",
".",
"getFileName",
"(",
")",
";",
"if",
"(",
"folderName",
".",
"startsWith",
"(",
"searchString",
")",
"&&",
"!",
"folderName",
".",
"equals",
"(",
"currentWorld",
")",
")",
"{",
"isaveformat",
".",
"deleteWorldDirectory",
"(",
"folderName",
")",
";",
"}",
"}",
"}"
] | Attempts to delete all Minecraft Worlds with "TEMP_" in front of the name
@param currentWorld excludes this world from deletion, can be null | [
"Attempts",
"to",
"delete",
"all",
"Minecraft",
"Worlds",
"with",
"TEMP_",
"in",
"front",
"of",
"the",
"name"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MapFileHelper.java#L118-L138 |
23,043 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java | BlockDrawingHelper.Draw | public void Draw( DrawingDecorator drawingNode, World world ) throws Exception
{
beginDrawing(world);
for(JAXBElement<?> jaxbobj : drawingNode.getDrawObjectType())
{
Object obj = jaxbobj.getValue();
// isn't there an easier way of doing this?
if( obj instanceof DrawBlock )
DrawPrimitive( (DrawBlock)obj, world );
else if( obj instanceof DrawItem )
DrawPrimitive( (DrawItem)obj, world );
else if( obj instanceof DrawCuboid )
DrawPrimitive( (DrawCuboid)obj, world );
else if (obj instanceof DrawSphere )
DrawPrimitive( (DrawSphere)obj, world );
else if (obj instanceof DrawLine )
DrawPrimitive( (DrawLine)obj, world );
else if (obj instanceof DrawEntity)
DrawPrimitive( (DrawEntity)obj, world );
else if (obj instanceof DrawContainer)
DrawPrimitive( (DrawContainer)obj, world );
else if (obj instanceof DrawSign)
DrawPrimitive( (DrawSign)obj, world );
else
throw new Exception("Unsupported drawing primitive: "+obj.getClass().getName() );
}
endDrawing(world);
} | java | public void Draw( DrawingDecorator drawingNode, World world ) throws Exception
{
beginDrawing(world);
for(JAXBElement<?> jaxbobj : drawingNode.getDrawObjectType())
{
Object obj = jaxbobj.getValue();
// isn't there an easier way of doing this?
if( obj instanceof DrawBlock )
DrawPrimitive( (DrawBlock)obj, world );
else if( obj instanceof DrawItem )
DrawPrimitive( (DrawItem)obj, world );
else if( obj instanceof DrawCuboid )
DrawPrimitive( (DrawCuboid)obj, world );
else if (obj instanceof DrawSphere )
DrawPrimitive( (DrawSphere)obj, world );
else if (obj instanceof DrawLine )
DrawPrimitive( (DrawLine)obj, world );
else if (obj instanceof DrawEntity)
DrawPrimitive( (DrawEntity)obj, world );
else if (obj instanceof DrawContainer)
DrawPrimitive( (DrawContainer)obj, world );
else if (obj instanceof DrawSign)
DrawPrimitive( (DrawSign)obj, world );
else
throw new Exception("Unsupported drawing primitive: "+obj.getClass().getName() );
}
endDrawing(world);
} | [
"public",
"void",
"Draw",
"(",
"DrawingDecorator",
"drawingNode",
",",
"World",
"world",
")",
"throws",
"Exception",
"{",
"beginDrawing",
"(",
"world",
")",
";",
"for",
"(",
"JAXBElement",
"<",
"?",
">",
"jaxbobj",
":",
"drawingNode",
".",
"getDrawObjectType",
"(",
")",
")",
"{",
"Object",
"obj",
"=",
"jaxbobj",
".",
"getValue",
"(",
")",
";",
"// isn't there an easier way of doing this?",
"if",
"(",
"obj",
"instanceof",
"DrawBlock",
")",
"DrawPrimitive",
"(",
"(",
"DrawBlock",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawItem",
")",
"DrawPrimitive",
"(",
"(",
"DrawItem",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawCuboid",
")",
"DrawPrimitive",
"(",
"(",
"DrawCuboid",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawSphere",
")",
"DrawPrimitive",
"(",
"(",
"DrawSphere",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawLine",
")",
"DrawPrimitive",
"(",
"(",
"DrawLine",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawEntity",
")",
"DrawPrimitive",
"(",
"(",
"DrawEntity",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawContainer",
")",
"DrawPrimitive",
"(",
"(",
"DrawContainer",
")",
"obj",
",",
"world",
")",
";",
"else",
"if",
"(",
"obj",
"instanceof",
"DrawSign",
")",
"DrawPrimitive",
"(",
"(",
"DrawSign",
")",
"obj",
",",
"world",
")",
";",
"else",
"throw",
"new",
"Exception",
"(",
"\"Unsupported drawing primitive: \"",
"+",
"obj",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"endDrawing",
"(",
"world",
")",
";",
"}"
] | Draws the specified drawing into the Minecraft world supplied.
@param drawingNode The sequence of drawing primitives to draw.
@param world The world in which to draw them.
@throws Exception Unrecognised block types or primitives cause an exception to be thrown. | [
"Draws",
"the",
"specified",
"drawing",
"into",
"the",
"Minecraft",
"world",
"supplied",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java#L180-L209 |
23,044 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java | BlockDrawingHelper.DrawPrimitive | private void DrawPrimitive( DrawBlock b, World w ) throws Exception
{
XMLBlockState blockType = new XMLBlockState(b.getType(), b.getColour(), b.getFace(), b.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecogised item type: " + b.getType().value());
BlockPos pos = new BlockPos( b.getX(), b.getY(), b.getZ() );
clearEntities(w, b.getX(), b.getY(), b.getZ(), b.getX() + 1, b.getY() + 1, b.getZ() + 1);
setBlockState(w, pos, blockType );
} | java | private void DrawPrimitive( DrawBlock b, World w ) throws Exception
{
XMLBlockState blockType = new XMLBlockState(b.getType(), b.getColour(), b.getFace(), b.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecogised item type: " + b.getType().value());
BlockPos pos = new BlockPos( b.getX(), b.getY(), b.getZ() );
clearEntities(w, b.getX(), b.getY(), b.getZ(), b.getX() + 1, b.getY() + 1, b.getZ() + 1);
setBlockState(w, pos, blockType );
} | [
"private",
"void",
"DrawPrimitive",
"(",
"DrawBlock",
"b",
",",
"World",
"w",
")",
"throws",
"Exception",
"{",
"XMLBlockState",
"blockType",
"=",
"new",
"XMLBlockState",
"(",
"b",
".",
"getType",
"(",
")",
",",
"b",
".",
"getColour",
"(",
")",
",",
"b",
".",
"getFace",
"(",
")",
",",
"b",
".",
"getVariant",
"(",
")",
")",
";",
"if",
"(",
"!",
"blockType",
".",
"isValid",
"(",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Unrecogised item type: \"",
"+",
"b",
".",
"getType",
"(",
")",
".",
"value",
"(",
")",
")",
";",
"BlockPos",
"pos",
"=",
"new",
"BlockPos",
"(",
"b",
".",
"getX",
"(",
")",
",",
"b",
".",
"getY",
"(",
")",
",",
"b",
".",
"getZ",
"(",
")",
")",
";",
"clearEntities",
"(",
"w",
",",
"b",
".",
"getX",
"(",
")",
",",
"b",
".",
"getY",
"(",
")",
",",
"b",
".",
"getZ",
"(",
")",
",",
"b",
".",
"getX",
"(",
")",
"+",
"1",
",",
"b",
".",
"getY",
"(",
")",
"+",
"1",
",",
"b",
".",
"getZ",
"(",
")",
"+",
"1",
")",
";",
"setBlockState",
"(",
"w",
",",
"pos",
",",
"blockType",
")",
";",
"}"
] | Draw a single Minecraft block.
@param b Contains information about the block to be drawn.
@param w The world in which to draw.
@throws Exception Throws an exception if the block type is not recognised. | [
"Draw",
"a",
"single",
"Minecraft",
"block",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java#L217-L225 |
23,045 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java | BlockDrawingHelper.DrawPrimitive | private void DrawPrimitive( DrawSphere s, World w ) throws Exception
{
XMLBlockState blockType = new XMLBlockState(s.getType(), s.getColour(), null, s.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecognised block type: " + s.getType().value());
int radius = s.getRadius();
for( int x = s.getX() - radius; x <= s.getX() + radius; x++ )
{
for( int y = s.getY() - radius; y <= s.getY() + radius; y++ )
{
for( int z = s.getZ() - radius; z <= s.getZ() + radius; z++ )
{
if ((z - s.getZ()) * (z - s.getZ()) + (y - s.getY()) * (y - s.getY()) + (x - s.getX()) * (x - s.getX()) <= (radius*radius))
{
BlockPos pos = new BlockPos( x, y, z );
setBlockState( w, pos, blockType );
AxisAlignedBB aabb = new AxisAlignedBB(pos, new BlockPos(x+1, y+1, z+1));
clearEntities(w, aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
}
}
}
}
} | java | private void DrawPrimitive( DrawSphere s, World w ) throws Exception
{
XMLBlockState blockType = new XMLBlockState(s.getType(), s.getColour(), null, s.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecognised block type: " + s.getType().value());
int radius = s.getRadius();
for( int x = s.getX() - radius; x <= s.getX() + radius; x++ )
{
for( int y = s.getY() - radius; y <= s.getY() + radius; y++ )
{
for( int z = s.getZ() - radius; z <= s.getZ() + radius; z++ )
{
if ((z - s.getZ()) * (z - s.getZ()) + (y - s.getY()) * (y - s.getY()) + (x - s.getX()) * (x - s.getX()) <= (radius*radius))
{
BlockPos pos = new BlockPos( x, y, z );
setBlockState( w, pos, blockType );
AxisAlignedBB aabb = new AxisAlignedBB(pos, new BlockPos(x+1, y+1, z+1));
clearEntities(w, aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
}
}
}
}
} | [
"private",
"void",
"DrawPrimitive",
"(",
"DrawSphere",
"s",
",",
"World",
"w",
")",
"throws",
"Exception",
"{",
"XMLBlockState",
"blockType",
"=",
"new",
"XMLBlockState",
"(",
"s",
".",
"getType",
"(",
")",
",",
"s",
".",
"getColour",
"(",
")",
",",
"null",
",",
"s",
".",
"getVariant",
"(",
")",
")",
";",
"if",
"(",
"!",
"blockType",
".",
"isValid",
"(",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Unrecognised block type: \"",
"+",
"s",
".",
"getType",
"(",
")",
".",
"value",
"(",
")",
")",
";",
"int",
"radius",
"=",
"s",
".",
"getRadius",
"(",
")",
";",
"for",
"(",
"int",
"x",
"=",
"s",
".",
"getX",
"(",
")",
"-",
"radius",
";",
"x",
"<=",
"s",
".",
"getX",
"(",
")",
"+",
"radius",
";",
"x",
"++",
")",
"{",
"for",
"(",
"int",
"y",
"=",
"s",
".",
"getY",
"(",
")",
"-",
"radius",
";",
"y",
"<=",
"s",
".",
"getY",
"(",
")",
"+",
"radius",
";",
"y",
"++",
")",
"{",
"for",
"(",
"int",
"z",
"=",
"s",
".",
"getZ",
"(",
")",
"-",
"radius",
";",
"z",
"<=",
"s",
".",
"getZ",
"(",
")",
"+",
"radius",
";",
"z",
"++",
")",
"{",
"if",
"(",
"(",
"z",
"-",
"s",
".",
"getZ",
"(",
")",
")",
"*",
"(",
"z",
"-",
"s",
".",
"getZ",
"(",
")",
")",
"+",
"(",
"y",
"-",
"s",
".",
"getY",
"(",
")",
")",
"*",
"(",
"y",
"-",
"s",
".",
"getY",
"(",
")",
")",
"+",
"(",
"x",
"-",
"s",
".",
"getX",
"(",
")",
")",
"*",
"(",
"x",
"-",
"s",
".",
"getX",
"(",
")",
")",
"<=",
"(",
"radius",
"*",
"radius",
")",
")",
"{",
"BlockPos",
"pos",
"=",
"new",
"BlockPos",
"(",
"x",
",",
"y",
",",
"z",
")",
";",
"setBlockState",
"(",
"w",
",",
"pos",
",",
"blockType",
")",
";",
"AxisAlignedBB",
"aabb",
"=",
"new",
"AxisAlignedBB",
"(",
"pos",
",",
"new",
"BlockPos",
"(",
"x",
"+",
"1",
",",
"y",
"+",
"1",
",",
"z",
"+",
"1",
")",
")",
";",
"clearEntities",
"(",
"w",
",",
"aabb",
".",
"minX",
",",
"aabb",
".",
"minY",
",",
"aabb",
".",
"minZ",
",",
"aabb",
".",
"maxX",
",",
"aabb",
".",
"maxY",
",",
"aabb",
".",
"maxZ",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Draw a solid sphere made up of Minecraft blocks.
@param s Contains information about the sphere to be drawn.
@param w The world in which to draw.
@throws Exception Throws an exception if the block type is not recognised. | [
"Draw",
"a",
"solid",
"sphere",
"made",
"up",
"of",
"Minecraft",
"blocks",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java#L248-L271 |
23,046 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java | BlockDrawingHelper.DrawPrimitive | private void DrawPrimitive( DrawEntity e, World w ) throws Exception
{
String oldEntityName = e.getType().getValue();
String id = null;
for (EntityEntry ent : net.minecraftforge.fml.common.registry.ForgeRegistries.ENTITIES)
{
if (ent.getName().equals(oldEntityName))
{
id = ent.getRegistryName().toString();
break;
}
}
if (id == null)
return;
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setString("id", id);
nbttagcompound.setBoolean("PersistenceRequired", true); // Don't let this entity despawn
Entity entity;
try
{
entity = EntityList.createEntityFromNBT(nbttagcompound, w);
if (entity != null)
{
positionEntity(entity, e.getX().doubleValue(), e.getY().doubleValue(), e.getZ().doubleValue(), e.getYaw().floatValue(), e.getPitch().floatValue());
entity.setVelocity(e.getXVel().doubleValue(), e.getYVel().doubleValue(), e.getZVel().doubleValue());
// Set all the yaw values imaginable:
if (entity instanceof EntityLivingBase)
{
((EntityLivingBase)entity).rotationYaw = e.getYaw().floatValue();
((EntityLivingBase)entity).prevRotationYaw = e.getYaw().floatValue();
((EntityLivingBase)entity).prevRotationYawHead = e.getYaw().floatValue();
((EntityLivingBase)entity).rotationYawHead = e.getYaw().floatValue();
((EntityLivingBase)entity).prevRenderYawOffset = e.getYaw().floatValue();
((EntityLivingBase)entity).renderYawOffset = e.getYaw().floatValue();
}
w.getBlockState(entity.getPosition()); // Force-load the chunk if necessary, to ensure spawnEntity will work.
if (!w.spawnEntity(entity))
{
System.out.println("WARNING: Failed to spawn entity! Chunk not loaded?");
}
}
}
catch (RuntimeException runtimeexception)
{
// Cannot summon this entity.
throw new Exception("Couldn't create entity type: " + e.getType().getValue());
}
} | java | private void DrawPrimitive( DrawEntity e, World w ) throws Exception
{
String oldEntityName = e.getType().getValue();
String id = null;
for (EntityEntry ent : net.minecraftforge.fml.common.registry.ForgeRegistries.ENTITIES)
{
if (ent.getName().equals(oldEntityName))
{
id = ent.getRegistryName().toString();
break;
}
}
if (id == null)
return;
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setString("id", id);
nbttagcompound.setBoolean("PersistenceRequired", true); // Don't let this entity despawn
Entity entity;
try
{
entity = EntityList.createEntityFromNBT(nbttagcompound, w);
if (entity != null)
{
positionEntity(entity, e.getX().doubleValue(), e.getY().doubleValue(), e.getZ().doubleValue(), e.getYaw().floatValue(), e.getPitch().floatValue());
entity.setVelocity(e.getXVel().doubleValue(), e.getYVel().doubleValue(), e.getZVel().doubleValue());
// Set all the yaw values imaginable:
if (entity instanceof EntityLivingBase)
{
((EntityLivingBase)entity).rotationYaw = e.getYaw().floatValue();
((EntityLivingBase)entity).prevRotationYaw = e.getYaw().floatValue();
((EntityLivingBase)entity).prevRotationYawHead = e.getYaw().floatValue();
((EntityLivingBase)entity).rotationYawHead = e.getYaw().floatValue();
((EntityLivingBase)entity).prevRenderYawOffset = e.getYaw().floatValue();
((EntityLivingBase)entity).renderYawOffset = e.getYaw().floatValue();
}
w.getBlockState(entity.getPosition()); // Force-load the chunk if necessary, to ensure spawnEntity will work.
if (!w.spawnEntity(entity))
{
System.out.println("WARNING: Failed to spawn entity! Chunk not loaded?");
}
}
}
catch (RuntimeException runtimeexception)
{
// Cannot summon this entity.
throw new Exception("Couldn't create entity type: " + e.getType().getValue());
}
} | [
"private",
"void",
"DrawPrimitive",
"(",
"DrawEntity",
"e",
",",
"World",
"w",
")",
"throws",
"Exception",
"{",
"String",
"oldEntityName",
"=",
"e",
".",
"getType",
"(",
")",
".",
"getValue",
"(",
")",
";",
"String",
"id",
"=",
"null",
";",
"for",
"(",
"EntityEntry",
"ent",
":",
"net",
".",
"minecraftforge",
".",
"fml",
".",
"common",
".",
"registry",
".",
"ForgeRegistries",
".",
"ENTITIES",
")",
"{",
"if",
"(",
"ent",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"oldEntityName",
")",
")",
"{",
"id",
"=",
"ent",
".",
"getRegistryName",
"(",
")",
".",
"toString",
"(",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"id",
"==",
"null",
")",
"return",
";",
"NBTTagCompound",
"nbttagcompound",
"=",
"new",
"NBTTagCompound",
"(",
")",
";",
"nbttagcompound",
".",
"setString",
"(",
"\"id\"",
",",
"id",
")",
";",
"nbttagcompound",
".",
"setBoolean",
"(",
"\"PersistenceRequired\"",
",",
"true",
")",
";",
"// Don't let this entity despawn",
"Entity",
"entity",
";",
"try",
"{",
"entity",
"=",
"EntityList",
".",
"createEntityFromNBT",
"(",
"nbttagcompound",
",",
"w",
")",
";",
"if",
"(",
"entity",
"!=",
"null",
")",
"{",
"positionEntity",
"(",
"entity",
",",
"e",
".",
"getX",
"(",
")",
".",
"doubleValue",
"(",
")",
",",
"e",
".",
"getY",
"(",
")",
".",
"doubleValue",
"(",
")",
",",
"e",
".",
"getZ",
"(",
")",
".",
"doubleValue",
"(",
")",
",",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
",",
"e",
".",
"getPitch",
"(",
")",
".",
"floatValue",
"(",
")",
")",
";",
"entity",
".",
"setVelocity",
"(",
"e",
".",
"getXVel",
"(",
")",
".",
"doubleValue",
"(",
")",
",",
"e",
".",
"getYVel",
"(",
")",
".",
"doubleValue",
"(",
")",
",",
"e",
".",
"getZVel",
"(",
")",
".",
"doubleValue",
"(",
")",
")",
";",
"// Set all the yaw values imaginable:",
"if",
"(",
"entity",
"instanceof",
"EntityLivingBase",
")",
"{",
"(",
"(",
"EntityLivingBase",
")",
"entity",
")",
".",
"rotationYaw",
"=",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"(",
"(",
"EntityLivingBase",
")",
"entity",
")",
".",
"prevRotationYaw",
"=",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"(",
"(",
"EntityLivingBase",
")",
"entity",
")",
".",
"prevRotationYawHead",
"=",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"(",
"(",
"EntityLivingBase",
")",
"entity",
")",
".",
"rotationYawHead",
"=",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"(",
"(",
"EntityLivingBase",
")",
"entity",
")",
".",
"prevRenderYawOffset",
"=",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"(",
"(",
"EntityLivingBase",
")",
"entity",
")",
".",
"renderYawOffset",
"=",
"e",
".",
"getYaw",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"}",
"w",
".",
"getBlockState",
"(",
"entity",
".",
"getPosition",
"(",
")",
")",
";",
"// Force-load the chunk if necessary, to ensure spawnEntity will work.",
"if",
"(",
"!",
"w",
".",
"spawnEntity",
"(",
"entity",
")",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"WARNING: Failed to spawn entity! Chunk not loaded?\"",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"RuntimeException",
"runtimeexception",
")",
"{",
"// Cannot summon this entity.",
"throw",
"new",
"Exception",
"(",
"\"Couldn't create entity type: \"",
"+",
"e",
".",
"getType",
"(",
")",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}"
] | Spawn a single entity at the specified position.
@param e the actual entity to be spawned.
@param w the world in which to spawn the entity.
@throws Exception | [
"Spawn",
"a",
"single",
"entity",
"at",
"the",
"specified",
"position",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java#L360-L408 |
23,047 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java | BlockDrawingHelper.DrawPrimitive | private void DrawPrimitive( DrawCuboid c, World w ) throws Exception
{
XMLBlockState blockType = new XMLBlockState(c.getType(), c.getColour(), c.getFace(), c.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecogised item type: "+c.getType().value());
int x1 = Math.min(c.getX1(), c.getX2());
int x2 = Math.max(c.getX1(), c.getX2());
int y1 = Math.min(c.getY1(), c.getY2());
int y2 = Math.max(c.getY1(), c.getY2());
int z1 = Math.min(c.getZ1(), c.getZ2());
int z2 = Math.max(c.getZ1(), c.getZ2());
clearEntities(w, x1, y1, z1, x2 + 1, y2 + 1, z2 + 1);
for( int x = x1; x <= x2; x++ ) {
for( int y = y1; y <= y2; y++ ) {
for( int z = z1; z <= z2; z++ ) {
BlockPos pos = new BlockPos(x, y, z);
setBlockState(w, pos, blockType);
}
}
}
} | java | private void DrawPrimitive( DrawCuboid c, World w ) throws Exception
{
XMLBlockState blockType = new XMLBlockState(c.getType(), c.getColour(), c.getFace(), c.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecogised item type: "+c.getType().value());
int x1 = Math.min(c.getX1(), c.getX2());
int x2 = Math.max(c.getX1(), c.getX2());
int y1 = Math.min(c.getY1(), c.getY2());
int y2 = Math.max(c.getY1(), c.getY2());
int z1 = Math.min(c.getZ1(), c.getZ2());
int z2 = Math.max(c.getZ1(), c.getZ2());
clearEntities(w, x1, y1, z1, x2 + 1, y2 + 1, z2 + 1);
for( int x = x1; x <= x2; x++ ) {
for( int y = y1; y <= y2; y++ ) {
for( int z = z1; z <= z2; z++ ) {
BlockPos pos = new BlockPos(x, y, z);
setBlockState(w, pos, blockType);
}
}
}
} | [
"private",
"void",
"DrawPrimitive",
"(",
"DrawCuboid",
"c",
",",
"World",
"w",
")",
"throws",
"Exception",
"{",
"XMLBlockState",
"blockType",
"=",
"new",
"XMLBlockState",
"(",
"c",
".",
"getType",
"(",
")",
",",
"c",
".",
"getColour",
"(",
")",
",",
"c",
".",
"getFace",
"(",
")",
",",
"c",
".",
"getVariant",
"(",
")",
")",
";",
"if",
"(",
"!",
"blockType",
".",
"isValid",
"(",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Unrecogised item type: \"",
"+",
"c",
".",
"getType",
"(",
")",
".",
"value",
"(",
")",
")",
";",
"int",
"x1",
"=",
"Math",
".",
"min",
"(",
"c",
".",
"getX1",
"(",
")",
",",
"c",
".",
"getX2",
"(",
")",
")",
";",
"int",
"x2",
"=",
"Math",
".",
"max",
"(",
"c",
".",
"getX1",
"(",
")",
",",
"c",
".",
"getX2",
"(",
")",
")",
";",
"int",
"y1",
"=",
"Math",
".",
"min",
"(",
"c",
".",
"getY1",
"(",
")",
",",
"c",
".",
"getY2",
"(",
")",
")",
";",
"int",
"y2",
"=",
"Math",
".",
"max",
"(",
"c",
".",
"getY1",
"(",
")",
",",
"c",
".",
"getY2",
"(",
")",
")",
";",
"int",
"z1",
"=",
"Math",
".",
"min",
"(",
"c",
".",
"getZ1",
"(",
")",
",",
"c",
".",
"getZ2",
"(",
")",
")",
";",
"int",
"z2",
"=",
"Math",
".",
"max",
"(",
"c",
".",
"getZ1",
"(",
")",
",",
"c",
".",
"getZ2",
"(",
")",
")",
";",
"clearEntities",
"(",
"w",
",",
"x1",
",",
"y1",
",",
"z1",
",",
"x2",
"+",
"1",
",",
"y2",
"+",
"1",
",",
"z2",
"+",
"1",
")",
";",
"for",
"(",
"int",
"x",
"=",
"x1",
";",
"x",
"<=",
"x2",
";",
"x",
"++",
")",
"{",
"for",
"(",
"int",
"y",
"=",
"y1",
";",
"y",
"<=",
"y2",
";",
"y",
"++",
")",
"{",
"for",
"(",
"int",
"z",
"=",
"z1",
";",
"z",
"<=",
"z2",
";",
"z",
"++",
")",
"{",
"BlockPos",
"pos",
"=",
"new",
"BlockPos",
"(",
"x",
",",
"y",
",",
"z",
")",
";",
"setBlockState",
"(",
"w",
",",
"pos",
",",
"blockType",
")",
";",
"}",
"}",
"}",
"}"
] | Draw a filled cuboid of Minecraft blocks of a single type.
@param c Contains information about the cuboid to be drawn.
@param w The world in which to draw.
@throws Exception Throws an exception if the block type is not recognised. | [
"Draw",
"a",
"filled",
"cuboid",
"of",
"Minecraft",
"blocks",
"of",
"a",
"single",
"type",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/BlockDrawingHelper.java#L513-L536 |
23,048 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/TCPUtils.java | TCPUtils.getSocketInRange | public static ServerSocket getSocketInRange(int minPort, int maxPort, boolean random)
{
TCPUtils.Log(Level.INFO, "Attempting to create a ServerSocket in range (" + minPort + "-" + maxPort + (random ? ") at random..." : ") sequentially..."));
ServerSocket s = null;
int port = minPort - 1;
Random r = new Random(System.currentTimeMillis());
while (s == null && port <= maxPort)
{
if (random)
port = minPort + r.nextInt(maxPort - minPort);
else
port++;
try
{
TCPUtils.Log(Level.INFO, " - trying " + port + "...");
s = new ServerSocket(port);
TCPUtils.Log(Level.INFO, "Succeeded!");
return s; // Created okay, so this port is available.
}
catch (IOException e)
{
// Try the next port.
TCPUtils.Log(Level.INFO, " - failed: " + e);
}
}
TCPUtils.Log(Level.SEVERE, "Could find no available port!");
return null; // No port found in the allowed range.
} | java | public static ServerSocket getSocketInRange(int minPort, int maxPort, boolean random)
{
TCPUtils.Log(Level.INFO, "Attempting to create a ServerSocket in range (" + minPort + "-" + maxPort + (random ? ") at random..." : ") sequentially..."));
ServerSocket s = null;
int port = minPort - 1;
Random r = new Random(System.currentTimeMillis());
while (s == null && port <= maxPort)
{
if (random)
port = minPort + r.nextInt(maxPort - minPort);
else
port++;
try
{
TCPUtils.Log(Level.INFO, " - trying " + port + "...");
s = new ServerSocket(port);
TCPUtils.Log(Level.INFO, "Succeeded!");
return s; // Created okay, so this port is available.
}
catch (IOException e)
{
// Try the next port.
TCPUtils.Log(Level.INFO, " - failed: " + e);
}
}
TCPUtils.Log(Level.SEVERE, "Could find no available port!");
return null; // No port found in the allowed range.
} | [
"public",
"static",
"ServerSocket",
"getSocketInRange",
"(",
"int",
"minPort",
",",
"int",
"maxPort",
",",
"boolean",
"random",
")",
"{",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"INFO",
",",
"\"Attempting to create a ServerSocket in range (\"",
"+",
"minPort",
"+",
"\"-\"",
"+",
"maxPort",
"+",
"(",
"random",
"?",
"\") at random...\"",
":",
"\") sequentially...\"",
")",
")",
";",
"ServerSocket",
"s",
"=",
"null",
";",
"int",
"port",
"=",
"minPort",
"-",
"1",
";",
"Random",
"r",
"=",
"new",
"Random",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"while",
"(",
"s",
"==",
"null",
"&&",
"port",
"<=",
"maxPort",
")",
"{",
"if",
"(",
"random",
")",
"port",
"=",
"minPort",
"+",
"r",
".",
"nextInt",
"(",
"maxPort",
"-",
"minPort",
")",
";",
"else",
"port",
"++",
";",
"try",
"{",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"INFO",
",",
"\" - trying \"",
"+",
"port",
"+",
"\"...\"",
")",
";",
"s",
"=",
"new",
"ServerSocket",
"(",
"port",
")",
";",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"INFO",
",",
"\"Succeeded!\"",
")",
";",
"return",
"s",
";",
"// Created okay, so this port is available.",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"// Try the next port.",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"INFO",
",",
"\" - failed: \"",
"+",
"e",
")",
";",
"}",
"}",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"SEVERE",
",",
"\"Could find no available port!\"",
")",
";",
"return",
"null",
";",
"// No port found in the allowed range.",
"}"
] | Choose a port from the specified range - either sequentially, or at random.
@param minPort minimum (inclusive) value for port.
@param maxPort max (inclusive) possible port value.
@param random true to allocate based on a random sample; false to allocate sequentially, starting from minPort.
@return a ServerSocket. | [
"Choose",
"a",
"port",
"from",
"the",
"specified",
"range",
"-",
"either",
"sequentially",
"or",
"at",
"random",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/TCPUtils.java#L175-L202 |
23,049 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/PositionHelper.java | PositionHelper.calcDistanceFromPlayerToPosition | public static float calcDistanceFromPlayerToPosition(EntityPlayerSP player, Pos targetPos)
{
double x = player.posX - targetPos.getX().doubleValue();
double y = player.posY - targetPos.getY().doubleValue();
double z = player.posZ - targetPos.getZ().doubleValue();
return (float)Math.sqrt(x*x + y*y + z*z);
} | java | public static float calcDistanceFromPlayerToPosition(EntityPlayerSP player, Pos targetPos)
{
double x = player.posX - targetPos.getX().doubleValue();
double y = player.posY - targetPos.getY().doubleValue();
double z = player.posZ - targetPos.getZ().doubleValue();
return (float)Math.sqrt(x*x + y*y + z*z);
} | [
"public",
"static",
"float",
"calcDistanceFromPlayerToPosition",
"(",
"EntityPlayerSP",
"player",
",",
"Pos",
"targetPos",
")",
"{",
"double",
"x",
"=",
"player",
".",
"posX",
"-",
"targetPos",
".",
"getX",
"(",
")",
".",
"doubleValue",
"(",
")",
";",
"double",
"y",
"=",
"player",
".",
"posY",
"-",
"targetPos",
".",
"getY",
"(",
")",
".",
"doubleValue",
"(",
")",
";",
"double",
"z",
"=",
"player",
".",
"posZ",
"-",
"targetPos",
".",
"getZ",
"(",
")",
".",
"doubleValue",
"(",
")",
";",
"return",
"(",
"float",
")",
"Math",
".",
"sqrt",
"(",
"x",
"*",
"x",
"+",
"y",
"*",
"y",
"+",
"z",
"*",
"z",
")",
";",
"}"
] | Calculate the Euclidean distance between the player and the target position.
@param player the player whose distance from target we want to know
@param targetPos the target position, specified as a Schema pos object
@return a float containing the Euclidean distance 'twixt player and target | [
"Calculate",
"the",
"Euclidean",
"distance",
"between",
"the",
"player",
"and",
"the",
"target",
"position",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/PositionHelper.java#L39-L45 |
23,050 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/CommandForWheeledRobotNavigationImplementation.java | CommandForWheeledRobotNavigationImplementation.updateState | protected boolean updateState()
{
if (!overrideKeyboardInput)
{
return false; // Let the class do the default thing.
}
// Update movement:
mTicksSinceLastVelocityChange++;
if (mTicksSinceLastVelocityChange <= mInertiaTicks)
{
mVelocity += (mTargetVelocity - mVelocity) * ((float)mTicksSinceLastVelocityChange/(float)mInertiaTicks);
}
else
{
mVelocity = mTargetVelocity;
}
this.overrideMovement.moveForward = mVelocity;
// This code comes from the Minecraft MovementInput superclass - needed so as not to give the bot an unfair
// advantage when sneaking!
if (this.overrideMovement.sneak)
{
this.overrideMovement.moveStrafe = (float)((double)this.overrideMovement.moveStrafe * 0.3D);
this.overrideMovement.moveForward = (float)((double)this.overrideMovement.moveForward * 0.3D);
}
updateYawAndPitch();
return true;
} | java | protected boolean updateState()
{
if (!overrideKeyboardInput)
{
return false; // Let the class do the default thing.
}
// Update movement:
mTicksSinceLastVelocityChange++;
if (mTicksSinceLastVelocityChange <= mInertiaTicks)
{
mVelocity += (mTargetVelocity - mVelocity) * ((float)mTicksSinceLastVelocityChange/(float)mInertiaTicks);
}
else
{
mVelocity = mTargetVelocity;
}
this.overrideMovement.moveForward = mVelocity;
// This code comes from the Minecraft MovementInput superclass - needed so as not to give the bot an unfair
// advantage when sneaking!
if (this.overrideMovement.sneak)
{
this.overrideMovement.moveStrafe = (float)((double)this.overrideMovement.moveStrafe * 0.3D);
this.overrideMovement.moveForward = (float)((double)this.overrideMovement.moveForward * 0.3D);
}
updateYawAndPitch();
return true;
} | [
"protected",
"boolean",
"updateState",
"(",
")",
"{",
"if",
"(",
"!",
"overrideKeyboardInput",
")",
"{",
"return",
"false",
";",
"// Let the class do the default thing.",
"}",
"// Update movement:",
"mTicksSinceLastVelocityChange",
"++",
";",
"if",
"(",
"mTicksSinceLastVelocityChange",
"<=",
"mInertiaTicks",
")",
"{",
"mVelocity",
"+=",
"(",
"mTargetVelocity",
"-",
"mVelocity",
")",
"*",
"(",
"(",
"float",
")",
"mTicksSinceLastVelocityChange",
"/",
"(",
"float",
")",
"mInertiaTicks",
")",
";",
"}",
"else",
"{",
"mVelocity",
"=",
"mTargetVelocity",
";",
"}",
"this",
".",
"overrideMovement",
".",
"moveForward",
"=",
"mVelocity",
";",
"// This code comes from the Minecraft MovementInput superclass - needed so as not to give the bot an unfair",
"// advantage when sneaking!",
"if",
"(",
"this",
".",
"overrideMovement",
".",
"sneak",
")",
"{",
"this",
".",
"overrideMovement",
".",
"moveStrafe",
"=",
"(",
"float",
")",
"(",
"(",
"double",
")",
"this",
".",
"overrideMovement",
".",
"moveStrafe",
"*",
"0.3D",
")",
";",
"this",
".",
"overrideMovement",
".",
"moveForward",
"=",
"(",
"float",
")",
"(",
"(",
"double",
")",
"this",
".",
"overrideMovement",
".",
"moveForward",
"*",
"0.3D",
")",
";",
"}",
"updateYawAndPitch",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Called by our overridden MovementInputFromOptions class.
@return true if we've handled the movement; false if the MovementInputFromOptions class should delegate to the default handling. | [
"Called",
"by",
"our",
"overridden",
"MovementInputFromOptions",
"class",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/CommandForWheeledRobotNavigationImplementation.java#L146-L174 |
23,051 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/QuitFromComposite.java | QuitFromComposite.addQuitter | public void addQuitter(IWantToQuit quitter)
{
if (this.quitters == null)
{
this.quitters = new ArrayList<IWantToQuit>();
}
this.quitters.add(quitter);
} | java | public void addQuitter(IWantToQuit quitter)
{
if (this.quitters == null)
{
this.quitters = new ArrayList<IWantToQuit>();
}
this.quitters.add(quitter);
} | [
"public",
"void",
"addQuitter",
"(",
"IWantToQuit",
"quitter",
")",
"{",
"if",
"(",
"this",
".",
"quitters",
"==",
"null",
")",
"{",
"this",
".",
"quitters",
"=",
"new",
"ArrayList",
"<",
"IWantToQuit",
">",
"(",
")",
";",
"}",
"this",
".",
"quitters",
".",
"add",
"(",
"quitter",
")",
";",
"}"
] | Add another IWantToQuit object to the children.
@param quitter the IWantToQuit object. | [
"Add",
"another",
"IWantToQuit",
"object",
"to",
"the",
"children",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/QuitFromComposite.java#L58-L65 |
23,052 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java | VideoHook.start | public void start(MissionInit missionInit, IVideoProducer videoProducer, VideoProducedObserver observer, MalmoEnvServer envServer)
{
if (videoProducer == null)
{
return; // Don't start up if there is nothing to provide the video.
}
videoProducer.prepare(missionInit);
this.missionInit = missionInit;
this.videoProducer = videoProducer;
this.observer = observer;
this.envServer = envServer;
this.buffer = BufferUtils.createByteBuffer(this.videoProducer.getRequiredBufferSize());
this.headerbuffer = ByteBuffer.allocate(20).order(ByteOrder.BIG_ENDIAN);
this.renderWidth = videoProducer.getWidth();
this.renderHeight = videoProducer.getHeight();
resizeIfNeeded();
Display.setResizable(false); // prevent the user from resizing using the window borders
ClientAgentConnection cac = missionInit.getClientAgentConnection();
if (cac == null)
return; // Don't start up if we don't have any connection details.
String agentIPAddress = cac.getAgentIPAddress();
int agentPort = 0;
switch (videoProducer.getVideoType())
{
case LUMINANCE:
agentPort = cac.getAgentLuminancePort();
break;
case DEPTH_MAP:
agentPort = cac.getAgentDepthPort();
break;
case VIDEO:
agentPort = cac.getAgentVideoPort();
break;
case COLOUR_MAP:
agentPort = cac.getAgentColourMapPort();
break;
}
this.connection = new TCPSocketChannel(agentIPAddress, agentPort, "vid");
this.failedTCPSendCount = 0;
try
{
MinecraftForge.EVENT_BUS.register(this);
}
catch(Exception e)
{
System.out.println("Failed to register video hook: " + e);
}
this.isRunning = true;
} | java | public void start(MissionInit missionInit, IVideoProducer videoProducer, VideoProducedObserver observer, MalmoEnvServer envServer)
{
if (videoProducer == null)
{
return; // Don't start up if there is nothing to provide the video.
}
videoProducer.prepare(missionInit);
this.missionInit = missionInit;
this.videoProducer = videoProducer;
this.observer = observer;
this.envServer = envServer;
this.buffer = BufferUtils.createByteBuffer(this.videoProducer.getRequiredBufferSize());
this.headerbuffer = ByteBuffer.allocate(20).order(ByteOrder.BIG_ENDIAN);
this.renderWidth = videoProducer.getWidth();
this.renderHeight = videoProducer.getHeight();
resizeIfNeeded();
Display.setResizable(false); // prevent the user from resizing using the window borders
ClientAgentConnection cac = missionInit.getClientAgentConnection();
if (cac == null)
return; // Don't start up if we don't have any connection details.
String agentIPAddress = cac.getAgentIPAddress();
int agentPort = 0;
switch (videoProducer.getVideoType())
{
case LUMINANCE:
agentPort = cac.getAgentLuminancePort();
break;
case DEPTH_MAP:
agentPort = cac.getAgentDepthPort();
break;
case VIDEO:
agentPort = cac.getAgentVideoPort();
break;
case COLOUR_MAP:
agentPort = cac.getAgentColourMapPort();
break;
}
this.connection = new TCPSocketChannel(agentIPAddress, agentPort, "vid");
this.failedTCPSendCount = 0;
try
{
MinecraftForge.EVENT_BUS.register(this);
}
catch(Exception e)
{
System.out.println("Failed to register video hook: " + e);
}
this.isRunning = true;
} | [
"public",
"void",
"start",
"(",
"MissionInit",
"missionInit",
",",
"IVideoProducer",
"videoProducer",
",",
"VideoProducedObserver",
"observer",
",",
"MalmoEnvServer",
"envServer",
")",
"{",
"if",
"(",
"videoProducer",
"==",
"null",
")",
"{",
"return",
";",
"// Don't start up if there is nothing to provide the video.",
"}",
"videoProducer",
".",
"prepare",
"(",
"missionInit",
")",
";",
"this",
".",
"missionInit",
"=",
"missionInit",
";",
"this",
".",
"videoProducer",
"=",
"videoProducer",
";",
"this",
".",
"observer",
"=",
"observer",
";",
"this",
".",
"envServer",
"=",
"envServer",
";",
"this",
".",
"buffer",
"=",
"BufferUtils",
".",
"createByteBuffer",
"(",
"this",
".",
"videoProducer",
".",
"getRequiredBufferSize",
"(",
")",
")",
";",
"this",
".",
"headerbuffer",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"20",
")",
".",
"order",
"(",
"ByteOrder",
".",
"BIG_ENDIAN",
")",
";",
"this",
".",
"renderWidth",
"=",
"videoProducer",
".",
"getWidth",
"(",
")",
";",
"this",
".",
"renderHeight",
"=",
"videoProducer",
".",
"getHeight",
"(",
")",
";",
"resizeIfNeeded",
"(",
")",
";",
"Display",
".",
"setResizable",
"(",
"false",
")",
";",
"// prevent the user from resizing using the window borders",
"ClientAgentConnection",
"cac",
"=",
"missionInit",
".",
"getClientAgentConnection",
"(",
")",
";",
"if",
"(",
"cac",
"==",
"null",
")",
"return",
";",
"// Don't start up if we don't have any connection details.",
"String",
"agentIPAddress",
"=",
"cac",
".",
"getAgentIPAddress",
"(",
")",
";",
"int",
"agentPort",
"=",
"0",
";",
"switch",
"(",
"videoProducer",
".",
"getVideoType",
"(",
")",
")",
"{",
"case",
"LUMINANCE",
":",
"agentPort",
"=",
"cac",
".",
"getAgentLuminancePort",
"(",
")",
";",
"break",
";",
"case",
"DEPTH_MAP",
":",
"agentPort",
"=",
"cac",
".",
"getAgentDepthPort",
"(",
")",
";",
"break",
";",
"case",
"VIDEO",
":",
"agentPort",
"=",
"cac",
".",
"getAgentVideoPort",
"(",
")",
";",
"break",
";",
"case",
"COLOUR_MAP",
":",
"agentPort",
"=",
"cac",
".",
"getAgentColourMapPort",
"(",
")",
";",
"break",
";",
"}",
"this",
".",
"connection",
"=",
"new",
"TCPSocketChannel",
"(",
"agentIPAddress",
",",
"agentPort",
",",
"\"vid\"",
")",
";",
"this",
".",
"failedTCPSendCount",
"=",
"0",
";",
"try",
"{",
"MinecraftForge",
".",
"EVENT_BUS",
".",
"register",
"(",
"this",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Failed to register video hook: \"",
"+",
"e",
")",
";",
"}",
"this",
".",
"isRunning",
"=",
"true",
";",
"}"
] | Resize the rendering and start sending video over TCP. | [
"Resize",
"the",
"rendering",
"and",
"start",
"sending",
"video",
"over",
"TCP",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java#L115-L168 |
23,053 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java | VideoHook.resizeIfNeeded | private void resizeIfNeeded()
{
// resize the window if we need to
int oldRenderWidth = Display.getWidth();
int oldRenderHeight = Display.getHeight();
if( this.renderWidth == oldRenderWidth && this.renderHeight == oldRenderHeight )
return;
try {
int old_x = Display.getX();
int old_y = Display.getY();
Display.setLocation(old_x, old_y);
Display.setDisplayMode(new DisplayMode(this.renderWidth, this.renderHeight));
System.out.println("Resized the window");
} catch (LWJGLException e) {
System.out.println("Failed to resize the window!");
e.printStackTrace();
}
forceResize(this.renderWidth, this.renderHeight);
} | java | private void resizeIfNeeded()
{
// resize the window if we need to
int oldRenderWidth = Display.getWidth();
int oldRenderHeight = Display.getHeight();
if( this.renderWidth == oldRenderWidth && this.renderHeight == oldRenderHeight )
return;
try {
int old_x = Display.getX();
int old_y = Display.getY();
Display.setLocation(old_x, old_y);
Display.setDisplayMode(new DisplayMode(this.renderWidth, this.renderHeight));
System.out.println("Resized the window");
} catch (LWJGLException e) {
System.out.println("Failed to resize the window!");
e.printStackTrace();
}
forceResize(this.renderWidth, this.renderHeight);
} | [
"private",
"void",
"resizeIfNeeded",
"(",
")",
"{",
"// resize the window if we need to",
"int",
"oldRenderWidth",
"=",
"Display",
".",
"getWidth",
"(",
")",
";",
"int",
"oldRenderHeight",
"=",
"Display",
".",
"getHeight",
"(",
")",
";",
"if",
"(",
"this",
".",
"renderWidth",
"==",
"oldRenderWidth",
"&&",
"this",
".",
"renderHeight",
"==",
"oldRenderHeight",
")",
"return",
";",
"try",
"{",
"int",
"old_x",
"=",
"Display",
".",
"getX",
"(",
")",
";",
"int",
"old_y",
"=",
"Display",
".",
"getY",
"(",
")",
";",
"Display",
".",
"setLocation",
"(",
"old_x",
",",
"old_y",
")",
";",
"Display",
".",
"setDisplayMode",
"(",
"new",
"DisplayMode",
"(",
"this",
".",
"renderWidth",
",",
"this",
".",
"renderHeight",
")",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"Resized the window\"",
")",
";",
"}",
"catch",
"(",
"LWJGLException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Failed to resize the window!\"",
")",
";",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"forceResize",
"(",
"this",
".",
"renderWidth",
",",
"this",
".",
"renderHeight",
")",
";",
"}"
] | Resizes the window and the Minecraft rendering if necessary. Set renderWidth and renderHeight first. | [
"Resizes",
"the",
"window",
"and",
"the",
"Minecraft",
"rendering",
"if",
"necessary",
".",
"Set",
"renderWidth",
"and",
"renderHeight",
"first",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java#L173-L192 |
23,054 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java | VideoHook.stop | public void stop(MissionDiagnostics diags)
{
if( !this.isRunning )
{
return;
}
if (this.videoProducer != null)
this.videoProducer.cleanup();
// stop sending video frames
try
{
MinecraftForge.EVENT_BUS.unregister(this);
}
catch(Exception e)
{
System.out.println("Failed to unregister video hook: " + e);
}
// Close our TCP socket:
this.connection.close();
this.isRunning = false;
// allow the user to resize the window again
Display.setResizable(true);
// And fill in some diagnostic data:
if (diags != null)
{
VideoData vd = new VideoData();
vd.setFrameType(this.videoProducer.getVideoType().toString());
vd.setFramesSent((int) this.framesSent);
if (this.timeOfLastFrame == this.timeOfFirstFrame)
vd.setAverageFpsSent(new BigDecimal(0));
else
vd.setAverageFpsSent(new BigDecimal(1000.0 * this.framesSent / (this.timeOfLastFrame - this.timeOfFirstFrame)));
diags.getVideoData().add(vd);
}
} | java | public void stop(MissionDiagnostics diags)
{
if( !this.isRunning )
{
return;
}
if (this.videoProducer != null)
this.videoProducer.cleanup();
// stop sending video frames
try
{
MinecraftForge.EVENT_BUS.unregister(this);
}
catch(Exception e)
{
System.out.println("Failed to unregister video hook: " + e);
}
// Close our TCP socket:
this.connection.close();
this.isRunning = false;
// allow the user to resize the window again
Display.setResizable(true);
// And fill in some diagnostic data:
if (diags != null)
{
VideoData vd = new VideoData();
vd.setFrameType(this.videoProducer.getVideoType().toString());
vd.setFramesSent((int) this.framesSent);
if (this.timeOfLastFrame == this.timeOfFirstFrame)
vd.setAverageFpsSent(new BigDecimal(0));
else
vd.setAverageFpsSent(new BigDecimal(1000.0 * this.framesSent / (this.timeOfLastFrame - this.timeOfFirstFrame)));
diags.getVideoData().add(vd);
}
} | [
"public",
"void",
"stop",
"(",
"MissionDiagnostics",
"diags",
")",
"{",
"if",
"(",
"!",
"this",
".",
"isRunning",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"videoProducer",
"!=",
"null",
")",
"this",
".",
"videoProducer",
".",
"cleanup",
"(",
")",
";",
"// stop sending video frames",
"try",
"{",
"MinecraftForge",
".",
"EVENT_BUS",
".",
"unregister",
"(",
"this",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Failed to unregister video hook: \"",
"+",
"e",
")",
";",
"}",
"// Close our TCP socket:",
"this",
".",
"connection",
".",
"close",
"(",
")",
";",
"this",
".",
"isRunning",
"=",
"false",
";",
"// allow the user to resize the window again",
"Display",
".",
"setResizable",
"(",
"true",
")",
";",
"// And fill in some diagnostic data:",
"if",
"(",
"diags",
"!=",
"null",
")",
"{",
"VideoData",
"vd",
"=",
"new",
"VideoData",
"(",
")",
";",
"vd",
".",
"setFrameType",
"(",
"this",
".",
"videoProducer",
".",
"getVideoType",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"vd",
".",
"setFramesSent",
"(",
"(",
"int",
")",
"this",
".",
"framesSent",
")",
";",
"if",
"(",
"this",
".",
"timeOfLastFrame",
"==",
"this",
".",
"timeOfFirstFrame",
")",
"vd",
".",
"setAverageFpsSent",
"(",
"new",
"BigDecimal",
"(",
"0",
")",
")",
";",
"else",
"vd",
".",
"setAverageFpsSent",
"(",
"new",
"BigDecimal",
"(",
"1000.0",
"*",
"this",
".",
"framesSent",
"/",
"(",
"this",
".",
"timeOfLastFrame",
"-",
"this",
".",
"timeOfFirstFrame",
")",
")",
")",
";",
"diags",
".",
"getVideoData",
"(",
")",
".",
"add",
"(",
"vd",
")",
";",
"}",
"}"
] | Stop sending video. | [
"Stop",
"sending",
"video",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java#L197-L234 |
23,055 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java | VideoHook.forceResize | private void forceResize(int width, int height)
{
// Are we in the dev environment or deployed?
boolean devEnv = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
// We need to know, because the method name will either be obfuscated or not.
String resizeMethodName = devEnv ? "resize" : "func_71370_a";
Class[] cArgs = new Class[2];
cArgs[0] = int.class;
cArgs[1] = int.class;
Method resize;
try
{
resize = Minecraft.class.getDeclaredMethod(resizeMethodName, cArgs);
resize.setAccessible(true);
resize.invoke(Minecraft.getMinecraft(), width, height);
}
catch (NoSuchMethodException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (InvocationTargetException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} | java | private void forceResize(int width, int height)
{
// Are we in the dev environment or deployed?
boolean devEnv = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
// We need to know, because the method name will either be obfuscated or not.
String resizeMethodName = devEnv ? "resize" : "func_71370_a";
Class[] cArgs = new Class[2];
cArgs[0] = int.class;
cArgs[1] = int.class;
Method resize;
try
{
resize = Minecraft.class.getDeclaredMethod(resizeMethodName, cArgs);
resize.setAccessible(true);
resize.invoke(Minecraft.getMinecraft(), width, height);
}
catch (NoSuchMethodException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (InvocationTargetException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} | [
"private",
"void",
"forceResize",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"// Are we in the dev environment or deployed?",
"boolean",
"devEnv",
"=",
"(",
"Boolean",
")",
"Launch",
".",
"blackboard",
".",
"get",
"(",
"\"fml.deobfuscatedEnvironment\"",
")",
";",
"// We need to know, because the method name will either be obfuscated or not.",
"String",
"resizeMethodName",
"=",
"devEnv",
"?",
"\"resize\"",
":",
"\"func_71370_a\"",
";",
"Class",
"[",
"]",
"cArgs",
"=",
"new",
"Class",
"[",
"2",
"]",
";",
"cArgs",
"[",
"0",
"]",
"=",
"int",
".",
"class",
";",
"cArgs",
"[",
"1",
"]",
"=",
"int",
".",
"class",
";",
"Method",
"resize",
";",
"try",
"{",
"resize",
"=",
"Minecraft",
".",
"class",
".",
"getDeclaredMethod",
"(",
"resizeMethodName",
",",
"cArgs",
")",
";",
"resize",
".",
"setAccessible",
"(",
"true",
")",
";",
"resize",
".",
"invoke",
"(",
"Minecraft",
".",
"getMinecraft",
"(",
")",
",",
"width",
",",
"height",
")",
";",
"}",
"catch",
"(",
"NoSuchMethodException",
"e",
")",
"{",
"// TODO Auto-generated catch block",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"SecurityException",
"e",
")",
"{",
"// TODO Auto-generated catch block",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"// TODO Auto-generated catch block",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"// TODO Auto-generated catch block",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"InvocationTargetException",
"e",
")",
"{",
"// TODO Auto-generated catch block",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Force Minecraft to resize its GUI
@param width new width of window
@param height new height of window | [
"Force",
"Minecraft",
"to",
"resize",
"its",
"GUI"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/VideoHook.java#L356-L398 |
23,056 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.ParseBlockType | public static IBlockState ParseBlockType( String s )
{
if( s == null )
return null;
Block block = (Block)Block.REGISTRY.getObject(new ResourceLocation( s ));
if( block instanceof BlockAir && !s.equals("air") ) // Minecraft returns BlockAir when it doesn't recognise the string
return null; // unrecognised string
return block.getDefaultState();
} | java | public static IBlockState ParseBlockType( String s )
{
if( s == null )
return null;
Block block = (Block)Block.REGISTRY.getObject(new ResourceLocation( s ));
if( block instanceof BlockAir && !s.equals("air") ) // Minecraft returns BlockAir when it doesn't recognise the string
return null; // unrecognised string
return block.getDefaultState();
} | [
"public",
"static",
"IBlockState",
"ParseBlockType",
"(",
"String",
"s",
")",
"{",
"if",
"(",
"s",
"==",
"null",
")",
"return",
"null",
";",
"Block",
"block",
"=",
"(",
"Block",
")",
"Block",
".",
"REGISTRY",
".",
"getObject",
"(",
"new",
"ResourceLocation",
"(",
"s",
")",
")",
";",
"if",
"(",
"block",
"instanceof",
"BlockAir",
"&&",
"!",
"s",
".",
"equals",
"(",
"\"air\"",
")",
")",
"// Minecraft returns BlockAir when it doesn't recognise the string",
"return",
"null",
";",
"// unrecognised string",
"return",
"block",
".",
"getDefaultState",
"(",
")",
";",
"}"
] | Attempts to parse the block type string.
@param s The string to parse.
@return The block type, or null if the string is not recognised. | [
"Attempts",
"to",
"parse",
"the",
"block",
"type",
"string",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L68-L76 |
23,057 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.ParseItemType | public static Item ParseItemType( String s, boolean checkBlocks )
{
if (s == null)
return null;
Item item = (Item)Item.REGISTRY.getObject(new ResourceLocation(s)); // Minecraft returns null when it doesn't recognise the string
if (item == null && checkBlocks)
{
// Maybe this is a request for a block item?
IBlockState block = MinecraftTypeHelper.ParseBlockType(s);
item = (block != null && block.getBlock() != null) ? Item.getItemFromBlock(block.getBlock()) : null;
}
return item;
} | java | public static Item ParseItemType( String s, boolean checkBlocks )
{
if (s == null)
return null;
Item item = (Item)Item.REGISTRY.getObject(new ResourceLocation(s)); // Minecraft returns null when it doesn't recognise the string
if (item == null && checkBlocks)
{
// Maybe this is a request for a block item?
IBlockState block = MinecraftTypeHelper.ParseBlockType(s);
item = (block != null && block.getBlock() != null) ? Item.getItemFromBlock(block.getBlock()) : null;
}
return item;
} | [
"public",
"static",
"Item",
"ParseItemType",
"(",
"String",
"s",
",",
"boolean",
"checkBlocks",
")",
"{",
"if",
"(",
"s",
"==",
"null",
")",
"return",
"null",
";",
"Item",
"item",
"=",
"(",
"Item",
")",
"Item",
".",
"REGISTRY",
".",
"getObject",
"(",
"new",
"ResourceLocation",
"(",
"s",
")",
")",
";",
"// Minecraft returns null when it doesn't recognise the string",
"if",
"(",
"item",
"==",
"null",
"&&",
"checkBlocks",
")",
"{",
"// Maybe this is a request for a block item?",
"IBlockState",
"block",
"=",
"MinecraftTypeHelper",
".",
"ParseBlockType",
"(",
"s",
")",
";",
"item",
"=",
"(",
"block",
"!=",
"null",
"&&",
"block",
".",
"getBlock",
"(",
")",
"!=",
"null",
")",
"?",
"Item",
".",
"getItemFromBlock",
"(",
"block",
".",
"getBlock",
"(",
")",
")",
":",
"null",
";",
"}",
"return",
"item",
";",
"}"
] | Attempts to parse the item type string.
@param s The string to parse.
@param checkBlocks if string can't be parsed as an item, attempt to parse as a block, if checkBlocks is true
@return The item type, or null if the string is not recognised. | [
"Attempts",
"to",
"parse",
"the",
"item",
"type",
"string",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L84-L96 |
23,058 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.blockColourMatches | public static boolean blockColourMatches(IBlockState bs, List<Colour> allowedColours)
{
for (IProperty prop : bs.getProperties().keySet())
{
if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
{
// The block in question has a colour, so check it is a specified one:
net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)bs.getValue(prop);
for (Colour col : allowedColours)
{
if (current.getName().equalsIgnoreCase(col.name()))
return true;
}
}
}
return false;
} | java | public static boolean blockColourMatches(IBlockState bs, List<Colour> allowedColours)
{
for (IProperty prop : bs.getProperties().keySet())
{
if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
{
// The block in question has a colour, so check it is a specified one:
net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)bs.getValue(prop);
for (Colour col : allowedColours)
{
if (current.getName().equalsIgnoreCase(col.name()))
return true;
}
}
}
return false;
} | [
"public",
"static",
"boolean",
"blockColourMatches",
"(",
"IBlockState",
"bs",
",",
"List",
"<",
"Colour",
">",
"allowedColours",
")",
"{",
"for",
"(",
"IProperty",
"prop",
":",
"bs",
".",
"getProperties",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"prop",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"color\"",
")",
"&&",
"prop",
".",
"getValueClass",
"(",
")",
"==",
"net",
".",
"minecraft",
".",
"item",
".",
"EnumDyeColor",
".",
"class",
")",
"{",
"// The block in question has a colour, so check it is a specified one:",
"net",
".",
"minecraft",
".",
"item",
".",
"EnumDyeColor",
"current",
"=",
"(",
"net",
".",
"minecraft",
".",
"item",
".",
"EnumDyeColor",
")",
"bs",
".",
"getValue",
"(",
"prop",
")",
";",
"for",
"(",
"Colour",
"col",
":",
"allowedColours",
")",
"{",
"if",
"(",
"current",
".",
"getName",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"col",
".",
"name",
"(",
")",
")",
")",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Test whether this block has a colour attribute which matches the list of allowed colours
@param bs blockstate to test
@param allowedColours list of allowed Colour enum values
@return true if the block matches. | [
"Test",
"whether",
"this",
"block",
"has",
"a",
"colour",
"attribute",
"which",
"matches",
"the",
"list",
"of",
"allowed",
"colours"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L103-L119 |
23,059 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.blockVariantMatches | public static boolean blockVariantMatches(IBlockState bs, List<Variation> allowedVariants)
{
for (IProperty prop : bs.getProperties().keySet())
{
if (prop.getName().equals("variant") && prop.getValueClass().isEnum())
{
Object current = bs.getValue(prop);
if (current != null)
{
for (Variation var : allowedVariants)
{
if (var.getValue().equalsIgnoreCase(current.toString()))
return true;
}
}
}
}
return false;
} | java | public static boolean blockVariantMatches(IBlockState bs, List<Variation> allowedVariants)
{
for (IProperty prop : bs.getProperties().keySet())
{
if (prop.getName().equals("variant") && prop.getValueClass().isEnum())
{
Object current = bs.getValue(prop);
if (current != null)
{
for (Variation var : allowedVariants)
{
if (var.getValue().equalsIgnoreCase(current.toString()))
return true;
}
}
}
}
return false;
} | [
"public",
"static",
"boolean",
"blockVariantMatches",
"(",
"IBlockState",
"bs",
",",
"List",
"<",
"Variation",
">",
"allowedVariants",
")",
"{",
"for",
"(",
"IProperty",
"prop",
":",
"bs",
".",
"getProperties",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"prop",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"variant\"",
")",
"&&",
"prop",
".",
"getValueClass",
"(",
")",
".",
"isEnum",
"(",
")",
")",
"{",
"Object",
"current",
"=",
"bs",
".",
"getValue",
"(",
"prop",
")",
";",
"if",
"(",
"current",
"!=",
"null",
")",
"{",
"for",
"(",
"Variation",
"var",
":",
"allowedVariants",
")",
"{",
"if",
"(",
"var",
".",
"getValue",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"current",
".",
"toString",
"(",
")",
")",
")",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Test whether this block has a variant attribute which matches the list of allowed variants
@param bs the blockstate to test
@param allowedVariants list of allowed Variant enum values
@return true if the block matches. | [
"Test",
"whether",
"this",
"block",
"has",
"a",
"variant",
"attribute",
"which",
"matches",
"the",
"list",
"of",
"allowed",
"variants"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L126-L144 |
23,060 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.attemptToGetAsColour | public static Colour attemptToGetAsColour(String part)
{
String target = part.toUpperCase();
for (int i = 0; i < Colour.values().length; i++)
{
String col = Colour.values()[i].name().replace("_", "");
if (col.equals(target))
return Colour.values()[i];
}
return null;
} | java | public static Colour attemptToGetAsColour(String part)
{
String target = part.toUpperCase();
for (int i = 0; i < Colour.values().length; i++)
{
String col = Colour.values()[i].name().replace("_", "");
if (col.equals(target))
return Colour.values()[i];
}
return null;
} | [
"public",
"static",
"Colour",
"attemptToGetAsColour",
"(",
"String",
"part",
")",
"{",
"String",
"target",
"=",
"part",
".",
"toUpperCase",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"Colour",
".",
"values",
"(",
")",
".",
"length",
";",
"i",
"++",
")",
"{",
"String",
"col",
"=",
"Colour",
".",
"values",
"(",
")",
"[",
"i",
"]",
".",
"name",
"(",
")",
".",
"replace",
"(",
"\"_\"",
",",
"\"\"",
")",
";",
"if",
"(",
"col",
".",
"equals",
"(",
"target",
")",
")",
"return",
"Colour",
".",
"values",
"(",
")",
"[",
"i",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Attempt to parse string as a Colour
@param part string token to parse
@return the Colour enum value for the requested colour, or null if it wasn't valid. | [
"Attempt",
"to",
"parse",
"string",
"as",
"a",
"Colour"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L150-L160 |
23,061 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.attemptToGetAsVariant | public static Variation attemptToGetAsVariant(String part)
{
// Annoyingly JAXB won't bind Variation as an enum, so we have to do this manually.
// TODO - can we do something more clever... eg make StoneTypes, WoodTypes etc inherit from an XSD baseclass,
// and have an object in the schemas that returns a list, so we can just iterate...
try
{
StoneTypes var = StoneTypes.valueOf(part.toUpperCase());
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
WoodTypes var = WoodTypes.valueOf(part.toUpperCase());
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
FlowerTypes var = FlowerTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
EntityTypes var = EntityTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
MonsterEggTypes var = MonsterEggTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
ShapeTypes var = ShapeTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
HalfTypes var = HalfTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
return null;
} | java | public static Variation attemptToGetAsVariant(String part)
{
// Annoyingly JAXB won't bind Variation as an enum, so we have to do this manually.
// TODO - can we do something more clever... eg make StoneTypes, WoodTypes etc inherit from an XSD baseclass,
// and have an object in the schemas that returns a list, so we can just iterate...
try
{
StoneTypes var = StoneTypes.valueOf(part.toUpperCase());
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
WoodTypes var = WoodTypes.valueOf(part.toUpperCase());
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
FlowerTypes var = FlowerTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
EntityTypes var = EntityTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
MonsterEggTypes var = MonsterEggTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
ShapeTypes var = ShapeTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
try
{
HalfTypes var = HalfTypes.fromValue(part);
if (var != null)
{
Variation bv = new Variation();
bv.setValue(var.value());
return bv;
}
}
catch (Exception e)
{
// Does nothing.
}
return null;
} | [
"public",
"static",
"Variation",
"attemptToGetAsVariant",
"(",
"String",
"part",
")",
"{",
"// Annoyingly JAXB won't bind Variation as an enum, so we have to do this manually.",
"// TODO - can we do something more clever... eg make StoneTypes, WoodTypes etc inherit from an XSD baseclass,",
"// and have an object in the schemas that returns a list, so we can just iterate...",
"try",
"{",
"StoneTypes",
"var",
"=",
"StoneTypes",
".",
"valueOf",
"(",
"part",
".",
"toUpperCase",
"(",
")",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"try",
"{",
"WoodTypes",
"var",
"=",
"WoodTypes",
".",
"valueOf",
"(",
"part",
".",
"toUpperCase",
"(",
")",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"try",
"{",
"FlowerTypes",
"var",
"=",
"FlowerTypes",
".",
"fromValue",
"(",
"part",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"try",
"{",
"EntityTypes",
"var",
"=",
"EntityTypes",
".",
"fromValue",
"(",
"part",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"try",
"{",
"MonsterEggTypes",
"var",
"=",
"MonsterEggTypes",
".",
"fromValue",
"(",
"part",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"try",
"{",
"ShapeTypes",
"var",
"=",
"ShapeTypes",
".",
"fromValue",
"(",
"part",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"try",
"{",
"HalfTypes",
"var",
"=",
"HalfTypes",
".",
"fromValue",
"(",
"part",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"Variation",
"bv",
"=",
"new",
"Variation",
"(",
")",
";",
"bv",
".",
"setValue",
"(",
"var",
".",
"value",
"(",
")",
")",
";",
"return",
"bv",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Does nothing.",
"}",
"return",
"null",
";",
"}"
] | Attempt to parse string as a Variation
@param part string token to parse
@return the BlockVariant enum value for the requested variant, or null if it wasn't valid. | [
"Attempt",
"to",
"parse",
"string",
"as",
"a",
"Variation"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L207-L311 |
23,062 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.getItemStackFromParameterString | public static ItemStack getItemStackFromParameterString(String parameters)
{
// Split into parameters:
List<String> params = new ArrayList<String>(Arrays.asList(parameters.split(" ")));
Colour col = null;
Variation var = null;
// See if any parameters appear to be a colour:
Iterator<String> it = params.iterator();
while (it.hasNext() && col == null)
{
col = MinecraftTypeHelper.attemptToGetAsColour(it.next());
if (col != null)
it.remove(); // This parameter was a colour - we've parsed it, so remove it.
}
// See if any parameters appear to be a variant:
it = params.iterator();
while (it.hasNext() && var == null)
{
var = MinecraftTypeHelper.attemptToGetAsVariant(it.next());
if (var != null)
it.remove(); // This parameter was a variant - we've parsed it, so remove it.
}
// Hopefully we have at most one parameter left, which will be the type.
if (params.size() == 0)
return null; // Dunno what to do, really.
String itemName = params.get(0);
DrawItem di = new DrawItem();
di.setColour(col);
di.setVariant(var);
di.setType(itemName);
return getItemStackFromDrawItem(di);
} | java | public static ItemStack getItemStackFromParameterString(String parameters)
{
// Split into parameters:
List<String> params = new ArrayList<String>(Arrays.asList(parameters.split(" ")));
Colour col = null;
Variation var = null;
// See if any parameters appear to be a colour:
Iterator<String> it = params.iterator();
while (it.hasNext() && col == null)
{
col = MinecraftTypeHelper.attemptToGetAsColour(it.next());
if (col != null)
it.remove(); // This parameter was a colour - we've parsed it, so remove it.
}
// See if any parameters appear to be a variant:
it = params.iterator();
while (it.hasNext() && var == null)
{
var = MinecraftTypeHelper.attemptToGetAsVariant(it.next());
if (var != null)
it.remove(); // This parameter was a variant - we've parsed it, so remove it.
}
// Hopefully we have at most one parameter left, which will be the type.
if (params.size() == 0)
return null; // Dunno what to do, really.
String itemName = params.get(0);
DrawItem di = new DrawItem();
di.setColour(col);
di.setVariant(var);
di.setType(itemName);
return getItemStackFromDrawItem(di);
} | [
"public",
"static",
"ItemStack",
"getItemStackFromParameterString",
"(",
"String",
"parameters",
")",
"{",
"// Split into parameters:",
"List",
"<",
"String",
">",
"params",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
"Arrays",
".",
"asList",
"(",
"parameters",
".",
"split",
"(",
"\" \"",
")",
")",
")",
";",
"Colour",
"col",
"=",
"null",
";",
"Variation",
"var",
"=",
"null",
";",
"// See if any parameters appear to be a colour:",
"Iterator",
"<",
"String",
">",
"it",
"=",
"params",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
"&&",
"col",
"==",
"null",
")",
"{",
"col",
"=",
"MinecraftTypeHelper",
".",
"attemptToGetAsColour",
"(",
"it",
".",
"next",
"(",
")",
")",
";",
"if",
"(",
"col",
"!=",
"null",
")",
"it",
".",
"remove",
"(",
")",
";",
"// This parameter was a colour - we've parsed it, so remove it.",
"}",
"// See if any parameters appear to be a variant:",
"it",
"=",
"params",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
"&&",
"var",
"==",
"null",
")",
"{",
"var",
"=",
"MinecraftTypeHelper",
".",
"attemptToGetAsVariant",
"(",
"it",
".",
"next",
"(",
")",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"it",
".",
"remove",
"(",
")",
";",
"// This parameter was a variant - we've parsed it, so remove it.",
"}",
"// Hopefully we have at most one parameter left, which will be the type.",
"if",
"(",
"params",
".",
"size",
"(",
")",
"==",
"0",
")",
"return",
"null",
";",
"// Dunno what to do, really.",
"String",
"itemName",
"=",
"params",
".",
"get",
"(",
"0",
")",
";",
"DrawItem",
"di",
"=",
"new",
"DrawItem",
"(",
")",
";",
"di",
".",
"setColour",
"(",
"col",
")",
";",
"di",
".",
"setVariant",
"(",
"var",
")",
";",
"di",
".",
"setType",
"(",
"itemName",
")",
";",
"return",
"getItemStackFromDrawItem",
"(",
"di",
")",
";",
"}"
] | Take a string of parameters, delimited by spaces, and create an ItemStack from it.
@param parameters the item name, variation, colour etc of the required item, separated by spaces.
@return an Itemstack for these parameters, or null if unrecognised. | [
"Take",
"a",
"string",
"of",
"parameters",
"delimited",
"by",
"spaces",
"and",
"create",
"an",
"ItemStack",
"from",
"it",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L434-L469 |
23,063 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.applyVariant | static IBlockState applyVariant(IBlockState state, Variation variant)
{
// Try the variant property first - if that fails, look for other properties that match the supplied variant.
boolean relaxRequirements = false;
for (int i = 0; i < 2; i++)
{
for (IProperty prop : state.getProperties().keySet())
{
if ((prop.getName().equals("variant") || relaxRequirements) && prop.getValueClass().isEnum())
{
Object[] values = prop.getValueClass().getEnumConstants();
for (Object obj : values)
{
if (obj != null && obj.toString().equalsIgnoreCase(variant.getValue()))
{
return state.withProperty(prop, (Comparable) obj);
}
}
}
}
relaxRequirements = true; // Failed to set the variant, so try again with other properties.
}
return state;
} | java | static IBlockState applyVariant(IBlockState state, Variation variant)
{
// Try the variant property first - if that fails, look for other properties that match the supplied variant.
boolean relaxRequirements = false;
for (int i = 0; i < 2; i++)
{
for (IProperty prop : state.getProperties().keySet())
{
if ((prop.getName().equals("variant") || relaxRequirements) && prop.getValueClass().isEnum())
{
Object[] values = prop.getValueClass().getEnumConstants();
for (Object obj : values)
{
if (obj != null && obj.toString().equalsIgnoreCase(variant.getValue()))
{
return state.withProperty(prop, (Comparable) obj);
}
}
}
}
relaxRequirements = true; // Failed to set the variant, so try again with other properties.
}
return state;
} | [
"static",
"IBlockState",
"applyVariant",
"(",
"IBlockState",
"state",
",",
"Variation",
"variant",
")",
"{",
"// Try the variant property first - if that fails, look for other properties that match the supplied variant.",
"boolean",
"relaxRequirements",
"=",
"false",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"2",
";",
"i",
"++",
")",
"{",
"for",
"(",
"IProperty",
"prop",
":",
"state",
".",
"getProperties",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"(",
"prop",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"variant\"",
")",
"||",
"relaxRequirements",
")",
"&&",
"prop",
".",
"getValueClass",
"(",
")",
".",
"isEnum",
"(",
")",
")",
"{",
"Object",
"[",
"]",
"values",
"=",
"prop",
".",
"getValueClass",
"(",
")",
".",
"getEnumConstants",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"values",
")",
"{",
"if",
"(",
"obj",
"!=",
"null",
"&&",
"obj",
".",
"toString",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"variant",
".",
"getValue",
"(",
")",
")",
")",
"{",
"return",
"state",
".",
"withProperty",
"(",
"prop",
",",
"(",
"Comparable",
")",
"obj",
")",
";",
"}",
"}",
"}",
"}",
"relaxRequirements",
"=",
"true",
";",
"// Failed to set the variant, so try again with other properties.",
"}",
"return",
"state",
";",
"}"
] | Select the request variant of the Minecraft block, if applicable
@param state The block to be varied
@param colour The new variation
@return A new blockstate which is the requested variant of the original, if such a variant exists; otherwise it returns the original block. | [
"Select",
"the",
"request",
"variant",
"of",
"the",
"Minecraft",
"block",
"if",
"applicable"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L530-L553 |
23,064 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.applyColour | static IBlockState applyColour(IBlockState state, Colour colour)
{
for (IProperty prop : state.getProperties().keySet())
{
if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
{
net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop);
if (!current.getName().equalsIgnoreCase(colour.name()))
{
return state.withProperty(prop, EnumDyeColor.valueOf(colour.name()));
}
}
}
return state;
} | java | static IBlockState applyColour(IBlockState state, Colour colour)
{
for (IProperty prop : state.getProperties().keySet())
{
if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
{
net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop);
if (!current.getName().equalsIgnoreCase(colour.name()))
{
return state.withProperty(prop, EnumDyeColor.valueOf(colour.name()));
}
}
}
return state;
} | [
"static",
"IBlockState",
"applyColour",
"(",
"IBlockState",
"state",
",",
"Colour",
"colour",
")",
"{",
"for",
"(",
"IProperty",
"prop",
":",
"state",
".",
"getProperties",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"prop",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"color\"",
")",
"&&",
"prop",
".",
"getValueClass",
"(",
")",
"==",
"net",
".",
"minecraft",
".",
"item",
".",
"EnumDyeColor",
".",
"class",
")",
"{",
"net",
".",
"minecraft",
".",
"item",
".",
"EnumDyeColor",
"current",
"=",
"(",
"net",
".",
"minecraft",
".",
"item",
".",
"EnumDyeColor",
")",
"state",
".",
"getValue",
"(",
"prop",
")",
";",
"if",
"(",
"!",
"current",
".",
"getName",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"colour",
".",
"name",
"(",
")",
")",
")",
"{",
"return",
"state",
".",
"withProperty",
"(",
"prop",
",",
"EnumDyeColor",
".",
"valueOf",
"(",
"colour",
".",
"name",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"return",
"state",
";",
"}"
] | Recolour the Minecraft block
@param state The block to be recoloured
@param colour The new colour
@return A new blockstate which is a recoloured version of the original | [
"Recolour",
"the",
"Minecraft",
"block"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L560-L574 |
23,065 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java | MinecraftTypeHelper.applyFacing | static IBlockState applyFacing(IBlockState state, Facing facing)
{
for (IProperty prop : state.getProperties().keySet())
{
if (prop.getName().equals("facing"))
{
if (prop.getValueClass() == EnumFacing.class)
{
EnumFacing current = (EnumFacing) state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumFacing.valueOf(facing.name()));
}
}
else if (prop.getValueClass() == EnumOrientation.class)
{
EnumOrientation current = (EnumOrientation) state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumOrientation.valueOf(facing.name()));
}
}
}
}
return state;
} | java | static IBlockState applyFacing(IBlockState state, Facing facing)
{
for (IProperty prop : state.getProperties().keySet())
{
if (prop.getName().equals("facing"))
{
if (prop.getValueClass() == EnumFacing.class)
{
EnumFacing current = (EnumFacing) state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumFacing.valueOf(facing.name()));
}
}
else if (prop.getValueClass() == EnumOrientation.class)
{
EnumOrientation current = (EnumOrientation) state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumOrientation.valueOf(facing.name()));
}
}
}
}
return state;
} | [
"static",
"IBlockState",
"applyFacing",
"(",
"IBlockState",
"state",
",",
"Facing",
"facing",
")",
"{",
"for",
"(",
"IProperty",
"prop",
":",
"state",
".",
"getProperties",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"prop",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"facing\"",
")",
")",
"{",
"if",
"(",
"prop",
".",
"getValueClass",
"(",
")",
"==",
"EnumFacing",
".",
"class",
")",
"{",
"EnumFacing",
"current",
"=",
"(",
"EnumFacing",
")",
"state",
".",
"getValue",
"(",
"prop",
")",
";",
"if",
"(",
"!",
"current",
".",
"getName",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"facing",
".",
"name",
"(",
")",
")",
")",
"{",
"return",
"state",
".",
"withProperty",
"(",
"prop",
",",
"EnumFacing",
".",
"valueOf",
"(",
"facing",
".",
"name",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"prop",
".",
"getValueClass",
"(",
")",
"==",
"EnumOrientation",
".",
"class",
")",
"{",
"EnumOrientation",
"current",
"=",
"(",
"EnumOrientation",
")",
"state",
".",
"getValue",
"(",
"prop",
")",
";",
"if",
"(",
"!",
"current",
".",
"getName",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"facing",
".",
"name",
"(",
")",
")",
")",
"{",
"return",
"state",
".",
"withProperty",
"(",
"prop",
",",
"EnumOrientation",
".",
"valueOf",
"(",
"facing",
".",
"name",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"state",
";",
"}"
] | Change the facing attribute of the Minecraft block
@param state The block to be edited
@param facing The new direction (N/S/E/W/U/D)
@return A new blockstate with the facing attribute edited | [
"Change",
"the",
"facing",
"attribute",
"of",
"the",
"Minecraft",
"block"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/MinecraftTypeHelper.java#L581-L606 |
23,066 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/CommandForKey.java | CommandForKey.create | private KeyHook create(KeyBinding key)
{
if (key != null && key instanceof KeyHook)
{
return (KeyHook)key; // Don't create a KeyHook to replace this KeyBinding, since that has already been done at some point.
// (Minecraft keeps a pointer to every KeyBinding that gets created, and they never get destroyed - so we don't want to create
// any more than necessary.)
}
return new KeyHook(key.getKeyDescription(), key.getKeyCode(), key.getKeyCategory());
} | java | private KeyHook create(KeyBinding key)
{
if (key != null && key instanceof KeyHook)
{
return (KeyHook)key; // Don't create a KeyHook to replace this KeyBinding, since that has already been done at some point.
// (Minecraft keeps a pointer to every KeyBinding that gets created, and they never get destroyed - so we don't want to create
// any more than necessary.)
}
return new KeyHook(key.getKeyDescription(), key.getKeyCode(), key.getKeyCategory());
} | [
"private",
"KeyHook",
"create",
"(",
"KeyBinding",
"key",
")",
"{",
"if",
"(",
"key",
"!=",
"null",
"&&",
"key",
"instanceof",
"KeyHook",
")",
"{",
"return",
"(",
"KeyHook",
")",
"key",
";",
"// Don't create a KeyHook to replace this KeyBinding, since that has already been done at some point.",
"// (Minecraft keeps a pointer to every KeyBinding that gets created, and they never get destroyed - so we don't want to create",
"// any more than necessary.)",
"}",
"return",
"new",
"KeyHook",
"(",
"key",
".",
"getKeyDescription",
"(",
")",
",",
"key",
".",
"getKeyCode",
"(",
")",
",",
"key",
".",
"getKeyCategory",
"(",
")",
")",
";",
"}"
] | Helper function to create a KeyHook object for a given KeyBinding object.
@param key the Minecraft KeyBinding object we are wrapping
@return an ExternalAIKey object to replace the original Minecraft KeyBinding object | [
"Helper",
"function",
"to",
"create",
"a",
"KeyHook",
"object",
"for",
"a",
"given",
"KeyBinding",
"object",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/CommandForKey.java#L223-L232 |
23,067 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/CommandForKey.java | CommandForKey.setOverriding | @Override
public void setOverriding(boolean b)
{
if (this.keyHook != null)
{
this.keyHook.isDown = false;
this.keyHook.justPressed = false;
this.keyHook.isOverridingPresses = b;
}
} | java | @Override
public void setOverriding(boolean b)
{
if (this.keyHook != null)
{
this.keyHook.isDown = false;
this.keyHook.justPressed = false;
this.keyHook.isOverridingPresses = b;
}
} | [
"@",
"Override",
"public",
"void",
"setOverriding",
"(",
"boolean",
"b",
")",
"{",
"if",
"(",
"this",
".",
"keyHook",
"!=",
"null",
")",
"{",
"this",
".",
"keyHook",
".",
"isDown",
"=",
"false",
";",
"this",
".",
"keyHook",
".",
"justPressed",
"=",
"false",
";",
"this",
".",
"keyHook",
".",
"isOverridingPresses",
"=",
"b",
";",
"}",
"}"
] | Switch this object "on" or "off".
@param b true if this object is to start overriding the normal Minecraft handling. | [
"Switch",
"this",
"object",
"on",
"or",
"off",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/CommandForKey.java#L254-L263 |
23,068 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java | MultidimensionalReward.add | public void add(int dimension, float value) {
if(this.map.containsKey(dimension))
this.map.put(dimension, this.map.get(dimension) + value);
else
this.map.put(dimension, value);
} | java | public void add(int dimension, float value) {
if(this.map.containsKey(dimension))
this.map.put(dimension, this.map.get(dimension) + value);
else
this.map.put(dimension, value);
} | [
"public",
"void",
"add",
"(",
"int",
"dimension",
",",
"float",
"value",
")",
"{",
"if",
"(",
"this",
".",
"map",
".",
"containsKey",
"(",
"dimension",
")",
")",
"this",
".",
"map",
".",
"put",
"(",
"dimension",
",",
"this",
".",
"map",
".",
"get",
"(",
"dimension",
")",
"+",
"value",
")",
";",
"else",
"this",
".",
"map",
".",
"put",
"(",
"dimension",
",",
"value",
")",
";",
"}"
] | Add a given reward value on a specified dimension.
@param dimension
the dimension to add the reward on.
@param value
the value of the reward. | [
"Add",
"a",
"given",
"reward",
"value",
"on",
"a",
"specified",
"dimension",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java#L70-L75 |
23,069 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java | MultidimensionalReward.add | public void add(MultidimensionalReward other) {
for (Map.Entry<Integer, Float> entry : other.map.entrySet()) {
Integer dimension = entry.getKey();
Float reward_value = entry.getValue();
this.add(dimension.intValue(), reward_value.floatValue());
}
} | java | public void add(MultidimensionalReward other) {
for (Map.Entry<Integer, Float> entry : other.map.entrySet()) {
Integer dimension = entry.getKey();
Float reward_value = entry.getValue();
this.add(dimension.intValue(), reward_value.floatValue());
}
} | [
"public",
"void",
"add",
"(",
"MultidimensionalReward",
"other",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Integer",
",",
"Float",
">",
"entry",
":",
"other",
".",
"map",
".",
"entrySet",
"(",
")",
")",
"{",
"Integer",
"dimension",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"Float",
"reward_value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"this",
".",
"add",
"(",
"dimension",
".",
"intValue",
"(",
")",
",",
"reward_value",
".",
"floatValue",
"(",
")",
")",
";",
"}",
"}"
] | Merge in another multidimensional reward structure.
@param other
the other multidimensional reward structure. | [
"Merge",
"in",
"another",
"multidimensional",
"reward",
"structure",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java#L83-L89 |
23,070 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java | MultidimensionalReward.getAsReward | public Reward getAsReward() {
Reward reward = new Reward();
for (Map.Entry<Integer, Float> entry : this.map.entrySet()) {
Integer dimension = entry.getKey();
Float reward_value = entry.getValue();
Value reward_entry = new Value();
reward_entry.setDimension(dimension);
reward_entry.setValue(new BigDecimal(reward_value));
reward.getValue().add(reward_entry);
}
return reward;
} | java | public Reward getAsReward() {
Reward reward = new Reward();
for (Map.Entry<Integer, Float> entry : this.map.entrySet()) {
Integer dimension = entry.getKey();
Float reward_value = entry.getValue();
Value reward_entry = new Value();
reward_entry.setDimension(dimension);
reward_entry.setValue(new BigDecimal(reward_value));
reward.getValue().add(reward_entry);
}
return reward;
} | [
"public",
"Reward",
"getAsReward",
"(",
")",
"{",
"Reward",
"reward",
"=",
"new",
"Reward",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Integer",
",",
"Float",
">",
"entry",
":",
"this",
".",
"map",
".",
"entrySet",
"(",
")",
")",
"{",
"Integer",
"dimension",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"Float",
"reward_value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"Value",
"reward_entry",
"=",
"new",
"Value",
"(",
")",
";",
"reward_entry",
".",
"setDimension",
"(",
"dimension",
")",
";",
"reward_entry",
".",
"setValue",
"(",
"new",
"BigDecimal",
"(",
"reward_value",
")",
")",
";",
"reward",
".",
"getValue",
"(",
")",
".",
"add",
"(",
"reward_entry",
")",
";",
"}",
"return",
"reward",
";",
"}"
] | Retrieve the reward structure as defined by the schema.
@return the reward structure as defined by the schema. | [
"Retrieve",
"the",
"reward",
"structure",
"as",
"defined",
"by",
"the",
"schema",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java#L96-L107 |
23,071 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java | MultidimensionalReward.getAsXMLString | public String getAsXMLString() {
// Create a string XML representation:
String rewardString = null;
try {
rewardString = SchemaHelper.serialiseObject(this.getAsReward(), Reward.class);
} catch (JAXBException e) {
System.out.println("Caught reward serialization exception: " + e);
}
return rewardString;
} | java | public String getAsXMLString() {
// Create a string XML representation:
String rewardString = null;
try {
rewardString = SchemaHelper.serialiseObject(this.getAsReward(), Reward.class);
} catch (JAXBException e) {
System.out.println("Caught reward serialization exception: " + e);
}
return rewardString;
} | [
"public",
"String",
"getAsXMLString",
"(",
")",
"{",
"// Create a string XML representation:",
"String",
"rewardString",
"=",
"null",
";",
"try",
"{",
"rewardString",
"=",
"SchemaHelper",
".",
"serialiseObject",
"(",
"this",
".",
"getAsReward",
"(",
")",
",",
"Reward",
".",
"class",
")",
";",
"}",
"catch",
"(",
"JAXBException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Caught reward serialization exception: \"",
"+",
"e",
")",
";",
"}",
"return",
"rewardString",
";",
"}"
] | Gets the reward structure as an XML string as defined by the schema.
@return the XML string. | [
"Gets",
"the",
"reward",
"structure",
"as",
"an",
"XML",
"string",
"as",
"defined",
"by",
"the",
"schema",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java#L114-L123 |
23,072 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java | MultidimensionalReward.getRewardTotal | public double getRewardTotal() {
double rewards = 0.0;
for (Map.Entry<Integer, Float> entry : this.map.entrySet()) {
rewards += entry.getValue();
}
return rewards;
} | java | public double getRewardTotal() {
double rewards = 0.0;
for (Map.Entry<Integer, Float> entry : this.map.entrySet()) {
rewards += entry.getValue();
}
return rewards;
} | [
"public",
"double",
"getRewardTotal",
"(",
")",
"{",
"double",
"rewards",
"=",
"0.0",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Integer",
",",
"Float",
">",
"entry",
":",
"this",
".",
"map",
".",
"entrySet",
"(",
")",
")",
"{",
"rewards",
"+=",
"entry",
".",
"getValue",
"(",
")",
";",
"}",
"return",
"rewards",
";",
"}"
] | Get the total rewards from all dimensions, each of which may be positive or negative.
@return The total rewards. | [
"Get",
"the",
"total",
"rewards",
"from",
"all",
"dimensions",
"each",
"of",
"which",
"may",
"be",
"positive",
"or",
"negative",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MultidimensionalReward.java#L148-L154 |
23,073 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java | MalmoEnvServer.serve | public void serve() throws IOException {
ServerSocket serverSocket = new ServerSocket(port);
while (true) {
try {
final Socket socket = serverSocket.accept();
Thread thread = new Thread("EnvServerSocketHandler") {
public void run() {
boolean running = false;
try {
checkHello(socket);
while (true) {
DataInputStream din = new DataInputStream(socket.getInputStream());
int hdr = din.readInt();
byte[] data = new byte[hdr];
din.readFully(data);
String command = new String(data, utf8);
if (command.startsWith("<Step")) {
step(command, socket, din);
} else if (command.startsWith("<Peek")) {
peek(command, socket, din);
} else if (command.startsWith("<Init")) {
init(command, socket);
} else if (command.startsWith("<Find")) {
find(command, socket);
} else if (command.startsWith("<MissionInit")) {
if (missionInit(din, command, socket))
running = true;
} else if (command.startsWith("<Quit")) {
quit(command, socket);
} else if (command.startsWith("<Exit")) {
exit(command, socket);
} else if (command.startsWith("<Close")) {
close(command, socket);
} else if (command.startsWith("<Status")) {
status(command, socket);
} else if (command.startsWith("<Echo")) {
command = "<Echo>" + command + "</Echo>";
data = command.getBytes(utf8);
hdr = data.length;
DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
dout.writeInt(hdr);
dout.write(data, 0, hdr);
dout.flush();
} else {
throw new IOException("Unknown env service command");
}
}
} catch (IOException ioe) {
TCPUtils.Log(Level.SEVERE, "MalmoEnv socket error: " + ioe + " (can be on disconnect)");
try {
if (running) {
TCPUtils.Log(Level.INFO,"Want to quit on disconnect.");
setWantToQuit();
}
socket.close();
} catch (IOException ioe2) {
}
}
}
};
thread.start();
} catch (IOException ioe) {
TCPUtils.Log(Level.SEVERE, "MalmoEnv service exits on " + ioe);
}
}
} | java | public void serve() throws IOException {
ServerSocket serverSocket = new ServerSocket(port);
while (true) {
try {
final Socket socket = serverSocket.accept();
Thread thread = new Thread("EnvServerSocketHandler") {
public void run() {
boolean running = false;
try {
checkHello(socket);
while (true) {
DataInputStream din = new DataInputStream(socket.getInputStream());
int hdr = din.readInt();
byte[] data = new byte[hdr];
din.readFully(data);
String command = new String(data, utf8);
if (command.startsWith("<Step")) {
step(command, socket, din);
} else if (command.startsWith("<Peek")) {
peek(command, socket, din);
} else if (command.startsWith("<Init")) {
init(command, socket);
} else if (command.startsWith("<Find")) {
find(command, socket);
} else if (command.startsWith("<MissionInit")) {
if (missionInit(din, command, socket))
running = true;
} else if (command.startsWith("<Quit")) {
quit(command, socket);
} else if (command.startsWith("<Exit")) {
exit(command, socket);
} else if (command.startsWith("<Close")) {
close(command, socket);
} else if (command.startsWith("<Status")) {
status(command, socket);
} else if (command.startsWith("<Echo")) {
command = "<Echo>" + command + "</Echo>";
data = command.getBytes(utf8);
hdr = data.length;
DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
dout.writeInt(hdr);
dout.write(data, 0, hdr);
dout.flush();
} else {
throw new IOException("Unknown env service command");
}
}
} catch (IOException ioe) {
TCPUtils.Log(Level.SEVERE, "MalmoEnv socket error: " + ioe + " (can be on disconnect)");
try {
if (running) {
TCPUtils.Log(Level.INFO,"Want to quit on disconnect.");
setWantToQuit();
}
socket.close();
} catch (IOException ioe2) {
}
}
}
};
thread.start();
} catch (IOException ioe) {
TCPUtils.Log(Level.SEVERE, "MalmoEnv service exits on " + ioe);
}
}
} | [
"public",
"void",
"serve",
"(",
")",
"throws",
"IOException",
"{",
"ServerSocket",
"serverSocket",
"=",
"new",
"ServerSocket",
"(",
"port",
")",
";",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"final",
"Socket",
"socket",
"=",
"serverSocket",
".",
"accept",
"(",
")",
";",
"Thread",
"thread",
"=",
"new",
"Thread",
"(",
"\"EnvServerSocketHandler\"",
")",
"{",
"public",
"void",
"run",
"(",
")",
"{",
"boolean",
"running",
"=",
"false",
";",
"try",
"{",
"checkHello",
"(",
"socket",
")",
";",
"while",
"(",
"true",
")",
"{",
"DataInputStream",
"din",
"=",
"new",
"DataInputStream",
"(",
"socket",
".",
"getInputStream",
"(",
")",
")",
";",
"int",
"hdr",
"=",
"din",
".",
"readInt",
"(",
")",
";",
"byte",
"[",
"]",
"data",
"=",
"new",
"byte",
"[",
"hdr",
"]",
";",
"din",
".",
"readFully",
"(",
"data",
")",
";",
"String",
"command",
"=",
"new",
"String",
"(",
"data",
",",
"utf8",
")",
";",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Step\"",
")",
")",
"{",
"step",
"(",
"command",
",",
"socket",
",",
"din",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Peek\"",
")",
")",
"{",
"peek",
"(",
"command",
",",
"socket",
",",
"din",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Init\"",
")",
")",
"{",
"init",
"(",
"command",
",",
"socket",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Find\"",
")",
")",
"{",
"find",
"(",
"command",
",",
"socket",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<MissionInit\"",
")",
")",
"{",
"if",
"(",
"missionInit",
"(",
"din",
",",
"command",
",",
"socket",
")",
")",
"running",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Quit\"",
")",
")",
"{",
"quit",
"(",
"command",
",",
"socket",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Exit\"",
")",
")",
"{",
"exit",
"(",
"command",
",",
"socket",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Close\"",
")",
")",
"{",
"close",
"(",
"command",
",",
"socket",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Status\"",
")",
")",
"{",
"status",
"(",
"command",
",",
"socket",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"startsWith",
"(",
"\"<Echo\"",
")",
")",
"{",
"command",
"=",
"\"<Echo>\"",
"+",
"command",
"+",
"\"</Echo>\"",
";",
"data",
"=",
"command",
".",
"getBytes",
"(",
"utf8",
")",
";",
"hdr",
"=",
"data",
".",
"length",
";",
"DataOutputStream",
"dout",
"=",
"new",
"DataOutputStream",
"(",
"socket",
".",
"getOutputStream",
"(",
")",
")",
";",
"dout",
".",
"writeInt",
"(",
"hdr",
")",
";",
"dout",
".",
"write",
"(",
"data",
",",
"0",
",",
"hdr",
")",
";",
"dout",
".",
"flush",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unknown env service command\"",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"SEVERE",
",",
"\"MalmoEnv socket error: \"",
"+",
"ioe",
"+",
"\" (can be on disconnect)\"",
")",
";",
"try",
"{",
"if",
"(",
"running",
")",
"{",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"INFO",
",",
"\"Want to quit on disconnect.\"",
")",
";",
"setWantToQuit",
"(",
")",
";",
"}",
"socket",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioe2",
")",
"{",
"}",
"}",
"}",
"}",
";",
"thread",
".",
"start",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"TCPUtils",
".",
"Log",
"(",
"Level",
".",
"SEVERE",
",",
"\"MalmoEnv service exits on \"",
"+",
"ioe",
")",
";",
"}",
"}",
"}"
] | Start servicing the MalmoEnv protocol.
@throws IOException | [
"Start",
"servicing",
"the",
"MalmoEnv",
"protocol",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java#L118-L207 |
23,074 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java | MalmoEnvServer.getObservation | private byte[] getObservation(boolean done) {
byte[] obs = envState.obs;
if (obs == null && !done) {
try {
cond.await(COND_WAIT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException ie) {
}
obs = envState.obs;
}
if (obs == null) {
obs = new byte[0];
}
return obs;
} | java | private byte[] getObservation(boolean done) {
byte[] obs = envState.obs;
if (obs == null && !done) {
try {
cond.await(COND_WAIT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException ie) {
}
obs = envState.obs;
}
if (obs == null) {
obs = new byte[0];
}
return obs;
} | [
"private",
"byte",
"[",
"]",
"getObservation",
"(",
"boolean",
"done",
")",
"{",
"byte",
"[",
"]",
"obs",
"=",
"envState",
".",
"obs",
";",
"if",
"(",
"obs",
"==",
"null",
"&&",
"!",
"done",
")",
"{",
"try",
"{",
"cond",
".",
"await",
"(",
"COND_WAIT_SECONDS",
",",
"TimeUnit",
".",
"SECONDS",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"ie",
")",
"{",
"}",
"obs",
"=",
"envState",
".",
"obs",
";",
"}",
"if",
"(",
"obs",
"==",
"null",
")",
"{",
"obs",
"=",
"new",
"byte",
"[",
"0",
"]",
";",
"}",
"return",
"obs",
";",
"}"
] | Get the current observation. If none and not done wait for a short time. | [
"Get",
"the",
"current",
"observation",
".",
"If",
"none",
"and",
"not",
"done",
"wait",
"for",
"a",
"short",
"time",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java#L510-L523 |
23,075 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java | MalmoEnvServer.observation | public void observation(String info) {
// Parsing obs as JSON would be slower but less fragile than extracting the turn_key using string search.
String pattern = "\"turn_key\":\"";
int i = info.indexOf(pattern);
String turnKey = "";
if (i != -1) {
turnKey = info.substring(i + pattern.length(), info.length() - 1);
turnKey = turnKey.substring(0, turnKey.indexOf("\""));
// TCPUtils.Log(Level.FINE, "Observation turn key: " + turnKey);
}
lock.lock();
try {
if (!envState.turnKey.equals(turnKey)) {
// TCPUtils.Log(Level.FINE,"Update TK: [" + turnKey + "][" + turnKey + "]");
}
if (!envState.lastTurnKey.equals(turnKey)) {
envState.turnKey = turnKey;
}
envState.info = info;
cond.signalAll();
} finally {
lock.unlock();
}
} | java | public void observation(String info) {
// Parsing obs as JSON would be slower but less fragile than extracting the turn_key using string search.
String pattern = "\"turn_key\":\"";
int i = info.indexOf(pattern);
String turnKey = "";
if (i != -1) {
turnKey = info.substring(i + pattern.length(), info.length() - 1);
turnKey = turnKey.substring(0, turnKey.indexOf("\""));
// TCPUtils.Log(Level.FINE, "Observation turn key: " + turnKey);
}
lock.lock();
try {
if (!envState.turnKey.equals(turnKey)) {
// TCPUtils.Log(Level.FINE,"Update TK: [" + turnKey + "][" + turnKey + "]");
}
if (!envState.lastTurnKey.equals(turnKey)) {
envState.turnKey = turnKey;
}
envState.info = info;
cond.signalAll();
} finally {
lock.unlock();
}
} | [
"public",
"void",
"observation",
"(",
"String",
"info",
")",
"{",
"// Parsing obs as JSON would be slower but less fragile than extracting the turn_key using string search.",
"String",
"pattern",
"=",
"\"\\\"turn_key\\\":\\\"\"",
";",
"int",
"i",
"=",
"info",
".",
"indexOf",
"(",
"pattern",
")",
";",
"String",
"turnKey",
"=",
"\"\"",
";",
"if",
"(",
"i",
"!=",
"-",
"1",
")",
"{",
"turnKey",
"=",
"info",
".",
"substring",
"(",
"i",
"+",
"pattern",
".",
"length",
"(",
")",
",",
"info",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"turnKey",
"=",
"turnKey",
".",
"substring",
"(",
"0",
",",
"turnKey",
".",
"indexOf",
"(",
"\"\\\"\"",
")",
")",
";",
"// TCPUtils.Log(Level.FINE, \"Observation turn key: \" + turnKey);",
"}",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"envState",
".",
"turnKey",
".",
"equals",
"(",
"turnKey",
")",
")",
"{",
"// TCPUtils.Log(Level.FINE,\"Update TK: [\" + turnKey + \"][\" + turnKey + \"]\");",
"}",
"if",
"(",
"!",
"envState",
".",
"lastTurnKey",
".",
"equals",
"(",
"turnKey",
")",
")",
"{",
"envState",
".",
"turnKey",
"=",
"turnKey",
";",
"}",
"envState",
".",
"info",
"=",
"info",
";",
"cond",
".",
"signalAll",
"(",
")",
";",
"}",
"finally",
"{",
"lock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | Record a Malmo "observation" json - as the env info since an environment "obs" is a video frame. | [
"Record",
"a",
"Malmo",
"observation",
"json",
"-",
"as",
"the",
"env",
"info",
"since",
"an",
"environment",
"obs",
"is",
"a",
"video",
"frame",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java#L693-L716 |
23,076 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java | MalmoEnvServer.doIWantToQuit | @Override
public boolean doIWantToQuit(MissionInit missionInit) {
lock.lock();
try {
return envState.quit;
} finally {
lock.unlock();
}
} | java | @Override
public boolean doIWantToQuit(MissionInit missionInit) {
lock.lock();
try {
return envState.quit;
} finally {
lock.unlock();
}
} | [
"@",
"Override",
"public",
"boolean",
"doIWantToQuit",
"(",
"MissionInit",
"missionInit",
")",
"{",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"return",
"envState",
".",
"quit",
";",
"}",
"finally",
"{",
"lock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | IWantToQuit implementation. | [
"IWantToQuit",
"implementation",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/MalmoEnvServer.java#L763-L771 |
23,077 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/TCPInputPoller.java | TCPInputPoller.stopServer | public void stopServer()
{
Log(Level.INFO, "Attempting to stop SocketServer");
keepRunning = false;
// Thread will be blocked waiting for input - unblock it by closing the socket underneath it:
if (this.serverSocket != null)
{
try
{
this.serverSocket.close();
}
catch (IOException e)
{
Log(Level.WARNING, "Something happened when closing SocketServer: " + e);
}
this.serverSocket = null;
}
} | java | public void stopServer()
{
Log(Level.INFO, "Attempting to stop SocketServer");
keepRunning = false;
// Thread will be blocked waiting for input - unblock it by closing the socket underneath it:
if (this.serverSocket != null)
{
try
{
this.serverSocket.close();
}
catch (IOException e)
{
Log(Level.WARNING, "Something happened when closing SocketServer: " + e);
}
this.serverSocket = null;
}
} | [
"public",
"void",
"stopServer",
"(",
")",
"{",
"Log",
"(",
"Level",
".",
"INFO",
",",
"\"Attempting to stop SocketServer\"",
")",
";",
"keepRunning",
"=",
"false",
";",
"// Thread will be blocked waiting for input - unblock it by closing the socket underneath it:",
"if",
"(",
"this",
".",
"serverSocket",
"!=",
"null",
")",
"{",
"try",
"{",
"this",
".",
"serverSocket",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"Log",
"(",
"Level",
".",
"WARNING",
",",
"\"Something happened when closing SocketServer: \"",
"+",
"e",
")",
";",
"}",
"this",
".",
"serverSocket",
"=",
"null",
";",
"}",
"}"
] | Immediately stop waiting for messages, and close the SocketServer. | [
"Immediately",
"stop",
"waiting",
"for",
"messages",
"and",
"close",
"the",
"SocketServer",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/TCPInputPoller.java#L186-L203 |
23,078 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/StateEpisode.java | StateEpisode.start | public void start() {
this.isLive = true; // This episode is now active.
try {
execute();
} catch (Exception e) {
System.out.println("State start - exception: " + e);
e.printStackTrace();
// TODO... what?
}
} | java | public void start() {
this.isLive = true; // This episode is now active.
try {
execute();
} catch (Exception e) {
System.out.println("State start - exception: " + e);
e.printStackTrace();
// TODO... what?
}
} | [
"public",
"void",
"start",
"(",
")",
"{",
"this",
".",
"isLive",
"=",
"true",
";",
"// This episode is now active.",
"try",
"{",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"State start - exception: \"",
"+",
"e",
")",
";",
"e",
".",
"printStackTrace",
"(",
")",
";",
"// TODO... what?",
"}",
"}"
] | Called to kick off the episode - should be no need for subclasses to override. | [
"Called",
"to",
"kick",
"off",
"the",
"episode",
"-",
"should",
"be",
"no",
"need",
"for",
"subclasses",
"to",
"override",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/StateEpisode.java#L50-L59 |
23,079 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/RewardForStructureCopyingImplementation.java | RewardForStructureCopyingImplementation.getReward | @Override
public void getReward(MissionInit missionInit, MultidimensionalReward multidimReward)
{
super.getReward(missionInit, multidimReward);
if (this.rewardDensity == RewardDensityForBuildAndBreak.MISSION_END)
{
// Only send the reward at the very end of the mission.
if (multidimReward.isFinalReward() && this.reward != 0)
{
float adjusted_reward = adjustAndDistributeReward(this.reward, this.dimension, this.rscparams.getRewardDistribution());
multidimReward.add(this.dimension, adjusted_reward);
}
}
else
{
// Send reward immediately.
if (this.reward != 0)
{
synchronized (this)
{
float adjusted_reward = adjustAndDistributeReward(this.reward, this.dimension, this.rscparams.getRewardDistribution());
multidimReward.add(this.dimension, adjusted_reward);
this.reward = 0;
}
}
}
} | java | @Override
public void getReward(MissionInit missionInit, MultidimensionalReward multidimReward)
{
super.getReward(missionInit, multidimReward);
if (this.rewardDensity == RewardDensityForBuildAndBreak.MISSION_END)
{
// Only send the reward at the very end of the mission.
if (multidimReward.isFinalReward() && this.reward != 0)
{
float adjusted_reward = adjustAndDistributeReward(this.reward, this.dimension, this.rscparams.getRewardDistribution());
multidimReward.add(this.dimension, adjusted_reward);
}
}
else
{
// Send reward immediately.
if (this.reward != 0)
{
synchronized (this)
{
float adjusted_reward = adjustAndDistributeReward(this.reward, this.dimension, this.rscparams.getRewardDistribution());
multidimReward.add(this.dimension, adjusted_reward);
this.reward = 0;
}
}
}
} | [
"@",
"Override",
"public",
"void",
"getReward",
"(",
"MissionInit",
"missionInit",
",",
"MultidimensionalReward",
"multidimReward",
")",
"{",
"super",
".",
"getReward",
"(",
"missionInit",
",",
"multidimReward",
")",
";",
"if",
"(",
"this",
".",
"rewardDensity",
"==",
"RewardDensityForBuildAndBreak",
".",
"MISSION_END",
")",
"{",
"// Only send the reward at the very end of the mission.",
"if",
"(",
"multidimReward",
".",
"isFinalReward",
"(",
")",
"&&",
"this",
".",
"reward",
"!=",
"0",
")",
"{",
"float",
"adjusted_reward",
"=",
"adjustAndDistributeReward",
"(",
"this",
".",
"reward",
",",
"this",
".",
"dimension",
",",
"this",
".",
"rscparams",
".",
"getRewardDistribution",
"(",
")",
")",
";",
"multidimReward",
".",
"add",
"(",
"this",
".",
"dimension",
",",
"adjusted_reward",
")",
";",
"}",
"}",
"else",
"{",
"// Send reward immediately.",
"if",
"(",
"this",
".",
"reward",
"!=",
"0",
")",
"{",
"synchronized",
"(",
"this",
")",
"{",
"float",
"adjusted_reward",
"=",
"adjustAndDistributeReward",
"(",
"this",
".",
"reward",
",",
"this",
".",
"dimension",
",",
"this",
".",
"rscparams",
".",
"getRewardDistribution",
"(",
")",
")",
";",
"multidimReward",
".",
"add",
"(",
"this",
".",
"dimension",
",",
"adjusted_reward",
")",
";",
"this",
".",
"reward",
"=",
"0",
";",
"}",
"}",
"}",
"}"
] | Get the reward value for the current Minecraft state.
@param missionInit the MissionInit object for the currently running mission,
which may contain parameters for the reward requirements.
@param multidimReward | [
"Get",
"the",
"reward",
"value",
"for",
"the",
"current",
"Minecraft",
"state",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/RewardForStructureCopyingImplementation.java#L52-L78 |
23,080 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/RewardForStructureCopyingImplementation.java | RewardForStructureCopyingImplementation.cleanup | @Override
public void cleanup()
{
super.cleanup();
MinecraftForge.EVENT_BUS.unregister(this);
structureHasBeenCompleted = false;
MalmoMod.MalmoMessageHandler.deregisterForMessage(this, MalmoMessageType.SERVER_MISSIONOVER);
} | java | @Override
public void cleanup()
{
super.cleanup();
MinecraftForge.EVENT_BUS.unregister(this);
structureHasBeenCompleted = false;
MalmoMod.MalmoMessageHandler.deregisterForMessage(this, MalmoMessageType.SERVER_MISSIONOVER);
} | [
"@",
"Override",
"public",
"void",
"cleanup",
"(",
")",
"{",
"super",
".",
"cleanup",
"(",
")",
";",
"MinecraftForge",
".",
"EVENT_BUS",
".",
"unregister",
"(",
"this",
")",
";",
"structureHasBeenCompleted",
"=",
"false",
";",
"MalmoMod",
".",
"MalmoMessageHandler",
".",
"deregisterForMessage",
"(",
"this",
",",
"MalmoMessageType",
".",
"SERVER_MISSIONOVER",
")",
";",
"}"
] | Called once after the mission ends - use for any necessary cleanup. | [
"Called",
"once",
"after",
"the",
"mission",
"ends",
"-",
"use",
"for",
"any",
"necessary",
"cleanup",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/RewardForStructureCopyingImplementation.java#L126-L133 |
23,081 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MissionBehaviour.java | MissionBehaviour.addHandler | private void addHandler(Object handler)
{
// Would be nice to have a better way to do this,
// but the type information isn't preserved in the XML format anymore -
// and the number of types of handler is pretty unlikely to change, so this list
// won't have to be added to often, if at all.
if (handler == null)
return;
if (handler instanceof IVideoProducer)
addVideoProducer((IVideoProducer)handler);
else if (handler instanceof IAudioProducer)
addAudioProducer((IAudioProducer)handler);
else if (handler instanceof ICommandHandler)
addCommandHandler((ICommandHandler)handler);
else if (handler instanceof IObservationProducer)
addObservationProducer((IObservationProducer)handler);
else if (handler instanceof IRewardProducer)
addRewardProducer((IRewardProducer)handler);
else if (handler instanceof IWorldGenerator)
addWorldGenerator((IWorldGenerator)handler);
else if (handler instanceof IWorldDecorator)
addWorldDecorator((IWorldDecorator)handler);
else if (handler instanceof IWantToQuit)
addQuitProducer((IWantToQuit)handler);
else
this.failedHandlers += handler.getClass().getSimpleName() + " isn't of a recognised handler type.\n";
} | java | private void addHandler(Object handler)
{
// Would be nice to have a better way to do this,
// but the type information isn't preserved in the XML format anymore -
// and the number of types of handler is pretty unlikely to change, so this list
// won't have to be added to often, if at all.
if (handler == null)
return;
if (handler instanceof IVideoProducer)
addVideoProducer((IVideoProducer)handler);
else if (handler instanceof IAudioProducer)
addAudioProducer((IAudioProducer)handler);
else if (handler instanceof ICommandHandler)
addCommandHandler((ICommandHandler)handler);
else if (handler instanceof IObservationProducer)
addObservationProducer((IObservationProducer)handler);
else if (handler instanceof IRewardProducer)
addRewardProducer((IRewardProducer)handler);
else if (handler instanceof IWorldGenerator)
addWorldGenerator((IWorldGenerator)handler);
else if (handler instanceof IWorldDecorator)
addWorldDecorator((IWorldDecorator)handler);
else if (handler instanceof IWantToQuit)
addQuitProducer((IWantToQuit)handler);
else
this.failedHandlers += handler.getClass().getSimpleName() + " isn't of a recognised handler type.\n";
} | [
"private",
"void",
"addHandler",
"(",
"Object",
"handler",
")",
"{",
"// Would be nice to have a better way to do this,",
"// but the type information isn't preserved in the XML format anymore -",
"// and the number of types of handler is pretty unlikely to change, so this list",
"// won't have to be added to often, if at all.",
"if",
"(",
"handler",
"==",
"null",
")",
"return",
";",
"if",
"(",
"handler",
"instanceof",
"IVideoProducer",
")",
"addVideoProducer",
"(",
"(",
"IVideoProducer",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"IAudioProducer",
")",
"addAudioProducer",
"(",
"(",
"IAudioProducer",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"ICommandHandler",
")",
"addCommandHandler",
"(",
"(",
"ICommandHandler",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"IObservationProducer",
")",
"addObservationProducer",
"(",
"(",
"IObservationProducer",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"IRewardProducer",
")",
"addRewardProducer",
"(",
"(",
"IRewardProducer",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"IWorldGenerator",
")",
"addWorldGenerator",
"(",
"(",
"IWorldGenerator",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"IWorldDecorator",
")",
"addWorldDecorator",
"(",
"(",
"IWorldDecorator",
")",
"handler",
")",
";",
"else",
"if",
"(",
"handler",
"instanceof",
"IWantToQuit",
")",
"addQuitProducer",
"(",
"(",
"IWantToQuit",
")",
"handler",
")",
";",
"else",
"this",
".",
"failedHandlers",
"+=",
"handler",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\" isn't of a recognised handler type.\\n\"",
";",
"}"
] | Add this handler to our set, creating containers as needs be.
@param handler The handler to add. | [
"Add",
"this",
"handler",
"to",
"our",
"set",
"creating",
"containers",
"as",
"needs",
"be",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MissionBehaviour.java#L152-L179 |
23,082 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MissionBehaviour.java | MissionBehaviour.createHandlerFromParams | private Object createHandlerFromParams(Object xmlHandler)
{
if (xmlHandler == null)
return null;
Object handler = null;
String handlerClass = xmlHandler.getClass().getSimpleName();
if (handlerClass == null || handlerClass.length() == 0)
{
return null;
}
try
{
// To avoid name collisions, the java class will have the suffix "Implementation".
Class<?> c = Class.forName("com.microsoft.Malmo.MissionHandlers." + handlerClass + "Implementation");
handler = c.newInstance();
if (!((HandlerBase)handler).parseParameters(xmlHandler))
this.failedHandlers += handlerClass + " failed to parse parameters.\n";
}
catch (ClassNotFoundException e)
{
System.out.println("Duff MissionHandler requested: "+handlerClass);
this.failedHandlers += "Failed to find " + handlerClass + "\n";
}
catch (InstantiationException e)
{
System.out.println("Could not instantiate specified MissionHandler.");
this.failedHandlers += "Failed to create " + handlerClass + "\n";
}
catch (IllegalAccessException e)
{
System.out.println("Could not instantiate specified MissionHandler.");
this.failedHandlers += "Failed to access " + handlerClass + "\n";
}
return handler;
} | java | private Object createHandlerFromParams(Object xmlHandler)
{
if (xmlHandler == null)
return null;
Object handler = null;
String handlerClass = xmlHandler.getClass().getSimpleName();
if (handlerClass == null || handlerClass.length() == 0)
{
return null;
}
try
{
// To avoid name collisions, the java class will have the suffix "Implementation".
Class<?> c = Class.forName("com.microsoft.Malmo.MissionHandlers." + handlerClass + "Implementation");
handler = c.newInstance();
if (!((HandlerBase)handler).parseParameters(xmlHandler))
this.failedHandlers += handlerClass + " failed to parse parameters.\n";
}
catch (ClassNotFoundException e)
{
System.out.println("Duff MissionHandler requested: "+handlerClass);
this.failedHandlers += "Failed to find " + handlerClass + "\n";
}
catch (InstantiationException e)
{
System.out.println("Could not instantiate specified MissionHandler.");
this.failedHandlers += "Failed to create " + handlerClass + "\n";
}
catch (IllegalAccessException e)
{
System.out.println("Could not instantiate specified MissionHandler.");
this.failedHandlers += "Failed to access " + handlerClass + "\n";
}
return handler;
} | [
"private",
"Object",
"createHandlerFromParams",
"(",
"Object",
"xmlHandler",
")",
"{",
"if",
"(",
"xmlHandler",
"==",
"null",
")",
"return",
"null",
";",
"Object",
"handler",
"=",
"null",
";",
"String",
"handlerClass",
"=",
"xmlHandler",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
";",
"if",
"(",
"handlerClass",
"==",
"null",
"||",
"handlerClass",
".",
"length",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"// To avoid name collisions, the java class will have the suffix \"Implementation\".",
"Class",
"<",
"?",
">",
"c",
"=",
"Class",
".",
"forName",
"(",
"\"com.microsoft.Malmo.MissionHandlers.\"",
"+",
"handlerClass",
"+",
"\"Implementation\"",
")",
";",
"handler",
"=",
"c",
".",
"newInstance",
"(",
")",
";",
"if",
"(",
"!",
"(",
"(",
"HandlerBase",
")",
"handler",
")",
".",
"parseParameters",
"(",
"xmlHandler",
")",
")",
"this",
".",
"failedHandlers",
"+=",
"handlerClass",
"+",
"\" failed to parse parameters.\\n\"",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Duff MissionHandler requested: \"",
"+",
"handlerClass",
")",
";",
"this",
".",
"failedHandlers",
"+=",
"\"Failed to find \"",
"+",
"handlerClass",
"+",
"\"\\n\"",
";",
"}",
"catch",
"(",
"InstantiationException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Could not instantiate specified MissionHandler.\"",
")",
";",
"this",
".",
"failedHandlers",
"+=",
"\"Failed to create \"",
"+",
"handlerClass",
"+",
"\"\\n\"",
";",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Could not instantiate specified MissionHandler.\"",
")",
";",
"this",
".",
"failedHandlers",
"+=",
"\"Failed to access \"",
"+",
"handlerClass",
"+",
"\"\\n\"",
";",
"}",
"return",
"handler",
";",
"}"
] | Attempt to create an instance of the specified handler class, using reflection.
@param xmlHandler the object which specifies both the name and the parameters of the requested handler.
@return an instance of the requested class, if possible, or null if the class wasn't found. | [
"Attempt",
"to",
"create",
"an",
"instance",
"of",
"the",
"specified",
"handler",
"class",
"using",
"reflection",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/MissionBehaviour.java#L291-L326 |
23,083 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java | ScoreHelper.update | static public void update(Configuration configs)
{
scoringPolicy = configs.get(MalmoMod.SCORING_CONFIGS, "policy", DEFAULT_NO_SCORING).getInt();
if (scoringPolicy > 0) {
String customLogHandler = configs.get(MalmoMod.SCORING_CONFIGS, "handler", "").getString();
setLogging(Level.INFO, customLogHandler);
}
if (logging)
log("<ScoreInit><Policy>" + scoringPolicy + "</Policy></ScoreInit>");
} | java | static public void update(Configuration configs)
{
scoringPolicy = configs.get(MalmoMod.SCORING_CONFIGS, "policy", DEFAULT_NO_SCORING).getInt();
if (scoringPolicy > 0) {
String customLogHandler = configs.get(MalmoMod.SCORING_CONFIGS, "handler", "").getString();
setLogging(Level.INFO, customLogHandler);
}
if (logging)
log("<ScoreInit><Policy>" + scoringPolicy + "</Policy></ScoreInit>");
} | [
"static",
"public",
"void",
"update",
"(",
"Configuration",
"configs",
")",
"{",
"scoringPolicy",
"=",
"configs",
".",
"get",
"(",
"MalmoMod",
".",
"SCORING_CONFIGS",
",",
"\"policy\"",
",",
"DEFAULT_NO_SCORING",
")",
".",
"getInt",
"(",
")",
";",
"if",
"(",
"scoringPolicy",
">",
"0",
")",
"{",
"String",
"customLogHandler",
"=",
"configs",
".",
"get",
"(",
"MalmoMod",
".",
"SCORING_CONFIGS",
",",
"\"handler\"",
",",
"\"\"",
")",
".",
"getString",
"(",
")",
";",
"setLogging",
"(",
"Level",
".",
"INFO",
",",
"customLogHandler",
")",
";",
"}",
"if",
"(",
"logging",
")",
"log",
"(",
"\"<ScoreInit><Policy>\"",
"+",
"scoringPolicy",
"+",
"\"</Policy></ScoreInit>\"",
")",
";",
"}"
] | Initialize scoing. | [
"Initialize",
"scoing",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java#L60-L69 |
23,084 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java | ScoreHelper.logMissionInit | public static void logMissionInit(MissionInit missionInit) throws JAXBException {
if (!logging || !isScoring())
return;
totalRewards = 0.0;
String missionXml = SchemaHelper.serialiseObject(missionInit.getMission(), Mission.class);
String hash;
try {
hash = digest(missionXml);
} catch (NoSuchAlgorithmException e) {
hash = "";
}
List<AgentSection> agents = missionInit.getMission().getAgentSection();
String agentName = agents.get(missionInit.getClientRole()).getName();
StringBuffer message = new StringBuffer("<MissionInit><MissionDigest>");
message.append(hash);
message.append("</MissionDigest>");
message.append("<AgentName>");
message.append(agentName);
message.append("</AgentName></MissionInit>");
if (scoringPolicy == TOTAL_WITH_MISSION_XML)
message.append(missionXml);
log(message.toString());
} | java | public static void logMissionInit(MissionInit missionInit) throws JAXBException {
if (!logging || !isScoring())
return;
totalRewards = 0.0;
String missionXml = SchemaHelper.serialiseObject(missionInit.getMission(), Mission.class);
String hash;
try {
hash = digest(missionXml);
} catch (NoSuchAlgorithmException e) {
hash = "";
}
List<AgentSection> agents = missionInit.getMission().getAgentSection();
String agentName = agents.get(missionInit.getClientRole()).getName();
StringBuffer message = new StringBuffer("<MissionInit><MissionDigest>");
message.append(hash);
message.append("</MissionDigest>");
message.append("<AgentName>");
message.append(agentName);
message.append("</AgentName></MissionInit>");
if (scoringPolicy == TOTAL_WITH_MISSION_XML)
message.append(missionXml);
log(message.toString());
} | [
"public",
"static",
"void",
"logMissionInit",
"(",
"MissionInit",
"missionInit",
")",
"throws",
"JAXBException",
"{",
"if",
"(",
"!",
"logging",
"||",
"!",
"isScoring",
"(",
")",
")",
"return",
";",
"totalRewards",
"=",
"0.0",
";",
"String",
"missionXml",
"=",
"SchemaHelper",
".",
"serialiseObject",
"(",
"missionInit",
".",
"getMission",
"(",
")",
",",
"Mission",
".",
"class",
")",
";",
"String",
"hash",
";",
"try",
"{",
"hash",
"=",
"digest",
"(",
"missionXml",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"hash",
"=",
"\"\"",
";",
"}",
"List",
"<",
"AgentSection",
">",
"agents",
"=",
"missionInit",
".",
"getMission",
"(",
")",
".",
"getAgentSection",
"(",
")",
";",
"String",
"agentName",
"=",
"agents",
".",
"get",
"(",
"missionInit",
".",
"getClientRole",
"(",
")",
")",
".",
"getName",
"(",
")",
";",
"StringBuffer",
"message",
"=",
"new",
"StringBuffer",
"(",
"\"<MissionInit><MissionDigest>\"",
")",
";",
"message",
".",
"append",
"(",
"hash",
")",
";",
"message",
".",
"append",
"(",
"\"</MissionDigest>\"",
")",
";",
"message",
".",
"append",
"(",
"\"<AgentName>\"",
")",
";",
"message",
".",
"append",
"(",
"agentName",
")",
";",
"message",
".",
"append",
"(",
"\"</AgentName></MissionInit>\"",
")",
";",
"if",
"(",
"scoringPolicy",
"==",
"TOTAL_WITH_MISSION_XML",
")",
"message",
".",
"append",
"(",
"missionXml",
")",
";",
"log",
"(",
"message",
".",
"toString",
"(",
")",
")",
";",
"}"
] | Record a secure hash of the mission init XML - if scoring. | [
"Record",
"a",
"secure",
"hash",
"of",
"the",
"mission",
"init",
"XML",
"-",
"if",
"scoring",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java#L74-L99 |
23,085 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java | ScoreHelper.logReward | public static void logReward(String reward) {
if (!logging || !isScoring())
return;
if (scoringPolicy == LOG_EACH_REWARD) {
log("<Reward>" + reward + "</Reward>");
} else if (scoringPolicy == TOTAL_ALL_REWARDS || scoringPolicy == TOTAL_WITH_MISSION_XML) {
int i = reward.indexOf(":");
totalRewards += Double.parseDouble(reward.substring(i + 1));
}
} | java | public static void logReward(String reward) {
if (!logging || !isScoring())
return;
if (scoringPolicy == LOG_EACH_REWARD) {
log("<Reward>" + reward + "</Reward>");
} else if (scoringPolicy == TOTAL_ALL_REWARDS || scoringPolicy == TOTAL_WITH_MISSION_XML) {
int i = reward.indexOf(":");
totalRewards += Double.parseDouble(reward.substring(i + 1));
}
} | [
"public",
"static",
"void",
"logReward",
"(",
"String",
"reward",
")",
"{",
"if",
"(",
"!",
"logging",
"||",
"!",
"isScoring",
"(",
")",
")",
"return",
";",
"if",
"(",
"scoringPolicy",
"==",
"LOG_EACH_REWARD",
")",
"{",
"log",
"(",
"\"<Reward>\"",
"+",
"reward",
"+",
"\"</Reward>\"",
")",
";",
"}",
"else",
"if",
"(",
"scoringPolicy",
"==",
"TOTAL_ALL_REWARDS",
"||",
"scoringPolicy",
"==",
"TOTAL_WITH_MISSION_XML",
")",
"{",
"int",
"i",
"=",
"reward",
".",
"indexOf",
"(",
"\":\"",
")",
";",
"totalRewards",
"+=",
"Double",
".",
"parseDouble",
"(",
"reward",
".",
"substring",
"(",
"i",
"+",
"1",
")",
")",
";",
"}",
"}"
] | Log a reward. | [
"Log",
"a",
"reward",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java#L102-L111 |
23,086 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java | ScoreHelper.logMissionEndRewards | public static void logMissionEndRewards(Reward reward) throws JAXBException {
if (!logging || !isScoring())
return;
if (scoringPolicy == LOG_EACH_REWARD) {
String rewardString = SchemaHelper.serialiseObject(reward, Reward.class);
log("<MissionEnd>" + rewardString + "</MissionEnd>");
} else if (scoringPolicy == TOTAL_ALL_REWARDS || scoringPolicy == TOTAL_WITH_MISSION_XML) {
List<Reward.Value> values = reward.getValue();
for(Reward.Value v : values) {
totalRewards += v.getValue().doubleValue();
}
log("<MissionTotal>" + totalRewards + "</MissionTotal>");
}
totalRewards = 0.0;
} | java | public static void logMissionEndRewards(Reward reward) throws JAXBException {
if (!logging || !isScoring())
return;
if (scoringPolicy == LOG_EACH_REWARD) {
String rewardString = SchemaHelper.serialiseObject(reward, Reward.class);
log("<MissionEnd>" + rewardString + "</MissionEnd>");
} else if (scoringPolicy == TOTAL_ALL_REWARDS || scoringPolicy == TOTAL_WITH_MISSION_XML) {
List<Reward.Value> values = reward.getValue();
for(Reward.Value v : values) {
totalRewards += v.getValue().doubleValue();
}
log("<MissionTotal>" + totalRewards + "</MissionTotal>");
}
totalRewards = 0.0;
} | [
"public",
"static",
"void",
"logMissionEndRewards",
"(",
"Reward",
"reward",
")",
"throws",
"JAXBException",
"{",
"if",
"(",
"!",
"logging",
"||",
"!",
"isScoring",
"(",
")",
")",
"return",
";",
"if",
"(",
"scoringPolicy",
"==",
"LOG_EACH_REWARD",
")",
"{",
"String",
"rewardString",
"=",
"SchemaHelper",
".",
"serialiseObject",
"(",
"reward",
",",
"Reward",
".",
"class",
")",
";",
"log",
"(",
"\"<MissionEnd>\"",
"+",
"rewardString",
"+",
"\"</MissionEnd>\"",
")",
";",
"}",
"else",
"if",
"(",
"scoringPolicy",
"==",
"TOTAL_ALL_REWARDS",
"||",
"scoringPolicy",
"==",
"TOTAL_WITH_MISSION_XML",
")",
"{",
"List",
"<",
"Reward",
".",
"Value",
">",
"values",
"=",
"reward",
".",
"getValue",
"(",
")",
";",
"for",
"(",
"Reward",
".",
"Value",
"v",
":",
"values",
")",
"{",
"totalRewards",
"+=",
"v",
".",
"getValue",
"(",
")",
".",
"doubleValue",
"(",
")",
";",
"}",
"log",
"(",
"\"<MissionTotal>\"",
"+",
"totalRewards",
"+",
"\"</MissionTotal>\"",
")",
";",
"}",
"totalRewards",
"=",
"0.0",
";",
"}"
] | Log mission end rewards. | [
"Log",
"mission",
"end",
"rewards",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/ScoreHelper.java#L114-L129 |
23,087 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Client/KeyManager.java | KeyManager.fixAdditionalKeyBindings | private void fixAdditionalKeyBindings(GameSettings settings)
{
if (this.additionalKeys == null)
{
return; // No extra keybindings to add.
}
// The keybindings are stored in GameSettings as a java built-in array.
// There is no way to append to such arrays, so instead we create a new
// array of the correct
// length, copy across the current keybindings, add our own ones, and
// set the new array back
// into the GameSettings:
KeyBinding[] bindings = (KeyBinding[]) ArrayUtils.addAll(settings.keyBindings, this.additionalKeys.toArray());
settings.keyBindings = bindings;
} | java | private void fixAdditionalKeyBindings(GameSettings settings)
{
if (this.additionalKeys == null)
{
return; // No extra keybindings to add.
}
// The keybindings are stored in GameSettings as a java built-in array.
// There is no way to append to such arrays, so instead we create a new
// array of the correct
// length, copy across the current keybindings, add our own ones, and
// set the new array back
// into the GameSettings:
KeyBinding[] bindings = (KeyBinding[]) ArrayUtils.addAll(settings.keyBindings, this.additionalKeys.toArray());
settings.keyBindings = bindings;
} | [
"private",
"void",
"fixAdditionalKeyBindings",
"(",
"GameSettings",
"settings",
")",
"{",
"if",
"(",
"this",
".",
"additionalKeys",
"==",
"null",
")",
"{",
"return",
";",
"// No extra keybindings to add.",
"}",
"// The keybindings are stored in GameSettings as a java built-in array.",
"// There is no way to append to such arrays, so instead we create a new",
"// array of the correct",
"// length, copy across the current keybindings, add our own ones, and",
"// set the new array back",
"// into the GameSettings:",
"KeyBinding",
"[",
"]",
"bindings",
"=",
"(",
"KeyBinding",
"[",
"]",
")",
"ArrayUtils",
".",
"addAll",
"(",
"settings",
".",
"keyBindings",
",",
"this",
".",
"additionalKeys",
".",
"toArray",
"(",
")",
")",
";",
"settings",
".",
"keyBindings",
"=",
"bindings",
";",
"}"
] | Call this to finalise any additional key bindings we want to create in the mod.
@param settings Minecraft's original GameSettings object which we are appending to. | [
"Call",
"this",
"to",
"finalise",
"any",
"additional",
"key",
"bindings",
"we",
"want",
"to",
"create",
"in",
"the",
"mod",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Client/KeyManager.java#L57-L72 |
23,088 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/SchemaHelper.java | SchemaHelper.getJAXBContext | static private JAXBContext getJAXBContext(Class<?> objclass) throws JAXBException
{
JAXBContext jaxbContext;
if (jaxbContentCache.containsKey(objclass.getName()))
{
jaxbContext = jaxbContentCache.get(objclass.getName());
}
else
{
jaxbContext = JAXBContext.newInstance(objclass);
jaxbContentCache.put(objclass.getName(), jaxbContext);
}
return jaxbContext;
} | java | static private JAXBContext getJAXBContext(Class<?> objclass) throws JAXBException
{
JAXBContext jaxbContext;
if (jaxbContentCache.containsKey(objclass.getName()))
{
jaxbContext = jaxbContentCache.get(objclass.getName());
}
else
{
jaxbContext = JAXBContext.newInstance(objclass);
jaxbContentCache.put(objclass.getName(), jaxbContext);
}
return jaxbContext;
} | [
"static",
"private",
"JAXBContext",
"getJAXBContext",
"(",
"Class",
"<",
"?",
">",
"objclass",
")",
"throws",
"JAXBException",
"{",
"JAXBContext",
"jaxbContext",
";",
"if",
"(",
"jaxbContentCache",
".",
"containsKey",
"(",
"objclass",
".",
"getName",
"(",
")",
")",
")",
"{",
"jaxbContext",
"=",
"jaxbContentCache",
".",
"get",
"(",
"objclass",
".",
"getName",
"(",
")",
")",
";",
"}",
"else",
"{",
"jaxbContext",
"=",
"JAXBContext",
".",
"newInstance",
"(",
"objclass",
")",
";",
"jaxbContentCache",
".",
"put",
"(",
"objclass",
".",
"getName",
"(",
")",
",",
"jaxbContext",
")",
";",
"}",
"return",
"jaxbContext",
";",
"}"
] | Serialise the object to an XML string
@param obj the object to be serialised
@param objclass the class of the object to be serialised
@return an XML string representing the object, or null if the object couldn't be serialised
@throws JAXBException | [
"Serialise",
"the",
"object",
"to",
"an",
"XML",
"string"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/SchemaHelper.java#L67-L80 |
23,089 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/SchemaHelper.java | SchemaHelper.deserialiseObject | static public Object deserialiseObject(String xml, String xsdFile, Class<?> objclass) throws JAXBException, SAXException, XMLStreamException
{
Object obj = null;
JAXBContext jaxbContext = getJAXBContext(objclass);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final String schemaResourceFilename = new String(xsdFile);
URL schemaURL = MalmoMod.class.getClassLoader().getResource(schemaResourceFilename);
Schema schema = schemaFactory.newSchema(schemaURL);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
StringReader stringReader = new StringReader(xml);
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader XMLreader = xif.createXMLStreamReader(stringReader);
obj = jaxbUnmarshaller.unmarshal(XMLreader);
return obj;
} | java | static public Object deserialiseObject(String xml, String xsdFile, Class<?> objclass) throws JAXBException, SAXException, XMLStreamException
{
Object obj = null;
JAXBContext jaxbContext = getJAXBContext(objclass);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final String schemaResourceFilename = new String(xsdFile);
URL schemaURL = MalmoMod.class.getClassLoader().getResource(schemaResourceFilename);
Schema schema = schemaFactory.newSchema(schemaURL);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
StringReader stringReader = new StringReader(xml);
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader XMLreader = xif.createXMLStreamReader(stringReader);
obj = jaxbUnmarshaller.unmarshal(XMLreader);
return obj;
} | [
"static",
"public",
"Object",
"deserialiseObject",
"(",
"String",
"xml",
",",
"String",
"xsdFile",
",",
"Class",
"<",
"?",
">",
"objclass",
")",
"throws",
"JAXBException",
",",
"SAXException",
",",
"XMLStreamException",
"{",
"Object",
"obj",
"=",
"null",
";",
"JAXBContext",
"jaxbContext",
"=",
"getJAXBContext",
"(",
"objclass",
")",
";",
"SchemaFactory",
"schemaFactory",
"=",
"SchemaFactory",
".",
"newInstance",
"(",
"XMLConstants",
".",
"W3C_XML_SCHEMA_NS_URI",
")",
";",
"final",
"String",
"schemaResourceFilename",
"=",
"new",
"String",
"(",
"xsdFile",
")",
";",
"URL",
"schemaURL",
"=",
"MalmoMod",
".",
"class",
".",
"getClassLoader",
"(",
")",
".",
"getResource",
"(",
"schemaResourceFilename",
")",
";",
"Schema",
"schema",
"=",
"schemaFactory",
".",
"newSchema",
"(",
"schemaURL",
")",
";",
"Unmarshaller",
"jaxbUnmarshaller",
"=",
"jaxbContext",
".",
"createUnmarshaller",
"(",
")",
";",
"jaxbUnmarshaller",
".",
"setSchema",
"(",
"schema",
")",
";",
"StringReader",
"stringReader",
"=",
"new",
"StringReader",
"(",
"xml",
")",
";",
"XMLInputFactory",
"xif",
"=",
"XMLInputFactory",
".",
"newFactory",
"(",
")",
";",
"xif",
".",
"setProperty",
"(",
"XMLInputFactory",
".",
"IS_SUPPORTING_EXTERNAL_ENTITIES",
",",
"false",
")",
";",
"xif",
".",
"setProperty",
"(",
"XMLInputFactory",
".",
"SUPPORT_DTD",
",",
"false",
")",
";",
"XMLStreamReader",
"XMLreader",
"=",
"xif",
".",
"createXMLStreamReader",
"(",
"stringReader",
")",
";",
"obj",
"=",
"jaxbUnmarshaller",
".",
"unmarshal",
"(",
"XMLreader",
")",
";",
"return",
"obj",
";",
"}"
] | Attempt to construct the specified object from this XML string
@param xml the XML string to parse
@param xsdFile the name of the XSD schema that defines the object
@param objclass the class of the object requested
@return if successful, an instance of class objclass that captures the data in the XML string | [
"Attempt",
"to",
"construct",
"the",
"specified",
"object",
"from",
"this",
"XML",
"string"
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/SchemaHelper.java#L98-L118 |
23,090 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/SchemaHelper.java | SchemaHelper.getRootNodeName | static public String getRootNodeName(String xml)
{
String rootNodeName = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setExpandEntityReferences(false);
DocumentBuilder dBuilder = dbf.newDocumentBuilder();
InputSource inputSource = new InputSource(new StringReader(xml));
Document doc = dBuilder.parse(inputSource);
doc.getDocumentElement().normalize();
rootNodeName = doc.getDocumentElement().getNodeName();
} catch (SAXException e) {
System.out.println("SAX exception: " + e);
} catch (IOException e) {
System.out.println("IO exception: " + e);
} catch (ParserConfigurationException e) {
System.out.println("ParserConfiguration exception: " + e);
}
return rootNodeName;
} | java | static public String getRootNodeName(String xml)
{
String rootNodeName = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setExpandEntityReferences(false);
DocumentBuilder dBuilder = dbf.newDocumentBuilder();
InputSource inputSource = new InputSource(new StringReader(xml));
Document doc = dBuilder.parse(inputSource);
doc.getDocumentElement().normalize();
rootNodeName = doc.getDocumentElement().getNodeName();
} catch (SAXException e) {
System.out.println("SAX exception: " + e);
} catch (IOException e) {
System.out.println("IO exception: " + e);
} catch (ParserConfigurationException e) {
System.out.println("ParserConfiguration exception: " + e);
}
return rootNodeName;
} | [
"static",
"public",
"String",
"getRootNodeName",
"(",
"String",
"xml",
")",
"{",
"String",
"rootNodeName",
"=",
"null",
";",
"try",
"{",
"DocumentBuilderFactory",
"dbf",
"=",
"DocumentBuilderFactory",
".",
"newInstance",
"(",
")",
";",
"dbf",
".",
"setExpandEntityReferences",
"(",
"false",
")",
";",
"DocumentBuilder",
"dBuilder",
"=",
"dbf",
".",
"newDocumentBuilder",
"(",
")",
";",
"InputSource",
"inputSource",
"=",
"new",
"InputSource",
"(",
"new",
"StringReader",
"(",
"xml",
")",
")",
";",
"Document",
"doc",
"=",
"dBuilder",
".",
"parse",
"(",
"inputSource",
")",
";",
"doc",
".",
"getDocumentElement",
"(",
")",
".",
"normalize",
"(",
")",
";",
"rootNodeName",
"=",
"doc",
".",
"getDocumentElement",
"(",
")",
".",
"getNodeName",
"(",
")",
";",
"}",
"catch",
"(",
"SAXException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"SAX exception: \"",
"+",
"e",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"IO exception: \"",
"+",
"e",
")",
";",
"}",
"catch",
"(",
"ParserConfigurationException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"ParserConfiguration exception: \"",
"+",
"e",
")",
";",
"}",
"return",
"rootNodeName",
";",
"}"
] | Retrieve the name of the root node in an XML string.
@param xml The XML string to parse.
@return The name of the root node, or null if parsing failed. | [
"Retrieve",
"the",
"name",
"of",
"the",
"root",
"node",
"in",
"an",
"XML",
"string",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/SchemaHelper.java#L124-L143 |
23,091 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/AddressHelper.java | AddressHelper.setMissionControlPort | static public void setMissionControlPort(int port)
{
if (port != AddressHelper.missionControlPort)
{
AddressHelper.missionControlPort = port;
// Also update our metadata, for displaying to the user:
ModMetadata md = Loader.instance().activeModContainer().getMetadata();
if (port != -1)
md.description = "Talk to this Mod using port " + TextFormatting.GREEN + port;
else
md.description = TextFormatting.RED + "ERROR: No mission control port - check configuration";
// See if changing the port should lead to changing the login details:
//AuthenticationHelper.update(MalmoMod.instance.getModPermanentConfigFile());
}
} | java | static public void setMissionControlPort(int port)
{
if (port != AddressHelper.missionControlPort)
{
AddressHelper.missionControlPort = port;
// Also update our metadata, for displaying to the user:
ModMetadata md = Loader.instance().activeModContainer().getMetadata();
if (port != -1)
md.description = "Talk to this Mod using port " + TextFormatting.GREEN + port;
else
md.description = TextFormatting.RED + "ERROR: No mission control port - check configuration";
// See if changing the port should lead to changing the login details:
//AuthenticationHelper.update(MalmoMod.instance.getModPermanentConfigFile());
}
} | [
"static",
"public",
"void",
"setMissionControlPort",
"(",
"int",
"port",
")",
"{",
"if",
"(",
"port",
"!=",
"AddressHelper",
".",
"missionControlPort",
")",
"{",
"AddressHelper",
".",
"missionControlPort",
"=",
"port",
";",
"// Also update our metadata, for displaying to the user:",
"ModMetadata",
"md",
"=",
"Loader",
".",
"instance",
"(",
")",
".",
"activeModContainer",
"(",
")",
".",
"getMetadata",
"(",
")",
";",
"if",
"(",
"port",
"!=",
"-",
"1",
")",
"md",
".",
"description",
"=",
"\"Talk to this Mod using port \"",
"+",
"TextFormatting",
".",
"GREEN",
"+",
"port",
";",
"else",
"md",
".",
"description",
"=",
"TextFormatting",
".",
"RED",
"+",
"\"ERROR: No mission control port - check configuration\"",
";",
"// See if changing the port should lead to changing the login details:",
"//AuthenticationHelper.update(MalmoMod.instance.getModPermanentConfigFile());",
"}",
"}"
] | Set the actual port used for mission control - not persisted, could be different each time the Mod is run.
@param port the port currently in use for mission control. | [
"Set",
"the",
"actual",
"port",
"used",
"for",
"mission",
"control",
"-",
"not",
"persisted",
"could",
"be",
"different",
"each",
"time",
"the",
"Mod",
"is",
"run",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/AddressHelper.java#L64-L79 |
23,092 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/TCPSocketChannel.java | TCPSocketChannel.sendTCPString | public boolean sendTCPString(String message, int retries)
{
Log(Level.FINE, "About to send: " + message);
byte[] bytes = message.getBytes();
return sendTCPBytes(bytes, retries);
} | java | public boolean sendTCPString(String message, int retries)
{
Log(Level.FINE, "About to send: " + message);
byte[] bytes = message.getBytes();
return sendTCPBytes(bytes, retries);
} | [
"public",
"boolean",
"sendTCPString",
"(",
"String",
"message",
",",
"int",
"retries",
")",
"{",
"Log",
"(",
"Level",
".",
"FINE",
",",
"\"About to send: \"",
"+",
"message",
")",
";",
"byte",
"[",
"]",
"bytes",
"=",
"message",
".",
"getBytes",
"(",
")",
";",
"return",
"sendTCPBytes",
"(",
"bytes",
",",
"retries",
")",
";",
"}"
] | Send string over TCP to the specified address via the specified port, including a header.
@param message string to be sent over TCP
@param retries number of times to retry in event of failure
@return true if message was successfully sent | [
"Send",
"string",
"over",
"TCP",
"to",
"the",
"specified",
"address",
"via",
"the",
"specified",
"port",
"including",
"a",
"header",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/TCPSocketChannel.java#L108-L113 |
23,093 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/RewardForSendingMatchingChatMessageImplementation.java | RewardForSendingMatchingChatMessageImplementation.addChatMatchSpecToRewardStructure | private void addChatMatchSpecToRewardStructure(ChatMatchSpec c) {
Float reward = c.getReward().floatValue();
Pattern pattern = Pattern.compile(c.getRegex(), Pattern.CASE_INSENSITIVE);
patternMap.put(pattern, reward);
distributionMap.put(pattern, c.getDistribution());
} | java | private void addChatMatchSpecToRewardStructure(ChatMatchSpec c) {
Float reward = c.getReward().floatValue();
Pattern pattern = Pattern.compile(c.getRegex(), Pattern.CASE_INSENSITIVE);
patternMap.put(pattern, reward);
distributionMap.put(pattern, c.getDistribution());
} | [
"private",
"void",
"addChatMatchSpecToRewardStructure",
"(",
"ChatMatchSpec",
"c",
")",
"{",
"Float",
"reward",
"=",
"c",
".",
"getReward",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"Pattern",
"pattern",
"=",
"Pattern",
".",
"compile",
"(",
"c",
".",
"getRegex",
"(",
")",
",",
"Pattern",
".",
"CASE_INSENSITIVE",
")",
";",
"patternMap",
".",
"put",
"(",
"pattern",
",",
"reward",
")",
";",
"distributionMap",
".",
"put",
"(",
"pattern",
",",
"c",
".",
"getDistribution",
"(",
")",
")",
";",
"}"
] | Helper function for adding a chat match specification to the pattern map.
@param c the chat message specification that contains the pattern and reward. | [
"Helper",
"function",
"for",
"adding",
"a",
"chat",
"match",
"specification",
"to",
"the",
"pattern",
"map",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/MissionHandlers/RewardForSendingMatchingChatMessageImplementation.java#L61-L66 |
23,094 | Microsoft/malmo | Minecraft/src/main/java/com/microsoft/Malmo/Utils/Discrete.java | Discrete.sample | public int sample()
{
double val = this.rand.nextDouble() * this.sum;
int sample = 0;
while(sample < this.likelihoods.length){
val -= this.likelihoods[sample];
if(val < 0){
return sample;
}
sample++;
}
return this.rand.nextInt(this.likelihoods.length);
} | java | public int sample()
{
double val = this.rand.nextDouble() * this.sum;
int sample = 0;
while(sample < this.likelihoods.length){
val -= this.likelihoods[sample];
if(val < 0){
return sample;
}
sample++;
}
return this.rand.nextInt(this.likelihoods.length);
} | [
"public",
"int",
"sample",
"(",
")",
"{",
"double",
"val",
"=",
"this",
".",
"rand",
".",
"nextDouble",
"(",
")",
"*",
"this",
".",
"sum",
";",
"int",
"sample",
"=",
"0",
";",
"while",
"(",
"sample",
"<",
"this",
".",
"likelihoods",
".",
"length",
")",
"{",
"val",
"-=",
"this",
".",
"likelihoods",
"[",
"sample",
"]",
";",
"if",
"(",
"val",
"<",
"0",
")",
"{",
"return",
"sample",
";",
"}",
"sample",
"++",
";",
"}",
"return",
"this",
".",
"rand",
".",
"nextInt",
"(",
"this",
".",
"likelihoods",
".",
"length",
")",
";",
"}"
] | Sample a value from the distribution.
@return The sampled dimension | [
"Sample",
"a",
"value",
"from",
"the",
"distribution",
"."
] | 4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a | https://github.com/Microsoft/malmo/blob/4139cd6f3e52f6e893a931a1d4b70d35f8e70e5a/Minecraft/src/main/java/com/microsoft/Malmo/Utils/Discrete.java#L78-L92 |
23,095 | willowtreeapps/Hyperion-Android | hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/Hyperion.java | Hyperion.setShakeGestureSensitivity | public static void setShakeGestureSensitivity(float sensitivity) {
requireApplication();
AppComponent.Holder.getInstance(application).getPublicControl().setShakeGestureSensitivity(sensitivity);
} | java | public static void setShakeGestureSensitivity(float sensitivity) {
requireApplication();
AppComponent.Holder.getInstance(application).getPublicControl().setShakeGestureSensitivity(sensitivity);
} | [
"public",
"static",
"void",
"setShakeGestureSensitivity",
"(",
"float",
"sensitivity",
")",
"{",
"requireApplication",
"(",
")",
";",
"AppComponent",
".",
"Holder",
".",
"getInstance",
"(",
"application",
")",
".",
"getPublicControl",
"(",
")",
".",
"setShakeGestureSensitivity",
"(",
"sensitivity",
")",
";",
"}"
] | Set the sensitivity threshold of shake detection in G's. Default is 3
@param sensitivity Sensitivity of shake detection in G's. Lower is easier to activate. | [
"Set",
"the",
"sensitivity",
"threshold",
"of",
"shake",
"detection",
"in",
"G",
"s",
".",
"Default",
"is",
"3"
] | 1910f53869a53f1395ba90588a0b4db7afdec79c | https://github.com/willowtreeapps/Hyperion-Android/blob/1910f53869a53f1395ba90588a0b4db7afdec79c/hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/Hyperion.java#L35-L38 |
23,096 | willowtreeapps/Hyperion-Android | hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/Hyperion.java | Hyperion.setPlugins | public static void setPlugins(PluginSource pluginSource) {
requireApplication();
AppComponent.Holder.getInstance(application).getPublicControl().setPluginSource(pluginSource);
} | java | public static void setPlugins(PluginSource pluginSource) {
requireApplication();
AppComponent.Holder.getInstance(application).getPublicControl().setPluginSource(pluginSource);
} | [
"public",
"static",
"void",
"setPlugins",
"(",
"PluginSource",
"pluginSource",
")",
"{",
"requireApplication",
"(",
")",
";",
"AppComponent",
".",
"Holder",
".",
"getInstance",
"(",
"application",
")",
".",
"getPublicControl",
"(",
")",
".",
"setPluginSource",
"(",
"pluginSource",
")",
";",
"}"
] | Hook to manually register a plugin source.
This API does not update the Hyperion menu retroactively,
so clients should call this as early as possible.
NOTE: For most users, the default {@link java.util.ServiceLoader} implementation will suffice.
@param pluginSource the {@link PluginSource} invoked in place of the default implementation. | [
"Hook",
"to",
"manually",
"register",
"a",
"plugin",
"source",
".",
"This",
"API",
"does",
"not",
"update",
"the",
"Hyperion",
"menu",
"retroactively",
"so",
"clients",
"should",
"call",
"this",
"as",
"early",
"as",
"possible",
"."
] | 1910f53869a53f1395ba90588a0b4db7afdec79c | https://github.com/willowtreeapps/Hyperion-Android/blob/1910f53869a53f1395ba90588a0b4db7afdec79c/hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/Hyperion.java#L67-L70 |
23,097 | willowtreeapps/Hyperion-Android | hyperion-timber/src/main/java/com/willowtreeapps/hyperion/timber/model/CircularBuffer.java | CircularBuffer.enqueue | public void enqueue(T item) {
queue[head] = item;
head++;
size++;
if (head == queue.length) head = 0;
} | java | public void enqueue(T item) {
queue[head] = item;
head++;
size++;
if (head == queue.length) head = 0;
} | [
"public",
"void",
"enqueue",
"(",
"T",
"item",
")",
"{",
"queue",
"[",
"head",
"]",
"=",
"item",
";",
"head",
"++",
";",
"size",
"++",
";",
"if",
"(",
"head",
"==",
"queue",
".",
"length",
")",
"head",
"=",
"0",
";",
"}"
] | Add an item to the queue.
@param item to be added | [
"Add",
"an",
"item",
"to",
"the",
"queue",
"."
] | 1910f53869a53f1395ba90588a0b4db7afdec79c | https://github.com/willowtreeapps/Hyperion-Android/blob/1910f53869a53f1395ba90588a0b4db7afdec79c/hyperion-timber/src/main/java/com/willowtreeapps/hyperion/timber/model/CircularBuffer.java#L28-L33 |
23,098 | willowtreeapps/Hyperion-Android | hyperion-timber/src/main/java/com/willowtreeapps/hyperion/timber/model/CircularBuffer.java | CircularBuffer.getItem | @SuppressWarnings("unchecked")
public T getItem(int index) {
int target = head - 1 - index;
if (target < 0) target = size + target - head;
return (T) queue[target];
} | java | @SuppressWarnings("unchecked")
public T getItem(int index) {
int target = head - 1 - index;
if (target < 0) target = size + target - head;
return (T) queue[target];
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"T",
"getItem",
"(",
"int",
"index",
")",
"{",
"int",
"target",
"=",
"head",
"-",
"1",
"-",
"index",
";",
"if",
"(",
"target",
"<",
"0",
")",
"target",
"=",
"size",
"+",
"target",
"-",
"head",
";",
"return",
"(",
"T",
")",
"queue",
"[",
"target",
"]",
";",
"}"
] | Get the item at a position `n` positions from the head.
@param index of the item to retrieve
@return the stored item | [
"Get",
"the",
"item",
"at",
"a",
"position",
"n",
"positions",
"from",
"the",
"head",
"."
] | 1910f53869a53f1395ba90588a0b4db7afdec79c | https://github.com/willowtreeapps/Hyperion-Android/blob/1910f53869a53f1395ba90588a0b4db7afdec79c/hyperion-timber/src/main/java/com/willowtreeapps/hyperion/timber/model/CircularBuffer.java#L50-L55 |
23,099 | willowtreeapps/Hyperion-Android | hyperion-phoenix/src/main/java/com/willowtreeapps/hyperion/phoenix/ProcessPhoenix.java | ProcessPhoenix.isPhoenixProcess | public static boolean isPhoenixProcess(Context context) {
int currentPid = Process.myPid();
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();
if (runningProcesses != null) {
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.pid == currentPid && processInfo.processName.endsWith(":phoenix")) {
return true;
}
}
}
return false;
} | java | public static boolean isPhoenixProcess(Context context) {
int currentPid = Process.myPid();
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();
if (runningProcesses != null) {
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.pid == currentPid && processInfo.processName.endsWith(":phoenix")) {
return true;
}
}
}
return false;
} | [
"public",
"static",
"boolean",
"isPhoenixProcess",
"(",
"Context",
"context",
")",
"{",
"int",
"currentPid",
"=",
"Process",
".",
"myPid",
"(",
")",
";",
"ActivityManager",
"manager",
"=",
"(",
"ActivityManager",
")",
"context",
".",
"getSystemService",
"(",
"Context",
".",
"ACTIVITY_SERVICE",
")",
";",
"List",
"<",
"ActivityManager",
".",
"RunningAppProcessInfo",
">",
"runningProcesses",
"=",
"manager",
".",
"getRunningAppProcesses",
"(",
")",
";",
"if",
"(",
"runningProcesses",
"!=",
"null",
")",
"{",
"for",
"(",
"ActivityManager",
".",
"RunningAppProcessInfo",
"processInfo",
":",
"runningProcesses",
")",
"{",
"if",
"(",
"processInfo",
".",
"pid",
"==",
"currentPid",
"&&",
"processInfo",
".",
"processName",
".",
"endsWith",
"(",
"\":phoenix\"",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if the current process is a temporary Phoenix Process.
This can be used to avoid initialisation of unused resources or to prevent running code that
is not multi-process ready.
@return true if the current process is a temporary Phoenix Process | [
"Checks",
"if",
"the",
"current",
"process",
"is",
"a",
"temporary",
"Phoenix",
"Process",
".",
"This",
"can",
"be",
"used",
"to",
"avoid",
"initialisation",
"of",
"unused",
"resources",
"or",
"to",
"prevent",
"running",
"code",
"that",
"is",
"not",
"multi",
"-",
"process",
"ready",
"."
] | 1910f53869a53f1395ba90588a0b4db7afdec79c | https://github.com/willowtreeapps/Hyperion-Android/blob/1910f53869a53f1395ba90588a0b4db7afdec79c/hyperion-phoenix/src/main/java/com/willowtreeapps/hyperion/phoenix/ProcessPhoenix.java#L164-L176 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.