Jump to content

Τα Πιο Βασικά Πράγματα Στην L2J (Java).


Recommended Posts

Χαιρετώ,

 

σήμερα αποφάσισα να κάνω ένα ακόμα share για αυτήν την κοινότητα!

 

Τι περιέχει αυτό το share :

 

- Πως φτιάχνουμε δικό μας config και μερικά χρήσιμα πράγματα για αυτό. (Κεφάλαιο 1)

- Γενικές πληροφορίες (Κεφάλαιο 2)

- Πως φτιάχνουμε ένα δικό μας voiced command. (Κεφάλαιο 3)

 

Κεφάλαιο 1

 

Ανοίγουμε το αρχείο Config.java (μπορεί να το δείτε και L2Config.java)

 

Στο πάνω μέρος θα δείτε αυτές τις γραμμές :

 

	public static final String BANNED_IP_XML = "./config/banned.xml";
public static final String CLANS_FILE = "./config/clans.properties";
public static final String EVENTS_FILE = "./config/events.properties";
public static final String FLOOD_PROTECTOR_FILE = "./config/floodprotector.properties";
public static final String HEXID_FILE = "./config/hexid.txt";
public static final String ID_CONFIG_FILE = "./config/idfactory.properties";
public static final String LOGIN_CONFIGURATION_FILE = "./config/loginserver.properties";
public static final String NPCS_FILE = "./config/npcs.properties";
public static final String PLAYERS_FILE = "./config/players.properties";
public static final String SERVER_FILE = "./config/server.properties";
public static final String SIEGE_FILE = "./config/siege.properties";

 

κάτω από την γραμμή (public static final String SIEGE_FILE = "./config/siege.properties";) βάζουμε την παρακάτω γραμμή :

 

public static final String ROMEO_FILE = "./config/romeo.properties";

 

χρησιμοποίησα το όνομα μου ως παράδειγμα. εσείς στην θέση του ROMEO_FILE μπορείτε να βάλετε το δικό σας όνομα πχ. CUSTOM_FILE και στην θέση του romeo.properties κάνετε ακριβώς το ίδιο πχ. custom.properties

 

Ακριβώς κάτω από παραπάνω γραμμές θα δείτε αυτό εδώ το κομμάτι :

 

	// --------------------------------------------------
// Clans settings
// --------------------------------------------------

 

κάτω από αυτό θα βάζετε το 1 μέρος από κάθε config που βάζετε για παράδειγμα public static boolean ALLOW_WEDDING_SYSTEM;

 

σε κάθε config που βάζετε γράφετε public static και μετά :

 

boolean = για περιπτώσεις True/False

int = για περιπτώσεις αριθμού

String = για οτιδήποτε όπως : !ahanvmc-@_!

 

συνολικές γραμμές :

 

public static boolean ALLOW_ROMEO_GUIDE; (πχ. True/False)

public static int HOW_MANY_CHAPTERS_GUIDE_HAS; (πχ. 4)

