Jump to content
  • 0

java 7 to java 8


Question

Posted

Hi guys , i'm trying to change this java code from java 7 to java 8 

 

who can help me please change it .

 

i want change it  , for L2RO-TEAM source

 

/*
 * 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 com.l2jserver.gameserver.network.serverpackets;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.ArabicUtilities;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.NpcStringId;
import com.l2jserver.gameserver.network.SystemMessageId;

/**
 * This class ...
 *
 * @version $Revision: 1.4.2.1.2.3 $ $Date: 2005/03/27 15:29:57 $
 */
public final class CreatureSay extends L2GameServerPacket
{
	// ddSS
	private static final String _S__4A_CREATURESAY = "[S] 4A CreatureSay";
	private int _objectId;
	private int _textType;
	private String _charName = null;
	private int _charId = 0;
	private String _text = null;
	private int _npcString = -1;
	private List<String> _parameters;
	
	/**
	 * @param objectId
	 * @param messageType
	 * @param charName
	 * @param text
	 */
	public CreatureSay(int objectId, int messageType, String charName, String text)
	{
		_objectId = objectId;
		_textType = messageType;
		_charName = charName;
		_text = text;
	}
	
	public CreatureSay(int objectId, int messageType, int charId, NpcStringId npcString)
	{
		_objectId = objectId;
		_textType = messageType;
		_charId = charId;
		_npcString = npcString.getId();
	}
	
	public CreatureSay(int objectId, int messageType, String charName, NpcStringId npcString)
	{
		_objectId = objectId;
		_textType = messageType;
		_charName = charName;
		_npcString = npcString.getId();
	}
	
	public CreatureSay(int objectId, int messageType, int charId, SystemMessageId sysString)
	{
		_objectId = objectId;
		_textType = messageType;
		_charId = charId;
		_npcString = sysString.getId();
	}
	
	/**
	 * String parameter for argument S1,S2,.. in npcstring-e.dat
	 * @param text
	 */
	public void addStringParameter(String text)
	{
		if (_parameters == null)
			_parameters = new ArrayList<>();
		_parameters.add(text);
	}
	
	@Override
	protected final void writeImpl()
	{
		writeC(0x4a);
		writeD(_objectId);
		writeD(_textType);
		if (_charName != null)
			writeS(_charName);
		else
			writeD(_charId);
		writeD(_npcString); // High Five NPCString ID
		if (_text != null)
		{//only edit this
			if (ArabicUtilities.hasArabicLetters(_text))
			{
				String ttext = ArabicUtilities.reshapeSentence(_text);
				writeS(ttext);
			}
			else
			{
				writeS(_text);
			}
		}//only edit this
		else
		{
			if (_parameters != null)
			{
				for (String s : _parameters)
					writeS(s);
			}
		}

	}
	
	@Override
	public final void runImpl()
	{
		L2PcInstance _pci = getClient().getActiveChar();
		if (_pci != null)
		{
			_pci.broadcastSnoop(_textType,_charName,_text);
		}
	}
	
	@Override
	public String getType()
	{
		return _S__4A_CREATURESAY;
	}
}

 

7 answers to this question

Recommended Posts

  • 0
Posted
2 hours ago, Nightw0lf said:

//only edit this

ok i've seen everything


ArabicUtilities

 

do you want ArabicUilities code ? 

 

 


/*
 * 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 com.l2jserver;

import java.util.ArrayList;
import java.util.List;

public class ArabicUtilities {

    /**
* the path of teh fonts file must be under assets folder
*/

/**
* Helper function is to check if the character passed, is Arabic
* @param target The Character to check Against
* @return true if the Character is Arabic letter, otherwise returns false
*/
private static boolean isArabicCharacter(char target){

//Iterate over the 36 Characters in ARABIC_GLPHIES Matrix
for(int i = 0; i < ArabicReshaper.ARABIC_GLPHIES.length;i++){
//Check if the target Character exist in ARABIC_GLPHIES Matrix
if(ArabicReshaper.ARABIC_GLPHIES[i][0]==target)
return true;
}

           for(int i = 0; i < ArabicReshaper.HARAKATE.length;i++){
//Check if the target Character exist in ARABIC_GLPHIES Matrix
if(ArabicReshaper.HARAKATE[i]==target)
return true;
}

return false;
}

/**
* Helper function to split Sentence By Space
* @param sentence the Sentence to Split into Array of Words
* @return Array Of words
*/
private static String[] getWords(String sentence){
if (sentence != null) {
return sentence.split("\\s");
}
return new String[0];
}

/**
* Helper function to check if the word has Arabic Letters
* @param word The to check Against
* @return true if the word has Arabic letters, false otherwise
*/
public static boolean hasArabicLetters(String word){

//Iterate over the word to check all the word's letters
for(int i=0;i<word.length();i++){

if(isArabicCharacter(word.charAt(i)))
return true;
}
return false;
}

