#help-development

1 messages · Page 2166 of 1

eternal oxide
#

the reference to yoru plugins class which extends JavaPlugin

quaint mantle
#

wait someone mentioned about base64

faint harbor
#

I'll look into it, thanks

fallow violet
#

try it out?

fallow violet
#

im sorry :c

quaint mantle
#

im sorry :(

fallow violet
#

not u

crimson terrace
#

I've got a small problem with the Vector#rotateAroundY Method. I rotate the vector around y with that method by 360°/amount of locations. When I have 3 as the amount it spawns them right next to each other instead of spreading them around the location passed in.
Am I not understanding the rotateAroundY() method correctly?

eternal night
#

The method takes radians

humble tulip
#

radians yeah

crimson terrace
#

so instead of passing it the degrees I would pass in Math.toRadians(degrees)

humble tulip
#

u can use Math.toRadians to convert

crimson terrace
#

oh ok

eternal night
#

Or just use 2pi

#

Instead of 360

crimson terrace
#

thats fair

fallow violet
#

is 2pi a circle?

crimson terrace
#

ye

humble tulip
#

1 rad is pi

fallow violet
#

ohh

humble tulip
#

wait no

eternal oxide
#

in radians, yes

crimson terrace
#

1 pi is a half circle

humble tulip
#

1 radian is not pi

fallow violet
#

radians remember me on VALORANT

dense falcon
# eternal oxide the reference to yoru plugins class which extends JavaPlugin

And to check if it's with the if ? ```java
NamespacedKey key = new NamespacedKey(plugin, "shop-key");
ItemStack chestGUI = new ItemStack(Material.CHEST, 1);
ItemMeta meta_chestGUI = chestGUI.getItemMeta();
meta_chestGUI.getPersistentDataContainer().set(key, PersistentDataType.DOUBLE, Math.PI);
meta_chestGUI.setDisplayName("Shop");
chestGUI.setItemMeta(meta_chestGUI);

    PersistentDataContainer container_chestGUI = meta_chestGUI.getPersistentDataContainer();

    if (container_chestGUI.has(key, PersistentDataType.DOUBLE)) {
        double foundValue = container_chestGUI.get(key, PersistentDataType.DOUBLE);
    }
humble tulip
#

pi radians is 180 degrees

wanton remnant
#

Hello, how can I remove collisions between players and mobs? setCollidable() doesn't work and I tried with this:


        scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
        afk = scoreboard.registerNewTeam("afk");
        afk.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
eternal oxide
wanton remnant
#

yes Main.getInstance().afk.addPlayer(p);

crimson terrace
#

the Math.toRadians() works perfectly, thank you 😄

eternal oxide
#

No need to use a double though, just a byte is enough

#

less space

dense falcon
chrome beacon
eternal oxide
dense falcon
#

Alr.

chrome beacon
eternal oxide
#

If it exists then its your custom item

wanton remnant
chrome beacon
#

You can have a getter

#

?main

fallow violet
#

quick question: Is someone using the Threads function?

wanton remnant
eternal oxide
#

getters protect your fields. You can alter teh code behind a getter however you like, but the end point is always the getter

dense falcon
fallow violet
#

ew this space

eternal oxide
dense falcon
#

This part of the code is in a function.

dense falcon
#

Wdym.

eternal oxide
#

when you are setting the PDC flag, you need to put the meta back on the item after

#

getItemMeta() fetches you a clone of the meta that is on the item. Use setMeta to put the meta back after altering it

quaint mantle
#

Okay so I'm trying to make a harvester hoe and I'm running into a tiny issue here.

@EventHandler
    void breakCrop(BlockBreakEvent e) {
        Block block = e.getBlock();
        Player p = e.getPlayer();
        Location loc = block.getLocation();
        loc.setY(loc.getY() + 1);
        Block blockUp = p.getWorld().getBlockAt(loc);
        if (block instanceof Ageable) {
            Ageable crop = (Ageable) e.getBlock();
            switch (crop.getMaterial()) {
                case SUGAR_CANE:
                    if (blockUp.getType() == Material.SUGAR_CANE) {
                        ItemStack scane = new ItemStack(Material.SUGAR_CANE, 1);
                        p.getInventory().addItem(scane);
                        e.drop
                    }
                    break;
            }
        }
    }```
dense falcon
quaint mantle
#

This is the code, and whenever I break a sugarcane, it wont put 1 cane in my invenvory

quaint mantle
#

It's supposed to add a sugar cane into your inventory, but it wont.

eternal oxide
quaint mantle
#

Nope.

dense falcon
eternal oxide
#

yep

dense falcon
#

Ok I try.

eternal oxide
#

perfect

fallow violet
#

you are sure that its instance of ageable?

quaint mantle
#

It's a sugarcane.

#

When i break it, it doesn't drop anything.

dense falcon
#

Yeah thank you!

summer scroll
quaint mantle
tardy delta
#
Location loc = block.getLocation();
        loc.setY(loc.getY() + 1);

-> block.getLocation().add(0, 1, 0)

fallow violet
chrome beacon
fallow violet
#

just check if its instance of sugarcane?

quaint mantle
summer scroll
#

It is Ageable somehow

fallow violet
#

but its not working so its not

eternal oxide
#

Doesn;t list sugar cane

quaint mantle
#

brb in a sec

summer scroll
fallow violet
#

he check the block

#

not the blockdata

#

thats the problerm

#

do if (block.getBlockData() instanceof Ageable ageable) {

eternal oxide
summer scroll
#

yeah, so weird

fallow violet
#

its there

eternal oxide
#

ah, there is no Interface for Sugar cane

#

just a Material

summer scroll
#

i guess when sugar cane has reached maximum age, they will grow another sugar cane on top

fallow violet
#

^

tardy delta
#

fun

eternal oxide
#

Yes, but so does bamboo

summer scroll
#

but they have an interface

#

why is that xd

eternal oxide
#

Bamboo has an Interface adn is listed under Ageable

#

odd that Sugar cane doesn;t

#

Oh I see

#

nope, I don;t

fallow violet
#

so?

#

does it work with blockdata now or not?

summer scroll
#

bamboo is special, i guess

eternal oxide
#

No clue, must just be a legacy thing.

prisma osprey
#

Lagacy

summer scroll
#

oh bamboo have a leaves

fallow violet
#

?

summer scroll
#

ahh, now i got it

#

it should work with Ageable according to the javadocs

fallow violet
#

thats what i am saying

eternal oxide
fallow violet
quaint mantle
fallow violet
#

try this

quaint mantle
#

Okay so..

#

ohh okay

fallow violet
#

if (block.getBlockData() instanceof Ageable ageable) {

#

if you have an older java version use do if (block.getBlockData() instanceof Ageable) {

quaint mantle
#

Still does the damn thing, the problem is, it doesn't give me the item in my inventory..

summer scroll
#

Are you sure your code reached that?

fallow violet
#

try to debug your code

quaint mantle
#

it disabled the drop

#

so it has to reach it

humble tulip
#

Can u paste your entire listener

chrome beacon
#

?paste

undone axleBOT
summer scroll
#

i don't see any of your code that cancel the drop

chrome beacon
#

It's cut off at the end

#

I think

quaint mantle
fallow violet
#

lol please paste the whole code everytime

summer scroll
#

you're still comparing block with blockdata

quaint mantle
#

It errors when I try to get the block data.

#

Says that it cannot be casted.

fallow violet
#

what is the error?

#

?paste

undone axleBOT
quaint mantle
fallow violet
#

bro

quaint mantle
#

I use feather client to host my server, I cannot copy the error.

#

I know.

summer scroll
#

Change this part Ageable crop = (Ageable) e.getBlock();

#

You need to cast the BlockData not the Block

fallow violet
#

this is so annoying error

#

its so bad formatted

quaint mantle
#

I know.

#

They just added the server thing.

fallow violet
#

why you cannot copy?

quaint mantle
#

It doesn't let you.

summer scroll
#

Honestly, since you're on 1.18.2 just use pattern variable.

humble tulip
#

Cast the block data to ageable

#

ClassCastException

rough drift
#

Say I have an array of materials of length 50, if I wanted to get the item at percentage 50% it would get 25, this is my code:

int index = (int) (i / (max * materials.length));
index = materials.length - index - 1; // Reversing here since the array is in the opposite order (C B A)
return materials[index];

However its only getting the last 2 materials in the array regardless of percentage

fallow violet
humble tulip
#

What is max

#

And int?

eternal oxide
#

it is alwasy going to be teh last one as you are max * length)

quaint mantle
#

I'm using 17

rough drift
fallow violet
rough drift
fallow violet
#

^

humble tulip
#

Why don't u just do percent as double * length

#

Then subtract 1 for index

quaint mantle
humble tulip
#

Well don't use a pattern

#

Just cast after

quiet ice
fallow violet
#

^

rough drift
#
double i = 56;
double max = 2;
int arrayLength = materials.length; // 50
int index = (int) (i / (max * arrayLength)); // 56 / 100
index = arrayLength - i - 1;
#

that's what it's doing

humble tulip
#

What is i

rough drift
#

Its not relevant, you know it is a number from 0 to max * arrayLength - 1

summer scroll
# quaint mantle

Might as well update your Java since you're creating plugin for 1.18.2

humble tulip
#

So why is it 56

quaint mantle
#

Yeah I'm doing it rn.

summer scroll
#

noice

quaint mantle
humble tulip
#

If materials.length is 50

quaint mantle
#

Now it doesn't reach the code that it should execute.

rough drift
humble tulip
#

Why is i 56 then

#

What does i represent

rough drift
#

its not 50 btw

#

its 50 * 2

#

or 2 * 50

#

100

humble tulip
#

That's not what I'm asking

#

If you were to give i a more descriptive name

#

Wjat wpuld it be

#

Because it's not being used to iterate

rough drift
#

distance?

quaint mantle
#

@fallow violet I'll try to use the regular block check and not with instanceof ageable

rough drift
#

but yeah its distance from start you could say

eternal oxide
#

(length / 100) * percentageYouWant

fallow violet
#

you need the #blockData(); @quaint mantle

rough drift
#

(It ain't that, but its the closest explanation I can give)

rough drift
#

Just realized I am doing index to percentage

#

rather than backwards

quaint mantle
#

so it'd be
Ageable crop = (Ageable) e.getBlock().getBlockData();?

summer scroll
#

yes

fallow violet
#

yes finally

quaint mantle
#

Okay yeah I'm just a bit not okay, thx!

fallow violet
#

does it work?

#

nice

fallow violet
quaint mantle
fallow violet
#

<3

twilit roost
#

BungeeCord
Title Doesn't get send

            String title = ChatColor.translateAlternateColorCodes('&',args[0]);
            String subTitle = ChatColor.translateAlternateColorCodes('&', StaffChatCommand.getMessage(args,1));
            Title tit = createTitle(title,subTitle);
            for(ProxiedPlayer p : Main.getPlugin.getProxy().getPlayers()){
                p.sendTitle(tit);
            }
    public Title createTitle(String title,String subtitle){
        return Main.getPlugin.getProxy().createTitle().title(TextComponent.fromLegacyText(title)).subTitle(TextComponent.fromLegacyText(subtitle));
    }
chrome beacon
#

?main

chrome beacon
#

Also use a getter

fallow violet
#

its the code called to 100%?

#

did you debug it?

twilit roost
#

100%

#
            for(ProxiedPlayer p : Main.getPlugin.getProxy().getPlayers()){
                p.sendTitle(tit);
            }
            sender.sendMessage(prefix + "Odeslano!");
chrome beacon
#

Also make sure your getPlayers actually contains the players

twilit roost
#

the "Odeslano" is being send

fallow violet
crisp steeple
#

that kind of defeats the whole point

fallow violet
twilit roost
#

I used it like so cause it's static

tardy delta
#

Main.getPlugin???

twilit roost
#

but k
imma change it next time

fallow violet
#

yes

tardy delta
#

change it now lol

fallow violet
#

yes

twilit roost
tardy delta
#

?di

undone axleBOT
twilit roost
#

I don't see the difference in it

fallow violet
#

bro

#

you dont call a variable like a method

twilit roost
#

okk
but thats little off topic
any clues why it's not being send?

fallow violet
#

i have no idea

#

debug the whole code and the title

fallow violet
twilit roost
#

Solved:
forgot to set fadeIn stay and fadeout values

shell bluff
#

So If a tripwire hook is placed on a block and you break that block, the tripwire hook will also break. Is there any way to disable this update?

chrome beacon
#

Probably the BlockPhysicsEvent

summer scroll
#

BlockPhysicsEvent maybe?

#

im first

chrome beacon
#

No I'm first

eternal oxide
#

cancel the block break and break it manually without physics

quaint mantle
#

Okay so whenever you /restart the server, it auto stops it, is there a way to make it so it boots up automatically again ?

eternal oxide
#

configure teh start option in spigot.yml

shell bluff
#
@EventHandler
    public void onBlockUpdate(BlockPhysicsEvent e) {
        if(e.getBlock().getType() == Material.TRIPWIRE_HOOK) {
            e.setCancelled(true);
        }
    }

Tried this but it's not working, am I doing it correctly?

summer scroll
#

Maybe start with debugging the block

quaint mantle
#

and it opens up an empty cmd

fallow violet
#

._.

quaint mantle
#

am i just 0iq ?

eternal oxide
#

take off the ./

quaint mantle
#

ooih

eternal oxide
#

and be sure you actually have a start.bat

fallow violet
#

^

#

do you have one?

quaint mantle
#

Yeap, works now!

#

Thanks!

#

Just had to remove the ./

fallow violet
#

do you have it looping now?

#

automatic restart?

quaint mantle
#

Nope.

#

Just did the start.bat

fallow violet
#

alright

quaint mantle
#
java -Xmx8G -jar spigot-1.18.2.jar
PAUSE```
fallow violet
#

i make you one

#

the first 3 lines are optional

chrome beacon
#

Use Aikars flags also you don't need - on nogui

fallow violet
dusk flicker
#

You shouldn't have to lol

fallow violet
#

Nice tool

eternal oxide
#

This is mine ```bat
for /f "tokens=" %%a in ('dir spigot.jar /b') do set p=%%a

if defined p (
echo Starting Server... %p%
java -Xms1G -Xmx1G -Dlog4j2.formatMsgNoLookups=true -jar -DIReallyKnowWhatIAmDoingISwear "%p%" nogui
) else (
echo No Spigot found!
)```

#

allows me to just drop any spigot jar in and it is executed

summer scroll
#

can you make choosing java version automatically?

eternal oxide
#

I've not tried

tardy delta
#

is that shell or smth?

dark arrow
#
mobSpawnLoc.getWorld().spawnEntity(mobSpawnLoc.add(0,0,i),EntityType.ZOMBIE);```
dark arrow
crisp steeple
#

locations are mutable

dark arrow
#

?

crisp steeple
#

when you do .add(0, 0, i), it adds on to the last one

dark arrow
#

i know

#

but if i have to do it for all directions i have to write for everying possible directions player can looks

#

so is there any shorter method

crisp steeple
#

so you’re just trying to spawn zombies all around someone?

dark arrow
#

yrd

#

yes

#

at random distance

crisp steeple
dark arrow
#

i am bascally trying to summon my custom mobs around player

crisp steeple
dark arrow
#

i made a random variable and it summons it

crisp steeple
#

i’m assuming i is an index in a for loop?

#

oh

dark arrow
#

when the random number is equal to my number

crisp steeple
#

so i is a random number

dark arrow
#
 for(int i=0;i<51;i++){
                        Location mobSpawnLoc = player.getLocation().add(0,0,1);
                        if(random.nextInt(19)+1==4){
                            mobSpawnLoc.getWorld().spawnEntity(mobSpawnLoc.add(0,0,i),EntityType.ZOMBIE);
                            
                        }
                    }```
#

it will loop and add in i

#

if the random number matches it will spawn

#

otherwise it will skips

crisp steeple
#

ok

dark arrow
#

so it works find

#

i just want to do it for all directions

cold pawn
#

How do I get when a player clicks on a specific area on their screen? I want to make custom menus to the side of the players screen, I want to know when the player interacts with said menus.

crisp steeple
crisp steeple
dark arrow
crisp steeple
#

technically there’s 2 different clicks for the different sides of an inventory, but that’ll only work if you only need 1 different input option

#

and you would still need mods anyways for actually making a menu on the client

dark arrow
#
for(int i=0;i<51;i++){
                        Location mobSpawnLoc = player.getLocation().add(random.nextInt(50)+1,0,random.nextInt(50)+1);

                    }

                    }``` Like this?
crisp steeple
#

well that’ll only add it in 2 different directions since it’s not negative

#

try like ThreadLocalRandom.current().nextInt(-50, 50)

dark arrow
#

ok

#

it worked tysm 🙂

stiff jacinth
#

Does anyone know a good way to spawn random loot in chests?

dark arrow
#

one last thing since they are spawning at player y it may spawn them underground so is there any way to avoid that since i cant use get highest y

spiral hinge
#

Anyone know why this isn't sending anything to the player

player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b&ltest."));
eternal oxide
#

My guess, the player object is stale as they have relogged and you maintained a reference

eternal oxide
tardy delta
#

where is that player coming from?

dense falcon
#

Can we add, update or delete elements in config.yml?

chrome beacon
#

Yes

midnight shore
dense falcon
#

How?

midnight shore
#

from the main instance getConfig();

chrome beacon
#

#set(path, value)

dense falcon
chrome beacon
#

Yes

#

You should use UUID not username

#

Especially not the display name

tardy delta
#

i actually forgot but if i set something in the config and get it right after that without saving, will it return it or not?

eternal oxide
ornate heart
#

Any easy way to place a name tag/hologram above the player's head without using scoreboards?

sacred mountain
#

i mean you can but itll be a bit laggy i would think to have an armorstand tracking your position, unless theres a better way idk

ornate heart
#

I just really dislike using scoreboards but I may have to bite the bullet.

dense falcon
# eternal oxide ```java if (plugin.getConfig().contains("players." + player.getUniqueId()) {```

Yeah but if I want to do : ```java
if (plugin.getConfig().getString("players." + player.getUniqueId()) == null) {
plugin.getConfig().set("players." + player.getUniqueId(), null);
plugin.getConfig().set("players." + player.getUniqueId() + ".level", 0);
plugin.getConfig().set("players." + player.getUniqueId() + ".xp", 0);
plugin.getConfig().set("players." + player.getUniqueId() + ".kills", 0);
}

#

To get something like this: ```yml
players:
beyptitloup:
level: 5
xp: 600
kills: 120


And it did not work.
eternal oxide
dense falcon
#

It did not change.

#

No errrors.

left swift
#

What is the best way for publish my project (private) as dependency then use it with gradle or maven?

eternal oxide
left swift
#

I mean I used jitpack, but private repo requires the subscription on jitpack

dense falcon
#

It did not add the player.

eternal oxide
#

If you are wanting to update it, simply doin't test if it exists

dense falcon
#

players.Program132 does not exist. ^

eternal oxide
#

did you call save on teh config after adding it?

dense falcon
#

Ah no?

#

plugin.saveConfig() ?

eternal oxide
#

Thats probably a good thing to do then 🙂

#

yes

humble tulip
#

If i wanna backup mysql to a sqlite db should i just select * from table

dense falcon
#

Alr.

#

I did not know, thanks.

humble tulip
#

Have a preparedstatement for the sqlite db and keep adding to batch for every result inthe resultset?

dense falcon
#
        String message = event.getMessage();
        Player plr = event.getPlayer();
        event.setCancelled(true);
        Bukkit.broadcastMessage("[" + plugin.getConfig().getString("players." + plr.getUniqueId() + ".rank") + "]" + "<" + plr.getDisplayName() + "> " + message);
``` We can check if the event come from a command (this event is AsyncPlayerChatEvent in this case).
crimson terrace
#

How do people usually manage GUI configuration? I'm having trouble imagining how to keep track of what the player clicked on after theyve gone through like 2 or 3 inventories

tall dragon
crimson terrace
#

for instance when I have a config which contains multiple of basically the same thing, like entity types and I want them to be able to configure that with a gui. for simplicity I would need one inventory which would let them choose the entity type to configure, then one to choose which setting to edit and then one where they can actually edit the setting. Would I make an object where I save those things and save it to a map keyed to the UUID?

rotund ravine
dense falcon
#

It works.

quaint mantle
#

just for a fun comparison, two types of packets sent to players. A packet of a changed itemstack and a packet of a moving armorstand, which one would be more intensive?

patent horizon
#

what's the best way for me to store various custom items that could be fished up? I was told yesterday to save a class instance into a map for each item, but i'm not sure how flexible that system is for items that require metadata

sacred mountain
#

Hello what does system.currentitmemillis return and how would i go about converting it to different time units

#

i know it's simple multiplication, but i'm not sure what the output is like

fallow violet
#

it returns the current datetime in a long

#

its like a long number

sacred mountain
#

unix?

fallow violet
#

and you can make a date of it by using new Date(long);

eternal night
#

Well yes currentTimeMillis returns you the machines current unix time

elfin atlas
#

Does someone know if there is a way to listen to Packet that the server is sending to the clients?

worldly ingot
#

ProtocolLib has outgoing packet listeners iirc

elfin atlas
#

But also for Packets from Server to Client?

fallow violet
#

that is outgoing

dark arrow
#
 while(mobSpawnLoc.subtract(0,1,0).getBlock().getType()==Material.AIR){
                            mobSpawnLoc.add(0,0.5,0);
                        }```
This code checks if the block below the zombie is not air if it is then is subtracts the cords to avoid fall damage but it suffocates them instead
crisp steeple
#

unless you mean on the client

eternal oxide
crisp steeple
eternal oxide
#

any air under teh zombie will move the loc up half a block

crisp steeple
#

so it ends up in a net value of -0.5

tender shard
#

and after that the loop runs once again setting the location to 1 below

crisp steeple
#

try adding .clone() to the condition

eternal oxide
#

actually, yes it will move it down half a block

#

you subtract, so that modifies the actual location

tender shard
#

it moves it down half a block as long as there is air and then when there's no air anymore, it removes 1 again

dark arrow
#

ok so it does the jobs now but i got 2 more problem they spawn half submerged and if i am in big cave then they fall from roof

tender shard
dark arrow
#

avoid them to spawn in air

#

it spawn at players y cords

#

so if player is at higher location

#

then they all just spawn in air

#

and i cant use get higest block

#

since it will only work at surface

crisp steeple
#

well these are kind of 2 contradicting goals here

tender shard
#

and why can't you just keep removing 1 from Y until there is no air anymore?

eternal oxide
#
while(mobSpawnLoc.getBlock().getType().isAir() && mobSpawnLoc.getBlockY() > mobSpawnLoc.getWorld()getMinHeight()){
    mobSpawnLoc.subtract(0,1,0);
}
mobSpawnLoc.add(0,0.5,0);```
tender shard
#

also use .isAir instead of ==AIR

#

otherwise you will experience this "falling from the roof of caves" thing

dark arrow
#

ok

#

works life a charm 🙂

#

thanks

vague swallow
#

If a player has opened his inventory and my plugin executes p.setItemOnCursor(ItemStack); then it's not working but if the player closes his inventory the item get's dropped

#

Does anyone know why or how I can fix it?

eternal oxide
#

Improved so it stops at zero

humble tulip
tender shard
eternal oxide
#

ah true

sacred mountain
tender shard
eternal oxide
#

I forgot world heights changed

tender shard
sacred mountain
#

there is? oh

#

well i guess for the BEST vaule

tender shard
#

in java its builtin

#
TimeUnit.DAYS.convert(123456789, TimeUnit.MILLISECONDS);
#

this converts 123456789 milliseconds to days

#

sure you still have to do the "Best" part

#

i just wanted to mention that converting between all those units is builtin

humble tulip
#

What do you mean by "best"?

tender shard
#

probably 1000 milliseconds would be 1 second while 60,000 would be one minute

#

and 998151259125762156 would convert it to the longest period, days in this case

humble tulip
#
@Override
    public String format(double value) {
        int seconds = (int) (value / 1000) % 60;
        int minutes = (int) ((value / (1000 * 60)) % 60);
        int hours = (int) ((value / (1000 * 60 * 60)) % 24);
        int days = (int) ((value / (1000 * 60 * 60 * 24)));
        String time = "";

        if (days != 0)
            time = days + " day" + (days == 1 ? "" : "s");
        if (hours != 0)
            time = time + (time.equals("") ? "" : " ") + hours + " hour" + (hours == 1 ? "" : "s");
        if (minutes != 0)
            time = time + (time.equals("") ? "" : " ") + minutes + " minute" + (minutes == 1 ? "" : "s");
        if (seconds != 0)
            time = time + (time.equals("") ? "" : " ") + seconds + " second" + (seconds == 1 ? "" : "s");
        return time;
    }
#

There's probably a better way to do that

#

@sacred mountain

void shale
#

Is it possible to add delay to item usage when i right click my custom item with right click, like enderpearl?

#

where it even shows that delay animation

tender shard
#

you can only set cooldowns for the whole material

#

at least if you want to show the animation

void shale
#

well i use paper for that so i guess it would work even if it was whole material cause paper dont have any action in default minecraft

#

how would i approach that then?

tender shard
#

I got no idea what you're talking about regarding paper now

#

oh you mean the material

#

player.setCooldown(Material.PAPER, 20)

#

that would mean a paper has a cooldown of 1 second

river oracle
#

Cooldown on material aye very interesting lol

void shale
#

that would stop PlayerInteractEvent from firing when i right click it right?

tender shard
#

probably it won't stop that event from being called

Set a cooldown on the specified material for a certain amount of ticks. ticks. 0 ticks will result in the removal of the cooldown.
Cooldowns are used by the server for items such as ender pearls and shields to prevent them from being used repeatedly.

Note that cooldowns will not by themselves stop an item from being used for attacking.

#

you'll just have to try it out

red sedge
#

is there anyway to get the amount of ticks passed since start

tender shard
#

start of what?

void shale
#

oh i see, i want to use this for my paper which works like special teleport scrolls with nbt data, sometimes it eats 2 "scrolls" on holding mouse too long or server lag or smth, or so my players told me

red sedge
#

server/plugin

void shale
#

so i would add little nice delay with this and it would prevent that from happening and would have nice little delay so people would not spam them for lag or smth

tender shard
# red sedge server/plugin

sure.

            final Field currentTickField = Bukkit.getScheduler().getClass().getDeclaredField("currentTick");
            currentTickField.setAccessible(true);
            final int currentTick = currentTickField.getInt(Bukkit.getScheduler());
void shale
#

well i will try it thanks, i will report my results

tender shard
#

do a Map<UUID,Long> that stores when a player last used the item

#

if they use it again, check if their timestamp is at least 1 second old

red sedge
#

ig i can start a repeating task at the start?

tender shard
tender shard
# void shale well i will try it thanks, i will report my results

I'd create a Cooldown class, like this or sth, idk havent tested, I wrote it in textedit

public class Cooldown {
    
    private final Map<UUID,Long> lastUsages = new HashMap<>();
    
    public void setCooldownNow(OfflinePlayer player) {
        lastUsages.put(player.getUniqueId(), System.currentTimeMillis());
    }
    
    public boolean hasCooldown(OfflinePlayer player, double seconds) {
        long lastValue = lastUsages.computeIfAbsent(player.getUniqueId(), __ -> 0L);
        long minDelay = (long) (seconds * 1000);
        return System.currentTimeMillis() - lastValue < minDelay; 
    }
}
#

so when a player uses your item, check if they hasCooldown(player, 0.5)

#

for 0.5 seconds

#

if it returns true, they cant use the item

#

if it returns false, use setCooldownNow to start a new cooldown from now on, and do your custom item code

robust zenith
#

Hi everybody, thanks for the patience reading this... I am new in creating plugins and now I have problems the setnodamageticks... i am just trying to do a "NoHitDelay" remake but also i want to customize the knockback for every hit.
The event listeners I am using is "EntityDamagedByEntity" but i don't know why the setNoDamageTicks completely disappeared and also if i want to take player entity by a command like Player p = (Player) sender; that's not working and this gave me variable like error....
Could you help me please?

fallow violet
#

please send your error and your classes

#

?paste @robust zenith

undone axleBOT
robust zenith
#

how can i respond with code? I just paste here the link?

fallow violet
#

yes

robust zenith
#

ok

fallow violet
#

alright

#

i need your error

robust zenith
#

error is this in red by intellij : "cannot find symbol"

fallow violet
#

i see

robust zenith
#

and if i click on the error this returns me to "p"

fallow violet
#

alright

#

first

#

You cast your Sender to a Player. Which is good. But you must do this AFTER the check, if is is a player. Right?

quaint mantle
#

Is there something like #BlockData that checks if a crops is placed by a player ?

fallow violet
robust zenith
#

so i have to repeat again if sender instance of player?

fallow violet
#

nah

#

wait

#

can you make a thread?

robust zenith
#

nope

fallow violet
#

in discord?

quaint mantle
#

Hi everybody thanks for the patience

#

?paste

undone axleBOT
void shale
#

thanks for that too

#

apparently it doesnt stop the action but it also has method getcooldown(material) so it worked

granite owl
#
if (pdc.has(nKey, PersistentDataType.INTEGER))
``` whats the return value if the given namespaced key is existent but is of datatype string?
#

This method will only return if the found value has the same primitive data type as the provided key.

#

will only return true*?

granite owl
#

in the console?

tender shard
#

well in the code lol

granite owl
#

so it can not handle other data types than the provided at all?

#

why

tender shard
#

huh wdym

granite owl
#

so

tender shard
#

of course you can create new datatypes

#

but if you same something as integer, of course you cannot read that one as string

granite owl
#

xD

#

what i mean is only

#

if i provide this key

quaint mantle
#

Hi, i needed disable Item move in my inventory / on lobby => dm me and solve it please 😉

tender shard
#

you have to understand how PDC types work. They have two generic attributes, which are T and Z. The T is the "stored" primitive data class and Z is the "complex" data class.

E.g. if you store an itemstack as byte[] then you can only read it using other PDC types that also use byte[] as primitive type

granite owl
#
if (pdc.has(new NamespacedKey(this, "version"), PersistentDataType.INTEGER))
``` -> and the object has a value of the namespaced key plugin:version but it is of type String, can the api handle this and return false or will it throw errors?
tender shard
#

all the builtin data classes map the complex to the primitive type

granite owl
#

and how do i actually typecheck it then

#

cause pdc doesnt offer a method for that

tender shard
#

you can only "mix" datatypes if the first class inside <...> matches

granite owl
#

so

#

how do i pre-check the data type of that value

#

before i compare it using .has()

#

i just need the proper error handling for this

#

because i didnt see in the api how to prevent data type violations then

tender shard
#

I wonder why you would EVER need it though

undone axleBOT
tender shard
#

after all you know what datatypes you use yourself

granite owl
#

1st. iirc u can use cheats to inject nbt tags

#

2.nd what if items deprecate

#

and i use different data types after years

#

for example

#

im asking in advance for longlivibility

#

before

#

i dork it

tender shard
#

line 136

granite owl
#

i see that

#

its frustrating

#

why is it not just returning false by default

tender shard
#

how would that work lol

#

if you use String as datatype, how would that ever be "false"

#

a String can't be false lol

granite owl
#

if pdc key is either not found or of illegal data type return false

#

only return true if its found and legal

tender shard
#

bruh as said

#

you cannot return false when you declare it to return <T> and T is String in this case

#

how would that work?

granite owl
#

but .has() is a primitive bool?

tender shard
#

oh you're talking about the has method

granite owl
#

all the time lol

#

xD

tender shard
#

yea that will return false if the datatypes mismatches

granite owl
#

thats what ive asked all the time xD

#

thats why i was so confused

#

obviously itll throw an error if i try to get the wrong type

tender shard
#

well why didn't you just read the docs then lol

granite owl
#

i did

#

and it was documented confusingly

tender shard
#

it's the second sentence in the docs

granite owl
#

return what

#

xD

#

return ....

#

will only return if type is matched

#

and waht else?

#

crash?

#

and dont get me wrong im not trying to be anoying on purpose

#

just saying RecipeChoice.ExactChoice and shapeless recipes

#

xD

#

btw

#
public boolean setItemInteger(String key, int value)
    {
        if (this.is != null)
        {
            if (this.is.hasItemMeta())
            {
                ItemMeta meta = this.is.getItemMeta();
                meta.getPersistentDataContainer().set(new NamespacedKey(main.getPlugin(main.class), key), PersistentDataType.INTEGER, value);
                this.is.setItemMeta(meta);
                return true;
            }
        }
        
        return false;
    }
    
    public int getItemInteger(String key)
    {
        if (this.is != null)
        {
            if (this.is.hasItemMeta())
            {
                PersistentDataContainer pdc = this.is.getItemMeta().getPersistentDataContainer();
                NamespacedKey nKey = new NamespacedKey(main.getPlugin(main.class), key);
                
                if (pdc.has(nKey, PersistentDataType.INTEGER))
                {
                    return pdc.get(nKey, PersistentDataType.INTEGER);
                }
            }
        }
        
        return -1;
    }
tender shard
#

yeah the javadocs are fucked up

granite owl
#

this is what im working with

#

and thats why ive asked

#

if this is typesafe

tender shard
#

also the @returns sentence is not a complete sentence lol

granite owl
#

^^

tender shard
#

idk lol

granite owl
#

basically i wanted to know if this is type safe

granite owl
#

so .has is safe to use on illegal types just returning false?

tender shard
#

yes

granite owl
#

kk

tender shard
#

but as said it ONLY compares the primitive type

vague swallow
#

Does anyone know how to get the int of the selected hotbar slot of a player?

tender shard
#

if you have for example a custom data type that uses String as primitive type, then checking for String will return true even when it's actually you custom data type, and vice versa

granite owl
#

yea thats cool if i work with complex types i always serialize them and store them as bytestream anyway

#

then i write the handling methods myself

granite owl
#

but since im still more used to C i use primitives most of the time tbh xD

granite owl
#

getHeldItemSlot(), getItemInMainHand(), getItemInOffHand()

#

i prefer in main hand

#

if i wanna explicitly use the hotbar one

sacred mountain
granite owl
#

btw whats the standard convention for functions like this

#
public int getItemInteger(String key)
    {
        if (this.is != null)
        {
            if (this.is.hasItemMeta())
            {
                PersistentDataContainer pdc = this.is.getItemMeta().getPersistentDataContainer();
                NamespacedKey nKey = new NamespacedKey(main.getPlugin(main.class), key);
                
                if (pdc.has(nKey, PersistentDataType.INTEGER))
                {
                    return pdc.get(nKey, PersistentDataType.INTEGER);
                }
            }
        }
        
        return -1;
    }
#

returning -1, 0 or null?

#

in java*

#

xD

#

if not found*

ivory sleet
#

I like to return OptionalInt in case the result does necessarily not return an int

granite owl
#

so a wrapper that contains the info?

ivory sleet
#

It just wraps an int mye

#

But else there’s no convention

tender shard
ivory sleet
#

sometimes 0 but if 0 belongs to the solution set your function returns then -1 might be a better alternative

granite owl
#

just asking cause like in C -1 represents a fatal error, 0 represents correct execution xD

tender shard
#

I'd use an OptionalInt or Integer. Probably OptionalInt is better since returning Integer, people could still store it as int ebcause auf auto-unboxing and then get NPEs

granite owl
#

however none of my functions can use negative values but i cant declare unsigned ints

tender shard
#

maybe they will be able to have negative values in the future

#

just use an OptionalInt and done

granite owl
#

kk ty xD

#

the only real advatage of returning 0 as default is that u can like check it like a bool

#

as it always returns true if its not 0

#

but iirc that doesnt work in java

ivory sleet
#

Correct

patent horizon
#

how would i loop through all the items under the items: branch in this yamlconfiguration and then pass all the parameters for each item into a method i've setup?

ivory sleet
#

Java is hardcore on its type system

granite owl
tender shard
granite owl
#

but errors are on u ofc

ivory sleet
granite owl
#

C++ is superior

#

even tho certain people would disagree

#

over C*

ivory sleet
#

Would say Java is nicer if you don’t care about sloppy memory management

quaint mantle
#

rust is better

patent horizon
quaint mantle
ivory sleet
#

But yeah Rust also kind of overshadows cpp

patent horizon
#

or would i have to getConfigSection once i have each name?

granite owl
#

cpp's real advantage is its freedom, something i struggle with in java

quaint mantle
#

java has wayyyy more freedom than cpp

granite owl
#

how so

#

u cant use ptrs

#

well u can

quaint mantle
#

lmao

ivory sleet
#

Freedom in terms of what? Memory management? Or just convenience features like generic varargs?

granite owl
#

direct access to the hardware

#

memory management

ivory sleet
#

Myeah

granite owl
#

typecasting

#

multilingual support

#

ive even embedded java code in my cpp programm accessing the JRE xD

tender shard
ivory sleet
#

Well one of Java’s selling point is that you get to disregard hardware related stuff

granite owl
#

tho u can use pointers in java

ivory sleet
#

Just beautiful abstractions and oo

quaint mantle
#
struct User<'a> {
    name: &'a str,
}

impl User<'_> {
    fn has_balls(&self) -> bool {
        self.name != "Timinator"
    } 
}

