#help-development

1 messages · Page 1660 of 1

paper viper
#

Component.text("I am red!", NamedTextColor.RED)

#

or other ways to specify the color

silver shuttle
#
            if(!(Objects.requireNonNull(e.getCurrentItem()).getType().equals(Material.valueOf(config.getString("gui.sell-item-1"))))) {
                if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-2"))))) {
                    if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-3"))))) {
                        if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.buy-item-1"))))) {
                            if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-2"))))) {
                                if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-3"))))) {
                                    e.setCancelled(true);
                                }
                            }
                        }
                    }
                }
            }

Is there a way of shortening this?

paper viper
#

wtf

tardy delta
#

Objects.requireNonNull again brrr

paper viper
#

have you ever heard of variables?

silver shuttle
paper viper
#

if you stored them into a variable it would look way less terrifying

paper viper
#

it greatly helps

tardy delta
#

thats alot of ifs

paper viper
#

If you used variables, and used &&

#

it would fix it

tardy delta
#

is a switch possible with own classes?

silver shuttle
#

I don't need to define a variable if i only call it once

paper viper
#

Store e.getCurrentItem() as a variable, null check it. Then store getType()

paper viper
silver shuttle
#

oh you mean that

paper viper
#

And also store config.getString("gui.sell-item-2") and related components as variables

silver shuttle
#

only call those once ^^

paper viper
#

then you are left with only type.equals(Material.valueOf(str))

#

much simpler

#

and you can use &&

#

much cleaner

silver shuttle
#

ugh I hate long lines

paper viper
#

Do you want if statement hell tho..?

silver shuttle
#

nah

paper viper
#

thats much worse

#

u know right

silver shuttle
#

I'll do what u said, ty

paper viper
#

np

stone sinew
#
List<Material> materials = Arrays.asList(Material.valueOf(config.getString("gui.sell-item-1")), Material.valueOf(config.getString("gui.sell-item-2")));
ItemStack item = e.getCurrentItem();
if(item != null && materials.contains(item.getType()))
    e.setCancelled(true);
ancient plank
#

if u format correctly long if statements using && / || aren't that hard to read

paper viper
#

ImmutableSet.of()

#

or Set.of() (for later java versions)

stone sinew
#

Either can be used. Its up to him

young knoll
#

But speed

paper viper
#

Yeah

#

and also Immutability

#

its full immutability

stone sinew
#

Again though... up to him lol

paper viper
#

not really up to him tho

#

if the benefits are greater

#

lol

hasty fog
#

Isn't calling config methods every time equal to nuking the server?

young knoll
#

Not really

#

Yaml files are cached

hasty fog
#

ah makes sense

paper viper
#

And its not a constant IO operation

#

for each get

young knoll
#

It does do a bit of string manipulation before calling map.get

#

But it’s not that bad

tardy delta
#

smh

hasty fog
#

I just store them at startup or reload anyway to be sure

hasty fog
paper viper
#

nuker hacks

tardy delta
#

spawn a few million tnt

stone sinew
#

Didn't 1.16 change the way TNT works so it only blows up layers at a time or something like that

paper viper
#

but why wouldnt you lol. We want to tell people to do it the better way xD

hasty fog
#

Life will also be much easier when fixing bugs or updating

stone sinew
#

Its preference

paper viper
#

that analogy doesnt make any sense lol

hasty fog
#

Parachute is quite safe

stone sinew
stone sinew
paper viper
#

and by safe immutable

#

😉

quaint mantle
#

Alright, thank you very much! Would a vanilla sound name work with the string method?

paper viper
#

If you want to use a vanilla sound, you can just use the Sound enum

#

custom sounds, however, must use String

stone sinew
#

I think there is Player.isEntityInView(Entity)

hasty fog
#

You'll have to do some testing, could also be view distance

young knoll
#

You could get the vector between the two and then trace along it

stone sinew
tardy delta
#

is there a difference between Bukkit.getServer and plugin.getServer

young knoll
#

No

paper viper
#

Use Bukkit.getServer inside static methods

#

and plugin.getServer for normal use

#

(the latter is better in terms of OOP if you use it with plugin instance DI)

tardy delta
#

oki

paper viper
#

keep static with static, and oop with oop methods (with the exception of utility methods of course)

#

but Bukkit.getServer isnt a utility method

stone sinew
#

Anyone know how to stop end worlds from creating DragonBattle when a player joins the world?

#

I've tried everything including NMS.

if(e == Environment.THE_END) {
    try {
        WorldServer ws = ((CraftWorld) w).getHandle();
        final Field field = ws.getDimensionManager().getClass().getDeclaredField("createDragonBattle");
        field.setAccessible(true);
        Field modField = Field.class.getDeclaredField("modifiers");
        modField.setAccessible(true);
        modField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(ws.getDimensionManager(), false);
        ConsoleOutput.debug(ws.getDimensionManager().isCreateDragonBattle()+"");
                
        /*Field prevKilled = ((CraftWorld) w).getHandle().getMinecraftWorld().getDragonBattle().getClass().getDeclaredField("previouslyKilled");
        prevKilled.setAccessible(true);
        prevKilled.set(((CraftWorld) w).getHandle().getMinecraftWorld().getDragonBattle(), true);
        ConsoleOutput.debug(prevKilled.get(((CraftWorld) w).getHandle().getMinecraftWorld().getDragonBattle())+"");*/
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) {
         e1.printStackTrace();
    }
}
knotty ruin
#

Cancel the spawn event of the ender dragon

#

ok well

stone sinew
knotty ruin
#

hm ok well I can’t read the code since I’m on phone

quaint mantle
#

Is it possible to do X:{A: 10, B:{name: "Hello world"}} in NBT data with Persistent Data Container?

eternal oxide
stone sinew
eternal oxide
#

But does it stop the portal being created?

#

as the portal is only created when the dragon dies

stone sinew
near aurora
#

Hello, quick question dose anyone know any good resources for webhooks within Spigot as I'm trying to send a request from my website.

stone sinew
young knoll
#

The portal is created with worldgen now

eternal oxide
#

yes, it creates the landing pad for the player

stone sinew
young knoll
#

It creates the exit portal too

#

Killing the dragon just activates it

eternal oxide
#

it does? That should not happen

young knoll
#

Yes it should

eternal oxide
#

the exit portal only appears when teh dragon dies

young knoll
#

Not since the dragon fight rework

eternal oxide
#

ah. I've not fought the dragon since then

stone sinew
tardy delta
#

i see no magma cube one

young knoll
#

I don’t see why it would be only for one

