Skip to content

Commit

Permalink
Add sounds. Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertik committed Feb 15, 2021
1 parent 316500c commit a7a6fff
Show file tree
Hide file tree
Showing 30 changed files with 377 additions and 110 deletions.
27 changes: 16 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>space.devport.utils</pattern>
<shadedPattern>${project.groupId}.utils</shadedPattern>
<pattern>space.devport.dock</pattern>
<shadedPattern>${project.groupId}.dock</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>space/devport/utils/xseries/XBiome*</exclude>
<exclude>space/devport/utils/xseries/NMSExtras*</exclude>
<exclude>space/devport/utils/xseries/NoteBlockMusic*</exclude>
<exclude>space/devport/dock/xseries/XBiome*</exclude>
<exclude>space/devport/dock/xseries/NMSExtras*</exclude>
<exclude>space/devport/dock/xseries/NoteBlockMusic*</exclude>
</excludes>
</filter>
</filters>
Expand All @@ -77,6 +77,10 @@
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<id>devport</id>
<url>https://nexus.pvpcraft.cz/repository/devport/</url>
</repository>
Expand Down Expand Up @@ -105,23 +109,24 @@
<version>1.18.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>space.devport.utils</groupId>
<artifactId>DevportUtils</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>space.devport.dock</groupId>
<artifactId>dock</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- SQL -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import space.devport.utils.callbacks.ExceptionCallback;
import space.devport.utils.utility.ParseUtil;
import space.devport.dock.callbacks.ExceptionCallback;
import space.devport.dock.util.ParseUtil;
import space.devport.wertik.custommessages.system.message.type.MessageType;
import space.devport.wertik.custommessages.system.user.User;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package space.devport.wertik.custommessages;

import space.devport.utils.DevportPlugin;
import space.devport.utils.text.language.LanguageDefaults;
import space.devport.dock.api.IDockedPlugin;
import space.devport.dock.text.language.LanguageDefaults;

