#help-development
1 messages Β· Page 1712 of 1
basically before the command was /advancedenchant, iand i added the whole args thing so that i can input values into there
so im guessing that the int or char isnt getting converted from string
just not sure
why doesnt the effect play
like, i changed the effect to another and it worked
but VILLAGER_PLANT_GROW doesnt work
a villager who is planting weed
doesnt exist anymore
declaration: package: org.bukkit, enum: Sound
oh looks like i used playEffect instead of spawnParticle. im dumb :D
player.spawnParticle(Particle.DRAGON_BREATH, player.getLocation(), 1) this straight up aint working. also no errors
Questions
ItemMeta#getLore() can return null if the item doesn't have lore
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<>();
}
lore.add("whatever");
meta.setLore(lore);```
why did it work before tho
There's also a more flexible method for creating roman numerals. https://paste.md-5.net/xusopitogi.java
The item you had before probably had lore
How i get all exp points of a player ? (exp and levels converted as exp)
So I made a plugin with the new mojmapped names for nms and shit
Is it normal that paper fails to load it then?
is there a way to detect another half of a chest next to another and both parts are connected?
well i found a post
checking if the inventory is instanceof DoubleChestInventory or something
and then i need to get the location
DoubleChest has getLeftSide() and getRightSide()
This isn't Paper 
Hello, if I create a spigot plugin for 1.7.10 will it be available for 1.16 ?
I just want to send requests to a minecraft server to be able to perform commands from a website (my plugin will just make the link)
Exactly like that
what event would be used to detect when a player is at a certain location (x,y,z)
PlayerMoveEvent
ok thx
cant seem to get args.length >= 0 to work
it says arrayoutofboundsexception
have even tried catching the error
it still goes through
the Material is showing me the error and the error is "Parameter is not a subclass of org.bukkit.event.Event "
Because it's not an event, but you have the @EventHandler annotation
ooh
my bad
how can i not see that
im blind
there you go, its fixed
thank you for fixing my eyes lol
π
how do i go about getting the coordinates? tried #getBlockAt
public void darlandiaTimeChange(PlayerMoveEvent e) {
if (e.getPlayer().getLocation() == coordinatesOfLocation) {
}
Is there a clean way I can use hex colors in a team prefix using just the API?
Quick q, why can gradle find org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT, but not org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT? Even both files literally exist right next to eachother in the repo?
hmm pretty sure yeah?
it should able to find both, but why would you need 1.17 
Exactly, I don't. I need 1.17.1, but it can't find it despite the file literally being right next to 1.17
Tell me, besides absolutely nowhere, where am I going wrong? https://bpa.st/QLNA
oh
yeah weird
it should work perfectly fine
what does the gradle error say
the stacktrace ofc
https://bpa.st/YBTA It tries to search in the dumbest of places lol
It's weird cos it works fine in VS Code, but it's being odd about it in IntelliJ
Neither the repo or restart sorts it
try deleting the .idea folder
and .gradle folder
then ofc restart and invalidate again
fails, when you say invalidate, is there anything I should be clicking?
File -> Invalidate Caches... -> Restart and Invalidate
or smtng
Use English, thanks
show time?
Any suggestions? The Team#setPrefix() method just accepts a string
same thing again, can't be found lol, tf
Idk what bossbar show time is rly lol
This is just so odd
It's a brand new project too
Oh yeah you can ofc use ChatColor#of(hex) and concat it in the string you'd pass there
https://i.imgur.com/Ae2W09W.png I don't suppose any of these default gradle settings look out of place?
its so weird, try
org.spigotmc:spigot-api:1.17.1-R0.1-20210929.090115-75
also
what Java version do u use
and gradle version
16 judging from the image above π
yeah, same error, could not find
what gradle version are you on
Trying to find it
gradle/gradle-wrapper.properties
ah, 7.1
try
org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT:20210929.090115-75
could not find
no
org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT:20210929.090115-75
try that one
not org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT-20210929.090115-75
fails too
just re-created the project again to make sure it wasn't a 1 off (as it's a fresh install) - exact same issue
oh lord
?
I'm out of my depth here with the mess that is gradle lol
Yeah
this issue of yours is quite a peculiar one I must say
We even tried specifiying snapshot version
Yea, I think it's something outside of the build.gradle file, something system based perhaps
yeah
hmm you could contact the gradle devs about it
Or maybe ask somewhere else where people are more knowledgeable about it lol
anyways best of luck
IntelliJ downloads and manages its own version of gradle right?
Sorta yeah
Fixed it.... apparently I needed to add mavenLocal() - despite the fact that the dependency is remote and not at all locally based and so therefore should have absolutely bugger all to do with anything local whatsoever
Well, it looks like I've actually somehow managed to download the jar file locally, stored in c:\users\user\.m2 (ofc, .m2 is a good name and place to hide this...)
Switching to Maven made all my issues go away, basically. Gradle seems abit crap.
Also ty for your time / help @ivory sleet !
ah
are there any good ways to make custom soundtracks
How find leaks memory?
yes
how to get the time the player spent on his server, what is the event of the Statistics object please?
I find this https://i.imgur.com/QqdAaUM.png
Play time iirc
ItemFrame frame = (ItemFrame) entity;
Just look at the list, should be obvious
PLAY_ONE_MINUTE is play time
if i recall correctly
Oh okok thanks
And I think it's in ticks not minutes, it's named wrong
its PLAY_ONE_MINUTE but it doesn't return a minute iirc, some other timeunit
yes ticks
ticks okok i will try to transform ticks into a second/mns/hours/day
@sullen marlin we need namespace pdc, so if the plugin is removed all pdc is removed from the player
or plugin pdc
is that how it works? or is it just nbt
It's stored per plugin, but it's not removed if the plugin disappears
it does
very intuitive name
whats entity
show where you get it
Hover over entity
i mean the entity variable
What does it say
Anyone know if & and hex are supported in console?
You didn't define entity
Well there is no entity in a PlayerInteractEvent
So youβll need to define it
if (enabled.contains(e.getPlayer()));
what is this
Test what the player is doing
I think it depends how you send messages, ConsoleSender#sendMessage seems to work
useful
consolesender
not sure for hex
try it
It would be general CommandSender with a custom colorize method, or would it be better to just cast to ConsoleSender and use that method instead?
cast where
private final ComandSender sender = Bukkit.getConsoleCommandSender();
// sender has chatcolor support
public void sendMessage(CommandSender sender, String message) {
if(sender instanceof Player player){
player.sendMessage(colorize(getPrefix() + message));
return;
}
sender.sendMessage(message);
}
I had the same thought when I was making my discord integration plugin
dumb af question, but i haven't touched spigot in ages π€£
works on malware detection for spigot
so remove the if and just send the message as colored?
jk
yeah
That's not spigot π
Pretty much
π
java with spigot
but not actually using spigot code lol
For example this works with players and console
https://github.com/Coll1234567/MineTweaks/blob/master/src/main/java/me/jishuna/minetweaks/commands/TempCommand.java
No idea what happens with command blocks
Fuck command blocks
@quaint mantle I do plan on getting back into actual spigot coding though, as one can tell from my basic question π
If it helps I do remember most things lol
Use PlayerInteractEntityEvent
Then you have access to the player and the clicked entity
just never had to worry about something this specific and I don't wanna wait 942089230849230 minutes just for everything to load properly for me to test
The heck you running the game on, a Ti85?
I only use like
I think you've seen my specs lol
1 for my test server and 2 for the client
:3
Also try using UUIDs when handling lists of Players.. As the player Object changes frequently whereas the UUID Doesnβt
The player object changes on reconnect
Are the PlayerQuitEvent and PlayerTeleportEvent events called before or after they play out ingame? I want to know if I'll be able to catch a player's open inventory and call InventoryCloseEvent before it closes. (1.8 doesn't call InventoryCloseEvent very well, so I plan to make a patcher)
Can you cancel the teleport event
`import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockListener implements Listener {
@EventHandler
public void onPlaced(BlockPlaceEvent e) {
if (e.getBlockPlaced().getType() == (Material.TNT_MINECART)) {
e.setCancelled(true);
}
if (e.getBlockPlaced().getType() == (Material.TNT)) {
e.setCancelled(true);
e.getPlayer().getWorld().setPVP(false);
}
}
}` Hi! So I was making a quick plugin to stop tnt from being placed Does anyone know why it wasn't working
But I can still place tnt
Lemme fix that though
Is it registered
Looks alright
Lol that sysout though
Can anyone help me? I'm getting this error in my console https://imgur.com/a/uHsUZe7 and this is the method https://pastebin.com/ppjitDZW
Only thing I am noticing is why do you have a listener in main?
Idk
dont name your class main
I would reccomend always putting listeners in another class
Also this
I don't get it
check out my thread
Wait it's not named?
It's called Main
Just choose a different name
Read my post
Main is the standard
No it is absolutely not
Not for plugin names
Then what should I write
Your plugin name
directly
Main is vague, doesn't say much, and also your plugin isnt a standalone application either
Also a heads up I can delete the plugin while the server's running
Oh I do that sometimes idk why it really matters though
it does indeed matter
Some good names are
WorldGuardPlugin, LuckPermsPlugin or maybe GriefPreventionEntryPoint
I guess that's fair
Do I just write __.java
Yeah lol
I mean without any warning
I mean, you should always shut your server off first, but for windows you cant
but i think for unix you can
well
some
I don't really care if the server gets corrupted
I name my plugins by inputting keywords into google translate with a random language then taking the phonetics for it
When the server is running nothing is using it for some reason so I can delete it
Noice
like Konchina, which was my last commission, or my current Molynsi (iirc)
Why don't I just share the plugin file and people can decompile it?
But the SEO
It seems much easier
i dont understand your logic here
Can't I just share the plugin its self in discord and other people can use java decomplier to look at it?
Ok
Ok
?paste
use a paste for larger code snippets
Ok, I really hate to say this. But you probably gotta learn some java basics and stuff first
at least the basics
like classes and stuff
Ok do you suggest any courses or stuff
PulseBeat_02 Java series on yt!
I gotta do some learning π gotta do smth with enums
Itβs chill, we have sealed now
sealed is so good for libraries
Yea
Wait can you reply I don't know which you mean
Man it gives us so much more power
Do you mean this?
Or this
Its a joke. I made a two video series and discontinued it.
Only cursed thing is the keyword non-sealed
do the command
dont watch it
?java
Ok
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
that exists?
Yeah lol
Time to do some reading
cause protected aint enough
I gotta make some custom "Classes" i.e. like how mmos have "Knights" and whatnot, been sitting here the past 10 minutes thinking about the best way to go about it
Assume class Vehicle is sealed
Then class Car which extends Vehicle must be declared sealed, non-sealed or final iirc
Yea
Luckily I have speechify
Oooo
Why do we need non-sealed though
Can't it just be declared normally, it would imply the same thing
Oh itβs in case you wanna extend a sealed derivative
Like where new derivatives of that derivative may be loaded during runtime
As sealed thing is kinda checked at compile time c
Ok
the only time I've used enums is to store discord webhooks π€ I think
Yeah I use one for namespaced keys
Although it's a bit weird since you need to call setup() on it
wdym setup()
Enum singleton π
Shh
i actually really hate that lol
i prefer using JavaPlugin.getPlugin since you use static with static and it avoids the unnecessary method call
or I just define it directly and just do it inside the constructor
Hmm, fair
AbstractPluginNameSpacedKeyFactoryImpl 
stop
clikck
iirc
π I like the inclusion of the entire class just to ask how to make an item frame invisible /s
declaration: package: org.bukkit.entity, interface: ItemFrame
sure
Where do find the api jar for spigot? I downloaded it before so that I could have nice documentation in my ide, but I can't find it now.
you dont need the jar
just add it using maven/gradle
unless you are using NMS or adding jars manually
en em ess
lol
I am unfortunately using nms. I tried to avoid it but I keep finding just one obscure thing that doesn't work without it
NMS is not documented
yeah I know
and also you can only use JARs for NMS
oops i meant
not only JARs
you can run buildtools
and use that too, and remove the -api part
just set visible back to true
player.getItemOnCursor is null and as said don't use .equals for enums
command /spawn:
trigger:
set {Spawn::%player%} to 5
send "Please don't move"
while {Spawn::%player%} is not 0:
wait a seconds
subtract 1 from {Spawn::%player%}
{Spawn::%player%} is 0
teleport player to {spawn}
on any move:
if {Spawn::%player%} is set:
delete {Spawn::%player%}
send "You moved..."
it says error at "on any move"
you'd likely be better off joining the skript discord https://discord.com/invite/q7UM6vJ
k
No
Why would the player be holding an item on their cursor while right clicking an entity?
abysmal colors too
cursed
At the start you should probably put: if (e.getItemOnCursor() == null) return;
That isn't what they want
- e is the event, and does not have a getItemOnCursor
- getItemOnCursor gets the item the player is holding when in an inventory, not what is in their hand
I think we should get an explanation from them on what exactly they want to happen
Wait, PlayerInteractEntityEvent does not have a getItem or getItemInHand or anything
Gross
well ye because there aren't any interactions where right clicking an entity fwith a specific item does anything in vanilla mc
just getplayer then their inv then item in main hand/off hand
Still annoying that the convivence method does not exist
ItemStack item;
if (event.getHand() == EquipmentSlot.HAND) {
item = event.getPlayer().getEquipment().getItemInMainHand();
} else {
item = event.getPlayer().getEquipment().getItemInOffHand();
}
Look at all those lines, terrible
yeah but it doesn't make sense to add lines to the underlying event code for "convenience" when it isn't applicable for most use cases
imo
Tell that to BlockPlaceEvent#getBlockPlaced
what about it
It only exists for connivence :p
how is that?
Itβs the same as getBlock
Technically itβs for clarity, but close enough
Also there are some vanilla entity interactions based on held item
you can shorten this to
item = event.getHand() == EquipmentSlot.HAND ? event.getPlayer().getEquipment().getItemInMainHand(); : event.getPlayer().getEquipment().getItemInOffHand(); idk I just felt like adding this lol
Not enough streams
@quaint mantle What are you trying to achieve here?
Minecraft version?
Okay well think through it. We need to detect when a player right clicks, which is PlayerInteractEvent. Then we need to see if the interaction is a right click, and if the thing right clicked is an itemframe. Then, get the itemframe, and then invert its invisibility.
actually @ancient plank or @young knoll do itemframes count as blocks? Because PlayerInteractEvent only supports block and air clicks :/
Maybe check if you interact with a living entity
yea thats what I thought
Yes
they are entities
Quick question
So I found this on spigot
private static final Pattern HEX_PATTERN = Pattern.compile("&(#\\w{6})");
public static String colorize(String message) {
Matcher matcher = HEX_PATTERN.matcher(ChatColor.translateAlternateColorCodes('&', message));
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group(1)).toString());
}
return matcher.appendTail(buffer).toString();
}```
PlayerInteractAtEntityEvent should be used, over playerinteractentityevent
I want to know what would be a valid way to call this method and get a Hex colored message?
Note that the client may sometimes spuriously send this packet in addition to PlayerInteractEntityEvent. Users are advised to listen to this (parent) class unless specifically required.
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerInteractAtEntityEvent.html
@EventHandler
public void onItemFrameClick(EntityInteractEvent e) {
if (e.getEntity().getType() == EntityType.ITEM_FRAME) {
ItemFrame frame = (ItemFrame) e.getEntity();
frame.setVisible(!frame.isVisible());
}
}
``` This should work if e.getEntity returns the entity interacted
unless I can't read
See thatβs always confused me
Because PlayerInteractEntity is the parent class of PlayerInteractAtEntity
:/
But it says (this), so I have no idea
You should really figure this out on your own though. I honestly shouldn'tve spoonfed you
idk anymore
Learning logic is more important than knowledge of Java or the Spigot API imo.
public String translateHexColorCodes(String startTag, String endTag, String message)
{
final Pattern hexPattern = Pattern.compile(startTag + "([A-Fa-f0-9]{6})" + endTag);
Matcher matcher = hexPattern.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
while (matcher.find())
{
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
);
}
return matcher.appendTail(buffer).toString();
}```
What would be a proper way to call this method?
googling is a skill π
Spigot hasnβt changed much since 1.11?
Donβt forget to check before you cast
Yes yes ofc
Use that sick new inline casting
I just figured that was implied
Can I get some help? π¦
Pattern variables 
Is that the name? I never remember official terms
im not up to date with new java versions, may I please have an example usecase of inline casting
ππ im a visual learner π₯Ί
Yeah I think it is
(sender instanceof Player player)
^
Very useful
Indeed
what version is that
15 I think?
No idea but 17 has it and that's all that matters 
ic ic
That's what I meant whoops
I only found out about it because IntelliJ called me a dumbass for not using it
lol
Itβs probably my favourite new feature
And like
1 of the 3 new features from java 9+ Iβve used so far
What are the other 2
Using method arguments in a try with resources
might upgrade the java version my current project uses, so I can use method arguments in try-with-resources
What do you mean method arguments?
would make my SQL code cleaner
?paste
And whatever this is called https://paste.md-5.net/lisojicevu.cpp
i just call them lambda switches lol
Yeah
You can use arguments passed to a method in the try with resources block
Something like
This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment
I can use it in 11
Do you mean a regular try-with-resources statement?
No
?paste
Hey quick question. So I want to use a TextComponent to send a message which is clickable.
But I could only find ways to execute like specific server commands but nothing you can code yourself like this:
TextComponent recieverMessage = new TextComponent("Test message");
recieverMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, ""));
But I want something like this:
recieverMessage.setClickEvent(new ClickEvent(ACTIONX, () -> System.out.println("Something")));
try (final Connection connection = getConnection) {
} catch (final Exception exception) {
}
That ^?
Thatβs just the normal one
look at my paste
So it's basically just, make these things, then do this?
Let me write an example
this is an example @hasty prawn @vital yacht @young knoll
Yeah that's what I'm looking at
What's the difference?
wait nvm cant do it in 11
is there any way to use java generics with static methods?
Isn't that the normal one?
In this example, the try-with-resources statement contains two declarations that are separated by a semicolon: ZipFile and BufferedWriter. When the block of code that directly follows it terminates, either normally or because of an exception, the close methods of the BufferedWriter and ZipFile objects are automatically called in this order.
No because the object isnβt created inside the try statement
That's what a try-with-resources is though right?
Also isn't it Autocloseable, or am I wrong?
Can someone help me with this?
You can't have a constructor with a class that extends JavaPlugin
grrr I wish oracle docs had a dark mode
Because generics are only applicable to the instance of the class
so it cant be static
but i need it to be static haha
Why would you need to do that?
Oh I see
No I am
Oyh
so basically
use generic
for the instance of the class
for example
public class Plugin extends CorePlugin<Plugin>
would automatically generate and instance grabber
for
the class Plugin
but it'd have to be static
Use dependency injection
You could always use a framework to inject the plugin instance
That would get rid of this whole issue
I have no clue how to do that though
If you donβt feel like writing the few extra lines to use di
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Heh
I think donators get it
There is one for donors iirc
That's cruel but ig
There are probably browser plugins that let you define your own css for it
Can someone just explain di to me
I'm not staring at this wiki with my eyes burning for 10 mins
You pass around an instance of your plugin instead of using a static instance
For example, say you had a listener class
class Something implements Listener
// add field for Plugin, pass plugin instance in class constructor
Or use a DI framework
Essentially you pass your plugin instance to the constructor of a class
So that class can then access it
Note to self, add shift-right click to toggle item frame visibility to my plugin :p
Okay 1 I already do that a bunch
2
I'm too lazy to make a constructor for every class, then pass it from my main class
Because
I jsut wanna use Plugin.getPrefix(), etc. in peace
:/
You can auto generate a constructor if you just define the final field
This is paining me
yea
but
thats one extra line
I can't afford
Β―_(γ)_/Β―
And
I still have to
That's static abuse
Use a DI framework like Guice if you don't want to pass around an instance
Thats literally the only time I use static
Still static abuse
It's not abuse if you do it once: /
Yes it is
Who wants to type Plugin.getPlugin().getPrefix()?
Plugin.getPlugin is the static abuse
Your brain is static
My brain is dynamic
Prove it
No
Actually i'd rather not see an autopsy of your brain
alright thank you.
its 10 pm
why would I wanna do that?
To learn and code better?
I'm not refusing lol
I still might do DI
I'm just arguing why I think I shouldn't do it
yea do you wanna do that for every class you use your main class with?
I'm sure you know better
I do that
To be fair with spigot itβs more about building a good habit
Kay maybe i'm just lazy but I don't like repeating myself a lot
The plugin class is a singleton anyway, so a static getter isnβt the worst
Why are you casting a string to Object lol
Lol? did I jsut see that
Hes casting a FileConfiguration to an object?
okay just do
Yes
Lo
getString isn't a method from the Object class anyways
Also why this.getConfig()? Just use getConfig()
then... why are you casting a config to an object?
I know you've probably heard this a lot, but maybe just take a one hour course on basic java?
so you don't forget
and OOP
That applies to you too Exortions
Hello, does anyone know or know of a plugin that allows chests to automatically sort items? preferably compatible from 1.12 onwards or 1.12
Then why use static to get your plugin instance?
I know a ton of people that do it?
Why DI every class you have?
also doesn't mean its the worst way of doing it
there isn't anything fundimentally wrong with it, it just might not be the most efficient
Can you back that up?
And what do you mean by efficient
I mean
Okay, back it up
are you saying DI is more efficient?
The plugin works
that's literally all I need to say
Lol
Are we talking about Dependency Injection vs Singleton :o
Kind of yeah
okay show me
Okay and your point is>
Always listen to Conclure
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
sendMessage(" ");
for (int i = 0; i < 50; i++) {
sendMessage(" ");
}
this actually
proves that DI is worse
Because the multiple sendMessages is basically you constructing every class u wanna DI with
the for loop is basically the singleton
No?
:/
No one is right all the time, he sure is right a lot but I still don't see the value of DI over Singleton π€·ββοΈ
Yeah
Nah Conclure is right 100% of the time
I AGREE
There isn't any point really not to use a singleton
DI takes up an extra 2+ lines per class
I mean, he probably is right about this. But until I see some pretty clear reasoning behind using DI over it, there's no reason to make the hard switch.
singleton is three lines forever
No?
yep
Not forever, you have to access it still.
public static Plugin getPlugin() {
return instance;
}
Well and define instance 
i was just gonna add that
5 lines then
Then you end up doing Plugin#getSomeObject#getSomethingElse#doSomething Everywhere
Not true
u need an object
Object o = Plugin#getObject()
o.
o#whatever
o#toString
You end up doing that anyways with the Plugin class that you're passing around
No
You actually do
You can instantiate everything in the constructor
I agree that DI is fantastic in a lot of cases, just not for the plugin class case.
How is passing the Plugin instance any different from a static Getter? You're getting the same object. You still have to call Plugin#getSomeObject#getSomethingElse#doSomething regardless of the method
Exactly
and if ur not using getter and using di
its
plugin#getSomeObject#getSomethingElse#doSomething as well
just lowercase plugin this time :)
yeah but
then
if u use static
its getPlugin#whatEver
?
so same thing
Yeah kinda
Sorry should have been Plugin.getInstance.getSomeObject.getSomethingElse.doSomething
Also im pretty sure DI will slow load time of plugin by a few ms
What
Can you test that
Maybe later
Please show me the results
Sure, but that's going to be negligible. Also, with DI you run into this issue
For example, if you're instantiating a class within another class, that's instantiated within another class, etc etc, you'd have to pass y our plugin instance across every single one of the classes, JUST so you can use it in the one you're trying to get to, regardless of whether the first 2 classes actually use the plugin instance or not. It seems like that would be far more complicated than just "oh, I need my plugin instance for this class. Main.getInstance() done."
Alright at this point ima just stop arguing. Let's all mutually agree that they both work, and everyone has preferences
This is literally
my point
i've been arguing the entire time
And it's just uglier IMO to be constantly forced to pass around an object, even if it's completely unnecessary to what you're doing.
You're probably violating single responsibility principle if you're doing that
idk, DI just seems like it's far more a pain to maintain. Β―_(γ)_/Β―
DI is a better practice
But in terms of the spigot plugin instance, it doesnβt really matter
Well I mean I feel like a certain advantage to passing an instance around is instance control. Like youβre basically saying βI only want these classes to have accessβ so if itβs an api the user of it canβt just do βmain.getinstanceβ and access everything
Also Bukkit provides a method to get an instance of the class
It definitely is extremely situational, yeah.
I'm more specifically talking about the Main plugin instance. IMO DI just doesn't make a ton of sense in that case. In most other cases, yes, I agree DI is better.
If you really donβt want to do DI
Standing for dependency injection?
Is there a yet a simple way of sending text to a players actionbar (without another api, would be the best)? I mean, actionbar has been a thing since 1.8 but i cant seem to find anything official in the docs
Yeah
Nvm maybe just found a way, sorry to trouble you
Canβt you just use a singleton pattern and use DI? The only thing youβd be not doing is having a static instance of main
Can anyone help me? I'm getting this error in my console https://imgur.com/a/uHsUZe7 and this is the method https://pastebin.com/ppjitDZW
It tells you what is null
How would I add a feature to return false if its zero... I thought it'd be easy but im struggling
in the method linked above
If what is 0
could someone make a simple plugin for me
I think something is wrong with the "this.main.battle"
actually maybe not
Just calling functions like
main.battle.startBattle(players, npcs)
``` returns the same null error
Is that onCommand method in the main class
It does tell you itβs null
I can't figure out why its null though... I'm just trying to call a method in another class
yeah
I declare in it the static main in the main class public BattleMenu battle;
How does one do that....
I'm very new and I'm following a tutorial to just learn the basics, and the person I'm watching has nothing else
What would I even set it to though?
An instance of BattleMenu
public BattleMenu battle = new BattleMenu(args);
As for the command that all looks fine
Make sure your exported jar has the right plugin.yml
That in the public class?
Public main class
It does
Wherever you declare, and before you want to use it
Does the /die command show up when trying to tab complete
I'm getting that the constructor is undefined....
What does your battle class look like
also dont put the "args" in there, that was just a placeholder if you had any arguments for it
It's prettu core, basically the core of the plugin. Did you want to see any part specifically
*pretty long
Remove the "args"
@upper tendon did you set executor for "die"?
.
replace it with public BattleMenu battle = new BattleMenu();
in your onEnable method
You donβt have to set executor if itβs your main class
I have the method public BattleMenu(Main mn, DataManager data) { main = mn; battles = new HashMap<>(); earnedXp = new HashMap<>(); countdowns = new HashMap<>(); lured = new HashMap<>(); traps = new HashMap<>(); dead = new ArrayList<>(); this.data = data; } So I think I must pass both main and data
Can I create the instance in this public BattleMenu method?
You should instantiate those maps and lists inline
doesn't have to
I can't put it elsewhere because I need to pass the data parameter
Not sure what inlining is
create the instance where you were trying to create it before
where you're actually using it
I'm trying to use it in the battlemenu class
Should I make the instance in the method I'm calling battle in?
why this aint working?
oh you saying that to wesbag?
So am I just screwed or
I need to use replies more
true
Define not working
Did you call bukkit.addRecipe
yup
Yes, that should work then
Again I always recommend a full restart instead of /reload to make sure
Also you wonβt get a sharpness 6 book from that
You have to get the meta and cast it
Ok @young knoll im so sorry im an idiot lol. I deleted my main class and then made a new one in its place but called it something else - didn't even check the log once π€¦ββοΈ sorry
It wonβt work in an anvil
Get the meta, cast it, used the linked method, and set the meta
Enchanted books have a different type of meta
so i did this..
but its red :(
wait dont tell anythingh
oh fixed it
the sword only maxes out to sharp 5 tho
The anvil might cap enchantments
Youβd have to use the PrepareItemAnvil event to get around that
Shouldnβt be
Just get the item in slot 2 and manually add the stored enchants to the output
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
k
is there a way to detect when a player is standing on everything?
why whenever i do SqlUtil.getConnection().close();
on disable
it has a chance for the plugin not to disable
and i have to kill the server
its so annoying
also the plugin disables before the world saves
I have not a single clue where you call it and what that actually is
Is it a Connection?
Also this is straight out wrong
Depending on what youβre doing, a static singleton, or the JavaPluginβs static way of getting a plugin instance may take even more time
They have different purposes
How is one better if they have different use cases?
Yeah I am just curious as to why
so uh, any idea why this is happening?..
How should we write E2E tests for MC plugins? Any tips, any tools? π€
How find leaks memory?
how to give a player an item ?
easiest would probably just to attach a profiler and look for classes that have "too many" instances, however many or few that may be. then is figuring out why they don't get gc'd
@EventHandler
public static void onPlayerMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
Material block = player.getWorld().getBlockAt(x, y - 1, z).getType();
if (block != Material.AIR) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9WalkDetector > &fYou are walking on " + block.name());
}
}
``` it seems that if i just stand on the block and move my camera, it will non stop sending the message, so is there any way for me to only detect when its on the y level and not x and z?
What are you trying to achieve here?
well i want it to detect when i am standing on the block but only once
because if i move my camera it will send the message saying i am standing on the block
i dont want that
i want it to only detect when i am on the block and not when i move my camera
Do you constantly want to check the block or only detect if the player enters a block for the first time
detect if the player enters a block
i want it like "player stand on a grass block and then a message pops up saying the player is standing on grass block and then when the player moves to another block it detects that one" but i dont want it to send the message when i move my camera
I think this performs decently.
private final Map<UUID, Material> playerMaterials = new HashMap<>();
@EventHandler
private void onMove(final PlayerMoveEvent event) {
final Player player = event.getPlayer();
final Material playerMaterial = this.playerMaterials.get(player.getUniqueId());
if (playerMaterial == null) {
return;
}
final Location from = event.getFrom();
final Location to = event.getTo();
final int fromX = from.getBlockX();
final int fromY = from.getBlockY();
final int fromZ = from.getBlockZ();
final int toX = to.getBlockX();
final int toY = to.getBlockY();
final int toZ = to.getBlockZ();
if (fromX == toX && fromY == toY && fromZ == toZ) {
return;
}
final Block below = to.getBlock().getRelative(BlockFace.DOWN);
final Material belowMaterial = below.getType();
if (belowMaterial != playerMaterial) {
return;
}
player.sendMessage("You have found your block!");
this.playerMaterials.remove(player.getUniqueId());
}
okie ill try it
i hope it is exactly what i want
oh why does it say "to.getBlockX();" might produce null?
Ah. Because in spigot the target location could be null.
final Location to = event.getTo();
if (to == null) {
return;
}
final int fromX = from.getBlockX();
Just insert this
ah okay
But how height is so low or so height?
why does this sound like its not english in my brain
π
what are you trying to say lol
I dont understand it either...
what if the block is below or above the maximum build height?
Ah
well it will not detect anything i guess
Pretty sure itβs air
Doesnt matter.
@lost matrix idk why but now it just doesnt say anything
Try to understand the code and you will figure out why. There is one precondition you have to fulfil.
ah
Are you starting Java?
@ivory sleet hire me 4 discord helper β€οΈ
Apps closed atm π¦
yes there is something wrong
Put in a good word for me and ya know π
Itβs been fixed @solar sable
ik
Toby, if you're more active, then maybe
I mean.. Iβve got work and College thoughβ¦
im an organised person and i mostly organise my class and stuff but seeing that he chooses his Main as a listener just makes me mad lol π
Also Iβm in Self Isolation right now.. Family tested positive
damn i hope you and your family is safe
Everyoneβs to their own.. Also heβs just started so gotta give him some slack haha
ah, well you currently have around 200 messages Toby
Huh what..
in this discord that is
Main class main m
Dont check how many I got lol
how did it go
Iβm Above average π
lol big brain
sheeesh
ππ€£
is it free? if its free imma take one hehehehe
gimme the link to the one you took lol
You want to help me with a big project?
what is it specifically
Command Framework π©
use mine π€‘
Any example of it in use?
uh
Like a command class

