Added Anti-FChest-Items

(Ability to deny storing items in factions chest)
This commit is contained in:
Driftay 2019-09-24 06:39:43 -04:00
parent 8338e21dd2
commit f358e6d75b
4 changed files with 75 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import com.massivecraft.factions.cmd.FCmdRoot;
import com.massivecraft.factions.cmd.FCommand; import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.cmd.check.CheckTask; import com.massivecraft.factions.cmd.check.CheckTask;
import com.massivecraft.factions.cmd.check.WeeWooTask; import com.massivecraft.factions.cmd.check.WeeWooTask;
import com.massivecraft.factions.cmd.chest.AntiChestListener;
import com.massivecraft.factions.cmd.chest.ChestLogsHandler; import com.massivecraft.factions.cmd.chest.ChestLogsHandler;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
@ -86,6 +87,7 @@ public class FactionsPlugin extends MPlugin {
private ClipPlaceholderAPIManager clipPlaceholderAPIManager; private ClipPlaceholderAPIManager clipPlaceholderAPIManager;
private boolean mvdwPlaceholderAPIManager = false; private boolean mvdwPlaceholderAPIManager = false;
private Listener[] eventsListener; private Listener[] eventsListener;
public List<String> itemList = getConfig().getStringList("fchest.Items-Not-Allowed");
public FactionsPlugin() { public FactionsPlugin() {
@ -268,6 +270,7 @@ public class FactionsPlugin extends MPlugin {
new FUpgradesGUI(), new FUpgradesGUI(),
new UpgradesListener(), new UpgradesListener(),
new MissionHandler(this), new MissionHandler(this),
new AntiChestListener(),
new ChestLogsHandler() new ChestLogsHandler()
}; };

View File

@ -0,0 +1,67 @@
package com.massivecraft.factions.cmd.chest;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class AntiChestListener implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (!e.getView().getTopInventory().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")))) return;
if (e.isCancelled()) return;
Inventory clicked = e.getClickedInventory();
if (e.getClick().isShiftClick()) {
if (clicked == e.getWhoClicked().getInventory()) {
ItemStack clickedOn = e.getCurrentItem();
if (clickedOn != null && FactionsPlugin.getInstance().itemList.contains(clickedOn.getType().toString())) {
fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, clickedOn.getType().toString());
e.setCancelled(true);
}
}
}
if (clicked != e.getWhoClicked().getInventory()) {
ItemStack onCursor = e.getCursor();
if (onCursor != null && FactionsPlugin.getInstance().itemList.contains(onCursor.getType().toString())) {
fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, onCursor.getType().toString());
e.setCancelled(true);
}
}
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent e) {
Player p = (Player) e.getWhoClicked();
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(p);
if (!e.getView().getTopInventory().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")))) return;
if (e.isCancelled()) return;
ItemStack dragged = e.getOldCursor();
if (FactionsPlugin.getInstance().itemList.contains(dragged.getType().toString())) {
int inventorySize = e.getInventory().getSize();
for (int i : e.getRawSlots()) {
if (i < inventorySize) {
fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, dragged.getType().toString());
e.setCancelled(true);
break;
}
}
}
}
}

View File

@ -239,6 +239,8 @@ public enum TL {
COMMAND_CLAIMLINE_ABOVEMAX("&c&l[!]&7 The &cmaximum&7 limit for claim line is &c%s&7."), COMMAND_CLAIMLINE_ABOVEMAX("&c&l[!]&7 The &cmaximum&7 limit for claim line is &c%s&7."),
COMMAND_CLAIMLINE_NOTVALID("&c&l[!]&7 &c%s&7 is not a &ccardinal &7direction. You may use &cnorth&7, &ceast&7, &csouth &7or &cwest&7."), COMMAND_CLAIMLINE_NOTVALID("&c&l[!]&7 &c%s&7 is not a &ccardinal &7direction. You may use &cnorth&7, &ceast&7, &csouth &7or &cwest&7."),
CHEST_ITEM_DENIED_TRANSFER("&c&l[!] &7You may not transfer &b%1$s &7into your factions chest!"),
COMMAND_CONFIG_NOEXIST("&c&l[!]&7 No configuration setting \"&c%1$s&7\" exists."), COMMAND_CONFIG_NOEXIST("&c&l[!]&7 No configuration setting \"&c%1$s&7\" exists."),
COMMAND_CONFIG_SET_TRUE("\" option set to true (enabled)."), COMMAND_CONFIG_SET_TRUE("\" option set to true (enabled)."),
COMMAND_CONFIG_SET_FALSE("\" option set to false (disabled)."), COMMAND_CONFIG_SET_FALSE("\" option set to false (disabled)."),

View File

@ -857,6 +857,9 @@ fvault:
fchest: fchest:
Enabled: true Enabled: true
Inventory-Title: '&2&lFaction Chest' Inventory-Title: '&2&lFaction Chest'
Items-Not-Allowed:
- 'MOB_SPAWNER'
- 'COOKIE'
# Chest size upgrades can be configured in the upgrades section of config # Chest size upgrades can be configured in the upgrades section of config
############################################################ ############################################################