#help-development
1 messages ยท Page 1546 of 1
BukkitRunnable declares a cancel method
new BukkitRunnable() { @Override public void run() { } }.runTaskTimer(plugin, 20, 20)
new BukkitRunnable() {
@Override
public void run() {
//code here
}
}``` will allow you to cancel
but how does the plugin know which runnable to cancel if you dont feed it the taskID
cancels itself
learn java
im just creating multiple runnables and im kinda having a hard time canceling them
is there a way to make a string like "0.4" into a Number?
paste the code
?paste the code
you are too daft to understand an explanation
so the only remaining option is a demonstration
Double.valueOf("0.4")
oh ok thanks
but beware
or parseDouble
the exception demons might getcha
lol
id = Manhunt.getInstance().getServer().getScheduler().runTaskTimer(Manhunt.getInstance(), new Runnable() {
@Override
public void run()
{
}
}, 1,20).getTaskId();```
cant refer to itself
new BukkitRunnable() {
@Override
public void run()
{
cancel(); //this cancels this task
}
}.runTaskTimer(Manhunt.getInstance(), 1,20)```
notice that Runnable was changed to BukkitRunnable
oh BukkitRunnable > runnable
nuice
not necessarily better
only if you need to cancel the task from within itself
in any other case, a runnable is cleaner
does it run slower or something
okay
how I can clone object?
depends on the object lol
month 2 of trying to clone a packet
yea I trying this again
but you remember wow
universal
depends on the object lol
is there an alternative to myBlockBreakEvent.setDropItems(false) in 1.8?
or do i just cancel the event and set the block
stuff like that is outa my league sry
interfase Packet
then dont run 1.8
no global clone method for objects
can i just use the 1.17 api on a 1.8 server
It's definitely possible, but you don't know how it can
i dont know how it can indeed
yeees
but im coding something for a 1.8 server
so stop coding something for a 1.8 server and start coding something for a 1.17 server
how do i make a task id for a task to cancel it?
and how would i make this into a syncrepeatingtask?
Bukkit.getScheduler().cancelTask(id);
but this work only how class implements cloneable
then there is no way to generally clone an object in java
int id = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
}
}, 20);```
the i is the id?
now you see?
yeah
now yvo see!
kinda
the .schedule methods return task ids
the .runtask methods return the tasks themselves
i dont care idiot
it's ๐คก
always posible task.getId
public static <T extends Object> T copyObject(T sourceObject) {
T copyObject = null;
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(sourceObject);
objectOutputStream.flush();
objectOutputStream.close();
byteArrayOutputStream.close();
byte[] byteData = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteData);
try {
copyObject = (T) new ObjectInputStream(byteArrayInputStream).readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return copyObject;
}
public static void copyInto(Object source,Object destination){
Class<?> clazz = source.getClass();
while (!clazz.equals(Object.class)) {
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
try {
field.set(destination, field.get(source));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
clazz = clazz.getSuperclass();
}
}```
I find intresting method
it says "Variable 'taskID' might not have been initialized"
oh
still says its not initialized
BukkitScheduler countdown = player.getServer().getScheduler();
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
and then theres a bunch of stuff inside the thing, didnt include the brackets or anything
wait i dont need the countdown anymore
so just the task id thing isnt working
Hello, good night !
I will need a little help ...
I am learning to use different configuration files than the default one.
For this, I am looking to set a value defined as follows:
@Override
public void setMailRead(UUID receiverUUID, Mail mail){
File mailPlayerDataFile = this.createFile(receiverUUID.toString());
FileConfiguration yamlDB = YamlConfiguration.loadConfiguration(mailPlayerDataFile);
yamlDB.set(mail.getId().toString() + ".isRead", true);
}
My problem: This file is not written. Should I save the file? If yes, how ? Thank you.
public static <T extends Object> T copyObject(T sourceObject) {
T copyObject = null;
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(sourceObject);
objectOutputStream.flush();
objectOutputStream.close();
byteArrayOutputStream.close();
byte[] byteData = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteData);
try {
copyObject = (T) new ObjectInputStream(byteArrayInputStream).readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return copyObject;
}``` I find this to clone object
What you think about it?
nothing transient will be cloned
Would I need to create a new inventory to be able to not take items from someones inventory or could you still just InventoryClickEvent on other players inventory
What's the accepted way to have multiple commands in a single plugin? One class per command, or multiple commands with the same handler and a check to see what string triggered the command
I broke IntelliJ ๐
one class per command otherwise the single class & method get messy
Wouldn't one class per command also get messy though, because java?
Not really
All the files though
easier to read though ๐
its just a preference, idk why someone would ask what they should do for that
in the case of commands, it's not a syntax thing.
It's more of "How easy do you want it to be to maintain"
where can I report bungeecord bugs
I'm more talking about the one public class per file, file matching class name, and package name matching directory structure rules
none of those seem liek an issue
^
Name another language that makes file structure part of the code
so I have java Player target = Bukkit.getPlayer(args[0]); if (checkOnline(args[0])) { player.openInventory(target.getInventory()); } and ```java
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
if (!e.getInventory().getName().equalsIgnoreCase("Inventory")) {
return;
}
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) {
return;
}
}
literally any language that groups source files hierarchially
C# iirc
why not C#?
Because it doesn't do that
also, strictly speaking, file structure is not part of the language
package structure is
You could also not use a file hierarchy with java by putting everything all in "src/main" or "src/" however that just gets messy as hell
there is no constraint that a source file that belongs to a certain package needs to be in a corresponding folder
c#, python, c++, rust, js, php, perl, ruby, go, swift, and r are all file name agnostic
Languages that I can think of off the top of my head that aren't are java, kotlin, and to a limited amount matlab
there is also strictly no need to have any more than one source file
There is if you need more than one public class
as static inner classes act just like regular classes
static inner classes can be public
classes in classes, but that's also messy
That's a subclass though, which is a very different construct
i didn't list that because I understand why you wouldn't consider it
butyeah if you don't do what intellij does and never import the top level class
inner class acts the exact same
the only difference is that you need to use a different syntax to refer to it from a different top level class than the one it is declared in
under the hood, it is the same
it even compiles to a distinct and separate top level class file
They can act the same under certain situations, but that does not mean that they are the same thing, and it certainly doesn't mean that they mean the same thing by convention
?paste
Java essentially forces you to use a single paradigm, and if you need to use anything outside of that paradigm things get messy very fast
'certain situations' majority of situations, and even in the minority of situations where they are not, the difference is a negligible difference in syntax
https://paste.md-5.net/oqoleyavik.cs you can shove anything and everything in a single class, as shown here though it gets messy quick
For example, why do we even need a create a class and then make a new instance of it to accept custom commands?
because, uh, it's an object oriented language
i'm not sure what you're looking for
It was mostly a rhetorical question
you could use JavaPlugin#onCommand for everthing, but again... it gets messy
"why do we need to use objects in an object oriented language"
You don't
"why do we need to use functions in a functional language"
That's not a requirement for most object oriented languages
It's not a requirement here either
For example, we could do something like
@register_command("something")
def something_command(context):
# do stuff with context when "/something" is run
There's command libraries for that kinda thing ๐
its literally just a preference
you either make it annotation based, or the way bukkit did
see ACF
but that commandmap thing exists so yeah.. you can just add support for annotation based
Yes, but that basic paradigm is very messy to get working in Java, especially when most of java is built very strongly around objects and interfaces
yes
it is an object oriented language
everything is an object
object is a first class citizen
That's not what an object oriented language is though
Even your annotation commands shockingly end up becoming an object
what do you mean?
Object-oriented programming is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields, and code, in the form of procedures. A feature of objects is that an object's own procedures can access and often modify the data fields of itself.
i mean.. how doesn't java fit this?
Java is an object oriented language, but an object oriented language is not a language where everything is an object
as for ruby
Ruby is a pure object-oriented language and everything appears to Ruby as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Even a class itself is an object that is an instance of the Class class.
What in Java is not an object?
Correct
java is actually less oop pure than some other oop languages, as it has the primitive data types
There are object oriented languages where everything is an object, like ruby, and there are object oriented languages where most things are objects, like java
Excuse me Mr Skull Head and other people ๐
in the end, everything is an object
you can throw annotations at it all you want
but at the end of the day, you're still fucking with objects
you're still instantiating a class and setting it as the command executor
Yup
even in your example, even in another oop language
And that's where java gets annoying in my opinion
objects are objects, syntax sugar is syntax sugar
if you want more syntax sugar, use kotlin
This sort of command registration screams functional programming, but you can't really do functional programming in java
even pointers are classified as objects it seems :p
sure you can; Bukkit just doesn't support it for command registrations
You can emulate functional programming through objects, it's not really the same thing
streams and functional interfaces are a thing, and in recent years java has become far more functional
?paste
https://paste.md-5.net/upecoxuxit.java object or functional?
Object emulating functional
if functional interfaces count as first class function objects then yes
yes, shockingly, the object oriented language doesn't natively support functional programming
And yet there are other OOP languages that do
yeah typescript
JS, TS, C++, Python...
kotlin is, yes
Yup
Java is all in all a very, very limited language
depends on the definition of limited
There's a lot of common stuff you can't do, a lot of comman stuff that's very hard to do
be more concrete
Huhhhhhhhh
Add that in with all of the syntax noise, and it becomes a pain to work with when you're used to more elegant or powerful languages
oh yeah surely it lacks of developer sided quality of life features
idk why you surprised about that one imagine
It's just generally a painful language
I've worked with python a good bit, don't really have an issue with java as a language ๐คทโโ๏ธ
the only downside of mine to java is that its so strongly typed
i just wish kotlin improved java but didn't make its syntax ugly
very sad
java does suck, but your basis for saying it sucks is rather silly and seems pretty biased
Give me a function that accepts a value by reference and I will accept that java is not limited
??????????????????????
Don't worry, I have many more reasons to believe it sucks
These are just usually the easiest to explain
private final A a;
public boolean b(A a) {
return a.equals(this.a):
}
idk what you mean by reference
Pass by value
i still cant get this to work, anyone know why it says taskID isnt initialized?
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
Bukkit.getScheduler().cancelTask(taskID);
var a;
void x(Object o) {
o = "string";
}
{
log.info(a); //prints null
x(a);
log.info(a); //prints string
}
``` for instance
how many languages are pass by reference/value
i wonder what the difference is
then how many do both
I still dont understnad
noob
Java is pass by value which means that only the value of references get passed
๐
(not talking about java Reference class)
just wrap it in a 1 length array ๐
lmao
A good way to check if a function passes by reference is to write a "swap" function
void someFunction(a, b) {
tmp = a
a = b
b = tmp
}
If the variables you passed swap values after calling swap, it's pass by reference
python
a, b = b, a
or smtng lol
Yup
yall mean
String string = "Dog";
String reference = string;
print(string == reference); // True
this right?
instead of like in python
obj#copy
That's a different thing, but similar
That's java not allowing operator overloading
Another thing that makes it annoying btw
I mean operator overloading doesn't seem that crucial to have in a language
of course it's still syntactically nice to have
but nothing of the life saving side
For a language like java where it hides memory management, no, it's not necessary
anyways, speaking of functional programming, you code in haskell?
Very nice for mathematical classes though
I've used some haskell. That's a weird place
monads and monoids ๐ฅฒ
lol
yeah well Java has Unsafe and is going to get the incubator thing also
so it kinda exposes memory management partly
java pretty cucked because of how much they want to preserve compatibility
sad times
Just give me pointers, you're a c type language ๐ญ

So overall Java doesn't have pointers (in the C/C++ sense) because it doesn't need them for general purpose OOP programming. Furthermore, adding pointers to Java would undermine security and robustness and make the language more complex.
can java give me loom, metropolis, panama, valhalla first
yes please
trust me, I get that pointers have security concerns
and you've got this answer too https://qr.ae/pGPpzD
yeah its slowly securing everytrhing lol
There are times when things would just be faster to throw a quick pointer
definitely
Nothing critical, they're just another nice to have
I guess that's one of the main things with java, all the "nice to have" features it doesn't have, while the main thing that's nice about it is it's enums
Side note, java enums are amazing
material enum 
a large part of it is md_5 wanting to keep backwards compat with pre 1.13 .-.
Go yell at md_5 for that one
I have multiverse core and I'm trying to find a way to get a queue system for different multiverse worlds. Any help?
Anyway, gtg
how do you convert a bungee component to a nms chatcomponent?
Probably through pure strings
yea... just dont like the idea of serializing to just unserialize
There are some examples of it in Spigot's implementation iirc
i cant find D:
nvm
found
// asserted: components != null
if (CraftMetaBook.this instanceof CraftMetaBookSigned) {
// Pages are in JSON format:
return ComponentSerializer.toString(components);
} else {
// Convert component to plain String:
return CraftChatMessage.fromJSONComponent(ComponentSerializer.toString(components));
}
}```
@worldly ingot idk if ur interested
for future use maybe
Yeah I'd figured it had to do with the ComponentSerializer
yea thats basically what i did anyways
i just dislike the serializing/unserializing
yeah its gross
can anyone help me with canceling a task using a task id
it says taskID isnt initialized
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
Bukkit.getScheduler().cancelTask(taskID);
use a bukkit runnable
Hey is this a good idea? Its in the AsyncChatEvent event ```java
// Due to the nature of spigot chat messages it is not a good idea to disable the event and broadcast later
// Luckily chat is handled on async threads anyway and members are cached after the first time so this is not that huge of a problem
Member member = plugin.getBot().getGuild().retrieveMemberById(playerInfo.getDiscordID()).complete();
Read the comment, its basically my question
Should I be doing that, usually id add a callback but the issue with that here is that I would have to Bukkit.broadcast instead of just editing the chat event, possibly making my plugin super intrusive? I thought since chat has multiple threads anyway and its likely not a very long task I can just wait for it to finish and block that one of many chat threads
someone told me to do it this way
but now im really confused because people keep saying different stuff
scheduleSyncRepeatingTask is deprecated, it got replaced with bukkit runnables
This reminds me of fork() lmao
???
Bukkit runnable
Kinda
Im getting this error with my plugin
Cannot invoke "Object.toString()" because the return value of "net.nukeStudios.nukeNPCS.PacketReader.getValue(Object, String)" is null
Bukkit has their own event loop and task queue system for this, theirs is better than using classic Runnables for this since it uses the bukkit threadpool/queue
instead of making a whole new one
Which means you dont need to do shit like Bukkit.getScheduler().runTask(plugin, () -> etc code);
how do i make this in the form of a bukkit runnable?
Well depends on which version of the API you use
im using 1.17
as in do this int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
EXCEPT
replace Runnable
with BukkitRunnable
or provide a lambda instead
it still says taskID isnt initialized tho and thats what i cant figure out
It SHOULD exist, which is weird, a bypass I guess is to use cancel() from within the task itself
ok
help
Read the error
The value is the return value was null
you cant toString a null
its nothing to make into a string
idk how to fix
Figure out why the return value was null
so i have ```java
int countdown = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new BukkitRunnable()
and i used cancel();
but now when i run the command it says Internal error message thing
(renamed to countdown)
i wanted to start with making something in dependencies i cannt add 1.17 spigot jar file
i changed it to runTaskTimer and its still giving the internal error
like inside the brackets?
on the bukkit runnable object that you instantiate with new BukkitRunnable
BukkitRunnable countdown = new BukkitRunnable() {
@Override
public void run() {
}
}.runTaskTimer(plugin, new BukkitRunnable()```
this?
ok i think i might have got it
Asked before but no response, ama bit confuse
Its in the AsyncChatEvent event ```java
// Due to the nature of spigot chat messages it is not a good idea to disable the event and broadcast later
// Luckily chat is handled on async threads anyway and members are cached after the first time so this is not that huge of a problem
Member member = plugin.getBot().getGuild().retrieveMemberById(playerInfo.getDiscordID()).complete();
Read the comment, its basically my question
Should I be doing that, usually id add a callback but the issue with that here is that I would have to Bukkit.broadcast instead of just editing the chat event, possibly making my plugin super intrusive? I thought since chat has multiple threads anyway and its likely not a very long task I can just wait for it to finish and block that one of many chat threads
it would delay the chat though, no?
Is the AsyncChatEvent which means there are many threads processing chat at once
it would still delay the chat message itself somewhat
So it would block a single chat thread and if/when another message gets sent while it blocks one of the threads it will just get picked up by another thread
Yeah it would
It usually would be instant unless something goes wrong with discord API
i would schedule an async task within
you don't want your in game chat breaking if discord does
True, I might attach a max timeout to it so the max time it takes is like 5 seconds and if that happens just handle it differently
Simply since it would lag chat either way if i have to attach a callback to it, just wouldnt lag the thread but the message
and its a bit... wack to cancel chat event just to send another broadcast yk?
why broadcast?
Well i need member data to get the required stuff for a message,
But I may not have it cached already, the problem is that if i need to put it in an async event i need to cancel the chat event or it gets processed before i can change the chat format
so make the placeholder return "Not Loaded" if it's not cached
or however you're doig it
The thing is that when you do retrieveMemberById and not cache it checks cache anyway
it's not worth it to lag a chat message just for the linked account
i forgot emote no work
lmao
but yeah I need to do cache check
it will load in at some point so yeah ill do that
How would i detect whether a chest is in a generated structure?
with great pain
What would be the optimal way of storing unlocked and selected cosmetics? For large amount of players, I wouldn't imagine a YML file?
I have made a sniper rifle for a minigame that uses shift to scope and a pumpkin with a resource pack but I think it would be a lot better to use a spyglass with left click to shoot. When I tried this out, when scoped in, an Interact event listener wouldn't hear left clicks. Is there a way to either detect left clicks while an item is used or to fake it for the client and give them the visuals of a spyglass?
could do it in the PDC
anyone know which api version 'org.bukkit.Material org.bukkit.Material.getMaterial(java.lang.String, boolean)' was first introduced in?
1.13?
do you know how ๐ค
1.13, yes
why would it be used before 1.13
although the jar name doesn't have space, the plugin name, i assume it is the name specified in plugin.yml, does
have you ever seen a plugin with a space in its name, SupaGamer?
ohh
yes
like?
for the jar file, maybe
so i cant have spaces
i'm talking about the name in /pl
interesting
every single plugin uses CamelCase
Ok maybe there was a time where spaces were permitted
isnt camel case likeThis
tf
that just sounds so wrong
anyway i also figured out how to do the bukkitrunnable thing and everything works flawlessly, spleef game now almost done :)
Or if you mean parcal case
Then maybe
but i rmb it is correct to say both are camelcase
is there a way i can make a genorator type thing were if i put all diamond ore and blocks down when you break them the whole mine resets after a minute or so and it randomly places the diamond ore and blocks?
ah yea
Up here in the north itโs called MooseCase
can you modify the block list from BlockExplodeEvent#blockList() to change which blocks it removes?
gonna cwy
Y?
yes you can
how
Y are you gonna cry :/
learn coding
learn java
i believe there are multiple plugins out there that do that
easier
name them
Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
๐คฃ
https://duckduckgo.com/?q=regenerating+block+plugin+spigot&t=brave&ia=web look what I found!
DuckDuckGo. Privacy, Simplified.
with one simple search!
duckduckgo
Yes
bump
bump
that's not what they were looking for, Player
Not?
I'll be honest, you seem to try to shut up conversations by giving a crappy or unhelpful answer just to send a message in the chat.
can i detect when a player gets hit by a snowball
and get the instance of thqat player
and the snowball
I think this is right.Not sure tho. https://paste.md-5.net/ibobuzedik.json
I believe if you check the entity damage event or something along those lines
snowballs dont do dmg
ProjectileHitEvent
Projectile p = e.getEntity();
if (!(p instanceof Snowball)) return;
Snowball s = (Snowball) p;
.getEntity might give me the player
so the .getEntity gives the snowball
And there's ur snowball
but what about the player
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/ProjectileHitEvent.html magical what the javadocs can show you
Is there a .getPlayer method?
hold on i just realized that the site is called md_5
nop
:7
nvm it does
reading helps more, i think
Forum staff
helpchat 1.8 lol
getEntity is not who got hit btw
close that Misleading website
that's not... spigot
:0
helpchat insists on justifying 1.8 by hosting the javadocs
do you know like why the json is formatted thta way
I've had so many API tabs open recently...
like what to put in the parent
Read some docs
Lol
another ppl said to put items/generated no matter what
Just fucking google
๐คฃ
The first thing I found was that resource
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.
Pep 8:22
how does the new 1.17 NMS work? im using an nms util class that uses net.minecraft.server but like ItemStack is in .server.world.item which throws errors
almost everything is repackaged
people are used to using reflection or NMS util, but those old ones won't work anymore
2 is ok
Though is normally 4 for java
Two is passable, it just isn't as visually distinct
Of course, if you use the indent rainbow plugin like me it's still plenty distinct
what's the method to spawn a new entity, like a new snowball, at a particular location?
or do i just initialize a Snowball object?
well, projectiles are kinda required to have a shooter
so you can use the ProjectileSource interface to shoot the projectile
how would i separate the skywars code and the survival games code into separate files, so i have a file for my main class, a file for my skywars class, and a file for my survival games class
public class Main extends JavaPlugin {
// Create SkyWars Teams
Team sw_team_one = scoreboard.registerNewTeam("sw_team_one");
Team sw_team_two = scoreboard.registerNewTeam("sw_team_two");
// Create Survival Games Teams
Team sg_team_one = scoreboard.registerNewTeam("sg_team_one");
Team sg_team_two = scoreboard.registerNewTeam("sg_team_two");
@Override
public void onEnable() {
// Setup SkyWars Teams
sw_team_one.color(NamedTextColor.RED);
sw_team_two.color(NamedTextColor.YELLOW);
// Create Survival Games Teams
sg_team_one.color(NamedTextColor.BLUE);
sg_team_two.color(NamedTextColor.GREEN);
}
@Override
public void onDisable() {
// Remove SkyWars Teams
sw_team_one.unregister();
sw_team_two.unregister();
// Remove Survival Games Teams
sg_team_one.unregister();
sg_team_two.unregister();
}
}```
i have the scoreboard defined elsewhere this is just a placeholder
If I'm making one of my classes serializable with the Config API is it okay for my deserialize(map args) method to return null or something else to indicate it can't properly be deserialized?
or wait
do i just throw an exception if i cant deserialize it?
well if you set a value to null it just won't show up
so you can technically set and get null values just fine
@EventHandler (ignoreCancelled = true)
public void onDamageCheck(EntityDamageByEntityEvent event) {
Bukkit.broadcastMessage("Hit");
}
Technically this should stop the message from appearing when getting hit in a worldguard region right?
priority matters
what priority does worldguard cancel at
try yours at highest, or monitor if you're not gonna modify the outcome of the event
Can I somehow override one plugin's method with another plugins method? I am writing both.
What i want to do is for a second plugin to impose restrictions on the reacttions of the first.
IE, as long as the second plugin is active, you need it's permissions too
the indentor
You can use Optionals, they are made for this.
for(Entity e: location.getChunk().getEntities()){
if(e.getLocation().distance(location)<1){
if(!e.equals(player)){
e.setGlowing(true);
}
}
}
how do i cancel the glowing effect after sometime
but thats instantly cancels it
is there way to listen for left click while the player is using an item, in this case a spy glass
when looking through the spyglass the event isn't called for a left click
interesting, must be client side
does that also mean a packet isn't sent at all
is there a way to send packets to make the client look like they're using the spy glass
or would that run into the same input problem
probably not
you can check whether item use statistic increments when using spyglass
oh interesting
so must be a packet sent then
just no api i guess
seems entirely clientside though
couldnt someone just send a shit ton of "i looked in spyglass" packets
I think the stat for spyglass is just looking through it
declaration: package: org.bukkit, enum: Statistic
there is also an event when statistics increase for a player
@EventHandler
public void onSpyglassLook(PlayerStatisticIncrementEvent evt) {
if (evt.getStatistic() != Statistic.USE_ITEM || evt.getMaterial() != Material.SPYGLASS) return;
Bukkit.broadcastMessage("spyglass looked through");
}``` works just fine
guess now you need to detect when they stop
that's not my issue, my issue is that I can't detect left clicks while they are looking through it
the left click doesn't trigger the event
clientside, you can't left click while looking through it
yeah
minigame, one class has a sniper
interesting, worthwhile to figure this out
been using shift and it gives you a pumpkin with a texture pack
works fine but would be nice to use spyglass
an item that clears a whole chunk when placed
a chunk that clears a whole item when placed
????
did I stutter?
Yes
sorry my internet connection keeps cutting off, what did you say?
was one of my first plugins
i think so. but not sure
?paste
Why?
https://paste.md-5.net/iruzucosiw.xml
Cannot resolve junit:junit:4.10
extend? more implement and its totally fine
How Do I import documentation into my IDE using gradle?
anyone remember off the top of their heads what the max image size limit was for a spigot post?
Didn't know there was one
pretty sure it's the only reason every spigot post isn't just one giant gif
like 5MB
but you can link to an external image url
hm
hmm
was it 3MB before because it seems like that's what I was targetting before
but ok
?jd
hi I have a problem in my geyser
when becrock players enter, their name it shows lik this
Bedrock Name: Derek
Server Name with Bedrock: .Derek
Can u help me
Gotta go to their discord
what is pigstep's material in spigot
MUSIC_DISC_PIGSTEP
01.07 06:52:49 [Server] ERROR app//it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap.get(Long2ObjectOpenHashMap.java:356)
there is the reason
damn why do some many "devs" not now how to read errors
Can i have my question answered? Can you overwrite functions from other plugins?
Yes and no, it depends.
i write both plugins
It's just basic java then, though, I think you can use event priorities to overwrite events?
got a reference? I'm not too sure what you mean
and player pre process or how ever it's called for commands
cancelling the command before it gets to the other plugin you mean?
polymorphism is a thing
problem is i need that for a playerInteractEvent
yep, I meant oop concepts when I mentioned basic java
^
Would i get an error were i to register two events with the same name but different priority?
or since this is bukkit same @EventHandler?
Wait can i listen for the activation of plugin functions?
Google your question before asking it:
https://www.google.com/
fair enough lol
You have to make a method for it yourself.
If you can't do anything with that info you probably wouldn't be able to do anything in the first place ... ๐คท
And if you gave me a few seconds I would post the code
Alright, a more detailed response, you can either write a method by yourself to check the length, add the write letter / remove the a few numbers, there is also another way, which you just need to think a the logic on how to use the Math class and google to write only a few lines, but by being rude isn't going to bring you any help
public String formatMoney(double amount) {
if(amount < 1000L ) { return format(amount); }
if(amount < 1000000L ) { return format(amount/1000L)+"k"; }
if(amount < 1000000000L ) { return format(amount/1000000L)+"m"; }
if(amount < 1000000000000L ) { return format(amount/1000000000L)+"b"; }
if(amount < 1000000000000000L ) { return format(amount/1000000000000L)+"t"; }
if(amount < 1000000000000000000L ) { return format(amount/1000000000000000L)+"q"; }
return String.valueOf((long) amount);
}
I've been using https://crafatar.com to get player skins for my plugins. Is there a Bedrock alternative to this site?
i have vault as a soft dependency on my plugin, can i make sure that if the server doesnt have it, the plugin loads like normal?
Why cast to long? Math::floor() but else nice
Yup
but i'm using a part of their economy
so i have an error every time i want to enable my plugin
Add it as softdepend and only run vault code if vault is on the server
You can check if the vault has been loaded and load those parts otherwise just skip them
Then you will have to check if an economy implementation is present
Because it goes above int's max number
i have this code for it now
private void dependenciesSetup() {
// Setup Economy
if (instance.getConfig().getBoolean("requires_vault") &&
Bukkit.getPluginManager().getPlugin("Vault") == null)
getServer().getPluginManager().disablePlugin(this);
RegisteredServiceProvider<Economy> economy = getServer().getServicesManager()
.getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economy != null)
eco = economy.getProvider();
if (eco == null) {
Utils.logInfo("You must have Vault installed and an Economy plugin!");
}
ah that first if is kinda wrong
Thereโs not int involved tho?
double I mean
Entity.setVelocity(Vector vector) seems to have no effect if the entity is in water; anybody have any ideas how to get around this?
doubles can be much greater than longs
You're disabling the plugin when you don't find the vault
Doubles max out at the same as ints don't they?
Nope
and if in the config "requires-vault" is so to true
yes
and by default its false
But if you use large doubles, precision and presumably calculation problems may be encountered
aren't they both 8 bytes long ?
yes, but they represent data differently
Yeah but it has something called a scaling factor or an exponent
Works quite differently from int/long
a double sacrifices some of the 64 bits of precision in order to be able to represent values of arbitrary scale
So, long should be bigger, no ?
they are the same size
but double can represent larger numbers at a lower precision
๐ณ
or smaller numbers at a higher precision
you can think of it as using 48 bits to represent an integer number
and then use the remaining bits to determine the position of the radix dot
12345.6789
Yes, that's what I was thinking
you can move the dot around, but the actual number of digits you can have is still fixed
123456789000000000.0
how can i prevent this
Caused by: java.lang.ClassNotFoundException: net.milkbowl.vault.economy.Economy
0.0000000000123456789
when vault isnt installed
Send your code
don't try loading the class if it isn't installed
anyways by looking from the code above it seems like you want to add a return; if the first branch is true
i don't remember if that is enough
It is
just referencing the class in the method might make it explode
i don't remember the exact semantics of when classes are prompted to be loaded
yea, no, never mind, I'm an idiot
null checking PluginManager#getPlugin(name) should be enough I think
Make sure you have the repositories in your POM
if (instance.getConfig().getBoolean("requires_vault") &&
Bukkit.getPluginManager().getPlugin("Vault") == null) {
getServer().getPluginManager().disablePlugin(this);
} else if (instance.getConfig().getBoolean("requires_vault") &&
Bukkit.getPluginManager().getPlugin("Vault") != null) {
RegisteredServiceProvider<Economy> economy = getServer().getServicesManager()
.getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economy != null)
eco = economy.getProvider();
if (eco == null) {
Utils.logInfo("No economy plugin found!");
}
}
Show POM and full error
If you want it to just disable add Vault as depend
i also want to let the plugin work without vault installed
Then why disable your plugin if vault is absent?
if in the config file require_vault is set to true then it disables
otherwise it just dont load the vault classes
Sounds very odd to have as a feature but I guess
i generally prefer to isolate soft dependencies and their classes entirely
plugin.getDependencies().VAULT.doVaultThing()
it does work but its strange code yea
public final?
myeah
i suppose I could or should use a method, but I like the enum-esque declaration
Lmao fair
Hi, i have been tryna do this for a while and I am confused on why its not working. My config is not saving what i am setting, LinkedHandler is my config handler and it is just a basic yml config handler.
Code:
new LinkedHandler().saveConfig();```
Config Handler:
```public static File configFile;
public static FileConfiguration config;
public void base(Main m){
if(!m.getDataFolder().exists()){
m.getDataFolder().mkdirs();
}
configFile = new File(m.getDataFolder(), "linked.yml");
if (!configFile.exists()) {
m.saveResource("linked.yml", false);
}
config = YamlConfiguration.loadConfiguration(configFile);
}
public void saveConfig() {
try {
config.save(configFile);
} catch (IOException e) {
}
}
is it in maven central?
learn java
lemme open an ide
Works fine for me
<dependency>
<groupId>xyz.xenondevs</groupId>
<artifactId>particle</artifactId>
<version>1.6.3</version>
<scope>provided</scope>
</dependency>
Tomato, what is your issue?
inb4 using dialup
There must be something that is causing that issue on your end then...
then dont press it ๐คก
is this a good way to check in the inventoryClickEVent if the clicked inventory is one i made myself? (the TrailsGui class)
if (event.getInventory() instanceof TrailsGui/*trails*/) {
Use the inventory holder
ah thats why i'm encountering the same problem as before
inventory holder or the inventory instance
i don't think it's a good idea to implement the bukkit inventory
doing that can generally cause shit to explode
instead of owner?
yes
inventoryholder doesn't mean the person who is looking at the inventory
it means the thing that holds the inventory
yes
for a chest inventory, it will be the chest
for your custom gui, it will be whatever handles your custom gui
ah okay
ah yes it works
thanks
but is there some way to push new contents of a file to the plugins datafolder with every new update?
there is a folder in plugins for every plugin's files
wut
How clone object without implements cloneable and without constructor?
do you mean an embedded resource in the jar?
aah i just want to write new text to the existing config files
like when there is an update or other things
you'll have a difficult time if you want to preserve comments
consider using a real config api or framework, like configurate
the constructor?
just pass all the data in and BANG you have another object but with the same data
oh wait you said without
idk
What is your usecase?
Hm ok
What packet and why do you need to copy it?
We've told you 4 times. Use the constructor to copy the packet
I need send to other players others packet about someone things
Why don't you want to use the constructor
CPU usage and it no universal
What????
well how can i "disable" my class when vault isnt installed?
Just dont instanciate it ๐
high CPU usage in my case
Not true
Well no other way
just put an if inside my methods that looks if vault is installed?
must be
public static <T extends Object> T copyObject(T sourceObject) {
T copyObject = null;
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(sourceObject);
objectOutputStream.flush();
objectOutputStream.close();
byteArrayOutputStream.close();
byte[] byteData = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteData);
try {
copyObject = (T) new ObjectInputStream(byteArrayInputStream).readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return copyObject;
}``` yestarday I find this but this is bad I think
if you find another way it almost 100% just uses the constructor under the hood
You can't create another instance without creating another instance
just check onEnable
you can not safely create an object without invoking a constructor
see on this source I don't understand it but this work
yes i already do that
fucking 1.8 users smh
and thats enough?
it could be dangerous
just use the constructor
so then, maybe have a boolean method onEnable that just returns whether there is vault
I not am user 1.8 xD
you clearly are
im gonna assume there is a language barrier here
Just use a constructor
nobody other than a 1.8 user could be this persistent about something this stupid
What is the issue
He wants to create an instance without a constructor
he wants to clone an object without the constuctor