fn main() {
    let user = User { name: "Timinator" };
    println!("{}", user.has_balls());
}
tender shard
#

their name is "Timinator", without r

ivory sleet
#

Yes but Java abstracts away malloc and free for instance

patent horizon
#
        for (String item : config.getConfigurationSection("items").getKeys(false)) {
            config.getConfigurationSection(item).
        }``` so once i've got each item, how would i get their values and put them into my method?
granite owl
#
    @EventHandler
    public void onFurnaceBurn(FurnaceBurnEvent event)
    {
        Callbacks.disableFuel(event);
    }

public static void disableFuel(FurnaceBurnEvent event)
    {
        ItemWrapper item = new ItemWrapper(event.getFuel(), null);
        
        if (item.getItemStack() != null)
        {
            if (item.isFuel() != Access.TRUE)
            {
                Furnace furnace = (Furnace)event.getBlock().getState();
                FurnaceInventory inv = furnace.getInventory();

                if (inv.getViewers().size() > 0) inv.getViewers().get(0).getInventory().addItem(item.getItemStack()); else furnace.getWorld().dropItemNaturally(furnace.getLocation(), item.getItemStack());
                inv.setFuel(new ItemStack(Material.AIR));
                event.setCancelled(true);
            }
        }
    }
``` this while looking weird to some maybe, is by no means inefficient just because i pass the event
ivory sleet
#

