#help-development
1 messages · Page 1727 of 1
getRecursiveAbstractFactoryFactorySodaBaseImpl()
why does this remind me so much of the internship I once did
FactoryFactories and stuff
ergh
JESUS FUCKING CHRIST WHAT IS THIS CODING CONVENTION
hehe java enterprise :p
cocacola, Cocacola
😮
(meanwhile, Kotlin: return CocaCola(cocaCola[0].toDouble(), sprite[1].toLong()))
wtf
public class player {
}
drinking Sprite reminds me of my BlitzBasic time
protected final synchronized sealed record A<T>(T t) {}
I don't think you can synchronize a record
I also don't think you can make a protected class
I also don't think you can make a sealed record when it's also final and also records can't be inherited (also final is redundant since records are final by default)
so there are many things wrong with this
seems like it's perfectly fine to me
hehe
sheesh
yeah maow
only 80% invalid keywoards, that's quite good
stop sippin sprite
mfnalex is
record A<T extends A<T>>(){} possible btw?
stop askin for more
IT'S SHOWTIME
TALK TO THE HAND "hello world"
YOU HAVE BEEN TERMINATED
cause that sprite ain't clean
yes
oh lol
lets make a programming language that compiles english
at least it doesnt complain and compiles fine
it's possible
And sue people for distributing our code
whenever they mention our words
bc nothing can extend so A so nothing besides a raw type or wildcard can be placed there
so your IDE would probably warn you about doing that
yeah indeed
i just witnessed bugs bunny scoring a hoop
but yeah, nothing semantically wrong about it ig
anyone know how I can add javadocs to the lombok constructors, builder methods and getters setters?
I know I can just write javadocs for the fields but that would require to always add the param and return things manually because IntelliJ doesnt generate them automatically for lombok annotated fields 😦
just dont use lombok
anyone know how I can add javadocs to the lombok constructors, builder methods and getters setters?
you can't, you have to write them manually
records are crying
I have to support MC 1.16 too 😦
record classes probably have internal JVM optimizations as they are immutable
1.16.5 latest supports java 16
so Lombok would be the one crying
but most 1.16 users are still on 1.8
and they won't upgrade just for one or three plugins
at least some of them won't
at least not today
so does anyone have a real idea instead of not using lombok? 😄
afaik records hashCode and equals method is generated using lambda meta factory and method handles, unsure about toString
.
ya
there is no other way, Alex
I just thought that IntelliJ would somehow support it using a plugin or sth but I didnt find anything
anybody here working with intellij idea? i cant add spigot 1.17.1 to the dependencies for some reason...
*spigot 1.17.1 api
im in macos
actually lombok is pretty awesome at times, e.g. sneakythrows, UtilityClass, Getter/Setter/Data, NonNull, etc bla bla
are you using maven?
Which can be generated with IntelliJ fairly easy
sneakythrows are concerning
just use Kotlin if you don't wanna deal with exceptions :p
yeah of course but still it's an extra step
no i dont know whats that
wat
literally isnt
if you know the keybinds it takes less time than writing it out through an annot even
very very very basic guide to setup your first project to just get started: https://blog.jeff-media.com/how-to-create-your-first-minecraft-plugin-using-the-spigot-api-and-maven/
usually i can make plugins in window os and can put the spigot api into the dependencies, but for macos idk why its not working
I simply don't like having 100 lines of boilerplate code cluttering the java file, I like just adding [at]Data annotation and it's done 🙂
I mean records and you can minimize it if you use a reasonable ide
but of course both have their advantages and disadvantages - I am used to lombok and will continue to use it, but of course it also has some downsides
also the code will be about same once compiled
as said I can't use records until almost everyone is on java 16/17 :/
¯_(ツ)_/¯
I'll just manually write the javadocs
for the fields
I don't have anything better to do right now anyway
javadocing fields lmao
thanks!
np! If you have any further questions about that guide, just write a comment on the blog so I can add it to the guide
my server gets angy if I use java 16 on 1.16.5 :(
huh?
what JDK are you using?
lemme boot the server
on windows I'm using oracles JDK and on debian 11 just the default openjdk-17-jdk from the official repos
hm strange
I'm still scared to switch my plugins java version to 16
too many java 8 users still around
they'll write one star reviews because "Unsupported major minor version" and then never reply again when I tell them what's wrong
you can do that too
/**
* Turns an ItemStack into a byte array
*
* @param itemStack ItemStack
* @return ItemStack as byte array
* @throws IOException exception
*/
public static byte[] toBytes(final ItemStack itemStack) throws IOException {
try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final ObjectOutput objectOutputStream = new BukkitObjectOutputStream(outputStream)
) {
objectOutputStream.writeObject(itemStack);
return outputStream.toByteArray();
}
}
like this?
that's perfectly fine in java 8
that right there is valid in Java 8 ^
wtf man
it wouldn't work for me
im so scuffed
i hate coding im gonna go become a janitor
my lib is full of that stuff and I always compile against java 8 😮
it was tellin me to upgrade to at least java 9 for that
it throws errors when you define non-autoclosables inside the ( ) though
but after all something that's not autocloseable doesn't have to be inside the brackets
wanted to use it for my database controller but it wasn't working
hm maybe you had some other mistake and the error was just misleading
Java 9 allows you to do try (localVar) { ... }
idk
all I know was intellij was telling me "ayo bro you gotta use at least java 9 to use this feature, wanna upgrade?"
Strange
f
I'd go check but intellij takes 50 years to open on my computer since I think it's on my hdd and not my ssd
can a paper server run spigot plugins?
yes
Make a bit of sense, paper it's a fork of spigot
Btw, what are u doing here go #help-server
ty
Hello, i have imported the API and this problem happens,
Could be the error caused by the version?
It's outdated
post your pom.xml pls
show me what that is
you didn't add any actionbarapi
ARM
also why would you need it? action bar is accessible by spigot
oh i just saw it
see the code I sent above
yea java 8 does have it
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()), y'know
learning
try-with-resources exists a long time
one sec I'll send an example
ARM has existed since Java 7
isnt it this
yes
exactly
exactly
here says i added the API
Automatic Resource Management
you didn't understand what maven is
you add your dependency to intellij although you're using maven
it closes baos at the end of the try block within a finally I believe, very useful
that's like paying your rent to your neighbour instead to your landlord @acoustic pendant
maven needs the dependency, not intellij
ok, i will check a thread ty
especially since the pre-Java 6 version is so fucking messy
thanks for the explanation
Do we have any others jar than bukkit (no counts its forks)
?
I have a hundred jars on my hard disk
I don't really get your question
OutputStream os = null;
try {
os = getStream(); // for example purposes
useStream(os);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (os != null)
os.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
wdym
that is basically an ARM block pre-Java 6
lol
im impressed
(os is assigned in try as getStream theoretically throws IOException)
Any other server jar that is different than bukkit and its forks, vanilla is an example
there's a ton
They have their own server patching methods.
Forge, Rift, and Fabric have server patching (I think Rift does).
sponge?
No counts mod either tho i forgot 🙂
minestom?
ssssh don't mention peasant software
They required players to uses mod
techniiicaaalllyyyy
depends
minestom and sponge, i just mentioned them
try (OutputStream os = getStream()) { then you don't need the finally
yep
Minestom? Sponge? Heard it before but never tried it
I was explaining the non-ARM version
Sponge is cool
Mixins :)
I uses sponges all the time when showering
smh
Uhmmm… nothing really interesting, do you guys aphave any other server jars?
Sponge isn't interesting to you?
spigot is love
although I'd use one of the works for a real server
but none of the forge / etc things
Pretty sure Sponge allows you to run Spigot and Forge.
Yep
all those hybrid things are either totally bugged or stuck on 1.12
Kinda?
well
Sponge just released a preview build for SpongeVanilla 1.17
which means that SpongeForge'll eventually get a 1.17 build too
all I remember is that I used to get a ton of bug reports from people using sponge and it was always caused by sponge only implementing bukkit/spigot very poorly
IIRC there was a timespan of a few months where they didnt even call PlayerDeathEvent when a player died
perhaps if Spigot was easier to implement lol
maybe I'm confusing the PlayerDeathEvent bug with another hybrid thing though
Uhh, just a minor question that I should know before even starting java, but do you guys think 2 years is the needed time to learn all of the basic of java? Maybe less if you already know how coding work
that highly depends. I'm sure you can learn it pretty decently in a few months when you have much time and also know other languages well. Other people however do java for years and still don't understand what they're doing
soooo
that can't be answered generally
Yep
Oh btw
Coding like what you love the most is better than just follow some tutorials about how you should code (clean code) right?
no
Depends i think
there is a line yea. Obviously on some high level you can argue about how to code and should just use your own style.
but "I like how my public static mutable global state variable is available everywhere" isn't too much help
I use static for utilities and stuff
if Java had top-level functions and namespaces
I used constructor for everything
then I wouldn't need to use static at all, really
How can I get information about potion such as type, durability, level and splash?
So let's say I have ItemStack and I want to check if it's potion and if it is then I want to get its type, durability...
Thanks
?paste
@eternal night I can't use PotionData tho
Are you using 1.8.9
🤷♂️ you're kinda on your own if you want to support 7 year old server software
My best guess would be setMainEffect
aight
https://paste.md-5.net/ujoropemem.css
Please tell me what's wrong 😂
Yes
How do u instantiate TestClass?
ItemRegistry field won’t be null unless you pass null to it ofc
But based on that little snippet you sent it’s impossible to tell
((LivingEntity) entity).damage(25);
entity.setVelocity(vector1.multiply(2));
``` Does anyone know how I could make it so that this code doesn't crash my server?
I fixed it
nvm
apparently it wont let me multiply it by 2 but it will let me multiply it by 1
I don't get all the hate about the static keyword. most of the time the people who don't even know what it does immediately scream "static" abuse whenever they see that keyword lol
How can I get a direction from two locations so one faces the other?
Lets say I have one object at 0, 0, 0 and another at 10, 10, 10. What direction does 0, 0, 0 need to face to be looking at 10, 10, 10?
Idk how else to explain it
you can convert both locations to a Vector
and then use Vector#angle(Vector) which returns the angle between both vectors in radians
is that what you need?
np
yes
uh
I have no idea about vectors and stuff, it's just what I found by looking through the javadocs, no idea if that's anyhow related to what you need lol
ah I think I know what you need
subtract one vector from the other and normalize the result
Oh
then you should have a vector pointing in the right direction
uh wait so lets say its 10, 10, 10 and 5, 5, 5
would give 5, 5, 5
then normalize gets
uh
how does one normalize
normalize()
What are you trying to do exactly?
in math
he has two locations and wants to get the direction that you have to look from loc1 to look to loc2
yes
I think you can just subtract one vector from the other and it'll give you a vector that starts at one and points to the other
yeah true
If you're setting Velocity, yeah, normalize it 
ok ill try it
to get pitch / yaw you probably have to do this ugly sin/cos things on the nomalized vector I assume? 😄
Location.toVector
I already wrote these functions for my own Java game before, but it could be useful to lots of other people
lookAt
What it does is make a Location...
this is probably what you're looking for?
the first code
you provide two locations
- your current location
- the location you want to look at
then it returns location number 1 with adjusted pitch/yaw
so that you are still standing at loc1 but you are looking at exactly loc2
isn't that what you need?
what exactly are you trying to achieve?
trying to make a turret that shoots at nearby players with arrows
I already got nearby players
just need to shoot them
uh
Im using the
World.spawnArrow(Location, Vector (rotation), speed, somethingelse)
Location turretLocation = ...;
Location whereToShootAt = ...;
Vector direction = turretLocation.toVector().substract(whereToShootAt.toVector()).normalize();
Its that short?
you can then then use turretLocation as Location in the spawnArrorMethod, and direction as your Vector (rotation) thing
(I THINK)
just try it
if it shoots in the opposite direction, you have to switch the turretLocation and whereToShootAt location of course in the vector calculations
I just typed it into discord
Object.substract works
?
yeah ik
and Object also doesnt have any "substract" method
Technically primitives aren’t objects
yeah of course
I meant
every object in java is instanceof Object
lol its shooting backwards
and from the corner of the block
just multiply by -1 i guess and subtract 0.5 from x and y
or is it add 0.5?
multiply by -1 or as said here:
multiplying by -1 should work fine
is it working?
Its getting stuck in the block
just gonna add 1 to the height
great
my ftp just stopped working
i cannot figure out this jdbc url for the life of me
why is it null?
im using the sql url format from here https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-jdbc-url-format.html#connector-j-url-single-host
specifically jdbc:mysql://address=(host=myhost1)(port=1111)(key1=value1),address=(host=myhost2)(port=2222)(key2=value2)/db
Connection con = DriverManager.getConnection("jdbc:mysql://address=(host=localhost)(port=3306) (user=paul) (password=password)/logReader")
I'd use the simple url unless you have a specific reason not to and passing username and password as arguments: getConnection("jdbc:mysql://localhost:3306/logReader", "paul", "password")
public void onBreak(BlockDamageEvent e) {
Location location;
Player player = e.getPlayer();
Block block = e.getBlock();
String broken = block.getType().name();
ItemStack item = player.getInventory().getItemInMainHand();
if (item != null) {
return;
}
if (item.hasItemMeta()) {
if (item.getItemMeta().getLore().contains(ChatColor.GREEN + "- Wood Cutter")) {
if (broken.endsWith("_LOG") || broken.endsWith("_PLANKS") || broken.endsWith("_STEM") || broken.endsWith("_WOOD")) {
e.setInstaBreak(true);
}
}
}
}``` anyone know why it won't insta break the block please
Item will be null
sends no errors
You return if the item is not null, yes
ohhh ty ty
sorry I meant to put == there
does anyone have an idea on how I could check whether a player is allowed to open a chest, without having other plugins think that I actually opened the chest? (other plugins might open a GUI or something)
The interact event maybe?
Currently I'm simply calling PlayerInteractEvent and check if it gets cancelled, buuut that leads to WorldGuard messages when they are not allowed, and sometimes opens GUIs for some plugins
yeah but that has some side effects for some plugins :/
well I'm just calling the event and then check if it was cancelled
I'm not listening to it
yeah imagine I have to know whether a player is allowed to open a chest at x100 y64 z100
so I call a PlayerInteractEvent with "player XY right clicked the block at x100 y64 z100"
and if that get's cancelled, i know a player isn't allowed to open that chest
Ah
I haven't found a better way so far
Feels like a terrible work around
Most plugins should have some sort of api for you to hook into
well I cannot hook into 100 APIs 😄
True
and actually the workaround isn't thaaaat terrible because
let me explain why I need it
for my ChestSort plugin, players can sort a chest by leftclicking it
What about nms?
the alternative would be the player to open the chest (so they would actually do a playerinteractevent anyway) and then sort it with the inventory open
packets
how would sending packets or NMS tell me whether other plugins allow a player to open a chest?
Is there a way to block packets from getting to the server?
override fun getServer(player: ProxiedPlayer): ServerInfo? {
if(onlinePlayers.containsKey(player.uniqueId)) return onlinePlayers[player.uniqueId]!!
if(!player.isStaff()){
player.disconnect(ComponentBuilder(ChatHelper.format("&cServer is in maintanence mode!")).currentComponent)
return null
}
if(main.serverHandler.hubs.isEmpty()){
player.disconnect(ComponentBuilder(ChatHelper.format("&cNo hubs online!")).currentComponent)
return null
}
val server = main.serverHandler.getHub()!!
onlinePlayers[player.uniqueId] = server
println("Player ${player.displayName} is being sent to hub: ${server.name}")
return server
}
Does anyone know the right way to do this? Because I'm getting a NullPointerException and the player isnt getting kicked.
soo IMHO a playerinteract event would be called anyway. the problem is just that some plugins decide to open a GUI when a player left clicks their chest
a NPE at what line?
the return nulls
well returning null cannot cause an exception
Is having too many repeating tasks a bad thing?
too many, yes
define "too many"
when those tasks compile spigot, then even one task is too many lol
How can I get the location of the tip of the end rod?
you mean regardless of whether it was placed left/right/up/down of a block?
Block has a method getBoundingBox
but you'd still have to do some calculations based on the rotation of the rod etc
Well if I know the rotation I can just add or subtract one to the right axis
e
Ill have to do that i guess
End rod's blockdata implements Directional
so cast the Block#getBlockData to Directional and you can get the BlockFace / "rotation"
import org.bukkit.block.data.Directional;
Block block = e.getBlockPlaced();
Directional blockData = (Directional) block.getBlockData();
blockData.getFacing()
i need help with this code i have been trying to get it working for a week @EventHandler public void onAnvil(PrepareAnvilEvent event){ AnvilInventory anvilInventory = event.getInventory(); ItemStack[] itemsInAnvil = anvilInventory.getContents(); ItemStack slot1 = itemsInAnvil[0]; ItemStack slot2 = itemsInAnvil[1]; ItemStack result = new ItemStack(slot1.getType()); if(slot2.getEnchantments().containsKey(Enchantment.getByKey(Enchantment.DURABILITY.getKey()))){ result.addEnchantment(Enchantment.DAMAGE_ALL, 4); event.setResult(result); }else{} } it has this NullPointerException java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.ItemStack.getType()" because "slot1" is null
can someone tell me why it says slot1 is null when its not
ok
it output this Lorg.bukkit.inventory.ItemStack;@1349ff99
ok
yo, newbie to spigot so please forgive me lol
is there a way to always get a player by username (assuming the player exists)? i see on the docs org.bukkit.Bukkit.getPlayer(string) may not return a Player if the player is offline
Bukkit.getOfflinePlayer?
seriously lmao is that it
it output 2
neither length nor printing out the array will help
you need to print out the actual object at the index
which will be null
otherwise it wouldn't error
Yes but also don't use names. Use UUIDs
see that's the thing- i need to use usernames here because it's a hassle for players to grab their uuid
is there some API i can poll?
Why can't you get the uuid?
because this is a command that's being run from discord 😛
What are you trying to do?
just make sure to throw those calls onto another thread
Oh are you using jda?
si
lookups obviously require network
What does the bot command do in discord?
whitelists a user if they have a given role
then links their discord ID to their minecraft UUID
it outputs the item i put in slot1 only when i put in slot1 if i put it in slot2 it only outputs the NullPointerException
Ah ok
which makes complete sense
because if there's no item in the first slot it will be null
and you're calling a method on it
Just do a null check @olive valve
ok.. i dont know how to do that.. please can you tell me.?
If thing null return
Show code
if(slot1 == null) return;, if (slot2 == null) return;
It's throwing an npe because slot1 is null. You need to check if slot1 is null before doing anything with it
What line is the npe being thrown at?
Hi how do i add content to a book? When I try i get this
23
wait one sec
ok
if(slot2.getEnchantments().containsKey(Enchantment.getByKey(Enchantment.DURABILITY.getKey()))) {
Anyone?
i dont know sorry
ok then check if slot2 is null first
if you don't want do anything when slot 2 is empty return if it's null
https://www.twilio.com/blog/5-ways-to-make-http-requests-in-java it seems there are ways to make asynchronous HTTP calls that won't block the main thread- as a mostly javascript developer, async means it doesn't block the main thread and allows other things to execute. is this not the case for java? do i still need to run the call on another thread?
it changed the NullPointerException to line ItemStack result = new ItemStack(slot1.getType());
then do the same for slot1
you always need to null check stuff like that before using it
Did you give it an author?
Books require some specific type of data, else they do that
Author is one of them, I think there's another but not 100% sure.
it worked!!
thank you!
i put the Null Checks in the wrong spots
when i was doing it
How do you get the name of an inventory?
Are you in an event
event.getView.getTitle iirc
object
ohhh
i was doing e.getInventory().getView()
that explains it
thanks
I'm making a thing where you right click a block and it opens a gui, and then you click different items to change that block. How can I get the block they right clicked in the inventory click event?
Hi, I have an issues with a ResultSet from a query... I don't know why but it seems that when I do rs.next() to get the first row, it seems that the resultset is empty.
I tried to make the command directly on the sql db and it does return a table with the values I want
So, I don't understand why 🥲
nvm... I found the issue 🥲
If anyone can make if u eat a specific item it give u effects dm me 🙂
Advice
Add a pdc tag to the item and use the PlayerItemConsomeEvent
ik but it hard
ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
BookMeta meta = (BookMeta) book.getItemMeta();
meta.setTitle(ChatColor.RED + "My Book");
meta.setAuthor(ChatColor.GREEN + "Gamer Girl");
meta.addPage(ChatColor.RED + "Hi,\n Welcome To Our Server "
+ "\n Enjoy Our Server. "
+ "\n Our Store is https://HarvsCraft.tebex.io");
book.setItemMeta(meta);
e.getPlayer().openBook(book);```
it give error that its not a book
Do you have api-version set
oh ye I always forgets i am on 1.16
#setPlayerListName doesn't work on Join
I'm on 1.17.1 spigot, any ideas?
Have you tried a 1 tick delay
Bukkit.getScheduler().runTaskTimer(Plugin.getInstance(), () -> {
player.setPlayerListName(finalId + "- " + player.getName() + " ");
playerIDs.put(player, finalId);
}, 0L, 5L);
Discord bridging plugin for block game https://www.spigotmc.org/resources/discordsrv.18494/ - GitHub - DiscordSRV/DiscordSRV: Discord bridging plugin for block game https://www.spigotmc.org/resourc...
well that was my whole idea xD
i was gonna try to make this disord minecraft bridigng plugin
but it already exists 🥲
make it better
what're the chances the dudes who made that are on this server
Would anyone know if there is an attribute or some kind of way to change the delay of being able to put up your shield?
Don't think so
wym?
so what is intended is for it to get the items from a config once
but for some reason every time I open the gui it decides to add another item to it
The inventory may be final
But the contents aren't
Similar to how you can add to a final ArrayList
no, the point is that you cannot re-assign a variable
^
anyways, it anyways is never setting that main variable as far as im aware to add items
final is mostly a compile time feature to write code defensively
yeah but that shit does it on runtime
and it actually overrides final, yes ikr hacky
But not static final
I only set the local variable to the inv, never set the items in the main gui
I believe only true constants cannot be changed with reflection due to inlining
Well you can't change static final fields anymore with just reflection
pretty sure you can?
Nah you need Unsafe
if its just static final MyCustomObject o = new MyCustomObject(); or smtng
ok
In java 16
you'd ofc need to set the field accessible but else than that afaik only constants are what dont work
(true constants)
The problem is you can't do this anymore
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
hey guys, i was wondering if there's any particular reason why you can't edit the drops of a blockbreakevent directly. the only way that you can currently edit item drops is if you set the event to not drop items and to then drop them manually, but i feel this to be kind of hacky and makes it harder to make your plugins compatible with others in certain situations. i dont need to know how to do it, i just wonder about the reason why there isn't a BlockBreakEvent#setDrops(collection of item) method to make it more straightforward
oh yeah but just
AccssibleObject::setAccessible should be enough on the actual field
Not if it's static
Why not? I use that
Newer java blocks it afaik
because you are reflecting into jdk internals
which are now locked in their module
Because Field is a protected class
and no longer exposed
same reason you can no longer call URLClassLoader#addUrl anymore
Sucks for you guys then lol
It's fine, we have unsafe
tbf, this reflection shit is garbage anyway
PR it to the server software and properly expose it
life is better that way
Takes much longer
unsafe is planned to be removed in the future I think
and be replaced with safer api
yee
I mean, at some point it just becomes an issue with how much JIT could technically do as well
if it works then skip all tests 
oo ye probably
Someone tell Mojang to stop using best practices with their private static final ImmutableLists
smh
which like, it already does xD
JIT actually can screw you already
public class JavaTest {
private final String FOO = "a";
@Test
public void testMuhJIT() {
try {
final Field foo = JavaTest.class.getDeclaredField("FOO");
foo.setAccessible(true);
foo.set(this, "b");
System.out.println(FOO);
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
}
}
I believe Mojang even uses a singleton for a sneaky thrower
yields very interesting results xD
which could just be a static utility method
🥲
Idc about the static abuse. But until im sure that I understand it completely, i think i will use it
I just wanted to say: using „static“ often has very good use cases
But of course not always
How can I use a custom ItemStack in a shaped crafting recipe?
new RecipeChoice.ExactChoice(itemstack)
ty
is it possible to force a player into a animation?
packets
That would be spawnParticle
playEffect lets you do stuff like item breaking or the totem animation
Oh
I want to make the player play a certain animation
or even better
like bedrock
make a player play a animation from another entity
not sure how im going to do that
me neither
I used constructor, but someone said that a constructor only need 3 classes, if it more than only 3 class then use something else, what it call, uhhh builder pattern or something
no no no thats definitely not what you want to follow
Sure it might be convenient
but if you have an intermediate component which just requires other intermediate components it'd be perfectly fine just doing smtng like
Configuration config = new JsonConfiguration(
new JsonLoader(),
new ConfigurationSerializer(serializerContext),
this.plugin,
path -> Files.newBufferedReader(path),
path -> Files.newBufferedWriter(path)
);
here all the components passed are significantly distinctive
so we dont need a builder really
even tho it surpasses 3 arguments
okay maybe not the last two
but yeah you get the point
How can I save a list of custom objects to a file?
dont save player to a file
That was an example
as long as they are serializable it is possible
?google "Bukkit serialization API"
Google your question before asking it:
https://www.google.com/
I did
The...
what are you serialising
public List<Player> safe = new ArrayList<Player>();
public Block block;
public Player owner;
public int tier;
public Turret(Block block, Player owner) {
this.block = block;
this.owner = owner;
safe.add(owner);
tier = 0;
}
}```
Im serialising this list
no
do not store a list of players
Use UUIDs
this list
oh yea
You could probably give UUIDs to the turrets too
is it just UUID instead of Player?
If they don't have one
yes
and probably use location instead of block
Set<UUID> uuids = new HashSet<>();
would that save to file?
uuids can go to string easily
and then i imagine there is a static from string
wdym
mmm idk
Either way you have toString and UUID.fromString
uuid is just a java thing tho right?
UUIDs normally give the string representation
they serialize perfectly
There ya go
im confused
oh
So what do I do after I switch to using uuids?
Annnnd you're gone...
Anyone know why no prefixes are showing up in tab?
shitlin 🤮
well do you have any ideas .w.
any tutorials on config.yml... location... ways to read... what to put in
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
found it sorry for askin like a dope
How do I serialize a Block?
Ik it's a dumb question, but what is the best way to innit a list? I am doing it like this rn:
List<String> bannedWords = new ArrayList<>(){{
add("word 1");
add("word 2");
add("word 3");
add("word 4");
add("word 5");
}};
Arrays.asList("word 1", "word 2" ....)
if you're looking for banned words consider using a set though
what would be the benefit?
faster
mk. I will look up the usage. it's been a while since i've used java. ty
Set<String> blockedWords = Set.of("word 1", "word 2");
//
blockedWords.contains(word);
yes
@quaint mantlehey it is possible get some help with NuVotifier and GAListener....this is killing me
How can I save a list of custom objects?
make a thread
List<Object>
I use a map.
?
oh... my bad.. did not read correct 😄
Ok I got my custom object serialized but now how can I serialize the list of serialized objects?
ty
you're thinking way too much of this
wdym
List<MyObject> list = ...;
config.set("path", list);
That saves to file?
🙂
if you're in your main plugin class, getConfig() will get it
Wont this just add it to the config.yml file?
heyo, what's the difference between Bukkit.getOfflinePlayer() and Server.getOfflinePlayer()?
Nothing
awesome
Yes. If you want to add it to a different one, you need to open that config and edit it
wdym
File file = new File(getDataFolder() + File.separator + "your_config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
config.set("path", "value");
try {
config.save(file);
} catch (IOException e) {
e.printStackTrace();
}```
for config.set("path", "value");, the path is inside the config file. Like if you wanted to set name to whatever value, you'd put name for the path.
If you're talking about new File(getDataFolder() + File.separator + "your_config.yml");, that's gonna be in your plugin's folder
yes and no
in the sense that you use a key to access a value, yes
but otherwise no
Getting UUIDs
how do you set up the config file to login to your database?
org.bukkit.configuration.InvalidConfigurationException: could not determine a constructor for the tag tag:yaml.org,2002:SMPly.utils.Turret
What happened here?
?google "Bukkit serialization api"
Google your question before asking it:
https://www.google.com/
?
Hello,
I am really struggling with understanding the Smithing Recipe API.
I have been reviewing this https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/SmithingRecipe.html but I simply cannot get it too work.
Does anyone have any resources to help my understanding?
Thank you
declaration: package: org.bukkit.inventory, class: SmithingRecipe
hello
i want to use the tab in the console
im using windows
when i type the tab
a huge space appears
instead of to do the tab completion
md_5 I am trying too create a new recipie to allow Iron items to be used and crafted with Diamond to create Diamond gear and also keep the enchantments on the item.
Iron helmet with Unbreaking 4 + x5 Diamond = Diamond helmet + Unbreaking 4.
Hey can I use a custom material what I mean is like (material.fireball.enchanted.fireprot.4)
is there a better way to have floating text above a fired arrow than using an armor stand that tracks the arrow in a runnable?
My hashmap has player
but i try remove return null.
cache.remove(uuid)
Can you show an example? If not its ok
You are removing from hash map whilst looping through it
Me?
was that for me?
?
I am just I was asking if I could include NBT data on items Material.fireball.enchant.fireprot.4 something like that
and sure you can. You can use PDC
I haven't heard of this before could you show an example
Btw, you can't add a "Material"
you have to create your own enum class
and add your own custom nbt items there
(or at least you should)
?pdc
ohh
How do I solve this?
I'm doing a foreach on the hashmap to save the data in the database, and I want to remove the data from players who are offline (checking)
😶
I gosh I need to keep working on my java skills
What is saveData(uuid)?
can you show the method
And also, you shouldn't use that symbol for color codes. ChatColor is better
Why? ChatColor is necessary to import and keep making a lot of codes, the symbol seems to be simpler and faster.
(This is a question)
compatability issues
and also
you get a weird A symbol sometimes
due to compatability issues
ChatColor fixes that
ohhhh
Help with saving
also
you dont have to search the color code up
and keep copying and pasting
ChatColor already has names
this my savedata method.
?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.
fyi i think this tutorial has a typo
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
unless i'm doing it wrong
Database database = config.getDatabase();
// we set out credentials
dataSource.setServerName(database.getHost());
dataSource.setPortNumber(database.getPort());
dataSource.setDatabaseName(database.getDatabase());
dataSource.setUser(database.getUser());
dataSource.setPassword(database.getPassword());```
Database should be Datasource
i can't resolve the object as Database
i might be wrong
i'm def wrong
ya'll are using hikari cp and i;'m not
why not
...?
it makes dbs 100x faster
especially for something as slow as sql
well it still uses java.sql.*
that's all the primitive version of my plugin is doing
which config object is being used here?
you cannot remove while iterating via for-loop/forEach
Use an iterator
What can I do?
you have to use iterator()
e.g.
Iterator<String> it = stringList.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
it.remove();
}
('tis an example)
also works for maps
what classifies as a player animation event
Looks like only arm swinging
Is there a better way to get entities in an EntityBlockStorage other than removeAllEntities()?? seems kinda dumb you gotta release them.
Doesn't look like there is anything in the API for it
I assume because an Entity has to be in the world
Is there any place I can get a list of functions that are thread safe, my plugin requires a lot of api requests and I don't want to freeze the main server thread
arm swinging as in the animation of breaking/placing blocks, attacking, shielding?
alright ty
Is bad use contains name from check unique menu?
public void onInventoryClick(InventoryClickEvent e) {
if (!e.getView().getTitle().contains("Perfil de ")) return;
e.setCancelled(true);
final ItemStack clickedItem = e.getCurrentItem();
if (clickedItem == null || clickedItem.getType().isAir()) return;
final Player p = (Player) e.getWhoClicked();
p.sendMessage("You clicked at slot " + e.getRawSlot());
}```
check for instance of the inventory
I've tried, but I can't.
I create a menu for each player.
to show player information.
this is my code (it's a test draft)
The best way is to save the View returned from openInventory into a set
And then make use of set.contains with the event.getView
I actually use a map to connect it with a custom inventory class, but a set is fine for most uses
Depends on whether or not you want to abstract it away
Yeah
Does anyone have any tutorials I can base myself on to open an inventory with player information?
What do you mean by information
Is there a reason why this doesn't work:
@EventHandler
public void onPlayerLogin(PlayerLoginEvent e) {
if (!main.started && !e.getPlayer().hasPermission("admin.minecraft"))
e.getPlayer().kickPlayer(ChatColor.YELLOW + "Server is closed right now. If you think this is an error, please contact an admin or owner.");
}
Player.getStatistic is a good start
Oh no. I just need a good way to create the menu.
my actual code: https://paste.md-5.net/huzafajuza.java
Ah, I want to know if using " if (e.getView().getTitle().contains("Perfil de ")) return;" is the best way
Method in the set interface
have example?
they use machine learning to detect jdk 7 users
I don’t event remember the last time I used java 7
Probably back before java 8 released
thats what they all say
Go to project structure
Oh… what happened? you don’t wanna use JDK 7 anymore?…
you know your default jdk is 7
Just a minor question, how would this (default reloadConfig by spigot (or paper idk if they changed those))
@Override
public void reloadConfig() {
newConfig = YamlConfiguration.loadConfiguration(configFile);
final InputStream defConfigStream = getResource("config.yml");
if (defConfigStream == null) {
return;
}
newConfig.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
}```
different than this
```java
public void reloadConfig() {
customConfig = new YamlConfiguration();
try {
customConfig.load(customConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}```
I read through the first one, but still havent found out the different between 2 of them
Using the Annotation Command Framework, is it possible to add command aliases loaded from the config file? Or do the aliases HAVE to be defined using an annotation?
I saw that in the example on GitHub (the EmpireRoleManagementComand), the CommandAlias annotation has "%empirecommand" as value, but I have no idea on how to define this %empirecommand in ACF :/
got another ACF question:
@Default
public static void onDefault(CommandSender sender, @Optional Player player) {
How can I make ACF print something like "Player asdasd not found" when an argument is given but the player isn't online? I want to the command to only work when people enter no player name, or a valid one, but not when they enter an invalid player name



