#help-development
1 messages · Page 2159 of 1
RecipeChoice.ExactChoice
is what makes custom items fully functional
cause it checks for nbt values matching
There have been changes to Furnace/recipe over time but The only thing I know you can;t do through recipes is require x amount of an item
btw the dust pile are emeralds
yea but thats not a vanilla concept anyway
to require > 1 quantity in a matrix slot
private final Map<String, Integer> npcDialogues = new HashMap<>();
public Map<String, Integer> getNpcDialogues() {
return this.npcDialogues;
}``` i have this map in a playerdata accessing class, but whenever i try to use the following method, i get this error message
```[20:12:00 ERROR]: Could not pass event PlayerInteractEntityEvent to PlexPvP v${version}
java.lang.NullPointerException: Cannot invoke "java.util.Map.getOrDefault(Object, Object)" because the return value of "net.plexpvp.core.data.instanceTargets.PlayerData.getNpcDialogues()" is null
at net.plexpvp.core.npc.NpcListener.onNpcClick(NpcListener.java:38) ~[PlexPvP-1.0-SNAPSHOT.jar:?]```
impossible, unless you are doing some crazy ass reflection or something
¯_(ツ)_/¯
or you are trying to use it in a static code block... possibly
Hello anyone know why the targetEntity isn't teleporting?
the code runs, as the printlns have run, except the entity doesnt get teleported
targetEntity will not exist in the world until the next tick.
how to set player balance with vault api?
right, but the code ran more than once
with the teleport message working
apply the meta back on the item
how are you calling the method?
I get an error when casting it do "Damagable"
so it ran all of that in under a tick? ok
var dialogueProgress = playerData.getNpcDialogues().getOrDefault(clicked.getName(), 0);
Yes, each pass of code runs in a single tick
Using 1.8.8 API
Sorry I don;t do 1.8
if you’re on 1.8 i believe you can just do .setDurability or setDamage
well
i don’t really have a clue how you’re getting that error
If I set the durability to 381 on a bow, it gives the null texture
is the bow unbreakable
Yes, but if the entity isn't actually in the world yet it can;t be teleported
my playerinteractentityevents aren't firing when i right click an invisible armorstand how do i solve this
why is it conventional to use getters and setters instead of just editing values directly?
armor stands have their own events
means can set the vanilla recipes to explicit vanilla item only
specifically for right click ⸮⸮⸮
wowowo
what are they under
i'm not trying to equip it with anything
this was after doing a 5 tick later bukkitrunnable
it's set as marker and everything
does this fire even if i'm not equipping anything
right click with fist
any help on how i can get a Recipe instances namespacedkey?
not sure
if i have a Recipe instance*
Then it shoudl be teleported
server crash sounds more like you are getting stuck in a loop
yeah that loop is in the code
its a 'server stopped from 10 seconds'
Then your code is never exiting and locking up the server
link it again
Bukkit.removeRecipe(new NamespacedKey("minecraft", "emerald_block")); found, any help on how to get a "plugin" instance to the vanilla minecraft namespace?
while (!targetEntity.getNearbyEntities(0.5D, 0.5D, 0.5D).contains(z)) {
//
continue;
}
this is where it's getting stuck, but it should not be getting stuck as the target should be teleporting
so idk
oh of course it is
basically, the target doesnt move, making the zombie not move either and then the server is stuck in a loop
its entering that loop and never exiting
nothing on the server can change while its in that while loop
but its while condition tho
oh
why doesnt the getnearbyentities work as a condition
it does, but its still in yoru code every time it repeats
nothing on the server has changed
its a single Thread
while in yoru code, no other code is running
oh
so uh
how do i do that
while the zombie isnt close enough from the target, just wait
waiting isnt a very good thing in code but thats what i need rn
you use a repeating task to check
right ok so just a runnable
yep
or threads
im legit stupid ok thanks
so in the repeating task its just delay 0L and interval 1L, check for nearby entities and when the condition is true i can just cancel();
right
unless you grew up with single core Processors its easy to be confused with Threads
Hi its possible to register a codec for mongo?
Because im getting exception when having saving my custom data
Its telling me that ClaimType no tiene un codec
read the reply to that thread about creating codecs
It sounds like you are trying to save an object that mongo doesn;t not know how to handle
@EventHandler
public void onDiamondBreak(BlockBreakEvent event) {
Block blockBroken = event.getBlock();
if (blockBroken.getType() != Material.DIAMOND_ORE || blockBroken.getType() != Material.DEEPSLATE_DIAMOND_ORE) {
Bukkit.getLogger().info("Broke a non-diamond block!");
return;
}
Bukkit.getLogger().info("Diamond Ore broken!");
}
I am fairly certain that Diamond Ore broken! should be getting logged in the console but it does not
how do i make these safe
so PlayerArmorStandManipulateEvent doesn't trigger when u aren't changing its armor
so how do i check when player right click invisible marker armorstand
why arent you just using EntityInteractEvent
because it doesn't work
w8
interesting
how can i make invisible immovable immortal armorstand
without it being marker
:v
nbt
just a non-marker and make it invulnearable ?
does invulnerable make it resistant to pistons also
that if check will pass on everything
yeah you dont even need nbt, there should be methods for invisible, immortal, and gravity
You will never see diamond ore broken
dunno if no gravity prevents piston movements
oh wait yeah
Yeah, but its an enum so hmn
how can i check if a entity/item contains persistentdata without triggering npe if it doesn't?
i dont wanna flood console with try/except messages either
since it could come up negative a lot
null check it
get(NamespacedKey, INTEGER) returns an Integer
not an int
you are auto unboxing it
which may lead to a null pointer
getString(heldItem, new NamespacedKey(PlexPvP.get(), "fishing_rod")) == null
i think the problem is i'm comparing what was returned from the method instead of comparing before returning
returns the persistentdata in the form of a string
supplied with an item/entity and a key
the PersistentDataType.STRING would work fine here
your issue is just auto unboxing
public static String getString(Entity entity, NamespacedKey key) {
return entity.getPersistentDataContainer().get(key, PersistentDataType.STRING);
}```
yea that works tho
nothing there will break yet
if the returned value is null
your issue is with your integer implementation
well i havent used the integer one yet
so the npe isnt coming from there
i'll fix it in advance tho
what NPE are you getting
java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.meta.ItemMeta.getPersistentDataContainer()" because the return value of "org.bukkit.inventory.ItemStack.getItemMeta()" is null
at net.plexpvp.core.util.PersistentData.getString(PersistentData.java:23) ~[PlexPvP-1.0-SNAPSHOT.jar:?]
at net.plexpvp.core.npc.FishermanNPC.open(FishermanNPC.java:25) ~[PlexPvP-1.0-SNAPSHOT.jar:?]
at net.plexpvp.core.npc.NpcListener.onNpcClick(NpcListener.java:48) ~[PlexPvP-1.0-SNAPSHOT.jar:?]```
well that was not the method you linked then
that just fails because you supply an item without item meta
like air
this is my condition tho
if (heldItem.getType() != Material.AIR || getString(heldItem, new NamespacedKey(PlexPvP.get(), "fishing_rod")) == null) {
oh wait
...
lol
but im tryna do like if the player is holding air or an item that doesn't contain the required data
would i just slap some parenthesis in the second one
so there's no immovable flag for armorstands
marker is the only way
how can i do a raycast
NoAI?
i will try that now but i thought armorstands dind't have ai
well they cant move, but AI also includes being pushed by a piston and whatnot
oh nvmd
noai mobs can still get pushed
uhhh
what if you just tried some good ol' packets
yea it still moves
this is like my first plugin
i don't know what NMS is or what packets are
i see all this stuff being thrown around
i had to get someone to help me with a dependency today
i haven't worked with maven before
you could try a marker armorstand and the actual one riding it 🤔
passengers should not be pushed
:V 🧠
how do i do
spawn armorstand then can i do like
.setRider?
is that a thing?
passenger wouldnt be aligned with the armorstand though
would end up above or below it
a little above
it is a marker
that should be rendered basically at the same height
there's a way to interact with armorstand packets
mate if they just started
ik so because i have a packet hologram leaderboard thing on my server that's rotatable
packets will not work
have any of yall messed with TAB's weird custom event system before? Waiting on TABs support but might as well ask here.
is tab supposed to be an acronym for something other than the playerlist ingame?
its the actual plugin name lmao
oh
so i could put an armorstand with a helmet on, make it a marker, but then make some invisible noai mob ride it, and i check for right clicks on that mob
how far up do passenger mobs sit
nonono i've already made a resource pack with the item displaying on an armorstands head
how can I make structures registered in the structuremanager persist through restarts? do I have to save the files myself?
yes
The structure manager does not even save vanilla ones by default
you have to save them in the structure block and actively load them back in
Why happen that mongo erro? If im saving an enum refence, which is a java object It extrange
does the yes mean i need to save files somewhere and then load them?
or that you can make them persist
The StructureManager has a saveStructure method
is .setMetaData just a way of storing miscellanious info inside a mob
like could i make my own flag and set it to true for a zombie
Won't u use persistent data container?
wot
To set data for entities
declaration: package: org.bukkit.persistence, interface: PersistentDataContainer
Yes
You do Entity#getPersistentDataContainer
?jd
And you cna look at the link to see the methods of the pdc
?pdc
var item = new ItemBuilder(Material.FISHING_ROD)
.name(localize(player, "item.fishing.rod.name", playerResolver))
.lore(localizeList(player, "item.fishing.rod.lore"))
.build();
setString(item, new NamespacedKey(PlexPvP.get(), "fishing_rod"), "true");
player.getInventory().addItem(item);``` would anyone know why the persistent data isnt actually being applied to the fishing rod that's given to the player?
public static void setString(ItemStack item, NamespacedKey key, String value) {
item.getItemMeta().getPersistentDataContainer().set(key, PersistentDataType.STRING, value);
}```
i guess we need to see the impl for the ItemBuilder class tho
item meta is a clone
ah nvm
wdym by clone
it clones itself
mutating it does nothing unless you feed the instance back
using setItemMeta
apply the meta back on teh item, after you set it
the meta being the persistent data?
ItemMeta you get from getItemMeta()
its pdc is hence obviously also the clone
and then set it back
no
you need to store it
getItemMeta returns a new instance
calling it again just creates another new instance
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
what's the difference
one cann be picked up iirc
first one ye
Player inventory is unaffected. What am I doing wrong here?
I don't think you need to update the inventory
doesn't do anything with or without that line
then make sure the code is even running
Is there a packet im not seeing that is sent when a player gets a new item? (Not pickup)
it is. Injecting a getAmount before reducing the count by 1 shows the correct amount in the logs, then 0 after the setItem method call
I've no idea what you mean by 0
here's the actual setup of my code, updateInventory commented out for now
and here's the debug output
item stack (11 carrots) is not decremented. The event is clearly firing twice (!?) and bailing out on the first run, when it shows the correct amount
ok, line 61, you are returning before you reduce the amount if its a golden carrot
the other 0 is the offhand trigger
both 0
that's it. its supposed to be a !=
getItem() returns a mirror iirc btw
So you shouldn’t have to setItem()
Of course you can do it for the sake of clarity, and I might even be wrong ;p
how would I go about changing the type of a material of a placed block in 1.8? so for example, oak stairs to birch stairs. Everything in MaterialData to do with changing the typeid seems to be deprecated
did you look why its depricated?
1.8 is so old it could just be depricated because of 1.9
if your using 1.8 don't even worry about deprication the API is so old do you really expect for it to be updated anyways
I'd like to make a plugin to let players maintain individual builds in a world separate from the overworld - new to spigot API and have been reading docs, seen methods for loading chunks from a created world, but is there general information somewhere about what specifically it means to load chunks? Want to make sure I handle loading/unloading properly
how can i listen for the ChunkLoadEvent of the default world
Check if the loaded chunk is in the defualt world
when the world is firstly loaded, spigot already loads the chunks before my plugin even loads
basically, im deserializing a location from a config and it is giving me "unknown world" if i set load: STARTUP
and also i want to listen to every chunk load event to do something
Can't u just get all the loaded chunks after startup
Like onEnable
And do whatever u want?
tryna add a new object to a json config. which one of these do i put in place for a map?
Think it is a jsonobject
alr
are you using vscode?
yes
hideous
intelliJ all the way
I'm trying to create this runnable, but for some reason its not running at all. the debug messages "pre worked" and "zipline has been created" is sent, but nothing in the runnable. no stacktraces as well, anyone knows why?
BukkitRunnable is deprecated, you should use Bukkit#getScheduler()#scheduleSyncRepeatingTask()
ah thanks, i'll look into it!
np
has anyone here used anvilgui
this one
I have this code in a PlayerInteractEntityEvent listener:
AnvilGUI gui = new AnvilGUI.Builder()
.title("Does this work")
.open(event.getPlayer());
This is the error when the event happens:
https://pastebin.com/zjWyyH3L
it's supposed to render an anvil gui
i've tried running .plugin(this.plugin) on it and that didn't help either
hello, who can help me with doing rectangular world border?
I have replaced it with one, and nothing is running still... any ideas?
debug outside of the for loop inside of your task to make sure it's running
oh god why didnt i think of that, let me try that 🤦
yep thats it... thanks LMAO
dammit 3 hours of sleep really isn't enough
I hear ya, I regret working last night when tired
np, gl
So say I have another Java program, (Discord Bot) is it possible to use Spigot API as a Listener and get server information, I keep reading that it has to be a plugin
Any help would be appreciated
@humble tulip
?
oh i didn't reply
e
i have the pastebin for ithere
and explanation
You can make a plugin that also acts as a discord bot
Or a plugin that communicates with a discord bot
You can't easily make a program that runs separately from the server and still interfaces with it otherwise though
I was seeing that first option, Idk why I could not find that answer before.
I would prefer the 2nd option myself, I am going to look into that route.
It's far more painful
yeah^
Oh rip
and what kinda data u wanna send back and forth?
Mostly, auto whitelisting, would be neat to have chat synced up but not required.
honestly the first option is the best
but you can use sockets
make the discord bot the server and all the mc servers clients
When i try detecting a player removing an item from a armor slot InventoryClickEvent doesn't fire, is there a different Event i can call that focuses to the main Player's Inventory? (using spigot 1.18.2)
Thanks for the help.
are u using the numbers on your keyboard for a hotbar swap?
just a regular click?
yep
public void onBannerRemoved(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
final ItemStack clickedItem = e.getCurrentItem();
if (clickedItem == null || clickedItem.getType().isAir()) return;
String playerGroup = getGroup(p); // group would be like Plains
String getKing = getKing(playerGroup); // My IGN
String playerName = p.getDisplayName(); // My IGN again
boolean isPlayerAKing = playerName.equals(getKing); // A Workaround for checking due to it skipping over it
p.sendMessage(isPlayerAKing + "");
if (!isPlayerAKing) return;
if(e.getSlotType() == InventoryType.SlotType.ARMOR) {
p.sendMessage("Slot Is In Armor");
if(e.getCursor().getType() == getKingBanner(playerGroup)) {
p.sendMessage("Item Is Banner");
e.setCancelled(true);
}
}
}```
trying to detect when a player tries to remove a banner from their head doesn't register it which is pretty odd, been looking around for 2 hours now and haven't really found a way around it
have you put any debug statements at the top to make sure the event is fired?
i have which was this:
p.sendMessage(isPlayerAKing + "");```
which would return true or false and it would only detect it in Inventories that were Chests but not the normal player inventory
is there a way to execute a vanilla command from code
probably Bukkit.getConsoleSender and run the command using that?
or if there is a way to make a listener detect whether a player right clicks an item such as a special stick, and to obtain the location of the player and the direction the player is facing?
yes there is
i want to try this method first
ive never dealt with right clicking any item, cuold u point me in the right direction?
playerinteractevent
it does call the event
i just tested that it does
something you're doing is wrong
this is my item btw
would i have to copy past this into the listener to check fo the item?
why is that a static method
no
save an instance of the stick in your listener class
tbh its not too hard to do, all i did was make the bot in a class called DiscordStuff which extends the ListenerAdapter and an variable JDA jda; then made an public DiscordStuff(Main main) { startBot(); this.jda.addEventListener(this); }
so then the Main plugin class can run the bot then a function to start the Bot so it will actually be active
try {
this.jda = JDABuilder.createDefault(this.token).build();
} catch (LoginException e) {
e.printStackTrace();
}
}```
afterwards i did whatever i needed to do in that class, if you wanted to make listeners to PlayerJoinEvent or anything then implement Listener to the class add a `public MainClass plugin;` then in the DiscordStuff(MainClass main) add in `plugin = main;` and a `plugin.getServer().getPluginManager().registerEvents(this, (Plugin)this.plugin);` to register the events to actually work.
and check if ItemStack#isSimilar(ItemStack)
if the itemstack is the same in all aspects but the amount
ah
if u wanna compare amount use the equals method
i think isSimilar seems fine for this purpose
then in the main plugin class i just extended JavaPlugin and made an onEnable this called new DiscordStuff(this); which made it so the bot was being hosted on the server itself and still received data
make sure you call jda methods on a separate thread cuz it can lag your server
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
wiki for me?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
this for u
ok ty
yes it's right but if you need to ask if that's right, you need to look around a bit more
Thank you for that response, but the problem is I want the Discord Bot to work alone without the Minecraft Server, simply because we don't always run it, since we do play multiple games that need a server.
supersand then sockets are your way to go
i know a janky way for it
cant find more detailed stuff on event api
if you would like to know it
Yeah I was looking into sockets
sure I'm down for suggestions
I'm mostly in the research phase rn.
@modest shard https://www.spigotmc.org/wiki/using-the-event-api/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
im on that page
what more detailed stuff do u want?
it doesnt have anything on more specific events
?jd
liek how to get info form the evnts
💀 i better get searching
alright so have 2 discord bots, 1 in the plugin, 1 for the main. now have a discord server that both bots will be in that will communicate data between each of them and just have checks if a message comes in from the other server from that one bot to then do a certain thing with the data included into it
its not the best way to do it, but it works
sockets would be the way to go but if you want an easy way for it then that would be it
I did think of that, but I quickly turned it down.
is there a way to "round" directions a player is facing to strictly NWSE
makes sense
without too much math
Thanks though guys, appreciate the time trying to help me.
hmm
i did it so a javascript bot could communicate with a jda bot
maybe
yes ty to peoples helping me
i think i could do it maybe if i knew how the direction facing stuff works
let me get the interaction thing down first
This turned out to be as simple as changing the world in the player's location. I thought loading extra worlds would be much harder, but I'm pleasantly surprised with how straightforward the API made the whole thing
For all those people who find it more convenient to bother you with their question rather than to Google it for themselves.
fk discord spoils it
You can disable embed previews with <> around the link
buy nitro again then
i won the nitro from a giveawa
lol
how to summon a primed tnt? i alr know how to summon a mob, but is it different for primed tnt
oh its TNTPrimed
is ther smth wrong with this? or is this not how you are supposed to summon tnt
o wait im oncrack
wait no
even after i changed null to TNTPrimed
anyone?
😭
TNTPrimed t = (TNTPrimed) w.spawnEntity(p.getLocation(), EntityType.PRIMED_TNT); ?
TNTPrimed t = (TNTPrimed) w.spawnEntity(p.getLocation(), EntityType.PRIMED_TNT);
shows no errors for me
maybe change it to something else
did i forget to import smth
i only needed to import import org.bukkit.entity.TNTPrimed;
guys i saw a server where they had this chest menu where you could click buttons, but the buttons didn't have the white highlight when you hover over an item
i thought they were using a custom font texture but i'm using a custom font texture rn and the items in the container are rendering on top of the text ·_ .
because it's a development question
people in here have probably made custom guis before
i want to know what technique is used to make that specific gui
pictures pls
i will have 2 find a server with it again
can we access jigsaw block's gui through spigot?
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/Jigsaw.html
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/data/type/Jigsaw.html
declaration: package: org.bukkit.block, interface: Jigsaw
declaration: package: org.bukkit.block.data.type, interface: Jigsaw
is there some way to make an itemstack into a Material that i can add to a recipe
nvm i figured it out
so can i set the info on the gui with setBlockData?
should be able to, BlockData contains the data of said block
but does parameters on that method change depending on different blocks?
cuz data of a chest and a jigsaw is different
not sure, will have to play around with it. Those API methods have inherited methods too
I haven't messed with jigsaws but those are the only API things I managed to find in relation to them
got it ty
not too familiar with itemstack deserialization and serialization, can you serialize to a custom yml manager? Or does it need to spigot fileconfiguration for yml
Itemstack has a serialize and static deserialize method, you can then save them however you want really be it json or yaml
so if i have a section of my custom config that has all the data for the itemstack, it will work?
Did you serialize an itemstack to get that section?
If so you should be able to deserialize it back into an itemstack
Hm, could you first tell me the difference between single keys, configurationsections, and how to use them? Like what do i put in them
not too sure how to serialize to file
Hi I want to implement a stop clock that can be called with a certain command and measures the time it takes a player from one coordinate to another?
How can I do that?
you can try a runnable which runs every second and cancel it when the player has reached the coords or location
there are other ways but thats what came to my mind
not sure what you are asking?
I can't select it as my main class
Due to 2 voids?
Oh
I'm an idiot
I don't need to specify a main class due to it being in the plugin.yml....
I do have one more issue that would help me
I have this
This is my YML
How would I get the chosen player?
like /command exampleaccount
if (args.length > 0)
Player player = Bukkit.getPlayer(args[0]);
if (player != null)
Anyone knows how to get this MariaDBV Source
How are you building your project?
You could add it to the library section of your plugin.yml
Thank you
does FileConfiguration#get return List<Object> for types such as Byte, Float, and Character?
im running into a type-mismatch for those 3 types with it trying to set a fields value with reflections
Do you have a code snippet to show?
wf.trySet(fileConfiguration.get(wf.getPath()));```
`wf` is my "WrappedField" object (https://paste.md-5.net/vexewuxacu.java), `fileConfiguration.get` is the get method in FileConfiguration (duh), and `wf.getPath()` is the path to the key (ie. `getConfig().getByteList("this.is.a.path")`
the 3 types are commented out rn so that it doesnt error out my smp for now
ik reflections is usually a can of worms not worth opening but this seems so simple that i cant grasp what would be going wrong
yo i have a quick question, is spigot like a java library for minecraft or what exactly is spigot?
https://paste.md-5.net/misudinode.java https://paste.md-5.net/ideyavevov.java heres full classes if u want @worn tundra
Spigot is an extension of the Bukkit API (Spigot-API) and also minecraft server software (Spigot-Server)
and what does it extend? it just simplifies working with the api because it has classes for certain elements and stuff?
it adds some stuff, cba to remember what tho
Spigot allows you to customize your servers with plugins
simply put
is there a place where I can find all of this stuff
it has an api which you can program and make plugins to do all sorts of stuff
It is an API for interacting with the Minecraft Server.
the error in (semi-)specific is like arraycopy issue, Object[] can not be casted to Byte[]
with a vanilla minecraft server jar you dont get a plugins folder (i dont think)
i dont think ive ever actually used one
you think there's a c++ version of spigot since it is an API and not part of the actual minecraft server, therefor not having to be java?
There was one I believe, but it was never finished
its an expansion on the java minecraft version
itd have to be a full port of the java edition server methinks
was it glowstone? or some other
perhaps I'm thinking of a full server rewrite
u mod something in the language its coded in
unless they have an inbuilt modding thing
being the same language is not a requirement of an api/mod
right that makes sense
u dont necessarily have to, its just easier
ppl have made plenty of injectable mods made in C++
I'm wondering how I should implement special abilities for my kits. I was thinking an enum for allowed events such as EventType.DEATH or EventType.KILL, a description which will be displayed and a consumer that takes player so I can actually implement the effect.
@RequiredArgsConstructor
class KitAbility implements Listener {
@Getter private final EventType calledOn;
@Getter private final String description;
private final Consumer<Player> effect;
@EventHandler
public void event() { // this is the problem
}
}
How do I map these enums to certain event classes so I can register them using something like.
@EventHandler
public void event(Event e) {
if (!(e instance of calledOn.getEvent().class event) return
}
Or
public void event(calledOn.getEvent().class event) {
effect.accept(event.getPlayer);
}
If not, is there a better way?
you could make your own event that has a field which is the enum
instead of creating different events
What? I don't quite understand, I was thinking EventType would be something like
@RequiredArgsConstructor
enum EventType {
DEATH(PlayerDeathEvent.class),
KILL(PlayerDeathEvent.class)
@Getter private final Class<E extends EntityEvent> event;
}
so how would you listen to that?
I don't know, that's why I am here
enums dont really work like that
i suggest you make your own event/method that runs on the PlayerDeathEvent
explain what ur trying to do again?
Special abilities for kits
You kill some effect takes place, you die some effect takes place and so on
ah
in your player death
even t
make a method that makes your effect once a certain condition is reached
something like
public void runEffect(EffectType type){
if (type == ..) {
//do so and so
}
}
run this on your player death event
Kits will have different effects and these effects could be triggered on different events
Or the same one
run this same method whenever you need to
sorry for this haphazard explanation im playing a video game rn i just didnt want to leave u hanging
Hello, I just discovered that since 1.17 API and NMS have been changed but I don't understand something
I imported the spigot remapped etc but why netty is not in?
How can I get it?
new BukkitRunnable(){
public void run(){
if(!giant.isDead()){
if(giant.getTarget() == null){
for(Entity entity : giant.getNearbyEntities(10, 10,10));
if(entity instanceof Player){
Player player = (Player) entity;
giant.setTarget(player);
}
}
}```
I keep getting this error "Cannot resolve symbol 'entity'
how 2 fix dis?
its not in the loop
How can I make my Time.System.Millis stop when a player reached certain coordinates ( a certain tile)?
Yeah but how can I store that millis time
set it to a variable
Of course I know
But is it like (if player.getLocation() == new Location(1, -60, 1) { time = ...
??
You have a ; after your for loop instead of a {
theres also not enough }
your opening too much and not closing them
unless ur leaving out some code at the bottom
?paste
yeah change the ; after your for into a {
and then add another } after the end of the if
which line?
41
is dis correct?
also will the auto spawn thing work
@EventHandler
public void onSpawn(EntitySpawnEvent event){
if (!(event.getEntity() instanceof Animals))
return;
if (!(event.getLocation().getBlock().isLiquid()))
return;
if ((int) (Math.random() * 10) == 1) {
event.setCancelled(true);
Bukkit.broadcastMessage("" + event.getLocation());
}
}
}```
and why do I keep thinking that ur pfp is that linus tech tips guy
ty
I want to store the timemillis in a variable if a player has reached the end of an maze. This exit can be defined with its coordinates so i try to use them
yea that should work then
Ok but somehow my if condition isnt working ingame
If I want to store timemillis when he reached for example the coordinates (1.0, -60, 1.0)
How would my If statement look like
make sure to use getBlockX
because that uses whole numbers
getX is a double
its like
5.3334
if ur in the middle
just use Location#getBlock and compare
if (p.getLocation() == new Location(p.getWorld(), 1.0, -60.0, 10.0))
if(player.getLocation().getBlock().equals(new Location(x,y,z).getBlock())
use blocks
because the player's location uses a double as coordinates so it will never be equal to your target
1.5, 1.5, 1.5 is not the same as 1,1,1 even if you're standing on top of the same block
Could I use generics instead?
@RequiredArgsConstructor
class Ability<E extends EntityEvent> implements Listener {
@Getter private final String name, description;
private final Consumer<Player> effect;
@EventHandler
public void event(E event) {
if(!(event.getEntity() instanceof Player player)) return;
effect.accept(player);
}
}
One problem, if in my abstract kit class I put
private Ability<EntityEvent> special;
And in a derived class I put
special = new Ability<PlayerDeathEvent> ("", "",...);
Would the event register PlayerDeathEvent or EntityEvent?
Well that's a shame
you can just do private Ability<? extends EntityEvent> special;
Oh, I forgot about that one. Thanks
Still somehow isnt working
If the block I stand on has the y coordinate -61
my location is still -60 right?
don't compare teh block under you
I didnt do that
`
if (p.getLocation().getBlock() == new Location(p.getWorld(), 1.0, -60.0, 10.0).getBlock())
== "should" work as there is only ever a single instance of each Block, but equals() is teh correct method to use
Still isnt working ( is there something wrong in my code)?
`
long timeMillis_start = System.currentTimeMillis();
if (p.getLocation().getBlock().equals(new Location(p.getWorld(), 1.0, -60.0, 10.0).getBlock())) {
long timeMillis_end = System.currentTimeMillis();
long timeSeconds = TimeUnit.MILLISECONDS.toSeconds(timeMillis_end-timeMillis_start);
p.sendMessage("Time: " + timeSeconds);
}
`
You're comparing a block with a location
Ok so what to do
So what des that mean for the code
that should be working
Ah wait
// whether effect should take place on killer
// only applies to PlayerDeathEvent
private final boolean killer;
@EventHandler
public void event(E event) { // wack
if(!(event instanceof Player player)) return;
if(event instanceof PlayerDeathEvent) {
player = killer ? player.getKiller() : player;
}
effect.accept(player);
}
A jank fix to target victim or attacker in PlayerDeathEvent
It should be working or not?
What do I have to do
`
public class TimeKeeperCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
if (sender instanceof Player) {
Player p = (Player) sender;
p.sendMessage(ChatColor.GREEN + "Time started! Go! Go! Go!");
long timeMillis_start = System.currentTimeMillis();
if ((p.getLocation().getBlock()).equals(new Location(p.getWorld(), 1.0, -60.0, 10.0).getBlock())) {
long timeMillis_end = System.currentTimeMillis();
long timeSeconds = TimeUnit.MILLISECONDS.toSeconds(timeMillis_end-timeMillis_start);
p.sendMessage("Time: " + timeSeconds);
}
}
return true;
}
}
`
Whole code?
Where can I implement the print
before the check
where you check if the blocks are the same
just print the block as a tostringm
p.sendMessage(p.getLocation().getBlock()+"");
p.sendMessage(new Location(p.getWorld(), 1.0, -60.0, 10.0).getBlock()+"");
you might have to individually compare the x,y,z
Don't use Event
Why not?
are you sure the event is firing
The E is specified by the kit, what would be the issue in using it?
i feel sorry for the server's ram
I have a feeling you don;t understand how this will work
the code/command will not wait for you to reach the destination block
Your code will only work if you are stood at teh location when you use the command
You need to use the Scheduler to start a repeating task to listen for the player reaching the destination
hope to get some help about something prob simple but i didnt find much on the internet neither the documentation nor the forums. so
i have a fully functional custom item and id like to now inject it into the namespaced map that the /give command utilizes so i can /give my custom items
and if possible also the map that the creative mode inventory is using
register the recipe and it shoudl appear in all menus
registered the recipe
works fine like ive said yesterday
but its not under gie
give
those are different maps
i suspect itll be somewhat similar to
try
{
Field mapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
mapField.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) mapField.get(Bukkit.getServer());
Field cmdsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
cmdsField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, Command> cmds = (Map<String, Command>) cmdsField.get(commandMap);
Command opCmd = new OpCommand("minecraft:op");
Command deopCmd = new DeopCommand("minecraft:deop");
cmds.replace("minecraft:op", opCmd);
cmds.replace("op", opCmd);
cmds.replace("minecraft:deop", deopCmd);
cmds.replace("deop", deopCmd);
cmdsField.set(commandMap, cmds);
mapField.setAccessible(false);
cmdsField.setAccessible(false);
}
catch (Exception e)
{
e.printStackTrace();
}
```this
Don’t need to use setAccessible(false) after
That will only affect the AccessibleObject instance you invoke it on
good to know though
ive actually wanted to do this
Think he's telling yo u to make your own command
the command was not what ive been asking for
i want to inject custom items into the namespaced map
of the /give command
and hes saying that its redundant to set fields inaccessible
Ya, at least for your purpose
still need help with adding items to the /give list
xD
also trying to set an items max stack size but ive been reading trough the servers source files and apparently its impossible because stack sizes are derrived from materials which use final fields so even if i could do it i would override the vanilla items stack size too
and this is the same in both the bukkit api and nms methods
well it’s not impossible
friend of mine changed the stack size of items just by forking spigot
keep in mind you’ll have to update the players inventory a lot in order for jt to look okay client side
its not a big issue i can either use wooden swords as dummy item or add a PDC uuid value to it to make them non-stacking
problem is rather to keep track of the UUIDs
in an efficient manner
just use random. Odds of having a collision which would allow stacking is near zero
thought about that but near zero aint zero
true
if i start to utilize uuids
i can also implement it in an anti cheat to detect dupes
however then punishing someone who got the near zero chance
is a nono
i just wonder why its so hard to make the stack size a member of the item meta
because its clearly not
its just that no one bothers to update that deprecated system from 12 years ago
?contribute
You can find information about contributing to Spigot at the following links:
https://www.spigotmc.org/wiki/cla/
https://www.spigotmc.org/wiki/guide-contributing-to-spigot/
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/README.md
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/CONTRIBUTING.md
haha u serious?
even IF i was to write that system
chances are going near zero that its even being considered i believe
xD
Yep
yep serious or yep near zero
near zero
then im not gonna bother with a contribution
my time is too valuable to go to waste
even tho some might argue about that here xD
I mean it will not get accepted anyway
The server would have to actively maintain the non vanilla item stack limit as the client doesn’t allow their modifications
yea nah its cool its just gonna be anoying cause i have to write a couple of system
to utilize wooden swords as dummy objects
without breaking vanilla mechanics
like when ive found that the api does support crafting with custom items and not only materials it solved so much work, even though everyone here said recipes take materials only which is wrong
Everyone?
anyways back to the roots to find a solution to inject custom items into the give command map first
well yes, ive asked many times and ppl told me i must manage custom recipes at runtime
but thats not true u can wrap itemstacks like this
I mean the api supports custom items
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "recipe_diamond_dust"), item.getItemStack());
recipe.shape("AAA", "AAA", "AAA");
recipe.setIngredient('A', new RecipeChoice.ExactChoice(new ItemStack(Material.COAL_BLOCK)));
Bukkit.addRecipe(recipe);
Yes exactly
thats what ive found when diving trough the servers source files
no one ever told me about that existing
Ugh weird, I guess you shouldn’t listen to everyone here btw
Then you must have been pretty unlucky with the support here xd
yea because it priotizes the vanilla item
Because that exact choice api has existed for quite some time now
well ive found it on my own by chance looking for something else trough the decompiled bukkit api
and then seeing exact choices being like
wait.. thats a thing?
xD
It was probably a generic reply from people as most enquiries along those lines are related to multiple items (stack sizes) in crafting
my custom items derrive from emeralds
so what ive done to set the vanilla recipe explicit
//Emerald Block Vanilla Override
Bukkit.removeRecipe(new NamespacedKey("minecraft", "emerald_block"));
ShapedRecipe recipe_emerald_block = new ShapedRecipe(new NamespacedKey("minecraft", "emerald_block"), new ItemStack(Material.EMERALD_BLOCK, 1));
recipe_emerald_block.shape("EEE", "EEE", "EEE");
recipe_emerald_block.setIngredient('E', new RecipeChoice.ExactChoice(new ItemStack(Material.EMERALD)));
Bukkit.addRecipe(recipe_emerald_block);
works totally fine
now no custom items can be used for the vanilla recipe
only thing is renamed emeralds cant be used either but tbh, not my problem xD
i mean whos renaming emeralds
so can i get some non generic help for this? because idk what the fields are called
😛
No clue. I've never played with the give command
How would I add special abilities into my kits? I tried making a class which would accept a consumer but two events of the same type cannot exist so that was a flop
does anyone have any resources as to where i could learn the minecraft and spigot api?
Do you know Java?
Yes, i learned java, I'd also like to know where i could find the terms accociated with some of the actions
let me refraise that
you know like if you were to say "passing an instance"
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
thanks, but what i'm looking for is a dictionary or something of the sort that tells you what stuff like that means, (i know dependency injection)
i know java, i just need to know the fancy words and stuff so i can actually be helped here
Di is literally passing an instance/reference
i know
It's called Google
I doubt there is a dictionary like that. Make mistakes, people will correct you and you learn
People love to correct mistakes 🙂
I could make an abstract function such as onKill() onDeath() but I think it'd be cleaner to have a class that stores the name and description of its ability
@EventHandler
public void onInteract(PlayerInteractEvent e) {
Block block = e.getClickedBlock();
BlockState state = block.getState();
if(state instanceof TileState) {
e.getPlayer().sendMessage("b");
if(((TileState) state).getPersistentDataContainer().has(Keys.ironConverterKey, PersistentDataType.STRING)) {
e.getPlayer().sendMessage("a");
}
}
}
```Hello, I'm checking if a block has specified persistent data type but it always returns false.
But actually block has a PersistentDataType
public class IronConverter {
private static ItemStack ironConverter = new ItemStack(Material.CHEST);
public static ItemStack setupIronConverter(String a, String text) {
ItemMeta meta = ironConverter.getItemMeta();
PersistentDataContainer ironConverterContainer = meta.getPersistentDataContainer();
ironConverterContainer.set(Keys.ironConverterKey, PersistentDataType.STRING, a);
meta.setDisplayName(text);
ironConverter.setItemMeta(meta);
return ironConverter;
}
}
I mean how do you set the value
Item PDCs are not auto copied to block pdcs when placed
So i need to add it on blockplace?
Yes
how do i check for when the server stops
onDisable?
yeah but it doesn't let me execute stuff
Oh but it does
It definitely let's you execute stuff
What kind of abilities?
When someone kills a person, they get strength and such
Well u can add methods to your kit class
Like onDie
OnAplly
That take a player
And call those methods from a listener
Are the kits configurable or are they coded in?
Yeah I know, but the specials will have a name and description to display
They are coded.
Why is this a problem?
Should I create a seperate data class that stores that data?
Create an abilitykit interface with those methods
Simple data class should work yea make sure you have an interface for easy storage
How would interface make it easier for storage?
I'm confused
He's asking how using an interface would make the data easier to store lmao
What data do u need to store about kit description?
You wanna make it configurable?
I have a Custom kit abstract class that the kits derive from
Returns a clone i beleive
You could makw the kit store the ability
Yes... But what do u need to store the ability name for?
Eh who knows maybe guis and such
I always like to store String names for ease of access for that type of stuff
To display them in the shop and selector.
Ah well then use a config file
Does anyone know how to have netty in spigot 1.18?
Those are GUIs
@Data
class KitAbility {
private final String name, description;
}
abstract class CustomKit {
private KitAbility ability = new KitAbility("NONE", "No special");
public void onDeath(Player player) {
}
public void onKill(Player player) {
}
}
I still don't understand why KitAbility being an interface would help
I'm setting it but it still not entering
Heya guys does anyone have any idea on how to prevent the player from moving an item when he is in creative mode?
@EventHandler
public void onBlockPlace (BlockPlaceEvent e) {
Block block = e.getBlockPlaced();
Player p = e.getPlayer();
if(block.getState() instanceof TileState) {
p.sendMessage("tilestate");
if(block.getType() == Material.CHEST){
p.sendMessage("CHEST");
if(p.getInventory().getItemInMainHand().isSimilar(IronConverter.getIronConverter())) {
p.sendMessage("getmethodu");
((TileState) block.getState()).getPersistentDataContainer().set(Keys.ironConverterKey, PersistentDataType.STRING, "ironconverter");
block.getState().update();
}
}
}
}
Is this right? @humble tulip @river oracle
states are snapshots @kindred valley
similar to ItemMeta
you need to store the result of getState
?paste
(found the mistake) Why is my join message still there? https://paste.md-5.net/sovetegiya.java (found the mistake)
what is that error: Error occurred while enabling BowSpleef v1.0-SNAPSHOT (Is it up to date?) java.lang.IllegalArgumentException: Plugin already initialized!?
Your plugin is already initialized => You have it twice
Do you use the same name for the main class of different plugins? That might also cause this issue. Although I'm not entirely sure about that
does it mean if I have two plugins with the same name?
?paste
nope
maybe
https://paste.md-5.net/zizokeragi.java like this?
im not 100% sure
i do not have any plugin with the same name
i had the error months ago because i copied a plugin and just changed the code. Maybe thats your case
i got the mistake
Make sure you're not creating a new instance of your main class
your main source is the same in the other
Then what?
Do all kitd have abilities?
no
No
yes
you call update on the variable
i fixed
wat
yes i get it
oh
i changed the name for main class
oh yea the code you linked was wrong
Well make an AbilityKit abstract class that extends kit
glad you fixed it yourself
and it still doesn't work
And add the methods specific to abilities there
Could you tell me why an interface would be better here?
I didn't say interface for data storage
can you tell me whats your Main source is? like net.example.test.Main
I'm just talking about kits
me.xsenny.bowspleef.Main
How can i add 1 in config if player jumps once?
and in the other plugins you have not this?
nope
mmh
i will try to delete all plugins
CustomKit has a constructor.
oh, wait
CustomKit has a constructor
your JoinCommand is the culprit
it is calling new Main() somewhere
in its constructor to be precise
agree
@restive tangle ??????
I'm confused as to what u want
Jjst extend kit and call it abilitykit
Add some abstract methods such as getAbilityName
And applyAbility
Or whatever
Hi, how can I break out of an Repeating Task with Scheduler if my if statement has occured?
You can cancel it if you have a reference to its bukkit task
What does that mean
the runTaskTimer method has an overload that takes a consumer
public void onDisable() {
EmbedBuilder builder2 = new EmbedBuilder()
.setAuthor(
"Server Status"
);
builder2.setDescription("The server stopped! :red_circle:");
builder2.setColor(Color.RED);
if (jda != null) jda.shutdownNow();
if (chatChannel == null) return;
}``` this didn't send anything
@Override moment
e.g.
runTaskTimer(plugin, task -> {
if(somethingBadStopTask) { task.cancel(); return; }
doOtherSTuffHereEveryTickOnMainThread
}, 0, 0)
You should probably override the default method
But who am i
`
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
if ((p.getLocation().getBlock()).equals(new Location(p.getWorld(), 1.0, -60.0, 10.0).getBlock())) {
long timeMillis_end = System.currentTimeMillis();
long timeSeconds = TimeUnit.MILLISECONDS.toSeconds(timeMillis_end-timeMillis_start);
p.sendMessage("Time: " + timeSeconds + "Seconds");
}
}, 0, 5);
`
Who knows
scheduleSyncRepeatingTask is the same as runTaskTimer
Thats my curent code, I am using Schedulesyncrepeatingtask, not tasktimer
just that instead of bukkit runnable you can use a consumer<BukkitTask>
they are passing a runnable
not a bukkit task
there is no this.cancel() in a runnable
oh im sorry
So what would that mean for my code
you replace scheduleSyncRepeatingTask with runTaskTimer
and then () -> with task ->
now you can call task.cancel() inside the lambda
it has a @Override above it if that's what you mean, i just didnt send it

@Override does not matter btw
you should add it
but your method would still override its parent method even without the annotation
Oh
I just use it didn't know you didn't need it
I mean you should