#help-development

1 messages Β· Page 114 of 1

buoyant viper
#

then why even write java

echo basalt
#

there are only a few rare instances where I actually like to enforce exceptions

buoyant viper
#

smh

tender shard
#

player between 3-16 blocks away: follow
otherwise: stop

echo basalt
#

Trycatch from a clock cycle perspective is a bit slow

tender shard
#

add debug statements

#

and see what they print

#

check what I sent above

#

yeah well if you say "its fine ", then no need to debug anything lol

echo basalt
#

I only throw exceptions when I'm doing something extremely wrong

tender shard
#

I got a method for that, 1 sec

echo basalt
#

like trying to load a template that never existed

tender shard
echo basalt
#

But from an API point of view, getting a canvas frame at the exact location of the pixel might return null sometimes

#

it'd be extremely unsettling if I got a result during my optimized calls because I make sure to validate my inputs

#

yet it's still a very valid possibility

tender shard
echo basalt
echo basalt
#

line 77

#

feels wasteful

tender shard
#

oh that

#

yeah it's probably not the fastest way

echo basalt
#

also items might be null

tender shard
#

but what I sent uses regular for loops

echo basalt
#

not sure how the stream handles that

#
int amount = 0;
for(ItemStack item : inventory.getContents())
  if(itemStack.isSimilar(item)) // not the other way around, nullability
    amount += item.getAmount();

return amount;
#

add braces if you want

#

I've been adding braces lately but my hands are hella sweaty and it's uncomfortable to type

tender shard
echo basalt
#

fuck no I'm not importing your lib into my IDE

tender shard
#

if you dont fix it yourself, you must not complain πŸ˜›

vocal cloud
#

PR every character change separately

echo basalt
#

consider it merely as a fine suggestion towards a replacement

echo basalt
#

then have a PR with like 200 commits

tender shard
#

yes, will do. I think you're also right about the stream thing breaking when a slot is empty

echo basalt
#

and hide some malware in one of them towards the middle

tender shard
#

it seemed to have worked by now

#

so I guess it's fine

#

EVERYTHING that's inside JeffLib is used somewhere in one of my plugins so I guess it does actually work fine

vocal cloud
#

Time to PR and change that /s

quartz solstice
#

Does anyone know how to store data about a player in spigot

tender shard
quartz solstice
#

1.19.2

quartz solstice
#

ok

#

i see

#

how would i use to make a cooldown for running a certain command

#

would i like remember the time last sent

tender shard
#

1 sec

quartz solstice
#

ty

tender shard
#

example usage:

public class MyCommand extends CommandExecutor {
  private final Cooldown cooldown = new Cooldown();