ancient plank
#

best link

tardy delta
#

😌

shadow skiff
#

ok so My server is under attack constantly by a group called [REDACTED] I have a plan to stop them from joining the server, however my code doesn't seem to work. Basically it's supposed to check their name for a banned word in this case all the clients that join have the name [REDCATED]pw(some random charaters). (the name isn't actually [REDACTED] but to protect anyone else I choose not to say the name)

package me.Teric7.Namekick;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {
  public void onEnable() {
    saveDefaultConfig();
    Bukkit.getPluginManager().registerEvents(this, (Plugin)this);
  }
  
  @EventHandler
  public void onLogin(PlayerLoginEvent e) {
    boolean containsBanned = false;
    for (String s : getConfig().getStringList("banned-words")) {
      if (e.getPlayer().getName().toLowerCase().contains(s.toLowerCase()))
        containsBanned = true; 
    } 
    if (containsBanned)
      e.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("kick-msg"))); 
  }
}
unreal quartz
#

damn, what a really intimidating group name

shadow skiff
#

lol

tardy delta
#

😂

#

ban them not kicking

shadow skiff
#

it's not kicking them either that's the issue

unreal quartz
#

PlayerLoginEvent#disallow

#

don't kick them

maiden briar
shadow skiff
hybrid spoke
tardy delta
#

loll

young knoll
#

Why not just use the built in ban system

rigid hazel
#

Hello. Can someone help?

regal lake
#

How i can stop a timer within the function ?
I create a timer in the PlayerDropItemEvent and want to stop that timer as soon the item is on the ground or it was picked up or despawned.
But how can i stop the Time within the function ?
Something like that: https://paste.md-5.net/uzetagexas.java

grim ice
#

@shadow skiff who r these tho

young knoll
regal lake
#

What do you neam with "task" ?
Do you mean new Runnable?
Okay i got it

rigid hazel
#

Can someone help please?

paper viper
young knoll
#

Or any name really, it’s a variable

rigid hazel
#

Tell me.

regal lake
#

Yeah i got it, you mean the parameter 😄

#

Thanks!

hasty fog
paper viper
#

the code is also messy because you arent use Adventure properly

#

and a ton of repetition

#

so its hard to read

rigid hazel
paper viper
#

Component message = Component.text("§6Möchtest du dich zu deiner Gilde teleportieren?\n");

#

you are literally using it

#

and also its the wrong way

#

do not use color codes like that inside Component

rigid hazel
#

But that's not the point.

#

The code isn't the problem!

#

After unloading a chunk and loading it again, the on interact events don't do anything!

narrow furnace
#

not the problem

rigid hazel
#

Is this too hard to understand?

narrow furnace
#

still a problem

rigid hazel
#

And how can I solve it?

#

7smile7 helped to fixed it with a beacon by using tile states, but normal block don't have tile states

#

Just help, please.

narrow furnace
#

who are you talking to?

#

do you think people know the answer and are just refusing to tell you?

#

are you trying to persuade them to tell you the answer?

#

if someone here knew how to help they would

rigid hazel
narrow furnace
#

thats not an answer

quaint mantle
#

jesus

hasty fog
#

we also aren't obligated to help you or something

paper viper
#

i just dont feel like helping...

#

because of that attitude

hasty fog
#

take a chill pill

paper viper
#

we dont get paid lol

#

its discord

#

we dedicate our time

narrow furnace
#

or we dont

tall dragon
paper viper
#

!!

#

Damn man

#

i thought it was a full time job

rigid hazel
#

What?! I thought!

quaint mantle
#

gigachad Volunteer

tall dragon
#

sheesh im out man

ancient plank
#

I get paid 20$/hr I spend on a project!

quiet ice
#

you better be

ancient plank
#

joking

quiet ice
#

Discord is a waste of time

quaint mantle
ancient plank
#

I made a program to ratelimit my wpm

maiden briar
rigid hazel
#

?ask

undone axleBOT
#

If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.

wintry pumice
#

whats the standard way to do local chat, just hook to asyncplayerchatevent and filter from there ?

rigid hazel
#

I will.

wintry pumice
#

cool

#

and i'm reading that the event locks the main thread if a plugin triggers the event. If i'm the only plugin on the server and I never trigger a player chat event, the main thread shouldn't ever block right

stone sinew
wintry pumice
#

reading this

young knoll
#

Are you triggering the event

hasty fog
#

Will only be sync if you make a player chat, but wouldn't do that using the event

wintry pumice
#

i dont, i just want to make sure theres nothing else if i have no other plugin loaded that could be triggering it

young knoll
#

No

wintry pumice
#

cool

#

tyty!!!

stone sinew
#

Ok so when I join a end world it runs EnderDragonBattle.b() But I can't find in spigots code where this is ran. Any ideas?

young knoll
#

It’s probably not in spigots code

#

It’s from the server

