#help-development
1 messages · Page 616 of 1
so the reason for Function and Predicate is for like mega softcoded code basically
kinda
Yeah, just pushing functionality to the caller instead
ohh
Helps make methods, or really anything that accepts a functional interface, a bit more flexible
and it helps people edit the code quickly
i seeeee
thanks so much
this helps alot
We do some callback stuff in Bukkit. The ones that come to mind immediately is a Consumer<T extends Entity> for World#spawn() to call methods on an entity before it's added to the world, and a Consumer<BlockData> for Material#createBlockData() to edit BlockData before it's returned
We seldom expose Predicates because it can be leaky API but the aforementioned methods are exclusive to Bukkit API so it's fine
Doesn’t Bukkit api have its own consumer too
If im writing a licence system with JNI is it fine to make the onEnable native?
yeah for pre Java 8. A mistake imo
We really don't like native code because it's a lot more difficult for us to verify what you're doing

Though a license system is already a red flag
ah
public class Main {
public static void main(String[] args) {
Testing<Integer> testing = new Testing<>();
testing.function(integer -> integer * 5);
}
static class Testing<K> {
public void check(Iterable<K> iterable, Predicate<K> predicate) {
iterable.forEach(integer -> {
if (predicate.test(integer)) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
}
});
}
public void function(Function<Integer, K> function) {
System.out.println(function.apply(5));
}
}
}``` which would return `25` right?
since apply would replace integer with 5
5 * 5 = 25
There is an IntUnaryOperator as well which would accept an int and return an int which is probably better suited in this specific scenario, but ye
Honestly so many types to remember, but a full list is here https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/function/package-summary.html
hmm
alr
so
public class Main {
public static void main(String[] args) {
Testing<Integer> testing = new Testing<>();
testing.function(integer -> integer * 5);
}
static class Testing<K extends Integer> {
public void check(Iterable<K> iterable, IntPredicate predicate) {
iterable.forEach(integer -> {
if (predicate.test(integer)) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
}
});
}
public void function(IntFunction<K> function) {
System.out.println(function.apply(5));
}
}
}```?
Yeah that would print out 25
Is there an API to check plugin updates, changelogs, etc. from spigot?
And if one of the stdlib interfaces don't fit your needs, you can make your own functional interface pretty easily
@FunctionalInterface // Compiler hint. Yells at you if there's more than one method in the interface
public interface PersonCreator {
public Person createPerson(String name, int age);
}
PersonCreator creator = (name, age) -> new Person(name, age); // Can technically be simplified to Person::new
Person choco = creator.createPerson("Choco", 23);
There is https://hub.spigotmc.org/changelog/ already but that uses the Stash's commit history iirc
I don't remember how to get the RSS stream
lol, also one more question if you dont mind
um, i have troubles naming classes / interfaces. I follow the java naming conventions but i just cant think of good names for them
any tips for that?
tbf, just follow CamelCase conventions and name it whatever you think makes the most sense
There's no strict guidelines for how to name your classes one way or another
i lied one more question xD
the best way to tackle enums is switch cases?
i've always wondered how to fully use enums
i'm guessing so since i've seen these in API's on github
That's some ugly code. In Java 17 we'd do this because we have switch expressions now
public static InteractionHand fromEquipmentSlot(EquipmentSlot slot) {
return switch (slot) {
case HAND -> MAIN_HAND;
case OFF_HAND -> OFF_HAND;
default -> null;
};
}```
Depends on what you need. Sometimes you don't need the exhaustiveness of a switch to handle all cases
Sometimes you only need to check one or two constants
Yeah
intellij allows you to disable that inspection 🤨
okay i got
@Override
public void saveData(@NotNull PlayerData value, @NotNull Predicate<PlayerData> predicate) {
if (predicate.test(value)) {
// TODO: save data to storage file
}
}``` this would be right correct?
be dumb to disable that seeing as it would nolonger be a FunctionalInterface if you added another method
The same issue still occurs to what I had before (currently serializing to byte stream, then to base64, then into the json object) but I found out that after deserializing, it somehow becomes org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack as opposed to org.bukkit.inventory.ItemStack. Not really sure why, but I assume this is GSON's doing so to that I say sod it and I'll just create configuration sections instead. For context, I'm randomly generating a quest - it picks 5 random objectives and 5 random rewards, but I need to save that quest data. I'll figure something out.
lmao why
Some ItemStacks are CraftItemStacks, others are ItemStacks. It depends on where you got the item
If you pull it from an inventory, or from an event, or really anywhere where it wasn't directly constructed by new ItemStack(), it's probably going to be a CraftItemStack
Well im not posting it on spigot, im just asking a simple question about it
I would likely post on BBB
I mean listen, you can try and make your onEnable() function native, but I'm unsure what benefit you believe it will bring
To make it more annoying for a weird person to crack plugin
Someone will do it anyways
ugh license system people
you do more harm than good
your code isn't that good, if your plugin is simple enough someone will recreate it and release it for free
Yes but if I spend time making a plugin and someone cracks it then that means less people would purchase from me, i could delay that by obuscating and using a licence system
those people wouldn't purchase from you anyways
flawed ass logic, don't go try to cater to the people who wouldn't buy it in the first place, its annoying
Craftitemstack is the implementation of itemstack
Cant serialize an interface
ItemStack isn’t an interface
I thought it was
How you think people be doin new Itemstack(material) then :p
Nah it's that I use an adapter for ItemStack, so it handles it but I'd need an adapter for that specific version of CraftItemStack too, entirely redundant at that point tbh
witchcraft
anything i should change here?
https://paste.md-5.net/nevirupeyu.java
it feels very chunky with ? super Player
which idk if i need
lol
now i think of it
😓
A few notes:
a. I don't imagine PlayerData will be generic with anything other than Player. Nothing extends Player (or nothing should). You're probably fine removing that generic entirely and saving yourself some headaches down the line
b. The Predicate in saveData() probably isn't super necessary if you're using it like that. The caller can probably just do a simple if statement before calling the method
Everything else seems fine
yeah i changed ? super Player to just Player xD
Well, your Optionals are annotated as @Nullable but the whole point of Optional is that they wrap a nullable value and they don't ever return null, so those should probably be NotNull but that's a nitpick
this is my interface: https://paste.md-5.net/omeqoyufog.java
oh whoops
my methods even do ofNullable
lol
Bit redundant to add such things to something that is implied
Well I just mean that you probably don't need the generic at all, right? Will it be anything other than Player? Why PlayerData<Player> if it's always going to be Player? You might as well just do just PlayerData
true dat
If you're null annotating, you annotate everything. Even the obvious ones
PlayerData<Ocelot>
well
On another note, does your PlayerData hold reference to the UUID it's associated with?
As a field, that is? Do you have a PlayerData#getUUID()?
Because this method is confusing to me
@Override
public void unloadData(@NotNull UUID key, @NotNull Map<UUID, PlayerData<? super Player>> map) { }```
1. I would imagine you wouldn't need both a UUID key and a Map<UUID, PlayerData>. You would want one or the other, probably
2. If you do just want the Map to unload multiple player data instances, perhaps a Collection<PlayerData> is better because PlayerData would have #getUUID() you could refer to rendering the Map's keys redundant
ahhh true
how about now: https://paste.md-5.net/yuxiwabine.java
i do want K extends Player
so i can change if i need too
but it looks wayyy cleaner now
What would you change it to though?
idk
HumanEntity > Player
did somebody say... Optionals?
my bukkit lib LOL
just to reduce my boilerplate
At least it isn’t a cursed fork
not yet
I'm switching to fukkit
Eventually you probably can use nothing but fork names to create some kind of story
okayy
hows this look?
https://paste.md-5.net/socosudeqo.java
it looks pretty clean to me
honestly
There's room for improvement
Not repeating yourself, returning futures because doing database operations in the main thread is bad etc
true
I'd name the class SQLStorage etc
This seems like a weird wrapper
This is how I do database stuff
ah
i was going to learn more about CompletableFuture
all ik is its better for multithreading
bam
ty
@echo basalt srry for ping but i needa know if im doing this right so i dont keep going
@Override
public CompletableFuture<Optional<PlayerData<Player>>> getDataFromFile(@NotNull Player player) {
return CompletableFuture.supplyAsync(() -> sqlHandler.loadData(player)).thenApply(data -> {
if (data == null) return Optional.empty();
PlayerData<Player> playerData;
try {
playerData = data.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
dataMap.put(player.getUniqueId(), playerData);
return Optional.of(playerData);
});
}```
or remove data == null and replace it with Optional.ofNullable
😭
idk if im doing this right
i asked ChatGPT and it says its right
but idk if i believe it
What's your data.get() method about
I mean
I expected PlayerData to be a data class
Ideally your loadData method returns the data object itself
You can supply a null value
It's a.. future
oki
A future is basically a reference of an object that'll be available in the.. future
so what should i do?
i changed somethings
@Override
public CompletableFuture<PlayerData> getDataFromFile(@NotNull Player player) {
return CompletableFuture.supplyAsync(() -> sqlHandler.loadData(player)).thenApply(data -> {
PlayerData playerData;
try {
playerData = data.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
dataMap.put(player.getUniqueId(), playerData);
return playerData;
});
}```
is your sqlHandler.loadData method returning a future?
Then you just
well shouldn't i not do that?
return sqlHandler.loadData(player).thenApply(data -> {
...
});
since it's already async?
And just work with that single future instead of creating a future of a future and joining
oh my
thanks
that helps alot
@Override
public CompletableFuture<PlayerData> getDataFromFile(@NotNull Player player) {
return sqlHandler.loadData(player).thenApply(data -> {
dataMap.put(player.getUniqueId(), data);
return data;
});
}```
its not goofy code anymore
😄
Exactly
so for my loadData method
should i do:
@Override
public CompletableFuture<PlayerData> loadData(@NotNull Player key) {
return CompletableFuture.supplyAsync(() -> {
return null;
});
}```?
I have a technical question- would it be possible to connect to the backend servers with online mode? You see, I'm attempting to join an external server but the problem is that I can't connect on online mode, I would happily put my credentials in the proxy as its running on my local machine.
I simply want to modify packets with bungeecord plugins
I am trying to use NMS (I am learning how to make plugins) and get this error when trying to add NMS to the pom.xml:
Missing artifact org.spigotmc:spigot:jar:1.20.1-R0.1-SNAPSHOT Java(0)
XML:
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
You do have the maven repo added, yes?
I have this one?
"spigot" (not spigot-api) installs into ur local .m2 repository
alright
you ran java -jar BuildTools.jar --rev 1.20.1 --remapped ?
Error: Unable to access jarfile BuildTools.jar?
do u have BuildTools downloaded?
I have no idea what I'm doing (never used NMS or BuildTools)
This should help ^
Does it matter where I put the jar file?
Yes.
BuildTools? nah
In some way, very yes.
If you want to keep it in your downloads folder, just make a seprate folder for it
Then you are good to go
cant run it from DropBox, GDrive, or OneDrive sync folders
thats abt the only hard limit on where u cant run it
.
Nope it's not.
The servers won't just check your session twice.
Its not? I've done it in javascript before.
(for security reasons obviously)
How did you even use JavaScript for an MC JAVA server...?
I mean having frontend bungee in offline mode and backend server (not mine) in online
Not possible.
it is
Using relative position in command arguments
Neither Bungee and Spigot will accept it hehhahh huhh...
i mean there is the Nashorn engine, or well, was, now theres Graal and some ppl use Mozilla Rhino
Bungee doesn't even let's you join an online mode spigot server
No I used the raw node mc protocol
I am sure you used some unsupported crap.
"unsupported"
But I'm tellin' ya, that BungeeCord DOES NOT allow you to connect to online mode Spigot servers.
Technically it does if you know how
Yeah you can, but don't except support from here then.
Thats my aim
Offline mode can't even connect to Online Mode... ._.
If its possible in one simple js file then how hard would it be to implement it in a proxy
you're thinking in the wrong way
If you set bungee to offline and the servers to online in theory it should work
It will not.
I've done it by purpose, and accident.
Neither of them allowed me to connect.
yes but I'd need to somehow auth the backend connection
I'm fine with my credentials being in the bungee
as its on my computer
Bungee doesnt handle credentials
I'm sure I could do some reverse engineering and see how the regular minecraft client authenticates
and replicate that on bungee side
MCPReborn
Basically client shares with server auth session data. Server then asks mojang auth servers if they are legit
not even
dont remind me that this exists
Mojangs auth lib is on github fyi
fair, I could use that
honestly what im thinking is making it as easy as a drop in plugin
Really all that needs to pass through is auth packets
In the proxy which shouldnt be hard
Only hard part is when players want to switch servers lol
personally I dont need to switch servers
Hence encryption stops at bungee
if u dont want to switch servers.... why even run a middle-man ?
I just tested to put bungee in offline mode, and put the Spigot into online mode. Safe to say it will not let me go on.
I have full access to send, modify, and block packets
without having to mod my client
Something to ask, how can i get the coordinate between 2 points, i have this "cube" selection (blockslist) and i want to get the corner a and b like a worldedit selection
https://paste.md-5.net/ivanatufej.cs
imagine like a corners and i want get them to then delete all of them, i already have the method i just need to get the pos1 and pos2 to delete all that amount of block
ded chat
yes even in my main language i can't express myself so that's cool, i can't even in another language
You need 2 loops for 2 dimensions. Means no moving on y. 3 loops if y changes.
just a
double minX = Double.MAX_VALUE;
minY, minZ
double maxX = Double.MIN_VALUE;
maxY, maxZ
loop through points
if(x > maxX) maxX = x;
...
y shouldn't change that's for a jackhammer seems strange (i used that name because i was doing the nuke but then they asked jackhammer and did the same code in there)
Then you only need 2 loops to interate between two opposing corners.
as imIllusion made
Yep that is the easy way
That is the proper way**
Hard way is using math to calculate all the coords. In 2d space not all that hard
Never touched SQL, how do formatting this work like what are the standards?
CREATE TABLE products
(
id VARCHAR PRIMARY KEY,
display_name VARCHAR NOT NULL,
)
As long as you use , to separate the params. Format however. Just remember there needs to be a ; at the end
private Location getMinLocation(List<Block> blocks) {
double minX = Double.MAX_VALUE;
double minY = blocks.get(0).getY();
double minZ = Double.MAX_VALUE;
for(Block block : blocks) {
if(block.getX() > minX) minX = block.getX();
}
}
should be this way?
Almost
Ah I didnt know if there was a standard for the amount of indentation
flip the <
and for the max the other way, even intelli said that was an error didn't notest
soo should be correct for the rest?
You can do both max and min in the same loop. As you would increase one way decrease the other
im making it so i can use it in a code to delete blocks that requires the locations and i don't need to recall it again
I swear I've made this code before wait
Probably from X-Prison or old UltraPrisonCore
If i was home i have a snippet for this but it uses bitshifts instead lol
I don't write prison stuff
private void calculateCuboid(Set<BlockVector> vectors) {
BlockVector min = new BlockVector(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
BlockVector max = new BlockVector(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
for (BlockVector vector : vectors) {
min.setX(Math.min(min.getBlockX(), vector.getBlockX()));
min.setY(Math.min(min.getBlockY(), vector.getBlockY()));
min.setZ(Math.min(min.getBlockZ(), vector.getBlockZ()));
max.setX(Math.max(max.getBlockX(), vector.getBlockX()));
max.setY(Math.max(max.getBlockY(), vector.getBlockY()));
max.setZ(Math.max(max.getBlockZ(), vector.getBlockZ()));
}
master = new Cuboid(min, max);
}
yeah
I have
lol
Looks like someone was nice tonight. Praise them 
?
We dont always just give complete code to people
i just finished the code right now so f
someone
one question im asking why Air is Air_Void and Air_Cave only for sounds? or for some game mechanics unkown?
Air cave is below the ground. Air void is in void space
but why not using Air and checks if the player is underground?
Mostly has to do with lighting since lighting is no longer stored in the chunk but separately
It might just be backwards-compatibility tbh
I don't see any uses in nms
And it doesn't exist in nms
It's an old material
Well its probably from 1.16 or so. Old i suppose in that sense
looks like microsoft doesn't change, they done it with windows and now with minecraft, using old code and build only on top and just put more and more
Its a mojang thing for remapping old worlds to new formats
Cave air is the air you find in caves. In this type of air you will hear cave sounds more often and bats will spawn more easily. Void air is pretty self explanatory. It's the air you find under bedrock
Otherwise old worlds would crash
hah no
added in 1.7 pretty sure
most of my old world from 1.8 are just dead if i transfer them so doesn't change that much
Interesting. Wonder why i never came across it then maybe i just dont remember lmao
now in mines i will put cave_air So people will hear minecraft scary sounds
cave_air is 1.13+ huh
I should break out the 1.5 spigot server at some point
Wtf?
bukkit*
Spigot
Does someone have the wiki of spigot 1.5? imagine coding plugin for that version
Explains why i never seen those materials then
I have all the bukkit and spigot versions
how many TB you have?
frosty got a collection
Think i am at 20tb now
even dev builds
Frosty the kind of guy to buy 512gb sd cards to patch spigot on the go
if bro has dev builds from the computer of md_5 is top
I dont have dev builds that md is working on. But i do have some of the dev builds that were released
He would just tell me to do it myself since i know the process of how its all done
lol
Both myself and md have been part of bukkit dev staff. I joined bukkit team a bit after md left them
from the beginning
Almost
But i been messing with mc since the beginning though
And java since nearly its beginning 
how old are you, for messing on java?
now that's understandable, java was born in May 1995 so lines
98
I've made plugins for spigot 1.5.2
Lol
two words: Eaglercraft Legacy
Think i have heard of that before
honestly 1.5 was an iconic version of mc
web browser minecraft yes
its ingrained in me because it was ported to web browser
I would play it at school with my friends
Finished with math work? Lets play minecraft!
I ran a server with it
That old server is gone
RIP HellTech SMP
Nowaways eaglercraft is on 1.8.8
And of course I run a server
its simply a bungeecord plugin
well its a plugin to allow connections from eagler
you still need to get a client from somewhere to join
hmm
why isn't this running?
@Override
public void createTable() {
CompletableFuture.runAsync(() -> {
String SQL = "CREATE TABLE IF NOT EXISTS players (uuid TEXT PRIMARY KEY, generators TEXT, max INTEGER)";
try {
Connection conn = getConnection();
Statement statement = conn.prepareStatement(SQL);
statement.execute(SQL);
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
}```
have you tried to use that method
ye
public static void setupDatabase() {
if (isAPILoaded() && !isDatabaseLoaded) {
manager.setupDatabase();
isDatabaseLoaded = true;
plugin.getLogger().log(Level.INFO, "Successfully loaded InvoiceGens database!");
}
}```
well then
don't swallow exceptions
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
CompletableFutures require you to actively handle exceptions
throwing a runtime exception there won't print to the terminal unless you handle it
okay...
so how would i do that?
but i tried broadcasting
before the try
and it didn't work
logging*
.exceptionally
^
null != value 
so like
@Override
public void setupDatabase() {
CompletableFuture.runAsync(() -> {
File file = new File(folder);
if (file.exists()) return;
file.mkdir();
createTable();
}).exceptionally(e -> {
Bukkit.getLogger().log(Level.SEVERE, "Error setting up database: " + e.getMessage());
return null;
});
}```?
ye
did you also add .exceptionally to the createTable
ahh
i see
[01:02:17 ERROR]: Error creating table: java.lang.IllegalStateException: Cannot connect to the database
i got
private static String folder = String.valueOf(InvoiceGens.getPlugin(InvoiceGens.class).getDataFolder());
private static String URI;
private SQLConverter converter = new SQLConverter();
static {
URI = "jdbc:sqlite:" + folder + "/storage.db";
}
private Connection getConnection() {
Connection conn;
try {
conn = DriverManager.getConnection(URI);
} catch (SQLException e) {
throw new IllegalStateException("Cannot connect to the database", e);
}
return conn;
}```
for my connection
provide the entire exception
yee
yeee
hmm
wouldn't
URI = "jdbc:sqlite:" + folder + "/storage.db".replace("\\", "/");``` fix it?
but it didn't
for some reason
its not compiling that
cuz its reduntant
Did you shade sqlite driver
im just using spigots
Oh spigot include it
Add Class.forName("org.sqlite.JDBC"); before making connection
What
you need sqlite downloaded
You don't need, it's shaded into spigot
ah
so um
i fixed this:
[01:11:45 WARN]: Caused by: java.sql.SQLException: No suitable driver found for jdbc:sqlite:plugins/InvoiceGens/storage.db
but still giving error
How am i ment to identify an inventory for a plugin, the only way i can think of is by name or an item in the inventory
since it was jdbc:sqlite:plugins\InvoiceGens/storage.db before
hmm
now i get this
i fixed
tsm
xD
someone good with math?
Something went wrong on the code i "made"
https://paste.md-5.net/ekipawuvit.cs
I REMOVED 800 MILLIONS PIECES OF GRASS in like 1ms but thats something else
ok found out the max X is like -4.89E.
ok so clear things the biggest number in the X block on getMaxLocation should be -581 but it return false when checking X > Double.MIN_VALUE
You can compare inventory instances,inventory1 == inventory2
what would that look like as code?
if(inventory1 == inventory2) {
}
ded chat
can you tell us what the code is supposed to do
just break blocks in a radius?
its a jackhammer, it removes a layer, the code is done to only work on regions where the player can break
please help how to Cannot resolve symbol 'EntityArmorStand', i'm switch from gradle to maven using mojmap
and then using a simple api to break all of them
missing Cannot resolve symbol 'PacketPlayOutSpawnEntity'
your imports are wrong, show your pom.xml
using the wrong jar or you are not remapping
a layer being.?
removed
the blocks in the same height
where i can post my pom.xml
?paste
is variable is given by the size of the region
which built jar are you using on your server to test?
you have the spigot dependency there twice btw
and your specialsource version is old
your code looks fine to me but theres many other classes that you don't provide so it's hard to tell you if the issue is in them
like IWrappedRegion, ICuboidSelection
also have you tried debugging values and seeing where its messing up?
the issues is in there because i logged the location and its from there that start, for some reason when X > Double.MIN_VALUE returns false, the x value in the test case is -508
so the value remains Double.MIN_VALUE
so -508 > min double value is being equated as false?
yes
huh
um
wtf lmao
looks like any negative number wont evaluate
so how to fix that?
reverse the test
you mean from < to >
x > -Double.MAX_VALUE
works for me
-Double.MAX_VALUE < -508
-508D > Double. ..
or that ^
that doesnt work
you could also use Double.NEGATIVE_INFINITY
i think that is probably best in your usecase
removes precision errors
something to ask
but if the number is positive?
then doesn't go back to the same error
like 508 > Double.MIN_VALUE?
now the code just broke
it gives true but no reply to break blocks
just use Double.NEGATIVE_INFINITY
the correct way should be -Double.MAX_VALUE
This is cool
wait is Double.MIN_VALUE the smallest possible value like as a fraction ?
the bro came back
the smallest possible positive value
ok so the code that you suggested me for taking coordinate doesn't work because X goes in to 4.89E-342
i mean imillusion
suggested me this code
what code
.
Why are you trying to replace like 19 quintillion blocks in a single for loop is my concern at the moment
im not, im just trying to get the points but X > Double.MIN_VALUE return false so the value inside the X coordinate is Double.MIN_VALUE
double maxX = Double.NEGATIVE_INFINITY;
for(blah blah x blah blah){
maxX = Math.max(maxX, x);
}```
ths is why you use integers instead
Do not use MIN_VALUE
or simply just negative
yeah this could all be solved with ints lol
so just int
int or -Double.MAX_VALUE
isnt double comparison more taxing anyway
She's workign with block replacement so no point in Doubles anyway
nothing else
negligible
and again ImIllusion saved my day
Generally the max of double wont fit into an integer and doubles use exponents to represent numbers unlike integers
damn thats a kick in the teeth lol
So would explain the weird numbers if you tried to stuff the max double into integer lol
Yes because doubles use exponents to represent numbers
Really the only thing that makes it more taxing lol
?switchmappings
why do people always assume they can keep using the old, wrong class names, after switching to mojang maps?
I mean if the names wouldn'T change, then what would be the purpose of mojang maps
Its makes too much sense. They must think its some conspiracy
Because people don't know what they're doing. They're just copy pasting old code they can find online
Itonically i have seen some projects that were essentially this. Its like some frankenstein code that some how they managed to get it to work
And its like in some ways amazing because it would be nice to have that ability to just see something online throw it into my project and then not worry about it until some problem comes along and then come up with some weird bad aide fix for it
Ehh not that big of a deal
It is a big deal for them
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
thanks
When you open up a tooltable (like a crafting table, furnace, loom, etc), does that utilize the CraftingInventory?
no just inventory and crafting table
. . . what are they asking about ?
they're asking if furnaces and stuff count as CraftingInventory
aaah
I got confused as I read it as loot table
?nocode
It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.
nice
public class freezecommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if(commandSender instanceof Player){
Player player =(Player) commandSender;
player.setInvulnerable(true);
if(!player.isInvulnerable()){
player.setInvulnerable(true);
}else{
player.setInvulnerable(false);
}
}
return true;
}
}
oh god
pls use code block
?codeblock
You can use the discord code block format to display code or just text in a more pleasing way:
```java
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
Becomes:
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
ops
freezecommand
no
FreezeCommand
?codeblock public class freezecommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if(commandSender instanceof Player){
Player player =(Player) commandSender;
player.setInvulnerable(true);
if(!player.isInvulnerable()){
player.setInvulnerable(true);
}else{
player.setInvulnerable(false);
}
}
return true;
}
}
You can use the discord code block format to display code or just text in a more pleasing way:
```java
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
Becomes:
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
@chilly hearth read this bro
use your brain a little bit
player.setInvulnerable(!player.isInvulnerable());
` not '
iam gona lose my mind
Just copy the character....
OMG
You have a logical error
You first set the invulnerability to true and then you try to set it based on if the player is invulnerable.. which he is
so do this
Also, rename the fricking class to what I sent
hit enter when you're outside of the backticks, the `
public class freezecommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if(commandSender instanceof Player){
Player player =(Player) commandSender;
player.setInvulnerable(true);
if(!player.isInvulnerable()){
player.setInvulnerable(true);
}else{
player.setInvulnerable(false);
}
}
return true;
}
}
finaly
yay
now you're just missing the "java" at the start
for pretty colors
we gave you answers already...
.
sry i was figurign out codeblcok
i did didnt worked so i switched it
but ima still try again
does "invulnerability" work for players ?
Don't you have to go through abilities ?
fuck discord
LMAO
indeed it does
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if(commandSender instanceof Player){
Player player =(Player) commandSender;
player.setInvulnerable(true);
if(player.isInvulnerable()){
player.setInvulnerable(false);
}else{
player.setInvulnerable(true);
}
}
return true;
}
}
will it work now ?
no
why ?
player.setInvulnerable(true);
if(player.isInvulnerable()) {
player.setInvulnerable(false);
}
else {
player.setInvulnerable(true);
}
so what it should be ?
again, read this
and the message I respond to
i did set it to true
and then i set it on based on the player
;-;
I was explaining your error...
what you do is incorrect
if you do that the rest of the code will work with "true"
SEE WHAT I RESPOND TO
you have literally been given a line of code
replace this with it
player.setInvulnerable(!player.isInvulnerable());
Digging a little deeper to what I'm trying to do.
When you put an item into a loom, what event is triggered?
declaration: package: org.bukkit.event.inventory, class: InventoryInteractEvent
for like any inventory interaction (- creative inventory)
The slots in a loom count as inventory?
yes
are you writing a plugin ?
oh wild. Ok.
if not then #help-server
inventory isnt just the player's inventory. It's any iteractable menu you can put items in
replace this
All of that
should be deleted, burned in the flames of hell
and replaced with that single line of code
TWO ppl have provided you with
chill he learning
and that like of code will work ?
||no, we gave you a wrong one for fun...||
Yes it will work
I get that but.. like... read
it worked
but
i dont still understand how that work and my code didnt it made sense ;-;
iam new to java man
boolean value = !player.isInvulnerable(); // Get the opposite of the current invulnerability state
player.setInvulnerable(value);
so you are inverting the current value
How long have you been learning English ?
lol
so with your code you were setting invulnerability to true, then checking if it was true, which is always true
bro if i dont understand java how can i understand the points u giving in english man
so it's always going to set it to false
i see so how typign the command again disables it /
?
it inverts the current value
.
so the rest of the code always worked with "player is invulnerable"
And then it set it to false
alr
ok now i want to send thnem a message on vanuralble and invanurable
but there is no else ;-;
you don't need an else
then ?
alr
well yes but... then you would have to check if the player is invulnerable and than if the player is vulnerable...
Two ifs no ?
else statements exist lol
Exactly... then why did you say this ?
he said there is no else im assuming he meant on the whole blockl
a
guys
public void onPlayerMove(PlayerMoveEvent e){
Player p =(Player) e.getPlayer();
if(p.isInvulnerable()){
e.setCancelled(true);
}else{
e.setCancelled(false);
}
}
}
mhm
that is certainly a piece of code
that may or may not do something that you may or may not want
we don't know
looks like a rubberbanding nightmare lol
I am way too hostile aren't I
wasn't riding an entity a better solution ?
riding ?
I guess not in your case actually
so this wont work ?
its not working
getCommand("freeze").setExecutor(new freezecommand());
getServer().getPluginManager().registerEvents(new MoveEvent(), this);
}
}```
well... from what little I see, you're missing the @EventHandler
we register it like that right
yes
bro, rename the class freezecommand to FreezeCommand
THIS MAN SHOULD GET NASA DEGREE
@chilly hearth I will bug you until I get a confirmation that you have renamed the class
why that matters ur solution worked : )
Because the class name is wrong
does that cause any issues ?
It does not matter that it works, it is wrong
yes, mental ones for any person reading that code
never open source that code then
oh THANK YOU
public class Freezecommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if(commandSender instanceof Player) {
Player player = (Player) commandSender;
player.setInvulnerable(!player.isInvulnerable());
if(player.isInvulnerable()){
player.sendMessage("you have been freezed!");
}else{
player.sendMessage("Your free!");
}
}
return true;
}
}```
there u go
: )
lesgo
Well... should be FreezeCommand but I will take it
Anyways, since this is a bigger error and players will see this one, "You're free!"
and "You have been frozen!"
steve nitpicking everything lmao
Well... I just do what I do at my job, review code and provide review comments :D
Tho at work they are less aggressive
i lvoe passive aggressive code review comments
xD
How can I sort a List of Players in a HashMap<TeamType, Array<UUID>> so every Team has not more than 6 players and the rest does equalliy have the same amount?
For example I have 4 Teams.... 2 of them are already full and there are only 2 or 3 player left to get sorted into the rest
ideally each team should be it's own class
but just iterate over the map enty and check the count
cant follow
add the next player to the team with the lowest member count
If you know how many players you start with
its even easier
how can I get the value in the HashMap with the lowest count?
With the lowest ArrayList
You can use a TreeMap with a Comparator to always have the lowest member count teams first
yeah thats what Conclube suggested
using just a HashMap you have to interate the values and count
Use two maps bro
One TreeMap and one HashMap
or maybe even just a TreeSet
Then u have TreeSet::ceiling and ::floor, ::last, ::first etc
Hey, is Custom Pathfinder Goals in 1.20 possible?
My problem with nms is, that if i extend the mob, it loops me in an error that cant be fixed.
What error?
Also, u probably need to override the methods that already register goals
spawn mob in spawn event again
'z()' in 'net.minecraft.world.entity.EntityInsentient' clashes with 'z()' in 'net.minecraft.world.entity.EntityLiving'; attempting to use incompatible return type
Is there a way to resend every visible chunk to a player, or is the only way to manually check distance and use nms to resend the packet
Got some code?
?paste the full error or no one can help
print "PRESS F3+A" over their entire screen
package de.splatcrafter.leavessimulator.entity.craftentity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.monster.EntityVex;
import net.minecraft.world.level.World;
import org.jetbrains.annotations.Nullable;
public class CraftBee extends EntityVex {
public CraftBee(EntityTypes<? extends EntityVex> entitytypes, World world) {
super(entitytypes, world);
}
@Nullable
@Override
public Entity v() {
return null;
}
@Override
public boolean f_() {
return false;
}
}
public class CraftBee extends EntityVex Error: 'z()' in 'net.minecraft.world.entity.EntityInsentient' clashes with 'z()' in 'net.minecraft.world.entity.EntityLiving'; attempting to use incompatible return type
lol
Use mojang maps
?nms
isn't it f3+a anyway
I tried resendChunk on the entire world's loaded chunks but 0 packets get sent to the player so ig that's just not working
please help, i use mojmap why this is missing:
import net.minecraft.core.Vector3f;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*;
import net.minecraft.world.entity.EnumItemSlot;
import net.minecraft.world.entity.decoration.EntityArmorStand;
need to add local library for this?, but the mojmap work, thanks for help me
Those classes don't have the same names
Since you're using Mojmapped
?switchmappings
i need to add local lib for this?
^
okay thanks, let me test
EntityArmorStand eg is not a mojang mapped name
okay i understand
Is the mojang mapped name from EntityVex = Vex?
?nms
this ^
?mappings
Compare different mappings with this website: https://mappings.cephx.dev
What is the Material for banners? I see a bunch of different type of banners. Is there a class that emcompasses them all?
declaration: package: org.bukkit, interface: Tag
no, but you can use the Banners tag
I don't like you 😠
you can either do Tag.BANNERS.getValues() which returns all banners, or Tag.BANNERS.isTagged(Material.SOMETHIING)
chicken wing
something like this for a check?: Tag.BANNERS.getValues().contains(bannerItem.getType())
no, rather do isTagged
getValues() creates a new stream, maps it and collects it everytime, while isTagged just checks the existing collection
Wild
Can I hide damage and attack speed in a tool itemstack?
declaration: package: org.bukkit.inventory, enum: ItemFlag
thank you
How does real players keep chunks loaded & ticking the area?
i wan't to make my fake player close to how real player does.
How do I show a Player an entity that only exists for him? In older versions I would just send a specific packet, but it seems that packets don't really exist anymore??
packets don't really exist anymore
How would servers work then ?
Email ?
They do exist, you're probably not looking at the right place.
Packets definitely still exist
Yeah I also don't get that. LMAO
The thing is i literally don't have any imports from net.minecraft
so im hella confused
They stopped using packets as they found Magic was more efficient.
?nms
Magic does save bandwidth
I see, thanks a lot 🙂
send the updates by owl
Not sure what kind of ping that would give
Depends on the speed of the owl
does spigot api have a method that is similar or the same as bed respawning position finder?
declaration: package: org.bukkit.entity, interface: HumanEntity
?help
selfrole Add or remove a selfrole from yourself.
cleanup Base command for deleting messages.
embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.
findcog Find which cog a command comes from.
names Show previous names and nicknames of a member.
userinfo Show information about a member.
listcases List cases for the specified member.
reason Specify a reason for a modlog case.
permissions Command permission management tools.
I have used nms mojang mapping for my class:
package de.splatcrafter.leavessimulator.entity.craftentity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.monster.Vex;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
public class CraftBee extends Vex {
public CraftBee(@NotNull Location location) {
super(EntityType.VEX, level);
}
}
but where can i get "level" (net.minecraft.world.level.Level)?
That is slightly different question then
I do not believe so
I believe casting World to the CraftBukkit one and then getting the handle should return Level
^
i think it is "((Level) location.getWorld()).getMinecraftWorld()" but idk.
It’s ((CraftWorld)location.getWorld()).geHandle()
you can't cast spigot World to MC world, you have to go throught the handle
what event triggers when player sets respawn bed by right click?
No, in 1.20 it returns WorldServer not Level.
It is in the package level but not inherited level
Required type:
Level
Provided:
WorldServer
super(EntityType.VEX, ((CraftWorld)location.getWorld()).getHandle());
isn't WorldServer a spigot name
World is Level
No, it is in package net.minecraft.server.level.
But not extends it
I wanna access material by its ordinal but i dont want to clone a 1000 sized array is it better to just use reflection to access enum's array
ordinal is a bad idea
But it returns WorldServer not ServerLevel.
Spigot mappings are not used in new versions
I use the remapped server i think.
the first dependency?
ye
i removed it
oh now it works
thanks, i hope the other code from me works too.
But how to spawn the Bee or in our case the CraftBee extends Vex?

