diff --git a/README.md b/README.md index 2b797b2..6aa1aeb 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,16 @@ -# MinecraftPEServer -An Android application which enables you to run Genisys or Nukkit on your phone! +# Pocket Server +An Android application which enables you to run PocketMine or Nukkit on your phone! -# Introduction -Although some codes come from PocketMine-Android, most of them have been rewritten! +# Download +You can download from the [Google Play](https://play.google.com/store/apps/details?id=net.fengberd.minecraftpe_server) or [Releases Page](https://github.com/fengberd/PocketServer/releases) # Usage -Genisys = Install App -> Press Install PHP -> Press Download & Install PHP7 -> Press Download Server, then press iTX-Genisys -> Check PocketMine at Server Type -> Press Start Server +PocketMine = Install App -> Install PHP -> Check PocketMine at Server Type -> Press Download Server, then choose server you want to use-> Press Start Server -Nukkit = Install App -> Rooting -> Put Nukkit.jar to /sdcard/Nukkit -> Check Nukkit at Server Type -> Install Java -> Press Download Server, then press anything -> Press Java Library(ROOT), if you use KingRoot, you check Use ku.sud to request root -> Start Server +Nukkit = Rooting -> Install App -> Install Java -> Check Nukkit at Server Type -> Press Mount Java Library(ROOT), if you use KingRoot, you check Use ku.sud in to request root in Settings -> Press Start Server # About JRE You can get "nukkit_library.tar.gz" from Here -# Download -You can download at the Google Play - # LICENSE GPLv3 (GNU Public License version 3) diff --git a/app/build.gradle b/app/build.gradle index 43846d9..2526443 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "net.fengberd.minecraftpe_server" minSdkVersion 14 targetSdkVersion 21 - versionCode 1080 - versionName "1.0.8.0" + versionCode 1090 + versionName "1.0.9.0" vectorDrawables.useSupportLibrary = true } diff --git a/app/src/main/assets/urls.json b/app/src/main/assets/urls.json index 3bf857a..a5edd59 100644 --- a/app/src/main/assets/urls.json +++ b/app/src/main/assets/urls.json @@ -6,8 +6,8 @@ "ZXDA|https://jenkins.zxda.net/job/Nukkit/" ], "pocketmine": [ + "[Suggested]GenisysPro (ZXDA)|https://jenkins.zxda.net/job/GenisysPro/", "Tesseract (ZXDA)|https://jenkins.zxda.net/job/Tesseract/", - "GenisysPro (ZXDA)|https://jenkins.zxda.net/job/GenisysPro/", "PocketMine-MP-PMMP (pmmp/x64)|https://jenkins.pmmp.gq/job/PocketMine-MP/", "PocketMine-MP-PMMP (ZXDA/x64)|https://jenkins.zxda.net/job/PocketMine-MP/", "[Abandoned]BlueLight (ZXDA)|https://jenkins.zxda.net/job/BlueLight/", diff --git a/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java b/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java index 9bc103e..7ef5ad8 100644 --- a/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java +++ b/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java @@ -1,6 +1,5 @@ package moe.berd.pocket_server.activity; -import android.annotation.*; import android.app.*; import android.content.*; import android.net.*; @@ -14,27 +13,22 @@ import java.io.*; import java.net.*; -import java.security.cert.*; - -import javax.net.ssl.*; import moe.berd.pocket_server.exception.*; import moe.berd.pocket_server.fragment.*; import moe.berd.pocket_server.service.*; import moe.berd.pocket_server.utils.*; -public class MainActivity extends Activity implements Handler.Callback, View.OnClickListener +public class MainActivity extends Activity implements Handler.Callback { public static Handler actionHandler=null; public final static int ACTION_STOP_SERVICE=1; - public final static int CHOOSE_PHP_CODE=1; + public final static int CHOOSE_PHP_CODE=1, CHOOSE_JAVA_CODE=2; public static Intent serverIntent=null; - public static boolean isStarted=false, nukkitMode=false, ansiMode=false; - - public static String[] jenkins_nukkit, jenkins_pocketmine; + public static boolean nukkitMode=false, ansiMode=false; public static void postMessage(int arg1,int arg2,Object obj) { @@ -48,9 +42,9 @@ public static void postMessage(int arg1,int arg2,Object obj) } } - static + public static void postStopService() { - StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); + postMessage(ACTION_STOP_SERVICE,0,null); } public Fragment currentFragment=null; @@ -65,6 +59,7 @@ public void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_main); ConfigProvider.init(getSharedPreferences("config",0)); + ansiMode=ConfigProvider.getBoolean("ANSIMode",nukkitMode); nukkitMode=ConfigProvider.getBoolean("NukkitMode",nukkitMode); ServerUtils.init(this); @@ -84,83 +79,29 @@ public void onCreate(Bundle savedInstanceState) actionHandler=new Handler(this); serverIntent=new Intent(this,ServerService.class); - switchFragment(fragment_main); - - reloadUrls(); - /* - config=getSharedPreferences("config",0); - ansiMode=config.getBoolean("ANSIMode",ansiMode); - nukkitMode=config.getBoolean("NukkitMode",nukkitMode); - - button_stop=(Button)findViewById(R.id.button_stop); - button_stop.setOnClickListener(this); - button_start=(Button)findViewById(R.id.button_start); - button_start.setOnClickListener(this); - findViewById(R.id.button_mount).setOnClickListener(this); - - check_ansi=(CheckBox)findViewById(R.id.check_ansi); - check_ansi.setOnClickListener(this); - check_kusud=(CheckBox)findViewById(R.id.check_kusud); - check_kusud.setOnClickListener(this); - - radio_nukkit=(RadioButton)findViewById(R.id.radio_nukkit); - radio_nukkit.setOnClickListener(this); - radio_pocketmine=(RadioButton)findViewById(R.id.radio_pocketmine); - radio_pocketmine.setOnClickListener(this); - - seekbar_fontsize=(SeekBar)findViewById(R.id.seekbar_fontsize); - seekbar_fontsize.setProgress(config.getInt("ConsoleFontSize",16)); - seekbar_fontsize.setMax(30); - seekbar_fontsize.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() - { - @Override - public void onProgressChanged(SeekBar p1,int p2,boolean p3) - { - - } - - @Override - public void onStartTrackingTouch(SeekBar p1) - { - - } - - @Override - public void onStopTrackingTouch(SeekBar p1) - { - // todo: write config - config.edit().putInt("ConsoleFontSize",p1.getProgress()).apply(); - } - }); - - check_ansi.setChecked(ansiMode); - check_kusud.setChecked(config.getBoolean("KusudMode",false)); - - radio_nukkit.setChecked(nukkitMode); - radio_pocketmine.setChecked(!nukkitMode); - - ServerUtils.init(this); - - reloadUrls(); - refreshEnabled(); - */ + switchFragment(fragment_main,R.string.activity_main); } @Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { + if(requestCode!=CHOOSE_PHP_CODE && requestCode!=CHOOSE_JAVA_CODE) + { + super.onActivityResult(requestCode,resultCode,data); + return; + } + if(data==null) + { + return; + } + final Uri choose=data.getData(); + final ProgressDialog processing_dialog=new ProgressDialog(this); + processing_dialog.setCancelable(false); + processing_dialog.setMessage(getString(R.string.message_installing)); + processing_dialog.show(); switch(requestCode) { case CHOOSE_PHP_CODE: - if(data==null) - { - return; - } - final Uri choosed=data.getData(); - final ProgressDialog processing_dialog=new ProgressDialog(this); - processing_dialog.setCancelable(false); - processing_dialog.setMessage(getString(R.string.message_installing)); - processing_dialog.show(); new Thread(new Runnable() { public void run() @@ -169,17 +110,7 @@ public void run() { File inside=new File(ServerUtils.getAppDirectory(),"php"); inside.delete(); - OutputStream os=new FileOutputStream(inside); - InputStream is=getContentResolver().openInputStream(choosed); - assert is!=null; - int cou=0; - byte[] buffer=new byte[8192]; - while((cou=is.read(buffer))!=-1) - { - os.write(buffer,0,cou); - } - is.close(); - os.close(); + ServerUtils.copyStream(getContentResolver().openInputStream(choose),new FileOutputStream(inside)); runOnUiThread(new Runnable() { public void run() @@ -205,96 +136,108 @@ public void run() } }).start(); break; - default: - super.onActivityResult(requestCode,resultCode,data); + case CHOOSE_JAVA_CODE: + new Thread(new Runnable() + { + public void run() + { + try + { + File inside=new File(ServerUtils.getAppDirectory() + "/java/nukkit_library.tar.gz"); + inside.delete(); + inside.getParentFile().mkdirs(); + ServerUtils.copyStream(getContentResolver().openInputStream(choose),new FileOutputStream(inside)); + Runtime.getRuntime() + .exec("../busybox tar zxf nukkit_library.tar.gz",new String[0],new File(ServerUtils + .getAppDirectory() + "/java")) + .waitFor(); + inside.delete(); + toast(R.string.message_install_success); + } + catch(Exception e) + { + toast(getString(R.string.message_install_fail) + "\n" + e.toString()); + } + runOnUiThread(new Runnable() + { + public void run() + { + processing_dialog.dismiss(); + } + }); + } + }).start(); break; } } - /* - @Override - public boolean onCreateOptionsMenu(Menu menu) - { - getMenuInflater().inflate(R.menu.main,menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) - { - menu.findItem(R.id.menu_install_php).setEnabled(!isStarted); - menu.findItem(R.id.menu_install_php_manually).setEnabled(!isStarted); - menu.findItem(R.id.menu_install_java).setEnabled(!isStarted); - menu.findItem(R.id.menu_download_server).setEnabled(!isStarted); - return true; - } - */ @Override - public boolean handleMessage(Message msg) + public boolean onOptionsItemSelected(MenuItem item) { - switch(msg.arg1) + switch(item.getItemId()) { - case ACTION_STOP_SERVICE: + case R.id.menu_kill: + ServerUtils.killServer(); stopService(serverIntent); fragment_main.refreshEnabled(); break; + default: + return super.onOptionsItemSelected(item); } - return false; + return true; } @Override - public void onClick(View v) + public void onBackPressed() { - switch(v.getId()) + if(currentFragment!=null && (currentFragment instanceof ConsoleFragment || currentFragment instanceof SettingsFragment)) { - /* - case R.id.check_ansi: - ansiMode=check_ansi.isChecked(); - config.edit().putBoolean("ANSIMode",ansiMode).apply(); - break; - case R.id.check_kusud: - config.edit().putBoolean("KusudMode",check_kusud.isChecked()).apply(); - break; - */ - default: + switchFragment(fragment_main,R.string.activity_main); return; } + super.onBackPressed(); } @Override - public boolean onOptionsItemSelected(MenuItem item) + public boolean handleMessage(Message msg) { - switch(item.getItemId()) + switch(msg.arg1) { - case R.id.menu_kill: - ServerUtils.killServer(); + case ACTION_STOP_SERVICE: stopService(serverIntent); fragment_main.refreshEnabled(); break; default: - return super.onOptionsItemSelected(item); + return false; } return true; } - @Override - public void onBackPressed() + public void toast(int text) { - if(currentFragment!=null && (currentFragment instanceof ConsoleFragment || currentFragment instanceof SettingsFragment)) + toast(getString(text)); + } + + public void toast(final String text) + { + final MainActivity instance=this; + runOnUiThread(new Runnable() { - switchFragment(fragment_main); - return; - } - super.onBackPressed(); + public void run() + { + Toast.makeText(instance,text,Toast.LENGTH_SHORT).show(); + } + }); } - public void switchFragment(Fragment target) + public void switchFragment(Fragment target,int title) { getFragmentManager().beginTransaction() .setCustomAnimations(R.animator.enter,R.animator.exit) .replace(R.id.layout_main,target) .commit(); currentFragment=target; + setTitle(title); } public void chooseFile(int code,String title) @@ -324,88 +267,97 @@ public void chooseFile(int code,String title) } } - public String getInternetString(String url) + public void downloadFile(String url,File saveTo,final ProgressDialog dialog) { + OutputStream output=null; + InputStream input=null; try { - BufferedReader reader=new BufferedReader(new InputStreamReader(openNetConnection(url).getInputStream())); - StringBuilder sb=new StringBuilder(); - String line=null; - while((line=reader.readLine())!=null) + if(saveTo.exists()) { - sb.append(line).append('\r'); + saveTo.delete(); } - reader.close(); - return sb.toString(); + URLConnection connection=ServerUtils.openNetConnection(url); + input=new BufferedInputStream(connection.getInputStream()); + output=new FileOutputStream(saveTo); + int count=0; + long read=0; + if(dialog!=null) + { + final long max=connection.getContentLength(); + runOnUiThread(new Runnable() + { + public void run() + { + dialog.setMax((int)max / 1024); + } + }); + } + byte[] buffer=new byte[4096]; + while((count=input.read(buffer))>=0) + { + output.write(buffer,0,count); + read+=count; + if(dialog!=null) + { + final int temp=(int)(read / 1000); + runOnUiThread(new Runnable() + { + public void run() + { + dialog.setProgress(temp); + } + }); + } + } + output.close(); + input.close(); + toast(R.string.message_done); } catch(Exception e) { - toast(e.toString()); + toast(e.getMessage()); } - return null; - } - - public void toast(int text) - { - toast(getString(text)); - } - - public void toast(final String text) - { - final MainActivity instance=this; - runOnUiThread(new Runnable() + finally { - public void run() + try { - Toast.makeText(instance,text,Toast.LENGTH_SHORT).show(); + if(output!=null) + { + output.close(); + } + if(input!=null) + { + input.close(); + } } - }); + catch(Exception ignored) + { + + } + } } - public void reloadUrls() + public String getInternetString(String url) { try { - File jfile=new File(getFilesDir(),"urls.json"); - if(!jfile.exists()) - { - copyAsset("urls.json",jfile); - } - FileInputStream fis=new FileInputStream(jfile); - byte[] data=new byte[(int)jfile.length()]; - fis.read(data); - fis.close(); - if(data.length<2) - { - jfile.delete(); - reloadUrls(); - return; - } - JSONObject json=new JSONObject(new String(data,"UTF-8")); - JSONObject jenkins=json.getJSONObject("jenkins"); + BufferedReader reader=new BufferedReader(new InputStreamReader(ServerUtils.openNetConnection(url) + .getInputStream())); + StringBuilder sb=new StringBuilder(); + String line=null; + while((line=reader.readLine())!=null) { - JSONArray nukkit=jenkins.getJSONArray("nukkit"); - { - jenkins_nukkit=new String[nukkit.length()]; - for(int i=0;i1) + { + // F**k PMMP + for(int i=0;i=0) - { - output.write(buffer,0,count); - read+=count; - if(dialog!=null) - { - final int temp=(int)(read / 1000); - runOnUiThread(new Runnable() - { - public void run() - { - dialog.setProgress(temp); - } - }); - } - } - output.close(); - input.close(); - toast(R.string.message_done); - } - catch(Exception e) - { - toast(e.getMessage()); - } - finally - { - try - { - if(output!=null) - { - output.close(); - } - if(input!=null) - { - input.close(); - } - } - catch(Exception ignored) - { - - } - } - } } diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java index c289266..05a2bea 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java @@ -3,8 +3,8 @@ import android.app.*; import android.content.*; import android.os.*; -import android.support.annotation.*; import android.text.*; +import android.util.*; import android.view.*; import android.widget.*; @@ -13,23 +13,22 @@ import moe.berd.pocket_server.activity.*; import moe.berd.pocket_server.utils.*; -import static moe.berd.pocket_server.activity.MainActivity.ansiMode; +import static moe.berd.pocket_server.activity.MainActivity.*; public class ConsoleFragment extends Fragment implements Handler.Callback { public MainActivity main=null; - private static final int MESSAGE_APPEND=1, MESSAGE_TITLE=2, MESSAGE_UPDATE_LINE=3; + private static final int MESSAGE_APPEND=1, MESSAGE_UPDATE_LINE=2; public static Handler logUpdateHandler=null; + public static CharSequence currentLine=""; + public static SpannableStringBuilder currentLog=new SpannableStringBuilder(); - public ScrollView scroll_log=null; public Button button_command=null; public TextView label_log=null, label_current=null; public EditText edit_command=null; - - public static CharSequence currentLine=""; - public static SpannableStringBuilder currentLog=new SpannableStringBuilder(); + public ScrollView scroll_log=null; public ConsoleFragment() { @@ -53,6 +52,7 @@ public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setHasOptionsMenu(true); } + @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { @@ -60,9 +60,8 @@ public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle save } @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) + public void onStart() { - super.onActivityCreated(savedInstanceState); logUpdateHandler=new Handler(this); label_log=(TextView)main.findViewById(R.id.label_log); @@ -93,15 +92,25 @@ public void onClick(View arg0) }); label_log.setTextSize(ConfigProvider.getInt("ConsoleFontSize",16)); + label_current.setTextSize(ConfigProvider.getInt("ConsoleFontSize",16)); postAppend(currentLog); + + super.onStart(); + } + + @Override + public void onStop() + { + logUpdateHandler=null; + super.onStop(); } @Override public void onCreateOptionsMenu(Menu menu,MenuInflater inflater) { super.onCreateOptionsMenu(menu,inflater); - inflater.inflate(R.menu.main,menu); + inflater.inflate(R.menu.console,menu); } @Override @@ -133,18 +142,21 @@ public boolean handleMessage(Message msg) { case MESSAGE_APPEND: label_log.append((CharSequence)msg.obj); - scroll_log.fullScroll(ScrollView.FOCUS_DOWN); - break; - case MESSAGE_TITLE: - //setTitle((CharSequence)msg.obj); + scrollToBottom(); break; case MESSAGE_UPDATE_LINE: - label_current.setText((CharSequence)msg.obj); + label_current.setText(currentLine); break; } return true; } + public void scrollToBottom() + { + scroll_log.smoothScrollBy(0,scroll_log.getChildAt(scroll_log.getChildCount() - 1) + .getBottom() + scroll_log.getPaddingBottom() - scroll_log.getScrollY() - scroll_log.getHeight()); + } + private void sendCommand() { log("> " + edit_command.getText()); @@ -152,19 +164,6 @@ private void sendCommand() edit_command.setText(""); } - public static boolean postTitle(CharSequence data) - { - if(logUpdateHandler!=null) - { - Message msg=new Message(); - msg.arg1=MESSAGE_TITLE; - msg.obj=data; - logUpdateHandler.sendMessage(msg); - return true; - } - return false; - } - public static boolean postAppend(CharSequence data) { if(logUpdateHandler!=null) @@ -178,13 +177,12 @@ public static boolean postAppend(CharSequence data) return false; } - public static boolean postNewLine(CharSequence data) + public static boolean postNewLine() { if(logUpdateHandler!=null) { Message msg=new Message(); msg.arg1=MESSAGE_UPDATE_LINE; - msg.obj=data; logUpdateHandler.sendMessage(msg); return true; } @@ -193,6 +191,12 @@ public static boolean postNewLine(CharSequence data) public static void log(String line) { + if(!currentLine.equals("")) + { + currentLog.append(ansiMode ? Html.fromHtml("
") : "\n").append(currentLine); + postAppend(ansiMode ? Html.fromHtml("
") : "\n"); + postAppend(currentLine); + } if(ansiMode) { int index=0; @@ -200,21 +204,16 @@ public static void log(String line) { line=line.substring(index + 4); } + long timeSpan=System.currentTimeMillis(); line=TerminalColorConverter.control2html(line.replace("&","&") .replace("<","<") .replace(">",">") .replace(" "," ") .replace("\u001b[1G","") .replace("\u001b[K","")); - } - if(!currentLine.equals("")) - { - currentLog.append(ansiMode ? Html.fromHtml("
") : "\n"); - postAppend(ansiMode ? Html.fromHtml("
") : "\n"); - currentLog.append(currentLine); - postAppend(currentLine); + Log.d("Parse Time",(System.currentTimeMillis() - timeSpan) + "ms"); } currentLine=ansiMode ? Html.fromHtml(line) : line; - postNewLine(currentLine); + postNewLine(); } } diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java index 866aad5..912bb9d 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java @@ -8,10 +8,11 @@ import net.fengberd.minecraftpe_server.*; +import org.json.*; + import java.io.*; import moe.berd.pocket_server.activity.*; -import moe.berd.pocket_server.exception.*; import moe.berd.pocket_server.utils.*; import static moe.berd.pocket_server.activity.MainActivity.*; @@ -20,6 +21,8 @@ public class MainFragment extends Fragment implements View.OnClickListener { public MainActivity main=null; + public String[] jenkins_nukkit, jenkins_pocketmine; + public Button button_start=null, button_stop=null, button_mount=null; public RadioButton radio_pocketmine=null, radio_nukkit=null; @@ -53,10 +56,8 @@ public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle save } @Override - public void onActivityCreated(Bundle savedInstanceState) + public void onStart() { - super.onActivityCreated(savedInstanceState); - button_stop=(Button)main.findViewById(R.id.button_stop); button_stop.setOnClickListener(this); button_start=(Button)main.findViewById(R.id.button_start); @@ -71,7 +72,10 @@ public void onActivityCreated(Bundle savedInstanceState) radio_pocketmine.setChecked(!nukkitMode); radio_pocketmine.setOnClickListener(this); + reloadUrls(); refreshEnabled(); + + super.onStart(); } @Override @@ -85,9 +89,6 @@ public void onCreateOptionsMenu(Menu menu,MenuInflater inflater) public void onPrepareOptionsMenu(Menu menu) { boolean running=ServerUtils.isRunning(); - menu.findItem(R.id.menu_install_php).setEnabled(!running); - menu.findItem(R.id.menu_install_php_manually).setEnabled(!running); - menu.findItem(R.id.menu_install_java).setEnabled(!running); menu.findItem(R.id.menu_download_server).setEnabled(!running); } @@ -98,113 +99,11 @@ public boolean onOptionsItemSelected(MenuItem item) switch(item.getItemId()) { case R.id.menu_console: - main.switchFragment(main.fragment_console); + main.switchFragment(main.fragment_console,R.string.activity_console); break; case R.id.menu_settings: - main.switchFragment(main.fragment_settings); - break; - case R.id.menu_install_php: - processing_dialog.setCancelable(false); - processing_dialog.setMessage(getString(R.string.message_installing)); - processing_dialog.show(); - new Thread(new Runnable() - { - public void run() - { - try - { - ServerUtils.installPHP(main,"7"); - main.toast(R.string.message_install_success); - } - catch(ABINotSupportedException e) - { - main.alertABIWarning(e.binaryName,null); - } - catch(Exception e) - { - main.toast(getString(R.string.message_install_fail) + "\n" + e.toString()); - } - main.runOnUiThread(new Runnable() - { - public void run() - { - processing_dialog.dismiss(); - refreshEnabled(); - } - }); - } - }).start(); - break; - /*case R.id.menu_install_php_manually: - new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(R.string.alert_install_php_title) - .setMessage(R.string.alert_install_php_message) - .setPositiveButton(R.string.button_ok,new DialogInterface.OnClickListener() - { - @Override - public void onClick(DialogInterface dialog,int which) - { - chooseFile(CHOOSE_PHP_CODE,getString(R.string.message_choose_php)); - } - }) - .setNegativeButton(R.string.button_cancel,null) - .show(); + main.switchFragment(main.fragment_settings,R.string.activity_settings); break; - case R.id.menu_install_java: - processing_dialog.setCancelable(false); - processing_dialog.setMessage(getString(R.string.message_installing)); - processing_dialog.show(); - new Thread(new Runnable() - { - public void run() - { - try - { - File libData=new File(Environment.getExternalStorageDirectory().toString() + "/nukkit_library.tar.gz"); - if(!libData.exists()) - { - toast(getString(R.string.message_install_fail_path) + " " + Environment.getExternalStorageDirectory() - .toString()); - } - else - { - File inside=new File(ServerUtils.getAppDirectory() + "/java/nukkit_library.tar.gz"); - inside.delete(); - new File(ServerUtils.getAppDirectory() + "/java").mkdirs(); - OutputStream os=new FileOutputStream(inside); - InputStream is=new FileInputStream(libData); - int cou=0; - byte[] buffer=new byte[8192]; - while((cou=is.read(buffer))!=-1) - { - os.write(buffer,0,cou); - } - is.close(); - os.close(); - installBusybox(); - Runtime.getRuntime() - .exec("../busybox tar zxf nukkit_library.tar.gz",new String[0],new File(ServerUtils - .getAppDirectory() + "/java")) - .waitFor(); - inside.delete(); - toast(R.string.message_install_success); - } - } - catch(Exception e) - { - toast(getString(R.string.message_install_fail) + "\n" + e.toString()); - } - runOnUiThread(new Runnable() - { - public void run() - { - processing_dialog.dismiss(); - fragment_main.refreshEnabled(); - } - }); - } - }).start(); - break;*/ case R.id.menu_download_server: AlertDialog.Builder download_dialog_builder=new AlertDialog.Builder(main); String[] jenkins=nukkitMode ? jenkins_nukkit : jenkins_pocketmine, values=new String[jenkins.length]; @@ -302,6 +201,52 @@ public void onClick(View v) refreshEnabled(); } + public void reloadUrls() + { + try + { + File file=new File(ServerUtils.getAppFilesDirectory(),"urls.json"); + if(!file.exists()) + { + main.copyAsset("urls.json",file); + } + FileInputStream fis=new FileInputStream(file); + byte[] data=new byte[(int)file.length()]; + fis.read(data); + fis.close(); + if(data.length<2) + { + file.delete(); + reloadUrls(); + return; + } + JSONObject json=new JSONObject(new String(data,"UTF-8")); + JSONObject jenkins=json.getJSONObject("jenkins"); + { + JSONArray nukkit=jenkins.getJSONArray("nukkit"); + { + jenkins_nukkit=new String[nukkit.length()]; + for(int i=0;i",(need_close ? "" : ""),foreground,background,(italic ? ";font-style: italic" : ""),(underscore ? ";text-decoration: underline" : ""))); + match.appendReplacement(sb,String.format("%s",(need_close ? "" : ""),foreground,background,(italic ? ";font-style: italic" : ""),(underscore ? ";text-decoration: underline" : ""))); need_close=true; } match.appendTail(sb); @@ -119,4 +124,144 @@ else if(40<=icode && icode<=47) } return sb.toString(); } + + public static int parseInt(final String s) + { + final int length=s.length(); + int num=0, i=0; + while(i"); + } + result.append(""); + bright=false; + break; + case 1: + bright=true; + break; + case 2: + // dim + break; + case 3: + result.append("font-style:italic;"); + break; + case 4: + result.append("text-decoration: underline;"); + break; + case 7: + result.append("direction: rtl; unicode-bidi: bidi-override;"); + break; + case 38: // RGB foreground + if(i"); + } + + public StringBuilder parseLine(CharSequence input) + { + modfied=false; + int index=0, length=input.length(); + StringBuilder sb=new StringBuilder(input); + while(index - - - - - - - - - - -