#development
1 messages Β· Page 98 of 1
No u
i know a certain paradigm that multi-threads really easily!
assert hUH
oh what would that be? Totally not fp
const?
What was it used for?
const does nothing
goto and const were reserved but never used
reserved keywords
native transient
XD
What the hell
But it might have been used for constants
const is in Java?
you can call C++/C functions
native is for natively implemented functions
barely
with native
transient is useful
transient is when u want to exclude serializability
assert is with a jvm flag something if you want to assert a boolean expression I believe
which if false throws AssertionError
useless
Yeah lol
Yeauh
final superior
mutable final 
val superior
Ubemubbe
imagine having a keyword for variables
Imagine not
People either use assert or Objects.requireNonNull() when they don't know how to null check
so assert is useless
No one uses assert
I've seen it in plugins
I have as well
Its suggested by IntelliJ
That's why I am asking
If you want to assert stuff use something like Junit maybe
π€¨
It has a utility class for that shit
People use it because they think it is a null check

because it doesn't do jackshit
Does anyone have an example on a websocket server in a spigot plugin? I'm trying to have a discord bot communicate to my server plugin.
mainly assert because thats an intellij suggestion π€’ https://i.imgur.com/fOHXq6v.png
That's what I said lol
I personally have used it for debugging and testing but never actually released anything with it
its so gross that its at top
ik D:
like it should have a suggestion from junit
Its on top because its the most used
if the dep is there
Dkim uses assert
lol
lol
WAT
PROOF
oh maybe
No definitely not
π₯²
Its because Dkim uses assert
also true
all because of me
That's the only explanation
π
Yeah
π
i'm sorry
Unbelievable
will you forgive me π₯Ί
lol
?learn-java
Online Courses:
Online courses are also great for learning java. Some websites that offer them are:
- Coursera - Free unless you want a certificate
- PluralSight - Great courses from what I've seen. Mostly Paid
- Udemy - Never used them myself but they seem to all or at least most be paid.
My first ever course was one from Coursera. - I can say it was pretty good at introducing me to the programming world as a whole not just java.
Oracle Docs:
Oracle docs can help a lot at learning and understanding java:
- Start with this,
- Breeze through this (skipping stuff that doesn't seem relevant like bitwise operators),
- Hit this.
They're the first three from this larger thing which you should definitely go through overall. But those three should be enough for slightly better understanding of what is happening here without feeling like a huge time sink.
That one is a small part of this larger site wherein "Essential Java Classes" and "Collections" also have good useful stuff
Other services:
Some other cool services that will help you learn java are:
As you can see there are plenty of good ways to learn as long as you're willing to invest the time. Have fun learning!
@dusky harness ^
βΉοΈ
LMAO
okay but
REMEMBER???
You have nothing you can say to defend yourself
dude I forgot we used to spawn that to dkim almost every day xD
learnyouahaskell
i don't
OOH
lol
LOL
I was so confused by generics at first
offends
π
Wow
Dkim has come a long way past months tbh
Something an assert user would do
:O
Cap
no cap
Yeah no cap
He just turned into stage 1 beginner
It's true
dkim haters vs dkim appreciators
but the assertions tho ποΈ
Also why is :this: a carrot lmao
oooooooooooooooooooooooooooooooooo
ummmmmmmmmmmmm
carrot = caret = this
π§’
billed cap
billed cap billed cap

tea
/tts
i have a bigger reverse card
Iβm getting too much xp from this, I canβt change my name color, bye everyone, Dkim stop using assert.
size matters πΌ

it does tho
aw
buried 
Ender we are trying to have a very serious conversation here
my bad
lmao
ooh i did that before
sorta
soz
although i had it where i had proxy as discord bot and servers that connected to it
and i didn't use a websocket either
XD
so just not that at all them
I trying to make a team selector for discord. the bot is always running pinging the server because the server can be offline or online
Not using a database rn and wanted to look into sockets but I'll look into radio scanner 
i mean
radio scanner uses sockets
harder uwu
π
π

π©
π₯
:creeper:
\π
A general java question
If I had this basic spigot GUI class: https://www.spigotmc.org/wiki/creating-a-gui-inventory/
How would I call it in another class without making it static?
final ExampleGui exampleGui = new ExampleGui()
Thank you
Ik how to make a package cuz I copied/pasted decompiled src into a new project in order to update them. Thatβs how I learn. Tried watching yt vids. Tried reading. They both failed. I learned by starting with existing code, asking questions from those who know, and then doing
decompiled π¬
Can I not use Player#attack?
I either need to have a player attack an entity, or get the damage that would normally be applied,
and use that with LivingEnttiy#damage
What issues are you having with using it?
It doesn't work
What's the difference between
ADD_NUMBER
ADD_SCALAR
With AttributeModifier?
Nvm
I just need to find a way to get how much damage a player would deal to an entity if it had attacked an entity normally
I can get the damage with attributes, it doesn't factor in swing cooldown though
How long did you attempt to learn from reading / Youtube videos? And did you try applying what you learned as you learned it?
just a question, how would this work for a discord bot lol or rather in javascript
this was the end product btw π
I have a PlayerChat event and I want to turn their string into a player to check if that player has been on the server before and has X playtime
How would I check if the player has joined the server before?
d;spigot player#hasplayerbefore
boolean hasPlayedBefore()```
Checks if this player has played on this server before.
True if the player has played before, otherwise false
ok thanks
Whats the easiest way to get a players next chat input without an API?
Put the player on a set or something and listen to AsyncPlayerChatEvent, and If the player is in the set, cancel the event and get the input message.
conversation api from bukkit
d;spigot conversation
public class Conversation
extends Object```
Conversation has 1 extensions, 15 methods, and 7 fields.
The Conversation class is responsible for tracking the current state of a conversation, displaying prompts to the user, and dispatching the user's response to the appropriate place. Conversation objects are not typically instantiated directly. Instead a ConversationFactory is used to construct identical conversations on demand.
Conversation flow consists of a directed graph of Prompt objects. Each time a prompt gets input from the user, it must return the next prompt in the graph. Since each Prompt chooses the next Prompt, complex conversation trees can be implemented where the nature of the player's response directs the flow of the conversation.
Each conversation has a ConversationPrefix that prepends all output from the conversation to the...
This description has been shortened as it was too long.
d;spigot prompt
public interface Prompt
extends Cloneable```
Prompt has 1 super interfaces, 1 extensions, 8 implementing classes, 3 methods, and 1 fields.
A Prompt is the main constituent of a Conversation. Each prompt displays text to the user and optionally waits for a user's response. Prompts are chained together into a directed graph that represents the conversation flow. To halt a conversation, END_OF_CONVERSATION is returned in liu of another Prompt object.
ok thanks ill take a gander
oh, didnt know that exist
it is pretty nice, could be better but yea
What in the actual heck is a "Conversation" lmao
damn thats sick
is there a way to check plugin message channels that i didnt register yet like so i can list every message channel you can listen to
oh oops, i thought u were making it in java π
how come ur doing it in js? i thought u had more experience in java π
Is it possible to spawn a fake player but consistently spawn a fake player with Steve character model?
How do you get the output of an event function in separate function?
This is a bad example but yea:```java
public Player getChatInput(AsyncPlayerChatEvent event) {
return Player
}
public getChatter() {
// Get Player from getChatInput()
}```
@EventHandler
public void getChatInput(AsyncPlayerChatEvent event) {
doSomething(event.getPlayer());
}
public void doSomething(Player player) {
player.sendMessage("chatted");
}
like this?
yea ty
sorry for asking so many questions, but why doesn't this work?
public void PlayerItemConsumeEvent(Player player, ItemStack item) {
ItemStack glowberry = new ItemStack(Material.GLOW_BERRIES);
if (item == glowberry) {
if (item.getEnchantments().containsKey(Enchantment.FIRE_ASPECT)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 100,1));
}
}
}
Have you add @EventHandler
And register it
That's not event
You're comparing the itemstack in the wrong way.
- an event can only have 1 parameter - and it has to be the event
- the if statement will never succeed, you have to check the material using
getType() == Material.GLOW_BERRIES
@EventHandler
public void onEat(PlayerItemConsumeEvent e) {
ItemStack item = e.getItem();
Player player = e.getPlayer();
if (item.getType() == Material.GLOW_BERRIES) {
if (item.getEnchantments().containsKey(Enchantment.FIRE_ASPECT)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 100,1));
}
}
}
}```
so I changed it to this
public static onEat onEat;
oh wait
i put those tow lines in the main
you need to implement Listener
no
theyre in seperate places
you don't need the second line
but you have to tell java that your class is a listener by doing this: java public class onEat implements Listener { // code } and to register: ```java
this.getServer().getPluginManager().registerEvents(new onEat(), this);
ok
that's paper api D:
guess that means I must use java 16? https://paste.helpch.at/hemusanafe.http
Does anyone have any resources about how to go about optimising you code to the fullest i.e using asynchronous code etc, I want to learn more about it, maybe a video or something?
for the spigot framework
use spark: https://www.spigotmc.org/resources/spark.57242/
/spark profiler to start profiling
/spark profiler --stop to stop profiling
once you click the link you'll see this: https://i.imgur.com/78ahR2K.png, click that so that it says sources so that it'll categorize by plugin
for async stuff, that depends on what you're doing, so I'd need more information
but note that you should be very careful when using the bukkit api async - and you shouldn't modify the world (including entities) async
sort of
Thank you, I didn't know this, that's why I'm asking for sources for optimisation techniques.
async is very helpful if done correctly
so ig
having a good structure + async = good
but it depends on what you're doing that needs to be ran async
there's no general approach, best is to use appropriate data structures and efficient algorithms, avoiding repetitive code, reuse instances etc
whats ur plugin name?
VerityMC
yea ur plugin seems optimized enough to not use async
it's only taking up 0.27% of the main thread
also async != async, there's a difference between parallelizing an algorithm and running a task separately
public void simulateBlockBreak(BlockBreakEvent e, UUID uuid) {
Bukkit.getScheduler().runTaskAsynchronously(pickaxeModule.plugin, () -> {
Pickaxe pickaxe = getUserPickaxe(uuid);
if (pickaxe == null) return;
pickaxeModule.getEnchantmentList().stream()
.filter(enchantment -> pickaxe.getEnchantments().get(enchantment) > 0)
.forEach(enchantment -> enchantment.blockBreakHandler(e));
pickaxe.addBlocksMined(1);
pickaxe.addExperience(3);
});
}
This is currently things I use Asynchronous tasks for, which I don't even think is needed?
then, it's also important to know which methods in spigot are costly and which aren't. That's probably the most important factor for most plugins
|| btw spigot isn't a framework i dont think ||
Alright, thanks for that π
well depending on what you're doing there, it's likely rather worse in performance and might be even incorrect
Well, this method will be run each time any player online breaks a block, so though it might be intensive on the main thread?
anyways im probably going to be afk, good luck π
Thanks for the help 
that does not automatically mean it's safe to not run it on the main thread. If you actually have performance issues with that method, you should e.g. avoid using streams there
most people also overestimate the cost of a few simple methods and underestimate the issues multithreading brings
Alright, so you're saying leave the asynchronous task out for now until any possible performance issues arise in the future then maybe revisit again if need be?
yes, especially consider looking into improving the time the method takes before running it async
Does this include spawning blocks using the FAWE API? It shouldn't be done asynchronously?
i've never used the FAWE api before
Well I've just had a problem, I've spawned a schematic asynchronously, one of them spawned fine, the other didn't spawn at all?
But if I don't spawn them asynchronously the server times out..
π€
showing code would help there
public static void paste(File file, Location location) {
try {
final BlockVector3 vector = BlockVector3.at(location.toVector().getX(), location.toVector().getY(), location.toVector().getZ());
Clipboard schematic = FaweAPI.load(file);
EditSession editSession = new EditSessionBuilder(FaweAPI.getWorld(location.getWorld().getName())).fastmode(true).build();
FaweAPI.createQueue(editSession.getWorld(), true).enableQueue();
Operation operation = new ClipboardHolder(schematic)
.createPaste(editSession)
.ignoreAirBlocks(true)
.to(vector).build();
try {
Operations.complete(operation);
editSession.flushQueue();
} catch (WorldEditException e) {
e.printStackTrace();
}
} catch (MaxChangedBlocksException | IOException e) {
e.printStackTrace();
}
}
Ended up doing this, Idk if it's an anomaly that the schematic doesn't spawn or something else, but it does take up a lot of performance when spawning one
At what percentage should I be concerned of performance in regards to thread percentage?
https://spark.lucko.me/Bi7vyKJ1XD
are you calling this code asynchonously?
Not anymore
you should do so in that case
But I was running into problems where my schematic wouldn't paste in some cases?
hard to tell what was wrong without seeing that code
FaweAPI.load(file) try caching this by making a Map<String, Clipboard>
wait
u might be able to do Map<File, Clipboard>
im not sure how the #equals in File works
uhh
Why would I need to cache it? I don't think it's much performance to load it
https://i.imgur.com/Id0bsot.png 0.94% of the thread
why my embeds never working anymore π
do you know what files are being loaded?
like are you hardcoding the files?
It's a singular file
it get's it from my plugin folder
Is 0.94% considered a large amount when it comes to performance, sorry I'm not really knowledgable on this sort of thing
just 1 file?
I have 2 accounts, both spawning the schematic running a command, only one spawns...
asynchronously ...
yea i think u should run it sync
and let FAWE handle async stuff
maybe you can cache the schematic in PMineManager
so that every time you're pasting the schematic, it's not reading the file
Good idea,
when running my task async it only takes 0.12% of the main thread 
like the entire plugin
so something like java private final VerityMCPlugin plugin; // assuming you have some sort of plugin field private final Schematic schematic = FaweAPI.load(/* file here */); you might have to do java public PMineManager(/* constructer params */) { // code Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> schematic = FaweAPI.load(/* file here */); )}; }though if you're making the PMineManager instance before the server is fully starting and if FaweAPI.load requires the server being up and running
then paste(schematic, location) instead of paste(file, location)
if you don't run it async, it will block the main thread (and when unlucky, you'll run in a deadlock)
so the whole paste method should be run async in best case
schematics aren't always loading
so i'd assume that the fawe api isn't meant to be ran async π€·
Β―_(γ)_/Β―
We suggest that FAWE operations are completed asynchronously.
hmm
interesting
it is meant to be ran async, everything else might cause issues
o also apparently EditSession has to be closed
So what do I do then?
so you can change this to ```java
public static void paste(Clipboard schematic, Location location) {
EditSession editSession = null;
try {
final BlockVector3 vector = BlockVector3.at(location.toVector().getX(), location.toVector().getY(), location.toVector().getZ());
editSession = new EditSessionBuilder(FaweAPI.getWorld(location.getWorld().getName())).fastmode(true).build();
FaweAPI.createQueue(editSession.getWorld(), true).enableQueue();
Operation operation = new ClipboardHolder(schematic)
.createPaste(editSession)
.ignoreAirBlocks(true)
.to(vector).build();
try {
Operations.complete(operation);
editSession.flushQueue();
} catch (WorldEditException e) {
e.printStackTrace();
}
} catch (MaxChangedBlocksException | IOException e) {
e.printStackTrace();
} finally {
editSession.close();
}
}
or try with resources
flushQueue closes it?
oh
welp
ohh
i didn't see that
nvm then xD
although putting it in a finally block is good practice π€·
since unless the server stops, the code will always run
Communicate to the EditSession that all block changes are complete, and that it should apply them to the world.
Deprecated
Replace with close() for proper cleanup behavior.
try with resources would be the good practice
true - as vector doesn't need to be in the try
If FAWE is supposed to be done asynchronously then why isn't my schematics spawning?
I run the command
/mine create on 2 separate accounts one after the other, one of the schematics paste but the other doesn't, this only happens when I put it inside a async scheduler ?
Now im getting things where the schematic is only 1/3 pasting
sync or async?
async
weird π€
i'd recommend just doing it sync for now since it's probably only going to take like 2% of the thread sync - and maybe you can ask in IntellectualSites discord (who created FAWE) about the issue
Yeah it's literally just async that causes the problems, here is it now without async and everything works perfectly, when 2 people load something at the same time there is like 0 noticable performance hits, still got to change the FAWE.load thing
well you still did not show your code with the async way
It's the same way just with
Bukkit.getScheduler().runTaskAsynchronously()
I'd like to see the actual code
Are you using FAWE? If so, wouldn't it handle the async itself?
Umm, well I'm not entirely sure??
thats what i thought - but the wiki said
We suggest that FAWE operations are completed asynchronously.
I recommended that he just keep it sync since theres only 1 schematic and it is only taking up 2% of the server thread without IO cache
That doesn't necessarily mean in an async task
and if FAWE needs to synchronize on the main thread for some reason it will just crash the server that way
1 schematic could mean any number of blocks
that's exactly what it's supposed to mean
well since he only has 1 im assuming that it's probably in the same range of blocks
There is a set schematic that will not be changed
@lyric gyro π¦
hi~ :3
Emily hates FAWE xD
every sane person does
xD
lol
SirYwell you're apart of the intellectual sites organisation, do you work on FAWE?
yes
oh lmao xD
So what do you suggest I do?
well it's supposed to work when pasting async. If it doesn't, there's something wrong. That can have several reasons and debugging it over a text channel is more than suboptimal
and I didn't touch fawe in a while now tbh
make sure you're up to date
Yeah I'm on the latest version
https://imgur.com/a/H9fQaWj This is what it's supposed to look like, when I run the paste inside of a async scheduler it either doesn't paste at all or only a section of it pastes
*the object in the centre isn't apart of the schematic
can you check if it's just a visualization issue or an actual pasting issue?
I will check now and get video evidience
No visual glitch.. do you mind if I send you the footage in DM?
ItemMeta meta = lucky.getItemMeta();
lucky.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 5);
I'm trying to add enchantments with this code
and it doesn't work
it says "Cannot resolve symbol 'addenchantment'"
d;spigot ItemStack#addEnchantment
public void addEnchantment(@NotNull Enchantment ench, int level)
throws IllegalArgumentException```
Adds the specified Enchantment to this item stack.
If this item stack already contained the given enchantment (at any level), it will be replaced.
IllegalArgumentException - if enchantment null, or enchantment is not applicable
ench - Enchantment to add
level - Level of the enchantment
uhm
It doesn't work with unsafe either
'addenchantment' If that's the exact same message, you are not using a capital letter for e
it is capital here
what version?
1.17
1.17 or 1.17.1
.1
does it say the error in your ide or in the server?
I want to learn js
ah
no, I believe you :p but I don't really have the time to debug it further, so I'd suggest you to ask for help in #347745984446726144. Maybe someone else has an idea what's going on
ide
No problem, Iβll probably just stick it sync for now, thank you for your time
what are your imports?
spigot 1.17.1 API
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
etc
yk what just upload the entire class to pastebin or smth
!paste
Why is your code outside luckyCookie()?
it isnt
it is
public void luckyCookie(PlayerItemConsumeEvent e) {
...
}
ItemStack lucky = new ItemStack(Material.COOKIE, 1);
lucky.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
the code your trying to define is outside of the scope of luckyCookie()
that isnt supposed to be in the event
well what is it supposed to do then?
I'm going to make a recipe with it
you cant kept it out of a method without defining its access modifier
i added a regular command but i am getting this error when i reload the plugin https://paste.helpch.at/umiloxoriv.bash
command executor code: https://paste.helpch.at/uvukivizez.java
java 15+ would tell you what exactly is null
you either didn't add the admin command to your plugin.yml or the plugin instance is null
anyone know how a bukkit scheduler actually works? like, is it possible to find the source for an implementation of it, or if someone is able to explain it in brief terms?
specifically, the way that it executes tasks on a scheduled basis. looking to make a similar version of it
The tasks are in a queue, and during the game loop, they are executed.
game loop = each tick
each tick = game loop
ik what a tick is lol
but how do i replicate a "game loop" outside of MC
i.e how do i make something happen after x milliseconds
Yeah
private final executors = Executors.newCachedThreadPool(); // sometimes you should use fixed thread pool to avoid having a lot of threads
executors.submit(() -> {
Thread.sleep(1000L);
System.out.println("1 second passed");
});
or ```java
Thread.sleep(1000L);
System.out.println("1 second passed");
oh
What if they schedule 2 tasks, second one is shorter?
But the thread is sleeping
so it'll just create a new thread
i was mostly just looking for the timing mechanism
which seems to be Thread.sleep
What if all the threads are used?
which is why you probably shouldn't use cached thread pool
then ur pc go die
π
lol
can't i just like make a new class that extends a thread or sum
sur
Yeah
Just have a queue and a submitTask method
It also depends if you want the task async
every 10 milliseconds it checks if the tasks are scheduled to occur
or smthing like that
Sure
it's for a discord bot so i don't think async matters too much compared to bukkit
It depends what youβre doing
yeah
hows that coming along 
Ideally you would have a single scheduled thread pool executor which execute its tasks by delegating them to a cached thread pool (which would probably be best for general use to achieve truly asynchronous and concurrent, scheduled task coordination asynchronously) however if you for some reason know what tasks are running in the thread pool you might wanna switch it out to something else like javas fixed size thread pool or javas work stealing pool. This is of course with the assumption that you know something called the βblocking coefficientβ which will determine the amount of threads you might need for the thread pool.
a couple more minutes π
β€οΈ
Bukkit has to queue the async tasks with the general game loop which if you have the ability to can break free from by using as I said a scheduled executor service implementation.
And this is precisely what something like a CompletableFuture might do if the common pool parallelism is like 1 or smtng iirc
It creates a new thread for every task :0
that doesn't sound like a good idea, is it
depends
I mean you achieve better concurrency
but itβs probably more cpu consuming
done π€
The biggest reason I can see why you want to avoid Thread::sleep would be, letβs say you do it in a Runnable instance which is passed to the executor, then the thread which runs the runnable will be "seen" as used but in reality itβs (the thread) just waiting. If itβs a cached thread pool, then your cached thread poolβs thread amount will grow unnecessarily.
can anyone here help me with my discord bot or no, only plugin related stuff?
@cerulean birch
https://paste.helpch.at/enanopopem.Scheduler.java
https://paste.helpch.at/efowohegug.EntryImpl.java <- not needed on java 9+
the delay parameter in Scheduler is how often it should check if the tasks should be ran
so if you put the delay as 1000L, it'll only run tasks every second
note that it won't run at exactly the milliseconds defined in delay, but it'll come pretty close
example usage: ```java
private final Scheduler scheduler = new Scheduler(50L); // 20 times per second
public void something() {
scheduler.runTask(1000L, () -> System.out.println("1 second later!"));
}
Sexy
Discord also
lol
how do I delete a single god damn message 
Message.delete?
what language/library?
discordjs
oh
Oh
π₯²
Get the message and just delete it?
Weβre Java bois here
yep
you see that's what I thought
.
itβs not different from how it would be done in Java like something similar to JDA or Javacord
Idk how it works in djs but in jda you need to queue actions
They donβt have queues the same way JDA does
Oh
iirc itβs just an async function
im just having trouble with basic stuff like storing objects and accessing objects but thanks anyways off to the djs server 
π©
D:
Well thatβs probably good enough
But like that isnβt going to be used as a game loop?
Anyways dkim only nitpick would be to use nanoTime instead of currentTimeMillis
But probably doesnβt matter
And ofc ScheduledExecutorService π
currentTimeMillis is more accurate iirc
edit: wait a minute
yep π
btw whats the diff between using singleThreadedExecutor vs new thread?
oh wait
the executor gives u an Executor
One can run multiple tasks
but in this case it doesn't matter since im only submitting once, right?
One can only run one task
Β―_(γ)_/Β―
yea
Thatβs not the point
nanoTime is best when you want to compare
how come? π
Because of close calls
now I doubt this is the case here
anyways yeah nanoTime is afaik not guaranteed to be consistent across different jvm instances
hmm
ah
and currentTimeMillis is clocked time if they havenβt changed it
Oh yeah
Stackoverflow 
Btw do you play skyblock on hypixel?
nope
Aw rip
Anyways multithreading is quite annoying imo due to how difficult it is to test sometimes
luckily i remembered that I had to add a Thread.sleep to prevent the program from ending early π

Why Map.Entry and not a Pair?
Pair?
Or something like that
Enterprise Verbosityβ’οΈ
o
idk Map.Entry already existed
and plus
theres Map.entry() or something like that on java 9+
so less code changing if they're on 9+ :)
Shouldnβt you only use it for Maps though?
Β―_(γ)_/Β―
You could make like a Task class with a time and runnable
true
Yuh itβs supposed to be used for Map related shit but Iβve seen it in god knows where lol
Lol
Dkim19375Coreβ’οΈ used to have an Entry impl lol

:)
what was the point of this method? idk π₯²
xD
π€ͺ
DkimBukkitCore π
π π€
Jesus
Looks like one of those functional java libs with something like QuadrillionOptionalFunction
π₯²
What the utterly fuck is this lmao
iOS destroyed that emote
Holy moly cheese
Thatβs absurdly awful lol
That's ridiculous
printToConsole
π€£
getServer().getConsoleSender().sendMessage("[" + getDescription().getName() + "] " + msg);
ah yes
"Core"
Ah
still... abstract π€
I just delegate to another class
Because of the fucking rigidity youβd get if you involve your logic with the inherited logic of JavaPlugin
Yeah
I usually have something like a bootstrap class
ooh wanna see something cool
Okay lol
π€
lol
reflection π₯΄
And that looks bad
π€£
Triple
but what that function does
You gotta stop with this now, I get a stroke everytime I see that one fr lol
No
sorry forgot
xD
π©

