#help-development
1 messages · Page 1605 of 1
did they even have discord server?
i actually dont know
alr found the packet i think
now to find out how to use it?
or send
thanks you!
found out how to use packets but idk which packet it is xD
google that what you want to do
for example, I want make only certain player to see entity,
google spigot personal entity packet
or etc
i know the packet but idk how to get to it
this one
I think protocol lib has packet wrappers
It might be like PacketPlayOutShootArrowWrapper or PacketPlayOutShootArrow or something but don't ask me
There's the entity metadata lol
nah its not animation
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
PacketContainer packet = pm.createPacket(PacketType.Play.Server.BLOCK_ACTION);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, p.getEntityId()).write(1, 5);
my code rn
not working tho
also i get this in chat when i reload?
Make sure u have installed protocol lib on your server
ye i have
And probs make your plugin depend on it
Add to your yml depend: ProtocolLib
I think
Try this
hi im having a problem with packaging my plugin in maven, and its saying that it "cannot access org.bukkit.Bukkit" how can i trouble shoot this?
Pom.xml?
what do i need to have in it?
yeah
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
all right
Did it work?
no :(
he was talking to me
Remove 61-64
Oof what's not working the packet getting sent ?
I can't really help much I'm on phone and know nothing about protocol lib
im just getting errors in console
Like what
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
PacketContainer packet = pm.createPacket(PacketType.Play.Client.BLOCK_DIG);
packet.getModifier().writeDefaults();
packet.getEnumEntityUseActions();
packet.getModifier().write(0, p.getEntityId());
try {
pm.sendServerPacket(p, packet);
} catch (InvocationTargetException invocationTargetException) {
invocationTargetException.printStackTrace();
}
CODE
This is the error
Hmm weird
That packet is fun
why
What server version are you using?
mc or protocol?
He's using 1.16.5
Mc and protocollib
Okay
Im trying to make it fire the bow
Firing a bow isn't block_dig
Hm ok
do u know which one then?
Isn't it entity metadata
no
ye idk i cnat find it :/
it's from client.
The client sends that packet to the server whenever it digs a block
It's bound to server.
So sending that packet to the client makes to sense in the first place
i just cant find the packet to fire the bow
You can't force a player to prime a bow iirc
I don't think you can
I saw in entity metadata a shoot arrow thing I think
There's a hacky workaround
Which is creating a fake player that's priming a bow and locking the target to that player in spectator
i need to do that or a way to cancel pulling back the bow
theres a way for one of those but i just dont know how
Bow pull animation is clientside but the client sends a packet to the server, which is sent to other players indicating <X> entity is pulling a bow iirc
if you want to cancel pulling back of the arrow, when you get that packet, check for it's ID, if it's the ID for pulling your bow back, just return or something or cancel the event
but it still might pull it back client side actually
^
so probs no point doing that
You can cancel other players viewing the animation
but other players wouldn't see you pulling the bow
Idk what the event is
But client might still render it
bc cancelling the PlayerInteractEvent just prevents it from shooting an arrow
don't cancel the whole event
im using custom arrows and spawning those
why not?
Somewhere it says about entity metadata
if you were to try to click an NPC or something whilst trying to shoot a bow, nothing would happen
The thing i want is that it doesnt pull back the bow and doesnt make u slower
Not on entity metadata
thats PlayerInteractAtEntity event
I don't think you can do that without a client side mod
this is a plugin
oh
misread it
So what's the effect you're trying to achieve?
Ah
Isn't that just not having an arrow in the inventory?
no bc the ability i made requires you to have an arrow in ur inv
bc i have a custom code for the arrows
He probably doesn't know its client side
The only way of stopping it would be a client side mod.
I dunno. I've never worked with the Java protocol except for when I fixed cats in Geyser
I mean theres entity metadata?
I feel like the effect he's trying to do can easily be done in another way
in what way?
There's nothing about pulling bow etc
i dont wanna have to use protocolLib
I just want something for the effect im trying to get
Doesnt matter how
i just want it to work xD
I see A bunch of posts about pulling a bow and people talk about this
Look into Entity Status rather than Entity Metadata
What is your goal at the end
Forget your solution
Alr so
For example "I want a bow to fire after <x> time"
I have a bow
tthat fires arrows
instantly
when u left/right click
but i wanna make it that if u hold right click
it keeps shooting with a delay that i set
the only problem rn is
that it pulls back the bow and bc of that doesnt keep shooting
so like, a gun?
I'd suggest working on the idea of using a bow without any arrows on the inventory
It never starts the animation in the first place
Although it might be hacky to send fake item packets indicating there's nothing
I saw this
Modifying that would stop the packet from being sent to other players
But it would still cause the animation client-side
One hacky thing possible is sending a packet indicating there's no arrows when the player clicks
And handling arrows separately
In 1.17 the constructor has the following params
int syncId, int revision, int slot, ItemStack stack
Not sure about 1.16
It will probably be the same Lmao
Yeah something similar
But nms uses ints instead of bytes or whatever
And protocollib is a fancy nms wrapper
Following the order on the packet
SyncId would be 0
Revision idk
Slot would be where your arrows are
And the stack would be air
I'm not too familiar with that packet as I'm only using it to make client-side lore
On another note
Does anyone know what status is sent for Block Dig when a block is insta-broken?
It isn't sending the finish break packets
Help me pls, how to use prepareitemcraftevent, may i see examples, sorry about my English
You use it like any other event
Constructor?
help?
I don't know how to use events( I want to see examples
After the variable try putting = eventStateManager.State
I can't really help then I'm on phone and it's a pain to show examples
Just search up spigot events on Google
Ok
Anyone knows how to change that message?
bungee config i guess if its not inside there i think its impossible
im using try with exception but is not working
check if a player has won then execute the runtask
Will the initialisation block run if i extend this class?
https://sourceb.in/dKNs9geXTI
if u wanna cancel
Bukkit.getScheduler().cancelTask();
?scheduler
yes there is
100% there is
You can play around with it
cancel then runTask same code
okay
Cannot resolve method 'spigot' in 'ItemMeta' ??
any one help me
meta.spigot().setUnbreakable(true);
ok ty
?
if u wanna hide it u can use hide item flag btw
the Unbreakable thing in the item makes it ugly imo
Yes, so long as you instance it
ok ty
This is how i extend it (dont bully me i started yesterday)
https://sourceb.in/tgW0JP9peQ
any one know if 8 cores and 24 ram vps good ?
24gb?
yes
You can;t instant Abstract classes
you only want abstract classes if you don;t want to instance them, only extend
How can i call the CommandManager.register(this) then?
without repeating the line over and over
your FlyCommand shoudl not be abstract
for 5 games ?
Then it trows an error related to the onCommand
Class 'Command' must either be declared abstract or implement abstract method 'onCommand(CommandSender, Command, String, String[])' in 'CommandExecutor'
luke dont bully me i started yesterday ;-;
started Java?
yeah
started development ?
from yt or google ?
Okay, first while is rough but welcome to programming 🙂
i have around 1 1/2 years of experience with Type- and JavaScript
partly
Or more functional style
a mix of both
Java is like 100% fully the class based style as you can see xD
yeah
But with less modern feel
any one have a code that when player place any block the blocks that player placed it removed after 5 s
Annotations only assign types right?
@fallow dragon stop react with this emoji
3mk just throw a runnable after 100 ticks set the block at position to air
Wym comic?
Do they allow like class manipulation ?
Like can you add an annotation and get the target class inside the annotation?
I dont know what you want here, canceling the task would be the same as ”ending the runtasklater”
Uhhh, I haven’t used an annotation for that, or maybe I’m misunderstanding sorry it’s 2:45 am xD
They’re usually for providing extra information for the compiler
ah
in TypeScript, a decorator is basically a function which has an target parameter which is the class/parameter/property/method
For what you want, check out dependency injection
Oh, hmmm
I don’t know type script or much JavaScript but you might find functional interfaces to be more at home
For Java, practice encapsulation and dependency injection and you can get your object handles in most cases pretty easily
ah okay, thanks
public final class Head {
public static ItemStack getCustomSkull(String url) {
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
if (url.isEmpty())
return head;
1.8.9 , 1.17
Okay, so first off
How can i disable collisions with entities? (1.16.5)
ihave minecraft server ;-;
Just make it for 1.17 and use via rewind
- this head for redstone pvp shop
ineed to fix head for redstonepvp head
Could be wrong but isn’t there a gamerule for this?
nope
only for entityCramming
I have no idea what you’re talking about lol but in the 6 or so years they’ve changed the way you get heads
i'm work on pvp plugin 1.8.9
and in shop menu heads you can click on head
to join like golden apple menu
so yah
Well, I’m not at a computer since it’s really late but you could drop packets if push comes to shove (no pun intended lol)
custom heads
I think that code you posted works in 1.8 but I can’t remember the exact material player head is
The short data looks right to me
ok
You should have this special tool called auto complete too that will help you find the material you’re looking for
Maybe try seeing what shows up with PLAYER, or SKULL
Just to confirm, you tried entity.setcollidable on both the colider and collided?
uhh
where would i do that
on the spawn event?
Scratch that, as I was reading the forum post people were saying it doesn’t work
One sec
Check out what the scoreboard team can do. There might be a more obvious solution but I think that will work
Probably is the most reasonable way to do it too. Lmk if you run into any trouble and I’ll help if I’m awake 👍🏼
too much work
Asking again in case anyone knows, is there any way to get the power of an explosion from a BlockExplodeEvent or EntityExplodeEvent
Is someone can help me how to launch wither skull towards player ?
Yield or radius?
from what?
from Player 1 to Player 2
I want to launch skull to all the players around Player 1
1 sec
Can someone help me with config crap?
I got two static config fields in my main class, but accessing one works fine while accessing the other results in, well, no results
but I'm using the exact same methods for both
and both files exist and are filled with data
OK
?paste code
structure_strings = getBakedConfig("structure.yml");
grimoire_data = getBakedConfig("grimoire.yml");```
```java
private FileConfiguration getBakedConfig(String configFile){
return YamlConfiguration.loadConfiguration(new InputStreamReader(getResource(configFile)));}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return (List<String>) (new ArrayList<>(Echo.structure_strings.getKeys(false)));
}//This is what works
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return (List<String>) (new ArrayList<>(Echo.grimoire_data.getKeys(false)));
}//This returns nothing
Both files exist and have fields in them. Otherwise apart from the field names everything is exactly the same
I also restarted the server
No errors in console either
What one works and which is broken?
look at the comments in the two @Overrides
the upper works the lowers broken
the lower one is also the one i added
use paste not in channel
Well does that matter in any way? I am asking for the first layer of keys
which returns nothign for that one map
switch teh file names around and see if the config breakgin switches too
k
found the issue
apparantly
to get a KEY LIST
with getKeys()
you need to have a SECOND key
behind every key you're getting
let me try something else
its the values
apparantly to get a key
it needs to have a legit value behind itself
ie a number or a string or another key
but not a string without quotes
odd but good to know
at least this one didnt take a week to solve lol
Yeah of course you need a legit value
Why not? It’s a key to a value
If it doesn’t have a value then it’s practically useless
Hello, is there a way to delay the changes between the states in player fish event? e.g: from caught to failed it's taking 10s (random number) can we change it to 30 secs?
update, you can't use 'null' as key in configs
isnt that treated as a string
ava.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "java.util.Map$Entry.getKey()" is null
u can do smthing like
Player main = p;
for(Entity et : main.getWorld().getEntities()) {
if(et.getType().equals(EntityType.PLAYER)) {
if(main.getLocation().distanceSquared(et.getLocation()) < 20 * blocks) {
Location loc = main.getLocation();
Location et_loc = et.getLocation();
double x = et_loc.getX() - loc.getX();
double y = et_loc.getY() - loc.getY();
double z = et_loc.getZ() - loc.getZ();
WitherSkull skull = (WitherSkull) loc.getWorld().spawnEntity(loc, EntityType.WITHER_SKULL);
skull.setVelocity(new Vector(x,y,z).normalize().multiply(speed));
}
}
}
speed should be smthing like 0.8
and blocks = range
should work
didnt test tho
THANK YOU I will go back to try at home, thank you very much for the help.
do u understand it tho?
yes i understood that code
@random ledge This code has some serious flaws. Iterating over all entities is not necessary for example.
I've tested it, it seems that wither skull in the beginning will go to another player's direction. But after that, the direction will turn out.
This way you can set the direction the skull will be flying in before it even gets spawned:
private static final double SKULL_SPEED = 2;
public void shootWitherSkullAtAllPlayers(final Location start) {
final World world = start.getWorld();
final List<Player> worldPlayers = world.getPlayers();
for (final Player player : worldPlayers) {
if (player.getGameMode() == GameMode.SURVIVAL) {
this.shootWitherSkull(start, player);
}
}
}
private void shootWitherSkull(final Location start, final Player player) {
final Vector direction = player.getLocation().toVector().subtract(start.toVector());
start.getWorld().spawn(start, WitherSkull.class, skull -> {
skull.setDirection(direction);
skull.setVelocity(direction.normalize().multiply(SKULL_SPEED));
});
}
Thank you very much, it works perfectly. I will take this part of the code for further study.
🙏
Hey, how would I go about making daily rewards plugin?
With a simple Map<UUID, Long> to check when the last daily reward was taken by the players.
Then when he wants to get the next reward just check if the timestamp is older than 00:00 on this day.
thanks
does inventory.getContents().size returns the amount of slots without the armourslots and the second hand etc?
I think it returns every slot, including armourslots and hands
not sure btw
I am getting this error when trying to remove info from a database
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'group = 'ee'' at line 1
at JustPermissions//com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at JustPermissions//com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at JustPermissions//com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1337)
at JustPermissions//com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2112)
at JustPermissions//com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1247)
at JustPermissions//com.imjustdoom.justpermissions.storage.SQLite.runSql(SQLite.java:51)
at JustPermissions//com.imjustdoom.justpermissions.commands.subcommands.GroupSubcommand.executeRemoveGroup(GroupSubcommand.java:51)
code is
JustPermissions.getInstance().getSqLite().runSql("DELETE FROM groups WHERE group = '" + group + "'");
and table is
"CREATE TABLE IF NOT EXISTS groups (" +
"`group` VARCHAR(36) NOT NULL," +
"PRIMARY KEY (`group`)" +
") ENGINE=InnoDB;";
Try removing the ' signs
If you just want the content of the slots that exclude the armor slots and extra content then call Inventory#getStorageContents()
saving
imma just leave it for now and come bak to it later unless someone knows why
Hello there!
According to the minecraft wiki:
Every chunk tick, some blocks are chosen at random from each section in the chunk. The blocks at those positions are given a "random tick".
Is there a kind of BlockRandomTickEvent ? If there is not, how can I detect these random ticks?
How do I use multiple classes with listeners (For example: I have 2 classes: | Main.java --- Listeners.java | and I want to register the Listeners in the Listeners.java, so how would I do that?)
I know how to do with commands (getCommand("hello").setExecutor(new Commands());) and bla bla bla
but with listeners, I dont
It's the same concept
server.getPluginManager().registerEvents(Listener, Plugin)
Are you needing a specific type of block? There doesn't seem to be an easy way of getting events when random ticks occur
But there are events for specific events, such as crops growing.
Imagine I have 2 classes (Main and Listeners), thats what I do?:
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(PlayerMoveEvent, Listeners);
}
}```
?
Yeah barriers or air blocks.
In fact I am trying to add new crops to the game
Those shouldn't be randomly ticked afaik
I dont think an event like this exists. Every tick that applies a change to a block is covered by a more specific spigot event
No, the arguments are wrong
Hmm okay, so there is a check for what blocks could get this random tick?
Interesting
You should probably create your own random tick implementation for your crops.
Alright, is there a way to get the actual random tick speed?

oups
World#getGameRuleValue(GameRule.RANDOM_TICK_SPEED) I think
Great
I don't know how I could do that without destroying performances
I would need to check every blocks of every loaded chunks, right?
Store where all your crops are and just tick those
Wouldn't it be worst if a lot of those blocks are placed?
I mean, minecraft doesn't store the crops blocks specifically
does it?
No, but that doesn't necessarily mean it's done well either 😂
You can scan loaded chunks if you want
Ah i think i know what it is. "group" is a keyword that is not allowed in SQL
But storing them, checking if they're loaded, then ticking will probably be slightly faster, just a little more messy to deal with.
Minecraft may actually know where all the crops are, probably loads/unloads them on Chunk load/unload.
may be I could just loop over all the entities
Because of the "GROUP BY" statement
I'm having issues with custom crafting through PrepareItemCraftEvents.
Do you think that would be better than looping over all blocks?
So you can do both, scan chunks when they load in, save them, tick while it's loaded, and then unload them when their chunk unloads.
No storing & you're also not scanning every chunk every random tick, seems like a decent compromise
I intercept the event and if my custom recipe matches, I use e.setResult(). When I do the recipe with only 1 item in each slot, it works fine. But if there is more than 1 item in the stack, instead of being consumed, its count increases.
Hello, i have a bungee plugin that adds spigot servers to the server list dynamically but theres one issue. When I do /server (server name) it says "You are already connected to this server!" even though I am not. I have tried making my own /server command through spigot using plugin channels and also using the bungee api to connect the player but I still get the same issue. Anyone know why?
@EventHandler(ignoreCancelled = true)
public void onTryCraft(PrepareItemCraftEvent e) {
Bukkit.broadcastMessage("r: " + e.getRecipe());
ItemInput[] inputs = ItemInput.fromStackArray(e.getInventory().getMatrix());
CraftingRecipe matching = RecipeManager.matchCraftingRecipe(inputs);
if(matching != null) {
e.getInventory().setResult(matching.getCachedOutputs().get(0).getStack()); //craft special item
return;
}
for (ItemStack itemStack : e.getInventory()) {
if(CustomItem.getFromStack(itemStack) != null) {
e.getInventory().setResult(new ItemStack(Material.AIR)); //make uncraftable
}
}
}
this is my code
Its probably a good idea to save the block data directly in the chunks PDC and then keep them in memory as long as the chunk is loaded. This way you can just have a collection of tickable blocks.
hmm that's a good idea actually
I'm currently using this lib:
Ah i see. He implemented the relative coord tracking i posted in the forum.
He is basically using the PDC to save block data in the chunk.
this only works for paper btw
unless they added pdc for chunks in 1.17
What? Spigot has had Chunk PDCs for years now.
in the API?
I thought so...
not for me
chunk does not have getPersistentDataContainer()
oh wait it does now?
man idk lol
swear it didn't have it since I spent a lot of time looking into it
Btw if you want to know how he implemented the keys:
https://www.spigotmc.org/threads/tracking-blocks-that-were-placed-by-players.500216/
welp I might try transfer over my custom block data framework to use chunk PDCs instead of my own files if that's the case
though idk how performant it is
okay so this seems really broken... https://imgur.com/Zuc4pSD
@EventHandler(ignoreCancelled = true)
public void onTryCraft(PrepareItemCraftEvent e) {
e.getInventory().setResult(new ItemStack(Material.TNT));
//
// ItemInput[] inputs = ItemInput.fromStackArray(e.getInventory().getMatrix());
// CraftingRecipe matching = RecipeManager.matchCraftingRecipe(inputs);
// if(matching != null) {
// e.getInventory().setResult(matching.getCachedOutputs().get(0).getStack()); //craft special item
// return;
// }
//
// for (ItemStack itemStack : e.getInventory()) {
// if(CustomItem.getFromStack(itemStack) != null) {
// e.getInventory().setResult(new ItemStack(Material.AIR)); //make uncraftable
// }
// }
}
if you have 1 item in the stack, it consumes it
if you have 2 items, it doesn't consume any
if you have 3 or more items, it adds to the stack instead of subtracting, based on how many items are already in the stack
the crafting logic seems broken when the recipe is null but the result is not air
I can't use vanilla recipes as they are too limiting, and custom ingredients are not supported
Custom ingredients are supported
With full NBT matching
^^ Just the output item can't have NBT
Yes it also can have NBT
But that can easily be fixed
I mean fully custom ingredients, as in we can program the logic ourselves
I may want to check if an nbt tag is between the value of 0.3 and 0.7
Well you can do that too
I tried extending the ingredient interface and it wasnt supported
You will need some NMS though
any way to do it without NMS?
Probably idk
Yes but its quite tricky and error prone
how?
Ill try a mock up
Add recipe without NBT if it matches prepare event will be fired then check NBT
Cancel event if needed
I need help getting Java 16 for 1.17 im on debian 9
?java16_linux
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
apt-get update
apt-get install -y openjdk-16-jdk
update-alternatives --config "java"```
do i have to copie those first 4 lines?
Copy all of it and run in termimal
everything?
Yes
still the same
What did running those commands tell you
private void registerCustomRecipe() {
final ItemStack result = new ItemStack(Material.DIAMOND_SWORD);
final ItemMeta resultMeta = result.getItemMeta();
resultMeta.addEnchant(Enchantment.DAMAGE_ALL, 9, true);
resultMeta.setDisplayName("§9Cool Sword ;D");
result.setItemMeta(resultMeta);
final ItemStack exactIngredient = new ItemStack(Material.DIAMOND_BLOCK);
final ItemMeta exactMeta = exactIngredient.getItemMeta();
exactMeta.addEnchant(Enchantment.DAMAGE_ALL, 1, true);
exactIngredient.setItemMeta(exactMeta);
final ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("cool_sword"), result);
recipe.shape("S", "S", "S");
recipe.setIngredient('S', new ExactChoice(exactIngredient));
Bukkit.addRecipe(recipe);
}
Results in:
mm but this won't work if I want to test for an NBT value in a specific range right
@chrome beacon so what do i do?
Nope. Custom Predicate<ItemStack> are currently not supported.
There might be a way if you want to use NMS
All I really need is for the recipe to match in all the valid cases, and it doesn't matter if there are false positives
Just add the unbreakable flag to the ItemMeta
oh I forgot about that
thx
biggest problem is I have PolymorphicItems, which means that they can be any Material
ItemMeta#setUnbreakable(true)
they are identified by an NBT tag
uh what
if there was a way to test that an item of any type has some NBT, then that's all I need I think
I know this problem. I worked on an RPG project back in the days and this was one of the issues.
Its quite tricky and i would have to look into that again.
great job!
because when registering my custom recipes I can convert them and register as a vanilla recipe:
Vanilla items are straightforward
Most custom items can just match by material
Polymorphic custom items will have to match by nbt but not by material
then do more advanced logic in the prepare craft event
I could just have a choice recipe with all materials but that might be laggy?
Then you def need NMS. Look how the Predicate from ExactChoice is implemented in NMS.
hmmmm, I have this
player.getInventory().setItem(0, new ItemStack(Material.DIAMOND_SWORD));
where should I add it?
i tried this but it should an error:
player.getInventory().setItem(0, new ItemStack(Material.DIAMOND_SWORD).getItemMeta().setUnbreakable(true));
honestly why is it so hard for them to support custom predicates .-.
Take it slow. Do it step by step. Create new variables and dont smush everything into one line.
ok
Because supporting it in a robust and scalable fashion isnt so easy. And someone has to pour in his time to do so. But you can always submit PRs yourself 😄
fair point I guess xd
can i somehow make a player open a book from his inventory? or even better, make it open one without having to put it in his inventory?
and then read it when he finishes writing it
Yes but this involves some packet magic iirc.
the "without having to put it in his inventory" thing? or the "open a book" thing?
Yes. Opening a virtual book might be a bit tricky.
ok, then just open a normal book in his inventory, can i do that?
Oh nvm. They added it to the API.
So there is Player#openBook(ItemStack) which forces the player to open that book (Even if its not in his Inventory)
thats great, i guess since its an itemstack i can write stuff to it first with some meta data or whatever
is there an event for when the player finish writing it?
PlayerEditBookEvent
And you can edit the book by getting the ItemStacks ItemMeta and casting it to BookMeta
ok thanks
Could anyone point me at some documentation about registering commands at runtime? I am aware it’s a bad idea.
You can register commands whenever you feel like it.
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Or do you want to register/unregister commands from other plugins at runtime?
I want to dynamically register them, so they won’t exist in the yml
You have to use reflection and directly add them to the command map
Thats not part of the API so there wont be any documentation for that.
You would need to access the command map directly
Reflection because PluginCommand's constructor is private I believe
Well, it's protected, not private, still inaccessible without Reflection either way lol
how can i look for something random in my config.yml file?
I want to lookup a home for a player like "homes." + p.getUniqueId() + someNumber that indicates the amount of homes the player has and idk that value + home name
Huh?
Why not do something like
"homes." + p.getUniqueId().toString() + ".amount" and store the amount they have there?
If that's not what you're asking then I don't know what you mean either
Generally you should not look for random stuff in a config. Load everything into memory
and use the collections that java provides you.
well maybe its better to loop through all their homes until i find it
I dont understand the problem to be fair. What do you want to find exactly?
Do you want to check how many homes a user has?
Reading things directly from configs in your code is slow, makes it stringly typed, and easy is to mess up with things like typo's as the IDE can't check whether your strings correspond to valid config entries
Well for starters you need a "." between the UUID and the number
Use a ConfigurationSection.
You should probably use a List for that instead of having a single incrementing number in your config path.
the homes are saved like that and i'm making a command that deletes one with the given name
Make your home ConfigurationSerializable and then just throw in a List<Home> in your config which you can later just read as a List<Home>
Might be better if you also let them name their homes. That way you can use that as the home key & they have something they can easily remember
the number is a string with a . xd
🙈

