PLUGIN HELP NEEDED - GUI SAVING

Status
This thread has been locked.

Jetterman

Premium
Feedback score
0
Posts
73
Reactions
34
Resources
0
I am trying to make it so when I put an item into this gui it will be saved. Can someone tell me what I need to make it save when closed.

Code:
package com.etterman.crdonate;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class CRdonate extends JavaPlugin implements Listener {
   
    public void onEnable() {
        System.out.println("Turning on...");
       
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        return true;
    }
   
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e){
        Player p = e.getPlayer();
        ItemStack item = p.getItemInHand();
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(item.getType() == Material.DIRT){
                Inventory inv = Bukkit.createInventory(null, 9 * 2, ChatColor.ITALIC + "Donations");
               
                p.openInventory(inv);
            }
        }
    }
}
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Skionz

ogminecraft.com
Premium
Feedback score
1
Posts
1,544
Reactions
1,527
Resources
0
I am trying to make it so when I put an item into this gui it will be saved. Can someone tell me what I need to make it save when closed.

Code:
package com.etterman.crdonate;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class CRdonate extends JavaPlugin implements Listener {
  
    public void onEnable() {
        System.out.println("Turning on...");
      
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        return true;
    }
  
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e){
        Player p = e.getPlayer();
        ItemStack item = p.getItemInHand();
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(item.getType() == Material.DIRT){
                Inventory inv = Bukkit.createInventory(null, 9 * 2, ChatColor.ITALIC + "Donations");
              
                p.openInventory(inv);
            }
        }
    }
}
Save the inventory in a field instead of creating a new one every time.
 

MJack

Feedback score
1
Posts
88
Reactions
18
Resources
0
Code:
public class CRdonate extends JavaPlugin implements Listener {
  

  Inventory inv;
    public void onEnable() {
        System.out.println("Turning on...");
      
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(this, this);
       inv = Bukkit.createInventory(null, 9 * 2, ChatColor.ITALIC + "Donations");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        return true;
    }
  
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e){
        Player p = e.getPlayer();
        ItemStack item = p.getItemInHand();
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(item.getType() == Material.DIRT){
                p.openInventory(inv);
            }
        }
    }
}
Try this instead.
We'll make the inventory once, in the onEnable rather than recreating it each time.
 

Jetterman

Premium
Feedback score
0
Posts
73
Reactions
34
Resources
0
Code:
public class CRdonate extends JavaPlugin implements Listener {
 

  Inventory inv;
    public void onEnable() {
        System.out.println("Turning on...");
     
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(this, this);
       inv = Bukkit.createInventory(null, 9 * 2, ChatColor.ITALIC + "Donations");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        return true;
    }
 
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e){
        Player p = e.getPlayer();
        ItemStack item = p.getItemInHand();
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(item.getType() == Material.DIRT){
                p.openInventory(inv);
            }
        }
    }
}
Try this instead.
We'll make the inventory once, in the onEnable rather than recreating it each time.
Thx worked.
 

Shattered

old-timer
Supreme
Feedback score
5
Posts
3,486
Reactions
2,059
Resources
0
If you want it to save on a server restart you will have to make a config or something to store it in.
 

Skionz

ogminecraft.com
Premium
Feedback score
1
Posts
1,544
Reactions
1,527
Resources
0
Code:
public class CRdonate extends JavaPlugin implements Listener {
 

  Inventory inv;
    public void onEnable() {
        System.out.println("Turning on...");
     
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(this, this);
       inv = Bukkit.createInventory(null, 9 * 2, ChatColor.ITALIC + "Donations");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        return true;
    }
 
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e){
        Player p = e.getPlayer();
        ItemStack item = p.getItemInHand();
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(item.getType() == Material.DIRT){
                p.openInventory(inv);
            }
        }
    }
}
Try this instead.
We'll make the inventory once, in the onEnable rather than recreating it each time.
If you're going to spoon-feed at least write quality code.
 

MJack

Feedback score
1
Posts
88
Reactions
18
Resources
0
If you're going to spoon-feed at least write quality code.
Sorry, was just trying to do it quickly.
In the future I won't just give it to them :p
 
Status
This thread has been locked.
Top