2019-10-17 16:04:43 -06:00
|
|
|
package dev.esophose.playerparticles.gui;
|
2018-11-04 04:03:54 -07:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.PlayerParticles;
|
2019-10-17 16:04:43 -06:00
|
|
|
import dev.esophose.playerparticles.manager.DataManager;
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.manager.GuiManager;
|
2019-10-17 16:04:43 -06:00
|
|
|
import dev.esophose.playerparticles.manager.LangManager;
|
|
|
|
import dev.esophose.playerparticles.manager.LangManager.Lang;
|
|
|
|
import dev.esophose.playerparticles.manager.ParticleGroupPresetManager;
|
|
|
|
import dev.esophose.playerparticles.manager.SettingManager.GuiIcon;
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.manager.SettingManager.Setting;
|
2019-10-17 16:04:43 -06:00
|
|
|
import dev.esophose.playerparticles.particles.PPlayer;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticleGroup;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticleGroupPreset;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
|
|
|
import dev.esophose.playerparticles.util.ParticleUtils;
|
2019-04-28 00:17:08 -06:00
|
|
|
import org.bukkit.Bukkit;
|
2019-04-28 04:25:35 -06:00
|
|
|
import org.bukkit.entity.Player;
|
2019-04-28 00:17:08 -06:00
|
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
2018-11-04 04:03:54 -07:00
|
|
|
|
|
|
|
public class GuiInventoryLoadPresetGroups extends GuiInventory {
|
|
|
|
|
2019-02-05 02:20:19 -07:00
|
|
|
public GuiInventoryLoadPresetGroups(PPlayer pplayer, boolean isEndPoint) {
|
2018-11-04 04:03:54 -07:00
|
|
|
super(pplayer, Bukkit.createInventory(pplayer.getPlayer(), INVENTORY_SIZE, LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP)));
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
DataManager dataManager = PlayerParticles.getInstance().getManager(DataManager.class);
|
|
|
|
|
2018-11-04 04:03:54 -07:00
|
|
|
this.fillBorder(BorderColor.GREEN);
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2019-04-28 04:25:35 -06:00
|
|
|
Player player = pplayer.getPlayer();
|
|
|
|
|
2018-11-04 04:03:54 -07:00
|
|
|
int index = 10;
|
|
|
|
int nextWrap = 17;
|
|
|
|
int maxIndex = 43;
|
2019-12-09 12:04:06 -07:00
|
|
|
List<ParticleGroupPreset> groups = PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer.getPlayer());
|
2019-01-31 23:27:09 -07:00
|
|
|
for (ParticleGroupPreset group : groups) {
|
2019-04-28 04:25:35 -06:00
|
|
|
if (!group.getGroup().canPlayerUse(player))
|
|
|
|
continue;
|
|
|
|
|
2019-01-31 23:27:09 -07:00
|
|
|
List<ParticlePair> particles = group.getGroup().getParticles();
|
2018-11-04 04:03:54 -07:00
|
|
|
particles.sort(Comparator.comparingInt(ParticlePair::getId));
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-11-04 04:03:54 -07:00
|
|
|
String[] lore = new String[particles.size() + 1];
|
|
|
|
lore[0] = LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_CLICK_TO_LOAD, particles.size());
|
|
|
|
int i = 1;
|
|
|
|
for (ParticlePair particle : particles) {
|
2019-01-26 00:34:50 -07:00
|
|
|
lore[i] = LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_PARTICLE_INFO, particle.getId(), ParticleUtils.formatName(particle.getEffect().getName()), ParticleUtils.formatName(particle.getStyle().getName()), particle.getDataString());
|
2018-11-04 04:03:54 -07:00
|
|
|
i++;
|
2019-04-28 00:17:08 -06:00
|
|
|
}
|
|
|
|
|
2018-11-04 04:03:54 -07:00
|
|
|
// Load Group Buttons
|
2019-01-31 23:27:09 -07:00
|
|
|
GuiActionButton groupButton = new GuiActionButton(index, group.getGuiIcon(), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + group.getDisplayName(), lore, (button, isShiftClick) -> {
|
2018-11-04 04:03:54 -07:00
|
|
|
ParticleGroup activeGroup = pplayer.getActiveParticleGroup();
|
|
|
|
activeGroup.getParticles().clear();
|
2019-12-11 19:24:33 -07:00
|
|
|
for (ParticlePair particle : particles) {
|
|
|
|
ParticlePair clonedParticle = particle.clone();
|
|
|
|
clonedParticle.setOwner(pplayer);
|
|
|
|
activeGroup.getParticles().add(clonedParticle);
|
|
|
|
}
|
2019-12-09 12:04:06 -07:00
|
|
|
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
if (Setting.GUI_CLOSE_AFTER_GROUP_SELECTED.getBoolean()) {
|
2019-02-05 02:20:19 -07:00
|
|
|
pplayer.getPlayer().closeInventory();
|
|
|
|
}
|
2018-11-04 04:03:54 -07:00
|
|
|
});
|
|
|
|
this.actionButtons.add(groupButton);
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-11-04 04:03:54 -07:00
|
|
|
index++;
|
|
|
|
if (index == nextWrap) { // Loop around border
|
|
|
|
nextWrap += 9;
|
2019-04-28 00:17:08 -06:00
|
|
|
index += 2;
|
2018-11-04 04:03:54 -07:00
|
|
|
}
|
|
|
|
if (index > maxIndex) break; // Overflowed the available space
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2019-02-05 02:20:19 -07:00
|
|
|
if (!isEndPoint) {
|
|
|
|
// Back Button
|
2019-04-28 00:17:08 -06:00
|
|
|
GuiActionButton backButton = new GuiActionButton(
|
|
|
|
INVENTORY_SIZE - 1, GuiIcon.BACK.get(),
|
|
|
|
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
|
|
|
|
new String[]{},
|
2019-12-09 12:04:06 -07:00
|
|
|
(button, isShiftClick) -> GuiManager.transition(new GuiInventoryDefault(pplayer)));
|
2019-02-05 02:20:19 -07:00
|
|
|
this.actionButtons.add(backButton);
|
|
|
|
} else {
|
|
|
|
// Reset Particles Button
|
2019-04-28 00:17:08 -06:00
|
|
|
GuiActionButton resetParticles = new GuiActionButton(
|
|
|
|
49,
|
|
|
|
GuiIcon.RESET.get(),
|
|
|
|
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_RESET_PARTICLES),
|
|
|
|
new String[]{LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_RESET_PARTICLES_DESCRIPTION)},
|
|
|
|
(button, isShiftClick) -> {
|
|
|
|
// Reset particles
|
2019-12-09 12:04:06 -07:00
|
|
|
dataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());
|
2019-04-28 00:17:08 -06:00
|
|
|
});
|
2019-02-05 02:20:19 -07:00
|
|
|
this.actionButtons.add(resetParticles);
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-11-04 04:03:54 -07:00
|
|
|
this.populate();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|