Jump to content

Recommended Posts

Posted

Καλησπεριζω τα μελη του mxc ειναι το πρωτο μου Java Code Share και ελπιζω να ειναι καλο και να βρειι πολλα ατομα χαρουμενα διοτι απο τη μια υπαρχει αυτη η εντολη αλλα δεν πολη δουλευει σωστα η ειναι bugαρισμενει.Λοιπον ας αρχισω την παρουσιαση του και πως θα την βαλλουμε μεσα στο pack μας:

Δημηουργουμε ενα νεο Java αρχειο με το ονομα "DelevelCmd.java" και το βαζουμε μεσα στον φακελο "voicedcommandhandlers" και αντιγραφουμε το κοδικα στο αρχειο οπου δημιουργισαμε

package com.l2jprotocol.gameserver.handler.voicedcommandhandlers;

import com.l2jprotocol.Config;
import com.l2jprotocol.gameserver.datatables.SkillTable;
import com.l2jprotocol.gameserver.datatables.xml.ExperienceData;
import com.l2jprotocol.gameserver.handler.IVoicedCommandHandler;
import com.l2jprotocol.gameserver.managers.SiegeManager;
import com.l2jprotocol.gameserver.model.actor.instance.L2PcInstance;
import com.l2jprotocol.gameserver.model.entity.siege.Siege;
import com.l2jprotocol.gameserver.model.L2Skill;

/**
* @author LastWarrior_Dev_Team
*/

public class DelevelCmd implements IVoicedCommandHandler
{
private static final String[] VOICED_COMMANDS =
{
		"delevel"
};

public static final int ZONE_PEACE = 2;

/* (non-Javadoc)
 * @see com.l2jprotocol.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(String, com.l2jprotocol.gameserver.model.L2PcInstance), String)
 */
@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	if(command.startsWith("delevel"))
	{
		requestDelevel(activeChar);
	}
	return true;
}

public boolean requestDelevel (L2PcInstance activeChar)
	{
		Siege siege = SiegeManager.getInstance().getSiege(activeChar);

		// Check the activeChar's level.
		if (activeChar.getLevel() < Config.DELEVEL_MIN_LEVEL)
		{
			activeChar.sendMessage("You do not meet the level requirement for Delevel!");
			return false;
		}	
		// Check activeChar if have SubClass
		else if (activeChar.isSubClassActive())
		{
			activeChar.sendMessage("Please switch to your Main Class before attempting Delevel.");
			return false;
		}	
		// Check activeChar if in Peace Zone
		else if(!activeChar.isInsideZone(ZONE_PEACE))
		{
			activeChar.sendMessage("You can only Delevel in peace zone.");
			return false;
		}
		 // Check activeChar is death/fake death and movement disable 
		else if(activeChar.isMovementDisabled() || activeChar.isAlikeDead())
		{	activeChar.sendMessage("You can't Delevel on death mode");
			return false; 
		}
		// Check if activeChar is in Siege
		else if(siege != null && siege.getIsInProgress())
		{
			activeChar.sendMessage("You are in siege, you can't Delevel.");
			return false;
		}
		// Check if activeChar is a Cursed Weapon owner
		else if(activeChar.isCursedWeaponEquiped())
		{
			activeChar.sendMessage("You can't Delevel! You are currently holding a cursed weapon.");
			return false;
		}
		// Check if activeChar is in Duel
		else if(activeChar.isInDuel())
		{
			activeChar.sendMessage("You can't Delevel You are in a duel!");
			return false;
		}
		// Check is in DimensionsRift
		else if(activeChar.isInParty() && activeChar.getParty().isInDimensionalRift())
		{
			activeChar.sendMessage("You can't Delevel! You are in the dimensional rift.");
			return false;
		}
		// Check to see if the activeChar is in an event
		else if(activeChar.isInFunEvent())
		{
			activeChar.sendMessage("You can't Delevel! You are in event now.");
			return false;
		}
		// Check activeChar is in Olympiade
		else if(activeChar.isInOlympiadMode() || activeChar.getOlympiadGameId() != -1)
		{
			activeChar.sendMessage("You can't Delevel! Your are fighting in Olympiad!");
			return false;
		}
		// Check activeChar is in observer mode
		else if(activeChar.inObserverMode())
		{
			activeChar.sendMessage("You can't Delevel in Observer mode!");
			return false;
		}
		// Check activeChar have karma/pk/pvp status
		if(activeChar.getKarma() > 0 || activeChar.getPvpFlag() > 0)
		{
			activeChar.sendMessage("player in PVP or with Karma can't use the Delevel command!");
			return false;
		}			
		// Check if activeChar have no one in target
		else if(activeChar.getTarget() == null)
		{
			activeChar.sendMessage("You can't have any one in your target when Delevel only your self.");
			return false;
		}
		// If activeChar have not any of theis can delevel
		delevelstart(activeChar);
		return true;
	}