  public void onCommand(...) {
    if(cooldown.hasCooldown(sender)) {
      sender.sendMessage("You gotta wait before running this again!");
      return;
    }
    cooldown.setCooldown(sender, 60, TimeUnit.SECOND);
    // Do your stuff. Players can only run this every 60 seconds
    }
echo basalt
#

command api when

#

πŸ‘€

tender shard
#

from me? never

echo basalt
#

maybe you can take some inspiration from mine

tender shard
#

I just use ACF ❀️

echo basalt
#

fuck

tender shard
#

i dont get the hate against ACF

echo basalt
#

I just don't like annotations tbh

tender shard
#

yeah well

#

but why not

echo basalt
#

also seems jank to shade like 200kb worth of parser stuff

#

annotations use reflections

#

and I'm a performance freak

tender shard
#

but who cares whether your plugins takes 20ns to enable, or 7ms?

echo basalt
#

I go to bed, spin for an hour, and get back to work because I want to optimize that 1 tiny method

#

code for another 3 hours and then sleep

tender shard
#

idk I wouldnt bother about stuff like that

#

when people send a spark or timings report, then it's time to start optimizing stuff

#

but before that? naaaah thanks

echo basalt
#

what if it's async

#

yet still takes more than 0.05ms

wet breach
#

this isn't what the image says

tender shard
#

noone ever complained to me that my plugin is 200kb bigger because of ACF, or that they doing /somecommand took 0.0003ms instead of 0.0001ms

echo basalt
#

Eh

echo basalt
#

I'd pitch rewriting hypixel in Assembly if the guys ever accepted me

tender shard
#

just check for "s" at the end?

echo basalt
#

actually I got most devs on my friend list

#

time to spam them

wet breach
#

am I part of most devs?

tender shard
#

then it would be "exodus' zombie"

#

no

echo basalt
#

if it ends with an s

tender shard
#

it should be "exodus' zombie"

echo basalt
#

then you add a '

echo basalt
tender shard
#

check if it ends with "s" and yes, add "'". Otherwise, add "'s"

wet breach
#

just so you know this won't work the way you expect

tender shard
#

oh and for X too

#

e.g. "alex' pet"

#

"Linus' pet"

#

"Thommy's pet"

#

etc

echo basalt
#

Illusion's - belongs to illusion
parent's - belongs to either parent
parents' - belongs to both parents

wet breach
#

so getDisplayName is effected by nicknames just fyi, unless that is your intention

wet breach
#

second if you are trying to add

#

's

tender shard
#

i'd just check for "x" or "s" at end, if yes: add one '
otherwise add 's

tender shard
#

yeah

#

but I'd also move this into an own method

#

e.g. getPetName(String playersName)

#

maybe you'll some day wanna add more stuff than just Undying zombies

#

if you can put something into its own method, then you should always do that

echo basalt
#
private final String TEXT_MASK = "xs";

public static String reference(String input) {
  char lastChar = input.charAt(input.length() - 1);
  input += "'";
  
  if(!TEXT_MASK.contains(lastChar))
    input += "s";
  
  return input
}
#

^ is the "little shit that likes to use constants" approach

tender shard
#

Alex' zombie

#

no

#

@wet breach is from USA so he must know it

echo basalt
#
public static String reference(String input) {
  if(input.endsWith("x") || input.endsWith("s"))
    return input + "'";

  return input + "'s";
}

is probably the most common approach

tender shard
#

is it "alex' zombie" or "alex's zombie"?

echo basalt
#

I'd say alex's zombie

#

honestly

tender shard
#

I'm pretty sure that it's "alex' zombie"

wet breach
#

This would be correct for possessiveness

tender shard
#

hm

#

maybe I learnt it wrong then

echo basalt
#
#

box's color

#

box color

#

I'd say box's color

tender shard
#

they agree with you

#

english being weird again

wet breach
#

if ends with an s using ' only is acceptable

echo basalt
#

don't do s's

#

that's bad

tender shard
echo basalt
#

example

#

gangstas's guns

tender shard
#

you could also just do "Undying zombie of Alex" lol

wet breach
tender shard
#

"The Undying Zombie owned by Alex"

#

lol

echo basalt
#

if we're having a 10 minute argument over something this irrevelant, the plugin will be baller

wet breach
#

Grammar is a pain in the US

#

or in English in general

tender shard
echo basalt
#

make a phonetic parser

#

feed it through a neuralnetwork

#

and have consistently wrong results

tender shard
#

or just make players enter a custom name for their zombie

wet breach
#

one year you learn something new

#

the following year, you learn what you learned last year isn't exactly true

tender shard
#

but german is also weird. we have random genders for every word

#

car is neutral, woman is obviously female, but the plural of "man" is also female

wet breach
#

lol

tender shard
#

lol wtf

#

who the fuck eats a whole pig('s) head

wet breach
#

for instance when you learn i before e, except after c So we learn this in school, but when you get to high school, you learn that this is actually false for so many things >>

tender shard
wet breach
#

for instance neighbor does not follow this rule

tender shard
#

caffeine

#

protein

#

keith

wet breach
#

exactly and it was annoying that what I was taught in school was wrong >>

tender shard
#

seizure

buoyant viper
#

i mean do names really count

tender shard
#

but e.g. seizure

#

weird

lost matrix
#

getTargetBlockExact or something

quartz solstice
#

How would I get a player variable based on their ign

lost matrix
quartz solstice
#

Well I am creating a command where you request to tp to another player using their ign, so I can't really use UUIDs

tender shard
#
Player player = Bukkit.getPlayer(args[0]);
if(player == null) {
  // send error message that this player isnt online
} else {
  // teleport
}
#

sth like this?

#

or using ACF πŸ˜„

@CommandAlias("tp")
public void onTp(Player sender, Player target) {
  ...
}
#

ACF is such a time savor

white root
#

Ok, so the whole chat formatting mess really has me feeling stupid rn.

Right now, I have a .parseColors() method that replaces normal color codes and hex colors (#rrggbb) with their ChatColor.of(color) format, and using player#sendMessage, it sends fine, colors and all.
But when I feed it into either TextComponent() or TextComponent.fromLegacyText(), the hex color formatting seems to just disappear.

Im trying to use components because in my plugin's config file, there are user defined strings that need to have (a pre-defined) click and hover actions, in addition to having both their normal and hex colors parsed.

This is my code: https://uploadi.ng/πŸ§†πŸ“œπŸ€·πŸ΄ [first screenshot attached]
and this is the output: https://uploadi.ng/πŸ¦™πŸ₯œπŸ‘„πŸ” [second screenshot attached]

Can someone help me figure out how to parse the normal and hex colors from the config string, then apply click and hover actions to it?

@𝕄𝕣. 𝕄𝕔𝕐𝕖𝕖π•₯#9300
@𝕄𝕣. 𝕄𝕔𝕐𝕖𝕖π•₯#9300
tender shard
#

e.g. like this:

#
String message = ChatColor.translateAlternateColorCodes('&', "&x&f&f&0&0&0&0This should be solid red");
white root
#

So doing that does let me send a red message (sending it with player#sendMessage()) but how do I then add hover and click actions to that?
When I use TextComponent.fromLegacyText(/* your example */),
it outputs an array of baseComponents ( https://uploadi.ng/πŸŽ‹πŸšπŸ¦ƒπŸŒ  ), so it seems like I can't just do message.clickEvent = blablabla

Is there some way to make TextComponent.fromLegacyText() not output an array? Or some way to merge the elements from the resulting array into one baseComponent or chatComponent

@𝕄𝕣. 𝕄𝕔𝕐𝕖𝕖π•₯#9300
tender shard
#

I also had this issue once and I somehow solved this but tbh I have no idea how

#

lemme check if I find it

#

but to answer your first question: It will always return an array because it basically splits the string by colors

#

e.g. "&aGreen&cRed" will return two components, "Green" with green color and "Red" with red color

#

hm I don't remember in which plugin I added the click event but it's definitely somehow possible. Unofrunately I don't find it right now :/

#

@white root cant you just do stuff like this?

#
        BaseComponent[] components = TextComponent.fromLegacyText("Β§cRedΒ§aGreen");
        components[1].setClickEvent(...);
#

this SHOULD add a click event to the "Green" part

white root
# tender shard ```java BaseComponent[] components = TextComponent.fromLegacyText("Β§cRed...

Actually, that isnt a bad idea, I can just iterate over the components, but again I feel dumb for not seeing a way of doing this, but how do I send that array of baseComponents to players?
Intellij seems to like nether player#sendMessage(BaseComponent[]) nor player#spigot()#sendMessage(BaseComponent[])
https://uploadi.ng/πŸ˜‡πŸ§‘πŸ™…πŸ”

@𝕄𝕣. 𝕄𝕔𝕐𝕖𝕖π•₯#9300
tender shard
#

if you want to add a click event too the whole message, then you gotta add it to ALL the array elements

#

huh

#

sendMessage DOES take a BaseComponent... thing

#

maybe you missed it because it's a varargs method?

#

this is part of Player.Spigot

white root
tender shard
#

hm that is weird. In your screenshot, I can see that the second "suggestion" shows the BaseComponent varargs method

#

I mean, you're using kotlin, but normally that should work totally fine

white root
#

The only thing that I can think of is that im building against 1.16 spigot api org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT, but even if I change that to 1.19, its still the same

tender shard
#

what error message do you get when you try to compile it anyway, besides IntelliJ complaining?

tender shard
tender shard
#

wow that's weird. it literally tells you that there's a varargs BaseComponent... function

tender shard
# tender shard

sorry no idea. It does work in normal java, as I showed here :/

#

what happens if you replace "val" with an explicit BaseComponent[] ?

#

I dont know much stuff about kotlin so no idea if this might fix it

#

like, try to explain to the kotlin compiler that "test2" is actually a BaseComponent array

#

(although normally it should know it already, so yeah, no idea :/ )

white root
tender shard
#

it might have something to do with the fact that it has the exclamation mark in this method signature

white root
#

that just means that it cant be null in kotlin, I think

tender shard
#

IIRC this is kotlins' version of saying "not null"

#

yeah

white root
tender shard
#

nice! Now you only gotta check if it actually works ingame, too πŸ˜„

white root
#

It does indeed :dogekek:

tender shard
#

oh okay, perfect

white root
#

You have no idea how long I spent this morning feeling dumb trying to mess with kyori, spigot's chat api and bungee's chat api trying to figure out how to just send the messages I was formatting lmao

#

Anyway, tysm <3

tender shard
#

no problem :3

#

im kinda surprised myself that I could help because I have absolutely no idea about kotlin lol

#

yeah NMS is a hell in some regards

#

what exactly are you struggling with?

#

"mob keys"?

haughty idol
#

hey y'alll, so i'm trying to code cooldowns and have no idea where to start, so i'd like a push in the right direction- like just the starting point and i can take it from there

#

i have a bunch of classes and i don't want to copy code too so i'd prefer to have a function in a class and reference it in other classes

lost matrix
#

Use unix timestamps (longs) and Maps.
First map each player to a CooldownContainer (A data class you write)
and then inside this container you map a String to a Long so you can
have named cooldown.

When an action occurs you simply check if the timestamp is in the future or past.
If you need a countdown or something similar then use a task that checks the timestamp
every so often against the current time,

haughty idol
#

hm

#

okay

#

so could i put this in a function in, lets say, my main java class?

#

and if so where?

#

i guess i could do a public static right inside the class

#

and could i use the config files for this?

#

i'm not good at SQL

#

unless i'm dumb and its not sql

lost matrix
#

Dont use any statics for this whatsoever.
Learn java and abandon the static keyword for a while.
The only things you can make static are constants like

public static final double PI = 3.14

Thats it. No more static for you.

haughty idol
#

ah

#

okay

#

public CooldownContainer cooldownContainer = new CooldownContainer(); would this work?

#

and then i'd make a new java class correct?

#

called cooldown container

lost matrix
#

The first thing you want is a CooldownManager
And you only create a single instance of this manager.

haughty idol
#

okay

#

this is a class, correct?

lost matrix
#

This manager manages a Map<UUID, CooldownContainer> with all the CRUD methods.

#

And every CooldownContainer has a Map<String, Long> representing the named cooldowns.

haughty idol
#

private final Map<UUID, CooldownContainer> cooldowns = new HashMap<>();

lost matrix
#

Yes this is a class. And you make it a singleton. This manager should only ever have one instance and then
you dont create another one. This instance should be in your JavaPlugin class and either passed through the constructor
of other classes or being retrieved by a getter.

lost matrix
#

Important design note:
Never every create getters or setters for Maps, Lists, Sets or other data structures.
Never.

haughty idol
#

okay

#

soo

#

i'll start

lost matrix
#

Not its as efficient as it gets.

#

You can check timestamps millions of times per minute if you wanted and the server wouldnt even notice.

haughty idol
#

how would i tweak this cooldown in each ability?

lost matrix
#

You make the cooldowns agnostic. Dont think about which application will use them later.
Just make it modular.

#

Thats what the Map<String, Long> is for.
You will be able to set cooldowns for everything you want.

haughty idol
#

orr i could make a setter :))

#

(jk (?))

#
    private final Map<UUID, CooldownContainer> cooldowns = new HashMap<>();
    public static final int defaultCooldown = 15;``` i got this so far
#

i'm not rlly good at this

#

twt

lost matrix
#

The first line is useless

haughty idol
#

ok

#

should i still have the cooldowncontainer class?

lost matrix
#

Yes of course.

haughty idol
#

ok

#

so what should i put next?

#

hm

lost matrix
#

What do you mean? Did you finish all the classes and methods?
If so then send them first.

haughty idol
#

uh

remote swallow
#

?paste

undone axleBOT
haughty idol
lost matrix
#
  1. The CooldownManager with all the CRUD methods
  2. The CooldownContainer with all the CRUD methods

CRUD=
Create
Remove
Update
Delete

haughty idol
#

i'm sorry, i've only been coding plugins for about a week now twt

lost matrix
#

Ok so the cooldown manager only needs a single map for now.
Map<UUID, CooldownContainer>
Nothing else.
Then you add the CRUD methods.
Create the CooldownContainer class but leave it empty for now.

haughty idol
#

okay

#

i'm applying crud to the cooldowns

#

right?

#

so i add the player, remove them, then update the cooldown container then delete the map?

#

i'm sorry i'm half asleep

#

gonna try to figure it out tomorrow

#

thanks so much for the help

lost matrix
#
public class CooldownManager {

  private final Map<UUID, CooldownContainer> cooldownContainerMap = new HashMap<>();

  public CooldownContainer createContainer(UUID playerId) {
    CooldownContainer container = new CooldownContainer();
    cooldownContainerMap.put(playerId, new CooldownContainer());
    return container;
  }

  public CooldownContainer removeContainer(UUID playerId) {
    return cooldownContainerMap.remove(playerId);
  }

  public CooldownContainer getContainer(UUID playerId) {
    return cooldownContainerMap.get(playerId);
  }

}
haughty idol
#

aa okay

lost matrix
#

This is how your typical manager class looks like

haughty idol
#

thanks

#

hold on i'm gonna read it

lost matrix
#

Player joins -> create or load container
Player quits -> remove and save container
On runtime -> you get the container and use it

haughty idol
#

so in the playerjoin event i should run createContainer(pUUID)

#
    public static CooldownManager getCdInstance() {
        return cdInstance;
    }``` in the javaplugin class
lost matrix
#

No statics

haughty idol
#

oh yeah

lost matrix
#

shush

haughty idol
#

cdInstance = new CooldownManager(); we instantiate it in the onEnable();

lost matrix
#

Yes. And then we pass this instance through constructors or create a getter for it.

haughty idol
#

i like getters SMH

#

just kidding i'm just using a template so i can't use a constructor here

#

CooldownManager cooldownManager = plugin.getCdInstance();

#

on join

#
        UUID pUUID = p.getUniqueId();
        String pUUIDString = pUUID.toString();
        CooldownManager cooldownManager = plugin.getCdInstance();
        cooldownManager.createContainer(pUUID);```
#

so this should create a container

lost matrix
#

Yes. What is the String for?

#

Remove it

haughty idol
#

it's for other stuff in the evetn

lost matrix
#

Oh god...

haughty idol
#

look, right now i'm using config.yml as a database

#

there's much worse stuff i'm doing than making a pUUIDString

#

so where does the Delete come in for CRUD

#

okay so how do i use this now

#

let's say... in my Mage handler

lost matrix
#

We are not at this point

haughty idol
#

oh

#

okay

#

so what next

#

i added and removed it

lost matrix
#

One moment

haughty idol
#

mk

#

do u mind if i go get some water

lost matrix
#
public class CooldownContainer implements ConfigurationSerializable {

  private final Map<String, Long> cooldownMap = new HashMap<>();

  public CooldownContainer(Map<String, Object> map) {
    map.forEach((key, value) -> cooldownMap.put(key, (long) value));
  }

  public CooldownContainer() {
    this(new HashMap<>());
  }

  public void setCooldownFromNow(String name, long millis) {
    cooldownMap.put(name, System.currentTimeMillis() + millis);
  }

  public long getCooldownLeft(String name) {
    return System.currentTimeMillis() - cooldownMap.getOrDefault(name, Long.MAX_VALUE);
  }

  public boolean isCooldownDone(String name) {
    return getCooldownLeft(name) <= 0;
  }

  @NotNull
  @Override
  public Map<String, Object> serialize() {
    return new HashMap<>(cooldownMap);
  }
}
lost matrix
haughty idol
#

back

#

okay do u mind letting me know what this does

#

cuz i really want to learn not copy code :/

lost matrix
#

Ok so here is the CooldownContainer. It implements ConfigurationSerializable so that you can simply throw it in your ymls

haughty idol
#

so i can put it into my config

#

ok cool

#

but i don't see anythign with the config in this code

lost matrix
#

This is the important code.
Ignore the rest.

#

A container can have many different cooldown timestamps.
They are identified by a String.

haughty idol
#

ok

#

ok first can you define a hashmap? i haven't done a deep delve into java yet so i'm not sure what it is :/

#

wait i can just search it up

#

oh

#

OH

#

so it's like the config file

#

but different

lost matrix
#

A map is a data structure which maps a key to a value.
You put in a key and a value and on a later point you can get that value by using a key

haughty idol
#

so like there's different values stored behind keys

#

that's really cool actually

lost matrix
haughty idol
#

so i can just plug in my player's uuid into the hashmap and get their cooldown

#

pretty cool lmfao

lost matrix
#

Yes you get their CooldownContainer. And the container has a Map<String, Long>
So every player can have thousands of cooldowns. All you need is a name for the cooldown.

haughty idol
#
        cooldownMap.put(name, System.currentTimeMillis() + millis);
    }```
#

so what are we doing there

#

we're just inputting the cooldown into the HashMap?

#

hold on need more water

#

it's a really hot day lmfao

drowsy helm
#

brain overheating

lost matrix
#

name is the name of the cooldown you want to set and millis is the time in milliseconds for this cooldown.
System.currentTimeMillis() returns the current time in millis.

In computer programs you will very often encounter the so called unix timestamp.
Its one number which started counting up at 01.01.1970 and will count for the next
couple of thousands of years.

#

This is how the current timestamp looks like.
You just have to think about 3 more digits at the end.
And this is the same for every computer.

haughty idol
#

okay

#

so what does the unix timestamp have to do with our plugin

lost matrix
#

You can think of this as a fixed point in time which is simply one long number counting the milliseconds

haughty idol
#

mkay

#

it counts up every millisecond

lost matrix
#

So

long future = System.currentTimeMillis() + 1500;

Is exactly 1.5s in the future.

haughty idol
#

so system.currenttimemillis gets the unix timestamp?

#

so what's the difference in doubles and floats? and why use floats instead of doubles? aren't floats just like half the size in bytes

#

same for like longs and ints, or ints and shorts

lost matrix
#

Imagine our current time is
50000
and our cooldown is
1000

Then we put 51000 in the map and every time something happens we check if the timestamp
is already over.

drowsy helm
#

double just holds more precise fvalues

haughty idol
drowsy helm
#

float is 32 bit, 7 decimals. double is 64 bit idk how many decimals

#

but more

haughty idol
#

so why use floats instead of doubles?

#

if doubles are more accurate?

drowsy helm
#

sometimes you only really need like 2 decimals

#

no point using all that memory

haughty idol
#

oh

lost matrix
#

double = double precision floating point = 64bit float
float = 32bit float

long = 64bit int
int = 32bit int
short = 16bit int
byte = 8bit

haughty idol
#

so it uses memory

#

i thought it jsut could STORE that much memory

#

so with this you can just choose how much memory to take up

#

thanks :)

drowsy helm
#

nah, even a double d = 0 uses 64 bits

haughty idol
#

i get it now

drowsy helm
#

its how much it reserves

haughty idol
#

oh

#

okay

#

yeayea that's what i emant

#

so @lost matrix in getCooldownLeft, you input the name and check if that time stamp has passed right?

#

and you return the amount of milliseconds left

#

and then in isCooldownDone you check if that cooldown is at 0

lost matrix
#

Yes. For example if the timestamp is 51000 and the current time is 50500 then there are still 500ms left

haughty idol
#

okay

#

you are REALLY helpful thanks so much for taking the time to explain stuff instead of just handing me the code :) it's really cool to do that

#

ok so next, we use these in runtime right?

lost matrix
#

Yes. I actually think we should add new methods to cooldown manager just for simplicity

haughty idol
#

okay

#

so these methods being?

#

hm

#

just tell me what they should do, i want to try doing them myself

lost matrix
#
  public void setCooldownFromNow(UUID playerId, String name, long millis) {
    CooldownContainer container = getContainer(playerId);
    container.setCooldownFromNow(name, millis);
  }