public static String WHAT_IS_THE_EXACTLY_NAME_OF_ROMEO; (πχ. `Romeo)

 

μετά από αυτό κάνουμε search στο αρχείο Config.java

 

			catch (Exception e)
		{
			e.printStackTrace();
			throw new Error("Server failed to load " + CLANS_FILE + " file.");
		}

 

κάτω από αυτό βάζουμε αυτές τις γραμμές :

 

			// Romeo settings
		try
		{
			Properties romeo = new Properties();
			InputStream is = new FileInputStream(new File(ROMEO_FILE));
			romeo.load(is);
			is.close();

		}
		catch (Exception e)
		{
			e.printStackTrace();
			throw new Error("Server failed to load " + ROMEO_FILE + " file.");
		}

 

κάτω από την γραμμή is.close(); βάζουμε το τελευταίο κομμάτι του config μας.

 

πχ. για αυτές τις γραμμές :

 

1) public static boolean ALLOW_ROMEO_GUIDE;

2) public static int HOW_MANY_CHAPTERS_GUIDE_HAS;

3) public static String WHAT_IS_THE_EXACTLY_NAME_OF_ROMEO;

 

βάζουμε :

 

1) ALLOW_ROMEO_GUIDE = Boolean.parseBoolean(romeo.getProperty("AllowRomeoGuide", "True"));

2) HOW_MANY_CHAPTERS_GUIDE_HAS= Integer.parseInt(romeo.getProperty("HowManyChaptersGuideHas", "4"));

3) WHAT_IS_THE_EXACTLY_NAME_OF_ROMEO = romeo.getProperty("WhatIsTheExactlyNameOfRomeo", "`Romeo"));

 

αφού δημιουργήσουμε το αρχείο romeo.properties στον φάκελο config βάζουμε μέσα τις παρακάτω γραμμές :

 

# Config guide by Romeo

AllowRomeoGuide = True

HowManyChaptersGuideHas = 4

WhatIsTheExactlyNameOfRomeo = `Romeo

 


 

Κεφάλαιο 2

 

Σήμερα θα σας μιλήσω για γενικά θέματα στην l2j. Ας αρχίσουμε,

 

Βασικοί ορισμοί :

 

- boolean = True/False (πχ, boolean l2j = true; )

- int = μεγάλοι ακέραιοι (πχ, int l2j = 100; )

- String = γενικό (τα πάντα) (πχ, String message = !l2jisdabest@; )

- static = είναι κάτι το στατικό (δεν αλλάζει)

 

- activeChar.setHero(true); = να κάνει τον ενεργό παίχτη hero για πάντα (true). ενώ για μέχρι το restart (false, βλέπε παρακάτω).

- activeChar.setNoble(false);

- activeChar.setName("εδώ το όνομα"); = με αυτήν την εντολή αλλάζει το όνομα του ενεργού παίχτη.

- activeChar.setTitle(""); = με αυτήν την εντολή αλλάζει τον τίτλο του ενεργού παίχτη σε κενό.

 

Διευκρινίσεις :

 

- package net.sf.l2j; (αυτό το βλέπουμε στο πάνω πάνω μέρος του αρχείου που είμαστε. τι σημαίνει? σημαίνει σε πιο package είναι το αρχείο που είμαστε (την διαδρομή του)

 

- import net.sf.l2j.gameserver.util.FloodProtectorConfig; (αυτό το βλέπουμε κάτω από το παραπάνω. τι σημαίνει? σημαίνει ότι χρησιμοποιούμε (στην προκειμένη περίπτωση το FloodProtectorConfig και βρίσκεται στο gameserver.util) μια εντολή από αυτό το αρχείο.

 

Δείγματα από κώδικες :

 

θέλουμε για παράδειγμα να βάλουμε ένα announce όταν μπαίνει ένας hero στον server. (ότι έχει να κάνει σχέση με το login, δηλαδή μόλις μπαίνει ο char στο l2 πάμε στο EnterWorld.java)

 

		if (activeChar.isHero())
	{
		Announcements.getInstance();
		Announcements.announceToAll("Hero Character : "+activeChar.getName()+" is now online!");
		return;
	}

 

ας αναλύσουμε κάθε κομμάτι αυτού του κώδικα :

 

if (activeChar.isHero()) = σημαίνει : εάν ο ενεργός παίχτης είναι hero.

{ = ανοίγουμε αγκύλες για να βάλουμε μέσα τον κώδικα που θέλουμε να δράσει.

Announcements.announceToAll("Hero Character : "+activeChar.getName()+" is now online!"); = είναι το announce που θέλουμε να δείξει όταν μπεί ο char.

} = κλείνουμε την αγκύλη που ανοίξαμε.

 

ένα άλλο δείγμα που είναι χρήσιμο (pvp spree system) :

 

πάμε στο αρχείο L2PcInstance.java και πατάμε CTRL + F για να αναζητήσουμε την γραμμή : private int _pvpKills;

 

από κάτω αφήνουμε ένα κενό και βάζουμε : private int pvpspree = 0;

 

μετά κάνουμε πάλι αναζήτηση για να βρούμε την γραμμή : setPvpKills(getPvpKills() + 1);

 

από κάτω βάζουμε αυτόν τον κώδικα :

 

		pvpspree++;

	switch (pvpspree)
	{
		case 1 : 
			Announcements.announceToAll(getName()+" is Dominating!");
			break;

		case 2 : 
			Announcements.announceToAll(getName()+" is on a killing spree!");
			break;
	}

 

το switch είναι ο καλύτερος τρόπος για να γίνει αυτό το πράγμα.

 

το case 1 μας δηλώνει στην προκειμένη περίπτωση ότι σε 1 συνεχόμενο pvp θα γίνει η παρακάτω πράξη δηλαδή το announce.

το ίδιο ισχύει και για το case 2 δηλαδή σε 2 συνεχόμενα pvp θα γίνει η παρακάτω πράξη.

 

προσοχή! μετά από κάθε πράξη στο switch βάζουμε το break;

 

αυτά πιστεύω είναι αρκετά!

 


 

Κεφάλαιο 3

 

Σε αυτό το κεφάλαιο θα σας δείξω πως να κάνετε ένα voicedcommand (.)

 

Πηγαίνουμε στην διαδρομή : net.sf.l2j.gameserver.handler.voicedcommandhandlers , πατάμε δεξί κλικ, New -> Class . Από μόνο του μας έχει απλά να βάλουμε το όνομα που θέλουμε να έχει το αρχείο για παράδειγμα MyFirstVC αφού πατήσουμε Finish μας ανοίγει ένα καινούργιο αρχείο που περιέχει αυτό :

 

/*
* This program 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.
* 
* This program 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 net.sf.l2j.gameserver.handler.voicedcommandhandlers;

/**
* @author `Romeo
*
*/
public class MyFirstVC
{

}

 

στην προκειμένη περίπτωση του voicedcommand δίπλα από το public class MyFirstVC βάζουμε : implements IVoicedCommandHandler και πρέπει να δείχνει κάπως έτσι :

 

public class MyFirstVC implements IVoicedCommandHandler

τότε θα δούμε error (σφάλμα) στην λέξη MyFirstVC. Ως πιθανές λύσεις μας έχει :

 

1) Add unimplemented methods

