#help-development
1 messages · Page 1611 of 1
wdym
is there a way to double block drops with blockbreakevent, because for some reason event.getDrops returns the block drops without fortune
No, please comment on them
?conventions
Java Coding Conventions: https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
BlockDropItemEvent
selfrole Add or remove a selfrole from yourself.
cleanup Base command for deleting messages.
embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.
findcog Find which cog a command comes from.
names Show previous names and nicknames of a member.
casesfor Display cases for the specified member.
listcases List cases for the specified member.
reason Specify a reason for a modlog case.
permissions Command permission management tools.
my maven goals are gone
Hi, i'm making a multi-lang plugin but i have a problem with an Enum. When the lang change i wanna "reload" my enum to refresh the value of it how can i do ?
ZEUS_LIGHTNING(GameSettings.LANG.textOf("godItem.ZEUS_LIGHTNING"), "zeus_lightning", 1, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS),```
here : GameSettings.LANG.textOf("godItem.ZEUS_LIGHTNING") is changing when lang change
You can't change enum values as they are running. (if I recall correctly.)
okay so my only solution is to make this :
ZEUS_LIGHTNING("godItem.ZEUS_LIGHTNING", "zeus_lightning", 1, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS);
public String getName(){
return GameSettings.LANG.textOf(this.name);
}
😫
or dont use an enum
Enum’s aren’t even meant for this purpose
it's a custom item wrapper don't have choice to make this clean
so you advise me to make N customItem class for each custom item i have ?
Yes, because enums are not the correct choice here
why ?
If they are going to be changeable, then don’t use Enums
That's up to you; Sure thats a possibility but I bet if you think enough another good option may come up
Enums are FIXED CONSTANTS is why
except this litle variable all variable thru the game are not changing and are constant
If you have all your translations already set and you are simply pulling a different translation, then you cna use Enums
how can i get every line under the uuid and print all the lines to the player?
this is probably the wrong way
List<String> homes = new ArrayList<>();
homesFile.getConfigurationSection("homes." + p.getUniqueId()).getKeys(true).forEach(home -> {
if (home.startsWith("homes." + p.getUniqueId())) {
homes.add(home);
}
});
the player is changing the lang at the begining of the game and will not change while game is running
yep thx
Enums are set at compile time, not after
okay i see the problem
is there an easy way in java i can create a random number that is not too random? i mean, for example, between 0 and 100, something that gives me, 23, 47 and 83 is fine, but 23 26 and 85 isnt bc 23 and 26 are too close. i want to teleport players, so, i prefer something less random, and keep them separate if possible
UUID will not be included as you already pulled the map from under that
i only want the name and the location
your home variable will be a map containing test and the map of K,V
Why do you you save the playername under their UUID? If you have their UUID already whats the point of the username?
Also a cleaner method is to put it in 1 string rather then multi paths
cleaner would be to scrap the player name in there and pull that from the OfflinePlayer object and then push the location as an actual Location object
you can then use the config method of ConfigSection#getLocation("test")
yea i know
you could even leave the player name in there. it will be ignored by getLocation
i mean, this doesnt look random at all, 3 times the random location was close to a previous random point, just next to it
I hope you also realize that random does mean it could give you the same location 10 times in a row
?paste
is there a way to check if a block is placeable? because Material.isBlock() doesn't work for redstone
https://paste.md-5.net/iwoyozubet.java
How do i access getRegular() out of its class?
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.
please @grim ice
i personally like this:
https://www.w3schools.com/java/
you got this right @grim ice?
w3schools 🥵
i mean they're not bad xd
its pretty good for learning basic java
vault
which packets i need?
?
like this
p.setDisplayName(Main.getChat().getPlayerPrefix(p) + " " + p.getName());
0wo
LMAO
GUESS WHAT
its the exact website i read
and here u find me :/
Go and ask your java questions in a Java discord
i know, thats why i ask if there is a random generator in java that is not really that random
we dont answers java question here, we're answers spigot api question
I mean yeah that's true, but it would be easier for people to understand me if they know spigot too
Random is as random as you can get. What you do with that is up to you
just joking lmao
o lol
Helo
but honestly i got a better understanding of java now, at least better than what i had
sure, you'll learn from time to time
Trust me, there are still a lot to learn. Im still learning too
Oh boy there is so much
You won't ever stop learning java
which packets i need for prefixes without scoreboards?
Take it from someone that has done it for at least 7 years you never stop learning
MethodHandles, streams, proper library coding
Generics, wildcards
It's bad when I use other langs because OOP is literally second nature for me lol
Isnt oop like more intuitive?
honestly I hate and like OOP at the same time
I hate it because of the horrible puzzle you have to solve
Puzzle?
Consider developing a large framework
Something like Spring
It’s a nightmare
That’s why the UML graphs exist
But then you still have to plan in advance
And half of the time your users wouldn’t understand the structure anyways
Lol
gestures at Bukkit
Mhm
Bukkit is a shit show imo though lol
does anyone know about this?
?jd
My only idea would be using Tag.REGISTRY_BLOCKS
Looking back dont think that will work
i guess i could make a list
Yeah I don't think there's anything that determines whether or not a material is placeable
.... Material.isBlock()???
Why not just use isBlock and also check if it's redstone?
well im not sure what other blocks it doesnt work for
Was responding to choco's message
https://hastebin.com/qivelerexo.java I try to give a Block the Glow effect, for that i want to Spawn a Shulker with glow effect but in the 1.17 i cant find the new flags. Anyone have ideas or a link with the new flag ids?
anyone knows how do i get a player last message
You can safe the message in a hashmap and can then spend it on you
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.
Yo quick question, when compiling a jar, when's the difference between mvn clean package, and just mvn package?
When building maven doesn't recompile all classes only the ones changed. clean will force it to delete all cached files and recompile everything
im trying to build block party server and i want to make the floor change every round and i made floor presets and i saved them in a class:
lass Platform {
public Location point1;
public Location point2;
public Platform(Location point1,Location point2){
this.point1 = point1;
this.point2 = point2;
}
public Platform(double x1,double y1,double z1,double x2,double y2,double z2){
this.point1 = new Location(Bukkit.getWorld("RainbowMan"),x1,y1,z1);
this.point2 = new Location(Bukkit.getWorld("RainbowMan"),x2,y2,z2);
}
public static List<Platform> getPlatforms(){
List<Platform> platforms = new ArrayList<>();
platforms.add(new Platform(12,79,-3,-2,79,11));
platforms.add(new Platform(12,74,-3,-2,74,11));
platforms.add(new Platform(12,69,-3,-2,69,11));
platforms.add(new Platform(12,64,-3,-2,64,11));
platforms.add(new Platform(-4,74,-3,-17,74,11));
platforms.add(new Platform(-4,69,-3,-17,69,11));
platforms.add(new Platform(-4,64,-3,-17,64,11));
platforms.add(new Platform(-4,74,13,-17,74,27));
platforms.add(new Platform(-4,69,13,-17,69,27));
platforms.add(new Platform(-4,64,13,-17,64,27));
platforms.add(new Platform(12,74,13,-2,74,27));
platforms.add(new Platform(12,69,13,-2,69,27));
platforms.add(new Platform(12,64,13,-2,64,27));
platforms.add(new Platform(12,69,29,-2,69,43));
platforms.add(new Platform(12,64,29,-2,64,43));
platforms.add(new Platform(-17,64,29,-4,64,43));
platforms.add(new Platform(-17,69,29,-4,69,43));
return platforms;
}
public static Platform getRandomPlatform(){
return getPlatforms().get(new Random().nextInt(getPlatforms().size()));
}
}
and i have this for the floor positions:
private Location getLocation1(){```
return new Location(Bukkit.getWorld("RainbowMan"),26 ,63, -21);
}
private Location getLocation2(){
return new Location(Bukkit.getWorld("RainbowMan"),12 ,63, -35);
}
but i dont know how to make it change with the world edit api and i searched it on google but it needed player session and i want it to work from the server and not the player`
Ah okay, thanks Olivo.
My guess is you have to make a CuboidRegion and then iterate through the blocks in the region & change them to something else.
No, you need to do that on your own. I'm just telling you what you should do. Mess around with IntelliJs autocomplete. There should be CuboidRegion constructors & methods for doing what you need.
It shows you how to create a new session and use it
Combine that with the pattern guide and you will have your random floor
but i need a player for session and i want it without a player session
is there a console session or something like that?
That too
If you're using FAWE make sure to fire things async or you will crash the server
with the scheduler?
There are many ways to do it. The scheduler is one
like another method for the Scheduler delayedtask
Well you're telling it to wait so it waits
I assume you mean runTaskLater
if i use the world edit maven in pom.xml it will work with fawe?
No, you need to use FAWE's dependency
Not really
FAWE contains the WorldEditAPI and as such you can just use WorldEdit but you will have to keep in mind FAWE might be slightly outdated
I don't think it contains, it just maintains compatibility
Which is pretty nice of them lol
FAWE is built on WorldEdit and acts as a replacement
Platform platform = Platform.getRandomPlatform();
CuboidRegion region = new CuboidRegion(
BlockVector3.at(
platform.point1.getBlockX(),platform.point1.getBlockY(),platform.point1.getBlockZ()
),
BlockVector3.at(
platform.point2.getBlockX(),platform.point2.getBlockY(),platform.point2.getBlockZ()
)
);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(region.getWorld())) {
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(
editSession, region, clipboard, region.getMinimumPoint()
);
// configure here
Operations.complete(forwardExtentCopy);
}```
the newEditSession() not exists
Yeah FAWE has that one missing
There is a deprecated one you can use
Don't have the name of it
WorldEdit.getInstance().getEditSessionFactory()
this?
its deprecated
will it still work?
Im planning on making a sign shop plugin, and was wondering if I should record the location of the shop or just check if the sign title has a specific color that gets added when someone with permissions creates the sign shop.
Might be this try it
how much do i need to set the max blocks?
its a floor of 15x15
what i copy
so 225?
You don't need to set max blocks if you don't want to
it needs the max blocks for the constructor
-1 or just max int
oh thx
Platform platform = Platform.getRandomPlatform();
CuboidRegion region = new CuboidRegion(
BlockVector3.at(
platform.point1.getBlockX(),platform.point1.getBlockY(),platform.point1.getBlockZ()
),
BlockVector3.at(
platform.point2.getBlockX(),platform.point2.getBlockY(),platform.point2.getBlockZ()
)
);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(region.getWorld(),-1)) {
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(
editSession, region, clipboard, region.getMinimumPoint()
);
// configure here
Operations.complete(forwardExtentCopy);
}
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(region.getWorld(),-1)) {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(getMainFloorPlatform().getPoint1())
// configure here
.build();
Operations.complete(operation);
}
thats what i did for now
its ok?
I would use max int it's probably better
can u see dm?
Hi, i'm french sry for this beautiful english
I make my first plugin in 1.16 and i want to break specific block with arrow
but idk what is the event for this
if anyone can help me c:
ProjectileHitEvent
Hello, does anyone know a method I can use that prevents players from joining a server?
Thanks for the help
any recommended method for adding advancements?
how do i register a permission for each argument in a command (plugin.yml)
you register a perm for teh root command. The args you have to manually test
implement it yourself by checking for permission when each argument is detected
oh ok
but
if i dont want a perm for the command
only for specific args
i should not
write permissions:
right
yes, just leave that field out
how can i get the actual values?
if (!homes.isEmpty()) {
Utils.message(p, "§f--- §9Homes §f---");
homes.forEach(home -> {
Utils.message(p, home);
Utils.message(p, homesFile.getConfigurationSection("homes." + p.getUniqueId() + "." + home).getKeys(true).toString());
});
}
Instead of using getKeys use getValues.
lmao you're too smart for this world
😂
have i really been struggling for this for 4 hours smh
Anyone know of a good method for adding advancements?
I guess because you are using args
with "onProjectileHit" i can't destroy arrow ? like this.death ?
remove()
@EventHandler
public void onProjectileHit(ProjectileHitEvent e) {
Entity entity = e.getEntity();
if(entity instanceof Arrow){
entity.remove();
}
}
i have this
Hmm, okay, but i want remove my arrow when it touch specific block
e.getHitBlock().getType()
== Material.Block ?
mhm
Yes
^
There is an API I would like to try out, in their releases page is a jar file, if add it as a library it all works fine and compiles fine. but its not a plugin so it wont load on the server and not including it the actual plugin can't locate the classes. How would I use this, extract the class path from the jar and drop it into the root of my project? I tried putting the whole jar in there and it didn't like it.
Shade it
Hey does anyone here have experience with TokenEnchantAPI?
how would i go about that?
Do you use maven?
nope
Intellij?
im using netbeans as my IDE
you couldn't make it more difficult if you wanted
use maven and install the jar locally
as for how to use maven with netbeans, idk, ask md5
he's the only one I know of who uses that dumpsterfire
it the library available via maven?
the bratwurst man
mhm
yep
how did your A* go
hahahhahaha
hahahahhaha
lmaooooo
ElgarL i tried to use ur algo but it was not really working
like
in sharp corners
it wouldn't path find
If its available via maven you can add it locally to your project, then add it to your plugin.yml in the libraries section. It will then be downloaded for you on whatever server your jar goes on.
so... i followed some shit C tutorial for A*
and it turned into an absolute dumpster fire
Worked fine for me. But I only tried it hidding behind things, or in alcoves
okay, but the server bitches about it being in the plugins folder because its not a plugin
hmmm, maybe i didn't give it enough runs 🤔
did you use the 8 line search thing I wrote
well
its not a plugin
that became the basis of the loop
but
it still used the underlying shit cost logic
which was made for 2d
show me what you have
so the dependency in the plugin.yml should make the server not try to load the jar as a plugin?
?paste
If you want to manually put it on your server, create a folder called libs in the root of your server, and drop it in there.
only works in the x and y axis
it is literally non - functional
ok, thank you. ill try that.
and if i want all blocks ? x)
what?
all of what blocks
it can only hit one block
how are the nodes laid out
are they spread on a voxel grid
like blocks
or are they just arbitrarily anywhere
yeah blocks = node
if(e.getHitBlock() != null) this its okay ?
the cost of each traversal is 1
how to detect when anvil hit the ground?
cost = distance from start afaik
How do I change items durability? I have tried item.setDurability etc
i wanna make the anvil destroy when hit the ground
durability is actually a damage counter
Oh
measures how much damage the item has taken
what do the various different costs prefixed by H na d F and G and whatever stand for
Well how do I set it?
wait ElgarL - ur class extended runnable - did it need to be ran several times for the optimal solution? now i am thinking that maybe i removed your plugin -specific code and made it non-functional
hang on
let me find the tutorial
delete
No, you just ran it once on command
if you want to increase the accuracy increase nodes or permitted time to run. Both are settings at teh top of the class.
idea is that when it moves towards the final goal the F cost is constant @valid crag
are the nodes created from scratch every time the algo runs or are they pulled from some globally shared network
scratch
meta.damage(30);
item.setItemMeta((ItemMeta) meta);```
I tried this but seems like it doesnt work
if closedSet.add returns false, continue;
that means the node has already been processed
no, what
let me load up an ide
how to detect when a player hit by falling anvil?
remove line 38
change closedSet.contains to !closedSet.add on line 45
remove openSet.contains on line 45
delete everything on lines 48 through 56
hi
replace them with openSet.push
cut the trousers of the potions off at the knees
^
((Damageable) itemMeta).setDamage(20);
item.setItemMeta(itemMeta);```
I tried this too but says "The method setDamage(int) is undefined for the type Damageable"
Oh ok
queue.pop -> queue.poll?
whatever is the one that removes and returns the element at the head
You know how can i remove blocks but with radius ?
rayon?
isn;t that a fabric used in dress making?
radius I think
Yes 😭
thats a circle
sry yes 😂
How To Remove Blocks in Oblate Spheroid
What is the right import for items? Eclipse doesnt seem to find one
org.bukkit.inventory.meta?
org.bukkit.inventory.meta.Damageable
Thanks
so how can i do that circle ?
three for loops over x,y,z
Hey there! I am trying to detect left clicks on persistent item frames. Since they are persistent they do not trigger a EntityHitByEntityEvent. What would you suggest?
I thought about ray tracing on player interact event
java.lang.ClassCastException: class com.jeff.spigotsandbox.astar.Node cannot be cast to class java.lang.Comparable (com.jeff.spigotsandbox.astar.Node is in unnamed module of loader org.bukkit.plugin.java.PluginClassLoader @383bc6f1; java.lang.Comparable is in module java.base of loader 'bootstrap')
huh?
how can i use this, exemple ? c:
either pass a Comparator to the queue's constructor, or make Node comparable
priority queues order their elements based on a property
oh
you loop over all the blocks in that area and check their distance to the origin
right
so the elements must either be comparable
or the queue needs to have a comparator for them
in this case we want the comparator to put the elements in order of shortest distance from target to longest distance from target
Oh okay, how i make this check ?
that is, the closest node to the target is always at the head of the queue
itemshop:
mainsize: 27
stuff:
categories:
blocks:
stuff:
weapons:
stuff:
So I have the above config and want to put every category under categories into a public inventory with the user being able to change the name in the config, so being able to change the blocks key to something like ranged, how can I get the first key under categories?
Location#distanceSquared
so does node need to implement Comparable?
I was sent an example yesterday, but I'm pretty sure it wouldn't be able to make the inventories public
either that or you need to provide a Comparator<Node> to the queue in the constructor
ok
probably makes more sense for making it comparable
ah ok
if o is less than this, we return negative
if o is equal, we return zero
so just return Math.signum(this.distance - other.distance)
since you're constructing the nodes as you go, just make the constructor require the target
and cache the distance to the target in the constructor
target or source?
@hasty prawn doesn't seem to work
Send the code for what you're doing
That's what gets run when the server is reloaded (only while someone is on) or someone joins
@Override
public int compareTo(Object o) {
if (o == null || getClass() != o.getClass()) throw new Error();
Node otherNode = (Node) o;
return Math.signum(this.target.distance(this.location) - this.target.distance(otherNode.getLocation()));
}
this good?
@eternal oxide you are the one who helped me with entities ray tracing the last time. Do you think this is the best option here?
implement Comparable<Node>
SpawnEntity -> Add Player -> wait 1 tick -> Head rotation -> 15-20 ticks -> Remove Player
that way compareTo will only accept Nodes
and you don't need the casting or other shit
Do you have to wait for a second then set the head rotation?
why are you setting them as persistant?
I do it in mine, don't remember the reason, if it's working for you normally then I guess not.
The rotation works that way for me
ok
Excuse me what the fuck
I’m using them to create custom furnitures. They must not break naturally (because of a mob, an explosion, physics, or anything)
😂
It's super finicky
How can I only get advancements that would usually show in chat and get the name that shows in chat? Right now, I'm doing PlayerAdvancementDoneEvent.getAdvancement().getKey().getKey() but this gets an advancement for every single crafting recipe and block you can mine and it shows it as stuff like recipes/building_blocks/spruce_stairs or story/mine_stone instead of Stone Age
Love how mine works for 15 but yours requires 20
I could make them vulnerable and cancel ALL the events but I don’t think this is the best idea
good logic
Mojang Logic 101
Atleast it works
In that case, yes you will have to ray trace
Yeah, thanks for the help
And I don’t understand why I can detect right click so easily and not left click
Isn’t it the same packet?
the protocol is pretty fucked around the clicking and interaction parts
hmm it dont work
like nothing gets returned
i think it is running off to infinity
you haven't completed the changes yet
show me what you have
did u just switch accounts???
yes
Lol
i felt like it
its so fucking obvious its u as well cause the names are always stupid as hell lmao
?paste
yes, well, the obvious accounts are obvious intentionally
i told you to add queue.push in place of the however many lines I told you to delete
Yep, tested 15 again and same results
line 44
Lmao welp
set the parent of the neighbour node to node
and add neighbornode to the queue
mext
instead of returning a hashset from getNeighbors
return an arraylist
and change the return type to collection
sets are inefficient for iteration and are not very space efficient
you want a queue.push(neighbourNode)
yes
am i using the wrong queue
is it a priority queue
PriorityQueue<Node> queue = new PriorityQueue<>();
why are you asking if you're using the wrong queue
cause push aint defined
idr what the actual method is
the one that adds an element and blows up if it runs into capacity restrictions
maybe add, maybe offer, maybe push
there's like 5 of them and I always mix all of them up
add
remember to set the parent
Okay, that didnt working 😂
and u wanted a different Set
an arraylist
you never do contains or remove or add or whatever on the set
it might as well be a collection
hashsets are very space inefficient
and not good at iteration
which are the 2 things we care about here
return type = collection
neighbours = ArrayList?
yes
ok
initialize the arraylist to have a size of blockFaces.size()
that way it doesn't get resized dumbly or have excess empty elements
ok
How do I make a bell ring? Bell#setPowered doesn't work and I don't see any other methods https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Bell.html
declaration: package: org.bukkit.block.data.type, interface: Bell
seems pretty good
but it does give you a path
anyone know how to use distanceSquared to place blocks arounds it ?
you remember the A* wiki page
i looked some exemple but i dont know how it's work
yep
what we have now gives something along the lines of the gif in the 'bounded relazation' section
what do you mean?
ok...
i want replace some blocks around a entity
Is there any way to detect the server software your plugin is running on?
you don't need Location#distanceSquared for that, just get the blocks you want and use Block#setType
really
the first seems better
He originally asked how to remove blocks in a radius.
ok true
idk how its work Location.distance
you can slightly improve the path by doing a second pass and picking the nearest node to the source rather than the parent during retrace
if(e.getHitBlock().getType() == Material.WHITE_CONCRETE)
{
for(int x = block.getX() - 1; x < block.getX() + 2; x++)
{
for(int z = block.getX() - 2; z < block.getX()+2; z++)
{
for(int y = block.getX() - 2; y < block.getX() + 2; y++)
{
Block blockToDelete = world.getBlockAt(x, y, z);
blockToDelete.setType(Material.AIR);
}
}
}
}
Its best you tell us what you actually want to do, as you have given two different things so far.
In inventoryclickevent, is event.isLeftClick() the same as event.getClick() == ClickType.LEFT ?
but that requires some reworking of the way how the nodes are constructed
so you are just removing blocks all around the hit block
hmm this definitely aint the optimal
How make this 😭
will you be around tomorrow? its just i have to go now
is the target directly behind the stone
whats the second yellow path
the one that carries on after the stone is made b4 i added the stone
the second with the arrow
is the way "around"
your distance function is probably broken
... maybe
no that's definitely optimal 🧠
@hasty prawn one other thing with NPCs, have you done turning the NPCs head to the player before?
How do you do it lol
I know the setting the head pos stuff, but idk how you would track the player's movement
use it to breaking blocks with radius ?
Well just periodically check which player is closest to the NPC
And look at them
if you want an actual radius, yes
entity.getLocation().distanceSquared(location) ?
if you just want a cube of blocks, then you don;t need a distance calculation
3 for loops over X,Y,Z + and - radius.
If you just want the whole area you set all blocks.
If you want a sphere you check the distance to each block from the origin before removing it.
i makes this yes, but i want circle x)
then you check the distance
if its outside the distance you don't remove the block
for(int x = block.getX() - 1; x < block.getX() + 2; x++)
{
for(int z = block.getZ() - 1; z < block.getZ() + 2; z++)
{
for(int y = block.getY() - 1; y < block.getY() + 2; y++)
{
Block blockToDelete = world.getBlockAt(x, y, z);
if(blockToDelete.getType() == Material.WHITE_CONCRETE)
{
blockToDelete.setType(Material.AIR);
}
}
}
What would be the most efficient way to do that, though?
You are only doing +/- 1 so you are not going to see any sphere, but you are also not checkign distance so all you will remove is a 3x3 cube
Every second or so, get all the player's with a few blocks of the NPC and check who is the closest
Hmm yes
Falling through the world in my test server
very nice
Alright then, game
yes but i dont want square 😂
Ok, you have told me two diferent things. You make you mind up and ask a proper question later
then add a distance check
if (block.getLocation().distanceSquared(blockToDelete.getLocation()) < distance) blockToDelete.setType(Material.AIR);```
spoon
a big wooden one
how do you guys usualyl go around getting the uuid of a player from their name without sending out requests to minecraft?
by using paper's getOfflinePlayerIfCached
which uses the local usercache
beyond that, it isn't really possible
oh
granted, getOfflinePlayer also uses the usercache I think
getOfflinePlayers() and loop them to search
that is gargantually slow and not reliable
that work perfectly thx
for one, there can be several offline players with the same name
there is no guarantee you'll get the "right" one
Correct, but with Spigot there is no alternative
use getOfflinePlayer off the main thread I suppose
so the network request doesn't kill the server
So in something like a repeating task?
Yeah
Alright
it'll try to look it up from the usercache anyway so the request is the worst case scenario
POssibly, if its not blocked from Async access
iirc it isn't
i vaguely remember that being intentional as well
as you would be legitimately fucked if it was blocked off
you'd have to make the ifCached call sync and then manually ring up mojang api if it doesn't return a result
Can somebody link me an open source Spigot mod that uses Brigadier please? Can't really find much.
Luck's got a library for it. Commodore
I think so but my friend is currently trying to use CommandSourceStack and can't find it so I think the issue is that he has to specify brigadier as a dependency in his Gradle files but he thinks I'm wrong
Ah so I was right
how can i run each iteration with a second or so of delay?
for (World world : worldRegions.keySet()) {
// just fill up the list up to the cache size
for (int i = 0; i < cacheLocationsSize - rtpLocations.size(); i++) {
// calculate a random location
Location randomLocation = getRandomLocation(world);
// add it to the cache
rtpLocations.get(world).add(randomLocation);
}
}
i dont fully understand yet the scope when using anonymous functions, or lambdas, or whatever theyre called, the thing u do when doing new BukkitRunnable() {... etc
?scheduling
that's an anonymous local class
what it does is creates a local, single-use class without a name that extends BukkitRunnable
How work location ? I maked this for try, but alltimes i've Z- and X-
if(player.getEyeLocation().getZ() > 0)
{
player.sendMessage("Z +");
}
if(player.getEyeLocation().getZ() < 0)
{
player.sendMessage("Z -");
}
if(player.getEyeLocation().getX() > 0)
{
player.sendMessage("X +");
}
if(player.getEyeLocation().getX() < 0)
{
player.sendMessage("X -");
}
eye location is just getting the player's location at their eyes
You want the direction they're looking
player.getLocation().getDirection()
Returns you a vector. Compare against those component instead
ohh
that doesnt say anything about scope, i cant use a local variable inside that, for example. i remember something about atomic integer, but maybe there is something specifically for loops
why can i sometimes use local variables inside the anon class and sometimes i cant? i dont understand the difference
depends if they are final or not
a MutableInt should probably do, no need to use atomically stuff unnecessarily
i can use them if theyre final? or if they are not?
the difference is finality
you can use final or effectively final variables
however variables that are assigned more than once, that is, effectively non-final variables, cannot be used
this is because the scope of the anonymous class cannot accurately reflect any changes made to those variables
and can i modify the value of an effectively final variable?
With Fabric there's a ServerCommandSource but since mappings for Spigot are different I can't find the equivalent here, the intermediary class name is class_2168 if that helps, where would I use that to find what it's called with Spigot?
by effectively final you mean keep it constant but without using the final keyword, right?
yes
ConsoleCommandSender iirc, Taco
if is effectively final, but not labeled as final
Thanks
which as far as the compiler and jvm are concerned, are equivalent
That's the Bukkit interface, sorry. Though there would be a Craft implementation of it that wraps an NMS value
ok, so, like a while loop, but with a MutableInt and a BukkitRunable instead of the while
and this.cancel instead of break
maybe
kind of smells like a design issue, but maybe
do you have code and context to show
If you are using a Runnable you can pass in a final variable to a local variable and modify it in the runnable
the thing is that it will generate chunks, in a pretty crap pc, and i dont want it to be generating world a lot, idk
thats the only reason i want a timer
consider using paper and chunky
a chunk pregenerator
ahh
yea, i pregenerated all worlds
but the resources world is new every day, so
im getting some random locations before a player needs it
so they dont have to wait for it to generate and stuff
🤔
it's a rtp plugin that pregenerates the chunks around the rtp locations ahead of time
basically what you're trying to achieve right now, I think
yea, thats my idea, but idk much about existing plugins, and i dont complain about having make them myself really, i want to know more about the spigot api
Thank you java
?paste
You couldn't have given a compile time error for this?
😄
well, you can't really convert a for loop into a runnable directly
you can make a for loop that runs in a runnable, or you can make a for loop that fires runnables
https://paste.md-5.net/duvudezeno.java
Any Idea why am I getting a NullPointerException at line 6 here?
Eclipse by any chance?
but trying to make a for loop pause-resume with a runnable is a bit more involved
jail loc = null @grim ice
No
oh
Aight just know that their jdk can compile with errors and code end up like that
Hmm okay but can i collect facing information, like X/Z position or EST/North ?
Yeah, I'm using openjdk with maven. The issue was a missing curly brace at the end of the class...
Seems like that should be compile time, right?
getDirection() or some shit I think
there are some flags you can set in some cases that allow you to compile shit that shouldn't compile
Player#getFacing() will get you the BlockFace they're facing
player.getLocation().getDirection() will get you the exact vector they're looking
note that it doesn't ever actually return up or down
Correct
config doesn't mean shit
Did you sysout it
if it's null it's null
It should throw an error during the compile. Did you use an OpenJ9 version of OpenJDK?
no
Do that
then it's probably null
wtf u mean
^
your config isn't omnipotent
its perfect ! 😄
its getting the values from the config
well it might be getting them wrong
But the location it makes is null
in a nutshell
the location is an xyz value
take a look
no
sysout it and trace the issue
ok
or use the helpful npe messages
can i make this ? if(player.getFacing().toString() == "SOUTH")
do you want help or not
You can just compare it directly. No reason to stringify it
getFacing() returns a BlockFace. Compare it
i have error
and that isn't how you compare strings, anyway
if (player.getFacing() == BlockFace.NORTH) for instance
yes i want help
how tho
System.out.println
thx you
I don't think so
right below the null line?
sysout the variable that you suspect being null before invoking any methods on it
its an object
yes but its a location how can it print a location
You could check by running java -version
did you even try it
It should tell you if it's OpenJ9 or not
Shows as OpenJDK 64-Bit
Hm idk then pretty sure the compile should fail
Remote server is the same fwiw
And local test environment
??
something like this
public static void fillRtpLocations() {
for (World world : worldRegions.keySet()) {
for (int i = 0; i < cacheLocationsSize - rtpLocations.size(); i++) {
Location randomLocation = getRandomLocation(world);
rtpLocations.get(world).add(randomLocation);
}
}
}
to this?
public static void fillRtpLocationsTimer() {
MutableInt worldIterator = new MutableInt(0);
MutableInt locationIterator = new MutableInt(0);
new BukkitRunnable() {
public void run() {
if (worldIterator.intValue() < worldRegions.size()) {
World world = worldRegions.keySet().stream().toList().get(worldIterator.intValue());
if (locationIterator.intValue() < cacheLocationsSize - rtpLocations.size()) {
Location randomLocation = getRandomLocation(world);
rtpLocations.get(world).add(randomLocation);
locationIterator.add(1);
} else
worldIterator.add(1);
} else
this.cancel();
}
}.runTaskTimer(instance, 0, 5);
}
5 sec of delay for each iteration
those don't need to be mutable
declare them as normal variables inside the bukkitrunnable
they only need to be effectively final if they are declared outside of it
mmm right
bat u there
other than that, building a list and getting the n'th element of a set with streams is inefficient
consider populating a Queue with the contents of the keyset
and then popping one element out of it with each iteration
right
2hex
org.bukkit.plugin.AuthorNagException: No legacy enum constant for WHITE_CONCRETE. Did you forget to define a modern (1.13+) api-version in your plugin.yml?
hmmmm ?
https://paste.md-5.net/duvudezeno.java
Any Idea why am I getting a NullPointerException at line 6 here?
Yes
SYSOUT THE LOC
did you do what I told you to do
then we help
just do it
Yes
try it instead of asking us for every single fucking step
Like that
ok
add api-version: 1.13 to your plugin.yml
if u dont want to help just dont
He does want to help
you really don't seem like you want help
But you are being a pain
screaming at ppl isnt rly helping
@hasty prawn one last thing, have you ever done getting the NPC a player is looking ata?
We are helping you trouble shoot and you are like but the config isn’t null
shut up and sysout the location already
Thx you, i add 1.16
Nope
Aw, okay
I guess I could also get the NPCs from the hash map and get their IDs and make a select command in the form of the ID...
when you try to load that plugin on -1.16 it throws a exception.
using api-version: 1.13 is the best way for non-private plugins
Well does your config contain the values you're reading
Yep
Double check that with a sysout
?paste config
the npe isn't important
what is important is what the sysout printed
why do you think we put the sysout there?
what line is the sysout on
Sysout won't run if error happens before it
give me a line number
or don't, whatever
what
That doesn't look like ints to me
1s
Im creating an economy plugin and am currently working on the api for it. Should I make the api methods static and synchronized so i am 100% sure there is no concurrent access?
and regrettably, learned nothing from this
when you run into a NPE next time, what will you do?
try to fix it, duh
btw
i should just replace int with double
righr
right
depends on whether you need an int or a double
depends on the precision you want/need
or how you save/load
.like you know there is a config#getLocation riight?

right so is there a way to get or compute a soft ref out of a map
without it being super gay
soft ref?
SoftReference
yeah, not sure what you mean
aka a reference to an object that may be nulled by the garbage collector if the system is low on memory
usually used for caches
Hello everyone, I want to save a HashMap on Disable and load it again on Enable. I already know how to save it, but I don't know how to load it again.
public void onDisable() {
// Plugin shutdown logic
File file = new File("plugins/SteinerAddon", "cooldowns.yml");
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
cfg.set("cooldowns", HeadCMD.cooldown);
try {
cfg.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}```
yeah but
is every entry/key wrapped with one?
every value is
if i make timer for use item, all server have this timer ?
Map::computeIfAbsent won't cut it I don't think, as the reference might be nulled by the gc between being grabbed/computed from the map, and actually returned
What map implementation are you using?
surely it would not be gc'd if there is a ref in the map being held
teh value would if thats null btu the key shoudl still be there
the whole point of the ordeal is that the actual value isn't referenced anywhere else other than the map, so it can be yeeted by the gc at will
So we're talking about a HashMap<K,SoftReference<V>>
and the map refers to it with a softref, facilitating said yeeting
yes
I want to get a V out of it
and ensure the V doesn't get yeeted in between the getting/computing and returning part
I can't computeIfAbsent a SoftRef<V> and then call get on it to get the V, as then there's a point in time when V isn't referenced strongly
so V can be yeeted in between the Map::computeIfAbsent and the SoftRef::get
the only way I can think of is to have alike a 1 sized array and put the V in the array inside the computeifabsent call
to strongly refer to V for the duration
but that's annoying
a way to improve this crap?
public static Location getRandomLocation(World world) {
Vector min = worldRegions.get(world).getMin();
Vector max = worldRegions.get(world).getMax();
Vector offset = max.subtract(min).multiply(new Vector(Math.random(), Math.random(), Math.random()));
Location randomLocation = min.add(offset).toLocation(world).getChunk().getBlock(0, 0, 0).getLocation();
Location teleportLocation;
for (int i = 0;; i++) {
teleportLocation = randomLocation.clone();
teleportLocation.setX(randomLocation.getBlockX() + 16 * i);
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
int airBlocks = 0;
for (int y = 128; y > 45; y--) {
Material blockType = teleportLocation.getBlock().getType();
if (blockType == Material.AIR)
airBlocks++;
else if (blockType == Material.GRASS_BLOCK && airBlocks >= 2)
return teleportLocation;
else
airBlocks = 0;
}
}
}
}
}
is there an enum or something to know if a block is, like, empty? grass, vines, etc, instead of just checking for air
You could wrap the softref in a class which would cache the value to its instance field during those computations, think its called an adapter or bridger
block#isSolid()
Will tell you if its an impassable block
will also return false for a lot stuff that is impassable
grass etc are not solid
like fences, glass panes, stairs, etc
there is a call on Material or Block for isCollidable or something
true
How can i make good timer ?
not super reliable either, but it's the best I know of
the api doesn't actually let you get to actual collision shapes
mmm so I'd use a Map<K, Bridger<V>> where Bridger implements softreference functionality with a sort of on/off switch that'd let me temporarily strongly reference it
maybe
yeah precisely
Hey is there a unified library to check if a player can build in a specific place?
Without having to make a compat with every single protection plugin
though I suppose that partly eliminates the idea of a soft reference
one problem I foresee is that for each call on call you always need to ensure an off call
otherwise it can accidentally or unexpectedly be left as strongly reachable forever
oh yeah
use the services manager like vault
should be possible to ensure that
i think
not enforce, but ensure
which is good enough i guess
ok, any other improvement?
yeah, well idk I would probably create my own map implementation as a decorator/bridger
yeah but vault doesn't support protection plugins
assuming one uses for each which effectively is an iterator loop
I'm not saying use Vault, I'm saying use the ServicesManager in Spigot like Vault does.
Yes this is basically what I am asking for
That is how Vault gets any economy/chat/permissions plugin without knowing it and implementing compatibility itself
so do you have any example of services manager for protection?
i could probably scrape something together with threadlocals or something that'd work as an util
alright gl
Yes this is what I meant by unified library
public static V retrieveV(Map<K, SoftReference<? extends V>, K key)
Not really, since I've never used it myself, but you should take a look at Vault's source code and see how they do it.
I know how they do it, but I don't want to do it?
They support a wide range of plugins
That's not what you want?
I don't want to write a code for every single protection plugin
I'm looking for something that already handles it
if (args.length == 2 && !args[0].equalsIgnoreCase("create") && plugin.getConfig().isConfigurationSection("jails." + args[1]) && !args[0].equalsIgnoreCase("help") && !args[0].equalsIgnoreCase("reload") && !args[0].equalsIgnoreCase("remove")) {
if (sender.hasPermission("jail.teleport")) {
Player target = Bukkit.getPlayer(args[1]);
Location jail_loc = new Location(p.getWorld(), plugin.getConfig().getDouble("jails." + args[1] + ".x"), plugin.getConfig().getDouble("jails." + args[1] + ".y"), plugin.getConfig().getDouble("jails." + args[1] + ".z"));
assert target != null;
target.teleport(jail_loc);
target.getPersistentDataContainer().set(new NamespacedKey(plugin, "jail"), PersistentDataType.STRING, "jailed");
p.sendMessage(ChatColor.DARK_GREEN + "Successfully Sent " + ChatColor.GOLD + target.getDisplayName() + ChatColor.DARK_GREEN + "to jail " + ChatColor.GOLD + args[1]);
}
}```
That's why Vault uses the ServicesManager - so that they don't have to write code for every single plugin using Vault, lol
Currently I'm calling on PlayerBlockPlaceEvent and I check if it is cancelled
if it is I revert my blockplacing
same with remove
Oh okay sorry I misunderstood that!
But then, what's the point of Vault if the ServicesManager allows you to not write a different code per plugin?
I'm a bit stuck. How do I cancel a repeating task from within the task?
use the correct type of task and call cancel()
BukkitTask isn't
?scheduling
Vault acts as a bridge to these economy/chat/permissions plugins by letting other plugins access them via abstraction.
You can just implement your region handling in the same plugin though
Bukkit.getScheduler().runTaskTimer(this, new BukkitRunnable() {
@Override
public void run() {
Bukkit.broadcastMessage("test");
}
}, 0, 20 * 1);
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:539) ~[spigot.jar:2991-Spigot-018b9a0-f3f3094]```
who can help me? 😦
we should have a #help-development-2 :L
Hmm I'm not sure to understand, isn't it the point of ServicesManager to allow you to access the registered plugins via abstraction?
Or just threads
But md is never here
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/ServicesManager.html#register-java.lang.Class-T-org.bukkit.plugin.Plugin-org.bukkit.plugin.ServicePriority-
Do you know where I can find a list of Service types?
declaration: package: org.bukkit.plugin, interface: ServicesManager
thankfully
ah. no threads here yet. rip
What's the event that I need to detect when a player throws an ender pearl?
player throw shit event
You'd be able to get a list of providers for your service with #getRegistrations(Class<T>)