  public long getCooldownLeft(UUID playerId, String name) {
    CooldownContainer container = getContainer(playerId);
    return container.getCooldownLeft(name);
  }

  public boolean isCooldownDone(UUID playerId, String name) {
    CooldownContainer container = getContainer(playerId);
    return container.isCooldownDone(name);
  }
haughty idol
#

okay

lost matrix
#

Oh didnt read

haughty idol
#

its ok

#

just spoiler that

#

pwp

#

and i'll look at it if i give up

#

nvm i'll just not look at it

lost matrix
#

You basically just want easier methods for setting and checking cooldowns without having to always get the CooldownContainer.

#

So you copy the 3 methods into your CooldownManager

setCooldownFromNow
getCooldownLeft
isCooldownDone

And add a UUID parameter.

haughty idol
#

ok

#

i think i did iscooldown done

#
        CooldownContainer container = getContainer(pUUID);
        return container.isCooldownDone(name);
    }```
#

i tried

#

did i get it right

lost matrix
#

Yes

#

thats right

haughty idol
#

oh

#

so i can just access the thing and return it

#

ok not that hard

#

alright so not that hard

#

thanks for letting me do it myself :)

#

okay so now

#

we can access this ONE instance of cdmanager

lost matrix
#

If you have all 3 methods then you are pretty much done

haughty idol
#

CooldownManager cooldownManager = plugin.getCdInstance();

#

at the start of each method i'd like to use it in?

lost matrix
#

Well you would want a field that store it

haughty idol
#

uh

#

it is in a field

#

CooldownManager cooldownManager = plugin.getCdInstance();

we're putting the instance into this variable

#

right?

#

or am i dumb

lost matrix
#

Example

public class SomeListener implements Listener {

  private final CooldownManager cooldownManager;

  public SomeListener(CooldownManager cooldownManager) {
    this.cooldownManager = cooldownManager;
  }

  @EventHandler
  public void onBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    UUID playerId = player.getUniqueId();

    if(cooldownManager.isCooldownDone(playerId, "block_break")) {
      cooldownManager.setCooldownFromNow(playerId, "block_break", Duration.ofMinutes(1).toMillis());
    } else {
      player.sendMessage("Sry but you can only break one block per minute.");
      event.setCancelled(true);
    }
  }

  @EventHandler
  public void onPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    UUID playerId = player.getUniqueId();

    if(cooldownManager.isCooldownDone(playerId, "block_place")) {
      cooldownManager.setCooldownFromNow(playerId, "block_place", Duration.ofMinutes(1).toMillis());
    } else {
      player.sendMessage("Sry but you can only place one block per minute.");
      event.setCancelled(true);
    }
  }

}
haughty idol
#

so the method you used was putting it into the constructor right? i'm using a getter

lost matrix
#

Well then you pass your JavaPlugin instance in the constructor and use the getter. Same result.

haughty idol
#

well you see

#

i have a getter for the java plugin

lost matrix
#
  private final CooldownManager cooldownManager;

  public SomeListener(YourPlugin plugin) {
    this.cooldownManager = plugin.getCdManager();
  }
haughty idol
#
CooldownManager cooldownManager = plugin.getCdInstance();```
#

