#help-development
1 messages · Page 462 of 1
Maybe it is just a language you dont quite grasp like some others.
Nothing wrong with that
Wrong way of doing it
Wait are you using path tracing?
Unless your complaint is with boiler plate code with c++
In which case you can tailor your ide to handle most of that lmao
Can’t you just disable weather with a gamerule now
Yes
Ive learned everything to C17 in uni for 2 years. Ive written games, a database, website backends
and machine learning applications with it. I think i have a pretty decent understanding of the
language and i can confidently say that writing C++ is the worst experience i had with any
programming language so far. And dont get me started with CMake. Absolutely abysmal.
Lol
Rust is literally a superior language
No, rust doesnt run hardware or os's
Can’t wait for them to release C—
Cant call something superior when it doesnt do what c++ does. I agree that it might be better when you dont quite need a language like c++ but to say it is superior is not quite right either
Thats not an argument. Most operating systems (At least the kernel modules and most drivers) are not written in C++ either
anyone got some example source code for custom block drops i cant find any
And writing an OS with a language doesnt make it good
Not sure what drivers you are talking about, but it is a mixture of C and C++
C++ however can load c libs but c cant load c++
You could simply listen to the BlockDropItemEvent
well i just so happend to fnd this
Or you can use a datapack 
Certainly doesnt help its case for the opposite. Java had an OS at one point.
i wanna know how to use trhat
And even if C++ was pleasent to write, CMake catapults it right back
oh now i know whats waiting for me
Sounds like a bad idea...
There arent any good build systems for C++
Only Cmake and some abominations nobody uses or
which havent been updated since 1996
There is alternatives like gnu make, apache buildr, apache ant, automake
All of those are maintained that i listed
Maybe not apache buildr would have to check when i get home, but the others are.
By all means, write C++ if you want to. But its dead to me. I would rather
write in any other language unless im writing some ultra low-level applications
or embedded code. Well even for embedded id use Rust.
It's a dumb question, but I should use equals() to check if two inventories are the same, right?
For what purpose? This would trigger every tick.
/gamerule doDaylightCycle false
yes
if ur looking for a time "skip" https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/world/TimeSkipEvent.html
declaration: package: org.bukkit.event.world, class: TimeSkipEvent
thanks
Just keep in mind that this does not account for the normal daycycle
in bukkit how do I set a parameter to null? do i just leave it blank or write "null" or what?
If you want always day just use the gamerule
You just put null
Never do that in java.
ah ok thanks 😉
If you have to do that then you are doing something wrong
😏
Unfortunately some things in bukkit require that
So cant say it is wrong when the implementation is the one that is wrong
Bukkit makes it clear what is nullable
There should never be something on your heap that needs to be set to null...
Sure i agree, doesnt change the implementation expectations
How to enable fly on spigot server
Ok
Wait we arent speaking about fields... Just parameters. My bad, i thought he wanted to manually set a field to null.
Lol
i thought are we getting into stack and heap now
@eternal oxide help since i did your thing i can't look at bukkit/spigot's file without using intellij's decompiler
ping me when you respond ❤️
@lost matrix how do u handle stuff that can be empty tho, using Optional<> ?
Very carefully
Depends. Sometimes i allow null values and sometimes i use optionals.
the billion dollar mistake 🙏
Yeah i thought we where talking about variables in general.
And you dont want to have live objects on the heap (like players, chunks, entities etc)
If my code was worth a billion dollars I wouldn’t have to worry about null ever again
where woiuld they be otherwise?
stack
Guys I'm using the code:
meta.hasChargedProjectiles().equals){
but equals "cannot be resolved".
I'm trying to get it to be .equals(true).
Where did I go wrong and how should I fix this?
i clearly havent learnt good enough
if(meta.hasChargedProjectils())
or if(meta.hasChargedProjectiles() == true)
it returns a boolean (primitive)
?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.
ah ok ty 🙂
Cursed
wtf
my classmates code like that
only refs to those are on the stack right?
if ((meta.hasChargedProjectiles() == true) ? true : false) better <
im confused lol
Needs more Boolean.valueOf
This reminds me of the terrible plugin
objects are on the heap but objects consists of primitives which are on the stack again 🤔
i have no idea what im saying
give me the link to it cause i forgot
oh god yes send me the github
id lost it
i need some laughing in my life rn
just too late
uh oh
the best thing are the comments actually trying to justify everything
so fking funny
its actually a style of programming, please do not harass the author
i added the abstractmotdfactory stuff and the Logic class
lmfaoooo
lmao
I love the comments
try {
throw new RuntimeException("Something went not really wrong");
} catch (RuntimeException ex) {
if(ex.getMessage().equals("Something went not really wrong")) {
// All good
} else {
throw ex;
}
}
yea the comments are so good
reminds me of someone who can barely speak english but when he does it sounds funny
realizing all plugins can do that 💀
what does HandlerList#bake do? the javadoc says it bakes a handlerlist which is not the most helpful of things
I do like the sql storage system they have
Why doesnt spigot use this method? It looks better than the current getOnlinePlayers() implementation
public Stack<Player> getEveryPlayerWhichIsCurrentlyOnlineOnTheServer() {
Stack<Player> allPlayers_which_arOnline = new Stack<>();
for (OfflinePlayer player_that_is_not_online : Arrays.stream(Bukkit.getOfflinePlayers()).collect(Collectors.toList())) {
if (player_that_is_not_online.isOnline()) {
Player player_that_might_be_online = player_that_is_not_online.getPlayer();
if (isThisThingReallyOnTheServer((Entity) player_that_might_be_online)) {
allPlayers_which_arOnline.push(player_that_might_be_online);
}
}
}
return allPlayers_which_arOnline;
}
yea same, mostly the fact thats randomly made in kotlin xd
😂
You should not call this method. It gets called whenever the handlerlist changes (events getting (un)registered)
got a question not directly related to spigot, anyhow: do i understand it correctly that i can implement actual new mobs with only a data pack and resource pack?
ah alright, thank you
What counts as actual new mobs
you can create new mobs with nms, still gotta have a texturepack for their texture
zombies in disguise
yea but if i inherit say the zombie class i can not update its skin without overriding the vanilla one
You can do a lot of stuff with display entities
Or armorstands if you’re feeling 2022
Custom AI logic cant be done with datapacks
And we can also not add new entity models to the game using resourcepacks.
You will always need some sort of magic to make that happen.
maybe thats a better approach than nms tho because nms is well we all know its fragile, obfuscated(yes ik ik maven) and its not persistent across server restarts
Im just going to let this sentence as is...
We should stop calling it nms and start calling it slughorn
nms not persistent accross restarts uh oh
What
„How can i spawn an npc using slughorn“
uh no my server is gone
Where did you come up with slughorn
„Ugh why are you using slughorn to send action bar messages“
Idk just came to my mind
is that some german thing?
No its from harry potter 6
💀
i mean if i inherit the zombie class to modify its behavior incl pathfinder goals, and then spawn one it behaves as desired, but once i shutdown the server, save the entity and restart the server its going back to the defaulting zombie class
maybe i did do it wrong idk
You should not mix datapacks and plugins. There is nothing you can do with a datapack that
you couldnt do with a plugin. Also datapacks are interpreted and quite a bit slower in many cases.
but from my exp its not persistent by default
Good luck adding new biomes and structures with a plugin
Nothing is persistent by default
minestom is way funnier
🤷
thats not what i meant, i mean its defaulting back to the vanilla mob after a restart and tbh
i havent figured out how to inject my custom mob behavior into the maps that in the end store entity states
Datapacks are fine for most static features
Since we have mojang mappings i find writing nms to be decent
It’s only functions that start to impact performance
hm
well tbh its been a while
i think last time i did custom mob behavior in nms was
hmm, 1.15? xD
maybe the api changed idk really
I'm working on lobby and minigames system, I'm making it from scratch. On other servers when you select some lobby or a game you will be put in a new world and in tab you see only players that are currently in the same world. I know that I can do it by managing tab system, but it seems to me it's incorrect... I guess that these servers use bungeecord to separate players, but I don't know exactly...
Probably
probably?
i think most larger servers do use bungeecord although im not familiar with how it works exactly😅. but multiple smaller dedicated servers have the advantage to be able to run on less resources since say u have a minigame with 20ppl per server instead of a megaserver with 4k players
pretty sure every single self respecting minigame server does it that way
isnt that how its supposed to work?
and since its a minigame, these 20ish players playing their game have no business with the rest 3.9k anyways
You compiled the header
That’s why it’s annoyed
You don’t compile headers just cpp or c files
ah
headers contain declarations
Should I avoid using the Bukkit class
makes sense lmao
and source files definitions
Like the static class that has the same functions as Server
@tardy delta ud rather do namespace...
extern constexpr int max_class_size;
``` in ur header file
and then define it in the same named .cpp file
that was the exercice i got
and tbh i dont understand what half of those keywords does
c/c++ is completly different from managed languahes
to me it feels like they all do the same
i think an explanation what it does is more helpful
no just in header
Pragma one only include file once by the compiler if its included by user multiple times
ik
#pragma once is a guard clausel to tell the compiler to not include the same header multiple times as this could cause an infinity loop if 2 headers include each other
right
Also why not just use Class and static fields for constants, I means it's nearly same as namespace but I guess it would be easier to you as its close to java
Is there any way for displaying transparent blocks? Or even a schematic from world edit?
theres so many ways xD.
macros, typedefs, constants
imma miss java switch
if i may ask why r u learning c++?
want to learn smth new
i mean its my personal fav lang xD but
id suggest learning C then
C++ is the same as C but more advanced with classes
well yes but the only reason to learn C/C++ is to learn an unmanaged language
No macros in cpp 
and c++ has so many abstractions that u can basically use it like java
exactly c is more barebone, dont get me wrong i prefer c++ over c by far, but to learn the fundamentals C is better from a didactic pov
i cant export my maven shit it always says acsess denied no matter where
wdym macros are great
esp for conditional compiling
No reason to use them in cpp as utility or whatever is it used for in c
It's not strongly typed, you have inlined functions for same purpose
True
i do use inline members for my own project
Cpp is somewhere between functional and object oriented
That it's why you can do many weird things
just because something is bad practice in a particular circumstance
it doesnt mean its not worth to be known
i barely use macros too, but if u really need em its good to be able to
and conditional compiling is one such instance in for example ive written cross plattform code thats able to compile from windows and unix plattforms using the same code base by replacing the plattform specific functions and includes with macros @hazy parrot
access denied to what from what
Tbh never knew about that usage of macros
Good to know ig
conditional compiling?
#ifdef whatever
...
#elif something else
...
#else
...
#endif
``` then u can for example check for the target OS to define macros with whatever u need to fit that plattform
if u want i can dm u an example cause i dont want to spam here any more xD
@last temple what you explained to me today worked, now it works without making the variable static thanks a lot
ik about that, but never saw someone using macros there
I wrote a static hashmap within the main class which stores some Custom ItemData based on an ID system. Is this good design? It will get referenced throughout the codebase.
/**
* A HashMap of every item's ItemData.
*
* Integer - The number used to represent this item's unique identification.
* ItemData - All the data associated with 7 Realm's Custom Item system.
*/
public static final HashMap<Integer, ItemData> ITEM_DATA = new HashMap<>();```
- Dont make it static
- Dont make it public
Oka oka. So what's a good way to reference it? Add a getter and reference the main class object?
That'd mean I would need access to the main class object throughout the code though, right?
you’d have a class responsible for sharing that data with proper methods
public class ItemDataManager {
// Never expose the map directly
private final Map<Integer, ItemData> itemDataMap;
public ItemDataManager() {
this.itemDataMap = new HashMap<>();
}
public void addData(ItemData itemData) {
this.itemDataMap.put(itemData.getId(), itemData);
}
public ItemData getData(int id) {
return this.itemDataMap.get(id);
}
public void removeData(int id) {
this.itemDataMap.remove(id);
}
}
Something like this. Create one single instance of this class and pass it around.
^ exposing a hash map is shit api
doesnt it only make sense to write a proper wrapper layer if thats gonna be an actual api and not only used by one plugin only
So can I make the instance of that class static?
it looks shit to call SomeClass.someMap.get() anywyas
No. Never expose your collections. There is no exception to this rule.
to be honest I prefer designing the API first and using the API in the implementation, not the other way around
Hm, yeah you could do that. But you will learn to write more robust code when you
inject it as a dependency (pass it around through the constructor of other classes)
it does create problems where you can’t do internally unsafe things that you don’t want in the API, but it leads to a better API in the end imo
the problem is that you first have to write the apis and most ppl dont have that patience
It seems very over engineered to pass it through every class that needs access to the ItemData hashmap. That's why I'm asking if I could just make it static. Makes it much easier to use and extremely accessible without needing to pass the object everywhere
my fucking Java code is horrendously beautiful though, I constructor DI each manager that I use instead of the plug-in instance (unless that instance is also needed, then I DI both)
like i wanted an ini parser i can use in every language, and by now im writing it for 6 months
even though it was supposed to be a 2 week project
it’s easier to make it static, it’s proper to pass it as a constructor parameter
Even if I end up having several types of hashmaps with various data that needs to be referenced?
Its not over engineered. Thats simple dependency injection.
Using a static instance is the singleton pattern. Both approaches
are equally valid with DI being more robust to problems like cyclic dependencies.
it’s called having a manager class for related data and passing that
once again, you don’t expose collections it just isn’t proper
im not that versed in java, you mean pass it trough constructors to store a copy of reference to that map? since java is call by reference
correct, that’s dependency injection
🙏
Alright noted. I feel I've learned a lot about what's proper now thanks guys 😄
Haven't learned why though
Technically Java is call by value. Always.
as in the reference is copied and as such a value?
basically a copy of a pointer?
the reference isn’t duplicated though, the reference is the same for the original object and injected object
Kind of. Yeah.
man i prefer the freedom to choose though as to what is passed xD
Unless there’s two references that point to the same memory address
but that doesn’t sound right
No the reference is a different reference. It gets copied.
a reference is just a fancy name for a pointer
isnt it like
class foo = new foo();//heap allocation
class foo2 = foo;// pointing to the same unmanaged address?
and then java wraps it
so we dont have direct access to it
Dont say that to your C++ teacher. Because thats not quite true.
should I learn java with spigot or should I learn java before spigot
new foo() has a reference, and both foo and foo2 have the same reference
Learn at least the basics of java first
maybe its better that i dont have a c++ teacher then
learn java basics
to be fair most is just fancy wording for things that happen in the background where you dont have access to
hmm
Java is pass by value, but the value is the reference unless it’s a primitive
ok ty
like a java reference is not a pointer but it behaves the same
its pass by value always by definition
depends what you consider being two same references 🤔
pass by reference is when the language has semantics that allows you to pass semantic variables/references as values
Pass by value will always copy the passed value into a new variable.
So the actual reference will be the same but there will be a new variable
containing this reference. So yeah the reference stays the same.
there’s a memory allocations for each field holding the same reference when you do this, right?
same reference just in 2 spots
it is backed by a pointer, hence why you can do a reference comparison to check if both references point to the same memory address
Why does java gotta call everything enhanced like
For-each loops are enhanced for loops
no only for the first foo from my understanding.
Pattern matching is enhanced switch
because there is a normal for loops, and you need a way to distinguish the two
only the new keyword actually allocates heap memory in java
so yes I’m right 7smile
Should we go with switch 2.0 then?
this
Right but they could just call it for each
Like everyone else
"slightly less bad for loops"
the field is still separate, which is why I can reassign foo2 without foo changing at all
semantically yes
although thats not entirely true
but the reference is the same
but u have stuff like the foreign memory api and unsafe
enhanced for loop and foreach are two different things in java
if u for example increase the size of a map by injecting an entry
theres also a heap alloc
hence the trim_to_size member
enhanced for loop is backed by for each
tim well lets say ur map entry push causes the map to resize the backing array
then there's a new keyword somewhere to ensure thats happening
enhanced for: for (X e : z)
for: for (int i=0;i<5;i++)
yea thats what i mean i just wanted to say, you the user using the new keyword isnt the only way to have heap allocs
it’s so fucking hard to type code in a phone with autocorrect
basicslly just corrected myself cause ik absoloute expressions are rarely valued xd
public static ItemStack getItemStack(Material material, Component displayName, List<Component> lore, boolean glow) {
ItemStack itemStack = new ItemStack(material);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(Translate.translate(displayName));
meta.setLore(Translate.translate(lore));
if(glow) {
itemStack.addUnsafeEnchantment(Enchantment.WATER_WORKER, 1);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemStack.setItemMeta(meta);
return itemStack;
}
Glow is not working is 1.19.4.
Could you please help me?
while this is true, it isn't true to say that using the new keyword means it will go on the heap
the JIT can decide that it should go on the stack memory instead
yea
well implicitly the bytecode instruction new anewarray multinewarray or newarray is called somewhere @granite owl
which is compiled from new
anyway this tho
for example if I do Sand.test(new Random()), then the instance of Random will go on the stack instead
and then theres native code
Just need a quick help, please
where the .dll / .so whatever can return pointers to heap allocated objects
which i for example used
hence im really annoyed tha java doesnt have actual destructors only autocloseables
also in more recent Java versions, the new keyword doesn't guarantee any allocation of memory on the heap or stack and the JIT can sometimes optimize it away
na
thats still on heap
like string literals in the byte code?
or no?
Wait seriously? If I do new Integer(5) it’ll return the pre-made one?
well Integer has the first few hundred integers cached
unless the JIT can optimize it away
ye
then no allocation is made
what’s considered optimizable though
it should go on the heap as new Random() returns a reference to the newly created random and since we dont know how many new randoms it should be the heap
but arent objects at lowest level just a wrapper around a bunch of primitives?
so arent those on the stack then
what have we started lol
primitives live on the stack
nah, at the lowest lvl objects are just bytes appended
oh well yeah it would go on the heap
in a consequtive array of bytes
the reference to the object from the heap is on the stack
but that’s just how methods are called
in memory
but if the object contains primitives, those are on the stack?
why do i deserve the clown
unless the object is too large to go on the stack then it gets placed outside of the stack and heap
how do i create blocks with blockdata that i can later use in a event
when that happens, the objects is slower to work with
hence why it is best to optimize for stack size 🙂
StackOverflowError 😏
doesnt that happen with a recursive infinity loop?
hey hey
🐒
yes because the stack is too large
it also happens if you exceed the limit of the amount of objects a single class can handle
^ you can only have Short.MAX_VALUE methods iirc
Any idea how the Midas Staff on skyblock was created?
think you mean to say, too small?
well it’s intending to allocate past the size
i like how java is supposed to manage everything for u and in the end to be an effective developer u still need to have a good understanding of how a computer works on hardware level🤣
yep too small, my bad for the wording
With a computer probably
burh
it was meant to be too large how I was wording it, but I worded it oddly
large guy
it’s “too large” for the size that’s already allocated
This is why software engineers exist
guys how can i declare variables within an event handler?
i once tried to set a mobs hp to Integer.MAX_VALUE and it basicslly phased out, couldnt kill it, AI froze, unresponsive to external forces like tnt etc
having good knowledge of the internals of whatever language you use is most helpful anywhere
software engineer is the person that should be telling you where something needs to be optimized or needs to be done differently, so that your developers don't need to actually know that stuff
I agree
even though you don’t technically need to know how the JVM works to use Java, it definitely helps a ton 🤷♂️
what about arrays of primitives 😛
yep especially in the those unique cases where you need to know some specific thing
ofc
for example the endianness of Java. Java stores objects/data in Big Endian format or network order as it is referred to sometimes
doesnt the reference to the array lives on the stack but the elements either on stack or heap?
id say learning C for the basics is a really good thing but most ppl whom i suggest that to tell me they dont have time for that
ya
🙂
declare a variable bruh
bump
i'm doing what it says in the docs but it says cannot resolve symbol
show code
probably should have researched what it means when it says cannot resolve symbol
wait dw i think i got it
yeah i did
iirc a reference can live on both the stack and the heap but for the garbage collector to not swallow ur object at least 1 reference must be active on the stack to keep the reference count above 0
what exactly "isnt working"?
so the reference is just the address?
is it?
must be a rather new iteration since inline members are a c++ 17 standard
Is it good practice to access static methods in this fashion? java public class ItemManager { public static void giveItem(Player player, int id) { ItemData itemData = Realms.ITEM_DATA.get(id); player.getInventory().addItem(itemData.getITEM_STACK()); } }
or should I pass an instance of the class to use this method?
but i really dont wanna read trough the whole repo to figure the exact purpose
it is a collection
but it would be fun
or create some itemmanager thing
bruh thats the itemmanager
whys that map in the realms class and is that the main class?
I'm going to rewrite it don't worry
It's not glowing
Yes, I'm rewriting it sorry xD
objects
btw serious question, if i load a native library and store 64bit pointers to functions so to speak function pointers in a long, is it bad practice to do so in private static fields?
but as frostalf said
Was hoping we would ignore that fact since I am planning to rewrite it lol
jit might do an escape analysis i believe
static can't be GC'ed
my brain is even more fucked up after reading this conversation
in most cases yes
basically load library, on first instance of my wrapper class, store function pointers and then use them across all instances since its hardly good practice to load a library once per instance
it can sometimes
like class unloading might allow it
but thats too arbitrary to rely on
this would be the only way to remove statics lol
Set everything to null?
but you would have to some how unload the class fully and there really isn't a way to check if it happened or if it like half unloaded
ofc not, thats the point. since its pointers to functions inside the native lib
i feel like maybe unsafe could hack it also
ill post what i mean here once ive written it
rn im at the c# importer
xD
after finishing c, and c++ for both static and dynamic libs
possibly but either one I wouldn't really consider it a solution to something that is self created lmao
indeed
Guys I'm trying to update the lore on an item.
I'm trying to get the first word on the first line of it's lore.
How would I do this?
substring
getLore().get(0)?
by seperating the string into an array based on the seperator which is a space?
doesnt that return the first char?
Wouldn't that get only the first line?
isnt lore a list of strings?
Yeah
I'll try using the substring thingy then
line.substring(0, line.indexOf(' '))
🤣
i guess this is why ill never be a good java developer
dont laugh at me
no i laugh at my low level approach
yea ik
i was more thinking of a ranged for loop iterate each char individually and then memcpy them over
xD
wtf
what does the indexof part of that do?
How can I make Wrappers?
I tried like so:
public abstract class PlayerWrapper implements Player {
private Menu lastOpenedMenu = null;
public Crew getCrew(){
return CrewLedger.getCrew(this);
}
public Menu lastOpenedMenu(){
return lastOpenedMenu;
}
public SlotLock getSlotLock(){
return SlotLock.slotLock(this.getUniqueId());
}
public PlayerWrapper lastOpenedMenu(Menu lastOpenedMenu) {
this.lastOpenedMenu = lastOpenedMenu;
return this;
}
}
resulted in error:
Caused by: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer cannot be cast to class io.tomko.bonestreasures.wrappers.PlayerWrapper (org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer is in unnamed module of loader java.net.URLClassLoader @45fe3ee3; io.tomko.bonestreasures.wrappers.PlayerWrapper is in unnamed module of loader 'BaT-0.0.1-shaded.jar' @41c2c70)
it gets the index of a space
why wtf
probably want to look into thr string javadocs
what if i wanted to get everything up to a "/" character?
Ah ok.
the what
hmm
bump
Look into delegates
you cannot implement Player
ranged for loop?
I'm using meta.setLore(Collections.singletonList(meta.getLore().split)); but split keeps saying "Cannot resolve symbol"
He can
as the server doesnt give a fuck about your impl
well you can
but the server will happily keep constructing craftplayers
He just needs to delegate properly
yah
Obv he can’t cast it
lore is list
how do they work?
wdym?
1 sec
just a wrapper
ok
is Player a private class?
always fun looking at internals , what is this crap bruh
md_5's code?
I'm now using meta.setLore((List<String>) Collections.singletonList(meta.getLore().toString().split("/")));
But where should I go from there to get the first half of the string?
xD
stop this code is awful
so messy
always fun when you see an assignment used as an expression
brr
I’ve never seen that actually be used in random Java code before
why exactly this.lore = null and in the next one this.lore.clear() xD
should i do like string[1] after that?
who will ever say
aight thx
how shall I get my wrapper class from Player?
you forgot the best part bruh
i mean after reading it 5x it does make sense, but its pretty redundant
or lombok, but delegating every single method hmm
still redundant conditioning. if lore == null then lore = Collections.EmptyList();
and then
this.lore.set
please ignore the pseduo before the code
pretty sure EmptyList() is immutable
🤷♀️
soo constructing new Wrapper?
basically
guys i'm using getlore but how can i specify a specific line of lore?
How can you send emotes like these with spigot?
You’d pass player through the constructor
i got ptsd from bukkits exception throwing
Store it locally
resourcepack probably
nope, its normal chat
Then either delegate each function or make a getPlayer method @twilit roost
so the list is
item 1 = line 1
etc?
idk if minecraft font supports those characters?
its like 1000 useless lines of msg and 1 line containing the actual error rest is just where it occured which is so large that it doesnt fit the console
yes, I saw many of them
How to register alias commands in bukkit command system
the list is
index 0; first line
index 1; second line
...
throught plugin.yml?
under the command there a param aliases: []
Oh yeah i just saw it
and there are many "emotes" plugins
but I need just to send an emote through a message
bruh my brother is cleaning his laptop internals with the vacuum cleaner
static discharge be like
pressurized air ftw
hmm somehow i need a new lappy
quick ways to fuck things up
ah yes big brain
remember my attempt from a year ago to manipulate the command list at runtime by directly accessing the private maps with reflection? yea it worked
its nasty but i managed to completly delete vanilla commands at runtime
🤣
why wouldnt it
yea but its a nasty hassle
i use reflections when i really shouldnt be using it
instead of making my field not final, i used reflections to change the internals of some lib i used 💀
💀
which is a private field of like 10 child classes
good news is i did manage to change it
bad news is server didnt like it and crashed
💀
xD yea reflection is wyld
but its a rigid approach and if they change something in their code ur code just goes full nuclear karen
What would be the most resource friendly way to check if player holds item and then display action bar if he does
There’s a event for player hotbar switch or smth
yes but you need to send an action bar message every so often anyways
and then timer as long as he holds it
bukkit runnable?
isnt java 18+ supposed to use var- and methodhandles for reflection? cant seem to find anything?
yep
you would probably always have a timer
and then just either show the held item or nothing
on each timer update
Have a set (weak) of players that has the item
One task that runs over the set
Double checks they’re holding the item then display it.
On that event add and remove from the set
yee just thought of this
imma implement it
thx
have a recursive bukkit runable
why double check
jk
Dropping items
you dont even need the event
He asked for a resource friendly way
yeah, having a single timer is most resource friendly is it not
isnt it action based = events and state based = ticks?
to accurately check for behavior?
what behaviour
like if the player takes the item off their hand
its an event
and to measure the time they helt it
its based on ticks
He has a single timer with my idea?
yes but also this set with players
He’s just not looping all players, but all players from the event.
a single timer gets more load the more players are online
No
Not the way i suggested.
id prob have a timer per player and only when they hold it for as long as they hold it
lemme backread again
no
this would be inefficient
It’s mostly useless optimizing, but whatever he wants he gets.
as in the runnable holds a map with players who hold the item
Not a map.
which is determined by the event
A simple weak set
for what reason is it not
isnt a runable a dedicated thread? xD
uh
Or should be atleast
this^
Is the event called if someone is holding X item and switches off of it
Is it InventoryMoveItemEvent?
?jd-s
use PlayerItemHeldEvent
👍
I assume the event gets called after the Item in hand is changed. so if I wanted to do something if a specific item was being held BEFORE it was changed, I don't even need to check the current item, just the event.getPreviousSlot()
👍
i need help
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
oh thx
this is how HR thinks problems are solved xD
im trying to make my own server using spigot but the run.bat file wont open, instead cmd prompt opens saying this: "Error: Unable to access jarfile spigot.jar"
erm
doesnt the spigot server have a version number behind its name
u need to use the explicit file name
#help-server @jovial shadow
oh thanks
How can people literally not even read the error message lol
you’re asking for a lot
This is spigot sir
The average iq is 5
?whereami
forgiven
I bash on all of spigot
- You're in the wrong channel
- You can search for the exact 5 words you said in google and first link will give you answer
^
3rd i didnt ask the question but answered it kekw
mb wrong tag, not that deep
As a matter fact, the first 4 links
Actually, the first 4 pages
are you telling me how to google
I'm telling the guy that asked the question how to google
mb wrong tag, not that deep
yes he couldve done better, no i do not agree with the SO mentality
idk I think when people are smart enough to blindly copy/paste some random bat file without knowing what it does nor trying to understand what it does, then they should at least copy/paste the error message they get into google too, instead of heading into a plugin development channel to throw it in there without any further context
you should never paste code you don't know what it is / or what it does
that's how people get hacked
My main class stores a static singleton. This instance of the ItemManager will be heavily used to reference a HashMap found in the singleton. Is this acceptable?
public static final ItemManager ITEM_MANAGER = new ItemManager();```
generally personally I'd stick with di
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
however, this could be acceptable
I also like DI more but it's fine
I'd just switch from a static field to a static method
oh okay. So I'll make the singleton non static and make a static method used to reference the singleton?
Thats basically the same thing
Lately I've just been having a public ItemManager itemManager;
field and initialize in onEnable then just with DI use plugin.itemManager
Yeah thats the better solution
I like it, it looks clean and does everything correctly
and just pass the itemManager instance into every class that needs it?
public PhoneManager phoneManager;
@Override
public void onEnable() {
phoneManager = new PhoneManager(this);
}
Yup
ik all im saying is that bashing on someone new doesnt really make em feel welcome like:
A: i have a stupid question.
B: ?ask
A: <asks stupid question>
BCDE: why are you so stupid.
this is like eh. remember when u just started did u know what is good and poor practice at the very beginning? xD
Oke, you guys are the pros. I'll do that 😄
Then inside the "manager class"
Ofc i didnt, but i used google for obvious error messages
public class ItemManager {
/**
* A HashMap of every item's ItemData.
*
* Integer - The number used to represent this item's unique identification.
* ItemData - All the data associated with 7 Realm's Custom Item system.
*/
private final HashMap<Integer, ItemData> itemDataMap;
public ItemManager() {
this.itemDataMap = new HashMap<>();
}
/**
* Give a Player a Custom Item.
*/
// TODO Create a command to execute this method
public void giveItem(Player player, int id) {
ItemData itemData = itemDataMap.get(id);
player.getInventory().addItem(itemData.getITEM_STACK());
}
/**
* Get item data based on unique ID.
*/
public ItemData getData(int id) {
return this.itemDataMap.get(id);
}
}```is this acceptable?
public class PhoneManager {
private final MainPlugin plugin;
public PhoneManager(MainPlugin plugin) {
this.plugin = plugin;
}
If you do not need a instance of the main class yes
What would be a good way to access the singleton when a player is executing a command though? for example.
We just said it no?
Just not sure how to pass it in without a constructor
btw intellij throws alot of warnings because i did not create an instance of my main class(obv), do i need some spigot plugin or so to have the IDE interpret the syntax correctly?
Show me what you're tring to do
What type of errors? I don't get any
I haven't done it yet, but I'll get started on the idea give me several minutes
Use method 2
not error, warnings that my in my plugin.yml defined main class has no instances
like im getting a warning that i never use it
obviously
no, just add @SuppressWarnings("unused") to your main class
xD
or just ignore the "unused declaration" things
Are you using maven?
ya
probably because of mc dev plugin
i mean is there another way but maven now
I don't use it
that they remapped the server jar
also i do admit that using maven has its advantages, like u dont need to download a copy of the repo as maven does that for u
Make sure you still make new projects using maven but it's nice to have it in the backgrouhnd
tbh if you're not using maven/gradle I would reconsider
tbh i hated to start using it cause its just overly complex
but it does have benefits
The days of adding dependency libraries using the jar file are dead
yea ik
If you want a quicker maven start for new plugin, use alex's architecture
i already set it up
Then you're ready to go
after like 2 hours of testing i also finally managed to install the jdk and jre 20 on both my windows machine and my WSL distro
I want to initiate a enum value with ItemStack. But I need this ItemStack to be modified (add lorelist, set title, etc.), this can't be done in one line. What should I do then?
Show some code please,
item builders is the simple answer
ItemBuilder
They have arrived
or you'd need to use some lambda or consumer/callable for it
though id still like to know how to download the remapped nms repo
?nms
Use the static init block
i heared there would be one
nms isnt on a repo, you have to build buildtools
Something like this, lambda is just for example...
BuildTools is just better
i did build it
public class Gi implements CommandExecutor {
private final Realms main;
public Gi(Realms main) {
this.main = main;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Must be executed by a player.");
return false;
}
main.ITEM_MANAGER.giveItem((Player) sender,1);
return false;
}
}```If this is what I'm supposed to do, how should I store the instance of the `Gi` class?
Lorelist and title depends on enum
where can i find the nms dependencies
it should now be on your local maven rpeo
kk
Why do you need a instance of GI class
good point lmao
$USER_HOME/.m2/repository/org/spigotmc/spigot/ver/spigot.version-remapped.jar
Wandering around your memory
and i presume ill include that instead of the repo url?
that path
Consumer<ItemStack>
Are static imports frowned upon or acceptable? I'm interested in using them for easier readability
Just fill the dependency section
kk
They are not but people tend to abuse static
So teaching to not use it when not needed is better at the start
i am so done, ive spent the past half hour figuring out why my listener doesnt work, now realising that i didnt register it
ffs
xd
When is an okay time to use a static import?
Happens to the best
they tend to be frowned upon unless you are working with a class with a super long name and require static methods from it frequently
y2k can prob answer that better
xD
Oh wait nvm @paper venture Function<Void, ItemStack>
but I assume static is mostly just used when you're making a Utility class or something that does not require a instance like a Utility methoid
i wonder if i could make an annotation processor to auto register my classes
Noted. I'll avoid them unless the naming gets too unbearably long
a good example of a decent place to use a static instance would be when working with a builder heavy library such as Brigadier a command library by mojang
So I just have to pass a functional interface and then an itemstack to my enums?
You can
I just went off what you posted.
Okay thanks!
thats called a Supplier<ItemStack> kek
these are some big scary words imma stick with String
I did that once for auto registering protocol packet classes
not for MC
you prob could, but like I wouldn't know how to do that on compile time
way to complex for my brain
javax annotation processor
you know who would know
i think im going to wrap a function inside a native library in which i write my code in inline assembly. then i load that to my plugin and unlimited power
hello yesterday i could look at bukkit and spigot's code but now intellij wants me to decompile it to see it
Ah yes that was it thank you
the what
I'm trying to modify the cauldron level but I have failed.
Is there anything wrong with my code?
This is my code. ("block" is the specific block that I want to modify)
Levelled cauldron = (Levelled) block.getBlockData();
cauldron.setLevel(0);
block.setBlockData(cauldron);
I mean yesterday i could just ctrl+click for example StructureManager to see the class, but now when i do that it asks if i want to decompile it
not entirely sure what went wrong there but do u have the correct api?
because decompiling sounds as if u have byte code
ugghhhhh
what is the best way to create constantConfig?
whats that
you also ran mvn clean. I don;t use InteliJ so perhaps you don;t have sources
like I want to change the sound of clicking UI which is configurable
i did have sources like, yesterday. but yeah it dissapeared after I cleaned
class/enum/inferface?
just make normal config file
a texture pack?
nah
unsure what you are really asking then
nvm
no idea how old https://i.stack.imgur.com/15hcl.png
damn i was looking there just when you sent that x) Thanks!
just create a config file
Static abuser!
.
why should it not be static?
It can be static, just not recommended, people usually make too much stuff static which is called static abuse when it doesn't have to be static
So learning to not spam static from the start is good
It should be static
It is constant value and no need to be like that
and it is editable so not final
Once again, never said it can't be static, just said it's not recommended
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
people usually make too much stuff static which is called static abuse when it doesn't have to be static
I do know this
hiw else would you be able to use it everywhere
instance and di?
anyone know if it's possible to reduce the size of the initial lingering potion bounding box before it splashes
Which is the principle of oop
di makes everything messy for bigger plugins
since you have to pass the same thing 50 times in every constructor to just get some config value
Which is why I said
It can be static, just not recommended
the file only exists once
I've explained 3 times why it's not recommended but sure, it's your code, go ahead
anyways what is the issue?
No idea, I stopped reading when he took advice as a personal attack
another question can you splash a potion forcefully, or does it have to land somewhere
like i want to spawn a splash potion that just splashes instantly
does it do that anyway
Does it have to be a splash potion or are you just trying to apply potion effects?
Any reason why you can't just spawn particles without the potion?
it might have functionality later
so i'd like to keep that open
if i want it to do anything in future
^
What do you mean highlight?
What's the acceptable way to reference a Material enum object from a config file?
My first thought was doing something like Material.valueOf("AMETHYST_SHARD"); as an example.
However this seems to produce an error, unsure why
String is the best way
No enum constant org.bukkit.Material.LEGACY_AMETHYST_SHARD
public ItemData(int id, String name, String description, String material, int customModelData, ItemRarity rarity, ItemStats stats, ItemAttributes[] attributes, ItemEffects[] effects) {
this.ID = id;
this.NAME = name;
this.DESCRIPTION = org.bukkit.Color.WHITE + description;
this.MATERIAL = Material.valueOf(material);
this.CUSTOM_MODEL_DATA = customModelData;
this.RARITY = rarity;
this.STATS = stats;
this.ATTRIBUTES = attributes;
this.EFFECTS = effects;
this.ITEM_STACK = generateItemStack(this);
}```
Before that
You forgot to set the api version in your plugin.yml
You're either doing config.getMaterial or config.getString
is it bad to have empty interfaces just to call instanceof on
for categorizing things
hmm singleton is a better way to do It :d
i used DI
Not sure if that's sarcasm or not
I wrote this to simulate reading data from a config filejava public ItemManager() { this.itemDataMap = new HashMap<>(); ItemStats stats = new ItemStats(1, 1, 10, 0, 0, 0, 0, 0, 0, 0); ItemData itemData = new ItemData(1, "Test", "This is a test item.", "AMETHYST_SHARD", -1, ItemRarity.MYTHIC, stats, null, null); this.itemDataMap.put(1, itemData); }
use*
.
ew no
Then yes, API version
Dependency Injection?
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
thank you as well @chrome beacon
I mean why?
