#How to prevent closing of a Inventory?
1 messages · Page 1 of 1 (latest)
Please name your thread more usefully next time
@onyx citrus This is the code from which the error is originating
Hmm as Vivian is very busy and his brain.exe going haywire Imma try it myself
and I think it could be because I set the name of the item to ""
I will try " " or "."
Please wait a second I am re adding the instance in another way
k
Yes I am checking it
Here take the code
should I post it as messag here?
or use hastebin or paste bin?
@onyx citrus
Also I used this way of adding instances
I used the third one in it
which was best rated
This is the code
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 {
public static Inventory inv;
public static Boolean trigger;
private setup mainClass;
public ResourcepackSelection(setup main) {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
load();
ItemPane();
this.mainClass = 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 = ItemPane();
inv.setItem(slot, item);
slot++;
} else {
trigger = true;
this.cancel();
}
}
}.runTaskTimer(mainClass,0,10);
}
private ItemStack ItemPane() {
ItemStack item = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(".");
item.setItemMeta(meta);
return item;
}
@Override
public Inventory getInventory() {
return inv;
}
}
looks the same, whats different
Also Vivian , if you have opened the thread in the parallel view then change it to full view by clicking on the three dots on the top right in the thread and select full view
So whats the error doing
what is it related to
why does it say Plugin cant be null
how do I fix it?
send me those lines
Basically its referring to The resourcepackSelection class
while I think its also referring to setup class
Just wait a moment I will re name all of the classes to match first letter upper case
Or wait more to let me create a completely new plugin'
just send me those lines
I just want to emphasize on this, the third one is best because it allows mock ability, it is less coupled because everything that depends on your plugin will become less coupled to your plugin instance thus adding reusability, flexibility and agility for the future. With that being said you should rarely pass your plugin instance to one of your other classes as it’s the highest level component/class/module of your application.
"Method 3" is what one I was telling you to use earlier.
So much cleaner
time set start this plugin and get the error again
@onyx citrus
Thats the error
so what does the plugin cannot be null mean?
These lines in the error
at data.ui.LoadingResourcepack.load(LoadingResourcepack.java:50) ~[?:?]
at data.ui.LoadingResourcepack.<init>(LoadingResourcepack.java:25) ~[?:?]
at data.main.Core.onEnable(Core.java:26) ~[?:?]
what is on line 50 of that
clearly state that its related to the loadingresourcepack class which is the gui class/trigger and the stup class
LoadingResourcepack.java:50
LoadingResourcepack.java:50
LoadingResourcepack.java:50
LoadingResourcepack
its right there
package data.ui;
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 data.main.Core;
public class LoadingResourcepack implements InventoryHolder {
public static Inventory inv;
public static Boolean trigger;
private Core mainClass;
public LoadingResourcepack(Core main) {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
load();
ItemPane();
this.mainClass = 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 = ItemPane();
inv.setItem(slot, item);
slot++;
} else {
trigger = true;
this.cancel();
}
}
}.runTaskTimer(mainClass,0,10);
}
private ItemStack ItemPane() {
ItemStack item = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(".");
item.setItemMeta(meta);
return item;
}
@Override
public Inventory getInventory() {
return inv;
}
}
Thats the full code
which one is line 50
Line 50: runTaskTimer(mainClass,0,10);
thanks
ok so
your "plugin" paramter is set to mainClass, so your reference to mainClass is null
which..it actually shouldnt be.
send your main class.
ah
ok
yep, i see the issue.
you're calling load() before assigning the mainClass variable.
so what should I do
public static Inventory inv;
public static Boolean trigger;
private Core core;
public LoadingResourcepack(Core core) {
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
load();
ItemPane();
this.core = core;
}
@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 = ItemPane();
inv.setItem(slot, item);
slot++;
} else {
trigger = true;
this.cancel();
}
}
}.runTaskTimer(core,0,10);
}
Thats the code atm
you're calling load() before assigning the mainClass variable.
OKAY
this is all you need to know to fix it
so before u get pissy
look where ur calling load()
and where ur assigning the mainClass variable.
im not gonna spoonfeed or ur not gonna learn.
load() thats the main method...
Assigning the mainclass variable..
should do I need to shift the methods up / down
When I am assigining it hmm
wait pls
public LoadingResourcepack(Core main) { // This is called before anything else in the class
inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
load(); // This is trying to call load() which is referencing...
ItemPane(); //|
this.mainClass = main; //<
}
look at the comments
the stuff with //
THIS
this.mainClass = main;
is assigned AFTER you're trying to use it with
load();
So basically I need to remove that load...
no, you need to move it to after the variable it uses is assigned.
Hmm should I add a scheduler?
no.
Hmm so do I need to move the code load() after the mainclass variable
YES.
Okay
Thanks the error is gone
I had another error before even though stuff worked find with it
fine*
nvm I guess the cleanup fixed it
okay new prob
aaa wait please again
@onyx citrus How to get title of a gui inventory In a inventoryclick event
Like in a old tutorial I used before I remembered he adding this to prevent dragging of items out of the gui
event.getClickedInventory().getTitle()
Not working
Oh wait
oh i was using wrong
Okay
Hmmm
in 1.17 did it change
cuz
gives no option
public void onClick(InventoryClickEvent e) {
String title = e.getView().getTitle();
int size = e.getInventory().getSize();
if (title == LoadingResourcepack.name || size == 9) {
Player p = (Player) e.getWhoClicked();
p.sendMessage("Test");
e.setCancelled(true);
}
}
@onyx citrus
Not workinggg
also tell me what does period mean in a runTaskTimer?
you need @EventHandler above the event.
Okaayyyy
Not okay to your @event handler as I just didnt include it in copy paste i gave to ya
Also Okay Now it workssss
also How to Make it so that if a specific type of inventory is closed before a certain if
Like I dont want the player to be able to close the gui till a certain boolean value is true
@onyx citrus
you'd have to cancel InventoryClose event
Ok so that event exists huzzzah
@onyx citrus
How to prevent it closing the ivnentory
It does not have a set cancelled boolean option
@EventHandler
public void onClose(InventoryCloseEvent e) {
String title = e.getView().getTitle();
int size = e.getInventory().getSize();
if(title == LoadingResourcepack.name || size == 9) {
if (LoadingResourcepack.trigger == false) {
}
}
}
Thats the event
and I need to put something similar to e.setcancelled(true) in the inner if statement
Ah. Right.
How to prevent closing of a Inventory?
You need to re-open the inventory if they try to close it.
why not
the variables will reset :(((
what variables
you might just be able to get the inventory that they close, then call open again on it.
I will try anyway............
@onyx citrus
If I set the runtasktimer to this
runTaskTimer(core,10L,20L);
what will be the psed
speed*
What does the L add
I saw it before in a scheduler tutorial
@onyx citrus
Heyyy
How to get the block player is left clicking on in the player interact event?
I was scrolling around in hypix and found that in the lobbies instead of cancelling the block break event they instead made it so that it will cancel the interact event which will stop right when player holds/left clicks on the block
Please tell how to get the block player is left clickinggg
I'm not home anymore.
Their lobbies are in adventure mode
Which stops you breaking blocks
@onyx citrus Imma just remove the resourcepack stuff..
Other than that tmr I need help making a thirst system
In which I have to use either variables or scoreboards
Gl
using scoreboards better?
are scoreboards saved always?
@onyx citrus
Are scoreboards saved after server stopped and restarts?
Scoreboards are not saved.
You don't have to ask it 48 times
I saw it the first time
Okay then do you know how to store certain data in numbers and uuid in data files?
Like how to make a yml/txt file to save data
which will auto load data from it everytime for every player
do you know?
..
why did you leave the thread! @onyx citrus
Stay in it dont close this thread or dont press leave button
sorry for ping
reply tmr or anytime ya want gn btw
see ya tmrr
I will share the plugin when I have completed it and also made a config