heehee haha

#

i love getters

lost matrix
#

Thats static abuse and i can assure your that it will lead to problems

haughty idol
#

uh

lost matrix
#

This here is the only other solution i would allow

  private final CooldownManager cooldownManager;

  public SomeListener() {
    ClassSystem plugin = ClassSystem.getInstance();
    this.cooldownManager = plugin.getCdManager();
  }
haughty idol
#

i really can't use a constructor here

#

okay s

lost matrix
#

Well as long as you are not using getters in field initializers your are fine

haughty idol
#

import org.bukkit.event.player.PlayerInteractEvent;

public abstract class PlayerClassTemplate {

    public abstract void onTrigger(PlayerInteractEvent e);

}
#

this is my PlayerClassTemplate

#

import classsystem.classsystem.ClassSystem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;

public class PlayerClassListener implements Listener {

    @EventHandler
    public void onInteract(PlayerInteractEvent e) {
        ClassSystem plugin = ClassSystem.getInstance();
        Player p = e.getPlayer();
        String pUUID = p.getUniqueId().toString();
        PlayerClass playerClass = PlayerClass.stringToClass(plugin.getConfig().getString(pUUID + ".class"));
        PlayerClassTemplate playerClassTemplate = playerClass.supplier.get();
        playerClassTemplate.onTrigger(e);
    }
}```
#

and this is my playerclasslistener

#

its just that i have so many classes and don't want to rewrite the same code

ornate mantle
#

is there any way to run my 1.8 plugin on a 1.19 server?

haughty idol
#

i also have an enum

drowsy helm
undone axleBOT
ornate mantle
#

or do i have to change every variable back to 1.19

lost matrix
ornate mantle
#

1.8 is older than my sister πŸ’€

#

nms

lost matrix
#

Then there is no way to use it in any other version

ornate mantle
#

massive bruh moment

haughty idol
#

should i be using NMS in my plugin?

ornate mantle
#

now i have to switch from spigot 1.8 mappings to 1.19 mojang mappings 😍

ornate mantle
haughty idol
#

or CraftBukkit?

ornate mantle
#

its painful its complicated its messy

haughty idol
#

i don't use either rn

ornate mantle
#

dont use nms unless you absolutely have to

#

which do you use rn

haughty idol
#

uh

#

would you believe neither?

ornate mantle
#

spigot is basically craftbukkit

#

i think

haughty idol
#

then spigot

#

i love spigot

lost matrix
#

You really dont need it if you use newer spigot versions.
Its really only viable for very specific and quite complicated topics.

haughty idol
#

ah ok

lost matrix
#

In trash versions like 1.8 you have to still clutter your code with a bunch
of garbage nms to use even the simplest of approaches.

lost matrix
#

When a player joins -> load all data from the config into classes
when he quits -> save all data from the classes back into the config

haughty idol
#

"demeters_saturation" can you use _'s in the names of cooldown containers @lost matrix

haughty idol
#

wait

#

but why not

lost matrix
#

You can as well just use "$%&§ BLib_ -- Blob ##Ü*" if you wanted to.

#

Its a String.

haughty idol
#

oh yeah

#

so i can use spaces?

lost matrix
#

sure

#

More context. Im assuming that your backend runs a newer version and that you use viaversion and viabackwards?

haughty idol
#

@lost matrix thank you SO much for the help today :)

lost matrix
#

Those plugins allow whitelisted versions

#

Yeah

haughty idol
lost matrix
haughty idol
lost matrix
#

I am not reading that mess

haughty idol
#

fair

lost matrix
#

I have not doubt that this is buggy has hell and that you will have to debug this for weeks

haughty idol
#

man.

lost matrix
#

You should extract this into like 5 different methods

haughty idol
#

well at least one of the abilities

floral drum
#

owo

lost matrix
#

Looks fine. Nothing wrong with this section

haughty idol
#

hm

lost matrix
#

Each of those should be in their own method

haughty idol
#

okay

#

i'll do that later after cooldowns work

#

not procrastinating dw about it

lost matrix
#

You can mark the lines, right click -> Refactor -> Exctract Method

haughty idol
#

waiat damn

lost matrix
haughty idol
#

coool

#

ok

#

so now

#

did i make a mistake with anything

#

OH WATI

haughty idol
#

that's not supposed to be caps right

#

all lower case

#

okay

#

i got it

#

pls work

lost matrix
#

doesnt really matter

haughty idol
#

uh

#

pain

#

i'm gonna try anyway

lost matrix
#

but yes. Best practice is to use primitives

#

Same in the second to last method

haughty idol
#

ok

#

the cooldowns seem to be in reverse

haughty idol
lost matrix
haughty idol
#

yea that's the one i was talking about

haughty idol
#

so its like wierd

#

weird

lost matrix
#

Oh yeah this method is wrong

  public long getCooldownLeft(String name) {
    return System.currentTimeMillis() - cooldownMap.getOrDefault(name, Long.MAX_VALUE);
  }

Should be

  public long getCooldownLeft(String name) {
    return cooldownMap.getOrDefault(name, 0L) - System.currentTimeMillis();
  }
#

In CooldownContainer

haughty idol
#

oh

#

okay so what's the difference

#

oh

#

dOSHFp

#

OH

#

i got it

#

thanks so much

#

pls say it works

#

FRICK YEAH

#

thanks so much smile :)

lost matrix
#

nice

haughty idol
#

hm its still acting a bit weird but it's way better than before

#

so milliseconds are 1/1000 of a second right?

#

so 5 seconds would be 5k milliseconds

lost matrix
#

right

haughty idol
#

then why is the cd of one of these 50 seconds and the cd of the top one is like .5 seconds lmfao

lost matrix
#

Sysout the modifier

haughty idol
#

it should be 1.0

#

yep

#
[22:55:26 INFO]: 1.0
[22:55:26 INFO]: 1.0
[22:55:26 INFO]: 1.0
[22:55:27 INFO]: 1.0```
lost matrix
#

