#help-development
1 messages · Page 432 of 1
smooth brain too smooth
?1.8
Too old! (Click the link to get the exact time)
enum CoolPeople {
Oliver,
EpicEpic,
Ollie
}
enum NotCoolPeople {
Coll1234567
}
😎
Hi so im getting an entity using Bukkit.getWorld("world").getEntities().get(l) and I want to be able to kill this entity. How do I do that?
i did
didn't work
l is the variable in a for loop, it goes through all entities
it works
what is PersistentDataType.TAG_CONTAINER ?
i think thats for chests and stuff
nvm i read it wrong
Essentially you can put a persistent data container inside another persistent data container
uhm ok
@remote swallow when i made exactly as you sent to me but when i made this conditional
isn't works
@remote swallow
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
switch (event.getMessage()) {
case "/gm":
event.setCancelled(true);
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
event.getPlayer().setGameMode(GameMode.SURVIVAL);
event.getPlayer().sendMessage("§aYou're in survival!");
}else{
event.getPlayer().setGameMode(GameMode.CREATIVE);
event.getPlayer().sendMessage("§aYou're in creative!");
}
break;
because its checking just for /gm
sounds pretty useful if your olugin has a lot data for container to save
if its /gm you want you dont need that
you only need that for /gamemode
alos that doesnt work because your syntax is wrong
can i store boolean?
?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.
in persistent data container
on pdc? yes
how
just use a byte
wait we dont have a bool?
uh
yes and cast it at both ends
getbyte() == 0 ? false : true
yep
yeah not really casting but you get the point
Don't even need the ternary. getByte() == 1 would suffice
oh yeah
3?
primary operator is like inverting something, i.e. !
why dont just use this
secondary operator are most operators like + and - etc
and ternary is like the if statement
yeah thats good to use
you asked about what a ternary was so I explained it
yeah
How can I know with what domain a player is joining a server ?
what do you mean by domain
like i'm joining using play.myserver.com
oh yes
ok
thanks for correcting me haha
alex has something for this
Urinary.
Sure, urinary
coll is so mature
Of course
@tender shard wake up
Oh nice
just looking at messages, check what PlayerLoginEvent#getHostname() returns
I have another question
what is finally for?
finally?
in try catch
It executes at the end of the statement
hello, I've been working on a plugin and I need to check if a block has gravity (so if it's sand, or gravel, or etc). Is there any quick way to check this, because I couldn't find anything in documentation. Would the best way be to check for all gravity blocks manually?
Regardless of if it succeeds or catches an error

