#help-development

1 messages · Page 1876 of 1

hardy swan
#

cancel BlockExplodeEvent

golden turret
#

how can i set that to an anvil

quiet ice
#

Don't try

#

Anvils are the most evil thing in existence, I have spent far too long debugging those only to come to the conclusion that they are far too evil

golden turret
#

ok

#

but how do i set the x in the anvil

quiet ice
#

Not possible without setting a second input item and hoping the server owner has the right server software

golden turret
#

bruh

quiet ice
#

You can force-set an output item but under certain impls the user will not be able to take it

#

Under other conditions the player will not be able to take it regardless of whether spigot or paper is used (didn't test anything else yet), even if the player sees that it can take it

#

Anyways, in theory it is doable via setting the output of PrepareAnvilEvent#setResult

golden turret
#

maybe i can just empty the 2nd slot

quiet ice
#

You could also perhaps mess with subtly renaming the item, but I have not tested that yet

#

It might also be worth checking whether anvil.setItem(3, itemstack); is doable, I haven't checked that either, though I fear it might have a few drawbacks

toxic mesa
#

How do bot attacks work? I've seen a couple and want to experiment with a protection plugin. I understand nobody is going to help me cuz that would be stupid, but what would be a good direction? Is it mostly done with an application or smth?

#

hard to imagine 100 different players joining yk

quiet ice
#

If I'd would want to DOS a server I'd spam the join request while sleeping for a relatively long time between responses between the steps of the join procedure, but I think newer versions of vanilla minecraft kinda make this hopeless to pull off

toxic mesa
#

Ye that makes sense

#

ty imma google xD

quaint mantle
#

Hello, i coding with the spigot 1.12.2 API and i have a NullPointerException from if (event.getItem().getType() == Material.FEATHER) when i click rightclick on block.

#

Why is this

quiet ice
#

getItem could be null (e.g. holding air)?

#

Just use Java 14+ honestly

quaint mantle
#

I use Java 8 is this the error?

quiet ice
#

No, but Java 14+ will tell you exactly what is null so you don't have to ask a human about it

quaint mantle
#

And why is this error?

quiet ice
#

Plus Nullabillity annotations would tell you that really only event.getItem() or event can be null; second one is unlikely, so it is the first one

#

Itemstacks are often null if they represent Air. Blame Bukkit for being decades old

quaint mantle
#

I rightclick with feather not with air

#

if (event.getItem().getType() == Material.FEATHER) { isnt wrong???

quiet ice
#

Not knowing what event is, event has to be null then

quaint mantle
#

event is PlayerInteractEvent

quiet ice
#

honestly, just use event.getMaterial()

#

?stash

undone axleBOT
quiet ice
#

hm, they didn't use nullabillity annotations back then.

#

It could be possible that it is generating two events, one for the on-hand and one for the off-hand

quaint mantle
#

But its working with event.getMaterial() thanksss#

tardy delta
#

isnt it event.getClickedItem()?

upper niche
#

how do you create a dyed shulkerbox itemstack?
like what part of the data would you have to grab to modify the dye value?

#

i see that the ShulkerBox interface has a getColor() method but no setColor() method

quaint mantle
tardy delta
#

there's nothing in the chestplate slot

chrome beacon
onyx fjord
#

how do u get an entity player is looking at

upper niche
royal vale
# hardy swan cancel `BlockExplodeEvent`
public class Grief implements Listener {

    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Material type = event.getBlock().getType();

        if (!type.equals(Material.OBSIDIAN) &&
                !type.equals(Material.CRYING_OBSIDIAN) &&
                !type.equals(Material.RESPAWN_ANCHOR) &&
                !type.equals(Material.COBWEB) &&
                !type.equals(Material.GLOWSTONE)) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onBlockBreak(BlockPlaceEvent event) {
        Material type = event.getBlock().getType();

        if (!type.equals(Material.OBSIDIAN) &&
                !type.equals(Material.CRYING_OBSIDIAN) &&
                !type.equals(Material.RESPAWN_ANCHOR) &&
                !type.equals(Material.COBWEB) &&
                !type.equals(Material.GLOWSTONE)) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onItemDrop(PlayerDropItemEvent event) {
        event.getItemDrop().remove();
    }

    @EventHandler
    public void onEntityExplode(EntityExplodeEvent event) {
        Bukkit.getPlayer("Dacaly").sendMessage("Entity Explosion");
        event.blockList().clear();
    }

    @EventHandler
    public void onBlockExplode(BlockExplodeEvent event) {
        Bukkit.getPlayer("Dacaly").sendMessage("Block Explosion");
        event.blockList().clear();
    }

}

First 3 events works, but both entity and block explode don't even fire when exploding tnt

hardy swan
#

Dont clear the blocklist

#

That wont do anything

tardy delta
#

i'd make an enumset for the materials

hardy swan
#

Cancel the event

tardy delta
#

and use #contains

hardy swan
#

And yea, that

royal vale
#

The event doesn't fire in the first place

hardy swan
#

BlockExplodeEvent

#

Not EntityExplodeEvent

tardy delta
#

is that only for creaper? imagine...

royal vale
hardy swan
#

Nvm im blind

royal vale
#

Hold up

#

Bruh no I'm blind

hardy swan
#

Lol

quaint mantle
#

Hey, can someone give me a link to md5's non flickering scoreboard?

hardy swan
#

Or wither, idk

young knoll
#

Creeper, tnt, end crystal, tnt minecart, ghast fireball, wither

tardy delta
#

oh end chrystal right

#

forgot those are entities tho

royal vale
hardy swan
#

Yes...

royal vale
#

I'm basically making a pvp server

#

With end crystals and stuff

#

So I want to disable all blocks being broken

hardy swan
#

Wg

young knoll
#

Just clear the block list them

hardy swan
#

Oh that actually works?

royal vale
#

And it's not necessary if I can make my own little version

#

Instead of listening to 30 events

young knoll
#

The list is mutable

royal vale
hardy swan
#

Thought would be defensively programmed

onyx fjord
#

Hello, I want to get an entity that player is looking at, how can I do it?

left oar
#

could go though all players in the world, and then do some sort of hitscan

young knoll
#

World#rayTrace

onyx fjord
young knoll
#

?jd

onyx fjord
#

very cool

left oar
#

probably a raytrace result, specifying the hit entity or tile

opal juniper
#

RayTracedResult

#

yes

#

rayTraceEntities can be used

onyx fjord
#

okay and the vector will be player eye location?

opal juniper
#

yes

#

wait why are u using visual bukkit

onyx fjord
#

helps me understand stuff

#

it also gives me source code later

#

so i can modify it and then compile

#
  • intellij decided to not start up 🙂
opal juniper
#

mm whatever

onyx fjord
#

i dunno whaty happened

#

but ye

opal juniper
#

but yeah just ray trace it

onyx fjord
#

gotcha, do i need ray size and filter or na

opal juniper
#

depends how far you want it

onyx fjord
#

isnt max distance for it?

opal juniper
#

oh yeah

#

nah you don’t need that

onyx fjord
#

ill limit it anyway

#

cuz i dont want players to interact with entities like 100 blocks away

#

basically what im doing is

#

when player clicks f and looks at item frame, it will open a spray gui

torn badge
#

Hey guys, I'm having a problem with Chunk#getEntities in ChunkLoadEvent

#

It only contains the mobs that are obviously there the second time I join

#

So when the server restarts and I join, it is missing a mob that is there, but when I rejoin again it works

onyx fjord
#

class org.bukkit.util.RayTraceResult cannot be cast to class org.bukkit.entity.Entity i am getting this, how to get an entity from raytraceresult?

onyx fjord
#

thanks

torn badge
#

Alright I found out that ChunkLoadEvent is not called for the chunk the player is in the first time he joins

#

But why?

onyx fjord
#

okay, i have the result

#

but its always me for some reason

woeful crescent
#

hey, can regular chatcolors be used in TextComponents? (I'm asking bc there's a method called setColor)

onyx fjord
#

could someone give me an example snippet of getting player eye vector?

brave sparrow
torn badge
#

But thank you!

sterile token
#

Allright thanks!

tardy delta
#

but you cant override the methods

sterile token
#

Sos hum

#

Big problem

#

Because i need to implements methods from interface/abstract class. One of them yes or yes should be static

tardy delta
#

dont make the method static 😊

sterile token
#

Do you understand i refer to?

tardy delta
#

yes

sterile token
#

So i dont know how to do it

#

Hum i will have to recode. In some way of having an interface/abstract class with a static method (that could be override)

#

Any ideas?

tardy delta
#

hmm i dont have my ide

#

google would be an idea i guess

sterile token
#

Right thanks, Drive carefully please

onyx fjord
#

back to the ray trace entities, for location do i use player location or player eye location

ancient plank
#

yes

sterile token
#

Mnns

sterile token
onyx fjord
midnight magnet
#

Does anyone know how to get the highest block in worldgen population, because

location.getWorld().getHighestBlockAt(location);

doesn't work because world is always null.

onyx fjord
#

yeah only i get logged

atomic violet
#

so how would i go about making a block that cant be broken faster with any tool? is there a way to do this?

sterile token
#

With Maven shade plugin its possible to relocate a class to another package?

ivory sleet
#

yes

#

in principle

sterile token
#

Allright thanks

midnight magnet
#

Does anyone know about block populators, because since 1.17 I have not been able to find out where the highest block is, e.g. to place a tree there.

#

pls help

solid cargo
#

There was something @willow widget

#

I forgot it

willow widget
#

how could I execute a command through my plugin?

For example: I (as an in-game user) send "/execute give @p diamond 1" and my plugin makes the server execute the command "give @p diamond 1"

solid cargo
#

Bukkit.dispatchCommand(Bukkit.getConsoleSender(), “cmd”)

#

Sum like that

willow widget
willow widget
#

Like this I think (?) xd

Bukkit.dispatchCommand(plugin.getServer().getConsoleSender(), "command");
willow widget
solid cargo
#

No i think

willow widget
#

oh lol why?

solid cargo
#

I think its just Bukkit.getConsoleSender()

willow widget
#

well according to eclipse, both of them return ConsoleCommandSender which I guess is instance of CommandSender (the first arg needed for dispatchCommand())

#

idk if there's a difference between the obj returned by each

onyx fjord
#

how can i ignore certain entity type in world#raytraceentities

solid cargo
#

Idk. I gotta learn school now

#

Bye

willow widget
#

bye (: ty

glossy venture
#

just enter a predicate that returns false if it is a type you want to ignore

#

or one without double raySize

#

also available, just missed it

quaint mantle
#

Is it possible to convert the ChatColor of Bungeecord to the ChatColor of Spigot or to set a custom color code in the Scoreboard Team.setColor?

sterile token
#

If i opened a custom inventory to a player using player#openInventory(). When doing player#getInventory() will return the object of my custom inventory or his inventory?

glossy venture
sterile token
#

Let me search

quaint mantle
#

And which one would that be? because ChatColor from Spigot is an enum

glossy venture
#

fixed it

quaint mantle
#

i try it

sterile token
glossy venture
#

so like the hotbar and stuff

#

not the open one

quaint mantle
glossy venture
#

you can use Player#getOpenInventory()

glossy venture
glossy venture
#

well then it wont work

#

i dont think you can use rgb colors in scoreboards

quaint mantle
sterile token
sterile token
quaint mantle
glossy venture
#

bukkit chatcolors dont support custom color codes

#

its an enum

sterile token
#

Custom?

glossy venture
#

even with reflection

sterile token
#

Expalin that

quaint mantle
#

html colors

glossy venture
#

hex/rgb colors

sterile token
#

Ahh i think he want to convert the default bungee colors. To the spigot ones

glossy venture
#

yeah

#

which is not possible with rgb codes

sterile token
#

Yeah

#

With rgb

#

But with default colors yes you can

glossy venture
#

he has a net.md_5.bungee.api.ChatColor.of(Color)

sterile token
#

Spigot has it too

glossy venture
#

should work

#

or myBungeeChatColor.name()

sterile token
#

Oh i will add that one to my lib. Do you have any problems?

glossy venture
#

i dont know for sure

sterile token
glossy venture
#

problems with what?

#

coding?

sterile token
#

Orby

#

Big problem

#

With player#getOpenInventory() i cannot get the name

#

😅

glossy venture
#

you need an inventory view

sterile token
#

Ah

glossy venture
#

yeah its kind of scuffed

#

give me a sec

sterile token
#

Allright

#

And for open it, as well i will need to open it as an InventoryView right?

wide coyote
#

no the Inventory is enough

#

Player#openInventory(Inventory)

sterile token
sterile token
glossy venture
#

yeah you dont need inventoryview to open it

sterile token
#

The problem is this. When i open my menu and click on the custom nenu its sent the debug message. And when i click outside the custom menu (player ivnentory) it send the debug message aswell

wide coyote
#

since Inventory interface does not have a method to get InventoryView, you can not access the view without an InventoryEvent

sterile token
#

Hyperion

glossy venture
#

it already returns an inventoryview

#

HumanEntity#getOpenInventory()

#

use getTitle()

sterile token
#

I cannot use player object?

glossy venture
#

player is a humanentity

#

works the same

sterile token
#

Its an extend i think

glossy venture
#

yeah

#

so it has it

#

and getTopInventory() should return your inventory itself

sterile token
#

player.getOpenInventory().getTopInventory().getName()

glossy venture
#

getBottomInventory() will return the players inventory

sterile token
glossy venture
sterile token
#

Omgg

#

I think i have explained wrong

glossy venture
sterile token
glossy venture
#

but it does contain color codes

sterile token
#

My custom menu title can contains color codes

#

I save it on my manager (map<>) with the color codes already

eternal oxide
#

Compare the inventory instance not its title.

sterile token
#

Hem??

glossy venture
#

yeah thats a better approach

sterile token
#

Omg im confused

glossy venture
sterile token
#

Its posible to force close a custom menu?

glossy venture
sterile token
glossy venture
#

what

sterile token
#

Omg

#

I will send code

glossy venture
#

?paste

undone axleBOT
glossy venture
#

so no need to check

#

if thats what you mean

sterile token
#

I send code and explain what i want to do

glossy venture
#

ok

#

?paste

undone axleBOT
glossy venture
#

^ use this

#

just paste your code, click save, copy the url and paste and send it here

silent stratus
#

Is it possible to stop carpet from being removed by water?

glossy venture
#

no clue

#

probably

#

but i dont know how

#

id assume using events

silent stratus
#

yeah but i cant find an event which would solve this xD

glossy venture
#
@EventHandler
public void flow(BlockFromToEvent event) {
  // get block
  Block to = event.getToBlock();
  
  // check for carpet
  if (to.getType().name().contains("CARPET") {
    // cancel
    event.setCancelled(true);
  }
}

@silent stratus try this

silent stratus
#

ok thx

proud basin
#

when you have a gui opened and you open another one does the old one stay opened?

glossy venture
#

i dont think so

#

you cant have two guis open

proud basin
#

okay so it closes automatically

glossy venture
#

yes

#

id assume

proud basin
#

so then why the hell my thing looking through the old gui that doesn't exist

glossy venture
#

whatt

glossy venture
#

what are you trying to do

#

if you are using Player.getOpenInventory().getTopInventory() it should yield the new one

proud basin
#

no

glossy venture
#

?

proud basin
#

im just opening the inventory

glossy venture
#

lets goo

#

wrote it in discord

silent stratus
#

xD

glossy venture
#

np

glossy venture
#

but i dont know 100% sure

silent stratus
#

ok

glossy venture
#

oh no wait

proud basin
#

so before this code when an item is clicked it opens a new inventory then here im checking to see if an item was clicked in the new inventory but for some reason its looking through the old one if (((InventoryClickEvent) event).getCurrentItem().getItemMeta().getDisplayName().contains("Autoban")) {

glossy venture
#

otherwise it will never flow

#

not even into empty blocks lol

silent stratus
#

ok thx

glossy venture
proud basin
#

because I debugged it

glossy venture
#

how

glossy venture
proud basin
#

no

glossy venture
#

or System.out.println("a")

proud basin
#

^

#

and other stuff

#

such as statements

glossy venture
#

but how do you check which inventory its looking through

glossy venture
proud basin
#

It is working

#

but its looking through the old one

glossy venture
#

but how do you know

#

show me one of the checks

proud basin
#

because I checked if it contains one of the other things in the old inventory and it's returning true

glossy venture
#

oh

#

ok

#

i dont know why

#

i dont have much context though

#

might need more code

proud basin
#

I even tried closing the inventory before opening new one

glossy venture
#

weird

#

but i need more code to really know whats going on

round elbow
#

ClassNotFoundException: com.mongodb.MongoClientSettings
this happens when trying to setup a client for MongoDB

private MongoClient client;
// ^ in the scope
MongoClientSettings settings = MongoClientSettings.builder()
                .applyConnectionString(creator.get())
                .build();
        client = MongoClients.create(settings);
#

even though MongoDB core and driver is implemented into my project

glossy venture
#

seems like the jar isnt shadowed correctly

#

using gradle?

round elbow
#

ye.

#

but idk about shadowing really

glossy venture
#

then use the shadow plugin

round elbow
#

first time using gradle

#

tbh

round elbow
glossy venture
#

add this

#

into the plugins block

#

the id thing

round elbow
#

okay

glossy venture
#

and then run shadowJar instead of jar

#

under a new shadow catagory i think

#

or under build

round elbow
#

uhh wait

glossy venture
#

?

round elbow
#

im not using gradle gradle

#

im using gradle-dsl

glossy venture
#

kotlin dsl?

round elbow
#

ye

glossy venture
#
plugins {
  // ...
  id("com.github.johnrengelman.shadow") version "7.1.2"
  // ...
}
#

use this instead

round elbow
#

ok thank u

glossy venture
#

np

round elbow
#

so i use shadowJar instead of jar when building ye?

glossy venture
#

yes

#

it will produce a fat jar

#

i gtg in a sec

proud basin
#

here is some code ```java
if (((InventoryClickEvent) event).isLeftClick()) {
if (((InventoryClickEvent) event).getCurrentItem().getType() == Material.BOOK_AND_QUILL) {
if (user != null) {
GUICommand.settingsInventory(user);
if (((InventoryClickEvent) event).getCurrentItem().getItemMeta().getDisplayName().contains("Autoban")) {

round elbow
glossy venture
#

yes

glossy venture
round elbow
#

yo wtf thats like 10x the size of the original one

glossy venture
#

this is nearly unreadable

proud basin
#

No

#

why would I? Just a waste of time

glossy venture
#

do you have it on compileOnly?

#

the spigot dependency

glossy venture
round elbow
round elbow
proud basin
#

all I need to write is event and it casts it for me

quaint mantle
#

ur also casting it three separate times

round elbow
#

compileOnly("io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT")

glossy venture
glossy venture
#

dont worry

round elbow
#

aight thank u so much u saved me alot of time to waste online

#

i alr wasted the entire day

glossy venture
#

np

round elbow
#

i really appreciate this

glossy venture
#

oh shit

glossy venture
proud basin
#

Which is fine

glossy venture
#

for some reason i couldnt figure out how to do that

round elbow
glossy venture
#

yeah lmfao

round elbow
#

it works now

#

thankfully

glossy venture
#

nice

glossy venture
quaint mantle
#

Repeating xode is alwqys bad

glossy venture
#

that doesnt give me enough context still

quaint mantle
#

If you want to change something, you'll have to change it in all places as well

proud basin
#

and btw it is in a variable

glossy venture
#

ok wait

quaint mantle
#

and yes the cast is fucking ugly

#

Ugliest operation in java

glossy venture
#

like checking which inventory its 'scanning'

glossy venture
#

especially when you need it in a statement directly

#

((Class) e)

#

horrible

quaint mantle
#

Exactly

glossy venture
#

aight i gtg now

#

bye

quaint mantle
#

bye

echo basalt
quaint mantle
#

acceptable

#

java cast aint that bad

#

try c++ cast

#

static_cast<InventoryClickEvent>(event)

wheat abyss
#

oof

#

what was that

willow widget
#

What do I have to do to log messages into console like:

[ERROR]: Something happened lol
#

?

chrome beacon
#

Use plugin#getLogger

#

Then Logger#error

wheat abyss
#

Logger logger = Bukkit.getLogger(); logger.info("Woa, a log");

At least thats how I do it

willow widget
#

Like this:

plugin.getLogger().log(Level.ERROR, "Something happened");

?

sterile token
quaint bough
#

what the fk is going on

willow widget
#

oh okay heh

#

ty ty

sterile token
#

Your werlcome

willow widget
#

everyone uses a different thing xD

sterile token
#

Yes

#

hahha

sterile token
wheat abyss
#

really anything works

sterile token
wheat abyss
#

I mean any of what we said

chrome beacon
quaint bough
#

look at the way it is just continuing if statements even though they are false

willow widget
quaint bough
#

I am losing my mind

willow widget
#

alr ty

sterile token
#

I recommend for that creating a method similar to this: public static String style(String text) { return ChatColor.translateAlternateColorCodes('&', text); }

sterile token
#

So you forget about using ChatColor.translate every where

willow widget
willow widget
willow widget
wheat abyss
#

Yeah I have a class thats whole purpose is so I can do CC.translate("&cCOLORS");

willow widget
#

lmao yes

#

I have it as utils bc I'll use it for some other stuff too

wheat abyss
#

One of the essentials

sterile token
quaint bough
willow widget
#

This is my previous thingy

public class General {
    
    public static String colorize(String str) {
        return ChatColor.translateAlternateColorCodes('&', str);
    }
    
    public static String colorWithPrefix(String str) {
        return ChatColor.translateAlternateColorCodes('&', Main.pluginPrefix + " " + str);
    }
    
    public static int randomize(int min, int max) {
        Random ran = new Random();
        int result = ran.nextInt(max+1)+min;
        return result;
    }
    
}
quaint bough
#

I have been trying to fix my code and it hasnt updated in 30 min cuz it compiled into the wrong folder

willow widget
sterile token
wheat abyss
sterile token
wheat abyss
#

I was right lesgo

#

and its effecient, thats amazing

#

non of that looping through each of the strings BS

willow widget
#

oh nice

sterile token
#

Any aproah about sending messages in this way:

new Message().message("[Command] Menu " + menu.getName() + " for " + player.getName() + " has been opened").sendMessage(player);

#

??

willow widget
dusk flicker
#

you could simplify that with a static util

sterile token
dusk flicker
#

ye

wheat abyss
#

did you declare it in your main?

#

you shouldnt need to do if (cmd.getName())

dusk flicker
#

you have ++i rather than i++, not sure if this will make a difference tho

sterile token
#

And that way of looping :sad:?

#

Use a forEach instead

wheat abyss
solar shell
dusk flicker
#

Personally instead of sendMessage I would just broadcast it to everyone so you remove a loop

sterile token
wheat abyss
#

^^

sterile token
dusk flicker
#

or just Bukkit.broadcastMessage("stuff"); Not like 1 foor loop is gonna make a big difference either way

wheat abyss
dusk flicker
#

Oh yeah fair

sterile token
#

Allright np

dusk flicker
#

yeah def do what VERANO said then

sterile token
#

Rack and rock are you experimented with guis/custom menu?

wheat abyss
#

it works

#

I mean kinda, GUIs are fun, wdym?

sterile token
wheat abyss
#

GREAT, I love GUIs, I made a simple wrapper in the past but yeah sure ill help

sterile token
#

Oh thanks!!

wheat abyss
#

Of course!

sterile token
#

Can i send paste code?

wheat abyss
#

Sure

sterile token
#

Wait i will test the recode. Because i made one. And now i recode it. Because lot of things were not working

wheat abyss
#

sure

#

would you like to DM?

sterile token
#

Yeah

#

its better

wheat abyss
#

Yeah

round elbow
#
public JSONObject getJsonValue() {
        JSONParser parser = new JSONParser();
        FileReader reader = new FileReader(file); // this had try catch to it aswell in the code but i removed it for explaination here
        Object o;
        try {
            o = parser.parse(reader);
            return (JSONObject) o;
        } catch (IOException | ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

I have this to parse json text to JSONObject but everytime i try to call this method it just clears the file for no reason

#

the file becomes empty everytime i try to call this

#

and it throws

[WARNING] .... Unexpected token END OF FILE at position 0.

[WARNING] .... at org.json.simple.parser.JSONParser.parse(JSONParser.java:257)

[WARNING] .... at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
sullen marlin
#

because you were making a FileWriter yesterday werent you

#

in your fields

#

making a new FileWriter will clear the file

#

but I've already told you that your code is shocking; and you haven't explained why you need json

round elbow
#

i need json because ive never used it, everyone of my friends are talking about it and would like to have new experience
but what is really bad about my code? i know i am still a beginner but what is bad? everyone says its bad but never why?
also thanks for telling me about Writer thing ima fix it

#

im working on an smp plugin that involves the use of json atm

spare marsh
#

Okay so I am using PlayerInteractEvent but I only want to run code when they interact like trying to open a door or chest, not just interacting with any block. Do those type of blocks come in a bulk or something or is there way to check that or I gotta specify all of them?

sullen marlin
#

well chests and doors do

#

but there is nothing that includes just chests and doors

spare marsh
#

so I would have to check for every instance? Check if it is a door, chest, shulker, etc... ?

sullen marlin
#

what are you trying to do

#

you said chest and door

#

now you say shulker

spare marsh
#

I said like a chest and door as an example but I mean every block that has like a special function. I want to send a message if a player is interacting with one of those special blocks

sullen marlin
spare marsh
#

So I have to check for material then?

#

alright will do that then, thank you...

sterile token
#

Which is the hashmap functions to get and object and if it doesnt exists, it add to the hashmap?

#

Thanks

dusk flicker
#

if !contains then add

#

might be one but thats how id just do it lol

wheat abyss
#

I think there is a function just for that actually

ivory sleet
#

computeIfAbsent

sterile token
wheat abyss
#

putIfAbsent

sterile token
#

It take 2 parameters right?

wheat abyss
ivory sleet
#

just compute does

#

the computeIfAbsent is a higher order function which takes a function with 1 param iirc

woeful moon
#

When I click Implement Methods for a CommandExecutor class, the onCommand() method looks like this:

    @Override
    public boolean onCommand(@org.jetbrains.annotations.NotNull CommandSender sender, @org.jetbrains.annotations.NotNull Command command, @org.jetbrains.annotations.NotNull String label, @org.jetbrains.annotations.NotNull String[] args) {
        return false;
    }

How can I prevent IntelliJ from adding @org.jetbrains.annotations.NotNull automatically?

ivory sleet
#

May I ask why you don’t want them there x)

wheat abyss
woeful moon
#

It gives me 4 errors

wheat abyss
#

What are the errors?

ivory sleet
#

Oh you haven’t imported the library perhaps

woeful moon
#

Cannot resolve symbol 'NotNull'

#

which library?

ivory sleet
#

jetbrains annotations library probably

woeful moon
#

how do I import it? and what does it do?

wheat abyss
#

You can hover over the @NotNull and click the import option I think

ivory sleet
#

Do you use maven or gradle?

ivory sleet
#

Yeah Well might be the case the library isn’t present at your compile time classpath

wheat abyss
#

I think at least

woeful moon
#

although what's the advantage of having it/what does it do?

vocal cloud
#

Well if you don't have the lib you can't import it.

#

It's great for annotating methods for if they have the possibility of returning a null value. Great if other people are working with your code.

wheat abyss
ivory sleet
#

But if you’re a disciplined developer

#

It will help you to determine Nullable types

#

It won’t guarantee anything

#

But yeah

woeful moon
#

Ok

vocal cloud
#

Yeah it's less useful if you're working alone or on code that no one else will see but it helps if you leave a project and come back.

ivory sleet
#

The problem is that for instance intellij will assert that anything with that annotation might be null/or never null, which is a bit false as you can still pass null to @NotNull for instance. It’s equally helpful for solo projects as well as team projects imho.

sterile token
#

How would be to get all class object that are annotated with a custom Annotation (Using reflections package from java) ?

ivory sleet
#

The annotation must have retention set to runtime

left swift
#

Is it possible to edit tab completer in existing minecraft command? like summon, kick etc

sterile token
ivory sleet
#

Then checkout AnnotatedElement

#

Stuff like Method, Constructor, Field, Class derive it

sterile token
#

But the annotation wont be on a method/contruscturo. It will be on top of the class name

#

Like this

ivory sleet
#

Yeah verano

#

Then use Class::isAnnotationPresent

sterile token
#

Please an example

sterile token
ivory sleet
#

And Class::getAnnotation

sterile token
#

Thanks

ivory sleet
#

(It has a type parameter which will help you with casting it to your annotation type)

left swift
# ivory sleet Yeah should be

so how? i tried with PacketPlayInTabComplete and PacketPlayOutTabComplete but that doesn't work with minecraft commands for me

ivory sleet
woeful moon
#

Unrelated to the annotations stuff, but I'm getting this error https://paste.md-5.net/yuhumopobo.cs and can't find anything useful online. I'm not extending JavaPlugin twice, and I don't have the plugin installed twice either.

My main class:

public final class BLDiscord extends JavaPlugin {

    @Override
    public void onEnable() {

        // init default config
        getConfig().options().copyDefaults();
        saveDefaultConfig();

        getCommand("discordsyncreload").setExecutor(new BLDiscord());
        Bukkit.getPluginManager().registerEvents(new ChatEvent(), this);

    }
}

Chat listener class: https://paste.md-5.net/urexatiyum.java
Reload command class: https://paste.md-5.net/fucoheluje.java
webhook class: https://paste.md-5.net/iqujofuyop.cpp

ivory sleet
#

Verano the T there is a type parameter

ivory sleet
sterile token
#

Like that conclure?

ivory sleet
#

Ye

#

Then just

#

MyClass.class.getAnnotation(Annotation.class)

#

(Null check also)

sterile token
#

I want something more specific

ivory sleet
#

I mean that’s all

#

The api is pretty minimal

sterile token
#

Conclure why?

#

Mnns

#

I love java btw

sterile token
ivory sleet
#

What does the error say

sterile token
#

required type int

faint sage
ivory sleet
#

Yeah it’s index based

#

Use a map rather then Ig

sterile token
#

I can do a singleton pattern via annotations?

#

I want to something like Spigot service

ivory sleet
#

Spigot service?

sterile token
#

Wait i explain my diea

ivory sleet
#

use this instead of new BLDiscord()

woeful moon
#

oh I see

#

I'll test that

#

although why this? the command is in a separate class

quaint mantle
#

how can I change what the player said using AsyncPlayerChatEvent?

ivory sleet
#

Because new BLDiscord() creates a new object (this does not)

quaint mantle
ivory sleet
#

Wat

sterile token
#

I want to annotate classes with custom annotation. When plugin init it will loop all clases and then save their instance. So i dont have a mess on main class with:

private Classname class;

public void onEnable() {
this.class = new Classname();
}

public Classname getClass() { return this.class; }

#

Do you understand my idea?

quaint mantle
#

I typed something

ivory sleet
#

Sounds strange

quaint mantle
#

and it printed to console

sterile token
ivory sleet
#

Not you

sterile token
#

Ah ok

ivory sleet
#

Verano if you want a dependency injection framework checkout guice Ig

woeful moon
ivory sleet
#

I need to go to sleep now but maybe verano can assist you KickSquare

sterile token
#

Can i tag him?

woeful moon
faint sage
quaint mantle
sterile token
woeful moon
woeful moon
sterile token
#

Thanks

woeful moon
faint sage
tender shard
#

extension methods in kotlin are basically just static methods and can only be accessed from the same kotlin class right? Like e.g.

class Test: JavaPlugin() {

    fun Player.sendColoredMessage(message: String) {
        sendMessage(ChatColor.translateAlternateColorCodes('&',message));
    }
}

is the same as

public class Test extends JavaPlugin {
  static void sendColoredMessage(Player player, String message) {
    player.sendMessage(ChatCOlor.translate.....);
  }
}

with the downside that the kotlin version can only be used in the same class right?

woeful moon
quaint bough
#

is there a way to check if the getItemMeta gives you a meta of type UNSPECIFIC_META

tender shard
quaint bough
#

cuz im causing a crack with item meta i believe

tender shard
#

you could just serialize the itemmeta to see what it is, but that's pretty useless because tbh you will never need it

quaint bough
#

why cant i post screenshots sadge

tender shard
#

you could also get the ItemMeta's classes annotations

quaint bough
tender shard
quaint bough
#

this is my problem ^

tender shard
#

prnt.sc is the worst screenshot website

quaint bough
#

reload

#

but i am verified now anyway so

#

here

#

that is an itemstack without meta

tender shard
#

call getItemMeta once

#

then you'll have ItemMeta

quaint bough
#

but why does it say null

tender shard
#

because the ItemMeta is only created when it is needed

#

that's the source of ItemStack#getItemMeta

quaint bough
#

so this might also be inaccurate

tender shard
#

what do you mean?

quaint bough
#

im just confised why displayName can be null

#

but the item stack is there

tender shard
quaint bough
#

so "Diamond Sword" is standard and gets not saved to displayname

#

cause no name change

tender shard
#

anyway getDisplayName() is annotated with NotNull so it actually should NEVER return null

quaint bough
#

yeah but it just did lol

tender shard
tender shard
quaint bough
#

yeah it doesnt check if it has displayname

#

ill add that and it should resolve the issue

#

weird thing to have @NotNull but still have "Should check that hasDisplayName returns true"

#

that is kinda contradicting

tender shard
#

yeah no idea lol

sullen marlin
#

its called a bug

#

though really it should throw an exception

#

but that would screw up too many plugins nowadays

tender shard
#

in what class is getDisplayName actually implemented?

#

I only found in ItemMeta where it's declared but not implemented

sullen marlin
#

CraftMetaItem

tender shard
#

aaah thx

sullen marlin
#

uh

tender shard
#

hm I can't find that class

sullen marlin
#

the code doesnt look like it will return null to me

#

what spigot version are you on

sterile token
#

md_5?

sullen marlin
#

if (component == null) return "";

#

returns an empty string

quaint bough
#

idk what version of spigot that actually is

sullen marlin
#

1.12.2 didnt have nullable annotations though???

quaint bough
#

not my screenshot

#

that might be the reason lmfao

#

documentation of something more recently

tender shard
#

it should really return "" in 1.18

left swift
#

how can i spawn slime with negative size? i tried with reflections but it doesn't work for me

            EntitySlime slime = new EntitySlime(EntityTypes.aD, worldServer);
            slime.setPosition(location.getX(), location.getY(), location.getZ());
            slime.setNoAI(true);
            try {
                final Field size = EntityInsentient.class.getDeclaredField("bK");
                size.setAccessible(true);
                size.setInt(slime, -2);
            } catch (NoSuchFieldException | IllegalAccessException e) {
                e.printStackTrace();
            }
            worldServer.addEntity(slime);```
quaint bough
#

what would happen with negative size aint that kind of impossible

sullen marlin
#

slimes can only be between 1 and 127 size

tender shard
#

in 1.12.2 getDisplayName() i's not annotated with NotNull and CraftMetaItem simply returns this.displayName there

sullen marlin
#

well guess what, 1.12.2 aint getting bug fixes

quaint bough
#

poor 1.12

tender shard
#

1.12.2 sucks

quaint bough
#

I like it

sterile token
#

Something related with reflections.

When class:
A extends B

The code: will be true?

A.class.isAssignableFrom(B.class)
tender shard
#

no, otherway around

sterile token
#

Ahh ok

#

That why its was not working

tender shard
#

B (the parameter) is a super class / superinterface of A, so B is assignable from A

#

Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.

sterile token
#

mfalex

#

Can you help me?

#

Im going to create a Service.class that every service will extend right?

#

I have a Set<Service> and a method with: Service get(Class<?> clazz) how can i check if the Set contains that class?

tender shard
#

set.contains(clazz) ? 😄

sterile token
#

My set is not type Class<?>

#

That why i ask

tender shard
#

oh

#

yeah

#

something like this:

sterile token
tender shard
#

to check if it contains it

#
        boolean isPresent = mySet.stream().anyMatch(service -> {
            if(service.getClass().equals(clazz)) {
                return true;
            }
            return false;
        });
sterile token
#

it doesnt work

#

Wait

#

My code its trash

#

I explain you

tender shard
#
    /**
     * Returns the given Service by it's class or null
     */
    private Service get(Class<? extends Service> clazz) {
        return mySet.stream()
                .filter(service -> service.getClass().equals(clazz)
                        || service.getClass().isAssignableFrom(clazz))
                .findAny().orElse(null);
    }
#

I'd do it like this

sterile token
#

I created a class with the pupourse of implement it on every service, so them i can do:

Service.get(ServiceTest.class).methodFromServiceClass()

#

But it not possible

tender shard
#

show your service class pls

sterile token
#

right

tender shard
#

and one of the implementations

sterile token
#

right

#

ServiceHandler -> Will be extended by every service
ServiceTest -> A service
Service -> The services manager

sterile token
lethal coral
#

When running a task with a delay should I do it asynchronously?

tender shard
#

you haven't declared any method there

#

oh wait sorry

#

I didnt see the third screenshot

#

but

#

still

#

Service should have a method, probably abstract, called enable()

#

ServiceTest must extend Service

#

and Service should be either an abstract class or an interface

sterile token
#

I want to do it back way around. I want get the methods from the TestService from ServiceHandler

#

And the serivehandler cannot have the methods

tender shard
#

then declare them in ServiceHandler

sterile token
#

Because you will implement it on your servvice class

#

I cannot

tender shard
#

you just write public abstract void enable(); inside

sterile token
#

ait i will use the translator

tender shard
#

anyway your naming is messed up too

#

the ServiceHandler (probably meant to be something like Bukkit's PluginManager) is the class that should handle registering your Services

#

and the Service class should be an interface or abstract class that declares the methods your actual Services should override

sterile token
#

Look, I want to make a system that records a class. And that I then by means of a get(ClassName) can obtain the class instance and then can use the methods. The problem is that each service can have the methods it wants. They will not be predefined from the interface. That's my problem

tender shard
#

so TestService should either implement or extend Service, not ServiceHandler

sterile token
#

Now its clear?

tender shard
charred echo
#

Am I not able to use Hex colors to set the Team#setColor

tender shard
sterile token
charred echo
sterile token
charred echo
#

not implemented yet or just mojang restricting it

tender shard
charred echo
sterile token
#

No no

#

you are not understanding

tender shard
#

well you are not understanding too

sterile token
#

Btw

tender shard
#

so that method should be declared in the interface

#

of course the implementations can have additional methods

sterile token
tender shard
#

yes

#

I know

sterile token
#

That why my code not work

#

Now we are understanding

tender shard
#

I understood this the whole time

sterile token
#

So why you said that i want to implement pre defined method on every service?

#

When i want the opposite

sterile token
tender shard
#
public abstract class Service {
    
    void enable() {
        
    }
    
}

public class TestService extends Service {

    @Override
    public void enable() {
        // Enable logic
    }
    
    public void doTestStuff() {
        // Do test stuff
    }
}

public class SomeOtherService extends Service {

    @Override
    void enable() {
        // Enable logic
    }
    
    public boolean yeeha() {
        return true;
    }
}
sterile token
tender shard
#

there is no sense in defining ANY interface or superclass if those classes are not meant to share at least ONE method

sterile token
#

Ahhh

tender shard
sterile token
#

Yeah

#

I want this bro

tender shard
#

Set<Object>

sterile token
#

1- Register a class
2- Set the instance and save it (until the plugin disable)
3- And get the methods from the service

#

In other words i want to be able to do that

#

I think I explain myself for the ass

tender shard
#

how would you know what methods it has? I don't see ANY real life example on why you would need to store totally unrelated class instances that do not share ANY methods inside the same set. I mean - what are you going to do with them?

#

so you have something like this

public abstract class ServiceHandler {

    Set<Object> myServices = new HashSet<>();
    
    public Object get(Class<?> clazz) {
        // return the Object that belongs to this class
    }

}
#

for what do you ever want to use it?

#
Object object = ServiceHandler.get(SomeClass.class);
// Now what? You have no idea what this object is unless you cast it
sterile token
#

My goal is to stop doing this with every class on my main plugin:

   private Class1 class1;
   private Class2 class2;
  
   public void onEnable() {
     this.class1 = new Class1();
     this.class2 = new Class2();
   } 

   public Class1 getClass1() { return class1; }
   public Class2 getClass2() { return class2; }
#

Now you understand?

errant snow
#

Lombok

#

or kotlin

eternal night
#

Records are crying out

tender shard
sterile token
#

Like what?

tender shard
#
Set<Object> static myServices = new HashSet<>();

    public static <T> T get(Class<T> clazz) {
        return clazz.cast(myServices.get(/* The logic you already have*/))
    }
#

whops

#

the static keyword is at the wrong place

sterile token
#

Yeah i know

#

And then i can do: Service.get(ServiceTest.class).enable() right?

tender shard
#
    static Set<Object> myServices = new HashSet<>();

    public static <T> T get(Class<T> clazz) {
        Optional<Object> result = myServices
                .stream()
                .filter(object -> object.getClass().equals(clazz) || clazz.isAssignableFrom(object.getClass()))
                .findAny();
        return result.map(clazz::cast).orElse(null);
    }
#

Although this is horrible and I have no idea why you would ever need sth like this 😛

#

Or use this instead of result.map:

return result.isPresent() ? clazz.cast(result.get()) : null;
tender shard
quaint bough
#

If you move an item from your players inventory to an (in my case) custom inventory how do I get the moved item? (its not event.getCursor() nor event.getCurrentItem() and also not bag.getItem(event.getSlot()) (InventoryInteractEvent)

#

Using the number buttons

#

so move item 1 with tapping 1 and hovering over the selected slot to move to

sterile token
quaint bough
#

why?

sterile token
#

Because InventoryInteractEvent its an abstract class

quaint bough
#

oh it actually is an inventory click evnet my bad

tender shard
#

@sterile token

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

public class Test {

    static Set<Object> myServices = new HashSet<>();

    public static <T> T get(Class<T> clazz) {
        Optional<Object> result = myServices
                .stream()
                .filter(object -> object.getClass().equals(clazz) || clazz.isAssignableFrom(object.getClass()))
                .findAny();
        return result.isPresent() ? clazz.cast(result.get()) : null;
    }

    public static void main(String[] args) {
        String myString = "this is a string";
        Integer myInteger = 42069;

        myServices.add(myString);
        myServices.add(myInteger);

        CharSequence myCharSequenceAgain = get(CharSequence.class);
        Integer myIntegerAgain = get(Integer.class);
        Double thisIsNull = get(Double.class);

        System.out.println("CharSequence: " + myCharSequenceAgain);
        System.out.println("Integer: " + myIntegerAgain);
        System.out.println("Double: " + thisIsNull);
    }
}

This returns:

CharSequence: this is a string
Integer: 42069
Double: null
#

So yeah it also works for superclasses etc

#

e.g. check it out, I stored a String and got it via get(CharSequence.class)

quaint bough
#

but using inventory click event how would you get the item?

#

nice interger

tender shard
#

but how are you going to store all your instances in the set @sterile token ?

quaint bough
#

ah it has a name

#

hot bar swap

sterile token
tender shard
#

I thought you wanted to store objects

#

there are no "void" objects

#

every object is at least of type Object

sterile token
#

No no forget

#

I was asking if it was possible to do:

Service.get(Class.class).methodName()

#

But its possible

charred echo
#

Am I able to implement support for net.md_5.bungee.api.ChatColor myself, inside of the Team interface? and if yes how would I do it

tender shard
#

it gives you at compile time the guarantee that your object will be of type clazz

sterile token
#

I will have to check

tender shard
#

yeah of course lol

quaint bough
#

How do I get the item that is getting moved to the inventory with a hotbar swap?

tender shard
#

didn't you check the code? if your class is not in the set, it returns null, what else should it return?

tender shard
#

check the event's getClickedSlot, and getCurrentItem

tender shard
sterile token
#

Wait

#

Why would return null?

sterile token
charred echo
tender shard
quaint bough
sterile token
quaint bough
#

but I cant seem to find it

charred echo
quaint bough
tender shard
sterile token
charred echo
sterile token
tender shard
#

I can't tel you if you don't show the code you tried it with

tender shard
#

I sent you a fully working example code in one file and as you can see, it works perfectly fine

sterile token
quaint bough
tender shard
tender shard
sterile token
#

if not i cannot register multiple services at the same time

#

Like i have to do a new line per new register method

sterile token
#

I will take that out

tender shard
#
    public static <T> T register(T object) {
        myServices.add(object);
        return object;
    }
#

Now you can do

charred echo
tender shard
#

MyObject myObject = Test.register(new MyObject());

charred echo
#

if the currentItem.getType is correct

quaint bough
#

im using 1.12.2

sterile token
#

That its want to skip using

tender shard
#
public class Test {

    private static Set<Object> myServices = new HashSet<>();

    public static <T> T register(T object) {
        myServices.add(object);
        return object;
    }

    public static <T> T get(Class<T> clazz) {
        Optional<Object> result = myServices
                .stream()
                .filter(object -> object.getClass().equals(clazz) || clazz.isAssignableFrom(object.getClass()))
                .findAny();
        return result.isPresent() ? clazz.cast(result.get()) : null;
    }

    public static void main(String[] args) {
        String myString = register("this is a string");
        Integer myInteger = register(42069);

        CharSequence myCharSequenceAgain = get(CharSequence.class);
        Integer myIntegerAgain = get(Integer.class);
        Double thisIsNull = get(Double.class);

        System.out.println("CharSequence: " + myCharSequenceAgain);
        System.out.println("Integer: " + myIntegerAgain);
        System.out.println("Double: " + thisIsNull);
    }
}

Works 10000% fine @sterile token

sterile token
#

Btww

dusk flicker
#

nice int

tender shard
#

and it does work fine

quaint bough
#

@charred echo but I know where the object is its on the playerInventory in a certain slot

sterile token
#

The problem is that i want to register the class name and then in the service class its the responsable for creating the object isntance if it doesnt exists

quaint bough
#

only the event.getSlot() returns the destination slot

#

not the startSlot where the item came from

tender shard
sterile token
charred echo
#

@quaint bough

tender shard
#

No it doesn't. It works fine. If it doesn't work, you did something wrong. This will work:```java
Jesus jesus = Test.get(Jesus.class);
if(jesus == null) jesus = Test.register(new Jesus());

charred echo
#

im pretty sure

quaint bough
#

i found it

#

e.hotbarKey

tender shard
quaint bough
#

I think

quaint bough
#

no that cant be right actually

sterile token
charred echo
#

@quaint bough you can just do InventoryClickEvent#isShiftClick

tender shard
#

Verano you have no idea what you are doing

#

you have added an object of instance Class into your set

#

then you try to get the instance of an object of the class SErviceTest

#

you never added any ServiceTest object

quaint bough
#

not to check if it is getting swapped

sterile token
charred echo
#

thats just the event item

tender shard
#

you do service.register(ServiceTest.class)

quaint bough
#

but it isnt

tender shard
#

ServiceTest.class is an object instanceof Class<?>

charred echo
#

what do you mean by swapped

quaint bough
#

hover over item and press 1

charred echo
#

when a player shift clicks an item and it goes directly into a chest

#

=

quaint bough
#

or hover over slot andp ress one

tender shard
#

what you obviously want to do is to register a NEW ServiceTest, and not ServiceTest.class

charred echo
#

ah

tender shard
#

@sterile token

charred echo
#

then u do

sterile token
#

Thats why i want this system

tender shard
#

erm what the fuck

#

why

sterile token
#

To skip doing new Class() and then getting its intance

dusk flicker
#

.newInstance();

tender shard
#

this can never work

sterile token
tender shard
#

what if your class requires constructor params?

dusk flicker
#

wouldent recommend it tho