You don’t even have to pay the slightest attention to that if you don’t want to

granite owl
#

because i dont pass the event

#

but only a pointer to object

#

instance*

ivory sleet
#

Yes as of now that is, but the underlying model for how pointers and memory management works could be shifted at any point of time and Java could still persist the change because of the abstractions it has offered

granite owl
#

well this is the same for all classes actually

ivory sleet
#

(It’s extremely unlikely but just as an example)

granite owl
#

as of JDK17

#

all objects are passed as pointers

#

only primitives are made copies of

granite owl
#

but its cleaner if it looks like this

ivory sleet
#

I mean objects are references in Java

granite owl
#
    @EventHandler
    public void onInventoryClick(InventoryClickEvent event)
    {
        Callbacks.onInventoryClickDisableEmeralds(event);
        Callbacks.onInventoryClickTransmuteSmithing(this, event);
    }
#

this is imo cleaner

#

than to smash everything in 1 function

#

even tho they have completly different purposes

ivory sleet
#

Yes but that’s how you abstract away concerns to some extent

#

Anyway Java has no real notion of pointers in the language

#

It’s just pass by value**

granite owl
#

yea ofc

#

but it defaults to the same

ivory sleet
#

The values are references

tender shard
#

IIRC you can get the memory address of objects

ivory sleet
#

