mirror of
https://github.com/Ne0nx3r0/BetterAlias.git
synced 2025-01-09 19:48:30 +01:00
Added support for !*
This commit is contained in:
parent
bb82b7ffaa
commit
c34db63b29
@ -4,8 +4,10 @@ banhammer:
|
|||||||
#name parameter is replaced with the command users name
|
#name parameter is replaced with the command users name
|
||||||
gmon:
|
gmon:
|
||||||
0: /gamemode !name 1
|
0: /gamemode !name 1
|
||||||
|
1: /gamemode !1 1
|
||||||
gmoff:
|
gmoff:
|
||||||
0: /gamemode !name 0
|
0: /gamemode !name 0
|
||||||
|
1: /gamemode !1 0
|
||||||
# putting a P after the parameter specifies this is a player, and BA should try to guess which player
|
# putting a P after the parameter specifies this is a player, and BA should try to guess which player
|
||||||
# useful for things like "/to e0n" instead of "/to Ne0nx3r0"
|
# useful for things like "/to e0n" instead of "/to Ne0nx3r0"
|
||||||
# This will ONLY look for players that are online
|
# This will ONLY look for players that are online
|
||||||
@ -22,3 +24,6 @@ tpthenkick:
|
|||||||
# special command for toggling GM mode
|
# special command for toggling GM mode
|
||||||
gm:
|
gm:
|
||||||
0: /gamemode !name !oppositeGameMode
|
0: /gamemode !name !oppositeGameMode
|
||||||
|
# hand all parameters in order
|
||||||
|
s:
|
||||||
|
"*": /say I want to say "!*", there I said it!
|
@ -5,13 +5,16 @@ import java.util.Map;
|
|||||||
|
|
||||||
class Alias{
|
class Alias{
|
||||||
//mapping number of parameters to string(s) to be executed
|
//mapping number of parameters to string(s) to be executed
|
||||||
private Map<Integer,String[]> params = new HashMap<Integer,String[]>();
|
private Map<String,String[]> params = new HashMap<String,String[]>();
|
||||||
|
|
||||||
public Alias(Map<Integer,String[]> p){
|
public Alias(Map<String,String[]> p){
|
||||||
this.params = p;
|
this.params = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getCommands(int p){
|
public String[] getCommands(int p){
|
||||||
return this.params.get(p);
|
if(this.params.containsKey(Integer.toString(p))){
|
||||||
|
return this.params.get(Integer.toString(p));
|
||||||
|
}
|
||||||
|
return this.params.get("*");//or null if it doesn't exist
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -19,8 +18,6 @@ public class AliasManager{
|
|||||||
public AliasManager(BetterAlias ba){
|
public AliasManager(BetterAlias ba){
|
||||||
plugin = ba;
|
plugin = ba;
|
||||||
|
|
||||||
// loadAliasesLocal();
|
|
||||||
|
|
||||||
loadAliases();
|
loadAliases();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,22 +41,29 @@ public class AliasManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(String sAlias : aliasList){
|
for(String sAlias : aliasList){
|
||||||
Map<Integer,String[]> shareMap = new HashMap<Integer,String[]>();
|
Map<String,String[]> shareMap = new HashMap<String,String[]>();
|
||||||
|
|
||||||
for(int i=0;i<10;i++){
|
for(int i=0;i<10;i++){
|
||||||
|
|
||||||
if(yml.isList(sAlias+"."+i)){
|
if(yml.isList(sAlias+"."+i)){
|
||||||
|
|
||||||
shareMap.put(i,yml.getStringList(sAlias+"."+i).toArray(new String[]{}));
|
shareMap.put(Integer.toString(i),yml.getStringList(sAlias+"."+i).toArray(new String[]{}));
|
||||||
|
|
||||||
}else if(yml.isString(sAlias+"."+i)){
|
}else if(yml.isString(sAlias+"."+i)){
|
||||||
|
|
||||||
shareMap.put(i,new String[]{yml.getString(sAlias+"."+i)});
|
shareMap.put(Integer.toString(i),new String[]{yml.getString(sAlias+"."+i)});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(yml.isList(sAlias+".*")){
|
||||||
|
shareMap.put("*",yml.getStringList(sAlias+".*").toArray(new String[]{}));
|
||||||
|
|
||||||
|
}else if(yml.isString(sAlias+".*")){
|
||||||
|
shareMap.put("*",new String[]{yml.getString(sAlias+".*")});
|
||||||
|
}
|
||||||
|
|
||||||
aliases.put(sAlias,new Alias(shareMap));
|
aliases.put(sAlias,new Alias(shareMap));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,16 @@ class BetterAliasPlayerListener implements Listener{
|
|||||||
|
|
||||||
for(String commandToExecute : commandsToExecute){
|
for(String commandToExecute : commandsToExecute){
|
||||||
//regex time!
|
//regex time!
|
||||||
Pattern patt = Pattern.compile("!([0-9a-zA-Z~]+)");
|
Pattern patt = Pattern.compile("!([0-9a-zA-Z~*]+)");
|
||||||
Matcher m = patt.matcher(commandToExecute);
|
Matcher m = patt.matcher(commandToExecute);
|
||||||
StringBuffer sb = new StringBuffer(commandToExecute.length());
|
StringBuffer sb = new StringBuffer(commandToExecute.length());
|
||||||
|
|
||||||
while(m.find()){
|
while(m.find()){
|
||||||
String text = m.group(0).substring(1);
|
String text = m.group(0).substring(1);
|
||||||
|
|
||||||
if(text.equalsIgnoreCase("name")){
|
if(text.equalsIgnoreCase("*")){
|
||||||
|
text = e.getMessage().replace("/"+cmd[0]+" ","");
|
||||||
|
}else if(text.equalsIgnoreCase("name")){
|
||||||
text = player.getName();
|
text = player.getName();
|
||||||
}else if(text.equalsIgnoreCase("oppositeGameMode")){
|
}else if(text.equalsIgnoreCase("oppositeGameMode")){
|
||||||
text = (player.getGameMode() == GameMode.SURVIVAL ? "1" : "0");
|
text = (player.getGameMode() == GameMode.SURVIVAL ? "1" : "0");
|
||||||
@ -74,15 +76,11 @@ class BetterAliasPlayerListener implements Listener{
|
|||||||
text = cmd[iParam];
|
text = cmd[iParam];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else if is numeric and cmd[i] exists, replace with cmd[i]
|
|
||||||
|
|
||||||
m.appendReplacement(sb, Matcher.quoteReplacement(text));
|
m.appendReplacement(sb, Matcher.quoteReplacement(text));
|
||||||
}
|
}
|
||||||
m.appendTail(sb);
|
m.appendTail(sb);
|
||||||
|
|
||||||
//tp !name !~1
|
|
||||||
//tp !1 !2
|
|
||||||
//tp !~1 !~2
|
|
||||||
//debug: player.sendMessage(sb.toString());
|
//debug: player.sendMessage(sb.toString());
|
||||||
player.chat(sb.toString());
|
player.chat(sb.toString());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: BetterAlias
|
name: BetterAlias
|
||||||
main: com.gmail.Ne0nx3r0.BetterAlias
|
main: com.gmail.Ne0nx3r0.BetterAlias
|
||||||
version: '0.1.2'
|
version: '0.1.3'
|
||||||
database: false
|
database: false
|
||||||
description: Command alias system
|
description: Command alias system
|
Loading…
Reference in New Issue
Block a user