bright quartz
#
                    Player p = Bukkit.getWorld("BirchForest").getPlayers().get(1);
                    p.teleport(worldManager.getMVWorld("BirchForest").getSpawnLocation());
                }``` anyone know why this isn't kicking me?
#

doesn't error, just doesn't kick me

reef wind
bright quartz
#

nevermind i'm blind 😐

tall dragon
#

huh

bright quartz
#

just realized what i did wrong

#

i am the smartest individual

reef wind
#

1: indexing starts at 0
2: why would you use a hardcoded index instead of i?

tardy delta
#

why not just Bukkit.getWorld(...).getPlayers().foreach(player -> player.tp to spawn)

reef wind
#

he doesn't know foreach exists

tardy delta
#

its easier

reef wind
#

ofc

tall dragon
#

well you could choose not to. to preserve memory

#

but it doesnt matter too much

tardy delta
#

doesnt use a for loop a foreach internally?

#

or something idk

wintry pumice
#

the compiler should optimize them both to be the same

#

its just stylistic

reef wind
#

the latter is also less code

wintry pumice
#

which isnt always a good thing

reef wind
#

when is more code = better

wintry pumice
#

when it's easier to read

#

lambdas are harder to parse and read

stone sinew
wintry pumice
#

and its more accessible for more people to work on your code

reef wind
#

in that case yes

wintry pumice
#

ye

#

so its not always better, it's just stylistic and depends on the case

tardy delta
#

whats the difference between also calling the new int[]?

int[] numArray = {10, 20, 30, 40};
vale ember
#

how to make chest look like opened and then close it, i googled but dont found working way, i am on 1.17.1

tall dragon
wintry pumice
#

i was gonna say break early but doesnt java9+ have takewhile

#

i forget these things

tall dragon
#

well you can use class state variables

#

but thats just ugly 🙃

winged bronze
#

how can i wait in an playdropitemevent until the velocity of the item 0 is?

eternal oxide
#

You can't

#

The drop item event is cancelable so it fires before teh item is spawned

#

all you can do is run a timer and watch for it

winged bronze
#

sooo how would i run a timer like that

vital shale
#

Helli

#

I need help.

quiet ice
quaint mantle
quaint mantle
undone axleBOT
#

If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.

quiet ice
#

No. You may not recieve help.

quaint mantle
quaint mantle
vital shale
quiet ice
#

It is an unspoken rule that existed for millenia that #help-development is NOT for help.

ancient plank
#

my name isn't help

quaint mantle
#

ask the damn question

quiet ice
#

Naysayers shall be executed

vital shale
#

I can't join non default server jn bungecord

quaint mantle
#

ok nvm yeah u cant get help sry

quiet ice
#

See, you may not recieve help here

eternal oxide
undone axleBOT
eternal oxide
#

um

#

about time you slow ass bot

winged bronze
#

thanks

ancient plank
#

lol

quaint mantle
#

i cant send a msg for like 2 seconds

eternal oxide
#

same

narrow furnace
#

🤔

#

is that discord or just this server

#

i thought it was me but apparantly not

unreal quartz
#

nah its u

quaint mantle
#

no i tihkn its discor§d

fiery inlet
#

Let's say i've got an event.getItem()
How do I get the stack size of that item.
And not the max stack size of given item, but the actual amount of the item is of the item.

lost matrix
deep elk
#

i have a question

deep elk
#

i cant access any plugins on spigot mc

#

it just gets stuck on cloudflare page

lost matrix
deep elk
#

but i turned it off but still no work

lost matrix
#

How long did you wait?

deep elk
#

nothing happened

lost matrix
#

Try restarting your browser. This usually only happens if your IP is untrusted.

deep elk
lost matrix
#

But sure. Try another browser.

sleek pond
#

anybody know why scoreboard team prefixes / suffixes don't show up in chat?

#

and if there is any way to do so?

vital shale
#

Helli

unreal quartz
#

hellicopter

quaint mantle
chrome beacon
#

He does

vital shale
#

Yea

chrome beacon
quaint mantle
vital shale
#

?

ivory sleet
#

It would

chrome beacon
#

It will continue

#

Why does it take like 2 seconds to send a message :c

#

Don't name your class Main ;/

ivory sleet
#

Why is that async

#

Feels like its gonna explode

chrome beacon
#

You should name it something else. It's not the main class of an application

#

I recommend naming it the same as your plugin

#

Well what's inDistance and explodeItem

#

How are you checking if it's running more than once

#

Then how you know it's not

ancient plank
#

I weirdly name the main class of my applications Core over using Main

grim ice
#

just close that specific tab

#

and open another tab, enter the link then done

#

guys

#

how do i create particles at a player line of sight

#

and get the player object of whoever touches the particles

eternal oxide
#

player.getEyeLocation().getDirection()

grim ice
#

would be really useful if someone knows a way to do this, thanks!

#

o

eternal oxide
#

gets you a vector

#

you can loop a location and add that vector over and over to spawn particles

unreal quartz
ancient plank
#

kek

ancient plank
grim ice
ancient plank
#

y not

ancient whale
#

Hey, I'm looking forward getting any left click from a player client side (not with any event as the server cap it beyond ~10 cps) I guess using protocol lib is the best bet but I couldn't find any packet working as I intend so far (tried USE_ITEM & USE_ENTITY) any ideas ? 🙂

deep elk
#

i cnt download any plugin

lost matrix
chrome beacon
#

Nothing you can do unless you force them to use a mod

lost matrix
ancient whale
ancient whale
grim ice
#

it is possible

#

olivo is bsing

#

i saw it in a server lol

chrome beacon
deep elk
lost matrix
chrome beacon
lost matrix
grim ice
#

can someone spoonfeed me i wanna make particles go thru a player line of sight until they hit a player

#

i dont wanna learn vectors

#

itll be a one time use and ill never use that shit of math again

chrome beacon
#

Learn Vectors

eternal oxide
#

No then. If you don;t want to learn

grim ice
#

ah shit do i have to do that chunk of math for a spigot plugin

lost matrix
grim ice
#

oh god\

chrome beacon
#

Vectors aren't hard

eternal oxide
#

Spigot does it all for you anyway

grim ice
#

Location start = player.getEyeLocation();
Vector direc = player.getEyeLocation().getDirection();
for (double i = 0; i < 10 ; i += 0.5) {
direc.multiply(i);
start.add(dir);
start.subtract(dir);
direc.normalize();
}

#

is what i got

#

from reading forum posts

eternal oxide
#

not quite

grim ice
#

i kinda understand it but not much

#

like the for loop idk why its there

eternal oxide
#
Location loc = player.getEyeLocation().clone();
Vector dir = loc.getDirection();

for (int i = 0; i < 10; i++) {
    loc.add(dir);
    loc.getWorld().spawn blah...
}```
grim ice
#

yeah but like

#

why is the loop

eternal oxide
#

to spawn each particle

grim ice
#

ohhhhhhhhhh

eternal oxide
#

each loop it adds the direction to the loc and spawns a particle

#

as getDirection() returns a unit vector (length of 1) it will increase loc by 1 in that direction each time you add

grim ice
#

OH BTW

#

the teams thingy

#

leaders.clear(); will clear everything right

#

or just leaders?

eternal oxide
#

everything

grim ice
#

pog as i wanted

#

how to create a placeholder for servers to use in tab

lost matrix
grim ice
#

h o w

lost matrix
grim ice
#

i read that

#

and thats not what i wanted to do

#

you see when he used &f%vault_rank%

#

i want to let people do that with a placeholder i make

lost matrix
grim ice
#

everywhere

lost matrix
#

Then you need PlaceholderAPI

grim ice
#

like in tab

#

Yeah i have it imported to my plugin

#

i added the maven dependency etc

#

now what do i do

lost matrix
#

Read the docs. It doesnt get better documented than this. You can almost copy paste your way through.

quiet ice
#

Provided you have larger amounts of java knowledge

#

I remember when I started with spigot I wanted to use PAPI but had no idea how even after reading the docs. But I haven't really done that much java up until that point

grim ice
#

can you please tell me how to use it instead of this

#

this isn't helpful :D

hasty fog
#

And look at the "Without a Plugin" section

#

Oh I mean With a Plugin (External Jar)