Yep

tender shard
#

and also directly set values at certain addresses

granite owl
#

if use give function(&PlayerDeathEvent event) in C++ or just pass the event in java as of now defaults to the same

ivory sleet
#

With the new memory api that should be possible (mfnalex)

granite owl
#

xD

tender shard
ivory sleet
#

Yep

granite owl
#

huh

ivory sleet
#

Altho its subject for removal

tender shard
#

e.g. Unsafe.getUnsafe() (okay that only works with reflection) and then just putAddress, putLong, putChar, ......

granite owl
#

tbh unless u write a memory hacking tool

tender shard
granite owl
#

or mod games on assembly level

#

u have virtually no reason to access mem addresses directly

humble tulip
#

Is there an easy way to create menus?

granite owl
tender shard
ivory sleet
#

It’s not exactly the same but equivalent enough

granite owl
ivory sleet
#

And then there’s the gc in Java which handles free for you

granite owl
#

the GC is G

#

xD

tender shard
ivory sleet
#

Yee

granite owl
#

i cant tell u how much i was frustrated

#

to learn there aint conventional destructors in java

#

xD

ivory sleet
#

finalize() kappa x)

granite owl
#

at that point

#

i was writing my api to access my ini parser.dll

#

which passed its pointer to the JRE

ivory sleet
#

