#help-development

1 messages ยท Page 171 of 1

fluid river
#

good morning tho

#

just woke up

young knoll
#

You can also just do 1d and 50d

fluid river
#

@echo basalt you banned me for nothing, undo that

silk mirage
#

anyone...

fluid river
#

what's wrong

silk mirage
#

That's my question

#

why is maven going nuts

molten hearth
#

well

#

I'm trying (int) (this.getDynamicStats().getMaxHealth() * ((double) (this.getDynamicStats().getMaxDefense() + 50) / 100));

#

and its still 100

fluid river
fluid river
#

?notworking

undone axleBOT
#

"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.

silk mirage
#

.

#

see that

molten hearth
#

oh I forgot the 1

fluid river
silk mirage
#

I'm using java 17 aka version 61

fluid river
#

basically

#

on both projects?

#

one you shade one you use in your

silk mirage
fluid river
#

one you specify in properties section of pom.xml on both

silk mirage
#

ik

molten hearth
#

now it says 200 instead of 150

#

LMAO

silk mirage
silk mirage
molten hearth
#

oh I messed up the formula again

#

goddamn it

fluid river
#

for all of the projects

silk mirage
molten hearth
#

?learnmath when

fluid river
#

bro show formula tell what it should return

#

basically explain yourself

molten hearth
#

now its 150

#

๐Ÿ‘

#

return (int) (this.getDynamicStats().getMaxHealth() * (1 + ((double) (this.getDynamicStats().getMaxDefense() / 100f))));

fluid river
#

i fixed it with telekinesis again

molten hearth
#

this is my formula

silk mirage
#

wait what's your shade plugin version

#

@fluid river

fluid river
#

i don't use it in this project

#

don't shade

silk mirage
#

uhh can you check

fluid river
#

i copypasted code from my tutorial

silk mirage
#

I don't want to initalize a runtime dependecy management for just 1mb

round finch
#

How do i implement spigot doc into eclipse?!

Do not tell me to use ij ide <--(i already know this)

crimson terrace
#

how about intellij

round finch
#

mfer

#

you guys! lmao

crimson terrace
round finch
#

you gotta be kidding

crimson terrace
#

maybe

round finch
#

all i need to know is how to get spigot doc working in ecplise

crimson terrace
#

I dont know my way around eclipse sadly, otherwise I could help

eternal oxide
#

Eclipse does it for you

round finch
#

it isn't showing the info

eternal oxide
#

using Maven?

round finch
round finch
#

but idk if i trust my ablities in maven

#

i will post maven file

#

?paste

undone axleBOT
eternal oxide
round finch
round finch
molten hearth
#

so uh I'm new to reflection, how can I cast xyz.invoke as an int?

eternal oxide
#

ensure the javadoc is ticked in that menu

lost matrix
molten hearth
#
for (Method m : this.getStats().getClass().getMethods()) {
            if (m.getName().startsWith("get") && m.getParameterTypes().length == 0) {
                try {
                    final Object r = m.invoke(this.getStats());
                    System.out.println((int) r); // I need this to be an int
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                } catch (InvocationTargetException e) {
                    throw new RuntimeException(e);
                }
            }
        }```
molten hearth
eternal oxide
#

then right click pom -> Maven -> update Project

#

ensure force update snapshot/releases is ticked

round finch
lost matrix
round finch
#

ooopsi here you go!

#

my settings

molten hearth
#

Exception in thread "main" java.lang.ClassCastException: class java.lang.Class cannot be cast to class java.lang.Integer (java.lang.Class and java.lang.Integer are in module java.base of loader 'bootstrap')

eternal oxide
lost matrix
molten hearth
#

but how is it of type class when i used Object as the type

lost matrix
#

For example getClass() from Object

molten hearth
#

oh

#

well

#

im not using getClass tho ๐Ÿฅฒ

lost matrix
#

You can check if the return type is int

molten hearth
#

ohh wait lmao

lost matrix
#
    for(Method method : methods) {
      if(method.getReturnType() == int.class && method.getName().startsWith("get")) {
        int result = (int) method.invoke(instance);
      }
    }
molten hearth
#

I had a method that I forgot existed in the class

lost matrix
#

Something like this

molten hearth
#

well that says object expected

#

Integer.valueOf(r.toString()) seems to work tho

eternal oxide
lost matrix
#

Cast it

molten hearth
#

nein

lost matrix
#

I edited the method

molten hearth
#

oh

#

fine ๐Ÿ˜”

#

perfect

#

ty

lost matrix
#

Please dont tell me that you use reflections on your own classes

molten hearth
#

yes ๐Ÿ˜Ž

#

i cannot be bothered typing all 20 of them out

#

im converting the stats into NBT and I'm using reflection to loop and get the values and I'll remove get from the method name and add it as an nbt value

lost matrix
#

You dont have to if you use a proper design... this sounds like a BIG design issue which you
are hackily trying to "fix".

molten hearth
#

nah impossible

round finch
#

very cursed

eternal oxide
#

did you manually add a jar or something?

sterile token
#

What its better for listening to redis message arrive event, using thread or an executor?

lost matrix
sterile token
#

Oh ok

#

So its would be the same using thread or executor

#

Because the executor will create a Thread for each process right?

lost matrix
#

Depends on the thread factory of the executor

round finch
#

on build import

sterile token
#

Because with a friend we are doing benchmarks and threads makes the plugin to work really slower

eternal oxide
#

the only reason it would not show the javadocs is if you manually added a jar or messed up your classpath

molten hearth
# lost matrix Please dont tell me that you use reflections on your own classes
public List<NBTCompound> getNBT() {
        List<NBTCompound> nbt = new ArrayList<>();
        for (Method m : this.getStats().getClass().getMethods()) {
            if (m.getName().startsWith("get") && m.getParameterTypes().length == 0) {
                try {
                    final int result = (int) m.invoke(this.getStats());
                    nbt.add(NBT.Compound(Map.of(m.getName().replace("get", ""), NBT.String(String.valueOf(result)))));
                } catch (IllegalAccessException e) {
                    // do nothing
                } catch (InvocationTargetException e) {
                    // do nothing
                } catch (ClassCastException e) {
                    // do nothing
                }
            }
        }
        return nbt;
    }``` look at this unprecedented beauty
