diff --git a/src/com/massivecraft/massivecore/SoundEffect.java b/src/com/massivecraft/massivecore/SoundEffect.java index eeb12fa9..b802d475 100644 --- a/src/com/massivecraft/massivecore/SoundEffect.java +++ b/src/com/massivecraft/massivecore/SoundEffect.java @@ -28,10 +28,7 @@ public final class SoundEffect implements Serializable @EditorType(TypeSoundId.class) private final String soundId; public String getSoundId() { return this.soundId; } - public Sound getSound() - { - return TypeSound.valueOf(this.getSoundId()); - } + public Sound getSound() { return TypeSound.valueOf(this.getSoundId()); } private final float volume; public float getVolume() { return this.volume; } diff --git a/src/com/massivecraft/massivecore/chestgui/ChestGui.java b/src/com/massivecraft/massivecore/chestgui/ChestGui.java index 14bd43f3..82c44e09 100644 --- a/src/com/massivecraft/massivecore/chestgui/ChestGui.java +++ b/src/com/massivecraft/massivecore/chestgui/ChestGui.java @@ -17,7 +17,7 @@ public class ChestGui // REGISTRY // -------------------------------------------- // - private static final Map inventoryToGui = new MassiveMap(); + private static final Map inventoryToGui = new MassiveMap<>(); public static Map getInventoryToGui() { return inventoryToGui; } public static ChestGui remove(Inventory inventory) { return inventoryToGui.remove(inventory); } public static ChestGui set(Inventory inventory, ChestGui gui) { return inventoryToGui.put(inventory, gui); } @@ -34,6 +34,11 @@ public class ChestGui // -------------------------------------------- // // ACTIONS // -------------------------------------------- // + // Actions are assigned to indexes in the inventory. + // This means the system does not care about what item is in the slot. + // It just cares about which slot it is. + // One could have imagined an approach where we looked at the item instead. + // That is however not feasible since the Bukkit ItemStack equals method is not reliable. private Map indexToAction = new MassiveMap(); public Map getIndexToAction() { return this.indexToAction; } @@ -45,6 +50,8 @@ public class ChestGui // -------------------------------------------- // // LAST ACTION // -------------------------------------------- // + // The last executed action is stored here. + // This can for example be useful in the inventory close task. private ChestAction lastAction = null; public ChestAction getLastAction() { return this.lastAction; } @@ -53,6 +60,8 @@ public class ChestGui // -------------------------------------------- // // META DATA // -------------------------------------------- // + // Store your arbitrary stuff here. Might come in handy in the future. + // I don't think we are currently using this ourselves. private final Map meta = new MassiveMap<>(); public Map getMeta() { return this.meta; } @@ -60,6 +69,9 @@ public class ChestGui // -------------------------------------------- // // RUNNABLES // -------------------------------------------- // + // Runnables to be executed after certain events. + // They are all delayed with one (or is it zero) ticks. + // This way we don't bug out if you open a new GUI after close. private final List runnablesOpen = new MassiveList<>(); public List getRunnablesOpen() { return this.runnablesOpen; } @@ -70,11 +82,22 @@ public class ChestGui // -------------------------------------------- // // SOUND // -------------------------------------------- // + // The click sound you should hear when clicking an action slot. + // You can disable it by setting null. private SoundEffect soundEffect = MassiveCoreMConf.get().clickSound; public SoundEffect getSoundEffect() { return this.soundEffect; } public ChestGui setSoundEffect(SoundEffect soundEffect) { this.soundEffect = soundEffect; return this; } + // -------------------------------------------- // + // AUTOCLOSING + // -------------------------------------------- // + // Should the GUI be automatically closed upon clicking an action? + + private boolean autoclosing = true; + public boolean isAutoclosing() { return this.autoclosing; } + public ChestGui setAutoclosing(boolean autoclosing) { this.autoclosing = autoclosing; return this; } + // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java index d18ec51a..1538eac3 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java @@ -9,6 +9,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.inventory.Inventory; import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.SoundEffect; import com.massivecraft.massivecore.chestgui.ChestAction; import com.massivecraft.massivecore.chestgui.ChestGui; import com.massivecraft.massivecore.mixin.MixinMessage; @@ -60,10 +61,11 @@ public class EngineMassiveCoreChestGui extends Engine gui.setLastAction(action); // ... then play the sound ... - gui.getSoundEffect().run(event.getWhoClicked()); + SoundEffect soundEffect = gui.getSoundEffect(); + if (soundEffect != null) soundEffect.run(event.getWhoClicked()); // ... close the GUI ... - event.getView().close(); + if (gui.isAutoclosing()) event.getView().close(); // ... and use that action. action.onClick(event);