Prechádzať zdrojové kódy

Fixing (some) MySQL 8 reserved words

Zoey76 6 rokov pred
rodič
commit
2b4a5ffcf0

+ 43 - 0
src/main/java/com/l2jserver/gameserver/dao/ClanDAO.java

@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2004-2019 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.dao;
+
+import java.util.Map;
+
+/**
+ * Clan DAO interface.
+ * @author Zoey76
+ */
+public interface ClanDAO {
+	
+	/**
+	 * Gets the clan privileges.
+	 * @param clanId the clan Id
+	 * @return the ranks and privileges
+	 */
+	Map<Integer, Integer> getPrivileges(int clanId);
+	
+	/**
+	 * Stores the clan privileges.
+	 * @param clanId the clan Id
+	 * @param rank the rank
+	 * @param privileges the privileges
+	 */
+	void storePrivileges(int clanId, int rank, int privileges);
+}

+ 4 - 2
src/main/java/com/l2jserver/gameserver/dao/factory/IDAOFactory.java

@@ -18,6 +18,7 @@
  */
 package com.l2jserver.gameserver.dao.factory;
 
+import com.l2jserver.gameserver.dao.ClanDAO;
 import com.l2jserver.gameserver.dao.FriendDAO;
 import com.l2jserver.gameserver.dao.HennaDAO;
 import com.l2jserver.gameserver.dao.ItemDAO;
@@ -40,8 +41,7 @@ import com.l2jserver.gameserver.dao.TeleportBookmarkDAO;
  * DAO Factory interface.
  * @author Zoey76
  */
