Added an option to make the group save gui icon print a message to chat

This commit is contained in:
Esophose 2020-12-05 18:10:19 -07:00
parent 72ee0ab219
commit 9bc4e82af0
8 changed files with 61 additions and 34 deletions

View file

@ -12,6 +12,7 @@ import dev.esophose.playerparticles.manager.PermissionManager;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleGroup;
import dev.esophose.playerparticles.particles.ParticlePair;
import dev.esophose.playerparticles.util.NMSUtil;
import dev.esophose.playerparticles.util.ParticleUtils;
import dev.esophose.playerparticles.util.StringPlaceholders;
import java.util.ArrayList;
@ -20,6 +21,9 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ClickEvent.Action;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
public class GuiInventoryManageGroups extends GuiInventory {
@ -148,44 +152,60 @@ public class GuiInventoryManageGroups extends GuiInventory {
if (hasReachedMax || !hasParticles)
return;
PlayerChatHook.addHook(new PlayerChatHookData(pplayer.getUniqueId(), 15, (textEntered) -> {
if (textEntered != null && !textEntered.equalsIgnoreCase("cancel")) {
String groupName = textEntered.split(" ")[0];
if (!Setting.GUI_GROUP_CREATION_BUNGEE_SUPPORT.getBoolean()) {
PlayerChatHook.addHook(new PlayerChatHookData(pplayer.getUniqueId(), 15, (textEntered) -> {
if (textEntered != null && !textEntered.equalsIgnoreCase("cancel")) {
String groupName = textEntered.split(" ")[0];
// Check that the groupName isn't the reserved name
if (groupName.equalsIgnoreCase(ParticleGroup.DEFAULT_NAME)) {
localeManager.sendMessage(pplayer, "group-reserved");
return;
}
// The database column can only hold up to 100 characters, cut it off there
if (groupName.length() >= 100) {
groupName = groupName.substring(0, 100);
}
// Use the existing group if available, otherwise create a new one
ParticleGroup group = pplayer.getParticleGroupByName(groupName);
boolean groupUpdated = false;
if (group == null) {
Map<Integer, ParticlePair> particles = new ConcurrentHashMap<>();
for (ParticlePair particle : pplayer.getActiveParticles())
particles.put(particle.getId(), particle.clone()); // Make sure the ParticlePairs aren't the same references in both the active and saved group
group = new ParticleGroup(groupName, particles);
} else {
groupUpdated = true;
}
// Apply changes and notify player
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
if (groupUpdated) {
localeManager.sendMessage(pplayer, "group-save-success-overwrite", StringPlaceholders.single("name", groupName));
} else {
localeManager.sendMessage(pplayer, "group-save-success", StringPlaceholders.single("name", groupName));
}
// Check that the groupName isn't the reserved name
if (groupName.equalsIgnoreCase(ParticleGroup.DEFAULT_NAME)) {
localeManager.sendMessage(pplayer, "group-reserved");
return;
}
// The database column can only hold up to 100 characters, cut it off there
if (groupName.length() >= 100) {
groupName = groupName.substring(0, 100);
}
// Use the existing group if available, otherwise create a new one
ParticleGroup group = pplayer.getParticleGroupByName(groupName);
boolean groupUpdated = false;
if (group == null) {
Map<Integer, ParticlePair> particles = new ConcurrentHashMap<>();
for (ParticlePair particle : pplayer.getActiveParticles())
particles.put(particle.getId(), particle.clone()); // Make sure the ParticlePairs aren't the same references in both the active and saved group
group = new ParticleGroup(groupName, particles);
} else {
groupUpdated = true;
}
// Apply changes and notify player
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), group);
if (groupUpdated) {
localeManager.sendMessage(pplayer, "group-save-success-overwrite", StringPlaceholders.single("name", groupName));
} else {
localeManager.sendMessage(pplayer, "group-save-success", StringPlaceholders.single("name", groupName));
}
guiManager.transition(new GuiInventoryManageGroups(pplayer, pageNumber));
}));
} else {
if (NMSUtil.getVersionNumber() >= 8) {
String message = localeManager.getLocaleMessage("gui-save-group-chat-message");
String prefix = "";
if (Setting.USE_MESSAGE_PREFIX.getBoolean())
prefix = localeManager.getLocaleMessage("prefix");
TextComponent component = new TextComponent(TextComponent.fromLegacyText(prefix + message));
component.setClickEvent(new ClickEvent(Action.SUGGEST_COMMAND, "/pp group save "));
pplayer.getPlayer().spigot().sendMessage(component);
} else {
localeManager.sendMessage(pplayer, "gui-save-group-chat-message");
}
guiManager.transition(new GuiInventoryManageGroups(pplayer, pageNumber));
}));
}
this.close();
});
this.actionButtons.add(saveGroupButton);

View file