i mean i want to spawn the entity in the world on the location from the player
public CraftBee(@NotNull Location location) {
super(EntityType.VEX, ((CraftWorld) location.getWorld()).getHandle());
this.setPos(location.getX(), location.getY(), location.getZ());
((CraftWorld) location.getWorld()).getHandle().addFreshEntity(this);
}
Like this?
if i only create a new instance from it on calling it in a command it not works.
well you can't spawn this custom entity with vanilla commands
You would have to listen to some event
what command did you try btw :D
an own command like /debug for me.
} else if (args[0].equalsIgnoreCase("bee")) {
Location loc = player.getLocation();
CraftBee bee = new CraftBee(loc);
player.sendMessage("§aBiene gespawnt!");
}
i get the message but the entity dont spawn.
ye I can't help much with this
Hope someone who knows custom entities comes to help you :D
Thank you anyway.
public CustomBee(Location location) {
super(EntityType.BEE, getWorld(location.getWorld()));
setPos(location.getX(), location.getY(), location.getZ());
level.addFreshEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
private static ServerLevel getWorld(org.bukkit.World bukkitWorld) {
return ((CraftWorld) bukkitWorld).getHandle();
}
thanks, i try it.
simply do new CustomBee(player.getLocation()) and then you might want to track that custom entity, if you need it
tanks
you can always use instanceof to check if x entity is that custom one
but first i need to check if it works to spawn it
test it
package de.splatcrafter.leavessimulator.entity.craftentity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.monster.Vex;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.jetbrains.annotations.NotNull;
public class CraftBee extends Vex {
public CraftBee(@NotNull Location location) {
super(EntityType.VEX, getWorld(location.getWorld()));
setPos(location.getX(), location.getY(), location.getZ());
getWorld(location.getWorld()).addFreshEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
private static ServerLevel getWorld(org.bukkit.World bukkitWorld) {
return ((CraftWorld) bukkitWorld).getHandle();
}
}
} else if (args[0].equalsIgnoreCase("bee")) {
Location loc = player.getLocation();
new CraftBee(loc);
player.sendMessage("§aBiene gespawnt!");
}
its not working but i dont get errors or other things. "player.sendMessage("§aBiene gespawnt!");" is executed and works but the bee dont spawn. (or in our case the vex)
Don;t Vex only spawn on a grass block?
idk i think not, if i spawn it natural than it also spawns on every block
oh i think i am stupid
ooohhhh i am so stupid
@EventHandler
public void onMobSpawn(EntitySpawnEvent event) {
if (!(event.getEntity() instanceof Player) && !(event.getEntity() instanceof Bat) && !(event.getEntity() instanceof FallingBlock)) {
event.setCancelled(true);
try {
event.getEntity().remove();
} catch (Exception ignored) {
}
}
Oh nooo, im stupid af.
🤔
must be another mob I'm thinking of
now it works without it.
im sooo sorry for all the time i wasted from all who wanted to help me.
Can i set custom pathfinder goals on the entity?
yes
Can you show me how or is there an tutorial?
You can look how vanilla mobs do AI
i think
That's good
Means you are
registerGoals is the method i think
serverplayer.connection.send(new ClientboundSetChunkCacheCenterPacket(serverplayer.chunkPosition().x,serverplayer.chunkPosition().z));
i tried to send this packet by the serverplayer (fake player) , it doesn't keep it's positioned chunk loading.
or is there other ways to let fake player chunk load.
isn't the packet sent to the server?
no ?
Clientbound
just load chunks via plugin tickets
or actually spawn the server player in the world and have the server believe it is a real player
that is rather dangerous tho
mind you, if you do this crops and such will not grow and maybe more
when not it crashes your server
yea, but having the server fully believe the player is real is a bit of a meh thing
when half the logic on it is not gonna work
e.g. no movement
or plugins doing hacky things with the player instances
just bundle the plugin with a minecraft client smh
||don't, legally you can not :D||
the only ticket found in serverplayer.class is TicketType.POST_TELEPORT, how real player does load the chunk then
the server maintains tickets for every real player
For a minecraft plugin, do you think having each server having their own way of storing the data such as file based or their own database or do you think a way of centralizing the data such as what luckperms does like a website?
what has a website to do with storing data
anyways, that really depends on the usecase
but normally you want to use a database