lost matrix
#

I think he uses maven

grim ice
#

The identifier is the string after the starting % and before the first _ (%identifier_values%) and, therefore, cannot contain _, % or spaces.
Wtf is he saying though

#

yes i use maven

lost matrix
grim ice
#

aha

#

what is params

lost matrix
#

Params are the arguments that can be provided by using underscores after the identifier.
You should for now ignore them and write a simple %placeholder% without any underscores.

grim ice
#

o

#

so what do i do

#

this is confusing

lost matrix
#

Do you use maven?

grim ice
#

yes

lost matrix
#

Did you add the PlaceholderAPI to your dependencies and set the scope as provided?

grim ice
#

yes

lost matrix
#
  1. Create a class. SomeExpansion(You name it somehow) and let it extend PlaceholderExpansion
grim ice
#

ok

lost matrix
#
  1. Implement all methods
public class SomeExpansion extends PlaceholderExpansion {

    private final SomePlugin plugin;
    
    public SomeExpansion(SomePlugin plugin) {
        this.plugin = plugin;
    }
    
    @Override
    public String getAuthor() {
        return "someauthor";
    }
    
    @Override
    public String getIdentifier() {
        return "example";
    }

    @Override
    public String getVersion() {
        return "1.0.0";
    }
    
    @Override
    public boolean persist() {
        return true; // This is required or else PlaceholderAPI will unregister the Expansion on reload
    }
    
    @Override
    public String onRequest(OfflinePlayer player, String params) {
      // Compute and return your placeholder here
    }
}
grim ice
#

o

lost matrix
#

onRequest is called whenever a placeholder is being replaced. So there you return your String based on the OfflinePlayer

grim ice
#

uh

#

what

lost matrix
#

Just implement all the methods:
getAuthor() -> return your author name
getIdentifier() -> return what should be in between the % chars. So here it would be %example%
getVersion() -> Whatever you want. Use 1.0.0
persist() -> true
onRequest(OfflinePlayer, String) -> return your replacement value

grim ice
#

so if i wanted a %teamvalue% get replaced with smth from config

#

how would i do that

#

i did implement them

lost matrix
#

getIdentifier() -> return "teamvalue"
onRequest() -> return teamvalue based on that OfflinePlayer

#

If you implemented everything then simply add this to your onEnable:

        // Small check to make sure that PlaceholderAPI is installed
        if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
              new SomeExpansion(this).register();
        }

Then you are done.

grim ice
#

o

#

but why OfflinePlayer

#

w h a t

lost matrix
#

Because placeholders can be called for values related to OfflinePlayers.

vale ember
#

how to make creeper firework?

grim ice
#

my thing doesnt have any thing to do with players

#

only with config

lost matrix
#

Then just return a value from a config and ignore the arguments. Nobody forces you to use them.

grim ice
#

ok

#

wattt

#

wait

#

wait

#

how do i get the player thats using the placeholder rn

lost matrix
#

That would be the OfflinePlayer then

grim ice
#

basically im trying to show the player a config thingy in tab

grim ice
lost matrix
#

Unless you want to use it yourself in other plugins.

grim ice
#

o

#

no

#

but like

#

i want to get some info related to a player seeing the place holder

lost matrix
#

Thats the OfflinePlayer

grim ice
#

o

lost matrix
#

Wait.

#

Yes, should be.

grim ice
#

ok

lost matrix
#

Its been a while since ive used this

grim ice
#

so i fi u se %teamnumber% in tab

#

it will show the config with the player unique id :

#

public String onRequest(OfflinePlayer player, @NotNull String params) {
// Compute and return your placeholder here
return plugin.getConfig().getString(String.valueOf(player.getUniqueId()));
}

eternal oxide
#

I added a placeholder in GroupManger to allow that placeholder to perform a permission check

#

use somethgin similar

lost matrix
#

Stop using configs on runtime. You will screw up half of your code with this.

grim ice
#

what

#

how

#

what im doing here is

#

im assigning a number

#

to a arraylist

#

of player unique ids

#

so the number is shown when u use that placeholder

lost matrix
#

You should use your config only at one place: In a config manager that loads your data when the server starts.
After that you dont touch your configs.

grim ice
#

then how

#

aaaaaaaaa

grim ice
lost matrix
#

Load your data out of those ugly config files and create properly structured classes. Load from them once then throw them in the garbage.

grim ice
#

but im not using configs much

#

what can it even do

eternal oxide
#

only config if your info changes rarely and needs to persist over restarts

grim ice
#

but

#

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

eternal oxide
#

there is no but

grim ice
#

ok i cant use configs then

#

ok then what can i even do

#

i want to stick a number to a list

eternal oxide
#

if your data is per session then in memory

grim ice
#

and show thaat number when using a data holder

#

btw the list gets cleared when server restarts

eternal oxide
#

you add the players UUID to a list

#

then to get their place in the list it list.indexOf(UUID)

lost matrix
grim ice
#

uhhh

#

btu

#

but

#

the placeholder class is alr extending smth

eternal oxide
#

you don;t extend

#

you use a getter to get whatever info you need

grim ice
#

yeah i was just about to do that

#

protected static Map<List<UUID>, Integer> number = new HashMap<>();

#

so uh

#

i want to link the team (list of uuids) to an integer

eternal oxide
#

god no

grim ice
#

w u t

eternal oxide
#

each team has a leader who has a UUID

grim ice
#

protected static Map<UUID, Integer> number = new HashMap<>();

#

ok

paper viper
#

why

#

why static

eternal oxide
#

why do you want a number?

paper viper
#

why protected

grim ice
quartz pike
grim ice
#

numerized? my english died

eternal oxide
#

when are you going to use teh number?

grim ice
#

place holder

eternal oxide
#

like team 1, team 2 ?

grim ice
#

yes

eternal oxide
#

then you still don;t need any of that

grim ice
#

o

eternal oxide
#

you find what leader they are under (with the util method you should already have written) then leaders.indexOf(leader)

#

it will give you the team index they are in

grim ice
#

oh my god im so dumb

eternal oxide
#

1,2,3 etc

grim ice
#

im so fucking dumb aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

eternal oxide
#

yes, get teh keySet

#

indexof works on arrays

grim ice
#

key set isnt an array Shrug

#

jk

#

toArray()

#

wait

paper viper
#

?

eternal oxide
#

Create a util method to do all that for you. Kepe your code tidy

burnt current
#

Hey! Does anyone happen to know how to set the direction of stairs? I have already tried with the following code:

