mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-05 09:09:40 +01:00
First commit
This commit is contained in:
commit
739ce9f10e
22
.gitattributes
vendored
Normal file
22
.gitattributes
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
215
.gitignore
vendored
Normal file
215
.gitignore
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.project
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.classpath
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
build/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.log
|
||||
*.scc
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
*.pubxml
|
||||
|
||||
# NuGet Packages Directory
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||
#packages/
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.[Pp]ublish.xml
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
App_Data/*.mdf
|
||||
App_Data/*.ldf
|
||||
|
||||
#############
|
||||
## Windows detritus
|
||||
#############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[co]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist/
|
||||
build/
|
||||
eggs/
|
||||
parts/
|
||||
var/
|
||||
sdist/
|
||||
develop-eggs/
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
8
plugin.yml
Normal file
8
plugin.yml
Normal file
@ -0,0 +1,8 @@
|
||||
name: LibsDisguises
|
||||
main: me.libraryaddict.disguise.LibsDisguises
|
||||
version: ${project.version}
|
||||
author: libraryaddict
|
||||
depend: [ProtocolLib]
|
||||
commands:
|
||||
disguise:
|
||||
aliases: [d, dis]
|
62
pom.xml
Normal file
62
pom.xml
Normal file
@ -0,0 +1,62 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>LibsDisguises</groupId>
|
||||
<artifactId>LibsDisguises</artifactId>
|
||||
<version>v1.0</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<directory>target</directory>
|
||||
<finalName>LibsDisguises</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${project.basedir}</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
<include>README.md</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>comphenix-rep</id>
|
||||
<name>Comphenix Repository</name>
|
||||
<url>http://repo.comphenix.net/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>2.4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.5.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
116
src/me/libraryaddict/disguise/DisguiseAPI.java
Normal file
116
src/me/libraryaddict/disguise/DisguiseAPI.java
Normal file
@ -0,0 +1,116 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
|
||||
import net.minecraft.server.v1_5_R3.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DisguiseAPI {
|
||||
|
||||
private static ConcurrentHashMap<String, Disguise> disguises = new ConcurrentHashMap<String, Disguise>();
|
||||
|
||||
/**
|
||||
* @param Player
|
||||
* - The player to disguise
|
||||
* @param Disguise
|
||||
* - The disguise to wear
|
||||
*/
|
||||
public static void disguiseToAll(Player p, Disguise disguise) {
|
||||
disguises.put(p.getName(), disguise);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (p.getWorld() != player.getWorld())
|
||||
continue;
|
||||
player.hidePlayer(p);
|
||||
player.showPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player
|
||||
* - The player who is being disguised
|
||||
* @param Player
|
||||
* - The player who is watching the disguised
|
||||
* @param Disguise
|
||||
* - The disguise he is wearing
|
||||
*/
|
||||
public static void disguiseToPlayer(Player disguiser, Player observer, Disguise disguise) {
|
||||
disguises.put(disguiser.getName(), disguise);
|
||||
Packet29DestroyEntity destroyPacket = new Packet29DestroyEntity(new int[] { disguiser.getEntityId() });
|
||||
Packet spawnPacket = null;
|
||||
if (disguise.getType().isMob()) {
|
||||
|
||||
EntityLiving entityLiving = ((MobDisguise) disguise).getEntityLiving(((CraftPlayer) disguiser).getHandle().world,
|
||||
disguiser.getLocation(), disguiser.getEntityId());
|
||||
spawnPacket = new Packet24MobSpawn(entityLiving);
|
||||
|
||||
} else if (disguise.getType().isMisc()) {
|
||||
|
||||
Entity entity = disguise.getEntity(((CraftPlayer) disguiser).getHandle().world, disguiser.getLocation(),
|
||||
disguiser.getEntityId());
|
||||
spawnPacket = new Packet23VehicleSpawn(entity, 0);
|
||||
|
||||
} else if (disguise.getType().isPlayer()) {
|
||||
|
||||
EntityHuman entityHuman = ((CraftPlayer) disguiser).getHandle();
|
||||
spawnPacket = new Packet20NamedEntitySpawn(entityHuman);
|
||||
((Packet20NamedEntitySpawn) spawnPacket).b = ((PlayerDisguise) disguise).getName();
|
||||
|
||||
}
|
||||
((CraftPlayer) observer).getHandle().playerConnection.sendPacket(destroyPacket);
|
||||
((CraftPlayer) observer).getHandle().playerConnection.sendPacket(spawnPacket);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* @return Disguise
|
||||
*/
|
||||
public static Disguise getDisguise(Player p) {
|
||||
return getDisguise(p.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* @return Disguise
|
||||
*/
|
||||
public static Disguise getDisguise(String name) {
|
||||
return disguises.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* @return Boolean - If the disguiser is disguised
|
||||
*/
|
||||
public static boolean isDisguised(Player p) {
|
||||
return isDisguised(p.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* @return boolean - If the disguiser is disguised
|
||||
*/
|
||||
public static boolean isDisguised(String name) {
|
||||
return disguises.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* - Undisguises him
|
||||
*/
|
||||
public static void undisguiseToAll(Player p) {
|
||||
disguises.remove(p.getName());
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (p.getWorld() != player.getWorld())
|
||||
continue;
|
||||
player.hidePlayer(p);
|
||||
player.showPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
80
src/me/libraryaddict/disguise/DisguiseCommand.java
Normal file
80
src/me/libraryaddict/disguise/DisguiseCommand.java
Normal file
@ -0,0 +1,80 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.MiscDisguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DisguiseCommand implements CommandExecutor {
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender.isOp()) {
|
||||
Player p = (Player) sender;
|
||||
if (args.length == 0) {
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
names.add(type.name().toLowerCase());
|
||||
}
|
||||
Collections.sort(names);
|
||||
sender.sendMessage(ChatColor.RED + "You can use the disguises: " + ChatColor.GREEN
|
||||
+ StringUtils.join(names, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||
} else if (args[0].equalsIgnoreCase("undiguise") || args[0].equalsIgnoreCase("undis")
|
||||
|| args[0].equalsIgnoreCase("un")) {
|
||||
if (DisguiseAPI.isDisguised(p.getName())) {
|
||||
DisguiseAPI.undisguiseToAll(p);
|
||||
sender.sendMessage(ChatColor.RED + "You are no longer disguised");
|
||||
} else
|
||||
sender.sendMessage(ChatColor.RED + "You are not disguised!");
|
||||
} else if (args[0].equalsIgnoreCase("player")) {
|
||||
if (args.length > 1) {
|
||||
String name = ChatColor.translateAlternateColorCodes('&',
|
||||
StringUtils.join(args, " ").substring(args[0].length() + 1));
|
||||
PlayerDisguise disguise = new PlayerDisguise(name);
|
||||
DisguiseAPI.disguiseToAll(p, disguise);
|
||||
sender.sendMessage(ChatColor.RED + "Now disguised as the player '" + ChatColor.GREEN + name + ChatColor.RESET
|
||||
+ ChatColor.RED + "'");
|
||||
} else
|
||||
sender.sendMessage(ChatColor.RED + "You need to provide a player name");
|
||||
} else {
|
||||
DisguiseType type;
|
||||
try {
|
||||
type = DisguiseType.valueOf(args[0].toUpperCase());
|
||||
} catch (Exception ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Failed to find disguise: " + ChatColor.GREEN + args[0]
|
||||
+ "\n/disguise player <Name>\n/disguise <Mob Name>\n/disguise undisguise/un/undis");
|
||||
return true;
|
||||
}
|
||||
boolean adult = true;
|
||||
if (args.length > 1) {
|
||||
if (args[1].equalsIgnoreCase("true")) {
|
||||
adult = false;
|
||||
} else if (!args[1].equalsIgnoreCase("false")) {
|
||||
sender.sendMessage(ChatColor.RED + "Set baby: " + ChatColor.GREEN + args[1] + ChatColor.RED
|
||||
+ " - Thats not true or false..");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Disguise disguise;
|
||||
if (type.isMob())
|
||||
disguise = new MobDisguise(type, adult);
|
||||
else
|
||||
disguise = new MiscDisguise(type);
|
||||
DisguiseAPI.disguiseToAll(p, disguise);
|
||||
sender.sendMessage(ChatColor.RED + "Now disguised as a " + type.name().toLowerCase() + "!");
|
||||
}
|
||||
} else
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission");
|
||||
return true;
|
||||
}
|
||||
}
|
72
src/me/libraryaddict/disguise/DisguiseTypes/Disguise.java
Normal file
72
src/me/libraryaddict/disguise/DisguiseTypes/Disguise.java
Normal file
@ -0,0 +1,72 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.server.v1_5_R3.DataWatcher;
|
||||
import net.minecraft.server.v1_5_R3.Entity;
|
||||
import net.minecraft.server.v1_5_R3.EntityCreeper;
|
||||
import net.minecraft.server.v1_5_R3.EntitySkeleton;
|
||||
import net.minecraft.server.v1_5_R3.World;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Disguise {
|
||||
protected DisguiseType disguiseType;
|
||||
private Entity entity;
|
||||
|
||||
protected Disguise(DisguiseType newType) {
|
||||
disguiseType = newType;
|
||||
}
|
||||
|
||||
public Entity getEntity(World world, Location loc, int entityId) {
|
||||
Entity entity = null;
|
||||
try {
|
||||
String name = toReadable(disguiseType.name());
|
||||
if (disguiseType == DisguiseType.WITHER_SKELETON) {
|
||||
name = "Skeleton";
|
||||
}
|
||||
if (disguiseType == DisguiseType.CHARGED_CREEPER) {
|
||||
name = "Creeper";
|
||||
}
|
||||
if (disguiseType == DisguiseType.TNT_PRIMED) {
|
||||
name = "TNTPrimed";
|
||||
}
|
||||
Class entityClass = Class.forName("net.minecraft.server.v1_5_R3.Entity" + name);
|
||||
Constructor<?> contructor = entityClass.getDeclaredConstructor(World.class);
|
||||
entity = (Entity) contructor.newInstance(world);
|
||||
if (disguiseType == DisguiseType.WITHER_SKELETON) {
|
||||
((EntitySkeleton) entity).setSkeletonType(1);
|
||||
}
|
||||
if (disguiseType == DisguiseType.CHARGED_CREEPER) {
|
||||
((EntityCreeper) entity).setPowered(true);
|
||||
}
|
||||
Field field = Entity.class.getDeclaredField("datawatcher");
|
||||
field.setAccessible(true);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
entity.id = entityId;
|
||||
this.entity = entity;
|
||||
return entity;
|
||||
}
|
||||
|
||||
public DisguiseType getType() {
|
||||
return disguiseType;
|
||||
}
|
||||
|
||||
public DataWatcher getDataWatcher() {
|
||||
return entity.getDataWatcher();
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String toReadable(String string) {
|
||||
String[] strings = string.split("_");
|
||||
string = "";
|
||||
for (String s : strings)
|
||||
string += s.substring(0, 1) + s.substring(1).toLowerCase();
|
||||
return string;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
public enum DisguiseType {
|
||||
BAT(EntityType.MOB), BLAZE(EntityType.MOB), CAVE_SPIDER(EntityType.MOB), CHARGED_CREEPER(EntityType.MOB), CHICKEN(
|
||||
EntityType.MOB), COW(EntityType.MOB), CREEPER(EntityType.MOB), ENDER_CRYSTAL(EntityType.MISC), ENDER_DRAGON(
|
||||
EntityType.MOB), ENDERMAN(EntityType.MOB), GHAST(EntityType.MOB), GIANT_ZOMBIE(EntityType.MOB), IRON_GOLEM(EntityType.MOB), MAGMA_CUBE(
|
||||
EntityType.MOB), MUSHROOM_COW(EntityType.MOB), OCELOT(EntityType.MOB), PIG(EntityType.MOB), PIG_ZOMBIE(EntityType.MOB), PLAYER(
|
||||
EntityType.PLAYER), TNT_PRIMED(EntityType.MISC), SHEEP(EntityType.MOB), SILVERFISH(EntityType.MOB), SKELETON(
|
||||
EntityType.MOB), SLIME(EntityType.MOB), SNOWMAN(EntityType.MOB), SPIDER(EntityType.MOB), SQUID(EntityType.MOB), VILLAGER(
|
||||
EntityType.MOB), WITCH(EntityType.MOB), WITHER(EntityType.MOB), WITHER_SKELETON(EntityType.MOB), WOLF(EntityType.MOB), ZOMBIE(
|
||||
EntityType.MOB);
|
||||
|
||||
public static enum EntityType {
|
||||
MISC, MOB, PLAYER;
|
||||
}
|
||||
|
||||
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
||||
return DisguiseType.valueOf(entityType.name());
|
||||
}
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private DisguiseType(EntityType newType) {
|
||||
entityType = newType;
|
||||
}
|
||||
|
||||
public boolean isMisc() {
|
||||
return entityType == EntityType.MISC;
|
||||
}
|
||||
|
||||
public boolean isMob() {
|
||||
return entityType == EntityType.MOB;
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return entityType == EntityType.PLAYER;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
public class MiscDisguise extends Disguise {
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType) {
|
||||
super(disguiseType);
|
||||
}
|
||||
|
||||
}
|
40
src/me/libraryaddict/disguise/DisguiseTypes/MobDisguise.java
Normal file
40
src/me/libraryaddict/disguise/DisguiseTypes/MobDisguise.java
Normal file
@ -0,0 +1,40 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
import net.minecraft.server.v1_5_R3.Entity;
|
||||
import net.minecraft.server.v1_5_R3.EntityAgeable;
|
||||
import net.minecraft.server.v1_5_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_5_R3.EntityZombie;
|
||||
import net.minecraft.server.v1_5_R3.World;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class MobDisguise extends Disguise {
|
||||
|
||||
private boolean adult;
|
||||
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
|
||||
super(disguiseType);
|
||||
adult = isAdult;
|
||||
}
|
||||
|
||||
public EntityLiving getEntityLiving(World w, Location loc, int id) {
|
||||
Entity entity = getEntity(w, loc, id);
|
||||
if (!adult) {
|
||||
if (entity instanceof EntityAgeable)
|
||||
((EntityAgeable) entity).setAge(-24000);
|
||||
else if (entity instanceof EntityZombie)
|
||||
((EntityZombie) entity).setBaby(true);
|
||||
}
|
||||
if (entity instanceof EntityLiving)
|
||||
return (EntityLiving) entity;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
return adult;
|
||||
}
|
||||
|
||||
public void setAdult(boolean setAdult) {
|
||||
adult = setAdult;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
public class PlayerDisguise extends Disguise {
|
||||
private String playerName;
|
||||
|
||||
public PlayerDisguise(String name) {
|
||||
super(DisguiseType.PLAYER);
|
||||
if (name.length() > 16)
|
||||
name = name.substring(0, 16);
|
||||
playerName = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
}
|
101
src/me/libraryaddict/disguise/LibsDisguises.java
Normal file
101
src/me/libraryaddict/disguise/LibsDisguises.java
Normal file
@ -0,0 +1,101 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.MiscDisguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
|
||||
import net.minecraft.server.v1_5_R3.DataWatcher;
|
||||
import net.minecraft.server.v1_5_R3.Entity;
|
||||
import net.minecraft.server.v1_5_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ConnectionSide;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
getCommand("disguise").setExecutor(new DisguiseCommand());
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(
|
||||
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, Packets.Server.NAMED_ENTITY_SPAWN,
|
||||
Packets.Server.ENTITY_METADATA) {
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
try {
|
||||
Player observer = event.getPlayer();
|
||||
org.bukkit.entity.Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
||||
if (entity instanceof Player) {
|
||||
Player watched = (Player) entity;
|
||||
if (DisguiseAPI.isDisguised(watched.getName())) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(watched);
|
||||
if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
|
||||
if (disguise.getType().isMob()) {
|
||||
event.setCancelled(true);
|
||||
DisguiseAPI.disguiseToPlayer(watched, observer, (MobDisguise) disguise);
|
||||
} else if (disguise.getType().isMisc()) {
|
||||
event.setCancelled(true);
|
||||
DisguiseAPI.disguiseToPlayer(watched, observer, (MiscDisguise) disguise);
|
||||
} else if (disguise.getType().isPlayer()) {
|
||||
String name = (String) mods.read(1);
|
||||
if (!name.equals(((PlayerDisguise) disguise).getName())) {
|
||||
event.setCancelled(true);
|
||||
DisguiseAPI.disguiseToPlayer(watched, observer, (PlayerDisguise) disguise);
|
||||
}
|
||||
}
|
||||
} else if (!disguise.getType().isPlayer()) {
|
||||
mods.write(1, modifyDataWatcher(disguise, watched));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private List modifyDataWatcher(Disguise disguise, Player p) {
|
||||
Entity e = disguise.getEntity();
|
||||
EntityPlayer hE = ((CraftPlayer) p).getHandle();
|
||||
e.setAirTicks(hE.getAirTicks());
|
||||
e.fireTicks = p.getFireTicks();
|
||||
a(e.getDataWatcher(), 0, e.fireTicks > 0);
|
||||
e.setSprinting(p.isSprinting());
|
||||
e.setSneaking(p.isSneaking());
|
||||
if (e instanceof EntityLiving) {
|
||||
EntityLiving lE = (EntityLiving) e;
|
||||
lE.setInvisible(hE.isInvisible());
|
||||
lE.effects = hE.effects;
|
||||
lE.updateEffects = true;
|
||||
try {
|
||||
Method method = EntityLiving.class.getDeclaredMethod("bA");
|
||||
method.setAccessible(true);
|
||||
method.invoke(lE);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
return e.getDataWatcher().b();
|
||||
}
|
||||
|
||||
protected void a(DataWatcher datawatcher, int i, boolean flag) {
|
||||
byte b0 = datawatcher.getByte(0);
|
||||
if (flag) {
|
||||
datawatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << i)));
|
||||
} else {
|
||||
datawatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << i))));
|
||||
}
|
||||
}
|
||||
}
|
BIN
target/LibsDisguises.jar
Normal file
BIN
target/LibsDisguises.jar
Normal file
Binary file not shown.
BIN
target/classes/me/libraryaddict/disguise/DisguiseAPI.class
Normal file
BIN
target/classes/me/libraryaddict/disguise/DisguiseAPI.class
Normal file
Binary file not shown.
BIN
target/classes/me/libraryaddict/disguise/DisguiseCommand.class
Normal file
BIN
target/classes/me/libraryaddict/disguise/DisguiseCommand.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/me/libraryaddict/disguise/LibsDisguises$1.class
Normal file
BIN
target/classes/me/libraryaddict/disguise/LibsDisguises$1.class
Normal file
Binary file not shown.
BIN
target/classes/me/libraryaddict/disguise/LibsDisguises.class
Normal file
BIN
target/classes/me/libraryaddict/disguise/LibsDisguises.class
Normal file
Binary file not shown.
8
target/classes/plugin.yml
Normal file
8
target/classes/plugin.yml
Normal file
@ -0,0 +1,8 @@
|
||||
name: LibsDisguises
|
||||
main: me.libraryaddict.disguise.LibsDisguises
|
||||
version: v1.0
|
||||
author: libraryaddict
|
||||
depend: [ProtocolLib]
|
||||
commands:
|
||||
disguise:
|
||||
aliases: [d, dis]
|
5
target/maven-archiver/pom.properties
Normal file
5
target/maven-archiver/pom.properties
Normal file
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sat May 18 09:04:19 NZST 2013
|
||||
version=v1.0
|
||||
groupId=LibsDisguises
|
||||
artifactId=LibsDisguises
|
Loading…
Reference in New Issue
Block a user