Author SHA1 Message Date
redtea db70651bb6 Merge branch 'main' of https://github.com/iRedTea/NoDropX 2023-07-26 13:39:31 +03:00
redtea d66027cb9b 1.0.2a SNAPSHOT HOTFIX
Fix MiniMessages on 1.20.1
2023-07-26 13:39:22 +03:00
Denis Istratov fabd2de076 Update README.md 2023-07-26 00:08:50 +03:00
Denis Istratov 0a431430bd Update README.md 2023-07-26 00:08:36 +03:00
redtea bb779badf5 Merge branch 'main' of https://github.com/iRedTea/NoDropX 2023-07-25 18:54:14 +03:00
redtea f9068c71d9 1.0.2 SNAPSHOT
New commands, ItemsAdder support
2023-07-25 18:54:00 +03:00
26 changed files with 393 additions and 75 deletions

No files matched your search

+2 -1
View File
@@ -6,7 +6,8 @@ The plugin will allow you to create items that will not drop out of your invento
Give an no drop item: `/nodrop give [player] [item] (count)` <br> Give an no drop item: `/nodrop give [player] [item] (count)` <br>
Check all plugin commands: https://github.com/iRedTea/NoDropX/wiki/Commands <br> Check all plugin commands: https://github.com/iRedTea/NoDropX/wiki/Commands <br>
Plugin wiki: https://github.com/iRedTea/NoDropX/wiki Plugin wiki: https://github.com/iRedTea/NoDropX/wiki <br>
SpigotMC resource: https://www.spigotmc.org/resources/nodropx.111485/
**Features** **Features**
- Supports HEX Colors (MiniMessages and MD5 ChatColor) - Supports HEX Colors (MiniMessages and MD5 ChatColor)
+8 -4
View File
@@ -5,7 +5,7 @@ plugins {
} }
group = 'me.redtea' group = 'me.redtea'
version = '1.0.1-SNAPSHOT' version = '1.0.2a-SNAPSHOT-HOTFIX'
repositories { repositories {
mavenCentral() mavenCentral()
@@ -25,19 +25,23 @@ repositories {
name = "papermc-repo" name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/" url = "https://repo.papermc.io/repository/maven-public/"
} }
maven {
url 'https://jitpack.io'
}
} }
dependencies { dependencies {
implementation 'org.jetbrains:annotations:24.0.0' implementation "org.jetbrains:annotations:24.0.0"
compileOnly 'org.projectlombok:lombok:1.18.26' compileOnly "org.projectlombok:lombok:1.18.26"
annotationProcessor 'org.projectlombok:lombok:1.18.26' annotationProcessor 'org.projectlombok:lombok:1.18.26'
compileOnly "com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT" compileOnly "com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT"
implementation "me.mattstudios.utils:matt-framework:1.4" implementation "me.mattstudios.utils:matt-framework:1.4"
implementation 'de.tr7zw:item-nbt-api:2.11.3' implementation "de.tr7zw:item-nbt-api:2.11.3"
implementation "net.kyori:adventure-api:4.14.0" implementation "net.kyori:adventure-api:4.14.0"
implementation "net.kyori:adventure-platform-bukkit:4.3.0" implementation "net.kyori:adventure-platform-bukkit:4.3.0"
implementation files("libs/MiniMessages.jar") implementation files("libs/MiniMessages.jar")
implementation "dev.triumphteam:triumph-gui:3.1.2" implementation "dev.triumphteam:triumph-gui:3.1.2"
compileOnly "com.github.LoneDev6:API-ItemsAdder:3.5.0b"
} }
def targetJavaVersion = 8 def targetJavaVersion = 8
+26 -5
View File
@@ -18,14 +18,19 @@ import me.redtea.nodropx.libs.carcadex.repo.MutableRepo;
import me.redtea.nodropx.libs.carcadex.repo.Repo; import me.redtea.nodropx.libs.carcadex.repo.Repo;
import me.redtea.nodropx.libs.carcadex.repo.impl.yaml.YamlRepo; import me.redtea.nodropx.libs.carcadex.repo.impl.yaml.YamlRepo;
import me.redtea.nodropx.libs.message.container.Messages; import me.redtea.nodropx.libs.message.container.Messages;
import me.redtea.nodropx.libs.message.verifier.impl.FileMessageVerifier;
import me.redtea.nodropx.listener.InventoryHandler; import me.redtea.nodropx.listener.InventoryHandler;
import me.redtea.nodropx.listener.PlayerHandler; import me.redtea.nodropx.listener.PlayerHandler;
import me.redtea.nodropx.model.cosmetic.impl.DisplayNameCosmetic; import me.redtea.nodropx.model.cosmetic.impl.DisplayNameCosmetic;
import me.redtea.nodropx.model.materialprovider.impl.ItemStackProviderDefault;
import me.redtea.nodropx.model.materialprovider.impl.ItemsAdderProvider;
import me.redtea.nodropx.schema.ItemStackListSchema; import me.redtea.nodropx.schema.ItemStackListSchema;
import me.redtea.nodropx.service.cosmetic.CosmeticService; import me.redtea.nodropx.service.cosmetic.CosmeticService;
import me.redtea.nodropx.service.cosmetic.impl.CosmeticServiceImpl; import me.redtea.nodropx.service.cosmetic.impl.CosmeticServiceImpl;
import me.redtea.nodropx.service.event.EventService; import me.redtea.nodropx.service.event.EventService;
import me.redtea.nodropx.service.event.impl.EventServiceImpl; import me.redtea.nodropx.service.event.impl.EventServiceImpl;
import me.redtea.nodropx.service.material.ItemStackService;
import me.redtea.nodropx.service.material.impl.ItemStackServiceImpl;
import me.redtea.nodropx.service.nbt.NBTService; import me.redtea.nodropx.service.nbt.NBTService;
import me.redtea.nodropx.service.nbt.impl.Tr7zwNBTServiceImpl; import me.redtea.nodropx.service.nbt.impl.Tr7zwNBTServiceImpl;
import me.redtea.nodropx.service.nodrop.NoDropService; import me.redtea.nodropx.service.nodrop.NoDropService;
@@ -60,6 +65,8 @@ public final class NoDropX extends JavaPlugin {
private boolean supportHEX; private boolean supportHEX;
@Getter @Getter
private boolean supportKyoriLore; private boolean supportKyoriLore;
@Getter
private boolean supportItemsAdder;
private MutableRepo<UUID, List<ItemStack>> pagesRepo; private MutableRepo<UUID, List<ItemStack>> pagesRepo;
private Repo<String, List<Integer>> capacity; private Repo<String, List<Integer>> capacity;
@@ -74,6 +81,7 @@ public final class NoDropX extends JavaPlugin {
supportHEX = textContext.isSupportHex(); supportHEX = textContext.isSupportHex();
supportKyoriLore = textContext.isSupportKyori(); supportKyoriLore = textContext.isSupportKyori();
messages = supportKyoriLore ? Messages.of(textContext.getMessages()) : Messages.legacy(textContext.getMessages()); messages = supportKyoriLore ? Messages.of(textContext.getMessages()) : Messages.legacy(textContext.getMessages());
messages.setVerifier(new FileMessageVerifier(getResource(textContext.getPath()), YamlConfiguration.loadConfiguration(textContext.getMessages()), textContext.getMessages()));
cosmeticService = new CosmeticServiceImpl(); cosmeticService = new CosmeticServiceImpl();
cosmeticService.add(new DisplayNameCosmetic()); cosmeticService.add(new DisplayNameCosmetic());
@@ -98,14 +106,17 @@ public final class NoDropX extends JavaPlugin {
.schema(new ItemStackListSchema(new File(getDataFolder(), "storage"))) .schema(new ItemStackListSchema(new File(getDataFolder(), "storage")))
.plugin(this) .plugin(this)
.build(); .build();
ItemStackService itemStackService = initItemStackService();
GuiFacade guiFacade = new GuiFacadeImpl( GuiFacade guiFacade = new GuiFacadeImpl(
new StorageGui(messages, pagesRepo, noDropService, this) new StorageGui(messages, pagesRepo, noDropService, this, itemStackService)
); );
StorageService storageService = new StorageServiceImpl(guiFacade, pagesRepo, noDropService); StorageService storageService = new StorageServiceImpl(guiFacade, pagesRepo, noDropService);
NoDropAPI noDropAPI = new NoDropXFacade(noDropService, noDropItemFactory, storageService, capacity);
NoDropAPI noDropAPI = new NoDropXFacade(noDropService, noDropItemFactory, storageService, capacity, itemStackService);
noDropAPIInstance = noDropAPI; noDropAPIInstance = noDropAPI;
@@ -126,13 +137,23 @@ public final class NoDropX extends JavaPlugin {
commandManager.getMessageHandler().register("cmd.no.console", sender -> messages.get("noConsole").send(sender)); commandManager.getMessageHandler().register("cmd.no.console", sender -> messages.get("noConsole").send(sender));
commandManager.getMessageHandler().register("cmd.no.exists", sender -> messages.get("noExists").send(sender)); commandManager.getMessageHandler().register("cmd.no.exists", sender -> messages.get("noExists").send(sender));
commandManager.getMessageHandler().register("cmd.wrong.usage", sender -> messages.get("usage").send(sender)); commandManager.getMessageHandler().register("cmd.wrong.usage", sender -> messages.get("usage").send(sender));
commandManager.getCompletionHandler().register("#materials", input -> Arrays.stream(Material.values()).map(Enum::name).collect(Collectors.toList())); commandManager.getCompletionHandler().register("#materials", input -> itemStackService.allMaterials());
commandManager.register(new NoDropCommand(messages, noDropAPI, guiFacade, this)); commandManager.register(new NoDropCommand(messages, noDropAPI, guiFacade, this, itemStackService));
bStatsInit(); bStatsInit();
printCredits(); printCredits();
checkUpdates(); checkUpdates();
} }
private ItemStackService initItemStackService() {
ItemStackService result = new ItemStackServiceImpl();
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
supportItemsAdder = true;
getLogger().info(ChatColor.GREEN + "ItemsAdder found! Registering a CustomStack provider for it.");
result.registerProvider(new ItemsAdderProvider());
}
result.registerProvider(new ItemStackProviderDefault());
return result;
}
private void checkUpdates() { private void checkUpdates() {
if(!(getConfig().contains("checkForUpdates") && getConfig().getBoolean("checkForUpdates"))) { if(!(getConfig().contains("checkForUpdates") && getConfig().getBoolean("checkForUpdates"))) {
@@ -143,7 +164,7 @@ public final class NoDropX extends JavaPlugin {
getLogger().info("There is not a new update available."); getLogger().info("There is not a new update available.");
} else { } else {
getLogger().info("There is a new update available: " + version); getLogger().info("There is a new update available: " + version);
getLogger().info(". Download it from https://www.spigotmc.org/resources/nodropx.111485/"); getLogger().info("Download it from https://www.spigotmc.org/resources/nodropx.111485/");
} }
}); });
} }
@@ -1,5 +1,6 @@
package me.redtea.nodropx.api.facade; package me.redtea.nodropx.api.facade;
import lombok.val;
import me.redtea.nodropx.api.facade.manipulator.StorageManipulator; import me.redtea.nodropx.api.facade.manipulator.StorageManipulator;
import me.redtea.nodropx.util.MaterialUtils; import me.redtea.nodropx.util.MaterialUtils;
import org.bukkit.Material; import org.bukkit.Material;
@@ -22,7 +23,7 @@ public interface NoDropAPI {
* @author redtea * @author redtea
* @since 1.0.0 * @since 1.0.0
*/ */
void setNoDrop(@NotNull ItemStack item, boolean isNoDrop); ItemStack setNoDrop(@NotNull ItemStack item, boolean isNoDrop);
/** /**
* Check if item is no drop item * Check if item is no drop item
@@ -41,8 +42,20 @@ public interface NoDropAPI {
* @author redtea * @author redtea
* @since 1.0.0 * @since 1.0.0
*/ */
ItemStack getNoDrop(@NotNull Material material, int amount); default ItemStack getNoDrop(@NotNull Material material, int amount) {
val item = new ItemStack(material, amount);
setNoDrop(item, true);
return item;
}
/**
* Gives the entity no drop item
* @param entity who will get no drop item
* @param item no drop item
* @author redtea
* @since 1.0.0
*/
void giveNoDrop(@NotNull HumanEntity entity, @NotNull ItemStack item);
/** /**
* Gives the entity no drop item * Gives the entity no drop item
@@ -52,7 +65,9 @@ public interface NoDropAPI {
* @author redtea * @author redtea
* @since 1.0.0 * @since 1.0.0
*/ */
void giveNoDrop(@NotNull HumanEntity entity, @NotNull Material material, int amount); default void giveNoDrop(@NotNull HumanEntity entity, @NotNull Material material, int amount) {
giveNoDrop(entity, getNoDrop(material, amount));
}
/** /**
* returns an object for accessing the storage of a player with UUID playerUniqueId * returns an object for accessing the storage of a player with UUID playerUniqueId
@@ -64,7 +79,7 @@ public interface NoDropAPI {
@NotNull StorageManipulator getStorageManipulator(@NotNull UUID playerUniqueId); @NotNull StorageManipulator getStorageManipulator(@NotNull UUID playerUniqueId);
/** /**
* returns the slot numbers that an no drop item with this material saves at death * returns the slot numbers that no drop item with this material saves at death
* @param material material to check * @param material material to check
* @return numbers of saved slots * @return numbers of saved slots
* @author redtea * @author redtea
@@ -75,9 +90,7 @@ public interface NoDropAPI {
/** /**
* @see NoDropAPI#getCapacitySlots(Material) * @see NoDropAPI#getCapacitySlots(Material)
*/ */
default @NotNull Collection<Integer> getCapacitySlots(String material) { @NotNull Collection<Integer> getCapacitySlots(String material);
return getCapacitySlots(MaterialUtils.getMaterialFromString(material));
}
/** /**
* @see NoDropAPI#getStorageManipulator(UUID) * @see NoDropAPI#getStorageManipulator(UUID)
@@ -89,9 +102,7 @@ public interface NoDropAPI {
/** /**
* @see NoDropAPI#giveNoDrop(HumanEntity, Material, int) * @see NoDropAPI#giveNoDrop(HumanEntity, Material, int)
*/ */
default void giveNoDrop(@NotNull HumanEntity entity, @NotNull String material, int amount) { void giveNoDrop(@NotNull HumanEntity entity, @NotNull String material, int amount);
giveNoDrop(entity, MaterialUtils.getMaterialFromString(material), amount);
}
/** /**
* @see NoDropAPI#giveNoDrop(HumanEntity, Material, int) * @see NoDropAPI#giveNoDrop(HumanEntity, Material, int)
@@ -110,9 +121,7 @@ public interface NoDropAPI {
/** /**
* @see NoDropAPI#getNoDrop(Material, int) * @see NoDropAPI#getNoDrop(Material, int)
*/ */
default @NotNull ItemStack getNoDrop(@NotNull String material, int amount) { @NotNull ItemStack getNoDrop(@NotNull String material, int amount);
return getNoDrop(MaterialUtils.getMaterialFromString(material), amount);
}
/** /**
* @see NoDropAPI#getNoDrop(Material, int) * @see NoDropAPI#getNoDrop(Material, int)
@@ -5,6 +5,7 @@ import me.redtea.nodropx.api.facade.manipulator.StorageManipulator;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.redtea.nodropx.factory.item.NoDropItemFactory; import me.redtea.nodropx.factory.item.NoDropItemFactory;
import me.redtea.nodropx.libs.carcadex.repo.Repo; import me.redtea.nodropx.libs.carcadex.repo.Repo;
import me.redtea.nodropx.service.material.ItemStackService;
import me.redtea.nodropx.service.nodrop.NoDropService; import me.redtea.nodropx.service.nodrop.NoDropService;
import me.redtea.nodropx.service.storage.StorageService; import me.redtea.nodropx.service.storage.StorageService;
import org.bukkit.Material; import org.bukkit.Material;
@@ -24,10 +25,12 @@ public class NoDropXFacade implements NoDropAPI {
private final NoDropItemFactory itemFactory; private final NoDropItemFactory itemFactory;
private final StorageService storageService; private final StorageService storageService;
private final Repo<String, List<Integer>> capacity; private final Repo<String, List<Integer>> capacity;
private final ItemStackService itemStackService;
@Override @Override
public void setNoDrop(@NotNull ItemStack item, boolean isNoDrop) { public ItemStack setNoDrop(@NotNull ItemStack item, boolean isNoDrop) {
noDropService.setNoDrop(item, isNoDrop); noDropService.setNoDrop(item, isNoDrop);
return item;
} }
@Override @Override
@@ -41,6 +44,11 @@ public class NoDropXFacade implements NoDropAPI {
return itemFactory.createNoDrop(material, amount); return itemFactory.createNoDrop(material, amount);
} }
@Override
public void giveNoDrop(@NotNull HumanEntity entity, @NotNull ItemStack item) {
entity.getInventory().addItem(setNoDrop(item, true));
}
@Override @Override
public void giveNoDrop(@NotNull HumanEntity entity, @NotNull Material material, int amount) { public void giveNoDrop(@NotNull HumanEntity entity, @NotNull Material material, int amount) {
entity.getInventory().addItem(getNoDrop(material, amount)); entity.getInventory().addItem(getNoDrop(material, amount));
@@ -70,4 +78,19 @@ public class NoDropXFacade implements NoDropAPI {
public @NotNull Collection<Integer> getCapacitySlots(Material material) { public @NotNull Collection<Integer> getCapacitySlots(Material material) {
return capacity.get(material.name()).orElse(new ArrayList<>()); return capacity.get(material.name()).orElse(new ArrayList<>());
} }
@Override
public @NotNull Collection<Integer> getCapacitySlots(String material) {
return getCapacitySlots(itemStackService.get(material, 1).getType());
}
@Override
public void giveNoDrop(@NotNull HumanEntity entity, @NotNull String material, int amount) {
giveNoDrop(entity, itemStackService.get(material, amount));
}
@Override
public @NotNull ItemStack getNoDrop(@NotNull String material, int amount) {
return setNoDrop(itemStackService.get(material, amount), true);
}
} }
@@ -1,14 +1,19 @@
package me.redtea.nodropx.command; package me.redtea.nodropx.command;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val;
import me.mattstudios.mf.annotations.*; import me.mattstudios.mf.annotations.*;
import me.mattstudios.mf.base.CommandBase; import me.mattstudios.mf.base.CommandBase;
import me.redtea.nodropx.NoDropX; import me.redtea.nodropx.NoDropX;
import me.redtea.nodropx.api.facade.NoDropAPI; import me.redtea.nodropx.api.facade.NoDropAPI;
import me.redtea.nodropx.gui.facade.GuiFacade; import me.redtea.nodropx.gui.facade.GuiFacade;
import me.redtea.nodropx.libs.message.container.Messages; import me.redtea.nodropx.libs.message.container.Messages;
import me.redtea.nodropx.service.material.ItemStackService;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.Date; import java.util.Date;
@@ -24,6 +29,7 @@ public class NoDropCommand extends CommandBase {
private final NoDropAPI noDropAPI; private final NoDropAPI noDropAPI;
private final GuiFacade guiFacade; private final GuiFacade guiFacade;
private final NoDropX plugin; private final NoDropX plugin;
private final ItemStackService itemStackService;
@Default @Default
public void onDefault(final CommandSender sender) { public void onDefault(final CommandSender sender) {
@@ -31,18 +37,18 @@ public class NoDropCommand extends CommandBase {
} }
@SubCommand("give") @SubCommand("give")
@Permission("R") @Permission("nodropx.give")
@Completion({"#players", "#materials", "#range:1-64"}) @Completion({"#players", "#materials", "#range:1-64"})
public void onGive(final CommandSender sender, public void onGive(final CommandSender sender,
final Player player, final Player player,
final String material, final String material,
@Optional final Integer amount) { @Optional final Integer amount) {
try { try {
noDropAPI.giveNoDrop(player, material, amount == null ? 1 : amount); noDropAPI.giveNoDrop(player, material, amount == null || amount == 0 ? 1 : amount);
messages.get("give.success") messages.get("give.success")
.replaceAll("%item%", material) .replaceAll("%item%", material)
.replaceAll("%player%", player.getName()) .replaceAll("%player%", player.getName())
.replaceAll("%amount%", amount == null ? "0" : amount.toString()) .replaceAll("%amount%", amount == null ? "1" : amount.toString())
.send(sender); .send(sender);
} catch (Throwable e) { } catch (Throwable e) {
messages.get("give.fail").send(sender); messages.get("give.fail").send(sender);
@@ -58,9 +64,53 @@ public class NoDropCommand extends CommandBase {
messages.get("reload").replaceAll("%time%", String.valueOf(new Date().getTime() - time)).send(sender); messages.get("reload").replaceAll("%time%", String.valueOf(new Date().getTime() - time)).send(sender);
} }
@SubCommand("giveStorage")
@Permission("nodropx.giveStorage")
@Completion({"#players", "#materials", "#range:1-64"})
public void onGiveStorage(final CommandSender sender,
String playerName,
final String material,
@Optional Integer amount) {
try {
val item = noDropAPI.setNoDrop(itemStackService.get(material, amount == null || amount == 0 ? 1 : amount), true);
val player = getOfflinePlayer(playerName);
if(player == null) {
messages.get("noExists").send(sender);
return;
}
noDropAPI.getStorageManipulator(player).add(item);
messages.get("giveToStorage.success")
.replaceAll("%item%", material)
.replaceAll("%player%", playerName)
.replaceAll("%amount%", amount == null ? "0" : amount.toString())
.send(sender);
} catch (Throwable e) {
messages.get("giveToStorage.fail").send(sender);
}
}
@SubCommand("applyHand")
@Permission("nodropx.applyhand")
public void onApplyHand(final Player sender) {
try {
noDropAPI.setNoDrop(sender.getInventory().getItemInMainHand(), true);
messages.get("applyHand.success").send(sender);
} catch (Throwable e) {
messages.get("applyHand.fail").send(sender);
}
}
@SubCommand("gui") @SubCommand("gui")
@Permission("nodropx.gui") @Permission("nodropx.gui")
public void onGui(final Player sender) { public void onGui(final Player sender) {
guiFacade.openNoDropStorage(sender); guiFacade.openNoDropStorage(sender);
} }
@Nullable
private OfflinePlayer getOfflinePlayer(String name) {
for(OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if(player.getName() != null && player.getName().equalsIgnoreCase(name)) return player;
}
return null;
}
} }
@@ -12,4 +12,5 @@ public class TextContext {
private final File cosmetics; private final File cosmetics;
private final boolean supportHex; private final boolean supportHex;
private final boolean supportKyori; private final boolean supportKyori;
private final String path;
} }
@@ -55,7 +55,7 @@ public class TextServicesFactoryImpl implements TextServicesFactory {
cosmeticStrategy = new LoreMD5Cosmetics(); cosmeticStrategy = new LoreMD5Cosmetics();
} else cosmeticStrategy = new LoreKyoriCosmetic(); } else cosmeticStrategy = new LoreKyoriCosmetic();
return new TextContext(cosmeticStrategy, messages, cosmetics, isSupportHEX, isSupportKyoriLore); return new TextContext(cosmeticStrategy, messages, cosmetics, isSupportHEX, isSupportKyoriLore, "text/" + folder + "/messages.yml");
} }
@@ -7,6 +7,7 @@ import dev.triumphteam.gui.guis.ScrollingGui;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.redtea.nodropx.libs.carcadex.repo.MutableRepo; import me.redtea.nodropx.libs.carcadex.repo.MutableRepo;
import me.redtea.nodropx.libs.message.container.Messages; import me.redtea.nodropx.libs.message.container.Messages;
import me.redtea.nodropx.service.material.ItemStackService;
import me.redtea.nodropx.service.nodrop.NoDropService; import me.redtea.nodropx.service.nodrop.NoDropService;
import me.redtea.nodropx.util.MaterialUtils; import me.redtea.nodropx.util.MaterialUtils;
import org.bukkit.Material; import org.bukkit.Material;
@@ -27,6 +28,7 @@ public class StorageGui {
private final MutableRepo<UUID, List<ItemStack>> pagesRepo; private final MutableRepo<UUID, List<ItemStack>> pagesRepo;
private final NoDropService noDropService; private final NoDropService noDropService;
private final Plugin plugin; private final Plugin plugin;
private final ItemStackService itemStackService;
public void open(Player player) { public void open(Player player) {
if(cache.containsKey(player.getUniqueId())) { if(cache.containsKey(player.getUniqueId())) {
@@ -108,20 +110,20 @@ public class StorageGui {
private void setFrame(ScrollingGui gui) { private void setFrame(ScrollingGui gui) {
for(int i = 1; i < 10; ++i) { for(int i = 1; i < 10; ++i) {
gui.setItem(6, i, ItemBuilder.from( gui.setItem(6, i, ItemBuilder.from(
MaterialUtils.getMaterialFromString(messages.get("gui.frame.material").asUnparsedString()) itemStackService.get(messages.get("gui.frame.material").asUnparsedString(), 1)
).name(messages.get("gui.frame.name").asComponent()).asGuiItem(event -> event.setCancelled(true))); ).name(messages.get("gui.frame.name").asComponent()).asGuiItem(event -> event.setCancelled(true)));
} }
} }
private void setButtons(ScrollingGui gui) { private void setButtons(ScrollingGui gui) {
gui.setItem(6, 3, ItemBuilder.from( gui.setItem(6, 3, ItemBuilder.from(
MaterialUtils.getMaterialFromString(messages.get("gui.prev.material").asUnparsedString()) itemStackService.get(messages.get("gui.prev.material").asUnparsedString(), 1)
).name(messages.get("gui.prev.name").asComponent()).asGuiItem(event -> { ).name(messages.get("gui.prev.name").asComponent()).asGuiItem(event -> {
gui.previous(); gui.previous();
event.setCancelled(true); event.setCancelled(true);
})); }));
gui.setItem(6, 7, ItemBuilder.from( gui.setItem(6, 7, ItemBuilder.from(
MaterialUtils.getMaterialFromString(messages.get("gui.next.material").asUnparsedString()) itemStackService.get(messages.get("gui.next.material").asUnparsedString(), 1)
).name(messages.get("gui.next.name").asComponent()).asGuiItem(event -> { ).name(messages.get("gui.next.name").asComponent()).asGuiItem(event -> {
gui.next(); gui.next();
event.setCancelled(true); event.setCancelled(true);
@@ -5,6 +5,7 @@ import me.redtea.nodropx.libs.message.factory.MessageFactory;
import me.redtea.nodropx.libs.message.factory.impl.LegacyFactoryImpl; import me.redtea.nodropx.libs.message.factory.impl.LegacyFactoryImpl;
import me.redtea.nodropx.libs.message.model.Message; import me.redtea.nodropx.libs.message.model.Message;
import me.redtea.nodropx.libs.message.model.impl.NullMessage; import me.redtea.nodropx.libs.message.model.impl.NullMessage;
import me.redtea.nodropx.libs.message.verifier.MessageVerifier;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@@ -119,7 +120,11 @@ public interface Messages {
/** /**
* <h1>Sets custom message parse factory.</h1> * <h1>Sets custom message parse factory.</h1>
*/ */
void factory(MessageFactory messageFactory); Messages factory(MessageFactory messageFactory);
Messages init();
void setVerifier(MessageVerifier verifier);
/** /**
* <h1>Create container using configuration section</h1> * <h1>Create container using configuration section</h1>
@@ -134,7 +139,7 @@ public interface Messages {
* @return container with messages * @return container with messages
*/ */
static Messages of(ConfigurationSection section) { static Messages of(ConfigurationSection section) {
return new MessagesImpl(section); return new MessagesImpl(section).init();
} }
/** /**
@@ -168,7 +173,7 @@ public interface Messages {
* @return container with messages * @return container with messages
*/ */
static Messages of(Plugin plugin) { static Messages of(Plugin plugin) {
return of(plugin, "text/legacy/messages.yml"); return of(plugin, "messages.yml");
} }
/** /**
@@ -202,28 +207,24 @@ public interface Messages {
* @return container with messages * @return container with messages
*/ */
static Messages legacy(ConfigurationSection section) { static Messages legacy(ConfigurationSection section) {
return asLegacy(of(section)); return new MessagesImpl(section).factory(new LegacyFactoryImpl()).init();
} }
/** @see Messages#legacy(ConfigurationSection) */ /** @see Messages#legacy(ConfigurationSection) */
static Messages legacy(Plugin plugin, String fileName) { static Messages legacy(Plugin plugin, String fileName) {
return asLegacy(of(plugin, fileName)); File file = new File(plugin.getDataFolder(), fileName);
if(!file.exists()) plugin.saveResource(fileName, false);
return new MessagesImpl(file).factory(new LegacyFactoryImpl()).init();
} }
/** @see Messages#legacy(ConfigurationSection) */ /** @see Messages#legacy(ConfigurationSection) */
static Messages legacy(Plugin plugin) { static Messages legacy(Plugin plugin) {
return asLegacy(of(plugin)); return legacy(plugin, "messages.yml");
} }
/** @see Messages#legacy(ConfigurationSection) */ /** @see Messages#legacy(ConfigurationSection) */
static Messages legacy(File file) { static Messages legacy(File file) {
return asLegacy(of(file)); return new MessagesImpl(file).factory(new LegacyFactoryImpl()).init();
}
/** @see Messages#legacy(ConfigurationSection) */
static Messages asLegacy(Messages messages) {
messages.factory(new LegacyFactoryImpl());
return messages;
} }
/** /**
@@ -1,5 +1,7 @@
package me.redtea.nodropx.libs.message.container.impl; package me.redtea.nodropx.libs.message.container.impl;
import lombok.Setter;
import me.redtea.nodropx.libs.message.verifier.MessageVerifier;
import me.redtea.nodropx.libs.message.container.Messages; import me.redtea.nodropx.libs.message.container.Messages;
import me.redtea.nodropx.libs.message.factory.MessageFactory; import me.redtea.nodropx.libs.message.factory.MessageFactory;
import me.redtea.nodropx.libs.message.model.Message; import me.redtea.nodropx.libs.message.model.Message;
@@ -11,6 +13,7 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
public class MessagesImpl implements Messages { public class MessagesImpl implements Messages {
private Map<String, Message> messages; private Map<String, Message> messages;
@@ -19,25 +22,51 @@ public class MessagesImpl implements Messages {
private final Message NULL_MESSAGE = factory.nullMessage(); private final Message NULL_MESSAGE = factory.nullMessage();
private ConfigurationSection section;
@Setter
private MessageVerifier verifier;
public MessagesImpl() { public MessagesImpl() {
} }
public MessagesImpl(@NotNull ConfigurationSection section) { public MessagesImpl(@NotNull ConfigurationSection section) {
messages = fromConfigurationToMap(section); this.section = section;
}
public MessagesImpl(@NotNull ConfigurationSection section, MessageVerifier verifier) {
this.section = section;
this.verifier = verifier;
} }
public MessagesImpl(@NotNull File file) { public MessagesImpl(@NotNull File file) {
this(YamlConfiguration.loadConfiguration(file)); this(YamlConfiguration.loadConfiguration(file));
} }
public MessagesImpl(@NotNull File file, MessageVerifier verifier) {
this(YamlConfiguration.loadConfiguration(file));
this.verifier = verifier;
}
@Override @Override
public Message get(String key) { public Message get(String key) {
return messages.get(key); if(!has(key)) {
if(verifier != null) {
Optional<String> def = verifier.fromDefault(key);
if(def.isPresent()) {
messages.put(key, factory.message(def.get()));
return messages.get(key);
}
return NULL_MESSAGE;
}
return NULL_MESSAGE;
}
return messages.get(key) == null ? NULL_MESSAGE : messages.get(key);
} }
@Override @Override
public Message put(String key, Message message) { public Message put(String key, Message message) {
if(!has(key)) return NULL_MESSAGE;
return messages.put(key, message); return messages.put(key, message);
} }
@@ -52,8 +81,15 @@ public class MessagesImpl implements Messages {
} }
@Override @Override
public void factory(MessageFactory messageFactory) { public Messages factory(MessageFactory messageFactory) {
this.factory = messageFactory; this.factory = messageFactory;
return this;
}
@Override
public Messages init() {
messages = fromConfigurationToMap(section);
return this;
} }
private Map<String, Message> fromConfigurationToMap(@NotNull ConfigurationSection section) { private Map<String, Message> fromConfigurationToMap(@NotNull ConfigurationSection section) {
@@ -38,7 +38,6 @@ public abstract class AbstractMessage implements Message {
parse(); parse();
Audience audience = adventure.sender(sender); Audience audience = adventure.sender(sender);
parsed.forEach(audience::sendMessage); parsed.forEach(audience::sendMessage);
} }
private Component cacheComponent = null; private Component cacheComponent = null;
@@ -7,7 +7,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.List; import java.util.List;
public class ComponentMessage extends AbstractMessage { public class ComponentMessage extends AbstractMessage {
private final MiniMessage mm = MiniMessage.get(); private final MiniMessage mm = MiniMessage.builder().build();
public ComponentMessage(List<String> unparsed) { public ComponentMessage(List<String> unparsed) {
super(unparsed); super(unparsed);
@@ -0,0 +1,7 @@
package me.redtea.nodropx.libs.message.verifier;
import java.util.Optional;
public interface MessageVerifier {
Optional<String> fromDefault(String key);
}
@@ -0,0 +1,38 @@
package me.redtea.nodropx.libs.message.verifier.impl;
import lombok.SneakyThrows;
import me.redtea.nodropx.libs.message.verifier.MessageVerifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Optional;
public class FileMessageVerifier implements MessageVerifier {
private ConfigurationSection defaultSection;
private final FileConfiguration toSaveSection;
private final File toSaveFile;
public FileMessageVerifier(InputStream defaultResource, FileConfiguration toSaveSection, File toSaveFile) {
defaultSection = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultResource));
this.toSaveSection = toSaveSection;
this.toSaveFile = toSaveFile;
}
@Override
public Optional<String> fromDefault(String key) {
Optional<String> o = Optional.ofNullable(defaultSection.getString(key));
o.ifPresent(s -> saveToMain(key, s));
return o;
}
@SneakyThrows
public void saveToMain(String path, Object obj) {
toSaveSection.set(path, obj);
toSaveSection.save(toSaveFile);
}
}
@@ -12,7 +12,7 @@ import java.util.stream.Collectors;
public class LoreKyoriCosmetic implements CosmeticStrategy { public class LoreKyoriCosmetic implements CosmeticStrategy {
private List<Component> lore; private List<Component> lore;
private final MiniMessage mm = MiniMessage.get(); private final MiniMessage mm = MiniMessage.builder().build();
@Override @Override
public void apply(ItemStack itemStack) { public void apply(ItemStack itemStack) {
List<Component> lore = itemStack.lore(); List<Component> lore = itemStack.lore();
@@ -0,0 +1,10 @@
package me.redtea.nodropx.model.materialprovider;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public interface ItemStackProvider {
ItemStack get(String s);
List<String> allMaterials();
}
@@ -0,0 +1,36 @@
package me.redtea.nodropx.model.materialprovider.impl;
import me.redtea.nodropx.model.materialprovider.ItemStackProvider;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class ItemStackProviderDefault implements ItemStackProvider {
@Override
public ItemStack get(String s) {
if(s == null || s.equals("")) return new ItemStack(Material.AIR);
Material material = Material.matchMaterial(s);
if(material != null) return new ItemStack(material);
String[] spl = s.split(":");
if (spl[0].equals("minecraft")) {
material = Material.matchMaterial(spl[1]);
} else {
if(spl.length < 2) {
material = Material.matchMaterial(spl[0]);
} else {
material = Material.matchMaterial(spl[0]+"_"+spl[1]);;
}
}
return new ItemStack(material == null ? Material.AIR : material);
}
@Override
public List<String> allMaterials() {
return Arrays.stream(Material.values()).map(Enum::name).collect(Collectors.toList());
}
}
@@ -0,0 +1,21 @@
package me.redtea.nodropx.model.materialprovider.impl;
import dev.lone.itemsadder.api.CustomStack;
import dev.lone.itemsadder.api.ItemsAdder;
import me.redtea.nodropx.model.materialprovider.ItemStackProvider;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.stream.Collectors;
public class ItemsAdderProvider implements ItemStackProvider {
@Override
public ItemStack get(String s) {
return CustomStack.getInstance(s).getItemStack();
}
@Override
public List<String> allMaterials() {
return ItemsAdder.getAllItems().stream().map(CustomStack::getNamespacedID).collect(Collectors.toList());
}
}
@@ -0,0 +1,16 @@
package me.redtea.nodropx.service.material;
import me.redtea.nodropx.model.materialprovider.ItemStackProvider;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface ItemStackService {
@NotNull
ItemStack get(String s, int amount);
void registerProvider(ItemStackProvider provider);
List<String> allMaterials();
}
@@ -0,0 +1,42 @@
package me.redtea.nodropx.service.material.impl;
import lombok.val;
import me.redtea.nodropx.model.materialprovider.ItemStackProvider;
import me.redtea.nodropx.service.material.ItemStackService;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ItemStackServiceImpl implements ItemStackService {
private final List<ItemStackProvider> providers = new ArrayList<>();
@Override
public @NotNull ItemStack get(String s, int amount) {
ItemStack result = new ItemStack(Material.AIR);
for(ItemStackProvider provider : providers) {
val i = provider.get(s);
if(i != null && i.getType() != Material.AIR) {
result = i;
break;
}
}
result.setAmount(amount);
return result;
}
@Override
public void registerProvider(ItemStackProvider provider) {
providers.add(provider);
}
private List<String> materials = null;
@Override
public List<String> allMaterials() {
if(materials == null) materials = providers.stream().map(ItemStackProvider::allMaterials).flatMap(List::stream).collect(Collectors.toList());
return materials;
}
}
@@ -7,27 +7,6 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class MaterialUtils { public class MaterialUtils {
@NotNull
public static Material getMaterialFromString(String s) {
if(s == null || s.equals("")) return Material.AIR;
Material material = Material.matchMaterial(s);
if(material != null) return material;
String[] spl = s.split(":");
if (spl[0].equals("minecraft")) {
material = Material.matchMaterial(spl[1]);
} else {
if(spl.length < 2) {
material = Material.matchMaterial(spl[0]);
} else {
material = Material.matchMaterial(spl[0]+"_"+spl[1]);;
}
}
return material == null ? Material.AIR : material;
}
public void remove(Inventory inventory, Material type, int amount) { public void remove(Inventory inventory, Material type, int amount) {
if (amount <= 0) return; if (amount <= 0) return;
int size = inventory.getSize(); int size = inventory.getSize();
+7 -2
View File
@@ -5,6 +5,7 @@ api-version: '1.13'
description: Set no drop status to your items description: Set no drop status to your items
author: itzRedTea author: itzRedTea
authors: [itzRedTea] authors: [itzRedTea]
softdepend: [ItemsAdder]
permissions: permissions:
nodropx.give: nodropx.give:
@@ -12,5 +13,9 @@ permissions:
nodropx.reload: nodropx.reload:
description: "Allows reload the plugin" description: "Allows reload the plugin"
nodropx.gui: nodropx.gui:
escription: "Allows open no drop gui" description: "Allows open no drop gui"
default: true default: true
nodropx.giveStorage:
description: "Allows give to storage"
nodropx.applyhand:
description: "Allows apply no drop to item in main hand"
@@ -5,6 +5,12 @@ give:
fail: "&4[!] &cFail! Check item type for valid." fail: "&4[!] &cFail! Check item type for valid."
success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a!" success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a!"
reload: "&aPlugin successfully reloaded at %time% ms" reload: "&aPlugin successfully reloaded at %time% ms"
applyHand:
fail: "&4&l[!] &cFailed to apply no drop!"
success: "&2&l[!] &aSuccessfully applied no drop status to your item!"
giveToStorage:
fail: "&4[!] &cFail! Check item type for valid."
success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a to storage!"
noPerms: "&4&l[!] &cNo perms for this!" noPerms: "&4&l[!] &cNo perms for this!"
noConsole: "&4&l[!] &cOnly players can use it!" noConsole: "&4&l[!] &cOnly players can use it!"
+6
View File
@@ -5,6 +5,12 @@ give:
fail: "&4[!] &cFail! Check item type for valid." fail: "&4[!] &cFail! Check item type for valid."
success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a!" success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a!"
reload: "&aPlugin successfully reloaded at %time% ms" reload: "&aPlugin successfully reloaded at %time% ms"
applyHand:
fail: "&4&l[!] &cFailed to apply no drop!"
success: "&2&l[!] &aSuccessfully applied no drop status to your item!"
giveToStorage:
fail: "&4[!] &cFail! Check item type for valid."
success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a to storage!"
noPerms: "&4&l[!] &cNo perms for this!" noPerms: "&4&l[!] &cNo perms for this!"
noConsole: "&4&l[!] &cOnly players can use it!" noConsole: "&4&l[!] &cOnly players can use it!"
+6 -1
View File
@@ -5,7 +5,12 @@ give:
fail: "<dark_red><bold>[!] <red>Fail! Check item type for valid." fail: "<dark_red><bold>[!] <red>Fail! Check item type for valid."
success: "<green><bold>[!] <reset><green>Gived <yellow>%item%<green> to <yellow>%player%<green> amount <yellow>%amount%<green>!" success: "<green><bold>[!] <reset><green>Gived <yellow>%item%<green> to <yellow>%player%<green> amount <yellow>%amount%<green>!"
reload: "<green>Plugin successfully reloaded at %time% ms" reload: "<green>Plugin successfully reloaded at %time% ms"
applyHand:
fail: "<dark_red><bold>[!] <red>Failed to apply no drop!"
success: "<green><bold>[!] <reset><green>Successfully applied no drop status to your item!"
giveToStorage:
fail: "<dark_red><bold>[!] <red>Fail! Check item type for valid."
success: "<green><bold>[!] <reset><green>Gived <yellow>%item%<green> to <yellow>%player%<green> amount <yellow>%amount%<green> to storage!"
noPerms: "<dark_red><bold>[!] <red>No perms for this!" noPerms: "<dark_red><bold>[!] <red>No perms for this!"
noConsole: "<dark_red><bold>[!] <red>Only players can use it!" noConsole: "<dark_red><bold>[!] <red>Only players can use it!"