#help-development
1 messages Ā· Page 1713 of 1
So you should be bless and help me š
annot cmd frameworks are limiting
I mean.. you donāt really need much in a command
Except some form of CommandSender
its about reusability
And parameters
I guess
Spigot Programming.. Episode 1 āSetting up the Projectā - GoodInside
I should become a yter
Lmao
I wrote one
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Ofc you did
hey there quick question, is there any way to display custom messages when loading into my server? like right when you click to connect to the server the dirt block screen to display custom text
How do I set up the bot?
Pretty sure youād have to that with a resource pack
Which iirc is loaded after that screen
Pls help someone
what bot
you just said "the bot" and didnt specify what it is
specify what you want to ask next time
Okay
Where exactly do you want to display custom messages?
In the server list of the client?
i think he said like when the game loads
so when it says like "Joining world" like that
If so then this is your event:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/server/ServerListPingEvent.html
declaration: package: org.bukkit.event.server, class: ServerListPingEvent
but that impossible lol
asking for a little spoonfeed, i cannot figure it out. how can i apply my custom made sharpness 6 book to a sword.
the sharpness caps at 5 for me btw
addUnsafeEnchantment
no, you dont understand
PrepareAnvilEvent + addUnsafeEnchantment
i have made this custom book
So yeah just listen to PrepareAnvilEvent
maybe uh
i can set the book a metedata
i understand what you are trying to get but i dont know how to
ah ok
ohhh
if (firstItem.equals(Material.WHATEVER_SWORD) && secondItem.equals(MY_BOOK)) { do that and that? }
Something like
@EventHandler
private void onPrepare(PrepareAnvilEvent event) {
Inventory inv = event.getInventory();
ItemStack one = inv.getItem(0);
ItemStack two = inv.getItem(1);
if(one == null || two == null)
return;
ItemStack result = one.clone();
result.addUnsafeEnchantments(two.getEnchantments());
event.setResult(result);
}
ah so pretty close
thanks
but @echo basalt now it doesnt apply books at all lol
even vanilla books
you didnt say what inventory?
uh
you can also do something like
Inventory inv = event.getView().getTopInventory();
This doesnt work. Again: Enchanted books keep their enchantments in a separate meta.
hmm
bit stupid but eh
idk i really want to ask straight up for a spoonfeed
whats a spoonfeed
@EventHandler
public void onPrepare(final PrepareAnvilEvent event) {
final AnvilInventory inventory = event.getInventory();
final ItemStack one = inventory.getItem(0);
final ItemStack two = inventory.getItem(1);
if (one == null || two == null) {
return;
}
final ItemStack result = one.clone();
final ItemMeta meta = two.getItemMeta();
if (!(meta instanceof EnchantmentStorageMeta enchantmentStorageMeta)) {
return;
}
result.addUnsafeEnchantments(enchantmentStorageMeta.getStoredEnchants());
event.setResult(result);
}
This is
asking for the whole code
aah
yeah @lost matrix i apologise :(
i always do that lol but i didnt know what a spoonfeed was
uu what will this do
Enable unsafe enchantments to be applied on the anvil
@lost matrix whats ur language level
Patterns in 'instanceof' are not supported at language level '5' getting this
16
ok
also i have a problem on this
getting weird errors
@EventHandler
private void onMove(final PlayerMoveEvent e) {
final Player player = e.getPlayer();
final Material playerMaterial = this.playerMaterials.get(player.getUniqueId());
if (playerMaterial == null) {
return;
}
final Location from = e.getFrom();
final Location to = e.getTo();
if (to == null) {
return;
}
final int fromX = from.getBlockX();
final int fromY = from.getBlockY();
final int fromZ = from.getBlockZ();
final int toX = to.getBlockX();
final int toY = to.getBlockY();
final int toZ = to.getBlockZ();
if (fromX == toX && fromY == toY && fromZ == toZ) {
return;
}
final Block below = to.getBlock().getRelative(BlockFace.DOWN);
final Material belowMaterial = below.getType();
if (belowMaterial != playerMaterial) {
return;
}
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9WalkDetector > &fYou are walking on "));
this.playerMaterials.remove(player.getUniqueId());
}
``` it didnt work ingame
@lost matrix it gives me this error when building
lambda expressions are not supported in -source 1.5
and it isnt colored red or anything
is it a warning or an error
ah
never seen that shit
need spoonfeed for this lol
Can anyone help me, I installed spigot on my server and now no one without op canāt build
@solar sable you should start using debug messages instead of just requesting help all the time here
and you don't need to make every variable final ffs 
did they try going outside the spawn radius? also, #help-server
@lost matrix getting this error in classes including the anvil event
How much is the spawn radius?
usually 10
and spawn protection is like 50
Look into your server.properties
Change your language level then
pom.xml
To whatever you have installed
<properties>
<java.version>16</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
oh is it just 16?
they changed it?
from 1.<versiontype>
to just <versionType?>
now it straight up rejects to compile ._.
the error will tell you why
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project SMPCore: Fatal error compiling
find the actual error in the log
š
My bet, you don't have java 16 JDK installed
pretty sure i do
will check for safety tho
whoops
my java home is set to 8
do i need to restart pc for it to apply?
same error btw
i did
what in cmd
Open a new cmd window
i have opened
Did you reopen it after changing java home
yea
You're building with Intellij right?
ye
Is jdk 16 selected in project settings
omfg, how do i do that
which
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>16</release>
</configuration>
</plugin>
You need to also change the project sdk
hm
ok will do
IT COMPILED
GG
the plugin died tho...
java.lang.UnsupportedClassVersionError
hmm
will check internet
that means the version of java you built against is not the same as yoru server version
what spigot is your server running?
?paste the full version error
or is 52 8? I forget
@EventHandler
private void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
Material playerMaterial = this.playerMaterials.get(player.getUniqueId());
if (playerMaterial == null) {
return;
}
Location from = e.getFrom();
Location to = e.getTo();
if (to == null) {
return;
}
int fromX = from.getBlockX();
int fromY = from.getBlockY();
int fromZ = from.getBlockZ();
int toX = to.getBlockX();
int toY = to.getBlockY();
int toZ = to.getBlockZ();
if (fromX == toX && fromY == toY && fromZ == toZ) {
return;
}
Block below = to.getBlock().getRelative(BlockFace.DOWN);
Material belowMaterial = below.getType();
if (belowMaterial == playerMaterial) {
return;
}
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9WalkDetector > &fYou are walking on "));
this.playerMaterials.remove(player.getUniqueId());
}
``` still need help with this
yep 52 is 8, 60 is 16
^ the problem is, it wont send the message
bro this is weird as hell
Well the error says you are trying to use some preview features
If it's not sending the message, then it could be hitting either one of those returns. Try adding logs in each of them to pinpoint where that might be
Yaknow, temporary sysouts
try it with a clean spigot 1.17, as we don;t support any other forks
ah okay
alright
System.out.println("it passed this return"); etc
any one tell me how to make bazar plugins
Man
right on top of those returns
learn java
but isnt clean spigot very cocky?
Spigot is what we support
Well go on and test it, see where the code ends up
okie
@eternal oxide the problem still goes in clean spigot btw
?paste teh error. Spigot error will be different
your java must be out of date, if you are running 16
my jre?
alright
the jre your server is running on
first test what jre yoru server is using
in a switch in java 8
should i return true and break
or just break
or i shouldn't break
i guess no need to break
command prompt, and I think java -version
if you are returning then no need for a break
ok
oh well
i have 16.0.2 on intelij
jdk i mean
i will check if it works on my main smp
yoru java looks fine
in your server launch line you could add --enable-preview after the java.
and to modify a string list in fileconfiguration, should i set it again
or if i add, set or anything will it get modified ?
On plugin start -> load list into memory and edit it there
On plugin stop -> save list into file again
will it get saved ?
i want to modify it, and reload
i dont have time for it
sucks
No
if i do saveConfig ?
Still no
if i get the list, modify it and set it and then save ?
Then yes
for hashmap, it was not like this
It is
You cant edit a data structure in memory and expect it to be magically save to disk
so guys i found which one that is wrong and apparently its this
private void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
Material playerMaterial = this.playerMaterials.get(player.getUniqueId());
if (playerMaterial == null) {
System.out.println("test54");
return;
}
well somewhere in that
it worked in a hashmap š¤
but it doesn't get saved in disk i guess
the code isnt mine tho, 7smile7 did it
No it didnt
i tested
it saves armorstand id
and when i send destroy packet
it will get destroyed
all lines
@lost matrix i promise its the last ping. when you told me to change to java 16, my whole plugin just got messed up and it died, have any alternatives for the anvil to accept unsafe enchants?
Sure. Just use ancient syntax then you can compile it with Java 5 or whatever you have
alright
@lost matrix i need help
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Create a thread in case the help channel you are using is already in use!
You need to add content into the HashMap.
Key -> Players UUID
Value -> The Material the player has to search
private final Map<UUID, Material> playerMaterials = new HashMap<>();
public void setPlayerMaterial(final Player player, final Material material) {
this.playerMaterials.put(player.getUniqueId(), material);
}
This method could then be called by an Event like the PlayerJoinEvent or by a command.
idk where to put this
oh ik where
private final Map<UUID, Material> playerMaterials = new HashMap<>();
public void setPlayerMaterial(final Player player, final Material material) {
this.playerMaterials.put(player.getUniqueId(), material);
}
@EventHandler
private void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
Material playerMaterial = this.playerMaterials.get(player.getUniqueId());
if (playerMaterial == null) {
System.out.println("test54");
return;
}
``` is this correct @lost matrix ?
Yes but "test54" will still be displayed.
NPE if playerMaterials doesn't contain uuid
oh yeh ill remove that
Nope
Nope you are not done
This method could then be called by an Event like the PlayerJoinEvent or by a command.
aah
Yeap
are you saying like, i need to insert it to a class that has onEnable(); ?
What do you think would be the cause for a NPE here? Which pointer exactly points to null.
.get() doesn't return null if its not in the map. It returns an NPE
No. Hashmaps return null if the key is not present.
^
This should all be in your listener class
im just asking what do you mean by
This method could then be called by an Event like the PlayerJoinEvent or by a command
yup it is
But when is your method setPlayerMaterial called?
If its never called then the map is always empty
Ah Yeap. My bad
private final Map<UUID, Material> playerMaterials = new HashMap<>();
public void setPlayerMaterial(final Player player, final Material material) {
this.playerMaterials.put(player.getUniqueId(), material);
}
@EventHandler
private void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
Material playerMaterial = this.playerMaterials.get(player.getUniqueId());
if (playerMaterial == null) {
System.out.println("test54");
return;
}
``` before the eventhandler
There you declare the method. But just declaring a method in a class does literally nothing.
I think you should try to get a grasp of the java basics before continuing.
Just the very basics
This code will run but it will just print out "test54" forever.
but will it say the message that i want it to?
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9WalkDetector > &fYou are walking on "));
``` this
No
oh
What are you trying to do? Do you want to write a game where certain players have to find a specific block?
no
i just want it to detect the block the person is standing/walking on but the last method i used, everytime i move my camera it will repeatedly sends the message so i want it to be only when it is standing on that one block and moving the camera will not make it spam the message
Ah. Then you can scrap the Map and just use this:
@EventHandler
private void onMove(final PlayerMoveEvent event) {
final Player player = event.getPlayer();
final Location from = event.getFrom();
final Location to = event.getTo();
if(to == null) {
return;
}
final int fromX = from.getBlockX();
final int fromY = from.getBlockY();
final int fromZ = from.getBlockZ();
final int toX = to.getBlockX();
final int toY = to.getBlockY();
final int toZ = to.getBlockZ();
if (fromX == toX && fromY == toY && fromZ == toZ) {
return;
}
final Block below = to.getBlock().getRelative(BlockFace.DOWN);
final Material belowMaterial = below.getType();
player.sendMessage("You entered a " + belowMaterial + " Block.");
}
thats a lot of finals lol
yum
int toX = to.getBlockX();
how to make this not null
look above
oh
thanks
yay it works now
finally
thank you @lost matrix !!
double heart for you <<33 ā¤ļø !!
oh sorry but this will be the last ping from today
but
@lost matrix
how to make it not detect air?
if i jump it detects air so
You should be able to find that out yourself.
Just filter materials that are air.
Material has a isAir() method
is there a checker that checks if the player has been kicked?
declaration: package: org.bukkit.event.player, class: PlayerKickEvent
is NNY still around here?
He probably got banned again
oh damn
He'll be back though
what about cipher
Not sure
I am unsure of where to ask this, but I discovered that SpigotMc doesn't support [hr] [/hr] in their plugin descriptions - Is there another way to create a rule/line?
so every move you're declaring variables? ā£ļø
any UTF-8 characters
Yes. Not a problem in the slightest.
Why do you want an array if you already got a List?
can i cast it directly to a ItemStack[] ?
i save inventory contents to a file
guys despite the version of the tutorial, can i just use an outdated tutorial like a 1.15 plugin tutorial and use it in a 1.17 plugin?
depends on the tutorial
cause i dont see many tutorial uses 1.17 yet so
setContents() needs an ItemStack[]
then why not use addAll?
unless you are preserving nulls you will not be putting items back in the same places
Should be fine
Casting a List you get from a YamlConfiguration will always be unsafe
okay thanks!
but menus is a hashmap<UUID, ItemStack[]>
to store a player's vault
So? you chose to use an array
i dunno if there is a better way
how can i set nothingness in a minecraft recipe?
yes
Material.AIR doesnt work btw
this wont work
but what will?
there should be an exp bottle
i also tried not defining "G"
{" "," C ","CAC"} No G
No, it's saying to add a "" between them
or .toString()
Yeah exactly. You can't add ChatColor and Player. You need a String inbetween so it can assume them both to be Strings and append them.
sender.getName() is a String
this doesnt work btw
So either add a String between or do player.getName()
it does if the rest of yoru code is correct
java
ItemStack item = new ItemStack(Material.EXPERIENCE_BOTTLE);
NamespacedKey key = new NamespacedKey(this, "exp_bottle");
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
meta.setDisplayName(ChatColor.GOLD + "Experience Bottle");
List<String> lore1 = Arrays.asList(ChatColor.AQUA + "Smash this bottle against your head", ChatColor.AQUA + "To get experience!");
meta.setLore(lore1);
item.setItemMeta(meta);
ShapedRecipe recipe = new ShapedRecipe(key, item);
recipe.shape(" ",
" C ",
"CFC");
recipe.setIngredient('F', Material.GLASS_BOTTLE);
recipe.setIngredient('C', Material.LAPIS_LAZULI);
return recipe;
@eternal oxide pretty sure this is correct
You never registered the recipe
i did i think
not in that code
Bukkit.addRecipe(this.getRecipeExp()); its in the onEnable thing
no
guys how to give a player an item?
Get his inventory and add an item to it
ah okay
Thereās a method called getInventory() call it on your player variable then call addItem(item) on that
is there a java doc for this? idk how to use it yet lol
just make a command that sends you a message, so you can teleport to the player and give them the item manually
?jd
thank you
?jd-s (:
isint that beautiful
we should show people that
the ones that only ask for "premade code"
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); something wrong in this line
?paste
yeah, why are you using enchantment?
whats the alternative then
its an exp bottle
Probably want to check if the instance is of type EnchantmentMetaStorage
its literally ItemMeta
is it possible to export structures to other worlds?
Schematics? (via WorldEdit)
kind like bedrock edition, with the structure block you can?
is there really no better way to save an inventory to a file?
Sure the structure block is also viable for smaller structures
Years ago I saw plugin using some.. library? In class he did @Somthing and it generated setter and getter methods.. But it was generated at build time, so the code looked really clean. Do you know what I might be reffering to?
in normal worlds
Just Base64 encode it
lombok
would i get one output from it or multiple (for each itemstack)?
One String for the whole Inventory
so when you save the structure to disk the file containing the structure is generated?
addItem does not issue an item to the left hand. how to fix it?
use a scheduler
you could repeat the code you are running, but hold it for 10 seconds wont work
you can pause it
and resume it later with a scheduler
addItem does not issue an item to the left hand. how to fix it?
get the left hand and set the item holding the one you want?
I have a code that gives out an item if it can stack
but if I use the code and hold the item in my left hand, the code is executed but the item is not added
addItem does not evaluate equipment slots
Add item works great, but you do want to have an inventory check, and then do something with it. Like dropping it on the ground.
You could just make your own add item method
ŃŠ¾ŠµŃŃŃ Š¼Š½Šµ Š½ŃŠ¶Š½Š¾ ŃŠµŃез ŃŠøŠŗŠ» полŃŃŠøŃŃ ŃŠ°Š·Š¼ŠµŃ ŠøŠ½Š²ŠµŠ½ŃŠ°ŃŃ?
sorry
I cant read cyrillic...
that is, I need to get the size of the inventory through the cycle?
Your for each syntax is faulty
for (final Entry<Enchantment, Integer> entry : player.getInventory().getItemInMainHand().getEnchantments().entrySet()) {
final Enchantment enchantment = entry.getKey();
final int lvl = entry.getValue();
}
But i would def not make such a long statement
No idea what dad means. If you want to add an ItemStack to the offhand then you need to manually check.
so its been a while since i coded for the last time, i have a Block block, i cant cast this to an itemstack to add it to the player inv, how can i add it?
i forgot how to turn it lmao
hes asking a question for me lol
You cant cast a Block to an ItemStack. A Block can have multiple drops. So you need to get all the drops of this
block as ItemStacks.
so 7smile7 you remember my walk detecting event?
ItemStack breakItem = ...;
Block block = ...;
List<ItemStack> drops = block.getDrops(breakItem);
what i want to do is, instead of sending a message, i want it to give the player the block they are on
so if i walk on grass = get grass yk the deal
public ItemStack toDirectItem(final Block block) {
return new ItemStack(block.getType());
}
this, thank you
You can not cast an Enum constant to anything else.
he probably wants to cast blockdata lmao
ItemFrame is not a Block but an Entity
š¤
This doesnt work for any type of Entity. This isnt even valid Java code.
how can i remove that annoying unbreaking 1 thing (completely no reference to skyblock, its just an item that i give to my smp players that find exploits)
hey i'm trying to build a gradle project but it can't find the spigot.jar?
i dont believe u can remove enchantment lores
Add the item flag that hides enchantments
I get this error
> Could not resolve all files for configuration ':randompackage-spigot:compileClasspath'.
> Could not find spigot.jar (org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT).
Searched in the following locations:
http://ci.ender.zone/plugin/repository/everything/org/spigotmc/spigot/1.14.4-R0.1-SNAPSHOT/spigot-1.14.4-R0.1-SNAPSHOT.jar
are u trying to use spigot api w nms
or spigot api
spigots api is the one provided by the maven repository
does .strikeLightningEffect give fire
Nope it just plays the effect
oh then my friend caused a false alarm. what an idiot
hey, I'm using some file systems to delete the world folder and replace it with a different world folder, it copies the files fine, but when I go on the server it still has all the old world, but restarting the server kicks the changes into effect. Is there any way I can make it do it by itself? I use this.plugin.getServer().unloadWorld("world", false); to unload it and Bukkit.createWorld(new WorldCreator("world")); to load it which I'd expect makes it work but it doesnt
I need some help with the end portal frame, i have to check if the portal frame has a eye or not.
So i tried this: https://paste.md-5.net/qemitusabu.java
But it always says NO, which i don't understand..
It's a end portal frame and i get the block data :/
i) Make sure it makes out through the if statement, add a sysout to make sure it does
Thanks, but i already found the issue..
Quiet silly one... A other event set the block to air.. sooo yea xD
_>
can a save a list like structure in base64?
like ```yml
test:
- 1
- 2
- 4
but i need to access the "test" too
wdym
well i figured it out
š¤
only stupid thing is that i cant call static methods from my command class cause player isnt static
how is that stupid lol
or i place make those methods not static and place them in another class or i make a instance of my command class and call the method :/
prob the first
why do you need static methods?
what are they doing
but the first option is better
saving and loading lists that my command need
I smell poor design
i think you're right
how do you spawn a structure? specifically a stronghold. i want the server to spawn strongholds with every chunk but i can't figure out a simple way to do it
If you want the entire world to be a stronghold you should probably write your own world generator
is there a way to just spawn a structure though?
something like world.spawnStructure
is there any method like that
this is not really what its supposed to be
static brrt
also that
Hi all, I am trying to create a plugin that uses WorldRegion. I'm setting the plugin up with IntelliJ, but I simply can't seem to avoid including the classes from the WorldRegion jar and shading them so my plugin can't access the other plugin at runtime. Any tips to what might cause this?
any help?
Listen to the playerinteractevent
Coordinates of what
Idk i cant go to the message anymore
Ah i see. The message still doesnt really explain what coordinates though
declaration: package: org.bukkit.event.player, class: PlayerMoveEvent
Its means Or
Bassically
U can combine 2 if statement liks so
If(check1 || check2)
Statement returns true if one of them is true
No problem
I'm genuinely surprised I have managed to make my onClick inventory handler crash the server with no exception in the console
congrats
love it
Perfection
rolled
throwback to when my friend crashed the server I used to be a dev on by setting himself as the subject for a /carry command, thus resulting in the attempt of "player#addPassenger(player)" which crashed the server because you can't set an entity as its own passenger. (there's no check on it!)
Why not use coords š¬
Theres gonna be a lot of the blocks
especially if this is the whole click handler lmao
ItemStack item = event.getCurrentItem();
if (item == null) return;
switch (item.getType()) {
default:
closeAndOpen((Player) event.getWhoClicked(), null);
}
event.setCancelled(true);
So what
I just dont want to š©
Whats the aplication?
alright this probably is the best solution... but how do you generate a structure in the world generator?
7smile7 likes final
application?
Probably to save on memory
Its just when a block is clicked a player is given an item
Yea where do you need this for
like whenever a chunk is created how do you make it just spawn in a stronghold?
simple question: i have a foreign key and a table that uses that. who sould i delete first? the row that uses the foreign key or the foreign key
Why would you need so many blocks that u cant use locations then
I'd say the foreign key first
I just want to try it both ways
Would metadata work?
Store location of block somewhere and when they click block at location give item. Itās really not to hard, if you need more features associated to the block, make an object, load blocks on enable, store block object in map. Bing bing bang boom.
I know but I want to try it without using locations
wats ur mc version
1.17.1
Its always super inefficient to use console commands, so is there a way to display a title to a player, I could just use a message but I like titles
you could use PersistentDataHolder
but this will not work for all blocks
Block and BlockData do not extend PersistentDataHolder
only TileState does
so if you really wish to to it this way your best bet is to make a custom Metadata System
since the solution above will only work on blocks with a TileState. for example a furnace, a chest
Thank you
š
If you're fine with utilizing an API, NBTAPI (https://www.spigotmc.org/resources/nbt-api.7939/?__cf_chl_jschl_tk__=pmd_41EM9ERMsEPzczL2bp.OoABKNw1DG0mec6X_9sw.74g-1633028114-0-gqNtZGzNAeWjcnBszQn9) contains a class called NBTBlock (only based on block location) that could be integrated to fix your issue.
Think about what your trying to achieve though, like logically. If you want a specific block to do something, you need a way to check this. You can do this based on type or location. Thatās really it. Metadata doesnāt save on reboots. An api is really unnecessary for this. I mean this is how crates work, a location, click block at location with crate key in hand. Give random reward.
Player player = (Player) event.getEntity();
if(player.isGliding()){
BukkitScheduler scheduler = Bukkit.getScheduler();
scheduler.runTaskTimer(plugin, () -> {
player.setGliding(false);
}, 1L * 1L /*<-- the initial delay */, 5L * 1L/*<-- the interval */);
// With BukkitRunnable
new BukkitRunnable() {
@Override
public void run() {
player.setGliding(false);
}
}.runTaskTimer(plugin, 1L * 1L /*<-- the initial delay */, 5L * 1L/*<-- the interval */);
}
}```
Hello, how can I make this run 20 times and then stop?
Caching MySQL ResultSet
Just increment an integer and check if integer is 20, then cancel runnable
thank you
How would I be able to share a variable across multiple classes?
eg:
class ClassWithVariable {
public ClassWithVariable() {
int myVar = 69420
}
}
class ClassWithoutVariable {
public ClassWithoutVariable(int myVar) {
System.out.println(myVar)
}
}
for example
there are libraries like guice:
class ClassWithVariable() {
public ClassWithVariable() {
Injector injector = Guice.createInjector(your guice module)
injector.get(ClassWithoutVariable.class)
}
}
class ClassWithoutVariable() {
@Inject
private int myVar;
@Inject
public ClassWithoutVariable(int myVarTwo) {
/// logic
}
}
i was going to say, learn java first, then mess around with using spigot api
or use some api that doesn't have as much bad practices as bukkit/spigot
not a great thing to learn from
i think discord just had a little outage, i lost connection from dms as well for a few seconds
possibly yeah
Same
Im just trying to share variables with different classes
Is it actually really hard to do that in java?
its not
just that its clear that you're new and I don't want people new to java to go through learning from bukkit stuff
but it is your choice, you do you
I'm a bit confused
I'm adding client-side lore:
And it mostly works fine
but not really
Yeah, I understand
But I don't know how else my plugin will work without sending the location to another class
what's the issue?
The middle line isn't being added
even though literally everything else is
The middle line isn't empty or null
And it isn't an issue with colorization as I've done tests with colored strings and it works fine
try adding a + "" after it
Still doesn't work
what kind of metadata
if you try it without colour codes does it work?
its weird because it's displaying in console as having the rarity there
it just doesn't add it to the item
Have you tried survival mode
I'm in survival..
Hm
can we see your getRarity method?
can someone gimmi some basic help- How can i like "get a file" then write in it?
so i have a .log file
Any idea how I'm supposed to get the entity a player might be within attack range of? (take a look at the blue line)
and i wanna like "log things" to it
Like the displayname
I dont think a skeleton skull has PDC data
oh
it's a tile entity
?
legit google "java write to file" or something
i did
@median flint iirc Purpur had a patch that keeps stuff like displayname and lore intact after a block has been placed, you might wanna look how that was implemented
(purpur is a paper fork)
How would I do this?
Thank you
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
how to cancel when a player say something in chat?
ah okay
How do I change the display name of an item/block using metadata?
Apparently not colorizing the lore makes it work ??
Idfk
might be because I have another plugin messing with client-side lore
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.
got this error how do i fix?
i can share code if necessary
You are trying to read past the end of a file
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.
bump
why whenever i do SqlUtil.getConnection().close();
on disable
it has a chance for the plugin not to disable
and i have to kill the server
its so annoying
also the plugin disables before the world saves
getConnection() is a Connection
are you sure that dat file is actually a valid gzip compressed file? seems like gzip is expecting more but reaches the end (either because it's an invalid gzip file or not gzip compressed at all)
wait how do i gzip the file?
you're loading the file as a gzip file, so it should already be gzipped
Can a placed block be an ItemStack?
no
oof
placed block is Block
How do I give the placed block a display name?
?
create invisible armorstand with nametag in the position of block
Use hologram api
It doesnt need to have a hologram
Just like when the block is mined it has a different name in your inventory
ahh
that "blue line" is called look vector im pretty sure there's a way to get that vector via bukkit api
so you can just change name of Itemstack
I thought placed blocks couldnt be ItemStacks ;-;
when player get certain item
so whats the error im getting?
If you want it to be specific blocks you will have to store that data somewhere
@tall dragon You know how you said to use coordinates to check for a block, how would I do that?
your code is assuming the file is a gzipped file and I'd be guessing the file that you're loading is not gzip compressed. so either your misusing the gzip stream or the file is not what you expect it to be. which one it is I can't say because I don't know what it's supposed to be.
or the file is broken, which could also be true
the file is just a empty minecoins.dat file
You can't readObject on an empty file
Hey, I have had a brainfart and forgot how to use XMaterial with gradle can anybody advise? š
well empty is no bueno then and you need to handle that before passing it over to the gzip stream
the only problem is idk what the hashmap would be to write in the .dat file
well you seem to be writing the data of another plugin, so you'll have to compare with that on what it expects / how it works
how do I add a player argument to a command?
no its all one plugin my whole manager code = https://pastebin.com/BH1sZgDn
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.
create a new Location and just compare
your loop is wrong when you write the file, you're creating a new file for each offline player
is there any bedwars plugin for spigot 1.8.8?
you can get a player for a given name and resolve the player that way
bedwars1058
marcely's bedwars
The right click event and the block are in different classes
need to pay to download :(
this is only called on my onEnable()
and onDisable so it shouldn't matter
how do I get all of the online players in a list of strings?
well then just take care of checking if the file is actually there and has content and you're good
loop through all online players and put their name in a list? seems pretty straight forward
yeah, when I learned java I had a lot of trouble with lists
soo
how?
wait
would this work? java args[0].equalsIgnoreCase(LifeSteal.getPlugin().getServer().getOnlinePlayers().toString())
No
that statement makes no sense
idk
If you want to see if a string is a valid online player
Use Bukkit.getPlayer and do a null check
so get an instance to the class where the block is then
;-;
could you help me out a bit
I really don't know what to do
"get an instance of the class where the block is then" means do new className() "new" creates a new instance of a class, remember that when you do this you reset the variables in it (unless you specify that you dont want them to reset like static variables etc)
oo
creating a new instace of a class when you need to use it multiple times is not a good idea, you can save a variable with the class for example
varName = new className()
varName.data
varName.setData
etc
that and
new className.data
new className.setData
etc
are the exact same thing
but the first one tends to be better in most casses
this is so confusing lol
once you understand the structure of java you realize how simple it gets
is the new className() the class its already in?
what?
I already have a class
Do I like use a different class name or is it still the same class
new className
qhat is the problem here
i dont get the question
say the problem to me
I need to pass a variable from one class to another
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Where exactly would I put this?
^
here
oh i'll try that ig
ćć
true
Im trying to make a noteblock item with custom block meta already set, im trying this
private ItemStack createItemStack(int note, Instrument instrument){
ItemStack itemStack = new ItemStack(Material.NOTE_BLOCK);
BlockStateMeta blockStateMeta = (BlockStateMeta) itemStack.getItemMeta();
NoteBlock noteBlock = (NoteBlock) blockStateMeta.getBlockState();
noteBlock.setInstrument(instrument);
noteBlock.setNote(new Note(note));
blockStateMeta.setBlockState((BlockState) noteBlock);
itemStack.setItemMeta(blockStateMeta);
return itemStack;
}```
But it says
`CraftMetaItem cannot be cast to class BlockStateMeta`
What can i do about this?
hi, i have problems with merchant inventory :(
i created a class extending EntityVillager, and gave it a new MerchantRecipe, but when i righ-click the villager, the inventory disappears
ur trying to cast an ItemMeta to a BlockMeta
that doesn't work
how do i get the block meta then?
well you would need reference to a placed block in the world
but i cant, its an item
you can do it with commands
/give @s minecraft:note_block{BlockStateTag:{note:9,instrument:bass}}
will give you the item, i just want it in a gui with code
?paste
https://paste.md-5.net/owumuyujiz.java that's the code
BlockSateMeta extends ItemMeta so i think you should be able to cast
and as its possible in vanilla with commands it has to be possible with spigot really
I donāt think spigot has an API for it
But I could be wrong
BlockStateMeta is for shulker boxes
and noteblocks
and many other blocks
Evidently not if you canāt cast it
then tbh thats kinda shit tbh
lol
so how can i do it then? i need to be able to basicaly set the item given by this command /give @s minecraft:note_block{BlockStateTag:{note:9,instrument:bass}} into a gui slot with spigot
does anyone know something about this? i'm dying š
how can I create a client entity using protocollib
that works for a placed block, but i dont think it would work for an item
as how can i cast the itemstack to a noteblock
@undone aspen just create the blockdata
ItemStack item = new ItemStack(Material.NOTE_BLOCK);
ItemMeta itemMeta = item.getItemMeta();
BlockData data = Material.NOTE_BLOCK.createBlockData();
NoteBlock noteBlock = (NoteBlock) data;
noteBlock.setInstrument(/* TODO */);
noteBlock.setNote(/* TODO */);
((BlockDataMeta) itemMeta).setBlockData(noteBlock);
item.setItemMeta(itemMeta);
this should work for you
just checked it
It does, thank you very much
š
Anyone know if theres a way to increase the max level of honey that a beehive can have?
not sure thats possible with the api. but i might be wrong
you could create an item that gives you X times the normal amount? not sure tho
Thats almost Java
BuildTools keeps installing maven because it says "Maven does not exist. " Any way to fix this? I definitely have maven installed. If I run "mvn" in terminal it works.
šµāš«
I don't know if you're really being serious
how do you make an item that is given to a mob undroppable while still keeping the basic mob drops
sorta like the dropChance:0 thing in nbt
wait can i just use nbt
Get the equipment and setXdropChance
Exists for the 4 armor slots, and the two hands
ok
no
just the armor and weapons
lol
wdym
u might be able to use the lure thing
like hypixel does
ye i think thats the lure for the item
*lore
lol
You can register custom enchantments to the registry
But I believe you still need custom lore to show the text
Does anyone know if I can add nbt when checking for the item in hand Material.FIRE_CHARGE
Explain?
how do you kill in a radius around an something
im trying to kill all the items around a dead player
player.getNearbyEntities(5, 5, 5, entity -> entity instanceof EntityItem); something like this
does the death event happen before they die btw
You can cancel drops
I think you can just remove all the drops in the death event
event.getDrops().clear();
thx
?
i believe it is
i can do e.setCancelled() on PlayerDeathEvent
No you can't
huh
It does not implement cancellable
Not on spigot anyway
paper
lol
public class EntityDeathEvent extends EntityEvent implements Cancellable {
public class PlayerDeathEvent extends EntityDeathEvent {
lol i already got it working btw
why whenever i do SqlUtil.getConnection().close();
on disable
it has a chance for the plugin not to disable
and i have to kill the server
its so annoying
also the plugin disables before the world saves
getConnection() is a Connection
Use a connection pool
Handling connections manually us not recommended. Use HikariCP or some other connection pool.
yea i am
wait
i can do that?
with hikari normally?
can i do HikariDataSource.close();?
Close your connections as soon as you are done with them
so onDisable()?
No. Right after committing the batch. You should have a connection for only a few milliseconds.
wait what
i just make the connection and then use it to make preparedstatements
and close it when server closes
so you make a new connection each query?
You get a new one from the pool when needed
so hikaridatasource.getConnection() makes a new one?
You can even add a flag to make Hikari yell at you if you forget to close them
setConnection(hikariDataSource.createConnectionBuilder().build());?
or
So I wanted to make something that would make the fireball in this block: https://pastebin.com/aFU8n7pf
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.
setConnection(hikariDataSource.getConnection());?
Each time you want to query your DB you should get a completely new connection. Dont store it anywhere.
okay
so in every query method, i do
Connection conn = hikariDataSource.createConnectionBuilder().build();
right?
No
getConnection()?
You initialise HikariCP once. One single instance. Then later on you get connections using HikariDataSource#getConnection()
okay
well i've made the hikaricp once anyway
guys what is the difference between a Statement lambda and an expression lambda
so every query method i use Connection conn = hikariDataSource.getConnection(); instead of storing it in the class?
because i kinda dont wanna see this warning lol
even tho it is a warning i just dont like seeing it lol
Show the line that causes it
well its a lot actually but ill just show one
if (e.getMessage().toLowerCase(Locale.ROOT).contains("fuck")) {
e.setCancelled(true);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&l(!) &bHey, no swearing ") + p.getDisplayName());
}, 20);
}
``` context on what i am doing, its just a swear detector lol
(x) -> { x.run() } This is a statement
(x) -> x.run() This is an expression
XClass::run This is also an expression
the lambda is the Bukkit.getScheduler().runTaskLater(plugin, () -> {
Yeah, it's suggesting you remove the { } from your lambda
because it's just a single line expression
aah okay
Though tbf, out of a preference of style, I too would use braces here because the line is as long as it is
I'd throw it onto a new line in a block like that as well
I would shorten the line by a lot and using an expression or create multiple lines withing this statement.
@solar sable
Could make a local var for that entire message tbf
String message = ChatColor.translateAlternateColorCodes('&', "&c&l(!) &bHey, no swearing ") + p.getDisplayName()
Bukkit.getScheduler().runTaskLater(plugin, () -> e.getPlayer().sendMessage(message), 20);
Really comes down to preference at that point lol
Not like an expression is going to be faster than a statement (*in any reasonable way)
Can't you change that to a method reference
No
If you hack a bit then yes.
Wait...
?javadocs
?jd
wait whats the command
Close
oh there it is
lol
gonna check an event
whats the event name for a picking up item by a player?
oh nvm i found it
EntityPickupItemEvent
The scheduler prevents us from just using fields. So this would be the only way i can think of XDD
@Builder
private static class FutureMessage {
private String msg;
private Player player;
private void send() {
this.player.sendMessage(this.msg);
}
}
private final ArrayDeque<FutureMessage> messages = new ArrayDeque<>();
@EventHandler
private void onSneak(final PlayerToggleSneakEvent event) {
this.messages.add(FutureMessage.builder().msg("Hi").player(event.getPlayer()).build());
Bukkit.getScheduler().runTaskLater(this, this::sendPlayerMessage, 20);
}
private void sendPlayerMessage() {
Optional.ofNullable(this.messages.poll()).ifPresent(FutureMessage::send);
}
how to detect when a player pick up something on the ground using EntityPickupItemEvent?
You mean how to check the ItemStack that is being picked up?
yes
- Get the Item entity by calling
getItem()on the event. - Then get the ItemStack from this ItemEntity
lol that's one way to do it
floods my console with this
?paste
That's usually caused by the pool being full of open connections. So you're not closing them after you're getting them
oh
so do i do
Connection.close() after query?
After you've done your necessary operations on the ResultSet, yes
try (Connection connection = dataSource.getConnection()) {
// Use connection here
}
This will auto close the connection as soon as the try block is over.
oh thanks
i did this and idk if its correct
@EventHandler
public void OnPickup(EntityPickupItemEvent e) {
Entity player = e.getEntity();
ItemStack pickup = e.getItem().getItemStack();
String itemStr = toReadableString(pickup.getType());
int amount = pickup.getAmount();
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9PickUp Detector > &fYou've picked up &9x%d %s").formatted(amount, itemStr));
}
Try it and see
LGTM, but yeah, always best to test it out
will do
Also, TIL about String#formatted()
Wait. lachmclach you do commissions, right?