Skip to content

Commit

Permalink
Release v1.0.3 - Metrics & Commands, Permissions and Menus improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubix327 committed Jun 30, 2022
1 parent 84b3e50 commit 3211af4
Show file tree
Hide file tree
Showing 23 changed files with 453 additions and 110 deletions.
12 changes: 12 additions & 0 deletions .run/Test Server 1.19.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test Server 1.19" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/../../MCServers/TestServer1.19/paper-1.19-20.jar" />
<option name="PROGRAM_PARAMETERS" value="-nogui" />
<option name="WORKING_DIRECTORY" value="C:\MCServers\TestServer1.19" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="ALTERNATIVE_JRE_PATH" value="$PROJECT_DIR$/../../Program Files/Java/openjdk-17.0.2" />
<method v="2">
<option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/build.xml" target="Build" />
</method>
</configuration>
</component>
110 changes: 109 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,110 @@
# AntiItemMove
A plugin that prevents players to move vanilla and custom items to another inventory.
This plugin forbids players to move specified items (vanilla and custom) in any way - this includes moving to any inventory (chest, furnace, etc.), placing, dropping, placing to item frame and dropping when dying.

#### NOTE that if you are OPped, restrictions will not apply to you because you will have all bypass permissions! To test the restricted item please deop yourself first!

## Showcase
### Work demonstration:

