import com.mysql.jdbc.Connection; //导入方法依赖的package包/类
@Override
public int execute(MapleClient c, String[] splitted) {
if (splitted.length < 1) {
c.getPlayer().dropMessage(6, “!pnpc “);
return 0;
}
int npcId = Integer.parseInt(splitted[1]);
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
if (npc != null && !npc.getName().equals(“MISSINGNO”)) {
final int xpos = c.getPlayer().getPosition().x;
final int ypos = c.getPlayer().getPosition().y;
final int fh = c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId();
npc.setPosition(c.getPlayer().getPosition());
npc.setCy(ypos);
npc.setRx0(xpos);
npc.setRx1(xpos);
npc.setFh(fh);
npc.setCustom(true);
try {
Connection con = (Connection) DatabaseConnection.getConnection();
try (PreparedStatement ps = (PreparedStatement) con.prepareStatement(“INSERT INTO wz_customlife (dataid, f, hide, fh, cy, rx0, rx1, type, x, y, mid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)”)) {
ps.setInt(1, npcId);
ps.setInt(2, 0); // 1 = right , 0 = left
ps.setInt(3, 0); // 1 = hide, 0 = show
ps.setInt(4, fh);
ps.setInt(5, ypos);
ps.setInt(6, xpos);
ps.setInt(7, xpos);
ps.setString(8, “n”);
ps.setInt(9, xpos);
ps.setInt(10, ypos);
ps.setInt(11, c.getPlayer().getMapId());
ps.executeUpdate();
}
} catch (SQLException e) {
c.getPlayer().dropMessage(6, “Failed to save NPC to the net.db.”);
}
c.getPlayer().getMap().addMapObject(npc);
c.getPlayer().getMap().broadcastMessage(NPCPacket.spawnNPC(npc, true));
c.getPlayer().dropMessage(6, “Please do not reload this map or else the NPC will disappear untill the next restart.”);
} else {
c.getPlayer().dropMessage(6, “You have entered an invalid npc id.”);
return 0;
}
return 1;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/39164.html