Add url based macro utility command. Also tweak TimeUnit a bit.
This commit is contained in:
parent
04f03eb14a
commit
c11e2ba234
@ -20,6 +20,7 @@ import com.massivecraft.massivecore.adapter.PlayerInventoryAdapter;
|
|||||||
import com.massivecraft.massivecore.adapter.UUIDAdapter;
|
import com.massivecraft.massivecore.adapter.UUIDAdapter;
|
||||||
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCore;
|
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCore;
|
||||||
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreBuffer;
|
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreBuffer;
|
||||||
|
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreCmdurl;
|
||||||
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreStore;
|
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreStore;
|
||||||
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreUsys;
|
import com.massivecraft.massivecore.cmd.massivecore.CmdMassiveCoreUsys;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreUuidUpdate;
|
import com.massivecraft.massivecore.event.EventMassiveCoreUuidUpdate;
|
||||||
@ -105,6 +106,9 @@ public class MassiveCore extends MassivePlugin
|
|||||||
private CmdMassiveCoreBuffer outerCmdMassiveCoreBuffer;
|
private CmdMassiveCoreBuffer outerCmdMassiveCoreBuffer;
|
||||||
public CmdMassiveCoreBuffer getOuterCmdMassiveCoreBuffer() { return this.outerCmdMassiveCoreBuffer; }
|
public CmdMassiveCoreBuffer getOuterCmdMassiveCoreBuffer() { return this.outerCmdMassiveCoreBuffer; }
|
||||||
|
|
||||||
|
private CmdMassiveCoreCmdurl outerCmdMassiveCoreCmdurl;
|
||||||
|
public CmdMassiveCoreCmdurl getOuterCmdMassiveCoreCmdurl() { return this.outerCmdMassiveCoreCmdurl; }
|
||||||
|
|
||||||
// Runnables
|
// Runnables
|
||||||
// TODO: Make this one a singleton
|
// TODO: Make this one a singleton
|
||||||
private Runnable collTickTask = new Runnable()
|
private Runnable collTickTask = new Runnable()
|
||||||
@ -186,6 +190,9 @@ public class MassiveCore extends MassivePlugin
|
|||||||
this.outerCmdMassiveCoreBuffer = new CmdMassiveCoreBuffer() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreBuffer; } };
|
this.outerCmdMassiveCoreBuffer = new CmdMassiveCoreBuffer() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreBuffer; } };
|
||||||
this.outerCmdMassiveCoreBuffer.register();
|
this.outerCmdMassiveCoreBuffer.register();
|
||||||
|
|
||||||
|
this.outerCmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreCmdurl; } };
|
||||||
|
this.outerCmdMassiveCoreCmdurl.register();
|
||||||
|
|
||||||
// Integration
|
// Integration
|
||||||
this.integrate(
|
this.integrate(
|
||||||
IntegrationVault.get()
|
IntegrationVault.get()
|
||||||
|
@ -32,6 +32,8 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
|
|||||||
|
|
||||||
public List<String> aliasesOuterMassiveCoreBuffer = MUtil.list("buffer");
|
public List<String> aliasesOuterMassiveCoreBuffer = MUtil.list("buffer");
|
||||||
|
|
||||||
|
public List<String> aliasesOuterMassiveCoreCmdurl = MUtil.list("cmdurl");
|
||||||
|
|
||||||
public boolean usingRecipientChatEvent = true;
|
public boolean usingRecipientChatEvent = true;
|
||||||
|
|
||||||
public Map<String, String> permissionDeniedFormats = MUtil.map(
|
public Map<String, String> permissionDeniedFormats = MUtil.map(
|
||||||
|
@ -40,6 +40,7 @@ public enum MassiveCorePerm
|
|||||||
BUFFER_SET("buffer.set"),
|
BUFFER_SET("buffer.set"),
|
||||||
BUFFER_ADD("buffer.add"),
|
BUFFER_ADD("buffer.add"),
|
||||||
BUFFER_WHITESPACE("buffer.whitespace"),
|
BUFFER_WHITESPACE("buffer.whitespace"),
|
||||||
|
CMDURL("cmdurl"),
|
||||||
NOTPDELAY("notpdelay"),
|
NOTPDELAY("notpdelay"),
|
||||||
VARIABLE_BOOK("variable.book"),
|
VARIABLE_BOOK("variable.book"),
|
||||||
VARIABLE_BUFFER("variable.buffer"),
|
VARIABLE_BUFFER("variable.buffer"),
|
||||||
|
@ -18,6 +18,7 @@ public class CmdMassiveCore extends MassiveCommand
|
|||||||
public CmdMassiveCoreTest cmdMassiveCoreTest = new CmdMassiveCoreTest();
|
public CmdMassiveCoreTest cmdMassiveCoreTest = new CmdMassiveCoreTest();
|
||||||
public CmdMassiveCoreHearsound cmdMassiveCoreHearsound = new CmdMassiveCoreHearsound();
|
public CmdMassiveCoreHearsound cmdMassiveCoreHearsound = new CmdMassiveCoreHearsound();
|
||||||
public CmdMassiveCoreBuffer cmdMassiveCoreBuffer = new CmdMassiveCoreBuffer();
|
public CmdMassiveCoreBuffer cmdMassiveCoreBuffer = new CmdMassiveCoreBuffer();
|
||||||
|
public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl();
|
||||||
public VersionCommand cmdMassiveCoreVersion = new VersionCommand(MassiveCore.get(), MassiveCorePerm.VERSION.node, "v", "version");
|
public VersionCommand cmdMassiveCoreVersion = new VersionCommand(MassiveCore.get(), MassiveCorePerm.VERSION.node, "v", "version");
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -33,6 +34,7 @@ public class CmdMassiveCore extends MassiveCommand
|
|||||||
this.addSubCommand(this.cmdMassiveCoreTest);
|
this.addSubCommand(this.cmdMassiveCoreTest);
|
||||||
this.addSubCommand(this.cmdMassiveCoreHearsound);
|
this.addSubCommand(this.cmdMassiveCoreHearsound);
|
||||||
this.addSubCommand(this.cmdMassiveCoreBuffer);
|
this.addSubCommand(this.cmdMassiveCoreBuffer);
|
||||||
|
this.addSubCommand(this.cmdMassiveCoreCmdurl);
|
||||||
this.addSubCommand(this.cmdMassiveCoreVersion);
|
this.addSubCommand(this.cmdMassiveCoreVersion);
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
|
@ -0,0 +1,126 @@
|
|||||||
|
package com.massivecraft.massivecore.cmd.massivecore;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
|
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||||
|
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||||
|
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||||
|
import com.massivecraft.massivecore.mixin.Mixin;
|
||||||
|
import com.massivecraft.massivecore.util.WebUtil;
|
||||||
|
|
||||||
|
public class CmdMassiveCoreCmdurl extends MassiveCommand
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public CmdMassiveCoreCmdurl()
|
||||||
|
{
|
||||||
|
// Aliases
|
||||||
|
this.addAliases("cmdurl");
|
||||||
|
|
||||||
|
// Args
|
||||||
|
this.addRequiredArg("url");
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
this.addRequirements(ReqHasPerm.get(MassiveCorePerm.CMDURL.node));
|
||||||
|
this.addRequirements(ReqIsPlayer.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
// Args
|
||||||
|
String urlString = this.arg(0);
|
||||||
|
|
||||||
|
final URL url;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL(urlString);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e)
|
||||||
|
{
|
||||||
|
msg("<b>Malformed URL: %s", e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
final Player commander = me;
|
||||||
|
msg("<i>Loading <aqua>%s <i>...", urlString);
|
||||||
|
async(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final List<String> lines = WebUtil.getUrlLines(url, 5000);
|
||||||
|
sync(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Mixin.msgOne(commander, "<i>... <h>%d <i>lines loaded. Now executing ...", lines.size());
|
||||||
|
for (int i = 0; i <= lines.size() - 1; i++)
|
||||||
|
{
|
||||||
|
String line = lines.get(i);
|
||||||
|
line = line.trim();
|
||||||
|
if (line.length() == 0 || line.startsWith("#"))
|
||||||
|
{
|
||||||
|
Mixin.msgOne(commander, "<b>#%d: <i>%s", i, line);
|
||||||
|
// Ignore the line
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mixin.msgOne(commander, "<g>#%d: <i>%s", i, line);
|
||||||
|
// Run the line
|
||||||
|
commander.chat(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (final Exception e)
|
||||||
|
{
|
||||||
|
sync(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Mixin.msgOne(commander, "<b>%s: %s", e.getClass().getSimpleName(), e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// ASYNC/SYNC SHORTHANDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static void sync(Runnable runnable)
|
||||||
|
{
|
||||||
|
Bukkit.getScheduler().runTask(MassiveCore.get(), runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void async(Runnable runnable)
|
||||||
|
{
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(MassiveCore.get(), runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -93,6 +93,21 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
|||||||
return Mixin.isOffline(this.getId());
|
return Mixin.isOffline(this.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getLastPlayed()
|
||||||
|
{
|
||||||
|
return Mixin.getLastPlayed(this.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getFirstPlayed()
|
||||||
|
{
|
||||||
|
return Mixin.getFirstPlayed(this.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPlayedBefore()
|
||||||
|
{
|
||||||
|
return Mixin.hasPlayedBefore(this.getId());
|
||||||
|
}
|
||||||
|
|
||||||
// DISPLAY NAME
|
// DISPLAY NAME
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -36,25 +36,35 @@ public class TimeUnit implements Comparable<TimeUnit>
|
|||||||
|
|
||||||
private static final TreeSet<TimeUnit> all = new TreeSet<TimeUnit>();
|
private static final TreeSet<TimeUnit> all = new TreeSet<TimeUnit>();
|
||||||
public static TreeSet<TimeUnit> getAll() { return new TreeSet<TimeUnit>(all); }
|
public static TreeSet<TimeUnit> getAll() { return new TreeSet<TimeUnit>(all); }
|
||||||
|
|
||||||
|
public static TreeSet<TimeUnit> getAllBut(TimeUnit... timeUnits)
|
||||||
|
{
|
||||||
|
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(all);
|
||||||
|
for (TimeUnit timeUnit : timeUnits)
|
||||||
|
{
|
||||||
|
ret.remove(timeUnit);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public static TreeSet<TimeUnit> getAllButMillis()
|
public static TreeSet<TimeUnit> getAllButMillis()
|
||||||
{
|
{
|
||||||
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(all);
|
return getAllBut(MILLISECOND);
|
||||||
ret.remove(MILLISECOND);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TreeSet<TimeUnit> getAllButMillisAndSeconds()
|
public static TreeSet<TimeUnit> getAllButMillisAndSeconds()
|
||||||
{
|
{
|
||||||
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(all);
|
return getAllBut(MILLISECOND, SECOND);
|
||||||
ret.remove(MILLISECOND);
|
|
||||||
ret.remove(SECOND);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TreeSet<TimeUnit> getAllButMillisSecondsAndMinutes()
|
public static TreeSet<TimeUnit> getAllButMillisSecondsAndMinutes()
|
||||||
{
|
{
|
||||||
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(all);
|
return getAllBut(MILLISECOND, SECOND, MINUTE);
|
||||||
ret.remove(MILLISECOND);
|
}
|
||||||
ret.remove(SECOND);
|
|
||||||
ret.remove(MINUTE);
|
public static TreeSet<TimeUnit> getSpecific(TimeUnit... timeUnits)
|
||||||
|
{
|
||||||
|
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(Arrays.asList(timeUnits));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
package com.massivecraft.massivecore.util;
|
package com.massivecraft.massivecore.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class WebUtil
|
public class WebUtil
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// ASYNC GET TOUCH
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static final ExecutorService executor = Executors.newSingleThreadExecutor();
|
private static final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
public static void asyncGetTouch(String url)
|
public static void asyncGetTouch(String url)
|
||||||
@ -44,4 +53,48 @@ public class WebUtil
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// GET URL LINES
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// This one should be run async since it's very slow.
|
||||||
|
public static List<String> getUrlLines(URL url, int timeoutMillis) throws IOException
|
||||||
|
{
|
||||||
|
HttpURLConnection uc = null;
|
||||||
|
InputStream is = null;
|
||||||
|
InputStreamReader isr = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uc = (HttpURLConnection) url.openConnection();
|
||||||
|
uc.setConnectTimeout(timeoutMillis);
|
||||||
|
uc.setRequestMethod("GET");
|
||||||
|
uc.addRequestProperty("User-Agent", "Mozilla/4.76");
|
||||||
|
uc.connect();
|
||||||
|
|
||||||
|
is = uc.getInputStream();
|
||||||
|
isr = new InputStreamReader(is, "UTF-8");
|
||||||
|
br = new BufferedReader(isr);
|
||||||
|
|
||||||
|
List<String> lines = new ArrayList<String>();
|
||||||
|
String line = null;
|
||||||
|
while ( (line = br.readLine()) != null )
|
||||||
|
{
|
||||||
|
lines.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Closing BufferedReader does close InputStreamReader does close InputStream.
|
||||||
|
try { br.close(); } catch (Exception ignored) {}
|
||||||
|
// However documentation suggested we must disconnect the HttpURLConnection manually.
|
||||||
|
try { uc.disconnect(); } catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ permissions:
|
|||||||
massivecore.buffer.set: {description: set buffer, default: false}
|
massivecore.buffer.set: {description: set buffer, default: false}
|
||||||
massivecore.buffer.add: {description: add to buffer, default: false}
|
massivecore.buffer.add: {description: add to buffer, default: false}
|
||||||
massivecore.buffer.whitespace: {description: add whitespace to buffer, default: false}
|
massivecore.buffer.whitespace: {description: add whitespace to buffer, default: false}
|
||||||
|
massivecore.cmdurl: {description: run all lines of url content, default: false}
|
||||||
# misc
|
# misc
|
||||||
massivecore.notpdelay: {description: teleport without delay, default: false}
|
massivecore.notpdelay: {description: teleport without delay, default: false}
|
||||||
massivecore.variable.book: {description: replace ***book*** with content of book in your hand, default: false}
|
massivecore.variable.book: {description: replace ***book*** with content of book in your hand, default: false}
|
||||||
@ -80,6 +81,7 @@ permissions:
|
|||||||
massivecore.buffer.set: true
|
massivecore.buffer.set: true
|
||||||
massivecore.buffer.add: true
|
massivecore.buffer.add: true
|
||||||
massivecore.buffer.whitespace: true
|
massivecore.buffer.whitespace: true
|
||||||
|
massivecore.cmdurl: true
|
||||||
massivecore.notpdelay: true
|
massivecore.notpdelay: true
|
||||||
massivecore.variable.book: true
|
massivecore.variable.book: true
|
||||||
massivecore.variable.buffer: true
|
massivecore.variable.buffer: true
|
||||||
|
Loading…
Reference in New Issue
Block a user