mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 05:36:45 +01:00
Merge pull request #1112 from manuelgu/stuffnthings
Method renaming, util class and logic change
This commit is contained in:
commit
2039cb2891
@ -464,7 +464,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
public void playerRespawn(PlayerRespawnEvent event) {
|
public void playerRespawn(PlayerRespawnEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
EventUtil.manager.doDeathTask(pp);
|
EventUtil.manager.doRespawnTask(pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
@ -1,52 +1,19 @@
|
|||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.PS.log;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.json.JSONArray;
|
import com.intellectualcrafters.json.JSONArray;
|
||||||
import com.intellectualcrafters.json.JSONObject;
|
import com.intellectualcrafters.json.JSONObject;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.util.HttpUtil;
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.PS.log;
|
||||||
|
|
||||||
public class Updater {
|
public class Updater {
|
||||||
|
|
||||||
private static String readUrl(String urlString) {
|
|
||||||
BufferedReader reader = null;
|
|
||||||
try {
|
|
||||||
URL url = new URL(urlString);
|
|
||||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
|
||||||
StringBuilder buffer = new StringBuilder();
|
|
||||||
int read;
|
|
||||||
char[] chars = new char[1024];
|
|
||||||
while ((read = reader.read(chars)) != -1) {
|
|
||||||
buffer.append(chars, 0, read);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log("&dCould not check for updates");
|
|
||||||
if (Settings.DEBUG) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static URL getUpdate() {
|
public static URL getUpdate() {
|
||||||
String str = readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
String str = HttpUtil.readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
||||||
JSONObject release = new JSONObject(str);
|
JSONObject release = new JSONObject(str);
|
||||||
JSONArray assets = (JSONArray) release.get("assets");
|
JSONArray assets = (JSONArray) release.get("assets");
|
||||||
String downloadURL = String.format("PlotSquared-%s.jar", PS.get().getPlatform());
|
String downloadURL = String.format("PlotSquared-%s.jar", PS.get().getPlatform());
|
||||||
|
@ -2,10 +2,9 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(command = "debug",
|
@CommandDeclaration(command = "debug",
|
||||||
@ -29,16 +28,9 @@ public class Debug extends SubCommand {
|
|||||||
String header = C.DEBUG_HEADER.s();
|
String header = C.DEBUG_HEADER.s();
|
||||||
String line = C.DEBUG_LINE.s();
|
String line = C.DEBUG_LINE.s();
|
||||||
String section = C.DEBUG_SECTION.s();
|
String section = C.DEBUG_SECTION.s();
|
||||||
final StringBuilder worlds = new StringBuilder("");
|
|
||||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
|
||||||
@Override
|
|
||||||
public void run(PlotArea value) {
|
|
||||||
worlds.append(value.toString()).append(", ");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
information.append(header);
|
information.append(header);
|
||||||
information.append(getSection(section, "PlotArea"));
|
information.append(getSection(section, "PlotArea"));
|
||||||
information.append(getLine(line, "Plot Worlds", worlds.substring(0, worlds.length() - 2)));
|
information.append(getLine(line, "Plot Worlds", StringMan.join(PS.get().getPlotAreas(), ", ")));
|
||||||
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
||||||
information.append(getSection(section, "Messages"));
|
information.append(getSection(section, "Messages"));
|
||||||
information.append(getLine(line, "Total Messages", C.values().length));
|
information.append(getLine(line, "Total Messages", C.values().length));
|
||||||
|
@ -3,13 +3,10 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
import com.intellectualcrafters.json.JSONObject;
|
import com.intellectualcrafters.json.JSONObject;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.HttpUtil;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
@CommandDeclaration(command = "plugin",
|
@CommandDeclaration(command = "plugin",
|
||||||
permission = "plots.use",
|
permission = "plots.use",
|
||||||
@ -28,35 +25,8 @@ public class PluginCmd extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getNewestVersionString() {
|
public String getNewestVersionString() {
|
||||||
String str = readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
String str = HttpUtil.readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
||||||
JSONObject release = new JSONObject(str);
|
JSONObject release = new JSONObject(str);
|
||||||
return release.getString("name");
|
return release.getString("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readUrl(String urlString) {
|
|
||||||
BufferedReader reader = null;
|
|
||||||
try {
|
|
||||||
URL url = new URL(urlString);
|
|
||||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
|
||||||
StringBuilder buffer = new StringBuilder();
|
|
||||||
int read;
|
|
||||||
char[] chars = new char[1024];
|
|
||||||
while ((read = reader.read(chars)) != -1) {
|
|
||||||
buffer.append(chars, 0, read);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
|
import com.intellectualcrafters.plot.Updater;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@ -23,7 +24,7 @@ public class Update extends SubCommand {
|
|||||||
public boolean onCommand(PlotPlayer plr, String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
URL url;
|
URL url;
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
url = PS.get().update;
|
url = Updater.getUpdate();
|
||||||
} else if (args.length == 1) {
|
} else if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
url = new URL(args[0]);
|
url = new URL(args[0]);
|
||||||
|
@ -79,7 +79,7 @@ public abstract class EventUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doDeathTask(final PlotPlayer pp) {
|
public void doRespawnTask(final PlotPlayer pp) {
|
||||||
final Plot plot = pp.getCurrentPlot();
|
final Plot plot = pp.getCurrentPlot();
|
||||||
if (Settings.TELEPORT_ON_DEATH && plot != null) {
|
if (Settings.TELEPORT_ON_DEATH && plot != null) {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.intellectualcrafters.plot.util;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class HttpUtil {
|
||||||
|
|
||||||
|
public static String readUrl(String urlString) {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
int read;
|
||||||
|
char[] chars = new char[1024];
|
||||||
|
while ((read = reader.read(chars)) != -1) {
|
||||||
|
buffer.append(chars, 0, read);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (Settings.DEBUG) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user