#help-development
1 messages · Page 1780 of 1
oh wait
ive had an idea
nope didnt work
its in the JAR's root
oh
i made a typo xD
string.replace(... where string is your string object
that doesnt modify string right?
try it and see
i tried
Strings are immutable
uhu
so any modifcation methods returns a New string
Is there a way to store an item and its NBT data in a flat file? without NMS
ah i understand
I believe you can use BukkitObjectOutputStream
But that doesnt save NBT does it?
it does?
oh ok
also does .replace() keeps colorcodes?
i was just wondering
they're part of the string so yes
thanks
yes. Color codes is spigot only thing, java doesnt care about them at all
Tho i've heard that it can break if you change server version
i mean, i can work around that
so how would i access my file from my plugins Data dir?
thanks for the info 👍
new File(plugin.getDataFolder(), file name)
thx
how would i detect when a player makes a grass path?
there's probably an event for that
gui.setItem(0, glassEmpty);
gui.setItem(1, glassEmpty);
gui.setItem(2, glassEmpty);
gui.setItem(3, glassEmpty);
gui.setItem(4, glassEmpty);
gui.setItem(5, glassEmpty);
gui.setItem(6, glassEmpty);
gui.setItem(6, glassEmpty);
gui.setItem(7, glassEmpty);
gui.setItem(8, glassEmpty);
gui.setItem(9, glassEmpty);```
is there an easier way of doing this? for all slots that dont have a value eg
``` gui.setItem(10, skull("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjIwNjU3ZTI0YjU2ZTFiMmY4ZmMyMTlkYTFkZTc4OGMwYzI0ZjM2Mzg4YjFhNDA5ZDBjZDJkOGRiYTQ0YWEzYiJ9fX0=","Blaze"));```
so i don't have so many lines
cant find any
lemme try find
its the PlayerInteractEvent
check if the player's holding a hoe
and if he rightclicked on grass block
Loops
basically the first println is the same as the seconds varuiable
and this is what i get
uh no :/
u mean shovel...
but ye basically that
I want to check if a player is in a determinate zone. So, i created two vectors (idk if I have to use Vector or Location) and now I don't know if there's a method for check if the player is between the vectors.
and check if the block clicked on is grass
when i use spigot().respawn() on a player in a PlayerDeathEvent, the dead player picks up the items they dropped before getting teleported
basically makes the server keep inventory
(Ping pls)
Use bounding box
ah yes
Are you on 1.17? If yes, set the immidiateRespawn gamerule to true instead of manually respawning players
nah i wish
anyways i solved by clearing the drops and respawning them on the ground a tick later
is there a better solution tho?
You respawn player after a tick when event fires?
then it would show the death screen for a split second
Thats the point. When Death event is fired, player is actually not dead. So, by respawning them you cancel his Death -> no loot
if (cmd.getName().equalsIgnoreCase("start")) {
Entity Scrooge = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"), 0 , 33 ,-181 ),EntityType.VINDICATOR);
Entity Pet = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"), 0 , 33 ,-181 ),EntityType.PHANTOM);
Entity Lightning2 = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"),-5, 67 ,-153 ),EntityType.LIGHTNING);
Entity Lightning3 = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"),4, 67, -153 ),EntityType.LIGHTNING);
Scrooge.setGlowing(true);
Scrooge.setCustomName(ChatColor.RED + "Scrooge");
Scrooge.setCustomNameVisible(true);
Scrooge.addScoreboardTag(label);
Pet.setCustomName(ChatColor.GOLD + "Scrooges Pet");
Pet.addPassenger(Scrooge);
Pet.setCustomNameVisible(true);
if (Scrooge.isDead()) {
Bukkit.broadcastMessage("test");
}``` here
Well, they need to put start.
if anyone else can figure out why the msg wont broadcast it would be greatly appreciated
huh?
Well i don't see defined in that part the Broadcast
Can I somehow check If a Player is directly infront of another player?
Location?
Maybe raytrace?
wdym. it already is defined? no?
Location and if you want to verify whether or not they're looking at them, dot product between product vector and their direction
targetLocation.toVector().subtract(playerLocation.toVector()).dot(player.getDirection()) should give you a value between 1 and -1, where 1 is looking directly at them
Well, it will be executed when u do the command "start"
i added a body so it willdo it once scrooge isdead
it doesnt execute it once i do command. I've tried it
I just wanted to ask for a explanation thank you I understand it now
how can i get the players who have OP perms?
You'll want to give some lenience there obviously because the likelihood of someone looking directly at another player is slim to none lol
Can do like <= 0.8 or something
Bukkit#getOperators(), Millzy
isnt it >= 0.8 ?
Right, >=, my bad
okay thank you
I mean at least that means you understand it 
yeah haha
there is no .dot() tho
thank you
why eclipse over intelliij idea ?
intellij helps alot while coding
idk if eclipse does
It does. It's an IDE as well. It's a matter of preference.
Hey, I am using LuckPerms and adding a permission from my own plugin to myself doesnt give me the ability to execute the command I set the permission to.
Show code
?paste
some tutorials that say to use eclipse over intellij for "reasons you will learn about later"
and am just curious
lol
Mostly bullshit tbh. You can use either, you'll output the same code
I feel far less efficient writing in IJ
I've seen people getting bullied for using eclipse
F
seems like its just preference then
i'll just keep using intellij cuz its cleaner looking imo xD
Ij has github copilot, not sure about eclipse
Yeah, it's entirely preference. I get ridiculed for my use of Eclipse pretty regularly but so long as I'm writing code the way I feel most comfortable, don't really care
i'd be full on intellij user if jetbrains didnt constantly push kotlin in my face
Wdym I don't get pushed kotlin
copilot ?
you mean the thing that helps you code ?
Ye
the "ai" that's supposed to turn human instructions into code
yeah that's what i meant here
yeh that thing saved me alot
its very nice
i like it
There might be a plugin.
Haven't looked because Copilot hasn't interested me at all
Entity Pet = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"), 0 , 33 ,-181 ),EntityType.PHANTOM);
Entity Lightning2 = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"),-5, 67 ,-153 ),EntityType.LIGHTNING);
Entity Lightning3 = Bukkit.getWorld("build").spawnEntity(new Location(Bukkit.getWorld("build"),4, 67, -153 ),EntityType.LIGHTNING);
Scrooge.setGlowing(true);
Scrooge.setCustomName(ChatColor.RED + "Scrooge");
Scrooge.setCustomNameVisible(true);
Pet.setCustomName(ChatColor.GOLD + "Scrooges Pet");
Pet.addPassenger(Scrooge);
Pet.setCustomNameVisible(true);
if (Scrooge.isDead()) {
Bukkit.broadcastMessage("test");
}
```
i dont want to be repetitive but i
just want to know why this code isnt working, the isdead statement
and why wheni killhim it doesnt broadcast themsg
Inventory gui = Bukkit.createInventory(null, 36,ChatColor.RED + "Test GUI" );
player.openInventory(gui);
How can I make it so people can't take or place items in that specific GUI
Listen to inventory click event and cancel it if the target GUI == your GUI.
Does anyone know a good tutorial for how to force resourcepacks on players?
but i would still like to listen to inventory clicks
because it's a menu GUI
with items
then you can check the X and Y for your "buttons"
how can I spawn a lightning bolt with packets? current code:
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
PacketContainer packet = pm.createPacket(PacketType.Play.Server.SPAWN_ENTITY_WEATHER);
packet.getIntegers().write(0, Utils.randInt(1000000000, Integer.MAX_VALUE));
//packet.getBytes().write(0, (byte) 1);
packet.getIntegers()
.write(1, x)
.write(2, y)
.write(3, z);
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getLocation().distance(victim.getLocation()) < 100.0f) {
pm.sendServerPacket(player, packet);
}
}
} catch (InvocationTargetException e){
e.printStackTrace();
}
wym? X and Y "buttons"
can you iterate on an empty hashmap?
=, not ==
?
Yes, but that Map is most certainly not empty and the NPE is sourced from your ChatPlayer class
you know what I mean.
you have a GUI, it has "buttons" (which are actually just itemstacks) that performs actions on click, you check the X and Y in that gui for the specific items you need actions to occur on clicking, and you cancel the event so that it doesn't pick up the item (but the code before the cancel still executes if it matches your X/Y checks)
channels is an initialized list
oh ye makes sense
it's coming from that line
mainChannel is probably null or smthn
use setResourcepack on the player, and also listen to the resourcepack status event to check if they accepted or declined or not
import org.apache.groovy.groovysh.Main;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
public class DataManager {
private Main plugin;
private FileConfiguration dataConfig = null;
private File configFile = null;
public DataManager(Main plugin){
this.plugin = plugin;
}
public void reloadConfig(){
if (this.configFile==null){
this.dataConfig = YamlConfiguration.loadConfiguration(this.configFile);
}
}
}
am getting error here
this.configFile = new File(this.plugin.getDataFolder(),"data.yml");
idk why
or you can use the new packet which has a boolean i think that allows you to force resourcepacks if you are on the new version
so I can just offer the player a resource pack when ever I want? (1.16.5)
to reiterate my problem from earlier, I have made a command from my plugin need a permission to function, set it to default: op and if I add the permission to a group in LuckPerms and add myself to that group I am not able to execute that command. here are the permissions and the code which prevents unauthorized use. https://paste.md-5.net/kinacuvuxa.cs
I can use the command when I am op, but not when I am deopped, so it works that far at least.
how can I see who opened an inventory? like event.getPlayer but for event InventoryClickEvent
uhhh there's a method for it I think gimme a sec
huh
wdym
Yeah
if you do that method sure
keep a set or something of people who sent the resourcepack to and check in the status event if the uuid is inside the set
ty
and remove it after
well
there's a small problem
you can see everyone who has access to that inventory
but not a specific player
Okay I am gonna try
best idea? store a Map<UUID, Inventory> or smthn to hook the player's UUID to the target inventory
oh well thats kinda sad
but ill try that
i still find this the best way to check for clicks besides some stupid things
https://www.spigotmc.org/threads/creating-guis-the-right-way.156378/
InventoryView?
I've seen that before
what is it for?
It's basically the top and bottom inventories combined
Inventory is just one of the two inventories
well @lavish hemlock the only reason I need a player is because when i create the gui I do public Inventory GUI(Player player){ return gui; }
Player#openInventory() will return the InventoryView and the InventoryView is fetchable in an InventoryClickEvent
They're == comparable as well last I recall
makes sense
why would it create multiple instances? lol
I made this a return so i can check if the inventory clicked is this one
are there any other ways i could do that though?
so what is your GUI (should be gui btw) method for?
lemme send paste bin of my code
wow a sane developer xd
you should see the people who were in here last night
multiple people posted errors without the first line
AKA the most important part of the error that tells you the actual type and message of the error
hehe i like bukkit has its own Consumer<T>
Pre-Java 8
well that and the fact that it's necessary for cancellation
unless, well
you wanted to make cancel a default method
otherwise it violates SAM requirements
what's SAM? 🥺
single abstract method
i already know SRP but yeah
the requirements for an interface to be able to be used as a lambda
aha
AKA a functional interface
never understood the FunctionalInterface annotation
an interface, if declared with @FunctionalInterface, must only have 1 abstract method
meaning one without a body, of course
that's cuz that method is used to call the lambda belonging to the interface
but if you just make an interface with one abstract method it also works
and it wouldn't make sense to have more than one abstract method, as there's no syntactical representation for it
hmm
ye, but @FunctionalInterface is used to enforce that as well as state that it is designed as a functional interface
without the annotation, compilers won't error if you violate the SAM contract
Java's got a lot of "warn/error if I have this and I do something bad" annotations
e.g. @Override, @SafeVarargs, @FunctionalInterface
wait
@lavish hemlock
could i check if ``` public void InventoryClick(InventoryClickEvent event){
}```
is an instance of GUI?
cant you use an interface with 2 abstract methods as lambda?
nah
replying to this btw
you'd have to do new MyInterface {}
I think that's the syntax at least
you can 1 abstract method but many default methods
I dunno honestly, it's a bit hard to understand your code...
but you cant have 2 abstract methods
i have tried that, didnt work
ye Pulse is right
did u get error message or what?
Bukkit's scheduler tasks require anonymous class usage tho
no it just didnt work
welp thanks for even trying in the first place
i find it so stupid that when i import the consumer for some of the bukkit methods i have to use the god damn bukkit one
in most cases i can just use the method reference
but still stupid
how do I create recipes?
This is my code
public void HarvestCheck(PlayerInteractEvent e) {
double rng = (int) (Math.random() * 10);
Block b = e.getClickedBlock();
Player p = e.getPlayer();
Material[] materials = {Material.DIAMOND_SHOVEL,Material.WOODEN_SHOVEL,Material.GOLDEN_SHOVEL,Material.IRON_SHOVEL,Material.NETHERITE_SHOVEL,Material.STONE_SHOVEL};
if (b.getType().equals(Material.GRASS_BLOCK)) {
p.sendMessage("blok");
if (materials.toString().contains(e.getItem().getType().toString())) {
p.sendMessage("itm");
if (rng < 5) {
p.sendMessage("yes");
b.getWorld().dropItemNaturally(b.getLocation(), rock);
}
}
}
}
i just use it because it doesnt have an andThen method
which i dont need
lmao
people are gonna flame you
ah bruh i switched to it over 10 minutes ago
but functional composition is great :(
how do I create recipes?
ShapedRecipe or ShapelessRecipe
regardless of the Java interface having additional methods, said methods are default and mainly just utils
Thats helpful
methods are part of the classes they're declared in and not the instances, so it makes no real difference in performance
and it's less clean to use Bukkit interfaces over Java interfaces
it says
You have to use exact choice iirc
you might need to use a different constructor then :p
whaaaaaa
well
why u testing for all shovels?
i'm tryna use this code to show the health of a player below its name but it doesn't do anything
private void createHealthBar(){
Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
Objective objective = scoreboard.registerNewObjective("health", Criterias.HEALTH);
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
objective.setDisplayName(ChatColor.RED + "❤" + ChatColor.GRAY);
}
lemme send something useful
e.getPlayer().getInventory().getItemInMainHand().getType().toString().toLowerCase().contains("pick")```
whats a NamespacedKey then
namespace + resource key
namespace being something like minecraft or your plugin ID
resource key being, well, the key of the resource (like dirt)
never used spigot scoreboards, i've followed a guide online
what do you mean with theres no health in it
@quaint mantle
@EventHandler
public void HarvestCheck(PlayerInteractEvent e) {
double rng = (int) (Math.random() * 10);
Block b = e.getClickedBlock();
Player p = e.getPlayer();
if(e.getPlayer().getInventory().getItemInMainHand().getType().toString().toLowerCase().contains("shovel")){
if (b.getType().equals(Material.GRASS_BLOCK)&&e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
p.sendMessage("blok");
if (rng < 5) {
p.sendMessage("yes");
}
}
}
}```
works
how do i check which slot was clicked in an InventoryClickEvent?
I believe there's an index
like uhhh
there's probably a getSlotId
but you'd have to do some math to extract the X and Y from that, if you wish
getRawSlot?
ah, getSlot would work I think
Why when i start a thread from a spigot plugin the server doesnt finish the start process?
It get locked
I did what the tutorial said. what
You're probably doing something between threads that causes a deadlock.
thanks
If you don't know what a deadlock is, don't use concurrency.
does it work?
uh ill see
yes thx
I dont understand. But im calling my library from the plugin, that library start a thread for the sockets
Can be that the problem?
Honestly I have no idea without seeing your code :p
But the likelihood is you're doing some kind of check that requires mutable state across threads, which is a big no-no.
stonks 👌
is this an adverstiment
can you send the coma used for code?
pls help
you are now officially a Kotlin dev @quaint mantle
...What?
`
Thanks
it's called a backtick
js 🥺
a comma is a ,
I didnt know the name thats why btw
what you were thinking of, which is similar to a backtick, is an apostrophe '
Server class (Called by the plugin)
public class Server {
protected ServerSocket server;
protected Connection connection;
public void connect(Integer port) throws IOException {
this.server = new ServerSocket(port);
System.out.println("[Server] Connection has been opened on port " + port);
while (true) {
new Thread(this.connection = new Connection(this.server.accept())).start();
}
}
public void disconnect() throws IOException {
this.connection.close();
this.server.close();
System.out.println("[Server] Connection has been closed");
}
public Handler subscribe() throws IOException, ClassNotFoundException {
return (Handler) this.connection.getInput().readObject();
}
public void publish (Handler handler) throws IOException {
this.connection.getOutput().writeObject(handler);
this.connection.getOutput().flush();
}
}
Connection class
public class Connection extends Run {
protected final Socket socket;
protected ObjectInputStream input;
protected ObjectOutputStream output;
public Connection(Socket socket) { this.socket = socket; }
@Override
public void execute() throws IOException {
System.out.println("Client " + this.socket.getPort() + " has connected");
this.input = new ObjectInputStream(this.socket.getInputStream());
this.output = new ObjectOutputStream(this.socket.getOutputStream());
}
public void close() throws IOException {
this.input.close();
this.output.close();
this.socket.close();
}
public ObjectInputStream getInput() { return input; }
public ObjectOutputStream getOutput() { return output; }
}
holy shi-
actually decently clean I'm a bit impressed but let's see
btw if you declare close, I recommend implementing Closeable
allows you to try-with-resources an instance of said closeable class
I think the server get locked when calling the new Thread() from Server.class
What do you think?
whats wrong here?
lol that while loop looks kinda uh yeah
yeah I was thinking about that too
instantiating a thread is an expensive operation, and might cause the server to slow down exponentially
I put it because i need a thread per socket
so creating a thread basically every tick is...
How i can do it? because every new socket its a new thread
hm well I understand the pattern
you should probably use an ExecutorService (Executors) btw
structured concurrency ftw
ftw?
for the win
ah ok
Executor executor = Executors.newFixedThreadPool(2);
executor.execute(connection);
right?
Verano idk if you are aware but there is something called AsynchronousSocketChannel
holy shit really?
Yeah lol
Anyway basically while (true) on the main thread will hang the server permanently.
At least in newer versions 
I use java 1.8 thats why
incoming Java 8 hate
I think it’s a thing in java 8 also
incoming Maow defending Java 8
Lol
listen Java 9 made it hard to do Java metaprogramming so I hate it >:(
Also got its server variant AsynchronousServerSocketChannel
Touche
I cant use another java, because the server fuck that its compiled with a recent version that the spigot doesnt support
🤔
In conclusion the while (true) its locking the server?
Oh yeah, BuildTools versions require you to have specific versions, is that what you're talking 'bout?
Yep.
whats about some higher java
I think spigot only support java 1.8
Nope.
It works on MC 1.16+ so it has to run on newer versions.
👀
can some one help me test if an inventory opened is a inventory that was created?
Anyway you probably need to start your Server on a separate thread from the main thread.
That it used when you are working with IO selectors
So i need to start my library in another thread?
Let me send my main pl class
Well Minecraft's server is running on the same thread as your Server, so when you run while (true) on that thread, it pauses the thread to perform actions indefinitely.
So i need to remoeve the while true
How i will wait for the socket connection if i remove the while?
No, you just need to launch your Server on a separate thread.
Plugin class
public class Main extends Plugin {
private static Main instance;
private Server server;
@Override
public void onEnable() {
instance = this;
this.server = new Server();
try {
this.server.connect(3021);
} catch (IOException ex) {
System.out.println("[Server] Has thrown an exception while opening the connection");
System.out.println("[Server] Exception: " + ex);
}
getProxy().getPluginManager().registerCommand(this, new Test());
System.out.println("[Server] Has been enabled");
}
@Override
public void onDisable() {
try {
this.server.disconnect();
} catch (IOException ex) {
System.out.println("[Server] Has thrown an exception while closing the connection");
System.out.println("[Server] Exception: " + ex);
}
System.out.println("[Server] Has been disabled");
}
public static Main getInstance() { return instance; }
public Server getServer() { return server; }
}
I will use this library for a network
That hate using data brokers
😂
But if it works i will publish it free on my gth
I think you can do
new Thread(() -> {
this.server.connect(3021);
}).start();
You do it for your socket connections, but not your server.
Ahhhhh
So, you probably need to do it for your server.
Im an idiot
I mean not really
sure it is
So the while should be on the server class
I'd argue otherwise, this code is actually quite clean compared to most other "beginners" I've seen.
but a socket is usually for single threaded stuff
Im just starting on java. I have 15 years
I've used a socket with multithreading in the past :p
public void InventoryClick(InventoryClickEvent event){
Player player = (Player) event.getWhoClicked();
if(event.getInventory()==GUI()){
player.sendMessage("hello");
}
}
public Inventory GUI(){
Inventory gui = Bukkit.createInventory(null, 36,ChatColor.RED + "Test Screen" );
ItemStack glassEmpty = new ItemStack (Material.PURPLE_STAINED_GLASS_PANE);
ItemMeta glassEmptyMeta = glassEmpty.getItemMeta();
glassEmpty.setItemMeta(glassEmptyMeta);
gui.setItem(0, glassEmpty);
return gui;
@lavish hemlock I changed the code abit to what I think might work but this doesn't? could u maybe explain why.
Bragging ^
Maow for just being new on Java do you think that i have good coding? Like code cleaning, etc
completablefuture :((
Ye
yeah well usually a SocketChannel will do better
Yes but i dont understand IO selector usage
I thought a SocketChannel was for communicating on a socket?
CompletableFuture might actually create a new thread
Socket is sort of an io device
socket channel is the non blocking variant
It's part of the NIO Channel API so, I assumed it was a replacement for using a OutputStream/InputStream on a Socket.
I havent explain but the Run class i have created using a java trick. Because with normal Runnable you cant thrown exceptions
Maow, in theory my plugin class should create a new thread for the server starting. And the while true should be there or should be taken out?
It's... been done before. https://github.com/pivovarit/throwing-function
?
Well the while (true) needs to be there otherwise you can't have more than one connection.
i copied some classes over but i dont use it mainly cause it seems evil and its for lazy devs XD
Well
When you've done
A try/catch around your method that declares a lambda
And then you have to put another try/catch in your lambda
And, if you have nested lambdas, even more try/catches
You kinda give up on living.
lol
I wish Java's lambdas took their parent scope's exception tables :p
Maow its should be:
new Thread(() -> {
this.server = new Server();
this.server.connect(3021);
}).start();
Right?
I could probably create a compiler that does that tbf but I'm lazy.
...I'm not sure, there's no reason to do so.
I mean, for the new
For the connect, yes.
Ah ok
So let me change it and tried again
Then i will try implementing a event-listener system like bungeecord one. For when the connection its opened, closed, receiving
But i couldn´t find anything on google. It shown other things
Really thanks!!!
Java Design Patterns
You and Conclure help me a lot
This is an event listener ^
Really good people here
Maow for the Server class connection closing i should stop the thread?
Not sure, I don't know if the GC does that automatically. Probably, though.
By the way this doesn't touch on an Event class, but for that you'd basically just create a class that contains all the data the listener needs for that event, so not particularly difficult.
one final question I see lots of people use Inventory.getName
but this doesn't work anymore
how could I possible work around this?
You can still grab the title of an inventory during interaction using the inventory view
ah thanks
lemme try this
any way to remove this message?
um
well
lemme check
but i don't think it is possible
@eternal night ur a life saver
does anyone knows what the &6 color is in ChatColor?
which ChatColor.
ah wait found it in the class
gold
event.setCancelled(true);
if(item.getItemMeta().getDisplayName().contains("§6")){
do stuff
}
}```
This works but if the player shift clicks it works some times and lets them take the item
how can i fix this
and by sometimes i mean 1% of the time
but still a bug that needs to be fixed
also monitor the drag event
probably with packets
Also check the actions and update the players inventory.
How can I remove / change entity recoil after hitting it, but to get damaged? I need to cancel the event and add my own velocity and damage is there any other option?
you could put their Attribute Knockback resistance to 1
Maybe cancel interact event?
A new question how does closeable works with socket?
Because when i use closeable when data goes out/in an exception is thrown
any plugin for prefixes for bungeecord?
I have luckperms but EssentialsChat doesn't support it because it is on the bungeecord
Wait wait
Explain again, you should put luckperms on Bungeecord and on the servers. Then use LPC (LuckPerms Chat) on every server
Yes you can
I think you should the event InventoryClickEvent
Then check if the slot equals to 9
And then block it
I did that but it doesn't work
You should do it via Item name and if it have lore, via item name and item lore
guys how do you test plugins
Putting it on servers btw
i meant like trying to avoid bugs, and that stuff
Try this:
- Check the item slot he clicked
- Then obtain the item stack of what he clicked
- Compare the item stack with your item stack
Explain more please, i dont understand u
like what circumstances do you check when doing doing stuff since i always miss like a small detail when trying implement a function (for example, it doesnt work with multiple players, or it doesnt work in the nether etc..)
Definitly i dont understand what you make reference
like bug testing
I put the plugin on the server i test it manually if I see a bug i tried to understand why happen and then how i can fix it
Sometimes when i dont find any bug i send the plugin to friends so they have another opinion about the plugin
oh you have friends :)
Thanks bro!! It worked. At least the connection has been stablished
congrats 👏
Now null pointer
I have that idk why
I have been looking for a while but i cannot find what happen
how can i make custom chat messages?
yea
Use the PlayerChatEvent
I think the name i said its for bungeecord
ok
Yeah its called AsyncPlayerChatEvent on Spigot
what do i do then?
I recommend you reading the javadocs of the event
ok
Or you can look for code snippet on spigot
use the async one
Yeah i already told
ty
Amazing seriable its not working on Java IO 1.8. I get the object from input/output null
Probably isn't, but just to make sure, your object shouldn't be transient
yes it works to save inventory to base64
you figured it out yet?
==
to compare numbers, what the heck are you doing there?
getting an ItemStack and trying to compare it to 8?
You do know you can just use e.getCurrentItem
first id check whether the item has meta and has lore or youll get returned null
unless you know for sure that the slot has lore
yeah check for that as well
is it possible to get a list of registred command by your plugin or do you need to save them yourself?
if (item != null && item.hasItemMeta && item.getItemMeta.hasLore)
i mean you can probably using reflection but its easier to store them yourself
item.hasItemMeta != null
oki
item.hasItemMeta is a boolean
e.getcursoritem
or wait no
yes cursoritem
do that instead
currentitem is during shiftclick
its e.getCursor()
Not working btw. Only the connection get stablish. But sending an receiving not working. Here is the error.
Unexpected exception while parsing console command "test out client-1 Hola"
Caused by: java.lang.NullPointerException at dev.alex.net.api.Client.publish(Client.java:29)
Im sending an serializable object with 2 parameters (sender, message)
how can I set the velocity for entity so that it moves in the direction the player hit?
get vector from player to entity and set entitys velocity to that
Does anyone know why you get a NullPointerException with sockets?
Im seding a serializable object
something in line 29 is null
this
public void publish (Handler handler) throws IOException { <- That its line 29
this.connection.getOutput().writeObject(handler);
this.connection.getOutput().flush();
}
The method its not null
Literally its saying that a method its null btw
which line is 29?
a method definition can not be throwing an NPE. thats not line 29
?paste your full stack trace
hello how can i change a potion's duration in PotionItemMeta (1.12.2)
i can extend it but how to decrease
how do I setup a MySql database in localhost ?
There is something up with yoru line numbering as line 29 can not cause an NPE, line 30 can. Either connection or handler are null
Do chunks not unload in 1.17.1?
they do
Do you want full code?
hmmm
wait i will send full client class and connection
just check connection
can anyone help me ?
I have my view distance set to 4 and it has 908 chunks loaded and when I walk out in the world it gets bigger, but never goes down.
Walked forward a big and now its at 921 and does not go down.
hmm 1012 and still not going down, very werid.
I said to "check" the connection
How check the connection?
sysout this.connection == null
Its connected because when i close my lobby console on the proxy appears a socket exception saying connection reset
um, what the heck is this? new Thread(this.connection = new Connection(socket)).start();
Per socket you need a new thread
this is not how threads work
= is actually an expression (mainly bc it's required for the init of a for), meaning it returns the right-hand value.
Now i dont know what the fuck but the connection its no getting stablish btw
Little known syntactical fact btw.
maow do you want all the source code?
I'm sorry I'm a bit busy atm.
Ahh ok
No problem
I will tried on my own
I really get angry because the connection its not getting opened and there is no exception thrown
Its amazing programming
how do I check if it is nighttime
Is there a way to recreate the deletion of the players chat like with F3+D, without just spamming the player with new empty lines ?
No
Since it's client side and not server side I presume ?
Does anyone knows a good article or documentation about the PerlinNoiseGenerator. I understand the basics, like generating a 2D heightmap, but i dont know how octave, freucenc and amplitude change the result
Hey guys! I want to delete a file but its in use. What can i do?
forcedeleting it
How can i do that?
When i try this i become an error, that the class can't be found.
try {
CraftTravelAgent = Class.forName("org.bukkit.craftbukkit"+Utils.getVesion()+"CraftTravelAgent");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (CraftTravelAgent == null)
return false;
TravelAgent travelAgent = null;
try {
travelAgent = (TravelAgent)CraftTravelAgent.getField("DEFAULT");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
how can I cast Field to a TravelAgent? Those reflections are too complicated 😅
whats the point of making a field private if you can access it using reflections
It's not in the Spigot API, but I need to use it to make PlayerPortalEvent
I don't need it in newer versions, but in 1.12.2 there is no other way
Reflections are hellla lot slower than simple reference read access
That's why I prefer PacketDataSerializers for Packets, they allow me to work without reflection overhead
Honestly they aren’t that slow those days
Especially if you cache the fields and methods
yea but still, if there's a way to not use them, exploit that way
unless its heavier to compute ofc
also by not using reflections you avoid all utility class mess with try catch blocks
there is probably one more way, but I don't want to make changes in spigot.jar
the problem is, I don't know how to cast that Field thing
TravelAgent is an interface
Can someone help me? I'd opened a Cross server for my friends and me and I installed a skills mod, but whenever they try to buy a skill point with xp they can't (in bedrock mobile). How can I solve this?
points-purchase:
material: 'BOOK'
name: '&2Skill Points: &e%points%'
slot: 4
lore:
- '&eRight Click &7- Buy 1 for &e%pointsprice% &7level(s).'
- ''
- '&7These are your skill points.'
- '&7You can use these skill points'
- '&7to spend them on individual skills.'
- '&7You can spend your experience levels'
- '&7for skill points.'
right-click: true
can you help me
you can try to run through online yaml parser
to see if there's an syntax error inside yaml file
method inovocation is till hella slow, even with caching
smae with fields
how can i set any enchant to for exaple block item or other type?
I mean it’s certainly slower that regular method calls
what is the best way to access CraftTravelAgent on 1.12.2? I don't think there is other solution other than editing server jar
But it’s been optimized a lot in modern java
How to let the player execute the command as the OP?
the best way is actually adding spigot server artifact and accesing a class directly. Why do you need CraftTravelAgent?
PlayerPortalEvent portalEvent = new PlayerPortalEvent(player, player.getLocation(), loc, (TravelAgent)travelAgent);
Bukkit.getPluginManager().callEvent(portalEvent);
guys i have some servers, from hub to another mode it's fine but from the other modes you can't go back, what can i do?
aha
Then use reflection, it isnt that bad. Probably better than depending on nms only because of single feature
I know I should use the reflection, my question wasn't about that 😅
here is it
please help me
I think it was related to my message
time for change the docs then xd
its packet level magic
Use field.get(null) and then cast given object
i basically wrote synced server just for this
thanks
are you using the packet or the method in spigot?
Why the player cannot get the result item from the anvil (PrepareAnvilEvent)
event.setResult(result);```
Is the level cost 0
I did not set any costs, I think it will be the reason, but I would like the cost to be natural, i.e. the higher the number of enchants
but how can i make it?
is there any lib that can convert stuff like 1m and 1,000,000 to 1000000?
is it safe to do travelAgent.findOrCreate in async/separate thread? It does seem to lag the server for a few seconds
Not that I know of but it would be very easy to write
Let me give it a shot on my phone
How can I fix this erro with reflection:
java.lang.IllegalAccessException: class de.neo.jagil.cmd.GuiExportCmd cannot access a member of class org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaSkull with modifiers "private"
--illegal-access=permit is already set.
My Code:
((SkullMeta)is.getItemMeta()).getClass().getField("profile").setAccessible(true);
((GameProfile)((SkullMeta)is.getItemMeta()).getClass().getField("profile").get(is.getItemMeta())).getProperties().get("texture").iterator().next().getValue(); // this line causes the exception.
You should cache the field object
private static String suffixes = "kmbt";
public static long parseFormattedNumber(String str) {
int pow = suffixes.indexOf(str.charAt(str.length() - 1));
long multiplier = (long) Math.pow(1000, pow + 1);
if (pow != -1) {
str = str.substring(0, str.length() - 1);
}
return Long.parseLong(str.replace(",", "")) * multiplier;
}```
@visual tide
Hmm, clever
Oh wait
That was for Durations
I wouldn’t have thought of that, I would have used a switch
:0 noice
tysm!
same
Of course, I can't resist a fun challenge like that even if I'm on my phone
I mean, this is a bit slower than a switch but it's shorter code
Didn't want to type any more than I had to on mobile
If you wanted it to be clean and fast you could use a map or array
But I feel like this isn't especially performance critical anyways
Not that indexOf on a 4 character string is really that slow, lol
yeah it's for a withdraw command, which hopefully doesnt have to be spammed
Oh yeah commands aren't performance critical
Unless you're running hundreds of them per second in which case I have some questions for you
server owners with cmd blocks go brr
@ivory sleet 🤦
I can just do
if(!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
💀
can you even use plugin commands in those
nah
Another 💀 for you
wait wouldnt be a problem anyways since the block's not a player
yeah, both me and Pulse posted that like several times lol
i've never really been in a situation where i've needed it, and most of those that i see seem more trouble than they're worth
Asks for a library to do basic parsing, doesn't use a library to handle commands
It's not really about needing it
The safety and simplicity really helps
And there are some that are very easy to use
cough
yeah but if you put basically your whole plugin.yml in a method call it's not more readable or simple than before
I never saw it I left a few messages after the one I replied to
Ah but you see
It is
is it?
Here can I dm you
yeye
yapperyapps for reference here
👍
can someone tell me why dont these two uuids equal
when should i be using what
oh ok
how can i get the texture form player head? (itemstack)
hi everyone
i have been trying to add a custom config file to cache player data before saving it to mysql database
but
it wouldnt work
i even followed a few tutorials
and it just gave errors everywhere
can someone help me out
^^
For some reason I can't get chunks to properly load when unloading/reloading the world very fast
yeah but
Has anyone had this issue before and knows how to fix it?
i still wanna learn how to use custom .yml file lol
and i dont know how to cache into memory ;-;
ok so i tried learning about classes and stuff ,
i'll have to do something like this ?
FileConfiguration config = YamlConfiguration.loadConfguration(file);
}```
and then i'll be able to use it on other classes ?
still dont know how tho lol
what are you trying to achieve @mortal hare ?
what
how do that
also
i get this error
every time
im just asking if non living entity for example arrow can be part of the scoreboard team
i dont think so
not sure tho
what api version are you using?
make sure you've imported the right YamlConfiguration class
1.8.8
either 1.8.8 doesnt suite static method for this
I remember, when I worked with command blocks i added armorstands to the team
youre missing an i lol
love ya
thanks
ArmorStands are living entities
But yes I believe you can add any entity
@west oxide something like this will probably work
public final class Main extends JavaPlugin {
public static FileConfiguration data;
@Override
public void onEnable() {
// Plugin startup logic
File folder = getDataFolder();
if(!folder.exists())
folder.mkdir();
File file = new File(getDataFolder() + "/data.yml");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
data = YamlConfiguration.loadConfiguration(file);
}
@Override
public void onDisable() {
// Plugin shutdown logic
File file = new File(getDataFolder() + "/data.yml");
try {
data.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
subComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.YELLOW + "[Teleport]")));
For the life of me I cant figure out why this is throughing an error, but only due to the "ChatColor.YELLOW + "[Teleport]"" part, the rest is fine.
Try this
subComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.YELLOW + "[Teleport]").create()));
ffs, I forgot the .create(), thx m8
np
it seems to be working, Ima try it out now
yup, colors work fine
how do I check if it's nighttime
Get the World object first, and use the method getTime()
Bukkit.getWorld(WORLDNAME).getTime();
From there you can check if the time is day or night
oh okay
i'll read it and try to recreate
ur approach is very different from every tutorial i have seen lol
why if I have event.getInventory().setMaxStackSize(1); I can give more with shift anyway?
It's possible to get a player's right and left click block actions.
Is it possible to get their pick (middle click) block actions?
declaration: package: org.bukkit.event.player, class: PlayerInteractEvent
I don't think there is an event for middle click
It is handled clientside
rip
When in creative mode the server basically just lets you do whatever with your inventory
You can still kind of detect it though
I have done it before
Let me dig up the code
?paste
😮
Basically, just check for when InventoryCreativeEvent is fired
Check if it's a hotbar slot and their cursor is empty
Then check if the block they selected is the same as the one they are looking at
Probably a dumb question, but does inventorycreativeevent fire in gms?
It's not perfect or foolproof but it should work
No
rip... the primary intended use case for my attempt to detect it is survival
Basically trying to find a way a player can interact with a block without right clicking it or left clicking it (both of which are already used for something else)
Hmm
I don't think that fires any event
Well, it would actually
The event for changing their hotbar slot
I guess the best you could do is see if they change their selected hotbar slot to be holding the same block as what they are looking at
That would be even less reliable than the creative mode one though
I'd imagine so
at me.wally.guilds.GUIHandler.Lore.getLore(Lore.java:35) ~[Guilds-1.0-SNAPSHOT.jar:?]
This is the line you need to be looking at
Lore.java, line 35
ah i just found it
Trying to cast string to int
nah it was a logic error
actually middle click should be possible to detect. I swear i saw it somewhere
only in inventory events
isnt there an event for that?
what about PlayerInteractEvent ClickType?
wait nvm
or InventoryCreativeEvent
he was asking for middle click outside inventory
that doesnt exist
like pick the block
well he can detect that by checking if the block is changed in his main hand
creative and inventories
but it could be tricky
this could be a solution
By any chance would anyone know why this would be happening? It happens after I moved my packages around and all of the sudden now when I want to import anything from this package it just absolutely refuses? It just tells me that the import doesn't exists, however when I type the package import in manually it shows up and I can tab complete it, ill show in next screenshot
recompile?
otherwise invalidate caches
Can i ask a question to you??
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Create a thread in case the help channel you are using is already in use!
is there any data structure in java or bukkit utils that could represent 3 floats in it (for storage of rotation)
thats funny asf, it compiles but it still shows up as invalid in the IDE haha
A Bukkit Vector, dovidas
that stores doubles
I think ill do that i knew there was something like that or redoing the project index's ty
(not java.util.Vector, that's a Collection)
Oh, if you specifically want floats, then no.
Vector stores doubles not floats, i don't want to cast it
Would be useful to implement some easy way to communicate on bungee-spigot/spigot-bungee networks? Something more sofisticated over than plugin message channel?
im currently using vectors
Vector species API is still in incubation so there's nothing native
J18 will have one
Thats good was grammar
but without any block stuff
bully
Im sorry
oh well i just turned you into not
Does anyone have problems with intellij ? like you change a method name you are calling from other class and until you close the class and re open the error go out
It’s not that easy
Conclure
Every backend server is essentially a server socket
that goes with bungeecord too
So you can’t establish another one
As the port is already reserved
You mean Redis?
People just setup Redis pub/sub lol
Yeah could use redis pub sub, Kafka or rabbitmq
I think it should be possible to hack the spigot and proxy netty to inject a new channel for sending/receiving data between proxy-server and server-proxy
But i cant find where the spigot has a getter for the Netty class
it would have the same limits as a plugin channel lol
if you want a message queue use a message queue
right tool for the job and all
Why netty should be same as plugin channel?
You can use it with/without players
Btw
Plugin message channel its to work with the client
No that’s not how netty works
aka shitty message queue
well how else are you going to use it without players
Via server connection
if sockets work without players netty that its based on sockets should work
Sure it would be possible for bungeecord to be a server socket whilst backend servers setup up their own sockets and connect to bungeecord
But then again, there are way better alternatives
Thats how my library will work
why
But idk why im getting NPE when the connection its open
well something have to be null
It happen when sending and receiving so that fuck me a lot
why would we use your duct-taped socket library when there are tools used by billion dollar companies that work totally reliably
I will put sout on every method to see what the fuck its happening
Or send the code here and we could see what’s the trouble
So you dont tried to help me on the air
?
Library:
https://paste.md-5.net/onusuqoqeq.java - Server (From my library)
https://paste.md-5.net/ibucofalup.java - Client (From my library)
https://paste.md-5.net/tiherugika.java - Connection (From my library)
https://paste.md-5.net/ohowowayit.java - Handler (From my library)
Plugins
https://paste.md-5.net/mimisinaso.java - Bungee plugin (Represent the server)
https://paste.md-5.net/ahojanefep.java - Spigot plugin (Represent the client)
https://paste.md-5.net/qanixiduta.java - Spigot command (Where the error occurs)
Error
https://paste.md-5.net/xiheruvuqa.java - Spigot command error
There you have all conclure for help
The erorr happen on line 30 on my Client library but line 30 its the method declaration
So im weird right now
a method declaration can't be null
are the version in your IDE and the one you tested the same?
Im not testing in the ide
Im testing the server plugin on a bungee and the spigot plugin on a spigot server
read again what i wrote
is the version of your plugin equal to the version of the plugin you have on your server?
Yes
so if you would compile it would be the same jar as on your server?
Yes
I have looked again the error its on line 30 on method publish, that line is: this.connection.getOutput().writeObject()
So probably the stream are not getting open
so check if either the connection or the output is null
I have made a command for checking that
GodCipher an error its thrown
>test info
[19:53:02 INFO]: Client info
[19:53:02 INFO]:
[19:53:02 INFO]: Connection: null
[19:53:02 WARN]: Unexpected exception while parsing console command "test info"
org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin Client v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[Spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[Spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [Spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [Spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [Spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [Spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [Spigot.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_301]
Caused by: java.lang.NullPointerException
at dev.alex.net.spigot.commands.Test.onCommand(Test.java:20) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Spigot.jar:git-Spigot-db6de12-18fbb24]
... 8 more
Hum now that i see connection its null, so the streams are null
Now i will have to discover why connection its null
a
Hum i cant understand why its null
while (true) { That is not good.
in Server
Why?? if i take out the server will accept only 1 connection
Your server is going to fall on its ass as its spawnign new Threads constantly
a while true loop around a new Thread? Once thats called its death
ServerSocket::accept or whatever it’s called is awaiting a socket to connect to the server socket
ah
So what i can do? I have been checking all the client and the connection i cant find the reason why its null
make a little more sense
the loop wait for connections and when a new its received it create a thread for that connection
Verano what about publishing it all on GitHub or smtng
For you to see it?
snippets are so hard to read when its this complex
for example, if no socket is accepted in that Thread, no connection is made and connection remains null forever
move your System.out.println("[Server] Connection has been opened on port " + port); message inside the While, after the new Thread
then you will see that no connection is ever made
There you have
Yuh, its probably smart to have something like
AtomicBoolean shutdownSignal = new AtomicBoolean();
CountDownLatch latch = new CountDownLatch(1);
Thread socketFactory = new Thread(() -> {
while (!shutdownSignal.get()) {
Socket socket = serverSocket.accept();
//TODO
}
this.latch.countDown();
}
socketFactory.start();
And then if you want to await destruction
latch.await();
move your System.out.println("[Server] Connection has been opened on port " + port); message inside the While, after the new Thread
then you will see if a connection is ever made
ok
