07-03-2012, 07:34 PM
Есть скрипт телепорта в аольт б, но проверяется так что ты когда флагнутый (розовый ник) то ты не можеш использовать телепорт, мне нужно это убрать что бы нельзя было использовать только когда персонаж в боевом режиме скажите где это тут.
Teleporter
Код:
public class CommunityTeleport implements ScriptFile, ICommunityBoardHandler
{
private static final Logger _log = LoggerFactory.getLogger(CommunityTeleport.class);
private List<TeleportList> _list = new ArrayList<TeleportList>();
private class Configs
{
// Нужное количество предмета для телепорта.
private static final int BBS_TELEPORT_DEFAULT_ITEM_COUNT = 1000;
// Нужный предмет для телепорта.
private static final int BBS_TELEPORT_DEFAULT_ITEM_ID = 57;
// Количество предметов которые используем при сохранение точки телепорта.
private static final int TELEPORT_BM_COUNT_SAVE = 1000;
// Предмет который используем при сохранение точки телепорта
private static final int TELEPORT_BM_ITEM_SAVE = 57;
// Количество предметов которые используем при возврате на точку сохраненного телепорта.
private static final int TELEPORT_BM_COUNT_GO = 5000;
// Предмет который используем при возврате на точку сохраненного телепорта.
private static final int TELEPORT_BM_ITEM_GO = 57;
// Максимальное количество сохраняемых телепортов
private static final int MAX_BOOK_MARKS = 10;
}
@Override
public void onLoad()
{
if(Config.COMMUNITYBOARD_ENABLED)
{
CommunityBoardManager.getInstance().registerHandler(this);
loadTeleportList();
}
}
@Override
public void onReload()
{
if(Config.COMMUNITYBOARD_ENABLED)
{
CommunityBoardManager.getInstance().removeHandler(this);
_list.clear();
loadTeleportList();
}
}
@Override
public void onShutdown()
{}
@Override
public String[] getBypassCommands()
{
return new String[] {"_cbbsteleport", "_cbbsteleportlist", "_cbbstppoints", "_cbbstpsavepoint", "_cbbsteleportpoint", "_cbbsteleportdelete"};
}
@Override
public void onBypassCommand(Player player, String bypass)
{
if(player.isTerritoryFlagEquipped())
{
if(player.isLangRus())
{
player.sendMessage("Не соблюдены условия для использование данной функции");
return;
}
else
{
player.sendMessage("You are not allowed to use this action in you current stance");
return;
}
}
StringTokenizer st = new StringTokenizer(bypass, "_");
String cmd = st.nextToken();
String html = "";
if("cbbsteleport".equals(cmd))
{
int listId = Integer.parseInt(st.nextToken());
int point = Integer.parseInt(st.nextToken());
int id = Integer.parseInt(st.nextToken());
if(player.getKarma() > 0)
html = HtmCache.getInstance().getNotNull("scripts/services/community/pages/teleports-pk.htm", player);
else
{
teleport(player, listId, point, id);
onBypassCommand(player, "_cbbsteleportlist");
return;
}
}
if("cbbsteleportlist".equals(cmd))
{
html = HtmCache.getInstance().getNotNull("scripts/services/community/pages/teleports.htm", player);
int listId = 0;
int pointId = 0;
if(st.hasMoreTokens())
{
listId = Integer.parseInt(st.nextToken());
pointId = Integer.parseInt(st.nextToken());
}
html = html.replace("<?price?>", String.valueOf(Configs.BBS_TELEPORT_DEFAULT_ITEM_COUNT));
html = html.replace("<?item_name?>", HtmlUtils.htmlItemName(Configs.BBS_TELEPORT_DEFAULT_ITEM_ID));
html = html.replace("<?teleport_list?>", generateTeleportList(player, listId, pointId));
}
if("cbbstppoints".equals(cmd))
{
if(player.getKarma() > 0)
html = HtmCache.getInstance().getNotNull("scripts/services/community/pages/teleports-pk.htm", player);
else
{
html = HtmCache.getInstance().getNotNull("scripts/services/community/pages/teleports-bm.htm", player);
CBteleport tp;
Connection con = null;
PreparedStatement statement = null;
ResultSet rs = null;
StringBuilder html1 = new StringBuilder();
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM bbs_teleport_bm WHERE char_id=?;");
statement.setLong(1, player.getObjectId());
rs = statement.executeQuery();
if( !rs.next())
{
html1.append("<tr>");
html1.append("<td>");
if(player.isLangRus())
html1.append("На данный момент нету сохраненных точек телепорта");
else
html1.append("There is no teleports bookmarks this time");
html1.append("</td>");
html1.append("</tr>");
}
while(rs.next())
{
tp = new CBteleport();
tp.PlayerId = rs.getInt("char_id");
tp.TpName = rs.getString("name");
tp.xC = rs.getInt("x");
tp.yC = rs.getInt("y");
tp.zC = rs.getInt("z");
html1.append("<tr>");
html1.append("<td>");
html1.append("<button value=\"" + tp.TpName + "\" action=\"bypass _cbbsteleportpoint_" + tp.xC + "_" + tp.yC + "_" + tp.zC + "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
html1.append("</td>");
html1.append("<td>");
html1.append("<button value=\"Удалить\" action=\"bypass _cbbsteleportdelete_" + tp.TpName + "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
html1.append("</td>");
html1.append("</tr>");
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DbUtils.closeQuietly(con, statement, rs);
}
StringBuilder content = new StringBuilder();
if(player.isLangRus())
content.append("<tr><td> Введите имя для сохранение: </td></tr>");
else
content.append("<tr><td> Enter your name for this teleport bookmark: </td></tr>");
content.append("<tr><td><edit var=\"newfname\" width=150></td></tr>");
content.append("<tr><td><button value=\"OK\" action=\"bypass _cbbstpsavepoint_ $newfname \" width=150 height=15></td></tr>");
html = html.replace("<?price_save?>", String.valueOf(Configs.TELEPORT_BM_COUNT_SAVE));
html = html.replace("<?item_name_save?>", HtmlUtils.htmlItemName(Configs.TELEPORT_BM_ITEM_SAVE));
html = html.replace("<?bookmarkssave?>", content);
html = html.replace("<?price_go?>", String.valueOf(Configs.TELEPORT_BM_COUNT_GO));
html = html.replace("<?item_name_go?>", HtmlUtils.htmlItemName(Configs.TELEPORT_BM_ITEM_GO));
html = html.replace("<?bookmarkslist?>", html1);
}
}
if("cbbsteleportpoint".equals(cmd))
{
if( !checkCond(player, false))
{
onBypassCommand(player, "_cbbstppoints");
return;
}
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int z = Integer.parseInt(st.nextToken());
Functions.removeItem(player, Configs.TELEPORT_BM_ITEM_GO, Configs.TELEPORT_BM_COUNT_GO);
player.teleToLocation(x, y, z);
onBypassCommand(player, "_cbbstppoints");
return;
}
if("cbbsteleportdelete".equals(cmd))
{
String name = st.nextToken();
Connection con = null;
PreparedStatement statement = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("DELETE FROM bbs_teleport_bm WHERE char_id=? AND name=?");
statement.setInt(1, player.getObjectId());
statement.setString(2, name);
statement.execute();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DbUtils.closeQuietly(con, statement);
}
onBypassCommand(player, "_cbbstppoints");
return;
}
if("cbbstpsavepoint".equals(cmd))
{
if( !st.hasMoreTokens())
{
onBypassCommand(player, "_cbbsteleportlist");
return;
}
String bmName = st.nextToken();
if(bmName.equals(" ") || bmName.isEmpty() || tpNameExist(player, bmName))
{
if(player.isLangRus())
player.sendMessage("Такое название для телепорта уже существует.");
else
player.sendMessage("You cannot use the same teleport name twice.");
onBypassCommand(player, "_cbbsteleportlist");
return;
}
if( !checkCond(player, true))
{
html = HtmCache.getInstance().getNotNull("scripts/services/community/pages/teleports-no-cond.htm", player);
ShowBoard.separateAndSend(html, player);
return;
}
Functions.removeItem(player, Configs.TELEPORT_BM_ITEM_SAVE, Configs.TELEPORT_BM_COUNT_SAVE);
Connection con = null;
PreparedStatement statement = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("INSERT INTO bbs_teleport_bm (char_id,name,x,y,z) VALUES (?,?,?,?,?)");
statement.setInt(1, player.getObjectId());
statement.setString(2, bmName);
statement.setInt(3, player.getX());
statement.setInt(4, player.getY());
statement.setInt(5, player.getZ());
statement.execute();
}
catch(Exception e)
{
_log.warn("CommunityTeleport: cannot save tp book mark for player " + player.getName() + "");
e.printStackTrace();
}
finally
{
DbUtils.closeQuietly(con, statement);
}
html = HtmCache.getInstance().getNotNull("scripts/services/community/pages/teleports-success.htm", player);
}
ShowBoard.separateAndSend(html, player);
}
public class CBteleport
{
public int PlayerId = 0; // charID
public String TpName = ""; // Loc name
public int xC = 0; // Location coords
public int yC = 0; //
public int zC = 0; //
}
private boolean checkCond(Player player, boolean save)
{
if(player.isDead())
return false;
if(player.getTeam() != TeamType.NONE)
return false;
if(player.isFlying() || player.isInFlyingTransform())
return false;
if(player.isInBoat())
return false;
if(player.isInStoreMode() || player.isInTrade() || player.isInOfflineMode())
return false;
if(player.isInDuel())
return false;
if(player.isCursedWeaponEquipped())
return false;
if(save)
{
if(player.isInZone(ZoneType.SIEGE) || player.isInZone(ZoneType.RESIDENCE) || player.isInZone(ZoneType.HEADQUARTER) || player.isInZone(ZoneType.battle_zone) || player.isInZone(ZoneType.ssq_zone) || player.isInZone(ZoneType.no_restart) || player.isInZone(ZoneType.offshore) || player.isInZone(ZoneType.epic) || player.isInOlympiadMode() || player.isOnSiegeField())
return false;
if(player.getReflection() != ReflectionManager.DEFAULT)
return false;
if(Functions.getItemCount(player, Configs.TELEPORT_BM_ITEM_SAVE) < Configs.TELEPORT_BM_COUNT_SAVE)
{
if(player.isLangRus())
player.sendMessage("У вас не хватает нужных вещей для выполнение опрации");
else
player.sendMessage("You have not enough item to procced the operation");
return false;
}
if(getCountTP(player) >= Configs.MAX_BOOK_MARKS)
{
if(player.isLangRus())
player.sendMessage("Вы достигли лимит сохраняемых точек телепорта.");
else
player.sendMessage("You have reached the limit of maximum savings of the teleport bookmarks");
return false;
}
}
if( !save)
if(Functions.getItemCount(player, Configs.TELEPORT_BM_ITEM_GO) < Configs.TELEPORT_BM_COUNT_GO)
{
if(player.isLangRus())
player.sendMessage("У вас не хватает нужных вещей для выполнение опрации");
else
player.sendMessage("You have not enough item to procced the operation");
return false;
}
return true;
}
private int getCountTP(Player player)
{
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
int i = 0;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT name FROM bbs_teleport_bm WHERE char_id=?");
statement.setInt(1, player.getObjectId());
rset = statement.executeQuery();
while(rset.next())
{
i++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DbUtils.closeQuietly(con, statement, rset);
}
return i;
}
private boolean tpNameExist(Player player, String bmName)
{
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
boolean isExist = false;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT name FROM bbs_teleport_bm WHERE char_id=?");
statement.setInt(1, player.getObjectId());
rset = statement.executeQuery();
while(rset.next())
{
String name = rset.getString("name");
if(name.equals(bmName))
isExist = true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DbUtils.closeQuietly(con, statement, rset);
}
return isExist;
}
@Override
public void onWriteCommand(Player player, String bypass, String arg1, String arg2, String arg3, String arg4, String arg5)
{}
private void teleport(Player player, int listId, int point, int id)
{
_log.info("teleport1 " + listId + " " + point + " " + id);
TeleportPoint points2 = null;
for(TeleportList lists : _list)
{
if(lists.getId() == listId)
{
_log.info("teleport2 " + lists.getId());
for(TeleportList2 lists2 : lists.getList())
{
if(lists2.getId() == point)
{
_log.info("teleport3 " + lists2.getId());
for(TeleportPoint point3 : lists2.getPoints())
{
if(point3.getId() == id)
{
_log.info("teleport4 " + point3.getId());
points2 = point3;
break;
}
}
}
}
}
}
if(points2 == null)
return;
if( !BookMarkList.checkFirstConditions(player) || !BookMarkList.checkTeleportConditions(player))
return;
if(player.getReflection().isDefault())
{
int castleId = points2.getCastleId();
Castle castle = castleId > 0 ? ResidenceHolder.getInstance().getResidence(Castle.class, castleId) : null;
// Нельзя телепортироваться в города, где идет осада
if(castle != null && castle.getSiegeEvent().isInProgress())
{
// player.sendPacket(SystemMsg.YOU_CANNOT_TELEPORT_TO_A_VILLAGE_THAT_IS_IN_A_SIEGE);
return;
}
}
int itemId = points2.getItemId();
int itemCount = points2.getItemCount();
if(Functions.getItemCount(player, itemId) < itemCount)
{
player.sendPacket(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
return;
}
Location loc = Location.findPointToStay(points2.getLocation(), 50, 100, player.getGeoIndex());
player.teleToLocation(loc);
Functions.removeItem(player, itemId, itemCount);
}
public void loadTeleportList()
{
Document doc = null;
File file = new File(Config.DATAPACK_ROOT, "data/bbs_teleports.xml");
if( !file.exists())
{
_log.warn("CommunityTeleport: bbs_teleports.xml file is missing.");
return;
}
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
doc = factory.newDocumentBuilder().parse(file);
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
parseTeleportList(doc);
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected void parseTeleportList(Document doc)
{
for(Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if("list".equalsIgnoreCase(n.getNodeName()))
{
for(Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if("teleport_list".equalsIgnoreCase(d.getNodeName()))
{
final int listId = Integer.parseInt(d.getAttributes().getNamedItem("id").getNodeValue());
final String listEnName = d.getAttributes().getNamedItem("name_en").getNodeValue();
final String listRuName = d.getAttributes().getNamedItem("name_ru").getNodeValue();
TeleportList teleportList = new TeleportList(listId, listEnName, listRuName);
for(Node t = d.getFirstChild(); t != null; t = t.getNextSibling())
{
if("teleport_list2".equalsIgnoreCase(t.getNodeName()))
{
final int listId2 = Integer.parseInt(t.getAttributes().getNamedItem("id2").getNodeValue());
final String listEnName2 = t.getAttributes().getNamedItem("name_en2").getNodeValue();
final String listRuName2 = t.getAttributes().getNamedItem("name_ru2").getNodeValue();
TeleportList2 teleportList2 = new TeleportList2(listId2, listEnName2, listRuName2);
for(Node t2 = t.getFirstChild(); t2 != null; t2 = t2.getNextSibling())
{
if("point".equalsIgnoreCase(t2.getNodeName()))
{
final int id = Integer.parseInt(t2.getAttributes().getNamedItem("id").getNodeValue());
final int x = Integer.parseInt(t2.getAttributes().getNamedItem("x").getNodeValue());
final int y = Integer.parseInt(t2.getAttributes().getNamedItem("y").getNodeValue());
final int z = Integer.parseInt(t2.getAttributes().getNamedItem("z").getNodeValue());
final int castleId = t2.getAttributes().getNamedItem("castle_id") == null ? 0 : Integer.parseInt(t2.getAttributes().getNamedItem("castle_id").getNodeValue());
final String enName = t2.getAttributes().getNamedItem("name_en").getNodeValue();
final String ruName = t2.getAttributes().getNamedItem("name_ru").getNodeValue();
final int itemId = t2.getAttributes().getNamedItem("item_id") == null ? 57 : Integer.parseInt(t2.getAttributes().getNamedItem("item_id").getNodeValue());
final int itemCount = t2.getAttributes().getNamedItem("item_count") == null ? 0 : Integer.parseInt(t2.getAttributes().getNamedItem("item_count").getNodeValue());
TeleportPoint teleportPoint = new TeleportPoint(id, new Location(x, y, z), castleId, enName, ruName, itemId, itemCount);
teleportList2.addPoint(teleportPoint);
}
}
teleportList.addList(teleportList2);
}
}
_list.add(teleportList);
}
}
}
}
}
private String generateTeleportList(Player player, int listId, int pointId)
{
StringBuilder result = new StringBuilder();
if(listId == 0)
{
for(TeleportList lists : _list)
{
result.append("<tr><td><button value=\"");
result.append(player.isLangRus() ? lists.getRuName() : lists.getEnName());
result.append("\" action=\"bypass _cbbsteleportlist_" + lists.getId() + "_" + pointId + "\" width=200 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>\n");
}
}
else
{
if(pointId == 0)
{
for(TeleportList lists : _list)
{
if(lists.getId() == listId)
{
for(TeleportList2 lists2 : lists.getList())
{
result.append("<tr><td><button value=\"");
result.append(player.isLangRus() ? lists2.getRuName() : lists2.getEnName());
result.append("\" action=\"bypass _cbbsteleportlist_" + lists.getId() + "_" + lists2.getId() + "\" width=200 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>\n");
}
}
}
}
else
{
for(TeleportList lists : _list)
{
if(lists.getId() == listId)
{
for(TeleportList2 lists2 : lists.getList())
{
if(lists2.getId() == pointId)
{
for(TeleportPoint point : lists2.getPoints())
{
result.append("<tr><td><button value=\"");
result.append(player.isLangRus() ? point.getRuName() : point.getEnName());
result.append("\" action=\"bypass _cbbsteleport_" + listId + "_" + pointId + "_" + point.getId() + "\" width=200 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>\n");
}
}
}
}
}
result.append("<tr><td><br></td></tr>\n");
result.append("<tr><td><button value=\"");
result.append(player.isLangRus() ? "Назад" : "Back");
result.append("\" action=\"bypass _cbbsteleportlist\" width=200 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>\n");
}
}
return result.toString();
}
private static class TeleportList
{
private final List<TeleportList2> _il;
private final int _id;
private final String _enName;
private final String _ruName;
public TeleportList(int id, String enName, String ruName)
{
_id = id;
_enName = enName;
_ruName = ruName;
_il = new ArrayList<TeleportList2>();
}
public void addList(TeleportList2 list)
{
_il.add(list);
}
public List<TeleportList2> getList()
{
return _il;
}
public int getId()
{
return _id;
}
public String getEnName()
{
return _enName;
}
public String getRuName()
{
return _ruName;
}
}
private static class TeleportList2
{
private final int _id;
private final String _enName;
private final String _ruName;
private final List<TeleportPoint> _points;
public TeleportList2(int id, String enName, String ruName)
{
_id = id;
_enName = enName;
_ruName = ruName;
_points = new ArrayList<TeleportPoint>();
}
public int getId()
{
return _id;
}
public String getEnName()
{
return _enName;
}
public String getRuName()
{
return _ruName;
}
public void addPoint(TeleportPoint point)
{
_points.add(point);
}
public List<TeleportPoint> getPoints()
{
return _points;
}
}
private static class TeleportPoint
{
private final int _id;
private final Location _loc;
private final int _castleId;
private final String _enName;
private final String _ruName;
private final int _itemId;
private final int _itemCount;
public TeleportPoint(int id, Location loc, int castleId, String enName, String ruName, int itemId, int itemCount)
{
_id = id;
_loc = loc;
_castleId = castleId;
_enName = enName;
_ruName = ruName;
_itemId = itemId;
_itemCount = itemCount;
}
public int getId()
{
return _id;
}
public Location getLocation()
{
return _loc;
}
public int getCastleId()
{
return _castleId;
}
public String getEnName()
{
return _enName;
}
public String getRuName()
{
return _ruName;
}
public int getItemId()
{
return _itemId;
}
public int getItemCount()
{
return _itemCount;
}
}
}