#help-development
1 messages · Page 1630 of 1
Yeah i added that before i put x>>4 in () lol thx
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
registerEvents(this, new JoinLeave(this));
event not regestering
Method invocation 'toUpperCase' may produce 'NullPointerException'
its in a Enum
how do i fix it
inside of an enum
check what you are trying to set to upper case
in your code
lmao
COW(new ItemStack(Material.COW_SPAWN_EGG),
plugin.getConfig().getString("Cow.matrix1").toUpperCase(), plugin.getConfig().getString("Cow.matrix2").toUpperCase(), plugin.getConfig().getString("Cow.matrix3").toUpperCase(),
plugin.getConfig().getString("Cow.order").toUpperCase(), new Material[]{Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(0)), Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(1)), Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(2))}),```
do i need to use
.toString()
@Nullable says the returned value can be null.
so you have to validate it. Make sure its not null before you attempt to use it
either use a utility method to check strings or set it to a variable so you can check it.
then a getter utility method
if(variable !=null) {
// do something normally
} else {
// handle it by possibly returning with an error
}
easiest way to grasp it
i know how to do that lol
o
private String getStringNonNull(String path) {
String value = getConfig().getString(path);
return (value != null)? value: "";
}```
o
Objects.requireNonNullElse(str, "") iirc but yeah
Yes, but you'd not understand what its doing if you were just given Objects.requireNonNullElse
ohhhh
It's a pretty common thing when working with configuration files. Especially in Bukkit
Every getter method in MemorySection has a companion with a default value
Yep. The whole point here is, that ANY time you can have null returned you must confirm its not null before you attempt to use it.

