#help-development
1 messages · Page 1700 of 1
lol
lol
lmao
well time to figure out how to do that
is it that easy?
yep
wow im dumb
That finally worked. Even though in the end I found the solution on my own, I appreciated your help and it was a moral lifesaver. Thank you very much for your help.
lol
Congrats
:D
Hey guys, I'm having a really weird issue. I have a table looking something ike:
player | some_boolean | timestamp
For some reason, modifying the some_boolean, sets the timestamp value to the current time.
I have tested it both in code and manually via a shell, to make sure I have no logic flaws in my code, and I can confirm it's not a flaw in my code.
Do you need a separate java file for each command?
No
what data type are you using to hold this table
dont need to but imo it's good practice as you dont have 100s of commands in one class
You could just store timestamp as bigint/long no? Might not be the best way though
If you can't figure out timestamp use millis
Unfortunately, no. But I can confirm it's not a problem in my code, the same problem occurs when executing sql manually
oh strange
I'll probably have to go for that, but it's really weird
Yeah
if you could that'd be great
ill have to do it later though ill get back to you if i do
okay, I'll probably be asleep, but do ping me and I'll check it later
From what I can find you can configure it to auto update timestamp
Not sure if that's on by default
another thing, it only happens when the boolean value actually changes, if you set it to true when it's already true it doesn't happen
what do you mean?
The timestamp field is generally used to define at which moment in time a row was added or updated and by default will automatically be assigned the current datetime when a record is inserted or updated.
oh I didn't know that, I was actually reading an article about the difference between DATETIME and TIMESTAMP, and it didn't mention that
thanks
gn 😴
is this bukit error?
https://paste.gg/p/anonymous/831e4faec9cc460f99fdadd7cf1cd69c
has something to do with a discord bot
what are you trying to do thats throwing the error
why does jda need a zipFile
to me that looks like a jda issue
is com.neovisionaries.ws.client your package?
could i see the line where you are trying to send the message
MessageChannel channel = event.getChannel();
channel.sendMessage("Pong!");
You need to queue it
Does spigot have any convenient way to check if a block can be legally placed at a location
IE: Saplings can not be placed if the block below is sand
Probably not. I think that check is clientsided
Unless someone went out of their way to make it
Isn’t it both client and server
there is Player#placeBlock
Could be
That’s paper ?
Hey so I want to check if there is a player near my npc how do i do that
I know I can do it with NMS but blah
Theres a function for entities that gets entities in radius
this one
Iterate through each entity in the areay and check if it’s a player
omg I should learn more java 😓
Indeed
List()
tried with a list
Does it return an array of entities?
List<Entity> entities = player.getNearbyEntities(5, 5, 5);
then i should do what?
for(entities : ?)
Yep then instanceof Player
ah
channel.sendMessage("Pong!") /* => RestAction<Message> /
.queue(response / => Message */ -> {
response.editMessageFormat("Pong: %d ms", System.currentTimeMillis() - time).queue();
});
that makes more sense
ayy I miss coding bots
}``` uh lol so basically i did instanceof then when i did autocomplete it did all this just wanted to know if its necessary or i should remove all that and just get ofc the instance of the player
Nah you want to iterate over entities
Then do if(entity instanceof Player)
So a regular iteration for(Entity entity : entities)
?codeblock
You can use the discord code block format to display code or just text in a more pleasing way:
```java
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
Becomes:
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
oh
that auto completed correctly
then if i just if the entity is an instance of player correct?
Yeah
Hey got a little issue:
I got this exception: Caused by: java.lang.NoSuchMethodError: 'java.util.List de.schmidi.config.PluginConfig.getCustomItemDrops()'
When calling the above named method. But I am kinda confused why it's happening. I am on Spigot Version 1.8.8 rn and made a other plugin similar to this one there methods like this work as well. Any idea why this error can pop up?
Binary incompatibilities
sooo, what can I do about it?
What if i use a domain i don't own for my plugins ids?
the internet police will find you
And if I'll buy it when they find me?
no but to be honest, it does not matter if no one owns the domain. stuff like me.raydanomg is perfectly fine even if you don't own it
Well that error is a linkage error and yields when you for instance depend on a compile dependency which provides a class or interface with a specific method.
Let’s say the method add(Object o); from the interface PluginDataHelper.
Now when the server runs it uses your plugin jar which depends on that compile time dependency with that method, however the runtime dependency variant does not have the method add(Object o) it has for instance add(String str, Object o); instead [different signature] thus yielding the exception. @wild reef
I wouldn't publish my library using com.google for example
what if you do?
but as long as it is only associated with you, its pretty okay
I mean, idk if google can do something about it ?
com.google.lynxplay 😏
lol
I can imagine com.youtube
if you need a url, use your github.io domain
io.github.raydanomgr
github reserves that for your github.io page anyway
so you can be sure no one can own it (unless you change your github username)
Hm I understand, but that shouldn't be the case for my own defined method if I got that correctly? There is only one version currently of my plugin which contains the method. The error is like not even coming from within the method, it's my own method itsself throwing it
yea
idk what that is, so I guess no xD
So, even if I own a github account I can't access anymore it'll still be my domain, right?
Oh okay gud
yea, as long as no one else can
Well might be the case some other plugin is reserving the plugin name of yours?
What’s the name of your plugin inside plugin.yml?
it's called customDrops but that's the only plugin on the server
And if you restart it would still yield the error?
I tried to run the plugin on a 1.17.1 server as well, it worked there. But on 1.8.8 it throws the error even after restart.
👀
Oh
But there is like no code contained in this method from spigot
it's literally just a print statement
are you sure there are no errors prior then
Send the entire error stacktrace
^^
?paste
I’m on phone so discord sucks btw
oh yea forgot about that, one sec
no that's the only one
that's why I am really confused about it. I had a similar functional plugin tested on 1.17 and 1.8.8 and it also worked
same happens
yep it is
can you decompile the jar in the 1.8.8 server and validate that the respective method is there
really don't know anything else 😦
yea I will give it a try
what is line 32? Caused by: java.lang.NoSuchMethodError: 'java.util.List de.schmidi.config.PluginConfig.getCustomItemDrops()' at de.schmidi.listener.PlayerDeathListener.onPlayerDeath(PlayerDeathListener.java:32) ~[?:?]
public void movement(PlayerMoveEvent e) {
Player player = e.getPlayer();
List<Entity> entities = player.getNearbyEntities(5, 5, 5);
for (Entity entity : entities) {
if(entity instanceof Player){
sneakEvent();
}
}
}
private void sneakEvent(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
player.sendMessage("hmh Works");
}``` so uhh why doesnt me calling the sneak event not work. Maybe its different with java
you don;t call the sneak event. Even then you called it with no args. that does not correspond to your method/
a PlayerSneakEvent is triggered when a player sneaks
and it needs to be annotated just like all other events
and public
oh yeah I forgot thank you!
hey how might one go about making some kind of minutely reward system
definitely hashmaps, lonsg, and runnables?
Look into repeating Tasks
Even async repeating tasks will help you
?scheduling
You need 1
Create one task that gives someone EXP depending on certain conditions
Than call that method for everyone
i see
Using a .forEach or something
Inside the repeating task
So like
task {
if player has 10 xp {
Give player diamond;
}
}
If you get me 🤣
I’m on phone rn
i created a plugin thats just an api to test, how am i supose to use that plugins api in another plugin? ive tried to google it but everything i found is rly bad and doesnt even explain it
Hey is there some sort of command I can use for detecting broken blocks like the opposite of e.getBlockPlaced()
BlockBreakEvent
public void movement(PlayerMoveEvent e) {
Player player = e.getPlayer();
List<Entity> entities = player.getNearbyEntities(5, 5, 5);
for (Entity entity : entities) {
if(entity instanceof Player){
player.sendMessage("ItWorks!");
}
}
}``` why is it not working its in my main class and i registered it onEnable like this ```getServer().getPluginManager().registerEvents(this, this);```
Oh boy that will be hard on the server
I wanna check if the player is near a corpse
your corpses are packet generated?
Store the location of the corpse and look for that
Store the location of the corpse and look for that
my corpse class
ohk
let me try tthat
I know this exists but I mean something I can use in this sentence: public class BlockListener implements Listener {
@EventHandler
public void onPlace(BlockPlaceEvent e) {
if (e.getBlockPlaced().getType().equals(Material.OBSIDIAN)) {
e.getBlockPlaced().setType(Material.LAVA);
e.getPlayer().getWorld().createExplosion(e.getPlayer().getLocation(), 10);
}
}
}
The entity does not actually exist on the server, so you can't find it with the API
Hi I'm retrieving a set of commands for Bungeecord, through the config.yml file. But I'm not able to retrieve specific values of the yml file.
I managed to separate the commands using the following, but I cannot get the key value pairs of the sub properties
this.commands = this.configManager.getConfig().getList("commands");
for (Object command : this.commands)
{
//getLogger().info(command.toString());
}```
Example config.yml
```yaml
commands:
- discord:
command: /discord
types:
- TEXT
text:
- 'Click here to join our Discord server!'
hover:
- 'link'
link: 'link'```
Oh sorry I'm new I meant a block of code
Okay so what is the issue
Change the event to BlockBreakEvent
And i'm pretty sure BlockBreakEvent just has event#getBlock
if (e.getBlockPlaced().getType().equals(Material.OBSIDIAN)) is there something like e.getblockbroken
?jd
Search for it
Good idea
anyone?
Try asking @ coll1234567 didn't want to ping him
or dont ping people specifically
someone will help when they can
unless coll allows you to
Ok
For the API I have I just use gradle to shade it into my other plugins
Sorry Coll
And to depend on it from my MavenLocal
im not using maven though, i made a test plugin that has an api and i just made a new project, added the jar file from the api, and idk how im supose to the use the api theres no tutorials or anything
Also I think spigot just forgot to add a e.getblockbroken I can only find events
Never mind I can't spell
I cant even getLocation
of the npc
so how do i store
it
Thats because it doesn;t exist
you created it and sent it to the client
so it now only exists on the client machine
oh
you have to store the data you need when you create it
I cant acess that?
ah
so how
like
I get location
corpse.getBukkitEntity().getLocation();
its the location you set when you send the packets to spawn it
ohh so its on the player
im gonna store it
same time
ok one last thing
I stored it
A ha! Spigot has boolean breakBlock(@NotNull
Block block) (That sounds very cheesy)
how do I take that location var from there to the main class
how do I use it on the main class
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Welp
anyone know how to put a long fishing line from a player and also set the bobber's location to a variable?
empthasis on long, i want more than the default 33 blocks distance
what do you recommend?
cause I dont think its the best way
omg i tried cant wrap my head around that its very different from c#
What are you trying to do?
its to excess the Location var from the corpse class in the Main class
I made a simple plugin (The picture below) for testing making blocks into lava but it isn't working does anyone know why?
try cancelling the event before setting the type
e.setCancelled(true)
Any idea regarding this. I'm clueless
Basically get fields from config.yml and put them in key value pairs or a non-generic class/object
dont use .equals
Not going to fix anything, but yes
This setup doesnt look like it should work.
Your setup should look like this:
commands:
discord:
command: /discord
types:
- TEXT
text:
- 'Click here to join our Discord server!'
hover:
- 'link'
link: 'link'
YamlConfiguration config = ...;
final ConfigurationSection commandDeclSection = config.getConfigurationSection("commands");
// Check if commandDeclSection == null
final Set<String> commandKeys = commandDeclSection.getKeys(false);
for (final String commandKey : commandKeys) {
final ConfigurationSection commandSection = commandDeclSection.getConfigurationSection(commandKey);
// Check if commandSection == null
final String commandAlias = commandSection.getString("command");
List<String> typesList = commandSection.getStringList("types");
// And so on
}
The block is set after the event is done. So you need to cancel the event and then set the blocks value or set the blocks value one tick later.
so can anybody help?
Not sure if you can do that without messing with internal stuff
Trying teleporting the bobber
Then yeah, messing with internal server stuff
wdym
NMS and packets
idk what those things are and how to use them
Hello, i have a question. This is my first time that i have create a Minecraft plugin but how can i set it in a file that i can add the plugin in a Minecraft server?
Just compile it like every other java application
I don't know how? 😅
🤷
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Thank you!
does anyone know how to make a player do a certain animation? like crossbow load, trident throwing etc etc
if i'm including external libraries do they have to be shaded into my plugin via the plugin.yml?
i'm including a java discord api interface
Either shade them with maven or gradle directly into your jar or you can download them using the plugin.yml
and use the scope "provided" in your dependency manager.
so it builds but still throws this exception: java.lang.NoClassDefFoundError: net/dv8tion/jda/api/JDABuilder
dumb question: how do i spawn an entity in a certain location? such as 0, 5, 0
i guess i don't understand the difference between building and shading
can i dm someone for help rq
wait nvm i think i got it
Just post here
compiling will just translate your human readable code to jvm binary code.
If you also shade your dependencies then your jar will include all the applications you depend on.
If you just set the scope as provided you will reference certain classes in your
code and hope that those classes are available in the jvm when your code is run.
alright so i probably did something wrong when adding it to my build.gradle
if i can run a script to shade the files vs just including it when compiling
You will still need the dependencies when compiling.
But assuring availability on runtime has to be done by
- Shading them in
- Downloading before starting (via plugin.yml)
I dont use gradle often. Its usually done via the shadow plugin.
awesome 🙂
anyone know why i can't spawn a fishing hook?
code: https://paste.md-5.net/eviquyunet.java
error when i run the command: https://paste.md-5.net/ukojuqivar.java
Looks like you need to dive into NMS
Anything can corrupt player data if you do it wrong enough
ya
I use Player#isGliding in my plugin but that makes it generate exeptions on 1.8 servers, how could I fix this and still use Player#isGliding?
Dont use outdated software. 1.8 support was dropped almost half a decade ago.
Many servers still use it sooo
its not my main target though, still would like basic support for it though
Check the server version and disable parts of your plugin.
ill do that, thanks
Location
Emm who can teach me how to get str[rand]
i want do a random announcer
it just say "The type of the expression must be an array type but it resolved to String"
getStringList will give you a list of strings
Which you can use get(index) to get a random element from
for (String message : getConfig().get("announcers")) ?
getConfig().get("announcers") returns a list
Okay, and?
Error?
getStringList will give you a list of strings
Which you can use get(index) to get a random element from
what .w.
?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.
hey
hi
is it possible to get a list of config sections
like
crops:
46ebc584-25f7-4915-be12-2804df5b5285:
owner: d36d4ae9-b37b-45c7-9426-5496390c98a9
growth-period: 5
location:
==: org.bukkit.Location
world: world
x: 1.0
y: 64.0
z: -14.0
pitch: 0.0
yaw: 0.0
1c4005dc-cdee-4f36-9e53-202e362197ef:
owner: d36d4ae9-b37b-45c7-9426-5496390c98a9
growth-period: 5
location:
==: org.bukkit.Location
world: world
x: 1.0
y: 64.0
z: -13.0
pitch: 0.0
yaw: 0.0
07db581d-b782-460c-acc1-c267f2134b2c:
owner: d36d4ae9-b37b-45c7-9426-5496390c98a9
growth-period: 5
location:
==: org.bukkit.Location
world: world
x: 1.0
y: 64.0
z: -12.0
pitch: 0.0
yaw: 0.0
b07a4390-94ff-4541-a3d3-918cbb556d38:
owner: d36d4ae9-b37b-45c7-9426-5496390c98a9
growth-period: 5
location:
==: org.bukkit.Location
world: world
x: 1.0
y: 64.0
z: -11.0
pitch: 0.0
yaw: 0.0```
i have this
i wanna get all the config sections in "crops"
Hey guys! I compressed my program to an exe file and made a installer with inno setup for it. Befor i publish , how is that wity the licences
Your server isn’t actually laggy
The load is only 17%
But whenever that task does run, it takes a lot of time, what the heck is it doing
Based on the name, it's probably a good thing it takes a while for whoever it involves 
?
What?
Plugins are pretty much always jar files
I mean we can’t say much about the task without seeing it
if (playerData.getConfigurationSection("profiles." + uuid.toString()) == null) {
why is that always true
it isnt
profiles:
ad53c106-4be2-461a-af03-604c46e6b1fb:
name: xEmty
money: 3072.0
xp: 456
level: 9
d36d4ae9-b37b-45c7-9426-5496390c98a9:
name: Quared
money: 0.0
xp: 69
level: 0
af9dd2f2-eb67-4df2-b3f4-69bd15fea282:
name: Mutiniux
money: 13592.0
xp: 291
level: 21```
the uuid is af9dd2f2-eb67-4df2-b3f4-69bd15fea282
which should be mutiniux's profile
but it returns true
when it clearly isnt
o/ does anyone know where to go to to learn how to make a plugin?
also does anyone if https://customrealms.io/ works?
?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.
that still works? even in 1.17.1
he has a 1.17; playlist too
oh fantastic
bump
try just config.get(“profiles” +…….
instead of using a memory section
if (config.get(“key”) == null) {}
so like this?
if (playerData.get("profiles." + uuid.toString()) == null) {
or just profiles
cuz uuid.tostring is another config section
yeah do the uuid as well
okay ill try
nope
meh idk then
I learn java and spigot at the same time, spigot is very easy to use but also needs to know some basic
How can I make sure that if someone does ./kit tools that it ends up in their inventory? https://gyazo.com/789fcaaaca5475d27546ede3b5e8942f
Hi, how do I create inventoryHolder?
I am trying to make a GUI using a library and I am kinda lost
which lib?
How to use it Take a look at the examples below to learn how to create a GUI with this library or use the InventoryGui Javadocs. Defining the GUI setup Every line in the array define the line in the inventory chest interface. The characters are getting assigned to certain elements laters, similar to how recipes are defined. Any empty slot w...
Was looking at this doc
But I am quite lost
i dont see nothing he does not explain
Also there’s an example section
yea
I think examples section is for other lib 😦
Yea, well, do I have to keep it null? because that gave me error
Keep what null?
InventoryHolder
The holder acts like an identity key if you want to later retrieve the same inventory gui instance
п
Is there a better/cleaner way to do HexColors?
private Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})");
public String hexColor(String s) {
if(s == null) return s;
if(s.isEmpty()) return s;
Matcher matcher = pattern.matcher(s);
while(matcher.find()) {
String color = s.substring(matcher.start(), matcher.end());
s = s.replace(color, String.valueOf(ChatColor.of(color)));
matcher = pattern.matcher(s);
}
return s;
}
Nothing particular
Just not a fan of while statements really lol
Well it suits you in this case (:
Ig you could use a StringBuilder instead of mutating the variable s
True.
I'll fiddle around with it see what I can come up with. Now that I know it just uses ChatColor.of(String)
👍
how to send a chat of a particular color
also how to kick and the kick message should be a particular color
please tell me thanks
Normal usage of chat color ?
can u please tell me how to call it
also for kick and ban messages
idk first google result
the message you pass to kick/banning can include those colour codes
wait yea I forgot to google anyways thnx
private static final Pattern HEX_PATTERN = Pattern.compile("#([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])");
public static String color(String message) {
return ChatColor.translateAlternateColorCodes('&', HEX_PATTERN.matcher(message).replaceAll("&x&$1&$2&$3&$4&$5&$6"));
}
or
private static final Pattern HEX_PATTERN = Pattern.compile("#([A-Fa-f0-9]){6}");
public static String color(String message) {
StringBuffer buffer = new StringBuffer();
Matcher matcher = HEX_PATTERN.matcher(message);
while (matcher.find()) {
matcher.appendReplacement(buffer, ChatColor.of(matcher.group()).toString());
}
matcher.appendTail(buffer);
return ChatColor.translateAlternateColorCodes('&', buffer.toString());
}
2nd is cleaner to me lol. Still uses while. I try to stay clear of while statements.
private static final Pattern HEX_PATTERN = Pattern.compile("#([A-Fa-f0-9]){6}");
public static String color(String message) {
return ChatColor.translateAlternateColorCodes(
'&',
HEX_PATTERN.matcher(message).replaceAll(m -> ChatColor.of(m.group()).toString())
);
}
idk why but my command always say that im a console not a player even when i go into the server
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player p && args.length == 1) {
if(!sender.hasPermission("risingcore.spawnsystem")) {
sender.sendMessage("hello u dont have perm");
return true;
}
String locationName = args[0];
locationsData.getCustomConfig().set(locationName, p.getLocation());
locationsData.saveCustomConfig();
p.sendTitle("hello", "hello" , 20, 60, 20);
return true;
}
sender.sendMessage("only player can execute this");
return true;
}
}```
already registered in main and plugin.yml, i know i should switch to acf but im testing things out
well do you actually supply an argument ?
well no but actually no
well there is your issue xD
🙏
imagine not knowing about replaceAll on matcher smh xD
man lol no way i can be that bad lololol
Oo that’s a nice oneliner
it is
Java 16?
Damn
Whats the best way to check if there is a Water source in a specific range of Blocks around the Player? Should be: as fast as possible, radius: 0-30, at max usage about once every 10 seconds.
just loop thru the blocks really
There is not much you can do besides iterating or traversal using a pathfinding algorithm like A*
its not that expensive
okay thank you do you have an example how I could use a pathfinding algorithm?
in like 15min i can give you an example
thank you!
did you forget?
Nope. Just about done
oh okay
Not sure but i sometimes get a StackOverflow. Mabye the recursion is faulty. Youll figure it out.
Example
@EventHandler
public void onInteract(final PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND) {
return;
}
final Block center = event.getClickedBlock();
final Optional<Block> optFound = BlockFinder.findNearest(center, 10, Material.WATER);
optFound.ifPresent(block -> block.setType(Material.RED_WOOL));
}
Thank you a lot!
do teams take a lot of resources if a lot of players are added?
dont thunk so
I think no
ok
anyways is there a way to write this shorter?
public static boolean isPlayerOnline(CommandSender sender, String playerToCheck, boolean exactName) {
if (exactName && !Bukkit.getOnlinePlayers().contains(Bukkit.getPlayerExact(playerToCheck))) {
message(sender, "&c" + playerToCheck + " is currently not online!");
return false;
} else if (Bukkit.getOnlinePlayers().contains(Bukkit.getPlayer(playerToCheck))) {
message(sender, "&c" + playerToCheck + " is currently not online!");
return false;
}
return true;
}
Bukkit.getPlayer(String) != null
so like this?
public static boolean h(CommandSender sender, String playerToCheck, boolean exactName) {
if ((exactName && Bukkit.getPlayerExact(playerToCheck) == null) ||
(!exactName && Bukkit.getPlayer(playerToCheck) == null)) {
message(sender, "&c" + playerToCheck + " is currently not online!");
return false;
}
return true;
}
or java Bukkit#getOfflinePlayer(String)#isOnline()
uhh first way seems easier
This can lead to a significant overhead vs Bukkit.getPlayer(String) != null
owh bruh returning Collections.emptyList() in a tabcomplete doesnt show the player names..
returning null might
tho actually, I don't think that does it either
but implementing your own player name tab suggestion is really not too difficult
yea i tried it with null and that worked
The scoreboard makes my server very slow, and I want to do it async on the NMS way. What is a good way?
how can i get current target of an entity bukkit?
entitytargetevent#getTarget or something?
i have a List<Entity>
List<Entity> entityList = player.getNearbyEntities(15, 15 ,15);
i want to see if there is any wither skeleton in it
im using getNearbyEntities
player.getNearbyEntities(15, 15 ,15);
so
so use the method I linked
how can i use it
what about it don;t you understand?
ok
its a lambda
i want to check if there is any wither skeleton near it
so it doesnt remove mana for no reason
..., entity -> entity instanceof Skeleton) or something
Location loc = player.getLocation();
List<Entity> entities = loc.getWorld().getNearbyEntities(loc, 15, 15, 15, e -> { return e.getType() == EntityType.WITHER_SKELETON; })```
or somethign close
xd
public void movement(PlayerMoveEvent e) {
CorpseEntity corpseEntity = new CorpseEntity();
Player player = e.getPlayer();
World world;
if(player.getLocation() == corpseEntity.loc){
player.sendMessage("IM tired");
}
}``` noooo still not working umm im trying to check if a player sneaks near a corpse(npc) i removed the uhh sneak event to test the location and its not working ive been trying to do this for soooo long
ah for some reason this gives a npr
if (dataFile.contains("safe_chests") && dataFile.getConfigurationSection("safe_chests").getKeys(false).size() > 0) {
People say me that most of the times I can better use team prefixes to display on the scoreboard instead of entries, but how?
so this is a collection of wither skeleton ?
And also (a common problem) the health is always 0 if the game starts, if sb takes damage it changes to the actual number
if its not empty yes
so i can check with isEmpty to see if there is any near it so it doesnt remove mana for no reason
right ?
yes
That is the main purpose of a List
Uhhh
you are instanciating on every move event??
so uh
i have no clue what you are doing
are you trying to detect them approaching the corpse while sneaking, or starting to sneak near a corpse?
starting to neak
then use https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerToggleSneakEvent.html not move event
its not gonna be good on the server 😭
ohh
ok so then how do i make the location part work tho?
im honestly unsure
cause I do have the location of the npc
when you spawned your corpse for teh player (not on the server) it had a location
you compare that location to teh players using player.getLocation().distance(npcLocation)
The distance method returns a double. you make sure thats under a certain amount to be close to teh corpse
How can you solve this problem? https://gyazo.com/afea643d39e58f0be7774854c739b555
hmm yeah i need double in there
what should I do to
my
Location loc
variable
for the corpse
check if you installed the jre thats compatible with your env is what the error is saying
do umm hold on
are you using jre16?
if so make sure your making your plugin on 1.17.1
cause its the version that uses that
1.16
is like 8
i think
Yes i use Java System Library [JavaSE-16]
Ohh, but wich one do i need for 1.12?
ah try 8
Okay, thank you! (:
tell me if it works
Shall i do
Is there some shorthand to getting the default world folder? Say the default world folder for example? (Where playerdata, advancements and everything else is saved)
World.getWorldFolder() I think.
welp you didn't understand my question but hey
guy on paper server said the first world in getWorlds() is the default one
uh i think it is normally - you would have to look at the implementation tho i imagine
ItemMeta lets you modify an item.
i mean the item itself
a wooden axe
like when you craft one
or take from your creative inventory
Oh, no it's not possible globally. You have to modify it for all cases yourself.
With the ItemMeta 
I was about to write in spanish cuz i'm in spanish class and we can only talk in spanish
cool
You dont "override" vanilla items. Minecraft items just have certain attributes that can be changed like the lore, name and enchantments.
You can also change their looks by using custom model ids and a resourcepack.
how to change their attributes ?
like lore
name
and stuff
the whole itemmeta
- Get the ItemMeta from an ItemStack
- Change it
- Set the ItemMeta back to the ItemStack
using the item meta ?
listen to the respective event ?
get from creative menu you are fucked
is there a way ?
creative mode does whatever it wants to do
Well you could listen to any form of inventory interact event and change old items to your "changed" version
seems like a lot of overhead tho
There are 2 ways players can obtain ItemStacks.
- Crafting
- Loot table (including mob drops)
Just listen to those two events and change the lore.
Another way that also supports all ItemStacks obtained by other plugins:
Listen for outgoing packets like WindowItems and change the lore in the packet
before it gets sent to a player.
ok thanks
How could you get an instance of a annotation?
I want test my plugin in my Minecraft server but he don't work, i already have set it in a java file and have a plugin.yml etc. https://gyazo.com/52f188e9c03f0b19d0a8651b62c39648, https://gyazo.com/9823b7535678eddf79430eaa1d5aee50, https://gyazo.com/5c123349097ffb3665e543888bd208c5. Does anyone know how I can fix this to make it work?
Via reflections
any other way?
Your main in the plugin.yml should be me.Joey.KitGui.main
Also please learn naming conventions 
Your plugin does nothing you register the events wrong and you actually have no events
Reflections is the main use case for annotations.
Thankss
uh
Ohh, i am a beginner in Java. I have learned this from someones Youtube video
I'm working on that (:
Ill give you an example
please do
- The annotation
- The annotated method in some arbitrary class
- The method that grabs all annotated methods and does something with it
There are several ways to get annotations.
One more example:
Scheduled[] scheduledAnnotations = clazz.getDeclaredAnnotationsByType(Scheduled.class);
Annotations are present in a class context not an instance context.
PS: i made a mistake in my invocation. It should be method.invoke(object);
well for what im doing it has nothing to do with spigot but I see
I made I plugin I can shoot water sources with. Now I can shoot the water in straight lines. I want them to be able to move around objects if there are some in the way tho. What is the best way to calculate the way the water has to go and get all the Blocks on that way?
What you you mean by shooting water sources?
If the player leftclicks I place a water source infront. Then I place the next one and remove the old. (every Tick until the max range) Then it looks like I am shouting water.
Ok but you want this water source to not stop when it hits something but rather find a way around it?
But when does it stop?
Yes I want it to find the best way around it. It stops at 30 placed water sources.
Finding the shortest path from A to B in a 3D space is complicated and expensive.
I would just try A* pathfinding. Theta* /Lazy Theta* are more precise for smooth movements.
This helped me with my Theta* implementation:
https://ascane.github.io/assets/portfolio/pathfinding3d-report.pdf
Does he need complicated path finding or just "i'm going north. there's a block directly in front of me. Can I go one block in any direction around in the north direction? no? ok stop, if yes, do it"
But what direction is chosen?
Left, right, top, random?
What if Left is chosen at random but its a dead end while right is just a one block obstacle?
Okay I will look at that thank you!
I suppose, but I guess it can just make that decision again at that point. If he needs it to be able to go around walls and such, your solution is far better. Depends on the usecase I guess.
If it just needs to stop at like a 3x3 wall, then A* seems overkill
But what do I know 
Theoertically Does It make sense to handel some packets with c++ instead of java to optimize server. I know i will be a lot of work
Sounds like a diminish optimization but give it a try why not
Like as far as i know c++ code could be injected to java
Yeah there’s some native interface if you want to do that
You could theoretically implement the whole protocol in C++ and also run the server with it.
This for example implemented the full client protocol in JavaScript (node application)
https://github.com/PrismarineJS/mineflayer
JavaScript sounds even slower
It is
Just an example that you can write both client and server in any language you want (As long as it can handle TCP connections)
So minecraft sever run on tcp :o
I only store ints and strings and I am very unfamiliar with configserializables, I just want to know if i need to use them?
Why they not use UDP?
Hm maybe they use udp? Usually for games udp is used because its just faster.
UDP is also connection-less so better for games.
The number of games you used to get kicked from when the internet hiccuped and your TCP connection broke.
RUDP :bigbrain:
im pretty sure mc uses a little bit of udp
Doesn’t Minecraft use both UDP and TCP?
at least according to their docs, it seems like java version is pure tcp
I now read everything but I havent quite got it yet. Can you make me an example of that as well or is it to complicated or to time-consuming? I just can understand things a lot easier with an example.
Eh. I implemented an A*-ish algo a few hours ago. You can probably modify it to return a List<Block> for pathfinding:
https://gist.github.com/Flo0/a08b65c169de3bddfdb78c49de0fe74f
okay I will try that
Hi, when I'm looping through List<Object[]>, Objects.isNull(object[x]) everytime
returns false, event if the object[x] was set as null
Is there any other way to check if the object is null?
TCP for java, UDP for bedrock
TCP is simpler to implement for a game. You only have to handle disconnects/reconnects
UDP is preferred tho, apparently
yes
Considering you send data faster and the idea of a packet not going through once or twice doesn't matter bc it will just be perceived as a short stutter.
Its connection-less and faster, but you have to manage all error correction, resend requests, packets out of sequence and missing packets.
(Unless it's in an FPS game and you try to shoot and the bullet packet doesn't go through to the server but your enemy's packets go through and so you die unfairly)
(TF2 why)
That doesn't sound too difficult, with the right API it's just a few event listeners really.
Not really
you have to queue up packets and keep them until the server/client gets a conformation it has been received
I have written UDP wrappers for a game years ago but its a pain
Again, doesn't sound too difficult.
So long as you can get your head around how to do it its not too bad
but its very complex
I think I'd need to see some actual impl code before I could judge the difficulty lol.
eg, you have a packet id sequence, then as the server receives packets it send confirmation packets back (not necessarily for each packet. If it gets 10 packets all error free and in sequence you could just send one confirmation for the last packet.
if the server misses a packet or gets one out of sequence it has to reorgnise or request any missing packets.
oh and error check
It has to go back to the store because it forgot to pick up tomatoes
you have to do that manually with a crc. There is no error checking on UDP
This? cyclic redundancy check
yes
Eh, Commons Codec probably has something for it.
also take into account split packets. as you have a packet size limit, so you have to split and reconstruct packets.
Okay yeah this is starting to sound more tedious.
TCP really does make the job so much simpler
Could just do both :>
T H E
U L T I M A T E
P R O T O C O L
I did UDP and wrote all those features but I also wrote it so I have two types of packet. essentials and fire and forget.
I've implemented TCP before using java.net, but that's nothing to brag about bc anyone can do it, really.
yeah, TCP is very nice. It does everything for you. You only have to worry about losing connection
oh also with UDP, as its connection-less you have to implement your own ping/keep-alive
Seems like java.net also has some UDP stuff in it too though?
oh
yes
I think a ping wouldn't be too bad tho, right?
its farily simple
just have the client send out a packet on an interval, server receives it and "keeps-alive" (lol) the client
if the server hasn't received one of those packets in an interval, murder the client (as in, disconnect it)
Doesn't MC have a keep-alive despite being TCP?
probably, yeah
MC has a ping
mostly because a TCP connection can be dropped but not seen to drop for quite some time
which in turn causes ghost players, ye?
yep, stops you reconnecting until the old connection is cleared
This just makes an error show up
Ok
what's the error?
Thanks
also you're never supposed to use .equals on enum types, as they are are best used with identity comparison (although .equals probably just ==s it anyway)
It does
it's nice to be explicit about it ig
(and also it reduces likelihood of NPE)
(but if your type is null then I have no idea what's going on)
e.getBlockPlaced().getType() == Material.OBSIDIAN
There's two types of comparison in Java
- value comparison
- identity comparison
Value comparison is equals, and it means to compare two references by the values they contain, like their fields.
Identity comparison is ==, and it compares the references based on if they are the same reference in the heap.
Does TextComponent for Bungeecord accept the minecraft colour codes E.g. "&b" or do I have to add colours using the ComponentBuilder?
There is a fromLegacyText or something like that
But you should be using the builder
I make sure all my .equals methods return random.nextBoolean()
You're awful. I never want to see you ever again. /j
:D
first of all
your .equals isn't even thread-safe bruh
😐 that doesn't seems right
ThreadLocalRandom that shit
you don't need the parentheses around Material.OBSIDIAN but uhhh
I also don't believe you can change the type of a block after it's been placed?
Should I just put e.setCancelled before the event handler
Maybe it needs a (true) 🤷
relatable
But you set it in the event
-_- ok e.setCancelled(true);
Now let's say I made a custom annotation right and used it in multiple areas and a variable is assigned in it in each class do I still need a reflection to retrieve all of the values from each class?
Yeah
To get the values of an annotation on anything, you need to reflect that thing to get its annotations.
(I don't believe annotation reflection is too slow though?)
Wait how do I delay it?
MyAnnotation anno = MyClass.class.getAnnotation(MyAnnotation.class);
System.out.println(anno.value());
That's an example for you jtx ^
ah ok thanks for explaining it
getAnnotation'll return null if the class doesn't have that annotation.
And if your annotation is repeatable, you can use getAnnotationsByType to return an array of all of your MyAnnotations on that class.
so to get the annotation values the annotation has to be used in that class where you want to retrieve them?
yeah
any way around that?
like in
@MyAnnotation("string value (this represents value())")
public class MyClass { ... }
no
otherwise, you could probably reflect the annotation itself? but the values are only set when used on an element like a class.
like I want to retrieve the values in the annotation from another class that doesn't have the annotation
then you'd just use the above getAnnotation code in that other class, but target the class that does have the annotation
I was using this as an example of a class that allows you to retrieve an annotation's values.
MyAnnotation anno = MyClass.class.getAnnotation(MyAnnotation.class); MyClass can be any class
ye it's just a Class instance
specifically Class<MyClass>, but you can just represent it as Class<?> if you want to
Using the bukkit scheduler
good to know
(some'll generate code via annotation processors, but that's very different)
like if you needed an example of that
DI frameworks:
Guice uses Reflection
Dagger uses Code Generation w/ Annotation Processors
hm ok
Spigot uses reflection with annotations too
ye
as does most Minecraft frameworks
like Forge and Fabric (I think) do as well
PlayerInteractEvent is called 2 times. How can I fix this?
Once for each hand
Check event.getHand
no
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
Action a = e.getAction();
EquipmentSlot h = e.getHand();
if (a != Action.RIGHT_CLICK_BLOCK)
return;
if (h == EquipmentSlot.HAND) {
p.sendMessage("HAND");
e.setCancelled(true);
}
else if (h == EquipmentSlot.OFF_HAND) {
p.sendMessage("OFF_HAND");
e.setCancelled(true);
} else {
return;
}
}
hand, off_hand is used
quick question so I have this ```java
Object class_instance = clazz.newInstance();
if (class_instance instanceof Draggable) {
container = new DraggableModuleContainer(clazz.getAnnotation(Module.class), ((Draggable) class_instance).getDefaultScreenPosition(), clazz.newInstance());
}
not worked
the class is implementing Draggable
instanceof is for direct instances iirc
you'd want Draggable.isAssignableFrom(class_instance) I believe?
gimme a sec
that might be for classes
yeah that's for classes
I wonder why instanceof isn't working then
yeah a bit weird
btw why are you doing a second clazz.newInstance within your if statement?
to get the instance
why not reuse class_instance?
I have to use a constructor for this right?
(newInstance is pretty slow btw, so it'd be best to reuse if you can)
alright
Hello, how can I use FileConfiguration config = this.getConfig(); outside the Main class? I tried FileConfiguration config = Main.getConfig(); but it does not work. Is there a way to do it properly?
Well, getConfig() isn't static, so of course you can't access it from outside the class that way.
Yeah, you need to pass in plugin instance
You would need to add a new parameter for your plugin class in the class trying to access your config or add a new parameter for the config.
but im still confused on how the class is not a of Draggable
e.g.
public GetsConfig(Plugin plugin) { ... }
// or
public GetsConfig(FileConfiguration config) { ... }
and then outside of that class, in your main class, you'd do
new GetsConfig(this);
// or
new GetsConfig(getConfig());
thanks, if I add that to the Main class like public final class Main(Plugin plugin) extends JavaPlugin {} I get Record header declared for non-record
oh sorry
i didnt read it well
nah it's fine I accidentally typed class on the constructor
too much Kotlin
besides, you don't need a constructor on Main for that bc your Main is your Plugin (as it extends JavaPlugin)
you need a constructor on the class that uses your configuration
oh actually maowcraft
Maow*
its returning false because it's null
oh
yeah that makes sense
does the class that implements your interface have a constructor?
newInstance may require parameters
yea
I'm a little lost, do I go in my other class which implements CommandExecutor and add (FileConfiguration config) next to its name or I go to main class and do it there?
public class Command implements CommandExecutor {
private final FileConfiguration config;
public Command(FileConfiguration config) {
this.config = config;
}
// the rest of your code here
}
oh
you should use clazz.getDeclaredConstructor().newInstance()
clazz.newInstance() bypasses compile-time exception checking, so it's been deprecated in newer versions
hm ok
thank you but now I get an error on this.getCommand("lock").setExecutor(new Locker()); 'Locker(org.bukkit.configuration.file.FileConfiguration)' in 'ml.yotdev.chestlocker.Locker' cannot be applied to '()'
that wouldn't fix my issue though
oh yeah right
Class<?>
are you doing Draggable.class?
no
if so, then of course it passes null, you can't instantiate an interface
if not, I still don't know
alright then
hm
okay the fact that it's returning null is actually very concerning
the nullpointerexception is pointing to this container = new DraggableModuleContainer(clazz.getAnnotation(Module.class), ((Draggable) class_instance).getDefaultScreenPosition(), clazz.getDeclaredConstructor().newInstance());
Just don't give MODER unban privileges?
yes
so the NPE is on that line?
if so, that means class_instance isn't null because it has entered the if statement's body
and so it's probably getAnnotation that's returning null since newInstance literally can't from what I've read
Well, is this for a custom plugin or an existing permissions plugin?
hm
Because there's a lot of different perms plugins that work in different ways.
If a mod is unbanning another staff member you may have bigger issues
I don't see why that would be null because the class has that annotation
Is it retained at runtime
^^^
yea
can I see your class that implements Draggable?
@Module(name = "FPS", description = "poop", enabled = true)
public class FPS implements Draggable {
@Instance
public static final FPS instance = new FPS();
@Override
public void draw(int xPosition, int yPosition, int width, int height) {
}
@Override
public ScreenPosition getDefaultScreenPosition() {
return new ScreenPosition(0.5 ,0.5);
}
@Override
public int defaultScale() {
return 0;
}
}
It's just allocates a field to be populated with the module instance
I mean it looks like that field is already populated with the module instance tho lol
noooooooooooo
wouldn't that cause some issues with newInstance() too?
it shouldn't
you have a Singleton-like field there
but no way to enforce instantiation
and you're also creating new ones anyway
so every time you newInstance() you're avoiding instance, which already exists
(which is not only inefficient, but could cause issues with state)
that wouldn't affect what im doing though
affect*
but you're right, I believe
uea
@proud basin I'm sorry but I got no idea what might be causing that error.
I must say though, looking like a pretty cool project 👍
All good. Thank you!
I assume this is part of some kind of client mod?
yeah Mixins
The whole Draggable and @Module thing seems to imply it.
So I imagine it's a draggable FPS counter.
Dope.
Mixins good
Mixins are beautiful 😍
yea
If only there were more docs for them
I wanna mixin the Java compiler, lemme do hacky shit please
Don't have to worry about internal API if I just make my own.
I haven't been able to find any docs for using mixin without ModLauncher tho.
Also you are correct
Forge coremodding is so embedded in just like
piles of "DON'T TELL PEOPLE ABOUT IT"
because they're worried about inexperienced people breaking shit
I thank them for that tho, as they have developed my opinions on API design/documentation due to their toxicness.
question
if i were to update a player's gamemode to survival if they were looking at a certain block
and adventure if they werent
sorta like
so they can only break certain blocks
on every playermoveevent
would that work
or no
Or you know nbt flags
yes
anyway how do i generate a world without ravines/caves
their staff get hurt easily
so Olivo do you know how to fix my issue?
Follow their rules and you'll be fine
What's the issue?
this
i get an npe on the third line
nah
Do you have any idea what's null
question about runTaskTimer, will it auto-cancel when the server stops?
Yes
cool, was thinking it /should/ but just double-ehckecing
Because like 3 different things could be null
what it actually does is it keeps running the timer task in the background and steals your credit card information and sends it to 
Bitcoin mining
Mining monero on a spigot servers cpu should actually be possible. And if you use non-server threads then it might not even be noticed XD
@vagrant stratus is a plugin that mines cryptocurrency allowed
(if it sends it to me btw)
lol no. Unless it is transparent.
Yeah
no
Most servers probably can't even handle it 😂
I think you can specify how aggressive it should be mined
Hey I have a few messages I want to send to p.
p.sendMessage("Message-1");
p.sendMessage("Message-2");
p.sendMessage("Message-3");
I want a 1 second delay in between each message.
Can anyone help?
Yeah I tried it but it just broke the plugin
👀
bitcoin mining is a pretty resource intensive process, right?
like no one's gonna actually use it
you'd be better off just buying hardware you own & doing it that way
.
is it spigotmc legal
if the user knows that it is a miner for me
what did you use that broke it?
i feel optic is ignoring my question 
no because i lost power
waiting on a response from other staff
oh lol
Guava has caches. But i highly recommend Caffeine for that.
Aint that the shit that keeps me up all night 🤨
Ah wait. You want a cached List?
just @ me if you get an answer. just curious
Hm... im not sure. You could just wrap a cache in your own List implementation.
@weary geyser
But why do you need a List?
answer's no
No you need a Cache<UUID, List<ItemStack>>