They use the same cooldown?

haughty idol
#

i'm so fudging dumb

#

yeah they work now

#

thanks so much

ornate mantle
#

BRUH

#

java version isnt switching from java 8 to java 18

#

changed the environment variables and stuff

#

still stuck on java 8

lost matrix
#

go into terminal and type in java -version

ornate mantle
#

did

#

java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

lost matrix
#

Just install the latest jdk then

ornate mantle
lost matrix
#

Eclipse Adoptium provides prebuilt OpenJDK binaries from a fully open source set of build scripts and infrastructure. Supported platforms include Linux, macOS, Windows, ARM, Solaris, and AIX.

#

Get the installer. It does everything for you.

ornate mantle
#

its german

#

oh i was on the /de page

lost matrix
#

I removed the de edning

ornate mantle
#

yeah

#

miss the good old days when you spent hours debugging stuff and did everything by hand rather than an application doing everything for you

vocal cloud
#

Can do it all by hand if you like lol

young knoll
#

Change the path

#

Not java home

boreal seal
#

intelliJ users

#

cloud explain me what this color says?

#

the getSeconds

#

why its colored that way?

young knoll
#

Deprecated

vocal cloud
#

Hovering it should tell you too

kindred valley
boreal seal
#

oh it doesnt return anything

#

?