Ough

granite owl
#

which my JRE stores as integer

#

well long

#

since unsigned int32 in c++ is javas long equivalent

#

unsigned and signed sigh

ivory sleet
#

One thing that Java messed up a bit

granite owl
#

with the destructor?

#

finalize isnt safe to be called

#

xD

ivory sleet
#

Yes but also signed and unsigned numbers

granite owl
#

cant paste the whole file here

#
    private long ptr;
        
    public IniReader()
    {  
    IniParser.Initialize(this);
    this.ptr = initPtr();
    }
ivory sleet
#

finalize can be fixed by using Weak, Soft and PhantomReference with a ReferenceQueue

#

And also try finally

granite owl
#
//Export for Java as .dll && .so
extern "C"
{
    JNIEXPORT jlong JNICALL Java_IniReader_initPtr(JNIEnv* env, jclass cls) { return reinterpret_cast<std::uintptr_t>(new IniReader()); }
    JNIEXPORT void JNICALL Java_IniReader_deletePtr(JNIEnv* env, jclass cls, jlong ptr) { delete (IniReader*)ptr; }
    JNIEXPORT jboolean JNICALL Java_IniReader_openFilePtr(JNIEnv* env, jclass cls, jlong ptr, jstring str) { return ((IniReader*)ptr)->openFile(env->GetStringUTFChars(str, 0)); }
    JNIEXPORT jboolean JNICALL Java_IniReader_closeFilePtr(JNIEnv* env, jclass cls, jlong ptr) { return ((IniReader*)ptr)->closeFile(); }
    JNIEXPORT jboolean JNICALL Java_IniReader_jumpToHeaderPtr(JNIEnv* env, jclass cls, jlong ptr, jstring str) { return ((IniReader*)ptr)->jumpToHeader(env->GetStringUTFChars(str, 0)); }
    JNIEXPORT jboolean JNICALL Java_IniReader_getNextLinePtr(JNIEnv* env, jclass cls, jlong ptr) { return ((IniReader*)ptr)->getNextLine(); }
    JNIEXPORT jboolean JNICALL Java_IniReader_isKeyValuePtr(JNIEnv* env, jclass cls, jlong ptr, jstring str) { return ((IniReader*)ptr)->isKeyValue(env->GetStringUTFChars(str, 0)); }
    JNIEXPORT jstring JNICALL Java_IniReader_getKeyValuePtr(JNIEnv* env, jclass cls, jlong ptr) { return env->NewStringUTF(((IniReader*)ptr)->getKeyValue()); }
    JNIEXPORT jstring JNICALL Java_IniReader_getValueStringPtr(JNIEnv* env, jclass cls, jlong ptr, jint index) { return env->NewStringUTF(((IniReader*)ptr)->getValueString(index)); }
    JNIEXPORT jint JNICALL Java_IniReader_getValueIntPtr(JNIEnv* env, jclass cls, jlong ptr, jint index) { return ((IniReader*)ptr)->getValueInt(index); }
    JNIEXPORT jfloat JNICALL Java_IniReader_getValueFloatPtr(JNIEnv* env, jclass cls, jlong ptr, jint index) { return ((IniReader*)ptr)->getValueFloat(index); }
}
#