What's the difference between this
try {
//code a
} catch (Exception exception) {
//code b
} finally {
//code c
}
and this
try {
//code a
} catch (Exception exception) {
//code b
}
//code c
because i dont understand
the first will run that finally code if theres an error it catches or not
the latter will error out and not run it
finally is always called. Doesnt matter if exception is throw or not
it return my connection (like my IP with my internet provider)
and in the second example code c isnt gonna run? what?
ah, idk what method alex used
if the error is caught the method ends there, because of an exception
finally would run code c regardless of that
Its not ran if the exception was critical and exits the current call stack
I'm creating a Mana system. Everything works except I want to make players be able to expand their Mana Limit. Base is 100 and I'm wondering how I can do it?
if by menus you mean me, ill join you
Is there a way to clone a instance of CraftBlockState?
why byte doesnt work?
what's the error
The value isn't a byte that's why, you need to cast the 1 to byte so like this: (byte) 1
why what
Java has no literal way to write a byte as far as I know
yeah it only has longs and floats
But I think byte x = 1; works without casting
and doubles
rule #38273 of programming: if it works, don't touch it, unless it falls apart
yeah
Hello. I registered event onInventoryDrag and my event doesn't work normally. I don't understand how it works but it doesn't called every times when I moving item in inventory. Event handler calling through time
It's only called when you drag a stack over several slots
Over several only?
tbh just don't work with raw Bukkit Inventory API
it's a pain in the ass
use a library
Which?
I just manipulating with item inside inventory. This is really bad that I should use some library instead of base api to make so simple thing...
well you can use base Bukkit API
is there faster way to do
if (boolean) {
a = 1;
} else {
a = 0;
}
?
but it's a pain
Why isnt my class sending an ActionBar? not giving any errors
https://paste.md-5.net/siqadilaxi.cs
You mean a smaller way?
a == boolean ? 1 : 0
ooh
ternary operator
yeeeh
might need to put boolean ? 1 : 0 into parentheses
Only one =
oops
yes
yeah
if you're into readability you can just do
if (boolean) a = 1;
else a = 0;
yeah I'm just sleepy rn my bad
no i use that
with ?
i like it
sure thing go for it then
wait i need to cast it to byte again? bruh
By my humble C# enjoyer opinion check and expression shouldn't be in single line
yeah
im quitting this job
lmao
You could use an int and cast it to an byte later
haha that's why I only have 2 hours of experience in C#
Just this looks like bad I think.
maybe you feel this way sure
one needs to write their code in a way that'll be readable to them particularly
I'd probably go for that instead of a ternary
but it's up to the coder to choose
I actually feel the opposite way haha
I'm agree. Ternary operator is good syntax sugar that has been added
boolean1 ? (boolean2 ? (boolean3 ? a : b) : (boolean4 ? c : d)) : e
That's unreadable imo
I sometimes catch myself doing stuff like this
final ObjectType longName =
longAssCondition ?
valueOne :
valueTwo;
oh
but barely ever do that for short ternarys
true
hi, ive intergraded my discord bot in a spigot plugin. everything works fine, but when i stop the server, it gets stuck at the disable part, do i have to add some code in the onDisable method to stop this from happening?
well the JDA bot should be stopped in onDisable afaik
where then?
?
So after more investigation I'm guessing there is no way to do so T^T
If anyone knows one anyway please contact me x)
And if return to that. Maybe someone understands why that event calling handler in random case when I'm dragging item?
?nocode
It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.
Sorry
@EventHandler
public void onInventoryDrag(InventoryDragEvent ev)
{
ev.getWhoClicked().setHealth(0.1);
if (!ev.getWhoClicked().getClass().isAssignableFrom(Player.class))
return;
if (ev.getCursor().getItemMeta().getAsString().toLowerCase() == "elytra")
ev.getInventory().removeItem(ev.getCursor());
}
setHealth added for debug
Don't compare strings with ==
So as far as I know getItemMeta().getAsString() doesn't return the item type as string
That too
ye lol
You should use .getType().name().toLowerCase().equals("eyltra") instead
use .equals()
If I will compare string using == java will try to compare links or values?
But if you're trying to compare the type then just compare the type enum
Which looks like this: .getType() == Material.ELYTRA
Understand. Thanks
But general problem is that my debug doesn't calling at any times when I'm drags item
The inventory drag event is only called if you are dragging an ItemStack (that is in your cursor) over multiple slots in the inventory GUI
also, instead of doing if (!ev.getWhoClicked().getClass().isAssignableFrom(Player.class)) you can just do if (!ev.getWhoClicked() instanceof Player) I believe
^
So what you want is probably the InventoryClickEvent anyway
you can also cast it in the same line if it can be casted with if (ev.getWhoClicked() instanceof Player newPlayerVar)
You'd probably want both
can someone help?
Only with Java 17 if I remember correctly
?nocode
It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.
Ah, right
@serene sigil
Oops sorry for the ping ZBLL
Thanks for help. I thought that java doesn't have an alternative for typeof() and is operator
that still doesnt fix it 💀
Show your code
@pearl seal remember that you will need 17 for that new cool syntax with the casted variable in the expression
17 version of java will run on spigot 1.19.3?
yes
yeah
this is what i currently have:
hello I need help with placing tall grass, it only places the lower half when I use getBlock().setType(Material.TALL_GRASS)
Use showdown now
Yeah set the other half
you will need to do it for the block above as well
they are two blocks
when I do that it removes the whole thing
But you need to use the BlockData object if I'm not mistaken and choose which side to set
^ It won't work if you try to place two bottom halves
wdym?
oh so remove everything and use shutdownnow?
Yeah
kk
@dire tapir
The blockdata for both looks like this
Lower half: minecraft:tall_grass[half=lower]
Uppwer half: minecraft:tall_grass[half=upper]
You can create a blockdata object with Bukkit.createBlockData(String)
There's also Material.createBlockData
I tried using that but placing the upper part deletes the lower one (it is correctly placed on a grass block)
thx it works now
Just don't update the blocks
@chrome beacon
event.getWorld().getBlockAt(0, 0, 0).setBlockData(<BlockData here>, false);
As an example
alright this doesnt work for me apparently but what did work is putting a 1 tick delay in between, thank you
some1 knows how change this default message? "Your game mode has been updated"
I think you can cancel the message with the PlayerGameModeChangeEvent
could you show me how can i do that?? cuz i tried but i dunno if its right
how can i check if a plugin is being loaded through a /rl
you do e.cancelMessage(); and then e.getPlayer().sendMessage("new message");
unless you have essentials or some other plugin like it this would work
e.cancelmessage() doesn't exist
how to change player name above his head?
Should be possible to do just loop all the online players in each server on the network
how to change player name above his head? AI is telling me weird things
so i have to ask human
wait wha
Wub dah zkah
does anyone know how I can listen to a economy update event (deposit/withdraw) in vault?
thanks I'll try that
hi, in my custom plugin, how do I send messages to the action bar?
.
for(Player player : players) btw
no need to use a fori w/ get
ooo i didnt know that ty
Looks like they depend on the jar
where would I find my pom.xml
oh you're not using maven?
ngl I have no idea what i'm using
im not familiar with intelliJ
when I learnt java I used NetBeans
frfr
ikik
Som1 know why its not working ? Its supposed to drop spawner with the pdc of the spawner gave with the /bspawner
Bspawner :
https://paste.md-5.net/ukajofeyim.java
Spawner :
https://paste.md-5.net/koxubuzici.java
it should work i havent error
I mean, what are you getting ?
beyond that, early returns would really help the readability of your code
nothings
when i do /spawner near of a spawner it should drop it
I recommend adding some debug messages to see where the code is failing. For all the if statements, give them an else block that says something like
player.sendMessage("state instanceof CreatureSpawner failed");
But lynxplay is right about early returns, your statements are indented way too much.
For some reason when detecting an ItemStack for it being of Material.[WOODTYPE]_PLANKS (for example, Material.OAK_PLANKS), oak planks don't return that
Make sure the api version is set in your plugin.yml
hey guys i want to make a permissions system how i make this??
Yeah It's correct
like in my plugin there are some "haspermissions" that i did set if i just use permissionsEx this is gonna works everything running well?
In this episode of the Spigot Tutorial series, I show you how to work with permissions. It is actually super simple and will allow your plugin to have some more functionality. With this feature you can limit players to have access to certain commands.
This episodes code: https://snippets.cacher.io/snippet/b1f557dd90cdd2502bf3
⭐ Kite is a free...
tysm
Pro tip: The internet exists; If you have a problem with knowledge google "[thing i dont know] tutorial"
well okay thx
hey dude but in this video he just teach how to detect the permissions
i wanna know
like
how i make the system to set roles
and give each role perm
yk?
The internet still does exist
Love the video or need more help...or maybe both?
💬Join us on Discord: http://discord.gg/invite/fw5cKM3
Thank you for tuning in to this episode of TheSourceCode! ❤️
If you enjoyed this video make sure to show your support by liking , commenting your thoughts, and sharing for all your friends to see and learn!
All code is available on Github:
...
🫡
green text? Advanced coding? Oh no we have a hacker in our midst
I have a pregunta:
I need to access a method in API section of completely different plugin. Specifically the method that you can see below. I added the plugin that has the method as a maven dependency and I can access all the files. But how can I actually use the method below?
package io.github.beefdev.police.api.handcuff.manager;
public interface HandcuffManager {
boolean isHandcuffed(Player player);
I can't just do HandcuffManager.isHandcuffed cause the method is not static, so how do I get an instance or what's the correct approach to this?
hespañol
You can't make an instance of an interface
Yes that is correct
There is a class that implements it somewhere that you need an instance of
But then
Why does this plugin that I need to use the method from have a API module and a plugin module?
What's the point
because anything implementing that interface will have that method
Ok yeah so the class is
BaseHandcuffManager
And indeed it implements the class that has the method that I need
Ok so I've reached the main file from the plugin that I need to get an instance from
probably not where you want to be
It has a #getAPI method
That paths all the way down to the instance of the class that implements what I need
So how do I get the instance of a running plugin that doesn't have a static method?
PluginManager#getPlugin
That's what it was
Ok
I assume it's safer to get the instance onLoad() instead of onEnable()
To ensure that it's loaded, right
?
Enable is called after load
hi all is anyone able to help me ban items on a server?
yeah just /ban oak_planks
does that realy work?
i am on 1.7.10 server and want to ban gem armor
?1.8 as we don;t have a ?1.7.10
Too old! (Click the link to get the exact time)
yes 1,8 sorry
site down?
Hi I really need some help. I'm trying to send a message to the action bar, but for some reason the ChatMessageType is just not available. Like it asks me to create a new variable or create a new class. I just can't use it. I have spigot API as a dependency and every other thing I use from spigot works. Here is my code:
for(Player player : players){
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent("§bhi"));
}```
players is an arraylist of players
?bootstrap
Bootstrap Jar
The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically.
Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163
I currently have spiot-api-1.16.5.jar
Where did you get it from
Wait are you not using maven?
You need the -shaded version if you're not using maven/gradle
how do i get that, or how do i switch my project to maven/gradle?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Idk @tender shard probably has a good tutorial
Is it possible to add a delay to an action?
Like PlayerInteractEvent by 0.3ms
So like, force a slight lag?
smallest unit would be 50ms
Sure. But why?
one question, am I the only one when looping with x y z loops y x z?
inner loop goes first
wdym
for (x...
for (y...
for (z...```
loops z then y then x.