/**
* Helper function to check if the word is all Arabic Word
* @param word The word to check against
* @return true if the word is Arabic Word, false otherwise
*/
public static boolean isArabicWord(String word){
//Iterate over the Word
for(int i=0;i<word.length();i++){
if(!isArabicCharacter(word.charAt(i)))
return false;
}
return true;
}

/**
* Helper function to split the Mixed Word into words with only Arabic, and English Words
* @param word The Mixed Word
* @return The Array of the Words of each Word may exist inside that word
*/
private static String[] getWordsFromMixedWord(String word){

//The return result of words
List<String> finalWords = new ArrayList<>();

//Temp word to hold the current word
String tempWord="";

//Iterate over the Word Length
for(int i=0;i<word.length();i++){

//Check if the Character is Arabic Character
if(isArabicCharacter(word.charAt(i))){

//Check if the tempWord is not empty, and what left in tempWord is not Arabic Word
if(!tempWord.equals("") && !isArabicWord(tempWord)) {

//add the Word into the Array
finalWords.add(tempWord);

//initiate the tempWord again
tempWord=""+word.charAt(i);

}else{

//Not to add the tempWord, but to add the character to the rest of the characters
tempWord+=word.charAt(i);
}

}else{

//Check if the tempWord is not empty, and what left in tempWord is Arabic Word
if(!tempWord.equals("") && isArabicWord(tempWord)){

//add the Word into the Array
finalWords.add(tempWord);

//initiate the tempWord again
tempWord=""+word.charAt(i);

}else{

//Not to add the tempWord, but to add the character to the rest of the characters
tempWord+=word.charAt(i);
}
}
}

//add remaining tempWord to finalWords
if (!tempWord.equals("")) {
finalWords.add(tempWord);
}

String[] theWords=new String[finalWords.size()];
theWords=finalWords.toArray(theWords);

return theWords;
}

public static String reshape(String allText) {
if (allText != null) {
StringBuffer result = new StringBuffer();
String[] sentences = allText.split("\n");
for (int i = 0; i < sentences.length; i++) {
result.append(reshapeSentence(sentences[i]));
//don't append the line feed to the final sentence
if (i < sentences.length - 1) {
result.append("\n");
}
}
return result.toString();
}
return null;

}
/**
* The Main Reshaping Function to be Used in Android Program
 * @param sentence 
* @return the Reshaped Text
*/
public static String reshapeSentence(String sentence){
//get the Words from the Text
String[] words=getWords(sentence);

//prepare the Reshaped Text
StringBuffer reshapedText=new StringBuffer("");

//Iterate over the Words
for(int i=words.length-1;i>=0;i--){

//Check if the Word has Arabic Letters
if(hasArabicLetters(words[i])){

//Check if the Whole word is Arabic
if(isArabicWord(words[i])){

//Initiate the ArabicReshaper functionality
ArabicReshaper arabicReshaper = new ArabicReshaper(words[i]);


//Append the Reshaped Arabic Word to the Reshaped Whole Text
String initial = arabicReshaper.getReshapedWord();
StringBuffer text = new StringBuffer(initial);
text = text.reverse();
initial = text.toString();
reshapedText.append(initial);
}else{ //The word has Arabic Letters, but its not an Arabic Word, its a mixed word

//Extract words from the words (split Arabic, and English)
String [] mixedWords=getWordsFromMixedWord(words[i]);

//iterate over mixed Words
for(int j=0;j<mixedWords.length;j++){

//Initiate the ArabicReshaper functionality
ArabicReshaper arabicReshaper=new ArabicReshaper(mixedWords[j]);

//Append the Reshaped Arabic Word to the Reshaped Whole Text
reshapedText.append(arabicReshaper.getReshapedWord());
}
}	
}else{//The word doesn't have any Arabic Letters

//Just append the word to the whole reshaped Text
reshapedText.append(words[i]);
}

//Append the space to separate between words
reshapedText.append(" ");
}

//return the final reshaped whole text
return reshapedText.toString();
}

}

  • 0
Posted

What are you trying to do here? As @Tryskell have already mentioned, there is nothing you can do here to convert your code to Java 8...Which means, the java 7 code would be equal to the Java 8 code. You could maybe use streams in ArabicUtilities class, but you don't have to.

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
Answer this question...