![Showcase](https://drive.google.com/u/0/uc?id=18aW8wgBPvNImHrWRJCqeKiMX3eycW-Lo&export=download)

### Convinient Easy To Use GUI:
![Restricted Items](https://drive.google.com/u/0/uc?id=1gtUc0snJJcjmpaGTF0qhqfMuvEBke-BH)

### 28 Different Options:
![Item Options](https://drive.google.com/u/0/uc?id=176Ok2E2g7SWZ140pF3Xz3LrCcCCNQUTi)

### Pre Created Groups
![a](https://drive.google.com/u/0/uc?id=1IF__5v5Pc9tNWTQt24UXe-S1yIJHuMxb)

## Available options:
You can add these options to an item. Not case-sensitive.
<details>
<summary>Click me</summary>

- Chest
- Dispenser
- Dropper
- Furnace
- Workbench - Disable moving an item to a Crafting Table
- Player_Inventory - Disable moving an item inside a Player inventory (except in Creative mode)
- Enchanting - An Enchantment Table
- Brewing - A Brewing Stand
- Merchant - A Villager
- Ender_Chest
- Anvil
- Beacon
- Hopper
- Smithing
- Shulker_Box
- Barrel
- Blast_Furnace
- Lectern
- Smoker
- Loom
- Cartography
- Grindstone
- Stonecutter
- Composter
- Item_Frame - Disable putting an item into an item frame
- Place - Disable placing an item on the ground (for blocks)
- Drop - Disable dropping an item (Q, Ctrl+Q, etc.)
- Die - Disable dropping an item as a loot when a player dies

</details>

## Predefined groups
These groups are unchangeable. You can only use them in items or other groups. Not case-sensitive.
<details>
<summary>Click me</summary>

- ALL - Contains all available options
- Containers - [Chest, Ender_Chest, Shulker_Box, Barrel]
- Tool_Blocks - [Dispenser, Dropper, Furnace, Workbench, Enchanting, Brewing, Anvil, Smithing, Beacon, Hopper, Blast_Furnce, Lectern, Smoker, Loom, Cartography, Grindstone, Stonecutter, Composter]
- Safe - [Workbench, Merchant, Ender_Chest, Player_Inventory, Enchanting]
- Not_Safe - All except SAFE
- Other - [Place, Drop, Item_Frame, Die]

</details>

## User groups

You can customize all of these groups as you want. Not case-sensitive.
<details>
<summary>Click me</summary>

- Default - When an item is added as restricted, it automatically acquires this group. By default this group contains NOT_SAFE inside itself.
- Custom_1 - [Dispenser, Dropper, Furnace] + Default group
- Custom_2 - [Loom, Brewing, Enchanting] + Custom_1 group
- Custom_3 - [Merchant, Anvil, Barrel] + Custom_2 group

</details>

## Commands (& permissions):

- /aim [gui] - Open the plugin’s GUI (`antiitemmove.gui`)
- `antiitemmove.gui.open.main` - Open the main menu
- `antiitemmove.gui.open.items` - Open the Items menu
- `antiitemmove.gui.edit.items` - Edit options and groups of any item
- `antiitemmove.gui.open.groups` - Open the Groups menu
- `antiitemmove.gui.edit.groups` - Edit options of any group
- /aim save - Save an item in hand as a restricted (`antiitemmove.save`)
- /aim remove <id> - Remove an item by id (`antiitemmove.remove`)
- /aim get <id> - Get an item by id (`antiitemmove.get`)
- /aim help - Open help page (`antiitemmove.help`)
- /aim reload - Reload the plugin (`antiitemmove.reload`)

## Other permissions (all defaults to op):

- `antiitemmove.bypass.*` - bypass all the restrictions
- `antiitemmove.bypass.item.<id>.<option>` - bypass restrictions for item with id <id> for the selected <option>
- `antiitemmove.bypass.item.1.*` - bypass all the restrictions for item with id 1
- `antiitemmove.bypass.item.2.chest` - player can move item with id 2 to a chest
- `antiitemmove.bypass.option.<option>` - bypass restrictions for all items for the selected option
- `antiitemmove.bypass.option.chest` - player can move all restricted items to a chest
- `antiitemmove.syntax` - Show syntax if the entered command is incorrect
- `antiitemmove.*` - All permissions at once

## Dependencies:

We have only one soft-dependency - [ItemsLangAPI](https://www.spigotmc.org/resources/itemslangapi.102979/) - to format item names. Really not necessary.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon Jun 27 00:12:43 MSK 2022
build.number=1204
#Thu Jun 30 22:01:48 MSK 2022
build.number=1324
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>me.rubix327</groupId>
<artifactId>antiitemmove</artifactId>
<name>AntiItemMove</name>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -16,9 +16,9 @@
<java.version>1.8</java.version>
<plugin.version>1.19-R0.1-SNAPSHOT</plugin.version>
<foundation.version>6.0.2.2</foundation.version>
<itemslangapi.version>1.0.2</itemslangapi.version>
<itemslangapi.version>558db44345</itemslangapi.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<server.path>C:\MCServers\TestServer1.8</server.path>
<server.path>C:\MCServers\TestServer1.19</server.path>

</properties>

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/me/rubix327/antiitemmove/AntiItemMoveMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ protected void onPluginStart() {

SimpleSettings.HIDE_INCOMPATIBILITY_WARNINGS = true;
SimpleSettings.HIDE_NASHORN_WARNINGS = true;
Common.setLogPrefix("[AntiItemMove]");
Common.setLogPrefix("[AntiItemMove] ");
Common.setTellPrefix(Settings.PREFIX);
registerCommand(new Commands());
registerEvents(new PlayerListener());
loadFiles();
Expand All @@ -38,4 +39,9 @@ public void loadFiles(){
BansStorage.getInstance().init();
GroupsStorage.getInstance().init();
}

@Override
public int getMetricsPluginId() {
return 15634;
}
}
73 changes: 42 additions & 31 deletions src/main/java/me/rubix327/antiitemmove/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.mineacademy.fo.Messenger;
import org.mineacademy.fo.MinecraftVersion;
import org.mineacademy.fo.command.SimpleCommand;
import org.mineacademy.fo.exception.CommandException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Commands extends SimpleCommand {
Expand All @@ -28,24 +28,27 @@ protected Commands() {

@Override
protected void onCommand() {
String syntax = "&7Syntax: &e/aim <gui | save | get | help | reload>";
Common.setTellPrefix("&8[&4AntiItemMove&8] ");
String syntax = "&7Syntax: &e/aim <gui | save | remove | get | help | reload>";
Common.setTellPrefix(Settings.PREFIX);
checkConsole();

if (args.length == 0){
checkPermission("antiitemmove.gui");
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.GUI_OPEN_MAIN);
openMainMenu(getPlayer());
}
else if ("gui".equalsIgnoreCase(args[0]) || "menu".equalsIgnoreCase(args[0])){
checkPermission("antiitemmove.gui");
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.GUI_OPEN_MAIN);
openMainMenu(getPlayer());
}
else if ("save".equalsIgnoreCase(args[0])){
checkPermission("antiitemmove.save");
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.SAVE);
ItemStack item = getPlayer().getInventory().getItemInHand().clone();
if (item.getType() == Material.AIR) returnTell("You must hold an item to save it as restricted.");

item.setAmount(1);
if (ItemsStorage.getInstance().getItemsMap().containsValue(item)){
returnTell("&cThis item is already added as restricted.");
}
ItemsStorage.getInstance().add(item);
int id = ItemsStorage.getInstance().getMaxId();
BansStorage.getInstance().addOptions(id, Group.DEFAULT.getIOptions());
Expand All @@ -58,8 +61,29 @@ else if ("save".equalsIgnoreCase(args[0])){
Messenger.success(getPlayer(), "&7You have successfully added &e" +
name + "&7 to the restricted items by id &e#" + id + "&7.");
}
else if ("remove".equalsIgnoreCase(args[0])){
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.REMOVE);
checkArgs(2, "&7Syntax: &e/aim remove <item_id>");
int id = findNumber(1, "&7Item ID must be whole number.");

ItemStack item = ItemsStorage.getInstance().getItem(id);
if (item == null){
returnTell("&7There is no restricted item with id " + id + ".");
}

ItemsStorage.getInstance().remove(id);
BansStorage.getInstance().remove(id);

String translated = null;
if (DependencyManager.ITEMS_LANG_API.isLoaded()){
translated = ItemsLangAPI.getApi().translate(item, Lang.EN_US);
}
String name = (translated == null ? Util.capitalizeString(item.getType().toString()) : translated);
Messenger.success(getPlayer(), "&7You have successfully removed &e" +
name + "&7 (id: " + id + ") from the restricted items.");
}
else if ("get".equalsIgnoreCase(args[0])){
checkPermission("antiitemmove.get");
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.GET);
checkArgs(2, "&7Syntax: &e/aim get <item_id>");
int number = findNumber(1, "&7Item ID must be whole number.");
ItemStack item = null;
Expand All @@ -84,28 +108,16 @@ else if ("get".equalsIgnoreCase(args[0])){
tellSuccess("&7You were given the &e" + name + "&7 with id &e#" + number + "&7.");
}
else if ("?".equalsIgnoreCase(args[0]) || "help".equalsIgnoreCase(args[0])){
checkPermission("antiitemmove.help");

List<String> messages = Arrays.asList(
"&8" + Common.chatLineSmooth(),
"&7 Help for &dAntiItemMove v" + AntiItemMoveMain.getVersion() + " &7by Rubix327",
"&7",
"&7 &d/aim [gui] &7- Open the plugin's GUI",
"&7 &d/aim save &7- Save item in hand as restricted",
"&7 &d/aim get <item_id> &7- Get an item by id",
"&7 &d/aim help &7- Open this page",
"&7 &d/aim reload &7- Reload the plugin",
"&8" + Common.chatLineSmooth()
);
Common.tellNoPrefix(getPlayer(), messages);
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.HELP);
Common.tellNoPrefix(getPlayer(), Settings.Messages.HELP);
}
else if ("reload".equalsIgnoreCase(args[0])){
checkPermission("antiitemmove.reload");
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.RELOAD);
AntiItemMoveMain.getInstance().loadFiles();
Common.tell(getPlayer(), "&aConfiguration reloaded!");
Common.tell(getPlayer(), "&7Configuration reloaded!");
}
else{
checkPermission("antiitemmove.syntax");
Util.checkPermissionCommand(getPlayer(), Settings.Permissions.SYNTAX);
Messenger.error(getPlayer(), syntax);
}

Expand All @@ -117,13 +129,12 @@ private void openMainMenu(Player player){

@Override
protected List<String> tabComplete() {
return new ArrayList<>(Arrays.asList("gui", "save", "get", "help", "reload"));
}

private void checkPermission(String permission){
if (!getPlayer().hasPermission(permission)){
Common.tell(getPlayer(), "&cYou don't have enough permissions.");
throw new CommandException();
if (args.length == 1){
return new ArrayList<>(Arrays.asList("gui", "save", "remove", "get", "help", "reload"));
}
if (args.length == 2 && args[0].equalsIgnoreCase("get") || args[0].equalsIgnoreCase("remove")){
return Collections.singletonList("<item_id>");
}
return Collections.singletonList("");
}
}
36 changes: 23 additions & 13 deletions src/main/java/me/rubix327/antiitemmove/PlayerListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.rubix327.antiitemmove;

import me.rubix327.antiitemmove.storage.*;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
Expand All @@ -24,8 +25,6 @@ public class PlayerListener implements Listener {
* This map only stores data between player death and respawn.
*/
private static final HashMap<UUID, List<ItemStack>> droppedItems = new HashMap<>();
private static final String optionPerm = "antiitemmove.bypass.option.";
private static final String itemPerm = "antiitemmove.bypass.item.";

@EventHandler
public void onItemDrop(PlayerDropItemEvent event){
Expand All @@ -34,9 +33,9 @@ public void onItemDrop(PlayerDropItemEvent event){
item.setAmount(1);

Integer itemId = ItemsStorage.getInstance().getKey(item);
if (itemId == null || event.getPlayer().hasPermission(optionPerm + "drop")
|| event.getPlayer().hasPermission(itemPerm + itemId + ".drop")
){
if (itemId == null || event.getPlayer().hasPermission(Settings.Permissions.BYPASS_OPTION.replace("$option", "drop"))
|| event.getPlayer().hasPermission(Settings.Permissions.BYPASS_ITEM_ID_OPTION.replace("$id", String.valueOf(itemId))
.replace("$option", "drop"))){
return;
}

Expand All @@ -55,13 +54,21 @@ public void onItemMove(InventoryClickEvent event){
String inventory = event.getInventory().getType().toString();

Integer itemId = ItemsStorage.getInstance().getKey(item);
if (itemId == null || event.getWhoClicked().hasPermission(optionPerm + inventory)
|| event.getWhoClicked().hasPermission(itemPerm + itemId + "." + inventory)){
if (itemId == null || event.getWhoClicked().hasPermission(Settings.Permissions.BYPASS_OPTION.replace("$option", inventory))
|| event.getWhoClicked().hasPermission(Settings.Permissions.BYPASS_ITEM_ID_OPTION.replace("$id", String.valueOf(itemId))
.replace("$option", inventory))){
return;
}

try{
List<IOption> bans = BansStorage.getInstance().getCachedBans().get(item);
if (inventory.equalsIgnoreCase("crafting")){
if (event.getWhoClicked().getGameMode() != GameMode.CREATIVE){
if (bans.contains(MoveOption.PLAYER_INVENTORY)){
event.setCancelled(true);
}
}
}
if (bans.contains(Group.ALL) || bans.contains(IOption.getOrNull(inventory))) {
event.setCancelled(true);
}
Expand All @@ -77,8 +84,9 @@ public void onItemPlace(PlayerInteractEvent event){
item.setAmount(1);

Integer itemId = ItemsStorage.getInstance().getKey(item);
if (itemId == null || event.getPlayer().hasPermission(optionPerm + "place")
|| event.getPlayer().hasPermission(itemPerm + itemId + ".place")){
if (itemId == null || event.getPlayer().hasPermission(Settings.Permissions.BYPASS_OPTION.replace("$option", "place"))
|| event.getPlayer().hasPermission(Settings.Permissions.BYPASS_ITEM_ID_OPTION.replace("$id", String.valueOf(itemId))
.replace("$option", "place"))){
return;
}

Expand All @@ -96,8 +104,9 @@ public void onItemFramePlace(PlayerInteractEntityEvent event){
item.setAmount(1);

Integer itemId = ItemsStorage.getInstance().getKey(item);
if (itemId == null || event.getPlayer().hasPermission(optionPerm + "item_frame")
|| event.getPlayer().hasPermission(itemPerm + itemId + ".item_frame")){
if (itemId == null || event.getPlayer().hasPermission(Settings.Permissions.BYPASS_OPTION.replace("$option", "item_frame"))
|| event.getPlayer().hasPermission(Settings.Permissions.BYPASS_ITEM_ID_OPTION.replace("$id", String.valueOf(itemId))
.replace("$option", "item_frame"))){
return;
}

Expand All @@ -119,8 +128,9 @@ public void onItemWasteDeath(PlayerDeathEvent event) {
if (!bans.contains(MoveOption.DIE)) continue;

Integer itemId = ItemsStorage.getInstance().getKey(itemStack);
if (itemId == null || event.getEntity().hasPermission(optionPerm + "die")
|| event.getEntity().hasPermission(itemPerm + itemId + ".die")){
if (itemId == null || event.getEntity().hasPermission(Settings.Permissions.BYPASS_OPTION.replace("$option", "id"))
|| event.getEntity().hasPermission(Settings.Permissions.BYPASS_ITEM_ID_OPTION.replace("$id", String.valueOf(itemId))
.replace("$option", "die"))){
return;
}

Expand Down
Loading

0 comments on commit 3211af4

Please sign in to comment.