#help-development
1 messages · Page 1620 of 1
If i use DecimalFormat("0.00") to store a double in the config, It wil place a double like this: 100,00 instead of 100.00
How can i fix that?
@smoky finch
float f = 0.1f;
float a = 3;
Vector fwd = location.getDirection().toVector();
fwd.y = 0;
fwd.normalize();
Vector right = Vector.rotate(fwd, Y, 90) //whatever the function actually is
for(float i = 0; i <= distance; i += increment) {
float offset = 2*a*(Math.abs((i*f % 1.0f) - 0.5f) - 0.25f)
Location loc = location.clone().add(fwd*i).add(right*offset);
}
What's \*?
Oops
Oh you were trying to escape it
yeah those are markdown escape characters
Forgot you don't need to escape them in code blocks
Use the non-regional version
can anyone help me with this, i am trying to make database but it won't connect due to password, it gives me an invalid configuration exception https://pastebin.com/QYTAeFL4 i don't know why i just know its because of the password, how could i fix this?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Or actually you're probably better off with actually writing the double and doing the rounding mathematically
double round(double d, int precision) {
int mult = Math.pow(10, precision);
return Math.round(d*mult)/mult;
}
new BukkitRunnable() {
double distance = 1;
static final double maxDistance = 10;
// boolean odd;
float f = 0.1f;
float a = 3;
Vector fwd = location.getDirection().setY(0).normalize();
Vector right = fwd.rotateAroundY(Math.toRadians(90));
@Override
public void run() {
double offset = 2*a*(Math.abs((distance*f % 1.0f) - 0.5f) - 0.25f);
Location loc = location.clone().add(fwd.clone().multiply(distance)).add(right.clone().multiply(offset));
player.getWorld().spawnParticle(Particle.FLAME, loc, 1,0,0,0,0);
if (distance++ >= maxDistance) cancel();
}
}.runTaskTimerAsynchronously(plugin, 0L, 3L);
Wait I think I figured it out
Oh wow it actually worked
I just forgot to fix your clone() on the right vector
I still gotta understand what the hell is happening here, but thanks a lot
quick q because I've not used lambdas that much, if I create a bukkit task using Bukkit.getScheduler().runTaskLater(plugin, (task)->{}, 20L}; is there a way for me to store a reference to the task outside of the task itself?
Nope, use a BukkitRunnable like I'm doing above ^
that's what I was doing previously but then every time I post any code with one people go on a witch hunt for not using lambda expressions
Huh really?
if you want the bukkit task on the outside, you could use the runTaskLater with a Runnable
oh yeah.
store the returned BukkitTask in an AtomicReference
and access inside if you need it inside
should be pretty safe concerning the Scheduler never ticks the runnable on the method stack it is scheduled
I heard some mixed feelings about atomic reference previously, I mean is there a point in using lambda expressions if it requires these workarounds?
tbh I have no idea why the method does not return the task as well
I do feel like it should return the task id
Yeaaa idk why it isn't returned
Can someone help me with my code?
I wanna write something in a file when someone is using a command imgame
whats wrong with my code
where is your code
package eu.hausgans.dc;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.FileWriter;
import java.io.IOException;
public final class Main extends JavaPlugin {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
FileWriter myWriter = new FileWriter("test.txt");
myWriter.write("Files in Java might be tricky, but it is fun enough!");
myWriter.close();
System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
sender.sendMessage("Dein Discord Name Wurde Verifiziert!");
return true;
}
}
How can I get rid of You have no bed or respawn anchor message?
What's wrong with it?
works fine
although usually you might want to save it to your plugins data folder
If i use the command there got nothing in the file it only is printing ingame Dein Discord Name Wurde Verifiziert!
the test.txt is empty
Plugins Folder
But i put it there the plugin should only write in and not create it
Oh i am lost
It works
thanks ^^
Since this is sent by the Minecraft Server and not some plugin or player, your best bet would be Listening to the Packet: PacketPlayOutChat and then if it contains that message, remove that outgoing packet to prevent it being sent
I have fixed with setting 0,0,0 as bedspawn location
ah ok
CommandSender sender;
Player p = (Player) sender;
is p the variable?
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
FileWriter myWriter = new FileWriter("/home/DC-Verify/DC.txt");
Player p = (Player) sender;
myWriter.write("Jemand ist ein Kek z.B. " + p);
myWriter.close();
System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
sender.sendMessage("Dein Discord Name Wurde Verifiziert!");
return true;
}
}
Do note that the cast will fail if it is the console executing the command not the player
Some people might do the following instead
// Check the CommandSender is not the console
if(!(sender instanceof Player)) { return; }
Player p = (Player) sender;
is that right?
I'd imagine home is the name of your plugin data folder?
// This is more reliable if the name of the data folder changes
new FileWriter(this.getDataFolder() + File.separator + "DC-Verify" + File.separator + "DC.txt");
this.getDataFolder() will work in your main class. The class extending JavaPlugin
Player#getName
p.getName()
Adding the player on the end will not print their name
otherwise you will just get the #toString result
what he said
was actually quickly looking to see if the toString() would just print their name and if md_5 override it
Are there any other reasons we want to prevent a console/non player from executing a command,besides some obvious errors it would cause in most use cases?
I'm confused about this part i*f % 1.0f
Isn't the remainder of any number divided by 1 equal to 0?
Edit: Oh sorry I missed that f is a decimal, I got it
its returns the CraftPlayers #toString which is just a JSON object with the players name as val
fairs
not a float
You prevent a console from running a command if the command requires actions of that only a player can provide
an int yes
like interacting with blocks, opening GUI's, hitting mobs etc.
we don't want to prevent the console to execute commands. we want to avoid the errors that can come from a "player-only" command
I already know that,but anything besides that
^
Security etc?
no
just the fact that the console isnt a player
and cant have a location, cant get opened an inventory
etc
Console is above op
but if you really wanted to, for security reasons you could prevent the console executing certain commands
if say, you wanted to mandate that a command be executed by a player on the server even though it may not require it from a technical point of view
?paste
I think I'm tripping, can someone tell me if this task should legitimately be using a lot of power in timings?
https://paste.md-5.net/dulimakoba.java
it seems really straightforward
It doesn't technically have to
For instance all you really need is the 3 second delay or x number of seconds as the delay
is it possible to change a players skin without them rejoining the server?
yes
put the code in a runnable?
I know i could go straight to 3 seconds but this notifies people if it gets cancelled while they wait
could notify people via the PlayerMovementEvent
and 3 seconds is a frustrating amount of time to wait for something that was cancelled without you knowing
if they move you can cancel it
I'm fine with a tops 1s delay between notifications for performance reasons but this is using silly amounts of power
how is it even doing that
I want to automaticly update my plugin from spigotmc
A HashMap containing a entries of teleports that are about to happen. When requesting to teleport, you can add a Class containing the source and destination locations of the teleport and the player. Right after adding it, you can create a runnable that after 3 seconds will remove it from the hashmap, check if it's null, and then procceed to teleport of the source location matches the players current location
that way you will not have to deal with cancelling
it gets removed from the map anyway
that's basically what I'm doing but with extra steps
ah
and fewer cancellable abilities
well besides the playermovementevent that seems like an optimal solution for fewer cycles
I mean did you read the class
I can't imagine a task that would use fewer cycles and still notify people of cancellations
Can someone please help me? I want to update my Plugin automaticly. I have code a Downloader so what is the url?
I believe there is something in the TOS about that. Something along the lines of you're not allowed to auto update because of security reasons
which makes sense, you could deploy malicious code to the server through an update
which is why spigot doesn't allow this. Other plugin hosting sites I'm not sure on.
You can still do this though
but you're not going to be able to host the plugin on spigot
also might be possible to update based on a prompt
I did read the class
as long as it requires admin interaction
my implementation would of been to move all the code in the runnable outside of the runnable
since you don't need it in there anyway
But you can check the version:
https://api.spigotmc.org/legacy/update.php?resource=recourcesID
it only ever is used by the runnable, not much of a point in extracting it
I meant from a space complexity standpoint you could have that code in the remove method of the hashmap
1. Someone requests teleport
2. Add a class to a map that holds the source and destination location Map<UUID,TeleportRequest>
3. After adding this class run a new DelayedTask to call a method to handle the removing of the teleport request from the map 3 seconds later
4. When the delayed task calls your remove() method you can grab the TeleportRequest class and run your checks before then deciding to teleport the player or not
This means you never have to mess with cancelling the BukkitRunnable
I mean I would since I am still going to be checking and notifying players if the teleport was cancelled on every second
Looking at your class idk why you're running it every 20 ticks if you wanted to wait 3 seconds
Oh
I see
I don't want people to wait 3 seconds just to let them know it was canceled 0.5 seconds into it
feedback-wise that is terrible
Correct, you can check the version and notify the operator that there is an update
true
Well your best options are what you have now or the movement event
the question I have here is not how to do it differently but rather how is it using so much power
or at least reporting that it is using so much power
hm I wonder
is it because it is passing the same performance impact as the teleport event which is passing the performance impact of all the chunk loads somehow?
that would be the only thing that actually makes sense to me
I guess technically the teleport is in the task
and the teleport causes chunk load
so this is chunk load lag?
lemme look at the code again
"unit-vector" = normalized...?
lol
Not chunk lag
but I do think the fact you're making IO calls each second the teleport counts down might be a factor
Grabbing stuff from the config file every second
to check if a plugin is activated can i just use bukkit.getpluginmanager.getplugin(... != null) ?
instead of grabbing it during server startup and storing it somewhere
Yup, I would think so
As long as the name is correct
which may not be the same the name of the jar
I am almost dead certain that is cached
why would it be cached?
l would like to personally bump this
I'm not seeing any variables for caching
ok so I was right actually regarding the chunk loading
a plugin I was using was adding a 26% overhead to chunk loads
and the teleport event was indirectly reporting it
I disabled the plugin and the exact same code uses ...
actually idk it dropped off the timings
so an external plugin caused it
the code looks fine
a plugin was messing with chunk loading and that was reporting chunk load performance indirectly
so yeah
What is an IPlayer?
it's been a hot minute since I've seriously looked at timings, I need to get into it more
timings is awesome
yeah just been too busy doing a rewrite to look at them, now that the rewrite is done I'm collecting user timings to improve performance
could alternatively run that on another thread
I do hope spigot will get to use timings v2 at some point, though at this stage it's looking unlikely
does it not already?
I(nterface)Player
So.. just Player
its a naming convention for interface and subclass with the same name
unless my memory is actively failing me I am almost dead certain I've gotten a timings v1 report for a pure spigot 1.17.1 server just a couple of days ago
also I went and double checked, yes I am pulling the config values from cached files
not io ops
is ConfigValues a custom class of yours then?
sorry cached configs
that caches
yeah it is one of mine
ah fairs
old system from 2017, legacy garbage at this point
haha
i'm gradually phasing it to cached final values instead
code we wrote a year ago can be considered garbage
a year ago? code from 3 weeks ago is garbage
wanna see my shiny new config system
Haha sure
code one second ago is garbage cries
Code a few nano seconds ago tho
?paste
nah thats alright
it seems fine
...until i compile...
https://paste.md-5.net/qemuximogi.java I ride to config valhalla all shiny and chrome
md 5 secretly collects code in his paste bin and uses it to compile a hung over confused AI
your comments be like
// this is a player
Player player = (Player) sender;
my comments?
dear lord the number of try catches
well considering I'm doing both package and yml file fuckery here I do have to make sure it works
The joke is that some coders believe you should not comment super obvious stuff
though they can probably be condensed a bit
if the code is obvious at face value, don't need no comments
if its not super obvious then commenting helps
Hey, I saw that ppl sometimes serializes stuff (like itemstacks) in base64 instead of using the one provided, is this a better way to do it ?
like for some complicated math function
and thats totally right
you should also name your classes, methods and variables so you dont even have to describe it
because its doing it on theirselfs just by the names
all of the comments in that thing I sent are reminders for things I actually forgot and messed up while I was working on it
wait cant i also use ispluginenabled?
return Bukkit.getServer().getPluginManager().isPluginEnabled("Vault");
for what
what are you doing
registering a vault listener if vault is activated
anyone know how to fill a map without travelling using a custom MapRenderer
Not sure why they do that, I serialise as byte array and have zero issues
Load all the chunks required for the map to render.
Depending on the map scale, grab the colour of each block.
Use MapCanvas to set each pixel of the map
Yes
what would be the best way to give a player rewards for their onlinetime
like every hour they get some coins
but i have to figure out a way to check their time
Create a bukkit delayed task when they join and then store it in a map. Make the task run after an hour
then you don't have to be constantly checking
cache it and if they leave write it to a file
in the event they leave:
- Create a Date object and get the time value (should be a long type)
- When they come back on you can do some math and create a new delayed task with the time remaining
why this send mi message two times?
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent e) {
Player p = e.getPlayer();
if (e.getRightClicked() instanceof ItemFrame) {
p.sendMessage("//");
}
}```
for each hand once
eh, so how can i do it only for right click? (right hand)
lemme figure it out
^
Hi
i just made that hello plugin which ig every new plugin maker makes at first
im having trouble testing it tho
u see, the problem is that i play the free version of minecraft
from
Buy the game
We dont support piracy
we are just pirates
can anyone help me with this, i am trying to make database but it won't connect due to password, it gives me an invalid configuration exception https://pastebin.com/QYTAeFL4 i don't know why i just know its because of the password, how could i fix this?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
just fix it
since you didnt provide code
i cant say more
password: "C6BEu(}p^\<sHz2A" that your password?
yes
nice
so? its localhost
idc i will hack your localhost
kk
at com.astral.roleplay.managers.ConfigManager.load(ConfigManager.java:142) ~[AstralRolePlayCore-1.0-SNAPSHOT.jar:?]
at com.astral.roleplay.managers.ConfigManager.reload(ConfigManager.java:96) ~[AstralRolePlayCore-1.0-SNAPSHOT.jar:?]
at com.astral.roleplay.managers.ConfigManager.create(ConfigManager.java:57) ~[AstralRolePlayCore-1.0-SNAPSHOT.jar:?]
at com.astral.roleplay.managers.ConfigManager.create(ConfigManager.java:68) ~[AstralRolePlayCore-1.0-SNAPSHOT.jar:?]
at com.astral.roleplay.managers.ConfigProcessor.<init>(ConfigProcessor.java:11) ~[AstralRolePlayCore-1.0-SNAPSHOT.jar:?]
at com.astral.roleplay.Roleplay.<init>(Roleplay.java:28) ~[AstralRolePlayCore-1.0-SNAPSHOT.jar:?]
^ doesnt seem like an issue with yaml
Does anyone know how to use ItemMeta.addEnchantments()
I'm trying to add multiple enchants with just one line
meta.addEnchant(Enchantment.ARROW_DAMAGE,2,false);
is there a way to let my command override the essentials one?
I meant multiple, im using meta.addEnchants
it only happens with that type of password that yaml cant parse
o ok
this is a new stacktrace, https://hastebin.com/irumiqohih.properties
MySQL class: https://paste.md-5.net/
https://paste.md-5.net/ nice
your configprocessor and configmanager would be important
since the error is coming from there
stack.addEnchantments(new HashMap<Enchantment,Integer>() {{
put(Enchantment.DAMAGE_ALL,2);
put(Enchantment.ARROW_DAMAGE,2);
}});
informative: https://stackoverflow.com/questions/38272137/yaml-parser-parsererror-while-parsing-a-block-mapping @kind coral
have your plugin initialise after essentials, your command will then overwrite the default in the command map
oh oky
The command map is full of commands without a fall back prefix, and commands with their fall back prefixes.
for example essentials will add
eco
essentials:eco
heres my configmanager https://hastebin.com/comobatato.kotlin
and configprocessor:
https://hastebin.com/gisuwosuga.php
how can i change itemstack durability? i use normal method setDurability() but it is deprecated and it doesn't work for me
thx
ItemMeta meta = stack.getItemMeta();
((Damageable) meta).setDamage(durability);
Bear in mind this doesn't "set" the durability, this sets the amount of damage that will be taken away from the items total durability
weird, I know
If you want a "Set Durability" method, you can use mine
/**
* Sets the durability of the item
*
* <p>Durability values that go beyond the materials maximum will be set
* to the materials maximum and values that go below 1 are set to 1.
* @param dura The new durability of the item
* @return ItemBuilder
*/
public void setDurability(int dura)
{
if(stack.getItemMeta() instanceof Damageable)
{
ItemMeta meta = stack.getItemMeta();
int durability = stack.getType().getMaxDurability();
if(dura > 0 && dura <= stack.getType().getMaxDurability())
{
durability = stack.getType().getMaxDurability() - dura;
}
else if(dura <= 0)
{
durability = stack.getType().getMaxDurability() - 1;
}
else if(dura > stack.getType().getMaxDurability())
{
durability = 0;
}
((Damageable) meta).setDamage(durability);
stack.setItemMeta(meta);
}
}
imagine cloning item meta twice 😢
?
is the plugin called Essentials or EssentialsX?
stack.getItemMeta
how can i get \< without parsing it ( YAML )
getItemMeta returns a copy
imagine caring about pre optimisation
I mean it is pretty heavy sometimes lol
How can I limit drops? Like if there are already 40 iron ingots, I will stop spawning more of them
@wraith apex how do I get the byte of a specific color in MapCanvas#setPixel(int, int, byte)?
Fair enough, it's cloned unfortunately. However, unless I'm calling that method every tick for some reason, It's not going to show much change in performance
probably not xD
That, I actually don't know. I couldn't find a byte code for colour on either Materials or Blocks. So for now, I'd probably go grab a map, render one normally in-game by running or flying around and then grabbing the map in code using the MapCanvas and grabbing the byte colour codes off of it to see what they are
thanks for the tip tho :p
ty
The reason is if methods change or new variables are introduced into ItemStack, base64 don't care
it will turn everything into a neat string
The two ints are for the X and Y coordinates of the canvas and the byte is the color from the map palette
I also believe that the inbuilt one doesn't save a few other things
Because Map colors are limited unfortunately to a byte
And are stupid and don’t support full RGB
except the MapPalette is deprecated?
ah found the list
@hoary knoll
i was just looking at that but they are all deprecated
ok, so how can i get current item durability?
((Damageable) meta).getDamage();
?jd
Honestly, for durability I think I'll spoonfeed. The docs really don't help with how tf you get durability the new way
the docs lack examples of use
they do
just read the @deprecated comment
they directly lead to Damageable#getDamage
yeah, what can you misunderstand?
Damageable.setDamage
"is now a part of Damagable"
where and how do you get an instance of Damageable
is what I would of loved to know a few years ago
Yeah I eventually worked that out
I know you can cast it, my point is for people who don't have the book of knowledge on spigot, an example would of been nice
Also pls javadocs in the api
literally just ((Damageable) meta).setDamage(int); would of been fine
It's in the org.bukkit.inventory.meta containing only ItemMeta interfaces
I haven't been following the convo
Might be hard to spot though
Is there any reason the docs aren't available locally
Instead gotta look them up online
There is a command for BuildTools to generate docs
Oh that sounds useful
If I have a location with yaw and pitch, how would I go about shifting that location forwards, relative to the pitch and yaw?
Multiply the vector
You know, a lot of Spigot API is deprecated
But you still have to/can use it sometimes
Like the scheduler
If you're using this to check blocks use rayTrace methods
It just means they are working on a replacement some time in the future
(Or entities)
That defeats the point of something being deprecated
I've been playing around with vectors a lot, but I can't quite understand how it works... what do you mean by multiply the vector?
Don’t ask me
Ask Spigot
I personally think they should warn their users in a different way instead of labeling it directly as @Deprecated
@Unsupported
Such as the @Beta annotation Gson uses but for different manner
?
Yeah
for example, if I have new Location(world, 0, 100, 0, 45, 45), and I add a vector to it, what values would I put into the vector :P
x, y, and z
but, xyz of what?
I simply want to shift the location 2 blocks forward in the direction it is facing
so, in the end I am trying to get the xyz of the new location... but how do I get the new location :P
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I know there is some annoying math shiz
Read this it will help with what you need
perfect thanks, will read that rn
Anyway use Location#getDirection multiply that with how far you want to go and then turn it back in to a location
Oh and understanding that math will be helpful in math lessons at school
rand.nextInt only returns whole numbers right
correct
ok ty
yes because it's an integer and not a double 😳
thanks guys
which event is fired when player pickup item from itemframe?
You mean the right click so that the item drops ?
probably playerinteractevent 🤷
Yeah
or PlayerInteractEntityEvent
then check if the entity interacted with is an itemframe then u should be golden
ok, thx, and how can i destroy item frame? (kill it)
event.clickedEntity.remove()
i have to stagger my enchants by one, like if i want knockback 5 i do
m.addEnchant(Enchantment.KNOCKBACK, 4, true);
right?
this is how i get the total experience of a player, right?
int xp = player.getExpToLevel()
but how do i set that exp back to the player? player.setTotalExperience(xp) doesnt work
I'm not certain but I'm pretty sure you put the level as it's displayed
So you start at 1
Where and how would you guys recommend storing NamespacedKeys
They need the plugin instance, which makes it a little awkward, so what should I do to make them cleanly accessible
I usually store NamespacedKeys as a constant and use a main instance getter to initialize it
I either throw them in the main class or in a class dedicated to storing keys
I usually have an enum indexing all my namespaced keys and, onEnable, create one for each of the Enum.values() and throw those into an enum map
pass that (wrapped in a class) around
I want to avoid passing around
or you can do it like mr. fancy here
That isn’t Mr. Fancy, that is the proper way to do it lol
Yeah it sounds proper
But I want to avoid passing around
Since the thing that needs these keys is exposed as API, and I don't want to put that burden on my clients
I made a static onEnable(Plugin) in the place that needs it and initialized the keys in that place. I believe it's the best I could do
If you want to just use static, you could very much just statically define them in, lets say an interface, and call your static plugin instance provider
interface Keys {
NamespacedKey KEY_ONE = new NamespacedKey(JavaPlugin.getPlugin(SpigotTestsuite.class), "key-one");
}
somewhere along those lines
Doesn't need to be an interface then
I mean, clean way to ensure no one creates dumb instances or does other useless stuff with it
Private ctor
also removes the need for public static final
True
Is there a proper way to cancel EntityTargetLivingEntity event? Even if i cancel it - it keeps processing after a few retries
Keep cancelling it
when i do /home (my own command) and put a space i get a nullptr for the tabcomplete for essentials :/
it has the same command
mmmh good plan
Oh and uh you could probably just override things by setting your own tab completer
i have one
what's the best way to get the minecraft version, such as 1.17 or 1.17.1 ?
I saw calling Bukkit.getServer().getBukkitVersion() has it but other info as well. Is this the most reliable way?
Then it should override the tab complete which means the nullpointer is from your plugin?
Yeah use that and filter the string out
Let me get the example from CombatLogX...
Send error
There is net.minecraft.SharedConstants VERSION_STRING in NMS
?paste
Hey, does anyone have a simple video / tutorial on how to use AnvilGUI ?
I've read the github tutorial from WesJD (his class) but i dont understand anything through builders and the use of maven
If anyone has an example of code to retrieve anvil strings or a simple tutorial or video that'll be very helpful 🙂
What's the isAuthorized method
it checks permission
this is my tabcomplete i dont think there's something wrong with it
@Override
protected List<String> tabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
arguments.add("set");
arguments.add("remove");
arguments.add("list");
arguments.add("tp");
arguments.add("help");
return StringUtil.copyPartialMatches(args[0], arguments, new ArrayList<>());
}
return null;
}
Youre never returning any sort of list
that
i'll try
arguments = Array.asList("set", "remove", etc);
uhh by empty list you did mean new arraylist or something no?
Make the arguments list final and immutable if its not a dynamic completion.
hi
Hi
hi
Hi
i'm a newby in java development and I have a bug, I search on forum but I don't find how to fix the issue
when i create my main java class, I want to import javaplugin, but when I import it, it doesn't work
the tabcomplete is done it the command class
so i assume its dynamic
what does not work?
The type org.bukkit.plugin.java.JavaPlugin is not accessible
Did you add spigot as a dependency?
what are you trying
yes
I'd say you didn't
it has to look like this
yes
Are you using Maven or Gradle?
can your code maybe that would be easier
Code isn't the problem
i dunno
Okay how are you building the plugin
I don't know
How did you get that error
how do you export your plugin in eclipse.
and in which way do i make it immutable?
ImmutableList.of(my original list) or something
List.of(vararg)
ImmutableList.of(vararg)
ImmutableList.copyOf(collection)
actually Collections.unmodifiableList(list) is a thing also
happy bday 😄
thanks
😄
wew there's the stacktrace again
this is stupid why does essentials makes an tabcomplete whilst the command is disabled
every tabcomplete from my side return a new arraylist instead of null
Send stacktrace
How can I get a download link for the latest version of a plugin
I can only get a link for a specific version
is there a good way to Location#getBlock() async
on the spigot/ bukkit site
can someone send me some tutorials about npcs?
Utils line 30. What's that
What are you trying to do?
npc
CitizensAPI?
That's what I hear should be used
return p.hasPermission(prefix + permission.toLowerCase()) || p.hasPermission(prefix + "admin");
```prefix is the name of my plugin with a dot after it
Not really just make sure chunk is loaded. If you're looping a lot of blocks use a ChunkSnapshot
One of those things is null
Fix it
the second thing it says is basecommand: 46
thats this
if (!Utils.isAuthorized(p, cmd.getPermission())) {
the cmd.getPermission() comes from the plugin.yml permission string and i'm 100% sure i've set that
Run some null checks
null checks are for losers
i think youre trying to get a permission without any arguments here
you are a loser
Which causes it to return null
show your plugin.yml too then
you need a seperate permissions: thing
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Permissions block
https://paste.md-5.net/soyeruqati.http here we go
ah ok
running a null test on that now
smh does not even work
i did a null check in the tabcomplete and it isnt executed :/
Optional#ifPresent 😄
I like this man ^^^
Can someone help me to increase the size of the editor? when formatting it does not pass the line.
how do I play a sound effect to all players?
Bukkit#getOnlinePlayers().foreach(ps -> {
ps.playsound(ps.getlocation, Sound.ENTITY_ITEM_PICKUP, 1.0F, 1.0F);
});
thanks
why r you using
eclipse
yes
its really bad
its fine
and I want you to drop this debate right now, thanks 😄
im trying to help him lol
Yelling at him that he's using the wrong IDE is everything but helpful
"Cannot resolve method 'foreach' in 'Collection'"
forEach
?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.
sorry I just wasn't sure
yeah lowerCamelCase
just camel case
its lowerCamelCase tho
really weird but .clone() is a method right
yeah
pretty sure OfflinePlayer does not extend Cloneable
right
yeah
im trying to make a plugin where if an item is in your inventory it becomes transparent but i have no clue what im actually doing
Packets
if you mean it disappears
your question isnt clear
Where is the code, when I install BuildTool(1.16.5), that can I import for my plugin proyekt?
Are you using Maven or Gradle?
just transparent. if you would hover over the item then it still would be there and usable
I installed BuildTool and then my version(1.16.5). Then I have a file. Must I only import it?
That is impossible
If you're not using Maven or Gradle just import the jar
you want them to look like NOTHING
or
just a bit transparent
if nothing (So it looks like an empty slot) it is possible with packets
but i dont know anything about packets so i cant help you
aight thanks tho
Please tell me how to hide the items in my hand from players other than myself .
?paste
You will have to modify packets. I recommend using Protocollib and PacketWrapper
https://paste.md-5.net/teyepowoze.java
this is my code and this is the error i get everytime I hit a endercrystal
https://paste.md-5.net/yofikidaxu.cs
I swear I called all possible null errors
before that I had living entity and it gave em this
CraftEnderCrystal cannot be cast to org.bukkit.entity.LivingEntity
how can I cancel all running tasks for a player?
Quick question: When you make a shaped recipe, how can you make it so that you need several items on one slot for the recipe? e.g. you make a recipe for which you need 10 earth blocks. one earth block must be on each crafting slot and 2 earth blocks must be on a certain slot?
For a player? You would have to keep track of them... for a plugin Bukkit.cancelTasks(Plugin)
You can't
I mean you can
with a event
how to change ladder facing?
ladder.setFacingDirection(BlockFace.DIRECTION);
replace DIRECTION with WEST or EAST or whatever
with which event?
PreCraftItemEvent or smth similar
ok thank you
declaration: package: org.bukkit.material, interface: Directional
cast to Directional maybe
I have another question: is it possible to use self-made item stacks as an ingredient in shapedrecipes?
help
hey, anyone knows in java how to wait for a string to be set
i have a playerchatevent, and i want to set it to String message (public string) then retrieve it in another, but in this other method, how could i wait for the string to be completed
player sends a message, i retrieve this message in a public string, and in another method, wait for the string to be not null
Two plugins have been introduced
Is there a site that can be used as a reference?
Read the source code of PacketWrapper and Protocollibs wiki has some info on how to read and modify the packets
Quick question: How can one, when setting stairs (through the plugin), set them in a certain direction?
I have already tried with the following code. Unfortunately it did not work:
event.getBlockPlaced().getLocation().add(-1, 4, 4).getBlock().setType(Material.BRICK_STAIRS);
event.getBlockPlaced().getLocation().add(1, 4, 4).getBlock().setType(Material.BRICK_STAIRS);
Block stair1 = player.getWorld().getBlockAt(event.getBlockPlaced().getLocation().add(-1, 4, 4));
BlockData stair1Data = stair1.getBlockData();
MultipleFacing facing1 = (MultipleFacing) stair1Data;
facing1.setFace(BlockFace.EAST, true);
stair1.setBlockData(stair1Data);
Block stair2 = player.getWorld().getBlockAt(event.getBlockPlaced().getLocation().add(1, 4, 4));
BlockData stair2Data = stair2.getBlockData();
MultipleFacing facing2 = (MultipleFacing) stair2Data;
facing2.setFace(BlockFace.NORTH, true);
stair2.setBlockData(stair2Data);
Can anyone help me with this by any chance?
How can I make a location face another location?
So basically use loc2.toVector().subtract(loc1.toVector()).toLocation(<stuff>)
Ah perfect, ty!
bump ? i guess
[Server] INFO Caused by: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_16_R3.block.impl.CraftLadder cannot be cast to class org.bukkit.block.data.MultipleFacing (org.bukkit.craftbukkit.v1_16_R3.block.impl.CraftLadder and org.bukkit.block.data.MultipleFacing are in unnamed module of loader 'app')
help?...
Material ladder = Material.LADDER;
world.getBlockAt(210 ,46 ,-363).setType(ladder);
Block ladder2 = world.getBlockAt(210 ,46 ,-363);
BlockData ladder2Data = ladder2.getBlockData();
MultipleFacing facing2 = (MultipleFacing) ladder2Data;
facing2.setFace(BlockFace.EAST, true);
ladder2.setBlockData(ladder2Data);```
you can't cast org.bukkit.craftbukkit.v1_16_R3.block.impl.CraftLadder to org.bukkit.block.data.MultipleFacing
what?
can you
maybe explain it
so dumb people like me can understand that?
MultipleFacing facing2 = (MultipleFacing) ladder2Data;
Only Fence, Fire, GlassPane, GlowLichen, Tripwire use that interface
you can't do that
Use the Directional interface
in method1, i need to return a string (event.getMessage from playerchatevent), this string is public, so i can retrieve it in method2, problem is i need, in this method2, to wait until the string isnt null (wait until the string is set)
public void onChat(PlayerChatEvent event) {
Player player = event.getPlayer();
String message = event.getMessage();
if(player.hasPotionEffect(PotionEffectType.WEAKNESS)) {
event.setCancelled(true);
chat = message;
}
}```
```public String chat;```
```player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 200, 1, false, false, false));
if(chat == null) Bukkit.broadcastMessage("null");
Bukkit.broadcastMessage(chat);
cooldowns.put(player.getName(), System.currentTimeMillis());```
use a consumer as a callback
consumer ?
hashmaps ?
i set a callback function, and in player chat event i fire this function ?
a Consumer is a functional interface which does take a single input argument and returns nothing.
later it accepts the given code on that argument
https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html
so you would have a consumer, which you do instantiate in your second method and accept in your first one
Is there a Player take damage event?
EntityDamageEvent
Thanks!
nvm there is no PlayerDamageEvent. you will have to go over the EntityDamageEvent
Ok
alrighty thanks
How do I summon a primed peace of TnT at the player location?
World#spawn(location, TNTPrimed.class)
Like this?
not at all lol
Oh
I would recommend learning Java
I am taking a class right now
You get the world object from the event I believe, or from the player
?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.
yep
event.getPlayer().getWorld()
the # is a part of the javadocs formatting.
A # means that the method is part of a certain class
object instance ^
yeah
might be static method, no?
wrong
?
they're cool
static is good
my favorite keyword
in several designpatterns you'll find statics.
bro nobody is talking about static
the topic is javadocs
String could literally be used for anything
and a # for a method
ya
oh sorry didn't knew you were talking to yourself
talking to that guy who actually typed in Class#method
How do I summon the TnT. Maybe that is a better question
and i am talking to the guy who gives the guy who actually typed in Class#method false inputs
:(
I'd like to know how to spawn primed tnt when a dispenser is activated by redstone. Please help! Thanks!
at net.squidstudios.mfhoppers.tasks.TaskManager.runItemsTask(TaskManager.java:584)
at net.squidstudios.mfhoppers.tasks.TaskManager$3.run(TaskManager.java:85)
at org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftTask.run(CraftTask.java:101)
at org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57)
at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)```
This plugin throws this error when it tries to pick up items from the ground. I'm trying to update it to 1.17... Something is changed in 1.17?
Here is the code: https://pastebin.com/zv0FP5GL
wwwhat? you just jumped in into the topic
anyways
JavaDoc: Class#anyMethod (the way its shown)
Java: ObjectInstance#method (for help clarification reasons)
and what about class methods?
that was the question
what is line 112 in EG and what does the TaskManager do?
i love you
Here is the whole code: https://pastebin.com/A9jiuyy4 (TaskManager)
I don't know what it does because it's not my plugin :/ I just want to update to 1.17
We need to see EntitiesGatherer line 112
I have a custom inventory and I would like to disable that some can put items into it but allow to take from it. I tried some articles from the forums but I didnt got it to work
You probably have to add 1.17 support in the OSimpleReflection class
Check what's on their Cursor, if it's nothing then they're taking, if it has something then cancel the event
which event are you reffering to?
how to access cursor
InventoryClickEvent#getCursor
if (event.getCursor() != null) {
event.setCancelled(true);
}
probably like that? Like now I can not take from the inventory anmore :D
yea thats not really fixing it
I introduced ```java
if (event.getCurrentItem() != null) { ````
before that, did not help
I assume I avoid some null pointer exception with that but I am still doing something wrong here
if(event.getCursor() == null || event.getCursor().getType() == Material.AIR) then cancel
Can you put them in
nope I can not get item to cursor now
Well you should only do this check if they click on the top inventory
And I think I sent the if statement backwards, invert it and it should work the other way around. (So allow items to be taken but not to be placed)
Yea but I guess I tried the inverted before here?
Because the inverted would be != null
Well make sure it's also not air
yea
So add && event.getCursor().getType() != Material.AIR
okay
well thats interesting
Now I can not predict if I can put into the invetory.
Sometimes its blocking sometimes it allows it
ahh i have some questions about working with YML files if anyone here knows a bit about them 🥲 can do it in dms so it doesn't get in the way of the current conversation
+1, doesnt switch the convo to whatever he likes selfishly, good person
Like if I try some slots to put it in, he blocks it and cancel the event successfully, but then I try a different slot and it works :D
sometimes works first try :D
dropping with draging not affected so far
Is it possible du give the respawn anchor the "portal" effect in the middle without giving him glowstone?
I kinda need to validate after a player put an itemstack into an inventory if that was a put into the custom inventory or if it was the player inventory, but I dont know how to do that
if that happend the item should be thrown out on the ground or sth.
Because the cursor only descirbes if someone got soemthing
@EventHandler
public void onInventoryDrag(InventoryDragEvent e) {
if (e.getInventory() != myInv) {
return;
}
e.setCancelled(true);
}
@astral burrow
this blocks anyone from putting an item into your inventory
but if you want the inventory to not be taken from/ put stuff in at all, listen to the inventoryclickevent
okay, can descirbe the myInv please? Like I think it should be the customItemInventory (it looks like if you open a chest) but I am not sure how you mean it here

uhh can not upload a screenshot explaining.
Right so you can see I have the custom inventory "Rest in Peace Meister". I assume that in your code in line 3 you are reffering with "my Inv" to this inventory I have here. But I am not so sure how to give it there
just use your inventory
hey, i tried making consumer callbacks and it outputs me error on method onClick
onChat((chat) -> {
msg = chat;
})
The target type of this expression must be a functional interface
and my initialized callback method :
@EventHandler
public void onChat(PlayerChatEvent event, Consumer<String> callback) {
Player player = event.getPlayer();
String message = event.getMessage();
if(player.hasPotionEffect(PotionEffectType.WEAKNESS)) {
event.setCancelled(true);
chat = message;
callback.accept(chat);
}
}
i tried following this tutorial
https://medium.com/@pra4mesh/callback-function-in-java-20fa48b27797
but without barely understanding anything
if someone could help me understand this, it'd be awesome
nb : underlined = errors on eclipse ide
Asking about your attempted solution rather than your actual problem
oh
maybe I am stupid but I dont know how
in method onChat, i need to return a string (event.getMessage from playerchatevent), this string is public, so i can retrieve it in onChat method. problem is i need, in this onChat method, to wait until the string isnt null (wait until the string is set) and i tried callbacks
What’s the meaning of that callback
is there any spigot 1.8 plugins to save and view players ips
Ur event method is literally a callback already
public class MyInventory implements Listener {
private Inventory inventory = null;
public void register(Plugin myPlugin) {
Bukkit.getPluginManager().registerEvents(this, myPlugin);
}
public Inventory getInventory() {
return inventory;
}
public void makeInventory() {
// Create your inventory here.
inventory = Bukkit.createInventory(null, 3 * 9, "My Inventory");
}
@EventHandler
public void onClick(InventoryClickEvent event) {
if (event.getInventory() != inventory || event.getClickedInventory() != inventory) {
return;
}
// Prevent clicking items.
event.setCancelled(true);
}
}
@astral burrow
use this example
@ivory sleet > example
Fair
so im printing my map and this is what its giving me ```{weeklyKit=0}
[22:26:31 INFO]: {weeklyKit=0, pvpKit=0}
[22:26:31 INFO]: {dailyKit=0, weeklyKit=0, pvpKit=0}I have a feeling that this is doing it but im not to sure because none of the kits were chosen so they shouldn't even be in the mapjava
public long getTime(IPlayer iPlayer, String cooldown) {
PlayerData data = playerMap.get(iPlayer.getUuid());
System.out.println(data.cooldownMap);
if (data.cooldownMap.get(cooldown) == null) {
data.addCooldown(cooldown, 0L);
}
return data.cooldownMap.get(cooldown);
}
Hi guys, im trying to make an "API" for my plugin, i was thinking of creating addons for it and i have an abstract class that "almost" does the job, the only thing is that i need to reload addons via a command, just one ( by name ) or every addon
I just need:
• The name of the items added by the addon
• The name of the addon
• The items ofc
• And the possibilty to reload one or all the addons as previously described
I currently have this class which only provides me the items and their names without telling me which addon added them.
https://paste.md-5.net/ihuyuyupen.java
Each addon has its own jar?
I like the idea of independent deployment 🙂
wdym?
if i were you, i'd handle everything inside the core jar
oh no
oh yeah yeah, but the addons must be external
https://github.com/ImajinDevon/GalaxyShop/blob/master/src/main/java/me/imaginedev/galaxyshop/api/GalaxyShopAPI.java
take a look here
they kinda need to be "toggleable"
its just a singleton which wraps all instances together
Make a KeyedItemStack maybe which encapsulates an addon
Thank you think I understand what you are telling now. The thing is it is a bit more complex, I need to take more investigation here.
And then the abstract method getItem has to return the KeyedItemStack
what is a Keyeditemstack?
@Getter
@AllArgsConstructor
public class PluginItemStack {
private final ItemStack item;
private final Plugin plugin;
}
@kind coral this is what i do
Lombok is a fucking cult I swear lol
then you can have a map running
so like making a class inside the addon and placing it inside the core map
this class would be inside the core plugin's api package
then your core plugin can rely on that
yeah ofc
and then your addon would make their own pluginItemstack
like im working so hard on this ahaha
lombok is fine
i dont like that lombok is not providing me with the argumets a construtor takes if I call a constructor from somewhere else
so you guys think i should just make a normal class ( that ofc contains the plugin that added the items and the items themselves ) and then get the core plugin instance and place it inside the map?
@ivory sleet flame it
wat
how do i learn java
Hmm, I’ll pass for now
btw today's error was not because of the plugin but because i was using "" instead of '
i wanna make minecraft but plugins

he's a strong advocate of multi module projects
@Data
public class MyData {
private final String myString;
private final Plugin registeredPlugin;
}
public class MyDataManager {
private final Set<MyData> myDatas = new HashSet<>();
// Handle MyData here
}
public class MyPluginAPI {
private static MyPluginAPI instance;
private final MyDataManager manager;
public MyPluginAPI(MyDataManager manager) {
this.manager = manager;
instance = this;
}
public MyDataManager getManager() {
return manager;
}
public static MyPluginAPI getInstance() {
return instance;
}
}
@kind coral
well kinda
then your addons could just
MyPluginAPI.getInstance().getManager().addData(new MyData(myString, this));
@kind coral
Gradle + multiproject + no maven + Guice + enterprise 😌 (+ no Lombok ofc)
rather do that than have a getter in my main class
you could use an interface as a service with static methods to manage it
but i am not saying anything
u like lombok?
public class Main {
private static void test = true;
}```
much rather prefer the singleton
Hope you’re joking with me now
singleton bad bad antipattern
I almost flamed Spleed lol
Singleton isn’t always an anti pattern but definitely used erroneously very often in spigot plugins for some reason
i like lombok ):
oh sorry missed that point was trying to fix my code here
lombok is nice
Bump it captain sry
in spigot it totally is
Why tf is this giving me an out of bounds warning in onCommand
if (args[1] == null)
because args[1] doesnt exist
args.length
And then the fact that spigot has singletons for plugin instances already
and anywhere other too. ofc., in some cases it has its advantages but you should always prefer DI
i hate using asnyc
instead of mystring i would put the itemstack right?
Shouldn't null account for if it doesn't exist?
string and itemstack actually
customize it to your need
yeah
If I use lombok to create constructor its not providing me the argument names when I create an instance. I NEED to go every time to check the order. So anoying
check if the length is what you need
DI you say? Just make everything global 🤡
java is picky, everything is an exception if you do it wrong
what?
maybe don't do that if you don't like it
args.lentgh == 2
just have everything in one class tho?
DI? just static void everything
facts
yea but using @getter and @setter is the point of using lombok or for what else do u use it?
public static Object for the win
Then it’s basically global
ffs Java
also idk what you're on about because i can use create constructors with it and get the argument names
🤷
no. it would be class internally
It’s global in the application because that class would be the highest scope
Since there would be no dependencies
technically not global
Depends on pov
Still happens
yea but like if I do that I can forget about lombok right?
?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.
Or just not use Lombok maybe :0
for absolutely no reason
i dont like having infinite getters and setters and im lazy so
anyone knows how can i set a BukkitScheduler that waits to be fired with runTask ?
A bukkit task i put somewhere in my code (a runnable) that gets fired with a command ?
Lombok lowkey fucks encapsulation of state but I guess it’s effective in source
whom are you reffering to here?
The person I replied to.
?

Elaborate
man sorry I am tired. worked for 6h on this.
6h on what
this
i hate you
I set Bukkit.getScheduler() somewhere in my code that gets fired with Bukkit.getScheduler().runTask(taskid);
wanna know how I like to handle commands now?
/command argument1="testing" argument2="testingasdaf"
because fuck anything else
On my plugin I am trying to develop
hi jochyoua
is it Bukkit.getScheduler().createTask ?
remember me?
no i don't
I remember you! - Jochyoua
😦
Oh nvm
i think we used to be friends
who are you

