#help-development
1 messages · Page 1664 of 1
cool
But I should have only one, I clear the default renderer to add mine with the red X cursor
This:
@EventHandler
public void onInteract(final EntityDamageEvent event) {
if (!(event.getEntity() instanceof final Player player)) {
return;
}
player.sendMessage("Yay");
}
let's watch how every other discord will say the same, but seeya 👍
bruh pattern variables are MWAH
“”” Strings “”” are also neat
okay i am not a fan of this
at least not yet
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
The instanceof variable creation is very nice
that final does look..... weird
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");
}
how in the world do you create a variable with a instanceof operator
Java 16 feature lol
Technically the final isn’t necessary
isnt that what he wants
yeah
😦
no isnt instanceof just comparing two objects and checks if both are instances of the same class?
@lost matrix why do you add final?
to let the compiler know it will not change anymore
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");
}
}
I liek this
My IDE does. I like my variables to be qualified in anonymous methods/classes like lambdas and thread safe by default.
yeah i know but its not necessary right
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
o
at least against the java language specifications
but if you're already using Java 16 you could also just use var to skip writing types completely lol
making my own style is really bad for now i guess, i found out i competely suck at principles
I would disagree on that. Wait let me search the article that explains why you cant
use enough final in java
var is a forbidden word for me
var is bae
im only using java 16 because I dont want to use legacy mode
Same. Go do JS if you want ambiguous variables.
it works and it's clean. why no likey?
https://javamex.com/tutorials/synchronization_final.shtml
"When should I use final?" -> "whenever you possibly can"
i am stuck on j8 due to my work so i cant really get into j16. maybe it will change sometime but not for now
It’s only bad if you purposely make things final that shouldn’t be final and then create ugly workarounds
unnecessary final usage is so ugly imo
You’d hate netbeans
How to check if the mobs is undead or not?
You’d probably need a custom method for that
I feel that. Had to fight a bit for java 11. But as long as its inside a container and the micro service delivers what its
specified to do i can use any LTS version.
I don’t know if the API exposed anything
if (entity instanceof Zombie) and then check for every other undead mob?
yea
You could make a set of entity types and then use contains()
In the sense that the SMITE enchantment would do extra damage to them?
this doesnt mean that you have to declare every var. as final. overdoing it is just "wrong" and ugly. instead you could just declare your method as final instead of the local vars
there's probably a tag for that
i getting this error on run my maven project why ? im using jdk 1.8
Don’t know if Mojang ever moved that to a tag
[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
your project sdk is probably too low
No I wanted to make if undead attack player the damage is reduced to 75%
set it to 8 or higher
Under certain cicumstance
then build again
But i prevent stuff like this by default:
You are using Java 8+ features with a compile target of java 5
Look at EntityDamageEvent (i think that's the name), check if its a player being damaged and then check if its a zombie, skeleton or whatever attacking. then override the damage. ez
@lost matrix btw how do i make intellIj do that too
yeah but does it even matter?
i think it doesnt do that for me
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
the sdk in your project structure
It wont compile otherwise
@minor garnet
Has to be final. Anyways.
not what i meant. if you get the error in your ide or not, does that even matter?
And what's wrong with that?
controlled final looks so much better than just declaring everything as final
Yes it matters. The error shows that this code will not compile because the used variable is not effectively final.
oh
so you make it final because your ide just said to do
would agree otherwise if you would code in notepad
but you dont
javac will tell you the same thing (in the lambda case)
No i make everything final so all my variables are automatically thread safe on default.
The test pop up in console but when I change the print(Test) to after isAssignableFrom it didn't pop up in console
I would just use a list of entity types rather than classes
It also shows a clear intention for the variables not being subject to re-declaration.
understandable on instance or class variables, but not at local variables. just declare the method or parameter as final so nobody can override it.
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.
thats a point but redundant for cases where this will never be required
So that means I had to put in every mob into the list right?
If the method is a bit longer and somewhere down the line the var is used in a lambda or another thread,
then someone going into that code has no idea what variables are safe to re-declare. He has to go through
the whole code and look for any usages before changing anything.
Every entity type that you want to consider undead
You can do it all in one line with Arrays.asList or similar
Alright thx
But i see your point. Im not saying its a convention. Just my preference.
^ agreed
instanceof Zombie and Skeleton should cover most of the alternatives
i think technically spider is undead?
Whats he trying to do?
EntityType#isAlive is also a thing
Zombie, skeleton, zombie piglin, wither
Did he follow up on my question what qualifies as "undead"
I would say everything affected by the SMITE enchantment.
honestly isAlive should cover all of it
Ah yeah isAlive looks good
I was wondering if spigot exposed that somewhere
Although that may be for LivingEntity not undead
what java tutorial do you guys think is good for functional interfaces and java principles? I'm missing on those
#isAlive doesnt even have javadocs
I was about to ask that
Ill go into NMS and look how the smite enchantment determines undead...
Because not all types are alive?
I assume there is a Boolean somewhere in NMS that spigot should expose
Yep it is
The smite enchant and instant health/damage effects must use something
arent nearly all Monster undead
No
No
Most are not
is a Creeper udnead?
Silverfish, spiders, creepers, endermen, ghast, blaze, are all not undead
Zombie variant, Skeleton variant, wither and zoglin only
there are 49 undead mobs
Those are counting from other game
Honestly... this is a bit undynamic but you could just write an EnumSet and add your EntityTypes that should be affected in there.
Like mc dungeons
there is nothing you can identify if its undead or not actually
at least not in the api
Isn't that same as writing an arraylist of entityType and check if the entityType is in the list or not?
This is how the smite enchantment does it.
entityliving.getMonsterType() == EnumMonsterType.b;
Very insightful
lmao
Monster type should be exposed in the API then
I assume arthropod is also a part of that
I have no idea whats part of that because i dont have the moj mappings applied atm
do you guys recommend "Clean Code"?
Well apply the dang mappings then :p
the book?
yes
which one
No. Make your code hacky and unreadable. This way they cant fire you because only you understand your code.
Exactly
by robert martin
no its a book lol
Job security through obscurity
yes
Definetively. But there is also a talk on yt where he goes through his whole book. Recommendable.
Watch the talk on yt. It covers almost everything in his book and is quite watchable.
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?
its pretty easy written
have it myself
informative
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
yeah he declares it as his own recommendations and cover every possbile unclean code part
french mistake^^ thanks
is that a default powerpoint background
but his idiom is like "you have to do this and everything except of me is doing it wrong"
yes why bother the content is more important isn't it? (it google doc BTW)
why bother having it in the first place
hey... I'm still stuck xD, why is the "dataSection.getKeys(false)" empty
well what does the config look like?
You also go watch the talk. He has great anecdotes and starts every chapter with an interesting science fact.
and how do you know it's empty?
Just check #isSet
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/configuration/ConfigurationSection.html#isSet(java.lang.String)
declaration: package: org.bukkit.configuration, interface: ConfigurationSection
dont use configs on runtime
smile wouldve told you that lol
yall really got some issues with configs
He doesnt. He loads it in his onEnable once. (unlike you...)
o
provide more code
I just printed the keySet of the map
can we see the code and the resulting print message?
look into plugin/YourPlugin/config.yml instead of the one in your IDE.
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?
it says items: {} I think this explains alot...
Thats what i suspected earlier.
why isn't my config.yml from the IDE saving?
Show your onEnable. the saveDefaultConfig() method fails silently if there is already a config present so that user configs dont get overwritten.
Ok
- Stop the server
- Remove the config.yml
- Start the server
If you just delete then restart, the onDisable will safe the empty map into your file
why are you reloading the config after just saving it
Does saving from jar -> disk also load the config?
Pog
it should
tytytytytytytytytyy
idk honsetly. I just use my custom config system.
gotta fix plugin stuff but thats ez. The part of loading the map works
tyty
not everything in coding is coding
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
I'm still stuck on my try to prerender a map, if someone can help me it would be awesome !
Here is the last code and the last result: https://paste.md-5.net/utajiwenic.java
coding for me is 30 minutes of making sure my packages and maven is set up correctly
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?
Coding for me is starting to write 2 lines of code and then getting side tracked by this channel
That render looks to me like the wrong width
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!"
Coding for me is setting out to make a prototype, and getting so bogged down on architecture that I don't code any features for 2 days
how that ?
I paste nothing
isnt coding like having a brilliant idea in midnight, getting up, setting everything up and then being lazy?
ok but what do you mean ?
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
Yes 100%. I always have those 1AM great ideas where i start a clean new project just to abandon it shortly after.
?paste
https://paste.md-5.net/meqexeboke.java is there spaghetti here
I really suck when it's about maths so can you explain me what operation I'm supposed to do here setPositionRaw(x, 1., z); ?
ok, each section of your map is 32?
or 64?
well you are setting chunk tickets on an area of chunks 64 x 64
Is it possible to do x marks the spot on 1.8?
^ using inbuilt spigot methods
aka no packets
i want to access something from an abstract class but the field is protected, what do I do
a getter
^

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
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.
i was using same package and it looks ugly as fuck
so i changed it
isnt it same as static abuse?
no
Thats fine, if yoru listener is ONLY affecting the command
not a listener class but a listener in a command class
i dont need the setters tho right
Yup, but if I was to do that then I would make a sub package for that command with the command + listener
up to you tho
Its time to redesign yoru whole layout.
i prefer a diff package for listeners
^ thats what I do
your leaders Map should now be in its own singleton class with util methods/getter/setters
wdym?
o
never give direct access to the map. Keep full control of add/remove/search/clear etc via getter/setter
o
btw
how to make a method accept any type of collection
like a list or an arraylist or a hashmap
I showed you a method like that
Collection<Object>?
public <T extends Collection<ItemStack>> void doStuff(T collection)
or whatever
public <T extends Collection<Object>> void doStuff(T collection)
?
don;t use Object if you know what the contents will be
Someone trying to learn, and someone helping
T means, read up on java generics
theyre not explaining whats t or e or whatever
NVM
i foudn a website
t means type right
i knew k and v
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
o
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?
/timings
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
google java random
i have
and what did you come up with?
new Random() shit
good shit
how do i return based on an if? isnt there smth liek return ? smth
hey, how can i count how many players have a certain potion effects ?
that returns an int
private int potionSearchIdk(){
int i = 0;
for(Player player : Bukkit.getOnlinePlayers){
if(player.hasPotionEffect(effect)
i++
}
return i;
}
thanks!
:D
@eternal oxide idk it seems useless to make those util methods
as each of my classes
have their own checks
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
if thats what you need, yes
aaa
is that really necessary, i cant see any improvement if i do that
its the same thing
you should only be needing isLeader, getLeader, isMember, addLeader, addMember, getTeamIndex, removeMember, removeLeader, clear
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPotionEffect(Effect)).collect
^
I MEAN
aaaaaaaaaaaa
why is life this painful
btw
dis no work
public <T extends Collection<Object>> void clear(T collection){
no work?
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>
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
it would be easier if you gave a full error
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>
and the code?
he's passing a map into his clear method that requires a collection
(1) your method signature above has no purpose being generic whatsoever
public <T extends Collection<Object>> void clear(T collection){
collection.clear();
}
clear(leaders);
other way around I believe
(2) tf are you writing a method to just call .clear()?
yeah, its a map nto a collection
so you need to find that collection in values to remove it
o
um, why are you calling clear on teh collection you just passed?
to cleaar it
Yeah but you can just not write the method to begin with and just call collection.clear()
Like... 
clear shoudl be a no args method to clear the map
Why are you writing a method for that?
someone told me i shouldnt give direct access to the map so i did it
i prob misunderstood him though
if you want to remove a specific team you create a method like removeTeam or removeLeader
I mean... yeah that's definitely not what they meant lol
then ill just use the built in method
private Map
public Map getMap() { return map; }
tbh why even make the methods
u prob dont get him too
yeah no, don;t return teh map
i dont think i should make those methods tbh
if i should i would prob just make isMember and isLeader
yes
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.
yes
DURABILITY should do the trick in 1.12 and below
or some other plugin tries to access your map via the async chat handler. You can easily make your code threadsafe.
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
Since I don't need the whole lib I included what I need and this is the modifications I did on ItemTrait (not tested yet):
I'm sorry but I will let you do so if and whenever you want. I'm working on something right now ^^
Okay
VersionResolver.getNms().getVersion() <= 1.12 float condition with doubles can be dangerous.
That's gonna be fine as long as you don't do ==
my bad. Thank you to have spotted that ^^
my getVersion returns an int. modified it on one side but forgot the other ^^
Might be 1.12000000000000024 and fail
True
anyone can help me make dis better
but no toxicity pls
im still learning
Pre-Generatred seeds with pre-generated worlds probably
did you make your repository private?
I don't know if it's possible to delete the main world
You can easily make more though
a collab did it 
how to make a description of the subject with the ability to add lines through the config?
hey, how to prevent a EntityDamageEvent to be reduced by armor or something
You want to prevent armor from reducing the damage?
yeah, sry
I think through if and setcanceled
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?
no im in 1.16
EntityDamageEvent e = new EntityDamageEvent(p, EntityDamageEvent.DamageReason.CUSTOM, 0);
Bukkit.callEvent(e);
p.setHealth(p.getHealth() - 10);
do you mean like this?
No
what do you mean with "in the event before"?
@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
ok, got it, thanks
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
For item stack building you can take a look at https://github.com/Redempt/RedLib/
I already have a config with the name of the item
how can I add a description to an item?
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
how to use it?
How to use what exactly?
how do I get the name and description from the config in the code?
oh
final List<String> lore = plugin.getConfig().getStringList("mySampleItem.lore");
final FileConfiguration configuration = ...;
List<String> lore = configuration.getStringList("item.lore");
String name = configuration.getString("item.name");
Material material = Material.matchMaterial(configuration.getString("item.type"));
can I add more lines of description?
yes
as many as you want
how?
but if you add too much you will have display issues in minecraft
well type them in the config
item:
type: IRON_SWORD
name: "Cool item name"
lore:
- ""
- "This is"
- "an example"
- "with more lines"
- "and even more lines"
as shown here
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);
}
Boolean
?
oh , alright ill try thanks
hm , so what do you think the issue is
well this is not quite enough information. can you show me the init part
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);
}```
huh
works. thank you very much to everyone
why dont you make createItem return an itemstack
and set the variable in the init method
like clicker = createItem(Material.BEACON, "&6&lClicker", true);
static init block
@tall dragon thanks , it works
how to get a random index of a list
list.get(ThreadLocalRandom.current().nextInt(smth and list.size())
yes
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?
You usually just ask your compiler nicely.
How often do you use the material enum?
I don't have problems with Material between versions
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
Material gets the enum from the server version so it shouldn't cause issues
Perhaps, but you need to port your old 1.17 material code down to 1.8
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
I have my own enum but I've used material (when testing) in all versions 1.8-1.17.1 with no issues.
Material.BROWN_WOOL is a candidate that would bork
Well obviously you would need to check xD
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
It becomes easier if you write your stuff with inter-version compat in mind
That is bark
bork bork
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?
huh
what does that even mean
how exactly do you mean?
what is the NMS packet for moving a fake player (both position and look)?
Yes. Check the type of the block.
Are there any spigot limitations to the Java method "Runtime.exec()"?
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
Sounds like you wanna do some shady stuff

Bukkit.getPluginManager().callEvent(new EntityDamageEvent(p, EntityDamageEvent.DamageCause.CUSTOM, 5));
any idea why this doest work?
and pass the arguments into that command

🙂
it does but why
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? 🙂
it doesnt, my healt does not change
ofc not
but it fires the event
use Attributable#getAttributeInstance to change the health
theres no static method
org.bukkit.attribute.Attributable.getAttributeInstance()
Attributable
its an instance method my fellow developer
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.
== not instanceof
ok how to get the attributable instance of the player?
it already is
oh ok. The line after that still gives the same error though
ah, ok
List<String> lore = config.getStringList("messages.gui.onebottle.lore");
lore = lore.replace("&", "\u00a7");
why doesn't it work?
Im dumb sry
player.getAttribute(Attribute)
thats a list
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
.add on a location operates on that object. You already modified the Location, so modifying it again will miss your target block
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
this is without the damage effect. is there a possibility to add it? also tried Player.damage(double) but this can be reduced by armor. :/
how can this be used?
yeah listen to the damge event also
read the link i sent
and neutralize possible resistance
how would that even work lol
ok and what should I use instead?
streams without generics 
🥲
create a Location object to test against, so you don;t modify it multilple times
@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
pog
why 1,1,4? seems a rather specific location
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.
always oriented in one direction?
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.
no not to the player. To the block placed by the player
Wait. let me look at the code again.
I have made it so that it is only executed when a certain block is placed. In this case a red banner
Mind showing the whole method?
of course
how to know that a entityDamageEvent is the on i called?
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
You can create a Set of events and call remove on it. It returns true if the removed element existed in the set.
Oh i see what you are trying to do...
Hm. There are two approaches. Ill give you one example.
@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
Main.getPlugin().getServer().getScheduler().runTaskLater(Main.getPlugin(), () -> { to Bukkit.getScheduler()
i have forgotten the {} after if(location.add(1,4,4).getBlock().getType() == Material.BRICK_STAIRS)
🥲
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));
}
oh 😅 thank you... This looks much simpler
You should try to avoid naming your main class as Main too
and get into the practice of using dependency injection
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
but this doesnt do the damage effect, does it?
I dont think does the damage effect.
2 Options: either damage the player with a value of 0. Or use the second approach im about to write ^^
Ok I will have a look at it. However, I still have a question about it: What are the differences there?
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));
}
so you know what a constructor is right?
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
I am not sure... I had studied OOP in Java but have never used it.
you should review some java skills then
but its what is called first when an object is being instantiated
np
that works! thank you so much <3
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?
Did you set the changed BlockData back on the block?
Sure...
@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);
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.
yeah it works 🥳 thank you so much for your help 🙏
are you sure the if statements are working?
can anybody tell me what an instance is and what it does
sysout inside the if statements and see if they are running
well 1st of all you should learn java because that's simple java logic but an instance is a new object of a class
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
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
ye basically an instance is a unit created from a class where the class acts like a blueprint
okay ty I will try to understand that xD
as kidalder said a new Car(...) is an instance of the class/type Car
yes types are declared in form of classes in Java
well screw the settings dir, it jumping to next line when i comment makes it super annoying pretty much unusable
can anybody give me a code example from the use of an instance with the car I am too dumb to get it
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
im so confused hahaha i think I have to start with Hello World again
ah yes
but thank you
i will take a size 1 car please
hello world is unorthodoxly complex
You should look at FizzBuzzEnterpriseEdition, much better than hello worlds
please? at least some tips
see, noone uses intelliJ nowadays so you wont get help \j
I do be that sometimes though
yet noone can help that man?
okay I give this one more try and ask a few questions. is "size"a variable in this case? Because why can you make an int variable that has the value "theSize"? xD bro im soooo confused
ive never had an installation issue with intellij
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
whats that
yes
its terminology for different variable types
u can make size private and final right
indeed
tbh i have a new goal now
what do people use... peipke screamed at me for NOT using it
instead of coding in spigot api
no need for the keyword spam at this point though
spigot api javadocs 😄
ill try to learn for like a month or smth idk
but learn the classes in java.lang
o
thats the utterly most important ones
i mean im mising on like
Well, except maybe ClassValue and co
functional interfaces
oh
inheritance i kinda understand it but i still need more foundation
ye
but from my pov u've evolved quite the knowledge just lookin back like 2 months
or 1
room for improvement 😄
true
// 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
Pin worthy almost
lol
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)
i mean
ikr
could ask md5 to pin it
Youll hate this:
@Data
@AllArgsConstructor
public final class Class {
private int i = 0;
}
@Data
😶
whats that
lombok
oh god
yeah im not gonn a learn that soon tbh
Lol
Yes ofc. Just wanted to mock conclure#
^ pls dont use lombok in abstract classes!!!!!!
LOL
I swear lombok is a fucking cult
I like Lombok :)
you could do it in parallel
You can learn quite a bit by just writing a bunch of spigot plugins. Ive learned java 2 years ago and only
wrote spigot plugins for the first year.
Lombok users:

Kotlin users:

Default java users: 🖐️ 🔨
worst thing with lombok is yet this annotation on annotation thing
a complete disaster
o
but i just feel pathetic when i talk in this channel tbh
A hammer is all a competent man needs
Annotation abuse is honestly horrible
lol
lmao
L
me who writes 10k letters long staff applications:
no
And also I already seen the text file
But yeah no idc that’s not going to persuade me lol
if anything lombok dissuades anyone who might have contributed
Hey, sorry but I'm back with my map problem, actually it works fine but it loads only around the 0:0, even if I select an another region 🤔
https://paste.md-5.net/icayigenac.java
Just to remind, I'm trying to prerender a map
whats ternary?
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.
its an if statement in a return thingy or what
bool ? a : b
yeah but can u explain it
basically an inlined if statement
Well yes ik how it feels like to use such libraries and be confused cause you have no idea what the hell is happening internally lol
if (x) {
return y;
}
return z;
return x ? y : z;
idk
im still learning doe
i mean usually thats the first thing and then you become intermediatw
It's not always cleaner
return if (x) y else z
but you are just eternally a beginner
are you learning entirely through discord
thou must read the entire html
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


Java Enterprise is ew
if you just took a beginner course
Yeah
.. then you wouldnt be a beginner anymore
idk man
and it would be a lot faster than asking in here for everyrhing
like every intermediate course guarantees to de-beginnerify you
i could send the first one i did if u want
If you are a student you can get this git something something student package with a ton of courses.
sure
uh
idk im too lazy to give them the proof
If you have an .edu email you will automatically get accepted
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
wtf
sounds engaging
Are you in america?
they got struck by a brick
Helsingin yliopiston kaikille avoin ja ilmainen ohjelmoinnin perusteet opettava verkkokurssi. Kurssilla perehdytään nykyaikaisen ohjelmoinnin perusideoihin sekä ohjelmoinnissa käytettävien työvälineiden lisäksi algoritmien laatimiseen. Kurssille osallistuminen ei vaadi ennakkotietoja ohjelmoinnista.
into their face
this course is elite
wth lol
its not just in finnish btw
nice embed desc
bro its the best course ive ever taken i stg
they have so many useless examples
they take too long on REALLY beginner stuff so they waste ur time
ik what u mean put thats like a lot of courses
wtf?
functions ftw
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
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
why 144
in total it was like a month and a half or something
first 3 parts took 3 days tho
so it gets harder lol
o
i skipped part 1.5 i think
when i was reading it
it was so boring and i wanst learning anything
yeah that can be frustrating
but r u sure javadocs wont help more than it
I strongly advocate to learn by doing
sure u can read on the internet
but then take that into practice also 😄
that means ill get bullied more for sucking :D
yes thats what the course has you doing
it has a lot of exercises
do i need to do their exercises
ew im not installing their ide or whatever
o right I tried something once and it had exercises but those were pretty meaningless, maybe yours is better
i switched to intellij half way through so it will ve fine
theres a bit of reading explaining something, then one or two exercises to practice and understand it
it would prob be better than the time im wasting here asking for basic stuff
You will burn out on the first day
really?
you should be able to complete it a lot faster than me if you do that i suppose
i bet not, i grinded games for 16 hours a day before
i also code 14h/ day
but i always suck
🙁
when im good at java ill become weak sure :D
lol
That’s it
HOW R U BETTER THAAN ME AHFUAWEFHAEFHFEAWHAWEFH
Rest of day I play clarinet, play tennis
i suck
Does the server currently expose Xbox gamertags for migrated players?
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
2 parts beginner and advanced
I play in BYSO 😂
each split into 7 parts
i finished the beginner one tho
so 14 total
what all 7?
im a failure
yes
Nah you aren’t
that was like 5 minutes lmao
no
The more you are experienced at code the more efficient you will write code
i knew the website
o
i got recommended that website when i was called a clown for coding plugins without knowing basic java
pulsebeat can vouch
wish thsi was true for me
i mean i still suck
I’m forced to do it cause I’m busy during the school year
Lol
stop saying u suck then
yeee
"the moment you doubt whether you can fly, you cease forever to be able to do it"
wisdom right there
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
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
wait so have u done all of java programming 1?
cos thats what i meant by the first 7 parts
yep and a bit of java programming 2
damn nice
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

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?
lmao
sintax