×   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.



  • Posts

    • Hello everyone I'm Albert, Starting now with the dream on have a L2 server, I'm having several issues with RS and I need someone help to Create an skill and implement to the correct class ID and make it work. Skill Required from me is  Festival Sweep  Skill or Item with the ability. I really need help guys and then after if possible i would need NPC and skins with .dressme        
    • Changeset 410 (3371)   Makers, NpcAi / Desires, Cursed Weapon rework, Bugfixes, Admincommands, Movement, Organization   Makers Fix ghost corpses. Introduce task manager for MultiSpawn spawn schedule. Introduce task managers for Npc respawn and despawn tasks. Add missing random treasurebox maker. NpcAi / Desires AttackableAttack > NpcAttack, allowing ATTACK_FINISHED event over Npc. Merge all reduceWeight from NpcAI operations. Don't broadcast MoveToPawn packet for cast hold scenarii. CH and CP managers use hold cast. Probably way more to add. Rework DesireQueue#addOrUpdate to avoid to generate a List. Drop _isInHitAnimation, avoid twice runAI calls upon attack end animation, save a ThreadPool. Implement Desire#isInvalid, used over the main loop to clean invalid Desires. All sided getDesires().removeIf are dropped, notably over AggroList/HateList. Cursed Weapon rework Fix potential task scheduling issues, reworking the whole layers. Reduce code by 1/3. Use L2OFF formulas/data for item drop rate, staging process. CW end duration now decreases when killing other Players. Bugfixes Revert schedule part from ThreadPool. Fix Pet inventory IU. Ty Denzel for the report. Fix Pet item timestamp reuse delay. Ty artemis for the fix. Disable automatic beastshots when his owner dies. Ty Root for the report. Player cannot craft while casting a skill, nor trade. Ty Root for the report. Add missing weight checks for player/summon pickup, and player craft. Ty Root for the report. Implement /graduatelist command, which displays a list of clan academy graduates for the past week. Ty RooT for the report. Fix PLAYING_FOR_LONG_TIME concept ; rest message is server related, not Player related. Ty RooT for the report. Player should stop movement when opening store. Fix Q351 occurences of itemId 4310 by 4407 one + slight fix. Fix Q365 missing memoState + poison skillId. Ty Root for the report. Fix Q417 Torai despawn over cond 11. Fix Q216 4 missing npcIds. Ty Karudin for the report. Fix the invalid comment of DeleteCharAfterDays Config. Fix NPC drop penalty level calculation. Ty Bandnentans for the report. Items are now dropped in a 30/45 donut shape around dropper. Ty Bandnentans for the report. PartyMatch fixes Don't show Party members or CW holder as available waiting members. You can't show overall List or join a PartyMatch room as CW holder. CW owner, upon acquisition, leave PartyMatch system. PartyMatch window is now automatically closed upon Player#removeMeFromPartyMatch. Remove Player from PartyMatch if Player and newly joined Party leader PartyMatch rooms differ. You can't join or be invited in a PartyMatch room if already partying/CW holding. Fix ShowLicence config when set to false. Ty artemis for the fix. Fix maximum number of macros. Ty artemis for the fix. Fix invalid IU update over //enchant. Ty artemis for the fix. Fix Castle Mass Gatekeeper HTMs. Ty kingNik0n for the fix. Drop _disabledItems implementation. Won't be used by next refactors. Ty artemis for the report. Fix loading handlers under debug. Ty Keku for the fix. Fix character_macroses table structure (commands = 12x32 chars minimum). Admincommands Merge all old spawn admincommands (//list_spawns, //spawn, //unspawnall, //respawnall, //delete) to //spawn and //unspawn (previously //delete). Generate //help. //unspawn works over all ASpawn. Merge all old fence admincommands (//spawnfence, //deletefence, //listfence) to //fence [add|remove], generate AdminFence. They now use proper Pagination. You can also teleport to it. Implementation of //show manor. Implementation of //set quest <id> [cond]. Related items must be hand-given. Implementation of //set henna [page] [add|remove symbolId]. The hennas are still bound to game logic (slots, canBeUsedBy). Movement - Ty LaRoja, Bandnentans Fix Boats IOOBE. Adapt getHeight logic from L2OFF. Introduce back WASD movement, handle boat board/unboard. Fix WATER/FLY movement logic. Avoid to pathfind diagonal cells with detected obstacle. Organization Addition of QuestVars class, holding all related variables from quests (itemIds, npcIds, questNames, sounds, etc), allowing to reduce length of each script while reusing variables. 100+ cloned variables were deleted. Refactor geometry package and Territory. Territory is now a unique 3D shape, holding any type of 2D geometry.  Remove few useless Location#clone uses. Implementation of ItemContainer#forEachItem. Clean many unused FrequentSkill. The whole enum is questionable. Drop MathUtil#checkIfInRange, implement WorldObject#isInStrictRadius (involve collision of that WorldObject, and potential WorldObject parameter). WorldObject#isIn2DRadius parameter is now a Point2D, not a Location (since a Location inherits Point2D, Location are still usable as parameter). Rework Pagination#generatePages to handle page number > 1000. Use Pagination over Tryskell SchemeBuffer. Ty CUCU23 for the share.
    • It's a custom instance used as Event not retail - like. You can re-create it easily.
    • GRAND OPENING TODAY !!! FROM - 16/05/2025, FRIDAY, 20:00 +3 GMT !
  • Topics

×
×
  • Create New...