2) Make type 'MyFirstVC' abstract

 

στην προκειμένη περίπτωση χρησιμοποιούμε την πρώτη πιθανή λύση. όταν την διαλέξουμε θα δείτε ότι στον κώδικα μας θα μπούν οι παρακάτω γραμμές :

 

	/* (non-Javadoc)
 * @see net.sf.l2j.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
 */
@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	// TODO Auto-generated method stub
	return false;
}

/* (non-Javadoc)
 * @see net.sf.l2j.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
 */
@Override
public String[] getVoicedCommandList()
{
	// TODO Auto-generated method stub
	return null;
}

 

κάτω από την γραμμή

 

public class MyFirstVC implements IVoicedCommandHandler
{

 

θα βάλουμε αυτόν τον κώδικα

 

	private static final String[] _voicedCommands =
{
	"myfirstvc"
};

 

που μέσα στις αγκύλες υπάρχει το command που θα είναι available για να χρησιμοποιήσουμε. τότε θα μας βγάλει ένα warning (ειδοποίηση) για το _voicedCommands. τότε κάνουμε αντιγραφή το _voicedCommands και πάμε κάτω κάτω που θα δούμε αυτό

 

	public String[] getVoicedCommandList()
{
	// TODO Auto-generated method stub
	return null;
}

και εκεί που λέει return null; στην θέση του null βάζουμε το _voicedCommands

 

τότε όλος ο κώδικας πρέπει να μοιάζει σαν αυτόν :

 

/*
* This program 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.
* 
* This program 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 net.sf.l2j.gameserver.handler.voicedcommandhandlers;

import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

/**
* @author `Romeo
*
*/
public class MyFirstVC implements IVoicedCommandHandler
{

private static final String[] _voicedCommands =
{
	"myfirstvc"
};

@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	return false;
}

@Override
public String[] getVoicedCommandList()
{
	return _voicedCommands;
}

}

 

τώρα είναι έτοιμος για να βάλουμε τις εντολές που θέλουμε να εκτελεί. εκεί που λέει

 

 	@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	return false;

 

