Post: [Snippet] Sending links
03-07-2015, 02:43 PM #1
Vesia
Haxor!
(adsbygoogle = window.adsbygoogle || []).push({}); Made this after seeing this comment on another forum
Originally posted by Makar
You could also add an "Do you want to open this?" message to prevent childish and immature owners from creating commands that spam open a link to flood people and lag their computers when they get mad at a player.


Not sure if this is the best way to do it or not

You must login or register to view this content.




    
public void openURL(String url) {
try {
UrlValidator urlValidator = new UrlValidator();
if(!urlValidator.isValid(url)) {
System.err.println("Invalid link specified: "+url);
System.err.println("http, https, and ftp are the only valid schemes.");
return;
}
int confirm = JOptionPane.showConfirmDialog(null, "URL: "+url, "URL Confirmation", JOptionPane.YES_NO_OPTION);
if(confirm == JOptionPane.YES_OPTION) {
Desktop.getDesktop().browse(new URI(url));
}
} catch (Exception e) {
e.printStackTrace();
}
}


    
if(inputString.startsWith("::url")) {
String[] args = inputString.split(" ");
openURL(args[1]);
}
(adsbygoogle = window.adsbygoogle || []).push({});

The following user thanked Vesia for this useful post:

Stunz
03-07-2015, 04:59 PM #2
Stunz
Former Staff
Originally posted by Vesia View Post
Made this after seeing this comment on another forum


Not sure if this is the best way to do it or not

You must login or register to view this content.




    
public void openURL(String url) {
try {
UrlValidator urlValidator = new UrlValidator();
if(!urlValidator.isValid(url)) {
System.err.println("Invalid link specified: "+url);
System.err.println("http, https, and ftp are the only valid schemes.");
return;
}
int confirm = JOptionPane.showConfirmDialog(null, "URL: "+url, "URL Confirmation", JOptionPane.YES_NO_OPTION);
if(confirm == JOptionPane.YES_OPTION) {
Desktop.getDesktop().browse(new URI(url));
}
} catch (Exception e) {
e.printStackTrace();
}
}


    
if(inputString.startsWith("::url")) {
String[] args = inputString.split(" ");
openURL(args[1]);
}
Good stuff Smile

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo