#help-development
1 messages · Page 939 of 1
you don't need the block you can get it directly from the world
wait why do people fork spigot for certain servers, wouldn't you have the same stuff as using NMS
yeah, why
i mean you can do some extra stuff like crash detection unlike spigot but that's pretty much all that i can think of
nvm u prob cant do crash detection\
it worked in the past
add it as a dependency
try {
new MinecraftServer().run();
} catch(Exception err) {
LOGGER.error("Crash detected!", e);
}
``` looks like a bad idea but it's a crash detection lol

what
smartest person in the world
bukkit is an API, craftbukkit is the implementation of bukkit, spigot is a fork of bukkit, paper is a fork of spigot
paper = bukkit + spigot
WorldGuard was primarily written for Spigot. It 100% works.
wait what?
i mean i know worldguard is pretty old but it was written for spigot?
I mean originally it was written for bukkit. They made it platform agnostic after a while.
why does this not work?
mm, hardcoding locations
Because you didnt get the BlockState.
Also getting a World like that is dangerous
everything in this screenshot is dangerous
It's not the Block that's a Chest, it's its state
oh so like this? Chest chest1Level1 = (Chest) l.getBlock().getState();
ye but with /plugins appears with red and cant seem to find the ploblem
problem*
Think about Block just describing a position in the World.
It has no actual properties.
Did you install WorldEdit?
check startup logs
i changed it to this but it still didnt work:
Location l = new Location(getWorld("poi"), 67, 137, 79);
Chest chest1Level1 = (Chest) l.getBlock().getState();
chest1Level1.getInventory().setItem(1, new ItemStack(Material.DIRT));```
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
like it doesnt make the item in the chest dirt
have you tried the magical thing called debugging
You need to call update(true) on the Chest after changing the state
as well as googling
Any exceptions in console?
nope
thanks
wait ima try use some loggers
Add a debug statement and check if your code is actually executed
u have to update
Yea realized as well
yep
check startup logs
Then check the logs. If the plugin is red then there is a stack trace.
else if (cmd.getName().equalsIgnoreCase("reloadpoiloot")) {
getLogger().info("reload poi loot command called");
// If it's a player and has plutotools.reloadpoiloot or if it's console
Player p = ((Player) sender).getPlayer();
if ((sender instanceof Player && p.hasPermission("plutotools.reloadpoiloot")) || sender instanceof ConsoleCommandSender) {
getLogger().info("player has all permissions");
Location l = new Location(getWorld("poi"), 67, 137, 79);
Chest chest1Level1 = (Chest) l.getBlock().getState();
chest1Level1.getInventory().setItem(1, new ItemStack(Material.DIRT));
chest1Level1.update(true);
getLogger().info("works");
}
return true;
}```
still doesnt work for some reason
Are the debug statements being printed?
yeah
try l.getBlock().setType(Material.DIAMOND_BLOCK) and check if your chest is replaced by a dia block
does getInventory return a copy
yep the chest becomes a dia block
CraftInventory inventory = new CraftInventory(chest);
and
// The logic here is basically identical to the logic in BlockChest.interact
in CraftChest
Try addItem instead of setItem
if i do that it wont let me replace the existing item tho
and it doesnt let me set the slot number
Try it out pls
tried it, didnt work
still doesnt work
and update
What version are you on?
1.20.1
yeah im doing that
Location l = new Location(getWorld("poi"), 67, 137, 79);
Chest chest1Level1 = (Chest) l.getBlock().getState();
chest1Level1.getBlockInventory().addItem(new ItemStack(Material.DIRT));
chest1Level1.update(true);```
Do you have any Listeners for the InventoryOpenEvent?
try to print a filled slot from the chest's inventory to make sure you have the correct instance
What does your PlayerInteractListener do?
like this for example? getLogger().info(chest1Level1.toString());
just makes a new inventory when a player clicks on a compass
I'm not 100% certain but wouldn't the update() override the inventory change?
That might be possible
It's really the only thing I can think of causing issues
YES that was it thanks
block states are a bit finnicky
There you go
do i need to change the server version
yes
Or use an older version of wg
^^
where can i find those?
Why are we giving server help in the development channel btw?
no idea
k
You're also using Paper 😛
So in the future, even if it's not specifically server software dependent, it's best you ask for support in the Discord server of the server software you're actually using
how can i brodcast all the args after the 0?
By index iterating but starting at 1 instead of 0.
Or by creating a sub-array from 1 to end and then joining the Strings.
Probably a dozen more approaches for this
like a done a command that work like /brodcast alert - - - - i want all the args after the "alert" then after the args[0] to show up in the brodcast
how should i make a list of contenents (multiple items) to go into a chest?
Are the slots important or do you just want to add them to the chest?
the slots are important
In that case you should probably just use setItem().
Alterantive would be setContent() by passing an ItemStack[] to the Inventory.
But this expects an array of the exact size as the inv
By index iterating but starting at 1 instead of 0.
Or by creating a sub-array from 1 to end and then joining the Strings.
Probably a dozen more approaches for this
well i want to have multiple chests with the same contents so i dont really want to repeat setItem() for all of them
Write a method then...
have a method that takes an inventory as parameter
Writing reusable code is key. Nobody wants DRY code.
DRY=
Dont
Repeat
Yourself
If you find yourself copy pasting code, then its time to think about how
to write reusable code.
You could for example create a method
public void fillInventoryWithGarbage(Inventory inventory) {
}
which fills an inventory, and then call it for as many different invs as you want.


