Added a way to clear particles

This commit is contained in:
Teriuihi 2022-01-14 04:52:05 +01:00
parent 5d76c39866
commit 763258c425
4 changed files with 47 additions and 12 deletions

View File

@ -45,8 +45,8 @@ public final class Config extends AbstractConfig {
public static String PARTICLE_TYPE_BUTTON_NAME = "<gold><name></gold>";
public static String PARTICLE_TYPE_GUI_NAME = "<red>AltitudeParticles</red>";
private static void loadGUIText() {
config.getString("gui-text.particle-type-button-name", PARTICLE_TYPE_BUTTON_NAME);
config.getString("gui-text.particles-type-gui-name", PARTICLE_TYPE_GUI_NAME);
PARTICLE_TYPE_BUTTON_NAME = config.getString("gui-text.particle-type-button-name", PARTICLE_TYPE_BUTTON_NAME);
PARTICLE_TYPE_GUI_NAME = config.getString("gui-text.particles-type-gui-name", PARTICLE_TYPE_GUI_NAME);
}
public static String SEE_OTHERS_ON = "<green>Particles visible</green>";
@ -57,18 +57,22 @@ public final class Config extends AbstractConfig {
public static String PARTICLES_ON_DESC = "<dark_aqua>Click to disable particles</dark_aqua>";
public static String PARTICLES_OFF = "<red>Particles off</red>";
public static String PARTICLES_OFF_DESC = "<dark_aqua>Click to enable particles</dark_aqua>";
public static String PARTICLES_CLEAR = "<yellow>Clear</yellow>";
public static String PARTICLES_CLEAR_DESC = "<dark_aqua>Clears all active particles</dark_aqua>";
public static String BACK_BUTTON = "<yellow>Back</yellow>";
private static void loadGUIButtons() {
config.getString("gui-buttons.see-others-on", SEE_OTHERS_ON);
config.getString("gui-buttons.see-others-on-desc", SEE_OTHERS_ON_DESC);
config.getString("gui-buttons.see-others-off", SEE_OTHERS_OFF);
config.getString("gui-buttons.see-others-off-desc", SEE_OTHERS_OFF_DESC);
config.getString("gui-buttons.particles-on", PARTICLES_ON);
config.getString("gui-buttons.particles-on-desc", PARTICLES_ON_DESC);
config.getString("gui-buttons.particles-off", PARTICLES_OFF);
config.getString("gui-buttons.particles-off-desc", PARTICLES_OFF_DESC);
config.getString("gui-buttons.back-button", BACK_BUTTON);
SEE_OTHERS_ON = config.getString("gui-buttons.see-others-on", SEE_OTHERS_ON);
SEE_OTHERS_ON_DESC = config.getString("gui-buttons.see-others-on-desc", SEE_OTHERS_ON_DESC);
SEE_OTHERS_OFF = config.getString("gui-buttons.see-others-off", SEE_OTHERS_OFF);
SEE_OTHERS_OFF_DESC = config.getString("gui-buttons.see-others-off-desc", SEE_OTHERS_OFF_DESC);
PARTICLES_ON = config.getString("gui-buttons.particles-on", PARTICLES_ON);
PARTICLES_ON_DESC = config.getString("gui-buttons.particles-on-desc", PARTICLES_ON_DESC);
PARTICLES_OFF = config.getString("gui-buttons.particles-off", PARTICLES_OFF);
PARTICLES_OFF_DESC = config.getString("gui-buttons.particles-off-desc", PARTICLES_OFF_DESC);
PARTICLES_CLEAR = config.getString("gui-buttons.particles-clear", PARTICLES_CLEAR);
PARTICLES_CLEAR_DESC = config.getString("gui-buttons.particles-clear-desc", PARTICLES_CLEAR_DESC);
BACK_BUTTON = config.getString("gui-buttons.back-button", BACK_BUTTON);
}
public static boolean DEBUG = false;

View File

@ -81,6 +81,19 @@ public class Queries {
}
}
public static void clearParticles(UUID uuid) {
String sql = "DELETE FROM active_particles " +
"WHERE uuid = ?";
try {
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
preparedStatement.setString(1, uuid.toString());
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static PlayerSettings getPlayerSettings(UUID uuid) {
String sql = "SELECT * FROM user_settings WHERE uuid = ?";
try {

View File

@ -23,7 +23,7 @@ public class OpenParticleGUI extends DefaultGUI {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
private static final Component GUIName;
private static final ItemStack seeOthersOn, seeOthersOff, particlesOn, particlesOff;
private static final ItemStack seeOthersOn, seeOthersOff, particlesOn, particlesOff, clearAll;
public OpenParticleGUI(Player player) {
super(GUIName);
@ -38,6 +38,12 @@ public class OpenParticleGUI extends DefaultGUI {
setItem(i++, particlesType.getItemStack(), new EnterParticleMenu(particlesType));
}
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
setItem(24, clearAll, player1 -> {
PlayerSettings pSettings = PlayerSettings.getPlayer(player1.getUniqueId());
if (pSettings == null)
return;
pSettings.clearParticles();
});
setItem(25, playerSettings.isSeeingParticles() ? seeOthersOn : seeOthersOff, new ToggleSeeParticles(this, playerSettings));
setItem(26, playerSettings.hasActiveParticles() ? particlesOn : particlesOff, new ToggleParticlesActive(this, playerSettings));
}
@ -88,5 +94,11 @@ public class OpenParticleGUI extends DefaultGUI {
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_OFF));
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_OFF_DESC));
particlesOff.setItemMeta(itemMeta);
clearAll = new ItemStack(Material.BUCKET);
itemMeta = clearAll.getItemMeta();
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_CLEAR));
itemMeta.displayName(miniMessage.deserialize(Config.PARTICLES_CLEAR_DESC));
clearAll.setItemMeta(itemMeta);
}
}

View File

@ -1,5 +1,6 @@
package com.alttd.storage;
import com.alttd.database.Queries;
import com.alttd.objects.APartType;
import com.alttd.objects.ParticleSet;
@ -77,4 +78,9 @@ public class PlayerSettings {
public ParticleSet getParticles(APartType aPartType) {
return particles.get(aPartType);
}
public void clearParticles() {
particles.clear();
Queries.clearParticles(uuid);
}
}