hmm everyone can have two homes and i check home many homes they already have with that number
Key them by name instead. Assuming there can't be duplicate names for a given player.
You can just count the size for how many they have
homes.uuid.homename.yaw, and so on
You can tell how many they have by looking at the size of the configuration section.
^
ki thanks
bruh what
[15:59:55] [Server thread/INFO]: [KaktuszLogistics] SHAPE: [012, 345, 678]
[15:59:55] [Server thread/ERROR]: Error occurred while enabling KaktuszLogistics v1.0 (Is it up to date?)
java.lang.IllegalArgumentException: Symbol does not appear in the shape:0
0 is clearly there
ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
BookMeta meta = (BookMeta) book.getItemMeta();
meta.addPage("some\n§cred\ntext\nhere");
book.setItemMeta(meta);
player.openBook(book);
what does it mean
is "012", "345", "678" not valid for shaped recipes?
You have to give it an Author & Title
I think you have to use letters, could be mistaken but I've only ever seen letters used in the past.
Also I assume you're actually giving 0 a value?
yes I'm trying to
How are you doing that
//generate shape
StringBuilder shape = new StringBuilder();
int num = 0;
for(int y = 0; y < r.getSizeY(); y++) {
for (int x = 0; x < r.getSizeX(); x++) {
shape.append(num);
num++;
}
shape.append("/");
}
recipe.shape(shape.substring(0, shape.length()-1).split("/"));
KaktuszLogistics.LOGGER.info("SHAPE: " + Arrays.toString(recipe.getShape()));
//set ingredients
num = 0;
for(int y = 0; y < r.getSizeY(); y++) {
for (int x = 0; x < r.getSizeX(); x++) {
ItemIngredient ingredient = r.getIngredientAt(x, y, 0, 0);
if(ingredient != null) {
recipe.setIngredient((char)num, ingredient.getVanillaRecipeChoice());
} else {
recipe.setIngredient((char)num, Material.AIR);
}
num++;
}
}
Bukkit.addRecipe(recipe);
Should print out b
ok ty Oculus
Since the unicode code point of b comes directly after a.
Also, what you are doing there is not using 012, 345, 678. int 0 does not correspond to the "0" character. The first few unicode symbols are control characters.
ayy sweet it seems to work 😄
thats what I was worried about but it was in fact doing the character '0'
The digit zero is only at u0030.
Let me show you a quick mock up i wrote. Location implements ConfigurationSerializable on default.
@Data
@AllArgsConstructor
public class Home implements ConfigurationSerializable {
private String name;
private String owner;
private final Location location;
@Override
public @NotNull Map<String, Object> serialize() {
final Map<String, Object> data = new HashMap<>();
data.put("name", this.name);
data.put("owner", this.name);
data.put("location", this.location);
return data;
}
public static Home deserialize(final Map<String, Object> map) {
final String name = (String) map.get("name");
final String owner = (String) map.get("owner");
final Location location = (Location) map.get("location");
return new Home(name, owner, location);
}
}
@SneakyThrows
public void savePlayerHomes(final UUID playerID, final File playerFile) {
final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(playerFile);
final List<Home> playerHomes = homeManager.getHomes(playerID);
configuration.set("homes", playerHomes);
configuration.save(playerFile);
}
public List<Home> loadPlayerHomes(final File playerFile) {
final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(playerFile);
final List<Home> homes = (List<Home>) configuration.getList("homes");
return homes;
}
I quite doubt that
sup
in my testing it did
as you can see here, I was printing recipe.getShape()
And what if you were to cast int 23 to a char?
no idea for double digits
yea, it works, but the problem now is that you can only open a Material.WRITTEN_BOCK, not a Material.WRITABLE_BOOK, which is what i need. i guess i will have to use protocollib
im not saying its right, im saying thats what Java did
I'll have to test it later
This only works because '0' just so happens to have the index 0 on the ascii table
tho this guy says its not possible anymore, so... i guess ill make the user write manually a book and then use it, whatever, it will only be used by admins, not players
Yeah I don't think it's possible to open a writable book 😦
yeah my bad so maybe it was working same as in C
but its weird that doing setIngredient((char)num) complained about symbol '0' instead of the ascii symbol at index #0
if i have an itemstack in my hand i store the reference to that object, then i drop it and another player grabs it, the reference is still the same? what if the item gets destroyed? any way of knowing that? or at least a way to know if that item went out of the player's inventory somehow
yeah
yea what
even after destroying Item object should still exists, for sure this works when it comes to destroy entity
then how do i know, at any point, if that item still exists?
Hello, I opened up Intellij today, with alot of errors. But, the yesterday, my IDE was working fine. No errors. these are my errors
Seems like your IDE was on break yesterday
How could I fix the issue?
Those are syntax errors, it gives you the line number & whats wrong
So you need to go back and fix them
but i did, the code thats in my ide rn, was there yestarday. With no errors
im using intellij 2021.2
the new build
Should've been errors, not sure why your IDE didn't show them
hello i am trying to create reload command
but when i do
Bukkit.getPluginManager().disablePlugin(PVP.plugin);
Bukkit.getPluginManager().enablePlugin(PVP.plugin);
it doesnt works
any help?
You can't enable a plugin in the plugin you disabled
use OnPluginDisableEvent to check if your code works
can i show my code and could you take a look at it?
so how i do plugin reload like
/pvp reload
how can i get the itemstack of the edited book inside PlayerEditBookEvent?
You reload all the data yourself
It tells you whats wrong, missing semicolons, parenthesis, brackets, not returning, etc etc
... and if i want command of that how i do it?
lemme try smh, hold on
and this shoulld be trigger by another plugin
You code it lol reload all the data you want to reload
so how other plugins do it?
like
/ess reload
for example
Most plugin reload commands just reload the configuration files, not actually restart the plugin
why dont you trigger method OnEnable and OnDisable
PVP.getPlugin(PvP.class).OnEnable(); PVP.getPlugin(PvP.class).OnDisable();
Yeah don't do that
Well, calling onEnable() and onDisable() isn't going to consider your plugin enabled/disabled
It's just dumb lol
If you were to do PluginManager#disablePlugin(this), however, then yes you're correct
Really though, there is no reason whatsoever for you to be enabling/disabling your plugin at runtime.
bungeecord question: is it possible to send a player to a specific server right after auth through a plugin? I need to have a fully dynamic configuration, so I'd like to send a player to a specific server without having to have an empty server just for the purpose of rerouting.
I want to check if an inventory contains a shulker box, is there a easier way to check than to loop through every item stack and check if its one of the 17 Material.<Shulker box here>?
just get the inventory contents and check if it contains
issue
there isnt just one kind of shulker box
inventory.contains(new ItemStack(Material.SHULKER_BOX),1);```
does not work
Hmm
get display name and if that contains Shulker Box?
what if its renamed
List<Material> shulkers = Array.asList(Material.<blue shulker>, Material.<red shulker>);
shulkers.forEach(shulker -> {
if(inventory.contains(shulker)) {
}
});
is that better or worse than this?
for(ItemStack i : inv.getContents()){
if(shulkerset.contains(i.getType())){
player.sendMessage("Shulkers cannot be stacked thrice.");
return;
}
}```
with shulkerset being enumSet ShulkerBox to BlackShulkerBox
you can get the material as a string with material.name
so you can get the item's material, turn it into a string, and do if string contains "shulker_box" or "shulker box"
people, I have a method that generates a random number with a minimum and maximum value, after that I will use a lerp to make these numbers smooth, after that I add them up to give this random value, after reaching this value, it will be decreased to 0, but I want to make it have a balancing effect that goes to the negative numbers, then goes up again and goes down and stays stopped at 0, as if it were moving, so someone know how i can do this ?
How is that a bukkit question
"development"
fair lol
.
there are dedicated java help servers though
does anyone know how to use deserialize staticly?
Neither the array in java.lang nor the array in java.sql has the asList function
The class Arrays has the method Arrays#asList(T[])
now it makes more sense
In the context of ConfigurationSerializable?
yeah
guys
I am trying to save a class var to a file and then get it back
should I use IntelliJ or eclipse? Which is better?
I use Intellij
You lucky i just wrote an example for someone:
@Data
@AllArgsConstructor
public class Home implements ConfigurationSerializable {
private String name;
private String owner;
private final Location location;
@Override
public @NotNull Map<String, Object> serialize() {
final Map<String, Object> data = new HashMap<>();
data.put("name", this.name);
data.put("owner", this.name);
data.put("location", this.location);
return data;
}
public static Home deserialize(final Map<String, Object> map) {
final String name = (String) map.get("name");
final String owner = (String) map.get("owner");
final Location location = (Location) map.get("location");
return new Home(name, owner, location);
}
}
Just let the class have a static method named "deserialize" which takes a Map<String, Object> and returns the class which it is in.
All preference
um new issue
that lambda operator makes it a method
so return does not 'return' from the super method
can i somehow do a double return or something?
k, thanks I will try this
just use a for loop
Whats the code in question?
Iterating over a List of materials and checking one by one if an inventory contains items of that type is significantly slower than iterating over the slots of an inventory and checking if a set contains the material of that slot.
Use the same exact code but use a for loop instead of a lambda
for(ItemStack s : inv.getContents()){
if(shulkerset.contains(s.getType())){
player.sendMessage("You can't stack shulkers trice!");
return;
}
}
IE return when the inventory contains a shulker
where shulkerset is the 17 enums that make up the shulker boxes in the game
don't use inv.getContents() use inv.contains()
dude
theres more than one kind of shulker box
thats why im doing this in the first place
Read the code I sent
No. Do not use inv.contains(). Like I just said, that would be an order of magnitude slower.
whats the difference
You iterate through the list of shulker box materials and check if the inv contains that material
There is a Tag for shulker boxes
for (final ItemStack itemStack : inv) {
if (itemStack != null && Tag.SHULKER_BOXES.isTagged(itemStack.getType())) {
player.sendMessage("You can't stack shulkers trice!");
return;
}
}
This is the ideal solution. ^^
And Inventory implements Iterable<ItemStack>
thats interesting
thanks
imma try
isnt that iterating tho?
wheres the difference between ItemStack itemstack : inv and ItemStack itemstack : inv.contains()
The difference is that an inventory is effectively a List. Calling contains on it is suboptimal.
aaah
You want to iterate over the List-like collection, because that is what Lists are good for.
since youre basically doing it twice
Hello,
! I made a custom recipe with prepareItemCraftEvent with custom itemstack with custom amount, but when I craft item with 2x+ item matrix, the matrix doesn't remove.;
I tried to clear inventory, but it occurs many erros (in my case.). how can I solve this?
And you want to call contains on the Set-like collection, because that is what Sets are good for.
So, you iterate over the inventory (the list), and call contains on the Tag (the set).
Recipe with ingredients that have a variable amount?
What yapperyapps suggested was the reverse: Iterating over the set, and calling contains on the list. Which is backwards.
explains a lot. On a similar note though, can you somehow get the inventory of a shulker box without doing this mess?
Inventory inv = Bukkit.createInventory(null, 27, "Shulker Box");
BlockStateMeta bsm = (BlockStateMeta) e.getCursor().getItemMeta();
BlockState bs = bsm.getBlockState();
ShulkerBox sb = (ShulkerBox) bs;
inv.setContents(sb.getInventory().getContents());```
yeah!
How can I get a specific row from sql
Not that I know of. The inventory is stored in the item meta. So you'll have to go through the standard itemmeta steps to get it.
Hello everybody! Today I will show you da wea of using ItemStacks inside of your crafting recipes! Don't forget to leave a like if you enjoyed :)
Full playlist: https://www.youtube.com/playlist?list=PL_MDptw3Zft_Xb8-i0WBGtwdUN14TMJ...
Yeah just read source thought contains ran differently
SELECT * FROM table WHERE condition
is it okay if I use JDK 1.8?
Selects all rows from this table where a certain condition is met. For example to select the row that contains a certain name:
SELECT * FROM homes WHERE owner='bob'
What spigot version do you develop for?
What spigot version are you on?
sorry, are you asking the minecraft version? Like 1.16.4, etc...?
Java 11 is currently the golden standard. 16 if you want to be up to date.
do I need to unistall java 1.8?
In order to achieve what?
You can just download and install jdk 11 or 16. It will set itself as default jdk. Having multiple jdk versions install doesnt harm you in any way (usually)
ok thx
and btw when you say "Java 11 is currently the golden standard", you are talking about java 11 or JDK 11?
well you cant build without jdk
but its functionally the same
difference is that the jdk includes the compiler
hmmmm ok, thx :D
since you're in a developement channel tho Imma guess you need the jdk
usually newer is better but remember that depending on the minecraft version you build you have to code in either 1.8, 11 or 16 java
Not JDK, but JRE*
Jdk is for development, it includes JRE and extra stuff for development
Jre is for just running Java programs
Both are Java
oooooh
I'm able to get all the rows but I want a specific one from a specific column, that's what I was trying to ask
alright then...
Ok for example you have a table named users that looks like this:
| name | age | UUID |
| bob | 19 | pmg-1hg |
| ron | 12 | hgt-m66 |
| ella | 17 | p33-hjt |
Now you want to get the following row:
| ron | 12 | hgt-m66 |
The query for that would be:
SELECT * FROM users WHERE name='ron'
This query would yield the same result:
SELECT * FROM users WHERE age=12
But only because there is one user in this table that is 12 years old
For fast lookup times you usually want to define one column with unique entries and index it.
In Spigot the UUID is most suitable for most tables.
man wtf
I tried to create a new spigot project
and then it doesnt created everything
it created a basic java project?
Just create everything else yourself
not that hard
im lazy
too bad
but want im wanting is bobs uuid nothing else
Then
SELECT UUID FROM users WHERE name='bob'
but that displays the age too
oh wait
hold up this is nothing i want to do
idk what im talking
Use the mcdev plugin for intellij. It automatically creates a fully assembled spigot project with plugin.yml and everything.
Or have a boilerplate...
- What data do you have?
- What data do you want?
but im doing that
im creating a spigot project from that plugin
and then it is creating errors
Like this?
Is there some way I can do something like PreparedStatement#getString("Cooldown").size()
Preparedstatement?
Or resultset
yea meant resultset
I have uuid, time, cooldown want im wanting is their cooldown but there is multiple values in cooldown so I have to loop through the column cooldown
This cooldown thing, is it nullable
@lost matrix btw I think the error is: "Could not find the pom.xml file"
can I fix it?
Create one
Do you get the whole table?
You should not need to iterate through your ResultSet but rather write a proper SELECT query.
btw I think where this error is coming from
If you want to get the cooldown of the user with a certain uuid then you can get it with
SELECT cooldown FROM cooldowns WHERE UUID='some_user_id'
You cant store multiple values in an entry, if thats what you were thinking
No
I just did ```java
for (int i = 1; i <= data.getColumnCount(); i ++) {
if (data.getColumnName(i).equalsIgnoreCase("Cooldown")) {
System.out.println(res.getString("Cooldown"));
}
}
@proud basin follow this
That's what have though...
Can you please just tell us what you are trying to do
This will select the whole row. But you only want the cooldown, right?
nah nah nah what I mean is I've already completed what I wanted
I just did it another way
If this is what you mean by you got it, we are suggesting otherwise
Eh...
Did i confuse you 7smile7
And res.getString("Cooldown") is already what you want, dun get why you are iterating through columns anyways
I think you are confused
oh yea
@lost matrix Fixed it, I had "hidden" the pom.xml file in the settings, so when creating a spigot project, it wasn't finding the pom.xml file
Hey! :3
I am new to plugins, could you tell me how and where I can use this commands?
Likely not a #help-development question
): ok
If it is server related commands you can ask in #help-server
If they are commands specific to a plugin, you may want to see if they have a support channel, discord or sth
If I want to use multiple classes with commands, thats how I would do it? (just to confirm)
Main.java
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
getCommand("hi").setExecutor(new CommandClass());
}
}```
----------------------------------------------------------------------------------
**CommandClass.java**
```java
public class CommandClass implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return false;
}
}```
well... yes?
ok thx
You need to use NMS iirc
You can add them to a Scoreboard Team and set the Team's color
Yeah you could do that too
Bukkit.getWorld fails, but the world is in the server folder
is it the correct name
Yes
Is the world loaded?
it should be loaded by default if its vanilla
Then its probably not. You need to load the world first.
Ok, I did not see a method .loadWorld() or smth
createWorld() reads from an existing world file.
Ok then well do that
new WorldCreator("") what is the name?
Just how I find the map named?
The name of the world folder
Ok
how can I remove the bed spawn point from player and set it to world spawn (I set the world spawn to the radius of 1000 so they spawn randomly)
I cannot null the setRespawnLocation
you can run this code to see worlds that are loaded Bukkit.getWorlds().stream().forEach(w -> Bukkit.getConsoleSender().sendMessage(w.getName()));
Good idea, but I would like it doing like this:
World world = Bukkit.getWorld(args[0]);
if(world == null)
world = Bukkit.getServer().createWorld(new WorldCreator(args[0]));
stream into foreach is obsolete.
Just call foreach on the collection directly.
good to know, since what version of Java?
Since lambdas got introduced. So 1.8 i suppose
Works very good
Weren't Streams introduced in 8?
hey 7smile7 did you perhaps have some time to look into what we talked about yesterday? I did some testing on my own when I had time but nothing really came out of it
So they were obsolete to being with? Lol
Yes. The whole stream API
yep ^^
the structure of containers was a mess for me to look at lmao
big brain
I mean the streams arent obsolete but calling foreach on a stream instead of a collection actually produces overhead.
Yeah I couldn't come up with anything Dan, from what I saw the way they handle registering is a disaster
Doesnt look possible anymore tbf
Yeah, I know about not calling forEach on a Stream, just odd that it was obsolete when they added it.
sad well I guess I will look into the older versions to see where it was changed
Even with packets its not possible. The client only knows these registered inventory types:
yeah I see, welp it would have been cool to do
if that was fixed before 1.15 then sadly I can't do what I was thinking to do
What exactly are you trying to do anyways?
Even if you get it working it's super ugly
so pretty much with the unicodes you can create guis how you want
How do u make custom attributemodifiers
so with a bigger size you could really have more options
Interesting, didn't know that was possible.
yeah it's pretty cool
I was testing with some stuff yesterday and the chest bug came back to my mind
DoEs AnYoNe KnOw FmL pRoToCoL?
String modName = "some_mod_name";
double value = 20.0;
Operation operation = Operation.ADD_NUMBER;
AttributeModifier modifier = new AttributeModifier(modName, value, operation);
You dont need the extra rows for that
oh that works?
but how would it work with custom stats
How? The slots literally reach into the bottom inventory.
having more slots would enable for some less common looking stuff
When it comes to mods. Do you know a way to refresh Forge mod in the runtime?
What do you mean by that?
well i have a GamePlayer class
for each player
that has custom stats in it
how would i make it add to that?
what do you mean by that?
what I mean is like with more clickable slots you could layout the guis differently too
You can do some really cool stuff already. This is what ive done a year ago in winter:
I mean yeah I know
I have done some custom menus yeah, just more possibilities with bigger gui sizes
Does it require texture packs to do that?
Ofc
it's not that I have something in mind specifically, just in general more creative freedom
I figured
yeah yeah resource packs are required
I forgot but you actually could open 2 double chests at the same time too
so much space lmao, sadly it can't be used
Me want
Make it happen
wait how does minecraft get the gui sizes actually? because of the not used sizes it wouldn't make sense for them to hard code the ones they don't use
oof no custom emoji
:otDan:
1.12 still has it hmm
yeah 1.13 fixes the physical version to open it up, idk if it changes it too
Im hustling with the NMS stuff because literally everything in there is private
yeah fr
@lost matrix
is there a way to build an api dependecy into the plugin with maven, rather than having it required in the plugins folder?
This would require you to do your own logic.
So just a Map<CustomAttribute, Double> for example
What do you mean by that?
like building nbt api into the plugin on build, instead of having to put the nbt api into the plugin folder itself
so instead of the stat in the GamePlayer class
rn its an int do i make it a Map?
im pretty sure its possible, im just not sure how
Sure. You can just shade the dependency into your plugin. But if its another plugin then it needs to be loaded by the spigot class loader or else it wont recognise the plugin.
yeah its another plugin
but i could do it with gradle i think
You can create a GamePlayer class which contains an AttributeContainer which contains a Map<CustomAttribute, AttributeInstance>
And so on. Just go nuts with object orientation.
It doesnt matter if you use maven or gradle.
You cant load another plugin into your own because the spigot classloader wont realise there is another plugin withing a plugin. So the onEnable() and onDisable() of that shaded plugin will never get called.
If you however just have a plugin with a bunch of utility classes in them and that doesnt need to be loaded/enabled then you can just shade it in with maven like you would do with every other depenency.
welp i suck too much at coding for this idk how
is there an event that gets triggered when an item breaks or loses durability?
yes
name?
I think PlayerDamageItemEvent or something
?javadocs
cancelling doesnt work if u wonder that
?help
selfrole Add or remove a selfrole from yourself.
cleanup Base command for deleting messages.
embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.
customcom Base command for Custom Commands management.
findcog Find which cog a command comes from.
names Show previous names and nicknames of a member.
casesfor Display cases for the specified member.
listcases List cases for the specified member.
reason Specify a reason for a modlog case.
permissions Command permission management tools.
thx
u have to se the damage to 0
i want to keep track of how many items were broken during an event that i am developing
?customcom
Syntax: ?customcom
Alias: ?cc
list List all available custom commands.
raw Get the raw response of a custom command, to get the proper...
search Searches through custom commands, according to the query.
show Shows a custom command's responses and its settings.
?help cc