public class MessageLanguage extends LanguageDefaults {

public MessageLanguage(DevportPlugin plugin) {
public MessageLanguage(IDockedPlugin plugin) {
super(plugin);
}

Expand All @@ -27,5 +27,9 @@ public void setDefaults() {

addDefault("Type-Defaults.kill.Victim", "md_5");
addDefault("Type-Defaults.kill.Health", "256");

addDefault("Types.join", "&eJoin");
addDefault("Types.leave", "&cLeave");
addDefault("Types.kill", "&4Kill");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.ChatColor;
import org.bukkit.event.HandlerList;
import space.devport.utils.DevportPlugin;
import space.devport.utils.UsageFlag;
import space.devport.utils.logging.DebugLevel;
import space.devport.utils.utility.DependencyUtil;
import space.devport.utils.utility.VersionUtil;
import space.devport.dock.DockedPlugin;
import space.devport.dock.UsageFlag;
import space.devport.dock.util.DependencyUtil;
import space.devport.dock.util.VersionUtil;
import space.devport.wertik.custommessages.commands.CommandParser;
import space.devport.wertik.custommessages.commands.MessageCommand;
import space.devport.wertik.custommessages.listeners.ListenerRegistry;
import space.devport.wertik.custommessages.listeners.PlayerListener;
import space.devport.wertik.custommessages.sounds.SoundRegistry;
import space.devport.wertik.custommessages.system.message.MessageManager;
import space.devport.wertik.custommessages.system.user.UserManager;

import java.text.DecimalFormat;
import java.text.NumberFormat;

@Log
public class MessagePlugin extends DevportPlugin {
public class MessagePlugin extends DockedPlugin {

@Getter
private static MessagePlugin instance;
Expand All @@ -35,6 +35,9 @@ public class MessagePlugin extends DevportPlugin {
@Getter
private final ListenerRegistry listenerRegistry = new ListenerRegistry(this);

@Getter
private final SoundRegistry soundRegistry = new SoundRegistry(this);

@Getter
private CommandParser commandParser;

Expand All @@ -52,6 +55,8 @@ public void onPluginEnable() {
messageManager.load();
messageManager.loadOptions();

soundRegistry.load();

loadOptions();

new MessageLanguage(this).register();
Expand Down Expand Up @@ -80,7 +85,7 @@ private void unregisterPlaceholders() {

expansion.unregister();
this.expansion = null;
log.log(DebugLevel.DEBUG, "Unregistered placeholder expansion.");
log.fine(() -> "Unregistered placeholder expansion.");
}
}

Expand Down Expand Up @@ -117,6 +122,8 @@ public void onReload() {

commandParser.emptyCache();

soundRegistry.load();

loadOptions();

messageManager.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import space.devport.utils.text.language.LanguageManager;
import space.devport.utils.utility.ParseUtil;
import space.devport.dock.text.language.LanguageManager;
import space.devport.dock.util.ParseUtil;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.system.message.type.MessageType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import space.devport.utils.commands.MainCommand;
import space.devport.utils.commands.struct.CommandResult;
import space.devport.utils.text.language.LanguageManager;
import space.devport.utils.text.message.Message;
import space.devport.dock.commands.MainCommand;
import space.devport.dock.commands.struct.CommandResult;
import space.devport.dock.text.language.LanguageManager;
import space.devport.dock.text.message.Message;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.commands.subcommands.MenuSubCommand;
import space.devport.wertik.custommessages.commands.subcommands.PreviewSubCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package space.devport.wertik.custommessages.commands;

import org.jetbrains.annotations.Nullable;
import space.devport.utils.commands.SubCommand;
import space.devport.utils.commands.struct.ArgumentRange;
import space.devport.dock.commands.SubCommand;
import space.devport.dock.commands.struct.ArgumentRange;
import space.devport.wertik.custommessages.MessagePlugin;

public abstract class MessageSubCommand extends SubCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import space.devport.utils.commands.struct.ArgumentRange;
import space.devport.utils.commands.struct.CommandResult;
import space.devport.utils.commands.struct.Preconditions;
import space.devport.utils.text.language.LanguageManager;
import space.devport.dock.commands.struct.ArgumentRange;
import space.devport.dock.commands.struct.CommandResult;
import space.devport.dock.commands.struct.Preconditions;
import space.devport.dock.text.language.LanguageManager;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.commands.MessageSubCommand;
import space.devport.wertik.custommessages.gui.MessageMenu;
Expand All @@ -22,7 +22,7 @@ public class MenuSubCommand extends MessageSubCommand {

public MenuSubCommand(MessagePlugin plugin) {
super(plugin, "menu");
this.preconditions = new Preconditions()
getPreconditions()
.playerOnly();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import space.devport.utils.commands.struct.ArgumentRange;
import space.devport.utils.commands.struct.CommandResult;
import space.devport.dock.commands.struct.ArgumentRange;
import space.devport.dock.commands.struct.CommandResult;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.commands.CommandParser;
import space.devport.wertik.custommessages.commands.MessageSubCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import space.devport.utils.commands.struct.ArgumentRange;
import space.devport.utils.commands.struct.CommandResult;
import space.devport.dock.commands.struct.ArgumentRange;
import space.devport.dock.commands.struct.CommandResult;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.commands.MessageSubCommand;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package space.devport.wertik.custommessages.commands.subcommands;

import lombok.extern.java.Log;
import lombok.extern.java.Log;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import space.devport.utils.callbacks.ExceptionCallback;
import space.devport.utils.commands.struct.ArgumentRange;
import space.devport.utils.commands.struct.CommandResult;
import space.devport.utils.utility.ParseUtil;
import space.devport.dock.callbacks.ExceptionCallback;
import space.devport.dock.commands.struct.ArgumentRange;
import space.devport.dock.commands.struct.CommandResult;
import space.devport.dock.util.ParseUtil;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.commands.MessageSubCommand;
import space.devport.wertik.custommessages.system.message.type.MessageType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import lombok.extern.java.Log;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import space.devport.utils.CustomisationManager;
import space.devport.utils.logging.DebugLevel;
import space.devport.utils.menu.Menu;
import space.devport.utils.menu.MenuBuilder;
import space.devport.utils.menu.item.MatrixItem;
import space.devport.utils.menu.item.MenuItem;
import space.devport.utils.text.Placeholders;
import space.devport.dock.CustomisationManager;
import space.devport.dock.menu.Menu;
import space.devport.dock.menu.MenuBuilder;
import space.devport.dock.menu.item.MatrixItem;
import space.devport.dock.menu.item.MenuItem;
import space.devport.dock.text.language.LanguageManager;
import space.devport.dock.text.placeholders.Placeholders;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.sounds.SoundType;
import space.devport.wertik.custommessages.system.message.type.MessageType;

import java.util.List;
Expand Down Expand Up @@ -60,7 +61,7 @@ public CompletableFuture<Void> build() {
MenuBuilder template = plugin.getManager(CustomisationManager.class).getMenu("message-overview");

if (template == null) {
log.warning("Menu `message-overview` is missing in customisation.yml. Delete the file and let it regenerate.");
log.warning(() -> "Menu `message-overview` is missing in customisation.yml. Delete the file and let it regenerate.");
return;
}

Expand All @@ -75,33 +76,42 @@ public CompletableFuture<Void> build() {
MenuItem messageItemTaken = new MenuItem(menuBuilder.getItem("message-item-taken"));

Placeholders placeholders = plugin.obtainPlaceholders()
.add("%type%", type.toString().toLowerCase())
.add("%player%", player.getName())
.add("%message_used%", usedMessage);
.add("type", type.toString().toLowerCase())
.add("type_display", plugin.getManager(LanguageManager.class).get(String.format("Types.%s", type.toString())))
.add("player", player.getName())
.add("message_used", usedMessage);

menuBuilder.getTitle().parseWith(placeholders);
menuBuilder.placeholders(placeholders);

List<String> messages = plugin.getMessageManager().getMessages(type);

for (int i = (this.page - 1) * slotsPerPage; i < messages.size() && i < slotsPerPage * this.page; i++) {

String key = messages.get(i);
MenuItem item = new MenuItem(usedMessage.equals(key) ? messageItemTaken : messageItem);
boolean used = usedMessage.equals(key);

MenuItem item;
if (used) {
item = new MenuItem(messageItemTaken);
messageItemTaken.setClickAction(click -> plugin.getSoundRegistry().play(player, SoundType.MENU_USED));
} else {
item = new MenuItem(messageItem);
item.setClickAction((itemClick) -> {
user.setMessage(type, key);
plugin.getSoundRegistry().play(player, SoundType.MENU_PICK);
build().thenRun(this::reload);
});
}

item.getPrefab().getPlaceholders()
.add("%message_name%", key)
.add("%message_formatted%", plugin.getMessageManager().obtainPreview(type, player, key));

item.setClickAction((itemClick) -> {
user.setMessage(type, key);
build().thenRun(this::reload);
});

messageMatrix.addItem(item);
}

for (MenuItem i : messageMatrix.getMenuItems()) {
log.log(DebugLevel.DEBUG, i.getPrefab().getPlaceholders().getPlaceholderCache().toString());
log.fine(() -> i.getPrefab().getPlaceholders().getPlaceholderCache().toString());
}

// Page control and close
Expand Down Expand Up @@ -129,14 +139,25 @@ public CompletableFuture<Void> build() {

setMenuBuilder(menuBuilder.construct());
}).exceptionally(e -> {
log.severe(String.format("Failed to open message menu for %s: %s", player.getName(), e.getMessage()));
log.severe(() -> String.format("Failed to open message menu for %s: %s", player.getName(), e.getMessage()));
e.printStackTrace();
return null;
});
}

public void open() {
build().thenRun(() -> Bukkit.getScheduler().runTask(plugin, () -> open(player)));
build().thenRun(() -> {
// Synchronize
Bukkit.getScheduler().runTask(plugin, () -> {
open(player);
plugin.getSoundRegistry().play(player, SoundType.MENU_OPEN);
});
});
}

@Override
public void onClose() {
plugin.getSoundRegistry().play(player, SoundType.MENU_CLOSE);
}

private int maxPage() {
Expand Down
Loading

0 comments on commit a7a6fff

Please sign in to comment.