#help-development
1 messages · Page 1488 of 1
Umm
I just tried to call
if (p.hasPermission(perm)) {
System.out.println("Has permission");
}
But it somehow acts as a return ?
"acts"?
also please share all the relevant code
you can't expect me to figure out what's on your screen just by reading world.spawnEntity(loc, EntityType.CREEPER) lmao
public void syncRoles() {
Config conf = Main.getInstance().config;
conf.reload();
String[] ranks = objectToStringArray(conf.getRanks());
ResultSet rs = sendStatement("SELECT * FROM DiscordTable");
int length = ranks.length;
System.out.println(ranks.length);
for (int i = 0; i < length; i++) {
System.out.println(i);
JSONObject ob = conf.getObject(ranks[i]);
System.out.println(ranks[i]);
String perm = ob.get("Permission").toString();
try {
System.out.println(perm + "\n" + rs.getString(1));
Player p = Bukkit.getServer().getPlayer(rs.getString(1));
System.out.println("rip");
if (p.hasPermission(perm)) {
System.out.println("Has permission");
}
} catch (SQLException throwables) {
System.out.println("Thrown");
throwables.printStackTrace();
}
}
}```
Full code
When I run it without the if statement it runs through 5 times like it should (ranks.length is 5) but when I add it again it would magically return. Everything I write after the for loop also doesnt execute
ah better
don't add the colons (:)
Also, this, seriously lol
you don't need to do any "manual reading", Bukkit will handle reading the yaml into a Location object
Does anyone know the reason for that?
as if it threw an exception/error?
No it didnt throw any error into the console at least...
But what could the error be then in line 17?
TabCompleteEvent did not exist in 1.8
Suit yourself https://helpch.at/docs/1.8.8/org/bukkit/event/server/package-summary.html
gradle stuck at analyzing
so are you saying if i will remove the : the code will work?
pretty sure thats not gradle stuck but your IDE
Okay found the problem
does anyone know if you press space does not turn on like in the old tuffer in sensecraft https://www.youtube.com/watch?v=Dk6qqSE8lbQ&t=138s
The player is null because I didnt get offlineplayers but onlineplayers. But it is weird that it didnt print any error message.
Primarily yes, but I'm also saying there is no point in a "location manager", you can simply do
Location someLocation = ...;
config.set("my-location", someLocation);
and
Location someLocation = config.getLocation("my-location");
Is there no spigot/bukkit native way to quickly check if a player has build perms at a location?
I've only been able to find ways that use WorldGuard or try to place a block
"build perms" isn't really a thing in bukkit
spawn protection yeah, and it's ass tbh lmao
What is the correct way to get a offline player? getOfflinePlayer is deprecated
Firing a BlockPlaceEvent won't work though since spawn protection is part of the game's code, not a plugin processed thing
So I guess you can check if the player is op and if spawn protection is enabled? ¯_(ツ)_/¯
By UUID if you have it
How do I create an uuid from a string again?
Doesn't quite work like that
Okay
If you don't have it, just use the username
Umm okay
if you have the UUID as a string you can UUID.fromString(string)
ty
-ban inappropriate
that was like days ago
Okay, how do I get permissions from offline players?
getOfflinePlayer().getPlayer().hasPermission doesnt work of course
what does return true; does in the onCommand method?

just escaping without the usage message?
You need to return true to tell the server that the command was executed successfully and return false if it wasnt
ki
i ma still geting null error
you don't, offline players are not permissible objects
some one?
Yeah I read that I would need Vault for that
show your current code
Not big of a problem
.
why don't you just use set(path, location) and getLocation(path)?
cfg.set(name+"world", loc.getWorld().getName());
that should probably bename + ".world", you're missing a period there
and you're setting the name somewhere but getting it from a totally different place
you're making this hard for yourself for no reason
is that toString() unneccesary?
target.sendMessage(ChatColor.DARK_GREEN + "Healed by " + sender.toString());
yes, and that is not the name
if you want to get the name, get the name
Does any1 know how to use custom texture heads from https://minecraft-heads.com/custom-heads/
Can you as the Client somehow detect If the Server send you Ghost Blocks/ Fake Blocks?
no
;7
well, if you damage the block it will revert
what is the path?
Would be too god to be true
where in the config you want to store the location
The server is constantly resending packets
then no
Location event = config.getLocation("event");
did you ever set it there in the first place?
what is "config" exactly?
?paste
Because getLocation is a thing https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/MemorySection.html#getLocation(java.lang.String)
uh...
that's.. not
not what?
config shouldn't be the name of a class, it was implied that config was a ConfigurationSection (YamlConfiguration, FileConfiguration, etc)
why is everything in that class static oml
yeah i can't
with "config" I was implying this
YamlConfiguration config = ...;
Location location = ...;
config.set("some.path", location);
and
YamlConfiguration config = ...;
Location location = config.getLocation("some.path");
public class seteventloc implements CommandExecutor {
Main plugin;
public seteventloc(Main plugin) { this.plugin = plugin; }
private File file = File("plugins/inbar_server/data/Location.yml");
private FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use that command!");
return true;
}
Player player = (Player) sender;
if(cmd.getName().equalsIgnoreCase("set-event")) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
Location location = player.getLocation();
config.set("some.path", location);
player.sendMessage("ok!");
}
return true;
}
}
and what in here?
it was an example
[16:31] Fefo6644: You already have cfg
[16:31] Fefo6644: set the location in there and save the file
but the world is null
what?
also that does not even compile
you should really learn Java before jumping into plugin development
like
really
hold on a minute
https://paste.helpch.at/ejikamecol.md
I've heard good things about JetBrains Academy (paid, but with free trial) and Coursera, I strongly suggest you know how to use Java before making actual things with it
Does any1 know how to use custom texture heads from https://minecraft-heads.com/custom-heads/
ok
hello
for some reason this works
wand = item;```but this doesn't?
```hs
test = item;```
what
Too little information to comment on
the rest is just a bunch of meta stuff
this is a single line of java code that apperantly reassigns a variable ?
like, we have no idea what is going on in your code
Answer me this, when I take an orange from my fridge it doesn't work?
1 sec im having weird problems
ok i'm back, i was missing a { and i had wrong indentation
the issue still occurs, what more information do you need btw
That's because your cat is jumping into your bed
Easy
Like, the actual code. Where arre the two variables initialized
private static void createFriedCoal() {
ItemStack item = new ItemStack(Material.COAL, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§7Fried Coal");
List<String> lore = new ArrayList<>();
lore.add("§7You somehow managed to");
lore.add("§7Fry coal");
lore.add("");
lore.add("§a§lCOMMON");
meta.setLore(lore);
item.setItemMeta(meta);
test = item;
}
}```
how is test initialized.
what's initialized
is test an ItenStack?
well the last thing sets it
^^ java requires you define a type, and test is never implicitly defined.
what
yeah it sets it to item
ItemStack test = item
why are you using haskell for your code blocks lmao
it worked fine in my other item thing
Show the full code of that
probably have a field named wand
public class LudicrousyItems {
public static ItemStack wand;
public static void init() {
// adds wand function to somethin, idk
createWand();
}
private static void createWand() {
// sets variable "item" to 1 blaze rod
ItemStack item = new ItemStack(Material.BLAZE_ROD, 1);
// sets variable "meta" to everything about variable "item"
ItemMeta meta = item.getItemMeta();
// sets item name of variable "meta" to "§6Explosive Stick"
meta.setDisplayName("§6Explosive Stick");
// sets variable "lore" to a new list
List<String> lore = new ArrayList<>();
// adding a line of lore to variable "lore"
lore.add("§7Right click on a");
lore.add("§7block to create an");
lore.add("§7explosion at your location!");
lore.add("");
lore.add("§3§lRARE");
meta.setLore(lore);
// adding an enchant to variable "meta
// false = ignores normal minecraft enchantment limit like sharpness 5, though someone said you need to set it to true for no cap
meta.addEnchant(Enchantment.LUCK, 1, false);
// sets flag
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
// sets variable "item"'s meta to variable "meta"
item.setItemMeta(meta);
// adds variable "item" to variable "wand"
// or how normal people say it: adds the meta i just made to the wand item
wand = item;
}
private static void createFriedCoal() {
ItemStack item = new ItemStack(Material.COAL, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§7Fried Coal");
List<String> lore = new ArrayList<>();
lore.add("§7You somehow managed to");
lore.add("§7Fry coal");
lore.add("");
lore.add("§a§lCOMMON");
meta.setLore(lore);
item.setItemMeta(meta);
test = item;
}
}```
yea
Gods what formatting is that
there is your field
var test = item :)
hs
java exists
but why does it work on top part
haskell lol
because you define a field called wand
You define a variable wand already with the type ItemStack.
maybe take a java basics code
The difference is you never define the type of test, only the value.
I think you should learn Java first instead of learning to use spigot API
A Java Field is a variable defined at the class level.
public static ItemStack wand;
public static ItemStack wand;
:>
at the top of your class you are defining that wand is of type ItemStack
i searched, 0 results
im new is this channel talking about plugins or coding?
it's literally there
Well we're all literally staring at the code
you should really learn Java before diving straight into plugin making
^^
but i don't want to learn java, i just want the minecraft part
500 iq play
i hate to tell you but minecraft plugins are written in java
yeah that's what i said minecraft part
m8
That's like saying you want to speak english without knowing how to speak.
Must learn Java, no clicky buttons make plugins
there is no minecraft part xD
That's impossible.
i mean the minecraft part of java
wtf xD
i don't want all of java
omg
Spigot and bungeecord plugin development but not necessarily plugins.
this is great
ok lemme ask this: what can you do with java
code programs
Everything
Likely everything
well i just want the minecraft part of everything
i don't want to code games or whatever
Example:
Hentai game
yes, and for that you still need a solid foundation of java
Thats Java, learn it or you can;t write plugins
java minecraft part of java idk man
to code good minecraft plugins you'll need a pretty deep understanding of the language
my english isn't the best
The only difference between learning to code games and code minecraft plugins is you're learning a different API. You still need to learn Java itself for both.
anyways i still don't know where i set wand
you look like a 1.8 user
public static ItemStack wand
oh i see now
1.16.5 actually
Just, learn the java basics first ;/ they are definitely part of your "minecraft java part"
my b, i put void after static, that's why there were no results
You're wasting your breath.
this person has a hard head, personally I will not waste my evening explaining something so obvious.
your mom
She's fine, thank you
you're welcome
anyways i'm out, thanks guys, gals and non-binary
We are all binary in here! Its a part of being a programmer.
I cant quite get clickEvent Books to work, can anybody help me? (Rather new to code so you might need to dumb it down)
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.
Send the code
does bungee have sync?
(Put it in a paste)
thx, i'll look into it
tho "async" really just works wherever. Java has a lot of its own threading model
the 3rd pages.add is where i was trying to impliemnt it
Does the event work at all or no
well
yes kidn of
i can get the book, im just unsure how to set up ClickEvents and HoverEVents
and i can get The first paoges
click events and hover events are part of the text inside the book
there is no event on the server side for them
these events happen on the client side
well yes i mean, atempting to get to run a command
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
there ya go
I mean it is the only way you'll get click/hover events in there using just spigot
true
can someone give me an example of a shaped recipe, shapeless recipe and a furance recipe? both of these don't work :/
https://www.youtube.com/watch?v=hSvdcA1NAxk&list=PLDhiRTZ_vnoUvdrkTnaWP_hPmbj2JfPAF&index=8&ab_channel=TechnoVision
https://www.spigotmc.org/wiki/recipe-example/
its just the issue is there, is that I cant seem to Format it in a pages.add(), it always gets some kind of either String error, semicolin error
https://www.spigotmc.org/wiki/recipe-example/ Last Modified: Feb 3, 2019 at 12:17 AM
It works.
Thats probably because you don't know Java.
i literally copy pasted the code
And thats why. Without knowing Java you will not notice any mistakes you made.
how can i do any mistakes if i copied the code
You don't know what the code is doing so you can't tell what you did wrong.
??????
Because not all code can be put everywhere
you make no sense
My intellij says that the project is out of source root folder, I already fixed that but it gives me error on all class.
I can't even use my own classes.
?paste the full code you have in your class
Where in teh example code is this line ShapedRecipe wandRecipe = new ShapedRecipe(NamespacedKey.minecraft("wand"), item);?
?
Pretty sure you need to do bookMeta.spigot().addPages(company)
Its not, so you didn;t copy/paste as you said
no this is the youtube video tutorial one
i copy pasted the spigotmc one, it didn't work so i removed it
tho i did try adding NamespacedKey key = new NamespacedKey(this, "diamondcustom"); from the spigotmc one
ok, your line 50 requires a plugin reference, you provided this, which is your LudicrousyItems class.
ye that's what it said on the spigotmc thing
no its said this if you were in your onEnable, in your main plugin class.
You are not in your onEnable or in your main class.
oh ok
the tutorial said to put it where i set my items
so i put it there
how do i set it to the main thing
well, you redesign your class to remove all the static and make it a singleton
yeah i understood 0% of that
Change yoru init function to a constructor you can use Dependency Injection to pass a plugin reference.
I know 😛
rip floofsy
i- what?
lol
learn java
neverrr
tbh
you just hurtin yourself not learning java
i'mma just put it i the main one
yeah write your entire plugin in a single class
you are wanting to drive a semi truck across the whole country without knowing how to walk
literally
no need to give a shit about oop
just imagine it's a functional language and make everything static
a what and make what
lol ye
what doesn't happen often
you
yep
I actually laughed out loud 🙂
functional programming 😌 😌 😌
lmao
Oh no
haha
hello there ladies and gents
it's your favourite person
here to talk to you about anarcho capitalism haskell!
I have been in here a lot and literally never seen you before
indeed
it is a rare occurrence that i step foot in this foul hovel
but when i do
😌
anyway
His name is familiar, but thats probably because it starts with Minecraft
what does everyone here know about monads?
Simon P. Jones?
okay 2nd favourite*
it's a very unique prefix,
You mean the things between my legs?
umm
ok so what do i do exactly
no that's not what i mean but ok!
btw i put it in the main and it sent a bunch of errors
let me move to #general so i don't interrupt
Spoonfeed a newbie for a day and they'll come back with more questions. Teach them to find their own answers and you'll both be better off: you won't get stuck answering the easy questions and they'll be much more productive than before.
errors are good! You can learn from them
i would learn from them if they were in english
what
and if they made sense too
I bet its almost English
i literally just set the variable, and then it says it can't find it in the line where i set it????
and it does make sense once you've learned some of it
NamespacedKey key = new NamespacedKey("Ludicrousy", "diamondcustom");```
https://i.imgur.com/u1O4JSI.png
If thats in your main class you shoudl be using this
also pog it's 12:00 AM now in my timezone
so i put it back
it may just be that NamspacedKeys arent in the api
ew it's mrenxo
this always refers to the class you are currently in.
good to know
but thats hopefully changed by now
i changed it tho
I need some help:
I am making a socket plugin for my bungeecord server so I can communicate between servers
and I want it so the socket plugin would be its own plugin that hosts the server and other plugins can hook into the socket plugin to communicate.
how would i do that
Not a simple answer
idc if its not a simple answer
i just need a answer
i put the example in my main thing and now it's still broken
you can expose an API within your plugin that other plugins can access.
how would i do that
https://i.imgur.com/2ixQ0WG.png red, yay!
You are getting closer
?
what IDE are you using? Intelij by the looks
yee
I've no idea on the key sequence for InteliJ to auto import
wat dat
Is there a way to check if an inventory is open? I want to have a progress bar inventory which doesn't update if nobody has the specific inventory open
what's import
ty Elgar
what do i do with all the errors
what are the errors
read teh link I gave you
oh i just removed one letter and press the thing from the list
allows your class to see code from other places. Ctrl+Alt+O and never worry about it again
ok so i did NamespacedKey key = new NamespacedKey("Ludicrousy", "wand"); in the items class but it gave me a warnning saying it's deprecated
you should use a reference to your plugin instead of a string for the first argument
im confused, what do i do
this
but i need to put it in the items class for the items
pressing ctrl+p when your cursor is inside a function will tell you what data type it expects
you need to get it working before you go breaking things
NamespacedKey required a Plugin reference, not a String
and i do that how exactly?
I just told you
How would i make events in my plugin api
every time something happens in your plugin , call that event
you can make it empty or do something
whats a best way to get 8 blocks in a 3x3 area around one block?
i can make a BlockFace array for NORTH EAST WEST and SOUTH but what is the best way for corner blocks except for 4 calls to blocks.getRelative(1, 0, -1) with 1 and -1 respectively
idk how that would work tho
i can easily do it in javascript
made it work, i fail to see how this helps
but java is way different
you can do a for loop and continue if dx == dy == 0
i think you have two ways, one is to make users @Override your event method (but in this case it has to be empty) and second is make a interface PluginEventHandler and make some methods there
more efficient may be to just make an array list but also harder to adapt for larger areas if you plan on that
can you give a example?
but wouldnt override the event method make only one plugin be able to use it?
yeah thats why i prefer the second way for plugins to register their listeners to your plugin
@silver robin renamed dy to dz since that's prob more accurate
for(int dz = -1; dz <= 1; dz++) {
for(int dx = -1; dx <= 1; dx++) {
if(dx == dz == 0) continue;
doYourThing(centreBlock.getRelative(dx, 0, dz));
}
}
replace the 1s with whatever radius you want
i see how it would be more efficient if i plan on large areas, for example 5x5
but with array list, i would have something like this, right?
(There maybe is a lot of bad syntax, i don't know everything by heart)
List<Set> a = Arrays.asList({1, 1}, {1, -1}, {-1, 1}, {-1, -1})
for (Set coordset : a) {
Block rb = centerBlock.getRelative(coordset[0], coordset[1]);
}```
i need the documentation for 1.8, and possible?
https://hub.spigotmc.org/javadocs/spigot/index.html?overview-summary.html
If I want to store all entities that spawned from Spawner, is it better to use WeakReference on the Entity or just create a Set and store the UUID instead? or it's just depends on what I'm gonna do with the entity.
You can create a weak hashset
Collections.newSetFromMap(new WeakHashMap<>());
if you want to hardcode it and only care that its super fast, then theres the ugly way:
static final int[] offsets3x3 = new int[] {
-1,-1
-1,0
-1,1
0,-1
0,1
1,-1
1,0
1,1
}
for(int i = 0; i < 8; i+=2) {
doYourThing(centreBlock.getRelative(offsets3x3[i], 0, offsets3x3[i+1]);
}
This will be fast but ugly
ah alright, thanks!
I recommend the double loop instead
both are pretty much instant anyway
if you're not doing it hundreds of thousands of times per tick it won't matter
ok
im very confused
so i have a gui for settings, and i want to read the players input from chat
settingsPane.addItem(new GuiItem(rlMsgItem, event -> {
}), 0, 0);
whatever i put in that gets run when the player clicks on the item
how do i get what the player says in chat?
you'll need a callback no
since you need to wait for the player to type something out
first solution that comes to my head is have a singleton chat listener with a hashmap between player and callback function
if they send a chat message and are present in the map, cancel the event and fire the callback, and remove them from the map
hmm
your settings pane would just tell the chat listener to add them to the map and you would specify the callback
but that would break if two people are trying to do it at the same time
i could close the gui, listen for chat event, repoen gui
and in onPlayerSentMessage:
if(awaitingInputMap.contains(messagePlayer)) {
awaitingInputMap.get(messagePlayer).accept(message);
awaitingInputMap.remove(messagePlayer);
e.setCancelled(true);
}
alright
if you want something fancy like a timeout, you could start a runnable or make a class which holds the callback and the expiry time, and use that in the hashmap instead
where's the random username dude, I want to make fun of him a bit more
No need to
@wraith rapids hey so I now have two powers which are in the bombardment category, they are specifically for the ender dragon, they are are both for fireballs and they are both configuration instancers, can you guess how long the class name got?
does calling openInventory() when a player has a similar inventory already open cause the cursor to jump back?
@grand swan i need the documentation for 1.8, and possible?
https://hub.spigotmc.org/javadocs/spigot/index.html?overview-summary.html
package index
hey, does someone know the best way to fill a circle? I made a flat particle circle, but dont know rly how to fill it. I know i can just draw alot of little circles inside it but thats gonna take like 20 for loops
So yeah if someone knows id be happy
Thats my current code:
private void drawCircle(Location loc, float radius) {
for (double t = 0; t < 50; t += 0.5) {
float x = radius * (float) Math.sin(t);
float z = radius * (float) Math.cos(t);
loc.getWorld().spawnParticle(Particle.REDSTONE,
new Location(loc.getWorld(), loc.getX() + x, loc.getY() + 0.5, loc.getZ() + z), 1,
new Particle.DustOptions(Color.PURPLE, 1));
new Location(loc.getWorld(), loc.getX() + x, loc.getY() + 0.5, loc.getZ() + z)```
can be written as```java
loc.clone().add(x,0.5,z)```
given a range of r
start at x = -r, z = -r
iterate over to x = r, z = r
over an increment of d
I'd just go with concentric circles, just requires an outer loop for radius
no
just this one loop will do
in other words, pretend that you are filling a square
but only spawn the particle if it's within the circle
1 for loop around it all to start at 1 and count up to the radius. The inner loop you do as a multiple of radius for the number of particles you are going to spawn
then move one notch up
and go back to the rightmost border
then go left
rinse and repeat
given a range of r
start at x = -r, z = -r
iterate over to x = r, z = r
over an increment of d
i thought thats like 4 for loopsd
for the radius check you can use square distance btw, to avoid a sqrt
well
the first loop
is going from
one side
to another side
basically draws a diameter
no
no it fills it in
one loop draws a line
inner loop runs once per outer loop iteration
the second loop makes it draw a line for every x
the inner loop iterates over every block in a row along the z axis
the outer loops repeats this operation once for every position in a row along the x axis
the code itself draws a dot
putting that code in a for x loop makes it draw a line
putting that code and loop in a for z loop makes it draw a square
so basically in the end
your inner loop does:
your outer loop does:
[inner loop]
[inner loop]
[inner loop]
[inner loop]
[inner loop]
putting that code and loop in a for y loop makes it draw a cube
yes
yeah that makes more sense
together you get:
precompute the value of r^2 so you can compare (x^2 + z^2) <= r^2 instead of sqrt(x^2 + z^2) <= r
as square roots are relatively expensive
okay as much as i understood
to make it a circle you just discard it if dx*dx + dz*dz > r*r
yea what nnya said pretty much
how tho?
if i have x + z
x and z
no, its x * z
since the z loop is inside the x loop
when you iterate over x, you do a full loop of z
so you do:
x=0
z=0, z=1, z=2, ...
x=1
z=0, z=1, z=2...
x=2
z=0, z=1, z=2...
x=...
consider the for loop as a multiplication operator
we start with 0 dimensions
a dot
a single particle
with a for loop, we can have a lot of particles
this makes a line
we have one dimension
if you had it like this:
for(int x=0; x < 10; x++)
doTaskA();
and then doTaskA() is defined as:
for(int z = 0; z < 10; z++)
doTaskB();
let us call this dimension x
how many times would task B run?
now, we want a square
a square has two dimensions
lets call this second dimension y
Dimension
what we do now, is we put the for loop in a second for loop
direction
what does that mean
axis of freedom
a direction that is orthogonal to all other dimensions
yea
and there is in/out
3 dimensions
x,y,z
so, let's take it from the top
we have a 0 dimensional object
a dot
it does not have width
y
How can I more accurately test if a slime entity is on the ground (or if/when it lands)?
Using Entity#isOnGround() to test when it hits the ground while falling returns as true about 2 blocks before it should.
mhm
surely there must be a guide out there that this guy can see a visual representation of lol
it is simply a dot
now, a line is just a lot of dots side by side
a line has one dimension
so left or right
yes
so we can take a dot
and put the dot in a for loop to place it side by side a bunch
and we get a line
so
whats the dot for loop tho
a square is just a lot of lines side by side
for (int x = 0;x < 10;x++) { //dot }
draws a line of 10 dots
the inner loop draws a line
now
we want a square
and just like a line is just a lot of dots side by side
a square is just a lot of lines side by side
so we put the for loop in a for loop
for (int y = 0;y < 10;y++) {for (int x = 0;x < 10;x++) { //dot } }
now we have 10 lines
but the for loops
each being 10 dots
^ i.e. the outer loop draws the inner loop (=a line) side by side along a different dimension.
right?
they are
i know there's geometry class going on but when someone can help i'd appreciate it xD
they are since one is inside another
okay so if i were to type sysout hey
it would be printed 20 times inside the for loop?
nope
10 x 10
it would be 20 if the loops were not nested
for(10 times)
hey
for (10 times)
hey
will do 20 times
okay
for(10 times)
for(10 times)
hey
will do 100 times
so nested for loops
since the inner loop is 10 heys and the outer loop is 10 of those, 10*10 = 100
yes by logical reasoning it will be x * y
@vital ridge does your spawnParticle even work? I just tested it and got nothing
for(10 times)
doTaskA();
and task A is:
for(10 times)
doTaskB();
^ you can say that saying doTaskA is the same as saying doTaskB 10 times, right
just gonna mention this here and there since the chat keeps getting flooded
so if you do task A 10 times, you will be doing 10 * (task A) = 10 * (10 * task B) = 100 task Bs
it does
you can try do an AABB check
or pathtrace down from the centre
though that wont work on corners
i didnt rly understand that tho:
for (x = -r; x <= r; x+=d)
i didnt understand the last x+=d
like shouldnt it be x++
or x+ 0.5
x+=d is short for x = x + d
i thought its diameter
r is the radius, (2*r) + 1 is the diameter
that might be a bit difficult but i can try lol hmm
oh wait, i can do a fall damage check on it?
If it has fallen far enough to take damage, yes
think it through, how many times would this code run:
for(int x = -1; x <= 1; x++)
//code
1
ah damn, sometimes it might not fall far enough
nope
-1 and 1 difference is 1?
1 - -1 = 2
but that isnt the amount of times it runs
go through the loop in your head
it says:
x starts at -1
check if x is less than or equal to 1
if so, do the code
now increment x by 1
should be 2 times
<= makes the range inclusive
-1 + 1 + 1 = 1
-1 inclusive to 1 inclusive
we start at -1
-1 <= 1
we go to 0
0 <= -1
we go to 1
1 is still <= 1
smaller or equal
A OR B = A, B, or both
nothing
think it through
stop talking and start thinking
start at x = -1
check the guard (is x = 1?)
if it passes, do the code and then do the increment step (x++)
if it doesnt pass, finish the loop (without executing the code inside it again)
I know what it does but math + java fcks everything up for me
you clearly don't
you have a vague, intuitive guess as to what it probably does
you don't actually know what it does
so look it up, make your understanding concrete
for(<assignment>;<guard>;<operation>) {
<body>
}
you should know exactly what each part of a for loop does
and when it does it
@vital ridge are you trying to achieve something like the dragon breath effect?
Basically just a filled circle
what he needs to achieve is understanding for loops
dragon breath or whatever else is secondary
it all depends on how he needs it to look. If he is filling grid based its going to show a pattern
yea but if you dont want a grid pattern you'd have to get into angles and golden ratio and shit
not really
or just random ig but its not gonna be as uniform a covering
private void drawCircle(Location loc, float radius) {
for (float r = 0.1f; r < radius; r += 0.1f) {
for (double t = 0; t < radius * 25; t += 0.5) {
float x = r * (float) Math.sin(t);
float z = r * (float) Math.cos(t);
loc.getWorld().spawnParticle(Particle.REDSTONE,
loc.clone().add(x, 0.5, z), 1,
new Particle.DustOptions(Color.PURPLE, 1));
}
}
}```
using his code
it increases in density as the radius gets larger
there's going to be a hole in the center
I can;t see one
you need glasses
possibly
but basically, the circumference at the center becomes so small you can't fit your interval in it
and you end up with a 1 particle sized hole
due to the particle size there is no hole as they overlap
maybe but that doesn't make it uniform
looks quite uniform to me, but as you say, I may need glasses 🙂
How many server resources can you allocate for the database?
To make it enough for her!
for a sunflower arrangement you'd want to have just one loop which adds a constant to the radius and increase the angle by the golden ratio (or a multiple thereof)
its about as uniform as you get
I'm probably just an idiot, but this code is giving me a NullPointerException, and I don't understand why.
private boolean UUIDUsed(UUID UUID) {
Path factionsfolder = Paths.get(plugin.getDataFolder() + "/factions");
if(Files.exists(factionsfolder)) {
try {
Files.createDirectories(factionsfolder);
} catch (IOException e) {
e.printStackTrace();
}
}
return Arrays.asList(ListFilesInDir(factionsfolder.toFile())).contains(UUID.toString());
}
The error: https://paste.md-5.net/ebugukocaj.bash
It makes no sense to me why there's a NullPointerException, nothing here should be null
plugin is null
no it's not
Lmao
there aren't really any other alternatives
ok its not, good luck
Where do you initialise “plugin”
static Main plugin;
public Factions(Main plugin) {
RTP.plugin = plugin;
plugin.getCommand("Factions").setExecutor(this);
}
Factions is called from Main.java(which is plugin) with
new Factions(this)
how do i call another java class?
NamespacedKey key = new NamespacedKey(>>><<<, "wand");
What is this
yep, plugin is null
But it's not... I can call to plugin from other places in that class and it works
remove static and assign with this.plugin =
Ah oof I had it to RTP.plugin = [...] instead of Factions.plugin = [...]
dont do static for stuff that is in any way related to order of execution
yeah don't use Factions.plugin either
use this.plugin
it's a constructor
you have an object
use it
weird, then why does it work when I call plugin in other parts of that class
you're probably calling them differently, I don't know
hmm
you are accessing the passed variable plugin not the Field
if we're talking about "other parts" == the constructor, this ^^
basically, don't make random shit static for no reason
and make fields final when possible
will save you from this happening again
I mean, I just have it static because my template plugin I made a while ago (with templates for commands, tab completion, etc.) had it static, I have so clue why I assigned it to static when making my template
revise your template
i still need help ._.
Actually, I know why I did that. Because it doesn't work if i don't do it like that lol
thats a bad sign
If it's not static I can't use plugin.*
yes you can, you use this.plugin, unless your method is static
a lot of my methods are static .-.
make them not static
or redesign that class as static methods should not be designed like you are.
learn what static is and what it's supposed to be used for
its your main class right
a static method can;t rely on a class being intialized
Static sabotages all oop advantages also :[
global state is a maintenance nightmare
if you HAVE to get a plugin reference in yoru static method get it using Bukkit
static methods are fine as long as you use them appropriately and keep in mind how your code flows. static code blocks are sussy
i'll sussy your ass
my ass is premium material
basically, your design is wrong, your layout is wrong, and you are running into development and maintenance issues like the NPE from earlier because of it
you should seek to improve
i know you're writing a "but it works and i have to do it that way" over there
but spare your effort
You're actually right and I don't have to do it that way at all
I just have always been more into other languages like Javascript and only know most basic syntax and how most things in java work, but not some things (even basic ones like static methods,) so I always end up trying to fix errors and just doing what my IDE says would fix it unless I know it won't, which, once again, because I don't always have the knowledge, makes it so I write bad code.
good, that's a good first step
i can't really give any concrete advice beyond git gud without seeing code, but acknowledging shortcomings is a good first step
I mean JavaScript isn’t a object oriented fundamentally compared to Java but surely they have some similar syntax
yeah they have quite a bit of similar syntax but also a few enormous differences
yeah whenever I find something I don't understand I usually google it to learn but thought I understood static methods even though I clearly didn't lol
Generally, static methods should be kept as utility methods
basically, java is an object oriented language, and many of its aspects and advantages revolve around everything being objects
static, however, declares dissociation from objects
that is, something that is static is not associated with an object
putting 2 and 2 together and we end up with static things not being able to use or leverage most of the advantages of the language's core principles
I see. I'll not make methods static that don't absolutely need to be static any more in the future
Thank you
functions without state can still be static; for example, see the java Math class
its methods are nearly all static and stateless
^ Utility class
they take their input, perform an operation on it, and then return some output
they have no internal state
I mean yeah JavaScript at least doesn’t enforce oop
File > Invalidate Cache
okie
refresh the maven project if you are using maven
im using gradle
once you invalidate cache wait for it to finish indexing libraries
thanks
also i thin kthere is no need for consolecommandsender unless i missed something
commandsender if it isn't an instance of player is automatically coming from console unless im dumb
im pretty sure there is
uhhh okay
there are a million different commandsenders
sender has method sendMessage()
didn't think of that
try {
String[] values = fileConfiguration.getString("games." + gameName + ".lobbyPoint").split(",");
double x = Double.parseDouble(values[0].split(":")[1]); // X:0 --> X, 0 -> 0
double y = Double.parseDouble(values[1].split(":")[1]);
double z = Double.parseDouble(values[2].split(":")[1]);
lobbyPoint = new Location(world, x, y, z);
} catch (Exception e) {
// Log the exception
VanillaSkywars.getInstance().getLogger().severe("Failed to load spawnPoint with metadata " + lobbyPoint + " for gameName: '" + gameName + "'. ExceptionType: " + e);
}
VanillaSkywars.getInstance().getLogger().info("lobbyPoint is " + world.getName() + " " + lobbyPoint.getBlockX() + " " + lobbyPoint.getBlockY() + " " + lobbyPoint.getBlockZ());
this is not working and i have no idea why
i've added log/debug lines but there's no errors or log
is there an event that is called when a firework is used? for some reason PlayerConsumeItemEvent isn't called when I use a firework
PlayerInteract detects right clicks
you should be able to check if the player is aiming at a block and is holding a firework
or check if the player is wearing elytra and is in the air
ok, thank you!
I don't use Gradle so I honestly have no idea
I'm creating trying create a plugin that requires custom anvil "recipes" or whatever you'd call them. I have a class that is an instance of Listener and have properly registered it as well. This class is listening for a PrepareAnvilEvent and checks the event.getInventory() for the required items. If the items are present the method will create the output item and call event.setResult() passing in the output item. I also set the repair value too. Everything seems to work in-game, the item shows up in the output slot when the required items are in the input slots but weirdly when I try to take the output item out of the slot nothing happens. Could anyone help me here?
Here is a condensed version of my code:
@EventHandler public void onPrepareAnvil(PrepareAnvilEvent event) { if(event.getInventory.contains(Material.DIRT) && event.getInventory.contain(Material.STONE)) { event.setResult(new ItemStack(Material.DIAMOND)); event.setRepairCost(1); } }
what's "nothing happens"?
The item stays in the slot and doesn't come onto the cursor
its like the item doesn't exist
if you then put the cursor in the inventory as normal does it place it anyhow?
Anyone know how I can get an armorstand to be close to where a nametag would be, I've tried using negative slimes and such but they never seem to be in close enough level.
no
wtf are negative slimes lol
negative slimes? wut
run code to see if the server is still aware that there is an item in the visual slot at the end of item creation and at the time of clicking it
yikes
?
I'm trying to use them as passengers, because I don't want to have some choppy animation
this.roleDisplay = (ArmorStand) this.villager.getWorld().spawnEntity(villager.getLocation().add(new Vector(0, 1.72, 0)), EntityType.ARMOR_STAND); here's an example of how I placed it for static entities
but it sounds like you should be using the teams api
I'm trying to use them for custom mobs essentially
not armorstands
Will that work with mobs?
you want to make the player ride a custom mob?
you'll have to check but I don't think so
it works on fake players
but not on just mobs
afaik
actually it probably does work
pretty sure mcmmo uses it
Hmm I'll look into that
What I'm trying to do is basically Hypixel's mob system
and any other plugin that uses teams and scoreboards
Hmm probably not the best way but hey, it'll be useful to see if it works
teams is the best way to do what you want to do
it's just that you can only have one and more than one plugin wants to use the best way
@torn shuttle Ok, I ran some code that printed the items in an inventory during an InventoryClickEvent and when I click on the output slot the item that is visibly located in the slot does not appear to actually be contained withing the contents array of the inventory
so it's empty
No the other two input items are accounted for, just not the output item
yes, the output is empty
yes
bet I solved the murder
but its visually there
it was the maid in the bathroom with sending a packet about an item but server logic not being overriden because you didn't cancel the event and that means the server instantly overwrites your custom output with the default one
oh, so i just need to cancel the event?
ok ill try that out
the PrepareAnvilEvent has no setCanceled() method so i dont think it can be canceled
ngl shit like this is why I gave up on using anvils and made my own custom GUI
minecraft
yeah, the only reason i want to use the anvil is because i want to keep the vanilla atheistic and functionality
I can think of a few ways around it but fundamentally you should double check if the actual inventory contents contain the output
maybe set it manually
Oh, that's quite.. weird
yeah, no kidding
maybe try calling update on the inventory
I am adding some custom item meta but i dont think that should affect it
Yeah, all I can say is maybe try updating the anvil inventory
wait
that method doesnt exist
for the anvil inventory 🤔
Also I checked the contents of the inventory both during the anvil event and afterward during and InventoryOnClick event and both return the two input items but not the output
how are you setting the output item?
how do i get data from the player nbt directly
im setting the output item through the event.setResult() method
i've also tried setting it directly through the inventory but when i do that it doesn't event apear visually
welp does anyone use gradle in here
how 2 fix the Unexpected lock protocol found in lock file. Expected 3, found 0. error
hm not entirely sure then
have you tried deleting gradle caches
and also for the event, idk why it would display visually but not work physically
@paper viper Welp, I might just have to use another gui to achieve the goal then. Thanks for your help
you may have to use the inventoryclickevent and do some weird inventory syncing, but I feel like
yes
idk i just dont know why
yeah
Like C: \ users \ [myusername] \ .gradle \ caches \ [version]
right?
what about the .gradle folder
in your local project
maybe try moving that somewhere at first
then restart ide
someone help
does InventoryOpenedEvent get called when a player is shown an inventory via plugins?
if so, is there a way to stop/check for it
on the fireworkexplodeevent is there a way to get the firework item that was used?
Can probs just check the inventory holder and see if its a chest or other container in the world.
could you elaborate?
i think i got it
Inventory.getHolder() | Gets the block or entity belonging to the open inventory
If its null.... more then likely a plugin made the inventory.
if (inv.getHolder() == null) return;
👍
thank you 😄
how do i view player data from the file
i want to be able to get info about a player even when offline
If its your files that your plugin created... save UUID's. If not... use Bukkit.getOfflinePlayer(<uuid>)
move the .gradle folder?
move it where?
can't get things like health, armor, coords ect from offline players
declaration: package: org.bukkit, interface: OfflinePlayer
You’ll need NMS to read the player data file
I'm making a GUI only crates plugin (theres probably a reason why people dont do this but oh well) and my test only accepts tripwire hooks that are in stacks of one exclusively. anymore than that and it just does the else thingy thing. Heres my code:
if (player.getInventory().contains(new ItemStack(Material.TRIPWIRE_HOOK))) {
player.getInventory().addItem(new ItemStack(Material.CHAINMAIL_BOOTS));
player.getInventory().remove(new ItemStack(Material.TRIPWIRE_HOOK, 1));
player.sendMessage("Aww... You didn't get the 0.001% chance for getting a good prize. Have some boots! ");
} else {
player.sendMessage("You don't have a key thing in your inventory!");
}
}```
there is no 0.001% chance. dont worry about that
are you saying it doesn't?
You can't no. Like Coll said you need NMS to read the saved data of a player from the world files.
Probably a reason for that
NMS is a bitch.
It’s probably best to save the data you need yourself somewhere else