#help-development
1 messages · Page 1796 of 1
You need to get the resource as a Stream and write this Stream into an FileOutputStream
I use getResource() and Files.copy()
Ex; Files.copy(getResource("name"), <file>);
I use REPLACE_EXISTING
So I wrote some code(code.java). But now I need this one more often so I did a method(codeButInMethod.java). But in this code I need to return if something specific happens. Thats no problem in the code.java. But if I call the removeEssence Method in the standardAbility Method how do I tell my standardAbility Method I want to return then?
https://gist.github.com/ItzJustNico/df0d62c75f04c2f4176d515ebe42b40a
Could you try to explain your problem a bit more thoroughly or more abstract pls?
I have a Method1 (removeEssence) in a other Method2 (standardAbility). If something specific happens in Method1 a want to return in Method2
I hope thats better now
Really hard to explain
So... java public void generateResource(String filename, File file) { try(InputStream inp = this.getClass().getClassLoader().getResourceAsStream(filename)) { System.out.println("CanWrite: "+file.canWrite()); Files.copy(inp, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace(); } } Outputs: CanWrite: true yet still errors with java.nio.file.FileSystemException: .\authentication.yml: The process cannot access the file because it is being used by another process.
This is a example but if you wanted to return a Boolean you would in the inner method use return Boolean and when you call the inner method from the other method you would do an if statement
And do if Boolean from inner method is true return
Oh I thought there maybe is some better method to do it or so haha but thank you
That is the only way if I’m reading your question right xD
perfect haha
btw
Just check out the source for saveResource and adjust it
public void saveResource(@NotNull String resourcePath, boolean replace) {
if (resourcePath != null && !resourcePath.equals("")) {
resourcePath = resourcePath.replace('\\', '/');
InputStream in = this.getResource(resourcePath);
if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + this.file);
} else {
File outFile = new File(this.dataFolder, resourcePath);
int lastIndex = resourcePath.lastIndexOf(47);
File outDir = new File(this.dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (outFile.exists() && !replace) {
this.logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
} else {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException var10) {
this.logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, var10);
}
}
} else {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}
}
yeah that's of course also possible
I also just noticed that from the source code lol
just do saveResource("resources/yourResource") and also put it into "resources" in your jar file
definitely the easiest solution 😄
How do i get the item that broke the block with BlockBreakEvent
Thats not my issue though. I use Files.copy on all my bots with no issues... Why is there an issue now?
Get the players main hand item
Player#getItemInMainHand
Player#getEquipment#getItemInMainHand
whats the sethealth syntax
player.sethealth but then what do i put like a number or
20 = 10 hearts
Player#getInventory#getItemInMainHand
so i put player.sethealth("20") for twn hearts
Player is an entity
That's a string
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
🗿
@karmic grove
it literally says it expects a double, why do you want to provide a string?
Replace with just 20
yea i saw with error
There are several ways.
- Just return a boolean
- Create an enum "AbilityResult" that contains > 2 cases if a boolean is not enough
- Pass a delegate to your method. A Runnable or Consumer<Something>
perfect thank you
@lost matrix did you have time for this one already?
I'm getting this error
This is my pom.xml dependencies:
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>8.3.0</version>
</dependency>
</dependencies>
I'm using Titles#sendTitle()
No errors on IDE
does getting the drops from BlockBreakEvent include fortune?
Are you shading it
ig
whats top sethealth you can do
Whatever the maxHealth is
I think the default spigot.yml limits it to 2048
o ok
which statistics requires additional parameter? all except the untyped ones?
damn
oooh i was looking for this for a long time
i had a trial version installed and i installed material ui for no reason
then deleted, and installd community and i forgot to install material ui
thanks
i deleted the trial version with the whole plugin thing
and installed community
and forgot to install material ui
and was looking for those icons
@karmic grove
btw
if u wanna set health to 20
dont do that
i prefer getting the max health
x.setHealth(x.getMaxHealth());
it is about the font
getMaxHealth is deprecated though :p
x is the player
try lucida sans or lucida console
and if still same, Editor>Color Scheme>Color Scheme Font
ussally its this but randomly it doubles
2048 is 1024 hearts
wat u trying to do rn
it isnt
its just glitching so it doesnt show the first time
i think
my colorscheme is cool
see i scared everyone
whats wrong with this tho?
do i need to escape '
ur yaml
is it the ' character?
yes
How can I make all the players on a server teleport to one place, in a defined time
is " " even supported by yaml?
yes
every time i set a string it changes to ' '
how can i get player head texture (item)
Probably due to snake yaml
hmm
Because yaml is quite uh inconsistent or rather allows various syntax
yea probably that
I tried creating a parser for yaml, in conclusion I gave up
How can I make all the players on a server teleport to one place, in a defined time
?scheduling
So i'm facing an issue with retreiving a pending task. When i schedule a new task. I grab the taskId and store it for later use.
Then when i try to retreive the pending task using its ID it throws me this exception:
Caused by: java.lang.IndexOutOfBoundsException: Index 22857 out of bounds for length 0
And yes, the task is still running while i'm trying to retreive it.
BukkitTask task = Bukkit.getScheduler().getPendingTasks().get(this.timerTaskID);
This piece of code throws the error
Any idea to how this is happening?
that's a big number
I use this code to start my task
this.timerTaskID = Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> this.execute(), interval);
Any clue?
Scheduler#getTask(int)?
No such method found
how do i open web config for luckperms
/lp editor
Bukkit.getScheduler().cancelTack(nameoftask);
uhh stupid me
Will test it out. Thanks buddy
Yep it worked. Thanks to your both
You may also use methods that returns BukkitTask
Quick question, is there an event for when a MOB starts targeting a player?
am i looking for custommodeldata to use textures of texturepacks on a item?
or custom damage
this is my code
import com.andrei1058.bedwars.BedWars;
import online.shakiz.BwCore.BwCore;
import online.shakiz.BwCore.files.NickManager;
import online.shakiz.BwCore.utils.utils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
public class Nick implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
NickManager nickManager = new NickManager(BwCore.getPlugin());
String prefix = utils.chat(BwCore.getPlugin().getConfig().getString("prefix"));
Player p = (Player) sender;
UUID uuid = p.getUniqueId();
String usedNicks = nickManager.getConfig().getConfigurationSection("Nicks").getValues(true).toString();
if(!(sender instanceof Player)){
sender.sendMessage("Command can only be executed by players.");
}
else if(!(args.length==1)){
sender.sendMessage(prefix + "wrong usage please input a nickname to use");
}
else{
if(!(BedWars.getAPI().getArenaUtil().isPlaying(p))){
if(!usedNicks.contains(args[0])) {
nickManager.getConfig().set("Nicks." + uuid, args[0]);
p.setDisplayName(args[0]);
}
else{
sender.sendMessage(prefix+"the provided nick is used by another player.");
}
}
else{
sender.sendMessage(prefix + "cant use this whilst ingame");
}
}
return true;
}
}
Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoClient Can someone help me?
Yes, thats EntityTargetEvent iirc
Did you shade mongo
Thank you
. rip
EntityTargetEvent is supposedly a very terrifying event to listen to given how frequently it can fire
So, you know... bear caution
What's the cause of the spacing here (javafx)? https://imgur.com/nHNZCon
i'm wondering how to set the data on itemmeta that these texturepack predicates need to apply textures on items
that is a plain percentage from 0 to 1 in regards to damage
yea but i'm currently using a plugin which uses that number to apply the correct texture on it
so what exactly is your issue here. As stated the predicates do not use custom model data but rather match the material being unbreakable and damaged
take the percentage and multiply it by the total damage the item can take
if there is a way in the api to set client side textures on itemstacks?
no
there isn't
the resource packs is the one that has complete control over how items are rendered
(well if you don't count skulls I guess or other nbt reliant items such as banners)
Well if you take the screenshot you posted
you could have diamond boots look like grim_boots by making them unbreakable and setting the durability to whatever number that is multiplied by the max durability
uhm custom model data exists
^^which is the preferred way
CMD is 1.14+ iirc?
Yes
and how to use it?
Meta has a setCustomModelData
i've always based textures on that predicate
ItemMeta.setCustomModelData
and see some guide on planetminecraft or youtube
damage for textures is not not smart these days
but i dunno how to change the json if i use the .setModelData
ok great
Hello, I'm Geegaz ! As you may know, the first snapshots of the 1.14 introduced a new format for the JSON item models custom model data . It's also a...
memory section is an implementation of configuration section ?
I mean, MemorySection is an implementation of ConfigurationSection..
😅
What’s not working to be more specific?
validate that the config file is actually containing this (e.g. written to disk if you read from there etc)
you are calling the correct method
Are you setting that value during runtime ?
grabbing these section when before throwing in some map will fail
ah
hmm let me test it in a local setup
it should work
Is your yaml malformatted ?
bump
well, idk my setup returns a memory section as expected :/
you are not writing the file to disk are you?
like you aren't calling saveDefaultConfig somewhere
ah
I mean, best guess would be to still throw your yaml into an online yaml parser (e.g. https://yaml-online-parser.appspot.com/)
and see what comes out
does the MapCanvas#render() function create a new CraftMapCanvas each time?
I get this output when printing it, that means yes, right?
[21:32:46 INFO]: de.MapMenu.master.Canvas@3a1dd9db
[21:32:46 INFO]: de.MapMenu.master.Canvas@729adcb1
[21:32:47 INFO]: de.MapMenu.master.Canvas@695fdea2
[21:32:47 INFO]: de.MapMenu.master.Canvas@2db092f5
[21:32:47 INFO]: de.MapMenu.master.Canvas@2d5ba98b
...```
I meant MapRenderer#render, sorry
😅😅 happens to the best, dang you outdated configs
I just have a local version of spigot checked out in my IDE (well paper to be exact but pssh)
xD
And in regards to creating new canvases, it does that if you changed the renderer
does it change automatically?
not that I know of
but your canvas you linked isn't even spigots canvas xD
seems like a yes
it is lol
Yea so you are creating a new wrapper
doesn't mean spigot is creating new instances
so the client will use the texture with the same custom model data as noted in the json file?
Well as with damage, you map a new texture onto the material
ah i understand
how do i get a player's ping
now trying it out :yes:
nms
okay
((CraftPlayer) player).getHandle().ping
declaration: package: org.bukkit.entity, interface: Player
owh really
i'm on 1.8.8
sucks to be you
another one 🙄
how can I shoot an arrow
and give the credit to player
ik launchProjectile
but it doesnt give the credit to player
shoot an arrow first 
PLayer#launchProjectile
public int getMinigameId(Minigame m) {
for (int i : getActiveMinigames().keySet()) {
if (getActiveMinigames().get(i).hashCode() == m.hashCode()) {
return i;
}
}
return -1;
}```
this returns -1 even when the item is in the list
i've tried without hashcode as well
that is a shocking method
lol it probs is
Use a HashMap 
its currently Map<Integer, Minigame>
so i swap around?
assign an id to each minigame
how do I give it more speed?
read the docs
declaration: package: org.bukkit.projectiles, interface: ProjectileSource
yo wait
so you can get the key from a value
and the value from a key
yes, its just two maps that are the inverse of each other
oh i always used to do it myself
didn't know there was a class already for that
also never thought of making it into a wrapper
public int getMinigameId(Minigame m) {
return activeMinigames.get(m);
}```
apparently the `Minigame` isnt in there
the items in the hashmap extend minigame
would that affect it
i think it would
can i force suspend a tripwire
it doesnt give the player credit
what do you mean credit
Of course
Arrow#getShooter
Because the player isn’t hitting them, the arrow is
if an object in the list extends <T> then would it be able to do .indexOf(itemthatextendsit)
equals doesn't work on this
lemme explain
there is a list of Minigames
instead of minigames in there, it is a list of HexHuntGames, which extend Minigame
but it is still a List<Minigame>
if i do indexOf(HexHuntGame)
it doesn't work
how do i fix it
i can't cast hexhuntgame back to minigame though
and i cant cast the list to List<HexHuntGame>
why
hello, is there any way to build a 1.18-rc3 version of spigot.jar?
or is there gonna be a full release available tommorow?
Dear All
As we mark the 9-year anniversary of SpigotMC.org, it is my pleasure to announce that development/preview builds of Spigot for Minecraft...
any idea?
Override the equals method
where
In the parent class
what would i make it be
Something that can determine if they are equal
@Override
public boolean equals(Object o) {
if (!(o instanceof Minigame)) return false;
return o.hashCode() == this.hashCode();
}```
oh lol
Just use the one intelliij makes for you
oh yeah, i forgot intellij had an equals() and hashCode() generator
Hi! I am trying to move a custom client-side EntityPlayer to a certain location, while also accounting for the look rotations. This is all done in the same tick. I send three packets:
- PlayServerRelEntityMove
- PlayServerEntityHeadRotation
- PlayServerEntityLook
For some reason when I add in the head rotation packet, the move packet just stops taking effect. Could it be that the head rotation and player movement can't be changed in the same tick? Or does anyone else have any possible insights on this? (I am using ProtocolLib and a packet wrapper, if someone has worked with NPCs using ProtocolLib, I'd really appreciate any help)
I have a question regarding the fact to use reflections to call methods by their name. Is that a thing that's "ok" to do or should i discourage from doing so?
Also sincr all the articles I've read about reflections dont really give a nice or even consistent answer to the question "when to use them" could someone voice their opinion?
'dont use reflection, use the API'
Could you elaborate pls?
He can not
what are you trying to do
Im trying to create an object in which I can parse a mathod to be executed
Ah that should do the job, thanks a lot
Lets say the Object "CustomItem"
I want it to execute a certain method when I right click with it.
So the constructor would gopefully look something like this:
new CustomItem(<name>, <eventId>, <methodToBeExecutedWhenEventHappens>)
Ah, thx, since I didn't want to use reflections, is there any "danger" Ill have to be aware of using refrencing ?
no
Sick
yes
intellij says Condition 'event.getEntity().getKiller() instanceof Player' is redundant and can be replaced with a null check
Hmm thought the api only captures player instances
oh
LivingEntity.getKiller is always a player
well maybe
Or null
Well, the attribute preferably
?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. Create a thread in case the help channel you are using is already in use!
i want to create a scoreboard api where i can update scores more easy
Okay and what do you need help with
Do you know Java?
I want to use teams because of flicker and so on
no its not
it is
it also doesnt appear to use packets
👀 the Bukkit API also uses packets
someone told me it uses packets
teams?
This
Everything uses packets if you get down to it
scoreboard api component support when
what's the difference between FIRE and FIRE_TICKS (damage cause)
standing in fire deals more damage than just burning
ahh
Scoreboard.Spigot 👀
can i store a location in metadata
can i do this? player.setMetadata("backLocation", new FixedMetadataValue(Core.getProvidingPlugin(Core.class), event.getFrom()));
Yea, it can store any value
Caused by: java.lang.ClassCastException: java.util.Collections$UnmodifiableRandomAccessList cannot be cast to org.bukkit.Location
@ivory sleet Where do I learn some serious plugin development, like from the beginning to a pro level
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
Not java, plugin development
I know enough java
then learn the bukkit api
Ye, where?
bukkit docs
?jd
whats the easiest way to store args when you run a command
for example when someone runs /command then i want to store this text
store them where
in a variable would be fine
Then just... store it to the variable?
how do i store the command input
the args[] in a CommandExecutor's onCommand is their arguments so
that stores what they put after?
Store? explain store
so "/command arg1 arg2 arg3"
args[] is { "arg1", "arg2", "arg3" }
shut
so i have this this will save it as variable args?
u can use that to copy its values into another String array if thats where u need to store it
if ur just accessing it within its command execution then theres no need to store it anywhere, just use that array
i just want it to be a variable for a little bit then ill do somthing with it later
Hi guys, I'm trying to create a new potion. What should I do? I had created a new class which extends the PottionEffect class and then I've implemented a new constructors that would pass the parameters to a super constructor. Am I going the right way?
- Creating a truly New potion effect is impossible without mods
- No, you shouldnt extend any api classes if they wasnt meant to be extnent/implemented by plugins
Oh XD
okay, thanks
but I'm able to create a potion with stronger effects, right?
when i do player.teleport((Location) player.getMetadata("backLocation")); it sends an error in console
full code:
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("You cannot execute this command in console.");
return true;
}
Player player = (Player) sender;
if (!(player.hasMetadata("backLocation"))) {
sender.sendMessage(Color.translate("&cCouldn't find your previous location."));
return true;
}
player.teleport((Location) player.getMetadata("backLocation"));
player.removeMetadata("backLocation", Core.getProvidingPlugin(Core.class));
player.sendMessage(Color.translate("&aTeleported back!"));
return true;
}
}```
getMetaData only returns a list, you have to extract teh values
you are doing nothing different
look at teh javadoc. See what the method returns
List<MetadataValue>
player.teleport(Location.valueOf(player.getMetadata("backLocation")));?
yes
what shoudl you do with a List?
get the value of it
how would i prevent an arrow from slowing down and stopping in water?
Is metadata capable of storing complex objects
so check each item in the list, get the value from the MetadataValue
Yes
anything thats serializable
iterate the list
in your case (if you only add one) getMetaData("tag").get[0].getValue()
.get(0)*
getValue is in red
value()
then you typed something wrong
player.teleport((Location) player.getMetadata("backLocation").get(0).getValue());
.value() not getValue()
tyy
NMS or calculate the trajectory yourself
You could easily apply a fixed velocity ```java
/**
* Pass a Projectile and a destination
* to set its direction and new velocity.
*
* @param projectile
* @param targetLoc
* @return
*/
public void setTarget(final Projectile projectile, final Location targetLoc) {
final Vector velocityVector = targetLoc.toVector().subtract(projectile.getLocation().toVector());
velocityVector.normalize().multiply(projectile.getVelocity().length());
projectile.setVelocity(velocityVector);
}```
yeah but a fixed velocity is different to "not slowing down in water"
which is over come by applying a fixed velocity repeatedly
You'd have to apply that method every tick for the arrow
more like gravity instead of drag?
How would you predict where the arrow is going to land if it wasn't in water?
both
idk what you're talking about anyway right now, so don't mind me lol
Would comparing the power and angle to how far that would make it go and then checking below that block?
That would make a weird flat trajectory
Hey anyone willing to help me set up Residence I am new to this stuff.
Oops
is it possible to add a value above 64 of stone to a player's inventory
With some hacky stuff you can
Ah
whatever args[0] is
when i type 65 it defaults to 1
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class PearlCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = (Player) sender;
if (args.length == 0) {
sender.sendMessage("");
sender.sendMessage(ChatColor.GOLD + "/givepearl <player>");
sender.sendMessage("");
} else if (args[0].equalsIgnoreCase()) {
} return true;
}
}```
how would i set arg 1 as a players name?
i dont specifically mean like "Notch"
Bukkit.getExactPlayer
oh
String playerName = args[0];
Player player = Bukkit.getPlayer(playerName);
ty
does anyone know how i can create a folder directory "playerdata" in my plugins folder on startup
File folder = new File(dataFolder + File.separator + "playerdata");
folder.mkdir();
it's that easy
damn
thankss
how can i check if the directory doesn't exist first
what's "dataFolder"
your plugin's data folder .....
Plugin#getDataFolder
if it's in your main class, just use getDataFolder()
Does your plugin have a config?
yes
btw instead of
new File(somePath + File.separator + "playerdata")
I'd rather use
new File(somePath, "playerData")
then saveDefaultConfig()
it actually doesn't matter but it's shorter and more intuitive imho
it will auto create yoru folder, you then only need create the playerdata one
I generally use the first method for folders and the second for files
what does File.separator do then
it returns \ on Windows and / on other OS
so if it does the same thing, why use it
well I could say the same
why use the longer version when you can use the shorter form
just use what you like what more, it doesn't matter
new File(dataFolder + File.separator + "some_generic_folder", "myfile.someextension");
I just wanted to mention that File(path,fileName) exists too
public File(File parent, String child) {
if (child == null) {
throw new NullPointerException();
}
if (parent != null) {
if (parent.path.isEmpty()) {
this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
this.path = fs.resolve(parent.path,
fs.normalize(child));
}
} else {
this.path = fs.normalize(child);
}
this.prefixLength = fs.prefixLength(this.path);
}
so yeah it's basically not exactly the same
it first checks whether the parent folder exists
and it might behave a bit different with symlinks depending on OS and/or filesystem
which is why I think that File(File,String) MIGHT be safer but tbh it just doesn't matter
bro
I told you five times
that IMHO it doesn't matter what you use in 99.9% of cases
here
here
You don’t even really need to use File.separator in the file constructor
here
yeah itnernally it works different but for the end user it's 99.9% the same
I don’t know if other places handle it, but the file constructor does
actually even using / on windows works as file separator IIRC
Not quite
so for the last time: no i didn't. I just wanted to show there's also the other way. I literally said at least 3 times that both ways are correct, so chill pls 😄
I've had exceptions on windows hosted machines due to hardcoding a "/"
oh okay I might be wrong on that one then
how do i create a file called "playername.yml" on join in the playerdata folder
might also depend on the windows or java version and/or filesystem, no idea^^ safest way is to use File(parent,child) or concating strings with the separator
It might work on windows explorer but that's about it
alisa have you ever worked with files smh
new File(new File(getDataFolder(),"playerdata"),"playername.yml").createNewFile()
or new File(getDataFolder() + File.separator() + "playerdata" + File.separator() + "playername.yml").createNewFile()
Should skip half the figuring out
how do i use it
?learnjava when
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.
tbh that's not even a java question but more like "how to google"
which class? I lost track of the conversation lol
YMLBase base = new YMLBase(plugin, new File(plugin.getDataFolder() + File.separator + "playerdata", player.getName()), false);
FileConfiguration config = base.getConfiguration();
ah your YML class, I missed that link
Or what I usually do for simple config files
@Getter
public class SettingsFile extends YMLBase {
private final String someValue;
public SettingsFile(JavaPlugin main) {
super(main, "settings.yml");
FileConfiguration config = getConfiguration();
someValue = config.getString("some-value");
}
}
Lombok features are probably not useful for someone who doesn't know how to create a file, otherwise the next question is "what's @Getter" ^^
let them figure it out
half their code disappears with lombok so less wasting time spamming unecessary code
you really have to bash on everything I do huh
No, cause what he is saying is right lmfao
i would highly advise against using lombok for someone who is new
Also you don't actually need File.separator() here. If you use /, java will automatically convert it to System dependent signs
when was it added?
Very long ago
I also thought that but @echo basalt said otherwise
Yeah idk what hes talking about...
I've had exceptions regarding that literally this year
im on java 16 hope it there
It's clearly written, and many other developers say its true too
how do i specify the file is a YML
welp test it out if you dont believe lol
because it created a folder
actually java.io.FileSystem should handle converting between file separators
if extension == yaml
at least that's what I thought
or something i forgot
Literally look at https://stackoverflow.com/a/2417546
comparing strings with == is a bad idea in 99% of cases
"With the Java libraries for dealing with files, you can safely use / (slash, not backslash) on all platforms. The library code handles translating things into platform-specific paths internally."
yeah because you did mkdir
I gave you two examples above that both show how to use createNewFile()
^
fast type, but just wanna ask why?
yeah how I had it in mind too
cause its ref comparison
just try this:
String a = "a";
String b = "ab".substr(0,1);
if(a==b) System.out.println("equals");
it probably won't print anything
although both a and b are "a"
well actually, also not 100% correct because the JVM caches strings
but you shouldnt rely on string caching in the JVM
.equals checks whether two objects have the same "content"
== checks whether they are actually the exact same object
since strings are created everytime you type "something", it's everytime actually a new, not exactly the same object
For example
String a = "hi";
String b = "hi";
System.out.println(a.equals(b)): // this prints true
System.out.println(a == b); // this prints false
b = a; // now we are assigning the reference of a to b
System.out.println(a == b); // this prints true now
no
while we need to compare what inside the string
== to compare IDENTITY
.equals to compare CONTENT
e.g. I'd equals() to my twin brother but I woudln't == to my twin brother
bad example but I don't have a better idea
👌 typoooooooooooooooooooooooooooooooooo
lol
ok
best example in this year
as long as equals is overwritten
That's one hell of an example
I don't even have any siblings
yeah sure but we're not talking about self written classes here I assume as it was about strings^^
so == would save you from the NPE
yeah but I invoked equals on me, not on my brother 🙂
and I'm quite sure I exist
not 100% sure, but quite
proof it
don't make me send stupid videos of me again, not today
yeah my bf has to get up in 3 hours
hm good point
also they didn't specify when to get up again
i was in bed on 10pm and then stood up at midnight again
so basically I already was asleep
oh anyway, I have a question
imagine a cuboid like in worldguard, or like a BoundingBox
of course the BoundingBox has a contains(Vector) method that simply checks whether the vector is inside minX, minZ, maxX, maxZ etc
buuut
worldedit also has polygon regions
and I'm not sure on how to calculate whether something is inside of that
I basically have a class that has a list of vectors (we can ignore the height, so just X/Z) and now I need to know whether a given point is inside this polygon
does anyone have any idea?
ugh, maths
I checked WorldEdit's source but I don't really get it and I don't wanna just copy it
and how can i add a value to the yml file?
do you even have any FileConfiguration object?
or a YamlConfiguration?
I’m sorry what is this about incest and .equals
someone wanted to compare strings with ==
File file = new File(Core.instance.getDataFolder() + File.separator + "playerdata" + File.separator + "playername.yml");
if(!file.exists()) {
try {
new File(new File(Core.instance.getDataFolder(),"playerdata"),"playername.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}```
then we had a NPE because I don't have a twin brother
and now incest is starting
You will need to get a YamlConfiguration
YamlConfiguration.loadConfiguration(File) will return a YamlConfiguration object
you can use it just like the config you get from JavaPlugin#getConfig
yeah indeed lol
what do i do after
learn java
you know, there's a rule of thumbs
when you have a new question after EVERY new line of code you've been spoonfed
you should enter ?learnjava and click on one of those links
no offense, but tbh you should know what you want to do
also
?javadocs
oh
?javadoc
go to the ConfigurationSection class/interface there
maybe this'll help for the beginning if configs are your only questions: https://www.spigotmc.org/wiki/config-files/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
@peak granite
i would like to do the collision physics
how could i do that
i wonder what is his ide?
context: im making a ball
that screams like quake's fast inverse square root
?
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.
?
what exactly do you want to do? calculate the vector? actually make the entity move?
let it do t pose
basically, if i hit an entity, it will move in the direction im looking with x force
then if the entity collides with a block, i would like to make it more realistic
basically this
is your entity a projectile? if not I believe that will be very hard to achieve
i suppose detect a collision with the bounding box of the entity and a block face and invert the velocity of the entity with the direction of the block face
yeah but it would probably require some scheduled tasks etc when not using projectiles right?
after all there's no "EntityHitSomethingEvent"
i would imagine so
however for projectiles, there is
you will need to check each tick whether the bounding box intersects the block
im using the Entity.move from nms 😔
yeah that was my idea too
yeah so you don't have any events when not using projectiles and have to do the hit calculation yourself every tick
so basically
you apply the velocity to a certain vector
im not using projectiles
then keep your entity in a running task timer
then check every tick whether it still got velocity above 0.01 or something
if not, cancel the task
if it's not cancelled and now interferes with something, calculate the new vector and velocity and apply it
if you're just wondering about how to get the rebound angle, there's many many examples you can google
but of course you'll have to do all the scheduling and hit detection yourself using the entities bounding box etc
anyone here good with FileConfigurations?
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. Create a thread in case the help channel you are using is already in use!
?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. Create a thread in case the help channel you are using is already in use!
that isnt what i was asking
then ask it
i wasnt asking to ask, i was asking if anyone here is good with FileConfigurations
yes, I studied FileCOnfigurations for 8 years
💀
Don't look for staff or topic experts.
so basically, i store player info in FileConfigurations
ok rule quoter
just ask what you have problems with, it's easier
dont say that...
and so im adding some player info, manually
he will argue with you the whole day
and im reloading the configuration... in hopes it'll create?
it'll create?
okay first of all
you have different FileConfigurations per player, right?
ok
yeah okay, so flatfile playerdata with UUIDs as keys
not so good...
precisely
im not really asking for your input, which is shocking 😭
and what's exactly your question now? 😄
why isn't my manually-created player info sections being saved
aren't my*
english moment
I Think Saying That To Me Is Not So Good...
well, do you ever call save() on your FileConfiguration?
yup!
i save() and then load()
not really sure why it doesnt do anything though lol
can you show us some code pls?
ye
?paste
screenshots work better :^)
mind the jank-ness of this
its not permanent lmao
you probably reference UserInfo.fc somewhere else right?
well tbh from seing only such small snippets, I can't say anything
w
bruh
idk what else you want to see
like, the whole class
the entire UserInfo class?
that would be more helpful, yes
i think not, im sending you the things that do not function as intended
because when a new player joins, it does create the section and treats everything right
its only when i try to manually create & save sections
well there's one thing I don't get
you call it "reloading" playerdata
but all you do is save what's currently in memory
so are you actually helping people?
did you manually change the file, and want to load those changes?
yeah, pretty sure i explained that
multiple times
bruh I'm literally spending my time at 2.30am to try to help you
why are you so hostile?
okay so let me explain and stop being toxic
do you actually want help?
- You change your file using an editor
- You overwrite your changes with what you have in RAM
- You load that again so have in RAM what you already had there
cool
:thanks:
just don't save the file before loading it again
right now is 2am in ur time?
also everyone here's trying to help but of course we need some input. we can't magically know what you're trying to do and what you're actually doing when you only give us 4 lines of code and no context @quaint mantle but ok
2.41
it is 8:41 am
@quaint mantle
for me
1:41am here
How do I make it so when a user clicks a message in chat it copies a certain character/text (ik already how to use text components and setclickevent with it).
programmer dont sleep...
currently going through a lecture i should've gone through last week
you must be from russia or india then
or somewhere near
asia
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
at the very bottom you can see message.setClickEvent
that's what you're looking for
Southeast Asia
"i dont wanna share my code because people are going to steal it"
what are you studying again?
comp sci
yeah those are the best people lol. I don't know how to use basic stuff but I'm afraid someone will steal it
i need to go make another gru meme
ah yes makes sense
fun
how could i disable the natural movement from a mob but allow him to be hitted
only with NMS I think
ever used NMS?
succ
Who’s code are we stealing?
im using nms 😎
yours
IIRC correctly you're looking to overwrite their pathfindergoal
Ah man not my open source code
that guy above, you can see how he being hostile while we talking nicely
or he just want fast answer
and being little too agressive
I regularly paste whole classes of my paid plugins, I really don't get why beginners think their non-working code must be protected lol
yes of course. You should learn basic java first
because
YamlConfiguration.loadConfiguration returns a YamlConfiguration
you never store it inside any variable, but you should
then you could use that variable
tiny example:
YamlConfiguration myConfig = YamlConfiguration.loadConfiguration(someFile);
myConfig.set("player-name",player.getName());
I even told them what was wrong although I actually didn't understand their sentence lol
but yeah sometimes people get upset when you don't understand their cursed english within 2 seconds and have replied 1 second ago
maybe md_5 should charge new users 5$ before being allowed in this channel
hope he dont do that with me
YamlConfiguration myConfig = YamlConfiguration.loadConfiguration(file);
myConfig.set("player-name", player.getName());```
nothing was added in the config
save when?
oh
of course it was. it's inside your RAM.
the bukkit yaml system want you to save
to save it to disk, you also have to tell your plugin to save the file to disk
i dont know why dont they just set it directly into the file
and remove the save method
bruh don't mock beginners
no, im talking about bukkit config api, i dont mock anyone
file.save() or file.saveConfig doesn't work
no, of course not
you didn't understand basic java
let me explain
your "file" object simply represents a location/file on your hard disk
the actual CONTENT that you can manipulate is stored inside your YamlConfiguration object called "myConfig"
and that's the thing you want to save
sooo
Yeah, its not like all the data is stored in that single object 😂
imagine a 5 gigabyte file
that would be 5 gigs of memory
the save method is provided by YamlConfiguration (or, to be exact, by FileCOnfiguration, which YamlConfiguration extends
its not because i think people are going to steal it, calm the ego about your paid plugins - i'm only following the guidelines i've setup for my server and development, in regards that anything internal is staff information
so you'll have to call that one
myConfig.saveConfig(); ?
that's no problem at all, but why being so hostile?
I just asked for a bit of context
i'll share as much as i can without breaking the guidelines that i setup^
and you instantly went like "ugh do people even try to help here"
i thought i shared the context already clearly
just imagine this
i guess not though
PersistentDataContainer pdc = player.getPersistentDataContainer();
if (pdc.has(Main.HAS_SEEN_MESSAGE_TAG, PersistentDataType.BYTE)) {
pdc.remove(Main.HAS_SEEN_MESSAGE_TAG);
}
Yo why doesn't this work?
no idea, you'd have to see the rest of the class
the thing about that is, i should have shared enough to potentially get an answer -- i thought i shared enough context
yeah and I asked for more and you went like "do you even try to help" instantly
let's just start over again and be friendly to each other, alrighty?
both you and me
works for me
myConfig.save(file); doesn't work as well
partialrelate
so, did you get it fixed? because you said "nvm I think I found the problem"
wdym? any error msg?
i thought i did but i think Eclipse was being fucky :U
so what i think i might do is just make a reload() method in UserInfo
that just calls save() and load() tbh
let me explain again and try to understand
you have your config loaded, then you change it on your HARD DRIVE although it was already loaded to RAM
i fixed it
and now you want the changes from your hard drive to your RAM, right?
then, you MUST NOT save the file before loading it again
otherwise you overwrite the changes you made on the hard disk
i had to put it in a catch
not my harddrive specifically, i dont save my server's information on this pc
basically: do not SAVE anything when it's just a RELOAD command
just load() ?
or?
yep
it's like.... you open a file in some program (minecraft)
then you change that file meanwhile in another program (your editor)
now you want minecraft to load the changes you did in the other program. that of course only works if you don't overwrite the changes made in your editor with what you already loaded in the beginning in minecraft^^
I hope you get what I'm trying to say
I'm not very good at explaining at 3am
mfnalex every time i want to edit the file, i would have to get it, then edit it, like editing a player's balance removing 500 i would have to get the value subtract by 500 thne set it again, then save the file?
no. after you saved it, of course you still have the file in memory
you don't have to save and load it everytime
you just load it on startup once, then keep your YamlConfiguration and use that, and on shutdown, you save it
oh, thanks
imagine saving/loading like taking something out of your backpack in RL
when you go to a lecture, you get your notebook out (loading it) and write stuff on it. maybe you also read something from it again. you only put it back into your backpack (saving) when the lesson ends and you go home
^^
you don't take it out and put it back for every sentence^^
didnt work @tender shard, tried just load()
hm yeah then you'd have to do so debugging etc, but as said I can't help you without seeing more of the code
i'll try the new UserInfo#reload() tbh
im sure it has to do with the static File and FileConfiguration 😳
you were the one with the flatfile config that contains all user infos in one file, right?
ye
Big brain
are you sure you always only have one instance of your UserInfo class?