Jump to content

Recommended Posts

Posted (edited)

Hello,i just create this code for my server & i am sharing cause i didn't found a share similar to this!

This is for l2jfrozen ,but it work in every project with  few changes.

Ass the tittle says,these are configs to disable healers from events or specific classes you wish.


Code:

Spoiler

head-src/gameserver/Config.java
----------------------------------------------------------------------------------------------------
+/** Event restricted classes*/
+public static boolean TVT_ALLOW_HEALER_CLASSES;
+public static String DISABLE_ID_CLASSES_TVT;
+public static FastList <Integer> DISABLE_CLASSES_TVT = new FastList <> ();

+
+public static boolean CTF_ALLOW_HEALER_CLASSES;
+public static String DISABLE_ID_CLASSES_CTF;
+public static FastList <Integer> DISABLE_CLASSES_CTF = new FastList <> ();

+
+public static String DISABLE_ID_CLASSES_DM;
+public static FastList <Integer> DISABLE_CLASSES_DM = new FastList <> ();

 +   // ============================================================

 

            TVT_TOP_KILLER_QTY = Integer.parseInt(TVTSettings.getProperty("TvTTopKillerRewardQty", "2000000"));
            TVT_AURA = Boolean.parseBoolean(TVTSettings.getProperty("TvTAura", "False"));
            TVT_STATS_LOGGER = Boolean.parseBoolean(TVTSettings.getProperty("TvTStatsLogger", "true"));
+TVT_ALLOW_HEALER_CLASSES = Boolean.parseBoolean (TVTSettings.getProperty ("TvTAllowedHealerClasses", "true"));
+DISABLE_ID_CLASSES_TVT = TVTSettings.getProperty ("DisableTvtClassesID", "");
+DISABLE_CLASSES_TVT = new FastList <> ();
+for (String class_id: DISABLE_ID_CLASSES_TVT.split (","))
+{
+if (! class_id.equals (""))
+DISABLE_CLASSES_TVT.add (Integer.parseInt (class_id));}

 

 

CTF_REVIVE_RECOVERY = Boolean.parseBoolean(CTFSettings.getProperty("CTFReviveRecovery", "False"));
            CTF_COMMAND = Boolean.parseBoolean(CTFSettings.getProperty("CTFCommand", "True"));
            CTF_AURA = Boolean.parseBoolean(CTFSettings.getProperty("CTFAura", "True"));
        
+CTF_ALLOW_HEALER_CLASSES = Boolean.parseBoolean (CTFSettings.getProperty ("CtfAllowedHealerClasses", "true"));
+DISABLE_ID_CLASSES_CTF = CTFSettings.getProperty ("DisableCtfClassesID", "");
+DISABLE_CLASSES_CTF = new FastList <> ();
+for (String class_id: DISABLE_ID_CLASSES_CTF.split (","))
+{
+if (! class_id.equals (""))
+DISABLE_CLASSES_CTF.add (Integer.parseInt (class_id));}

 

 

DM_STATS_LOGGER = Boolean.parseBoolean(DMSettings.getProperty("DMStatsLogger", "true"));         
            DM_ALLOW_HEALER_CLASSES = Boolean.parseBoolean(DMSettings.getProperty("DMAllowedHealerClasses", "true"));         
            DM_REMOVE_BUFFS_ON_DIE = Boolean.parseBoolean(DMSettings.getProperty("DMRemoveBuffsOnPlayerDie", "false"));    
+DISABLE_ID_CLASSES_DM = DMSettings.getProperty ("DisableDmClassesID", "");
+DISABLE_CLASSES_DM = new FastList <> ();
+for (String class_id: DISABLE_ID_CLASSES_DM.split (","))
+{
+if (! class_id.equals (""))
+DISABLE_CLASSES_DM.add (Integer.parseInt (class_id));}

 

 

 

config/frozen/tvt.Properties:
----------------------------------------------

+# ======================================================== #
+#      Restrict Classes for events   #

