The method sign.setline is not working - java

im haveing a problem running a setline command
witch i want to set the line of a sign with..
it isn't doing anything
This is the part of the code that has the setline method in it it will run with a few other things when the player will give the input (the "if (SignEvent.isNumericArray(times))" is true for sure and the code is running i did check that )
if (SignEvent.isNumericArray(times)){
double uses = Double.parseDouble(times);
uses = uses -1;
sign.setLine(2 , uses + "/" + str[1] + parts[1]);
if (uses <= 0){
sign.setLine(0, ChatColor.STRIKETHROUGH + "StartPayment");
}
}
i did check a few things :
no errors in console or eclipse error list
object sign is type Sign imported from import org.bukkit.block.Sign
object sign is the right sign (checked by doing e.getPlayer().sendMessage(sign.getLine(0)); it worked..
no matter what the string is it isn't working
no matter where i put this line of code its not working
the this line is running
i just have no idea what could i do to fix it i tried a lot of things and im pretty sure the problem is in the
sign.setLine(2 , uses + "/" + str[1] + parts[1]); line
any one have any idea for what did i do wrong ?
Note: no matter where in this method i put the setline method or with what string/lineIndex ,it isn't doing anything

I think you have to execute sign.update(); after a modification to apply changes.

Related

IntelliJ Idea debug/run console; System.out.flush not flushing

This has been bugging me for the last couple days, because it used to work. I upgraded my intellij and now it doesn't work. I don't want to go back, but I need an answer.
So, I'm writing a console application, and while it runs, I want to have a shell'd out display of progress. It works fine when it's running, but when I'm debugging in IntelliJ Idea, the System.out.flush() won't flush to the console unless the buffer contains a newline. I wrote the following unit test to find out if it was me or my application.
#Test
public void flushTest() {
int loops = 100;
for (int i = 0 ; i < 100 ; ++i) {
System.out.print("This is a print, does it flush : " + i + "\r");
if (i %10 == 0) {
System.out.print("\n");
}
System.out.flush();
}
}
Spoiler, it is the application. I don't know what's changed, but it makes it very difficult to debug display issues without doing a full build and running on the command line. If someone can help me figure out why this changed and/or help me fix it so It'll flush properly, I'd be very grateful.
Tested on version 2016.3.5, the problem is still there.
The bug is caused by all characters after "\r" will be cleared in the console.
For example, using a string "Test\r" will be got "Test" written to console, after cursor is moved to the left by the "\r", all the characters "Test" is cleared. So you won't see anything.
The workaround is to move "\r" to the beginning of the string. For example, "\rTest" will see the output in console.
The following codes will illustrate the bug. You will see "0000" and "111" will appear for 1 second and then all are cleared by "22".
System.out.print("0000\r");
Thread.sleep(1000);
System.out.print("111\r");
Thread.sleep(1000);
System.out.print("22\r");
Until this issue is not resolved, current workaround is to use
-Deditable.java.test.console=true (specify it in idea.properties).

Can I run a .java class in a specific java program with its variables?

So again this is one of my Java minecraft plugins, and I'm trying to make a command that runs a specific code that will run on the server, so what I stumbled on is
String code = "package code; \n"
+ "public class MyClass { \n"
+ " public void myMethod(){ \n"
+ " " + args[1] + "\n"
+ " } \n"
+ "}";
Dir.save(code, new File(getDataFolder(), "MyClass.java"));
so this is my code it will try to save the string in a file, btw please tell me if this string will work as it is meant to be.
then what I want to do In here is that I want to compile this file and run it in my server, its like an external file out side the program, so how do I do it.
How do I run this MyClass.java with the libraries of the server's codes, because I want the code to run with what the server offers from classes!
this is my code it will try to save the string in a file, btw please tell me if this string will work as it is meant to be
This part of the question could have been ommitted. You may try to run that code snippet and check if the file will be saved as you want it to; if it is, then the answer is yes. Otherwise, it is no.
It is possible to dinamically compile and execute code in the server. To achieve this effect, you may want to take a look at:
Dynamic code execution
Set up Java compiler on server?
Java's JavaCompiler interface

Minecraft 1.7.2 setting textures efficiently

I set textures in each individual file, this is the non efficient way to set it
this.setUnlocalizedName("ItemName");
this.setTextureName("MyModName:ItemName");
This way made sense to me, but didn't work:
this.setUnlocalizedName("ItemName");
this.setTextureName(OtherClassName.MODID + ":" + this.getUnlocalizedName());
the 'OtherClassName.MODID' is referring to a variable in another class that contains 'MyModName'
The this.getUnlocalizedName() gets the UnlocalizedName that has been declared, 'ItemName'
Any help? I am not sure why it doesn't work.
getUnlocalizedName is slightly weird - it returns the string you passed into setUnlocalizedName, but with "item." at the start. The joys of working with deobfuscated code...
This would work:
String name = "ItemName";
this.setUnlocalizedName(name);
this.setTextureName(OtherClassName.MODID + ":" + name);
Note that it's not more efficient as in faster to run, but it might be faster to write if you change the item name a lot.

Inconvertible Types in PuTTY (unix) But Not Eclipse

I am getting an error when I run my program in PuTTY but not in Eclipse. I have looked around online to try and find an answer to my issue, but have not been able too.
error:
dataSummary.java.227: inconvertible types
found: java.lang.Object
required: int
int contractIDDisplay = (int) int intr.next();
^
1 error
and here is the code:
Iterator itr = set.iterator();
while (itr.hasNext())
{ //while
int contractIDDisplay = (int) itr.next();
if (contractIDDisplay == 1)
{
System.out.printf("%d, %d, %d, %d",contractIDDisplay, monthCounter1, firstDate1, lastDate1);
file.format(contractIDDisplay + ", " + monthCounter1 + ", " + firstDate1 + ", " + lastDate1 + ", ");
}
There is more code before and after the these lines, however I do not think those lines are important. If they are please let me know. "set" is a Set.
Why would Eclipse be able to run my code and PuTTY not? Is there a way I can work around this issue if it cannot be fixed?
When you run Java from the command line, you might be invoking a different version of Java than the one that runs eclipse. It's not uncommon for a system to have multiple installations of java - over time folks upgrade, patch, whatever and end up with parallel installations. The key question is which version of java is in your PATH when you execute java from the command line?
One way to find out is to run "java --version" from the command line and see if it's what you expect.
You can then compare that to the version referenced in your eclipse.ini file.
Well I don't know why you're talking about PUTTY but in JAVA int isn't an object Integer is.
Eclipse (well I think it's the compiler) may autocast int to Integer, while the other compiler won't.
Try using Integer instead of int. Then you can call intValue() if the object isn't NULL
If you use Sun, you may be interested by this link also : http://geek.starbean.net/?p=160

Eclipse debugger "jumps" skipping important code

I have a weird problem debugging an android application.
To be accurate, I copy here the exact code I'm running on:
// Get the puzzles from cache
List<PuzzleDetails> newPuzzles = m_cachedPuzzles.getPuzzles(count);
if(newPuzzles.size() > 0){
// Remove from cache
m_cachedPuzzles.removePuzzles(newPuzzles); // LINE (A)
// Add the new puzzles from cache immediately
m_ownedPuzzles.addPuzzles(newPuzzles);
Log.d("requests", "" + newPuzzles.size() + " moved from cache to user");
}
int left = count - newPuzzles.size();
String deviceId = ResourcesPublisher.getInstance().getDeviceId();
// Don't let anyone else use these points for now
ChallengePointsManagerImpl.getInstance().usePoints(left);
Log.d("requests", "aquirePuzzles(" + left + ")");
// Get a list of requests for 'left' number of puzzles
RequestList reqList = getRequestList(left);
// TODO this is a bug, now
if(reqList.size() > 1){
reqList = getRequestList(left); // LINE (B)
}
When I run on this code, after stepping over the line (A)
m_cachedPuzzles.removePuzzles(newPuzzles);
The debugger "jumps" to the last line (B)
reqList = getRequestList(left);
A simple check shows it really skipped all code between these code lines.
For example the Log.d(...) was never called nor written.
Can anyone give me a clue why does it happen???
Thanks!
Try to do a right click > refresh on the project as it appears on the Project Explorer after you compile the code and before you start debugging.
Perhaps an exception was thrown from line A, and the next step corresponds to it closing off this stack frame?
mIsReaded = (mIsReaded)?false:true;
//mIsReaded = !mIsReaded;
saveReadFlag();
refreshUI();
Toast.makeText(getSherlockActivity(),...
In my case commented codeline cause the similar problem (two lines are skipped). For to solve it I just changed this line by codeline posted above (I mean mIsReaded = (mIsReaded)?false:true;) So different cases haves different solutions. It is result of code optimization by compiler, so please refactor something in (inside)
m_cachedPuzzles.removePuzzles(newPuzzles);
I had the same problem. The thing is, you are probably debugging the code that is in your IDE and not the on on the server. You have to deploy the code from the IDE (Eclypse, Netbeans etc.) on the server. It worked for me! Good luck!
Not directly related to Eclipse but I experienced a similar problem using the Xamarin Extension for Visual Studio and my realization may be of some help. I was developing an App with a Class library. when i made changes to the library then began emulating my App, the DLL wouldn't always rebuild so the debugger would step through the PDB as it was before my latest changes. After rebuilding the DLL, it would step through fine.
In short, rebuild dependencies if there are any changes made.
Hope you solve your issue. Have a good one
comment TODO using multi-line comment
/*// TODO this is a bug, now*/
and try again.

Categories