mirror of
https://github.com/Ne0nx3r0/BetterAlias.git
synced 2024-11-27 12:46:12 +01:00
Adding wait times
This commit is contained in:
parent
404f460b4c
commit
e221ccb7f3
28
aliases.yml
28
aliases.yml
@ -30,6 +30,10 @@ hand:
|
|||||||
handid:
|
handid:
|
||||||
0: /give !name !handItemID
|
0: /give !name !handItemID
|
||||||
|
|
||||||
|
# Toggle the current player's game mode from survival to creative
|
||||||
|
gm:
|
||||||
|
0: /gamemode !oppositeGameMode !name
|
||||||
|
|
||||||
# Send everything with a command
|
# Send everything with a command
|
||||||
sendAll:
|
sendAll:
|
||||||
"*": /say !*
|
"*": /say !*
|
||||||
@ -71,3 +75,27 @@ makeop:
|
|||||||
- /me has opped !1
|
- /me has opped !1
|
||||||
2: console /say testing single line
|
2: console /say testing single line
|
||||||
3: reply testing single line
|
3: reply testing single line
|
||||||
|
|
||||||
|
# Wait example
|
||||||
|
wait:
|
||||||
|
# Quotes are required because 0 uses a colon (:)
|
||||||
|
0:
|
||||||
|
- wait 80 /me thinks this message will come third
|
||||||
|
- wait 40 /me thinks this message will come second
|
||||||
|
- /me thinks this message will come first
|
||||||
|
|
||||||
|
# wait then reply example
|
||||||
|
waitreply:
|
||||||
|
# Quotes are required because 0 uses a colon (:)
|
||||||
|
0:
|
||||||
|
- wait 80 reply this came third!
|
||||||
|
- wait 40 reply this came second!
|
||||||
|
- reply this came first!
|
||||||
|
|
||||||
|
# Wait then console example
|
||||||
|
waitconsole:
|
||||||
|
# Quotes are required because 0 uses a colon (:)
|
||||||
|
0:
|
||||||
|
- wait 40 console /say this message was delayed!
|
||||||
|
- wait 80 console /say this message was delayed longer!
|
||||||
|
- console /say this message came first!
|
@ -4,10 +4,16 @@ public class AliasCommand
|
|||||||
{
|
{
|
||||||
final String command;
|
final String command;
|
||||||
final AliasCommandTypes type;
|
final AliasCommandTypes type;
|
||||||
|
int waitTime;
|
||||||
|
|
||||||
public AliasCommand(String command,AliasCommandTypes type)
|
public AliasCommand(String command,AliasCommandTypes type,int waitTime)
|
||||||
{
|
{
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
|
if(waitTime > 0)
|
||||||
|
{
|
||||||
|
this.waitTime = waitTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ public enum AliasCommandTypes
|
|||||||
{
|
{
|
||||||
PLAYER,
|
PLAYER,
|
||||||
CONSOLE,
|
CONSOLE,
|
||||||
REPLY_MESSAGE;
|
REPLY_MESSAGE,
|
||||||
|
WAIT,
|
||||||
|
WAIT_THEN_CONSOLE,
|
||||||
|
WAIT_THEN_REPLY;
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,22 @@ import java.util.logging.Level;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
public class AliasManager
|
public class AliasManager
|
||||||
{
|
{
|
||||||
private final BetterAlias plugin;
|
private static BetterAlias plugin;
|
||||||
private HashMap<String, Alias> aliases;
|
private HashMap<String, Alias> aliases;
|
||||||
|
|
||||||
public AliasManager(BetterAlias plugin)
|
public AliasManager(BetterAlias plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
AliasManager.plugin = plugin;
|
||||||
|
|
||||||
this.loadAliases();
|
this.loadAliases();
|
||||||
}
|
}
|
||||||
@ -98,6 +101,8 @@ public class AliasManager
|
|||||||
{
|
{
|
||||||
AliasCommandTypes type = AliasCommandTypes.PLAYER;
|
AliasCommandTypes type = AliasCommandTypes.PLAYER;
|
||||||
|
|
||||||
|
int waitTime = 0;
|
||||||
|
|
||||||
if(sArgLine.contains(" "))
|
if(sArgLine.contains(" "))
|
||||||
{
|
{
|
||||||
String sType = sArgLine.substring(0,sArgLine.indexOf(" "));
|
String sType = sArgLine.substring(0,sArgLine.indexOf(" "));
|
||||||
@ -114,11 +119,46 @@ public class AliasManager
|
|||||||
|
|
||||||
sArgLine = sArgLine.substring(sArgLine.indexOf(" ")+1);
|
sArgLine = sArgLine.substring(sArgLine.indexOf(" ")+1);
|
||||||
}
|
}
|
||||||
|
else if(sType.equalsIgnoreCase("wait"))
|
||||||
|
{
|
||||||
|
String[] sArgLineParams = sArgLine.split(" ");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
waitTime = Integer.parseInt(sArgLineParams[1]);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
plugin.getLogger().log(Level.WARNING, "Invalid wait time for command {0} in alias {1}, skipping line",
|
||||||
|
new Object[]{sArgLine, sAlias});
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sArgLineParams[2].equalsIgnoreCase("reply"))
|
||||||
|
{
|
||||||
|
type = AliasCommandTypes.WAIT_THEN_REPLY;
|
||||||
|
|
||||||
|
sArgLine = sArgLine.replace(sArgLineParams[0]+" "+sArgLineParams[1]+" "+sArgLineParams[2]+" ", "");
|
||||||
|
}
|
||||||
|
else if(sArgLineParams[2].equalsIgnoreCase("console"))
|
||||||
|
{
|
||||||
|
type = AliasCommandTypes.WAIT_THEN_CONSOLE;
|
||||||
|
|
||||||
|
sArgLine = sArgLine.replace(sArgLineParams[0]+" "+sArgLineParams[1]+" "+sArgLineParams[2]+" ", "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
type = AliasCommandTypes.WAIT;
|
||||||
|
|
||||||
|
sArgLine = sArgLine.replace(sArgLineParams[0]+" "+sArgLineParams[1]+" ", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sArgLine = this.replaceColorCodes(sArgLine);
|
sArgLine = this.replaceColorCodes(sArgLine);
|
||||||
|
|
||||||
commandsList.add(new AliasCommand(sArgLine,type));
|
commandsList.add(new AliasCommand(sArgLine,type,waitTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
alias.setCommandsFor(iArg,commandsList);
|
alias.setCommandsFor(iArg,commandsList);
|
||||||
@ -229,6 +269,21 @@ public class AliasManager
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(text.equalsIgnoreCase("oppositeGameMode"))
|
||||||
|
{
|
||||||
|
if(player != null)
|
||||||
|
{
|
||||||
|
text = player.getGameMode().equals(GameMode.SURVIVAL)?"creative":"survival";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cs.sendMessage("[BetterAlias] "+ChatColor.RED+"A parameter of this alias requires a player.");
|
||||||
|
|
||||||
|
cs.sendMessage("[BetterAlias] Line: "+ac.command);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(text.equalsIgnoreCase("*"))
|
else if(text.equalsIgnoreCase("*"))
|
||||||
{
|
{
|
||||||
text = commandString;
|
text = commandString;
|
||||||
@ -286,16 +341,59 @@ public class AliasManager
|
|||||||
m.appendTail(sb);
|
m.appendTail(sb);
|
||||||
|
|
||||||
String sNewCommand = sb.toString();
|
String sNewCommand = sb.toString();
|
||||||
|
|
||||||
if(ac.type.equals(AliasCommandTypes.REPLY_MESSAGE))
|
if(ac.type.equals(AliasCommandTypes.REPLY_MESSAGE))
|
||||||
{
|
{
|
||||||
cs.sendMessage(sNewCommand);
|
cs.sendMessage(sNewCommand);
|
||||||
}
|
}
|
||||||
|
else if(ac.type.equals(AliasCommandTypes.WAIT_THEN_REPLY))
|
||||||
|
{
|
||||||
|
final CommandSender csWait = cs;
|
||||||
|
final String message = sNewCommand;
|
||||||
|
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
csWait.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, ac.waitTime);
|
||||||
|
}
|
||||||
|
else if(ac.type.equals(AliasCommandTypes.WAIT_THEN_CONSOLE))
|
||||||
|
{
|
||||||
|
if(player != null)
|
||||||
|
{
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin,new waitConsoleCommand(sNewCommand.substring(1),
|
||||||
|
"[BetterAlias] "+ChatColor.AQUA+"Running console command for "+player.getName()+": "+sNewCommand), ac.waitTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitConsoleCommand(sNewCommand.substring(1),
|
||||||
|
"[BetterAlias] "+ChatColor.AQUA+"Running: "+sNewCommand), ac.waitTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(ac.type.equals(AliasCommandTypes.WAIT))
|
||||||
|
{
|
||||||
|
if(player != null)
|
||||||
|
{
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitPlayerCommand(sNewCommand,player.getName()), ac.waitTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitConsoleCommand(sNewCommand.substring(1),
|
||||||
|
"[BetterAlias] "+ChatColor.AQUA+"Running: "+sNewCommand), ac.waitTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(ac.type.equals(AliasCommandTypes.CONSOLE)
|
else if(ac.type.equals(AliasCommandTypes.CONSOLE)
|
||||||
|| player == null)
|
|| player == null)
|
||||||
{
|
{
|
||||||
if(player != null)
|
if(player != null)
|
||||||
{
|
{
|
||||||
plugin.getLogger().log(Level.INFO,"[BetterAlias] "+ChatColor.AQUA+"Running console command for "+player.getName()+": "+sNewCommand);
|
plugin.getLogger().log(Level.INFO,
|
||||||
|
"[BetterAlias] {0}Running console command for {1}: {2}",
|
||||||
|
new Object[]{ChatColor.AQUA, player.getName(), sNewCommand});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -316,7 +414,48 @@ public class AliasManager
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method
|
// Delayed tasks
|
||||||
|
private static class waitConsoleCommand implements Runnable
|
||||||
|
{
|
||||||
|
private final String message;
|
||||||
|
private final String command;
|
||||||
|
|
||||||
|
public waitConsoleCommand(String command,String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class waitPlayerCommand implements Runnable
|
||||||
|
{
|
||||||
|
private final String playerName;
|
||||||
|
private final String command;
|
||||||
|
|
||||||
|
public waitPlayerCommand(String command,String playerName)
|
||||||
|
{
|
||||||
|
this.playerName = playerName;
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Player p = plugin.getServer().getPlayer(playerName);
|
||||||
|
|
||||||
|
if(p != null)
|
||||||
|
{
|
||||||
|
p.chat(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void copy(InputStream in, File file)
|
public void copy(InputStream in, File file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: BetterAlias
|
name: BetterAlias
|
||||||
main: com.ne0nx3r0.betteralias.BetterAlias
|
main: com.ne0nx3r0.betteralias.BetterAlias
|
||||||
version: '1.1.0'
|
version: '1.2'
|
||||||
database: false
|
database: false
|
||||||
description: Command alias system
|
description: Command alias system
|
||||||
commands:
|
commands:
|
||||||
|
Loading…
Reference in New Issue
Block a user