Created
February 11, 2014 23:08
-
-
Save aadnk/8946262 to your computer and use it in GitHub Desktop.
Disable potion particles. Works in Minecraft 1.7.2 - 1.5.2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.comphenix.example; | |
import java.util.List; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import com.comphenix.protocol.PacketType; | |
import com.comphenix.protocol.ProtocolLibrary; | |
import com.comphenix.protocol.ProtocolManager; | |
import com.comphenix.protocol.events.PacketAdapter; | |
import com.comphenix.protocol.events.PacketEvent; | |
import com.comphenix.protocol.utility.MinecraftVersion; | |
import com.comphenix.protocol.wrappers.WrappedWatchableObject; | |
public class ExampleMod extends JavaPlugin { | |
private static final MinecraftVersion POTION_CHANGE = new MinecraftVersion("1.6.0"); | |
@Override | |
public void onEnable() { | |
final ProtocolManager manager = ProtocolLibrary.getProtocolManager(); | |
final int POTION_INDEX = manager.getMinecraftVersion().compareTo(POTION_CHANGE) <= 0 ? 8 : 7; | |
manager.addPacketListener( | |
new PacketAdapter(this, PacketType.Play.Server.ENTITY_METADATA) { | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
Entity entity = event.getPacket().getEntityModifier(event).read(0); | |
// Disable "personal" potion effect particles. | |
if (event.getPlayer().equals(entity)) { | |
modifyWatchable(event, POTION_INDEX, (int) 0); | |
} | |
// You can also disable potion effects on other player entities too. | |
} | |
}); | |
} | |
/** | |
* Set the value of a particular watchable object, if if is present in the list. | |
* @param event - the packet event. | |
* @param index - index of the watchable object. | |
* @param value - the new value, if the object is present. | |
*/ | |
private void modifyWatchable(PacketEvent event, int index, Object value) { | |
// Determine if we need to modify this packet | |
if (hasIndex(getWatchable(event), index)) { | |
// We do - clone it first, as it might have been broadcasted | |
event.setPacket(event.getPacket().deepClone()); | |
for (WrappedWatchableObject object : getWatchable(event)) { | |
if (object.getIndex() == index) { | |
object.setValue(value); | |
} | |
} | |
} | |
} | |
/** | |
* Fetch the current list of watchable objects. | |
* @param event - the packet event. | |
* @return List of watchabel objects. | |
*/ | |
private List<WrappedWatchableObject> getWatchable(PacketEvent event) { | |
return event.getPacket().getWatchableCollectionModifier().read(0); | |
} | |
/** | |
* Determine if a watchable object is present with the given index. | |
* @param list - the list of objects. | |
* @param index - the index. | |
* @return TRUE if there is such an object in the list, FALSE otherwise. | |
*/ | |
private boolean hasIndex(List<WrappedWatchableObject> list, int index) { | |
for (WrappedWatchableObject object : list) { | |
if (object.getIndex() == index) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: that class don't remove potion particles, it makes them only more transparent ("ambient") but you can see them anyway