kindred valley
#

No the method just deprecated

boreal seal
#

so deprecated stays for in simple english?

#

i cloud google it yeah guys but i want an human being explanation

lost matrix
#

Deprecation means this method is about to be removed and should not be used.
In almost all cases there is a better alternative for that method already implemented.

boreal seal
#

oh

vocal cloud
#

Read the docs for the method to find the better one

boreal seal
#

so the hint it shows me is the better alternative?

vocal cloud
#

Well it might if you have the documentation for it

boreal seal
#

the other thing showed the same thing

#

ill just not give it attention might Date be outdated a bit

#

but its fine

#

i dont see a reason to switch it if it works it works

boreal seal
lost matrix
boreal seal
#

yeah i have so many ways to get correct second

lost matrix
#

What do you need?

boreal seal
#

im just trying to get current second

#

im storing it into an data class i make

lost matrix
#

The current second in which context?

boreal seal
#

int

#

just the second

#

not Hour not day

#

or actually a better question

lost matrix
#

I dont understand. There is no "current second"

river oracle
#

System#getCurrenrMilli

boreal seal
#

yeah i dont need it

lost matrix
#

Unless you are speaking about the unix timestamp

river oracle
#

Should get thr current millisecond

#

Than divide

boreal seal
#

ik we got either nanosecond..

#

i have different goal guys its alright thanks!

river oracle
#

Lol u make no sense

lost matrix
#

Whats your goal? There is 100% a better approach.

boreal seal
#

i already think about making own timing system instead of comparing time...

#

so ill just make in the data class an integar that will be timer

#

i just make a player select a block and be able to execute commands

#

now i was thinking to make a timer to remove him from the block

river oracle
#

Your making a timer? Why not just use a ticker for a timer seems nonsensical to use much else isn't that how timers work after all?

boreal seal
#

instead of checking if he is near all the time

lost matrix
river oracle
#

Alternatively if you don't need per tick updates just compare current millisecond timings

boreal seal
#

but i cloud update it anyway ;/

#

if he selects a different door the hashmap will replace it

#

each time

river oracle
#

Cloud update it? Wrf

lost matrix
#

Always compare timestamps. Never ever manually update a timer.
Its an absolutely horrible idea.

river oracle
boreal seal
#

i dont store in database

#

i store it in hashmap you told me to make own objects to store locations

#

so why dont i make either a timer inside of it and update it

river oracle
#

Oh I wouldn't consider that the cloud lol

#

Mb

young knoll
#

I think it was a mistype of could

river oracle
#

Mf I'm dumb

boreal seal
#

why?

lost matrix
#

Ill just say this one more time and then im off to sleep.
Dont manually increment a timer
Its a really really bad idea. Worst possible performance.
Most possible code fragility and worst sync issues.

boreal seal
#

you understand what i mean now?

boreal seal
#

remove from map

lost matrix
#

Yes. Terrible

#

Te ri ble

boreal seal
#

why its terriable but if i need update value each time

#

what you do compare if value is >

#

and if remove and allow

lost matrix
#

I dont have the willpower to deal with this right now.
Read the message ive posted above. It has a bunch of code you can read through and utilize.

boreal seal
#

ine

#

+=

ornate mantle
#

can i use 1.19.2 nms plugins on a 1.19 server?

undone axleBOT
ornate mantle
#

best answer

#

absolute genius

#

be a shame if i had no way of trying it

young knoll
#

I believe it’s all the same NMS version

river oracle
#

The simplest answer is

#

Depends

ornate mantle
#

depends how

river oracle
#

Depends what you use

#

Depends how it's used and where it's used

ornate mantle
#

i dont think 1.19.1 and 2 added something relating to nms?

river oracle
#

Depends you'd have to check

ornate mantle
#

1.19.1 added allay duplication and chat reports

#

1.19.2 fixed a join bug

river oracle
#

Idk you could try and see if it works

ornate mantle
#

yeah except i cant πŸ’€

river oracle
#

I'd say maybe

ornate mantle
#

you cant join 1.19.2 servers with a 1.19 client

#

yeah maybe

river oracle
#

I mean nms mighttt work across version maybe depending on what you use though I thought those classes couldn't be referenced cross version no Matter what

#

My best advice would be to try and see

ornate mantle
#

another help

#

Unresolved dependency: 'org.spigotmc:spigot:jar:1.19.2-R0.1-SNAPSHOT'

#

using nms

boreal seal
#

damn not gonna read his explanation to the guy who learn java yesterday

#

ill better stick to ways i know

#

damn

ornate mantle
#

lmao

boreal seal
#

im not about it if u look up u will get it

ornate mantle
#

what

boreal seal
#

but 7smile7 tells me to take a look at his high performance cooldown util or what ever

#

now i dont believe u can check 1 million times and server wont feel

#

will do a layer 7 attack on the cpu lmao

#

now in general it will do maybe a really small perfomrance tweak that maybe doesnt even worth the attention

#

i know an guy which converts UUID into binary

#

you know how efficent it will be

#

if you store 1 million UUID in binary instead of the normal way

#

it will save you 10 mb's

#

so sometimes those performance tweaks are dogshit and thanks god i pay for dedicated server and not for shared hosting with half theard lol

young knoll
#

What

eternal oxide
#

lol

#

The "normal way" to store a UUID is as 2 longs. Shortest it can be.

ornate mantle
#

would ServerPlayer#displayName = "balls" set the serverplayer's display name to balls?

young knoll
#

Yes

ornate mantle
#

how do i set location of a serverplayer in nms mojang mappings

boreal seal
#

im wondering

#

where i put those x,y,z for god sake

#

that what my mind told me

#

not sure if its the right that

#

gonna just try it..

scarlet creek
#

I’m trying to make a countdown system but I’m not sure how to go about it. I’m using a runnable and I’m trying to get the counter value that increases whenever the runnable is running

#

