#help-development
1 messages · Page 1660 of 1
if(!(Objects.requireNonNull(e.getCurrentItem()).getType().equals(Material.valueOf(config.getString("gui.sell-item-1"))))) {
if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-2"))))) {
if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-3"))))) {
if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.buy-item-1"))))) {
if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-2"))))) {
if(!(e.getCurrentItem().getType().equals(Material.valueOf(config.getString("gui.sell-item-3"))))) {
e.setCancelled(true);
}
}
}
}
}
}
Is there a way of shortening this?
wtf
Objects.requireNonNull again brrr
have you ever heard of variables?
that doesn't help in this situation
if you stored them into a variable it would look way less terrifying
thats alot of ifs
is a switch possible with own classes?
I don't need to define a variable if i only call it once
Store e.getCurrentItem() as a variable, null check it. Then store getType()
Then its going to stay as messy like that
oh you mean that
And also store config.getString("gui.sell-item-2") and related components as variables
only call those once ^^
then you are left with only type.equals(Material.valueOf(str))
much simpler
and you can use &&
much cleaner
ugh I hate long lines
Do you want if statement hell tho..?
nah
I'll do what u said, ty
np
List<Material> materials = Arrays.asList(Material.valueOf(config.getString("gui.sell-item-1")), Material.valueOf(config.getString("gui.sell-item-2")));
ItemStack item = e.getCurrentItem();
if(item != null && materials.contains(item.getType()))
e.setCancelled(true);
if u format correctly long if statements using && / || aren't that hard to read
You can use Set (and it would be faster), but yea
ImmutableSet.of()
or Set.of() (for later java versions)
Either can be used. Its up to him
But speed
Again though... up to him lol
Isn't calling config methods every time equal to nuking the server?
ah makes sense
It does do a bit of string manipulation before calling map.get
But it’s not that bad
nuke a server with tnt
smh
I just store them at startup or reload anyway to be sure
worse
nuker hacks
spawn a few million tnt
Thats still up to him LMFAO if he doesn't want to make use of more performance based methods he doesn't have to.
Didn't 1.16 change the way TNT works so it only blows up layers at a time or something like that
but why wouldnt you lol. We want to tell people to do it the better way xD
Life will also be much easier when fixing bugs or updating
Jump off this bridge with this parachute it will be faster then walking down the mountain safely.
Its preference
that analogy doesnt make any sense lol
Parachute is quite safe
One way is faster but you both end up at the same spot. just at different times
cough
Alright, thank you very much! Would a vanilla sound name work with the string method?
If you want to use a vanilla sound, you can just use the Sound enum
custom sounds, however, must use String
I think there is Player.isEntityInView(Entity)
You'll have to do some testing, could also be view distance
You could get the vector between the two and then trace along it
NVM can't find an exact method in either entity or player interfaces
is there a difference between Bukkit.getServer and plugin.getServer
No
Use Bukkit.getServer inside static methods
and plugin.getServer for normal use
(the latter is better in terms of OOP if you use it with plugin instance DI)
oki
keep static with static, and oop with oop methods (with the exception of utility methods of course)
but Bukkit.getServer isnt a utility method
Anyone know how to stop end worlds from creating DragonBattle when a player joins the world?
I've tried everything including NMS.
if(e == Environment.THE_END) {
try {
WorldServer ws = ((CraftWorld) w).getHandle();
final Field field = ws.getDimensionManager().getClass().getDeclaredField("createDragonBattle");
field.setAccessible(true);
Field modField = Field.class.getDeclaredField("modifiers");
modField.setAccessible(true);
modField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(ws.getDimensionManager(), false);
ConsoleOutput.debug(ws.getDimensionManager().isCreateDragonBattle()+"");
/*Field prevKilled = ((CraftWorld) w).getHandle().getMinecraftWorld().getDragonBattle().getClass().getDeclaredField("previouslyKilled");
prevKilled.setAccessible(true);
prevKilled.set(((CraftWorld) w).getHandle().getMinecraftWorld().getDragonBattle(), true);
ConsoleOutput.debug(prevKilled.get(((CraftWorld) w).getHandle().getMinecraftWorld().getDragonBattle())+"");*/
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
}
Still allows a portal to be created and displays the boss bar to all players
hm ok well I can’t read the code since I’m on phone
Is it possible to do X:{A: 10, B:{name: "Hello world"}} in NBT data with Persistent Data Container?
Can you not instantly kill the dragon and cancel the PortalCreateEvent?
If I cancel portal create when the someone rejoins the world it just says dragon has not previously been killed in this world
But does it stop the portal being created?
as the portal is only created when the dragon dies
I can porbs do that yeah. But I don't want to have to constantly check and cancel that event
Hello, quick question dose anyone know any good resources for webhooks within Spigot as I'm trying to send a request from my website.
No it creates bedrock when the player joins the world to
The portal is created with worldgen now
yes, it creates the landing pad for the player
Not obsidian... bedrock at y=0
it does? That should not happen
Yes it should
the exit portal only appears when teh dragon dies
Not since the dragon fight rework
ah. I've not fought the dragon since then
best link
😌
ok so My server is under attack constantly by a group called [REDACTED] I have a plan to stop them from joining the server, however my code doesn't seem to work. Basically it's supposed to check their name for a banned word in this case all the clients that join have the name [REDCATED]pw(some random charaters). (the name isn't actually [REDACTED] but to protect anyone else I choose not to say the name)
package me.Teric7.Namekick;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener {
public void onEnable() {
saveDefaultConfig();
Bukkit.getPluginManager().registerEvents(this, (Plugin)this);
}
@EventHandler
public void onLogin(PlayerLoginEvent e) {
boolean containsBanned = false;
for (String s : getConfig().getStringList("banned-words")) {
if (e.getPlayer().getName().toLowerCase().contains(s.toLowerCase()))
containsBanned = true;
}
if (containsBanned)
e.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("kick-msg")));
}
}
damn, what a really intimidating group name
lol
it's not kicking them either that's the issue
What does A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T mean after the anti-check name?
smart
damn chill bro
loll
Why not just use the built in ban system
Hello. Can someone help?
How i can stop a timer within the function ?
I create a timer in the PlayerDropItemEvent and want to stop that timer as soon the item is on the ground or it was picked up or despawned.
But how can i stop the Time within the function ?
Something like that: https://paste.md-5.net/uzetagexas.java
@shadow skiff who r these tho
Ask the developer
Replace the () -> with task -> and then you can do task.cancel
What do you neam with "task" ?
Do you mean new Runnable?
Okay i got it
I have this problem with normal blocks too. Like grass
Can someone help please?
No, I mean the word task
spamming your issue isnt going to make more people want to solve it
Or any name really, it’s a variable
What I have to do then?
Tell me.
Figure it out yourself I guess, we don't know either
the code is also messy because you arent use Adventure properly
and a ton of repetition
so its hard to read
What is Adventure?
Component message = Component.text("§6Möchtest du dich zu deiner Gilde teleportieren?\n");
you are literally using it
and also its the wrong way
do not use color codes like that inside Component
But that's not the point.
The code isn't the problem!
After unloading a chunk and loading it again, the on interact events don't do anything!
not the problem
Is this too hard to understand?
still a problem
Just tell me, why there is this bug?
And how can I solve it?
7smile7 helped to fixed it with a beacon by using tile states, but normal block don't have tile states
Just help, please.
who are you talking to?
do you think people know the answer and are just refusing to tell you?
are you trying to persuade them to tell you the answer?
if someone here knew how to help they would
Not to you.
thats not an answer
jesus
we also aren't obligated to help you or something
take a chill pill
or we dont
we dont get paid?!
What?! I thought!
Volunteer
sheesh im out man
I get paid 20$/hr I spend on a project!
you better be
joking
Discord is a waste of time
type at 2wpm
I made a program to ratelimit my wpm
Good idea
?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.
whats the standard way to do local chat, just hook to asyncplayerchatevent and filter from there ?
I will.
yep
yes
cool
and i'm reading that the event locks the main thread if a plugin triggers the event. If i'm the only plugin on the server and I never trigger a player chat event, the main thread shouldn't ever block right
Its async it won't block the main thread
Are you triggering the event
Will only be sync if you make a player chat, but wouldn't do that using the event
i dont, i just want to make sure theres nothing else if i have no other plugin loaded that could be triggering it
No
Ok so when I join a end world it runs EnderDragonBattle.b() But I can't find in spigots code where this is ran. Any ideas?
Player p = Bukkit.getWorld("BirchForest").getPlayers().get(1);
p.teleport(worldManager.getMVWorld("BirchForest").getSpawnLocation());
}``` anyone know why this isn't kicking me?
doesn't error, just doesn't kick me

nevermind i'm blind 😐
huh
1: indexing starts at 0
2: why would you use a hardcoded index instead of i?
why not just Bukkit.getWorld(...).getPlayers().foreach(player -> player.tp to spawn)
he doesn't know foreach exists
its easier
ofc
the latter is also less code
which isnt always a good thing
when is more code = better
I don't think so because it runs when the player joins the world... you might be right though.
and its more accessible for more people to work on your code
in that case yes
whats the difference between also calling the new int[]?
int[] numArray = {10, 20, 30, 40};
how to make chest look like opened and then close it, i googled but dont found working way, i am on 1.17.1
you might also want to use a regular loop when you want to update local variables. since Stream#forEach() makes their capture final
i was gonna say break early but doesnt java9+ have takewhile
i forget these things
how can i wait in an playdropitemevent until the velocity of the item 0 is?
You can't
The drop item event is cancelable so it fires before teh item is spawned
all you can do is run a timer and watch for it
sooo how would i run a timer like that
not sure about that, given that World.getPlayers() likely returns a clone the foreach variant will perform better than the uncached list access.
what
?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.
No. You may not recieve help.

RIP
What
It is an unspoken rule that existed for millenia that #help-development is NOT for help.
my name isn't help
ask the damn question
Naysayers shall be executed
I can't join non default server jn bungecord
See, you may not recieve help here
?scheduling
thanks
lol
the servers having issues
i cant send a msg for like 2 seconds
same
nah its u
no i tihkn its discor§d
Let's say i've got an event.getItem()
How do I get the stack size of that item.
And not the max stack size of given item, but the actual amount of the item is of the item.
It returns an ItemStack of which you can call the getAmount() method
i have a question
ohh ok thanks
How long did you wait? Do you use a VPN. Are you from china?
i did use vpn
but i turned it off but still no work
How long did you wait?
Try restarting your browser. This usually only happens if your IP is untrusted.
should i try using microsoft edge
How about literally anything else?
But sure. Try another browser.
anybody know why scoreboard team prefixes / suffixes don't show up in chat?
and if there is any way to do so?
Helli
hellicopter
so do you need help still?
He does
Yea
in #help-server
?
It would
It will continue
Why does it take like 2 seconds to send a message :c
Don't name your class Main ;/
You should name it something else. It's not the main class of an application
I recommend naming it the same as your plugin
Well what's inDistance and explodeItem
How are you checking if it's running more than once
Then how you know it's not
I weirdly name the main class of my applications Core over using Main
yeah this happens for me often
just close that specific tab
and open another tab, enter the link then done
guys
how do i create particles at a player line of sight
and get the player object of whoever touches the particles
player.getEyeLocation().getDirection()
gets you a vector
you can loop a location and add that vector over and over to spawn particles
kek
made me giggle
why in the fuck is this 1099p
y not
Hey, I'm looking forward getting any left click from a player client side (not with any event as the server cap it beyond ~10 cps) I guess using protocol lib is the best bet but I couldn't find any packet working as I intend so far (tried USE_ITEM & USE_ENTITY) any ideas ? 🙂
i cnt download any plugin
The cap is in the client
Listening for incoming packets with plib is your best bet.
Nothing you can do unless you force them to use a mod
F
I found an example of a CPS test little plugin, the guy simulated a zombie in front of the player to trigger USE_ENTITY and his test worked with 10cps +
i'll take a look thanks
Cap is removed when hitting an entity
fixed i reinstalled chrome
Disable your vpn. Restart your pc. Restart your router.
He just said it was fixed .-.
Oh i thought that was gibberish. He meant. "Its fixed. I reinstalled Chrome."
can someone spoonfeed me i wanna make particles go thru a player line of sight until they hit a player
i dont wanna learn vectors
itll be a one time use and ill never use that shit of math again
Learn Vectors
No then. If you don;t want to learn
ah shit do i have to do that chunk of math for a spigot plugin
You need to learn vectors at some point. Better start today.
oh god\
Vectors aren't hard
Spigot does it all for you anyway
Location start = player.getEyeLocation();
Vector direc = player.getEyeLocation().getDirection();
for (double i = 0; i < 10 ; i += 0.5) {
direc.multiply(i);
start.add(dir);
start.subtract(dir);
direc.normalize();
}
is what i got
from reading forum posts
not quite
Location loc = player.getEyeLocation().clone();
Vector dir = loc.getDirection();
for (int i = 0; i < 10; i++) {
loc.add(dir);
loc.getWorld().spawn blah...
}```
to spawn each particle
ohhhhhhhhhh
each loop it adds the direction to the loc and spawns a particle
as getDirection() returns a unit vector (length of 1) it will increase loc by 1 in that direction each time you add
OH BTW
the teams thingy
leaders.clear(); will clear everything right
or just leaders?
everything
Usually you register a placeholder with PlaceholderAPI. Its well documented.
h o w
i read that
and thats not what i wanted to do
you see when he used &f%vault_rank%
i want to let people do that with a placeholder i make
You want people to use that in the config of your own plugin or everywhere?
everywhere
Then you need PlaceholderAPI
like in tab
Yeah i have it imported to my plugin
i added the maven dependency etc
now what do i do
Read the docs. It doesnt get better documented than this. You can almost copy paste your way through.
Provided you have larger amounts of java knowledge
I remember when I started with spigot I wanted to use PAPI but had no idea how even after reading the docs. But I haven't really done that much java up until that point
Well.. this specific page: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/PlaceholderExpansion
And look at the "Without a Plugin" section
Oh I mean With a Plugin (External Jar)
I think he uses maven
The identifier is the string after the starting % and before the first _ (%identifier_values%) and, therefore, cannot contain _, % or spaces.
Wtf is he saying though
yes i use maven
He is saying that the first word that comes after the first '%' char is the identifier and can therefore not contain any '%' or ' ' chars.
Params are the arguments that can be provided by using underscores after the identifier.
You should for now ignore them and write a simple %placeholder% without any underscores.
Do you use maven?
yes
Did you add the PlaceholderAPI to your dependencies and set the scope as provided?
yes
- Create a class.
SomeExpansion(You name it somehow) and let it extendPlaceholderExpansion
ok
- Implement all methods
public class SomeExpansion extends PlaceholderExpansion {
private final SomePlugin plugin;
public SomeExpansion(SomePlugin plugin) {
this.plugin = plugin;
}
@Override
public String getAuthor() {
return "someauthor";
}
@Override
public String getIdentifier() {
return "example";
}
@Override
public String getVersion() {
return "1.0.0";
}
@Override
public boolean persist() {
return true; // This is required or else PlaceholderAPI will unregister the Expansion on reload
}
@Override
public String onRequest(OfflinePlayer player, String params) {
// Compute and return your placeholder here
}
}
o
onRequest is called whenever a placeholder is being replaced. So there you return your String based on the OfflinePlayer
Just implement all the methods:
getAuthor() -> return your author name
getIdentifier() -> return what should be in between the % chars. So here it would be %example%
getVersion() -> Whatever you want. Use 1.0.0
persist() -> true
onRequest(OfflinePlayer, String) -> return your replacement value
so if i wanted a %teamvalue% get replaced with smth from config
how would i do that
i did implement them
getIdentifier() -> return "teamvalue"
onRequest() -> return teamvalue based on that OfflinePlayer
If you implemented everything then simply add this to your onEnable:
// Small check to make sure that PlaceholderAPI is installed
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new SomeExpansion(this).register();
}
Then you are done.
Because placeholders can be called for values related to OfflinePlayers.
how to make creeper firework?
Then just return a value from a config and ignore the arguments. Nobody forces you to use them.
That would be the OfflinePlayer then
basically im trying to show the player a config thingy in tab
You dont have any control over where the placeholder will be used later
Unless you want to use it yourself in other plugins.
Thats the OfflinePlayer
o
ok
Its been a while since ive used this
so i fi u se %teamnumber% in tab
it will show the config with the player unique id :
public String onRequest(OfflinePlayer player, @NotNull String params) {
// Compute and return your placeholder here
return plugin.getConfig().getString(String.valueOf(player.getUniqueId()));
}
I added a placeholder in GroupManger to allow that placeholder to perform a permission check
use somethgin similar
Stop using configs on runtime. You will screw up half of your code with this.
what
how
what im doing here is
im assigning a number
to a arraylist
of player unique ids
so the number is shown when u use that placeholder
You should use your config only at one place: In a config manager that loads your data when the server starts.
After that you dont touch your configs.
wdym
Load your data out of those ugly config files and create properly structured classes. Load from them once then throw them in the garbage.
only config if your info changes rarely and needs to persist over restarts
there is no but
ok i cant use configs then
ok then what can i even do
i want to stick a number to a list
if your data is per session then in memory
and show thaat number when using a data holder
btw the list gets cleared when server restarts
you add the players UUID to a list
then to get their place in the list it list.indexOf(UUID)
Then using a config makes a ton of sense. Why not scrap all your classes and write everything in the config? Everything in one place.
sarcasm be like:
o
uhhh
btu
but
the placeholder class is alr extending smth
yeah i was just about to do that
protected static Map<List<UUID>, Integer> number = new HashMap<>();
so uh
i want to link the team (list of uuids) to an integer
god no
w u t
each team has a leader who has a UUID
why do you want a number?
why protected
so theyre like
yeah lol
numerized? my english died
when are you going to use teh number?
place holder
like team 1, team 2 ?
yes
then you still don;t need any of that
o
you find what leader they are under (with the util method you should already have written) then leaders.indexOf(leader)
it will give you the team index they are in
oh my god im so dumb
1,2,3 etc
im so fucking dumb aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
wait no
its a map?
?
Create a util method to do all that for you. Kepe your code tidy
Hey! Does anyone happen to know how to set the direction of stairs? I have already tried with the following code:
location.add(1,4,4).getBlock().setType(BRICK_STAIRS);
Stairs stairs1 = (Stairs) player.getWorld().getBlockAt(location.add(1,4,4)).getBlockData();
stairs1.setFacing(BlockFace.WEST);
player.getWorld().getBlockAt(location.add(1,4,4)).setBlockData(stairs1);
but then I get the following error through the console: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData cannot be cast to class org.bukkit.block.data.type.Stairs
This refers to the following line:
Stairs stairs1 = (Stairs) player.getWorld().getBlockAt(location.add(1,4,4)).getBlockData();
can anyone help me there by any chance?
do i get each thing of the set and add it to an array
yeah still
Hey, I'm looking for an event what will let me find what itemstack another item is being dropped onto in the player gui any advice? context: I want to drop a gemstone onto a pickaxe and I'd like to get the details of both itemstacks.
.toArray().indexOf(leader)
Cannot resolve method 'indexOf' in 'Object'
You can set block data directly you know
oh hey redempt
toArray(new UUID[keySet.size()]).indexOf(leader)
Stairs stairs = (Stairs) Material.BRICK_STAIRS.createBlockData();
stairs.setFacing(BlockFace.WEST);
block.setBlockData(stairs);```
You can do this with InventoryClickEvent
not sure but see if you have the correct import since there are 2 stairs import
org.bukkit.block.data.type
OR
org.bukkit.material
you want the first one
You mean when a player clicks on an item with another item, right?
How so?
So I wanna get the event when a player drops a book onto a pickaxe
Yeah that doesn't clarify anything
Dropped onto as in they drop a pickaxe in the world and then drop a book on it in the world?
Or do you mean in an inventory, they click on a pickaxe with a book on the cursor?
I mean, when a player drops a book onto a pickaxe in their inventory
That's not dropping
Like drag and drop in the gui
It's clicking
And that can be done with InventoryClickEvent
You just look at getCurrentItem, the item in the slot that was clicked on, and getCursor, the item on the player's cursor
I was about to say would getCursor do it 😅
If someone asks you to clarify your question, restating the same thing you said originally doesn't help
Be more specific about the context
Was that to me or someone else?
You
You are getting the keySet of your map
smh, dinotoucher
converting that to an array
OI
that doesnt return an arraylist either way
UUID[]
Set<UUID> keySet = leaders.keySet();
keySet.toArray(new UUID[keySet.size()]).indexOf(leader);
Redempt, the event doesn't even fire.. hm
oh i'm dumb
i forgot to register it ahahahaa
?paste code
gradle could do this better 🙂
it's a mess
maven uses 5 gradle 1, iirc gradle is faster
@eternal oxide Set<UUID> keySet = leaders.keySet();
ArrayList<UUID> list = keySet.toArray(new UUID[keySet.size()]);
its not big
yes, then list.indexOf(leader)
@waxen plinth i forgot to register it all along 🥲
Required type:
ArrayList
<java.util.UUID>
Provided:
UUID[]
why? no you are creatign an array
what are you trying to do
Register what?
the listener 🥲
u sure u wanna help me? most ppl dont have patience for me
Incredible
i see why they dont have patience for you
one sec
LOL
im trying get a
arraylist
of a set
new ArrayList(Set)
swear you could have done every link in ?learnjava in the time youve spent getting help here
make sure you're shading whatever that dependency is
ArrayList<UUID> list = new ArrayList<>(keySet);
then you can do indexOf
also change yoru Map to LinkedHashMap<UUID, List<UUID>> leaders = new LinkedHashMap<>();
So the ordering remains the same
o
Hello so i'm asking for how to code player ID permanent
for one player
ond other player give them another id
@eternal oxide but how do i get the leader of the team the player is in
is that posible?
wait nvm im dumb
??
public int getTeamIndex(UUID leader) {
Set<UUID> keySet = leaders.keySet();
ArrayList<UUID> list = new ArrayList<>(keySet);
return list.indexOf(leader);
}```
uuid?
you're asking a very broad question
just give a player a random number and don't give it for onther player.
that is the entire purpose of UUIDs
uuid.
You should have already written teh method to get teh leader a player is under
🤔
what does that have to do with spigot?
i want to list players they joined first player to last player
first player gets 1
and last player gets idk the number
i know what you want
send your pom
just learn java
this is not make a plugin and then learn java . it's the other way around
E i didnt
then you did not shade it in
for (UUID key : leaders.keySet()) {
if (leaders.get(key).contains(player.getUniqueId())) {
leaders.get(key).remove(player.getUniqueId());
inTeam = true;
}
}
i have dis tho
1s
you don't shade spigot
public UUID getLeader(Player player) {
for(UUID uid: leaders.keySet()) {
if (leaders.get(uid).contains(player.getUniqueId())) return uid;
}
return null;
}```
why firework.detonate() makes just dead particles
so why tf does maven return at "package" that there are 100 erors in classes
and when i open one of the classes
they are fine
because spigot doesnt shade whatever discord dependency you're using so it is not available at runtime
thus you must do it yourself
do not shade spigot
then you've added it to the wrong location or you copies the java files not the compiled class files
?paste
@eternal oxide https://paste.md-5.net/opisusilus.java u think dis good
line 14 return getTeamIndex(key)
16 return null
scrap 11
or 16 return ""
You don;t want to be calling getTeamIndex (null)
i am spawning firework but its not exploding but flying and disappearing what to do? here is my code: https://paste.md-5.net/epoyiboxow.pl
o
ok done i think
now how do i register the place holder
pls help ^^^^^^^^^^^^^^^^
yeah so i think it was because of paper @unreal quartz , wierd
tried with spigot, it was fine :))
TIL, there is a limit on class name length in java
was doing some funny JSON deserialization, resulting in this monster: https://paste.md-5.net/luyitipahi.cs
...which does not compile due to:
YTMFrontendSearch$Content$TabbedSearchResultsRenderer$Tab$TabRenderer$Content1$SectionListRenderer$Content2$MusicShelfRenderer$Content3$MusicResponsiveListItemRenderer$FlexColumn$MusicResponsiveListItemFlexColumnRenderer$Text$Run$NavigationEndpoint$WatchEndpoint.class: Class name too long
The heck is this?
Blame google for that 🤣
?
Wanting to deserialize JSON, so I use GSON for that
But google's json is worse than most onions in terms of layers
But Gson doesnt generate new classes
Hey so, I got one last thing I can't work out how to do do, https://paste.bristermitten.me/ehylivowac.cs after player.sendMessage("target: " + targetMeta.getDisplayName()); how can I destroy the item of which was placed?
You could just have one class with some fields. There is literally no reason to write such a class.
?
What do you mean?
What is the best way to make a list of mobs the player can interact with
I get a massive json tree from one of Google's APIs, and I need to get to one of it's inner layers
now I could create 50 different files, all with 1 class with 1 field
but I thought, might as well nest them
Store it in a Set
switch
buuut javac doesn't appreciate that past a certain point
Use Set.of or ImmutableSet.of
Use a Map<String, Consumer<NPCInteractEvent>> and add that pdc tag to an NPC
yeah dont hardcode a lot of if statements
You can traverse the json tree without having to serialize the whole thing.
Oeh now do tell
If you just want one value
I could use org.json I know that one, but it makes for a mess
I'm not using citizens. I'm looking to make a simple npc plugin for personal use. The plugin is simple, put a mob without artificial intelligence with some data and use player interaction.
This is my old code before it was dropped.
Add a PDC tag to that NPC and use a Map<String, Consumer<PlayerInteractEvent>> then to delegate the event based on the NPCs PDC content.
How would I add the PDC to a hashmap if it keeps deleting when restarting the server?
interface NPC { // name this better
void onInteract(Player p, Entity e);
NamespacedKey getKey();
}
@quaint mantle
class Archer implements NPC
String json = ...
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
JsonObject subObject = jsonObject.get("SomeObjectKey").getAsJsonObject();
JsonObject subSubObject = subObject.get("AnotherKey").getAsJsonObject();
// And a lot more
Huh?
In this example the NPC is both the instance object and the composition component.
I dont understand the Set<NPC>
to loop through on the event
Yeah. No.
No need to loop through anything. Scales O(n) and Sets loop quite slowly.
Just use a Map<NamespacedKey, NPC> if you already got a key.
Compile-time and Runtime versions might not match.
Is the dependency "discord-webhooks" provided by another plugin?
Did you make sure to shade it into your plugin then?
hey, i currently have https://paste.bristermitten.me/uwasuduzov.cs but I can't work out how to cancel the placement of the stack and destroy it but get some nbt from it before any advice?
Add the maven-shade plugin to your pom.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you use Java 16 then you need to get a snapshot version. But well do that if you get any compiler problems.
Just make sure to add the provided scope to all dependencies you dont want to shade. You surely dont want
to deliver the whole spigot api within your plugin. 😄
<dependency>
<groupId>some.group.id</groupId>
<artifactId>some-atifact</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Try to set Material.AIR
but that'd destroy the current item?
POTION:
slot: 0
effect: INCREASE_DAMAGE
duration: 100 #in ticks
amplifier: 1
splash: false
POTION:
slot: 1
effect: SPEED
duration: 100
amplifier: 1
splash: false
POTION:
slot: 2
effect: POISON
duration: 100
amplifier: 1
splash: true```
how would i make potions using that
rn im using potionmeta
You need to add the ItemStack into a variable before nulling it in the players hand.
Then you can get some information from that ItemStack.
but idk how to make it splash
I wanna get the event of dragging https://i.imgur.com/Z3T0vVa.png lets say the orange wool onto the carrot
Potion and SplashPotion are two different items. You need to handle them separately by also using SplashPotionMeta
Nope. 1.8 is rly old and doesnt have such nice API features.
do you have any idea how to do it in 1.8
So @lost matrix would you go like
player.setItemOnCursor(null); ItemStack stack1 = target;
Material.SPLASH_POTION isn't a thing
The bigger jar also contains all your dependencies. Its also known as "uber" jar.
stupid discord formatting
what is Yeltsa Kcir backwards?
player.setItemOnCursor(null); doesn't work :/ I can still switch the items around
Example:
@EventHandler
public void onClick(final InventoryClickEvent event) {
final Player player = (Player) event.getWhoClicked();
final ItemStack cursorItem = event.getCursor();
final ItemStack target = event.getCurrentItem();
if (target == null || cursorItem == null) {
return;
}
final ItemMeta cursorMeta = cursorItem.getItemMeta();
final ItemMeta targetMeta = target.getItemMeta();
if (targetMeta == null || cursorMeta == null) {
return;
}
player.sendMessage("Target: " + targetMeta.getDisplayName());
if (target.getType() == Material.EMERALD) {
// Now ill copy the display name from the cursor item to the
// target item while destroying the cursor item.
final String cursorName = cursorMeta.getDisplayName();
targetMeta.setDisplayName(cursorName);
target.setItemMeta(targetMeta);
player.setItemOnCursor(null);
event.setCancelled(true);
}
}
Yes thats pretty big. It looks like all the dependencies you use are bloating the plugin. Did you make sure that the spigot-api is not shaded in?
I tried that but even that doesn't work for some reason?
provided means it wont be shaded in but is provided by another jar later at runtime.
I don't know if this is something wrong with spigot or?
99.99% of the time its not the API
I mean, I've been trying in many different ways and no hope
It says the target item but the dropped item doesn't delete itself
I get all this output what's fine https://i.imgur.com/VIYQFjZ.png but the gemstone just won't delete itself from the inventory
Just tested my code. Works like a charm.
Yes. 1:1 the code from above.
Did you register the listener and added the @EventHandler annotation?
yep
Spigot version?
Then the code works.
Debug your code. Make sure the code inside the conditional statement gets fired.
I'm gonna debug now, this is really really weird.
Show your exact code.
You drag the item on the emerald and not the other way around, right?
But the target is the item in the current slot.
Try dragging the item on the emerald XDD youll see what i mean
"target" is the clicked item. The slot item if (target.getType() == Material.EMERALD)
If the slot item is an emerald.
So, the target needs to be the trident then?
I'll quickly switch it around and see how that goes
tbh
everything i needed
exists in 1.8 and in 1.17
btw is a plugin being 40kb bad
Well, apart from it duplicating the trident i think you fixed it thank you!
not it doesn’t
am using teh 1.8 api for a project atm
it is utter shite
no… depends on how many classes
and what your plugin is doing
a 40kb join message plugin is bad
but a 40kb mini game is amazing
one last thing, when i drop a item onto the item it duplicates the item of which i dropped onto?
I now feel like creating a join message plugin on an alt account that is packed with 200mb of
cat images and see via bstats if anyone dares running it XD
When I drop the item on the other item it renames it to the dropped item? https://i.imgur.com/qrEXq5V.png
i have seen it done before and i’m pretty sure it don’t
I think i found it 😅
edit: It just duplicates the whole target item now hm..
Hey @lost matrix how did you destroy the dropped item? I can't do that for some reason
Looks good so far.
it's okay?
Screenshot or code block. Who tf takes a photo of his screen in 2021?
Bruh did you take a photo of your screen??? Lmao
BRO
WHAT THE FUCK
player.sendMessage(ChatColor.RED + "No Player Matching " + args[1]);
HOW IS THIS NULL
player is command sender btw
Full code pls
And stack trace
?paste
Player is null
args[1] is your player
line 35
player.sendMessage(ChatColor.RED + "No Player Matching " + args[1]);
it’s a work of art 🤩
Try splitting the methods/variables in separate lines to see exactly what is null
what
args 1 is bull
player.
sendMessage(
ChatColor.RED
+ "No Player Matching" +
args[1]);```
i checked iaargs length is 2?????????????????????
lol that willl be the same wont it
Try that and see what line is null
It tells you what line, but just try printing args[1]
Easily fix this by 5 seconds of debugging
Tell me this isn’t yours lol
Thats peak performance right there
Lol
If so, get help 😂
ofc its not his lmfao
and size coild matter less
Idk why you would worry about it
40kb is not that much
entity.getPersistentDataContainer().getKeys().toString return [pluginanem:dataone] how do i return just a string?
my plugin used to be 2.2MB because of shading kotlin stdlib 👍
i didnt shade anything
40KB is nothing
You dont want a String. You can check with has() if the key exists.
I already checked back
When I query the SQL to get a ResultSet object, the last result in the set is always equal to the last piece of data I inserted into the SQL. How do I put data into the SQL at certain locations?
@quaint mantle do you want to get the value for that key?
or what are you trying to do
well keys are the keys not values
so iterate over the the map using the keys and get each one?
it's simple
Dont iterate pls. Use a HashMap.
Hi, i'm trying to build a fat jar with gradle, but i have some problems.. can someone help me?
I need it to use "Java Discord API".
That's my gradle: https://pastebin.com/YGcRfTTA
Use the gradle shadow plugin to shade in your dependencies.
Sorry, I'm new in this.. where can i find it?
How can I use Packets to send an ItemFrame with a map to a player?
@chrome beacon you were wrong, the multi-version compatibility is possible, including 1.17 nms, without using java 1.8 and reflexion only ^^ send me a pm if you want explanations on how I did it ^^
What j ver?
Hope you’re not writing a Bible
- java version 16
- set javac compatibility 1.8. Using gradle it can be done using :
compileJava {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}
It’s a simple question
How did you not use reflection?
but that would restrict you from using j16 features or no?
Yeah
yes
ok guess it’s doable
But what’s the point tho honestly if you have it but you can’t use any of the features
Seems dumb imo
Just switch entirely
I mean compatibility I guess
Tho personally I’d just use java 8 and keep it simple that way
The goal is to have a plugin that use NMS (without going through slow and painful reflexion) and which is compatible with multiple spigot versions
Only the latter actually, afraid pattern matching might compile down to some normal instanceof and then cast
I did it at start but at some point (while trying to achieve compatibility) I came back on Java 8 so I deleted those features usage ^^
Ah well then
So I have no answer to the question "will it break the javac 1.8 compatibility or not ?"
Idk I mean you should be able to achieve a 1.8-1.17 compatibility with solely devoting your compiler to java 8.
As far as I can see compatibility is working well. I'm currently building heads with custom textures without any reflexion in my nms-1.17 submodule. And I tested the plugin in both 1.12 and 1.17 without any issue ^^
How do I remove x amount of an ItemStack matching all data but the Display name from a players inventory? Needs to support differently named items aswell
I’m happy you’re using gradle, I hope kotlin dsl
you will need to build a ItemStack.isSimilar method. Let me send you a code extract.
just look at the stash code and remove the displayname part
?stash
int invAmount = 0;
for (int i = 0; i < 36; i++) {
if(contents[i] != null && contents[i].getType() != Material.AIR) {
ItemStack itemSlot = contents[i];
ItemMeta metaSlot = itemSlot.getItemMeta();
metaSlot.setDisplayName(null);
if(Objects.equals(item.getType(), itemSlot.getType()) && Objects.equals(meta, metaSlot)) {
invAmount += contents[i].getAmount();
}
}
}
Well at the moment I am only using this to get the amount of items in their inventory that match everything but their displayname
(For some reason it outputs 1 less than the amount of items he has)
Still can't figure that one out ^^
ah nvm i found that one out lol
had to use <= instead of <
(in another line)
well I don't have any issues counting items, I need to remove them from their inventory, so is there a solution to do that without looping through each slot in their inventory?
no you have to loop over each slot
ugh .-.
If I remember well, there is an inventory iterator.
It implements Iterable
for (int i = 0; i < 36; i++) {
if(amount == 0) {
break;
}
if(contents[i] != null && contents[i].getType() != Material.AIR) {
ItemStack itemSlot = contents[i];
ItemMeta metaSlot = itemSlot.getItemMeta();
metaSlot.setDisplayName(null);
if(Objects.equals(item.getType(), itemSlot.getType()) && Objects.equals(meta, metaSlot)) {
if(amount >= item.getAmount()) {
amount -= contents[i].getAmount();
player.getInventory().removeItem(contents[i]);
}
else {
contents[i].setAmount(amount);
player.getInventory().removeItem(contents[i]);
amount = 0;
}
}
}
}
So this would work?
@silver shuttle just use Object == Object
my IDE recommended it to me
weird, just use ==
kk
== doesnt work here
can't be null, as i have checks in previous code
wdym
for material == works but for ItemMeta it doesnt
weird
not really
for some reason, that code also removes ALL items matching the given item from my inventory, not just "amount" of items
and I can't figure out why lol
It’s because Material is an enum
And enum values can be compared using reference equality
ahhh
Due to them being constant
yeah
Because you're doing it real weird
The contents are not modified when the inventory is
I just came up with this general approach.
/**
* Removes all items from this inventory that match the given predicate.
*
* @param inventory the target inventory
* @param selector the predicate that defines what items should be removed
* @param count the amount of items to remove
* @return how many items couldnt be removed
*/
public int removeFrom(final Inventory inventory, final Predicate<ItemStack> selector, final int count) {
final Predicate<ItemStack> nullSafeSelector = ((Predicate<ItemStack>) Objects::nonNull).and(selector);
int amountToRemove = count;
for (int index = 0; index < inventory.getSize(); index++) {
final ItemStack indexItem = inventory.getItem(index);
if (!nullSafeSelector.test(indexItem)) {
continue;
}
final int stackAmount = indexItem.getAmount();
if (stackAmount >= amountToRemove) {
indexItem.setAmount(stackAmount - amountToRemove);
return 0;
} else {
amountToRemove -= stackAmount;
indexItem.setAmount(0);
}
}
return amountToRemove;
}
Every enum constant field points to its own instance the entire runtime usually (unless classloader thing blah)
Method that does the same thing you're looking for
thanks, but I am actually quite close to solving it myself
Why do you have an ItemStack and a BiPredicate as params? Seems confusing.
That's fair
I could have probably just used a Predicate<ItemStack>
Guess I didn't think of it when I wrote that method
But I think I did it so that I could use a method reference with my compare method
I have a separate method to compare items based on specific traits
XD. Gotta make this look fance. Put all the :: in there
is it possible that Inventory#removeItem(ItemStack) removes the entire ItemStack in that inventory, regardless of size? Because I set the size to something lower than the stack I have in my inventory (have 64, ItemStack amount is 2) and it removes the entire stack
itemSlot.setAmount(removeAmount);
player.getInventory().removeItem(itemSlot);
hello where can I get started on spigot plugin dev
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
ty
String.valueOf()??
Loop through and use getNamespace() and getKey(), depending on which part you want.
Namespace is the first part, basically an identifier.
Like minecraft:tp, minecraft is the namespace
ahh
does anyone know the dimensions of the player bounding box in 1.8?
approximately 1 player
ah would never of guessed that
Hello, org.bukkit.scoreboard.Team#getEntries().clear() does UnsupportedOperationException
on the internet they suggest to copy it but it is not useful because obviously I need to clear the real Team Set
That is the funniest answer I've ever seen 
