#help-development

1 messages · Page 1664 of 1

smoky oak
#

you cant change one variable you have to make it completely new

hybrid spoke
#

yeah

#

immutable concept

#

DTOs

#

very useful

daring sierra
#

cool

calm whale
#

But I should have only one, I clear the default renderer to add mine with the red X cursor

lost matrix
#

This:

  @EventHandler
  public void onInteract(final EntityDamageEvent event) {
    if (!(event.getEntity() instanceof final Player player)) {
      return;
    }
    player.sendMessage("Yay");
  }
lusty cipher
#

let's watch how every other discord will say the same, but seeya 👍

hybrid spoke
#

we already helped you enough

#

aaand hes gone

candid galleon
#

bruh pattern variables are MWAH

young knoll
#

“”” Strings “”” are also neat

hybrid spoke
#

at least not yet

lusty cipher
#

The biggest downside I see of records is that Gson doesn't support them and it's the only lib embedded in MC (or Spigot? idk) that I am aware of

young knoll
#

The instanceof variable creation is very nice

lusty cipher
lost matrix
# hybrid spoke okay i am not a fan of this

Oh you like casting and redundant calls...

  @EventHandler
  public void onInteract(final EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player)) {
      return;
    }
    final Player player = (Player) event.getEntity();
    player.sendMessage("Yay");
  }
smoky oak
#

how in the world do you create a variable with a instanceof operator

grim ice
#

wdym

#

itll run code

#

for each stick

lusty cipher
young knoll
#

Technically the final isn’t necessary

grim ice
#

isnt that what he wants

lost matrix
smoky oak
#

no isnt instanceof just comparing two objects and checks if both are instances of the same class?

grim ice
#

@lost matrix why do you add final?

hybrid spoke
lusty cipher
#

You could also just do it like this, makes it even simpler for a short code block

  @EventHandler
  public void onInteract(final EntityDamageEvent event) {
    if (event.getEntity() instanceof final Player player) {
      player.sendMessage("Yay");
    }
  }
lost matrix
grim ice
smoky oak
#

ah so you create the variable if and only if its an instance of the variable you are trying to create

#

that makes more sense

hybrid spoke
#

and overusing it is bad too

grim ice
#

o

hybrid spoke
#

at least against the java language specifications

grim ice
#

but tbh i like how smile do stuff

#

ill prob do his way dunno

lusty cipher
#

but if you're already using Java 16 you could also just use var to skip writing types completely lol

grim ice
#

making my own style is really bad for now i guess, i found out i competely suck at principles

lost matrix
candid galleon
#

var is a forbidden word for me

lusty cipher
#

var is bae

smoky oak
#

im only using java 16 because I dont want to use legacy mode

lost matrix
#

Same. Go do JS if you want ambiguous variables.

smoky oak
#

urgh

#

in js

#

I can never remember what 'this' is

daring sierra
lost matrix
grim ice
#

for me i liked how smile did it

#

ill 100% use his way from now on

hybrid spoke
young knoll
#

It’s only bad if you purposely make things final that shouldn’t be final and then create ugly workarounds

candid galleon
#

unnecessary final usage is so ugly imo

young knoll
#

You’d hate netbeans

celest oasis
#

How to check if the mobs is undead or not?

young knoll
#

You’d probably need a custom method for that

lost matrix
young knoll
#

I don’t know if the API exposed anything

lusty cipher
smoky oak
#

yea

young knoll
#

You could make a set of entity types and then use contains()

lost matrix
hybrid spoke
candid galleon
#

there's probably a tag for that

minor garnet
#

i getting this error on run my maven project why ? im using jdk 1.8

young knoll
#

Don’t know if Mojang ever moved that to a tag

cyan oyster
#

[19:49:03 ERROR]: Could not load 'plugins\a.jar' in folder 'plugins': uses the space-character (0x20) in its name

but the plugin name is

a.jar
no spaces

#

error

young knoll
#

Not the file name

#

The name in plugin.yml

hybrid spoke
celest oasis
hybrid spoke
celest oasis
#

Under certain cicumstance

hybrid spoke
#

then build again

lost matrix
quiet ice
lusty cipher
grim ice
#

@lost matrix btw how do i make intellIj do that too

hybrid spoke
grim ice
#

i think it doesnt do that for me

celest oasis
#
        if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) {
            System.out.println("Test");
            for (Class classCheck: UNDEAD) {
                if (classCheck.isAssignableFrom(event.getEntity().getType().getEntityClass())) {
                    event.setDamage(event.getDamage() * 0.75);
                    return;
                }
            }
        }

That's what I did for now event is EntityDamageEntityEvent

hybrid spoke
#

the sdk in your project structure

lost matrix
hybrid spoke
lost matrix
#

Has to be final. Anyways.

candid galleon
#

could also just use a ternary

#

one line it

hybrid spoke
lusty cipher
hybrid spoke
lost matrix
cyan oyster
hybrid spoke
#

would agree otherwise if you would code in notepad

#

but you dont

lusty cipher
lost matrix
celest oasis
young knoll
#

I would just use a list of entity types rather than classes

lusty cipher
#

^

#

reflection for such a case is..... nasty

lost matrix
#

It also shows a clear intention for the variables not being subject to re-declaration.

young knoll
#

Just don’t be like mojang

#

final immutable lists are evil for modders

hybrid spoke
#

understandable on instance or class variables, but not at local variables. just declare the method or parameter as final so nobody can override it.

lusty cipher
#

For the final thing, I personally only really care for fields to be final if they should and then. Inside of a function I don't make anything final in 90% of the cases, except if there's a lambda.

hybrid spoke
celest oasis
lost matrix
young knoll
#

Every entity type that you want to consider undead

#

You can do it all in one line with Arrays.asList or similar

celest oasis
#

Alright thx

lost matrix
hybrid spoke
#

^ agreed

candid galleon
#

instanceof Zombie and Skeleton should cover most of the alternatives

#

i think technically spider is undead?

stone sinew
#

Whats he trying to do?

candid galleon
#

EntityType#isAlive is also a thing

young knoll
#

Zombie, skeleton, zombie piglin, wither

lost matrix
candid galleon
#

honestly isAlive should cover all of it

young knoll
#

Ah yeah isAlive looks good

#