public boolean delevelstart(L2PcInstance activeChar)
{
	try
	{
		double actual_hp = activeChar.getCurrentHp();
		double actual_cp = activeChar.getCurrentCp();				
		int max_level = ExperienceData.getInstance().getMaxLevel();				
		// Protections
		Integer returnToLevel = Config.DELEVEL_TO_LEVEL;
		if (returnToLevel < 1)
			returnToLevel = 1;
		if (returnToLevel > max_level)
			returnToLevel = max_level;				
		// Resets character to first class.
		activeChar.setClassId(activeChar.getBaseClass());				
		activeChar.broadcastUserInfo();				
		final byte lvl = Byte.parseByte(returnToLevel + "");				
		final long pXp = activeChar.getStat().getExp();
		final long tXp = ExperienceData.getInstance().getExpForLevel(lvl);		
		if (pXp > tXp)
		{
			activeChar.getStat().removeExpAndSp(pXp - tXp, 0);
		}
		else if (pXp < tXp)
		{
			activeChar.getStat().addExpAndSp(tXp - pXp, 0);
		}
		// Remove the activeChar's current skills.
		for (L2Skill skill : activeChar.getAllSkills())
		{
			activeChar.removeSkill(skill);
		}
		// Give activeChars their eligible skills.
		activeChar.giveAvailableSkills();		
		// restore Hp-Mp-Cp
		activeChar.setCurrentCp(actual_cp);
		activeChar.setCurrentMp(activeChar.getMaxMp());
		activeChar.setCurrentHp(actual_hp);
		activeChar.broadcastStatusUpdate();
		// Updates the activeChar's information in the Character Database.
		activeChar.store();
		// Update skill list
		activeChar.sendSkillList();
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	return true;
}

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

}

Το κανουμε save :) μετα παμε στο αρχειο "voicedcommandhandlers.java" οπου θα ειναι ενας φακελος πισω με το ονομα "handler".

αφου ανοιξουμε το αρχειο "voicedcommandhandlers.java" ψαχουμε να βρουμε που κανει "register" τα voicecommands μας,οταν τα βρουμε παμε στο τελευταιο "register" και βαζουμε αυτες τις 4 γραμουλες

	if (Config.DELEVEL_ENABLE)
	{
		registerVoicedCommandHandler(new DelevelCmd());
	}

Aυτο το κανουμε για να διαβασει ο σερβερ την νεα εντολη "delevel".

Αφου ολοκληρωσουμε αυτο το σημειο κανουμε save...Πανε να βρουμε αλλο ενα αρχειο της java με ονομα Config.Java οπου βρισκεται στο root του σερβερ μας παντα...:/Μολις το βρουμε το ανοιγουμε και προσθετουμε αυτους τους κοδικες οπου θα ειναι τα config του "delevel"

                //============================================================
	public static boolean DELEVEL_ENABLE;
	public static int DELEVEL_MIN_LEVEL;
	public static int DELEVEL_TO_LEVEL;
	//============================================================
	public static void loadDELEVELconfig()
	{
		final String DELEVEL_SYSTEM = FService.DELEVEL_FILE;
		try
		{
			Properties DELEVELSettings = new Properties();
			InputStream is = new FileInputStream(new File(DELEVEL_SYSTEM));
			DELEVELSettings.load(is);
			is.close();

			/** Delevel System **/
			DELEVEL_ENABLE= Boolean.parseBoolean(DELEVELSettings.getProperty("Delevel_Enable","False"));
			DELEVEL_MIN_LEVEL = Integer.parseInt(DELEVELSettings.getProperty("Delevel_Min_Level", "80"));
			DELEVEL_TO_LEVEL = Integer.parseInt(DELEVELSettings.getProperty("Delevel_RETURN_TO_LEVEL", "40"));
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new Error("Failed to Load " + DELEVEL_SYSTEM + " File.");
		}
	}

μολις κανουμε την εισαγωγει παμε τρεμα κατω σχεδω στο αρχειο Config.java ωστε να δηλωσουμε τις μεταβλητες για να μπορει ο σερβερ να τις ανακαλεσει

