Here are all the new ways to teleport if you are tired of people teleporting to you without permission, and to keep people off your map if you wish. Just add this whole thing to one project and compile, it will be loaded all in the same .dll. With this I also used the Dictionary class as an example to use in minecraft. I also used Dictionary because i tried to extend the player class but it was considered sealed. Oh well here ya guys go. enjoy!
- Code: Select all
//created by tommyz_
using System;
using System.IO;
using System.Threading;
using System.Collections.Generic;
namespace MCDzienny
{
//I tried to extend the player class to make this a lot easier but it seems that the Player class is sealed?
//public class CmdTpa : Player
//{
// //a new variable I added
// public string lastTpaName = "";
//}
public class cmdTpahere : Command
{
//hehe
private string creator = "tommyz_";
public override string name { get { return "tpahere"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
Player pl = Player.Find(message);
//if the player is the same player as the one called
if (pl == p)
{ Player.SendMessage(p, "You can't teleport to yourself."); return; }
//if the player is still on the server
if (pl != null)
{
Player.SendMessage(p, "Teleport request sent to " + pl.name);
Player.SendMessage(pl, "&4" + p.name + " would like you to teleport to them. Would you like to accept /tpaccept to accept, or /tpadeny to deny.");
}
else { Player.SendMessage(p, message + " was not found on the server."); return; }
//destination user goes in front, host user goes second.
PlayersExtension.Players.Add(pl,p);
//add the player to a list to show that it is a tpahere person
PlayersExtension.TpaHerePlayer.Add(pl);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/tpa [player] - asks a user if you can teleport to them. ");
Player.SendMessage(p, "/tpahere [player] - asks a user if you want them to teleport to you.");
Player.SendMessage(p, "/tpaccept [player] - accepts a user to teleport to them. ");
Player.SendMessage(p, "/tpadeny [player] - denys a user to teleport to them.");
}
}
public class cmdTpa : Command
{
//hehe
private string creator = "tommyz_";
public override string name { get { return "tpa"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
Player pl = Player.Find(message);
//if the player is the same player as the one called
if (pl == p)
{ Player.SendMessage(p, "You can't teleport to yourself."); return; }
//if the player is still on the server
if (pl != null)
{Player.SendMessage(p, "Teleport request sent to " + pl.name);
Player.SendMessage(pl, "&c" + p.name + " would like to teleport to you. Would you like to accept /tpaccept to accept, or /tpadeny to deny."); }
else { Player.SendMessage(p, message + " was not found on the server."); return; }
//destination user goes in front, host user goes second. user in front is also the identifier.
PlayersExtension.Players.Add(pl, p);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/tpa [player] - asks a user if you can teleport to them. ");
Player.SendMessage(p, "/tpahere [player] - asks a user if you want them to teleport to you.");
Player.SendMessage(p, "/tpaccept [player] - accepts a user to teleport to them. ");
Player.SendMessage(p, "/tpadeny [player] - denys a user to teleport to them.");
}
}
public class cmdTPAccept : Command
{
//hehe
private string creator = "tommyz_";
public override string name { get { return "tpaccept"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
//A dictionary sample for minecraft
//compare one name to see which keypair contains name
//key is the first value as the identifier, value is the second value
int found = 0;
foreach (KeyValuePair<Player, Player> myPair in PlayersExtension.Players)
{
//if desination person is the acceptor, continue
//regular tpa
if (myPair.Key == p && !PlayersExtension.TpaHerePlayer.Contains(p))
{
found++;
//setup the value of the host user
Player who = myPair.Value;
if (who.level != p.level)
{
if (p.level.name.Contains("cMuseum"))
{
Player.SendMessage(who, "Player \"" + message + "\" is in a museum!");
PlayersExtension.Players.Remove(p);
return;
}
else
{
Command.all.Find("goto").Use(who, p.level.name);
//remove the acceptor destination p
PlayersExtension.Players.Remove(p); return;
}
}
if (who.level == p.level)
{
if (p.Loading)
{
Player.SendMessage(who, "Waiting for " + p.color + p.name + Server.DefaultColor + " to spawn...");
while (p.Loading) ;
}
while (who.Loading) ; //Wait for player to spawn in new map
// Player.SendMessage(who, "Teleporting..");
Player.SendMessage(who, "&a" + p.name + " has accepted your teleport request.");
Thread.Sleep(1000);
while (who.pos[0] != p.pos[0] || who.pos[1] != p.pos[1] || who.pos[2] != p.pos[2])
unchecked { who.SendPos((byte)-1, p.pos[0], p.pos[1], p.pos[2], p.rot[0], 0); }
Player.SendMessage(who, "Teleport successful.");
//remove the request from the dictionary
PlayersExtension.Players.Remove(p); return;
}
}
//tpahere code
else if (myPair.Key == p && PlayersExtension.TpaHerePlayer.Contains(p))
{
found++;
//setup the value of the host user
Player who = myPair.Value;
if (p.level != who.level)
{
if (who.level.name.Contains("cMuseum"))
{
Player.SendMessage(p, "Player \"" + message + "\" is in a museum!");
PlayersExtension.Players.Remove(p);
PlayersExtension.TpaHerePlayer.Remove(p);
return;
}
else
{
Command.all.Find("goto").Use(p, who.level.name);
//remove the acceptor destination p
PlayersExtension.Players.Remove(p);
PlayersExtension.TpaHerePlayer.Remove(p); return;
}
}
if (p.level == who.level)
{
if (who.Loading)
{
Player.SendMessage(p, "Waiting for " + who.color + who.name + Server.DefaultColor + " to spawn...");
while (who.Loading) ;
}
while (p.Loading) ; //Wait for player to spawn in new map
// Player.SendMessage(p, "Teleporting..");
Player.SendMessage(p, "&a" + who.name + " has accepted your teleport request.");
Thread.Sleep(1000);
while (p.pos[0] != who.pos[0] || p.pos[1] != who.pos[1] || p.pos[2] != who.pos[2])
unchecked { p.SendPos((byte)-1, who.pos[0], who.pos[1], who.pos[2], who.rot[0], 0); }
Player.SendMessage(p, "Teleport successful.");
//remove the request from the dictionary
PlayersExtension.Players.Remove(p);
PlayersExtension.TpaHerePlayer.Remove(p); return;
}
}
}
if (found == 0)
{ Player.SendMessage(p, "No requests were available."); return; }
}
public override void Help(Player p)
{
Player.SendMessage(p, "/tpa [player] - asks a user if you can teleport to them. ");
Player.SendMessage(p, "/tpahere [player] - asks a user if you want them to teleport to you.");
Player.SendMessage(p, "/tpaccept [player] - accepts a user to teleport to them. ");
Player.SendMessage(p, "/tpadeny [player] - denys a user to teleport to them.");
}
}
public class cmdTPADeny : Command
{
//hehe
private string creator = "tommyz_";
public override string name { get { return "tpadeny"; } }
public override string shortcut { get { return "tpad"; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
int found = 0;
//A dictionary sample for minecraft
//compare one name to see which keypair contains name
//key is the first value as the identifier, value is the second value
foreach (KeyValuePair<Player, Player> myPair in PlayersExtension.Players)
{
//if dictionary contains the destination user
if (myPair.Key == p && !PlayersExtension.TpaHerePlayer.Contains(p))
{
found++;
//setup the value of the host user
Player who = Player.Find( myPair.Value.name);
//remove the request from the dictionary, where the denyer is the key value of the dictionary
PlayersExtension.Players.Remove(p);
Player.SendMessage(p, "You have declined " + who.name + "'s teleport request");
Player.SendMessage(who, p.name + " has declined your teleport request.");
return;
}
else if (myPair.Key == p && PlayersExtension.TpaHerePlayer.Contains(p))
{
found++;
//setup the value of the host user
Player who = myPair.Value;
//remove the request from the dictionary, where the denyer is the key value of the dictionary
PlayersExtension.Players.Remove(p);
PlayersExtension.TpaHerePlayer.Remove(p);
Player.SendMessage(p, "You have declined " + who.name + "'s teleport request.");
Player.SendMessage(who, p.name + " has declined your teleport request.");
return;
}
}
//another way but doesnt cycle through multiple teleport requests
// if (PlayersExtension.Players.ContainsKey(p))
//{ }
if (found == 0)
{ Player.SendMessage(p, "No requests were available."); return; }
}
public override void Help(Player p)
{
Player.SendMessage(p, "/tpa [player] - asks a user if you can teleport to them. ");
Player.SendMessage(p, "/tpahere [player] - asks a user if you want them to teleport to you.");
Player.SendMessage(p, "/tpaccept [player] - accepts a user to teleport to them. ");
Player.SendMessage(p, "/tpadeny [player] - denys a user to teleport to them.");
}
}
//I added this because there was no other way to extend the player class, since it was considered sealed
public static class PlayersExtension
{
public static Dictionary<Player, Player> Players = new Dictionary<Player, Player>();
public static List<Player> TpaHerePlayer = new List<Player>();
}
}