I'm trying to create and "IDE" for minecraft commands. I'm trying to implement command autocomplete and i can't figure out how to do it. That's a try with bukkit:
// Example command
String fullCommand = "fill 3 ";
String command = "";
List<String> argList = new ArrayList<>();
for (String string : fullCommand.split(" ")) {
if (command == "") {
command = string;
} else {
argList.add(string);
}
}
Command cmd = new Command(command) {
#Override
public boolean execute(CommandSender arg0, String arg1, String[] arg2) {
return false;
}
};
System.out.println(command);
TabCompleter tabCompleter = getCommand(command).getTabCompleter();
tabCompleter.onTabComplete(Bukkit.getConsoleSender(), cmd, command, argList.toArray(new String[0]));
I'm getting the following error:
java.lang.NullPointerException
at de.simonmeusel.mcide.plugin.Plugin.onEnable(Plugin.java:44) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) ~[s
pigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
.java:340) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
r.java:405) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin(CraftServer.jav
a:361) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins(CraftServer.
java:321) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.craftbukkit.v1_9_R1.CraftServer.reload(CraftServer.java:74
5) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.Bukkit.reload(Bukkit.java:539) [spigot-1.9.2.jar:git-Spigo
t-e000104-4cb3258]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
25) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
1) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServe
r.java:645) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchServerCommand(Craf
tServer.java:631) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at net.minecraft.server.v1_9_R1.DedicatedServer.aL(DedicatedServer.java:
438) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:4
01) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:6
60) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java
:559) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_73]
Is there any way to this in bukkit, forge or something else?
try changing:
TabCompleter tabCompleter = getCommand(command).getTabCompleter();
to
getCommand(command).setTabCompleter(new TabCompleter() {
#Override
public List<String> onTabComplete(Sender s, Command cmd, String label, String[] args) {
if(s instanceof ConsoleSender && cmd.equalsIgnoreCase("fill") {
return argList;
}
}
});
Also remove the last line.
If you have any doubts or if you are having any errors with the code, reply to this answer.
(Picture of error) try:
You're getting a Null Pointer, make sure the plugin.yml is outside of the src.
Also make sure no errors! And you should be fine.
1. This also depends on what spigot/bukkit jar ur using. 1.9+ has renamed a lot!
Related
After upgrading to selenium Java 3.8.1 the wait.until(ExpectedCondition) has started giving error message.
For the following piece of code
WebElement framei = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='ctl00_ContentPlaceHolder1_dlgModal_IFrame']")));
driver.switchTo().frame(framei);
WebElement AcceptRadioButton=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='RblStatus']/tbody/tr[1]/td/label")));
AcceptRadioButton.click();
The following error is given:
Type The method until(Function<? super WebDriver,V>) in the type FluentWait<WebDriver> is not applicable for the arguments (ExpectedCondition<WebElement>)
I tried to resolve the following issue by removing the Selenium java version 3.8.1 of
Same problem as you but not so sure about Eugene S answer I search in sources of selenium-java 2.53.1 and 3.8.1 to see what was different between FluentWait class. Here are until fonctions of the different version:
2.53.1 :
public void until(final Predicate<T> isTrue) {
until(new Function<T, Boolean>() {
public Boolean apply(T input) {
return isTrue.apply(input);
}
public String toString() {
return isTrue.toString();
}
});
}
OR
public <V> V until(Function<? super T, V> isTrue) {
long end = clock.laterBy(timeout.in(MILLISECONDS));
Throwable lastException = null;
while (true) {
try {
V value = isTrue.apply(input);
if (value != null && Boolean.class.equals(value.getClass())) {
if (Boolean.TRUE.equals(value)) {
return value;
}
} else if (value != null) {
return value;
}
} catch (Throwable e) {
lastException = propagateIfNotIgnored(e);
}
// Check the timeout after evaluating the function to ensure conditions
// with a zero timeout can succeed.
if (!clock.isNowBefore(end)) {
String message = messageSupplier != null ?
messageSupplier.get() : null;
String toAppend = message == null ?
" waiting for " + isTrue.toString() : ": " + message;
String timeoutMessage = String.format("Timed out after %d seconds%s",
timeout.in(SECONDS), toAppend);
throw timeoutException(timeoutMessage, lastException);
}
try {
sleeper.sleep(interval);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new WebDriverException(e);
}
}
}
AND IN 3.8.1:
public <V> V until(Function<? super T, V> isTrue) {
long end = clock.laterBy(timeout.in(MILLISECONDS));
Throwable lastException;
while (true) {
try {
V value = isTrue.apply(input);
if (value != null && (Boolean.class != value.getClass() || Boolean.TRUE.equals(value))) {
return value;
}
// Clear the last exception; if another retry or timeout exception would
// be caused by a false or null value, the last exception is not the
// cause of the timeout.
lastException = null;
} catch (Throwable e) {
lastException = propagateIfNotIgnored(e);
}
// Check the timeout after evaluating the function to ensure conditions
// with a zero timeout can succeed.
if (!clock.isNowBefore(end)) {
String message = messageSupplier != null ?
messageSupplier.get() : null;
String timeoutMessage = String.format(
"Expected condition failed: %s (tried for %d second(s) with %s interval)",
message == null ? "waiting for " + isTrue : message,
timeout.in(SECONDS), interval);
throw timeoutException(timeoutMessage, lastException);
}
try {
sleeper.sleep(interval);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new WebDriverException(e);
}
}
}
I don't see any difference between the three functions arguments but the project I work on did not return me any error with 2.53.1 version but with 3.8.1 I have the same error than Akhil.
As it says in the error message:
FluentWait<WebDriver> is not applicable for the arguments (ExpectedCondition<WebElement>)
Starting from Selenium 3, until method declaration now looks like this:
public <V> V until(Function<? super T, V> isTrue)
where Function is:
public interface Function<T, R>
So it has been converted to use Java 8 functional interface. You will need to rewrite your expected conditions accordingly.
As per best practices we must try to switch to a <iframe> with proper WebDriverWait as follows :
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#id='ctl00_ContentPlaceHolder1_dlgModal_IFrame']")));
#Override
protected ArrayList<HashMap<String, String>> doInBackground(Void... params) {
ArrayList<HashMap<String, String>> PLIST = new ArrayList<>();
HttpHandler sh = new HttpHandler();
String jsonStr = sh.makeServiceCall(jsonUrl);
ArrayList<String> URLList = new ArrayList<>();
if (jsonStr != null) {
placesList.clear();
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray placesJsonArray = jsonObj.getJSONArray("results");
String pToken = "";
// looping through All Places
for (int i = 0; i < placesJsonArray.length(); i++) {
JSONObject placesJSONObject = placesJsonArray.getJSONObject(i);
String id = placesJSONObject.getString("id");
String name = placesJSONObject.getString("name");
HashMap<String, String> places = new HashMap<>();
// adding each child node to HashMap key => value
places.put("id", id);
places.put("name", name);
PLIST.add(places);
}
//TODO: fix this...
if (SEARCH_RADIUS == 1500) {
Log.e(TAG, "did it get to 1500?");
try {
for (int k = 0; k < 2; k++) {
//error is no value for next_page_token... this
ERROR HERE
pToken = jsonObj.getString("next_page_token"); //if I place breakpoint here, debugger runs correctly, and returns more than 20 results if there is a next_page_token.
String newjsonUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="
+ midpointLocation.getLatitude() + "," + midpointLocation.getLongitude()
+ "&radius=" + SEARCH_RADIUS + "&key=AIzaSyCiK0Gnape_SW-53Fnva09IjEGvn55pQ8I&pagetoken=" + pToken;
URLList.add(newjsonUrl);
jsonObj = new JSONObject(new HttpHandler().makeServiceCall(newjsonUrl)); //moved
Log.e(TAG, "page does this try catch");
}
}
catch (Exception e ) {
Log.e(TAG, "page token not found: " + e.toString());
}
for (String url : URLList){
Log.e(TAG, "url is : " + url);
}
I made an ArrayList of URLS after many attempts to debug this code, I planned on unpacking the ArrayList after all the urls with next_page_tokens were added, and then parsing through each of them later. When running the debugger with the breakpoint on pToken = getString("next_page_token") i get the first url from the Logger, and then the second url correctly. When I run as is, I get the first url, and then the following error: JSONException: No value for next_page_token
Things I've tried
Invalidating Caches and restarting
Clean Build
Run on different SDK versions
Made sure that the if statement is hitting (SEARCH_RADIUS == 1500)
Any help would be much appreciated, thanks!
Function is called in a listener function like this.
new GetPlaces(new AsyncResponse() {
#Override
public void processFinish(ArrayList<HashMap<String, String>> output) {
Log.e(TAG, "outputasync:" );
placesList = output;
}
}).execute();
My onPostExecute method.
#Override
protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
delegate.processFinish(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
It turns out that the google places api takes a few milliseconds to validate the next_page_token after it is generated. As such, I have used the wait() function to pause before creating the newly generated url based on the next_page_token. This fixed my problem. Thanks for the help.
Managed to download .zip file to my filesystem on mobile phone. But after a while realised I can't find a way how to unzip that file. As I tried with:
https://github.com/plrthink/react-native-zip-archive
https://github.com/remobile/react-native-zip
First one dies immidiately after requiring, getting error "Cannot read property 'unzip' of undefined" (followed instructions carefully)
And the second one dies because it's dependant on codrova port to react native which also doesn't work.
Any suggestions or way to solve these problems?
Using react-native 0.35, testing on Note4 with android 5.1.1.
I did manage in the end solve my problem:
using react-native-zip-archive
the solution was to change code inside:
RNZipArchiveModule.java file which is inside module
The changes that needed to be applied are written in this comment:
https://github.com/plrthink/react-native-zip-archive/issues/14#issuecomment-261712319
So credits to hujiudeyang for solving problem.
go to this direction :
node_modules\react-native-zip-archive\android\src\main\java\com\rnziparchive\RNZipArchiveModule.java
and replace this codes instead of unzip method
public static void customUnzip(File zipFile, File targetDirectory) throws IOException {
ZipInputStream zis = new ZipInputStream(
new BufferedInputStream(new FileInputStream(zipFile)));
try {
ZipEntry ze;
int count;
byte[] buffer = new byte[8192];
while ((ze = zis.getNextEntry()) != null) {
File file = new File(targetDirectory, ze.getName());
File dir = ze.isDirectory() ? file : file.getParentFile();
if (!dir.isDirectory() && !dir.mkdirs())
throw new FileNotFoundException("Failed to ensure directory: " +
dir.getAbsolutePath());
if (ze.isDirectory())
continue;
FileOutputStream fout = new FileOutputStream(file);
try {
while ((count = zis.read(buffer)) != -1)
fout.write(buffer, 0, count);
} finally {
fout.close();
}
/* if time should be restored as well
long time = ze.getTime();
if (time > 0)
file.setLastModified(time);
*/
}
} finally {
zis.close();
}
}
//**************************
#ReactMethod
public void unzip(final String zipFilePath, final String destDirectory, final String charset, final Promise promise) {
new Thread(new Runnable() {
#Override
public void run() {
try {
customUnzip(new File(zipFilePath ) , new File(destDirectory));
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
I want to execute SSIS package using command line arguments.
As we can do it in executing C# project. And i want to use that argument.
CmdLineArguments: INTRADAY OPT OPTION_DAILY_INTRADAY_VOL12/02/2014
And then i want to use these different vlues to do some operations.
What I have got: I searched on line and got that we have to give something like below
dtexec /file Package.dtsx /Set \Package.Variables[User::UniversFileAddress].Properties[Value];\" INTRADAY OPT OPTION_DAILY_INTRADAY_VOL12/02/2014\"
which have no effect on execution. i mean it's not working for me. May be my concept is wrong.
whereas i want to pass arguments as below
INTRADAY OPT OPTION_DAILY_INTRADAY_VOL12/02/2014
And use these arguments in script task.
How can i do so..?
There are many ways actually but i found following way suitable for my application.
Create a console application.
Call that ssis package in that application.
And you can set varible values in that console application
here is the code:
using Microsoft.SqlServer.Dts.Runtime;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] argsArray = new string[] {"","","","" };
if (args == null)
Console.WriteLine("args is null");
else
{
if (args.Length > 4)
{
}
else if (args.Length > 3)
{
for (int i=0;i<args.Length;i++)
{
argsArray[i] = args[i];
}
}
}
string pkglocation="h:\\My Documents\\Visual Studio 2008\\Projects\\Try_Project_To_Convert_Fro_Asia_Euro_US\\Try_Project_To_Convert_Fro_Asia_Euro_US\\Package.dtsx";
Application app= new Application();
Package Pkg=app.LoadPackage(pkglocation ,null);
Pkg.Variables["User::fileName"].Value = argsArray[2] + argsArray[3].Substring(6, 4) + argsArray[3].Substring(3, 2) + argsArray[3].Substring(0, 2);
string test = (string )Pkg.Variables["User::fileName"].Value;
Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = Pkg.Execute();
if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
{
string err = "";
foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in Pkg.Errors)
{
string error = local_DtsError.Description.ToString();
err = err + error;
}
}
if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
{
string message = "Package Executed Successfully....";
}
}
}
Please let me know if you have any problem
I am using powermock to mock some native command invocation using process builder. the strange thing is these test pass sometimes and fail sometimes giving a NPE. Is this a powermock issue or some gotcha in the program.
Here is a snippet of the class I am testing:
public void method1(String jsonString, String filename) {
try {
JSONObject jObj = new JSONObject(jsonString);
JSONArray jArr = jObj.getJSONArray("something");
String cmd = "/home/y/bin/perl <perlscript>.pl<someConstant>" + " -k " + <someConstant> + " -t " + <someConstant>;
cmd += vmArr.getJSONObject(i).getString("jsonKey");
ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
pb.redirectErrorStream(false);
Process shell = pb.start();
shell.waitFor();
if (shell.exitValue() != 0) {
throw new RuntimeException("Error in Collecting the logs. cmd="+cmd);
}
StringBuilder error = new StringBuilder();
InputStream iError = shell.getErrorStream();
BufferedReader bfr =
new BufferedReader(
new InputStreamReader(iError));
String line = null;
while ((line = bfr.readLine()) != null) {
error.append(line + "\n");
}
if (!error.toString().isEmpty()) {
LOGGER.error(error`enter code here`);
}
iError.close();
bfr.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
and the unit test case is:
#PrepareForTest( {<Classtobetested>.class, ProcessBuilder.class,Process.class, InputStream.class,InputStreamReader.class, BufferedReader.class} )
#Test(sequential=true)
public class TestClass {
#Test(groups = {"unit"})
public void testMethod() {
try {
ProcessBuilder prBuilderMock = createMock(ProcessBuilder.class);
Process processMock = createMock(Process.class);
InputStream iStreamMock = createMock(InputStream.class);
InputStreamReader iStrRdrMock = createMock(InputStreamReader.class);
BufferedReader bRdrMock = createMock(BufferedReader.class);
String errorStr =" Error occured";
String json = <jsonStringInput>;
String cmd = "/home/y/bin/perl <perlscript>.pl -k "+<someConstant>+" -t "+<someConstant>+" "+<jsonValue>;
expectNew(ProcessBuilder.class, "bash", "-c", cmd).andReturn(prBuilderMock);
expect(prBuilderMock.redirectErrorStream(false)).andReturn(prBuilderMock);
expect(prBuilderMock.start()).andReturn(processMock);
expect(processMock.waitFor()).andReturn(0);
expect(processMock.exitValue()).andReturn(0);
expect(processMock.getErrorStream()).andReturn(iStreamMock);
expectNew(InputStreamReader.class, iStreamMock)
.andReturn(iStrRdrMock);
expectNew(BufferedReader.class, iStrRdrMock)
.andReturn(bRdrMock);
expect(bRdrMock.readLine()).andReturn(errorStr);
expect(bRdrMock.readLine()).andReturn(null);
iStreamMock.close();
bRdrMock.close();
expectLastCall().once();
replayAll();
<ClassToBeTested> instance = new <ClassToBeTested>();
instance.method1(json, fileName);
verifyAll();
} catch (Exception e) {
Assert.fail("failed while collecting log.", e);
}
}
I get an error on execution and the test case fails..
Caused by: java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:438)
Note: I do not get this error on all executions. Sometimes it passes and sometimes it fails. I am not able to understand this behavior. Also, I have camouflaged some variable names because of the copyright issues.
Since your are mocking the constructor call you have to prepare your code as wall. This is because the constructor invocation is part of your code. Read more in the PowerMock documentation:
http://code.google.com/p/powermock/wiki/MockConstructor