alright thanks
ill try it out
= Will eat tables
lol, chatgpt found the best answer 'Write Everything Twice'
do i need to specificy how big the inventory is?
it can't be bigger than 54
but the inventories have to be the same since the content is?
so if this is my content say:
public void contents1Level1(Inventory i) {
i.setItem(1, new ItemStack(Material.ENDER_PEARL));
}```
how do i set it to be in the chest? `chest1Level1.getBlockInventory().setContents();`
You pass the chests inventory to the method...
exactly ^
now it depends if that's the correct inventory, blockstate usually works differently than you'd assume
like this? contents1Level1(chest1Level1.getBlockInventory());
yeah
alr
whats best way to check when player enters a region with worldguard api?
I suppose you should ask enginehub people.
whats that?
The people who make worldedit and worldguard
oh you mean the creators of it
Yes; they would know their API more than us collectively.
ok
good luck
When i try to start the server with a plugin where i put mysql database it gave me that error:
[21:16:01 WARN]: at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:708)
[21:16:01 WARN]: at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:253)
[21:16:01 WARN]: at org.giutv.gkitutils.database.DataBase.<init>(DataBase.java:12)
[21:16:01 WARN]: at org.giutv.gkitutils.Gkitutils.onEnable(Gkitutils.java:44)
[21:16:01 WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
[21:16:01 WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
[21:16:01 WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
[21:16:01 WARN]: at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357)
[21:16:01 WARN]: at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317)
[21:16:01 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414)
[21:16:01 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378)
[21:16:01 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333)
[21:16:01 WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263)
[21:16:01 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525)
[21:16:01 WARN]: at java.base/java.lang.Thread.run(Thread.java:1623)```
Running 1.8 means you have to init your driver Class.forName(...
wdym?
i do it
this.connection = DriverManager.getConnection("jdbc:sqlite:"+file);
Class.forName("org.sqlite.JDBC");
createTable();
}
class forName BEFORE you try to use it
https://paste.md-5.net/zezivoyele.cpp
I Feel Like Im Doing Something Wrong Here
Any Ideas?
thanks you a lot :D
what?
best version for me :D
not for anything else lol
September 2, 2014 the release of the 1.8 XD
10y ago
yeah legacy
what is the better the 1.20?
i use both
what is it even meant to do
a list of blocks with their data so we can see if a player has the right requirements to break that block or no
and their custom drops
a) dont use new BlockData but Material.VALUE.createBlockData() and b) why do you even need block data here, just use a material to material map for drops
Hi, my plugin has a big problem, i write to a file to get information about a score, the score is binded to a player and saved to the file. I have a command to set the score of the player, but when i do that or edit the file myselfe it doesnt change on save or it seeems to get it old value back after some time. I use a .yml file
no its not just that
and the BlockData is class of my plugin
its multiple files so not easy to post all here, is a github link ok?
Go for it
Just editing a file wont change the values in memory.
If you edit a file, and save your memory values back later, then your edited file obviously gets overridden.
question:
static private
private static
which one is better
latter
better?
Access modifier always comes first
oh thanks
https://github.com/LeonBoettcher/LimitedDeath/ The Problem is that when i set the credits manually and a player has 0 credits the player cant join duo the file is still 0 credits
Repo's private
oh sry wair
now its public
when i want to have placeholders, but they all can have completely different parameters. How would I implement that, an interface doesnt work as the placeholders all have different params?
Cool, I'd like to suggest we do some restructuring so this code makes a bit more sense
Do what PAPI does.
Use a separation character (like a dot) and then split the placeholder.
if you want a good data structure for placeholders keep in mind they're basically like a little scripting lang
yes i thought about this, but then, when for example using it in a config file you cannot fill it out correctly?
i need the actual durability of a picaxe, but ItemStack#getDurability is deprecated, whats the new method to get that?
Hm?
Casting to the ITEMMETA Damageable if possible
you cant %myplaceholder.<playersuuid>%?
in code it would work
but not in a config
I know that this isnt good written code its not really made to be easy to understand. Iam still learning. But I apreaciat every help
Example:
Your separation char is #
Your placeholder key is chance
It has one parameter:
%chance#<value>%
Then a placeholder in a config could be:
"%chance#15.25%"
In your implementation your simply parse for all Strings between two %. Then you split it at #.
The first entry is your placeholder key, the other entries are your String[] args like you would have in a command.
yes this would work, but think about a config file about a playerscoreboard then i want to implement %money#playersuuid% i cannot get the player uuid from the config, this system is great for devs, but not for configs

