#help-development
1 messages · Page 2028 of 1
you will have to translate the string using ChatColor.translateAlternativeColorCodes()
iirc
do + "" because you cant concat enum constants
or just .toString() one
also possible
so add a "" in between?
can the console output rgb?
ye or to string
oh ok
this should fade from aqua to green but idk if im doing something wrong
or that the console just doesnt support rgb
but im pretty sure it does because i tested it
once
Hey, I have a question real quick, what is the difference between:
new BukkitRunnable() {
@Override
public void run() {
//Code here
}
}.runTaskTimer(this, 0L, 20L);```
and:
```java
Bukkit.getScheduler().runTaskTimer(this, () -> {
//Code here
}, 0L, 20L);```
Not any thing Else?
im pretty sure it does the exact same thing
So no difference?
Oh ok thanks for your answer
nothing
you can do BukkitRunnable r = new BukkitRunnable() { bla bla}
if you need it somewhere or smth
but the non deprecated scheduler method return a bukkittask too iirc
You mean if I need to access it to cancel it or something somewhere else?
ye
Ah thanks
not sure what u mean
I have seen youtubers do the same i think and it don,t work so its not more on the Line than that?
ChatColor.translateAlternateColors translates string like "&cNO" to a red colored string "NO"
fancy
i just need to fix my gradient function
well yea you have to input a char to translate and a string to translate
for example ChatColor#translateAlternativeColorCodes('&', "&1My Cool String")
does this look good or trippy
the C should get a gradient
but im tired so ill fix that tomorrow
?scheduling what fourteen said is true but I believe a comparison is done in that wiki page
i need lib ideas
Make a pub sub lib
what
With implementations like redis, rabbitmq, mysql or just server sockets
Or even plugin message channels
literally nothing
There is tho
its a functional interface that has only one abstract method
so u can use a lambda instead
wait whatg
How can I assign a variable that I have given an object as a parameter as scanner.next in the scanner?
I have an object as parameter
Mind sharing the code?
public void Racing(Car car1, Car car2) {
System.out.print("First Car: ");
!!!! //car1 = scanner.nextLine();
System.out.println("Second Car: ");
!!!! //car2 = scanner.nextLine();
}```
BufferedReader better afaik
String car1 = scanner.nextLine();
i already defined the car1 in parameter
Remove that
In other words you can’t cast a car to a string. Your IDE should pick that up and tell you, then you can read the advice.
how to make an event listener without using any annotations (@EventHandler) or any kind
I need to do that because my interactive debugger doesn't support annotations
but
listener argument
must be an EventListener class
which, I assume, will only listen to annotated events no?
dunno
just use new Listener() {}
what are the formulas for a linear gradient from the top left to the bottom right?
the x and y are floats from 0 to 1, start to end respectively
How to make a mob move to a location in 1.17.1 using NMS
you are inputting texts on methods
your formal function arguments
in that very function you gave us, you dont use those
so they can be removed in principle
im using
...
im not using types on that function but i will use it in main method.
Ah i did
just made String types and equal it to Car type by valueOf
I still dont get your issue here,
Scanner::nextLine returns a String, and since you seem to unable to drop the formal function arguments, you'd either have to use different names for the variables, or mutate the formal function argument and assign them to new Car instances, or just get rid of the formal function arguments.
how would i interpolate like this
i already have an interpolation function to get the color inbetween two others based on a given point (float)
could look at sth like minimessage
but i need to figure out the points in each cell
i dont know where to find it
link?
In adventure GitHub repo iirc
What is the event when you right click on an item?
@glossy venture
PlayerInteractEvent
PlayerInteractEvent
Oh thanks
ah but thats 1d
i already did that
im trying to do it on a grid
Oh
daaamn that's pretty
lets goo it was worth it
Yeah that looks scrumptious
event.getDrops().removeIf(items -> items.containsEnchantment(Enchantment.DAMAGE_ALL)); I wrote this code that makes sure that all objects that have sharpness are not dropped, how can I make all objects with sharpness 4 not be dropped?
Check for the level of the enchantment too
declaration: package: org.bukkit.inventory.meta, interface: ItemMeta
How can I do? I don't know how to do much
returns 0 if enchantment not found
Can you show me a code please?
i just told you what to use?
We're not going to spoonfeed something that simple ^^'
Yes, but I don't know how to use it, have recently been using java 😦 ahahah
well, almost exactly the same as what you have rn
except you need to use the method i send
anyone know how to enable and disable a specific players ability to PVP
Save player UUID to a Set and then when someone gets hit check if the player is in the set and cancel if so
what is a Set
or nvm I think I get what u saying
java.lang.NullPointerException: Cannot invoke "net.minecraft.nbt.NBTBase.a()" because "var1" is null
any solution?
:>
tryng to serialize an item with ItemStack.serialize
create a List<UUID>, this must contains player uuids, then, create a EntityDamageByEntityEvent listener
aright
Better use a Set like Olivo said
in that, check if listener.getDamager().getUUID() is contained in your Set
if it is, its ok, if its not, then cancell the event
same thing
kinda
then
oh I see, I see
that every entity has
no prob
btw anyone has a solution?
so does this make any sense ```public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
boolean playerCanAttack = false;
for(int i = 0; i < Join.players.size(); i++){
if(Join.players.get(i) == event.getDamager()){
playerCanAttack = true;
}
}
if(playerCanAttack == false){
event.setCancelled(true);
}
}```
Join.players is the arraylist
wdym
like players is the array list
and it is found in class Join
players that can attack
can be enchanced
how, should I change it
first, use for(Player player : Join.players)
and ofc use player instead of Join.players.get(i) then
why for each loop instead
because you can use less code
its all about making code easier to understand and make it less big possible
i see
there is also another thing
?
actually
:0
i see
and you could also remove the boolean
just do event.setCancelled(!Join.players.contains(e.getDamager()))
its the opposite
.-.
i wanted to explain him step by step xDD
that's why i just didn't give him the code
btw
ZeTioZ
do you have any solution?
I mean, sure, but here there is a lack of java knowledge ^^'
dang u cant posts gifs
yeah i know, that's why i wanted him to understand instead of copy-paste the code
btw, petarpotato i see you're still learning, keep going
🙂
could you post the code ?
And, you should use mojang mapping instead of original one
way easier when dealing with nms
its actually just a ItemStack.serialize of an already created itemstack
not much to copy xD
Oh
I would look at the get() that could be null here
it is not
or maybe the ItemStack serialization got broky
yep
i though that too, cuz the error comes directly from nbt called from bukkit serialization
what can i do?
i'll try
and then you decode when needed
Thanks!
yw
what does that mean? XD i'm italian
your welcome ^^
ofc, you need to encode it by bytes, so don't just encode the object itself
yeah, but the only issue now would be, converting savings now... xD
since now all the save files of my users are saved with itemstack.serialize and decoded with itemStack.deserialize, will be difficult
to convert everything
that's why i hoped there was an easier way
you can chug the serialized data
and convert to b64
it will give you the same result
like get them all from the file
since the serialization is what you convert anyway in b64
that's surely helps, thanks again
no problems ^^
well, it's better to save encoded items in database, takes less space and it's consistent ^^
wdym with database?
btw is this what you meant:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream bukkitObjectOutputStream = new BukkitObjectOutputStream(byteArrayOutputStream);
bukkitObjectOutputStream.writeObject(paramItemStack);
bukkitObjectOutputStream.close();
something like that
and then convert to b64 these bytes?
yeah
if (!(sender instanceof Player)){
sender.sendMessage("Only players can run this command");
}else if (!(sender.isOp())){
sender.sendMessage("You don't have the permissions to run this command");
}else{
sender.sendMessage("you are a player and you are op");
}
this looks messy is there a way to make this look better?
looks like something like that
ok, thanks again for the help
remove the else, that's the only thing you can really change
(and ofc you add returns to avoid going off the branchs)
does anyone know if there is a way to select a large area and make it air
by code ?
Take two points, loop through the x and y change the blocks through your loops
no wait wrong message xDDD
is there no other way or is this the only solution
That's pretty much the only solution
like can I just get all blocks inbetween two coords to become air
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can run this command");
return;
}
if (!(sender.isOp())){
sender.sendMessage("You don't have the permissions to run this command");
}else{
sender.sendMessage("you are a player and you are op");
}
That's exactly what I said
only thing i see can be done
dang
yeah it is
if (!(sender instanceof Player)){
sender.sendMessage("Only players can run this command");
return true;
}else if (!(sender.isOp())){
sender.sendMessage("You don't have the permissions to run this command");
return true;
}else{
sender.sendMessage("you are a player and you are op");
}
this is what i have dis good?
you coudl remove the else now
since there are returns
if (!(sender instanceof Player)){
sender.sendMessage("Only players can run this command");
return true;
}
if (!(sender.isOp())){
sender.sendMessage("You don't have the permissions to run this command");
}else{
sender.sendMessage("you are a player and you are op");
}
wheres the else for if the senders not a player?
ohh ok
return stops the function
what the dif between your code and mine?
remove the last else x) not needed
pretty much no difference
ok
do i need return or return true whats the diff
depends
anyone know how to make a specific block turn into air
It compiles down to a raw nested if else
if you have a void there is return, if you have boolean there is return false and true
So pretty much no difference apart from readability
ok
block.setType(Material.AIR)
danke
but just for a speicfic location
wdym?
does anyone know what i cant generate a getter and setter method? im using intelliJ and i used to be able tot do it
i'm italian so i don't understand much
so like block x,y,z = air
right click -> generate -> getter and setter
oh
then Location loc = new Location(world, x, y, z)
loc.getBlock().setType(Material.AIR)
How can I check if a player right clicked on a certain item using PlayerInteractEvent?
have a nice day bye
on a certain item?
yes
you mean With a certain item or on a certain block?
I have created the itemstack already
I mean if they right clicked a certain item
basically interacted with the item
so like if they click on a diamond block
oh interacted with the item like they use flint and steel
no lol
Just get the item in main hand
I need to check if they right clicked the item
Player#getInventory()$getItemInMainHand()
check interactEvent.getAction() == Action.RIGHT_CLICK_AIR
and doing this check
When the action is right click air or right click block
Yeah, that's what the "or" do
alr
wait wdym
interactEvent.getAction() == Action.RIGHT_CLICK_AIR || interactEvent.getAction() == Action.RIGHT_CLICK_BLOCK
oh wait
if(e.getAction() == Action.RIGHT_CLICK_AIR) or (e.getAction() == Action.RIGHT_CLICK_BLOCK)
xD
or = || in java
Well you can't x)
you need to use ||
Inventory tpGUI = Bukkit.createInventory(, 9, "Teleport GUI");
what do i set the holder as?
i was trying to make a teloport gui, if i set it to null would i stilll be able to do a click event?>
yeah you would
anyone know whats wrong with this code
boolean playerCanPlaceBlock = false;
for(int i = 0; i < Join.players.size(); i++){
if(Join.players.get(i) == event.getPlayer()){
playerCanPlaceBlock = true;
}
}
if(playerCanPlaceBlock == false || Join.isGameRunning == false){
event.setCancelled(true);
}
}```
trying to dissable a players ability to place a block
use UUIDs instead of referencing the player
you can also just use .contains
and idk the context but this is probs static abuse
is there any reason for Join.players to be static
idk how
ArrayList<UUID>
yeah should be
dang
getServer().getPluginManager().registerEvents(this, this);
is that listener in the main class?
yes
very strange
I have not checked
I will try
I got that
server is loading
how can i see what then name of a opened inventory is with InventoryOpenEvent?
use the InventoryView class
class?
are you checking name to handling clicking?
if so theres way better ways of doing that
i want to get the name of a chest and if the chest name is give then i want it to fill up with netherite
Player#getInventoryView()$getTitle()
can you show your entire class
did you registered the event in your main class?
sure one sec
where can I paste code
?paste
to long here
then yes
paste it, press save then send the link
that is link
probably in the same package
its a diffrent class
doesnt need to be imported
and I am just using it to acess the arraylist found in the class
Oh, weird structure x)
they're new let him be
🙂
doesent @ just tell the dev u are overide something
I never knew it actually did anything to code
I thought it was like a comment
but
nah it can actually have functionality
its more so for when the event manager scrapes through your code it sees "oh this function handles events, im gonna register it"
aright, cool
But yeah i'd really recommend looking into changing the players arraylist to a uuid arraylist
having a collection of players can cause mem leaks
uuid is just their unique identifier
how do i get a list of all online players and there names?
getPlayer().getUniqueId()
Bukkit.getOnlinePlayers()
then iterate through that and get their name
like if we had ArrayList<UUID> something = new ArrayList<UUID>(); would I do something.get(0).getPlayer(); if there was a player in the 0 index
oh you want to get a palyer from uuid?
Bukkit.getPlayer(UUID)
ok
List<UUID> playerUUIDs = new ArrayList<>();
//Adding a player to the list
playerUUIDs.add(player.getUniqueID());
//getting a player from the list
Player myPlayer = Bukkit.getPlayer(playerUUIDs.get(0));
//Check if a player is in the list
boolean isInList = playerUUIDs.contains(player.getUniqueID());
you're basically doing the same thing as you were before but using the UUID instead of the player object itself
Because of the cross-region Minecraft server, I want to cluster Minecraft server through bungee core, but it seems that bungee core is not based on redirection but proxy, I am not sure about this problem, with doubts, I read bungee core once Part of the code seems to be based on the fact that the proxy is so, all the traffic from the client needs to go through the bungee core to reach the server, just like the relationship between the reverse proxy on nginx and 301 / 302 / 303 redirection, like this The process will cause significant delays. Is there a way to make bungee core redirect the client directly to the server without going through bungee core? Or am I overlooking something...
My English is not very good, please forgive me if there are any grammar mistakes.
Is there any way to convert a bukkit entity back into a custom entity? I know I can use getHandle(), but I can't convert it back into a custom entity with casting it
bungee is purely a proxy i dont think theres any way to actually bypass that. the delay is negligible though and iirc you can have multiple proxies, so just have region based proxies
additionally having a proxy means you don't have to expose the port which makes life much easier
If there is a local server cluster, the delay may be negligible, but if the two regions are separated by thousands of miles, this delay will become unacceptable... So is it true that bungee core cannot achieve this requirement? Are there other alternatives?
as for minecraft solutions i havent heard of any but i would recommend looking into BGP (Border gateway protocol) i've heard that can help. If you have the development team for it you could also try and fork bungee and see what options you have but again multiple proxies is probably your easiest option
then you could set up a load balancer which sends them to the appropriate proxy based off of latency or something
but this is pretty hard to achieve
In fact, if the bungee core host suffers a network attack, all sub-server players will be offline. I imagine a redirection portal that accepts the client and forwards it to the verification server for verification and shares the verification result with other servers and then redirects to the game server. , is a redirect instead of a proxy. This makes it possible to deploy multiple servers across regions.
When i used to own a multi server network i just used kubernetes to instance the servers, afaik ping wasn't really a big issue but then again we really only had players from the us, australia and parts of europe and asia
ok i'll try to research, thank you
no worries, its quite a complex topic but there are a few solutions
I'm trying to call public void openCratesMenuGui(Player player, InventoryClickEvent e) in a different class but when I do Class openCratesMenuGui = new Class().openCratesMenuGui(player, ); I don't know what to put in the 2nd parameter
I called the class CratesSystem
is CratesSystem already instantiated?
because it's an event
no
I think you're confusing yourself a bit
I am
CratesSystem cratesSystem = new CratesSystem();
cratesSystem.openCratesMenuGui(player);
you shouldn't need to take the event in
you're not doing and event handling
just remove that parameter all together
openCratesMenuGui is event handling
public void openCratesMenuGui(Player player, InventoryClickEvent e)```
and I use inventoryclickevent inside the openCratesMenuGui
you should have 1 function for openCratesMenuGui and another function for cratesMenuClickEvent
logically speaking how you are doing it won't work
and cant work actually
oh
Can i see what you are doing in openCratesMenuGui
so I have to make some variables global then I think
show the whole function
?paste
i can read it lol
show your code, theres different ways of doing it depending on how you're executing it
this.cancel() should work
let me read up one min
oh try using BukkitRunnable
@drowsy helm nvm I'ma need help
yes
okay so first off I'd start by splitting that into 5 different functions
for each inventory
should I make the inventory variables global?
I just found a load balancing solution: redis bungee https://github.com/ProxioDev/RedisBungee , have you heard about it?
yeah redis bungee hasnt been updated in years
maybe they've started working on it again idk
so instead you can just use a HashMap of Inventory,UUID then map it whenever a player opens an inventory and whenever a player closes one
you could make them global but its not really good practice
https://paste.md-5.net/iquwozefix.css
51: EnchantmentStorageMeta metaH = (EnchantmentStorageMeta)h.getItemMeta();
idk how hashmaps work lol
yeah just use global variables then lol
alr lol
show all your code
and pls dont use 1 letter variables
i will stop but this is just a small project
wait but then when I'm calling the void, will it not know what the variables are?
bcuz the variables are outside of the void
no, if its declared outside of a variable you can access it in side the function
oh
is that
just
the reason
cuz it was working before
i just added more recipes
idk i dont work with EnchantmentStorageMeta, but you don't need to do it in the first place anyway
i did
i tried with doing addenchantment and it said that it was in between 1 and 4
i got an error
wdym
on itemStack
declaration: package: org.bukkit.inventory, class: ItemStack
This method is unsafe and will ignore level restrictions or item type. Use at your own discretion.
did you do addEnchantment or addUnsafeEnchantment?
and that still didnt work?
ok so i just had 1 recipe
i had 1 recipe and it worked i copied it and pasted more it doesnt anymore
what is something?
even tjough i changed the variables
so h works but the rest dont
none work because it errored
you're confusing me, so when you used ItemStack#addUnsafeEnchant it stopped work or when you used the item meta way?
no
nop
so
i have
i had
addenchantments
and it didnt work
then i used
unsafeenchantments
it worked
and
i copied the recipe
changed it a little
and pasted it
and changed the variables
wait im stupid i forgot to change something
It seems that this will not be the final solution, because the traffic will still go through the entry bungeecord. From what I understand, when the bungee cord changes the subserver, the client's response is to change a dimension (world), so the bungee cord and the client The established connection is unbreakable, once cut means leaving the game... And my idea is to send a login packet to the client through bungee cord, so that the client mistakenly thinks that it is entering the server and according to the bungee cord data packet After entering the designated new server, the subsequent data will only be processed on the new server without going through the bungee cord. Is it possible to achieve such a requirement without the help of forge/fabric?
The context is the problem: if the implementation of bungee cord is similar to 301 / 302 jump in nginx, avoid the network delay caused by the physical distance between bungee cord and the actual game server, the reason for using bungee cord is because there are many ingress connections to implement game server
My English is not very good, I try to make the questions as clear as possible, which makes them seem a bit long...and excuse me.
😋
I am trying to figure out why when I use a sword with an enchant on it I get a null error even though it should just pass on through. If you can explain to me what I am missing I would appreciate it ```java
public void EntityDamage(EntityDamageByEntityEvent event) {
if (!(Objects.requireNonNull(((Player) event.getDamager()).getPlayer()).getInventory().getItemInMainHand().hasItemMeta())) return;
//rest of my code
}
I found the issue that I was checking with the wrong stuff
Thanks for trying to help though
I don't see any obvious reason for it to have been deprecated. It's been deprecated literally since it was added in 2014
I'd say it's probably just to encourage you to use Bungee's scheduler instead
Yeah that's what I mean. Not meant for use outside of internal calls but it's a way to associate tasks with a plugin
So make use of Bungee's scheduler. Consider that deprecated method as internal
how in all is godly do i make ui like this
Realistically, it should be marked as @ApiStatus.Internal from Jetbrains' annotations
It's quite simple
3D models as items placed inside interfaces
many of them use a special font to create the background, and the dynamic parts are done with the custom models
well that seems complicated
also weird question: can i compile a server resouce pack
AKA decrypt it
havent updated the code but exactly the same concept
I’m genuinely surprised this was a trade secret, I had been doing this before it even went mainstream at all. None of my projects went anywhere but the ground though lol
how lol
What file format is it again
are you asking if you can download a server's resource pack?
Correct, and view its contents
If I remember correctly 7zip can extract those files
idk but if you want Origin Realms' you can download it anywhere
there isa folder in your %appdata%
What
It’s in .minecraft in the serverresourcepacks folder
well that screenshot is from OR so i was assuming thats what you wanted
yes
resource packs are not designed to be hidden o.O
Hello! Please tell me how to put a mob on the player's head using protocolLib.
Can someone tell me what's wrong because whenever I load the server it console it says it enables my plugin(one is plugins.yml and the other is the main class)
and what's the issue with that
the server doesn't recognize what the commands are when I do them
they're not indented properly
notice how the first command is indented but the others arent
the first command doesn't work either
ok well fix the issue i just pointed out
theres this plugin i relally want,its meant for 1.13 when Im on 1.18 it loads into /plugins, but it doesnt work and console goes crazy when health updates (low health screen plugin) is there a way to make it work?
anyone know how to change the experience gained from killing a mob
Pay someone to port it or ask the original dev if they can
do you know other health plugins that mess with the player screen when getting hurt / or low? 1.18
This isn't exactly the place to ask. This is for development help not a plugin search service
Tell me the packet that allows the mob to land on the player (ProtocolLib)
i could take a look, but cant promise anything
Will FileConfiguration#getStringList work for an array?
aliases: ["dc"]
how can i prevent chest loots to generate tools with enchantments?
i checked loottables on doc but i couldnt find how to remove an item from it
yes, that's what it means
btw u dont need the quotes
I didn't know it worked with an array too, I always used it just for this:
output:
- "&6Our &6&lDiscord&r&6 Server:"
- "&6https://discord.gg/spigotmc"
Thank you!
Ohhh
can i run code at normal onEnable time (post-world) from a plugin with
load: STARTUP
something like
// called on startup due to flag in plugin.yml
public void onEnable() {
// run code that is supposed to run here
// ...
// run code at normal onEnable time
Bukkit.runPostWorld(() -> {
// ...
});
}
i know that Bukkkit.runPostWorld being a thing is very unrealistic
try waiting a tick
maaaaaybe 🧐
declaration: package: org.bukkit.event.world, class: WorldLoadEvent
@glossy venture
ay thanks
illlook into it
declaration: package: org.bukkit.event.server, class: PluginEnableEvent
i found this
i might be able to use that to run the code
just when a plugin has been enabled, i run it right after
thats not reliable
@EventHandler
public void tryFullInit(PluginEnableEvent event) {
if (event.getPlugin().getDescription().getLoad() == PluginLoadOrder.STARTUP) return;
initialize();
}
what if there are no plugins?
if there are no other plugins
yeah
you know what ill just use the scheduler to make it run later
ez
is spigot the same as paper plugin?
for paper servers I always created spigot plugins, but what if I use paper instead, is code the same?
Code isn’t the same, paper is a fork of spigot
It will mostly be the same except for the things paper changes
You can use a spigot plugin with paper but if you use paper to make a plugin only paper servers can use it
Unless you use something from paper which is why I said it will mostly be the same
But not exactly the same
how would you name something that splits an array of elements into pages of elements?
Correct or not, you probably shouldn’t be using a fork of spigot to be making spigot plugins
Pagination...stuff
paginate
PaginatedCollection
Why else would you use paper instead of spigot?
I was having Paginator
public void tpjoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Location loc = new Location(Bukkit.getWorld("lobby"), 1, 64, 0, 0, 0);
player.teleport(loc);
}```
what's wrong with this?
sounds like a villain
you tell us. what doesnt work?
the event doesn't work
probably the teleport. do it on the next tick
Are you registering the event
no one shall have more than pageSize elements >:) @hybrid spoke
yep i do
with scheduler?
yes
aight lemme test
and whats your solution goal?
the code?
^
either you do some docs or your compile method needs a more descriptive name
the name seems pretty descriptive
oh and a int getPageOfElement(T element) would be cool
it compiles the array into pages
and/or hasElement
and/or hasPageElement(int, T)
well, more or less. i wouldn't understand the purpose without looking at the code
also i would try to avoid null.
it's internal most of it
the only thing left is from get page but it's annotated with nullable
even if its internal i would avoid null
it's very difficult then to update the pagination with new elements
if i pre instance the pages
you don't do anything else than wrapping Arrays.copyOf(objects, objects.length, sample) in an optional
hm.. which would need a little rework since you cant just pass in an array
i don't like that much that class
but other developers and your systems do
except that it's a bad design. else you could also return a static empty array everytime
but i don't like initializing objects for no good reason
thats a pretty good reason
other than to be safe
or rather to prevent others from doing mistakes
except if you get it returned
okay, well. lets see the scenarios
public void doSomeStuffWithMyPage(Pagination<Object> pagionation) {
Object[] myPage = pagination.getPage(2);
// is it there? is it not? we have to check! otherwise possible circumstances
if(myPage == null) return; // can't do further actions here anymore
for(....) {...}
}
// but with returning a once initialized static array (**global context**) you won't have thoes problems
public void doSomeStuffWithMyPage(Pagination<Object> pagionation) {
Object[] myPage = pagination.getPage(2);
for(....) {...} // it could be empty but who cares
}
@hybrid spoke there you go https://paste.md-5.net/mabubumoti.java
you don't want to create a new object everytime
hence i said static array. a class variable
so get a static Object array?
i can at worst have one at the constructor
a static object array will fail casting if that is what you mean
for what casting?
if i need a T[] array
casting Object[] to T[] will fail casting
they are not of the same type
https://paste.md-5.net/aqigoyibuv.java i think you mean this
yes and that should work. but still dont know what the purpose of sample is
is to know at runtime what type of array i need
you know java has type erasure
there's no other way to work with arrays and generic
all of this has to be blamed on backwards compatibility and the bad decision of making arrays covariants
who ghost pinged >.<
you need reflection for this
one second, I'll send my code to create generic arrays
i've actually looked and i haven't found anything good
package de.jeff_media.jefflib;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Array manipulation related methods
*/
@UtilityClass
public class ArrayUtils {
/**
* Returns a new array of the given class type with length 0
* @param componentType Class of the array's component type
* @param <T> Array's component type
* @return Array of the given class type with length 0
*/
public static <T> T[] createArray(@NotNull final Class<T> componentType) {
return createArray(componentType, 0);
}
/**
* Returns a new array of the given class type with the given length
* @param componentType Class of the array's component type
* @param <T> Array's component type
* @param length Array's length
* @return Array of the given class type with the given length
*/
public static <T> T[] createArray(@NotNull final Class<T> componentType, final int length) {
//noinspection unchecked
return (T[]) Array.newInstance(componentType, length);
}
@lilac dagger
is it really that bad with generic arrays?
ah yes, i know of this already
i was actually looking into this
but i don't wanna make a util to just skip the inspection warning
why can't I make 1.18.2 plugin with intellij's minecraft plguin:
what warning?
update it
can you choose it?
or just manually change the value in your pom.xml or build.gradle to 1.18.2
I use maven
that only applies to that one statement
then change 1.18.1 to 1.18.2 in your pom.xml
there is no other way to create a generic array and as said, you can suppress the warning just for this statement so where's the problem?
I'm so sorry... try reading what I sent after that again
if i change <version> in pom.xml from 1.17.1 to 1.18.1 does it mean plugin will work on 1.18.1?
usually if your plugin works on 1.17.1 it works on 1.18.1
so i just need to change <version>?
like that? ```xml
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
ye
you shouldnt even need to change the version
ok
I think if you change the version it wont work on 1.17 anymore
lower version is better imo since the plugin will work on more versions overall
@tender shard this is the best i could think of
is that ok in plugin.yml: api-version: 1.18 in 1.18.2 plugin
then it will def. not work on <1.18 anymore
but yeah
you can of course just an Object[] and cast all it's content objects
https://www.spigotmc.org/threads/world-biome.550452/#post-4382359
anyone can help me?
what do you think about my genius exception name?
try {
final StateFlag allowFlag = new StateFlag("allow-angelchest", true);
registry.register(allowFlag);
FLAG_ALLOW_ANGELCHEST = allowFlag;
} catch (final Exception weDontUseflagConflictExceptionBecauseItThrowsNoClassDefFoundErrorWhenWorldGuardIsNotInstalled) {
final Flag<?> existing = registry.get("allow-angelchest");
if (existing instanceof StateFlag) {
FLAG_ALLOW_ANGELCHEST = (StateFlag) existing;
} else {
main.getLogger().warning("Could not register WorldGuard flag \"allow-angelchest\"");
}
}
thanks!
but stateFlag and all those other worldguard classes will throw before it anyway so
nope they're wrapper classes I've written
my whole worldguard code is a bit weird lol
it's not an actual WorldGuard StateFlag but my custom one
oh
I wish it would be easier to support WorldGuard without needing to wrap all the code in case worldguard is not installed
basically a WorldGuardAPI that does what it tells you to or just silently fails/does nothing when WG is not installed
is worldedit open-source, I wanna manually update it to 1.18.2
what is that?
fast async world edit
faster and up to date version of world edit
i believe it also has more features
I can use it if it's not virus
yes i believe
wow it actually works
FastAsyncWorldEdit officially supports the Spigot and *Paper (recommended)
just use the worldedit snapshot builds
it works fine on 1.18.2
WorldEdit Builds. Build #6141 for WorldEdit version/7.2.x. Download test builds at EngineHub.
bdw
I wanna get unbanned from enginehub discord
I was banned because I didn't talk in off-topic
they ban you for that? lol
Doubt that
I doubt that was the reason
no joke
I asked intellij vs eclipse
and he said so ban then?
if it was really like that, they're jerks
you can actually see that
Well, that topic is banned in many discords
Plus it is possible that they have a tyrannical mod
Spigot is extremely lax in moderation stuff
Why use this when you can extract jar files using 7zip
can u say if they can ban me they don't even have ban appeals lol
wdym lol
no
Extracting the .jar with 7zip gives you the files in the extracted folder
Which jar though?
Any
so instead of downloading a proper worldedit version, I should just extract a random .jar and then I have a working worldedit version?
black magic yo
Extract, change what's inside, zip it, change to .jar
are you drunk or sth?
Probs
k
maybe both
Perhaps
Essentials
Just do //wand
And change the whole house to tnt
Or download a Nuke mod
Plugin
Worldedit probably works, yes
summon a few explosions
Or /summon creeper ~ ~ ~ {ExplosionRadius:120}
AH
radius 120?
Any higher is nothing
It will Not instantly explode though
2.5 secs is fast enough for me
Just go onto the house
Not in
It's that strong
Summon a million
And an Obsidian House will Withstand this
Use /ban Joe bidens mom
But you would need to Prime the Creeper manually
No
Really?
Yes, that requires Manual labour
Or have it go near the guy and it will prob die, so summon a million
I will prob break all his armor
Do /spawnmob tnt_minecart 1000
Isn't it summon?
Also this is #help-server talk
Few have ESS to begin with
why use the essentials one
Idk
does anyone have a more efficient algorithm for this?
If that's Code, send it as a Code block
ight
static JsonValueSpec<?> getPrimitiveFor(Object o) {
if (o == null) return JsonValueSpec.NULL_PRIMITIVE;
if (o instanceof Number) return JsonValueSpec.NUMBER_PRIMITIVE;
else if (o instanceof Boolean) return JsonValueSpec.BOOLEAN_PRIMITIVE;
else if (o instanceof String) return JsonValueSpec.STRING_PRIMITIVE;
else if (o instanceof Character) return JsonValueSpec.CHAR_PRIMITIVE;
else if (o instanceof JsonArray) return JsonValueSpec.JSON_ARRAY_PRIMITIVE;
else if (o instanceof JsonObject) return JsonValueSpec.JSON_OBJECT_PRIMITIVE;
throw new IllegalArgumentException();
}
but it wraps
soyeah
i thought that looks better
Bandwidth is more important
Anyways, that is as efficent as it gets without reordering the blocks
can we give abstract methods parameter
Yes
i cant
Why that?
should i pass the parameter in the abstract class or inside the abstract class method which i redefine in the inheriting class?
The Parameter needs to be defined in the head of both Abstract and overriding method
hmm so i dont need to type parameter in brackets
What
public abstract void Meth(Clazz param);
@Override
public void Meth(Clazz param) {}
This is how you define it
i cant do this
To invoke it is Like a regular method
Why?
hi, I need to do some action lasting 5 seconds, after the expiration, disable the task and remove the object from the list, how can this be implemented
ugh someone got any idea why my HttpUrlConnection changes its URL once I call getResponseCode()? It seems to use rDNS to turn the given IP into a host name or something similar weird
?scheduling
It could also be redirects
hm yeah it probably is, it seems to use the wrong Host header
although I am explicitly changing it
As in 255.252.475.252:8080 will redirect to https://example.org/welcome.html
yeah it seems like it doesn't apply the custom host header i'm setting
because I wanna use the IP to avoid DNS lookups
then add the Host: header manually
it's working in my CLI project but not in Spigot >.<
I AM STO STUPID
I am using setRequestProperty instead of addRequestProperty
so I am overriding the host field when setting the user agent
Something with Unchecked Calls...
hm weird, addRequestProperty also overwrites existing properties