+#            By: Irrelevant
+# ======================================================== #
+
+TvTAllowedHealerClasses = False
+#Add restriction for extra Classes Id:
+#example: 97.92
+DisableTvtClassesID = 

 

config/frozen/ctf.Properties:
---------------------------------------------------------

+# ======================================================== #
+#      Restrict Classes for events   #

+#            By: Irrelevant
+# ======================================================== #

+CtfAllowedHealerClasses = False
+#Add restriction for extra Classes Id:
+#example: 97.92
+DisableCtfClassesID = 

 

config/frozen/dm.Properties:
--------------------------------------------------

+# ======================================================== #
+#      Restrict Classes for events   #

+#            By: Irrelevant
+# ======================================================== #

+#Disabled Healer classes for DM are already in configs
+#Add extra restrictions below
+#Add restriction for extra Classes Id:
+#example: 97.92
+DisableDmClassesID = 


com.l2jfrozen.gameserver.model.entity.event. TvT.java
-------------------------------------------------------------------------

    eventPlayer.sendMessage("You already participated in event with another char!");
                        return false;
                    }
                }

+if (! Config.TVT_ALLOW_HEALER_CLASSES && (eventPlayer.getClassId() == ClassId.cardinal || eventPlayer.getClassId() == ClassId.bishop || eventPlayer.getClassId() == ClassId.elder || eventPlayer.getClassId() == ClassId.evaSaint || eventPlayer.getClassId() == ClassId.shillenElder|| eventPlayer.getClassId() == ClassId.shillienSaint))
+{
+    eventPlayer.sendMessage("You can't join with Healer Class!");
+    return false;
+        }
+    {
+    if (Config.DISABLE_CLASSES_TVT.contains (eventPlayer.getClassId (). getId ())) {
+    eventPlayer.sendMessage ("Your Class has disabled for TvT Event");
+    return false;
+    }
+    }

 

com.l2jfrozen.gameserver.model.entity.event. CTF.java
-------------------------------------------------------------------------

eventPlayer.sendMessage("You already participated in event with another char!");
                        return false;
                    }
                }

+if (! Config.TVT_ALLOW_HEALER_CLASSES && (eventPlayer.getClassId() == ClassId.cardinal || eventPlayer.getClassId() == ClassId.bishop || eventPlayer.getClassId() == ClassId.elder || eventPlayer.getClassId() == ClassId.evaSaint || eventPlayer.getClassId() == ClassId.shillenElder|| eventPlayer.getClassId() == ClassId.shillienSaint))
+{
+    eventPlayer.sendMessage("You cant join with Healer Class!");
+    return false;
+        }
+    {
+    if (Config.DISABLE_CLASSES_CTF.contains (eventPlayer.getClassId (). getId ())) {
+    eventPlayer.sendMessage ("Your Class has disabled for TvT Event");
+    return false;
+    }
+    }

 

 

com.l2jfrozen.gameserver.model.entity.event. DM.java
---------------------------------------------------------------------------

eventPlayer.sendMessage("You already participated in event with another char!");
                        return false;
                    }
                }

+if (Config.DISABLE_CLASSES_DM.contains (eventPlayer.getClassId (). getId ())) {
+eventPlayer.sendMessage ("Your Class has disabled for DM Event");
+return false;
+}

 





Special Thanks to " Melron "!
for code improving help(actually he gave the entire code XD).

 

Updated code: 

Spoiler

Config.java
--------------------
+/** Event prohibit classes*/
+     public static Map<Class<?>, List<Integer>> EVENT_RESTRICTED_CLASSES = new HashMap<>();

//=========================//
 

@3032,34

PVP1_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP1CustomMeesage", "You have been teleported to PvP Zone 1!");
            PVP2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP2CustomMeesage", "You have been teleported to PvP Zone 2!");

