The plugin should use it's own API

This commit is contained in:
Esophose 2020-01-08 18:27:12 -07:00
parent 69d23c0527
commit c69860622d
17 changed files with 102 additions and 76 deletions

View file

@ -1,7 +1,5 @@
/*
* TODO: v7.0
* * Refactor the DataManager to not update the PPlayer objects, it should only handle saving/loading data, not applying it
* * Add an API, accessible through the dev.esophose.playerparticles.api.PlayerParticlesAPI class
* + Add ability to create/manage fixed effects from the GUI
* * Convert fixed effect ids into names
* + Add command '/pp fixed teleport <id>' that requires the permission playerparticles.fixed.teleport
@ -14,6 +12,8 @@
*/
/*
* + Added an API, accessible through the dev.esophose.playerparticles.api.PlayerParticlesAPI class
* * Refactored the DataManager to only handle saving/loading data
* * Refactored and cleaned up code to remove static abuse
* * Changed the package names
* + Config and lang files will no longer reset every update

View file

@ -32,7 +32,6 @@ import org.jetbrains.annotations.Nullable;
* Note: This API will bypass all permissions and does not send any messages.
* Any changes made through the API will be saved to the database automatically.
*/
@SuppressWarnings("unused")
public final class PlayerParticlesAPI {
private static PlayerParticlesAPI INSTANCE;
@ -260,7 +259,7 @@ public final class PlayerParticlesAPI {
public void savePlayerParticleGroup(@NotNull Player player, @NotNull ParticleGroup particleGroup) {
Objects.requireNonNull(particleGroup);
if (particleGroup.getParticles().isEmpty())
if (particleGroup.getParticles().isEmpty() && !particleGroup.getName().equals(ParticleGroup.DEFAULT_NAME))
throw new IllegalArgumentException("Cannot save an empty ParticleGroup");
DataManager dataManager = this.playerParticles.getManager(DataManager.class);
@ -364,6 +363,21 @@ public final class PlayerParticlesAPI {
this.createFixedParticleEffect(player, location, particle);
}
public void editFixedParticleEffect(@NotNull Player player, @NotNull FixedParticleEffect fixedEffect) {
Objects.requireNonNull(fixedEffect);
PPlayer pplayer = this.getPPlayer(player);
if (pplayer == null)
return;
DataManager dataManager = this.playerParticles.getManager(DataManager.class);
if (this.validateFixedParticleEffect(player, fixedEffect.getId()) != null) {
pplayer.removeFixedEffect(fixedEffect.getId());
pplayer.addFixedEffect(fixedEffect);
dataManager.updateFixedEffect(fixedEffect);
}
}
public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull Location location) {
Objects.requireNonNull(location);
Objects.requireNonNull(location.getWorld());
@ -448,21 +462,32 @@ public final class PlayerParticlesAPI {
}
}
public void removeFixedEffectsInRange(@NotNull Location location, double radius) {
/**
* Removes fixed effects within a given radius of a location
*
* @param location The location to search around
* @param radius The radius to remove
* @return The number of fixed effects that were removed
*/
public int removeFixedEffectsInRange(@NotNull Location location, double radius) {
Objects.requireNonNull(location);
Objects.requireNonNull(location.getWorld());
DataManager dataManager = this.playerParticles.getManager(DataManager.class);
ParticleManager particleManager = this.playerParticles.getManager(ParticleManager.class);
int removed = 0;
for (PPlayer pplayer : particleManager.getPPlayers()) {
for (FixedParticleEffect fixedEffect : pplayer.getFixedParticles()) {
if (fixedEffect.getLocation().getWorld() == location.getWorld() && fixedEffect.getLocation().distance(location) <= radius) {
pplayer.removeFixedEffect(fixedEffect.getId());
dataManager.removeFixedEffect(pplayer.getUniqueId(), fixedEffect.getId());
removed++;
}
}
}
return removed;
}
@Nullable

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.ParticleStyleManager;
@ -133,7 +134,7 @@ public class AddCommandModule implements CommandModule {
ParticleGroup group = pplayer.getActiveParticleGroup();
ParticlePair newParticle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, itemData, blockData, colorData, noteColorData);
group.getParticles().put(newParticle.getId(), newParticle);
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
StringPlaceholders addParticlePlaceholders = StringPlaceholders.builder("effect", newParticle.getEffect().getName())
.addPlaceholder("style", newParticle.getStyle().getName())

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.PermissionManager;
@ -94,7 +95,7 @@ public class EditCommandModule implements CommandModule {
}
}
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
localeManager.sendMessage(pplayer, "edit-success-effect", StringPlaceholders.builder("id", id).addPlaceholder("effect", effect.getName()).build());
}
@ -125,7 +126,7 @@ public class EditCommandModule implements CommandModule {
}
}
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
localeManager.sendMessage(pplayer, "edit-success-style", StringPlaceholders.builder("id", id).addPlaceholder("style", style.getName()).build());
}
@ -226,7 +227,7 @@ public class EditCommandModule implements CommandModule {
}
}
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
localeManager.sendMessage(pplayer, "edit-success-data", StringPlaceholders.builder("id", id).addPlaceholder("data", updatedDataString).build());
}

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.ParticleManager;
@ -269,12 +270,9 @@ public class FixedCommandModule implements CommandModule {
}
}
int nextFixedEffectId = pplayer.getNextFixedEffectId();
ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), nextFixedEffectId, effect, style, itemData, blockData, colorData, noteColorData);
FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), nextFixedEffectId, new Location(p.getLocation().getWorld(), xPos, yPos, zPos), particle);
ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextFixedEffectId(), effect, style, itemData, blockData, colorData, noteColorData);
PlayerParticlesAPI.getInstance().createFixedParticleEffect(pplayer.getPlayer(), new Location(p.getLocation().getWorld(), xPos, yPos, zPos), particle);
localeManager.sendMessage(pplayer, "fixed-create-success");
PlayerParticles.getInstance().getManager(DataManager.class).saveFixedEffect(fixedEffect);
}
/**
@ -486,7 +484,7 @@ public class FixedCommandModule implements CommandModule {
return;
}
PlayerParticles.getInstance().getManager(DataManager.class).updateFixedEffect(fixedEffect);
PlayerParticlesAPI.getInstance().editFixedParticleEffect(pplayer.getPlayer(), fixedEffect);
localeManager.sendMessage(pplayer, "fixed-edit-success", StringPlaceholders.builder("prop", editType).addPlaceholder("id", id).build());
}
@ -514,7 +512,7 @@ public class FixedCommandModule implements CommandModule {
}
if (pplayer.getFixedEffectById(id) != null) {
PlayerParticles.getInstance().getManager(DataManager.class).removeFixedEffect(pplayer.getUniqueId(), id);
PlayerParticlesAPI.getInstance().removeFixedEffect(pplayer.getPlayer(), id);
localeManager.sendMessage(pplayer, "fixed-remove-success", StringPlaceholders.single("id", id));
} else {
localeManager.sendMessage(pplayer, "fixed-remove-invalid", StringPlaceholders.single("id", id));
@ -625,21 +623,11 @@ public class FixedCommandModule implements CommandModule {
return;
}
ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<>();
for (PPlayer ppl : particleManager.getPPlayers())
for (FixedParticleEffect fixedEffect : ppl.getFixedParticles())
if (fixedEffect.getLocation().getWorld() == p.getLocation().getWorld() && fixedEffect.getLocation().distance(p.getLocation()) <= radius)
fixedEffectsToRemove.add(fixedEffect);
for (FixedParticleEffect fixedEffect : fixedEffectsToRemove)
dataManager.removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId());
localeManager.sendMessage(pplayer, "fixed-clear-success", StringPlaceholders.builder("amount", fixedEffectsToRemove.size()).addPlaceholder("range", radius).build());
int amountRemoved = PlayerParticlesAPI.getInstance().removeFixedEffectsInRange(p.getLocation(), radius);
localeManager.sendMessage(pplayer, "fixed-clear-success", StringPlaceholders.builder("amount", amountRemoved).addPlaceholder("range", radius).build());
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
Player p = pplayer.getPlayer();
List<String> matches = new ArrayList<>();

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.ParticleGroupPresetManager;
@ -110,7 +111,7 @@ public class GroupCommandModule implements CommandModule {
}
// Apply changes and notify player
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
if (groupUpdated) {
localeManager.sendMessage(pplayer, "group-save-success-overwrite", StringPlaceholders.single("name", groupName));
} else {
@ -165,7 +166,7 @@ public class GroupCommandModule implements CommandModule {
activeGroup.getParticles().put(particle.getId(), particle.clone());
// Update group and notify player
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
if (!isPreset)
localeManager.sendMessage(pplayer, "group-load-success", StringPlaceholders.builder("amount", activeGroup.getParticles().size()).addPlaceholder("name", groupName).build());
@ -202,7 +203,7 @@ public class GroupCommandModule implements CommandModule {
}
// Delete the group and notify player
PlayerParticles.getInstance().getManager(DataManager.class).removeParticleGroup(pplayer.getUniqueId(), group.getName());
PlayerParticlesAPI.getInstance().removePlayerParticleGroup(pplayer.getPlayer(), group.getName());
localeManager.sendMessage(pplayer, "group-remove-success", StringPlaceholders.single("name", groupName));
}

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.particles.PPlayer;
@ -49,7 +50,7 @@ public class RemoveCommandModule implements CommandModule {
return;
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
localeManager.sendMessage(pplayer, "remove-id-success", StringPlaceholders.single("id", id));
} else { // Removing by effect/style name
ParticleEffect effect = ParticleEffect.fromName(args[0]);
@ -66,7 +67,7 @@ public class RemoveCommandModule implements CommandModule {
}
if (removedCount > 0) {
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
localeManager.sendMessage(pplayer, "remove-effect-success", StringPlaceholders.builder("amount", removedCount).addPlaceholder("effect", effect.getName()).build());
} else {
localeManager.sendMessage(pplayer, "remove-effect-none", StringPlaceholders.single("effect", effect.getName()));
@ -82,7 +83,7 @@ public class RemoveCommandModule implements CommandModule {
}
if (removedCount > 0) {
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
localeManager.sendMessage(pplayer, "remove-style-success", StringPlaceholders.builder("amount", removedCount).addPlaceholder("style", style.getName()).build());
} else {
localeManager.sendMessage(pplayer, "remove-style-none", StringPlaceholders.single("style", style.getName()));

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.particles.PPlayer;
@ -13,7 +14,7 @@ public class ResetCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) {
int particleCount = pplayer.getActiveParticles().size();
PlayerParticles.getInstance().getManager(DataManager.class).saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), ParticleGroup.getDefaultGroup());
PlayerParticles.getInstance().getManager(LocaleManager.class).sendMessage(pplayer, "reset-success", StringPlaceholders.single("amount", particleCount));
}

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.particles.PPlayer;
@ -12,7 +13,7 @@ public class ToggleCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
boolean canSee = pplayer.canSeeParticles();
PlayerParticles.getInstance().getManager(DataManager.class).updateSettingParticlesHidden(pplayer.getUniqueId(), canSee);
PlayerParticlesAPI.getInstance().togglePlayerParticleVisibility(pplayer.getPlayer(), canSee);
if (canSee) {
localeManager.sendMessage(pplayer, "toggle-off");

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.gui;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.ConfigurationManager.GuiIcon;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.GuiManager;
@ -135,7 +136,7 @@ public class GuiInventoryDefault extends GuiInventory {
} else {
group.getParticles().put(editingParticle.getId(), editingParticle);
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
guiManager.transition(new GuiInventoryDefault(pplayer));
});
@ -173,7 +174,7 @@ public class GuiInventoryDefault extends GuiInventory {
break;
}
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
guiManager.transition(new GuiInventoryDefault(pplayer));
});
@ -219,7 +220,7 @@ public class GuiInventoryDefault extends GuiInventory {
break;
}
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
guiManager.transition(new GuiInventoryDefault(pplayer));
});

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.gui;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.ConfigurationManager.GuiIcon;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.GuiManager;
@ -58,7 +59,7 @@ public class GuiInventoryEditParticle extends GuiInventory {
break;
}
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
guiManager.transition(new GuiInventoryEditParticle(pplayer, editingParticle));
});
@ -84,7 +85,7 @@ public class GuiInventoryEditParticle extends GuiInventory {
break;
}
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
guiManager.transition(new GuiInventoryEditParticle(pplayer, editingParticle));
});
@ -116,7 +117,7 @@ public class GuiInventoryEditParticle extends GuiInventory {
break;
}
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
guiManager.transition(new GuiInventoryEditParticle(pplayer, editingParticle));
});

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.gui;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.ConfigurationManager.GuiIcon;
import dev.esophose.playerparticles.manager.ConfigurationManager.Setting;
import dev.esophose.playerparticles.manager.DataManager;
@ -65,7 +66,7 @@ public class GuiInventoryLoadPresetGroups extends GuiInventory {
clonedParticle.setOwner(pplayer);
activeGroup.getParticles().put(clonedParticle.getId(), clonedParticle);
}
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
if (Setting.GUI_CLOSE_AFTER_GROUP_SELECTED.getBoolean()) {
pplayer.getPlayer().closeInventory();
@ -98,7 +99,7 @@ public class GuiInventoryLoadPresetGroups extends GuiInventory {
new String[]{localeManager.getLocaleMessage("gui-color-unavailable") + localeManager.getLocaleMessage("gui-reset-particles-description")},
(button, isShiftClick) -> {
// Reset particles
dataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), ParticleGroup.getDefaultGroup());
});
this.actionButtons.add(resetParticles);
}

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.gui;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.gui.hook.PlayerChatHook;
import dev.esophose.playerparticles.gui.hook.PlayerChatHookData;
import dev.esophose.playerparticles.manager.ConfigurationManager.GuiIcon;
@ -66,7 +67,7 @@ public class GuiInventoryManageGroups extends GuiInventory {
lore,
(button, isShiftClick) -> {
if (isShiftClick) {
dataManager.removeParticleGroup(pplayer.getUniqueId(), group.getName());
PlayerParticlesAPI.getInstance().removePlayerParticleGroup(pplayer.getPlayer(), group.getName());
this.actionButtons.remove(button);
this.inventory.setItem(button.getSlot(), null);
@ -75,7 +76,7 @@ public class GuiInventoryManageGroups extends GuiInventory {
activeGroup.getParticles().clear();
for (ParticlePair particle : particles)
activeGroup.getParticles().put(particle.getId(), particle.clone());
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
if (Setting.GUI_CLOSE_AFTER_GROUP_SELECTED.getBoolean()) {
pplayer.getPlayer().closeInventory();
@ -148,7 +149,7 @@ public class GuiInventoryManageGroups extends GuiInventory {
}
// Apply changes and notify player
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
if (groupUpdated) {
localeManager.sendMessage(pplayer, "group-save-success-overwrite", StringPlaceholders.single("name", groupName));
} else {

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.gui;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.ConfigurationManager.GuiIcon;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.GuiManager;
@ -57,7 +58,7 @@ public class GuiInventoryManageParticles extends GuiInventory {
// Delete particle
ParticleGroup activeGroup = pplayer.getActiveParticleGroup();
activeGroup.getParticles().remove(particle.getId());
dataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
// Update inventory to reflect deletion
this.actionButtons.remove(button);
@ -100,7 +101,7 @@ public class GuiInventoryManageParticles extends GuiInventory {
// Save new particle
ParticleGroup group = pplayer.getActiveParticleGroup();
group.getParticles().put(editingParticle.getId(), editingParticle);
dataManager.saveParticleGroup(pplayer.getUniqueId(), group);
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
// Reopen the manage particle inventory
guiManager.transition(new GuiInventoryManageParticles(pplayer));
@ -116,7 +117,7 @@ public class GuiInventoryManageParticles extends GuiInventory {
new String[]{localeManager.getLocaleMessage("gui-color-unavailable") + localeManager.getLocaleMessage("gui-reset-particles-description")},
(button, isShiftClick) -> {
// Reset particles
dataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), ParticleGroup.getDefaultGroup());
// Reopen this same inventory to refresh it
guiManager.transition(new GuiInventoryManageParticles(pplayer));

View file

@ -24,6 +24,11 @@ public class ConfigurationManager extends Manager {
" \\/\\/ \\/ \\/ \\/ \\/ \\/"
};
private static final String[] FOOTER = new String[] {
"That's everything! You reached the end of the configuration.",
"Enjoy the plugin!"
};
public enum Setting {
CHECK_UPDATES("check-updates", true, "Check for new versions of the plugin"),
SEND_METRICS("send-metrics", true, "If metrics should be sent to bStats", "I would appreciate it if you left this enabled, it helps me get statistics on how the plugin is used"),
@ -261,7 +266,11 @@ public class ConfigurationManager extends Manager {
if (!(this.defaultValue instanceof List) && this.defaultValue != null) {
String defaultComment = "Default: ";
if (this.defaultValue instanceof String) {
defaultComment += "'" + this.defaultValue + "'";
if (ParticleUtils.containsConfigSpecialCharacters((String) this.defaultValue)) {
defaultComment += "'" + this.defaultValue + "'";
} else {
defaultComment += this.defaultValue;
}
} else {
defaultComment += this.defaultValue;
}
@ -310,11 +319,11 @@ public class ConfigurationManager extends Manager {
@Override
public void reload() {
File configFile = new File(this.playerParticles.getDataFolder(), "config.yml");
boolean setHeader = !configFile.exists();
boolean setHeaderFooter = !configFile.exists();
this.configuration = CommentedFileConfiguration.loadConfiguration(this.playerParticles, configFile);
if (setHeader)
if (setHeaderFooter)
this.configuration.addComments(HEADER);
for (Setting setting : Setting.values()) {
@ -325,6 +334,9 @@ public class ConfigurationManager extends Manager {
for (GuiIcon icon : GuiIcon.values())
icon.resetDefault();
if (setHeaderFooter)
this.configuration.addComments(FOOTER);
this.configuration.save();
}

View file

@ -267,8 +267,6 @@ public class DataManager extends Manager {
updateStatement.executeUpdate();
}
}));
this.getPPlayer(playerUUID, (pplayer) -> pplayer.setParticlesHidden(particlesHidden));
}
/**
@ -329,16 +327,6 @@ public class DataManager extends Manager {
particlesStatement.executeBatch();
}
}));
this.getPPlayer(playerUUID, (pplayer) -> {
for (ParticleGroup existing : pplayer.getParticleGroups().values()) {
if (group.getName().equalsIgnoreCase(existing.getName())) {
pplayer.getParticleGroups().remove(existing.getName());
break;
}
}
pplayer.getParticleGroups().put(group.getName(), group);
});
}
/**
@ -379,8 +367,6 @@ public class DataManager extends Manager {
statement.executeUpdate();
}
}));
this.getPPlayer(playerUUID, (pplayer) -> pplayer.getParticleGroups().remove(groupName));
}
/**
@ -421,8 +407,6 @@ public class DataManager extends Manager {
statement.executeUpdate();
}
}));
this.getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> pplayer.addFixedEffect(fixedEffect));
}
/**
@ -462,11 +446,6 @@ public class DataManager extends Manager {
statement.executeUpdate();
}
}));
this.getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> {
pplayer.removeFixedEffect(fixedEffect.getId());
pplayer.addFixedEffect(fixedEffect);
});
}
/**
@ -506,8 +485,6 @@ public class DataManager extends Manager {
statement.executeUpdate();
}
}));
this.getPPlayer(playerUUID, (pplayer) -> pplayer.removeFixedEffect(id));
}
/**

View file

@ -109,4 +109,17 @@ public final class ParticleUtils {
return n.length + 1;
}
public static boolean containsConfigSpecialCharacters(String string) {
for (char c : string.toCharArray()) {
// Range taken from SnakeYAML's Emitter.java
if (!(c == '\n' || (0x20 <= c && c <= 0x7E)) &&
(c == 0x85 || (c >= 0xA0 && c <= 0xD7FF)
|| (c >= 0xE000 && c <= 0xFFFD)
|| (c >= 0x10000 && c <= 0x10FFFF))) {
return true;
}
}
return false;
}
}