I was wondering if spigot exposed that somewhere

#

Although that may be for LivingEntity not undead

grim ice
#

what java tutorial do you guys think is good for functional interfaces and java principles? I'm missing on those

hybrid spoke
#

#isAlive doesnt even have javadocs

celest oasis
young knoll
#

You can always test it

#

But I assume its the same as instanceof LivingEntity

candid galleon
#

wym

#

why would it be attached to entitytype lol

lost matrix
#

Ill go into NMS and look how the smite enchantment determines undead...

young knoll
#

Because not all types are alive?

candid galleon
#

ah

#

i see

young knoll
#

I assume there is a Boolean somewhere in NMS that spigot should expose

celest oasis
young knoll
#

The smite enchant and instant health/damage effects must use something

hybrid spoke
#

arent nearly all Monster undead

young knoll
#

No

grim ice
#

No

young knoll
#

Most are not

lusty cipher
#

is a Creeper udnead?

young knoll
#

Silverfish, spiders, creepers, endermen, ghast, blaze, are all not undead

celest oasis
#

Zombie variant, Skeleton variant, wither and zoglin only

grim ice
#

there are 49 undead mobs

celest oasis
lost matrix
celest oasis
#

Like mc dungeons

young knoll
#

Yeah that was my original suggestion

#

Well a set, enumset is a good call

hybrid spoke
#

there is nothing you can identify if its undead or not actually

young knoll
#

There is

#

There has to be somewhere

hybrid spoke
#

at least not in the api

celest oasis
young knoll
#

Pretty much

#

But set.contains is faster than list.contains

lost matrix
#

This is how the smite enchantment does it.

entityliving.getMonsterType() == EnumMonsterType.b;
#

Very insightful

celest oasis
#

lmao

young knoll
#

Monster type should be exposed in the API then

#

I assume arthropod is also a part of that

lost matrix
#

I have no idea whats part of that because i dont have the moj mappings applied atm

grim ice
#

do you guys recommend "Clean Code"?

young knoll
#

Well apply the dang mappings then :p

hybrid spoke
grim ice
#

yes

hybrid spoke
#

which one

lost matrix
young knoll
#

Exactly

grim ice
#

by robert martin

young knoll
#

Job security through obscurity

hybrid spoke
lost matrix
grim ice
#

okay ill read it i guess

#

i hope i can understand something from it though LOL

lost matrix
zealous crow
#

hello there, not 100% sure it's a good place to do it, but as dev's what do you think about my project and it's documentation attached? is it reallistic to have a 200€ budget(shops hook excluded) for it?

hybrid spoke
#

have it myself

#

informative

young knoll
#

I’m sure he’s a great guy but writing an entire book about clean code does not make you sound fun at parties :p

hybrid spoke
zealous crow
#

french mistake^^ thanks

candid galleon
#

is that a default powerpoint background

hybrid spoke
#

but his idiom is like "you have to do this and everything except of me is doing it wrong"

zealous crow
candid galleon
#

why bother having it in the first place

grim ice
#

bro why is he explaining how far away is the sun

#

wtf

dim bluff
#

hey... I'm still stuck xD, why is the "dataSection.getKeys(false)" empty

candid galleon
#

well what does the config look like?

lost matrix
dim bluff
candid galleon
#

and how do you know it's empty?

grim ice
#

smile wouldve told you that lol

candid galleon
#

yall really got some issues with configs

lost matrix
grim ice
#

o

dim bluff
candid galleon
#

can we see the code and the resulting print message?

lost matrix
open pawn
#

hey i made a copy paste plugin and when i copy chests and tileentity in general i use nbtTagCompound with 1.15 NMS and when i load the nbt the chest/beacon/any other tile entity i see the copied chest/beacon inventory for a milisecond and then it instantly closes. i checked and the items are not bugged

#

any help?

dim bluff
lost matrix
dim bluff
#

why isn't my config.yml from the IDE saving?

lost matrix
#

Show your onEnable. the saveDefaultConfig() method fails silently if there is already a config present so that user configs dont get overwritten.

grim ice
#

WTFs/minute

dim bluff
lost matrix
# dim bluff

Should be fine. Remove the config.yml and restart your server.

dim bluff
#

it keeps creating an emptry config

#

"empty"

lost matrix
#

Ok

  1. Stop the server
  2. Remove the config.yml
  3. Start the server
#

If you just delete then restart, the onDisable will safe the empty map into your file

hybrid spoke
#

why are you reloading the config after just saving it

lost matrix
dim bluff
#

Pog

hybrid spoke
dim bluff
#

tytytytytytytytytyy

lost matrix
lost matrix
#

Noice

hybrid spoke
#

yeah it does

#

at least if the config doesnt exist

#

otherwise it fails

dim bluff
#

tyty

grim ice
#

its been fking 30 minutes

#

he still didnt start talking about coding

#

what the fuck?

hybrid spoke
#

not everything in coding is coding

grim ice
#

yeah but i dont wanna know how faar is the sun from me

#

or why i would go to jail for coding

#

ffs im making spigot plugins

calm whale
ancient plank
#

coding for me is 30 minutes of making sure my packages and maven is set up correctly

grim ice
#

wtf

#

it takes like 3 minutes

bitter mural
#

Hey, all! Is there a standard way to simulate a random tick in a chunk that is more than 128 blocks from any players, or should I roll my own?

lost matrix
ancient plank
#

lol

#

actual truth

eternal oxide
zealous crow
#

I have a nice score for my WTF per minute about my plugin request documentation i published few minutes ago: only one typo and not a single "WTF bro 200€ for that work! you are crazy!"

bitter mural
calm whale
grim ice
#

aaa im so lost

#

idk what to start with

#

i wanna get better at java but idk what to do

eternal oxide
#

you are pasting in quaters

calm whale
#

I paste nothing

hybrid spoke
eternal oxide
#

you are setting the map in quaters

#

4 across teh z

calm whale
eternal oxide
#

you are doing a whole mess of math in your for loops that can easily go wrong. do the math in the setPositionRaw not the for loops

lost matrix
grim ice
#

?paste

undone axleBOT
grim ice
calm whale
eternal oxide
#

ok, each section of your map is 32?

#

or 64?

#

well you are setting chunk tickets on an area of chunks 64 x 64

calm whale
#