Code:

        new BukkitRunnable() {

            // active for 30 secs
            // To Do, have a getter for counter?
            private int counter = 0;
            private int maxCounter = 30;

            @Override
            public void run() {
                // if game end
                if (counter == maxCounter || playerQueueStatus.getQueueSize() < playerQueueStatus.getMinQueueSize()){
                    cancel();
                    Bukkit.broadcastMessage("" + ChatColor.GOLD + ChatColor.BOLD + "Game Ended!");
                }
               
                counter ++;
            }

        }.runTaskTimer(plugin, 0, 20);
    }```
#

Unfortunately it’s not as simple as creating a getter inside the method.

agile anvil
#

move your counter outside the runnable

#

btw if you're creating a game mode, it's easier to have one task running and put everything in it

scarlet creek
scarlet creek
oblique geyser
#

Hey, How can I get this part of a player inventory?

agile anvil
manic furnace
#

In my plugin, I serialize data with gson. I have to use a custom-type-adapter, but how do I write one for a map?

agile anvil
oblique geyser
#

Yes I have this but then I get a player inventory, if I cast it to inventory, it return only the 4x9 items?

kindred valley
#

What happends after e.setCancelled(true);

#

does it finishes the code after setting the event cancelled

agile anvil
tall dragon
#

that event will just be set to cancelled and will not happen

agile anvil
oblique geyser
#

Can I do this with player inventory?

agile anvil
#

Well how do you save Inventory ?

#

because it works the same : just save for each slots the item it contains

oblique geyser
#

my problem is not save

#

is load it

#

I suppose I should storage the contents

scarlet creek
quaint mantle
#

the editionNumber part

chrome beacon
quaint mantle
#

?di

undone axleBOT
chrome beacon
#

You did not

#

Also there is a typo on line 21 in DctrSpaceHelm

quaint mantle
#

wait lemme check

quaint mantle
chrome beacon
#

yes

quaint mantle
#

alrighty guess im more drunk now

#

also is there some kind of rule saying that u shouldnt have more than 1 extends java plugin thing

#

wait isnt super. a nms thing

chrome beacon
#

That's a Java thing

chrome beacon
quaint mantle
#

ah

kindred valley
#
public HashMap<String, Integer> theBackSlot(String s, int i) {
        new HashMap<String, Integer>().put(s,i);
        return HashMap<>();
    }```
#

I want to do something like this
everytime method have been called it will create a new hashmap and add the parameters in it and will return it
how can i do that

hazy parrot
#

Why would you do that

kindred valley
#

Complicated

hazy parrot
#

To me it looks like you don't want to use hashmaps

hazy parrot
kindred valley
#

but i am trying to control which slot, player have been came

hazy parrot
#

So why creating new hash map

#

Every time

kindred valley
#

and they are different

hazy parrot
#

Is the slot key or value?

lost knoll
#

When creating a custom entity, I saw that you use the initPathfinding() to add new path finding goals. How would I do that with Mojang Mapping? Also, if there's a doc site where it shows what everything does, it'll help a lot

drowsy helm
#

RegistGoals iirc

#

Let me double check

kindred valley
drowsy helm
#

Yeah registerGaols

kindred valley
#

Δ°magine an inventory has sword, food,block, tool categoires and i am clicking one of them and saving the name of them such as if its sword saving the "sword" string and the slot sword is on.

scarlet creek
#

I'm trying to make a minigame timer, however when I added a static to the values that increase in the runnable, every time I activate the runnable, it sends the time left on the countdown one more time to the player.

#
    static int maxCounter = 30;```
#

doing cancel; stops and deletes a runnable right?

agile anvil
#

It's easier to create a single runnable that loop for a the game long

#

instead of creating multiple

#

but yes cancel stop the task

scarlet creek
#

Hmm if that’s the case, it can’t be that I have runnables that aren’t stopped

#

So I’m confused why it is outputting the countdown more than once

agile anvil
#

?paste your code

undone axleBOT
scarlet creek
jade knot
#

Is PluginMessageListener working as async?

agile anvil
scarlet creek
agile anvil
#

use depency injection

#

?di

undone axleBOT
agile anvil
scarlet creek
agile anvil
#

that's what i said. creating multiple tasks makes it a lot harder to manage.
you should definitely have only one task that you don't stop

sage dragon
#
java.lang.IllegalArgumentException: x out of range (expected 0-15, got 27)
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:193) ~[guava-31.0.1-jre.jar:?]
        at org.bukkit.craftbukkit.v1_19_R1.CraftChunk.validateChunkCoordinates(CraftChunk.java:362)
        at org.bukkit.craftbukkit.v1_19_R1.CraftChunkSnapshot.validateChunkCoordinates(CraftChunkSnapshot.java:171)
        at org.bukkit.craftbukkit.v1_19_R1.CraftChunkSnapshot.getBlockSkyLight(CraftChunkSnapshot.java:106)
        at me.entity303.tramaniaclasses.listener.BlazeListener.lambda$new$2(BlazeListener.java:64) ~[TramaniaClasses-1.0-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftTask.run(CraftTask.java:101)
        at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

ChunkSnapshot#getBlockSkyLight returns 27?

eternal night
#

?

#

it does not return 27, you feed it an x of 27

sage dragon
#

How exactly am I supposed to feed it with an x of 27 while reading data? πŸ˜…

eternal night
#

?

#

getBlockSkyLight takes x y and z

#

you are feeding it an x of 27

sage dragon
#
                if (chunkSnapshot.getBlockSkyLight(
                        all.getLocation().getBlockX(),
                        all.getLocation().getBlockY(),
                        all.getLocation().getBlockZ()) >= 15)
#

Oooh

#

Ops

#

Sorry, my mistake πŸ˜…

#

Thought it was returning a light level of 27 for some reason

sage dragon
#

Now it always returns 15, no matter what...

Tried one block below, tried one block up, nothing

eternal oxide
#

You are working with a snapshot. Its not going to detect changes

#

the light level will be whatever it was when you took the snapshot

sage dragon
#

Yes, I'm taking the snapshot after the change though

eternal oxide
#

15 I belive is direct sky light

sage dragon
#

Yes, I blocked any light, so it should be 0

#

It's completely dark, as you can see

agile anvil
#

You're inputting a location x y z into a chunk location

#

First get the chunk of the location

#

Take your x y z modulo 15

#

And get the result

tender shard
#

why tf does this always happen

#

why can intellij not understand that its the sources root folder

#

without me marking this explictly as sources root

#

I mean its in src/main/resources lol

#

erm

sage dragon
tender shard
#

I meant src/main/java

agile anvil
undone axleBOT
eternal oxide
sage dragon
agile anvil
#

Uhh

#

AtomicReference 🀧

sage dragon
sage dragon
agile anvil
#

Why do you need it ?

#

Just put your variable inside the task

#

Try to test the SkyLight outside all of your code

tardy delta
#

why the fuck are people calling their player variable 'all'?

burnt sand
#

Can i make a web proxy for my spigot plugin?

tardy delta
#

unless that player's called All it doesnt refer to all the players

agile anvil
#

Like to a BlockPlacdEvent and get a sky light

sage dragon
tardy delta
#

πŸ€”

tender shard
#
for(Player all : Bukkit.getPlayers())

this is fine to me

sage dragon
tardy delta
sage dragon
#

And makes totally sense

tardy delta
sage dragon
tardy delta
#

expression parser progress meh

agile anvil
#

Create a BlockPlaceEvent and try to get its sky light level

tender shard
#

i dont get why people call atomic "shit"

agile anvil
#

Without creating loops, and tasks or whatever

tender shard
#

I mean, what's the problem in using it?

agile anvil
eternal oxide
#

or search the snapshot for ANY block thats not level 15

tardy delta
#

its shitty that you have to use that instead of assigning a variable within a lambda expression

sage dragon
eternal oxide
#

then its down to how you are checking. wrong chunk, wrong coords or something

sage dragon
#

All of these blocks are at chunkX 4, way up in the sky and chunkZ 12 πŸ€”

eternal oxide
#

are you certain there is a block above where you are testing?

sage dragon
eternal oxide
#

then you have no blocks there. 16 is correct

#

exposed to the sky

sage dragon
eternal oxide
#

you just said no blocks were there, they were all air

sage dragon
#

Let's try checking the light when placing a block

eternal oxide
#

you can;t get a snapshot the second you place a block

#

it will not have the block

sage dragon
tender shard
#

ah yes, "half life" icons lol

sage dragon
#

But ChunkSnapshot doesn't

tender shard
#

yes, the block hasnt been placed yet

#

it only gets placed after the event was called

eternal oxide
#

actually I believe the block place is an odd event, it is placed and if you cancel the event it undoes the placement.

#

If I'm remembering correctly

tender shard
#

I just tried to find that part of code but I cant find it lol

agile anvil
#

It's dark magic. It exists but doesn't really exist

tender shard
#

very weird code

#

its indeed some weird "inbetween state" during the actual event

terse ore
#

Hey

#

I am trying to fill a chest with items but only at the center

#

but I can't manage to make it not to fill the right side

#
    public static ArrayList<Integer> getIndexes(int amount) {
        ArrayList<Integer> indexes = new ArrayList<Integer>();
        int index = 0;

        while (indexes.size() <= amount) {
            if (!(index % 9 == 0 || index >= 0 && index <= 8 || index >= 45 && index <= 53)) {
                indexes.add(index);
            }

            index += 1;
        }

        return indexes;
    }```