glossy venture
#

otherwise youd have a lot of repeating code

molten hearth
#
[{"Damage":"260"}, {"GearScore":"712"}, {"Rarity":"4"}, {"Strength":"150"}, {"Health":"0"}, {"Speed":"0"}, {"MiningFortune":"0"}, {"FarmingFortune":"0"}, {"AbilityDamage":"0"}, {"Defense":"0"}, {"PetLuck":"0"}, {"BonusAtkSpeed":"0"}, {"MagicFind":"0"}, {"ForagingFortune":"0"}, {"TrueDefense":"0"}, {"MiningSpeed":"0"}, {"Pristine":"0"}, {"CritChance":"0"}, {"Intelligence":"350"}, {"Ferocity":"30"}, {"CritDamage":"0"}, {"SeaCreatureChance":"0"}]```
glossy venture
#

and this can be used for basically anything

tardy delta
#

isnt there Map.singleton(K, V)?

molten hearth
#

seems pretty useful

glossy venture
#

yeah

molten hearth
#

oh is there

#

I'll give that a try

lost matrix
tardy delta
#

me who thought that java internally uses reflections

glossy venture
tardy delta
#

how are they slow tho

glossy venture
#

last time i used them it optimized to ~10 ns per method call i think

molten hearth
glossy venture
#

using reflection

lost matrix
glossy venture
#

not for a few calls

lost matrix
#

*If you use java 8

glossy venture
#

yeah

lost matrix
#

300ms for 1 invocation

glossy venture
#

on an old vm then

lost matrix
#

Depending on how cold the classloader is for this class

#

He uses 1.8 i assume

lost matrix
#

reflections are absolute garbage if you dont properly cache them

lost matrix
tardy delta
#

mye

#

might wanna use jmh

glossy venture
lost matrix
#

no

#

It may take seconds or it may take hours

#

Or it wont jit compile ever

#

All possible

glossy venture
#

then benchmark it with one pass and see the time i guess

#

or a couple times

lost matrix
#

It can def. give you an understanding about the magnitude

#

0.1ms 1ms 10ms 100ms

glossy venture
#

will JIT optimize the actual reflection too

#

yeah right

#

until it calls into native or vm code

lost matrix
#

Yes. It will actually create concrete method calls. They wont be indistinguishable from a normal call then.

#

*If the JIT think its worth it

glossy venture
#

you could cache the method handles for a class in a hash map and use those

#

if youre very concerned about performance

lost matrix
#

This is what every half decent plugin which is using reflections does.

#

But in java 18 every method invocation is backed by a methodhandle anyways

sterile token
#

Method Handle exists on JVM 8

molten hearth
#

however

#

Total execution time: 14ms

glossy venture
#

for one iteration

molten hearth
#

for all of them

#

oh you want it for one

#

one sec

glossy venture
#

for all methods

molten hearth
#

including me setting to to NBT and stuff or just the reflection

lost matrix
glossy venture
#

just the reflection

molten hearth
#

14ms is great bruh

glossy venture
#

yeah

molten hearth
#

im a js dev im surprised when my code doesnt take 2000ms

glossy venture
#

14ms is pretty slow thats ~1/5 of a tick

molten hearth
#

Total execution time: 0ms

#

wonderfuil

#

one sec switching to nano lol

#
Total execution time: 33100ns
Total execution time: 33500ns
Total execution time: 19200ns
Total execution time: 21600ns
Total execution time: 21900ns
Total execution time: 19000ns
Total execution time: 35400ns
Total execution time: 16300ns
Total execution time: 16900ns
Total execution time: 17600ns
Total execution time: 17000ns
Total execution time: 17000ns
Total execution time: 16700ns
Total execution time: 16800ns
Total execution time: 34500ns
Total execution time: 18300ns
Total execution time: 17900ns
Total execution time: 17300ns
Total execution time: 29100ns
Total execution time: 17600ns
Total execution time: 16400ns
Total execution time: 29800ns```
lost matrix
#

Minecraft has 50ms per tick.
If you have a decent playerbase then 20-30ms are taken up
by mc itself and another 1-3ms by spigot.
Then add 10ms for other plugins and you are left with maybe
15-20ms for your own plugin. If a single method call already eats

75% of your entire CPU time then this is very bad.

molten hearth
#

its uh

#

variating

#

well its fine

#

this call is only used during startup to create an item

#

after that I just store it in a hashmap and never really re-create it again

lost matrix
#

Well on startup time doesnt matter

molten hearth
#

yeah luckily for me

lost matrix
#

But using reflections like this is a clear sign of faulty design

molten hearth
#

idk I dont think design gets much better than this

#

I have like 20 stats and need to access them somehow

lost matrix
# molten hearth I have like 20 stats and need to access them somehow

Well. Create a stats enum. Then a Map<Stat, Integer>
And getting all stats is as simple as iterating through the enum

for(StatType type : StatType.values()) {
  int stat = statMap.get(type);
}

And instead of having one method for every single stat you can
have one method which works for every stat you want:

public int getStat(StatType type) {
  return this.statMap.getOrDefault(type, 0);
}
molten hearth
#

oh yeah that could work too lol

lost matrix
#

Then you just need to add new entries to your enum and dont have to worry about all the places for your new stat

#

Very important to respect the DRY principle:
Dont
Repeat
Yourself

If you find yourself copy pasting something or writing something
repeatedly, then its time to stop and think about how to write it more modular.

