Removed MineKart code.
Fixed up DisguisePlayer Added ProfileLoader Fixed up Notch gadget.
This commit is contained in:
parent
3a47a161c5
commit
931cb5ece8
@ -0,0 +1,118 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.util.com.mojang.authlib.properties.Property;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
public class ProfileLoader
|
||||
{
|
||||
private final String uuid;
|
||||
private final String name;
|
||||
private final String skinOwner;
|
||||
|
||||
public ProfileLoader(String uuid, String name)
|
||||
{
|
||||
this(uuid, name, name);
|
||||
}
|
||||
|
||||
public ProfileLoader(String uuid, String name, String skinOwner)
|
||||
{
|
||||
this.uuid = uuid == null ? null : uuid.replaceAll("-", ""); // We add
|
||||
// these
|
||||
// later
|
||||
String displayName = ChatColor.translateAlternateColorCodes('&', name);
|
||||
this.name = ChatColor.stripColor(displayName);
|
||||
this.skinOwner = skinOwner;
|
||||
}
|
||||
|
||||
public GameProfile loadProfile()
|
||||
{
|
||||
UUID id = uuid == null ? parseUUID(getUUID(name)) : parseUUID(uuid);
|
||||
GameProfile profile = new GameProfile(id, name);
|
||||
addProperties(profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
private void addProperties(GameProfile profile)
|
||||
{
|
||||
String uuid = getUUID(skinOwner);
|
||||
try
|
||||
{
|
||||
// Get the name from SwordPVP
|
||||
URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
|
||||
URLConnection uc = url.openConnection();
|
||||
uc.setUseCaches(false);
|
||||
uc.setDefaultUseCaches(false);
|
||||
uc.addRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
uc.addRequestProperty("Pragma", "no-cache");
|
||||
|
||||
// Parse it
|
||||
String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next();
|
||||
JSONParser parser = new JSONParser();
|
||||
Object obj = parser.parse(json);
|
||||
JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties");
|
||||
for (int i = 0; i < properties.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
JSONObject property = (JSONObject) properties.get(i);
|
||||
String name = (String) property.get("name");
|
||||
String value = (String) property.get("value");
|
||||
String signature = property.containsKey("signature") ? (String) property.get("signature") : null;
|
||||
if (signature != null)
|
||||
{
|
||||
profile.getProperties().put(name, new Property(name, value, signature));
|
||||
}
|
||||
else
|
||||
{
|
||||
profile.getProperties().put(name, new Property(value, name));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to apply auth property", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
; // Failed to load skin
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private String getUUID(String name)
|
||||
{
|
||||
return Bukkit.getOfflinePlayer(name).getUniqueId().toString().replaceAll("-", "");
|
||||
}
|
||||
|
||||
private UUID parseUUID(String uuidStr)
|
||||
{
|
||||
// Split uuid in to 5 components
|
||||
String[] uuidComponents = new String[] { uuidStr.substring(0, 8), uuidStr.substring(8, 12),
|
||||
uuidStr.substring(12, 16), uuidStr.substring(16, 20), uuidStr.substring(20, uuidStr.length()) };
|
||||
|
||||
// Combine components with a dash
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String component : uuidComponents)
|
||||
{
|
||||
builder.append(component).append('-');
|
||||
}
|
||||
|
||||
// Correct uuid length, remove last dash
|
||||
builder.setLength(builder.length() - 1);
|
||||
return UUID.fromString(builder.toString());
|
||||
}
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
package mineplex.core.disguise.disguises;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mineplex.core.common.util.UUIDFetcher;
|
||||
import net.minecraft.server.v1_7_R4.MathHelper;
|
||||
import net.minecraft.server.v1_7_R4.Packet;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
|
||||
@ -10,29 +7,23 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
public class DisguisePlayer extends DisguiseHuman
|
||||
{
|
||||
private String _name;
|
||||
private UUID _uuid;
|
||||
private GameProfile _profile;
|
||||
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
}
|
||||
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity, String name)
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity, GameProfile profile)
|
||||
{
|
||||
this(entity);
|
||||
|
||||
setName(name);
|
||||
setProfile(profile);
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
public void setProfile(GameProfile profile)
|
||||
{
|
||||
if (name.length() > 16)
|
||||
_name = name.substring(0, 16);
|
||||
else
|
||||
_name = name;
|
||||
|
||||
_uuid = UUIDFetcher.getUUIDOf(_name);
|
||||
_profile = profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,7 +31,7 @@ public class DisguisePlayer extends DisguiseHuman
|
||||
{
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
packet.a = Entity.getId();
|
||||
packet.b = new GameProfile(_uuid, _name);
|
||||
packet.b = _profile;
|
||||
packet.c = MathHelper.floor(Entity.locX * 32.0D);
|
||||
packet.d = MathHelper.floor(Entity.locY * 32.0D);
|
||||
packet.e = MathHelper.floor(Entity.locZ * 32.0D);
|
||||
|
@ -101,7 +101,7 @@ public class GadgetManager extends MiniPlugin
|
||||
addGadget(new MorphBlock(this));
|
||||
addGadget(new MorphVillager(this));
|
||||
addGadget(new MorphCow(this));
|
||||
//addGadget(new MorphNotch(this));
|
||||
addGadget(new MorphNotch(this));
|
||||
|
||||
// Particles
|
||||
addGadget(new ParticleGreen(this));
|
||||
|
@ -1,11 +1,15 @@
|
||||
package mineplex.core.gadget.gadgets;
|
||||
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.ProfileLoader;
|
||||
import mineplex.core.common.util.UUIDFetcher;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||
@ -15,6 +19,8 @@ import mineplex.core.gadget.types.MorphGadget;
|
||||
|
||||
public class MorphNotch extends MorphGadget
|
||||
{
|
||||
private GameProfile _notchProfile = null;
|
||||
|
||||
public MorphNotch(GadgetManager manager)
|
||||
{
|
||||
super(manager, "Notch", new String[]
|
||||
@ -24,6 +30,8 @@ public class MorphNotch extends MorphGadget
|
||||
},
|
||||
50000,
|
||||
ArmorSlot.Helmet, Material.SKULL_ITEM, (byte)3);
|
||||
|
||||
_notchProfile = new ProfileLoader(UUIDFetcher.getUUIDOf("Notch").toString(), "Notch").loadProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -31,8 +39,7 @@ public class MorphNotch extends MorphGadget
|
||||
{
|
||||
this.ApplyArmor(player);
|
||||
|
||||
DisguisePlayer disguise = new DisguisePlayer(player);
|
||||
disguise.setName("Notch");
|
||||
DisguisePlayer disguise = new DisguisePlayer(player, _notchProfile);
|
||||
Manager.getDisguiseManager().disguise(disguise);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -57,14 +56,12 @@ import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.minecraft.game.core.condition.ConditionManager;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.disguise.DisguiseManager;
|
||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||
import mineplex.core.disguise.disguises.DisguiseSlime;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
|
||||
import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.logger.Logger;
|
||||
import mineplex.core.mount.MountManager;
|
||||
import mineplex.core.pet.PetManager;
|
||||
import mineplex.core.portal.Portal;
|
||||
@ -421,11 +418,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
{
|
||||
if (((LivingEntity)entity).isCustomNameVisible() && ((LivingEntity)entity).getCustomName() != null)
|
||||
{
|
||||
if (ChatColor.stripColor(((LivingEntity)entity).getCustomName()).equalsIgnoreCase("Minekart"))
|
||||
{
|
||||
_disguiseManager.disguise(new DisguisePlayer(entity, ChatColor.YELLOW + "MineKart"));
|
||||
}
|
||||
else if (ChatColor.stripColor(((LivingEntity)entity).getCustomName()).equalsIgnoreCase("Block Hunt"))
|
||||
if (ChatColor.stripColor(((LivingEntity)entity).getCustomName()).equalsIgnoreCase("Block Hunt"))
|
||||
{
|
||||
DisguiseSlime disguise = new DisguiseSlime(entity);
|
||||
disguise.SetCustomNameVisible(true);
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user