Lol
Cya dkim
best way to get a User in JDA? assuming u have the long id and the bot is only in one server?
I assume
return DiscordBot.getBot().getGuild().getJDA().getUserById(id);
(Guild#getJDA#getUserById) isnt the best
public static String getResult(Player player){
String result;
result = Main.data.getConfig().getString("Players." + player.getUniqueId().toString() + ".currentResult");
return result;
}```
Why does the above return null?
```yml
players:
6b7b95b0-85b5-30cf-b997-271790f60040:
currentResult: Kangaroozy```
That can all be one statement btw
Also config matches case sensitive
I wanna use it alot and wanna make it more organized, I'm using it in this
public void openInventory(final HumanEntity ent) {
if(DataUtil.hasResult((Player) ent) == true)
ent.sendMessage(getResult((Player)ent));
inv.setItem(13, ResultPlayer);
if(DataUtil.hasResult((Player) ent) == false)
inv.setItem(13, NonFound);
ent.openInventory(inv);
}
ent.sendMessage(getResult((Player)ent));
returns null
This
You have Player and player in the config
ah i understand thank you
I call the function when a player opens a certain GUI, I'm getting null for
voteMap.get(0)
What have I done wrong?
Why am I getting this?
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
even though I have log4j added in dependenciess
repositories {
mavenCentral()
maven {
name = "m2-dv8tion"
url = "https://m2.dv8tion.net/releases"
}
}
dependencies {
implementation("net.dv8tion:JDA:4.3.0_340")
implementation("org.apache.logging.log4j:log4j-api:2.14.1")
implementation("org.apache.logging.log4j:log4j-core:2.14.1")
}
you need to add slf4j i believe
idk but it's generally an error you'll very rarely need to worry about in discord bots iirc
yeah but it's annoying
you should name classes based on what they do
and they should only do a single thing
I mean like for example, i have a class that triggers the playerjoin event in minecraft?
Its fine to name it ''onJoin'' right?
you will literally die if you do that
there's 2 issues with naming your class that
first it goes against java's class naming conventions, classes need to be named using pascal case
Ah, thats why i ask it here
the second issue is that it doesn't really describe what the class does
I mean sure, it's technically true
you are listening to onjoin
the class name will tell you that
but it doesn't tell you anything about why it's listening to join, what it's really doing
how would i fix that when multiple of my plugins start that the messages go on one line?
And the first letter needs to be uppercase?
why are you listening to join?
Oh for example, i wanna send the player a message when joining.
how are you sending the message?
system.out.print
You can use Bukkit.getLogger to right?
what is the diffrence?
I'd recommend using the logger assigned to your plugin specifically, accessible via JavaPlugin#getLogger
I just use System.out.println().
@formal crane println will end the message with a new line, print doesn't
then name the class based on this functionality
But @wheat carbon what do you recommend then naming a Event class?
but whats the diffrence between printing it and logging it
Ah.
logging shows the [CoolPlugin] prefix (for the plugin logger) and also supports different logging levels (SEVERE, INFO, WARNING)
is there a documentation on how to use the logging or is it just as simple as printing
It's fairly simple
you'll need to get an instance of the logger, which you can do via JavaPlugin#getLogger
plugin.getLogger().log("text", Level.INFO);
or ```java
plugin.getLogger().info("text");
True right?
you need to follow pascal case for class names
(I'm not specifically answering your question because the implication is that you'll go and google pascal case and learn about it properly)
Oke thank you
is this structure correct?
yeah
thats how I do mine
my onPlayerDeath event doesnt save inventory on 1.7 down to 1.5
Permissions.KEEP_INV.get()
Consider using string constants instead of enums here
the save inventory works on all versions above 1.7. I will take in mind using string contants.
Do you get any exceptions thrown on below versions?
I dont think so
I also dont think compatibility below 1.8 is even worth it, theres barely a few idiots using such outdated version now
we run a 1.5 modpack server
and it goes all the way up to 1.16
Ah, anyway, try not silencing the exceptions
Instead of try catch clauses to handle version differences, you different implementations of a class depending on version
generating an exception is quite costly
The stacktrace
yeah, we are using Reflection for different versions, and I dont know if player.setKeepInventory() changed between versions
Use https://paste.helpch.at/ for errors, logs and configs. So we don't spam the discord.
there is an exception
That seems incomplete, try to get the complete stacktrace
maybe this? https://paste.helpch.at/xecajebetu.cs
ah yes
its just an NPE
Show us this function com.apocgaming.worldcontrol.object.VInv.flatten
wait a second
that was a outdated build
here is the latest exception
;ok
so
PlayerDeathEvent is fixed
but
PlayerRespawn isnt
it appears setting health doesnt work
π₯² minecraft 1.5
Old setHealth seems to have an int argument
You're depending on a newer version of spigot
The version you're depending on has a double signature
Hence it resolves to that
Use an interface and provide a separate implementation from another module that depends on 1.5
Or alternatively, you can use reflection like you mentioned earlier
I'd suggest looking into MethodHandles as well
alright
but
it is asking for an int right?
I do give it a int, hmm
alright, I will try and solve this with what you said above
No
Since the resolved method at compile-time has a double, its implicitly converted to a double
alright
Any paper plugin developers that can help me out? dm me please
Ask your question here, doubt anyone will dm
makes sense, i saw the service request so i put it there
idk how this works lol im new to the whole server thing
Oh gotcha, yeah use the services, this channel is for support for making plugins
seems pretty simple but idk how i'd do it without super messy code:
I have a list of numbers
and i need to get the highest available number
so for example java final int max = Integer.MAX_VALUE; List<Integer> list = /* [max - 1, max - 2] */ would result in max
but java final int max = Integer.MAX_VALUE; List<Integer> list = /* [max, max - 1, max - 2] */ would result in max - 3 and java final int max = Integer.MAX_VALUE; List<Integer> list = /* [max, max - 2] */ would result in max - 1
these uppercase variables are painful
look now π
You mean the highest int in the list?
highest available slot in the list
but wouldn't that just give the highest number in the list?
Based on the comparator you give it
I want have a delay of 5 min between actions, how can I do this without pausing everything else?
Schedule a task with bukkit scheduler?
I was doing that, but it wouldnt run
I was doing a delayed task
and it never ran
a bunch of people tried to help, none of us could figure it out
can anyone help me with curse.jar ?
you'll have to explain what that is
nope. haven't played or done anything modded in a long long time
alright this will be quite the ride
basically my file is not starting properly if anyone can send me a forge server.jar file and ill test it if it works thanks if it doesn't its a problem with my host
pog i got it to work ```kt
fun getHighestID(): Int {
val list = listOf(2, 5, 1, 9, 10).sortedDescending().toMutableList()
var id = 10
if (list.isEmpty()) {
return id
}
while (true) {
val highest = list.firstOrNull() ?: return id
if (id > highest) {
return id
}
id = highest - 1
list.removeFirst()
}
}
why is that a while loop
lol
idk how else to do it
wait
i could probably loop through the list and do somehting
idk
LOL
I still don't know what it is supposed to do, it returns 8, how is that the highest id?
the highest available one
so if the list has 10 9 7
it would return 8
fun getHighestID(): Int {
val list = listOf(2, 5, 1, 9, 10).sortedDescending()
var id = 10
if (list.isEmpty()) {
return id
}
for (highest in list) {
if (id > highest) {
return id
}
id = highest - 1
}
return id
}
```i think this works too
without a while loop lol
Highest available slow from what? Basically highest not present in the list?
yep
nvm i didn't even need this π
actually i might
idk
Makes no sense
what is the point of using Sets.newHashSet() instead of new HashSet<>()?
val list = listOf(2, 5, 1, 9, 10).sortedDescending()
val max = (10 downTo 0).find { it !in list}
@dusky harness
π
shouldn't find be first instead?
It's the same thing
really? I have never used find xD
I used find because it should be val max = (10 downTo 0).find { it !in list} ?: 10
Find just calls firstOrNull
one thing - since im going from Int.MAX_VALUE - is it safe for me to do Int.MAX_VALUE downTo 0? π
You're going down from .. max int? Why?
Pretty sure there's a way to get the last entity is from bukkit
I've seen it somewhere
I should have asked what the original goal is lmao
This is sounding more and more like an xy issue
yeah
the reason why i said this is because 2,147,483,647 is a really big number and so i might just be able to make an int variable counting down instead
i thought i said this before
edit: nope turns out i didn't ;-;
oops
Bukkit.getWorld(blah).getEntities().maxOf { it.id } or something like that
then you just add 1
but then if bukkit makes an entity
if you run this code on the main thread, that won't happen π
The number is stored internally somewhere
Explain what your goal is first Dkim
fake entities - specifically holograms/armorstands
the reason why i need an entity id is so for packets
and i think this is stored in nms.Entity
as a static variable
Why not just UUID.randomUUID?
needs to be an id
aka int
for the client
idk why the client doesn't use uuids
dkim?
i'd need to modify the variable
im making a fake entity - so it won't be tracked in that unless i do it myself
which is why im just starting from Int.MAX_VALUE
instead of 0
no
then why not just Random().nextInt(Int.MAX_VALUE - 100_000) + 100_000?
Or just start at max int and go down one by one as you spawn them
yea
I would just use random xD
and i realized a couple minutes ago that the max int value is 2 billion π
it might have conflict
with an existing one
with 2 billion ids?
Β―_(γ)_/Β―
but this would have 0 chance of conflict
haha then why not store the "used values" in a set and generate it again?
i was planning to do that (besides the random part) above
but it'll run out of ids sometime in the future
true
ofc I doubt that would really happen anyway, but yeah I just wanted to point it out
Arenβt entity ids not persistent on restart?
They are not persistent even between chunks unloading and reloading
I didn't mean bukkit IDs, I meant dkim plugin' ids since it would count down to zero and never reset
(moved to dev-general)
Is it possible to write a SPIGOT plugin that acts as a BUNGEE proxy and just redirects somebody to another server?
like the spigot plugin just intercepts traffic with netty or something
that seems sketchy at best
You are mine now buttercup no playing hypixel you play hypwixel now
Yes
Not sure, essentially you'll just be mediating packets between the target player and server
player sends packet to your proxy server,
proxy server sends it as the player to the target server
and vice versa
So all you really need to do is establish a connection to the server as the player
I assume you'll find samples to joining a server on github
Try botting clients maybe
how do i send an action bar to all online players?
loop thru all online players and send it?
i have this in my on enable but it wont work:
@Override
public void run() {
Bukkit.getOnlinePlayers().forEach(p -> {
Bukkit.broadcastMessage("Test");
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("&7Speel je ook mee? &aMelon&2Network"));
});
}
}, 0, 200);```
This should send the action bar to everyone logged in your serverjava Bukkit.getOnlinePlayers() .forEach(player -> { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("&7Speel je ook mee? &aMelon&2Network")) });
what the actual fuck
you don't need a stream to call forEach lmao
was talking about Secret's code
use lambdas in your code, avoid using legacy/old syntax for Java as it makes it less readable
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
Bukkit.getOnlinePlayers().forEach() -> {
Bukkit.broadcastMessage("Test");
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("&7Speel je ook mee? &aMelon&2Network"));
}
}, 0, 200);
runTaskTimer π
It makes you look cooler though
How would i make a bossbar change color every x seconds? like red, green, blue and then it starts again
Resend the message
public static ArrayList<Pair> getTop(){
ArrayList<Pair> getVoted = new ArrayList<>();
String result;
if(Main.data.getConfig().contains("players")) {
for (String key : Main.data.getConfig().getConfigurationSection("players").getKeys(false)) {
ConfigurationSection userData = Main.data.getConfig().getConfigurationSection("players." + key);
result = Main.data.getConfig().getString("players." + key + ".currentResult");
getVoted.add(new Pair(userData.getInt("votesFor"), result));
}
Collections.sort(getVoted);
}
return getVoted;
}```
I have this, but since my yml is
```yml
players:
6b7b95b0-85b5-30cf-b997-271790f60040:
currentResult: Kangaroozy
hasvoted: true
votesFor: 1
votedFor: Kpaw```
Its returning null since it cant find the other 8 values i search for
How do I make it return "No Value" when it cant find the data
if null do smth lol
Im getting an out of bounds error
-1
i - 1
like when you iterate you probably have too large number to search for
like if you have 3 elements
This works since it exists in the yml file:
"&e1. " + getTop().get(0).getValue() + "&7 - &e" + getTop().get(0).getKey() + " votes"));
This doesnt work since there is no data:
"&e2. " + getTop().get(1).getValue() + "&7 - &e" + getTop().get(1).getKey() + " votes"));```
Right now if it cant find the second one the whole plugin shuts down, I jsut want it to return "No Value" instead of shutting down completely
public static ArrayList<Pair> getTop(){
ArrayList<Pair> getVoted = new ArrayList<>();
String result;
try {
if (Main.data.getConfig().contains("players")) {
for (String key : Main.data.getConfig().getConfigurationSection("players").getKeys(false)) {
ConfigurationSection userData = Main.data.getConfig().getConfigurationSection("players." + key);
result = Main.data.getConfig().getString("players." + key + ".currentResult");
getVoted.add(new Pair(userData.getInt("votesFor"), result));
}
Collections.sort(getVoted);
}
} catch (NullPointerException exception){
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "[CraftGasmCore] " + ChatColor.RED + "An error occured, please report this here with a screenshot of the error (Leaderboards)");
exception.printStackTrace();
}
return getVoted;
}```
Doesnt stop it from disabling the plugin
Exception
idk then man
im on my phone and wont help much but i wish you good luck fixing that error π
Hey Im using "Math" with placeholderapi and my variables aren't working what so ever for "math"
CraftGasm 
maybe #placeholder-api actually
i would recommend that you dont store all player data in 1 yaml file.
make multiple and name them based on the player uuid
catch (NullPointerException exception) π€£ that's a sign, man, sign that you're doing something wrong
oh and also this static ArrayList<Pair> getTop()
Hi there, having a question. How would I go about pushing default settings back into the config on reloading my plugin for cases when users have deleted an entire setting block without them having to delete the entire config to generate a new one?
if I use my command and it is returning false it will send the command I send in chat like /sc
if (args.length < 1) {
p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "FlipsMC SC" + ChatColor.DARK_GRAY + "]" + ChatColor.RESET + " " + ChatColor.DARK_RED + "You cannot send message with no text!");
return false;
This will give me the command back with the message
Went on a long search, unfortunately to push settings back into the config when missing, I have to use safeConfig() which also yeets all my comments. Now I guess I'll look at how I can save my comments from being f'ed sideways
Plugin#saveResource(βconfig.ymlβ, true); it resets everything though.
Why do you need NMS for that? Does the API have setMaxStack()?
Problem's with it..
- It returns the command /sc to the player who send it.
- It won't give messages to the second player with the permission.
Please help me thank you
Exactly what I do not want. Objective is to push missing settings on a per setting base when reloading if missing without touching any other settings. If i was a user of my plugin and the whole config resets when one setting got yeeted by accident, I'd simply tell the dev to f off lol
did you register it correctly?
Use a library like Configurate