-public interface IDAOFactory
-{
+public interface IDAOFactory {
 	FriendDAO getFriendDAO();
 	
 	HennaDAO getHennaDAO();
@@ -75,4 +75,6 @@ public interface IDAOFactory
 	SubclassDAO getSubclassDAO();
 	
 	TeleportBookmarkDAO getTeleportBookmarkDAO();
+	
+	ClanDAO getClanDAO();
 }

+ 26 - 36
src/main/java/com/l2jserver/gameserver/dao/factory/impl/MySQLDAOFactory.java

@@ -18,6 +18,7 @@
  */
 package com.l2jserver.gameserver.dao.factory.impl;
 
+import com.l2jserver.gameserver.dao.ClanDAO;
 import com.l2jserver.gameserver.dao.FriendDAO;
 import com.l2jserver.gameserver.dao.HennaDAO;
 import com.l2jserver.gameserver.dao.ItemDAO;
@@ -36,6 +37,7 @@ import com.l2jserver.gameserver.dao.SkillDAO;
 import com.l2jserver.gameserver.dao.SubclassDAO;
 import com.l2jserver.gameserver.dao.TeleportBookmarkDAO;
 import com.l2jserver.gameserver.dao.factory.IDAOFactory;
+import com.l2jserver.gameserver.dao.impl.mysql.ClanDAOMySQLImpl;
 import com.l2jserver.gameserver.dao.impl.mysql.FriendDAOMySQLImpl;
 import com.l2jserver.gameserver.dao.impl.mysql.HennaDAOMySQLImpl;
 import com.l2jserver.gameserver.dao.impl.mysql.ItemDAOMySQLImpl;
@@ -58,8 +60,7 @@ import com.l2jserver.gameserver.dao.impl.mysql.TeleportBookmarkDAOMySQLImpl;
  * MySQL DAO Factory implementation.
  * @author Zoey76
  */
-enum MySQLDAOFactory implements IDAOFactory
-{
+enum MySQLDAOFactory implements IDAOFactory {
 	INSTANCE;
 	
 	private final FriendDAO friendDAO = new FriendDAOMySQLImpl();
@@ -79,106 +80,95 @@ enum MySQLDAOFactory implements IDAOFactory
 	private final SkillDAO skillDAO = new SkillDAOMySQLImpl();
 	private final SubclassDAO subclassDAO = new SubclassDAOMySQLImpl();
 	private final TeleportBookmarkDAO teleportBookmarkDAO = new TeleportBookmarkDAOMySQLImpl();
+	private final ClanDAO clanDAO = new ClanDAOMySQLImpl();
 	
 	@Override
-	public FriendDAO getFriendDAO()
-	{
+	public FriendDAO getFriendDAO() {
 		return friendDAO;
 	}
 	
 	@Override
-	public HennaDAO getHennaDAO()
-	{
+	public HennaDAO getHennaDAO() {
 		return hennaDAO;
 	}
 	
 	@Override
-	public ItemDAO getItemDAO()
-	{
+	public ItemDAO getItemDAO() {
 		return itemDAO;
 	}
 	
 	@Override
-	public ItemReuseDAO getItemReuseDAO()
-	{
+	public ItemReuseDAO getItemReuseDAO() {
 		return itemReuseDAO;
 	}
 	
 	@Override
-	public PetDAO getPetDAO()
-	{
+	public PetDAO getPetDAO() {
 		return petDAO;
 	}
 	
 	@Override
-	public PetSkillSaveDAO getPetSkillSaveDAO()
-	{
+	public PetSkillSaveDAO getPetSkillSaveDAO() {
 		return petSkillSaveDAO;
 	}
 	
 	@Override
-	public PlayerDAO getPlayerDAO()
-	{
+	public PlayerDAO getPlayerDAO() {
 		return playerDAO;
 	}
 	
 	@Override
-	public PlayerSkillSaveDAO getPlayerSkillSaveDAO()
-	{
+	public PlayerSkillSaveDAO getPlayerSkillSaveDAO() {
 		return playerSkillSaveDAO;
 	}
 	
 	@Override
-	public PremiumItemDAO getPremiumItemDAO()
-	{
+	public PremiumItemDAO getPremiumItemDAO() {
 		return premiumItemDAO;
 	}
 	
 	@Override
-	public RecipeBookDAO getRecipeBookDAO()
-	{
+	public RecipeBookDAO getRecipeBookDAO() {
 		return recipeBookDAO;
 	}
 	
 	@Override
-	public RecipeShopListDAO getRecipeShopListDAO()
-	{
+	public RecipeShopListDAO getRecipeShopListDAO() {
 		return recipeShopListDAO;
 	}
 	
 	@Override
-	public RecommendationBonusDAO getRecommendationBonusDAO()
-	{
+	public RecommendationBonusDAO getRecommendationBonusDAO() {
 		return recommendationBonusDAO;
 	}
 	
 	@Override
-	public ServitorSkillSaveDAO getServitorSkillSaveDAO()
-	{
+	public ServitorSkillSaveDAO getServitorSkillSaveDAO() {
 		return servitorSkillSaveDAO;
 	}
 	
 	@Override
-	public ShortcutDAO getShortcutDAO()
-	{
+	public ShortcutDAO getShortcutDAO() {
 		return shortcutDAO;
 	}
 	
 	@Override
-	public SkillDAO getSkillDAO()
-	{
+	public SkillDAO getSkillDAO() {
 		return skillDAO;
 	}
 	
 	@Override
-	public SubclassDAO getSubclassDAO()
-	{
+	public SubclassDAO getSubclassDAO() {
 		return subclassDAO;
 	}
 	
 	@Override
-	public TeleportBookmarkDAO getTeleportBookmarkDAO()
-	{
+	public TeleportBookmarkDAO getTeleportBookmarkDAO() {
 		return teleportBookmarkDAO;
 	}
+	
+	@Override
+	public ClanDAO getClanDAO() {
+		return clanDAO;
+	}
 }

+ 79 - 0
src/main/java/com/l2jserver/gameserver/dao/impl/mysql/ClanDAOMySQLImpl.java

@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2004-2019 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.dao.impl.mysql;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
+import com.l2jserver.gameserver.dao.ClanDAO;
+
+/**
+ * Clan DAO MySQL implementation.
+ * @author Zoey76
+ */
+public class ClanDAOMySQLImpl implements ClanDAO {
+	
+	private static final Logger LOG = LoggerFactory.getLogger(ClanDAOMySQLImpl.class);
+	
+	private static final String SELECT_CLAN_PRIVILEGES = "SELECT `privs`, `rank`, `party` FROM `clan_privs` WHERE clan_id=?";
+	
+	private static final String INSERT_CLAN_PRIVILEGES = "INSERT INTO `clan_privs` (`clan_id`, `rank`, `party`, `privs`) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE `privs`=?";
+	
+	@Override
+	public Map<Integer, Integer> getPrivileges(int clanId) {
+		final var result = new HashMap<Integer, Integer>();
+		try (var con = ConnectionFactory.getInstance().getConnection();
+			var ps = con.prepareStatement(SELECT_CLAN_PRIVILEGES)) {
+			ps.setInt(1, clanId);
+			try (var rs = ps.executeQuery()) {
+				while (rs.next()) {
+					final int rank = rs.getInt("rank");
+					if (rank == -1) {
+						continue;
+					}
+					result.put(rank, rs.getInt("privs"));
+				}
+			}
+		}
+		catch (Exception ex) {
+			LOG.error("Unable to restore clan privileges for clan Id {}!", clanId, ex);
+		}
+		return result;
+	}
+	
+	@Override
+	public void storePrivileges(int clanId, int rank, int privileges) {
+		try (var con = ConnectionFactory.getInstance().getConnection();
+			var ps = con.prepareStatement(INSERT_CLAN_PRIVILEGES)) {
+			ps.setInt(1, clanId);
+			ps.setInt(2, rank);
+			ps.setInt(3, 0);
+			ps.setInt(4, privileges);
+			ps.setInt(5, privileges);
+			ps.execute();
+		}
+		catch (Exception ex) {
+			LOG.error("Unable to store clan privileges for clan Id {}!", clanId, ex);
+		}
+	}
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 144 - 286
src/main/java/com/l2jserver/gameserver/model/L2Clan.java


Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov