#help-development
1 messages ยท Page 2080 of 1
how does one make it such that a villager gets infected at any difficulty
this is my current code now:
public class VillagerInfectEvent implements Listener {
@EventHandler
public void onInfected(EntityDeathEvent ed){
LivingEntity e = ed.getEntity();
if(e instanceof Villager){
Villager vill = (Villager)e;
EntityDamageEvent entityDamageEvent = vill.getLastDamageCause();
if(entityDamageEvent == null) return;
if(entityDamageEvent.getCause().equals(ENTITY_ATTACK)){
//what do i do here
}
}
}
}```
as in how do i spawn the zombie villager that on healed, would give discounted trades of the original villager and all that
Don't think there's API for that at the moment, but Villager#zombify() is being PR'd at the moment
public void zombify() {
this.entityType = EntityType.ZOMBIE_VILLAGER;
}
your welcome choco!
in the mean time you could run your own RNG for it, then just kill the entity spawn a zombie villager
you can merge now ๐
since that is what the code does
you forgot to add it to bukkit too
oh yes
public void zombify();
lemme contact the bukkit devs directly
here you go
Not quite. Internals retain villager data, gossip, trade offers, and experience
I am too lazy to add it
NO
naaah we dont do that around here
jsut change type and worry about it later
exactly
technically not on the bukkit dev team anymore, but I don't think people at this point care about the technicalities anymore ๐

sheeesh
He's old
Yeah I was a bukkit Dev staff member ๐
damn right he is
but how do i copy the trades the villager had over to the zombi
he could be my dad almost
you can copy the metadata or should be able to at least
assuming zombie villagers have trades, been a while since I messed with them
You'd have to keep track of it because there's no API for setting the villager data of a zombie
(hence the #zombify() API being added)
wtf I thought you were way older
not sure why you thought that, like I idk how many times I tell people my age lmao
does zombify "exchange" an existing entity into a zombie thing, or does it create a new entity?
i don't know either lol
yeah but I mean
even the internal code kills the previous entity
if I do this:
Villager frostalf = Bukkit.getEntity(...);
frostalf.zombify();
// is frostalf now still a valid reference to the now zombified frostalf?
are you sure? because this means that the frostalf object changed it's class
but technically it should keep that reference
Well, most entities can be reduced to just entity class
does zombify() return anything?
that's the question ๐
The zombified entity
ah ok
well then thats that XD
so it indeed replaces it by returning a new entity
btw did you people know about the light block?
It's a new entity
I found out about it in a technoblade stream
there's now a block called "Light" that is invisible (like barrier blocks) and that you can walk through (so basically like air) but you can set a custom light level between 0 and 15 for it
ITS SO AWESOME
we can now cause epileptic seizures more easily now
oh wait, don't think that is the purpose of it
the only irony here is there being garbage else where too
as if the tower garbage made a difference
yeah the whole table is a big pile of garbage
@noble lantern you should benchmark those math utils you have now
be interesting to see how much more efficient they are over the traditional methods
public interface MathUtils {
int add(int a, int b);
}
I don't mean in terms of writing them out efficient
meant in execution wise
the addition one might be a bit harder to benchmark
because I mean its pretty efficient in java as it is XD
we almost have a complete window typing
I have a strange behavior, for me it seems the saturation of the food is maybe broken on spigot.
The wiki (https://minecraft.fandom.com/wiki/Hunger#Food_level_and_saturation_level_restoration) says a bread gives you 6 saturation points.
I tested it with the following code, but it gives me different saturations (5, 2.5, 3.75, ...) for the bread.
@EventHandler
public void playerItemConsumeEvent(PlayerItemConsumeEvent event) {
ItemStack itemStack = event.getItem();
Material material = itemStack.getType();
if (!material.isEdible()) {
return;
}
Player player = event.getPlayer();
float beforeSaturation = player.getSaturation();
Bukkit.getScheduler().runTaskLater(this.main, () -> {
float newSaturation = player.getSaturation();
float saturationDiff = newSaturation - beforeSaturation;
Bukkit.broadcastMessage("gained saturation: " + saturationDiff);
}, 1L);
}
have you checked your spigot.yml?
If you spam that block, you can even lag your players without them noticing any blocks \o/
its the default one.
they get "different" values from the same food, so can't really be anything in spigot.yml
I'll just try that code quickly
I am pretty sure the test isn't designed properly
How would you test it ?
I don't found any methods on the event to get the "gained" saturation.
you can get the players saturation before they eat, and after they eat. You wouldn't test it before the event completes though at least not that event. You need to know what their points were before and then need to wait till the event completes to then see what is after
it's always 6 for me
wtf o.O
as expected ๐
I always tp'ed myself 10 blocks up to lose some health, until I lost hunger level, then ate a bread
it was always 6
what that method of getting what time it is
EssentialsX
yes, EssentialsX
ok thx
did you use the same code @tender shard or did you alter it?
It's surprising to hear somebody doesn't know what Essentials is
same
interesting
I only changed this.main to this
probably the reason they are having issues lol
lol
anyways food items are not broken in spigot
whatever you are doing is causing it to do something different @regal lake
I try to figure out what happens here ๐ค
you got any other plugins?
oooor
maybe
your saturation was already almost full when you ate
so it hit the limit
No, i always set the saturation to 0 with the hunger effect
maybe that is where it is going wrong for you in regards to your test
I will setup a fresh spigot server without any other plugins and add one ofter the other
but more curiously not sure what gave you the inclination you needed to test the saturation levels to begin with
I want to increased the gained saturation, that was the reason why i saw that the gained saturation changed ๐
ah ok
currently not using them rn
but when i do use them i will ๐
thats a fleshlight
not the best things to say in this discord >>
cock
oh sorry i mispelled flashlight
๐ตโ๐ซ
rooster
chicken
Hello seameone know how I can't but a sign on front face of a chest when I put him ?
I have try that but didn't work
if (b.getBlockData() instanceof Chest) {
Chest chest = (Chest) b.getBlockData();
BlockFace face = chest.getFacing();
BlockState sign = b.getRelative(face).getState();
sign.setType(Material.OAK_WALL_SIGN);
((Directional)sign).setFacing(face);
sign.update();
}
you need a wall sign iirc
How can i get the UUID of a player that is offline?
I am saving the playtime in seconds to a file every time a player logs out and i want to be able to get the playtime of that player when offline.
This is what my .yml file looks like ```yaml
users:
UUID-HERE:
playtime: 48242
This is what i'm using in my code to get the "targeted player" `Player targetPlayer = Bukkit.getPlayer(args[0]);`
But if the player is offline it is just returning null...
Yes, i have read about that... But i still need to get the UUID
And how should i do that?
it returns an OfflinePlayer, which you can call getUniqueId()
Bukkit.getOfflinePlayer(String PlayerName).getUniqueId();
what is iirc ?
if i remember correctly
if you remember correctly what?
yes? as you were saying
๐
we want to know what is iirc
so fun fact since I had a bit of fun with some math earlier
There is no well defined function for the perimeter of an ellipse
huh
So then i should just replace String PlayerName with args[0]?
yes
in other words, you can only approximate the perimeter of an ellipse
rtfm
Deprecated.
Persistent storage of users should be by UUID as names are no longer unique past a single session.
because the player is offline
anyways, is deprecated for the reasons it states in the javadocs, however that doesn't mean your server magically updated the record of the player name so it is still valid in some cases to use the player name to fetch the UUID of the player if they are offline. The exception of this is if there is no record on your server, it will contact mojang API to get the UUID instead ๐
I really need to start my own teaching channel lmao
or a channel that has these weird facts that no one really thinks abouts
can i ask a question about packets / nms here?
I still don't get it...
I know about the deprecated stuff but i just can't get other stuff to work...
absolutely
elaborate and we might be able to help
Yes, i'm just gonna try something
spawning an itemframe with packet f***s the rotation
Is there some additional packet I need to send?
that is because you are using the wrong values is all
https://wiki.vg should help you out
the best place to go in regards to looking up packet stuff as its really the only place that has it the most documented
excuse me for being dumb, packets not my thing, but how am i using the wrong values, when im supplying the data watcher of an existing entity?
I think i figured it out... I added some stuff just to test it, but here is the code: https://paste.gg/p/anonymous/47880e0bcf5a488baf96b60ff4d0aa4a
targetPlayer is still null tho so it still sends the noPlayer string
It's kinda messy
But i think it is working...
Player targetPlayer = Bukkit.getPlayer(args[0]);
UUID ofPlayer = Bukkit.getOfflinePlayer(args[0]).getUniqueId();
So this needs to be fixed
this is how its going to get fixed
OfflinePlayer offPlayer = Bukkit.gettOfflinePlayer(args[0]);
UUID playerUUID = offPlayer.getUniqueId();
if you need to that Offline player to be a player Object because maybe they are online? (for future reference)
you can do this
if (offPlayer.isOnline()) {
Player player = (Player)offplayer;
}
//or we can also do this since you got the UUID
Player player = Bukkit.getPlayer(playerUUID);
why does that code only detect fly hacks and not speed hacks? : ```java
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
if (!e.getPlayer().hasPotionEffect(PotionEffectType.SPEED)) {
if (e.getFrom().distance(e.getTo()) > 4.317) {
//code
}
but for your usage you want to use offlineplayer because your code actually doesn't require there to be a Player object and also there is a possibility they can be offline so because of that we can just use offlineplayer and save the time for null checking ๐
I am not the best person to ask in regards to the packets to MC, however that is the only reason I can think of why it would end up that way
I think what you would need to do is possibly add to the meta that it is attached to a block?
Alright, so then i won't need to to do if (targetPlayer == null)?
exactly ๐
Alright, i'm gonna try and see if i can get it to work properly
Thanks for the help!
so i'm not really expecting an answer because you said you're not the best to ask, but what meta would that be, since it only takes in rotation and item.
curiously, why are you using entity look?
{
EntityPlayer nmsplayer = ((CraftPlayer) p).getHandle();
EntityItemFrame itemframe = new EntityItemFrame(nmsplayer.world);
itemframe.setLocation(e.getValue().getX(), e.getValue().getY(), e.getValue().getBlockZ(), 0, 0);
itemframe.setItem(CraftItemStack.asNMSCopy(getMap(e.getKey())));
nmsplayer.playerConnection.sendPacket(new PacketPlayOutSpawnEntity(itemframe, 71));
nmsplayer.playerConnection.sendPacket(new PacketPlayOutEntityMetadata(itemframe.getId(), itemframe.getDataWatcher(), false));
}
this is how an itemframe packet should look
this specific code sets the itemframe to have a map in it
I am still getting Method invocation 'getStatistic' may produce 'NullPointerException' on line 7
https://paste.gg/p/anonymous/2691e3b9760f40e38af0491d5f65d21b
And that is probably because targetPlayer still can be null, right?
pls help
well your IDE probably isn't detecting that you have a check already for it so its warning you about a possible NPE that we know can't happen. However, your code even with it updated doesn't require you to use a Player object, it can still just be done using nothing but OfflinePlayer
OfflinePlayer doesn't require the player to be online, and even if the player is online it is still fine
Hmm okay, but am i doing this correct? Player targetPlayer = Bukkit.getPlayer(playerUUID);
you only need the Player object if what you are doing requires there to be an online player, such as sending the player in question a message for example which you don't do
it was supposed to be a test thing, but this is the same code for other entities as well, so it fits pretty good to get their rotation. and without the rotation packet this happens:
if you needed a Player object yes
Alright
that is interesting
setting false in the meta packet, doesn't display the item in my tests
I will leave it to someone else more suited to help ๐
hopefully someone who is, is online or will be online soon lol
alright, well thank you ig
And this i should just leave like this?
yeah its fine
just because it is deprecated doesn't mean can't be used, it is just important you understand why it is deprecated
Yeah, but if someone would change their name... what would happen? Do they just need to log in again before it can be used?
if someone changes their name, but hasn't re-joined your server
you will still get the correct UUID
Ohh okay
however, if say you know their name but haven't joined yet
and lets say they changed it and didn't tell you
now the server is going to contact Mojang API since they hadn't joined your server
and fetch the UUID for that name, which could be someone else, since that player changed their name and that isn't their name anymore
Yeah alright
for your purposes of how you are using it, it is fine
๐
Thanks a lot for the help!
I have been trying to figure this out for like 2 days now
well that is part of the learning process
and not everyone learns at the same pace ๐
Yep ๐
I'm a genius, change my mind
public class HookHandler {
private static final boolean worldBorderApiInstalled;
static {
worldBorderApiInstalled = Bukkit.getPluginManager().getPlugin("WorldBorderAPI") != null;
}
public static boolean isInsideWorldBorder(Location loc, Player player) {
if(!worldBorderApiInstalled) return true;
try {
return WorldBorderApiHook.isWithinWorldWorder(loc, player);
} catch (Throwable throwable) {
return true;
}
}
}
what does player.getVelocety(); do
Its better to do events private ?
Why cant I use 1.18.2 there?

return player.getWorld().getWorldBorder().isInside(player.getLocation());```
really? there is no problem with a plugin on 1.18.1 on a 1.18.2 server?
Nop
I do my plugin in 1.18.1 spigot in a server of 1.18.2
Hey, short question: I try to programm, that mobs (for example two zombies or one zombie and one skeleton) fight against each other. Someone said i should use living entities for that and i saw that there is a attack() method for living entities. But i have the problem that idk how to work with living entities. Does maybe someone have an tutorial for working with living enties?
spawning an itemframe with packet f***s the rotation
https://cdn.discordapp.com/attachments/741875863271899136/962672896579350558/2022-04-10_13.15.57.png
https://cdn.discordapp.com/attachments/741875863271899136/962672898013823026/unknown.png
Is there some additional packet I need to send?
repost if anyone can answer
check the permission yourself
for whatever reason, doing CreatureSpawnEvent doesnt trigger for stuff like golems and withers
any ideas what should be used>
?
it should, can you show the code section?
yes
if i summon it, it works, but if i build it it doesnt
those buffs apply to every mob, but i have some health-specific things in the wither that require the buff to be there on the wither
oh
Dont create a random object every time just have one main object in your class
oh
ive always wondered why they have an object for random
instead of just a function
ThreadLocalRandom.current() also returns a random
which is bound to the current thread or something
oh
anyways, why isnt the event triggering when the wither spawns
maybe attributes cant be added until it explodes?
how do you know the event doesnt trigger?
idk maybe it does
put a debug line to check for sure
add a sysout
getLogger().info
Bukkit.broadcastMessage()
xd
ez
PacketContainer packet53 = protocolManager.createPacket(53);
packet53.getIntegers().write(0, x).write(1, y).write(2, z).write(3, 63).write(4, 0);
packets.add(packet53);
PacketContainer packet130 = protocolManager.createPacket(130);
packet130.getIntegers().write(0, x).write(1, y).write(2, z);
packet130.getStringArrays().write(0, defaultText);
packets.add(packet130);
}
PacketContainer packet133 = protocolManager.createPacket(133);
packet133.getIntegers().write(0, 0).write(1, x).write(2, y).write(3, z);
packets.add(packet133);
if (defaultText != null) {
PacketContainer packet53 = protocolManager.createPacket(53);
packet53.getIntegers().write(0, x).write(1, y).write(2, z).write(3, 7).write(4, 0);
packets.add(packet53);
}
so im trying to make some sign gui but the source is kinda old. here i get errors by the numbers. are these diffrent in newer versions? im using protecollin
did you add a sysout at the end of the code?
yes
so it fully executed
my guess is buffs reset when it fully spawns
after chargeup
any idea how many ticks the chargeup is?
Have you tried to add a delay? Like 1-3 tick
yes
its the chargeup thingy i think that breaks it
cuz summoning it works and it doesnt have the chargeup time
y e s
.
ty
sad whered the embed go
wait why CreatureSpawnEvent
it works in creaturespawnevent
one might get called before/after the other
just the buffs dont get added
is there an entityspawnevent? there isnt iirc
indeed there is
there is
or crystals
normally you do a check
ah ye i see
i dont think he needs entity spawn event
your trying to add leviation?
his event runs every time
no
Packet Question...
So, what could be the reason for this behavior?
I'm trying to hide and show a certain entity, in this case, we're using a item frame. Every other entity works as expected, but an issue arises when item frames are being used.
entity.getEntityId(), ((CraftEntity) entity).getHandle().ai(),
true);
sendPacket(player, PacketType.Play.Server.ENTITY_METADATA, metaPacket);```
This code gets the Data Watcher of the Item Frame entity that we're trying to show, that renders the item correctly.
The problem with this code, is that the item frame doesn't have the right rotation, which it should according to my research. Instead, it get rendered from the top. *(see image 1)* To try and combat this, I added this rotation packet, which takes in the yaw and pitch of the entity.
```PacketPlayOutEntity.PacketPlayOutEntityLook rotationPacket = new PacketPlayOutEntity.PacketPlayOutEntityLook(
entity.getEntityId(), (byte) entity.getLocation().getYaw(), (byte) entity.getLocation().getPitch(),
true);
sendPacket(player, PacketType.Play.Server.ENTITY_LOOK, rotationPacket);```
Now, this made things better *(see image 2)*, but I still can't fix the problem that the Item Frame is attached to the block itself, and instead it adds a couple of degrees by itself. Does anyone know why this occurs?
__**Image 1 & Image 2:**__
CreatureSpawnEvent extends EntitySpawnEvent
omg
thats only for phantoms
or the attributes
attributes
Image 2 to post above ^^
i think it's the same
and what does creature mean then?
wait what would happen if i did smth stupid like nuking the world on Event
seems to be rotating off a corner rather than the center
How do they register placeholders that are updated on an event?
entity spawn event includes all entities like arrows and stuff
creature spawn event is for creatures
i just want creatures
your event is fine, its just the delay issue
ye i think the game creates a new wither or smth after it explodes
if that is the case, i didn't know item frames can do that, and how do you even fix that? i'm supplying the information directly from the entity itself, so how does the rotation change?
so it resets all the nbt
maybe use this and check when his health is max?
for wither exclusively
theoretically that should only trigger when he first spawns so sounds to me like the best way to solve your problem
ItemFrames are registered as entities internally
perhaps, that's the most helpful thing i found on the javadocs
which is odd, but only exists because you can attach them to all block faces simultaneously
The item rotation itself is part of the datawatcher
Lmao i losted my message
How do they register placeholders that are updated on an event? Thanks
yeah, i know it is, but since i'm feeding it the rotation of an actual entity (that is correctly placed), how come it render the item frame in the wrong rotation.
Oh ok good advice Idk why I didnt do that instead of over complicate my life
sometimes the best solution is the simplest
when initializing your EntityItemFrame you could try setting its blockposition on the constructor (third param)
How can player.getLocation().getWorld().getName() produce "NullPointerException"?
player is null
lmao
๐ค
im just watching youtube sitting on this channel
im just deleting a folder for 15 minutes now
Uhhm
show code
was about to type that 
?paste
hahah get ninja'd
private is something lol
?
private Main plugin
lmao
hold up
hes doing
Main.getPlugin
instead of plugin.
idk if it will matter cuz idk what Main looks like
Let me try
but also you should prob have shown the nullpointerexception too
ah lol
tho i guess it doesnt matter since u said what line it was so nvm
but yea pretty sure its cuz you create a Main plugin variable and dont even use it lol
that isnt throwing a npe
yea idk
It says Method 'getWorld' is annotated as 'nullable'
im trying to use vault api and when i start my plugin it says Disabled due to no Vault dependency found!
i want to use economy
you need an economy plugin too
why sometimes yaw get negative?
final Location eye = player.getLocation();
final float yaw = 0 - eye.getYaw();```
the problem, and that usually the number stays positive, but ends up becoming negative, and that makes the numbers flip, from 0 360 ending up being 360 to 0
0 - eye.getYaw()?
its because is gedtting negative values
i want invert it for more easy to manipulate
is getting negative
final Location eye = player.getLocation();
final float yaw = eye.getYaw();```
also try using getEyeLocation() not get Location()
I use 0 - to transform from negative to positive, but sometimes it becomes positive and negative
still negative
final Location eye = player.getEyeLocation();
final float yaw = eye.getYaw();
//final float yaw = 0 - eye.getYaw();
actionBarMessage(player, "yaw: " + yaw);```
No clue, theoretically impossible.
7-8 years back I seem to remember MC rotated the world by 90 degrees so the sun went east/west
Im working on SignGUI over 10 hours and everything i find is outdated or doesnt work. I basicly want to make it so you have a shop and you can set the title of that shop by clicking on a button and a sign will pop up where you can type something in and then make it so the title will be what the players shop name will; be what he typed in the sign. Does annyone have any expiriences with this or wants to help me with this? you can dm me.
how do you escape a for loop? break?
Alright, I have a question. If I want to make an API for my plugin, I would create a class and create the needed methods for it. If I wanted to create another plugin that depends on the first plugins methods, would I add it as a dependency and then if I call the method would it work?
public class FirstPluginAPI {
public FirstPluginAPI() {
// stuff
}
public boolean linkedAccount(Player player){
// stuff 2
}
}
Second plugin :
maven,
<dependenies>
<dependency>
// all the things
<dependency>
<dependencies>
public class SecondPluginCommand implements CommandExecutor {
@Override
public boolean onCommand(.....) {
Main.firstPluginAPI.linkedAccount((Player) sender);
}
}
remember to declare your scope right tho
if it's provided you need to add the api as plugin to the server
i think
when i add the test-economy command to plugin.yml then the plugin breaks
how does it break?
Then how would I implement the functionality?
Sorry, I don't understand what you mean by that
normal classes
lets take a look at spigot for instance
the api mostly consist of interfaces
in your second plugin you have a maven part where you dclare scope
then we have underlying classes that implement them
for instance Player -> CraftPlayer
and the CraftPlayer on its own adapts EntityPlayer or the nms Player instance (altho we as api consumers know nothing about that)
So would it be
public interface APIInterface {
public boolean linked(Player player);
}
And I would make a class that implements this interface and add functionality?
mye
consider to use a more useful name, such as isLinked
or if it does something perhaps linkTo
Would the class need to have the same name as the interface?
nah
class DodoEpicConclureism implements APIInterface {
}
that'd work
altho questionable class name of the implementation class
but ye
So then I'd override the functions right? Thanks
yup
is there a way to alterate the permission token in this event PlayerCommandPreprocessEvent for players? Say, usually player has no permission to execute given command but this time its decided that he can
what error do you get?
afaik not possible
or well
technically you could change the permission for the underlying command instance
how
can i just send you the log file?
but in theory that wont work well
?paste it then
ik a command contains a token who sent the command and if he has permission or not
yes
alternatively i could also cancel the event and create a new command instance in which he has permission
but then you need to take into account the fact that plugins may not use the permission system bukkit offers
thats fine because im writing a system to bypass it
and now dont yell at me xD
and write my own
for instance setExecutor((sender,cmd,label,args) -> { if (sender.hasPermission("some.perm") { return true; } throw new RuntimeException(); })
@mighty pier send ur plugin.yml
?paste
version: '${project.version}'
main: me.frandma.disabler.Disabler
api-version: 1.18
authors: [ Frandma ]
description: Custom plugin for Disabler.
commands:
test-economy:
permission-message: e
permission: *```
'*'
hm
ah
its supposed to be 1.8.8
im pmuch done writing a permission system which is using the scoreboard teams as its base, disabled the team and scoreboard command and execute logic via that xD
that too
that wont cause trouble because i dont intend to use other ppls plugins
Don't need to specify a api version for 1.8.8
yes
By the way, would I use DodoEpicConclureism or APIInterface to call the methods?
Dodo...linked(Player) or APIInterface.linked(Player)?
Assuming Dodo, right?
yes
Location original_loc = new Location(world, 0,0,0);
func(original_loc);
...
func(Location loc){
loc.add(1,1,1);
}
after calling the function, is original_loc still pointing to 0,0,0 ?
but I sincerely hope that wasnt the name of your class
I'm not making anything right now lmao
oh right
Why is it better to use an interface then?
well then in addition you usually use services manager to provide the api instance from one plugin to another
well because when using an interface your design becomes considerably more robust
I mean in practice, when 2 plugins communicate there is no inherit need for an interface
but it really helps
Alright thanks, I'll look into the service manager
poke... yay or nay? Does origin_loc change here?
and in theory, you decouple your api layer from your business logic, you properly invert your dependencies and your api becomes mockable
@restive tangle
you know that your answers conflict here right?
@NotNull
public Location add(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
perhaps this is enough then
urgh conclure im calling a method with origin_loc as argument and in taht method the argument gets changed. WHat im asking is if the location used as argument outside the method changes due to this
Yes, unless you clone
^since add mutates the data of your location object
would calling loc = loc.clone() inside the method work?
no i need to mutate the location inside the method for the purpose of the method but the location passed as argument cannot change as a result of this
it needs to continue pointing towards the same location
so doing loc = loc.clone() inside the method would reassign loc to a new Location object thats a copy of the passed argument, correct?
yes
ok thanks
plugin still brokie
nw
k
**how do you make valid, working enchanted books as an itemstack? **@ me with an answer
Hello, my code here isn't working, I have reviewed a lot of resources and can't figure out why it doesn't work.
plugin = this;
NamespacedKey glowkey = (new NamespacedKey(this, "glow"));
this.getServer().getPluginManager().registerEvents(glow, this );
ItemStack glowitem = new ItemStack(Material.BOOK, 1);
ItemMeta glowmeta = glowitem.getItemMeta();
PersistentDataContainer glowdata = glowmeta.getPersistentDataContainer();
glowmeta.setDisplayName("ยงd");
glowdata.set(glowkey, PersistentDataType.STRING, "glow");
glowitem.setItemMeta(glowmeta);
NamespacedKey glowrecipekey = new NamespacedKey(this, "glowrecipekey");
ShapedRecipe glowrecipe = new ShapedRecipe(glowrecipekey, glowitem);
glowrecipe.shape("EEE", "ECE", "EEE");
glowrecipe.setIngredient('E', Material.GOLD_BLOCK);
glowrecipe.setIngredient('W', Material.GLOW_BERRIES);
glowrecipe.setIngredient('G', Material.GOLDEN_CARROT);
glowrecipe.setIngredient('C', Material.BOOK);
Bukkit.addRecipe(glowrecipe);
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
the recipe doesn't work, 0 console errors
like i put it into crafting table, and the recipe does not exist
did you teach it to the player?
?
Bukkit.getServer().dispatchCommand(...); returns a bool
``` what exactly does its return value represent?
returns false if no target is found
declaration: package: org.bukkit, interface: Server
How can I unban a banned player?
tried didnt find the doc for that
neeeed help
so if the sender is found?
Bukkit.getServer().dispatchComamnd(Bukkit.getConsoleSender(), "unban <player>");
if sender is found, it returns true
Thereโs a special EnchantedBookMeta
aight ty
ye depends on which plugin ofc
Hey guys, I want to create an inventory with player heads. In the middle should be the numbers from 1-5. On top and bottom should be player heads with which you can make the numbers "higher" and "deeper". Can somebody help with this?
but default is pardon i think
thx
okay so whats the easiest way to bypass a command instances op check
look up a tutorial
https://www.spigotmc.org/wiki/creating-a-gui-inventory/
in your intializeItems, use a for loop to place your heads.
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
What should I search?
what do you mean?
I already have this. But I don't know how I should do it with higher and lower
And how can I put custom heads in a GUI?
oh sweet
ive written my own permissions system, and i need a way to override the op check esp for the vanilla commands
what exactly do you want to do, do you want the numbers of the middle heads to increase or lower when you click on the heads on the top or bottom?
Yes exactly
alright:
-
in your inventory class, load up the default values in the inventory (1-5 or whatever you want), then set a variable for your current number.
-
create a config where you can save all the heads, or whatever you want to do to get the texture of the head.
the config could maybe look something like this:
- "headtexture" # head 1
- "headtexture" # head 2
these values saves the texture of the head with the one on it, two on it, etc.
- if the player clicks on the top heads or bottom heads (check in inventoryclicklistener), you update the heads in the inventory with the texture
of the head in the next index of your config list
if you don't understand i'll provide some code examples later :p
easiest way to give them the * perm, but that causes some problems on its own
if you want them to access everything
Thanks I will try
Can somebody help my with config file?
is there a Method to check if a Inventory contains all Itemstacks of a Collection?
*arraylist
yeah I'm currently doing java Arrays.stream(user.getPlayer().getInventory().getStorageContents()).toList().contains(getItems())but a containsAll Method would be quite handy
Why
If I need to check for more than 1 item thats the most readable Solution
you could just do a contains on getStorageContents since that returns an array already
and that isn't the most readable solution
is there something like that on the internet? if so what can you look for?
for(ItemStack items : user.getPlayer().getInventory().getStorageContents()) {
for(ItemStack items2 : getItems()) {
if(items.equals(items2)) {
//do something here
}
}
}
very readable and easy to understand, and not very difficult or super inefficient ๐
Why would have a pyramid of doom thats 6 lines long if I can do it one more readable one
your style of writing is up to you
has nothing to do with how it compiles
you want to write the entire thing on one single line
then go for it ๐
still compiles the same
I asked if there was a containsAll Method. I still haven't gotten an answer for that
no
but, hey its your project your code so it don't matter to us if its inefficient just we like to be nice and point such things out from time to time to people when its not obvious to them ๐
The performance impact from using Streams is negligible in this case
if you say so
I am not going to argue ๐
you could probably find people who ask this question on the forums and find some examples. Regarding how to stop tab completion and what not and how to stop brigadier from doing its thing. But like it doesn't matter to hide commands though if they don't have permission to run them anyways
ok?
more of a reason they shouldn't do things then if they find that ๐
if you think your server will be more secure because you obscure something, then you are mistaken
as long as the plugins you use respect permissions and you setup permissions appropriately, even if they discover a plugin command
doesn't mean they will be able to use it
and as for your example it is a poor one even if it is just an example. Everyone already knows about vanish and that literally almost every server uses it or has their own version of it lol
I have worked for a large network before, they are not around anymore but we never bothered to hide commands at all
we didn't even bother to hide plugins we used as well
most of them were custom anyways ๐
there is a permission to prevent usage of pl
it isn't that the custom plugins didn't have commands
they didn't register a bunch of commands
also aliasing is a thing
you can alias a command to include parameters to a single alias command ๐
and even register such in code too
no
as in, it has its own permission nodes and is sane in its checking if a player has whatever permission required
instead of going by if you are opped or not opped type deal lol
we never had issues is all I am saying and as far as I am aware no one who had permissions granted to them were able to run commands they were not allowed
yeah they could see the command exists, but that was it, most of the time they had no clue what it even does XD
you could just demonstrate it for them ๐
well sure, but if you have a decent community
generally whenever someone question it some random in the community answers it for you ๐
not like telling them what it does, exposes the specifics of it lol
we had anti-cheat related command stuff where we can enable reporting on any player we chose ๐
or visually turn on stats in our chat
telling them and even showing them what it looks like, doesn't reveal how those stats or anti-cheat reporting stuff gets its information or how it looks at the information XD
but it helps the loyal ones know you have cool tools and then they start doing your job for you sometimes lol
which is awesome to have ๐
key1:
key2: value
- "list_1"
- "list_2"
does calling config.getStringList("key1") return a collection of {"list_1", "list_2"}?
Hi guys!
do more potential command senders but Player, CommandBlock and ConsoleSender exist?
any other instances that can perform commands?
How can I check the side of the clicked block? I try it:
if (blockFace == null) return;
Location targetLocation = null;
if (blockFace.equals(BlockFace.UP)) {
targetLocation = new Location(player.getWorld(), block.getX(), block.getY()+1, block.getZ());```
but it doesent worked.
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
Just look at the things that implement command sender
Well mobs can technically send commands with the execute command but I'm not sure if they are counted as the command sender
yes they count
ooo that's alot
Why are you appending the bold symbol to every char?
You only need it at the begging of the string unless you reset formatting
if (item == null || item.getType() == Material.AIR) continue;
player.getWorld().dropItemNaturally(player.getLocation(), item);
}``` items dont drop
I'm not sure how I use <Player>.getAdvancementProgress(), is there any guide about it?
I'm editing a YAML value in my plugin which "works" but the actual value in the file doesn't seem to change and when i restart it wasn't affected at all.
anyone know how to add custom loot tables to structures
Did you call the save method?
Np lol it's easy to forget
do you guys use final for local variables or method parameters, why or why not?
No because I'm lazy
how can i get the loc of the area where a snowball lands
projectilehitevent
i know which event
but how i create the box
of entities or blocks
maths
a custom radius of the snowball loc
just block s
so i want to summon lots of anvils in the radius when the snowball lands
public void onProjectileHit(ProjectileHitEvent event) {
ProjectileSource shooter = event.getEntity().getShooter();
Entity entity = event.getEntity();
if (entity instanceof Snowball) {
Iterator<Block> iterator = new BlockIterator(entity.getWorld(),
entity.getLocation().toVector(),
entity.getVelocity().normalize(), 0, 4);
while (iterator.hasNext()) {
Block block = iterator.next();
}
}
}```
then just spawn anvils around `block.getLocation();`
Final keyword for local variables or parameters
I need help with toPrimitive, I dont know what to do here
just encode the object into bytes
yea, but I dont know how to do that
why not store it as a string then use JSON to serialize it
bytearrayoutputstream
alex' pdc thing is saving stuff in byte arrays iirc and thats what hes using
like nbt does this
is there a way to extract the only value from a HashSet of guaranteed size 1 without using the same for(Object o : set) loop one uses for multi-entry HashSets
whut
to get the element out of the set when the size is 1
just do the loop
just for loop is the thing
ok
god ninja'd again
hehe
lmao i really cant type in the dark
we love tuples
fn balls() -> (usize, usize) {
(5, 10)
}
def balls() -> tuple[int, int]:
return 5, 10
meh
deez are some good names
just to verify but .equals() on hashMaps with the same set of key-> value mappings and the same key& value types results in true correct?
let deez_nuts = || (1, 2)
mye but its still not a method
didnt realise that one of your balls was half the size of the other
im trying to find mt keyboard ๐คฃ
should get that checked out
its a disease.. ๐ฅบ
didnt even notice that
thanks
record Tuple<T, Z>(T t, Z z) {}
// somewhere
Tuple<Integer, Integer> balls() {
return new Tuple(5, 10);
}
i think i have seen a Pair but no more
cant you cast it
probably
cool
there a simple way to get al corners of a BoundingBox?
how can a command be null? when i try to write this.getCommand("test").setExecutor(new testManager()); it recommends that i replace it with Objects.requireNonNull(this.getCommand("test")).setExecutor(new testManager()); why is that?
how can i convert a string like ยงxยง0ยง0ยงfยงfยง8ยง0TEXT to a minecraft chat component with colors?
TextComponent.fromLegacyText
don't forget to translate it
you can then get its json through ComponentSerializer
if the command isn't registered on the plugin.yml file, it will be null
BoundingBoxes might just carry 2 corners, do it the long way
EDIT: they just carry variables for min and max values
ooh that makes sense
String text = "ยงaยงb";
String json = ComponentSerializer.toString(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('ยง', text)));
How to set the head skin by id?
you recon it'd be faster do to arrays of min7max three times and iterate over them or to just do it manually?
premature optimizaiton ยฏ_(ใ)_/ยฏ
ima do the latter one then since its more readable
does someone know why BlockDropItemEvent doesn't work for chests?
iirc its because its the nbt dropped and not the block itself
assuming you mean the items inside
yeah the items inside
How to set the head skin by id?
you mean the head texture?
Its for 1.15 but it should still work
Need to know how to get a specific player's ItemStack skull? Watch the video above :)
Get a player head that works in all versions of spigot!
It doesn't matter if they joined your server or not!
------ Links ------
Download Eclipse: https://www.eclipse.org/downloads/packages/release/2019-03/r/eclipse-ide-java-developers
Download Spigot: http...
yep if not search it on google there are a ton of posts about this
I found something about GameProfile in Google, but I don't have it
thanks
i think i could use some help on this. ```txt
- Player is not op
- Player executes /gamemode creative
- I now want to alternate the command that will be parsed so that the player has op permission for this one and only this time
- So the player for this single one command is being treated as if op, but is not actually an op
you can do anything with coding
why not just execute gamemode creative <player> as console
i first thought of that but thats a nasty solution
what version of spigot you're using and what IDE? if you're using Eclipse and you're using the spigot API by the Build Path then you need to go inside your server folder and find a folder called bundler open it then open libraries and import everything from this folder to your Build Path and then you're gonna have the GameProfiles class
first of the messages then aint sent to the player who actually executed the command to say inform him of incorrect args
also since the sender is a console he MUST specify a target
why do you even need a command though? just directly change the gamemode of the player
funny iknow that, but i want to use the api
because i want to be able to specify certain commands for ranks that can bypass that commands admin permission check
and i dont want to use the permissions.yml
writing own implementations is like hardcoding in this case
Yall
Where do i grt help if my acc got stolen
Mojang's support, they'll ask for your TID.
#general
Ok.. well i have no idea why you want to do it the hard way
still stands
Dpigot acc
What is the reason for not using permissions?
Yeah that my question too
ik that ppl will call me out on it again sooo
im using the scoreboard teams to check for permissions
Spigot contains a class called PermissionAttachment
why would you ever need to over complicate something like that?? whatever your doing you need to rethink it because there is no reason for that
I dotn even understand why he is doing in that way and what is his goal
Please explain the goal of your project and why in the world you need such a work around
so theres the bashing xD
ive built a permission system which revolves around mc teams instead of spigots permission system
whats wrong about that
everything
the redundant call to retrieve the teams instance?
ppl here suggested to iterate trough offline players instead of using an indexed map
ive split the op system
in full access
and limited access
by severing the system into teams
removed the /team and /scoreboard command from the command map using reflection
overriden the /op /deop to fit my needs
and wrote a /rank system to modularly create new ranks based on teams
What is the purpose of this teams based permission system over spigots built in permissions?
now im at the point to create a permission system for the softcoded ranks which will be stored using serialization
permissions are player bound by default
u give players access
not groups
my system gives a usergroup access
and if that group gets deleted so do all priviledges for everyone from that team
so, can you help me or not?
Thats what permission plugins and group manager plugins or for
yea
i dont use other ppls plugins
ive written a system which directly binds permissions to ranks
hardcoded the full access admin, limited access admin and default user group
and softcoded other ranks
I get if you want to make your own but there is no reason for not using normal permissions you can simply set group members permissions to the group permissions
and overriden mcs vanilla methods via reflection accessing
its already finished and working
i only need to bypass admin checks for special groups not having admin power
but being able to access certain admin commands
Ok well clearly i can't change your mind and I don't understand your project so you will have to ask someone else
the question wasnt about how to work with teams or such
the question was how to access a pending command, and modify its value as to if the sender has had op at the time of sending the command
im sorry if i sound rude but so far ive only been called out for doing things the way i did, without the intention of providing help which happens all too often if u dont ask standard questions
The only way things i can think of would be either execute said command as console or giving the player op on command preprocess and removing it once the command is run
i think ive figured a way
im going to send it as consolesender
reparse the command on preprocessing so its always in the right format
What plugin is making me not be able to break blocks when not oped? world guard regions are set to allow block break
https://cdn.discordapp.com/attachments/962808760525533265/962811177690333224/unknown.png
say guy tries to execute /gamemode creative someoneElse
itll be reparsed to /gamemode creative ownName
and then send feedback to the executor of what has been executed
how exactly do you expect someone to find the answer between 40ish unknown plugins
throw them all out, put em in one by one
and then trial & error
til u get the answer
oh @unkempt peak this ^ right there is the answer as to why i dont use existing permission plugins
Hey do you konw how I can get the front face of a chest when I put him for put a sign on itt ?
idk exactly somewhere in the block data
get the instance of ur chest block
somewhere u can retrieve the info of its rotation
Yes I have try but I don"t find it
BlockFace
getFace(Block block)
Gets the face relation of this block compared to the given block.
something like that
Hi guys,
How do I make it so on maven <build></build> only the .jar file gets placed in the directory given?
Thx I have already try that but that not work like I want
Hey do you konw how I can get the front face of a chest when I put him for put a sign on it ?
I have try that but that didn't work
if (b.getBlockData() instanceof Chest) {
Chest chest = (Chest) b.getBlockData();
BlockFace face = chest.getFacing();
BlockState sign = b.getRelative(face).getState();
sign.setType(Material.OAK_WALL_SIGN);
((Directional)sign).setFacing(face);
sign.update();
}
so I'm getting this error ```
java.lang.NullPointerException: Cannot read field "glowkey" because "me.nrgking.imbuements.ImbuementsMain.glow" is null
at me.nrgking.imbuements.Imbuements.Glow.<init>(Glow.java:25) ~[?:?]
at me.nrgking.imbuements.ImbuementsMain.onEnable(ImbuementsMain.java:27) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_18_R2.CraftServer.enablePlugin(CraftServer.java:517) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at org.bukkit.craftbukkit.v1_18_R2.CraftServer.enablePlugins(CraftServer.java:431) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:612) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:414) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:263) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1007) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3468-Spigot-ffceeae-d53c4fb]
at java.lang.Thread.run(Thread.java:833) [?:?]
my main class is:
private static ImbuementsMain plugin;
public static Glow glow;
@Override
public void onEnable() {
plugin = this;
NamespacedKey glowkey = (new NamespacedKey(this, "glow"));
this.getServer().getPluginManager().registerEvents(new Glow(), this );
ItemStack glowitem = new ItemStack(Material.BOOK, 1);
ItemMeta glowmeta = glowitem.getItemMeta();
PersistentDataContainer glowdata = glowmeta.getPersistentDataContainer();
glowmeta.setDisplayName("ยงdGlowing Spellbook");
glowdata.set(glowkey, PersistentDataType.STRING, "glow");
glowitem.setItemMeta(glowmeta);
NamespacedKey glowrecipekey = new NamespacedKey(this, "glowrecipekey");
ShapedRecipe glowrecipe = new ShapedRecipe(glowrecipekey, glowitem);
glowrecipe.shape("EEE", "ECE", "EEE");
glowrecipe.setIngredient('E', Material.GOLD_BLOCK);
glowrecipe.setIngredient('W', Material.GLOW_BERRIES);
glowrecipe.setIngredient('G', Material.GOLDEN_CARROT);
glowrecipe.setIngredient('C', Material.BOOK);
Bukkit.addRecipe(glowrecipe);
}
public static ImbuementsMain getPlugin(){
return plugin;
}
my other class is ```java
NamespacedKey glowkey = ImbuementsMain.glow.glowkey;
@EventHandler
public void GlowHit(EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Player) {
Player player = (Player) e.getDamager();
if (e.getEntity() instanceof Player); {
LivingEntity victim = (LivingEntity) e.getEntity();
ItemStack item = player.getEquipment().getItemInMainHand();
PersistentDataContainer data = item.getItemMeta().getPersistentDataContainer();
if (data.has(glowkey, PersistentDataType.STRING)) {
victim.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 600, 1));
}
}
}
}
@EventHandler
public void GlowInteract(EntityInteractEvent e) {
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
ItemStack item = player.getEquipment().getItemInMainHand();
ItemMeta meta = item.getItemMeta();
PersistentDataContainer data = meta.getPersistentDataContainer();
ItemStack item2 = player.getEquipment().getItemInOffHand();
PersistentDataContainer data2 = item2.getItemMeta().getPersistentDataContainer();
if (data2.has(glowkey, PersistentDataType.STRING) && item.equals(Material.DIAMOND_SWORD)) {
data.set(glowkey, PersistentDataType.STRING, "glow");
item.setItemMeta(meta);
player.sendMessage(ChatColor.LIGHT_PURPLE + "Your weapon glows with an ethereal light.");
}
}
}
you never set glow
is it possible to add pdc data to scoreboard teams?
No
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html
The Method getHighestBlockYAt(int x, int z):
is it nowadays giving the highest block regarding to the original chunkdata or does it check when i run it with the current blocks build?
declaration: package: org.bukkit, interface: World
hey so i just started using spigot and i have a basic knowledge about java, anyways so i was trying to make a cooldown for my "FeedCommand", but i was getting this error!
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Long.longValue()" because the return value of "java.util.HashMap.get(Object)" is null at me.cqveman.learning_everything.commands.FeedCommand.onCommand(FeedCommand.java:32) ~[?:?]
my code:
`package me.cqveman.learning_everything.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.UUID;
public class FeedCommand implements CommandExecutor {
private final HashMap<UUID, Long> cooldown;
public FeedCommand() {
this.cooldown = new HashMap<>();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player p = (Player) sender;
if (!this.cooldown.containsKey(p.getUniqueId()) && p.getFoodLevel() < 20) {
this.cooldown.put(p.getUniqueId(), System.currentTimeMillis());
p.setFoodLevel(20);
p.sendMessage(ChatColor.YELLOW + "Stop eating you that much you dump fat.");
} else {
long timeElapsed = System.currentTimeMillis() - cooldown.get(p.getUniqueId());
if (timeElapsed >= 10000) {
this.cooldown.put(p.getUniqueId(), System.currentTimeMillis());
p.setFoodLevel(20);
p.sendMessage(ChatColor.YELLOW + "Stop eating you that much you dump fat.");
} else {
p.sendMessage(ChatColor.GRAY + "You're already too fat! Wait for another " + (10000 / 1000 - timeElapsed) + " seconds!");
}
}
}
return true;
}
}
`
plz help
also if i didnt provide enough info plz tell me!
Your hashmap doesn't contain the value
wym
it does
private final HashMap<UUID, Long> cooldown;
there
or do u mean smthing else?
im a beginner so plz explain
Basically the error is saying that you're calling longValue on null, which doesn't work
This is caused by you trying to use a cooldown time from the hashmap but it doesn't exist
Check if map containd value before using the value
o okay
I have coordinates stored in a file. How can i make it so that the coordinates only have 2 decimals instead of 14?
Also how can i do it with yaw and pitch?
DecimalFormat
Actually I think String.format("%.2f", numberHere) would also work
Yea it does
Hello, I'm trying to use Hibernate-jpa inside my plugin, can you guys have any ideas why ?
Okay so for example, essentials has a thing that stores the spawn location somewhere in the ram, or something idk if it's actually what it does..
My question now is, how do they do it and what is that method called?
It stores it in a .yml file
Ahhh okay, thanks!
No worries, feel free to dm me if you need help. I am working on the same thing right now
Hey i just started using spigot since 2 days and I have made an announcement in the chat when a player breaks a block, but now I would like to add a time in which that message is not sent because if he breaks the block several times it appears all the time in the chat as an announcement, can someone help me?
huh?
Player#sendMessage()?
So basically
Bukkit.getServer().broadcastMessage
you want to have a HashMap of UUID's that are players that you recently sent messages too with a integer value of the last time you sent the message to
Run through the HashMap every 20 ticks and decrement value by 1 (This is lightweight your just doing simple math) and when value is 0 remove UUID and value from the HashMap
From then its just a simple if hashMap.get(thatPlayersUuid) == null { handleStuffAndAddToHashMap(); }
or look into how WorldGuard does theyre message delays
Maybe add a boolean and check if it's a true for that player?
this is one way to add delay in between messages so its not sending the message every block break
okay
and where i can put the time i want???
hashMap.get(thatPlayersUuid) == null { handleStuffAndAddToHashMap(); }
i want 3 min with out sending this message
you have a runTaskLater in your class's constructor that runs every 20 tickets (1 second) and it just checks values of the hashmap
You just need to add values to hashmap when you send the message and from there the runTaskLater handles this all
i can maybe get some type of example spun up
one second
thx ๐
im so noob at this
I started yesterday watching videos to learn something
public class HandleDelayedMessage {
public final HashMap<UUID, Integer> playersInCooldown;
public HandleDelayedMessage(YourPlugin plugin) {
this.playersInCooldown = new HashMap<>(); // initalize hashmap
new BukkitRunnable() {
@Override
public void run() {
this.playersInCooldown.forEach((K, V) -> { // loop throughall keys and value in the hashmap
V--; // decrement seconds value by one
if (v <= 0) this.playersInCooldown.remove(K); // if seconds less than or equal to 0, remove player from cooldown
});
}
}.runTaskLater(plugin, 20L); // 20 = 1 seconds ie 20 ticks
}
public void addToCooldown(final Player player, final int seconds) {
this.playersInCooldown.putIfAbsent(player.getUniqueId(), seconds); // add player to the hashmap with a second cooldown, putIfAbset should be used to prevent duplicates, you can add ifInCooldown check as well if this method doesnt work for some reason, and just return if that methods true
}
public boolean isInCooldown(final Player player) {
return this.playersInCooldown.get(player.getUniqueId()) != null; // null check if player's uuid is inside the HashMap
}
}
i added comments
to explain everything
please make sure you read them
also do note theres prolly some syntax stuff wrong as i wrote this in discord
its pretty simple but hard to explain without showing code
Thank you so much
essentially you create a instance of this class onEnable and create a getter for it in your main class
theres likely better ways to handle it, but this is really lightweight and easy to understand
okay
either in the form of BukkitRunnable or Bukkit for Bukkit.getSchedular() or whatever that method name is
you can change to getSchedular() if you like
yes
no real difference though as to my knowledge performance-wise, just in looks
i change hashmap for this?
negative that HashMap is necessary
aaa
It stores how many seconds player have left in theyre cooldown session
You can learn more about them here if you dont know how quite they work: https://www.w3schools.com/java/java_hashmap.asp
have enough comments
i didn't want to just spoonfeed outright, had to explain ๐
should of seen my latest spigot post
shits like 1k words i bet
daamn was almost right on point
whats the error?
i cant send images
?verify
bad bot
you need to verify to send pics ie link your spigot account to discord
i forgot how its done
i send it to you in private
odd wonder why your IDE says that
what version of java?
Thats a warning right
if so you can ignore it
or
just remove the final declaration
anyone know how to make a actionbar appear when you type a command
and the solution that programs give me is this -> create 'playersInCooldown' in type 'new BukkitRunnable()'
@Override
public void run() {
this.playersInCooldown.forEach((K, V) -> { // loop throughall keys and value in the hashmap
the error is there in blond
blond
You just send the actionbar in the command?
remove this. or use HandleDelayedMessage.this
playersInCooldown isnt defined