#

Will save you literal hours of work

molten hearth
#

imagine

fluid river
#

bro

#

๐Ÿ’ฉ

crimson terrace
#

the fact that this constructor has like 20 parameters alone is weird, the repeating of getStats just makes it a little worse

fluid river
#

tho you can send stats to contructor

molten hearth
#

that

#

is a good point

#

lmao

fluid river
#

And use reflection

#

or enum

#

who knows

#

need deep understanding of your entire plugin

molten hearth
#

well I had it like this

#

i guess just passing getStats is better

crimson terrace
#

ye

untold jewel
#

Stupid question. I have default values in a config I want to appear if it doesnt contain "path" so I do getConfig().options.copyDefaults(true); but when I reload / restart server it just gives default values again after I changed and saved them

#

Probably easy solution just havent worked a whole lot with configs

hazy parrot
#

I want to appear if it doesnt contain "path"
what does this mean

untold jewel
#

like if someone removes the path so path:
blabla:
blabla:

#

I want it to set the values agian

#

just so it cant be empty

eternal oxide
#

you set the default

hazy parrot
#

default will be used anyway

#

if not path is present iirc

eternal oxide
#

look on stash to see how bukkit does it for their config

untold jewel
#

But when I change something and restart the server it just sets the defaults agian

#

again*

eternal oxide
#

then you are not saving yoru changes

untold jewel
#

I am

eternal oxide
#

can;t be

#

you are doing it wrong

#

?stash

undone axleBOT
untold jewel
#

Obviously thats why I'm asking forhelp

tardy delta
#

"ResultOfMethodCallIgnored" iirc

torn shuttle
#

man as it turns out I have a lot of stalkers on spigot

twin venture
#

hi , so i have a kit system with permission per kit , so i have a problem if a player have a rank that it depend on another rank , [this 2 rank have diffrent kits] , he will receive both

#

how would i give him the kit that is the same as his rank

hazy parrot
molten hearth
#

alright I refactored half my code to use enums thats a few hundred lines gone

molten hearth
molten hearth
torn shuttle
#

seems like necroposting mr choco lyrics is taking off

echo basalt
#

oh that

#

funny thing

#

last guy that posted is my homie irl

torn shuttle
#

yeah hard to know which part of your extensive stalking activities I was referring to right

echo basalt
#

I actually had your page open when you sent that message

#

was checking my notifications lol

torn shuttle
#

I think my beard game has leveled up

#

I have reached a new power level

#

a supersayan +2 if you will

torn shuttle
#

merlin wishes he had a beard like mine

molten hearth
#

๐Ÿ˜‚

#

does HikariPool ever timeout

#

I can see [Ms-TickScheduler] [15:58:28] (HikariDataSource.getConnection) - INFO - HikariPool-1 - Starting... [Ms-TickScheduler] [15:58:29] (HikariPool.checkFailFast) - INFO - HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@22d59864 from my old logs but now im unable to connect and all I see is [Ms-TickScheduler] [16:05:23] (HikariDataSource.getConnection) - INFO - HikariPool-1 - Starting... so im assuming the db died but doesn't hikari timeout or smth

#

meh there's hikari.setLoginTimeout(5); I guess that works

twin venture
#

this is my problem

#

do you know why this hapening ?

#

dosen't happend on my test server

molten hearth
#

yes

#

somewhere the network sucks

twin venture
molten hearth
#

well something is taking ages to respond (it could be due to a firewall as well)

eternal oxide
twin venture
twin venture
molten hearth
#

well did you configure mysql & iptables correctly

#

oh

twin venture
#

and after that this the bug happens .

eternal oxide
#

are you certain the ports are open>?

twin venture
eternal oxide
#

remote SQL is never a good idea. Too slow

mighty pier
twin venture
eternal oxide
#

if you cna connect to the sql its possible you are running out of connections

#

using batch updates consumes them really fast

fast onyx
#

Hello! I'm trying to teleport a player to the projectile location on ProjectileHitEvent, however it seems to teleport to the inverse yaw and pitch; how I can rotate the vector 180deg to literally teleport to the opposite position? (Already tried getting the vector and multiplying it for -1 and 2, as i saw on a random forum)
Thanks.

fluid river
#

vector.multiply(-1);

#

xD

#

tho gonna rotate entire vector

fast onyx
fluid river
#

what exactly is happening?

fast onyx
fluid river
#

right X Y Z but wrong Yaw Pitch

fast onyx
#

not "wrong", just that i want to "invert it"

fluid river
#

tho in projectile hit event shouldn't velocity be 0?

eternal oxide
#

use getDirection() not velocity

fluid river
#

try setting player YAW PITCH from projectile.getDirection()

#

basicallyjava player.getLocation().setDirection(projectile.getLocation().getDirection())

#

smth like this

#

?di

undone axleBOT
fluid river
#

@civic wind

fast onyx
#
Vector vector = projectileLocation.getDirection().multiply(-1);
player.getLocation().setDirection(vector);
fluid river
#

you don't need to multiply it now tho

fast onyx
#

oh yeah i forgot that part, my bad

#

๐Ÿ’€

fluid river
#

why don't you just teleport player

#

directly to projectile location

#

player.teleport(projectile.getLocation());

fast onyx
#

tried that before, and the "problem" happens xD

fluid river
#

that shouldn't affect yaw pitch tho

#

it just copies YAW and PITCH from projectile direction

#

@noble lantern what's with this guy's hair

#

tho arrow might bounce from block

fast onyx
fluid river
#

ye

fast onyx
#

yeah with that the "problem" happens

#

just want to invert yaw and pitch

