#help-development
1 messages · Page 790 of 1
that's actually quite hard
not really actually
just make them ride the entity
ill just make it so the arrows drop as items when they hit a dummy
Never said it was easy :p
guys i have a issue with maven
but i don't have this (import / dependecy) in my plugin
looks like something lombok would spit out
make sure you have the latest version of it, a supported compiler and a compatible jdk
Also looks pretty similar to hypixel lol
he is just lying
Huh
the code quality is also subjective
But performance and scalability isnt
maybe, but both of those are hard to measure accurately
Yall didnt have no problem to tell me how scalable my code is so make ur mind 🤷♀️
i was going more with the noita-style damage indicators honestly
i mean you aint wrong about that 😅
i mean you know what programmers are like lol
wait so uh if I have a database lookup for on block break event and I use an external thread for the database lookup, what if someone for example uses like haste 2 on a bunch of blocks, does that open a bunch of threads at the same time? (my server has 3 threads)
we like to correct people and tell people they are wrong even if their implementation works perfectly fine for them
i could post the code for that damage indicator and there will always be people saying its wrong or how many mistakes it has
granted, it absolutely does have lots of little mistakes and looks terrible, but thats besides the point
why do you need to do a database lookup every time someone breaks a block
and cant you just use async tasks
to check if the block is natural with CoreProtectAPI
Aint an External Thread and Async the same thing?
yeah but you probably dont have to implement multithreading like that yourself
so uh getServer().getScheduler().runTaskAsynchronously(this, () -> { is this async or is this multithread
also you can probably do it the other way around, i apply a little persistent data tag to blocks that have been placed and see if blocks are natural or not in that way
This runs on a different thread
ok cool
getServer().getScheduler().runTask(this, () -> { and this puts me back to my main thread?
yes
Right. Btw, this is technically async, but on the main thread.
are you planning to modify the blockplaceevent by the way
ok and if I want to save data for example isBlockNatural boolean inside of the thread do I need to use AtomicBoolean?
you mean setCancelled?
or what
ty i fixed
for example yes
Not if its effectively final. So a variable
public void someEvent(SomeEvent event) {
...
final boolean natural = ...;
getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
// natural can be used here
});
}
can be used in other scopes
ok but can I access the natural variabale in getServer().getScheduler().runTask(this, () -> {
(main thread)
HashMaps are not thread safe. So either use a ConcurrentHashMap to access directly from inside the other thread, or use
a normal HashMap and sync back using another runTask()
If its final then you can use it in any higher scope you like
na sorry thats not what I meant I forgot, I dont need a hashmap in my other thread I just need a boolean
if(!event.isCancelled()) {
boolean containsBlock = false;
Material[] blockedBlocks = {Material.DIRT, Material.CAVE_VINES, Material.GRASS_BLOCK, Material.TALL_GRASS, Material.GRASS, Material.NETHERRACK, Material.OAK_LEAVES, Material.SPRUCE_LEAVES, Material.JUNGLE_LEAVES, Material.BIRCH_LEAVES, Material.DARK_OAK_LEAVES, Material.CHERRY_LEAVES, Material.ACACIA_LEAVES, Material.MANGROVE_LEAVES};
for (Material blockType : blockedBlocks) {
if (blockType == material) {
containsBlock = true;
}
}
if (containsBlock == false) {
List<String[]> lookup = CoreProtect.getInstance().getAPI().blockLookup(block, 2147483647);
if (lookup != null) {
boolean hasPlaced = CoreProtect.getInstance().getAPI().hasPlaced(playerName, block, 2147483647, 0);
boolean hasRemoved = CoreProtect.getInstance().getAPI().hasRemoved(playerName, block, 2147483647, 0);
for (String[] result : lookup) {
CoreProtectAPI.ParseResult parseResult = CoreProtect.getInstance().getAPI().parseResult(result);
String lookupPlayer = parseResult.getPlayer();
if (!lookupPlayer.startsWith("#")) {
if (!hasPlaced) {
if (!hasRemoved) {
doAlert.set(true);
}
}
}
}
}
}
}```
right now its atomic from yesterday but ill change it
You should really try to reduce this nesting to 2 nests at max.
This can be achieved by using early escapes and a bunch of additional methods.
Try to also crop your methods length
will that cause issues? the method length
It makes your code horribly dirty and hard to read
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
// This is an early escape, if the player is not an op, we don't need to do anything.
if (!player.hasPermission("op")) {
return;
}
String playerName = player.getName();
Bukkit.getScheduler().runTask(this, () -> broadcastOpJoin(playerName));
}
// This is a named method to make the code more readable.
private void broadcastOpJoin(String playerName) {
for (Player online : Bukkit.getOnlinePlayers()) {
// This is a variation of early escape to skip a loop iteration.
if (!online.hasPermission("view.op")) {
continue;
}
online.sendMessage(playerName + " joined the server.");
}
}
also doesnt the word final mean that its final and cant be altered anymore? or does java not care about english grammar
It can nolonger be reassigned
You can still do stuff and use the setters and getters
You just can't reassign that variable
PS: This is how the code looks with nesting and no named methods
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPermission("op")) {
String playerName = player.getName();
Bukkit.getScheduler().runTask(this, () -> {
for (Player online : Bukkit.getOnlinePlayers()) {
if (online.hasPermission("view.op")) {
online.sendMessage(playerName + " joined the server.");
}
}
});
}
}
Its significantly less readable and you need to really dig into everything to understand whats happening
I dont understand what this is supposed to show? Async thread usage? why run code on a different thread for just an on join event
No this is supposed to show how to write cleaner code
Ok thanks
- Less nesting
- More methods with meaningful names
Cannot assign a value to final variable 'natural'
damn
also can somebody answer this
?nocode
It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.
?paste
Yes, this is a very bad idea. You should load all data associated with a chunk into memory, when your chunk loads,
and write it back into your DB when the chunk unloads. Events should ideally only use in-memory data.
Imagine guessing smh
so what you mean make a chunkSnapshot variable, then get the block from the chunkSnapshot variable?
no
i think hes saying you should load all blocks of a chunk into memory from the database when the chunk loads
whichever u have data about in your database
then in your events access that data, not the database
Unless you need to do global lookups you can also just store your data in the chunk PDC, no need for the complicated database stuff
na so for every block in a chunk I need to access the coreprotect database, and put it into a variable?
What can I store in plugin configs
aint that a bit too laggy
anything that can be a YML value (i think)
I mean in what cases do I want to use them
Yes
Anything
anything as long as you make an adapter
And you can write custom adapters, so yeah basically anything
anything, mainly things that people need to be able to read and edit manually
For configuration. Data is ususally stored in a different format.
not even that necessarily if your doing a naive approach and using it as a database you could store in bytes/base64
Maybe CoreProtect is not the right tool for your case. What are you trying to do?
check if the block is natural, and if the player has placed the block or na
yeah but you shouldnt use yml as a database lol
json, sql schema, bson, binary
if you have many methods like broadcastOpJoin, isn't it better to just have them on a utils class?
since there's no state here
For all intents and purposes of the average Minecraft plugin it's perfectly fine
Well people told me its fine
yes im just saying generally speaking
xdxdddd
its "fine" there are just better solutions
I mean if you are going to run a server with a million total players
Maybe avoid yaml
So now I have to start from scratch
(which you're not)
But for the average server it's technically fine
I usually have a ton of manager classes and only very few utility methods which extend spigots functionality
I rather have plugins storing data in yaml than Devs not understanding databases and blocking the main thread with them
for example, im doing a custom crafting plugin. if i didnt have guis to edit my recipes, yml would be the best approach as humans need too be able to read and edit them. but since i have guis i dont have to make them readable, so in my case i use json
I still want an api for NBT files
but i could also just use a database or something
That would be cool
unfortunately I don't think that'd ever be merged
if you wanna use yml just use yml lol
you dont have to scratch all your work
cant I just make it so it wont create more threads if one is open? Like queue them all up
Its not optimal at this rate
What are you trying to do in the first place?
in any case, gson is very easy to use for json storage
tbh if you're data is so tightly coupled to your project where you have to scrap it, you need to rework your organization anyways
converting your yml solution to json will not be a lot of effort
here I sent it
Ah missed it
Hi, how can i make a mob Walk to a specific location?
what about blocks that were placed before the plugin is installed? My map is 4 months old, will they all render as natural? (i assume yes)
This is also technically possible with CoreProtect, but you need a very good understanding of their internals
and when data is in memory/queried from a DB
You can 100% not do a CoreProtect query in the BlockbreakEvent.
Doesnt matter how you do it.
easiest way to get 999 dupes on your server
so far 0
because I dont rollback stuff before I trace back to where it went
They're mostly not public
I know there is setTarget and just teleport but is there a better solution?
not with api afaik
Ok and setTarget would look most natural right?
how can i get a biome from a certain location
World#getBiome
Yes setTarget should be natural
And you should be able to use an invisible mob for the target
Location location = ...;
location.getBlock().getBiome();
I just need to get rid of configs and make db manager
I guess Sql?
But maybe later now im rather demotivated
guys, i need help with something
good luck
?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. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
Not sure I can advise on something
but i thought you knew about something
i have a folder in the resources folder called assets, how can i access it though code?
i need to copy files out of the assets folder to a difrent folder
name the folder correctly in your jar
then Plugin#saveResource
no need to bother messing with folders then
yeah but i am making a plugin that other plugins will put fils in the said assets folder then my plugin needs to mess with those files
my plugin is gonna copy the files out of resource folder
i'd advise against letting other plugins inject things into your resource folder
do what ElgarL said and use Plugin#saveResource
why tho?
because that's mainly because its unnecessarily complex and, but also opens you up to more vulnerabilities
you'd be providing an API to inject content into your jar
why not just uhh idk, use the plugin data folder that spigot already oh so graciously gives you instead of doing some convoluted weird shit
i'm copying files from other plugins resource folders into my plugins data folder
its nicer for devlopers using the resource folder
not for me tho xD
this seems like an accident waiting to happen, have you thought about what happens if a clash in naming occurs?
it'd be much easier and safer to provide developers with API to add files into your plugin data folder
well the files i'm copying out are just files for resource packs
true true
welp thanks for your help! i gtg now
what is the event that gets called when a block breaks because a block below it boke
broke*
for example what is the event if you break a grass block and on top of that is a sapling
it doesnt work tho
It’ll only trigger for one of em ye
is it good for the cpu to actually implement a listener for an event that gets called so many times?
Why
So you can
that was just an example
Same principle
because rails can also be on top of gravel and if u break a gravel 5 blocks below it, it also drops
?jd-s
?
I was just checking smth
ok
@rotund ravine
decompiling my plugin jar wont effect how the code works right?
Bing has the answers to ur problem.
cant you just listen for the block break of the rails?
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
// Implement the Listener interface
public class BlockBreakListener implements Listener {
// Handle the BlockBreakEvent
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
// Get the block that was broken
Block block = event.getBlock();
// Check if there is a rail above the block or the pile of sand/gravel
if (hasRailAbove(block)) {
// Cancel the event
event.setCancelled(true);
}
}
// Helper method to check if there is a rail above a block or a pile of sand/gravel
private boolean hasRailAbove(Block block) {
// Get the block above the block
Block above = block.getRelative(0, 1, 0);
// Get the material of the block above
Material material = above.getType();
// Check if the material is a rail
if (material == Material.RAIL || material == Material.POWERED_RAIL || material == Material.DETECTOR_RAIL || material == Material.ACTIVATOR_RAIL) {
// Return true
return true;
}
// Check if the material is sand or gravel
else if (material == Material.SAND || material == Material.GRAVEL) {
// Recursively check the block above
return hasRailAbove(above);
}
// Otherwise, return false
else {
return false;
}
}
}
Decomp is mess
But ur not breaking the rail
That’s just a physics update
It does not make bugs or something but makes the codebase worse
oh does that not send the event?
EnumSet.contains for the types to check for.
Hey anyone knows how to get ur plugin downloads from 5k to 50k downloads ping me if u know
I wish I knew
patience and regular updates (if needed) and support
Suresure didn’t write it
Just told bing to write it cause i was lazy
lmk how to even get to 5k lmao
lazy ass 🙂
Just make smth dumb and people will download it
also doing that recursively is kinda pointless
Make a useful plugin and get a youtuber promote it
I see
Doing what?
Why?
💀
It isn’t
you could use a list or a while loop
Gravel falls from any height as long as the block under it broky
Sure
Or i could just do it recursively
I told it to just do it like that at the end
It was trying some other schenanigans
i see
java.lang.IllegalStateException: Already scheduled as 14
at org.bukkit.scheduler.BukkitRunnable.checkNotYetScheduled(BukkitRunnable.java:162) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.scheduler.BukkitRunnable.runTaskLater(BukkitRunnable.java:78) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at net.fabledrealms.entityMotion.EntityULMHandler$1.run(EntityULMHandler.java:67) ~[fabledrealms-1.0.0.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.scheduler.CraftTask.run(CraftTask.java:101) ~[purpur-1.20.1.jar:git-Purpur-2062]
at org.bukkit.craftbukkit.v1_20_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:480) ~[purpur-1.20.1.jar:git-Purpur-2062]
at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1506) ~[purpur-1.20.1.jar:git-Purpur-2062]
at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:486) ~[purpur-1.20.1.jar:git-Purpur-2062]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1420) ~[purpur-1.20.1.jar:git-Purpur-2062]
when running this function :
public void playAnimation(List<TeleportData> teleportDataList) {
currentIndex = 0; // Reset currentIndex at the beginning
int ticksPerSecond = 20;
int delay = 1000 / ticksPerSecond;
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (currentIndex < teleportDataList.size()) {
TeleportData teleportData = teleportDataList.get(currentIndex);
entity.teleport(teleportData.toLocation());
currentIndex++;
// Recursive call after the delay
runTaskLater(plugin, delay);
}
}
};
// Schedule the BukkitRunnable
runnable.runTaskLater(plugin, delay);
}```
What could it possibly be ?
You can’t rerun the same runnable
maybe runTaskLater ?
hey how i can get line number from config?
@upper hazel ?
1, 2, 3 etc
so it cant be recursive ?
you should never need the line number in a config file
in config
configs are not treated as having line numbers
Not like that no
plugin.getConfig.getInt(<key>);
something like that
no
oh he meant the line of the config
not exists
yep
i thought an int value in the config
line numbers mean nothign in a config as whitespace is ignored when parsed
do you just want to run a timer?
What
you can manually map the keys with an error message and onEnable you check all your key values and if they're not valid you throw the error message
you would probably print the path of the value you are trying to access
You want a yaml linter then
I want it to be known in which line of the config the error occurred
Yaml linter
a linter ?
what?
a linter
like probably some library that will read the yml file and spit out errors and lines
for syntax errors mostly
but I can’t find out the line number where I got the value from the config?
Seems unnessacary
which is like section.getInt().getLine
if you have a section you know the path to the section probably
so you can just look up what line it is
when you want to log errors well then it will be needed
is this for users or just for debugging
The problem is that there may be gaps there. The config section is not displayed for some reason
that means its probably null
no i mean plugin.getConfig.getSection.getPath not shows the way
I wanted to display an error something like - config.yml/key1/key2
but now this - /key1/key2
so the path of key1.key2 is not showing up?
config.yml/ - not exists in log
Hf from bing
are you working for microsoft or something
I broke it sec
just keys insade config
well the section is just for the file
Getting the line number of a key and value in a YAML file using SnakeYAML is not a straightforward task, as the library does not provide a built-in method for that. However, there are some possible ways to achieve this, depending on your use case and requirements.
One way is to use the org.yaml.snakeyaml.error.Mark class, which represents a position in a YAML stream. This class has methods such as getLine() and getColumn() that return the line and column numbers of the position. You can obtain a Mark object from a Node object, which represents a YAML node in the abstract syntax tree (AST) generated by SnakeYAML. To get a Node object, you can use the org.yaml.snakeyaml.composer.Composer class, which parses a YAML stream and produces a single node. For example, you can use the following code to get the line number of the key FirstKey in your YAML file¹:
import java.io.FileInputStream;
import java.io.IOException;
import org.yaml.snakeyaml.composer.Composer;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.parser.Parser;
import org.yaml.snakeyaml.parser.ParserImpl;
import org.yaml.snakeyaml.reader.StreamReader;
public class LineNumberDemo {
public static void main(String[] args) throws IOException {
// Create a parser for the YAML file
Parser parser = new ParserImpl(new StreamReader(new FileInputStream("./config.yaml")));
// Create a composer that produces a single node from the parser
Composer composer = new Composer(parser);
// Get the root node of the YAML file
Node rootNode = composer.getSingleNode();
// Check if the root node is a mapping node
if (rootNode instanceof MappingNode) {
// Cast the root node to a mapping node
MappingNode mappingNode = (MappingNode) rootNode;
// Iterate over the key-value pairs in the mapping node
for (NodeTuple nodeTuple : mappingNode.getValue()) {
// Get the key node and the value node
Node keyNode = nodeTuple.getKeyNode();
Node valueNode = nodeTuple.getValueNode();
// Get the mark of the key node
Mark keyMark = keyNode.getStartMark();
// Get the line number of the key node
int keyLine = keyMark.getLine();
// Get the mark of the value node
Mark valueMark = valueNode.getStartMark();
// Get the line number of the value node
int valueLine = valueMark.getLine();
// Print the key, the value, and their line numbers
System.out.println("Key: " + keyNode + ", Value: " + valueNode + ", Key line: " + keyLine + ", Value line: " + valueLine);
}
}
}
}
The output of this code is:
Key: FirstKey, Value: {SecondKey={Enabled=true, ID=Some text}, AnotherKey={AValue=true}}, Key line: 0, Value line: 0
Key: TestKey, Value: {TestValue=More text}, Key line: 4, Value line: 4
Another way is to use the org.yaml.snakeyaml.events.Event interface, which represents an event that occurs during the parsing of a YAML stream. This interface also has a method getStartMark() that returns a Mark object for the event. You can use the org.yaml.snakeyaml.Yaml class to parse a YAML stream and iterate over the events that it produces. For example, you can use the following code to get the line number of the key FirstKey in your YAML file²:
import java.io.FileInputStream;
import java.io.IOException;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.events.MappingEndEvent;
import org.yaml.snakeyaml.events.MappingStartEvent;
import org.yaml.snakeyaml.events.ScalarEvent;
public class LineNumberDemo2 {
public static void main(String[] args) throws IOException {
// Create a YAML object for the YAML file
Yaml yaml = new Yaml();
// Parse the YAML file and iterate over the events
for (Event event : yaml.parse(new FileInputStream("./config.yaml"))) {
// Check if the event is a scalar event
if (event instanceof ScalarEvent) {
// Cast the event to a scalar event
ScalarEvent scalarEvent = (ScalarEvent) event;
// Get the value of the scalar event
String value = scalarEvent.getValue();
// Get the line number of the scalar event
int line = scalarEvent.getStartMark().getLine();
// Print the value and the line number
System.out.println("Value: " + value + ", Line: " + line);
}
}
}
}
The output of this code is:
Value: FirstKey, Line: 0
Value: SecondKey, Line: 1
Value: Enabled, Line: 2
Value: true, Line: 2
Value: ID, Line: 3
Value: Some text, Line: 3
Value: AnotherKey, Line: 4
Value: AValue, Line: 5
Value: true, Line: 5
Value: TestKey, Line: 6
Value: TestValue, Line: 7
Value: More text, Line: 7
I hope this helps you with your question. If you need more information, you can check out the following links:
- Java - SnakeYaml | Get all keys of a file
- Java - Get all keys of a map recursively
- Reading and Writing YAML Files in Java with SnakeYAML
Source: Conversation with Bing, 14/11/2023
(1) Java - SnakeYaml | Get all keys of a file - Stack Overflow. https://stackoverflow.com/questions/67880449/java-snakeyaml-get-all-keys-of-a-file.
(2) java - How to Access the inner(nested) key-value in an YAML file using .... https://stackoverflow.com/questions/48744919/how-to-access-the-innernested-key-value-in-an-yaml-file-using-snakeyaml-librar.
(3) Java - SnakeYaml | Get all keys of a file - Stack Overflow. https://stackoverflow.com/questions/67880449/java-snakeyaml-get-all-keys-of-a-file.
(4) Java - Get all keys of a map recursively - Stack Overflow. https://stackoverflow.com/questions/67938579/java-get-all-keys-of-a-map-recursively.
(5) Reading and Writing YAML Files in Java with SnakeYAML - Stack Abuse. https://stackabuse.com/reading-and-writing-yaml-files-in-java-with-snakeyaml/.
(6) undefined. https://www.java-success.com/yaml-java-using-snakeyaml-library-tutorial/.
First of all, I have been reading a few posts about keys, but none of them asks my question on how to get ALL keys of a yaml file, only on how to get an specific key.
Now, I want to create a file u...
I am trying to read config.yaml file using the snakeYaml library in java.
I am able to get the Module name (i.e [{ABC=true}, {PQR=false}]) in my config file.
Is there a way where I can directly re...
So currently I'm working on a yml file updater with SnakeYaml, but I have this issue that I don't know how to solve.
This is my class to get all the keys of the yaml file as a Set< String >:
...
In this tutorial, we'll go over how to read and write YAML files in Java with SnakeYAML, a popular alternative to Jackson.
presumably you opened the file somewhere with a path name
Hf trying to get what gpt-4 says is true to work
I am just lazy
Then why, when syntax errors occur, does the console display the line number of the config where it happened?
why i not can get this line from config at will
because those are separate systems probably
not in a sophisticated way
what do you mean
not using libraries, systems. Why can't I get the line number using 1 method?
syntax errors are thrown by snakeyaml during the parse process, it simply doesn't store this metadata beyond the deserialization process
translate error
Also the error snakeyaml gives is not always indicative of the actual error
Yaml can be broken in many ways where snakeyaml suddenly doesn’t know what to do
where on that page
all im doing is that. i want to factor out the region so it doesnt effect the region
Just check if there's a region at the players location
whats the method to check
Read the documentation page
?tryandsee
lmao
it really shouldn't be that hard to read the page
Hey, i only use one region
Exactly
so that'll factor out spawn?
Tag.LEAVES.isTagged(block.getType()), using the name and doing a string comparison just hurts
GiveBallCommand.java:24 is ```java
ItemManager.getInstance().giveItem((Player) commandSender);
which is
public void giveItem(Player player) {
player.getInventory().addItem(pokeBallItem);
}
yeah
Caused by: java.lang.IllegalArgumentException: Plugin already initialized!```
at codes.domino.pokeballmc.PokeballMC.<init>(PokeballMC.java:12) ~[?:?]```
clearly you did somehwere :P
get searchin
at codes.domino.pokeballmc.PokeballMC.<init>(PokeballMC.java:12) ~[?:?]
at codes.domino.pokeballmc.PokeballMC.getInstance(PokeballMC.java:33) ~[?:?]
at codes.domino.pokeballmc.item.ItemManager.<init>(ItemManager.java:26) ~[?:?]
at codes.domino.pokeballmc.item.ItemManager.getInstance(ItemManager.java:87) ~[?:?]
at codes.domino.pokeballmc.command.GiveBallCommand.onCommand(GiveBallCommand.java:24) ~[?:?]```
yeah i did
💀
i used a normal singleton pattern
forgot im working with bukkit
public static PokeballMC getInstance() {
if (INSTANCE == null) {
INSTANCE = new PokeballMC();
}
return INSTANCE;
}
this
ah right
how do u make an item glow again
u cant just give it infinity 1 and hide it anymore
at least make your lazy init thread safe
thread safety is lame 😎 live on the wild side
this is minecraft, what is thread safety?
hey how would I set a 1/10 chance to get an item?
^
like enchantment glow?
you just add an enchantment
than use the HIDE_ENCHANTMENTS flag
im kinda new to spigot and java in general
you can usually use google for those kind of questions
how would it work for 1/3?
the same logic applied for the 10%
but
Maybe you should take a look at a Java tutorial
this is a good one
what's the best way to check that a player has started holding an item?
declaration: package: org.bukkit.event.player, class: PlayerItemHeldEvent
much appreciated
what if i wanted all the things to have an answer
then don't use probability
ok
how would I do it if I didn't use probability, sorry if I'm being annoying I've tried a lot of stuff
do what?
run code
you juts uhh type it out
and compile it
then put hte plugin in the server
I meant how would I calculate the chances, sorry if I was unclear
you need to use random
just follow the suggetsion of the thread I posted earlier
there isn't really a much better way than that
How do I change a player's fall speed?
does any1 know if its feasable to cancel knockback? as in when i hit an entity it should take damage as normal. but take zero knockback
hmmm have you tried setting its velocity to 0 on damage event? or does that not work well
By setting his velocity
you could also maybe cancel the damage and then reapply it by getting hte playres attack damage and apply it to the entity via code?
im never sure if final damage is with all calculations done
it should be right?
hm yea i could try this. but im pretty sure this will not show my client the hit visually
using EntityDamageByEntityEvent#getDamage should work
which is a problem
you might need to send the packet for that unfortunately
i think so indeed.
bukkit might have API for that for some reason I remember there being API for that
il see if i can figure that out. thanks for the insight
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Player.html#sendHurtAnimation(float)
only for player 🥲
yikes
thats pretty interesting
shoulnt that be the same code for all livingentities
oh I think that does incoming damage
How about you dont set it to 0 but what it is during the damage event?
that should actually work better
yea il defo try that first thanks
Do I set that value once or do I need to set it multiple times?
Depends if you want to set the fall-speed or fall-acceleration
I want to make the player fall slower
best option is using the potion effect for that
everything else will look janky because the client and server will disagree about velocity
This actually sounds like something that could be added to spigots API with a bit of work. Entity#setGravityScalar(double)
for other entities that will work fine, visually for other players too. just for the player itself not really
Bukkit.getEntity(UUID) called in ChunkLoadEvent returns null, even after 1 tick. Is there a way to know when entities are 'registered' and Bukkit.getEntity(UUID) is safe to use with newly loaded entity uuids from loaded chunks?
You can get entities which are loaded with the chunk by calling Chunk#getEntities()
Actually this might be exactly what I am looking for
👍
how to cancel a minecart move where the player pressed "w"
hmm this worked for 1 but not 2
int min = 0;
int max = 8;
int result = (int) Math.floor(Math.random() * (max - min + 1) + min);
if(result == 1) {
Its good if you do this by hand for some experience, but java has built in methods for that.
Random random = ThreadLocalRandom.current();
int min = 0;
int max = 8;
// Rolls a random number from 0 (inclusive) to 8 (exclusive)
// So possible values are: 0, 1, 2, 3, 4, 5, 6, 7
int roll = random.nextInt(min, max);
yo if I register custom commands but I don't want to do so whenever Essentials' present
but just checking whether the command was already registered doesn't work (Essentials only problem)
can I do some loadbefore magic
to fix this?
Check if essentials was loaded and do a softdepend on Essentials
Still makes me sad that ThreadLocalRandom has nextInt(min, max) but regular Random doesn't
Ah right
it's just random.nextInt(max - min) + min
I'll try that, thanks
Do a PR
The result 2 isn't working but 1 does
I know this isnt completely spigot related but idk where else to ask this. I have an animatronics plugin which lets me play an armorstand animation when I use /anim play test
I can put that cmd in a command block too and it works fine, but I want to run it whenever a player is at a certain location. I wanted to do that with
/execute if entity @p[x=-1040.441,y=71,z=-1336.528,distance=..1] run anim play test
but the anim play test part is not recognised. It does however recognise other plugins' commands. Any ideas? I'd like to keep it in 1 cmd block if possible
Generally spigot commands don't work with /execute
Show your code
plugin commands are really not designed to be used with /execute
Other plugins may be using a library that registers them
Hmm damn
So what should I do in this case?
Add another cmd block and activate that command block with this one?
Chain command blocks ig
condition roll == 2 is always false
how can i create potion arrow entity?
Still null when using EntitiesLoadEvent :/ even after waiting a tick. Any clues why @young knoll ?
i find org.bukkit.entity.Arrow.setBasePotionType, but cant understand, how can i initialize a variable
Doesnt work
Not sure, are you sure the UUID is correct
Caused by: java.lang.IllegalArgumentException: Specified enchantment cannot be applied to this itemstack
Use the unsafe method
addUnsafeEnchantment iirc
Or for ItemMeta there is a boolean as the last arg
Yeah basically doing this:
@EventHandler
fun onChunkLoad(event: EntitiesLoadEvent) {
for (entity in event.entities) {
println("${entity.uniqueId} <> ${Bukkit.getEntity(entity.uniqueId)?.uniqueId}")
}
}
First uuid is not null, but the second one is with Bukkit.getEntity
It ain't used by any program
int min = 1;
int max = 8;
int roll = Random.nextInt(min, max);
if(roll == 1) {
if (target != null) {
ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
ItemMeta meta = item.getItemMeta();
// Check if meta is not null before setting display name
if (meta != null) {
meta.setDisplayName("§6§lORANGE §b§lSWORD");
meta.setCustomModelData(1);
item.setItemMeta(meta);
target.getInventory().addItem(item);
} else {
sender.sendMessage("Failed to get item meta.");
}
} else {
sender.sendMessage("Player not found.");
if(roll == 2) {
if (target != null) {
ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
ItemMeta meta = item.getItemMeta();
// Check if meta is not null before setting display name
if (meta != null) {
meta.setDisplayName("§d§lPINK §b§lSWORD");
meta.setCustomModelData(3);
item.setItemMeta(meta);
target.getInventory().addItem(item);
} else {
sender.sendMessage("Failed to get item meta.");
}
} else {
sender.sendMessage("Player not found.");
Are you?
checking if roll == 2 after a roll == 1 if statement?
omg TY i forgot
anyway what the fuq
Your if(roll == 2) is inside the block for if(roll == 1) { so it will never be true
where should I put it?
Outside the if (roll == 1) block
Check for 1, 2 and 3 ticks afterwards
THERE'S A LIMIT
on how big the gif the can be?
sucks
Yes there is a file size limit
hmm
;-; ok, but do you know the reasoning behind these magic numbers?
Probably multithreaded jank
The event knows the information before the rest of the server does
because the event can be cancelled therefore it makes no sense for the rest of the server to know about an entity which ultimately never existed 😛
It can't be cancelled
There is a seperate event for loading entities https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/world/EntitiesLoadEvent.html
ah ok, all I saw was chunk load
ah his method name was chuink not entities, so confusing
ah
well its still the case that the event still knows before hand before other things
or at least that is typically how it is for the events anyways
itemStack.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING) != null;
returns false
even tho i just did
meta.getPersistentDataContainer().set(key, PersistentDataType.STRING, entity.getUniqueId().toString());
itemStack.setItemMeta(meta);
well uh
how do I make it
show the gif
well?
and I mean
for like
spigot resources
but shit ain't cooperating
use the img tag?
doesn't work
it might be imgur not allowing embeds possibly?
only thing I can think of unless you are using the img tag incorrectly
typically its [img url=""](text here that shows up if img does not[/img]
what
No markdown 
just tell me what's missing
you're being extremely useless right now, you know that?
Well, what I said has no relation to your problem
Im pointing out the poor design of the post editor
It should utilise markdown
Its more portable
Simpler
And is used almost everywhere
it does make use of markdown
it uses the good old BBCodes
let me go look on my page
You mean markup?
Well let me clarify
BBCodes & Markdown are both markup languages
Bruh
Markdown itself isn't a markup language
It is though
unless there is a lib called Markdown
Bro
Markdown is the language, CommonMark is the standard
You obviously have preprocessors to interpret the language into images/html
But its a markup language
oh, which editor are you using?
now that I remember
you need to use the editor that lets you edit everything
Well I guess I'll just go fuck myself
I learned this hard way myself long time ago with Bukkit
anyone know a good builder generator for intellij
Wdym by that?
yo! any ideas why my test-bots cannot connect to my server? ```/127.0.0.1:64226 lost connection: Internal Exception: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(7) + length(8) exceeds writerIndex(8): PooledUnsafeDirectByteBuf(ridx: 7, widx: 8, cap: 8)
I use another botter for my antibot testing
Please rate my antibot
It has very little recognition to how well it's written
It's for spigot servers
builder pattern
Just start up a second launcher
well
it seems to use the wrong protocol version for 1.20.2
"Outdated server! I'm still on 1.20.2"
A simple app used for stress testing Minecraft servers with bots - crpmax/mc-bots
It has a different release version for each mc ver
Also my antibot is called AlixSystem if you could test it
Wha-
yeah
Download ViaVersion then
ehhh thats gonna cause issues with my plugin
yeah it does not make any sense
Also ViaVersion seeme to be decently written
had the same issue with the old botting software
I just changed the protocol version there
.
but yeah it's not that easy here
How would it cause any issues anyway?
im not gonna use ViaVersion for my whole server
You do know how testing works, right?
im also not gonna rely on ViaVersion for testing
thats a factor than can cause errors which makes it uncomfortable
It's probably the most reliable plugin out there
not really
What
You're being really pessimistic for an unknown reason
I do not wanna rely on other plugins for ANYTHING in my testing
It would only matter in anticrashes, antibots and anticheats
Maybe packet analysers also
But not for some gun plugin
which is exactly what im doing too lol
What
it's not only a gun plugin
and even my gun system might mess with some packet stuff indeed
it's not just normal entity guns
it's a custom written projectile system with my own raycasting algorithm and hitboxes lol
the fact is that im not gonna use viaversion
Yeah then it won't matter
I am creating a vehicles plugin and I am creating a train. I want this train to move on rails. The problem is that when the train is fast enough, he leaves the rail. How can I get the current rail even if the train is fast?
Also that's really easy to make
no it's not
There's a lot of implementations out there already
And even a built-in one
The bukkit one
raycasting algorithm? Yes. A raycasting algorithm customized to my needs? no
because it's raycasting my custom projectiles
How the fuck am I suppose to know your needs
it does not exist
It's still increadibly easy to make
my gun system is not easy to make
no
And ViaVersion only matters for 1.14 changes pretty much
what was the name of that SQL something shit
for databases in plugins
I cant find it
But that's only for anticheats
Bro
I am tracking player bodyparts as custom Cuboids with my own hitbox intersection algorithm on the playermodel
That's subjective
you shoot your gun, it raytraces and can exactly tell you on what pixel of the SKIN you hit, not the normal hitbox
You say it like it's a big deal
declaration: package: org.bukkit.event.vehicle, class: VehicleMoveEvent
it is a big deal imo
I am using a custom nms entity
This approach has not been done publicly by now
Have you accounted for everything?
custom entities still have events thrown
unless its an entity that doesn't exist in the server
im working on it, but so far it is looking well
it is a cow
Hmm
dumped at least 100-200 hours into working on it lol
then use the entity move event
I have no idea right now of how I could do it with pixel accuracy with the player's body turned and great distance calculation offsets
I did much more for my antibot
yeah see, so you admit that it's not "very easy"?
its simple, you need to obtain the skin texture so you can have measurements
sounds like making separate game would be easier lol
however, saying pixel accuracy is a bit of a misnomer due to the fact that there is two different kinds of pixels
skin texture pixel's locations are not stored anywhere on the server
Well yes, but exactly why do you neef pixel accuracy?
you gotta calculate it by reversing the client code lol
not necessary if you know the size of an image
because I like it
make it store them
as long as you know the size you know its size in the server
and you can then do calculations on that
basic algebra
thats what im doing, im simulating the player model just how the client displays it
Ah you mean like getting the pixels as bytes, and the faced location?
the server does not know the size of the texture on screen?
and size is not the deal
I am confused on why you are talking about texture size
It's much more complex hmm
it's not like it's a flat 2D texture
I don't think you're seeing the whole image right now
do you not know how to obtain picture sizes?
what picture?!
skin textures are just a flat 2d png
and?
No shit
you can measure the size of a skin
how do I manage SQL database in plugin
multiple of them
once you have the skins size you know how large it is in the server
Yt tutorials
great now you have 0 data on where the bullet is gonna intersect lol
yeah im asking for a tutorial
because there are 10000 rotations, tracking and so on
not kody simpson cuz guy literally just does "well you put it here because I say so" without explanation
this is not true
this is true
you obviously fail at basic math
?????????????????????????????????????????????
Bro
you seem to not understand what im even doing
Are you really that ignorant?
Well that's most yt tutorials
well that aint gonna teach me much is it
I am not ignorant just I know how to do pixel accuracy as being claimed and that it isn't super difficult, I already helped someone do pixel accuracies last year
if I dont get where did shit come from
You can search for the code explanation on the web
pixel accuracy on what? Do you even know what im doing?
do me a favour and explain to me what you think im doing
I was replying to the part doing pixel accuracy on trajectories of bullets is not hard
pixel accuracy on WHAT
Most of it is just connection handling and maybe some caching
if you want to make actual trajectory you need more than basic math (trig)
and basic understanding of physics
do you have short term memory?
Trigonometry is easy at this level
this applies to 3D space, NOT the hitbox, the actual skin, with rotations, and then also calculating if you for example shot through multiple bodyparts and so on
if you have a fucking flat 2D texture you know 0 shit about the rotation of the player model and so on
idk what basic math exactly means but I'd assume its primary school math, lol
It is
they dont really teach trig and its application in primary school usually
it's not easy to track an exact player skin model on a serverside player
rare case if you are academically gifted
Oh wait no
I consider algebra basic math
I ain't english-native
you basically gotta recreate the behaviour of the player-model on clientside on server
trig can obviously be used here and may make it easier in terms of formulas to use
Middle school
however, algebra is more the sufficient for this
your understanding of basic math is extremely broad and vague
if that is all you know that is
Show it.
Show how you did it
Or explain in detail
linear algebra is NOT basic maths
but yeah you won't come any far with just linear algebra knowledge lol
I had endomorphism a few hours ago
yes it is not basic at all
ok, you don't consider algebra basic but I do since you learn algebra in middle school and beginning of high school in the US
which could be technically useful if you want to do some shenanigans with planes
idk when high schools exactly is in America
like vector conversion from x,y,z to x,y
but there is a huge difference between high level algebra and low level algebra, for example
happens right after middle school, we don't base school years on ones age
no its just, when you say "algebra" you are mentioning entire chapter of mathematics
idk when "right after middle school" is
you'd have to say what you consider basic in algebra
because there are both complex and basic things in algebra chapter
you do not learn complex linear algebra in 8th grade
you still continue to learn this stuff even in uni
I took 4 years of algebra before I even got to high shcool, so yes you do
are you asian by any chance
no
I am Half Canadian French and Half native american
into learning linear algebra before hs
I bet you won't do complex linear algebra in 8th gradem no
you wont, at school
you might do it in your free time
I learned like 30% of algebra because of the gun system and shit lol
back in the days
I started this project years ago and returned
im not balls deep into algebra
yeah same
I prefer analitic math
but alf bro you are just ignoring anything else while just saying "tHiS iS bAsIc MaThS"
like when I learn that sine can actually be expressed as power series
without even understanding what is being done
it depends on your school I have gone to two extremely well funded schools
you still won't
I live in Poland my school barely could afford heating
lmao
Yoooo you Polish as well?
we had 2 weeks off cuz they couldnt afford to pay
Bracie kurwa
you are ignoring anything else while just hooking on one stupid thing
Witaj
Polska gurom
F
I have been to Poland
thats the most american thing I have ever heard
Greatly relatable
its ghetto but
think im gonna drop the botting stuff for today then
nostalgic ghetto
America 👍
I dont talk in absurd insulin price
Sure, but it doesn't make it any less true. To believe that just becacuse in your country you didn't learn it doesn't mean it applies to another country especially one as large as the US where just going the next county over is the difference in a good education or a bad one
LMAO
how tf does this work
ah shit I gotta learn some French for tomorrow too
okay fine you went to prestige school and were most likely academically gifted, you are pretty damn good at maths and used your free time well, but what does it exactly change rn in the conversation
and it's already 11pm
your understanding of basic math is way beyond average person at this point
nothing
No I am not ignoring everything else. I think the hardest part of your system would be doing the rotations in an efficient manner where it wouldn't be too late
And I gotta learn Polish
even one that is kind of into maths or technical stuff
I wake up at 6 am
yes, which is far beyond basic maths. The maths part of it is also not the only hard part
ja pierdole mialem dzisiaj od 10 do 20 zajecia na uczelni XD
Ło chuj
Jak dobrze że ja jeszcze w średniaku
it is a combination of a lot of mid-tier-complex systems that make it so special
https://youtube.com/shorts/Wtf84-ujVN4?si=NwvwCy88Z8HY9h_L @orchid gazelle thats how the cannon was made
:]
oh yes
well algebra has existed before trig, so yes you can do everything with algebra, just probably not fast enough depending on the system. I think for the rotations if I was to do it would be to use Quadratics
or like ester of HNO3 and celuloze
but we live in trig era so no need to reinvent the wheel
point being basic math term isn't static and same for everyone
I first tried to use a Quaternion-based system with a custom Quat implementation but then I dropped it with a 100x more simple matrix mult rotation -> cuboid system
which is still, kinda complex but 1000x better
Gl y'all 👍
I would have been interested to see that attempt
Amma head to temporary slumber of nothingess
the quat attempt?
not many people here attempt such things 😛
yeah just to see how you were going about it
well imma try to remember but it's from like 2.5 years ago lmao
well I don't need you to replicate it lmao its fine
imma try to find the project rq maybe I still have it
had to use EulerOrders, basically I have a playerTransform, limbTransform and then that calculates into every single limb of the player which I then save
so you have a Quaternion centered on the player, which applies it's rotation and so on on halfExtents
which yea, you gotta let that all happen in relative space and then translate it to world space and so on
iirc the software basically creates the representation of the rotated playermodel in relative space and then translates it into world space
and yeah, you can imagine that this is INSANE for a previously 13 year old guy in school lmao
then I switched up to my matrix mult system, which was literally the way how I learned about a lot of algebra stuff in the first place
fun story, I learned how matrix mults applied on vectors work and then like 10 weeks later we learned it in school
ah so you ended up ahead 🙂
yeah vectors are just matrices
but multiplying matrices isnt really AxB = BxA idk how its called in English
you get what I mean
you gotta transpose it
so yeah need to get a gist of basic operations
yeah, that was around the point where I switched to only hitting the best grades in maths because I got motivated asf lmao
surprisingly for mathematicians its not common to assume that a+b = b+a
yeah we had to do it without a calculator
applying rotations on vectors and so on
without calculator
its not
now after graduating on it I switched to the gymnasium
Cross P?
one of my favorite theorems from Algebra is Pythagoras's Theorem
it is such a useful theorem that can be applied almost anywhere lol
yeah lmao
Does anyone know how to hide potion details?
declaration: package: org.bukkit.inventory, enum: ItemFlag
Hey the name fits for once!
accept it doesn't here
HIDE_POTION_EFFECTS does much more than that
oh nvm I get what you meant now lol
bruh
Wait
i used it all but nothing work! i just want to hide the details in the circle
Why does the armor trim flag say it hides trim from leather armor
Hide potion effects should work
Otherwise maybe hide attributes
how can i set an entitys max health
its an attribute, getAttribute(generic_max_health) and set/modify that
thx
How bad is it that I pretty much want to replicate hypixel skyblock mechanics and make an indicator of how well I manage to recreate them and after that adjust them to my needs
if im not sure Ilussion Skyblock is the base of Hypixel skyblock or something similar
I mean trying to make enemies, damage indicators and statistic system, profession levels and world divided maps
And then adjust or build additional things to my need
Like use hypixel mechanics as base
how do i apply the modified attribute to the entity
also why cant i do entity.setHealth just found that in the living entity class
you can use set health, but max health is an attribute
but you don't need to apply anything. you either add an AttributeModifier, or you set the base value
setHealth() is for setting the health itself, not for declaring how much health can have in total
in player
not in entity
a player is an entity
well yes but player extends entity
oh okay then spigot forums lied to me
good to nkow
i can not get this to work ?paste
?paste
i think that error is pretty descriptive
yh apart from the fact that it is not null
its right there
it finds the key
but the data itself is null
yeah casting to List<Object> seems really wrong
make your own (de)serializer
but why cant i just cast it to List<Object> all of them are objects arent they
and i asked previously and everyone agreed that lists can contain differnt data types
oh fair enough
list is for example something: [1,2,3]
Lists can just have 1 data type per object, if that what you mean
you treat whole section as a list
yh i though its possible to do that
or also:
something:
- 1
- 2
- 3
but yh makes sense
its supposed to be if the creature has a gender or not
yeah that was extrange when i read haha. I had to read it many times
What exactly trying to do?
ark
Because what you sent seens more to be a config section, atleast the yaml format you sent
oh you masking ark evolved?
yes
the cojnfig is supposed to let you create and edit all creatures
in various ways
thats why i have so much data in there
that still a section
from what i seeparamite and paramite2 are config section object
but yeah as they have said i would make a custom serializer for that format saver
this should work then im too lazy to make it rn
wanna test if the other 100 classes work
remember smth
the first thing which is hide in the cap
you still have a section let say
gian_octopus is an array, thats true
i know its supposed to be like that
there you have array with more arrays inside
makes it easier to read out the values
not a problem,
i pass everything into a class constructor afterwards anyways
its extrange i would treat as you did before with config sections
why not just make custom serializer for your object ?
yeah what we told hehehe
im to lazy RN
GPT
i wanna test out the other stuff first
GPT less than 10m