αυτο θα το κανουμε με την εισαγωγει αυτης της λεξεις "loadDELEVELconfig();" οπου θα την βαλουμε μαζι με τις αλλες :)

		loadChampionConfig();
		loadWeddingConfig();
		loadREBIRTHConfig();
		loadAWAYConfig();
		loadBankingConfig();
		loadPCBPointConfig();
		loadOfflineConfig();
		loadPowerPack();
		loadVoteSystemConfig();
		loadDELEVELconfig(); <-------θα την βαλουμε

Τελος με το Config.Java ας κανουμε ενα save.

Τωρα παμε να δημιουργισουμε το αρχειο delevel.properties και να δηλωσουμε την διαδρομη του ωστε να αλλαζουμε τα config του delevel command

Για αρχη ας παμε στο αρχειο Fservice.java οπου λογικα θα ειναι στον ιδιο φακελο με το Config.java και το ανουγουμε και βαζουμε αυτον τον κοδικα

public static final String DELEVEL_FILE = "./config/fun/delevel.properties";

κανουμε ενα save!!! Εχουμε τελειωσει με τα java files το μονο που μας μενει ειναι να φτιαξουμε το αρχειο "delevel.properties" και ειμαστε ετοιμη...Για αυτο παμε στον φακελο "Server/config/fun/ και εδω θα φτιαξουμε το αρχειο delevel.properties" διοτι συμφωνα με τον πρωηγουμενο κοδικα εδω δηλωνουμε την παρουσια του εσεις μπορειτε να το πατε αλλου αρκει να το δηλωσεται μετα.. αφου το δημιουργησουμε το ανοιγουμε και βαζουμε αυτα μεσα

# ==================================== #
#            Delevel System            #
# ==================================== #

# Enable Delevel system
# If set it true then allow players to use 
# command .delevel to delevel ther levels
Delevel_Enable = false

# Minimum level for Deleve
Delevel_Min_Level = 80

# Return to level? (Default = 40)
Delevel_RETURN_TO_LEVEL = 40

αυτο ηταν κανουμε ενα save και ειμαστε ετοιμη...Δοκιμασμενο στο δικο μου σερβερ...αν σας εχω μπερδεψει ζητω συγνωμη αλλα ειναι το πρωτο μου share και οσο να πουμε εχω λιγο τρακ :P

 

 

Posted

kali prospa9ia file, ala pistevw oti 9a itane kalitera an to ekanes 3erw go .delevel 60 kai na se kanei 60 lvl

 

nvm, ty for share

Posted