fluid river
eternal oxide
#
player.teleport(projectileLocation.setDirection(projectileLocation.getDirection().multiply(-1)));```
fluid river
#

unbeatable

eternal oxide
#

you would be better to maintain the players yaw/pitch though

#

not use the projectiles

#

projectiles can bounce or hit top of a block etc

fluid river
#

Why is location so strange tho

#

setters return Location object

#

what's this pattern name

#

looks kinda like builder

#

append().append().build()

crimson terrace
crimson terrace
#

its not a design pattern imo, its a design choice

eternal oxide
#

then don;t use the projectile direction

fluid river
#

but really looks like copypaste of builder

fast onyx
crimson terrace
#

the builder pattern does exist, its probably a variation of it

fluid river
#

yeah

hazy parrot
fluid river
#

that's what i think about

hazy parrot
#

Or fluent interface

eternal oxide
#
player.teleport(projectileLocation.setDirection(player.getLocation().getDirection()));```
fluid river
#

well the only problem is that you usually need Location.clone

#

cuz it's half static half non-static

#

strange class

#

Don't like how bukkit made it

#

the cringest thing is it's basically copying lots of public methods from world

#

which you anyways pass to constructor

#

Maybe they wanted to make it fully static but then changed opinion

fast onyx
#

thanks!

round finch
#

any way i can make it show more infomation?

eternal oxide
#

It only shows what the javadocs say. but you can click the icon before teh name to open teh actual doc

round finch
eternal oxide
#

yes, click the icon top left

#

should open teh class for you

round finch
#

ok! i were just confusing myself i believe

#

thought there wasn't enough details for me

#

but thank you for saving me โค๏ธ

#

with this mess

civic wind
#

Does anybody have experience with text components and hoverable/clickable messages? I've been following a course on udemy about bukkit and thought it would be cool to try this but it doesn't seem to be working. This is one of the ways demonstrated in the course... :/

round finch
#

full error stack?

civic wind
#

Sorry,

hazy parrot
#

what is your dependency

civic wind
#

It didn't say i needed a dependency for it?

hazy parrot
#

you obv need spigot dependency for making spigot plugin

round finch
#

his instance is probably null

hazy parrot
#

I mean, its class not found

civic wind
#

I think i worked out why

hazy parrot
civic wind
grizzled steeple
#

Hello can anyone make me a panel (minecraft hosting)

civic wind
grizzled steeple
#

