➽ ♛ Item Exchange GUI ♛ ✪

Discussion in 'Plugin Development' started by ProMCKingz, Sep 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ProMCKingz

    Hey!
    I was wondering how abouts I could go coding a part, in which when I click on an item in a different GUI, it will clone that and store it in a different GUI, and also save it, so when the user goes back on the GUI the item(s) are still there.
    Thanks,
    ProMCKingz

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  2. Offline

    AeroMC

    Don't bump every couple minutes... Only every 24 hours :)
     
  3. Offline

    Gerov

    ProMCKingz Well, it is possible, you'd just need to store the data somewhere if you wanted it to work after reloads and re starts.
     
  4. Offline

    ProMCKingz

    Gerov
    How can I do this?
     
  5. Offline

    Nateb1121

  6. Offline

    ProMCKingz

    Nateb1121
    How would I store the data in a config file?
    And how would I manipulate it into a form of data, and re use it for a new one for every person? Gerov
     
  7. Offline

    CraftCreeper6

    ProMCKingz
    Why don't you just use normal config.
    1) Save their UUID or name in a config and a list of items under it.
    2) Make your inventory & add the List of items from the config as ItemStacks
    3) Open the GUI for them.

    Before anyone asks "will this work". Yes, it will, I tried it before.
     
  8. Offline

    ProMCKingz

    CraftCreeper6
    How would I make it load?

    ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  9. Offline

    fireblast709

    ProMCKingz ItemStacks are ConfigurationSerializable, which means that the Config API is able to serialize and deserialize ItemStacks. Simply use set(path, stack) and stack = getItemStack(path).
     
  10. Offline

    ProMCKingz

    fireblast709
    Code:java
    1. SettingsManager settings = SettingsManager.getInstance();
    2. CompassPort CP = CompassPort.getInstance();
    3. SubHelmet plugin;
    4. public int BEACON;// This was moved
    5.  
    6. public HelmetClick() {
    7. }
    8.  
    9. @EventHandler
    10. public void onClick(InventoryClickEvent event) {
    11. HumanEntity entity = event.getWhoClicked();
    12. if ((entity instanceof Player)) {
    13. Player player = (Player) entity;
    14. if (event.getInventory().getName()
    15. .equals(SubHelmet.getHelmetInventory().getName())) {
    16. event.setCancelled(true);
    17. ItemStack clicked = event.getCurrentItem();
    18. Inventory MW = MyWardrobe.getMyInventory();
    19. if (clicked != null) {
    20. if (clicked.getType() == Material.DIAMOND_HELMET) {
    21. player.closeInventory();
    22. player.awardAchievement(Achievement.DIAMONDS_TO_YOU);
    23. CP.getConfig().set(player.getName(), clicked);
    24. player.sendMessage(ChatColor.GREEN + "Sucess! " + ChatColor.AQUA + "You have purchased a diamond helmet");

    Doesn't save anything more in the config.yml
     
  11. Offline

    fireblast709

    ProMCKingz I never see you call saveConfig(), so I am not surprised it doesn't save:p
     
  12. Offline

    ProMCKingz

  13. Offline

    CraftCreeper6

    ProMCKingz
    If your save config is in your onEnable then please rethink what you are doing.
    1) You're saving the config on start up...
    2) If you disable the plugin and the onEnable is saving the config when it re-enables, it's not going to do anything.

    Therefore, to be safe, in your onEnable create a repeating task that runs every x ticks and make it do saveConfig();
    That way, it is less intense on your server and you do not need to remember to put saveConfig(); at the end of everything you do to do with the config.
     
  14. Offline

    ProMCKingz

  15. Offline

    CraftCreeper6

    ProMCKingz
    Where are you saving your Config in your Main Class? In onEnable? A method?
     
  16. Offline

    ProMCKingz

    CraftCreeper6
    Like so,
    Code:java
    1. public class CompassPort extends JavaPlugin {
    2. FileConfiguration config;
    3. private static Location targetPoint = null;
    4.  
    5. @Override
    6. public void onEnable() {
    7. CompassPort.getTarget();
    8. String BukkitV = Bukkit.getBukkitVersion();
    9. getLogger().info("Wardrobe is currently running on" + BukkitV);
    10. getLogger()
    11. .warning(
    12. "Thanks for supporting this plugin, and keep supporting us, by downloading our new versions!");
    13. config = this.getConfig();
    14. getServer().getPluginManager().registerEvents(new InteractListener(),
    15. this);
    16. getServer().getPluginManager().registerEvents(new ClickListener(this),
    17. this);
    18. getServer().getPluginManager().registerEvents(new HelmetClick (), this);
    19. getServer().getPluginManager().registerEvents(new ChestplateClick (), this);
    20. getServer().getPluginManager().registerEvents(new LeggingClick (), this);
    21. getServer().getPluginManager().registerEvents(new BootClick (), this);
    22. getCommand("wardrobe").setExecutor(new ConsoleListener());
    23. getCommand("wardrobe").setExecutor(new Commands(this));
    24. getConfig().options().copyDefaults(true);
    25. saveDefaultConfig();
    26. SettingsManager.getInstance().data.options().copyDefaults(true);
    27. SettingsManager.getInstance().data.addDefault("LetsHopeThisWorks", 2);
    28. }
     
  17. Offline

    CraftCreeper6

    Your saving your config in your on enable, all this will do is save the config when the plugin first starts up, which is pointless. So like I said, save frequently with a scheduler or simply save everytime you edit the config

    EG you are doing getConfig.set
    What is the first thing you would do after that? Save the config.
    Save the config.
    Get my point? If not then type saveDefaultConfig(); after you edit the config, EVERY time.
     
  18. Offline

    ProMCKingz

    CraftCreeper6
    I get your point, I added a save config method, however it still doesn't save, updated code:
    Code:java
    1. @EventHandler
    2. public void onClick(InventoryClickEvent event) {
    3. HumanEntity entity = event.getWhoClicked();
    4. if ((entity instanceof Player)) {
    5. Player player = (Player) entity;
    6. if (event.getInventory().getName()
    7. .equals(SubHelmet.getHelmetInventory().getName())) {
    8. event.setCancelled(true);
    9. ItemStack clicked = event.getCurrentItem();
    10. Inventory MW = MyWardrobe.getMyInventory();
    11. if (clicked != null) {
    12. if (clicked.getType() == Material.DIAMOND_HELMET) {
    13. player.closeInventory();
    14. CP.getConfig().set(player.getName(), clicked);
    15. CP.saveConfig();

    Also when ever I click on the helmet it does not read the message "You have purchased a diamond helmet" anymore
     
  19. Offline

    CraftCreeper6

    ProMCKingz
    What is "CP"?
    Show me the class?
    By the way, rather than using that class, use your main class.

    Use this:
    Code:java
    1. private mainClass plugin;
    2. public yourClassName(Main instance)
    3. {
    4. this.plugin = instance;
    5. }


    Then use:
    Code:java
    1. plugin.getConfig().set(path, value);
    2. plugin.saveConfig();


    Edit: Many edits o.o
     
  20. Offline

    ProMCKingz

    CraftCreeper6
    I do, do that. CompassPort is my main class and that is my instance. Let me show you again:
    Code:java
    1. SettingsManager settings = SettingsManager.getInstance();
    2. CompassPort CP = CompassPort.getInstance();
    3. SubHelmet plugin;
    4. public int BEACON;// This was moved

    And my main class:
    Code:java
    1. public class CompassPort extends JavaPlugin {
     
  21. Offline

    CraftCreeper6

    ProMCKingz
    Sorry! Didn't realise CP was your main class!
    I still recommend you use:
    Code:java
    1. private mainClass plugin;
    2. public yourClassName(Main instance)
    3. {
    4. this.plugin = instance;
    5. }
     
  22. Offline

    ProMCKingz

    CraftCreeper6
    Its ok, I get errors when I do so. What do you mean by that? Can you re write it for my situation please. E.g yourclassname = HelmetClick
     
  23. Offline

    CraftCreeper6

    ProMCKingz
    Sorry, never used "getInstance" before, just thought it would not allow you to do certain things. I am not sure.

    You're editing & saving your config

    I am not sure what the issue could possibly be...

    timtower
    Uh.
     
  24. Offline

    timtower Moderator Moderator

  25. Offline

    ProMCKingz

  26. Offline

    timtower Moderator Moderator

    Well, tldr version?
     
  27. Offline

    ProMCKingz

  28. Offline

    timtower Moderator Moderator

    Too Long Didn't Read
     
  29. Offline

    ProMCKingz

  30. Offline

    timtower Moderator Moderator

    The thread.
    That doesn't give everything you tried already.
     
Thread Status:
Not open for further replies.

Share This Page