location.add(1,4,4).getBlock().setType(BRICK_STAIRS);
                Stairs stairs1 = (Stairs) player.getWorld().getBlockAt(location.add(1,4,4)).getBlockData();
                stairs1.setFacing(BlockFace.WEST);
                player.getWorld().getBlockAt(location.add(1,4,4)).setBlockData(stairs1);

but then I get the following error through the console: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData cannot be cast to class org.bukkit.block.data.type.Stairs

This refers to the following line:
Stairs stairs1 = (Stairs) player.getWorld().getBlockAt(location.add(1,4,4)).getBlockData();

can anyone help me there by any chance?

grim ice
#

do i get each thing of the set and add it to an array

eternal oxide
#

no

#

you are throwing it away once finished

#

.toArray

grim ice
#

yeah still

next stratus
#

Hey, I'm looking for an event what will let me find what itemstack another item is being dropped onto in the player gui any advice? context: I want to drop a gemstone onto a pickaxe and I'd like to get the details of both itemstacks.

eternal oxide
#

.toArray().indexOf(leader)

grim ice
#

Cannot resolve method 'indexOf' in 'Object'

waxen plinth
next stratus
eternal oxide
#

toArray(new UUID[keySet.size()]).indexOf(leader)

waxen plinth
#
Stairs stairs = (Stairs) Material.BRICK_STAIRS.createBlockData();
stairs.setFacing(BlockFace.WEST);
block.setBlockData(stairs);```
waxen plinth
quartz pike
waxen plinth
#

You mean when a player clicks on an item with another item, right?

next stratus
#

So I wanna get the event when a player drops a book onto a pickaxe

waxen plinth
#

Yeah that doesn't clarify anything

#

Dropped onto as in they drop a pickaxe in the world and then drop a book on it in the world?

#

Or do you mean in an inventory, they click on a pickaxe with a book on the cursor?

next stratus
#

I mean, when a player drops a book onto a pickaxe in their inventory

waxen plinth
#

That's not dropping

next stratus
#

Like drag and drop in the gui

waxen plinth
#

It's clicking

#

And that can be done with InventoryClickEvent

#

You just look at getCurrentItem, the item in the slot that was clicked on, and getCursor, the item on the player's cursor

next stratus
#

I was about to say would getCursor do it 😅

waxen plinth
#

If someone asks you to clarify your question, restating the same thing you said originally doesn't help

#

Be more specific about the context

next stratus
#

Was that to me or someone else?

waxen plinth
#

You

eternal oxide
next stratus
#

oh sorry

#

I'm not good at explaining at times :/

unreal quartz
#

smh, dinotoucher

eternal oxide
#

converting that to an array

next stratus
grim ice
#

UUID[]

eternal oxide
#

Set<UUID> keySet = leaders.keySet();

#

keySet.toArray(new UUID[keySet.size()]).indexOf(leader);

next stratus
#

Redempt, the event doesn't even fire.. hm

#

oh i'm dumb

#

i forgot to register it ahahahaa

grim ice
#

Cannot resolve method 'indexOf' in 'UUID' @eternal oxide

#

same thing lol

eternal oxide
#

?paste code

undone axleBOT
next stratus
#

gradle could do this better 🙂

#

it's a mess

#

maven uses 5 gradle 1, iirc gradle is faster

grim ice
#

@eternal oxide Set<UUID> keySet = leaders.keySet();
ArrayList<UUID> list = keySet.toArray(new UUID[keySet.size()]);

#

its not big

eternal oxide
next stratus
#

@waxen plinth i forgot to register it all along 🥲

grim ice
#

Required type:
ArrayList
<java.util.UUID>
Provided:
UUID[]

eternal oxide
#

why? no you are creatign an array

grim ice
#

bro

#

there is no indexOf in arrays

unreal quartz
#

what are you trying to do

next stratus
#

the listener 🥲

grim ice
waxen plinth
#

Incredible

next stratus
#

ikr

#

it works now tho ty

unreal quartz
eternal oxide
grim ice
#

LOL

grim ice
#

arraylist

#

of a set

unreal quartz
#

new ArrayList(Set)

narrow furnace
#

swear you could have done every link in ?learnjava in the time youve spent getting help here

unreal quartz
#

make sure you're shading whatever that dependency is

eternal oxide
#

ArrayList<UUID> list = new ArrayList<>(keySet);

#

then you can do indexOf

#

also change yoru Map to LinkedHashMap<UUID, List<UUID>> leaders = new LinkedHashMap<>();

#

So the ordering remains the same

grim ice
#

o

quaint mantle
#

Hello so i'm asking for how to code player ID permanent
for one player
ond other player give them another id

grim ice
#

@eternal oxide but how do i get the leader of the team the player is in

quaint mantle
#

is that posible?

grim ice
#

wait nvm im dumb

eternal oxide
#
    public int getTeamIndex(UUID leader) {

        Set<UUID> keySet = leaders.keySet();
        ArrayList<UUID> list = new ArrayList<>(keySet);
        
        return list.indexOf(leader);
    }```
quaint mantle
#

ID 1 - 2 - 3 - 4 -5 -6 @unreal quartz

#

give it for players

narrow furnace
#

uuid?

unreal quartz
#

you're asking a very broad question

quaint mantle
#

just give a player a random number and don't give it for onther player.

unreal quartz
#

that is the entire purpose of UUIDs

narrow furnace
#

uuid.

eternal oxide
tacit drift
quartz pike
quaint mantle
#

i want to list players they joined first player to last player

#

first player gets 1

#

and last player gets idk the number

quartz pike
#

i know what you want

unreal quartz
quartz pike
#

just learn java

tacit drift
quartz pike
#

this is not make a plugin and then learn java . it's the other way around

unreal quartz
#

then you did not shade it in

grim ice
#

for (UUID key : leaders.keySet()) {
if (leaders.get(key).contains(player.getUniqueId())) {
leaders.get(key).remove(player.getUniqueId());
inTeam = true;
}
}

#

i have dis tho

#

1s

unreal quartz
#

you don't shade spigot