tbf I missed that part of the discussion but yeah, Bukkit's methods are all covered with nullability annotations
Makes it fairly easy if your IDE supports nullability analyzing
It expects you to know basic java to fix it
public void run() {
ItemStack item = new ItemStack(Material.IRON_INGOT);
for(Player p : getServer().getOnlinePlayers()) {
int count = 0;
for(Location l : activeLocations) {
if (distanceBetween(p.getLocation(), l) <= 2.2) {
++count;
}
}
item.setAmount(count);
p.getInventory().addItem(item);
}
}
}, 0, REWARD_TICK_DELAY);``` I need to give the player an item at each of the active locations but when I spawn more than one location, the player gets more than 1 iron a tick
How can I remove fake players only on the tablist? I want to achieve player name tab completer with the fake player.
what fuck?
that was spigot api
No, null checking is basic java
also, what Is wrong with my distanceBetween method as I get an item anywhere I go instead of a 2.2 block radius ```java
private static double distanceBetween(Location l1, Location l2) {
double x1 = l1.getX();
double x2 = l2.getX();
double y1 = l1.getY();
double y2 = l2.getY();
double z1 = l1.getZ();
double z2 = l2.getZ();
double xDist = Math.pow(x1-x2, 2);
double yDist = Math.pow(y1-y2, 2);
double zDist = Math.pow(z1-z2, 2);
return Math.sqrt(xDist + yDist + zDist);
}
Yes, but do you understand now why you were getting the warning?
yes lmao
declaration: package: org.bukkit, class: Location
why not just use a normal method
I can't get distance of an array of locations
how does this method solve it xD
public static List<Location> activeLocations = new ArrayList<>();```
I need to get each individual location of the blocks from the array, how do I do that?
You loop the array?
Yeah I know I need a loop
l1.distance(l2)
Would opt for distanceSquared if you're doing anything comparatively. Unless you're showing something to a user, use distanceSquared
which also doesn't use Math.pow
unless the JIT compiler is finally good enough to optimize Math.pow(x,2) calls to x*x
They want to compare distance between other locations. distanceSquared is the right method here lol
yeah this works
oh yea I know, just saying that Math.pow might not be the best call to actually square a number
What are your locations for and why do you need the distance between them?
now however, I get 1 item for every generator, i currently have 5 generator location and am getting 5 iron_ingots/t
5 every tick because I have 5 block locations
every tick is a heck of a lot of iron
Wouldn't that have something to do with how the iron is being spawned, not really related to the distance?
I question how accurate multiplication is over Math#pow(). At least when it comes to decimals
distance is fixed now, it looks like iron spawns for every location because of java for(Location l : activeLocations) { I don't want this, I need 1 iron/t at each location
Well, you know which spawner they're near. Spawn the iron there.
Then just drop one iron at each location
Or do that, depends on how you want the game to work ^
I only 1 piece of iron for every location and i have been working for hours trying to fix this
ok
here it is https://paste.md-5.net/ejalifisen.java
what limitation is there to spigot plugin development if it is only spigot api
delete that wait method in your Listener
never ever sleep the main thread
ok
Nothing, really. Just can't access NMS but that should only ever be a last resort anyways
General rule of thumb is to compile against API until you require something in the net.minecraft package
and at that point, make a PR so there is API for it
ok, so you are giving every player who is online 1 ingot in their inventory for each location in your list
Ayo I can't bother to make a suggestion / PR but can you make API to force a mob to walk somewhere?
LMAO
yeah that's what is going on, I need to give 1 iron ingot at each location not for each location
I keep seeing people use NMS for this
Just loop through each Location and spawn an Iron there
You don't need to check if the players are close really, they can just pick it up.
If you cant be bothered to contribute then why should you get to use it :>
API for that isn't actually that hard. implementation is likely along the lines of entity.getNavigation().a(BlockPosition). I haven't looked at mob navigation in a good few years but I remember it being extremely simple
Yeah
Just that nobody's done it
Go do it 🥳
I don't have the time to contribute much anymore because I'm either working or doing school
making a PR and importing the entirety of spigot in my IDE takes lots of time
If you are getting 5 ingots then you are within range of 5 generators
Tho tbh someone just get the chunk entity pr to merge
That'd be kinda nice
Since it has been an issue since 1.17 but it's just stale
I have a 2.2 block distance for each generator
how would I do that? Is there a resource I could read/use?
what information do the server receive from the client?
Oh, I see the problem
Put
item.setAmount(count);
p.getInventory().addItem(item);
Inside the distance if block
ok
Serverbound packets are what the client sends
Is it just me or is IntelliJ's autocomplete & decompiling far more useful than wiki.vg 🤔
thats going to exponentially increase the rewards
The wiki and what's decompiled in IntelliJ aren't necessarily the same thing
Yeah and what's decompiled seems to be more accurate
The fields in the packets are used by ProtocolLib whereas the wiki actually documents the protocol itself
There is a difference
Ah
If someone wanted to make their own server from scratch, reading through the protocol is how they'd be able to interpret what the client sends
They may then implement it however they'd like. So long as the server reads what the client sends properly, you have a server
still an issue
Could just remove count and just add 1 of the ItemStacks for each generator within the Player's distance I think?
It's like a manual on how they communicate ;p
yes, but his current code is only counting generators within 2.,2 range. so he must have 5 within 2.2 block radius
That makes sense, ty for explaining Choco
o/
yeah but they are way farther than 2.2 blocks from each other
you are adding 1 block per generator, 20 times a second
Oh wait yeah I read it wrong, formatting is really weird
Yeah, how can I fix this? This is my first real plugin project.
20 nearly 1 secound
Minecraft ticks != seconds. roughly 20 per second.
that won't stop the item drop for every location
I have it every 20 ticks
you are not giving a reward for every location
It is running every 20 ticks
your gif is too small. I can;t see how many its showing
I just see it giving a reward every second
Oh I see your issue
did you run the command each time you placed a generator?
yes
then you have 5 tasks running
ohhhh lmao
?paste
Nice catch Elgar
how do I run 1 task per block?
You should only run the task once
you don't run per block, you run per player
ohhh
Why per player
fefiweifbawefuabwefuhagbwefyagwefabwefawefuhwagfeuagbewfbwaiyfgaywefbwaeifywa
It loops all the players
yes, one task. will cover all.
or one per player dedicated to that player.
one for all players is better. but ONLY one task
Yeah, I was just confused when you said per-player lol
So your fix, is don;t start your task in your command
run ONE task for the whole server, outside the command
It's a YAML error, something is wrong with your config.yml
bad yaml formatting
how
Cow:
matrix1: " D "
matrix2: " D "
matrix3: " S "
order: "DS"
items: [DIAMOND_SWORD, STICK]```
no clue, show us your yaml
thats my config.yml
show with formatting
Probably using tabs instead of spaces
I remove my for each location loop and now I need to get the distance of each active location
No, you just need to move the whole runnable out of yoru command
start it when you load the class
try this @grim ice
Cow:
matrix1: " D "
matrix2: " D "
matrix3: " S "
order: "DS"
items: [DIAMOND_SWORD, STICK]
alright so like this? ```java
public final class Generators extends JavaPlugin {
protected static Generators instance;
//public List<Location> locations;
@Override
public void onEnable() {
this.getCommand("Gens").setExecutor(new Commands());
this.getCommand("gm").setExecutor(new Commands());
this.getServer().getPluginManager().registerEvents(new Events(), this);
instance = this;
//locations = (List<Location>) getConfig().get("locations");
saveDefaultConfig();
getConfig().getLocation("locations");
BukkitScheduler scheduler = getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(Generators.getInstance(), new Runnable() {
@Override
public void run() {
}
}, 0, 20);
}``` just don't know what to put in my run() method
What is RecipesManager line 143
1s
plugin.getConfig().getString("Cow.order", "").toUpperCase(), new Material[]{Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(0)), Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(1)), Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(2))}),```
the code you had was fine.you just don;t run it every time you run the command
you need one runnable that runs all the time.
same code in the run method you already had
There isn't a 2nd index
ok
get(2) throws an error
its inside an enum
wdym
public enum Things {
plugin.getConfig().getString("Cow.order", "").toUpperCase(), new Material[]{Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(0)), Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(1)), Material.getMaterial(plugin.getConfig().getStringList("Cow.items").get(2))}),
}```
there are other stuff
but thats the main idea
so
u there
Yeah hang on
Ok and how would I run the task timer all of the time? put it in my onEnable() method?
yes, or the constructor of your command class
ok
You should be able to set the Material[] inside the constructor of the Enum I think?
It would probably be best if you just... didn't use an enum
wat
Use a class, that way they can add/remove recipes as they please
that'll break my whole code tho
its not a difficult change
^
You currently have an enum as you were using fixed recipes created in code
You're not really going to be able to have customization with enums.
you can still use teh rest of your code
but instead of an enum you will create a Map of recipes
How do I, in IntelliJ IDEA change the version of an mc plugin? I tried importing the librabry of 1.17.1-R01-Snapshot but it didnt find it
yes i know, i copied it from spigot, it still doesnt find it
And you have the respective repository added too?
this is Maven
that's maven lmfao
You add dependencies theough a GUI now ?
it will only find the spigot artifact if you ran buildtools first (and have it install the artifact in your local repository)
oh lol
uhuhuhuh
I'm pretty new to this, what do I do exactly?
use spigot-api if you just want to use the API
Concerning you are new to this, API might be all you need
Sorry, but I have literally no clue what i need to do
Yeah I think API will be fine for you then XD
like this?
Yea I guess
Tho It still looks to me like you are downloadinf this to a lib folder and are working off of that
Map<NamespacedKey, ShapedRecipe> Recipes = new HashMap<>();
Instead of a pom.xnl
I made the runnable now I need to get the distance of every active location, how do I do that? ```java
(p.getLocation().distance(activeLocations) //???
quietly dies
I just want to change the plugin version from 1.16.5 to be compatible with 1.9 to 1.17.1
if you did it in your command class you for loop the locations, as you did before
ok
seems to be doing the same thing?
BukkitScheduler scheduler = getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(Generators.getInstance(), new Runnable() {
@Override
public void run() {
ItemStack item = new ItemStack(Material.IRON_INGOT);
for(Player p : getServer().getOnlinePlayers()) {
for(Location l : activeLocations) {
if (p.getLocation().distance(l) <= 2.2) {
switch (l.getBlock().getType()) {
case IRON_ORE:
item.setAmount(1);
p.getInventory().addItem(item);
}
}
}
}
}
}, 0, 20);```
thats it?
do you only create/start that runnable once?
well it's right under java public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { so that might be the issue
it can NOT be IN your command
Dumb question, but api versions are forward compatible, right?
Like if I make a 1.8 plugin using pure API, I can use anywhere 1.8+
thats your store. You then load/add all your recipes in your RecipeManager constructor
Any help to that please?
tbh idk exactly how to do that and it seems complicated so i might not do it
I put it in my onEnable() method and it works! Just had to import my active locations array
Then you will have to compile against 1.9
Use 1.9 as spigot dependency and Java 8
Okay and how do I make the plugin compatible with 1.17.1 if it was for 1.16.5 previously?
(Using IntelliJ IDEA here)
Since you seem to be new with Spigot I doubt you're using NMS which means the plugin already is compatible
it wont load with it
What does it say?
I did get it, now I need to save those locations to the config, I have this java Generators.getInstance().getConfig().set("locations", activeLocations); Generators.getInstance().saveConfig(); but on reload, the locations are deleted
I tested with another plugin previously, but the one I need works weirdly, thank you tho Olivo
config is saved on every command
You need to load them back into the activeLocations when the plugin enables.
ok
something like this? getConfig().get("locations", activeLocations);
How do I read a value from a config file form the main class file? I know how to do it form any other class file
(messages_prefix = myplugin.getConfig().getString("prefix");)
But if I try that in the main class it doesnt work. I need it as a global static
Or like how do I make a public static inside the onEnable Event, for example
You create the variable outside it and set it in the onEnable
having the same issue
This should have been convered in Java basics (Which I hope you know)
I just need to look up config manipulation
This is for the variable creating thingy if you're wondering
So how do I do it?
You put the variable outside of onEnable and then set it's value inside of the onEnable
public void loadConfig() {
getConfig().options().copyDefaults();
saveConfig();
}```
@eternal oxide
is there another way
i can like
get all the existing indexes of a list
so i dont mess up if its more or less
do you know a way of doing that? if you understood my question
Does anyone know how to go about creating a redstone pulse on a redstone wire?
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/AnaloguePowerable.html#setPower(int)
I assume this is what you're looking for?
How would I spawn a entity on a player?
declaration: package: org.bukkit, interface: World
then you can use playerReference.getLocation()
Ok
i've updated to 1.17.1 and for some reason, the isSilent parameter of the World.Spigot#strikeLightningEffect(Location loc, boolean isSilent) method being set to true doesn't seem to make the lightning bolt silent anymore. does anyone know why this might be the case?
How do I, if I have stored an ItemStack in a MySQL, read it from there (as string) and convert it into an ItemStack?
Maybe its a bug ? If you can replicate it on the latest spigot release with just your test plugin, open a bug report
There are a few ways
simplest preffered
The first is with BukkitObjectOutputStream
Which is annoying
You want my alternative?
sure
My library has a method to convert items to and from JSON strings
Might be that
oaky but whats so annoying with using BukkitObjectOutputStream?
The setup is annoying and it takes up way more space
It's something like this if I recall though
Why not just use separate columns if you dont mind me asking?
can you store items in a mysql as ItemStack?
No
Don't think so
I mean it is in there in the exact format like the itemStack
ah interesting, that would make sense
No
No, you can't
To my knowledge there is no method to convert back from that format
ByteArrayOutputStream bao = new ByteArrayOutputStream();
BukkitObjectOutputStream boo = new BukkitObjectOutputStream();
boo.writeObject(item);
boo.flush();
byte[] arr = bao.toByteArray();
String out = Base64Coder.encode(arr);```
It's something like this to convert an item to a string using BukkitObjectOutputStream
But it's not human-readable and it's not space efficient
My library has ItemUtils.toString and ItemUtils.fromString which convert to and from JSON strings
That's convenient. I'd use his library unless you want more control over your database structure
ok now I need to show how dumb I am again: How do you add libraries
Maven dependencies
Well for RedLib
You can't shade it
You have to have the jar on your server
I imagine you don't really want that
So honestly the easiest way is to just copy the code from the ItemUtils class and the JSON parser package
public static ItemStack fromString(String json) {
JSONMap map = JSONParser.parseMap(json);
ItemStack item = (ItemStack) deserialize(map);
ItemMeta meta = item.getItemMeta();
// Everything except enchantments works. Not sure why, but it has to be done manually.
if (map.containsKey("meta")) {
JSONMap jsonMeta = map.getMap("meta");
JSONMap enchants = jsonMeta.getMap("enchants");
if (enchants != null) {
enchants.forEach((k, v) -> {
meta.addEnchant(Enchantment.getByName(k), (int) v, true);
});
}
}
item.setItemMeta(meta);
return item;
}
So this section?
It's not shaded because it does a hell of a lot more than just those 2 utility methods but for just those 2 it's not worth the plugin dependency
Yes, and toString and all the helper methods they use
I rarely make anything configurable. Is it worth it to make a class that collects and caches all the configurable values or should I just grab them from the config object?
why tf is there no method to just convert stuff -.-
But you should avoid storing very large amounts of data in config
sexy
Because all of it is loaded into memory when you load it
Yeah I don't plan on it for this little project
Databases are better for large scale
Well aware
Ok
Challenger, technically there i
is
how
no I mena
just be a sigma and convert it yourself
I have a string and I want that string to become an itemstack
Yes, it can be stored directly in config
My utility methods take advantage of that, the serializable aspects
the string literally was an itemstack before it was put into the mysql
Uses it to convert to json instead of yaml
json is technically yaml iirc
sorry but I really dont know how to implement it, how do I do it
I am a total newbie
Yes, it will convert objects to strings automatically
Just using toString()
You'll need to store it by calling ItemUtils.toString first instead
Copy the toString and fromString methods from the ItemUtils class
And all the helper methods they rely on
Then copy everything in this package
And I just put them into a class file somewhere in my plugin?
Sure
RedLib 😌
You'll need yo copy the json package and make sure the imports for those methods are correct
Since when did you like it? 🤔
Oh and Challenger, if you're using my code I would appreciate it if you give me credit 🙂
Just a small disclaimer is plenty
sure will
Nice
That's the whole idea so I'm glad it helps you
But also crunch is my favorite
❤️

