#help-development
1 messages ยท Page 1384 of 1
help
my custom recipe plugin is not working
this works well with items on 3*3
but not working like this image
this is working well
a good note with programming, if it repeatable, you can cut it down
Yeah. Im not doing that for sure. I would rather create a quick tool that uses NMS on the latest version and generate one big json file that i can use later on.
check out org.bukkit.craftbukkit.util.CraftMagicNumbers
I'm not sure if it's a still a thing tho ill check
It is
but there is a getItem(material).canDEstroySpecialBlock(IBlockData)
Will be helpful
and a getDestroySpeed in item
ig you could match the default with the current item's
Creating a custom recipe resolver is quite the task. You can do one of two things:
Generate some sort of hash for the 3x3 grid. Map the shape to a Predicate<ItemStack> and iterate over all registered recipes until you find the right one.
i have code for a recipe resolver if you want but it has my own code intertwined in it
umm.. plz look my code, find error
you can cut that code down by 80%
do that first then you have less points of failure
I will pay someone like 20 dollars to update this 1.15 plugin that uses protocollib to 1.16 https://github.com/iso2013/PacketEntityAPI
๐
It is brokey
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
80%?? but how to set 'A' to Material.AIR (empty) ?
You will get big problems when someone wants to create a 1x2 or 2x2 or 2x2 or 2x3 or 3x2 or 1x3 or 3x1 recipe. This is quite more complex then you might think.
But im willing to share my MatrixTruncator class when you are at that point.
What does your Bukkit.broadcastMessage(one + "/" + two + "/" + three); tell you when you register a recipe that doesnt work? Is the shape alright?
Also you dont cache the registered recipes anywhere. So when the server restarts, all recipes are gone.