eternal oxide
#
    public UUID getLeader(Player player) {
        
        for(UUID uid: leaders.keySet()) {
            
            if (leaders.get(uid).contains(player.getUniqueId())) return uid;
        }
        return null;
    }```
vale ember
#

why firework.detonate() makes just dead particles

tacit drift
#

so why tf does maven return at "package" that there are 100 erors in classes

#

and when i open one of the classes

#

they are fine

unreal quartz
#

because spigot doesnt shade whatever discord dependency you're using so it is not available at runtime

#

thus you must do it yourself

tacit drift
#

do not shade spigot

unreal quartz
#

then you've added it to the wrong location or you copies the java files not the compiled class files

tacit drift
#

shade the webhook client thing

#

should work

#

worked for me for JDA

grim ice
#

?paste

undone axleBOT
grim ice
eternal oxide
#

line 14 return getTeamIndex(key)

#

16 return null

#

scrap 11

#

or 16 return ""

#

You don;t want to be calling getTeamIndex (null)

vale ember
grim ice
#

o

grim ice
#

now how do i register the place holder

tacit drift
#

yeah so i think it was because of paper @unreal quartz , wierd

#

tried with spigot, it was fine :))

lunar schooner
#

TIL, there is a limit on class name length in java

#

...which does not compile due to:

YTMFrontendSearch$Content$TabbedSearchResultsRenderer$Tab$TabRenderer$Content1$SectionListRenderer$Content2$MusicShelfRenderer$Content3$MusicResponsiveListItemRenderer$FlexColumn$MusicResponsiveListItemFlexColumnRenderer$Text$Run$NavigationEndpoint$WatchEndpoint.class: Class name too long
lunar schooner
#

Blame google for that 🤣

lost matrix
lunar schooner
#

Wanting to deserialize JSON, so I use GSON for that

#

But google's json is worse than most onions in terms of layers

lost matrix
#

But Gson doesnt generate new classes

lunar schooner
#

It doesnt, I handwrote those

#

but GSON can deserialize to that

next stratus
lost matrix
lunar schooner
#

dont blame me for that

#

Google is giving me that json

quaint mantle
#

?

lost matrix
#

What do you mean?

quaint mantle
#

What is the best way to make a list of mobs the player can interact with

lunar schooner
#

I get a massive json tree from one of Google's APIs, and I need to get to one of it's inner layers

#

now I could create 50 different files, all with 1 class with 1 field

#

but I thought, might as well nest them

lunar schooner
#

buuut javac doesn't appreciate that past a certain point

paper viper
#

Use Set.of or ImmutableSet.of

lost matrix
quaint mantle
#

yeah dont hardcode a lot of if statements

lost matrix
lunar schooner
#

Oeh now do tell

lost matrix
#

If you just want one value

lunar schooner
#

I could use org.json I know that one, but it makes for a mess

quaint mantle
#

This is my old code before it was dropped.

lost matrix
quaint mantle
#
interface NPC { // name this better
    void onInteract(Player p, Entity e);
    NamespacedKey getKey();
}

@quaint mantle

class Archer implements NPC
lost matrix
lunar schooner
#

hm

#

I might do that yeah

lost matrix
#

Huh?

quaint mantle
#

Archer, Fisherman

#

right?SadMan

lost matrix
#

In this example the NPC is both the instance object and the composition component.
I dont understand the Set<NPC>

quaint mantle
#

to loop through on the event

lost matrix
#

Yeah. No.

quaint mantle
#

they change it as they wish

#

its up to them if they wish to use a registry system

lost matrix
#

No need to loop through anything. Scales O(n) and Sets loop quite slowly.
Just use a Map<NamespacedKey, NPC> if you already got a key.

quaint mantle
#

works

#

good point

lost matrix
#

Compile-time and Runtime versions might not match.

#

Is the dependency "discord-webhooks" provided by another plugin?

#

Did you make sure to shade it into your plugin then?

next stratus
lost matrix
#

Add the maven-shade plugin to your pom.

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.4</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

If you use Java 16 then you need to get a snapshot version. But well do that if you get any compiler problems.

Just make sure to add the provided scope to all dependencies you dont want to shade. You surely dont want
to deliver the whole spigot api within your plugin. 😄

#
    <dependency>
      <groupId>some.group.id</groupId>
      <artifactId>some-atifact</artifactId>
      <version>1.17.1-R0.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
next stratus
#

but that'd destroy the current item?

torn oyster
#
      POTION:
        slot: 0
        effect: INCREASE_DAMAGE
        duration: 100 #in ticks
        amplifier: 1
        splash: false
      POTION:
        slot: 1
        effect: SPEED
        duration: 100
        amplifier: 1
        splash: false
      POTION:
        slot: 2
        effect: POISON
        duration: 100
        amplifier: 1
        splash: true```
#

how would i make potions using that

#

rn im using potionmeta

lost matrix
torn oyster
#

but idk how to make it splash

next stratus
lost matrix
torn oyster
#

gonna assume splash potion meta isnt a thing in 1.8

#

lol

lost matrix
torn oyster
#

do you have any idea how to do it in 1.8

next stratus
#

So @lost matrix would you go like
player.setItemOnCursor(null); ItemStack stack1 = target;

torn oyster
#

Material.SPLASH_POTION isn't a thing

lost matrix
#

The bigger jar also contains all your dependencies. Its also known as "uber" jar.

next stratus
#

stupid discord formatting

torn oyster
#

what is Yeltsa Kcir backwards?

next stratus
#

player.setItemOnCursor(null); doesn't work :/ I can still switch the items around

lost matrix
# next stratus I wanna get the event of dragging https://i.imgur.com/Z3T0vVa.png lets say the o...

Example:

  @EventHandler
  public void onClick(final InventoryClickEvent event) {
    final Player player = (Player) event.getWhoClicked();

    final ItemStack cursorItem = event.getCursor();
    final ItemStack target = event.getCurrentItem();

    if (target == null || cursorItem == null) {
      return;
    }

    final ItemMeta cursorMeta = cursorItem.getItemMeta();
    final ItemMeta targetMeta = target.getItemMeta();

    if (targetMeta == null || cursorMeta == null) {
      return;
    }

    player.sendMessage("Target: " + targetMeta.getDisplayName());
    if (target.getType() == Material.EMERALD) {
      // Now ill copy the display name from the cursor item to the
      // target item while destroying the cursor item.
      final String cursorName = cursorMeta.getDisplayName();
      targetMeta.setDisplayName(cursorName);
      target.setItemMeta(targetMeta);

      player.setItemOnCursor(null);
      event.setCancelled(true);
    }

  }
#

Yes thats pretty big. It looks like all the dependencies you use are bloating the plugin. Did you make sure that the spigot-api is not shaded in?

next stratus
lost matrix
#

provided means it wont be shaded in but is provided by another jar later at runtime.

next stratus
#

I don't know if this is something wrong with spigot or?

lost matrix
next stratus
#

I mean, I've been trying in many different ways and no hope

#

It says the target item but the dropped item doesn't delete itself

lost matrix
next stratus
#

