Skip to content

Commit

Permalink
Merge pull request #1 from drjawa/master
Browse files Browse the repository at this point in the history
Revert enchantment spoofing removal
  • Loading branch information
rourke750 committed Sep 11, 2014
2 parents bedb5ff + 1c9f42d commit 08c25ff
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
@@ -1,6 +1,6 @@
name: AttrHider
main: com.civpvp.attrhider.AttrHider
version: 1.0.1
version: 1.0.2
description: Hides various armour and player attributes, such as enchantments and armour damage, to the client
author: Squeenix
depend: [ProtocolLib]
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@
<groupId>com.civpvp</groupId>
<artifactId>AttrHider</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<name>AttrHider</name>
<url>https://github.com/ttk2/AttrHider</url>

Expand Down
85 changes: 81 additions & 4 deletions src/com/civpvp/attrhider/AttrHider.java
Expand Up @@ -5,6 +5,8 @@
import java.util.Random;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
Expand All @@ -14,6 +16,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import com.comphenix.protocol.PacketType;
Expand Down Expand Up @@ -44,8 +47,26 @@ public void onEnable() {

private void registerPacketListeners(){
protocolManager = ProtocolLibrary.getProtocolManager();

//Strips potion duration length and sets it to 420 ticks so you can blaze it

//Strips armour
protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override
public void onPacketSending(PacketEvent e) {
try {
PacketContainer p = e.getPacket();
StructureModifier<ItemStack> items = p.getItemModifier();
ItemStack i = items.read(0);
if (i != null) {
adjustEnchantment(i);
items.write(0, i);
}
} catch (FieldAccessException exception) { //Should catch if the packet is the wrong type
exception.printStackTrace();
}
}
});

//Strips potion duration length and sets it to 420 ticks so you can blaze it
protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Play.Server.ENTITY_EFFECT){
@Override
public void onPacketSending(PacketEvent e){
Expand Down Expand Up @@ -92,8 +113,64 @@ public void onPacketSending(PacketEvent event) {
});

}

@EventHandler

private ItemStack adjustEnchantment(ItemStack i) {
if (i != null) {
Material type = i.getData().getItemType();
/* Only applying to commonly enchanted items because
* Items such as potions and wood rely on damage values for appearance
*/
if (type == Material.DIAMOND_HELMET
|| type == Material.DIAMOND_CHESTPLATE
|| type == Material.DIAMOND_LEGGINGS
|| type == Material.DIAMOND_BOOTS
|| type == Material.IRON_HELMET
|| type == Material.IRON_CHESTPLATE
|| type == Material.IRON_LEGGINGS
|| type == Material.IRON_BOOTS
|| type == Material.GOLD_HELMET
|| type == Material.GOLD_CHESTPLATE
|| type == Material.GOLD_LEGGINGS
|| type == Material.GOLD_BOOTS
|| type == Material.LEATHER_HELMET
|| type == Material.LEATHER_CHESTPLATE
|| type == Material.LEATHER_LEGGINGS
|| type == Material.LEATHER_BOOTS
|| type == Material.DIAMOND_SWORD
|| type == Material.GOLD_SWORD
|| type == Material.IRON_SWORD
|| type == Material.STONE_SWORD
|| type == Material.WOOD_SWORD
|| type == Material.DIAMOND_AXE
|| type == Material.GOLD_AXE
|| type == Material.IRON_AXE
|| type == Material.STONE_AXE
|| type == Material.WOOD_AXE
|| type == Material.DIAMOND_PICKAXE
|| type == Material.GOLD_PICKAXE
|| type == Material.IRON_PICKAXE
|| type == Material.STONE_PICKAXE
|| type == Material.WOOD_PICKAXE
|| type == Material.DIAMOND_SPADE
|| type == Material.GOLD_SPADE
|| type == Material.IRON_SPADE
|| type == Material.STONE_SPADE
|| type == Material.WOOD_SPADE) {
Object[] copy = i.getEnchantments().keySet().toArray();

for (Object enchantment : copy) {
i.removeEnchantment((Enchantment) enchantment);
}
i.setDurability((short) 1);
if (copy.length > 0) {
i.addEnchantment(Enchantment.DURABILITY, 1);
}
}
}
return i;
}

@EventHandler
public void onMount(final VehicleEnterEvent event) {
if ((event.getEntered() instanceof Player))
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
Expand Down

0 comments on commit 08c25ff

Please sign in to comment.