+//Disable classes in events
+Arrays.asList("CTF", "TvT", "DM").forEach(ev -> 
+      {
+          try
+          {
+             EVENT_RESTRICTED_CLASSES.put(Class.forName("com.l2jfrozen.gameserver.model.entity.event." + ev), Stream.of(l2jfrozenSettings.getProperty(ev + +"RestrictedClasses").split(",")).map(Integer::parseInt).collect(Collectors.toList()));
+         }
+         catch (ClassNotFoundException ex)
+         {
+             ex.printStackTrace();
+          }
+      });

         }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                        throw new Error("Failed to Load " + L2JFROZEN + " File.");

 

 

config/functions/l2jfrozen.Properties:
-----------------------------------------------

+# ======================================================== #
+#      Restrict Classes for events   #
+# ======================================================== #
+TvTRestrictedClasses=92,97
+CTFRestrictedClasses=92,97
+DMRestrictedClasses=92,97 


com.l2jfrozen.gameserver.model.entity.event. TvT.java
-------------------------------------------------------------------------
eventPlayer.sendMessage("You already participated in event with another char!");
                        return false;
                    }
                }

 

+    if (Config.EVENT_RESTRICTED_CLASSES.getOrDefault(TvT.class, Collections.emptyList()).contains(eventPlayer.getClassId().getId()))
+                {
+                eventPlayer.sendMessage("Your class is prohibited.");
+                return false;
+            }

 

com.l2jfrozen.gameserver.model.entity.event. CTF.java
------------------------------------------------------------------------

eventPlayer.sendMessage("You already participated in event with another char!");
                        return false;
                    }
                }

 

+    if (Config.EVENT_RESTRICTED_CLASSES.getOrDefault(CTF.class, Collections.emptyList()).contains(eventPlayer.getClassId().getId()))
+                {
+                eventPlayer.sendMessage("Your class is prohibited.");
+                return false;
+            }


com.l2jfrozen.gameserver.model.entity.event. DM.java
------------------------------------------------------------------------

eventPlayer.sendMessage("You already participated in event with another char!");
                        return false;
                    }
                }

 

+    if (Config.EVENT_RESTRICTED_CLASSES.getOrDefault(DM.class, Collections.emptyList()).contains(eventPlayer.getClassId().getId()))
+                {
+                eventPlayer.sendMessage("Your class is prohibited.");
+                return false;
+            }

 

 

Edited by Irrelevant
Posted (edited)

1. Convert the following into Set or even better a single HashMap that uses as a key a String which refer to the case "CTF", "TVT", "OLYMPIAD" and the value is a Set. 

 

You can retrieve this like:

CLASS_ID_RESTRICTION.getOrDefault("OLYMPIAD", Collections.emptySet()).contains(ClassId.cardinal.getId());

 

2. You don't need to write By: Irrelevant on each single config's line.

 

3. Replace this with a switch

 

+if (! Config.TVT_ALLOW_HEALER_CLASSES && (eventPlayer.getClassId() == ClassId.cardinal || eventPlayer.getClassId() == ClassId.bishop || eventPlayer.getClassId() == ClassId.elder || eventPlayer.getClassId() == ClassId.evaSaint || eventPlayer.getClassId() == ClassId.shillenElder|| eventPlayer.getClassId() == ClassId.shillienSaint))

 

Edited by Kara
Posted (edited)
18 hours ago, Kara said:

1. Convert the following into Set or even better a single HashMap that uses as a key a String which refer to the case "CTF", "TVT", "OLYMPIAD" and the value is a Set. 

 

You can retrieve this like:



CLASS_ID_RESTRICTION.getOrDefault("OLYMPIAD", Collections.emptySet()).contains(ClassId.cardinal.getId());

 

2. You don't need to write By: Irrelevant on each single config's line.

 

3. Replace this

 



+if (! Config.TVT_ALLOW_HEALER_CLASSES && (eventPlayer.getClassId() == ClassId.cardinal || eventPlayer.getClassId() == ClassId.bishop || eventPlayer.getClassId() == ClassId.elder || eventPlayer.getClassId() == ClassId.evaSaint || eventPlayer.getClassId() == ClassId.shillenElder|| eventPlayer.getClassId() == ClassId.shillienSaint))

 

