Compare commits
10
Commits
61873f6dd7
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af920884aa | ||
|
|
48b3955add | ||
|
|
50bb40d701 | ||
|
|
5cd86f3850 | ||
|
|
4fb73836f3 | ||
|
|
6015933000 | ||
|
|
395037cba5 | ||
|
|
c307386645 | ||
|
|
e5ea0c1ae2 | ||
|
|
8f3565dd95 |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
# NoDropX
|
||||
Give no drop items!
|
||||
=======
|
||||
<img src="https://i.imgur.com/4KNCfzl.png"></img>
|
||||
<img src="https://i.imgur.com/PMxKZEP.png"></img>
|
||||
|
||||
# NoDropX
|
||||
**Give no drop items!**
|
||||
@@ -23,6 +23,7 @@ SpigotMC resource: https://www.spigotmc.org/resources/nodropx.111485/
|
||||
- Mods support (tested on Arclight 1.16.5)
|
||||
- ItemsAdder support
|
||||
- Folia support
|
||||
- Items thats protect all items in inventory from death
|
||||
|
||||
|
||||
This plugin uses <a href="https://github.com/iRedTea/CarcadeX">CarcadeX</a> library
|
||||
+22
-12
@@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'me.redtea'
|
||||
version = '1.0.3c-SNAPSHOT'
|
||||
version = '1.1.2-STABLE'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -17,6 +17,10 @@ repositories {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/groups/public/"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
maven {
|
||||
name = "CodeMC"
|
||||
url = uri("https://repo.codemc.io/repository/maven-public/")
|
||||
@@ -28,6 +32,9 @@ repositories {
|
||||
maven {
|
||||
url 'https://jitpack.io'
|
||||
}
|
||||
maven {
|
||||
url = "https://repo.triumphteam.dev/snapshots/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -35,13 +42,16 @@ dependencies {
|
||||
compileOnly "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"
|
||||
implementation "me.mattstudios.utils:matt-framework:1.4"
|
||||
implementation "de.tr7zw:item-nbt-api:2.11.3"
|
||||
implementation "net.kyori:adventure-api:4.14.0"
|
||||
// implementation "tech.carcadex:kotlinbukkitkit-commands:1.0.0.4b-SNAPSHOT"
|
||||
implementation "de.tr7zw:item-nbt-api:2.15.3"
|
||||
implementation "net.kyori:adventure-api:4.25.0"
|
||||
implementation "net.kyori:adventure-platform-bukkit:4.3.0"
|
||||
implementation files("libs/MiniMessages.jar")
|
||||
implementation "dev.triumphteam:triumph-gui:3.1.2"
|
||||
compileOnly "com.github.LoneDev6:API-ItemsAdder:3.5.0b"
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.25.0")
|
||||
implementation "dev.triumphteam:triumph-gui:3.1.13"
|
||||
implementation "dev.triumphteam:triumph-cmd-bukkit:2.0.0-BETA-4"
|
||||
implementation("beer.devs:FastNbt-jar:1.4.15")
|
||||
|
||||
compileOnly "com.github.LoneDev6:API-ItemsAdder:3.6.1"
|
||||
compileOnly files("libs/nodropxforgebridge-1.4.jar")
|
||||
}
|
||||
|
||||
@@ -61,6 +71,8 @@ tasks.withType(JavaCompile).configureEach {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
processResources {
|
||||
def props = [version: version]
|
||||
inputs.properties props
|
||||
@@ -72,10 +84,8 @@ processResources {
|
||||
|
||||
|
||||
shadowJar {
|
||||
relocate 'de.tr7zw.changeme.nbtapi', 'me.redtea.nodropx.libs.tr7zw.nbt'
|
||||
relocate 'de.tr7zw.annotations', 'me.redtea.nodropx.libs.tr7zw.annotations'
|
||||
relocate 'me.mattstudios.mf', 'me.redtea.nodropx.libs.commands'
|
||||
relocate 'dev.triumphteam', 'me.redtea.nodropx.libs.gui'
|
||||
relocate 'de.tr7zw', 'me.redtea.nodropx.libs.tr7zw'
|
||||
relocate 'dev.triumphteam', 'me.redtea.nodropx.libs.triumphteam'
|
||||
relocate 'org.checkerframework', 'me.redtea.nodropx.libs.message.oskarsmc.libs.checker'
|
||||
relocate 'org.intellij', 'me.redtea.nodropx.libs.intellij'
|
||||
relocate 'org.jetbrains', 'me.redtea.nodropx.libs.jetbrains'}
|
||||
@@ -83,6 +93,6 @@ shadowJar {
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
minecraftVersion("1.16.5")
|
||||
minecraftVersion("1.12.2")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,7 +1,13 @@
|
||||
package me.redtea.nodropx;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.BukkitCommandManager;
|
||||
import dev.triumphteam.cmd.core.argument.keyed.Argument;
|
||||
import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey;
|
||||
import dev.triumphteam.cmd.core.message.MessageKey;
|
||||
import dev.triumphteam.cmd.core.suggestion.SuggestionContext;
|
||||
import dev.triumphteam.cmd.core.suggestion.SuggestionKey;
|
||||
import dev.triumphteam.cmd.core.suggestion.SuggestionResolver;
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import me.redtea.nodropx.api.facade.NoDropAPI;
|
||||
import me.redtea.nodropx.api.facade.impl.NoDropXFacade;
|
||||
import me.redtea.nodropx.command.NoDropCommand;
|
||||
@@ -25,6 +31,7 @@ import me.redtea.nodropx.menu.Menu;
|
||||
import me.redtea.nodropx.menu.dropconfirm.DropConfirmMFGui;
|
||||
import me.redtea.nodropx.menu.facade.MenuFacade;
|
||||
import me.redtea.nodropx.menu.facade.impl.MenuFacadeImpl;
|
||||
import me.redtea.nodropx.menu.facade.impl.NullMenuFacadeImpl;
|
||||
import me.redtea.nodropx.menu.storage.pages.MFPageGui;
|
||||
import me.redtea.nodropx.menu.storage.singlepage.SinglePageController;
|
||||
import me.redtea.nodropx.menu.storage.singlepage.SinglePageGui;
|
||||
@@ -32,6 +39,8 @@ 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.service.allnodrop.AllNoDropService;
|
||||
import me.redtea.nodropx.service.allnodrop.impl.AllNoDropServiceImpl;
|
||||
import me.redtea.nodropx.service.capasity.CapacityService;
|
||||
import me.redtea.nodropx.service.capasity.impl.CapacityServiceImpl;
|
||||
import me.redtea.nodropx.service.cosmetic.CosmeticService;
|
||||
@@ -44,7 +53,7 @@ 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.impl.Tr7zwNBTServiceImpl;
|
||||
import me.redtea.nodropx.service.nbt.impl.FastNBTServiceImpl;
|
||||
import me.redtea.nodropx.service.nodrop.NoDropService;
|
||||
import me.redtea.nodropx.service.nodrop.impl.NoDropServiceImpl;
|
||||
import me.redtea.nodropx.service.respawn.RespawnService;
|
||||
@@ -56,13 +65,19 @@ import me.redtea.nodropx.util.FoliaSupportedUtils;
|
||||
import me.redtea.nodropx.util.UpdateChecker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class NoDropX extends JavaPlugin {
|
||||
@@ -106,12 +121,13 @@ public final class NoDropX extends JavaPlugin {
|
||||
noDropCosmeticService.load(YamlConfiguration.loadConfiguration(textContext.getCosmetics()));
|
||||
|
||||
dropConfirmService = getConfig().getBoolean("confirmThrowNoDropItem") ? new DropConfirmServiceImpl() : new DropConfirmNull();
|
||||
NBTService nbtService = new Tr7zwNBTServiceImpl();
|
||||
NBTService nbtService = new FastNBTServiceImpl();
|
||||
noDropService = new NoDropServiceImpl(nbtService, noDropCosmeticService);
|
||||
NoDropItemFactory noDropItemFactory = new NoDropItemFactoryImpl(noDropService);
|
||||
EventService eventService = new EventServiceImpl(noDropService);
|
||||
capacityService = new CapacityServiceImpl(this);
|
||||
RespawnService respawnService = new RespawnServiceImpl(noDropService, capacityService);
|
||||
AllNoDropService allNoDropService = new AllNoDropServiceImpl(nbtService);
|
||||
RespawnService respawnService = new RespawnServiceImpl(noDropService, allNoDropService, capacityService);
|
||||
|
||||
//EXPERIMENTAL! Folia support!
|
||||
FoliaSupporter foliaSupporter = new FoliaSupporter();
|
||||
@@ -129,7 +145,9 @@ public final class NoDropX extends JavaPlugin {
|
||||
StorageService storageService = new StorageServiceImpl(menuFacade, personalStorageRepo, noDropService);
|
||||
|
||||
|
||||
NoDropAPI noDropAPI = new NoDropXFacade(noDropService, noDropItemFactory, storageService, capacityService, itemStackService);
|
||||
|
||||
NoDropAPI noDropAPI = new NoDropXFacade(noDropService, noDropItemFactory, storageService, capacityService,
|
||||
itemStackService, allNoDropService);
|
||||
noDropAPIInstance = noDropAPI;
|
||||
|
||||
|
||||
@@ -140,21 +158,67 @@ public final class NoDropX extends JavaPlugin {
|
||||
Bukkit.getServicesManager().register(NoDropAPI.class,
|
||||
noDropAPI, this, ServicePriority.Normal);
|
||||
|
||||
CommandManager commandManager = new CommandManager(this);
|
||||
commandManager.getMessageHandler().register("cmd.no.permission", sender -> messages.get("noPerms").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.wrong.usage", sender -> messages.get("usage").send(sender));
|
||||
commandManager.getCompletionHandler().register("#materials", input -> itemStackService.allMaterials());
|
||||
commandManager.register(new NoDropCommand(messages, noDropAPI, menuFacade, this, itemStackService, dropConfirmService));
|
||||
// CommandManager commandManager = CommandManager.get(this);
|
||||
// commandManager.message("#no-perm", sender -> {
|
||||
// messages.get("noPerms").send(sender);
|
||||
// return Unit.INSTANCE;
|
||||
// });
|
||||
// commandManager.message("#for-players-only", sender -> {
|
||||
// messages.get("noConsole").send(sender);
|
||||
// return Unit.INSTANCE;
|
||||
// });
|
||||
// commandManager.message("#no-such-player", sender -> {
|
||||
// messages.get("noExists").send(sender);
|
||||
// return Unit.INSTANCE;
|
||||
// });
|
||||
// commandManager.message("#no-such-player", sender -> {
|
||||
// messages.get("usage").send(sender);
|
||||
// return Unit.INSTANCE;
|
||||
// });
|
||||
// commandManager.tabComplete("#materials", input -> itemStackService.allMaterials());
|
||||
// commandManager.register(new NoDropCommand(messages, noDropAPI, menuFacade, this,
|
||||
// itemStackService, dropConfirmService, eventService, allNoDropService));
|
||||
final BukkitCommandManager<CommandSender> commandManager = BukkitCommandManager.create(this, builder -> {
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
commandManager.registerSuggestion(SuggestionKey.of("allmaterials"),
|
||||
new SuggestionResolver.Simple<CommandSender>() {
|
||||
@Override
|
||||
public @NotNull List<String> resolve(@NotNull SuggestionContext<CommandSender> context) {
|
||||
return itemStackService.allMaterials();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
commandManager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> {
|
||||
messages.get("usage").send(sender);
|
||||
});
|
||||
commandManager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> {
|
||||
messages.get("usage").send(sender);
|
||||
});
|
||||
commandManager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> {
|
||||
messages.get("usage").send(sender);
|
||||
});
|
||||
commandManager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> {
|
||||
messages.get("error").send(sender);
|
||||
});
|
||||
|
||||
|
||||
commandManager.registerCommand(new NoDropCommand(messages, noDropAPI, menuFacade, this,
|
||||
itemStackService, dropConfirmService, eventService, allNoDropService));
|
||||
bStatsInit();
|
||||
printCredits();
|
||||
checkUpdates();
|
||||
}
|
||||
|
||||
private MenuFacade initMenus() {
|
||||
try {
|
||||
CachedMenu personalStorageCachedMenu;
|
||||
if (getConfig().getString("personalStorageType").equalsIgnoreCase("SINGLE_PAGE")) {
|
||||
if (Objects.requireNonNull(getConfig().getString("personalStorageType")).equalsIgnoreCase("SINGLE_PAGE")) {
|
||||
SinglePageGui singlePageGui = new SinglePageGui(messages, personalStorageRepo);
|
||||
personalStorageCachedMenu = singlePageGui;
|
||||
Bukkit.getPluginManager().registerEvents(new SinglePageGuiHandler(new SinglePageController(noDropService,
|
||||
@@ -164,13 +228,20 @@ public final class NoDropX extends JavaPlugin {
|
||||
|
||||
Menu confirmMenu = new DropConfirmMFGui(messages, dropConfirmService, this);
|
||||
return new MenuFacadeImpl(personalStorageCachedMenu, confirmMenu);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().severe(e.getMessage());
|
||||
e.printStackTrace();
|
||||
printConsoleLine("&4Can not use menus on this server!");
|
||||
}
|
||||
|
||||
return new NullMenuFacadeImpl();
|
||||
}
|
||||
|
||||
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.");
|
||||
printConsoleLine("ItemsAdder found! Registering a CustomStack provider for it.");
|
||||
result.registerProvider(new ItemsAdderProvider());
|
||||
}
|
||||
result.registerProvider(new ItemStackProviderDefault());
|
||||
@@ -183,10 +254,10 @@ public final class NoDropX extends JavaPlugin {
|
||||
}
|
||||
new UpdateChecker(this, 111485, foliaSupportedUtils).getVersion(version -> {
|
||||
if (this.getDescription().getVersion().equals(version)) {
|
||||
getLogger().info("There is not a new update available.");
|
||||
printConsoleLine("There is not a new update available.");
|
||||
} else {
|
||||
getLogger().info("There is a new update available: " + version);
|
||||
getLogger().info("Download it from https://www.spigotmc.org/resources/nodropx.111485/");
|
||||
printConsoleLine("&eThere is a new update available: " + ChatColor.GOLD + version);
|
||||
printConsoleLine("&eDownload it from " + ChatColor.GOLD + "https://www.spigotmc.org/resources/nodropx.111485/");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -200,7 +271,7 @@ public final class NoDropX extends JavaPlugin {
|
||||
|
||||
private void printCredits() {
|
||||
printCreditLine("&a************************************************************");
|
||||
printCreditLine("&a* &eNoDropX version &6" + getDescription().getVersion() + "&7 (uses CarcadeX v. 1.0.7)");
|
||||
printCreditLine("&a* &2&lNoDrop&a&lX&e version &6" + getDescription().getVersion());
|
||||
printCreditLine("&a* &eBy &citzRedTea");
|
||||
printCreditLine("&a* &eDetected bukkit version &6" + Bukkit.getBukkitVersion());
|
||||
printCreditLine("&a* &esupport HEX colors " + (supportHEX ? "&2YES" : "&4NO"));
|
||||
@@ -208,6 +279,11 @@ public final class NoDropX extends JavaPlugin {
|
||||
printCreditLine("&a************************************************************");
|
||||
}
|
||||
|
||||
private void printConsoleLine(String s) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
"&e[&2&lNoDrop&a&lX&e] &f" + s));
|
||||
}
|
||||
|
||||
private void printCreditLine(String s) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', s));
|
||||
}
|
||||
|
||||
+6
-3
@@ -11,10 +11,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* This event is called when item changes no drop status
|
||||
*/
|
||||
public class ChangeNoDropEvent extends PlayerEvent implements Cancellable {
|
||||
public class PlayerChangeNoDropEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Getter
|
||||
|
||||
private final boolean newValue;
|
||||
|
||||
@Getter
|
||||
@@ -23,7 +23,7 @@ public class ChangeNoDropEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private boolean isCancelled;
|
||||
|
||||
public ChangeNoDropEvent(@NotNull Player who, boolean newValue, @NotNull ItemStack item) {
|
||||
public PlayerChangeNoDropEvent(@NotNull Player who, boolean newValue, @NotNull ItemStack item) {
|
||||
super(who);
|
||||
this.newValue = newValue;
|
||||
this.item = item;
|
||||
@@ -48,4 +48,7 @@ public class ChangeNoDropEvent extends PlayerEvent implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public boolean getNewValue() {
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
@@ -144,4 +144,55 @@ public interface NoDropAPI {
|
||||
default @NotNull ItemStack getNoDrop(@NotNull String material) {
|
||||
return getNoDrop(material, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set AllNoDrop
|
||||
* @param item the item who's AllNoDrop property are changing
|
||||
* @param isAllNoDrop will the item save all items in player's inventory from death?
|
||||
* @author redtea
|
||||
* @since 1.0.4
|
||||
*/
|
||||
ItemStack setAllNoDrop(@NotNull ItemStack item, boolean isAllNoDrop);
|
||||
|
||||
/**
|
||||
* Check if item is AllNoDrop
|
||||
* @param item the item being checked
|
||||
* @return true if the item save all items in player's inventory from death
|
||||
* @author redtea
|
||||
* @since 1.0.4
|
||||
*/
|
||||
boolean isAllNoDrop(@NotNull ItemStack item);
|
||||
|
||||
/**
|
||||
* Generate new nodropall item by material and amount
|
||||
* @param material material of item
|
||||
* @param amount count of item
|
||||
* @return nodropall item
|
||||
* @author redtea
|
||||
* @since 1.0.4
|
||||
*/
|
||||
default ItemStack getAllNoDrop(@NotNull Material material, int amount) {
|
||||
val item = new ItemStack(material, amount);
|
||||
setAllNoDrop(item, true);
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate new nodropall item by material and amount
|
||||
* @param material material of item
|
||||
* @param amount count of item
|
||||
* @return nodropall item
|
||||
* @author redtea
|
||||
* @since 1.0.4
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see NoDropAPI#getAllNoDrop(Material, int)
|
||||
*/
|
||||
ItemStack getAllNoDrop(@NotNull String material, int amount);
|
||||
|
||||
/**
|
||||
* @see NoDropAPI#getAllNoDrop(Material, int)
|
||||
*/
|
||||
void giveAllNoDrop(HumanEntity entity, @NotNull String material, int amount);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import me.redtea.nodropx.api.facade.manipulator.StorageManipulator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.redtea.nodropx.factory.item.NoDropItemFactory;
|
||||
import me.redtea.nodropx.libs.carcadex.repo.Repo;
|
||||
import me.redtea.nodropx.service.allnodrop.AllNoDropService;
|
||||
import me.redtea.nodropx.service.capasity.CapacityService;
|
||||
import me.redtea.nodropx.service.material.ItemStackService;
|
||||
import me.redtea.nodropx.service.nodrop.NoDropService;
|
||||
@@ -27,6 +28,7 @@ public class NoDropXFacade implements NoDropAPI {
|
||||
private final StorageService storageService;
|
||||
private final CapacityService capacityService;
|
||||
private final ItemStackService itemStackService;
|
||||
private final AllNoDropService allNoDropService;
|
||||
|
||||
@Override
|
||||
public ItemStack setNoDrop(@NotNull ItemStack item, boolean isNoDrop) {
|
||||
@@ -99,4 +101,25 @@ public class NoDropXFacade implements NoDropAPI {
|
||||
public @NotNull ItemStack getNoDrop(@NotNull String material, int amount) {
|
||||
return setNoDrop(itemStackService.get(material, amount), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setAllNoDrop(@NotNull ItemStack item, boolean isAllNoDrop) {
|
||||
allNoDropService.setAllNoDrop(item, isAllNoDrop);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllNoDrop(@NotNull ItemStack item) {
|
||||
return allNoDropService.isAllNoDrop(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getAllNoDrop(@NotNull String material, int amount) {
|
||||
return setAllNoDrop(itemStackService.get(material, amount), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveAllNoDrop(HumanEntity entity, @NotNull String material, int amount) {
|
||||
entity.getInventory().addItem(getAllNoDrop(material, amount));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,33 @@
|
||||
package me.redtea.nodropx.command;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotations.Command;
|
||||
import dev.triumphteam.cmd.core.annotations.NamedArguments;
|
||||
import dev.triumphteam.cmd.core.annotations.Optional;
|
||||
import dev.triumphteam.cmd.core.annotations.Suggestion;
|
||||
import dev.triumphteam.cmd.core.suggestion.SuggestionContext;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import me.redtea.nodropx.NoDropX;
|
||||
import me.redtea.nodropx.api.facade.NoDropAPI;
|
||||
import me.redtea.nodropx.menu.facade.MenuFacade;
|
||||
import me.redtea.nodropx.libs.message.container.Messages;
|
||||
import me.redtea.nodropx.service.allnodrop.AllNoDropService;
|
||||
import me.redtea.nodropx.service.dropconfirm.DropConfirmService;
|
||||
import me.redtea.nodropx.service.event.EventService;
|
||||
import me.redtea.nodropx.service.material.ItemStackService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Main command of plugin
|
||||
@@ -26,40 +36,49 @@ import java.util.Date;
|
||||
*/
|
||||
@Command("nodrop")
|
||||
@RequiredArgsConstructor
|
||||
public class NoDropCommand extends CommandBase {
|
||||
public class NoDropCommand {
|
||||
private final Messages messages;
|
||||
private final NoDropAPI noDropAPI;
|
||||
private final MenuFacade menuFacade;
|
||||
private final NoDropX plugin;
|
||||
private final ItemStackService itemStackService;
|
||||
private final DropConfirmService confirmService;
|
||||
private final EventService eventService;
|
||||
private final AllNoDropService allNoDropService;
|
||||
|
||||
@Default
|
||||
@Command
|
||||
public void onDefault(final CommandSender sender) {
|
||||
messages.get("usage").send(sender);
|
||||
}
|
||||
|
||||
@SubCommand("give")
|
||||
|
||||
|
||||
@Command("give")
|
||||
@Permission("nodropx.give")
|
||||
@Completion({"#players", "#materials", "#range:1-64"})
|
||||
@NamedArguments("query-parameters")
|
||||
//@TabComplete(complete = {"#players", "#materials", "#range:1-64"})
|
||||
public void onGive(final CommandSender sender,
|
||||
final Player player,
|
||||
final String material,
|
||||
@Suggestion("allmaterials") final String material,
|
||||
@Optional final Integer amount) {
|
||||
try {
|
||||
noDropAPI.giveNoDrop(player, material, amount == null || amount == 0 ? 1 : amount);
|
||||
ItemStack item = noDropAPI.getNoDrop(material, amount == null || amount == 0 ? 1 : amount);
|
||||
player.getInventory().addItem(item);
|
||||
|
||||
|
||||
messages.get("give.success")
|
||||
.replaceAll("%item%", material)
|
||||
.replaceAll("%player%", player.getName())
|
||||
.replaceAll("%amount%", amount == null ? "1" : amount.toString())
|
||||
.send(sender);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
messages.get("give.fail").send(sender);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("reload")
|
||||
@Command("reload")
|
||||
@Permission("nodropx.reload")
|
||||
public void onReload(final CommandSender sender) {
|
||||
long time = new Date().getTime();
|
||||
@@ -67,9 +86,10 @@ public class NoDropCommand extends CommandBase {
|
||||
messages.get("reload").replaceAll("%time%", String.valueOf(new Date().getTime() - time)).send(sender);
|
||||
}
|
||||
|
||||
@SubCommand("giveStorage")
|
||||
@Command("givestorage")
|
||||
@Permission("nodropx.giveStorage")
|
||||
@Completion({"#players", "#materials", "#range:1-64"})
|
||||
@NamedArguments("query-parameters")
|
||||
//@TabComplete(complete = {"#players", "#materials", "#range:1-64"})
|
||||
public void onGiveStorage(final CommandSender sender,
|
||||
final String playerName,
|
||||
final String material,
|
||||
@@ -93,14 +113,14 @@ public class NoDropCommand extends CommandBase {
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("ignoreConfirm")
|
||||
@Command("ignoreconfirm")
|
||||
@Permission("nodropx.ignoreConfirm")
|
||||
public void onIgnoreConfirm(final CommandSender sender, @Optional Player target) {
|
||||
if(target == null) {
|
||||
if(!(sender instanceof Player)) {
|
||||
sender.sendMessage("player only");
|
||||
return;
|
||||
messages.get("error").send(sender);
|
||||
} else {
|
||||
messages.get("ignoreConfirm.on").send(sender);
|
||||
confirmService.forceConfirm((Player) sender);
|
||||
}
|
||||
} else {
|
||||
@@ -108,17 +128,17 @@ public class NoDropCommand extends CommandBase {
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand("ignoreConfirmTimed")
|
||||
@Command("ignoreconfirmtimed")
|
||||
@Permission("nodropx.ignoreConfirm.timed")
|
||||
public void onIgnoreConfirmTimed(final CommandSender sender, Integer sec, @Optional Player target) {
|
||||
if(target == null) {
|
||||
if(!(sender instanceof Player)) {
|
||||
sender.sendMessage("player only");
|
||||
return;
|
||||
messages.get("error").send(sender);
|
||||
} else {
|
||||
confirmService.forceConfirm((Player) sender);
|
||||
try {
|
||||
Bukkit.getScheduler().runTaskLater(plugin,() -> confirmService.removeForceConfirm((Player) sender),20L*sec);
|
||||
messages.get("ignoreConfirm.on").send(sender);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
sender.sendMessage(ChatColor.RED + "This operation didn't supports on your environment");
|
||||
}
|
||||
@@ -133,33 +153,33 @@ public class NoDropCommand extends CommandBase {
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand("noIgnoreConfirm")
|
||||
@Command("noignoreconfirm")
|
||||
@Permission("nodropx.noIgnoreConfirm")
|
||||
public void onNoIgnoreConfirm(final CommandSender sender, @Optional Player target) {
|
||||
if(target == null) {
|
||||
if(!(sender instanceof Player)) {
|
||||
sender.sendMessage("player only");
|
||||
return;
|
||||
messages.get("error").send(sender);
|
||||
} else {
|
||||
confirmService.removeForceConfirm((Player) sender);
|
||||
messages.get("ignoreConfirm.off").send(sender);
|
||||
}
|
||||
} else {
|
||||
confirmService.removeForceConfirm(target);
|
||||
}
|
||||
}
|
||||
@SubCommand("applyHand")
|
||||
@Command("applyhand")
|
||||
@Permission("nodropx.applyhand")
|
||||
public void onApplyHand(final Player sender) {
|
||||
try {
|
||||
noDropAPI.setNoDrop(sender.getInventory().getItemInMainHand(), true);
|
||||
val event = eventService.callPlayerChangeNoDropEvent(sender, sender.getInventory().getItemInMainHand(), true);
|
||||
noDropAPI.setNoDrop(sender.getInventory().getItemInMainHand(), event.getNewValue());
|
||||
messages.get("applyHand.success").send(sender);
|
||||
} catch (Throwable e) {
|
||||
messages.get("applyHand.fail").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand("gui")
|
||||
@Alias("storage")
|
||||
@Command(value = "gui", alias = "storage")
|
||||
@Permission("nodropx.gui")
|
||||
public void onGui(final Player sender) {
|
||||
menuFacade.openPersonalStorage(sender);
|
||||
@@ -172,4 +192,24 @@ public class NoDropCommand extends CommandBase {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Command("giveallnodrop")
|
||||
@Permission("nodropx.giveallnodrop")
|
||||
@NamedArguments("query-parameters")
|
||||
// @TabComplete(complete = {"#players", "#materials", "#range:1-64"})
|
||||
public void onGiveAllNoDrop(final CommandSender sender,
|
||||
final Player player,
|
||||
final String material,
|
||||
@Optional final Integer amount) {
|
||||
try {
|
||||
noDropAPI.giveAllNoDrop(player, material, amount == null || amount == 0 ? 1 : amount);
|
||||
messages.get("give.success")
|
||||
.replaceAll("%item%", material)
|
||||
.replaceAll("%player%", player.getName())
|
||||
.replaceAll("%amount%", amount == null ? "1" : amount.toString())
|
||||
.send(sender);
|
||||
} catch (Throwable e) {
|
||||
messages.get("give.fail").send(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,14 @@ public class FoliaSupporter {
|
||||
@SneakyThrows
|
||||
public void run(RespawnService respawnService, Plugin plugin) {
|
||||
try {
|
||||
boolean isFolia = false;
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
isFolia = true;
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
String version = ((JsonObject) new JsonParser().parse(new FileReader("version_history.json"))).get("currentVersion").getAsString();
|
||||
if(!version.toLowerCase().contains("folia") && !plugin.getConfig().getBoolean("forceUseFoliaPatches")) {
|
||||
if(!isFolia && !version.toLowerCase().contains("folia") && !plugin.getConfig().getBoolean("forceUseFoliaPatches")
|
||||
&& !(Bukkit.getName().toLowerCase().contains("folia"))) {
|
||||
return;
|
||||
}
|
||||
runningOnFolia = true;
|
||||
@@ -56,7 +62,7 @@ public class FoliaSupporter {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
@@ -46,6 +47,11 @@ public class PlayerHandler implements Listener {
|
||||
respawnService.giveSavedItems(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
respawnService.giveSavedItems(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
menuFacade.clearCache(event.getPlayer());
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
|
||||
public class SinglePageGuiHandler implements Listener {
|
||||
private final SinglePageController controller;
|
||||
@@ -19,6 +20,13 @@ public class SinglePageGuiHandler implements Listener {
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
if(gui.isStorageGui(event.getInventory())) {
|
||||
controller.onDrag(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.redtea.nodropx.menu.facade.impl;
|
||||
|
||||
import me.redtea.nodropx.menu.CachedMenu;
|
||||
import me.redtea.nodropx.menu.facade.MenuFacade;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NullMenuFacadeImpl implements MenuFacade {
|
||||
@Override
|
||||
public CachedMenu noDropStorage() {
|
||||
return new CachedMenu() {
|
||||
@Override
|
||||
public void clearCache(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCache() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Player player) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openPersonalStorage(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openConfirmDrop(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCache(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCache() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import me.redtea.nodropx.libs.carcadex.repo.MutableRepo;
|
||||
import me.redtea.nodropx.service.nodrop.NoDropService;
|
||||
import me.redtea.nodropx.util.FoliaSupportedUtils;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -30,16 +30,28 @@ public class SinglePageController {
|
||||
if(clickActions.contains(event.getAction()) && !(noDropService.isNoDrop(event.getCurrentItem()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
foliaCheck(event.getInventory(), event.getWhoClicked(), event);
|
||||
|
||||
}
|
||||
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
if((event.getNewItems().entrySet().stream().anyMatch(it -> !noDropService.isNoDrop(it.getValue())))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
foliaCheck(event.getInventory(), event.getWhoClicked(), event);
|
||||
|
||||
}
|
||||
|
||||
private void foliaCheck(Inventory inventory, HumanEntity whoClicked, InventoryEvent event) {
|
||||
foliaSupportedUtils.runTask(() -> {
|
||||
for(ItemStack itemStack : event.getInventory()) {
|
||||
for(ItemStack itemStack : inventory) {
|
||||
if (itemStack != null && !noDropService.isNoDrop(itemStack)) {
|
||||
event.getWhoClicked().getInventory().addItem(itemStack);
|
||||
event.getInventory().remove(itemStack);
|
||||
((Player) event.getWhoClicked()).updateInventory();
|
||||
whoClicked.getInventory().addItem(itemStack);
|
||||
inventory.remove(itemStack);
|
||||
((Player) whoClicked).updateInventory();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
|
||||
@@ -26,7 +26,13 @@ public class SinglePageGui implements CachedMenu {
|
||||
player.openInventory(cache.get(player.getUniqueId()));
|
||||
return;
|
||||
}
|
||||
Inventory gui = Bukkit.createInventory(null, 54, MD5ColorUtils.translateHexColorCodes(messages.get("gui.personalStorage.title").asUnparsedString()));
|
||||
Inventory gui;
|
||||
try {
|
||||
gui = Bukkit.createInventory(null, 54, messages.get("gui.personalStorage.title").asComponent());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
gui = Bukkit.createInventory(null, 54, MD5ColorUtils.translateHexColorCodes(messages.get("gui.personalStorage.title").asUnparsedString()));
|
||||
}
|
||||
for(ItemStack item : personalStorageRepo.get(player.getUniqueId()).orElse(new ArrayList<>())) if(item != null) gui.addItem(item);
|
||||
|
||||
cache.put(player.getUniqueId(), gui);
|
||||
|
||||
@@ -5,17 +5,21 @@ import dev.lone.itemsadder.api.ItemsAdder;
|
||||
import me.redtea.nodropx.model.materialprovider.ItemStackProvider;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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();
|
||||
CustomStack stack = CustomStack.getInstance(s);
|
||||
return (stack != null) ? stack.getItemStack().clone() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> allMaterials() {
|
||||
return ItemsAdder.getAllItems().stream().map(CustomStack::getNamespacedID).collect(Collectors.toList());
|
||||
if((ItemsAdder.getAllItems() == null) || ItemsAdder.getAllItems().isEmpty()) return Collections.emptyList();
|
||||
return ItemsAdder.getAllItems().stream().map(CustomStack::getNamespacedID).filter(s -> !s.startsWith("_iainternal")).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package me.redtea.nodropx.service.allnodrop;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Service for checking all no drop items
|
||||
* @since 1.0.4
|
||||
* @author redtea
|
||||
*/
|
||||
public interface AllNoDropService {
|
||||
/**
|
||||
* Set no drop to item
|
||||
* @param item the item who's no drop property are changing
|
||||
* @param isAllNoDrop will the item can drop from inventory on death?
|
||||
* @author redtea
|
||||
* @since 1.0.4
|
||||
*/
|
||||
void setAllNoDrop(ItemStack item, boolean isAllNoDrop);
|
||||
/**
|
||||
* Check if item is NoDropAll
|
||||
* @param item the item being checked
|
||||
* @return true if item is NoDropAll
|
||||
* @author redtea
|
||||
* @since 1.0.4
|
||||
*/
|
||||
boolean isAllNoDrop(ItemStack item);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.redtea.nodropx.service.allnodrop.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.redtea.nodropx.service.allnodrop.AllNoDropService;
|
||||
import me.redtea.nodropx.service.nbt.NBTService;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class AllNoDropServiceImpl implements AllNoDropService {
|
||||
private final NBTService nbtService;
|
||||
|
||||
@Override
|
||||
public void setAllNoDrop(ItemStack item, boolean isAllNoDrop) {
|
||||
nbtService.setBoolTag(item, "isAllNoDrop", isAllNoDrop);
|
||||
nbtService.setBoolTag(item, "isNoDrop", isAllNoDrop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllNoDrop(ItemStack item) {
|
||||
return nbtService.getBoolTag(item, "isAllNoDrop");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.redtea.nodropx.service.capasity.impl;
|
||||
|
||||
import beer.devs.fastnbt.nms.nbt.NItem;
|
||||
import me.redtea.nodropx.libs.carcadex.repo.Repo;
|
||||
import me.redtea.nodropx.libs.carcadex.repo.impl.yaml.YamlRepo;
|
||||
import me.redtea.nodropx.service.capasity.CapacityService;
|
||||
@@ -7,24 +8,19 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CapacityServiceImpl implements CapacityService {
|
||||
private final Repo<String, List<Integer>> capacityRepo;
|
||||
private final Map<String, Integer> customModelDataRequired = new HashMap<>();
|
||||
public CapacityServiceImpl(Plugin plugin) {
|
||||
capacityRepo = new YamlRepo<>(
|
||||
new File(plugin.getDataFolder(), "capacity.yml").toPath(),
|
||||
plugin,
|
||||
conf -> conf.getKeys(false).stream().collect(Collectors.toMap(
|
||||
value -> {
|
||||
if(value.contains("->")) {
|
||||
String[] args = value.split("->");
|
||||
customModelDataRequired.put(args[0], Integer.parseInt(args[1]));
|
||||
return args[0];
|
||||
} else return value;
|
||||
},
|
||||
value -> value,
|
||||
conf::getIntegerList))
|
||||
);
|
||||
}
|
||||
@@ -32,17 +28,18 @@ public class CapacityServiceImpl implements CapacityService {
|
||||
@Override
|
||||
public List<Integer> get(ItemStack item) {
|
||||
String key = item.getType().name();
|
||||
|
||||
if(NItem.hasNBT(item)) {
|
||||
NItem nItem = NItem.of(item);
|
||||
if(nItem.hasKey("itemsadder")) {
|
||||
key = nItem.getCompound("itemsadder").getString("namespace") + ":" + nItem.getCompound("itemsadder").getString("id");
|
||||
} else if(item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) {
|
||||
key += "->" + item.getItemMeta().getCustomModelData();
|
||||
}
|
||||
}
|
||||
|
||||
Optional<List<Integer>> result = capacityRepo.get(key);
|
||||
if(!result.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if(customModelDataRequired.containsKey(key)) {
|
||||
int cmi = customModelDataRequired.get(key);
|
||||
if(!item.getItemMeta().hasCustomModelData() || item.getItemMeta().getCustomModelData() != cmi) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
return result.get();
|
||||
return result.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package me.redtea.nodropx.service.event;
|
||||
|
||||
import me.redtea.nodropx.api.event.NoDropItemThrownEvent;
|
||||
import me.redtea.nodropx.api.event.PlayerChangeNoDropEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface EventService {
|
||||
void callThrownEvent(Player who, ItemStack item, NoDropItemThrownEvent.Reason reason, Optional<Cancellable> rootEvent);
|
||||
PlayerChangeNoDropEvent callPlayerChangeNoDropEvent(Player who, ItemStack item, boolean value);
|
||||
@Nullable
|
||||
NoDropItemThrownEvent callThrownEvent(Player who, ItemStack item, NoDropItemThrownEvent.Reason reason, Optional<Cancellable> rootEvent);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.redtea.nodropx.service.event.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.redtea.nodropx.api.event.NoDropItemThrownEvent;
|
||||
import me.redtea.nodropx.api.event.PlayerChangeNoDropEvent;
|
||||
import me.redtea.nodropx.service.event.EventService;
|
||||
import me.redtea.nodropx.service.nodrop.NoDropService;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -16,8 +17,15 @@ public class EventServiceImpl implements EventService {
|
||||
private final NoDropService noDropService;
|
||||
|
||||
@Override
|
||||
public void callThrownEvent(Player who, ItemStack item, NoDropItemThrownEvent.Reason reason, Optional<Cancellable> rootEvent) {
|
||||
if(!noDropService.isNoDrop(item)) return;
|
||||
public PlayerChangeNoDropEvent callPlayerChangeNoDropEvent(Player who, ItemStack item, boolean value) {
|
||||
PlayerChangeNoDropEvent callingEvent = new PlayerChangeNoDropEvent(who, value, item);
|
||||
Bukkit.getPluginManager().callEvent(callingEvent);
|
||||
return callingEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoDropItemThrownEvent callThrownEvent(Player who, ItemStack item, NoDropItemThrownEvent.Reason reason, Optional<Cancellable> rootEvent) {
|
||||
if(!noDropService.isNoDrop(item)) return null;
|
||||
NoDropItemThrownEvent callingEvent = new NoDropItemThrownEvent(
|
||||
who,
|
||||
reason,
|
||||
@@ -25,5 +33,6 @@ public class EventServiceImpl implements EventService {
|
||||
);
|
||||
Bukkit.getPluginManager().callEvent(callingEvent);
|
||||
rootEvent.ifPresent(cancellable -> cancellable.setCancelled(callingEvent.isCancelled()));
|
||||
return callingEvent;
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,20 @@ public interface NBTService {
|
||||
/**
|
||||
* Sets the NBT tag "isNoDrop", which indicates that the item is no drop
|
||||
* @param item editable item
|
||||
* @param isNoDrop tag value
|
||||
* @since 1.0.0
|
||||
* @param tag nbt tag
|
||||
* @param value tag value
|
||||
* @since 1.0.4
|
||||
* @author redtea
|
||||
*/
|
||||
void setNoDropTag(ItemStack item, boolean isNoDrop);
|
||||
void setBoolTag(ItemStack item, String tag, boolean value);
|
||||
|
||||
/**
|
||||
* Gets the value of the "isNoDrop" tag, which indicates that the item is no drop
|
||||
* @param item checking item
|
||||
* @param tag nbt tag
|
||||
* @return tag value
|
||||
* @since 1.0.0
|
||||
* @since 1.0.4
|
||||
* @author redtea
|
||||
*/
|
||||
boolean getNoDropTag(ItemStack item);
|
||||
boolean getBoolTag(ItemStack item, String tag);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.redtea.nodropx.service.nbt.impl;
|
||||
|
||||
import beer.devs.fastnbt.nms.nbt.NItem;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import me.redtea.nodropx.service.nbt.NBTService;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class FastNBTServiceImpl implements NBTService {
|
||||
|
||||
|
||||
@Override
|
||||
public void setBoolTag(ItemStack item, String tag, boolean value) {
|
||||
NItem nbtItem = new NItem(item);
|
||||
nbtItem.setBoolean(tag, value);
|
||||
nbtItem.merge(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolTag(ItemStack item, String tag) {
|
||||
if(item == null || item.getType() == Material.AIR) return false;
|
||||
NItem nbtItem = new NItem(item);
|
||||
return nbtItem.hasKey(tag) && nbtItem.getBoolean(tag);
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,19 @@ import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Tr7zwNBTServiceImpl implements NBTService {
|
||||
|
||||
|
||||
@Override
|
||||
public void setNoDropTag(ItemStack item, boolean isNoDrop) {
|
||||
public void setBoolTag(ItemStack item, String tag, boolean value) {
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
nbtItem.setBoolean("isNoDrop", true);
|
||||
nbtItem.setBoolean(tag, value);
|
||||
nbtItem.applyNBT(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getNoDropTag(ItemStack item) {
|
||||
public boolean getBoolTag(ItemStack item, String tag) {
|
||||
if(item == null || item.getType() == Material.AIR) return false;
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
return nbtItem.hasTag("isNoDrop") && nbtItem.getBoolean("isNoDrop");
|
||||
return nbtItem.hasTag(tag) && nbtItem.getBoolean(tag);
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,13 @@ public class NoDropServiceImpl implements NoDropService {
|
||||
|
||||
@Override
|
||||
public void setNoDrop(ItemStack item, boolean isNoDrop) {
|
||||
nbtService.setNoDropTag(item, isNoDrop);
|
||||
cosmeticService.applyAll(item);
|
||||
nbtService.setBoolTag(item, "isNoDrop", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNoDrop(ItemStack item) {
|
||||
if(item == null) return false;
|
||||
return nbtService.getNoDropTag(item);
|
||||
return nbtService.getBoolTag(item, "isNoDrop");
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,13 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import me.redtea.nodropx.api.event.NoDropItemDropOnDeathEvent;
|
||||
import me.redtea.nodropx.libs.carcadex.repo.Repo;
|
||||
import me.redtea.nodropx.service.allnodrop.AllNoDropService;
|
||||
import me.redtea.nodropx.service.capasity.CapacityService;
|
||||
import me.redtea.nodropx.service.dropconfirm.DropConfirmService;
|
||||
import me.redtea.nodropx.service.nodrop.NoDropService;
|
||||
import me.redtea.nodropx.service.respawn.RespawnService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -21,6 +23,7 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class RespawnServiceImpl implements RespawnService {
|
||||
private final NoDropService noDropService;
|
||||
private final AllNoDropService allNoDropService;
|
||||
private final Map<String, Pair[]> toRespawn = new HashMap<>();
|
||||
private final CapacityService capacityService;
|
||||
|
||||
@@ -31,6 +34,7 @@ public class RespawnServiceImpl implements RespawnService {
|
||||
Pair[] pairs = toRespawn.get(player.getName());
|
||||
for(Pair pair : pairs) player.getInventory().setItem(pair.slot, pair.item);
|
||||
toRespawn.remove(player.getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +42,11 @@ public class RespawnServiceImpl implements RespawnService {
|
||||
public void saveItemsBeforeDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
Set<Integer> noDropSlots = new HashSet<>();
|
||||
boolean isHasAllNoDropItem = event.getDrops().stream().anyMatch(allNoDropService::isAllNoDrop);
|
||||
for(int i = 0; i < player.getInventory().getSize(); ++i) {
|
||||
ItemStack item = player.getInventory().getItem(i);
|
||||
if(!noDropService.isNoDrop(item)) continue;
|
||||
if(!(noDropService.isNoDrop(item) || isHasAllNoDropItem) || item == null ||
|
||||
item.getType() == Material.AIR) continue;
|
||||
NoDropItemDropOnDeathEvent callingEvent = new NoDropItemDropOnDeathEvent(
|
||||
player,
|
||||
item
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Dev's discord tag - itzredtea
|
||||
|
||||
forceUseLegacy: false
|
||||
forceUseMD5Colors: false
|
||||
forceUseFoliaPatches: false
|
||||
@@ -8,6 +10,5 @@ checkForUpdates: true
|
||||
# Use it on your own risk
|
||||
confirmThrowNoDropItem: false
|
||||
|
||||
#Single did not supports minimessages!
|
||||
#Can be SINGLE_PAGE or MULTI_PAGES (Use MULTI_PAGES on your own risk)
|
||||
personalStorageType: SINGLE_PAGE
|
||||
@@ -7,10 +7,13 @@ author: itzRedTea
|
||||
authors: [itzRedTea]
|
||||
softdepend: [ItemsAdder]
|
||||
folia-supported: true
|
||||
website: https://github.com/iRedTea/NoDropX
|
||||
|
||||
permissions:
|
||||
nodropx.give:
|
||||
description: "Allows give no drop items"
|
||||
nodropx.giveallnodrop:
|
||||
description: "Allows give allnodrop items"
|
||||
nodropx.reload:
|
||||
description: "Allows reload the plugin"
|
||||
nodropx.gui:
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
usage:
|
||||
- "&7[ &aUsage of command &e/nodrop &7]"
|
||||
- "&7| &a/give [player] [item] (amount) &e- give no drop item"
|
||||
- "&7| &a/nodrop give [player] [item] (amount) &e- give no drop item"
|
||||
- "&7| &a/nodrop storage &e- open no drop items storage"
|
||||
- "&7| &a/nodrop giveStorage [player] [material] (amount) &e- Gives nodrop item to the player's personal storage"
|
||||
- "&7| &a/nodrop giveallnodrop [player] [material] (amount) &e- Gives allnodrop item to player"
|
||||
- "&7| &a/nodrop ignoreconfirm &e- Ignore confirm gui (only if confirm enabled)"
|
||||
- "&7| &a/nodrop ignoreconfirmtimed [seconds] &e- Timed ignore confirm gui (only if confirm enabled)"
|
||||
- "&7| &a/nodrop noIgnoreConfirm &e- Drop ignore confirm setting (only if confirm enabled)"
|
||||
give:
|
||||
fail: "&4[!] &cFail! Check item type for valid."
|
||||
success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a!"
|
||||
@@ -11,10 +17,14 @@ applyHand:
|
||||
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!"
|
||||
ignoreConfirm:
|
||||
on: "&2&l[!] &aNow you are ignore confirm menu!"
|
||||
off: "&2&l[!] &aNow you are not ignore confirm menu!"
|
||||
|
||||
noPerms: "&4&l[!] &cNo perms for this!"
|
||||
noConsole: "&4&l[!] &cOnly players can use it!"
|
||||
noExists: "&4&l[!] &cThis player doesnt exists!"
|
||||
error: "&4&l[!] &cAn error occurred during the execution of the command!"
|
||||
|
||||
gui:
|
||||
confirm:
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
usage:
|
||||
- "&7[ &aUsage of command &e/nodrop &7]"
|
||||
- "&7| &a/give [player] [item] (amount) &e- give no drop item"
|
||||
- "&7| &a/nodrop give [player] [item] (amount) &e- give no drop item"
|
||||
- "&7| &a/nodrop storage &e- open no drop items storage"
|
||||
- "&7| &a/nodrop giveStorage [player] [material] (amount) &e- Gives nodrop item to the player's personal storage"
|
||||
- "&7| &a/nodrop giveAllNoDrop [player] [material] (amount) &e- Gives allnodrop item to player"
|
||||
- "&7| &a/nodrop ignoreConfirm &e- Ignore confirm gui (only if confirm enabled)"
|
||||
- "&7| &a/nodrop ignoreConfirmTimed [seconds] &e- Timed ignore confirm gui (only if confirm enabled)"
|
||||
- "&7| &a/nodrop noIgnoreConfirm &e- Drop ignore confirm setting (only if confirm enabled)"
|
||||
give:
|
||||
fail: "&4[!] &cFail! Check item type for valid."
|
||||
success: "&2&l[!] &aGived &e%item%&a to &e%player%&a amount &e%amount%&a!"
|
||||
@@ -11,10 +17,14 @@ applyHand:
|
||||
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!"
|
||||
ignoreConfirm:
|
||||
on: "&2&l[!] &aNow you are ignore confirm menu!"
|
||||
off: "&2&l[!] &aNow you are not ignore confirm menu!"
|
||||
|
||||
noPerms: "&4&l[!] &cNo perms for this!"
|
||||
noConsole: "&4&l[!] &cOnly players can use it!"
|
||||
noExists: "&4&l[!] &cThis player doesnt exists!"
|
||||
error: "&4&l[!] &cAn error occurred during the execution of the command!"
|
||||
|
||||
gui:
|
||||
confirm:
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
usage:
|
||||
- "<gray>[ <green>Usage of command <yellow>/nodrop <gray>]"
|
||||
- "<gray>| <green>/give [player] [item] (amount) <yellow>- give no drop item"
|
||||
- "<gray>| <green>/nodrop give [player] [item] (amount) <yellow>- give no drop item"
|
||||
- "<gray>| <green>/nodrop storage <yellow>- open no drop items storage"
|
||||
- "<gray>| <green>/nodrop giveStorage [player] [material] (amount) <yellow>- Gives nodrop item to the player's personal storage"
|
||||
- "<gray>| <green>/nodrop giveallnodrop [player] [material] (amount) <yellow>- Gives allnodrop item to player"
|
||||
- "<gray>| <green>/nodrop ignoreConfirm <yellow>- Ignore confirm gui (only if confirm enabled)"
|
||||
- "<gray>| <green>/nodrop ignoreConfirmTimed [seconds] <yellow>- Timed ignore confirm gui (only if confirm enabled)"
|
||||
- "<gray>| <green>/nodrop noIgnoreConfirm <yellow>- Drop ignore confirm setting (only if confirm enabled)"
|
||||
give:
|
||||
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>!"
|
||||
@@ -11,10 +17,14 @@ applyHand:
|
||||
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!"
|
||||
ignoreConfirm:
|
||||
on: "<green><bold>[!] <reset><green>Now you are ignore confirm menu!"
|
||||
off: "<green><bold>[!] <reset><green>Now you are not ignore confirm menu!"
|
||||
|
||||
noPerms: "<dark_red><bold>[!] <red>No perms for this!"
|
||||
noConsole: "<dark_red><bold>[!] <red>Only players can use it!"
|
||||
noExists: "<dark_red><bold>[!] <red>This player doesnt exists!"
|
||||
error: "<dark_red><bold>[!] <red>An error occurred during the execution of the command!"
|
||||
|
||||
gui:
|
||||
confirm:
|
||||
|
||||
Reference in new issue
Block a user