@@ -1399,188 +1399,176 @@ private static void TeleportHandler(Player player, CommandReader cmd) {
13991399 player . Message ( "Hey no cheating!" ) ;
14001400 return ;
14011401 }
1402+
14021403 if ( name == "zone" ) {
1403- string zoneName = cmd . Next ( ) ;
1404- if ( zoneName == null ) {
1405- player . Message ( "No zone name specified. See &H/Help tpzone" ) ;
1406- return ;
1407- } else {
1408- Zone zone = player . World . Map . Zones . Find ( zoneName ) ;
1409- if ( zone == null ) {
1410- player . MessageNoZone ( zoneName ) ;
1411- return ;
1412- }
1404+ TeleportToZone ( player , cmd ) ;
1405+ } else if ( name == "random" || name == "rand" ) {
1406+ TeleportToRandom ( player , cmd ) ;
1407+ } else if ( cmd . Next ( ) != null ) {
1408+ TeleportToCoords ( player , cmd ) ;
1409+ } else {
1410+ TeleportToPlayer ( player , name ) ;
1411+ }
1412+ }
1413+
14131414
1414- Vector3I P = player . World . map . HighestFreeSpace ( zone . Bounds . XCentre ,
1415- zone . Bounds . YCentre , zone . Bounds . ZCentre ) ;
1416- Position zPos = new Position ( P . X * 32 + 16 , P . Y * 32 + 16 , P . Z * 32 + Player . CharacterHeight ) ;
1417- if ( player . World != null ) {
1418- player . LastWorld = player . World ;
1419- player . LastPosition = player . Position ;
1420- }
1421- player . TeleportTo ( ( zPos ) ) ;
1422- player . Message ( "Teleporting you to zone " + zone . ClassyName ) ;
1423- return ;
1424- }
1415+ static void TeleportToZone ( Player player , CommandReader cmd ) {
1416+ string zoneName = cmd . Next ( ) ;
1417+ if ( zoneName == null ) {
1418+ player . Message ( "No zone name specified. See &H/Help tpzone" ) ;
1419+ return ;
1420+ }
1421+
1422+ Zone zone = player . World . Map . Zones . Find ( zoneName ) ;
1423+ if ( zone == null ) {
1424+ player . MessageNoZone ( zoneName ) ;
1425+ return ;
1426+ }
1427+
1428+ Vector3I P = player . World . map . HighestFreeSpace ( zone . Bounds . XCentre ,
1429+ zone . Bounds . YCentre , zone . Bounds . ZCentre ) ;
1430+ Position zPos = new Position ( P . X * 32 + 16 , P . Y * 32 + 16 , P . Z * 32 + Player . CharacterHeight ) ;
1431+ if ( player . World != null ) {
1432+ player . LastWorld = player . World ;
1433+ player . LastPosition = player . Position ;
14251434 }
1426- if ( name == "random" || name == "rand" ) {
1427- Random rand = new Random ( ) ;
1428- int x = rand . Next ( 0 , player . WorldMap . Width ) ;
1429- int y = rand . Next ( 0 , player . WorldMap . Length ) ;
1430- int z = ( player . Position . Z - Player . CharacterHeight ) / 32 ;
1431- Vector3I P = player . WorldMap . HighestFreeSpace ( x , y , z ) ;
1435+
1436+ player . TeleportTo ( ( zPos ) ) ;
1437+ player . Message ( "Teleporting you to zone " + zone . ClassyName ) ;
1438+ }
1439+
1440+
1441+ static void TeleportToRandom ( Player player , CommandReader cmd ) {
1442+ Random rand = new Random ( ) ;
1443+ int x = rand . Next ( 0 , player . WorldMap . Width ) ;
1444+ int y = rand . Next ( 0 , player . WorldMap . Length ) ;
1445+ int z = ( player . Position . Z - Player . CharacterHeight ) / 32 ;
1446+ Vector3I P = player . WorldMap . HighestFreeSpace ( x , y , z ) ;
14321447
1448+ if ( player . World != null ) {
1449+ player . LastWorld = player . World ;
1450+ player . LastPosition = player . Position ;
1451+ }
1452+ player . TeleportTo ( new Position {
1453+ X = ( P . X * 32 + 16 ) ,
1454+ Y = ( P . Y * 32 + 16 ) ,
1455+ Z = ( P . Z * 32 + Player . CharacterHeight ) ,
1456+ R = player . Position . R ,
1457+ L = player . Position . L
1458+ } ) ;
1459+ player . Message ( "Teleported to: ({0}, {1}, {2})" , x , y , z ) ;
1460+ }
1461+
1462+
1463+ static void TeleportToCoords ( Player player , CommandReader cmd ) {
1464+ cmd . Rewind ( ) ;
1465+ int x , y , z , rot , lot ;
1466+ rot = player . Position . R ;
1467+ lot = player . Position . L ;
1468+
1469+ if ( cmd . NextCoord ( player . Position . ToBlockCoords ( ) . X , out x )
1470+ && cmd . NextCoord ( player . Position . ToBlockCoords ( ) . Y , out y )
1471+ && cmd . NextCoord ( player . Position . ToBlockCoords ( ) . Z , out z ) ) {
1472+
1473+ if ( cmd . CountRemaining >= 2 ) {
1474+ if ( cmd . NextInt ( out rot ) && cmd . NextInt ( out lot ) ) {
1475+ if ( rot > 255 || rot < 0 ) {
1476+ player . Message ( "R must be inbetween 0 and 255. Set to player R" ) ;
1477+ }
1478+ if ( lot > 255 || lot < 0 ) {
1479+ player . Message ( "L must be inbetween 0 and 255. Set to player L" ) ;
1480+ }
1481+ }
1482+ }
1483+
14331484 if ( player . World != null ) {
14341485 player . LastWorld = player . World ;
14351486 player . LastPosition = player . Position ;
14361487 }
14371488 player . TeleportTo ( new Position {
1438- X = ( P . X * 32 + 16 ) ,
1439- Y = ( P . Y * 32 + 16 ) ,
1440- Z = ( P . Z * 32 + Player . CharacterHeight ) ,
1441- R = player . Position . R ,
1442- L = player . Position . L
1443- } ) ;
1444- player . Message ( "Teleported to: ({0}, {1}, {2})" , x , y , z ) ;
1489+ X = ( x * 32 + 16 ) ,
1490+ Y = ( y * 32 + 16 ) ,
1491+ Z = ( z * 32 + Player . CharacterHeight ) ,
1492+ R = ( byte ) rot ,
1493+ L = ( byte ) lot
1494+ } ) ;
1495+ } else {
1496+ CdTeleport . PrintUsage ( player ) ;
1497+ }
1498+ }
1499+
1500+
1501+ static void TeleportToPlayer ( Player player , string name ) {
1502+ Player target = Server . FindPlayerOrPrintMatches ( player , name , SearchOptions . ReturnSelfIfOnlyMatch ) ;
1503+ if ( target == null ) return ;
1504+ if ( target == player ) {
1505+ player . Message ( "You cannot &H/Teleport&S to yourself." ) ;
1506+ return ;
1507+ }
1508+
1509+ World targetWorld = target . World ;
1510+ if ( targetWorld == null ) PlayerOpException . ThrowNoWorld ( target ) ;
1511+ if ( target . Info . TPDeny && target . Info . Rank >= player . Info . Rank ) {
1512+ player . Message ( "&CThis player does not want people teleporting to them" ) ;
1513+ player . Message ( "Cannot teleport to {0}" , target . ClassyName , targetWorld . ClassyName ,
1514+ targetWorld . AccessSecurity . MinRank . ClassyName ) ;
14451515 return ;
14461516 }
14471517
1448- if ( cmd . Next ( ) != null ) {
1449- cmd . Rewind ( ) ;
1450- int x , y , z , rot , lot ;
1451- rot = player . Position . R ;
1452- lot = player . Position . L ;
1453- if ( cmd . NextCoord ( player . Position . ToBlockCoords ( ) . X , out x )
1454- && cmd . NextCoord ( player . Position . ToBlockCoords ( ) . Y , out y )
1455- && cmd . NextCoord ( player . Position . ToBlockCoords ( ) . Z , out z ) ) {
1456- if ( cmd . HasNext ) {
1457- if ( cmd . HasNext ) {
1458- if ( cmd . NextInt ( out rot ) && cmd . NextInt ( out lot ) ) {
1459- if ( rot > 255 || rot < 0 ) {
1460- player . Message ( "R must be inbetween 0 and 255. Set to player R" ) ;
1461- }
1462- if ( lot > 255 || lot < 0 ) {
1463- player . Message ( "L must be inbetween 0 and 255. Set to player L" ) ;
1464- }
1465- }
1466- }
1467- }
1468-
1469- if ( player . World != null ) {
1470- player . LastWorld = player . World ;
1471- player . LastPosition = player . Position ;
1472- }
1473- player . TeleportTo ( new Position {
1474- X = ( x * 32 + 16 ) ,
1475- Y = ( y * 32 + 16 ) ,
1476- Z = ( z * 32 + 52 ) ,
1477- R = ( byte ) rot ,
1478- L = ( byte ) lot
1479- } ) ;
1480- } else {
1481- CdTeleport . PrintUsage ( player ) ;
1482- }
1483- } else {
1484- if ( name == "-" ) {
1485- if ( player . LastUsedPlayerName != null ) {
1486- name = player . LastUsedPlayerName ;
1487- } else {
1488- player . Message ( "Cannot repeat player name: you haven't used any names yet." ) ;
1489- return ;
1490- }
1491- }
1492- Player [ ] matches = Server . FindPlayers ( player , name , SearchOptions . ReturnSelfIfOnlyMatch ) ;
1493- if ( matches . Length == 0 ) {
1494- player . Message ( "No player found by the name \" {0}\" " , name ) ;
1495- return ;
1518+ if ( targetWorld == player . World ) {
1519+ if ( player . World != null ) {
1520+ player . LastWorld = player . World ;
1521+ player . LastPosition = player . Position ;
14961522 }
1497- if ( matches . Length == 1 ) {
1498- Player target = matches [ 0 ] ;
1499- if ( target == player ) {
1500- player . Message ( "You cannot &H/Teleport&S to yourself." ) ;
1501- return ;
1502- }
1523+
1524+ player . TeleportTo ( target . Position ) ;
1525+ return ;
1526+ }
15031527
1504- World targetWorld = target . World ;
1505- if ( targetWorld == null ) PlayerOpException . ThrowNoWorld ( target ) ;
1506- if ( target . Info . TPDeny && target . Info . Rank >= player . Info . Rank ) {
1507- player . Message ( "&CThis player does not want people teleporting to them" ) ;
1508- player . Message ( "Cannot teleport to {0}" , target . ClassyName , targetWorld . ClassyName ,
1509- targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1510- return ;
1528+ if ( targetWorld . Name . StartsWith ( "PW_" ) && ! targetWorld . AccessSecurity . ExceptionList . Included . Contains ( player . Info ) ) {
1529+ player . Message ( "You cannot join due to that player being in a personal world that you cannot access." ) ;
1530+ return ;
1531+ }
1532+
1533+ switch ( targetWorld . AccessSecurity . CheckDetailed ( player . Info ) ) {
1534+ case SecurityCheckResult . Allowed :
1535+ case SecurityCheckResult . WhiteListed :
1536+ if ( player . Info . Rank . Name == "Banned" ) {
1537+ player . Message ( "&CYou can not change worlds while banned." ) ;
1538+ player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1539+ targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1540+ break ;
15111541 }
1512-
1513- if ( targetWorld == player . World ) {
1514- if ( player . World != null ) {
1515- player . LastWorld = player . World ;
1516- player . LastPosition = player . Position ;
1517- }
1518- player . TeleportTo ( target . Position ) ;
1519-
1520- } else {
1521- if ( targetWorld . Name . StartsWith ( "PW_" ) &&
1522- ! targetWorld . AccessSecurity . ExceptionList . Included . Contains ( player . Info ) ) {
1523- player . Message (
1524- "You cannot join due to that player being in a personal world that you cannot access." ) ;
1525- return ;
1526- }
1527- switch ( targetWorld . AccessSecurity . CheckDetailed ( player . Info ) ) {
1528- case SecurityCheckResult . Allowed :
1529- case SecurityCheckResult . WhiteListed :
1530- if ( player . Info . Rank . Name == "Banned" ) {
1531- player . Message ( "&CYou can not change worlds while banned." ) ;
1532- player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1533- targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1534- break ;
1535- }
1536- if ( targetWorld . IsFull ) {
1537- player . Message ( "Cannot teleport to {0}&S because world {1}&S is full." ,
1538- target . ClassyName , targetWorld . ClassyName ) ;
1539- player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1540- targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1541- break ;
1542- }
1543- player . StopSpectating ( ) ;
1544- player . JoinWorld ( targetWorld , WorldChangeReason . Tp , target . Position ) ;
1545- break ;
1546- case SecurityCheckResult . BlackListed :
1547- player . Message ( "Cannot teleport to {0}&S because you are blacklisted on world {1}" ,
1548- target . ClassyName , targetWorld . ClassyName ) ;
1549- break ;
1550- case SecurityCheckResult . RankTooLow :
1551- if ( player . Info . Rank . Name == "Banned" ) {
1552- player . Message ( "&CYou can not change worlds while banned." ) ;
1553- player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1554- targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1555- break ;
1556- }
1557-
1558- if ( targetWorld . IsFull ) {
1559- if ( targetWorld . IsFull ) {
1560- player . Message ( "Cannot teleport to {0}&S because world {1}&S is full." ,
1561- target . ClassyName , targetWorld . ClassyName ) ;
1562- player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1563- targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1564- break ;
1565- }
1566- player . StopSpectating ( ) ;
1567- player . JoinWorld ( targetWorld , WorldChangeReason . Tp , target . Position ) ;
1568- break ;
1569- }
1570- player . Message ( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join." ,
1571- target . ClassyName , targetWorld . ClassyName ,
1572- targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1573- break ;
1574- }
1542+
1543+ if ( targetWorld . IsFull ) {
1544+ player . Message ( "Cannot teleport to {0}&S because world {1}&S is full." ,
1545+ target . ClassyName , targetWorld . ClassyName ) ;
1546+ player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1547+ targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1548+ break ;
15751549 }
1576-
1577- } else if ( matches . Length > 1 ) {
1578- player . MessageManyMatches ( "player" , matches ) ;
1579-
1580- }
1550+
1551+ player . StopSpectating ( ) ;
1552+ player . JoinWorld ( targetWorld , WorldChangeReason . Tp , target . Position ) ;
1553+ break ;
1554+ case SecurityCheckResult . BlackListed :
1555+ player . Message ( "Cannot teleport to {0}&S because you are blacklisted on world {1}" ,
1556+ target . ClassyName , targetWorld . ClassyName ) ;
1557+ break ;
1558+ case SecurityCheckResult . RankTooLow :
1559+ if ( player . Info . Rank . Name == "Banned" ) {
1560+ player . Message ( "&CYou can not change worlds while banned." ) ;
1561+ player . Message ( "Cannot teleport to {0}&S." , target . ClassyName ,
1562+ targetWorld . ClassyName , targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1563+ break ;
1564+ }
1565+
1566+ player . Message ( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join." ,
1567+ target . ClassyName , targetWorld . ClassyName ,
1568+ targetWorld . AccessSecurity . MinRank . ClassyName ) ;
1569+ break ;
15811570 }
15821571 }
1583-
15841572 #endregion
15851573 #region TPP
15861574
0 commit comments