#help-development
1 messages · Page 1702 of 1
idk im testing that
i dont think so
ok trying
nope
Didn't think so
i remember doing this tho
requiring 64 of an item
in 1.16
is it CraftItemEvent
PrepareItemCraftEvent
@EventHandler
public void onCraft(PrepareItemCraftEvent e) {
if (e.getInventory().getMatrix().length == 1) {
ItemStack wheat = e.getInventory().getMatrix()[0];
if (wheat.getType() == Material.WHEAT && wheat.getAmount() == 64) {
e.getInventory().setResult(new CustomItem(Material.WHEAT)
.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.setName("&aCompacted Wheat")
.addItemFlags(ItemFlag.HIDE_ENCHANTS).getItemStack());
}
}
}```
will that work
prob not
lmao
I generally go about setting the result to null when the condition is not met
wouldn't that eliminate other recipes tho
idk
That is why you check if the result is the item you want
could u give an example?
i'm a bit confused
If result = yourItem and matrix != what you want {
set result to null
}
ohh i see
@EventHandler
public void onCraft(PrepareItemCraftEvent e) {
if (e.getInventory().getMatrix().length == 1) {
ItemStack itemStack = e.getInventory().getMatrix()[0];
ItemStack wheat = new CustomItem(Material.WHEAT)
.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.setName("&aCompacted Wheat")
.addItemFlags(ItemFlag.HIDE_ENCHANTS).getItemStack();
if (itemStack.getType() == Material.WHEAT && itemStack.getAmount() == 64) {
e.getInventory().setResult(wheat);
} else if (e.getInventory().getResult() == wheat) {
e.getInventory().setResult(new ItemStack(Material.AIR));
}
}
}```
would this work
prob not
lmao
You will need to use the craftitemevent to handle that
listen to another event
ok
what do i do now
@EventHandler
public void onCraft(CraftItemEvent e) {
ItemStack compactedWheat = CustomItemManager.compactedWheat.getItemStack();
if (e.getInventory().getResult() != null) {
if (e.getInventory().getResult().equals(compactedWheat)) {
}
}
}```
Loop the matrix and remove extra items
@EventHandler
public void onCraft(CraftItemEvent e) {
ItemStack compactedWheat = CustomItemManager.compactedWheat.getItemStack();
ItemStack air = new ItemStack(Material.AIR);
if (e.getInventory().getResult() != null) {
if (e.getInventory().getResult().equals(compactedWheat)) {
ItemStack recipeItem = new ItemStack(Material.WHEAT, 64);
for (int i = 0; i < 9; i++) {
ItemStack stack = e.getInventory().getMatrix()[i];
if (stack.equals(recipeItem)) {
e.getInventory().getMatrix()[i] = air;
}
}
}
}
}```
this?
doesnt work lol
idk what to do
Learn to debug code
Set breakpoints, use System.out statements
print out if it got past the second conditional
i am currently doing that
good then
method not even being called
@EventHandler
public void onCraft(CraftItemEvent e) {
ItemStack compactedWheat = CustomItemManager.compactedWheat.getItemStack();
ItemStack air = new ItemStack(Material.AIR);
System.out.println("item crafted");```
i dont see "item crafted" in console
then solve the problem. What are the reasons why the method might not be called?
is this in the same class?
One second
I mean no the one event does not call the other
^
so i have to manually call the event?..
No
no idea what im doing at this point lol
It's called when the player crafts the item
so what do i do
About what
to make the event get called
Did you register it properly
yes lol
when this screen appears it doesn't trigger any resource pack event for some reason
the prepare event is in the same class
and the prepare works
I assume that is fully client side
yeah but doesn't make sense as every other resource pack event triggers something
any idea why the event isnt being called
i know for a fact it isnt
cuz it doesnt system.out "item craft"
oh
if i craft a normal item
the event is called
if i craft the special item
it doesnt
work
Is the special item added as a recipe
should it be?
Yes?
...
im literally done lol
i was told "just listen to the event" when trying to ask about the recipe
i took that as "use event instead of recipe"
oh alright
still has 126
but when i place it in inventory
it becomes 63
nvm
i made an issue already about this, they wont reply 😦
the client doesnt even send the proper resourcepack packet
it only sends SUCCESFUL or DECLINED
but nothing else
What else did it used to send
it does.
sorry i meant "ACCEPTED"
not "SUCCESFUL"
Basically it only sends whether the user accepted or declined the pack
Yes
but never anything about whether the resourcepack was failed to be applied or not
But this is a different screen
Yes, that occurs after you try to accept the pack
it signfies that the client failed to download or apply the pack
Ah so before it would tell you it failed
Hey, sooo... I'm trying to despawn my hologram (armorstand)
public void despawnHologram(Player player, Hologram hologram) {
int entityID = hologram.getEntityID();
int [] integerArray = {entityID};
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_DESTROY);
packet.getIntegers().write(0, integerArray.length);
packet.getIntegerArrays().write(0, integerArray);
protocolManager.broadcastServerPacket(packet);
}
I'm getting an error that No field with type int exists in PacketPlayOutEntityDestroy. The wiki.vg says that it's supposed to be an int, please help
https://i.gyazo.com/5ac260006ee98a8b9d417b1cb325b7ad.png
Note that the protocol documentation != what ProtocolLib expects
PL acts based on the fields in the actual packet class, the protocol documents how they're transmitted across the network
Because protocollib isn’t part of the spigot API
im searching for the normal packets
They aren’t part of the API either
so then...how am I supposed to know what they are and how to use them
Decompile the server code
Correct
nice.
Modding is third party, Mojang isn’t going to document it for you
Packets change each version and they're implementation details. We have no reason to document them
Do I decompile the server jar then?
Yes. Or browse the BuildTools directory as it's already decompiled there
Which folder/directory tree do I follow?
you can use https://github.com/dmulloy2/PacketWrapper but some may be outdated
That's just a reader though isnt it..? I need to know what fields to write to
setEntityIds( is the one
Yeah, I'm supplying an int[] as the second argument
its giving me an issue with my first
i believe the in[] is the only argument
ShapedRecipe r = new ShapedRecipe(NamespacedKey.minecraft("flint_shovel"), item);
r.shape(" F ",
" S ",
" S ");
r.setIngredient('F', Material.FLINT);
r.setIngredient('S', Material.STICK);
Bukkit.getServer().addRecipe(r);
``` That's the shaped recipe in which instead of the F ingredient as Flint how do I change it to another custom Item I made?
```java
public static ItemStack FlintShard() {
ItemStack item = new ItemStack(Material.FLINT, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§7Flint Shard");
// List<String> lore = new ArrayList<>();
// lore.add("§fExample Lore");
// meta.setLore(lore);
meta.setCustomModelData(1);
item.setItemMeta(meta);
flintshard = item;
return item;
}
``` Also this is my custom item atm and I already Initialized it
RecipeChoice.ExactChoice
My error: TRIGGER WARNING ||https://pastebin.com/raw/KmAmZWei ||
That's after getting rid of the int I was supplying, now im only supplying int[].
That scared me for a sec
...do i need to attach trigger warnings to errors now
apply pastebin links to your long code then homie, was longer than my error
No, it’s for setIngredient
Hmm well kay i just like dms better but nvm
So I found this
declaration: package: org.bukkit.inventory, interface: RecipeChoice, class: ExactChoice
Correct
can you tell where to put it in the ingridient?
r.setIngredient('F', Material.FLINT);
Like in it
Where the material is?
I give code above but its id is flintshard
I made it as public static ItemStack flintshard; and Initialized it in one of the methods in the same class
Oh wait I understood wrong
Oh okay a seconddd
..
r.setIngredient('F', RecipeChoice.ExactChoice);?
So..where are the packet classes located in the spigot jar? I see nothing about packets
r.setIngredient('F', new RecipeChoice.ExactChoice(flintshard));
Pretty much
You’ll have access to them if you are depending on the spigot jar or on spigot with a build tool
The server is running Spigot 1.17.
so the spigot is the server jar..
unless you mean the vanilla one?
Either
which jar u opening
does anyone know what symbol is used for colored vertical rectangles in minecraft? I've seen them on servers but this symbol 🟩(U+1F7E9) is the only thing close to what I'm looking for that i have found and the color doesn't show up.
Thanks
oh boi java [ERROR] .... Could not pass event PlayerRespawnEvent to RisingCore v1.0 java.util.NoSuchElementException: null at java.util.TreeMap.key(Unknown Source) ~[?:?] at java.util.TreeMap.firstKey(Unknown Source) ~[?:?] at com.risingcore.events.onDeathRespawn.onRespawn(onDeathRespawn.java:71) ~[?:?]
public Map<Double, String> unsorteddistance = new HashMap<>();
public TreeMap<Double, String> sorteddistance = new TreeMap<>(unsorteddistance);
@EventHandler
public void onRespawn(PlayerRespawnEvent e) {
for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
for (int i = 0; i < locationsData.getCustomConfig().getKeys(false).size(); i++) {
if (p.getWorld().getName().equals(locationsData.getCustomConfig().get(locationName + ".world"))){
unsorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
}
}
}
sorteddistance.putAll(unsorteddistance);
String locationName = sorteddistance.remove(sorteddistance.firstKey());
e.setRespawnLocation(locationsData.getCustomConfig().getLocation(locationName));
}
}```
why... :<
What is line 71
String locationName = sorteddistance.remove(sorteddistance.firstKey()); // error here
Why do you remove?
remove to get the key
*value
You don’t need to remove for that
... .get(key)
Also you shouldn’t be loading this on every respawn
coll
:?
How to add single type of custom item to a player inventory?
p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.FLINT, 1) });
This is the code for removing
The add would use p.getInventory().addItem(); ?
What is the format to put items in the additem one
what would i do lol i spend 3 days and still get this error...
Load it on startup
I want it to add one custom item
huh?
oh right
addItem
?jd
for inside the bracked
Just an itemstack iirc
bracket*
a se
p.getInventory().addItem(new ItemStack[] {new ItemStack(flintitems.flintshard)});
wait i can set the setspawn mid game, so i need to put it there lol
^
I thought you wanted to add 1
?help
selfrole Add or remove a selfrole from yourself.
cleanup Base command for deleting messages.
embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.
findcog Find which cog a command comes from.
names Show previous names and nicknames of a member.
userinfo Show information about a member.
listcases List cases for the specified member.
reason Specify a reason for a modlog case.
permissions Command permission management tools.
- you don’t need the array
will that work for adding one item?
- flintShard is already an itemstack
@sharp kelp
Remove:
p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
Add:
p.getInventory().addItem(new ItemStack(Material.FLINT, 1));
Just add that
Okay thanks
If you need to change the amount, .clone() it and setAmount 1
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerAction(PlayerInteractEvent e) {
Player p = e.getPlayer();
Material i = p.getItemInHand().getType();
Material b = e.getClickedBlock().getType();
if(i == Material.FLINT) {
if(b == Material.STONE || b == Material.COBBLESTONE || b == Material.DEEPSLATE || b == Material.END_STONE || b == Material.COBBLED_DEEPSLATE) {
if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
p.getInventory().removeItem(new ItemStack(new ItemStack(Material.FLINT, 1)));
p.getInventory().addItem(new ItemStack(new ItemStack(flintitems.flintshard)));
}
}
}
}
@young knoll Correct code?
Its meant to give player a flint shard and remove flint from his inventory if he left clicks a stone block with flint in hand
Check if they are even clicking a block or else it will throw and NPE
Player p = e.getPlayer();
Material i = p.getItemInHand().getType();
Material b = e.getClickedBlock().getType();
if(i == Material.FLINT) {
if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
if(b == Material.STONE || b == Material.COBBLESTONE || b == Material.DEEPSLATE || b == Material.END_STONE || b == Material.COBBLED_DEEPSLATE) {
p.getInventory().removeItem(new ItemStack(new ItemStack(Material.FLINT, 1)));
p.getInventory().addItem(new ItemStack(new ItemStack(flintitems.flintshard)));
}
}
}
is that correct?
Also what on earth is going on here ```
p.getInventory().addItem(new ItemStack(new ItemStack(flintitems.flintshard)));
Looks right
I made it check if a block is clicked first and then check which block
man .get(); dont do anything :l wait i want to get the value not the key :L
You are making an itemstack of an itemstack of an itemstack
You gotta pass the key to .get
...
Please read the javadocs for a map
where??
In the code I just sent
Sorry just read tree map. One sec
Surely your ide will yell at your about this
man this work so why didnt this work too?
ItemStack[] items = playerMap.remove(p.getUniqueId().toString());```
Player p = e.getPlayer();
Material i = p.getItemInHand().getType();
Material b = e.getClickedBlock().getType();
if(i == Material.FLINT) {
if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
if(b == Material.STONE || b == Material.COBBLESTONE || b == Material.DEEPSLATE || b == Material.END_STONE || b == Material.COBBLED_DEEPSLATE) {
p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
p.getInventory().addItem(new ItemStack(flintitems.flintshard));
}
}
}
*this work
@young knoll
or yapperyapps
is that correct?/
Yeah TreeMap has a .get(Key) method.
yes
All maps do
I’m going to wager a guess flintItems.flintShard is an itemstack
Yep.
You can’t make an itemstack using an itemstack
Your ide will tell you this is wrong
Listen to it
It shouldn’t if it’s already an itemstack
and if I use new ItemStack(Material.FLINT, 1) it doesnt give error
Okay so thanks
Not a material
I understood what you mean
The custom item is
and the one i removing the flint
Is not
so i need just p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
Mhm
No?
anyway exam time please halt the talk
yes man but i have no idea to use it
Give it the key
welp this is my key .-.
So assign it to a variable so you can use it later
You don’t even need a map for this honestly, just loop through all locations and keep track of the closest one
welp i have no idea how lol
Have a variable for the location and one for distance
Every time you find a closer one, update the two variables
At the end of the loop you will have the closest one stored in the variable
oh man i still cant process it
hmmmmmmmmmmm
let me try find something on the internet
welp
i think this is what you are talking about
for (String locationName : getCustomConfig.getKeys(false)) {
if (p.getWorld().getName().equals(getCustomConfig.get(locationName + ".world"))) {
double distance = p.getLocation().distanceSquared(getCustomConfig.getLocation(locationName));
}
}```
Wait, if i want to make things like a vehicle builder, and a thing that interacts with those vehicles. Wouldnt that be more of a framework rather than an API?
I have a question. When i made a installer with inno setup, can i publish it? Because auf yhe license.
Yes, it may be used completely free of charge, even when deploying commercial applications. However if you wish to show your appreciation and support its development you can make a donation.
(Note: "Completely free of charge" must not be confused with "completely free". Inno Setup is copyrighted software, not public domain software. There are some restrictions on distribution and use; see the LICENSE.TXT file for details.)```
nah man i still think hashmap is the best
for (String locationName : getCustomConfig.getKeys(false)) {
if (getCustomConfig.getString(locationName + ".world").equals(p.getWorld().getName())) {
unsorteddistance.put(p.getLocation().distanceSquared(getCustomConfig.getLocation(locationName)), locationName);
}
}
TreeMap<Double, String> sorteddistance = new TreeMap<>(unsorteddistance);
e.setRespawnLocation(getCustomConfig.getLocation((String) sorteddistance.values().toArray()[0]));```
hi im back
question
i did player.sendBlockChange(player.getLocation(), Bukkit.createBlockData(Material.COBBLESTONE);
works
but whenever someone right clicks it
it disappears
how do i prevent
Listen for the interact event and send the change again
Or use a packet listener to stop the change going out in the first place
how can i check to see if they are looking at a fake block?
Actually I don’t know if a packet would be fired for that
Is it replacing air or replacing another block
air
its fired
BACK
There you go then
@young knoll This correct?
p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
p.getInventory().addItem(flintitems.flintshard);
how do i check if they were looking at a fake block
do i add meta
no i cant
Keep track of the location
Looks to be
You can't easily. As soon as they interact the block will vanish. So yoru location may be of air already
also is checking if a block has metadata preformance costing
or checking if its data is instanceof ageable
Hence you have to track the location
Your item is null at that point
You try to use flintShard before you call the method that initializes flintShard
Fixed
Instead of messing some variables I copied the flint shard item meta info code to the other methods and made small variables
Which was more easier
wooo
finally its doneee
It works just Like I want it too
Now i gotta work on resourcepack soon
Code: ```java
protocolManager.addPacketListener(new PacketAdapter(cadiaCore, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
PacketContainer packet = event.getPacket();
Player player = event.getPlayer();
int interactEntityID = packet.getIntegers().read(0);
if(packet.getEntityUseActions().read(0) != EnumWrappers.EntityUseAction.ATTACK) {
Bukkit.broadcastMessage("test");
}
}
});
Error: https://pastebin.com/raw/mzxtgAza
com.comphenix.protocol.reflect.FieldAccessException: No field with type
hmm, had to change "read(0)" to "readSafely(0)". Apparently it doesnt like being unsafe.
well what is it?
this
bruh
if(packet.getEntityUseActions().read(0) != EnumWrappers.EntityUseAction.ATTACK) {
V
if(packet.getEntityUseActions().readSafely(0) != EnumWrappers.EntityUseAction.ATTACK) {
How to open a book when players joins and also use json in that book to run certain events/commands when clicked on text in the book
... do you know???
dont fucking ping random people
when replying smth it pings em
is using an itemstacks localized name for identifying an itemstack bad practise?
or should i stick to using PDCs
okay, thank you
i think i'll use the localized name, since its for buttons in a GUI
it can be dangerous!
it's easy to fake it, like with GUI
?
Little bug it's okay xD
https://i.gyazo.com/babaf48904be7ec75afb50fd1689c209.png ProtocolLib, any idea how to get rid of it..?
yes
Depending of his code
If he just test names, it could be unsafe
I think he should encapsulate his GUI Inventory, then check on it
You asking a question, I answer it then you cry
You the only one to blame
Stop asking questions
please just turn off ping
You should not depend on item names
when repöying
Or GUI names
Mute discord server, so you will have no problem anymore
Ty xD
lmao
anyone have other ideas for my message?
For some reason it only does it with this in the code
Bukkit.broadcastMessage(packet.getEntityUseActions().read(0).toString());
(which isn't working anyway...)
Would be nice if it actually had the placeholders replaced
Huh?
ahh
well, it's because of me trying to get the EntityUseActions
protocolManager.addPacketListener(new PacketAdapter(cadiaCore, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
PacketContainer packet = event.getPacket();
Player player = event.getPlayer();
int interactEntityID = packet.getIntegers().read(0);
if(packet.getEntityUseActions().readSafely(0) == EnumWrappers.EntityUseAction.INTERACT_AT) {
Bukkit.broadcastMessage("Test");
}
}
});
I'm trying to make it ONLY trigger when right clicking an entity, and only trigger once (only mainhand)
this is exactly what they use in a lot of Spigot threads and it works for them..
Doesn’t matter what you use as long as it’s from the plugin you depend or softdepend on
huh
if you have a stream and do .filter().findFirst() does it filter the whole thing and give out the first element or does it one by one and stop when find
Well, I got it working
if(packet.getEntityUseActions().readSafely(0) != EnumWrappers.EntityUseAction.ATTACK) {
Bukkit.broadcastMessage("Test");
}
This only triggers "Test" once, and only when right clicking my holograms so it'll do
I guess it filter the whole thing
i tested myself and it seems to just stop when it finds which is good
what is the event name when player kills a mob?
hi someone know how to execute code after a click inventory event ?
i need to execute my code after the player has clicked
but the event is trigger "before" the click event
?
Like:
Player1 his looking inventory of Player2
Player2 move an item in his inventory
So my code trigger and fire a refresh inventory of Player1
But the inventory of player2 have one action late whith the player1
Because the code is fire before the server do the clickEvent and not after
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class org.bukkit.entity.Entity (java.util.ArrayList is in module java.base of loader 'bootstrap'; org.bukkit.entity.Entity is in unnamed module of loader 'app')
I know whats wrong but idk how to fix it
Entity nearbyEnt = (Entity) e.getEntity().getNearbyEntities(5, 5, 5);
if(nearbyEnt instanceof LivingEntity)
{
double distance = e.getEntity().getLocation().distanceSquared(nearbyEnt.getLocation());
if(distance<0.5)
{
nearbyEnt.setVelocity(new Location(nearbyEnt.getWorld(), 0, 100, 0).toVector());
}
else
{
nearbyEnt.setVelocity(nearbyEnt.getLocation().subtract(e.getEntity().getLocation()).toVector().multiply(1 / distance));
}
}
This should be working but doesn't work
Entity nearbyEnt = (Entity) e.getEntity().getNearbyEntities(5, 5, 5);
This line is the problem
I defined the nearby entities as Entity nearbyEnt
respond to my question what's returning the method getNearbyEntites() ?
no no its not a method i have a condition above that line
th's not the question
here you make a wrong cast
the method is returning you this type of variable java.util.List<Entity>
and you try to cast it with (Entity)
see the problem ?
List<Entity> nearbyEnt = e.getEntity().getNearbyEntities(5, 5, 5);
I am thinking this can work but I want to return only Players from those nearby Entities
better, but you will need to adapte your code
instanceof
yeah i casted nearbyEnt with (Entity) everywhere I used it.
Not that
do you know what is a List in java ?
oh and thnx for instanceof i forgot about that
Don't cast things to certain datatypes when they could return multiple different things
an entity will not always be a player
no you can but don't cast a List of object
but a player will always be an entity.
you can cast each object of the list but not the list it self
if you cast a Zombie to (Player), you'll get errors.
but if you cast (Entity) to Player it should work, but wont get all methods for players
instanceof return you if you can cast it
Yeah i know
im tryna give hints not all the beans lol
yeah but he have some lesson to learn...
You can cast the list, just not to a specific type of its type parameter due to type erasure
What would be a way to debug where my own plugin makes server lag? I haven't touched any related code to the function timings paste points at for past week... and I have no idea which line of code causes the lag, I guess I do know which file (class) it is since timings paste told me ;_;
It gets a bit complex because I call lots of database and rest API calls around that class.. :/
I checked and rest API output is fine, lol
Can a MySQL query be getting stuck? if so I probably need to set a timeout or something?
Use a profiler like spark maybe
Anyways when it comes to database questions it should be done async
Does spark give more detail? not like it can see my source
Yeah but I thought timings paste was about same
Idk I found spark more helpful personally
Well anyways I am lagging up the onplayerjoin event, and some specific players get stuck and keepalive kicks them, lol
What are you doing in the join event?
A bit of everything... 😦 database calls, other plugin API calls
even rest API call
That’s bad
Sounds reasonable why your server hangs
yea
I mean from what I've seen, most profilers have the ability to find which calls take the most time.
Do it in AsyncPlayerPreLoginEvent (file loading, database calls or anything with IO)
mental pain
Yeah. but clearly something is clogged either way :c, I'll try spark now
Yeah, I'll check it out too, the async method
So I have completed the base of the gui class but I want to make it that the Black glass panes appear one by one every half second in the 9 slots of the gui and after the 9th slot has a black staiend pane it will send the resourcepack to the player
How can I make it? Is it possible using while () and for () ? with variables? anyone got a example code or tips?
@ivory sleet hI! you awake right?
someone??? I guess least people on this tim?
Hello I am trying to create database with SQLite but, I am getting the following error java.sql.SQLException: No suitable driver found for jdbc:sqlite:plugins/BedEffect/data/data.db
I'm probably just an idiot, but I'm trying to get the "Test" portion of my config
holos:
Test:
location: world, -337.9180889181425, 72.0, -446.26819453769014
owner: e42b60b0-c35a-462f-a2b4-b1a9980f399e
lines:
- '&cTest 1'
- '&cTest 2'
- '&cTest 3'
- '&cTest 4'
with ```java
for(String holoNames : getHoloConfig().getConfigurationSection("holos").getKeys(true)) {
String holoName = getHoloConfig().getString("holos" + "." + holoNames);
but I keep getting a long string for holoName instead of just "Test"
Change "getKeys(true)" to "getKeys(false)"
someone?
can u help me as well please?
I tried that, still getting MemorySection[path='holos.Test', root='YamlConfiguration']
bukkit runnable,has start value(slot 0) every X ticks set the new item,when starting value reached 8 do the texture pack
is not hard.. you just need to be creative how you do it
Okay so I use scheduler for timer?
I think you will need to use async (to stop thread for 0.5sc) and callback (to set glass panes)
Also I found this in a tutorial for scheduler but i dont get what this mans
BukkitTask task = new ExampleTask(this.plugin).runTaskLater(this.plugin, 20);
What does this do? smaller version of scheduler?
How do I use it then ??
its same as a scheduler
Can you show me the entire code pls ?
wait oh I get ittt
Okiii goodd
soo if I use multiple schedulers in my gui it should be fine right?
Oh yes you can, It will schedule a new task one second later (20 game ticks)
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.
new BukkitRunnable() {
int startingValue = 0;
@Override
public void run() {
if (startingValue==8){
//texture pack
this.cancel();
return;
}
inventory.setItem(startingValue,new ItemStack(Material.GLASS_PANE));
startingValue++;
}
}.runTaskTimer(this,0,10);
Hey, is there an event for players added to scoreboard ?
Ooo so this basically ends the program when its 8 Hmm
When the variable is 8 the program ends right?
end that loop
I don't really understand what's the problem, and that's not easy on phone sorry
How can I forward that ending to another event which gives the player the resourcepack
Yes you can do this
@onyx shale
you call your method there
Hmm okay good enough Hmm
declaration: package: org.bukkit.entity, interface: Player
In this at the end in the runtask timer
the 10 means?
ticks?
or seconds?
first number is delay, 2nd in period. always ticks.
period hmm
how often it runs.
how long to wait till it starts
and the delay is 0
Oh okay
And by period what does how often it runs means?
Uhm error here
It doesnt show any imports for it
Nvm fixed
what does period mean I dont get it
you are not passing the plugin instnace
this
the "this" needs the main
I added the (Plugin)
dont cast you need to pass the class extending JavaPlugin
how do I do that?
get the instance of your main class
AyUniz, I got it. I was way overthinking it.
typical
it's 6am and ive been up all night 😄 😭
@tardy delta I added it
private setup mainClass = setup.getPlugin(setup.class);
Its like this right?
nope
wait what
but my class name is In lower case
runTaskTimer(mainClass,0,10);
^^ thats how right?
private FirstClass firstClass;
public MySecondClass(FirstClass firstClass) {
this.firstClass = firstClass;
}
that wont work
this is the proper way.
dependency injection...
Hmm please wait a second
thats just the same
There are many ways though
that would go in the 2nd class, then in the main you'd do...
SecondClass secondClass = new SecondClass(this);
final it please..
there's a right way, and 40 hacky ways.
What?
last thing someone needs is to give it a value after
explain?
just use private final Main plugin = Main.getInstance(Main.class);
what I posted is the right way..
ok
mark the field as final so its always initialised once
making it final doesn't matter..but...thats interesting i guess
I need a getinstance class in the main class then 🙂
wrong quotee
sigh
i got my ass reamed for YEARS for doing that on the forums.
but you do you boo
https://www.spigotmc.org/wiki/using-dependency-injection/ seems examples are needed..
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I guess I dont make mine final cause I'm not dumb enough to try assigning it twice lol
private static setup instance;
@Override
public void onEnable() {
PluginManager event = getServer().getPluginManager();
event.registerEvents(new woodbreak(), (Plugin) this);
event.registerEvents(new makeshard(), (Plugin) this);
getCommand("customgive").setExecutor(new customgive());
flintitems.load();
instance = this;
}
@Override
public void onDisable() {
}
public static setup getInstance() {
return instance;
}
well you know what it does,others like this case might.. get ideeas
?
whered ya go
patience...
oKI
public static setup getInstance(Class<setup> class1) {
return instance;
}
If I dont add that Class<Setup> CLASS1 in that brackets it gives error
wut did u told mee ??
^
^
..give a look here before attempting,might give you an ideea https://www.spigotmc.org/wiki/using-dependency-injection/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
That passes an instance of the main into the second class so you can reference it in the second class.
private final Inventory inv;
private setup main;
public ResourcepackSelection() {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
init();
this.main = main;
}
@SuppressWarnings("unused")
private void init() {
ItemStack item;
List<String> lore = new ArrayList<>();
// lore.add("§7Example Lore");
new BukkitRunnable() {
int startingValue = 0;
@Override
public void run() {
if (startingValue==8){
//texture pack
this.cancel();
return;
}
inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
startingValue++;
}
}.runTaskTimer(main,0,10);
}
@carmine nacelle
is ResourcepackSelection the name of your secondary class? looks good in there.
wut this.main = main;
change
private setup main;
to
private final setup main;
to make Stellrow happy lol
actually yeah you're missing something.
the IDE will force her
to have it in the cosntructor
if its final,making it dumb proof
It doesn't fix anything...
Yep resourcepack selection Is the name
public ResourcepackSelection(Main main) {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
init();
this.main = main;
}
also wut to do in main
"main" would be whatever the name of your main class is.
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
I remember being told to hang myself by people on the forums when I was still new. 😄
I was being cursed like some people here are still doing in their minds
I need to learn java, which one is the best?
Now @carmine nacelle What to put in main class
where do you make an instance of the secondary from the main?
they usually all teach the same thing,you can even try youtube way up to you
SecondClass secondClass = new SecondClass(this);
this would go in your onEnable() in the main.
youtube way up to you
edited ofc.
Yes yes yes?
I mean this
surprised he didnt got booted by bot for spam
youtube way up to you
true
youtube bad for programming, I've had that stuck in my head since I started
yup
YouTube is great for programming tutorials, especially Spigot.
u dont have to keep mentioning me i have the chat open.
ka
Send your constructor in the second class
private final Inventory inv;
private setup main;
public ResourcepackSelection() {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
init();
this.main = main;
}
@SuppressWarnings("unused")
private void init() {
ItemStack item;
List<String> lore = new ArrayList<>();
// lore.add("§7Example Lore");
new BukkitRunnable() {
int startingValue = 0;
@Override
public void run() {
if (startingValue==8){
//texture pack
this.cancel();
return;
}
inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
startingValue++;
}
}.runTaskTimer(main,0,10);
}
Stellrow, any easy way to convert & back to § (proper spigot way, not just String#replace)? from my configs?
That translates the other way around, § to &, I need the opposite.
ChatColor.translatealternatecolorcodes('&', "§7Hmmm")
ok so...
public ResourcepackSelection() {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
init();
this.main = main;
}
This is called whenever a new instance of the class is created.
Thats for the symbol to &
ResourcepackSelection rs = new ResourcepackSelection(this);
This is passing in "this" (the main class) into the second class
afaik the symbols are avoided to not mess with configs
why this error then
i only use &
Because you're passing SOMETHING this into NOTHING ()
sooo wut do I do...
can someone give me a quick think out of making a morph plugin cause i think its easier with spigot cause. Its a lot of work with datapacks
Me too, but setting my hologram names from my config where I have &c, is just doing this lol https://i.gyazo.com/ecaeecb3a79aadd1c1cae870b9f7ed5e.png
are you passing them with ChatColor.translateAlternateColorCodes('&', toTranslate);
You need to add MainClass mainClass to your ResourcepackSelection()
I'm doing that to save them to config, but loading from config it loads the & anyway, and if I use the translate when loading, it doesn't do anything because it's already in the & format
private setup main;
public ResourcepackSelection() {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
init();
setup main;
this.main = main;
}
..
you still didn't do it
I added setup main; ...
wait you are saving translated color text to config?
public ResourcepackSelection() {
needs to be
public ResourcepackSelection(Main main) {
Worst case just make a utility method
That o?
have like Utils.translateS(string) and return the translated string
The run task timer? I set it right? or not?
@carmine nacelle
oh sry for ping**
List<String> holoLinesBefore = holograms.getHoloLines();
List<String> holoLinesAfter = new ArrayList<>();
for(String holoLinesFormatted : holoLinesBefore) {
holoLinesAfter.add(ChatColor.translateAlternateColorCodes('&', holoLinesFormatted));
}
``` doing that to save, then in my config..
```java
holos:
Test:
location: world, -337.9180889181425, 72.0, -446.26819453769014
owner: e42b60b0-c35a-462f-a2b4-b1a9980f399e
lines:
- '&cTest 1'
- '&cTest 2'
- '&cTest 3'
- '&cTest 4'
It's saving to config properly, just not loading it back with colors :p
For what?
the scheduler
That will run every half second
send the full code again of what you're trying to do
so the lines list is getHoloLines? if yes its rather strange that it doesnt do it
good enough it does what I wanted enough
Yeah, super weird
@carmine nacelle I want to ask one thing
After the scheduler
the value goes to 8
How can we detect when it goes to 8 and then trigger a event?
send the scheduler
new BukkitRunnable() {
int startingValue = 0;
@Override
public void run() {
if (startingValue==8){
//texture pack
this.cancel();
return;
}
inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
startingValue++;
}
}.runTaskTimer(main,0,10);
you don't need a return AND cancel, cancel will automatically return
surprised it isnt telling you that
just do
good enough
change ==8 to <8, then setitem and increment, else cancel
looks cleaner
new BukkitRunnable() {
int startingValue = 0;
@Override
public void run() {
if (startingValue < 8){
inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
startingValue++;
} else {
//texture pack
// Do other task
this.cancel();
}
}
}.runTaskTimer(main,0,10);
that looks cleaner 🤷♂️
yes
correct
after this if I first make a player join event
and then make it run this inventory event in a scheduler and also add a delay in scheduler of 4.5
and the scheduler runs it will send the resourcepack to player?
and it will run after the gui closes
you'd set the delay to 90 to run after 4.5s
try it
and I need to add same instance in the event class as well right?
I gtg rn tuition will come after this kay?
bye
Anyone know any simple UPnP libs? I've found WaifUPnP but it doesn't seem to work
just need to open/close ports on UPnP
Got it working, Stell.
List<String> holoLines = getHoloConfig().getStringList("holos" + "." + holoName + ".lines");
List<String> holoLinesFormatted = new ArrayList<>();
for(String holoLine : holoLines) {
holoLinesFormatted.add(ChatColor.translateAlternateColorCodes('&', holoLine));
}
Super weird having to do that.
Hey If in this gui class after the else statement if I add that when the starting value is finally 8 it will make a boolean variable true then I can pass that variable to the event class to run the event?
will that work? does the event check variables again and again as well? Like checking for the event action iteself
So, each time that your runnable runs, it runs EVERYTHING inside public void run()
public void run() {
if (startingValue < 8){
inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
startingValue++;
} else {
//texture pack
// Do other task
this.cancel();
}
}
This is run every half second.
oKAY OKAY
But in that code
if after the else statement
I first create a public static variable which I in the else statement I give it the value true
dont make it static
static means it cannot change
you can't update static variables
But static variables can be changed in the class itself
I using it in one area
wait
do you mean static variable can only be givenvalue once?
Oh okay
Okay then instead of static what else to use?
Bruh, yes?
FINAL variables are set once then can never be changed again
STATIC can be changed by every static member
😐
What else to use instead of static then
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
I sure hope that isnt directed at me bud lmao
Idk about pro lol
bruh
he's technically right but still being a dick about it
[ERROR] .... Could not pass event PlayerRespawnEvent to RisingCore v1.0
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.risingcore.events.onDeathRespawn.onRespawn(onDeathRespawn.java:68) ~[?:?]
this is so suck
public Map<Double, String> sorteddistance = new TreeMap<>();```
mans is lurking just to call ppl out
finals can only be stated at where you set the variable right?
man im getting ignore ...
@carmine nacelle Then instead of static what else to use?
Pretty much, yeah. You dont have to set finals right away but once you do thats the only time they can be set
Send the code in question
Your map is empty, you're trying to get the item at the first position of an empty map
Btw a clas which does have any data storage file with all variabls being saved
wont the variable data be gone anyway after the static variable gets a value and then the event is triggered which resets this gui class data anyway
static is fine in this case
wont be if the variables are saved somewhere however
for (double i =0; i<locationsData.getCustomConfig().getKeys(false).size(); i++)
sorteddistance.put(i, locationName);```
yeah i can read so im gonna use this to see if it actually because of the doubles can not put into the map
for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);``` this code dont even work man this is so suck
you need to change getKeys to true
send the whole code man
its hard to piece this together.
i just realized
whole code?
public class onDeathRespawn implements Listener {
public Map<String, ItemStack[]> playerMap = new HashMap<>();
public Map<Double, String> sorteddistance = new TreeMap<>();
RisingCore plugin;
LocationsData locationsData;
SoulData soulData;
public onDeathRespawn(RisingCore plugin, LocationsData locationsData, SoulData soulData) {
this.plugin = plugin;
this.locationsData = locationsData;
this.soulData = soulData;
}
@EventHandler
public void onRespawn(PlayerRespawnEvent e) {
// Spawn at nearest location
for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
}
}
System.out.print(sorteddistance.values().toArray()[0].toString());
sorteddistance.clear();
// Small Details
p.sendTitle(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("title.player.respawnevent")), ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("subtitle.player.respawnevent")), 20, 60, 20);
}
}
``` nothing really matters to this
send your config
i dont think so? i used commands to set the spawn
so nothing in the configs, and i did setspawn before i try to test out that code
you arent saving anything to config?
Firminus:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
What is "LocationsData"?
still getting the same error of the empty map?
could someone tell me, why this throws an class not initialized error, even though i have configured my pom.xml correctly?
before (yes) and after setspawn
Show me your entire confg.yml
custom?
Wherever you save the locations
locationsdata.yml and i already show u
gotta add
depend: [DependencyName] in plugin.yml
so that way the dependency loads before your plugin
your whole config is just that one location?
yea man i only set one, i dont think it will work even if i set 2 lol
Well, change getKeys to true for starters
@carmine nacelle
package srv.yassev.customitem.gui;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import srv.yassev.customitem.setup.setup;
public class ResourcepackSelection implements InventoryHolder {
private final Inventory inv;
private setup main;
public static Boolean trigger;
public ResourcepackSelection(setup main) {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
load();
this.main = main;
}
@SuppressWarnings("unused")
private void load() {
ItemStack item;
List<String> lore = new ArrayList<>();
// lore.add("§7Example Lore");
new BukkitRunnable() {
int slot = 0;
@Override
public void run() {
if (slot<8){
ItemStack item = createItem("", Material.BLACK_STAINED_GLASS_PANE);
inv.setItem(slot, item);
slot++;
} else {
trigger = true;
this.cancel();
}
}
}.runTaskTimer(main,0,10);
}
private ItemStack createItem(String name, Material m) {
ItemStack item = new ItemStack(m, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
return item;
}
@Override
public Inventory getInventory() {
return inv;
}
}
at the start of for loop?
what's the error
and tells to change the public Inventory getInventory() to public static Inventory getInventory()
man this isn't really cool lol, but ok
hold on theres more
for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
}
}
What is this supposed to be doing?
so:
i loop through all the locations in locationsData
right
VIVIAN
So, what I would recommend is structuring your config like..
locations:
Firminus:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
Firminus2:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
Answer me too
no locations:
i just save it without the locations:
VIAAAAAAAAAAVIAAAAAN
:< u ignore me
😦
😭
u should know my level of patience after helping me here and there atleast
wait a little bit, dont be that annoying lol
My brain broken
You need an instance of your class
wut?
You could structure it like above, or something like
locations:
- Firminus:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
- Firminus2:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
Or you know make it static
So that would be saving a list of your locations
My school classes got no instance and I think only teacher can add
Making static is error
which is better for referencing and such.
What error
oh man i already post it lol
Firminus:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: -46.29094
yaw: 9.873211
says surround with try and catch
That way you could do..
for (String locationName : locationsData.getCustomConfig().getConfigurationSection("locations").getKeys(true)) { // This line here
if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
}
}
if I do that then there is a chain of ERRORS
Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())
As far as I can tell, this isn't doing anything at all
huh
:?
You might want to learn a bit more Java
public class LocationsData {
RisingCore plugin;
private File customConfigFile;
private FileConfiguration customConfig;
public LocationsData(RisingCore plugin) {
this.plugin = plugin;
}
public FileConfiguration getCustomConfig() {
return this.customConfig;
}
public void createCustomConfig() {
customConfigFile = new File(plugin.getDataFolder(), "locations.yml");
if (!customConfigFile.exists()) {
plugin.saveResource("locations.yml", false);
}
customConfig = new YamlConfiguration();
try {
customConfig.load(customConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void saveCustomConfig() {
try {
customConfig.save(customConfigFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
nothing such
?paste
just some copy from the original wiki of spigot :madman:
here,
for (String locationName : locationsData.getCustomConfig().getConfigurationSection("locations").getKeys(true)) { // Would loop through "locations"
if (locationsData.getCustomConfig().getString(locationName + ".world").equals(p.getWorld().getName())) {
sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
}
}
this could work
So if you format your config like this:
locations:
Firminus:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
Firminus2:
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
I know you arent CURRENTLY, but you COULD
nothing actually change man, i mean i dont think adding another line of locations will work better than not having it lol
yes, structuring it, but i dont think it really matters
locations: // This is the configurationsection
Firminus: // Key
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
Firminus2: Key
==: org.bukkit.Location
world: world
x: -6.5
y: 70.0
z: -250.5
pitch: 0.0
yaw: 0.0
for (String locationName : locationsData.getCustomConfig().getConfigurationSection("locations").getKeys(true)) {
This would loop through all of the keys of the "locations"
that deep things actually is for loop through not only the key but the things in it too.
these things
Yeah, well dont you need that?
so you can try it with false then I guess, but
I changed your entire second line in that loop
if (locationsData.getCustomConfig().getString(locationName + ".world").equals(p.getWorld().getName())) {
way better than trying to compare with the Object class.
so actually nothing really change since the start? just add another configurationsection and nothing else? i dont think it will work. the second line i forgot to change back after testing
my brain hurts
for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
if (locationsData.getCustomConfig().getString(locationName + ".world").equals(p.getWorld().getName())) {
sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
}
}
since you're so dead set on the keeping the config how it is, here
I changed your comparison line and kept the top
try it like that
you already are
is it bleeding?
ok, but just for some notice
can I then make it explode
that's why i replace it with the Objects.replace
it's saying that because your config could be null
*equasl
if your config isnt null you're fine, but you could do a check before that
or just change it to == instead of equals
Okay so Now to get the inventory in another class Like my player join event class
I need to use the getInventory method in my code but as I was using a tutorial to make the gui it says that the get Inventory class needs to be static
idk if that would avoid the alert
oooooo