OH, WAIT, I juste set the scale to normal

#

it is almost good

crude charm
#

Is it possible to do x marks the spot on 1.8?

#

^ using inbuilt spigot methods

#

aka no packets

grim ice
#

i want to access something from an abstract class but the field is protected, what do I do

eternal oxide
#

a getter

crude charm
#

^

grim ice
#

it works there?

#

ok ig

worldly ingot
#

If you have a protected field you can access it from the child class. Unless you're not extending it

#

In which case, yeah, same package or a getter

eternal oxide
#

Originally his design was an abstract class with a protected static Map as he only need to access it within all command classes. But his design seems to have expanded beyond that and he is now wanting to access it from other classes, invalidating the original design. He should move the map to its own class now with getters/setters. and scrap the abstract base class.

grim ice
#

so i changed it

#

isnt it same as static abuse?

eternal oxide
#

no

grim ice
#

either way

#

i had a listener class in a commands package

#

lol

eternal oxide
#

Thats fine, if yoru listener is ONLY affecting the command

#

not a listener class but a listener in a command class

crude charm
#

up to you tho

eternal oxide
#

Its time to redesign yoru whole layout.

grim ice
#

i prefer a diff package for listeners

crude charm
#

^ thats what I do

eternal oxide
#

your leaders Map should now be in its own singleton class with util methods/getter/setters

crude charm
grim ice
#

o

eternal oxide
#

never give direct access to the map. Keep full control of add/remove/search/clear etc via getter/setter

grim ice
#

o

grim ice
#

how to make a method accept any type of collection

#

like a list or an arraylist or a hashmap

eternal oxide
#

I showed you a method like that

stone sinew
eternal oxide
#

public <T extends Collection<ItemStack>> void doStuff(T collection)

grim ice
#

o

#

Raw use of parameterized class 'Collection'

eternal oxide
#

or whatever

grim ice
#

public <T extends Collection<Object>> void doStuff(T collection)
?

eternal oxide
#

don;t use Object if you know what the contents will be

grim ice
#

btw what does "T" mean?

#

also i dont

quiet ice
#

what the hell am I witnessing

#

T is a generic parameter in this case

grim ice
eternal oxide
#

T means, read up on java generics

grim ice
#

theyre not explaining whats t or e or whatever

#

NVM

#

i foudn a website

#

t means type right

#

i knew k and v

eternal oxide
#

yes

#

they are all generic variables

#

you assign something to, then use in yoru code

#

in our case it was a type variable T was assigned T extends Collection<Object>

#

so T value would accept anyhing that extended Collection

grim ice
#