thanks.
oh hahaha noo , i just have them all in custom config and i change the location for this share so i copy/paste 3 time above each one of them XD

Edited by Irrelevant
Posted
1 hour ago, Irrelevant said:

thanks.
oh hahaha noo , i just have them all in custom config and i change the location for others by copy/paste 3 time above each one of them XD

 

Sit down and improve your code. When i come back in 24 hours this must be in such perfect shape that i'll be speechless. Go !

Posted
57 minutes ago, Kara said:

 

Sit down and improve your code. When i come back in 24 hours this must be in such perfect shape that i'll be speechless. Go !

haha ok , i will try tommorow :)

Posted (edited)

Create a local svn . It will help you to see your changes and export your diff files instead of adding + at every line.

 

@onCode

 

Your config should looks like

TvTRestrictedClasses=1,2,3,4,5
CtFRestrictedClasses=10,20,30,40,50
DMRestrictedClasses=20,30,40,50

 

 

Lets parse it... Since we have in common the "RestrictedClasses" ...

Arrays.asList("CTF", "TvT", "DM").forEach(ev -> 
{
	try
	{
		EVENT_RESTRICTED_CLASSES.put(Class.forName("com.l2jfrozen.gameserver.model.entity.event." + ev), Stream.of(MyEventSettings.getProperty(ev + "RestrictedClasses").split(",")).map(Integer::parseInt).collect(Collectors.toList()));
	}
	catch (ClassNotFoundException ex)
	{
		ex.printStackTrace();
	}
});

 

Your config should looks like:

public static Map<Class<?>, List<Integer>> EVENT_RESTRICTED_CLASSES = new HashMap<>();

 

And as mentioned before...

This check can be used everywhere at all your events

if (Config.EVENT_RESTRICTED_CLASSES.getOrDefault(getClass(), Collections.emptyList()).contains(eventPlayer.getClassId().getId()))
{
	eventPlayer.sendMessage("Your class is prohibited.");
	return false;
}

 

if you use this check inside of a static method, you have to use the name of the class directly.

Config.EVENT_RESTRICTED_CLASSES.getOrDefault(TvT.class, Collections.emptyList()).contains(eventPlayer.getClassId().getId())

 

Edited by melron
  • Like 1
Posted
6 minutes ago, melron said:

Create a local svn . It will help you to see your changes and export your diff files instead of adding + at every line.

 

@onCode

 

Your config should looks like


TvTRestrictedClasses=1,2,3,4,5
CtFRestrictedClasses=10,20,30,40,50
DMRestrictedClasses=20,30,40,50

 

 

Lets parse it... Since we have in common the "RestrictedClasses" ...


Arrays.asList("CTF", "TvT", "DM").forEach(ev -> 
{
	try
	{
		EVENT_RESTRICTED_CLASSES.put(Class.forName("com.l2jfrozen.gameserver.model.entity.event." + ev), Stream.of(MyEventSettings.getProperty(ev + "RestrictedClasses").split(",")).map(Integer::parseInt).collect(Collectors.toList()));
	}
	catch (ClassNotFoundException ex)
	{
		ex.printStackTrace();
	}
});

 

Your config should looks like:


public static Map<Class<?>, List<Integer>> EVENT_RESTRICTED_CLASSES = new HashMap<>();

 

And as mentioned before...

This check can be used everywhere at all your events


if (Config.EVENT_RESTRICTED_CLASSES.getOrDefault(getClass(), Collections.emptyList()).contains(eventPlayer.getClassId().getId()))
{
	eventPlayer.sendMessage("Your class is prohibited.");
	return false;
}

 

if you use this check inside of a static method, you have to use the name of the class directly.


Config.EVENT_RESTRICTED_CLASSES.getOrDefault(TvT.class, Collections.emptyList()).contains(eventPlayer.getClassId().getId())

 

WOW ,that was really nice of you! THANKS!!!!!!!!! i will change them tommorow!

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...