#help-development
1 messages ¡ Page 2035 of 1
you know, in case i come back to make a plugin in 2024 or so
i wont remember all this
you should not do that
thats my primary goal
you should not just update your dependencies just because there's a new version
but im always compiling to the latest mc version
you can use mvn version plugin
one second
mvn versions:display-dependency-updates
or for your maven plugins:
mvn versions:display-plugin-updates
it'll print out all plugins you can "update" then
or dependencies
but you should never just automatically update them, you should always stick to the version you know that's working for you, and only update if you have a reason to
that's basically the whole point of maven - to make your build consistent and reproducable
Ironically Maven has been worse at this than Gradle for me
why does it print like that
how so?
I always have to turn to IntelliJ's "before launch tasks" system to get shit to work
that's the default output format if you don't have the maven-iforgotthename-plugin specified
maven-enforcer it is I guess
yea, but im not updating any dependency on already existing projects, its to create boilerplate for new projects
Also:
Why the fuck do I need to install a submodule to be able to use it as a dependency
Also:
you don't have to do that
Why the fuck didn't Maven compile before running one of my submodules?
Why do I have to configure it to do that manually?
how would it compile your stuff if your submodules, on which you depend on, weren't compiled yet?
I'm referring to
a completely isolated submodule
where
I try to run it
and then I get a class not found error
because Maven didn't even try to compile it
compile what exactly?
the submodule
and what class didn't it find?
if your submodule depends on a class from your main module, then of course that won't work
it doesn't
then I don't understand your setup
I had two modules
which did not depend on the parent, or each other
I just needed to use a parent POM so I could have them in the same Maven project
I compiled one and used its binary as an input to the other
But manually
Because fuck trying to do that through Maven
works fine for me, you must have gotten something wrong
this is what i want i think https://repo1.maven.org/maven2/org/codehaus/mojo/exec-maven-plugin/
I don't think so because I've done similar things in other projects and its worked fine
For this particular one it just broke
Also
It is fucking impossible to use Maven for anything complicated and I will take that to my grave
that's why I say, you must have gotten something wrong in this particular project then đ
it's really not
I literally spent 2 hours on something before giving up because it just didn't make sense and Google did not help
I was trying to place the binary of one submodule inside the binary of another
Which is a slightly uncommon thing
but shouldn't be too hard, right?
If I can describe it in a single sentence, it should be easily done
2 hours
normally you want to have a "distribution" pom that puts your stuff together instead of letting the parent pom do it
And it still didn't work
That is what I tried
Fucking what is it uhh
maven-assembly-plugin is impossible to use
And the modules system is god awful
assembly is the stupid version of the shade plugin
I'd always use shade instead of assembly plugin
Shade plugin has no option not to unpack binaries
It is too specific
I mean my use-case is pretty specific
I was trying to have a dynamic agent jar inside my jar so I could extract it at runtime
but
binary-in-binary stuff in Java is also common with JNI
which is actually common
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
this version will change depending on what is minecraft using, right?
because thats what minecraft is using?
what if i set that to 8, for example
i cant use that plugin in 1.17+
how can i get that? https://hub.spigotmc.org/javadocs/spigot/org/bukkit/map/MapCanvas.html
declaration: package: org.bukkit.map, interface: MapCanvas
or something like that
of course you can
java 8 plugins run fine on MC 1.18
and 1.17
etc
if you only want to support mc 1.18+, yes
you can get that in a MapRenderer's render() method
example:
public class DeathMapManager {
private static final Main main = Main.getInstance();
private static MapCursor.Type getCursorType() {
MapCursor.Type type = EnumUtils.getIfPresent(MapCursor.Type.class,main.getConfig().getString(Config.DEATH_MAP_MARKER.toUpperCase(Locale.ROOT)))
.orElse(null);
if(type == null) {
type = MapCursor.Type.RED_X;
main.getLogger().warning("You are using an invalid value for " + Config.DEATH_MAP_MARKER + ". Please see config.yml for valid values. Falling back to RED_X now.");
}
return type;
}
public static ItemStack getDeathMap(Location location) {
ItemStack map = new ItemStack(Material.FILLED_MAP);
MapMeta meta = (MapMeta) map.getItemMeta();
MapView view = Bukkit.createMap(location.getWorld());
view.setScale(MapView.Scale.CLOSE);
view.setCenterX(location.getBlockX());
view.setCenterZ(location.getBlockZ());
view.setUnlimitedTracking(true);
view.setTrackingPosition(true);
view.addRenderer(new DeathMapRenderer(getCursorType()));
meta.setMapView(view);
PDCUtils.set(meta, NBTTags.DEATH_MAP, PersistentDataType.BYTE,(byte) 1);
map.setItemMeta(meta);
return map;
}
public static boolean isDeathMap(ItemStack itemStack) {
if(itemStack == null) return false;
if(!itemStack.hasItemMeta()) return false;
return PDCUtils.has(itemStack,NBTTags.DEATH_MAP,PersistentDataType.BYTE);
}
private static class DeathMapRenderer extends MapRenderer {
private boolean isDone = false;
private final MapCursor.Type type;
private DeathMapRenderer(MapCursor.Type type) {
this.type = type;
}
@Override
public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Player player) {
if(isDone) return;
isDone = true;
canvas.getCursors().addCursor(new MapCursor((byte)0, (byte)0, (byte)0, type, true));
}
}
}
isnt there a getter method?
you don't have a MapCanvas outside of a MapRenderer
:C
what do yo uneed it for?
i want to draw some pixels
yeah, just attach a custom MapRenderer to your map's view
as I did above
my maprenderer above simply adds a cursor
a square
you can use the same to draw your rectangle
ok thanks
np
intelligence
256x256 I believe
Mb it's 128x128
Sorry had to look it up on Google
does spigot have 1.19 support? if it does, can i use buildtools to get it?
are the nms mappings subject to change also?
because you use it wrong and for the wrong purpose
most people should stick with shade plugin as that is the most appropriate to use
assembly plugin is for when you need to do other things like making a WAR file or configurations need to go into other places.
also you need the assembly plugin when dealing with native dependencies
No
sadness
Lets the say the wool block closer to the bottom is the starting location, and the wool block closer to the top is the end location. I've figured out how to get the location in front (stone block), how would I get the blocks to the left/right of it (the dirt blocks)
well, depends on when you need to do such things
and why
there is various ways you can do it
but which is the most ideal depends on some factors you haven't presented
Vectors have various rotateAround methods
Hmmm, so basically I'm making a mob pathfind to the nearest ore, and I want to find the 2 blocks beside it so I can set them to air.
I've not figured out how to make it go downwards yet, but that's probably not very hard
Hierarchical Path A* look into that kind of pathfinding might be able to find a lib somewhere that implements that
Interesting, I'll take a loom
Our looms cost $20
lol
It seems like this algo finds it's way around ores, ores would usually be in the ground, will it still work
yes, the reason I suggested it is that it breaks up the pathfinding up into maps
making it easier to see what is near your path
similar to like how bounding boxes work
you would modify it so that instead of going around ores
it will go to ores đ
Wait, I've kind of cheesed it, I set it to path find to the location, and when it is done, if it still more than 3 blocks away from the destination it break the 3 blocks in front of them and restart the pathfinding, the only problem is it doesn't work if it isn't right in front, which is why I wanted to break the 3 blocks to the left and right as well
well, the pathfinding method I stated, when it breaks it up into maps
you can better find the ores along the path
including in front
Hmm, I have no clue how I would even approach implementing that into the pathfinding of a spigot mob, do you have a link on how I would implement it or something of the sort
Sheesh
Howdy! Does anyone know how to assign a banner pattern to a shield?
bannermeta
cast the itemmeta to BannerMeta
declaration: package: org.bukkit.inventory.meta, interface: BannerMeta
BannerMeta#setPattern(index, Pattern)
@strong parcel
Yea , you should be able to do item.getMeta
But cast it to banner Mets
And then set the pattern
And then set the meta@of the item to your banner meta
Thanks! I am also changing the Display name and lore of the shield. Would setting the item meta to the banner meta overwrite the name and lore changes?
Okay, so I could do BannerMeta.setDisplay(âCool shieldâ) ?
yes
Alright, thanks!
banner meta is just item meta with extra methods for banners
same as skullmeta, etc
Hii , when i dev plugins for spigot 1.17.1 , on file plugin.yml , the api-version is 1.17 or 1.17.1 ?
1.17
ok thanks :p
website or IDE docs?
i'm french , and i'm bad in english so not easy for me ^^
Website javadocs are great. Use the search box, top right
as for teh layout, it comes with experience.
hi
how to make click on leave all the leaves nearby turn to web?
i have try to world.getlocation but it only get x+, x- or y+y-, z+z- it don't have every block near change
You want to change all connected leaf blocks in an area to web when you click on one block?
You would need to either write an algorithm to search connected blocks from the clicked block (with a range limit), or search an area (cuboid) around the clicked block to find all leaf blocks
Run it async then when you've discovered a block run a sync task to change it
I'm currently parsing some poms and came to an edge case: is "${pom.version}" equivalent to "${project.version}" in maven or is there some difference?
How can i animate something like a fake fire? Like much smoke that is raising in the air?
you could spawn smoke particles
Yeah but the just fly away in all directions
Given that that pom is from 2006 and assuming pom.version to be equal to project.version doesn't cause any problems, I'll just assume that it is equal
after how many comparations/invocations with a value / uses of a function does it make sense to cache said value/object of the function?
for example in event registering
when does it start making sense to cache the PluginManager?
For this particular case:
Performance wise -> never.
You would only do that for cleanness.
Generally speaking:
Really depends on your methods.
do you know why it wouldnt improve performance?
how would i distribute x amount of objects over y amount of threads, using
List<Object> objs;
/* into */ Map<Integer, List<Object>> distributed;
without leaving any
for (int i = 0; i < objs.size();i++) {
distrbuted.put(i % y, objs.get(i));
}
it's a pretty bad implementation performance-wise but certainly the easiest
technically it could be a List<List<Object>>
I'm feeling like im slowly becoming insane here
where does the --remapped, --generate-docs and --generate-sources spit out said .jar files???
Heya guys. Does it exists a way to see git blame online on a spigot stash's repo?
maven local likely
?stash
yea see thing is
mh, what?
white mode
And you are sure that you are building 1.18.2?
yes, my args are --rev 1.18.2 --remapped --generate-docs --generate-sources
?bt
thats where i got them from yes
which does NOT answer the question why it builds only the api
I'm building it myself
I never use NMS myself, so I rarely have a bt jar lying around myself, so that command is the easiest way to obtain it
on that topic it said that --remapped is not an 'existing profile'
do you know the correct argument for that?
Guys, is it normal that on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Bukkit.java doesn't exist the method getMinecraftVersion() ?
Did it use to exist?
yeah
did it ever exist đ
Ohhh, maybe it was a paper thing
Isnt it the same as getVersion()
just use that
It is, https://helpch.at/docs/1.17/org/bukkit/Bukkit.html does show as it having existed in recent time
It is slightly different, using that method I need to work on the string
path-to-your-bt-jar/Spigot/Spigot-Server/target
Or ~/.m2/repository/org/spigotmc/spigot
You don't know why when I import org.bukkit.command.CommandSender; so will it give me an error?
Did you include the bukkit/spigot-api/etc. jar in your build path?
originally i did not since I've been told i can just leave like that but that gives an error
something something not avilable something something
Nah that was to @spare sky
I tested spigot 1.12.2 spigot 1.18.1 and spigot 1.8
Maven or gradle?
me be maven, and reason for this question in the first place is that just leaving it 'as is' does NOT import javadoc
You should just be using org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT
?
Okay, then let's assume neither. IntelliJ or Eclipse?
Eclipse
do i just hit 'import sources and javadoc' here, then?
Then either migrate to maven/gradle or add https://hub.spigotmc.org/nexus/content/repositories/snapshots/org/spigotmc/spigot-api/1.18.2-R0.1-SNAPSHOT/spigot-api-1.18.2-R0.1-20220318.230433-21-shaded.jar to your build path
or rather does that import the sources/javadoc from the web or from the .m2 folder?
okey
You need to depend on spigot-api for javadocs. spigot itself does not have any
You can easily do that while not importing the spigot-api itself by having a classifier
different artifact, not classifier
what's the correct pom.xml entry then
no, classifier
Can I have more modulepaths? I'm sorry to ask about stupid questions but I just started and I want to put one plugin from 1.12.2 to 1.18.1
<dependency>
<groupId>io.github.coolmineman</groupId>
<artifactId>trieharder</artifactId>
<version>0.2.0</version>
<classifier>javadoc</classifier>
<type>jar</type>
</dependency>
something like this I guess
a doubt, all entities are updated within the world within a period of 50ms (20 tps) or on the tick base of Minecraft?
i meant for getting the javadoc from the .m2 folder
What the hell do you use
1.12.2 does not support Java 9 or higher by default, you would need add the jar to the classpath (not module path)
But either way, this works of course with org.spigotmc:spigot-api instead of whatever I have included
i dont know what i did but it works now
thanks i guess
on a different note
should i make a public static field for the plugin instance or make it private and write a getter, which method is wrong, and why?
uh what am i supposed to do then
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/java/JavaPlugin.html#getPlugin(java.lang.Class) is the correct solution
declaration: package: org.bukkit.plugin.java, class: JavaPlugin
Can you go to PM? I will send you screenshot how i did it
MainClass.getPlugin(MainClass.class) somehow looks wrong
am i really supposed to do that?
MainClass pluginInstance = JavaPlugin.getPlugin(MainClass.class) is correct, yes
No
why not cache the instance in a static variable?
you should not use it within your own plugin - for that you should use DI
i meant in my own plugin
API consumers should only call this method once
?di Then all three methods are wrong
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
there is no need for a static field
And the difference between GETSTATIC and GETFIELD is perhaps a few clock cycles but not much more
It works with pretty much everything and long as you have relatively sane code
is that a copy of the mainclass or a pointer?
It's a low-level reference, yes
To answer your question, it does not copy the contents of the object. It might copy the header structure or whatever, but that is small enough to be discardable
ah that makes sense
since it can still access the actual object it is closer to a pointer, yes?
Yes and an instance comparison will yield true
k thanks
wish we could just do public this(args){} instead of having to specify the class name
You can do
{
// Code
}
If you want to have a no-args constructor. Just note that this block will also be implicitly run when a constructor is invoked with args
huh thats interesting if a bit useless
i have never found myself using a empty constructor
*no-args
It is usefull if you are dealing with checked exceptions
wait what
oh
so thats the concept behind
static {
// ...
}
just that static {} runs on class init and {} on object init
yeah
hey wahts the best way to get a random double between two numbers?
ThreadLocalRandom.current().nextDouble(min, max);?
yeah
aight thanks
A more simplictic solution would be random.nextDouble(max - min) + min
Or if you use a more modern version of java even random.nextDouble(min, max) works
(where as random is an instance of java.util.Random)
hey does creating a new entitydamageevent and specifiing the damage and entity
does that actually damage the entity
or do i have to run LivingEntity#damage()
The even itself does nothing
It's only a signal to plugins
Also be aware that event constructors are not public API
(A strange design decision though - but it is true)
why is the get method in Map not of the signature V get(T t) instead of V get(Object obj)?
so to actually damage the player i would need to do livingentity.damage
yes
someone was drunk that day
It could have also been an artifact of the early days of generics
fun
i wish there was a way to just push a stack frame onto the thread stack and force a synchronous method call
Hello!
I made a command that sends player to a server, and I would like to make a reliable system that tries every 5 seconds to send a player to a server if it's online.
I tried with a while boucle that sends the player if the server is accessible (with the method .canAccess(ProxiedPlayer p) & responds with a ping, and sometimes it sends me even if the server isn't available.
How can I proceed?
Thanks
why would you want to do that
to test my task system
i dont have the bukkit scheduler available in junit
so i need to do something else
A thread group might be good there
I however rarely use it so I do not know the name of the central thread pool
?
you mean java.lang.ThreadGroup
or something
https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/Executors.html actually I meant the ThreadPools
no but i want a structure like
- main -> calls task 1 (sync)
| main -> executes task 1
- main -> calls task 2 (async)
| other thread -> executes task 2
v makes main call task 3
- main -> calls task 3 (...)
oh wait
i think i see what you mean
Also just note that async is the worst word to ever exist
does a Callable grant the ability to call it in the thread where it was made
It could run on a new thread, on a thread pool, on a thread dedicated for such operations, on the main thread or it could also never run
so if i create it in main and call it in other thread will it run on the main thread
As such I prefer if people use the words "Off-thread" or "Concurrent"
Yes that is possible
The callable needs to be defined before or while the operation runs. You cannot define it after it runs
How to enchant an item?
?jd-s
nah this doesnt work
declaration: package: org.bukkit.inventory, class: ItemStack
Or you are thinking about futures
Could you try to specify it further?
i simply want to call back to a different thread from another thread
whenever its needed
could i use threadlocals?
oh no wait
So something like
task1 () {
}task2 (Lock lock) {
lock.unlock();
}
task3() {}
main() {
task1();
Lock lock = createLock();
lock.lock();
new Thread(() -> task2(lock)).start();
lock.awawitUnlock();
task3();
}
?
In that case, you could replace your task2 with a (completeable-)future
is lock a built in class
oh ye
but the problem is that the whole point is that it will be asynchronous
so it wont block the caller thread while an async task is running
You need to block the thread in order for it process the task
i'm having a small problem with dealing the correct amount of damage to a player.
ive been using LivingEntity#damage(double damage, @Nullable Entity source)
its been quite inaccurate.
it dealt 5 hearts when the message says it should have dealt 6.25
[12:46:26 INFO]: EntitiesDamaged Fresh Hashmap: {}
[12:46:26 INFO]: PlayerDamage Fresh Hashmap: {}
[12:46:26 INFO]: Shooter: CraftPlayer{name=clonkc}
[12:46:26 INFO]: Entity: CraftPlayer{name=clonkc}
[12:46:26 INFO]: Minimum damage: 10.0
[12:46:26 INFO]: Maximum damage: 14.0
[12:46:26 INFO]: Randomdamage: 12.529193606696865
[12:46:26 INFO]: TruncatedRandomDamage: 12.5
[12:46:26 INFO]: Distance: 4.219880848263866
[12:46:26 INFO]: DistanceTruncated: 4.2
[12:46:26 INFO]: TotalDamage Filled Hashmap: {5c93ac00-5aeb-45f6-8163-b2740cf27a68=12.5}
[12:46:26 INFO]: EntitiesDamaged Filled Hashmap: {5c93ac00-5aeb-45f6-8163-b2740cf27a68=1}
[12:46:26 INFO]: PlayerDamage Filled Hashmap: {}
[12:46:26 INFO]: TotalDamageDealt: 12.5
[12:46:26 INFO]: TotalDamageDealt Truncated: 12.5
[12:46:26 INFO]: Entities Damaged end hashmap: {}
[12:46:26 INFO]: total damage end hashmap: {}
[12:46:26 INFO]: player damage end hashmap: {}```
i outputted some info
there doesnt seem to be any issues
Or if you do not care about when it invokes the task on the main thread and have some tick system
list<Runnable> sdghnjksvb
void tick()
// caighhklj5r
sdghnjksvb.foreach(Runnable::run)
}
task2() {
sdghnjksvb.add(() -> this::task3);
}
this might give some backstory
yeah thats what i use in 'production'
with the bukkit scheduler
ok well somethings clearly wrong but i dont know what.
doesn't explosion damage have falloff
but i guess ill test the rest and optimize it later
whats that?
more distance == less damage
Or just stop attempting to try to have something run on thread X
yeah is there a way to make that static
(Concurrency safety!!!)
Like, as soon as everything is thread-safe you don't have to care about on what thread something runs on at all
are you directly dealing damage or setting the damage the fireball does to entities
directly dealing since im using onexplode and not entitydamagebyentityevent
i couldnbt really get my head around using entitydamagebyentityevent
should i add all the damaged entities by a certain explosion to a hashmap and then get the info there?
code for damage plese
im using bukkit here
but then i would need a multimap/nested map since i would need to store damage values and distance
thats not thread safe at all
it actually prevents usage of the api asynchronously
should i put it in a paste
would help
usually we use something else but meh that works too
for the record this discord uses
?paste
async block#setType when? đŚ
o
im using that tho
that might convert the damage to what's normal for an explosoin
oh right
then i would have to make an entitydamageevent to set the last damage cause
otherwise errors would bt thrown
wdym?
the player would die from an unknown cause right
livingEntity.setLastDamageCause(new EntityDamageEvent(livingEntity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, truncatedRandomDamage));
Is there a way to make like a win and losses system?
just tried, same result
12.5 -> 6.25 hearts
yeah ik
that should be an absolute value
you are going to have to be a little more specific
1 entities
noob
shut
i dont think grammar is the issue here
Like a minigame win and losses system
also I am really unsure why the damage fluctuates like that, sorry
yea, why would that not be possible
Well I was figuring out a way how to do that but I couldn't really find a good solution
honestly still not sure what u mean with a win/loss system
Bruh
you were given
Just search win loss hypixel and see images
yeah but for what
so you want to display a players wins & losses & have a leaderboard
????? why does 150+ damage not kill a zombe
Well not in a lb but more on their scoreboard
OH I KNOW WHY
well then just store their wins and loses somewhere and display them where you want.
i cant damage the entity in the no damage tick, i.e. the part where they are red
its just doing the normal fireball damage im fairly sure
Yea but I was wondering how do you make that system
lol
Bukkit has it's own API for dealing with this. And if you are outside of Bukkit then there is likely somewhere some API for dealing with pushing a task on the "main" thread. However when creating your own APIs you should just make your (and other's) life easier by making everything thread-safe
But if ya got like any suggestions
i have to do it in the not server thread tho
but i already found a solution
so its fine
idk if u have other playerdata. but i would have some kind of PlayerCache that holds all the player specific data which would get saved to a file
How can you generate a vanilla structure, for example an ocean monument ?
although im getting this
(besides calling a command)
Ok..
what exactly is your solution there?
ok nvm that completely did not work
And why is it using monitors...
its meant to do 1.7 damage wtf is wrong with it
[13:12:38 INFO]: Randomdamage: 1.7340708572622148
and it insta kills me
im fairly sure thats not normal
static or JavaPlugin linked instances of FileConfigurations?
i dont use fileconfiguration
lmao
i have used javaplugin linked
in the past but i dont know if htats the best way
ask geol
he probably knows
Ideally you'd not link the file config to anything
so a static public one?
Nah
?
Either way I do not know enough context to make a call there
public static is probably wrong though
well configurations... I've been told earlier to for example not store a static instancce of the MainClass instance, but configurations are something that i feel like they should be global
i setup my whole config in one line lol
usually you'd just pass the config down wherever it is needed
setConfiguration(new Configuration(this, YamlDocument.create(new File(getDataFolder(), "config.yml"), getResource("config.yml"), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setAutoSave(true).setVersioning(new Pattern(Segment.range(1, Integer.MAX_VALUE), Segment.literal("."), Segment.range(0, 10)), "file-version").build())));
well but how to store it
store what
the config
i just use a lmobok gettter class
field
the thing im passing down is my MainClass but how do i stuff the configuration in that MainClass is my question
lemme draw a schematic
ok its a bit messy but this should owrk
what is it doin?
@smoky oak something like that
Works until you want to wait for multiple processes
you create multiple services
Also what are you going to do when something crashes?
LMAo
Or if there is a deadlock
microsoft paint moment
what if i want to pass the main class as well? I should just pass the main class, but what kind of field should i choose for the config instance?
hey how would i set the explosion of an entities last damage to 0
You really need to have a supervisor thread (technically you can use the main thread for that but that is going to cause issues)
ight thanks for the feedback ill work on it
but my problem is that i cant damage them in the no damage ticks time
Plus why not inline the wait into the main thread right now it is just wasting CPU cycles
although its probably not needed for what im trying to do
it blocks using a lock
so until there are tasks to run it wont waste cpu
heres the code
yes, that is the issue.
Let's say Thread A schedules Task C to run on Thread B. Thread B taskes 583 ms to complete Task C. However Thread A waits until Task C is completed - i. e. it spends more than 583 ms waiting. Why shouldn't Thread A run Task C directly instead of delegating the task to Thread B?
its not on a different thread
tickLoop() is a direct function
check the code
i mean TickLoop#run()
Even better
i have the running flag for terminating the blocking when the process has ended
as its not needed
uh, I am not sure if you synchronized (lock) is going to work
yeah
but the service is meant to be used by one thread
idk how to enforce that tho
also i spent more than a day on that task system just to use it for building my resource pack on multiple threads
I'll be working on a multi-threaded resolution of maven artifacts right about now, so perhaps I can make use of your attempts
nice
i could make the lock halt for a limited time
like a timeout
is that a good idea
It's pretty staggering on how deep the dependency tree of many artifacts go if you include test and provided dependencies
yeah
you should make a viewer of dependencies
that you can move around in
of the humongous tree
my artifact wont have any
actually
paper is huge
i bet
paper is quite small, junit will be huge
Ah right, actually paper will be nonexistent I assume
and everything used by bukkit and spigot
hey i still cannot seem to damage the player properly from an onexplode event.
EntittyExplodeEvent i mean
ok i finally found the actual damage
[13:51:51 INFO]: Last damage values: 41.0
[13:51:51 INFO]: Last Damage cause: org.bukkit.event.entity.EntityDamageByEntityEvent@691af3e2```
why is it 41, i literally cancelled it and set it to 1.5
the spaces
the spaces are air
u have way too many
u also have way too many string
Yeah, the spaces are the issue
first string first row
and the fact that he has 9 rows of ingredients
Ah, each string is a row... Then why does it compile in the first place?
pretty sure it takes a String...
"ABA","BCB", "ABA"
this would be your correct strings
thats would be kinda cool ngl
it takes 3 Strings, one for each row of the crafting table
fellas, problem fixed
lol beautiful
now we can finally craft 5 meter torches
lmfa
finnalyyy
Ive always wanted a longsword
i can finally craft a space shuttle now
wonderful
its beatiful i can look at it for 5 hours
How i can say an integer like: 1000000000000, if it says: Integer number too large
anyone?
use long instead of int
thank you, thank you. i was unaware of how great an artist i am
or biginteger idk
Integer.Max_Value or something? (not sure if thats the actual value)
use a long
also i have a question
integers only go up to ~2.7 billion
ok thx
yeah
Chest. Set the amount of rows
long
how can we get a recipe's namespaced key?
oh
cast it to Keyed
it will NOT work for MerchantRecipes though
only all other types
what am i gonna cast to tho
Keyed
i wanna use Bukkit.removeRecipe method
Keyed keyed = (Keyed) myRecipe;
Can anyone help me? I am trying to setup MySQL to my plugin but I am getting this error;
double allows numbers until infinity
Now, I know my plugin is not able to connect, it is timing out but idk the reason for it
it works the same
Of course it has some precision errors, but you can fully handle really large numbers with it
qhat avoht floats
wat
what about floats*
split the number into 2 longs lol
long goes up to 9.223.372.036.854.775.807, I guess that's enough in their case
floats can too
whats the benefit of using BigDecimal?
rounding ? idk
Float roundedNumber = new BigDecimal(number).setScale(2, RoundingMode.HALF_UP).floatValue(
looks like it does have some methods for rounding yea
It is more precise when dealing with anything that can be read by a general human
Floats/Doubles and such use base 2, BigDecimal deals with base 10 or at least so I assume
ah, interesting
Money
when u do arithmetic calculations, bigdecimal gives more precise results
same as biginteger
Arbitrary precision
More precise is debateable
Is there a timeout statement you can add
the city in seattle has a separate computer just for bill gates tax declaration lol
I think there is
yea the problem is Vault still uses doubles. so how could i use BigDecimal
or will it still work correctly when converting to double at the end of calculations
It will work okay-ish
There is a huge performance overhead when converting however and as long as you are not working with large numbers doubles are okay
Doubles are most likely fine for Minecraft since they are accurate up to 15 decimal places
well as long as calculations are not inaccurate by like thousands off its fine for me
given that a double is something like x * 2^y.
Then it will probably only take an effect if you are dealing with billions
what packets are sent when a client hits a player?
well when dealing with billions i doubt players will care for a thousand off
I have a monolithic listener, yea
Anyone?
Its probably defined somewhere in https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
yes
?
I made a class basically called "EnchantsListener"
https://i.stack.imgur.com/V7kvk.png @tall dragon might also interest you
hmm yea, thanks
god i still couldnt understand how to get a vanilla recipe's key
ay geol the system also works with multiple threads at the same time
with ParallelTask
Cast the Recipe object to Keyed
then use getKey()
that's it
Bukkit.recipeIterator() gives you an iterator over all registered recipes
you can also just use NamespacedKey.minecraft("some-crafting-recipe") to get the key you need
what crafting recipe do you want to remove?
enchanting table
Sorry your not allowed to work with me
okay one second
I will not allow it
lmao
You can do Bukkit.getRecipesFor(new ItemStack(Material.ENCHANTING_TABLE));
which packets inform the player of item details? ik there's WindowItems and PickupItem but what other ones?
sheesh
Anyone here worked with protocollib? Can BLOCK_CHANGE packets be cancelled?
Reason I'm asking this is because I've tried cancelling the BLOCK_CHANGE packet yet it still sends the block change to the player.
that returns a list of all recipes that result in an enchanting table
enchanting table has only one recipe, so should i make
Keyed keyed = (Keyed) list.get(0).getKey
.
Can someone help me with this?
yes, or just directly do this @coarse shadow :
NamespacedKey recipeKey = NamespacedKey.minecraft("enchanting_table");
NamespacedKey recipeKey = NamespacedKey.minecraft("enchanting_table");
Bukkit.removeRecipe(recipeKey);
yes
yes it is
you should however think about the recipe back in onDisable
I am not sure whether it will be gone forever otherwise
probably builtin recipes will reapper after a restart
does it really matter if i wont use it on my server
or i can just do addRecipe on onDisable method
yes
I have other plugins connected to it too
public void connect() throws SQLException {
connection = DriverManager.getConnection(
"jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE + "?useSSL=false",
USERNAME, PASSWORD);
}
I will test the database wait
does the ```java
ChatColor.getByChar("");
or how does it work
if i wanna use hex colors
instead of predefined macros
enums*
static ChatColor
getByChar(char code)
Gets the color represented by the specified color code
``` documentation aint that helpful here
Is there a way to avoid autospawn? I mean that when someone enters the server for the first time, they tp the default spawn but I don't want that to happen
you need to use net.md_5.bungee.api.ChatColor
if you want rgb
then you can do ChatColor.of(new Color(r, g, b))
im having a bit of confusion with how item metas are supposed to work, i want to differentiate tools from items and im doing that by checking if an item's meta is instanceof Damageable
but its returning true for regular items like blaze powder
isnt it the case that tools will have a damageable itemmeta and stuff like books get bookmeta etc.
ah teye alot
yea i came as far as to bungee
np
main.gdprLink = new TextComponent(ChatColor.of("#FFFF00") + main.gdprArgs.get("UrlMsg"));
```that far ive got alone đ
for test later its obv outsourced to a config file
nice
try repairable?
like they NEVER expose their methods to java methods directly
except for this one time
strangely, that also returns true
code?
what
main.gdprLink = new TextComponent(ChatColor.of(new Color(0, 0, 1)) + main.gdprArgs.get("UrlMsg"));
this is the hex color of #0000FF
0,0,1 is #00001 right
nah its 0, 0, 255
0,0,255 would be 0000FF
yeah
where can i post images hejre
get verified
u need to verify
then you can post them everywhere
use imgur or smth
this
because it is a link to the data protection agreement
to comply with EU law
hmm
doesnt TextComponent have a color property
but predefined chatcolors work fine
main.gdprLink.setColor(null);
apparently it does have such a member
works now
xD
and now i can also parse it from hex colors as well
Hello, i'm trying to get the enchantment(s) from an enchanted book, but it doesn't seem to store them like other items. Is there any way to do it?
that's because enchanted books use EnchantmentStorageMeta i believe
Ah thanks
anyway, back to my issue
if (t.getItemMeta() instanceof Damageable){
ItemUtils.damageItem(who, t, 1, EntityEffect.BREAK_EQUIPMENT_MAIN_HAND);
} else {
if (t.getAmount() <= 1){
who.getInventory().setItemInMainHand(null);
} else {
t.setAmount(t.getAmount() - 1);
}
}
this is meant to decrease an item's amount by 1 if it's a normal item, or damage it if it's a tool. the item (t) here is some blaze powder and for some reason t.getItemMeta() instanceof Damageable is returning true, isn't this only meant to be true for items that can, you know, be damaged?
repairable
i replied to u before
try that
didnt see sorry
its also not some funky custom item blaze powder either it was taken straight from the creative inventory
yeah im confused too lol to my experience this always worked fine
how are you getting t
its the item in the player's main hand
if there is one
i also checked t.getType() and it was saying blaze powder just fine
k
that makes actually no sense
so its nothing weird with java
is that a recent thing?
they just coded it badly
i could have sworn this wasnt the case in earlier versions
it seems like its the case everywhere
maybe you were using paper and it patched it out?
or something
i am on paper now
what the hell
gonna have to use a different method then i guess
might be a requirement with bukkit
maybe shit doesnt work properly if it doesnt work this way
if i do
for(int i = fetchStart(); i<fetchEnd(); i++){
//Code
}
does it call fetchEnd() once and caches it or does it run fetchEnd() every loop?
yes
i think it might optimize it out but im not sure
because there might be some other thread changing the results
the compiler doesnt know
try it? put like a little console output in fetchEnd() and see if its prints several times
i usually do
int l = ...;
for (int i = 0; i < l; i++) { }
yeah regardless thats the better usage
i think it wouldnt do it then
because the compiler may think "ah, this println is intended behaviour, we should keep calling"
but idk if it goes that deep
getActiveItem is not a spigot method
hey im summoning a fireball with player#launchProjectile(Fireball.class) and in my damage listener i cant seem to set the damage? It completely ignores my LivingEntity#damage() or LivingEntity#setLastDamage().
my code isnt wrong - i printed out all the values and they work fine, but when i set the damage it doesnt actually do anything
and then i checked the actual damage by Sysout(e.getEntity().getLastDamage()) and its completely different
Hey, if i add an enchantment with bypassrestrictions to false, will the enchantment apply even if it isn't compatible with the item in question? Or do I need to create a hashmap will compatibilities and check from there?
bypassrestrictions speaks for itself
so shouldnt it bypass item or vanilla restrictions if you enable that
and if not then it wont add?
Actually , it's called "Ignore Level Restrictions", sorry
declaration: package: org.bukkit.inventory, class: ItemStack
This method is unsafe and will ignore level restrictions or item type. Use at your own discretion.
the normal addEnchantments() throws:
IllegalArgumentException - if enchantment null, or enchantment is not applicable
also, any ideas anyone?
Oh thanks you :)
Hmm... maybe try creating a new fireball, at the player's location, and then set the damage from there, without using player#launchProjectile? I once made a plugin that shot 3 arrows at once, and I just created the extra arrows
why at the players location?
Because, otherwise it won't know where to spawn the fireball
Yeah, in my arrow plugin i just spawned it in front of the player's head
You can also setDamage in the damage events
its an EntityExplodeEvent
since i need to gather data for the explosion and not just one entity
could i just create another listener
Youâll need to damage them manually then
and do. the damage there
And probably with a 1 tick delay
scheduler?
or runnable
its just i cant damage the entity in the no-damage-ticks time
and i want to cancel that original damage and set my own
but since im not listening for that event im not sure how to
Yeah you gotta use the damage event to cancel damage
yeah then thats another problem because i need to gather all the data from one explosion
to send a message to the shooter which is currenlty "You damaged %count% entities for %totaldmg% damage"
is there a way to make acheivments per world
could i just create another listener that deals with the damage instead of the explosion
but then i cant set it individually for each entity bruh
Well, you could get an entityhitblock event or whatever its called, and when the projectile hits, destroy it, make an explosion effect, and damage them from there, damage which you can take and send to the player
I tried to do what you told me, but I am still running into an error. Caused by: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaBlockState cannot be cast to class org.bukkit.inventory.meta.BannerMeta (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaBlockState and org.bukkit.inventory.meta.BannerMeta are in unnamed module of loader 'app')
Here is the code. Am I missing something? https://paste.md-5.net/ezawurakeb.java
hmmm good idea ill give it a go
IIRC a shield doesn't have BannerMeta but a BlockStateMeta
then you can cast the BlockStateMeta.getBlockState() to Banner
and yeah that should be everything
Is there a recommended inventory library I should use for menus
There are quite a few. I personally use phoenix616's InventoryGUI library, but inventory framework is more popular
(Noobie question) How does the (e.g) Worldguard API interact with the worldguard plugin? how does it "hook" into it and allow me to use the worldguard functionality? In case of that it would take to long to explain, -> what do I have to google to find that out?
No idea how they do that but I'd assume either via callbacks or events
i personally use triumphgui (aka mfgui) and i can recommend it
Hey im still trying to do my explosion fireball.
I want the fireball to explode, and the surrounding entities to be counted into a map and sent to the shooter as a message "You hit 5 entities for 22.4 damage" and for the entities hit, "you were hit for 6.8 by <player>"
could i use
Map<UUID, Double> totalDamageInner = new HashMap<>();```
Then in my listener:
```totalDamageInner.put(shooter.getUniqueId(), totalDamage.getOrDefault(shooter.getUniqueId(), 0F) + damage);
totalDamage.put(e.getDamager(), totalDamageInner)```
do any of them allow runnables to be done on an item click
Myes
I think most do
mmm I like that
https://docs.phoenix616.dev/inventorygui/de/themoep/inventorygui/GuiElement.html#setAction(de.themoep.inventorygui.GuiElement.Action) inventoryGUI for example doesn't use pure runnables, but it would be easy enough to convert to runnables
Thanks! That worked.
dude
ima have to host an http server on the mc server
to host the resource pack download
bruh
and then somehow get the address the player refers to for the server
and use that as the url
in the Player#setResourcePack(...) method
What would be the best practise for saving data to database? Saving it async (as realtime as possible), so for every "action" or save all the "actions" in a hashmap or any data structure and iterate with for loop and batches after a certain amount of time (also perform async). Also the data should be able to get accessed the whole time so that would let me think its better to use the hashmap way instead of requesting connections for every request to get the data.
Personally I save data real time asynchronously but I'm planning to implement a cache soon here
With a hashmap I will warn you about memory usage if you don't cap the size your saving to memory
How many requests per second?
or transactions i mean
Plugin hasn't passed production yet it'd be a lower amount though since I'm developing for a friend probably 10ish transactions per second would be what would be happening on his server
Which data structure you recommend to use for caching?
Haven't looked into caching yet. So I'm not quite sure
I'm a junior dev so I'm still learning a lot I've got slightly less than a year of experience.
me too
There are plenty of good apis out there. Looks like apache commons has caching which is a library I already depend on so I would use that but it all is what works best for you
how would i push changes to my repo if i made a new project with the same code but in maven instead of gradle
should be the same only the title you may wanna change if they're different plugins
yeah but like how do i connect the new project to the existing repo
Anyone know how to edit the blocks in a Structure Palette?
Like the ones from: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/structure/Palette.html#getBlocks()
declaration: package: org.bukkit.structure, interface: Palette
Changing the type isn't working
dude, I'll take a look at your problem, but no need to spam and hide other people's messages acting like you're the only person who matters
sorry .
It's okay! Your approach should work, but you should change totalDamageInner.put(shooter.getUniqueId(), totalDamage.getOrDefault(shooter.getUniqueId(), 0F) + damage); to totalDamageInner.put(shooter.getUniqueId(), totalDamageInner.getOrDefault(shooter.getUniqueId(), 0F) + damage);, because I assume you want to increment totaleDamageInner for shooter.getUniqueId() by the damage each time
is there break event for bungeecord
Hey may i ask you a question
Yes
Use a ConcurrentHashMap tho
As youâre gonna use it over multiple threads
İm seeing the cod messages white on mobile. How can i fix it
And then the general idea is to save quite often, so for most actions and bulk operations, read when needed (most likely only on join assuming you donât synchronize data over an entire network in which things become significantly more intricate)
Iâd advice looking at for instance LuckPerms
Itâs a great start
Also if you want a legit good and maintained caching library (as opposed to just ConcurrentHashMap) then Caffeine is your best bet
EDIT of course maps take some memory, but itâs not going to be the slightest issue unless youâre scaling something to the moon
@ivory sleet