από κάτω βάζουμε τις εντολές που θέλουμε, εγώ για παράδειγμα θα βάλω να βγάζει ένα announce και να κάνει τον char hero μέχρι το restart.

 

βάζουμε :

 

		Announcements.announceToAll(activeChar.getName()+ ": I used .myfirstvc and I am hero until restart.");
	activeChar.setHero(false);

 

τελιώσαμε, τώρα όλος ο κώδικας μας πρέπει να μοιάζει σαν αυτόν :

 

/*
* This program 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.
* 
* This program 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 net.sf.l2j.gameserver.handler.voicedcommandhandlers;

import net.sf.l2j.gameserver.Announcements;
import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

/**
* @author `Romeo
*
*/
public class MyFirstVC implements IVoicedCommandHandler
{

private static final String[] _voicedCommands =
{
	"myfirstvc"
};

@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	Announcements.announceToAll(activeChar.getName()+ ": I used .myfirstvc and I am hero until restart.");
	activeChar.setHero(false);
	return false;
}

@Override
public String[] getVoicedCommandList()
{
	return _voicedCommands;
}

}

 

Description : όταν πατάς .myfirstvc γίνεσαι hero μέχρι το restart και βγάζει announce προς όλους.

 

το τελευταίο πράγμα που πρέπει να κάνεις είναι να δηλώσεις το voiced command. λοιπόν, πηγαίνουμε στο VoicedCommandHandler.java και κάτω από την γραμμή

 

_datatable = new HashMap<String, IVoicedCommandHandler>();

 

βάζουμε

 

registerVoicedCommandHandler(new MyFirstVC()); θα βγάλει error στο MyFirstVC γιατί πρέπει να το κάνεις import.

 

αυτό ήταν όλο για να κάνεις ένα voiced command.

 

Περισσότερα κεφάλαια, soon!

 

Kind regards,

 

`Romeo

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Posts

    • L2 Insignia High Five 20x MID SERVER FOCUSED ON OLYMPIAD | PVP | AUTOFARM       OPEN BETA TEST SERVER 3 MAY 2024   GRAND OPENING 10 MAY 2024    Rates: 📜 XP/SP 20x | Spoil 15x | Drop 10x | Adena 10x 📜     Server Features: 🔥 No Olf-T Shirt, No big over-enchant, No over-power Donate 🔥 🔥 VIP Gold Color Chat, Unique Olympiad Extra Points Engine, GvG Event 🔥 🔥 Auto-Farm, LoA and DV scheduled PvP Zone, Calendar Daily Reward 🔥 🔥 Castle Instance, Solo Instance, PvP Solo Rift, Dress me system, Adena Boxes 🔥        Website: https://www.l2insignia.com  Discord: https://discord.com/invite/yEgsrHn2hQ      
    • I am selling the essence project which includes versions 388 and 439 that have been running for over 2 years or (447 as custom PVP like Pride). I have a test server for you to test them out. If you are really interested in it then contact my seller at discord: kiwi7106. Price: 4000 Euro P/s: This is a project that I have spent a lot of money and time developing, so if you are not interested in it, please get out of this topic, thank you. P/s 2: If you find the price too expensive, it's best to skip this article and find another project and don't comment negatively on my topic, thank you.
    • Someone ask me for this, it should work on any client that has Kamael race, preview:     Installation - there are two ways to install depending on how you want to use it:   Method 1: If you want to completely replace the original, do:   Copy all lines from your armorgrp to Notepad++, press Ctrl+H, check the "match whole word" option and replace:   kamael.Mkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_MKamael_m001_w_ad00   Then replace:   MKamael.Mkamael_m000_t00_w   by:   AvengersKamaelWings.MKamael_m001_t00_w   Now repeat the same process with the female, replace:   kamael.Fkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_FKamael_m001_w_ad00   Then replace:   FKamael.Fkamael_m000_t00_w   by:   AvengersKamaelWings.FKamael_m001_t00_w   You're done, paste everything back into File Edit and save!   Method 2: If you only want to replace in specific sets, execute the above process only on the armorgrp of those sets.   Repack by: AvengersTeamBr Password: LadrãoDeFrango      
  • Topics

×
×
  • Create New...