I need a way to have a player with multiple line tags over their head. Have tried MultilineAPI but it doesn't work and has weird issues with 1.16
ye. i'll make recipe cacher later, (one/to/three) returns ABC/DEF/GHI on 3x3 items, else returns nothing
Cant find any other way to do that
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
What do you mean by "nothing"
havent tested it
but like along those lines
you see how you dont need to set an individual variable for each item
nothing on chat
theres many ways, some use invisible slimes riding player, some teleport armorstands every tick
Yeah the namer API was the one that did that, I don't know how i would implement stuff like that myself tho
when i use multilineapi
Its really tedious. I have a personal multi line API and it uses a bunch of different entities to get the spacing right.
Tipp: Use an invisible EnderMite or a small slime instead of armorstands.
wont there be noises and stuff
Custom nms entity implementation. No noises, no server side ticking.
And fully async.
oh god nms
๐ This is the one time i will ask. May a kind soul give me code
yeah i saw protocollib being used for that one
But the real problem starts when another plugin tries to mount the player with something. Boy that was a hustle with packet listening and re arranging the nametags.
I mean it does under the hood.
Then the method isnt even called? Do you get any exceptions?
no, just nothing displayed
so its not being called
But with this code you should get exceptions. Do you use any try{} catch blocks?
ok, i'll try try/catch
Material m11 = i11.getType(); throws a NPE if the slot is empty.
No pls dont
i sent a refactored method before, look at that and see how you can cut down
yo smile wanna have a contest
If its not too tedious and/or long
who can write the shortest method for that snippet he gave
What are the exact specifications?
Input ItemStack[]
Output String[] which represents the shape?
Ok. With or without truncation?
eh, with makes it even shorter lol
alr without then lol
Uh sure. So
public String[] toShape(Inventory inv)
But then the ingredients kind of get lost in the process.
in the method
10, 11, 12, 19 20, 21 28,29, 30 are the matrix slots
and 23 is output slot
So should we just make the shortest code that adds a recipe to bukkit by taking the Inventory as input then?
Alright lets try that.
this not working
ok
Has anyone developed a version of tnt that's slightly stronger
what is npe
null pointer exception
oh ok
Just set the yield of TNTPrimed higher.
I understand how i would make tnt itself stronger but how would you create a separate version of tnt
Not in any easy way
alr i believe I'm done smile
You would have to find a way to make them unstackable
That's easy...
Why would they need to be unstackable
So you can differentiate between the 2
Do you mine explaining how it would work
PDC makes it easy to distinguish between the items
It's a bit harder when they are placed
I'm just not clear on how to add a new item
You'll need to store the custom TNT in a database or chunk PDC
I've never done it before
bro
you're printing the entire class
i can't see printStackTrace() because of this
Do you have an example I could look at?
Look at any plugin that handles custom block data
Sliemfun does, but that may not be the best example
I realize this sounds really dumb but could you provide a specific example?
I'm the type of learner that needs to look at a specific section that clearly demonstrates something
I don't have a specific example
Would you be willing to find one? I have been finding this problem really frustrating so it would be a tremendous help
declaration: package: org.bukkit.event.entity, class: ExplosionPrimeEvent
Btw im on it.
The recipe i mean
Im almost done
oh 0x41
You're trying to set the item for a recipe key, but the recipe doesn't have that key
can i set ingeident before shape?
What command would I use to spawn tnt at a certain location
Command? /summon
no, you need to set shape first
But what is the entity name for a primed tnt
I saw that it changed from primetnt in 2018
Is there just an API that lets me set a custom username above head, ive tried all the public ones but they either dont work with spaces or dont support hex colors
I mean, /summon lets you tab through all entities
ok
๐ so uh... where can i grab
AreaEffectClouds may also be useful for that
The problem I had was invisible entities hiding them name of lower entities in the stack
ItemStack[][] map = new ItemStack[][] {
new ItemStack[] {inv.getItem(10), inv.getItem(11), inv.getItem(12)},
new ItemStack[] {inv.getItem(19), inv.getItem(20), inv.getItem(21)},
new ItemStack[] {inv.getItem(28), inv.getItem(29), inv.getItem(30)}
};
int charIndex = 65; // 0x41
List<String> tier = new ArrayList<>();
ItemStack result = inv.getItem(23);
NamespacedKey key = new NamespacedKey(Main.pl, "ay");
ShapedRecipe r = new ShapedRecipe(key, result);
for(ItemStack[] f : map) {
StringBuilder sb = new StringBuilder();
for(ItemStack s : f) {
if(s == null) {
sb.append(" ");
}else {
sb.append((char)charIndex);
}
r.setIngredient((char)charIndex, s.getType());
charIndex++;
}
tier.add(sb.toString());
}
r.shape(tier.get(0), tier.get(1), tier.get(2));
Bukkit.addRecipe(r);
} catch (Exception e) {
Bukkit.broadcastMessage(e.getMessage());
}
OK, and @drowsy helm 's code set ingerdiit first
Ok im done:
private static final int[] MATRIX_SLOTS = {10, 11, 12, 19, 20, 21, 28, 29, 30};
private static final int RESULT_SLOT = 23;
public void register(final Inventory inventory) {
final AtomicInteger c = new AtomicInteger('A');
final String line = Arrays.toString(IntStream.rangeClosed(0, 9)
.map(i -> SpigotCore.MATRIX_SLOTS[i])
.mapToObj(inventory::getItem)
.map(i -> i == null ? ' ' : (char) c.getAndIncrement())
.toArray(Character[]::new));
final String randomName = Arrays.toString(IntStream.generate(ThreadLocalRandom.current()::nextInt)
.limit(10)
.map(char.class::cast)
.toArray());
final ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft(randomName), inventory.getItem(SpigotCore.RESULT_SLOT));
recipe.shape(line.substring(0, 3), line.substring(3, 6), line.substring(6, 9));
c.set('A');
IntStream.rangeClosed(0, 9).map(i -> SpigotCore.MATRIX_SLOTS[i]).forEach(index -> {
ItemStack i;
if((i = inventory.getItem(index)) != null) recipe.setIngredient((char) c.getAndIncrement(), i.getType());
});
}
ouu i like that
One letter variables everywhere
We should make the code as short as possible. So readability was no concern XD
void addCustomRecipe(Inventory inv) {
ItemStack[] map = new ItemStack[] {inv.getItem(10), inv.getItem(11), inv.getItem(12), inv.getItem(19), inv.getItem(20), inv.getItem(21),inv.getItem(28), inv.getItem(29), inv.getItem(30)};
NamespacedKey key = new NamespacedKey(plugin, "");
ShapedRecipe r = new ShapedRecipe(key, inv.getItem(23));
char indexChar = 'a';
String output = "abc,def,ghi";
for(ItemStack item : map) {
if(item == null) output.replace(indexChar, ' ');
r.setIngredient(indexChar, item.getType());
indexChar++;}
r.shape(output.split(",")[0], output.split(",")[1], output.split(",")[2]);
Bukkit.addRecipe(r);
}```
but now i realise i can't set ingredient before hand so I'm sorta disqualified lmao
and i didnt do a random name
so i think you win smile lol
never new char had a getAndIncrement method thats great
lmao, doesn't need to be readable just works
Thats from AtomicInteger so i had an effectively final mutable character in my streams

Wait until you try AtomicBombs
Its normally used for multithreading. But MutableInt from apache is normally the way to go.
Sounds interesting ๐ค๐ค๐ค
private final Map<UUID, Integer> scores = new HashMap<>();
public void incrementScore(final UUID id) {
final int current = this.scores.getOrDefault(id, 0);
this.scores.put(id, current + 1);
}
public int getScore(final UUID id) {
return this.scores.getOrDefault(id, 0);
}
Can be simplified to
private final Map<UUID, MutableInt> scores = new HashMap<>();
public void incrementScore(final UUID id) {
this.scores.computeIfAbsent(id, key -> new MutableInt()).increment();
}
public int getScore(final UUID id) {
return this.scores.getOrDefault(id, new MutableInt()).intValue();
}
does that use maps?
I mean... you could also do this:
private final Map<UUID, Integer> scores = new HashMap<>();
public void incrementScore(final UUID id) {
this.scores.compute(id, (key, value) -> value == null ? 0 : value + 1);
}
public int getScore(final UUID id) {
return this.scores.getOrDefault(id, 0);
}
But thats not as understandable.
I'm really just struggling to understand how i create a custom variant of an item
No streams. Just lamdas. I use MutableInts in Maps because then i dont need to get the element, do stuff with it and then put it back in.
Because Integers are immutable you have to always change the value of your map. If its mutable then you can just get it and mutate it as you like.
Just use its PersistentDataContainer.
Ah I see yeah that's really interesting I think I'll adopt that more
Its bundled with spigot
@lost matrix can you please help me
I'm confused by what you mean when you say "Its" Pdc
Does it have a pdc by default?
Sure
Yes
Yes. Every ItemStacks ItemMeta has a PersistentDataContainer on default where you can just save data in.
I know it's probably juvenile for an experienced minecraft dev
But i haven't done any work with minecraft before
I'm just trying to help a friend add a stronger tnt to his server
I replied to the message where I post the code and stuff
Its really not. TNT is not a TileEntity so making this exact Block a stronger tnt might need some extra work.
theres no real way of differentiating a tnt block once it is placed
so it might be hard keeping track of it
Oh god scoreboards... looks like luckperms is missing some RegisteredServiceProvider<>
How about a way to make a custom tnt summon a second tnt to its explosion?
Nevermind that would probably have the same issue
its not luckperms
its an api
made by the same guy tho
it would be easy to modify any tnt explosion
but just for some explosions may be hard
The hard part is having custom data stored in your block that helps to distinguish between vanilla and custom tnts
Do you have any suggestions on workarounds
I just want a variant which is a bit better for raiding
Any insight is really appreciated
The advice so far has been really educational ๐
If you are fine with just a primed tnt spawning that has a longer fuse time instead of a block that is placed then i can give you a simple solution.
you could always cache the location, but theres no permanence over restarts
I think we found a way to make a longer fuse time but that probably wouldnt make raiding all that easier
I would say chunk pdc would work well here
Actually. Yes. But getting this right might be a bit complicated. I thought about an approach like this one when you said chunk pdc:
https://www.spigotmc.org/threads/tracking-blocks-that-were-placed-by-players.500216/
Actually I think we just found a plugin!
Thanks so much guys, I really appreciated this
Share pls
i wolder how they did it
We are looking into it
Lets decompile it and see ๐
they have one main class
thats always good
it just primes the tnt
instantly
lmao
Thats what we suggested earlier...
I believe I have a adapter that can store xyz+string
Actually itโs an array of a custom class that stores xyz+string
Same idea though
lmao no you didnt
it's pretty badly coded
but if you dont mind it instantly priming you could use it
So this plugin also just instantly spawns a primed tnt instead of placing a block.
Lol ok. Then i can give you a bit of that juicy spoon feed
๐ฅ
pls spoonfeed me smile ๐ซ
How did you decompile it btw? The plugin comes with x10, x100, x100 but we would like to alter it to be a bit more manageable.
Or any decompiler
or any yes, but i like jd lel
Iโve never tried using one to modify and recompile anything

can you not just use the default spigot stuff
It looks like it just isnt registering the service, either theres a setup step that you missed or the api is broken
theres probably a help discord for that api
This class does it all for you:
https://gist.github.com/Flo0/2563702ddff61a3bde726dd7933f7029
Example usage:
public class SpigotCore extends JavaPlugin {
private TNTManager tntManager;
@Override
public void onEnable() {
this.tntManager = new TNTManager(this);
}
public ItemStack createTNT(final float strength, final float yield, final int fuseTime) {
final ItemStack tntItem = new ItemStack(Material.TNT);
final ItemMeta meta = tntItem.getItemMeta();
meta.setLore(Arrays.asList("", "ยง7Str: " + strength, "ยง7Yield: " + yield, "ยง7FuseTime: " + fuseTime));
tntItem.setItemMeta(meta);
this.tntManager.setStrength(tntItem, strength);
this.tntManager.setYield(tntItem, yield);
this.tntManager.setFuseTime(tntItem, fuseTime);
return tntItem;
}
}
Result:
Thanks a bunch!
Now Iโm tempted to make a proper more tnt plugin with a resource pack and all
Hmm
Another idea for the pile I suppose
I got like 10 different project ideas with half written plugins laying around. One Just the usual boost of creativity each month that slowly fades into a new cool idea that is never going to be finished.
Pretty much
But i actually currently re-write AdvancedMachines 2.0.0 which is almost done and will def be released ๐
Sounds fancy
I probably wouldnโt even need and pdc storage if I just used noteblock states, although the issue with that is compatibility with other plugins, and disabling note blocks...
Data driven blocks when Mojang
Data driven blocks, entities and GUIs is all we need. Then mods are almost obsolete.
Custom blocks are also a thing. But all of those 3 have really big drawbacks.
The mobs lag the server like hell. The GUIs are not dynamic (So bars etc are really hard)
and blocks might also lag the server (if done with spawners) or replace current states.
Origin realms doesnโt seem to be doing too bad with what they have
Let me google that
Ok this all looks really refined. But there are no mobs i would call "crazy"
Just normal mobs that are mounted with ItemStacks which have different models and animations based on
the current state of the mob.
Really refined actually...
But i guess you can do a lot already. But in every video i saw the guy was like "origin realms is experiencing lags"
hi angy
BECAUSE ITS ME
STUPID SCOREBOARD 

util
dont work
3 apis
dont work
compiling it into my project
but... but... but
im about to cry 

wow pepe crying actually got me emotional

ok the ultimate soundcloud @lilac dagger
I will use bukkit scoreboard
just for you
itemframes seem to lose all persistent data attached to them, any workaround for it?
are you actually using teh PDC or just meta?
Yes, the entity has both PDC and meta which is why I asked
I need to know something, he says crying
can you use a list to add the lines using spigot scoreboard, it reluctantly asks @eternal oxide
What is a good way of getting a hash for the setResourcePack?
I need to it stay the same if the resource pack stayed the same
i try to code a mlg plugin and i want to tp the player 40 blocks in the air, but only when there is not a block over the player not even in 1000 blocks hight how can i do this?
in 1.16
the problem might be the update method from CraftItemFrame:
private void update() {
EntityItemFrame old = this.getHandle();
WorldServer world = ((CraftWorld) getWorld()).getHandle();
BlockPosition position = old.getBlockPosition();
EnumDirection direction = old.getDirection();
ItemStack item = old.getItem() != null ? old.getItem().cloneItemStack() : null;
old.die();
EntityItemFrame frame = new EntityItemFrame(world, position, direction);
frame.setItem(item);
world.addEntity(frame);
this.entity = frame;
}
I don;t understand your question
getHighestBlockAt
but i dont want just the highest block i want every block in the range from the players hight to lets say 1000 or so
you'll have to do the same
you get highestblockat then compare its Y to teh players Y
and how can i compare it?
wdym
this is what I wanna do
public String getTitle(Player player) {
return Hub.mainColour + Hub.serverName;
}
public List<String> getLines(Player player) {
final List<String> line = new ArrayList<>();
line.add(Hub.ambientColour + "----------------------------");
line.add(Hub.mainColour + "PlayerCount:");
line.add(Hub.secondColour + "1");
line.add(" ");
line.add(Hub.mainColour + "Rank:");
line.add(Hub.secondColour + Hub.rankPlaceholder(player));
line.add(Hub.ambientColour + "---------------------------- ");
return line;
}
}
I wanna use these values
i have this code at the moment: import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class mlgCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(args.length == 0) {
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcBitte benutze ยง6/mlg");
}
return false;
}
}
```java
is a think u know
how can i do this?
'''java
ah okay
sorry
'''java import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class mlgCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(args.length == 0) {
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcBitte benutze ยง6/mlg");
}
return false;
}
}
hmmm....
nonono
oh hahaha
ye
'''java import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class mlgCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(args.length == 0) {
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcBitte benutze ยง6/mlg");
}
return false;
}
}'''
ups
`
top left ontop of the tilda key
`` then a third
xD iam so lost sooorry guys ๐ฆ
you're fine man lmao
If the getHighestBlockY is > the player Y then there is a block above them
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class mlgCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(args.length == 0) {
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcBitte benutze ยง6/mlg");
}
return false;
}
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class mlgCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(args.length == 0) {
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcBitte benutze ยง6/mlg");
}
return false;
}
}```
close
dont worry we see the code now
ah okay
so what exactly is the problem with it?
whats wrong?
i want that the player can not teleport when there is a block anywhere over his had
even in hight 1000 or so
okay
You were already told. getHighestBlockY and compare to the players Y. if its greater then there is a block above them.
p.getWorld().getHighestBlockYAt(p.getLocation())
then if that location is higher than their loc, they cant
i guess
Wait, you said any height?
yes
if there is any single or multiple block above the player, then the highest block at the players position is higher than the players position itself
no need to check for more blocks
ok
why not just do the highest block up to the height limit? I mean technically the height can go up forever....
if ya set your server with no limit
getHIghestBlockYAt returns an int of the highest block
thats all you need to check
okay thanks guys i love you
Sus!
The limit in 1.16 is 256
ik thats the limit by default, i was just saying it could be changed and he should set it to whatever it is for his server
hell, i never worry about that because i only code for 1.8 XD
you sure? I think you can on Hyperion jar
lol, i know that a lot of cannon jars have a max y option
as far as i know, the client only knows how to handle blocks up to 256, only with the 1.17 snapshots there is the support for higher blocks
and that, like the others said, the limit setting can only be lowered
Yeah the internal data structures just donโt support above that
yeah its probably max input between 0 and 256
anything over the client isnt made to deal with