what?
placeholder needs player specific input, how am i gonna get player specific details
so cast the ItemMeta do Damageable and then do .damage()?
getDamage on the itemmeta damageable yeah
Damageable idk = (Damageable) itemmeta;
.damage is probably a method from the entity damageable
Please give another example. Yours doesnt make sense in the first place.
Nobody would write the score of a single specific UUID in their scoreboard...
do people like kt around here?
thats why this system is flawed
you can only have the data of a single specific uuid with this kinda approach
Remember that your placeholder always has the viewer as its first context:
public String evaluate(Player viewer, String placeholder, String[] args)
And then you simply treat it the same way as bukkit commands
Anyone know how to fix MockBukkit just like not running 🥲
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.Server.getRegistry(java.lang.Class)" because "org.bukkit.Bukkit.server" is null
This is my setup for gradle
plugins {
id("crown-module")
}
repositories {
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
testCompileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0")
}```
https://paste.md-5.net/egoteqizug.m
whats MockBukkit for?
mocking bukkit
ok
you're welcome
wow you are a real intellectual
someone should give you an award
I am aware
Ok but that is simply not a viable example.
If you wanted to have a toplist in your scoreboard, then your placeholder would look like this:
%topkills#<rank>%
With a config which might look like this:
score:
- "%topkills#1%"
- "%topkills#2%"
- "%topkills#3%"
Its all up to the developer to provide usable placeholders
this would work, but i was thinking about not having the player as a forced param, that why i was asking how the system is gonna work

Ah ok. Yeah without a viewer context it wont work.
Its like trying to let someone send a command, but you dont have the command sender in your method.
Try getting the command sender now for context. Cant really pull him out of thin air ^^
ok
what does a entity with no ai does in its tick method, and how expensive is it compared to a entity created with packets?
to set durability what can i do?
There is def a difference between a purely virtual entity and a physical one without ai
Cast ItemMeta to Damageable and call setDamage()
So a big performance difference?
k
Depends a bit on what you are doing
Salvatíoné
i just wanna
subtract
10 from the actual durability
so i can do
setDamage(getDamage+10)
I want to create entities which are only seen by certain players and ther dont do anything except exist, packets afe perfect but i dont want to use them, bevause they are not maintainable
I am trying to rework a plugin called "FactionMobs" which is deprecated, and the point of it is to allow players to spawn mobs are allied with their Nation in Towny, now I have no problem with any of that except one part, and it is how do I make mobs attack a specific player yet be friendly to another? Does anybody know of a Library made for controlling mobs and their behaviors? If not, then I would appreciate if I was given a simple Idea from one developer to another on how to do something like
I can know who is the enemy, and I can know who is supposed to be friendly, and I know how to do everything else it's just the mob control part I can't get
But wouldn't this make it so the mob would still attack the ally of it?
Like this seems like it just readjusts the pathfinding
ahh whatever I will try it
Thanks for the idea
I appreciate it
You can cancel it under certain conditions
Intellectuals, i require your help once again
how can you get generic attack damage attribute from an entity? I want to get the total damage a player can deal with their main hand plus effects and enchants, but i'm not sure if generic attack damage alone gets this
can i send kt code or i will not receive support
from here, how can I check for sharpness enchant and add that to the damage?
good evening I am looking for a java developer for minecraft server for the pvp factions theme with a price of £86.21
is it possible to redirect me to a developer
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
Very specific price
Also, where did u find that 0.21 xd
on Google
conversion rate?
100euro=86.21£
this is my code
and the picaxe durability isnt changing
what could be going wrong?
i feel guilty not pulling before pushing on a repo that only i have access to. should i pull before pushing on a fully private repo?
no
why
only you make pushes
lol
even in pubhlic repos i make push request without pulling
unless you modified any files on github your fine
and then i get flamed
and what is the difference between commiting and pushing
commiting is stored in ur local machine
you cang push without committing
pushing just passes all the commits in ur local machine to the remote repo
oh thanks
declaration: package: org.bukkit.inventory.meta, interface: Damageable
im doing setDamage
kt has integrated getters and setters
:/
it looks really strange 😭
Are you setting the meta back
i wanted to die looking at that kotlin code
not cuz its bad but cuz it has weird syntax
no
but it does changes the stuff
btw
item.durability = (amount you want to subtract)
that works
lol
strangely but works
deprecated method im pretty sure
You have to set the meta back
why is the author name BuildTools when i push? i want it to be my github name
there's a file
where
Buildtools used to override your global git name
That’s fixed now, but you’ll have to fix your global stuffs
where and how
*set it by default, it never overrode settings
no way md_5 is here
Ah
thanks
player.launchProjectile(ThrownPotion.class, new Vector(0, 0, 0)).setItem(this.healItem);
anybody know a way that makes it look if i threw the actual potion not a water bottle
that damageable varable can be defined as just item.itemMeta s Damageable
without any parenthesis
launchProjectile will return ThrownPotion instance which you can change the metadata iirc
probably the healitem wasn't properly defined
yeah what is healItem
it is defined, and its a heal potion whenever it hits the ground
however when its shot its visually is still a water bottle
its the heal potion found in the inventory xd
can you show the whole code snippet
if (this.shouldHeal()) {
if (NPCUtil.consumeItem(npc, this.healItem)) {
if (healItem.getType() == Material.POTION) {
final int heal = healItem.getDurability() == 16453 ? 2 : 4;
bot.setHealth(Math.min(bot.getMaxHealth() + heal, bot.getMaxHealth()));
bot.launchProjectile(ThrownPotion.class, new Vector(0, 0, 0)).setItem(this.healItem);
}
}
}
i remember the colors of the potions were off for me
i had to do something weird to make them work
I think creating the NMS entity would fix it
but im asking if there is a bukkit api for it
how can i convert a Material[] to an ArrayList<Material>
maybe somehow convert the potion to an entity
Arrays.asList
oh thanks
this is supposed to be for all versions
xd
but yes im testing on 1.8 upwards
lmk how it goes
alright
how can i get the friendly name of a material
the friendly name?
and if your hand is empty, will player.getInventory().getItemInMainHand().getType() return null
DIAMOND_SWORD: Diamond Sword
split on _ get first char, uppercase and replace
getItemInMainHand will be null, yes
and yeah, no method for it, either use the itemstack to get displayName from meta or do waht Epic say on material
display name wont exist for un renamed items
you didnt google before you asked on here?
i barely know how to format text in java
nah its just easier
you really should be googling before coming here
blocked.
because thers a solid chance sometimes the answer you are looking for takes 1 second to find
public static String getFriendlyText(String text){
//Credits To My Bro ChatGpt
String[] words = text.toLowerCase().split("_");
StringBuilder result = new StringBuilder();
for (String word : words) {
if (!word.isEmpty()) {
result.append(word.substring(0, 1).toUpperCase())
.append(word.substring(1))
.append(" ");
}
}
String finalText = result.toString().trim();
return finalText;
}```
just return then, why temp var
alr
how can i get the block under the player and set it to a random block?
Block blockUnderFeet = blockAtFeet.getRelative(BlockFace.DOWN);```
thanks
anyone know how to code on java? need help with a simple custom item
https://github.com/Xemuain/testing what do you think about this GUI system?
everyone on this channel knows how to code in java, whats your question exactly
great, so basically
im trying to make a custom item and I coded everything for it using a tutorial
however for some reason when i load into minecraft the actual texture doesn't load.
static {
Bukkit.getPluginManager().registerEvents(new Listener() {
``` this is a big no-no
im very sad to tell you no one here knows how to code in java and were all fake
can I send you my code and show you what i mean?
?paste
put it on that
send it lol?
like.. how
lmfao
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "minecraft:item/diamond_sword"
},
"overrides": [
{"predicate": {"custom_model_data": 40000}, "model": "minecraft:item/kingsword"}
]
}
and
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "minecraft:item/kingsword"
}
}
separeted into 2 files ofc
i mainly care about the fact that a new inventory is created for each player and the example of using Menu.class will be a burden for about 200 players
Is there some better way of checking if the server runs raw bukkit, spigot or any other fork than doing Class#forName?
i made the texture for it as well if you need me to send that
@tawdry echo
inv.getListeners().stream()
.filter(listener -> listener.getEvent() == InventoryDragEvent.class)
.forEach(listener -> ((GuiListener<InventoryDragEvent>) listener).run(e));
could be replaced with a for loop and if statement, will be a lot more performant
The use of the gui map is good
but yeah, move that static listener bs elsewhere
That is a non negotiable, a static registration of listeners WILL break
and it breaks bukkit conventions
Error: https://paste.md-5.net/cohukodati.sql
Code 1: https://paste.md-5.net/vigipixale.java (This Is The Source)
Code 2: https://paste.md-5.net/cuvexihuda.java (This Is Where We Set The Player Accounts)
Code 3: https://paste.md-5.net/toremigivo.cpp (The PlayerManager)
I Would Appreciate It If Anyone Would Help
so you want to know how to apply custom model data?
but now how do i set the block to a random block
mm.. I guess so? is there anything wrong with the code because it just doesn't work... I have a custom texture pack for it aswell.
by a wild chance, are you using plug man or /reload confirm
supposed to show a png of a sword i made
but after change registering listener it its will all ok?
but its just a normal diamond sword
print the map before you call line 53 block break handler
how to print a map in a human readable format?
just an fyi this has nothing to do with java, it's minecraft resourcepack stuff.
but you're 100% the custom model data is applied to the item?
calling println will tostring it for you
and is kingsword in the item directory
found out how thanks 🙂
ima show u a screenshot
i believe so
?img
Can't send images? That's because you're not verified! Use !verify to complete verification.
Alternatively, you can upload screenshots to any image hosting site and share the link.
Here's some screenshot utilities that you can use to upload images.
Lightshot: https://prnt.sc
Imgur: https://imgur.com/upload
Flameshot: https://flameshot.org
lets move to #help-server @obsidian wolf
alright
double check you are actually registering the join event
and make sure your restarting
oh
//Register Stuff
getServer().getPluginManager().registerEvents(new BlockBreakHandler(), this);```
Proof That Im Blind:
```java
public void registerHandlers() {
getServer().getPluginManager().registerEvents(new BlockBreakHandler(), this);
getServer().getPluginManager().registerEvents(new PlayerConnectionHandler(), this);
}```
thanks btw Epic
@sand spire sorry for ping
nvm
i think i did it
@EventHandler
private void onPlayerMove(PlayerMoveEvent event){
List<Material> blocks = new ArrayList<Material>();
for (Material block : Material.values()) {
if (block.isBlock()) {
blocks.add(block);
}
}
Material randomBlock = blocks.get(new Random().nextInt(blocks.size()));
}```
you'll have to get an array of block materials and get inbetween 0 and the length
pre-bake the list/array
orelse you are calling that each time ap layer moves
I never tried to get a random block but I guess you can add every block or material to an arraylist and use Random to get a random index
and this code changes the block every time the player moves, not moves to a different block so this can cause huge lag
eh
its just for fun
and it also doesnt work
do i have to register the event even if its in the main class?
private method 🤔
you have to register the main class itself
well its in the main class
even if it is JavaPlugin
when i read this: Minecraft But Random Blocks Spawn Under Me Every Time I Move -Shorts Youtuber
oh
No
but that code is gonna lag your server
im a begineer and a friend of mine who knows java told me to try and do this
to learn
alright
but make sure to prebake the list and change the block only if he switched to a new rounded xyz location
Maybe something like this will work
List<Material> list = List.of(Material.values());
Material material = list.get(0); //random logic
location.getBlock().setType(material);```
that works
i just didnt register it
.
if you are learning you need to also learn to optimize your code @final wharf
?notworking btw
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
well yeah
but for a few minutes it doesnt hurt
theres nothing in the arraylist
"of" is underlined
java 8 i assume?
old java version
java 21
bump it up
im using java 21
Point to it and see what it says?
check the problems tab of your editor
then you imported the wrong List
and right click on it
yeah that
it is the wrong version
How?
click on it
i created the plugin with java 21
i did
reload maven
You can try List<Material> blocks = Material.values(); then check the error and see what intellij suggests, for me it suggested List.of
can use Arrays.asList
List<Material> blocks = Arrays.asList(Material.values());
thats some spoonfeeding and a half
yeah lol
i kinda understand better from spoonfeeding(personally)
xdd
so like this?java Location location = event.getPlayer().getLocation(); List<Material> blocks = Arrays.asList(Material.values()); Material material = blocks.get(0); //random logic location.getBlock().setType(material);
I mean sure, you understand just this very specific usecase and way to do this very thing, but its not really applicable to find your own solutions later down the line 😛
somehow i do
dont know how
you still want logic to filter the blocks
doesnt u want the block that is under the player
check if its air and if it is then return
you also need to make sure the block is solid with isSolid
got it, also isOccluding to only get blocks that sufficate you so no slabs and random smaller blocks
yeah right
were turning this guys random project to a full on minecraft gamemode XD
xdd
and maybe use mfnalex's PDC for blocks so we dont replace already randomized blocks
😳
and maybe replace the block with its original block after like 100 seconds
an make sure the player cannot break non random blocks
was fun to code something that doesn't give me a headache 💀
if you do that you don't need a pdc. Could use a Set and then reset on restart/reload (or after 100 seconds) - whatever comes first
both would work, one would just be persistent on restart
no i meant that we need pdc to make sure they dont break non random blocks and we dont replace random blocks
If they stay randomized forever I'd agree on using pdc. But if you wanna reset them after a short time it's not required to make it persistent
that would be cool if they turn back like disco floor
gotta put random blocks smp on my game mode todo list for my server
time to push to master and rest
https://pastes.dev/RMnetngHOE @spare hazel epic disco floor plugin! imma keep this on while testing my stuff and hope i don't regret xd
probably very bad for performance xd
its just messy
nah im stupid
Bukkit.getScheduler().runTaskLater(CustomItems.getINSTANCE(), () -> {
if (list.isEmpty()) {
return;
}
BlockState block = list.get(0);
list.remove(0);
block.getLocation().getBlock().setType(block.getType());
}, 100);```
what is this supposed to do
after 100 ticks it sets the block back to the old block
oh cool
it breaks randomly but whatever lmao
ah
anyone got a code snipped for testing if a (list of) itemstack(s) fit in a players inventory
you could clone inventory and then check addItem.isEmpty
i've got worse
bumpy :3
are you not making a mock server or smth
double check that that is actually being called
itis b
because the error is happening in the BeforeEach method
when I call MockBukkit#mock
idk if mock bukkit has registries
It does otherwise stuff would break lol
also maven central where
?whereami
it is a spigot and Bungeecord programming/development related topic
would you prefer if I said it was on jitpack?
testCompileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
nothing to do with where it is hosted
oh I just did that to see if it was the issue I use spigot its just implemented as an API source if you look at my gradle paste
getting "where am i"d by md_5 himself must be a traumatic experience
difference between #addDefault and #set in FileConfiguration
I assume addDefault doesn't overwrite existing data, and set does
right?
Default is like a default value
bump
It doesn't even write data. It's just on memory, if the entry doesn't exist in the file it will return that value
Oh
No one leaves the poor guy alone
Hello there, I was wondering how I could update the victim's scoreboard inside the if (killer != null) in my onPlayerDeath script. I tried importing the code below into it but it won't work.
int victimKillStreak = killStreaks.getOrDefault(victimId, 0);
int limitedVictimKillStreak = Math.min(victimKillStreak, 5);
ChatColor victimKillStreakColor = getColorForKillStreak(limitedVictimKillStreak);
String coloredVictimKillStreak = victimKillStreakColor + String.valueOf(limitedVictimKillStreak);
victim.setPlayerListName(victim.getName() + " " + victimKillStreakColor + "[" + coloredVictimKillStreak + "]" + ChatColor.RESET);
updatePlayerScoreboard(victim);```
Full onPlayerDeath script: https://pastebin.com/ZCfYshw8
Debug and check if the code is actually executed
if (killerKillStreak + 1 >= 4) {
can be
if (killerKillStreak > 3)
same goes for all the other ones
How can I detect when a player interacts with a hologram (packet armorstand)
Like this? https://pastebin.com/NKZUT5w5 because it is still not updating victim's scoreboard when he is dying to the killer and the other way around as well.
ah you want to know the secret to interacting with holograms
also known as touch holograms unless you meant something different
There are Three ways:
- When a player interacts, check his direction and calculate the vector and if it is close enough to the hologram line.
- Use an
Interactionentity - Use some invisible fake entity like a slime
All of those require a decent amount of work
I can point you to a project that actually does implement touch holograms, not sure if you will be able to understand it though
Where do you listen for the touches?
Ah wait. Probably not a bukkit listener but a packet listener

ffs github
Lol
?
you wanted to know where it was implemented, that is where it starts
then you found the event for it
I just wanted to look for "new HoloTouchEvent" and this would lead me to the actual impl
there is no event in the Bukkit API that lets you listen for touches with holograms
so it has to all be implemented using some clever tricks 🙂
This is your own event you bob
I wanted to see where you fire it so that i can backtrack what you are doing
yes I am aware its our own event never said we didn't have an event for it. Just that its completely custom is all
Thats all i wanted to see 🙂
Why is this tightly coupled to the hologram?
Anyway thats what i did as well before Interaction entities where a thing. Slimes are most suitable for this.
because this a plugin designed to be an API for plugins as well as providing features of its own
but that is the implementation which plugins shouldn't need
This API allowed you to do quite a lot of stuff
wihtout having to worry about implementing it yourself 😄
you could also let the API handle your holograms for you if you wanted, or do the opposite
either was acceptable
sadly 1.8 kind of killed it and I haven't had time to update this code base mainly because of how large it it is it took 3 devs to make this XD
InventoryOpenEvent isnt triggered when the player opens their own inventory, anyone know a solution or a different event for it?
there is none
rip
player inventory is completely client sided
next best thing is detecing when they click it, thats the closest you will get
isn't the new way now that the players inventory is considered to always be opened?
if so, just check the inventory type they are interacting with
whats best way to make a help cmd without putting each command? like
when player does a command without putting argument it sends the list of commands
if you have a proper command system that should be fairly easy
since each subcommand can then define its usage, & u can simply fetch the usage of each command and print it to the user
yea so surely you have a collection of those somewhere
so u can just loop over that collection and get each commands usage right?
okay
could be better @worthy star
but uhm well
i don't have a collection for them 🙂
should i like have a set map like Map<String, String> and put the command with usage in it?
how ru even invoking commands then
i have a class that i extend in my commands classes and it has the stuff like execute() and checking permission,args,permission message,usage
how ru calling execute()
not done yet
so the handler is just hardcoded in a command? ;d
what does this error mean?
i would have a commandmanager that has a map<String,CommandHandler> that maps the main commands to a command handler, then u can easily invoke the command by checking the main command & u can also get all commands usages
Caused by: java.lang.ArrayIndexOutOfBoundsException
so whats the problem here:
// contents1Level2
contents1Level2(((Chest) new Location(w, 111, 126, 102).getBlock().getState()).getBlockInventory());
contents1Level2(((Chest) new Location(w, 107, 126, 110).getBlock().getState()).getBlockInventory());
contents1Level2(((Chest) new Location(w, 103, 126, 110).getBlock().getState()).getBlockInventory());
contents1Level2(((Chest) new Location(w, 111, 126, 52).getBlock().getState()).getBlockInventory());
contents1Level2(((Chest) new Location(w, 107, 126, 48).getBlock().getState()).getBlockInventory());
contents1Level2(((Chest) new Location(w, 103, 126, 48).getBlock().getState()).getBlockInventory());```
with
```java
public void contents1Level2(Inventory i) {
i.setItem(0, new ItemStack(Material.IRON_INGOT, 8));
i.setItem(3, new ItemStack(Material.COBWEB));
i.setItem(5, new ItemStack(Material.COBWEB));
i.setItem(7, new ItemStack(Material.SANDSTONE));
i.setItem(8, new ItemStack(Material.DEAD_BUSH));
i.setItem(10, new ItemStack(Material.ENDER_PEARL));
i.setItem(11, new ItemStack(Material.SANDSTONE));
i.setItem(14, new ItemStack(Material.ENDER_PEARL, 2));
i.setItem(17, new ItemStack(Material.SANDSTONE, 10));
i.setItem(18, new ItemStack(Material.IRON_INGOT, 8));
i.setItem(19, new ItemStack(Material.DEAD_BUSH));
i.setItem(20, new ItemStack(Material.EYE_ARMOR_TRIM_SMITHING_TEMPLATE));
i.setItem(21, new ItemStack(Material.IRON_INGOT, 8));
i.setItem(22, new ItemStack(Material.COBWEB));
i.setItem(23, new ItemStack(Material.ENDER_PEARL));
i.setItem(25, new ItemStack(Material.COBWEB));
i.setItem(26, new ItemStack(Material.SANDSTONE));
i.setItem(27, new ItemStack(Material.ENDER_PEARL));
}```
well, what item isn't working well?
just add a help.yml
to your plugin
server will take care of generating a help map for you 🙂
declaration: package: org.bukkit.help, interface: HelpMap
declaration: package: org.bukkit.help, class: HelpTopic
how do i make a chest empty?
declaration: package: org.bukkit.help, class: IndexHelpTopic
this exists??
yeah has existed for quite a long time actually
never known
naturally, its the same how people don't know about the conversation api
Well I think people know a bit more about the conversation api since I keep telling people about it when I get a chance 😛
however this is the first I have gotten the chance to talk about the help stuff
now, once this becomes a bit more known, it will be back to waiting on spreading some other unknown thing of the api 😄
how does he know it all!
Well, I been around since the beginning of MC and nearly the beginning of Bukkit 😉
im getting this warning:
> reloadpoiloot
[10:52:43 WARN]: Unexpected exception while parsing console command "reloadpoiloot"
org.bukkit.command.CommandException: Unhandled exception executing command 'reloadpoiloot' in plugin PlutoTools v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:987) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchServerCommand(CraftServer.java:972) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:500) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:447) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1393) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1170) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.20.1.jar:git-Paper-196]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.ClassCastException: class com.destroystokyo.paper.console.TerminalConsoleCommandSender cannot be cast to class org.bukkit.entity.Player (com.destroystokyo.paper.console.TerminalConsoleCommandSender and org.bukkit.entity.Player are in unnamed module of loader java.net.URLClassLoader @759ebb3d)
at net.plutocraft.plutotools.CommandExecutor.onCommand(CommandExecutor.java:489) ~[PlutoTools-1.0.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
... 9 more```
in one of your checks you are not checking if the command was the console
and you are assuming all commands are players
you can't cast console to player, so you should be checking if the sender is consolesender
this is what i have to check if its a console if ((sender instanceof Player && p.hasPermission("plutotools.reloadpoiloot")) || sender instanceof ConsoleCommandSender)
and then inside that if statement i got this:
if (sender instanceof Player) {
p.sendMessage(ChatColor.GREEN + "All POI's loot has been reloaded!");
} else {
getLogger().info("All POI's loot has been reloaded!");
}```
well you are casting somewhere
IE you are doing (Player) sender somewhere
most likely before this check
oh yeah i am
you need to do the casting after the check
alright 👍
wait but then i cant check if the player has the permission in the first if statement
since im using p.hasPermission()
you can, you first do your check to see which sender is which. Once you know its a player, then do your casting and then do your permission check
you just have the order in the wrong arrangement is all
alr
why is this if statement not getting called when im moving from the world "world" to the world "poi" witha multiverse portal?
if (e.getTo().getWorld().equals("poi")) {
getLogger().info("if statement called");
Inventory savedInv = p.getInventory();
getLogger().info(savedInv.toString());
}```
A World object is never equal to a String object
Check if the location is inside the BoundingBox.
You first need to convert the Location to a Vector ofc. (toVector())
Hi, I want to store enchantment into my config (like this):
enchantment:
-SHARPNESS:2
-LUCK:3
But when getting enchantments from an ItemStack i found that Enchantment.getName()' is deprecated and i should use use Keyed.getKey() witch returns an NamespacedKey. I have no idea how NamespacedKeys work, please help
A namespaced key contains two values
a namespace and a key
The namespace would be minecraft and the key sharpness
so minecraft:sharpness
thank you i think i understand it now
I have these particles spawning at a block with an offset, how do i make them offest above the block and not both ways
nvm i just added to the default y position
do i have to clear a players inventory before setting it's contents?
Hello, so I'm trying to make an input GUI with fake (packet based) signs, I've tried a lot of different things for over 10 hours, but with ProtocolLib I never figured out how to change the text on the sign and with player.sendBlockChange + player.openSign i got the issue that the sign has to be real. All the information on google is outdated because signs have 2 sides now and the TILE_ENTITY_DATA packet takes different parameters, and everyone with same issue in this discord never figured it out.
My last idea is to have a real sign to open at some location far away which solves the issue of not being able to add default text to the sign but now I got the problem that if the sign is like 5+ blocks away it instantly closes.
So my question is if there is a way to cancel the closing of a sign when you move too far and if anyone has a solution for one of my other problems it would be amazing.
Stuff that doesn't work:
||player.sendBlockChange + player.openSign: https://pastes.dev/VKQNnbwnLQ Issue: java.lang.IllegalArgumentException: Sign must be placed||
||ProtocolLib player.sendBlockChange + (packets server to player) OPEN_SIGN_EDITOR & TILE_ENTITY_DATA: https://www.spigotmc.org/threads/signmenu-1-16-5-get-player-sign-input.249381/ Issue: signData doesn't hold a varInt anymore https://wiki.vg/Protocol#Block_Entity_Data||
This seems very complicated so thank you in advance to anyone who even tries to help me
why does getLogger().info("left after completion"); and getLogger().info("left before completion"); not get triggered in this event?
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent e) {
getLogger().info("player teleported");
Player p = e.getPlayer();
if (e.getTo().getWorld().getName().equals("poi")) {
savedInv = p.getInventory().getContents();
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "You entered the POI!"));
} else if (e.getFrom().getWorld().equals("poi")) {
getLogger().info("from poi");
Vector fromLoc = e.getFrom().toVector();
if (leavePyramid.contains(fromLoc)) {
getLogger().info("left after completion");
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "Congratulations! You completed the POI!"));
} else {
getLogger().info("left before completion");
p.getInventory().setContents(savedInv);
p.sendMessage(ChatColor.RED + "You exited the POI without completing it so your items didn't save.");
}
}
}```
which mc version
1.20.4
As 7smile7 previously said, a World object can never be equal to a string
ohh i must have missed that thanks!
let me just try some stuff
how do i get the block under the player?
Whats a secure way to store data on a file and it not be changed by the user
@final wharf
thanks
so like this java @EventHandler private void onPlayerMove(PlayerMoveEvent event){ Player player = event.getPlayer(); Block blockAtFeet = player.getLocation().getBlock(); Block blockUnderFeet = blockAtFeet.getRelative(BlockFace.DOWN); Location location = event.getPlayer().getLocation(); List<Material> blocks = Arrays.asList(Material.values()); Material material = blocks.get(0); //random logic location.getBlock().setType(material); }
@final wharf don't just copy it, try to understand it
Do I just make a custom file format and use Serializable
I'll just do that nvm
oh thanks
Hello I just started my spigot plugins development and I need help I really don't know what I'm doing wrong
ask ur questions
Okay nevermind idk how to show it without screenshots
?img
Can't send images? That's because you're not verified! Use !verify to complete verification.
Alternatively, you can upload screenshots to any image hosting site and share the link.
Here's some screenshot utilities that you can use to upload images.
Lightshot: https://prnt.sc
Imgur: https://imgur.com/upload
Flameshot: https://flameshot.org
?conventions
^^ name your methods correctly
I just started and that tutorials from youtube or somewhere are just making my brain getting crazy
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.cheese.naukaconfigu.NaukaConfigu;
public class Zmienne {
public static String join_message(NaukaConfigu plugin) {
String join_message = plugin.getConfig().getString("join_message");
return join_message;
}
public static Boolean allow_Heal(NaukaConfigu plugin) {
Boolean allow_Heal = plugin.getConfig().getBoolean("allow_Heal");
return allow_Heal;
}
}``` That is working but If I want to use allow_Heal
For Beginners:
Codecademy - Learn Java: Interactive Java programming course from basics to more advanced concepts. Perfect for absolute beginners.
https://www.codecademy.com/learn/learn-java
JetBrains Academy - Java Developer Track: Learn by doing with projects and challenges. It covers Java fundamentals to advanced topics.
https://www.jetbrains.com/academy/
Udemy - Java Programming Masterclass for Software Developers: Updated courses that cover Java 8 to Java 17 features. Suitable for those who prefer structured learning.
https://www.udemy.com/course/java-the-complete-java-developer-course/
For Intermediate to Advanced Learners:
Oracle Java Tutorials: The official guides by Oracle for Java programming—great for understanding the depth of Java.
https://docs.oracle.com/javase/tutorial/
Baeldung - Learn Java and Spring: Focus on Spring Framework and modern Java technologies. Best for intermediate learners aiming to expand their knowledge.
https://www.baeldung.com/
Practice and Hands-on Learning:
Exercism - Java Track: Solve exercises and get feedback from mentors. Great for practicing coding skills.
https://exercism.io/tracks/java
LeetCode: Practice your coding skills and prepare for technical interviews with Java.
https://leetcode.com/
Free Resources and Documentation:
Java Programming and Documentation: A comprehensive collection of Java programming guides, tutorials, and API documentation.
https://docs.oracle.com/en/java/
Community and Support:
Stack Overflow: A vast community of developers. Great for getting help with specific problems or understanding concepts.
https://stackoverflow.com/questions/tagged/java
r/learnjava on Reddit: Join the community of Java learners and get advice, share resources, and discuss projects.
https://www.reddit.com/r/learnjava/
Remember: Learning to program takes practice and patience. Don't hesitate to experiment with code and participate in community discussions. Happy coding! 🎉
ohh thx
@Override
public boolean onCommand(@NotNull CommandSender Sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
Boolean allow_Heal = Zmienne.allow_Heal(this.plugin);
Player player = (Player) Sender;
Double hp = player.getMaxHealth();
player.setHealth(hp);
return false;
}
}```
but about that error is in the Boolean allow_Heal = Zmienne.allow_Heal(this.plugin);
Boolean allow_Heal = plugin.getConfig().getBoolean("allow_Heal");
return allow_Heal;
}``` that is the class
yeah you have no idea how static works
@sand spire managed to get this to work. but im pretty sure in 1.20+ its inpossible to have the sign be non visible, since the 1.20 client actually started immediately closing out of the sign if its far away.
Take the time and go through a Java course or two
yes you're right I tryed finding it but I didnt
okay I'm going to
?learnjava
For Beginners:
Codecademy - Learn Java: Interactive Java programming course from basics to more advanced concepts. Perfect for absolute beginners.
https://www.codecademy.com/learn/learn-java
JetBrains Academy - Java Developer Track: Learn by doing with projects and challenges. It covers Java fundamentals to advanced topics.
https://www.jetbrains.com/academy/
Udemy - Java Programming Masterclass for Software Developers: Updated courses that cover Java 8 to Java 17 features. Suitable for those who prefer structured learning.
https://www.udemy.com/course/java-the-complete-java-developer-course/
For Intermediate to Advanced Learners:
Oracle Java Tutorials: The official guides by Oracle for Java programming—great for understanding the depth of Java.
https://docs.oracle.com/javase/tutorial/
Baeldung - Learn Java and Spring: Focus on Spring Framework and modern Java technologies. Best for intermediate learners aiming to expand their knowledge.
https://www.baeldung.com/
Practice and Hands-on Learning:
Exercism - Java Track: Solve exercises and get feedback from mentors. Great for practicing coding skills.
https://exercism.io/tracks/java
LeetCode: Practice your coding skills and prepare for technical interviews with Java.
https://leetcode.com/
Free Resources and Documentation:
Java Programming and Documentation: A comprehensive collection of Java programming guides, tutorials, and API documentation.
https://docs.oracle.com/en/java/
Community and Support:
Stack Overflow: A vast community of developers. Great for getting help with specific problems or understanding concepts.
https://stackoverflow.com/questions/tagged/java
r/learnjava on Reddit: Join the community of Java learners and get advice, share resources, and discuss projects.
https://www.reddit.com/r/learnjava/
Remember: Learning to program takes practice and patience. Don't hesitate to experiment with code and participate in community discussions. Happy coding! 🎉
I recommend jetbrains academy, but they're all decent
how do i hide an entity on defautl?
Omg that is perfect I never managed to get the text on the fake sign, thank you for spending an entire hour to solve my problem. Can you send the code so I can see what I was doign wrong 💀
well there might be an issue, i used no protocol lib with mojang mappings
idk what ur using rn
I tried it with protocollib & player.sendBlockUpdate
ru using mojang mappings?
i'm not sure what those are but I'm using spigot methods & protocollib methods
bassically its a set of names that converts obfuscated methods to non obfuscated methods. then when you compile it automatically converts it all back to the obfucated version
ur will need that if u want to use my version
Doesn't really matter, I just want the result
does that mean I need to import with maven or is it already in spigot just less beginner friendly
bassically u would need to do this https://blog.jeff-media.com/nms-use-mojang-mappings-for-your-spigot-plugins/
it would fk up any nms already present in ur plugin tho
Only protocollib stuff or also spigot stuff? or just anythign with packets
this is the first time i'm consciously working with packets so doesn't really matter i guess
alright tysm I'll let you know when i got it to work
EDIT: it works!
edit: resolved
do i need to put it in my plugin folder or something
or is it my new server folder cause when I click on the spigotjar it starts generating stuff
or how do I forceupdate
is someone help me with ClientboundSetEntityDataPacket
?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. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
Did you forget the --remapped flag
i dont know how to do the DataValue part
i am trying to make a armor stand invisible
how do I even do that; java -jar BuildTools.jar --rev 1.20.4 --remapped
yeah like that
Yes
yeah but where
in cmd
oh in here <classifier>remapped-mojang</classifier> <!-- Important! -->
or just open the BuildTools GUI if you can't figure it out
no
The GUI has an option called Generate Remapped Jars
It'll also show you the command preview when you switch back to the main page.
You can always run java -jar BuildTools.jar --rev 1.20.4 --remapped if you have the jar file as well. :p
oh so I should make it compile again with this on
Yes
i have no idea how to run code anymore since I downloaded spigot 💀 it just always compiles now
It should be quick compared to the first run.
how can i set the datavalue part in ClientboundSetEntityDataPacket
Take a look at how Mojang uses it
where can i do that?
It works now thanks yall!
never done that before do u want me to just decompile minecraft?
You already have
o?
If you're using Intellij just Ctrl click the class you want to open
oh ok
i did open the packet class but what do i do with it
Now you can see the methods and stuff
if you can't find what you need keep digging through other classes
if you can't figure it out you can always work with a packet library like ProtocolLib and PacketEvents
SynchedEntityData data = stand.getHandle().getEntityData();
data.set(new EntityDataAccessor<Byte>(0, EntityDataSerializers.BYTE), (byte) 0x20);
ClientboundSetEntityDataPacket dataPacket = new ClientboundSetEntityDataPacket(id, data.packDirty());``` is it just this?
yk imma test it
omg yes
i am pro
this feels soo goood
whatt happens to a packet entity when i leave?
It gets removed
What version are you using?
nvm you figured it out
The entity doesn't exist on the server, when you leave the client just nukes all the world data
somebody help me out
?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. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
automatically disconnects upon receiving it with this message
Show code
a buffer is a netty ByteBuf
it's scattered all over, but okay
@SuppressWarnings("UnstableApiUsage")
public static ByteBuf createBuffer(PacketWrapper<?> wrapper, int initialCapacity) {
if (wrapper.buffer != null) throw new AlixException("Incorrect invocation of NettyUtils.createBuffer - buffer exists ");
wrapper.buffer = Unpooled.buffer(initialCapacity);
wrapper.writeVarInt(wrapper.getPacketTypeData().getNativePacketId());
wrapper.write();
return (ByteBuf) wrapper.buffer;
}
public static ByteBuf constBuffer(PacketWrapper<?> wrapper) {
return Unpooled.unreleasableBuffer(createBuffer(wrapper, 1));
}
I create my static final ByteBufs using constBuffer
and the PacketEvents PacketWrapper
I do this mainly because I need to send packet "silently" so without the interceptor knowing
so I get the silent context the same way PacketEvents does:
@SuppressWarnings("UnstableApiUsage")
public static ChannelHandlerContext getSilentContext(Channel channel) {
return channel.pipeline().context(PacketEvents.ENCODER_NAME);
}
I then invoke silentContext.writeAndFlush(somePacketByteBuf.duplicate())
but it just gives me this
the only real difference I found is that PacketEvent's allocates the ByteBuf with Channel#alloc#buffer
but upon investigating that just uses the default ByteBufAllocator
there's no console errors
Have you tried asking the man himself? @alpine urchin
but I also don't know where to find the client-side decoder code, which could help me out
yes
he said contact netty
lmfao rip
and netty said contact the api
he's also really against the idea of not fully using his api
and engaging with netty
public void increaseXP(int amount){
xp += amount;
TextComponent textComponent = new TextComponent();
textComponent.setText(ChatColor.DARK_AQUA.toString() + "+" + amount + " ("+ xp + "/" + (xp * 100) + ")");
Bukkit.getPlayer(uuid).spigot().sendMessage(ChatMessageType.ACTION_BAR, textComponent);
if(xp > level * 100){
xp -= level * 100;
level++;
Bukkit.getPlayer(uuid).sendTitle(
ChatColor.AQUA.toString() + ChatColor.BOLD + "LEVEL UP!",
ChatColor.DARK_AQUA.toString() + (level-1) + " ➡ " + level,
4, 35, 7);
}
}```
am i doing anything wrong releated to the TextComponent?
Yes
Appending colors like that is icky
You should be using the component builder
well textcomponent inherits from component builder
so whats the problem
public void increaseXP(int amount){
xp += amount;
TextComponent textComponent = new TextComponent();
textComponent.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
textComponent.setBold(true);
textComponent.setText("+" + amount + " ("+ xp + "/" + (xp * 100) + ")");
Bukkit.getPlayer(uuid).spigot().sendMessage(ChatMessageType.ACTION_BAR, textComponent);
if(xp > level * 100){
xp -= level * 100;
level++;
Bukkit.getPlayer(uuid).sendTitle(
ChatColor.AQUA.toString() + ChatColor.BOLD + "LEVEL UP!",
ChatColor.DARK_AQUA.toString() + (level-1) + " ➡ " + level,
4, 35, 7);
}
}```
why did stand.setCustomNameVisible(true); work but not stand.setVisible(false);
You can't use legacy string colors in components
I send a buffer with a message
so what should i do
No clue, just keep in mind there are 2 packets for setting an entity "invisible"
thing is
There's a visible field in the metadata and there's the remove packet
CustomNameVisible is also part of the metadata
But not part of the bitmask 0
i had stand.setVisible(false); b4 too but it didnt work...this time i had both packet and .setVisible soo idek which one did it
i will removing .setVisible in next compile
I need more context
is this code correct
no
wait imma trry something else
homie you can't use legacy color codes like that
i will do some debugging and if i still occur some issues i will lyk
Bukkit.getPlayer(uuid).spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(textComponent).create());
alright
should i keep this in?
No it does nothing
choco
do you know netty
or rather client-side decoding?
of bytebufs into packets
I've manually made some packets via bytebuff and sent them to the client
ohoho
Pretty easy as long as you follow the format Mojang uses
tell me
after some debugging it was indeed the packet that did the magic!
did you read the messages I sent?
czu I also do it
and it just
does this
Idk how the header would be messed up
so you sent packets wiithout using nms?
afaik the game handles that
what bytebuf did you use?
Just a normal FriendlyByteBuf wrapping Unpooled.buffer
why the wrap?
maybe I should wrap mine as well
and did you have some constant packets?
Well you need to pass something to FriendByteBuf constructor
I do it like that
And it has a bunch of nice write methods
stand.setCustomName("something");
SynchedEntityData data = stand.getHandle().getEntityData();
data.set(new EntityDataAccessor<Byte>(0, EntityDataSerializers.BYTE), (byte) 0x20);
ClientboundSetEntityDataPacket dataPacket = new ClientboundSetEntityDataPacket(id, data.packDirty());
```can the name part be working cause i got the data after i set the name?
I don't see it
FriendlyByteBuf
not a class
oh it's PacketDataSerializer
yall know how if a player dies after getting hit by another player , for example a player a hits player b , and then player b dies from example fall damage , and it says that player b died while trying to escape player a ? is it possible to get who got kill credit or do i have to reimplement that myself
getKiller in the death event
wouldnt that only get if the kill was direct ? like killing them with a melee weapon?
or does it get even if they died from natural causes after a player hits them
oooh ty
does someone know?
Try and see but that should work
alr i will add the name setter after i send the packet
meh
I hate that a bunch of the synced data fields for entities are private
yea my theory was correct
since i set the name before it set the name
wait so i can just do the normal methods ands send a data packet at the end
good to know
that’s your interpretation but it’s logical
nms would be analogous
the more you tamper around with NMS, the less help you can expect from the Bukkit community
since you’re doing some additional netty stuff, it’s not really my responsibility to help you use those features
I'm aware
i also mentioned its fair for you to use those netty things as an addition to my library
but it's not like you help out of responsibility
good
but saying im against you not fully using my api is reaching too far
since i mentioned i understand why you’re doing it
public static ChannelFuture writeAndFlushConst(ChannelHandlerContext context, ByteBuf constByteBuf) {
ByteBuf send = context.alloc().buffer().writeBytes(constByteBuf);
return context.writeAndFlush(send);
}
``` I changed it to this like ViaVersion does it
still doesn't help
i might look at this again
if you would allow constant wrappers
and also cache the silent context
then I'd really appreciate it
make a github issue
and maybe even one line could've helped
to solve this
well I'm currently
rewriting the core mechanics
or rather I already finished it
it's just that it kicks me out
you can make an issue, and leave it in our hands
i’m generally not against it
once all other things have been solved, im down to add this little addition
well it's pretty necessary for me
and also create like PacketCreationUtil
so that you don't have to create a new packet for each version by yourself
so methods like newPlayerInfo or newMessage and stuff
Hello,
I'm looking to serialize the contents of players' inventories using a HashMap<UUID, ItemStack[]>.
I manage to store this via JSON in the following way:
{"568d365a-5fb2-4169-8e64-fb33b8c108ef":[{"type":"STONE","amount":1,"meta":{"repairCost":0,"hideFlag":0,"unbreakable":false,"damage":0,"unhandledTags":{},"persistentDataContainer":{"customDataTags":{},"registry":{"CREATE_ADAPTER":{},"adapters":{}},"adapterContext":{"registry":{"CREATE_ADAPTER":{},"adapters":{}}}},"version":2975}},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1},{"type":"AIR","amount":1}]}
It seems that you're having trouble loading the data back into a HashMap; it always ends up being null.
public static File onStaffModeFile;
@Override
public void onEnable() {
try {
getDataFolder().mkdir();
onStaffModeFile = new File(getDataFolder(), "staffmode.json");
if(!onStaffModeFile.exists()) {
onStaffModeFile.createNewFile();
}
Gson gson = new Gson();
Writer writer = new FileWriter(onStaffModeFile, false);
BufferedReader reader = new BufferedReader(new FileReader(onStaffModeFile));
HashMap<UUID, ItemStack[]> map = gson.fromJson(reader, HashMap.class);
if(map!=null) {
StaffCommand.setInStaffMode(map);
reader.close();
} else {
gson.toJson(new HashMap<UUID, ItemStack[]>(), writer);
StaffCommand.setInStaffMode(new HashMap<>());
writer.flush();
writer.close();
}
paste bin?
?paste
Is there a reason why you're using gson instead of the yaml config api?
or
gson doesn't serialize it properly
^^ you'll need to fix your serializers
someone have idea why dont work?
@Override
public CompletableFuture<Void> insertArena(Arena arena) {
System.out.println("insert");
return CompletableFuture.runAsync(() -> {
run("INSERT INTO arenas (id, name) VALUES (?, ?);", statement -> {
System.out.println("insert 1");
statement.setString(1, arena.getId().toString());
System.out.println("insert 2");
statement.setString(2, arena.getName());
System.out.println("insert 3");
statement.execute();
System.out.println("insert " + arena.getName());
});
});
}
[18:00:07 INFO]: [Duels] [STDOUT] insert
[18:00:07 INFO]: [Duels] [STDOUT] insert 1
[18:00:07 INFO]: [Duels] [STDOUT] insert 2
[18:00:07 INFO]: [Duels] [STDOUT] insert 3
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
No you did not send what the run method is for example
but last dont print
what you expect it to do, and what actually happens
void run(String sql, ThrowingConsumer<PreparedStatement, SQLException> consumer) {
try (Connection connection = this.database.getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
consumer.accept(statement);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
last check dont log
statement#execute block but why
Where's the throwing consumer from
arena needs to be static since you are technically creating an inner anonymous class
most likely, but its also likely the error is that arena is not static lol
I don't see any other possible error it could be unless its some weird NPE
bruh
oh wait
I was supposed to make an issue
@Override
public CompletableFuture<Void> insertArena(Arena arena) {
System.out.println("insert");
return CompletableFuture.runAsync(() -> {
run("INSERT INTO arenas (id, name) VALUES (?, ?);", statement -> {
System.out.println("insert 1");
statement.setString(1, arena.getId().toString());
System.out.println("insert 2");
statement.setString(2, arena.getName());
System.out.println("insert 3");
System.out.println(statement);
statement.executeUpdate();
System.out.println("insert " + arena.getName());
});
});
}
[18:11:01 INFO]: [Duels] [STDOUT] insert
[18:11:01 INFO]: [Duels] [STDOUT] insert 1
[18:11:01 INFO]: [Duels] [STDOUT] insert 2
[18:11:01 INFO]: [Duels] [STDOUT] insert 3
[18:11:01 INFO]: HikariProxyPreparedStatement@1401976472 wrapping INSERT INTO arenas (id, name) VALUES (?, ?);
[18:11:01 INFO]: parameters=[77f58b16-ca87-4991-a02e-28bed0ad8586, test]
bros tryna commit xd