do it whatever order you want, but inner loop has to complete before the outer can run
it's the only thing that makes sense in my head
y,x,z makes sense in a 3d space
yay
In this video, I take a look at the source code for the Linux IPv4 TCP stack that basically runs the internet.
Some of my related videos:
- Let's read the Linux kernel source code: https://www.youtube.com/watch?v=C43VxGZ_ugU
- Let's read the gRPC source code: https://www.youtube.com/watch?v=pXKOsSwutLU
Useful links:
- Code: https://github.com/...
How do I go about cancelling the client side block break animation? I can control server-side sending to player using "Set Block Destroy Stage", but the client side overlaps with this. The effect I'm looking for is similar to hypixel mining/cosmicprisons.
They give the player client side mining fatigue
Ah, I didn't even think of this. Thanks!
good morning everyone
can we jus tmake you the official docs
I love writing docs lol
Does anyone know how to add color w/ holographic displays?
so, sure
MD is gonna make your write all future javadocs for spigot
It's for a game functionality. How can I do it?
?paste
0.3ms is literally nothing
does it not support the normal color codes?
did you mean 0.3 seconds
gm?
._.
I did, apologies. It is 0.3 seconds so 300ms
I mean, it does but I'm making a plugin with it as an api so color just show up as text like &7Test instead of being grey
https://dev.bukkit.org/projects/holographic-displays
Using this one
throw your text through ChatColor.translateAlternateColorCodes
btw des HolographicDisplays use NMS area effect clouds, or at least NMS armorstands? Because if not, you are better of just using spigot API
especially now that Displays exist
oh ok displays were added in 1.19.4
how does ChatColor.translateAlternateColorCodes work?
example:
also should I be using the bukkit one or md5's?
String text = "&cThis is red";
String translatedText = ChatColor.translateAlternateColorCodes('&', text);
translatedText now is red + "this is red"
ah got it?
so not like this? lol
or would that still work
yeah nvm that would still work
im just confused
System.out.println(minLocation);
System.out.println(maxLocation);
minLocation.getBlock().setType(Material.DIAMOND_BLOCK);```
Holy shit it actually worked lmao
That worked, surprisingly
ofc it worked 😄
you mean bukkit vs bungeecord
Use the bungee one
It supports hex color
rule 1: do not care about "optimized" but use whatever works
if both work, then look at optimization
do you need hex colors?
I'm trying to save items out to a .json file after serializing them to use later. This is so I can make a in-game item editor to make viewing items easier and other reasons I have. When I call CustomItems#saveItem() from my onEnable in the ChunkWars class it works perfectly. But in the SaveItem (CommandExecutor) class it gives me this https://paste.md-5.net/himoqosuha.cs. Here is the source code https://paste.md-5.net/qujotijuli.java. I've been going nuts all day. I don't want to use yaml but I will if I have to?
Back when the bungee chat color was added to spigot MD said to use that
So I just use that
probably not, but idk maybe in the future they'll want the that like gradient thing people are doing now
and those like boxes around the ranks that's weird
write a proper TypeAdapter for your class
"I don't want to use yaml" - why not?
yml annoying
spigot's builtin ConfigurationSerliazable will do everything you are looking for
ive got these https://paste.md-5.net/yafufokaxa.java
alternatives?
yeah p much
the spacing can easily get fucked and ruin everything and you not even know
well all the alternatives like json etc are way more annoying
yaml it is ig
apparently tabbing and spacing, and whitespaces are all different
obviously yaml is nicer for admins to edit, while json takes 0.000127 seconds less to parse
however you only parse the file once, so who cares whether it takes 0.0000127 seconds or 0.0002 seconds
Muh CPU cycles
I'm an egalitarian, I make the main thread wait for 3 seconds for every file I load
it's not nice to discriminate
You can slowly lower that every update to make yourself look like a master of optimization
How can I add 300ms delay to something like an InteractEvent
Every $1 you give me i'll remove 100ms from the thread.sleep
Well you don't have control over what actually happens after your event listener code
So the only easy solution I can think of is to just sleep the entire server
Which is of course, not a good
Yeah I don’t need to cancel it either, just need to have my event listener have a bit of lag
lol
Why not? The server may be tired, let him sleep! #ServerRights
that's not how that works, that's not how any of this works
is dumb
I’m trying to have action stacking
Because you can delay your handler code with just a bukkit runnable
But you can't delay the server's code
Too late, just stole them
does Location#add return a new Location or it just modifies the current x y z of the Location?
probably could just clone the event itself somehow
modifies
Asking about your attempted solution rather than your actual problem
any way of making a copy instead of modifying?
.clone
the clone wars have begun
k restarting let me try
Them darn starwarts be cloning again
I’m making a volleyball game. When you hit the ball the first time it goes up. And while it’s going up, you can hit it a second time to have more power straight
Maps?
But currently with no delay, it’s really hard to do, so if I add some lag to the event listener
I can take advantage of action stacking
You might be better just adding there name or uuid to a set and checking if its their before doing stuff
That’s not the problem
The problem is since there is no lag, actually doing both hits in game is too hard because it’s way too responsive
So by adding a delay to the hit, you can 300ms more to move your crosshair a bit further up to be able to hit it correctly. Something that you can’t do without lag
have you taken the fact that people do not have ping towards your server into account?
So I just started making plugins literally today, and i was trying to make a plugin just to learn where when you break a block, the block you broke turns into dirt. For some reason, the block just drops dirt as an item instead of replacing the block itself with dirt, here's my code:
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
block.setType(Material.DIRT);
}
}
Cancel the event
You may also have to wait a tick before changing the block if you cancel the event
ill try it, but why would cancelling the event make it not drop the item? Just trying to learn
Because cancelling the event stops the block from breaking
so after which line should i cancel it?
Doesn't matter
and what causes it to break in the first place?
Because you are breaking it?
I used a gif compressor online
And it literally increased my gif file size by 14%
well GIF is an awful format
Yeah but I just thought it was funny when I saw the -14% compression
You cant delay an event like that.
If you want something to happen 300ms later then you simply schedule a task
Fair, I thought it wasn't possible either
Why do you need to delay it anyways?
Best you can do: Always cancel the event and replicate the outcome 300ms later
I’m trying to have action stacking. Like hit stacking, It’s for a game mechanic
I’m making a volleyball game. When you hit the ball the first time it goes up. And while it’s going up, you can hit it a second time to have more power straight
But currently with no delay, it’s really hard to do, so if I add some lag to the event listener
I can take advantage of action stacking
The problem is since there is no lag, actually doing both hits in game is too hard because it’s way too responsive
So by adding a delay to the hit, you can 300ms more to move your crosshair a bit further up to be able to hit it correctly. Something that you can’t do without lag
Well... then just keep the ball in the air for half a second and count every hit it takes in that time
Yeah could be an alternative
Or make the ball start going up slightly slower
And speed up gradually
But I feel like those micro adjustments aren't that efficient for our lovely java
I dont understand that statement... we have a tick based timescale. 20tps is 20tps. Doesnt matter if its being scheduled on C or Python or Java.
Anyways i would do the following:
If you recieve the ball then the first hit slowly moves the ball up regardless of where its
hit and the second hit defines the final direction of the ball. Or even N hits after the first one
are counted together to a final vector
Ok yeah that's great
Thanks for drawing that up
Will get that working
It's interesting
Less help and more "Rate my code" :L
Lands / CoreProtect Addon with the purpose of checking if players have had (roughly) 90 minutes of playtime or more in the last 30 days.
Idea was to streamline the process for a server that has the 90 min per 30 days as a rule for if land claims are to be deleted (but didnt want it to automatic deletion for obvs reasons)
I'm having trouble getting a straight answer on this: custom Minecraft player heads. I know Spigot doesn't allow them through some easy-to-use method (though I'm unsure as to why), but I'm having trouble understanding exactly how it works in Minecraft. All custom heads were heads worn by players at some point, then changed to something else, but still linger in the Minecraft database? Is that how it works?
review java naming conventions
In the first three clicks I saw an upper camel case package (Commands) lower camel case package (subCommands) and an upper camel case method (GetSubCommand or something)
Do you know what it is?
PlayerProfile
SkullMeta has setOwnerProfile
I believe the skull block state has something similar
Doesn't that only allow current player skins? I want a custom skin from a url
No, you can create arbitrary profiles
And set the skin via a url
You can make a profile with a random UUID, then designate textures via the base64-encoded URL
I think if you keep using a different uuid they won’t stack properly
I derive the uuid from the url
That's a good idea, yeah
Am I mistaken that custom player heads are pretty common on Paper servers? Why is it so hacky to get a custom player head?
Just has nobody in Spigot thought it was time to make some simple way to do it (aka CustomPlayerHead(String url) and it generates its own false UUID, etc)
It's really not all that complicated ;p
Could somebody point me to an example? Like how are you deriving a UUID from the url? etc
And do you have to store the UUIDs for each custom head?
I appreciate it, thank you, all google searches on the topic point to WILDLY outdated information
I thought it was 1.18
Somewhere around there
The 3 tutorials I found were all from 2016, and half the methods came back as deprecated, lol
As for the value you pass to the method, it’s the base64 encoded url for the skin
I just grab it from minecraft-heads
Good site
Ah an easy fix. Cheers. One part of java I haven't spent a lot of time learning.
How can I automatically upload a compiled jar to this section using maven?
hi, im not quite sure why my code isn't working here. It's purpose is to fin all the players within a certain region and if they do not have the permission or if they are not part of the list of players called players, they are teleported somewhere. I know the issue is in the if statement comparing the player to the player in the list as if I remove it, it works with the permission if statement. Here is the code
for (int j = y1; j <= y2; j++) {
for (int k = z1; k <= z2; k++) {
for(int l = 0; l < Bukkit.getWorld(world).getPlayers().size(); l++){
if(Bukkit.getWorld(world).getPlayers().get(l).getLocation().getBlockX() == i
&& Bukkit.getWorld(world).getPlayers().get(l).getLocation().getBlockY() == j
&& Bukkit.getWorld(world).getPlayers().get(l).getLocation().getBlockZ() == k){
if(!(Bukkit.getWorld(world).getPlayers().get(l).hasPermission("OPSeeker.*") || Bukkit.getWorld(world).getPlayers().get(l).hasPermission("OPSeeker.dungeons"))){
for(int m = 0; m < players.size(); m++){
if(!(players.get(m).equals(Bukkit.getWorld(world).getPlayers().get(l)))){
Bukkit.getWorld(world).getPlayers().get(l).teleport(spawn);
}
}
}
}
}
}
}
}```
ik lol
Just loop the players and check if their x y and z fall within the bounds of the region
going through the x, y and z position of the player then going through the list of players in the world and the players in the list of players
Spigot even has a class to help with this, BoundingBox
You also really, really need to look into making variables
yes I did that, what I want is for people not in the list of players called players to be teleported
Loop all players, check if they are within the bounding box, if not yeet them
that's what the code does
for(int m = 0; m < players.size(); m++){
if(!(players.get(m).equals(Bukkit.getWorld(world).getPlayers().get(l)))){
Bukkit.getWorld(world).getPlayers().get(l).teleport(spawn);
}
}```
it's this that doesn't work
The reason the code doesn’t work is because a players x y and z will rarely exactly match an integer
coll
ur not listening to me lol
that part works
its the part after the permission if statment that doesn't
if I remove after the permission id statement, if you have the permission it doesn't tp u, if u dont it does
The point is that the way you've implemented it is wildly inefficient. You are
- Iterating every single block in your region
- Iterating over all online players to see if their coordinates match one of the blocks
- Iterating over all online players a second time to check if they equal the first player you're iterating over
for 3 I dont do it a second time
but you do though
the players arraylist only has 1-4 players in it
You still add them to the list and then loop over the list
players is a list of people who can enter the region, if a player is not in the list or if they dont have the specified permissions, they are teleported out
that's not the problem rn lol
I can clean up the code later
rn i want to know why the code I have isn't working
You’ve check that the teleport line is being called I assume
By adding a sysout or something
Why does it print out /points after I type a command?
Return true instead of false
Returning false makes spigot print out the usage for the command
thank
I've read you can spawn NPC Player entity's. Has anyone else done this yet? I'm wondering how they act, as if it's a Friendly mob or a Villager AI?
idk what your doing , but Look at a game called Rocket league.
Or a Overwatch custom gamemode by
Genji Dodgeball- Mazawrath <- this is open source , I think.
Is that something that can be done within Spigot or is NMS needed?
What is the difference between a BlockState and BlockData?
Does anyone know why some of the items are going in a random direction? Some go towards the armor stand and some go to the opposite. it does eventually go back to the armor stand but its really weird.
// location = location of the armor stand
//item = each item
// speed is a number based on the distance of the item
item.setVelocity(location.subtract(item.getLocation()).toVector().normalize().multiply(speed));```
With minecraft server rental companies. I see that it allows you to upload Spigot plugins to the server for use, do you know if it allows for existing config files to be uploaded as well or do they have to be generated on the rental server?
Cheer's I wanted to create a custom Java application that allows for creation of the config file as I have a lot of user commands.
?xy
Asking about your attempted solution rather than your actual problem
?paste
Idk look for a getter or something
new File("myfile").createNewFile();
You should start first by thinking which format you want to use. Secondly whether there is already an included Java implementation (likely not). Include the required library to your program. And lastly read its docs or read through some examples
do I have to get a player's Connection class with reflections in 1.19?
No, the field is literally called connection with the mojang mappings
How would I change the text value of a sign at a certain location?
that sucks
(Sign) World#getBlock(Location).getState(); <sign>#setLine; <sign>#update()
I won't lie, im confused with this lol
He's telling you to cast the block state to a sign
Then use the sign object to set the line and then update it
or :: are usually used to indicate methods
The reason for that (as far as I'm aware) is because # is used in javadoc links
For example: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Bukkit.html#createPlayerProfile(java.util.UUID)
declaration: package: org.bukkit, class: Bukkit
It is public in newer versions
Bukkit#createPlayerProfile
it's 1.19.4 🤔
or should I rebuild spigot again?
They are too
guess i'll have to re-run buildtools again
You already are accessing it fine
but you try to get the connection from the connection? For which there exists a getter (at least in 1.19.2.. where the field was still public)
Sign sign = (Sign) World.getBlock(new Location(Bukkit.getWorld(world), -49, 64, -231)).getState();
sign.setLine(<stuff>);
sign.update();
?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.
int minutes = time / 60;
int seconds = time % 60;
for(Player player : players){
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§cTime left: §b" + minutes + ":" + seconds));
}
Sign sign = (Sign) Bukkit.getWorld(world).getBlockAt(new Location(Bukkit.getWorld(world), -49, 64, -231)).getState();
sign.setLine(1, "§cTime left:");
sign.setLine(2, "§b" + minutes + ":" + seconds);
sign.update();
}```
it doesn't change the sign at all
1.19.4 made it private
there's no getter
No I can see that you're accessing it
You yourself showed that the field is accessible
how can i use the worldedit api?
because ive added the repositories and dependencys but its underlined red
ah right. You'll need to use reflection
What world does spigot place the players in if player data saving is off? The first world loaded?
Did you reload the pom
Probably just the default world just like a new player would
Default world?
You specify a world name in the server properties. The default world would be the overworld
I fixed it thx 🙂
Mojang auth servers being a little bitch this morning?
Had no issues
must be a local issue then
But you can't do that because of the mappings
💀
You can. Use the unmapped values for the target method names
You can use screamingsandals to find the correct unmapped name or disable the mappings and check
Too much technical for only one packet to listen to
Could just use Protocollib or PacketEvents
How do i make the endermen look like they are getting hurt?
https://paste.md-5.net/ivociyilax.java
Help please, I create an object and save it. But when I try to interact with it, nothing comes out.
I even checked manually, when comparing locations, the same values, but it still gives null
and probably want to use a map
don't use ==
Use location.equals(other location)
IJ sucks more every day. E.g., why doesn't it tell me WHERE this thing is?
So in my command I have this code: player.sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(this.word)); Player is an Entity variable so it can be @p or MyName. I get this error message for the code. How can I resolve it? no suitable method found for sendMessage(net.md_5.bungee.api.ChatMessageType,net.md_5.bungee.api.chat.TextComponent)
zero width space lol
because Player#sendMessage() only takes a string
player.spigot().sendMessage()
lmao, just open it on vscode iirc they properly show weird characters
is it normal that when I set an ArrayList to a path it doesn't get indented?
hm it doesn't show anything, at least not on the side
yeah thats fine
Yes
That’s acceptable
okok
This.word is a string?
hmm well usually it would show in place of where it is but you have a large file, but you can probably ctrl f for the character
Gives same error
Why am I getting this args error?
and new TextComponent is a TextComponent, and ChatMessageType.ACTION_BAR is a ChatMessageType
because you call args[3] when you only have 3 arguments
args[0] = first, args[1] = second, args[2] = third, args[3] = fourth element
args[0] is "mobsword" args[1] is "give" args[2] is the player and args[3] is amount
/command args[0] args[1] args[2] … args[n-1]
n is argument amount
the command name itself is not an argument
I didn't say it was
okay
the base command is "grindaddons"
well are you sure you typed it correctly?
Yep
okay, print args there and see what t says
no, there is no args[3]
Yes there is
no, there's not. you literally sent the error message 2 minutes ago
where it says that 3 is out of bounds
How is there no args[3]
So why doesn't it work?
because you entered less than 4 arguments
vexx you access args[3] even though u never check that the argument length is 4
just print args and see what it says
I already told you, because you throw in a ChatMessageType and a BaseComponent into a method that has a different signature. Use the proper method from Player.Spigot
you are also checking whether the length is < 4 but then you just continue to run your code that accesses args[1], args[2] and args[3]
yes but I think thats just their way of determining what command was used
Doesnt make sense still
but like, atleast return then inside the if
so yeah the issue is probably that you tried the first command but you forgot to return after its done
Yeah it's usage, It's my args messed up
They blag my head sometimes
I'm now getting out of bounds for the args[1] but i'm checking for args with the if statement no?
What u need is this
if (args.length > 4){
yellAtUser(sender)
return;
}
return terminates the function scope
Yeah it was legit bcos I forgot to return the args check
Yh
but return is more scalable
how do I change nether portal direction?
More readable (:
since you avoid nested logic
Scalability refers to sth else usually
what is a nether portal "direction"?
java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_19_R2.block.CraftBlock cannot be cast to class org.bukkit.block.data.Orientable
((Orientable) block).setAxis(Axis.Z);
is this wrong?
BlockData
I said it already
(Hint: Orientable is from the org.bukkit.block.data package)
Pog :)
Can I get the name of the block that was placed?
like BlockPlaceEvent, e.getBlockthatPlaced();
you mean the material?
no
you mean a name you set on the item lore?
Blocks dont have a name
if so thats not possible
since all of that data is just lost when placing the block
Let's say I have a quartz block called "Custom block". And put a custom block, not quartz
Then after placing this block its a plain old quartz block
You need to store custom data for that location. Mfnalex has a resource for that.
Help how to add the library to the plugin, because the server is starting, it throws an error: java.lang.NoClassDefFoundError: mc/obliviate/inventory/InventoryAPI
Maven or gradle?
Maven
Here is an example pom
Dont forget the <provided> tag for spigot and every dependency you dont want to shade
one question guys, is there any license that allows to do whatever you want with my code but need to give credit?
Does GPLv3 need the user to give tribute?
You just saved me, thank you very much, have a nice day!
CPAL license
okok ty
?paste
https://paste.md-5.net/vuberegoni.cs & https://paste.md-5.net/epejopagun.cs <-- I'm trying to update an item inside an inventory on click. It's working but it's not updating when I'm in the inventory I have to close out and then open it again to see the change. Any way I can visually update on click? I've done it in the past but I've checked my old code and I literally use the same method i'm using now...
MIT all the way
Sure
Can you give me a feedback of my pl code?
I did it a couple months ago tho
Sure
can I send it here?
What kind of feedback do u want?
what do you think of the code
Ah alr, quality wise and relevance that is?
yeah
Alr alr sure
I am trying to get better at OOP and Java in general
View villager inventories with shift right click. Contribute to akex06/VillagerInvView development by creating an account on GitHub.
- Implicit else/guarded clauses over nested if statements if possible
- Use
thisandsuperif possible to clarify instance method calls and instance field accesses - Personally would not use shortcut names and abbreviations like Inv (your main class as an example)
- I’d add Listener to the names the two classes that implement Listener as to clarify their purpose on a high level.
- Title inventory identification is not ideal, so avoid and use == to compare inventories directly, or use InventoryHolder.
- loadEvents() can be a private method, as by a means of defending it from being called wrongly. But good method I like that you did it, many plus points.
- I would use Plugin#getServer() and depend on Server over the Bukkit if possible. Since that leads to more unit testability and object orientation.
- Color is a utility class, can be final.
I hope it is okay if I ask you to give a feedback for my code
https://github.com/fodded/HypixelDuels/blob/master/src/main/java/me/fodded/duels/data/PlayerData.java
if it's not bothering you
tysm, I will try to make it better
Sure
how many fields can you have? https://paste.md-5.net/koqoxoguqu.java
- int over Integer
- Use
thisandsuperwhen accessing instance fields or invoking instance methods to clarify. - Avoid indirect injection, for instance when u inject data by a method call in the constructor as player.getUniqueId(). Since its less unit testable and your code hides what it actually depends on. If you want default values for your fields, or want to avoid long parameter constructors, use the builder pattern as suggested by effective java.
- Some of your functions are quite huge and large, that makes them less readable and a bit messier, try to extract out smaller functions. This gives the reader the ability to exit early in an abstract sense a function must only do one single thing, which is defined when you cannot meaningfully extract out another function, take this rule with a pinch of salt tho.
- PlayerData is a data transfer class I would re-design it such that creation logic is in another class (if its complicated). I would also put the storage save/load logic in another class as you currently break single responsibility principle.
- try-with-resources can be used for PreparedStatement.
- Looks like unnecessary reflection is being used.
- Your comments there are redundant, instead you can do something like:
boolean isWinning = this.getStreak()>1;
if (isWinning){
…
}```
(Speaking of readability, defining functions such as decrementStreak() and incrementStreak() might be nice as it adds fluency)
yo guys i want to cancel the drop animation then i made this, but the item it's becoming in Material.STONE
@EventHandler
public void dropItem(PlayerDropItemEvent e){
e.setCancelled(true);
e.getItemDrop().setItemStack(new ItemStack(Material.AIR));
}
oh now I see my problems, thank you
i tried like this as well but nothing happens
@EventHandler
public void dropItem(PlayerDropItemEvent e){
e.setCancelled(true);
e.getItemDrop().remove();
}
You dont need to set the itemstack of the dropped item.
If you cancel the event then nothing will be dropped.
i want to delete item from selected slot on hotbar
i meant i don't want to let the item dropped on the floor
yk
i just want to obliterate it
event.getItemDrop().remove();
Without cancelling the event
no way
lemme see
bro
I've been trying to do this for hours
thx
ah cmon
fields(table, type.params[i], i == 0 ? p1 : i == 1 ? p2 : i == 2 ? p3 : i == 3 ? p4 : p5, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : i == 2 ? v -> p3 = v : i == 3 ? v -> p4 = v : v -> p5 = v).width(100f);
Object parameter;
Consumer<Object> consumer;
if (i == 0) {
parameter = p1;
consumer = v -> p1 = v;
} else if (i == 1) {
parameter = p2;
consumer = v -> p2 = v;
} else if (i == 2) {
parameter = p3;
consumer = v -> p3 = v;
} else if (i == 3) {
parameter = p4;
consumer = v -> p4 = v;
} else {
parameter = p5;
consumer = v -> p5 = v;
}
fields(table, type.params[i], parameter, consumer).width(100f);
could even use a switch
A switch with integers can get compiled to a lut by the compiler.
So probably better to use a switch
What is lut
look up table
probably
for small integer values its O(1) and for large its O(log(n))
Latter is done via binary search
Oh cool
lazy init seq
also need that id
Use the ordinal
Idiotic question but ive never mucked around with permissions before. By setting the permission within the plugin.yml is that all thats needed? No checks within the code or?
Depends on what permission you're talking about
If you mean for a command, yes that's all you need
commands:
foo:
permission: plugin.command.foo # Automatically checked for before the command runs
permissions:
some.other.permission: # Must be checked manually with permissible.hasPermission("some.other.permission")```
I'd make it lowercase to follow the standard, but yea.
Permissions are generally lowercase, but yes, that is fine
It will also hide the command from tab completion of players that don't have the permission
This still doesn't work: player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(this.word)); It gives the same error
someone ghost ping?
Seems fine. Just be sure you're importing the correct TextComponent. I believe java.awt also has a TextComponent class. You want net.md_5.bungee.api.chat.TextComponent
does anyone know how do I listen to vault events cuz this isn't working anymore https://www.spigotmc.org/resources/vault-events.72930/
does anyone know how can i add custom textures to my guis like shown in this preview
if it's gui's like inventories, i'd say server-resourcepacks
yeah i can do like items adder and there i can add like those resources and everything
but how do i implement it in my code
unicode chars
a custom font
if you just wanna change the font, you just use any unused (well, kind of unused) font schemes that are present in vanilla
you can then use these font characters to draw whatever you want
you texture some private use characters (\ue000 through \uf8ff)
never retexture random chinese characters
there arent just chinese characters
there are latin and shit, that are 99% never used lol
never retexture characters for your own purposes
if unicode already defines them
this is what the PUA is for
im pretty sure theres some un-used unicode chars in the game people can use
thats essentially what i am talking about, but there ofc is always that one person who is like "omg, dont do that, it's not right"
because it's not right? you're not supposed to use some random icon in place of \u0234 ȴ
if its unused anyway, no one frickin cares
why are you against this
it's just asking them to use the characters already provided for this specific purpose
also i never said i'm against it
i am against people claiming "dont do X, because it's not how you are supposed to do it", but that may just be me ._.
i personally think "if it works, it works", i dont care about some random guy saying "dont do that, there are better ways"
again
may just be me
yeah except unicode is a standard meant to unify and avoid the problem of characters being different across machines
like, to avoid this exact thing
i mean, you explicitly said "NEVER"
what is so bad about it, that you explicitly NEED to avoid it
because to me it sounds like doing it would make your pc explode
because it's against the standard and a very bad idea
exactly what i said lol
just use \ue800-\uf8ff 😭
Arbitrary UTF characters are seldom used, but they can be used. If you have an oversized texture and someone finds that latin char (which they can do by looking at your server's resource pack, not hard), your chat is suddenly filled with very, very large images
They should be under a different component font
If you re-texture chinese characters, people who use the chinese font as their default will not see their expected language but a random image instead.
if you wouldve just sent that message, i would never have said anything btw
isn't arguing fun
Same goes for any other character set.
So use the empty characters provided by unicode.
no one fricking uses latin language set in minecraft for real
let's be fucking honest
you are using it right now
Even it that's true, which it likely is, it doesn't matter.
Standards are used for a reason.
People may not use it now, but someone will use it eventually if it's an option.
its some weird one that isnt even a "language" as we know it, but idk which one it was
lemme see
U+0061 : LATIN SMALL LETTER A odd how that is
wow it's awesome, didnt knew it exists
"Dele" is wrong though