Made duping usage for class shop impossible

This commit is contained in:
AlexTheCoder 2016-07-28 20:22:30 -04:00
parent 97d5d21a55
commit 16804a860c
2 changed files with 60 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import java.sql.Timestamp;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestoreData;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
@ -23,6 +24,7 @@ import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -62,6 +64,25 @@ public class ClansGame extends MiniPlugin
_clans = clans;
}
public static boolean isDupedFromClassShop(ItemStack item)
{
if (item == null || item.getType() == Material.AIR)
{
return false;
}
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName())
{
return false;
}
String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()).toUpperCase();
if (name.contains("APPLY DEFAULT BUILD") || name.contains("APPLY BUILD") || name.contains("EDIT BUILD") || name.contains("DELETE BUILD"))
{
return true;
}
return false;
}
@EventHandler(ignoreCancelled = true)
public void openClanShop(PlayerInteractEvent event)
{
@ -102,6 +123,26 @@ public class ClansGame extends MiniPlugin
if (event.getBlock().getType() != Material.LADDER) return;
if (isDupedFromClassShop(event.getItemInHand()))
{
event.setCancelled(true);
for (Player p : Bukkit.getOnlinePlayers())
{
if (ClansManager.getInstance().getClientManager().hasRank(p, Rank.HELPER))
{
UtilPlayer.message(p, F.elem("[" + C.cRedB + "!" + C.cGray + "] ") + event.getPlayer().getName() + " just tried to use a duped item/block!");
}
}
final int slot = event.getPlayer().getInventory().getHeldItemSlot();
ClansManager.getInstance().runSyncLater(() ->
{
event.getPlayer().getInventory().setItem(slot, new ItemStack(Material.AIR));
event.getPlayer().updateInventory();
}, 1L);
return;
}
if (_clans.getClanUtility().getAccess(event.getPlayer(), event.getBlock().getLocation()) == ClanRelation.SELF) return;
final Block block = event.getBlock();

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -22,6 +23,7 @@ import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
@ -36,6 +38,8 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansGame;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
@ -216,6 +220,7 @@ public class Cannon extends SiegeWeapon
}));
}
@SuppressWarnings("deprecation")
@EventHandler
protected void InventoryClick(InventoryClickEvent event)
{
@ -224,7 +229,7 @@ public class Cannon extends SiegeWeapon
return;
}
if (event.getClick() == ClickType.SHIFT_RIGHT || event.getClick() == ClickType.SHIFT_RIGHT)
if (event.getClick() == ClickType.SHIFT_RIGHT || event.getClick() == ClickType.SHIFT_LEFT)
{
if(_inventory.getViewers().contains(event.getWhoClicked()))
{
@ -282,6 +287,19 @@ public class Cannon extends SiegeWeapon
{
event.setCancelled(true);
}
else if (event.getSlot() == _ammunitionSlot && ClansGame.isDupedFromClassShop(event.getCursor()))
{
event.setCancelled(true);
for (Player p : Bukkit.getOnlinePlayers())
{
if (ClansManager.getInstance().getClientManager().hasRank(p, Rank.HELPER))
{
UtilPlayer.message(p, F.elem("[" + C.cRedB + "!" + C.cGray + "] ") + event.getWhoClicked().getName() + " just tried to use a duped item/block!");
}
}
event.setCursor(new ItemStack(Material.AIR));
((Player)event.getWhoClicked()).updateInventory();
}
}
private void updateInventory()