Skip to content

Commit

Permalink
Prevent players from adding the shortcut to item frames and armor stands
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Jan 9, 2020
1 parent 6716927 commit 124f865
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>

<scm>
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public String getDBFields(String sub, String def)
public boolean getUseUUIDs()
{
boolean uuid = getConfigE().getBoolean("Database.UseUUIDs", true);
if(!uuid) logger.warning(ConsoleColor.RED + "Disabling UUIDs is not recommended and can lead to unexpected behaviour. Please consider enabling UUIDs. The option will be removed with v2.1." + ConsoleColor.RESET);
if(!uuid) logger.warning(ConsoleColor.RED + "Disabling UUIDs is not recommended and can lead to unexpected behaviour. Please consider enabling UUIDs. The option will be removed at some point." + ConsoleColor.RESET);
return uuid;
}

Expand Down
39 changes: 35 additions & 4 deletions src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package at.pcgamingfreaks.Minepacks.Bukkit.Listener;

import at.pcgamingfreaks.Bukkit.HeadUtils;
import at.pcgamingfreaks.Bukkit.MCVersion;
import at.pcgamingfreaks.Bukkit.Message.Message;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;

Expand All @@ -33,10 +34,8 @@
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -97,6 +96,38 @@ public void onItemInteract(PlayerInteractEvent event)
}
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onArmorStandManipulation(PlayerArmorStandManipulateEvent event)
{
if(isItemShortcut(event.getPlayerItem()))
{
event.getPlayer().performCommand("backpack open");
event.setCancelled(true);
}
}

private static final boolean DUAL_WIELDING_MC = MCVersion.isNewerOrEqualThan(MCVersion.MC_1_9);

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onItemFrameInteract(PlayerInteractEntityEvent event)
{
Player player = event.getPlayer();
ItemStack item;
if(DUAL_WIELDING_MC)
{
item = (event.getHand() == EquipmentSlot.HAND) ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
}
else
{
item = player.getItemInHand();
}
if(isItemShortcut(item))
{
event.getPlayer().performCommand("backpack open");
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onItemClick(InventoryClickEvent event)
{
Expand Down

0 comments on commit 124f865

Please sign in to comment.