Improving the /disguise command.

This commit is contained in:
Sarah 2015-08-05 07:57:52 +02:00
parent 95bb4ab04b
commit e55557e1fd
8 changed files with 73 additions and 69 deletions

View File

@ -8,6 +8,7 @@ public class CoreClient
{ {
private int _accountId = -1; private int _accountId = -1;
private String _name; private String _name;
private String _disguisedAs;
private Player _player; private Player _player;
private Rank _rank; private Rank _rank;
@ -62,4 +63,14 @@ public class CoreClient
{ {
_rank = rank; _rank = rank;
} }
public String getDisguisedAs()
{
return _disguisedAs;
}
public void setDisguisedAs(String originalName)
{
this._disguisedAs = originalName;
}
} }

View File

@ -118,16 +118,19 @@ public class CoreClientManager extends MiniPlugin
{ {
synchronized(_clientLock) synchronized(_clientLock)
{ {
for(CoreClient client : _clientList.values())
{
if(client.getDisguisedAs() != null)
if(client.getDisguisedAs().equalsIgnoreCase(name))
return client;
}
return _clientList.get(name); return _clientList.get(name);
} }
} }
public CoreClient Get(Player player) public CoreClient Get(Player player)
{ {
synchronized(_clientLock) return Get(player.getName());
{
return _clientList.get(player.getName());
}
} }
public int getPlayerCountIncludingConnecting() public int getPlayerCountIncludingConnecting()

View File

@ -1,15 +1,23 @@
package mineplex.core.stats; package mineplex.core.stats;
import java.lang.reflect.Field;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Iterator; import java.util.Iterator;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniDbClientPlugin; import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.command.GiveStatCommand; import mineplex.core.stats.command.GiveStatCommand;

View File

@ -1,61 +0,0 @@
package nautilus.game.arcade.command;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.ProfileLoader;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguisePlayer;
import nautilus.game.arcade.ArcadeManager;
public class DisguiseCommand extends CommandBase<ArcadeManager>
{
public DisguiseCommand(ArcadeManager plugin)
{
super(plugin, Rank.ADMIN, new Rank[] {Rank.YOUTUBE, Rank.TWITCH, Rank.JNR_DEV}, "disguise");
}
@Override
public void Execute(final Player caller, final String[] args)
{
if (args.length == 0)
{
UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise <name>");
return;
}
Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
{
@Override
public void run()
{
try
{
final GameProfile profile = new ProfileLoader(UUIDFetcher.getUUIDOf(args[0]).toString(), args[0]).loadProfile();
Bukkit.getServer().getScheduler().runTask(Plugin.getPlugin(), new Runnable()
{
public void run()
{
DisguisePlayer playerDisguise = new DisguisePlayer(caller, profile);
Plugin.GetDisguise().disguise(playerDisguise);
UtilPlayer.message(caller, C.cGreen + C.Bold + "Disguise Active: " + ChatColor.RESET + args[0]);
}
});
}
catch (Exception e)
{
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
return;
}
}}
);
}
}

View File

@ -10,7 +10,7 @@ public class KitUnlockCommand extends CommandBase<ArcadeManager>
{ {
public KitUnlockCommand(ArcadeManager plugin) public KitUnlockCommand(ArcadeManager plugin)
{ {
super(plugin, Rank.OWNER, new Rank[] {Rank.YOUTUBE, Rank.TWITCH}, new String[] {"youtube", "twitch", "kits"}); super(plugin, Rank.OWNER, new Rank[] {Rank.YOUTUBE, Rank.TWITCH, Rank.JNR_DEV}, new String[] {"youtube", "twitch", "kits"});
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package nautilus.game.arcade.game; package nautilus.game.arcade.game;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -13,6 +14,8 @@ import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging; import org.bukkit.entity.Hanging;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -55,6 +58,8 @@ import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.scoreboard.GameScoreboard; import nautilus.game.arcade.scoreboard.GameScoreboard;
import nautilus.game.arcade.stats.*; import nautilus.game.arcade.stats.*;
import nautilus.game.arcade.world.WorldData; import nautilus.game.arcade.world.WorldData;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.util.com.mojang.authlib.GameProfile;
public abstract class Game implements Listener public abstract class Game implements Listener
{ {

View File

@ -7,9 +7,8 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.party.Party; import mineplex.core.party.Party;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,7 +1,9 @@
package nautilus.game.arcade.managers; package nautilus.game.arcade.managers;
import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import mineplex.core.account.event.GetClientEvent;
import mineplex.core.achievement.Achievement; import mineplex.core.achievement.Achievement;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -18,8 +20,12 @@ import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GemData; import nautilus.game.arcade.game.GemData;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.GameTeam.PlayerState;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -157,6 +163,14 @@ public class GameGemManager implements Listener
int total = earned; int total = earned;
String oldName = player.getName();
if(Manager.GetClients().Get(player).getDisguisedAs() != null)
{
changeName(player, Manager.GetClients().Get(player).GetPlayerName());
System.out.println("Gems for " + Manager.GetClients().Get(player).GetPlayerName());
}
//Gem Boooster //Gem Boooster
if (game.GemBoosterEnabled) if (game.GemBoosterEnabled)
total += (int)(earned * game.GetGemBoostAmount()); total += (int)(earned * game.GetGemBoostAmount());
@ -179,6 +193,31 @@ public class GameGemManager implements Listener
//Stats //Stats
Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total); Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total);
Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total); Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total);
if(Manager.GetClients().Get(player).getDisguisedAs() != null)
{
changeName(player, oldName);
}
}
private void changeName(Player player, String newName)
{
try
{
Field name = GameProfile.class.getDeclaredField("name");
Field declaredProfile = EntityHuman.class.getDeclaredField("i");
declaredProfile.setAccessible(true);
GameProfile gameProfile = (GameProfile) declaredProfile.get(((CraftHumanEntity)((CraftPlayer) player)).getHandle());
name.setAccessible(true);
name.set(gameProfile, newName);
name.setAccessible(false);
}
catch (Exception e)
{
e.printStackTrace();
}
} }
public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give) public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give)