#development
1 messages · Page 9 of 1
more like Alice asks Bob for a random number
Bob is randomNumber
Alice is foo
it's called an analogy
:))
why you calling alice a fool
what did she do to you
she's a thief and stole from me
we cannot trust her for random numbers anymore
my niece is named alice
she's a spoiled brat
so
return is pretty much like
i understand it ig
i just dont know how to put it
lol
each method can return 1 value
so, once you return, java won't let you run any more code
even if the return type is void, it still won't let you run any more code
if it's not void however, that return value can be used for Alice
(if it's void Alice gets nothing :p)
am I stupid or do they just make it hard for you to download a .jar
I just opened it in intellij and built it that way
return is returning the value of 36 to variable number
since they are equal the same
OHHH
Oxygen Hydrogen Hydrogen Hydrogen
I didnt do it just incase bc of the "Your Connection is not private" classic no certification
OH³
oh
oh well
there it is!
should I go exotic with pufferfish instead of paper for my server jar 😈
ive just seen it used it the past, fork of paper
is there a spoon of paper
Alice asks Bob to do something and get back with a number to her when he is done, sometimes he will finish sooner and get back to her when he is done sooner and has nothing else to do (returns earlier), some other times he will take a bit longer while he does some additional things, but in the end gets back to Alice as well (doesn't return earlier and continues execution of some task)
int getNumberFromBob() {
if (bobIsLazy) {
return 0;
}
// do something useful
return 2;
}
usually the returned value depends on what is being done inside the useful part
but uh i'm lazy
i'll try to understand this tomorrow
get some sleep
and see if my brain is normal
oh god
how can i make a countdown display using xp bar? ik about player#setExp and player#setLevel, but player#setExp only allows values 0-1 and i have countdowns that range from 3 seconds to 10 seconds (so i cant just divide by 10 and call it a day). so how do i go about doing this so that it could work with any number?
divide by whatever your countdown is
oh true 
hey can anyone help me with command deployment?
I wanna add Enchantments names and their level in the ItemStack's lore. 3 enchantments in a line like in hypixel skyblock
any suggestions on how should I do it?
stringbuilder and a for loop
for loop over the enchantments that are on the weapon, append them to the stringbuilder, check if (i+1 % 3)
then add the stringbuilder as a string to the list<String> and clear the string builder and itll repeat till its done
ofcourse append the commas as well
@lyric gyro I finally understood this
sorry for the ping
told you it was my brain
not that I don't know the code
and I finally understood how return works
I just needed a break
string builder?
so I just searched it up and Its not quite understandable. Is there any way you can provide an example on how can I do that
you can use string for it as well
appending to a string is not performant
therefore stringbuilder is a thing
appending fundamentally is fine, it's when you do it in a loop that becomes problematic
which is extremely common
true
actually is the compiler smart enough to differentiate between
a = a + b
a = a +c
and the loop variant?
ItemStack i;
StringBuilder s = new StringBuilder();
# String s = "";
int c = 0;
List<String> l = new ArrayList<>();
i.getEchantments().forEach(e -> {
c++;
s.append(e.getName()+": "+e.getLevel()+(c < 3 ? "," : ""));
# s += e.getName()+": "+e.getLevel()+(c < 3 ? "," : "");
if(c == 3) {
c = 0;
l.add(s.toString());
# l.add(s);
s.clear();
# s = "";
}
});
Imagine if you could use more than 1 letter to name a variable
There you go. Fixed it for you.
@dusky harness
Believe it or not, I have just finished a plugin that does exactly that lol, I had to deal with Clipboard copying, fetching location, storing block offsets, rotating the clipboard content, everything you just described lmao, literally ask me anything and I'll provide you a solution for that if I already have it done in my plugin
The plugin I've made basically loads structures that the user provide (from a schematic file), finds them in the world (using signs as anchors for performance reasons), and do stuff with them
it depends, i know that the compiler has used some clever stuff for string concatenation since java 9 but im not sure if it's smart enough to transform things in loops
Hello I have the following problem, I am trying to setup my two classes for a OneToMany and a ManyToOne relation but I get this error.
Error: https://paste.gg/p/anonymous/31ee88a3dfd145fc9b0e67ade1864735
Classes: https://paste.gg/p/anonymous/1c7291b5f22f4dad8410717365aa2b52
i woukd assume that session factory cannot be null, and you have set it up to always be null
Hello again, time for regex questions
so I have this regex:
([[ꑡ][ꐇ][ꐆ][ꐅ][ꐄ]]) ([a-zA-Z0-9]+): ([a-zA-Z 0-9\W]+)
the first part and the others are just testing
what I have problems with is the first part
this regex was made to separate in three parts this string type:
ꑡ StarL0stGaming: I'm an idiot
my problem here
is that I need to parse different ranks
which is the first part
and those ranks have 3 unicode characters each
what is your actual question
getting to it
ok
forgot to do it in a single message lmao

my problem here is that I'm not able to make the regex parse those 3 characters
bc of how they are encapsulated
have you considered |
it tries to only parse one of then
what does it do?
this is my test btw
it only parses the last character
[...] is a character set, i.e. it matches any of the characters in the set once
what you probably want is ((abc)|(d)|(e))
OR
yeah
replacing abc with the weird symbols obviously, and also the parentheses might not be necessary
so here it looks for a group that's either abc or d or e.
the last |?
dunno what you're talking about
see what?
nothing
thats right

it does work
thanks
btw
if I use that on a String#split() will it work
or do I need to do some fancy shit?
uhhhh
umm. the Regex#matcher method only works on a CharSequence
it won't split it into all of the components if that's what you're expecting
what I need for it to do is to split into three strings
based on the groups
I suppose it wont work right
#split certainly wont
what you want is to create a Matcher and then use Matcher#groups
i think
d;jdk Matcher#groups
public Matcher reset()```
Resets this matcher.
Resetting a matcher discards all of its explicit state information and sets its append position to zero. The matcher's region is set to the default region, which is its entire character sequence. The anchoring and transparency of this matcher's region boundaries are unaffected.
This matcher
yes. you are right bm
huh
docdex smells
makes sense
group(0..groupCount())
close enough
yes blitz you're right i'm right
i made that syntax up btw
Pattern is your friend
YOUR-REGEX-PATTERN.match(input)
you should be using this class almost whenever you're using regexes
wot
public final class Pattern
extends Object
implements Serializable```
Pattern has 1 extensions, 1 implementations, 1 all implementations, 11 methods, and 9 fields.
A compiled representation of a regular expression.
A regular expression, specified as a string, must first be compiled into an instance of this class. The resulting pattern can then be used to create a Matcher object that can match arbitrary character sequences against the regular expression. All of the state involved in performing a match resides in the matcher, so many matchers can share the same pattern.
A typical invocation sequence is thus
compile
A matches method is defined by this class as a convenience for when a regular expression is used just once. This method compiles an expression and matches an input sequence against it in a single invocation. The statement
is equivalent to the three statements above, though for repeated matches it is less efficient since it does...
This description has been shortened as it was too long.
1.4
d;jdk Pattern#match
public Matcher matcher(CharSequence input)```
Creates a matcher that will match the given input against this pattern.
A new matcher for this pattern
input - The character sequence to be matched
you create your Pattern
then you use the matcher method with the string as input
that gives you the matcher
^
then you can get the groups from there
can't be
ooh jpa in spigot
this is big
dont see that very often
@frigid pollen
@Id
@OneToOne(mappedBy = "player_id")
private UUID player_id;
``` I believe this is causing your issue, Hibernate has no idea what table this column is supposed to reference
try setting targetEntity = Account.class
That fixed it thanks!
Why is that? is it a bad idea?
not necessarily, just uncommon
a lot of people dont like having big jar files so you rarely see big libraries like hibernate being used
Oh
guys
can I ask you to give me ideas of what to code?
I want to do something
I just cant figure out what
because I've got to practice
what, a plugin?
a small console game is always a decent thing to do
card game, rpg, puzzle, whatever
allow players to save their progress to a file
i do not know what I need, i do not know how it works
well there's nothing you "need", it's up to you to decide what you make
how do I begin developing a software
how much experience do you actually have?
a whole one or two weeks of coding
ah
thats why i need to practice
what about a text-based bank account simulator?
let people deposit and withdraw money (basically just changing a number), saving their balance to a file
potentially add multiple accounts
seems simple enough
I already did that except I didn't do it with inputs
how did you do it then lol
I just defined the variables myself
🤨
so the user couldnt actually do anything?
no
well lol
thats just printing stuff lol
yeah
make it so the user can actually change stuff
user input handling is pretty common
and if you feel confident add the file loading / saving like i said
I am fascinated with making plugins with inputs
specially because I want to dominate them
ok
let's start
thanks man
one last question @icy shadow
do you like coding while listening to music?
what do you usually listen to
my go to for stuff like this is just my youtube music playlist
yeah
@icy shadow how do I make it so that the program doesn't stop after the first input?
so you can input multiple things running the program only once
show code please
public class sandbox {
public static void main(String[] args){
class contaDoBanco {
String nome = "João da Silva";
String endereço = "Casa dos Cacetes";
int idade = 69;
int dinheiroBase = 1000;
}
int input;
try {
input = (int) System.in.read();
} catch (IOException e) {
throw new RuntimeException(e);
}
}```
this is what i've done so far
its not finished yet
well currently it's ending because theres nothing left to do
i know
the code's reached the end, so it stops running
if you add more code then it will also run that code
similarly if you ask for another input it will wait for that second input
but what I want to do is
when you insert a number
it will either subtract from int dinheiroBase
or add
and then it will print out the result
okay so do that
but the program wont stop
because
it will wait for another input
and it will keep going for as long as you want
can I use like return statements for this?
i dont really know how they work
look, if you want to ask for another input, do that
it's really not that complicated
the program will only do what you tell it to
if you want the user to input something else, read something else from the scanner
okay but
what I am asking if there is a way so the program doesn't stop after the input
and keeps going on forever
for as long as you like
until you stop the program manually
lets say i run the program
then I input +1000
the program takes this input
adds to the int dinheiroBase
and prints out the result
then it asks for input again
ah right right
put your input handling in an infinite loop
something like while(true)
tbh I did think about that
don't know why I ignored this thought
also
I don't need that try and catch statement right?
I just added it because the ide asked and i was lazy to fix it
you do with that code
however
that is a very bad way of getting input
because it only allows you to read 1 character at a time
look into the Scanner class instead
okay
I've used scanner before
let me see how to implement it because i forgot
nah wait
if its a class then its the same as creating a new instance of a class
im stupid 💀
aight back to work
yeah don't worry
I know what I mean
you'll see
import java.io.IOException;
public class sandbox {
public static void main(String[] args) throws IOException {
int input;
String operatorDetector;
while (true) {
input = (int) System.in.read();
}
class idkAAA {
void adicionarDinheiro(){
}
}
}
}``` @icy shadow
why does it say class idkAAA is unreachable
what am I doing wrong
(also I dropped the scanner thing because I couldn't figure out how it works)
i dont think your supposed to declare a class inside of a method
maybe that's why
you are talking about the main method?
there is no issue on declaring a method inside the main class
but for some reason the ide is just being a jerk and not allowing me to do it
class idkAAA {
void adicionarDinheiro(){
}
}
this is a class
why is it inside a method
what method
it's not inside a method
i'm creating a new class with a method
i'm not creating a class inside a method
unless you are talking about the main method
which doesn't make sense afaik
you are declaring a class
not creating it
well whats the difference
by using new keyword
you create an instance of a class
by plugging it like you do
you create errors lmao
it can be inside another class
but not in a method
yeah i just added new before class
and the error disappeared
but there are two errors now
let me check what these are
you dont ad
add new like that
you need to declare the class somewhere
THEN
you instantiate it
inside your methods
can I just create a method without a class?
i cant right?
cause the class needs to be there
for what i am trying to do
yeah
that class needs to be another file
well
I think the issue is because the main method is throwing ioexception
and file 2 with the new class
no its not
thats another issue
you should catch all the exceptions that are being thrown
where you do it is up to you though
well i just removed the throws thingy and now I don't have that error anymore
that class needs to be there
for what i am trying to do
thats the problem
ok i'll do that
christ programming is too confusing
but rome wasn't built in one day i guess
@merry knoll
may sound like a stupid question but
it probably is
how do I use an integer create in one class in another class?
you know me lmao
you pass it
how do i do that again
I see
I'll do that
also
you don't get annoyed by my stupid questions right?
you know that i am learning
i mean if you tried to learn my language you would also make a lot of stupid questions
but i'd answer them
so I ask a lot of stupid questions about your language
which is java
I once asked a question
I'll ask you a question
how do I pass the variable from a class to another
I want to use the same variable in a different class
if you dont need to keep the variable
pass it in the method
if you need to reuse it later
then pass it in constructor
then put on field
import java.util.Scanner;
import java.io.IOException;
public class sandbox {
public static void main(String[] args) throws IOException {
int input;
while (true) {
input = (int) System.in.read();
}
}
}
the variable that i need to pass is input
to another class
in the same package
okay lets fix some small
but quite important mistakes first
class name
ALWAYS starts uppercase
so rename that to Sandbox
your package name, go with something like
me.yourname
for how to pass
you can define it in a function like this
public void function(Int input) {
// do stuff with input
}
you call that function like
function(15)
let me try
i wanna bang my head against the wall
i know i am doing something wrong, i know where the error is
i just dont know what
is the error
or how to solve it
that's why i am doing this
to practice
public class MoneyClass {
int baseMoney = 1000;
public void moneyAdder(int input){
String operatorDetector = null;
if(operatorDetector == "+"){
System.out.println(baseMoney + input);
}
}
}
import java.util.Scanner;
import java.io.IOException;
public class sandbox {
public static void main(String[] args) throws IOException {
int input;
input = (int) System.in.read();
}
}
here is the whole code
for context
i was trying to do a bank account simulator
where you input +(number) or -(number) to subtract or add money from your account
you dont put Class in the name
making the first letter capital means that its a clas
then call the method
first you need an instance of your MoneyClass
so MoneyClass money = new MoneyClass()
now "money" holds an instance of your MoneyClass
then you call your method
money.moneyAdder(input);
this might help
and this for oop basics
what is 'money'? you mean basemoney?
its what i named my variable
here
😮
Perfecttt
Can you give a method to get the block locations?
will this make so that when i input +1000 it will add 1000 to basemoney?
nope
for that you need to parse that string
first you need to take the first character
to see what action is being taken
then take the rest to see whats the amount
parse them to the data types you need
and do the calculation after
you do not need new classes for that though
what you do need new classes for
is storing balance of each person
what does parsing means
you have a text in hand
and you need to extract
- a calculation (+ - * /)
- an amount
from that text
thats called parsing
you are parsing the text (aka translating) into these 2 things
do a basic calculator
ill do a calculator using java's calculator?
i dont think im able to do that
You are, we'll help you 😏
well only if you help me
Wait, I'm not sure what do you need exactly, what do you mean with locations? If you just want to know all locations present in the Clipboard, Clipboard's Region (Clipboard#getRegion) is an Iterable<BlockVector3>, so you can just use Kotlin's toList on it to get a List<BlockVector3>, get all blocks by using clipboard.region.map(clipboard::getFullBlock), or get a Map<BlockVector3, BaseBlock> by associating the block with its location (aka clipboard.region.associateWith(clipboard::getFullBlock)).
In my plugin I used only offsets so I subtracted the minimum point (Clipboard#getMinimumPoint) of all the locations (so your lowest "location" offset is always 0, 0, 0, and it goes up from there). Ping me if your question was not about that.
cause im sure aki is losing patience
im kinda confused can you describe the issue in 1 message
i wanted to make a bank account simulator
that when you input like
+1000
it would add to the base ammount of cash
the issue is you are lacking extreme basic knowledge
do something simpler first
like a calculator
when you input it where, in chat?
console, he is not doing spigot stuff
im just trying to practice java
ooh okay
since im a beginner
but the issue is
when I type in +1000
nothing happens
aki said i need to parse something or whatever its called
and idk how to do that
im getting so confused
like what
aight but
in 1 message
please xd
i'll do it in one line for you
i understand now but dont type every 3 words in new message
i wntd t d a bnk acnt sm tht wn y inpt +1000 it wd + t th bse vl bt idk hw
is that clear
the thing with just the regular clipboard is that it doesn't take in the new spawn location and the rotation
So basically getting the pasted blocks from a ClipboardHolder
hmm what do you want to do exactly, are you reading a schematic file or something? cause that sounds like problem x y
#dev-general message
This is the link to the original question
I basically want to scan the new placed blocks for specific signs
but I need the signs in the new pasted location, not the location in the schematic file
cant you just convert the coords?
its just an offset
get paste location + add location in schem
you get the final location
and I'll need to rotate the blocks
I can do this yes, but if SecretX has a working & tested method already, it would be better to use his, I think (unless it's too much work "extracting" the needed code from his plugin, then it's fine)
i mean block coord in a schem
is just an offset
from the paste location effectively
i am not familiar with the api
but does it not let you check coords afterwards?
(and you can calculate rotated location too easily)
not in a documented way, no
Okay so you need to:
- Get the input
- Trim it (if you don't know what trimming is Google it)
- Check if input contain forbidden characters (not operator/number), if yes, print error message
- Parse it
- Do the bank operation
How to parse? There are few options, let's say your trimmed input is +1000
ig easiest option is to split it at 1st character so you will get the opreation (+ in this case) and the amount (1000)
So it will look like this:
- Get the input -> + 1000
- Trim it -> +1000
- Check if input contain forbidden characters (not operator/number) - ✔
- Parse it - [+, 1000]
- Do the bank operation - can look like this: https://paste.helpch.at/ulenutihes.cs
Also you want to check if operation & amount are valid (like if somebody input +++1000 it will be broken) but I would ignore it rn
yes I know but I'm just saying that it eliminate the need to test/experiment with worldedit's schematic api
So if he wants, I can just do this method
so lets see how do i start
you start from Get the input
don't worry about figuring out the entire thing before coding any of it
do you know how to read console input?
how are you letting the users give their input
dw, we were all there 😄
isn't that just reading one character at a time 😬
here's a little tool that java has:
Scanner scanner = new Scanner(System.in); // tool to read console input
String lineOfInput = scanner.nextLine();
i know about scanners
might want to just use scanners instead
i just dont know how to use them properly
this is basically the only thing you have to know
yeah but i am like
different
im dumber than a door
what do scanners read
numbers
words
If I entered hello my name is dkim19375(and pressed enter) then lineOfInput would be hello my name is dkim19375
I tried to use the native API (rotating clipboard content using ClipboardHolder) and it sucked so much that I've written my own method to do that, plus it gives you full control of what is being paste, and also control of the location
btw are you trying to code generally or you want to code in java (just curious)
for now just java
oh 💀 💀 💀 💀
lol
c# is the best i can do
i'll just erase the code
and do the whole thing again
ok
xd
?
ok
for now just try to get the input and print it (multiple times)
i'll try to use the bloody scanner
why u give him a basic oop task when he cant even do basic methods yet
what
learn extreme basics first
i can do basic methods
bro i had no idea what he could and couldnt do, all he said was that he had about 2 weeks of experience
i bet i can
technically that'll compile
yeah dude
not a local class
it's just not a great idea
Without further ado, here's the method:
fun Clipboard.rotateY(rotateDegrees: Double): Clipboard {
val rotator = AffineTransform().rotateY(-rotateDegrees)
val newMinimumPoint = rotator.apply(minimumPoint.toVector3()).toBlockPoint()
val newMaximumPoint = rotator.apply(maximumPoint.toVector3()).toBlockPoint()
val newOrigin = rotator.apply(origin.toVector3()).toBlockPoint()
val newRegion = CuboidRegion(newMinimumPoint, newMaximumPoint)
val newClipboard = BlockArrayClipboard(newRegion).apply { origin = newOrigin }
region.forEach { location ->
val oldBlock = getFullBlock(location)
val newLocation = rotator.apply(location.toVector3()).toBlockPoint()
newClipboard.setBlock(newLocation, oldBlock)
}
return newClipboard
}```
it rotates the structure by the Y axis (probably what is are also doing), and the use example is here (copy pasted from my plugin):
```kotlin
/**
* Rotate this schematic by 90 degrees four times, returning all possible 90 degrees rotations.
*/
private fun Clipboard.getAllPossibleRotations(): Set<Clipboard> =
(0..3).mapTo(mutableSetOf()) { rotateY(it.toDouble() * 90.0) }
you mean a loop?
oh lol
k*tlin
Oh wow tyyy
and it's in kotlin 🤩 🤩 🤩 🤩
ig idk how scanner works lemme check
isn't rotating a clipboard like 2 lines?
kotlin doesn't require classes 😌
no more class confusion
ez
/s (but it really doesn't require classes)
you will forget how classes work then
it's rotating the thing like you are looking to it from the top, rotating it like a clock
you rotate along one axes, idk what you mean by that
i'll try
you dont really forget stuff like that after you've been using them for years
(no matter how hard you try)
oh uh
interesting
like if I was in mc and was moving my mouse left and right
if that makes sense
but ofc you can change that by calling the other methods of AffineTransform
java = bloat just RIIR
yes, this code will compile if you copy paste just that snippet
just code in binary
imports!1!!1!
how the fuck do you use scanners
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard
import com.sk89q.worldedit.extent.clipboard.Clipboard
import com.sk89q.worldedit.math.BlockVector3
import com.sk89q.worldedit.math.transform.AffineTransform
import com.sk89q.worldedit.regions.CuboidRegion
import com.sk89q.worldedit.world.block.BlockState```
lol
not sure why you need to do all this instead of simply setting the transform in the clipboard holder but you do you, lol
i literally made a new scanner loop and it just started fucking printing nonsense
what am I doing wrong for god's sake
here
can you send the code?
import java.util.Scanner;
public class Sandbox {
public static void main(String[] args) {
Scanner bigBuxScanner = new Scanner(System.in);
while(true){
System.out.println(bigBuxScanner);
}
}
}
well
@dusky harness note that Clipboard stores not only blocks, but also biomes (?) and entities, I just couldn't be arsed to copy them all, so this method only copies the blocks
ye i dont need blocks & biomes
bruh just apply the damned transform on the holder lmao
please look here
this only works if you just want to paste the blocks and do not care where they were placed and also do not want to control anything
it "only works" if you know how to maths
surprisingly, worldedit is all about vectors
in my defense, my plugin do not paste any structures, it only deals with them in memory, and WorldEdit ClipboardHolder did not provide me a modified (in my case, rotated) Clipboard copy that I could use to query stuff, at least not one that I could find, so I just wrote one myself, and also I wrote a method to trim Clipboard region removing all sides of the cube where there is just air (and this functionality do not exist on the WE api)
it doesn't modify the clipboard itself
@cinder forum what i did wrong
it "stacks" transformations that are applied when an operation is applied
reading the holder returns the blocks with the transformations applied
You’re just converting the scanner object to a string and printing that infinitely
yeah, in my case basically useless because I needed access to the modified clipboard to query its (rotated) blocks
what am i supposed to do
what are you trying to do?
just input
and printing that input again and again and again
Ok well you have to take the input first
how
you’ve been told how to do above by a couple other people
well its infinite loop that is printing scanner
while (true) {} = infinite loop
ik ik
i just needed to add .nextline
what now
Look:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String input = scanner.nextLine();
System.out.println(input);
}
this code will took input, print it and wait for next input
use nextLine btw @lyric gyro
:)
well you can use hasNextLine & nextLine
although I usually just see hasNext
¯_(ツ)_/¯
or a while true loop also works fine
instead of next()
and in some cases a while true loop is the better method
You can easily make exit input by adding
if (input.equals("exit")) {
break;
}
to the while loop
but yes notice how he's doing nextLine on the scanner
instead of printing the scanner
i already got it
what i got to do next again
aight
lemme see
Let's come back to this
Now you want to trim the input
Which will remove whitespaces (space, new line etc)
You want to trim the input string
So you can do String input = scanner.nextLine().trim();
wait wait wait wait
do I have to make an integer named input?
i told you im restarting
wdym?
because you put input after string
also does this even count as practice?
since im basically asking for help
i don't understand, yeah, the text you enter into console is variable input which is type of string
can you send yuor code?
import java.util.Scanner;
public class Sandbox {
public static void main(String[] args) {
Scanner bigBuxScanner = new Scanner(System.in);
String input = Scanner.nextLine().trim();
while(true){
System.out.println(bigBuxScanner.nextInt());
}
}
}
okay
int/integer = whole number (basically)
i know
does it work? (because i think it shouldnt 🤔 )
it doesn't
okay nice so
it says that next line cant be referenced from a static context
ill try to understand this whole thing later
just keep saying what i've got to do
Scanner bigBuxScanner = new Scanner(System.in);
String input = Scanner.nextLine().trim(); // <--- you need to use bigBuxScanner here instead of Scanner, that's why are you getting the error
while(true){
System.out.println(bigBuxScanner.nextInt()); // <--- print the input variable here
}
ok
& put the input variable in the while loop
it should look like this
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
String input = scanner.nextLine().trim().replace(" ", "");
System.out.println(input);
if (input.equals("exit")) {
break;
}
}
(you need to add the String#replace method to remove space so if the input is +1000 or + 1000 it doesnt matter, trim doesn't remove spaces between characters, my bad)
ok
what next
- Get the input - done
- Trim it (if you don't know what trimming is Google it) - done
THIS:
- Check if input contain forbidden characters (not operator/number), if yes, print error message
- Parse it
- Do the bank operation
do you have any idea how could you do that?
if statement
something like
if(input.contains)
and then a list of forbidden characters
is this right?
and then a list of forbidden characters
Nope, there are thousands of characters, you need to list the good ones (which is only numbers and operators)
But I think there's better way
I think this is better, because it also fix this issue: "Also you want to check if operation & amount are valid (like if somebody input +++1000 it will be broken) but I would ignore it rn"
First you parse the input (basically 1st char is operator then remaining characters is number)
So you just parse the int = Integer.parseInt(num), if its number, you will get int, if its not number you will get error (which you can catch and print error message)
ok
how do i do that
Firstly you get the operator like this: char operator = input.charAt(0);
(indexes starts at zero)
k
Then you get the amount: input.substring(1, input.length() -1); (-1 because indexes starts at zero)
first value in String#substring is start index, second end index
If the end index is last index, you can omit it: input.substring(1)
so i gotta put this in my code
import java.util.Scanner;
public class Sandbox {
public static void main(String[] args) {
Scanner bigBuxScanner = new Scanner(System.in);
while(true){
String input = bigBuxScanner.nextLine().trim().replace(" ", "");
System.out.println(bigBuxScanner.nextInt());
char operator = input.charAt(0);
if (input.equals("exit")) {
break;
}
}
}
}
this correct?
yeah should be just delete System.out.println(bigBuxScanner.nextInt()); line or it will give you error when the input is not a number
now save the amount in variable by using
String amount = input.substring(1);
thats what i thought
nice
ok
import java.util.Scanner;
public class Sandbox {
public static void main(String[] args) {
Scanner bigBuxScanner = new Scanner(System.in);
while(true){
String input = bigBuxScanner.nextLine().trim().replace(" ", "");
char operator = input.charAt(0);
String amount = input.substring(1);
if (input.equals("exit")) {
break;
}
}
}
}
right
now you parse the amount
try {
Integer.parseInt(amount);
System.out.println("Amount: " + amount);
} catch (NumberFormatException ignored) {
System.out.println("ERROR! Wrong input");
}
yeah because
String amount = input.substring(1);
Then you get the amount: input.substring(1, input.length() -1); (-1 because indexes starts at zero)
first value in String#substring is start index, second end index
If the end index is last index, you can omit it: input.substring(1)
and indexes starts at zero
wait are you trying to do that when you do +100 it will add 100 to bank account then when you do -100 it will remove 100 from back account right
yes
okay nice so
you need to do +100
and the amount will be 100
and the operator will be +
mhm
it gave me 100
now we got to add a class correct?
so we can have our base value
which our input will add or remove to
you don't need to just keep it all in 1 class to keep it simple for now
do you know what switch statement does in Java?
okay so now you want to switch the operator
like this
switch (operator) {
case '+':
//will be added later
break;
case '-':
//will be added later
break;
default:
System.out.println("ERROR! Operator is not specified");
break;
}
do you understand why?
lemme see
yeah yeah
i understand
if
we will take the input
and add to the base value
if -
we will subtract
where do i add this
after the try catch block
well you can put it before it it doesn't matter
but not before operator is declared
yeah
so what now
what is the operator again
i have short lived attention
maybe thats why coding is stupidly hard for me
its the sign
- or -
first character of the input
oh right right right
Here's the whole code, I think you'll understand: https://paste.helpch.at/oyarejohub.cs
If you don't understand something just ask
i'll paste this
then
you will help me understand it fully ok
because if i dont understand fully
okay
im not practicing
where is new ammount declared
import java.util.Scanner;
public class Sandbox {
public static void main(String[] args) {
int baseAmount = 80085;
System.out.println("STARTING WITH BALANCE: " + baseAmount);
Scanner bigBuxScanner = new Scanner(System.in);
while(true){
String input = bigBuxScanner.nextLine().trim().replace(" ", "");
char operator = input.charAt(0);
String amount = input.substring(1);
try {
Integer.parseInt(amount);
System.out.println("Amount: " + amount);
} catch (NumberFormatException ignored) {
System.out.println("ERROR! Wrong input");
}
switch (operator) {
case '+':
baseAmount = baseAmount + newAmount;
break;
case '-':
baseAmount = baseAmount - newAmount;
break;
default:
System.out.println("ERROR! Operator is not specified");
break;
}
if (input.equals("exit")) {
break;
}
System.out.println("New balance: " +baseAmount);
}
}
}
Here's code with explanation: https://paste.helpch.at/agugorulep.java
If you still don't understand something just ask but I ll go to bed soon
you can try to add check if you are not in negative numbers 👍
bro i cant run the code
because newamount doesnt exist
then declare it
newamount = input??
here's explanation
line 11
compare my try block and yours
yours work
because you didnt define a base amount
but anyways
can you help me understand all this code now?
i did
im takking about this
newAmount = Integer.parseInt(amount);
you dont assign amount to newAmount
so it doesnt change
now it works
brb
dont leave
i still need your help
@cinder forum
im back
please tell me you are still there
ye
good
now lets understand the code
so first
we are creating an integer named based value
and it is equal to 0
then we are printing out
the base ammount
and a message
after that
we are creating a scanner
which will read in the input
then we are creating an inifinite while loop
then we are trimming the input
what does scanner.nextline mean
that it will continue on the next line?
if you dint know what something means in java
google "java <> docs"
and you will get official docs
so just google "java scanner docs"
i see
so
after that we are creating a char named operator
i dont remember what this does
you mean the input or variable type
charAt is for this:
String woof = "dog";
woof.charAt(0) = d
woof.charAt(1) = o
woof.charAt(2) = g
so when you do input.charAt(0)
and the input is +100
you well get the operator - plus sign
or why not just one variable - amount?
from this point forward i can understand the rest of the code
yeah you dont need to use newAmount you can just convert the amount to integer in the math operations (in the switch cases)
ty for all the help
no problemo
Object blah = getBlah1();
if (check) blah.doBlah2();```if `check` is false, is `blah` still parsed? *basically, are variables parsed before being used?*
also, how can i keep a chunk loaded with a specific item in it? im spawning an item, so if there's a way to keep a chunk loaded by location or something thats fine
for some reason my plugin's version isnt updating
it's previous version was 1.9.2 (which its stuck at for some reason), and its updated version is 1.10.0
plugin.yml:yml version: ${version}````build.gradle.kts`:kts
version = "1.10.0"
tasks {
processResources {
filesMatching("**/plugin.yml") {
expand(rootProject.project.properties)
}
}
}```the plugin's file is renamed (PLUGIN-1.10.0.jar), its just the part in plugin.yml
i think it has something to do with updating it from 1.9.x to 1.10.x
May believe for Gracie it’s @version@
Or something like that
personally i use
outputs.upToDateWhen { false }
filesMatching('**/plugin.yml') {
filter {
it.replace('@version@', project.version.toString())
}
}
}```
you can do something like this and it will work aswel
Caused by: java.lang.ClassNotFoundException: com.mongodb.client.MongoClients
at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:151) ~[paper-api-1.19-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:103) ~[paper-api-1.19-R0.1-SNAPSHOT.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
... 13 more
what does this error mean...
you need to shade it inside your jar
or make use of spigot dependency shading
I never shaded before, was it because I swapped over to paper?
https://www.spigotmc.org/wiki/plugin-yml/
use this in case you dont want maven shading (havent tested it tho)
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
no
the problem is that the dependency you added into the IDE when you are coding will not be included into the plugin jar unless you shade it using maven or gradle
so the server will not load the library and your plugin doesnt know where to refer from
plugin.yml would help if you dont know how to use maven
you just have to include the libraries config into your plugin.yml and the spigot server will download it for you
name: myplugin
.......
libraries:
- com.squareup.okhttp3:okhttp:4.9.0
oh im doing this through artifacts building
and I see the maven is included in the output layer
what IDE are you using
intellij
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>package:libraryname</include>
<include>commons-io:commons-io</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
you can try to add this to your pom.xml and it should shade it for you
i personally use expand(version: project.version)
just change the include tags inside the artifact set
it works with intellij too
nice
that saves much effort of the maven mess
but if your plugin is a public plugin then your user's server may have to download the libraries first run too
I wanna check if players are dragging items in custom inventory or in their own inventory, how can i do that with InventoryDragEvent?
i wanna cancel the drag event if they're dragging in custom inventory
check inventory title maybe? @misty dragon
Cannot invoke "dev.failures.core.Config.ConfigHandler.get()" because the return value of "dev.failures.core.Commands.SellCommand.access$000(dev.failures.core.Commands.SellCommand)" is null
access error?
Dont use inventory name
just make like a menulistener with their session stored or sth
I can't check if they're dragging in their own inventory if use gettitle
dragging is barely useful in practice so i just cancel it whenever they drag
i just use inventoryclickevent to do stuffs
its way more easier and more clear
what is the code of sellcommand.accesss$000
sellcommand file?
SellCommand.access method
I dont have that
dev.failures.core.Commands.SellCommand.access$000 this?
cant help you without the code
its coding problem from what i see
a snippet is ok
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
wait I think I see it
is it cause map is above it
yes
cuz by the time when your hashmap is initialized its before the constructor
and its before confighandler is ever initialized
so at that time when you try to do anonymous class and call methods, the confighandler is null
so you will have to make it a regular hashmap and call the put methods after confighandler = confighandler
private ConfigHandler cropValues;
public SellCommand(ConfigHandler cropValues) {
this.cropValues = cropValues;
}
Map<Material, Double> CROP_VALUES = new HashMap<Material, Double>() {{
put(Material.CACTUS, cropValues.get().getDouble("cactus-price"));
put(Material.SUGAR_CANE, cropValues.get().getDouble("sugarcane-price"));
put(Material.COCOA, cropValues.get().getDouble("cocoa-price"));
put(Material.WHEAT, cropValues.get().getDouble("wheat-price"));
}};
like this
I think im still getting the error, I'll try again
no lik
no like
private ConfigHandler cropValues;
Map<Material, Double> CROP_VALUES = new HashMap<Material, Double>() {};
public SellCommand(ConfigHandler cropValues) {
this.cropValues = cropValues;
CROP_VALUES.put(Material.CACTUS, cropValues.get().getDouble("cactus-price"));
CROP_VALUES.put(Material.SUGAR_CANE, cropValues.get().getDouble("sugarcane-price"));
CROP_VALUES.put(Material.COCOA, cropValues.get().getDouble("cocoa-price"));
CROP_VALUES.put(Material.WHEAT, cropValues.get().getDouble("wheat-price"));
}
oh alright
i mean i've tried to use only InventoryClickEvent but player can stack item in my GUI
ok fixed it using rawslot
I'm getting an issue where I have something in the map but when I access it after its empty