#

amount is the amount of items the chest is going to have

tender shard
#

check if (index + 1) % 9 == 0

sage dragon
tender shard
agile anvil
#

Index % 8 == 0

tender shard
#

I dont think that would work

agile anvil
#

Since sides are multiples of 8 and 0

tender shard
#

it would return true for the 16th slot which is not on the right side

agile anvil
#

Oh yeah also 9

terse ore
sage dragon
#

Let's just skip the light test then 🀷

Works just fine without it...

agile anvil
#

index % 8 for right side and index % 9 for left side

terse ore
#

17 % 8 == 0 != true

#

it would work if the chest were of 8 width

agile anvil
#

Indeed

tender shard
#

tbh I'd just hardcode the borders as quick fix lol

agile anvil
#

My brain doesn't want to work today

tender shard
#

int[] illegalSlots = { 0, 8, 9, 17, ... };

#

easiest solution πŸ˜„

agile anvil
#

index % 9 == 0 || index % 9 == 8

#

Finally

tender shard
#

i usually have a MenuPosition class that uses int row and int column

#

so I can just check if column is 0 or 8

#

?paste

undone axleBOT
agile anvil
#

That's quite the same actually

tender shard
tender shard
terse ore
#

now I have this error

#
[14:22:44 ERROR]: Could not pass event InventoryClickEvent to EcoEnchantsInterface v1.0
java.lang.ArrayIndexOutOfBoundsException: null```
agile anvil
#

Show the code again pls

terse ore
#
...
if (!(index % 9 == 0 || index >= 0 && index <= 8 || index >= 45 && index <= 53 || (index + 1) % 9 == 0)) ...

tender shard
#

yeah code like this is horrible, why not just wrap the slot into some kinda object

#

then just check if the column is 0 or 8

agile anvil
#

Or add a index > 53 in your ! Check πŸ˜‚

tender shard
#

I hate slot numbers

dusk flicker
#

arent there also numbers for the crafting grid?

tender shard
#

i dont know, I made this for angelchest which doesn't care about the crafting stuff

dusk flicker
#

oh cool

tender shard
#

but yeah IIRC the crafting grid is 41-44 and the result is 45

hazy parrot
#

Why not like

for(int i=10; i<37; i+=9){
 for(int j = i; j<6; j++)    {
  setItem(i+j, item);
} 
}

Might be wrong cuz I'm on phone but something similar

#

If that is considered "center"

tender shard
#

I'd still just do it like this πŸ˜›

        for(int i = 0; i < inv.getSize(); i++) {
            GUIUtils.MenuPosition pos = GUIUtils.slotToPosition(i);
            if(pos.getRow() == 1 || pos.getRow() == 6) continue;
            if(pos.getColumn() == 1 || pos.getColumn() == 9) continue;
            // Do stuff
        }
warm mica
#

I hate to work with slots. Simply do the following.

int slot = ;
int x = slot%9;
int y = (int) (slot/9);

int slot = x + y*9;

This is making it so much easier

visual tide
#

bukkit's inventory api sucks in general

shell finch
#

is there a way to set an entity or a player to a riptide state?

tender shard
visual tide
#

is it gonna be null? is it gonna be Material.AIR?
who fucking knows?

tender shard
#

yeah that's so random

#

it's also funny how the amount of AIR is always 0

#

like

visual tide
#

yah

tender shard
#

if I have 0 air, then it's not actually air, I guess?

#

I could understand it if it at least would be 1 air

#

but 0 air?

warm mica
#

Ig nothing would be a better name

terse ore
#

how do I check if an int is inside

    private static int[] illegalSlots = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 27, 36, 45, 17, 26, 35, 45, 53, 46, 47, 48, 49, 50, 51, 52};
    ```
warm mica
#

Otherwise Arrays.binarySearch(array, entry) >= 0

warm mica
drowsy helm
#

probs want an immutable set

tender shard
#

isnt Arrays.asList immutable?

#

so why put it into a set

drowsy helm
#

new HashSet<>(list) will make it mutable again right?

tender shard
#

yes

#

but why put it into a set in the first place

#

i mean it will only ever have like 8 entries or so

drowsy helm
#

trying to over optimise

tender shard
#

yeah it's a waste of time to even think about "is a list or a set better" lol

sterile token
#

What better a list or set?

tender shard
sterile token
#

I always make that question

tender shard
#

if someone really wants to overoptimize this, then just use a switch case

visual tide
#

:concerned:

drowsy helm
#

lmao

tender shard
#

i guess this would indeed be the fastest way

sterile token
#

What the best way for disabling a logger from another library?

#

For example I want to disable JDA logger

#

Because its really painfull to see that ugly Messages

tender shard
#

logback.xml

sterile token
#

?

#

Explain detailed please

tender shard
#

with this, JDA only logs "info" stuff (and higher, like WARN and SEVERE) while my own stuff also logs "debug" stuff

sterile token
#

I cannot do that

#

Because im using it as maven dependency

#

😬

#

Also why the heck Logger.getLogger("paxkage.logger.Class").setLevel(Level.OFF); doesnt work with JDA when with mongo works perfect

#

Sometime java coding its really weird

dusk flicker
#

I feel like turning off logging is just a bad idea in general

tender shard
#

yeah

#

although JDA indeed prints many useless stuff

shell finch
#

How could I get a player to be able to use a bow even without arrows in their inventory? is that possible or is that fully client side?

dusk flicker
#

I would think that would probably be clientsided; might be a way to do it with packets

sterile token
dusk flicker
#

personally when they rightclick with the bow I would just give them an arrow and cancel the event when done

tender shard
sterile token
#

Oh thanks mfalex