@ -289,6 +289,7 @@ public class EnglishLocale implements Locale {
this.put("gui-save-group-full", "You have reached the max number of groups");
this.put("gui-save-group-no-particles", "You do not have any particles applied");
this.put("gui-save-group-hotbar-message", "&eType &b1 &eword in chat for the new group name. Type &ccancel&e to cancel. (&b%seconds%&es left)");
this.put("gui-save-group-chat-message", "&eUse &b/pp group save <name> &eto save a new particle group.");
this.put("#33", "GUI Reset Messages");
this.put("gui-reset-particles", "Reset Your Particles");

View file

@ -289,6 +289,7 @@ public class FrenchLocale implements Locale {
this.put("gui-save-group-full", "Vous avez atteint le nombre maximal de groupe !");
this.put("gui-save-group-no-particles", "Vous avez aucunes particules appliquées");
this.put("gui-save-group-hotbar-message", "&eTapez &b1 &enom dans le tchat pour le nouveau nom du groupe. Tapez &ccancel&e pour annuler. (&b%seconds%&es restants)");
this.put("gui-save-group-chat-message", "&eUtilisez &b/pp group save <name> &epour enregistrer un nouveau groupe de particules.");
this.put("#33", "GUI Reset Messages");
this.put("gui-reset-particles", "Réinitialisez vos particules");

View file

@ -289,6 +289,7 @@ public class GermanLocale implements Locale {
this.put("gui-save-group-full", "Sie haben die maximale Anzahl von Gruppen erreicht");
this.put("gui-save-group-no-particles", "Sie haben keine Partikel");
this.put("gui-save-group-hotbar-message", "&eGeben Sie im Chat &b1 &eWort für den neuen Gruppennamen ein. Geben Sie &ccancel&e ein, um den Vorgang abzubrechen. (Noch&b%seconds%&e)");
this.put("gui-save-group-chat-message", "&eVerwenden Sie /pp group save <name>&e, um eine neue Partikelgruppe zu speichern.");
this.put("#33", "GUI Reset Messages");
this.put("gui-reset-particles", "Setzen Sie Ihre Partikel zurück");

View file

@ -289,6 +289,7 @@ public class RussianLocale implements Locale {
this.put("gui-save-group-full", "Вы достигли максимального числа групп!");
this.put("gui-save-group-no-particles", "У Вас нет каких-либо активных частиц!");
this.put("gui-save-group-hotbar-message", "&eВведите &b1 &eслово в чат, которое будет названием группы. Введите &cотмена&e для отмены.");
this.put("gui-save-group-chat-message", "&eИспользуйте &b/pp group save <имя> &eдля сохранения новой группы частиц.");
this.put("#33", "GUI Reset Messages");
this.put("gui-reset-particles", "Удалить ваши частицы");

View file

@ -289,6 +289,7 @@ public class SimplifiedChineseLocale implements Locale {
this.put("gui-save-group-full", "你已达到粒子组上限");
this.put("gui-save-group-no-particles", "你没有使用粒子特效");
this.put("gui-save-group-hotbar-message", "&e请在聊天框内输入&b1 &e新的粒子组名。 输入 &ccancel&e 取消。 (剩余&b%seconds%&e秒)");
this.put("gui-save-group-chat-message", "&e使用&b/pp group save <名称>&e来保存一个新的粒子组。");
this.put("#33", "GUI Reset Messages");
this.put("gui-reset-particles", "重置你的粒子特效");

View file

@ -289,6 +289,7 @@ public class VietnameseLocale implements Locale {
this.put("gui-save-group-full", "Bạn đã đạt đến giới hạn số lượng group có thể tạo");
this.put("gui-save-group-no-particles", "Bạn không có bất kì Hhạt hiệu ứng nào được áp dụng");
this.put("gui-save-group-hotbar-message", "&eNhập &b1 &etên group trong chat. Nhập &ccancel&e để hủy. (&b%seconds%&es left)");
this.put("gui-save-group-chat-message", "&eSử dụng &b/pp group save <Tên> &eđể lưu một nhóm hạt mới.");
this.put("#33", "GUI Reset Messages");
this.put("gui-reset-particles", "Làm mới Hạt hiệu ứng của bạn");

View file

@ -59,6 +59,7 @@ public class ConfigurationManager extends Manager {
RAINBOW_CYCLE_SPEED("rainbow-cycle-speed", 2, "How many out of 360 hue ticks to move per game tick", "Higher values make the rainbow cycle faster", "Note: Must be a positive whole number"),
DUST_SIZE("dust-size", 1.0, "How large should dust particles appear?", "Note: Can include decimals", "Only works in 1.13+"),
GUI_GROUP_CREATION_MESSAGE_DISPLAY_AREA("gui-group-creation-message-display-area", "ACTION_BAR", "Valid values: ACTION_BAR, TITLE, CHAT", "Where should the GUI group creation countdown message be displayed?", "Note: Server versions less than 1.11.2 will always use CHAT"),
GUI_GROUP_CREATION_BUNGEE_SUPPORT("gui-group-creation-bungee-support", false, "If true, a message will be displayed in chat telling the player to enter the command", "This might be required for some servers using bungee chat plugins"),
WORLDGUARD_SETTINGS("worldguard-settings", null, "Settings for WorldGuard", "If WorldGuard is not installed, these settings will do nothing"),
WORLDGUARD_USE_ALLOWED_REGIONS("worldguard-settings.use-allowed-regions", false, "If true, particles will only be able to spawn if they are in an allowed region and not a disallowed region", "If false, particles will be able to spawn as long as they are not in a disallowed region"),