#help-development
1 messages Ā· Page 1756 of 1
And tacos
Best I can do is 3$
And this is why you donāt have a rewrite
How do i spawn a baby zombie?
spawn a zombie and setBaby it
is there a better way to find the Location of a target block within x amount of chunks around a player than doing something perhaps a linear search with the blocks in the chunks? I feel like this isnt that efficient and is slow especially when multiple players will be using it...
so you want to find a block within a radius?
yes, within x amount of chunks
example is something like 4x4 chunks around the player
i mean probably the best way to do it is iterate from -x -> +x if you iterate through each block in a chunk itll probably take longer
yeah just a triple nested for loop should do the job fine
could even do it async if necessary but that would raise a lot more issues that would have to be rectified
i see... im just woried that checking through every single blocks in x and z will be very slow if im working with something like 8x8 chunks
whats the context for this? Is a single search like that the best method?
i'll look more into chunk snapshots, i haven't heard that yet...
They are for async processing
to find the Location of a nearby target block within a certain chunks around the player
ill try you guys' method and ill look more into them, thanks!
im not sure whether chunk snapshots will be faster than straight Location.getBlock
i think its a matter of testing
well speed is what im going for, but im also going for the efficiency with lower ram usage if many players will be using this "function" then there'll be constant checks of blocks
i really doubt this would use much ram
especially if you're not caching it
i would just do it async if i were you
huh
even with something like 30 players?
alright i see, ill try both methods. thanks!
OS?
Open source
oh i see, i'm also research something about finding the nearest block too, i can't find any sadly
isn't getBlockAt already async?
I thought it did
nope
is there a way to stop people from using elytras
Like a built in event that you can cancel
rn im dropping the elytra/taking it off if they try to fly but i feel like there should be a more efficient way
Hey! I'm trying to randomly generate items into a chest.
here's the code to generate the items:
public Chest generateNormalRng(Chest chest) {
if (!(chest.getType() == Material.CHEST)) return chest;
Inventory inv = chest.getInventory();
for (int i = 0; i < inv.getSize(); i++) inv.setItem(i, generateNormalRng());
chest.update();
return chest;
}
public ItemStack generateNormalRng() {
// Note: normal is a hashmap (Integer, ItemStack)
ItemStack stack = normal.get(new Random().nextInt(400));
if (stack != null) System.out.println("Generated itemstack: " + stack);
return stack == null ? new ItemStack(Material.AIR) : stack;
}
And here's the implementation code:
private void loadChests() {
this.chest1 = loadChest(chest1);
this.chest2 = loadChest(chest2);
this.chest3 = loadChest(chest3);
}
private Chest loadChest(Chest chest) {
RNGGenerator rng = RNGGenerator.getInstance();
return this.insane ? rng.generateInsaneRng(chest) : rng.generateNormalRng(chest);
}
When I run this, the console prints:
Generated itemstack: ItemStack{LEATHER_CHESTPLATE x 1}
[INFO] Generated itemstack: ItemStack{STONE_SWORD x 1}
[INFO] Generated itemstack: ItemStack{FISHING_ROD x 1}
[INFO] Generated itemstack: ItemStack{EGG x 16}
[INFO] Generated itemstack: ItemStack{EXP_BOTTLE x 16}
[INFO] Generated itemstack: ItemStack{EGG x 12}
[INFO] Generated itemstack: ItemStack{SNOW_BALL x 12}
but the chests don't get updated and they stay empty. Any help on this?
Might be EntityToggleGlideEvent actually
Iirc you donāt want to call chest.update
Just donāt call update
how are you getting the Chest object
Also why do you have a map with integer keys
(Chest) Bukkit.getWorld(map.getWorld()).getBlockAt(map.getChest1()).getState();
um
because
brain
its complicated to explain
and its messy code :/
lemme see if the chest is null
From a quick search on the forums the only thing I found was not using .update
one sec
There is also getBlockInventory
But I think thatās just for getting the half inventory for a double chest.
not null
I was using getBlockInventory before
wait a sec
Youāve made sure there are no other update calls?
super dumb question, do you need to cancel all runnables onDisable()
or does spigot do that for you
no you dont
so spigot takes care of that?
Yes
yep
By checking when the plugin you passed in to make the runnable is no longer loaded?
Just curious^
Is it possible to detect a custom packet sent from a forge client in spigot? I've tried using a library (https://www.spigotmc.org/resources/api-packetlistenerapi.2930/), but it doesn't work for any packets. I'm fairly sure I'm sending the packets correctly on the client side. What is the best way to accomplish this?
Iād ideally like to do it without a library, and itās mc version 1.17
custom packet? Use the custom payload / plugin messages / whatever forge calls it rather than an entirely custom packet
a custom packet wont work without server modding
what is the difference of chunk and chunksnapshot?
unfortunately not
doesnt actually cancel the event
I got a weird error with sql, so this is my command and I got this error. https://paste.md-5.net/okakusaxuj.http
it already tells you whats wrong. read the first line.
I know but I didn't search for aglerr column.
not sure if this is correct. try taking the '' off the column name maybe?
and put them on the aglerr
tried that too, but i'll try it again'
SELECT * FROM theonly_mobcoins WHERE name = 'aglerr';
is what I would do
also ' not `
i think you have to use them
Youre searching for a string. I think the ' ' on the aglerr is necessary
^
use prepared statements
if youre having trouble getting the results you need we will have to get more information
np
how to get the last element of this set ?
get list.size-1
Anyone here familiar with Hikari? I'm trying to get rid of this warning because it sounds bad.
[15:02:12 WARN]: Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Oh fixed it.
hello, how to auto pull fishing rod when CHAUGHT_ENTITY given?
hello what is the best way to get all players from a server with big amount of players ?
Is there any way to request players with a limit/offset ? Or is it safe to use getOfflinePlayers for a LARGE amount ?
I need to list them in a gui with pagination but maybe using getofflineplayers could be very bad performance
List ALL players that have ever joined your server in a GUI?
yes
Maybe I can use one time getOfflinePlayers and store them myself in a database
what do you think
List of all online players or all players that have joined the server?
It's just nonsensical to me to do that
All players
For some reason he wants all players to be in a GUI. What is the GUI for? @acoustic widget
Well, you can store the data everytime players joined the server
should be fine
maybe look at what it do in craftbukkit
so you can be sure to not open and read the playerdata file everytime
Why isn't my inventory clearing?
https://paste.md-5.net/yazixemiku.java
bruh I forgot, so dumb smh lol
Where can I find sources ?
i just linked it
ty
Any way to get them from idea easily ?
just get them at server start and cache them from there on
why when i try to compile my plugin with gradle, this happens ?
Yes i'll do that. But any way to get bukkit source in Inttelij IDEA instead on spigot website ?
Is there any !!!short!!! small snippet for sending players to another server using bungeeeeecord
onEnable: Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
DataOutputStream out = new DataOutputStream(b);
try
{
out.writeUTF("Connect");
out.writeUTF(server);
}
catch (IOException localIOException) {}
event.getPlayer().sendPluginMessage(this, "BungeeCord", b.toByteArray());````
Trying to pass an instance of my main class to an event listener so I can access my config... Tried searching about a bit but couldn't find what I needed, any pointers?
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
thank you
could be something to do with an api i use?
I'd honestly assume it has to do with a permissions plugin, since you said you were trying to do commands
let me get my holy crystal ball
my holy crystal ball says
that we cant help you without any code which could cause that
but i dont have perms for it
hover over it in your IDE
i mean like, i dont have a set up perm
i mean, is this now a server or dev issue?
no idea lol
i coded the command
so i guess a dev issue
OH SHOOT
i forgot to change executor class
yeah it happens, i sometimes forget how to hack the NASA
the NASA or The NSA
NASA = NSA
I mean...
they left an A
of course
Also can I assume I've done this right, will the event listener work?
public class onBlockBreak implements Listener {
private final Pureores plugin;
private final Collection<Material> blocks = Arrays.asList(new Material[] {});
public onBlockBreak(Pureores plugin) {
this.plugin = plugin;
}
@EventHandler
public void onBreak(BlockBreakEvent event) {
if(blocks.contains(event.getBlock().getType())) {
// Do stuff
}
}
}```
Main class(not the whole thing):
```java
private onBlockBreak BlockBreakEventListener;
onEnable(){
BlockBreakEventListener = new onBlockBreak(this);}
ah ofc
hah the issue is I can't really do that since the rest of the code isn't implemented yet
But I'm gonna charge ahead assuming the impossible: That I did something correctly first try
more or less
the listener looks fine except of new Material[] {}, but why are you making your listener to an instance variable in your main?
also the variable is redundant, you can just directly register it
I want to pass the config so I can access it in that onBlockBreak class, since the Collection there is meant to contain the blocks I want to check for in the if statement
yeah, I was just following what md_5 linked earlier and that's what they did. I've changed it now
any ideas how Notchian server (NMS) generates entity ids on the server?
is it a counter
like inventory ids?
if so, is there any maximum entity id value
since i need to generate entityId which does not collide with server's entityID
EDIT: Found it
**this.as **is a field for entityId in NMS entity class. It uses AtomicInteger to increment value, although it seems no sense to increment it atomically since entityId is a local class field, and the AtomicInteger is not used anywhere apart inside the constructor lol?
this.as = b.incrementAndGet();
atomicInteger object is created inside the class too. what a useless object
is there a way to is there a way to cancel a method when something is true and if not, execute the overridden method from itsself?
Call super ?
You want to explicitly call the child classes version of a method ?
kinda
That is not how inheritance works š
The parents method wouldn't even be called unless you call super in your child's method
So I don't know how you would only partially execute the parent one
hello, are there anyone who do stuff with fishing rod?
hmmm... my father kinda in love with fishing, so can i ask:
- average time you need to get a fish
- why you like it?
- 10-15 minutes (according to water sources)
- i love stop thinking
i mean, i need write a plugin where auto pull the fishing rods, when fish / entity
- Depends on the day, sometimes 20 mins, sometimes 2 hours lol
- Its very nice to chill out
i dont think it is possible to get the player to pull the rod on their side if thats what you mean
Hi I have a problem for settings some values in config :
KnockbackFFA.getInstance().getConfig().set("kits.1.contains", Arrays.stream(playerinventory.getContents()).filter(item -> item != null).toArray());
KnockbackFFA.getInstance().getConfig().set("kits.1.name", args[1]);```
the main problem is actually that the config shows like this :
https://paste.md-5.net/ezibeyaciv.makefile
But i dont want to display - ==: org.bukkit.inventory.ItemStack
but if i try to remove them i could only get the item contents so i cant get the item meta's that easily
what can i do
i see
how
just make a method that read/writes the config to/from an item stack, all you really need is name, stack size, lore, enchants
whats the usecase anyway?
oh
right i need to try that
thanks
- ==: org.bukkit.inventory.ItemStack tells the serializer what the object is. you can;t remove it simply
i think they just want a more readable human version of it
i wanna get this data in another class which is for creating kits
Elgarl is the best, always helpful ^^
you would be better accepting the extra line in teh config than rewriting the majority of a serializer/deserializer
ElgarL stan
hm ok
i mean making your own serializer really isnt that hard
you also have a typo in the lore of yoru knockback stick
you also have a type in your message
Oh wait
fuck
I always do
is it worth disabling the tabcomplete when the sender is the console?
wdym used? i cant see the options
I actually had a request to allow it in console
oh
ik its available in paper
paper..
spigot should really add it too
hmm true would be nice
whats wrong with paper lmfao
isnt tab complete already available in spigot?
console
yes
Wait so does Spigot show the options?
Believe paper has somewhat a more sophisticated variant but yeah
Yeah
Should be in spigot afaimc
I only have that when I click on this method, not the bukkit source
You will have to import NMS and look around in there
Should be called Craft<something>
They come together
I tried developing a plugin but in the console, it tells me to use Version 60 of Java instead of 61, but i dont know how to switch it. I downloaded Java 16 but in IntelliJ it tells ne to use Java 17
i want to try stream.filter
but i dont know what are these exactly called can it even work?
someth like this :
" ));
Arrays.stream(Arrays.stream ) :/
oh uh
!String.equals
Objects::nonNull
i already stopped - 'null'
with Arrays.stream(playerinventory.getContents()).filter(item -> item != null)
Yeah youād be using the method reference instead of that lambda expression
hm ok
Anyways you could also flatMap that stream
btw cant i stop - ==: org.bukkit.inventory.ItemStack
by adding itemstack?
The later predicate always passes
Because a string will never be equal to an ItemStack through an identity comparison
so how can i remove org.bukkit.inventory.ItemStack
Without touching anyother data's
cause i need them
i never seen a plugin configuration file like this :o
So im feeling a bit wierd about this
Yeah well bukkits serializing system adds those - :== class.Class
Itās a way to later tell which class to use for deserialization
so if i want to get these data i may need these too!?
Yeah
oh than i dont think removing it is a good idea
Assuming youāre storing and ItemStack just like that
Yeah wise choice
a temporary itemstack
Some people decide to instead just serialize and deserialize it their own way, not depending on the Bukkit serialization system
So thatās why you might not always encounter that - ==: thing
however thanks for your help and giving some informations about this š
š
Oh is it configuration?
yeah
Ah then you might want to actually serialize it/ deserialize it your own way to make some what more appealing to the end user
i'll probably ignore that for now
cause there are more bugs than that
Yeah, well everything comes at a cost
how do i keep items in an inventory?
what kind of inventory? player? a custom one like a backpack? gui?
gui
you dont store it, you set it ever and ever again
I click on the campfire, put the stuff on, can't you save?
Well, i dont think so.
Store it to set it š
storing a gui which you can't normally change?
I think every gui should be cuztomizeableā¦
I am assuming that at this point here is no configuration that can be adjusted using a config gui
so
he have to set it ever and ever again
and even if he stores it somewhere
he have to set it ever and ever again
except if he saves the inventory somewhere
which he opens for every player
need small help with PrepareItemCraftEvent
?paste
How can i set the executer for a tab completer?
plugin.getCommand(name).setTabcompleter(tabcompleter)
Is there a way to only make part of a message clickable?
I already imported craftbukkit with buildtools
Ie: Click HERE to teleport and only clicking "HERE" will execute the event
https://www.youtube.com/watch?v=FWoYpM-E3EQ this video helped me so much when learning streams, I highly recommend watching it
ComponentBuilder
like thiss
Can anyone tell me why my tree populator only generates trees at y level 60 and close to water?
@Override
public void populate(World world, Random random, Chunk source) {
if (random.nextBoolean()) {
int x = random.nextInt(16);
int z = random.nextInt(16);
int y = 0;
for (y = world.getMaxHeight() - 1; source.getBlock(x, y, z).getType() == Material.AIR; y--);
world.generateTree(source.getBlock(x, y, z).getLocation(), TreeType.BIRCH);
}
}
i know streams but thanks i'll check it
minecraft no longer works, how can i fix it?
I tested with a flat chunk generator and still no trees.
Damn generate tree function needs y + 1
Just seems like you didnāt with the code you sent above my b
wym doesnāt work
help
You have told us nothing, how are we supposed to help 
i downloaded the new launcher, deleting the old one but it says unable to update the native launcher
but before they answer I will have broken the pc
Have you checked the Minecraft discord launcher support channel?
no
Then maybe start there :)
install the older one back
nothing goes anymore, it tells me it is impossible to move the file to another disk drive
Why stream duplicates values in my config file?
something happens in config like this
They're not in the same depth, the first kits is a child section
but they are in the same depth atleast i think?
They're not, notice the 2 spaces before the first one
ohhh
Then find the implementation?
well you'll have to handle all the serialisation logic
or NBTTagCompound is just for vanilla data
it isn't
but you can just use stuff like NBT-API
and worry a bit less about server internals
not using 1.8
bruhh thx im gonna run a bedwars server on 1.17 ooooo
I mean, the PDC implementation is open for you to look at
i would play that
but others wont
their loss i guess
you can simply use some plugins like via rewind
we also have a plugin for that
patch the server yourself for 1.8-like pvp
yes
i was just asking for help about something like pdc in 1.8
so i wont have to use lores
Well, yes you can use the items NBTTagCompound
Why do you need it for a bedwars gamemode in the first place
identifying custom items ?
i just said for example
huh
glhf shipping your own PDC implementation to multiple versions
Then how, i'm asking a fast way to get source from idea when ctrl+left click on method
Hiring Java Developers
hi everyone, i have a very basic question that you will most likely make fun of me for:
how do i use the logger to send a message to the console? currently i just use the sout thing, but every time i do it, it tells me in the console to use the logger.
?services @viscid edge
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
since spigot is just the interface you will have to look it up elsewhere
Plugin.getLogger()
and then .info("hi") right?
It has various methods for sending different level messages
hey, i want to make my plugin work on 1.8-1.17.1 and i want to know, is there any point on making nms support for version like 1.16.1, 1.13.1 and so on?
Probably not
different modules for each nms version
That wasnāt the question
yep, but is there any point of making such modules for version like 1.16.1 or make it only for latest sub-version like 1.16.5?
those versions mostly share a nms version
just like 1.8.8 has 1.8.1_R iirc
i did this in the main class:
getPlugin(this).getLogger().info(ChatColor.translateAlternateColorCodes('&', "hello"));
but (this) has a red line below it
the hello will be changed later btw
Bukkit Version: 1.16.4-R0.1-SNAPSHOT
Bukkit Version: 1.16.5-R0.1-SNAPSHOT
aren't they different? https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-16/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
nvm i just needed to add .getClass()
Yes
just 16.2, 16.3 and 16.4, 16.5 have the same
1.16 has 3 NMS versions
btw can someone tell me if i'm doing this right or not
However hopefully no one is using 1.16.1-4
just swear on them in console if they do
Just donāt add support for them unless people start asking I guess
maybe i dont really know how nms works but spigot says this:
1.16.3 - NMS Version: 1_16_R2
1.16.4 - NMS Version: 1_16_R3
or just fuck 1.16 and go for 1.17 
yes, different nms versions.
so i need different sub modules right?
most likely
OK ty
not sure if you cant just count up xd
but nms changes are so fucked
prob doesnt work
and also, what should i import in pom.xml spigot or bukkit or something else?
Spigot
you need to shade in CraftBukkit ig
spigot doesnt have nms
spigot does
sure?
if i use spigot instead of spigot-api it has
spigot-api does not
oh well then forgot what i said
and ig i should build like 10+ servers to test them working?
Have fun with that
me, yes
strong people*
does anyone know what the label parameter in a command method does?
what alias is used to issue command
the command which was sent in iirc
i'm getting 2 different answers, i'm confused
label is the command/alias as it was typed
i don't understand
cmd is the actual registered command
label is the thing triggered your command executor
command is the command
which belongs to the label
so your command may have alias like gamemode and gm, the label says what alias is used
if you have a command called /test with an alias of /fubar. If you type /fubar, label will say fubar, while cmd will say test
it's not letting me do it in another class
pass a reference of your main class when you create the other class
getPlugin is static method of your main class
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Get plugin is a static method of JavaPlugin actually
dep injection is your option but if you REALLY need to use getPlugin you can use
YourPluginClass.getPlugin(YourPluginClass.class)
JavaPlugin.getPlugin(YourPluginClass.class)
i just read like the first 3 lines of this and i already have no clue what this means
simple words: if you need plugin in your method, require it as parameter, if you need it in your class require it in constructor
will this actually be useful to me in the future? cause right now i can just make a method in the main class with an input parameter that will send the inputed message, and then i can call it from another class
How can I program an event to happen each X minutes?
For example :
every 5 minutes:
set weather clear in world "world"
give all players online 1 diamond
i don't understand
ill explain
?scheduling
skript boi
?
what's skript?
uh this is english lol not skript
yep, skript is mostly english
well this is the first time I coded something without meaning to š
i don't think it will work, but it is probably very close to working
so can anyone explain to me dep injection? i don't even know what it is
1 second
alright
oh and just keep in mind: i'm not going to click on any links that i do not know of, so if you're like making a big expliniation text wall or whatever, don't bother including any links to anything that is not well known
example:
public class SomeClass {
public void registerListenerBAD(Listener listener) {
JavaPlugin plugin = JavaPlugin.getPlugin(YourPluginClass.class);
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
}
public void registerListenerGOOD(Listener listener, JavaPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
}
}
oh nvm i thought you were gonna explain it to me
um i don't really understand what's going on here
in simple words
it means you should not use getPlugin()
you should just take plugin as parameter if you need it in other classes
for example, if you have method, in which you need your plugin's class, you should just ask it as argument in method like:
public void myCoolMethod(JavaPlugin plugin, ...) {}
So if I call this method in the onEnable() method, it should clear the weather each 5 minutes?
public static void repeat(MaxiCity plugin) {
BukkitScheduler scheduler = Bukkit.getScheduler();
scheduler.runTaskTimer(plugin, () -> {
plugin.getServer().getWorld("world").setClearWeatherDuration(99999);
}, 20L * 5L * 60L, 20L * 5L * 60L);
}
actually you shud not use bukkit scheduler
the better option is to use BukkitRunnable
@vale ember what do you think the scheduler runs?
that is better option, AFAIK
they are the same thing
back
i heard people recommending BukkitRunnable instead of BukkitScheduler
BukkitTask and BukkitRunnables are the objects that run on teh Scheduler
aregcraft sorry but i still don't understand, one of the things i don't understand for example is why you should put the plugin as a parameter, and where it's supposed to be called from and where to
like from the main to another class?
just don;t use any deprecated runnables
you should put plugin as parameter when you actually need it
Depends
what parameter? where? when? i don't understand
But BukkitRunnable is more powerful
if in method outside of main class you are doing something that requires plugin, like registering events or scheduling tasks
ok, but how do i get the plugin if i'm not supposed to use getPlugin
just ask it as argument
Do you know what a constructor is?
am i supposed to make a method in the main class that returns this?
Like this?
public static void repeat(MaxiCity plugin) {
new BukkitRunnable() {
@Override
public void run() {
plugin.getServer().getWorld(plugin.getConfig().getString("main_world")).setClearWeatherDuration(99999);
HologramCommand hologram = new HologramCommand(plugin);
hologram.regenerateHolo(plugin);
}
}.runTaskTimer(plugin, 20L * 5L * 60L, 20L * 5L * 60L);
}
yes
if method is in main class you shud use "this", if method is outside, ask plugin as argument, and invoke it from main class, putting as argument "this"
i'm not sure i understand, lemme write some code and send it here to see if i do understand
yep
best option is to use JavaPlugin
this is the class (object/instance) you're writing this in.
"this" is of your main class type which extends JavaPlugin
but it is also extends Plugin, so you may use Plugin
If he is new to coding don't tell him that. He might use this in every class thinking its calling his main.
okay
ok i already have a problem, i can't use this method:
public JavaPlugin getPluginFromMain() {
return this;
}```
this is in the main class btw
why would you even need this
that's what i understood from what you said
also i am sorry that i do not understand this
thats ok
also if you can, please like dumb it down by a lot
public class <SomeMainClass> extends JavaPlugin {
private static <SomeMainClass> instance;
public void onEnable() {
instance = this;
}
public static <SomeMainClass> getInstance() {
return instance;
}
}
This creates a class. It sets an variable named instance which is the class object. onEnable() it will set the instance as this which is the main class. When getInstance() is ran it will return the instance of the main class.
@lean gull
Imagine you have some class (not your main class), and you have some method in it.
That method registering listeners or scheduling tasks, or doing something that requires plugin class.
public void myMethod() {
// doing some task that requires main class
}
Just require plugin's class as argument, like this:
public void myMethod(JavaPlugin plugin) {
// do some task requiring plugin's class via plugin argument
}
And here is how to call it FROM MAIN CLASS:
@Override
public void onEnable() {
MyClass.myMethod(this);
}
what about return this?
i don't understand, sorry
i do not know what an instance is or what an object is, i've tried to google them before to understand but i just couldn't
š
Everything is an object expect for the primitive types int double long float char byte
I think I missed one
last step I need to figure out : detect when a player right clicks on a block
what are primitives :kekw:
short
Object is exactly what the name says... and object that you create.
Instance I can't really explain lol Instance is like your call of the object if that makes sense.
Short, thank you
actually this is called singletone, not dep. injection
i don't get it, areg.
from what i understand, you want me to call a method from another class to main, and then that method will then call yet another method back from main to the other class?
wouldn't that be the same result as what i did
@lean gull show your actual code.
main class: https://paste.md-5.net/fogerasoza.java
other class: https://paste.md-5.net/kenepupenu.java
in other class:
if you doing some job in class other than main, and the job you do requires plugin class, just add "plugin" argument of "JavaPlugin" type to your method, and pass "this" as argument in MAIN class when you call that method
Its not accessible to other classes.
You need to make an instance like I showed above. Or make that method static
it's public?
its not static
this is singletone pattern, you can use it, it's simpler
Public means its accessible by its instance. Static means its accessible by its class call.
what's instance and class call
Class.someMethod() - static method
instead of objectt.someMethod() - not a static method
i don't know what an object is
also, the right way is to make executor class constructor require plugin as argument and than, when you register it in main class, pass "this"
Instance is what i showed you above. You create an instance of the class. Class call is just Class.<method> and then using its methods.
ill make sample
something you make with the new keyword
ok can only 1 person explain to me please? there are currently 3 people talking to me and my brain is just pure confusion
you got all the code, what don't you understand?
this is dep. injection:
Command class: https://paste.md-5.net/ezimidozog.java
And main class:
https://paste.md-5.net/awobayiweg.java
everything. i understand nothing.
?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.
this is how i learn
@lean gull this is right way it's done
sololearn :kekw:
sorry
i use it :kekw:
command class is:https://paste.md-5.net/ezimidozog.java
also you don't need getPluginFromMain method.
what does this.plugin do
it set's plugin field to constructor passed arguemnt
that is required cuz argument and field name is same
player does extends commandsender but not in reverse š
again, i don't understand, sorry
no offense areg, but your english makes it harder to understand
this.plugin is a field
i know, i am not from america, and im still learning english
this. just makes sure that it uses the plugin named variable from this class and not the parameter
right?
yes
yes
ok so from what i understand, when i set the executor for the command it will also set the plugin variable to the plugin until it restarts, but then it also repeats when u start again
is that right?
yes
not getCommand() but setExecutor(new HashMapTest(this))
looks cursed
when constructor called, the plugin field in command class is set
new problem, yay!
if anyone can help that would be great lol
remove "()" after hashMapCommand
ah ok
cuz hashMapCommand is variable, not method
how do i check if a hashmap key is set?
containsKey
Integer.parseInt
many ways
try catch w integer parseint
how do i use parseInt
also there is NumberUtils in apache.commons
Integer.parseInt(#String)
i don't understand, sorry
also please only 1 person help me at a time, my brain can only handle so much lol
but that will throw exception if argument isn't number?
Is there any way to get all unloaded entities of players view range?
and handling exception is slow
int i = -1;
try {
i = Integer.parseInt(args[?]);
} catch (NumberFormatException e)
{
//tell user it isnt a number
return;
}```
they arent unloaded if its in his view range? wut
int i;
try {
i = Integer.parseInt(args[0]); // Number arg
}
catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "That is not a valid number!");
return;
}
// code
imagine i wrote it on phone ez claps
š
š
alright, thank you
handling exceptions is very slow, best option is apache commons
I meant to get the entities that are getting unloaded from player's range
its not that slow
just use parseint
its still a good way to learn
yeah just use it
hmm you might get them listeing to chunk unload
and get entities inside it
better to learn ways than to always use apis i mean
Bennchmarks:
Benchmark Mode Cnt Score Error Units
Benchmarking.usingCoreJava avgt 20 57.241 ± 0.792 ns/op
Benchmarking.usingNumberUtils_isCreatable avgt 20 26.711 ± 1.110 ns/op
Benchmarking.usingNumberUtils_isParsable avgt 20 46.577 ± 1.973 ns/op
Benchmarking.usingRegularExpressions avgt 20 101.580 ± 4.244 ns/op
Benchmarking.usingStringUtils_isNumeric avgt 20 35.885 ± 1.691 ns/op
Benchmarking.usingStringUtils_isNumericSpace avgt 20 31.979 ± 1.393 ns/op
ok werdo
isnt that for server chunk loading
the apache method is the slowest compared to Integer.parseInt
the fastes way would be to check each char manually
"As we can see, the most costly operations are regular expressions. After that is our core Java-based solution."
and no, exception handling is not slow, it just takes a few extra steps
totally fine in his case
*core java is exception handling
there is nothing wrong with parseInt here, and it is not slow
if you were worrying about performance (why?) you'd parse it yourself
what does (NumberFormatException e) do? also can someone tell me what does try and catch do? i'm guessing it try checks if it's possible to do something, and if there's an error, it will not do it and then catch runs? correct me if im wrong
string utils isnumeric literally uses a loop
the only thing being slow in exception handling is the stacktrace. everything else is just normal
i'm also guessing that (NumberFormatException e) is the error that it's looking for?
its basically a critical error that halts your code above. you can handle the error by adding try catch block, without making your program go boom
it catches any exception thrown from whats done in the try block
in this case, when u do a parseint, theres a possibly of a numberformatexception being thrown
i.e. u parse a string with a letter
it will throw a numberformatexception
i don't understand, sorry
dont explain it step by step. go all at once
boom
its hard to type all on phone haha
you're at the wrong place. @lean gull https://www.youtube.com/watch?v=xNVlq9IEBEg
Full Java Course: https://course.alexlorenlee.com/courses/learn-java-fast
If you're new to programming, I HIGHLY RECOMMEND solving challenges on Edabit: https://edabit.com/?ref=alexlee
Get my favorite programming audiobook for free! https://audibletrial.com/alexleefree
20% off Brain.fm (productivity hack): https://www.brain.fm/alexlee20
Get Tabn...
else i'd comment it out
exception handling is good in some cases, but "From this result, we learn that throwing and handling of the NumberFormatException, which occurs in only 5% of the cases, has a relatively big impact on the overall performance. So we can conclude that the optimal solution depends on our expected input."
please only one person help, i cannot read all of this without being confused
thank you
but anyways,
try ->, code to be run. try/catch is great for debugging
catch -> will catch an exception thrown by anything in the try block
use this, and you'll understand @lean gull
some code statements will throw specific exceptions
but u can always just use the (i think superclass?) Exception class
don't understand again, sorry
my code could be dangerous for my application and could stop it when it comes to exceptions. so i try my code and am catching those exceptions, if there are any so it doesn't stop my application.
i don't know how else to explain it on my phone, i'd recommend just watching a video then or awaiting someone else's reply
also you may check https://www.javatpoint.com/try-catch-block
Java try-catch block. Let's see what is try and catch block and how can we write a simple program of exception handling
is_numeric?
is there any way to get players that are in selected player's view range
apart from for looping
isNumeric, isNumericSpace, isParsable, isCreatable is approx same speed
Bukkit.getOnlinePlayers().stream().filter(p -> executor.getLocation().distance(p) <= max).collect()?
uhh probably not then
i was wondering if there's more lighter way to do that
Spawn Player
This packet is sent by the server when a player comes into visible range, not when a player joins.
this seems useful way to get players around, but this could be stale data, if player leaves the visible range and never comes back
Paper has getTrackedPlayers
getCrackedPlayers :kekw:
player.getNearByEntities(radiusX, radiusY, radiusZ);
this loops all of the entities around the radius
it could be costly
especially in mob farms
getTrackedPlayers is great
u use paper?
oh ok
is there anyway that config would saveitself without deleting something?
not just even only comments it also removes some values in the config
currently im using saveConfig();
whats the difference between SomeClass<?> and SomeClass<Object>?
doesnt seem to work with ?
Depends on context. Like, List<Integer> Can be List<?>, but it cant be List<Object>
oh
I'm pretty sure that List<Object> is fine
depends
only generic arrays cause huge problems
like, if you wanna return a List of ints as List<Object> you'd have to convert it
I think List<?> In most cases
how do i check if a command argument is a string?
Its always a string LoL
oh right
hey cuties
Hey Conclure
can you believe that im still stuck in the config file? š
Generics is interesting, because the type Object is not the same as the wildcard, youād need a List<Integer> or a List<? extends Integer> to avoid casting or converting here assuming you work with the type Integer
I cant find the problem that why it duplicates in config file
Sounds intriguing
i have no idea actually that why it duplicates something in config file or it removes some values
?paste
uwu hewwo
owo
please delete this messages
uwu
no ā¤ļø
no ā¤ļø
yesnt ā¤ļø
most certainly not ā¤ļø
Howās it going with the pasting?
wassup @iron palm
im feeling that i knew you before uh but hi
this is probably a bad question, wondering if this will help anyway java Object playerName = res.get("name"); logger.info("Name of " + playerName.toString()); this.server.broadcastMessage(String.format( "<%s%2> %s%s", ChatColor.BLUE, playerName.toString(), ChatColor.RESET, msg.toString())); the log shows a valid name but the broadcast doesnt work and just stops the entire plugin somehow java Object playerName = res.get("name"); logger.info("Name of " + playerName.toString()); this.server.broadcastMessage(String.format( "<%s%2> %s%s", ChatColor.BLUE, playerName.toString(), ChatColor.RESET, msg.toString())); does work for note but playerName is from a different source
how can i get a servers RAM and CPU usage? Atm im using java Runtime r = Runtime.getRuntime(); long memUsed = (r.totalMemory() - r.freeMemory()) / 1048576; But this aint giving me the result i wanthaha
I mean totalMemory should give you precisely what you need
I think you just need to divide it to get MB/GB
do you mby have a example lmao
I've wrotten a command code
but it duplicates the value in the config
the code : https://paste.md-5.net/facoqirora.cs (please dont say where is the } i've cut that in the pastebin)
https://paste.md-5.net/lepakafozo.makefile the config result when you use the command
Runtime.getRuntime().maxMemory() gives max memory
Returns used(max) memory in MB : Runtime « Development Class « Java
take a look at that
ty
I have no idea whats going on and why this is happening
I tried stop using streams but not working
I'll check
totalMemory gives the currently allocated memory
and usedMemory gives you the used memory
im after the ram thats being used so like if i have server with 6gb of ram but only 2 is being used i want just the 2 to show
sounds plausible
Send the config also
usedMemory aint a thing
Oh yeah my bad
is that the ENTIRE config or a snippet?
freeMemory
snippet tho
But you can use freeMemory and totalMemory to calculate used memory
I don't exactly see the issue
uhh
is it possible to send the whole config
instead of a snippet
What is the duplicate there?
yea
???
LMAO
what kind of response is that
'1':
name: ''
contains:
- null
- null
- null
- null
icon: IRON_SWORD
'2':
name: ''
'3':
name: ''
'4':
name: ''
kits:
'1':
contains:
- ==: org.bukkit.inventory.ItemStack
v: 2586
type: STICK
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"aqua","text":"Knocbkack
Stick"}],"text":""}'
and ...
kits.1 is duplicated
Theyāre at different levels tho
But yeah their content seems to be duplicated Ig?
and i have no idea why
Well
the 1st kits is inside "scoreboard"?
^
nope
yes it is
yes
yea..
lmao
LMFAO
Whats wrong with incrementing?
alr
this problem made me thinking and checking codes for many hours wtf
no, not really
loll
How can i change the name of a player above his head?
You May do for(int i = 0;...) loop tho
You could set the size of the array list you create to the size of the map or top or whatever that is
Like on instantiation
(:
(:
?
player.setDisplayName(""); ?
btw you need to get the player before that i think
why does this happen? I have a random int (Bound 100) and i have set up chances like this:
int random = ThreadLocalRandom.current().nextInt(100);
if (random <= 5) {
// do that and that
} else if (random <=15) {
// do that and that
} else if (random <=80) {
// do that and that
} else {
Bukkit.broadcastMessage("Something went wrong. How the hell?")
}
doesnt work with me too
i saw this
Send the following
PacketPlayOutPlayerInfo with action REMOVE_PLAYER
PacketPlayOutPlayerInfo with action ADD_PLAYER with a different name
PacketPlayOutDestroyEntity to all players except you
PacketPlayOutNamedEntitySpawn to all players except you
i also saw this
GameProfile pprofile = craftPlayer.getProfile();
Field ff = pprofile.getClass().getDeclaredField("name");//don't change here
ff.setAccessible(true);
ff.set(pprofile, //name here);
i saw alot š
so i did some digging, and it just left out the number 95
how do i set a variable that i can later use but that will delete itself on restart?
looks like it excepts 85-100
Anything over 80 will run the broadcast
That has 16 characters limit and thats a plain string not component tho
Same with playerinfo packet
You should use a WeightedRandom impl of some sort
currently your "something went wrong" is getting triggered by anything above 80
yes
could i just put else if (random < 80)
that doesnt change anything except it will not take 80 aswell
what are you even trying to do
why this isnt working
I mean am i wrong in usage of stream?
KnockbackFFA.getInstance().getConfig().set("kits.1.contains", Arrays.stream( playerinventory.getContents()).filter(Objects::nonNull).toArray());
But the output :
'1':
name: test
contains: []```
here is an explenation in a nutshell
Math.random would be the same aswell
oh wait
since its the same
there is no explaination
by setting chances
so for example: 10% chance for diamonds, 5% chance for emeralds and so on
but here i have 3 items
seems weird seeing god here
item1
item2
item3
5% chance to get item1
15% chance to get item2
80% chance to get item3
hopefully you prayed
does this explain well enough?
but you know that your second item just will have a chance of 10% and your third item just a chance of 65% for now?
So you want < 5, < 5 + 15 (20), and less than 5 + 15 + 80 (100)
Bukkit.getBanList.addBan
you gotta kick them tho
Correct
player.ban(String) I think
playerkickevent
Bukkit.getPlayer(player.getName()).kickPlayer("§cyou got kicked!");
Why tf you need getPlayer
heh
oops
is there any replace method for filter?
i cant use it for a list of values :(
Bukkit.getPlayer(Bukkit.getPlayer(player.getUniqueId()).getName()).getPlayer().getPlayer().kickPlayer("Banana");
Best code
Best part of that code is "Banana"
getLocalizedName doesnt take a parameter
Also several things there could be null
Hm? replaceIf?
Actually just one, itemmeta
you could use #map
stream.filter?
yee
whats the xy
cant use it for list of things
hashmaps?!
list.stream()
list.stream.filter
can I do
(Player) commandSender
yes but you should check before if the commandSender is a Player
ah yes obviously, thanks
EntityDamageByEntityEvent
block break
?scheduling
OMG You Read my mind
I was about to ask does anyone already creating squid game plugin or not
there are several already