-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
287 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 53 additions & 1 deletion
54
Plugin/src/main/java/dev/lrxh/neptune/cosmetics/CosmeticManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,56 @@ | ||
package dev.lrxh.neptune.cosmetics; | ||
|
||
public class CosmeticManager { | ||
import dev.lrxh.neptune.Neptune; | ||
import dev.lrxh.neptune.cosmetics.impl.KillMessagePackage; | ||
import dev.lrxh.neptune.providers.manager.IManager; | ||
import dev.lrxh.neptune.utils.ConfigFile; | ||
import org.bukkit.Material; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class CosmeticManager implements IManager { | ||
public final Map<String, KillMessagePackage> deathMessages; | ||
private final Neptune plugin; | ||
|
||
public CosmeticManager() { | ||
this.plugin = Neptune.get(); | ||
this.deathMessages = new HashMap<>(); | ||
load(); | ||
} | ||
|
||
public void load() { | ||
FileConfiguration config = plugin.getConfigManager().getCosmeticsConfig().getConfiguration(); | ||
if (config.contains("KILL_MESSAGES")) { | ||
for (String deathPackageName : getKeys("KILL_MESSAGES")) { | ||
String path = "KILL_MESSAGES." + deathPackageName + "."; | ||
String displayName = config.getString(path + "DISPLAY_NAME"); | ||
Material material = Material.getMaterial(Objects.requireNonNull(config.getString(path + "MATERIAL"))); | ||
List<String> description = config.getStringList(path + "DESCRIPTION"); | ||
int slot = config.getInt(path + "SLOT"); | ||
List<String> messages = config.getStringList(path + "MESSAGES"); | ||
|
||
deathMessages.put(deathPackageName, new KillMessagePackage(deathPackageName, displayName, material, description, slot, messages)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public ConfigFile getConfigFile() { | ||
return plugin.getConfigManager().getCosmeticsConfig(); | ||
} | ||
|
||
public KillMessagePackage getDeathMessagePackage(String packageName) { | ||
if (!deathMessages.containsKey(packageName)) { | ||
return getDefault(); | ||
} | ||
return deathMessages.get(packageName); | ||
} | ||
|
||
public KillMessagePackage getDefault() { | ||
return deathMessages.get("DEFAULT"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Plugin/src/main/java/dev/lrxh/neptune/cosmetics/impl/KillMessagePackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.lrxh.neptune.cosmetics.impl; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.bukkit.Material; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class KillMessagePackage { | ||
private final SecureRandom secureRandom = new SecureRandom(); | ||
private String name; | ||
private String displayName; | ||
private Material material; | ||
private List<String> description; | ||
private int slot; | ||
private List<String> messages; | ||
|
||
public String getRandomMessage() { | ||
return messages.get(secureRandom.nextInt(messages.size())); | ||
} | ||
|
||
public String permission() { | ||
return "neptune.cosmetics.killmessages." + name.toLowerCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Plugin/src/main/java/dev/lrxh/neptune/cosmetics/menu/killMessages/KillMessageButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dev.lrxh.neptune.cosmetics.menu.killMessages; | ||
|
||
import dev.lrxh.neptune.configs.impl.CosmeticsLocale; | ||
import dev.lrxh.neptune.configs.impl.MenusLocale; | ||
import dev.lrxh.neptune.cosmetics.impl.KillMessagePackage; | ||
import dev.lrxh.neptune.profile.Profile; | ||
import dev.lrxh.neptune.utils.ItemBuilder; | ||
import dev.lrxh.neptune.utils.menu.Button; | ||
import lombok.AllArgsConstructor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.inventory.ClickType; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
public class KillMessageButton extends Button { | ||
private final KillMessagePackage killMessagePackage; | ||
|
||
@Override | ||
public ItemStack getButtonItem(Player player) { | ||
Profile profile = plugin.getProfileManager().getByUUID(player.getUniqueId()); | ||
if (profile == null) return null; | ||
boolean selected = profile.getSettingData().getKillMessagePackage().equals(killMessagePackage); | ||
List<String> lore; | ||
|
||
if (player.hasPermission(killMessagePackage.permission())) { | ||
lore = selected ? MenusLocale.KILL_EFFECTS_SELECTED_LORE.getStringList() : MenusLocale.KILL_EFFECTS_UNSELECTED_LORE.getStringList(); | ||
} else { | ||
lore = MenusLocale.KILL_EFFECTS_NO_PERMISSION_LORE.getStringList(); | ||
} | ||
|
||
return new ItemBuilder(killMessagePackage.getMaterial()).name(killMessagePackage.getDisplayName() | ||
.replace("<selected>", selected ? CosmeticsLocale.SELECTED_DISPLAY_NAME.getString() : "")) | ||
.lore(lore) | ||
.clearFlags() | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void onClick(Player player, ClickType clickType) { | ||
if (!player.hasPermission(killMessagePackage.permission())) return; | ||
plugin.getProfileManager().getByUUID(player.getUniqueId()).getSettingData().setKillMessagePackage(killMessagePackage); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Plugin/src/main/java/dev/lrxh/neptune/cosmetics/menu/killMessages/KillMessagesMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dev.lrxh.neptune.cosmetics.menu.killMessages; | ||
|
||
import dev.lrxh.neptune.configs.impl.MenusLocale; | ||
import dev.lrxh.neptune.cosmetics.impl.KillMessagePackage; | ||
import dev.lrxh.neptune.utils.menu.Button; | ||
import dev.lrxh.neptune.utils.menu.Filter; | ||
import dev.lrxh.neptune.utils.menu.Menu; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class KillMessagesMenu extends Menu { | ||
@Override | ||
public String getTitle(Player player) { | ||
return MenusLocale.KILL_MESSAGES_TITLE.getString(); | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return MenusLocale.KILL_MESSAGES_SIZE.getInt(); | ||
} | ||
|
||
@Override | ||
public Filter getFilter() { | ||
return Filter.valueOf(MenusLocale.KILL_MESSAGES_FILTER.getString()); | ||
} | ||
|
||
@Override | ||
public boolean isUpdateOnClick() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Map<Integer, Button> getButtons(Player player) { | ||
Map<Integer, Button> buttons = new HashMap<>(); | ||
|
||
for (KillMessagePackage killMessagePackage : plugin.getCosmeticManager().deathMessages.values()) { | ||
buttons.put(killMessagePackage.getSlot(), new KillMessageButton(killMessagePackage)); | ||
} | ||
|
||
return buttons; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.