#help-development
1 messages · Page 2136 of 1
- listen for inventory click event
- check if it’s the correct inventory
- cancel the event
- clone the item they clicked on and add it to the players inventory
^
I want to check if this item can be added like if the player has enough inventory space to add the item in the slot but if I check if the returned hashMap is epty the items are already added
should I calculate the amount of items that can be given in a function?
Either that or you remove the amount they received (first one is cleaner tho)
Just check to see if the player has an open slot.
addItem() will also fill slots that aren't empty and have the same item
and if he doesn't but he has a slot that has this item and isn't full?
Hi, does anyone know how to get Packet Enums in 1.18?
This is true. Maybe you’d want to check the amount of the itemstack in the inventory and then add it if it has space.
i'll calculate the amount of items that can be given in a function
public static int getPullTime(ItemStack stack) {
int i = 0;
if (EnchantmentHelper.get(stack).containsKey(Enchantments.QUICK_CHARGE)) {
return i == 0 ? 25 : 25 - 5 * EnchantmentHelper.getLevel(Enchantments.QUICK_CHARGE, stack);
}
if (EnchantmentHelper.get(stack).containsKey(GizmosEnchantments.BALLISTA)) {
return BallistaEnchantment.DRAW_TIME;
}
return 25;
}```
Just wondering if a more skilled Java developer sees a glaring way to optimize this better than I have it
You can remove the if curly brackets if that counts 😛
Does that optimize it in any capacity?
nope
I don’t think it does. It’s just another way to write the statement
it will be compiled all the same.
Figured as much
This actually isn't spigot at all, it's a mixin that overwrites the getPullTime method for crossbow loading time and apparently it executes often
What exactly are you trying to optimize?
it increases readability but yes, performance wise it's the same
what should it do
Anyone?
Are you doing something with the value of EnchantmentHelper.get(stack)?
that's what retrieves the enchantments map
for the item stack
So the value is the level?
Correct
Alright wasn't sure from what I can see above
So you say it's called multiple times in very short intervals?
apparently for almost every tick that a crossbow is in someone's inventory
for each crossbow
o.o that sounds weird
that's how the vanilla game does it lol
That sounds like good exploit potential
even if it's not equipped or used?
I'm just overwriting the method that's present in the vanilla game
Like, that happens in vanilla apparently
On the first glance I'd blame that on an intern
working with minecraft's source code is eye opening lol
i would assume it only gets called when someone pulls one right?
Well as weird as it is: You could consider caching the result of your calculations per itemstack
is there a way to get the players in front of a player, in a certains radius, in a straight line in front of the original player?
like in his eyesight?
that's certainly something I could probably do, but since a very similar method runs in Vanilla it'll probably be fine as is
May I know what class you found that in? I wanna know if spigot optimized that
public static int getPullTime(ItemStack stack) {
int i = EnchantmentHelper.getLevel(Enchantments.QUICK_CHARGE, stack);
return i == 0 ? 25 : 25 - 5 * i;
}```
CrossbowItem.java
using yarn's mappings atm
and this is the unmodified method
yeah i want it so that if (from the pov of the original player) an other player is on the cross of the screen, it gets detected
let me know if spigot does optimize that
then i will just get the idstance
I'd love to know
but i know how to do that
i just dont know how to detect the players on the crosshair of an other player
you might consider shooting ray casts then.
shoot a ray from the original player's eye location in the direction hes watching. and see if it hits any other players
idk how to do that, do u have a link to a good tutorial on how to do it?
thought if you want to detect whenever this happens. you would need to do this on a time loop. which might not be good for performance
can I get the full package?
its fairly straightforward using this method https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html#rayTrace(org.bukkit.Location,org.bukkit.util.Vector,double,org.bukkit.FluidCollisionMode,boolean,double,java.util.function.Predicate)
declaration: package: org.bukkit, interface: World
net.minecraft.item.CrossbowItem
i dont want to detect when it happens its just when a player clicks a certain object it gives an effect to the players that are less than 20 blocks from him (ik how to do that) and on his crosshair
so then you are fine using the method i explained above
okey imma check it out thx !
You’d have to raycast every time the player right clicks then so long as they are holding the item.
honestly from looking at this it seems like it'd be more sensible to store the pull time of a crossbow as nbt
I got this and there is still the problem that the slot with the stack becomes 1
public void OnClick(InventoryClickEvent event){
if (event.getCurrentItem() == null || event.getClickedInventory() == null){
return;
}
if (event.getClickedInventory().getHolder() instanceof getCoinsInv){
ItemStack clone = event.getCurrentItem().clone();
ItemStack[] items = event.getWhoClicked().getInventory().getContents();
Player player = (Player) event.getWhoClicked();
int amount = amountOne(items);
if (event.getCurrentItem().getAmount() > amount){
player.sendMessage(ChatColor.RED + "You don't have enough inventory space!");
} else {
player.getInventory().addItem(clone);
event.getClickedInventory().setItem(event.getSlot(), clone);
player.sendMessage(ChatColor.GOLD + "You've been given coins!");
}
event.setCancelled(true);
}
}```
OH AND i should mention that i am using 1.8.9
ik bad version
but i dont have a choice
yeah im used to code in 1.16.5 but for this project i dont have a choice
how to do it then
class names should start with an uppercase character pls
you would have to create your own method to do it
oh my
hmmmmm any link to a method lmao?
read dis
Can anyone help?
the problem is explained here: #help-development message
Are you sure you are recompiling your code? Like is the message you receive correct? @harsh totem
tbh you should consider creating a proper gui framework. or use one provided by the community
wdym
I get the items and the message but the slot changes to be 1 rather that stack
on the tutorial, they say to do this :
Vector playerEntityVec = player.getLocation().subtract(playerEyeLoc);
but player.getLocation().subtract(playerEyeLoc); returns a location
cus ur calling it on the location
Vector entityLoc = entity.getLocation().toVector();
Vector playerEntityVec = entityLoc.subtract(playerEyeLoc);
its shown like this
.ohh yeah im stupid
honnestly, i didnt even know toVector() was a thing
thats gonna be usefull
yup
So that method is not optimized. Could be that is is called less. Still investigating
Since it's apparently calculated per item, it seems like it would be better for Mojang to throw that in as a nbt field, no?
I think you can simply leave out that line event.getClickedInventory().setItem(event.getSlot(), clone);
I would have expected them to only call it when necessary. Why calculate it permanently?
It's not like it would affect much of anything, and clearly it doesn't, but it does seem terribly unnecessary
Guys, tf is this
Might be why pillagers have had a history of being heavy on servers
because for every tick they're existing, the game is checking the pull time on their crossbow
but how would that fix the issue
Because you are overwriting what's inside the slot?
looks like a lot of effort for nothing, exactly
ok so i m a bit lost in the tutorial :
so this gets the vector :
Vector playerLookDir = player.getEyeLocation().getDirection();
Vector playerEyeLoc = player.getEyeLocation().toVector();
Vector entityLoc = player.getLocation().toVector();
Vector playerEntityVec = entityLoc.subtract(playerEyeLoc);
float angle = playerLookDir.angle(playerEntityVec);
and this the nearby entities:
player.getNearbyEntities(20, 20, 20)
but how do i combine the 2?
please
I feel myself getting sucked into the fabric black hole
well he explains the "angle" is bassically how close the cursor is to the entity.
not sure i understand
what are you doing?
nothing just starting up my server
no plugins?
the nearby entities makes sure you only check in a range of 20 blocks. you can change this
and where do i say wich entity is the second entity
yeah there are plugins but i didn't change anything and it does this, before it worked with no difference to the plugins
i know
i guess stop the server and try again
i know
wait a sec il make you a quick method
try to remove all plugins and see if its still there
you bassically want the closest entity to the cursor of the player right?
i'm trying to delete the worlds
yep !
uhm do plugins first
give me 2 minutes
thx lmao im so lost with this one
public Player getClosestToCursor(Player player) {
Vector playerLookDir = player.getEyeLocation().getDirection();
Vector playerEyeLoc = player.getEyeLocation().toVector();
Entity selected = null;
float selectedAngle = 5; //Set to 5 initially since the angle will always be smalled than this.
for (Entity entity : player.getNearbyEntities(20, 20, 20)) { // Search for all players in a radius around the original player.
if (!(entity instanceof Player)) continue; // check if the entity is a player.
Vector targetLoc = entity.getLocation().toVector();
Vector entityVec = targetLoc.subtract(playerEyeLoc);
float angle = playerLookDir.angle(entityVec);
if (angle <= MAX_ANGLE) { // check if the angle is less than some maximum number. you can change this to find how much you like. can be a number from 0 to PI, i suggest something like 0.2 - 0.5
if (angle < selectedAngle) {
selected = entity;
selectedAngle = angle;
}
}
}
//return the selected entity. or null if none were close enough.
return (Player) selected;
}
i think something like this should do the trick.
well. good luck 🙂
ok so there are a few parts that i dont get, but i think i get how it works
its pretty simple essentially right now it gets all entities in a 20 block range. checks if they are a players, then calculates the angle of the player looking at that entity. so the smaller the angle. the closer the crosshair is. then it just selects the smallest one it finds.
but i can understand if you dont understand all the math. vector math is a bitch 😄
i am juste not getting the float angle = playerLookDir.angle(entityVec);
that calculates this https://gyazo.com/0886713446ba5a3261ff2cea952e141c
ik this looks very scuffed xD
but it kinda explains it
the angle will return a number between 0 and pi(3.14), which you could convert to radians
but thats not rlly needed
so now you see, the smaller the angle
the better the match is
we dont need your spam here
Java Coding Conventions: https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
bro it wasnt even the whole code
chill
also ty ty
💋
so
i was doing a punch bow command
which it gives me a bow with punch 10 and INFINITE
it all works fine
but i made a lil listener which it disables the fall damage that is cuzed by shooting myself
and for some reason
it doesnt work
also i dont have any errors in console
im using spigot 1.8.8
dont save players in a list
mmmm
use a Set<UUID> instead
o okay
theres no reason to store pplayer objects instead of just their 'ids'
and a set wont allow duplicated elements
im wondering if a set has a better performance than an arraylist :/
i guesss not
I mean HasSet#contains is also just a lot faster than ArrayList#contains
Not when it comes to using .contains
I mean worst case scenario
hashset does not iterate, that is why you hash 😅
well
depends on collision logic but generally it does not want to iterate on contains calls
ArrayList#contains iterates from 0 to len-1 and .equals each until it finds it
do you guys separate your interfaces and classes from bukkit api as much as you can
it seems a good way to ensure backwards compatibility and cross server software support
by only providing impl classes
for example for bukkit api
Well you end up with a lot of "copies" from the bukkit api
is it possible to make a "then" after a try catch
e.g. representing a location, you now need your own interface
not finally
what would that then do ? 👀
question: I'm trying to make it so when the player clicks green wool within a GUI, it checks for a certain recipe and provides an item based on whether they have the correct resources.
I've managed to do this fine--however, I'm having an issue where the player must have a specific stack of a material (ie. 20 dirt) but would anyone be able to point me in the right direction to how I would make it so it would remove 20 dirt from any-stack of that material and not IF it's just a specific stack of 20?
Depends on what benchmark you’re talking about
for searching yes, iteration not.
also it eats memory like a chrome tab
since its based on hash principles
HashSet can insert and search in amortized constant time
ArrayList can iterate quickly but is somewhat slow for large amounts of inserts or removing by index, and searching is linear time
If you need to insert lots of values, but have the same linear structure use linkedlist instead
by default arraylist capacity is 10
if you add more than 10 that array which got filled will get copied by each index to a new array
which is expensive
especially with large lists
You can allocate a larger array if you know you’ll need it
cool kids just know the size of their array list beforehand
And the larger it grows the more you can insert before it needs to grow again
cool kids use primitive arrays in their impl hidden in private fields
Do arraylists grow by 10 each time it’s filled?
``` `` if (e.getCurrentItem().getType() == Material.GREEN_WOOL) {
boolean checking = true;
if (checking == true && sword == true) {
ItemStack swordstack = new ItemStack(Material.DIRT,20); // error: must be exactly 20
if(!(player.getInventory().contains(swordstack))) {
player.sendMessage("Invalid Resources");
sword = false;
return;
} else {
player.getInventory().removeItem(swordstack); ``` (here is the portion of code so far if anyone has the time to take a look. tysm^^ let me know if so)
All data structures have trade offs, that’s why it comes down to more complex choices than “A is better than B”
if data is fixed size
No
It typically doubles
What do you mean maxed out at 16
huh
The amount of buckets is based on increasing powers of 2, it’s not fixed
Like it uses an array to store linked lists, but that array is always 16
afaik hashsets expand dynamically if the load coefficient is higher than specific value
It’s not always 16 no
Idk I might be wrong about that
to amortize its time complexity
It grows as needed to reduce the number of hash collisions
The structure reallocates itself at runtime to keep the size of each LinkedList very small
Which is why it’s amortized constant time
Java in particular uses power of 2 buckets because it’s faster to compute the bucket index with bit operations than mod
Oh well i didnt knew that sets used linked lists
i thought these were just plain arraylists
but it makes sense i guess
it probably uses bucket technique where instead of placing the element at the place next to the collision index it chains it at the same index with linked list and then iterates the values until it finds the right one
right
that's why it uses it right?
fwiw, if all you're storing is a few UUIDs (even up to a thousand UUIDs or more tbh), the performance difference between an ArrayList and a HashSet are going to be negligible lol
Use the right tool for the job, but all things considered, you're going to save maybe a couple nanoseconds
sometimes i think hashmaps are slower than just plain old iteration
i mean
if you have lets say 10 values
some people still use maps for that
probably due to scalability
Every key that has a hashcode which evaluates to the same bucket goes in the LinkedList at that bucket
The larger the number of buckets, the less such collisions will occur
thats what I said basically.
Also depends on the key, if the key is an enum value you can use an EnumMap which will beat an ArrayList
in 99.9% of cases, it doesn't mater at all which kind of collection or map you use
whoever named those parts as "buckets" should burn to hell
indeed
i remember when i researched this
I thought
who tf would name something like this
a bucket
we don't talk about bukkits here, we're spigot
Lol
pepega
I love data structures, I used to help teach it at my university
which one's your favorite?
Map<String,Object> is definitely the most useful one ❤️
You can always use generics
in my case i would probably use it
since i already use it in my own generic interfaces
I mean, how will you use generics for that
i would let the impl define the type
A bukkit Location and a sponge whatever will not align
yea but how do you on your end then work with that
or API wise
like if your impl says I expect a bukkit locaiton here
what API type do you provide
Maybe if you have a base interface that acts like an adapter (for locations), then you have specific implementations that prototype the underlying location delegate. Which could be useful if you need to use bukkit specific shit in conjunction with your "common" abstraction or sth. Though this sounds like a contradiction in terms of design but yeah.
thats what i would do
i would create an generic interface
then implement it with bukkit specific calls
I mean yea then you end up with
interface YourAPILocation {
double x();
double y();
double z();
}
interface BukkitAdapter {
YourAPILocation location(org.bukkit.Location location);
}
at which point, yea you are writing "copies" of your spigot api etc
which is fine if you explicitly want to support multi version
but if you are not actively planning on it, I don't think I'd call it a good design for a spigot plugin api
hey kids
hey adult
what happens if i contribute to a repo
you get github street creds
interface LocationAdapter<O> {
double x();
double y();
double z();
O prototypeDelegate();
}
class BukkitLocationAdapterImpl implements LocationAdapter<Location> {
Location prototypeDelegate() {
return loc.clone();
}
}
record BukkitListener(Platform<LocationAdapter<Location>> platform) implements Listener {
@EventHandler void onEvent(var e) {
var location = platform.process(e.entity()).prototypeDelegate();
}
}
this looks like shit design but hey
and he contributes after i do without the changes i did
guess if you're into generics then perhaps
there'll be a merge conflict
so
i dont get what that means :o
well ii dont really contribute to other projects i dont really know many of the concepts
if there's a merge conflict, the repo owner who wants to merge your (now outdated changes) basically gets a GUI/text file and then they have to manually "mess with that file"
you don't have to worry about it until it happens. and when it happens, you'll see how it works
maually?
i'd love to show you an example but I can't
it's really nothing special
it takes like 2 minutes and you're done, most of the time
oh ok
if two changes are incompatible for instance if they both change the same set of lines then you manually have to go through that in principle to tell how the changes are supposed to be applied
and the other times it’s stuck for hours
if you need hours to resolve merge conflicts, then the person who committed changes fucked up though
commits are always supposed to only change small things
i remember one time someone accidentally changed the indents on every annotation in a multi-module git project somehow
different threads accessing the same thing
ugh wat
that took a while to fix
I mean to some extent
and changes overlap
then just reject that pull request and tell them to not change stuff they didN't actually change
it makes complete sense
since individual computers have their own threads
i still think it’s on the weird indents now since they added more than me
but like you could probably come up with hundreds of examples similar to the ones concurrency brings
myea or avoid locks with atomicity if possible :p
?
Move to another channel, this isn't the one for this type of chitchat
?kick @gritty hawk stop trolling
Done. That felt good.
Does someone know?
why does setHealth not make the player screen move as if they're taking damage
how can i make it be realistic
damage the player by calling damage(double)
double?
Yes. The data type
create a EntityDamageEvent?
LivingEntity#damage(double)
https://github.com/Silent-Program/SimpleGraves
Anyone wanna just nitpick, and tell me everything im doing wrong
make your instance variables in SimpleGraves.java private
and final if possible
you could encapsulate that map in another class
myeah but its mostly to write code defensively
I used it in the previous version
But changed a bunch of stuff
I mean sure, but there's this principle called single responsibility principle
and it states, that a class must only have one major reason to change thus it most only carry one significant responsibility
usually managing a Map implementation is considered a big enough of a responsibility such that it deserves its own class
Really?
also I'd say use this whenever applicable, yes not everyone uses it
but for readability its extremely nice
i agree, i usually do. But i took a long break before writing this
yeah
also, register the listener in onEnable
not in the constructor of Listeners.java
it doesnt read better
you couple instantiation with registration
your SimpleGraves.java is the class that should register things accordingly
therefore that logic in principle should belong to your SimpleGraves.java
for you method onPlayerDeath, I'd certainly reduce it into smaller methods/functions
big functions are rude to the reader
or well, functions that do a lot of things
because if we want to know what they do, we need to read the entire funciton
yea
Put everything in one method as a new way to "obfuscate" code
so if you can, find a more specific name
For DataManager?
consider LocationRepository or LocationRegistry more concrete names
oh yeah
DataManager
whatever, but yeah manager in general
Well it manages the data config
Sounds like a StorageFacade then
StorageFacade?
yes
Not understanding the facade part of that
a facade is when you have a (single) class that simplifies logic of several other classes by encapsulating instances of those classes
Data config;
SimpleGraves plugin;
File configFile;
ObjectMapper om = new ObjectMapper();
the more low level, complicated, implementation specific stuff
got it
your methods
initializeConfig
saveConfig
getConfig
is like a nice button menu
anyway this is very nitpicky
but yeah you asked for it
Lol yep
so allow me to continue
Go ahead
Why?
Many methods didn't throw exceptions when they failed, so it was impossible to obtain a useful error message. For example, if a file deletion failed, the program would receive a "delete fail" but wouldn't know if it was because the file didn't exist, the user didn't have permissions, or there was some other problem.
The rename method didn't work consistently across platforms.
There was no real support for symbolic links.
More support for metadata was desired, such as file permissions, file owner, and other security attributes.
Accessing file metadata was inefficient.
Many of the File methods didn't scale. Requesting a large directory listing over a server could result in a hang. Large directories could also cause memory resource problems, resulting in a denial of service.
It was not possible to write reliable code that could recursively walk a file tree and respond appropriately if there were circular symbolic links.
Odd that it would be fixe don the other ones and just left ignored on File.java
mye
well it probably will get deprecated sooner or later
as soon as more apis and libraries have favored Path to File
the name of your class Listeners.java also suggests the class is held responsible for several significant accountabilities
I dont think the writevalue method for the object mapper will allow me to use path
it is
it does
because you can pass a Writer or an OutputStream
anyway thats all I believe
there are some other things
but those nitpicks wont even benefit you
since you're not doing enterprise :3
public void onPacketReceiving(PacketEvent event) {
PacketContainer packet = event.getPacket();
if (event.getPlayer().getVehicle() == null) {
return;
}
if (!(event.getPlayer().getVehicle() instanceof ArmorStand)) {
return;
}
ArmorStand armorStand = (ArmorStand)((Object)event.getPlayer().getVehicle());
float forward = ((Float)packet.getFloat().read(1)).floatValue();
float side = ((Float)packet.getFloat().read(0)).floatValue();
Player player = event.getPlayer();
armorStand.setHeadPose(new EulerAngle(player.getLocation().getDirection().getY() * -1.0, 0.0, 0.0));
float speed = 1.2f;
if (forward > 0.0f) {
this.goForward(armorStand, speed);
}
else if (forward < 0.0f) {
this.goForward(armorStand, -speed);
} else {
armorStand.setVelocity(armorStand.getLocation().getDirection().multiply(0.01F));
}
}
public void goForward(ArmorStand armorStand, float speed) {
armorStand.setVelocity(armorStand.getLocation().getDirection().multiply(speed));
}
public void goBackward(ArmorStand armorStand, float speed) {
armorStand.setVelocity(armorStand.getLocation().getDirection().multiply(speed));
}```
Does someone know why this is not working?
Im trying to make a packetadapter with protocollib for "flying" on a armorstand.
If you are riding an armorstand and go forward then you would go forward to the direction you are looking at
When im riding a armorstand it just does nothing now
I also depended protocollib in the plugin.yml and i implemented this class in the main
I assume this instance of ArmorStand is a normal entity, so no custom entity?
And it has gravity on?
how are you registering it?
If the armorstand has either noAI or noGravity set to it, setVelocity won't work
Is the scope provided in the pom?
hello,do you know how hypixel made for example on skyblock now basiclly map,so if you click on map and for example click on your island it teleports you
is that hard?
i mean this
Man that is one low-res image
Guys, how can I code a countdown? I can't think of how
I want to put the time in a scoreboard using the PlaceHolderAPI (I can this, but the countdown doesn't occur to me)
thats clientsided
Setgravity is set to false
And it is an armorstand that you are on, so instance of armorstand would work right?
Ouu
the armorstand is set on as.setGravity(false);
I wish we could do stuff like that serversided lol
setGravity removes gravity and velocity ticking entirely so uhh
teleports still work
So i need to set gravity to true? or not
setting it to true makes the stand fall
you can apply counter-velocity or use fancy nms and override some tick methods
or you can just teleport it
Ahh then im going to use teleport instead of velocity
how do i make an item frame invisible, it doesn't seem to have a method despite that being added 2 years ago
nvm
itemFrame.setVisible(false) ```
armorStand.teleport(armorStand.getLocation().getDirection().multiply(1.2f));```
Does someone know why the teleport part doesnt work?
I get this error: `The method teleport(Location) in the type Entity is not applicable for the arguments (Vector)`
i also cant use setVelocity because then it just doesnt teleport the armorstand
declaration: package: org.bukkit.util, class: Vector
Thank you! I will try it :D
Now when i try it in minecraft it doesnt teleport the armorstand, but the debug message works so if the code worked it should have teleported the armorstand
armorStand.teleport(armorStand.getLocation().getDirection().multiply(speed).toLocation(Bukkit.getWorld(armorStand.getLocation().getWorld().getName())));```
This is my code now, and i get no errors now
Guys to convert this countdown timer to bukkit plugin (because I can't use while) i need to use one Runnable to Subtract the time right?
armorStand.setRotation(player.getEyeLocation().getYaw(), player.getEyeLocation().getPitch());
Does someone know how i could do this on 1.12.2? Because armorstand setrotation doesnt work
you look quite dapper in your profile picture 🧐
Damn you’re not kidding
ikr??
Thank you
haha no problem man
Okay, I see the HeightMap type in the Spigot API, but I'm not sure how to obtain a HeightMap for a particular chunk. Anybody know?
I believe its mostly used as an argument for the api functions, not really something thats returned?
can one use the data generators to generate a dimension codec?
pretty sure you can generate custom dimensions through packets 🤔
There was a plugin for it on 1.16.5
Math.
When i try it in minecraft it doesnt teleport the armorstand, but a debug message works so if the code worked it should have teleported the armorstand
armorStand.teleport(armorStand.getLocation().getDirection().multiply(speed).toLocation(Bukkit.getWorld(armorStand.getLocation().getWorld().getName())));```
Anyone know of a way to make custom player skulls in 1.18?
whats the difference between itemstack.getEnchantments() and meta.getEnchants() ?
how to loop in radius x of a location?
first one is a shortcut in principle
Someone knows why armorstand doesnt tp
to set a block to something at a location u have to create a new location right
is there any other way
you dont need to write armorStand.getLocation.getWorld
you can just use Entity#getWorld
just use skull creator api
and you don't have to handle nms shit
Thank i did it!
But i still have the problem that it doesnt teleport the armorstand, maybe because it has an passenger i dont know
public class ArmorstandMovement extends PacketAdapter {
public ArmorstandMovement() {
super(JavaPlugin.getPlugin(Main.class), ListenerPriority.HIGHEST,
new PacketType[] { PacketType.Play.Client.STEER_VEHICLE });
}
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
PacketContainer packet = event.getPacket();
Entity e = player.getVehicle();
if (e instanceof ArmorStand) {
ArmorStand armorStand = (ArmorStand) player.getVehicle();
float forward = ((Float) packet.getFloat().read(1)).floatValue();
float side = ((Float) packet.getFloat().read(0)).floatValue();
armorStand.setHeadPose(new EulerAngle(player.getLocation().getDirection().getY() * -1.0, 0.0, 0.0));
float speed = 1.2f;
if (forward > 0.0f) {
event.getPlayer().sendMessage("[debug] forwards");
armorStand.teleport(armorStand.getLocation().getDirection().multiply(speed)
.toLocation(Bukkit.getWorld(armorStand.getWorld().getName())));
} else if (forward < 0.0f) {
event.getPlayer().sendMessage("[debug] backwards");
armorStand.teleport(armorStand.getLocation().getDirection().multiply(speed)
.toLocation(Bukkit.getWorld(armorStand.getWorld().getName())));
} else {
final Vector f = armorStand.getLocation().getDirection().multiply(0.01F);
armorStand.setVelocity(f);
}
}
}
}```
This is the whole class, it sends the debug message when i press W or S but it doesnt teleport the armorstand
if you're riding it
then you can't teleport it
you could set the gravity to true while moving
Ooh alright thanks! Then i will do that
hyy there is a plugin BedWars1058 - OpenSource 22.3.4 which is open source can anyone please add 1.18.2 support in it?
Guys to convert this countdown timer to spigot countdown plugin (because I can't use while) i need to use one Runnable to Subtract the time every 20L right?
if anyone can that will be so helpful
?scheduling
or can anyone just tell me how to import a plugin with source code in eclips?
It's not as easy as it seems lol
ya ik i tried many times but there always some dependency missing 😦
are you using maven
who me?
yes
as a modder from forge/fabric i normally use an Identifier/ResourceLocation for item ids
like, minecraft:diamond_axe would be for diamond axe
is there anything similar?
NamespacedKey iirc
You mean part of spigot?
Pretty sure you can still use ResourceLocation if you use NMS.
But yea, NamespacedKey is part of the API.
i need a tutorial on NMS
yeah good luck
i have it set up in my thing but i don't want to use it
like, is there mixin? no? then why do I care
spigot is the api ontop of nms
yes
so use that
i do use spigot
anyway, thanks for NamespacedKey
i was using Enum#name because the Material was an enum
Material might not be an enum for long. Do not rely on that behaviour
Do you have any tutorial about guis
Caused by: java.lang.NoClassDefFoundError: net/minecraft/world/entity/npc/Villager
how do i fix my project to get the latest buildtools stuff
i have created a bossbar for a mob but when there is more that 1 mob of that kind it justs confilcts instead of creating new bossbar?
Wdym
How can i add attributes
wym attributes? to the bossbar?
i sended better pic xD
Read the Release notes and you get what I nean
I think you need nms for that
I usually just modify the EntityDamageByEntityEvent since I already have a setup for my mobs to be identified
alternatively you can apply potion effects
hey, i am using hashmap to give each player an integer. Problem : when the player disconects and reconnects, the number is reset, how to solve that
use the UUID
what do you do when a player leaves?
I suppose the player instance wouldn't be the same when they reconnect, so using the player as a key is not the best thing
Hi my plugin does crash and i don't now what it is but it goes som hours and then it crash
send the errors it gives you
?paste
it does not give me any
so instead of :
public HashMap<Player, Team> team = new HashMap<Player, Team>();
I'd do
public HashMap<UUID, Team> team = new HashMap<UUID, Team>();
then what does it say?
nothing it yust crash the server
yup
how big is your plugin? send some code you think might be crashing it in the paste thingy above
it's big
look up the logs
probably some infinite loop
i got a message that is be send every hour
please look up the logs
of your server
the plugin does not send any errors or anything the server does stop
i don,t even now if it's my plugin
there has to be an error if it crashes
send the logs
i can't bacus i am yusing multicraft and the logs is not readebel
ok
can you recreate the crash?
but it now that is a command that sends in consol in every 2 min /list but don't now how to disebel it
how many lines is your plugin? if its like 200 lines I think its easier to read through the code
debug
thats just a multicraft thing
u might be able to disable it googlin something
And make it private final and dont write any getters/setters for it while you are at it
Oh, ok
Already tried that but then also nothing happens that
didnt imagine already sent the solution?
Where? I didnt saw it
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>```
why am i can't use vault api?
i have some errors but everything should work fine
armorStand.setRotation(player.getEyeLocation().getYaw(), player.getEyeLocation().getPitch());
Why isnt this working? I get this error
The method setRotation(float, float) is undefined for the type ArmorStand
I think this means ur server version isn’t recognizing #setRotation as a method
Meaning the version in ur ide isn’t the same as the server
But i mean i get the error in my ide
I wonder what's the best way to parse console commands in my discord bot. I currently have a parseCommand(...) method. It's possible to run commands both from console (terminal) and of course through actual discord messages. But I'm wondering whether the "console" part should be inside my bootstrap main class or directly inside the bot's "main" class. This is my current bootstrap "main" class, which only creates the bot instance, and then listens for incoming input, I wonder if that's a good solution or not:
Simply the method with that parameters doesn't exist
Then it means it’s not a method
Do you maybe know a alternative? Because my friend send this but i think he uses another version i use 1.12.2
Maybe set location?
Use the correct parameters
so did anyone knows what is wrong with this maven?
Every Entity has a setRotation(float,float) method. Unless you are using a 8 year old outdated spigot version
what's your version?
Jep i use 1.12.2 😂
But the server i work on is 1.12.2 so i have no other choice
it would be helpful to actually SEND US those errors
dependency not found
yeah then you have to use the teleport method
basically clone the location of the armorstand, change pitch and yaw, then teleport it to the new location
Aah alright, then i will do that, thank you!
yeah vault is using jitpack which sucks very hard. try to run mvn clean package -U
click on this button
then enter mvn clean package -U and hit enter/return
i can't
Why
in general there is probably a better solution but for the "where to put it?": i would place it in the bootstrap main method since, how i understood it, you execute the command to control the bot and not to "be" the bot
yeah that's true
alrighty, then I'll keep it in the bootstrap class, thx
why not?
i can only edit configurations and run blockEconomy
no, you can also just click the button I sent a screenshot of
i clicked
is it intellij?
yes
leaked
no, you
fuck
i am unable to use nms packages even tho i have install the build tools.What to do?
Did you declare it as a dependency ? 👀
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>```?
like this
you want the mojang mapped version no ?
i have exit code 1 not 0 so something is wrong
1.18.x
that's not an answer. You probably want the mojang mapped versions
follow the maven examples in the second post
ok
tbh I think my blog post is a bit easier to follow to get mojang mappings working 😛
https://blog.jeff-media.com/nms-use-mojang-mappings-for-your-spigot-plugins/
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
``` i have this error
read this pls @dark arrow
man is literally on a self promotion hustle 24/7
you somewhere typed "packge" instead of "package" in your pom.xml
I just want to help people lol
also did you just assume my gender? triggered
ok
ugh shit the squirrel came into my apartment again
sorry for that image xD
I have to make it leave brb
not what I meant
mfnalex's blog >
oh boy
How can I detect if player collide or bump into a wall?
I don't think there's an event for that. I fear you'll have to schedule a runnable every tick, then check if the player's boundingbox intercepts/"touches" with the nearby blocks' bounding boxes
maybe there's better solution, if so, I don't know it yet
Damn, sounds so complicated
Simple but expensive resource wise
again related to JDA:
public static void deleteMessage(Message message) {
if (message != null) {
new Thread(() -> {
try {
message.delete().complete();
} catch (Exception ignored) {
}
}).start();
}
}
Is there a better way of doing this? I cannot instantly delete the message because then it might throw an "Unknown Message" exception when the message was already deleted by other means. I have to use the blocking "complete()" instead of the async "queue()" method because otherwise I cannot catch the exception, so I wrapped it up in a thread myself
I need to deal with nms right? to get the bounding box
no
that's API
someBlock.getBoundingBox()
someEntity.getBoundingBox()
then you can use BoundingBox#intersection or BoundingBox#overlaps (probably the first one is the only one that'll work)
the resulting boundingbox will probably have a width, height or length of 0, but at least ONE of those values will be a positive number
if yes, there's a collision
void queue(@Nullable Consumer<? super T> success, @Nullable Consumer<? super Throwable> failure);
Alright, thank you so much. I'll play around with it a little bit.
yeah but that's basically the same, isn't it? I was basically looking for a way to check if a message even exists before I try to delete it, but haven't found anything :/
the reason why I ask this is that I have a config option "delete-command-messages" that can be true globally, so all command messages get deleted instantly. however, I also have some commands where I wanna delete the message, regardless of the global setting, so I am basically calling this method twice in some cases, yielding this exception :<
unfortunately there's a Message#delete() method, but no Message#isDeleted()
np, I have to add that I never tested this, I am not sure if it'll work. Let me know pls 🙂
JDA operations normally "end" with being in a queue
by invoking queue() at the end
afaik there is no other way to do it. Pretty sure it's a discord API issue since a lot of people say it's bad
isnt that possible over the guild/channel?
Is there a CommandExecutedEvent?
I need to check if a command is targeted at players/entities in other worlds
I know, but since queue doesn't let me catch exceptions, I've used "complete()" this time
hm maybe, I'll check it
doesn't seem so
The error part of queue doesn't catch the messagenotfound error?
oh you mean the queue(Consumer,Consumer) thing? I haven't tested that yet, yeah that will probably work
It looks a bit nicer I imagine. Sadly I'm not sure there is any other way to do it
yeah it does indeed look nicer lol
public static void deleteMessage(@Nullable Message message) {
if (message != null) {
message.delete().queue(unused -> {}, throwable -> {});
}
}
and it works, too
I still don't like it, knowing that it will throw exceptoins in 50% of the time :/
Hello team ! How is it possible to do : I have a maximum click on block of 20 click. I would like to show in action bar how many time the player have clicked on the block, is it possible ?
#help-server pls 👉 👈
20 clicks per player and block or 20 clicks per block?
per player and per block
you could create a Map that stores the amount of clicks per player and block
sth like
Map<Location,Map<UUID,Integer>>
i think uuid,map<location, integer>> is better
doesn't really make a difference imho
thanks for your help
well you can easily access all of the player's clicked blocks
i guess the same could be said about the other weay
yeah true, but from what they told, that's not needed
but yeah maybe they need it later, so yeah, doesn't really matter which way the maps are nested 😄
So BoundingBox#intersection will throw an IllegalArgumentException if the BoundingBox doesn't overlap, it uses BoundBox#overlaps too, so I guess using overlaps is the better option here.
Is there any way to check if a command executed is targeted at a player from another dimension/world? I want to make so that @a only works on players in the same world
what if it is a command block?
Oh well but if they only „touch“, i dont think that they‘ll overlap 😦
what event do I use
no event
command executor
ive never done command block command support before
but commandsender should be an instanceof something that a commandblock is
it might have a special class CommandBlock
you could look into it
If only touching it the overlaps will return false
Is there a way to get the targeted players?
yeah with arguments
Let me explain what I need again
I want to check every time a command is run if the targeted players/entities are in a different dimension/world
I have trouble getting every command and finding the targets
ik
but different commands have different places for arguments
its not a player
You answered it yourself
I fear you'll have to do the math yourself then
although I have no idea how, lol
How do you even see the blocks' bounding box?
https://prnt.sc/UgtP52QRY8R0 what am i doing wrong ?
theres no clicked block variable
you are passing three arguments instead of two
ofc there is, they just use a fucked up color scheme
I was testing it with entity, and now with blocks it doesn't send anything.
hm that's weird. block.getBoundingBox() should work fine
no theres no variable called clickedBlock
I will try
i think you meant to use block
bruh obviously there is, look at the first line
clickedBlock is my Map
I want to know if player bump into a solid block, is it possible with that?
whats not working
it even says "exepcted 2 arguments" 😄
yeah as said, you should be able to check if the block's boundingbox has a common "border" with the player's boundingbox, and if yes, there's a collision
So how can i write ?
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
yeh
yep
@EventHandler
public void actionBar(PlayerInteractEvent e){
Player p = e.getPlayer();
Block block = e.getClickedBlock();
Location loc = e.getClickedBlock().getLocation().add(block.getY(), block.getX(), block.getZ());
int clickedAmount = 0;
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.DIAMOND_BLOCK)){
clickedBlock.put(p.getUniqueId(), loc, clickedAmount);
}
}
clickedBlock.put(p.getUniqueId(), clickedBlock.get(p.getUniqueId()).put(loc, clickedAmount);
sorry im playing a game rn cant explainw ell
yes don't worry i will try
It only overlaps when player is inside the block
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.DIAMOND_BLOCK)){
Map<Location,Integer> map = clickedBlock.computeIfAbsent(p.getUniqueId(), uuid -> new HashMap<>());
int existing = map.getOrDefault(loc,0);
existing++;
map.put(loc, existing);
clickedBlock.put(p.getUniqueId(), map);
}
^
omg, nice, thanks i will try that
yeah, you'll have to manually do some math
Damn, that sucks, how about checking the distance?
won't work
check the link I sent, and expand it to work with 3 dimensions instead of 2
oh wait
the link I sent is for overlapping, too
I googled "collide" and not "overlap" >.<
sorry I don't have time to write this out, but basically yo uhave to check if any of your minX, maxX, minY,minZ, ... is between the other boxes' minX,maxX, etc
and then do it for all three axis
e.g. collision is true when player's minX OR maxX is BETWEEN the block's minX and maxX, AND if the player's minY OR maxY is BETWEEN the block's minY and maxY, and same for Z
(not sure though lol)
yo @summer scroll
I have an alternative solution
that is extremely simple
enlarge the player's boundingbox by 0.0001 to EVERY side
now you can check if they overlap
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.DIAMOND_BLOCK)){
Map<Location,Integer> map = clickedBlock.computeIfAbsent(p.getUniqueId(), uuid -> new HashMap<>());
int existing = map.getOrDefault(loc,0) += 1;
map.put(loc, existing);
}
that better
isn't that exactly the same?
shorter
damn, you're genius it works!
no beacause you put evertime in map so we add process
oh yeah, shorter always better
😄
can you uwu for me?
uwu :3
hot
It's snorkel time! ٩(- ̮̮̃-̃)۶ uwu :3
no 😂
fun fact: I once dated a guy, and... okay I better shut up
obv. yes. do you know the cipher project and its performance?
How can I get the "anvil uses" of an item. I cant find anything in the docs that seems relevant.
ItemMeta#getRepairCost() or sth like that, IIRC
declaration: package: org.bukkit.inventory.meta, interface: Repairable
ahh I see, thanks!
Wow that realy fun
check out my "angelchest within 5 lines" implementation lol
that is beautiful
What the
I want to let the armorstand im riding fly where i look when im pressing W but now it only goes this way:
https://gyazo.com/da8f35d434e79ca773b3b8a28c7fe045
This is my code: https://hastebin.com/uzenukeyek.java
Can someone help me?
thats because you take the armorstands direction
not the players one
and well your goForward and goBackward methods are effectively the same
as well as goBackward is never invoked anywhere anyways
Ooh yes i see
Now the direction flying works, but when im entering the armorstand i cant go forward at first, if i go backwards 1 time then i can go forward
is it possible to turn a 1.17 Structure into a schematic
i am unable to use nms even i have installed the build tools and changed the repsotory pls help
any errs in your maven project?
why wtf? 😄 that project has rules: a maximum of 3 ; per line lol
and no contributor must change/add more than 25 lines in total (except for imports and package declaration)
so yeah lol
Nope
I only get errr if i tru to use nms package
I mean if there is any errs when you try to import NMS package as a maven dependency
Nope
Are you guys able to access spigotmc.org?
rip spigot
then you mean you can't use any classes provided by NMS?
Yup
which classes you are trying to use when it occur errs
and have you check those NMS libs been imported correctly?
new ItemStack(Material.WAIFU)
I downloaded build tools and changed spigot-api to spigot
Entity class,when I try public name() entends Entity(NAME) it gives error
can you show us your pom.xml?
I think you should do classifier when you import NMS
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
</dependency>
like this one
so i should replace it with the old one?
<classifier>remapped-mojang</classifier>try add this line down below the <scope>provided</scope>
ok
error
which kind
Could not resolve dependencies for project me.Sammu212:CustomBossssssss:jar:1.0-SNAPSHOT: org.spigotmc:spigot:jar:remapped-mojang:1.18.2-R0.1-SNAPSHOT was not found in https://hub.spigotmc.org/nexus/content/repositories/snapshots/ during
i dont think it could find the mojang remapped there
Have you ran BuildTools with the —remapped flag?
hu?
yes you need to do that
how?
the post on spigotmc can't be access right now
java -jar BuildTools.jar —rev 1.18.2 —remapped
umm it has started with different command
what to do
Well if you don’t specify a version it will default to the latest build anyways.
ohk
i got scared
i wanted to do for latest only
java -jar BuildTools.jar --remapped
it completed
it now compliles with no error but i still cant use the nms package
can you use ServerPlayer class
if you can means NMS worked
nope i cant
i did it already
have you checked your external libraries to make sure NMS packages were imported correctly?
which libraries?
there is no library called nms or spigot
it should has libs like this
there is a spigot api library but i dont think its useful
then you should try reboot your IDEA or rebuild your maven project
which kind of plugin, IDEA's plugin?
I don't think that would affect your NMS package using or importing
idea
did you 100% run build tools with the --remapped option in the command line
i got a similar error when doing that myself
and my issue was i ran build tools without the remapped option
for some reason my death is not getting registered even tho i got killed by someone
I think you should try rebuild your project first
on line 64 im subtracting the death count by 1 when the player is killed by another player
but for some reason my death does not get registered tested it twice
if you actually did, then it would have worked fine though
intellij or maven doesn't randomly break for some people
do you know why me death is not registering
👻
Hello ! I have one class with all my arrayList, i use these arrayList in different other class, I would like to check when i click on an item, if the player is already in a arrayList (UUID) if it is not, put in the specific ArrayList(associate to the item..), Is there any fast method to check that ? Is it possible to use a switch ?
contains?
use a HashSet, it wont allow duplicates and you can try Set#add and it will return true if it could be added
Set<UUID> ye
I am not sure about what you told.
I can try
$YOURARRAYLIST#contains() ?
anyways is it possible to have a gui, made in C# code, which communicates with java code?
My english is bad x) For exemple, I have 20 arraysList like public static ArrayList<UUID> kit1 = new ArrayList<>(); in a specific java class, i would like in a InventoryClickEvent check if the player is in one of 20 arrays list and if it's not in one, put in a specific
oh
then you can use HashMap<String,List<UUID>>
Map<String,List<UUID>> listMap=new HashMap<>(){{
put("type",new ArrayList<>());
}};
Java Native Interface may help?
and when you want to use do listMap.get("type").contains //check
and when you want to use do listMap.get("type").add //add
oh nice i didn't know that it's possible to do that
just try it
dont do that lol
memory leaks go brr
lol
and it looks ugly too
xDDD
if you think it looks ugly
well mye i might want to look for an implementation for that
you can use enum instead string
"memory leak"
In fact the arraylist won't gets remove
if you put 20 arraylist it same
so you don't need worry about memory leak
no
I actually don't understand your question in the first place
too less information
a static block exists for a reason
and you can add log for checking code is working
heh
also pls do not ping me unless you're replying to any of my messages
@tender shard 
pls don't
lmao
How do I save a player's inventory when they leave (im using PlayerQuitEvent), and reload it later when the join back?
save the contents to a file or database or somthing
there's a reason why I don't like useless pings
one tag more or less :p
why do you need to do it?
that makes no sense tbh
they automatically get their inventory back when they join
yeah
run through every item in the player's inventory, and store them in a yml file?
serializing items would be a better idea tbh
lol ye
but inventory can't
public static String toYML(ItemStack i) {
YamlConfiguration yml = new YamlConfiguration();
yml.set("i", i);
return yml.saveToString();
}
public static ItemStack fromYML(String s) {
YamlConfiguration yml = new YamlConfiguration();
try {
yml.loadFromString(s);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
return yml.getItemStack("i");
}
public static String convertItemStackToString(ItemStack what) {
return Base64.encode(toYML(what));
}
public static ItemStack convertStringToItemStack(String data) {
return fromYML(Base64.decode(data));
}
public static String convertItemStackArrayToString(ItemStack[] what) {
List<String> r = new ArrayList<>();
for (ItemStack i : what) r.add(toYML(i));
return Base64.encode(StringUtils.join(r, "(ITEM)"));
}
public static ItemStack[] convertStringToItemStackArray(String data) {
return Arrays.stream(Base64.decode(data).split(Pattern.quote("(ITEM)"), -1)).map(ItemStackSerializer::fromYML).toList().toArray(new ItemStack[0]);
}
loop over the contents lol
so if you wanna store item you need to store them one by one
?paste
yah but my pom.xml is same as that
ye base64 op
public class Base64 {
public static String encode(String s) {
return java.util.Base64.getEncoder().encodeToString(s.getBytes());
}
public static String decode(String s) {
return new String(java.util.Base64.getDecoder().decode(s));
}
}
Try this
base64 takes so much place in a file
i got like 2 itemstacks and a bunch of nulls and it took 10 lines
It in a single line
I stored an entire inventory once as a single line and it took 5000 char 💀