but public void clear(Collection<Object> collection){

#

would work too

#

right

eternal oxide
#

yes

#

learn generics and use them

#

they are mighty powerful

grim ice
#

o

bitter mural
#

How does one measure the impact of one's plugin on a server? I.e. how much lag?

#

Is there maybe a tool people use, or maybe emperical evidence? Feedback from users?

eternal oxide
#

/timings

tidal skiff
#

bruh i thought this was a simple thing but apparently not

#

how tf do u generate a random number

#

i cant find any useful info online

#

that explains how it works

eternal oxide
#

google java random

tidal skiff
#

i have

eternal oxide
#

and what did you come up with?

tidal skiff
#

new Random() shit

eternal oxide
#

good shit

grim ice
#

how do i return based on an if? isnt there smth liek return ? smth

manic bison
#

hey, how can i count how many players have a certain potion effects ?

#

that returns an int

grim ice
manic bison
#

thanks!

grim ice
#

:D

#

@eternal oxide idk it seems useless to make those util methods

#

as each of my classes

#

have their own checks

eternal oxide
#

all your checks shoudl be in your one class

#

the one with the Map

#

all your other classes should use the util methods to request a result

grim ice
#

so i have to make like

#

7 util methods

#

for checks?

eternal oxide
#

if thats what you need, yes

grim ice
#

aaa

#

is that really necessary, i cant see any improvement if i do that

#

its the same thing

eternal oxide
#

you should only be needing isLeader, getLeader, isMember, addLeader, addMember, getTeamIndex, removeMember, removeLeader, clear

stone sinew
grim ice
#

^

grim ice
#

aaaaaaaaaaaa

#

why is life this painful

#

btw

#

dis no work

#

public <T extends Collection<Object>> void clear(T collection){

eternal oxide
#

no work?

grim ice
#

yes 1s lemme sendu da thing

#

reason: no instance(s) of type variable(s) exist so that LinkedHashMap<UUID, List<UUID>> conforms to Collection<Object>

tidal skiff
#

anyone know how dream did his 'Minecraft, But The World Changes Every Time...'?? like how do u generate a new seed and delete the old one

eternal oxide
#

it would be easier if you gave a full error

grim ice
#

Required type:
T

Provided:
LinkedHashMap
<java.util.UUID,
java.util.List<java.util.UUID>>
reason: no instance(s) of type variable(s) exist so that LinkedHashMap<UUID, List<UUID>> conforms to Collection<Object>

eternal oxide
#

and the code?

worldly ingot
#

he's passing a map into his clear method that requires a collection

#

(1) your method signature above has no purpose being generic whatsoever

grim ice
#

public <T extends Collection<Object>> void clear(T collection){
collection.clear();
}
clear(leaders);

eternal oxide
#

other way around I believe

worldly ingot
#

(2) tf are you writing a method to just call .clear()?

eternal oxide
#

yeah, its a map nto a collection

#

so you need to find that collection in values to remove it

grim ice
#

o

eternal oxide
#

um, why are you calling clear on teh collection you just passed?

grim ice
#

to cleaar it

worldly ingot
#

Yeah but you can just not write the method to begin with and just call collection.clear()

#

Like... pandaWtf

eternal oxide
#

clear shoudl be a no args method to clear the map

worldly ingot
#

Why are you writing a method for that?

grim ice
#

i prob misunderstood him though

eternal oxide
#

if you want to remove a specific team you create a method like removeTeam or removeLeader

worldly ingot
#

I mean... yeah that's definitely not what they meant lol

grim ice
stone sinew
grim ice
#

tbh why even make the methods

grim ice
eternal oxide
#

yeah no, don;t return teh map

grim ice
#

i dont think i should make those methods tbh

#

if i should i would prob just make isMember and isLeader

eternal oxide
#

yes

grim ice
#

and getteamindex

#

are the only ones useful

#

others are like 2 lines

eternal oxide
#

Thats what I'm saying. util methods. Do not explose the map itself

#

before it was fine as your map was in an abstract class as protected static

#

Now you are needing access in other classes you move it to its own singleton class with util methods to control all access

#

You may not see the point in this simple code, but later when you want to run things async and have to synchronise code.

grim ice
#

yes

waxen plinth
#

DURABILITY should do the trick in 1.12 and below

eternal oxide
#

or some other plugin tries to access your map via the async chat handler. You can easily make your code threadsafe.

worldly ingot
#

There's nothing wrong with exposing the map in a getter but if you're going to do so, at least either make a copy. Immutable or mutable depending on whether or not you want to allow developers to adjust a copy of the map when they receive it (either Collections.unmodifiableMap(map), Guava's ImmutableMap.copyOf(), or new HashMap<>(map) depending on what you want - all of them are different)

#

Though it also shouldn't be your primary means of receiving information from a map. Ideally there would be getters that yield the appropriate values/keys

quaint mantle
waxen plinth
#

I'm on mobile

#

Could you put it on a paste service?

#

?paste

undone axleBOT
quaint mantle
waxen plinth
#

Looks good to me

#

I'll merge if you want to PR it

quaint mantle
#

I'm sorry but I will let you do so if and whenever you want. I'm working on something right now ^^

waxen plinth
#

Okay

lost matrix
#

VersionResolver.getNms().getVersion() <= 1.12 float condition with doubles can be dangerous.

waxen plinth
#

That's gonna be fine as long as you don't do ==

quaint mantle
#

my bad. Thank you to have spotted that ^^

#

my getVersion returns an int. modified it on one side but forgot the other ^^

waxen plinth
#

But it would be a good idea to use an int for the major semver

#

Okay

lost matrix
#

Might be 1.12000000000000024 and fail

waxen plinth
#

True

grim ice
#

anyone can help me make dis better

#

but no toxicity pls

#

im still learning

cold field
hidden delta
waxen plinth
#

I don't know if it's possible to delete the main world

#

You can easily make more though

grim ice
quaint mantle
#

how to make a description of the subject with the ability to add lines through the config?

severe zenith
#

hey, how to prevent a EntityDamageEvent to be reduced by armor or something

lost matrix
severe zenith
#

yeah, sry

quaint mantle
#

I think through if and setcanceled

severe zenith
#

didnt get the english word

#

no i want to call it

lost matrix
#

Thats not possible directly. You can set the damage in the event to 0 and reduce the entities health by the amount of damage in the event before.

#

Unless you are in an older version. For some reason the event had a setFinalDamage() method which could be used to bypass all damage reduction...

#

Why was that removed anyways?

severe zenith
#

no im in 1.16

severe zenith
severe zenith
#

what do you mean with "in the event before"?

lost matrix
#
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onDamage(final EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player player)) {
      return;
    }
    final double damage = event.getDamage();
    event.setDamage(0);
    player.setHealth(Math.max(player.getHealth() - damage, 0));
  }
#

You should also increase the event priority

severe zenith
#

ok, got it, thanks

quaint mantle
#

how to make a description of the subject with the ability to add lines through the config?

#

are you speaking about items name and lore @quaint mantle ?

#

yes

#

via config

#

It's complicated.
You need to read the config file and to build the item stack accordingly.

#

You know how to read a config file ?

#

yes

#

I already have a config with the name of the item

#

how can I add a description to an item?

lost matrix
#

You can load a List<String> from a config.

item:
  type: IRON_SWORD
  name: "Cool item name"
  lore:
    - ""
    - "This is"
    - "an example"

Then you can read the List<String> from the path item.lore

quaint mantle
#

how to use it?

lost matrix
quaint mantle
#

how do I get the name and description from the config in the code?

#

oh

#

final List<String> lore = plugin.getConfig().getStringList("mySampleItem.lore");

lost matrix
#
    final FileConfiguration configuration = ...;
    List<String> lore = configuration.getStringList("item.lore");
    String name = configuration.getString("item.name");
    Material material = Material.matchMaterial(configuration.getString("item.type"));
quaint mantle
#

can I add more lines of description?

tall dragon
#

yes

quaint mantle
#

as many as you want

#

how?

#

but if you add too much you will have display issues in minecraft

tall dragon
#

well type them in the config

quaint mantle
#
item:
  type: IRON_SWORD
  name: "Cool item name"
  lore:
    - ""
    - "This is"
    - "an example"
    - "with more lines"
    - "and even more lines"
quaint mantle
#

thank you all very much for your help. I will try

#

Good luck

restive tangle
#
    private static void createItem(Material mat, String name, Boolean glow, ItemStack itemParse){
        ItemStack item = new ItemStack(mat);
        ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(Utility.color(name));
        if(glow){
            itemMeta.addEnchant(Enchantment.LUCK,1,false);
            itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        }
        item.setItemMeta(itemMeta);
        itemParse = item;
    }

I made this method , on the init i added the createItem and added it to the on enable , the itemParse is the private itemstack in the class

#

it does not seem to work because whenever i call this command it does nothing

    public static void giveLobbyItems(Player p){
        p.getInventory().clear();
        p.getInventory().setItem(0,Items.multiplier);
        p.getInventory().setItem(4,Items.clicker);
        p.getInventory().setItem(5,Items.playerCompass);
        p.getInventory().setItem(8,Items.warp);
    }
tardy delta
#

Boolean

restive tangle
#

?

tall dragon
#

he means you should use the primitive type

#

aka "boolean"

restive tangle
#

oh , alright ill try thanks

tall dragon
#

well that wont solve the problem

#

it was just an observation

restive tangle
#

hm , so what do you think the issue is

tall dragon
#

well this is not quite enough information. can you show me the init part

restive tangle
#
    public static ItemStack warp;
    public static ItemStack multiplier;
    public static ItemStack playerCompass;

    public static void init(){
        createItem(Material.BEACON, "&6&lClicker", true, clicker);
        createItem(Material.PAPER, "&e&lWarp",true, warp);
        createItem(Material.EMERALD, "&e&lShop",true, multiplier);
        createItem(Material.COMPASS, "&e&lPlayers", true, playerCompass);
    }```
tall dragon
#

huh

quaint mantle
#

works. thank you very much to everyone

tall dragon
#

why dont you make createItem return an itemstack

#

and set the variable in the init method

#

like clicker = createItem(Material.BEACON, "&6&lClicker", true);

restive tangle
#

@tall dragon thanks , it works

grim ice
#

how to get a random index of a list

#

list.get(ThreadLocalRandom.current().nextInt(smth and list.size())

tardy delta
#

yes

hardy pivot
#

Hi

#

I have created a 1.17 plugin and i want to run in 1.8, but i dont want to create the same plugin for 1.8, how i can do a complete [1.8-1.17] support?

stone sinew
quiet ice
#

How often do you use the material enum?

stone sinew
quiet ice
#

If you use it often that you may need to rewrite your plugin, if you never use it, there isn't too much of an issue

stone sinew
#

Material gets the enum from the server version so it shouldn't cause issues

quiet ice
#

And if you don't want to have the 10+ second delay (may differ from machine to machine) you will have to basically have two declarations for each version

stone sinew
quiet ice
#

Material.BROWN_WOOL is a candidate that would bork

stone sinew
#

When I wasn't using my own enum I did Material.valueOf() for the materials everything else I only got the material from getType() anyways

quiet ice
#

It becomes easier if you write your stuff with inter-version compat in mind

quaint mantle
#

🐶

quiet ice
#

That is bark

quaint mantle
#

bork bork

burnt current
#

Sorry, I don't quite understand what you mean. So I should use System.out.println() to print the type of the block and see if it is the right type and then before I fetch the BlockData from the block check with an Instanceof check if it is the right type?

burnt current
#

how exactly do you mean?

feral lodge
#

what is the NMS packet for moving a fake player (both position and look)?

lost matrix
silver shuttle
#

Are there any spigot limitations to the Java method "Runtime.exec()"?

ivory sleet
#

probably not

#

Tho I usually use the process builder or what its called over exec from Runtime altho I'd presume they do roughly the same thing

silver shuttle
#

kk

#

ty

lost matrix
silver shuttle
#

pfffh I would never

#

just add an ingame command to execute real cmds

severe zenith
#
Bukkit.getPluginManager().callEvent(new EntityDamageEvent(p, EntityDamageEvent.DamageCause.CUSTOM, 5));

any idea why this doest work?

silver shuttle
#

and pass the arguments into that command

ivory sleet
silver shuttle
#

🙂

next stratus
#

Hey, just a question regarding lores + nbt; I wanna store some values on a item and make it update in the lore when something happens how would ya'll do it? 🙂

severe zenith
ivory sleet
#

ofc not

#

but it fires the event

#

use Attributable#getAttributeInstance to change the health

severe zenith
#

theres no static method
org.bukkit.attribute.Attributable.getAttributeInstance()

eternal oxide
#

Attributable

ivory sleet
#

its an instance method my fellow developer

burnt current
# lost matrix Yes. Check the type of the block.

ok, so I tried if(location.add(1,4,4).getBlock().getType() instanceof Material.BRICK_STAIRS), but then Material.BRICK_STAIRS in my IDE gives me the error Unknown Class 'Material.BRICK_STAIRS and the line after that (Stairs stairs1 = (Stairs) player.getWorld().getBlockAt(location.add(1,4,4)).getBlockData();) gives the error Declaration not allowed here.

severe zenith
eternal oxide
burnt current
ivory sleet
#

actually

#

player.setHealth(amount) should work

severe zenith
quaint mantle
#

List<String> lore = config.getStringList("messages.gui.onebottle.lore");
lore = lore.replace("&", "\u00a7");

why doesn't it work?

ivory sleet
#

Im dumb sry

eternal oxide
#

player.getAttribute(Attribute)

quaint mantle
#

you cant do replace

#

List#stream().map(s -> s.replace()).collect(Collectors.toList())

#

how can I do this? this is a description of the subject

eternal oxide
quaint mantle
severe zenith
quaint mantle
ivory sleet
#

yeah listen to the damge event also

quaint mantle
ivory sleet
#

and neutralize possible resistance

quaint mantle
#

streams are the most useful thing in java collections

ivory sleet
#

imagine streams without lambdas

quaint mantle
#

how would that even work lol

burnt current
quaint mantle
#

create a runnable in every function aPES_Giggle

#

.map(new Mapper<T>())

ivory sleet
#

streams without generics ASevil

quaint mantle
#

cast from objects

ivory sleet
#

🥲

eternal oxide
quaint mantle
#

@quaint mantle, I still didn't understand how to do it

#

Bruh

#
List#stream().map(s -> s.replace()).collect(Collectors.toList())
#

cmon you got this

ivory sleet
#

pog

eternal oxide
burnt current
#

yes. The whole thing is in a listener for a BlockPlaceEvent. When a certain block is placed, a block should be set at certain coordinates from the coordinate where it was placed.

eternal oxide
#

always oriented in one direction?

burnt current
#

yes

lost matrix
# burnt current yes

So its not relative to the placed block. Always in the same position relative to the player.

#

And from the looks it could even be the same block the player just placed.

burnt current
#

no not to the player. To the block placed by the player

lost matrix
burnt current
#

I have made it so that it is only executed when a certain block is placed. In this case a red banner

burnt current
#

of course

severe zenith
burnt current
#

But I remove some parts that have nothing to do with this part of the method, as the message would then also be too big

lost matrix
severe zenith
#

when i use damage() i dont get the event object

#

or do i?

lost matrix
#

Oh i see what you are trying to do...

#

Hm. There are two approaches. Ill give you one example.

burnt current
# lost matrix Mind showing the whole method?
@EventHandler
    public void BannerListener(BlockPlaceEvent event){


        if(event.getBlockPlaced().getType() == Material.RED_BANNER) {
            Player player = event.getPlayer();
            event.setCancelled(true);
            Location location = event.getBlockPlaced().getLocation();

Main.getPlugin().getServer().getScheduler().runTaskLater(Main.getPlugin(), () -> {
                location.add(1,4,4).getBlock().setType(BRICK_STAIRS);
                if(location.add(1,4,4).getBlock().getType() == Material.BRICK_STAIRS)
                Stairs stairs1 = (Stairs) player.getWorld().getBlockAt()).getBlockData();
                stairs1.setFacing(BlockFace.WEST);
                player.getWorld().getBlockAt(location.add(1,4,4)).setBlockData(stairs1);



                player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 29);
            }, 300);
#

Oh crap I think I have found the error

stone sinew
#

Main.getPlugin().getServer().getScheduler().runTaskLater(Main.getPlugin(), () -> { to Bukkit.getScheduler()

burnt current
#

i have forgotten the {} after if(location.add(1,4,4).getBlock().getType() == Material.BRICK_STAIRS)

lost matrix
# severe zenith when i use damage() i dont get the event object

Number one:

  public void damageWithoutReduction(final Player player, final double damage, final DamageCause cause) {
    final EntityDamageEvent event = new EntityDamageEvent(player, cause, damage);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
      return;
    }
    player.setHealth(Math.max(0, player.getHealth() - damage));
  }
burnt current
paper viper
#

You should try to avoid naming your main class as Main too

#

and get into the practice of using dependency injection

#

?di

undone axleBOT
severe zenith
lost matrix
burnt current
lost matrix
# severe zenith but this doesnt do the damage effect, does it?
  private final Set<UUID> bypassedPlayers = new HashSet<>();

  public void damageWithoutReduction(final Player player, final double damage) {
    this.bypassedPlayers.add(player.getUniqueId());
    player.damage(damage);
  }

  @EventHandler
  public void onDamage(final EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player player)) {
      return;
    }
    if (!this.bypassedPlayers.remove(player.getUniqueId())) {
      return;
    }
    final double damage = event.getDamage();
    event.setDamage(0);
    player.setHealth(Math.max(0, player.getHealth() - damage));
  }
paper viper
#

So instead of storing the plugin instance as a singleton (which is what you are doing right now while using static), you remove the static to make it not a singleton anymore, and pass that instance around

#

through the constructor

#

For example:

public final class MyPlugin extends JavaPlugin {

  private MyPlugin instance;

  @Override
  public void onEnable() {
    instance = this;
    getServer().getPluginManager().registerEvents(this, new MyListener(this));
  }

}

public final class MyListener implements Listener {
  
  private final MyPlugin plugin;

  public MyListener(final MyPlugin plugin) {
    this.plugin = plugin;
  } 

  @EventHandler
  public void onDeath(final PlayerDeathEvent event) {
    plugin.doSomething ... etc
  }

}
#

i typed this in Discord and without IDE

#

so im not sure if the second line of onEnable is correct but I think it is

burnt current
paper viper
#

you should review some java skills then

#

but its what is called first when an object is being instantiated

burnt current
#

ok

#

I'll have another look at that too. Thanks for the tip

paper viper
#

np

severe zenith
burnt current
# lost matrix Mind showing the whole method?

ok, so now I don't get an error in my IDE or in the console, but the stairs are still facing south, even though I set their facing to west. Do you know what I could have done wrong?

lost matrix
burnt current
#

yes

#

Should I send the complete code again?

lost matrix
#

Sure...

burnt current
#
@EventHandler
    public void BannerListener(BlockPlaceEvent event){


        if(event.getBlockPlaced().getType() == Material.RED_BANNER) {
            Player player = event.getPlayer();
            event.setCancelled(true);
            Location location = event.getBlockPlaced().getLocation();

Bukkit.getScheduler().runTaskLater(Main.getPlugin(), () -> {
                location.add(1,4,4).getBlock().setType(BRICK_STAIRS);
                if(location.add(1,4,4).getBlock().getType() == Material.BRICK_STAIRS) {
                Stairs stairs1 = (Stairs) player.getWorld().getBlockAt()).getBlockData();
                stairs1.setFacing(BlockFace.WEST);
                player.getWorld().getBlockAt(location.add(1,4,4)).setBlockData(stairs1);
              }


                player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 29);
            }, 300);
lost matrix
#
    if (event.getBlockPlaced().getType() == Material.RED_BANNER) {
      Player player = event.getPlayer();
      event.setCancelled(true);
      Location location = event.getBlockPlaced().getLocation();
      Block relativeBlock = location.add(1, 4, 4).getBlock();

      Main.getPlugin().getServer().getScheduler().runTaskLater(Main.getPlugin(), () -> {
        relativeBlock.setType(Material.BRICK_STAIRS);
        BlockData stairData = relativeBlock.getBlockData();
        Stairs stairs = (Stairs) stairData;
        stairs.setFacing(BlockFace.WEST);
        relativeBlock.setBlockData(stairs);
        player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0F, 2.9F);
      }, 300);
    }

Cleaned it a bit up. This should work.
If you dont see changes then the stairs might already face west.

#

Just tested it. It works.

burnt current
#

yeah it works 🥳 thank you so much for your help 🙏

unkempt peak
#

are you sure the if statements are working?

gilded spruce
#

can anybody tell me what an instance is and what it does

unkempt peak
#

sysout inside the if statements and see if they are running

unkempt peak
gaunt saffron
#

i sadly had to install intellij, have 2 issues i can't really solve
my plugin gave me this directory jetbrains://Idea/settings?name=Better+Comments
where are the configs? im on win10

when i use comment with line shortcut, it jumps to the next line, i don't want that...
how do i fix this?

also, where are all the settings located, i'd like same setup on multiple machines

unkempt peak
# gilded spruce can anybody tell me what an instance is and what it does

for example you have a class with named Car with 2 variables for color and size. In that class you could have a constructor to define those values. then to make a new car object you would say something like new Car("red", 100); that is an instance of the Car class with the color variable set to red and the size as 100

ivory sleet
#

ye basically an instance is a unit created from a class where the class acts like a blueprint

gilded spruce
#

okay ty I will try to understand that xD

ivory sleet
#

as kidalder said a new Car(...) is an instance of the class/type Car

#

yes types are declared in form of classes in Java

gaunt saffron
gilded spruce
#

can anybody give me a code example from the use of an instance with the car I am too dumb to get it

ivory sleet
#
class Car {
  int size;
  public Car(int theSize) {
    size = theSize;
  }
}

//then
Car instanceOne = new Car(3);
Car instanceTwo = new Car(4);
Car instanceThree = new Car(3);
#

three separate instances of the class Car

#

despite both instanceOne and instanceThree having the same value in terms of size

#

they're separate instances

gilded spruce
#

im so confused hahaha i think I have to start with Hello World again

unreal quartz
#

ah yes

gilded spruce
#

but thank you

unreal quartz
#

i will take a size 1 car please

ivory sleet
#

hello world is unorthodoxly complex

quiet ice
#

You should look at FizzBuzzEnterpriseEdition, much better than hello worlds

quaint mantle
#

print Sus

#

if the number is 69 print funny

quiet ice
#

see, noone uses intelliJ nowadays so you wont get help \j

#

I do be that sometimes though

quaint mantle
#

intellij is just better

#

slower, but better

quiet ice
#

yet noone can help that man?

gilded spruce
quaint mantle
#

ive never had an installation issue with intellij

ivory sleet
#
class MightyAlmost {
  Object o1;  //called a field or instance variable
  static Object o2; //called a static field or static variable

  void method(Object o3 /* called a parameter variable or just a parameter*/) {
    Object o4; //called a local variable or just variable sometimes
  } 
}``` @gilded spruce
gilded spruce
#

whats that

quaint mantle
#

yes

ivory sleet
#

its terminology for different variable types

grim ice
ivory sleet
#

indeed

grim ice
#

tbh i have a new goal now

gaunt saffron
grim ice
#

instead of coding in spigot api

quiet ice
#

no need for the keyword spam at this point though

grim ice
#

ill stop

#

and move on to javadocs

ivory sleet
#

spigot api javadocs 😄

grim ice
#

ill try to learn for like a month or smth idk

grim ice
#

the normal javadocs :D

ivory sleet
#

oh

#

there's a lot of things there

grim ice
#

will it take a year to finish>

#

2?

ivory sleet
#

but learn the classes in java.lang

grim ice
#

o

ivory sleet
#

thats the utterly most important ones

grim ice
#

i mean im mising on like

quiet ice
#

Well, except maybe ClassValue and co

grim ice
#

functional interfaces

ivory sleet
#

oh

grim ice
#

which i kinda understand

#

and uhh

#

principles sort of

ivory sleet
#

yeah

#

principles and design patterns are arguably senior level

grim ice
#

inheritance i kinda understand it but i still need more foundation

ivory sleet
#

ye

grim ice
#

idk whats more

#

oh yeah oop

#

i gotta get better at oop too

ivory sleet
#

but from my pov u've evolved quite the knowledge just lookin back like 2 months

#

or 1

grim ice
#

o poggers

#

i still suc doe lUl

ivory sleet
#

room for improvement 😄

grim ice
#

true

quaint mantle
#
// Required type declaration (class, enum, record, interface, abstract class)
// The class can be public, package private, or final
public final class Class {
    //   ^ this means the class cannot be extended
    // If the "field" is public, you can do instance.field
    // with no modifiers, (public or private), the field is public to other classes in the package
    private int i = 0;

    // i is a parameter: new Class(2)
    public Class(int i) {
        // since the two variables have the same name, you must use 'this' to assign it
        this.i = i;
    }

    // instance only method
    public void setI(int i) {
        this.i = i;
    }

    // instance-only "Getter" method
    public int getI() {
        return i;
    }
}

@gilded spruce

ivory sleet
#

Pin worthy almost

quaint mantle
#

lol

grim ice
#

why are java docs example so simple but when i see someone's example it gets so confusing

#

(i dont mean the one imaginedev sent btw)

quaint mantle
#

i mean

ivory sleet
#

ikr

quaint mantle
#

could ask md5 to pin it

lost matrix
grim ice
#

LOL

quaint mantle
#

lombokgigachad2

grim ice
#

oh god

paper viper
#

Lombok isn’t friendly for beginners tho

#

Makes em confused

#

Where the hell methods

grim ice
#

yeah im not gonn a learn that soon tbh

paper viper
#

Lol

lost matrix
#

Yes ofc. Just wanted to mock conclure#

quaint mantle
#

^ pls dont use lombok in abstract classes!!!!!!

grim ice
ivory sleet
lavish hemlock
#

I like Lombok :)