Not sure why any fork would need that considering itโs in vanilla(?)
I think itโs vanilla anyway
idk, they just add it usually lol
this doesnt work ๐ฆ
most those forks are $500 each XD
here, ill just write ya something
Forks of what
usually they fork TacoSpigot
That test is true if there is a block above the person. reverse it to run code if there isn;t one
public static boolean idkWhatToNameThis(Location loc) {
while (loc.getBlock().getType().equals(Material.AIR)) {
if (loc.getBlockY() >= 256) {
return true;
}
loc = loc.add(0, 1, 0);
}
return false;
}
@near crypt this should work
Spigot forks?
Only stella sells for that much
noo i get it now
lol, i can name at least 5 that are that much XD
i think
No reason for a loop with getHighestBlock existing
StellarSpigot, GemSpigot, Hyperion, Bestles, etc
he said it didnt work for him so i just made him that
They private thp
Fr?
Thought they were provate
Ikr cause rich guys with no exp buy them
If you are spending $500 on a silly 1.8 optimized fork then you may want to re-evaluate some things
Ikr
well, they kinda have to use it for Factions servers
Its a fucking jar
or cannons dont work
Makes sens for cores
they have no option
Cannons work fine?
they have to pay it
No
no they dont without a cannon jar
Buy one cheaper
Whatever
Make ur own
Optimise a cheap one
If you want some fancy cannons, make a plugin for it
Aspigot
Factions Players dont want that
Beer spigot
here let me show ya something
Sure
Im not a factions guy
I do prac, kitpvp, hubs, server cores, ffa, uhc, meetup and so on
ok, found a SS
let me show ya have the jars have to handle multiple of (all shotting at 2sec-3sec each) and hold a steady 20tps
this is just a basic raiding cannon
without sand loaded ofc
if you dont have a good jar your server will just go to 2tps and the cannons just blow up
Is โconsider meโ a thing people put in their name
I swear ive done commission work for like 5 people with that in their name
No idea, iv had this account for 8 years
๐ฏ


