#help-development
1 messages · Page 1385 of 1
ok but why
because the method has e#getFrom so i'd imagine this method is called after they change
yes could be true
I'd just try it out. See what happens. If that doesn't work, then you may need another method
I was thinking of listening to the packet but that is EVERY message, and not just player messages, which isn't what I really want
and includes non global messages
Or you could use a BukkitRunnable to delay the checking of the world.
erm
It tells you where (Mysql.java line 43) and probably which error too, if you look all the way at the top.
you're calling getConnection inside of getConnection
can't be
obfuscation code...
have fun
if that's what line 43 is, that's not the code that is currently running in the JVM, try rebuilding
yep i'm going to there discord
how tf is this too many
scoreboard.setTitle(Hub.mainColour + Hub.serverName);
line1.setMessage(Hub.ambientColour + "--------------------");
rank.setMessage(Hub.mainColour + "Rank: " + Hub.secondColour + Hub.rankPlaceholder(player));
onlinePlayers.setMessage(Hub.mainColour + "Online Players: " + Hub.secondColour + playerCount(player));
line2.setMessage(Hub.ambientColour + "--------------------");
scoreboard.finish();
scoreboard.display(player);
It's too wide
Are you sure that the colors are not accounted for?
what?
The client is only sent the string
If the client was to know the name of the method it would be a serious security concern
So no
Have you strings smaller
the strings return like nothing
You sure "--------------------" is under 16 chars?
mind 2 chars might be taken by the color
oh
then its over
WTF
why is it so little
like I cant do anything
with this lttle
just slashed both the ---------------
lines
and im still getting it
@quiet ice
Trying #length() ing all the strings
is there any way I could store data after restarts? lets say I want to save a string, how would I do that?
store it
where?
which would be best for storing a lot of those strings?
well ints and strings
`can someone help me ? this code return player correct name but a totally wrong uuid. is there a better way to get uuid from an offline player (banned player on database) if (cmd.getName().equalsIgnoreCase("gunban") && player.hasPermission("geyseradmintools.gunban")) { String uname = args[0]; UUID target = Bukkit.getOfflinePlayer(uname).getUniqueId(); OfflinePlayer offplayer = Bukkit.getOfflinePlayer(target); System.out.println("this is the username: " + uname);
Just make sure you have Java 9+ though, Java 8 is aids for storing data
small descriptions of players, their discord and their rating (ex: 1/5, 2/5 and so on)
smth like a mysql?
ok
probs sql tho
obtaining players via names has always been shabby, also why are you obtaining the offline player twice? That is useless ops
copy that ty
np
DB is really overrated most of the time, I personally store everything to flatfile using bytebuffs and it works just fiine (until now)
ok
this is my current code. im not that good with java and msql so its being a pain especially msql. i think is possible to check with query if player name is in db and use that uuid to delete
hello, i have method which place block next to the wall when i clicked on this noteblock wall, but I would like to do that if you click with a box or something like that, it will turn towards the gamer, like normal minecraft offers. My code:
@EventHandler
public void onRightClick(PlayerInteractEvent e) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (e.getClickedBlock().getType() == Material.NOTE_BLOCK && e.getClickedBlock() != null) {
e.setCancelled(true);
Block b = e.getClickedBlock().getRelative(e.getBlockFace());
if (b == null || b.getType() == Material.AIR) {
if (e.getPlayer().getItemInHand().getType().isBlock()) {
b.setType(e.getPlayer().getItemInHand().getType());
}
}
}
}
}```
@quiet ice
What are the numbers?
those
I know, but what is the right and left one?
idk
oh
this
rank.setMessage(Hub.mainColour + "Rank: ".length() + Hub.secondColour + Hub.rankPlaceholder(player).length());
onlinePlayers.setMessage(Hub.mainColour + "Online Players: ".length() + Hub.secondColour + playerCount(player).length());
line2.setMessage(Hub.ambientColour + "-------------".length());
scoreboard.finish();
scoreboard.display(player);
see
yellow is first
white is second
might be easier to see
I guess you could make the online players and rank on a second line
Something like
key:
<value>
key2:
<value2>
I've seen a couple of servers do that, so unless you have many pairs it should be doable
yeah ik
ill do that then
guys, how do you typically name your config.yml keys? Like, is there a naming convention? Talking about "foo-bar: " vs "fooBar: " vs "foo_bar: " etc.
i know its not that important, just wondering
I either go for java code style so fooBarBaz or if its the first key FooBarBaz
all lowercase with dashes is my concention
But there is no convention
hmm
If you want inspiration then look into the spigot.yml
oh, good one
I am trying to get the UUID or name of a player async, but this will get me always null (if I ask the name, name = null, if I ask the UUID, UUID = null)
(line 106 / 126)
Hey, I have a litle problem with my code :
I created a method that write some lines into the config file of the plugin.
And when i look at the config file i seed this :
cosmetics-data:
827f8c48-cdb2-4105-af39-df5a64f93490:
HATS: &id001 []
BANDANAS: *id001
And there is my code :
public void addNewPlayer(Player player) {
List<String> blankCosmeticList = new ArrayList<String>();
System.out.println(blankCosmeticList);
for(CosmeticType cosmeticType : CosmeticType.values()) {
config.set("cosmetics-data." + player.getUniqueId().toString() + "." + cosmeticType, blankCosmeticList);
}
main.saveConfig();
return;
}
You can't set an full class in config, only (lists of) strings, ints and longs
all other classes have to implement ConfigurationSerializable
@maiden briar I dont understand... I am french and i dont understand everything lmao
Ask Elgar he is more clear
You must do as this interface requires https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/serialization/ConfigurationSerializable.html
Where I need to do that ?
In any class you want to store in your config
Because in my other plugin i made the same thing and it worked as expected
and it does not put *id001 in the config file before, and when i replace in my method the list by a classic string like "test" it works perfectly
yes, primitives are serializable. Complex objects are not
@thorny orchid You have to implement the ConfigurationSerializable Interface in any complex object you want to store
Ok but why it's working without in my other plugin, as i store list (of string) the same way ?
If I have a resource pack link, how do I generate the correct sha1 for it?
i'm going to try this thanks you
Make sure your serialized Byte[] has contents
@opal juniper i'm not sure, but if you don't have one you are not forced to type the sha1
You tried to implement Javas Serialiable
@opal juniper https://emn178.github.io/online-tools/sha1_checksum.html you can get it here if you want to put sha1 anyway
SHA1 online hash file checksum function
there shoudl be an sha1 method shaded in Spigot
how is chance called ? i need to have a 50% chance of something happening, if that doesn happen then you have a 30% of one thing and 20% of the other 2, and then a 10% 10% of the last two things happening
Hashing.sha1().hashString(string, StandardCharsets.UTF_8).toString()
👍
If I want to get content from the web async, I really can't return any value
https://paste.md-5.net/otudulawel.java The task handeling just works, but when I want to get the value I always get null
you use a Consumer to pass data back
If you are only gettign null then you are not parsing the Json correctly.
No it is working, I have printed both taskresults, and they al printed the correct uuid value (
@Override
public void done(TaskResult<String> result)
{
name = result.getValue();
System.out.println(name);
}
```)
@eternal oxide I implemented ConfigurationSerializable but what should I do now with the serialize method ?
The left side is the name in your config, the right side is the value
You have to implement as the Interface says, then register your class
ok I think i understand
Getting values async is impossible! Who knows the solution?
At what point do you get null?
At the 'getName' or 'getUUID' method
So after 'done' I set the field, but constantly get null if I get the field
Btw this was for Ch0ze
This is what you are looking for
I printed 'uuid' and 'result.getValue()' and noticed that 'uuid' is printed (null) before 'result.getValue()'
@eternal oxide ?
Then your getURLContent is probably falling through and returnign null
no stack trace?
Nope, I printed everything out
if i am making a plugin with multiple storage methods what are the main ones that people us
No strack trace
But when you debug in your done method the value returned is nuill
I will add comments to explain, a moment
How can i make HashMap work with MySQL?
@eternal oxide I just understand what's ConfigurationSerializable is, but it's not what i want to do with my configuration file.
I want to get all the content of my list<String> and put it into my config.yml
like this :
List<String> blankList = new ArrayList<String>();
blankList.add("foo");
blankList.add("bar");
config.set("something.test", blankList);
And the output :
something:
test:
- foo
- bar
Then your Json Parse is returnign null. Either the content you get from yoru URL is not as you expect or you are parsing it incorrectly
A string list can just be directly passed to the set method
I know
@eternal oxide https://paste.md-5.net/qopucujoqu.java
if it is just a List<String> you can getConfig().set("something.test", yourList)
to get it back you getConfig().getStringList("something.test")
Yes, I know, i've already made this in past but this time I see this as output : ```yaml
cosmetics-data:
827f8c48-cdb2-4105-af39-df5a64f93490:
HATS: &id001 []
BANDANAS: *id001
i see &id001 idk why
thats an object ID, which means its not "just a List<String>"
No, because the for was with Class class : classes (No String)
Do not forget to look
That is not the code thats producing that config entry
well
it is
Yes, it looks like it should work
And when i put a string it works perfectly i dont know what goes wrong, obv after i make a litle System.out.println and a see a normal blank list lmao []
Why don't you use in your for loop new ArrayList<String>
Or just toArray the list before saving
If it were me I'd not add the node if the list is empty
like creating a new array every time ? ok i'm going to try this
Good idea
i'm going to save everytime the loop do a loop also
well
that's working lmao
i don't understand, it's the same fu*** code
thanks to everyone lmao
btw, do you know how to make the server "believe" that this is the first time you have joined the server? What file should i delete ?
?paste
I am trying to track mobs and it works until you unload the chunk and load it again. This is my class https://paste.md-5.net/ixakehojuj.java
There is a file in the world which you can delete, I believe 'PlayerData.something'
im still getting null CommandException any reason why target == null aint working ?
try Bukkit.getPlayerExact(args[0]);
target == null is useless
Probably yoru player is null not target?
makes sense sike
Also, try using Java 15+, it has better NPE messages
true x)
What exactly are you doing
fake packets?
Don;t compare UUID with == as when the UUID is created on chunk load its not the same identity. Use compareTo
what is the event of on attack and what is the event of on get damage?
EntityDamageByEntityEvent
thx
Why not equals?
because the UUID objects will be identical but they will not be the same object. == will return false in that instance
They mean why not UUID#equals
oh you are saying why not use the equals method
You could use equals
or compareTo, just not ==
True
This is resource pack with remodelled totem effect
yep just found how they do
and yeah
im gonna make content just like this on my server
im really hyped to provide modded vanilla experience for players which they've never seen in my national minecraft server market
Just watched this stream of this guy doing spigot plugin development, this stuff is insane wtf https://i.kawaii.sh/OEoL40p.png
That is ALL vanilla
asked how it works, supposedly its an image generated on the server based on state and updated on click/event, sent back to the user too but its a whole ass gui
so maps
Yeah it just looks really cool though, that was the most eye catching thing though
He has a whole energy system and stuff too
honestly resource packs nowadays are powerful enough to replace most of the medium complexity content mods
yeah you could probably do that using a canvas and swing, or something simpler.
there's image API in java
you can draw images there too
question is how much computer power does it need to handle vast majority of players
to render the GUI for them
I mean supposedly he does it all async, it has a threadpool and tries to process tasks like that
updates and such
probably not much, you are only copying a canvas, relaying clicks and updating changes
probs uses raycast to detect which place of map was clicked
heck you could recreate computercraft mod with this
Would it be that difficult? afaik CC does this anyway
just send the canvas and process events differently
Converting to a map canvas isn;t that easy btu there is probably an api for that
this doesnt work for some reason java public void onEnderDragonDeath(EntityDeathEvent event){ if(event.getEntityType().equals(EntityType.ENDER_DRAGON)){ Bukkit.broadcastMessage(" "); Bukkit.broadcastMessage(" "); Bukkit.broadcastMessage("§8» §aThe Challenge has been completed §2§lsuccessfully§a."); Bukkit.broadcastMessage("§8» §7The §2§lEnderdragon §7has died."); Bukkit.broadcastMessage("§8» §e§oReset the World with§r §6/reset §e§o."); Bukkit.broadcastMessage("§8» §6The seed was §e" + Bukkit.getWorlds().get(0).getSeed()); Bukkit.broadcastMessage("§8» §6Time: §e" + Main.shortInteger(timer.getTime())); Bukkit.broadcastMessage(" "); Bukkit.broadcastMessage(" "); } }
lost connection: Internal Exception: java.lang.IllegalStateException: PlayerDropItemEvent may only be triggered synchronously. Anyone know how to fix this? Im setting item data through netty channel handler, ik its async, but for some reason while dragging it throws this shit. Even if i discard packet it still does this.
maybe because of .equals() ? Enums are singletons so you can do ==
I do, how does it work?
ill try that ty
im not sure actually
Just use equals
okay
anyone?
You can;t do it Async.
ik
You can’t do it ssync ye
Async
but i can't see why
The packet triggers the event
it wouldn't work
Because its not permitted
but i discard the packet
that doesnt work either :/
i discard the packet after it was catched by that handler
Spawn a new sync task to drop stuff
im trying to build Packet GUI
everything works
i synced the inventory with the server
but dragging vomits this error
i guess i fixed it actually
packet's slot got sent with -999 while dragging
which cause setting of item method be confused
that im dropping it or smth like that
Small question. What is the "Mot" (Vec3D) of an entity? What does this defines and what is it used for?
represents the velocity of the entity
it holds the same values as spigots Entity#getVelocity
So its used for moving an entity?
Is it possible to disable gravity for plants so they can stay where they were placed even if the block underneath them is missing?
No
Not gravity, but block updates
If they receive block updates, they will get broken. You will need to make sure they don't receive block updates
Oh, I see. I'm actually calling state.update manually https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/BlockState.html#update(boolean,boolean)
Guess I'll have to prioritize normal blocks before updating these.
so
file.addDefault("cooldown", 0);
file.options().copyDefaults(true);
saveConfig();
will create a default "cooldown", but if i edit it while the server is running, and reload the server the cooldown will be what i just set it to, but if i stop the server and start it back up, would the cooldown go back to 0 because of the saveConfig() or remain what i set it to?
because of what i saw here https://riptutorial.com/bukkit/example/23159/plugin-config-yml
bukkit documentation: Plugin Config.yml
To load the default configuration file to your plugin's folder, the following code must be added to your onEnable():
saveDefaultConfig()
make your config, it should already be in your resources folder, then add all the stuff you want inside
then call saveDefaultConfig when your plugin enables, and that's it
and if i edit it while the server is running, save it and reload the server the new data will be used
right?
and when i start the server the new data wont be erased
or replaced with the old one
yea
hey guys
I am making gambling crash plugin
gambling plugin
crash that is seen on roobet and other gambling sites
I need help with making algorithm for it
I am making crash plugin never have i seen a faster reputation loss in my life
word it different
done
its rly sounding like a malicious plugin
alr
good
lmao
rip
rep gone
You are wasting my time @onyx shale
hey guys
I am making gambling crash plugin
gambling plugin
crash that is seen on roobet and other gambling sites
I need help with making algorithm for it
yet hes still typing deciding to somehow waste his time,wut
NO idea what a "crash" is
being a dick makes us just wanna not help u
@eternal oxide have you heard for roobet?
no
basically it's gambling site
and
you will enter amount you want to gamble
For example $100
and there will be multiplier going up every second
1.1x
1.2x 1.3x 1.4x 1.5x
It will go up until it crashes
o
when it crashes you lose your money
essentially u pull out before you lose it all
nah
because ppl are risky
i mean isnt that just a simple random chance to crash? like not rly an algorithm needed
^
sometimes it may crash instantly sometimes after hours
just center it around a range so it doesn't instantly crash
Yep but I aint got any experience with something like this
How could I write this?
yeah, just use java random to generate a random int of when its going to crash
lol
I still don't know honestly
then you need to learn java basics
use the links above but with ur own numbers ex,every 2 minutes check a random chance,if its lower than 5(out of 100) crash
from there you can go as complex as you want with minimums and maximums crash chances
eq for 1.6x crash chance starts at 20
How do I detect if the player got xp?
hmm not sure you can go as deep as experience,seems spigot only has a event for levels
declaration: package: org.bukkit.event.player, class: PlayerLevelChangeEvent
my man had that jd ready
its on fast history as i used it alot in the past
I use paper jd 😂
same stuff beside theyr custom things
Should this work?
if (CrashGambling.getInstance().getConfig().getBoolean("neon") &&
neon) {
int neonmath = (int)(Math.random() * 1.0D + 0.0D);
if (neonmath == 0) {
crash = Math.random() * 90.0D + 10.0D;
crash = Math.round(crash * 100.0D) / 100.0D;
return crash;
}
crash = Math.random() * 4.98D + 3.01D;
crash = Math.round(crash * 100.0D) / 100.0D;
return crash;
}
crash = Math.random() * (top - 1.0D) + 1.0D;
crash = Math.round(crash * 100.0D) / 100.0D;
return crash;
}
}
?paste
also whyare you adding 0 lmao
is that a random multiplied by a double then casted to a int wut
also you never specify the range of the random
player.getWorld().spawnParticle(Particle.SOUL_FIRE_FLAME, player.getLocation(), 5, 1, 1, 1);``` Is there a way I can decrease the speed of these particles so they aren't super fast, just more slow.
That's why I asked for someone to help me write it
ur using the wrong random
Random.nextInt(100) will return a random number between 0 and 99,you can offset if you dont want 0 and do +1 after
Hmm
so... Random random = new Random();
why cant you get a random number and increase the current amount until it hits that number and then crashes?
that would be v simple
both work
not an int value
then yeah you could
How fast place block in version 1.12.2?
dang now i want to recode a casino plugin
do it make some fun games
have 4 kind of games on the last one
do yall sell premium resources?
a slot machine(inventory based),a roulette,a simple coin flip and a dice
not bothering selling any,i alrdy have a full job with uni beside,cant be bothered to offer 24/7 support
mostly are retired spigot devs
who kinda got a job in coding so they just stick around from time to time
I am one
how old r u
I would say 50% kids
15
Lollll
How fast place block in 1.12.2
I try use this https://www.spigotmc.org/threads/methods-for-changing-massive-amount-of-blocks-up-to-14m-blocks-s.395868/ but metod 2 and upper don't work
Well those are for 1.14
You'll have to convert all the NMS stuff to 1.12 methods and names
Obfuscation names?
maybe you know how I should change?
I don't use 1.12
Guys, quick question, https://wiki.vg/Protocol#Entity_Position_and_Rotation, what type it is Angle? The constructor of the packet accepts byte
Angle 1 A rotation angle in steps of 1/256 of a full turn Whether or not this is signed does not matter, since the resulting angles are the same.
Literally the first mention of "Angle" on the site
Oh i didn't look for it xD
what am i missign here? cant find it in the docs
i copied from here https://riptutorial.com/bukkit/example/23159/plugin-config-yml
bukkit documentation: Plugin Config.yml
but https://riptutorial.com/bukkit/example/23159/plugin-config-yml says its fine
bukkit documentation: Plugin Config.yml
- You have a field that should be final
- You leave a field undeclared
- You shadow a field
- You use an undeclared field in the implicit constructor by doing
plugin.getConfig()
but it's wrong
It's not even wrong, it's just not working
ah..
thats not good
But I recommend to use Dependency Injection (which you appear to do)
protected StarFight(JavaPlugin pluginInstance) {
plugin = pluginInstance;
}
Add this
Then instead of doing new StarFight() you can do new StarFight(this) (provided you do that in your plugin main)
whats this called?
that is the constructor
no nvm i can google that
since you mentioned it... what is dependency injection better at doing than the other traditional methods?
it's the tradtional method
Guice is 3 mb and i'm not sure it's that worth it 🤔
Don't do automated DI
How can I list everything in my config that has the definition true?
i mean beside the constructors or static singletons
Automated dependency injection is only good if you are doing API at a scale of bukkit without having to worry what the Constructor is
you can loop with config.getKeys(true), which wil return a set of keys, check each key
uhh what's the non-automated one? never knew they had types
That's passing the reference through the constructor
I call it dependency injection because everyone else calls it like that
like that?
yeah
would I do that with a for each?
guess it's a common mistake haha
yeah
Well, as far as I know "passing the reference through the constructor" does not have a really proper name, so I just stick with dependency injection until I find a better word for it
Issue is that the human factor can lead to people thinking that it is automated with tools such as guice
I was also confused by that when i worked with CDI frameworks for the first time. But dependency injection is both a design pattern and a container framework tool. Similar because CDI basically enforces the dependency injection pattern, but not the same.
It all comes down to how the "injection" is done.
Btw constructor injection > field/method injection
How can I check if player is facing up or down and have BlockFace returned to me?
I tried this:
BlockFace f = p.getFacing();```But this return anything other than north, east, west, south
How can I get the head height of a player
Player#getEyeHeight()
@left swift maybe use pitch?
You could use the pitch of the player. If its above ~50.0 then its down. If its below -50.0 its up
50? not 45?
I think 45 is a bit early for calling it up or down. But that arbitrary.
public BlockFace getExactFacing(final Player player) {
final float pitch = player.getEyeLocation().getPitch();
if (pitch > 50F) {
return BlockFace.DOWN;
} else if (pitch < -50F) {
return BlockFace.UP;
}
return player.getFacing();
}
how can i check itemstack's equality? equals seems to not work. I want to check if the itemstack would be stackable with item in cursor?
Use isSimilar
isSimilare
It ignores stack size
-.-
very thanks!
oh
If I took the block underneath the player, how would I loop through all blocks next to it?
Using Block#getRelative(x, y, z) and 3 for loops.
If you only want adjacent ones the you can also hard code all 6 cases of Block#getRelative(BlockFace)
Cheers
How can I make custom armor
Dyed leather usually
How custom do you want it?
You can't change the armor model without optifine
Change stats
- Attributes
- Add data using the PersistentDataContainer and listen for events then check the armor slots.
ok
public ItemStack setItem() {
ItemStack i = new ItemStack(Material.SKULL_ITEM, 1, (byte)3);
SkullMeta meta = (SkullMeta) i.getItemMeta();
assert meta != null;
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6Golden Head"));
StringBuilder surl = new StringBuilder();
surl.append(url);
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] data = Base64.getEncoder().encode(String.format("{textures:SKIN:{url:\"&s\"}}}", surl.toString()).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(data)));
try {
Field f = meta.getClass().getDeclaredField("profile");
f.setAccessible(true);
try {
f.set(meta, profile);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
i.setItemMeta(meta);
return i;
}```
this throws null point exception
what did i do wrong
Show the exception
Use Java 15+
What is line 48
The JVM will tell you directly what is null
a method that refers to this
should i save things like sethome locations and balance (economy) in files or in database?
to put it in a hashmap
Show the line pls
<ignore>
idealy make it configurable and support both
it will be an core plugin for our server
then use whatever, db is faster than IO but IO is faster to program
I would still write against an interface and then decide if you want to implement files or a db.
specialItems.put("GoldenHead", goldenHead.getItem());
I don't see setItem in there at all
This cant be generalized in this way
I'd just store it in flatfile that I load into memory at runtime
String url = "https://textures.minecraft.net/texture/3bb612eb495ede2c5ca5178d2d1ecf1ca5a255d25dfc3c254bc47f6848791d8";
private ItemStack goldenHead = setItem();
public ItemStack getItem() {
return goldenHead;
}```
Yeah, the setItem is really not relevant to your case
Initially flat files will be faster. Databases just scale better.
depends on the medium they're on i suppose
huh
Either specialItems or goldenHead is null
Java performs methods eagerly
but yeah, if you're expecting lots of reads/writes go with a db, since it does indeed scale better
So the setItem() is invoked way before you invoke your getItem call
oh i understand
And all of them have a memory cache which will really help if you hit it often.
for(int i = 0; i < plugin.getResources().CustomItemDatas().getConfigurationSection("Ranks." + r + ".itemNames").getKeys(false).size(); ++i){
String name = (String) plugin.getResources().CustomItemDatas().get("Ranks." + r + ".itemNames." + i );
if (CustomItems.spawnCustomItems()[i].getItemMeta().getDisplayName().equals(name)) {
System.out.print(CustomItems.spawnCustomItems()[i]);
player.getInventory().addItem(CustomItems.spawnCustomItems()[i]);
}
}
}
This is how I add an item to the players inventory, CustomItems.spawnCustomItems()[i] Is the array holding all the items, name item wanting to be given to the player. The system print.out gives the itemStack but the item is never added to the inventory. Why is this happening?
well if you do flatfile and load it into memory its also cached
Caffeine 😄
please define variables this is hard to look at
or use pastebin
also your method names are a bit weird, why is your method named spawnCustomItems when it doesnt actually spawn them but just gets/creates them and adds them to the inventory
anything above >10 lines of code on here is nasty to look at
not really its just that his method chaining is too long so it messes up in discord
I mean. Meh. I think the discord formatting is actually quite pretty for properly formatted code
i dont see why it wouldnt work tho
whats the type of the itemstack thats returned?
CustomItems.spawnCustomItems() returns a ItemStack[]
yeah ok but what material type
loop over its contents and see whats actually them
if they're air ofc its not gonna give anything
It is giving all custom items that i specified in my yaml
ill give the code of CustomItems.spawnCustomItems() as it will be a bit easier maybe.
It is basically a system of putting the custom items from my yaml to an array. I tested it and it was working before adding the items like i am doing
This is what the ItemStack returns
Scrap all of that. Didn't refresh the yaml with the new file contents 🤦
public static void setBlockInNativeChunkSection(World world, int x, int y, int z, int blockId, byte data) {
net.minecraft.server.v1_14_R1.World nmsWorld = ((CraftWorld) world).getHandle();
net.minecraft.server.v1_14_R1.Chunk nmsChunk = nmsWorld.getChunkAt(x >> 4, z >> 4);
IBlockData ibd = net.minecraft.server.v1_14_R1.Block.getByCombinedId(blockId + (data << 12));
ChunkSection cs = nmsChunk.getSections()[y >> 4];
if (cs == nmsChunk.a()) {
cs = new ChunkSection(y >> 4 << 4);
nmsChunk.getSections()[y >> 4] = cs;
}
cs.setType(x & 15, y & 15, z & 15, ibd);
}```
How I can translate this to 1.12.2?
Kind of a more java related question, but how many or statments can I have?
Is there a limit
infinitely, but at some point you should ask yourself if you should have more, rather than if you could have more
ok
Another question, i have made some custom recipes, how do I refer to thim in this code. Where it says != recipe How do i make recipe a custome recipe
You should not use this event for custom recipes but rather use the recipe API to properly register one.
I don't understand, is the recipe api a different event to listen for?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
k thx
I don't think u understand, i already made the recipe using the same method thjat u sent me or maybe i'm missing something. What this code trys to do is make is so that you have to have 2 items in a specific slot for the recipe to work. What I want to know, is if I already had my recipe made, what do i put in the if statement. Where it says event.getRecipe() != recipe I wanna know what to put in the recipe space to target a custom recipe I made
Oh i see. You need to identify the recipe by its NamespacedKey then.
ok
like this?
NamespacedKey.fromString is not a method. Are you on an ancient spigot version?
What version are you on
because i tried a different way and it autocorrected to that
1.16.5 minecraft version
I don't know how to check spigot version, I'm using intelij 😳
I think you can check your dependencies for the spigot version
Ok anyways. You need to compare the NamespacedKey of the current recipe with the one from your custom one using .equals()
so.equals("NAME SPACED KEY AS STRING")
No
ok....
Ill write an example... this is pretty basic java stuff
srry i'm being slow
Is the latest version of MangNecraft Server Drive better than the old version?
what
nvm, I think i figured out what u mean
public class SpigotCore extends JavaPlugin implements Listener {
private NamespacedKey recipeKey;
@Override
public void onEnable() {
this.recipeKey = new NamespacedKey(this, "some_recipe");
this.registerRecipe();
Bukkit.getPluginManager().registerEvents(this, this);
}
private void registerRecipe() {
final ItemStack result = new ItemStack(Material.IRON_AXE);
final ShapedRecipe recipe = new ShapedRecipe(this.recipeKey, result);
recipe.shape("isi", " s ", " s ");
recipe.setIngredient('i', Material.IRON_INGOT);
recipe.setIngredient('s', Material.STICK);
Bukkit.addRecipe(recipe);
}
@EventHandler
public void onCraft(final PrepareItemCraftEvent event) {
final Recipe recipe = event.getRecipe();
if (!(recipe instanceof Keyed)) {
return;
}
final NamespacedKey currentlyCraftedKey = ((Keyed) recipe).getKey();
if (!currentlyCraftedKey.equals(this.recipeKey)) {
return;
}
System.out.println("Your custom recipe was prepared.");
}
}
ok thanks
what is the best way to get someones location?
Player#getLocation()
ok thx
public static void setBlockInNativeChunkSection(World world, int x, int y, int z, int blockId, byte data) {
net.minecraft.server.v1_14_R1.World nmsWorld = ((CraftWorld) world).getHandle();
net.minecraft.server.v1_14_R1.Chunk nmsChunk = nmsWorld.getChunkAt(x >> 4, z >> 4);
IBlockData ibd = net.minecraft.server.v1_14_R1.Block.getByCombinedId(blockId + (data << 12));
ChunkSection cs = nmsChunk.getSections()[y >> 4];
if (cs == nmsChunk.a()) {
cs = new ChunkSection(y >> 4 << 4);
nmsChunk.getSections()[y >> 4] = cs;
}
cs.setType(x & 15, y & 15, z & 15, ibd);
}```
I find this code to fast modify chunk (fast setblock) but this on version 1.14 I need this on version 1.12.2 Who can help me?
Should be as easy as changing the imports to the 1.12 ones
yea I do this
but don't work
if (cs == chunk.a()) {
cs = new ChunkSection(y >> 4 << 4);
chunk.getSections()[y >> 4] = cs;
}```
Not sure if <1.13 had the chunks separated in sections already
yea XD he has
as well as understanding this piece of code, it forces an unloaded chunk to be loaded
Just tried building the 1.12 sources but BuildTools requires a java version below 11
So no help from me on this one.
god i hate old versions
Jeb gonna visit you for this
lol
Anyone having issue with VaultAPI repo? https://jitpack.io/net/milkbowl/vault/Vault/1.7.1/Vault-1.7.1.pom
Anyone aware of any libs that lets you saves schematics to mongo?
Thank you 👍
is it possible to make a dispenser dispense an item (not Dispenser#dispense)? ideally, something like the BlockProjectileSource#launchProjectile but for an item, maybe have it take in an ItemStack?
shoot out the item as if the item were inside
when a dispenser dispenses, the item comes out with a velocity out of a certain location
i want to replicate that
To?
replicate...
So u want the dispenser to throw the item or whatever multiple times?
as if the item is being dispensed from the dispenser, but it is not in the dispenser originally
I'm not that good at English but is it just me or isn't this confusing
Why is the ev red?
well it should tell you
it doesn;t hmm
Dispenser#getBlockProjectileSource() -> BlockProjectileSource#launchProjectile(Class<? extends T> projectile)
item isn't a projectile though
Oh you mean a dropper?
no, it's a dispenser
i want to launch an item as if it is coming out of the dispenser
Check the error page/tab
but it was never actually in the dispenser
And it must be bcz of the comment in side of a command
no, that is probably not why
Oh I see he has ev red
i would assume it's because he doesn't have the dependencies set up correctly
Maybe used this variable before
IDEs do this a lot
if you have a code error somewhere the IDE will think there's a whooole bunch of errors elsewhere
I found the nms method. But there is no way of doing that with the bukkit API unless you just spawn an ItemStack, give it a small velocity in the direction
the dispenser is facing and spawn some particles.
that's what i'm considering
BlockDispenseEvent already has getVelocity so that's nice
How do i get the player from this event?
How would i loop every block in a certain area ?
although this kinda sucks
3 for loops
get the inventory then get the viewer from that
ok
like one y, one x and one z ?
yep
With Block#getRelative(x, y, z) and 3 for loops
Is this it?
getView
event.getView().getPlayer()
ok
already using nms, why not use some more :P
Do I have to register the Namespacedkey?
Take a look at net.minecraft.server.v1_16_R3.DispenseBehaviorItem
Either create a new instance of it or use the static method DispenseBehaviorItem.a(...) and see what happens
then waht is this?
that sets the key to have the namespace of your plugin and the key to some_recipe, then calls the registerRecipe method, then registers event listeners
Does this kinda do the same thing (shovelI is the item variable)
dont do that
Sure. Just without having the NamespacedKey reference.
so will the other part of ur code work if i do it like that (srry for all the beginner questions)
Anyone know how to code in js ?
If you modify it for your key then sure.
i need help
k thx
- Ew. 2) Maybe.
huh ? x)
i don't find js that slow ngl
Nobody that is sane likes js. I literally know no one that writes js without the ts layer.
the only expeience i have in js is writing a very simple discord bot
i'm not that good though
We all start somewhere
what the hell is ISourceBlock supposed to be
lol
No idea. Follow the CraftDispenser class and find out how they get the ISourceBlock
they don't use the static function xD
Anything in js thats not in a method scope is global.
So literally write
var value = 100;
and its global
Show some code pls. If you define a variable in the root scope then its global.
events.on('playerRespawnEvent', event => {
event.getPlayer().getInventory().clear()
startShop.give(event.getPlayer())
let death = 0;
})```
i need the death variable to be global
which isn't there
var death;
events.on('playerRespawnEvent', event => {
event.getPlayer().getInventory().clear()
startShop.give(event.getPlayer())
death = 0;
})
How can I set a block to a fully grown wheat plant?
If you make a new namespaced key 2 times with the same string, is it a new instance or can it still be used to check against a different instance with the same string?
You need to get the BlockData of the Block and check if its Ageable. Then set the max age of Ageable and the BlockData back on the Block.
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/Ageable.html
declaration: package: org.bukkit.block.data, interface: Ageable
what is the easiest way to make a reload command? like /plguin reload
- Its a new instance
- You can compare .equals() on different instances. Only
==checks if two variables are the exact same instance.
ok, thx!
Properly implement onEnable() and onDisable(). Then you can just unload and load the plugin again with the PluginLoader
or
Make your plugin data driven and try to support dynamic loading/unloading
It all comes down to having a good design pattern. In most cases you dont want to support reloading a plugin.
I would just properly implement onEnable and onDisable
@lost matrix Would this work if my namespacedkey was axe?
No. You are comparing a NamespacedKey with a String. Those two are not even the same Object types.
ok, i just got confused because when i set it up i used quotes
so if how i set it up was "axe" then how would I comapre it?
Create new variables and then think about what you want to compare. What should be equal.
You want to compare the NamespacedKey of the recipe that is currently prepared with the NamespacedKey of your recipe. Then check if both those keys are equal.
Thats better
so is that right?
If your recipe was created using a NamespacedKey that looked like this then yes.
ok, thanks for all the help!
BlockData data = loopblock.getLocation().add(0,1,0).getBlock().getBlockData();
if (data instanceof Ageable) {
int age = ((Ageable) data).getMaximumAge();
((Ageable) data).setAge(age);
``` I tried it but the code it isn't working, no errors, and lines 3, and 4 are able to be ran, but just not working.
So a plugin opens a menu when the key F is pressed
How would I do this or map keys to events
public void setGrownWheat(final Location location, final int age) {
final Block block = location.getBlock();
block.setType(Material.WHEAT);
final BlockData data = block.getBlockData();
final Ageable ageable = (Ageable) data;
final int finalAge = Math.min(age, ageable.getMaximumAge());
ageable.setAge(finalAge);
block.setBlockData(data);
}
You cant check what keys are being pressed. You can only listen for events.
Somehow when i press the F key something happens in spigot
in the game
on a non modded client
The hands swap
declaration: package: org.bukkit.event.player, class: PlayerSwapHandItemsEvent
ah
Oh also so I wanted to start making my own NMS solution for multiline nametags, so basically i create an endermite, remove AI, make it invis, and mount the endermite on the player or vice versa?
Where does the armor stand come in this
It doesnt. Multilines are just done using different entities. But you should def make that packet based.
Sure. Just use packets instead of adding the entities to the world. NMS packets are probably simpler in this regard unless you know ProtocolLib quite well.
Isnt the issue that it has to send the packets to every player
Sure. But spigot does exactly this too
You cant. You can only set the result slot to null
oh, so doe s that mean that the player gets their stuff back?
?
There is no stuff consumed in this event. It is only fired when the recipe is prepared. So before it is crafted.
a better solution would be to remove the recipe
oh well duh!
so i basically send a nametag packet or the packets to a player when they join for every other player
or when the nametag changes i loop over everyone and send them a packet for the player?
is there an even that triggers when they take something out of a crafting table?
You need several packets for this.
So first a spawn packet then a metadata packet then a mount packet.
And all that for every line entity and every player. When you update a line then you rename the
entity and send a metadata packet of that renamed entity to every player.
InventoryClickEvent
I don't want to change the tab name and fake the users to the player
I want just for the tag to be different
Ok
You wanted multiple lines above a players head right?
there's CraftItemEvent, which is kinda weird
you can also use StatisticIncrementEvent for Statistic.CRAFT_ITEM and compare for material
Then just
A spawn packet, a metadata packet, a mount packet.
And if the name changes then another metadata packet
Is there NMS documentation anywhere on how to use that
No. nms is just mojangs source code.
right but there is no decipher documentation project for it?
if you ring mojang and ask really nicely then they might just help you
Also for some reason I cant add org.bukkit as a dependency
it only goes up to 1.15.1
cant access NMS rn
Does anyone know what the slot numbers for crafting tables are?
whats the phone number
I need to call them
I have something to discuss
214 114 69420
^
try it
The last didgets i gave u are literally 69420
I googled it and it doesent come out with anything
it's their hidden number
I made that up
my phone number is 61 234 532 694
it has 69
see
no
@unreal quartz do u know the slot numbers for crafting tables
yea
and the result slot is 9
yea
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
declaration: package: org.bukkit.event.inventory, class: InventoryClickEvent
k thx
How do you get the full error message from a spigot server console?
by copying it?
Nvmd
how do i check if the player has 3 arrows in his inv ?
do i have too loop through all the inv to check if he has 3 arrows ?
Inventory#containsAtLeast
player.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 3)
Does anyone know a good way to generate a dummy entity with specific metadata without it being spawned in the world?
How would I do a delay, like wait 10 seconds or something
Bukkit scheduler
package index
declaration: package: org.bukkit.scheduler, interface: BukkitScheduler
probably but why would you need that lol
Okay so it's stupidly specific
I want to make a custom death message for an artificial damage application source
and I figured if I could check if the dead player was killed by that entity, it would do the trick
I really don't want to make an expiring list or hashmap for this lol
I mean I probably should but if I can just instantiate an entity that'd probably work
Are you the one that's applying the damage?
With a plugin, yes
Then just show the message when that damage is lethal?
What would the code look like for a simple couple second delay using bukkit scheduler
Ah, that would work fine
Thanks
lol np
does anyone know how RecipeChoice.MaterialChoice works for planks for setIngredient
this is what i got so far
bpR.setIngredient('W', new RecipeChoice.MaterialChoice);
wasn't there something like .setIngredient ('W', Material.OAK_PLANKS);
theres documentation on it just no examples. and I have yet to understand spigot documentation fully
https://hub.spigotmc.org/javadocs/s...dient-char-org.bukkit.inventory.RecipeChoice-
https://hub.spigotmc.org/javadocs/s...e.html#MaterialChoice-org.bukkit.Material...-
https://hub.spigotmc.org/javadocs/s...ialChoice.html#MaterialChoice-java.util.List-
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Tag.html#PLANKS****
declaration: package: org.bukkit, interface: Tag
what are you trying to do
tryna set a recipe ingredient to all planks using materialchoice
new RecipeChoice.MaterialChoice(Material.OAK_PLANKS, Material.BIRCH_PLANKS, ...);
should work?
ill try it
if it was that easy imma smash my head into a table
in the meantime while i try any idea on how to use this tag? https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Tag.html#PLANKS****
declaration: package: org.bukkit, interface: Tag
Is there not a simple way to make the code wait a couple seconds?
it didnt work sadly
if (Tag.PLANKS.isTagged(itemStack))
//...
probably
ok, i have a problem my code runs everytime aplayer takes something out of a crafting table, I am trying to stop the player from being able to take things out of the crafting table if they don't have a specific item. Here are my attempts to stop it, the event i'm listening to is inventory click event, and it checks if they click on the output slot of a crafting table, the problem is that if you shift click you can steal the item faster then my plugin can stop you. any ideas on how to fix?
bpR.setIngredient('W', new RecipeChoice.MaterialChoice(Tag.PLANKS));
so like this?
?
?
if (!player.getInventory().containsAtLeast($item, $amount)) {
event.setCancelled(true);
}
isn't that what my code does
IT just doesn't do it fast enough
because if i shift click on the itim
it gives it to me before it gets canceled
ok
Hi, how could I get the view of the actual player inventory ?
(So I can use raw slot to change items)
No, you'd use it in something like a block place event. For example, you want to listen to people place wool, but don't want to bother checking every wool color.
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (Tag.WOOL.isTagged(event.getBlock().getType()))
event.getPlayer().sendMessage("You placed wool!");
}
Or, if someone knows how to change the crafting slots of the player inventory
how do i compile a jar file from github without any pom.xml?
also its from a paid plugin that said to compile the open source code if u cant pay
im also assuming this is legal
you set it up yourself I guess
Clone it using git then run the maven goals mvn clean install
In the folder of your pom
Actually, you could use gradle
It literally tells you how to compile it.
Clone the repo, go into the folder of the cloned repo and execute gradlew build there
didn't work, I can still shift click the item out of the crafting table
anyone wanna spoonfeed me a quick snippet of how to set a skull texture
Not skull owner, actual texture
texture.skull(yes);
Just made a thing for a new plugin yesterday. Ill gist the thing
ur a leg
https://gist.github.com/Flo0/de004e84d02191b056db7ca7f32e61cd
Sadly its done using my reflection wrapper class. So you need to either extract the reflection from there or use
it as is.
ok, i have a problem my code runs everytime aplayer takes something out of a crafting table, I am trying to stop the player from being able to take things out of the crafting table if they don't have a specific item. Here are my attempts to stop it, the event i'm listening to is inventory click event, and it checks if they click on the output slot of a crafting table, the problem is that if you shift click you can steal the item faster then my plugin can stop you. any ideas on how to fix?
tyvm ill check it
I would just set the result to null in the prepare event if they dont have a specific item to be honest.
so I just set the result to null in that if statment?
Is this the prepare event?
?paste
I dont think so. I just wouldnt tinker with the click event at all
does anyone have decent knowledge on vectors, im trying to launch an armor stand and based on the pitch/yaw it should move a certain distance
@lost matrix https://paste.md-5.net/vukonopewe.cs Here is code, goal of this is to stop them from being able to craft if they don't have enough EP (which is energy in my game)
and the reaso for that long clicked item statment is becsause it costs a specific number of energy points (EP) to do different things, so that checks for the tools @lost matrix
Number one:
boolean corrSlot = false;
switch (event.getSlot()){
case 0: {
corrSlot = true;
break;
}
}
Can be just
boolean corrSlot = event.getSlot() == 0;
ok
Fatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags -> [Help 1]
?paste
will this solve the shift click problem?]
- Your very long if statement with all the
||should be replaced with something else.
I would just use this at the start of my class and then call the isValidMaterial method instead of this huge if clause
private final EnumSet<Material> validMaterials = EnumSet.of(
Material.STONE_AXE,
Material.STONE_PICKAXE,
Material.STONE_SHOVEL,
Material.STONE_HOE,
Material.STONE_SWORD,
Material.WOODEN_SWORD
);
private boolean isValidMaterial(Material tMaterial) {
return this.validMaterials.contains(tMaterial);
}
I had a feeling that wasn't the best way to do it 😜
can someone PLEASE help me
Looks like your code might be malformed
god that's a long error
-e
332 lines of error
Are all of these things just to reduce the time it takes to do this so that it doesn't take that long for the plugin to stop the shift click or is this just u helping me be a less messy programmer?
Did you set your java version in the maven compiler plugin?
For now this is all just code cleanup. The performance is also better but thats not a concern.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
paste your pom pls
ok