grim ice
#

when should i come back to spigot api?

#

a month or

ivory sleet
#

you could do it in parallel

lost matrix
quaint mantle
#

Lombok users: gigachad2 gigachad2 gigachad2 gigachad2 gigachad2 gigachad2
Kotlin users: gigachad2 gigachad2 gigachad2 wojaktired
Default java users: 🖐️ 🔨

ivory sleet
#

worst thing with lombok is yet this annotation on annotation thing

#

a complete disaster

grim ice
#

but i just feel pathetic when i talk in this channel tbh

quiet ice
paper viper
#

Annotation abuse is honestly horrible

grim ice
#

lol

paper viper
#

It’s so unreadable

#

Lol

quaint mantle
#

@jade perch

paper viper
#

L

grim ice
paper viper
#

And also I already seen the text file

#

But yeah no idc that’s not going to persuade me lol

ivory sleet
#

if anything lombok dissuades anyone who might have contributed

calm whale
#

Just to remind, I'm trying to prerender a map

grim ice
#

whats ternary?

lost matrix
# paper viper It’s so unreadable

Never written enterprise code i see. Get into some container like Spring or Quarkus where 90% of the code is just generate at compile time with lazy loading proxy classes and all that nonsense and where you have honestly no idea where half of your instance get injected from.