Yea, well thats why they cost so much though
Ik but it still seems crazy, a fork of spigot costs the same as a server core
Server cores take months, with alot of knowledge this can take a week
Trust me, those forks dont take a week XD
I bet if u know what ur doing and ur me (working from 9-1am) then it would take a week
and how can i tp the player in the hight that he gives in the command for example /mlg 100 (100 blocks in the height)
change the method to return a location at the top block if its air
or pass Player into the method
and right before ya return try
ture*
just tp the player to the location
ยดยดยดimport org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class mlgCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(args.length == 0) {
if(p.getLocation().getBlockY() > p.getWorld().getHighestBlockYAt(p.getLocation())){
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcEs dรผrfen sich keine Blรถcke รผber dir befinden!");
} else if(args.length == 1) {
Location customMlg = p.getLocation().add(0, args[0], 0);
}ยดยดยดjava
}
return false;
}
}
damn
If you check that they have given at least one argument, you can parse it to an integer with parseInt
you new to coding?
yeah a bit
ahh
?
Integer.parseInt(args[0])
okay thx
np
How do I check If the player has specific amount of itemstack with nbt tag on their inventory?
not worth it
You mean it's bad for performance?
how can i cap the Integer so that i cant give /mlg 100000
Math.clamp(arg, 100000)
idk
Just use if statements with this conditions >=
oh yes true
so checking that is not worth at all?
private int clamp(int i, int max) {
return i > max ? max : i;
}
i'm currently creating a shop with item as the currency, custom item that has nbt tag on it.
well, spigot api nbt tag
pretty much
and i'm using that currently
are there anyone good with netty?
how can i discard data received through the pipeline channel handler?
nvm
why cant i do this?
ยดยดif(p.getItemInHand().getType() == Material.WATER_BUCKET) {
}ยดยดยดjava
ยดยดยดif(p.getItemInHand().getType() == Material.WATER_BUCKET) {
}ยดยดยด
}```
sry
What do you mean why can;t you do it?
deprecated. use getItemInMainHand()
This is deprecated because 1.9 introduced second hand mechanic
there is no p.getItemInMainHand
normal 1.16.5 spigot
#Player.getInventory().getItemInMainHand()
oh okay
How would I get the display name of a Written Book?
I tried itemStack.getItemMeta().displayName() but I always get null
getDisplayName() returns the item name
so you shouldn't be unless you're doing something else
are you iterating through the player's contents?
or how are you getting the item
public void questBook(PlayerInteractEvent event) {
Player player = event.getPlayer();
player.sendMessage("Event fired!");
ItemStack itemStack = event.getItem();
if (event.getHand() == EquipmentSlot.HAND) {
player.sendMessage("Hand");
if (itemStack != null) {
player.sendMessage("Not Null");
player.sendMessage(itemStack.getItemMeta().displayName().toString());```
and how can i check the armor of a player?
NullPointerException at player.sendMessage(itemStack.getItemMeta().displayName().toString())
is displayName() really working for you @vapid oyster
the function is getDisplayName()
That's depreciated for me, but I'm using Paper API, so maybe that's why
How can i check the armor of a player when i created a variable for the player
so player. ...
getArmorContents
getInventory()
player.getInventory().getArmorContents()
of inventory
yes thx
and how can i ask if the armor contains a specific armor piece?
if(!p.getInventory().getArmorContents().)java
this is my code
getArmorContents() returns an array, so check each for a match
and what is the code if i want to check if a player has a elytra?
equipped? it will be in an armor slot
yes when a elytra is equipped
ok so I need help with some code
idk how it works
and, like i have never used this ways in normal java
?paste
yes sorry
return false will show usage you defined in plugin.yml
@eternal oxide do you solved my problem?
check the appropriate slot in the array, Skull.
what about private Main plugin?
don't call the main class Main
is that even possible in java?
no
ok
it will conflict with standalone application naming of Main
i see
i usually just call the main class the name of the plugin
An applications Main class is when that application is an executable that instances itself. A plugin is instanced by Spigot so Spigot has a Main, your plugin should use something else, like your plugins name as its main class.
it stores the plugin object so it can be accessed
thats a private field (variable)
but it is not accessed
@sage swift how can i get the slot of the array and what is the slot of the Elytra
and when you create the command class it sets the variable to the plugin object so you can use it locally
that as you wrote it is defined but not initialized
learning basic java may help with this
2
ok
Thats a basic Java array, identical in every language
so getArmorContents()[1] should be sufficient.
ah okay
check null first, of course
yes
but do I have to make a variable?
cant I just use the args?
instead of this private CreeperSpawn plugin;
this public CreeperCommand(CreeperSpawn plugin)
Location mlg = p.getLocation().add(0, 60, 0);
p.teleport(mlg);
} else
p.sendMessage("ยงcDu darfst keine Elytra anhaben");
} else```
so is this right?
why? the elytra is on 2 or not?
No, its in the 2nd slot, which is not [2]
so 1 because it begins at 0
yes
but it is still not right
ItemStack chest = p.getInventory.getArmorContents()[1];
if (chest == null || chest.getType() != Material.ELYTRA) {
//codehere
}```
or != as you want to do it if they are not wearing an elytra
read the javadocs and see if you can tell me https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/PlayerInventory.html#getArmorContents()
There, I fixed the code above for your use case.
#equals() would be more accurate here
you never use equals on null nor an enum comparison
why not on enums? (i know that == also works there though)
How to make this optmize?
Entity victim2 = victim.getEntity();
if (victim2 instanceof Player){
Player p = ((Player) victim2).getPlayer();
if (p.hasPermission("damage.get.1")){
victim.setDamage(level1_getdamage);
}
if (p.hasPermission("damage.get.2")){
victim.setDamage(level2_getdamage);
}
if (p.hasPermission("damage.get.3")){
victim.setDamage(level3_getdamage);
}
if (p.hasPermission("damage.get.4")){
victim.setDamage(level4_getdamage);
}
if you use equals it could throw an NPE if the object is null. == is null safe
yes
That is completely wrong.
I think the #equals() method is better for reasons written out here: https://stackoverflow.com/a/14874376/14574069
Besides, after further research, it doesn't matter in the end because the #equals() method of an enum 1. cannot be overwritten and 2. looks like this:
public final boolean equals(Object other) {
return this==other;
}
Whats completely wrong? == is null safe. There can be no argument about that
This โฌ๏ธ
that statement is true
an equals check does defer to == however equals is not null safe
The #equals() method is an equals operator as you can see here: https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/java/lang/Enum.java
yes and its NOT null safe
Plus it is an additional method call
doesn't matter on Enums
what is an extra method call?
in my opinion it's a huge plus. I would rather get a NPE than ignoring it
Its not ignoring it, its null safe checking.
Use #ordinal(), it is not null safe and it safe for when people are doing strange shit with reflection
null safe checking is good if you expect a value to be null
This is java. nulls are everywhere
"strange shit with reflection" lmfao
exactly
so sometimes you'd rather have an exception if something isn't supposed to be null but somehow is it anyway
There are instances where people mess with the internal int cache
personally i use .equals when the enum is used in a more object-like context, and == when it's used in a more constant-like context
and == for small pieces of code where i know or don't know if it can be null and don't care about it XD
Enums should always compared by their identity. Its null safe and internally its compard like this anyways
lol. when is being null safe not a good thing?
scroll up
How far ^^ link plz
Generally you will never have null enums
If you have your API is flawed and you'd need to rethink it
If you use null as another state of an enum, why not just make another enum state?
yep, that's another reason why throwing an exception is better
how to fix this when trying to add an enchantment to block item?
'addEnchant(org.bukkit.enchantments.Enchantment, int, boolean)' in 'org.bukkit.inventory.meta.ItemMeta' cannot be applied to '(net.minecraft.server.v1_8_R3.Enchantment, int)'
line:
meta.addEnchant(Enchantment.ARROW_FIRE, 1);```
(i think this is starting to become more of a philosophical discussion and unrelated to this channel)
Ok so this has nothing to do with null safety being a bad thing. Throwing an exception means that your code just failed to cover all possibilities. Being null safe means that you handle those cases.
Null safety is always preferable. No exceptions as far as i know.
What I'm saying is that it's that you need to try very hard to get null enums, internal java API throws exceptions when trying to look up wrong enum states
using "==" is not always a "covering the case" thing though, it can just as likely be being ignorant to it
More often than not the application will run just fine being null safe
if the value being null is an invalid state of the program, the == operator will not do anything about it, instead of noticing that the state is invalid
i'm not saying "==" is bad or to never use it, i use it most of the times, but i think there are enough valid use cases for .equals
guys how can i make Fake packet?
Not for Enums
equals has its uses, they are just not for null or enum checks.
What does that even mean?
fake packets
How do you determine if a packet is "fake"
We do not know
packets but fake
use a pencil and copy a packet so you have a fake one?
yes
Fake as in "not sent to the client" or as in "sent to the client but not sent naturally"
I mean... you could just write a serializer that sends the client random bytes... the notchian client will most likely just throw them away. Thats pretty fake.
I'm sensing troll
That is an excellent explanation of your question, support will arrive soonโข๏ธ
use nsm code, e.g. ((CraftPlayer)player).getHandle().playerConnection.sendPacket(...)
you mean ((CraftPlayer)player).getHandle().playerConnection.sendFakePacket(...)
no no, the packet is fake, not the delivery system:
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new FakePacket(...))
But by sending it you are materialising it in a real packet, I don't get it
Silly, just use the fakePlayerConnection.
packets r real
Bogus. They are not.
yes
but how
im crashing servers with it!
ok
its new bypass
very good ๐
yes
one packet crash
a have my own engine
Fake Packet Engine
do you want it guys?
This is server support, not client support
Since fabric just killed itself, you need to ask forge support
I thought he tried to implement fake packet into a plugin
What happened to fabric? It felt like the next big mod hype.
Just some Drama and a new WIP fork
so I solved my problem
Did you send fake packets? Heard it helps
public class CreeperCommand implements CommandExecutor
{
private CreeperSpawn plugin;
public CreeperCommand(CreeperSpawn plugin)
{
this.plugin = plugin;
plugin.getCommand("creeperspawn").setExecutor(this);
}```
i didnt see the this in this.plugin = plugin;
lmao
fake packets??
Ignore it. But i would advise against letting commands and listeners register themselves.
Several.
- Use an enum for each effect with each entry having an abstract method that consumes a player.
- Use HashMap<String, Consumer<Player>> that applies effects to the player based on the given String
Ill give you an example for the enum
i dont think a consumer would be necessary since it's all the same code
oh sorry nvm its diff effects
i woudl just use a HashMap<String, PotionEffectType>
but a consumer would def work aswell
Thanks for help!
This is the abstract enum aproach.
public enum PlayerEffect {
NAUSEA() {
@Override
void apply(final Player player, final int duration, final int amplifier) {
player.sendMessage("You are now nauseous for " + duration / 20D + "s");
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, duration, amplifier));
}
},
SPEED() {
@Override
void apply(final Player player, final int duration, final int amplifier) {
player.sendMessage("You are now fast for " + duration / 20D + "s");
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, duration, amplifier));
}
};
abstract void apply(Player player, int duration, int amplifier);
public static PlayerEffect fromCommandInput(final String input) {
return PlayerEffect.valueOf(input.toUpperCase());
}
}
Then just use PlayerEffect.fromCommandInput(input).apply(player, 120, 1); Or something like that.
How could I listen for an event thats specified in the config?
like this
https://proxy.spigotmc.org/df1305638f3f0a9c14ac659a5bd8f551dac36759?url=https%3A%2F%2Fi.imgur.com%2FDFOrte0.png
Use a Map<UUID, Long> with the value being the unix timestamp (gotten from System.currentTimeMillis()) and check the time against
the current time when a player executes the command the next time
Oh thats is quite complicated. Might even have to use reflections.
okay, might not do it then lol
@lost matrix accept
thanks anyway
@lost matrix do u have a code for this?
I could write it in a second. But this is so fundamental that you should try and make it work yourself.
Bukkit.getPluginManager().registerEvent(BlockBreakEvent.class, new Listener() {}, EventPriority.NORMAL, (listener, event) -> {
// Do your thing here
}, this);```
okay i try it and you try it okay? ๐
though obviously you'd pull that class from reflection with Class.getByName()
or whatever that method is. I forget. it's 6am lol
forName
yeah that one
@lost matrix should i do the cooldown in the main?
I would def create a new class for that
I would use a HashMap for mapping. Yes.
What do you mean by "it"?
should i create a HashMap for the cooldown
?
private HashMap<UUID, Long> map = new HashMap<>();
so i created the Map now
and what should i do with it
@lost matrix
Yes. But this way you would have a global cooldown and couldnt distinguish between different commands.
Giving each cooldown a name. So basically Map<UUID, Map<String, Long>>
@lost matrix I have an error with this code IntelliJ doesn't know input what would i do?
sorry but idk how this works does anyone has a code for a cooldown for a command?
You can google it
no i find nothing
With this you essentially remove all the if cases and just pass args[1] as the input
This is what i just wrote. Didnt test and its not easy to understand for someone who just started.
public class CooldownManager {
private final Map<String, Long> cooldownDefinitions = new HashMap<>();
private final Map<UUID, Map<String, Long>> executionTimes = new HashMap<>();
public void defineCooldown(final String cooldownName, final long timeInMillis) {
this.cooldownDefinitions.put(cooldownName, timeInMillis);
}
public long getCooldownLeft(final UUID userID, final String cooldownName) {
final long lastExecution = this.executionTimes.computeIfAbsent(userID, id -> new HashMap<>()).getOrDefault(cooldownName, 0L);
final long definedCooldown = this.cooldownDefinitions.getOrDefault(cooldownName, 0L);
final long timePassed = System.currentTimeMillis() - lastExecution;
return definedCooldown - timePassed;
}
public boolean isCooldownRunning(final UUID userID, final String cooldownName) {
return this.getCooldownLeft(userID, cooldownName) > 0;
}
public void setExecution(final UUID userID, final String cooldownName) {
this.executionTimes.computeIfAbsent(userID, id -> new HashMap<>()).put(cooldownName, System.currentTimeMillis());
}
}
This is my final code:
https://paste.md-5.net/vuqeqesoki.java
@lost matrix will this work or it has a problem?
I'm gonna https://tryitands.ee/
Looks fine to me. But time and level still need to be parsed later on
but i have a problem with this
And you should check if o is null
input is just args[1]
Yes i forgot
And really try to prevent single character variables.
So player instead of p
and targetPlayer instead of o
Yes but It's save's more time if i have a single character
readable code is better than shorter
Doesnt matter. Its dirty coding and readable code is more valuable than all the initial time you spend because it
saves you time overall.
Okay
private void giveEffects(Player player, String[] args) {
Player target = Bukkit.getPlayer(args[0]);
final String input = args[1];
if (args.length <= 1) {
player.sendMessage(coloredChat.chat("&cUsage: /Effect (Player) (Effect) [Time] [Level]"));
return;
} else {
PotionEffects.fromCommandInput(input).apply(target, 120, 1);
}
player.sendMessage(coloredChat.chat("&8[&cErrors&8] &7Effect Mored Nazar Peyda Nashod!"));
}
Is it good now?
You need to check args.length <= 1 before you get the first element from your array.
Thats not a problem. But this line: final String input = args[1]; will throw an ArrayIndexOutOfBoundsException if
you dont check if the array even has enough elements.
Okay
but it already checks if args are less that 1
[1] needs a check of 2, and checked BEFORE you try to read it
But after you accessed the array.
Its like sitting down in the theatre and then checking if there is a chair where you just sat down
instead of first checking if a chair is at the point where you about to sit down.
Could you tell me how to check then?
Sorry if i'm wasting your time
What size does an array at least has to have if you wanted to access the index 10.
So with args[10] for example. What should the minimal length of this array be?
9?
of whole array?
you mean?
minimal is 0
Java starts at 0 am i right?
so minimal length should be 0
Nope.
Ok lets say we have an array defined like this:
int[] content = new int[3];
What is
A) The length of this array
B) The content of this array
A: 4
B: 0 - 1 - 2 - 3
got problem OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); this is not returning the players correct uuid but it does return players correct name any reason why ?
Is it correct?
No
What's wrong?
The right answer is
A) 3
B) {0, 0, 0}
Next question. What would the result of this code be:
public static void main(final String[] args) {
int[] content = new int[3];
int x = content[3];
System.out.println(x);
}
the syntax is new Object[length], where as length is the length of the array
can i make custom structures spawning from my plugins?
as in alot of plugins which gen custom terrian?
Sure
package index
hmm
ill wiat for a reply woth soem tut m a super rookie i know some java
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/world/ChunkPopulateEvent.html is probably the event you are looking for, but honestly there might be a better way to do it. Afaik the most vanilla way might be datapacks
Then you should not start with custom world generation. It is quite complex.
hmmi dontw anna use datapacks thats teh thiong
na i just want to gen some structuers
And that can be very complicated depending on how you want to achieve this.
They can be a pain to do
Someone know how to summun a totem revive effect with custom textures (if i can use custom model data will be the best) ?
Especially in code, most of the vanilla minecraft world gen is now handled in datapacks as far as I have heard
is there any place you recomend me to learn about plugins?
Spigot
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Or just watch videos
Hi, I'm having an issue where when I upload an update to a plugin in spigotmc.org it doesn't actually update. I have a test server and my plugin works. When I update the resource and then download it, plugin doesn't work. Why does this happen?
if(p.getWorld().getName() == "world")
why does this not work?
i want to check if the player is in the overworld
String compare uses .equals
oh okay
Never compare Strings by their identity. Use .equals() instead.
You should generally use .equals() for Objects and == only for primitives and enums
is their any solution or totorial for me to learn how to gen custom structures i justw anna do that?
You need to learn how world and chunk generation works. Its one of the sections that is not very well known/documented.
So you will have to do quite a bit of research.
hmm i saw tons of plugins which do it
and m interested in adding custom structures which vanilla neeeeeds
is there a way to change the spigot.yml file from the plugin
Sure. You can change all the files on the machine if the jvm has enough permissions for that.
ok thanks
This is pretty old but looks still usable:
https://bukkit.fandom.com/wiki/Developing_a_World_Generator_Plugin
https://bukkit.org/threads/adding-a-block-populator-to-default-chunk-generator.107298/
You really need advanced java experience. Its quite complex. Especially understanding how to use noise properly.
well, the basics will be the same
I mean... you can use a combination of the WorldEdit api and this event:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/world/ChunkPopulateEvent.html
For a quick solution. But thats not really strucuture generation but only randomly pasting schematics in.
Unless the structure is vanilla, then that will be a bit different
how can i refresh the block? My point is that when I do setType for example a fence it doesn't connect to adjacent blocks so I would like to refresh it to get those connections. I tried:
b.getState().update(true, true);``` but it doesn't work
I AM
SO SO SO ANGRY
3 apis, 2 utils and scoreboards aint working
got a util that WORKS
now
BUT
its static
and I didnt know before using it
ugh
aluminium > aluminum
up
Who says aluminum?
me
americans
I'm american but calling aluminium better is 1) half true and 2) starts arguments :D
im not
lol
pretty sure it's a few textures
the totem and a few particles
idk which
but i wanna use different textures depending on the custom model data
i saw a server doing this but can't find it again
Is there an event for when the player's inv gets updated in any way, be it click, pick up item, add item with plugin etc?
or will i have to manually check myself
Check
Im currently looking at the src code of CraftPlayer#playEffect and all that is passed is ony byte that determines the type of the effect.
Hmm, I have a plugin that syncs my inv between bungee servers and currently I'm saving to a db on PlayerQuitEvent, however it doesn't save fast enough so by the time the player joins the next server they will have pulled old data
so i conclude there is no way to use different texture on the particle effect except change the main texture of the totem ?
cant think of a better way of doing it atm
dont' switch the player while the save request is not save
Block in the AsyncPlayerPreLoginEvent until the data is fully persisted.
you can "lock" a player login ?
hmm theres not really a way of knowing whether the data has persisted between servers though
I was thinking literally just delay the loading of data by 1 second after join
https://wiki.vg/Protocol#Entity_Effect
This is the sent packet. I dont see any data that could be used for custom totem effects.
But i think i have done something like that with model ids...
but then that opens the door for duplication
Do you use bungeecord?
yep
model ids ?
PreparedStatement ps = plugin.MySQL.getConnection().prepareStatement("INSERT IGNORE INTO tokens" + " (NAME,UUID) VALUES(?,?)");
why this line is not working
Then just send a message via the plugin messaging channel, and add the user ID to a Set on your bungeecord.
Then send the player to the other server and keep him in the AsyncPlayerPreLoginEvent. Constantly ask bungeecord if the player is still in the Set (also using the plugin messaging channel) and just wait in a loop.
Then create a query on a new thread on the origin server that saves the data. As soon as the query is done you send a plugin message to the bungeecord that removes the player from the set, then loads the data (still in the async event) and lets him connect.
I think so.
what do you mean by model ?
3D model ?
something like that ?
I just set the model id of the ItemStack to another texture and it then showed its icon when the player died. But i cant quite remember if it worked like that. It was not intended but just a nice side effect.
okay i see thx for help
This might actually be a client side thing
PreparedStatements are a bit more special than that. The statement is first sent to the database without executing it, so the database can parse and compile it. Then, when you execute the statement, you bind the values (setString(1, "name");) to the parameters(?) and the database can execute the statement.
Whichever interface you're using probably won't allow you to emulate that procedure and requires you to immediately specify values.
and how can i make that to work?
what is the event for a player enter the end?
If you want to verify your query would work, replace the question marks with values while testing it. If it runs, you know you can put it into your code with the question marks.
paste in codeblocks pls
you could also use this if you mean enters the end through a portal https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html
declaration: package: org.bukkit.event.player, class: PlayerTeleportEvent, enum: TeleportCause
over 2000 lines :/
pastebin
Are you trying to get the scoreboard manager before your onEnable()??
So in your onLoad() or in a field like ScoreBoard board = Bukkit.getScoreboardManager...??
it worked before
plugin.MySQL.getConnection().prepareStatement("SELECT * FROM tokens WHERE UUID=" + uuid.toString()); something i can use
PreparedStatement ps = plugin.MySQL.getConnection().prepareStatement("SELECT * FROM `tokens` WHERE `UUID`=?");
ps.setString(1, uuid.toString());
You can't access things like the scoreboard manager before onEnable (post world)
https://www.youtube.com/watch?v=RlgfggheNAE&ab_channel=LoneDev found a plugin doing this
most bukkit related api methods shouldn't be accessed before onEnable is called
and how can i get the world teleported to
- You are using 1.8 which is an ancient version and unsuppoted
- You cant get the ScoreboardManager before Bukkit initialized it. So the onEnable is the first location you should ever call for the ScoreboardManager
Which event are you using?
guys, how do I contact with spigot forum support?
iam using the PlayerChangedWorldEvent
anyone aware of an event that allows me to get a Player's message after it is processed. AsyncPlayerChatEvent gives me the message and format, but not the processed message
@ornate heart PlayerChangedWorldEvent
I mean, realiably, no
lmaooo
that's great
Just get the player's world
player#getWorld
- I kinda have to use 1.8, its what consumers want
public void load() {
// commands
new ServerCommand(this).register();
// events
//
loadPlayer();
itemHandler.selectorManager.openSelectorEvent();
itemHandler.selectorManager.clickedSlot();
scoreboardHandler.makeScoreboard();
scoreboardHandler.updateScoreboard();
noWeather.noWeather();
itemHandler.storeItem.sendStoreLink();
itemHandler.giveItems();
itemHandler.onInvMove();
itemHandler.onDrop();
doubleJump.setFlight();
doubleJump.addVelocity();
doubleJump.keepDoubleJump();
noDamage.onDamage();
noDamage.solveWorldHunger();
build.blockPlace();
build.blockBreak();
yep trying to get the source code of it now
you can listen to the chat event on the monitor level, but, generally, if some plugin cancels the event and does it on its own you have no way to hook into that without hooking every chat plugin