i love fanatics
Yall talkin about this?
no - that is just something he gave
This has a constructor inside
Yeah
Try telling him that
All other constructors are fine exept the constructor of the object he's cloning
other people tell this imposible but I tell this is posibble but this source is bad I think
;/
what makes you think you know better
do you had a nightmare about constructors?
Ok whenever you see an instance popping out from no where, you can safely assume there is a constructor implemented somewhere
^^
^^
^^
yea this is true but this is universal copy

I don't want to use just the constructor of the class I want to clone
YOU CANNOT DO IT SAFELY ANY OTHER WAY
There is no reason to work around the constructor
USE IT
And without absusing oops concepts
I have a reason
Not a valid one
Not a valid one
Lol
lmao
๐ ๐
If you can give a good reason we may help you more
but if not - use the constructor
oke I can
divulge me your wisdom
public PacketPlayOutMapChunk(Chunk var1, int var2) {
this.a = var1.locX;
this.b = var1.locZ;
this.f = var2 == 65535;
boolean var3 = var1.getWorld().worldProvider.m();
this.d = new byte[this.a(var1, var3, var2)];
this.c = this.a(new PacketDataSerializer(this.g()), var1, var3, var2);
this.e = Lists.newArrayList();
Iterator var4 = var1.getTileEntities().entrySet().iterator();
while(true) {
TileEntity var7;
int var8;
do {
if (!var4.hasNext()) {
return;
}
Entry var5 = (Entry)var4.next();
BlockPosition var6 = (BlockPosition)var5.getKey();
var7 = (TileEntity)var5.getValue();
var8 = var6.getY() >> 4;
} while(!this.e() && (var2 & 1 << var8) == 0);
NBTTagCompound var9 = var7.d();
this.e.add(var9);
}
}```
ok i didn't know there is a provided nms code lol
one constructor for each on all blocks check all NBT and check all entity on chunk
i think you have to bare in mind that the server sends hundreds of these per second
it is not that inneficient
calling this constructor causes high CPU usage
If you really want to make it faster create your own packet
And no we won't guide you with that
yea this true generating even more is not crazy?
Nope
So little of the server tick is spent sending these
you are over thinking this
10 times more is not madness?
Why are you sending 10 times more
I have so many questions
what plugin are you making @main dew
sending this packet does not only generate new chunks but also refresh old ones
the server then creates one package for all players that have that chunk loaded
but if I want to send a slightly changed package to each player, I have to clone it
blocks and nbt
why dont you send them packets seperately
rather than changing the chunk send blockchange packets
what do you mean?
if you are changing blocks in the chunk packet
just send blockchange packets after and un-modified chunk packet
which will have a lower over-head
Also why not just use Protocollib or smth
^^
I see little reason to remake things that already exists and is almost installed everywhere regardless...
moment I can send you video where they did
This the right place to ask why config files aint working?
Depends on which config files
a config file which stores player data
if plugin config yes
Your plugin or someone elses
Then this is the right place
config: ```yml
<some_uuid>:
<first_key>: Alpha
code:```java
//MainClass
public FileConfiguration cfg = null;
File dataFolder = this.getDataFolder();
//OnEnable
cfg = YamlConfiguration.loadConfiguration(new File(dataFolder, "config.yml"));
//Other Class, same package:
sender.sendMessage(Bukkit.getPluginManager.getPlugin("MyPlugin").cfg.getString(player.getUniqueId() + ".first_key", null));
result:
null
Why isn't it the saved value? There's no error in the console either, and the plugin is has read/write permissions
yes
JavaPlugin#getConfig()
oh
i just shortened it to make it easier to read
Also why are you using the plugin manager to get your instance
different class?
You should pass it along in the constructor
that is in a command call
and?
static instance is what I see used
but this config file that you are trying to access, it is config.yml
oh ok
@opal juniper sorry I can't find this but bigger changes are detrimental to gamers as well as internet connection
then you dun need Bukkit.getPluginManager.getPlugin("MyPlugin") infront of cfg
Not sure if that's bad practice tho
and sometimes another plugin to refresh the chunks and then everything goes to waste (worldedit etc)
In the constructor of you command class pass your plugin instance and save that to a variable
idk man i cannot help u anymore
will do but that still doesnt tell me why it returns null instead of the string i want
their internet shouldn't matter
Could you send us the raw unmodified code. Because I've seen way too many people changing it too much so we can't help
onyl the relevant parts but yes. Give me a moment
Is there reason to do this rather than a static reference to the plugin
A static refrence is fine too
Okay good to know
dammit then heres the code
main class (named Echo):
FileConfiguration config_players = null;//YamlConfiguration.loadConfiguration(new File(dataFolder, ""));
@Override
public void onEnable() {
//File cFile= new File(this.getDataFolder(), "config.yml");
//if(cFile.exists()) {
// cFile.delete();}
//getConfig().options().copyDefaults(true);
//saveDefaultConfig();
loadPlayerConfig();
getCommand("getrace").setExecutor(new GetRaceCmd());
}
public void loadPlayerConfig() {
File pdf = new File(dataFolder, "config_players.yml");
if(!pdf.exists()) {
pdf.mkdirs();
try {
pdf.createNewFile();
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not save Log file due to: "+e.getMessage());
}
}
config_players = YamlConfiguration.loadConfiguration(pdf);}
command class, relevant part:
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(args.length == 0)
return false;
Player p;
p = Bukkit.getPlayer(args[0]);
if(p==null) {
sender.sendMessage("Player not online, checking offline.");
p = (Player) Bukkit.getOfflinePlayer(args[0]);
if(p == null) {
sender.sendMessage("Could not find offline player. Does a player with that name exist?");
return true;
}
}
//Standard return value null
String race = Echo.Instance().cfg.getString(p.getUniqueId() + ".race", null);
if(race == null) //This always trigg
sender.sendMessage("The player has no race assigned. Did he ever join?");
else
sender.sendMessage("The player has the race '"+race+"' assigned.");```
Use the plugins logger
Also I recommend reading this: https://www.spigotmc.org/wiki/config-files/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
More specifically the creating custom configs part
Does your config actually contain anything
Aight
that uuid is that of the player im checking too
Looks fine
thats the issue lol
Could you show me the cfg variable