Eyxaristo :) polu file m gia ayto exw kanei kai to arxeio delevel.properties gia na to ri9mizoyn apo kei ;) yparxoun polles parages kai ides

  • 3 weeks later...
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • what pack you use  send me on discord for it
    • package custom.events.RandomZoneEvent; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.ScheduledFuture; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.l2jmobius.commons.threads.ThreadPool; import org.l2jmobius.commons.time.SchedulingPattern; import org.l2jmobius.commons.time.TimeUtil; import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.gameserver.managers.ZoneManager; import org.l2jmobius.gameserver.model.StatSet; import org.l2jmobius.gameserver.model.actor.Creature; import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.quest.Event; import org.l2jmobius.gameserver.model.zone.ZoneId; import org.l2jmobius.gameserver.model.zone.ZoneType; import org.l2jmobius.gameserver.model.zone.type.RandomZone; import org.l2jmobius.gameserver.util.Broadcast; /** * Random Zone Event - Activates one random PvP zone temporarily. No modifica la clase de la zona: usa flags PvP en runtime. * @author Juan */ public class RandomZoneEvent extends Event { private static final String CONFIG_FILE = "data/scripts/custom/events/RandomZoneEvent/config.xml"; private static int EVENT_DURATION_MINUTES = 15; private static boolean _isActive = false; private ScheduledFuture<?> _eventTask = null; private final List<ZoneType> _availableZones = new ArrayList<>(); private ZoneType _activeZone = null; public RandomZoneEvent() { loadConfig(); loadZones(); registerZoneListeners(); } /** * Registra listeners a TODAS LAS ZONAS random */ private void registerZoneListeners() { for (ZoneType zone : _availableZones) { addEnterZoneId(zone.getId()); addExitZoneId(zone.getId()); LOGGER.info("[RandomZoneEvent] Registered listener for zone: " + zone.getName()); } } private void loadConfig() { new IXmlReader() { @Override public void load() { parseDatapackFile(CONFIG_FILE); } @Override public void parseDocument(Document doc, File file) { forEach(doc, "event", eventNode -> { final StatSet att = new StatSet(parseAttributes(eventNode)); final String name = att.getString("name"); for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling()) { if ("schedule".equals(node.getNodeName())) { final StatSet attributes = new StatSet(parseAttributes(node)); final String pattern = attributes.getString("pattern"); final SchedulingPattern schedulingPattern = new SchedulingPattern(pattern); final StatSet params = new StatSet(); params.set("Name", name); params.set("SchedulingPattern", pattern); final long delay = schedulingPattern.getDelayToNextFromNow(); getTimers().addTimer("Schedule_" + name, params, delay + 5000, null, null); LOGGER.info("[RandomZoneEvent] Event " + name + " scheduled at " + TimeUtil.getDateTimeString(System.currentTimeMillis() + delay)); } } }); } }.load(); } private void loadZones() { for (ZoneType zone : ZoneManager.getInstance().getAllZones(RandomZone.class)) { if ((zone.getName() != null) && zone.getName().toLowerCase().startsWith("random_zone")) { _availableZones.add(zone); LOGGER.info("[RandomZoneEvent] Loaded zone: " + zone.getName() + " (id=" + zone.getId() + ")"); } } LOGGER.info("[RandomZoneEvent] Total random zones loaded: " + _availableZones.size()); } @Override public void onTimerEvent(String event, StatSet params, Npc npc, Player player) { if (event.startsWith("Schedule_")) { eventStart(null); final SchedulingPattern schedulingPattern = new SchedulingPattern(params.getString("SchedulingPattern")); final long delay = schedulingPattern.getDelayToNextFromNow(); getTimers().addTimer(event, params, delay + 5000, null, null); LOGGER.info("[RandomZoneEvent] Rescheduled for " + TimeUtil.getDateTimeString(System.currentTimeMillis() + delay)); } } @Override public boolean eventStart(Player eventMaker) { if (_isActive) { if (eventMaker != null) { eventMaker.sendMessage("RandomZoneEvent already active."); } return false; } if (_availableZones.isEmpty()) { Broadcast.toAllOnlinePlayers("[RandomZoneEvent] No zones configured."); return false; } _isActive = true; Broadcast.toAllOnlinePlayers("⚔️ Random Zone Event has started!"); _eventTask = ThreadPool.schedule(this::activateRandomZone, 5_000); return true; } private void activateRandomZone() { _activeZone = _availableZones.get(new Random().nextInt(_availableZones.size())); _activeZone.setEnabled(true); Broadcast.toAllOnlinePlayers("🔥 Random Zone Event: " + _activeZone.getName() + " is now PvP for " + EVENT_DURATION_MINUTES + " minutes!"); _eventTask = ThreadPool.schedule(this::eventStop, EVENT_DURATION_MINUTES * 60 * 1000L); } @Override public boolean eventStop() { if (!_isActive) { return false; } _isActive = false; if (_eventTask != null) { _eventTask.cancel(true); _eventTask = null; } if (_activeZone != null) { _activeZone.setEnabled(false); Broadcast.toAllOnlinePlayers("🏁 Random Zone Event ended. " + _activeZone.getName() + " is back to normal."); _activeZone = null; } else { Broadcast.toAllOnlinePlayers("🏁 Random Zone Event ended."); } return true; } @Override public void onEnterZone(Creature creature, ZoneType zone) { if (!_isActive || (_activeZone == null)) { return; } if ((zone == _activeZone) && creature.isPlayable()) { creature.setInsideZone(ZoneId.PVP, true); if (creature.isPlayer()) { creature.sendMessage("Esta zona está en modo PvP temporalmente."); } } } @Override public void onExitZone(Creature creature, ZoneType zone) { if (!_isActive || (_activeZone == null)) { return; } if ((zone == _activeZone) && creature.isPlayable()) { creature.setInsideZone(ZoneId.PVP, false); if (creature.isPlayer()) { creature.sendMessage("Abandonaste la zona PvP temporal."); } } } @Override public boolean eventBypass(Player player, String bypass) { return true; } @Override public String onEvent(String event, Npc npc, Player player) { return super.onEvent(event, npc, player); } @Override public String onFirstTalk(Npc npc, Player player) { return null; } public static void main(String[] args) { new RandomZoneEvent(); } } i have this but its not working
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock