#help-development
1 messages · Page 1380 of 1
Ever
@lost matrix
Math.pow(500, 2)
Wouldnt be such a difference really. But the variable name makes this clear i think.
When she tells you "thats not 8 inches"
why does it give me an error
You got the IDE and the code. So you tell me 😄
We need to see more
You put teh annotation inside your onEnable
Oh i see
package me.configz1.spawnleave;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.java.JavaPlugin;
public final class SpawnLeave extends JavaPlugin implements Listener {
@Override
public void onEnable() {
private static final int MAX_DISTANCE_SQ = 500 * 500;
@EventHandler
public void onMove(final PlayerMoveEvent event) {
final Location worldSpawn = event.getPlayer().getWorld().getSpawnLocation();
final Location targetLocation = event.getTo();
if (targetLocation == null) {
return;
}
if (worldSpawn.distanceSquared(event.getTo()) > MAX_DISTANCE_SQ) {
event.setTo(worldSpawn);
}
}
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}
I think its best for you if you find out whats wrong with that code on your own.
Hint: You can not declare a method inside another method or constructor in Java.
oohk
it is! but the amount of packets they must have to send
fair bit of math too i guess
have got locale system with many languages working yey
can use it like https://i.kawaii.sh/Z2kvzLz.png
Locale is soon to accept player as an arg to getElement so it can get their language settings
or LocalPlayer for many messages
My computer crash and ... how I can fix this?
Spigot isn't imported I think
Could you make that screen a little smaller please
Oh event.player.* is imported, weird
Its not seeing your libs. As you are not using maven I've no clue how you refresh/clean your project in Intelij
even java dependencies aren't importing, 🤔
Maven one year I don't use Maven xD
oh thanks realy thanks
ffs why is there no Spigot interface for GameProfile. Im in reflection hell trying to add a simple Property in the GameProfile.
You can PR one if you want 👀
Only reason we don't have one is because no one's PR'd one
I knew this was coming...
I mean really though, it's true. If you need a feature, you can add it. We can't just know what everyone needs
Alright i think ill try making a PR again. Last time i got frustrated. But that was a while ago.
but but, don't take away the joys of reflection hell 😪
I was really happy to abstract that away from me until i realised that i cant use a generic for classes which are not on my classpath.
So ReflectiveAccess<OfflinePlayer> for accessing CraftOflinePlayer fields was fine but then it got just messy.
See that seems like so much fun and like such an easy usage XD
Yes. Many fun. Much wow. And type safe
Yes XD can't wait for the PR tho, can hopefully learn a bit from the shortcomings of papers player profile
hey i need to delete something from my config like jumpPad49 but it removes the thing on top like jumpPad1 not jumpPad49
show code
Regarding the contribution
So im not quite sure how to approach this. So my thought was to:
- Fork Bukkit and provide an interface that can be later implemented by CraftBukkit.
- Fork CraftBukkit then create a wrapper class that holds the GameProfile as handle.
Im actually not sure where Spigot comes into play.
And how to get a spigot jar with the patches applied from the repositories
Spigot patches Bukkit / Craftbukkit. You can probably just stick to modifying Bukkit and CB respectively
if (block.getX() == x) {
if (block.getY() == y) {
if (block.getZ() == z) {```These will always pass as you set them outside the for loop.
You are literally checking the same value against itself every iteration
so should i do like if (block.getX() == x && block.getY() == y && block.getZ() == z) {
isJumpPad is never going to be true as you never set it true.
your loop just runs to the end and falls out the bottom with the last entry in c
so how should i fix it
well, its alwasy going to be true then, so it exits on teh very first element
which is why you are deletign 1 and not 49
i dont get it how do i fix that code
then all your tests shoudl be against c.getInt("y") etc and set c at teh begining fo the for loop
yeah i got it i didnt notice that the x values are not being from config
ty
okey
Move configSection = c; to right after your for loop
then do your 4 tests, world, x, y, z against c
https://prnt.sc/11iyrub https://prnt.sc/11iyt89 I need help with the programming and I have an island floating in the air and would like to generate random ores in this cave, but how do I do that outside of this no ores are generated
Well, do you know where the cave is in the first place?
Yes, the cave always stays the same so I could know the location
Well, then store all the locations of the blocks in a hashset and then proceed to generate ores if a given block is exposed to one of the blocks in that hashset
So now I should click on each block and save that an ore is to be produced there. That is then 500-1000 entries
how do i stop that specific blocks get deytroyed by explosion
But how do I get the locations randomly from this hash set and so that the ores are not all in the heap so they are distributed.
Are you even generating the cave programatically @river spear ?
This is a built map and ores should only be generated in this cave that are visible so there are no ores behind the stones
Well then it is almost impossible to generate the ores without some large amount of work
If you are lucky the cave is filled with CAVE_AIR, so you could use that, but chances are you are not so lucky
But I don't want to produce caves, but ores
https://sourceb.in/f4mSrZB0xd - what it's doing is partially correct, it's putting the name and stuff, but it sends the message more than once, depending on how many quests I have, that's because I'm doing a for each, how could I fix it?
is it possible to give tirdent gravity for selected item?
Quick question, I got the location of an entity with getLocation()
I wanted to know how I could get this location but 3 blocks higher
To summon something 3 blocks higher than this entity
.add(0,3,0)
public static ItemStack createSkull(String url, String name){
ItemStack head = new ItemStack(Material.SKULL_ITEM);
if(!url.isEmpty()){
SkullMeta skullMeta = (SkullMeta) head.getItemMeta();
skullMeta.setDisplayName(name);
GameProfile profile = new GameProfile(UUID.randomUUID(),null);
profile.getProperties().put("textures", new Property("textures", url));
try{
Field profileField = skullMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(skullMeta, profile);
}catch (IllegalArgumentException|SecurityException|NoSuchFieldException|IllegalAccessException e){
e.printStackTrace();
}
head.setItemMeta(skullMeta);
return head;
}else{
return head;
}
} my code doesn't work
i want to create a plugin
that gives a player a player head
with a skin from mc heads
i found that code in the internet
but it doesn't work
it gives me heads without skins ;-;
here is my code can sb help me pls?
❤️```
What are you passing into the method
nowhere xd
i tried it in another method
but it doesn't work
oh
sorry
url to a skin
form mc heads
On Minecraft-Heads.com you can find more than 30.000 custom heads, which can be used to decorate your world! The collection is seperated into two databases: the first contains custom heads, which never change their texture, using the Give-Codes from Minecraft 1.8+, the second one includes player heads which can be used in all Minecraft versions.
the second var is not important
it's jus an item name that i want to set
Show us the exact URL you pass
eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjBiMzJkMmZlODZhY2JkOWVlZjI2ZWJjOTY4ODRjNzlkOWY5ZGRiMjVkY2JkYTIzODQ3NTcxYzIwNGQyZWRiNyJ9fX0=
private ItemStack getCustomHead(String value) {
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) head.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
profile.getProperties().put("textures", new Property("textures", value));
Field profileField = null;
try {
profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta, profile);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
}
head.setItemMeta(meta);
return head;
}```
This is what I use to get a custom head. just pass in the Value from minecraft-heads.
Yeah that URL is still base64 encoded
I made a plugin in Intellij, however when I try to load the compiled jar file to my locally hosted server it doesnt load. When someone else compiled the exact same plugin and sent me the jar file it works. Not sure whats going on here
Hey there, quick question. I'm trying to parse a configuration file using Bukkit's YamlConfiguration. I'm using YamlConfiguration#getKeys(true), where true indicates that I want all children. However it seems that an item with children isn't being returned? See the following config snippet:
debugMode: true
listenPort: 8080
tokens:
- name: TEST
token: ABC
scopes:
- READ_CONSOLE
- SEND_COMMAND
I only get back debugMode and listenPort. Anyone got any ideas?
Hi, i'm making a spigot plugin 1.16.5 with Intellij, but the IDE doesn't find net.minecraft.server, do u know why?
You're probably importing the API
If you're using Gradle:
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT'
Try using Maven and build spigot via buildtools (DO NOT USE ANY OTHER SITES)
the latter will also include net.minecraft.server code
But indeed, you MUST run build tools for your required version
where i have to put this?
spigot includes spigot-api, as such only latter is built
For Gradle, in dependencies.
https://github.com/TheDutchMC/BaseBukkitPlugin This might help
Well not must, there are (in my opinion) illegal sites that host nms for you
There are yes, but you should avoid those imo
I just try to steer clear of avoiding the full package in general, since it makes the plugin non version compatible. So I avoid NMS where I can and use reflection where I cant 😄
for the plugin i used the "Minecraft" plugin for Intellij
That should be fine, I think.
I use Eclipse myself so I cant provide any IDE specific support
Same here
btw i need NMS for a custom npc
Use ProtocolLib, or if you dont want that, use Reflection
because i didn't find a tutorial for ProtocolLib
i don't know how
APIs such as citizens exist for such things
i can't use that
The way you want to do it will tie you to that specific version. Since NMS imports are versioned
Can't help you without more info
So NMS Is a lot of minecraft+spigot source digging, remember that. But if you can figure out how to get the things you need, this might help you with reflection: https://github.com/TheDutchMC/SkinFixer/blob/master/src/main/java/nl/thedutchmc/SkinFixer/util/ReflectionUtil.java
because i need to make the ncp visible to one player only
for an anti cheat
Anyways, anyone got some ideas for this one? 😄
@lunar schooner I could be really wrong here, but in my testing I never get back values from deep searches so I always just iterate through when I need deep keys
Odd, Guess the api is a bit broken there then
Wait, what do you get back when you print the deep keys? @lunar schooner
Everything that does not have a child
So from my above YAML Example I get:
[20:05:58] [Server thread/INFO]: debugMode: true
[20:05:58] [Server thread/INFO]: listenPort: 8080
Nothing more unfortunately
Wait a sec, I never deleted the old config from my plugins folder 🤦♂️
me too
tokens: [{name=TEST, token=ABC, scopes=[READ_CONSOLE, SEND_COMMAND]}], oh like this. That isnt very optimal
Might just toss out this parser and use gson
I need to include gson anyways, so its not much of an issue :"D
In 99% of cases the api isnt broken but misused.
Or it's me messing up lol, happens to the best of us
I get
[20:19:42 INFO]: debugMode
[20:19:42 INFO]: listenPort
[20:19:42 INFO]: tokens
are you sure you're saving data like tokens.name = TEST etc instead of tokens = [data]
yeah its showing up as it should, its just not very nice to work with lol
oh alright
Gson is already included in spigot
to maybe make it more easy to read, this is the same but in json:
{
"debugMode": true,
"listenPort": 8080,
"tokens": [
{
"name": "TEST",
"token": "ABC",
"scopes": [
"READ_CONSOLE",
"SEND_COMMAND"
]
}
]
}
btw maven can't find the dependency
What do you use?
Correct, You need to build it locally with BuildTools
maven or gradle?
and you need the repository mavenLocal
Could not find artifact org.spigotmc
pom:1.16.5-R0.1-SNAPSHOT in spigotmc-repo
oh no the emoji lol
maven
then you only need to run buildtools
?bt
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
How do I cancel blocks from dropping items
If they break by any source
Not only players
i'm building but idk what to do after
By "any source" do you mean your plugin or also other causes?
what "doesn't work"?
there is nothing you need to do afterwards, BT will do everything for you
I mean like if a block is destroyed, by a command, a creeper, a player or anything else, it doesn't drop
Well it drops items
destroyed by a command would require teh command to properly break it
but where i have to put the build
Like nowhere, bt does it for you
an example is no good. give us specifics
You just need to build your version of spigot and it will install it into maven local
Well I have an item shooting fireball, and it destroys the ground
I want the ground to not drop the items
But to be destroyed
Can you store a 10x10x10 part of a minecraft world and put each block into a 3d array? If so would you have three for loops cycling through from bottom to top and adding each block position to the array? (Sorry for dropping g mid convo)
Then set the types to AIR instead of destroying them
ok, well the drop items event will not trigger for that
I can't since it's an explosion
well, you could likely inline everything in a single loop (sorry, wrong reply meant to reply to https://discordapp.com/channels/690411863766466590/741875863271899136/832684980626915399)
You can remove everything from the event and then manually set it to air
Or change the yield to 0.0
then listen to the explosion event
Or /gamerule doTileDrops false
Frick forgot about that command
it worked thx
why does everyone use
Player player = (Player) sender;
when sender can be a player
like is there any real difference?
why dont we just use sender.sendMessage or sender.openInventory etc
i use sender.sendMessage unless it needs the Player object for something
like location, inventory, etc
not sure if there is any actualy difference but i know there is no visible difference
hm yea it autofill to ((Player) sender).getLocation()
something like sender.openInventory() would not work because CommandSender can also not be a player
yea but if i do
sender.sendMessage("You can't run this command on console");
return true;
}```
before that
that works
its always a player
Anyone know how to use PacketPlayOutRelEntityMove on 1.16.5 NMS?
How would i go about doing this?
Modulo everywhere!
If you check if the sender is a player first then the cast to player is fine
Warning: your CPU likes that
And gives you access to a lot more methods
Just use 3 nested for loops
you probably saw this already but here's a thread https://www.spigotmc.org/threads/1-15-1-question.408836/
My commands are repeating in chat I can't figure out what's wrong
ok thanks
is there a comprehensive breakdown of licensure of spigot/bukkit code? like what code/binaries i can or cant include in a product or repository
Return true in the onCommand method
lol I was going to give a more hacky method
if you don't have double of your jars in the plugin folder
just put StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); at the beginning of the command code
and print it out
My onCommand method does return true and my command still is not working
can you paste it here
Gonna need a bit more info
is there a way to open an inv, allow the player to put a block in a slot and get the item meta and type of the block?
cant find a plugin that does that
You can listen to the InventoryClick event in that inventory
question about development ethics
currently in the midst of developing an RPG plugin with quests, spells, events, etc. and have gathered a small community of around 200 people interested in its progress
i haven't given a release date because it's a hobby project, a lot of the code has been optimized but i abused static to hell and back in some parts
hm thanks
the plugin runs smoothly for the most part as of now, but in the future as it becomes more complex, it will probably show signs of its age
the plugin is about 15k lines
so the question is this
tf you have there an entire server in a single class? lol
ha
it's just an estimation
i searched for \n in my IDE
but anyway
do you think i should:
A) start completely from scratch using the knowledge i have compared to when i started
B) continue as normal with better practice and clean up the code in parts with each update
Depends on your intentions with it
is that a general question?
Private? Public? Premium?
private, but if it gains traction i might hand it off to another developer in the future
or make it open source for people to tinker
i mean 15k lines of codes, you sure do know more than what you knew when you started, i think you can now make all those plugins better and more orginized
i'll admit
the idea of making the entire thing again seems time consuming but exciting
but dev rule N1: If it works dont touch it
I mean if it’s private it’s really up to you
You could run a pile of spaghetti for all the players care :p
i guess i am trying to future proof it
hahahaa yea
how do you upload that to github tho?
I mean if it’s a giant mess to maintain and expand, then you probably want to spend the time to fix that
is it 1 big file? hahaha
Future you will thank you
yeah thats what i am thinking
the code is organized but the main issue is old static abuse
honestly i think you should ask more experienced developers like 7smile7 and those guys
LMBishop
hmm alright
Sad developer noises
hahahaahaa
a rewrite does sound fun and would be better in the long run
cries in 3 months of experience
lol
ive been working on this for about three years but this is my second plugin
a lot of that time was used experimenting and making mistakes
and learning java in general
public void InvClick(InventoryClickEvent e) {
if (e.getView().getTitle().equals("Create the custom craft")) {
Player player = (Player) e.getWhoClicked();
//Determine what they selected and what to do
String meta = e.getCurrentItem().getItemMeta().getDisplayName();
player.sendMessage(String.valueOf(meta));
//e.setCancelled(true);
}
}```
any idea of why this isint running?
public void OpenGUI(Player player){
Inventory inv = Bukkit.createInventory(null, 27, "Create the custom craft");
ItemStack pane = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
inv.setItem(3, pane);
inv.setItem(12, pane);
inv.setItem(21, pane);
player.openInventory(inv);
}```
eventHandler
hmm
in console
already did
Also you really shouldn’t use the title to compare
Use the InventoryView returned from openInventory
yea i have never seen it any other way
Any idea why this isnt working ?
Im trying to spawn 3 boats on the client only, but it only spawns one
for(int i = 0; i < 3; ++i){
((CraftPlayer) target).getHandle().playerConnection.sendPacket(new PacketPlayOutSpawnEntity(boat, 1));
}
I assume you need different numbers in the packet
Not sure what that int field is though
ill try setting it to i and see what happens
i think thats the entity id or something cus it spawned a bunch of other stuff like fishing rods , end crystals etc
yeah
it probably relates to metadata in some way
instead of the amount
i dont think there is a way to spawn multiple entities at the same time using that
It’s an int
Is there a player ban event?
Yes 🙂
Bukkit.getBanList(BanList.Type.NAME); NAME but prefer UUID
Just add player to that list
There is a kick event
hmm i think that i can check in the quit event gives member the isBanned
is that a good idea?
Yes
Perhaps use something like e.disallow(AsyncPlayerPreLoginEvent?
^ that's how I do it, store banned players uuid and name check if player uuid is in list if true disallow
That’s basically what vanilla does
if they are banned it won't let them log in regardless
https://github.com/SamiCraft/MainPlugin/blob/main/src/main/java/com/samifying/plugin/events/PlayerLogin.java#L21 this is how i do player bans and allows
Although i need to shame banned players on discord server, this us why i need to check for banned event
I assume you can check if they are banned in the kick event
be careful when doing that
discord can ToS ban users for that sort of thing
though if it only mentions their MC username and not their discord account you are probably safe
still
i would tread carefully
discord goes down quite frequently as well btw 😛
?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.
trying to word it
sorry
so I'm trying to write a 'creature creator' mechanic for members of the content team on my server
there is an object called "Critter" which stores things such as its name, level, health, mana, etc
this Critter is paired with a reference ID of their choosing, and when a mob is spawned, it references this ID, which pulls data from the Critter object
here's a snippet
public class Critter implements Serializable {
public final String DEFAULT_CRITTER_NAME = "Unnamed Critter";
private String CRITTER_NAME;
private String CRITTER_COSTUME;
private int CRITTER_LEVEL;
private int CRITTER_STARTING_HEALTH;
private int CRITTER_STARTING_MAX_HEALTH;
private int CRITTER_STARTING_MANA;
private int CRITTER_STARTING_MAX_MANA;
//example
public Critter(String critterName) {
CRITTER_NAME = "CritterName";
}
public JSONObject serialize() {
//???
}
public Critter deserialize(/*any ideas?*/) {
//???
}
public String getName() {return CRITTER_NAME;}
public String getCostume() {return CRITTER_COSTUME;}
public int getLevel() {return CRITTER_LEVEL;}
public double getStartingHealth() {return CRITTER_STARTING_HEALTH;}
public double getStartingMaxHealth() {return CRITTER_STARTING_MAX_HEALTH;}
public double getStartingMana() {return CRITTER_STARTING_MANA;}
public double getStartingMaxMana() {return CRITTER_STARTING_MAX_MANA;}
}
here's a rough outline
i was thinking of serializing it into a JSONObject for easy storage, but then i have to store the reference to a bunch of keys as well
i also have tried implementing Serializable but am a bit stuck
Oh boy naming conventions
well thats better
but then the vars
lmao
should be camelCase without _'s
also you dont need to include 'CRITTER' in them as its a object class, not helpful.
For serialization, you need to create a JSONObject and add all the required fields like a map, and to deserialize you would have a constructor var of a JSONObject and return a new 'Critter' with all the options pulled from the JSONObject
I'll find one of mine for an example
if you like, but i have experience using JSON so it shouldn't be a problem
was just wondering if using json would be an absolutely terrible idea or if there is a better way of serializing
Np
nice, thanks
If you are going to be creating a lot of serializations for objects, id recommend you create an interface so its even across objects
Is there a way for me to turn off default crafting recipes, I want to make my own custom ones but I also want to stop default game ones
You can remove them with Bukkit.removeRecipe iirc
Might be able to remove them with a datapack too
ok, would I put that in the on startup code
yeah
what is iirc
if i recall correctly
o
k
is there a way to remove all of the default ones, or do i have to remove every one indifisually
is there a way to remove all of the default ones, or do i have to remove every one indivisually
pls ping me if responding
I believe you can get an iterator of all recipes and then call remove on each one
Of course that may cause issues with other plugins
HashMap<UUID,Integer>
Do hashmaps like the one above hold more than one item, So only on UUID or can it hold multiple?
so theoretically i could have all players stored into a hashmap?
learning java could help you
yes, that is very often what they are used for
the error quite clearly tells you the issue
if you are unable to read it then everything seeming right to you means little as you clearly don't understand how the language works
I think I should change the name of the class.
getNewScoreboard returns a bukkit scoreboard
But the variable is of your scoreboard type
What do I need to learn to make my own spigot plugins
I want to learn how to make custom enchant plugin
Java first
And then try https://www.spigotmc.org/wiki/spigot-plugin-development/ and
?jd
package index
Okay thanks
anyone know what library/classes are used to get timestamps from those 1m2d3s strings?
Hi again, How do I fix this ?
I think because of this, when I join in to the server, the scoreboard does not appear.
several plugins have for example a /tempban where you specify a time. as in 1d is 1 day, and 3s is 3 seconds
Consult the method directly below it
I see a few on spigot when I search it, you could also look at the source of a plugin that uses it
EssentialsX does I believe
yea they do, i jut cant find it
I mean it's not required if you do it from the method
@young knoll Scoreboard still does not appear when I join in to the server -_- any idea?
main
listener
No @brave glenHandler above the listener
Ah, I overlooked -_-
There is also @NotNull#8197
lol
Is there a way to make so that when you get it by a snowball it pushes back ?
Give it a tiny bit of damage
That will be null if kirilanBlok doesn't already have an entry for the player
What would you suggest?
Main:
Listener:
Change to Integer and nullcheck or use containsKey first
if you are going to update the value right after you can use getOrDefault with the default value rather than having to do a check
oh int to Integer save me xD, thanks
hello, how can I add my own changes to the kernel and build it through buildtools?
i tried to add changes via folder work
Is there a way to push a player upwards?
The only way Google proposes is with vectors and stuff
Broke my brain
set a players velocity to like 2 in the y @trail oriole
What is wrong with my yml file? I'm not too sure what the errors mean
show us the yml file
Mines:
A: a #change to what you want your mine to be called. Make sure to change both values!
1: pumpkin
prob: #this is the probability of how much will spawn. 0.2
2: yellow_flower
prob: 0.1
3: grass
prob: 0.15
4: gravel
prob: 0.2
5: lapis_ore
prob: 0.05
6: stone
prob: 0.13
7: cobblestone
prob: 0.12
8: hay_block
prob: 0.05
9: coal_ore
prob: 0.15
10: iron_ore
prob: 0.05
indentation is off
your prob for pumpkin is commented out so it won't have a value
^
ah, i see. Thanks
is there any way to do this number?
i mean where it shows above like tab complete but it doesn't actually complete when you tab
like for vanilla commands
like showing the syntax of the command
@EventHandler
public void onOpenInventory(InventoryOpenEvent e) {
openInvs.add(e.getPlayer());
}
@EventHandler
public void onCloseInventory(InventoryCloseEvent e) {
openInvs.remove(e.getPlayer());
}```
This tracks open chests etc but not the player's own inventory?
anyone know how to get a custom enchant to show up in tooltip?
adding it to an item work great, it glows, nbt shows that the item is enchanted
but if you hover over it, you wont see anything about the enchant
is hide_enchants flag on the item @upbeat yarrow
no, its a pickaxe
probably an interferring plugin
i only have my plugin active
it doesn't interact with items other than adding this enchant
what enchant does it add
how do you handle your enchant
I register it like this
public void registerEnchant() {
try {
Field f = Enchantment.class.getDeclaredField("acceptingNew");
f.setAccessible(true);
f.set(null, true);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
SpawnerEnchant spawnerEnchant = new SpawnerEnchant(this);
Enchantment.registerEnchantment(spawnerEnchant);
}```
then I have a command that adds the enchant to a users hand using this
ItemStack mainHandItem = toEnchant.getInventory().getItemInMainHand();
if (ToolHelper.isPickaxe(mainHandItem)) {
mainHandItem.addEnchantment(this.plugin.SPAWNER_ENCHANT, level);
} else {
return false;
}
just cancel the tabcomplete event
i think thats how they do it
yeah
😞
but that doesn't matter
event.setCancelled(true)
The onTabComplete method does not have a setCancelled
whats is the code for create NPC
PacketPlayOutAddPlayer iirc
Looking for a developer for my factions server, I can pay if needed. DM me if interested
?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/
So im trying to set block with the material from the config file, i keep getting an error 'java.lang.String cannot be cast to org.bukkit.Material' is there any way to change a string to a material?
Material.matchMaterial
is that on the sLoc.getBlock() ?
it's a method from Material enum
hi, it´s me again, this time the problem than have mario091205 is from his host, he need a solution for his server to work without a problem
Hello, why this is not working? , i'm working on PSQL ;
java.sql.SQLException: Column 'Tokens' not found.
public static void createPlayer(String playername)
{
if (!exists(playername))
MySQL.update("INSERT INTO PSQL (Playername, UUID, Level, XP, Tokens) VALUES ('" + playername + "', '0', '0', '0', '0')");
}
public static void createTable()
{
try
{
PreparedStatement ps = MySQL.getStatement("CREATE TABLE IF NOT EXISTS PSQL (Playername VARCHAR(100), UUID VARCHAR(100), Level INT(100), XP INT(100), Tokens INT(100))");
ps.executeUpdate();
} catch (Exception ex) {
ex.printStackTrace();
}
}
I WAS Putting the Tokens on the CreatingPlayer & the CreatingTable
then register it
public static void register(Player p)
{
try {
PreparedStatement ps = MySQL.getStatement("INSERT INTO PSQL (Playername, UUID, Level, XP, Tokens) VALUES (?, ?, ?, ?, ?)");
ps.setString(1, p.getName());
ps.setString(2, p.getUniqueId().toString());
ps.setInt(3, 0);
ps.setInt(4, 0);
ps.setInt(5, 0);
ps.executeUpdate();
ps.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
java.sql.SQLException: Column 'Tokens' not found.
i mean, CREATE TABLE IF NOT EXISTS is only creating the table if it doesn't exist yet, maybe your local database contains version of the table scheme without the Tokens column ?
Also there is no need for defining an int using INT(100)
int is 4 bytes by SQL definition
Is there any way to send a "BungeeCord" message from Spigot through the Spigot console? I have the code working for it to be possible by a player running a command, but trying to let console do it as well
You need an active Player in order to send a message via the plugin messaging channel.
So you can do it from the conosle with a random player as target.
Concerning that BungeeCord Messages are delivered through a player's connection to the server, this might be challenging.
oof
obviously means that you cannot send any bungee cord messages if there are no players on your sever
Yeah, I've tried using both of these to get a random player :
Player player = Bukkit.getOnlinePlayers().stream().skip((int) (Bukkit.getOnlinePlayers().size() * Math.random())).findFirst().orElse(null);
```and
```java
Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
```then:
```java
player.sendPluginMessage(Main.getPlugin(), "BungeeCord", b.toByteArray());
```to actually send the message
In which both give me errors in console..
You could write a little PrismarineJS application which starts with your server. This way you can have at least one connection
at all times. ^^
But at that point its probably better to think about proper communication channels.
I mean I'm fine with it only working while having a player online, just want to be able to run it from console instead of the player
Was there anything in specific that I was doing wrong with how I was getting a random player?
public Player getRandomOnlinePlayer() {
final Iterator<? extends Player> iterator = Bukkit.getOnlinePlayers().iterator();
return iterator.hasNext() ? iterator.next() : null;
}
Why use a random player and not just the first available?
I'll give that a go
Bukkit returns a Collection<? extends Player> (which doesnt have index access) and i couldnt think of a better way of getting a random player form it.
ah
That would return the first player wouldn't it? Every time
Still erroring out:
https://paste.helpch.at/suqohojeki.bash
? Bukkit.getOnlinePlayers().iterator().next()
ah thats what you did
Im not sure what "first" means in this case because Collection does not assure any order.
I didn't really read past random player
You are trying to pass a ConsoleCommandSender where a Player is expected.
If you run Bukkit.getOnlinePlayers() twice it would return the same order wouldn't it?
It should return the players in teh order they joined the server
Exactly
No. I think the Collection is taken from the values of a HashMap. So the order could be altered at any moment when
the values of the map get a new memory location for example. The Collection might appear to have a certain order but it is not deterministic.
But it depends where the Collection comes from.
Well if that's that case why not just use Bukkit.getOnlinePlayers().get(0)
Since that's what the iterator is doing.
- Its not doing that. This wouldnt even compile.
- The iterator already does all the complex work. Why re invent the wheel.
Simplicity and I updated it.
But the Collection originates from a List<CraftPlayer>
So the order is maintained at least.
There is no get method on a Collection
This is also not possible because the Collection interface does not specify any index access.
Index of then lol I'm not on my pc
The thing I'm confused about is the only thing that actually is using Player p = (Player) sender; is something to send the player a message if there was an error, the player sending the command isn't really touched by the actual thing sending the Bungee message (at least that I know of):
public static void sendMessageToBungee(String target, String message) {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {
out.writeUTF("Message");
out.writeUTF(target); // or "ALL"
out.writeUTF(message);
} catch (Exception e) {
e.printStackTrace();
}
getRandomOnlinePlayer().sendPluginMessage(Main.getPlugin(), "BungeeCord", b.toByteArray());
}
Index of would return the index of a specific element. Which is
- Not provided by the Collection interface either
- Not even helpful here
Its not sending to the player. its using the player object to send as the player queue is buffered
Or do you mean:
public Player getRandomOnlinePlayer() {
return Bukkit.getOnlinePlayers().toArray(Player[]::new)[0];
}
- Which would be way more expensive
- Throw an ArrayIndexOutOfBoundsException when no player is online
You can only cast a CommandSender to a Player if its really a Player object. But ConsoleCommandSender is not a Player.
Thats why you get a ClassCastException when you cast it to a Player. You cant just randomly cast Objects around.
I'm not on my PC. I'll check it later
So guessing I would have to check to see if it is run by the console and do something different or would there be an easier way to go about doing it?
You could always send it to a random player regardless of who sent the message.
So the cast is pointless unless you need methods from the Player interface.
Thanks for that explanation, figured it out
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I am trying to make a command that opens a crafting table menu. I tired creating an inventory with the type crafting but it gives this error. How would I do this?
Crafting is the 2x2 crafting slot in a players inventory. You probably want WORKBENCH
how do i portforverd bungeecord server
Ok that worked! Now here's another problem, if you press escape when in a normal crafting table, it drops the items (gives the items to the user) if they're in the crafting table when escape is pressed. I am just opening a crafting inventory, is there a way to give the player back the stuff that they left in the crafting table using the crafting inventory
Listen for the InventoryCloseEvent and drop all ItemStacks which are not null at the players location.
Mhm
is it possible to create a fireball with no fire?
AAA help
my intellisens in intellij stopped working
how do i get it to work so that it autocompletes minecraft related stuff?
Are you sure that spigot is on your classpath?
Do you use maven?
Then take a look into your pom.xml
Do you have thjs dependency:
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
its for paper instead
Look into Configure: Settings/Preferences | Editor | General | Code Completion
And make sure that Show suggestions as you type is enabled
np... probably wasnt done loading
^
I have 2 questions...
-
How would I spawn or automatically place water under me if I were to press a certain key?
-
How would I be able to enable water breathing, I am getting stuck on how to check if the player was in water or not
i forgot how to build my project
You cannot detect key presses directly, only interactions the server understands
You can try this: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Entity.html#setFireTicks(int)
declaration: package: org.bukkit.entity, interface: Entity
Does anyone have a regex which can match and get an array of all colors in a message? This includes hex colors btw, like &x&f&f&f&f&f&f
oh so if I were to like jump, could I spawn water under me?
Yes
Detecting jumps isn’t a perfect system, but it can be made well enough
I prefer the StatisticIncrementEvent and checking for the jump stat
` public void isInWater(___ e){
Material m = e.getPlayer().getLocation().getBlock().getType();
if (m == Material.STATIONARY_WATER || m == Material.WATER) {
e.addPotionEffect(new PotionEffect(PotionEffectType.POISON,
1 , 1));
}
}`
For 2) https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityAirChangeEvent.html
Listen for the event and cancel it if the player is flagged with some water breathing tag.
declaration: package: org.bukkit.event.entity, class: EntityAirChangeEvent
It’s valid for any entity
ok
thanks
yeah but I get an error for the addPortionEffect part and it only suggest me to delete isInWater
Only LivingEntities can have potion effects
oh so would i just put p instead of e for the potion part?
p as in player btw
one letter variables
:/
First thing you should do is replace single letter variables with proper descriptive ones.
How to set the eventhandler on other class?
I am a noob on plugin dev
What do you mean by that?
Gets the last color of a string iirc
that means I dont want to use @ EventHandler on my main class i want to set it on other class
the issue, it prints out literally nothing
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
System.out.println(ChatColor.getLastColors(colorized) + "bruh");
not even the bruh
system.out.println doesn't handle ChatColors
There is no color
there is a color
Those are strings, I would have thought it would just print them directly
I changed my e variable to entity cause I was assuming that was what it was... I copied this from a forum thing cause I just started working on this
If not even the bruh is printed then the method might not even be called at all
You can probably create one by looking at the implementation of getLastColors
Show the code in question pls ^^
`public void isInWater(isInWater entity){
Material m = entity.getPlayer().getLocation().getBlock().getType();
if (m == Material.STATIONARY_WATER || m == Material.WATER) {
e.addPotionEffect(new PotionEffect(PotionEffectType.POISON,
1 , 1));
}`
I'll change the poison effect part
Just pass a LivingEntity instead of an Entity to the method.
So first method parameter should be of type LivingEntity.
ok
so you mean the variable or the beginning of the parameter?
Tried and it doesn’t work
The method parameter of your isInWater method should be of type LivingEntity
Why are you still creating your own water detection?
Is it possible to make a custom class?
What exactly are you trying to achieve?
Entity#isInWater
ok
just simply create a new class?What i need to type on the main class to link the event class?
Sure. You have a full blown programming language at your disposal. You can create all the classes you want.
You could spawn a snowball and setItem to a fire charge
Not sure how similar it would look
`public void isInWater(LivingEntity entity){
Material m = entity.getPlayer().getLocation().getBlock().getType();
if (m == Material.STATIONARY_WATER || m == Material.WATER) {
e.addPotionEffect(new PotionEffect(PotionEffectType.POISON,
1 , 1));
}`
What should I do next?
Thanks!
You need to learn the Java basics or else you will be confused a lot.
Material m = entity.getPlayer().getLocation().getBlock().getType();
if (m == Material.STATIONARY_WATER || m == Material.WATER) {```
When I tried implementing SizedFireball it didn’t work
There were tons of issues
Cut out that, replace with entity.isInWater
You would need NMS for that. You cant just implement spigot interfaces.
Also entity.getPlayer isn’t a thing
thanks
its fine if you ping me
What’s nms?
So how would I modify it?
lol
I would advise avoiding that
Even if you make a new entity, it’ll have to render as an existing entity
Mhm, that I know
Where would I replace entity.isInWater?
`public void isInWater(LivingEntity entity){
entity.isInWater
e.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING,
1 , 1));
}`
This is what I have now
the entire part?
Should I have the if statement wrap around the entire thing or just inside the public void part
this code kind of works, it's supposed to works if there is one item in the crafting gui, but it doesn't work if there is a stack of items, it's supposed to get te amount it also doesn't do every item in the table, but i put a continue thing in there I know i'm doing something wrong
?paste
`public void isInWater(LivingEntity entity){
if entity.isInWater(){
e.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING,
1 , 1));
}
}`
Do you mean something like this?
Mhm
Why copy the item and not just use it outright
Sure
anyone got a method to just get a list of every color in a string
should it work now? Im too lazy to test it cause I'm really tired
will it have the same amounts and stuff?
Mhm
what about the problem where it doesn't continue (only works for one item)
were you responding to me or @deft sedge ?
It’s possible you need to iterate over getInventory.getContents
Does someone know what this is supposed to mean?
I have never heard of an Spawn Object packet. I have always spawned an ArmorStand with its raw id...
should it be event.getInventory().getContents()
Spawn object is a link, where does it go
Just to the protocol site.
Looks good to me
k thx
Which is not even a valid packet...
`public void isInWater(LivingEntity entity){
if entity.isInWater(){
e.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING,
1 , 1));
}
}`
would this be good for the water breathing thing?
I'm getting a few errors off of it
I’d imagine it’s just spawn entity
¯_(ツ)_/¯
@young knoll now none of it works it just eats my item, here is code: https://paste.md-5.net/dikafeseda.cs
@young knoll
You don’t have brackets around your if statement
o lmao oops
Please learn java before trying to use the spigot API
if (itemStack == null || itemstack.getType() == Material.AIR) {
yea I usually code on python :/
what is this
huh
what is this
i made explotion plugins
u mean this one?
yes
show code
Does the player see the message?
I see nothing wrong with that code
^
Try adding itemStack.clone to their inv
at teh very bottom, outside the for loop
You also don;t need to cast event.getPlayer() to Player
ok this is really wierd
i tried it with different blocks, and it worked for some of them
i tried it with nether gold ore, and it didn't work, but with nether mycelium thing it worked
idk y
You do realise when an item is added to a players inventory, if it can stack it will
as in player.updateInventory()
I have a gui that i want to have a button to have a potion bag for people what would be a good plugin to allow a player to have there own personal potion bag thats not a physical item
can't hurt
this is a plugin development server
idk maybe someone can help u tho
what server do i use then?
for plugin questions #help-server
this is the dev channel
ok
yea what he said
https://pastebin.com/1LMJJ8sQ [SQLITE_ERROR] SQL error or missing database (near "VALUE": syntax error). someone any clue why sql errors and mysql not ?:)
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.
@eternal oxide I havent' added the update inventory thing yet, but it won't work now if i put 2 different item stacks in there, would update inventory solve this?
No idea
i thot that that was what the continue statment did
that u had me delete
bc then it would keep looking
omg this thing is so touchy!
now its not wroking
no, continue tells the loop to skip this iteration
Every SQL version has slightly different syntax
Because yay
Brr need to find way to get MySQL and sql compatible with same code :p
inv update didn't work either 😦
show code again
I think people generally abstract sql code for this reason
https://paste.md-5.net/omitugoyeg.java There's nothing special i have to delcair in main for this right? decided to inclued eitire class
for this paste
If the player sees teh debug its running
you can remove the updateInventory() its not in a good spot anyway
Do you mean its only returning the first slot?
if i do this with the item, it doesn't work but after i use a different slot it makes it a 50/50 chance to work
idk
but it's that first slot that's the problem
odd, try player.getInventory().addItem(itemStack.clone());
ok, but i think it's not getting the itme from the first slot of the crafting table inventoruy
ill try that
tho
Would you recommend abstract? I'm not yet that familiar with that. Could just use Boolean and skip MySQL code and do sql code
🤷🏻♂️if it works
@eternal oxide Still doesn't work for that stupid first slot
ok
Currently, I'm trying to make a fireball with a head. The problem is that it is on fire. is there any way to make it not on fire?
Did you try the snowball method I suggested
snowball wont work as you cant change item
No
@young knoll my crafting table code is being wierd, it isn't working for only the first slot of the crafting table
any ideas?
k
ok
Thanks for all ur help
oh, then that wont work
its way too small\
are there any other methods/
taht's what she said
So you want a big fireball
This code works perfectly https://paste.md-5.net/likajayire.cs
Probably nothing you can do
not even any janky stuff?
If the fireball is forcibly rendered with fire by the client, probably not
actually I have blocks duplicating. sec
i think its every tick its rendered with fire
k only difference is that u used HumanEntity
ah I'm gettign the items back from the inventory and gettign teh one from code, as my craftign table is a real one
I mean you can try setting the fire ticks to 0 every tick
yea
Not exactly the most elegant solution
i am using an open inventory thing
bc i can't use a real crafting table
Well, from a real inventory it works perfectly
what’s your problem?
Show how you are creating your workbench instance
@eternal oxide Here is code for crafting table https://paste.md-5.net/cogitekaju.java
what’s the problem
ah your reference is probably going stale as its scope is lost once the command exits
sec and I'll test
k
Inventory close listener to return all items to the players inventory misses items
yep, works here. its yoru scope
your gui is defined inside your command event, its reference is lost once the command exits. you need a field outside yoru method to hold your reference
So when the reference is lost events behave weirdly?
Because I normally only define them in local scope
this is what I just did https://paste.md-5.net/daxageqato.cs
ok
how do i setup nms
Dont. Avoid it at almost all costs.
well there really isnt any other solution for what im doing currently
What are you trying to do`?
It seems the server lost the reference to the crafting inventory as soon as the command finished, but the client still had it open. It was hit and miss if the server coudl still find its contents when it closed on teh client.
Huh, weird
very
Never encountered that, but I normally only use click events
or the opposite