(๏ฟฃใƒ˜๏ฟฃ๏ผ‰แดดแดนแดน

round finch
#

do you mean your own panel?

#

like making your own host

grizzled steeple
#

nah on petyocry or smth

civic wind
grizzled steeple
grizzled steeple
civic wind
round finch
#

what your main plugin class?

grizzled steeple
grizzled steeple
civic wind
pseudo hazel
civic wind
hazy parrot
civic wind
hazy parrot
civic wind
fluid river
hazy parrot
fluid river
#

gradle build

#

or just export

round finch
#

onEnable please?

#

lemme see

vast raven
#

with @Ovveride?

fluid river
#

onDisable thanks

round finch
#

and that too

fluid river
civic wind
#

Then I just 'build artifact' and export to saved file destination

fluid river
#

Zombie z = ...;

#

z.set...

civic wind
fluid river
tardy delta
#

dont buld artefact

#

^^

civic wind
#

Ahh

tardy delta
#

fucks up dependencies

civic wind
#

Ah i see, thanks

fluid river
#

hello brush

tardy delta
#

man making snake lol

civic wind
#

I should google how to compile with maven? Never done it

fluid river
tardy delta
#

you should have a maven tab on the right

hazy parrot
#

if ij

tardy delta
#

double ctrl*

fluid river
#

call me

#

i'll show

hazy parrot
tardy delta
#

cant speak lol

hazy parrot
fluid river
round finch
fluid river
#

no vc

tardy delta
#

join general 1 or whatever

#

brrrrr

#

little kids hmm

fluid river
#

basically run .jar

tardy delta
#

how am i supposed to move

fluid river
#

A D

civic wind
#

What does "invalid target release: 1.8.0_202" mean?

fluid river
#

Basically try to avoid hitting the walls

tardy delta
#

ah just ad

fluid river
#

they have fixed bounce velocity

tardy delta
#

well done

fluid river
round finch
#

how do you work with mns and maven?

#

i heard something about mojang mappings?

#

but i never done it before

fluid river
#

umm

#

when running buildtools use --remapped

#

tho you just need to add NMS dependencies as far as i remember

civic wind
#

Anyone? Maven giving me errors

round finch
#

like maven docs?

fluid river
#

there is mojang map which binds a,b,c,d and other methods to their real names

tardy delta
fluid river
#

on the internet

fluid river
#

well actually look at it

round finch
tardy delta
#

lol

fluid river
#

find my code where i get PP length

tardy delta
#

decompiled code always shitty

fluid river
#

it's shitty in general

round finch
#

heyyo advanced binary code? xd

sterile token
#

How do you usually name artifactId for a multi module project?

Parent: parent-<project-name>
Modules: <project-name>-<module-name>

tardy delta
#

mhh gui code always shitty

fluid river
#

I used images instead of buttons

#

and checked coordinates of cursor

round finch
sterile token
#

Why!

fluid river
#

@old jay helped me draw buttons

tardy delta
#

dont even want to make smth gui based in java

fluid river
fluid river
civic wind
fluid river
tardy delta
tardy delta
#

and who cares lol

round finch
#

i like that very detailed and clean tut

civic wind
fluid river
#

open project settings send screenshot

#

are u using right jdk

civic wind
tardy delta
#

what java version in pom?

civic wind
tardy delta
#

ah

civic wind
#

am i using right jdk?

fluid river
#

remove <configuration> section

#

or replace ${java.version} with 17

#

everywhere

civic wind
#

ah it's done it, thanks

#

Does interactentityevent register two clicks ?

#

It's double clicking, or is my mouse broke lol

eternal oxide
#

?hands

#

?hand

glossy venture
#

pretty sure it calls twice for the hand and off hand

eternal oxide
#

?handed

lost matrix
glossy venture
lost matrix
eternal oxide
#

there is a command

glossy venture
#

no

lost matrix
#

?twohands

tardy delta
#

a player does have two hands

lost matrix
#

?handy

civic wind
#

damn how can i make it only once?

tardy delta
#

lmfao

lost matrix
#

?interact

civic wind
#

I checked for item in main hand

tardy delta
#

only listen for event.getAction() == Action.RIGHT_CLICK or smth

eternal oxide
#

they make the stupidest of commands. Can never remember them

tardy delta
#

or left whatever

lost matrix
tardy delta
#

?workloaddistro kinda stupid one too

tardy delta
#

smh

lost matrix
tardy delta
#

i even forgot it you see

untold jewel
#
 //check if the action is right_click
        if(event.getAction().toString().contains("RIGHT")) {
}
tardy delta
#

::getHand

civic wind
#

I've checked for click, it all works, it's double clicking though

tardy delta
#

imagine interacting an entity with your legs

civic wind
#

lol

lost matrix
#
  @EventHandler
  public void onInteract(PlayerInteractEvent event) {
    ItemStack usedItem = event.getItem();
    if(!this.freezeHandler.isFreezingTool(usedItem)) {
      return;
    }
    // Freeze target here
  }
river oracle
civic wind
#

if (!e.getHand().equals(EquipmentSlot.OFF_HAND)) return;

#

This should work?

untold jewel
#

ItemStack itemInHand;

try {

itemInHand = player.getInventory().getItemInMainHand();
} catch (Exception ex) {

}```
lost matrix
untold jewel
#

No

eternal oxide
#

?interactevent

undone axleBOT
#

The PlayerInteractEvent may be called once per hand. If you only want code to be executed once, you can check the result of https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerInteractEvent.html#getHand(), then decide functionality.

For example, only executing code if the main hand was used:

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getHand() != EquipmentSlot.HAND) { // * if the hand used is NOT the main hand:
        return; // do not progress past this point  |
    }
    // provide functionality
}
eternal oxide
#

I remembered

lost matrix
# eternal oxide ?interactevent

There we go. But my approach supports a freezing item in both hands.
You could as well just only support the main hand with the slot safeguard.

#

Either way is viable

tardy delta
#

putting return in {} ๐Ÿ’€

lost matrix
#

Yes. Clean code all the way.

#

I get the urge to just return in the same line but its technically not clean.

tardy delta
#

i always return in the same line, except for returning actual values

#

if (event.getHand() != EquipmentSlot.HAND) { return; } those people are just evil tho

sterile token
#

I need some help trying to load a classes from a jar

civic wind
sterile token
#

I mean dont know where to start coding it

#

Because my goal is to make a simple loading system like does spigot

tardy delta
#

wait wha

sullen wharf
#

ah yes get_name

sterile token
#

ok

sterile token
#

๐Ÿค”

round finch
#

is CraftInventoryPlayer still a thing in 1.18.2?

chrome beacon
#

Probably

sterile token
# tardy delta wha

First of all i need to scan the jar, looking for a json file and get the field main (which keeps the main class)
Second load only that class to the JVM and check if it extends my custom Extension class
Finally if first and second phases are okay, load the rest things from the jar

#

Is it a good design?

tardy delta
#

so youre first looking for a json file with the main class name in?

sterile token
#

Yes

#

That i know how to do it

tardy delta
#

good enough ig

#

then read that file and use Class::forName?

sterile token
#

I mean i just need to use JarEntry and other related things to reading the jar

#

The main issue come to only load the main class into the JVM

#

Because URLClassLoader load the full jar/file not only a specific class

tardy delta
#

this maybe?

#

never done it before lol

#

and it your main class depends on other class in that jar, it makes sense to load them all ig

round finch
sterile token
#

Because i was thinking that doesnt make sense loading the full jar if then when i check the main class doesnt extends my custom class i just load it for nothing

tardy delta
#

dunno if loading the main class loads the classes that it uses tho

#

ig not

sterile token
#

Doesnt have translation

#

neither ig

zealous osprey
#

I wished you could do smth like this:

try (Reader input = new FileReader(filePath)) {
  // do stuff
} catch (Exception e) {
  // handle exception
} finally {
  input.close()
}```
instead of having to declare reader first as `null` so you can close it in the `finally` block
tardy delta
#

cant you?

river oracle
zealous osprey
#

ye, but for other thorwable methods, the reader was just a good example

river oracle
#

Pry much everything should auto close when defined like that can't think of any exceptions

zealous osprey
#

ยฏ_(ใƒ„)_/ยฏ

river oracle
#

Finally kinda useless

#

Unless you have some weird cleanup work but I've never had to use it

radiant umbra
#

Hello, im using https://github.com/hub4j/github-api and wanna download a jar file from a release in a private repo (download to a specific path). Right now im stuck on the downloading part, I get like an FileNotFoundException Error. Someone said I need to send like the OAuth Token as a bearer to authenticate? Btw: Im using java 8 so i cannot use HttpClient from java 11

glossy venture
#

is there a way to remap a port of a process using a ProcessBuilder or Process in java

#

lets say a process listens on port 2000 but i want it to actually open and listen on port 2001 on the host, without changing the configuration of the process

sterile token
radiant umbra
#

gonna try that

#

What should the request property be then?

sterile token
#

Wait

#

I write wrong code

#

I will do it using Intelij

#

1m please

radiant umbra
#

sure

sterile token
#

@radiant umbra

public static void main(String[] args) throws IOException {
        URL url = new URL("url here");
        HttpURLConnection client = (HttpURLConnection) url.openConnection();
        client.setRequestMethod("request method verb");
        client.setRequestProperty("Authentication", "Bearer token-here");
        client.setDoInput(true);
        client.setDoOutput(true);
        client.connect();
}```
#

There you have

#

For getting the responses you have to use the client.getInputStream() and for passing data use client.getOutputStream()

#

Sorry for ping its just for you to know that i answered

radiant umbra
#

Whats the request method verb?

sterile token
#

Could be GET, POST, PUT, DELETE

#

Github rest api have diff endpoints with diff request methods, parameters, etc

radiant umbra
#

alright, trying "GET"

sterile token
#

That should be specified on github api

#

I mean read about the endpoint you are trying to use it will tell how to use it, the parameters, etc

radiant umbra
#

and then can i download it with Files.copy(client.getInputStream(), Paths.get("test.jar"), StandardCopyOption.REPLACE_EXISTING); ?

quiet ice
#

I'd not use HttpURLConnection as that one is prone to DNS issues from my experience, I'd rather recommend the http client lib built into java these days

radiant umbra
# sterile token <@498097438956191744> ```java public static void main(String[] args) throws IOE...

This doesnt work (file still doesnt found)

public static void download() throws IOException {
        URL url = new URL("https://github.com/ole1011/Newsc-master/releases/download/release/test.jar");
        HttpURLConnection client = (HttpURLConnection) url.openConnection();
        client.setRequestMethod("GET");
        client.setRequestProperty("Authentication", "Bearer [token]");
        client.setDoInput(true);
        client.setDoOutput(true);
        client.connect();
        Files.copy(client.getInputStream(), Paths.get("test.jar"), StandardCopyOption.REPLACE_EXISTING);
        client.disconnect();
    }
tardy delta
#

you can create a DateTime object or smth from a string afaik

remote swallow
#

wouldnt essentials code have something similar to that you could look at

round finch
#

Loading API from specific Folder location how so?

twin venture
#

hi , anyone know a fix for this ?
HikariPool-1 - Connection is not available, request timed out after 30002ms.

#

keep spamming this error .. after few minutes of server start

civic wind
#

For a combat tag timer, right now i have it for move event, for the timer to expire, but if a players stood still it will keep counting below 0 till the player moves. What better way could i do this?

crimson terrace
#

Gives you more control and a surefire way of calling your methods

#

The event only triggers when you move anything. If youre afk it doesnt

civic wind
crimson terrace
#

Ye, thats not the question tho

civic wind
#

Yeah, but if player isnt moving i'm saying

#

lol

crimson terrace
#

I say put it on a timer instead of an event

civic wind
#

I was going to check it with player coords?

crimson terrace
#

Thats what the move event does

tardy delta
#

dont call both ::contains and ::get too

civic wind
#

Why?

crimson terrace
quiet ice
#

.contains is loosely a .get call

#

You can just call .get and then do a null check on that

tardy delta
#

if (contains(k)) { get(k).whatever() } is redundant, call get and see if its notnull

quiet ice
#

Thus avoiding a get call

civic wind
#

Ah i see, does it really matter though or?

quiet ice
#

Though arguably outside of hot code it wont matter that much

crimson terrace
#

Does contains just do get and nullcheck? If so I agree, even tho its not too bad to do it

quiet ice
#

If you absolutely need to optimise something that is an easy way to get rid of a few opcodes

crimson terrace
#

Tbh contains makes the code more readable

#

So its a tradeoff

quiet ice
#

But I believe that JIT will optimise that method call away anyways as long as you are not using concurrent stuff

quiet ice
crimson terrace
#

Valid point on the optimization

zealous osprey
#
private static final Map<ShipType, List<Ship>> shipMap = new HashMap<>();
    protected Ship(int size, ShipType type, int coordY, int coordX, ShipDirection dir) {
        this.size = size;
        this.type = type;
        this.coordY = coordY;
        this.coordX = coordX;
        this.dir = dir;

        shipMap.computeIfPresent(type, (shipType, ships) -> { ships.add(this); return ships; });
        shipMap.computeIfAbsent(type, shipType -> List.of(this));
    }

Is there a better way of doing this?

quiet ice
#

How considering that the collection itself can be modified between .contains and .get JIT might actually not run

zealous osprey
quiet ice
#

Yeah, hashmap doesn't do a nullcheck on the value

crimson terrace
quiet ice
#

CHM probably does though

tardy delta
#

HashMap::containsKey and HashMap::get does exactly the same

quiet ice
tardy delta
#

oh just telling

quiet ice
#

Hashmap can store null values and null keys

#

So you are treading on very thin ice

fluid river
#
shipMap.compute(type, (var10001, ships) -> {
   if (ships == null) { ships = List.of(this); }
   return ships;
});```
hasty prawn
#

It can only store 1 null key right?

fringe hemlock
#

I thought a HashMap canโ€™t store Null keys

zealous osprey
fluid river
#

does he need mutable

quiet ice
#

Probably

#

And it wont add the new ship if the list already exists

fluid river
#

then never use my solution friend

zealous osprey
#

Ye, I need mutability

tardy delta
zealous osprey
fluid river
quiet ice
#

null value != null node

#

A node is a key -> value pair for reference

tardy delta
#

well ye i was more talking about performance actually

#

to not call both methods

quiet ice
#

Well then you are correct

#

Although the behaviour differs

tardy delta
#

why arent those methods generic tho

#

mye

fluid river
#

hey guys

quiet ice
#

(though for the reason we came to this discussion a null check on .get is actually better than a .contains call)

fluid river
#

void process(Object o) {} can basically eat every object right?

quiet ice
#

Object, yes

fluid river
#

what if i want the method to eat every object BUT not objects of Object class

quiet ice
#

At least until LWorld comes along - at that point I do not know

lost matrix
# civic wind

One could also use a functional approach

    Player player = event.getPlayer();
    UUID playerId = player.getUniqueId();
    Optional.ofNullable(combat.get(playerId))
            .map(cd -> cd - System.currentTimeMillis())
            .filter(remaining -> remaining / 1000 <= 0)
            .ifPresent(remaining -> {
              combat.remove(playerId);
              player.sendMessage("Something");
            });
quiet ice
#

Or T super Object idk

fluid river
#
void process(T extends Object o) {}``` would it look like this
#

is this even possible

tardy delta
#

T will always extend object

quiet ice
#

Yeah, LocalDateTimeFormat will do the trick

fluid river
lost matrix
tardy delta
#

uhh explain me

fluid river
#

the easiest solution is like if (o.getClass() == Object.class) return;

fluid river
#

which eats everything except Object

quiet ice
#

Does not exist

lost matrix
fluid river
#

oh true

#

i misread

quiet ice
#

Use DateTimeFormatterBuilder, which does actually work for parsing too

fluid river
#

what's this syntax lol

#

see for the first time

lost matrix
quiet ice
#

        new DateTimeFormatterBuilder().appendValue(ChronoField.SECOND_OF_MINUTE).toFormatter().parse("15");
lost matrix
fluid river
#

that object doesn't extend its own class

lost matrix
fluid river
#

i mean instanceof would return true

lost matrix
fluid river
#

I mean yeah you cant but

quiet ice
#

At runtime do

if (obj.getClass() == Object.class)
#

noonopjhoipy bnkvipsjkรถldhmzkj,
fj

fluid river
fluid river
#

cuz object is object

quiet ice
#

The answer is yes if you couldn't tell

tardy delta
#

so youre restricting an Object from being passed in?

quiet ice
#

If you meant what I hope you meant

fluid river
#

Didn't work tho

quiet ice
quiet ice
#

instead of extends Object

fluid river
#

i guess not technically possible

#

basically Object does extend itself xD

#

Somehow

#

weird oop i guess

#

i tried T super String and passed anonymous CharSequence

#

still not possible

#

not for typed method at least

quiet ice
#

I guess it's work If done through generics provided by class

#

Ie by ? extends Object

fluid river
#

so i guess the only real way is to use

#

if (o.getClass() == Object.class) return;

#

cuz objects do extend their own classes

#

for some reason

quiet ice
#

Mye

#

Signatures are only a recommendatikn anyways

#

Nothing the JVM/other Classes need to uihold to the letter

#

Hence the only safeguwrd is Javac itself

fluid river
civic wind
tardy delta
#

mmyes

fluid river
#

u

civic wind
#

I just did this for location (Don't hate on me if it's dumb i not really worked with tasks lol)

tardy delta
#

where early returns

twin venture
#

Hello :
Connection leak detection triggered for com.mysql.cj.jdbc.ConnectionImpl@2eac3147 on thread Thread-41, stack trace follows
java.lang.Exception: Apparent connection leak detected

fluid river
#

nested ifs go brrt

quiet ice
civic wind
fluid river
twin venture
civic wind
#

howcome?

#

"Why This is Bad. Deeply nested conditionals make it just about impossible to tell what code will run, or when. The big problem with nested conditionals is that they muddy up code's control flow: in other words, they make it just about impossible to tell what code will run, or when."

#

ahhh

quiet ice
tardy delta
#

i wish java had something like a LazyValue<T> which could be treated like a T instance but couldnt been computed yet ๐Ÿ˜ข

grim ice
#

im bored

civic wind
#

I'm tired

quiet ice
#

The temporal accessor Stores Your Seconds already

#

Just use the right chrono fields(s)

lost matrix
quiet ice
#

Yeah then use the instance millis chrono field

grim ice
#

is having a public static final map or set in a class that uses it, and for some other related classes to use it as well, static abuse

quiet ice
#

Or Epoch millis whatever you should get the gist

grim ice
#

just had to make sure

lost matrix
#

Prime static abuse even

civic wind
lost matrix
#

*If the map is immutable then the story is different

worldly ingot
lost matrix
#

Its used for fields only iirc

#

lateinit

onyx fjord
#

is anyone aware which animation ID golem uses for attack

twin venture
#

HELP : Connection leak detection triggered for com.mysql.cj.jdbc.ConnectionImpl@2eac3147 on thread Thread-41, stack trace follows
java.lang.Exception: Apparent connection leak detected

#

how i can fix this?

tardy delta
#

well basically want something like

LazyValue<Location> location = LazyValue.wrap(this::computeLocation);
location.setX(20);

so you can call methods on the object without knowing if it needs to be computed first or whatever

#

no need for null checks and stuff

grim ice
#

man i always read hikari as hikaru (as the chess grandmaster hikaru nakamura)

floral drum
tardy delta
#

atleast use a Set.of().stream().allMatch for that lol

floral drum
#

L @tardy delta

#

trolled

tardy delta
#

Set.of(flag1, flag2, flag3, ...).stream().allMatch(t -> t)

#

boolean b = 1 smh

#

would work in c++ ig

floral drum
#

so it doesn't have the orange underline

#

in the if ()

#

just why not error before it haha

grim ice
#

i kinda wanna learn csharp

#

for unity

#

but like

floral drum
#

aka this

grim ice
#

csharp just bothers me

floral drum
# grim ice but like

Instead of using network libraries, I decided to make networking for my game with sockets... WOOO

#

it was fun tho

tardy delta
#

time to play coc

floral drum
#

c#

#

unity

grim ice
#

is it worth learning

#

idk what i would make with unity tho

#

im kinda just bored

floral drum
#

For games development yes, and if you want to make simple-ish type games without being in a large company

civic wind
#

Damn it didn't work

floral drum
#

like it's good for beginning

#

no cap

#

I do games dev in college and we do Unity

#

I did start using unity when I was 11-12 tho

tardy delta
#

instead of get != null => remove check if remove

floral drum
#

18 now

grim ice
#

yeah idk

remote swallow
grim ice
#

im honestly just bored

floral drum
#

what the fuck

grim ice
#

i dont have an idea of what to do

#

except watching naruto

floral drum
#

bro I don't make babies, I get no girls ๐Ÿ˜ญ

grim ice
#

which idk why im doing ๐Ÿ’€

floral drum
#

I'm not a baby boomer!

civic wind
#

i'm 21....

tardy delta
#

?

civic wind
floral drum
undone axleBOT
floral drum
#

vouch

remote swallow
#

why do i need to learn java

#

other than needing to learn java

tardy delta
#
if (contains()) { remove() }
//is the same thing as
if (remove()) { // object is removed, do other stuff }```
floral drum
remote swallow
#

i confuse myself

floral drum
#

fairs

tardy delta
#

actually its if (remove(key) != null)

#

confused it with hashset

floral drum
#

YO your toe bones are so fucking long wtf\

remote swallow
#

lmao

grim ice
#

im having an idea of like

#

something called routines

remote swallow
#

wanna know the dumbest thing i did like 3 or 4 months ago

grim ice
#

its a desktop startup that does a macro u record (routine) and select

floral drum
#

look at how long those bones are

tardy delta
#

that doesnt look exactly healty

grim ice
#

e.g u record a macro that launches chrome once ur device starts and youtube, as well as discord

floral drum
#

exactlyyy

remote swallow
#

i hate that that feels true

grim ice
#

then u can select it

floral drum
#

๐Ÿ˜ญ

remote swallow
#

anyone got an axe

tardy delta
#

should be working on java stuff but school gives me webdev appointments smh

floral drum
#

๐Ÿ˜ญ

#

it's realll

remote swallow
#

purple

#

do you have an axe

floral drum
#

yo

#

nah fam

remote swallow
#

get one or ill chef you up bruv

floral drum
#

wtf

#

fam you come down to birmingham

#

lmaooo

remote swallow
#

im in birmingham

floral drum
#

oh fuck

#

you got me

#

I'm near leeds

remote swallow
#

ill pull a map up one sec

floral drum
remote swallow
#

telling me to go to birmingham when your like 3 years away

#

looks like your just off the m1

floral drum
#

lol it's crazy tho that we think it's such a big distance

#

but people in america travel across states

remote swallow
#

takes days

floral drum
#

๐Ÿ˜ญ

remote swallow
#

i went to nottingham for a desk

#

took like 4 hours

floral drum
#

F

remote swallow
#

ikea had no large desks near me

floral drum
#

whatchu getting for christmas fam

remote swallow
#

debating on getting a new pc

#

one that actually has a gpu

floral drum
#

I getting new SSD Pog

keen basin
#

Why when I update the value in the scoreboard it adds a new line ?

remote swallow
floral drum
#

WD Black SN850 2TB gen 4 NVME m.2

remote swallow
#

look at you

civic wind
#

It's doing what i want it to do, but getting this error i need a null check right but where

civic wind
#

like if its null, do what?

remote swallow
#

can we get line numbers on that screenshot

zealous osprey
civic wind
keen basin
zealous osprey
civic wind
#

ahh yh kk

#

im tired and hungry, im being stupid af

zealous osprey
#

eat and take a short break, often helps

crimson terrace
#

I cant seem to figure out how to get rid of these boss bars. They appear when a mob which has a boss bar attached to it by my plugin is still alive when I stop the server completely. doesnt happen on reload

#

trying to handle it like this, its not working, the boss bar remains even when the method was called. The bottom part of the method is probably the one thats not correct --SOLVED--

wary topaz
remote swallow
#

i dont think its possible to fully reload your plugin by itself

tardy delta
#

?main

crimson terrace
#

you could make a method to reload all necessary values and clear all maps/lists

remote swallow
#

main.java doesnt even go to 55

tardy delta
#

whys everything public

wary topaz
#

oh wait let me reupload it

#

refresh

remote swallow
#

still last commit 14 hours ago

wary topaz
#

than what should I press

#

I tried "update project"

tardy delta
#

make a commit and push

crimson terrace
#

maybe wrong branch?

remote swallow
#

commit then press commit and push

wary topaz
#

comitted

crimson terrace
#

you have to push it to remote aswell

remote swallow
#

still no update

wary topaz
#

refresah

#

agiN

#

again

remote swallow
#

got it

wary topaz
#

53 and 54 are the main probloms

#
Bukkit.getPluginManager().disablePlugin(this);
        Bukkit.getPluginManager().enablePlugin(this);
remote swallow
#

they will just mark the plugin as disabled not actually turn it off

wary topaz
#

how can I reload the jar

remote swallow
#

depends, do you only need it for testing or just to reload some values in the pluign

wary topaz
#

for testing

#

its a local host

remote swallow
#

/plug reload pluginname --noconfirm

wary topaz
#

whats the difference between plugwoman and plugman

remote swallow
#

plugman is more resource intensive

wary topaz
#

ohhh

#

thanks

#

now I dont have to reload any more ๐Ÿ˜„

#

also another question, I have my alt+s keybinded to build the project, any way I can make it control s because when I set it to that it just doesnt work

#

I want it to do both

remote swallow
#

crtl s is probably mapped somewhere else

wary topaz
#

save and build

remote swallow
#

ill check one sec

wary topaz
#

also another question (lol) every time the plugin reloads is there a way I can add a 1 to the version in the .jar file and the console ([BetterCommand] version: 1.0.0)

#

wait not the jar file

#

nvm

#

just the console

wind blaze
#

may anyone tell me how to let code go off on exact times of the day? like everyday at 7 am for example

wary topaz
#

if (time == <interval>)

#

or switch (time){

#

something like that

remote swallow
wind blaze
#

like inbetween you mean

remote swallow
#

yeah

wind blaze
#

probs will yeah

remote swallow
unborn kiln
#

Can you go down a line for a gameprofile name like this?

wind blaze