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.



×
×
  • Create New...