grim ice
#

its an if statement in a return thingy or what

quiet ice
grim ice
#

yeah but can u explain it

quiet ice
#

basically an inlined if statement

grim ice
#

oh ok

#

it looks cleaner than my if() return true; :(

paper viper
ivory sleet
#
if (x) {
  return y;
}
return z;

return x ? y : z;
grim ice
#

thxxx conclure

#

conclure best

narrow furnace
#

@grim ice how long have you been a beginner

#

at java

grim ice
#

im still learning doe

narrow furnace
#

i mean usually thats the first thing and then you become intermediatw

quiet ice
quaint mantle
narrow furnace
#

but you are just eternally a beginner

grim ice
#

fam

#

no need to mock u know

narrow furnace
#

are you learning entirely through discord

grim ice
#

no

#

i read websites too

#

but thats it

quaint mantle
lost matrix
#

I mean its great because this is already a fully working endpoint:

@Path("/hello")
public class GreetingResource {

    @Inject
    GreetingService service;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/greeting/{name}")
    public String greeting(@PathParam String name) {
        return service.greeting(name);
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "hello";
    }
}
#

But confusing af

ivory sleet
lost matrix
#

Java Enterprise is ew

narrow furnace
#

if you just took a beginner course

paper viper
#

Yeah

narrow furnace
#

.. then you wouldnt be a beginner anymore

grim ice
narrow furnace
#

and it would be a lot faster than asking in here for everyrhing

grim ice
#

what course

#

i dont pay btw

ivory sleet
#

like every intermediate course guarantees to de-beginnerify you

narrow furnace
#

i could send the first one i did if u want

lost matrix
# grim ice what course

If you are a student you can get this git something something student package with a ton of courses.

grim ice
#

sure

grim ice
#

idk im too lazy to give them the proof

lost matrix
#

If you have an .edu email you will automatically get accepted

grim ice
#

no, my school is too bad for this shit

#

my school is the type of place

#

that people die in

#

some guy actually got murdered here

lost matrix
#

wtf

ivory sleet
#

sounds engaging

lost matrix
#

Are you in america?

grim ice
#

they got struck by a brick

narrow furnace
#
grim ice
#

into their face

narrow furnace
#

this course is elite

grim ice
#

i tried that

ivory sleet
#

wth lol

narrow furnace
#

its not just in finnish btw

ivory sleet
#

nice embed desc

narrow furnace
#

bro its the best course ive ever taken i stg

grim ice
#

they have so many useless examples

#

they take too long on REALLY beginner stuff so they waste ur time

narrow furnace
#

ik what u mean put thats like a lot of courses

quaint mantle
#

took me 2 months to understand classes

grim ice
quaint mantle
#

functions ftw

narrow furnace
#

you think they are below you until youve done the first one or two parts

#

then it gets to harder stuff

#

and harder stuff becomes easy

grim ice
#

o

#

ok il take ur advice

#

how much did it take you

#

to finish it

#

ppl told me its like 144 hours

#

if it is, im ready to learn all day if its gonna help me

ivory sleet
#

why 144

paper viper
#

12^2

#

Obviously

narrow furnace
#

in total it was like a month and a half or something

#

first 3 parts took 3 days tho

#

so it gets harder lol

grim ice
#

o

#

i skipped part 1.5 i think

#

when i was reading it

#

it was so boring and i wanst learning anything

narrow furnace
#

yeah that can be frustrating

grim ice
#

but r u sure javadocs wont help more than it

ivory sleet
#

I strongly advocate to learn by doing

#

sure u can read on the internet

#

but then take that into practice also 😄

grim ice
narrow furnace
#

it has a lot of exercises

grim ice
#

ew im not installing their ide or whatever

narrow furnace
#

well yes

#

learn by doing

ivory sleet
#

o right I tried something once and it had exercises but those were pretty meaningless, maybe yours is better

narrow furnace
grim ice
#

ok

#

ill try to do this website 7 hours a day first

#

if its too short ill go for 12

narrow furnace
#

theres a bit of reading explaining something, then one or two exercises to practice and understand it

grim ice
#

it would prob be better than the time im wasting here asking for basic stuff

lost matrix
grim ice
narrow furnace
grim ice
#

i bet not, i grinded games for 16 hours a day before

#

i also code 14h/ day

#

but i always suck

narrow furnace
#

bro

#

sleep

grim ice
#

no

#

sleep is for the weak

narrow furnace
#

🙁

grim ice
#

when im good at java ill become weak sure :D

paper viper
#

I only code 3 hours a day

#

Play video games an hour

narrow furnace
#

lol

paper viper
#

That’s it

grim ice
paper viper
#

Rest of day I play clarinet, play tennis

grim ice
#

i suck

paper viper
#

Do other stuff

#

Lmao

hexed hatch
#

Does the server currently expose Xbox gamertags for migrated players?

grim ice
#

i didnt move from my home since 3 months

#

i just eat code and play

#

im useless to society lol

#

@narrow furnace

#

wait wdym

#

there are only 2 parts in that website lol

narrow furnace
#

2 parts beginner and advanced

paper viper
#

I play in BYSO 😂

narrow furnace
#

each split into 7 parts

grim ice
#

i finished the beginner one tho

narrow furnace
#

so 14 total

grim ice
#

how do i stilll suck

#

:<

narrow furnace
#

what all 7?

grim ice
#

im a failure

grim ice
narrow furnace
#

wow

#

nice

paper viper
#

Nah you aren’t

narrow furnace
#

that was like 5 minutes lmao

grim ice
paper viper
#

The more you are experienced at code the more efficient you will write code

grim ice
#

i knew the website

grim ice
#

i got recommended that website when i was called a clown for coding plugins without knowing basic java

#

pulsebeat can vouch

ivory sleet
grim ice
#

i mean i still suck

paper viper
#

Lol

narrow furnace
#

stop saying u suck then

narrow furnace
#

"the moment you doubt whether you can fly, you cease forever to be able to do it"

#

wisdom right there

grim ice
#

nah

#

ill get clowned on if i say im good :D

paper viper
#

Btw you should always have an open mind if you are a beginner

#

Don’t argue with us like last time like that cause we are trying to help you

#

Lol

grim ice
#

i w a s n t

#

e

#

wait what the fuck

#

this mooc thingy is fucked up

#

why do they teach about npe and null only at the end of Java Programming I

#

wtf

#

i mean its free so

narrow furnace
#

wait so have u done all of java programming 1?

#

cos thats what i meant by the first 7 parts

grim ice
narrow furnace
#

damn nice

grim ice
#

i mean part 7 i dont understand a few stuff in it

#

but i understand stuff in 8 and 9

#

which kinda triggers me lmfao

#

theyre talking about hashmaps

#

at like

#

part 9 or 8

narrow furnace
#

lmao

#

well it is a beginner course so

grim ice
#

i prob will finsih it in a week if i wanna completely understand it

#

bro

#

im fucking done

#

@narrow furnace they tell u about packages and what "import" means at part 11

#

what the actual fuck bro

#

this should be in part 1?

opal juniper
#

import after hash maps

#

we love to see it

grim ice
lavish hemlock