xD

#

thats how i made java handle pointers

ivory sleet
#

🌞

granite owl
#

store them as long

#

xD

granite owl
#
return reinterpret_cast<std::uintptr_t>(new IniReader());
``` xD this returns its own instance ptr as unsigned int
#

that then can be stored as long by the JRE

#

^^

quaint mantle
#

what the fuck

granite owl
quaint mantle
granite owl
quaint mantle
#

cast an ini reader to an unsigned int pointer

granite owl
#

no

#

i instantiate a new ini reader

#

and then typecast its pointer into an int

#

and return this int to the JRE

#

so the JRE side code can store the pointer as integer

granite owl
#

i wrote that for my plugins to access their ini parser from a dll

#

but my hostprovider blocks binary code execution

tender shard
#

With Unsafe you can basically do your pointer stuff that you seem to like lol

#

I only read until the end of the AtomicCounter example

rotund pond
#

Hello !
I'm looking for a good inventory framework 👍

#

All that I find are no longer maintained

tender shard
#

I have a fork of that for 1.18 including a proper maven artifact

#

np

quaint mantle
#

how do i get the config file from a class that isn't the main class

wind tulip
#

How would I go about installing the mapped version of spigot with build tools?

sullen dome
tender shard
sullen dome
#

advertisement for his website -_- what did i expect lol

tender shard
#

where's the problem?

#

don't read it if you don't want to

wind tulip
dusk flicker
#

thats not even bad

tender shard
knotty gale
#

Would anyone know how to make a scoreboard, where you can change the words of it using a command?

wind tulip
#

do I even need to add the whole <build> thing if I'm just adding the dependency tags instead

tender shard
# wind tulip

it's in the official spigot repo, did you add that?

wind tulip
#

yes

tender shard
#

try clicking on "maven" -> the "m" button -> enter mvn clean package -U

#

see if that fixes it

wind tulip
#

do I need the build tag though

tender shard
#

yes

wind tulip
#

like do I really need all that gibberish in my pom.xml

#

alright

tender shard
#

yes

#

it's needed to "reobfuscate" your plugin

sullen dome
tender shard
#

you cannot simply use mojang mappings in your plugin. you can only use it in your code, and let this plugin translate it back to the "obfuscated" names the spigot.jar is using

tender shard
# sullen dome was just a joke :(

sometimes there's even people claiming "ugh I don't click on random links, they can contain viruses" so I wasn't sure if you're serious lol

sullen dome
#

i don't think you can get a virus by only clicking a link

#

idk about shit tho

tender shard
#

to get the FULL log, you have to click the uppermost thing on the left next your the console output

#

and yeah then copy everything from the console

wind tulip
tender shard
#

it has worked fine

#

your intelliJ is just a bit stupid. Do File -> Invalidate Caches -> Invalidate and Restart, then wait a bit

wind tulip
#

Okay, everything works & all, but I'm trying to parse an item's nbt to an item stack, and seems to me that on the remapped version classes such as MojangsonParser and NBTTagCompound have been renamed. Do you happen to know what they are?

tender shard
#

check out the source of CraftPersistentDataContainer, there you'll see how they are called

#

IIRC then NBTTagCompound is just CompoundTag or sth like that

iron glade
#

Hey there,
does anyone know a simpler way to get the duration of something in seconds with 2 decimals? I currently use the following, which works fine, but seems kinda ugly

tender shard
tender shard
proper notch
#

Note the .0 on the 1000 is necessary as you need it as a double.

#

I'm also assuming your duration starts out as milliseconds.

iron glade
#

I used System.nanoTime(); and tried converting it in seconds by dividing it by 1.000.000.000, but this always got me something like 4.0 seconds or 5.0 seconds and not 4.35

proper notch
#

Yh u gotta add a .0 on the end otherwise it'll come out as a long.

tender shard
proper notch
#

long/long = long, long/double = double.

tender shard
#

it's a one liner

proper notch
#

what's actually the difference? coz why would they create DecimalFormat if u could just use String.format

#

Or does DecimalFomat just provide more granularity

iron glade
proper notch
#

Your nanoseconds -> seconds issue is just that ur dividing a long by a long. That'll give you a long.

When you divide it, add a .0 on the end so you're doing a long divided by a double.

tender shard
tender shard
tender shard
#

double myseconds = something / (double) 10000000

iron glade
#

double duration = (this.end - this.start) / 1000000000.0;

#

this.end and this.start being long values

tender shard
#

yeah and now just put that into

String.format("Duration: %.2f seconds",duration);
proper notch
#

^^

iron glade
#

Will try, give me a second

proper notch
#

Ok looks like the difference with DecimalFormat is it accounts for system locale, e.g 1.0 vs 1,0 and currency symbols.

tender shard
#

        private static final long SECOND_IN_NANOSECONDS = TimeUnit.SECONDS.toNanos(1);

    @SneakyThrows
    public static void main(String[] args) {
        long startTime = System.nanoTime();
        Thread.sleep(2500);
        long differenceInNanoSeconds = System.nanoTime() - startTime;
        double differenceInSeconds = differenceInNanoSeconds / (double) SECOND_IN_NANOSECONDS;
        System.out.println(String.format(Locale.ENGLISH,"Duration: %.2f seconds",differenceInSeconds));
    }

this prints out "Duration: 2.50 seconds"

tender shard
iron glade
#

It works, but the thing is I'm only getting values like 1.80 seconds, 2.35 seconds, 3.45 seconds etc, not smth like 4.27 seconds

tender shard
#

where is the difference between 1.80, 2.35, 3.45 and 4.27?

iron glade
#

only values with 0 or 5 at the end

#

like it doesn't get more accurate than that

proper notch
#

can u print out the difference (in nanos) to check the raw value.

iron glade
#

yes wait a sec

tender shard
#

it works fine for me.

public class Test2 {

    private static final long SECOND_IN_NANOSECONDS = TimeUnit.SECONDS.toNanos(1);

    @SneakyThrows
    public static void main(String[] args) {
        long startTime = System.nanoTime();
        Thread.sleep(2510);
        long differenceInNanoSeconds = System.nanoTime() - startTime;
        double differenceInSeconds = differenceInNanoSeconds / (double) SECOND_IN_NANOSECONDS;
        System.out.println(String.format(Locale.ENGLISH,"Duration: %.2f seconds",differenceInSeconds));
    }
}

Same as above but it prints "Duration: 2.51 seconds". Which is totally accurate, I've did Thread.sleep for 2510ms

humble tulip
#

What wakes a sleeping thread?

crimson terrace
#

usually mom

iron glade
humble tulip
#

Seems abt right

iron glade
#

ye seems like it's working, I'm just surprised cause it ends with 0 or 5 very often

tender shard
tender shard
# iron glade

well remember that ticks are always 1/20th of a second

#

so depending on what you do, it makes sense that it's * 0.05 very often

iron glade
#

right, makes sense now

#

thank you all for your help < 3

proper notch
#

np :)

tender shard
#

np :3

iron glade
#

Recently I found out that there's no way to detect a middle-click in an inventory of a player in survival gamemode anymore

#

I had to change some plugins to shift-left-click 😦

tender shard
#

that's correct, IF the slot is empty

#

it should work fine on non-empty slots IIRC

#

although I don't 100% remember that

iron glade
#

middle click was so handy ngl

#

although shift-left-click ain't that ugly

tender shard
#

yeah RIP for my ChestSort

iron glade
#

you changed it to shift left click too?

tender shard
#

ChestSort has 5 different hotkeys anyway

#

shift-left is one of them

iron glade
#

idk there were some other click types but I found shift left click one of the better options

proper notch
#

wait it doesn't seem to even send it when on an item

iron glade
proper notch
#

well that sucks

iron glade
#

I tried yesterday and I didn't get it working

proper notch
#

yh the client sends no packet

tender shard
#

i still hope that it comes back in 1.19

iron glade
#

was kinda annoying me when I updated some plugins from older versions to 1.18+

iron glade
#

This might be a dumb question but can you set the default of a switch operation to just break; ?

sullen dome
#

sure

tender shard
#

sure

iron glade
#

perfect

tender shard
#

you can also use weird names for your enums

#
public enum $$ {
    __;

    public $$ $$($$ this) {
        switch (this) {
            case __:
            default:
                break;
        }
        return __;
    }
}
proper notch
#

no one needed to witness this

fallow violet
#

xd

#

looks shitty

iron glade
fallow violet
#

imagine using this in your project

proper notch
#

i enjoy my enhanced switches :)

fallow violet
#

xd

tender shard
fallow violet
#

ok

#

so

proper notch
#

I just call them unused.

tender shard
#

for example

long lastValue = lastUsages.computeIfAbsent(player.getUniqueId(), __ -> 0L);
fallow violet
#

maybe makes sense

#

but idk

proper notch
#

.queue(unused -> channel.getManager().setLocked(true).queue());

tender shard
#

it was explained like this in a java bbook I read so I sticked to it

#

they said another way would be to use the type, e.g.

iron glade
#

I want to replace the blocks around the player, like that

Would the most efficient way be to get the blocks within a radius of 1 around the player?

tender shard
#
long lastValue = lastUsages.computeIfAbsent(player, OfflinePlayer -> 0L);
fallow violet
#

in this method 2 loops for x and z

tender shard
#

yeh just use a nested for loop

#

can't get faster than that

fallow violet
#

imagine writing 8 lines with the relative positions

iron glade
#

ikr

tender shard
fallow violet
#

no way

tender shard
#

and they copy paste their whole code again to add for example the next 2 instead of next 1 blocks

proper notch
#

it pains me to know that happens

fallow violet
#

same

iron glade
#

I think and hope most people improve stuff like that over time

#

and get more efficient

fallow violet
#

it wont

iron glade
#

those people end up working for ubisoft

queen geode
#

I've looked around and I'm kinda stuck. Is there a way to prevent a dependency from unloading until all it's dependents have completely unloaded?

wintry oxide
#

Hello, i'm trying to load a world here is the code:

String[] worldNames = { "", "_end", "nether"};
            World.Environment[] worldType = {World.Environment.NORMAL, World.Environment.THE_END, World.Environment.NETHER};

            for (int i = 0; i < worldNames.length; i ++) {
                int finalI = i;
                new Thread(() -> {
                    World world = new WorldCreator(game.getId()+worldNames[finalI])
                            .environment(worldType[finalI]).createWorld();
                    Bukkit.getServer().getWorlds().add(world);
                }).start();
                
                System.out.println(game.getId()+worldNames[i]);
            }

The proble is that when i load the world it take a lot of time and lags the whole lobby

queen geode
#

I have a plugin that provides kotlin-stdlib and exposed for my plugins and it seems to unload before it's dependents :P

humble tulip
#

@queen geode maybe plugindisableevent?

#

Maybe unload the dependants there

queen geode
#

Alrighty, I'll give that a try!

iron glade
#

Does anyone know a shortcut to switch from a tab to another one which is on another split window in intelliJ?

sleek turret
#

alt+tab?

#

or is it all on one page?

iron glade
#

it's on one page

lethal python
#

if i have a playerinteractevent and i do ItemStack item = event.getItem(); then modify item, will later doing event.getItem() return the modified item or does .getItem() clone the event item

iron glade
#

I mean when you rightclick on a tab you can choose to split it

sleek turret
#

hmmm, not sure. i think intellij has a shortcuts section in preferences

iron glade
#

I'll look into it, thanks!

sleek turret
#

np! im gonna take a quick look too

#

@iron glade In preferences go to Keymap and search "split". I saw a few things that might be what you wanted

iron glade
sleek turret
#

hmmmm

iron glade
#

but I can't jump into the other window which was split

sleek turret
#

Preferences -> Keymap -> Mainmenu -> Window -> Editor tabs

#

thats what i found

#

im on mac so my key combinations are different

iron glade
sleek turret
#

try got next splitter

#

what does that do?

iron glade
#

I have no idea

sleek turret
#

damn

humble tulip
sleek turret
#

that was he best idea i had

iron glade
sleek turret
iron glade
sleek turret
#

np < 3

sullen dome
winged anvil
winged anvil
#

There doesn't seem to be any attributes

#

tuff

sullen dome
#

thats clientside

#

thats what breaks so many gui stuff imo

sleek turret
#

lmao

winged anvil
#

what does

#

it being clientside?

sullen dome
#

those aren't item tags or shit, but rather "tags" that are added by the client to not be changeable

#

or removeable

#

short: no, you can't remove it without a clientside mod

winged anvil
#

im tweakin

#

i just removed it from my game

#

no clue how

sleek turret
#

f3 + h probably

winged anvil
#

nah its not that

sleek turret
#

oh

sullen dome
#

f3+h is just the nbt tags

#

and the item id

sleek turret
#

oh ok

sullen dome
#

tho i wonder... aren't those blue tags in creative only?

sleek turret
#

im not at my pc rn so i wasnt sure

winged anvil
#

im in creative rn

sleek turret
winged anvil
#

i applied like every ItemFlag tho

#

except potion effect

#

so maybe its one of those

sleek turret
#

so you know what section its from