#help-development
1 messages Ā· Page 61 of 1
shade spigot instead š¤”
if your going to shade LP just shade spigot tbh might as well throw it all int here
Shade JRE
I'll shade your mum
0 bytes
oh shit
what the actual
How can I make a worldedit BaseBlock from a Bukkit Block?
I've tried:
editSession.setBlocks(selection, new BaseBlock(trailBlock.getState()));
``` but that constructor is protected
BukkitAdapter
Oh okay let me see
How can I retrieve the permission node of a command from another plugin?
Or at least test if a player has permission to that command
thanks, this seems to work java editSession.setBlocks(selection, BukkitAdapter.asBlockState(new ItemStack(trailMaterial, 1)));
I am registering aliases for main command so user can change it to what ever they want in config.yml
aliases are registered you can type them in they work
but
you can't tab complete them like when you type / PressTab
So what would be solution is there some other map which contains are command names when u press tab
On normal restart of server I use same method to register aliases from my config file and then they you can tab them
so am I missing some thing
on my plugin reload
code
if you change teh command map be sure to update all online players
somethign like Player#updateCommands()
ArrayList<String> lore_sila = new ArrayList<>();
lore_sila.add(ChatColor.translateAlternateColorCodes('&', "&7Daje efekt sily"));
lore_sila.add(ChatColor.translateAlternateColorCodes('&', "&2Cena w Blokach Emeraldow: &a") + ChatColor.translateAlternateColorCodes('&', instance.getConfig().getInt("cenasila")));```
so basically since the arraylist is made of strings i cannot use `config.getInt()` even though the path in the config has to be an int. I have tried putting `instance.getConfig....` inside of toString() or adding toString at the end of it, but it doesnt work, how would i transfer it into a string?
- What does the arraylist have to do with you not being able to call getInt() on a config?
- The path in a config does not have to be an int. That would be ridiculous
- "adding toString at the end of it" at the end of what?
- "how would i transfer it into a string" transfer what into a String.
You are speaking gibberish
dfsgdfg?
- the arraylist is ArrayList<String> so i cannot put an int inside
- well if i want to make a price for something and put it inside of an item lore how would i do that without an int?
- almost every ) at the end of the third line except for the last one cause that would make no sense
- instance.getconfig.getint
You mean this line?
ChatColor.translateAlternateColorCodes('&', instance.getConfig().getInt("cenasila")));
Just use one of
ChatColor.translateAlternateColorCodes('&', "" + instance.getConfig().getInt("cenasila")));
or
ChatColor.translateAlternateColorCodes('&', String.valueOf(instance.getConfig().getInt("cenasila"))));
But then translating the color makes no sense because an int never has any color.
So you can simply do
"" + instance.getConfig().getInt("cenasila");
Or
String.valueOf(instance.getConfig().getInt("cenasila"));
How can I play an evoker's spellcasting animation?
good to know
when i set the inventory if a player and then listen for the inventory click event, can i then just compare the two inventory objects, or is there some other way to compare them
How Can I create different inventories per world?
(this was stupid)
That didn't help still player can't tab new aliases?
Yeah. Most def. dont do that. Unless this was a joke...
You need to serialize inventories and store them mapped to a world.
So each player has a Map<UUID, ItemStack[]> which is a simple mapping of the worlds UUID and the
inventory contents. When a player joins, you load the map and if he changes a world you first save the current content
and then load the corresponding content for the target world.
Anyone know exactly how Player#swingOffhand works?
Makes this entity swing their off hand. This method does nothing if this entity does not have an animation for swinging their off hand.```
Does this mean there is no punch animation for every item?
im trying to make them "attack" with a piece of paper
but its probably from LivingEntity
a Class thats not in Player
doesnt seem to swing a sword either
I have an array of locations that completes to a polygonal outline, how can I flood fill with blocks inside the outline? Is there a world edit api for this or how can I do it manually?
Just do 3 nested for loops over x y and z
Big areas will lag or even crash the server
For this you can do
?workdistro
How to use a String in minimessages hover? "rohlik" is a name of the string
That too
oh i forgot String#replace
thanks
huh
Map only has the forEach(BiConsumer) method
or do i need to define it as a hashmap?
or you do skills.entrySet(). Then you can use a for loop.
no
ah weird
Postgres has that too
Well either on conflict or on duplicate key do update
this will work ig
idk i did some research on stackoverflow but ye... stackoverflow....
mm
replace does an delete and insert so ig on conflict is better than
Player#hasPlayedBefore
i think it uses uuid cache
It uses the playerdata file
š
lol
- bungeecord api
- Burgerking foot letuce
whyythe armor stand is dont spawning ignited or with items on hand?
Im new to spigot development, and im following a tutorial I linked. https://www.youtube.com/watch?v=spggI5Dmfp0&t=321s
When I get to 1:48 in the video, it has you import the event. For him it worked immediately first try, but for me it's an error. Do i have to import it another way or something?
Love the video or need more help...or maybe both?
š¬Join us on Discord: http://discord.gg/invite/fw5cKM3
Thank you for tuning in to this episode of TheSourceCode! ā¤ļø
If you enjoyed this video make sure to show your support by liking , commenting your thoughts, and sharing for all your friends to see and learn!
All code is available on Github:
...
how do I get all potion effects without hardocidng it
registerEvents takes 2 arguments
PotionEffectType#values
ty
There are literally billions of possible different potion effects...
types, not with amplifiers
but yeah that works
Then PotionEffectType.values()
hey you should
make a constractur as well
between the classes
check dependecy injection guide
it wont work since main class doenst regocnize your listener..
i would either reccomend learn some java before because its the basics
if you will learn spigot api without knowing java you will run into many problems later
lmao why another method
isNew could also be non-existent
haters gonna hate
Also I am one of the proponents who advocate to never inline if, for statements etc
whats the benefit
Somewhat faster
k
Altho you lose polymorphism
when static when no
tf is polymorphism
Different subclasses do different things when calling the same method
it really depends
is DI good for utils?
No. Utils should be stateless.
Right after the access modifier
Static can be used for
(Singletons, tho scarcely)
(Multitons and monostate, even more scarcely)
(Utilities, always)
(Helper methods, mostly always)
(Factory methods, scenario dependent but not a bad choice often)
(Constants, almost always)
I like the former
which one is former
But I think thats a preference
Just remove that method. It literally adds no clarity to the code.
Class.staticMethod();
oh
Iād do sth like
boolean isNew = player.hasPlayedBefore(); in this case
Assuming I wanna be elaborate on the code
hey guys what kind of object is in-game fire?
and umm how do people make apis for ther plugins
tile entity or smth?
posts from bukkit from 2012 dont sound like good advice tbh
if it works it works
well
use static whenever you feel it needs
if you dont want a job then sure
If you use 1.8 then thats right where you belong
static abuse is a lie
Well APIs are usually for the entire world to consume, thus we think about
- having a small surface area where necessary functionality is exposed, what can we do with the api?
- because we wanna make sure the consumers can rely on the api against retro incompatible changes we as the api providers might commit, then having a module of interfaces will help with separating concerns
all my plugins use latest spigot api and java 17 š
i only done 1.8 plugins for a lobby server and a little bedwars
on later java intellij gives more cool tips
I get 1.8 for lobby servers
And nms? šļø
never touched nms
Nice. Something fresh. We dont have enough lobby and bedwars plugins for 1.8 anyways.
i never needed nms
Block
i feel like if theres something that cant be done with spigot api, it should be pull requested or made as external api
its not public
just a normal block?
and its not a lobby core
speaking of I need to make my main plugin different version compatable lol
just some item thing
thanks
and i just coded a small amount of the bedwars thing
back in a day you could hold lava
easier to bug fix if we coded it ourself
antipopup teached me a lot
yeah happened to me
keeps telling me another git process is running
why
I like it, it's pretty rare that it messes up
just click commit and push
commit is broken, I'm debugging it rn
there we go
had to delete .git/index.lock and restart intellij
Mye
Well it does help
Having to write everything out every time gets exasperating rather quickly
Yes it is almost essential tbh
For mongo, how do I search for a field in every document in a collection?
Like:
Paul's document
Code: 1234
Joe's Document
Code:4321
and I want to search all codes and see if any match
u look familiar, what plugin did u make
Only one im proud of, largeraids
But i dont think thats why you think i look familiar
Just do a find with a simple filter
How do I do #find? I can't do that on getDocument and I need to specify a collection if I'm to try it on a collection
getMongoManager().getClient().getDatabase("Documentation").****
MongoCollection<Document> collection = ...;
Bson filter = Filters.eq("Code", 400);
FindIterable<Document> iterable = collection.find(filter);
Aight thanks
how do ppl do stuff like
"{player}" and then replace {player} with something else?
placeholders i mean
ik format() exists
"{player}".replace("{player}",player.getName)
Can be chained even more since replace returns a new string with the modifications applied <:
whcih one
You need to write regex which finds every element between { and } and then replace them based on a mapping and the context
didnt import
should i just leave api-version to real api's version?
sorry if I seem a little stupid but I havent donee this in a while, how would I get the opposite of a players direction
like ik how to get the direction, just not the opposite
Is there ANY way to get an instance of player in a JDA event method?
I mean spigot Player
Probably not
Aight
JDA doesnt have anything concerning spigot
Youād have to bridge that yourself im afraid of
Yup
either inject it or get the player by UUID
My brain is gonna explode from this
I don't wanna get a specific player
so UUID wouldn't work
Then just get a random one
You can use sth like Iterables.getFirst from guava
Infact the reason I want an instance of player is for UUID
pls answer
Get players and randomly select one?
Multiply with -1
I mean the direction is a vector, vector multiplied by scalar -1 always gives the opposite direction but same magnitude
Ah
quicc maffs
ive written all my messages with hardcoded placeholders lol
"Conorsmine has vanished. Poof"
I mean placeholders are inherently "hardcoded" ;p
ty
well i mean you cant just put %player% in any of the messages as it wouldnt know what to do with it
its hardcoded what should be filled in
Just pipe every string through papi
im not even using papi on my server
I cant use the * symbol on block face
what should I do to fix this?
Get the direction as a vector
ok lemme try it
Doesnāt blockface have a getOpposite
aint no way
Yeah look what coll said, you might not need to mess w vector
I tryied looking that up and found nothing
it worked tho
wait but its not block face sorry, its getting the face of the player, and puting it down there
im kinda stupid sorry
so lemme try the same thing with that['
hi kinda stupid sorry, I'm mom
ok but now I have that, how could I add the normal direction and the opposite direction together? because I cant use the normal + symbol using these types of faces and such
any one can explain where the hack is loadPlugins() method from SimplePluginManager called
I am scoped thru all imported libs
I have and there is no usage of that method anywhere
how the hack are plugins loaded then
CraftServer#loadPlugins
Is there an event for when a potion effect is ending?
EntityPotionEffectEvent should be called
dam it is really there
is something wrong with my intellj
because still can't find it in search box
I want to create a utility package for spigot, I don't want it to be ran as a plugin/mod, how can I achieve this?
plugins would have to shade it as a library
I am still trying to find out how to make new aliases or command registered to be TAB compatible
Would the library itself be in the template of a Spigot plugin with the plugin.yml files and the such?
Am I missing something, why isn't this working?
MongoCollection<Document> collection = plugin.getMongoManager().getClient().getDatabase("aqua_core").getCollection("Documentation");
Bson syncCodeFilter = Filters.eq("syncCode");
FindIterable<Document> iterable = collection.find(syncCodeFilter);
if (event.getMessage() != iterable) {
if (event.getAuthor().isBot()) return;
event.getMessage().delete();
event.getMessage().reply("Not a valid sync code").queue();
} else {
event.getMessage().reply("valid").queue();
}
That looks like jda
^
but yeah I didnt compare right
it shouldn't affect it though?
MongoCollection<Document> collection = plugin.getMongoManager().getClient().getDatabase("aqua_core").getCollection("Documentation");
Bson syncCodeFilter = Filters.eq("syncCode");
FindIterable<Document> iterable = collection.find(syncCodeFilter);
if (!event.getMessage().equals(iterable)) {
if (event.getAuthor().isBot()) return;
event.getMessage().delete();
event.getMessage().reply("Not a valid sync code").queue();
} else {
event.getMessage().reply("valid").queue();
}
I'm trying to make a boat step-up feature which needs to work at high boat velocities (boats which run into a 1 block tall wall will go on top of it). I'm using raytracing right now to achieve this, and have got it to work. However, my current system is unreliable as a lot of the time the boat will lose it's velocity when it steps up the wall. I was wondering if anyone had any ideas as I am kind of stumped
My current code
I suspect it's a ping issue when the client hits the wall before the server tells it to teleport up, so loses it's velocity. I tried setting the velocity of the boat again after it gets teleported, and tried delaying this by a tick too, but in both cases the velocity was still sometimes lost
getType().isAir() kek
is that an issue š¤
oh right
I'll change
Any thoughts, FourteenBrush?
whats a boat step-up feature supposed to mean?
anyone have any ideas?
make sense or?
yes
kk
so any ideas then?
I don't know what's causing the boat to lose velocity even when I set the velocity of the boat again
Does teleporting entites reset their velocity?
no
I've tried setting the velocity of the boat again after the tp anyway
still, sometimes the boat loses velocity
if you want to see it in action you can join my server
My guess is the client hits the wall before the boat does
Because I've noticed sometimes the clients hitbox can be in front of the boat sometimes
yeah, that's what I'm thinking. Setting the velocity again after the tping should fix that though but it doesn't
That should only happen if they are on the side of the wall no? Isn't the boat hitbox larger than the player's?
boat hitbox is larger than player's, why would that stop it from hitting the wall tho?
The player's hitbox shouldn't hit the wall first then.
Probably not but is there a way to change how particles move? Like make a redstone dust particle move like an enchant particle for example
I think he was saying that the boat hits the wall on the client side before it does on server side
Is that what you meant?
Yeah
mhm
Oh, I see.
If it collides the client shoudl send a steering packet
Steering packet?
I believe
Because on servers there's a delay between the boat updating to the players actual position
What's a steering packet?
yes
last I was messing boats and riding
I would have thought setting the velocity of the boat again after the teleporting would have fixed this, however it doesn't
Yeah not sure why that wouldn't work
Any other ideas then? Maybe if you saw it you might see other problems? I could send you server IP
or anyone here
Maybe sometimes the client updates after the boat has already hit the wall and the velocity was set
hmm
I did try delaying the setting of the velocity
up to 5ticks
5ticks it got weird
1 tick I didn't notice any changes
I didn't try inbetween times
Right ok, will try this in a bit
Is there a way to see how much damage the item in the players hand caused to the entity damaged?
is there a better way for doing this?
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
PlayerData playerData = RoleplaySystem.getInstance().getPlayerData(event.getPlayer());
if (playerData.getLockedSlots().contains(event.getPlayer().getInventory().getHeldItemSlot()) &&
event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.AIR)) {
event.setCancelled(true);
}
}```
I kinda want to see it in action. I also want to see if it works on more than just full blocks.
getFinalDamage() in the event
kk
I'll send u ip
getLockedSlots get slots?
and this code cancel if the slot of main had is in lockedslots and the item is air?
method bad readed...
Doesnāt this also apply critical hit damage as well though?
i have a list of slots that are "locked" and i just want to cancel if the item in that slot gets dropped
i know that this code is bad, thats why i am here, i want a better solution
because right now if the locked slot is empty and the selected hot bar slot dropping is impossible
my question about this is the event... if is only fired for main item drop or for any.. if you drop a random item from inventory then this validation not work because in all cases check the main hand.
https://pastebin.mozilla.org/g1sPykLw Could someone help? I wanted to modify cow's drops with custom items but it doesnt work
its called for any item drop 
thats why i tried to filter it in that stupid way
or is there a event that only gets called when q is pressed
so strange no body request the event show the slot used
you can detect through the inventory click event if a item from the inventory is dropped and cancel it
but that doesnt work if you use q
you sure your are get the item? the getMaterial can return null.
i made a command that works and i can obtain the item
smh
smh you cannot switch over classes
Yes
that is pattern matching
not a straight up switch with a jump table
jep 406
my sserver doesnt like the fact that i need to enable preview features lol
Hello I need an event when Water break a crop, what is it?
then fully update to J16
Hm, then it might still be like that for switches
any let me know what is the problem here
uhh hover over it lol
something: []
is empty list in yml right?
Hello !
I'm reading a spark from a lagging server and there's something I don't understand.
Most of the problems come with the function NMS.level.WorldServer.tickNonPassenger() ...
I don't really know how NMS works and I looked at google, I can't find anything about this function.
Can anyone explain pls ?
check my code on gh lol
you're trying to use an nms constructor with bukkit values
tickNonPassenger likely refers to entities
That's what I understood, but I don't know what exactly, and I don't really know how to fix it (instead of kill them all I mean)
you cant fix it because there are just too many entities in your world it seems
removing their AI will definitely help
Alright, gonna check ty
What better way to know how many blocks the player has walked in the world? Is there a way to get the stats in minecraft?
same
.
check for the spawn event
and then spawn them in that world?
install nms
In file ?
Cannot resolve method 'setData' in 'Block'
no no wrong
https://paste.md-5.net/negiwukoro.cs
this code throws that error
do yall know any free service for hosting small maven repo?
Could this fail? I'm using it to check if a player joins certain worlds
public class Test implements Listener {
@EventHandler
public static void onChangeWorld(PlayerChangedWorldEvent event) {
boolean EnteredWorld1 = false;
boolean EnteredWorld2 = false;
boolean EnteredWorld3 = false;
Player player = event.getPlayer();
String world = event.getPlayer().getWorld().getName();
switch (world) {
case "World1" -> {
EnteredWorld1 = true;
}
case "World2" -> {
EnteredWorld2 = true;
}
case "World3" -> {
EnteredWorld3 = true;
}
}
So will the booleans always be false unless the player entered one of the worlds in the switch statement? (Noob question sorry but I wanna fullproof as much as I can)
just do the per-world action in the switch statement
Ok that was dumb
and just use event.getWorld()
thanks
not player.getWorld because we dont know if the player's world has changed yet when that event fires
In PlayerChangedWorld does event.getWorld() return the world the player is leaving or the world it is going to
? if player doesnt change world so how can that event trigger ?
?jd-s
you can try log it out
so player.getworld is better
not always
why not ?
player.getWorld is not defined behavior when the player switches worlds in that event
it could very well change between API versions
because the player.getWorld() is possible to not be updated when the event fires
When making dependency libraries for spigot plugin programming, which library should I use? spigot-mc or spigot?
spigot-api for api
https://photos.app.goo.gl/7hwU2p69JGL6Au8o7
How do I make him spawn In the world in which he died
I dont see no event.getWorld()
that doesn't look like spigot ?
Okay thanks
oh...
i should do a better job at reading
how do check if a potion effect is ending
is there any event for it?
player.getWorld it is lol
spigot isnt for both spigot and nms ?
but holdup what if the event didnt fire yet
i thought spigot-api and spigot were different...
there is an event for applying potion effects
.
spigot-api doesnt include nms
*player didnt change worlds yet
spigot-api is the well the API, spigot is the server implementation which does also contain the api, but lets you target NMS as well
player.spigot.respawn ?
i checked code
oh no please arrest me
anyways
here the player's world changes before the event is fired
there are 2 api: spigot and spigot-api
so you will get the correct world
sorry for confusion
I don't understand
np thanks for your help
i thought PlayerWorldChangedEvent extended a different class...
is this for spigot
it doesnt look like it
based on your pic
(hes on PE)
bro I use GeyserMC
problem is if you decide to cancel the event, then this wouldn't be true till after the event
event isnt cancellable
delightful
there is an damage event
you can cancel that damage
So I downloaded plugin for Java to my server
are you developing the plugin?
Me ?
Sometimes yes
@lost matrix You should make a guide into using Prometheus for internal metrics ( https://github.com/prometheus/client_java#instrumenting )
to change where a player respawns
OK how
declaration: package: org.bukkit.event.player, class: PlayerRespawnEvent
what
Ok I downloaded 1m
Is there a name for the lowest level folder in a project sturcture?
so org.commands.dot, what is dot?
That's usually the artifact id
Ah I see, and there's usually a file like this there org.commands.dot.Dot
Okay makes sense
I am looking for when it ends, basically want to renew the potion effect when player is standing on a pressure plate
Do i Should to download this
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.
pom?
wtf I am doing wrong
Is it plugin or something in server files
change spigot-api to just spigot
thats not the problem
you taking to me
i want to see your pom in full
Does anyone have an updated tutorial for getting started writing mods compatible with spigot using either vscode or intellij idea?
has it been tried already?
well if you notice...
he has the spigot dependency there
and spigot-api is commented out
anyone have a easy method for a countdown, bukkit runnables are freaking me out
you need to use a runnable
true
maybe just refresh maven
Gast tell me the file who i should to edit @glossy scroll
@glossy scroll by rebuild you mean do maven clean
Bukkit.getScheduler().runTaskTimer(plugin, bukkitTask -> {
if (this.countdown-- <= 0) {
bukkitTask.cancel();
}
}, 0, 20);```
and then again try to maven package it
Where can I find up to date tutorials for developing mods using Spigot?
maven tab
also try to run mvn clean install instead of just package
cleaning can sometimes help
do it in terminal
and rebuild thing can't be run because project is maven
what is the output then?
Rebuild Project isnt a mven thing
its an intellij thing
its just like a cache clearing tool thingy idk
whenever i have weird behavior i run it
If a premium plugin needs to be able to run without internet (rules say that)
What happens when the plugin wants to connect to a database?
there are buttons for that
it needs to be able to function without the internet
that is from rebuild thing
sory
is there an event that triggers when player leaves server no matter if its kick or manual leaving or server stop?
Bro What now @glossy scroll
it is install button i think
in your mvn compiler plugin
<configuration>
<source>17</source>
<target>17</target>
</configuration>```
the regular quit event should be called no matter what or why the player left
sorry i cant hlep you any further, youre asking for a coding tutorial. im not here to assist with that.
when the server crashes no player quit is called >:
even if kicked?
@glossy scroll all fine
skill issue for server owner ig
?
quit still runs if the player is kicked, the kick event is called first then quit
I just did rebuild thing and changed java to 17
did u put that in ur pom tho
yea, what if it depends on a database
Bro I gast I want to change place spawn death
once again, it needs to function without the internet
well I think
what im getting at here
I don't care if it's a code or plugin
is that you need to find a different solution
I've been wondering how to efficiently sort a list of objects based on member variables for a long time.
Here's an example:
public class MainClass {
public static HashMap<Integer, Weapon> weapons = new HashMap<>();
public static void main(String[] args) {
for (int id = 1; id <= 1000; id++) {
weapons.put(id, new Weapon(id, (int) (Math.random() * 1000)));
}
}
}```
The above code stores 1,000 instances of a `Weapon` object within a HashMap called `weapons`.
```java
public class Weapon {
private int id;
private String name;
private int damage;
public Weapon(int id, int damage) {
this.id = id;
this.damage = damage;
this.name = "Unknown";
}
}```
What is an efficient way to make a list of these `Weapon` objects **from** the `weapons` HashMap sorted from highest `damage` to lowest `damage` (Weapon member variables)?
SQLite or just disable the internet database if theyre offline
true
where is java.version
treemap is a map which is sorted by keys
well thanks for help
you cant sort a hashmap
I am not able to translate progress messages in the HoverEvent, I have tried to put the key in several ways and have not been successful.
I'm using TranslatableComponent, has anyone managed to deal with this ?
advancements.husbandry.safely_harvest_honey.description not work (example)
There's no way to take the data from a HashMap and output a list of any kind?
there is
map.values
declaration: module: java.base, package: java.util, interface: NavigableMap
Finally figure out how to make commands tab complitble
its the superclass of TreeMap
thanks god
(you should downcast TreeMap to navigableMap)
after you edit CommandMap you need to call
cs.syncCommands(); CraftServer cs = (CraftServer) pl.getServer();
cs.syncCommands();```
so theres no premium plugin that uses a db?
Bro I gast want plugin fix this problem
basically imagine you are making a skyblock plugin
database can run on localhost?
oh yea
SQLite my guy
but not every database runs on localhost
nice
my plugin doesnt work without db too lol
Like there is planty of simple installers for localhost data bases
whats bad about that
I can't download these sources, I just click on Download Sources and nothing happens...
no
make runable
is this nms?
yeah
yea theres no sources available for nms
ah alright
which counts down after player consumed potion
ty
a runnable that loops through all players checking if they have a potion effect and if they do, getting its duration
that sounds so bad performancewise
I would make some type of CustoPlayer class with map
declaration: package: org.bukkit.scheduler, interface: BukkitScheduler
Just to make it look nicer
btw
I believe youre looking for
and then just make custom event which gets called when potion expires
Collections.sort(map.values(), Comparator.comparingInt(Weapon::getDamage))
could be wrong
that just comes to mind
actually
Basically what I want is this. If I have a large list of objects, how can I sort the list based on the member variables within the objects?
could be any form of stored data, doesn't necessarily need to originate from a HashMap
you'll be using Comparator
declaration: module: java.base, package: java.util, interface: Comparator
many of these methods accept functional interfaces
which can be used with a lambda
can you register events for more than one class in your main class?
as in:
getServer().getPluginManager().registerEvents(new Events(), this);
getServer().getPluginManager().registerEvents(new Events1(), this);
oh ok great!
i have this code
public static boolean joinedBefore(Player player, Boolean shouldSave) throws IOException {
are booleans false by default?
or true
good thanks
hi this is my code now
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1){
List<String> playernames = new ArrayList<>();
Player[] players = new Player[Bukkit.getServer().getOnlinePlayers().size()];
Bukkit.getServer().getOnlinePlayers().toArray(players);
for (int i = 0; i < players.length; i++){
playernames.add(players[i].getName());
}
return playernames;
}
return null;
}
}```
and i want so if i type * after that i seleckt all player what do i need to add? tag me
uh
well
first
Bukkit.getOnlinePlayers().stream().map(Player::getName).toList()
and second i dont know what youre asking
@eternal needle
It is possible to somehow find out how many hours (ticks or something else that can be converted to hours) the player has on the server (BungeeCord)
not without tracking yourself
well actually there are statistics but i believe those are per-server
it's like if i want to give everyone on mye server i don't want to type every name so i can type * and it seleckt all player so /eco give * 100
I watched some forums and there is bukkit.getstatistics but thats bukkit
...yea?
you would need to test if the string is *
ok
I fix it withe /spawnpoint š„²@glossy scroll
can i listen to events that i have no access to?
basically i want user to place a list of events that my plugin will listen to (including custom plugin events)
for example com.github.somebody.someplugin.SomeEvent
what is the purpose of this?
my plugin will execute commands on any event server owner can imagine
and i know its possible, kiteboard does that
then can you look at kiteboard's source?
id have to buy it
maybe a different question, is there event that runs on any event š ?
thanks!
returning null in the onTabComplete, will tabcomplete the playernames by default
if you want it to show nothing, use Collections.emptyList()
i need it to return that i can do * after a command like "eco give * 1000" so i don't need to type all names
ig create a new arraylist with the player names then and add "*"
ok thx
Can someone send me discord plugin redstonepvpcore
lol
Bukkit.getPluginManager().registerEvent
I want plugin When someone kills a player throw him item
\
The listener passed when registering
But keep in mind registerEvent still takes an instance of Class<extends Event> which requires an event class that has handlers
yes
this person would need to cast the user-defined class to that type
and just trust that the user put in the necessary handler stuff
Ye
do you think that storing data on the ItemStack instead of using a database is a good idea?
@onyx fjord you will need to catch the error IllegalPluginAccessException
Depends on what type of data
ill see what i can do
well im telling u to catch that error
yee will do
otherwise your whole plugin will just stop when trying to register events and things
Is there no way to wait for a certain amount of ticks without a scheduler?
BukkitScheduler or ScheduledExecutorService in principle
The normal time sleep? Yeah that blocks the thread
why dont you want to use the scheduler?
I'm just curious, it feels like something that should exist.
It does
ScheduledExecutorService
It still schedules
But far more efficiently compared to CraftBukkitScheduler
it wont be synched with the server thread tho
That too
if you want to use ticks as your timing device (you really should...)
unless
its db related
You can always callback to server thread with the BukkitScheduler <:
yes lol
How do I disable damage to minecarts?
I tried this but it doesnt work
if(event.getEntity() == Minecart){
event.setCancelled(true);
}
I see, thank you
i mean you can also use CompletableFuture too
theres many ways
but BukkitScheduler should be used for all gameplay/api purposes
That just uses any instance of an Executor in the end but ye
yes
instanceof
I think theres a class called timer task or sth but its shitty as fuck so dont use it
i tried that as well
what does your event look like
how do i add "*"?
list.add?
@EventHandler
public static void onAttack(EntityDamageByEntityEvent event){
if(event.getEntity() instanceof Minecart){
event.setCancelled(true);
}
I want to make a place inaccessible to only those with special ranks Is there plugin like this
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
please stop making plugin requests
@quaint mantle if you are willing to pay drop me a dm
wdym?
List<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toCollection(ArrayList::new))
names.add("*");
return names;
```but streams bruhh
is making money illegal or what
wdym not cool, he literally asked if someone can do it
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
pay what
its also unethical to prey on someone looking for a plugin that already exists
and offer to make a custom one
well idk what he wants
#help-server @quaint mantle
I now
^ say in that channel what exactly you need
Ok
So I listened to the steering packet
I'm getting it every tick driving the boat
So I'm not sure how I can use this to determine if the boat hits the wall or not
50% of the time it goes over blocks fine
other 50% all velocity is lost for no apparent reason
My favorite thing to use boats for is to place it inside a door and move through it, on servers with door lock plugins
lol
that's possible?
I'm trying to make a boat step-up feature
Yub
so it can ride over one block walls
boat hitboxes are larger than you place them in the corners
so you can angle it to clip through blocks
lol thats possible?3
make a plugin that fixes it š
another server I was on had a plugin that prevents you from placing boats on land but you can use that hitbox to get boats on land anyways
keke it's funny
why is this not working
it works in my other projekt
Player player = event.getPlayer();
for(Player p : player.getWorld().getPlayers()){
p.teleport(somewhere);
}
Will that teleport all players in the players world? If not, how do I do that?
should work
how do i get a class out of main from another project?
ive linked one with the other
and i can get the main class
but i don't want to make a new main cus that will make it that its dubble
yes
public class Main extends JavaPlugin {
public Select select = new Select(this);
@Override
public void onEnable()
{
new CancelEvents(this, select);
getServer().getPluginManager().registerEvents(select, this);
}
public Select getSelect() {
return this.select;
}
}
so i want to get the select in another project
Select is a class
You have to add your plugin as a dependency in the other plugin
and then import your main class
I would recommend not naming your main class "Main" in every plugin
Instead just name it after the plugin. If it's for warps the plugins Main can either be "Warp" or "WarpMain"
thx for the feedback
how can i ban a player
.
.
uh....
One time you have an instance of "Player" the other time you have an instance of "OfflinePlayer"
Also OfflinePlayer#setBanned is deprecated. You should not use it
Instead you wanna use the Banlist https://hub.spigotmc.org/javadocs/spigot/org/bukkit/BanList.html
declaration: package: org.bukkit, interface: BanList
you can get it via getServer().getBanList()
this is the other project i tried what you said and is this what you meant??
package com.dami.kingdomServerCommands;
import org.bukkit.plugin.java.JavaPlugin;
import com.dami.Commands.KingdomCommand;
import com.dami.main.Main;
public class KingdomServerCommands extends JavaPlugin
{
@Override
public void onEnable()
{
Main main = null;
new KingdomCommand(this,main.select);
}
}
import com.dami.main.Main is the other script i showed earlier
Yeah but you can't do main.select if main is null
this is probably more of a twitch question but im not really sure so im just gonna ask here
lets say i was to make a minecraft plugin that integrates with twitch
would I be able to use the server to host my twitch bot?
Yes. I had a website running as a plugin on my minecraft server for a while
Ah alright
thankfully i dont need to pay for hosting then
i'll just make the server host an instance of the bot for one twitch channel
yup that works
Just make sure everything is async / doesn't take too much time
otherwise the bot will lag your server when it's under load
š
how can i make it a perma ban
i don't understand how do i fix this dumb stuff XD
same
how am i supossed to cast string to Event?
Class.forName
just pass null as the duration. It's written in the docs under addBan
i end up with this crap
Well you need a way to retrieve the instance of your main class of the other plugin. Like a static getter method or a public variable
ij fails to generify it
(Class<? extends Event>) Class.forName("")
thanks
yeah well thats the problem im trying to get Select(a public class) from Main to kingdomservercommands
Class<? extends Event> aClass = (Class<? extends Event>) Class.forName("");
Bukkit.getPluginManager().registerEvent(aClass, new Listener() {}, EventPriority.NORMAL, (listener, event) -> {}, plugin);```
well you either have to make the variable select static (or the getter) or you have to make a static reference to your main classes instance. Otherwise you can't access it
do you think that storing data on the ItemStack instead of using a database is a good idea?
Usually you would use DI but since you are in different projects that will not be possible. Unless spigot has a method to retrieve the JavaPlugin class of a plugin. I don't know if that's the case
thank you very much
Is there a way to remove arrows that hit blocks and not entities? So they don't clog up?
Depends on the amount of data, how often it is written and how often you have to update it
btw i wouldnt recommend copying this
to bad i have to make it static anyways its cool thx for your help
like, applications, application data
you should use your own values
Well you can still hold the data in a map/object and save it in the database every 5 minutes
i do
i also put listener and executor in own classes
I mean you could also use reflection but that's not a lot better than static
i would not know what that is
I just checked and there's a way to get it via the plugin manager. Check #getPlugin() https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/PluginManager.html
declaration: package: org.bukkit.plugin, interface: PluginManager
No bruh dont use static getters, that why exists a pattern called DI (Dependency Injection)
Then you just have to cast it to your own main class and you can retrieve the Select
He's trying to get a main class of another plugin. DI is not possible
But the pluginManager method sounds promising
In that case using plugin manager which returns you a singleton instance
How can I update the config file within a plugin
like change a setting for when a player runs a command
Yup that's what I said after I checked whether spigot has a method for that. Before I said I'm unsure if one exists
Get the plugin instance and then the FileConfiguration object of the config you want to edit
lemme see FileConfiguration javadocs
Is what you use for managing files!
projectile source exist in 1.18.2?
yes
package dev.tapwatero.greatgear;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.*;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
public class HomingArrowRunnable extends BukkitRunnable {
private Entity arrow;
private Player player;
private Entity target;
public HomingArrowRunnable(Entity arrow, Player shooter) {
this.arrow = arrow;
this.player = shooter;
}
@Override
public void run() {
Projectile proj = (Projectile) arrow;
if (target == null || player.hasLineOfSight(target)) {
setTarget();
}
if (arrow.isDead() || target.isDead() || target.getLocation().distance(arrow.getLocation()) <= 3) {
cancel();
return;
}
Vector newVector = target.getBoundingBox().getCenter().subtract(arrow.getLocation().toVector()).normalize();
arrow.setVelocity(newVector);
}
private void setTarget() {
List<Entity> nearbyEntities = arrow.getNearbyEntities(50, 50, 50);
if (nearbyEntities.size() == 0)
cancel();
Optional<Entity> optionalEntity = nearbyEntities.stream()
.filter(entity -> entity instanceof LivingEntity && ((Projectile) arrow).getShooter() != entity)
.min(Comparator.comparing(entity -> entity.getLocation().distanceSquared(arrow.getLocation())));
if (!optionalEntity.isPresent())
cancel();
target = optionalEntity.get();
ParticleBeam.spawn(player.getLocation(), target.getLocation(), Particle.FIREWORKS_SPARK, 20, 40, 0, 0, 0, 0, null, false, null);
}
}
Can you guys help me make it so that only entites that can be seen by the player are targeted and the arrow doesn't go through blocks
not through blocks
but stop it from hitting blocks in its journey
you can take the entities in "nearbyEntities" and check if the player can see that entity
how do i add this to the Optional
FileConfiguration has a save(String) and save(File) method
is there a way I can get the config file location of a plugin
just looking for a built in method before i do it manually
how can i copy comments to my config.yml
Is there a way to get the event when an entity targets another entity for breeding, I know EntityTargetEvent, but I couldn't find the reason for breeding
i use ```java
private void registerConfig() {
File config = new File(this.getDataFolder(), "config.yml");
if (!config.exists()) {
getLogger().info("Generating config.yml... It may take a while.");
saveDefaultConfig();
}
}
on enebale ```java
registerConfig();
getConfig().options().copyDefaults(true);
saveDefaultConfig();
saveConfig();
getConfig().set("plugin.version", version);
saveConfig();
getLogger().info("Config.yml was generated..");
You don't need that for the default config