How on earth

#

InventoryClickEvent?

lost matrix
#

Yes. 1:1 the code from above.

#

Did you register the listener and added the @EventHandler annotation?

next stratus
#

yep

lost matrix
#

Spigot version?

next stratus
#

1.17 iirc

#

yeah paper 1.17

lost matrix
#

Then the code works.

lost matrix
next stratus
#

I'm gonna debug now, this is really really weird.

lost matrix
#

Show your exact code.

next stratus
lost matrix
#

You drag the item on the emerald and not the other way around, right?

next stratus
#

No, I drag the emerald onto the item

#

The emerald is the gemstone

lost matrix
#

But the target is the item in the current slot.

#

Try dragging the item on the emerald XDD youll see what i mean

next stratus
#

it then turns into a emerald

#

Oh i've done it the wrong way around somehow?

lost matrix
#

"target" is the clicked item. The slot item if (target.getType() == Material.EMERALD)

#

If the slot item is an emerald.

next stratus
#

So, the target needs to be the trident then?

#

I'll quickly switch it around and see how that goes

grim ice
#

everything i needed

#

exists in 1.8 and in 1.17

#

btw is a plugin being 40kb bad

next stratus
#

Well, apart from it duplicating the trident i think you fixed it thank you!

opal juniper
#

am using teh 1.8 api for a project atm

#

it is utter shite

opal juniper
#

and what your plugin is doing

#

a 40kb join message plugin is bad

#

but a 40kb mini game is amazing

grim ice
#

hmm

#

its a party plugin with like 14 commands

#

and a few events

next stratus
#

one last thing, when i drop a item onto the item it duplicates the item of which i dropped onto?

lost matrix
opal juniper
#

lmaoo

#

make sure you shade the spigot api too just for good measure

lost matrix
#

Oh yeah. good idea.

#

But wouldnt that break the plugin?

#

Ill try

next stratus
opal juniper
next stratus
#

I think i found it 😅
edit: It just duplicates the whole target item now hm..

#

Hey @lost matrix how did you destroy the dropped item? I can't do that for some reason

lost matrix
plucky wind
#

it's okay?

lost matrix
unkempt peak
grim ice
#

BRO

#

WHAT THE FUCK

#

player.sendMessage(ChatColor.RED + "No Player Matching " + args[1]);

#

HOW IS THIS NULL

#

player is command sender btw

unkempt peak
#

args[1]

#

?

grim ice
#

and i checked arg length

#

before that

#

i checked if arg length is 2

lost matrix
#

And stack trace

grim ice
#

?paste

undone axleBOT
unkempt peak
#

Player is null

grim ice
#

HO

#

HOW

#

ITS A COMMAND SENDER

eternal oxide
#

args[1] is your player

grim ice
#

no

#

the line that got an npe is 35

#

not 34

eternal oxide
#

line 35

grim ice
#

player.sendMessage(ChatColor.RED + "No Player Matching " + args[1]);

opal juniper
grim ice
#

args[1] is a string

#

and player is a command sender

eternal oxide
#

look at line 34

#

ah I see

grim ice
#