hello mr redempt can u halp me again
What
Ok so you have lerp
Lerp takes 3 values
yes
The value to interpolate from
The value to interpolate to
And the ratio
The ratio is a value between 0 and 1
yeah
Currently you plug in values corresponding to the distance along the line for the ratio, right?
yes
What would happen if you plugged in 1 - Math.sqrt(ratio) instead
Actually I might have that backwards
One sec lol
guys is there a way i can get all the existing Indexes of a list
Stop
SPECIFY
like instead of plugin.getConfig().getStringList("Cow.items").get(0)
You can get the size of the list
.-.
instead of:
The max valid index is size - 1
plugin.getConfig().getStringList("Cow.items").get(1)
plugin.getConfig().getStringList("Cow.items").get(2)
plugin.getConfig().getStringList("Cow.items").get(3
)
The min valid index is 0 if an element is present
u do
You want a loop..?
plugin.getConfig().getStringList("Cow.items").getAll()
yes but loops dont work inside of an enum so
im looking for a different way
for (String entry : plugin.getConfig().getStringList("Cow.Items")) {
//Do stuff
}```
What do you mean "inside an enum"
You're trying to pass it as a parameter to an enum constructor?
No
Then what
breh.
Alternatively you could do 1 - (1 - r)^2
for(i in 1..10){
armorStands.add(SkyblockHolograms.createFloatingBlock(armorStand.location.lerp(armorStand3.location,i.toDouble()/10), ItemStack(Material.STONE)))
}
so instead of that do this
for(i in 1..10){
armorStands.add(SkyblockHolograms.createFloatingBlock(armorStand.location.lerp(armorStand3.location,Math.sqrt(i.toDouble()/10)), ItemStack(Material.STONE)))
}
Don't breh me
Give me more details
"my shit is inside an enum" still does not explain ANYTHING
WHERE are you trying to put it
i want to get all the indexes of a string list
from my config
and i cant use loops there
also i hear square roots are expensive for cpu should i just store the values in like an array?
Ok so it IS in an enum constructor
yeah ig
And good lord please don't do that to your code
Are you trying to make craftable spawn eggs or something?
I'm trying to save my locations array to the config so it can still spawn items at locations after reload/ restart, what am I doing wrong?
https://paste.md-5.net/ixamugeduk.java
yeah sort of but im letting the users
decide the recipe
Ah the classic "here is all of my code tell me what's wrong with it"
Yeah don't use an enum for that
There is already an enum for each mob in the game
is there no way of doing what i wanted
What's ur problem?
Sure there is
Use an EnumMap
Not an enum
You can map each EntityType enum to the data for that entity
how to do that?
And you can programmatically retrieve the spawn egg for each entity
I am saving the config every command but on reload, my locations are gone
Then you could make that configurable
You know that location is configserializable right?
HOW
By allowing them to do
oh ok
Does this seem right
for(i in 1..10){
var ratio = i.toDouble()/10
ratio = 1-(1-ratio).pow(2)
val location = armorStand.location.lerp(armorStand3.location, ratio)
armorStands.add(SkyblockHolograms.createFloatingBlock(location, ItemStack(Material.STONE)))
}
Oh it's in kotlin lol
wahat
How do I get my variables from the config after saving though?
Not sure why it took me so long to notice
Yeah try this out
Not you
Where do u save ur locations?
config stores things are key value pairs so assign a key to it when you store it then get it using that key
p.getTargetBlock((Set<Material>) null, 3).setType(Material.IRON_ORE);
blockLocation = (p.getTargetBlock((Set<Material>) null, 3).getLocation());
activeLocations.add(blockLocation);
if (activeLocations != null)
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("Generator Placed at " + blockLocation.getBlockX() + ", " + blockLocation.getBlockY() + ", " + blockLocation.getBlockZ()));
Generators.getInstance().getConfig().set("locations." + blockLocation.getBlockX() + ", " + blockLocation.getBlockY() + ", " + blockLocation.getBlockZ() + " " + blockLocation.getBlock().getType(), activeLocations);
Generators.getInstance().saveConfig();
}``` here
?conventions Also please ;/
Java Coding Conventions: https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
And also get a better name
ok
For that key
Anyone knows how can i get all indexes of a list without loops? like instead of
plugin.getConfig().getStringList("Cow.items").get(1)
plugin.getConfig().getStringList("Cow.items").get(2)
plugin.getConfig().getStringList("Cow.items").get(3
)
u do plugin.getConfig().getStringList("Cow.items").getAll() or something. any ideas?
did i do something wrong
getConfig().get("Cow.items").getKeys(false)
its not real hypixel skyblock
you sayd .get its .getConfigurationSection
yep, getConfigurationSection not get
Hey its from memory here. Do some of the work yourself 🙂
^
if config is like items: [DIAMOND_SWORD, STICK]
will it return DIAMOND_SWORD, STICK
or
what
Sure looks like it
that is not a section, thats an array
yes
Oh wait I know what's wrong
well if lerp only is across a line then me changing the ratio would only change the blocks position along the line
ah how do i do that .w.
You don't need to move them further along the lerp line
You need to move them up
Do you need the third point?
wdym
Well
If you had only 2 points
And it automatically just created a curve up
Would that be acceptable to you
so what then
Is to have it curve up
Yes, like a boost pad
yea
ok
But move the point up based on how far it is from the midpoint
Closer to the midpoint = higher up
Do you use these items anywhere else other than your recipes?
no
then stop using an enum
i dont know how to do anything else
use a straight map as I told you earlier
is there an equation i should use
can you give me a brief idea of how to put stuff in it
ik map.put
but like the parameters
Let's say l is the length of the line
And d is the distance to the midpoint
You could do something like this
height += sqrt(l/2 - d)
and i know i want the highest point to be half the distance
because thats how i was generating my third point
Yes, that would do it
val l = start.distance(end)
val mid = start.clone().add(end).multiply(0.5)
...
for (i in 0..10) {
...
d = point.distance(mid)
height += sqrt(l/2 - d)```
I have this now java else { switch (args[0].toLowerCase()) { case "iron": p.getTargetBlock((Set<Material>) null, 3).setType(Material.IRON_ORE); blockLocation = (p.getTargetBlock((Set<Material>) null, 3).getLocation()); activeLocations.add(blockLocation); if (activeLocations != null) p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("Generator Placed at " + blockLocation.getBlockX() + ", " + blockLocation.getBlockY() + ", " + blockLocation.getBlockZ())); Generators.getInstance().getConfig().set("generator locations." + blockLocation.getBlock().getType(), activeLocations); Generators.getInstance().saveConfig(); } }
eeee
Anyone knows how can i get all indexes of a list without loops? like instead of
plugin.getConfig().getStringList("Cow.items").get(1)
plugin.getConfig().getStringList("Cow.items").get(2)
plugin.getConfig().getStringList("Cow.items").get(3
)
u do plugin.getConfig().getStringList("Cow.items").getAll() or something. any ideas?
3rd repost :D
plugin.getConfig().getStringList("Cow.items").get(1)
plugin.getConfig().getStringList("Cow.items").get(2)
plugin.getConfig().getStringList("Cow.items").get(3)
the same as this
You keep asking an inane question, of course nobody's giving you an answer
Get them how
A list already contains them all
They're all in there
What are you doing with them
i want to get them all
recipes
Then getting the list already does that
They're all in the list
Your question makes no sense
No, no it doesn't
You want them as an array?
You want them joined together as a single string?
What?
example ```java
private Map<NamespacedKey, ShapedRecipe> recipes = new HashMap<>();
public RecipeManager(JavaPlugin plugin) {
RecipeManager.plugin = plugin;
ConfigurationSection section = plugin.getConfig().getConfigurationSection("recipes");
for (String entry: section.getKeys(false)) {
NamespacedKey key = new NamespacedKey(RecipeManager.plugin, entry.toLowerCase());
ShapedRecipe recipe = new ShapedRecipe(key, new ItemStack(Material.matchMaterial(section.getString(entry + ".itemStack"))));
//etc
recipes.put(key, recipe);
}
}```
I don't even think you understand what you're asking for
You want to get all the items in a list
A list already contains all of the items
What else is there to be done
What would getAll do?
You have elements in a list
You want to "get all of them"
You can put them into an array
So you want to get the first element..?
Just fill in the //etc section to create your recipe
getting the list does not give all the lements
but i have to add in a for loop
to do that
for
every recipe
there is already a for loop
oh wait fuck
so "recipe.cow" "recipe.zombie"
o
that for loop grabs everything under recipe
so you have recipe.cow.itemstack: COW_SPAWN_EGG
my config? no
Cow:
matrix1: " D "
matrix2: " D "
matrix3: " S "
order: "DS"
items: [DIAMOND_SWORD, STICK]
recipe:
cow:
itemstack: COW_SPAWN_EGG
//etc```
Ok so you have a list of items
What are you trying to do with the elements of that list
if you remember from teh enum you specify the ItemStack that is going to be the result
yes
so you need to include that along with all teh other things like matrix
i mean elgar is helping me with the same info im giving
o
ok i got it
where even is this enum
from example code I wrote for him a week back?!
you can get rid of matrix1 etc, as you are going to a config use matrix: ["AAA", "BBB", "CCC"]
no point in keeping them seperate when you will be putting them into an array
yes, but you will reuse some of its code
UHH
how do i get the matrix tho
you put it in the yml as I just showed you
recipe:
cow:
itemstack: COW_SPAWN_EGG
matrix1: [DDD, SSS, DDD]
order: "DS"
items: [DIAMOND_SWORD, STICK]
like that
but what i meant is how to get the matrix, when shaping the recipe
String[] matrix = (String[]) section.get("matrix");
oh right
should work fine
no
you just have one matrix
thinking about it that cast may not work. You'll have to test it
its an easy change if it errors
What do I do to save my activeLocations location array to the config so it saves after reload/restart, it's my first time working with configs
If anyone can help me with this problem:
If I have several numbers in an int variable, is there any way I can select only the largest number?
You mean int[]?
put them into an array and ```java
static int largest()
{
int i;
int max = arr[0];
for (i = 1; i < arr.length; i++)
if (arr[i] > max)
max = arr[i];
return max;
}``` this sorts the array and finds the largest number
Or do you have multiple bytes packed into an int or something
Cause if you have an int array
Arrays.stream(arr).max().getAsInt() will do the trick
so uh i wanna check if order: "DS" equals items: [DIAMOND_SWORD, STICK] (like in amount)
If it's a list
but
list.stream().max(Comparator.comparingInt()).get()
is there a method for string lengths
The fix for your cast is java String[] matrix = section.getObject("matrix", String[].class);
Do the same to get your items
Thank you
Thank you
yes string has a length
.length()
o
OH I WAS USING get
not getString
my bad
@eternal oxide
but
i dont find it making sense
like
what bit?
here
ConfigurationSection section = plugin.getConfig().getConfigurationSection("recipes");
String[] matrix = section.getObject("matrix", String[].class);
like
there isnt only 1 matrix
there are multiple
like
yes there is, in each recipe
cow:
rabbit:
but u didnt specify the path
like it should be recipe.cow.matrix
not recipe.matrix
You don;t need to. section is only whats under recipes
thats why you get a section so you can loop and not need to know any paths
its literally like cutting out that section of the file
Umm for some reason I can not import gson
o
Like I have the library, added it to maven but IntelliJ doesnt let me use it in code
Auto import doesnt work aswell
oh you do have a point though, you do need to include the entry
so java String[] matrix = section.getObject(entry + ".matrix", String[].class);
o
teh entry is like cow, zombie
btw
from the for loop
yes
o
how many chars in your order must match the number of elements in yoru items array
so getString("entry + ".order")
uh
What am I looking at
If you're trying to get the max digit in a string
You don't need to do all that
You can just do string.chars().map(i -> i - '0').max().getAsInt()
Ok
aaa
how do i fix Array access 'section.getObject(entry + ".order".charAt(i), items.[i]' may produce 'NullPointerException'
i tried many stuff they dont seem to work
aefjoawhefuahwfeoauwefoawef
for (int i = 0; i < section.getString("items", "").length(); i++) {
recipe.setIngredient(section.getObject(entry + ".order".charAt(i), items[i]);
}
that sounds like bad code. Paste
?paste
asserts are a waste of time, they are not used at run time
you could add a check for data and section to see if they are null
o
if section is null return, if data is null continue
im commiting ....
Argument 'data.getString("itemStack")' might be null
if(data.getString("itemStack") != null)
continue;
if(Material.matchMaterial(data.getString("itemStack")) == null)
continue;
i legit fucking checked if its null 1 line before ??
you have to use a variable, else your IDE does not know its teh same thing
so String item = data.getString("itemstack)
then null check item
ok
String item = data.getString("itemStack");
if(item != null)
continue;
if(Material.matchMaterial(data.getString("itemStack")) == null)
continue;
still
same thing
Argument 'matrix' might be null
Method invocation 'length' may produce 'NullPointerException'
Argument 'Material.matchMaterial(data.getString("itemStack"))' might be null
throw your ide in the bin
this is annoying, isnt there a plugin or something for intellij idea that checks for declared commands on plugin.yml?
yeah, and they are in a try/catch. Your ide shoudl not care at that point
yeah ok but now uh
change the NPE to Exception
o
a catch all shoudl shut it up
Yeah, eff InteliJ.
Stupid IDE is intelligent enough to warn but not cleaver enough to see that it doesn;t matter
how to make a countdown when logging on to the server, with lvl replenishment every second?
how to make a countdown when logging on to the server, with lvl replenishment every second?
dont spam
yes, however I'd put them in their own file if I were you
ok
for now config is fine
o
ok
oh god
i have to write 50 recipes again
AAAA
i mean if it works, its worth it
че
да так
can we English please
как сделать обратный отсчет при входе на сервер, с пополнением lvl каждую секунду?
the Player join event
yes
dm
Can this code work?
instead of Recipes.values() you now use recipes.keys() and discover(recipe)
int[] tab = {account.getID()};
IntSummaryStatistics stat = Arrays.stream(tab).summaryStatistics();
int max = stat.getMax();
System.out.println("Max = " + max);```
o
Unknown class: 'recipes'
what the fuck
Sure but why would you do that with just one element
And if you only use max why get the whole summary statistics
show your code
for (recipes recipe : recipes.getKeys(false)) {
I just want the largest number of this object
or do i send everything
NamespacedKey recipe
But how can I get only the highest number?
o
What
You make an array
Put only one element in
And then try to get the max
What are you expecting to happen
It will always just return whatever that one value you put in is
uhhh
thing is
- how do i add enchants
- how do i check the recipe name
Itemmeta.addEnchant
- how am i supposed to disable certain recipes with their name
thats the problem with not using enums :<
exactly as you have already done for disabling.
what I was doing was getting the enum name
o
Hello, my vault isn't hooking for some reason:
[23:04:47 INFO]: [Vault] Economy: null [null]
[23:04:47 INFO]: [Vault] Permission: SuperPerms [SuperPerms]
[23:04:47 INFO]: [Vault] Chat: None [null]```
ill show the code in sec
economyImplementer = new EconomyImplementer();
vaultHook = new VaultHook();
vaultHook.hook();
}```
this is on my main
private Main plugin = (Main) Main.getPlugin();
private Economy provider;
public void hook() {
provider = plugin.economyImplementer;
Bukkit.getServicesManager().register(Economy.class, this.provider, Main.getPlugin(), ServicePriority.Normal);
Bukkit.getConsoleSender().sendMessage(Main.f("&b[&3!&b] &aVaultAPI hooked!"));
}
public void unhook() {
Bukkit.getServicesManager().unregister(Economy.class, this.provider);
Bukkit.getConsoleSender().sendMessage(Main.f("&b[&3!&b] &aVaultAPI unhooked!"));
}```
this is my VaultHook class
it sends VaultAPI hooked
ok I'm back
Unhook anything before hooking
how?
Like iirc some impls register a higher priority
how do i make my plugin hook first
Try with ServicePriority.Highest
i mean highest
First
i am committing suicide right now
it still says to my console [!] Hooked
Hmm okay and your plugin depends on vault?
i hate intelliJ
Use notepad++ then
LOOK AT HOW MANY NULLS R THERE WTF
fuck?
Won’t yield any warnings
lol
well thats my opinion
It’s actually good
i mean yeha
Just ridiculous UI arguably 🤒
K as conclure said Notepad++ won't give u any errors/stuff
I use Eclipse, because I don;t need an IDE nagging me.
Its really more for corporate
bump
intelliJ way easier to use
yep
IntelliJ is hard for me eclipse is super ez for me
How would I get if onDisabled has been called in a separate file? I have a system for functions setup, but don't get how I would add it to a Boolean