#help-development
1 messages · Page 497 of 1
No
public class ChatListener implements Listener {
@EventHandler
public void OnChat(AsyncPlayerChatEvent e){
e.setFormat(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "A" + ChatColor.DARK_GRAY + "]" + " " + ChatColor.GRAY + "%s%s");
}
}
Thanks
nvm i fixed the issue, i was casting a List to an ArrayList which doesnt work
why would you do that anyways
To say fuck Liskovs Substitution Principle
feels like college
Can i somehow make so if your in the world is or message will be e.setFormat(ChatColor.DARK_GRAY + "[" + ChatColor.RED+ "C" + ChatColor.DARK_GRAY + "]" + " " + ChatColor.GRAY + "%s%s"); and if B is will be B insted for a?
In what world
You can just change whatever you enter into the format instead of A
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
instead of those string templates java is planning to add, they should've done prefixes so we can do C"Text &cTo &dColor"
No i mean if i have 3 world, c, b and a, and if your in world a, will the first in your message be A if your in B it will be B and C it will be C
Yes.
Simply enter whatever instead of A
e.setFormat(ChatColor.DARK_GRAY + "[" + ChatColor.RED+ world.getName().upperCase() + ChatColor.DARK_GRAY + "]" + " " + ChatColor.GRAY + "%s%s");
Oh ok, but i want C to be red and B to be blue and A to be green
I dont know how to?
Figure it out. 👌🏻
Im trying
progress lol
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
Hello, is there an event for when a block is updated ?
what are you trying to do
Pretty sure there’s a block state event
I've got this code :java @EventHandler public void OreBlockBelowBreak(BlockBreakEvent event){ Block noteblock = event.getBlock().getRelative(BlockFace.UP); if (noteblock.getType() == Material.NOTE_BLOCK){ NoteBlock nb = (NoteBlock) noteblock.getBlockData().clone(); Bukkit.getScheduler().runTask(this, () -> noteblock.setBlockData(nb)); } }But when this block is updated, if there is a noteblock up the updated noteblock, he is also updated
(I also got the same with BlockPlaceEvent)
When endermen are angry at some player, is there a time limit for their anger?
because it seems to me like they stop being angry at some point if they don't kill the player
@quaint mantle ? Or do I need to loop for each block in the y axis ?
You should be able to stop all noteblock updates with the BlockPhysicsEvent
Or a packet listener
😅
I'm a little scary using an event called thousands time per second
Use a packet listener then
ProtocolLib ?
how to add permission to player without luckyperms
Add a permission attachment
But be aware you need to handle saving and loading over restarts
how can I listen to a packet ? And what is the packet do I need to listen ?
Not sure what Mojang does for this
I think they use arrays instead of lists
I think one big performance boost would be to cache the last used recipe
That way you can avoid looking through every recipe when someone crafts a bunch of the same thing
anyone got an idea how i can check if a server in a bungecoord network is online
thats what im doing but i dont know how to ask a server if its online
do i ping it?
and if so
how
no they hold grudges. They are eternally angry
Ok, thx
that's not accurate
Endermen lose their aggression after 30 seconds
As long as their attacker is not within 10 blocks of range iirc
Seems alright
Perhaps consider using a namespaced key for the recipeName
Make a namespaced key using whatever plugin is reading the recipe and registering it
tag what with pdc
Hello, I want to create a Minecraft plugin but I have this error :
Description Resource Path Location Type
The package org.bukkit is not accessible Main.java
I have imported packages but the class JavaPlugin does not exist.
I have tried to change version, to reload eclipse and to restart my computer.
Try to use Intellij
I know that on 1.19.4 display text, display block are available. Can you use this in Spigot? I can't find information about plugins that use this, for examples
?jd-s
It's called TextDisplay, BlockDisplay, ItemDisplay
thanks, guys
man i hate gcc sometimes
in inline assembly component of gcc you need to input a variable name, not a pointer, in order to pass the address of a variable from C/C++ code
like why
break C/C++ standards lmao
and here I am wondering why i get segfaults
for 4 hours
just for this shitty thing
Why coding on asamble? 💀
I have an assignment on SIMD instructions
Ohh ok school that males sense
what is the best way to create items in config? I need to create in this format. So how can I read it?
- 1:
- material
amount
- material
amount
- material
amount
- material
amount
- material
amount
- 2:
- material
amount
- material
amount
- material
amount
- material
amount
- material
amount
I need to implement algorithm that processes 4 integers at the same time with SIMD SSE instructions
4 numbers squared at the same time
mulps xmm0, xmm0
store the itemstacks directly, they are serializable
config.set(items, List<ItemStack>) I think will work just fine
writer a parser in c++ is fun lol
Is it really convenient if you fill it out manually?
depends on what you wanna parse
what do you mean by convenient?
i had written primitive assembly language
with 19 instructions
and instruction parser
im writing my own kind of assembly language
I mean, fill it all in the configuration by keyboard, and not fill it with code
why would you want to
I mean still I think itemstacks work fine
but you still just do what you proposed ofc
if you just need materials and amounts its fine
for the materials I would use what you get when doing Material.getName()
where can I get an example of an itemStack in config?
in the itemstacks code probably
or just save one yourself
config.set("example", new ItemStack(Material.DIAMOND, 20))
c++ switches are weird bruh
just add a scope to the case
ye its still weird
cant argue with that
switch cases are overall weird concept
cant even do a switch on a string
man firefox really does suck in terms of performance on linux
at least on my machine
i've downloaded chromium and it runs like 60-70% faster and uses less ram
too bad tho since I loved ui of firefox and its dev tools
but open up something that renders for example google maps
and that's a monstrocity on my machine via firefox browser
firefox is just chrome in disguise
too bad that you cant longer login with your google account in chromium
idk why, but it doesn`t work
not really it uses different web engine
and that's why im sad that I had to quit using firefox
because its the only survivor which has its own web engine
in terms of ram :X
save it
did you import it?
tru
not even a weird hexadecimal exit code
Why does it say Cannot resolve method 'getWorld' in a 'AsyncPlayerChatEvent'
World world = e.getWorld();```
why would a chat event have a world?
get the player and get the world
How can i check if a player is clicking into another player
@EventHandler
public void event(PlayerInteractEvent e) {
Player p = e.getPlayer();
if(!p.isSneaking()) return;
if(e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
ItemStack item = p.getItemInHand();
if(item == null) return;
Material t = item.getType(); // type of item
if(t == Material.PAPER) {
}
}
lmao
did you guys know
that you could put two or more statements at the end of the for loop?
aa[i] = i, i++
at least on c/c++ this is legal
a lot of weird stuff
well auto is cool
dunno what i; is supposed to do 💀
nothing
poke a variable
for a thread
i dunno
maybe it flushes L cache from the cpu
on separate threads
doesn't seem to be possible call the entity is the player clicking so i cannot check if it is a player, nothing found it
if i had to guess
for( i = 0; i < bb; aa[i] = i, i++ );
you can do one liners like this
pretty cool huh
declaration: package: org.bukkit.event.player, class: PlayerInteractEntityEvent
you should just take the entity and check for an (instance of) condition
you know this, if i have an iterator and i keep using the element at that position a lot, should i dereference it and put it in a variable or keep using -> ?
this whole c++ thing scares me when i use "slower" variants of things
shouldnt have done assembly cuz now i want to optimize everything
Anyone?
we told you
Where?
under your message
e.getPlayer().getWorld()
and becareful, you should note that event is async, if you wanna do modifications to world and chunk stuff, you always should do it sync
Thanks
Can you please help me with this:
Canot resolve method 'upperCase' in 'String'
e.setFormat(ChatColor.DARK_GRAY + "[" + ChatColor.RED + world.getName().upperCase() + ChatColor.DARK_GRAY + "]" + " " + ChatColor.GRAY + "%s:" + ChatColor.WHITE + " " + "%s");
it's toUpperCase()
The method would be called toUpperCase
do have an IDE?
how you are writing a plugin?
in what kind of editor?
I suppose that he does, otherwise there wouldn't be an error message
Thanks
How could i create a invsee inventory but with armor contents?
What part of it do you need help with? The command? The inventory? Getting the armor content? Setting the armor content?
The inventory
How do i make so if your in world C the C will be red and if your in b the B will be blue and a it will be green?
You can create a custom inventory using Bukkit.createInventory() after that you can set the items inside the slots using Inventory#addItem oder maybe setItem, I'm not sure how it's called
ok, thank u
Sure, there's also a lot of inventory gui guides if you Google for them. Smile also made one for creating your own Inventory lib. It is a little advanced though
@flint coyote Do you know something about this?
I made it, im already using a lib for the guis its called triumphgui and for me it works really well
myes
Alright. Just wanted to get you started
I know that this should be in a config and not hardcoded. If you do want to hardcode it you would have to string compare and set the colors accordingly. There's the ChatColor Class
whats even better: Process finished with exit code -1073741819 (0xC0000005)
Visual studio
yeah?
Only afaik it throws this nonsense exit codes with msvc compiler
actually this error is probably that you tried to edit string that is passed into method args
i got that few times
clion
example
void foo(char* bar) {
bar++;
}
int main() {
foo("smth");
}
why do people post C code here
what the
are you using a translator? what's your actual language?
seems like chinese -> english
I mean, the sentence you sent makes no sense whatsoever
im working on making custom enchants and was thinking about good ways to do it and i had an idea but i dont know if its a good way or not
basically the idea is make an abstract class enchant with all the basic identifiers like name maxlevel etc, but have an abstract method execute which will contain what each enchant does
the reason i think this might be a bad idea is because id be having multiple listeners for one event. for example i changed mob drops on entitydeathevent and if i have say looting on a sword then it would be listening for the entitydeathevent again
C# conventions? xd
discord with all their weird emotes bruh
i would guess czezch or polish
due to was amount of z's and w's in the string literal in his screenshot 😄
yea
Polish is very easy to detect 😄
Z, W, l with that - in the middle, and you know it its polish
🤡
#define true false
#define false true
nah you cant be that bad
🌝
now only stripping those stupid whitespaces
c++20 probably has string::trim
but im on 17
Sry, i dont really know what i need to do
I wrote it, but list is null. What should I do?
why is there a trailing .
people also dont seem to understand what a threadlocal random does
- Get the players world name.
- Compare it to whatever you want to set colors for
- Set the chat format of the event to the format you like and include your colors
no
but was is the issue?
Sry, but i dont know how to do step 2. ...
you should pass player object instead of "this'"
or wtf
its just not that way to do it
When i have a config with for example players and their kills, should i load it into hashMap and when plugin disables save the hashmap to config??
wait let me send
???
Is this how you do it?
player.performCommand("kit")
getCommand, just gives you the plugin command that you created it by editing the plugin.yml
ive been trying to add a shapeless recipe that requires a specific namespaced key on one of the ingredients but nothing i try will work, how can it be done?
💀
💀
What exactly are you trying to do?
If you can i would like a descriptive message of wha you want to do and provide any code about what you are doing
.
does the new entity hiding stuff work for hiding players
yes. Although I'd also save it every 5 minutes so you don't lose as much on a crash. + I'd load and save it for the player on join and on quit
Can I make two events in one class?
yes
but when i restart server every player quits right?
thankfully yes
yes
saving what
it does make sense for /reload
onDisable will be run before the server shuts down
players don't quit on /reload
what
Yes you shouldn't rely on it but it still makes sense to support it as good as possible
yes i guess
okay
Otherwise you are the one asked for support when someone used it and something broke
it won't be additional effort on a restart anyway. Since you remove the saved entry on quit. Therefore if the map is empty ondisable you can skip the saving entirely
bump
ok
I don't think when server stops/restart the PlayerQuitEvent got called.
So you need to save the data on onDisable
ok thanks
You can listen as many events you want on the same class. But for orgnizations pupouses some times you dont put all the different logic together
With logic i mean your plugin will do staff mode let say and another for custom items, that logic should be splited in 2 classes so then your code is better to read and to know what does
you can do RecipeChoice.ExactChoice choice = new RecipeChoice.ExactChoice(ItemStack); and then recipe.setIngredient(choice);
that will set the ingredient as the exact item stack (ignoring amount)
so it includes meta
both of those will trigger at the same time
put it in one method
you can set an item stack as exact choice? didnt know that
but i just made it work with loopholes, ty tho
can;t use ExactChoice on Shapeless
does anyone know if there is any flag add ons for block gravity on items like concrete powder and anvils? I know world guard can halt sand and gravel falling but it isnt working on other blocks. Maybe someone knows a plugin or a github, but just asking before building
my plugin doesnt show up when i do /plugins
show your logs and plugin.yml
how do i send the plugin.yml
?paste
do you guys use an ORM or raw sql?
use hyperskill
wha
google it
nah not what i need
logic lezzon
basically i need to grab all pairs in the array which don't contain the specified element(by index)
like this
My array
[1, 2, 3, 4, 5]
Pairs:
[1, 3]
[1, 4]
[1, 5]
[3, 5]
[4, 5]
ask chatgpt to teach u
blocked in my country
int[] arr = {1, 2, 3, 4, 5};
int excludeIndex = 2;
List<String> pairs = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
if (i != excludeIndex) {
for (int j = i + 1; j < arr.length; j++) {
if (j != excludeIndex) {
pairs.add("(" + arr[i] + ", " + arr[j] + ")");
}
}
}
}
System.out.println(pairs);
}
This?
cool what about all three-element combinations
pairs is kinda ez
and then all for-element combinations
and then all k-element combinations
can be up to 299999-element combinations
Are you storing int pairs like strings? 💀
do you just mean working with multi dimensional arrays
no
i just copied it straight from chatgpt lol
just do two loops
and i need all combinations of K elements which don't contain this element
it can be bigger than just pair
what is the use case
Do you need to count this combinations or what?
i don't think spigot help is where u wanna be lol
i need to find all of the possible combinations(excluding where elements are just in different spots)
and use a dist() method on them
to find smallest possible value which can dist() return
why not
fourteen asks for help with his math solver everyday
oh you are new
didn't see
any ideas
the entire task is on russian and i'm too lazy to translate
so trying to describe what i currently need
i need to return smth like this after my task is done
for first element the optimal combination(S) = {2, 3}, because dist(element, S) = 3
so i need to loop through all possible combinations which exclude first element, to find the most optimal combo
which gives the smallest return value when i call dist() on it
auksto lygio matematika
the dist method is given, so don't care about it
man ive been doing too much assembly i cant think straight
cant you create all pairs first and then remove the ones you dont need?
efficiency go brr
?
for pairs i would just use nested loops to get all possible pairs
and then easily use dist on them
but the problem is i need to work with combinations of any size
not just pairs
combo can consist of 299999 elements
as a limit
300k
and the array can be even bigger
like from all numbers combinded to smallest combination?
combo of all numbers except one
let's for example make a code where combo has length of 4
and the array has size 6
[1, 2, 3, 4, 5, 6]
and i need to get all combos except ones which contain first element
[2, 3, 4, 5]
[2, 3, 4, 6]
[2, 3, 5, 4]
[2, 3, 5, 6]
[2, 3, 6, 4]
[2, 3, 6, 5]
[2, 4, 3, 5]
[2, 4, 3, 6]
and so on
if the elements just switch places it's still the same
so [2,3,4,5] == [2,3,5,4]
i need the unique combos
idk tho
i mean
it's not a problem
i need the indexes to be different
if the element has same value but different index then it's a different combo again
the example has an array of 4 elements
and you only need pairs
[1,2,3,4]
[1, 3]
[1, 4]
[3, 4]
a lot of probability math that is for sure
and well, i just call dist 3 times on this 3 pairs
what do i do if the logs say they couldnt load my plugin
to get the optimal one
and that's the end
but fuck
on the actual task you never get pairs
only combos which are longer
read the error prorerly
and get the reason why it cant
logs should tell you
idk what the big error means
post it
other then could not load
[Server] [ERROR] Could not load 'plugins/NoIronLossPlugin.jar' in folder 'plugins'
read teh caused by line
where tf
oh
found it
Caused by: java.lang.ClassNotFoundException: me.sw11per.noironlossplugin.NoIronLossPlugin
this is my code btw
im trying to make so you dont lose iron armor on death
either the path/package is incorrect in your plugin.yml or you are using artifacts to build but have maven setup
package com.example.noironloss;```
looks very different to java me.sw11per.noironlossplugin.NoIronLossPlugin
uh theres probably a note but dont expose functional interfaces
i was wondering the same thing actually
it just infuriates me
from what I know about probability is
length pow of length
so alphabet (26) * alphabet (26) * alphabet(26) = 26 pow of 3
it would generate 3 length combinations ( x _ x _ x)
i learned that from cracking
.
lol names something function
isn't that just poor practice?
You need to use
case BARRIER:
<code>
break;
Instead?
:
What's the easy way to make a tabcompletion return all the values from an enum
I know there's some cool way to do it
store Arrays.stream(Enum.values()).map(Enum::name).toList()
That's what it was
Thanks
Oh but
What if I want to filter
While it gets typed
startswith right?
Stream -> filter
It filters it automatically with what elements in the list match it. But ig you can add more filtering using stream#filter(Predicate)
Need last bit of help regarding packets and protocolLib
I'm trying to create a packet for entity metadata
//I'm trying to send a packet to a player regarding a different players metadata settings.
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
I believe I'm getting the concept wrong
Lets say I want to start/stop the glowing effect for just a specific player
https://wiki.vg/Entity_metadata#Entity_Metadata_Format:~:text=classes they extend.-,Entity Metadata,-Entity
hello.
I wanna render some world borders per player, how do i go about doing that?
and I also wanna limit the chunks being sent to each player, configuring my own render-distance or something, well, more like choosing which chunks get rendered for each player.
nvm.
Can entities have multiple passengers
Yes
Only in newer versions
Is anyone here a expert in netty pipeline and packet injections?
how can i actually use the i variable in a stream
for (int i = 0; i < amount; i++) {
System.out.println(squares.values().stream().filter(v -> v == i).count());
}```
i worked too much today
my brain is dead
local variable i defined in enclosing scope must be final or effectively final
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
Make a new final variable that has the value i
final int j = i;
For example
for (int i = 0; i < amount; i++) {
final int i2 = i;
System.out.println(squares.values().stream().filter(v -> v == i2).count());
}```
liek dis?
Yes
this fucking compiler doesn't have preview features enabled
i cant use pattern matching
nooo
?paste
I hate codeforces.
is it okay to override the onLoad() function?
i'm using Kotlin:
instance = this
}
override fun onLoad() {
instance = this
}```
I was going to replace this
bruh i wish i had 3d shape lib for spigot
but i would be cheating on my math teaching
its not
just dont work with an instance and use dependency injection
uh oh
this is worse than writing custom assembly
is dependency injection just passing a class in the constructor?
instead of creating it in the class itself
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
hmm i see
does anyone use the getInstance() in production?
How can I get a player from an command (bungeecord)
they better dont
Plenty do
sometimes
but they are 💀 already
i nuked them
Cuz lazy pass instances to the constuctor
i havent seen any getInstances in c# production code, everyone i talked with uses dependency injection
hello, I'm facing a problem, I don't know how to add a custom item to shopguiplus or to buy a certain access or command
i just added the dependency injection
but i have to use it in 3 classes because i wanted to use it in one
my table manager class has to do this now
Instead of
??
yeah thats fine
oh i see
better yet is to not rely on your plugin/parent class at all if you can prevent it
that's how it should be
what error does Bossbar give if it's less than 0?
good thing I only develop for latest 👍
probably either nothing or IllegalArgumentException
thanks
I mean just try it out and see
just do checks instead of catching exceptions ig
tbh, I don't understand anything from that message
"closing the case"?
"two good ones"?
did you use a translater?
I still don't get it
I'm trying to cancel splash potion damage to potion thrower, so basically if you throw a harming potion you don't get damaged, only other players do, and I can't get thing working, any ideas on what methods to use, also It has to be a specific potion, for example if you throw healing potion u get healed, but if you throw poison you dont get poisoned.
how to cancel task in it?
call cancel()
this.cancel()
use the Consumer<BukkitTask> scheduler method
it doesn`t work, I tried
instead of using () in the lambda, use "myTask" or sth
Oh
what'S your question
just ask your questin
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
yeah but I won't watch it, I much rather just read messages
wdym? builder for what?
try to put your question int a text message
ok
the back button isnt working?
add sysouts and see if it runs
you most likely check its type while its air/null
com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: User customer_485511_sql already has more than 'max_user_connections' active connections```
Is there a way to kill these connections?
the if & switch is pointless
you check if its null or a barrier, if its null you close if its not null you close
just close the inventory when they click
i can't even log in because there are too many connections
add sysouts to it
see whats running
then you can fix it
after if, in ifs before ifs
how many did you open?
the "default" limit is like 150 IIRC
which is a bit little. But if your plugin needs more, you did a bad job
first of all i forgot to close them
secondly its capped at 10
maximimum pool size?
max_values should be a few thousands
or is that different
mysql
default in mysql is 151 IIRC
System.out.println("passed XYZ")
are you hosting the DB yourself on a VPS?
oh then you probabyl cannot increase it
but you can try, do you got mysql "root" access?
what should the maximum pool size be?
number of requests you need at max at the same time * 100
no
you add one before the if, inside the {} of the if, and after the if
if it returns
do you only create one connection typically?
i'm a bit new to using sql and minecraft
are you using HikariCP?
yea
then just call "getConection()" everytime you need one
?learnjava!
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming. https://media.discordapp.net/attachments/694661573125472256/998143126373941248/6n0v4g.gif
add a sysoutline BEFORE the if, INSIDE the {} of the if]
and then after if it has return; in it
Do i always close the connection after i make one?
?spoon
Spoonfeed a newbie for a day and they'll come back with more questions. Teach them to find their own answers and you'll both be better off: you won't get stuck answering the easy questions and they'll be much more productive than before.
so if i use getConnection to create a connection do i close it after?
yes
you are usually supposed to use every connection from Hikaro in a try-with-resources block
the LINE before it
like this
and close statement 🥺
try does that
connection = HikariCP(plugin).getConnection()
statement = connection?.createStatement()
statement?.execute("CREATE TABLE IF NOT EXISTS `gens_playerdata` (`uuid` VARCHAR(36) NOT NULL, `name` VARCHAR(16) NOT NULL, `jsondata` LONGTEXT NOT NULL) ENGINE=InnoDB;")
} catch (exception: Exception) {
exception.printStackTrace()
} finally {
statement?.close()
connection?.close()
}```
something wrong
try w/ resources does that automatically
this is what i have right now
HikariCP(plugin) lol
are you making a new hikari connection to the db each time?
put the "get connection" part into (paranthesis)
i dont see the ps in the closing block
try (Connection myConnection = ...) {
// do stuff with connection now
you should connect do the db once on startup then call getConnection on the hikari stuff wen you want to send data
i don't think you can do that in kotlin
uh oh kotlin
if you cant do it in kotlin dont use kotlin
you can definitely do everything you can do in java, in kotlin too
try {
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery("SELECT 1;").use { resultSet ->
if (resultSet.next()) {
plugin.logger.info("Connected to database!")
}
}
}
}
return dataSource.connection
} catch (exception: Exception) {
plugin.logger.severe("Failed to connect to database!")
exception.printStackTrace()
throw exception
}
}```
In Kotlin, the .use function is an extension function that is available on any class that implements the AutoCloseable interface. The purpose of the .use function is to ensure that the resources acquired in a try block are automatically closed when the block is exited.
damn wtf
you may be better to just use java
is that what it is?
most of us use java, we can help a lot easier with java
is there's a reason why you're using shitlin instead of just using java?
trying to improve, i also use it with other stuff
try-with-resources is definitly possible in kotlin, but I gotta admin, I don't know how
why is there a pic of @torn shuttle
wondering the same thing
transfer this to kotlin, create an instance of your hikari class on onEnable, save that class to a variable and have a getter, then when you need a connection called plugin.getThatClas().getConnection()
and dont execute a query each time
please dont do that via your plugin lol
a)) put something in the sysouts that is descriptive of where it is
and an if statement usually has {}
if not add them, and add the sysout before return
?learnjava! for the love of god
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming. https://media.discordapp.net/attachments/694661573125472256/998143126373941248/6n0v4g.gif
dont think anyone has ever clicked on that
Ooh it has a gif now
to be extra rude
if (soemthnig) {
System.out.println("in the if");
return;
}
you didn't encapsualte it
Now I did. What you gonna do about it?
sysout takes a string, if you dont give it anything you arent gonna know whats passing
i live in your walls
he didn't understand because it wasn't encapsulated tho lol
there was no {}
and an if statement usually has {}
EW
now you just need to add a string in the other sysouts and add a sysout after the if
if anything you need to learn java and learn naming conventions
since i'm new to hikaricp, this might be a dumb question, but is the connection supposed to run as long as the server online? or only when a request is made ( for example if a player changes their nickname and it gets updated to the database)
normally a hikari instance should be made on enable then you can called ThatClass#getConnection, which would return a connection from the hikari instance
no it shouldnt, when you "close" the connection, it doesnt actually close it, it just gives it back to the pool and the pool keeps it alive for any subsequent requests
you write System.out.println("passed if XYZ")
so you just request a "new" connection every time you need one
wtf am i looking at
if your compiler says it goes brr its probably not supposed to be like that
System.out.println("before if");
if (something) {
System.out.println("Inside if");
return;
}
System.out.println("Passed if");
copy and paste the code here
writing the same thing in a sysout isjust going to make it harder to help, give them something descriptive
imagine using kotlin because "it's better"
and then kotlin lacks basic java features
and you're like "wtf"
how?
so the createConnection method should be try with resources or no
getConnection()? yes
why do u have ; lol
yeah, now just change the string in the if so you can tell what if its refering to
I still don't know how to do it
new HashSet(viewers) or smth idk what type that is
here are my functions:
configureHikariCP()
createDataSource()
createConnection()
getConnection()
closeConnection()
lol
I'm guessing createConnection is pointless?
show the code without the error
idk what that does
imma just use chatgpt and translate it to java
i just request a connection when my plugin starts to shut down when it doesnt work
you have a ; at the end of your if
no
on the if (e.getCurrentItem() == null || something) you have a ; at the end
remove that
add the ; back to the sysout
and add something into the quotes
?
waittt the pool is supposed to be always open right
wdym by open
something descriptive about where it is
white guy with beard = magmaguy. SMH on this blatant racism
I'll have you know my beard is much nicer
eg "passed item check"
new HashSet<>(inventory.getViewers()).forEach(HumanEntity::closeInv)
HikariConfig config = new HikariConfig();
// configuring hikari-cp
List<Object> hikariCPConfig = configureHikariCP();
String host = (String) hikariCPConfig.get(0);
String name = (String) hikariCPConfig.get(1);
String username = (String) hikariCPConfig.get(2);
String password = (String) hikariCPConfig.get(3);
int port = (int) hikariCPConfig.get(4);
int minimumIdle = (int) hikariCPConfig.get(5);
int maximumPoolSize = (int) hikariCPConfig.get(6);
int connectionTimeout = (int) hikariCPConfig.get(7);
config.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + name);
config.setUsername(username);
config.setPassword(password);
config.setMinimumIdle(minimumIdle);
config.setMaximumPoolSize(maximumPoolSize);
config.setConnectionTimeout(connectionTimeout);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
public Connection getConnection() {
try {
Connection connection = dataSource.getConnection();
if (connection.isClosed()) {
plugin.getLogger().severe("Connection to database is closed!");
return null;
}
return connection;
} catch (SQLException exception) {
plugin.getLogger().severe("Failed to get connection to database!");
exception.printStackTrace();
return null;
}
}
public void closeConnection() {
try {
if (dataSource != null && !dataSource.isClosed()) {
dataSource.close();
}
} catch (SQLException exception) {
plugin.getLogger().severe("Failed to close connection to database!");
exception.printStackTrace();
}
}
if you need more hand holding than this someone else is gonna have to help you, im not spoon feeding you anymore
hikaridatasource extends hikariconfig, configure datasource instead of doing pointless work
well done
datasource.getConnection also never returns a closed connection, it would rather throw
so get connection is always supposed to close
wdym
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
try (Connection connection = dataSource.getConnection()) {
if (connection.isClosed()) {
plugin.getLogger().severe("Connection to database is closed!");
return null;
}
return connection;
} catch (SQLException exception) {
plugin.getLogger().severe("Failed to get connection to database!");
exception.printStackTrace();
return null;
}
}
Is this better?
well the datasource will never return a closed connection so that check is pointless
what country are u from?
i meant to say that, not that you should use a try with resources
is chatgpt blocked in poland
ohhhh
because you have to give more than a fragment for context and it can read stack traces
i'm trying to learn from other people's open source stuff as well, but their stuff is less modern i guess
try {
return dataSource.getConnection();
} catch (SQLException exception) {
plugin.getLogger().severe("Failed to get connection to database!");
exception.printStackTrace();
return null;
}
}```
i just looked at the code
why the hell do you have a class player var
that you never set
remove the title check
and make player p = event.getPlayer()
replacing your Player p = Player; yes
does anyone know how you can remove the red numbers of a scoreboard? I know some servers have done it but I think its through a resourcepack
but idk how
theres a shader for rps that can do it
whats rps
resource packs
oh xD
no
you remove the if check for the title
never do that
and you replace Player p = Player; and make it Player p = event.getPlayer();
change event to e then
Don't detect inventories by their name
and use your brain please
red == bad
usually you can hover over it to see why its red
read what you wrote
your syntax doesnt make any sense
remove line 23
just ask yourself, what is getView()("blah blah") even supposed to mean
MC dev is known to be a bit unstable
a bit unstable really is an understatement
it crashes 1 out of 3 times I try paste something
something being a string btw
it dies with teh material class
that too
i disabled the bytecode decompiler and i havent crashedin a while
I actually haven't had any issues with it
how do I do that
settings/plugins/installed then hit the checkbox on the bytecode decompiler
Why would the minecraft dev plugin have anything to do with the material decompiler
it just do
thanks
Eclipse sometimes crashes with the material class too tbf
its just too big lmao
yeah thats what the plugin says when it crashes my ide
Mojang has fully removed their material class now
but luckily past traumas have taught me to spam ctrl + s all the time
you need to save an instance of the inventory or the view when it opens
you can then check to see if its the inventory or the view
alternatively, read this https://www.spigotmc.org/threads/a-modern-approach-to-inventory-guis.594005/
no
you dont check the name
you check in instance
You can also use the inventory instance itself
Hello everyone. Can you help me?
My BossBars aren't updating.
Code for the task:
https://pastebin.com/4p3Q3kxz
OR
https://paste.md-5.net/ikoyodapid.java
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
?paste
Anyone know how to get the actual dimensions of a textDisplay (both getDisplayWidth/Height() and getWidth/Height() return 0)?
Also - not sure what unit getLineWidth() is given in (default is 200) - pixels, perhaps?
does anyone know why I can't throw an exception on an integer, but it works for a string?
val minimumIdle: Int = hikariCPSettings.getInt("minimum-idle") ?: throw IllegalStateException("Missing 'minimum-idle' value in config.yml")
int cant be null, Integer can
getInt probably returns a primitive. Therefore it can't be null
you can use the normal get and check if it's null before using getInt
or use the get and cast it to an int
getString will lead to an exception since it's an integer
wait does it get the key or the value?
the value. You have to hand it the key
I had this:
`val port: String = databaseConfig.getString("port") ?: throw IllegalStateException("Missing 'port' value in config.yml")`
But it didn't cause any errors
and the plugin works
You can also just use isSet
wdym
ohh
like just put a value
if it is not existing
getString("port", "default");
why would port be string
yea i'm fixing it
192.168.1.2:25A65
but wouldn't a default be pointless for an sql connection
since it won't connect regardless
25A65 as port 🤔
Are you telling me ports aren’t in hex
[2001:db8::9090]:9090 hehe
can use an inline if Republic
Help please? Mnfalex
val port: Int = if (config.isSet(“port”)) config.getInt(“port”) else throw MissingException(…) @flint carbon
a tad unfortunate you need to repeat but that’s the only way I can think of instantly
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
what if someone deletes it from the config.yml
more progress, decided to do it in c++ lol
Wdym
host: localhost
name: database
username: root
password: password
port: 3306 //delete this line completely
hikari-cp-settings:
minimum-idle: 20
maximum-pool-size: 20
connection-timeout: 30000
?
my assumption is that isSet is false when it’s not there lmao
the isSet will return false
Correct
did you even read the line I sent
its loaded into memory that config
if it’s not there it’ll throw the error 🤷♂️
so unless someone calls reload() that wont change anything about your values
No errors. Title and progress values aren’t updating. Already showed boss bars don’t get updated.
I don’t even think that’s valid yaml
^^
"Ofc it's valid yaml" - yaml in a nutshell
then what is isSet?
Its true
Why not read the docs for isSet
Its set to null
this site just places "null" bruh
because I’m not the developer asking and I don’t even know where isSet is from
Format string is not null. Just the boss bar update thing doesn’t work
Is isSet from ConfigurationSectiin? Is that what we are talking about knack
why isnt getInt returning an OptionalInt
Ew
isSet is likely to be true if it’s set to null
and yet it will likely return 0 on getInt
my assumptions 🤷♂️
i guess this is pointless to do:
val portValue = databaseConfig.getInt("port")
if (portValue == 0) {
throw IllegalStateException("Invalid 'port' value in config.yml")
}
portValue
} else {
throw IllegalStateException("Missing 'port' value in config.yml")
}```
(for each config option)
pretty sure kotlin has Optional<Int> which proves kotlin’s superiority
gn
?
so it will work for both key and value missing
Int ew
Republic the other way would be to use a Delegate which I highly recommend since it makes the code more organized. val port by ConfigOption.Int(key = “port”) for example
than replicating that one liner for how ever many ints you have
definitely if it was whatever that huge if you had tho, optional if it’s just the one line
yes
Kotlin is so weird. Seems like I made it while being drunk.
„Lol name more important than type.
Lol i hate null, in dont know what it is????
Static bad. Companion object it is
Kotlin is just shit
idk why everyone in this server hates kotlin
Because it is objectively shitty
Alex you’re a hater of literally everything
You should ask him about paper
You don’t like kotlin, nosql, paper
That is only the partly true
no it’s completely true
Correct
and not only do you not like it, you have to make it known whenever someone uses it or brings it up 😭
are you good with kotlin?
in my opinion, why
do you know if val config = ConfigFactory.load().getConfig("database")
would read this:
database:
host: localhost
name: database
username: root
password: password
port: 3306
hikari-cp-settings:
minimum-idle: 20
maximum-pool-size: 20
connection-timeout: 30000
maybe this is not kotlin lol
but it is before i use the delegates
that’s literally not a kotlin question lmao
considering I’ve never seen that class before ConfigFactory, no idea
If someone randomly pings me, they deserve an answer. Kotlin is ofc not shitty, but java is obv better, no doubt
That is just my opinion
Sup guys!
Any of you familiar with remapping with Gradle?
Yes
Use maven if possible
It‘s way easier
Ooh speaking of things Alex doesn’t like
Then you go explain it pls
do you use config4k
Good luck
Use paper weight userdev
how to add chunk hopper in shopgui+ ? please someone help me!
I used to use maven, but migrated my project to a multy-modular project to add a Fabric port, which forces you into Gradle
Cheap workaround lol
how to add chunk hopper in shopgui+ ? please someone help me!
?
I'm trying, but getting:
paperweight requires a development bundle to be added to the 'paperweightDevelopmentBundle' configuration, as well as a repository to resolve it from in order to function. Use the paperweightDevBundle extension function to do this easily.
No idea how to add developmentBundle with groovy
Message the author of that plugin
All I use is
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19.4-R0.1-SNAPSHOT")
as a dependency
Maybe that’d even work, after waiting 25 minutes
Wait, no. Gradle doesn’t even check .m2
takes 3 min for me
3 minutes until gradle throws up?
no untill the user dev is done setting up
Where is that plugin supposed to come from? Its not on maven central
It’s on maven central now
i thought its on gradle portal now
Or whatever the default for gradle is
not their repo
This seemed to work. Let me do some tests. Thanks!
No
Lmao fr?
yeah
Gradle gets more funny every day
how
Gradle devs be like „lol we dont use maven central. Our builds should be reproducable without external depencencies“
3 years later:
„Yes“
we use maven central, but why would we put thousands of plugins on maven central
you can still put them on other repos its just more config for end users
Dont say „we“ while referring to actual gradle devs
I set the background image to something I have on my PC and lowered the opacity. As for the color scheme, I downloaded one a long time ago and have kept it with every update since. You can however edit nearly everything you want in the Color Scheme Editor
Gradle claims to be „reproducable“, but still used your m2 folder. Erm. Whut?
wat
Yeah explain it
ive never heard of that
I think I chose the right setting to export that theme. Just go to File > Manage IDE Settings > Import Settings
You claimed yourself that gradle uses random files from some website
Remind me again - what‘s not official?
Oh, the shadow plugin- because gradle itself is a bit stupid
most gradle plugins
Nvm lemme just create a new archetype
Oh dw, you won‘t get it. Gradle doesn’t know about that eithrr
Maybe i will just run apt to update to maven
Oooh i forgot, you guys need a 150mb wrapper in every repo instead, my bad
Maybe that‘ll change in gradle 10
Or i forgot, your build files breaks on every update
You can use a global install if you want
See msg above