if (Bukkit.getPlayer(args[1]) == null) {

#

??

unkempt peak
#

Try splitting the methods/variables in separate lines to see exactly what is null

grim ice
#

what

quaint mantle
#

args 1 is bull

unkempt peak
#
player.
sendMessage(
ChatColor.RED
+ "No Player Matching" +
args[1]);```
grim ice
#

i checked iaargs length is 2?????????????????????

grim ice
unkempt peak
quaint mantle
#

It tells you what line, but just try printing args[1]

#

Easily fix this by 5 seconds of debugging

quaint mantle
lost matrix
unkempt peak
#

Lol

quaint mantle
#

If so, get help 😂

grim ice
#

ofc its not his lmfao

quaint mantle
#

Idk why you would worry about it

unkempt peak
#

40kb is not that much

quaint mantle
#

entity.getPersistentDataContainer().getKeys().toString return [pluginanem:dataone] how do i return just a string?

lusty cipher
#

my plugin used to be 2.2MB because of shading kotlin stdlib 👍

grim ice
#

i didnt shade anything

lusty cipher
#

40KB is nothing

lost matrix
quaint mantle
true perch
#

When I query the SQL to get a ResultSet object, the last result in the set is always equal to the last piece of data I inserted into the SQL. How do I put data into the SQL at certain locations?

quaint mantle
lusty cipher
#

@quaint mantle do you want to get the value for that key?

#

or what are you trying to do

quaint mantle
#

I want to get all the values ​​that the mob contains in string

#

but return

lusty cipher
#

well keys are the keys not values

#

so iterate over the the map using the keys and get each one?

#

it's simple

lost matrix
#

Dont iterate pls. Use a HashMap.

tidal socket
#

Hi, i'm trying to build a fat jar with gradle, but i have some problems.. can someone help me?
I need it to use "Java Discord API".
That's my gradle: https://pastebin.com/YGcRfTTA

lost matrix
tidal socket
river spear
#

How can I use Packets to send an ItemFrame with a map to a player?

quaint mantle
#

@chrome beacon you were wrong, the multi-version compatibility is possible, including 1.17 nms, without using java 1.8 and reflexion only ^^ send me a pm if you want explanations on how I did it ^^

ivory sleet
#

Hope you’re not writing a Bible

quaint mantle
#
  • java version 16
  • set javac compatibility 1.8. Using gradle it can be done using :
compileJava {
    sourceCompatibility = JavaVersion.VERSION_16
    targetCompatibility = JavaVersion.VERSION_16
}
ivory sleet
#

It’s a simple question

paper viper
ivory sleet
#

but that would restrict you from using j16 features or no?

paper viper
#

Yeah

ivory sleet
#

ok guess it’s doable

quaint mantle
#

or the code is translated ^^

#

dunno

paper viper
#

But what’s the point tho honestly if you have it but you can’t use any of the features

#

Seems dumb imo

#

Just switch entirely

ivory sleet
#

I mean compatibility I guess

#

Tho personally I’d just use java 8 and keep it simple that way

quaint mantle
ivory sleet
#

box have you tried using any java 16 feature like pattern matching

#

Or records

paper viper
#

Or any features between 9-16

#

Like switch expressions

ivory sleet
#

Only the latter actually, afraid pattern matching might compile down to some normal instanceof and then cast

quaint mantle
#

I did it at start but at some point (while trying to achieve compatibility) I came back on Java 8 so I deleted those features usage ^^

ivory sleet
#

Ah well then

quaint mantle
#

So I have no answer to the question "will it break the javac 1.8 compatibility or not ?"

ivory sleet
#

Idk I mean you should be able to achieve a 1.8-1.17 compatibility with solely devoting your compiler to java 8.

quaint mantle
#

As far as I can see compatibility is working well. I'm currently building heads with custom textures without any reflexion in my nms-1.17 submodule. And I tested the plugin in both 1.12 and 1.17 without any issue ^^

silver shuttle
#

How do I remove x amount of an ItemStack matching all data but the Display name from a players inventory? Needs to support differently named items aswell

ivory sleet
quaint mantle
#

just look at the stash code and remove the displayname part

#

?stash

undone axleBOT
silver shuttle
#
                int invAmount = 0;
                for (int i = 0; i < 36; i++) {
                    if(contents[i] != null && contents[i].getType() != Material.AIR) {
                        ItemStack itemSlot = contents[i];
                        ItemMeta metaSlot = itemSlot.getItemMeta();
                        metaSlot.setDisplayName(null);
                        if(Objects.equals(item.getType(), itemSlot.getType()) && Objects.equals(meta, metaSlot)) {
                            invAmount += contents[i].getAmount();
                        }
                    }
                }

Well at the moment I am only using this to get the amount of items in their inventory that match everything but their displayname

#

(For some reason it outputs 1 less than the amount of items he has)

#

Still can't figure that one out ^^

#

ah nvm i found that one out lol

#

had to use <= instead of <

#

(in another line)

quaint mantle
silver shuttle
#

well I don't have any issues counting items, I need to remove them from their inventory, so is there a solution to do that without looping through each slot in their inventory?

quaint mantle
#

no you have to loop over each slot

silver shuttle
#

ugh .-.

quaint mantle
#

If I remember well, there is an inventory iterator.

ivory sleet
#

It implements Iterable

silver shuttle
#
                for (int i = 0; i < 36; i++) {
                    if(amount == 0) {
                      break;
                    }
                    if(contents[i] != null && contents[i].getType() != Material.AIR) {
                        ItemStack itemSlot = contents[i];
                        ItemMeta metaSlot = itemSlot.getItemMeta();
                        metaSlot.setDisplayName(null);
                        if(Objects.equals(item.getType(), itemSlot.getType()) && Objects.equals(meta, metaSlot)) {
                            if(amount >= item.getAmount()) {
                                amount -= contents[i].getAmount();
                                player.getInventory().removeItem(contents[i]);
                            }
                            else {
                                contents[i].setAmount(amount);
                                player.getInventory().removeItem(contents[i]);
                                amount = 0;
                            }
                        }
                    }
                }

So this would work?

quaint mantle
#

@silver shuttle just use Object == Object

silver shuttle
#

my IDE recommended it to me

quaint mantle
#

weird, just use ==

silver shuttle
#

kk

quaint mantle
#

== doesnt work here

silver shuttle
#

can't be null, as i have checks in previous code

quaint mantle
lost matrix
#

for material == works but for ItemMeta it doesnt

quaint mantle
#

weird

opal juniper
#

not really

silver shuttle
#

for some reason, that code also removes ALL items matching the given item from my inventory, not just "amount" of items

#

and I can't figure out why lol

paper viper
#

And enum values can be compared using reference equality

quaint mantle
#

ahhh

paper viper
#

Due to them being constant

quaint mantle
#

yeah

waxen plinth
#

The contents are not modified when the inventory is

lost matrix
#

I just came up with this general approach.

  /**
   * Removes all items from this inventory that match the given predicate.
   *
   * @param inventory the target inventory
   * @param selector  the predicate that defines what items should be removed
   * @param count     the amount of items to remove
   * @return how many items couldnt be removed
   */
  public int removeFrom(final Inventory inventory, final Predicate<ItemStack> selector, final int count) {
    final Predicate<ItemStack> nullSafeSelector = ((Predicate<ItemStack>) Objects::nonNull).and(selector);
    int amountToRemove = count;
    for (int index = 0; index < inventory.getSize(); index++) {
      final ItemStack indexItem = inventory.getItem(index);
      if (!nullSafeSelector.test(indexItem)) {
        continue;
      }
      final int stackAmount = indexItem.getAmount();
      if (stackAmount >= amountToRemove) {
        indexItem.setAmount(stackAmount - amountToRemove);
        return 0;
      } else {
        amountToRemove -= stackAmount;
        indexItem.setAmount(0);
      }
    }
    return amountToRemove;
  }
ivory sleet
#

Every enum constant field points to its own instance the entire runtime usually (unless classloader thing blah)

waxen plinth
#

Method that does the same thing you're looking for

silver shuttle
#

thanks, but I am actually quite close to solving it myself

lost matrix
waxen plinth
#

That's fair

#

I could have probably just used a Predicate<ItemStack>

#

Guess I didn't think of it when I wrote that method

#

But I think I did it so that I could use a method reference with my compare method

#

I have a separate method to compare items based on specific traits

lost matrix
#

XD. Gotta make this look fance. Put all the :: in there

waxen plinth
#

Yeah lol

#

Love me my method references

silver shuttle
#

is it possible that Inventory#removeItem(ItemStack) removes the entire ItemStack in that inventory, regardless of size? Because I set the size to something lower than the stack I have in my inventory (have 64, ItemStack amount is 2) and it removes the entire stack

itemSlot.setAmount(removeAmount);
player.getInventory().removeItem(itemSlot);
quaint mantle
#

How to convert object entity.getPersistentDataContainer().getKeys() to string?

round python
#

hello where can I get started on spigot plugin dev

silver shuttle
round python
#

ty

quaint mantle
silver shuttle
#

?

#

what do you mean

hasty prawn
#

Loop through and use getNamespace() and getKey(), depending on which part you want.

quaint mantle
#

what is "getNamespace()"

#

icant be bothered to look rn

hasty prawn
#

Namespace is the first part, basically an identifier.

quaint mantle
#

oh weird

#

well not weird nevermind

hasty prawn
#

Like minecraft:tp, minecraft is the namespace

quaint mantle
#

ahh

feral lodge
#

does anyone know the dimensions of the player bounding box in 1.8?

unreal quartz
#

approximately 1 player

feral lodge
#

ah would never of guessed that

regal anchor
#

Hello, org.bukkit.scoreboard.Team#getEntries().clear() does UnsupportedOperationException

#

on the internet they suggest to copy it but it is not useful because obviously I need to clear the real Team Set

hasty prawn
crude charm
#

Thats why docs exist 😄

#

then what are you looking for?